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 <[email protected]> --- 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
