ehci-spear.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. /*
  2. * Driver for EHCI HCD on SPEAR SOC
  3. *
  4. * Copyright (C) 2010 ST Micro Electronics,
  5. * Deepak Sikri <deepak.sikri@st.com>
  6. *
  7. * Based on various ehci-*.c drivers
  8. *
  9. * This file is subject to the terms and conditions of the GNU General Public
  10. * License. See the file COPYING in the main directory of this archive for
  11. * more details.
  12. */
  13. #include <linux/clk.h>
  14. #include <linux/jiffies.h>
  15. #include <linux/of.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/pm.h>
  18. struct spear_ehci {
  19. struct ehci_hcd ehci;
  20. struct clk *clk;
  21. };
  22. #define to_spear_ehci(hcd) (struct spear_ehci *)hcd_to_ehci(hcd)
  23. static void spear_start_ehci(struct spear_ehci *ehci)
  24. {
  25. clk_prepare_enable(ehci->clk);
  26. }
  27. static void spear_stop_ehci(struct spear_ehci *ehci)
  28. {
  29. clk_disable_unprepare(ehci->clk);
  30. }
  31. static int ehci_spear_setup(struct usb_hcd *hcd)
  32. {
  33. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  34. int retval = 0;
  35. /* registers start at offset 0x0 */
  36. ehci->caps = hcd->regs;
  37. retval = ehci_setup(hcd);
  38. if (retval)
  39. return retval;
  40. ehci_port_power(ehci, 0);
  41. return retval;
  42. }
  43. static const struct hc_driver ehci_spear_hc_driver = {
  44. .description = hcd_name,
  45. .product_desc = "SPEAr EHCI",
  46. .hcd_priv_size = sizeof(struct spear_ehci),
  47. /* generic hardware linkage */
  48. .irq = ehci_irq,
  49. .flags = HCD_MEMORY | HCD_USB2,
  50. /* basic lifecycle operations */
  51. .reset = ehci_spear_setup,
  52. .start = ehci_run,
  53. .stop = ehci_stop,
  54. .shutdown = ehci_shutdown,
  55. /* managing i/o requests and associated device resources */
  56. .urb_enqueue = ehci_urb_enqueue,
  57. .urb_dequeue = ehci_urb_dequeue,
  58. .endpoint_disable = ehci_endpoint_disable,
  59. .endpoint_reset = ehci_endpoint_reset,
  60. /* scheduling support */
  61. .get_frame_number = ehci_get_frame,
  62. /* root hub support */
  63. .hub_status_data = ehci_hub_status_data,
  64. .hub_control = ehci_hub_control,
  65. .bus_suspend = ehci_bus_suspend,
  66. .bus_resume = ehci_bus_resume,
  67. .relinquish_port = ehci_relinquish_port,
  68. .port_handed_over = ehci_port_handed_over,
  69. .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
  70. };
  71. #ifdef CONFIG_PM
  72. static int ehci_spear_drv_suspend(struct device *dev)
  73. {
  74. struct usb_hcd *hcd = dev_get_drvdata(dev);
  75. bool do_wakeup = device_may_wakeup(dev);
  76. return ehci_suspend(hcd, do_wakeup);
  77. }
  78. static int ehci_spear_drv_resume(struct device *dev)
  79. {
  80. struct usb_hcd *hcd = dev_get_drvdata(dev);
  81. ehci_resume(hcd, false);
  82. return 0;
  83. }
  84. #endif /* CONFIG_PM */
  85. static SIMPLE_DEV_PM_OPS(ehci_spear_pm_ops, ehci_spear_drv_suspend,
  86. ehci_spear_drv_resume);
  87. static u64 spear_ehci_dma_mask = DMA_BIT_MASK(32);
  88. static int spear_ehci_hcd_drv_probe(struct platform_device *pdev)
  89. {
  90. struct usb_hcd *hcd ;
  91. struct spear_ehci *ehci;
  92. struct resource *res;
  93. struct clk *usbh_clk;
  94. const struct hc_driver *driver = &ehci_spear_hc_driver;
  95. int irq, retval;
  96. char clk_name[20] = "usbh_clk";
  97. static int instance = -1;
  98. if (usb_disabled())
  99. return -ENODEV;
  100. irq = platform_get_irq(pdev, 0);
  101. if (irq < 0) {
  102. retval = irq;
  103. goto fail_irq_get;
  104. }
  105. /*
  106. * Right now device-tree probed devices don't get dma_mask set.
  107. * Since shared usb code relies on it, set it here for now.
  108. * Once we have dma capability bindings this can go away.
  109. */
  110. if (!pdev->dev.dma_mask)
  111. pdev->dev.dma_mask = &spear_ehci_dma_mask;
  112. /*
  113. * Increment the device instance, when probing via device-tree
  114. */
  115. if (pdev->id < 0)
  116. instance++;
  117. else
  118. instance = pdev->id;
  119. sprintf(clk_name, "usbh.%01d_clk", instance);
  120. usbh_clk = clk_get(NULL, clk_name);
  121. if (IS_ERR(usbh_clk)) {
  122. dev_err(&pdev->dev, "Error getting interface clock\n");
  123. retval = PTR_ERR(usbh_clk);
  124. goto fail_get_usbh_clk;
  125. }
  126. hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev));
  127. if (!hcd) {
  128. retval = -ENOMEM;
  129. goto fail_create_hcd;
  130. }
  131. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  132. if (!res) {
  133. retval = -ENODEV;
  134. goto fail_request_resource;
  135. }
  136. hcd->rsrc_start = res->start;
  137. hcd->rsrc_len = resource_size(res);
  138. if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len,
  139. driver->description)) {
  140. retval = -EBUSY;
  141. goto fail_request_resource;
  142. }
  143. hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
  144. if (hcd->regs == NULL) {
  145. dev_dbg(&pdev->dev, "error mapping memory\n");
  146. retval = -ENOMEM;
  147. goto fail_ioremap;
  148. }
  149. ehci = (struct spear_ehci *)hcd_to_ehci(hcd);
  150. ehci->clk = usbh_clk;
  151. spear_start_ehci(ehci);
  152. retval = usb_add_hcd(hcd, irq, IRQF_SHARED);
  153. if (retval)
  154. goto fail_add_hcd;
  155. return retval;
  156. fail_add_hcd:
  157. spear_stop_ehci(ehci);
  158. iounmap(hcd->regs);
  159. fail_ioremap:
  160. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  161. fail_request_resource:
  162. usb_put_hcd(hcd);
  163. fail_create_hcd:
  164. clk_put(usbh_clk);
  165. fail_get_usbh_clk:
  166. fail_irq_get:
  167. dev_err(&pdev->dev, "init fail, %d\n", retval);
  168. return retval ;
  169. }
  170. static int spear_ehci_hcd_drv_remove(struct platform_device *pdev)
  171. {
  172. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  173. struct spear_ehci *ehci_p = to_spear_ehci(hcd);
  174. if (!hcd)
  175. return 0;
  176. if (in_interrupt())
  177. BUG();
  178. usb_remove_hcd(hcd);
  179. if (ehci_p->clk)
  180. spear_stop_ehci(ehci_p);
  181. iounmap(hcd->regs);
  182. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  183. usb_put_hcd(hcd);
  184. if (ehci_p->clk)
  185. clk_put(ehci_p->clk);
  186. return 0;
  187. }
  188. static struct of_device_id spear_ehci_id_table[] __devinitdata = {
  189. { .compatible = "st,spear600-ehci", },
  190. { },
  191. };
  192. static struct platform_driver spear_ehci_hcd_driver = {
  193. .probe = spear_ehci_hcd_drv_probe,
  194. .remove = spear_ehci_hcd_drv_remove,
  195. .shutdown = usb_hcd_platform_shutdown,
  196. .driver = {
  197. .name = "spear-ehci",
  198. .bus = &platform_bus_type,
  199. .pm = &ehci_spear_pm_ops,
  200. .of_match_table = of_match_ptr(spear_ehci_id_table),
  201. }
  202. };
  203. MODULE_ALIAS("platform:spear-ehci");