ehci-xilinx-of.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * EHCI HCD (Host Controller Driver) for USB.
  4. *
  5. * Bus Glue for Xilinx EHCI core on the of_platform bus
  6. *
  7. * Copyright (c) 2009 Xilinx, Inc.
  8. *
  9. * Based on "ehci-ppc-of.c" by Valentine Barshak <vbarshak@ru.mvista.com>
  10. * and "ehci-ppc-soc.c" by Stefan Roese <sr@denx.de>
  11. * and "ohci-ppc-of.c" by Sylvain Munaut <tnt@246tNt.com>
  12. */
  13. #include <linux/err.h>
  14. #include <linux/signal.h>
  15. #include <linux/of.h>
  16. #include <linux/of_platform.h>
  17. #include <linux/of_address.h>
  18. #include <linux/of_irq.h>
  19. /**
  20. * ehci_xilinx_port_handed_over - hand the port out if failed to enable it
  21. * @hcd: Pointer to the usb_hcd device to which the host controller bound
  22. * @portnum:Port number to which the device is attached.
  23. *
  24. * This function is used as a place to tell the user that the Xilinx USB host
  25. * controller does support LS devices. And in an HS only configuration, it
  26. * does not support FS devices either. It is hoped that this can help a
  27. * confused user.
  28. *
  29. * There are cases when the host controller fails to enable the port due to,
  30. * for example, insufficient power that can be supplied to the device from
  31. * the USB bus. In those cases, the messages printed here are not helpful.
  32. */
  33. static int ehci_xilinx_port_handed_over(struct usb_hcd *hcd, int portnum)
  34. {
  35. dev_warn(hcd->self.controller, "port %d cannot be enabled\n", portnum);
  36. if (hcd->has_tt) {
  37. dev_warn(hcd->self.controller,
  38. "Maybe you have connected a low speed device?\n");
  39. dev_warn(hcd->self.controller,
  40. "We do not support low speed devices\n");
  41. } else {
  42. dev_warn(hcd->self.controller,
  43. "Maybe your device is not a high speed device?\n");
  44. dev_warn(hcd->self.controller,
  45. "The USB host controller does not support full speed "
  46. "nor low speed devices\n");
  47. dev_warn(hcd->self.controller,
  48. "You can reconfigure the host controller to have "
  49. "full speed support\n");
  50. }
  51. return 0;
  52. }
  53. static const struct hc_driver ehci_xilinx_of_hc_driver = {
  54. .description = hcd_name,
  55. .product_desc = "OF EHCI",
  56. .hcd_priv_size = sizeof(struct ehci_hcd),
  57. /*
  58. * generic hardware linkage
  59. */
  60. .irq = ehci_irq,
  61. .flags = HCD_MEMORY | HCD_USB2 | HCD_BH,
  62. /*
  63. * basic lifecycle operations
  64. */
  65. .reset = ehci_setup,
  66. .start = ehci_run,
  67. .stop = ehci_stop,
  68. .shutdown = ehci_shutdown,
  69. /*
  70. * managing i/o requests and associated device resources
  71. */
  72. .urb_enqueue = ehci_urb_enqueue,
  73. .urb_dequeue = ehci_urb_dequeue,
  74. .endpoint_disable = ehci_endpoint_disable,
  75. .endpoint_reset = ehci_endpoint_reset,
  76. /*
  77. * scheduling support
  78. */
  79. .get_frame_number = ehci_get_frame,
  80. /*
  81. * root hub support
  82. */
  83. .hub_status_data = ehci_hub_status_data,
  84. .hub_control = ehci_hub_control,
  85. #ifdef CONFIG_PM
  86. .bus_suspend = ehci_bus_suspend,
  87. .bus_resume = ehci_bus_resume,
  88. #endif
  89. .relinquish_port = NULL,
  90. .port_handed_over = ehci_xilinx_port_handed_over,
  91. .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
  92. };
  93. /**
  94. * ehci_hcd_xilinx_of_probe - Probe method for the USB host controller
  95. * @op: pointer to the platform_device bound to the host controller
  96. *
  97. * This function requests resources and sets up appropriate properties for the
  98. * host controller. Because the Xilinx USB host controller can be configured
  99. * as HS only or HS/FS only, it checks the configuration in the device tree
  100. * entry, and sets an appropriate value for hcd->has_tt.
  101. */
  102. static int ehci_hcd_xilinx_of_probe(struct platform_device *op)
  103. {
  104. struct device_node *dn = op->dev.of_node;
  105. struct usb_hcd *hcd;
  106. struct ehci_hcd *ehci;
  107. struct resource res;
  108. int irq;
  109. int rv;
  110. int *value;
  111. if (usb_disabled())
  112. return -ENODEV;
  113. dev_dbg(&op->dev, "initializing XILINX-OF USB Controller\n");
  114. rv = of_address_to_resource(dn, 0, &res);
  115. if (rv)
  116. return rv;
  117. hcd = usb_create_hcd(&ehci_xilinx_of_hc_driver, &op->dev,
  118. "XILINX-OF USB");
  119. if (!hcd)
  120. return -ENOMEM;
  121. hcd->rsrc_start = res.start;
  122. hcd->rsrc_len = resource_size(&res);
  123. irq = irq_of_parse_and_map(dn, 0);
  124. if (!irq) {
  125. dev_err(&op->dev, "%s: irq_of_parse_and_map failed\n",
  126. __FILE__);
  127. rv = -EBUSY;
  128. goto err_irq;
  129. }
  130. hcd->regs = devm_ioremap_resource(&op->dev, &res);
  131. if (IS_ERR(hcd->regs)) {
  132. rv = PTR_ERR(hcd->regs);
  133. goto err_irq;
  134. }
  135. ehci = hcd_to_ehci(hcd);
  136. /* This core always has big-endian register interface and uses
  137. * big-endian memory descriptors.
  138. */
  139. ehci->big_endian_mmio = 1;
  140. ehci->big_endian_desc = 1;
  141. /* Check whether the FS support option is selected in the hardware.
  142. */
  143. value = (int *)of_get_property(dn, "xlnx,support-usb-fs", NULL);
  144. if (value && (*value == 1)) {
  145. ehci_dbg(ehci, "USB host controller supports FS devices\n");
  146. hcd->has_tt = 1;
  147. } else {
  148. ehci_dbg(ehci,
  149. "USB host controller is HS only\n");
  150. hcd->has_tt = 0;
  151. }
  152. /* Debug registers are at the first 0x100 region
  153. */
  154. ehci->caps = hcd->regs + 0x100;
  155. rv = usb_add_hcd(hcd, irq, 0);
  156. if (rv == 0) {
  157. device_wakeup_enable(hcd->self.controller);
  158. return 0;
  159. }
  160. err_irq:
  161. usb_put_hcd(hcd);
  162. return rv;
  163. }
  164. /**
  165. * ehci_hcd_xilinx_of_remove - shutdown hcd and release resources
  166. * @op: pointer to platform_device structure that is to be removed
  167. *
  168. * Remove the hcd structure, and release resources that has been requested
  169. * during probe.
  170. */
  171. static int ehci_hcd_xilinx_of_remove(struct platform_device *op)
  172. {
  173. struct usb_hcd *hcd = platform_get_drvdata(op);
  174. dev_dbg(&op->dev, "stopping XILINX-OF USB Controller\n");
  175. usb_remove_hcd(hcd);
  176. usb_put_hcd(hcd);
  177. return 0;
  178. }
  179. static const struct of_device_id ehci_hcd_xilinx_of_match[] = {
  180. {.compatible = "xlnx,xps-usb-host-1.00.a",},
  181. {},
  182. };
  183. MODULE_DEVICE_TABLE(of, ehci_hcd_xilinx_of_match);
  184. static struct platform_driver ehci_hcd_xilinx_of_driver = {
  185. .probe = ehci_hcd_xilinx_of_probe,
  186. .remove = ehci_hcd_xilinx_of_remove,
  187. .shutdown = usb_hcd_platform_shutdown,
  188. .driver = {
  189. .name = "xilinx-of-ehci",
  190. .of_match_table = ehci_hcd_xilinx_of_match,
  191. },
  192. };