ohci-tilegx.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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 OHCI 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_ohc(void)
  25. {
  26. }
  27. static void tilegx_stop_ohc(void)
  28. {
  29. }
  30. static int tilegx_ohci_start(struct usb_hcd *hcd)
  31. {
  32. struct ohci_hcd *ohci = hcd_to_ohci(hcd);
  33. int ret;
  34. ret = ohci_init(ohci);
  35. if (ret < 0)
  36. return ret;
  37. ret = ohci_run(ohci);
  38. if (ret < 0) {
  39. dev_err(hcd->self.controller, "can't start %s\n",
  40. hcd->self.bus_name);
  41. ohci_stop(hcd);
  42. return ret;
  43. }
  44. return 0;
  45. }
  46. static const struct hc_driver ohci_tilegx_hc_driver = {
  47. .description = hcd_name,
  48. .product_desc = "Tile-Gx OHCI",
  49. .hcd_priv_size = sizeof(struct ohci_hcd),
  50. /*
  51. * Generic hardware linkage.
  52. */
  53. .irq = ohci_irq,
  54. .flags = HCD_MEMORY | HCD_LOCAL_MEM | HCD_USB11,
  55. /*
  56. * Basic lifecycle operations.
  57. */
  58. .start = tilegx_ohci_start,
  59. .stop = ohci_stop,
  60. .shutdown = ohci_shutdown,
  61. /*
  62. * Managing I/O requests and associated device resources.
  63. */
  64. .urb_enqueue = ohci_urb_enqueue,
  65. .urb_dequeue = ohci_urb_dequeue,
  66. .endpoint_disable = ohci_endpoint_disable,
  67. /*
  68. * Scheduling support.
  69. */
  70. .get_frame_number = ohci_get_frame,
  71. /*
  72. * Root hub support.
  73. */
  74. .hub_status_data = ohci_hub_status_data,
  75. .hub_control = ohci_hub_control,
  76. .start_port_reset = ohci_start_port_reset,
  77. };
  78. static int ohci_hcd_tilegx_drv_probe(struct platform_device *pdev)
  79. {
  80. struct usb_hcd *hcd;
  81. struct tilegx_usb_platform_data *pdata = dev_get_platdata(&pdev->dev);
  82. pte_t pte = { 0 };
  83. int my_cpu = smp_processor_id();
  84. int ret;
  85. if (usb_disabled())
  86. return -ENODEV;
  87. /*
  88. * Try to initialize our GXIO context; if we can't, the device
  89. * doesn't exist.
  90. */
  91. if (gxio_usb_host_init(&pdata->usb_ctx, pdata->dev_index, 0) != 0)
  92. return -ENXIO;
  93. hcd = usb_create_hcd(&ohci_tilegx_hc_driver, &pdev->dev,
  94. dev_name(&pdev->dev));
  95. if (!hcd) {
  96. ret = -ENOMEM;
  97. goto err_hcd;
  98. }
  99. /*
  100. * We don't use rsrc_start to map in our registers, but seems like
  101. * we ought to set it to something, so we use the register VA.
  102. */
  103. hcd->rsrc_start =
  104. (ulong) gxio_usb_host_get_reg_start(&pdata->usb_ctx);
  105. hcd->rsrc_len = gxio_usb_host_get_reg_len(&pdata->usb_ctx);
  106. hcd->regs = gxio_usb_host_get_reg_start(&pdata->usb_ctx);
  107. tilegx_start_ohc();
  108. /* Create our IRQs and register them. */
  109. pdata->irq = irq_alloc_hwirq(-1);
  110. if (!pdata->irq) {
  111. ret = -ENXIO;
  112. goto err_no_irq;
  113. }
  114. tile_irq_activate(pdata->irq, TILE_IRQ_PERCPU);
  115. /* Configure interrupts. */
  116. ret = gxio_usb_host_cfg_interrupt(&pdata->usb_ctx,
  117. cpu_x(my_cpu), cpu_y(my_cpu),
  118. KERNEL_PL, pdata->irq);
  119. if (ret) {
  120. ret = -ENXIO;
  121. goto err_have_irq;
  122. }
  123. /* Register all of our memory. */
  124. pte = pte_set_home(pte, PAGE_HOME_HASH);
  125. ret = gxio_usb_host_register_client_memory(&pdata->usb_ctx, pte, 0);
  126. if (ret) {
  127. ret = -ENXIO;
  128. goto err_have_irq;
  129. }
  130. ohci_hcd_init(hcd_to_ohci(hcd));
  131. ret = usb_add_hcd(hcd, pdata->irq, IRQF_SHARED);
  132. if (ret == 0) {
  133. platform_set_drvdata(pdev, hcd);
  134. device_wakeup_enable(hcd->self.controller);
  135. return ret;
  136. }
  137. err_have_irq:
  138. irq_free_hwirq(pdata->irq);
  139. err_no_irq:
  140. tilegx_stop_ohc();
  141. usb_put_hcd(hcd);
  142. err_hcd:
  143. gxio_usb_host_destroy(&pdata->usb_ctx);
  144. return ret;
  145. }
  146. static int ohci_hcd_tilegx_drv_remove(struct platform_device *pdev)
  147. {
  148. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  149. struct tilegx_usb_platform_data *pdata = dev_get_platdata(&pdev->dev);
  150. usb_remove_hcd(hcd);
  151. usb_put_hcd(hcd);
  152. tilegx_stop_ohc();
  153. gxio_usb_host_destroy(&pdata->usb_ctx);
  154. irq_free_hwirq(pdata->irq);
  155. return 0;
  156. }
  157. static void ohci_hcd_tilegx_drv_shutdown(struct platform_device *pdev)
  158. {
  159. usb_hcd_platform_shutdown(pdev);
  160. ohci_hcd_tilegx_drv_remove(pdev);
  161. }
  162. static struct platform_driver ohci_hcd_tilegx_driver = {
  163. .probe = ohci_hcd_tilegx_drv_probe,
  164. .remove = ohci_hcd_tilegx_drv_remove,
  165. .shutdown = ohci_hcd_tilegx_drv_shutdown,
  166. .driver = {
  167. .name = "tilegx-ohci",
  168. }
  169. };
  170. MODULE_ALIAS("platform:tilegx-ohci");