Skip to contentSkip to conversation

Fixes for Rockchip NFC driver part 1

PATCH Superseded Johan Jonker 3 participants 26 messages Feb 7, 2023 – Feb 16, 2023

Subsystems (3)

v2 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

v2 cover Fixes for Rockchip NFC driver part 1

This serie contains fixes for the Rockchip NFC driver, which was ported to U-boot and merged with little review and testing it seems.
Part 1 aims at passing the probe function without errors.

Fixed are:
64bit FDT parsing
compatible string removal
add missing layout structure
add missing flash_node pointer
add missing chip ID

Johan Jonker (9):
include: fdtdec: decouple fdt_addr_t and phys_addr_t size
include: dm: ofnode: fix headers
core: remap: convert regmap_init_mem_plat() input to phys_addr_t
rockchip: adc: rockchip-saradc: convert dev_read_addr output to
phys_addr_t
rockchip: timer: dw-apb-timer: convert dev_read_addr output to
phys_addr_t
rockchip: mtd: raw: rockchip_nfc convert dev_read_addr output to
phys_addr_t
mtd: nand: raw: rockchip_nfc: remove the compatible string

    "rockchip,rk3308-nfc"

mtd: nand: raw: rockchip_nfc: add layout structure
mtd: nand: raw: rockchip_nfc: add flash_node to chip stucture

Paweł Jarosz (1):
mtd: nand: add support for the Sandisk SDTNQGAMA chip

 Kconfig                             |  8 ++++
 drivers/adc/rockchip-saradc.c       |  2 +-
 drivers/core/regmap.c               |  2 +-
 drivers/core/syscon-uclass.c        |  2 +-
 drivers/mtd/nand/raw/nand_ids.c     |  3 ++
 drivers/mtd/nand/raw/rockchip_nfc.c | 68 ++++++++++-------------------
 drivers/ram/rockchip/sdram_rk3066.c |  2 +-
 drivers/ram/rockchip/sdram_rk3188.c |  2 +-
 drivers/ram/rockchip/sdram_rk322x.c |  2 +-
 drivers/ram/rockchip/sdram_rk3288.c |  2 +-
 drivers/ram/rockchip/sdram_rk3328.c |  2 +-
 drivers/ram/rockchip/sdram_rk3399.c |  2 +-
 drivers/timer/dw-apb-timer.c        |  4 +-
 include/dm/ofnode.h                 | 16 +++----
 include/fdtdec.h                    | 13 ++++--
 include/regmap.h                    |  2 +-
 16 files changed, 62 insertions(+), 70 deletions(-)

--
2.20.1

#1 lore raw

PATCH v2 1/10 include: fdtdec: decouple fdt_addr_t and phys_addr_t size

The DT specification supports CPUs with both 32-bit and 64-bit addressing capabilities. In U-boot the fdt_addr_t and phys_addr_t size are coupled by a typedef. The MTD NAND drivers for 32-bit CPU's can describe partitions with a 64-bit reg property. These partitions synced from Linux end up with the wrong offset and sizes when only the lower 32-bit is passed. Decouple the fdt_addr_t and phys_addr_t size as they don't necessary match.

---

Changed V2:
reword

---

Note:
Most drivers still assume that FDT and CPU capabilities are identical. In order to use these variables a cast is needed.

---
 Kconfig          |  8 ++++++++
 include/fdtdec.h | 13 +++++++++----
 2 files changed, 17 insertions(+), 4 deletions(-)
Kconfig +8 -0
index a75cce7e..7697dade 100644
@@ -422,11 +422,19 @@ endif # EXPERT
 
 config PHYS_64BIT
 	bool "64bit physical address support"
+	select FDT_64BIT
 	help
 	  Say Y here to support 64bit physical memory address.
 	  This can be used not only for 64bit SoCs, but also for
 	  large physical address extension on 32bit SoCs.
 
+config FDT_64BIT
+	bool "64bit fdt address support"
+	help
+	  Say Y here to support 64bit fdt addresses.
+	  This can be used not only for 64bit SoCs, but also
+	  for large address extensions on 32bit SoCs.
+
 config HAS_ROM
 	bool
 	select BINMAN
include/fdtdec.h +9 -4
index 12355afd..af29ac0c 100644
@@ -18,15 +18,18 @@
 #include <pci.h>
 
 /*
- * A typedef for a physical address. Note that fdt data is always big
+ * Support for 64bit fdt addresses.
+ * This can be used not only for 64bit SoCs, but also
+ * for large address extensions on 32bit SoCs.
+ * Note that fdt data is always big
  * endian even on a litle endian machine.
  */
-typedef phys_addr_t fdt_addr_t;
-typedef phys_size_t fdt_size_t;
 
 #define FDT_SIZE_T_NONE (-1U)
 
-#ifdef CONFIG_PHYS_64BIT
+#ifdef CONFIG_FDT_64BIT
+typedef u64 fdt_addr_t;
+typedef u64 fdt_size_t;
 #define FDT_ADDR_T_NONE ((ulong)(-1))
 
 #define fdt_addr_to_cpu(reg) be64_to_cpu(reg)
@@ -35,6 +38,8 @@ typedef phys_size_t fdt_size_t;
 #define cpu_to_fdt_size(reg) cpu_to_be64(reg)
 typedef fdt64_t fdt_val_t;
 #else
+typedef u32 fdt_addr_t;
+typedef u32 fdt_size_t;
 #define FDT_ADDR_T_NONE (-1U)
 
 #define fdt_addr_to_cpu(reg) be32_to_cpu(reg)

--
2.20.1

Reviewed-by on v2 1/10
#2 lore raw

Re: [PATCH v2 01/10] include: fdtdec: decouple fdt_addr_t and phys_addr_t size

Quoted 10 lines · Johan Jonker

The DT specification supports CPUs with both 32-bit and 64-bit addressing capabilities. In U-boot the fdt_addr_t and phys_addr_t size are coupled by a typedef. The MTD NAND drivers for 32-bit CPU's can describe partitions with a 64-bit reg property. These partitions synced from Linux end up with the wrong offset and sizes when only the lower 32-bit is passed. Decouple the fdt_addr_t and phys_addr_t size as they don't necessary match.

Thanks,
- Kever

Quoted 78 lines

---

Changed V2:
reword

---

Note:
Most drivers still assume that FDT and CPU capabilities are identical. In order to use these variables a cast is needed.

---
  Kconfig          |  8 ++++++++
  include/fdtdec.h | 13 +++++++++----
  2 files changed, 17 insertions(+), 4 deletions(-)
Kconfig +8 -0
index a75cce7e..7697dade 100644
@@ -422,11 +422,19 @@ endif # EXPERT
 
  config PHYS_64BIT
  	bool "64bit physical address support"
+	select FDT_64BIT
  	help
  	  Say Y here to support 64bit physical memory address.
  	  This can be used not only for 64bit SoCs, but also for
  	  large physical address extension on 32bit SoCs.
 
+config FDT_64BIT
+	bool "64bit fdt address support"
+	help
+	  Say Y here to support 64bit fdt addresses.
+	  This can be used not only for 64bit SoCs, but also
+	  for large address extensions on 32bit SoCs.
+
  config HAS_ROM
  	bool
  	select BINMAN
include/fdtdec.h +9 -5
index 12355afd..af29ac0c 100644
@@ -18,15 +18,18 @@
  #include <pci.h>
 
  /*
- * A typedef for a physical address. Note that fdt data is always big
+ * Support for 64bit fdt addresses.
+ * This can be used not only for 64bit SoCs, but also
+ * for large address extensions on 32bit SoCs.
+ * Note that fdt data is always big
   * endian even on a litle endian machine.
   */
-typedef phys_addr_t fdt_addr_t;
-typedef phys_size_t fdt_size_t;
 
  #define FDT_SIZE_T_NONE (-1U)
 
-#ifdef CONFIG_PHYS_64BIT
+#ifdef CONFIG_FDT_64BIT
+typedef u64 fdt_addr_t;
+typedef u64 fdt_size_t;
  #define FDT_ADDR_T_NONE ((ulong)(-1))
 
  #define fdt_addr_to_cpu(reg) be64_to_cpu(reg)
@@ -35,6 +38,8 @@ typedef phys_size_t fdt_size_t;
  #define cpu_to_fdt_size(reg) cpu_to_be64(reg)
  typedef fdt64_t fdt_val_t;
  #else
+typedef u32 fdt_addr_t;
+typedef u32 fdt_size_t;
  #define FDT_ADDR_T_NONE (-1U)
 
  #define fdt_addr_to_cpu(reg) be32_to_cpu(reg)
--

2.20.1

#3 lore raw

PATCH v2 2/10 include: dm: ofnode: fix headers

In reply to Johan Jonker

When fdt_addr_t and phys_addr_t are split it turns out that the header don't match the functions, so fix the headers.

---
 include/dm/ofnode.h | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
include/dm/ofnode.h +8 -8
index fa986560..287b0c35 100644
@@ -678,8 +678,8 @@ int ofnode_read_size(ofnode node, const char *propname);
  * @size: Pointer to size of the address
  * Return: address, or FDT_ADDR_T_NONE if not present or invalid
  */
-phys_addr_t ofnode_get_addr_size_index(ofnode node, int index,
-				       fdt_size_t *size);
+fdt_addr_t ofnode_get_addr_size_index(ofnode node, int index,
+				      fdt_size_t *size);
 
 /**
  * ofnode_get_addr_size_index_notrans() - get an address/size from a node
@@ -695,8 +695,8 @@ phys_addr_t ofnode_get_addr_size_index(ofnode node, int index,
  * @size: Pointer to size of the address
  * Return: address, or FDT_ADDR_T_NONE if not present or invalid
  */
-phys_addr_t ofnode_get_addr_size_index_notrans(ofnode node, int index,
-					       fdt_size_t *size);
+fdt_addr_t ofnode_get_addr_size_index_notrans(ofnode node, int index,
+					      fdt_size_t *size);
 
 /**
  * ofnode_get_addr_index() - get an address from a node
@@ -707,7 +707,7 @@ phys_addr_t ofnode_get_addr_size_index_notrans(ofnode node, int index,
  * @index: Index of address to read (0 for first)
  * Return: address, or FDT_ADDR_T_NONE if not present or invalid
  */
-phys_addr_t ofnode_get_addr_index(ofnode node, int index);
+fdt_addr_t ofnode_get_addr_index(ofnode node, int index);
 
 /**
  * ofnode_get_addr() - get an address from a node
@@ -717,7 +717,7 @@ phys_addr_t ofnode_get_addr_index(ofnode node, int index);
  * @node: node to read from
  * Return: address, or FDT_ADDR_T_NONE if not present or invalid
  */
-phys_addr_t ofnode_get_addr(ofnode node);
+fdt_addr_t ofnode_get_addr(ofnode node);
 
 /**
  * ofnode_get_size() - get size from a node
@@ -1055,8 +1055,8 @@ const void *ofprop_get_property(const struct ofprop *prop,
  * @sizep: place to put size value (on success)
  * Return: address value, or FDT_ADDR_T_NONE on error
  */
-phys_addr_t ofnode_get_addr_size(ofnode node, const char *propname,
-				 phys_size_t *sizep);
+fdt_addr_t ofnode_get_addr_size(ofnode node, const char *propname,
+				fdt_size_t *sizep);
 
 /**
  * ofnode_read_u8_array_ptr() - find an 8-bit array

--
2.20.1

Reviewed-by on v2 2/10
#4 lore raw

Re: [PATCH v2 02/10] include: dm: ofnode: fix headers

Quoted 5 lines · Johan Jonker

When fdt_addr_t and phys_addr_t are split it turns out that the header don't match the functions, so fix the headers.

Thanks,
- Kever

Quoted 62 lines
---
  include/dm/ofnode.h | 16 ++++++++--------
  1 file changed, 8 insertions(+), 8 deletions(-)
include/dm/ofnode.h +8 -9
index fa986560..287b0c35 100644
@@ -678,8 +678,8 @@ int ofnode_read_size(ofnode node, const char *propname);
   * @size: Pointer to size of the address
   * Return: address, or FDT_ADDR_T_NONE if not present or invalid
   */
-phys_addr_t ofnode_get_addr_size_index(ofnode node, int index,
-				       fdt_size_t *size);
+fdt_addr_t ofnode_get_addr_size_index(ofnode node, int index,
+				      fdt_size_t *size);
 
  /**
   * ofnode_get_addr_size_index_notrans() - get an address/size from a node
@@ -695,8 +695,8 @@ phys_addr_t ofnode_get_addr_size_index(ofnode node, int index,
   * @size: Pointer to size of the address
   * Return: address, or FDT_ADDR_T_NONE if not present or invalid
   */
-phys_addr_t ofnode_get_addr_size_index_notrans(ofnode node, int index,
-					       fdt_size_t *size);
+fdt_addr_t ofnode_get_addr_size_index_notrans(ofnode node, int index,
+					      fdt_size_t *size);
 
  /**
   * ofnode_get_addr_index() - get an address from a node
@@ -707,7 +707,7 @@ phys_addr_t ofnode_get_addr_size_index_notrans(ofnode node, int index,
   * @index: Index of address to read (0 for first)
   * Return: address, or FDT_ADDR_T_NONE if not present or invalid
   */
-phys_addr_t ofnode_get_addr_index(ofnode node, int index);
+fdt_addr_t ofnode_get_addr_index(ofnode node, int index);
 
  /**
   * ofnode_get_addr() - get an address from a node
@@ -717,7 +717,7 @@ phys_addr_t ofnode_get_addr_index(ofnode node, int index);
   * @node: node to read from
   * Return: address, or FDT_ADDR_T_NONE if not present or invalid
   */
-phys_addr_t ofnode_get_addr(ofnode node);
+fdt_addr_t ofnode_get_addr(ofnode node);
 
  /**
   * ofnode_get_size() - get size from a node
@@ -1055,8 +1055,8 @@ const void *ofprop_get_property(const struct ofprop *prop,
   * @sizep: place to put size value (on success)
   * Return: address value, or FDT_ADDR_T_NONE on error
   */
-phys_addr_t ofnode_get_addr_size(ofnode node, const char *propname,
-				 phys_size_t *sizep);
+fdt_addr_t ofnode_get_addr_size(ofnode node, const char *propname,
+				fdt_size_t *sizep);
 
  /**
   * ofnode_read_u8_array_ptr() - find an 8-bit array
--

2.20.1

#5 lore raw

PATCH v2 3/10 core: remap: convert regmap_init_mem_plat() input to phys_addr_t

In reply to Johan Jonker

The fdt_addr_t and phys_addr_t size have been decoupled. A 32bit CPU can expect 64-bit data from the device tree parser, so convert regmap_init_mem_plat() input to phys_addr_t in files that use this function.

---
 drivers/core/regmap.c               | 2 +-
 drivers/core/syscon-uclass.c        | 2 +-
 drivers/ram/rockchip/sdram_rk3066.c | 2 +-
 drivers/ram/rockchip/sdram_rk3188.c | 2 +-
 drivers/ram/rockchip/sdram_rk322x.c | 2 +-
 drivers/ram/rockchip/sdram_rk3288.c | 2 +-
 drivers/ram/rockchip/sdram_rk3328.c | 2 +-
 drivers/ram/rockchip/sdram_rk3399.c | 2 +-
 include/regmap.h                    | 2 +-
 9 files changed, 9 insertions(+), 9 deletions(-)
drivers/core/regmap.c +1 -1
index e33bb9d7..37da64b2 100644
@@ -79,7 +79,7 @@ static struct regmap *regmap_alloc(int count)
 }
 
 #if CONFIG_IS_ENABLED(OF_PLATDATA)
-int regmap_init_mem_plat(struct udevice *dev, fdt_val_t *reg, int count,
+int regmap_init_mem_plat(struct udevice *dev, phys_addr_t *reg, int count,
 			 struct regmap **mapp)
 {
 	struct regmap_range *range;
drivers/core/syscon-uclass.c +1 -1
index 25fdb66e..69b66773 100644
@@ -58,7 +58,7 @@ static int syscon_pre_probe(struct udevice *dev)
 #if CONFIG_IS_ENABLED(OF_PLATDATA)
 	struct syscon_base_plat *plat = dev_get_plat(dev);
 
-	return regmap_init_mem_plat(dev, plat->reg, ARRAY_SIZE(plat->reg),
+	return regmap_init_mem_plat(dev, (phys_addr_t *)plat->reg, ARRAY_SIZE(plat->reg),
 					&priv->regmap);
 #else
 	return regmap_init_mem(dev_ofnode(dev), &priv->regmap);
drivers/ram/rockchip/sdram_rk3066.c +1 -1
index a2425f22..9bb26b64 100644
@@ -801,7 +801,7 @@ static int rk3066_dmc_conv_of_plat(struct udevice *dev)
 	memcpy(&plat->base, of_plat->rockchip_sdram_params, sizeof(plat->base));
 	/* RK3066 supports dual-channel, set default channel num to 2. */
 	plat->num_channels = 1;
-	ret = regmap_init_mem_plat(dev, of_plat->reg,
+	ret = regmap_init_mem_plat(dev, (phys_addr_t *)of_plat->reg,
 				   ARRAY_SIZE(of_plat->reg) / 2, &plat->map);
 	if (ret)
 		return ret;
drivers/ram/rockchip/sdram_rk3188.c +1 -1
index 272b1b2d..1838985c 100644
@@ -867,7 +867,7 @@ static int conv_of_plat(struct udevice *dev)
 	memcpy(&plat->base, of_plat->rockchip_sdram_params, sizeof(plat->base));
 	/* rk3188 supports dual-channel, set default channel num to 2 */
 	plat->num_channels = 1;
-	ret = regmap_init_mem_plat(dev, of_plat->reg,
+	ret = regmap_init_mem_plat(dev, (phys_addr_t *)of_plat->reg,
 				   ARRAY_SIZE(of_plat->reg) / 2, &plat->map);
 	if (ret)
 		return ret;
drivers/ram/rockchip/sdram_rk322x.c +1 -1
index 1b204fb5..33599dc5 100644
@@ -769,7 +769,7 @@ static int conv_of_plat(struct udevice *dev)
 	memcpy(&plat->base, of_plat->rockchip_sdram_params, sizeof(plat->base));
 
 	plat->num_channels = 1;
-	ret = regmap_init_mem_plat(dev, of_plat->reg,
+	ret = regmap_init_mem_plat(dev, (phys_addr_t *)of_plat->reg,
 				   ARRAY_SIZE(of_plat->reg) / 2, &plat->map);
 	if (ret)
 		return ret;
drivers/ram/rockchip/sdram_rk3288.c +1 -1
index 83778ad1..1a548da5 100644
@@ -1029,7 +1029,7 @@ static int conv_of_plat(struct udevice *dev)
 	memcpy(&plat->base, of_plat->rockchip_sdram_params, sizeof(plat->base));
 	/* Rk3288 supports dual-channel, set default channel num to 2 */
 	plat->num_channels = 2;
-	ret = regmap_init_mem_plat(dev, of_plat->reg,
+	ret = regmap_init_mem_plat(dev, (phys_addr_t *)of_plat->reg,
 				   ARRAY_SIZE(of_plat->reg) / 2, &plat->map);
 	if (ret)
 		return ret;
drivers/ram/rockchip/sdram_rk3328.c +1 -1
index b511c6bf..2427efe0 100644
@@ -54,7 +54,7 @@ static int conv_of_plat(struct udevice *dev)
 	struct dtd_rockchip_rk3328_dmc *dtplat = &plat->dtplat;
 	int ret;
 
-	ret = regmap_init_mem_plat(dev, dtplat->reg,
+	ret = regmap_init_mem_plat(dev, (phys_addr_t *)dtplat->reg,
 				   ARRAY_SIZE(dtplat->reg) / 2, &plat->map);
 	if (ret)
 		return ret;
drivers/ram/rockchip/sdram_rk3399.c +1 -1
index 136e4ede..c88fdbb3 100644
@@ -3049,7 +3049,7 @@ static int conv_of_plat(struct udevice *dev)
 	struct dtd_rockchip_rk3399_dmc *dtplat = &plat->dtplat;
 	int ret;
 
-	ret = regmap_init_mem_plat(dev, dtplat->reg,
+	ret = regmap_init_mem_plat(dev, (phys_addr_t *)dtplat->reg,
 				   ARRAY_SIZE(dtplat->reg) / 2, &plat->map);
 	if (ret)
 		return ret;
include/regmap.h +1 -1
index e81a3602..a274fb27 100644
@@ -388,7 +388,7 @@ int regmap_init_mem(ofnode node, struct regmap **mapp);
  * Use regmap_uninit() to free it.
  *
  */
-int regmap_init_mem_plat(struct udevice *dev, fdt_val_t *reg, int count,
+int regmap_init_mem_plat(struct udevice *dev, phys_addr_t *reg, int count,
 			 struct regmap **mapp);
 
 int regmap_init_mem_index(ofnode node, struct regmap **mapp, int index);

--
2.20.1

Reviewed-by on v2 3/10
#6 lore raw

Re: [PATCH v2 03/10] core: remap: convert regmap_init_mem_plat() input to phys_addr_t

Quoted 6 lines · Johan Jonker

The fdt_addr_t and phys_addr_t size have been decoupled. A 32bit CPU can expect 64-bit data from the device tree parser, so convert regmap_init_mem_plat() input to phys_addr_t in files that use this function.

Thanks,
- Kever

Quoted 132 lines
---
  drivers/core/regmap.c               | 2 +-
  drivers/core/syscon-uclass.c        | 2 +-
  drivers/ram/rockchip/sdram_rk3066.c | 2 +-
  drivers/ram/rockchip/sdram_rk3188.c | 2 +-
  drivers/ram/rockchip/sdram_rk322x.c | 2 +-
  drivers/ram/rockchip/sdram_rk3288.c | 2 +-
  drivers/ram/rockchip/sdram_rk3328.c | 2 +-
  drivers/ram/rockchip/sdram_rk3399.c | 2 +-
  include/regmap.h                    | 2 +-
  9 files changed, 9 insertions(+), 9 deletions(-)
drivers/core/regmap.c +1 -1
index e33bb9d7..37da64b2 100644
@@ -79,7 +79,7 @@ static struct regmap *regmap_alloc(int count)
  }
 
  #if CONFIG_IS_ENABLED(OF_PLATDATA)
-int regmap_init_mem_plat(struct udevice *dev, fdt_val_t *reg, int count,
+int regmap_init_mem_plat(struct udevice *dev, phys_addr_t *reg, int count,
  			 struct regmap **mapp)
  {
  	struct regmap_range *range;
drivers/core/syscon-uclass.c +1 -1
index 25fdb66e..69b66773 100644
@@ -58,7 +58,7 @@ static int syscon_pre_probe(struct udevice *dev)
  #if CONFIG_IS_ENABLED(OF_PLATDATA)
  	struct syscon_base_plat *plat = dev_get_plat(dev);
 
-	return regmap_init_mem_plat(dev, plat->reg, ARRAY_SIZE(plat->reg),
+	return regmap_init_mem_plat(dev, (phys_addr_t *)plat->reg, ARRAY_SIZE(plat->reg),
  					&priv->regmap);
  #else
  	return regmap_init_mem(dev_ofnode(dev), &priv->regmap);
drivers/ram/rockchip/sdram_rk3066.c +1 -1
index a2425f22..9bb26b64 100644
@@ -801,7 +801,7 @@ static int rk3066_dmc_conv_of_plat(struct udevice *dev)
  	memcpy(&plat->base, of_plat->rockchip_sdram_params, sizeof(plat->base));
  	/* RK3066 supports dual-channel, set default channel num to 2. */
  	plat->num_channels = 1;
-	ret = regmap_init_mem_plat(dev, of_plat->reg,
+	ret = regmap_init_mem_plat(dev, (phys_addr_t *)of_plat->reg,
  				   ARRAY_SIZE(of_plat->reg) / 2, &plat->map);
  	if (ret)
  		return ret;
drivers/ram/rockchip/sdram_rk3188.c +1 -1
index 272b1b2d..1838985c 100644
@@ -867,7 +867,7 @@ static int conv_of_plat(struct udevice *dev)
  	memcpy(&plat->base, of_plat->rockchip_sdram_params, sizeof(plat->base));
  	/* rk3188 supports dual-channel, set default channel num to 2 */
  	plat->num_channels = 1;
-	ret = regmap_init_mem_plat(dev, of_plat->reg,
+	ret = regmap_init_mem_plat(dev, (phys_addr_t *)of_plat->reg,
  				   ARRAY_SIZE(of_plat->reg) / 2, &plat->map);
  	if (ret)
  		return ret;
drivers/ram/rockchip/sdram_rk322x.c +1 -1
index 1b204fb5..33599dc5 100644
@@ -769,7 +769,7 @@ static int conv_of_plat(struct udevice *dev)
  	memcpy(&plat->base, of_plat->rockchip_sdram_params, sizeof(plat->base));
 
  	plat->num_channels = 1;
-	ret = regmap_init_mem_plat(dev, of_plat->reg,
+	ret = regmap_init_mem_plat(dev, (phys_addr_t *)of_plat->reg,
  				   ARRAY_SIZE(of_plat->reg) / 2, &plat->map);
  	if (ret)
  		return ret;
drivers/ram/rockchip/sdram_rk3288.c +1 -1
index 83778ad1..1a548da5 100644
@@ -1029,7 +1029,7 @@ static int conv_of_plat(struct udevice *dev)
  	memcpy(&plat->base, of_plat->rockchip_sdram_params, sizeof(plat->base));
  	/* Rk3288 supports dual-channel, set default channel num to 2 */
  	plat->num_channels = 2;
-	ret = regmap_init_mem_plat(dev, of_plat->reg,
+	ret = regmap_init_mem_plat(dev, (phys_addr_t *)of_plat->reg,
  				   ARRAY_SIZE(of_plat->reg) / 2, &plat->map);
  	if (ret)
  		return ret;
drivers/ram/rockchip/sdram_rk3328.c +1 -1
index b511c6bf..2427efe0 100644
@@ -54,7 +54,7 @@ static int conv_of_plat(struct udevice *dev)
  	struct dtd_rockchip_rk3328_dmc *dtplat = &plat->dtplat;
  	int ret;
 
-	ret = regmap_init_mem_plat(dev, dtplat->reg,
+	ret = regmap_init_mem_plat(dev, (phys_addr_t *)dtplat->reg,
  				   ARRAY_SIZE(dtplat->reg) / 2, &plat->map);
  	if (ret)
  		return ret;
drivers/ram/rockchip/sdram_rk3399.c +1 -1
index 136e4ede..c88fdbb3 100644
@@ -3049,7 +3049,7 @@ static int conv_of_plat(struct udevice *dev)
  	struct dtd_rockchip_rk3399_dmc *dtplat = &plat->dtplat;
  	int ret;
 
-	ret = regmap_init_mem_plat(dev, dtplat->reg,
+	ret = regmap_init_mem_plat(dev, (phys_addr_t *)dtplat->reg,
  				   ARRAY_SIZE(dtplat->reg) / 2, &plat->map);
  	if (ret)
  		return ret;
include/regmap.h +1 -2
index e81a3602..a274fb27 100644
@@ -388,7 +388,7 @@ int regmap_init_mem(ofnode node, struct regmap **mapp);
   * Use regmap_uninit() to free it.
   *
   */
-int regmap_init_mem_plat(struct udevice *dev, fdt_val_t *reg, int count,
+int regmap_init_mem_plat(struct udevice *dev, phys_addr_t *reg, int count,
  			 struct regmap **mapp);
 
  int regmap_init_mem_index(ofnode node, struct regmap **mapp, int index);
--

2.20.1

#7 lore raw

PATCH v2 4/10 rockchip: adc: rockchip-saradc: convert dev_read_addr output to phys_addr_t

In reply to Johan Jonker

The fdt_addr_t and phys_addr_t size have been decoupled. A 32bit CPU can expext 64-bit data from the device tree parser, so convert dev_read_addr output to phys_addr_t in the rockchip-saradc.c file.

---
 drivers/adc/rockchip-saradc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/adc/rockchip-saradc.c +1 -1
index 760f8fe6..1ba7c483 100644
@@ -145,7 +145,7 @@ int rockchip_saradc_of_to_plat(struct udevice *dev)
 	struct rockchip_saradc_data *data;
 
 	data = (struct rockchip_saradc_data *)dev_get_driver_data(dev);
-	priv->regs = (struct rockchip_saradc_regs *)dev_read_addr(dev);
+	priv->regs = (struct rockchip_saradc_regs *)((phys_addr_t)dev_read_addr(dev));
 	if (priv->regs == (struct rockchip_saradc_regs *)FDT_ADDR_T_NONE) {
 		pr_err("Dev: %s - can't get address!", dev->name);
 		return -ENODATA;

--
2.20.1

Reviewed-by on v2 4/10
#8 lore raw

Re: [PATCH v2 04/10] rockchip: adc: rockchip-saradc: convert dev_read_addr output to phys_addr_t

Quoted 6 lines · Johan Jonker

The fdt_addr_t and phys_addr_t size have been decoupled. A 32bit CPU can expext 64-bit data from the device tree parser, so convert dev_read_addr output to phys_addr_t in the rockchip-saradc.c file.

Thanks,
- Kever

Quoted 20 lines
---
  drivers/adc/rockchip-saradc.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/adc/rockchip-saradc.c +1 -2
index 760f8fe6..1ba7c483 100644
@@ -145,7 +145,7 @@ int rockchip_saradc_of_to_plat(struct udevice *dev)
  	struct rockchip_saradc_data *data;
 
  	data = (struct rockchip_saradc_data *)dev_get_driver_data(dev);
-	priv->regs = (struct rockchip_saradc_regs *)dev_read_addr(dev);
+	priv->regs = (struct rockchip_saradc_regs *)((phys_addr_t)dev_read_addr(dev));
  	if (priv->regs == (struct rockchip_saradc_regs *)FDT_ADDR_T_NONE) {
  		pr_err("Dev: %s - can't get address!", dev->name);
  		return -ENODATA;
--

2.20.1

#9 lore raw

PATCH v2 5/10 rockchip: timer: dw-apb-timer: convert dev_read_addr output to phys_addr_t

In reply to Johan Jonker

The fdt_addr_t and phys_addr_t size have been decoupled. A 32bit CPU can expect 64-bit data from the device tree parser, so convert dev_read_addr output to phys_addr_t in the dw-apb-timer.c file.

---
 drivers/timer/dw-apb-timer.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/timer/dw-apb-timer.c +2 -2
index 10f0a9f6..f55a3c54 100644
@@ -23,7 +23,7 @@
 #define DW_APB_CTRL		0x8
 
 struct dw_apb_timer_priv {
-	fdt_addr_t regs;
+	phys_addr_t regs;
 	struct reset_ctl_bulk resets;
 };
 
@@ -92,7 +92,7 @@ static int dw_apb_timer_of_to_plat(struct udevice *dev)
 	if (CONFIG_IS_ENABLED(OF_REAL)) {
 		struct dw_apb_timer_priv *priv = dev_get_priv(dev);
 
-		priv->regs = dev_read_addr(dev);
+		priv->regs = (phys_addr_t)dev_read_addr(dev);
 	}
 
 	return 0;

--
2.20.1

Reviewed-by on v2 5/10
#10 lore raw

Re: [PATCH v2 05/10] rockchip: timer: dw-apb-timer: convert dev_read_addr output to phys_addr_t

Quoted 6 lines · Johan Jonker

The fdt_addr_t and phys_addr_t size have been decoupled. A 32bit CPU can expect 64-bit data from the device tree parser, so convert dev_read_addr output to phys_addr_t in the dw-apb-timer.c file.

Thanks,
- Kever

Quoted 29 lines
---
  drivers/timer/dw-apb-timer.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
drivers/timer/dw-apb-timer.c +2 -3
index 10f0a9f6..f55a3c54 100644
@@ -23,7 +23,7 @@
  #define DW_APB_CTRL		0x8
 
  struct dw_apb_timer_priv {
-	fdt_addr_t regs;
+	phys_addr_t regs;
  	struct reset_ctl_bulk resets;
  };
 
@@ -92,7 +92,7 @@ static int dw_apb_timer_of_to_plat(struct udevice *dev)
  	if (CONFIG_IS_ENABLED(OF_REAL)) {
  		struct dw_apb_timer_priv *priv = dev_get_priv(dev);
 
-		priv->regs = dev_read_addr(dev);
+		priv->regs = (phys_addr_t)dev_read_addr(dev);
  	}
 
  	return 0;
--

2.20.1

#11 lore raw

PATCH v2 6/10 rockchip: mtd: raw: rockchip_nfc convert dev_read_addr output to phys_addr_t

In reply to Johan Jonker

The fdt_addr_t and phys_addr_t size have been decoupled. A 32bit CPU can expext 64-bit data from the device tree parser, so convert dev_read_addr output to phys_addr_t in the rockchip_nfc.c file.

---
 drivers/mtd/nand/raw/rockchip_nfc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mtd/nand/raw/rockchip_nfc.c +1 -1
index d016d255..78e2a691 100644
@@ -1180,7 +1180,7 @@ static int rk_nfc_probe(struct udevice *dev)
 	nfc->cfg = (void *)dev_get_driver_data(dev);
 	nfc->dev = dev;
 
-	nfc->regs = (void *)dev_read_addr(dev);
+	nfc->regs = (void *)((phys_addr_t)dev_read_addr(dev));
 	if (IS_ERR(nfc->regs)) {
 		ret = PTR_ERR(nfc->regs);
 		goto release_nfc;

--
2.20.1

#12 lore raw

Re: [PATCH v2 06/10] rockchip: mtd: raw: rockchip_nfc convert dev_read_addr output to phys_addr_t

Hi Johan

Quoted 16 lines · Johan Jonker

The fdt_addr_t and phys_addr_t size have been decoupled. A 32bit CPU can expext 64-bit data from the device tree parser, so convert dev_read_addr output to phys_addr_t in the rockchip_nfc.c file.

---
 drivers/mtd/nand/raw/rockchip_nfc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mtd/nand/raw/rockchip_nfc.c +0 -0
index d016d255..78e2a691 100644

drivers/mtd/nand/raw/rockchip_nfc.c static int rk_nfc_probe(struct udevice *dev) · line 1183

Quoted 5 lines
drivers/mtd/nand/raw/rockchip_nfc.c +1 -1
@@ -1180,7 +1180,7 @@ static int rk_nfc_probe(struct udevice *dev)
        nfc->cfg = (void *)dev_get_driver_data(dev);
        nfc->dev = dev;
 
-       nfc->regs = (void *)dev_read_addr(dev);
+       nfc->regs = (void *)((phys_addr_t)dev_read_addr(dev));

Is phy_read_addr_ptr() family supposed to be used in this case?

Michael

Quoted 6 lines
drivers/mtd/nand/raw/rockchip_nfc.c +0 -1
        if (IS_ERR(nfc->regs)) {
                ret = PTR_ERR(nfc->regs);
                goto release_nfc;
--

2.20.1

Signature · 11 lines
Michael Nazzareno Trimarchi
Co-Founder & Chief Executive Officer
M. +39 347 913 2170
[email protected]
__________________________________

Amarula Solutions BV
Joop Geesinkweg 125, 1114 AB, Amsterdam, NL
T. +31 (0)85 111 9172
[email protected]
www.amarulasolutions.com
Reviewed-by on v2 6/10
#13 lore raw

Re: [PATCH v2 06/10] rockchip: mtd: raw: rockchip_nfc convert dev_read_addr output to phys_addr_t

In reply to Johan Jonker
Quoted 6 lines · Johan Jonker

The fdt_addr_t and phys_addr_t size have been decoupled. A 32bit CPU can expext 64-bit data from the device tree parser, so convert dev_read_addr output to phys_addr_t in the rockchip_nfc.c file.

Thanks,
- Kever

Quoted 20 lines
---
  drivers/mtd/nand/raw/rockchip_nfc.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mtd/nand/raw/rockchip_nfc.c +1 -2
index d016d255..78e2a691 100644
@@ -1180,7 +1180,7 @@ static int rk_nfc_probe(struct udevice *dev)
  	nfc->cfg = (void *)dev_get_driver_data(dev);
  	nfc->dev = dev;
 
-	nfc->regs = (void *)dev_read_addr(dev);
+	nfc->regs = (void *)((phys_addr_t)dev_read_addr(dev));
  	if (IS_ERR(nfc->regs)) {
  		ret = PTR_ERR(nfc->regs);
  		goto release_nfc;
--

2.20.1

#14 lore raw

PATCH v2 7/10 mtd: nand: raw: rockchip_nfc: remove the compatible string "rockchip,rk3308-nfc"

In reply to Johan Jonker

The compatible string for rk3308 has as fallback string "rockchip,rv1108-nfc". As there is no logic in probe priority between the SoC orientated string and the fall back, so remove the compatible string "rockchip,rk3308-nfc" from the driver.

---
 drivers/mtd/nand/raw/rockchip_nfc.c | 4 ----
 1 file changed, 4 deletions(-)
drivers/mtd/nand/raw/rockchip_nfc.c +0 -4
index 78e2a691..3809702e 100644
@@ -1165,10 +1165,6 @@ static const struct udevice_id rk_nfc_id_table[] = {
 		.compatible = "rockchip,rv1108-nfc",
 		.data = (unsigned long)&nfc_v8_cfg
 	},
-	{
-		.compatible = "rockchip,rk3308-nfc",
-		.data = (unsigned long)&nfc_v8_cfg
-	},
 	{ /* sentinel */ }
 };
 

--
2.20.1

Reviewed-by on v2 7/10
#15 lore raw

Re: [PATCH v2 07/10] mtd: nand: raw: rockchip_nfc: remove the compatible string "rockchip,rk3308-nfc"

Hi Johan

Quoted 16 lines · Johan Jonker

The compatible string for rk3308 has as fallback string "rockchip,rv1108-nfc". As there is no logic in probe priority between the SoC orientated string and the fall back, so remove the compatible string "rockchip,rk3308-nfc" from the driver.

---
 drivers/mtd/nand/raw/rockchip_nfc.c | 4 ----
 1 file changed, 4 deletions(-)
drivers/mtd/nand/raw/rockchip_nfc.c +0 -0
index 78e2a691..3809702e 100644

drivers/mtd/nand/raw/rockchip_nfc.c static const struct udevice_id rk_nfc_id_table[] = { · line 1171

Quoted 7 lines
drivers/mtd/nand/raw/rockchip_nfc.c +0 -4
@@ -1165,10 +1165,6 @@ static const struct udevice_id rk_nfc_id_table[] = {
                .compatible = "rockchip,rv1108-nfc",
                .data = (unsigned long)&nfc_v8_cfg
        },
-       {
-               .compatible = "rockchip,rk3308-nfc",
-               .data = (unsigned long)&nfc_v8_cfg
-       },

Ok, same on linux

Quoted 6 lines
drivers/mtd/nand/raw/rockchip_nfc.c +0 -1
        { /* sentinel */ }
 };
 
--

2.20.1

Signature · 11 lines
Michael Nazzareno Trimarchi
Co-Founder & Chief Executive Officer
M. +39 347 913 2170
[email protected]
__________________________________

Amarula Solutions BV
Joop Geesinkweg 125, 1114 AB, Amsterdam, NL
T. +31 (0)85 111 9172
[email protected]
www.amarulasolutions.com
Reviewed-by on v2 7/10
#16 lore raw

Re: [PATCH v2 07/10] mtd: nand: raw: rockchip_nfc: remove the compatible string "rockchip,rk3308-nfc"

In reply to Johan Jonker
Quoted 6 lines · Johan Jonker

The compatible string for rk3308 has as fallback string "rockchip,rv1108-nfc". As there is no logic in probe priority between the SoC orientated string and the fall back, so remove the compatible string "rockchip,rk3308-nfc" from the driver.

Thanks,
- Kever

Quoted 22 lines
---
  drivers/mtd/nand/raw/rockchip_nfc.c | 4 ----
  1 file changed, 4 deletions(-)
drivers/mtd/nand/raw/rockchip_nfc.c +0 -5
index 78e2a691..3809702e 100644
@@ -1165,10 +1165,6 @@ static const struct udevice_id rk_nfc_id_table[] = {
  		.compatible = "rockchip,rv1108-nfc",
  		.data = (unsigned long)&nfc_v8_cfg
  	},
-	{
-		.compatible = "rockchip,rk3308-nfc",
-		.data = (unsigned long)&nfc_v8_cfg
-	},
  	{ /* sentinel */ }
  };
 
--

2.20.1

#17 lore raw

PATCH v2 8/10 mtd: nand: raw: rockchip_nfc: add layout structure

In reply to Johan Jonker

The MTD framework in U-boot is not identical for drivers ported from Linux. The rockchip_nfc driver was ported with OOB ops functions while the framework expects a layout structure per chip. Fix by adding a structure with OOB data and remove unused functions.

---
 drivers/mtd/nand/raw/rockchip_nfc.c | 61 ++++++++++-------------------
 1 file changed, 20 insertions(+), 41 deletions(-)
drivers/mtd/nand/raw/rockchip_nfc.c +20 -41
index 3809702e..5e2b8346 100644
@@ -814,47 +814,9 @@ static void rk_nfc_disable_clks(struct rk_nfc *nfc)
 	clk_disable_unprepare(nfc->ahb_clk);
 }
 
-static int rk_nfc_ooblayout_free(struct mtd_info *mtd, int section,
-				 struct mtd_oob_region *oob_region)
-{
-	struct nand_chip *chip = mtd_to_nand(mtd);
-	struct rk_nfc_nand_chip *rknand = rk_nfc_to_rknand(chip);
-
-	if (section)
-		return -ERANGE;
-
-	/*
-	 * The beginning of the OOB area stores the reserved data for the NFC,
-	 * the size of the reserved data is NFC_SYS_DATA_SIZE bytes.
-	 */
-	oob_region->length = rknand->metadata_size - NFC_SYS_DATA_SIZE - 2;
-	oob_region->offset = NFC_SYS_DATA_SIZE + 2;
-
-	return 0;
-}
-
-static int rk_nfc_ooblayout_ecc(struct mtd_info *mtd, int section,
-				struct mtd_oob_region *oob_region)
-{
-	struct nand_chip *chip = mtd_to_nand(mtd);
-	struct rk_nfc_nand_chip *rknand = rk_nfc_to_rknand(chip);
-
-	if (section)
-		return -ERANGE;
-
-	oob_region->length = mtd->oobsize - rknand->metadata_size;
-	oob_region->offset = rknand->metadata_size;
-
-	return 0;
-}
-
-static const struct mtd_ooblayout_ops rk_nfc_ooblayout_ops = {
-	.rfree = rk_nfc_ooblayout_free,
-	.ecc = rk_nfc_ooblayout_ecc,
-};
-
 static int rk_nfc_ecc_init(struct rk_nfc *nfc, struct nand_chip *chip)
 {
+	struct rk_nfc_nand_chip *rknand = rk_nfc_to_rknand(chip);
 	const u8 *strengths = nfc->cfg->ecc_strengths;
 	struct mtd_info *mtd = nand_to_mtd(chip);
 	struct nand_ecc_ctrl *ecc = &chip->ecc;
@@ -892,6 +854,21 @@ static int rk_nfc_ecc_init(struct rk_nfc *nfc, struct nand_chip *chip)
 	ecc->steps = mtd->writesize / ecc->size;
 	ecc->bytes = DIV_ROUND_UP(ecc->strength * fls(8 * chip->ecc.size), 8);
 
+	if (ecc->bytes * ecc->steps > mtd->oobsize - rknand->metadata_size)
+		return -EINVAL;
+
+	ecc->layout = kzalloc(sizeof(*ecc->layout), GFP_KERNEL);
+	if (!ecc->layout)
+		return -ENOMEM;
+
+	ecc->layout->eccbytes = ecc->bytes * ecc->steps;
+
+	for (i = 0; i < ecc->layout->eccbytes; i++)
+		ecc->layout->eccpos[i] = rknand->metadata_size + i;
+
+	ecc->layout->oobfree[0].length = rknand->metadata_size - NFC_SYS_DATA_SIZE - 2;
+	ecc->layout->oobfree[0].offset = NFC_SYS_DATA_SIZE + 2;
+
 	return 0;
 }
 
@@ -969,7 +946,6 @@ static int rk_nfc_nand_chip_init(ofnode node, struct rk_nfc *nfc, int devnum)
 	chip->bbt_options = NAND_BBT_USE_FLASH | NAND_BBT_NO_OOB;
 	chip->options |= NAND_NO_SUBPAGE_WRITE | NAND_USE_BOUNCE_BUFFER;
 
-	mtd_set_ooblayout(mtd, &rk_nfc_ooblayout_ops);
 	rk_nfc_hw_init(nfc);
 	ret = nand_scan_ident(mtd, nsels, NULL);
 	if (ret)
@@ -998,13 +974,16 @@ static int rk_nfc_nand_chip_init(ofnode node, struct rk_nfc *nfc, int devnum)
 
 	if (!nfc->page_buf) {
 		nfc->page_buf = kzalloc(NFC_MAX_PAGE_SIZE, GFP_KERNEL);
-		if (!nfc->page_buf)
+		if (!nfc->page_buf) {
+			kfree(ecc->layout);
 			return -ENOMEM;
+		}
 	}
 
 	if (!nfc->oob_buf) {
 		nfc->oob_buf = kzalloc(NFC_MAX_OOB_SIZE, GFP_KERNEL);
 		if (!nfc->oob_buf) {
+			kfree(ecc->layout);
 			kfree(nfc->page_buf);
 			nfc->page_buf = NULL;
 			return -ENOMEM;

--
2.20.1

Reviewed-by on v2 8/10
#18 lore raw

Re: [PATCH v2 08/10] mtd: nand: raw: rockchip_nfc: add layout structure

Hi

Quoted 113 lines · Johan Jonker

The MTD framework in U-boot is not identical for drivers ported from Linux. The rockchip_nfc driver was ported with OOB ops functions while the framework expects a layout structure per chip. Fix by adding a structure with OOB data and remove unused functions.

---
 drivers/mtd/nand/raw/rockchip_nfc.c | 61 ++++++++++-------------------
 1 file changed, 20 insertions(+), 41 deletions(-)
drivers/mtd/nand/raw/rockchip_nfc.c +20 -42
index 3809702e..5e2b8346 100644
@@ -814,47 +814,9 @@ static void rk_nfc_disable_clks(struct rk_nfc *nfc)
        clk_disable_unprepare(nfc->ahb_clk);
 }
 
-static int rk_nfc_ooblayout_free(struct mtd_info *mtd, int section,
-                                struct mtd_oob_region *oob_region)
-{
-       struct nand_chip *chip = mtd_to_nand(mtd);
-       struct rk_nfc_nand_chip *rknand = rk_nfc_to_rknand(chip);
-
-       if (section)
-               return -ERANGE;
-
-       /*
-        * The beginning of the OOB area stores the reserved data for the NFC,
-        * the size of the reserved data is NFC_SYS_DATA_SIZE bytes.
-        */
-       oob_region->length = rknand->metadata_size - NFC_SYS_DATA_SIZE - 2;
-       oob_region->offset = NFC_SYS_DATA_SIZE + 2;
-
-       return 0;
-}
-
-static int rk_nfc_ooblayout_ecc(struct mtd_info *mtd, int section,
-                               struct mtd_oob_region *oob_region)
-{
-       struct nand_chip *chip = mtd_to_nand(mtd);
-       struct rk_nfc_nand_chip *rknand = rk_nfc_to_rknand(chip);
-
-       if (section)
-               return -ERANGE;
-
-       oob_region->length = mtd->oobsize - rknand->metadata_size;
-       oob_region->offset = rknand->metadata_size;
-
-       return 0;
-}
-
-static const struct mtd_ooblayout_ops rk_nfc_ooblayout_ops = {
-       .rfree = rk_nfc_ooblayout_free,
-       .ecc = rk_nfc_ooblayout_ecc,
-};
-
 static int rk_nfc_ecc_init(struct rk_nfc *nfc, struct nand_chip *chip)
 {
+       struct rk_nfc_nand_chip *rknand = rk_nfc_to_rknand(chip);
        const u8 *strengths = nfc->cfg->ecc_strengths;
        struct mtd_info *mtd = nand_to_mtd(chip);
        struct nand_ecc_ctrl *ecc = &chip->ecc;
@@ -892,6 +854,21 @@ static int rk_nfc_ecc_init(struct rk_nfc *nfc, struct nand_chip *chip)
        ecc->steps = mtd->writesize / ecc->size;
        ecc->bytes = DIV_ROUND_UP(ecc->strength * fls(8 * chip->ecc.size), 8);
 
+       if (ecc->bytes * ecc->steps > mtd->oobsize - rknand->metadata_size)
+               return -EINVAL;
+
+       ecc->layout = kzalloc(sizeof(*ecc->layout), GFP_KERNEL);
+       if (!ecc->layout)
+               return -ENOMEM;
+
+       ecc->layout->eccbytes = ecc->bytes * ecc->steps;
+
+       for (i = 0; i < ecc->layout->eccbytes; i++)
+               ecc->layout->eccpos[i] = rknand->metadata_size + i;
+
+       ecc->layout->oobfree[0].length = rknand->metadata_size - NFC_SYS_DATA_SIZE - 2;
+       ecc->layout->oobfree[0].offset = NFC_SYS_DATA_SIZE + 2;
+
        return 0;
 }
 
@@ -969,7 +946,6 @@ static int rk_nfc_nand_chip_init(ofnode node, struct rk_nfc *nfc, int devnum)
        chip->bbt_options = NAND_BBT_USE_FLASH | NAND_BBT_NO_OOB;
        chip->options |= NAND_NO_SUBPAGE_WRITE | NAND_USE_BOUNCE_BUFFER;
 
-       mtd_set_ooblayout(mtd, &rk_nfc_ooblayout_ops);
        rk_nfc_hw_init(nfc);
        ret = nand_scan_ident(mtd, nsels, NULL);
        if (ret)
@@ -998,13 +974,16 @@ static int rk_nfc_nand_chip_init(ofnode node, struct rk_nfc *nfc, int devnum)
 
        if (!nfc->page_buf) {
                nfc->page_buf = kzalloc(NFC_MAX_PAGE_SIZE, GFP_KERNEL);
-               if (!nfc->page_buf)
+               if (!nfc->page_buf) {
+                       kfree(ecc->layout);
                        return -ENOMEM;
+               }
        }
 
        if (!nfc->oob_buf) {
                nfc->oob_buf = kzalloc(NFC_MAX_OOB_SIZE, GFP_KERNEL);
                if (!nfc->oob_buf) {
+                       kfree(ecc->layout);
                        kfree(nfc->page_buf);
                        nfc->page_buf = NULL;
                        return -ENOMEM;
--
Quoted 2 lines

2.20.1

Signature · 11 lines
Michael Nazzareno Trimarchi
Co-Founder & Chief Executive Officer
M. +39 347 913 2170
[email protected]
__________________________________

Amarula Solutions BV
Joop Geesinkweg 125, 1114 AB, Amsterdam, NL
T. +31 (0)85 111 9172
[email protected]
www.amarulasolutions.com
Reviewed-by on v2 8/10
#19 lore raw

Re: [PATCH v2 08/10] mtd: nand: raw: rockchip_nfc: add layout structure

In reply to Johan Jonker
Quoted 6 lines · Johan Jonker

The MTD framework in U-boot is not identical for drivers ported from Linux. The rockchip_nfc driver was ported with OOB ops functions while the framework expects a layout structure per chip. Fix by adding a structure with OOB data and remove unused functions.

Thanks,
- Kever

Quoted 108 lines
---
  drivers/mtd/nand/raw/rockchip_nfc.c | 61 ++++++++++-------------------
  1 file changed, 20 insertions(+), 41 deletions(-)
drivers/mtd/nand/raw/rockchip_nfc.c +20 -42
index 3809702e..5e2b8346 100644
@@ -814,47 +814,9 @@ static void rk_nfc_disable_clks(struct rk_nfc *nfc)
  	clk_disable_unprepare(nfc->ahb_clk);
  }
 
-static int rk_nfc_ooblayout_free(struct mtd_info *mtd, int section,
-				 struct mtd_oob_region *oob_region)
-{
-	struct nand_chip *chip = mtd_to_nand(mtd);
-	struct rk_nfc_nand_chip *rknand = rk_nfc_to_rknand(chip);
-
-	if (section)
-		return -ERANGE;
-
-	/*
-	 * The beginning of the OOB area stores the reserved data for the NFC,
-	 * the size of the reserved data is NFC_SYS_DATA_SIZE bytes.
-	 */
-	oob_region->length = rknand->metadata_size - NFC_SYS_DATA_SIZE - 2;
-	oob_region->offset = NFC_SYS_DATA_SIZE + 2;
-
-	return 0;
-}
-
-static int rk_nfc_ooblayout_ecc(struct mtd_info *mtd, int section,
-				struct mtd_oob_region *oob_region)
-{
-	struct nand_chip *chip = mtd_to_nand(mtd);
-	struct rk_nfc_nand_chip *rknand = rk_nfc_to_rknand(chip);
-
-	if (section)
-		return -ERANGE;
-
-	oob_region->length = mtd->oobsize - rknand->metadata_size;
-	oob_region->offset = rknand->metadata_size;
-
-	return 0;
-}
-
-static const struct mtd_ooblayout_ops rk_nfc_ooblayout_ops = {
-	.rfree = rk_nfc_ooblayout_free,
-	.ecc = rk_nfc_ooblayout_ecc,
-};
-
  static int rk_nfc_ecc_init(struct rk_nfc *nfc, struct nand_chip *chip)
  {
+	struct rk_nfc_nand_chip *rknand = rk_nfc_to_rknand(chip);
  	const u8 *strengths = nfc->cfg->ecc_strengths;
  	struct mtd_info *mtd = nand_to_mtd(chip);
  	struct nand_ecc_ctrl *ecc = &chip->ecc;
@@ -892,6 +854,21 @@ static int rk_nfc_ecc_init(struct rk_nfc *nfc, struct nand_chip *chip)
  	ecc->steps = mtd->writesize / ecc->size;
  	ecc->bytes = DIV_ROUND_UP(ecc->strength * fls(8 * chip->ecc.size), 8);
 
+	if (ecc->bytes * ecc->steps > mtd->oobsize - rknand->metadata_size)
+		return -EINVAL;
+
+	ecc->layout = kzalloc(sizeof(*ecc->layout), GFP_KERNEL);
+	if (!ecc->layout)
+		return -ENOMEM;
+
+	ecc->layout->eccbytes = ecc->bytes * ecc->steps;
+
+	for (i = 0; i < ecc->layout->eccbytes; i++)
+		ecc->layout->eccpos[i] = rknand->metadata_size + i;
+
+	ecc->layout->oobfree[0].length = rknand->metadata_size - NFC_SYS_DATA_SIZE - 2;
+	ecc->layout->oobfree[0].offset = NFC_SYS_DATA_SIZE + 2;
+
  	return 0;
  }
 
@@ -969,7 +946,6 @@ static int rk_nfc_nand_chip_init(ofnode node, struct rk_nfc *nfc, int devnum)
  	chip->bbt_options = NAND_BBT_USE_FLASH | NAND_BBT_NO_OOB;
  	chip->options |= NAND_NO_SUBPAGE_WRITE | NAND_USE_BOUNCE_BUFFER;
 
-	mtd_set_ooblayout(mtd, &rk_nfc_ooblayout_ops);
  	rk_nfc_hw_init(nfc);
  	ret = nand_scan_ident(mtd, nsels, NULL);
  	if (ret)
@@ -998,13 +974,16 @@ static int rk_nfc_nand_chip_init(ofnode node, struct rk_nfc *nfc, int devnum)
 
  	if (!nfc->page_buf) {
  		nfc->page_buf = kzalloc(NFC_MAX_PAGE_SIZE, GFP_KERNEL);
-		if (!nfc->page_buf)
+		if (!nfc->page_buf) {
+			kfree(ecc->layout);
  			return -ENOMEM;
+		}
  	}
 
  	if (!nfc->oob_buf) {
  		nfc->oob_buf = kzalloc(NFC_MAX_OOB_SIZE, GFP_KERNEL);
  		if (!nfc->oob_buf) {
+			kfree(ecc->layout);
  			kfree(nfc->page_buf);
  			nfc->page_buf = NULL;
  			return -ENOMEM;
--

2.20.1

#20 lore raw

PATCH v2 9/10 mtd: nand: raw: rockchip_nfc: add flash_node to chip stucture

In reply to Johan Jonker

Add flash_node to the rockchip_nfc driver chip stucture in order to find the partitions in the add_mtd_partitions_of() functions.

---
 drivers/mtd/nand/raw/rockchip_nfc.c | 1 +
 1 file changed, 1 insertion(+)
drivers/mtd/nand/raw/rockchip_nfc.c +1 -0
index 5e2b8346..9e3a2533 100644
@@ -934,6 +934,7 @@ static int rk_nfc_nand_chip_init(ofnode node, struct rk_nfc *nfc, int devnum)
 
 	nand_set_controller_data(chip, nfc);
 
+	chip->flash_node = node;
 	chip->chip_delay = NFC_RB_DELAY_US;
 	chip->select_chip = rk_nfc_select_chip;
 	chip->cmd_ctrl = rk_nfc_cmd;

--
2.20.1

Reviewed-by on v2 9/10
#21 lore raw

Re: [PATCH v2 09/10] mtd: nand: raw: rockchip_nfc: add flash_node to chip stucture

Hi

Quoted 22 lines · Johan Jonker

Add flash_node to the rockchip_nfc driver chip stucture in order to find the partitions in the add_mtd_partitions_of() functions.

---
 drivers/mtd/nand/raw/rockchip_nfc.c | 1 +
 1 file changed, 1 insertion(+)
drivers/mtd/nand/raw/rockchip_nfc.c +1 -1
index 5e2b8346..9e3a2533 100644
@@ -934,6 +934,7 @@ static int rk_nfc_nand_chip_init(ofnode node, struct rk_nfc *nfc, int devnum)
 
        nand_set_controller_data(chip, nfc);
 
+       chip->flash_node = node;
        chip->chip_delay = NFC_RB_DELAY_US;
        chip->select_chip = rk_nfc_select_chip;
        chip->cmd_ctrl = rk_nfc_cmd;
--
Quoted 2 lines

2.20.1

Signature · 11 lines
Michael Nazzareno Trimarchi
Co-Founder & Chief Executive Officer
M. +39 347 913 2170
[email protected]
__________________________________

Amarula Solutions BV
Joop Geesinkweg 125, 1114 AB, Amsterdam, NL
T. +31 (0)85 111 9172
[email protected]
www.amarulasolutions.com
Reviewed-by on v2 9/10
#22 lore raw

Re: [PATCH v2 09/10] mtd: nand: raw: rockchip_nfc: add flash_node to chip stucture

In reply to Johan Jonker
Quoted 4 lines · Johan Jonker

Add flash_node to the rockchip_nfc driver chip stucture in order to find the partitions in the add_mtd_partitions_of() functions.

Thanks,
- Kever

Quoted 19 lines
---
  drivers/mtd/nand/raw/rockchip_nfc.c | 1 +
  1 file changed, 1 insertion(+)
drivers/mtd/nand/raw/rockchip_nfc.c +1 -1
index 5e2b8346..9e3a2533 100644
@@ -934,6 +934,7 @@ static int rk_nfc_nand_chip_init(ofnode node, struct rk_nfc *nfc, int devnum)
 
  	nand_set_controller_data(chip, nfc);
 
+	chip->flash_node = node;
  	chip->chip_delay = NFC_RB_DELAY_US;
  	chip->select_chip = rk_nfc_select_chip;
  	chip->cmd_ctrl = rk_nfc_cmd;
--

2.20.1

#23 lore raw

PATCH v2 10/10 mtd: nand: add support for the Sandisk SDTNQGAMA chip

In reply to Johan Jonker

Sandisk SDTNQGAMA is a 8GB size, 3.3V 8 bit chip with 16KB page size, 1KB write size and 40 bit ecc support

---
 drivers/mtd/nand/raw/nand_ids.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/mtd/nand/raw/nand_ids.c +3 -0
index d0cfacc6..22ea5e2f 100644
@@ -48,6 +48,9 @@ struct nand_flash_dev nand_flash_ids[] = {
 	{"TC58NVG6D2 64G 3.3V 8-bit",
 		{ .id = {0x98, 0xde, 0x94, 0x82, 0x76, 0x56, 0x04, 0x20} },
 		  SZ_8K, SZ_8K, SZ_2M, 0, 8, 640, NAND_ECC_INFO(40, SZ_1K) },
+	{"SDTNQGAMA 64G 3.3V 8-bit",
+		{ .id = {0x45, 0xde, 0x94, 0x93, 0x76, 0x57} },
+		  SZ_16K, SZ_8K, SZ_4M, 0, 6, 1280, NAND_ECC_INFO(40, SZ_1K) },
 	{"SDTNRGAMA 64G 3.3V 8-bit",
 		{ .id = {0x45, 0xde, 0x94, 0x93, 0x76, 0x50} },
 		  SZ_16K, SZ_8K, SZ_4M, 0, 6, 1280, NAND_ECC_INFO(40, SZ_1K) },

--
2.20.1

Reviewed-by on v2 10/10
#24 lore raw

Re: [PATCH v2 10/10] mtd: nand: add support for the Sandisk SDTNQGAMA chip

Quoted 4 lines · Johan Jonker

Sandisk SDTNQGAMA is a 8GB size, 3.3V 8 bit chip with 16KB page size, 1KB write size and 40 bit ecc support

Thanks,
- Kever

Quoted 21 lines
---
  drivers/mtd/nand/raw/nand_ids.c | 3 +++
  1 file changed, 3 insertions(+)
drivers/mtd/nand/raw/nand_ids.c +3 -1
index d0cfacc6..22ea5e2f 100644
@@ -48,6 +48,9 @@ struct nand_flash_dev nand_flash_ids[] = {
  	{"TC58NVG6D2 64G 3.3V 8-bit",
  		{ .id = {0x98, 0xde, 0x94, 0x82, 0x76, 0x56, 0x04, 0x20} },
  		  SZ_8K, SZ_8K, SZ_2M, 0, 8, 640, NAND_ECC_INFO(40, SZ_1K) },
+	{"SDTNQGAMA 64G 3.3V 8-bit",
+		{ .id = {0x45, 0xde, 0x94, 0x93, 0x76, 0x57} },
+		  SZ_16K, SZ_8K, SZ_4M, 0, 6, 1280, NAND_ECC_INFO(40, SZ_1K) },
  	{"SDTNRGAMA 64G 3.3V 8-bit",
  		{ .id = {0x45, 0xde, 0x94, 0x93, 0x76, 0x50} },
  		  SZ_16K, SZ_8K, SZ_4M, 0, 6, 1280, NAND_ECC_INFO(40, SZ_1K) },
--

2.20.1

#25 lore raw

PATCH 1/1 mtd: nand: raw: rockchip_nfc: fix oobfree offset and description

In reply to Johan Jonker

The MTD framework reserves 1 or 2 bytes for the bad block marker depending on the bus size. The rockchip_nfc driver currently only supports a 8 bit bus, but reserves standard 2 bytes for the BBM. The first free OOB byte is therefore OOB2 at offset 2. Page address(PA) bytes are moved to the last 4 positions before ECC. Update the description for U-boot.

---

Note:
Merge after serie:
[PATCH v2 00/10] Fixes for Rockchip NFC driver part 1

---
 drivers/mtd/nand/raw/rockchip_nfc.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/mtd/nand/raw/rockchip_nfc.c +4 -4
index 9e3a2533..bcab219b 100644
@@ -487,10 +487,10 @@ static int rk_nfc_write_page_raw(struct mtd_info *mtd,
 		 *
 		 *    BBM  OOB1 OOB2 OOB3 |......|  PA0  PA1  PA2  PA3
 		 *
-		 * The rk_nfc_ooblayout_free() function already has reserved
-		 * these 4 bytes with:
+		 * The oobfree structure already has reserved these 4 bytes
+		 * together with 2 bytes for BBM by reducing it's length:
 		 *
-		 * oob_region->offset = NFC_SYS_DATA_SIZE + 2;
+		 * oobfree[0].length = rknand->metadata_size - NFC_SYS_DATA_SIZE - 2;
 		 */
 		if (!i)
 			memcpy(rk_nfc_oob_ptr(chip, i),
@@ -867,7 +867,7 @@ static int rk_nfc_ecc_init(struct rk_nfc *nfc, struct nand_chip *chip)
 		ecc->layout->eccpos[i] = rknand->metadata_size + i;
 
 	ecc->layout->oobfree[0].length = rknand->metadata_size - NFC_SYS_DATA_SIZE - 2;
-	ecc->layout->oobfree[0].offset = NFC_SYS_DATA_SIZE + 2;
+	ecc->layout->oobfree[0].offset = 2;
 
 	return 0;
 }

--
2.20.1