aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/host/ehci-pci.c
diff options
context:
space:
mode:
authorJeff Garzik <jgarzik@pobox.com>2005-11-29 03:57:29 -0500
committerJeff Garzik <jgarzik@pobox.com>2005-11-29 03:57:29 -0500
commit5f3fdeb6242d84126e4bd45ac9e2246833fe8352 (patch)
tree011ff83db06c9d42c72544e8c10c06c978ba88ce /drivers/usb/host/ehci-pci.c
parent98a5d024eb589a863c1c79f3c3f8ecb666c0eec9 (diff)
parentb71d4da092801634d04190693a38ca03bdbe2505 (diff)
Merge branch 'upstream'
Diffstat (limited to 'drivers/usb/host/ehci-pci.c')
-rw-r--r--drivers/usb/host/ehci-pci.c359
1 files changed, 170 insertions, 189 deletions
diff --git a/drivers/usb/host/ehci-pci.c b/drivers/usb/host/ehci-pci.c
index dfd9bd0b1828..441c26064b44 100644
--- a/drivers/usb/host/ehci-pci.c
+++ b/drivers/usb/host/ehci-pci.c
@@ -27,7 +27,7 @@
27/* EHCI 0.96 (and later) section 5.1 says how to kick BIOS/SMM/... 27/* EHCI 0.96 (and later) section 5.1 says how to kick BIOS/SMM/...
28 * off the controller (maybe it can boot from highspeed USB disks). 28 * off the controller (maybe it can boot from highspeed USB disks).
29 */ 29 */
30static int bios_handoff (struct ehci_hcd *ehci, int where, u32 cap) 30static int bios_handoff(struct ehci_hcd *ehci, int where, u32 cap)
31{ 31{
32 struct pci_dev *pdev = to_pci_dev(ehci_to_hcd(ehci)->self.controller); 32 struct pci_dev *pdev = to_pci_dev(ehci_to_hcd(ehci)->self.controller);
33 33
@@ -48,7 +48,7 @@ static int bios_handoff (struct ehci_hcd *ehci, int where, u32 cap)
48 where, cap); 48 where, cap);
49 // some BIOS versions seem buggy... 49 // some BIOS versions seem buggy...
50 // return 1; 50 // return 1;
51 ehci_warn (ehci, "continuing after BIOS bug...\n"); 51 ehci_warn(ehci, "continuing after BIOS bug...\n");
52 /* disable all SMIs, and clear "BIOS owns" flag */ 52 /* disable all SMIs, and clear "BIOS owns" flag */
53 pci_write_config_dword(pdev, where + 4, 0); 53 pci_write_config_dword(pdev, where + 4, 0);
54 pci_write_config_byte(pdev, where + 2, 0); 54 pci_write_config_byte(pdev, where + 2, 0);
@@ -58,96 +58,47 @@ static int bios_handoff (struct ehci_hcd *ehci, int where, u32 cap)
58 return 0; 58 return 0;
59} 59}
60 60
61/* called by khubd or root hub init threads */ 61/* called after powerup, by probe or system-pm "wakeup" */
62static int ehci_pci_reset (struct usb_hcd *hcd) 62static int ehci_pci_reinit(struct ehci_hcd *ehci, struct pci_dev *pdev)
63{ 63{
64 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
65 u32 temp; 64 u32 temp;
65 int retval;
66 unsigned count = 256/4; 66 unsigned count = 256/4;
67 67
68 spin_lock_init (&ehci->lock); 68 /* optional debug port, normally in the first BAR */
69 69 temp = pci_find_capability(pdev, 0x0a);
70 ehci->caps = hcd->regs; 70 if (temp) {
71 ehci->regs = hcd->regs + HC_LENGTH (readl (&ehci->caps->hc_capbase)); 71 pci_read_config_dword(pdev, temp, &temp);
72 dbg_hcs_params (ehci, "reset"); 72 temp >>= 16;
73 dbg_hcc_params (ehci, "reset"); 73 if ((temp & (3 << 13)) == (1 << 13)) {
74 74 temp &= 0x1fff;
75 /* cache this readonly data; minimize chip reads */ 75 ehci->debug = ehci_to_hcd(ehci)->regs + temp;
76 ehci->hcs_params = readl (&ehci->caps->hcs_params); 76 temp = readl(&ehci->debug->control);
77 77 ehci_info(ehci, "debug port %d%s\n",
78 if (hcd->self.controller->bus == &pci_bus_type) { 78 HCS_DEBUG_PORT(ehci->hcs_params),
79 struct pci_dev *pdev = to_pci_dev(hcd->self.controller); 79 (temp & DBGP_ENABLED)
80 80 ? " IN USE"
81 switch (pdev->vendor) { 81 : "");
82 case PCI_VENDOR_ID_TDI: 82 if (!(temp & DBGP_ENABLED))
83 if (pdev->device == PCI_DEVICE_ID_TDI_EHCI) { 83 ehci->debug = NULL;
84 ehci->is_tdi_rh_tt = 1;
85 tdi_reset (ehci);
86 }
87 break;
88 case PCI_VENDOR_ID_AMD:
89 /* AMD8111 EHCI doesn't work, according to AMD errata */
90 if (pdev->device == 0x7463) {
91 ehci_info (ehci, "ignoring AMD8111 (errata)\n");
92 return -EIO;
93 }
94 break;
95 case PCI_VENDOR_ID_NVIDIA:
96 /* NVidia reports that certain chips don't handle
97 * QH, ITD, or SITD addresses above 2GB. (But TD,
98 * data buffer, and periodic schedule are normal.)
99 */
100 switch (pdev->device) {
101 case 0x003c: /* MCP04 */
102 case 0x005b: /* CK804 */
103 case 0x00d8: /* CK8 */
104 case 0x00e8: /* CK8S */
105 if (pci_set_consistent_dma_mask(pdev,
106 DMA_31BIT_MASK) < 0)
107 ehci_warn (ehci, "can't enable NVidia "
108 "workaround for >2GB RAM\n");
109 break;
110 }
111 break;
112 }
113
114 /* optional debug port, normally in the first BAR */
115 temp = pci_find_capability (pdev, 0x0a);
116 if (temp) {
117 pci_read_config_dword(pdev, temp, &temp);
118 temp >>= 16;
119 if ((temp & (3 << 13)) == (1 << 13)) {
120 temp &= 0x1fff;
121 ehci->debug = hcd->regs + temp;
122 temp = readl (&ehci->debug->control);
123 ehci_info (ehci, "debug port %d%s\n",
124 HCS_DEBUG_PORT(ehci->hcs_params),
125 (temp & DBGP_ENABLED)
126 ? " IN USE"
127 : "");
128 if (!(temp & DBGP_ENABLED))
129 ehci->debug = NULL;
130 }
131 } 84 }
85 }
132 86
133 temp = HCC_EXT_CAPS (readl (&ehci->caps->hcc_params)); 87 temp = HCC_EXT_CAPS(readl(&ehci->caps->hcc_params));
134 } else
135 temp = 0;
136 88
137 /* EHCI 0.96 and later may have "extended capabilities" */ 89 /* EHCI 0.96 and later may have "extended capabilities" */
138 while (temp && count--) { 90 while (temp && count--) {
139 u32 cap; 91 u32 cap;
140 92
141 pci_read_config_dword (to_pci_dev(hcd->self.controller), 93 pci_read_config_dword(pdev, temp, &cap);
142 temp, &cap); 94 ehci_dbg(ehci, "capability %04x at %02x\n", cap, temp);
143 ehci_dbg (ehci, "capability %04x at %02x\n", cap, temp);
144 switch (cap & 0xff) { 95 switch (cap & 0xff) {
145 case 1: /* BIOS/SMM/... handoff */ 96 case 1: /* BIOS/SMM/... handoff */
146 if (bios_handoff (ehci, temp, cap) != 0) 97 if (bios_handoff(ehci, temp, cap) != 0)
147 return -EOPNOTSUPP; 98 return -EOPNOTSUPP;
148 break; 99 break;
149 case 0: /* illegal reserved capability */ 100 case 0: /* illegal reserved capability */
150 ehci_warn (ehci, "illegal capability!\n"); 101 ehci_dbg(ehci, "illegal capability!\n");
151 cap = 0; 102 cap = 0;
152 /* FALLTHROUGH */ 103 /* FALLTHROUGH */
153 default: /* unknown */ 104 default: /* unknown */
@@ -156,77 +107,109 @@ static int ehci_pci_reset (struct usb_hcd *hcd)
156 temp = (cap >> 8) & 0xff; 107 temp = (cap >> 8) & 0xff;
157 } 108 }
158 if (!count) { 109 if (!count) {
159 ehci_err (ehci, "bogus capabilities ... PCI problems!\n"); 110 ehci_err(ehci, "bogus capabilities ... PCI problems!\n");
160 return -EIO; 111 return -EIO;
161 } 112 }
162 if (ehci_is_TDI(ehci))
163 ehci_reset (ehci);
164 113
165 ehci_port_power (ehci, 0); 114 /* PCI Memory-Write-Invalidate cycle support is optional (uncommon) */
115 retval = pci_set_mwi(pdev);
116 if (!retval)
117 ehci_dbg(ehci, "MWI active\n");
118
119 ehci_port_power(ehci, 0);
120
121 return 0;
122}
123
124/* called by khubd or root hub (re)init threads; leaves HC in halt state */
125static int ehci_pci_reset(struct usb_hcd *hcd)
126{
127 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
128 struct pci_dev *pdev = to_pci_dev(hcd->self.controller);
129 u32 temp;
130 int retval;
131
132 ehci->caps = hcd->regs;
133 ehci->regs = hcd->regs + HC_LENGTH(readl(&ehci->caps->hc_capbase));
134 dbg_hcs_params(ehci, "reset");
135 dbg_hcc_params(ehci, "reset");
136
137 /* cache this readonly data; minimize chip reads */
138 ehci->hcs_params = readl(&ehci->caps->hcs_params);
139
140 retval = ehci_halt(ehci);
141 if (retval)
142 return retval;
143
144 /* NOTE: only the parts below this line are PCI-specific */
145
146 switch (pdev->vendor) {
147 case PCI_VENDOR_ID_TDI:
148 if (pdev->device == PCI_DEVICE_ID_TDI_EHCI) {
149 ehci->is_tdi_rh_tt = 1;
150 tdi_reset(ehci);
151 }
152 break;
153 case PCI_VENDOR_ID_AMD:
154 /* AMD8111 EHCI doesn't work, according to AMD errata */
155 if (pdev->device == 0x7463) {
156 ehci_info(ehci, "ignoring AMD8111 (errata)\n");
157 return -EIO;
158 }
159 break;
160 case PCI_VENDOR_ID_NVIDIA:
161 /* NVidia reports that certain chips don't handle
162 * QH, ITD, or SITD addresses above 2GB. (But TD,
163 * data buffer, and periodic schedule are normal.)
164 */
165 switch (pdev->device) {
166 case 0x003c: /* MCP04 */
167 case 0x005b: /* CK804 */
168 case 0x00d8: /* CK8 */
169 case 0x00e8: /* CK8S */
170 if (pci_set_consistent_dma_mask(pdev,
171 DMA_31BIT_MASK) < 0)
172 ehci_warn(ehci, "can't enable NVidia "
173 "workaround for >2GB RAM\n");
174 break;
175 }
176 break;
177 }
178
179 if (ehci_is_TDI(ehci))
180 ehci_reset(ehci);
166 181
167 /* at least the Genesys GL880S needs fixup here */ 182 /* at least the Genesys GL880S needs fixup here */
168 temp = HCS_N_CC(ehci->hcs_params) * HCS_N_PCC(ehci->hcs_params); 183 temp = HCS_N_CC(ehci->hcs_params) * HCS_N_PCC(ehci->hcs_params);
169 temp &= 0x0f; 184 temp &= 0x0f;
170 if (temp && HCS_N_PORTS(ehci->hcs_params) > temp) { 185 if (temp && HCS_N_PORTS(ehci->hcs_params) > temp) {
171 ehci_dbg (ehci, "bogus port configuration: " 186 ehci_dbg(ehci, "bogus port configuration: "
172 "cc=%d x pcc=%d < ports=%d\n", 187 "cc=%d x pcc=%d < ports=%d\n",
173 HCS_N_CC(ehci->hcs_params), 188 HCS_N_CC(ehci->hcs_params),
174 HCS_N_PCC(ehci->hcs_params), 189 HCS_N_PCC(ehci->hcs_params),
175 HCS_N_PORTS(ehci->hcs_params)); 190 HCS_N_PORTS(ehci->hcs_params));
176 191
177 if (hcd->self.controller->bus == &pci_bus_type) { 192 switch (pdev->vendor) {
178 struct pci_dev *pdev; 193 case 0x17a0: /* GENESYS */
179 194 /* GL880S: should be PORTS=2 */
180 pdev = to_pci_dev(hcd->self.controller); 195 temp |= (ehci->hcs_params & ~0xf);
181 switch (pdev->vendor) { 196 ehci->hcs_params = temp;
182 case 0x17a0: /* GENESYS */ 197 break;
183 /* GL880S: should be PORTS=2 */ 198 case PCI_VENDOR_ID_NVIDIA:
184 temp |= (ehci->hcs_params & ~0xf); 199 /* NF4: should be PCC=10 */
185 ehci->hcs_params = temp; 200 break;
186 break;
187 case PCI_VENDOR_ID_NVIDIA:
188 /* NF4: should be PCC=10 */
189 break;
190 }
191 } 201 }
192 } 202 }
193 203
194 /* force HC to halt state */ 204 /* Serial Bus Release Number is at PCI 0x60 offset */
195 return ehci_halt (ehci); 205 pci_read_config_byte(pdev, 0x60, &ehci->sbrn);
196}
197
198static int ehci_pci_start (struct usb_hcd *hcd)
199{
200 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
201 int result = 0;
202
203 if (hcd->self.controller->bus == &pci_bus_type) {
204 struct pci_dev *pdev;
205 u16 port_wake;
206
207 pdev = to_pci_dev(hcd->self.controller);
208
209 /* Serial Bus Release Number is at PCI 0x60 offset */
210 pci_read_config_byte(pdev, 0x60, &ehci->sbrn);
211
212 /* port wake capability, reported by boot firmware */
213 pci_read_config_word(pdev, 0x62, &port_wake);
214 hcd->can_wakeup = (port_wake & 1) != 0;
215 206
216 /* help hc dma work well with cachelines */ 207 /* REVISIT: per-port wake capability (PCI 0x62) currently unused */
217 result = pci_set_mwi(pdev);
218 if (result)
219 ehci_dbg(ehci, "unable to enable MWI - not fatal.\n");
220 }
221
222 return ehci_run (hcd);
223}
224 208
225/* always called by thread; normally rmmod */ 209 retval = ehci_pci_reinit(ehci, pdev);
226 210
227static void ehci_pci_stop (struct usb_hcd *hcd) 211 /* finish init */
228{ 212 return ehci_init(hcd);
229 ehci_stop (hcd);
230} 213}
231 214
232/*-------------------------------------------------------------------------*/ 215/*-------------------------------------------------------------------------*/
@@ -235,90 +218,88 @@ static void ehci_pci_stop (struct usb_hcd *hcd)
235 218
236/* suspend/resume, section 4.3 */ 219/* suspend/resume, section 4.3 */
237 220
238/* These routines rely on the bus (pci, platform, etc) 221/* These routines rely on the PCI bus glue
239 * to handle powerdown and wakeup, and currently also on 222 * to handle powerdown and wakeup, and currently also on
240 * transceivers that don't need any software attention to set up 223 * transceivers that don't need any software attention to set up
241 * the right sort of wakeup. 224 * the right sort of wakeup.
225 * Also they depend on separate root hub suspend/resume.
242 */ 226 */
243 227
244static int ehci_pci_suspend (struct usb_hcd *hcd, pm_message_t message) 228static int ehci_pci_suspend(struct usb_hcd *hcd, pm_message_t message)
245{ 229{
246 struct ehci_hcd *ehci = hcd_to_ehci (hcd); 230 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
247 231
248 if (time_before (jiffies, ehci->next_statechange)) 232 if (time_before(jiffies, ehci->next_statechange))
249 msleep (100); 233 msleep(10);
250 234
251#ifdef CONFIG_USB_SUSPEND 235 // could save FLADJ in case of Vaux power loss
252 (void) usb_suspend_device (hcd->self.root_hub);
253#else
254 usb_lock_device (hcd->self.root_hub);
255 (void) ehci_bus_suspend (hcd);
256 usb_unlock_device (hcd->self.root_hub);
257#endif
258
259 // save (PCI) FLADJ in case of Vaux power loss
260 // ... we'd only use it to handle clock skew 236 // ... we'd only use it to handle clock skew
261 237
262 return 0; 238 return 0;
263} 239}
264 240
265static int ehci_pci_resume (struct usb_hcd *hcd) 241static int ehci_pci_resume(struct usb_hcd *hcd)
266{ 242{
267 struct ehci_hcd *ehci = hcd_to_ehci (hcd); 243 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
268 unsigned port; 244 unsigned port;
269 struct usb_device *root = hcd->self.root_hub; 245 struct usb_device *root = hcd->self.root_hub;
246 struct pci_dev *pdev = to_pci_dev(hcd->self.controller);
270 int retval = -EINVAL; 247 int retval = -EINVAL;
271 248
272 // maybe restore (PCI) FLADJ 249 // maybe restore FLADJ
273 250
274 if (time_before (jiffies, ehci->next_statechange)) 251 if (time_before(jiffies, ehci->next_statechange))
275 msleep (100); 252 msleep(100);
253
254 /* If CF is clear, we lost PCI Vaux power and need to restart. */
255 if (readl(&ehci->regs->configured_flag) != FLAG_CF)
256 goto restart;
276 257
277 /* If any port is suspended (or owned by the companion), 258 /* If any port is suspended (or owned by the companion),
278 * we know we can/must resume the HC (and mustn't reset it). 259 * we know we can/must resume the HC (and mustn't reset it).
260 * We just defer that to the root hub code.
279 */ 261 */
280 for (port = HCS_N_PORTS (ehci->hcs_params); port > 0; ) { 262 for (port = HCS_N_PORTS(ehci->hcs_params); port > 0; ) {
281 u32 status; 263 u32 status;
282 port--; 264 port--;
283 status = readl (&ehci->regs->port_status [port]); 265 status = readl(&ehci->regs->port_status [port]);
284 if (!(status & PORT_POWER)) 266 if (!(status & PORT_POWER))
285 continue; 267 continue;
286 if (status & (PORT_SUSPEND | PORT_OWNER)) { 268 if (status & (PORT_SUSPEND | PORT_RESUME | PORT_OWNER)) {
287 down (&hcd->self.root_hub->serialize); 269 usb_hcd_resume_root_hub(hcd);
288 retval = ehci_bus_resume (hcd); 270 return 0;
289 up (&hcd->self.root_hub->serialize);
290 break;
291 } 271 }
272 }
273
274restart:
275 ehci_dbg(ehci, "lost power, restarting\n");
276 for (port = HCS_N_PORTS(ehci->hcs_params); port > 0; ) {
277 port--;
292 if (!root->children [port]) 278 if (!root->children [port])
293 continue; 279 continue;
294 dbg_port (ehci, __FUNCTION__, port + 1, status); 280 usb_set_device_state(root->children[port],
295 usb_set_device_state (root->children[port],
296 USB_STATE_NOTATTACHED); 281 USB_STATE_NOTATTACHED);
297 } 282 }
298 283
299 /* Else reset, to cope with power loss or flush-to-storage 284 /* Else reset, to cope with power loss or flush-to-storage
300 * style "resume" having activated BIOS during reboot. 285 * style "resume" having let BIOS kick in during reboot.
301 */ 286 */
302 if (port == 0) { 287 (void) ehci_halt(ehci);
303 (void) ehci_halt (ehci); 288 (void) ehci_reset(ehci);
304 (void) ehci_reset (ehci); 289 (void) ehci_pci_reinit(ehci, pdev);
305 (void) ehci_pci_reset (hcd); 290
306 291 /* emptying the schedule aborts any urbs */
307 /* emptying the schedule aborts any urbs */ 292 spin_lock_irq(&ehci->lock);
308 spin_lock_irq (&ehci->lock); 293 if (ehci->reclaim)
309 if (ehci->reclaim) 294 ehci->reclaim_ready = 1;
310 ehci->reclaim_ready = 1; 295 ehci_work(ehci, NULL);
311 ehci_work (ehci, NULL); 296 spin_unlock_irq(&ehci->lock);
312 spin_unlock_irq (&ehci->lock); 297
313 298 /* restart; khubd will disconnect devices */
314 /* restart; khubd will disconnect devices */ 299 retval = ehci_run(hcd);
315 retval = ehci_run (hcd); 300
316 301 /* here we "know" root ports should always stay powered */
317 /* here we "know" root ports should always stay powered; 302 ehci_port_power(ehci, 1);
318 * but some controllers may lose all power.
319 */
320 ehci_port_power (ehci, 1);
321 }
322 303
323 return retval; 304 return retval;
324} 305}
@@ -339,12 +320,12 @@ static const struct hc_driver ehci_pci_hc_driver = {
339 * basic lifecycle operations 320 * basic lifecycle operations
340 */ 321 */
341 .reset = ehci_pci_reset, 322 .reset = ehci_pci_reset,
342 .start = ehci_pci_start, 323 .start = ehci_run,
343#ifdef CONFIG_PM 324#ifdef CONFIG_PM
344 .suspend = ehci_pci_suspend, 325 .suspend = ehci_pci_suspend,
345 .resume = ehci_pci_resume, 326 .resume = ehci_pci_resume,
346#endif 327#endif
347 .stop = ehci_pci_stop, 328 .stop = ehci_stop,
348 329
349 /* 330 /*
350 * managing i/o requests and associated device resources 331 * managing i/o requests and associated device resources
@@ -377,7 +358,7 @@ static const struct pci_device_id pci_ids [] = { {
377 }, 358 },
378 { /* end: all zeroes */ } 359 { /* end: all zeroes */ }
379}; 360};
380MODULE_DEVICE_TABLE (pci, pci_ids); 361MODULE_DEVICE_TABLE(pci, pci_ids);
381 362
382/* pci driver glue; this is a "new style" PCI driver module */ 363/* pci driver glue; this is a "new style" PCI driver module */
383static struct pci_driver ehci_pci_driver = { 364static struct pci_driver ehci_pci_driver = {
@@ -393,22 +374,22 @@ static struct pci_driver ehci_pci_driver = {
393#endif 374#endif
394}; 375};
395 376
396static int __init ehci_hcd_pci_init (void) 377static int __init ehci_hcd_pci_init(void)
397{ 378{
398 if (usb_disabled()) 379 if (usb_disabled())
399 return -ENODEV; 380 return -ENODEV;
400 381
401 pr_debug ("%s: block sizes: qh %Zd qtd %Zd itd %Zd sitd %Zd\n", 382 pr_debug("%s: block sizes: qh %Zd qtd %Zd itd %Zd sitd %Zd\n",
402 hcd_name, 383 hcd_name,
403 sizeof (struct ehci_qh), sizeof (struct ehci_qtd), 384 sizeof(struct ehci_qh), sizeof(struct ehci_qtd),
404 sizeof (struct ehci_itd), sizeof (struct ehci_sitd)); 385 sizeof(struct ehci_itd), sizeof(struct ehci_sitd));
405 386
406 return pci_register_driver (&ehci_pci_driver); 387 return pci_register_driver(&ehci_pci_driver);
407} 388}
408module_init (ehci_hcd_pci_init); 389module_init(ehci_hcd_pci_init);
409 390
410static void __exit ehci_hcd_pci_cleanup (void) 391static void __exit ehci_hcd_pci_cleanup(void)
411{ 392{
412 pci_unregister_driver (&ehci_pci_driver); 393 pci_unregister_driver(&ehci_pci_driver);
413} 394}
414module_exit (ehci_hcd_pci_cleanup); 395module_exit(ehci_hcd_pci_cleanup);