ehci-grlib.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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_setup(hcd);
  38. if (retval)
  39. return retval;
  40. ehci_port_power(ehci, 1);
  41. return retval;
  42. }
  43. static const struct hc_driver ehci_grlib_hc_driver = {
  44. .description = hcd_name,
  45. .product_desc = "GRLIB GRUSBHC EHCI",
  46. .hcd_priv_size = sizeof(struct ehci_hcd),
  47. /*
  48. * generic hardware linkage
  49. */
  50. .irq = ehci_irq,
  51. .flags = HCD_MEMORY | HCD_USB2,
  52. /*
  53. * basic lifecycle operations
  54. */
  55. .reset = ehci_grlib_setup,
  56. .start = ehci_run,
  57. .stop = ehci_stop,
  58. .shutdown = ehci_shutdown,
  59. /*
  60. * managing i/o requests and associated device resources
  61. */
  62. .urb_enqueue = ehci_urb_enqueue,
  63. .urb_dequeue = ehci_urb_dequeue,
  64. .endpoint_disable = ehci_endpoint_disable,
  65. .endpoint_reset = ehci_endpoint_reset,
  66. /*
  67. * scheduling support
  68. */
  69. .get_frame_number = ehci_get_frame,
  70. /*
  71. * root hub support
  72. */
  73. .hub_status_data = ehci_hub_status_data,
  74. .hub_control = ehci_hub_control,
  75. #ifdef CONFIG_PM
  76. .bus_suspend = ehci_bus_suspend,
  77. .bus_resume = ehci_bus_resume,
  78. #endif
  79. .relinquish_port = ehci_relinquish_port,
  80. .port_handed_over = ehci_port_handed_over,
  81. .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
  82. };
  83. static int __devinit ehci_hcd_grlib_probe(struct platform_device *op)
  84. {
  85. struct device_node *dn = op->dev.of_node;
  86. struct usb_hcd *hcd;
  87. struct ehci_hcd *ehci = NULL;
  88. struct resource res;
  89. u32 hc_capbase;
  90. int irq;
  91. int rv;
  92. if (usb_disabled())
  93. return -ENODEV;
  94. dev_dbg(&op->dev, "initializing GRUSBHC EHCI USB Controller\n");
  95. rv = of_address_to_resource(dn, 0, &res);
  96. if (rv)
  97. return rv;
  98. /* usb_create_hcd requires dma_mask != NULL */
  99. op->dev.dma_mask = &op->dev.coherent_dma_mask;
  100. hcd = usb_create_hcd(&ehci_grlib_hc_driver, &op->dev,
  101. "GRUSBHC EHCI USB");
  102. if (!hcd)
  103. return -ENOMEM;
  104. hcd->rsrc_start = res.start;
  105. hcd->rsrc_len = resource_size(&res);
  106. if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
  107. printk(KERN_ERR "%s: request_mem_region failed\n", __FILE__);
  108. rv = -EBUSY;
  109. goto err_rmr;
  110. }
  111. irq = irq_of_parse_and_map(dn, 0);
  112. if (irq == NO_IRQ) {
  113. printk(KERN_ERR "%s: irq_of_parse_and_map failed\n", __FILE__);
  114. rv = -EBUSY;
  115. goto err_irq;
  116. }
  117. hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
  118. if (!hcd->regs) {
  119. printk(KERN_ERR "%s: ioremap failed\n", __FILE__);
  120. rv = -ENOMEM;
  121. goto err_ioremap;
  122. }
  123. ehci = hcd_to_ehci(hcd);
  124. ehci->caps = hcd->regs;
  125. /* determine endianness of this implementation */
  126. hc_capbase = ehci_readl(ehci, &ehci->caps->hc_capbase);
  127. if (HC_VERSION(ehci, hc_capbase) != GRUSBHC_HCIVERSION) {
  128. ehci->big_endian_mmio = 1;
  129. ehci->big_endian_desc = 1;
  130. ehci->big_endian_capbase = 1;
  131. }
  132. rv = usb_add_hcd(hcd, irq, 0);
  133. if (rv)
  134. goto err_ehci;
  135. return 0;
  136. err_ehci:
  137. iounmap(hcd->regs);
  138. err_ioremap:
  139. irq_dispose_mapping(irq);
  140. err_irq:
  141. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  142. err_rmr:
  143. usb_put_hcd(hcd);
  144. return rv;
  145. }
  146. static int ehci_hcd_grlib_remove(struct platform_device *op)
  147. {
  148. struct usb_hcd *hcd = dev_get_drvdata(&op->dev);
  149. dev_set_drvdata(&op->dev, NULL);
  150. dev_dbg(&op->dev, "stopping GRLIB GRUSBHC EHCI USB Controller\n");
  151. usb_remove_hcd(hcd);
  152. iounmap(hcd->regs);
  153. irq_dispose_mapping(hcd->irq);
  154. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  155. usb_put_hcd(hcd);
  156. return 0;
  157. }
  158. static void ehci_hcd_grlib_shutdown(struct platform_device *op)
  159. {
  160. struct usb_hcd *hcd = dev_get_drvdata(&op->dev);
  161. if (hcd->driver->shutdown)
  162. hcd->driver->shutdown(hcd);
  163. }
  164. static const struct of_device_id ehci_hcd_grlib_of_match[] = {
  165. {
  166. .name = "GAISLER_EHCI",
  167. },
  168. {
  169. .name = "01_026",
  170. },
  171. {},
  172. };
  173. MODULE_DEVICE_TABLE(of, ehci_hcd_grlib_of_match);
  174. static struct platform_driver ehci_grlib_driver = {
  175. .probe = ehci_hcd_grlib_probe,
  176. .remove = ehci_hcd_grlib_remove,
  177. .shutdown = ehci_hcd_grlib_shutdown,
  178. .driver = {
  179. .name = "grlib-ehci",
  180. .owner = THIS_MODULE,
  181. .of_match_table = ehci_hcd_grlib_of_match,
  182. },
  183. };