xref: /linux/drivers/usb/host/ohci-hcd.c (revision e288fc982820e1bf397c873b0cf0cbf876829b7f)
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
191da177e4SLinus Torvalds  * through the http://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 */
105900937c0SGeyslan G. Bem static bool distrust_firmware = true;
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 
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  */
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;
1741da177e4SLinus Torvalds 			/* 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
1841da177e4SLinus Torvalds 					% usb_maxpacket (urb->dev, pipe,
1851da177e4SLinus Torvalds 						usb_pipeout (pipe))) == 0)
1861da177e4SLinus Torvalds 				size++;
1871da177e4SLinus Torvalds 			break;
1881da177e4SLinus Torvalds 		case PIPE_ISOCHRONOUS: /* number of packets from URB */
1891da177e4SLinus Torvalds 			size = urb->number_of_packets;
1901da177e4SLinus Torvalds 			break;
1911da177e4SLinus Torvalds 	}
1921da177e4SLinus Torvalds 
1931da177e4SLinus Torvalds 	/* allocate the private part of the URB */
194dd00cc48SYoann Padioleau 	urb_priv = kzalloc (sizeof (urb_priv_t) + size * sizeof (struct td *),
1951da177e4SLinus Torvalds 			mem_flags);
1961da177e4SLinus Torvalds 	if (!urb_priv)
1971da177e4SLinus Torvalds 		return -ENOMEM;
1981da177e4SLinus Torvalds 	INIT_LIST_HEAD (&urb_priv->pending);
1991da177e4SLinus Torvalds 	urb_priv->length = size;
2001da177e4SLinus Torvalds 	urb_priv->ed = ed;
2011da177e4SLinus Torvalds 
2021da177e4SLinus Torvalds 	/* allocate the TDs (deferring hash chain updates) */
2031da177e4SLinus Torvalds 	for (i = 0; i < size; i++) {
2041da177e4SLinus Torvalds 		urb_priv->td [i] = td_alloc (ohci, mem_flags);
2051da177e4SLinus Torvalds 		if (!urb_priv->td [i]) {
2061da177e4SLinus Torvalds 			urb_priv->length = i;
2071da177e4SLinus Torvalds 			urb_free_priv (ohci, urb_priv);
2081da177e4SLinus Torvalds 			return -ENOMEM;
2091da177e4SLinus Torvalds 		}
2101da177e4SLinus Torvalds 	}
2111da177e4SLinus Torvalds 
2121da177e4SLinus Torvalds 	spin_lock_irqsave (&ohci->lock, flags);
2131da177e4SLinus Torvalds 
2141da177e4SLinus Torvalds 	/* don't submit to a dead HC */
215541c7d43SAlan Stern 	if (!HCD_HW_ACCESSIBLE(hcd)) {
2168de98402SBenjamin Herrenschmidt 		retval = -ENODEV;
2178de98402SBenjamin Herrenschmidt 		goto fail;
2188de98402SBenjamin Herrenschmidt 	}
219b7463c71SAlan Stern 	if (ohci->rh_state != OHCI_RH_RUNNING) {
2201da177e4SLinus Torvalds 		retval = -ENODEV;
2211da177e4SLinus Torvalds 		goto fail;
2221da177e4SLinus Torvalds 	}
223e9df41c5SAlan Stern 	retval = usb_hcd_link_urb_to_ep(hcd, urb);
224e9df41c5SAlan Stern 	if (retval)
2251da177e4SLinus Torvalds 		goto fail;
2261da177e4SLinus Torvalds 
2271da177e4SLinus Torvalds 	/* schedule the ed if needed */
2281da177e4SLinus Torvalds 	if (ed->state == ED_IDLE) {
2291da177e4SLinus Torvalds 		retval = ed_schedule (ohci, ed);
230e9df41c5SAlan Stern 		if (retval < 0) {
231e9df41c5SAlan Stern 			usb_hcd_unlink_urb_from_ep(hcd, urb);
232e9df41c5SAlan Stern 			goto fail;
233e9df41c5SAlan Stern 		}
23481e38333SAlan Stern 
23581e38333SAlan Stern 		/* Start up the I/O watchdog timer, if it's not running */
236b2685bdaSShigeru Yoshida 		if (ohci->prev_frame_no == IO_WATCHDOG_OFF &&
23721a60f6eSGerd Hoffmann 				list_empty(&ohci->eds_in_use) &&
23821a60f6eSGerd Hoffmann 				!(ohci->flags & OHCI_QUIRK_QEMU)) {
239499b3803SAlan Stern 			ohci->prev_frame_no = ohci_frame_no(ohci);
24081e38333SAlan Stern 			mod_timer(&ohci->io_watchdog,
24181e38333SAlan Stern 					jiffies + IO_WATCHDOG_DELAY);
242499b3803SAlan Stern 		}
24381e38333SAlan Stern 		list_add(&ed->in_use_list, &ohci->eds_in_use);
24481e38333SAlan Stern 
2451da177e4SLinus Torvalds 		if (ed->type == PIPE_ISOCHRONOUS) {
2461da177e4SLinus Torvalds 			u16	frame = ohci_frame_no(ohci);
2471da177e4SLinus Torvalds 
2481da177e4SLinus Torvalds 			/* delay a few frames before the first TD */
2491da177e4SLinus Torvalds 			frame += max_t (u16, 8, ed->interval);
2501da177e4SLinus Torvalds 			frame &= ~(ed->interval - 1);
2511da177e4SLinus Torvalds 			frame |= ed->branch;
2521da177e4SLinus Torvalds 			urb->start_frame = frame;
253a8693424SAlan Stern 			ed->last_iso = frame + ed->interval * (size - 1);
2541da177e4SLinus Torvalds 		}
2556a41b4d3SAlan Stern 	} else if (ed->type == PIPE_ISOCHRONOUS) {
256e1944017SAlan Stern 		u16	next = ohci_frame_no(ohci) + 1;
2576a41b4d3SAlan Stern 		u16	frame = ed->last_iso + ed->interval;
258a8693424SAlan Stern 		u16	length = ed->interval * (size - 1);
2596a41b4d3SAlan Stern 
2606a41b4d3SAlan Stern 		/* Behind the scheduling threshold? */
2616a41b4d3SAlan Stern 		if (unlikely(tick_before(frame, next))) {
2626a41b4d3SAlan Stern 
263a8693424SAlan Stern 			/* URB_ISO_ASAP: Round up to the first available slot */
264815fa7b9SAlan Stern 			if (urb->transfer_flags & URB_ISO_ASAP) {
2656a41b4d3SAlan Stern 				frame += (next - frame + ed->interval - 1) &
2666a41b4d3SAlan Stern 						-ed->interval;
2676a41b4d3SAlan Stern 
2686a41b4d3SAlan Stern 			/*
269a8693424SAlan Stern 			 * Not ASAP: Use the next slot in the stream,
270a8693424SAlan Stern 			 * no matter what.
2716a41b4d3SAlan Stern 			 */
272815fa7b9SAlan Stern 			} else {
2736a41b4d3SAlan Stern 				/*
2746a41b4d3SAlan Stern 				 * Some OHCI hardware doesn't handle late TDs
275815fa7b9SAlan Stern 				 * correctly.  After retiring them it proceeds
276815fa7b9SAlan Stern 				 * to the next ED instead of the next TD.
277815fa7b9SAlan Stern 				 * Therefore we have to omit the late TDs
278815fa7b9SAlan Stern 				 * entirely.
2796a41b4d3SAlan Stern 				 */
280815fa7b9SAlan Stern 				urb_priv->td_cnt = DIV_ROUND_UP(
281815fa7b9SAlan Stern 						(u16) (next - frame),
2826a41b4d3SAlan Stern 						ed->interval);
283a8693424SAlan Stern 				if (urb_priv->td_cnt >= urb_priv->length) {
284a8693424SAlan Stern 					++urb_priv->td_cnt;	/* Mark it */
285a8693424SAlan Stern 					ohci_dbg(ohci, "iso underrun %p (%u+%u < %u)\n",
286a8693424SAlan Stern 							urb, frame, length,
287a8693424SAlan Stern 							next);
288a8693424SAlan Stern 				}
2896a41b4d3SAlan Stern 			}
290815fa7b9SAlan Stern 		}
2916a41b4d3SAlan Stern 		urb->start_frame = frame;
292a8693424SAlan Stern 		ed->last_iso = frame + length;
2936a41b4d3SAlan Stern 	}
2941da177e4SLinus Torvalds 
2951da177e4SLinus Torvalds 	/* fill the TDs and link them to the ed; and
2961da177e4SLinus Torvalds 	 * enable that part of the schedule, if needed
2971da177e4SLinus Torvalds 	 * and update count of queued periodic urbs
2981da177e4SLinus Torvalds 	 */
2991da177e4SLinus Torvalds 	urb->hcpriv = urb_priv;
3001da177e4SLinus Torvalds 	td_submit_urb (ohci, urb);
3011da177e4SLinus Torvalds 
3021da177e4SLinus Torvalds fail:
3031da177e4SLinus Torvalds 	if (retval)
3041da177e4SLinus Torvalds 		urb_free_priv (ohci, urb_priv);
3051da177e4SLinus Torvalds 	spin_unlock_irqrestore (&ohci->lock, flags);
3061da177e4SLinus Torvalds 	return retval;
3071da177e4SLinus Torvalds }
3081da177e4SLinus Torvalds 
3091da177e4SLinus Torvalds /*
31055d84968SAlan Stern  * decouple the URB from the HC queues (TDs, urb_priv).
31155d84968SAlan Stern  * reporting is always done
3121da177e4SLinus Torvalds  * asynchronously, and we might be dealing with an urb that's
3131da177e4SLinus Torvalds  * partially transferred, or an ED with other urbs being unlinked.
3141da177e4SLinus Torvalds  */
315e9df41c5SAlan Stern static int ohci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
3161da177e4SLinus Torvalds {
3171da177e4SLinus Torvalds 	struct ohci_hcd		*ohci = hcd_to_ohci (hcd);
3181da177e4SLinus Torvalds 	unsigned long		flags;
319e9df41c5SAlan Stern 	int			rc;
3208b3ab0edSAlan Stern 	urb_priv_t		*urb_priv;
3211da177e4SLinus Torvalds 
3221da177e4SLinus Torvalds 	spin_lock_irqsave (&ohci->lock, flags);
323e9df41c5SAlan Stern 	rc = usb_hcd_check_unlink_urb(hcd, urb, status);
3248b3ab0edSAlan Stern 	if (rc == 0) {
3251da177e4SLinus Torvalds 
3261da177e4SLinus Torvalds 		/* Unless an IRQ completed the unlink while it was being
3271da177e4SLinus Torvalds 		 * handed to us, flag it for unlink and giveback, and force
3281da177e4SLinus Torvalds 		 * some upcoming INTR_SF to call finish_unlinks()
3291da177e4SLinus Torvalds 		 */
3301da177e4SLinus Torvalds 		urb_priv = urb->hcpriv;
3311da177e4SLinus Torvalds 		if (urb_priv->ed->state == ED_OPER)
3321da177e4SLinus Torvalds 			start_ed_unlink(ohci, urb_priv->ed);
3338b3ab0edSAlan Stern 
3348b3ab0edSAlan Stern 		if (ohci->rh_state != OHCI_RH_RUNNING) {
3358b3ab0edSAlan Stern 			/* With HC dead, we can clean up right away */
336cdb4dd15SAlan Stern 			ohci_work(ohci);
3371da177e4SLinus Torvalds 		}
3381da177e4SLinus Torvalds 	}
3391da177e4SLinus Torvalds 	spin_unlock_irqrestore (&ohci->lock, flags);
340e9df41c5SAlan Stern 	return rc;
3411da177e4SLinus Torvalds }
3421da177e4SLinus Torvalds 
3431da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/
3441da177e4SLinus Torvalds 
3451da177e4SLinus Torvalds /* frees config/altsetting state for endpoints,
3461da177e4SLinus Torvalds  * including ED memory, dummy TD, and bulk/intr data toggle
3471da177e4SLinus Torvalds  */
3481da177e4SLinus Torvalds 
3491da177e4SLinus Torvalds static void
3501da177e4SLinus Torvalds ohci_endpoint_disable (struct usb_hcd *hcd, struct usb_host_endpoint *ep)
3511da177e4SLinus Torvalds {
3521da177e4SLinus Torvalds 	struct ohci_hcd		*ohci = hcd_to_ohci (hcd);
3531da177e4SLinus Torvalds 	unsigned long		flags;
3541da177e4SLinus Torvalds 	struct ed		*ed = ep->hcpriv;
3551da177e4SLinus Torvalds 	unsigned		limit = 1000;
3561da177e4SLinus Torvalds 
3571da177e4SLinus Torvalds 	/* ASSERT:  any requests/urbs are being unlinked */
3581da177e4SLinus Torvalds 	/* ASSERT:  nobody can be submitting urbs for this any more */
3591da177e4SLinus Torvalds 
3601da177e4SLinus Torvalds 	if (!ed)
3611da177e4SLinus Torvalds 		return;
3621da177e4SLinus Torvalds 
3631da177e4SLinus Torvalds rescan:
3641da177e4SLinus Torvalds 	spin_lock_irqsave (&ohci->lock, flags);
3651da177e4SLinus Torvalds 
366b7463c71SAlan Stern 	if (ohci->rh_state != OHCI_RH_RUNNING) {
3671da177e4SLinus Torvalds sanitize:
3681da177e4SLinus Torvalds 		ed->state = ED_IDLE;
369cdb4dd15SAlan Stern 		ohci_work(ohci);
3701da177e4SLinus Torvalds 	}
3711da177e4SLinus Torvalds 
3721da177e4SLinus Torvalds 	switch (ed->state) {
3731da177e4SLinus Torvalds 	case ED_UNLINK:		/* wait for hw to finish? */
3741da177e4SLinus Torvalds 		/* major IRQ delivery trouble loses INTR_SF too... */
3751da177e4SLinus Torvalds 		if (limit-- == 0) {
37689a0fd18SMike Nuss 			ohci_warn(ohci, "ED unlink timeout\n");
3771da177e4SLinus Torvalds 			goto sanitize;
3781da177e4SLinus Torvalds 		}
3791da177e4SLinus Torvalds 		spin_unlock_irqrestore (&ohci->lock, flags);
38022c43863SNishanth Aravamudan 		schedule_timeout_uninterruptible(1);
3811da177e4SLinus Torvalds 		goto rescan;
3821da177e4SLinus Torvalds 	case ED_IDLE:		/* fully unlinked */
3831da177e4SLinus Torvalds 		if (list_empty (&ed->td_list)) {
3841da177e4SLinus Torvalds 			td_free (ohci, ed->dummy);
3851da177e4SLinus Torvalds 			ed_free (ohci, ed);
3861da177e4SLinus Torvalds 			break;
3871da177e4SLinus Torvalds 		}
388*e288fc98SGustavo A. R. Silva 		fallthrough;
3891da177e4SLinus Torvalds 	default:
3901da177e4SLinus Torvalds 		/* caller was supposed to have unlinked any requests;
3911da177e4SLinus Torvalds 		 * that's not our job.  can't recover; must leak ed.
3921da177e4SLinus Torvalds 		 */
3931da177e4SLinus Torvalds 		ohci_err (ohci, "leak ed %p (#%02x) state %d%s\n",
3941da177e4SLinus Torvalds 			ed, ep->desc.bEndpointAddress, ed->state,
3951da177e4SLinus Torvalds 			list_empty (&ed->td_list) ? "" : " (has tds)");
3961da177e4SLinus Torvalds 		td_free (ohci, ed->dummy);
3971da177e4SLinus Torvalds 		break;
3981da177e4SLinus Torvalds 	}
3991da177e4SLinus Torvalds 	ep->hcpriv = NULL;
4001da177e4SLinus Torvalds 	spin_unlock_irqrestore (&ohci->lock, flags);
4011da177e4SLinus Torvalds }
4021da177e4SLinus Torvalds 
4031da177e4SLinus Torvalds static int ohci_get_frame (struct usb_hcd *hcd)
4041da177e4SLinus Torvalds {
4051da177e4SLinus Torvalds 	struct ohci_hcd		*ohci = hcd_to_ohci (hcd);
4061da177e4SLinus Torvalds 
4071da177e4SLinus Torvalds 	return ohci_frame_no(ohci);
4081da177e4SLinus Torvalds }
4091da177e4SLinus Torvalds 
4101da177e4SLinus Torvalds static void ohci_usb_reset (struct ohci_hcd *ohci)
4111da177e4SLinus Torvalds {
4121da177e4SLinus Torvalds 	ohci->hc_control = ohci_readl (ohci, &ohci->regs->control);
4131da177e4SLinus Torvalds 	ohci->hc_control &= OHCI_CTRL_RWC;
4141da177e4SLinus Torvalds 	ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
415b7463c71SAlan Stern 	ohci->rh_state = OHCI_RH_HALTED;
4161da177e4SLinus Torvalds }
4171da177e4SLinus Torvalds 
41864a21d02SAleksey Gorelov /* ohci_shutdown forcibly disables IRQs and DMA, helping kexec and
419f4df0e33SDavid Brownell  * other cases where the next software may expect clean state from the
420f4df0e33SDavid Brownell  * "firmware".  this is bus-neutral, unlike shutdown() methods.
421f4df0e33SDavid Brownell  */
422a349b95dSYoshihiro Shimoda static void _ohci_shutdown(struct usb_hcd *hcd)
423f4df0e33SDavid Brownell {
424f4df0e33SDavid Brownell 	struct ohci_hcd *ohci;
425f4df0e33SDavid Brownell 
42664a21d02SAleksey Gorelov 	ohci = hcd_to_ohci (hcd);
427c6187597SAlan Stern 	ohci_writel(ohci, (u32) ~0, &ohci->regs->intrdisable);
4283df7169eSAlan Stern 
429c6187597SAlan Stern 	/* Software reset, after which the controller goes into SUSPEND */
430c6187597SAlan Stern 	ohci_writel(ohci, OHCI_HCR, &ohci->regs->cmdstatus);
431c6187597SAlan Stern 	ohci_readl(ohci, &ohci->regs->cmdstatus);	/* flush the writes */
432c6187597SAlan Stern 	udelay(10);
4333df7169eSAlan Stern 
434c6187597SAlan Stern 	ohci_writel(ohci, ohci->fminterval, &ohci->regs->fminterval);
43581e38333SAlan Stern 	ohci->rh_state = OHCI_RH_HALTED;
436f4df0e33SDavid Brownell }
437f4df0e33SDavid Brownell 
438a349b95dSYoshihiro Shimoda static void ohci_shutdown(struct usb_hcd *hcd)
439a349b95dSYoshihiro Shimoda {
440a349b95dSYoshihiro Shimoda 	struct ohci_hcd	*ohci = hcd_to_ohci(hcd);
441a349b95dSYoshihiro Shimoda 	unsigned long flags;
442a349b95dSYoshihiro Shimoda 
443a349b95dSYoshihiro Shimoda 	spin_lock_irqsave(&ohci->lock, flags);
444a349b95dSYoshihiro Shimoda 	_ohci_shutdown(hcd);
445a349b95dSYoshihiro Shimoda 	spin_unlock_irqrestore(&ohci->lock, flags);
446a349b95dSYoshihiro Shimoda }
447a349b95dSYoshihiro Shimoda 
4481da177e4SLinus Torvalds /*-------------------------------------------------------------------------*
4491da177e4SLinus Torvalds  * HC functions
4501da177e4SLinus Torvalds  *-------------------------------------------------------------------------*/
4511da177e4SLinus Torvalds 
4521da177e4SLinus Torvalds /* init memory, and kick BIOS/SMM off */
4531da177e4SLinus Torvalds 
4541da177e4SLinus Torvalds static int ohci_init (struct ohci_hcd *ohci)
4551da177e4SLinus Torvalds {
4561da177e4SLinus Torvalds 	int ret;
4576a9062f3SDavid Brownell 	struct usb_hcd *hcd = ohci_to_hcd(ohci);
4581da177e4SLinus Torvalds 
4596f65126cSAlan Stern 	/* Accept arbitrarily long scatter-gather lists */
4602d7a3dc3SLaurentiu Tudor 	if (!hcd->localmem_pool)
4616f65126cSAlan Stern 		hcd->self.sg_tablesize = ~0;
4626f65126cSAlan Stern 
4631133cd8aSDmitry Baryshkov 	if (distrust_firmware)
4641133cd8aSDmitry Baryshkov 		ohci->flags |= OHCI_QUIRK_HUB_POWER;
4651133cd8aSDmitry Baryshkov 
466b7463c71SAlan Stern 	ohci->rh_state = OHCI_RH_HALTED;
4676a9062f3SDavid Brownell 	ohci->regs = hcd->regs;
4681da177e4SLinus Torvalds 
4696a9062f3SDavid Brownell 	/* REVISIT this BIOS handshake is now moved into PCI "quirks", and
4706a9062f3SDavid Brownell 	 * was never needed for most non-PCI systems ... remove the code?
4716a9062f3SDavid Brownell 	 */
4726a9062f3SDavid Brownell 
4731da177e4SLinus Torvalds #ifndef IR_DISABLE
4741da177e4SLinus Torvalds 	/* SMM owns the HC?  not for long! */
4751da177e4SLinus Torvalds 	if (!no_handshake && ohci_readl (ohci,
4761da177e4SLinus Torvalds 					&ohci->regs->control) & OHCI_CTRL_IR) {
4771da177e4SLinus Torvalds 		u32 temp;
4781da177e4SLinus Torvalds 
4791da177e4SLinus Torvalds 		ohci_dbg (ohci, "USB HC TakeOver from BIOS/SMM\n");
4801da177e4SLinus Torvalds 
4811da177e4SLinus Torvalds 		/* this timeout is arbitrary.  we make it long, so systems
4821da177e4SLinus Torvalds 		 * depending on usb keyboards may be usable even if the
4831da177e4SLinus Torvalds 		 * BIOS/SMM code seems pretty broken.
4841da177e4SLinus Torvalds 		 */
4851da177e4SLinus Torvalds 		temp = 500;	/* arbitrary: five seconds */
4861da177e4SLinus Torvalds 
4871da177e4SLinus Torvalds 		ohci_writel (ohci, OHCI_INTR_OC, &ohci->regs->intrenable);
4881da177e4SLinus Torvalds 		ohci_writel (ohci, OHCI_OCR, &ohci->regs->cmdstatus);
4891da177e4SLinus Torvalds 		while (ohci_readl (ohci, &ohci->regs->control) & OHCI_CTRL_IR) {
4901da177e4SLinus Torvalds 			msleep (10);
4911da177e4SLinus Torvalds 			if (--temp == 0) {
4921da177e4SLinus Torvalds 				ohci_err (ohci, "USB HC takeover failed!"
4931da177e4SLinus Torvalds 					"  (BIOS/SMM bug)\n");
4941da177e4SLinus Torvalds 				return -EBUSY;
4951da177e4SLinus Torvalds 			}
4961da177e4SLinus Torvalds 		}
4971da177e4SLinus Torvalds 		ohci_usb_reset (ohci);
4981da177e4SLinus Torvalds 	}
4991da177e4SLinus Torvalds #endif
5001da177e4SLinus Torvalds 
5011da177e4SLinus Torvalds 	/* Disable HC interrupts */
5021da177e4SLinus Torvalds 	ohci_writel (ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable);
5036a9062f3SDavid Brownell 
5046a9062f3SDavid Brownell 	/* flush the writes, and save key bits like RWC */
5056a9062f3SDavid Brownell 	if (ohci_readl (ohci, &ohci->regs->control) & OHCI_CTRL_RWC)
5066a9062f3SDavid Brownell 		ohci->hc_control |= OHCI_CTRL_RWC;
5071da177e4SLinus Torvalds 
508fdd13b36SDavid Brownell 	/* Read the number of ports unless overridden */
509fdd13b36SDavid Brownell 	if (ohci->num_ports == 0)
510fdd13b36SDavid Brownell 		ohci->num_ports = roothub_a(ohci) & RH_A_NDP;
511fdd13b36SDavid Brownell 
5121da177e4SLinus Torvalds 	if (ohci->hcca)
5131da177e4SLinus Torvalds 		return 0;
5141da177e4SLinus Torvalds 
515e99e88a9SKees Cook 	timer_setup(&ohci->io_watchdog, io_watchdog_func, 0);
516b2685bdaSShigeru Yoshida 	ohci->prev_frame_no = IO_WATCHDOG_OFF;
51781e38333SAlan Stern 
518b0310c2fSLaurentiu Tudor 	if (hcd->localmem_pool)
519ff2437beSFredrik Noring 		ohci->hcca = gen_pool_dma_alloc_align(hcd->localmem_pool,
520b0310c2fSLaurentiu Tudor 						sizeof(*ohci->hcca),
521ff2437beSFredrik Noring 						&ohci->hcca_dma, 256);
522b0310c2fSLaurentiu Tudor 	else
5236a9062f3SDavid Brownell 		ohci->hcca = dma_alloc_coherent(hcd->self.controller,
524b0310c2fSLaurentiu Tudor 						sizeof(*ohci->hcca),
525b0310c2fSLaurentiu Tudor 						&ohci->hcca_dma,
526b0310c2fSLaurentiu Tudor 						GFP_KERNEL);
5271da177e4SLinus Torvalds 	if (!ohci->hcca)
5281da177e4SLinus Torvalds 		return -ENOMEM;
5291da177e4SLinus Torvalds 
5301da177e4SLinus Torvalds 	if ((ret = ohci_mem_init (ohci)) < 0)
5316a9062f3SDavid Brownell 		ohci_stop (hcd);
5326a9062f3SDavid Brownell 	else {
5336a9062f3SDavid Brownell 		create_debug_files (ohci);
5346a9062f3SDavid Brownell 	}
5351da177e4SLinus Torvalds 
5361da177e4SLinus Torvalds 	return ret;
5371da177e4SLinus Torvalds }
5381da177e4SLinus Torvalds 
5391da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/
5401da177e4SLinus Torvalds 
5411da177e4SLinus Torvalds /* Start an OHCI controller, set the BUS operational
5421da177e4SLinus Torvalds  * resets USB and controller
5431da177e4SLinus Torvalds  * enable interrupts
5441da177e4SLinus Torvalds  */
5451da177e4SLinus Torvalds static int ohci_run (struct ohci_hcd *ohci)
5461da177e4SLinus Torvalds {
54796f90a8bSH Hartley Sweeten 	u32			mask, val;
5481da177e4SLinus Torvalds 	int			first = ohci->fminterval == 0;
5496a9062f3SDavid Brownell 	struct usb_hcd		*hcd = ohci_to_hcd(ohci);
5501da177e4SLinus Torvalds 
551b7463c71SAlan Stern 	ohci->rh_state = OHCI_RH_HALTED;
5521da177e4SLinus Torvalds 
5531da177e4SLinus Torvalds 	/* boot firmware should have set this up (5.1.1.3.1) */
5541da177e4SLinus Torvalds 	if (first) {
5551da177e4SLinus Torvalds 
55696f90a8bSH Hartley Sweeten 		val = ohci_readl (ohci, &ohci->regs->fminterval);
55796f90a8bSH Hartley Sweeten 		ohci->fminterval = val & 0x3fff;
5581da177e4SLinus Torvalds 		if (ohci->fminterval != FI)
5591da177e4SLinus Torvalds 			ohci_dbg (ohci, "fminterval delta %d\n",
5601da177e4SLinus Torvalds 				ohci->fminterval - FI);
5611da177e4SLinus Torvalds 		ohci->fminterval |= FSMP (ohci->fminterval) << 16;
5621da177e4SLinus Torvalds 		/* also: power/overcurrent flags in roothub.a */
5631da177e4SLinus Torvalds 	}
5641da177e4SLinus Torvalds 
5656fd9086aSAlan Stern 	/* Reset USB nearly "by the book".  RemoteWakeupConnected has
5666fd9086aSAlan Stern 	 * to be checked in case boot firmware (BIOS/SMM/...) has set up
5676fd9086aSAlan Stern 	 * wakeup in a way the bus isn't aware of (e.g., legacy PCI PM).
5686fd9086aSAlan Stern 	 * If the bus glue detected wakeup capability then it should
569bcca06efSAlan Stern 	 * already be enabled; if so we'll just enable it again.
5701da177e4SLinus Torvalds 	 */
571bcca06efSAlan Stern 	if ((ohci->hc_control & OHCI_CTRL_RWC) != 0)
572bcca06efSAlan Stern 		device_set_wakeup_capable(hcd->self.controller, 1);
5731da177e4SLinus Torvalds 
5741da177e4SLinus Torvalds 	switch (ohci->hc_control & OHCI_CTRL_HCFS) {
5751da177e4SLinus Torvalds 	case OHCI_USB_OPER:
57696f90a8bSH Hartley Sweeten 		val = 0;
5771da177e4SLinus Torvalds 		break;
5781da177e4SLinus Torvalds 	case OHCI_USB_SUSPEND:
5791da177e4SLinus Torvalds 	case OHCI_USB_RESUME:
5801da177e4SLinus Torvalds 		ohci->hc_control &= OHCI_CTRL_RWC;
5811da177e4SLinus Torvalds 		ohci->hc_control |= OHCI_USB_RESUME;
58296f90a8bSH Hartley Sweeten 		val = 10 /* msec wait */;
5831da177e4SLinus Torvalds 		break;
5841da177e4SLinus Torvalds 	// case OHCI_USB_RESET:
5851da177e4SLinus Torvalds 	default:
5861da177e4SLinus Torvalds 		ohci->hc_control &= OHCI_CTRL_RWC;
5871da177e4SLinus Torvalds 		ohci->hc_control |= OHCI_USB_RESET;
58896f90a8bSH Hartley Sweeten 		val = 50 /* msec wait */;
5891da177e4SLinus Torvalds 		break;
5901da177e4SLinus Torvalds 	}
5911da177e4SLinus Torvalds 	ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
5921da177e4SLinus Torvalds 	// flush the writes
5931da177e4SLinus Torvalds 	(void) ohci_readl (ohci, &ohci->regs->control);
59496f90a8bSH Hartley Sweeten 	msleep(val);
595383975d7SAlan Stern 
5961da177e4SLinus Torvalds 	memset (ohci->hcca, 0, sizeof (struct ohci_hcca));
5971da177e4SLinus Torvalds 
5981da177e4SLinus Torvalds 	/* 2msec timelimit here means no irqs/preempt */
5991da177e4SLinus Torvalds 	spin_lock_irq (&ohci->lock);
6001da177e4SLinus Torvalds 
6011da177e4SLinus Torvalds retry:
6021da177e4SLinus Torvalds 	/* HC Reset requires max 10 us delay */
6031da177e4SLinus Torvalds 	ohci_writel (ohci, OHCI_HCR,  &ohci->regs->cmdstatus);
60496f90a8bSH Hartley Sweeten 	val = 30;	/* ... allow extra time */
6051da177e4SLinus Torvalds 	while ((ohci_readl (ohci, &ohci->regs->cmdstatus) & OHCI_HCR) != 0) {
60696f90a8bSH Hartley Sweeten 		if (--val == 0) {
6071da177e4SLinus Torvalds 			spin_unlock_irq (&ohci->lock);
6081da177e4SLinus Torvalds 			ohci_err (ohci, "USB HC reset timed out!\n");
6091da177e4SLinus Torvalds 			return -1;
6101da177e4SLinus Torvalds 		}
6111da177e4SLinus Torvalds 		udelay (1);
6121da177e4SLinus Torvalds 	}
6131da177e4SLinus Torvalds 
6141da177e4SLinus Torvalds 	/* now we're in the SUSPEND state ... must go OPERATIONAL
6151da177e4SLinus Torvalds 	 * within 2msec else HC enters RESUME
6161da177e4SLinus Torvalds 	 *
6171da177e4SLinus Torvalds 	 * ... but some hardware won't init fmInterval "by the book"
6181da177e4SLinus Torvalds 	 * (SiS, OPTi ...), so reset again instead.  SiS doesn't need
6191da177e4SLinus Torvalds 	 * this if we write fmInterval after we're OPERATIONAL.
6201da177e4SLinus Torvalds 	 * Unclear about ALi, ServerWorks, and others ... this could
6211da177e4SLinus Torvalds 	 * easily be a longstanding bug in chip init on Linux.
6221da177e4SLinus Torvalds 	 */
6231da177e4SLinus Torvalds 	if (ohci->flags & OHCI_QUIRK_INITRESET) {
6241da177e4SLinus Torvalds 		ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
6251da177e4SLinus Torvalds 		// flush those writes
6261da177e4SLinus Torvalds 		(void) ohci_readl (ohci, &ohci->regs->control);
6271da177e4SLinus Torvalds 	}
6281da177e4SLinus Torvalds 
6291da177e4SLinus Torvalds 	/* Tell the controller where the control and bulk lists are
6301da177e4SLinus Torvalds 	 * The lists are empty now. */
6311da177e4SLinus Torvalds 	ohci_writel (ohci, 0, &ohci->regs->ed_controlhead);
6321da177e4SLinus Torvalds 	ohci_writel (ohci, 0, &ohci->regs->ed_bulkhead);
6331da177e4SLinus Torvalds 
6341da177e4SLinus Torvalds 	/* a reset clears this */
6351da177e4SLinus Torvalds 	ohci_writel (ohci, (u32) ohci->hcca_dma, &ohci->regs->hcca);
6361da177e4SLinus Torvalds 
6371da177e4SLinus Torvalds 	periodic_reinit (ohci);
6381da177e4SLinus Torvalds 
6391da177e4SLinus Torvalds 	/* some OHCI implementations are finicky about how they init.
6401da177e4SLinus Torvalds 	 * bogus values here mean not even enumeration could work.
6411da177e4SLinus Torvalds 	 */
6421da177e4SLinus Torvalds 	if ((ohci_readl (ohci, &ohci->regs->fminterval) & 0x3fff0000) == 0
6431da177e4SLinus Torvalds 			|| !ohci_readl (ohci, &ohci->regs->periodicstart)) {
6441da177e4SLinus Torvalds 		if (!(ohci->flags & OHCI_QUIRK_INITRESET)) {
6451da177e4SLinus Torvalds 			ohci->flags |= OHCI_QUIRK_INITRESET;
6461da177e4SLinus Torvalds 			ohci_dbg (ohci, "enabling initreset quirk\n");
6471da177e4SLinus Torvalds 			goto retry;
6481da177e4SLinus Torvalds 		}
6491da177e4SLinus Torvalds 		spin_unlock_irq (&ohci->lock);
6501da177e4SLinus Torvalds 		ohci_err (ohci, "init err (%08x %04x)\n",
6511da177e4SLinus Torvalds 			ohci_readl (ohci, &ohci->regs->fminterval),
6521da177e4SLinus Torvalds 			ohci_readl (ohci, &ohci->regs->periodicstart));
6531da177e4SLinus Torvalds 		return -EOVERFLOW;
6541da177e4SLinus Torvalds 	}
6551da177e4SLinus Torvalds 
65637ebb549SPetr Mladek 	/* use rhsc irqs after hub_wq is allocated */
657541c7d43SAlan Stern 	set_bit(HCD_FLAG_POLL_RH, &hcd->flags);
658d413984aSDavid Brownell 	hcd->uses_new_polling = 1;
659d413984aSDavid Brownell 
6601da177e4SLinus Torvalds 	/* start controller operations */
6611da177e4SLinus Torvalds 	ohci->hc_control &= OHCI_CTRL_RWC;
6621da177e4SLinus Torvalds 	ohci->hc_control |= OHCI_CONTROL_INIT | OHCI_USB_OPER;
6631da177e4SLinus Torvalds 	ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
664b7463c71SAlan Stern 	ohci->rh_state = OHCI_RH_RUNNING;
6651da177e4SLinus Torvalds 
6661da177e4SLinus Torvalds 	/* wake on ConnectStatusChange, matching external hubs */
6671da177e4SLinus Torvalds 	ohci_writel (ohci, RH_HS_DRWE, &ohci->regs->roothub.status);
6681da177e4SLinus Torvalds 
6691da177e4SLinus Torvalds 	/* Choose the interrupts we care about now, others later on demand */
6701da177e4SLinus Torvalds 	mask = OHCI_INTR_INIT;
671d413984aSDavid Brownell 	ohci_writel (ohci, ~0, &ohci->regs->intrstatus);
6721da177e4SLinus Torvalds 	ohci_writel (ohci, mask, &ohci->regs->intrenable);
6731da177e4SLinus Torvalds 
6741da177e4SLinus Torvalds 	/* handle root hub init quirks ... */
67596f90a8bSH Hartley Sweeten 	val = roothub_a (ohci);
67696f90a8bSH Hartley Sweeten 	val &= ~(RH_A_PSM | RH_A_OCPM);
6771da177e4SLinus Torvalds 	if (ohci->flags & OHCI_QUIRK_SUPERIO) {
6781da177e4SLinus Torvalds 		/* NSC 87560 and maybe others */
67996f90a8bSH Hartley Sweeten 		val |= RH_A_NOCP;
68096f90a8bSH Hartley Sweeten 		val &= ~(RH_A_POTPGT | RH_A_NPS);
68196f90a8bSH Hartley Sweeten 		ohci_writel (ohci, val, &ohci->regs->roothub.a);
6821133cd8aSDmitry Baryshkov 	} else if ((ohci->flags & OHCI_QUIRK_AMD756) ||
6831133cd8aSDmitry Baryshkov 			(ohci->flags & OHCI_QUIRK_HUB_POWER)) {
6841da177e4SLinus Torvalds 		/* hub power always on; required for AMD-756 and some
6851da177e4SLinus Torvalds 		 * Mac platforms.  ganged overcurrent reporting, if any.
6861da177e4SLinus Torvalds 		 */
68796f90a8bSH Hartley Sweeten 		val |= RH_A_NPS;
68896f90a8bSH Hartley Sweeten 		ohci_writel (ohci, val, &ohci->regs->roothub.a);
6891da177e4SLinus Torvalds 	}
6901da177e4SLinus Torvalds 	ohci_writel (ohci, RH_HS_LPSC, &ohci->regs->roothub.status);
69196f90a8bSH Hartley Sweeten 	ohci_writel (ohci, (val & RH_A_NPS) ? 0 : RH_B_PPCM,
6921da177e4SLinus Torvalds 						&ohci->regs->roothub.b);
6931da177e4SLinus Torvalds 	// flush those writes
6941da177e4SLinus Torvalds 	(void) ohci_readl (ohci, &ohci->regs->control);
6951da177e4SLinus Torvalds 
696d413984aSDavid Brownell 	ohci->next_statechange = jiffies + STATECHANGE_DELAY;
6971da177e4SLinus Torvalds 	spin_unlock_irq (&ohci->lock);
6981da177e4SLinus Torvalds 
6991da177e4SLinus Torvalds 	// POTPGT delay is bits 24-31, in 2 ms units.
70096f90a8bSH Hartley Sweeten 	mdelay ((val >> 23) & 0x1fe);
7011da177e4SLinus Torvalds 
702256dbcd8SAlan Stern 	ohci_dump(ohci);
7031da177e4SLinus Torvalds 
7041da177e4SLinus Torvalds 	return 0;
7051da177e4SLinus Torvalds }
7061da177e4SLinus Torvalds 
70795e44d44SManjunath Goudar /* ohci_setup routine for generic controller initialization */
70895e44d44SManjunath Goudar 
70995e44d44SManjunath Goudar int ohci_setup(struct usb_hcd *hcd)
71095e44d44SManjunath Goudar {
71195e44d44SManjunath Goudar 	struct ohci_hcd		*ohci = hcd_to_ohci(hcd);
71295e44d44SManjunath Goudar 
71395e44d44SManjunath Goudar 	ohci_hcd_init(ohci);
71495e44d44SManjunath Goudar 
71595e44d44SManjunath Goudar 	return ohci_init(ohci);
71695e44d44SManjunath Goudar }
71795e44d44SManjunath Goudar EXPORT_SYMBOL_GPL(ohci_setup);
71895e44d44SManjunath Goudar 
71995e44d44SManjunath Goudar /* ohci_start routine for generic controller start of all OHCI bus glue */
72095e44d44SManjunath Goudar static int ohci_start(struct usb_hcd *hcd)
72195e44d44SManjunath Goudar {
72295e44d44SManjunath Goudar 	struct ohci_hcd		*ohci = hcd_to_ohci(hcd);
72395e44d44SManjunath Goudar 	int	ret;
72495e44d44SManjunath Goudar 
72595e44d44SManjunath Goudar 	ret = ohci_run(ohci);
72695e44d44SManjunath Goudar 	if (ret < 0) {
72795e44d44SManjunath Goudar 		ohci_err(ohci, "can't start\n");
72895e44d44SManjunath Goudar 		ohci_stop(hcd);
72995e44d44SManjunath Goudar 	}
73095e44d44SManjunath Goudar 	return ret;
73195e44d44SManjunath Goudar }
73295e44d44SManjunath Goudar 
7331da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/
7341da177e4SLinus Torvalds 
73581e38333SAlan Stern /*
73681e38333SAlan Stern  * Some OHCI controllers are known to lose track of completed TDs.  They
73781e38333SAlan Stern  * don't add the TDs to the hardware done queue, which means we never see
73881e38333SAlan Stern  * them as being completed.
73981e38333SAlan Stern  *
74081e38333SAlan Stern  * This watchdog routine checks for such problems.  Without some way to
74181e38333SAlan Stern  * tell when those TDs have completed, we would never take their EDs off
74281e38333SAlan Stern  * the unlink list.  As a result, URBs could never be dequeued and
74381e38333SAlan Stern  * endpoints could never be released.
74481e38333SAlan Stern  */
745e99e88a9SKees Cook static void io_watchdog_func(struct timer_list *t)
74681e38333SAlan Stern {
747e99e88a9SKees Cook 	struct ohci_hcd	*ohci = from_timer(ohci, t, io_watchdog);
74881e38333SAlan Stern 	bool		takeback_all_pending = false;
74981e38333SAlan Stern 	u32		status;
75081e38333SAlan Stern 	u32		head;
75181e38333SAlan Stern 	struct ed	*ed;
75281e38333SAlan Stern 	struct td	*td, *td_start, *td_next;
753b2685bdaSShigeru Yoshida 	unsigned	frame_no, prev_frame_no = IO_WATCHDOG_OFF;
75481e38333SAlan Stern 	unsigned long	flags;
75581e38333SAlan Stern 
75681e38333SAlan Stern 	spin_lock_irqsave(&ohci->lock, flags);
75781e38333SAlan Stern 
75881e38333SAlan Stern 	/*
75981e38333SAlan Stern 	 * One way to lose track of completed TDs is if the controller
76081e38333SAlan Stern 	 * never writes back the done queue head.  If it hasn't been
76181e38333SAlan Stern 	 * written back since the last time this function ran and if it
76281e38333SAlan Stern 	 * was non-empty at that time, something is badly wrong with the
76381e38333SAlan Stern 	 * hardware.
76481e38333SAlan Stern 	 */
76581e38333SAlan Stern 	status = ohci_readl(ohci, &ohci->regs->intrstatus);
76681e38333SAlan Stern 	if (!(status & OHCI_INTR_WDH) && ohci->wdh_cnt == ohci->prev_wdh_cnt) {
76781e38333SAlan Stern 		if (ohci->prev_donehead) {
76881e38333SAlan Stern 			ohci_err(ohci, "HcDoneHead not written back; disabled\n");
769499b3803SAlan Stern  died:
77081e38333SAlan Stern 			usb_hc_died(ohci_to_hcd(ohci));
77181e38333SAlan Stern 			ohci_dump(ohci);
772a349b95dSYoshihiro Shimoda 			_ohci_shutdown(ohci_to_hcd(ohci));
77381e38333SAlan Stern 			goto done;
77481e38333SAlan Stern 		} else {
77581e38333SAlan Stern 			/* No write back because the done queue was empty */
77681e38333SAlan Stern 			takeback_all_pending = true;
77781e38333SAlan Stern 		}
77881e38333SAlan Stern 	}
77981e38333SAlan Stern 
78081e38333SAlan Stern 	/* Check every ED which might have pending TDs */
78181e38333SAlan Stern 	list_for_each_entry(ed, &ohci->eds_in_use, in_use_list) {
78281e38333SAlan Stern 		if (ed->pending_td) {
78381e38333SAlan Stern 			if (takeback_all_pending ||
78481e38333SAlan Stern 					OKAY_TO_TAKEBACK(ohci, ed)) {
78581e38333SAlan Stern 				unsigned tmp = hc32_to_cpu(ohci, ed->hwINFO);
78681e38333SAlan Stern 
78781e38333SAlan Stern 				ohci_dbg(ohci, "takeback pending TD for dev %d ep 0x%x\n",
78881e38333SAlan Stern 						0x007f & tmp,
78981e38333SAlan Stern 						(0x000f & (tmp >> 7)) +
79081e38333SAlan Stern 							((tmp & ED_IN) >> 5));
79181e38333SAlan Stern 				add_to_done_list(ohci, ed->pending_td);
79281e38333SAlan Stern 			}
79381e38333SAlan Stern 		}
79481e38333SAlan Stern 
79581e38333SAlan Stern 		/* Starting from the latest pending TD, */
79681e38333SAlan Stern 		td = ed->pending_td;
79781e38333SAlan Stern 
79881e38333SAlan Stern 		/* or the last TD on the done list, */
79981e38333SAlan Stern 		if (!td) {
80081e38333SAlan Stern 			list_for_each_entry(td_next, &ed->td_list, td_list) {
80181e38333SAlan Stern 				if (!td_next->next_dl_td)
80281e38333SAlan Stern 					break;
80381e38333SAlan Stern 				td = td_next;
80481e38333SAlan Stern 			}
80581e38333SAlan Stern 		}
80681e38333SAlan Stern 
80781e38333SAlan Stern 		/* find the last TD processed by the controller. */
8086aa7de05SMark Rutland 		head = hc32_to_cpu(ohci, READ_ONCE(ed->hwHeadP)) & TD_MASK;
80981e38333SAlan Stern 		td_start = td;
81081e38333SAlan Stern 		td_next = list_prepare_entry(td, &ed->td_list, td_list);
81181e38333SAlan Stern 		list_for_each_entry_continue(td_next, &ed->td_list, td_list) {
81281e38333SAlan Stern 			if (head == (u32) td_next->td_dma)
81381e38333SAlan Stern 				break;
81481e38333SAlan Stern 			td = td_next;	/* head pointer has passed this TD */
81581e38333SAlan Stern 		}
81681e38333SAlan Stern 		if (td != td_start) {
81781e38333SAlan Stern 			/*
81881e38333SAlan Stern 			 * In case a WDH cycle is in progress, we will wait
81981e38333SAlan Stern 			 * for the next two cycles to complete before assuming
82081e38333SAlan Stern 			 * this TD will never get on the done queue.
82181e38333SAlan Stern 			 */
82281e38333SAlan Stern 			ed->takeback_wdh_cnt = ohci->wdh_cnt + 2;
82381e38333SAlan Stern 			ed->pending_td = td;
82481e38333SAlan Stern 		}
82581e38333SAlan Stern 	}
82681e38333SAlan Stern 
82781e38333SAlan Stern 	ohci_work(ohci);
82881e38333SAlan Stern 
82981e38333SAlan Stern 	if (ohci->rh_state == OHCI_RH_RUNNING) {
830499b3803SAlan Stern 
831499b3803SAlan Stern 		/*
832499b3803SAlan Stern 		 * Sometimes a controller just stops working.  We can tell
833499b3803SAlan Stern 		 * by checking that the frame counter has advanced since
834499b3803SAlan Stern 		 * the last time we ran.
835499b3803SAlan Stern 		 *
836499b3803SAlan Stern 		 * But be careful: Some controllers violate the spec by
837499b3803SAlan Stern 		 * stopping their frame counter when no ports are active.
838499b3803SAlan Stern 		 */
839499b3803SAlan Stern 		frame_no = ohci_frame_no(ohci);
840499b3803SAlan Stern 		if (frame_no == ohci->prev_frame_no) {
841499b3803SAlan Stern 			int		active_cnt = 0;
842499b3803SAlan Stern 			int		i;
843499b3803SAlan Stern 			unsigned	tmp;
844499b3803SAlan Stern 
845499b3803SAlan Stern 			for (i = 0; i < ohci->num_ports; ++i) {
846499b3803SAlan Stern 				tmp = roothub_portstatus(ohci, i);
847499b3803SAlan Stern 				/* Enabled and not suspended? */
848499b3803SAlan Stern 				if ((tmp & RH_PS_PES) && !(tmp & RH_PS_PSS))
849499b3803SAlan Stern 					++active_cnt;
850499b3803SAlan Stern 			}
851499b3803SAlan Stern 
852499b3803SAlan Stern 			if (active_cnt > 0) {
853499b3803SAlan Stern 				ohci_err(ohci, "frame counter not updating; disabled\n");
854499b3803SAlan Stern 				goto died;
855499b3803SAlan Stern 			}
856499b3803SAlan Stern 		}
85781e38333SAlan Stern 		if (!list_empty(&ohci->eds_in_use)) {
858b2685bdaSShigeru Yoshida 			prev_frame_no = frame_no;
85981e38333SAlan Stern 			ohci->prev_wdh_cnt = ohci->wdh_cnt;
86081e38333SAlan Stern 			ohci->prev_donehead = ohci_readl(ohci,
86181e38333SAlan Stern 					&ohci->regs->donehead);
86281e38333SAlan Stern 			mod_timer(&ohci->io_watchdog,
86381e38333SAlan Stern 					jiffies + IO_WATCHDOG_DELAY);
86481e38333SAlan Stern 		}
86581e38333SAlan Stern 	}
86681e38333SAlan Stern 
86781e38333SAlan Stern  done:
868b2685bdaSShigeru Yoshida 	ohci->prev_frame_no = prev_frame_no;
86981e38333SAlan Stern 	spin_unlock_irqrestore(&ohci->lock, flags);
87081e38333SAlan Stern }
87181e38333SAlan Stern 
8721da177e4SLinus Torvalds /* an interrupt happens */
8731da177e4SLinus Torvalds 
8747d12e780SDavid Howells static irqreturn_t ohci_irq (struct usb_hcd *hcd)
8751da177e4SLinus Torvalds {
8761da177e4SLinus Torvalds 	struct ohci_hcd		*ohci = hcd_to_ohci (hcd);
8771da177e4SLinus Torvalds 	struct ohci_regs __iomem *regs = ohci->regs;
8781da177e4SLinus Torvalds 	int			ints;
8791da177e4SLinus Torvalds 
880565227c0SBenjamin Herrenschmidt 	/* Read interrupt status (and flush pending writes).  We ignore the
881565227c0SBenjamin Herrenschmidt 	 * optimization of checking the LSB of hcca->done_head; it doesn't
882565227c0SBenjamin Herrenschmidt 	 * work on all systems (edge triggering for OHCI can be a factor).
88389a0fd18SMike Nuss 	 */
884565227c0SBenjamin Herrenschmidt 	ints = ohci_readl(ohci, &regs->intrstatus);
8851da177e4SLinus Torvalds 
886565227c0SBenjamin Herrenschmidt 	/* Check for an all 1's result which is a typical consequence
887565227c0SBenjamin Herrenschmidt 	 * of dead, unclocked, or unplugged (CardBus...) devices
888565227c0SBenjamin Herrenschmidt 	 */
889565227c0SBenjamin Herrenschmidt 	if (ints == ~(u32)0) {
890b7463c71SAlan Stern 		ohci->rh_state = OHCI_RH_HALTED;
8911da177e4SLinus Torvalds 		ohci_dbg (ohci, "device removed!\n");
89269fff59dSAlan Stern 		usb_hc_died(hcd);
8931da177e4SLinus Torvalds 		return IRQ_HANDLED;
894565227c0SBenjamin Herrenschmidt 	}
895565227c0SBenjamin Herrenschmidt 
896565227c0SBenjamin Herrenschmidt 	/* We only care about interrupts that are enabled */
897565227c0SBenjamin Herrenschmidt 	ints &= ohci_readl(ohci, &regs->intrenable);
8981da177e4SLinus Torvalds 
8991da177e4SLinus Torvalds 	/* interrupt for some other device? */
900b7463c71SAlan Stern 	if (ints == 0 || unlikely(ohci->rh_state == OHCI_RH_HALTED))
9011da177e4SLinus Torvalds 		return IRQ_NOTMINE;
9021da177e4SLinus Torvalds 
9031da177e4SLinus Torvalds 	if (ints & OHCI_INTR_UE) {
904d576bb9fSMichael Hanselmann 		// e.g. due to PCI Master/Target Abort
90589a0fd18SMike Nuss 		if (quirk_nec(ohci)) {
906d576bb9fSMichael Hanselmann 			/* Workaround for a silicon bug in some NEC chips used
907d576bb9fSMichael Hanselmann 			 * in Apple's PowerBooks. Adapted from Darwin code.
908d576bb9fSMichael Hanselmann 			 */
909d576bb9fSMichael Hanselmann 			ohci_err (ohci, "OHCI Unrecoverable Error, scheduling NEC chip restart\n");
910d576bb9fSMichael Hanselmann 
911d576bb9fSMichael Hanselmann 			ohci_writel (ohci, OHCI_INTR_UE, &regs->intrdisable);
912d576bb9fSMichael Hanselmann 
913d576bb9fSMichael Hanselmann 			schedule_work (&ohci->nec_work);
914d576bb9fSMichael Hanselmann 		} else {
9151da177e4SLinus Torvalds 			ohci_err (ohci, "OHCI Unrecoverable Error, disabled\n");
916b7463c71SAlan Stern 			ohci->rh_state = OHCI_RH_HALTED;
91769fff59dSAlan Stern 			usb_hc_died(hcd);
918d576bb9fSMichael Hanselmann 		}
9191da177e4SLinus Torvalds 
920256dbcd8SAlan Stern 		ohci_dump(ohci);
9211da177e4SLinus Torvalds 		ohci_usb_reset (ohci);
9221da177e4SLinus Torvalds 	}
9231da177e4SLinus Torvalds 
924583ceadaSAlan Stern 	if (ints & OHCI_INTR_RHSC) {
925d2c4254fSOliver Neukum 		ohci_dbg(ohci, "rhsc\n");
926583ceadaSAlan Stern 		ohci->next_statechange = jiffies + STATECHANGE_DELAY;
927583ceadaSAlan Stern 		ohci_writel(ohci, OHCI_INTR_RD | OHCI_INTR_RHSC,
928583ceadaSAlan Stern 				&regs->intrstatus);
929052ac01aSAlan Stern 
930052ac01aSAlan Stern 		/* NOTE: Vendors didn't always make the same implementation
931052ac01aSAlan Stern 		 * choices for RHSC.  Many followed the spec; RHSC triggers
932052ac01aSAlan Stern 		 * on an edge, like setting and maybe clearing a port status
933052ac01aSAlan Stern 		 * change bit.  With others it's level-triggered, active
93437ebb549SPetr Mladek 		 * until hub_wq clears all the port status change bits.  We'll
93537ebb549SPetr Mladek 		 * always disable it here and rely on polling until hub_wq
936052ac01aSAlan Stern 		 * re-enables it.
937052ac01aSAlan Stern 		 */
938052ac01aSAlan Stern 		ohci_writel(ohci, OHCI_INTR_RHSC, &regs->intrdisable);
939583ceadaSAlan Stern 		usb_hcd_poll_rh_status(hcd);
940583ceadaSAlan Stern 	}
941583ceadaSAlan Stern 
942583ceadaSAlan Stern 	/* For connect and disconnect events, we expect the controller
943583ceadaSAlan Stern 	 * to turn on RHSC along with RD.  But for remote wakeup events
944583ceadaSAlan Stern 	 * this might not happen.
945583ceadaSAlan Stern 	 */
946583ceadaSAlan Stern 	else if (ints & OHCI_INTR_RD) {
947d2c4254fSOliver Neukum 		ohci_dbg(ohci, "resume detect\n");
948e0fd3cbcSDavid Brownell 		ohci_writel(ohci, OHCI_INTR_RD, &regs->intrstatus);
949541c7d43SAlan Stern 		set_bit(HCD_FLAG_POLL_RH, &hcd->flags);
9508d1a243bSAlan Stern 		if (ohci->autostop) {
9518d1a243bSAlan Stern 			spin_lock (&ohci->lock);
9528d1a243bSAlan Stern 			ohci_rh_resume (ohci);
9538d1a243bSAlan Stern 			spin_unlock (&ohci->lock);
9548d1a243bSAlan Stern 		} else
955f197b2c5SDavid Brownell 			usb_hcd_resume_root_hub(hcd);
9561da177e4SLinus Torvalds 	}
9571da177e4SLinus Torvalds 
9581da177e4SLinus Torvalds 	spin_lock(&ohci->lock);
959c6fcb85eSAlan Stern 	if (ints & OHCI_INTR_WDH)
960c6fcb85eSAlan Stern 		update_done_list(ohci);
9611da177e4SLinus Torvalds 
9621da177e4SLinus Torvalds 	/* could track INTR_SO to reduce available PCI/... bandwidth */
9631da177e4SLinus Torvalds 
9641da177e4SLinus Torvalds 	/* handle any pending URB/ED unlinks, leaving INTR_SF enabled
9651da177e4SLinus Torvalds 	 * when there's still unlinking to be done (next frame).
9661da177e4SLinus Torvalds 	 */
967cdb4dd15SAlan Stern 	ohci_work(ohci);
96895d9a01dSAlan Stern 	if ((ints & OHCI_INTR_SF) != 0 && !ohci->ed_rm_list
969b7463c71SAlan Stern 			&& ohci->rh_state == OHCI_RH_RUNNING)
9701da177e4SLinus Torvalds 		ohci_writel (ohci, OHCI_INTR_SF, &regs->intrdisable);
9711da177e4SLinus Torvalds 
972b7463c71SAlan Stern 	if (ohci->rh_state == OHCI_RH_RUNNING) {
9731da177e4SLinus Torvalds 		ohci_writel (ohci, ints, &regs->intrstatus);
97481e38333SAlan Stern 		if (ints & OHCI_INTR_WDH)
97581e38333SAlan Stern 			++ohci->wdh_cnt;
97681e38333SAlan Stern 
9771da177e4SLinus Torvalds 		ohci_writel (ohci, OHCI_INTR_MIE, &regs->intrenable);
9781da177e4SLinus Torvalds 		// flush those writes
9791da177e4SLinus Torvalds 		(void) ohci_readl (ohci, &ohci->regs->control);
9801da177e4SLinus Torvalds 	}
981c6fcb85eSAlan Stern 	spin_unlock(&ohci->lock);
9821da177e4SLinus Torvalds 
9831da177e4SLinus Torvalds 	return IRQ_HANDLED;
9841da177e4SLinus Torvalds }
9851da177e4SLinus Torvalds 
9861da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/
9871da177e4SLinus Torvalds 
9881da177e4SLinus Torvalds static void ohci_stop (struct usb_hcd *hcd)
9891da177e4SLinus Torvalds {
9901da177e4SLinus Torvalds 	struct ohci_hcd		*ohci = hcd_to_ohci (hcd);
9911da177e4SLinus Torvalds 
992256dbcd8SAlan Stern 	ohci_dump(ohci);
9931da177e4SLinus Torvalds 
994569ff2deSTejun Heo 	if (quirk_nec(ohci))
99543829731STejun Heo 		flush_work(&ohci->nec_work);
99681e38333SAlan Stern 	del_timer_sync(&ohci->io_watchdog);
997b2685bdaSShigeru Yoshida 	ohci->prev_frame_no = IO_WATCHDOG_OFF;
9981da177e4SLinus Torvalds 
9991da177e4SLinus Torvalds 	ohci_writel (ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable);
1000435932f2Scaizhiyong 	ohci_usb_reset(ohci);
100171795c1dSPete Zaitcev 	free_irq(hcd->irq, hcd);
1002cd70469dSFelipe Balbi 	hcd->irq = 0;
10031da177e4SLinus Torvalds 
1004ab1666c1SLibin Yang 	if (quirk_amdiso(ohci))
1005ad93562bSAndiry Xu 		usb_amd_dev_put();
100689a0fd18SMike Nuss 
10071da177e4SLinus Torvalds 	remove_debug_files (ohci);
10081da177e4SLinus Torvalds 	ohci_mem_cleanup (ohci);
10091da177e4SLinus Torvalds 	if (ohci->hcca) {
1010b0310c2fSLaurentiu Tudor 		if (hcd->localmem_pool)
1011b0310c2fSLaurentiu Tudor 			gen_pool_free(hcd->localmem_pool,
1012b0310c2fSLaurentiu Tudor 				      (unsigned long)ohci->hcca,
1013b0310c2fSLaurentiu Tudor 				      sizeof(*ohci->hcca));
1014b0310c2fSLaurentiu Tudor 		else
10151da177e4SLinus Torvalds 			dma_free_coherent(hcd->self.controller,
1016b0310c2fSLaurentiu Tudor 					  sizeof(*ohci->hcca),
10171da177e4SLinus Torvalds 					  ohci->hcca, ohci->hcca_dma);
10181da177e4SLinus Torvalds 		ohci->hcca = NULL;
10191da177e4SLinus Torvalds 		ohci->hcca_dma = 0;
10201da177e4SLinus Torvalds 	}
10211da177e4SLinus Torvalds }
10221da177e4SLinus Torvalds 
10231da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/
10241da177e4SLinus Torvalds 
10252c93e790Syuan linyu #if defined(CONFIG_PM) || defined(CONFIG_USB_PCI)
1026da6fb570SDavid Brownell 
10271da177e4SLinus Torvalds /* must not be called from interrupt context */
102895e44d44SManjunath Goudar int ohci_restart(struct ohci_hcd *ohci)
10291da177e4SLinus Torvalds {
10301da177e4SLinus Torvalds 	int temp;
10311da177e4SLinus Torvalds 	int i;
10321da177e4SLinus Torvalds 	struct urb_priv *priv;
10331da177e4SLinus Torvalds 
103495e44d44SManjunath Goudar 	ohci_init(ohci);
10351da177e4SLinus Torvalds 	spin_lock_irq(&ohci->lock);
1036b7463c71SAlan Stern 	ohci->rh_state = OHCI_RH_HALTED;
1037d576bb9fSMichael Hanselmann 
1038d576bb9fSMichael Hanselmann 	/* Recycle any "live" eds/tds (and urbs). */
10391da177e4SLinus Torvalds 	if (!list_empty (&ohci->pending))
10401da177e4SLinus Torvalds 		ohci_dbg(ohci, "abort schedule...\n");
10411da177e4SLinus Torvalds 	list_for_each_entry (priv, &ohci->pending, pending) {
10421da177e4SLinus Torvalds 		struct urb	*urb = priv->td[0]->urb;
10431da177e4SLinus Torvalds 		struct ed	*ed = priv->ed;
10441da177e4SLinus Torvalds 
10451da177e4SLinus Torvalds 		switch (ed->state) {
10461da177e4SLinus Torvalds 		case ED_OPER:
10471da177e4SLinus Torvalds 			ed->state = ED_UNLINK;
10481da177e4SLinus Torvalds 			ed->hwINFO |= cpu_to_hc32(ohci, ED_DEQUEUE);
10491da177e4SLinus Torvalds 			ed_deschedule (ohci, ed);
10501da177e4SLinus Torvalds 
10511da177e4SLinus Torvalds 			ed->ed_next = ohci->ed_rm_list;
10521da177e4SLinus Torvalds 			ed->ed_prev = NULL;
10531da177e4SLinus Torvalds 			ohci->ed_rm_list = ed;
1054*e288fc98SGustavo A. R. Silva 			fallthrough;
10551da177e4SLinus Torvalds 		case ED_UNLINK:
10561da177e4SLinus Torvalds 			break;
10571da177e4SLinus Torvalds 		default:
10581da177e4SLinus Torvalds 			ohci_dbg(ohci, "bogus ed %p state %d\n",
10591da177e4SLinus Torvalds 					ed, ed->state);
10601da177e4SLinus Torvalds 		}
10611da177e4SLinus Torvalds 
106255d84968SAlan Stern 		if (!urb->unlinked)
106355d84968SAlan Stern 			urb->unlinked = -ESHUTDOWN;
10641da177e4SLinus Torvalds 	}
1065cdb4dd15SAlan Stern 	ohci_work(ohci);
10661da177e4SLinus Torvalds 	spin_unlock_irq(&ohci->lock);
10671da177e4SLinus Torvalds 
10681da177e4SLinus Torvalds 	/* paranoia, in case that didn't work: */
10691da177e4SLinus Torvalds 
10701da177e4SLinus Torvalds 	/* empty the interrupt branches */
10711da177e4SLinus Torvalds 	for (i = 0; i < NUM_INTS; i++) ohci->load [i] = 0;
10721da177e4SLinus Torvalds 	for (i = 0; i < NUM_INTS; i++) ohci->hcca->int_table [i] = 0;
10731da177e4SLinus Torvalds 
10741da177e4SLinus Torvalds 	/* no EDs to remove */
10751da177e4SLinus Torvalds 	ohci->ed_rm_list = NULL;
10761da177e4SLinus Torvalds 
10771da177e4SLinus Torvalds 	/* empty control and bulk lists */
10781da177e4SLinus Torvalds 	ohci->ed_controltail = NULL;
10791da177e4SLinus Torvalds 	ohci->ed_bulktail    = NULL;
10801da177e4SLinus Torvalds 
10811da177e4SLinus Torvalds 	if ((temp = ohci_run (ohci)) < 0) {
10821da177e4SLinus Torvalds 		ohci_err (ohci, "can't restart, %d\n", temp);
10831da177e4SLinus Torvalds 		return temp;
10841da177e4SLinus Torvalds 	}
1085383975d7SAlan Stern 	ohci_dbg(ohci, "restart complete\n");
10861da177e4SLinus Torvalds 	return 0;
10871da177e4SLinus Torvalds }
108895e44d44SManjunath Goudar EXPORT_SYMBOL_GPL(ohci_restart);
1089d576bb9fSMichael Hanselmann 
1090da6fb570SDavid Brownell #endif
1091da6fb570SDavid Brownell 
1092cd1965dbSFlorian Fainelli #ifdef CONFIG_PM
1093cd1965dbSFlorian Fainelli 
109495e44d44SManjunath Goudar int ohci_suspend(struct usb_hcd *hcd, bool do_wakeup)
1095cd1965dbSFlorian Fainelli {
1096cd1965dbSFlorian Fainelli 	struct ohci_hcd	*ohci = hcd_to_ohci (hcd);
1097cd1965dbSFlorian Fainelli 	unsigned long	flags;
1098e1bffbf6SMajunath Goudar 	int		rc = 0;
1099cd1965dbSFlorian Fainelli 
1100d4ae47dcSFlorian Fainelli 	/* Disable irq emission and mark HW unaccessible. Use
1101cd1965dbSFlorian Fainelli 	 * the spinlock to properly synchronize with possible pending
1102cd1965dbSFlorian Fainelli 	 * RH suspend or resume activity.
1103cd1965dbSFlorian Fainelli 	 */
1104cd1965dbSFlorian Fainelli 	spin_lock_irqsave (&ohci->lock, flags);
1105cd1965dbSFlorian Fainelli 	ohci_writel(ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable);
1106cd1965dbSFlorian Fainelli 	(void)ohci_readl(ohci, &ohci->regs->intrdisable);
1107cd1965dbSFlorian Fainelli 
1108cd1965dbSFlorian Fainelli 	clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
1109cd1965dbSFlorian Fainelli 	spin_unlock_irqrestore (&ohci->lock, flags);
1110cd1965dbSFlorian Fainelli 
1111e1bffbf6SMajunath Goudar 	synchronize_irq(hcd->irq);
1112e1bffbf6SMajunath Goudar 
1113e1bffbf6SMajunath Goudar 	if (do_wakeup && HCD_WAKEUP_PENDING(hcd)) {
1114e1bffbf6SMajunath Goudar 		ohci_resume(hcd, false);
1115e1bffbf6SMajunath Goudar 		rc = -EBUSY;
1116e1bffbf6SMajunath Goudar 	}
1117e1bffbf6SMajunath Goudar 	return rc;
1118cd1965dbSFlorian Fainelli }
111995e44d44SManjunath Goudar EXPORT_SYMBOL_GPL(ohci_suspend);
1120cd1965dbSFlorian Fainelli 
1121cd1965dbSFlorian Fainelli 
112295e44d44SManjunath Goudar int ohci_resume(struct usb_hcd *hcd, bool hibernated)
1123cd1965dbSFlorian Fainelli {
1124cfa49b4bSFlorian Fainelli 	struct ohci_hcd		*ohci = hcd_to_ohci(hcd);
1125cfa49b4bSFlorian Fainelli 	int			port;
1126cfa49b4bSFlorian Fainelli 	bool			need_reinit = false;
1127cfa49b4bSFlorian Fainelli 
1128cd1965dbSFlorian Fainelli 	set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
1129cd1965dbSFlorian Fainelli 
1130cd1965dbSFlorian Fainelli 	/* Make sure resume from hibernation re-enumerates everything */
1131cd1965dbSFlorian Fainelli 	if (hibernated)
1132cfa49b4bSFlorian Fainelli 		ohci_usb_reset(ohci);
1133cd1965dbSFlorian Fainelli 
1134cfa49b4bSFlorian Fainelli 	/* See if the controller is already running or has been reset */
1135cfa49b4bSFlorian Fainelli 	ohci->hc_control = ohci_readl(ohci, &ohci->regs->control);
1136cfa49b4bSFlorian Fainelli 	if (ohci->hc_control & (OHCI_CTRL_IR | OHCI_SCHED_ENABLES)) {
1137cfa49b4bSFlorian Fainelli 		need_reinit = true;
1138cfa49b4bSFlorian Fainelli 	} else {
1139cfa49b4bSFlorian Fainelli 		switch (ohci->hc_control & OHCI_CTRL_HCFS) {
1140cfa49b4bSFlorian Fainelli 		case OHCI_USB_OPER:
1141cfa49b4bSFlorian Fainelli 		case OHCI_USB_RESET:
1142cfa49b4bSFlorian Fainelli 			need_reinit = true;
1143cfa49b4bSFlorian Fainelli 		}
1144cfa49b4bSFlorian Fainelli 	}
1145cfa49b4bSFlorian Fainelli 
1146cfa49b4bSFlorian Fainelli 	/* If needed, reinitialize and suspend the root hub */
1147cfa49b4bSFlorian Fainelli 	if (need_reinit) {
1148cfa49b4bSFlorian Fainelli 		spin_lock_irq(&ohci->lock);
1149cfa49b4bSFlorian Fainelli 		ohci_rh_resume(ohci);
1150cfa49b4bSFlorian Fainelli 		ohci_rh_suspend(ohci, 0);
1151cfa49b4bSFlorian Fainelli 		spin_unlock_irq(&ohci->lock);
1152cfa49b4bSFlorian Fainelli 	}
1153cfa49b4bSFlorian Fainelli 
1154cfa49b4bSFlorian Fainelli 	/* Normally just turn on port power and enable interrupts */
1155cfa49b4bSFlorian Fainelli 	else {
1156cfa49b4bSFlorian Fainelli 		ohci_dbg(ohci, "powerup ports\n");
1157cfa49b4bSFlorian Fainelli 		for (port = 0; port < ohci->num_ports; port++)
1158cfa49b4bSFlorian Fainelli 			ohci_writel(ohci, RH_PS_PPS,
1159cfa49b4bSFlorian Fainelli 					&ohci->regs->roothub.portstatus[port]);
1160cfa49b4bSFlorian Fainelli 
1161cfa49b4bSFlorian Fainelli 		ohci_writel(ohci, OHCI_INTR_MIE, &ohci->regs->intrenable);
1162cfa49b4bSFlorian Fainelli 		ohci_readl(ohci, &ohci->regs->intrenable);
1163cfa49b4bSFlorian Fainelli 		msleep(20);
1164cfa49b4bSFlorian Fainelli 	}
1165cfa49b4bSFlorian Fainelli 
1166cfa49b4bSFlorian Fainelli 	usb_hcd_resume_root_hub(hcd);
1167cfa49b4bSFlorian Fainelli 
1168cd1965dbSFlorian Fainelli 	return 0;
1169cd1965dbSFlorian Fainelli }
117095e44d44SManjunath Goudar EXPORT_SYMBOL_GPL(ohci_resume);
1171cd1965dbSFlorian Fainelli 
1172cd1965dbSFlorian Fainelli #endif
1173cd1965dbSFlorian Fainelli 
1174d576bb9fSMichael Hanselmann /*-------------------------------------------------------------------------*/
1175d576bb9fSMichael Hanselmann 
117695e44d44SManjunath Goudar /*
117795e44d44SManjunath Goudar  * Generic structure: This gets copied for platform drivers so that
117895e44d44SManjunath Goudar  * individual entries can be overridden as needed.
117995e44d44SManjunath Goudar  */
118095e44d44SManjunath Goudar 
118195e44d44SManjunath Goudar static const struct hc_driver ohci_hc_driver = {
118295e44d44SManjunath Goudar 	.description =          hcd_name,
118395e44d44SManjunath Goudar 	.product_desc =         "OHCI Host Controller",
118495e44d44SManjunath Goudar 	.hcd_priv_size =        sizeof(struct ohci_hcd),
118595e44d44SManjunath Goudar 
118695e44d44SManjunath Goudar 	/*
118795e44d44SManjunath Goudar 	 * generic hardware linkage
118895e44d44SManjunath Goudar 	*/
118995e44d44SManjunath Goudar 	.irq =                  ohci_irq,
11907b81cb6bSChristoph Hellwig 	.flags =                HCD_MEMORY | HCD_DMA | HCD_USB11,
119195e44d44SManjunath Goudar 
119295e44d44SManjunath Goudar 	/*
119395e44d44SManjunath Goudar 	* basic lifecycle operations
119495e44d44SManjunath Goudar 	*/
119595e44d44SManjunath Goudar 	.reset =                ohci_setup,
119695e44d44SManjunath Goudar 	.start =                ohci_start,
119795e44d44SManjunath Goudar 	.stop =                 ohci_stop,
119895e44d44SManjunath Goudar 	.shutdown =             ohci_shutdown,
119995e44d44SManjunath Goudar 
120095e44d44SManjunath Goudar 	/*
120195e44d44SManjunath Goudar 	 * managing i/o requests and associated device resources
120295e44d44SManjunath Goudar 	*/
120395e44d44SManjunath Goudar 	.urb_enqueue =          ohci_urb_enqueue,
120495e44d44SManjunath Goudar 	.urb_dequeue =          ohci_urb_dequeue,
120595e44d44SManjunath Goudar 	.endpoint_disable =     ohci_endpoint_disable,
120695e44d44SManjunath Goudar 
120795e44d44SManjunath Goudar 	/*
120895e44d44SManjunath Goudar 	* scheduling support
120995e44d44SManjunath Goudar 	*/
121095e44d44SManjunath Goudar 	.get_frame_number =     ohci_get_frame,
121195e44d44SManjunath Goudar 
121295e44d44SManjunath Goudar 	/*
121395e44d44SManjunath Goudar 	* root hub support
121495e44d44SManjunath Goudar 	*/
121595e44d44SManjunath Goudar 	.hub_status_data =      ohci_hub_status_data,
121695e44d44SManjunath Goudar 	.hub_control =          ohci_hub_control,
121795e44d44SManjunath Goudar #ifdef CONFIG_PM
121895e44d44SManjunath Goudar 	.bus_suspend =          ohci_bus_suspend,
121995e44d44SManjunath Goudar 	.bus_resume =           ohci_bus_resume,
122095e44d44SManjunath Goudar #endif
122195e44d44SManjunath Goudar 	.start_port_reset =	ohci_start_port_reset,
122295e44d44SManjunath Goudar };
122395e44d44SManjunath Goudar 
122495e44d44SManjunath Goudar void ohci_init_driver(struct hc_driver *drv,
122595e44d44SManjunath Goudar 		const struct ohci_driver_overrides *over)
122695e44d44SManjunath Goudar {
122795e44d44SManjunath Goudar 	/* Copy the generic table to drv and then apply the overrides */
122895e44d44SManjunath Goudar 	*drv = ohci_hc_driver;
122995e44d44SManjunath Goudar 
1230c80ad6d1SKevin Hilman 	if (over) {
123195e44d44SManjunath Goudar 		drv->product_desc = over->product_desc;
123295e44d44SManjunath Goudar 		drv->hcd_priv_size += over->extra_priv_size;
123395e44d44SManjunath Goudar 		if (over->reset)
123495e44d44SManjunath Goudar 			drv->reset = over->reset;
123595e44d44SManjunath Goudar 	}
1236c80ad6d1SKevin Hilman }
123795e44d44SManjunath Goudar EXPORT_SYMBOL_GPL(ohci_init_driver);
123895e44d44SManjunath Goudar 
123995e44d44SManjunath Goudar /*-------------------------------------------------------------------------*/
124095e44d44SManjunath Goudar 
12411da177e4SLinus Torvalds MODULE_AUTHOR (DRIVER_AUTHOR);
12422b70f073SAlan Stern MODULE_DESCRIPTION(DRIVER_DESC);
12431da177e4SLinus Torvalds MODULE_LICENSE ("GPL");
12441da177e4SLinus Torvalds 
12456381fad7SEric Miao #if defined(CONFIG_ARCH_SA1100) && defined(CONFIG_SA1111)
12461da177e4SLinus Torvalds #include "ohci-sa1111.c"
12475e16fabeSSylvain Munaut #define SA1111_DRIVER		ohci_hcd_sa1111_driver
12481da177e4SLinus Torvalds #endif
12491da177e4SLinus Torvalds 
1250495a678fSSylvain Munaut #ifdef CONFIG_USB_OHCI_HCD_PPC_OF
1251495a678fSSylvain Munaut #include "ohci-ppc-of.c"
1252495a678fSSylvain Munaut #define OF_PLATFORM_DRIVER	ohci_hcd_ppc_of_driver
1253495a678fSSylvain Munaut #endif
1254495a678fSSylvain Munaut 
12556a6c957eSGeoff Levand #ifdef CONFIG_PPC_PS3
12566a6c957eSGeoff Levand #include "ohci-ps3.c"
12577a4eb7fdSGeoff Levand #define PS3_SYSTEM_BUS_DRIVER	ps3_ohci_driver
12586a6c957eSGeoff Levand #endif
12596a6c957eSGeoff Levand 
1260f54aab6eSMagnus Damm #ifdef CONFIG_MFD_SM501
1261f54aab6eSMagnus Damm #include "ohci-sm501.c"
12623ee38d8bSBen Dooks #define SM501_OHCI_DRIVER	ohci_hcd_sm501_driver
1263f54aab6eSMagnus Damm #endif
1264f54aab6eSMagnus Damm 
126578c73414SDmitry Baryshkov #ifdef CONFIG_MFD_TC6393XB
126678c73414SDmitry Baryshkov #include "ohci-tmio.c"
126778c73414SDmitry Baryshkov #define TMIO_OHCI_DRIVER	ohci_hcd_tmio_driver
126878c73414SDmitry Baryshkov #endif
126978c73414SDmitry Baryshkov 
12705e16fabeSSylvain Munaut static int __init ohci_hcd_mod_init(void)
12715e16fabeSSylvain Munaut {
12725e16fabeSSylvain Munaut 	int retval = 0;
12735e16fabeSSylvain Munaut 
12745e16fabeSSylvain Munaut 	if (usb_disabled())
12755e16fabeSSylvain Munaut 		return -ENODEV;
12765e16fabeSSylvain Munaut 
12772b70f073SAlan Stern 	printk(KERN_INFO "%s: " DRIVER_DESC "\n", hcd_name);
12785b5e0928SAlexey Dobriyan 	pr_debug ("%s: block sizes: ed %zd td %zd\n", hcd_name,
12795e16fabeSSylvain Munaut 		sizeof (struct ed), sizeof (struct td));
12809beeee65SAlan Stern 	set_bit(USB_OHCI_LOADED, &usb_hcds_loaded);
12815e16fabeSSylvain Munaut 
1282485f4f39SGreg Kroah-Hartman 	ohci_debug_root = debugfs_create_dir("ohci", usb_debug_root);
1283684c19e0STony Jones 
12846a6c957eSGeoff Levand #ifdef PS3_SYSTEM_BUS_DRIVER
12857a4eb7fdSGeoff Levand 	retval = ps3_ohci_driver_register(&PS3_SYSTEM_BUS_DRIVER);
12866a6c957eSGeoff Levand 	if (retval < 0)
12876a6c957eSGeoff Levand 		goto error_ps3;
12886a6c957eSGeoff Levand #endif
12896a6c957eSGeoff Levand 
1290495a678fSSylvain Munaut #ifdef OF_PLATFORM_DRIVER
1291d35fb641SGrant Likely 	retval = platform_driver_register(&OF_PLATFORM_DRIVER);
1292495a678fSSylvain Munaut 	if (retval < 0)
1293de44743bSBenjamin Herrenschmidt 		goto error_of_platform;
1294495a678fSSylvain Munaut #endif
1295495a678fSSylvain Munaut 
12965e16fabeSSylvain Munaut #ifdef SA1111_DRIVER
12975e16fabeSSylvain Munaut 	retval = sa1111_driver_register(&SA1111_DRIVER);
12985e16fabeSSylvain Munaut 	if (retval < 0)
1299de44743bSBenjamin Herrenschmidt 		goto error_sa1111;
13005e16fabeSSylvain Munaut #endif
13015e16fabeSSylvain Munaut 
13023ee38d8bSBen Dooks #ifdef SM501_OHCI_DRIVER
13033ee38d8bSBen Dooks 	retval = platform_driver_register(&SM501_OHCI_DRIVER);
13043ee38d8bSBen Dooks 	if (retval < 0)
13053ee38d8bSBen Dooks 		goto error_sm501;
13063ee38d8bSBen Dooks #endif
13073ee38d8bSBen Dooks 
130878c73414SDmitry Baryshkov #ifdef TMIO_OHCI_DRIVER
130978c73414SDmitry Baryshkov 	retval = platform_driver_register(&TMIO_OHCI_DRIVER);
131078c73414SDmitry Baryshkov 	if (retval < 0)
131178c73414SDmitry Baryshkov 		goto error_tmio;
131278c73414SDmitry Baryshkov #endif
131378c73414SDmitry Baryshkov 
13145e16fabeSSylvain Munaut 	return retval;
13155e16fabeSSylvain Munaut 
13165e16fabeSSylvain Munaut 	/* Error path */
131778c73414SDmitry Baryshkov #ifdef TMIO_OHCI_DRIVER
131878c73414SDmitry Baryshkov 	platform_driver_unregister(&TMIO_OHCI_DRIVER);
131978c73414SDmitry Baryshkov  error_tmio:
132078c73414SDmitry Baryshkov #endif
13213ee38d8bSBen Dooks #ifdef SM501_OHCI_DRIVER
132278c73414SDmitry Baryshkov 	platform_driver_unregister(&SM501_OHCI_DRIVER);
13233ee38d8bSBen Dooks  error_sm501:
13243ee38d8bSBen Dooks #endif
13255e16fabeSSylvain Munaut #ifdef SA1111_DRIVER
13265e16fabeSSylvain Munaut 	sa1111_driver_unregister(&SA1111_DRIVER);
1327de44743bSBenjamin Herrenschmidt  error_sa1111:
1328de44743bSBenjamin Herrenschmidt #endif
1329de44743bSBenjamin Herrenschmidt #ifdef OF_PLATFORM_DRIVER
1330d35fb641SGrant Likely 	platform_driver_unregister(&OF_PLATFORM_DRIVER);
1331de44743bSBenjamin Herrenschmidt  error_of_platform:
1332de44743bSBenjamin Herrenschmidt #endif
13336a6c957eSGeoff Levand #ifdef PS3_SYSTEM_BUS_DRIVER
13347a4eb7fdSGeoff Levand 	ps3_ohci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);
13356a6c957eSGeoff Levand  error_ps3:
13366a6c957eSGeoff Levand #endif
1337684c19e0STony Jones 	debugfs_remove(ohci_debug_root);
1338684c19e0STony Jones 	ohci_debug_root = NULL;
1339684c19e0STony Jones 
13409beeee65SAlan Stern 	clear_bit(USB_OHCI_LOADED, &usb_hcds_loaded);
13415e16fabeSSylvain Munaut 	return retval;
13425e16fabeSSylvain Munaut }
13435e16fabeSSylvain Munaut module_init(ohci_hcd_mod_init);
13445e16fabeSSylvain Munaut 
13455e16fabeSSylvain Munaut static void __exit ohci_hcd_mod_exit(void)
13465e16fabeSSylvain Munaut {
134778c73414SDmitry Baryshkov #ifdef TMIO_OHCI_DRIVER
134878c73414SDmitry Baryshkov 	platform_driver_unregister(&TMIO_OHCI_DRIVER);
134978c73414SDmitry Baryshkov #endif
13503ee38d8bSBen Dooks #ifdef SM501_OHCI_DRIVER
13513ee38d8bSBen Dooks 	platform_driver_unregister(&SM501_OHCI_DRIVER);
13523ee38d8bSBen Dooks #endif
13535e16fabeSSylvain Munaut #ifdef SA1111_DRIVER
13545e16fabeSSylvain Munaut 	sa1111_driver_unregister(&SA1111_DRIVER);
13555e16fabeSSylvain Munaut #endif
1356495a678fSSylvain Munaut #ifdef OF_PLATFORM_DRIVER
1357d35fb641SGrant Likely 	platform_driver_unregister(&OF_PLATFORM_DRIVER);
1358495a678fSSylvain Munaut #endif
13596a6c957eSGeoff Levand #ifdef PS3_SYSTEM_BUS_DRIVER
13607a4eb7fdSGeoff Levand 	ps3_ohci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);
13616a6c957eSGeoff Levand #endif
1362684c19e0STony Jones 	debugfs_remove(ohci_debug_root);
13639beeee65SAlan Stern 	clear_bit(USB_OHCI_LOADED, &usb_hcds_loaded);
13645e16fabeSSylvain Munaut }
13655e16fabeSSylvain Munaut module_exit(ohci_hcd_mod_exit);
13665e16fabeSSylvain Munaut 
1367