xref: /linux/drivers/usb/host/ohci-hcd.c (revision 4232da23d75d173195c6766729e51947b64f83cd)
15fd54aceSGreg Kroah-Hartman // SPDX-License-Identifier: GPL-1.0+
21da177e4SLinus Torvalds /*
3578333abSAlan Stern  * Open Host Controller Interface (OHCI) driver for USB.
4578333abSAlan Stern  *
5578333abSAlan Stern  * Maintainer: Alan Stern <stern@rowland.harvard.edu>
61da177e4SLinus Torvalds  *
71da177e4SLinus Torvalds  * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
81da177e4SLinus Torvalds  * (C) Copyright 2000-2004 David Brownell <dbrownell@users.sourceforge.net>
91da177e4SLinus Torvalds  *
101da177e4SLinus Torvalds  * [ Initialisation is based on Linus'  ]
111da177e4SLinus Torvalds  * [ uhci code and gregs ohci fragments ]
121da177e4SLinus Torvalds  * [ (C) Copyright 1999 Linus Torvalds  ]
131da177e4SLinus Torvalds  * [ (C) Copyright 1999 Gregory P. Smith]
141da177e4SLinus Torvalds  *
151da177e4SLinus Torvalds  *
161da177e4SLinus Torvalds  * OHCI is the main "non-Intel/VIA" standard for USB 1.1 host controller
171da177e4SLinus Torvalds  * interfaces (though some non-x86 Intel chips use it).  It supports
181da177e4SLinus Torvalds  * smarter hardware than UHCI.  A download link for the spec available
19681aa3cfSAlexander A. Klimov  * through the https://www.usb.org website.
201da177e4SLinus Torvalds  *
211da177e4SLinus Torvalds  * This file is licenced under the GPL.
221da177e4SLinus Torvalds  */
231da177e4SLinus Torvalds 
241da177e4SLinus Torvalds #include <linux/module.h>
251da177e4SLinus Torvalds #include <linux/moduleparam.h>
261da177e4SLinus Torvalds #include <linux/pci.h>
271da177e4SLinus Torvalds #include <linux/kernel.h>
281da177e4SLinus Torvalds #include <linux/delay.h>
291da177e4SLinus Torvalds #include <linux/ioport.h>
301da177e4SLinus Torvalds #include <linux/sched.h>
311da177e4SLinus Torvalds #include <linux/slab.h>
321da177e4SLinus Torvalds #include <linux/errno.h>
331da177e4SLinus Torvalds #include <linux/init.h>
341da177e4SLinus Torvalds #include <linux/timer.h>
351da177e4SLinus Torvalds #include <linux/list.h>
361da177e4SLinus Torvalds #include <linux/usb.h>
373a16f7b4SDavid Brownell #include <linux/usb/otg.h>
3827729aadSEric Lescouet #include <linux/usb/hcd.h>
391da177e4SLinus Torvalds #include <linux/dma-mapping.h>
40f4df0e33SDavid Brownell #include <linux/dmapool.h>
41d576bb9fSMichael Hanselmann #include <linux/workqueue.h>
42684c19e0STony Jones #include <linux/debugfs.h>
43b0310c2fSLaurentiu Tudor #include <linux/genalloc.h>
441da177e4SLinus Torvalds 
451da177e4SLinus Torvalds #include <asm/io.h>
461da177e4SLinus Torvalds #include <asm/irq.h>
471da177e4SLinus Torvalds #include <asm/unaligned.h>
481da177e4SLinus Torvalds #include <asm/byteorder.h>
491da177e4SLinus Torvalds 
501da177e4SLinus Torvalds 
511da177e4SLinus Torvalds #define DRIVER_AUTHOR "Roman Weissgaerber, David Brownell"
521da177e4SLinus Torvalds #define DRIVER_DESC "USB 1.1 'Open' Host Controller (OHCI) Driver"
531da177e4SLinus Torvalds 
541da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/
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)
77ed6d6f8fSBryan Paluch #define	IO_WATCHDOG_DELAY	msecs_to_jiffies(275)
78b2685bdaSShigeru Yoshida #define	IO_WATCHDOG_OFF		0xffffff00
79d413984aSDavid Brownell 
801da177e4SLinus Torvalds #include "ohci.h"
81ad93562bSAndiry Xu #include "pci-quirks.h"
821da177e4SLinus Torvalds 
83256dbcd8SAlan Stern static void ohci_dump(struct ohci_hcd *ohci);
841da177e4SLinus Torvalds static void ohci_stop(struct usb_hcd *hcd);
85e99e88a9SKees Cook static void io_watchdog_func(struct timer_list *t);
86ab1666c1SLibin Yang 
871da177e4SLinus Torvalds #include "ohci-hub.c"
881da177e4SLinus Torvalds #include "ohci-dbg.c"
891da177e4SLinus Torvalds #include "ohci-mem.c"
901da177e4SLinus Torvalds #include "ohci-q.c"
911da177e4SLinus Torvalds 
921da177e4SLinus Torvalds 
931da177e4SLinus Torvalds /*
941da177e4SLinus Torvalds  * On architectures with edge-triggered interrupts we must never return
951da177e4SLinus Torvalds  * IRQ_NONE.
961da177e4SLinus Torvalds  */
971da177e4SLinus Torvalds #if defined(CONFIG_SA1111)  /* ... or other edge-triggered systems */
981da177e4SLinus Torvalds #define IRQ_NOTMINE	IRQ_HANDLED
991da177e4SLinus Torvalds #else
1001da177e4SLinus Torvalds #define IRQ_NOTMINE	IRQ_NONE
1011da177e4SLinus Torvalds #endif
1021da177e4SLinus Torvalds 
1031da177e4SLinus Torvalds 
1041da177e4SLinus Torvalds /* Some boards misreport power switching/overcurrent */
105c4005a8fSHamish Martin static bool distrust_firmware;
1061da177e4SLinus Torvalds module_param (distrust_firmware, bool, 0);
1071da177e4SLinus Torvalds MODULE_PARM_DESC (distrust_firmware,
1081da177e4SLinus Torvalds 	"true to distrust firmware power/overcurrent setup");
1091da177e4SLinus Torvalds 
1101da177e4SLinus Torvalds /* Some boards leave IR set wrongly, since they fail BIOS/SMM handshakes */
111900937c0SGeyslan G. Bem static bool no_handshake;
1121da177e4SLinus Torvalds module_param (no_handshake, bool, 0);
1131da177e4SLinus Torvalds MODULE_PARM_DESC (no_handshake, "true (not default) disables BIOS handshake");
1141da177e4SLinus Torvalds 
1151da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/
1161da177e4SLinus Torvalds 
number_of_tds(struct urb * urb)1176f65126cSAlan Stern static int number_of_tds(struct urb *urb)
1186f65126cSAlan Stern {
1196f65126cSAlan Stern 	int			len, i, num, this_sg_len;
1206f65126cSAlan Stern 	struct scatterlist	*sg;
1216f65126cSAlan Stern 
1226f65126cSAlan Stern 	len = urb->transfer_buffer_length;
1236f65126cSAlan Stern 	i = urb->num_mapped_sgs;
1246f65126cSAlan Stern 
1256f65126cSAlan Stern 	if (len > 0 && i > 0) {		/* Scatter-gather transfer */
1266f65126cSAlan Stern 		num = 0;
1276f65126cSAlan Stern 		sg = urb->sg;
1286f65126cSAlan Stern 		for (;;) {
1296f65126cSAlan Stern 			this_sg_len = min_t(int, sg_dma_len(sg), len);
1306f65126cSAlan Stern 			num += DIV_ROUND_UP(this_sg_len, 4096);
1316f65126cSAlan Stern 			len -= this_sg_len;
1326f65126cSAlan Stern 			if (--i <= 0 || len <= 0)
1336f65126cSAlan Stern 				break;
1346f65126cSAlan Stern 			sg = sg_next(sg);
1356f65126cSAlan Stern 		}
1366f65126cSAlan Stern 
1376f65126cSAlan Stern 	} else {			/* Non-SG transfer */
1386f65126cSAlan Stern 		/* one TD for every 4096 Bytes (could be up to 8K) */
1396f65126cSAlan Stern 		num = DIV_ROUND_UP(len, 4096);
1406f65126cSAlan Stern 	}
1416f65126cSAlan Stern 	return num;
1426f65126cSAlan Stern }
1436f65126cSAlan Stern 
1441da177e4SLinus Torvalds /*
1451da177e4SLinus Torvalds  * queue up an urb for anything except the root hub
1461da177e4SLinus Torvalds  */
ohci_urb_enqueue(struct usb_hcd * hcd,struct urb * urb,gfp_t mem_flags)1471da177e4SLinus Torvalds static int ohci_urb_enqueue (
1481da177e4SLinus Torvalds 	struct usb_hcd	*hcd,
1491da177e4SLinus Torvalds 	struct urb	*urb,
15055016f10SAl Viro 	gfp_t		mem_flags
1511da177e4SLinus Torvalds ) {
1521da177e4SLinus Torvalds 	struct ohci_hcd	*ohci = hcd_to_ohci (hcd);
1531da177e4SLinus Torvalds 	struct ed	*ed;
1541da177e4SLinus Torvalds 	urb_priv_t	*urb_priv;
1551da177e4SLinus Torvalds 	unsigned int	pipe = urb->pipe;
1561da177e4SLinus Torvalds 	int		i, size = 0;
1571da177e4SLinus Torvalds 	unsigned long	flags;
1581da177e4SLinus Torvalds 	int		retval = 0;
1591da177e4SLinus Torvalds 
1601da177e4SLinus Torvalds 	/* every endpoint has a ed, locate and maybe (re)initialize it */
16171f46340SGreg Kroah-Hartman 	ed = ed_get(ohci, urb->ep, urb->dev, pipe, urb->interval);
16271f46340SGreg Kroah-Hartman 	if (! ed)
1631da177e4SLinus Torvalds 		return -ENOMEM;
1641da177e4SLinus Torvalds 
1651da177e4SLinus Torvalds 	/* for the private part of the URB we need the number of TDs (size) */
1661da177e4SLinus Torvalds 	switch (ed->type) {
1671da177e4SLinus Torvalds 		case PIPE_CONTROL:
1681da177e4SLinus Torvalds 			/* td_submit_urb() doesn't yet handle these */
1691da177e4SLinus Torvalds 			if (urb->transfer_buffer_length > 4096)
1701da177e4SLinus Torvalds 				return -EMSGSIZE;
1711da177e4SLinus Torvalds 
1721da177e4SLinus Torvalds 			/* 1 TD for setup, 1 for ACK, plus ... */
1731da177e4SLinus Torvalds 			size = 2;
1741d6903a6SNick Desaulniers 			fallthrough;
1751da177e4SLinus Torvalds 		// case PIPE_INTERRUPT:
1761da177e4SLinus Torvalds 		// case PIPE_BULK:
1771da177e4SLinus Torvalds 		default:
1786f65126cSAlan Stern 			size += number_of_tds(urb);
1796f65126cSAlan Stern 			/* maybe a zero-length packet to wrap it up */
1801da177e4SLinus Torvalds 			if (size == 0)
1811da177e4SLinus Torvalds 				size++;
1821da177e4SLinus Torvalds 			else if ((urb->transfer_flags & URB_ZERO_PACKET) != 0
1831da177e4SLinus Torvalds 				&& (urb->transfer_buffer_length
184dcd2e49bSVincent Mailhol 					% usb_maxpacket(urb->dev, pipe)) == 0)
1851da177e4SLinus Torvalds 				size++;
1861da177e4SLinus Torvalds 			break;
1871da177e4SLinus Torvalds 		case PIPE_ISOCHRONOUS: /* number of packets from URB */
1881da177e4SLinus Torvalds 			size = urb->number_of_packets;
1891da177e4SLinus Torvalds 			break;
1901da177e4SLinus Torvalds 	}
1911da177e4SLinus Torvalds 
1921da177e4SLinus Torvalds 	/* allocate the private part of the URB */
1936943ee7cSLen Baker 	urb_priv = kzalloc(struct_size(urb_priv, td, size), mem_flags);
1941da177e4SLinus Torvalds 	if (!urb_priv)
1951da177e4SLinus Torvalds 		return -ENOMEM;
1961da177e4SLinus Torvalds 	INIT_LIST_HEAD (&urb_priv->pending);
1971da177e4SLinus Torvalds 	urb_priv->length = size;
1981da177e4SLinus Torvalds 	urb_priv->ed = ed;
1991da177e4SLinus Torvalds 
2001da177e4SLinus Torvalds 	/* allocate the TDs (deferring hash chain updates) */
2011da177e4SLinus Torvalds 	for (i = 0; i < size; i++) {
2021da177e4SLinus Torvalds 		urb_priv->td [i] = td_alloc (ohci, mem_flags);
2031da177e4SLinus Torvalds 		if (!urb_priv->td [i]) {
2041da177e4SLinus Torvalds 			urb_priv->length = i;
2051da177e4SLinus Torvalds 			urb_free_priv (ohci, urb_priv);
2061da177e4SLinus Torvalds 			return -ENOMEM;
2071da177e4SLinus Torvalds 		}
2081da177e4SLinus Torvalds 	}
2091da177e4SLinus Torvalds 
2101da177e4SLinus Torvalds 	spin_lock_irqsave (&ohci->lock, flags);
2111da177e4SLinus Torvalds 
2121da177e4SLinus Torvalds 	/* don't submit to a dead HC */
213541c7d43SAlan Stern 	if (!HCD_HW_ACCESSIBLE(hcd)) {
2148de98402SBenjamin Herrenschmidt 		retval = -ENODEV;
2158de98402SBenjamin Herrenschmidt 		goto fail;
2168de98402SBenjamin Herrenschmidt 	}
217b7463c71SAlan Stern 	if (ohci->rh_state != OHCI_RH_RUNNING) {
2181da177e4SLinus Torvalds 		retval = -ENODEV;
2191da177e4SLinus Torvalds 		goto fail;
2201da177e4SLinus Torvalds 	}
221e9df41c5SAlan Stern 	retval = usb_hcd_link_urb_to_ep(hcd, urb);
222e9df41c5SAlan Stern 	if (retval)
2231da177e4SLinus Torvalds 		goto fail;
2241da177e4SLinus Torvalds 
2251da177e4SLinus Torvalds 	/* schedule the ed if needed */
2261da177e4SLinus Torvalds 	if (ed->state == ED_IDLE) {
2271da177e4SLinus Torvalds 		retval = ed_schedule (ohci, ed);
228e9df41c5SAlan Stern 		if (retval < 0) {
229e9df41c5SAlan Stern 			usb_hcd_unlink_urb_from_ep(hcd, urb);
230e9df41c5SAlan Stern 			goto fail;
231e9df41c5SAlan Stern 		}
23281e38333SAlan Stern 
23381e38333SAlan Stern 		/* Start up the I/O watchdog timer, if it's not running */
234b2685bdaSShigeru Yoshida 		if (ohci->prev_frame_no == IO_WATCHDOG_OFF &&
23521a60f6eSGerd Hoffmann 				list_empty(&ohci->eds_in_use) &&
23621a60f6eSGerd Hoffmann 				!(ohci->flags & OHCI_QUIRK_QEMU)) {
237499b3803SAlan Stern 			ohci->prev_frame_no = ohci_frame_no(ohci);
23881e38333SAlan Stern 			mod_timer(&ohci->io_watchdog,
23981e38333SAlan Stern 					jiffies + IO_WATCHDOG_DELAY);
240499b3803SAlan Stern 		}
24181e38333SAlan Stern 		list_add(&ed->in_use_list, &ohci->eds_in_use);
24281e38333SAlan Stern 
2431da177e4SLinus Torvalds 		if (ed->type == PIPE_ISOCHRONOUS) {
2441da177e4SLinus Torvalds 			u16	frame = ohci_frame_no(ohci);
2451da177e4SLinus Torvalds 
2461da177e4SLinus Torvalds 			/* delay a few frames before the first TD */
2471da177e4SLinus Torvalds 			frame += max_t (u16, 8, ed->interval);
2481da177e4SLinus Torvalds 			frame &= ~(ed->interval - 1);
2491da177e4SLinus Torvalds 			frame |= ed->branch;
2501da177e4SLinus Torvalds 			urb->start_frame = frame;
251a8693424SAlan Stern 			ed->last_iso = frame + ed->interval * (size - 1);
2521da177e4SLinus Torvalds 		}
2536a41b4d3SAlan Stern 	} else if (ed->type == PIPE_ISOCHRONOUS) {
254e1944017SAlan Stern 		u16	next = ohci_frame_no(ohci) + 1;
2556a41b4d3SAlan Stern 		u16	frame = ed->last_iso + ed->interval;
256a8693424SAlan Stern 		u16	length = ed->interval * (size - 1);
2576a41b4d3SAlan Stern 
2586a41b4d3SAlan Stern 		/* Behind the scheduling threshold? */
2596a41b4d3SAlan Stern 		if (unlikely(tick_before(frame, next))) {
2606a41b4d3SAlan Stern 
261a8693424SAlan Stern 			/* URB_ISO_ASAP: Round up to the first available slot */
262815fa7b9SAlan Stern 			if (urb->transfer_flags & URB_ISO_ASAP) {
2636a41b4d3SAlan Stern 				frame += (next - frame + ed->interval - 1) &
2646a41b4d3SAlan Stern 						-ed->interval;
2656a41b4d3SAlan Stern 
2666a41b4d3SAlan Stern 			/*
267a8693424SAlan Stern 			 * Not ASAP: Use the next slot in the stream,
268a8693424SAlan Stern 			 * no matter what.
2696a41b4d3SAlan Stern 			 */
270815fa7b9SAlan Stern 			} else {
2716a41b4d3SAlan Stern 				/*
2726a41b4d3SAlan Stern 				 * Some OHCI hardware doesn't handle late TDs
273815fa7b9SAlan Stern 				 * correctly.  After retiring them it proceeds
274815fa7b9SAlan Stern 				 * to the next ED instead of the next TD.
275815fa7b9SAlan Stern 				 * Therefore we have to omit the late TDs
276815fa7b9SAlan Stern 				 * entirely.
2776a41b4d3SAlan Stern 				 */
278815fa7b9SAlan Stern 				urb_priv->td_cnt = DIV_ROUND_UP(
279815fa7b9SAlan Stern 						(u16) (next - frame),
2806a41b4d3SAlan Stern 						ed->interval);
281a8693424SAlan Stern 				if (urb_priv->td_cnt >= urb_priv->length) {
282a8693424SAlan Stern 					++urb_priv->td_cnt;	/* Mark it */
283a8693424SAlan Stern 					ohci_dbg(ohci, "iso underrun %p (%u+%u < %u)\n",
284a8693424SAlan Stern 							urb, frame, length,
285a8693424SAlan Stern 							next);
286a8693424SAlan Stern 				}
2876a41b4d3SAlan Stern 			}
288815fa7b9SAlan Stern 		}
2896a41b4d3SAlan Stern 		urb->start_frame = frame;
290a8693424SAlan Stern 		ed->last_iso = frame + length;
2916a41b4d3SAlan Stern 	}
2921da177e4SLinus Torvalds 
2931da177e4SLinus Torvalds 	/* fill the TDs and link them to the ed; and
2941da177e4SLinus Torvalds 	 * enable that part of the schedule, if needed
2951da177e4SLinus Torvalds 	 * and update count of queued periodic urbs
2961da177e4SLinus Torvalds 	 */
2971da177e4SLinus Torvalds 	urb->hcpriv = urb_priv;
2981da177e4SLinus Torvalds 	td_submit_urb (ohci, urb);
2991da177e4SLinus Torvalds 
3001da177e4SLinus Torvalds fail:
3011da177e4SLinus Torvalds 	if (retval)
3021da177e4SLinus Torvalds 		urb_free_priv (ohci, urb_priv);
3031da177e4SLinus Torvalds 	spin_unlock_irqrestore (&ohci->lock, flags);
3041da177e4SLinus Torvalds 	return retval;
3051da177e4SLinus Torvalds }
3061da177e4SLinus Torvalds 
3071da177e4SLinus Torvalds /*
30855d84968SAlan Stern  * decouple the URB from the HC queues (TDs, urb_priv).
30955d84968SAlan Stern  * reporting is always done
3101da177e4SLinus Torvalds  * asynchronously, and we might be dealing with an urb that's
3111da177e4SLinus Torvalds  * partially transferred, or an ED with other urbs being unlinked.
3121da177e4SLinus Torvalds  */
ohci_urb_dequeue(struct usb_hcd * hcd,struct urb * urb,int status)313e9df41c5SAlan Stern static int ohci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
3141da177e4SLinus Torvalds {
3151da177e4SLinus Torvalds 	struct ohci_hcd		*ohci = hcd_to_ohci (hcd);
3161da177e4SLinus Torvalds 	unsigned long		flags;
317e9df41c5SAlan Stern 	int			rc;
3188b3ab0edSAlan Stern 	urb_priv_t		*urb_priv;
3191da177e4SLinus Torvalds 
3201da177e4SLinus Torvalds 	spin_lock_irqsave (&ohci->lock, flags);
321e9df41c5SAlan Stern 	rc = usb_hcd_check_unlink_urb(hcd, urb, status);
3228b3ab0edSAlan Stern 	if (rc == 0) {
3231da177e4SLinus Torvalds 
3241da177e4SLinus Torvalds 		/* Unless an IRQ completed the unlink while it was being
3251da177e4SLinus Torvalds 		 * handed to us, flag it for unlink and giveback, and force
3261da177e4SLinus Torvalds 		 * some upcoming INTR_SF to call finish_unlinks()
3271da177e4SLinus Torvalds 		 */
3281da177e4SLinus Torvalds 		urb_priv = urb->hcpriv;
3291da177e4SLinus Torvalds 		if (urb_priv->ed->state == ED_OPER)
3301da177e4SLinus Torvalds 			start_ed_unlink(ohci, urb_priv->ed);
3318b3ab0edSAlan Stern 
3328b3ab0edSAlan Stern 		if (ohci->rh_state != OHCI_RH_RUNNING) {
3338b3ab0edSAlan Stern 			/* With HC dead, we can clean up right away */
334cdb4dd15SAlan Stern 			ohci_work(ohci);
3351da177e4SLinus Torvalds 		}
3361da177e4SLinus Torvalds 	}
3371da177e4SLinus Torvalds 	spin_unlock_irqrestore (&ohci->lock, flags);
338e9df41c5SAlan Stern 	return rc;
3391da177e4SLinus Torvalds }
3401da177e4SLinus Torvalds 
3411da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/
3421da177e4SLinus Torvalds 
3431da177e4SLinus Torvalds /* frees config/altsetting state for endpoints,
3441da177e4SLinus Torvalds  * including ED memory, dummy TD, and bulk/intr data toggle
3451da177e4SLinus Torvalds  */
3461da177e4SLinus Torvalds 
3471da177e4SLinus Torvalds static void
ohci_endpoint_disable(struct usb_hcd * hcd,struct usb_host_endpoint * ep)3481da177e4SLinus Torvalds ohci_endpoint_disable (struct usb_hcd *hcd, struct usb_host_endpoint *ep)
3491da177e4SLinus Torvalds {
3501da177e4SLinus Torvalds 	struct ohci_hcd		*ohci = hcd_to_ohci (hcd);
3511da177e4SLinus Torvalds 	unsigned long		flags;
3521da177e4SLinus Torvalds 	struct ed		*ed = ep->hcpriv;
3531da177e4SLinus Torvalds 	unsigned		limit = 1000;
3541da177e4SLinus Torvalds 
3551da177e4SLinus Torvalds 	/* ASSERT:  any requests/urbs are being unlinked */
3561da177e4SLinus Torvalds 	/* ASSERT:  nobody can be submitting urbs for this any more */
3571da177e4SLinus Torvalds 
3581da177e4SLinus Torvalds 	if (!ed)
3591da177e4SLinus Torvalds 		return;
3601da177e4SLinus Torvalds 
3611da177e4SLinus Torvalds rescan:
3621da177e4SLinus Torvalds 	spin_lock_irqsave (&ohci->lock, flags);
3631da177e4SLinus Torvalds 
364b7463c71SAlan Stern 	if (ohci->rh_state != OHCI_RH_RUNNING) {
3651da177e4SLinus Torvalds sanitize:
3661da177e4SLinus Torvalds 		ed->state = ED_IDLE;
367cdb4dd15SAlan Stern 		ohci_work(ohci);
3681da177e4SLinus Torvalds 	}
3691da177e4SLinus Torvalds 
3701da177e4SLinus Torvalds 	switch (ed->state) {
3711da177e4SLinus Torvalds 	case ED_UNLINK:		/* wait for hw to finish? */
3721da177e4SLinus Torvalds 		/* major IRQ delivery trouble loses INTR_SF too... */
3731da177e4SLinus Torvalds 		if (limit-- == 0) {
37489a0fd18SMike Nuss 			ohci_warn(ohci, "ED unlink timeout\n");
3751da177e4SLinus Torvalds 			goto sanitize;
3761da177e4SLinus Torvalds 		}
3771da177e4SLinus Torvalds 		spin_unlock_irqrestore (&ohci->lock, flags);
37822c43863SNishanth Aravamudan 		schedule_timeout_uninterruptible(1);
3791da177e4SLinus Torvalds 		goto rescan;
3801da177e4SLinus Torvalds 	case ED_IDLE:		/* fully unlinked */
3811da177e4SLinus Torvalds 		if (list_empty (&ed->td_list)) {
3821da177e4SLinus Torvalds 			td_free (ohci, ed->dummy);
3831da177e4SLinus Torvalds 			ed_free (ohci, ed);
3841da177e4SLinus Torvalds 			break;
3851da177e4SLinus Torvalds 		}
386e288fc98SGustavo A. R. Silva 		fallthrough;
3871da177e4SLinus Torvalds 	default:
3881da177e4SLinus Torvalds 		/* caller was supposed to have unlinked any requests;
3891da177e4SLinus Torvalds 		 * that's not our job.  can't recover; must leak ed.
3901da177e4SLinus Torvalds 		 */
3911da177e4SLinus Torvalds 		ohci_err (ohci, "leak ed %p (#%02x) state %d%s\n",
3921da177e4SLinus Torvalds 			ed, ep->desc.bEndpointAddress, ed->state,
3931da177e4SLinus Torvalds 			list_empty (&ed->td_list) ? "" : " (has tds)");
3941da177e4SLinus Torvalds 		td_free (ohci, ed->dummy);
3951da177e4SLinus Torvalds 		break;
3961da177e4SLinus Torvalds 	}
3971da177e4SLinus Torvalds 	ep->hcpriv = NULL;
3981da177e4SLinus Torvalds 	spin_unlock_irqrestore (&ohci->lock, flags);
3991da177e4SLinus Torvalds }
4001da177e4SLinus Torvalds 
ohci_get_frame(struct usb_hcd * hcd)4011da177e4SLinus Torvalds static int ohci_get_frame (struct usb_hcd *hcd)
4021da177e4SLinus Torvalds {
4031da177e4SLinus Torvalds 	struct ohci_hcd		*ohci = hcd_to_ohci (hcd);
4041da177e4SLinus Torvalds 
4051da177e4SLinus Torvalds 	return ohci_frame_no(ohci);
4061da177e4SLinus Torvalds }
4071da177e4SLinus Torvalds 
ohci_usb_reset(struct ohci_hcd * ohci)4081da177e4SLinus Torvalds static void ohci_usb_reset (struct ohci_hcd *ohci)
4091da177e4SLinus Torvalds {
4101da177e4SLinus Torvalds 	ohci->hc_control = ohci_readl (ohci, &ohci->regs->control);
4111da177e4SLinus Torvalds 	ohci->hc_control &= OHCI_CTRL_RWC;
4121da177e4SLinus Torvalds 	ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
413b7463c71SAlan Stern 	ohci->rh_state = OHCI_RH_HALTED;
4141da177e4SLinus Torvalds }
4151da177e4SLinus Torvalds 
41664a21d02SAleksey Gorelov /* ohci_shutdown forcibly disables IRQs and DMA, helping kexec and
417f4df0e33SDavid Brownell  * other cases where the next software may expect clean state from the
418f4df0e33SDavid Brownell  * "firmware".  this is bus-neutral, unlike shutdown() methods.
419f4df0e33SDavid Brownell  */
_ohci_shutdown(struct usb_hcd * hcd)420a349b95dSYoshihiro Shimoda static void _ohci_shutdown(struct usb_hcd *hcd)
421f4df0e33SDavid Brownell {
422f4df0e33SDavid Brownell 	struct ohci_hcd *ohci;
423f4df0e33SDavid Brownell 
42464a21d02SAleksey Gorelov 	ohci = hcd_to_ohci (hcd);
425c6187597SAlan Stern 	ohci_writel(ohci, (u32) ~0, &ohci->regs->intrdisable);
4263df7169eSAlan Stern 
427c6187597SAlan Stern 	/* Software reset, after which the controller goes into SUSPEND */
428c6187597SAlan Stern 	ohci_writel(ohci, OHCI_HCR, &ohci->regs->cmdstatus);
429c6187597SAlan Stern 	ohci_readl(ohci, &ohci->regs->cmdstatus);	/* flush the writes */
430c6187597SAlan Stern 	udelay(10);
4313df7169eSAlan Stern 
432c6187597SAlan Stern 	ohci_writel(ohci, ohci->fminterval, &ohci->regs->fminterval);
43381e38333SAlan Stern 	ohci->rh_state = OHCI_RH_HALTED;
434f4df0e33SDavid Brownell }
435f4df0e33SDavid Brownell 
ohci_shutdown(struct usb_hcd * hcd)436a349b95dSYoshihiro Shimoda static void ohci_shutdown(struct usb_hcd *hcd)
437a349b95dSYoshihiro Shimoda {
438a349b95dSYoshihiro Shimoda 	struct ohci_hcd	*ohci = hcd_to_ohci(hcd);
439a349b95dSYoshihiro Shimoda 	unsigned long flags;
440a349b95dSYoshihiro Shimoda 
441a349b95dSYoshihiro Shimoda 	spin_lock_irqsave(&ohci->lock, flags);
442a349b95dSYoshihiro Shimoda 	_ohci_shutdown(hcd);
443a349b95dSYoshihiro Shimoda 	spin_unlock_irqrestore(&ohci->lock, flags);
444a349b95dSYoshihiro Shimoda }
445a349b95dSYoshihiro Shimoda 
4461da177e4SLinus Torvalds /*-------------------------------------------------------------------------*
4471da177e4SLinus Torvalds  * HC functions
4481da177e4SLinus Torvalds  *-------------------------------------------------------------------------*/
4491da177e4SLinus Torvalds 
4501da177e4SLinus Torvalds /* init memory, and kick BIOS/SMM off */
4511da177e4SLinus Torvalds 
ohci_init(struct ohci_hcd * ohci)4521da177e4SLinus Torvalds static int ohci_init (struct ohci_hcd *ohci)
4531da177e4SLinus Torvalds {
4541da177e4SLinus Torvalds 	int ret;
4556a9062f3SDavid Brownell 	struct usb_hcd *hcd = ohci_to_hcd(ohci);
4561da177e4SLinus Torvalds 
4576f65126cSAlan Stern 	/* Accept arbitrarily long scatter-gather lists */
4582d7a3dc3SLaurentiu Tudor 	if (!hcd->localmem_pool)
4596f65126cSAlan Stern 		hcd->self.sg_tablesize = ~0;
4606f65126cSAlan Stern 
4611133cd8aSDmitry Baryshkov 	if (distrust_firmware)
4621133cd8aSDmitry Baryshkov 		ohci->flags |= OHCI_QUIRK_HUB_POWER;
4631133cd8aSDmitry Baryshkov 
464b7463c71SAlan Stern 	ohci->rh_state = OHCI_RH_HALTED;
4656a9062f3SDavid Brownell 	ohci->regs = hcd->regs;
4661da177e4SLinus Torvalds 
4676a9062f3SDavid Brownell 	/* REVISIT this BIOS handshake is now moved into PCI "quirks", and
4686a9062f3SDavid Brownell 	 * was never needed for most non-PCI systems ... remove the code?
4696a9062f3SDavid Brownell 	 */
4706a9062f3SDavid Brownell 
4711da177e4SLinus Torvalds #ifndef IR_DISABLE
4721da177e4SLinus Torvalds 	/* SMM owns the HC?  not for long! */
4731da177e4SLinus Torvalds 	if (!no_handshake && ohci_readl (ohci,
4741da177e4SLinus Torvalds 					&ohci->regs->control) & OHCI_CTRL_IR) {
4751da177e4SLinus Torvalds 		u32 temp;
4761da177e4SLinus Torvalds 
4771da177e4SLinus Torvalds 		ohci_dbg (ohci, "USB HC TakeOver from BIOS/SMM\n");
4781da177e4SLinus Torvalds 
4791da177e4SLinus Torvalds 		/* this timeout is arbitrary.  we make it long, so systems
4801da177e4SLinus Torvalds 		 * depending on usb keyboards may be usable even if the
4811da177e4SLinus Torvalds 		 * BIOS/SMM code seems pretty broken.
4821da177e4SLinus Torvalds 		 */
4831da177e4SLinus Torvalds 		temp = 500;	/* arbitrary: five seconds */
4841da177e4SLinus Torvalds 
4851da177e4SLinus Torvalds 		ohci_writel (ohci, OHCI_INTR_OC, &ohci->regs->intrenable);
4861da177e4SLinus Torvalds 		ohci_writel (ohci, OHCI_OCR, &ohci->regs->cmdstatus);
4871da177e4SLinus Torvalds 		while (ohci_readl (ohci, &ohci->regs->control) & OHCI_CTRL_IR) {
4881da177e4SLinus Torvalds 			msleep (10);
4891da177e4SLinus Torvalds 			if (--temp == 0) {
4901da177e4SLinus Torvalds 				ohci_err (ohci, "USB HC takeover failed!"
4911da177e4SLinus Torvalds 					"  (BIOS/SMM bug)\n");
4921da177e4SLinus Torvalds 				return -EBUSY;
4931da177e4SLinus Torvalds 			}
4941da177e4SLinus Torvalds 		}
4951da177e4SLinus Torvalds 		ohci_usb_reset (ohci);
4961da177e4SLinus Torvalds 	}
4971da177e4SLinus Torvalds #endif
4981da177e4SLinus Torvalds 
4991da177e4SLinus Torvalds 	/* Disable HC interrupts */
5001da177e4SLinus Torvalds 	ohci_writel (ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable);
5016a9062f3SDavid Brownell 
5026a9062f3SDavid Brownell 	/* flush the writes, and save key bits like RWC */
5036a9062f3SDavid Brownell 	if (ohci_readl (ohci, &ohci->regs->control) & OHCI_CTRL_RWC)
5046a9062f3SDavid Brownell 		ohci->hc_control |= OHCI_CTRL_RWC;
5051da177e4SLinus Torvalds 
506fdd13b36SDavid Brownell 	/* Read the number of ports unless overridden */
507fdd13b36SDavid Brownell 	if (ohci->num_ports == 0)
508fdd13b36SDavid Brownell 		ohci->num_ports = roothub_a(ohci) & RH_A_NDP;
509fdd13b36SDavid Brownell 
5101da177e4SLinus Torvalds 	if (ohci->hcca)
5111da177e4SLinus Torvalds 		return 0;
5121da177e4SLinus Torvalds 
513e99e88a9SKees Cook 	timer_setup(&ohci->io_watchdog, io_watchdog_func, 0);
514b2685bdaSShigeru Yoshida 	ohci->prev_frame_no = IO_WATCHDOG_OFF;
51581e38333SAlan Stern 
516b0310c2fSLaurentiu Tudor 	if (hcd->localmem_pool)
517ff2437beSFredrik Noring 		ohci->hcca = gen_pool_dma_alloc_align(hcd->localmem_pool,
518b0310c2fSLaurentiu Tudor 						sizeof(*ohci->hcca),
519ff2437beSFredrik Noring 						&ohci->hcca_dma, 256);
520b0310c2fSLaurentiu Tudor 	else
5216a9062f3SDavid Brownell 		ohci->hcca = dma_alloc_coherent(hcd->self.controller,
522b0310c2fSLaurentiu Tudor 						sizeof(*ohci->hcca),
523b0310c2fSLaurentiu Tudor 						&ohci->hcca_dma,
524b0310c2fSLaurentiu Tudor 						GFP_KERNEL);
5251da177e4SLinus Torvalds 	if (!ohci->hcca)
5261da177e4SLinus Torvalds 		return -ENOMEM;
5271da177e4SLinus Torvalds 
5281da177e4SLinus Torvalds 	if ((ret = ohci_mem_init (ohci)) < 0)
5296a9062f3SDavid Brownell 		ohci_stop (hcd);
5306a9062f3SDavid Brownell 	else {
5316a9062f3SDavid Brownell 		create_debug_files (ohci);
5326a9062f3SDavid Brownell 	}
5331da177e4SLinus Torvalds 
5341da177e4SLinus Torvalds 	return ret;
5351da177e4SLinus Torvalds }
5361da177e4SLinus Torvalds 
5371da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/
5381da177e4SLinus Torvalds 
5391da177e4SLinus Torvalds /* Start an OHCI controller, set the BUS operational
5401da177e4SLinus Torvalds  * resets USB and controller
5411da177e4SLinus Torvalds  * enable interrupts
5421da177e4SLinus Torvalds  */
ohci_run(struct ohci_hcd * ohci)5431da177e4SLinus Torvalds static int ohci_run (struct ohci_hcd *ohci)
5441da177e4SLinus Torvalds {
54596f90a8bSH Hartley Sweeten 	u32			mask, val;
5461da177e4SLinus Torvalds 	int			first = ohci->fminterval == 0;
5476a9062f3SDavid Brownell 	struct usb_hcd		*hcd = ohci_to_hcd(ohci);
5481da177e4SLinus Torvalds 
549b7463c71SAlan Stern 	ohci->rh_state = OHCI_RH_HALTED;
5501da177e4SLinus Torvalds 
5511da177e4SLinus Torvalds 	/* boot firmware should have set this up (5.1.1.3.1) */
5521da177e4SLinus Torvalds 	if (first) {
5531da177e4SLinus Torvalds 
55496f90a8bSH Hartley Sweeten 		val = ohci_readl (ohci, &ohci->regs->fminterval);
55596f90a8bSH Hartley Sweeten 		ohci->fminterval = val & 0x3fff;
5561da177e4SLinus Torvalds 		if (ohci->fminterval != FI)
5571da177e4SLinus Torvalds 			ohci_dbg (ohci, "fminterval delta %d\n",
5581da177e4SLinus Torvalds 				ohci->fminterval - FI);
5591da177e4SLinus Torvalds 		ohci->fminterval |= FSMP (ohci->fminterval) << 16;
5601da177e4SLinus Torvalds 		/* also: power/overcurrent flags in roothub.a */
5611da177e4SLinus Torvalds 	}
5621da177e4SLinus Torvalds 
5636fd9086aSAlan Stern 	/* Reset USB nearly "by the book".  RemoteWakeupConnected has
5646fd9086aSAlan Stern 	 * to be checked in case boot firmware (BIOS/SMM/...) has set up
5656fd9086aSAlan Stern 	 * wakeup in a way the bus isn't aware of (e.g., legacy PCI PM).
5666fd9086aSAlan Stern 	 * If the bus glue detected wakeup capability then it should
567bcca06efSAlan Stern 	 * already be enabled; if so we'll just enable it again.
5681da177e4SLinus Torvalds 	 */
569bcca06efSAlan Stern 	if ((ohci->hc_control & OHCI_CTRL_RWC) != 0)
570bcca06efSAlan Stern 		device_set_wakeup_capable(hcd->self.controller, 1);
5711da177e4SLinus Torvalds 
5721da177e4SLinus Torvalds 	switch (ohci->hc_control & OHCI_CTRL_HCFS) {
5731da177e4SLinus Torvalds 	case OHCI_USB_OPER:
57496f90a8bSH Hartley Sweeten 		val = 0;
5751da177e4SLinus Torvalds 		break;
5761da177e4SLinus Torvalds 	case OHCI_USB_SUSPEND:
5771da177e4SLinus Torvalds 	case OHCI_USB_RESUME:
5781da177e4SLinus Torvalds 		ohci->hc_control &= OHCI_CTRL_RWC;
5791da177e4SLinus Torvalds 		ohci->hc_control |= OHCI_USB_RESUME;
58096f90a8bSH Hartley Sweeten 		val = 10 /* msec wait */;
5811da177e4SLinus Torvalds 		break;
5821da177e4SLinus Torvalds 	// case OHCI_USB_RESET:
5831da177e4SLinus Torvalds 	default:
5841da177e4SLinus Torvalds 		ohci->hc_control &= OHCI_CTRL_RWC;
5851da177e4SLinus Torvalds 		ohci->hc_control |= OHCI_USB_RESET;
58696f90a8bSH Hartley Sweeten 		val = 50 /* msec wait */;
5871da177e4SLinus Torvalds 		break;
5881da177e4SLinus Torvalds 	}
5891da177e4SLinus Torvalds 	ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
5901da177e4SLinus Torvalds 	// flush the writes
5911da177e4SLinus Torvalds 	(void) ohci_readl (ohci, &ohci->regs->control);
59296f90a8bSH Hartley Sweeten 	msleep(val);
593383975d7SAlan Stern 
5941da177e4SLinus Torvalds 	memset (ohci->hcca, 0, sizeof (struct ohci_hcca));
5951da177e4SLinus Torvalds 
5961da177e4SLinus Torvalds 	/* 2msec timelimit here means no irqs/preempt */
5971da177e4SLinus Torvalds 	spin_lock_irq (&ohci->lock);
5981da177e4SLinus Torvalds 
5991da177e4SLinus Torvalds retry:
6001da177e4SLinus Torvalds 	/* HC Reset requires max 10 us delay */
6011da177e4SLinus Torvalds 	ohci_writel (ohci, OHCI_HCR,  &ohci->regs->cmdstatus);
60296f90a8bSH Hartley Sweeten 	val = 30;	/* ... allow extra time */
6031da177e4SLinus Torvalds 	while ((ohci_readl (ohci, &ohci->regs->cmdstatus) & OHCI_HCR) != 0) {
60496f90a8bSH Hartley Sweeten 		if (--val == 0) {
6051da177e4SLinus Torvalds 			spin_unlock_irq (&ohci->lock);
6061da177e4SLinus Torvalds 			ohci_err (ohci, "USB HC reset timed out!\n");
6071da177e4SLinus Torvalds 			return -1;
6081da177e4SLinus Torvalds 		}
6091da177e4SLinus Torvalds 		udelay (1);
6101da177e4SLinus Torvalds 	}
6111da177e4SLinus Torvalds 
6121da177e4SLinus Torvalds 	/* now we're in the SUSPEND state ... must go OPERATIONAL
6131da177e4SLinus Torvalds 	 * within 2msec else HC enters RESUME
6141da177e4SLinus Torvalds 	 *
6151da177e4SLinus Torvalds 	 * ... but some hardware won't init fmInterval "by the book"
6161da177e4SLinus Torvalds 	 * (SiS, OPTi ...), so reset again instead.  SiS doesn't need
6171da177e4SLinus Torvalds 	 * this if we write fmInterval after we're OPERATIONAL.
6181da177e4SLinus Torvalds 	 * Unclear about ALi, ServerWorks, and others ... this could
6191da177e4SLinus Torvalds 	 * easily be a longstanding bug in chip init on Linux.
6201da177e4SLinus Torvalds 	 */
6211da177e4SLinus Torvalds 	if (ohci->flags & OHCI_QUIRK_INITRESET) {
6221da177e4SLinus Torvalds 		ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
6231da177e4SLinus Torvalds 		// flush those writes
6241da177e4SLinus Torvalds 		(void) ohci_readl (ohci, &ohci->regs->control);
6251da177e4SLinus Torvalds 	}
6261da177e4SLinus Torvalds 
6271da177e4SLinus Torvalds 	/* Tell the controller where the control and bulk lists are
6281da177e4SLinus Torvalds 	 * The lists are empty now. */
6291da177e4SLinus Torvalds 	ohci_writel (ohci, 0, &ohci->regs->ed_controlhead);
6301da177e4SLinus Torvalds 	ohci_writel (ohci, 0, &ohci->regs->ed_bulkhead);
6311da177e4SLinus Torvalds 
6321da177e4SLinus Torvalds 	/* a reset clears this */
6331da177e4SLinus Torvalds 	ohci_writel (ohci, (u32) ohci->hcca_dma, &ohci->regs->hcca);
6341da177e4SLinus Torvalds 
6351da177e4SLinus Torvalds 	periodic_reinit (ohci);
6361da177e4SLinus Torvalds 
6371da177e4SLinus Torvalds 	/* some OHCI implementations are finicky about how they init.
6381da177e4SLinus Torvalds 	 * bogus values here mean not even enumeration could work.
6391da177e4SLinus Torvalds 	 */
6401da177e4SLinus Torvalds 	if ((ohci_readl (ohci, &ohci->regs->fminterval) & 0x3fff0000) == 0
6411da177e4SLinus Torvalds 			|| !ohci_readl (ohci, &ohci->regs->periodicstart)) {
6421da177e4SLinus Torvalds 		if (!(ohci->flags & OHCI_QUIRK_INITRESET)) {
6431da177e4SLinus Torvalds 			ohci->flags |= OHCI_QUIRK_INITRESET;
6441da177e4SLinus Torvalds 			ohci_dbg (ohci, "enabling initreset quirk\n");
6451da177e4SLinus Torvalds 			goto retry;
6461da177e4SLinus Torvalds 		}
6471da177e4SLinus Torvalds 		spin_unlock_irq (&ohci->lock);
6481da177e4SLinus Torvalds 		ohci_err (ohci, "init err (%08x %04x)\n",
6491da177e4SLinus Torvalds 			ohci_readl (ohci, &ohci->regs->fminterval),
6501da177e4SLinus Torvalds 			ohci_readl (ohci, &ohci->regs->periodicstart));
6511da177e4SLinus Torvalds 		return -EOVERFLOW;
6521da177e4SLinus Torvalds 	}
6531da177e4SLinus Torvalds 
65437ebb549SPetr Mladek 	/* use rhsc irqs after hub_wq is allocated */
655541c7d43SAlan Stern 	set_bit(HCD_FLAG_POLL_RH, &hcd->flags);
656d413984aSDavid Brownell 	hcd->uses_new_polling = 1;
657d413984aSDavid Brownell 
6581da177e4SLinus Torvalds 	/* start controller operations */
6591da177e4SLinus Torvalds 	ohci->hc_control &= OHCI_CTRL_RWC;
6601da177e4SLinus Torvalds 	ohci->hc_control |= OHCI_CONTROL_INIT | OHCI_USB_OPER;
6611da177e4SLinus Torvalds 	ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
662b7463c71SAlan Stern 	ohci->rh_state = OHCI_RH_RUNNING;
6631da177e4SLinus Torvalds 
6641da177e4SLinus Torvalds 	/* wake on ConnectStatusChange, matching external hubs */
6651da177e4SLinus Torvalds 	ohci_writel (ohci, RH_HS_DRWE, &ohci->regs->roothub.status);
6661da177e4SLinus Torvalds 
6671da177e4SLinus Torvalds 	/* Choose the interrupts we care about now, others later on demand */
6681da177e4SLinus Torvalds 	mask = OHCI_INTR_INIT;
669d413984aSDavid Brownell 	ohci_writel (ohci, ~0, &ohci->regs->intrstatus);
6701da177e4SLinus Torvalds 	ohci_writel (ohci, mask, &ohci->regs->intrenable);
6711da177e4SLinus Torvalds 
6721da177e4SLinus Torvalds 	/* handle root hub init quirks ... */
67396f90a8bSH Hartley Sweeten 	val = roothub_a (ohci);
674b77d2a0aSHamish Martin 	/* Configure for per-port over-current protection by default */
675b77d2a0aSHamish Martin 	val &= ~RH_A_NOCP;
676b77d2a0aSHamish Martin 	val |= RH_A_OCPM;
6771da177e4SLinus Torvalds 	if (ohci->flags & OHCI_QUIRK_SUPERIO) {
678b77d2a0aSHamish Martin 		/* NSC 87560 and maybe others.
679b77d2a0aSHamish Martin 		 * Ganged power switching, no over-current protection.
680b77d2a0aSHamish Martin 		 */
68196f90a8bSH Hartley Sweeten 		val |= RH_A_NOCP;
682b77d2a0aSHamish Martin 		val &= ~(RH_A_POTPGT | RH_A_NPS | RH_A_PSM | RH_A_OCPM);
6831133cd8aSDmitry Baryshkov 	} else if ((ohci->flags & OHCI_QUIRK_AMD756) ||
6841133cd8aSDmitry Baryshkov 			(ohci->flags & OHCI_QUIRK_HUB_POWER)) {
6851da177e4SLinus Torvalds 		/* hub power always on; required for AMD-756 and some
686b77d2a0aSHamish Martin 		 * Mac platforms.
6871da177e4SLinus Torvalds 		 */
68896f90a8bSH Hartley Sweeten 		val |= RH_A_NPS;
6891da177e4SLinus Torvalds 	}
690b77d2a0aSHamish Martin 	ohci_writel(ohci, val, &ohci->regs->roothub.a);
691b77d2a0aSHamish Martin 
6921da177e4SLinus Torvalds 	ohci_writel (ohci, RH_HS_LPSC, &ohci->regs->roothub.status);
69396f90a8bSH Hartley Sweeten 	ohci_writel (ohci, (val & RH_A_NPS) ? 0 : RH_B_PPCM,
6941da177e4SLinus Torvalds 						&ohci->regs->roothub.b);
6951da177e4SLinus Torvalds 	// flush those writes
6961da177e4SLinus Torvalds 	(void) ohci_readl (ohci, &ohci->regs->control);
6971da177e4SLinus Torvalds 
698d413984aSDavid Brownell 	ohci->next_statechange = jiffies + STATECHANGE_DELAY;
6991da177e4SLinus Torvalds 	spin_unlock_irq (&ohci->lock);
7001da177e4SLinus Torvalds 
7011da177e4SLinus Torvalds 	// POTPGT delay is bits 24-31, in 2 ms units.
70296f90a8bSH Hartley Sweeten 	mdelay ((val >> 23) & 0x1fe);
7031da177e4SLinus Torvalds 
704256dbcd8SAlan Stern 	ohci_dump(ohci);
7051da177e4SLinus Torvalds 
7061da177e4SLinus Torvalds 	return 0;
7071da177e4SLinus Torvalds }
7081da177e4SLinus Torvalds 
70995e44d44SManjunath Goudar /* ohci_setup routine for generic controller initialization */
71095e44d44SManjunath Goudar 
ohci_setup(struct usb_hcd * hcd)71195e44d44SManjunath Goudar int ohci_setup(struct usb_hcd *hcd)
71295e44d44SManjunath Goudar {
71395e44d44SManjunath Goudar 	struct ohci_hcd		*ohci = hcd_to_ohci(hcd);
71495e44d44SManjunath Goudar 
71595e44d44SManjunath Goudar 	ohci_hcd_init(ohci);
71695e44d44SManjunath Goudar 
71795e44d44SManjunath Goudar 	return ohci_init(ohci);
71895e44d44SManjunath Goudar }
71995e44d44SManjunath Goudar EXPORT_SYMBOL_GPL(ohci_setup);
72095e44d44SManjunath Goudar 
72195e44d44SManjunath Goudar /* ohci_start routine for generic controller start of all OHCI bus glue */
ohci_start(struct usb_hcd * hcd)72295e44d44SManjunath Goudar static int ohci_start(struct usb_hcd *hcd)
72395e44d44SManjunath Goudar {
72495e44d44SManjunath Goudar 	struct ohci_hcd		*ohci = hcd_to_ohci(hcd);
72595e44d44SManjunath Goudar 	int	ret;
72695e44d44SManjunath Goudar 
72795e44d44SManjunath Goudar 	ret = ohci_run(ohci);
72895e44d44SManjunath Goudar 	if (ret < 0) {
72995e44d44SManjunath Goudar 		ohci_err(ohci, "can't start\n");
73095e44d44SManjunath Goudar 		ohci_stop(hcd);
73195e44d44SManjunath Goudar 	}
73295e44d44SManjunath Goudar 	return ret;
73395e44d44SManjunath Goudar }
73495e44d44SManjunath Goudar 
7351da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/
7361da177e4SLinus Torvalds 
73781e38333SAlan Stern /*
73881e38333SAlan Stern  * Some OHCI controllers are known to lose track of completed TDs.  They
73981e38333SAlan Stern  * don't add the TDs to the hardware done queue, which means we never see
74081e38333SAlan Stern  * them as being completed.
74181e38333SAlan Stern  *
74281e38333SAlan Stern  * This watchdog routine checks for such problems.  Without some way to
74381e38333SAlan Stern  * tell when those TDs have completed, we would never take their EDs off
74481e38333SAlan Stern  * the unlink list.  As a result, URBs could never be dequeued and
74581e38333SAlan Stern  * endpoints could never be released.
74681e38333SAlan Stern  */
io_watchdog_func(struct timer_list * t)747e99e88a9SKees Cook static void io_watchdog_func(struct timer_list *t)
74881e38333SAlan Stern {
749e99e88a9SKees Cook 	struct ohci_hcd	*ohci = from_timer(ohci, t, io_watchdog);
75081e38333SAlan Stern 	bool		takeback_all_pending = false;
75181e38333SAlan Stern 	u32		status;
75281e38333SAlan Stern 	u32		head;
75381e38333SAlan Stern 	struct ed	*ed;
75481e38333SAlan Stern 	struct td	*td, *td_start, *td_next;
755b2685bdaSShigeru Yoshida 	unsigned	frame_no, prev_frame_no = IO_WATCHDOG_OFF;
75681e38333SAlan Stern 	unsigned long	flags;
75781e38333SAlan Stern 
75881e38333SAlan Stern 	spin_lock_irqsave(&ohci->lock, flags);
75981e38333SAlan Stern 
76081e38333SAlan Stern 	/*
76181e38333SAlan Stern 	 * One way to lose track of completed TDs is if the controller
76281e38333SAlan Stern 	 * never writes back the done queue head.  If it hasn't been
76381e38333SAlan Stern 	 * written back since the last time this function ran and if it
76481e38333SAlan Stern 	 * was non-empty at that time, something is badly wrong with the
76581e38333SAlan Stern 	 * hardware.
76681e38333SAlan Stern 	 */
76781e38333SAlan Stern 	status = ohci_readl(ohci, &ohci->regs->intrstatus);
76881e38333SAlan Stern 	if (!(status & OHCI_INTR_WDH) && ohci->wdh_cnt == ohci->prev_wdh_cnt) {
76981e38333SAlan Stern 		if (ohci->prev_donehead) {
77081e38333SAlan Stern 			ohci_err(ohci, "HcDoneHead not written back; disabled\n");
771499b3803SAlan Stern  died:
77281e38333SAlan Stern 			usb_hc_died(ohci_to_hcd(ohci));
77381e38333SAlan Stern 			ohci_dump(ohci);
774a349b95dSYoshihiro Shimoda 			_ohci_shutdown(ohci_to_hcd(ohci));
77581e38333SAlan Stern 			goto done;
77681e38333SAlan Stern 		} else {
77781e38333SAlan Stern 			/* No write back because the done queue was empty */
77881e38333SAlan Stern 			takeback_all_pending = true;
77981e38333SAlan Stern 		}
78081e38333SAlan Stern 	}
78181e38333SAlan Stern 
78281e38333SAlan Stern 	/* Check every ED which might have pending TDs */
78381e38333SAlan Stern 	list_for_each_entry(ed, &ohci->eds_in_use, in_use_list) {
78481e38333SAlan Stern 		if (ed->pending_td) {
78581e38333SAlan Stern 			if (takeback_all_pending ||
78681e38333SAlan Stern 					OKAY_TO_TAKEBACK(ohci, ed)) {
78781e38333SAlan Stern 				unsigned tmp = hc32_to_cpu(ohci, ed->hwINFO);
78881e38333SAlan Stern 
78981e38333SAlan Stern 				ohci_dbg(ohci, "takeback pending TD for dev %d ep 0x%x\n",
79081e38333SAlan Stern 						0x007f & tmp,
79181e38333SAlan Stern 						(0x000f & (tmp >> 7)) +
79281e38333SAlan Stern 							((tmp & ED_IN) >> 5));
79381e38333SAlan Stern 				add_to_done_list(ohci, ed->pending_td);
79481e38333SAlan Stern 			}
79581e38333SAlan Stern 		}
79681e38333SAlan Stern 
79781e38333SAlan Stern 		/* Starting from the latest pending TD, */
79881e38333SAlan Stern 		td = ed->pending_td;
79981e38333SAlan Stern 
80081e38333SAlan Stern 		/* or the last TD on the done list, */
80181e38333SAlan Stern 		if (!td) {
80281e38333SAlan Stern 			list_for_each_entry(td_next, &ed->td_list, td_list) {
80381e38333SAlan Stern 				if (!td_next->next_dl_td)
80481e38333SAlan Stern 					break;
80581e38333SAlan Stern 				td = td_next;
80681e38333SAlan Stern 			}
80781e38333SAlan Stern 		}
80881e38333SAlan Stern 
80981e38333SAlan Stern 		/* find the last TD processed by the controller. */
8106aa7de05SMark Rutland 		head = hc32_to_cpu(ohci, READ_ONCE(ed->hwHeadP)) & TD_MASK;
81181e38333SAlan Stern 		td_start = td;
81281e38333SAlan Stern 		td_next = list_prepare_entry(td, &ed->td_list, td_list);
81381e38333SAlan Stern 		list_for_each_entry_continue(td_next, &ed->td_list, td_list) {
81481e38333SAlan Stern 			if (head == (u32) td_next->td_dma)
81581e38333SAlan Stern 				break;
81681e38333SAlan Stern 			td = td_next;	/* head pointer has passed this TD */
81781e38333SAlan Stern 		}
81881e38333SAlan Stern 		if (td != td_start) {
81981e38333SAlan Stern 			/*
82081e38333SAlan Stern 			 * In case a WDH cycle is in progress, we will wait
82181e38333SAlan Stern 			 * for the next two cycles to complete before assuming
82281e38333SAlan Stern 			 * this TD will never get on the done queue.
82381e38333SAlan Stern 			 */
82481e38333SAlan Stern 			ed->takeback_wdh_cnt = ohci->wdh_cnt + 2;
82581e38333SAlan Stern 			ed->pending_td = td;
82681e38333SAlan Stern 		}
82781e38333SAlan Stern 	}
82881e38333SAlan Stern 
82981e38333SAlan Stern 	ohci_work(ohci);
83081e38333SAlan Stern 
83181e38333SAlan Stern 	if (ohci->rh_state == OHCI_RH_RUNNING) {
832499b3803SAlan Stern 
833499b3803SAlan Stern 		/*
834499b3803SAlan Stern 		 * Sometimes a controller just stops working.  We can tell
835499b3803SAlan Stern 		 * by checking that the frame counter has advanced since
836499b3803SAlan Stern 		 * the last time we ran.
837499b3803SAlan Stern 		 *
838499b3803SAlan Stern 		 * But be careful: Some controllers violate the spec by
839499b3803SAlan Stern 		 * stopping their frame counter when no ports are active.
840499b3803SAlan Stern 		 */
841499b3803SAlan Stern 		frame_no = ohci_frame_no(ohci);
842499b3803SAlan Stern 		if (frame_no == ohci->prev_frame_no) {
843499b3803SAlan Stern 			int		active_cnt = 0;
844499b3803SAlan Stern 			int		i;
845499b3803SAlan Stern 			unsigned	tmp;
846499b3803SAlan Stern 
847499b3803SAlan Stern 			for (i = 0; i < ohci->num_ports; ++i) {
848499b3803SAlan Stern 				tmp = roothub_portstatus(ohci, i);
849499b3803SAlan Stern 				/* Enabled and not suspended? */
850499b3803SAlan Stern 				if ((tmp & RH_PS_PES) && !(tmp & RH_PS_PSS))
851499b3803SAlan Stern 					++active_cnt;
852499b3803SAlan Stern 			}
853499b3803SAlan Stern 
854499b3803SAlan Stern 			if (active_cnt > 0) {
855499b3803SAlan Stern 				ohci_err(ohci, "frame counter not updating; disabled\n");
856499b3803SAlan Stern 				goto died;
857499b3803SAlan Stern 			}
858499b3803SAlan Stern 		}
85981e38333SAlan Stern 		if (!list_empty(&ohci->eds_in_use)) {
860b2685bdaSShigeru Yoshida 			prev_frame_no = frame_no;
86181e38333SAlan Stern 			ohci->prev_wdh_cnt = ohci->wdh_cnt;
86281e38333SAlan Stern 			ohci->prev_donehead = ohci_readl(ohci,
86381e38333SAlan Stern 					&ohci->regs->donehead);
86481e38333SAlan Stern 			mod_timer(&ohci->io_watchdog,
86581e38333SAlan Stern 					jiffies + IO_WATCHDOG_DELAY);
86681e38333SAlan Stern 		}
86781e38333SAlan Stern 	}
86881e38333SAlan Stern 
86981e38333SAlan Stern  done:
870b2685bdaSShigeru Yoshida 	ohci->prev_frame_no = prev_frame_no;
87181e38333SAlan Stern 	spin_unlock_irqrestore(&ohci->lock, flags);
87281e38333SAlan Stern }
87381e38333SAlan Stern 
8741da177e4SLinus Torvalds /* an interrupt happens */
8751da177e4SLinus Torvalds 
ohci_irq(struct usb_hcd * hcd)8767d12e780SDavid Howells static irqreturn_t ohci_irq (struct usb_hcd *hcd)
8771da177e4SLinus Torvalds {
8781da177e4SLinus Torvalds 	struct ohci_hcd		*ohci = hcd_to_ohci (hcd);
8791da177e4SLinus Torvalds 	struct ohci_regs __iomem *regs = ohci->regs;
8801da177e4SLinus Torvalds 	int			ints;
8811da177e4SLinus Torvalds 
882565227c0SBenjamin Herrenschmidt 	/* Read interrupt status (and flush pending writes).  We ignore the
883565227c0SBenjamin Herrenschmidt 	 * optimization of checking the LSB of hcca->done_head; it doesn't
884565227c0SBenjamin Herrenschmidt 	 * work on all systems (edge triggering for OHCI can be a factor).
88589a0fd18SMike Nuss 	 */
886565227c0SBenjamin Herrenschmidt 	ints = ohci_readl(ohci, &regs->intrstatus);
8871da177e4SLinus Torvalds 
888565227c0SBenjamin Herrenschmidt 	/* Check for an all 1's result which is a typical consequence
889565227c0SBenjamin Herrenschmidt 	 * of dead, unclocked, or unplugged (CardBus...) devices
890565227c0SBenjamin Herrenschmidt 	 */
891*fe81f354SGuenter Roeck again:
892565227c0SBenjamin Herrenschmidt 	if (ints == ~(u32)0) {
893b7463c71SAlan Stern 		ohci->rh_state = OHCI_RH_HALTED;
8941da177e4SLinus Torvalds 		ohci_dbg (ohci, "device removed!\n");
89569fff59dSAlan Stern 		usb_hc_died(hcd);
8961da177e4SLinus Torvalds 		return IRQ_HANDLED;
897565227c0SBenjamin Herrenschmidt 	}
898565227c0SBenjamin Herrenschmidt 
899565227c0SBenjamin Herrenschmidt 	/* We only care about interrupts that are enabled */
900565227c0SBenjamin Herrenschmidt 	ints &= ohci_readl(ohci, &regs->intrenable);
9011da177e4SLinus Torvalds 
9021da177e4SLinus Torvalds 	/* interrupt for some other device? */
903b7463c71SAlan Stern 	if (ints == 0 || unlikely(ohci->rh_state == OHCI_RH_HALTED))
9041da177e4SLinus Torvalds 		return IRQ_NOTMINE;
9051da177e4SLinus Torvalds 
9061da177e4SLinus Torvalds 	if (ints & OHCI_INTR_UE) {
907d576bb9fSMichael Hanselmann 		// e.g. due to PCI Master/Target Abort
90889a0fd18SMike Nuss 		if (quirk_nec(ohci)) {
909d576bb9fSMichael Hanselmann 			/* Workaround for a silicon bug in some NEC chips used
910d576bb9fSMichael Hanselmann 			 * in Apple's PowerBooks. Adapted from Darwin code.
911d576bb9fSMichael Hanselmann 			 */
912d576bb9fSMichael Hanselmann 			ohci_err (ohci, "OHCI Unrecoverable Error, scheduling NEC chip restart\n");
913d576bb9fSMichael Hanselmann 
914d576bb9fSMichael Hanselmann 			ohci_writel (ohci, OHCI_INTR_UE, &regs->intrdisable);
915d576bb9fSMichael Hanselmann 
916d576bb9fSMichael Hanselmann 			schedule_work (&ohci->nec_work);
917d576bb9fSMichael Hanselmann 		} else {
9181da177e4SLinus Torvalds 			ohci_err (ohci, "OHCI Unrecoverable Error, disabled\n");
919b7463c71SAlan Stern 			ohci->rh_state = OHCI_RH_HALTED;
92069fff59dSAlan Stern 			usb_hc_died(hcd);
921d576bb9fSMichael Hanselmann 		}
9221da177e4SLinus Torvalds 
923256dbcd8SAlan Stern 		ohci_dump(ohci);
9241da177e4SLinus Torvalds 		ohci_usb_reset (ohci);
9251da177e4SLinus Torvalds 	}
9261da177e4SLinus Torvalds 
927583ceadaSAlan Stern 	if (ints & OHCI_INTR_RHSC) {
928d2c4254fSOliver Neukum 		ohci_dbg(ohci, "rhsc\n");
929583ceadaSAlan Stern 		ohci->next_statechange = jiffies + STATECHANGE_DELAY;
930583ceadaSAlan Stern 		ohci_writel(ohci, OHCI_INTR_RD | OHCI_INTR_RHSC,
931583ceadaSAlan Stern 				&regs->intrstatus);
932052ac01aSAlan Stern 
933052ac01aSAlan Stern 		/* NOTE: Vendors didn't always make the same implementation
934052ac01aSAlan Stern 		 * choices for RHSC.  Many followed the spec; RHSC triggers
935052ac01aSAlan Stern 		 * on an edge, like setting and maybe clearing a port status
936052ac01aSAlan Stern 		 * change bit.  With others it's level-triggered, active
93737ebb549SPetr Mladek 		 * until hub_wq clears all the port status change bits.  We'll
93837ebb549SPetr Mladek 		 * always disable it here and rely on polling until hub_wq
939052ac01aSAlan Stern 		 * re-enables it.
940052ac01aSAlan Stern 		 */
941052ac01aSAlan Stern 		ohci_writel(ohci, OHCI_INTR_RHSC, &regs->intrdisable);
942583ceadaSAlan Stern 		usb_hcd_poll_rh_status(hcd);
943583ceadaSAlan Stern 	}
944583ceadaSAlan Stern 
945583ceadaSAlan Stern 	/* For connect and disconnect events, we expect the controller
946583ceadaSAlan Stern 	 * to turn on RHSC along with RD.  But for remote wakeup events
947583ceadaSAlan Stern 	 * this might not happen.
948583ceadaSAlan Stern 	 */
949583ceadaSAlan Stern 	else if (ints & OHCI_INTR_RD) {
950d2c4254fSOliver Neukum 		ohci_dbg(ohci, "resume detect\n");
951e0fd3cbcSDavid Brownell 		ohci_writel(ohci, OHCI_INTR_RD, &regs->intrstatus);
952541c7d43SAlan Stern 		set_bit(HCD_FLAG_POLL_RH, &hcd->flags);
9538d1a243bSAlan Stern 		if (ohci->autostop) {
9548d1a243bSAlan Stern 			spin_lock (&ohci->lock);
9558d1a243bSAlan Stern 			ohci_rh_resume (ohci);
9568d1a243bSAlan Stern 			spin_unlock (&ohci->lock);
9578d1a243bSAlan Stern 		} else
958f197b2c5SDavid Brownell 			usb_hcd_resume_root_hub(hcd);
9591da177e4SLinus Torvalds 	}
9601da177e4SLinus Torvalds 
9611da177e4SLinus Torvalds 	spin_lock(&ohci->lock);
962c6fcb85eSAlan Stern 	if (ints & OHCI_INTR_WDH)
963c6fcb85eSAlan Stern 		update_done_list(ohci);
9641da177e4SLinus Torvalds 
9651da177e4SLinus Torvalds 	/* could track INTR_SO to reduce available PCI/... bandwidth */
9661da177e4SLinus Torvalds 
9671da177e4SLinus Torvalds 	/* handle any pending URB/ED unlinks, leaving INTR_SF enabled
9681da177e4SLinus Torvalds 	 * when there's still unlinking to be done (next frame).
9691da177e4SLinus Torvalds 	 */
970cdb4dd15SAlan Stern 	ohci_work(ohci);
97195d9a01dSAlan Stern 	if ((ints & OHCI_INTR_SF) != 0 && !ohci->ed_rm_list
972b7463c71SAlan Stern 			&& ohci->rh_state == OHCI_RH_RUNNING)
9731da177e4SLinus Torvalds 		ohci_writel (ohci, OHCI_INTR_SF, &regs->intrdisable);
9741da177e4SLinus Torvalds 
975b7463c71SAlan Stern 	if (ohci->rh_state == OHCI_RH_RUNNING) {
9761da177e4SLinus Torvalds 		ohci_writel (ohci, ints, &regs->intrstatus);
97781e38333SAlan Stern 		if (ints & OHCI_INTR_WDH)
97881e38333SAlan Stern 			++ohci->wdh_cnt;
97981e38333SAlan Stern 
9801da177e4SLinus Torvalds 		ohci_writel (ohci, OHCI_INTR_MIE, &regs->intrenable);
9811da177e4SLinus Torvalds 		// flush those writes
9821da177e4SLinus Torvalds 		(void) ohci_readl (ohci, &ohci->regs->control);
9831da177e4SLinus Torvalds 	}
984c6fcb85eSAlan Stern 	spin_unlock(&ohci->lock);
9851da177e4SLinus Torvalds 
986*fe81f354SGuenter Roeck 	/* repeat until all enabled interrupts are handled */
987*fe81f354SGuenter Roeck 	if (ohci->rh_state != OHCI_RH_HALTED) {
988*fe81f354SGuenter Roeck 		ints = ohci_readl(ohci, &regs->intrstatus);
989*fe81f354SGuenter Roeck 		if (ints && (ints & ohci_readl(ohci, &regs->intrenable)))
990*fe81f354SGuenter Roeck 			goto again;
991*fe81f354SGuenter Roeck 	}
992*fe81f354SGuenter Roeck 
9931da177e4SLinus Torvalds 	return IRQ_HANDLED;
9941da177e4SLinus Torvalds }
9951da177e4SLinus Torvalds 
9961da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/
9971da177e4SLinus Torvalds 
ohci_stop(struct usb_hcd * hcd)9981da177e4SLinus Torvalds static void ohci_stop (struct usb_hcd *hcd)
9991da177e4SLinus Torvalds {
10001da177e4SLinus Torvalds 	struct ohci_hcd		*ohci = hcd_to_ohci (hcd);
10011da177e4SLinus Torvalds 
1002256dbcd8SAlan Stern 	ohci_dump(ohci);
10031da177e4SLinus Torvalds 
1004569ff2deSTejun Heo 	if (quirk_nec(ohci))
100543829731STejun Heo 		flush_work(&ohci->nec_work);
100681e38333SAlan Stern 	del_timer_sync(&ohci->io_watchdog);
1007b2685bdaSShigeru Yoshida 	ohci->prev_frame_no = IO_WATCHDOG_OFF;
10081da177e4SLinus Torvalds 
10091da177e4SLinus Torvalds 	ohci_writel (ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable);
1010435932f2Scaizhiyong 	ohci_usb_reset(ohci);
101171795c1dSPete Zaitcev 	free_irq(hcd->irq, hcd);
1012cd70469dSFelipe Balbi 	hcd->irq = 0;
10131da177e4SLinus Torvalds 
1014ab1666c1SLibin Yang 	if (quirk_amdiso(ohci))
1015ad93562bSAndiry Xu 		usb_amd_dev_put();
101689a0fd18SMike Nuss 
10171da177e4SLinus Torvalds 	remove_debug_files (ohci);
10181da177e4SLinus Torvalds 	ohci_mem_cleanup (ohci);
10191da177e4SLinus Torvalds 	if (ohci->hcca) {
1020b0310c2fSLaurentiu Tudor 		if (hcd->localmem_pool)
1021b0310c2fSLaurentiu Tudor 			gen_pool_free(hcd->localmem_pool,
1022b0310c2fSLaurentiu Tudor 				      (unsigned long)ohci->hcca,
1023b0310c2fSLaurentiu Tudor 				      sizeof(*ohci->hcca));
1024b0310c2fSLaurentiu Tudor 		else
10251da177e4SLinus Torvalds 			dma_free_coherent(hcd->self.controller,
1026b0310c2fSLaurentiu Tudor 					  sizeof(*ohci->hcca),
10271da177e4SLinus Torvalds 					  ohci->hcca, ohci->hcca_dma);
10281da177e4SLinus Torvalds 		ohci->hcca = NULL;
10291da177e4SLinus Torvalds 		ohci->hcca_dma = 0;
10301da177e4SLinus Torvalds 	}
10311da177e4SLinus Torvalds }
10321da177e4SLinus Torvalds 
10331da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/
10341da177e4SLinus Torvalds 
10352c93e790Syuan linyu #if defined(CONFIG_PM) || defined(CONFIG_USB_PCI)
1036da6fb570SDavid Brownell 
10371da177e4SLinus Torvalds /* must not be called from interrupt context */
ohci_restart(struct ohci_hcd * ohci)103895e44d44SManjunath Goudar int ohci_restart(struct ohci_hcd *ohci)
10391da177e4SLinus Torvalds {
10401da177e4SLinus Torvalds 	int temp;
10411da177e4SLinus Torvalds 	int i;
10421da177e4SLinus Torvalds 	struct urb_priv *priv;
10431da177e4SLinus Torvalds 
104495e44d44SManjunath Goudar 	ohci_init(ohci);
10451da177e4SLinus Torvalds 	spin_lock_irq(&ohci->lock);
1046b7463c71SAlan Stern 	ohci->rh_state = OHCI_RH_HALTED;
1047d576bb9fSMichael Hanselmann 
1048d576bb9fSMichael Hanselmann 	/* Recycle any "live" eds/tds (and urbs). */
10491da177e4SLinus Torvalds 	if (!list_empty (&ohci->pending))
10501da177e4SLinus Torvalds 		ohci_dbg(ohci, "abort schedule...\n");
10511da177e4SLinus Torvalds 	list_for_each_entry (priv, &ohci->pending, pending) {
10521da177e4SLinus Torvalds 		struct urb	*urb = priv->td[0]->urb;
10531da177e4SLinus Torvalds 		struct ed	*ed = priv->ed;
10541da177e4SLinus Torvalds 
10551da177e4SLinus Torvalds 		switch (ed->state) {
10561da177e4SLinus Torvalds 		case ED_OPER:
10571da177e4SLinus Torvalds 			ed->state = ED_UNLINK;
10581da177e4SLinus Torvalds 			ed->hwINFO |= cpu_to_hc32(ohci, ED_DEQUEUE);
10591da177e4SLinus Torvalds 			ed_deschedule (ohci, ed);
10601da177e4SLinus Torvalds 
10611da177e4SLinus Torvalds 			ed->ed_next = ohci->ed_rm_list;
10621da177e4SLinus Torvalds 			ed->ed_prev = NULL;
10631da177e4SLinus Torvalds 			ohci->ed_rm_list = ed;
1064e288fc98SGustavo A. R. Silva 			fallthrough;
10651da177e4SLinus Torvalds 		case ED_UNLINK:
10661da177e4SLinus Torvalds 			break;
10671da177e4SLinus Torvalds 		default:
10681da177e4SLinus Torvalds 			ohci_dbg(ohci, "bogus ed %p state %d\n",
10691da177e4SLinus Torvalds 					ed, ed->state);
10701da177e4SLinus Torvalds 		}
10711da177e4SLinus Torvalds 
107255d84968SAlan Stern 		if (!urb->unlinked)
107355d84968SAlan Stern 			urb->unlinked = -ESHUTDOWN;
10741da177e4SLinus Torvalds 	}
1075cdb4dd15SAlan Stern 	ohci_work(ohci);
10761da177e4SLinus Torvalds 	spin_unlock_irq(&ohci->lock);
10771da177e4SLinus Torvalds 
10781da177e4SLinus Torvalds 	/* paranoia, in case that didn't work: */
10791da177e4SLinus Torvalds 
10801da177e4SLinus Torvalds 	/* empty the interrupt branches */
10811da177e4SLinus Torvalds 	for (i = 0; i < NUM_INTS; i++) ohci->load [i] = 0;
10821da177e4SLinus Torvalds 	for (i = 0; i < NUM_INTS; i++) ohci->hcca->int_table [i] = 0;
10831da177e4SLinus Torvalds 
10841da177e4SLinus Torvalds 	/* no EDs to remove */
10851da177e4SLinus Torvalds 	ohci->ed_rm_list = NULL;
10861da177e4SLinus Torvalds 
10871da177e4SLinus Torvalds 	/* empty control and bulk lists */
10881da177e4SLinus Torvalds 	ohci->ed_controltail = NULL;
10891da177e4SLinus Torvalds 	ohci->ed_bulktail    = NULL;
10901da177e4SLinus Torvalds 
10911da177e4SLinus Torvalds 	if ((temp = ohci_run (ohci)) < 0) {
10921da177e4SLinus Torvalds 		ohci_err (ohci, "can't restart, %d\n", temp);
10931da177e4SLinus Torvalds 		return temp;
10941da177e4SLinus Torvalds 	}
1095383975d7SAlan Stern 	ohci_dbg(ohci, "restart complete\n");
10961da177e4SLinus Torvalds 	return 0;
10971da177e4SLinus Torvalds }
109895e44d44SManjunath Goudar EXPORT_SYMBOL_GPL(ohci_restart);
1099d576bb9fSMichael Hanselmann 
1100da6fb570SDavid Brownell #endif
1101da6fb570SDavid Brownell 
1102cd1965dbSFlorian Fainelli #ifdef CONFIG_PM
1103cd1965dbSFlorian Fainelli 
ohci_suspend(struct usb_hcd * hcd,bool do_wakeup)110495e44d44SManjunath Goudar int ohci_suspend(struct usb_hcd *hcd, bool do_wakeup)
1105cd1965dbSFlorian Fainelli {
1106cd1965dbSFlorian Fainelli 	struct ohci_hcd	*ohci = hcd_to_ohci (hcd);
1107cd1965dbSFlorian Fainelli 	unsigned long	flags;
1108e1bffbf6SMajunath Goudar 	int		rc = 0;
1109cd1965dbSFlorian Fainelli 
1110d4ae47dcSFlorian Fainelli 	/* Disable irq emission and mark HW unaccessible. Use
1111cd1965dbSFlorian Fainelli 	 * the spinlock to properly synchronize with possible pending
1112cd1965dbSFlorian Fainelli 	 * RH suspend or resume activity.
1113cd1965dbSFlorian Fainelli 	 */
1114cd1965dbSFlorian Fainelli 	spin_lock_irqsave (&ohci->lock, flags);
1115cd1965dbSFlorian Fainelli 	ohci_writel(ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable);
1116cd1965dbSFlorian Fainelli 	(void)ohci_readl(ohci, &ohci->regs->intrdisable);
1117cd1965dbSFlorian Fainelli 
1118cd1965dbSFlorian Fainelli 	clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
1119cd1965dbSFlorian Fainelli 	spin_unlock_irqrestore (&ohci->lock, flags);
1120cd1965dbSFlorian Fainelli 
1121e1bffbf6SMajunath Goudar 	synchronize_irq(hcd->irq);
1122e1bffbf6SMajunath Goudar 
1123e1bffbf6SMajunath Goudar 	if (do_wakeup && HCD_WAKEUP_PENDING(hcd)) {
1124e1bffbf6SMajunath Goudar 		ohci_resume(hcd, false);
1125e1bffbf6SMajunath Goudar 		rc = -EBUSY;
1126e1bffbf6SMajunath Goudar 	}
1127e1bffbf6SMajunath Goudar 	return rc;
1128cd1965dbSFlorian Fainelli }
112995e44d44SManjunath Goudar EXPORT_SYMBOL_GPL(ohci_suspend);
1130cd1965dbSFlorian Fainelli 
1131cd1965dbSFlorian Fainelli 
ohci_resume(struct usb_hcd * hcd,bool hibernated)113295e44d44SManjunath Goudar int ohci_resume(struct usb_hcd *hcd, bool hibernated)
1133cd1965dbSFlorian Fainelli {
1134cfa49b4bSFlorian Fainelli 	struct ohci_hcd		*ohci = hcd_to_ohci(hcd);
1135cfa49b4bSFlorian Fainelli 	int			port;
1136cfa49b4bSFlorian Fainelli 	bool			need_reinit = false;
1137cfa49b4bSFlorian Fainelli 
1138cd1965dbSFlorian Fainelli 	set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
1139cd1965dbSFlorian Fainelli 
1140cd1965dbSFlorian Fainelli 	/* Make sure resume from hibernation re-enumerates everything */
1141cd1965dbSFlorian Fainelli 	if (hibernated)
1142cfa49b4bSFlorian Fainelli 		ohci_usb_reset(ohci);
1143cd1965dbSFlorian Fainelli 
1144cfa49b4bSFlorian Fainelli 	/* See if the controller is already running or has been reset */
1145cfa49b4bSFlorian Fainelli 	ohci->hc_control = ohci_readl(ohci, &ohci->regs->control);
1146cfa49b4bSFlorian Fainelli 	if (ohci->hc_control & (OHCI_CTRL_IR | OHCI_SCHED_ENABLES)) {
1147cfa49b4bSFlorian Fainelli 		need_reinit = true;
1148cfa49b4bSFlorian Fainelli 	} else {
1149cfa49b4bSFlorian Fainelli 		switch (ohci->hc_control & OHCI_CTRL_HCFS) {
1150cfa49b4bSFlorian Fainelli 		case OHCI_USB_OPER:
1151cfa49b4bSFlorian Fainelli 		case OHCI_USB_RESET:
1152cfa49b4bSFlorian Fainelli 			need_reinit = true;
1153cfa49b4bSFlorian Fainelli 		}
1154cfa49b4bSFlorian Fainelli 	}
1155cfa49b4bSFlorian Fainelli 
1156cfa49b4bSFlorian Fainelli 	/* If needed, reinitialize and suspend the root hub */
1157cfa49b4bSFlorian Fainelli 	if (need_reinit) {
1158cfa49b4bSFlorian Fainelli 		spin_lock_irq(&ohci->lock);
1159cfa49b4bSFlorian Fainelli 		ohci_rh_resume(ohci);
1160cfa49b4bSFlorian Fainelli 		ohci_rh_suspend(ohci, 0);
1161cfa49b4bSFlorian Fainelli 		spin_unlock_irq(&ohci->lock);
1162cfa49b4bSFlorian Fainelli 	}
1163cfa49b4bSFlorian Fainelli 
1164cfa49b4bSFlorian Fainelli 	/* Normally just turn on port power and enable interrupts */
1165cfa49b4bSFlorian Fainelli 	else {
1166cfa49b4bSFlorian Fainelli 		ohci_dbg(ohci, "powerup ports\n");
1167cfa49b4bSFlorian Fainelli 		for (port = 0; port < ohci->num_ports; port++)
1168cfa49b4bSFlorian Fainelli 			ohci_writel(ohci, RH_PS_PPS,
1169cfa49b4bSFlorian Fainelli 					&ohci->regs->roothub.portstatus[port]);
1170cfa49b4bSFlorian Fainelli 
1171cfa49b4bSFlorian Fainelli 		ohci_writel(ohci, OHCI_INTR_MIE, &ohci->regs->intrenable);
1172cfa49b4bSFlorian Fainelli 		ohci_readl(ohci, &ohci->regs->intrenable);
1173cfa49b4bSFlorian Fainelli 		msleep(20);
1174cfa49b4bSFlorian Fainelli 	}
1175cfa49b4bSFlorian Fainelli 
1176cfa49b4bSFlorian Fainelli 	usb_hcd_resume_root_hub(hcd);
1177cfa49b4bSFlorian Fainelli 
1178cd1965dbSFlorian Fainelli 	return 0;
1179cd1965dbSFlorian Fainelli }
118095e44d44SManjunath Goudar EXPORT_SYMBOL_GPL(ohci_resume);
1181cd1965dbSFlorian Fainelli 
1182cd1965dbSFlorian Fainelli #endif
1183cd1965dbSFlorian Fainelli 
1184d576bb9fSMichael Hanselmann /*-------------------------------------------------------------------------*/
1185d576bb9fSMichael Hanselmann 
118695e44d44SManjunath Goudar /*
118795e44d44SManjunath Goudar  * Generic structure: This gets copied for platform drivers so that
118895e44d44SManjunath Goudar  * individual entries can be overridden as needed.
118995e44d44SManjunath Goudar  */
119095e44d44SManjunath Goudar 
119195e44d44SManjunath Goudar static const struct hc_driver ohci_hc_driver = {
119295e44d44SManjunath Goudar 	.description =          hcd_name,
119395e44d44SManjunath Goudar 	.product_desc =         "OHCI Host Controller",
119495e44d44SManjunath Goudar 	.hcd_priv_size =        sizeof(struct ohci_hcd),
119595e44d44SManjunath Goudar 
119695e44d44SManjunath Goudar 	/*
119795e44d44SManjunath Goudar 	 * generic hardware linkage
119895e44d44SManjunath Goudar 	*/
119995e44d44SManjunath Goudar 	.irq =                  ohci_irq,
12007b81cb6bSChristoph Hellwig 	.flags =                HCD_MEMORY | HCD_DMA | HCD_USB11,
120195e44d44SManjunath Goudar 
120295e44d44SManjunath Goudar 	/*
120395e44d44SManjunath Goudar 	* basic lifecycle operations
120495e44d44SManjunath Goudar 	*/
120595e44d44SManjunath Goudar 	.reset =                ohci_setup,
120695e44d44SManjunath Goudar 	.start =                ohci_start,
120795e44d44SManjunath Goudar 	.stop =                 ohci_stop,
120895e44d44SManjunath Goudar 	.shutdown =             ohci_shutdown,
120995e44d44SManjunath Goudar 
121095e44d44SManjunath Goudar 	/*
121195e44d44SManjunath Goudar 	 * managing i/o requests and associated device resources
121295e44d44SManjunath Goudar 	*/
121395e44d44SManjunath Goudar 	.urb_enqueue =          ohci_urb_enqueue,
121495e44d44SManjunath Goudar 	.urb_dequeue =          ohci_urb_dequeue,
121595e44d44SManjunath Goudar 	.endpoint_disable =     ohci_endpoint_disable,
121695e44d44SManjunath Goudar 
121795e44d44SManjunath Goudar 	/*
121895e44d44SManjunath Goudar 	* scheduling support
121995e44d44SManjunath Goudar 	*/
122095e44d44SManjunath Goudar 	.get_frame_number =     ohci_get_frame,
122195e44d44SManjunath Goudar 
122295e44d44SManjunath Goudar 	/*
122395e44d44SManjunath Goudar 	* root hub support
122495e44d44SManjunath Goudar 	*/
122595e44d44SManjunath Goudar 	.hub_status_data =      ohci_hub_status_data,
122695e44d44SManjunath Goudar 	.hub_control =          ohci_hub_control,
122795e44d44SManjunath Goudar #ifdef CONFIG_PM
122895e44d44SManjunath Goudar 	.bus_suspend =          ohci_bus_suspend,
122995e44d44SManjunath Goudar 	.bus_resume =           ohci_bus_resume,
123095e44d44SManjunath Goudar #endif
123195e44d44SManjunath Goudar 	.start_port_reset =	ohci_start_port_reset,
123295e44d44SManjunath Goudar };
123395e44d44SManjunath Goudar 
ohci_init_driver(struct hc_driver * drv,const struct ohci_driver_overrides * over)123495e44d44SManjunath Goudar void ohci_init_driver(struct hc_driver *drv,
123595e44d44SManjunath Goudar 		const struct ohci_driver_overrides *over)
123695e44d44SManjunath Goudar {
123795e44d44SManjunath Goudar 	/* Copy the generic table to drv and then apply the overrides */
123895e44d44SManjunath Goudar 	*drv = ohci_hc_driver;
123995e44d44SManjunath Goudar 
1240c80ad6d1SKevin Hilman 	if (over) {
124195e44d44SManjunath Goudar 		drv->product_desc = over->product_desc;
124295e44d44SManjunath Goudar 		drv->hcd_priv_size += over->extra_priv_size;
124395e44d44SManjunath Goudar 		if (over->reset)
124495e44d44SManjunath Goudar 			drv->reset = over->reset;
124595e44d44SManjunath Goudar 	}
1246c80ad6d1SKevin Hilman }
124795e44d44SManjunath Goudar EXPORT_SYMBOL_GPL(ohci_init_driver);
124895e44d44SManjunath Goudar 
124995e44d44SManjunath Goudar /*-------------------------------------------------------------------------*/
125095e44d44SManjunath Goudar 
12511da177e4SLinus Torvalds MODULE_AUTHOR (DRIVER_AUTHOR);
12522b70f073SAlan Stern MODULE_DESCRIPTION(DRIVER_DESC);
12531da177e4SLinus Torvalds MODULE_LICENSE ("GPL");
12541da177e4SLinus Torvalds 
12556381fad7SEric Miao #if defined(CONFIG_ARCH_SA1100) && defined(CONFIG_SA1111)
12561da177e4SLinus Torvalds #include "ohci-sa1111.c"
12575e16fabeSSylvain Munaut #define SA1111_DRIVER		ohci_hcd_sa1111_driver
12581da177e4SLinus Torvalds #endif
12591da177e4SLinus Torvalds 
1260495a678fSSylvain Munaut #ifdef CONFIG_USB_OHCI_HCD_PPC_OF
1261495a678fSSylvain Munaut #include "ohci-ppc-of.c"
1262495a678fSSylvain Munaut #define OF_PLATFORM_DRIVER	ohci_hcd_ppc_of_driver
1263495a678fSSylvain Munaut #endif
1264495a678fSSylvain Munaut 
12656a6c957eSGeoff Levand #ifdef CONFIG_PPC_PS3
12666a6c957eSGeoff Levand #include "ohci-ps3.c"
12677a4eb7fdSGeoff Levand #define PS3_SYSTEM_BUS_DRIVER	ps3_ohci_driver
12686a6c957eSGeoff Levand #endif
12696a6c957eSGeoff Levand 
1270f54aab6eSMagnus Damm #ifdef CONFIG_MFD_SM501
1271f54aab6eSMagnus Damm #include "ohci-sm501.c"
12723ee38d8bSBen Dooks #define SM501_OHCI_DRIVER	ohci_hcd_sm501_driver
1273f54aab6eSMagnus Damm #endif
1274f54aab6eSMagnus Damm 
ohci_hcd_mod_init(void)12755e16fabeSSylvain Munaut static int __init ohci_hcd_mod_init(void)
12765e16fabeSSylvain Munaut {
12775e16fabeSSylvain Munaut 	int retval = 0;
12785e16fabeSSylvain Munaut 
12795e16fabeSSylvain Munaut 	if (usb_disabled())
12805e16fabeSSylvain Munaut 		return -ENODEV;
12815e16fabeSSylvain Munaut 
12825b5e0928SAlexey Dobriyan 	pr_debug ("%s: block sizes: ed %zd td %zd\n", hcd_name,
12835e16fabeSSylvain Munaut 		sizeof (struct ed), sizeof (struct td));
12849beeee65SAlan Stern 	set_bit(USB_OHCI_LOADED, &usb_hcds_loaded);
12855e16fabeSSylvain Munaut 
1286485f4f39SGreg Kroah-Hartman 	ohci_debug_root = debugfs_create_dir("ohci", usb_debug_root);
1287684c19e0STony Jones 
12886a6c957eSGeoff Levand #ifdef PS3_SYSTEM_BUS_DRIVER
12897a4eb7fdSGeoff Levand 	retval = ps3_ohci_driver_register(&PS3_SYSTEM_BUS_DRIVER);
12906a6c957eSGeoff Levand 	if (retval < 0)
12916a6c957eSGeoff Levand 		goto error_ps3;
12926a6c957eSGeoff Levand #endif
12936a6c957eSGeoff Levand 
1294495a678fSSylvain Munaut #ifdef OF_PLATFORM_DRIVER
1295d35fb641SGrant Likely 	retval = platform_driver_register(&OF_PLATFORM_DRIVER);
1296495a678fSSylvain Munaut 	if (retval < 0)
1297de44743bSBenjamin Herrenschmidt 		goto error_of_platform;
1298495a678fSSylvain Munaut #endif
1299495a678fSSylvain Munaut 
13005e16fabeSSylvain Munaut #ifdef SA1111_DRIVER
13015e16fabeSSylvain Munaut 	retval = sa1111_driver_register(&SA1111_DRIVER);
13025e16fabeSSylvain Munaut 	if (retval < 0)
1303de44743bSBenjamin Herrenschmidt 		goto error_sa1111;
13045e16fabeSSylvain Munaut #endif
13055e16fabeSSylvain Munaut 
13063ee38d8bSBen Dooks #ifdef SM501_OHCI_DRIVER
13073ee38d8bSBen Dooks 	retval = platform_driver_register(&SM501_OHCI_DRIVER);
13083ee38d8bSBen Dooks 	if (retval < 0)
13093ee38d8bSBen Dooks 		goto error_sm501;
13103ee38d8bSBen Dooks #endif
13113ee38d8bSBen Dooks 
13125e16fabeSSylvain Munaut 	return retval;
13135e16fabeSSylvain Munaut 
13145e16fabeSSylvain Munaut 	/* Error path */
13153ee38d8bSBen Dooks #ifdef SM501_OHCI_DRIVER
131678c73414SDmitry Baryshkov 	platform_driver_unregister(&SM501_OHCI_DRIVER);
13173ee38d8bSBen Dooks  error_sm501:
13183ee38d8bSBen Dooks #endif
13195e16fabeSSylvain Munaut #ifdef SA1111_DRIVER
13205e16fabeSSylvain Munaut 	sa1111_driver_unregister(&SA1111_DRIVER);
1321de44743bSBenjamin Herrenschmidt  error_sa1111:
1322de44743bSBenjamin Herrenschmidt #endif
1323de44743bSBenjamin Herrenschmidt #ifdef OF_PLATFORM_DRIVER
1324d35fb641SGrant Likely 	platform_driver_unregister(&OF_PLATFORM_DRIVER);
1325de44743bSBenjamin Herrenschmidt  error_of_platform:
1326de44743bSBenjamin Herrenschmidt #endif
13276a6c957eSGeoff Levand #ifdef PS3_SYSTEM_BUS_DRIVER
13287a4eb7fdSGeoff Levand 	ps3_ohci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);
13296a6c957eSGeoff Levand  error_ps3:
13306a6c957eSGeoff Levand #endif
1331684c19e0STony Jones 	debugfs_remove(ohci_debug_root);
1332684c19e0STony Jones 	ohci_debug_root = NULL;
1333684c19e0STony Jones 
13349beeee65SAlan Stern 	clear_bit(USB_OHCI_LOADED, &usb_hcds_loaded);
13355e16fabeSSylvain Munaut 	return retval;
13365e16fabeSSylvain Munaut }
13375e16fabeSSylvain Munaut module_init(ohci_hcd_mod_init);
13385e16fabeSSylvain Munaut 
ohci_hcd_mod_exit(void)13395e16fabeSSylvain Munaut static void __exit ohci_hcd_mod_exit(void)
13405e16fabeSSylvain Munaut {
13413ee38d8bSBen Dooks #ifdef SM501_OHCI_DRIVER
13423ee38d8bSBen Dooks 	platform_driver_unregister(&SM501_OHCI_DRIVER);
13433ee38d8bSBen Dooks #endif
13445e16fabeSSylvain Munaut #ifdef SA1111_DRIVER
13455e16fabeSSylvain Munaut 	sa1111_driver_unregister(&SA1111_DRIVER);
13465e16fabeSSylvain Munaut #endif
1347495a678fSSylvain Munaut #ifdef OF_PLATFORM_DRIVER
1348d35fb641SGrant Likely 	platform_driver_unregister(&OF_PLATFORM_DRIVER);
1349495a678fSSylvain Munaut #endif
13506a6c957eSGeoff Levand #ifdef PS3_SYSTEM_BUS_DRIVER
13517a4eb7fdSGeoff Levand 	ps3_ohci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);
13526a6c957eSGeoff Levand #endif
1353684c19e0STony Jones 	debugfs_remove(ohci_debug_root);
13549beeee65SAlan Stern 	clear_bit(USB_OHCI_LOADED, &usb_hcds_loaded);
13555e16fabeSSylvain Munaut }
13565e16fabeSSylvain Munaut module_exit(ohci_hcd_mod_exit);
13575e16fabeSSylvain Munaut 
1358