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