ehci-grlib.c 4.6 KB

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