ehci-xilinx-of.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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 __devinit 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. if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
  136. printk(KERN_ERR "%s: request_mem_region failed\n", __FILE__);
  137. rv = -EBUSY;
  138. goto err_rmr;
  139. }
  140. irq = irq_of_parse_and_map(dn, 0);
  141. if (!irq) {
  142. printk(KERN_ERR "%s: irq_of_parse_and_map failed\n", __FILE__);
  143. rv = -EBUSY;
  144. goto err_irq;
  145. }
  146. hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
  147. if (!hcd->regs) {
  148. printk(KERN_ERR "%s: ioremap failed\n", __FILE__);
  149. rv = -ENOMEM;
  150. goto err_ioremap;
  151. }
  152. ehci = hcd_to_ehci(hcd);
  153. /* This core always has big-endian register interface and uses
  154. * big-endian memory descriptors.
  155. */
  156. ehci->big_endian_mmio = 1;
  157. ehci->big_endian_desc = 1;
  158. /* Check whether the FS support option is selected in the hardware.
  159. */
  160. value = (int *)of_get_property(dn, "xlnx,support-usb-fs", NULL);
  161. if (value && (*value == 1)) {
  162. ehci_dbg(ehci, "USB host controller supports FS devices\n");
  163. hcd->has_tt = 1;
  164. } else {
  165. ehci_dbg(ehci,
  166. "USB host controller is HS only\n");
  167. hcd->has_tt = 0;
  168. }
  169. /* Debug registers are at the first 0x100 region
  170. */
  171. ehci->caps = hcd->regs + 0x100;
  172. rv = usb_add_hcd(hcd, irq, 0);
  173. if (rv == 0)
  174. return 0;
  175. iounmap(hcd->regs);
  176. err_ioremap:
  177. err_irq:
  178. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  179. err_rmr:
  180. usb_put_hcd(hcd);
  181. return rv;
  182. }
  183. /**
  184. * ehci_hcd_xilinx_of_remove - shutdown hcd and release resources
  185. * @op: pointer to platform_device structure that is to be removed
  186. *
  187. * Remove the hcd structure, and release resources that has been requested
  188. * during probe.
  189. */
  190. static int ehci_hcd_xilinx_of_remove(struct platform_device *op)
  191. {
  192. struct usb_hcd *hcd = dev_get_drvdata(&op->dev);
  193. dev_set_drvdata(&op->dev, NULL);
  194. dev_dbg(&op->dev, "stopping XILINX-OF USB Controller\n");
  195. usb_remove_hcd(hcd);
  196. iounmap(hcd->regs);
  197. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  198. usb_put_hcd(hcd);
  199. return 0;
  200. }
  201. /**
  202. * ehci_hcd_xilinx_of_shutdown - shutdown the hcd
  203. * @op: pointer to platform_device structure that is to be removed
  204. *
  205. * Properly shutdown the hcd, call driver's shutdown routine.
  206. */
  207. static void ehci_hcd_xilinx_of_shutdown(struct platform_device *op)
  208. {
  209. struct usb_hcd *hcd = dev_get_drvdata(&op->dev);
  210. if (hcd->driver->shutdown)
  211. hcd->driver->shutdown(hcd);
  212. }
  213. static const struct of_device_id ehci_hcd_xilinx_of_match[] = {
  214. {.compatible = "xlnx,xps-usb-host-1.00.a",},
  215. {},
  216. };
  217. MODULE_DEVICE_TABLE(of, ehci_hcd_xilinx_of_match);
  218. static struct platform_driver ehci_hcd_xilinx_of_driver = {
  219. .probe = ehci_hcd_xilinx_of_probe,
  220. .remove = ehci_hcd_xilinx_of_remove,
  221. .shutdown = ehci_hcd_xilinx_of_shutdown,
  222. .driver = {
  223. .name = "xilinx-of-ehci",
  224. .owner = THIS_MODULE,
  225. .of_match_table = ehci_hcd_xilinx_of_match,
  226. },
  227. };