xref: /linux/drivers/usb/host/ohci-hcd.c (revision 828d55c58cba6b652fd30e00c3d940cb7c523e3c)
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 
49d413984aSDavid Brownell #define DRIVER_VERSION "2006 August 04"
501da177e4SLinus Torvalds #define DRIVER_AUTHOR "Roman Weissgaerber, David Brownell"
511da177e4SLinus Torvalds #define DRIVER_DESC "USB 1.1 'Open' Host Controller (OHCI) Driver"
521da177e4SLinus Torvalds 
531da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/
541da177e4SLinus Torvalds 
558de98402SBenjamin Herrenschmidt #undef OHCI_VERBOSE_DEBUG	/* not always helpful */
561da177e4SLinus Torvalds 
571da177e4SLinus Torvalds /* For initializing controller (mask in an HCFS mode too) */
581da177e4SLinus Torvalds #define	OHCI_CONTROL_INIT	OHCI_CTRL_CBSR
591da177e4SLinus Torvalds #define	OHCI_INTR_INIT \
60d413984aSDavid Brownell 		(OHCI_INTR_MIE | OHCI_INTR_RHSC | OHCI_INTR_UE \
61d413984aSDavid Brownell 		| OHCI_INTR_RD | OHCI_INTR_WDH)
621da177e4SLinus Torvalds 
631da177e4SLinus Torvalds #ifdef __hppa__
641da177e4SLinus Torvalds /* On PA-RISC, PDC can leave IR set incorrectly; ignore it there. */
651da177e4SLinus Torvalds #define	IR_DISABLE
661da177e4SLinus Torvalds #endif
671da177e4SLinus Torvalds 
681da177e4SLinus Torvalds #ifdef CONFIG_ARCH_OMAP
691da177e4SLinus Torvalds /* OMAP doesn't support IR (no SMM; not needed) */
701da177e4SLinus Torvalds #define	IR_DISABLE
711da177e4SLinus Torvalds #endif
721da177e4SLinus Torvalds 
731da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/
741da177e4SLinus Torvalds 
751da177e4SLinus Torvalds static const char	hcd_name [] = "ohci_hcd";
761da177e4SLinus Torvalds 
77d413984aSDavid Brownell #define	STATECHANGE_DELAY	msecs_to_jiffies(300)
78d413984aSDavid Brownell 
791da177e4SLinus Torvalds #include "ohci.h"
801da177e4SLinus Torvalds 
811da177e4SLinus Torvalds static void ohci_dump (struct ohci_hcd *ohci, int verbose);
821da177e4SLinus Torvalds static int ohci_init (struct ohci_hcd *ohci);
831da177e4SLinus Torvalds static void ohci_stop (struct usb_hcd *hcd);
84da6fb570SDavid Brownell 
85da6fb570SDavid Brownell #if defined(CONFIG_PM) || defined(CONFIG_PCI)
86d576bb9fSMichael Hanselmann static int ohci_restart (struct ohci_hcd *ohci);
87da6fb570SDavid Brownell #endif
881da177e4SLinus Torvalds 
891da177e4SLinus Torvalds #include "ohci-hub.c"
901da177e4SLinus Torvalds #include "ohci-dbg.c"
911da177e4SLinus Torvalds #include "ohci-mem.c"
921da177e4SLinus Torvalds #include "ohci-q.c"
931da177e4SLinus Torvalds 
941da177e4SLinus Torvalds 
951da177e4SLinus Torvalds /*
961da177e4SLinus Torvalds  * On architectures with edge-triggered interrupts we must never return
971da177e4SLinus Torvalds  * IRQ_NONE.
981da177e4SLinus Torvalds  */
991da177e4SLinus Torvalds #if defined(CONFIG_SA1111)  /* ... or other edge-triggered systems */
1001da177e4SLinus Torvalds #define IRQ_NOTMINE	IRQ_HANDLED
1011da177e4SLinus Torvalds #else
1021da177e4SLinus Torvalds #define IRQ_NOTMINE	IRQ_NONE
1031da177e4SLinus Torvalds #endif
1041da177e4SLinus Torvalds 
1051da177e4SLinus Torvalds 
1061da177e4SLinus Torvalds /* Some boards misreport power switching/overcurrent */
1071da177e4SLinus Torvalds static int distrust_firmware = 1;
1081da177e4SLinus Torvalds module_param (distrust_firmware, bool, 0);
1091da177e4SLinus Torvalds MODULE_PARM_DESC (distrust_firmware,
1101da177e4SLinus Torvalds 	"true to distrust firmware power/overcurrent setup");
1111da177e4SLinus Torvalds 
1121da177e4SLinus Torvalds /* Some boards leave IR set wrongly, since they fail BIOS/SMM handshakes */
1131da177e4SLinus Torvalds static int no_handshake = 0;
1141da177e4SLinus Torvalds module_param (no_handshake, bool, 0);
1151da177e4SLinus Torvalds MODULE_PARM_DESC (no_handshake, "true (not default) disables BIOS handshake");
1161da177e4SLinus Torvalds 
1171da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/
1181da177e4SLinus Torvalds 
1191da177e4SLinus Torvalds /*
1201da177e4SLinus Torvalds  * queue up an urb for anything except the root hub
1211da177e4SLinus Torvalds  */
1221da177e4SLinus Torvalds static int ohci_urb_enqueue (
1231da177e4SLinus Torvalds 	struct usb_hcd	*hcd,
1241da177e4SLinus Torvalds 	struct urb	*urb,
12555016f10SAl Viro 	gfp_t		mem_flags
1261da177e4SLinus Torvalds ) {
1271da177e4SLinus Torvalds 	struct ohci_hcd	*ohci = hcd_to_ohci (hcd);
1281da177e4SLinus Torvalds 	struct ed	*ed;
1291da177e4SLinus Torvalds 	urb_priv_t	*urb_priv;
1301da177e4SLinus Torvalds 	unsigned int	pipe = urb->pipe;
1311da177e4SLinus Torvalds 	int		i, size = 0;
1321da177e4SLinus Torvalds 	unsigned long	flags;
1331da177e4SLinus Torvalds 	int		retval = 0;
1341da177e4SLinus Torvalds 
1351da177e4SLinus Torvalds #ifdef OHCI_VERBOSE_DEBUG
13655d84968SAlan Stern 	urb_print(urb, "SUB", usb_pipein(pipe), -EINPROGRESS);
1371da177e4SLinus Torvalds #endif
1381da177e4SLinus Torvalds 
1391da177e4SLinus Torvalds 	/* every endpoint has a ed, locate and maybe (re)initialize it */
140e9df41c5SAlan Stern 	if (! (ed = ed_get (ohci, urb->ep, urb->dev, pipe, urb->interval)))
1411da177e4SLinus Torvalds 		return -ENOMEM;
1421da177e4SLinus Torvalds 
1431da177e4SLinus Torvalds 	/* for the private part of the URB we need the number of TDs (size) */
1441da177e4SLinus Torvalds 	switch (ed->type) {
1451da177e4SLinus Torvalds 		case PIPE_CONTROL:
1461da177e4SLinus Torvalds 			/* td_submit_urb() doesn't yet handle these */
1471da177e4SLinus Torvalds 			if (urb->transfer_buffer_length > 4096)
1481da177e4SLinus Torvalds 				return -EMSGSIZE;
1491da177e4SLinus Torvalds 
1501da177e4SLinus Torvalds 			/* 1 TD for setup, 1 for ACK, plus ... */
1511da177e4SLinus Torvalds 			size = 2;
1521da177e4SLinus Torvalds 			/* FALLTHROUGH */
1531da177e4SLinus Torvalds 		// case PIPE_INTERRUPT:
1541da177e4SLinus Torvalds 		// case PIPE_BULK:
1551da177e4SLinus Torvalds 		default:
1561da177e4SLinus Torvalds 			/* one TD for every 4096 Bytes (can be upto 8K) */
1571da177e4SLinus Torvalds 			size += urb->transfer_buffer_length / 4096;
1581da177e4SLinus Torvalds 			/* ... and for any remaining bytes ... */
1591da177e4SLinus Torvalds 			if ((urb->transfer_buffer_length % 4096) != 0)
1601da177e4SLinus Torvalds 				size++;
1611da177e4SLinus Torvalds 			/* ... and maybe a zero length packet to wrap it up */
1621da177e4SLinus Torvalds 			if (size == 0)
1631da177e4SLinus Torvalds 				size++;
1641da177e4SLinus Torvalds 			else if ((urb->transfer_flags & URB_ZERO_PACKET) != 0
1651da177e4SLinus Torvalds 				&& (urb->transfer_buffer_length
1661da177e4SLinus Torvalds 					% usb_maxpacket (urb->dev, pipe,
1671da177e4SLinus Torvalds 						usb_pipeout (pipe))) == 0)
1681da177e4SLinus Torvalds 				size++;
1691da177e4SLinus Torvalds 			break;
1701da177e4SLinus Torvalds 		case PIPE_ISOCHRONOUS: /* number of packets from URB */
1711da177e4SLinus Torvalds 			size = urb->number_of_packets;
1721da177e4SLinus Torvalds 			break;
1731da177e4SLinus Torvalds 	}
1741da177e4SLinus Torvalds 
1751da177e4SLinus Torvalds 	/* allocate the private part of the URB */
176dd00cc48SYoann Padioleau 	urb_priv = kzalloc (sizeof (urb_priv_t) + size * sizeof (struct td *),
1771da177e4SLinus Torvalds 			mem_flags);
1781da177e4SLinus Torvalds 	if (!urb_priv)
1791da177e4SLinus Torvalds 		return -ENOMEM;
1801da177e4SLinus Torvalds 	INIT_LIST_HEAD (&urb_priv->pending);
1811da177e4SLinus Torvalds 	urb_priv->length = size;
1821da177e4SLinus Torvalds 	urb_priv->ed = ed;
1831da177e4SLinus Torvalds 
1841da177e4SLinus Torvalds 	/* allocate the TDs (deferring hash chain updates) */
1851da177e4SLinus Torvalds 	for (i = 0; i < size; i++) {
1861da177e4SLinus Torvalds 		urb_priv->td [i] = td_alloc (ohci, mem_flags);
1871da177e4SLinus Torvalds 		if (!urb_priv->td [i]) {
1881da177e4SLinus Torvalds 			urb_priv->length = i;
1891da177e4SLinus Torvalds 			urb_free_priv (ohci, urb_priv);
1901da177e4SLinus Torvalds 			return -ENOMEM;
1911da177e4SLinus Torvalds 		}
1921da177e4SLinus Torvalds 	}
1931da177e4SLinus Torvalds 
1941da177e4SLinus Torvalds 	spin_lock_irqsave (&ohci->lock, flags);
1951da177e4SLinus Torvalds 
1961da177e4SLinus Torvalds 	/* don't submit to a dead HC */
1978de98402SBenjamin Herrenschmidt 	if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) {
1988de98402SBenjamin Herrenschmidt 		retval = -ENODEV;
1998de98402SBenjamin Herrenschmidt 		goto fail;
2008de98402SBenjamin Herrenschmidt 	}
2011da177e4SLinus Torvalds 	if (!HC_IS_RUNNING(hcd->state)) {
2021da177e4SLinus Torvalds 		retval = -ENODEV;
2031da177e4SLinus Torvalds 		goto fail;
2041da177e4SLinus Torvalds 	}
205e9df41c5SAlan Stern 	retval = usb_hcd_link_urb_to_ep(hcd, urb);
206e9df41c5SAlan Stern 	if (retval)
2071da177e4SLinus Torvalds 		goto fail;
2081da177e4SLinus Torvalds 
2091da177e4SLinus Torvalds 	/* schedule the ed if needed */
2101da177e4SLinus Torvalds 	if (ed->state == ED_IDLE) {
2111da177e4SLinus Torvalds 		retval = ed_schedule (ohci, ed);
212e9df41c5SAlan Stern 		if (retval < 0) {
213e9df41c5SAlan Stern 			usb_hcd_unlink_urb_from_ep(hcd, urb);
214e9df41c5SAlan Stern 			goto fail;
215e9df41c5SAlan Stern 		}
2161da177e4SLinus Torvalds 		if (ed->type == PIPE_ISOCHRONOUS) {
2171da177e4SLinus Torvalds 			u16	frame = ohci_frame_no(ohci);
2181da177e4SLinus Torvalds 
2191da177e4SLinus Torvalds 			/* delay a few frames before the first TD */
2201da177e4SLinus Torvalds 			frame += max_t (u16, 8, ed->interval);
2211da177e4SLinus Torvalds 			frame &= ~(ed->interval - 1);
2221da177e4SLinus Torvalds 			frame |= ed->branch;
2231da177e4SLinus Torvalds 			urb->start_frame = frame;
2241da177e4SLinus Torvalds 
2251da177e4SLinus Torvalds 			/* yes, only URB_ISO_ASAP is supported, and
2261da177e4SLinus Torvalds 			 * urb->start_frame is never used as input.
2271da177e4SLinus Torvalds 			 */
2281da177e4SLinus Torvalds 		}
2291da177e4SLinus Torvalds 	} else if (ed->type == PIPE_ISOCHRONOUS)
2301da177e4SLinus Torvalds 		urb->start_frame = ed->last_iso + ed->interval;
2311da177e4SLinus Torvalds 
2321da177e4SLinus Torvalds 	/* fill the TDs and link them to the ed; and
2331da177e4SLinus Torvalds 	 * enable that part of the schedule, if needed
2341da177e4SLinus Torvalds 	 * and update count of queued periodic urbs
2351da177e4SLinus Torvalds 	 */
2361da177e4SLinus Torvalds 	urb->hcpriv = urb_priv;
2371da177e4SLinus Torvalds 	td_submit_urb (ohci, urb);
2381da177e4SLinus Torvalds 
2391da177e4SLinus Torvalds fail:
2401da177e4SLinus Torvalds 	if (retval)
2411da177e4SLinus Torvalds 		urb_free_priv (ohci, urb_priv);
2421da177e4SLinus Torvalds 	spin_unlock_irqrestore (&ohci->lock, flags);
2431da177e4SLinus Torvalds 	return retval;
2441da177e4SLinus Torvalds }
2451da177e4SLinus Torvalds 
2461da177e4SLinus Torvalds /*
24755d84968SAlan Stern  * decouple the URB from the HC queues (TDs, urb_priv).
24855d84968SAlan Stern  * reporting is always done
2491da177e4SLinus Torvalds  * asynchronously, and we might be dealing with an urb that's
2501da177e4SLinus Torvalds  * partially transferred, or an ED with other urbs being unlinked.
2511da177e4SLinus Torvalds  */
252e9df41c5SAlan Stern static int ohci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
2531da177e4SLinus Torvalds {
2541da177e4SLinus Torvalds 	struct ohci_hcd		*ohci = hcd_to_ohci (hcd);
2551da177e4SLinus Torvalds 	unsigned long		flags;
256e9df41c5SAlan Stern 	int			rc;
2571da177e4SLinus Torvalds 
2581da177e4SLinus Torvalds #ifdef OHCI_VERBOSE_DEBUG
25955d84968SAlan Stern 	urb_print(urb, "UNLINK", 1, status);
2601da177e4SLinus Torvalds #endif
2611da177e4SLinus Torvalds 
2621da177e4SLinus Torvalds 	spin_lock_irqsave (&ohci->lock, flags);
263e9df41c5SAlan Stern 	rc = usb_hcd_check_unlink_urb(hcd, urb, status);
264e9df41c5SAlan Stern 	if (rc) {
265e9df41c5SAlan Stern 		;	/* Do nothing */
266e9df41c5SAlan Stern 	} else if (HC_IS_RUNNING(hcd->state)) {
2671da177e4SLinus Torvalds 		urb_priv_t  *urb_priv;
2681da177e4SLinus Torvalds 
2691da177e4SLinus Torvalds 		/* Unless an IRQ completed the unlink while it was being
2701da177e4SLinus Torvalds 		 * handed to us, flag it for unlink and giveback, and force
2711da177e4SLinus Torvalds 		 * some upcoming INTR_SF to call finish_unlinks()
2721da177e4SLinus Torvalds 		 */
2731da177e4SLinus Torvalds 		urb_priv = urb->hcpriv;
2741da177e4SLinus Torvalds 		if (urb_priv) {
2751da177e4SLinus Torvalds 			if (urb_priv->ed->state == ED_OPER)
2761da177e4SLinus Torvalds 				start_ed_unlink (ohci, urb_priv->ed);
2771da177e4SLinus Torvalds 		}
2781da177e4SLinus Torvalds 	} else {
2791da177e4SLinus Torvalds 		/*
2801da177e4SLinus Torvalds 		 * with HC dead, we won't respect hc queue pointers
2811da177e4SLinus Torvalds 		 * any more ... just clean up every urb's memory.
2821da177e4SLinus Torvalds 		 */
2831da177e4SLinus Torvalds 		if (urb->hcpriv)
28455d84968SAlan Stern 			finish_urb(ohci, urb, status);
2851da177e4SLinus Torvalds 	}
2861da177e4SLinus Torvalds 	spin_unlock_irqrestore (&ohci->lock, flags);
287e9df41c5SAlan Stern 	return rc;
2881da177e4SLinus Torvalds }
2891da177e4SLinus Torvalds 
2901da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/
2911da177e4SLinus Torvalds 
2921da177e4SLinus Torvalds /* frees config/altsetting state for endpoints,
2931da177e4SLinus Torvalds  * including ED memory, dummy TD, and bulk/intr data toggle
2941da177e4SLinus Torvalds  */
2951da177e4SLinus Torvalds 
2961da177e4SLinus Torvalds static void
2971da177e4SLinus Torvalds ohci_endpoint_disable (struct usb_hcd *hcd, struct usb_host_endpoint *ep)
2981da177e4SLinus Torvalds {
2991da177e4SLinus Torvalds 	struct ohci_hcd		*ohci = hcd_to_ohci (hcd);
3001da177e4SLinus Torvalds 	unsigned long		flags;
3011da177e4SLinus Torvalds 	struct ed		*ed = ep->hcpriv;
3021da177e4SLinus Torvalds 	unsigned		limit = 1000;
3031da177e4SLinus Torvalds 
3041da177e4SLinus Torvalds 	/* ASSERT:  any requests/urbs are being unlinked */
3051da177e4SLinus Torvalds 	/* ASSERT:  nobody can be submitting urbs for this any more */
3061da177e4SLinus Torvalds 
3071da177e4SLinus Torvalds 	if (!ed)
3081da177e4SLinus Torvalds 		return;
3091da177e4SLinus Torvalds 
3101da177e4SLinus Torvalds rescan:
3111da177e4SLinus Torvalds 	spin_lock_irqsave (&ohci->lock, flags);
3121da177e4SLinus Torvalds 
3131da177e4SLinus Torvalds 	if (!HC_IS_RUNNING (hcd->state)) {
3141da177e4SLinus Torvalds sanitize:
3151da177e4SLinus Torvalds 		ed->state = ED_IDLE;
31689a0fd18SMike Nuss 		if (quirk_zfmicro(ohci) && ed->type == PIPE_INTERRUPT)
31789a0fd18SMike Nuss 			ohci->eds_scheduled--;
3187d12e780SDavid Howells 		finish_unlinks (ohci, 0);
3191da177e4SLinus Torvalds 	}
3201da177e4SLinus Torvalds 
3211da177e4SLinus Torvalds 	switch (ed->state) {
3221da177e4SLinus Torvalds 	case ED_UNLINK:		/* wait for hw to finish? */
3231da177e4SLinus Torvalds 		/* major IRQ delivery trouble loses INTR_SF too... */
3241da177e4SLinus Torvalds 		if (limit-- == 0) {
32589a0fd18SMike Nuss 			ohci_warn(ohci, "ED unlink timeout\n");
32689a0fd18SMike Nuss 			if (quirk_zfmicro(ohci)) {
32789a0fd18SMike Nuss 				ohci_warn(ohci, "Attempting ZF TD recovery\n");
32889a0fd18SMike Nuss 				ohci->ed_to_check = ed;
32989a0fd18SMike Nuss 				ohci->zf_delay = 2;
33089a0fd18SMike Nuss 			}
3311da177e4SLinus Torvalds 			goto sanitize;
3321da177e4SLinus Torvalds 		}
3331da177e4SLinus Torvalds 		spin_unlock_irqrestore (&ohci->lock, flags);
33422c43863SNishanth Aravamudan 		schedule_timeout_uninterruptible(1);
3351da177e4SLinus Torvalds 		goto rescan;
3361da177e4SLinus Torvalds 	case ED_IDLE:		/* fully unlinked */
3371da177e4SLinus Torvalds 		if (list_empty (&ed->td_list)) {
3381da177e4SLinus Torvalds 			td_free (ohci, ed->dummy);
3391da177e4SLinus Torvalds 			ed_free (ohci, ed);
3401da177e4SLinus Torvalds 			break;
3411da177e4SLinus Torvalds 		}
3421da177e4SLinus Torvalds 		/* else FALL THROUGH */
3431da177e4SLinus Torvalds 	default:
3441da177e4SLinus Torvalds 		/* caller was supposed to have unlinked any requests;
3451da177e4SLinus Torvalds 		 * that's not our job.  can't recover; must leak ed.
3461da177e4SLinus Torvalds 		 */
3471da177e4SLinus Torvalds 		ohci_err (ohci, "leak ed %p (#%02x) state %d%s\n",
3481da177e4SLinus Torvalds 			ed, ep->desc.bEndpointAddress, ed->state,
3491da177e4SLinus Torvalds 			list_empty (&ed->td_list) ? "" : " (has tds)");
3501da177e4SLinus Torvalds 		td_free (ohci, ed->dummy);
3511da177e4SLinus Torvalds 		break;
3521da177e4SLinus Torvalds 	}
3531da177e4SLinus Torvalds 	ep->hcpriv = NULL;
3541da177e4SLinus Torvalds 	spin_unlock_irqrestore (&ohci->lock, flags);
3551da177e4SLinus Torvalds 	return;
3561da177e4SLinus Torvalds }
3571da177e4SLinus Torvalds 
3581da177e4SLinus Torvalds static int ohci_get_frame (struct usb_hcd *hcd)
3591da177e4SLinus Torvalds {
3601da177e4SLinus Torvalds 	struct ohci_hcd		*ohci = hcd_to_ohci (hcd);
3611da177e4SLinus Torvalds 
3621da177e4SLinus Torvalds 	return ohci_frame_no(ohci);
3631da177e4SLinus Torvalds }
3641da177e4SLinus Torvalds 
3651da177e4SLinus Torvalds static void ohci_usb_reset (struct ohci_hcd *ohci)
3661da177e4SLinus Torvalds {
3671da177e4SLinus Torvalds 	ohci->hc_control = ohci_readl (ohci, &ohci->regs->control);
3681da177e4SLinus Torvalds 	ohci->hc_control &= OHCI_CTRL_RWC;
3691da177e4SLinus Torvalds 	ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
3701da177e4SLinus Torvalds }
3711da177e4SLinus Torvalds 
37264a21d02SAleksey Gorelov /* ohci_shutdown forcibly disables IRQs and DMA, helping kexec and
373f4df0e33SDavid Brownell  * other cases where the next software may expect clean state from the
374f4df0e33SDavid Brownell  * "firmware".  this is bus-neutral, unlike shutdown() methods.
375f4df0e33SDavid Brownell  */
37664a21d02SAleksey Gorelov static void
37764a21d02SAleksey Gorelov ohci_shutdown (struct usb_hcd *hcd)
378f4df0e33SDavid Brownell {
379f4df0e33SDavid Brownell 	struct ohci_hcd *ohci;
380f4df0e33SDavid Brownell 
38164a21d02SAleksey Gorelov 	ohci = hcd_to_ohci (hcd);
382f4df0e33SDavid Brownell 	ohci_writel (ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable);
383f4df0e33SDavid Brownell 	ohci_usb_reset (ohci);
384f4df0e33SDavid Brownell 	/* flush the writes */
385f4df0e33SDavid Brownell 	(void) ohci_readl (ohci, &ohci->regs->control);
386f4df0e33SDavid Brownell }
387f4df0e33SDavid Brownell 
38889a0fd18SMike Nuss static int check_ed(struct ohci_hcd *ohci, struct ed *ed)
38989a0fd18SMike Nuss {
39089a0fd18SMike Nuss 	return (hc32_to_cpu(ohci, ed->hwINFO) & ED_IN) != 0
39189a0fd18SMike Nuss 		&& (hc32_to_cpu(ohci, ed->hwHeadP) & TD_MASK)
39289a0fd18SMike Nuss 			== (hc32_to_cpu(ohci, ed->hwTailP) & TD_MASK)
39389a0fd18SMike Nuss 		&& !list_empty(&ed->td_list);
39489a0fd18SMike Nuss }
39589a0fd18SMike Nuss 
39689a0fd18SMike Nuss /* ZF Micro watchdog timer callback. The ZF Micro chipset sometimes completes
39789a0fd18SMike Nuss  * an interrupt TD but neglects to add it to the donelist.  On systems with
39889a0fd18SMike Nuss  * this chipset, we need to periodically check the state of the queues to look
39989a0fd18SMike Nuss  * for such "lost" TDs.
40089a0fd18SMike Nuss  */
40189a0fd18SMike Nuss static void unlink_watchdog_func(unsigned long _ohci)
40289a0fd18SMike Nuss {
403da6fb570SDavid Brownell 	unsigned long	flags;
40489a0fd18SMike Nuss 	unsigned	max;
40589a0fd18SMike Nuss 	unsigned	seen_count = 0;
40689a0fd18SMike Nuss 	unsigned	i;
40789a0fd18SMike Nuss 	struct ed	**seen = NULL;
40889a0fd18SMike Nuss 	struct ohci_hcd	*ohci = (struct ohci_hcd *) _ohci;
40989a0fd18SMike Nuss 
41089a0fd18SMike Nuss 	spin_lock_irqsave(&ohci->lock, flags);
41189a0fd18SMike Nuss 	max = ohci->eds_scheduled;
41289a0fd18SMike Nuss 	if (!max)
41389a0fd18SMike Nuss 		goto done;
41489a0fd18SMike Nuss 
41589a0fd18SMike Nuss 	if (ohci->ed_to_check)
41689a0fd18SMike Nuss 		goto out;
41789a0fd18SMike Nuss 
41889a0fd18SMike Nuss 	seen = kcalloc(max, sizeof *seen, GFP_ATOMIC);
41989a0fd18SMike Nuss 	if (!seen)
42089a0fd18SMike Nuss 		goto out;
42189a0fd18SMike Nuss 
42289a0fd18SMike Nuss 	for (i = 0; i < NUM_INTS; i++) {
42389a0fd18SMike Nuss 		struct ed	*ed = ohci->periodic[i];
42489a0fd18SMike Nuss 
42589a0fd18SMike Nuss 		while (ed) {
42689a0fd18SMike Nuss 			unsigned	temp;
42789a0fd18SMike Nuss 
42889a0fd18SMike Nuss 			/* scan this branch of the periodic schedule tree */
42989a0fd18SMike Nuss 			for (temp = 0; temp < seen_count; temp++) {
43089a0fd18SMike Nuss 				if (seen[temp] == ed) {
43189a0fd18SMike Nuss 					/* we've checked it and what's after */
43289a0fd18SMike Nuss 					ed = NULL;
43389a0fd18SMike Nuss 					break;
43489a0fd18SMike Nuss 				}
43589a0fd18SMike Nuss 			}
43689a0fd18SMike Nuss 			if (!ed)
43789a0fd18SMike Nuss 				break;
43889a0fd18SMike Nuss 			seen[seen_count++] = ed;
43989a0fd18SMike Nuss 			if (!check_ed(ohci, ed)) {
44089a0fd18SMike Nuss 				ed = ed->ed_next;
44189a0fd18SMike Nuss 				continue;
44289a0fd18SMike Nuss 			}
44389a0fd18SMike Nuss 
44489a0fd18SMike Nuss 			/* HC's TD list is empty, but HCD sees at least one
44589a0fd18SMike Nuss 			 * TD that's not been sent through the donelist.
44689a0fd18SMike Nuss 			 */
44789a0fd18SMike Nuss 			ohci->ed_to_check = ed;
44889a0fd18SMike Nuss 			ohci->zf_delay = 2;
44989a0fd18SMike Nuss 
45089a0fd18SMike Nuss 			/* The HC may wait until the next frame to report the
45189a0fd18SMike Nuss 			 * TD as done through the donelist and INTR_WDH.  (We
45289a0fd18SMike Nuss 			 * just *assume* it's not a multi-TD interrupt URB;
45389a0fd18SMike Nuss 			 * those could defer the IRQ more than one frame, using
45489a0fd18SMike Nuss 			 * DI...)  Check again after the next INTR_SF.
45589a0fd18SMike Nuss 			 */
45689a0fd18SMike Nuss 			ohci_writel(ohci, OHCI_INTR_SF,
45789a0fd18SMike Nuss 					&ohci->regs->intrstatus);
45889a0fd18SMike Nuss 			ohci_writel(ohci, OHCI_INTR_SF,
45989a0fd18SMike Nuss 					&ohci->regs->intrenable);
46089a0fd18SMike Nuss 
46189a0fd18SMike Nuss 			/* flush those writes */
46289a0fd18SMike Nuss 			(void) ohci_readl(ohci, &ohci->regs->control);
46389a0fd18SMike Nuss 
46489a0fd18SMike Nuss 			goto out;
46589a0fd18SMike Nuss 		}
46689a0fd18SMike Nuss 	}
46789a0fd18SMike Nuss out:
46889a0fd18SMike Nuss 	kfree(seen);
46989a0fd18SMike Nuss 	if (ohci->eds_scheduled)
47089a0fd18SMike Nuss 		mod_timer(&ohci->unlink_watchdog, round_jiffies_relative(HZ));
47189a0fd18SMike Nuss done:
47289a0fd18SMike Nuss 	spin_unlock_irqrestore(&ohci->lock, flags);
47389a0fd18SMike Nuss }
47489a0fd18SMike Nuss 
4751da177e4SLinus Torvalds /*-------------------------------------------------------------------------*
4761da177e4SLinus Torvalds  * HC functions
4771da177e4SLinus Torvalds  *-------------------------------------------------------------------------*/
4781da177e4SLinus Torvalds 
4791da177e4SLinus Torvalds /* init memory, and kick BIOS/SMM off */
4801da177e4SLinus Torvalds 
4811da177e4SLinus Torvalds static int ohci_init (struct ohci_hcd *ohci)
4821da177e4SLinus Torvalds {
4831da177e4SLinus Torvalds 	int ret;
4846a9062f3SDavid Brownell 	struct usb_hcd *hcd = ohci_to_hcd(ohci);
4851da177e4SLinus Torvalds 
4861da177e4SLinus Torvalds 	disable (ohci);
4876a9062f3SDavid Brownell 	ohci->regs = hcd->regs;
4881da177e4SLinus Torvalds 
4896a9062f3SDavid Brownell 	/* REVISIT this BIOS handshake is now moved into PCI "quirks", and
4906a9062f3SDavid Brownell 	 * was never needed for most non-PCI systems ... remove the code?
4916a9062f3SDavid Brownell 	 */
4926a9062f3SDavid Brownell 
4931da177e4SLinus Torvalds #ifndef IR_DISABLE
4941da177e4SLinus Torvalds 	/* SMM owns the HC?  not for long! */
4951da177e4SLinus Torvalds 	if (!no_handshake && ohci_readl (ohci,
4961da177e4SLinus Torvalds 					&ohci->regs->control) & OHCI_CTRL_IR) {
4971da177e4SLinus Torvalds 		u32 temp;
4981da177e4SLinus Torvalds 
4991da177e4SLinus Torvalds 		ohci_dbg (ohci, "USB HC TakeOver from BIOS/SMM\n");
5001da177e4SLinus Torvalds 
5011da177e4SLinus Torvalds 		/* this timeout is arbitrary.  we make it long, so systems
5021da177e4SLinus Torvalds 		 * depending on usb keyboards may be usable even if the
5031da177e4SLinus Torvalds 		 * BIOS/SMM code seems pretty broken.
5041da177e4SLinus Torvalds 		 */
5051da177e4SLinus Torvalds 		temp = 500;	/* arbitrary: five seconds */
5061da177e4SLinus Torvalds 
5071da177e4SLinus Torvalds 		ohci_writel (ohci, OHCI_INTR_OC, &ohci->regs->intrenable);
5081da177e4SLinus Torvalds 		ohci_writel (ohci, OHCI_OCR, &ohci->regs->cmdstatus);
5091da177e4SLinus Torvalds 		while (ohci_readl (ohci, &ohci->regs->control) & OHCI_CTRL_IR) {
5101da177e4SLinus Torvalds 			msleep (10);
5111da177e4SLinus Torvalds 			if (--temp == 0) {
5121da177e4SLinus Torvalds 				ohci_err (ohci, "USB HC takeover failed!"
5131da177e4SLinus Torvalds 					"  (BIOS/SMM bug)\n");
5141da177e4SLinus Torvalds 				return -EBUSY;
5151da177e4SLinus Torvalds 			}
5161da177e4SLinus Torvalds 		}
5171da177e4SLinus Torvalds 		ohci_usb_reset (ohci);
5181da177e4SLinus Torvalds 	}
5191da177e4SLinus Torvalds #endif
5201da177e4SLinus Torvalds 
5211da177e4SLinus Torvalds 	/* Disable HC interrupts */
5221da177e4SLinus Torvalds 	ohci_writel (ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable);
5236a9062f3SDavid Brownell 
5246a9062f3SDavid Brownell 	/* flush the writes, and save key bits like RWC */
5256a9062f3SDavid Brownell 	if (ohci_readl (ohci, &ohci->regs->control) & OHCI_CTRL_RWC)
5266a9062f3SDavid Brownell 		ohci->hc_control |= OHCI_CTRL_RWC;
5271da177e4SLinus Torvalds 
528fdd13b36SDavid Brownell 	/* Read the number of ports unless overridden */
529fdd13b36SDavid Brownell 	if (ohci->num_ports == 0)
530fdd13b36SDavid Brownell 		ohci->num_ports = roothub_a(ohci) & RH_A_NDP;
531fdd13b36SDavid Brownell 
5321da177e4SLinus Torvalds 	if (ohci->hcca)
5331da177e4SLinus Torvalds 		return 0;
5341da177e4SLinus Torvalds 
5356a9062f3SDavid Brownell 	ohci->hcca = dma_alloc_coherent (hcd->self.controller,
5361da177e4SLinus Torvalds 			sizeof *ohci->hcca, &ohci->hcca_dma, 0);
5371da177e4SLinus Torvalds 	if (!ohci->hcca)
5381da177e4SLinus Torvalds 		return -ENOMEM;
5391da177e4SLinus Torvalds 
5401da177e4SLinus Torvalds 	if ((ret = ohci_mem_init (ohci)) < 0)
5416a9062f3SDavid Brownell 		ohci_stop (hcd);
5426a9062f3SDavid Brownell 	else {
5436a9062f3SDavid Brownell 		create_debug_files (ohci);
5446a9062f3SDavid Brownell 	}
5451da177e4SLinus Torvalds 
5461da177e4SLinus Torvalds 	return ret;
5471da177e4SLinus Torvalds }
5481da177e4SLinus Torvalds 
5491da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/
5501da177e4SLinus Torvalds 
5511da177e4SLinus Torvalds /* Start an OHCI controller, set the BUS operational
5521da177e4SLinus Torvalds  * resets USB and controller
5531da177e4SLinus Torvalds  * enable interrupts
5541da177e4SLinus Torvalds  */
5551da177e4SLinus Torvalds static int ohci_run (struct ohci_hcd *ohci)
5561da177e4SLinus Torvalds {
5571da177e4SLinus Torvalds 	u32			mask, temp;
5581da177e4SLinus Torvalds 	int			first = ohci->fminterval == 0;
5596a9062f3SDavid Brownell 	struct usb_hcd		*hcd = ohci_to_hcd(ohci);
5601da177e4SLinus Torvalds 
5611da177e4SLinus Torvalds 	disable (ohci);
5621da177e4SLinus Torvalds 
5631da177e4SLinus Torvalds 	/* boot firmware should have set this up (5.1.1.3.1) */
5641da177e4SLinus Torvalds 	if (first) {
5651da177e4SLinus Torvalds 
5661da177e4SLinus Torvalds 		temp = ohci_readl (ohci, &ohci->regs->fminterval);
5671da177e4SLinus Torvalds 		ohci->fminterval = temp & 0x3fff;
5681da177e4SLinus Torvalds 		if (ohci->fminterval != FI)
5691da177e4SLinus Torvalds 			ohci_dbg (ohci, "fminterval delta %d\n",
5701da177e4SLinus Torvalds 				ohci->fminterval - FI);
5711da177e4SLinus Torvalds 		ohci->fminterval |= FSMP (ohci->fminterval) << 16;
5721da177e4SLinus Torvalds 		/* also: power/overcurrent flags in roothub.a */
5731da177e4SLinus Torvalds 	}
5741da177e4SLinus Torvalds 
5756a9062f3SDavid Brownell 	/* Reset USB nearly "by the book".  RemoteWakeupConnected was
5766a9062f3SDavid Brownell 	 * saved if boot firmware (BIOS/SMM/...) told us it's connected,
5776a9062f3SDavid Brownell 	 * or if bus glue did the same (e.g. for PCI add-in cards with
5786a9062f3SDavid Brownell 	 * PCI PM support).
5791da177e4SLinus Torvalds 	 */
5806a9062f3SDavid Brownell 	if ((ohci->hc_control & OHCI_CTRL_RWC) != 0
5816a9062f3SDavid Brownell 			&& !device_may_wakeup(hcd->self.controller))
5826a9062f3SDavid Brownell 		device_init_wakeup(hcd->self.controller, 1);
5831da177e4SLinus Torvalds 
5841da177e4SLinus Torvalds 	switch (ohci->hc_control & OHCI_CTRL_HCFS) {
5851da177e4SLinus Torvalds 	case OHCI_USB_OPER:
5861da177e4SLinus Torvalds 		temp = 0;
5871da177e4SLinus Torvalds 		break;
5881da177e4SLinus Torvalds 	case OHCI_USB_SUSPEND:
5891da177e4SLinus Torvalds 	case OHCI_USB_RESUME:
5901da177e4SLinus Torvalds 		ohci->hc_control &= OHCI_CTRL_RWC;
5911da177e4SLinus Torvalds 		ohci->hc_control |= OHCI_USB_RESUME;
5921da177e4SLinus Torvalds 		temp = 10 /* msec wait */;
5931da177e4SLinus Torvalds 		break;
5941da177e4SLinus Torvalds 	// case OHCI_USB_RESET:
5951da177e4SLinus Torvalds 	default:
5961da177e4SLinus Torvalds 		ohci->hc_control &= OHCI_CTRL_RWC;
5971da177e4SLinus Torvalds 		ohci->hc_control |= OHCI_USB_RESET;
5981da177e4SLinus Torvalds 		temp = 50 /* msec wait */;
5991da177e4SLinus Torvalds 		break;
6001da177e4SLinus Torvalds 	}
6011da177e4SLinus Torvalds 	ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
6021da177e4SLinus Torvalds 	// flush the writes
6031da177e4SLinus Torvalds 	(void) ohci_readl (ohci, &ohci->regs->control);
6041da177e4SLinus Torvalds 	msleep(temp);
605383975d7SAlan Stern 
6061da177e4SLinus Torvalds 	memset (ohci->hcca, 0, sizeof (struct ohci_hcca));
6071da177e4SLinus Torvalds 
6081da177e4SLinus Torvalds 	/* 2msec timelimit here means no irqs/preempt */
6091da177e4SLinus Torvalds 	spin_lock_irq (&ohci->lock);
6101da177e4SLinus Torvalds 
6111da177e4SLinus Torvalds retry:
6121da177e4SLinus Torvalds 	/* HC Reset requires max 10 us delay */
6131da177e4SLinus Torvalds 	ohci_writel (ohci, OHCI_HCR,  &ohci->regs->cmdstatus);
6141da177e4SLinus Torvalds 	temp = 30;	/* ... allow extra time */
6151da177e4SLinus Torvalds 	while ((ohci_readl (ohci, &ohci->regs->cmdstatus) & OHCI_HCR) != 0) {
6161da177e4SLinus Torvalds 		if (--temp == 0) {
6171da177e4SLinus Torvalds 			spin_unlock_irq (&ohci->lock);
6181da177e4SLinus Torvalds 			ohci_err (ohci, "USB HC reset timed out!\n");
6191da177e4SLinus Torvalds 			return -1;
6201da177e4SLinus Torvalds 		}
6211da177e4SLinus Torvalds 		udelay (1);
6221da177e4SLinus Torvalds 	}
6231da177e4SLinus Torvalds 
6241da177e4SLinus Torvalds 	/* now we're in the SUSPEND state ... must go OPERATIONAL
6251da177e4SLinus Torvalds 	 * within 2msec else HC enters RESUME
6261da177e4SLinus Torvalds 	 *
6271da177e4SLinus Torvalds 	 * ... but some hardware won't init fmInterval "by the book"
6281da177e4SLinus Torvalds 	 * (SiS, OPTi ...), so reset again instead.  SiS doesn't need
6291da177e4SLinus Torvalds 	 * this if we write fmInterval after we're OPERATIONAL.
6301da177e4SLinus Torvalds 	 * Unclear about ALi, ServerWorks, and others ... this could
6311da177e4SLinus Torvalds 	 * easily be a longstanding bug in chip init on Linux.
6321da177e4SLinus Torvalds 	 */
6331da177e4SLinus Torvalds 	if (ohci->flags & OHCI_QUIRK_INITRESET) {
6341da177e4SLinus Torvalds 		ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
6351da177e4SLinus Torvalds 		// flush those writes
6361da177e4SLinus Torvalds 		(void) ohci_readl (ohci, &ohci->regs->control);
6371da177e4SLinus Torvalds 	}
6381da177e4SLinus Torvalds 
6391da177e4SLinus Torvalds 	/* Tell the controller where the control and bulk lists are
6401da177e4SLinus Torvalds 	 * The lists are empty now. */
6411da177e4SLinus Torvalds 	ohci_writel (ohci, 0, &ohci->regs->ed_controlhead);
6421da177e4SLinus Torvalds 	ohci_writel (ohci, 0, &ohci->regs->ed_bulkhead);
6431da177e4SLinus Torvalds 
6441da177e4SLinus Torvalds 	/* a reset clears this */
6451da177e4SLinus Torvalds 	ohci_writel (ohci, (u32) ohci->hcca_dma, &ohci->regs->hcca);
6461da177e4SLinus Torvalds 
6471da177e4SLinus Torvalds 	periodic_reinit (ohci);
6481da177e4SLinus Torvalds 
6491da177e4SLinus Torvalds 	/* some OHCI implementations are finicky about how they init.
6501da177e4SLinus Torvalds 	 * bogus values here mean not even enumeration could work.
6511da177e4SLinus Torvalds 	 */
6521da177e4SLinus Torvalds 	if ((ohci_readl (ohci, &ohci->regs->fminterval) & 0x3fff0000) == 0
6531da177e4SLinus Torvalds 			|| !ohci_readl (ohci, &ohci->regs->periodicstart)) {
6541da177e4SLinus Torvalds 		if (!(ohci->flags & OHCI_QUIRK_INITRESET)) {
6551da177e4SLinus Torvalds 			ohci->flags |= OHCI_QUIRK_INITRESET;
6561da177e4SLinus Torvalds 			ohci_dbg (ohci, "enabling initreset quirk\n");
6571da177e4SLinus Torvalds 			goto retry;
6581da177e4SLinus Torvalds 		}
6591da177e4SLinus Torvalds 		spin_unlock_irq (&ohci->lock);
6601da177e4SLinus Torvalds 		ohci_err (ohci, "init err (%08x %04x)\n",
6611da177e4SLinus Torvalds 			ohci_readl (ohci, &ohci->regs->fminterval),
6621da177e4SLinus Torvalds 			ohci_readl (ohci, &ohci->regs->periodicstart));
6631da177e4SLinus Torvalds 		return -EOVERFLOW;
6641da177e4SLinus Torvalds 	}
6651da177e4SLinus Torvalds 
666d413984aSDavid Brownell 	/* use rhsc irqs after khubd is fully initialized */
667d413984aSDavid Brownell 	hcd->poll_rh = 1;
668d413984aSDavid Brownell 	hcd->uses_new_polling = 1;
669d413984aSDavid Brownell 
6701da177e4SLinus Torvalds 	/* start controller operations */
6711da177e4SLinus Torvalds 	ohci->hc_control &= OHCI_CTRL_RWC;
6721da177e4SLinus Torvalds 	ohci->hc_control |= OHCI_CONTROL_INIT | OHCI_USB_OPER;
6731da177e4SLinus Torvalds 	ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
6746a9062f3SDavid Brownell 	hcd->state = HC_STATE_RUNNING;
6751da177e4SLinus Torvalds 
6761da177e4SLinus Torvalds 	/* wake on ConnectStatusChange, matching external hubs */
6771da177e4SLinus Torvalds 	ohci_writel (ohci, RH_HS_DRWE, &ohci->regs->roothub.status);
6781da177e4SLinus Torvalds 
6791da177e4SLinus Torvalds 	/* Choose the interrupts we care about now, others later on demand */
6801da177e4SLinus Torvalds 	mask = OHCI_INTR_INIT;
681d413984aSDavid Brownell 	ohci_writel (ohci, ~0, &ohci->regs->intrstatus);
6821da177e4SLinus Torvalds 	ohci_writel (ohci, mask, &ohci->regs->intrenable);
6831da177e4SLinus Torvalds 
6841da177e4SLinus Torvalds 	/* handle root hub init quirks ... */
6851da177e4SLinus Torvalds 	temp = roothub_a (ohci);
6861da177e4SLinus Torvalds 	temp &= ~(RH_A_PSM | RH_A_OCPM);
6871da177e4SLinus Torvalds 	if (ohci->flags & OHCI_QUIRK_SUPERIO) {
6881da177e4SLinus Torvalds 		/* NSC 87560 and maybe others */
6891da177e4SLinus Torvalds 		temp |= RH_A_NOCP;
6901da177e4SLinus Torvalds 		temp &= ~(RH_A_POTPGT | RH_A_NPS);
6911da177e4SLinus Torvalds 		ohci_writel (ohci, temp, &ohci->regs->roothub.a);
6921da177e4SLinus Torvalds 	} else if ((ohci->flags & OHCI_QUIRK_AMD756) || distrust_firmware) {
6931da177e4SLinus Torvalds 		/* hub power always on; required for AMD-756 and some
6941da177e4SLinus Torvalds 		 * Mac platforms.  ganged overcurrent reporting, if any.
6951da177e4SLinus Torvalds 		 */
6961da177e4SLinus Torvalds 		temp |= RH_A_NPS;
6971da177e4SLinus Torvalds 		ohci_writel (ohci, temp, &ohci->regs->roothub.a);
6981da177e4SLinus Torvalds 	}
6991da177e4SLinus Torvalds 	ohci_writel (ohci, RH_HS_LPSC, &ohci->regs->roothub.status);
7001da177e4SLinus Torvalds 	ohci_writel (ohci, (temp & RH_A_NPS) ? 0 : RH_B_PPCM,
7011da177e4SLinus Torvalds 						&ohci->regs->roothub.b);
7021da177e4SLinus Torvalds 	// flush those writes
7031da177e4SLinus Torvalds 	(void) ohci_readl (ohci, &ohci->regs->control);
7041da177e4SLinus Torvalds 
705d413984aSDavid Brownell 	ohci->next_statechange = jiffies + STATECHANGE_DELAY;
7061da177e4SLinus Torvalds 	spin_unlock_irq (&ohci->lock);
7071da177e4SLinus Torvalds 
7081da177e4SLinus Torvalds 	// POTPGT delay is bits 24-31, in 2 ms units.
7091da177e4SLinus Torvalds 	mdelay ((temp >> 23) & 0x1fe);
7106a9062f3SDavid Brownell 	hcd->state = HC_STATE_RUNNING;
7111da177e4SLinus Torvalds 
71289a0fd18SMike Nuss 	if (quirk_zfmicro(ohci)) {
71389a0fd18SMike Nuss 		/* Create timer to watch for bad queue state on ZF Micro */
71489a0fd18SMike Nuss 		setup_timer(&ohci->unlink_watchdog, unlink_watchdog_func,
71589a0fd18SMike Nuss 				(unsigned long) ohci);
71689a0fd18SMike Nuss 
71789a0fd18SMike Nuss 		ohci->eds_scheduled = 0;
71889a0fd18SMike Nuss 		ohci->ed_to_check = NULL;
71989a0fd18SMike Nuss 	}
72089a0fd18SMike Nuss 
7211da177e4SLinus Torvalds 	ohci_dump (ohci, 1);
7221da177e4SLinus Torvalds 
7231da177e4SLinus Torvalds 	return 0;
7241da177e4SLinus Torvalds }
7251da177e4SLinus Torvalds 
7261da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/
7271da177e4SLinus Torvalds 
7281da177e4SLinus Torvalds /* an interrupt happens */
7291da177e4SLinus Torvalds 
7307d12e780SDavid Howells static irqreturn_t ohci_irq (struct usb_hcd *hcd)
7311da177e4SLinus Torvalds {
7321da177e4SLinus Torvalds 	struct ohci_hcd		*ohci = hcd_to_ohci (hcd);
7331da177e4SLinus Torvalds 	struct ohci_regs __iomem *regs = ohci->regs;
7341da177e4SLinus Torvalds 	int			ints;
7351da177e4SLinus Torvalds 
736565227c0SBenjamin Herrenschmidt 	/* Read interrupt status (and flush pending writes).  We ignore the
737565227c0SBenjamin Herrenschmidt 	 * optimization of checking the LSB of hcca->done_head; it doesn't
738565227c0SBenjamin Herrenschmidt 	 * work on all systems (edge triggering for OHCI can be a factor).
73989a0fd18SMike Nuss 	 */
740565227c0SBenjamin Herrenschmidt 	ints = ohci_readl(ohci, &regs->intrstatus);
7411da177e4SLinus Torvalds 
742565227c0SBenjamin Herrenschmidt 	/* Check for an all 1's result which is a typical consequence
743565227c0SBenjamin Herrenschmidt 	 * of dead, unclocked, or unplugged (CardBus...) devices
744565227c0SBenjamin Herrenschmidt 	 */
745565227c0SBenjamin Herrenschmidt 	if (ints == ~(u32)0) {
7461da177e4SLinus Torvalds 		disable (ohci);
7471da177e4SLinus Torvalds 		ohci_dbg (ohci, "device removed!\n");
7481da177e4SLinus Torvalds 		return IRQ_HANDLED;
749565227c0SBenjamin Herrenschmidt 	}
750565227c0SBenjamin Herrenschmidt 
751565227c0SBenjamin Herrenschmidt 	/* We only care about interrupts that are enabled */
752565227c0SBenjamin Herrenschmidt 	ints &= ohci_readl(ohci, &regs->intrenable);
7531da177e4SLinus Torvalds 
7541da177e4SLinus Torvalds 	/* interrupt for some other device? */
755565227c0SBenjamin Herrenschmidt 	if (ints == 0)
7561da177e4SLinus Torvalds 		return IRQ_NOTMINE;
7571da177e4SLinus Torvalds 
7581da177e4SLinus Torvalds 	if (ints & OHCI_INTR_UE) {
759d576bb9fSMichael Hanselmann 		// e.g. due to PCI Master/Target Abort
76089a0fd18SMike Nuss 		if (quirk_nec(ohci)) {
761d576bb9fSMichael Hanselmann 			/* Workaround for a silicon bug in some NEC chips used
762d576bb9fSMichael Hanselmann 			 * in Apple's PowerBooks. Adapted from Darwin code.
763d576bb9fSMichael Hanselmann 			 */
764d576bb9fSMichael Hanselmann 			ohci_err (ohci, "OHCI Unrecoverable Error, scheduling NEC chip restart\n");
765d576bb9fSMichael Hanselmann 
766d576bb9fSMichael Hanselmann 			ohci_writel (ohci, OHCI_INTR_UE, &regs->intrdisable);
767d576bb9fSMichael Hanselmann 
768d576bb9fSMichael Hanselmann 			schedule_work (&ohci->nec_work);
769d576bb9fSMichael Hanselmann 		} else {
7701da177e4SLinus Torvalds 			disable (ohci);
7711da177e4SLinus Torvalds 			ohci_err (ohci, "OHCI Unrecoverable Error, disabled\n");
772d576bb9fSMichael Hanselmann 		}
7731da177e4SLinus Torvalds 
7741da177e4SLinus Torvalds 		ohci_dump (ohci, 1);
7751da177e4SLinus Torvalds 		ohci_usb_reset (ohci);
7761da177e4SLinus Torvalds 	}
7771da177e4SLinus Torvalds 
778583ceadaSAlan Stern 	if (ints & OHCI_INTR_RHSC) {
779583ceadaSAlan Stern 		ohci_vdbg(ohci, "rhsc\n");
780583ceadaSAlan Stern 		ohci->next_statechange = jiffies + STATECHANGE_DELAY;
781583ceadaSAlan Stern 		ohci_writel(ohci, OHCI_INTR_RD | OHCI_INTR_RHSC,
782583ceadaSAlan Stern 				&regs->intrstatus);
783052ac01aSAlan Stern 
784052ac01aSAlan Stern 		/* NOTE: Vendors didn't always make the same implementation
785052ac01aSAlan Stern 		 * choices for RHSC.  Many followed the spec; RHSC triggers
786052ac01aSAlan Stern 		 * on an edge, like setting and maybe clearing a port status
787052ac01aSAlan Stern 		 * change bit.  With others it's level-triggered, active
788052ac01aSAlan Stern 		 * until khubd clears all the port status change bits.  We'll
789052ac01aSAlan Stern 		 * always disable it here and rely on polling until khubd
790052ac01aSAlan Stern 		 * re-enables it.
791052ac01aSAlan Stern 		 */
792052ac01aSAlan Stern 		ohci_writel(ohci, OHCI_INTR_RHSC, &regs->intrdisable);
793583ceadaSAlan Stern 		usb_hcd_poll_rh_status(hcd);
794583ceadaSAlan Stern 	}
795583ceadaSAlan Stern 
796583ceadaSAlan Stern 	/* For connect and disconnect events, we expect the controller
797583ceadaSAlan Stern 	 * to turn on RHSC along with RD.  But for remote wakeup events
798583ceadaSAlan Stern 	 * this might not happen.
799583ceadaSAlan Stern 	 */
800583ceadaSAlan Stern 	else if (ints & OHCI_INTR_RD) {
8011da177e4SLinus Torvalds 		ohci_vdbg(ohci, "resume detect\n");
802e0fd3cbcSDavid Brownell 		ohci_writel(ohci, OHCI_INTR_RD, &regs->intrstatus);
8038d1a243bSAlan Stern 		hcd->poll_rh = 1;
8048d1a243bSAlan Stern 		if (ohci->autostop) {
8058d1a243bSAlan Stern 			spin_lock (&ohci->lock);
8068d1a243bSAlan Stern 			ohci_rh_resume (ohci);
8078d1a243bSAlan Stern 			spin_unlock (&ohci->lock);
8088d1a243bSAlan Stern 		} else
809f197b2c5SDavid Brownell 			usb_hcd_resume_root_hub(hcd);
8101da177e4SLinus Torvalds 	}
8111da177e4SLinus Torvalds 
8121da177e4SLinus Torvalds 	if (ints & OHCI_INTR_WDH) {
8131da177e4SLinus Torvalds 		spin_lock (&ohci->lock);
8147d12e780SDavid Howells 		dl_done_list (ohci);
8151da177e4SLinus Torvalds 		spin_unlock (&ohci->lock);
8161da177e4SLinus Torvalds 	}
8171da177e4SLinus Torvalds 
81889a0fd18SMike Nuss 	if (quirk_zfmicro(ohci) && (ints & OHCI_INTR_SF)) {
81989a0fd18SMike Nuss 		spin_lock(&ohci->lock);
82089a0fd18SMike Nuss 		if (ohci->ed_to_check) {
82189a0fd18SMike Nuss 			struct ed *ed = ohci->ed_to_check;
82289a0fd18SMike Nuss 
82389a0fd18SMike Nuss 			if (check_ed(ohci, ed)) {
82489a0fd18SMike Nuss 				/* HC thinks the TD list is empty; HCD knows
82589a0fd18SMike Nuss 				 * at least one TD is outstanding
82689a0fd18SMike Nuss 				 */
82789a0fd18SMike Nuss 				if (--ohci->zf_delay == 0) {
82889a0fd18SMike Nuss 					struct td *td = list_entry(
82989a0fd18SMike Nuss 						ed->td_list.next,
83089a0fd18SMike Nuss 						struct td, td_list);
83189a0fd18SMike Nuss 					ohci_warn(ohci,
83289a0fd18SMike Nuss 						  "Reclaiming orphan TD %p\n",
83389a0fd18SMike Nuss 						  td);
83489a0fd18SMike Nuss 					takeback_td(ohci, td);
83589a0fd18SMike Nuss 					ohci->ed_to_check = NULL;
83689a0fd18SMike Nuss 				}
83789a0fd18SMike Nuss 			} else
83889a0fd18SMike Nuss 				ohci->ed_to_check = NULL;
83989a0fd18SMike Nuss 		}
84089a0fd18SMike Nuss 		spin_unlock(&ohci->lock);
84189a0fd18SMike Nuss 	}
84289a0fd18SMike Nuss 
8431da177e4SLinus Torvalds 	/* could track INTR_SO to reduce available PCI/... bandwidth */
8441da177e4SLinus Torvalds 
8451da177e4SLinus Torvalds 	/* handle any pending URB/ED unlinks, leaving INTR_SF enabled
8461da177e4SLinus Torvalds 	 * when there's still unlinking to be done (next frame).
8471da177e4SLinus Torvalds 	 */
8481da177e4SLinus Torvalds 	spin_lock (&ohci->lock);
8491da177e4SLinus Torvalds 	if (ohci->ed_rm_list)
8507d12e780SDavid Howells 		finish_unlinks (ohci, ohci_frame_no(ohci));
85189a0fd18SMike Nuss 	if ((ints & OHCI_INTR_SF) != 0
85289a0fd18SMike Nuss 			&& !ohci->ed_rm_list
85389a0fd18SMike Nuss 			&& !ohci->ed_to_check
8541da177e4SLinus Torvalds 			&& HC_IS_RUNNING(hcd->state))
8551da177e4SLinus Torvalds 		ohci_writel (ohci, OHCI_INTR_SF, &regs->intrdisable);
8561da177e4SLinus Torvalds 	spin_unlock (&ohci->lock);
8571da177e4SLinus Torvalds 
8581da177e4SLinus Torvalds 	if (HC_IS_RUNNING(hcd->state)) {
8591da177e4SLinus Torvalds 		ohci_writel (ohci, ints, &regs->intrstatus);
8601da177e4SLinus Torvalds 		ohci_writel (ohci, OHCI_INTR_MIE, &regs->intrenable);
8611da177e4SLinus Torvalds 		// flush those writes
8621da177e4SLinus Torvalds 		(void) ohci_readl (ohci, &ohci->regs->control);
8631da177e4SLinus Torvalds 	}
8641da177e4SLinus Torvalds 
8651da177e4SLinus Torvalds 	return IRQ_HANDLED;
8661da177e4SLinus Torvalds }
8671da177e4SLinus Torvalds 
8681da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/
8691da177e4SLinus Torvalds 
8701da177e4SLinus Torvalds static void ohci_stop (struct usb_hcd *hcd)
8711da177e4SLinus Torvalds {
8721da177e4SLinus Torvalds 	struct ohci_hcd		*ohci = hcd_to_ohci (hcd);
8731da177e4SLinus Torvalds 
8741da177e4SLinus Torvalds 	ohci_dump (ohci, 1);
8751da177e4SLinus Torvalds 
8761da177e4SLinus Torvalds 	flush_scheduled_work();
8771da177e4SLinus Torvalds 
8781da177e4SLinus Torvalds 	ohci_usb_reset (ohci);
8791da177e4SLinus Torvalds 	ohci_writel (ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable);
88071795c1dSPete Zaitcev 	free_irq(hcd->irq, hcd);
88171795c1dSPete Zaitcev 	hcd->irq = -1;
8821da177e4SLinus Torvalds 
88389a0fd18SMike Nuss 	if (quirk_zfmicro(ohci))
88489a0fd18SMike Nuss 		del_timer(&ohci->unlink_watchdog);
88589a0fd18SMike Nuss 
8861da177e4SLinus Torvalds 	remove_debug_files (ohci);
8871da177e4SLinus Torvalds 	ohci_mem_cleanup (ohci);
8881da177e4SLinus Torvalds 	if (ohci->hcca) {
8891da177e4SLinus Torvalds 		dma_free_coherent (hcd->self.controller,
8901da177e4SLinus Torvalds 				sizeof *ohci->hcca,
8911da177e4SLinus Torvalds 				ohci->hcca, ohci->hcca_dma);
8921da177e4SLinus Torvalds 		ohci->hcca = NULL;
8931da177e4SLinus Torvalds 		ohci->hcca_dma = 0;
8941da177e4SLinus Torvalds 	}
8951da177e4SLinus Torvalds }
8961da177e4SLinus Torvalds 
8971da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/
8981da177e4SLinus Torvalds 
899da6fb570SDavid Brownell #if defined(CONFIG_PM) || defined(CONFIG_PCI)
900da6fb570SDavid Brownell 
9011da177e4SLinus Torvalds /* must not be called from interrupt context */
9021da177e4SLinus Torvalds static int ohci_restart (struct ohci_hcd *ohci)
9031da177e4SLinus Torvalds {
9041da177e4SLinus Torvalds 	int temp;
9051da177e4SLinus Torvalds 	int i;
9061da177e4SLinus Torvalds 	struct urb_priv *priv;
9071da177e4SLinus Torvalds 
9081da177e4SLinus Torvalds 	spin_lock_irq(&ohci->lock);
9091da177e4SLinus Torvalds 	disable (ohci);
910d576bb9fSMichael Hanselmann 
911d576bb9fSMichael Hanselmann 	/* Recycle any "live" eds/tds (and urbs). */
9121da177e4SLinus Torvalds 	if (!list_empty (&ohci->pending))
9131da177e4SLinus Torvalds 		ohci_dbg(ohci, "abort schedule...\n");
9141da177e4SLinus Torvalds 	list_for_each_entry (priv, &ohci->pending, pending) {
9151da177e4SLinus Torvalds 		struct urb	*urb = priv->td[0]->urb;
9161da177e4SLinus Torvalds 		struct ed	*ed = priv->ed;
9171da177e4SLinus Torvalds 
9181da177e4SLinus Torvalds 		switch (ed->state) {
9191da177e4SLinus Torvalds 		case ED_OPER:
9201da177e4SLinus Torvalds 			ed->state = ED_UNLINK;
9211da177e4SLinus Torvalds 			ed->hwINFO |= cpu_to_hc32(ohci, ED_DEQUEUE);
9221da177e4SLinus Torvalds 			ed_deschedule (ohci, ed);
9231da177e4SLinus Torvalds 
9241da177e4SLinus Torvalds 			ed->ed_next = ohci->ed_rm_list;
9251da177e4SLinus Torvalds 			ed->ed_prev = NULL;
9261da177e4SLinus Torvalds 			ohci->ed_rm_list = ed;
9271da177e4SLinus Torvalds 			/* FALLTHROUGH */
9281da177e4SLinus Torvalds 		case ED_UNLINK:
9291da177e4SLinus Torvalds 			break;
9301da177e4SLinus Torvalds 		default:
9311da177e4SLinus Torvalds 			ohci_dbg(ohci, "bogus ed %p state %d\n",
9321da177e4SLinus Torvalds 					ed, ed->state);
9331da177e4SLinus Torvalds 		}
9341da177e4SLinus Torvalds 
93555d84968SAlan Stern 		if (!urb->unlinked)
93655d84968SAlan Stern 			urb->unlinked = -ESHUTDOWN;
9371da177e4SLinus Torvalds 	}
9387d12e780SDavid Howells 	finish_unlinks (ohci, 0);
9391da177e4SLinus Torvalds 	spin_unlock_irq(&ohci->lock);
9401da177e4SLinus Torvalds 
9411da177e4SLinus Torvalds 	/* paranoia, in case that didn't work: */
9421da177e4SLinus Torvalds 
9431da177e4SLinus Torvalds 	/* empty the interrupt branches */
9441da177e4SLinus Torvalds 	for (i = 0; i < NUM_INTS; i++) ohci->load [i] = 0;
9451da177e4SLinus Torvalds 	for (i = 0; i < NUM_INTS; i++) ohci->hcca->int_table [i] = 0;
9461da177e4SLinus Torvalds 
9471da177e4SLinus Torvalds 	/* no EDs to remove */
9481da177e4SLinus Torvalds 	ohci->ed_rm_list = NULL;
9491da177e4SLinus Torvalds 
9501da177e4SLinus Torvalds 	/* empty control and bulk lists */
9511da177e4SLinus Torvalds 	ohci->ed_controltail = NULL;
9521da177e4SLinus Torvalds 	ohci->ed_bulktail    = NULL;
9531da177e4SLinus Torvalds 
9541da177e4SLinus Torvalds 	if ((temp = ohci_run (ohci)) < 0) {
9551da177e4SLinus Torvalds 		ohci_err (ohci, "can't restart, %d\n", temp);
9561da177e4SLinus Torvalds 		return temp;
9571da177e4SLinus Torvalds 	}
958383975d7SAlan Stern 	ohci_dbg(ohci, "restart complete\n");
9591da177e4SLinus Torvalds 	return 0;
9601da177e4SLinus Torvalds }
961d576bb9fSMichael Hanselmann 
962da6fb570SDavid Brownell #endif
963da6fb570SDavid Brownell 
964d576bb9fSMichael Hanselmann /*-------------------------------------------------------------------------*/
965d576bb9fSMichael Hanselmann 
9661da177e4SLinus Torvalds #define DRIVER_INFO DRIVER_VERSION " " DRIVER_DESC
9671da177e4SLinus Torvalds 
9681da177e4SLinus Torvalds MODULE_AUTHOR (DRIVER_AUTHOR);
9691da177e4SLinus Torvalds MODULE_DESCRIPTION (DRIVER_INFO);
9701da177e4SLinus Torvalds MODULE_LICENSE ("GPL");
9711da177e4SLinus Torvalds 
9721da177e4SLinus Torvalds #ifdef CONFIG_PCI
9731da177e4SLinus Torvalds #include "ohci-pci.c"
9745e16fabeSSylvain Munaut #define PCI_DRIVER		ohci_pci_driver
9751da177e4SLinus Torvalds #endif
9761da177e4SLinus Torvalds 
9771da177e4SLinus Torvalds #ifdef CONFIG_SA1111
9781da177e4SLinus Torvalds #include "ohci-sa1111.c"
9795e16fabeSSylvain Munaut #define SA1111_DRIVER		ohci_hcd_sa1111_driver
9801da177e4SLinus Torvalds #endif
9811da177e4SLinus Torvalds 
9823eb0c5f4SBen Dooks #ifdef CONFIG_ARCH_S3C2410
9833eb0c5f4SBen Dooks #include "ohci-s3c2410.c"
9845e16fabeSSylvain Munaut #define PLATFORM_DRIVER		ohci_hcd_s3c2410_driver
9853eb0c5f4SBen Dooks #endif
9863eb0c5f4SBen Dooks 
9871da177e4SLinus Torvalds #ifdef CONFIG_ARCH_OMAP
9881da177e4SLinus Torvalds #include "ohci-omap.c"
9895e16fabeSSylvain Munaut #define PLATFORM_DRIVER		ohci_hcd_omap_driver
9901da177e4SLinus Torvalds #endif
9911da177e4SLinus Torvalds 
9921da177e4SLinus Torvalds #ifdef CONFIG_ARCH_LH7A404
9931da177e4SLinus Torvalds #include "ohci-lh7a404.c"
9945e16fabeSSylvain Munaut #define PLATFORM_DRIVER		ohci_hcd_lh7a404_driver
9951da177e4SLinus Torvalds #endif
9961da177e4SLinus Torvalds 
997e77ec189Seric miao #if defined(CONFIG_PXA27x) || defined(CONFIG_PXA3xx)
9981da177e4SLinus Torvalds #include "ohci-pxa27x.c"
9995e16fabeSSylvain Munaut #define PLATFORM_DRIVER		ohci_hcd_pxa27x_driver
10001da177e4SLinus Torvalds #endif
10011da177e4SLinus Torvalds 
1002a5b7474aSLennert Buytenhek #ifdef CONFIG_ARCH_EP93XX
1003a5b7474aSLennert Buytenhek #include "ohci-ep93xx.c"
10045e16fabeSSylvain Munaut #define PLATFORM_DRIVER		ohci_hcd_ep93xx_driver
1005a5b7474aSLennert Buytenhek #endif
1006a5b7474aSLennert Buytenhek 
10071da177e4SLinus Torvalds #ifdef CONFIG_SOC_AU1X00
10081da177e4SLinus Torvalds #include "ohci-au1xxx.c"
10095e16fabeSSylvain Munaut #define PLATFORM_DRIVER		ohci_hcd_au1xxx_driver
10101da177e4SLinus Torvalds #endif
10111da177e4SLinus Torvalds 
10125151d040SVitaly Wool #ifdef CONFIG_PNX8550
10135151d040SVitaly Wool #include "ohci-pnx8550.c"
10145e16fabeSSylvain Munaut #define PLATFORM_DRIVER		ohci_hcd_pnx8550_driver
10155151d040SVitaly Wool #endif
10165151d040SVitaly Wool 
10171da177e4SLinus Torvalds #ifdef CONFIG_USB_OHCI_HCD_PPC_SOC
10181da177e4SLinus Torvalds #include "ohci-ppc-soc.c"
10195e16fabeSSylvain Munaut #define PLATFORM_DRIVER		ohci_hcd_ppc_soc_driver
10201da177e4SLinus Torvalds #endif
10211da177e4SLinus Torvalds 
102258a0cd78SAndrew Victor #ifdef CONFIG_ARCH_AT91
102339a269c0SAndrew Victor #include "ohci-at91.c"
10245e16fabeSSylvain Munaut #define PLATFORM_DRIVER		ohci_hcd_at91_driver
102539a269c0SAndrew Victor #endif
102639a269c0SAndrew Victor 
102760bbfc84SVitaly Wool #ifdef CONFIG_ARCH_PNX4008
102860bbfc84SVitaly Wool #include "ohci-pnx4008.c"
10295e16fabeSSylvain Munaut #define PLATFORM_DRIVER		usb_hcd_pnx4008_driver
103060bbfc84SVitaly Wool #endif
103160bbfc84SVitaly Wool 
1032*828d55c5SYoshihiro Shimoda #if defined(CONFIG_CPU_SUBTYPE_SH7720) || \
1033*828d55c5SYoshihiro Shimoda     defined(CONFIG_CPU_SUBTYPE_SH7721) || \
1034*828d55c5SYoshihiro Shimoda     defined(CONFIG_CPU_SUBTYPE_SH7763)
1035*828d55c5SYoshihiro Shimoda #include "ohci-sh.c"
1036*828d55c5SYoshihiro Shimoda #define PLATFORM_DRIVER		ohci_hcd_sh_driver
1037*828d55c5SYoshihiro Shimoda #endif
1038*828d55c5SYoshihiro Shimoda 
10395e16fabeSSylvain Munaut 
1040495a678fSSylvain Munaut #ifdef CONFIG_USB_OHCI_HCD_PPC_OF
1041495a678fSSylvain Munaut #include "ohci-ppc-of.c"
1042495a678fSSylvain Munaut #define OF_PLATFORM_DRIVER	ohci_hcd_ppc_of_driver
1043495a678fSSylvain Munaut #endif
1044495a678fSSylvain Munaut 
10456a6c957eSGeoff Levand #ifdef CONFIG_PPC_PS3
10466a6c957eSGeoff Levand #include "ohci-ps3.c"
10477a4eb7fdSGeoff Levand #define PS3_SYSTEM_BUS_DRIVER	ps3_ohci_driver
10486a6c957eSGeoff Levand #endif
10496a6c957eSGeoff Levand 
1050c604e851SMichael Buesch #ifdef CONFIG_USB_OHCI_HCD_SSB
1051c604e851SMichael Buesch #include "ohci-ssb.c"
1052c604e851SMichael Buesch #define SSB_OHCI_DRIVER		ssb_ohci_driver
1053c604e851SMichael Buesch #endif
1054c604e851SMichael Buesch 
10555e16fabeSSylvain Munaut #if	!defined(PCI_DRIVER) &&		\
10565e16fabeSSylvain Munaut 	!defined(PLATFORM_DRIVER) &&	\
1057495a678fSSylvain Munaut 	!defined(OF_PLATFORM_DRIVER) &&	\
10586a6c957eSGeoff Levand 	!defined(SA1111_DRIVER) &&	\
1059c604e851SMichael Buesch 	!defined(PS3_SYSTEM_BUS_DRIVER) && \
1060c604e851SMichael Buesch 	!defined(SSB_OHCI_DRIVER)
10611da177e4SLinus Torvalds #error "missing bus glue for ohci-hcd"
10621da177e4SLinus Torvalds #endif
10635e16fabeSSylvain Munaut 
10645e16fabeSSylvain Munaut static int __init ohci_hcd_mod_init(void)
10655e16fabeSSylvain Munaut {
10665e16fabeSSylvain Munaut 	int retval = 0;
10675e16fabeSSylvain Munaut 
10685e16fabeSSylvain Munaut 	if (usb_disabled())
10695e16fabeSSylvain Munaut 		return -ENODEV;
10705e16fabeSSylvain Munaut 
10715e16fabeSSylvain Munaut 	printk (KERN_DEBUG "%s: " DRIVER_INFO "\n", hcd_name);
10725e16fabeSSylvain Munaut 	pr_debug ("%s: block sizes: ed %Zd td %Zd\n", hcd_name,
10735e16fabeSSylvain Munaut 		sizeof (struct ed), sizeof (struct td));
10745e16fabeSSylvain Munaut 
1075684c19e0STony Jones #ifdef DEBUG
1076684c19e0STony Jones 	ohci_debug_root = debugfs_create_dir("ohci", NULL);
1077684c19e0STony Jones 	if (!ohci_debug_root) {
1078684c19e0STony Jones 		retval = -ENOENT;
1079684c19e0STony Jones 		goto error_debug;
1080684c19e0STony Jones 	}
1081684c19e0STony Jones #endif
1082684c19e0STony Jones 
10836a6c957eSGeoff Levand #ifdef PS3_SYSTEM_BUS_DRIVER
10847a4eb7fdSGeoff Levand 	retval = ps3_ohci_driver_register(&PS3_SYSTEM_BUS_DRIVER);
10856a6c957eSGeoff Levand 	if (retval < 0)
10866a6c957eSGeoff Levand 		goto error_ps3;
10876a6c957eSGeoff Levand #endif
10886a6c957eSGeoff Levand 
10895e16fabeSSylvain Munaut #ifdef PLATFORM_DRIVER
10905e16fabeSSylvain Munaut 	retval = platform_driver_register(&PLATFORM_DRIVER);
10915e16fabeSSylvain Munaut 	if (retval < 0)
1092de44743bSBenjamin Herrenschmidt 		goto error_platform;
10935e16fabeSSylvain Munaut #endif
10945e16fabeSSylvain Munaut 
1095495a678fSSylvain Munaut #ifdef OF_PLATFORM_DRIVER
1096495a678fSSylvain Munaut 	retval = of_register_platform_driver(&OF_PLATFORM_DRIVER);
1097495a678fSSylvain Munaut 	if (retval < 0)
1098de44743bSBenjamin Herrenschmidt 		goto error_of_platform;
1099495a678fSSylvain Munaut #endif
1100495a678fSSylvain Munaut 
11015e16fabeSSylvain Munaut #ifdef SA1111_DRIVER
11025e16fabeSSylvain Munaut 	retval = sa1111_driver_register(&SA1111_DRIVER);
11035e16fabeSSylvain Munaut 	if (retval < 0)
1104de44743bSBenjamin Herrenschmidt 		goto error_sa1111;
11055e16fabeSSylvain Munaut #endif
11065e16fabeSSylvain Munaut 
11075e16fabeSSylvain Munaut #ifdef PCI_DRIVER
11085e16fabeSSylvain Munaut 	retval = pci_register_driver(&PCI_DRIVER);
11095e16fabeSSylvain Munaut 	if (retval < 0)
1110de44743bSBenjamin Herrenschmidt 		goto error_pci;
11115e16fabeSSylvain Munaut #endif
11125e16fabeSSylvain Munaut 
1113c604e851SMichael Buesch #ifdef SSB_OHCI_DRIVER
1114c604e851SMichael Buesch 	retval = ssb_driver_register(&SSB_OHCI_DRIVER);
1115c604e851SMichael Buesch 	if (retval)
1116c604e851SMichael Buesch 		goto error_ssb;
1117c604e851SMichael Buesch #endif
1118c604e851SMichael Buesch 
11195e16fabeSSylvain Munaut 	return retval;
11205e16fabeSSylvain Munaut 
11215e16fabeSSylvain Munaut 	/* Error path */
1122c604e851SMichael Buesch #ifdef SSB_OHCI_DRIVER
1123c604e851SMichael Buesch  error_ssb:
1124c604e851SMichael Buesch #endif
1125de44743bSBenjamin Herrenschmidt #ifdef PCI_DRIVER
1126c604e851SMichael Buesch 	pci_unregister_driver(&PCI_DRIVER);
1127de44743bSBenjamin Herrenschmidt  error_pci:
1128495a678fSSylvain Munaut #endif
11295e16fabeSSylvain Munaut #ifdef SA1111_DRIVER
11305e16fabeSSylvain Munaut 	sa1111_driver_unregister(&SA1111_DRIVER);
1131de44743bSBenjamin Herrenschmidt  error_sa1111:
1132de44743bSBenjamin Herrenschmidt #endif
1133de44743bSBenjamin Herrenschmidt #ifdef OF_PLATFORM_DRIVER
1134de44743bSBenjamin Herrenschmidt 	of_unregister_platform_driver(&OF_PLATFORM_DRIVER);
1135de44743bSBenjamin Herrenschmidt  error_of_platform:
1136de44743bSBenjamin Herrenschmidt #endif
1137de44743bSBenjamin Herrenschmidt #ifdef PLATFORM_DRIVER
1138de44743bSBenjamin Herrenschmidt 	platform_driver_unregister(&PLATFORM_DRIVER);
1139de44743bSBenjamin Herrenschmidt  error_platform:
11405e16fabeSSylvain Munaut #endif
11416a6c957eSGeoff Levand #ifdef PS3_SYSTEM_BUS_DRIVER
11427a4eb7fdSGeoff Levand 	ps3_ohci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);
11436a6c957eSGeoff Levand  error_ps3:
11446a6c957eSGeoff Levand #endif
1145684c19e0STony Jones #ifdef DEBUG
1146684c19e0STony Jones 	debugfs_remove(ohci_debug_root);
1147684c19e0STony Jones 	ohci_debug_root = NULL;
1148684c19e0STony Jones  error_debug:
1149684c19e0STony Jones #endif
1150684c19e0STony Jones 
11515e16fabeSSylvain Munaut 	return retval;
11525e16fabeSSylvain Munaut }
11535e16fabeSSylvain Munaut module_init(ohci_hcd_mod_init);
11545e16fabeSSylvain Munaut 
11555e16fabeSSylvain Munaut static void __exit ohci_hcd_mod_exit(void)
11565e16fabeSSylvain Munaut {
1157c604e851SMichael Buesch #ifdef SSB_OHCI_DRIVER
1158c604e851SMichael Buesch 	ssb_driver_unregister(&SSB_OHCI_DRIVER);
1159c604e851SMichael Buesch #endif
11605e16fabeSSylvain Munaut #ifdef PCI_DRIVER
11615e16fabeSSylvain Munaut 	pci_unregister_driver(&PCI_DRIVER);
11625e16fabeSSylvain Munaut #endif
11635e16fabeSSylvain Munaut #ifdef SA1111_DRIVER
11645e16fabeSSylvain Munaut 	sa1111_driver_unregister(&SA1111_DRIVER);
11655e16fabeSSylvain Munaut #endif
1166495a678fSSylvain Munaut #ifdef OF_PLATFORM_DRIVER
1167495a678fSSylvain Munaut 	of_unregister_platform_driver(&OF_PLATFORM_DRIVER);
1168495a678fSSylvain Munaut #endif
11695e16fabeSSylvain Munaut #ifdef PLATFORM_DRIVER
11705e16fabeSSylvain Munaut 	platform_driver_unregister(&PLATFORM_DRIVER);
11715e16fabeSSylvain Munaut #endif
11726a6c957eSGeoff Levand #ifdef PS3_SYSTEM_BUS_DRIVER
11737a4eb7fdSGeoff Levand 	ps3_ohci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);
11746a6c957eSGeoff Levand #endif
1175684c19e0STony Jones #ifdef DEBUG
1176684c19e0STony Jones 	debugfs_remove(ohci_debug_root);
1177684c19e0STony Jones #endif
11785e16fabeSSylvain Munaut }
11795e16fabeSSylvain Munaut module_exit(ohci_hcd_mod_exit);
11805e16fabeSSylvain Munaut 
1181