ehci-grlib.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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 | HCD_BH,
  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. dev_err(&op->dev, "%s: irq_of_parse_and_map failed\n",
  99. __FILE__);
  100. rv = -EBUSY;
  101. goto err_irq;
  102. }
  103. hcd->regs = devm_ioremap_resource(&op->dev, &res);
  104. if (IS_ERR(hcd->regs)) {
  105. rv = PTR_ERR(hcd->regs);
  106. goto err_ioremap;
  107. }
  108. ehci = hcd_to_ehci(hcd);
  109. ehci->caps = hcd->regs;
  110. /* determine endianness of this implementation */
  111. hc_capbase = ehci_readl(ehci, &ehci->caps->hc_capbase);
  112. if (HC_VERSION(ehci, hc_capbase) != GRUSBHC_HCIVERSION) {
  113. ehci->big_endian_mmio = 1;
  114. ehci->big_endian_desc = 1;
  115. ehci->big_endian_capbase = 1;
  116. }
  117. rv = usb_add_hcd(hcd, irq, 0);
  118. if (rv)
  119. goto err_ioremap;
  120. device_wakeup_enable(hcd->self.controller);
  121. return 0;
  122. err_ioremap:
  123. irq_dispose_mapping(irq);
  124. err_irq:
  125. usb_put_hcd(hcd);
  126. return rv;
  127. }
  128. static int ehci_hcd_grlib_remove(struct platform_device *op)
  129. {
  130. struct usb_hcd *hcd = platform_get_drvdata(op);
  131. dev_dbg(&op->dev, "stopping GRLIB GRUSBHC EHCI USB Controller\n");
  132. usb_remove_hcd(hcd);
  133. irq_dispose_mapping(hcd->irq);
  134. usb_put_hcd(hcd);
  135. return 0;
  136. }
  137. static const struct of_device_id ehci_hcd_grlib_of_match[] = {
  138. {
  139. .name = "GAISLER_EHCI",
  140. },
  141. {
  142. .name = "01_026",
  143. },
  144. {},
  145. };
  146. MODULE_DEVICE_TABLE(of, ehci_hcd_grlib_of_match);
  147. static struct platform_driver ehci_grlib_driver = {
  148. .probe = ehci_hcd_grlib_probe,
  149. .remove = ehci_hcd_grlib_remove,
  150. .shutdown = usb_hcd_platform_shutdown,
  151. .driver = {
  152. .name = "grlib-ehci",
  153. .of_match_table = ehci_hcd_grlib_of_match,
  154. },
  155. };