ehci-xilinx-of.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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 <[email protected]>
  10. * and "ehci-ppc-soc.c" by Stefan Roese <[email protected]>
  11. * and "ohci-ppc-of.c" by Sylvain Munaut <[email protected]>
  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. * Return: Always return 0
  34. */
  35. static int ehci_xilinx_port_handed_over(struct usb_hcd *hcd, int portnum)
  36. {
  37. dev_warn(hcd->self.controller, "port %d cannot be enabled\n", portnum);
  38. if (hcd->has_tt) {
  39. dev_warn(hcd->self.controller,
  40. "Maybe you have connected a low speed device?\n");
  41. dev_warn(hcd->self.controller,
  42. "We do not support low speed devices\n");
  43. } else {
  44. dev_warn(hcd->self.controller,
  45. "Maybe your device is not a high speed device?\n");
  46. dev_warn(hcd->self.controller,
  47. "The USB host controller does not support full speed nor low speed devices\n");
  48. dev_warn(hcd->self.controller,
  49. "You can reconfigure the host controller to have 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_DMA | 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. * Return: zero on success, negative error code otherwise
  103. */
  104. static int ehci_hcd_xilinx_of_probe(struct platform_device *op)
  105. {
  106. struct device_node *dn = op->dev.of_node;
  107. struct usb_hcd *hcd;
  108. struct ehci_hcd *ehci;
  109. struct resource res;
  110. int irq;
  111. int rv;
  112. int *value;
  113. if (usb_disabled())
  114. return -ENODEV;
  115. dev_dbg(&op->dev, "initializing XILINX-OF USB Controller\n");
  116. rv = of_address_to_resource(dn, 0, &res);
  117. if (rv)
  118. return rv;
  119. hcd = usb_create_hcd(&ehci_xilinx_of_hc_driver, &op->dev,
  120. "XILINX-OF USB");
  121. if (!hcd)
  122. return -ENOMEM;
  123. hcd->rsrc_start = res.start;
  124. hcd->rsrc_len = resource_size(&res);
  125. irq = irq_of_parse_and_map(dn, 0);
  126. if (!irq) {
  127. dev_err(&op->dev, "%s: irq_of_parse_and_map failed\n",
  128. __FILE__);
  129. rv = -EBUSY;
  130. goto err_irq;
  131. }
  132. hcd->regs = devm_ioremap_resource(&op->dev, &res);
  133. if (IS_ERR(hcd->regs)) {
  134. rv = PTR_ERR(hcd->regs);
  135. goto err_irq;
  136. }
  137. ehci = hcd_to_ehci(hcd);
  138. /* This core always has big-endian register interface and uses
  139. * big-endian memory descriptors.
  140. */
  141. ehci->big_endian_mmio = 1;
  142. ehci->big_endian_desc = 1;
  143. /* Check whether the FS support option is selected in the hardware.
  144. */
  145. value = (int *)of_get_property(dn, "xlnx,support-usb-fs", NULL);
  146. if (value && (*value == 1)) {
  147. ehci_dbg(ehci, "USB host controller supports FS devices\n");
  148. hcd->has_tt = 1;
  149. } else {
  150. ehci_dbg(ehci,
  151. "USB host controller is HS only\n");
  152. hcd->has_tt = 0;
  153. }
  154. /* Debug registers are at the first 0x100 region
  155. */
  156. ehci->caps = hcd->regs + 0x100;
  157. rv = usb_add_hcd(hcd, irq, 0);
  158. if (rv == 0) {
  159. device_wakeup_enable(hcd->self.controller);
  160. return 0;
  161. }
  162. err_irq:
  163. usb_put_hcd(hcd);
  164. return rv;
  165. }
  166. /**
  167. * ehci_hcd_xilinx_of_remove - shutdown hcd and release resources
  168. * @op: pointer to platform_device structure that is to be removed
  169. *
  170. * Remove the hcd structure, and release resources that has been requested
  171. * during probe.
  172. *
  173. * Return: Always return 0
  174. */
  175. static int ehci_hcd_xilinx_of_remove(struct platform_device *op)
  176. {
  177. struct usb_hcd *hcd = platform_get_drvdata(op);
  178. dev_dbg(&op->dev, "stopping XILINX-OF USB Controller\n");
  179. usb_remove_hcd(hcd);
  180. usb_put_hcd(hcd);
  181. return 0;
  182. }
  183. static const struct of_device_id ehci_hcd_xilinx_of_match[] = {
  184. {.compatible = "xlnx,xps-usb-host-1.00.a",},
  185. {},
  186. };
  187. MODULE_DEVICE_TABLE(of, ehci_hcd_xilinx_of_match);
  188. static struct platform_driver ehci_hcd_xilinx_of_driver = {
  189. .probe = ehci_hcd_xilinx_of_probe,
  190. .remove = ehci_hcd_xilinx_of_remove,
  191. .shutdown = usb_hcd_platform_shutdown,
  192. .driver = {
  193. .name = "xilinx-of-ehci",
  194. .of_match_table = ehci_hcd_xilinx_of_match,
  195. },
  196. };