ehci-xilinx-of.c 6.8 KB

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