* [PATCH 1/2] usb: align with Linux usb_get_dr_mode API
@ 2025-11-28 17:21 Ahmad Fatoum
2025-11-28 17:21 ` [PATCH 2/2] usb: add support for barebox,dr_mode Ahmad Fatoum
2025-12-01 9:56 ` [PATCH 1/2] usb: align with Linux usb_get_dr_mode API Sascha Hauer
0 siblings, 2 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2025-11-28 17:21 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
There's no of_usb_get_dr_mode() in Linux, but drivers call
usb_get_dr_mode() instead, which also handles OF.
Adapt barebox accordingly.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
drivers/usb/core/of.c | 42 +++++++++++++++++++++-------------
drivers/usb/dwc2/core.c | 2 +-
drivers/usb/dwc3/core.c | 2 +-
drivers/usb/imx/chipidea-imx.c | 2 +-
drivers/usb/musb/musb_dsps.c | 2 +-
include/linux/usb/usb.h | 3 +--
6 files changed, 31 insertions(+), 22 deletions(-)
diff --git a/drivers/usb/core/of.c b/drivers/usb/core/of.c
index 9d4bd2b5f978..bfe0ae315763 100644
--- a/drivers/usb/core/of.c
+++ b/drivers/usb/core/of.c
@@ -17,32 +17,42 @@ static const char *usb_dr_modes[] = {
};
/**
- * of_usb_get_dr_mode - Get dual role mode for given device_node
- * @np: Pointer to the given device_node
+ * usb_get_dr_mode_from_string() - Get dual role mode for given string
+ * @str: String to find the corresponding dual role mode for
+ *
+ * This function performs a lookup for the given string and returns the
+ * corresponding enum usb_dr_mode. If no match for the string could be found,
+ * 'USB_DR_MODE_UNKNOWN' is returned.
+ */
+static enum usb_dr_mode usb_get_dr_mode_from_string(const char *str)
+{
+ int ret;
+
+ ret = match_string(usb_dr_modes, ARRAY_SIZE(usb_dr_modes), str);
+ return (ret < 0) ? USB_DR_MODE_UNKNOWN : ret;
+}
+
+/**
+ * usb_get_dr_mode - Get dual role mode for given device
+ * @dev: Pointer to the given device
*
* The function gets phy interface string from property 'dr_mode',
- * and returns the correspondig enum usb_dr_mode
+ * in the given device's device tree node and returns the correspondig
+ * enum usb_dr_mode
*/
-enum usb_dr_mode of_usb_get_dr_mode(struct device_node *np,
- const char *propname)
+enum usb_dr_mode usb_get_dr_mode(struct device *dev)
{
+ struct device_node *np = dev_of_node(dev);
const char *dr_mode;
- int err, i;
+ int err;
- if (!propname)
- propname = "dr_mode";
-
- err = of_property_read_string(np, propname, &dr_mode);
+ err = of_property_read_string(np, "dr_mode", &dr_mode);
if (err < 0)
return USB_DR_MODE_UNKNOWN;
- for (i = 0; i < ARRAY_SIZE(usb_dr_modes); i++)
- if (!strcmp(dr_mode, usb_dr_modes[i]))
- return i;
-
- return USB_DR_MODE_UNKNOWN;
+ return usb_get_dr_mode_from_string(dr_mode);
}
-EXPORT_SYMBOL_GPL(of_usb_get_dr_mode);
+EXPORT_SYMBOL_GPL(usb_get_dr_mode);
static const char *usbphy_modes[] = {
[USBPHY_INTERFACE_MODE_UNKNOWN] = "",
diff --git a/drivers/usb/dwc2/core.c b/drivers/usb/dwc2/core.c
index b198ba6bf88d..60cc690fdbc0 100644
--- a/drivers/usb/dwc2/core.c
+++ b/drivers/usb/dwc2/core.c
@@ -672,7 +672,7 @@ int dwc2_get_dr_mode(struct dwc2 *dwc2)
{
enum usb_dr_mode mode;
- mode = of_usb_get_dr_mode(dwc2->dev->of_node, NULL);
+ mode = usb_get_dr_mode(dwc2->dev);
dwc2->dr_mode = mode;
if (dwc2_hw_is_device(dwc2)) {
diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index 985213deb4f1..7f2cb6c4a70a 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -1179,7 +1179,7 @@ static void dwc3_get_properties(struct dwc3 *dwc)
dwc->maximum_speed = of_usb_get_maximum_speed(dev->of_node, NULL);
// dwc->max_ssp_rate = usb_get_maximum_ssp_rate(dev);
- dwc->dr_mode = of_usb_get_dr_mode(dev->of_node, NULL);
+ dwc->dr_mode = usb_get_dr_mode(dev);
dwc->hsphy_mode = of_usb_get_phy_mode(dev->of_node, NULL);
dwc->sysdev_is_parent = of_property_read_bool(dev->of_node,
diff --git a/drivers/usb/imx/chipidea-imx.c b/drivers/usb/imx/chipidea-imx.c
index e09857f23c27..a3b8452d8c17 100644
--- a/drivers/usb/imx/chipidea-imx.c
+++ b/drivers/usb/imx/chipidea-imx.c
@@ -118,7 +118,7 @@ static int imx_chipidea_probe_dt(struct imx_chipidea *ci)
ci->flags = MXC_EHCI_MODE_UTMI_8BIT;
- ci->mode = of_usb_get_dr_mode(ci->dev->of_node, NULL);
+ ci->mode = usb_get_dr_mode(ci->dev);
if (ci->mode == USB_DR_MODE_UNKNOWN) {
/*
diff --git a/drivers/usb/musb/musb_dsps.c b/drivers/usb/musb/musb_dsps.c
index 914212498c79..89fb64902dfc 100644
--- a/drivers/usb/musb/musb_dsps.c
+++ b/drivers/usb/musb/musb_dsps.c
@@ -264,7 +264,7 @@ static int get_musb_port_mode(struct device *dev)
{
enum usb_dr_mode mode;
- mode = of_usb_get_dr_mode(dev->of_node, NULL);
+ mode = usb_get_dr_mode(dev);
switch (mode) {
case USB_DR_MODE_HOST:
return MUSB_PORT_MODE_HOST;
diff --git a/include/linux/usb/usb.h b/include/linux/usb/usb.h
index cc994fdff1e6..c25f3d73c3c8 100644
--- a/include/linux/usb/usb.h
+++ b/include/linux/usb/usb.h
@@ -461,8 +461,7 @@ struct usb_device_id {
#define USB_CTRL_SET_TIMEOUT 5000
#define USB_CTRL_GET_TIMEOUT 5000
-enum usb_dr_mode of_usb_get_dr_mode(struct device_node *np,
- const char *propname);
+enum usb_dr_mode usb_get_dr_mode(struct device *dev);
enum usb_dr_mode {
USB_DR_MODE_UNKNOWN,
--
2.47.3
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 2/2] usb: add support for barebox,dr_mode
2025-11-28 17:21 [PATCH 1/2] usb: align with Linux usb_get_dr_mode API Ahmad Fatoum
@ 2025-11-28 17:21 ` Ahmad Fatoum
2025-12-01 9:56 ` [PATCH 1/2] usb: align with Linux usb_get_dr_mode API Sascha Hauer
1 sibling, 0 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2025-11-28 17:21 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
It's not rare to have barebox configure a USB-A port as peripheral or
OTG, because it's used for initial bootstrap of the system with a
non-spec compliant cable.
Allow for this reason to set a barebox,dr_mode that barebox will use
instead of dr_mode if available and Linux will ignore.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
drivers/usb/core/of.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/drivers/usb/core/of.c b/drivers/usb/core/of.c
index bfe0ae315763..3c2ba5a64ae2 100644
--- a/drivers/usb/core/of.c
+++ b/drivers/usb/core/of.c
@@ -36,9 +36,9 @@ static enum usb_dr_mode usb_get_dr_mode_from_string(const char *str)
* usb_get_dr_mode - Get dual role mode for given device
* @dev: Pointer to the given device
*
- * The function gets phy interface string from property 'dr_mode',
- * in the given device's device tree node and returns the correspondig
- * enum usb_dr_mode
+ * The function gets phy interface string from property 'barebox,dr_mode'
+ * or 'dr_mode' in the given device's device tree node and returns the
+ * correspondig enum usb_dr_mode
*/
enum usb_dr_mode usb_get_dr_mode(struct device *dev)
{
@@ -46,7 +46,9 @@ enum usb_dr_mode usb_get_dr_mode(struct device *dev)
const char *dr_mode;
int err;
- err = of_property_read_string(np, "dr_mode", &dr_mode);
+ err = of_property_read_string(np, "barebox,dr_mode", &dr_mode);
+ if (err < 0)
+ err = of_property_read_string(np, "dr_mode", &dr_mode);
if (err < 0)
return USB_DR_MODE_UNKNOWN;
--
2.47.3
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH 1/2] usb: align with Linux usb_get_dr_mode API
2025-11-28 17:21 [PATCH 1/2] usb: align with Linux usb_get_dr_mode API Ahmad Fatoum
2025-11-28 17:21 ` [PATCH 2/2] usb: add support for barebox,dr_mode Ahmad Fatoum
@ 2025-12-01 9:56 ` Sascha Hauer
1 sibling, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2025-12-01 9:56 UTC (permalink / raw)
To: barebox, Ahmad Fatoum
On Fri, 28 Nov 2025 18:21:35 +0100, Ahmad Fatoum wrote:
> There's no of_usb_get_dr_mode() in Linux, but drivers call
> usb_get_dr_mode() instead, which also handles OF.
>
> Adapt barebox accordingly.
>
>
Applied, thanks!
[1/2] usb: align with Linux usb_get_dr_mode API
https://git.pengutronix.de/cgit/barebox/commit/?id=24fcf8108f0d (link may not be stable)
[2/2] usb: add support for barebox,dr_mode
https://git.pengutronix.de/cgit/barebox/commit/?id=53b07035a814 (link may not be stable)
Best regards,
--
Sascha Hauer <s.hauer@pengutronix.de>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-12-01 9:57 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-11-28 17:21 [PATCH 1/2] usb: align with Linux usb_get_dr_mode API Ahmad Fatoum
2025-11-28 17:21 ` [PATCH 2/2] usb: add support for barebox,dr_mode Ahmad Fatoum
2025-12-01 9:56 ` [PATCH 1/2] usb: align with Linux usb_get_dr_mode API Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox