ehci-atmel.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. /*
  2. * Driver for EHCI UHP on Atmel chips
  3. *
  4. * Copyright (C) 2009 Atmel Corporation,
  5. * Nicolas Ferre <nicolas.ferre@atmel.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/platform_device.h>
  15. /* interface and function clocks */
  16. static struct clk *iclk, *fclk;
  17. static int clocked;
  18. /*-------------------------------------------------------------------------*/
  19. static void atmel_start_clock(void)
  20. {
  21. clk_enable(iclk);
  22. clk_enable(fclk);
  23. clocked = 1;
  24. }
  25. static void atmel_stop_clock(void)
  26. {
  27. clk_disable(fclk);
  28. clk_disable(iclk);
  29. clocked = 0;
  30. }
  31. static void atmel_start_ehci(struct platform_device *pdev)
  32. {
  33. dev_dbg(&pdev->dev, "start\n");
  34. atmel_start_clock();
  35. }
  36. static void atmel_stop_ehci(struct platform_device *pdev)
  37. {
  38. dev_dbg(&pdev->dev, "stop\n");
  39. atmel_stop_clock();
  40. }
  41. /*-------------------------------------------------------------------------*/
  42. static int ehci_atmel_setup(struct usb_hcd *hcd)
  43. {
  44. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  45. int retval = 0;
  46. /* registers start at offset 0x0 */
  47. ehci->caps = hcd->regs;
  48. ehci->regs = hcd->regs +
  49. HC_LENGTH(ehci_readl(ehci, &ehci->caps->hc_capbase));
  50. dbg_hcs_params(ehci, "reset");
  51. dbg_hcc_params(ehci, "reset");
  52. /* cache this readonly data; minimize chip reads */
  53. ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
  54. retval = ehci_halt(ehci);
  55. if (retval)
  56. return retval;
  57. /* data structure init */
  58. retval = ehci_init(hcd);
  59. if (retval)
  60. return retval;
  61. ehci->sbrn = 0x20;
  62. ehci_reset(ehci);
  63. ehci_port_power(ehci, 0);
  64. return retval;
  65. }
  66. static const struct hc_driver ehci_atmel_hc_driver = {
  67. .description = hcd_name,
  68. .product_desc = "Atmel EHCI UHP HS",
  69. .hcd_priv_size = sizeof(struct ehci_hcd),
  70. /* generic hardware linkage */
  71. .irq = ehci_irq,
  72. .flags = HCD_MEMORY | HCD_USB2,
  73. /* basic lifecycle operations */
  74. .reset = ehci_atmel_setup,
  75. .start = ehci_run,
  76. .stop = ehci_stop,
  77. .shutdown = ehci_shutdown,
  78. /* managing i/o requests and associated device resources */
  79. .urb_enqueue = ehci_urb_enqueue,
  80. .urb_dequeue = ehci_urb_dequeue,
  81. .endpoint_disable = ehci_endpoint_disable,
  82. /* scheduling support */
  83. .get_frame_number = ehci_get_frame,
  84. /* root hub support */
  85. .hub_status_data = ehci_hub_status_data,
  86. .hub_control = ehci_hub_control,
  87. .bus_suspend = ehci_bus_suspend,
  88. .bus_resume = ehci_bus_resume,
  89. .relinquish_port = ehci_relinquish_port,
  90. .port_handed_over = ehci_port_handed_over,
  91. };
  92. static int __init ehci_atmel_drv_probe(struct platform_device *pdev)
  93. {
  94. struct usb_hcd *hcd;
  95. const struct hc_driver *driver = &ehci_atmel_hc_driver;
  96. struct resource *res;
  97. int irq;
  98. int retval;
  99. if (usb_disabled())
  100. return -ENODEV;
  101. pr_debug("Initializing Atmel-SoC USB Host Controller\n");
  102. irq = platform_get_irq(pdev, 0);
  103. if (irq <= 0) {
  104. dev_err(&pdev->dev,
  105. "Found HC with no IRQ. Check %s setup!\n",
  106. dev_name(&pdev->dev));
  107. retval = -ENODEV;
  108. goto fail_create_hcd;
  109. }
  110. hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev));
  111. if (!hcd) {
  112. retval = -ENOMEM;
  113. goto fail_create_hcd;
  114. }
  115. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  116. if (!res) {
  117. dev_err(&pdev->dev,
  118. "Found HC with no register addr. Check %s setup!\n",
  119. dev_name(&pdev->dev));
  120. retval = -ENODEV;
  121. goto fail_request_resource;
  122. }
  123. hcd->rsrc_start = res->start;
  124. hcd->rsrc_len = res->end - res->start + 1;
  125. if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len,
  126. driver->description)) {
  127. dev_dbg(&pdev->dev, "controller already in use\n");
  128. retval = -EBUSY;
  129. goto fail_request_resource;
  130. }
  131. hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len);
  132. if (hcd->regs == NULL) {
  133. dev_dbg(&pdev->dev, "error mapping memory\n");
  134. retval = -EFAULT;
  135. goto fail_ioremap;
  136. }
  137. iclk = clk_get(&pdev->dev, "ehci_clk");
  138. if (IS_ERR(iclk)) {
  139. dev_err(&pdev->dev, "Error getting interface clock\n");
  140. retval = -ENOENT;
  141. goto fail_get_iclk;
  142. }
  143. fclk = clk_get(&pdev->dev, "uhpck");
  144. if (IS_ERR(fclk)) {
  145. dev_err(&pdev->dev, "Error getting function clock\n");
  146. retval = -ENOENT;
  147. goto fail_get_fclk;
  148. }
  149. atmel_start_ehci(pdev);
  150. retval = usb_add_hcd(hcd, irq, IRQF_SHARED);
  151. if (retval)
  152. goto fail_add_hcd;
  153. return retval;
  154. fail_add_hcd:
  155. atmel_stop_ehci(pdev);
  156. clk_put(fclk);
  157. fail_get_fclk:
  158. clk_put(iclk);
  159. fail_get_iclk:
  160. iounmap(hcd->regs);
  161. fail_ioremap:
  162. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  163. fail_request_resource:
  164. usb_put_hcd(hcd);
  165. fail_create_hcd:
  166. dev_err(&pdev->dev, "init %s fail, %d\n",
  167. dev_name(&pdev->dev), retval);
  168. return retval;
  169. }
  170. static int __exit ehci_atmel_drv_remove(struct platform_device *pdev)
  171. {
  172. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  173. ehci_shutdown(hcd);
  174. usb_remove_hcd(hcd);
  175. iounmap(hcd->regs);
  176. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  177. usb_put_hcd(hcd);
  178. atmel_stop_ehci(pdev);
  179. clk_put(fclk);
  180. clk_put(iclk);
  181. fclk = iclk = NULL;
  182. return 0;
  183. }
  184. static struct platform_driver ehci_atmel_driver = {
  185. .probe = ehci_atmel_drv_probe,
  186. .remove = __exit_p(ehci_atmel_drv_remove),
  187. .shutdown = usb_hcd_platform_shutdown,
  188. .driver.name = "atmel-ehci",
  189. };