public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Johan Jonker <jbx6244@gmail.com>
To: dario.binacchi@amarulasolutions.com,
	michael@amarulasolutions.com, sjg@chromium.org,
	philipp.tomsich@vrull.eu, kever.yang@rock-chips.com
Cc: u-boot@lists.denx.de, yifeng.zhao@rock-chips.com
Subject: [PATCH v7 11/23] core: remap: fix regmap_init_mem_plat() reg size handeling
Date: Fri, 10 Mar 2023 17:42:52 +0100	[thread overview]
Message-ID: <9c422311-ad84-d2e5-348b-7d3d4463dd91@gmail.com> (raw)
In-Reply-To: <4caa17bc-6d32-5b07-68f3-f5ced40bfcbb@gmail.com>

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 handel both. The
syscon class driver also makes use of the regmap_init_mem_plat()
function, but has no way of knowing the format of the
device-specific platform data. In case of odd reg structures other
then that the syscon class driver assumes the regmap must be
filled in the individual syscon driver before pre-probe.
Also fix the ARRAY_SIZE divider in the syscon class driver.

Signed-off-by: Johan Jonker <jbx6244@gmail.com>
---

Changed V7:
  changed title
  add reg size input
  rework function calls
---
 drivers/core/regmap.c               | 23 +++++++++++++++++++----
 drivers/core/syscon-uclass.c        | 21 ++++++++++++++++-----
 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                    |  5 +++--
 include/syscon.h                    | 13 -------------
 10 files changed, 44 insertions(+), 30 deletions(-)

diff --git a/drivers/core/regmap.c b/drivers/core/regmap.c
index e33bb9d7..dd323280 100644
--- a/drivers/core/regmap.c
+++ b/drivers/core/regmap.c
@@ -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, void *reg, int size, int count,
 			 struct regmap **mapp)
 {
 	struct regmap_range *range;
@@ -89,9 +89,24 @@ int regmap_init_mem_plat(struct udevice *dev, fdt_val_t *reg, int count,
 	if (!map)
 		return -ENOMEM;

-	for (range = map->ranges; count > 0; reg += 2, range++, count--) {
-		range->start = *reg;
-		range->size = reg[1];
+	if (size == sizeof(fdt32_t)) {
+		fdt32_t *ptr = (fdt32_t *)reg;
+
+		for (range = map->ranges; count > 0;
+		     ptr += 2, range++, count--) {
+			range->start = *ptr;
+			range->size = ptr[1];
+		}
+	} else if (size == sizeof(fdt64_t)) {
+		fdt64_t *ptr = (fdt64_t *)reg;
+
+		for (range = map->ranges; count > 0;
+		     ptr += 2, range++, count--) {
+			range->start = *ptr;
+			range->size = ptr[1];
+		}
+	} else {
+		return -EINVAL;
 	}

 	*mapp = map;
diff --git a/drivers/core/syscon-uclass.c b/drivers/core/syscon-uclass.c
index 25fdb66e..7b65db6f 100644
--- a/drivers/core/syscon-uclass.c
+++ b/drivers/core/syscon-uclass.c
@@ -49,17 +49,28 @@ static int syscon_pre_probe(struct udevice *dev)
 	if (device_get_uclass_id(dev->parent) == UCLASS_PCI)
 		return 0;

+#if CONFIG_IS_ENABLED(OF_PLATDATA)
 	/*
 	 * With OF_PLATDATA we really have no way of knowing the format of
 	 * the device-specific platform data. So we assume that it starts with
-	 * a 'reg' member, and this holds a single address and size. Drivers
-	 * using OF_PLATDATA will need to ensure that this is true.
+	 * a 'reg' member that holds a single address and size. Drivers
+	 * using OF_PLATDATA will need to ensure that this is true. In case of
+	 * odd reg structures other then the syscon_base_plat structure
+	 * below the regmap must be defined in the individual syscon driver.
 	 */
-#if CONFIG_IS_ENABLED(OF_PLATDATA)
+	struct syscon_base_plat {
+		phys_addr_t reg[2];
+	};
+
 	struct syscon_base_plat *plat = dev_get_plat(dev);

-	return regmap_init_mem_plat(dev, plat->reg, ARRAY_SIZE(plat->reg),
-					&priv->regmap);
+	/* Return if the regmap is already defined in the individual
+	 * syscon driver. */
+	if (priv->regmap)
+		return 0;
+
+	return regmap_init_mem_plat(dev, plat->reg, sizeof(plat->reg[0]),
+				    ARRAY_SIZE(plat->reg) / 2, &priv->regmap);
 #else
 	return regmap_init_mem(dev_ofnode(dev), &priv->regmap);
 #endif
diff --git a/drivers/ram/rockchip/sdram_rk3066.c b/drivers/ram/rockchip/sdram_rk3066.c
index a2425f22..39c0be56 100644
--- a/drivers/ram/rockchip/sdram_rk3066.c
+++ b/drivers/ram/rockchip/sdram_rk3066.c
@@ -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, of_plat->reg, sizeof(of_plat->reg[0]),
 				   ARRAY_SIZE(of_plat->reg) / 2, &plat->map);
 	if (ret)
 		return ret;
diff --git a/drivers/ram/rockchip/sdram_rk3188.c b/drivers/ram/rockchip/sdram_rk3188.c
index 272b1b2d..ad9f936d 100644
--- a/drivers/ram/rockchip/sdram_rk3188.c
+++ b/drivers/ram/rockchip/sdram_rk3188.c
@@ -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, of_plat->reg, sizeof(of_plat->reg[0]),
 				   ARRAY_SIZE(of_plat->reg) / 2, &plat->map);
 	if (ret)
 		return ret;
diff --git a/drivers/ram/rockchip/sdram_rk322x.c b/drivers/ram/rockchip/sdram_rk322x.c
index 1b204fb5..892766a8 100644
--- a/drivers/ram/rockchip/sdram_rk322x.c
+++ b/drivers/ram/rockchip/sdram_rk322x.c
@@ -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, of_plat->reg, sizeof(of_plat->reg[0]),
 				   ARRAY_SIZE(of_plat->reg) / 2, &plat->map);
 	if (ret)
 		return ret;
diff --git a/drivers/ram/rockchip/sdram_rk3288.c b/drivers/ram/rockchip/sdram_rk3288.c
index 83778ad1..c99118fd 100644
--- a/drivers/ram/rockchip/sdram_rk3288.c
+++ b/drivers/ram/rockchip/sdram_rk3288.c
@@ -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, of_plat->reg, sizeof(of_plat->reg[0]),
 				   ARRAY_SIZE(of_plat->reg) / 2, &plat->map);
 	if (ret)
 		return ret;
diff --git a/drivers/ram/rockchip/sdram_rk3328.c b/drivers/ram/rockchip/sdram_rk3328.c
index 184c93f7..b5ca8ca4 100644
--- a/drivers/ram/rockchip/sdram_rk3328.c
+++ b/drivers/ram/rockchip/sdram_rk3328.c
@@ -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, dtplat->reg, sizeof(dtplat->reg[0]),
 				   ARRAY_SIZE(dtplat->reg) / 2, &plat->map);
 	if (ret)
 		return ret;
diff --git a/drivers/ram/rockchip/sdram_rk3399.c b/drivers/ram/rockchip/sdram_rk3399.c
index b1fea04e..ec9baddd 100644
--- a/drivers/ram/rockchip/sdram_rk3399.c
+++ b/drivers/ram/rockchip/sdram_rk3399.c
@@ -3048,7 +3048,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, dtplat->reg, sizeof(dtplat->reg[0]),
 				   ARRAY_SIZE(dtplat->reg) / 2, &plat->map);
 	if (ret)
 		return ret;
diff --git a/include/regmap.h b/include/regmap.h
index e81a3602..22b04340 100644
--- a/include/regmap.h
+++ b/include/regmap.h
@@ -378,17 +378,18 @@ int regmap_init_mem(ofnode node, struct regmap **mapp);
  *
  * @dev:	Device that uses this map
  * @reg:	List of address, size pairs
+ * @size:	Size of one reg array item
  * @count:	Number of pairs (e.g. 1 if the regmap has a single entry)
  * @mapp:	Returns allocated map
  * Return: 0 if OK, -ve on error
  *
  * This creates a new regmap with a list of regions passed in, rather than
- * using the device tree. It only supports 32-bit machines.
+ * using the device tree.
  *
  * 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, void *reg, int size, int count,
 			 struct regmap **mapp);

 int regmap_init_mem_index(ofnode node, struct regmap **mapp, int index);
diff --git a/include/syscon.h b/include/syscon.h
index f5e6cc1a..7a5ee3fa 100644
--- a/include/syscon.h
+++ b/include/syscon.h
@@ -25,19 +25,6 @@ struct syscon_ops {

 #define syscon_get_ops(dev)        ((struct syscon_ops *)(dev)->driver->ops)

-#if CONFIG_IS_ENABLED(OF_PLATDATA)
-/*
- * We don't support 64-bit machines. If they are so resource-contrained that
- * they need to use OF_PLATDATA, something is horribly wrong with the
- * education of our hardware engineers.
- *
- * Update: 64-bit is now supported and we have an education crisis.
- */
-struct syscon_base_plat {
-	fdt_val_t reg[2];
-};
-#endif
-
 /**
  * syscon_get_regmap() - Get access to a register map
  *
--
2.20.1


  parent reply	other threads:[~2023-03-10 16:43 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-10 16:36 [PATCH v7 00/23] Fixes for Rockchip NFC driver part 1 Johan Jonker
2023-03-10 16:40 ` [PATCH v7 01/23] mtd: nand: raw: rockchip_nfc: use dev_read_addr_ptr Johan Jonker
2023-03-10 16:42   ` Michael Nazzareno Trimarchi
2023-03-10 16:40 ` [PATCH v7 02/23] mtd: nand: raw: rockchip_nfc: remove the compatible string "rockchip,rk3308-nfc" Johan Jonker
2023-03-10 16:40 ` [PATCH v7 03/23] mtd: nand: raw: rockchip_nfc: add layout structure Johan Jonker
2023-03-10 16:41 ` [PATCH v7 04/23] mtd: nand: raw: rockchip_nfc: add flash_node to chip structure Johan Jonker
2023-03-10 16:41 ` [PATCH v7 05/23] mtd: nand: raw: rockchip_nfc: fix oobfree offset and description Johan Jonker
2023-03-10 16:41 ` [PATCH v7 06/23] mtd: nand: add support for the Sandisk SDTNQGAMA chip Johan Jonker
2023-03-10 16:41 ` [PATCH v7 07/23] rockchip: adc: rockchip-saradc: use dev_read_addr_ptr Johan Jonker
2023-03-10 16:42 ` [PATCH v7 08/23] rockchip: timer: dw-apb-timer: use reg variable with phys_addr_t size Johan Jonker
2023-03-10 16:42 ` [PATCH v7 10/23] include: dm: ofnode: fix headers Johan Jonker
2023-03-10 16:42 ` Johan Jonker [this message]
2023-03-11  1:37   ` [PATCH v7 11/23] core: remap: fix regmap_init_mem_plat() reg size handeling Simon Glass
2023-03-12 12:21     ` Johan Jonker
2023-03-13  3:10       ` Simon Glass
2023-03-10 16:43 ` [PATCH v7 12/23] rockchip: rk3288: syscon_rk3288: store syscon platdata in regmap Johan Jonker
2023-03-10 16:44 ` [PATCH v7 13/23] core: fdtaddr: add devfdt_get_addr_size_index_ptr function Johan Jonker
2023-03-11  1:37   ` Simon Glass
2023-03-10 16:45 ` [PATCH v7 14/23] core: read: add dev_read_addr_index_ptr function Johan Jonker
2023-03-10 16:45 ` [PATCH v7 15/23] spi: spi-aspeed-smc: use devfdt_get_addr_index_ptr Johan Jonker
2023-03-10 16:45 ` [PATCH v7 16/23] drivers: use dev_read_addr_index_ptr when cast to pointer Johan Jonker
2023-03-11  1:37   ` Simon Glass
2023-03-10 16:45 ` [PATCH v7 17/23] drivers: use dev_read_addr_ptr " Johan Jonker
2023-03-10 16:46 ` [PATCH v7 18/23] drivers: use devfdt_get_addr_size_index_ptr " Johan Jonker
2023-03-10 16:46 ` [PATCH v7 19/23] drivers: use devfdt_get_addr_index_ptr " Johan Jonker
2023-03-10 16:46 ` [PATCH v7 20/23] drivers: use devfdt_get_addr_ptr " Johan Jonker
2023-03-10 16:46 ` [PATCH v7 21/23] drivers: fix debug string with fdt_addr_t input Johan Jonker
2023-03-10 16:47 ` [PATCH v7 22/23] arm: stm32mp: spl: fix function " Johan Jonker
2023-03-11  1:37   ` Simon Glass
2023-03-10 16:47 ` [PATCH v7 23/23] include: fdtdec: decouple fdt_addr_t and phys_addr_t size Johan Jonker
2023-03-10 16:50 ` [RESEND PATCH v7 09/23] rockchip: pwm: rk_pwm: use reg variable with " Johan Jonker

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9c422311-ad84-d2e5-348b-7d3d4463dd91@gmail.com \
    --to=jbx6244@gmail.com \
    --cc=dario.binacchi@amarulasolutions.com \
    --cc=kever.yang@rock-chips.com \
    --cc=michael@amarulasolutions.com \
    --cc=philipp.tomsich@vrull.eu \
    --cc=sjg@chromium.org \
    --cc=u-boot@lists.denx.de \
    --cc=yifeng.zhao@rock-chips.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox