ehci-omap.c 8.5 KB

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