1 // SPDX-License-Identifier: GPL-2.0+
3 * Provides code common for host and device side USB.
6 * Texas Instruments Incorporated, <www.ti.com>
11 #include <asm/global_data.h>
12 #include <linux/usb/otg.h>
13 #include <linux/usb/ch9.h>
14 #include <linux/usb/phy.h>
16 DECLARE_GLOBAL_DATA_PTR;
18 static const char *const usb_dr_modes[] = {
19 [USB_DR_MODE_UNKNOWN] = "",
20 [USB_DR_MODE_HOST] = "host",
21 [USB_DR_MODE_PERIPHERAL] = "peripheral",
22 [USB_DR_MODE_OTG] = "otg",
25 enum usb_dr_mode usb_get_dr_mode(ofnode node)
30 dr_mode = ofnode_read_string(node, "dr_mode");
32 pr_debug("usb dr_mode not found\n");
33 return USB_DR_MODE_UNKNOWN;
36 for (i = 0; i < ARRAY_SIZE(usb_dr_modes); i++)
37 if (!strcmp(dr_mode, usb_dr_modes[i]))
40 return USB_DR_MODE_UNKNOWN;
43 enum usb_dr_mode usb_get_role_switch_default_mode(ofnode node)
48 dr_mode = ofnode_read_string(node, "role-switch-default-mode");
50 return USB_DR_MODE_UNKNOWN;
52 for (i = 0; i < ARRAY_SIZE(usb_dr_modes); i++)
53 if (!strcmp(dr_mode, usb_dr_modes[i]))
56 return USB_DR_MODE_UNKNOWN;
59 static const char *const speed_names[] = {
60 [USB_SPEED_UNKNOWN] = "UNKNOWN",
61 [USB_SPEED_LOW] = "low-speed",
62 [USB_SPEED_FULL] = "full-speed",
63 [USB_SPEED_HIGH] = "high-speed",
64 [USB_SPEED_WIRELESS] = "wireless",
65 [USB_SPEED_SUPER] = "super-speed",
66 [USB_SPEED_SUPER_PLUS] = "super-speed-plus",
69 const char *usb_speed_string(enum usb_device_speed speed)
71 if (speed < 0 || speed >= ARRAY_SIZE(speed_names))
72 speed = USB_SPEED_UNKNOWN;
73 return speed_names[speed];
76 enum usb_device_speed usb_get_maximum_speed(ofnode node)
78 const char *max_speed;
81 max_speed = ofnode_read_string(node, "maximum-speed");
83 pr_debug("usb maximum-speed not found\n");
84 return USB_SPEED_UNKNOWN;
87 for (i = 0; i < ARRAY_SIZE(speed_names); i++)
88 if (!strcmp(max_speed, speed_names[i]))
91 return USB_SPEED_UNKNOWN;
94 #if CONFIG_IS_ENABLED(DM_USB)
95 static const char *const usbphy_modes[] = {
96 [USBPHY_INTERFACE_MODE_UNKNOWN] = "",
97 [USBPHY_INTERFACE_MODE_UTMI] = "utmi",
98 [USBPHY_INTERFACE_MODE_UTMIW] = "utmi_wide",
99 [USBPHY_INTERFACE_MODE_ULPI] = "ulpi",
100 [USBPHY_INTERFACE_MODE_SERIAL] = "serial",
101 [USBPHY_INTERFACE_MODE_HSIC] = "hsic",
104 enum usb_phy_interface usb_get_phy_mode(ofnode node)
106 const char *phy_type;
109 phy_type = ofnode_get_property(node, "phy_type", NULL);
111 return USBPHY_INTERFACE_MODE_UNKNOWN;
113 for (i = 0; i < ARRAY_SIZE(usbphy_modes); i++)
114 if (!strcmp(phy_type, usbphy_modes[i]))
117 return USBPHY_INTERFACE_MODE_UNKNOWN;