ehci-tilegx.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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,
  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 = pdev->dev.platform_data;
  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. return -ENOMEM;
  103. /*
  104. * We don't use rsrc_start to map in our registers, but seems like
  105. * we ought to set it to something, so we use the register VA.
  106. */
  107. hcd->rsrc_start =
  108. (ulong) gxio_usb_host_get_reg_start(&pdata->usb_ctx);
  109. hcd->rsrc_len = gxio_usb_host_get_reg_len(&pdata->usb_ctx);
  110. hcd->regs = gxio_usb_host_get_reg_start(&pdata->usb_ctx);
  111. tilegx_start_ehc();
  112. ehci = hcd_to_ehci(hcd);
  113. ehci->caps = hcd->regs;
  114. ehci->regs =
  115. hcd->regs + HC_LENGTH(ehci, readl(&ehci->caps->hc_capbase));
  116. /* cache this readonly data; minimize chip reads */
  117. ehci->hcs_params = readl(&ehci->caps->hcs_params);
  118. /* Create our IRQs and register them. */
  119. pdata->irq = create_irq();
  120. if (pdata->irq < 0) {
  121. ret = -ENXIO;
  122. goto err_no_irq;
  123. }
  124. tile_irq_activate(pdata->irq, TILE_IRQ_PERCPU);
  125. /* Configure interrupts. */
  126. ret = gxio_usb_host_cfg_interrupt(&pdata->usb_ctx,
  127. cpu_x(my_cpu), cpu_y(my_cpu),
  128. KERNEL_PL, pdata->irq);
  129. if (ret) {
  130. ret = -ENXIO;
  131. goto err_have_irq;
  132. }
  133. /* Register all of our memory. */
  134. pte = pte_set_home(pte, PAGE_HOME_HASH);
  135. ret = gxio_usb_host_register_client_memory(&pdata->usb_ctx, pte, 0);
  136. if (ret) {
  137. ret = -ENXIO;
  138. goto err_have_irq;
  139. }
  140. ret = usb_add_hcd(hcd, pdata->irq, IRQF_SHARED);
  141. if (ret == 0) {
  142. platform_set_drvdata(pdev, hcd);
  143. return ret;
  144. }
  145. err_have_irq:
  146. destroy_irq(pdata->irq);
  147. err_no_irq:
  148. tilegx_stop_ehc();
  149. usb_put_hcd(hcd);
  150. gxio_usb_host_destroy(&pdata->usb_ctx);
  151. return ret;
  152. }
  153. static int ehci_hcd_tilegx_drv_remove(struct platform_device *pdev)
  154. {
  155. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  156. struct tilegx_usb_platform_data *pdata = pdev->dev.platform_data;
  157. usb_remove_hcd(hcd);
  158. usb_put_hcd(hcd);
  159. tilegx_stop_ehc();
  160. gxio_usb_host_destroy(&pdata->usb_ctx);
  161. destroy_irq(pdata->irq);
  162. platform_set_drvdata(pdev, NULL);
  163. return 0;
  164. }
  165. static void ehci_hcd_tilegx_drv_shutdown(struct platform_device *pdev)
  166. {
  167. usb_hcd_platform_shutdown(pdev);
  168. ehci_hcd_tilegx_drv_remove(pdev);
  169. }
  170. static struct platform_driver ehci_hcd_tilegx_driver = {
  171. .probe = ehci_hcd_tilegx_drv_probe,
  172. .remove = ehci_hcd_tilegx_drv_remove,
  173. .shutdown = ehci_hcd_tilegx_drv_shutdown,
  174. .driver = {
  175. .name = "tilegx-ehci",
  176. .owner = THIS_MODULE,
  177. }
  178. };
  179. MODULE_ALIAS("platform:tilegx-ehci");