ehci-grlib.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. /*
  2. * Driver for Aeroflex Gaisler GRLIB GRUSBHC EHCI host controller
  3. *
  4. * GRUSBHC is typically found on LEON/GRLIB SoCs
  5. *
  6. * (c) Jan Andersson <jan@gaisler.com>
  7. *
  8. * Based on ehci-ppc-of.c which is:
  9. * (c) Valentine Barshak <vbarshak@ru.mvista.com>
  10. * and in turn based on "ehci-ppc-soc.c" by Stefan Roese <sr@denx.de>
  11. * and "ohci-ppc-of.c" by Sylvain Munaut <tnt@246tNt.com>
  12. *
  13. * This program is free software; you can redistribute it and/or modify it
  14. * under the terms of the GNU General Public License as published by the
  15. * Free Software Foundation; either version 2 of the License, or (at your
  16. * option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful, but
  19. * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  20. * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  21. * for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License
  24. * along with this program; if not, write to the Free Software Foundation,
  25. * Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  26. */
  27. #include <linux/signal.h>
  28. #include <linux/of_irq.h>
  29. #include <linux/of_address.h>
  30. #include <linux/of_platform.h>
  31. #define GRUSBHC_HCIVERSION 0x0100 /* Known value of cap. reg. HCIVERSION */
  32. /* called during probe() after chip reset completes */
  33. static int ehci_grlib_setup(struct usb_hcd *hcd)
  34. {
  35. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  36. int retval;
  37. retval = ehci_halt(ehci);
  38. if (retval)
  39. return retval;
  40. retval = ehci_init(hcd);
  41. if (retval)
  42. return retval;
  43. ehci->sbrn = 0x20;
  44. ehci_port_power(ehci, 1);
  45. return ehci_reset(ehci);
  46. }
  47. static const struct hc_driver ehci_grlib_hc_driver = {
  48. .description = hcd_name,
  49. .product_desc = "GRLIB GRUSBHC EHCI",
  50. .hcd_priv_size = sizeof(struct ehci_hcd),
  51. /*
  52. * generic hardware linkage
  53. */
  54. .irq = ehci_irq,
  55. .flags = HCD_MEMORY | HCD_USB2,
  56. /*
  57. * basic lifecycle operations
  58. */
  59. .reset = ehci_grlib_setup,
  60. .start = ehci_run,
  61. .stop = ehci_stop,
  62. .shutdown = ehci_shutdown,
  63. /*
  64. * managing i/o requests and associated device resources
  65. */
  66. .urb_enqueue = ehci_urb_enqueue,
  67. .urb_dequeue = ehci_urb_dequeue,
  68. .endpoint_disable = ehci_endpoint_disable,
  69. .endpoint_reset = ehci_endpoint_reset,
  70. /*
  71. * scheduling support
  72. */
  73. .get_frame_number = ehci_get_frame,
  74. /*
  75. * root hub support
  76. */
  77. .hub_status_data = ehci_hub_status_data,
  78. .hub_control = ehci_hub_control,
  79. #ifdef CONFIG_PM
  80. .bus_suspend = ehci_bus_suspend,
  81. .bus_resume = ehci_bus_resume,
  82. #endif
  83. .relinquish_port = ehci_relinquish_port,
  84. .port_handed_over = ehci_port_handed_over,
  85. .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
  86. };
  87. static int __devinit ehci_hcd_grlib_probe(struct platform_device *op)
  88. {
  89. struct device_node *dn = op->dev.of_node;
  90. struct usb_hcd *hcd;
  91. struct ehci_hcd *ehci = NULL;
  92. struct resource res;
  93. u32 hc_capbase;
  94. int irq;
  95. int rv;
  96. if (usb_disabled())
  97. return -ENODEV;
  98. dev_dbg(&op->dev, "initializing GRUSBHC EHCI USB Controller\n");
  99. rv = of_address_to_resource(dn, 0, &res);
  100. if (rv)
  101. return rv;
  102. /* usb_create_hcd requires dma_mask != NULL */
  103. op->dev.dma_mask = &op->dev.coherent_dma_mask;
  104. hcd = usb_create_hcd(&ehci_grlib_hc_driver, &op->dev,
  105. "GRUSBHC EHCI USB");
  106. if (!hcd)
  107. return -ENOMEM;
  108. hcd->rsrc_start = res.start;
  109. hcd->rsrc_len = resource_size(&res);
  110. if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
  111. printk(KERN_ERR "%s: request_mem_region failed\n", __FILE__);
  112. rv = -EBUSY;
  113. goto err_rmr;
  114. }
  115. irq = irq_of_parse_and_map(dn, 0);
  116. if (irq == NO_IRQ) {
  117. printk(KERN_ERR "%s: irq_of_parse_and_map failed\n", __FILE__);
  118. rv = -EBUSY;
  119. goto err_irq;
  120. }
  121. hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
  122. if (!hcd->regs) {
  123. printk(KERN_ERR "%s: ioremap failed\n", __FILE__);
  124. rv = -ENOMEM;
  125. goto err_ioremap;
  126. }
  127. ehci = hcd_to_ehci(hcd);
  128. ehci->caps = hcd->regs;
  129. /* determine endianness of this implementation */
  130. hc_capbase = ehci_readl(ehci, &ehci->caps->hc_capbase);
  131. if (HC_VERSION(ehci, hc_capbase) != GRUSBHC_HCIVERSION) {
  132. ehci->big_endian_mmio = 1;
  133. ehci->big_endian_desc = 1;
  134. ehci->big_endian_capbase = 1;
  135. }
  136. ehci->regs = hcd->regs +
  137. HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
  138. /* cache this readonly data; minimize chip reads */
  139. ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
  140. rv = usb_add_hcd(hcd, irq, 0);
  141. if (rv)
  142. goto err_ehci;
  143. return 0;
  144. err_ehci:
  145. iounmap(hcd->regs);
  146. err_ioremap:
  147. irq_dispose_mapping(irq);
  148. err_irq:
  149. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  150. err_rmr:
  151. usb_put_hcd(hcd);
  152. return rv;
  153. }
  154. static int ehci_hcd_grlib_remove(struct platform_device *op)
  155. {
  156. struct usb_hcd *hcd = dev_get_drvdata(&op->dev);
  157. dev_set_drvdata(&op->dev, NULL);
  158. dev_dbg(&op->dev, "stopping GRLIB GRUSBHC EHCI USB Controller\n");
  159. usb_remove_hcd(hcd);
  160. iounmap(hcd->regs);
  161. irq_dispose_mapping(hcd->irq);
  162. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  163. usb_put_hcd(hcd);
  164. return 0;
  165. }
  166. static void ehci_hcd_grlib_shutdown(struct platform_device *op)
  167. {
  168. struct usb_hcd *hcd = dev_get_drvdata(&op->dev);
  169. if (hcd->driver->shutdown)
  170. hcd->driver->shutdown(hcd);
  171. }
  172. static const struct of_device_id ehci_hcd_grlib_of_match[] = {
  173. {
  174. .name = "GAISLER_EHCI",
  175. },
  176. {
  177. .name = "01_026",
  178. },
  179. {},
  180. };
  181. MODULE_DEVICE_TABLE(of, ehci_hcd_grlib_of_match);
  182. static struct platform_driver ehci_grlib_driver = {
  183. .probe = ehci_hcd_grlib_probe,
  184. .remove = ehci_hcd_grlib_remove,
  185. .shutdown = ehci_hcd_grlib_shutdown,
  186. .driver = {
  187. .name = "grlib-ehci",
  188. .owner = THIS_MODULE,
  189. .of_match_table = ehci_hcd_grlib_of_match,
  190. },
  191. };