ehci-atmel.c 4.9 KB

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