mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] fixup! regmap-mmio: Add big endian support
@ 2020-04-13  7:11 Ahmad Fatoum
  2020-04-14  7:14 ` Sascha Hauer
  0 siblings, 1 reply; 4+ messages in thread
From: Ahmad Fatoum @ 2020-04-13  7:11 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

("regmap-mmio: Add big endian support") required syscons to have a device_d
instantiated for them. This doesn't work for clock drivers though,
like the sama5d2's, because of_clk_init is called before
of_platform_populate allocates the devices.

Restore the old behavior by passing NULL to regmap_init_mmio_clk again.
Because we want syscons to be endianness aware, do as Linux does and
duplicate the device tree endianness retrieval in the syscon driver.

[Note: Clock drivers wishing to make use of this should take care to not
call syscon_node_to_regmap on a node with a clocks property as this
will probably fail. This is the Linux behavior. A safer
device_node_to_regmap will be introduced in a separate series that
ignores clocks. ]
---
Hopefully my last fixup for this, I think I got it right now.
This should be squashed into the original, because otherwise we have
an intermittent breakage for booting sama5d2 SoCs
--
 drivers/base/regmap/regmap.c |  2 +-
 drivers/mfd/syscon.c         | 45 ++++++++++++++++++++++--------------
 2 files changed, 29 insertions(+), 18 deletions(-)

diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c
index 374d3ea3d6e1..ee5120fd7465 100644
--- a/drivers/base/regmap/regmap.c
+++ b/drivers/base/regmap/regmap.c
@@ -145,7 +145,7 @@ struct regmap *of_node_to_regmap(struct device_node *node)
 	struct regmap *map;
 
 	list_for_each_entry(map, &regmaps, list) {
-		if (map->dev->device_node == node)
+		if (map->dev && map->dev->device_node == node)
 			return map;
 	}
 
diff --git a/drivers/mfd/syscon.c b/drivers/mfd/syscon.c
index 252d91120b53..67e2ebb6c2f5 100644
--- a/drivers/mfd/syscon.c
+++ b/drivers/mfd/syscon.c
@@ -26,7 +26,7 @@
 static LIST_HEAD(syscon_list);
 
 struct syscon {
-	struct device_d *dev;
+	struct device_node *np;
 	void __iomem *base;
 	struct list_head list;
 	struct regmap *regmap;
@@ -40,9 +40,10 @@ static const struct regmap_config syscon_regmap_config = {
 
 static struct syscon *of_syscon_register(struct device_node *np, bool check_clk)
 {
-	int ret;
+	struct regmap_config syscon_config = syscon_regmap_config;
 	struct syscon *syscon;
-	struct device_d *dev;
+	u32 reg_io_width;
+	int ret;
 	struct resource res;
 
 	if (!of_device_is_compatible(np, "syscon"))
@@ -57,22 +58,32 @@ static struct syscon *of_syscon_register(struct device_node *np, bool check_clk)
 
 	syscon->base = IOMEM(res.start);
 
-	for_each_device(dev) {
-		if (np == dev->device_node) {
-			syscon->dev = dev;
-			break;
-		}
-	}
-
-	if (!syscon->dev) {
-		ret = -ENODEV;
-		goto err_map;
-	}
+	/* Parse the device's DT node for an endianness specification */
+	if (of_property_read_bool(np, "big-endian"))
+		syscon_config.val_format_endian = REGMAP_ENDIAN_BIG;
+	else if (of_property_read_bool(np, "little-endian"))
+		syscon_config.val_format_endian = REGMAP_ENDIAN_LITTLE;
+	else if (of_property_read_bool(np, "native-endian"))
+		syscon_config.val_format_endian = REGMAP_ENDIAN_NATIVE;
+
+	/*
+	 * search for reg-io-width property in DT. If it is not provided,
+	 * default to 4 bytes. regmap_init_mmio will return an error if values
+	 * are invalid so there is no need to check them here.
+	 */
+	ret = of_property_read_u32(np, "reg-io-width", &reg_io_width);
+	if (ret)
+		reg_io_width = 4;
+
+	syscon_config.name = np->full_name;
+	syscon_config.reg_stride = reg_io_width;
+	syscon_config.val_bits = reg_io_width * 8;
+	syscon_config.max_register = resource_size(&res) - reg_io_width;
 
 	list_add_tail(&syscon->list, &syscon_list);
 
-	syscon->regmap = regmap_init_mmio_clk(syscon->dev, NULL, syscon->base,
-					      &syscon_regmap_config);
+	syscon->regmap = regmap_init_mmio_clk(NULL, NULL, syscon->base,
+					      &syscon_config);
 
 	if (check_clk) {
 		struct clk *clk = of_clk_get(np, 0);
@@ -100,7 +111,7 @@ static struct syscon *node_to_syscon(struct device_node *np)
 	struct syscon *entry, *syscon = NULL;
 
 	list_for_each_entry(entry, &syscon_list, list)
-		if (entry->dev->device_node == np) {
+		if (entry->np == np) {
 			syscon = entry;
 			break;
 		}
-- 
2.26.0.rc2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 4+ messages in thread
* [PATCH] fixup! regmap-mmio: Add big endian support
@ 2020-03-31 17:26 Ahmad Fatoum
  2020-04-01  5:53 ` Sascha Hauer
  0 siblings, 1 reply; 4+ messages in thread
From: Ahmad Fatoum @ 2020-03-31 17:26 UTC (permalink / raw)
  To: barebox

Now unused, drop it.

---
 drivers/mfd/syscon.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/mfd/syscon.c b/drivers/mfd/syscon.c
index c9dfb151ee0a..252d91120b53 100644
--- a/drivers/mfd/syscon.c
+++ b/drivers/mfd/syscon.c
@@ -26,7 +26,6 @@
 static LIST_HEAD(syscon_list);
 
 struct syscon {
-	struct device_node *np;
 	struct device_d *dev;
 	void __iomem *base;
 	struct list_head list;
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-04-14  7:14 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-13  7:11 [PATCH] fixup! regmap-mmio: Add big endian support Ahmad Fatoum
2020-04-14  7:14 ` Sascha Hauer
  -- strict thread matches above, loose matches on Subject: below --
2020-03-31 17:26 Ahmad Fatoum
2020-04-01  5:53 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox