1
2
3
4
5
6
7
8
9
10#include <linux/of.h>
11#include <linux/of_platform.h>
12#include <linux/usb/of.h>
13
14
15
16
17
18
19
20
21
22
23
24
25struct device_node *usb_of_get_device_node(struct usb_device *hub, int port1)
26{
27 struct device_node *node;
28 u32 reg;
29
30 for_each_child_of_node(hub->dev.of_node, node) {
31 if (of_property_read_u32(node, "reg", ®))
32 continue;
33
34 if (reg == port1)
35 return node;
36 }
37
38 return NULL;
39}
40EXPORT_SYMBOL_GPL(usb_of_get_device_node);
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57bool usb_of_has_combined_node(struct usb_device *udev)
58{
59 struct usb_device_descriptor *ddesc = &udev->descriptor;
60 struct usb_config_descriptor *cdesc;
61
62 if (!udev->dev.of_node)
63 return false;
64
65 switch (ddesc->bDeviceClass) {
66 case USB_CLASS_PER_INTERFACE:
67 case USB_CLASS_HUB:
68 if (ddesc->bNumConfigurations == 1) {
69 cdesc = &udev->config->desc;
70 if (cdesc->bNumInterfaces == 1)
71 return true;
72 }
73 }
74
75 return false;
76}
77EXPORT_SYMBOL_GPL(usb_of_has_combined_node);
78
79
80
81
82
83
84
85
86
87
88
89
90
91struct device_node *
92usb_of_get_interface_node(struct usb_device *udev, u8 config, u8 ifnum)
93{
94 struct device_node *node;
95 u32 reg[2];
96
97 for_each_child_of_node(udev->dev.of_node, node) {
98 if (of_property_read_u32_array(node, "reg", reg, 2))
99 continue;
100
101 if (reg[0] == ifnum && reg[1] == config)
102 return node;
103 }
104
105 return NULL;
106}
107EXPORT_SYMBOL_GPL(usb_of_get_interface_node);
108
109
110
111
112
113
114
115
116
117
118
119
120struct device *usb_of_get_companion_dev(struct device *dev)
121{
122 struct device_node *node;
123 struct platform_device *pdev = NULL;
124
125 node = of_parse_phandle(dev->of_node, "companion", 0);
126 if (node)
127 pdev = of_find_device_by_node(node);
128
129 of_node_put(node);
130
131 return pdev ? &pdev->dev : NULL;
132}
133EXPORT_SYMBOL_GPL(usb_of_get_companion_dev);
134