ehci-sead3.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  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/platform_device.h>
  22. static int ehci_sead3_setup(struct usb_hcd *hcd)
  23. {
  24. int ret;
  25. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  26. ehci->caps = hcd->regs + 0x100;
  27. #ifdef __BIG_ENDIAN
  28. ehci->big_endian_mmio = 1;
  29. ehci->big_endian_desc = 1;
  30. #endif
  31. ret = ehci_setup(hcd);
  32. if (ret)
  33. return ret;
  34. ehci->need_io_watchdog = 0;
  35. /* Set burst length to 16 words. */
  36. ehci_writel(ehci, 0x1010, &ehci->regs->reserved[1]);
  37. return ret;
  38. }
  39. const struct hc_driver ehci_sead3_hc_driver = {
  40. .description = hcd_name,
  41. .product_desc = "SEAD-3 EHCI",
  42. .hcd_priv_size = sizeof(struct ehci_hcd),
  43. /*
  44. * generic hardware linkage
  45. */
  46. .irq = ehci_irq,
  47. .flags = HCD_MEMORY | HCD_USB2,
  48. /*
  49. * basic lifecycle operations
  50. *
  51. */
  52. .reset = ehci_sead3_setup,
  53. .start = ehci_run,
  54. .stop = ehci_stop,
  55. .shutdown = ehci_shutdown,
  56. /*
  57. * managing i/o requests and associated device resources
  58. */
  59. .urb_enqueue = ehci_urb_enqueue,
  60. .urb_dequeue = ehci_urb_dequeue,
  61. .endpoint_disable = ehci_endpoint_disable,
  62. .endpoint_reset = ehci_endpoint_reset,
  63. /*
  64. * scheduling support
  65. */
  66. .get_frame_number = ehci_get_frame,
  67. /*
  68. * root hub support
  69. */
  70. .hub_status_data = ehci_hub_status_data,
  71. .hub_control = ehci_hub_control,
  72. .bus_suspend = ehci_bus_suspend,
  73. .bus_resume = ehci_bus_resume,
  74. .relinquish_port = ehci_relinquish_port,
  75. .port_handed_over = ehci_port_handed_over,
  76. .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
  77. };
  78. static int ehci_hcd_sead3_drv_probe(struct platform_device *pdev)
  79. {
  80. struct usb_hcd *hcd;
  81. struct resource *res;
  82. int ret;
  83. if (usb_disabled())
  84. return -ENODEV;
  85. if (pdev->resource[1].flags != IORESOURCE_IRQ) {
  86. pr_debug("resource[1] is not IORESOURCE_IRQ");
  87. return -ENOMEM;
  88. }
  89. hcd = usb_create_hcd(&ehci_sead3_hc_driver, &pdev->dev, "SEAD-3");
  90. if (!hcd)
  91. return -ENOMEM;
  92. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  93. hcd->rsrc_start = res->start;
  94. hcd->rsrc_len = resource_size(res);
  95. if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
  96. pr_debug("request_mem_region failed");
  97. ret = -EBUSY;
  98. goto err1;
  99. }
  100. hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
  101. if (!hcd->regs) {
  102. pr_debug("ioremap failed");
  103. ret = -ENOMEM;
  104. goto err2;
  105. }
  106. /* Root hub has integrated TT. */
  107. hcd->has_tt = 1;
  108. ret = usb_add_hcd(hcd, pdev->resource[1].start,
  109. IRQF_SHARED);
  110. if (ret == 0) {
  111. platform_set_drvdata(pdev, hcd);
  112. return ret;
  113. }
  114. iounmap(hcd->regs);
  115. err2:
  116. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  117. err1:
  118. usb_put_hcd(hcd);
  119. return ret;
  120. }
  121. static int ehci_hcd_sead3_drv_remove(struct platform_device *pdev)
  122. {
  123. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  124. usb_remove_hcd(hcd);
  125. iounmap(hcd->regs);
  126. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  127. usb_put_hcd(hcd);
  128. platform_set_drvdata(pdev, NULL);
  129. return 0;
  130. }
  131. #ifdef CONFIG_PM
  132. static int ehci_hcd_sead3_drv_suspend(struct device *dev)
  133. {
  134. struct usb_hcd *hcd = dev_get_drvdata(dev);
  135. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  136. unsigned long flags;
  137. int rc = 0;
  138. if (time_before(jiffies, ehci->next_statechange))
  139. msleep(20);
  140. /* Root hub was already suspended. Disable irq emission and
  141. * mark HW unaccessible. The PM and USB cores make sure that
  142. * the root hub is either suspended or stopped.
  143. */
  144. ehci_prepare_ports_for_controller_suspend(ehci, device_may_wakeup(dev));
  145. spin_lock_irqsave(&ehci->lock, flags);
  146. ehci_writel(ehci, 0, &ehci->regs->intr_enable);
  147. (void)ehci_readl(ehci, &ehci->regs->intr_enable);
  148. clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
  149. spin_unlock_irqrestore(&ehci->lock, flags);
  150. /* could save FLADJ in case of Vaux power loss
  151. * ... we'd only use it to handle clock skew
  152. */
  153. return rc;
  154. }
  155. static int ehci_hcd_sead3_drv_resume(struct device *dev)
  156. {
  157. struct usb_hcd *hcd = dev_get_drvdata(dev);
  158. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  159. /* maybe restore FLADJ. */
  160. if (time_before(jiffies, ehci->next_statechange))
  161. msleep(100);
  162. /* Mark hardware accessible again as we are out of D3 state by now */
  163. set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
  164. /* If CF is still set, we maintained PCI Vaux power.
  165. * Just undo the effect of ehci_pci_suspend().
  166. */
  167. if (ehci_readl(ehci, &ehci->regs->configured_flag) == FLAG_CF) {
  168. int mask = INTR_MASK;
  169. ehci_prepare_ports_for_controller_resume(ehci);
  170. if (!hcd->self.root_hub->do_remote_wakeup)
  171. mask &= ~STS_PCD;
  172. ehci_writel(ehci, mask, &ehci->regs->intr_enable);
  173. ehci_readl(ehci, &ehci->regs->intr_enable);
  174. return 0;
  175. }
  176. ehci_dbg(ehci, "lost power, restarting\n");
  177. usb_root_hub_lost_power(hcd->self.root_hub);
  178. /* Else reset, to cope with power loss or flush-to-storage
  179. * style "resume" having let BIOS kick in during reboot.
  180. */
  181. (void) ehci_halt(ehci);
  182. (void) ehci_reset(ehci);
  183. /* emptying the schedule aborts any urbs */
  184. spin_lock_irq(&ehci->lock);
  185. if (ehci->reclaim)
  186. end_unlink_async(ehci);
  187. ehci_work(ehci);
  188. spin_unlock_irq(&ehci->lock);
  189. ehci_writel(ehci, ehci->command, &ehci->regs->command);
  190. ehci_writel(ehci, FLAG_CF, &ehci->regs->configured_flag);
  191. ehci_readl(ehci, &ehci->regs->command); /* unblock posted writes */
  192. /* here we "know" root ports should always stay powered */
  193. ehci_port_power(ehci, 1);
  194. ehci->rh_state = EHCI_RH_SUSPENDED;
  195. return 0;
  196. }
  197. static const struct dev_pm_ops sead3_ehci_pmops = {
  198. .suspend = ehci_hcd_sead3_drv_suspend,
  199. .resume = ehci_hcd_sead3_drv_resume,
  200. };
  201. #define SEAD3_EHCI_PMOPS (&sead3_ehci_pmops)
  202. #else
  203. #define SEAD3_EHCI_PMOPS NULL
  204. #endif
  205. static struct platform_driver ehci_hcd_sead3_driver = {
  206. .probe = ehci_hcd_sead3_drv_probe,
  207. .remove = ehci_hcd_sead3_drv_remove,
  208. .shutdown = usb_hcd_platform_shutdown,
  209. .driver = {
  210. .name = "sead3-ehci",
  211. .owner = THIS_MODULE,
  212. .pm = SEAD3_EHCI_PMOPS,
  213. }
  214. };
  215. MODULE_ALIAS("platform:sead3-ehci");