aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFelipe Balbi <balbi@ti.com>2013-06-30 06:56:45 -0400
committerFelipe Balbi <balbi@ti.com>2013-07-29 06:56:46 -0400
commit1494a1f62bf7cf57345e9282c8189fe2a21fab64 (patch)
tree16b5e45329a149af37278811b760422ae5e0d46d
parent410aee70f06da60dd8f78c3ec3346cc74c9bed46 (diff)
usb: common: introduce of_usb_get_maximum_speed()
this helper will be used for controllers which want to work at a lower speed even though they support higher USB transfer rates. One such case is Texas Instruments' AM437x SoC where it uses a USB3 controller without a USB3 PHY, rendering the controller USB2-only. Signed-off-by: Felipe Balbi <balbi@ti.com>
-rw-r--r--Documentation/devicetree/bindings/usb/generic.txt24
-rw-r--r--drivers/usb/usb-common.c49
-rw-r--r--include/linux/usb/of.h8
3 files changed, 70 insertions, 11 deletions
diff --git a/Documentation/devicetree/bindings/usb/generic.txt b/Documentation/devicetree/bindings/usb/generic.txt
new file mode 100644
index 000000000000..477d5bb5e51c
--- /dev/null
+++ b/Documentation/devicetree/bindings/usb/generic.txt
@@ -0,0 +1,24 @@
1Generic USB Properties
2
3Optional properties:
4 - maximum-speed: tells USB controllers we want to work up to a certain
5 speed. Valid arguments are "super-speed", "high-speed",
6 "full-speed" and "low-speed". In case this isn't passed
7 via DT, USB controllers should default to their maximum
8 HW capability.
9 - dr_mode: tells Dual-Role USB controllers that we want to work on a
10 particular mode. Valid arguments are "host",
11 "peripheral" and "otg". In case this attribute isn't
12 passed via DT, USB DRD controllers should default to
13 OTG.
14
15This is an attribute to a USB controller such as:
16
17dwc3@4a030000 {
18 compatible = "synopsys,dwc3";
19 reg = <0x4a030000 0xcfff>;
20 interrupts = <0 92 4>
21 usb-phy = <&usb2_phy>, <&usb3,phy>;
22 maximum-speed = "super-speed";
23 dr_mode = "otg";
24};
diff --git a/drivers/usb/usb-common.c b/drivers/usb/usb-common.c
index 675384dabfe9..d771870a819e 100644
--- a/drivers/usb/usb-common.c
+++ b/drivers/usb/usb-common.c
@@ -43,20 +43,20 @@ const char *usb_otg_state_string(enum usb_otg_state state)
43} 43}
44EXPORT_SYMBOL_GPL(usb_otg_state_string); 44EXPORT_SYMBOL_GPL(usb_otg_state_string);
45 45
46static const char *const speed_names[] = {
47 [USB_SPEED_UNKNOWN] = "UNKNOWN",
48 [USB_SPEED_LOW] = "low-speed",
49 [USB_SPEED_FULL] = "full-speed",
50 [USB_SPEED_HIGH] = "high-speed",
51 [USB_SPEED_WIRELESS] = "wireless",
52 [USB_SPEED_SUPER] = "super-speed",
53};
54
46const char *usb_speed_string(enum usb_device_speed speed) 55const char *usb_speed_string(enum usb_device_speed speed)
47{ 56{
48 static const char *const names[] = { 57 if (speed < 0 || speed >= ARRAY_SIZE(speed_names))
49 [USB_SPEED_UNKNOWN] = "UNKNOWN",
50 [USB_SPEED_LOW] = "low-speed",
51 [USB_SPEED_FULL] = "full-speed",
52 [USB_SPEED_HIGH] = "high-speed",
53 [USB_SPEED_WIRELESS] = "wireless",
54 [USB_SPEED_SUPER] = "super-speed",
55 };
56
57 if (speed < 0 || speed >= ARRAY_SIZE(names))
58 speed = USB_SPEED_UNKNOWN; 58 speed = USB_SPEED_UNKNOWN;
59 return names[speed]; 59 return speed_names[speed];
60} 60}
61EXPORT_SYMBOL_GPL(usb_speed_string); 61EXPORT_SYMBOL_GPL(usb_speed_string);
62 62
@@ -112,6 +112,33 @@ enum usb_dr_mode of_usb_get_dr_mode(struct device_node *np)
112 return USB_DR_MODE_UNKNOWN; 112 return USB_DR_MODE_UNKNOWN;
113} 113}
114EXPORT_SYMBOL_GPL(of_usb_get_dr_mode); 114EXPORT_SYMBOL_GPL(of_usb_get_dr_mode);
115
116/**
117 * of_usb_get_maximum_speed - Get maximum requested speed for a given USB
118 * controller.
119 * @np: Pointer to the given device_node
120 *
121 * The function gets the maximum speed string from property "maximum-speed",
122 * and returns the corresponding enum usb_device_speed.
123 */
124enum usb_device_speed of_usb_get_maximum_speed(struct device_node *np)
125{
126 const char *maximum_speed;
127 int err;
128 int i;
129
130 err = of_property_read_string(np, "maximum-speed", &maximum_speed);
131 if (err < 0)
132 return USB_SPEED_UNKNOWN;
133
134 for (i = 0; i < ARRAY_SIZE(speed_names); i++)
135 if (strcmp(maximum_speed, speed_names[i]) == 0)
136 return i;
137
138 return USB_SPEED_UNKNOWN;
139}
140EXPORT_SYMBOL_GPL(of_usb_get_maximum_speed);
141
115#endif 142#endif
116 143
117MODULE_LICENSE("GPL"); 144MODULE_LICENSE("GPL");
diff --git a/include/linux/usb/of.h b/include/linux/usb/of.h
index a0ef405368b8..5a7cb9ebf0ef 100644
--- a/include/linux/usb/of.h
+++ b/include/linux/usb/of.h
@@ -7,16 +7,24 @@
7#ifndef __LINUX_USB_OF_H 7#ifndef __LINUX_USB_OF_H
8#define __LINUX_USB_OF_H 8#define __LINUX_USB_OF_H
9 9
10#include <linux/usb/ch9.h>
10#include <linux/usb/otg.h> 11#include <linux/usb/otg.h>
11#include <linux/usb/phy.h> 12#include <linux/usb/phy.h>
12 13
13#if IS_ENABLED(CONFIG_OF) 14#if IS_ENABLED(CONFIG_OF)
14enum usb_dr_mode of_usb_get_dr_mode(struct device_node *np); 15enum usb_dr_mode of_usb_get_dr_mode(struct device_node *np);
16enum usb_device_speed of_usb_get_maximum_speed(struct device_node *np);
15#else 17#else
16static inline enum usb_dr_mode of_usb_get_dr_mode(struct device_node *np) 18static inline enum usb_dr_mode of_usb_get_dr_mode(struct device_node *np)
17{ 19{
18 return USB_DR_MODE_UNKNOWN; 20 return USB_DR_MODE_UNKNOWN;
19} 21}
22
23static inline enum usb_device_speed
24of_usb_get_maximum_speed(struct device_node *np)
25{
26 return USB_SPEED_UNKNOWN;
27}
20#endif 28#endif
21 29
22#if IS_ENABLED(CONFIG_OF) && IS_ENABLED(CONFIG_USB_PHY) 30#if IS_ENABLED(CONFIG_OF) && IS_ENABLED(CONFIG_USB_PHY)