ehci-omap.c 8.7 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-2011 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. *
  12. * Copyright (C) 2009 Nokia Corporation
  13. * Contact: Felipe Balbi <felipe.balbi@nokia.com>
  14. *
  15. * Based on "ehci-fsl.c" and "ehci-au1xxx.c" ehci glue layers
  16. *
  17. * This program is free software; you can redistribute it and/or modify
  18. * it under the terms of the GNU General Public License as published by
  19. * the Free Software Foundation; either version 2 of the License, or
  20. * (at your option) any later version.
  21. *
  22. * This program is distributed in the hope that it will be useful,
  23. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  25. * GNU General Public License for more details.
  26. *
  27. * You should have received a copy of the GNU General Public License
  28. * along with this program; if not, write to the Free Software
  29. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  30. *
  31. * TODO (last updated Feb 27, 2010):
  32. * - add kernel-doc
  33. * - enable AUTOIDLE
  34. * - add suspend/resume
  35. * - add HSIC and TLL support
  36. * - convert to use hwmod and runtime PM
  37. */
  38. #include <linux/platform_device.h>
  39. #include <linux/slab.h>
  40. #include <linux/usb/ulpi.h>
  41. #include <plat/usb.h>
  42. #include <linux/regulator/consumer.h>
  43. /* EHCI Register Set */
  44. #define EHCI_INSNREG04 (0xA0)
  45. #define EHCI_INSNREG04_DISABLE_UNSUSPEND (1 << 5)
  46. #define EHCI_INSNREG05_ULPI (0xA4)
  47. #define EHCI_INSNREG05_ULPI_CONTROL_SHIFT 31
  48. #define EHCI_INSNREG05_ULPI_PORTSEL_SHIFT 24
  49. #define EHCI_INSNREG05_ULPI_OPSEL_SHIFT 22
  50. #define EHCI_INSNREG05_ULPI_REGADD_SHIFT 16
  51. #define EHCI_INSNREG05_ULPI_EXTREGADD_SHIFT 8
  52. #define EHCI_INSNREG05_ULPI_WRDATA_SHIFT 0
  53. /*-------------------------------------------------------------------------*/
  54. static const struct hc_driver ehci_omap_hc_driver;
  55. static inline void ehci_write(void __iomem *base, u32 reg, u32 val)
  56. {
  57. __raw_writel(val, base + reg);
  58. }
  59. static inline u32 ehci_read(void __iomem *base, u32 reg)
  60. {
  61. return __raw_readl(base + reg);
  62. }
  63. static void omap_ehci_soft_phy_reset(struct platform_device *pdev, u8 port)
  64. {
  65. struct usb_hcd *hcd = dev_get_drvdata(&pdev->dev);
  66. unsigned long timeout = jiffies + msecs_to_jiffies(1000);
  67. unsigned reg = 0;
  68. reg = ULPI_FUNC_CTRL_RESET
  69. /* FUNCTION_CTRL_SET register */
  70. | (ULPI_SET(ULPI_FUNC_CTRL) << EHCI_INSNREG05_ULPI_REGADD_SHIFT)
  71. /* Write */
  72. | (2 << EHCI_INSNREG05_ULPI_OPSEL_SHIFT)
  73. /* PORTn */
  74. | ((port + 1) << EHCI_INSNREG05_ULPI_PORTSEL_SHIFT)
  75. /* start ULPI access*/
  76. | (1 << EHCI_INSNREG05_ULPI_CONTROL_SHIFT);
  77. ehci_write(hcd->regs, EHCI_INSNREG05_ULPI, reg);
  78. /* Wait for ULPI access completion */
  79. while ((ehci_read(hcd->regs, EHCI_INSNREG05_ULPI)
  80. & (1 << EHCI_INSNREG05_ULPI_CONTROL_SHIFT))) {
  81. cpu_relax();
  82. if (time_after(jiffies, timeout)) {
  83. dev_dbg(&pdev->dev, "phy reset operation timed out\n");
  84. break;
  85. }
  86. }
  87. }
  88. /* configure so an HC device and id are always provided */
  89. /* always called with process context; sleeping is OK */
  90. /**
  91. * ehci_hcd_omap_probe - initialize TI-based HCDs
  92. *
  93. * Allocates basic resources for this USB host controller, and
  94. * then invokes the start() method for the HCD associated with it
  95. * through the hotplug entry's driver_data.
  96. */
  97. static int ehci_hcd_omap_probe(struct platform_device *pdev)
  98. {
  99. struct device *dev = &pdev->dev;
  100. struct ehci_hcd_omap_platform_data *pdata = dev->platform_data;
  101. struct resource *res;
  102. struct usb_hcd *hcd;
  103. void __iomem *regs;
  104. struct ehci_hcd *omap_ehci;
  105. int ret = -ENODEV;
  106. int irq;
  107. int i;
  108. char supply[7];
  109. if (usb_disabled())
  110. return -ENODEV;
  111. if (!dev->parent) {
  112. dev_err(dev, "Missing parent device\n");
  113. return -ENODEV;
  114. }
  115. irq = platform_get_irq_byname(pdev, "ehci-irq");
  116. if (irq < 0) {
  117. dev_err(dev, "EHCI irq failed\n");
  118. return -ENODEV;
  119. }
  120. res = platform_get_resource_byname(pdev,
  121. IORESOURCE_MEM, "ehci");
  122. if (!res) {
  123. dev_err(dev, "UHH EHCI get resource failed\n");
  124. return -ENODEV;
  125. }
  126. regs = ioremap(res->start, resource_size(res));
  127. if (!regs) {
  128. dev_err(dev, "UHH EHCI ioremap failed\n");
  129. return -ENOMEM;
  130. }
  131. hcd = usb_create_hcd(&ehci_omap_hc_driver, dev,
  132. dev_name(dev));
  133. if (!hcd) {
  134. dev_err(dev, "failed to create hcd with err %d\n", ret);
  135. ret = -ENOMEM;
  136. goto err_io;
  137. }
  138. hcd->rsrc_start = res->start;
  139. hcd->rsrc_len = resource_size(res);
  140. hcd->regs = regs;
  141. /* get ehci regulator and enable */
  142. for (i = 0 ; i < OMAP3_HS_USB_PORTS ; i++) {
  143. if (pdata->port_mode[i] != OMAP_EHCI_PORT_MODE_PHY) {
  144. pdata->regulator[i] = NULL;
  145. continue;
  146. }
  147. snprintf(supply, sizeof(supply), "hsusb%d", i);
  148. pdata->regulator[i] = regulator_get(dev, supply);
  149. if (IS_ERR(pdata->regulator[i])) {
  150. pdata->regulator[i] = NULL;
  151. dev_dbg(dev,
  152. "failed to get ehci port%d regulator\n", i);
  153. } else {
  154. regulator_enable(pdata->regulator[i]);
  155. }
  156. }
  157. ret = omap_usbhs_enable(dev);
  158. if (ret) {
  159. dev_err(dev, "failed to start usbhs with err %d\n", ret);
  160. goto err_enable;
  161. }
  162. /*
  163. * An undocumented "feature" in the OMAP3 EHCI controller,
  164. * causes suspended ports to be taken out of suspend when
  165. * the USBCMD.Run/Stop bit is cleared (for example when
  166. * we do ehci_bus_suspend).
  167. * This breaks suspend-resume if the root-hub is allowed
  168. * to suspend. Writing 1 to this undocumented register bit
  169. * disables this feature and restores normal behavior.
  170. */
  171. ehci_write(regs, EHCI_INSNREG04,
  172. EHCI_INSNREG04_DISABLE_UNSUSPEND);
  173. /* Soft reset the PHY using PHY reset command over ULPI */
  174. if (pdata->port_mode[0] == OMAP_EHCI_PORT_MODE_PHY)
  175. omap_ehci_soft_phy_reset(pdev, 0);
  176. if (pdata->port_mode[1] == OMAP_EHCI_PORT_MODE_PHY)
  177. omap_ehci_soft_phy_reset(pdev, 1);
  178. omap_ehci = hcd_to_ehci(hcd);
  179. omap_ehci->sbrn = 0x20;
  180. /* we know this is the memory we want, no need to ioremap again */
  181. omap_ehci->caps = hcd->regs;
  182. omap_ehci->regs = hcd->regs
  183. + HC_LENGTH(ehci, readl(&omap_ehci->caps->hc_capbase));
  184. dbg_hcs_params(omap_ehci, "reset");
  185. dbg_hcc_params(omap_ehci, "reset");
  186. /* cache this readonly data; minimize chip reads */
  187. omap_ehci->hcs_params = readl(&omap_ehci->caps->hcs_params);
  188. ret = usb_add_hcd(hcd, irq, IRQF_DISABLED | IRQF_SHARED);
  189. if (ret) {
  190. dev_err(dev, "failed to add hcd with err %d\n", ret);
  191. goto err_add_hcd;
  192. }
  193. /* root ports should always stay powered */
  194. ehci_port_power(omap_ehci, 1);
  195. return 0;
  196. err_add_hcd:
  197. omap_usbhs_disable(dev);
  198. err_enable:
  199. usb_put_hcd(hcd);
  200. err_io:
  201. return ret;
  202. }
  203. /**
  204. * ehci_hcd_omap_remove - shutdown processing for EHCI HCDs
  205. * @pdev: USB Host Controller being removed
  206. *
  207. * Reverses the effect of usb_ehci_hcd_omap_probe(), first invoking
  208. * the HCD's stop() method. It is always called from a thread
  209. * context, normally "rmmod", "apmd", or something similar.
  210. */
  211. static int ehci_hcd_omap_remove(struct platform_device *pdev)
  212. {
  213. struct device *dev = &pdev->dev;
  214. struct usb_hcd *hcd = dev_get_drvdata(dev);
  215. usb_remove_hcd(hcd);
  216. omap_usbhs_disable(dev);
  217. usb_put_hcd(hcd);
  218. return 0;
  219. }
  220. static void ehci_hcd_omap_shutdown(struct platform_device *pdev)
  221. {
  222. struct usb_hcd *hcd = dev_get_drvdata(&pdev->dev);
  223. if (hcd->driver->shutdown)
  224. hcd->driver->shutdown(hcd);
  225. }
  226. static struct platform_driver ehci_hcd_omap_driver = {
  227. .probe = ehci_hcd_omap_probe,
  228. .remove = ehci_hcd_omap_remove,
  229. .shutdown = ehci_hcd_omap_shutdown,
  230. /*.suspend = ehci_hcd_omap_suspend, */
  231. /*.resume = ehci_hcd_omap_resume, */
  232. .driver = {
  233. .name = "ehci-omap",
  234. }
  235. };
  236. /*-------------------------------------------------------------------------*/
  237. static const struct hc_driver ehci_omap_hc_driver = {
  238. .description = hcd_name,
  239. .product_desc = "OMAP-EHCI Host Controller",
  240. .hcd_priv_size = sizeof(struct ehci_hcd),
  241. /*
  242. * generic hardware linkage
  243. */
  244. .irq = ehci_irq,
  245. .flags = HCD_MEMORY | HCD_USB2,
  246. /*
  247. * basic lifecycle operations
  248. */
  249. .reset = ehci_init,
  250. .start = ehci_run,
  251. .stop = ehci_stop,
  252. .shutdown = ehci_shutdown,
  253. /*
  254. * managing i/o requests and associated device resources
  255. */
  256. .urb_enqueue = ehci_urb_enqueue,
  257. .urb_dequeue = ehci_urb_dequeue,
  258. .endpoint_disable = ehci_endpoint_disable,
  259. .endpoint_reset = ehci_endpoint_reset,
  260. /*
  261. * scheduling support
  262. */
  263. .get_frame_number = ehci_get_frame,
  264. /*
  265. * root hub support
  266. */
  267. .hub_status_data = ehci_hub_status_data,
  268. .hub_control = ehci_hub_control,
  269. .bus_suspend = ehci_bus_suspend,
  270. .bus_resume = ehci_bus_resume,
  271. .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
  272. };
  273. MODULE_ALIAS("platform:omap-ehci");
  274. MODULE_AUTHOR("Texas Instruments, Inc.");
  275. MODULE_AUTHOR("Felipe Balbi <felipe.balbi@nokia.com>");