23 #include <linux/module.h>
25 #include <linux/pci.h>
26 #include <linux/kernel.h>
29 #include <linux/sched.h>
30 #include <linux/slab.h>
31 #include <linux/errno.h>
34 #include <linux/list.h>
45 #include <asm/unaligned.h>
46 #include <asm/byteorder.h>
49 #define DRIVER_AUTHOR "Roman Weissgaerber, David Brownell"
50 #define DRIVER_DESC "USB 1.1 'Open' Host Controller (OHCI) Driver"
54 #undef OHCI_VERBOSE_DEBUG
57 #define OHCI_CONTROL_INIT OHCI_CTRL_CBSR
58 #define OHCI_INTR_INIT \
59 (OHCI_INTR_MIE | OHCI_INTR_RHSC | OHCI_INTR_UE \
60 | OHCI_INTR_RD | OHCI_INTR_WDH)
67 #ifdef CONFIG_ARCH_OMAP
74 static const char hcd_name [] =
"ohci_hcd";
76 #define STATECHANGE_DELAY msecs_to_jiffies(300)
83 static void ohci_stop (
struct usb_hcd *hcd);
85 #if defined(CONFIG_PM) || defined(CONFIG_PCI)
90 static void sb800_prefetch(
struct ohci_hcd *
ohci,
int on);
92 static inline void sb800_prefetch(
struct ohci_hcd *
ohci,
int on)
109 #if defined(CONFIG_SA1111)
110 #define IRQ_NOTMINE IRQ_HANDLED
112 #define IRQ_NOTMINE IRQ_NONE
117 static bool distrust_firmware = 1;
120 "true to distrust firmware power/overcurrent setup");
123 static bool no_handshake = 0;
125 MODULE_PARM_DESC (no_handshake,
"true (not default) disables BIOS handshake");
132 static int ohci_urb_enqueue (
140 unsigned int pipe = urb->pipe;
145 #ifdef OHCI_VERBOSE_DEBUG
146 urb_print(urb,
"SUB", usb_pipein(pipe), -
EINPROGRESS);
150 if (! (ed = ed_get (ohci, urb->ep, urb->dev, pipe, urb->interval)))
157 if (urb->transfer_buffer_length > 4096)
167 size += urb->transfer_buffer_length / 4096;
169 if ((urb->transfer_buffer_length % 4096) != 0)
174 else if ((urb->transfer_flags & URB_ZERO_PACKET) != 0
175 && (urb->transfer_buffer_length
176 % usb_maxpacket (urb->dev, pipe,
177 usb_pipeout (pipe))) == 0)
180 case PIPE_ISOCHRONOUS:
181 size = urb->number_of_packets;
186 urb_priv = kzalloc (
sizeof (
urb_priv_t) + size *
sizeof (
struct td *),
190 INIT_LIST_HEAD (&urb_priv->
pending);
195 for (i = 0; i <
size; i++) {
196 urb_priv->
td [
i] = td_alloc (ohci, mem_flags);
197 if (!urb_priv->
td [i]) {
199 urb_free_priv (ohci, urb_priv);
207 if (!HCD_HW_ACCESSIBLE(hcd)) {
221 retval = ed_schedule (ohci, ed);
226 if (ed->
type == PIPE_ISOCHRONOUS) {
233 urb->start_frame =
frame;
239 }
else if (ed->
type == PIPE_ISOCHRONOUS)
246 urb->hcpriv = urb_priv;
247 td_submit_urb (ohci, urb);
251 urb_free_priv (ohci, urb_priv);
252 spin_unlock_irqrestore (&ohci->
lock, flags);
262 static int ohci_urb_dequeue(
struct usb_hcd *hcd,
struct urb *urb,
int status)
264 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
268 #ifdef OHCI_VERBOSE_DEBUG
269 urb_print(urb,
"UNLINK", 1, status);
283 urb_priv = urb->hcpriv;
286 start_ed_unlink (ohci, urb_priv->
ed);
294 finish_urb(ohci, urb, status);
296 spin_unlock_irqrestore (&ohci->
lock, flags);
307 ohci_endpoint_disable (
struct usb_hcd *hcd,
struct usb_host_endpoint *ep)
309 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
311 struct ed *ed = ep->hcpriv;
312 unsigned limit = 1000;
326 if (quirk_zfmicro(ohci) && ed->
type == PIPE_INTERRUPT)
328 finish_unlinks (ohci, 0);
336 if (quirk_zfmicro(ohci)) {
337 ohci_warn(ohci,
"Attempting ZF TD recovery\n");
343 spin_unlock_irqrestore (&ohci->
lock, flags);
347 if (list_empty (&ed->
td_list)) {
348 td_free (ohci, ed->
dummy);
357 ohci_err (ohci,
"leak ed %p (#%02x) state %d%s\n",
358 ed, ep->desc.bEndpointAddress, ed->
state,
359 list_empty (&ed->
td_list) ?
"" :
" (has tds)");
360 td_free (ohci, ed->
dummy);
364 spin_unlock_irqrestore (&ohci->
lock, flags);
367 static int ohci_get_frame (
struct usb_hcd *hcd)
369 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
371 return ohci_frame_no(ohci);
374 static void ohci_usb_reset (
struct ohci_hcd *ohci)
387 ohci_shutdown (
struct usb_hcd *hcd)
391 ohci = hcd_to_ohci (hcd);
402 static int check_ed(
struct ohci_hcd *ohci,
struct ed *ed)
415 static void unlink_watchdog_func(
unsigned long _ohci)
419 unsigned seen_count = 0;
421 struct ed **seen =
NULL;
432 seen = kcalloc(max,
sizeof *seen,
GFP_ATOMIC);
443 for (temp = 0; temp < seen_count; temp++) {
444 if (seen[temp] == ed) {
452 seen[seen_count++] =
ed;
453 if (!check_ed(ohci, ed)) {
471 &ohci->
regs->intrstatus);
473 &ohci->
regs->intrenable);
486 spin_unlock_irqrestore(&ohci->
lock, flags);
495 static int ohci_init (
struct ohci_hcd *ohci)
498 struct usb_hcd *hcd = ohci_to_hcd(ohci);
500 if (distrust_firmware)
504 ohci->
regs = hcd->regs;
516 ohci_dbg (ohci,
"USB HC TakeOver from BIOS/SMM\n");
529 ohci_err (ohci,
"USB HC takeover failed!"
530 " (BIOS/SMM bug)\n");
534 ohci_usb_reset (ohci);
557 if ((ret = ohci_mem_init (ohci)) < 0)
572 static int ohci_run (
struct ohci_hcd *ohci)
576 struct usb_hcd *hcd = ohci_to_hcd(ohci);
586 ohci_dbg (ohci,
"fminterval delta %d\n",
626 spin_lock_irq (&ohci->
lock);
634 spin_unlock_irq (&ohci->
lock);
635 ohci_err (ohci,
"USB HC reset timed out!\n");
664 periodic_reinit (ohci);
669 if ((
ohci_readl (ohci, &ohci->
regs->fminterval) & 0x3fff0000) == 0
673 ohci_dbg (ohci,
"enabling initreset quirk\n");
676 spin_unlock_irq (&ohci->
lock);
677 ohci_err (ohci,
"init err (%08x %04x)\n",
684 set_bit(HCD_FLAG_POLL_RH, &hcd->flags);
685 hcd->uses_new_polling = 1;
702 val = roothub_a (ohci);
719 &ohci->
regs->roothub.b);
724 spin_unlock_irq (&ohci->
lock);
727 mdelay ((val >> 23) & 0x1fe);
729 if (quirk_zfmicro(ohci)) {
732 (
unsigned long) ohci);
749 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
762 if (ints == ~(
u32)0) {
764 ohci_dbg (ohci,
"device removed!\n");
778 if (quirk_nec(ohci)) {
782 ohci_err (ohci,
"OHCI Unrecoverable Error, scheduling NEC chip restart\n");
788 ohci_err (ohci,
"OHCI Unrecoverable Error, disabled\n");
794 ohci_usb_reset (ohci);
822 set_bit(HCD_FLAG_POLL_RH, &hcd->flags);
824 spin_lock (&ohci->
lock);
825 ohci_rh_resume (ohci);
826 spin_unlock (&ohci->
lock);
828 usb_hcd_resume_root_hub(hcd);
832 spin_lock (&ohci->
lock);
834 spin_unlock (&ohci->
lock);
838 spin_lock(&ohci->
lock);
842 if (check_ed(ohci, ed)) {
851 "Reclaiming orphan TD %p\n",
853 takeback_td(ohci, td);
859 spin_unlock(&ohci->
lock);
867 spin_lock (&ohci->
lock);
869 finish_unlinks (ohci, ohci_frame_no(ohci));
870 if ((ints & OHCI_INTR_SF) != 0
875 spin_unlock (&ohci->
lock);
889 static void ohci_stop (
struct usb_hcd *hcd)
891 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
898 ohci_usb_reset (ohci);
903 if (quirk_zfmicro(ohci))
905 if (quirk_amdiso(ohci))
909 ohci_mem_cleanup (ohci);
921 #if defined(CONFIG_PM) || defined(CONFIG_PCI)
924 static int ohci_restart (
struct ohci_hcd *ohci)
928 struct urb_priv *
priv;
930 spin_lock_irq(&ohci->
lock);
934 if (!list_empty (&ohci->
pending))
935 ohci_dbg(ohci,
"abort schedule...\n");
937 struct urb *urb = priv->
td[0]->urb;
938 struct ed *ed = priv->
ed;
944 ed_deschedule (ohci, ed);
953 ohci_dbg(ohci,
"bogus ed %p state %d\n",
960 finish_unlinks (ohci, 0);
961 spin_unlock_irq(&ohci->
lock);
976 if ((temp = ohci_run (ohci)) < 0) {
977 ohci_err (ohci,
"can't restart, %d\n", temp);
980 ohci_dbg(ohci,
"restart complete\n");
994 #define PCI_DRIVER ohci_pci_driver
997 #if defined(CONFIG_ARCH_SA1100) && defined(CONFIG_SA1111)
999 #define SA1111_DRIVER ohci_hcd_sa1111_driver
1002 #if defined(CONFIG_ARCH_S3C24XX) || defined(CONFIG_ARCH_S3C64XX)
1004 #define PLATFORM_DRIVER ohci_hcd_s3c2410_driver
1007 #ifdef CONFIG_USB_OHCI_EXYNOS
1009 #define PLATFORM_DRIVER exynos_ohci_driver
1012 #ifdef CONFIG_USB_OHCI_HCD_OMAP1
1014 #define OMAP1_PLATFORM_DRIVER ohci_hcd_omap_driver
1017 #ifdef CONFIG_USB_OHCI_HCD_OMAP3
1019 #define OMAP3_PLATFORM_DRIVER ohci_hcd_omap3_driver
1022 #if defined(CONFIG_PXA27x) || defined(CONFIG_PXA3xx)
1024 #define PLATFORM_DRIVER ohci_hcd_pxa27x_driver
1027 #ifdef CONFIG_ARCH_EP93XX
1029 #define PLATFORM_DRIVER ohci_hcd_ep93xx_driver
1032 #ifdef CONFIG_MIPS_ALCHEMY
1034 #define PLATFORM_DRIVER ohci_hcd_au1xxx_driver
1037 #ifdef CONFIG_PNX8550
1039 #define PLATFORM_DRIVER ohci_hcd_pnx8550_driver
1042 #ifdef CONFIG_USB_OHCI_HCD_PPC_SOC
1044 #define PLATFORM_DRIVER ohci_hcd_ppc_soc_driver
1047 #ifdef CONFIG_ARCH_AT91
1049 #define PLATFORM_DRIVER ohci_hcd_at91_driver
1052 #ifdef CONFIG_ARCH_LPC32XX
1054 #define PLATFORM_DRIVER usb_hcd_nxp_driver
1057 #ifdef CONFIG_ARCH_DAVINCI_DA8XX
1059 #define PLATFORM_DRIVER ohci_hcd_da8xx_driver
1062 #ifdef CONFIG_USB_OHCI_SH
1064 #define PLATFORM_DRIVER ohci_hcd_sh_driver
1068 #ifdef CONFIG_USB_OHCI_HCD_PPC_OF
1070 #define OF_PLATFORM_DRIVER ohci_hcd_ppc_of_driver
1073 #ifdef CONFIG_PLAT_SPEAR
1075 #define PLATFORM_DRIVER spear_ohci_hcd_driver
1078 #ifdef CONFIG_PPC_PS3
1080 #define PS3_SYSTEM_BUS_DRIVER ps3_ohci_driver
1083 #ifdef CONFIG_MFD_SM501
1085 #define SM501_OHCI_DRIVER ohci_hcd_sm501_driver
1088 #ifdef CONFIG_MFD_TC6393XB
1090 #define TMIO_OHCI_DRIVER ohci_hcd_tmio_driver
1093 #ifdef CONFIG_MACH_JZ4740
1095 #define PLATFORM_DRIVER ohci_hcd_jz4740_driver
1098 #ifdef CONFIG_USB_OCTEON_OHCI
1100 #define PLATFORM_DRIVER ohci_octeon_driver
1103 #ifdef CONFIG_TILE_USB
1105 #define PLATFORM_DRIVER ohci_hcd_tilegx_driver
1108 #ifdef CONFIG_USB_CNS3XXX_OHCI
1110 #define PLATFORM_DRIVER ohci_hcd_cns3xxx_driver
1113 #ifdef CONFIG_CPU_XLR
1115 #define PLATFORM_DRIVER ohci_xls_driver
1118 #ifdef CONFIG_USB_OHCI_HCD_PLATFORM
1120 #define PLATFORM_DRIVER ohci_platform_driver
1123 #if !defined(PCI_DRIVER) && \
1124 !defined(PLATFORM_DRIVER) && \
1125 !defined(OMAP1_PLATFORM_DRIVER) && \
1126 !defined(OMAP3_PLATFORM_DRIVER) && \
1127 !defined(OF_PLATFORM_DRIVER) && \
1128 !defined(SA1111_DRIVER) && \
1129 !defined(PS3_SYSTEM_BUS_DRIVER) && \
1130 !defined(SM501_OHCI_DRIVER) && \
1131 !defined(TMIO_OHCI_DRIVER)
1132 #error "missing bus glue for ohci-hcd"
1135 static int __init ohci_hcd_mod_init(
void)
1143 pr_debug (
"%s: block sizes: ed %Zd td %Zd\n", hcd_name,
1144 sizeof (
struct ed),
sizeof (
struct td));
1149 if (!ohci_debug_root) {
1155 #ifdef PS3_SYSTEM_BUS_DRIVER
1156 retval = ps3_ohci_driver_register(&PS3_SYSTEM_BUS_DRIVER);
1161 #ifdef PLATFORM_DRIVER
1164 goto error_platform;
1167 #ifdef OMAP1_PLATFORM_DRIVER
1170 goto error_omap1_platform;
1173 #ifdef OMAP3_PLATFORM_DRIVER
1176 goto error_omap3_platform;
1179 #ifdef OF_PLATFORM_DRIVER
1182 goto error_of_platform;
1185 #ifdef SA1111_DRIVER
1192 retval = pci_register_driver(&PCI_DRIVER);
1197 #ifdef SM501_OHCI_DRIVER
1203 #ifdef TMIO_OHCI_DRIVER
1212 #ifdef TMIO_OHCI_DRIVER
1216 #ifdef SM501_OHCI_DRIVER
1224 #ifdef SA1111_DRIVER
1228 #ifdef OF_PLATFORM_DRIVER
1232 #ifdef PLATFORM_DRIVER
1236 #ifdef OMAP1_PLATFORM_DRIVER
1238 error_omap1_platform:
1240 #ifdef OMAP3_PLATFORM_DRIVER
1242 error_omap3_platform:
1244 #ifdef PS3_SYSTEM_BUS_DRIVER
1245 ps3_ohci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);
1250 ohci_debug_root =
NULL;
1259 static void __exit ohci_hcd_mod_exit(
void)
1261 #ifdef TMIO_OHCI_DRIVER
1264 #ifdef SM501_OHCI_DRIVER
1270 #ifdef SA1111_DRIVER
1273 #ifdef OF_PLATFORM_DRIVER
1276 #ifdef PLATFORM_DRIVER
1279 #ifdef OMAP3_PLATFORM_DRIVER
1282 #ifdef PS3_SYSTEM_BUS_DRIVER
1283 ps3_ohci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);