U-Boot Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Zixun LI <admin@hifiphile.com>
To: Simon Glass <sjg@chromium.org>, Tom Rini <trini@konsulko.com>,
	Lukasz Majewski <lukma@denx.de>,
	Mattijs Korpershoek <mkorpershoek@baylibre.com>,
	Marek Vasut <marex@denx.de>
Cc: Zixun LI <admin@hifiphile.com>, u-boot@lists.denx.de
Subject: [RFC PATCH 1/4] dm: core: Add a way to specify an alt name for alias sequence numbering
Date: Wed, 31 Jul 2024 15:42:16 +0200	[thread overview]
Message-ID: <20240731134257.686017-2-admin@hifiphile.com> (raw)
In-Reply-To: <20240731134257.686017-1-admin@hifiphile.com>

A new field name_seq_alias is added to uclass_driver structure, which
allows an uclass driver to use an alternate name for alias sequence
numbering.

For example an uclass named "usb_gadget" can share alias with
"usb" uclass :
    UCLASS_DRIVER(usb_gadget_generic) = {
	    .id = UCLASS_USB_GADGET_GENERIC,
	    .name = "usb_gadget",
	    .name_seq_alias = "usb",
    	.flags = DM_UC_FLAG_SEQ_ALIAS,
    };

Currently there are some uclasses with duplicate name which break uclass
functions like uclass_get_by_name(), with this patch it's now possible
to rename these classes without break the existing alias function.

Signed-off-by: Zixun LI <admin@hifiphile.com>
---
 drivers/core/device.c |  3 ++-
 drivers/core/read.c   |  7 ++++++-
 drivers/core/uclass.c | 11 +++++++++--
 include/dm/read.h     |  9 ++++++++-
 include/dm/uclass.h   |  2 ++
 5 files changed, 27 insertions(+), 5 deletions(-)

diff --git a/drivers/core/device.c b/drivers/core/device.c
index 779f371b9d..a98e75b0b8 100644
--- a/drivers/core/device.c
+++ b/drivers/core/device.c
@@ -89,7 +89,8 @@ static int device_bind_common(struct udevice *parent, const struct driver *drv,
 		 */
 		if (CONFIG_IS_ENABLED(OF_CONTROL) &&
 		    !CONFIG_IS_ENABLED(OF_PLATDATA)) {
-			if (uc->uc_drv->name && ofnode_valid(node)) {
+			if ((uc->uc_drv->name || uc->uc_drv->name_seq_alias) &&
+			    ofnode_valid(node)) {
 				if (!dev_read_alias_seq(dev, &dev->seq_)) {
 					auto_seq = false;
 					log_debug("   - seq=%d\n", dev->seq_);
diff --git a/drivers/core/read.c b/drivers/core/read.c
index 55c19f335a..97b12fb7a9 100644
--- a/drivers/core/read.c
+++ b/drivers/core/read.c
@@ -347,9 +347,14 @@ const void *dev_read_prop_by_prop(struct ofprop *prop,
 int dev_read_alias_seq(const struct udevice *dev, int *devnump)
 {
 	ofnode node = dev_ofnode(dev);
-	const char *uc_name = dev->uclass->uc_drv->name;
+	const char *uc_name;
 	int ret = -ENOTSUPP;
 
+	if (dev->uclass->uc_drv->name_seq_alias)
+		uc_name = dev->uclass->uc_drv->name_seq_alias;
+	else
+		uc_name = dev->uclass->uc_drv->name;
+
 	if (ofnode_is_np(node)) {
 		ret = of_alias_get_id(ofnode_to_np(node), uc_name);
 		if (ret >= 0) {
diff --git a/drivers/core/uclass.c b/drivers/core/uclass.c
index 7ae0884a75..6dfbee2e78 100644
--- a/drivers/core/uclass.c
+++ b/drivers/core/uclass.c
@@ -308,11 +308,18 @@ int uclass_find_next_free_seq(struct uclass *uc)
 {
 	struct udevice *dev;
 	int max = -1;
+	const char *uc_name;
 
 	/* If using aliases, start with the highest alias value */
 	if (CONFIG_IS_ENABLED(DM_SEQ_ALIAS) &&
-	    (uc->uc_drv->flags & DM_UC_FLAG_SEQ_ALIAS))
-		max = dev_read_alias_highest_id(uc->uc_drv->name);
+	    (uc->uc_drv->flags & DM_UC_FLAG_SEQ_ALIAS)) {
+		if (uc->uc_drv->name_seq_alias)
+			uc_name = uc->uc_drv->name_seq_alias;
+		else
+			uc_name = uc->uc_drv->name;
+
+		max = dev_read_alias_highest_id(uc_name);
+	}
 
 	/* Avoid conflict with existing devices */
 	list_for_each_entry(dev, &uc->dev_head, uclass_node) {
diff --git a/include/dm/read.h b/include/dm/read.h
index 894bc698bb..5a86e43d86 100644
--- a/include/dm/read.h
+++ b/include/dm/read.h
@@ -1169,7 +1169,14 @@ static inline const void *dev_read_prop_by_prop(struct ofprop *prop,
 static inline int dev_read_alias_seq(const struct udevice *dev, int *devnump)
 {
 #if CONFIG_IS_ENABLED(OF_CONTROL)
-	return fdtdec_get_alias_seq(gd->fdt_blob, dev->uclass->uc_drv->name,
+	const char *uc_name;
+
+	if (dev->uclass->uc_drv->name_seq_alias)
+		uc_name = dev->uclass->uc_drv->name_seq_alias;
+	else
+		uc_name = dev->uclass->uc_drv->name;
+
+	return fdtdec_get_alias_seq(gd->fdt_blob, uc_name,
 				    dev_of_offset(dev), devnump);
 #else
 	return -ENOTSUPP;
diff --git a/include/dm/uclass.h b/include/dm/uclass.h
index 456eef7f2f..8339e0d88b 100644
--- a/include/dm/uclass.h
+++ b/include/dm/uclass.h
@@ -57,6 +57,7 @@ struct udevice;
  * drivers.
  *
  * @name: Name of uclass driver
+ * @name_seq_alias: Name used for alias sequence numbering
  * @id: ID number of this uclass
  * @post_bind: Called after a new device is bound to this uclass
  * @pre_unbind: Called before a device is unbound from this uclass
@@ -88,6 +89,7 @@ struct udevice;
  */
 struct uclass_driver {
 	const char *name;
+	const char *name_seq_alias;
 	enum uclass_id id;
 	int (*post_bind)(struct udevice *dev);
 	int (*pre_unbind)(struct udevice *dev);
-- 
2.45.2


  reply	other threads:[~2024-07-31 21:11 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-31 13:42 [RFC PATCH 0/4] dm: Duplicate uclass name fix and alias improvements Zixun LI
2024-07-31 13:42 ` Zixun LI [this message]
2024-07-31 13:42 ` [RFC PATCH 2/4] dm: core: Show device sequence instead in dm_dump_tree() Zixun LI
2024-08-01 14:42   ` Simon Glass
2024-07-31 13:42 ` [RFC PATCH 3/4] cmd: bind: Use device sequence instead for driver bind/unbind Zixun LI
2024-08-01 14:42   ` Simon Glass
2024-07-31 13:42 ` [RFC PATCH 4/4] usb: gadget: udc: Fix duplicate uclass name Zixun LI
2024-08-01 14:42 ` [RFC PATCH 0/4] dm: Duplicate uclass name fix and alias improvements Simon Glass
2024-08-01 18:37   ` Zixun LI
2024-08-01 19:28     ` Simon Glass

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=20240731134257.686017-2-admin@hifiphile.com \
    --to=admin@hifiphile.com \
    --cc=lukma@denx.de \
    --cc=marex@denx.de \
    --cc=mkorpershoek@baylibre.com \
    --cc=sjg@chromium.org \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    /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