2 * OHCI HCD (Host Controller Driver) for USB.
4 * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
5 * (C) Copyright 2000-2004 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 Russell 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>
21 #include <asm/mach-types.h>
23 #include <asm/arch/hardware.h>
24 #include <asm/arch/mux.h>
25 #include <asm/arch/irqs.h>
26 #include <asm/arch/gpio.h>
27 #include <asm/arch/fpga.h>
28 #include <asm/arch/usb.h>
30 #include "ohci-omap.h"
32 #ifndef CONFIG_ARCH_OMAP
33 #error "This file is OMAP bus glue. CONFIG_OMAP must be defined."
36 extern int usb_disabled(void);
37 extern int ocpi_enable(void);
40 * OHCI clock initialization for OMAP-1510 and 1610
42 static int omap_ohci_clock_power(int on)
45 /* for 1510, 48MHz DPLL is set up in usb init */
47 if (cpu_is_omap16xx()) {
49 omap_writel(omap_readl(ULPD_SOFT_REQ) | SOFT_USB_OTG_REQ,
52 /* USB host clock request if not using OTG */
53 omap_writel(omap_readl(ULPD_SOFT_REQ) | SOFT_USB_REQ,
56 omap_writel(omap_readl(ULPD_STATUS_REQ) | USB_HOST_DPLL_REQ,
60 /* Enable 48MHz clock to USB */
61 omap_writel(omap_readl(ULPD_CLOCK_CTRL) | USB_MCLK_EN,
64 omap_writel(omap_readl(ARM_IDLECT2) | (1 << EN_LBFREECK) | (1 << EN_LBCK),
67 omap_writel(omap_readl(MOD_CONF_CTRL_0) | USB_HOST_HHC_UHOST_EN,
70 /* Disable 48MHz clock to USB */
71 omap_writel(omap_readl(ULPD_CLOCK_CTRL) & ~USB_MCLK_EN,
74 /* FIXME: The DPLL stays on for now */
81 * Hardware specific transceiver power on/off
83 static int omap_ohci_transceiver_power(int on)
86 if (machine_is_omap_innovator() && cpu_is_omap1510())
87 fpga_write(fpga_read(INNOVATOR_FPGA_CAM_USB_CONTROL)
88 | ((1 << 5/*usb1*/) | (1 << 3/*usb2*/)),
89 INNOVATOR_FPGA_CAM_USB_CONTROL);
90 else if (machine_is_omap_osk()) {
91 /* FIXME: GPIO1 -> 1 on the TPS65010 I2C chip */
94 if (machine_is_omap_innovator() && cpu_is_omap1510())
95 fpga_write(fpga_read(INNOVATOR_FPGA_CAM_USB_CONTROL)
96 & ~((1 << 5/*usb1*/) | (1 << 3/*usb2*/)),
97 INNOVATOR_FPGA_CAM_USB_CONTROL);
98 else if (machine_is_omap_osk()) {
99 /* FIXME: GPIO1 -> 0 on the TPS65010 I2C chip */
107 * OMAP-1510 specific Local Bus clock on/off
109 static int omap_1510_local_bus_power(int on)
112 omap_writel((1 << 1) | (1 << 0), OMAP1510_LB_MMU_CTL);
115 omap_writel(0, OMAP1510_LB_MMU_CTL);
122 * OMAP-1510 specific Local Bus initialization
123 * NOTE: This assumes 32MB memory size in OMAP1510LB_MEMSIZE.
124 * See also arch/mach-omap/memory.h for __virt_to_dma() and
125 * __dma_to_virt() which need to match with the physical
126 * Local Bus address below.
128 static int omap_1510_local_bus_init(void)
131 unsigned long lbaddr, physaddr;
133 omap_writel((omap_readl(OMAP1510_LB_CLOCK_DIV) & 0xfffffff8) | 0x4,
134 OMAP1510_LB_CLOCK_DIV);
136 /* Configure the Local Bus MMU table */
137 for (tlb = 0; tlb < OMAP1510_LB_MEMSIZE; tlb++) {
138 lbaddr = tlb * 0x00100000 + OMAP1510_LB_OFFSET;
139 physaddr = tlb * 0x00100000 + PHYS_OFFSET;
140 omap_writel((lbaddr & 0x0fffffff) >> 22, OMAP1510_LB_MMU_CAM_H);
141 omap_writel(((lbaddr & 0x003ffc00) >> 6) | 0xc,
142 OMAP1510_LB_MMU_CAM_L);
143 omap_writel(physaddr >> 16, OMAP1510_LB_MMU_RAM_H);
144 omap_writel((physaddr & 0x0000fc00) | 0x300, OMAP1510_LB_MMU_RAM_L);
145 omap_writel(tlb << 4, OMAP1510_LB_MMU_LCK);
146 omap_writel(0x1, OMAP1510_LB_MMU_LD_TLB);
149 /* Enable the walking table */
150 omap_writel(omap_readl(OMAP1510_LB_MMU_CTL) | (1 << 3), OMAP1510_LB_MMU_CTL);
156 #ifdef CONFIG_USB_OTG
158 static void start_hnp(struct ohci_hcd *ohci)
160 const unsigned port = ohci->hcd.self.otg_port - 1;
163 otg_start_hnp(ohci->transceiver);
165 local_irq_save(flags);
166 ohci->transceiver->state = OTG_STATE_A_SUSPEND;
167 writel (RH_PS_PSS, &ohci->regs->roothub.portstatus [port]);
168 OTG_CTRL_REG &= ~OTG_A_BUSREQ;
169 local_irq_restore(flags);
174 /*-------------------------------------------------------------------------*/
176 static int omap_start_hc(struct ohci_hcd *ohci, struct platform_device *pdev)
178 struct omap_usb_config *config = pdev->dev.platform_data;
179 int need_transceiver = (config->otg != 0);
181 dev_dbg(&pdev->dev, "starting USB Controller\n");
184 ohci->hcd.self.otg_port = config->otg;
185 /* default/minimum OTG power budget: 8 mA */
186 ohci->power_budget = 8;
189 /* boards can use OTG transceivers in non-OTG modes */
190 need_transceiver = need_transceiver
191 || machine_is_omap_h2();
193 if (cpu_is_omap16xx())
196 #ifdef CONFIG_ARCH_OMAP_OTG
197 if (need_transceiver) {
198 ohci->transceiver = otg_get_transceiver();
199 if (ohci->transceiver) {
200 int status = otg_set_host(ohci->transceiver,
202 dev_dbg(&pdev->dev, "init %s transceiver, status %d\n",
203 ohci->transceiver->label, status);
205 if (ohci->transceiver)
206 put_device(ohci->transceiver->dev);
210 dev_err(&pdev->dev, "can't find transceiver\n");
216 if (machine_is_omap_osk()) {
217 omap_request_gpio(9);
218 omap_set_gpio_direction(9, 1);
219 omap_set_gpio_dataout(9, 1);
222 omap_ohci_clock_power(1);
224 omap_ohci_transceiver_power(1);
226 if (cpu_is_omap1510()) {
227 omap_1510_local_bus_power(1);
228 omap_1510_local_bus_init();
231 /* board init will have already handled HMC and mux setup.
232 * any external transceiver should already be initialized
233 * too, so all configured ports use the right signaling now.
239 static void omap_stop_hc(struct platform_device *pdev)
241 dev_dbg(&pdev->dev, "stopping USB Controller\n");
244 * FIXME: Put the USB host controller into reset.
248 * FIXME: Stop the USB clock.
250 //omap_disable_device(dev);
255 /*-------------------------------------------------------------------------*/
257 void usb_hcd_omap_remove (struct usb_hcd *, struct platform_device *);
259 /* configure so an HC device and id are always provided */
260 /* always called with process context; sleeping is OK */
264 * usb_hcd_omap_probe - initialize OMAP-based HCDs
265 * Context: !in_interrupt()
267 * Allocates basic resources for this USB host controller, and
268 * then invokes the start() method for the HCD associated with it
269 * through the hotplug entry's driver_data.
271 int usb_hcd_omap_probe (const struct hc_driver *driver,
272 struct platform_device *pdev)
275 struct usb_hcd *hcd = 0;
276 struct ohci_hcd *ohci;
278 if (pdev->num_resources != 2) {
279 printk(KERN_ERR "hcd probe: invalid num_resources: %i\n",
280 pdev->num_resources);
284 if (pdev->resource[0].flags != IORESOURCE_MEM
285 || pdev->resource[1].flags != IORESOURCE_IRQ) {
286 printk(KERN_ERR "hcd probe: invalid resource type\n");
290 if (!request_mem_region(pdev->resource[0].start,
291 pdev->resource[0].end - pdev->resource[0].start + 1, hcd_name)) {
292 dev_dbg(&pdev->dev, "request_mem_region failed\n");
296 hcd = driver->hcd_alloc ();
298 dev_dbg(&pdev->dev, "hcd_alloc failed\n");
302 dev_set_drvdata(&pdev->dev, hcd);
303 ohci = hcd_to_ohci(hcd);
305 hcd->driver = (struct hc_driver *) driver;
306 hcd->description = driver->description;
307 hcd->irq = pdev->resource[1].start;
308 hcd->regs = (void *)pdev->resource[0].start;
309 hcd->self.controller = &pdev->dev;
311 retval = omap_start_hc(ohci, pdev);
315 retval = hcd_buffer_create (hcd);
317 dev_dbg(&pdev->dev, "pool alloc fail\n");
321 retval = request_irq (hcd->irq, usb_hcd_irq,
322 SA_INTERRUPT, hcd->description, hcd);
324 dev_dbg(&pdev->dev, "request_irq failed\n");
329 dev_info(&pdev->dev, "at 0x%p, irq %d\n", hcd->regs, hcd->irq);
331 usb_bus_init (&hcd->self);
332 hcd->self.op = &usb_hcd_operations;
333 hcd->self.release = &usb_hcd_release;
334 hcd->self.hcpriv = (void *) hcd;
335 hcd->self.bus_name = pdev->dev.bus_id;
336 hcd->product_desc = "OMAP OHCI";
338 INIT_LIST_HEAD (&hcd->dev_list);
339 usb_register_bus (&hcd->self);
341 if ((retval = driver->start (hcd)) < 0)
343 usb_hcd_omap_remove(hcd, pdev);
350 hcd_buffer_destroy (hcd);
355 release_mem_region(pdev->resource[0].start,
356 pdev->resource[0].end - pdev->resource[0].start + 1);
358 dev_set_drvdata(&pdev->dev, 0);
363 /* may be called without controller electrically present */
364 /* may be called with controller, bus, and devices active */
367 * usb_hcd_omap_remove - shutdown processing for OMAP-based HCDs
368 * @dev: USB Host Controller being removed
369 * Context: !in_interrupt()
371 * Reverses the effect of usb_hcd_omap_probe(), first invoking
372 * the HCD's stop() method. It is always called from a thread
373 * context, normally "rmmod", "apmd", or something similar.
376 void usb_hcd_omap_remove (struct usb_hcd *hcd, struct platform_device *pdev)
378 dev_info(&pdev->dev, "remove: state %x\n", hcd->state);
383 hcd->state = USB_STATE_QUIESCING;
385 dev_dbg(&pdev->dev, "roothub graceful disconnect\n");
386 usb_disconnect (&hcd->self.root_hub);
388 hcd->driver->stop (hcd);
389 hcd_buffer_destroy (hcd);
390 hcd->state = USB_STATE_HALT;
392 if (machine_is_omap_osk())
395 free_irq (hcd->irq, hcd);
397 usb_deregister_bus (&hcd->self);
401 release_mem_region(pdev->resource[0].start,
402 pdev->resource[0].end - pdev->resource[0].start + 1);
405 /*-------------------------------------------------------------------------*/
408 ohci_omap_start (struct usb_hcd *hcd)
410 struct omap_usb_config *config;
411 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
414 if ((ret = ohci_init(ohci)) < 0)
417 config = hcd->self.controller->platform_data;
418 if (config->otg || config->rwc)
419 writel(OHCI_CTRL_RWC, &ohci->regs->control);
421 if ((ret = ohci_run (ohci)) < 0) {
422 err ("can't start %s", ohci->hcd.self.bus_name);
429 /*-------------------------------------------------------------------------*/
431 static const struct hc_driver ohci_omap_hc_driver = {
432 .description = hcd_name,
435 * generic hardware linkage
441 * basic lifecycle operations
443 .start = ohci_omap_start,
447 * memory lifecycle (except per-request)
449 .hcd_alloc = ohci_hcd_alloc,
452 * managing i/o requests and associated device resources
454 .urb_enqueue = ohci_urb_enqueue,
455 .urb_dequeue = ohci_urb_dequeue,
456 .endpoint_disable = ohci_endpoint_disable,
461 .get_frame_number = ohci_get_frame,
466 .hub_status_data = ohci_hub_status_data,
467 .hub_control = ohci_hub_control,
468 #ifdef CONFIG_USB_SUSPEND
469 .hub_suspend = ohci_hub_suspend,
470 .hub_resume = ohci_hub_resume,
472 .start_port_reset = ohci_start_port_reset,
475 /*-------------------------------------------------------------------------*/
477 static int ohci_hcd_omap_drv_probe(struct device *dev)
479 return usb_hcd_omap_probe(&ohci_omap_hc_driver,
480 to_platform_device(dev));
483 static int ohci_hcd_omap_drv_remove(struct device *dev)
485 struct platform_device *pdev = to_platform_device(dev);
486 struct usb_hcd *hcd = dev_get_drvdata(dev);
487 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
489 usb_hcd_omap_remove(hcd, pdev);
490 if (ohci->transceiver) {
491 (void) otg_set_host(ohci->transceiver, 0);
492 put_device(ohci->transceiver->dev);
494 dev_set_drvdata(dev, NULL);
499 /*-------------------------------------------------------------------------*/
501 #if defined(CONFIG_USB_SUSPEND) || defined(CONFIG_PM)
503 /* states match PCI usage, always suspending the root hub except that
504 * 4 ~= D3cold (ACPI D3) with clock off (resume sees reset).
507 static int ohci_omap_suspend(struct device *dev, u32 state, u32 level)
509 struct ohci_hcd *ohci = hcd_to_ohci(dev_get_drvdata(dev));
510 int status = -EINVAL;
512 if (state <= dev->power.power_state)
515 dev_dbg(dev, "suspend to %d\n", state);
516 down(&ohci->hcd.self.root_hub->serialize);
517 status = ohci_hub_suspend(&ohci->hcd);
520 /* power off + reset */
521 OTG_SYSCON_2_REG &= ~UHOST_EN;
522 ohci->hcd.self.root_hub->state = USB_STATE_SUSPENDED;
525 ohci->hcd.state = HCD_STATE_SUSPENDED;
526 dev->power.power_state = state;
528 up(&ohci->hcd.self.root_hub->serialize);
532 static int ohci_omap_resume(struct device *dev, u32 level)
534 struct ohci_hcd *ohci = hcd_to_ohci(dev_get_drvdata(dev));
537 switch (dev->power.power_state) {
541 if (time_before(jiffies, ohci->next_statechange))
543 ohci->next_statechange = jiffies;
544 OTG_SYSCON_2_REG |= UHOST_EN;
547 dev_dbg(dev, "resume from %d\n", dev->power.power_state);
548 #ifdef CONFIG_USB_SUSPEND
549 /* get extra cleanup even if remote wakeup isn't in use */
550 status = usb_resume_device(ohci->hcd.self.root_hub);
552 down(&ohci->hcd.self.root_hub->serialize);
553 status = ohci_hub_resume(&ohci->hcd);
554 up(&ohci->hcd.self.root_hub->serialize);
557 dev->power.power_state = 0;
565 /*-------------------------------------------------------------------------*/
568 * Driver definition to register with the OMAP bus
570 static struct device_driver ohci_hcd_omap_driver = {
572 .bus = &platform_bus_type,
573 .probe = ohci_hcd_omap_drv_probe,
574 .remove = ohci_hcd_omap_drv_remove,
575 #if defined(CONFIG_USB_SUSPEND) || defined(CONFIG_PM)
576 .suspend = ohci_omap_suspend,
577 .resume = ohci_omap_resume,
581 static int __init ohci_hcd_omap_init (void)
583 printk (KERN_DEBUG "%s: " DRIVER_INFO " (OMAP)\n", hcd_name);
587 pr_debug("%s: block sizes: ed %Zd td %Zd\n", hcd_name,
588 sizeof (struct ed), sizeof (struct td));
590 return driver_register(&ohci_hcd_omap_driver);
593 static void __exit ohci_hcd_omap_cleanup (void)
595 driver_unregister(&ohci_hcd_omap_driver);
598 module_init (ohci_hcd_omap_init);
599 module_exit (ohci_hcd_omap_cleanup);