ohci-spear.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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. #include <linux/of.h>
  17. struct spear_ohci {
  18. struct ohci_hcd ohci;
  19. struct clk *clk;
  20. };
  21. #define to_spear_ohci(hcd) (struct spear_ohci *)hcd_to_ohci(hcd)
  22. static void spear_start_ohci(struct spear_ohci *ohci)
  23. {
  24. clk_prepare_enable(ohci->clk);
  25. }
  26. static void spear_stop_ohci(struct spear_ohci *ohci)
  27. {
  28. clk_disable_unprepare(ohci->clk);
  29. }
  30. static int ohci_spear_start(struct usb_hcd *hcd)
  31. {
  32. struct ohci_hcd *ohci = hcd_to_ohci(hcd);
  33. int ret;
  34. ret = ohci_init(ohci);
  35. if (ret < 0)
  36. return ret;
  37. ohci->regs = hcd->regs;
  38. ret = ohci_run(ohci);
  39. if (ret < 0) {
  40. dev_err(hcd->self.controller, "can't start\n");
  41. ohci_stop(hcd);
  42. return ret;
  43. }
  44. create_debug_files(ohci);
  45. #ifdef DEBUG
  46. ohci_dump(ohci, 1);
  47. #endif
  48. return 0;
  49. }
  50. static const struct hc_driver ohci_spear_hc_driver = {
  51. .description = hcd_name,
  52. .product_desc = "SPEAr OHCI",
  53. .hcd_priv_size = sizeof(struct spear_ohci),
  54. /* generic hardware linkage */
  55. .irq = ohci_irq,
  56. .flags = HCD_USB11 | HCD_MEMORY,
  57. /* basic lifecycle operations */
  58. .start = ohci_spear_start,
  59. .stop = ohci_stop,
  60. .shutdown = ohci_shutdown,
  61. #ifdef CONFIG_PM
  62. .bus_suspend = ohci_bus_suspend,
  63. .bus_resume = ohci_bus_resume,
  64. #endif
  65. /* managing i/o requests and associated device resources */
  66. .urb_enqueue = ohci_urb_enqueue,
  67. .urb_dequeue = ohci_urb_dequeue,
  68. .endpoint_disable = ohci_endpoint_disable,
  69. /* scheduling support */
  70. .get_frame_number = ohci_get_frame,
  71. /* root hub support */
  72. .hub_status_data = ohci_hub_status_data,
  73. .hub_control = ohci_hub_control,
  74. .start_port_reset = ohci_start_port_reset,
  75. };
  76. static int spear_ohci_hcd_drv_probe(struct platform_device *pdev)
  77. {
  78. const struct hc_driver *driver = &ohci_spear_hc_driver;
  79. struct usb_hcd *hcd = NULL;
  80. struct clk *usbh_clk;
  81. struct spear_ohci *ohci_p;
  82. struct resource *res;
  83. int retval, irq;
  84. irq = platform_get_irq(pdev, 0);
  85. if (irq < 0) {
  86. retval = irq;
  87. goto fail;
  88. }
  89. /*
  90. * Right now device-tree probed devices don't get dma_mask set.
  91. * Since shared usb code relies on it, set it here for now.
  92. * Once we have dma capability bindings this can go away.
  93. */
  94. retval = dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
  95. if (retval)
  96. goto fail;
  97. usbh_clk = devm_clk_get(&pdev->dev, NULL);
  98. if (IS_ERR(usbh_clk)) {
  99. dev_err(&pdev->dev, "Error getting interface clock\n");
  100. retval = PTR_ERR(usbh_clk);
  101. goto fail;
  102. }
  103. hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev));
  104. if (!hcd) {
  105. retval = -ENOMEM;
  106. goto fail;
  107. }
  108. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  109. if (!res) {
  110. retval = -ENODEV;
  111. goto err_put_hcd;
  112. }
  113. hcd->rsrc_start = pdev->resource[0].start;
  114. hcd->rsrc_len = resource_size(res);
  115. if (!devm_request_mem_region(&pdev->dev, hcd->rsrc_start, hcd->rsrc_len,
  116. hcd_name)) {
  117. dev_dbg(&pdev->dev, "request_mem_region failed\n");
  118. retval = -EBUSY;
  119. goto err_put_hcd;
  120. }
  121. hcd->regs = devm_ioremap(&pdev->dev, hcd->rsrc_start, hcd->rsrc_len);
  122. if (!hcd->regs) {
  123. dev_dbg(&pdev->dev, "ioremap failed\n");
  124. retval = -ENOMEM;
  125. goto err_put_hcd;
  126. }
  127. ohci_p = (struct spear_ohci *)hcd_to_ohci(hcd);
  128. ohci_p->clk = usbh_clk;
  129. spear_start_ohci(ohci_p);
  130. ohci_hcd_init(hcd_to_ohci(hcd));
  131. retval = usb_add_hcd(hcd, platform_get_irq(pdev, 0), 0);
  132. if (retval == 0)
  133. return retval;
  134. spear_stop_ohci(ohci_p);
  135. err_put_hcd:
  136. usb_put_hcd(hcd);
  137. fail:
  138. dev_err(&pdev->dev, "init fail, %d\n", retval);
  139. return retval;
  140. }
  141. static int spear_ohci_hcd_drv_remove(struct platform_device *pdev)
  142. {
  143. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  144. struct spear_ohci *ohci_p = to_spear_ohci(hcd);
  145. usb_remove_hcd(hcd);
  146. if (ohci_p->clk)
  147. spear_stop_ohci(ohci_p);
  148. usb_put_hcd(hcd);
  149. return 0;
  150. }
  151. #if defined(CONFIG_PM)
  152. static int spear_ohci_hcd_drv_suspend(struct platform_device *dev,
  153. pm_message_t message)
  154. {
  155. struct usb_hcd *hcd = platform_get_drvdata(dev);
  156. struct ohci_hcd *ohci = hcd_to_ohci(hcd);
  157. struct spear_ohci *ohci_p = to_spear_ohci(hcd);
  158. if (time_before(jiffies, ohci->next_statechange))
  159. msleep(5);
  160. ohci->next_statechange = jiffies;
  161. spear_stop_ohci(ohci_p);
  162. return 0;
  163. }
  164. static int spear_ohci_hcd_drv_resume(struct platform_device *dev)
  165. {
  166. struct usb_hcd *hcd = platform_get_drvdata(dev);
  167. struct ohci_hcd *ohci = hcd_to_ohci(hcd);
  168. struct spear_ohci *ohci_p = to_spear_ohci(hcd);
  169. if (time_before(jiffies, ohci->next_statechange))
  170. msleep(5);
  171. ohci->next_statechange = jiffies;
  172. spear_start_ohci(ohci_p);
  173. ohci_resume(hcd, false);
  174. return 0;
  175. }
  176. #endif
  177. static struct of_device_id spear_ohci_id_table[] = {
  178. { .compatible = "st,spear600-ohci", },
  179. { },
  180. };
  181. /* Driver definition to register with the platform bus */
  182. static struct platform_driver spear_ohci_hcd_driver = {
  183. .probe = spear_ohci_hcd_drv_probe,
  184. .remove = spear_ohci_hcd_drv_remove,
  185. #ifdef CONFIG_PM
  186. .suspend = spear_ohci_hcd_drv_suspend,
  187. .resume = spear_ohci_hcd_drv_resume,
  188. #endif
  189. .driver = {
  190. .owner = THIS_MODULE,
  191. .name = "spear-ohci",
  192. .of_match_table = spear_ohci_id_table,
  193. },
  194. };
  195. MODULE_ALIAS("platform:spear-ohci");