ehci-mcs814x.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /*
  2. * MCS814X EHCI Host Controller Driver
  3. *
  4. * Based on "ehci-fsl.c" by Randy Vinson <rvinson@mvista.com>
  5. *
  6. * 2007 (c) MontaVista Software, Inc. This file is licensed under
  7. * the terms of the GNU General Public License version 2. This program
  8. * is licensed "as is" without any warranty of any kind, whether express
  9. * or implied.
  10. */
  11. #include <linux/platform_device.h>
  12. #include <linux/of.h>
  13. #define MCS814X_EHCI_CAPS_OFFSET 0x68
  14. static int mcs814x_ehci_init(struct usb_hcd *hcd)
  15. {
  16. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  17. int retval = 0;
  18. ehci->caps = hcd->regs + MCS814X_EHCI_CAPS_OFFSET;
  19. ehci->regs = hcd->regs
  20. + HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
  21. ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
  22. ehci_reset(ehci);
  23. retval = ehci_init(hcd);
  24. if (retval) {
  25. pr_err("ehci_init failed\n");
  26. return retval;
  27. }
  28. return retval;
  29. }
  30. static const struct hc_driver mcs814x_ehci_hc_driver = {
  31. .description = hcd_name,
  32. .product_desc = "MCS814X EHCI Host Controller",
  33. .hcd_priv_size = sizeof(struct ehci_hcd),
  34. .irq = ehci_irq,
  35. .flags = HCD_MEMORY | HCD_USB2,
  36. .reset = mcs814x_ehci_init,
  37. .start = ehci_run,
  38. .stop = ehci_stop,
  39. .shutdown = ehci_shutdown,
  40. .urb_enqueue = ehci_urb_enqueue,
  41. .urb_dequeue = ehci_urb_dequeue,
  42. .endpoint_disable = ehci_endpoint_disable,
  43. .get_frame_number = ehci_get_frame,
  44. .hub_status_data = ehci_hub_status_data,
  45. .hub_control = ehci_hub_control,
  46. #if defined(CONFIG_PM)
  47. .bus_suspend = ehci_bus_suspend,
  48. .bus_resume = ehci_bus_resume,
  49. #endif
  50. .relinquish_port = ehci_relinquish_port,
  51. .port_handed_over = ehci_port_handed_over,
  52. .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
  53. };
  54. static int mcs814x_ehci_probe(struct platform_device *pdev)
  55. {
  56. struct usb_hcd *hcd;
  57. const struct hc_driver *driver = &mcs814x_ehci_hc_driver;
  58. struct resource *res;
  59. int irq;
  60. int retval;
  61. if (usb_disabled())
  62. return -ENODEV;
  63. res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
  64. if (!res) {
  65. dev_err(&pdev->dev,
  66. "Found HC with no IRQ. Check %s setup!\n",
  67. dev_name(&pdev->dev));
  68. return -ENODEV;
  69. }
  70. irq = res->start;
  71. pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
  72. pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask;
  73. hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev));
  74. if (!hcd) {
  75. retval = -ENOMEM;
  76. goto fail_create_hcd;
  77. }
  78. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  79. if (!res) {
  80. dev_err(&pdev->dev,
  81. "Found HC with no register addr. Check %s setup!\n",
  82. dev_name(&pdev->dev));
  83. retval = -ENODEV;
  84. goto fail_request_resource;
  85. }
  86. hcd->rsrc_start = res->start;
  87. hcd->rsrc_len = resource_size(res);
  88. if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len,
  89. driver->description)) {
  90. dev_dbg(&pdev->dev, "controller already in use\n");
  91. retval = -EBUSY;
  92. goto fail_request_resource;
  93. }
  94. hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len);
  95. if (hcd->regs == NULL) {
  96. dev_dbg(&pdev->dev, "error mapping memory\n");
  97. retval = -EFAULT;
  98. goto fail_ioremap;
  99. }
  100. retval = usb_add_hcd(hcd, irq, IRQF_SHARED);
  101. if (retval)
  102. goto fail_add_hcd;
  103. dev_info(&pdev->dev, "added MCS814X EHCI driver\n");
  104. return retval;
  105. fail_add_hcd:
  106. iounmap(hcd->regs);
  107. fail_ioremap:
  108. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  109. fail_request_resource:
  110. usb_put_hcd(hcd);
  111. fail_create_hcd:
  112. dev_err(&pdev->dev, "init %s fail, %d\n", dev_name(&pdev->dev), retval);
  113. return retval;
  114. }
  115. static int mcs814x_ehci_remove(struct platform_device *pdev)
  116. {
  117. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  118. usb_remove_hcd(hcd);
  119. iounmap(hcd->regs);
  120. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  121. usb_put_hcd(hcd);
  122. return 0;
  123. }
  124. MODULE_ALIAS("platform:mcs814x-ehci");
  125. static const struct of_device_id mcs814x_ehci_id[] = {
  126. { .compatible = "moschip,mcs814x-ehci" },
  127. { .compatible = "usb-ehci" },
  128. { /* sentinel */ },
  129. };
  130. static struct platform_driver mcs814x_ehci_driver = {
  131. .probe = mcs814x_ehci_probe,
  132. .remove = mcs814x_ehci_remove,
  133. .driver = {
  134. .name = "mcs814x-ehci",
  135. .of_match_table = mcs814x_ehci_id,
  136. },
  137. };