23 #include <linux/module.h>
24 #include <linux/pci.h>
26 #include <linux/kernel.h>
29 #include <linux/sched.h>
31 #include <linux/errno.h>
33 #include <linux/hrtimer.h>
34 #include <linux/list.h>
41 #include <linux/slab.h>
44 #include <asm/byteorder.h>
47 #include <asm/unaligned.h>
49 #if defined(CONFIG_PPC_PS3)
69 #define DRIVER_AUTHOR "David Brownell"
70 #define DRIVER_DESC "USB 2.0 'Enhanced' Host Controller (EHCI) Driver"
72 static const char hcd_name [] =
"ehci_hcd";
83 #define EHCI_TUNE_CERR 3
84 #define EHCI_TUNE_RL_HS 4
85 #define EHCI_TUNE_RL_TT 0
86 #define EHCI_TUNE_MULT_HS 1
87 #define EHCI_TUNE_MULT_TT 1
94 #define EHCI_TUNE_FLS 1
97 static int log2_irq_thresh = 0;
102 static unsigned park = 0;
107 static bool ignore_oc = 0;
109 MODULE_PARM_DESC (ignore_oc,
"ignore bogus hardware overcurrent indications");
112 static unsigned int hird;
116 #define INTR_MASK (STS_IAA | STS_FATAL | STS_PCD | STS_ERR | STS_INT)
149 result = ehci_readl(ehci, ptr);
150 if (result == ~(
u32)0)
162 static int tdi_in_host_mode (
struct ehci_hcd *ehci)
166 tmp = ehci_readl(ehci, &ehci->
regs->usbmode);
174 static int ehci_halt (
struct ehci_hcd *ehci)
178 spin_lock_irq(&ehci->
lock);
181 ehci_writel(ehci, 0, &ehci->
regs->intr_enable);
183 if (
ehci_is_TDI(ehci) && !tdi_in_host_mode(ehci)) {
184 spin_unlock_irq(&ehci->
lock);
193 temp = ehci_readl(ehci, &ehci->
regs->command);
195 ehci_writel(ehci, temp, &ehci->
regs->command);
197 spin_unlock_irq(&ehci->
lock);
205 static void tdi_reset (
struct ehci_hcd *ehci)
209 tmp = ehci_readl(ehci, &ehci->
regs->usbmode);
217 ehci_writel(ehci, tmp, &ehci->
regs->usbmode);
224 static int ehci_reset (
struct ehci_hcd *ehci)
231 if (ehci->
debug && !dbgp_reset_prep(ehci_to_hcd(ehci)))
235 dbg_cmd (ehci,
"reset", command);
236 ehci_writel(ehci, command, &ehci->
regs->command);
244 &ehci->
regs->usbmode_ex);
254 dbgp_external_startup(ehci_to_hcd(ehci));
265 static void ehci_quiesce (
struct ehci_hcd *ehci)
277 spin_lock_irq(&ehci->
lock);
279 ehci_writel(ehci, ehci->
command, &ehci->
regs->command);
280 spin_unlock_irq(&ehci->
lock);
288 static void end_unlink_async(
struct ehci_hcd *ehci);
289 static void unlink_empty_async(
struct ehci_hcd *ehci);
290 static void ehci_work(
struct ehci_hcd *ehci);
291 static void start_unlink_intr(
struct ehci_hcd *ehci,
struct ehci_qh *qh);
292 static void end_unlink_intr(
struct ehci_hcd *ehci,
struct ehci_qh *qh);
308 static void ehci_turn_off_all_ports(
struct ehci_hcd *ehci)
314 &ehci->
regs->port_status[port]);
321 static void ehci_silence_controller(
struct ehci_hcd *ehci)
325 spin_lock_irq(&ehci->
lock);
327 ehci_turn_off_all_ports(ehci);
330 ehci_writel(ehci, 0, &ehci->
regs->configured_flag);
333 ehci_readl(ehci, &ehci->
regs->configured_flag);
334 spin_unlock_irq(&ehci->
lock);
341 static void ehci_shutdown(
struct usb_hcd *hcd)
343 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
345 spin_lock_irq(&ehci->
lock);
349 spin_unlock_irq(&ehci->
lock);
351 ehci_silence_controller(ehci);
356 static void ehci_port_power (
struct ehci_hcd *ehci,
int is_on)
363 ehci_dbg (ehci,
"...power%s ports...\n", is_on ?
"up" :
"down");
365 (
void) ehci_hub_control(ehci_to_hcd(ehci),
366 is_on ? SetPortFeature : ClearPortFeature,
370 ehci_readl(ehci, &ehci->
regs->command);
380 static void ehci_work (
struct ehci_hcd *ehci)
408 turn_on_io_watchdog(ehci);
414 static void ehci_stop (
struct usb_hcd *hcd)
416 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
422 spin_lock_irq(&ehci->
lock);
424 spin_unlock_irq(&ehci->
lock);
427 ehci_silence_controller(ehci);
431 remove_sysfs_files(ehci);
435 spin_lock_irq (&ehci->
lock);
437 spin_unlock_irq (&ehci->
lock);
438 ehci_mem_cleanup (ehci);
444 ehci_dbg(ehci,
"irq normal %ld err %ld iaa %ld (lost %ld)\n",
445 ehci->stats.normal, ehci->stats.error, ehci->stats.iaa,
446 ehci->stats.lost_iaa);
447 ehci_dbg (ehci,
"complete %ld unlink %ld\n",
448 ehci->stats.complete, ehci->stats.unlink);
452 ehci_readl(ehci, &ehci->
regs->status));
456 static int ehci_init(
struct usb_hcd *hcd)
458 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
472 ehci->
hrtimer.function = ehci_hrtimer_func;
475 hcc_params = ehci_readl(ehci, &ehci->
caps->hcc_params);
501 if ((retval = ehci_mem_init(ehci,
GFP_KERNEL)) < 0)
518 hw = ehci->
async->hw;
521 #if defined(CONFIG_PPC_PS3)
530 if (log2_irq_thresh < 0 || log2_irq_thresh > 6)
532 temp = 1 << (16 + log2_irq_thresh);
535 ehci_dbg(ehci,
"enable per-port change event\n");
547 park =
min(park, (
unsigned) 3);
563 ehci_dbg(ehci,
"hird %d invalid, use default 0",
572 if (!(hcd->driver->flags & HCD_LOCAL_MEM))
573 hcd->self.sg_tablesize = ~0;
578 static int ehci_run (
struct usb_hcd *hcd)
580 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
584 hcd->uses_new_polling = 1;
589 ehci_writel(ehci, (
u32)ehci->
async->qh_dma, &ehci->
regs->async_next);
603 hcc_params = ehci_readl(ehci, &ehci->
caps->hcc_params);
605 ehci_writel(ehci, 0, &ehci->
regs->segment);
618 ehci_writel(ehci, ehci->
command, &ehci->
regs->command);
637 ehci_writel(ehci,
FLAG_CF, &ehci->
regs->configured_flag);
638 ehci_readl(ehci, &ehci->
regs->command);
640 up_write(&ehci_cf_port_reset_rwsem);
643 temp =
HC_VERSION(ehci, ehci_readl(ehci, &ehci->
caps->hc_capbase));
645 "USB %x.%x started, EHCI %x.%02x%s\n",
646 ((ehci->
sbrn & 0xf0)>>4), (ehci->
sbrn & 0x0f),
647 temp >> 8, temp & 0xff,
648 ignore_oc ?
", overcurrent ignored" :
"");
651 &ehci->
regs->intr_enable);
658 create_sysfs_files(ehci);
663 static int ehci_setup(
struct usb_hcd *hcd)
665 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
670 dbg_hcs_params(ehci,
"reset");
671 dbg_hcc_params(ehci,
"reset");
676 ehci->
sbrn = HCD_USB2;
679 retval = ehci_init(hcd);
683 retval = ehci_halt(ehci);
699 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
703 spin_lock (&ehci->
lock);
705 status = ehci_readl(ehci, &ehci->
regs->status);
708 if (status == ~(
u32) 0) {
709 ehci_dbg (ehci,
"device removed\n");
721 spin_unlock(&ehci->
lock);
726 ehci_writel(ehci, masked_status, &ehci->
regs->status);
727 cmd = ehci_readl(ehci, &ehci->
regs->command);
740 COUNT (ehci->stats.normal);
742 COUNT (ehci->stats.error);
764 ehci_dbg(ehci,
"IAA with IAAD still set?\n");
766 COUNT(ehci->stats.iaa);
767 end_unlink_async(ehci);
769 ehci_dbg(ehci,
"IAA with nothing unlinked?\n");
782 usb_hcd_resume_root_hub(hcd);
792 if (ehci->
has_ppcd && !(ppcd & (1 << i)))
794 pstatus = ehci_readl(ehci,
795 &ehci->
regs->port_status[i]);
813 ehci_dbg (ehci,
"port %d remote wakeup\n", i + 1);
830 ehci_writel(ehci, ehci->
command, &ehci->
regs->command);
831 ehci_writel(ehci, 0, &ehci->
regs->intr_enable);
832 ehci_handle_controller_death(ehci);
840 spin_unlock (&ehci->
lock);
860 static int ehci_urb_enqueue (
865 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
870 switch (usb_pipetype (urb->pipe)) {
875 if (urb->transfer_buffer_length > (16 * 1024))
880 if (!qh_urb_transaction (ehci, urb, &
qtd_list, mem_flags))
882 return submit_async(ehci, urb, &
qtd_list, mem_flags);
885 if (!qh_urb_transaction (ehci, urb, &
qtd_list, mem_flags))
887 return intr_submit(ehci, urb, &
qtd_list, mem_flags);
889 case PIPE_ISOCHRONOUS:
891 return itd_submit (ehci, urb, mem_flags);
893 return sitd_submit (ehci, urb, mem_flags);
901 static int ehci_urb_dequeue(
struct usb_hcd *hcd,
struct urb *urb,
int status)
903 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
913 switch (usb_pipetype (urb->pipe)) {
917 qh = (
struct ehci_qh *) urb->hcpriv;
923 start_unlink_async(ehci, qh);
931 qh_completions(ehci, qh);
937 qh = (
struct ehci_qh *) urb->hcpriv;
943 start_unlink_intr(ehci, qh);
946 qh_completions (ehci, qh);
949 ehci_dbg (ehci,
"bogus qh %p state %d\n",
955 case PIPE_ISOCHRONOUS:
963 spin_unlock_irqrestore (&ehci->
lock, flags);
972 ehci_endpoint_disable (
struct usb_hcd *hcd,
struct usb_host_endpoint *ep)
974 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
993 if (!list_empty(&stream->
td_list))
1006 for (tmp = ehci->
async->qh_next.qh;
1014 start_unlink_async(ehci, qh);
1019 spin_unlock_irqrestore (&ehci->
lock, flags);
1026 qh_destroy(ehci, qh);
1034 ehci_err (ehci,
"qh %p (#%02x) state %d%s\n",
1035 qh, ep->desc.bEndpointAddress, qh->
qh_state,
1036 list_empty (&qh->
qtd_list) ?
"" :
"(has tds)");
1041 spin_unlock_irqrestore (&ehci->
lock, flags);
1045 ehci_endpoint_reset(
struct usb_hcd *hcd,
struct usb_host_endpoint *ep)
1047 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
1049 int eptype = usb_endpoint_type(&ep->desc);
1050 int epnum = usb_endpoint_num(&ep->desc);
1051 int is_out = usb_endpoint_dir_out(&ep->desc);
1052 unsigned long flags;
1066 usb_settoggle(qh->
dev, epnum, is_out, 0);
1068 WARN_ONCE(1,
"clear_halt for a busy endpoint\n");
1077 start_unlink_async(ehci, qh);
1079 start_unlink_intr(ehci, qh);
1082 spin_unlock_irqrestore(&ehci->
lock, flags);
1085 static int ehci_get_frame (
struct usb_hcd *hcd)
1087 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
1088 return (ehci_read_frame_index(ehci) >> 3) % ehci->
periodic_size;
1099 static int __maybe_unused ehci_suspend(
struct usb_hcd *hcd,
bool do_wakeup)
1101 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
1113 spin_lock_irq(&ehci->
lock);
1114 ehci_writel(ehci, 0, &ehci->
regs->intr_enable);
1115 (
void) ehci_readl(ehci, &ehci->
regs->intr_enable);
1117 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
1118 spin_unlock_irq(&ehci->
lock);
1124 static int __maybe_unused ehci_resume(
struct usb_hcd *hcd,
bool hibernated)
1126 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
1132 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
1142 if (ehci_readl(ehci, &ehci->
regs->configured_flag) ==
FLAG_CF &&
1148 spin_lock_irq(&ehci->
lock);
1152 if (!hcd->self.root_hub->do_remote_wakeup)
1154 ehci_writel(ehci, mask, &ehci->
regs->intr_enable);
1155 ehci_readl(ehci, &ehci->
regs->intr_enable);
1157 spin_unlock_irq(&ehci->
lock);
1165 usb_root_hub_lost_power(hcd->self.root_hub);
1166 (
void) ehci_halt(ehci);
1167 (
void) ehci_reset(ehci);
1169 spin_lock_irq(&ehci->
lock);
1173 ehci_writel(ehci, ehci->
command, &ehci->
regs->command);
1174 ehci_writel(ehci,
FLAG_CF, &ehci->
regs->configured_flag);
1175 ehci_readl(ehci, &ehci->
regs->command);
1178 spin_unlock_irq(&ehci->
lock);
1181 ehci_port_power(ehci, 1);
1196 #ifndef CHIPIDEA_EHCI
1204 #define PCI_DRIVER ehci_pci_driver
1207 #ifdef CONFIG_USB_EHCI_FSL
1209 #define PLATFORM_DRIVER ehci_fsl_driver
1212 #ifdef CONFIG_USB_EHCI_MXC
1214 #define PLATFORM_DRIVER ehci_mxc_driver
1217 #ifdef CONFIG_USB_EHCI_SH
1219 #define PLATFORM_DRIVER ehci_hcd_sh_driver
1222 #ifdef CONFIG_MIPS_ALCHEMY
1224 #define PLATFORM_DRIVER ehci_hcd_au1xxx_driver
1227 #ifdef CONFIG_USB_EHCI_HCD_OMAP
1229 #define PLATFORM_DRIVER ehci_hcd_omap_driver
1232 #ifdef CONFIG_PPC_PS3
1234 #define PS3_SYSTEM_BUS_DRIVER ps3_ehci_driver
1237 #ifdef CONFIG_USB_EHCI_HCD_PPC_OF
1239 #define OF_PLATFORM_DRIVER ehci_hcd_ppc_of_driver
1242 #ifdef CONFIG_XPS_USB_HCD_XILINX
1244 #define XILINX_OF_PLATFORM_DRIVER ehci_hcd_xilinx_of_driver
1247 #ifdef CONFIG_PLAT_ORION
1249 #define PLATFORM_DRIVER ehci_orion_driver
1252 #ifdef CONFIG_ARCH_IXP4XX
1254 #define PLATFORM_DRIVER ixp4xx_ehci_driver
1257 #ifdef CONFIG_USB_W90X900_EHCI
1259 #define PLATFORM_DRIVER ehci_hcd_w90x900_driver
1262 #ifdef CONFIG_ARCH_AT91
1264 #define PLATFORM_DRIVER ehci_atmel_driver
1267 #ifdef CONFIG_USB_OCTEON_EHCI
1269 #define PLATFORM_DRIVER ehci_octeon_driver
1272 #ifdef CONFIG_USB_CNS3XXX_EHCI
1274 #define PLATFORM_DRIVER cns3xxx_ehci_driver
1277 #ifdef CONFIG_ARCH_VT8500
1279 #define PLATFORM_DRIVER vt8500_ehci_driver
1282 #ifdef CONFIG_PLAT_SPEAR
1284 #define PLATFORM_DRIVER spear_ehci_hcd_driver
1287 #ifdef CONFIG_USB_EHCI_MSM
1289 #define PLATFORM_DRIVER ehci_msm_driver
1292 #ifdef CONFIG_TILE_USB
1294 #define PLATFORM_DRIVER ehci_hcd_tilegx_driver
1297 #ifdef CONFIG_USB_EHCI_HCD_PMC_MSP
1299 #define PLATFORM_DRIVER ehci_hcd_msp_driver
1302 #ifdef CONFIG_USB_EHCI_TEGRA
1304 #define PLATFORM_DRIVER tegra_ehci_driver
1307 #ifdef CONFIG_USB_EHCI_S5P
1309 #define PLATFORM_DRIVER s5p_ehci_driver
1312 #ifdef CONFIG_SPARC_LEON
1314 #define PLATFORM_DRIVER ehci_grlib_driver
1317 #ifdef CONFIG_CPU_XLR
1319 #define PLATFORM_DRIVER ehci_xls_driver
1322 #ifdef CONFIG_USB_EHCI_MV
1324 #define PLATFORM_DRIVER ehci_mv_driver
1327 #ifdef CONFIG_MACH_LOONGSON1
1329 #define PLATFORM_DRIVER ehci_ls1x_driver
1332 #ifdef CONFIG_MIPS_SEAD3
1334 #define PLATFORM_DRIVER ehci_hcd_sead3_driver
1337 #ifdef CONFIG_USB_EHCI_HCD_PLATFORM
1339 #define PLATFORM_DRIVER ehci_platform_driver
1342 #if !defined(PCI_DRIVER) && !defined(PLATFORM_DRIVER) && \
1343 !defined(PS3_SYSTEM_BUS_DRIVER) && !defined(OF_PLATFORM_DRIVER) && \
1344 !defined(XILINX_OF_PLATFORM_DRIVER)
1345 #error "missing bus glue for ehci-hcd"
1348 static int __init ehci_hcd_init(
void)
1360 " before uhci_hcd and ohci_hcd, not after\n");
1362 pr_debug(
"%s: block sizes: qh %Zd qtd %Zd itd %Zd sitd %Zd\n",
1369 if (!ehci_debug_root) {
1375 #ifdef PLATFORM_DRIVER
1382 retval = pci_register_driver(&PCI_DRIVER);
1387 #ifdef PS3_SYSTEM_BUS_DRIVER
1388 retval = ps3_ehci_driver_register(&PS3_SYSTEM_BUS_DRIVER);
1393 #ifdef OF_PLATFORM_DRIVER
1399 #ifdef XILINX_OF_PLATFORM_DRIVER
1406 #ifdef XILINX_OF_PLATFORM_DRIVER
1410 #ifdef OF_PLATFORM_DRIVER
1414 #ifdef PS3_SYSTEM_BUS_DRIVER
1415 ps3_ehci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);
1422 #ifdef PLATFORM_DRIVER
1428 ehci_debug_root =
NULL;
1436 static void __exit ehci_hcd_cleanup(
void)
1438 #ifdef XILINX_OF_PLATFORM_DRIVER
1441 #ifdef OF_PLATFORM_DRIVER
1444 #ifdef PLATFORM_DRIVER
1450 #ifdef PS3_SYSTEM_BUS_DRIVER
1451 ps3_ehci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);