ohci-ep93xx.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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/io.h>
  28. #include <linux/kernel.h>
  29. #include <linux/module.h>
  30. #include <linux/platform_device.h>
  31. #include <linux/signal.h>
  32. #include <linux/usb.h>
  33. #include <linux/usb/hcd.h>
  34. #include "ohci.h"
  35. #define DRIVER_DESC "OHCI EP93xx driver"
  36. static const char hcd_name[] = "ohci-ep93xx";
  37. static struct hc_driver __read_mostly ohci_ep93xx_hc_driver;
  38. static struct clk *usb_host_clock;
  39. static int ohci_hcd_ep93xx_drv_probe(struct platform_device *pdev)
  40. {
  41. struct usb_hcd *hcd;
  42. struct resource *res;
  43. int irq;
  44. int ret;
  45. if (usb_disabled())
  46. return -ENODEV;
  47. irq = platform_get_irq(pdev, 0);
  48. if (irq < 0)
  49. return irq;
  50. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  51. if (!res)
  52. return -ENXIO;
  53. hcd = usb_create_hcd(&ohci_ep93xx_hc_driver, &pdev->dev, "ep93xx");
  54. if (!hcd)
  55. return -ENOMEM;
  56. hcd->rsrc_start = res->start;
  57. hcd->rsrc_len = resource_size(res);
  58. hcd->regs = devm_ioremap_resource(&pdev->dev, res);
  59. if (IS_ERR(hcd->regs)) {
  60. ret = PTR_ERR(hcd->regs);
  61. goto err_put_hcd;
  62. }
  63. usb_host_clock = devm_clk_get(&pdev->dev, NULL);
  64. if (IS_ERR(usb_host_clock)) {
  65. ret = PTR_ERR(usb_host_clock);
  66. goto err_put_hcd;
  67. }
  68. clk_enable(usb_host_clock);
  69. ret = usb_add_hcd(hcd, irq, 0);
  70. if (ret)
  71. goto err_clk_disable;
  72. return 0;
  73. err_clk_disable:
  74. clk_disable(usb_host_clock);
  75. err_put_hcd:
  76. usb_put_hcd(hcd);
  77. return ret;
  78. }
  79. static int ohci_hcd_ep93xx_drv_remove(struct platform_device *pdev)
  80. {
  81. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  82. usb_remove_hcd(hcd);
  83. clk_disable(usb_host_clock);
  84. usb_put_hcd(hcd);
  85. return 0;
  86. }
  87. #ifdef CONFIG_PM
  88. static int ohci_hcd_ep93xx_drv_suspend(struct platform_device *pdev, pm_message_t state)
  89. {
  90. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  91. struct ohci_hcd *ohci = hcd_to_ohci(hcd);
  92. bool do_wakeup = device_may_wakeup(&pdev->dev);
  93. int ret;
  94. if (time_before(jiffies, ohci->next_statechange))
  95. msleep(5);
  96. ohci->next_statechange = jiffies;
  97. ret = ohci_suspend(hcd, do_wakeup);
  98. if (ret)
  99. return ret;
  100. ep93xx_stop_hc(&pdev->dev);
  101. return ret;
  102. }
  103. static int ohci_hcd_ep93xx_drv_resume(struct platform_device *pdev)
  104. {
  105. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  106. struct ohci_hcd *ohci = hcd_to_ohci(hcd);
  107. if (time_before(jiffies, ohci->next_statechange))
  108. msleep(5);
  109. ohci->next_statechange = jiffies;
  110. clk_enable(usb_host_clock);
  111. ohci_resume(hcd, false);
  112. return 0;
  113. }
  114. #endif
  115. static struct platform_driver ohci_hcd_ep93xx_driver = {
  116. .probe = ohci_hcd_ep93xx_drv_probe,
  117. .remove = ohci_hcd_ep93xx_drv_remove,
  118. .shutdown = usb_hcd_platform_shutdown,
  119. #ifdef CONFIG_PM
  120. .suspend = ohci_hcd_ep93xx_drv_suspend,
  121. .resume = ohci_hcd_ep93xx_drv_resume,
  122. #endif
  123. .driver = {
  124. .name = "ep93xx-ohci",
  125. .owner = THIS_MODULE,
  126. },
  127. };
  128. static int __init ohci_ep93xx_init(void)
  129. {
  130. if (usb_disabled())
  131. return -ENODEV;
  132. pr_info("%s: " DRIVER_DESC "\n", hcd_name);
  133. ohci_init_driver(&ohci_ep93xx_hc_driver, NULL);
  134. return platform_driver_register(&ohci_hcd_ep93xx_driver);
  135. }
  136. module_init(ohci_ep93xx_init);
  137. static void __exit ohci_ep93xx_cleanup(void)
  138. {
  139. platform_driver_unregister(&ohci_hcd_ep93xx_driver);
  140. }
  141. module_exit(ohci_ep93xx_cleanup);
  142. MODULE_DESCRIPTION(DRIVER_DESC);
  143. MODULE_LICENSE("GPL");
  144. MODULE_ALIAS("platform:ep93xx-ohci");