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