ehci-tilegx.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. /*
  2. * Copyright 2012 Tilera Corporation. All Rights Reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation, version 2.
  7. *
  8. * This program is distributed in the hope that it will be useful, but
  9. * WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
  11. * NON INFRINGEMENT. See the GNU General Public License for
  12. * more details.
  13. */
  14. /*
  15. * Tilera TILE-Gx USB EHCI host controller driver.
  16. */
  17. #include <linux/irq.h>
  18. #include <linux/platform_device.h>
  19. #include <linux/usb/tilegx.h>
  20. #include <linux/usb.h>
  21. #include <asm/homecache.h>
  22. #include <gxio/iorpc_usb_host.h>
  23. #include <gxio/usb_host.h>
  24. static void tilegx_start_ehc(void)
  25. {
  26. }
  27. static void tilegx_stop_ehc(void)
  28. {
  29. }
  30. static int tilegx_ehci_setup(struct usb_hcd *hcd)
  31. {
  32. int ret = ehci_init(hcd);
  33. /*
  34. * Some drivers do:
  35. *
  36. * struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  37. * ehci->need_io_watchdog = 0;
  38. *
  39. * here, but since this is a new driver we're going to leave the
  40. * watchdog enabled. Later we may try to turn it off and see
  41. * whether we run into any problems.
  42. */
  43. return ret;
  44. }
  45. static const struct hc_driver ehci_tilegx_hc_driver = {
  46. .description = hcd_name,
  47. .product_desc = "Tile-Gx EHCI",
  48. .hcd_priv_size = sizeof(struct ehci_hcd),
  49. /*
  50. * Generic hardware linkage.
  51. */
  52. .irq = ehci_irq,
  53. .flags = HCD_MEMORY | HCD_USB2 | HCD_BH,
  54. /*
  55. * Basic lifecycle operations.
  56. */
  57. .reset = tilegx_ehci_setup,
  58. .start = ehci_run,
  59. .stop = ehci_stop,
  60. .shutdown = ehci_shutdown,
  61. /*
  62. * Managing I/O requests and associated device resources.
  63. */
  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. /*
  69. * Scheduling support.
  70. */
  71. .get_frame_number = ehci_get_frame,
  72. /*
  73. * Root hub support.
  74. */
  75. .hub_status_data = ehci_hub_status_data,
  76. .hub_control = ehci_hub_control,
  77. .bus_suspend = ehci_bus_suspend,
  78. .bus_resume = ehci_bus_resume,
  79. .relinquish_port = ehci_relinquish_port,
  80. .port_handed_over = ehci_port_handed_over,
  81. .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
  82. };
  83. static int ehci_hcd_tilegx_drv_probe(struct platform_device *pdev)
  84. {
  85. struct usb_hcd *hcd;
  86. struct ehci_hcd *ehci;
  87. struct tilegx_usb_platform_data *pdata = dev_get_platdata(&pdev->dev);
  88. pte_t pte = { 0 };
  89. int my_cpu = smp_processor_id();
  90. int ret;
  91. if (usb_disabled())
  92. return -ENODEV;
  93. /*
  94. * Try to initialize our GXIO context; if we can't, the device
  95. * doesn't exist.
  96. */
  97. if (gxio_usb_host_init(&pdata->usb_ctx, pdata->dev_index, 1) != 0)
  98. return -ENXIO;
  99. hcd = usb_create_hcd(&ehci_tilegx_hc_driver, &pdev->dev,
  100. dev_name(&pdev->dev));
  101. if (!hcd) {
  102. ret = -ENOMEM;
  103. goto err_hcd;
  104. }
  105. /*
  106. * We don't use rsrc_start to map in our registers, but seems like
  107. * we ought to set it to something, so we use the register VA.
  108. */
  109. hcd->rsrc_start =
  110. (ulong) gxio_usb_host_get_reg_start(&pdata->usb_ctx);
  111. hcd->rsrc_len = gxio_usb_host_get_reg_len(&pdata->usb_ctx);
  112. hcd->regs = gxio_usb_host_get_reg_start(&pdata->usb_ctx);
  113. tilegx_start_ehc();
  114. ehci = hcd_to_ehci(hcd);
  115. ehci->caps = hcd->regs;
  116. ehci->regs =
  117. hcd->regs + HC_LENGTH(ehci, readl(&ehci->caps->hc_capbase));
  118. /* cache this readonly data; minimize chip reads */
  119. ehci->hcs_params = readl(&ehci->caps->hcs_params);
  120. /* Create our IRQs and register them. */
  121. pdata->irq = irq_alloc_hwirq(-1);
  122. if (!pdata->irq) {
  123. ret = -ENXIO;
  124. goto err_no_irq;
  125. }
  126. tile_irq_activate(pdata->irq, TILE_IRQ_PERCPU);
  127. /* Configure interrupts. */
  128. ret = gxio_usb_host_cfg_interrupt(&pdata->usb_ctx,
  129. cpu_x(my_cpu), cpu_y(my_cpu),
  130. KERNEL_PL, pdata->irq);
  131. if (ret) {
  132. ret = -ENXIO;
  133. goto err_have_irq;
  134. }
  135. /* Register all of our memory. */
  136. pte = pte_set_home(pte, PAGE_HOME_HASH);
  137. ret = gxio_usb_host_register_client_memory(&pdata->usb_ctx, pte, 0);
  138. if (ret) {
  139. ret = -ENXIO;
  140. goto err_have_irq;
  141. }
  142. ret = usb_add_hcd(hcd, pdata->irq, IRQF_SHARED);
  143. if (ret == 0) {
  144. platform_set_drvdata(pdev, hcd);
  145. device_wakeup_enable(hcd->self.controller);
  146. return ret;
  147. }
  148. err_have_irq:
  149. irq_free_hwirq(pdata->irq);
  150. err_no_irq:
  151. tilegx_stop_ehc();
  152. usb_put_hcd(hcd);
  153. err_hcd:
  154. gxio_usb_host_destroy(&pdata->usb_ctx);
  155. return ret;
  156. }
  157. static int ehci_hcd_tilegx_drv_remove(struct platform_device *pdev)
  158. {
  159. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  160. struct tilegx_usb_platform_data *pdata = dev_get_platdata(&pdev->dev);
  161. usb_remove_hcd(hcd);
  162. usb_put_hcd(hcd);
  163. tilegx_stop_ehc();
  164. gxio_usb_host_destroy(&pdata->usb_ctx);
  165. irq_free_hwirq(pdata->irq);
  166. return 0;
  167. }
  168. static void ehci_hcd_tilegx_drv_shutdown(struct platform_device *pdev)
  169. {
  170. usb_hcd_platform_shutdown(pdev);
  171. ehci_hcd_tilegx_drv_remove(pdev);
  172. }
  173. static struct platform_driver ehci_hcd_tilegx_driver = {
  174. .probe = ehci_hcd_tilegx_drv_probe,
  175. .remove = ehci_hcd_tilegx_drv_remove,
  176. .shutdown = ehci_hcd_tilegx_drv_shutdown,
  177. .driver = {
  178. .name = "tilegx-ehci",
  179. }
  180. };
  181. MODULE_ALIAS("platform:tilegx-ehci");