ehci-spear.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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/platform_device.h>
  14. #include <linux/clk.h>
  15. struct spear_ehci {
  16. struct ehci_hcd ehci;
  17. struct clk *clk;
  18. };
  19. #define to_spear_ehci(hcd) (struct spear_ehci *)hcd_to_ehci(hcd)
  20. static void spear_start_ehci(struct spear_ehci *ehci)
  21. {
  22. clk_enable(ehci->clk);
  23. }
  24. static void spear_stop_ehci(struct spear_ehci *ehci)
  25. {
  26. clk_disable(ehci->clk);
  27. }
  28. static int ehci_spear_setup(struct usb_hcd *hcd)
  29. {
  30. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  31. int retval = 0;
  32. /* registers start at offset 0x0 */
  33. ehci->caps = hcd->regs;
  34. ehci->regs = hcd->regs + HC_LENGTH(ehci, ehci_readl(ehci,
  35. &ehci->caps->hc_capbase));
  36. /* cache this readonly data; minimize chip reads */
  37. ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
  38. retval = ehci_halt(ehci);
  39. if (retval)
  40. return retval;
  41. retval = ehci_init(hcd);
  42. if (retval)
  43. return retval;
  44. ehci_reset(ehci);
  45. ehci_port_power(ehci, 0);
  46. return retval;
  47. }
  48. static const struct hc_driver ehci_spear_hc_driver = {
  49. .description = hcd_name,
  50. .product_desc = "SPEAr EHCI",
  51. .hcd_priv_size = sizeof(struct spear_ehci),
  52. /* generic hardware linkage */
  53. .irq = ehci_irq,
  54. .flags = HCD_MEMORY | HCD_USB2,
  55. /* basic lifecycle operations */
  56. .reset = ehci_spear_setup,
  57. .start = ehci_run,
  58. .stop = ehci_stop,
  59. .shutdown = ehci_shutdown,
  60. /* managing i/o requests and associated device resources */
  61. .urb_enqueue = ehci_urb_enqueue,
  62. .urb_dequeue = ehci_urb_dequeue,
  63. .endpoint_disable = ehci_endpoint_disable,
  64. .endpoint_reset = ehci_endpoint_reset,
  65. /* scheduling support */
  66. .get_frame_number = ehci_get_frame,
  67. /* root hub support */
  68. .hub_status_data = ehci_hub_status_data,
  69. .hub_control = ehci_hub_control,
  70. .bus_suspend = ehci_bus_suspend,
  71. .bus_resume = ehci_bus_resume,
  72. .relinquish_port = ehci_relinquish_port,
  73. .port_handed_over = ehci_port_handed_over,
  74. .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
  75. };
  76. static int spear_ehci_hcd_drv_probe(struct platform_device *pdev)
  77. {
  78. struct usb_hcd *hcd ;
  79. struct spear_ehci *ehci;
  80. struct resource *res;
  81. struct clk *usbh_clk;
  82. const struct hc_driver *driver = &ehci_spear_hc_driver;
  83. int *pdata = pdev->dev.platform_data;
  84. int irq, retval;
  85. char clk_name[20] = "usbh_clk";
  86. if (pdata == NULL)
  87. return -EFAULT;
  88. if (usb_disabled())
  89. return -ENODEV;
  90. irq = platform_get_irq(pdev, 0);
  91. if (irq < 0) {
  92. retval = irq;
  93. goto fail_irq_get;
  94. }
  95. if (*pdata >= 0)
  96. sprintf(clk_name, "usbh.%01d_clk", *pdata);
  97. usbh_clk = clk_get(NULL, clk_name);
  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_get_usbh_clk;
  102. }
  103. hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev));
  104. if (!hcd) {
  105. retval = -ENOMEM;
  106. goto fail_create_hcd;
  107. }
  108. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  109. if (!res) {
  110. retval = -ENODEV;
  111. goto fail_request_resource;
  112. }
  113. hcd->rsrc_start = res->start;
  114. hcd->rsrc_len = resource_size(res);
  115. if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len,
  116. driver->description)) {
  117. retval = -EBUSY;
  118. goto fail_request_resource;
  119. }
  120. hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
  121. if (hcd->regs == NULL) {
  122. dev_dbg(&pdev->dev, "error mapping memory\n");
  123. retval = -ENOMEM;
  124. goto fail_ioremap;
  125. }
  126. ehci = (struct spear_ehci *)hcd_to_ehci(hcd);
  127. ehci->clk = usbh_clk;
  128. spear_start_ehci(ehci);
  129. retval = usb_add_hcd(hcd, irq, IRQF_SHARED | IRQF_DISABLED);
  130. if (retval)
  131. goto fail_add_hcd;
  132. return retval;
  133. fail_add_hcd:
  134. spear_stop_ehci(ehci);
  135. iounmap(hcd->regs);
  136. fail_ioremap:
  137. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  138. fail_request_resource:
  139. usb_put_hcd(hcd);
  140. fail_create_hcd:
  141. clk_put(usbh_clk);
  142. fail_get_usbh_clk:
  143. fail_irq_get:
  144. dev_err(&pdev->dev, "init fail, %d\n", retval);
  145. return retval ;
  146. }
  147. static int spear_ehci_hcd_drv_remove(struct platform_device *pdev)
  148. {
  149. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  150. struct spear_ehci *ehci_p = to_spear_ehci(hcd);
  151. if (!hcd)
  152. return 0;
  153. if (in_interrupt())
  154. BUG();
  155. usb_remove_hcd(hcd);
  156. if (ehci_p->clk)
  157. spear_stop_ehci(ehci_p);
  158. iounmap(hcd->regs);
  159. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  160. usb_put_hcd(hcd);
  161. if (ehci_p->clk)
  162. clk_put(ehci_p->clk);
  163. return 0;
  164. }
  165. static struct platform_driver spear_ehci_hcd_driver = {
  166. .probe = spear_ehci_hcd_drv_probe,
  167. .remove = spear_ehci_hcd_drv_remove,
  168. .shutdown = usb_hcd_platform_shutdown,
  169. .driver = {
  170. .name = "spear-ehci",
  171. .bus = &platform_bus_type
  172. }
  173. };
  174. MODULE_ALIAS("platform:spear-ehci");