1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22#include <linux/usb.h>
23#include <linux/usb/ch11.h>
24#include <linux/usb/hcd.h>
25#include "usb.h"
26
27struct usb_hub {
28 struct device *intfdev;
29 struct usb_device *hdev;
30 struct kref kref;
31 struct urb *urb;
32
33
34 u8 (*buffer)[8];
35 union {
36 struct usb_hub_status hub;
37 struct usb_port_status port;
38 } *status;
39 struct mutex status_mutex;
40
41 int error;
42 int nerrors;
43
44 unsigned long event_bits[1];
45 unsigned long change_bits[1];
46
47 unsigned long removed_bits[1];
48
49 unsigned long wakeup_bits[1];
50
51 unsigned long power_bits[1];
52 unsigned long child_usage_bits[1];
53
54 unsigned long warm_reset_bits[1];
55
56#if USB_MAXCHILDREN > 31
57#error event_bits[] is too short!
58#endif
59
60 struct usb_hub_descriptor *descriptor;
61 struct usb_tt tt;
62
63 unsigned mA_per_port;
64#ifdef CONFIG_PM
65 unsigned wakeup_enabled_descendants;
66#endif
67
68 unsigned limited_power:1;
69 unsigned quiescing:1;
70 unsigned disconnected:1;
71 unsigned in_reset:1;
72
73 unsigned quirk_check_port_auto_suspend:1;
74
75 unsigned has_indicators:1;
76 u8 indicator[USB_MAXCHILDREN];
77 struct delayed_work leds;
78 struct delayed_work init_work;
79 struct work_struct events;
80 struct usb_port **ports;
81};
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96struct usb_port {
97 struct usb_device *child;
98 struct device dev;
99 struct usb_dev_state *port_owner;
100 struct usb_port *peer;
101 struct dev_pm_qos_request *req;
102 enum usb_port_connect_type connect_type;
103 usb_port_location_t location;
104 struct mutex status_lock;
105 u8 portnum;
106 unsigned int is_superspeed:1;
107};
108
109#define to_usb_port(_dev) \
110 container_of(_dev, struct usb_port, dev)
111
112extern int usb_hub_create_port_device(struct usb_hub *hub,
113 int port1);
114extern void usb_hub_remove_port_device(struct usb_hub *hub,
115 int port1);
116extern int usb_hub_set_port_power(struct usb_device *hdev, struct usb_hub *hub,
117 int port1, bool set);
118extern struct usb_hub *usb_hub_to_struct_hub(struct usb_device *hdev);
119extern int hub_port_debounce(struct usb_hub *hub, int port1,
120 bool must_be_connected);
121extern int usb_clear_port_feature(struct usb_device *hdev,
122 int port1, int feature);
123
124static inline bool hub_is_port_power_switchable(struct usb_hub *hub)
125{
126 __le16 hcs;
127
128 if (!hub)
129 return false;
130 hcs = hub->descriptor->wHubCharacteristics;
131 return (le16_to_cpu(hcs) & HUB_CHAR_LPSM) < HUB_CHAR_NO_LPSM;
132}
133
134static inline int hub_is_superspeed(struct usb_device *hdev)
135{
136 return hdev->descriptor.bDeviceProtocol == USB_HUB_PR_SS;
137}
138
139static inline unsigned hub_power_on_good_delay(struct usb_hub *hub)
140{
141 unsigned delay = hub->descriptor->bPwrOn2PwrGood * 2;
142
143
144 return max(delay, 100U);
145}
146
147static inline int hub_port_debounce_be_connected(struct usb_hub *hub,
148 int port1)
149{
150 return hub_port_debounce(hub, port1, true);
151}
152
153static inline int hub_port_debounce_be_stable(struct usb_hub *hub,
154 int port1)
155{
156 return hub_port_debounce(hub, port1, false);
157}
158
159