mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH v2] of: partition: do not try to translate offset as OF address
@ 2025-05-28 15:03 Ahmad Fatoum
  0 siblings, 0 replies; only message in thread
From: Ahmad Fatoum @ 2025-05-28 15:03 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

of_platform_populate will eventually call of_platform_device_create,
which will print out errors for partitions with a compatible, because
of_translate_address chokes on the partitions container node as it's
not a valid platform (child) device:

  ERROR: prom_parse: Bad cell count for /soc/bus@5c007000/i2c@5c002000/eeprom@50/partitions

The correct fix would be not to use a platform bus here, but until we
add an alternative bus or switch to mtd_notifier as in Linux, just
create the platform device without the address translation parts.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
v1 -> v2:
  - factor platform device creation code into of_add_child_device
---
 drivers/base/resource.c | 25 +++++++++++++++++++++++++
 drivers/of/partition.c  | 16 +++++++++++++---
 include/driver.h        | 11 +++++++++++
 3 files changed, 49 insertions(+), 3 deletions(-)

diff --git a/drivers/base/resource.c b/drivers/base/resource.c
index 0d6f200a9d51..e20c939c342c 100644
--- a/drivers/base/resource.c
+++ b/drivers/base/resource.c
@@ -75,6 +75,31 @@ struct device *add_child_device(struct device *parent,
 }
 EXPORT_SYMBOL(add_child_device);
 
+struct device *of_add_child_device(struct device *parent,
+		const char* devname, int id, struct device_node *np)
+{
+	struct device *dev;
+	int err;
+
+	if (!of_property_present(np, "compatible") || !of_device_is_available(np))
+		return NULL;
+
+	dev = device_alloc(devname, id);
+	dev->parent = parent;
+	dev->of_node = np;
+
+	np->dev = dev;
+	err = platform_device_register(dev);
+	if (err) {
+		np->dev = NULL;
+		free_device(dev);
+		return ERR_PTR(err);
+	}
+
+	return dev;
+}
+EXPORT_SYMBOL(of_add_child_device);
+
 struct device *add_generic_device_res(const char* devname, int id,
 		struct resource *res, int nb, void *pdata)
 {
diff --git a/drivers/of/partition.c b/drivers/of/partition.c
index 7f5a526ac88f..5b769959c80d 100644
--- a/drivers/of/partition.c
+++ b/drivers/of/partition.c
@@ -112,11 +112,21 @@ int of_parse_partitions(struct cdev *cdev, struct device_node *node)
 	}
 
 	for_each_child_of_node(node, n) {
-		of_parse_partition(cdev, n);
+		struct cdev *partcdev;
+		struct device *dev;
+
+		partcdev = of_parse_partition(cdev, n);
+		if (!partcdev || !subnode)
+			continue;
+
+		/* TODO: migrate to a partition-only bus?
+		 * Linux uses mtd_notifier for this
+		 */
+		dev = of_add_child_device(partcdev->dev, partcdev->name,
+					  DEVICE_ID_SINGLE, n);
+		WARN_ON(IS_ERR(dev));
 	}
 
-	if (subnode)
-		of_platform_populate(subnode, NULL, cdev->dev);
 	return 0;
 }
 
diff --git a/include/driver.h b/include/driver.h
index b5f4de01e424..da10171546fa 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -227,6 +227,17 @@ struct device *add_child_device(struct device *parent,
 				resource_size_t start, resource_size_t size, unsigned int flags,
 				void *pdata);
 
+#ifdef CONFIG_OFDEVICE
+struct device *of_add_child_device(struct device *parent,
+		const char* devname, int id, struct device_node *np);
+#else
+static inline struct device *of_add_child_device(struct device *parent,
+		const char* devname, int id, struct device_node *np)
+{
+	return NULL;
+}
+#endif
+
 /*
  * register a generic device
  * with only one resource
-- 
2.39.5




^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2025-05-28 15:05 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-05-28 15:03 [PATCH v2] of: partition: do not try to translate offset as OF address Ahmad Fatoum

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