ehci-xilinx-of.c 7.9 KB

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