11da177e4SLinus Torvalds /* 21da177e4SLinus Torvalds * OHCI HCD (Host Controller Driver) for USB. 31da177e4SLinus Torvalds * 41da177e4SLinus Torvalds * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at> 51da177e4SLinus Torvalds * (C) Copyright 2000-2004 David Brownell <dbrownell@users.sourceforge.net> 61da177e4SLinus Torvalds * 71da177e4SLinus Torvalds * [ Initialisation is based on Linus' ] 81da177e4SLinus Torvalds * [ uhci code and gregs ohci fragments ] 91da177e4SLinus Torvalds * [ (C) Copyright 1999 Linus Torvalds ] 101da177e4SLinus Torvalds * [ (C) Copyright 1999 Gregory P. Smith] 111da177e4SLinus Torvalds * 121da177e4SLinus Torvalds * 131da177e4SLinus Torvalds * OHCI is the main "non-Intel/VIA" standard for USB 1.1 host controller 141da177e4SLinus Torvalds * interfaces (though some non-x86 Intel chips use it). It supports 151da177e4SLinus Torvalds * smarter hardware than UHCI. A download link for the spec available 161da177e4SLinus Torvalds * through the http://www.usb.org website. 171da177e4SLinus Torvalds * 181da177e4SLinus Torvalds * This file is licenced under the GPL. 191da177e4SLinus Torvalds */ 201da177e4SLinus Torvalds 211da177e4SLinus Torvalds #include <linux/module.h> 221da177e4SLinus Torvalds #include <linux/moduleparam.h> 231da177e4SLinus Torvalds #include <linux/pci.h> 241da177e4SLinus Torvalds #include <linux/kernel.h> 251da177e4SLinus Torvalds #include <linux/delay.h> 261da177e4SLinus Torvalds #include <linux/ioport.h> 271da177e4SLinus Torvalds #include <linux/sched.h> 281da177e4SLinus Torvalds #include <linux/slab.h> 291da177e4SLinus Torvalds #include <linux/errno.h> 301da177e4SLinus Torvalds #include <linux/init.h> 311da177e4SLinus Torvalds #include <linux/timer.h> 321da177e4SLinus Torvalds #include <linux/list.h> 331da177e4SLinus Torvalds #include <linux/usb.h> 343a16f7b4SDavid Brownell #include <linux/usb/otg.h> 351da177e4SLinus Torvalds #include <linux/dma-mapping.h> 36f4df0e33SDavid Brownell #include <linux/dmapool.h> 37f4df0e33SDavid Brownell #include <linux/reboot.h> 38d576bb9fSMichael Hanselmann #include <linux/workqueue.h> 39684c19e0STony Jones #include <linux/debugfs.h> 401da177e4SLinus Torvalds 411da177e4SLinus Torvalds #include <asm/io.h> 421da177e4SLinus Torvalds #include <asm/irq.h> 431da177e4SLinus Torvalds #include <asm/system.h> 441da177e4SLinus Torvalds #include <asm/unaligned.h> 451da177e4SLinus Torvalds #include <asm/byteorder.h> 461da177e4SLinus Torvalds 47f4df0e33SDavid Brownell #include "../core/hcd.h" 481da177e4SLinus Torvalds 491da177e4SLinus Torvalds #define DRIVER_AUTHOR "Roman Weissgaerber, David Brownell" 501da177e4SLinus Torvalds #define DRIVER_DESC "USB 1.1 'Open' Host Controller (OHCI) Driver" 511da177e4SLinus Torvalds 521da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/ 531da177e4SLinus Torvalds 548de98402SBenjamin Herrenschmidt #undef OHCI_VERBOSE_DEBUG /* not always helpful */ 551da177e4SLinus Torvalds 561da177e4SLinus Torvalds /* For initializing controller (mask in an HCFS mode too) */ 571da177e4SLinus Torvalds #define OHCI_CONTROL_INIT OHCI_CTRL_CBSR 581da177e4SLinus Torvalds #define OHCI_INTR_INIT \ 59d413984aSDavid Brownell (OHCI_INTR_MIE | OHCI_INTR_RHSC | OHCI_INTR_UE \ 60d413984aSDavid Brownell | OHCI_INTR_RD | OHCI_INTR_WDH) 611da177e4SLinus Torvalds 621da177e4SLinus Torvalds #ifdef __hppa__ 631da177e4SLinus Torvalds /* On PA-RISC, PDC can leave IR set incorrectly; ignore it there. */ 641da177e4SLinus Torvalds #define IR_DISABLE 651da177e4SLinus Torvalds #endif 661da177e4SLinus Torvalds 671da177e4SLinus Torvalds #ifdef CONFIG_ARCH_OMAP 681da177e4SLinus Torvalds /* OMAP doesn't support IR (no SMM; not needed) */ 691da177e4SLinus Torvalds #define IR_DISABLE 701da177e4SLinus Torvalds #endif 711da177e4SLinus Torvalds 721da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/ 731da177e4SLinus Torvalds 741da177e4SLinus Torvalds static const char hcd_name [] = "ohci_hcd"; 751da177e4SLinus Torvalds 76d413984aSDavid Brownell #define STATECHANGE_DELAY msecs_to_jiffies(300) 77d413984aSDavid Brownell 781da177e4SLinus Torvalds #include "ohci.h" 791da177e4SLinus Torvalds 801da177e4SLinus Torvalds static void ohci_dump (struct ohci_hcd *ohci, int verbose); 811da177e4SLinus Torvalds static int ohci_init (struct ohci_hcd *ohci); 821da177e4SLinus Torvalds static void ohci_stop (struct usb_hcd *hcd); 83da6fb570SDavid Brownell 84da6fb570SDavid Brownell #if defined(CONFIG_PM) || defined(CONFIG_PCI) 85d576bb9fSMichael Hanselmann static int ohci_restart (struct ohci_hcd *ohci); 86da6fb570SDavid Brownell #endif 871da177e4SLinus Torvalds 88ab1666c1SLibin Yang #ifdef CONFIG_PCI 89ab1666c1SLibin Yang static void quirk_amd_pll(int state); 90ab1666c1SLibin Yang static void amd_iso_dev_put(void); 91ab1666c1SLibin Yang #else 92ab1666c1SLibin Yang static inline void quirk_amd_pll(int state) 93ab1666c1SLibin Yang { 94ab1666c1SLibin Yang return; 95ab1666c1SLibin Yang } 96ab1666c1SLibin Yang static inline void amd_iso_dev_put(void) 97ab1666c1SLibin Yang { 98ab1666c1SLibin Yang return; 99ab1666c1SLibin Yang } 100ab1666c1SLibin Yang #endif 101ab1666c1SLibin Yang 102ab1666c1SLibin Yang 1031da177e4SLinus Torvalds #include "ohci-hub.c" 1041da177e4SLinus Torvalds #include "ohci-dbg.c" 1051da177e4SLinus Torvalds #include "ohci-mem.c" 1061da177e4SLinus Torvalds #include "ohci-q.c" 1071da177e4SLinus Torvalds 1081da177e4SLinus Torvalds 1091da177e4SLinus Torvalds /* 1101da177e4SLinus Torvalds * On architectures with edge-triggered interrupts we must never return 1111da177e4SLinus Torvalds * IRQ_NONE. 1121da177e4SLinus Torvalds */ 1131da177e4SLinus Torvalds #if defined(CONFIG_SA1111) /* ... or other edge-triggered systems */ 1141da177e4SLinus Torvalds #define IRQ_NOTMINE IRQ_HANDLED 1151da177e4SLinus Torvalds #else 1161da177e4SLinus Torvalds #define IRQ_NOTMINE IRQ_NONE 1171da177e4SLinus Torvalds #endif 1181da177e4SLinus Torvalds 1191da177e4SLinus Torvalds 1201da177e4SLinus Torvalds /* Some boards misreport power switching/overcurrent */ 1211da177e4SLinus Torvalds static int distrust_firmware = 1; 1221da177e4SLinus Torvalds module_param (distrust_firmware, bool, 0); 1231da177e4SLinus Torvalds MODULE_PARM_DESC (distrust_firmware, 1241da177e4SLinus Torvalds "true to distrust firmware power/overcurrent setup"); 1251da177e4SLinus Torvalds 1261da177e4SLinus Torvalds /* Some boards leave IR set wrongly, since they fail BIOS/SMM handshakes */ 1271da177e4SLinus Torvalds static int no_handshake = 0; 1281da177e4SLinus Torvalds module_param (no_handshake, bool, 0); 1291da177e4SLinus Torvalds MODULE_PARM_DESC (no_handshake, "true (not default) disables BIOS handshake"); 1301da177e4SLinus Torvalds 1311da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/ 1321da177e4SLinus Torvalds 1331da177e4SLinus Torvalds /* 1341da177e4SLinus Torvalds * queue up an urb for anything except the root hub 1351da177e4SLinus Torvalds */ 1361da177e4SLinus Torvalds static int ohci_urb_enqueue ( 1371da177e4SLinus Torvalds struct usb_hcd *hcd, 1381da177e4SLinus Torvalds struct urb *urb, 13955016f10SAl Viro gfp_t mem_flags 1401da177e4SLinus Torvalds ) { 1411da177e4SLinus Torvalds struct ohci_hcd *ohci = hcd_to_ohci (hcd); 1421da177e4SLinus Torvalds struct ed *ed; 1431da177e4SLinus Torvalds urb_priv_t *urb_priv; 1441da177e4SLinus Torvalds unsigned int pipe = urb->pipe; 1451da177e4SLinus Torvalds int i, size = 0; 1461da177e4SLinus Torvalds unsigned long flags; 1471da177e4SLinus Torvalds int retval = 0; 1481da177e4SLinus Torvalds 1491da177e4SLinus Torvalds #ifdef OHCI_VERBOSE_DEBUG 15055d84968SAlan Stern urb_print(urb, "SUB", usb_pipein(pipe), -EINPROGRESS); 1511da177e4SLinus Torvalds #endif 1521da177e4SLinus Torvalds 1531da177e4SLinus Torvalds /* every endpoint has a ed, locate and maybe (re)initialize it */ 154e9df41c5SAlan Stern if (! (ed = ed_get (ohci, urb->ep, urb->dev, pipe, urb->interval))) 1551da177e4SLinus Torvalds return -ENOMEM; 1561da177e4SLinus Torvalds 1571da177e4SLinus Torvalds /* for the private part of the URB we need the number of TDs (size) */ 1581da177e4SLinus Torvalds switch (ed->type) { 1591da177e4SLinus Torvalds case PIPE_CONTROL: 1601da177e4SLinus Torvalds /* td_submit_urb() doesn't yet handle these */ 1611da177e4SLinus Torvalds if (urb->transfer_buffer_length > 4096) 1621da177e4SLinus Torvalds return -EMSGSIZE; 1631da177e4SLinus Torvalds 1641da177e4SLinus Torvalds /* 1 TD for setup, 1 for ACK, plus ... */ 1651da177e4SLinus Torvalds size = 2; 1661da177e4SLinus Torvalds /* FALLTHROUGH */ 1671da177e4SLinus Torvalds // case PIPE_INTERRUPT: 1681da177e4SLinus Torvalds // case PIPE_BULK: 1691da177e4SLinus Torvalds default: 1701da177e4SLinus Torvalds /* one TD for every 4096 Bytes (can be upto 8K) */ 1711da177e4SLinus Torvalds size += urb->transfer_buffer_length / 4096; 1721da177e4SLinus Torvalds /* ... and for any remaining bytes ... */ 1731da177e4SLinus Torvalds if ((urb->transfer_buffer_length % 4096) != 0) 1741da177e4SLinus Torvalds size++; 1751da177e4SLinus Torvalds /* ... and maybe a zero length packet to wrap it up */ 1761da177e4SLinus Torvalds if (size == 0) 1771da177e4SLinus Torvalds size++; 1781da177e4SLinus Torvalds else if ((urb->transfer_flags & URB_ZERO_PACKET) != 0 1791da177e4SLinus Torvalds && (urb->transfer_buffer_length 1801da177e4SLinus Torvalds % usb_maxpacket (urb->dev, pipe, 1811da177e4SLinus Torvalds usb_pipeout (pipe))) == 0) 1821da177e4SLinus Torvalds size++; 1831da177e4SLinus Torvalds break; 1841da177e4SLinus Torvalds case PIPE_ISOCHRONOUS: /* number of packets from URB */ 1851da177e4SLinus Torvalds size = urb->number_of_packets; 1861da177e4SLinus Torvalds break; 1871da177e4SLinus Torvalds } 1881da177e4SLinus Torvalds 1891da177e4SLinus Torvalds /* allocate the private part of the URB */ 190dd00cc48SYoann Padioleau urb_priv = kzalloc (sizeof (urb_priv_t) + size * sizeof (struct td *), 1911da177e4SLinus Torvalds mem_flags); 1921da177e4SLinus Torvalds if (!urb_priv) 1931da177e4SLinus Torvalds return -ENOMEM; 1941da177e4SLinus Torvalds INIT_LIST_HEAD (&urb_priv->pending); 1951da177e4SLinus Torvalds urb_priv->length = size; 1961da177e4SLinus Torvalds urb_priv->ed = ed; 1971da177e4SLinus Torvalds 1981da177e4SLinus Torvalds /* allocate the TDs (deferring hash chain updates) */ 1991da177e4SLinus Torvalds for (i = 0; i < size; i++) { 2001da177e4SLinus Torvalds urb_priv->td [i] = td_alloc (ohci, mem_flags); 2011da177e4SLinus Torvalds if (!urb_priv->td [i]) { 2021da177e4SLinus Torvalds urb_priv->length = i; 2031da177e4SLinus Torvalds urb_free_priv (ohci, urb_priv); 2041da177e4SLinus Torvalds return -ENOMEM; 2051da177e4SLinus Torvalds } 2061da177e4SLinus Torvalds } 2071da177e4SLinus Torvalds 2081da177e4SLinus Torvalds spin_lock_irqsave (&ohci->lock, flags); 2091da177e4SLinus Torvalds 2101da177e4SLinus Torvalds /* don't submit to a dead HC */ 2118de98402SBenjamin Herrenschmidt if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) { 2128de98402SBenjamin Herrenschmidt retval = -ENODEV; 2138de98402SBenjamin Herrenschmidt goto fail; 2148de98402SBenjamin Herrenschmidt } 2151da177e4SLinus Torvalds if (!HC_IS_RUNNING(hcd->state)) { 2161da177e4SLinus Torvalds retval = -ENODEV; 2171da177e4SLinus Torvalds goto fail; 2181da177e4SLinus Torvalds } 219e9df41c5SAlan Stern retval = usb_hcd_link_urb_to_ep(hcd, urb); 220e9df41c5SAlan Stern if (retval) 2211da177e4SLinus Torvalds goto fail; 2221da177e4SLinus Torvalds 2231da177e4SLinus Torvalds /* schedule the ed if needed */ 2241da177e4SLinus Torvalds if (ed->state == ED_IDLE) { 2251da177e4SLinus Torvalds retval = ed_schedule (ohci, ed); 226e9df41c5SAlan Stern if (retval < 0) { 227e9df41c5SAlan Stern usb_hcd_unlink_urb_from_ep(hcd, urb); 228e9df41c5SAlan Stern goto fail; 229e9df41c5SAlan Stern } 2301da177e4SLinus Torvalds if (ed->type == PIPE_ISOCHRONOUS) { 2311da177e4SLinus Torvalds u16 frame = ohci_frame_no(ohci); 2321da177e4SLinus Torvalds 2331da177e4SLinus Torvalds /* delay a few frames before the first TD */ 2341da177e4SLinus Torvalds frame += max_t (u16, 8, ed->interval); 2351da177e4SLinus Torvalds frame &= ~(ed->interval - 1); 2361da177e4SLinus Torvalds frame |= ed->branch; 2371da177e4SLinus Torvalds urb->start_frame = frame; 2381da177e4SLinus Torvalds 2391da177e4SLinus Torvalds /* yes, only URB_ISO_ASAP is supported, and 2401da177e4SLinus Torvalds * urb->start_frame is never used as input. 2411da177e4SLinus Torvalds */ 2421da177e4SLinus Torvalds } 2431da177e4SLinus Torvalds } else if (ed->type == PIPE_ISOCHRONOUS) 2441da177e4SLinus Torvalds urb->start_frame = ed->last_iso + ed->interval; 2451da177e4SLinus Torvalds 2461da177e4SLinus Torvalds /* fill the TDs and link them to the ed; and 2471da177e4SLinus Torvalds * enable that part of the schedule, if needed 2481da177e4SLinus Torvalds * and update count of queued periodic urbs 2491da177e4SLinus Torvalds */ 2501da177e4SLinus Torvalds urb->hcpriv = urb_priv; 2511da177e4SLinus Torvalds td_submit_urb (ohci, urb); 2521da177e4SLinus Torvalds 2531da177e4SLinus Torvalds fail: 2541da177e4SLinus Torvalds if (retval) 2551da177e4SLinus Torvalds urb_free_priv (ohci, urb_priv); 2561da177e4SLinus Torvalds spin_unlock_irqrestore (&ohci->lock, flags); 2571da177e4SLinus Torvalds return retval; 2581da177e4SLinus Torvalds } 2591da177e4SLinus Torvalds 2601da177e4SLinus Torvalds /* 26155d84968SAlan Stern * decouple the URB from the HC queues (TDs, urb_priv). 26255d84968SAlan Stern * reporting is always done 2631da177e4SLinus Torvalds * asynchronously, and we might be dealing with an urb that's 2641da177e4SLinus Torvalds * partially transferred, or an ED with other urbs being unlinked. 2651da177e4SLinus Torvalds */ 266e9df41c5SAlan Stern static int ohci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status) 2671da177e4SLinus Torvalds { 2681da177e4SLinus Torvalds struct ohci_hcd *ohci = hcd_to_ohci (hcd); 2691da177e4SLinus Torvalds unsigned long flags; 270e9df41c5SAlan Stern int rc; 2711da177e4SLinus Torvalds 2721da177e4SLinus Torvalds #ifdef OHCI_VERBOSE_DEBUG 27355d84968SAlan Stern urb_print(urb, "UNLINK", 1, status); 2741da177e4SLinus Torvalds #endif 2751da177e4SLinus Torvalds 2761da177e4SLinus Torvalds spin_lock_irqsave (&ohci->lock, flags); 277e9df41c5SAlan Stern rc = usb_hcd_check_unlink_urb(hcd, urb, status); 278e9df41c5SAlan Stern if (rc) { 279e9df41c5SAlan Stern ; /* Do nothing */ 280e9df41c5SAlan Stern } else if (HC_IS_RUNNING(hcd->state)) { 2811da177e4SLinus Torvalds urb_priv_t *urb_priv; 2821da177e4SLinus Torvalds 2831da177e4SLinus Torvalds /* Unless an IRQ completed the unlink while it was being 2841da177e4SLinus Torvalds * handed to us, flag it for unlink and giveback, and force 2851da177e4SLinus Torvalds * some upcoming INTR_SF to call finish_unlinks() 2861da177e4SLinus Torvalds */ 2871da177e4SLinus Torvalds urb_priv = urb->hcpriv; 2881da177e4SLinus Torvalds if (urb_priv) { 2891da177e4SLinus Torvalds if (urb_priv->ed->state == ED_OPER) 2901da177e4SLinus Torvalds start_ed_unlink (ohci, urb_priv->ed); 2911da177e4SLinus Torvalds } 2921da177e4SLinus Torvalds } else { 2931da177e4SLinus Torvalds /* 2941da177e4SLinus Torvalds * with HC dead, we won't respect hc queue pointers 2951da177e4SLinus Torvalds * any more ... just clean up every urb's memory. 2961da177e4SLinus Torvalds */ 2971da177e4SLinus Torvalds if (urb->hcpriv) 29855d84968SAlan Stern finish_urb(ohci, urb, status); 2991da177e4SLinus Torvalds } 3001da177e4SLinus Torvalds spin_unlock_irqrestore (&ohci->lock, flags); 301e9df41c5SAlan Stern return rc; 3021da177e4SLinus Torvalds } 3031da177e4SLinus Torvalds 3041da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/ 3051da177e4SLinus Torvalds 3061da177e4SLinus Torvalds /* frees config/altsetting state for endpoints, 3071da177e4SLinus Torvalds * including ED memory, dummy TD, and bulk/intr data toggle 3081da177e4SLinus Torvalds */ 3091da177e4SLinus Torvalds 3101da177e4SLinus Torvalds static void 3111da177e4SLinus Torvalds ohci_endpoint_disable (struct usb_hcd *hcd, struct usb_host_endpoint *ep) 3121da177e4SLinus Torvalds { 3131da177e4SLinus Torvalds struct ohci_hcd *ohci = hcd_to_ohci (hcd); 3141da177e4SLinus Torvalds unsigned long flags; 3151da177e4SLinus Torvalds struct ed *ed = ep->hcpriv; 3161da177e4SLinus Torvalds unsigned limit = 1000; 3171da177e4SLinus Torvalds 3181da177e4SLinus Torvalds /* ASSERT: any requests/urbs are being unlinked */ 3191da177e4SLinus Torvalds /* ASSERT: nobody can be submitting urbs for this any more */ 3201da177e4SLinus Torvalds 3211da177e4SLinus Torvalds if (!ed) 3221da177e4SLinus Torvalds return; 3231da177e4SLinus Torvalds 3241da177e4SLinus Torvalds rescan: 3251da177e4SLinus Torvalds spin_lock_irqsave (&ohci->lock, flags); 3261da177e4SLinus Torvalds 3271da177e4SLinus Torvalds if (!HC_IS_RUNNING (hcd->state)) { 3281da177e4SLinus Torvalds sanitize: 3291da177e4SLinus Torvalds ed->state = ED_IDLE; 33089a0fd18SMike Nuss if (quirk_zfmicro(ohci) && ed->type == PIPE_INTERRUPT) 33189a0fd18SMike Nuss ohci->eds_scheduled--; 3327d12e780SDavid Howells finish_unlinks (ohci, 0); 3331da177e4SLinus Torvalds } 3341da177e4SLinus Torvalds 3351da177e4SLinus Torvalds switch (ed->state) { 3361da177e4SLinus Torvalds case ED_UNLINK: /* wait for hw to finish? */ 3371da177e4SLinus Torvalds /* major IRQ delivery trouble loses INTR_SF too... */ 3381da177e4SLinus Torvalds if (limit-- == 0) { 33989a0fd18SMike Nuss ohci_warn(ohci, "ED unlink timeout\n"); 34089a0fd18SMike Nuss if (quirk_zfmicro(ohci)) { 34189a0fd18SMike Nuss ohci_warn(ohci, "Attempting ZF TD recovery\n"); 34289a0fd18SMike Nuss ohci->ed_to_check = ed; 34389a0fd18SMike Nuss ohci->zf_delay = 2; 34489a0fd18SMike Nuss } 3451da177e4SLinus Torvalds goto sanitize; 3461da177e4SLinus Torvalds } 3471da177e4SLinus Torvalds spin_unlock_irqrestore (&ohci->lock, flags); 34822c43863SNishanth Aravamudan schedule_timeout_uninterruptible(1); 3491da177e4SLinus Torvalds goto rescan; 3501da177e4SLinus Torvalds case ED_IDLE: /* fully unlinked */ 3511da177e4SLinus Torvalds if (list_empty (&ed->td_list)) { 3521da177e4SLinus Torvalds td_free (ohci, ed->dummy); 3531da177e4SLinus Torvalds ed_free (ohci, ed); 3541da177e4SLinus Torvalds break; 3551da177e4SLinus Torvalds } 3561da177e4SLinus Torvalds /* else FALL THROUGH */ 3571da177e4SLinus Torvalds default: 3581da177e4SLinus Torvalds /* caller was supposed to have unlinked any requests; 3591da177e4SLinus Torvalds * that's not our job. can't recover; must leak ed. 3601da177e4SLinus Torvalds */ 3611da177e4SLinus Torvalds ohci_err (ohci, "leak ed %p (#%02x) state %d%s\n", 3621da177e4SLinus Torvalds ed, ep->desc.bEndpointAddress, ed->state, 3631da177e4SLinus Torvalds list_empty (&ed->td_list) ? "" : " (has tds)"); 3641da177e4SLinus Torvalds td_free (ohci, ed->dummy); 3651da177e4SLinus Torvalds break; 3661da177e4SLinus Torvalds } 3671da177e4SLinus Torvalds ep->hcpriv = NULL; 3681da177e4SLinus Torvalds spin_unlock_irqrestore (&ohci->lock, flags); 3691da177e4SLinus Torvalds return; 3701da177e4SLinus Torvalds } 3711da177e4SLinus Torvalds 3721da177e4SLinus Torvalds static int ohci_get_frame (struct usb_hcd *hcd) 3731da177e4SLinus Torvalds { 3741da177e4SLinus Torvalds struct ohci_hcd *ohci = hcd_to_ohci (hcd); 3751da177e4SLinus Torvalds 3761da177e4SLinus Torvalds return ohci_frame_no(ohci); 3771da177e4SLinus Torvalds } 3781da177e4SLinus Torvalds 3791da177e4SLinus Torvalds static void ohci_usb_reset (struct ohci_hcd *ohci) 3801da177e4SLinus Torvalds { 3811da177e4SLinus Torvalds ohci->hc_control = ohci_readl (ohci, &ohci->regs->control); 3821da177e4SLinus Torvalds ohci->hc_control &= OHCI_CTRL_RWC; 3831da177e4SLinus Torvalds ohci_writel (ohci, ohci->hc_control, &ohci->regs->control); 3841da177e4SLinus Torvalds } 3851da177e4SLinus Torvalds 38664a21d02SAleksey Gorelov /* ohci_shutdown forcibly disables IRQs and DMA, helping kexec and 387f4df0e33SDavid Brownell * other cases where the next software may expect clean state from the 388f4df0e33SDavid Brownell * "firmware". this is bus-neutral, unlike shutdown() methods. 389f4df0e33SDavid Brownell */ 39064a21d02SAleksey Gorelov static void 39164a21d02SAleksey Gorelov ohci_shutdown (struct usb_hcd *hcd) 392f4df0e33SDavid Brownell { 393f4df0e33SDavid Brownell struct ohci_hcd *ohci; 394f4df0e33SDavid Brownell 39564a21d02SAleksey Gorelov ohci = hcd_to_ohci (hcd); 396f4df0e33SDavid Brownell ohci_writel (ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable); 397f4df0e33SDavid Brownell ohci_usb_reset (ohci); 398f4df0e33SDavid Brownell /* flush the writes */ 399f4df0e33SDavid Brownell (void) ohci_readl (ohci, &ohci->regs->control); 400f4df0e33SDavid Brownell } 401f4df0e33SDavid Brownell 40289a0fd18SMike Nuss static int check_ed(struct ohci_hcd *ohci, struct ed *ed) 40389a0fd18SMike Nuss { 40489a0fd18SMike Nuss return (hc32_to_cpu(ohci, ed->hwINFO) & ED_IN) != 0 40589a0fd18SMike Nuss && (hc32_to_cpu(ohci, ed->hwHeadP) & TD_MASK) 40689a0fd18SMike Nuss == (hc32_to_cpu(ohci, ed->hwTailP) & TD_MASK) 40789a0fd18SMike Nuss && !list_empty(&ed->td_list); 40889a0fd18SMike Nuss } 40989a0fd18SMike Nuss 41089a0fd18SMike Nuss /* ZF Micro watchdog timer callback. The ZF Micro chipset sometimes completes 41189a0fd18SMike Nuss * an interrupt TD but neglects to add it to the donelist. On systems with 41289a0fd18SMike Nuss * this chipset, we need to periodically check the state of the queues to look 41389a0fd18SMike Nuss * for such "lost" TDs. 41489a0fd18SMike Nuss */ 41589a0fd18SMike Nuss static void unlink_watchdog_func(unsigned long _ohci) 41689a0fd18SMike Nuss { 417da6fb570SDavid Brownell unsigned long flags; 41889a0fd18SMike Nuss unsigned max; 41989a0fd18SMike Nuss unsigned seen_count = 0; 42089a0fd18SMike Nuss unsigned i; 42189a0fd18SMike Nuss struct ed **seen = NULL; 42289a0fd18SMike Nuss struct ohci_hcd *ohci = (struct ohci_hcd *) _ohci; 42389a0fd18SMike Nuss 42489a0fd18SMike Nuss spin_lock_irqsave(&ohci->lock, flags); 42589a0fd18SMike Nuss max = ohci->eds_scheduled; 42689a0fd18SMike Nuss if (!max) 42789a0fd18SMike Nuss goto done; 42889a0fd18SMike Nuss 42989a0fd18SMike Nuss if (ohci->ed_to_check) 43089a0fd18SMike Nuss goto out; 43189a0fd18SMike Nuss 43289a0fd18SMike Nuss seen = kcalloc(max, sizeof *seen, GFP_ATOMIC); 43389a0fd18SMike Nuss if (!seen) 43489a0fd18SMike Nuss goto out; 43589a0fd18SMike Nuss 43689a0fd18SMike Nuss for (i = 0; i < NUM_INTS; i++) { 43789a0fd18SMike Nuss struct ed *ed = ohci->periodic[i]; 43889a0fd18SMike Nuss 43989a0fd18SMike Nuss while (ed) { 44089a0fd18SMike Nuss unsigned temp; 44189a0fd18SMike Nuss 44289a0fd18SMike Nuss /* scan this branch of the periodic schedule tree */ 44389a0fd18SMike Nuss for (temp = 0; temp < seen_count; temp++) { 44489a0fd18SMike Nuss if (seen[temp] == ed) { 44589a0fd18SMike Nuss /* we've checked it and what's after */ 44689a0fd18SMike Nuss ed = NULL; 44789a0fd18SMike Nuss break; 44889a0fd18SMike Nuss } 44989a0fd18SMike Nuss } 45089a0fd18SMike Nuss if (!ed) 45189a0fd18SMike Nuss break; 45289a0fd18SMike Nuss seen[seen_count++] = ed; 45389a0fd18SMike Nuss if (!check_ed(ohci, ed)) { 45489a0fd18SMike Nuss ed = ed->ed_next; 45589a0fd18SMike Nuss continue; 45689a0fd18SMike Nuss } 45789a0fd18SMike Nuss 45889a0fd18SMike Nuss /* HC's TD list is empty, but HCD sees at least one 45989a0fd18SMike Nuss * TD that's not been sent through the donelist. 46089a0fd18SMike Nuss */ 46189a0fd18SMike Nuss ohci->ed_to_check = ed; 46289a0fd18SMike Nuss ohci->zf_delay = 2; 46389a0fd18SMike Nuss 46489a0fd18SMike Nuss /* The HC may wait until the next frame to report the 46589a0fd18SMike Nuss * TD as done through the donelist and INTR_WDH. (We 46689a0fd18SMike Nuss * just *assume* it's not a multi-TD interrupt URB; 46789a0fd18SMike Nuss * those could defer the IRQ more than one frame, using 46889a0fd18SMike Nuss * DI...) Check again after the next INTR_SF. 46989a0fd18SMike Nuss */ 47089a0fd18SMike Nuss ohci_writel(ohci, OHCI_INTR_SF, 47189a0fd18SMike Nuss &ohci->regs->intrstatus); 47289a0fd18SMike Nuss ohci_writel(ohci, OHCI_INTR_SF, 47389a0fd18SMike Nuss &ohci->regs->intrenable); 47489a0fd18SMike Nuss 47589a0fd18SMike Nuss /* flush those writes */ 47689a0fd18SMike Nuss (void) ohci_readl(ohci, &ohci->regs->control); 47789a0fd18SMike Nuss 47889a0fd18SMike Nuss goto out; 47989a0fd18SMike Nuss } 48089a0fd18SMike Nuss } 48189a0fd18SMike Nuss out: 48289a0fd18SMike Nuss kfree(seen); 48389a0fd18SMike Nuss if (ohci->eds_scheduled) 4849cebcdc7SRichard Kennedy mod_timer(&ohci->unlink_watchdog, round_jiffies(jiffies + HZ)); 48589a0fd18SMike Nuss done: 48689a0fd18SMike Nuss spin_unlock_irqrestore(&ohci->lock, flags); 48789a0fd18SMike Nuss } 48889a0fd18SMike Nuss 4891da177e4SLinus Torvalds /*-------------------------------------------------------------------------* 4901da177e4SLinus Torvalds * HC functions 4911da177e4SLinus Torvalds *-------------------------------------------------------------------------*/ 4921da177e4SLinus Torvalds 4931da177e4SLinus Torvalds /* init memory, and kick BIOS/SMM off */ 4941da177e4SLinus Torvalds 4951da177e4SLinus Torvalds static int ohci_init (struct ohci_hcd *ohci) 4961da177e4SLinus Torvalds { 4971da177e4SLinus Torvalds int ret; 4986a9062f3SDavid Brownell struct usb_hcd *hcd = ohci_to_hcd(ohci); 4991da177e4SLinus Torvalds 5001133cd8aSDmitry Baryshkov if (distrust_firmware) 5011133cd8aSDmitry Baryshkov ohci->flags |= OHCI_QUIRK_HUB_POWER; 5021133cd8aSDmitry Baryshkov 5031da177e4SLinus Torvalds disable (ohci); 5046a9062f3SDavid Brownell ohci->regs = hcd->regs; 5051da177e4SLinus Torvalds 5066a9062f3SDavid Brownell /* REVISIT this BIOS handshake is now moved into PCI "quirks", and 5076a9062f3SDavid Brownell * was never needed for most non-PCI systems ... remove the code? 5086a9062f3SDavid Brownell */ 5096a9062f3SDavid Brownell 5101da177e4SLinus Torvalds #ifndef IR_DISABLE 5111da177e4SLinus Torvalds /* SMM owns the HC? not for long! */ 5121da177e4SLinus Torvalds if (!no_handshake && ohci_readl (ohci, 5131da177e4SLinus Torvalds &ohci->regs->control) & OHCI_CTRL_IR) { 5141da177e4SLinus Torvalds u32 temp; 5151da177e4SLinus Torvalds 5161da177e4SLinus Torvalds ohci_dbg (ohci, "USB HC TakeOver from BIOS/SMM\n"); 5171da177e4SLinus Torvalds 5181da177e4SLinus Torvalds /* this timeout is arbitrary. we make it long, so systems 5191da177e4SLinus Torvalds * depending on usb keyboards may be usable even if the 5201da177e4SLinus Torvalds * BIOS/SMM code seems pretty broken. 5211da177e4SLinus Torvalds */ 5221da177e4SLinus Torvalds temp = 500; /* arbitrary: five seconds */ 5231da177e4SLinus Torvalds 5241da177e4SLinus Torvalds ohci_writel (ohci, OHCI_INTR_OC, &ohci->regs->intrenable); 5251da177e4SLinus Torvalds ohci_writel (ohci, OHCI_OCR, &ohci->regs->cmdstatus); 5261da177e4SLinus Torvalds while (ohci_readl (ohci, &ohci->regs->control) & OHCI_CTRL_IR) { 5271da177e4SLinus Torvalds msleep (10); 5281da177e4SLinus Torvalds if (--temp == 0) { 5291da177e4SLinus Torvalds ohci_err (ohci, "USB HC takeover failed!" 5301da177e4SLinus Torvalds " (BIOS/SMM bug)\n"); 5311da177e4SLinus Torvalds return -EBUSY; 5321da177e4SLinus Torvalds } 5331da177e4SLinus Torvalds } 5341da177e4SLinus Torvalds ohci_usb_reset (ohci); 5351da177e4SLinus Torvalds } 5361da177e4SLinus Torvalds #endif 5371da177e4SLinus Torvalds 5381da177e4SLinus Torvalds /* Disable HC interrupts */ 5391da177e4SLinus Torvalds ohci_writel (ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable); 5406a9062f3SDavid Brownell 5416a9062f3SDavid Brownell /* flush the writes, and save key bits like RWC */ 5426a9062f3SDavid Brownell if (ohci_readl (ohci, &ohci->regs->control) & OHCI_CTRL_RWC) 5436a9062f3SDavid Brownell ohci->hc_control |= OHCI_CTRL_RWC; 5441da177e4SLinus Torvalds 545fdd13b36SDavid Brownell /* Read the number of ports unless overridden */ 546fdd13b36SDavid Brownell if (ohci->num_ports == 0) 547fdd13b36SDavid Brownell ohci->num_ports = roothub_a(ohci) & RH_A_NDP; 548fdd13b36SDavid Brownell 5491da177e4SLinus Torvalds if (ohci->hcca) 5501da177e4SLinus Torvalds return 0; 5511da177e4SLinus Torvalds 5526a9062f3SDavid Brownell ohci->hcca = dma_alloc_coherent (hcd->self.controller, 5531da177e4SLinus Torvalds sizeof *ohci->hcca, &ohci->hcca_dma, 0); 5541da177e4SLinus Torvalds if (!ohci->hcca) 5551da177e4SLinus Torvalds return -ENOMEM; 5561da177e4SLinus Torvalds 5571da177e4SLinus Torvalds if ((ret = ohci_mem_init (ohci)) < 0) 5586a9062f3SDavid Brownell ohci_stop (hcd); 5596a9062f3SDavid Brownell else { 5606a9062f3SDavid Brownell create_debug_files (ohci); 5616a9062f3SDavid Brownell } 5621da177e4SLinus Torvalds 5631da177e4SLinus Torvalds return ret; 5641da177e4SLinus Torvalds } 5651da177e4SLinus Torvalds 5661da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/ 5671da177e4SLinus Torvalds 5681da177e4SLinus Torvalds /* Start an OHCI controller, set the BUS operational 5691da177e4SLinus Torvalds * resets USB and controller 5701da177e4SLinus Torvalds * enable interrupts 5711da177e4SLinus Torvalds */ 5721da177e4SLinus Torvalds static int ohci_run (struct ohci_hcd *ohci) 5731da177e4SLinus Torvalds { 5741da177e4SLinus Torvalds u32 mask, temp; 5751da177e4SLinus Torvalds int first = ohci->fminterval == 0; 5766a9062f3SDavid Brownell struct usb_hcd *hcd = ohci_to_hcd(ohci); 5771da177e4SLinus Torvalds 5781da177e4SLinus Torvalds disable (ohci); 5791da177e4SLinus Torvalds 5801da177e4SLinus Torvalds /* boot firmware should have set this up (5.1.1.3.1) */ 5811da177e4SLinus Torvalds if (first) { 5821da177e4SLinus Torvalds 5831da177e4SLinus Torvalds temp = ohci_readl (ohci, &ohci->regs->fminterval); 5841da177e4SLinus Torvalds ohci->fminterval = temp & 0x3fff; 5851da177e4SLinus Torvalds if (ohci->fminterval != FI) 5861da177e4SLinus Torvalds ohci_dbg (ohci, "fminterval delta %d\n", 5871da177e4SLinus Torvalds ohci->fminterval - FI); 5881da177e4SLinus Torvalds ohci->fminterval |= FSMP (ohci->fminterval) << 16; 5891da177e4SLinus Torvalds /* also: power/overcurrent flags in roothub.a */ 5901da177e4SLinus Torvalds } 5911da177e4SLinus Torvalds 5926fd9086aSAlan Stern /* Reset USB nearly "by the book". RemoteWakeupConnected has 5936fd9086aSAlan Stern * to be checked in case boot firmware (BIOS/SMM/...) has set up 5946fd9086aSAlan Stern * wakeup in a way the bus isn't aware of (e.g., legacy PCI PM). 5956fd9086aSAlan Stern * If the bus glue detected wakeup capability then it should 596bcca06efSAlan Stern * already be enabled; if so we'll just enable it again. 5971da177e4SLinus Torvalds */ 598bcca06efSAlan Stern if ((ohci->hc_control & OHCI_CTRL_RWC) != 0) 599bcca06efSAlan Stern device_set_wakeup_capable(hcd->self.controller, 1); 6001da177e4SLinus Torvalds 6011da177e4SLinus Torvalds switch (ohci->hc_control & OHCI_CTRL_HCFS) { 6021da177e4SLinus Torvalds case OHCI_USB_OPER: 6031da177e4SLinus Torvalds temp = 0; 6041da177e4SLinus Torvalds break; 6051da177e4SLinus Torvalds case OHCI_USB_SUSPEND: 6061da177e4SLinus Torvalds case OHCI_USB_RESUME: 6071da177e4SLinus Torvalds ohci->hc_control &= OHCI_CTRL_RWC; 6081da177e4SLinus Torvalds ohci->hc_control |= OHCI_USB_RESUME; 6091da177e4SLinus Torvalds temp = 10 /* msec wait */; 6101da177e4SLinus Torvalds break; 6111da177e4SLinus Torvalds // case OHCI_USB_RESET: 6121da177e4SLinus Torvalds default: 6131da177e4SLinus Torvalds ohci->hc_control &= OHCI_CTRL_RWC; 6141da177e4SLinus Torvalds ohci->hc_control |= OHCI_USB_RESET; 6151da177e4SLinus Torvalds temp = 50 /* msec wait */; 6161da177e4SLinus Torvalds break; 6171da177e4SLinus Torvalds } 6181da177e4SLinus Torvalds ohci_writel (ohci, ohci->hc_control, &ohci->regs->control); 6191da177e4SLinus Torvalds // flush the writes 6201da177e4SLinus Torvalds (void) ohci_readl (ohci, &ohci->regs->control); 6211da177e4SLinus Torvalds msleep(temp); 622383975d7SAlan Stern 6231da177e4SLinus Torvalds memset (ohci->hcca, 0, sizeof (struct ohci_hcca)); 6241da177e4SLinus Torvalds 6251da177e4SLinus Torvalds /* 2msec timelimit here means no irqs/preempt */ 6261da177e4SLinus Torvalds spin_lock_irq (&ohci->lock); 6271da177e4SLinus Torvalds 6281da177e4SLinus Torvalds retry: 6291da177e4SLinus Torvalds /* HC Reset requires max 10 us delay */ 6301da177e4SLinus Torvalds ohci_writel (ohci, OHCI_HCR, &ohci->regs->cmdstatus); 6311da177e4SLinus Torvalds temp = 30; /* ... allow extra time */ 6321da177e4SLinus Torvalds while ((ohci_readl (ohci, &ohci->regs->cmdstatus) & OHCI_HCR) != 0) { 6331da177e4SLinus Torvalds if (--temp == 0) { 6341da177e4SLinus Torvalds spin_unlock_irq (&ohci->lock); 6351da177e4SLinus Torvalds ohci_err (ohci, "USB HC reset timed out!\n"); 6361da177e4SLinus Torvalds return -1; 6371da177e4SLinus Torvalds } 6381da177e4SLinus Torvalds udelay (1); 6391da177e4SLinus Torvalds } 6401da177e4SLinus Torvalds 6411da177e4SLinus Torvalds /* now we're in the SUSPEND state ... must go OPERATIONAL 6421da177e4SLinus Torvalds * within 2msec else HC enters RESUME 6431da177e4SLinus Torvalds * 6441da177e4SLinus Torvalds * ... but some hardware won't init fmInterval "by the book" 6451da177e4SLinus Torvalds * (SiS, OPTi ...), so reset again instead. SiS doesn't need 6461da177e4SLinus Torvalds * this if we write fmInterval after we're OPERATIONAL. 6471da177e4SLinus Torvalds * Unclear about ALi, ServerWorks, and others ... this could 6481da177e4SLinus Torvalds * easily be a longstanding bug in chip init on Linux. 6491da177e4SLinus Torvalds */ 6501da177e4SLinus Torvalds if (ohci->flags & OHCI_QUIRK_INITRESET) { 6511da177e4SLinus Torvalds ohci_writel (ohci, ohci->hc_control, &ohci->regs->control); 6521da177e4SLinus Torvalds // flush those writes 6531da177e4SLinus Torvalds (void) ohci_readl (ohci, &ohci->regs->control); 6541da177e4SLinus Torvalds } 6551da177e4SLinus Torvalds 6561da177e4SLinus Torvalds /* Tell the controller where the control and bulk lists are 6571da177e4SLinus Torvalds * The lists are empty now. */ 6581da177e4SLinus Torvalds ohci_writel (ohci, 0, &ohci->regs->ed_controlhead); 6591da177e4SLinus Torvalds ohci_writel (ohci, 0, &ohci->regs->ed_bulkhead); 6601da177e4SLinus Torvalds 6611da177e4SLinus Torvalds /* a reset clears this */ 6621da177e4SLinus Torvalds ohci_writel (ohci, (u32) ohci->hcca_dma, &ohci->regs->hcca); 6631da177e4SLinus Torvalds 6641da177e4SLinus Torvalds periodic_reinit (ohci); 6651da177e4SLinus Torvalds 6661da177e4SLinus Torvalds /* some OHCI implementations are finicky about how they init. 6671da177e4SLinus Torvalds * bogus values here mean not even enumeration could work. 6681da177e4SLinus Torvalds */ 6691da177e4SLinus Torvalds if ((ohci_readl (ohci, &ohci->regs->fminterval) & 0x3fff0000) == 0 6701da177e4SLinus Torvalds || !ohci_readl (ohci, &ohci->regs->periodicstart)) { 6711da177e4SLinus Torvalds if (!(ohci->flags & OHCI_QUIRK_INITRESET)) { 6721da177e4SLinus Torvalds ohci->flags |= OHCI_QUIRK_INITRESET; 6731da177e4SLinus Torvalds ohci_dbg (ohci, "enabling initreset quirk\n"); 6741da177e4SLinus Torvalds goto retry; 6751da177e4SLinus Torvalds } 6761da177e4SLinus Torvalds spin_unlock_irq (&ohci->lock); 6771da177e4SLinus Torvalds ohci_err (ohci, "init err (%08x %04x)\n", 6781da177e4SLinus Torvalds ohci_readl (ohci, &ohci->regs->fminterval), 6791da177e4SLinus Torvalds ohci_readl (ohci, &ohci->regs->periodicstart)); 6801da177e4SLinus Torvalds return -EOVERFLOW; 6811da177e4SLinus Torvalds } 6821da177e4SLinus Torvalds 683d413984aSDavid Brownell /* use rhsc irqs after khubd is fully initialized */ 684d413984aSDavid Brownell hcd->poll_rh = 1; 685d413984aSDavid Brownell hcd->uses_new_polling = 1; 686d413984aSDavid Brownell 6871da177e4SLinus Torvalds /* start controller operations */ 6881da177e4SLinus Torvalds ohci->hc_control &= OHCI_CTRL_RWC; 6891da177e4SLinus Torvalds ohci->hc_control |= OHCI_CONTROL_INIT | OHCI_USB_OPER; 6901da177e4SLinus Torvalds ohci_writel (ohci, ohci->hc_control, &ohci->regs->control); 6916a9062f3SDavid Brownell hcd->state = HC_STATE_RUNNING; 6921da177e4SLinus Torvalds 6931da177e4SLinus Torvalds /* wake on ConnectStatusChange, matching external hubs */ 6941da177e4SLinus Torvalds ohci_writel (ohci, RH_HS_DRWE, &ohci->regs->roothub.status); 6951da177e4SLinus Torvalds 6961da177e4SLinus Torvalds /* Choose the interrupts we care about now, others later on demand */ 6971da177e4SLinus Torvalds mask = OHCI_INTR_INIT; 698d413984aSDavid Brownell ohci_writel (ohci, ~0, &ohci->regs->intrstatus); 6991da177e4SLinus Torvalds ohci_writel (ohci, mask, &ohci->regs->intrenable); 7001da177e4SLinus Torvalds 7011da177e4SLinus Torvalds /* handle root hub init quirks ... */ 7021da177e4SLinus Torvalds temp = roothub_a (ohci); 7031da177e4SLinus Torvalds temp &= ~(RH_A_PSM | RH_A_OCPM); 7041da177e4SLinus Torvalds if (ohci->flags & OHCI_QUIRK_SUPERIO) { 7051da177e4SLinus Torvalds /* NSC 87560 and maybe others */ 7061da177e4SLinus Torvalds temp |= RH_A_NOCP; 7071da177e4SLinus Torvalds temp &= ~(RH_A_POTPGT | RH_A_NPS); 7081da177e4SLinus Torvalds ohci_writel (ohci, temp, &ohci->regs->roothub.a); 7091133cd8aSDmitry Baryshkov } else if ((ohci->flags & OHCI_QUIRK_AMD756) || 7101133cd8aSDmitry Baryshkov (ohci->flags & OHCI_QUIRK_HUB_POWER)) { 7111da177e4SLinus Torvalds /* hub power always on; required for AMD-756 and some 7121da177e4SLinus Torvalds * Mac platforms. ganged overcurrent reporting, if any. 7131da177e4SLinus Torvalds */ 7141da177e4SLinus Torvalds temp |= RH_A_NPS; 7151da177e4SLinus Torvalds ohci_writel (ohci, temp, &ohci->regs->roothub.a); 7161da177e4SLinus Torvalds } 7171da177e4SLinus Torvalds ohci_writel (ohci, RH_HS_LPSC, &ohci->regs->roothub.status); 7181da177e4SLinus Torvalds ohci_writel (ohci, (temp & RH_A_NPS) ? 0 : RH_B_PPCM, 7191da177e4SLinus Torvalds &ohci->regs->roothub.b); 7201da177e4SLinus Torvalds // flush those writes 7211da177e4SLinus Torvalds (void) ohci_readl (ohci, &ohci->regs->control); 7221da177e4SLinus Torvalds 723d413984aSDavid Brownell ohci->next_statechange = jiffies + STATECHANGE_DELAY; 7241da177e4SLinus Torvalds spin_unlock_irq (&ohci->lock); 7251da177e4SLinus Torvalds 7261da177e4SLinus Torvalds // POTPGT delay is bits 24-31, in 2 ms units. 7271da177e4SLinus Torvalds mdelay ((temp >> 23) & 0x1fe); 7286a9062f3SDavid Brownell hcd->state = HC_STATE_RUNNING; 7291da177e4SLinus Torvalds 73089a0fd18SMike Nuss if (quirk_zfmicro(ohci)) { 73189a0fd18SMike Nuss /* Create timer to watch for bad queue state on ZF Micro */ 73289a0fd18SMike Nuss setup_timer(&ohci->unlink_watchdog, unlink_watchdog_func, 73389a0fd18SMike Nuss (unsigned long) ohci); 73489a0fd18SMike Nuss 73589a0fd18SMike Nuss ohci->eds_scheduled = 0; 73689a0fd18SMike Nuss ohci->ed_to_check = NULL; 73789a0fd18SMike Nuss } 73889a0fd18SMike Nuss 7391da177e4SLinus Torvalds ohci_dump (ohci, 1); 7401da177e4SLinus Torvalds 7411da177e4SLinus Torvalds return 0; 7421da177e4SLinus Torvalds } 7431da177e4SLinus Torvalds 7441da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/ 7451da177e4SLinus Torvalds 7461da177e4SLinus Torvalds /* an interrupt happens */ 7471da177e4SLinus Torvalds 7487d12e780SDavid Howells static irqreturn_t ohci_irq (struct usb_hcd *hcd) 7491da177e4SLinus Torvalds { 7501da177e4SLinus Torvalds struct ohci_hcd *ohci = hcd_to_ohci (hcd); 7511da177e4SLinus Torvalds struct ohci_regs __iomem *regs = ohci->regs; 7521da177e4SLinus Torvalds int ints; 7531da177e4SLinus Torvalds 754565227c0SBenjamin Herrenschmidt /* Read interrupt status (and flush pending writes). We ignore the 755565227c0SBenjamin Herrenschmidt * optimization of checking the LSB of hcca->done_head; it doesn't 756565227c0SBenjamin Herrenschmidt * work on all systems (edge triggering for OHCI can be a factor). 75789a0fd18SMike Nuss */ 758565227c0SBenjamin Herrenschmidt ints = ohci_readl(ohci, ®s->intrstatus); 7591da177e4SLinus Torvalds 760565227c0SBenjamin Herrenschmidt /* Check for an all 1's result which is a typical consequence 761565227c0SBenjamin Herrenschmidt * of dead, unclocked, or unplugged (CardBus...) devices 762565227c0SBenjamin Herrenschmidt */ 763565227c0SBenjamin Herrenschmidt if (ints == ~(u32)0) { 7641da177e4SLinus Torvalds disable (ohci); 7651da177e4SLinus Torvalds ohci_dbg (ohci, "device removed!\n"); 7661da177e4SLinus Torvalds return IRQ_HANDLED; 767565227c0SBenjamin Herrenschmidt } 768565227c0SBenjamin Herrenschmidt 769565227c0SBenjamin Herrenschmidt /* We only care about interrupts that are enabled */ 770565227c0SBenjamin Herrenschmidt ints &= ohci_readl(ohci, ®s->intrenable); 7711da177e4SLinus Torvalds 7721da177e4SLinus Torvalds /* interrupt for some other device? */ 773565227c0SBenjamin Herrenschmidt if (ints == 0) 7741da177e4SLinus Torvalds return IRQ_NOTMINE; 7751da177e4SLinus Torvalds 7761da177e4SLinus Torvalds if (ints & OHCI_INTR_UE) { 777d576bb9fSMichael Hanselmann // e.g. due to PCI Master/Target Abort 77889a0fd18SMike Nuss if (quirk_nec(ohci)) { 779d576bb9fSMichael Hanselmann /* Workaround for a silicon bug in some NEC chips used 780d576bb9fSMichael Hanselmann * in Apple's PowerBooks. Adapted from Darwin code. 781d576bb9fSMichael Hanselmann */ 782d576bb9fSMichael Hanselmann ohci_err (ohci, "OHCI Unrecoverable Error, scheduling NEC chip restart\n"); 783d576bb9fSMichael Hanselmann 784d576bb9fSMichael Hanselmann ohci_writel (ohci, OHCI_INTR_UE, ®s->intrdisable); 785d576bb9fSMichael Hanselmann 786d576bb9fSMichael Hanselmann schedule_work (&ohci->nec_work); 787d576bb9fSMichael Hanselmann } else { 7881da177e4SLinus Torvalds disable (ohci); 7891da177e4SLinus Torvalds ohci_err (ohci, "OHCI Unrecoverable Error, disabled\n"); 790d576bb9fSMichael Hanselmann } 7911da177e4SLinus Torvalds 7921da177e4SLinus Torvalds ohci_dump (ohci, 1); 7931da177e4SLinus Torvalds ohci_usb_reset (ohci); 7941da177e4SLinus Torvalds } 7951da177e4SLinus Torvalds 796583ceadaSAlan Stern if (ints & OHCI_INTR_RHSC) { 797583ceadaSAlan Stern ohci_vdbg(ohci, "rhsc\n"); 798583ceadaSAlan Stern ohci->next_statechange = jiffies + STATECHANGE_DELAY; 799583ceadaSAlan Stern ohci_writel(ohci, OHCI_INTR_RD | OHCI_INTR_RHSC, 800583ceadaSAlan Stern ®s->intrstatus); 801052ac01aSAlan Stern 802052ac01aSAlan Stern /* NOTE: Vendors didn't always make the same implementation 803052ac01aSAlan Stern * choices for RHSC. Many followed the spec; RHSC triggers 804052ac01aSAlan Stern * on an edge, like setting and maybe clearing a port status 805052ac01aSAlan Stern * change bit. With others it's level-triggered, active 806052ac01aSAlan Stern * until khubd clears all the port status change bits. We'll 807052ac01aSAlan Stern * always disable it here and rely on polling until khubd 808052ac01aSAlan Stern * re-enables it. 809052ac01aSAlan Stern */ 810052ac01aSAlan Stern ohci_writel(ohci, OHCI_INTR_RHSC, ®s->intrdisable); 811583ceadaSAlan Stern usb_hcd_poll_rh_status(hcd); 812583ceadaSAlan Stern } 813583ceadaSAlan Stern 814583ceadaSAlan Stern /* For connect and disconnect events, we expect the controller 815583ceadaSAlan Stern * to turn on RHSC along with RD. But for remote wakeup events 816583ceadaSAlan Stern * this might not happen. 817583ceadaSAlan Stern */ 818583ceadaSAlan Stern else if (ints & OHCI_INTR_RD) { 8191da177e4SLinus Torvalds ohci_vdbg(ohci, "resume detect\n"); 820e0fd3cbcSDavid Brownell ohci_writel(ohci, OHCI_INTR_RD, ®s->intrstatus); 8218d1a243bSAlan Stern hcd->poll_rh = 1; 8228d1a243bSAlan Stern if (ohci->autostop) { 8238d1a243bSAlan Stern spin_lock (&ohci->lock); 8248d1a243bSAlan Stern ohci_rh_resume (ohci); 8258d1a243bSAlan Stern spin_unlock (&ohci->lock); 8268d1a243bSAlan Stern } else 827f197b2c5SDavid Brownell usb_hcd_resume_root_hub(hcd); 8281da177e4SLinus Torvalds } 8291da177e4SLinus Torvalds 8301da177e4SLinus Torvalds if (ints & OHCI_INTR_WDH) { 8311da177e4SLinus Torvalds spin_lock (&ohci->lock); 8327d12e780SDavid Howells dl_done_list (ohci); 8331da177e4SLinus Torvalds spin_unlock (&ohci->lock); 8341da177e4SLinus Torvalds } 8351da177e4SLinus Torvalds 83689a0fd18SMike Nuss if (quirk_zfmicro(ohci) && (ints & OHCI_INTR_SF)) { 83789a0fd18SMike Nuss spin_lock(&ohci->lock); 83889a0fd18SMike Nuss if (ohci->ed_to_check) { 83989a0fd18SMike Nuss struct ed *ed = ohci->ed_to_check; 84089a0fd18SMike Nuss 84189a0fd18SMike Nuss if (check_ed(ohci, ed)) { 84289a0fd18SMike Nuss /* HC thinks the TD list is empty; HCD knows 84389a0fd18SMike Nuss * at least one TD is outstanding 84489a0fd18SMike Nuss */ 84589a0fd18SMike Nuss if (--ohci->zf_delay == 0) { 84689a0fd18SMike Nuss struct td *td = list_entry( 84789a0fd18SMike Nuss ed->td_list.next, 84889a0fd18SMike Nuss struct td, td_list); 84989a0fd18SMike Nuss ohci_warn(ohci, 85089a0fd18SMike Nuss "Reclaiming orphan TD %p\n", 85189a0fd18SMike Nuss td); 85289a0fd18SMike Nuss takeback_td(ohci, td); 85389a0fd18SMike Nuss ohci->ed_to_check = NULL; 85489a0fd18SMike Nuss } 85589a0fd18SMike Nuss } else 85689a0fd18SMike Nuss ohci->ed_to_check = NULL; 85789a0fd18SMike Nuss } 85889a0fd18SMike Nuss spin_unlock(&ohci->lock); 85989a0fd18SMike Nuss } 86089a0fd18SMike Nuss 8611da177e4SLinus Torvalds /* could track INTR_SO to reduce available PCI/... bandwidth */ 8621da177e4SLinus Torvalds 8631da177e4SLinus Torvalds /* handle any pending URB/ED unlinks, leaving INTR_SF enabled 8641da177e4SLinus Torvalds * when there's still unlinking to be done (next frame). 8651da177e4SLinus Torvalds */ 8661da177e4SLinus Torvalds spin_lock (&ohci->lock); 8671da177e4SLinus Torvalds if (ohci->ed_rm_list) 8687d12e780SDavid Howells finish_unlinks (ohci, ohci_frame_no(ohci)); 86989a0fd18SMike Nuss if ((ints & OHCI_INTR_SF) != 0 87089a0fd18SMike Nuss && !ohci->ed_rm_list 87189a0fd18SMike Nuss && !ohci->ed_to_check 8721da177e4SLinus Torvalds && HC_IS_RUNNING(hcd->state)) 8731da177e4SLinus Torvalds ohci_writel (ohci, OHCI_INTR_SF, ®s->intrdisable); 8741da177e4SLinus Torvalds spin_unlock (&ohci->lock); 8751da177e4SLinus Torvalds 8761da177e4SLinus Torvalds if (HC_IS_RUNNING(hcd->state)) { 8771da177e4SLinus Torvalds ohci_writel (ohci, ints, ®s->intrstatus); 8781da177e4SLinus Torvalds ohci_writel (ohci, OHCI_INTR_MIE, ®s->intrenable); 8791da177e4SLinus Torvalds // flush those writes 8801da177e4SLinus Torvalds (void) ohci_readl (ohci, &ohci->regs->control); 8811da177e4SLinus Torvalds } 8821da177e4SLinus Torvalds 8831da177e4SLinus Torvalds return IRQ_HANDLED; 8841da177e4SLinus Torvalds } 8851da177e4SLinus Torvalds 8861da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/ 8871da177e4SLinus Torvalds 8881da177e4SLinus Torvalds static void ohci_stop (struct usb_hcd *hcd) 8891da177e4SLinus Torvalds { 8901da177e4SLinus Torvalds struct ohci_hcd *ohci = hcd_to_ohci (hcd); 8911da177e4SLinus Torvalds 8921da177e4SLinus Torvalds ohci_dump (ohci, 1); 8931da177e4SLinus Torvalds 8941da177e4SLinus Torvalds flush_scheduled_work(); 8951da177e4SLinus Torvalds 8961da177e4SLinus Torvalds ohci_usb_reset (ohci); 8971da177e4SLinus Torvalds ohci_writel (ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable); 89871795c1dSPete Zaitcev free_irq(hcd->irq, hcd); 89971795c1dSPete Zaitcev hcd->irq = -1; 9001da177e4SLinus Torvalds 90189a0fd18SMike Nuss if (quirk_zfmicro(ohci)) 90289a0fd18SMike Nuss del_timer(&ohci->unlink_watchdog); 903ab1666c1SLibin Yang if (quirk_amdiso(ohci)) 904ab1666c1SLibin Yang amd_iso_dev_put(); 90589a0fd18SMike Nuss 9061da177e4SLinus Torvalds remove_debug_files (ohci); 9071da177e4SLinus Torvalds ohci_mem_cleanup (ohci); 9081da177e4SLinus Torvalds if (ohci->hcca) { 9091da177e4SLinus Torvalds dma_free_coherent (hcd->self.controller, 9101da177e4SLinus Torvalds sizeof *ohci->hcca, 9111da177e4SLinus Torvalds ohci->hcca, ohci->hcca_dma); 9121da177e4SLinus Torvalds ohci->hcca = NULL; 9131da177e4SLinus Torvalds ohci->hcca_dma = 0; 9141da177e4SLinus Torvalds } 9151da177e4SLinus Torvalds } 9161da177e4SLinus Torvalds 9171da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/ 9181da177e4SLinus Torvalds 919da6fb570SDavid Brownell #if defined(CONFIG_PM) || defined(CONFIG_PCI) 920da6fb570SDavid Brownell 9211da177e4SLinus Torvalds /* must not be called from interrupt context */ 9221da177e4SLinus Torvalds static int ohci_restart (struct ohci_hcd *ohci) 9231da177e4SLinus Torvalds { 9241da177e4SLinus Torvalds int temp; 9251da177e4SLinus Torvalds int i; 9261da177e4SLinus Torvalds struct urb_priv *priv; 9271da177e4SLinus Torvalds 9281da177e4SLinus Torvalds spin_lock_irq(&ohci->lock); 9291da177e4SLinus Torvalds disable (ohci); 930d576bb9fSMichael Hanselmann 931d576bb9fSMichael Hanselmann /* Recycle any "live" eds/tds (and urbs). */ 9321da177e4SLinus Torvalds if (!list_empty (&ohci->pending)) 9331da177e4SLinus Torvalds ohci_dbg(ohci, "abort schedule...\n"); 9341da177e4SLinus Torvalds list_for_each_entry (priv, &ohci->pending, pending) { 9351da177e4SLinus Torvalds struct urb *urb = priv->td[0]->urb; 9361da177e4SLinus Torvalds struct ed *ed = priv->ed; 9371da177e4SLinus Torvalds 9381da177e4SLinus Torvalds switch (ed->state) { 9391da177e4SLinus Torvalds case ED_OPER: 9401da177e4SLinus Torvalds ed->state = ED_UNLINK; 9411da177e4SLinus Torvalds ed->hwINFO |= cpu_to_hc32(ohci, ED_DEQUEUE); 9421da177e4SLinus Torvalds ed_deschedule (ohci, ed); 9431da177e4SLinus Torvalds 9441da177e4SLinus Torvalds ed->ed_next = ohci->ed_rm_list; 9451da177e4SLinus Torvalds ed->ed_prev = NULL; 9461da177e4SLinus Torvalds ohci->ed_rm_list = ed; 9471da177e4SLinus Torvalds /* FALLTHROUGH */ 9481da177e4SLinus Torvalds case ED_UNLINK: 9491da177e4SLinus Torvalds break; 9501da177e4SLinus Torvalds default: 9511da177e4SLinus Torvalds ohci_dbg(ohci, "bogus ed %p state %d\n", 9521da177e4SLinus Torvalds ed, ed->state); 9531da177e4SLinus Torvalds } 9541da177e4SLinus Torvalds 95555d84968SAlan Stern if (!urb->unlinked) 95655d84968SAlan Stern urb->unlinked = -ESHUTDOWN; 9571da177e4SLinus Torvalds } 9587d12e780SDavid Howells finish_unlinks (ohci, 0); 9591da177e4SLinus Torvalds spin_unlock_irq(&ohci->lock); 9601da177e4SLinus Torvalds 9611da177e4SLinus Torvalds /* paranoia, in case that didn't work: */ 9621da177e4SLinus Torvalds 9631da177e4SLinus Torvalds /* empty the interrupt branches */ 9641da177e4SLinus Torvalds for (i = 0; i < NUM_INTS; i++) ohci->load [i] = 0; 9651da177e4SLinus Torvalds for (i = 0; i < NUM_INTS; i++) ohci->hcca->int_table [i] = 0; 9661da177e4SLinus Torvalds 9671da177e4SLinus Torvalds /* no EDs to remove */ 9681da177e4SLinus Torvalds ohci->ed_rm_list = NULL; 9691da177e4SLinus Torvalds 9701da177e4SLinus Torvalds /* empty control and bulk lists */ 9711da177e4SLinus Torvalds ohci->ed_controltail = NULL; 9721da177e4SLinus Torvalds ohci->ed_bulktail = NULL; 9731da177e4SLinus Torvalds 9741da177e4SLinus Torvalds if ((temp = ohci_run (ohci)) < 0) { 9751da177e4SLinus Torvalds ohci_err (ohci, "can't restart, %d\n", temp); 9761da177e4SLinus Torvalds return temp; 9771da177e4SLinus Torvalds } 978383975d7SAlan Stern ohci_dbg(ohci, "restart complete\n"); 9791da177e4SLinus Torvalds return 0; 9801da177e4SLinus Torvalds } 981d576bb9fSMichael Hanselmann 982da6fb570SDavid Brownell #endif 983da6fb570SDavid Brownell 984d576bb9fSMichael Hanselmann /*-------------------------------------------------------------------------*/ 985d576bb9fSMichael Hanselmann 9861da177e4SLinus Torvalds MODULE_AUTHOR (DRIVER_AUTHOR); 9872b70f073SAlan Stern MODULE_DESCRIPTION(DRIVER_DESC); 9881da177e4SLinus Torvalds MODULE_LICENSE ("GPL"); 9891da177e4SLinus Torvalds 9901da177e4SLinus Torvalds #ifdef CONFIG_PCI 9911da177e4SLinus Torvalds #include "ohci-pci.c" 9925e16fabeSSylvain Munaut #define PCI_DRIVER ohci_pci_driver 9931da177e4SLinus Torvalds #endif 9941da177e4SLinus Torvalds 9956381fad7SEric Miao #if defined(CONFIG_ARCH_SA1100) && defined(CONFIG_SA1111) 9961da177e4SLinus Torvalds #include "ohci-sa1111.c" 9975e16fabeSSylvain Munaut #define SA1111_DRIVER ohci_hcd_sa1111_driver 9981da177e4SLinus Torvalds #endif 9991da177e4SLinus Torvalds 1000*3ba5f38fSBen Dooks #if defined(CONFIG_ARCH_S3C2410) || defined(CONFIG_ARCH_S3C64XX) 10013eb0c5f4SBen Dooks #include "ohci-s3c2410.c" 10025e16fabeSSylvain Munaut #define PLATFORM_DRIVER ohci_hcd_s3c2410_driver 10033eb0c5f4SBen Dooks #endif 10043eb0c5f4SBen Dooks 10051da177e4SLinus Torvalds #ifdef CONFIG_ARCH_OMAP 10061da177e4SLinus Torvalds #include "ohci-omap.c" 10075e16fabeSSylvain Munaut #define PLATFORM_DRIVER ohci_hcd_omap_driver 10081da177e4SLinus Torvalds #endif 10091da177e4SLinus Torvalds 10101da177e4SLinus Torvalds #ifdef CONFIG_ARCH_LH7A404 10111da177e4SLinus Torvalds #include "ohci-lh7a404.c" 10125e16fabeSSylvain Munaut #define PLATFORM_DRIVER ohci_hcd_lh7a404_driver 10131da177e4SLinus Torvalds #endif 10141da177e4SLinus Torvalds 1015e77ec189Seric miao #if defined(CONFIG_PXA27x) || defined(CONFIG_PXA3xx) 10161da177e4SLinus Torvalds #include "ohci-pxa27x.c" 10175e16fabeSSylvain Munaut #define PLATFORM_DRIVER ohci_hcd_pxa27x_driver 10181da177e4SLinus Torvalds #endif 10191da177e4SLinus Torvalds 1020a5b7474aSLennert Buytenhek #ifdef CONFIG_ARCH_EP93XX 1021a5b7474aSLennert Buytenhek #include "ohci-ep93xx.c" 10225e16fabeSSylvain Munaut #define PLATFORM_DRIVER ohci_hcd_ep93xx_driver 1023a5b7474aSLennert Buytenhek #endif 1024a5b7474aSLennert Buytenhek 10251da177e4SLinus Torvalds #ifdef CONFIG_SOC_AU1X00 10261da177e4SLinus Torvalds #include "ohci-au1xxx.c" 10275e16fabeSSylvain Munaut #define PLATFORM_DRIVER ohci_hcd_au1xxx_driver 10281da177e4SLinus Torvalds #endif 10291da177e4SLinus Torvalds 10305151d040SVitaly Wool #ifdef CONFIG_PNX8550 10315151d040SVitaly Wool #include "ohci-pnx8550.c" 10325e16fabeSSylvain Munaut #define PLATFORM_DRIVER ohci_hcd_pnx8550_driver 10335151d040SVitaly Wool #endif 10345151d040SVitaly Wool 10351da177e4SLinus Torvalds #ifdef CONFIG_USB_OHCI_HCD_PPC_SOC 10361da177e4SLinus Torvalds #include "ohci-ppc-soc.c" 10375e16fabeSSylvain Munaut #define PLATFORM_DRIVER ohci_hcd_ppc_soc_driver 10381da177e4SLinus Torvalds #endif 10391da177e4SLinus Torvalds 104058a0cd78SAndrew Victor #ifdef CONFIG_ARCH_AT91 104139a269c0SAndrew Victor #include "ohci-at91.c" 10425e16fabeSSylvain Munaut #define PLATFORM_DRIVER ohci_hcd_at91_driver 104339a269c0SAndrew Victor #endif 104439a269c0SAndrew Victor 104560bbfc84SVitaly Wool #ifdef CONFIG_ARCH_PNX4008 104660bbfc84SVitaly Wool #include "ohci-pnx4008.c" 10475e16fabeSSylvain Munaut #define PLATFORM_DRIVER usb_hcd_pnx4008_driver 104860bbfc84SVitaly Wool #endif 104960bbfc84SVitaly Wool 1050828d55c5SYoshihiro Shimoda #if defined(CONFIG_CPU_SUBTYPE_SH7720) || \ 1051828d55c5SYoshihiro Shimoda defined(CONFIG_CPU_SUBTYPE_SH7721) || \ 1052828d55c5SYoshihiro Shimoda defined(CONFIG_CPU_SUBTYPE_SH7763) 1053828d55c5SYoshihiro Shimoda #include "ohci-sh.c" 1054828d55c5SYoshihiro Shimoda #define PLATFORM_DRIVER ohci_hcd_sh_driver 1055828d55c5SYoshihiro Shimoda #endif 1056828d55c5SYoshihiro Shimoda 10575e16fabeSSylvain Munaut 1058495a678fSSylvain Munaut #ifdef CONFIG_USB_OHCI_HCD_PPC_OF 1059495a678fSSylvain Munaut #include "ohci-ppc-of.c" 1060495a678fSSylvain Munaut #define OF_PLATFORM_DRIVER ohci_hcd_ppc_of_driver 1061495a678fSSylvain Munaut #endif 1062495a678fSSylvain Munaut 10636a6c957eSGeoff Levand #ifdef CONFIG_PPC_PS3 10646a6c957eSGeoff Levand #include "ohci-ps3.c" 10657a4eb7fdSGeoff Levand #define PS3_SYSTEM_BUS_DRIVER ps3_ohci_driver 10666a6c957eSGeoff Levand #endif 10676a6c957eSGeoff Levand 1068c604e851SMichael Buesch #ifdef CONFIG_USB_OHCI_HCD_SSB 1069c604e851SMichael Buesch #include "ohci-ssb.c" 1070c604e851SMichael Buesch #define SSB_OHCI_DRIVER ssb_ohci_driver 1071c604e851SMichael Buesch #endif 1072c604e851SMichael Buesch 1073f54aab6eSMagnus Damm #ifdef CONFIG_MFD_SM501 1074f54aab6eSMagnus Damm #include "ohci-sm501.c" 10753ee38d8bSBen Dooks #define SM501_OHCI_DRIVER ohci_hcd_sm501_driver 1076f54aab6eSMagnus Damm #endif 1077f54aab6eSMagnus Damm 107878c73414SDmitry Baryshkov #ifdef CONFIG_MFD_TC6393XB 107978c73414SDmitry Baryshkov #include "ohci-tmio.c" 108078c73414SDmitry Baryshkov #define TMIO_OHCI_DRIVER ohci_hcd_tmio_driver 108178c73414SDmitry Baryshkov #endif 108278c73414SDmitry Baryshkov 10835e16fabeSSylvain Munaut #if !defined(PCI_DRIVER) && \ 10845e16fabeSSylvain Munaut !defined(PLATFORM_DRIVER) && \ 1085495a678fSSylvain Munaut !defined(OF_PLATFORM_DRIVER) && \ 10866a6c957eSGeoff Levand !defined(SA1111_DRIVER) && \ 1087c604e851SMichael Buesch !defined(PS3_SYSTEM_BUS_DRIVER) && \ 10883ee38d8bSBen Dooks !defined(SM501_OHCI_DRIVER) && \ 108978c73414SDmitry Baryshkov !defined(TMIO_OHCI_DRIVER) && \ 1090c604e851SMichael Buesch !defined(SSB_OHCI_DRIVER) 10911da177e4SLinus Torvalds #error "missing bus glue for ohci-hcd" 10921da177e4SLinus Torvalds #endif 10935e16fabeSSylvain Munaut 10945e16fabeSSylvain Munaut static int __init ohci_hcd_mod_init(void) 10955e16fabeSSylvain Munaut { 10965e16fabeSSylvain Munaut int retval = 0; 10975e16fabeSSylvain Munaut 10985e16fabeSSylvain Munaut if (usb_disabled()) 10995e16fabeSSylvain Munaut return -ENODEV; 11005e16fabeSSylvain Munaut 11012b70f073SAlan Stern printk(KERN_INFO "%s: " DRIVER_DESC "\n", hcd_name); 11025e16fabeSSylvain Munaut pr_debug ("%s: block sizes: ed %Zd td %Zd\n", hcd_name, 11035e16fabeSSylvain Munaut sizeof (struct ed), sizeof (struct td)); 11049beeee65SAlan Stern set_bit(USB_OHCI_LOADED, &usb_hcds_loaded); 11055e16fabeSSylvain Munaut 1106684c19e0STony Jones #ifdef DEBUG 1107684c19e0STony Jones ohci_debug_root = debugfs_create_dir("ohci", NULL); 1108684c19e0STony Jones if (!ohci_debug_root) { 1109684c19e0STony Jones retval = -ENOENT; 1110684c19e0STony Jones goto error_debug; 1111684c19e0STony Jones } 1112684c19e0STony Jones #endif 1113684c19e0STony Jones 11146a6c957eSGeoff Levand #ifdef PS3_SYSTEM_BUS_DRIVER 11157a4eb7fdSGeoff Levand retval = ps3_ohci_driver_register(&PS3_SYSTEM_BUS_DRIVER); 11166a6c957eSGeoff Levand if (retval < 0) 11176a6c957eSGeoff Levand goto error_ps3; 11186a6c957eSGeoff Levand #endif 11196a6c957eSGeoff Levand 11205e16fabeSSylvain Munaut #ifdef PLATFORM_DRIVER 11215e16fabeSSylvain Munaut retval = platform_driver_register(&PLATFORM_DRIVER); 11225e16fabeSSylvain Munaut if (retval < 0) 1123de44743bSBenjamin Herrenschmidt goto error_platform; 11245e16fabeSSylvain Munaut #endif 11255e16fabeSSylvain Munaut 1126495a678fSSylvain Munaut #ifdef OF_PLATFORM_DRIVER 1127495a678fSSylvain Munaut retval = of_register_platform_driver(&OF_PLATFORM_DRIVER); 1128495a678fSSylvain Munaut if (retval < 0) 1129de44743bSBenjamin Herrenschmidt goto error_of_platform; 1130495a678fSSylvain Munaut #endif 1131495a678fSSylvain Munaut 11325e16fabeSSylvain Munaut #ifdef SA1111_DRIVER 11335e16fabeSSylvain Munaut retval = sa1111_driver_register(&SA1111_DRIVER); 11345e16fabeSSylvain Munaut if (retval < 0) 1135de44743bSBenjamin Herrenschmidt goto error_sa1111; 11365e16fabeSSylvain Munaut #endif 11375e16fabeSSylvain Munaut 11385e16fabeSSylvain Munaut #ifdef PCI_DRIVER 11395e16fabeSSylvain Munaut retval = pci_register_driver(&PCI_DRIVER); 11405e16fabeSSylvain Munaut if (retval < 0) 1141de44743bSBenjamin Herrenschmidt goto error_pci; 11425e16fabeSSylvain Munaut #endif 11435e16fabeSSylvain Munaut 1144c604e851SMichael Buesch #ifdef SSB_OHCI_DRIVER 1145c604e851SMichael Buesch retval = ssb_driver_register(&SSB_OHCI_DRIVER); 1146c604e851SMichael Buesch if (retval) 1147c604e851SMichael Buesch goto error_ssb; 1148c604e851SMichael Buesch #endif 1149c604e851SMichael Buesch 11503ee38d8bSBen Dooks #ifdef SM501_OHCI_DRIVER 11513ee38d8bSBen Dooks retval = platform_driver_register(&SM501_OHCI_DRIVER); 11523ee38d8bSBen Dooks if (retval < 0) 11533ee38d8bSBen Dooks goto error_sm501; 11543ee38d8bSBen Dooks #endif 11553ee38d8bSBen Dooks 115678c73414SDmitry Baryshkov #ifdef TMIO_OHCI_DRIVER 115778c73414SDmitry Baryshkov retval = platform_driver_register(&TMIO_OHCI_DRIVER); 115878c73414SDmitry Baryshkov if (retval < 0) 115978c73414SDmitry Baryshkov goto error_tmio; 116078c73414SDmitry Baryshkov #endif 116178c73414SDmitry Baryshkov 11625e16fabeSSylvain Munaut return retval; 11635e16fabeSSylvain Munaut 11645e16fabeSSylvain Munaut /* Error path */ 116578c73414SDmitry Baryshkov #ifdef TMIO_OHCI_DRIVER 116678c73414SDmitry Baryshkov platform_driver_unregister(&TMIO_OHCI_DRIVER); 116778c73414SDmitry Baryshkov error_tmio: 116878c73414SDmitry Baryshkov #endif 11693ee38d8bSBen Dooks #ifdef SM501_OHCI_DRIVER 117078c73414SDmitry Baryshkov platform_driver_unregister(&SM501_OHCI_DRIVER); 11713ee38d8bSBen Dooks error_sm501: 11723ee38d8bSBen Dooks #endif 1173c604e851SMichael Buesch #ifdef SSB_OHCI_DRIVER 117478c73414SDmitry Baryshkov ssb_driver_unregister(&SSB_OHCI_DRIVER); 1175c604e851SMichael Buesch error_ssb: 1176c604e851SMichael Buesch #endif 1177de44743bSBenjamin Herrenschmidt #ifdef PCI_DRIVER 1178c604e851SMichael Buesch pci_unregister_driver(&PCI_DRIVER); 1179de44743bSBenjamin Herrenschmidt error_pci: 1180495a678fSSylvain Munaut #endif 11815e16fabeSSylvain Munaut #ifdef SA1111_DRIVER 11825e16fabeSSylvain Munaut sa1111_driver_unregister(&SA1111_DRIVER); 1183de44743bSBenjamin Herrenschmidt error_sa1111: 1184de44743bSBenjamin Herrenschmidt #endif 1185de44743bSBenjamin Herrenschmidt #ifdef OF_PLATFORM_DRIVER 1186de44743bSBenjamin Herrenschmidt of_unregister_platform_driver(&OF_PLATFORM_DRIVER); 1187de44743bSBenjamin Herrenschmidt error_of_platform: 1188de44743bSBenjamin Herrenschmidt #endif 1189de44743bSBenjamin Herrenschmidt #ifdef PLATFORM_DRIVER 1190de44743bSBenjamin Herrenschmidt platform_driver_unregister(&PLATFORM_DRIVER); 1191de44743bSBenjamin Herrenschmidt error_platform: 11925e16fabeSSylvain Munaut #endif 11936a6c957eSGeoff Levand #ifdef PS3_SYSTEM_BUS_DRIVER 11947a4eb7fdSGeoff Levand ps3_ohci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER); 11956a6c957eSGeoff Levand error_ps3: 11966a6c957eSGeoff Levand #endif 1197684c19e0STony Jones #ifdef DEBUG 1198684c19e0STony Jones debugfs_remove(ohci_debug_root); 1199684c19e0STony Jones ohci_debug_root = NULL; 1200684c19e0STony Jones error_debug: 1201684c19e0STony Jones #endif 1202684c19e0STony Jones 12039beeee65SAlan Stern clear_bit(USB_OHCI_LOADED, &usb_hcds_loaded); 12045e16fabeSSylvain Munaut return retval; 12055e16fabeSSylvain Munaut } 12065e16fabeSSylvain Munaut module_init(ohci_hcd_mod_init); 12075e16fabeSSylvain Munaut 12085e16fabeSSylvain Munaut static void __exit ohci_hcd_mod_exit(void) 12095e16fabeSSylvain Munaut { 121078c73414SDmitry Baryshkov #ifdef TMIO_OHCI_DRIVER 121178c73414SDmitry Baryshkov platform_driver_unregister(&TMIO_OHCI_DRIVER); 121278c73414SDmitry Baryshkov #endif 12133ee38d8bSBen Dooks #ifdef SM501_OHCI_DRIVER 12143ee38d8bSBen Dooks platform_driver_unregister(&SM501_OHCI_DRIVER); 12153ee38d8bSBen Dooks #endif 1216c604e851SMichael Buesch #ifdef SSB_OHCI_DRIVER 1217c604e851SMichael Buesch ssb_driver_unregister(&SSB_OHCI_DRIVER); 1218c604e851SMichael Buesch #endif 12195e16fabeSSylvain Munaut #ifdef PCI_DRIVER 12205e16fabeSSylvain Munaut pci_unregister_driver(&PCI_DRIVER); 12215e16fabeSSylvain Munaut #endif 12225e16fabeSSylvain Munaut #ifdef SA1111_DRIVER 12235e16fabeSSylvain Munaut sa1111_driver_unregister(&SA1111_DRIVER); 12245e16fabeSSylvain Munaut #endif 1225495a678fSSylvain Munaut #ifdef OF_PLATFORM_DRIVER 1226495a678fSSylvain Munaut of_unregister_platform_driver(&OF_PLATFORM_DRIVER); 1227495a678fSSylvain Munaut #endif 12285e16fabeSSylvain Munaut #ifdef PLATFORM_DRIVER 12295e16fabeSSylvain Munaut platform_driver_unregister(&PLATFORM_DRIVER); 12305e16fabeSSylvain Munaut #endif 12316a6c957eSGeoff Levand #ifdef PS3_SYSTEM_BUS_DRIVER 12327a4eb7fdSGeoff Levand ps3_ohci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER); 12336a6c957eSGeoff Levand #endif 1234684c19e0STony Jones #ifdef DEBUG 1235684c19e0STony Jones debugfs_remove(ohci_debug_root); 1236684c19e0STony Jones #endif 12379beeee65SAlan Stern clear_bit(USB_OHCI_LOADED, &usb_hcds_loaded); 12385e16fabeSSylvain Munaut } 12395e16fabeSSylvain Munaut module_exit(ohci_hcd_mod_exit); 12405e16fabeSSylvain Munaut 1241