1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun * Provides code common for host and device side USB.
4*4882a593Smuzhiyun *
5*4882a593Smuzhiyun * If either host side (ie. CONFIG_USB=y) or device side USB stack
6*4882a593Smuzhiyun * (ie. CONFIG_USB_GADGET=y) is compiled in the kernel, this module is
7*4882a593Smuzhiyun * compiled-in as well. Otherwise, if either of the two stacks is
8*4882a593Smuzhiyun * compiled as module, this file is compiled as module as well.
9*4882a593Smuzhiyun */
10*4882a593Smuzhiyun
11*4882a593Smuzhiyun #include <linux/kernel.h>
12*4882a593Smuzhiyun #include <linux/module.h>
13*4882a593Smuzhiyun #include <linux/of.h>
14*4882a593Smuzhiyun #include <linux/usb/ch9.h>
15*4882a593Smuzhiyun #include <linux/usb/of.h>
16*4882a593Smuzhiyun #include <linux/usb/otg.h>
17*4882a593Smuzhiyun #include <linux/of_platform.h>
18*4882a593Smuzhiyun #include <linux/debugfs.h>
19*4882a593Smuzhiyun #include "common.h"
20*4882a593Smuzhiyun
21*4882a593Smuzhiyun static const char *const ep_type_names[] = {
22*4882a593Smuzhiyun [USB_ENDPOINT_XFER_CONTROL] = "ctrl",
23*4882a593Smuzhiyun [USB_ENDPOINT_XFER_ISOC] = "isoc",
24*4882a593Smuzhiyun [USB_ENDPOINT_XFER_BULK] = "bulk",
25*4882a593Smuzhiyun [USB_ENDPOINT_XFER_INT] = "intr",
26*4882a593Smuzhiyun };
27*4882a593Smuzhiyun
28*4882a593Smuzhiyun /**
29*4882a593Smuzhiyun * usb_ep_type_string() - Returns human readable-name of the endpoint type.
30*4882a593Smuzhiyun * @ep_type: The endpoint type to return human-readable name for. If it's not
31*4882a593Smuzhiyun * any of the types: USB_ENDPOINT_XFER_{CONTROL, ISOC, BULK, INT},
32*4882a593Smuzhiyun * usually got by usb_endpoint_type(), the string 'unknown' will be returned.
33*4882a593Smuzhiyun */
usb_ep_type_string(int ep_type)34*4882a593Smuzhiyun const char *usb_ep_type_string(int ep_type)
35*4882a593Smuzhiyun {
36*4882a593Smuzhiyun if (ep_type < 0 || ep_type >= ARRAY_SIZE(ep_type_names))
37*4882a593Smuzhiyun return "unknown";
38*4882a593Smuzhiyun
39*4882a593Smuzhiyun return ep_type_names[ep_type];
40*4882a593Smuzhiyun }
41*4882a593Smuzhiyun EXPORT_SYMBOL_GPL(usb_ep_type_string);
42*4882a593Smuzhiyun
usb_otg_state_string(enum usb_otg_state state)43*4882a593Smuzhiyun const char *usb_otg_state_string(enum usb_otg_state state)
44*4882a593Smuzhiyun {
45*4882a593Smuzhiyun static const char *const names[] = {
46*4882a593Smuzhiyun [OTG_STATE_A_IDLE] = "a_idle",
47*4882a593Smuzhiyun [OTG_STATE_A_WAIT_VRISE] = "a_wait_vrise",
48*4882a593Smuzhiyun [OTG_STATE_A_WAIT_BCON] = "a_wait_bcon",
49*4882a593Smuzhiyun [OTG_STATE_A_HOST] = "a_host",
50*4882a593Smuzhiyun [OTG_STATE_A_SUSPEND] = "a_suspend",
51*4882a593Smuzhiyun [OTG_STATE_A_PERIPHERAL] = "a_peripheral",
52*4882a593Smuzhiyun [OTG_STATE_A_WAIT_VFALL] = "a_wait_vfall",
53*4882a593Smuzhiyun [OTG_STATE_A_VBUS_ERR] = "a_vbus_err",
54*4882a593Smuzhiyun [OTG_STATE_B_IDLE] = "b_idle",
55*4882a593Smuzhiyun [OTG_STATE_B_SRP_INIT] = "b_srp_init",
56*4882a593Smuzhiyun [OTG_STATE_B_PERIPHERAL] = "b_peripheral",
57*4882a593Smuzhiyun [OTG_STATE_B_WAIT_ACON] = "b_wait_acon",
58*4882a593Smuzhiyun [OTG_STATE_B_HOST] = "b_host",
59*4882a593Smuzhiyun };
60*4882a593Smuzhiyun
61*4882a593Smuzhiyun if (state < 0 || state >= ARRAY_SIZE(names))
62*4882a593Smuzhiyun return "UNDEFINED";
63*4882a593Smuzhiyun
64*4882a593Smuzhiyun return names[state];
65*4882a593Smuzhiyun }
66*4882a593Smuzhiyun EXPORT_SYMBOL_GPL(usb_otg_state_string);
67*4882a593Smuzhiyun
68*4882a593Smuzhiyun static const char *const speed_names[] = {
69*4882a593Smuzhiyun [USB_SPEED_UNKNOWN] = "UNKNOWN",
70*4882a593Smuzhiyun [USB_SPEED_LOW] = "low-speed",
71*4882a593Smuzhiyun [USB_SPEED_FULL] = "full-speed",
72*4882a593Smuzhiyun [USB_SPEED_HIGH] = "high-speed",
73*4882a593Smuzhiyun [USB_SPEED_WIRELESS] = "wireless",
74*4882a593Smuzhiyun [USB_SPEED_SUPER] = "super-speed",
75*4882a593Smuzhiyun [USB_SPEED_SUPER_PLUS] = "super-speed-plus",
76*4882a593Smuzhiyun };
77*4882a593Smuzhiyun
78*4882a593Smuzhiyun static const char *const ssp_rate[] = {
79*4882a593Smuzhiyun [USB_SSP_GEN_UNKNOWN] = "UNKNOWN",
80*4882a593Smuzhiyun [USB_SSP_GEN_2x1] = "super-speed-plus-gen2x1",
81*4882a593Smuzhiyun [USB_SSP_GEN_1x2] = "super-speed-plus-gen1x2",
82*4882a593Smuzhiyun [USB_SSP_GEN_2x2] = "super-speed-plus-gen2x2",
83*4882a593Smuzhiyun };
84*4882a593Smuzhiyun
85*4882a593Smuzhiyun /**
86*4882a593Smuzhiyun * usb_speed_string() - Returns human readable-name of the speed.
87*4882a593Smuzhiyun * @speed: The speed to return human-readable name for. If it's not
88*4882a593Smuzhiyun * any of the speeds defined in usb_device_speed enum, string for
89*4882a593Smuzhiyun * USB_SPEED_UNKNOWN will be returned.
90*4882a593Smuzhiyun */
usb_speed_string(enum usb_device_speed speed)91*4882a593Smuzhiyun const char *usb_speed_string(enum usb_device_speed speed)
92*4882a593Smuzhiyun {
93*4882a593Smuzhiyun if (speed < 0 || speed >= ARRAY_SIZE(speed_names))
94*4882a593Smuzhiyun speed = USB_SPEED_UNKNOWN;
95*4882a593Smuzhiyun return speed_names[speed];
96*4882a593Smuzhiyun }
97*4882a593Smuzhiyun EXPORT_SYMBOL_GPL(usb_speed_string);
98*4882a593Smuzhiyun
99*4882a593Smuzhiyun /**
100*4882a593Smuzhiyun * usb_get_maximum_speed - Get maximum requested speed for a given USB
101*4882a593Smuzhiyun * controller.
102*4882a593Smuzhiyun * @dev: Pointer to the given USB controller device
103*4882a593Smuzhiyun *
104*4882a593Smuzhiyun * The function gets the maximum speed string from property "maximum-speed",
105*4882a593Smuzhiyun * and returns the corresponding enum usb_device_speed.
106*4882a593Smuzhiyun */
usb_get_maximum_speed(struct device * dev)107*4882a593Smuzhiyun enum usb_device_speed usb_get_maximum_speed(struct device *dev)
108*4882a593Smuzhiyun {
109*4882a593Smuzhiyun const char *maximum_speed;
110*4882a593Smuzhiyun int ret;
111*4882a593Smuzhiyun
112*4882a593Smuzhiyun ret = device_property_read_string(dev, "maximum-speed", &maximum_speed);
113*4882a593Smuzhiyun if (ret < 0)
114*4882a593Smuzhiyun return USB_SPEED_UNKNOWN;
115*4882a593Smuzhiyun
116*4882a593Smuzhiyun ret = match_string(ssp_rate, ARRAY_SIZE(ssp_rate), maximum_speed);
117*4882a593Smuzhiyun if (ret > 0)
118*4882a593Smuzhiyun return USB_SPEED_SUPER_PLUS;
119*4882a593Smuzhiyun
120*4882a593Smuzhiyun ret = match_string(speed_names, ARRAY_SIZE(speed_names), maximum_speed);
121*4882a593Smuzhiyun return (ret < 0) ? USB_SPEED_UNKNOWN : ret;
122*4882a593Smuzhiyun }
123*4882a593Smuzhiyun EXPORT_SYMBOL_GPL(usb_get_maximum_speed);
124*4882a593Smuzhiyun
125*4882a593Smuzhiyun /**
126*4882a593Smuzhiyun * usb_get_maximum_ssp_rate - Get the signaling rate generation and lane count
127*4882a593Smuzhiyun * of a SuperSpeed Plus capable device.
128*4882a593Smuzhiyun * @dev: Pointer to the given USB controller device
129*4882a593Smuzhiyun *
130*4882a593Smuzhiyun * If the string from "maximum-speed" property is super-speed-plus-genXxY where
131*4882a593Smuzhiyun * 'X' is the generation number and 'Y' is the number of lanes, then this
132*4882a593Smuzhiyun * function returns the corresponding enum usb_ssp_rate.
133*4882a593Smuzhiyun */
usb_get_maximum_ssp_rate(struct device * dev)134*4882a593Smuzhiyun enum usb_ssp_rate usb_get_maximum_ssp_rate(struct device *dev)
135*4882a593Smuzhiyun {
136*4882a593Smuzhiyun const char *maximum_speed;
137*4882a593Smuzhiyun int ret;
138*4882a593Smuzhiyun
139*4882a593Smuzhiyun ret = device_property_read_string(dev, "maximum-speed", &maximum_speed);
140*4882a593Smuzhiyun if (ret < 0)
141*4882a593Smuzhiyun return USB_SSP_GEN_UNKNOWN;
142*4882a593Smuzhiyun
143*4882a593Smuzhiyun ret = match_string(ssp_rate, ARRAY_SIZE(ssp_rate), maximum_speed);
144*4882a593Smuzhiyun return (ret < 0) ? USB_SSP_GEN_UNKNOWN : ret;
145*4882a593Smuzhiyun }
146*4882a593Smuzhiyun EXPORT_SYMBOL_GPL(usb_get_maximum_ssp_rate);
147*4882a593Smuzhiyun
148*4882a593Smuzhiyun /**
149*4882a593Smuzhiyun * usb_state_string - Returns human readable name for the state.
150*4882a593Smuzhiyun * @state: The state to return a human-readable name for. If it's not
151*4882a593Smuzhiyun * any of the states devices in usb_device_state_string enum,
152*4882a593Smuzhiyun * the string UNKNOWN will be returned.
153*4882a593Smuzhiyun */
usb_state_string(enum usb_device_state state)154*4882a593Smuzhiyun const char *usb_state_string(enum usb_device_state state)
155*4882a593Smuzhiyun {
156*4882a593Smuzhiyun static const char *const names[] = {
157*4882a593Smuzhiyun [USB_STATE_NOTATTACHED] = "not attached",
158*4882a593Smuzhiyun [USB_STATE_ATTACHED] = "attached",
159*4882a593Smuzhiyun [USB_STATE_POWERED] = "powered",
160*4882a593Smuzhiyun [USB_STATE_RECONNECTING] = "reconnecting",
161*4882a593Smuzhiyun [USB_STATE_UNAUTHENTICATED] = "unauthenticated",
162*4882a593Smuzhiyun [USB_STATE_DEFAULT] = "default",
163*4882a593Smuzhiyun [USB_STATE_ADDRESS] = "addressed",
164*4882a593Smuzhiyun [USB_STATE_CONFIGURED] = "configured",
165*4882a593Smuzhiyun [USB_STATE_SUSPENDED] = "suspended",
166*4882a593Smuzhiyun };
167*4882a593Smuzhiyun
168*4882a593Smuzhiyun if (state < 0 || state >= ARRAY_SIZE(names))
169*4882a593Smuzhiyun return "UNKNOWN";
170*4882a593Smuzhiyun
171*4882a593Smuzhiyun return names[state];
172*4882a593Smuzhiyun }
173*4882a593Smuzhiyun EXPORT_SYMBOL_GPL(usb_state_string);
174*4882a593Smuzhiyun
175*4882a593Smuzhiyun static const char *const usb_dr_modes[] = {
176*4882a593Smuzhiyun [USB_DR_MODE_UNKNOWN] = "",
177*4882a593Smuzhiyun [USB_DR_MODE_HOST] = "host",
178*4882a593Smuzhiyun [USB_DR_MODE_PERIPHERAL] = "peripheral",
179*4882a593Smuzhiyun [USB_DR_MODE_OTG] = "otg",
180*4882a593Smuzhiyun };
181*4882a593Smuzhiyun
usb_get_dr_mode_from_string(const char * str)182*4882a593Smuzhiyun static enum usb_dr_mode usb_get_dr_mode_from_string(const char *str)
183*4882a593Smuzhiyun {
184*4882a593Smuzhiyun int ret;
185*4882a593Smuzhiyun
186*4882a593Smuzhiyun ret = match_string(usb_dr_modes, ARRAY_SIZE(usb_dr_modes), str);
187*4882a593Smuzhiyun return (ret < 0) ? USB_DR_MODE_UNKNOWN : ret;
188*4882a593Smuzhiyun }
189*4882a593Smuzhiyun
usb_get_dr_mode(struct device * dev)190*4882a593Smuzhiyun enum usb_dr_mode usb_get_dr_mode(struct device *dev)
191*4882a593Smuzhiyun {
192*4882a593Smuzhiyun const char *dr_mode;
193*4882a593Smuzhiyun int err;
194*4882a593Smuzhiyun
195*4882a593Smuzhiyun err = device_property_read_string(dev, "dr_mode", &dr_mode);
196*4882a593Smuzhiyun if (err < 0)
197*4882a593Smuzhiyun return USB_DR_MODE_UNKNOWN;
198*4882a593Smuzhiyun
199*4882a593Smuzhiyun return usb_get_dr_mode_from_string(dr_mode);
200*4882a593Smuzhiyun }
201*4882a593Smuzhiyun EXPORT_SYMBOL_GPL(usb_get_dr_mode);
202*4882a593Smuzhiyun
203*4882a593Smuzhiyun /**
204*4882a593Smuzhiyun * usb_decode_interval - Decode bInterval into the time expressed in 1us unit
205*4882a593Smuzhiyun * @epd: The descriptor of the endpoint
206*4882a593Smuzhiyun * @speed: The speed that the endpoint works as
207*4882a593Smuzhiyun *
208*4882a593Smuzhiyun * Function returns the interval expressed in 1us unit for servicing
209*4882a593Smuzhiyun * endpoint for data transfers.
210*4882a593Smuzhiyun */
usb_decode_interval(const struct usb_endpoint_descriptor * epd,enum usb_device_speed speed)211*4882a593Smuzhiyun unsigned int usb_decode_interval(const struct usb_endpoint_descriptor *epd,
212*4882a593Smuzhiyun enum usb_device_speed speed)
213*4882a593Smuzhiyun {
214*4882a593Smuzhiyun unsigned int interval = 0;
215*4882a593Smuzhiyun
216*4882a593Smuzhiyun switch (usb_endpoint_type(epd)) {
217*4882a593Smuzhiyun case USB_ENDPOINT_XFER_CONTROL:
218*4882a593Smuzhiyun /* uframes per NAK */
219*4882a593Smuzhiyun if (speed == USB_SPEED_HIGH)
220*4882a593Smuzhiyun interval = epd->bInterval;
221*4882a593Smuzhiyun break;
222*4882a593Smuzhiyun case USB_ENDPOINT_XFER_ISOC:
223*4882a593Smuzhiyun interval = 1 << (epd->bInterval - 1);
224*4882a593Smuzhiyun break;
225*4882a593Smuzhiyun case USB_ENDPOINT_XFER_BULK:
226*4882a593Smuzhiyun /* uframes per NAK */
227*4882a593Smuzhiyun if (speed == USB_SPEED_HIGH && usb_endpoint_dir_out(epd))
228*4882a593Smuzhiyun interval = epd->bInterval;
229*4882a593Smuzhiyun break;
230*4882a593Smuzhiyun case USB_ENDPOINT_XFER_INT:
231*4882a593Smuzhiyun if (speed >= USB_SPEED_HIGH)
232*4882a593Smuzhiyun interval = 1 << (epd->bInterval - 1);
233*4882a593Smuzhiyun else
234*4882a593Smuzhiyun interval = epd->bInterval;
235*4882a593Smuzhiyun break;
236*4882a593Smuzhiyun }
237*4882a593Smuzhiyun
238*4882a593Smuzhiyun interval *= (speed >= USB_SPEED_HIGH) ? 125 : 1000;
239*4882a593Smuzhiyun
240*4882a593Smuzhiyun return interval;
241*4882a593Smuzhiyun }
242*4882a593Smuzhiyun EXPORT_SYMBOL_GPL(usb_decode_interval);
243*4882a593Smuzhiyun
244*4882a593Smuzhiyun #ifdef CONFIG_OF
245*4882a593Smuzhiyun /**
246*4882a593Smuzhiyun * of_usb_get_dr_mode_by_phy - Get dual role mode for the controller device
247*4882a593Smuzhiyun * which is associated with the given phy device_node
248*4882a593Smuzhiyun * @np: Pointer to the given phy device_node
249*4882a593Smuzhiyun * @arg0: phandle args[0] for phy's with #phy-cells >= 1, or -1 for
250*4882a593Smuzhiyun * phys which do not have phy-cells
251*4882a593Smuzhiyun *
252*4882a593Smuzhiyun * In dts a usb controller associates with phy devices. The function gets
253*4882a593Smuzhiyun * the string from property 'dr_mode' of the controller associated with the
254*4882a593Smuzhiyun * given phy device node, and returns the correspondig enum usb_dr_mode.
255*4882a593Smuzhiyun */
of_usb_get_dr_mode_by_phy(struct device_node * np,int arg0)256*4882a593Smuzhiyun enum usb_dr_mode of_usb_get_dr_mode_by_phy(struct device_node *np, int arg0)
257*4882a593Smuzhiyun {
258*4882a593Smuzhiyun struct device_node *controller = NULL;
259*4882a593Smuzhiyun struct of_phandle_args args;
260*4882a593Smuzhiyun const char *dr_mode;
261*4882a593Smuzhiyun int index;
262*4882a593Smuzhiyun int err;
263*4882a593Smuzhiyun
264*4882a593Smuzhiyun do {
265*4882a593Smuzhiyun controller = of_find_node_with_property(controller, "phys");
266*4882a593Smuzhiyun if (!of_device_is_available(controller))
267*4882a593Smuzhiyun continue;
268*4882a593Smuzhiyun index = 0;
269*4882a593Smuzhiyun do {
270*4882a593Smuzhiyun if (arg0 == -1) {
271*4882a593Smuzhiyun args.np = of_parse_phandle(controller, "phys",
272*4882a593Smuzhiyun index);
273*4882a593Smuzhiyun args.args_count = 0;
274*4882a593Smuzhiyun } else {
275*4882a593Smuzhiyun err = of_parse_phandle_with_args(controller,
276*4882a593Smuzhiyun "phys", "#phy-cells",
277*4882a593Smuzhiyun index, &args);
278*4882a593Smuzhiyun if (err)
279*4882a593Smuzhiyun break;
280*4882a593Smuzhiyun }
281*4882a593Smuzhiyun
282*4882a593Smuzhiyun of_node_put(args.np);
283*4882a593Smuzhiyun if (args.np == np && (args.args_count == 0 ||
284*4882a593Smuzhiyun args.args[0] == arg0))
285*4882a593Smuzhiyun goto finish;
286*4882a593Smuzhiyun index++;
287*4882a593Smuzhiyun } while (args.np);
288*4882a593Smuzhiyun } while (controller);
289*4882a593Smuzhiyun
290*4882a593Smuzhiyun finish:
291*4882a593Smuzhiyun err = of_property_read_string(controller, "dr_mode", &dr_mode);
292*4882a593Smuzhiyun of_node_put(controller);
293*4882a593Smuzhiyun
294*4882a593Smuzhiyun if (err < 0)
295*4882a593Smuzhiyun return USB_DR_MODE_UNKNOWN;
296*4882a593Smuzhiyun
297*4882a593Smuzhiyun return usb_get_dr_mode_from_string(dr_mode);
298*4882a593Smuzhiyun }
299*4882a593Smuzhiyun EXPORT_SYMBOL_GPL(of_usb_get_dr_mode_by_phy);
300*4882a593Smuzhiyun
301*4882a593Smuzhiyun /**
302*4882a593Smuzhiyun * of_usb_host_tpl_support - to get if Targeted Peripheral List is supported
303*4882a593Smuzhiyun * for given targeted hosts (non-PC hosts)
304*4882a593Smuzhiyun * @np: Pointer to the given device_node
305*4882a593Smuzhiyun *
306*4882a593Smuzhiyun * The function gets if the targeted hosts support TPL or not
307*4882a593Smuzhiyun */
of_usb_host_tpl_support(struct device_node * np)308*4882a593Smuzhiyun bool of_usb_host_tpl_support(struct device_node *np)
309*4882a593Smuzhiyun {
310*4882a593Smuzhiyun return of_property_read_bool(np, "tpl-support");
311*4882a593Smuzhiyun }
312*4882a593Smuzhiyun EXPORT_SYMBOL_GPL(of_usb_host_tpl_support);
313*4882a593Smuzhiyun
314*4882a593Smuzhiyun /**
315*4882a593Smuzhiyun * of_usb_update_otg_caps - to update usb otg capabilities according to
316*4882a593Smuzhiyun * the passed properties in DT.
317*4882a593Smuzhiyun * @np: Pointer to the given device_node
318*4882a593Smuzhiyun * @otg_caps: Pointer to the target usb_otg_caps to be set
319*4882a593Smuzhiyun *
320*4882a593Smuzhiyun * The function updates the otg capabilities
321*4882a593Smuzhiyun */
of_usb_update_otg_caps(struct device_node * np,struct usb_otg_caps * otg_caps)322*4882a593Smuzhiyun int of_usb_update_otg_caps(struct device_node *np,
323*4882a593Smuzhiyun struct usb_otg_caps *otg_caps)
324*4882a593Smuzhiyun {
325*4882a593Smuzhiyun u32 otg_rev;
326*4882a593Smuzhiyun
327*4882a593Smuzhiyun if (!otg_caps)
328*4882a593Smuzhiyun return -EINVAL;
329*4882a593Smuzhiyun
330*4882a593Smuzhiyun if (!of_property_read_u32(np, "otg-rev", &otg_rev)) {
331*4882a593Smuzhiyun switch (otg_rev) {
332*4882a593Smuzhiyun case 0x0100:
333*4882a593Smuzhiyun case 0x0120:
334*4882a593Smuzhiyun case 0x0130:
335*4882a593Smuzhiyun case 0x0200:
336*4882a593Smuzhiyun /* Choose the lesser one if it's already been set */
337*4882a593Smuzhiyun if (otg_caps->otg_rev)
338*4882a593Smuzhiyun otg_caps->otg_rev = min_t(u16, otg_rev,
339*4882a593Smuzhiyun otg_caps->otg_rev);
340*4882a593Smuzhiyun else
341*4882a593Smuzhiyun otg_caps->otg_rev = otg_rev;
342*4882a593Smuzhiyun break;
343*4882a593Smuzhiyun default:
344*4882a593Smuzhiyun pr_err("%pOF: unsupported otg-rev: 0x%x\n",
345*4882a593Smuzhiyun np, otg_rev);
346*4882a593Smuzhiyun return -EINVAL;
347*4882a593Smuzhiyun }
348*4882a593Smuzhiyun } else {
349*4882a593Smuzhiyun /*
350*4882a593Smuzhiyun * otg-rev is mandatory for otg properties, if not passed
351*4882a593Smuzhiyun * we set it to be 0 and assume it's a legacy otg device.
352*4882a593Smuzhiyun * Non-dt platform can set it afterwards.
353*4882a593Smuzhiyun */
354*4882a593Smuzhiyun otg_caps->otg_rev = 0;
355*4882a593Smuzhiyun }
356*4882a593Smuzhiyun
357*4882a593Smuzhiyun if (of_property_read_bool(np, "hnp-disable"))
358*4882a593Smuzhiyun otg_caps->hnp_support = false;
359*4882a593Smuzhiyun if (of_property_read_bool(np, "srp-disable"))
360*4882a593Smuzhiyun otg_caps->srp_support = false;
361*4882a593Smuzhiyun if (of_property_read_bool(np, "adp-disable") ||
362*4882a593Smuzhiyun (otg_caps->otg_rev < 0x0200))
363*4882a593Smuzhiyun otg_caps->adp_support = false;
364*4882a593Smuzhiyun
365*4882a593Smuzhiyun return 0;
366*4882a593Smuzhiyun }
367*4882a593Smuzhiyun EXPORT_SYMBOL_GPL(of_usb_update_otg_caps);
368*4882a593Smuzhiyun
369*4882a593Smuzhiyun /**
370*4882a593Smuzhiyun * usb_of_get_companion_dev - Find the companion device
371*4882a593Smuzhiyun * @dev: the device pointer to find a companion
372*4882a593Smuzhiyun *
373*4882a593Smuzhiyun * Find the companion device from platform bus.
374*4882a593Smuzhiyun *
375*4882a593Smuzhiyun * Takes a reference to the returned struct device which needs to be dropped
376*4882a593Smuzhiyun * after use.
377*4882a593Smuzhiyun *
378*4882a593Smuzhiyun * Return: On success, a pointer to the companion device, %NULL on failure.
379*4882a593Smuzhiyun */
usb_of_get_companion_dev(struct device * dev)380*4882a593Smuzhiyun struct device *usb_of_get_companion_dev(struct device *dev)
381*4882a593Smuzhiyun {
382*4882a593Smuzhiyun struct device_node *node;
383*4882a593Smuzhiyun struct platform_device *pdev = NULL;
384*4882a593Smuzhiyun
385*4882a593Smuzhiyun node = of_parse_phandle(dev->of_node, "companion", 0);
386*4882a593Smuzhiyun if (node)
387*4882a593Smuzhiyun pdev = of_find_device_by_node(node);
388*4882a593Smuzhiyun
389*4882a593Smuzhiyun of_node_put(node);
390*4882a593Smuzhiyun
391*4882a593Smuzhiyun return pdev ? &pdev->dev : NULL;
392*4882a593Smuzhiyun }
393*4882a593Smuzhiyun EXPORT_SYMBOL_GPL(usb_of_get_companion_dev);
394*4882a593Smuzhiyun #endif
395*4882a593Smuzhiyun
396*4882a593Smuzhiyun struct dentry *usb_debug_root;
397*4882a593Smuzhiyun EXPORT_SYMBOL_GPL(usb_debug_root);
398*4882a593Smuzhiyun
usb_common_init(void)399*4882a593Smuzhiyun static int __init usb_common_init(void)
400*4882a593Smuzhiyun {
401*4882a593Smuzhiyun usb_debug_root = debugfs_create_dir("usb", NULL);
402*4882a593Smuzhiyun ledtrig_usb_init();
403*4882a593Smuzhiyun return 0;
404*4882a593Smuzhiyun }
405*4882a593Smuzhiyun
usb_common_exit(void)406*4882a593Smuzhiyun static void __exit usb_common_exit(void)
407*4882a593Smuzhiyun {
408*4882a593Smuzhiyun ledtrig_usb_exit();
409*4882a593Smuzhiyun debugfs_remove_recursive(usb_debug_root);
410*4882a593Smuzhiyun }
411*4882a593Smuzhiyun
412*4882a593Smuzhiyun subsys_initcall(usb_common_init);
413*4882a593Smuzhiyun module_exit(usb_common_exit);
414*4882a593Smuzhiyun
415*4882a593Smuzhiyun MODULE_LICENSE("GPL");
416