ehci-atmel.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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. #include <linux/of.h>
  16. #include <linux/of_platform.h>
  17. /* interface and function clocks */
  18. static struct clk *iclk, *fclk;
  19. static int clocked;
  20. /*-------------------------------------------------------------------------*/
  21. static void atmel_start_clock(void)
  22. {
  23. clk_enable(iclk);
  24. clk_enable(fclk);
  25. clocked = 1;
  26. }
  27. static void atmel_stop_clock(void)
  28. {
  29. clk_disable(fclk);
  30. clk_disable(iclk);
  31. clocked = 0;
  32. }
  33. static void atmel_start_ehci(struct platform_device *pdev)
  34. {
  35. dev_dbg(&pdev->dev, "start\n");
  36. atmel_start_clock();
  37. }
  38. static void atmel_stop_ehci(struct platform_device *pdev)
  39. {
  40. dev_dbg(&pdev->dev, "stop\n");
  41. atmel_stop_clock();
  42. }
  43. /*-------------------------------------------------------------------------*/
  44. static int ehci_atmel_setup(struct usb_hcd *hcd)
  45. {
  46. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  47. int retval;
  48. /* registers start at offset 0x0 */
  49. ehci->caps = hcd->regs;
  50. retval = ehci_setup(hcd);
  51. if (retval)
  52. return retval;
  53. ehci_port_power(ehci, 0);
  54. return retval;
  55. }
  56. static const struct hc_driver ehci_atmel_hc_driver = {
  57. .description = hcd_name,
  58. .product_desc = "Atmel EHCI UHP HS",
  59. .hcd_priv_size = sizeof(struct ehci_hcd),
  60. /* generic hardware linkage */
  61. .irq = ehci_irq,
  62. .flags = HCD_MEMORY | HCD_USB2,
  63. /* basic lifecycle operations */
  64. .reset = ehci_atmel_setup,
  65. .start = ehci_run,
  66. .stop = ehci_stop,
  67. .shutdown = ehci_shutdown,
  68. /* managing i/o requests and associated device resources */
  69. .urb_enqueue = ehci_urb_enqueue,
  70. .urb_dequeue = ehci_urb_dequeue,
  71. .endpoint_disable = ehci_endpoint_disable,
  72. .endpoint_reset = ehci_endpoint_reset,
  73. /* scheduling support */
  74. .get_frame_number = ehci_get_frame,
  75. /* root hub support */
  76. .hub_status_data = ehci_hub_status_data,
  77. .hub_control = ehci_hub_control,
  78. .bus_suspend = ehci_bus_suspend,
  79. .bus_resume = ehci_bus_resume,
  80. .relinquish_port = ehci_relinquish_port,
  81. .port_handed_over = ehci_port_handed_over,
  82. .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
  83. };
  84. static u64 at91_ehci_dma_mask = DMA_BIT_MASK(32);
  85. static int __devinit ehci_atmel_drv_probe(struct platform_device *pdev)
  86. {
  87. struct usb_hcd *hcd;
  88. const struct hc_driver *driver = &ehci_atmel_hc_driver;
  89. struct resource *res;
  90. int irq;
  91. int retval;
  92. if (usb_disabled())
  93. return -ENODEV;
  94. pr_debug("Initializing Atmel-SoC USB Host Controller\n");
  95. irq = platform_get_irq(pdev, 0);
  96. if (irq <= 0) {
  97. dev_err(&pdev->dev,
  98. "Found HC with no IRQ. Check %s setup!\n",
  99. dev_name(&pdev->dev));
  100. retval = -ENODEV;
  101. goto fail_create_hcd;
  102. }
  103. /* Right now device-tree probed devices don't get dma_mask set.
  104. * Since shared usb code relies on it, set it here for now.
  105. * Once we have dma capability bindings this can go away.
  106. */
  107. if (!pdev->dev.dma_mask)
  108. pdev->dev.dma_mask = &at91_ehci_dma_mask;
  109. hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev));
  110. if (!hcd) {
  111. retval = -ENOMEM;
  112. goto fail_create_hcd;
  113. }
  114. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  115. if (!res) {
  116. dev_err(&pdev->dev,
  117. "Found HC with no register addr. Check %s setup!\n",
  118. dev_name(&pdev->dev));
  119. retval = -ENODEV;
  120. goto fail_request_resource;
  121. }
  122. hcd->rsrc_start = res->start;
  123. hcd->rsrc_len = resource_size(res);
  124. hcd->regs = devm_request_and_ioremap(&pdev->dev, res);
  125. if (hcd->regs == NULL) {
  126. dev_dbg(&pdev->dev, "error mapping memory\n");
  127. retval = -EFAULT;
  128. goto fail_request_resource;
  129. }
  130. iclk = devm_clk_get(&pdev->dev, "ehci_clk");
  131. if (IS_ERR(iclk)) {
  132. dev_err(&pdev->dev, "Error getting interface clock\n");
  133. retval = -ENOENT;
  134. goto fail_request_resource;
  135. }
  136. fclk = devm_clk_get(&pdev->dev, "uhpck");
  137. if (IS_ERR(fclk)) {
  138. dev_err(&pdev->dev, "Error getting function clock\n");
  139. retval = -ENOENT;
  140. goto fail_request_resource;
  141. }
  142. atmel_start_ehci(pdev);
  143. retval = usb_add_hcd(hcd, irq, IRQF_SHARED);
  144. if (retval)
  145. goto fail_add_hcd;
  146. return retval;
  147. fail_add_hcd:
  148. atmel_stop_ehci(pdev);
  149. fail_request_resource:
  150. usb_put_hcd(hcd);
  151. fail_create_hcd:
  152. dev_err(&pdev->dev, "init %s fail, %d\n",
  153. dev_name(&pdev->dev), retval);
  154. return retval;
  155. }
  156. static int __devexit ehci_atmel_drv_remove(struct platform_device *pdev)
  157. {
  158. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  159. ehci_shutdown(hcd);
  160. usb_remove_hcd(hcd);
  161. usb_put_hcd(hcd);
  162. atmel_stop_ehci(pdev);
  163. fclk = iclk = NULL;
  164. return 0;
  165. }
  166. #ifdef CONFIG_OF
  167. static const struct of_device_id atmel_ehci_dt_ids[] = {
  168. { .compatible = "atmel,at91sam9g45-ehci" },
  169. { /* sentinel */ }
  170. };
  171. MODULE_DEVICE_TABLE(of, atmel_ehci_dt_ids);
  172. #endif
  173. static struct platform_driver ehci_atmel_driver = {
  174. .probe = ehci_atmel_drv_probe,
  175. .remove = __devexit_p(ehci_atmel_drv_remove),
  176. .shutdown = usb_hcd_platform_shutdown,
  177. .driver = {
  178. .name = "atmel-ehci",
  179. .of_match_table = of_match_ptr(atmel_ehci_dt_ids),
  180. },
  181. };