ehci-atmel.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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, 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. .endpoint_reset = ehci_endpoint_reset,
  83. /* scheduling support */
  84. .get_frame_number = ehci_get_frame,
  85. /* root hub support */
  86. .hub_status_data = ehci_hub_status_data,
  87. .hub_control = ehci_hub_control,
  88. .bus_suspend = ehci_bus_suspend,
  89. .bus_resume = ehci_bus_resume,
  90. .relinquish_port = ehci_relinquish_port,
  91. .port_handed_over = ehci_port_handed_over,
  92. .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
  93. };
  94. static int __devinit ehci_atmel_drv_probe(struct platform_device *pdev)
  95. {
  96. struct usb_hcd *hcd;
  97. const struct hc_driver *driver = &ehci_atmel_hc_driver;
  98. struct resource *res;
  99. int irq;
  100. int retval;
  101. if (usb_disabled())
  102. return -ENODEV;
  103. pr_debug("Initializing Atmel-SoC USB Host Controller\n");
  104. irq = platform_get_irq(pdev, 0);
  105. if (irq <= 0) {
  106. dev_err(&pdev->dev,
  107. "Found HC with no IRQ. Check %s setup!\n",
  108. dev_name(&pdev->dev));
  109. retval = -ENODEV;
  110. goto fail_create_hcd;
  111. }
  112. hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev));
  113. if (!hcd) {
  114. retval = -ENOMEM;
  115. goto fail_create_hcd;
  116. }
  117. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  118. if (!res) {
  119. dev_err(&pdev->dev,
  120. "Found HC with no register addr. Check %s setup!\n",
  121. dev_name(&pdev->dev));
  122. retval = -ENODEV;
  123. goto fail_request_resource;
  124. }
  125. hcd->rsrc_start = res->start;
  126. hcd->rsrc_len = resource_size(res);
  127. if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len,
  128. driver->description)) {
  129. dev_dbg(&pdev->dev, "controller already in use\n");
  130. retval = -EBUSY;
  131. goto fail_request_resource;
  132. }
  133. hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len);
  134. if (hcd->regs == NULL) {
  135. dev_dbg(&pdev->dev, "error mapping memory\n");
  136. retval = -EFAULT;
  137. goto fail_ioremap;
  138. }
  139. iclk = clk_get(&pdev->dev, "ehci_clk");
  140. if (IS_ERR(iclk)) {
  141. dev_err(&pdev->dev, "Error getting interface clock\n");
  142. retval = -ENOENT;
  143. goto fail_get_iclk;
  144. }
  145. fclk = clk_get(&pdev->dev, "uhpck");
  146. if (IS_ERR(fclk)) {
  147. dev_err(&pdev->dev, "Error getting function clock\n");
  148. retval = -ENOENT;
  149. goto fail_get_fclk;
  150. }
  151. atmel_start_ehci(pdev);
  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. atmel_stop_ehci(pdev);
  158. clk_put(fclk);
  159. fail_get_fclk:
  160. clk_put(iclk);
  161. fail_get_iclk:
  162. iounmap(hcd->regs);
  163. fail_ioremap:
  164. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  165. fail_request_resource:
  166. usb_put_hcd(hcd);
  167. fail_create_hcd:
  168. dev_err(&pdev->dev, "init %s fail, %d\n",
  169. dev_name(&pdev->dev), retval);
  170. return retval;
  171. }
  172. static int __devexit ehci_atmel_drv_remove(struct platform_device *pdev)
  173. {
  174. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  175. ehci_shutdown(hcd);
  176. usb_remove_hcd(hcd);
  177. iounmap(hcd->regs);
  178. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  179. usb_put_hcd(hcd);
  180. atmel_stop_ehci(pdev);
  181. clk_put(fclk);
  182. clk_put(iclk);
  183. fclk = iclk = NULL;
  184. return 0;
  185. }
  186. static struct platform_driver ehci_atmel_driver = {
  187. .probe = ehci_atmel_drv_probe,
  188. .remove = __devexit_p(ehci_atmel_drv_remove),
  189. .shutdown = usb_hcd_platform_shutdown,
  190. .driver.name = "atmel-ehci",
  191. };