From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: mfe@pengutronix.de, Jules Maselbas <jmaselbas@zdiv.net>,
Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 5/6] usb: otg: turn global otg device into device alias
Date: Wed, 28 Feb 2024 17:05:17 +0100 [thread overview]
Message-ID: <20240228160518.1589193-5-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20240228160518.1589193-1-a.fatoum@pengutronix.de>
barebox supports manual switching of USB OTG ports to either peripheral
or host via the otgX.mode={host,peripheral} device parameter.
When support for configuring multiple OTG ports was added, the old
singleton otg device was kept, as not to break existing scripts.
Since then, barebox has gained support for device aliases, which are a
light weight mechanism to resolve device names and point at a different
device. This is exactly what's required here, so make use of it.
Cc: Jules Maselbas <jmaselbas@zdiv.net>
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
drivers/usb/otg/otgdev.c | 22 +++++++++-------------
1 file changed, 9 insertions(+), 13 deletions(-)
diff --git a/drivers/usb/otg/otgdev.c b/drivers/usb/otg/otgdev.c
index e035c988af2d..b4315c2d3c28 100644
--- a/drivers/usb/otg/otgdev.c
+++ b/drivers/usb/otg/otgdev.c
@@ -58,11 +58,6 @@ static int register_otg_device(struct device *dev, struct otg_mode *otg)
return PTR_ERR_OR_ZERO(param_mode);
}
-static struct device otg_device = {
- .name = "otg",
- .id = DEVICE_ID_SINGLE,
-};
-
struct bus_type otg_bus_type = {
.name = "usbotg" /* "otg" is already taken for the alias */
};
@@ -70,6 +65,7 @@ struct bus_type otg_bus_type = {
int usb_register_otg_device(struct device *parent,
int (*set_mode)(void *ctx, enum usb_dr_mode mode), void *ctx)
{
+ bool first_otg = list_empty(&otg_bus_type.device_list);
int ret;
struct otg_mode *otg;
@@ -85,15 +81,15 @@ int usb_register_otg_device(struct device *parent,
otg->set_mode_callback = set_mode;
otg->ctx = ctx;
- /* register otg.mode as an alias of otg0.mode */
- if (otg_device.parent == NULL) {
- otg_device.parent = parent;
- ret = register_otg_device(&otg_device, otg);
- if (ret)
- return ret;
- }
+ ret = register_otg_device(&otg->dev, otg);
+ if (ret)
+ return ret;
- return register_otg_device(&otg->dev, otg);
+ /* register otg.mode as an alias of otg0.mode */
+ if (first_otg)
+ dev_add_alias(&otg->dev, "otg");
+
+ return 0;
}
static int otg_bus_init(void)
--
2.39.2
next prev parent reply other threads:[~2024-02-28 16:06 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-28 16:05 [PATCH 1/6] driver: make struct bus_type::match optional Ahmad Fatoum
2024-02-28 16:05 ` [PATCH 2/6] driver: make struct bus_type::probe optional Ahmad Fatoum
2024-02-28 16:05 ` [PATCH 3/6] treewide: remove bus probe functions that just call driver probe Ahmad Fatoum
2024-02-28 16:05 ` [PATCH 4/6] usb: otg: maintain list of USB OTG controllers Ahmad Fatoum
2024-02-28 16:05 ` Ahmad Fatoum [this message]
2024-02-28 16:05 ` [PATCH 6/6] usb: print number of skipped OTG controllers when scanning Ahmad Fatoum
2024-02-29 8:10 ` [PATCH 1/6] driver: make struct bus_type::match optional Sascha Hauer
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=20240228160518.1589193-5-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
--cc=jmaselbas@zdiv.net \
--cc=mfe@pengutronix.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