aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/host/uhci-hcd.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/usb/host/uhci-hcd.c')
-rw-r--r--drivers/usb/host/uhci-hcd.c458
1 files changed, 177 insertions, 281 deletions
diff --git a/drivers/usb/host/uhci-hcd.c b/drivers/usb/host/uhci-hcd.c
index 448b9d1f0e70..fba99b120588 100644
--- a/drivers/usb/host/uhci-hcd.c
+++ b/drivers/usb/host/uhci-hcd.c
@@ -48,7 +48,6 @@
48#include <asm/system.h> 48#include <asm/system.h>
49 49
50#include "uhci-hcd.h" 50#include "uhci-hcd.h"
51#include "pci-quirks.h"
52 51
53/* 52/*
54 * Version Information 53 * Version Information
@@ -94,7 +93,7 @@ static void uhci_get_current_frame_number(struct uhci_hcd *uhci);
94/* 93/*
95 * Calculate the link pointer DMA value for the first Skeleton QH in a frame. 94 * Calculate the link pointer DMA value for the first Skeleton QH in a frame.
96 */ 95 */
97static __le32 uhci_frame_skel_link(struct uhci_hcd *uhci, int frame) 96static __hc32 uhci_frame_skel_link(struct uhci_hcd *uhci, int frame)
98{ 97{
99 int skelnum; 98 int skelnum;
100 99
@@ -116,7 +115,7 @@ static __le32 uhci_frame_skel_link(struct uhci_hcd *uhci, int frame)
116 skelnum = 8 - (int) __ffs(frame | UHCI_NUMFRAMES); 115 skelnum = 8 - (int) __ffs(frame | UHCI_NUMFRAMES);
117 if (skelnum <= 1) 116 if (skelnum <= 1)
118 skelnum = 9; 117 skelnum = 9;
119 return LINK_TO_QH(uhci->skelqh[skelnum]); 118 return LINK_TO_QH(uhci, uhci->skelqh[skelnum]);
120} 119}
121 120
122#include "uhci-debug.c" 121#include "uhci-debug.c"
@@ -135,15 +134,12 @@ static void finish_reset(struct uhci_hcd *uhci)
135 * We have to clear them by hand. 134 * We have to clear them by hand.
136 */ 135 */
137 for (port = 0; port < uhci->rh_numports; ++port) 136 for (port = 0; port < uhci->rh_numports; ++port)
138 outw(0, uhci->io_addr + USBPORTSC1 + (port * 2)); 137 uhci_writew(uhci, 0, USBPORTSC1 + (port * 2));
139 138
140 uhci->port_c_suspend = uhci->resuming_ports = 0; 139 uhci->port_c_suspend = uhci->resuming_ports = 0;
141 uhci->rh_state = UHCI_RH_RESET; 140 uhci->rh_state = UHCI_RH_RESET;
142 uhci->is_stopped = UHCI_IS_STOPPED; 141 uhci->is_stopped = UHCI_IS_STOPPED;
143 uhci_to_hcd(uhci)->state = HC_STATE_HALT;
144 clear_bit(HCD_FLAG_POLL_RH, &uhci_to_hcd(uhci)->flags); 142 clear_bit(HCD_FLAG_POLL_RH, &uhci_to_hcd(uhci)->flags);
145
146 uhci->dead = 0; /* Full reset resurrects the controller */
147} 143}
148 144
149/* 145/*
@@ -153,7 +149,7 @@ static void finish_reset(struct uhci_hcd *uhci)
153static void uhci_hc_died(struct uhci_hcd *uhci) 149static void uhci_hc_died(struct uhci_hcd *uhci)
154{ 150{
155 uhci_get_current_frame_number(uhci); 151 uhci_get_current_frame_number(uhci);
156 uhci_reset_hc(to_pci_dev(uhci_dev(uhci)), uhci->io_addr); 152 uhci->reset_hc(uhci);
157 finish_reset(uhci); 153 finish_reset(uhci);
158 uhci->dead = 1; 154 uhci->dead = 1;
159 155
@@ -168,97 +164,118 @@ static void uhci_hc_died(struct uhci_hcd *uhci)
168 */ 164 */
169static void check_and_reset_hc(struct uhci_hcd *uhci) 165static void check_and_reset_hc(struct uhci_hcd *uhci)
170{ 166{
171 if (uhci_check_and_reset_hc(to_pci_dev(uhci_dev(uhci)), uhci->io_addr)) 167 if (uhci->check_and_reset_hc(uhci))
172 finish_reset(uhci); 168 finish_reset(uhci);
173} 169}
174 170
171#if defined(CONFIG_USB_UHCI_SUPPORT_NON_PCI_HC)
172/*
173 * The two functions below are generic reset functions that are used on systems
174 * that do not have keyboard and mouse legacy support. We assume that we are
175 * running on such a system if CONFIG_USB_UHCI_SUPPORT_NON_PCI_HC is defined.
176 */
177
178/*
179 * Make sure the controller is completely inactive, unable to
180 * generate interrupts or do DMA.
181 */
182static void uhci_generic_reset_hc(struct uhci_hcd *uhci)
183{
184 /* Reset the HC - this will force us to get a
185 * new notification of any already connected
186 * ports due to the virtual disconnect that it
187 * implies.
188 */
189 uhci_writew(uhci, USBCMD_HCRESET, USBCMD);
190 mb();
191 udelay(5);
192 if (uhci_readw(uhci, USBCMD) & USBCMD_HCRESET)
193 dev_warn(uhci_dev(uhci), "HCRESET not completed yet!\n");
194
195 /* Just to be safe, disable interrupt requests and
196 * make sure the controller is stopped.
197 */
198 uhci_writew(uhci, 0, USBINTR);
199 uhci_writew(uhci, 0, USBCMD);
200}
201
202/*
203 * Initialize a controller that was newly discovered or has just been
204 * resumed. In either case we can't be sure of its previous state.
205 *
206 * Returns: 1 if the controller was reset, 0 otherwise.
207 */
208static int uhci_generic_check_and_reset_hc(struct uhci_hcd *uhci)
209{
210 unsigned int cmd, intr;
211
212 /*
213 * When restarting a suspended controller, we expect all the
214 * settings to be the same as we left them:
215 *
216 * Controller is stopped and configured with EGSM set;
217 * No interrupts enabled except possibly Resume Detect.
218 *
219 * If any of these conditions are violated we do a complete reset.
220 */
221
222 cmd = uhci_readw(uhci, USBCMD);
223 if ((cmd & USBCMD_RS) || !(cmd & USBCMD_CF) || !(cmd & USBCMD_EGSM)) {
224 dev_dbg(uhci_dev(uhci), "%s: cmd = 0x%04x\n",
225 __func__, cmd);
226 goto reset_needed;
227 }
228
229 intr = uhci_readw(uhci, USBINTR);
230 if (intr & (~USBINTR_RESUME)) {
231 dev_dbg(uhci_dev(uhci), "%s: intr = 0x%04x\n",
232 __func__, intr);
233 goto reset_needed;
234 }
235 return 0;
236
237reset_needed:
238 dev_dbg(uhci_dev(uhci), "Performing full reset\n");
239 uhci_generic_reset_hc(uhci);
240 return 1;
241}
242#endif /* CONFIG_USB_UHCI_SUPPORT_NON_PCI_HC */
243
175/* 244/*
176 * Store the basic register settings needed by the controller. 245 * Store the basic register settings needed by the controller.
177 */ 246 */
178static void configure_hc(struct uhci_hcd *uhci) 247static void configure_hc(struct uhci_hcd *uhci)
179{ 248{
180 struct pci_dev *pdev = to_pci_dev(uhci_dev(uhci));
181
182 /* Set the frame length to the default: 1 ms exactly */ 249 /* Set the frame length to the default: 1 ms exactly */
183 outb(USBSOF_DEFAULT, uhci->io_addr + USBSOF); 250 uhci_writeb(uhci, USBSOF_DEFAULT, USBSOF);
184 251
185 /* Store the frame list base address */ 252 /* Store the frame list base address */
186 outl(uhci->frame_dma_handle, uhci->io_addr + USBFLBASEADD); 253 uhci_writel(uhci, uhci->frame_dma_handle, USBFLBASEADD);
187 254
188 /* Set the current frame number */ 255 /* Set the current frame number */
189 outw(uhci->frame_number & UHCI_MAX_SOF_NUMBER, 256 uhci_writew(uhci, uhci->frame_number & UHCI_MAX_SOF_NUMBER,
190 uhci->io_addr + USBFRNUM); 257 USBFRNUM);
191
192 /* Mark controller as not halted before we enable interrupts */
193 uhci_to_hcd(uhci)->state = HC_STATE_SUSPENDED;
194 mb();
195
196 /* Enable PIRQ */
197 pci_write_config_word(pdev, USBLEGSUP, USBLEGSUP_DEFAULT);
198 258
199 /* Disable platform-specific non-PME# wakeup */ 259 /* perform any arch/bus specific configuration */
200 if (pdev->vendor == PCI_VENDOR_ID_INTEL) 260 if (uhci->configure_hc)
201 pci_write_config_byte(pdev, USBRES_INTEL, 0); 261 uhci->configure_hc(uhci);
202} 262}
203 263
204
205static int resume_detect_interrupts_are_broken(struct uhci_hcd *uhci) 264static int resume_detect_interrupts_are_broken(struct uhci_hcd *uhci)
206{ 265{
207 int port;
208
209 /* If we have to ignore overcurrent events then almost by definition 266 /* If we have to ignore overcurrent events then almost by definition
210 * we can't depend on resume-detect interrupts. */ 267 * we can't depend on resume-detect interrupts. */
211 if (ignore_oc) 268 if (ignore_oc)
212 return 1; 269 return 1;
213 270
214 switch (to_pci_dev(uhci_dev(uhci))->vendor) { 271 return uhci->resume_detect_interrupts_are_broken ?
215 default: 272 uhci->resume_detect_interrupts_are_broken(uhci) : 0;
216 break;
217
218 case PCI_VENDOR_ID_GENESYS:
219 /* Genesys Logic's GL880S controllers don't generate
220 * resume-detect interrupts.
221 */
222 return 1;
223
224 case PCI_VENDOR_ID_INTEL:
225 /* Some of Intel's USB controllers have a bug that causes
226 * resume-detect interrupts if any port has an over-current
227 * condition. To make matters worse, some motherboards
228 * hardwire unused USB ports' over-current inputs active!
229 * To prevent problems, we will not enable resume-detect
230 * interrupts if any ports are OC.
231 */
232 for (port = 0; port < uhci->rh_numports; ++port) {
233 if (inw(uhci->io_addr + USBPORTSC1 + port * 2) &
234 USBPORTSC_OC)
235 return 1;
236 }
237 break;
238 }
239 return 0;
240} 273}
241 274
242static int global_suspend_mode_is_broken(struct uhci_hcd *uhci) 275static int global_suspend_mode_is_broken(struct uhci_hcd *uhci)
243{ 276{
244 int port; 277 return uhci->global_suspend_mode_is_broken ?
245 const char *sys_info; 278 uhci->global_suspend_mode_is_broken(uhci) : 0;
246 static char bad_Asus_board[] = "A7V8X";
247
248 /* One of Asus's motherboards has a bug which causes it to
249 * wake up immediately from suspend-to-RAM if any of the ports
250 * are connected. In such cases we will not set EGSM.
251 */
252 sys_info = dmi_get_system_info(DMI_BOARD_NAME);
253 if (sys_info && !strcmp(sys_info, bad_Asus_board)) {
254 for (port = 0; port < uhci->rh_numports; ++port) {
255 if (inw(uhci->io_addr + USBPORTSC1 + port * 2) &
256 USBPORTSC_CCS)
257 return 1;
258 }
259 }
260
261 return 0;
262} 279}
263 280
264static void suspend_rh(struct uhci_hcd *uhci, enum uhci_rh_state new_state) 281static void suspend_rh(struct uhci_hcd *uhci, enum uhci_rh_state new_state)
@@ -321,8 +338,8 @@ __acquires(uhci->lock)
321 !int_enable) 338 !int_enable)
322 uhci->RD_enable = int_enable = 0; 339 uhci->RD_enable = int_enable = 0;
323 340
324 outw(int_enable, uhci->io_addr + USBINTR); 341 uhci_writew(uhci, int_enable, USBINTR);
325 outw(egsm_enable | USBCMD_CF, uhci->io_addr + USBCMD); 342 uhci_writew(uhci, egsm_enable | USBCMD_CF, USBCMD);
326 mb(); 343 mb();
327 udelay(5); 344 udelay(5);
328 345
@@ -331,7 +348,7 @@ __acquires(uhci->lock)
331 * controller should stop after a few microseconds. Otherwise 348 * controller should stop after a few microseconds. Otherwise
332 * we will give the controller one frame to stop. 349 * we will give the controller one frame to stop.
333 */ 350 */
334 if (!auto_stop && !(inw(uhci->io_addr + USBSTS) & USBSTS_HCH)) { 351 if (!auto_stop && !(uhci_readw(uhci, USBSTS) & USBSTS_HCH)) {
335 uhci->rh_state = UHCI_RH_SUSPENDING; 352 uhci->rh_state = UHCI_RH_SUSPENDING;
336 spin_unlock_irq(&uhci->lock); 353 spin_unlock_irq(&uhci->lock);
337 msleep(1); 354 msleep(1);
@@ -339,7 +356,7 @@ __acquires(uhci->lock)
339 if (uhci->dead) 356 if (uhci->dead)
340 return; 357 return;
341 } 358 }
342 if (!(inw(uhci->io_addr + USBSTS) & USBSTS_HCH)) 359 if (!(uhci_readw(uhci, USBSTS) & USBSTS_HCH))
343 dev_warn(uhci_dev(uhci), "Controller not stopped yet!\n"); 360 dev_warn(uhci_dev(uhci), "Controller not stopped yet!\n");
344 361
345 uhci_get_current_frame_number(uhci); 362 uhci_get_current_frame_number(uhci);
@@ -361,15 +378,14 @@ __acquires(uhci->lock)
361 378
362static void start_rh(struct uhci_hcd *uhci) 379static void start_rh(struct uhci_hcd *uhci)
363{ 380{
364 uhci_to_hcd(uhci)->state = HC_STATE_RUNNING;
365 uhci->is_stopped = 0; 381 uhci->is_stopped = 0;
366 382
367 /* Mark it configured and running with a 64-byte max packet. 383 /* Mark it configured and running with a 64-byte max packet.
368 * All interrupts are enabled, even though RESUME won't do anything. 384 * All interrupts are enabled, even though RESUME won't do anything.
369 */ 385 */
370 outw(USBCMD_RS | USBCMD_CF | USBCMD_MAXP, uhci->io_addr + USBCMD); 386 uhci_writew(uhci, USBCMD_RS | USBCMD_CF | USBCMD_MAXP, USBCMD);
371 outw(USBINTR_TIMEOUT | USBINTR_RESUME | USBINTR_IOC | USBINTR_SP, 387 uhci_writew(uhci, USBINTR_TIMEOUT | USBINTR_RESUME |
372 uhci->io_addr + USBINTR); 388 USBINTR_IOC | USBINTR_SP, USBINTR);
373 mb(); 389 mb();
374 uhci->rh_state = UHCI_RH_RUNNING; 390 uhci->rh_state = UHCI_RH_RUNNING;
375 set_bit(HCD_FLAG_POLL_RH, &uhci_to_hcd(uhci)->flags); 391 set_bit(HCD_FLAG_POLL_RH, &uhci_to_hcd(uhci)->flags);
@@ -392,9 +408,9 @@ __acquires(uhci->lock)
392 unsigned egsm; 408 unsigned egsm;
393 409
394 /* Keep EGSM on if it was set before */ 410 /* Keep EGSM on if it was set before */
395 egsm = inw(uhci->io_addr + USBCMD) & USBCMD_EGSM; 411 egsm = uhci_readw(uhci, USBCMD) & USBCMD_EGSM;
396 uhci->rh_state = UHCI_RH_RESUMING; 412 uhci->rh_state = UHCI_RH_RESUMING;
397 outw(USBCMD_FGR | USBCMD_CF | egsm, uhci->io_addr + USBCMD); 413 uhci_writew(uhci, USBCMD_FGR | USBCMD_CF | egsm, USBCMD);
398 spin_unlock_irq(&uhci->lock); 414 spin_unlock_irq(&uhci->lock);
399 msleep(20); 415 msleep(20);
400 spin_lock_irq(&uhci->lock); 416 spin_lock_irq(&uhci->lock);
@@ -402,10 +418,10 @@ __acquires(uhci->lock)
402 return; 418 return;
403 419
404 /* End Global Resume and wait for EOP to be sent */ 420 /* End Global Resume and wait for EOP to be sent */
405 outw(USBCMD_CF, uhci->io_addr + USBCMD); 421 uhci_writew(uhci, USBCMD_CF, USBCMD);
406 mb(); 422 mb();
407 udelay(4); 423 udelay(4);
408 if (inw(uhci->io_addr + USBCMD) & USBCMD_FGR) 424 if (uhci_readw(uhci, USBCMD) & USBCMD_FGR)
409 dev_warn(uhci_dev(uhci), "FGR not stopped yet!\n"); 425 dev_warn(uhci_dev(uhci), "FGR not stopped yet!\n");
410 } 426 }
411 427
@@ -425,10 +441,10 @@ static irqreturn_t uhci_irq(struct usb_hcd *hcd)
425 * interrupt cause. Contrary to the UHCI specification, the 441 * interrupt cause. Contrary to the UHCI specification, the
426 * "HC Halted" status bit is persistent: it is RO, not R/WC. 442 * "HC Halted" status bit is persistent: it is RO, not R/WC.
427 */ 443 */
428 status = inw(uhci->io_addr + USBSTS); 444 status = uhci_readw(uhci, USBSTS);
429 if (!(status & ~USBSTS_HCH)) /* shared interrupt, not mine */ 445 if (!(status & ~USBSTS_HCH)) /* shared interrupt, not mine */
430 return IRQ_NONE; 446 return IRQ_NONE;
431 outw(status, uhci->io_addr + USBSTS); /* Clear it */ 447 uhci_writew(uhci, status, USBSTS); /* Clear it */
432 448
433 if (status & ~(USBSTS_USBINT | USBSTS_ERROR | USBSTS_RD)) { 449 if (status & ~(USBSTS_USBINT | USBSTS_ERROR | USBSTS_RD)) {
434 if (status & USBSTS_HSE) 450 if (status & USBSTS_HSE)
@@ -450,6 +466,7 @@ static irqreturn_t uhci_irq(struct usb_hcd *hcd)
450 lprintk(errbuf); 466 lprintk(errbuf);
451 } 467 }
452 uhci_hc_died(uhci); 468 uhci_hc_died(uhci);
469 usb_hc_died(hcd);
453 470
454 /* Force a callback in case there are 471 /* Force a callback in case there are
455 * pending unlinks */ 472 * pending unlinks */
@@ -483,7 +500,7 @@ static void uhci_get_current_frame_number(struct uhci_hcd *uhci)
483 if (!uhci->is_stopped) { 500 if (!uhci->is_stopped) {
484 unsigned delta; 501 unsigned delta;
485 502
486 delta = (inw(uhci->io_addr + USBFRNUM) - uhci->frame_number) & 503 delta = (uhci_readw(uhci, USBFRNUM) - uhci->frame_number) &
487 (UHCI_NUMFRAMES - 1); 504 (UHCI_NUMFRAMES - 1);
488 uhci->frame_number += delta; 505 uhci->frame_number += delta;
489 } 506 }
@@ -520,61 +537,6 @@ static void release_uhci(struct uhci_hcd *uhci)
520 uhci->frame, uhci->frame_dma_handle); 537 uhci->frame, uhci->frame_dma_handle);
521} 538}
522 539
523static int uhci_init(struct usb_hcd *hcd)
524{
525 struct uhci_hcd *uhci = hcd_to_uhci(hcd);
526 unsigned io_size = (unsigned) hcd->rsrc_len;
527 int port;
528
529 uhci->io_addr = (unsigned long) hcd->rsrc_start;
530
531 /* The UHCI spec says devices must have 2 ports, and goes on to say
532 * they may have more but gives no way to determine how many there
533 * are. However according to the UHCI spec, Bit 7 of the port
534 * status and control register is always set to 1. So we try to
535 * use this to our advantage. Another common failure mode when
536 * a nonexistent register is addressed is to return all ones, so
537 * we test for that also.
538 */
539 for (port = 0; port < (io_size - USBPORTSC1) / 2; port++) {
540 unsigned int portstatus;
541
542 portstatus = inw(uhci->io_addr + USBPORTSC1 + (port * 2));
543 if (!(portstatus & 0x0080) || portstatus == 0xffff)
544 break;
545 }
546 if (debug)
547 dev_info(uhci_dev(uhci), "detected %d ports\n", port);
548
549 /* Anything greater than 7 is weird so we'll ignore it. */
550 if (port > UHCI_RH_MAXCHILD) {
551 dev_info(uhci_dev(uhci), "port count misdetected? "
552 "forcing to 2 ports\n");
553 port = 2;
554 }
555 uhci->rh_numports = port;
556
557 /* Kick BIOS off this hardware and reset if the controller
558 * isn't already safely quiescent.
559 */
560 check_and_reset_hc(uhci);
561 return 0;
562}
563
564/* Make sure the controller is quiescent and that we're not using it
565 * any more. This is mainly for the benefit of programs which, like kexec,
566 * expect the hardware to be idle: not doing DMA or generating IRQs.
567 *
568 * This routine may be called in a damaged or failing kernel. Hence we
569 * do not acquire the spinlock before shutting down the controller.
570 */
571static void uhci_shutdown(struct pci_dev *pdev)
572{
573 struct usb_hcd *hcd = pci_get_drvdata(pdev);
574
575 uhci_hc_died(hcd_to_uhci(hcd));
576}
577
578/* 540/*
579 * Allocate a frame list, and then setup the skeleton 541 * Allocate a frame list, and then setup the skeleton
580 * 542 *
@@ -669,16 +631,16 @@ static int uhci_start(struct usb_hcd *hcd)
669 * 8 Interrupt queues; link all higher int queues to int1 = async 631 * 8 Interrupt queues; link all higher int queues to int1 = async
670 */ 632 */
671 for (i = SKEL_ISO + 1; i < SKEL_ASYNC; ++i) 633 for (i = SKEL_ISO + 1; i < SKEL_ASYNC; ++i)
672 uhci->skelqh[i]->link = LINK_TO_QH(uhci->skel_async_qh); 634 uhci->skelqh[i]->link = LINK_TO_QH(uhci, uhci->skel_async_qh);
673 uhci->skel_async_qh->link = UHCI_PTR_TERM; 635 uhci->skel_async_qh->link = UHCI_PTR_TERM(uhci);
674 uhci->skel_term_qh->link = LINK_TO_QH(uhci->skel_term_qh); 636 uhci->skel_term_qh->link = LINK_TO_QH(uhci, uhci->skel_term_qh);
675 637
676 /* This dummy TD is to work around a bug in Intel PIIX controllers */ 638 /* This dummy TD is to work around a bug in Intel PIIX controllers */
677 uhci_fill_td(uhci->term_td, 0, uhci_explen(0) | 639 uhci_fill_td(uhci, uhci->term_td, 0, uhci_explen(0) |
678 (0x7f << TD_TOKEN_DEVADDR_SHIFT) | USB_PID_IN, 0); 640 (0x7f << TD_TOKEN_DEVADDR_SHIFT) | USB_PID_IN, 0);
679 uhci->term_td->link = UHCI_PTR_TERM; 641 uhci->term_td->link = UHCI_PTR_TERM(uhci);
680 uhci->skel_async_qh->element = uhci->skel_term_qh->element = 642 uhci->skel_async_qh->element = uhci->skel_term_qh->element =
681 LINK_TO_TD(uhci->term_td); 643 LINK_TO_TD(uhci, uhci->term_td);
682 644
683 /* 645 /*
684 * Fill the frame list: make all entries point to the proper 646 * Fill the frame list: make all entries point to the proper
@@ -791,86 +753,6 @@ static int uhci_rh_resume(struct usb_hcd *hcd)
791 return rc; 753 return rc;
792} 754}
793 755
794static int uhci_pci_suspend(struct usb_hcd *hcd, bool do_wakeup)
795{
796 struct uhci_hcd *uhci = hcd_to_uhci(hcd);
797 struct pci_dev *pdev = to_pci_dev(uhci_dev(uhci));
798 int rc = 0;
799
800 dev_dbg(uhci_dev(uhci), "%s\n", __func__);
801
802 spin_lock_irq(&uhci->lock);
803 if (!HCD_HW_ACCESSIBLE(hcd) || uhci->dead)
804 goto done_okay; /* Already suspended or dead */
805
806 if (uhci->rh_state > UHCI_RH_SUSPENDED) {
807 dev_warn(uhci_dev(uhci), "Root hub isn't suspended!\n");
808 rc = -EBUSY;
809 goto done;
810 };
811
812 /* All PCI host controllers are required to disable IRQ generation
813 * at the source, so we must turn off PIRQ.
814 */
815 pci_write_config_word(pdev, USBLEGSUP, 0);
816 clear_bit(HCD_FLAG_POLL_RH, &hcd->flags);
817
818 /* Enable platform-specific non-PME# wakeup */
819 if (do_wakeup) {
820 if (pdev->vendor == PCI_VENDOR_ID_INTEL)
821 pci_write_config_byte(pdev, USBRES_INTEL,
822 USBPORT1EN | USBPORT2EN);
823 }
824
825done_okay:
826 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
827done:
828 spin_unlock_irq(&uhci->lock);
829 return rc;
830}
831
832static int uhci_pci_resume(struct usb_hcd *hcd, bool hibernated)
833{
834 struct uhci_hcd *uhci = hcd_to_uhci(hcd);
835
836 dev_dbg(uhci_dev(uhci), "%s\n", __func__);
837
838 /* Since we aren't in D3 any more, it's safe to set this flag
839 * even if the controller was dead.
840 */
841 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
842
843 spin_lock_irq(&uhci->lock);
844
845 /* Make sure resume from hibernation re-enumerates everything */
846 if (hibernated)
847 uhci_hc_died(uhci);
848
849 /* The firmware or a boot kernel may have changed the controller
850 * settings during a system wakeup. Check it and reconfigure
851 * to avoid problems.
852 */
853 check_and_reset_hc(uhci);
854
855 /* If the controller was dead before, it's back alive now */
856 configure_hc(uhci);
857
858 /* Tell the core if the controller had to be reset */
859 if (uhci->rh_state == UHCI_RH_RESET)
860 usb_root_hub_lost_power(hcd->self.root_hub);
861
862 spin_unlock_irq(&uhci->lock);
863
864 /* If interrupts don't work and remote wakeup is enabled then
865 * the suspended root hub needs to be polled.
866 */
867 if (!uhci->RD_enable && hcd->self.root_hub->do_remote_wakeup)
868 set_bit(HCD_FLAG_POLL_RH, &hcd->flags);
869
870 /* Does the root hub have a port wakeup pending? */
871 usb_hcd_poll_rh_status(hcd);
872 return 0;
873}
874#endif 756#endif
875 757
876/* Wait until a particular device/endpoint's QH is idle, and free it */ 758/* Wait until a particular device/endpoint's QH is idle, and free it */
@@ -908,67 +790,62 @@ static int uhci_hcd_get_frame_number(struct usb_hcd *hcd)
908 /* Minimize latency by avoiding the spinlock */ 790 /* Minimize latency by avoiding the spinlock */
909 frame_number = uhci->frame_number; 791 frame_number = uhci->frame_number;
910 barrier(); 792 barrier();
911 delta = (inw(uhci->io_addr + USBFRNUM) - frame_number) & 793 delta = (uhci_readw(uhci, USBFRNUM) - frame_number) &
912 (UHCI_NUMFRAMES - 1); 794 (UHCI_NUMFRAMES - 1);
913 return frame_number + delta; 795 return frame_number + delta;
914} 796}
915 797
916static const char hcd_name[] = "uhci_hcd"; 798/* Determines number of ports on controller */
917 799static int uhci_count_ports(struct usb_hcd *hcd)
918static const struct hc_driver uhci_driver = { 800{
919 .description = hcd_name, 801 struct uhci_hcd *uhci = hcd_to_uhci(hcd);
920 .product_desc = "UHCI Host Controller", 802 unsigned io_size = (unsigned) hcd->rsrc_len;
921 .hcd_priv_size = sizeof(struct uhci_hcd), 803 int port;
922
923 /* Generic hardware linkage */
924 .irq = uhci_irq,
925 .flags = HCD_USB11,
926
927 /* Basic lifecycle operations */
928 .reset = uhci_init,
929 .start = uhci_start,
930#ifdef CONFIG_PM
931 .pci_suspend = uhci_pci_suspend,
932 .pci_resume = uhci_pci_resume,
933 .bus_suspend = uhci_rh_suspend,
934 .bus_resume = uhci_rh_resume,
935#endif
936 .stop = uhci_stop,
937 804
938 .urb_enqueue = uhci_urb_enqueue, 805 /* The UHCI spec says devices must have 2 ports, and goes on to say
939 .urb_dequeue = uhci_urb_dequeue, 806 * they may have more but gives no way to determine how many there
807 * are. However according to the UHCI spec, Bit 7 of the port
808 * status and control register is always set to 1. So we try to
809 * use this to our advantage. Another common failure mode when
810 * a nonexistent register is addressed is to return all ones, so
811 * we test for that also.
812 */
813 for (port = 0; port < (io_size - USBPORTSC1) / 2; port++) {
814 unsigned int portstatus;
940 815
941 .endpoint_disable = uhci_hcd_endpoint_disable, 816 portstatus = uhci_readw(uhci, USBPORTSC1 + (port * 2));
942 .get_frame_number = uhci_hcd_get_frame_number, 817 if (!(portstatus & 0x0080) || portstatus == 0xffff)
818 break;
819 }
820 if (debug)
821 dev_info(uhci_dev(uhci), "detected %d ports\n", port);
943 822
944 .hub_status_data = uhci_hub_status_data, 823 /* Anything greater than 7 is weird so we'll ignore it. */
945 .hub_control = uhci_hub_control, 824 if (port > UHCI_RH_MAXCHILD) {
946}; 825 dev_info(uhci_dev(uhci), "port count misdetected? "
826 "forcing to 2 ports\n");
827 port = 2;
828 }
947 829
948static const struct pci_device_id uhci_pci_ids[] = { { 830 return port;
949 /* handle any USB UHCI controller */ 831}
950 PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_USB_UHCI, ~0),
951 .driver_data = (unsigned long) &uhci_driver,
952 }, { /* end: all zeroes */ }
953};
954 832
955MODULE_DEVICE_TABLE(pci, uhci_pci_ids); 833static const char hcd_name[] = "uhci_hcd";
956 834
957static struct pci_driver uhci_pci_driver = { 835#ifdef CONFIG_PCI
958 .name = (char *)hcd_name, 836#include "uhci-pci.c"
959 .id_table = uhci_pci_ids, 837#define PCI_DRIVER uhci_pci_driver
838#endif
960 839
961 .probe = usb_hcd_pci_probe, 840#ifdef CONFIG_SPARC_LEON
962 .remove = usb_hcd_pci_remove, 841#include "uhci-grlib.c"
963 .shutdown = uhci_shutdown, 842#define PLATFORM_DRIVER uhci_grlib_driver
843#endif
964 844
965#ifdef CONFIG_PM_SLEEP 845#if !defined(PCI_DRIVER) && !defined(PLATFORM_DRIVER)
966 .driver = { 846#error "missing bus glue for uhci-hcd"
967 .pm = &usb_hcd_pci_pm_ops
968 },
969#endif 847#endif
970}; 848
971
972static int __init uhci_hcd_init(void) 849static int __init uhci_hcd_init(void)
973{ 850{
974 int retval = -ENOMEM; 851 int retval = -ENOMEM;
@@ -994,13 +871,27 @@ static int __init uhci_hcd_init(void)
994 if (!uhci_up_cachep) 871 if (!uhci_up_cachep)
995 goto up_failed; 872 goto up_failed;
996 873
997 retval = pci_register_driver(&uhci_pci_driver); 874#ifdef PLATFORM_DRIVER
998 if (retval) 875 retval = platform_driver_register(&PLATFORM_DRIVER);
999 goto init_failed; 876 if (retval < 0)
877 goto clean0;
878#endif
879
880#ifdef PCI_DRIVER
881 retval = pci_register_driver(&PCI_DRIVER);
882 if (retval < 0)
883 goto clean1;
884#endif
1000 885
1001 return 0; 886 return 0;
1002 887
1003init_failed: 888#ifdef PCI_DRIVER
889clean1:
890#endif
891#ifdef PLATFORM_DRIVER
892 platform_driver_unregister(&PLATFORM_DRIVER);
893clean0:
894#endif
1004 kmem_cache_destroy(uhci_up_cachep); 895 kmem_cache_destroy(uhci_up_cachep);
1005 896
1006up_failed: 897up_failed:
@@ -1017,7 +908,12 @@ errbuf_failed:
1017 908
1018static void __exit uhci_hcd_cleanup(void) 909static void __exit uhci_hcd_cleanup(void)
1019{ 910{
1020 pci_unregister_driver(&uhci_pci_driver); 911#ifdef PLATFORM_DRIVER
912 platform_driver_unregister(&PLATFORM_DRIVER);
913#endif
914#ifdef PCI_DRIVER
915 pci_unregister_driver(&PCI_DRIVER);
916#endif
1021 kmem_cache_destroy(uhci_up_cachep); 917 kmem_cache_destroy(uhci_up_cachep);
1022 debugfs_remove(uhci_debugfs_root); 918 debugfs_remove(uhci_debugfs_root);
1023 kfree(errbuf); 919 kfree(errbuf);