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/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. /**
  33. * ehci_xilinx_port_handed_over - hand the port out if failed to enable it
  34. * @hcd: Pointer to the usb_hcd device to which the host controller bound
  35. * @portnum:Port number to which the device is attached.
  36. *
  37. * This function is used as a place to tell the user that the Xilinx USB host
  38. * controller does support LS devices. And in an HS only configuration, it
  39. * does not support FS devices either. It is hoped that this can help a
  40. * confused user.
  41. *
  42. * There are cases when the host controller fails to enable the port due to,
  43. * for example, insufficient power that can be supplied to the device from
  44. * the USB bus. In those cases, the messages printed here are not helpful.
  45. */
  46. static int ehci_xilinx_port_handed_over(struct usb_hcd *hcd, int portnum)
  47. {
  48. dev_warn(hcd->self.controller, "port %d cannot be enabled\n", portnum);
  49. if (hcd->has_tt) {
  50. dev_warn(hcd->self.controller,
  51. "Maybe you have connected a low speed device?\n");
  52. dev_warn(hcd->self.controller,
  53. "We do not support low speed devices\n");
  54. } else {
  55. dev_warn(hcd->self.controller,
  56. "Maybe your device is not a high speed device?\n");
  57. dev_warn(hcd->self.controller,
  58. "The USB host controller does not support full speed "
  59. "nor low speed devices\n");
  60. dev_warn(hcd->self.controller,
  61. "You can reconfigure the host controller to have "
  62. "full speed support\n");
  63. }
  64. return 0;
  65. }
  66. static const struct hc_driver ehci_xilinx_of_hc_driver = {
  67. .description = hcd_name,
  68. .product_desc = "OF EHCI",
  69. .hcd_priv_size = sizeof(struct ehci_hcd),
  70. /*
  71. * generic hardware linkage
  72. */
  73. .irq = ehci_irq,
  74. .flags = HCD_MEMORY | HCD_USB2,
  75. /*
  76. * basic lifecycle operations
  77. */
  78. .reset = ehci_setup,
  79. .start = ehci_run,
  80. .stop = ehci_stop,
  81. .shutdown = ehci_shutdown,
  82. /*
  83. * managing i/o requests and associated device resources
  84. */
  85. .urb_enqueue = ehci_urb_enqueue,
  86. .urb_dequeue = ehci_urb_dequeue,
  87. .endpoint_disable = ehci_endpoint_disable,
  88. .endpoint_reset = ehci_endpoint_reset,
  89. /*
  90. * scheduling support
  91. */
  92. .get_frame_number = ehci_get_frame,
  93. /*
  94. * root hub support
  95. */
  96. .hub_status_data = ehci_hub_status_data,
  97. .hub_control = ehci_hub_control,
  98. #ifdef CONFIG_PM
  99. .bus_suspend = ehci_bus_suspend,
  100. .bus_resume = ehci_bus_resume,
  101. #endif
  102. .relinquish_port = NULL,
  103. .port_handed_over = ehci_xilinx_port_handed_over,
  104. .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
  105. };
  106. /**
  107. * ehci_hcd_xilinx_of_probe - Probe method for the USB host controller
  108. * @op: pointer to the platform_device bound to the host controller
  109. *
  110. * This function requests resources and sets up appropriate properties for the
  111. * host controller. Because the Xilinx USB host controller can be configured
  112. * as HS only or HS/FS only, it checks the configuration in the device tree
  113. * entry, and sets an appropriate value for hcd->has_tt.
  114. */
  115. static int ehci_hcd_xilinx_of_probe(struct platform_device *op)
  116. {
  117. struct device_node *dn = op->dev.of_node;
  118. struct usb_hcd *hcd;
  119. struct ehci_hcd *ehci;
  120. struct resource res;
  121. int irq;
  122. int rv;
  123. int *value;
  124. if (usb_disabled())
  125. return -ENODEV;
  126. dev_dbg(&op->dev, "initializing XILINX-OF USB Controller\n");
  127. rv = of_address_to_resource(dn, 0, &res);
  128. if (rv)
  129. return rv;
  130. hcd = usb_create_hcd(&ehci_xilinx_of_hc_driver, &op->dev,
  131. "XILINX-OF USB");
  132. if (!hcd)
  133. return -ENOMEM;
  134. hcd->rsrc_start = res.start;
  135. hcd->rsrc_len = resource_size(&res);
  136. irq = irq_of_parse_and_map(dn, 0);
  137. if (!irq) {
  138. printk(KERN_ERR "%s: irq_of_parse_and_map failed\n", __FILE__);
  139. rv = -EBUSY;
  140. goto err_irq;
  141. }
  142. hcd->regs = devm_ioremap_resource(&op->dev, &res);
  143. if (IS_ERR(hcd->regs)) {
  144. rv = PTR_ERR(hcd->regs);
  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. };