0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026 #include <linux/module.h>
0027 #include <linux/pci.h>
0028 #include <linux/kernel.h>
0029 #include <linux/init.h>
0030 #include <linux/delay.h>
0031 #include <linux/ioport.h>
0032 #include <linux/slab.h>
0033 #include <linux/errno.h>
0034 #include <linux/unistd.h>
0035 #include <linux/interrupt.h>
0036 #include <linux/spinlock.h>
0037 #include <linux/debugfs.h>
0038 #include <linux/pm.h>
0039 #include <linux/dmapool.h>
0040 #include <linux/dma-mapping.h>
0041 #include <linux/usb.h>
0042 #include <linux/usb/hcd.h>
0043 #include <linux/bitops.h>
0044 #include <linux/dmi.h>
0045
0046 #include <linux/uaccess.h>
0047 #include <asm/io.h>
0048 #include <asm/irq.h>
0049
0050 #include "uhci-hcd.h"
0051
0052
0053
0054
0055 #define DRIVER_AUTHOR \
0056 "Linus 'Frodo Rabbit' Torvalds, Johannes Erdfelt, " \
0057 "Randy Dunlap, Georg Acher, Deti Fliegl, Thomas Sailer, " \
0058 "Roman Weissgaerber, Alan Stern"
0059 #define DRIVER_DESC "USB Universal Host Controller Interface driver"
0060
0061
0062 static bool ignore_oc;
0063 module_param(ignore_oc, bool, S_IRUGO);
0064 MODULE_PARM_DESC(ignore_oc, "ignore hardware overcurrent indications");
0065
0066
0067
0068
0069
0070
0071
0072
0073 #ifdef CONFIG_DYNAMIC_DEBUG
0074
0075 static int debug = 1;
0076 module_param(debug, int, S_IRUGO | S_IWUSR);
0077 MODULE_PARM_DESC(debug, "Debug level");
0078 static char *errbuf;
0079
0080 #else
0081
0082 #define debug 0
0083 #define errbuf NULL
0084
0085 #endif
0086
0087
0088 #define ERRBUF_LEN (32 * 1024)
0089
0090 static struct kmem_cache *uhci_up_cachep;
0091
0092 static void suspend_rh(struct uhci_hcd *uhci, enum uhci_rh_state new_state);
0093 static void wakeup_rh(struct uhci_hcd *uhci);
0094 static void uhci_get_current_frame_number(struct uhci_hcd *uhci);
0095
0096
0097
0098
0099 static __hc32 uhci_frame_skel_link(struct uhci_hcd *uhci, int frame)
0100 {
0101 int skelnum;
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116
0117
0118 skelnum = 8 - (int) __ffs(frame | UHCI_NUMFRAMES);
0119 if (skelnum <= 1)
0120 skelnum = 9;
0121 return LINK_TO_QH(uhci, uhci->skelqh[skelnum]);
0122 }
0123
0124 #include "uhci-debug.c"
0125 #include "uhci-q.c"
0126 #include "uhci-hub.c"
0127
0128
0129
0130
0131 static void finish_reset(struct uhci_hcd *uhci)
0132 {
0133 int port;
0134
0135
0136
0137
0138
0139 for (port = 0; port < uhci->rh_numports; ++port)
0140 uhci_writew(uhci, 0, USBPORTSC1 + (port * 2));
0141
0142 uhci->port_c_suspend = uhci->resuming_ports = 0;
0143 uhci->rh_state = UHCI_RH_RESET;
0144 uhci->is_stopped = UHCI_IS_STOPPED;
0145 clear_bit(HCD_FLAG_POLL_RH, &uhci_to_hcd(uhci)->flags);
0146 }
0147
0148
0149
0150
0151
0152 static void uhci_hc_died(struct uhci_hcd *uhci)
0153 {
0154 uhci_get_current_frame_number(uhci);
0155 uhci->reset_hc(uhci);
0156 finish_reset(uhci);
0157 uhci->dead = 1;
0158
0159
0160 ++uhci->frame_number;
0161 }
0162
0163
0164
0165
0166
0167
0168 static void check_and_reset_hc(struct uhci_hcd *uhci)
0169 {
0170 if (uhci->check_and_reset_hc(uhci))
0171 finish_reset(uhci);
0172 }
0173
0174 #if defined(CONFIG_USB_UHCI_SUPPORT_NON_PCI_HC)
0175
0176
0177
0178
0179
0180
0181
0182
0183
0184
0185 static void uhci_generic_reset_hc(struct uhci_hcd *uhci)
0186 {
0187
0188
0189
0190
0191
0192 uhci_writew(uhci, USBCMD_HCRESET, USBCMD);
0193 mb();
0194 udelay(5);
0195 if (uhci_readw(uhci, USBCMD) & USBCMD_HCRESET)
0196 dev_warn(uhci_dev(uhci), "HCRESET not completed yet!\n");
0197
0198
0199
0200
0201 uhci_writew(uhci, 0, USBINTR);
0202 uhci_writew(uhci, 0, USBCMD);
0203 }
0204
0205
0206
0207
0208
0209
0210
0211 static int uhci_generic_check_and_reset_hc(struct uhci_hcd *uhci)
0212 {
0213 unsigned int cmd, intr;
0214
0215
0216
0217
0218
0219
0220
0221
0222
0223
0224
0225 cmd = uhci_readw(uhci, USBCMD);
0226 if ((cmd & USBCMD_RS) || !(cmd & USBCMD_CF) || !(cmd & USBCMD_EGSM)) {
0227 dev_dbg(uhci_dev(uhci), "%s: cmd = 0x%04x\n",
0228 __func__, cmd);
0229 goto reset_needed;
0230 }
0231
0232 intr = uhci_readw(uhci, USBINTR);
0233 if (intr & (~USBINTR_RESUME)) {
0234 dev_dbg(uhci_dev(uhci), "%s: intr = 0x%04x\n",
0235 __func__, intr);
0236 goto reset_needed;
0237 }
0238 return 0;
0239
0240 reset_needed:
0241 dev_dbg(uhci_dev(uhci), "Performing full reset\n");
0242 uhci_generic_reset_hc(uhci);
0243 return 1;
0244 }
0245 #endif
0246
0247
0248
0249
0250 static void configure_hc(struct uhci_hcd *uhci)
0251 {
0252
0253 uhci_writeb(uhci, USBSOF_DEFAULT, USBSOF);
0254
0255
0256 uhci_writel(uhci, uhci->frame_dma_handle, USBFLBASEADD);
0257
0258
0259 uhci_writew(uhci, uhci->frame_number & UHCI_MAX_SOF_NUMBER,
0260 USBFRNUM);
0261
0262
0263 if (uhci->configure_hc)
0264 uhci->configure_hc(uhci);
0265 }
0266
0267 static int resume_detect_interrupts_are_broken(struct uhci_hcd *uhci)
0268 {
0269
0270
0271
0272
0273
0274
0275 if (ignore_oc || uhci_is_aspeed(uhci))
0276 return 1;
0277
0278 return uhci->resume_detect_interrupts_are_broken ?
0279 uhci->resume_detect_interrupts_are_broken(uhci) : 0;
0280 }
0281
0282 static int global_suspend_mode_is_broken(struct uhci_hcd *uhci)
0283 {
0284 return uhci->global_suspend_mode_is_broken ?
0285 uhci->global_suspend_mode_is_broken(uhci) : 0;
0286 }
0287
0288 static void suspend_rh(struct uhci_hcd *uhci, enum uhci_rh_state new_state)
0289 __releases(uhci->lock)
0290 __acquires(uhci->lock)
0291 {
0292 int auto_stop;
0293 int int_enable, egsm_enable, wakeup_enable;
0294 struct usb_device *rhdev = uhci_to_hcd(uhci)->self.root_hub;
0295
0296 auto_stop = (new_state == UHCI_RH_AUTO_STOPPED);
0297 dev_dbg(&rhdev->dev, "%s%s\n", __func__,
0298 (auto_stop ? " (auto-stop)" : ""));
0299
0300
0301
0302
0303 egsm_enable = USBCMD_EGSM;
0304 int_enable = USBINTR_RESUME;
0305 wakeup_enable = 1;
0306
0307
0308
0309
0310
0311
0312 if (auto_stop) {
0313 if (!device_may_wakeup(&rhdev->dev))
0314 egsm_enable = int_enable = 0;
0315 }
0316
0317 #ifdef CONFIG_PM
0318
0319
0320
0321
0322 else {
0323 if (!rhdev->do_remote_wakeup)
0324 wakeup_enable = 0;
0325 }
0326 #endif
0327
0328
0329
0330
0331
0332
0333
0334
0335
0336
0337
0338
0339
0340
0341
0342
0343 if (!wakeup_enable || global_suspend_mode_is_broken(uhci) ||
0344 resume_detect_interrupts_are_broken(uhci))
0345 egsm_enable = int_enable = 0;
0346
0347 uhci->RD_enable = !!int_enable;
0348 uhci_writew(uhci, int_enable, USBINTR);
0349 uhci_writew(uhci, egsm_enable | USBCMD_CF, USBCMD);
0350 mb();
0351 udelay(5);
0352
0353
0354
0355
0356
0357
0358 if (!auto_stop && !(uhci_readw(uhci, USBSTS) & USBSTS_HCH)) {
0359 uhci->rh_state = UHCI_RH_SUSPENDING;
0360 spin_unlock_irq(&uhci->lock);
0361 msleep(1);
0362 spin_lock_irq(&uhci->lock);
0363 if (uhci->dead)
0364 return;
0365 }
0366 if (!(uhci_readw(uhci, USBSTS) & USBSTS_HCH))
0367 dev_warn(uhci_dev(uhci), "Controller not stopped yet!\n");
0368
0369 uhci_get_current_frame_number(uhci);
0370
0371 uhci->rh_state = new_state;
0372 uhci->is_stopped = UHCI_IS_STOPPED;
0373
0374
0375
0376
0377
0378
0379 if (wakeup_enable && (!int_enable || !egsm_enable))
0380 set_bit(HCD_FLAG_POLL_RH, &uhci_to_hcd(uhci)->flags);
0381 else
0382 clear_bit(HCD_FLAG_POLL_RH, &uhci_to_hcd(uhci)->flags);
0383
0384 uhci_scan_schedule(uhci);
0385 uhci_fsbr_off(uhci);
0386 }
0387
0388 static void start_rh(struct uhci_hcd *uhci)
0389 {
0390 uhci->is_stopped = 0;
0391
0392
0393
0394
0395
0396 if (uhci_is_aspeed(uhci))
0397 uhci_writew(uhci, uhci_readw(uhci, USBSTS), USBSTS);
0398
0399
0400
0401
0402 uhci_writew(uhci, USBCMD_RS | USBCMD_CF | USBCMD_MAXP, USBCMD);
0403 uhci_writew(uhci, USBINTR_TIMEOUT | USBINTR_RESUME |
0404 USBINTR_IOC | USBINTR_SP, USBINTR);
0405 mb();
0406 uhci->rh_state = UHCI_RH_RUNNING;
0407 set_bit(HCD_FLAG_POLL_RH, &uhci_to_hcd(uhci)->flags);
0408 }
0409
0410 static void wakeup_rh(struct uhci_hcd *uhci)
0411 __releases(uhci->lock)
0412 __acquires(uhci->lock)
0413 {
0414 dev_dbg(&uhci_to_hcd(uhci)->self.root_hub->dev,
0415 "%s%s\n", __func__,
0416 uhci->rh_state == UHCI_RH_AUTO_STOPPED ?
0417 " (auto-start)" : "");
0418
0419
0420
0421
0422
0423 if (uhci->rh_state == UHCI_RH_SUSPENDED) {
0424 unsigned egsm;
0425
0426
0427 egsm = uhci_readw(uhci, USBCMD) & USBCMD_EGSM;
0428 uhci->rh_state = UHCI_RH_RESUMING;
0429 uhci_writew(uhci, USBCMD_FGR | USBCMD_CF | egsm, USBCMD);
0430 spin_unlock_irq(&uhci->lock);
0431 msleep(20);
0432 spin_lock_irq(&uhci->lock);
0433 if (uhci->dead)
0434 return;
0435
0436
0437 uhci_writew(uhci, USBCMD_CF, USBCMD);
0438 mb();
0439 udelay(4);
0440 if (uhci_readw(uhci, USBCMD) & USBCMD_FGR)
0441 dev_warn(uhci_dev(uhci), "FGR not stopped yet!\n");
0442 }
0443
0444 start_rh(uhci);
0445
0446
0447 mod_timer(&uhci_to_hcd(uhci)->rh_timer, jiffies);
0448 }
0449
0450 static irqreturn_t uhci_irq(struct usb_hcd *hcd)
0451 {
0452 struct uhci_hcd *uhci = hcd_to_uhci(hcd);
0453 unsigned short status;
0454
0455
0456
0457
0458
0459
0460 status = uhci_readw(uhci, USBSTS);
0461 if (!(status & ~USBSTS_HCH))
0462 return IRQ_NONE;
0463 uhci_writew(uhci, status, USBSTS);
0464
0465 spin_lock(&uhci->lock);
0466 if (unlikely(!uhci->is_initialized))
0467 goto done;
0468
0469 if (status & ~(USBSTS_USBINT | USBSTS_ERROR | USBSTS_RD)) {
0470 if (status & USBSTS_HSE)
0471 dev_err(uhci_dev(uhci),
0472 "host system error, PCI problems?\n");
0473 if (status & USBSTS_HCPE)
0474 dev_err(uhci_dev(uhci),
0475 "host controller process error, something bad happened!\n");
0476 if (status & USBSTS_HCH) {
0477 if (uhci->rh_state >= UHCI_RH_RUNNING) {
0478 dev_err(uhci_dev(uhci),
0479 "host controller halted, very bad!\n");
0480 if (debug > 1 && errbuf) {
0481
0482 uhci_sprint_schedule(uhci, errbuf,
0483 ERRBUF_LEN - EXTRA_SPACE);
0484 lprintk(errbuf);
0485 }
0486 uhci_hc_died(uhci);
0487 usb_hc_died(hcd);
0488
0489
0490
0491 mod_timer(&hcd->rh_timer, jiffies);
0492 }
0493 }
0494 }
0495
0496 if (status & USBSTS_RD) {
0497 spin_unlock(&uhci->lock);
0498 usb_hcd_poll_rh_status(hcd);
0499 } else {
0500 uhci_scan_schedule(uhci);
0501 done:
0502 spin_unlock(&uhci->lock);
0503 }
0504
0505 return IRQ_HANDLED;
0506 }
0507
0508
0509
0510
0511
0512
0513
0514
0515
0516 static void uhci_get_current_frame_number(struct uhci_hcd *uhci)
0517 {
0518 if (!uhci->is_stopped) {
0519 unsigned delta;
0520
0521 delta = (uhci_readw(uhci, USBFRNUM) - uhci->frame_number) &
0522 (UHCI_NUMFRAMES - 1);
0523 uhci->frame_number += delta;
0524 }
0525 }
0526
0527
0528
0529
0530 static void release_uhci(struct uhci_hcd *uhci)
0531 {
0532 int i;
0533
0534
0535 spin_lock_irq(&uhci->lock);
0536 uhci->is_initialized = 0;
0537 spin_unlock_irq(&uhci->lock);
0538
0539 debugfs_remove(debugfs_lookup(uhci_to_hcd(uhci)->self.bus_name,
0540 uhci_debugfs_root));
0541
0542 for (i = 0; i < UHCI_NUM_SKELQH; i++)
0543 uhci_free_qh(uhci, uhci->skelqh[i]);
0544
0545 uhci_free_td(uhci, uhci->term_td);
0546
0547 dma_pool_destroy(uhci->qh_pool);
0548
0549 dma_pool_destroy(uhci->td_pool);
0550
0551 kfree(uhci->frame_cpu);
0552
0553 dma_free_coherent(uhci_dev(uhci),
0554 UHCI_NUMFRAMES * sizeof(*uhci->frame),
0555 uhci->frame, uhci->frame_dma_handle);
0556 }
0557
0558
0559
0560
0561
0562
0563
0564
0565
0566
0567
0568
0569
0570
0571
0572
0573
0574
0575
0576 static int uhci_start(struct usb_hcd *hcd)
0577 {
0578 struct uhci_hcd *uhci = hcd_to_uhci(hcd);
0579 int retval = -EBUSY;
0580 int i;
0581
0582 hcd->uses_new_polling = 1;
0583
0584 if (!hcd->localmem_pool)
0585 hcd->self.sg_tablesize = ~0;
0586
0587 spin_lock_init(&uhci->lock);
0588 timer_setup(&uhci->fsbr_timer, uhci_fsbr_timeout, 0);
0589 INIT_LIST_HEAD(&uhci->idle_qh_list);
0590 init_waitqueue_head(&uhci->waitqh);
0591
0592 #ifdef UHCI_DEBUG_OPS
0593 debugfs_create_file(hcd->self.bus_name, S_IFREG|S_IRUGO|S_IWUSR,
0594 uhci_debugfs_root, uhci, &uhci_debug_operations);
0595 #endif
0596
0597 uhci->frame = dma_alloc_coherent(uhci_dev(uhci),
0598 UHCI_NUMFRAMES * sizeof(*uhci->frame),
0599 &uhci->frame_dma_handle, GFP_KERNEL);
0600 if (!uhci->frame) {
0601 dev_err(uhci_dev(uhci),
0602 "unable to allocate consistent memory for frame list\n");
0603 goto err_alloc_frame;
0604 }
0605
0606 uhci->frame_cpu = kcalloc(UHCI_NUMFRAMES, sizeof(*uhci->frame_cpu),
0607 GFP_KERNEL);
0608 if (!uhci->frame_cpu)
0609 goto err_alloc_frame_cpu;
0610
0611 uhci->td_pool = dma_pool_create("uhci_td", uhci_dev(uhci),
0612 sizeof(struct uhci_td), 16, 0);
0613 if (!uhci->td_pool) {
0614 dev_err(uhci_dev(uhci), "unable to create td dma_pool\n");
0615 goto err_create_td_pool;
0616 }
0617
0618 uhci->qh_pool = dma_pool_create("uhci_qh", uhci_dev(uhci),
0619 sizeof(struct uhci_qh), 16, 0);
0620 if (!uhci->qh_pool) {
0621 dev_err(uhci_dev(uhci), "unable to create qh dma_pool\n");
0622 goto err_create_qh_pool;
0623 }
0624
0625 uhci->term_td = uhci_alloc_td(uhci);
0626 if (!uhci->term_td) {
0627 dev_err(uhci_dev(uhci), "unable to allocate terminating TD\n");
0628 goto err_alloc_term_td;
0629 }
0630
0631 for (i = 0; i < UHCI_NUM_SKELQH; i++) {
0632 uhci->skelqh[i] = uhci_alloc_qh(uhci, NULL, NULL);
0633 if (!uhci->skelqh[i]) {
0634 dev_err(uhci_dev(uhci), "unable to allocate QH\n");
0635 goto err_alloc_skelqh;
0636 }
0637 }
0638
0639
0640
0641
0642 for (i = SKEL_ISO + 1; i < SKEL_ASYNC; ++i)
0643 uhci->skelqh[i]->link = LINK_TO_QH(uhci, uhci->skel_async_qh);
0644 uhci->skel_async_qh->link = UHCI_PTR_TERM(uhci);
0645 uhci->skel_term_qh->link = LINK_TO_QH(uhci, uhci->skel_term_qh);
0646
0647
0648 uhci_fill_td(uhci, uhci->term_td, 0, uhci_explen(0) |
0649 (0x7f << TD_TOKEN_DEVADDR_SHIFT) | USB_PID_IN, 0);
0650 uhci->term_td->link = UHCI_PTR_TERM(uhci);
0651 uhci->skel_async_qh->element = uhci->skel_term_qh->element =
0652 LINK_TO_TD(uhci, uhci->term_td);
0653
0654
0655
0656
0657
0658 for (i = 0; i < UHCI_NUMFRAMES; i++) {
0659
0660
0661 uhci->frame[i] = uhci_frame_skel_link(uhci, i);
0662 }
0663
0664
0665
0666
0667
0668 mb();
0669
0670 spin_lock_irq(&uhci->lock);
0671 configure_hc(uhci);
0672 uhci->is_initialized = 1;
0673 start_rh(uhci);
0674 spin_unlock_irq(&uhci->lock);
0675 return 0;
0676
0677
0678
0679
0680 err_alloc_skelqh:
0681 for (i = 0; i < UHCI_NUM_SKELQH; i++) {
0682 if (uhci->skelqh[i])
0683 uhci_free_qh(uhci, uhci->skelqh[i]);
0684 }
0685
0686 uhci_free_td(uhci, uhci->term_td);
0687
0688 err_alloc_term_td:
0689 dma_pool_destroy(uhci->qh_pool);
0690
0691 err_create_qh_pool:
0692 dma_pool_destroy(uhci->td_pool);
0693
0694 err_create_td_pool:
0695 kfree(uhci->frame_cpu);
0696
0697 err_alloc_frame_cpu:
0698 dma_free_coherent(uhci_dev(uhci),
0699 UHCI_NUMFRAMES * sizeof(*uhci->frame),
0700 uhci->frame, uhci->frame_dma_handle);
0701
0702 err_alloc_frame:
0703 debugfs_remove(debugfs_lookup(hcd->self.bus_name, uhci_debugfs_root));
0704
0705 return retval;
0706 }
0707
0708 static void uhci_stop(struct usb_hcd *hcd)
0709 {
0710 struct uhci_hcd *uhci = hcd_to_uhci(hcd);
0711
0712 spin_lock_irq(&uhci->lock);
0713 if (HCD_HW_ACCESSIBLE(hcd) && !uhci->dead)
0714 uhci_hc_died(uhci);
0715 uhci_scan_schedule(uhci);
0716 spin_unlock_irq(&uhci->lock);
0717 synchronize_irq(hcd->irq);
0718
0719 del_timer_sync(&uhci->fsbr_timer);
0720 release_uhci(uhci);
0721 }
0722
0723 #ifdef CONFIG_PM
0724 static int uhci_rh_suspend(struct usb_hcd *hcd)
0725 {
0726 struct uhci_hcd *uhci = hcd_to_uhci(hcd);
0727 int rc = 0;
0728
0729 spin_lock_irq(&uhci->lock);
0730 if (!HCD_HW_ACCESSIBLE(hcd))
0731 rc = -ESHUTDOWN;
0732 else if (uhci->dead)
0733 ;
0734
0735
0736
0737
0738
0739
0740 else if (hcd->self.root_hub->do_remote_wakeup &&
0741 uhci->resuming_ports) {
0742 dev_dbg(uhci_dev(uhci),
0743 "suspend failed because a port is resuming\n");
0744 rc = -EBUSY;
0745 } else
0746 suspend_rh(uhci, UHCI_RH_SUSPENDED);
0747 spin_unlock_irq(&uhci->lock);
0748 return rc;
0749 }
0750
0751 static int uhci_rh_resume(struct usb_hcd *hcd)
0752 {
0753 struct uhci_hcd *uhci = hcd_to_uhci(hcd);
0754 int rc = 0;
0755
0756 spin_lock_irq(&uhci->lock);
0757 if (!HCD_HW_ACCESSIBLE(hcd))
0758 rc = -ESHUTDOWN;
0759 else if (!uhci->dead)
0760 wakeup_rh(uhci);
0761 spin_unlock_irq(&uhci->lock);
0762 return rc;
0763 }
0764
0765 #endif
0766
0767
0768 static void uhci_hcd_endpoint_disable(struct usb_hcd *hcd,
0769 struct usb_host_endpoint *hep)
0770 {
0771 struct uhci_hcd *uhci = hcd_to_uhci(hcd);
0772 struct uhci_qh *qh;
0773
0774 spin_lock_irq(&uhci->lock);
0775 qh = (struct uhci_qh *) hep->hcpriv;
0776 if (qh == NULL)
0777 goto done;
0778
0779 while (qh->state != QH_STATE_IDLE) {
0780 ++uhci->num_waiting;
0781 spin_unlock_irq(&uhci->lock);
0782 wait_event_interruptible(uhci->waitqh,
0783 qh->state == QH_STATE_IDLE);
0784 spin_lock_irq(&uhci->lock);
0785 --uhci->num_waiting;
0786 }
0787
0788 uhci_free_qh(uhci, qh);
0789 done:
0790 spin_unlock_irq(&uhci->lock);
0791 }
0792
0793 static int uhci_hcd_get_frame_number(struct usb_hcd *hcd)
0794 {
0795 struct uhci_hcd *uhci = hcd_to_uhci(hcd);
0796 unsigned frame_number;
0797 unsigned delta;
0798
0799
0800 frame_number = uhci->frame_number;
0801 barrier();
0802 delta = (uhci_readw(uhci, USBFRNUM) - frame_number) &
0803 (UHCI_NUMFRAMES - 1);
0804 return frame_number + delta;
0805 }
0806
0807
0808 static int uhci_count_ports(struct usb_hcd *hcd)
0809 {
0810 struct uhci_hcd *uhci = hcd_to_uhci(hcd);
0811 unsigned io_size = (unsigned) hcd->rsrc_len;
0812 int port;
0813
0814
0815
0816
0817
0818
0819
0820
0821
0822 for (port = 0; port < (io_size - USBPORTSC1) / 2; port++) {
0823 unsigned int portstatus;
0824
0825 portstatus = uhci_readw(uhci, USBPORTSC1 + (port * 2));
0826 if (!(portstatus & 0x0080) || portstatus == 0xffff)
0827 break;
0828 }
0829 if (debug)
0830 dev_info(uhci_dev(uhci), "detected %d ports\n", port);
0831
0832
0833 if (port > UHCI_RH_MAXCHILD) {
0834 dev_info(uhci_dev(uhci),
0835 "port count misdetected? forcing to 2 ports\n");
0836 port = 2;
0837 }
0838
0839 return port;
0840 }
0841
0842 static const char hcd_name[] = "uhci_hcd";
0843
0844 #ifdef CONFIG_USB_PCI
0845 #include "uhci-pci.c"
0846 #define PCI_DRIVER uhci_pci_driver
0847 #endif
0848
0849 #ifdef CONFIG_SPARC_LEON
0850 #include "uhci-grlib.c"
0851 #define PLATFORM_DRIVER uhci_grlib_driver
0852 #endif
0853
0854 #ifdef CONFIG_USB_UHCI_PLATFORM
0855 #include "uhci-platform.c"
0856 #define PLATFORM_DRIVER uhci_platform_driver
0857 #endif
0858
0859 #if !defined(PCI_DRIVER) && !defined(PLATFORM_DRIVER)
0860 #error "missing bus glue for uhci-hcd"
0861 #endif
0862
0863 static int __init uhci_hcd_init(void)
0864 {
0865 int retval = -ENOMEM;
0866
0867 if (usb_disabled())
0868 return -ENODEV;
0869
0870 printk(KERN_INFO "uhci_hcd: " DRIVER_DESC "%s\n",
0871 ignore_oc ? ", overcurrent ignored" : "");
0872 set_bit(USB_UHCI_LOADED, &usb_hcds_loaded);
0873
0874 #ifdef CONFIG_DYNAMIC_DEBUG
0875 errbuf = kmalloc(ERRBUF_LEN, GFP_KERNEL);
0876 if (!errbuf)
0877 goto errbuf_failed;
0878 uhci_debugfs_root = debugfs_create_dir("uhci", usb_debug_root);
0879 #endif
0880
0881 uhci_up_cachep = kmem_cache_create("uhci_urb_priv",
0882 sizeof(struct urb_priv), 0, 0, NULL);
0883 if (!uhci_up_cachep)
0884 goto up_failed;
0885
0886 #ifdef PLATFORM_DRIVER
0887 retval = platform_driver_register(&PLATFORM_DRIVER);
0888 if (retval < 0)
0889 goto clean0;
0890 #endif
0891
0892 #ifdef PCI_DRIVER
0893 retval = pci_register_driver(&PCI_DRIVER);
0894 if (retval < 0)
0895 goto clean1;
0896 #endif
0897
0898 return 0;
0899
0900 #ifdef PCI_DRIVER
0901 clean1:
0902 #endif
0903 #ifdef PLATFORM_DRIVER
0904 platform_driver_unregister(&PLATFORM_DRIVER);
0905 clean0:
0906 #endif
0907 kmem_cache_destroy(uhci_up_cachep);
0908
0909 up_failed:
0910 #if defined(DEBUG) || defined(CONFIG_DYNAMIC_DEBUG)
0911 debugfs_remove(uhci_debugfs_root);
0912
0913 kfree(errbuf);
0914
0915 errbuf_failed:
0916 #endif
0917
0918 clear_bit(USB_UHCI_LOADED, &usb_hcds_loaded);
0919 return retval;
0920 }
0921
0922 static void __exit uhci_hcd_cleanup(void)
0923 {
0924 #ifdef PLATFORM_DRIVER
0925 platform_driver_unregister(&PLATFORM_DRIVER);
0926 #endif
0927 #ifdef PCI_DRIVER
0928 pci_unregister_driver(&PCI_DRIVER);
0929 #endif
0930 kmem_cache_destroy(uhci_up_cachep);
0931 debugfs_remove(uhci_debugfs_root);
0932 #ifdef CONFIG_DYNAMIC_DEBUG
0933 kfree(errbuf);
0934 #endif
0935 clear_bit(USB_UHCI_LOADED, &usb_hcds_loaded);
0936 }
0937
0938 module_init(uhci_hcd_init);
0939 module_exit(uhci_hcd_cleanup);
0940
0941 MODULE_AUTHOR(DRIVER_AUTHOR);
0942 MODULE_DESCRIPTION(DRIVER_DESC);
0943 MODULE_LICENSE("GPL");