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 if (cpu_is_omap1510()) {
46 /* Use DPLL, not APLL */
47 omap_writel(omap_readl(ULPD_APLL_CTRL) & ~APLL_NDPLL_SWITCH,
51 omap_writel(omap_readl(ULPD_DPLL_CTRL) | DPLL_PLL_ENABLE,
54 /* Software request for USB 48MHz clock */
55 omap_writel(omap_readl(ULPD_SOFT_REQ) | SOFT_REQ_REG_REQ,
58 while (!(omap_readl(ULPD_DPLL_CTRL) & DPLL_LOCK));
61 if (cpu_is_omap16xx()) {
63 omap_writel(omap_readl(ULPD_SOFT_REQ) | SOFT_USB_OTG_REQ,
66 /* USB host clock request if not using OTG */
67 omap_writel(omap_readl(ULPD_SOFT_REQ) | SOFT_USB_REQ,
70 omap_writel(omap_readl(ULPD_STATUS_REQ) | USB_HOST_DPLL_REQ,
74 /* Enable 48MHz clock to USB */
75 omap_writel(omap_readl(ULPD_CLOCK_CTRL) | USB_MCLK_EN,
78 omap_writel(omap_readl(ARM_IDLECT2) | (1 << EN_LBFREECK) | (1 << EN_LBCK),
81 omap_writel(omap_readl(MOD_CONF_CTRL_0) | USB_HOST_HHC_UHOST_EN,
84 /* Disable 48MHz clock to USB */
85 omap_writel(omap_readl(ULPD_CLOCK_CTRL) & ~USB_MCLK_EN,
88 /* FIXME: The DPLL stays on for now */
95 * Hardware specific transceiver power on/off
97 static int omap_ohci_transceiver_power(int on)
100 if (machine_is_omap_innovator() && cpu_is_omap1510())
101 fpga_write(fpga_read(INNOVATOR_FPGA_CAM_USB_CONTROL) | 0x20,
102 INNOVATOR_FPGA_CAM_USB_CONTROL);
103 else if (machine_is_omap_osk()) {
104 /* FIXME: GPIO1 -> 1 on the TPS65010 I2C chip */
107 if (machine_is_omap_innovator() && cpu_is_omap1510())
108 fpga_write(fpga_read(INNOVATOR_FPGA_CAM_USB_CONTROL) & ~0x20,
109 INNOVATOR_FPGA_CAM_USB_CONTROL);
110 else if (machine_is_omap_osk()) {
111 /* FIXME: GPIO1 -> 0 on the TPS65010 I2C chip */
119 * OMAP-1510 specific Local Bus clock on/off
121 static int omap_1510_local_bus_power(int on)
124 omap_writel((1 << 1) | (1 << 0), OMAP1510_LB_MMU_CTL);
127 omap_writel(0, OMAP1510_LB_MMU_CTL);
134 * OMAP-1510 specific Local Bus initialization
135 * NOTE: This assumes 32MB memory size in OMAP1510LB_MEMSIZE.
136 * See also arch/mach-omap/memory.h for __virt_to_dma() and
137 * __dma_to_virt() which need to match with the physical
138 * Local Bus address below.
140 static int omap_1510_local_bus_init(void)
143 unsigned long lbaddr, physaddr;
145 omap_writel((omap_readl(OMAP1510_LB_CLOCK_DIV) & 0xfffffff8) | 0x4,
146 OMAP1510_LB_CLOCK_DIV);
148 /* Configure the Local Bus MMU table */
149 for (tlb = 0; tlb < OMAP1510_LB_MEMSIZE; tlb++) {
150 lbaddr = tlb * 0x00100000 + OMAP1510_LB_OFFSET;
151 physaddr = tlb * 0x00100000 + PHYS_OFFSET;
152 omap_writel((lbaddr & 0x0fffffff) >> 22, OMAP1510_LB_MMU_CAM_H);
153 omap_writel(((lbaddr & 0x003ffc00) >> 6) | 0xc,
154 OMAP1510_LB_MMU_CAM_L);
155 omap_writel(physaddr >> 16, OMAP1510_LB_MMU_RAM_H);
156 omap_writel((physaddr & 0x0000fc00) | 0x300, OMAP1510_LB_MMU_RAM_L);
157 omap_writel(tlb << 4, OMAP1510_LB_MMU_LCK);
158 omap_writel(0x1, OMAP1510_LB_MMU_LD_TLB);
161 /* Enable the walking table */
162 omap_writel(omap_readl(OMAP1510_LB_MMU_CTL) | (1 << 3), OMAP1510_LB_MMU_CTL);
168 #ifdef CONFIG_USB_OTG
170 static void start_hnp(struct ohci_hcd *ohci)
172 const unsigned port = ohci->hcd.self.otg_port - 1;
175 otg_start_hnp(ohci->transceiver);
177 local_irq_save(flags);
178 ohci->transceiver->state = OTG_STATE_A_SUSPEND;
179 writel (RH_PS_PSS, &ohci->regs->roothub.portstatus [port]);
180 OTG_CTRL_REG &= ~OTG_A_BUSREQ;
181 local_irq_restore(flags);
186 /*-------------------------------------------------------------------------*/
188 static int omap_start_hc(struct ohci_hcd *ohci, struct platform_device *pdev)
190 struct omap_usb_config *config = pdev->dev.platform_data;
191 int need_transceiver = (config->otg != 0);
193 dev_dbg(&pdev->dev, "starting USB Controller\n");
196 ohci->hcd.self.otg_port = config->otg;
197 /* default/minimum OTG power budget: 8 mA */
198 ohci->power_budget = 8;
201 /* boards can use OTG transceivers in non-OTG modes */
202 need_transceiver = need_transceiver
203 || machine_is_omap_h2();
205 if (cpu_is_omap16xx())
208 #ifdef CONFIG_ARCH_OMAP_OTG
209 if (need_transceiver) {
210 ohci->transceiver = otg_get_transceiver();
211 if (ohci->transceiver) {
212 int status = otg_set_host(ohci->transceiver,
214 dev_dbg(&pdev->dev, "init %s transceiver, status %d\n",
215 ohci->transceiver->label, status);
217 if (ohci->transceiver)
218 put_device(ohci->transceiver->dev);
222 dev_err(&pdev->dev, "can't find transceiver\n");
228 if (machine_is_omap_osk()) {
229 omap_request_gpio(9);
230 omap_set_gpio_direction(9, 1);
231 omap_set_gpio_dataout(9, 1);
234 omap_ohci_clock_power(1);
236 omap_ohci_transceiver_power(1);
238 if (cpu_is_omap1510()) {
239 omap_1510_local_bus_power(1);
240 omap_1510_local_bus_init();
243 /* board init will have already handled HMC and mux setup.
244 * any external transceiver should already be initialized
245 * too, so all configured ports use the right signaling now.
251 static void omap_stop_hc(struct platform_device *pdev)
253 dev_dbg(&pdev->dev, "stopping USB Controller\n");
256 * FIXME: Put the USB host controller into reset.
260 * FIXME: Stop the USB clock.
262 //omap_disable_device(dev);
267 /*-------------------------------------------------------------------------*/
269 void usb_hcd_omap_remove (struct usb_hcd *, struct platform_device *);
271 /* configure so an HC device and id are always provided */
272 /* always called with process context; sleeping is OK */
276 * usb_hcd_omap_probe - initialize OMAP-based HCDs
277 * Context: !in_interrupt()
279 * Allocates basic resources for this USB host controller, and
280 * then invokes the start() method for the HCD associated with it
281 * through the hotplug entry's driver_data.
283 int usb_hcd_omap_probe (const struct hc_driver *driver,
284 struct platform_device *pdev)
287 struct usb_hcd *hcd = 0;
288 struct ohci_hcd *ohci;
290 if (pdev->num_resources != 2) {
291 printk(KERN_ERR "hcd probe: invalid num_resources: %i\n",
292 pdev->num_resources);
296 if (pdev->resource[0].flags != IORESOURCE_MEM
297 || pdev->resource[1].flags != IORESOURCE_IRQ) {
298 printk(KERN_ERR "hcd probe: invalid resource type\n");
302 if (!request_mem_region(pdev->resource[0].start,
303 pdev->resource[0].end - pdev->resource[0].start + 1, hcd_name)) {
304 dev_dbg(&pdev->dev, "request_mem_region failed\n");
308 hcd = driver->hcd_alloc ();
310 dev_dbg(&pdev->dev, "hcd_alloc failed\n");
314 dev_set_drvdata(&pdev->dev, hcd);
315 ohci = hcd_to_ohci(hcd);
317 hcd->driver = (struct hc_driver *) driver;
318 hcd->description = driver->description;
319 hcd->irq = pdev->resource[1].start;
320 hcd->regs = (void *)pdev->resource[0].start;
321 hcd->self.controller = &pdev->dev;
323 retval = omap_start_hc(ohci, pdev);
327 retval = hcd_buffer_create (hcd);
329 dev_dbg(&pdev->dev, "pool alloc fail\n");
333 retval = request_irq (hcd->irq, usb_hcd_irq,
334 SA_INTERRUPT, hcd->description, hcd);
336 dev_dbg(&pdev->dev, "request_irq failed\n");
341 dev_info(&pdev->dev, "at 0x%p, irq %d\n", hcd->regs, hcd->irq);
343 usb_bus_init (&hcd->self);
344 hcd->self.op = &usb_hcd_operations;
345 hcd->self.hcpriv = (void *) hcd;
346 hcd->self.bus_name = pdev->dev.bus_id;
347 hcd->product_desc = "OMAP OHCI";
349 INIT_LIST_HEAD (&hcd->dev_list);
350 usb_register_bus (&hcd->self);
352 if ((retval = driver->start (hcd)) < 0)
354 usb_hcd_omap_remove(hcd, pdev);
361 hcd_buffer_destroy (hcd);
363 driver->hcd_free(hcd);
367 release_mem_region(pdev->resource[0].start,
368 pdev->resource[0].end - pdev->resource[0].start + 1);
370 dev_set_drvdata(&pdev->dev, 0);
375 /* may be called without controller electrically present */
376 /* may be called with controller, bus, and devices active */
379 * usb_hcd_omap_remove - shutdown processing for OMAP-based HCDs
380 * @dev: USB Host Controller being removed
381 * Context: !in_interrupt()
383 * Reverses the effect of usb_hcd_omap_probe(), first invoking
384 * the HCD's stop() method. It is always called from a thread
385 * context, normally "rmmod", "apmd", or something similar.
388 void usb_hcd_omap_remove (struct usb_hcd *hcd, struct platform_device *pdev)
392 dev_info(&pdev->dev, "remove: state %x\n", hcd->state);
397 hcd->state = USB_STATE_QUIESCING;
399 dev_dbg(&pdev->dev, "roothub graceful disconnect\n");
400 usb_disconnect (&hcd->self.root_hub);
402 hcd->driver->stop (hcd);
403 hcd_buffer_destroy (hcd);
404 hcd->state = USB_STATE_HALT;
406 if (machine_is_omap_osk())
409 free_irq (hcd->irq, hcd);
411 usb_deregister_bus (&hcd->self);
414 hcd->driver->hcd_free (hcd);
418 release_mem_region(pdev->resource[0].start,
419 pdev->resource[0].end - pdev->resource[0].start + 1);
422 /*-------------------------------------------------------------------------*/
425 ohci_omap_start (struct usb_hcd *hcd)
427 struct omap_usb_config *config;
428 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
431 config = hcd->self.controller->platform_data;
432 ohci->hcca = dma_alloc_coherent (hcd->self.controller,
433 sizeof *ohci->hcca, &ohci->hcca_dma, 0);
437 memset (ohci->hcca, 0, sizeof (struct ohci_hcca));
438 if ((ret = ohci_mem_init (ohci)) < 0) {
442 ohci->regs = hcd->regs;
444 if (config->otg || config->rwc)
445 writel(OHCI_CTRL_RWC, &ohci->regs->control);
447 if (hc_reset (ohci) < 0) {
452 if (hc_start (ohci) < 0) {
453 err ("can't start %s", ohci->hcd.self.bus_name);
457 if (ohci->power_budget)
458 hub_set_power_budget(ohci->hcd.self.root_hub,
460 create_debug_files (ohci);
468 /*-------------------------------------------------------------------------*/
470 static const struct hc_driver ohci_omap_hc_driver = {
471 .description = hcd_name,
474 * generic hardware linkage
480 * basic lifecycle operations
482 .start = ohci_omap_start,
486 * memory lifecycle (except per-request)
488 .hcd_alloc = ohci_hcd_alloc,
489 .hcd_free = ohci_hcd_free,
492 * managing i/o requests and associated device resources
494 .urb_enqueue = ohci_urb_enqueue,
495 .urb_dequeue = ohci_urb_dequeue,
496 .endpoint_disable = ohci_endpoint_disable,
501 .get_frame_number = ohci_get_frame,
506 .hub_status_data = ohci_hub_status_data,
507 .hub_control = ohci_hub_control,
508 #ifdef CONFIG_USB_SUSPEND
509 .hub_suspend = ohci_hub_suspend,
510 .hub_resume = ohci_hub_resume,
512 .start_port_reset = ohci_start_port_reset,
515 /*-------------------------------------------------------------------------*/
517 static int ohci_hcd_omap_drv_probe(struct device *dev)
519 return usb_hcd_omap_probe(&ohci_omap_hc_driver,
520 to_platform_device(dev));
523 static int ohci_hcd_omap_drv_remove(struct device *dev)
525 struct platform_device *pdev = to_platform_device(dev);
526 struct usb_hcd *hcd = dev_get_drvdata(dev);
527 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
529 usb_hcd_omap_remove(hcd, pdev);
530 if (ohci->transceiver) {
531 (void) otg_set_host(ohci->transceiver, 0);
532 put_device(ohci->transceiver->dev);
534 dev_set_drvdata(dev, NULL);
539 /*-------------------------------------------------------------------------*/
541 #if defined(CONFIG_USB_SUSPEND) || defined(CONFIG_PM)
543 /* states match PCI usage, always suspending the root hub except that
544 * 4 ~= D3cold (ACPI D3) with clock off (resume sees reset).
547 static int ohci_omap_suspend(struct device *dev, u32 state, u32 level)
549 struct ohci_hcd *ohci = hcd_to_ohci(dev_get_drvdata(dev));
550 int status = -EINVAL;
552 if (state <= dev->power.power_state)
555 dev_dbg(dev, "suspend to %d\n", state);
556 down(&ohci->hcd.self.root_hub->serialize);
557 status = ohci_hub_suspend(&ohci->hcd);
560 /* power off + reset */
561 OTG_SYSCON_2_REG &= ~UHOST_EN;
562 ohci->hcd.self.root_hub->state = USB_STATE_SUSPENDED;
565 ohci->hcd.state = HCD_STATE_SUSPENDED;
566 dev->power.power_state = state;
568 up(&ohci->hcd.self.root_hub->serialize);
572 static int ohci_omap_resume(struct device *dev, u32 level)
574 struct ohci_hcd *ohci = hcd_to_ohci(dev_get_drvdata(dev));
577 switch (dev->power.power_state) {
581 if (time_before(jiffies, ohci->next_statechange))
583 ohci->next_statechange = jiffies;
584 OTG_SYSCON_2_REG |= UHOST_EN;
587 dev_dbg(dev, "resume from %d\n", dev->power.power_state);
588 #ifdef CONFIG_USB_SUSPEND
589 /* get extra cleanup even if remote wakeup isn't in use */
590 status = usb_resume_device(ohci->hcd.self.root_hub);
592 down(&ohci->hcd.self.root_hub->serialize);
593 status = ohci_hub_resume(&ohci->hcd);
594 up(&ohci->hcd.self.root_hub->serialize);
597 dev->power.power_state = 0;
605 /*-------------------------------------------------------------------------*/
608 * Driver definition to register with the OMAP bus
610 static struct device_driver ohci_hcd_omap_driver = {
612 .bus = &platform_bus_type,
613 .probe = ohci_hcd_omap_drv_probe,
614 .remove = ohci_hcd_omap_drv_remove,
615 #if defined(CONFIG_USB_SUSPEND) || defined(CONFIG_PM)
616 .suspend = ohci_omap_suspend,
617 .resume = ohci_omap_resume,
621 static int __init ohci_hcd_omap_init (void)
623 printk (KERN_DEBUG "%s: " DRIVER_INFO " (OMAP)\n", hcd_name);
627 pr_debug("%s: block sizes: ed %Zd td %Zd\n", hcd_name,
628 sizeof (struct ed), sizeof (struct td));
630 return driver_register(&ohci_hcd_omap_driver);
633 static void __exit ohci_hcd_omap_cleanup (void)
635 driver_unregister(&ohci_hcd_omap_driver);
638 module_init (ohci_hcd_omap_init);
639 module_exit (ohci_hcd_omap_cleanup);