ohci-ep93xx.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /*
  2. * OHCI HCD (Host Controller Driver) for USB.
  3. *
  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
  7. *
  8. * Bus Glue for ep93xx.
  9. *
  10. * Written by Christopher Hoover <ch@hpl.hp.com>
  11. * Based on fragments of previous driver by Russell King et al.
  12. *
  13. * Modified for LH7A404 from ohci-sa1111.c
  14. * by Durgesh Pattamatta <pattamattad@sharpsec.com>
  15. *
  16. * Modified for pxa27x from ohci-lh7a404.c
  17. * by Nick Bane <nick@cecomputing.co.uk> 26-8-2004
  18. *
  19. * Modified for ep93xx from ohci-pxa27x.c
  20. * by Lennert Buytenhek <buytenh@wantstofly.org> 28-2-2006
  21. * Based on an earlier driver by Ray Lehtiniemi
  22. *
  23. * This file is licenced under the GPL.
  24. */
  25. #include <linux/clk.h>
  26. #include <linux/device.h>
  27. #include <linux/signal.h>
  28. #include <linux/platform_device.h>
  29. static struct clk *usb_host_clock;
  30. static int ohci_ep93xx_start(struct usb_hcd *hcd)
  31. {
  32. struct ohci_hcd *ohci = hcd_to_ohci(hcd);
  33. int ret;
  34. if ((ret = ohci_init(ohci)) < 0)
  35. return ret;
  36. if ((ret = ohci_run(ohci)) < 0) {
  37. dev_err(hcd->self.controller, "can't start %s\n",
  38. hcd->self.bus_name);
  39. ohci_stop(hcd);
  40. return ret;
  41. }
  42. return 0;
  43. }
  44. static struct hc_driver ohci_ep93xx_hc_driver = {
  45. .description = hcd_name,
  46. .product_desc = "EP93xx OHCI",
  47. .hcd_priv_size = sizeof(struct ohci_hcd),
  48. .irq = ohci_irq,
  49. .flags = HCD_USB11 | HCD_MEMORY,
  50. .start = ohci_ep93xx_start,
  51. .stop = ohci_stop,
  52. .shutdown = ohci_shutdown,
  53. .urb_enqueue = ohci_urb_enqueue,
  54. .urb_dequeue = ohci_urb_dequeue,
  55. .endpoint_disable = ohci_endpoint_disable,
  56. .get_frame_number = ohci_get_frame,
  57. .hub_status_data = ohci_hub_status_data,
  58. .hub_control = ohci_hub_control,
  59. #ifdef CONFIG_PM
  60. .bus_suspend = ohci_bus_suspend,
  61. .bus_resume = ohci_bus_resume,
  62. #endif
  63. .start_port_reset = ohci_start_port_reset,
  64. };
  65. static int ohci_hcd_ep93xx_drv_probe(struct platform_device *pdev)
  66. {
  67. struct usb_hcd *hcd;
  68. struct resource *res;
  69. int irq;
  70. int ret;
  71. if (usb_disabled())
  72. return -ENODEV;
  73. irq = platform_get_irq(pdev, 0);
  74. if (irq < 0)
  75. return irq;
  76. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  77. if (!res)
  78. return -ENXIO;
  79. hcd = usb_create_hcd(&ohci_ep93xx_hc_driver, &pdev->dev, "ep93xx");
  80. if (!hcd)
  81. return -ENOMEM;
  82. hcd->rsrc_start = res->start;
  83. hcd->rsrc_len = resource_size(res);
  84. hcd->regs = devm_ioremap_resource(&pdev->dev, res);
  85. if (IS_ERR(hcd->regs)) {
  86. ret = PTR_ERR(hcd->regs);
  87. goto err_put_hcd;
  88. }
  89. usb_host_clock = devm_clk_get(&pdev->dev, NULL);
  90. if (IS_ERR(usb_host_clock)) {
  91. ret = PTR_ERR(usb_host_clock);
  92. goto err_put_hcd;
  93. }
  94. clk_enable(usb_host_clock);
  95. ohci_hcd_init(hcd_to_ohci(hcd));
  96. ret = usb_add_hcd(hcd, irq, 0);
  97. if (ret)
  98. goto err_clk_disable;
  99. return 0;
  100. err_clk_disable:
  101. clk_disable(usb_host_clock);
  102. err_put_hcd:
  103. usb_put_hcd(hcd);
  104. return ret;
  105. }
  106. static int ohci_hcd_ep93xx_drv_remove(struct platform_device *pdev)
  107. {
  108. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  109. usb_remove_hcd(hcd);
  110. clk_disable(usb_host_clock);
  111. usb_put_hcd(hcd);
  112. return 0;
  113. }
  114. #ifdef CONFIG_PM
  115. static int ohci_hcd_ep93xx_drv_suspend(struct platform_device *pdev, pm_message_t state)
  116. {
  117. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  118. struct ohci_hcd *ohci = hcd_to_ohci(hcd);
  119. if (time_before(jiffies, ohci->next_statechange))
  120. msleep(5);
  121. ohci->next_statechange = jiffies;
  122. clk_disable(usb_host_clock);
  123. return 0;
  124. }
  125. static int ohci_hcd_ep93xx_drv_resume(struct platform_device *pdev)
  126. {
  127. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  128. struct ohci_hcd *ohci = hcd_to_ohci(hcd);
  129. if (time_before(jiffies, ohci->next_statechange))
  130. msleep(5);
  131. ohci->next_statechange = jiffies;
  132. clk_enable(usb_host_clock);
  133. ohci_resume(hcd, false);
  134. return 0;
  135. }
  136. #endif
  137. static struct platform_driver ohci_hcd_ep93xx_driver = {
  138. .probe = ohci_hcd_ep93xx_drv_probe,
  139. .remove = ohci_hcd_ep93xx_drv_remove,
  140. .shutdown = usb_hcd_platform_shutdown,
  141. #ifdef CONFIG_PM
  142. .suspend = ohci_hcd_ep93xx_drv_suspend,
  143. .resume = ohci_hcd_ep93xx_drv_resume,
  144. #endif
  145. .driver = {
  146. .name = "ep93xx-ohci",
  147. .owner = THIS_MODULE,
  148. },
  149. };
  150. MODULE_ALIAS("platform:ep93xx-ohci");