2 * OHCI HCD (Host Controller Driver) for USB.
4 * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
5 * (C) Copyright 2000-2002 David Brownell <dbrownell@users.sourceforge.net>
6 * (C) Copyright 2002 Hewlett-Packard Company
10 * Written by Christopher Hoover <ch@hpl.hp.com>
11 * Based on fragments of previous driver by Rusell King et al.
13 * Modified for OMAP from ohci-sa1111.c by Tony Lindgren <tony@atomide.com>
14 * Based on the 2.4 OMAP OHCI driver originally done by MontaVista Software Inc.
16 * This file is licenced under the GPL.
19 #include <asm/hardware.h>
22 #include <asm/arch/bus.h>
23 #include <asm/arch/hardware.h>
24 #include <asm/arch/mux.h>
25 #include <asm/arch/irqs.h>
27 #include "ohci-omap.h"
29 #ifndef CONFIG_ARCH_OMAP
30 #error "This file is OMAP bus glue. CONFIG_OMAP must be defined."
33 extern int usb_disabled(void);
34 extern int ocpi_enable(void);
37 * Use the first port only by default. Override with hmc_mode option.
39 * NOTE: Many OMAP-1510 Innovators supposedly have bad wiring for the USB ports
40 * 1 & 2, so only port 0 will work. To use the OHCI on the first port, use
41 * the Innovator USB client cable with a client-to-client connector and modify
42 * either the cable or the hub to feed 5V VBUS back to Innovator. VBUS should
43 * be the red lead in the cable.
45 * To mount USB hard disk as root, see the patch for do_mounts.c that tries
46 * remounting the root, and use root=0801 if your root is on sda1. Does not
49 static int default_hmc_mode = 16;
50 static int hmc_mode = 1234;
53 * Set the USB host pin multiplexing and the selected HMC mode
55 static int omap_usb_set_hmc_mode(int hmc_mode)
61 /* 0: function, 1: disabled, 2: disabled */
62 omap_cfg_reg(W4_USB_PUEN);
63 omap_cfg_reg(R18_1510_USB_GPIO0);
66 /* 0: function 1: host 2: host */
67 omap_cfg_reg(usb1_speed);
68 omap_cfg_reg(usb1_susp);
69 omap_cfg_reg(usb1_seo);
70 omap_cfg_reg(usb1_txen);
71 omap_cfg_reg(usb1_txd);
72 omap_cfg_reg(usb1_vp);
73 omap_cfg_reg(usb1_vm);
74 omap_cfg_reg(usb1_rcv);
75 omap_cfg_reg(usb2_susp);
76 omap_cfg_reg(usb2_seo);
77 omap_cfg_reg(usb2_txen);
78 omap_cfg_reg(usb2_txd);
79 omap_cfg_reg(usb2_vp);
80 omap_cfg_reg(usb2_vm);
81 omap_cfg_reg(usb2_rcv);
84 /* 0: host, 1: disabled, 2: disabled */
85 omap_cfg_reg(W9_USB0_TXEN);
86 omap_cfg_reg(AA9_USB0_VP);
87 omap_cfg_reg(Y5_USB0_RCV);
88 omap_cfg_reg(R9_USB0_VM);
89 omap_cfg_reg(V6_USB0_TXD);
90 omap_cfg_reg(W5_USB0_SE0);
93 printk("Unknown USB host configuration: %i\n", hmc_mode);
97 /* Write the selected HMC mode */
98 val = readl(MOD_CONF_CTRL_0) & ~HMC_CLEAR;
99 val |= (hmc_mode << 1);
100 writel(val, MOD_CONF_CTRL_0);
106 * OHCI clock initialization for OMAP-1510 and 1610
108 static int omap_ohci_clock_power(int on)
111 if (cpu_is_omap_1510()) {
112 /* Use DPLL, not APLL */
113 writel(readl(ULPD_APLL_CTRL_REG) & ~APLL_NDPLL_SWITCH,
117 writel(readl(ULPD_DPLL_CTRL_REG) | DPLL_PLL_ENABLE,
120 /* Software request for USB 48MHz clock */
121 writel(readl(ULPD_SOFT_REQ_REG) | SOFT_REQ_REG_REQ,
124 while (!(readl(ULPD_DPLL_CTRL_REG) & DPLL_LOCK));
127 if (cpu_is_omap_1610()) {
129 writel(readl(ULPD_SOFT_REQ_REG) | SOFT_USB_OTG_REQ,
132 /* USB host clock request if not using OTG */
133 writel(readl(ULPD_SOFT_REQ_REG) | SOFT_USB_REQ,
136 writel(readl(ULPD_STATUS_REQ_REG) | USB_HOST_DPLL_REQ,
137 ULPD_STATUS_REQ_REG);
140 /* Enable 48MHz clock to USB */
141 writel(readl(ULPD_CLOCK_CTRL_REG) | USB_MCLK_EN,
142 ULPD_CLOCK_CTRL_REG);
144 writel(readl(ARM_IDLECT2) | (1 << EN_LBFREECK) | (1 << EN_LBCK),
147 writel(readl(MOD_CONF_CTRL_0) | USB_HOST_HHC_UHOST_EN,
150 /* Disable 48MHz clock to USB */
151 writel(readl(ULPD_CLOCK_CTRL_REG) & ~USB_MCLK_EN,
152 ULPD_CLOCK_CTRL_REG);
154 /* FIXME: The DPLL stays on for now */
161 * Hardware specific transceiver power on/off
163 static int omap_ohci_transceiver_power(int on)
166 if (omap_is_innovator())
167 writel(readl(OMAP1510_FPGA_HOST_CTRL) | 0x20,
168 OMAP1510_FPGA_HOST_CTRL);
170 if (omap_is_innovator())
171 writel(readl(OMAP1510_FPGA_HOST_CTRL) & ~0x20,
172 OMAP1510_FPGA_HOST_CTRL);
179 * OMAP-1510 specific Local Bus clock on/off
181 static int omap_1510_local_bus_power(int on)
184 writel((1 << 1) | (1 << 0), OMAP1510_LB_MMU_CTL);
187 writel(0, OMAP1510_LB_MMU_CTL);
194 * OMAP-1510 specific Local Bus initialization
195 * NOTE: This assumes 32MB memory size in OMAP1510LB_MEMSIZE.
196 * See also arch/mach-omap/memory.h for __virt_to_bus() and
197 * __bus_to_virt() which need to match with the physical
198 * Local Bus address below.
200 static int omap_1510_local_bus_init(void)
203 unsigned long lbaddr, physaddr;
205 writel((readl(OMAP1510_LB_CLOCK_DIV) & 0xfffffff8) | 0x4,
206 OMAP1510_LB_CLOCK_DIV);
208 /* Configure the Local Bus MMU table */
209 for (tlb = 0; tlb < OMAP1510_LB_MEMSIZE; tlb++) {
210 lbaddr = tlb * 0x00100000 + OMAP1510_LB_OFFSET;
211 physaddr = tlb * 0x00100000 + PHYS_OFFSET;
212 writel((lbaddr & 0x0fffffff) >> 22, OMAP1510_LB_MMU_CAM_H);
213 writel(((lbaddr & 0x003ffc00) >> 6) | 0xc,
214 OMAP1510_LB_MMU_CAM_L);
215 writel(physaddr >> 16, OMAP1510_LB_MMU_RAM_H);
216 writel((physaddr & 0x0000fc00) | 0x300, OMAP1510_LB_MMU_RAM_L);
217 writel(tlb << 4, OMAP1510_LB_MMU_LCK);
218 writel(0x1, OMAP1510_LB_MMU_LD_TLB);
221 /* Enable the walking table */
222 writel(readl(OMAP1510_LB_MMU_CTL) | (1 << 3), OMAP1510_LB_MMU_CTL);
229 * OMAP-1610 specific hardware initialization
231 * Intended to configure OMAP-1610 USB host and OTG ports depending on
232 * the HMC mode selected.
234 * FIXME: Currently only supports alternate ping group 2 mode, should
235 * be easy to modify for other configurations once there is some
236 * hardware to test with.
238 static int omap_1610_usb_init(int mode)
242 /* Configure the OMAP transceiver settings */
243 val |= (1 << 8); /* CONF_USB2_UNI TRM p 15-205*/
244 val |= (4 << 4); /* TRM p 5-59, p 15-157 (1224) */
246 //val |= (1 << 3); /* Isolate integrated transceiver from port 0 */
247 val |= (1 << 2); /* Disable pulldown on integrated transceiver DM */
248 val |= (1 << 1); /* Disable pulldown on integraded transceiver DP */
250 writel(val, USB_TRANSCEIVER_CTRL);
252 /* Set the USB0_TRX_MODE */
256 val &= ~(7 << 16); /* Clear USB0_TRX_MODE */
257 val |= (3 << 16); /* 0 or 3, 6-wire DAT/SE0, TRM p 15-159 */
258 writel(val, OTG_SYSCON_1);
261 * Control via OTG, see TRM p 15-163
264 //val |= 1; /* REVISIT: Enable OTG = 1 */
266 /* Control via OTG */
271 val &= ~0x3f; /* Clear HMC mode */
272 val |= mode; /* Set HMC mode */
273 val &= ~(7 << 16); /* Clear ASE0_BRST */
274 val |= (4 << 16); /* Must be 4 */
275 val |= USBX_SYNCHRO; /* Must be set */
277 writel(val, OTG_SYSCON_2);
279 /* Enable OTG idle */
280 //writel(readl(OTG_SYSCON_1) | OTG_IDLE_EN, OTG_SYSCON_1);
285 /*-------------------------------------------------------------------------*/
287 static void omap_start_hc(struct omap_dev *dev)
289 printk(KERN_DEBUG __FILE__
290 ": starting OMAP OHCI USB Controller\n");
293 * Set the HMC mode for the USB ports
296 /* See note about the Innovator wiring above */
297 if (omap_is_innovator())
298 hmc_mode = 4; /* 0: function 1: host 2: host */
301 if (cpu_is_omap_1610())
304 omap_usb_set_hmc_mode(hmc_mode);
306 omap_ohci_clock_power(1);
307 omap_ohci_transceiver_power(1);
309 if (cpu_is_omap_1510()) {
310 omap_1510_local_bus_power(1);
311 omap_1510_local_bus_init();
314 if (cpu_is_omap_1610())
315 omap_1610_usb_init(hmc_mode);
317 //omap_enable_device(dev);
320 static void omap_stop_hc(struct omap_dev *dev)
322 printk(KERN_DEBUG __FILE__
323 ": stopping OMAP OHCI USB Controller\n");
326 * FIXME: Put the USB host controller into reset.
330 * FIXME: Stop the USB clock.
332 //omap_disable_device(dev);
337 /*-------------------------------------------------------------------------*/
339 static irqreturn_t usb_hcd_omap_hcim_irq (int irq, void *__hcd, struct pt_regs * r)
341 struct usb_hcd *hcd = __hcd;
343 return usb_hcd_irq(irq, hcd, r);
346 /*-------------------------------------------------------------------------*/
348 void usb_hcd_omap_remove (struct usb_hcd *, struct omap_dev *);
350 /* configure so an HC device and id are always provided */
351 /* always called with process context; sleeping is OK */
355 * usb_hcd_omap_probe - initialize OMAP-based HCDs
356 * Context: !in_interrupt()
358 * Allocates basic resources for this USB host controller, and
359 * then invokes the start() method for the HCD associated with it
360 * through the hotplug entry's driver_data.
362 * Store this function in the HCD's struct pci_driver as probe().
364 int usb_hcd_omap_probe (const struct hc_driver *driver,
365 struct usb_hcd **hcd_out,
366 struct omap_dev *dev)
369 struct usb_hcd *hcd = 0;
371 if (!request_mem_region(dev->res.start,
372 dev->res.end - dev->res.start + 1, hcd_name)) {
373 dbg("request_mem_region failed");
379 hcd = driver->hcd_alloc ();
381 dbg ("hcd_alloc failed");
386 hcd->driver = (struct hc_driver *) driver;
387 hcd->description = driver->description;
388 hcd->irq = dev->irq[0];
389 hcd->regs = dev->mapbase;
390 hcd->self.controller = &dev->dev;
392 retval = hcd_buffer_create (hcd);
394 dbg ("pool alloc fail");
398 retval = request_irq (hcd->irq,
399 usb_hcd_omap_hcim_irq,
400 SA_INTERRUPT, hcd->description, hcd);
402 dbg("request_irq failed");
407 info ("%s (OMAP) at 0x%p, irq %d\n",
408 hcd->description, hcd->regs, hcd->irq);
410 usb_bus_init (&hcd->self);
411 hcd->self.op = &usb_hcd_operations;
412 hcd->self.hcpriv = (void *) hcd;
413 hcd->self.bus_name = "omap";
414 hcd->product_desc = "OMAP OHCI";
416 INIT_LIST_HEAD (&hcd->dev_list);
417 usb_register_bus (&hcd->self);
419 if ((retval = driver->start (hcd)) < 0)
421 usb_hcd_omap_remove(hcd, dev);
429 hcd_buffer_destroy (hcd);
431 driver->hcd_free(hcd);
435 release_mem_region(dev->res.start, dev->res.end - dev->res.start + 1);
441 /* may be called without controller electrically present */
442 /* may be called with controller, bus, and devices active */
445 * usb_hcd_omap_remove - shutdown processing for OMAP-based HCDs
446 * @dev: USB Host Controller being removed
447 * Context: !in_interrupt()
449 * Reverses the effect of usb_hcd_omap_probe(), first invoking
450 * the HCD's stop() method. It is always called from a thread
451 * context, normally "rmmod", "apmd", or something similar.
454 void usb_hcd_omap_remove (struct usb_hcd *hcd, struct omap_dev *dev)
458 info ("remove: %s, state %x", hcd->self.bus_name, hcd->state);
463 hcd->state = USB_STATE_QUIESCING;
465 dbg ("%s: roothub graceful disconnect", hcd->self.bus_name);
466 usb_disconnect (&hcd->self.root_hub);
468 hcd->driver->stop (hcd);
469 hcd_buffer_destroy (hcd);
470 hcd->state = USB_STATE_HALT;
472 free_irq (hcd->irq, hcd);
474 usb_deregister_bus (&hcd->self);
477 hcd->driver->hcd_free (hcd);
481 release_mem_region(dev->res.start, dev->res.end - dev->res.start + 1);
484 /*-------------------------------------------------------------------------*/
487 ohci_omap_start (struct usb_hcd *hcd)
489 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
492 ohci->hcca = dma_alloc_consistent (hcd->self.controller,
493 sizeof *ohci->hcca, &ohci->hcca_dma);
497 memset (ohci->hcca, 0, sizeof (struct ohci_hcca));
498 if ((ret = ohci_mem_init (ohci)) < 0) {
502 ohci->regs = hcd->regs;
503 if (hc_reset (ohci) < 0) {
508 if (hc_start (ohci) < 0) {
509 err ("can't start %s", ohci->hcd.self.bus_name);
513 create_debug_files (ohci);
521 /*-------------------------------------------------------------------------*/
523 static const struct hc_driver ohci_omap_hc_driver = {
524 .description = hcd_name,
527 * generic hardware linkage
533 * basic lifecycle operations
535 .start = ohci_omap_start,
537 /* suspend: ohci_omap_suspend, -- tbd */
538 /* resume: ohci_omap_resume, -- tbd */
543 * memory lifecycle (except per-request)
545 .hcd_alloc = ohci_hcd_alloc,
546 .hcd_free = ohci_hcd_free,
549 * managing i/o requests and associated device resources
551 .urb_enqueue = ohci_urb_enqueue,
552 .urb_dequeue = ohci_urb_dequeue,
553 .endpoint_disable = ohci_endpoint_disable,
558 .get_frame_number = ohci_get_frame,
563 .hub_status_data = ohci_hub_status_data,
564 .hub_control = ohci_hub_control,
565 #ifdef CONFIG_USB_SUSPEND
566 .hub_suspend = ohci_hub_suspend,
567 .hub_resume = ohci_hub_resume,
571 /*-------------------------------------------------------------------------*/
573 static int ohci_hcd_omap_drv_probe(struct omap_dev *dev)
575 struct usb_hcd *hcd = NULL;
581 ret = usb_hcd_omap_probe(&ohci_omap_hc_driver, &hcd, dev);
584 omap_set_drvdata(dev, hcd);
589 static int ohci_hcd_omap_drv_remove(struct omap_dev *dev)
591 struct usb_hcd *hcd = omap_get_drvdata(dev);
593 usb_hcd_omap_remove(hcd, dev);
595 omap_set_drvdata(dev, NULL);
601 * Driver definition to register with the OMAP bus
603 static struct omap_driver ohci_hcd_omap_driver = {
605 .name = OMAP_OHCI_NAME,
607 .devid = OMAP_OCP_DEVID_USB,
608 .busid = OMAP_BUS_OCP,
610 .probe = ohci_hcd_omap_drv_probe,
611 .remove = ohci_hcd_omap_drv_remove,
614 /* Any dma_mask must be set for OHCI to work */
615 static u64 omap_dmamask = 0xffffffffUL;
618 * Device definition to match the driver above
620 static struct omap_dev ohci_hcd_omap_device = {
621 .name = OMAP_OHCI_NAME,
622 .devid = OMAP_OCP_DEVID_USB,
623 .busid = OMAP_BUS_OCP,
624 .mapbase = (void *)OMAP_OHCI_BASE,
625 .dma_mask = &omap_dmamask, /* Needed only for OHCI */
627 .start = OMAP_OHCI_BASE,
628 .end = OMAP_OHCI_BASE + OMAP_OHCI_SIZE,
635 static int __init ohci_hcd_omap_init (void)
639 dbg (DRIVER_INFO " (OMAP)");
640 dbg ("block sizes: ed %d td %d\n",
641 sizeof (struct ed), sizeof (struct td));
643 if (hmc_mode < 0 || hmc_mode > 25)
644 hmc_mode = default_hmc_mode;
646 /* Register the driver with OMAP bus */
647 ret = omap_driver_register(&ohci_hcd_omap_driver);
651 /* Register the device with OMAP bus */
652 ret = omap_device_register(&ohci_hcd_omap_device);
654 omap_driver_unregister(&ohci_hcd_omap_driver);
661 MODULE_PARM(hmc_mode, "hmc_mode");
663 static void __exit ohci_hcd_omap_cleanup (void)
665 omap_device_unregister(&ohci_hcd_omap_device);
666 omap_driver_unregister(&ohci_hcd_omap_driver);
669 module_init (ohci_hcd_omap_init);
670 module_exit (ohci_hcd_omap_cleanup);