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