Merge branch 'for-3.11' of git://linux-nfs.org/~bfields/linux
[linux-2.6.git] / drivers / usb / usb-common.c
blob675384dabfe987f59d2e8678875e4801ceda488b
1 /*
2 * Provides code common for host and device side USB.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation, version 2.
8 * If either host side (ie. CONFIG_USB=y) or device side USB stack
9 * (ie. CONFIG_USB_GADGET=y) is compiled in the kernel, this module is
10 * compiled-in as well. Otherwise, if either of the two stacks is
11 * compiled as module, this file is compiled as module as well.
14 #include <linux/kernel.h>
15 #include <linux/module.h>
16 #include <linux/of.h>
17 #include <linux/usb/ch9.h>
18 #include <linux/usb/of.h>
19 #include <linux/usb/otg.h>
21 const char *usb_otg_state_string(enum usb_otg_state state)
23 static const char *const names[] = {
24 [OTG_STATE_A_IDLE] = "a_idle",
25 [OTG_STATE_A_WAIT_VRISE] = "a_wait_vrise",
26 [OTG_STATE_A_WAIT_BCON] = "a_wait_bcon",
27 [OTG_STATE_A_HOST] = "a_host",
28 [OTG_STATE_A_SUSPEND] = "a_suspend",
29 [OTG_STATE_A_PERIPHERAL] = "a_peripheral",
30 [OTG_STATE_A_WAIT_VFALL] = "a_wait_vfall",
31 [OTG_STATE_A_VBUS_ERR] = "a_vbus_err",
32 [OTG_STATE_B_IDLE] = "b_idle",
33 [OTG_STATE_B_SRP_INIT] = "b_srp_init",
34 [OTG_STATE_B_PERIPHERAL] = "b_peripheral",
35 [OTG_STATE_B_WAIT_ACON] = "b_wait_acon",
36 [OTG_STATE_B_HOST] = "b_host",
39 if (state < 0 || state >= ARRAY_SIZE(names))
40 return "UNDEFINED";
42 return names[state];
44 EXPORT_SYMBOL_GPL(usb_otg_state_string);
46 const char *usb_speed_string(enum usb_device_speed speed)
48 static const char *const 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",
57 if (speed < 0 || speed >= ARRAY_SIZE(names))
58 speed = USB_SPEED_UNKNOWN;
59 return names[speed];
61 EXPORT_SYMBOL_GPL(usb_speed_string);
63 const char *usb_state_string(enum usb_device_state state)
65 static const char *const names[] = {
66 [USB_STATE_NOTATTACHED] = "not attached",
67 [USB_STATE_ATTACHED] = "attached",
68 [USB_STATE_POWERED] = "powered",
69 [USB_STATE_RECONNECTING] = "reconnecting",
70 [USB_STATE_UNAUTHENTICATED] = "unauthenticated",
71 [USB_STATE_DEFAULT] = "default",
72 [USB_STATE_ADDRESS] = "addresssed",
73 [USB_STATE_CONFIGURED] = "configured",
74 [USB_STATE_SUSPENDED] = "suspended",
77 if (state < 0 || state >= ARRAY_SIZE(names))
78 return "UNKNOWN";
80 return names[state];
82 EXPORT_SYMBOL_GPL(usb_state_string);
84 #ifdef CONFIG_OF
85 static const char *const usb_dr_modes[] = {
86 [USB_DR_MODE_UNKNOWN] = "",
87 [USB_DR_MODE_HOST] = "host",
88 [USB_DR_MODE_PERIPHERAL] = "peripheral",
89 [USB_DR_MODE_OTG] = "otg",
92 /**
93 * of_usb_get_dr_mode - Get dual role mode for given device_node
94 * @np: Pointer to the given device_node
96 * The function gets phy interface string from property 'dr_mode',
97 * and returns the correspondig enum usb_dr_mode
99 enum usb_dr_mode of_usb_get_dr_mode(struct device_node *np)
101 const char *dr_mode;
102 int err, i;
104 err = of_property_read_string(np, "dr_mode", &dr_mode);
105 if (err < 0)
106 return USB_DR_MODE_UNKNOWN;
108 for (i = 0; i < ARRAY_SIZE(usb_dr_modes); i++)
109 if (!strcmp(dr_mode, usb_dr_modes[i]))
110 return i;
112 return USB_DR_MODE_UNKNOWN;
114 EXPORT_SYMBOL_GPL(of_usb_get_dr_mode);
115 #endif
117 MODULE_LICENSE("GPL");