ohci-tilegx.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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 = pdev->dev.platform_data;
  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. return -ENOMEM;
  97. /*
  98. * We don't use rsrc_start to map in our registers, but seems like
  99. * we ought to set it to something, so we use the register VA.
  100. */
  101. hcd->rsrc_start =
  102. (ulong) gxio_usb_host_get_reg_start(&pdata->usb_ctx);
  103. hcd->rsrc_len = gxio_usb_host_get_reg_len(&pdata->usb_ctx);
  104. hcd->regs = gxio_usb_host_get_reg_start(&pdata->usb_ctx);
  105. tilegx_start_ohc();
  106. /* Create our IRQs and register them. */
  107. pdata->irq = create_irq();
  108. if (pdata->irq < 0) {
  109. ret = -ENXIO;
  110. goto err_no_irq;
  111. }
  112. tile_irq_activate(pdata->irq, TILE_IRQ_PERCPU);
  113. /* Configure interrupts. */
  114. ret = gxio_usb_host_cfg_interrupt(&pdata->usb_ctx,
  115. cpu_x(my_cpu), cpu_y(my_cpu),
  116. KERNEL_PL, pdata->irq);
  117. if (ret) {
  118. ret = -ENXIO;
  119. goto err_have_irq;
  120. }
  121. /* Register all of our memory. */
  122. pte = pte_set_home(pte, PAGE_HOME_HASH);
  123. ret = gxio_usb_host_register_client_memory(&pdata->usb_ctx, pte, 0);
  124. if (ret) {
  125. ret = -ENXIO;
  126. goto err_have_irq;
  127. }
  128. ohci_hcd_init(hcd_to_ohci(hcd));
  129. ret = usb_add_hcd(hcd, pdata->irq, IRQF_SHARED);
  130. if (ret == 0) {
  131. platform_set_drvdata(pdev, hcd);
  132. return ret;
  133. }
  134. err_have_irq:
  135. destroy_irq(pdata->irq);
  136. err_no_irq:
  137. tilegx_stop_ohc();
  138. usb_put_hcd(hcd);
  139. gxio_usb_host_destroy(&pdata->usb_ctx);
  140. return ret;
  141. }
  142. static int ohci_hcd_tilegx_drv_remove(struct platform_device *pdev)
  143. {
  144. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  145. struct tilegx_usb_platform_data* pdata = pdev->dev.platform_data;
  146. usb_remove_hcd(hcd);
  147. usb_put_hcd(hcd);
  148. tilegx_stop_ohc();
  149. gxio_usb_host_destroy(&pdata->usb_ctx);
  150. destroy_irq(pdata->irq);
  151. platform_set_drvdata(pdev, NULL);
  152. return 0;
  153. }
  154. static void ohci_hcd_tilegx_drv_shutdown(struct platform_device *pdev)
  155. {
  156. usb_hcd_platform_shutdown(pdev);
  157. ohci_hcd_tilegx_drv_remove(pdev);
  158. }
  159. static struct platform_driver ohci_hcd_tilegx_driver = {
  160. .probe = ohci_hcd_tilegx_drv_probe,
  161. .remove = ohci_hcd_tilegx_drv_remove,
  162. .shutdown = ohci_hcd_tilegx_drv_shutdown,
  163. .driver = {
  164. .name = "tilegx-ohci",
  165. .owner = THIS_MODULE,
  166. }
  167. };
  168. MODULE_ALIAS("platform:tilegx-ohci");