ohci-spear.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. /*
  2. * OHCI HCD (Host Controller Driver) for USB.
  3. *
  4. * Copyright (C) 2010 ST Microelectronics.
  5. * Deepak Sikri<deepak.sikri@st.com>
  6. *
  7. * Based on various ohci-*.c drivers
  8. *
  9. * This file is licensed under the terms of the GNU General Public
  10. * License version 2. This program is licensed "as is" without any
  11. * warranty of any kind, whether express or implied.
  12. */
  13. #include <linux/signal.h>
  14. #include <linux/platform_device.h>
  15. #include <linux/clk.h>
  16. struct spear_ohci {
  17. struct ohci_hcd ohci;
  18. struct clk *clk;
  19. };
  20. #define to_spear_ohci(hcd) (struct spear_ohci *)hcd_to_ohci(hcd)
  21. static void spear_start_ohci(struct spear_ohci *ohci)
  22. {
  23. clk_enable(ohci->clk);
  24. }
  25. static void spear_stop_ohci(struct spear_ohci *ohci)
  26. {
  27. clk_disable(ohci->clk);
  28. }
  29. static int __devinit ohci_spear_start(struct usb_hcd *hcd)
  30. {
  31. struct ohci_hcd *ohci = hcd_to_ohci(hcd);
  32. int ret;
  33. ret = ohci_init(ohci);
  34. if (ret < 0)
  35. return ret;
  36. ohci->regs = hcd->regs;
  37. ret = ohci_run(ohci);
  38. if (ret < 0) {
  39. dev_err(hcd->self.controller, "can't start\n");
  40. ohci_stop(hcd);
  41. return ret;
  42. }
  43. create_debug_files(ohci);
  44. #ifdef DEBUG
  45. ohci_dump(ohci, 1);
  46. #endif
  47. return 0;
  48. }
  49. static const struct hc_driver ohci_spear_hc_driver = {
  50. .description = hcd_name,
  51. .product_desc = "SPEAr OHCI",
  52. .hcd_priv_size = sizeof(struct spear_ohci),
  53. /* generic hardware linkage */
  54. .irq = ohci_irq,
  55. .flags = HCD_USB11 | HCD_MEMORY,
  56. /* basic lifecycle operations */
  57. .start = ohci_spear_start,
  58. .stop = ohci_stop,
  59. .shutdown = ohci_shutdown,
  60. #ifdef CONFIG_PM
  61. .bus_suspend = ohci_bus_suspend,
  62. .bus_resume = ohci_bus_resume,
  63. #endif
  64. /* managing i/o requests and associated device resources */
  65. .urb_enqueue = ohci_urb_enqueue,
  66. .urb_dequeue = ohci_urb_dequeue,
  67. .endpoint_disable = ohci_endpoint_disable,
  68. /* scheduling support */
  69. .get_frame_number = ohci_get_frame,
  70. /* root hub support */
  71. .hub_status_data = ohci_hub_status_data,
  72. .hub_control = ohci_hub_control,
  73. .start_port_reset = ohci_start_port_reset,
  74. };
  75. static int spear_ohci_hcd_drv_probe(struct platform_device *pdev)
  76. {
  77. const struct hc_driver *driver = &ohci_spear_hc_driver;
  78. struct usb_hcd *hcd = NULL;
  79. struct clk *usbh_clk;
  80. struct spear_ohci *ohci_p;
  81. struct resource *res;
  82. int retval, irq;
  83. int *pdata = pdev->dev.platform_data;
  84. char clk_name[20] = "usbh_clk";
  85. if (pdata == NULL)
  86. return -EFAULT;
  87. irq = platform_get_irq(pdev, 0);
  88. if (irq < 0) {
  89. retval = irq;
  90. goto fail_irq_get;
  91. }
  92. if (*pdata >= 0)
  93. sprintf(clk_name, "usbh.%01d_clk", *pdata);
  94. usbh_clk = clk_get(NULL, clk_name);
  95. if (IS_ERR(usbh_clk)) {
  96. dev_err(&pdev->dev, "Error getting interface clock\n");
  97. retval = PTR_ERR(usbh_clk);
  98. goto fail_get_usbh_clk;
  99. }
  100. hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev));
  101. if (!hcd) {
  102. retval = -ENOMEM;
  103. goto fail_create_hcd;
  104. }
  105. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  106. if (!res) {
  107. retval = -ENODEV;
  108. goto fail_request_resource;
  109. }
  110. hcd->rsrc_start = pdev->resource[0].start;
  111. hcd->rsrc_len = resource_size(res);
  112. if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
  113. dev_dbg(&pdev->dev, "request_mem_region failed\n");
  114. retval = -EBUSY;
  115. goto fail_request_resource;
  116. }
  117. hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
  118. if (!hcd->regs) {
  119. dev_dbg(&pdev->dev, "ioremap failed\n");
  120. retval = -ENOMEM;
  121. goto fail_ioremap;
  122. }
  123. ohci_p = (struct spear_ohci *)hcd_to_ohci(hcd);
  124. ohci_p->clk = usbh_clk;
  125. spear_start_ohci(ohci_p);
  126. ohci_hcd_init(hcd_to_ohci(hcd));
  127. retval = usb_add_hcd(hcd, platform_get_irq(pdev, 0), 0);
  128. if (retval == 0)
  129. return retval;
  130. spear_stop_ohci(ohci_p);
  131. iounmap(hcd->regs);
  132. fail_ioremap:
  133. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  134. fail_request_resource:
  135. usb_put_hcd(hcd);
  136. fail_create_hcd:
  137. clk_put(usbh_clk);
  138. fail_get_usbh_clk:
  139. fail_irq_get:
  140. dev_err(&pdev->dev, "init fail, %d\n", retval);
  141. return retval;
  142. }
  143. static int spear_ohci_hcd_drv_remove(struct platform_device *pdev)
  144. {
  145. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  146. struct spear_ohci *ohci_p = to_spear_ohci(hcd);
  147. usb_remove_hcd(hcd);
  148. if (ohci_p->clk)
  149. spear_stop_ohci(ohci_p);
  150. iounmap(hcd->regs);
  151. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  152. usb_put_hcd(hcd);
  153. if (ohci_p->clk)
  154. clk_put(ohci_p->clk);
  155. platform_set_drvdata(pdev, NULL);
  156. return 0;
  157. }
  158. #if defined(CONFIG_PM)
  159. static int spear_ohci_hcd_drv_suspend(struct platform_device *dev,
  160. pm_message_t message)
  161. {
  162. struct usb_hcd *hcd = platform_get_drvdata(dev);
  163. struct ohci_hcd *ohci = hcd_to_ohci(hcd);
  164. struct spear_ohci *ohci_p = to_spear_ohci(hcd);
  165. if (time_before(jiffies, ohci->next_statechange))
  166. msleep(5);
  167. ohci->next_statechange = jiffies;
  168. spear_stop_ohci(ohci_p);
  169. return 0;
  170. }
  171. static int spear_ohci_hcd_drv_resume(struct platform_device *dev)
  172. {
  173. struct usb_hcd *hcd = platform_get_drvdata(dev);
  174. struct ohci_hcd *ohci = hcd_to_ohci(hcd);
  175. struct spear_ohci *ohci_p = to_spear_ohci(hcd);
  176. if (time_before(jiffies, ohci->next_statechange))
  177. msleep(5);
  178. ohci->next_statechange = jiffies;
  179. spear_start_ohci(ohci_p);
  180. ohci_finish_controller_resume(hcd);
  181. return 0;
  182. }
  183. #endif
  184. /* Driver definition to register with the platform bus */
  185. static struct platform_driver spear_ohci_hcd_driver = {
  186. .probe = spear_ohci_hcd_drv_probe,
  187. .remove = spear_ohci_hcd_drv_remove,
  188. #ifdef CONFIG_PM
  189. .suspend = spear_ohci_hcd_drv_suspend,
  190. .resume = spear_ohci_hcd_drv_resume,
  191. #endif
  192. .driver = {
  193. .owner = THIS_MODULE,
  194. .name = "spear-ohci",
  195. },
  196. };
  197. MODULE_ALIAS("platform:spear-ohci");