mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH v2] of: partition: do not try to translate offset as OF address
Date: Wed, 28 May 2025 17:03:22 +0200	[thread overview]
Message-ID: <20250528150322.611761-1-a.fatoum@pengutronix.de> (raw)

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




                 reply	other threads:[~2025-05-28 15:05 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20250528150322.611761-1-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /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