ehci-xilinx-of.c 6.4 KB

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