ehci-omap.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * ehci-omap.c - driver for USBHOST on OMAP3/4 processors
  4. *
  5. * Bus Glue for the EHCI controllers in OMAP3/4
  6. * Tested on several OMAP3 boards, and OMAP4 Pandaboard
  7. *
  8. * Copyright (C) 2007-2013 Texas Instruments, Inc.
  9. * Author: Vikram Pandita <[email protected]>
  10. * Author: Anand Gadiyar <[email protected]>
  11. * Author: Keshava Munegowda <[email protected]>
  12. * Author: Roger Quadros <[email protected]>
  13. *
  14. * Copyright (C) 2009 Nokia Corporation
  15. * Contact: Felipe Balbi <[email protected]>
  16. *
  17. * Based on "ehci-fsl.c" and "ehci-au1xxx.c" ehci glue layers
  18. */
  19. #include <linux/kernel.h>
  20. #include <linux/module.h>
  21. #include <linux/io.h>
  22. #include <linux/platform_device.h>
  23. #include <linux/slab.h>
  24. #include <linux/usb/ulpi.h>
  25. #include <linux/pm_runtime.h>
  26. #include <linux/clk.h>
  27. #include <linux/usb.h>
  28. #include <linux/usb/hcd.h>
  29. #include <linux/of.h>
  30. #include <linux/dma-mapping.h>
  31. #include "ehci.h"
  32. #include <linux/platform_data/usb-omap.h>
  33. /* EHCI Register Set */
  34. #define EHCI_INSNREG04 (0xA0)
  35. #define EHCI_INSNREG04_DISABLE_UNSUSPEND (1 << 5)
  36. #define EHCI_INSNREG05_ULPI (0xA4)
  37. #define EHCI_INSNREG05_ULPI_CONTROL_SHIFT 31
  38. #define EHCI_INSNREG05_ULPI_PORTSEL_SHIFT 24
  39. #define EHCI_INSNREG05_ULPI_OPSEL_SHIFT 22
  40. #define EHCI_INSNREG05_ULPI_REGADD_SHIFT 16
  41. #define EHCI_INSNREG05_ULPI_EXTREGADD_SHIFT 8
  42. #define EHCI_INSNREG05_ULPI_WRDATA_SHIFT 0
  43. #define DRIVER_DESC "OMAP-EHCI Host Controller driver"
  44. static const char hcd_name[] = "ehci-omap";
  45. /*-------------------------------------------------------------------------*/
  46. struct omap_hcd {
  47. struct usb_phy *phy[OMAP3_HS_USB_PORTS]; /* one PHY for each port */
  48. int nports;
  49. };
  50. static inline void ehci_write(void __iomem *base, u32 reg, u32 val)
  51. {
  52. __raw_writel(val, base + reg);
  53. }
  54. /* configure so an HC device and id are always provided */
  55. /* always called with process context; sleeping is OK */
  56. static struct hc_driver __read_mostly ehci_omap_hc_driver;
  57. static const struct ehci_driver_overrides ehci_omap_overrides __initconst = {
  58. .extra_priv_size = sizeof(struct omap_hcd),
  59. };
  60. /**
  61. * ehci_hcd_omap_probe - initialize TI-based HCDs
  62. * @pdev: Pointer to this platform device's information
  63. *
  64. * Allocates basic resources for this USB host controller, and
  65. * then invokes the start() method for the HCD associated with it
  66. * through the hotplug entry's driver_data.
  67. */
  68. static int ehci_hcd_omap_probe(struct platform_device *pdev)
  69. {
  70. struct device *dev = &pdev->dev;
  71. struct usbhs_omap_platform_data *pdata = dev_get_platdata(dev);
  72. struct resource *res;
  73. struct usb_hcd *hcd;
  74. void __iomem *regs;
  75. int ret;
  76. int irq;
  77. int i;
  78. struct omap_hcd *omap;
  79. if (usb_disabled())
  80. return -ENODEV;
  81. if (!dev->parent) {
  82. dev_err(dev, "Missing parent device\n");
  83. return -ENODEV;
  84. }
  85. /* For DT boot, get platform data from parent. i.e. usbhshost */
  86. if (dev->of_node) {
  87. pdata = dev_get_platdata(dev->parent);
  88. dev->platform_data = pdata;
  89. }
  90. if (!pdata) {
  91. dev_err(dev, "Missing platform data\n");
  92. return -ENODEV;
  93. }
  94. irq = platform_get_irq(pdev, 0);
  95. if (irq < 0)
  96. return irq;
  97. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  98. regs = devm_ioremap_resource(dev, res);
  99. if (IS_ERR(regs))
  100. return PTR_ERR(regs);
  101. /*
  102. * Right now device-tree probed devices don't get dma_mask set.
  103. * Since shared usb code relies on it, set it here for now.
  104. * Once we have dma capability bindings this can go away.
  105. */
  106. ret = dma_coerce_mask_and_coherent(dev, DMA_BIT_MASK(32));
  107. if (ret)
  108. return ret;
  109. ret = -ENODEV;
  110. hcd = usb_create_hcd(&ehci_omap_hc_driver, dev,
  111. dev_name(dev));
  112. if (!hcd) {
  113. dev_err(dev, "Failed to create HCD\n");
  114. return -ENOMEM;
  115. }
  116. hcd->rsrc_start = res->start;
  117. hcd->rsrc_len = resource_size(res);
  118. hcd->regs = regs;
  119. hcd_to_ehci(hcd)->caps = regs;
  120. omap = (struct omap_hcd *)hcd_to_ehci(hcd)->priv;
  121. omap->nports = pdata->nports;
  122. platform_set_drvdata(pdev, hcd);
  123. /* get the PHY devices if needed */
  124. for (i = 0 ; i < omap->nports ; i++) {
  125. struct usb_phy *phy;
  126. /* get the PHY device */
  127. phy = devm_usb_get_phy_by_phandle(dev, "phys", i);
  128. if (IS_ERR(phy)) {
  129. ret = PTR_ERR(phy);
  130. if (ret == -ENODEV) { /* no PHY */
  131. phy = NULL;
  132. continue;
  133. }
  134. if (ret != -EPROBE_DEFER)
  135. dev_err(dev, "Can't get PHY for port %d: %d\n",
  136. i, ret);
  137. goto err_phy;
  138. }
  139. omap->phy[i] = phy;
  140. if (pdata->port_mode[i] == OMAP_EHCI_PORT_MODE_PHY) {
  141. usb_phy_init(omap->phy[i]);
  142. /* bring PHY out of suspend */
  143. usb_phy_set_suspend(omap->phy[i], 0);
  144. }
  145. }
  146. pm_runtime_enable(dev);
  147. pm_runtime_get_sync(dev);
  148. /*
  149. * An undocumented "feature" in the OMAP3 EHCI controller,
  150. * causes suspended ports to be taken out of suspend when
  151. * the USBCMD.Run/Stop bit is cleared (for example when
  152. * we do ehci_bus_suspend).
  153. * This breaks suspend-resume if the root-hub is allowed
  154. * to suspend. Writing 1 to this undocumented register bit
  155. * disables this feature and restores normal behavior.
  156. */
  157. ehci_write(regs, EHCI_INSNREG04,
  158. EHCI_INSNREG04_DISABLE_UNSUSPEND);
  159. ret = usb_add_hcd(hcd, irq, IRQF_SHARED);
  160. if (ret) {
  161. dev_err(dev, "failed to add hcd with err %d\n", ret);
  162. goto err_pm_runtime;
  163. }
  164. device_wakeup_enable(hcd->self.controller);
  165. /*
  166. * Bring PHYs out of reset for non PHY modes.
  167. * Even though HSIC mode is a PHY-less mode, the reset
  168. * line exists between the chips and can be modelled
  169. * as a PHY device for reset control.
  170. */
  171. for (i = 0; i < omap->nports; i++) {
  172. if (!omap->phy[i] ||
  173. pdata->port_mode[i] == OMAP_EHCI_PORT_MODE_PHY)
  174. continue;
  175. usb_phy_init(omap->phy[i]);
  176. /* bring PHY out of suspend */
  177. usb_phy_set_suspend(omap->phy[i], 0);
  178. }
  179. return 0;
  180. err_pm_runtime:
  181. pm_runtime_put_sync(dev);
  182. pm_runtime_disable(dev);
  183. err_phy:
  184. for (i = 0; i < omap->nports; i++) {
  185. if (omap->phy[i])
  186. usb_phy_shutdown(omap->phy[i]);
  187. }
  188. usb_put_hcd(hcd);
  189. return ret;
  190. }
  191. /**
  192. * ehci_hcd_omap_remove - shutdown processing for EHCI HCDs
  193. * @pdev: USB Host Controller being removed
  194. *
  195. * Reverses the effect of usb_ehci_hcd_omap_probe(), first invoking
  196. * the HCD's stop() method. It is always called from a thread
  197. * context, normally "rmmod", "apmd", or something similar.
  198. */
  199. static int ehci_hcd_omap_remove(struct platform_device *pdev)
  200. {
  201. struct device *dev = &pdev->dev;
  202. struct usb_hcd *hcd = dev_get_drvdata(dev);
  203. struct omap_hcd *omap = (struct omap_hcd *)hcd_to_ehci(hcd)->priv;
  204. int i;
  205. usb_remove_hcd(hcd);
  206. for (i = 0; i < omap->nports; i++) {
  207. if (omap->phy[i])
  208. usb_phy_shutdown(omap->phy[i]);
  209. }
  210. usb_put_hcd(hcd);
  211. pm_runtime_put_sync(dev);
  212. pm_runtime_disable(dev);
  213. return 0;
  214. }
  215. static const struct of_device_id omap_ehci_dt_ids[] = {
  216. { .compatible = "ti,ehci-omap" },
  217. { }
  218. };
  219. MODULE_DEVICE_TABLE(of, omap_ehci_dt_ids);
  220. static struct platform_driver ehci_hcd_omap_driver = {
  221. .probe = ehci_hcd_omap_probe,
  222. .remove = ehci_hcd_omap_remove,
  223. .shutdown = usb_hcd_platform_shutdown,
  224. /*.suspend = ehci_hcd_omap_suspend, */
  225. /*.resume = ehci_hcd_omap_resume, */
  226. .driver = {
  227. .name = hcd_name,
  228. .of_match_table = omap_ehci_dt_ids,
  229. }
  230. };
  231. /*-------------------------------------------------------------------------*/
  232. static int __init ehci_omap_init(void)
  233. {
  234. if (usb_disabled())
  235. return -ENODEV;
  236. ehci_init_driver(&ehci_omap_hc_driver, &ehci_omap_overrides);
  237. return platform_driver_register(&ehci_hcd_omap_driver);
  238. }
  239. module_init(ehci_omap_init);
  240. static void __exit ehci_omap_cleanup(void)
  241. {
  242. platform_driver_unregister(&ehci_hcd_omap_driver);
  243. }
  244. module_exit(ehci_omap_cleanup);
  245. MODULE_ALIAS("platform:ehci-omap");
  246. MODULE_AUTHOR("Texas Instruments, Inc.");
  247. MODULE_AUTHOR("Felipe Balbi <[email protected]>");
  248. MODULE_AUTHOR("Roger Quadros <[email protected]>");
  249. MODULE_DESCRIPTION(DRIVER_DESC);
  250. MODULE_LICENSE("GPL");