ehci-sead3.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /*
  2. * MIPS CI13320A EHCI Host Controller driver
  3. * Based on "ehci-au1xxx.c" by K.Boge <karsten.boge@amd.com>
  4. *
  5. * Copyright (C) 2012 MIPS Technologies, Inc.
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published by the
  9. * Free Software Foundation; either version 2 of the License, or (at your
  10. * option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  14. * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  15. * for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software Foundation,
  19. * Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. */
  21. #include <linux/err.h>
  22. #include <linux/platform_device.h>
  23. static int ehci_sead3_setup(struct usb_hcd *hcd)
  24. {
  25. int ret;
  26. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  27. ehci->caps = hcd->regs + 0x100;
  28. #ifdef __BIG_ENDIAN
  29. ehci->big_endian_mmio = 1;
  30. ehci->big_endian_desc = 1;
  31. #endif
  32. ret = ehci_setup(hcd);
  33. if (ret)
  34. return ret;
  35. ehci->need_io_watchdog = 0;
  36. /* Set burst length to 16 words. */
  37. ehci_writel(ehci, 0x1010, &ehci->regs->reserved1[1]);
  38. return ret;
  39. }
  40. const struct hc_driver ehci_sead3_hc_driver = {
  41. .description = hcd_name,
  42. .product_desc = "SEAD-3 EHCI",
  43. .hcd_priv_size = sizeof(struct ehci_hcd),
  44. /*
  45. * generic hardware linkage
  46. */
  47. .irq = ehci_irq,
  48. .flags = HCD_MEMORY | HCD_USB2 | HCD_BH,
  49. /*
  50. * basic lifecycle operations
  51. *
  52. */
  53. .reset = ehci_sead3_setup,
  54. .start = ehci_run,
  55. .stop = ehci_stop,
  56. .shutdown = ehci_shutdown,
  57. /*
  58. * managing i/o requests and associated device resources
  59. */
  60. .urb_enqueue = ehci_urb_enqueue,
  61. .urb_dequeue = ehci_urb_dequeue,
  62. .endpoint_disable = ehci_endpoint_disable,
  63. .endpoint_reset = ehci_endpoint_reset,
  64. /*
  65. * scheduling support
  66. */
  67. .get_frame_number = ehci_get_frame,
  68. /*
  69. * root hub support
  70. */
  71. .hub_status_data = ehci_hub_status_data,
  72. .hub_control = ehci_hub_control,
  73. .bus_suspend = ehci_bus_suspend,
  74. .bus_resume = ehci_bus_resume,
  75. .relinquish_port = ehci_relinquish_port,
  76. .port_handed_over = ehci_port_handed_over,
  77. .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
  78. };
  79. static int ehci_hcd_sead3_drv_probe(struct platform_device *pdev)
  80. {
  81. struct usb_hcd *hcd;
  82. struct resource *res;
  83. int ret;
  84. if (usb_disabled())
  85. return -ENODEV;
  86. if (pdev->resource[1].flags != IORESOURCE_IRQ) {
  87. pr_debug("resource[1] is not IORESOURCE_IRQ");
  88. return -ENOMEM;
  89. }
  90. hcd = usb_create_hcd(&ehci_sead3_hc_driver, &pdev->dev, "SEAD-3");
  91. if (!hcd)
  92. return -ENOMEM;
  93. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  94. hcd->regs = devm_ioremap_resource(&pdev->dev, res);
  95. if (IS_ERR(hcd->regs)) {
  96. ret = PTR_ERR(hcd->regs);
  97. goto err1;
  98. }
  99. hcd->rsrc_start = res->start;
  100. hcd->rsrc_len = resource_size(res);
  101. /* Root hub has integrated TT. */
  102. hcd->has_tt = 1;
  103. ret = usb_add_hcd(hcd, pdev->resource[1].start,
  104. IRQF_SHARED);
  105. if (ret == 0) {
  106. platform_set_drvdata(pdev, hcd);
  107. device_wakeup_enable(hcd->self.controller);
  108. return ret;
  109. }
  110. err1:
  111. usb_put_hcd(hcd);
  112. return ret;
  113. }
  114. static int ehci_hcd_sead3_drv_remove(struct platform_device *pdev)
  115. {
  116. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  117. usb_remove_hcd(hcd);
  118. usb_put_hcd(hcd);
  119. return 0;
  120. }
  121. #ifdef CONFIG_PM
  122. static int ehci_hcd_sead3_drv_suspend(struct device *dev)
  123. {
  124. struct usb_hcd *hcd = dev_get_drvdata(dev);
  125. bool do_wakeup = device_may_wakeup(dev);
  126. return ehci_suspend(hcd, do_wakeup);
  127. }
  128. static int ehci_hcd_sead3_drv_resume(struct device *dev)
  129. {
  130. struct usb_hcd *hcd = dev_get_drvdata(dev);
  131. ehci_resume(hcd, false);
  132. return 0;
  133. }
  134. static const struct dev_pm_ops sead3_ehci_pmops = {
  135. .suspend = ehci_hcd_sead3_drv_suspend,
  136. .resume = ehci_hcd_sead3_drv_resume,
  137. };
  138. #define SEAD3_EHCI_PMOPS (&sead3_ehci_pmops)
  139. #else
  140. #define SEAD3_EHCI_PMOPS NULL
  141. #endif
  142. static struct platform_driver ehci_hcd_sead3_driver = {
  143. .probe = ehci_hcd_sead3_drv_probe,
  144. .remove = ehci_hcd_sead3_drv_remove,
  145. .shutdown = usb_hcd_platform_shutdown,
  146. .driver = {
  147. .name = "sead3-ehci",
  148. .pm = SEAD3_EHCI_PMOPS,
  149. }
  150. };
  151. MODULE_ALIAS("platform:sead3-ehci");