1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun * Universal Host Controller Interface driver for USB.
4*4882a593Smuzhiyun *
5*4882a593Smuzhiyun * Maintainer: Alan Stern <stern@rowland.harvard.edu>
6*4882a593Smuzhiyun *
7*4882a593Smuzhiyun * (C) Copyright 1999 Linus Torvalds
8*4882a593Smuzhiyun * (C) Copyright 1999-2002 Johannes Erdfelt, johannes@erdfelt.com
9*4882a593Smuzhiyun * (C) Copyright 1999 Randy Dunlap
10*4882a593Smuzhiyun * (C) Copyright 1999 Georg Acher, acher@in.tum.de
11*4882a593Smuzhiyun * (C) Copyright 1999 Deti Fliegl, deti@fliegl.de
12*4882a593Smuzhiyun * (C) Copyright 1999 Thomas Sailer, sailer@ife.ee.ethz.ch
13*4882a593Smuzhiyun * (C) Copyright 2004 Alan Stern, stern@rowland.harvard.edu
14*4882a593Smuzhiyun */
15*4882a593Smuzhiyun
16*4882a593Smuzhiyun static const __u8 root_hub_hub_des[] =
17*4882a593Smuzhiyun {
18*4882a593Smuzhiyun 0x09, /* __u8 bLength; */
19*4882a593Smuzhiyun USB_DT_HUB, /* __u8 bDescriptorType; Hub-descriptor */
20*4882a593Smuzhiyun 0x02, /* __u8 bNbrPorts; */
21*4882a593Smuzhiyun HUB_CHAR_NO_LPSM | /* __u16 wHubCharacteristics; */
22*4882a593Smuzhiyun HUB_CHAR_INDV_PORT_OCPM, /* (per-port OC, no power switching) */
23*4882a593Smuzhiyun 0x00,
24*4882a593Smuzhiyun 0x01, /* __u8 bPwrOn2pwrGood; 2ms */
25*4882a593Smuzhiyun 0x00, /* __u8 bHubContrCurrent; 0 mA */
26*4882a593Smuzhiyun 0x00, /* __u8 DeviceRemovable; *** 7 Ports max */
27*4882a593Smuzhiyun 0xff /* __u8 PortPwrCtrlMask; *** 7 ports max */
28*4882a593Smuzhiyun };
29*4882a593Smuzhiyun
30*4882a593Smuzhiyun #define UHCI_RH_MAXCHILD 7
31*4882a593Smuzhiyun
32*4882a593Smuzhiyun /* must write as zeroes */
33*4882a593Smuzhiyun #define WZ_BITS (USBPORTSC_RES2 | USBPORTSC_RES3 | USBPORTSC_RES4)
34*4882a593Smuzhiyun
35*4882a593Smuzhiyun /* status change bits: nonzero writes will clear */
36*4882a593Smuzhiyun #define RWC_BITS (USBPORTSC_OCC | USBPORTSC_PEC | USBPORTSC_CSC)
37*4882a593Smuzhiyun
38*4882a593Smuzhiyun /* suspend/resume bits: port suspended or port resuming */
39*4882a593Smuzhiyun #define SUSPEND_BITS (USBPORTSC_SUSP | USBPORTSC_RD)
40*4882a593Smuzhiyun
41*4882a593Smuzhiyun /* A port that either is connected or has a changed-bit set will prevent
42*4882a593Smuzhiyun * us from AUTO_STOPPING.
43*4882a593Smuzhiyun */
any_ports_active(struct uhci_hcd * uhci)44*4882a593Smuzhiyun static int any_ports_active(struct uhci_hcd *uhci)
45*4882a593Smuzhiyun {
46*4882a593Smuzhiyun int port;
47*4882a593Smuzhiyun
48*4882a593Smuzhiyun for (port = 0; port < uhci->rh_numports; ++port) {
49*4882a593Smuzhiyun if ((uhci_readw(uhci, USBPORTSC1 + port * 2) &
50*4882a593Smuzhiyun (USBPORTSC_CCS | RWC_BITS)) ||
51*4882a593Smuzhiyun test_bit(port, &uhci->port_c_suspend))
52*4882a593Smuzhiyun return 1;
53*4882a593Smuzhiyun }
54*4882a593Smuzhiyun return 0;
55*4882a593Smuzhiyun }
56*4882a593Smuzhiyun
get_hub_status_data(struct uhci_hcd * uhci,char * buf)57*4882a593Smuzhiyun static inline int get_hub_status_data(struct uhci_hcd *uhci, char *buf)
58*4882a593Smuzhiyun {
59*4882a593Smuzhiyun int port;
60*4882a593Smuzhiyun int mask = RWC_BITS;
61*4882a593Smuzhiyun
62*4882a593Smuzhiyun /* Some boards (both VIA and Intel apparently) report bogus
63*4882a593Smuzhiyun * overcurrent indications, causing massive log spam unless
64*4882a593Smuzhiyun * we completely ignore them. This doesn't seem to be a problem
65*4882a593Smuzhiyun * with the chipset so much as with the way it is connected on
66*4882a593Smuzhiyun * the motherboard; if the overcurrent input is left to float
67*4882a593Smuzhiyun * then it may constantly register false positives. */
68*4882a593Smuzhiyun if (ignore_oc)
69*4882a593Smuzhiyun mask &= ~USBPORTSC_OCC;
70*4882a593Smuzhiyun
71*4882a593Smuzhiyun *buf = 0;
72*4882a593Smuzhiyun for (port = 0; port < uhci->rh_numports; ++port) {
73*4882a593Smuzhiyun if ((uhci_readw(uhci, USBPORTSC1 + port * 2) & mask) ||
74*4882a593Smuzhiyun test_bit(port, &uhci->port_c_suspend))
75*4882a593Smuzhiyun *buf |= (1 << (port + 1));
76*4882a593Smuzhiyun }
77*4882a593Smuzhiyun return !!*buf;
78*4882a593Smuzhiyun }
79*4882a593Smuzhiyun
80*4882a593Smuzhiyun #define CLR_RH_PORTSTAT(x) \
81*4882a593Smuzhiyun status = uhci_readw(uhci, port_addr); \
82*4882a593Smuzhiyun status &= ~(RWC_BITS|WZ_BITS); \
83*4882a593Smuzhiyun status &= ~(x); \
84*4882a593Smuzhiyun status |= RWC_BITS & (x); \
85*4882a593Smuzhiyun uhci_writew(uhci, status, port_addr)
86*4882a593Smuzhiyun
87*4882a593Smuzhiyun #define SET_RH_PORTSTAT(x) \
88*4882a593Smuzhiyun status = uhci_readw(uhci, port_addr); \
89*4882a593Smuzhiyun status |= (x); \
90*4882a593Smuzhiyun status &= ~(RWC_BITS|WZ_BITS); \
91*4882a593Smuzhiyun uhci_writew(uhci, status, port_addr)
92*4882a593Smuzhiyun
93*4882a593Smuzhiyun /* UHCI controllers don't automatically stop resume signalling after 20 msec,
94*4882a593Smuzhiyun * so we have to poll and check timeouts in order to take care of it.
95*4882a593Smuzhiyun */
uhci_finish_suspend(struct uhci_hcd * uhci,int port,unsigned long port_addr)96*4882a593Smuzhiyun static void uhci_finish_suspend(struct uhci_hcd *uhci, int port,
97*4882a593Smuzhiyun unsigned long port_addr)
98*4882a593Smuzhiyun {
99*4882a593Smuzhiyun int status;
100*4882a593Smuzhiyun int i;
101*4882a593Smuzhiyun
102*4882a593Smuzhiyun if (uhci_readw(uhci, port_addr) & SUSPEND_BITS) {
103*4882a593Smuzhiyun CLR_RH_PORTSTAT(SUSPEND_BITS);
104*4882a593Smuzhiyun if (test_bit(port, &uhci->resuming_ports))
105*4882a593Smuzhiyun set_bit(port, &uhci->port_c_suspend);
106*4882a593Smuzhiyun
107*4882a593Smuzhiyun /* The controller won't actually turn off the RD bit until
108*4882a593Smuzhiyun * it has had a chance to send a low-speed EOP sequence,
109*4882a593Smuzhiyun * which is supposed to take 3 bit times (= 2 microseconds).
110*4882a593Smuzhiyun * Experiments show that some controllers take longer, so
111*4882a593Smuzhiyun * we'll poll for completion. */
112*4882a593Smuzhiyun for (i = 0; i < 10; ++i) {
113*4882a593Smuzhiyun if (!(uhci_readw(uhci, port_addr) & SUSPEND_BITS))
114*4882a593Smuzhiyun break;
115*4882a593Smuzhiyun udelay(1);
116*4882a593Smuzhiyun }
117*4882a593Smuzhiyun }
118*4882a593Smuzhiyun clear_bit(port, &uhci->resuming_ports);
119*4882a593Smuzhiyun usb_hcd_end_port_resume(&uhci_to_hcd(uhci)->self, port);
120*4882a593Smuzhiyun }
121*4882a593Smuzhiyun
122*4882a593Smuzhiyun /* Wait for the UHCI controller in HP's iLO2 server management chip.
123*4882a593Smuzhiyun * It can take up to 250 us to finish a reset and set the CSC bit.
124*4882a593Smuzhiyun */
wait_for_HP(struct uhci_hcd * uhci,unsigned long port_addr)125*4882a593Smuzhiyun static void wait_for_HP(struct uhci_hcd *uhci, unsigned long port_addr)
126*4882a593Smuzhiyun {
127*4882a593Smuzhiyun int i;
128*4882a593Smuzhiyun
129*4882a593Smuzhiyun for (i = 10; i < 250; i += 10) {
130*4882a593Smuzhiyun if (uhci_readw(uhci, port_addr) & USBPORTSC_CSC)
131*4882a593Smuzhiyun return;
132*4882a593Smuzhiyun udelay(10);
133*4882a593Smuzhiyun }
134*4882a593Smuzhiyun /* Log a warning? */
135*4882a593Smuzhiyun }
136*4882a593Smuzhiyun
uhci_check_ports(struct uhci_hcd * uhci)137*4882a593Smuzhiyun static void uhci_check_ports(struct uhci_hcd *uhci)
138*4882a593Smuzhiyun {
139*4882a593Smuzhiyun unsigned int port;
140*4882a593Smuzhiyun unsigned long port_addr;
141*4882a593Smuzhiyun int status;
142*4882a593Smuzhiyun
143*4882a593Smuzhiyun for (port = 0; port < uhci->rh_numports; ++port) {
144*4882a593Smuzhiyun port_addr = USBPORTSC1 + 2 * port;
145*4882a593Smuzhiyun status = uhci_readw(uhci, port_addr);
146*4882a593Smuzhiyun if (unlikely(status & USBPORTSC_PR)) {
147*4882a593Smuzhiyun if (time_after_eq(jiffies, uhci->ports_timeout)) {
148*4882a593Smuzhiyun CLR_RH_PORTSTAT(USBPORTSC_PR);
149*4882a593Smuzhiyun udelay(10);
150*4882a593Smuzhiyun
151*4882a593Smuzhiyun /* HP's server management chip requires
152*4882a593Smuzhiyun * a longer delay. */
153*4882a593Smuzhiyun if (uhci->wait_for_hp)
154*4882a593Smuzhiyun wait_for_HP(uhci, port_addr);
155*4882a593Smuzhiyun
156*4882a593Smuzhiyun /* If the port was enabled before, turning
157*4882a593Smuzhiyun * reset on caused a port enable change.
158*4882a593Smuzhiyun * Turning reset off causes a port connect
159*4882a593Smuzhiyun * status change. Clear these changes. */
160*4882a593Smuzhiyun CLR_RH_PORTSTAT(USBPORTSC_CSC | USBPORTSC_PEC);
161*4882a593Smuzhiyun SET_RH_PORTSTAT(USBPORTSC_PE);
162*4882a593Smuzhiyun }
163*4882a593Smuzhiyun }
164*4882a593Smuzhiyun if (unlikely(status & USBPORTSC_RD)) {
165*4882a593Smuzhiyun if (!test_bit(port, &uhci->resuming_ports)) {
166*4882a593Smuzhiyun
167*4882a593Smuzhiyun /* Port received a wakeup request */
168*4882a593Smuzhiyun set_bit(port, &uhci->resuming_ports);
169*4882a593Smuzhiyun uhci->ports_timeout = jiffies +
170*4882a593Smuzhiyun msecs_to_jiffies(USB_RESUME_TIMEOUT);
171*4882a593Smuzhiyun usb_hcd_start_port_resume(
172*4882a593Smuzhiyun &uhci_to_hcd(uhci)->self, port);
173*4882a593Smuzhiyun
174*4882a593Smuzhiyun /* Make sure we see the port again
175*4882a593Smuzhiyun * after the resuming period is over. */
176*4882a593Smuzhiyun mod_timer(&uhci_to_hcd(uhci)->rh_timer,
177*4882a593Smuzhiyun uhci->ports_timeout);
178*4882a593Smuzhiyun } else if (time_after_eq(jiffies,
179*4882a593Smuzhiyun uhci->ports_timeout)) {
180*4882a593Smuzhiyun uhci_finish_suspend(uhci, port, port_addr);
181*4882a593Smuzhiyun }
182*4882a593Smuzhiyun }
183*4882a593Smuzhiyun }
184*4882a593Smuzhiyun }
185*4882a593Smuzhiyun
uhci_hub_status_data(struct usb_hcd * hcd,char * buf)186*4882a593Smuzhiyun static int uhci_hub_status_data(struct usb_hcd *hcd, char *buf)
187*4882a593Smuzhiyun {
188*4882a593Smuzhiyun struct uhci_hcd *uhci = hcd_to_uhci(hcd);
189*4882a593Smuzhiyun unsigned long flags;
190*4882a593Smuzhiyun int status = 0;
191*4882a593Smuzhiyun
192*4882a593Smuzhiyun spin_lock_irqsave(&uhci->lock, flags);
193*4882a593Smuzhiyun
194*4882a593Smuzhiyun uhci_scan_schedule(uhci);
195*4882a593Smuzhiyun if (!HCD_HW_ACCESSIBLE(hcd) || uhci->dead)
196*4882a593Smuzhiyun goto done;
197*4882a593Smuzhiyun uhci_check_ports(uhci);
198*4882a593Smuzhiyun
199*4882a593Smuzhiyun status = get_hub_status_data(uhci, buf);
200*4882a593Smuzhiyun
201*4882a593Smuzhiyun switch (uhci->rh_state) {
202*4882a593Smuzhiyun case UHCI_RH_SUSPENDED:
203*4882a593Smuzhiyun /* if port change, ask to be resumed */
204*4882a593Smuzhiyun if (status || uhci->resuming_ports) {
205*4882a593Smuzhiyun status = 1;
206*4882a593Smuzhiyun usb_hcd_resume_root_hub(hcd);
207*4882a593Smuzhiyun }
208*4882a593Smuzhiyun break;
209*4882a593Smuzhiyun
210*4882a593Smuzhiyun case UHCI_RH_AUTO_STOPPED:
211*4882a593Smuzhiyun /* if port change, auto start */
212*4882a593Smuzhiyun if (status)
213*4882a593Smuzhiyun wakeup_rh(uhci);
214*4882a593Smuzhiyun break;
215*4882a593Smuzhiyun
216*4882a593Smuzhiyun case UHCI_RH_RUNNING:
217*4882a593Smuzhiyun /* are any devices attached? */
218*4882a593Smuzhiyun if (!any_ports_active(uhci)) {
219*4882a593Smuzhiyun uhci->rh_state = UHCI_RH_RUNNING_NODEVS;
220*4882a593Smuzhiyun uhci->auto_stop_time = jiffies + HZ;
221*4882a593Smuzhiyun }
222*4882a593Smuzhiyun break;
223*4882a593Smuzhiyun
224*4882a593Smuzhiyun case UHCI_RH_RUNNING_NODEVS:
225*4882a593Smuzhiyun /* auto-stop if nothing connected for 1 second */
226*4882a593Smuzhiyun if (any_ports_active(uhci))
227*4882a593Smuzhiyun uhci->rh_state = UHCI_RH_RUNNING;
228*4882a593Smuzhiyun else if (time_after_eq(jiffies, uhci->auto_stop_time) &&
229*4882a593Smuzhiyun !uhci->wait_for_hp)
230*4882a593Smuzhiyun suspend_rh(uhci, UHCI_RH_AUTO_STOPPED);
231*4882a593Smuzhiyun break;
232*4882a593Smuzhiyun
233*4882a593Smuzhiyun default:
234*4882a593Smuzhiyun break;
235*4882a593Smuzhiyun }
236*4882a593Smuzhiyun
237*4882a593Smuzhiyun done:
238*4882a593Smuzhiyun spin_unlock_irqrestore(&uhci->lock, flags);
239*4882a593Smuzhiyun return status;
240*4882a593Smuzhiyun }
241*4882a593Smuzhiyun
242*4882a593Smuzhiyun /* size of returned buffer is part of USB spec */
uhci_hub_control(struct usb_hcd * hcd,u16 typeReq,u16 wValue,u16 wIndex,char * buf,u16 wLength)243*4882a593Smuzhiyun static int uhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
244*4882a593Smuzhiyun u16 wIndex, char *buf, u16 wLength)
245*4882a593Smuzhiyun {
246*4882a593Smuzhiyun struct uhci_hcd *uhci = hcd_to_uhci(hcd);
247*4882a593Smuzhiyun int status, lstatus, retval = 0;
248*4882a593Smuzhiyun unsigned int port = wIndex - 1;
249*4882a593Smuzhiyun unsigned long port_addr = USBPORTSC1 + 2 * port;
250*4882a593Smuzhiyun u16 wPortChange, wPortStatus;
251*4882a593Smuzhiyun unsigned long flags;
252*4882a593Smuzhiyun
253*4882a593Smuzhiyun if (!HCD_HW_ACCESSIBLE(hcd) || uhci->dead)
254*4882a593Smuzhiyun return -ETIMEDOUT;
255*4882a593Smuzhiyun
256*4882a593Smuzhiyun spin_lock_irqsave(&uhci->lock, flags);
257*4882a593Smuzhiyun switch (typeReq) {
258*4882a593Smuzhiyun
259*4882a593Smuzhiyun case GetHubStatus:
260*4882a593Smuzhiyun *(__le32 *)buf = cpu_to_le32(0);
261*4882a593Smuzhiyun retval = 4; /* hub power */
262*4882a593Smuzhiyun break;
263*4882a593Smuzhiyun case GetPortStatus:
264*4882a593Smuzhiyun if (port >= uhci->rh_numports)
265*4882a593Smuzhiyun goto err;
266*4882a593Smuzhiyun
267*4882a593Smuzhiyun uhci_check_ports(uhci);
268*4882a593Smuzhiyun status = uhci_readw(uhci, port_addr);
269*4882a593Smuzhiyun
270*4882a593Smuzhiyun /* Intel controllers report the OverCurrent bit active on.
271*4882a593Smuzhiyun * VIA controllers report it active off, so we'll adjust the
272*4882a593Smuzhiyun * bit value. (It's not standardized in the UHCI spec.)
273*4882a593Smuzhiyun */
274*4882a593Smuzhiyun if (uhci->oc_low)
275*4882a593Smuzhiyun status ^= USBPORTSC_OC;
276*4882a593Smuzhiyun
277*4882a593Smuzhiyun /* UHCI doesn't support C_RESET (always false) */
278*4882a593Smuzhiyun wPortChange = lstatus = 0;
279*4882a593Smuzhiyun if (status & USBPORTSC_CSC)
280*4882a593Smuzhiyun wPortChange |= USB_PORT_STAT_C_CONNECTION;
281*4882a593Smuzhiyun if (status & USBPORTSC_PEC)
282*4882a593Smuzhiyun wPortChange |= USB_PORT_STAT_C_ENABLE;
283*4882a593Smuzhiyun if ((status & USBPORTSC_OCC) && !ignore_oc)
284*4882a593Smuzhiyun wPortChange |= USB_PORT_STAT_C_OVERCURRENT;
285*4882a593Smuzhiyun
286*4882a593Smuzhiyun if (test_bit(port, &uhci->port_c_suspend)) {
287*4882a593Smuzhiyun wPortChange |= USB_PORT_STAT_C_SUSPEND;
288*4882a593Smuzhiyun lstatus |= 1;
289*4882a593Smuzhiyun }
290*4882a593Smuzhiyun if (test_bit(port, &uhci->resuming_ports))
291*4882a593Smuzhiyun lstatus |= 4;
292*4882a593Smuzhiyun
293*4882a593Smuzhiyun /* UHCI has no power switching (always on) */
294*4882a593Smuzhiyun wPortStatus = USB_PORT_STAT_POWER;
295*4882a593Smuzhiyun if (status & USBPORTSC_CCS)
296*4882a593Smuzhiyun wPortStatus |= USB_PORT_STAT_CONNECTION;
297*4882a593Smuzhiyun if (status & USBPORTSC_PE) {
298*4882a593Smuzhiyun wPortStatus |= USB_PORT_STAT_ENABLE;
299*4882a593Smuzhiyun if (status & SUSPEND_BITS)
300*4882a593Smuzhiyun wPortStatus |= USB_PORT_STAT_SUSPEND;
301*4882a593Smuzhiyun }
302*4882a593Smuzhiyun if (status & USBPORTSC_OC)
303*4882a593Smuzhiyun wPortStatus |= USB_PORT_STAT_OVERCURRENT;
304*4882a593Smuzhiyun if (status & USBPORTSC_PR)
305*4882a593Smuzhiyun wPortStatus |= USB_PORT_STAT_RESET;
306*4882a593Smuzhiyun if (status & USBPORTSC_LSDA)
307*4882a593Smuzhiyun wPortStatus |= USB_PORT_STAT_LOW_SPEED;
308*4882a593Smuzhiyun
309*4882a593Smuzhiyun if (wPortChange)
310*4882a593Smuzhiyun dev_dbg(uhci_dev(uhci), "port %d portsc %04x,%02x\n",
311*4882a593Smuzhiyun wIndex, status, lstatus);
312*4882a593Smuzhiyun
313*4882a593Smuzhiyun *(__le16 *)buf = cpu_to_le16(wPortStatus);
314*4882a593Smuzhiyun *(__le16 *)(buf + 2) = cpu_to_le16(wPortChange);
315*4882a593Smuzhiyun retval = 4;
316*4882a593Smuzhiyun break;
317*4882a593Smuzhiyun case SetHubFeature: /* We don't implement these */
318*4882a593Smuzhiyun case ClearHubFeature:
319*4882a593Smuzhiyun switch (wValue) {
320*4882a593Smuzhiyun case C_HUB_OVER_CURRENT:
321*4882a593Smuzhiyun case C_HUB_LOCAL_POWER:
322*4882a593Smuzhiyun break;
323*4882a593Smuzhiyun default:
324*4882a593Smuzhiyun goto err;
325*4882a593Smuzhiyun }
326*4882a593Smuzhiyun break;
327*4882a593Smuzhiyun case SetPortFeature:
328*4882a593Smuzhiyun if (port >= uhci->rh_numports)
329*4882a593Smuzhiyun goto err;
330*4882a593Smuzhiyun
331*4882a593Smuzhiyun switch (wValue) {
332*4882a593Smuzhiyun case USB_PORT_FEAT_SUSPEND:
333*4882a593Smuzhiyun SET_RH_PORTSTAT(USBPORTSC_SUSP);
334*4882a593Smuzhiyun break;
335*4882a593Smuzhiyun case USB_PORT_FEAT_RESET:
336*4882a593Smuzhiyun SET_RH_PORTSTAT(USBPORTSC_PR);
337*4882a593Smuzhiyun
338*4882a593Smuzhiyun /* Reset terminates Resume signalling */
339*4882a593Smuzhiyun uhci_finish_suspend(uhci, port, port_addr);
340*4882a593Smuzhiyun
341*4882a593Smuzhiyun /* USB v2.0 7.1.7.5 */
342*4882a593Smuzhiyun uhci->ports_timeout = jiffies +
343*4882a593Smuzhiyun msecs_to_jiffies(USB_RESUME_TIMEOUT);
344*4882a593Smuzhiyun break;
345*4882a593Smuzhiyun case USB_PORT_FEAT_POWER:
346*4882a593Smuzhiyun /* UHCI has no power switching */
347*4882a593Smuzhiyun break;
348*4882a593Smuzhiyun default:
349*4882a593Smuzhiyun goto err;
350*4882a593Smuzhiyun }
351*4882a593Smuzhiyun break;
352*4882a593Smuzhiyun case ClearPortFeature:
353*4882a593Smuzhiyun if (port >= uhci->rh_numports)
354*4882a593Smuzhiyun goto err;
355*4882a593Smuzhiyun
356*4882a593Smuzhiyun switch (wValue) {
357*4882a593Smuzhiyun case USB_PORT_FEAT_ENABLE:
358*4882a593Smuzhiyun CLR_RH_PORTSTAT(USBPORTSC_PE);
359*4882a593Smuzhiyun
360*4882a593Smuzhiyun /* Disable terminates Resume signalling */
361*4882a593Smuzhiyun uhci_finish_suspend(uhci, port, port_addr);
362*4882a593Smuzhiyun break;
363*4882a593Smuzhiyun case USB_PORT_FEAT_C_ENABLE:
364*4882a593Smuzhiyun CLR_RH_PORTSTAT(USBPORTSC_PEC);
365*4882a593Smuzhiyun break;
366*4882a593Smuzhiyun case USB_PORT_FEAT_SUSPEND:
367*4882a593Smuzhiyun if (!(uhci_readw(uhci, port_addr) & USBPORTSC_SUSP)) {
368*4882a593Smuzhiyun
369*4882a593Smuzhiyun /* Make certain the port isn't suspended */
370*4882a593Smuzhiyun uhci_finish_suspend(uhci, port, port_addr);
371*4882a593Smuzhiyun } else if (!test_and_set_bit(port,
372*4882a593Smuzhiyun &uhci->resuming_ports)) {
373*4882a593Smuzhiyun SET_RH_PORTSTAT(USBPORTSC_RD);
374*4882a593Smuzhiyun
375*4882a593Smuzhiyun /* The controller won't allow RD to be set
376*4882a593Smuzhiyun * if the port is disabled. When this happens
377*4882a593Smuzhiyun * just skip the Resume signalling.
378*4882a593Smuzhiyun */
379*4882a593Smuzhiyun if (!(uhci_readw(uhci, port_addr) &
380*4882a593Smuzhiyun USBPORTSC_RD))
381*4882a593Smuzhiyun uhci_finish_suspend(uhci, port,
382*4882a593Smuzhiyun port_addr);
383*4882a593Smuzhiyun else
384*4882a593Smuzhiyun /* USB v2.0 7.1.7.7 */
385*4882a593Smuzhiyun uhci->ports_timeout = jiffies +
386*4882a593Smuzhiyun msecs_to_jiffies(20);
387*4882a593Smuzhiyun }
388*4882a593Smuzhiyun break;
389*4882a593Smuzhiyun case USB_PORT_FEAT_C_SUSPEND:
390*4882a593Smuzhiyun clear_bit(port, &uhci->port_c_suspend);
391*4882a593Smuzhiyun break;
392*4882a593Smuzhiyun case USB_PORT_FEAT_POWER:
393*4882a593Smuzhiyun /* UHCI has no power switching */
394*4882a593Smuzhiyun goto err;
395*4882a593Smuzhiyun case USB_PORT_FEAT_C_CONNECTION:
396*4882a593Smuzhiyun CLR_RH_PORTSTAT(USBPORTSC_CSC);
397*4882a593Smuzhiyun break;
398*4882a593Smuzhiyun case USB_PORT_FEAT_C_OVER_CURRENT:
399*4882a593Smuzhiyun CLR_RH_PORTSTAT(USBPORTSC_OCC);
400*4882a593Smuzhiyun break;
401*4882a593Smuzhiyun case USB_PORT_FEAT_C_RESET:
402*4882a593Smuzhiyun /* this driver won't report these */
403*4882a593Smuzhiyun break;
404*4882a593Smuzhiyun default:
405*4882a593Smuzhiyun goto err;
406*4882a593Smuzhiyun }
407*4882a593Smuzhiyun break;
408*4882a593Smuzhiyun case GetHubDescriptor:
409*4882a593Smuzhiyun retval = min_t(unsigned int, sizeof(root_hub_hub_des), wLength);
410*4882a593Smuzhiyun memcpy(buf, root_hub_hub_des, retval);
411*4882a593Smuzhiyun if (retval > 2)
412*4882a593Smuzhiyun buf[2] = uhci->rh_numports;
413*4882a593Smuzhiyun break;
414*4882a593Smuzhiyun default:
415*4882a593Smuzhiyun err:
416*4882a593Smuzhiyun retval = -EPIPE;
417*4882a593Smuzhiyun }
418*4882a593Smuzhiyun spin_unlock_irqrestore(&uhci->lock, flags);
419*4882a593Smuzhiyun
420*4882a593Smuzhiyun return retval;
421*4882a593Smuzhiyun }
422