ehci-grlib.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Driver for Aeroflex Gaisler GRLIB GRUSBHC EHCI host controller
  4. *
  5. * GRUSBHC is typically found on LEON/GRLIB SoCs
  6. *
  7. * (c) Jan Andersson <jan@gaisler.com>
  8. *
  9. * Based on ehci-ppc-of.c which is:
  10. * (c) Valentine Barshak <vbarshak@ru.mvista.com>
  11. * and in turn based on "ehci-ppc-soc.c" by Stefan Roese <sr@denx.de>
  12. * and "ohci-ppc-of.c" by Sylvain Munaut <tnt@246tNt.com>
  13. */
  14. #include <linux/err.h>
  15. #include <linux/signal.h>
  16. #include <linux/of_irq.h>
  17. #include <linux/of_address.h>
  18. #include <linux/of_platform.h>
  19. #define GRUSBHC_HCIVERSION 0x0100 /* Known value of cap. reg. HCIVERSION */
  20. static const struct hc_driver ehci_grlib_hc_driver = {
  21. .description = hcd_name,
  22. .product_desc = "GRLIB GRUSBHC EHCI",
  23. .hcd_priv_size = sizeof(struct ehci_hcd),
  24. /*
  25. * generic hardware linkage
  26. */
  27. .irq = ehci_irq,
  28. .flags = HCD_MEMORY | HCD_DMA | HCD_USB2 | HCD_BH,
  29. /*
  30. * basic lifecycle operations
  31. */
  32. .reset = ehci_setup,
  33. .start = ehci_run,
  34. .stop = ehci_stop,
  35. .shutdown = ehci_shutdown,
  36. /*
  37. * managing i/o requests and associated device resources
  38. */
  39. .urb_enqueue = ehci_urb_enqueue,
  40. .urb_dequeue = ehci_urb_dequeue,
  41. .endpoint_disable = ehci_endpoint_disable,
  42. .endpoint_reset = ehci_endpoint_reset,
  43. /*
  44. * scheduling support
  45. */
  46. .get_frame_number = ehci_get_frame,
  47. /*
  48. * root hub support
  49. */
  50. .hub_status_data = ehci_hub_status_data,
  51. .hub_control = ehci_hub_control,
  52. #ifdef CONFIG_PM
  53. .bus_suspend = ehci_bus_suspend,
  54. .bus_resume = ehci_bus_resume,
  55. #endif
  56. .relinquish_port = ehci_relinquish_port,
  57. .port_handed_over = ehci_port_handed_over,
  58. .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
  59. };
  60. static int ehci_hcd_grlib_probe(struct platform_device *op)
  61. {
  62. struct device_node *dn = op->dev.of_node;
  63. struct usb_hcd *hcd;
  64. struct ehci_hcd *ehci = NULL;
  65. struct resource res;
  66. u32 hc_capbase;
  67. int irq;
  68. int rv;
  69. if (usb_disabled())
  70. return -ENODEV;
  71. dev_dbg(&op->dev, "initializing GRUSBHC EHCI USB Controller\n");
  72. rv = of_address_to_resource(dn, 0, &res);
  73. if (rv)
  74. return rv;
  75. /* usb_create_hcd requires dma_mask != NULL */
  76. op->dev.dma_mask = &op->dev.coherent_dma_mask;
  77. hcd = usb_create_hcd(&ehci_grlib_hc_driver, &op->dev,
  78. "GRUSBHC EHCI USB");
  79. if (!hcd)
  80. return -ENOMEM;
  81. hcd->rsrc_start = res.start;
  82. hcd->rsrc_len = resource_size(&res);
  83. irq = irq_of_parse_and_map(dn, 0);
  84. if (irq == NO_IRQ) {
  85. dev_err(&op->dev, "%s: irq_of_parse_and_map failed\n",
  86. __FILE__);
  87. rv = -EBUSY;
  88. goto err_irq;
  89. }
  90. hcd->regs = devm_ioremap_resource(&op->dev, &res);
  91. if (IS_ERR(hcd->regs)) {
  92. rv = PTR_ERR(hcd->regs);
  93. goto err_ioremap;
  94. }
  95. ehci = hcd_to_ehci(hcd);
  96. ehci->caps = hcd->regs;
  97. /* determine endianness of this implementation */
  98. hc_capbase = ehci_readl(ehci, &ehci->caps->hc_capbase);
  99. if (HC_VERSION(ehci, hc_capbase) != GRUSBHC_HCIVERSION) {
  100. ehci->big_endian_mmio = 1;
  101. ehci->big_endian_desc = 1;
  102. ehci->big_endian_capbase = 1;
  103. }
  104. rv = usb_add_hcd(hcd, irq, 0);
  105. if (rv)
  106. goto err_ioremap;
  107. device_wakeup_enable(hcd->self.controller);
  108. return 0;
  109. err_ioremap:
  110. irq_dispose_mapping(irq);
  111. err_irq:
  112. usb_put_hcd(hcd);
  113. return rv;
  114. }
  115. static int ehci_hcd_grlib_remove(struct platform_device *op)
  116. {
  117. struct usb_hcd *hcd = platform_get_drvdata(op);
  118. dev_dbg(&op->dev, "stopping GRLIB GRUSBHC EHCI USB Controller\n");
  119. usb_remove_hcd(hcd);
  120. irq_dispose_mapping(hcd->irq);
  121. usb_put_hcd(hcd);
  122. return 0;
  123. }
  124. static const struct of_device_id ehci_hcd_grlib_of_match[] = {
  125. {
  126. .name = "GAISLER_EHCI",
  127. },
  128. {
  129. .name = "01_026",
  130. },
  131. {},
  132. };
  133. MODULE_DEVICE_TABLE(of, ehci_hcd_grlib_of_match);
  134. static struct platform_driver ehci_grlib_driver = {
  135. .probe = ehci_hcd_grlib_probe,
  136. .remove = ehci_hcd_grlib_remove,
  137. .shutdown = usb_hcd_platform_shutdown,
  138. .driver = {
  139. .name = "grlib-ehci",
  140. .of_match_table = ehci_hcd_grlib_of_match,
  141. },
  142. };