ehci-omap.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847
  1. /*
  2. * ehci-omap.c - driver for USBHOST on OMAP 34xx processor
  3. *
  4. * Bus Glue for OMAP34xx USBHOST 3 port EHCI controller
  5. * Tested on OMAP3430 ES2.0 SDP
  6. *
  7. * Copyright (C) 2007-2008 Texas Instruments, Inc.
  8. * Author: Vikram Pandita <vikram.pandita@ti.com>
  9. *
  10. * Copyright (C) 2009 Nokia Corporation
  11. * Contact: Felipe Balbi <felipe.balbi@nokia.com>
  12. *
  13. * Based on "ehci-fsl.c" and "ehci-au1xxx.c" ehci glue layers
  14. *
  15. * This program is free software; you can redistribute it and/or modify
  16. * it under the terms of the GNU General Public License as published by
  17. * the Free Software Foundation; either version 2 of the License, or
  18. * (at your option) any later version.
  19. *
  20. * This program is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU General Public License
  26. * along with this program; if not, write to the Free Software
  27. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  28. *
  29. * TODO (last updated Feb 12, 2010):
  30. * - add kernel-doc
  31. * - enable AUTOIDLE
  32. * - add suspend/resume
  33. * - move workarounds to board-files
  34. */
  35. #include <linux/platform_device.h>
  36. #include <linux/clk.h>
  37. #include <linux/gpio.h>
  38. #include <linux/regulator/consumer.h>
  39. #include <linux/slab.h>
  40. #include <linux/usb/ulpi.h>
  41. #include <plat/usb.h>
  42. /*
  43. * OMAP USBHOST Register addresses: VIRTUAL ADDRESSES
  44. * Use ehci_omap_readl()/ehci_omap_writel() functions
  45. */
  46. /* TLL Register Set */
  47. #define OMAP_USBTLL_REVISION (0x00)
  48. #define OMAP_USBTLL_SYSCONFIG (0x10)
  49. #define OMAP_USBTLL_SYSCONFIG_CACTIVITY (1 << 8)
  50. #define OMAP_USBTLL_SYSCONFIG_SIDLEMODE (1 << 3)
  51. #define OMAP_USBTLL_SYSCONFIG_ENAWAKEUP (1 << 2)
  52. #define OMAP_USBTLL_SYSCONFIG_SOFTRESET (1 << 1)
  53. #define OMAP_USBTLL_SYSCONFIG_AUTOIDLE (1 << 0)
  54. #define OMAP_USBTLL_SYSSTATUS (0x14)
  55. #define OMAP_USBTLL_SYSSTATUS_RESETDONE (1 << 0)
  56. #define OMAP_USBTLL_IRQSTATUS (0x18)
  57. #define OMAP_USBTLL_IRQENABLE (0x1C)
  58. #define OMAP_TLL_SHARED_CONF (0x30)
  59. #define OMAP_TLL_SHARED_CONF_USB_90D_DDR_EN (1 << 6)
  60. #define OMAP_TLL_SHARED_CONF_USB_180D_SDR_EN (1 << 5)
  61. #define OMAP_TLL_SHARED_CONF_USB_DIVRATION (1 << 2)
  62. #define OMAP_TLL_SHARED_CONF_FCLK_REQ (1 << 1)
  63. #define OMAP_TLL_SHARED_CONF_FCLK_IS_ON (1 << 0)
  64. #define OMAP_TLL_CHANNEL_CONF(num) (0x040 + 0x004 * num)
  65. #define OMAP_TLL_CHANNEL_CONF_ULPINOBITSTUFF (1 << 11)
  66. #define OMAP_TLL_CHANNEL_CONF_ULPI_ULPIAUTOIDLE (1 << 10)
  67. #define OMAP_TLL_CHANNEL_CONF_UTMIAUTOIDLE (1 << 9)
  68. #define OMAP_TLL_CHANNEL_CONF_ULPIDDRMODE (1 << 8)
  69. #define OMAP_TLL_CHANNEL_CONF_CHANEN (1 << 0)
  70. #define OMAP_TLL_ULPI_FUNCTION_CTRL(num) (0x804 + 0x100 * num)
  71. #define OMAP_TLL_ULPI_INTERFACE_CTRL(num) (0x807 + 0x100 * num)
  72. #define OMAP_TLL_ULPI_OTG_CTRL(num) (0x80A + 0x100 * num)
  73. #define OMAP_TLL_ULPI_INT_EN_RISE(num) (0x80D + 0x100 * num)
  74. #define OMAP_TLL_ULPI_INT_EN_FALL(num) (0x810 + 0x100 * num)
  75. #define OMAP_TLL_ULPI_INT_STATUS(num) (0x813 + 0x100 * num)
  76. #define OMAP_TLL_ULPI_INT_LATCH(num) (0x814 + 0x100 * num)
  77. #define OMAP_TLL_ULPI_DEBUG(num) (0x815 + 0x100 * num)
  78. #define OMAP_TLL_ULPI_SCRATCH_REGISTER(num) (0x816 + 0x100 * num)
  79. #define OMAP_TLL_CHANNEL_COUNT 3
  80. #define OMAP_TLL_CHANNEL_1_EN_MASK (1 << 1)
  81. #define OMAP_TLL_CHANNEL_2_EN_MASK (1 << 2)
  82. #define OMAP_TLL_CHANNEL_3_EN_MASK (1 << 4)
  83. /* UHH Register Set */
  84. #define OMAP_UHH_REVISION (0x00)
  85. #define OMAP_UHH_SYSCONFIG (0x10)
  86. #define OMAP_UHH_SYSCONFIG_MIDLEMODE (1 << 12)
  87. #define OMAP_UHH_SYSCONFIG_CACTIVITY (1 << 8)
  88. #define OMAP_UHH_SYSCONFIG_SIDLEMODE (1 << 3)
  89. #define OMAP_UHH_SYSCONFIG_ENAWAKEUP (1 << 2)
  90. #define OMAP_UHH_SYSCONFIG_SOFTRESET (1 << 1)
  91. #define OMAP_UHH_SYSCONFIG_AUTOIDLE (1 << 0)
  92. #define OMAP_UHH_SYSSTATUS (0x14)
  93. #define OMAP_UHH_HOSTCONFIG (0x40)
  94. #define OMAP_UHH_HOSTCONFIG_ULPI_BYPASS (1 << 0)
  95. #define OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS (1 << 0)
  96. #define OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS (1 << 11)
  97. #define OMAP_UHH_HOSTCONFIG_ULPI_P3_BYPASS (1 << 12)
  98. #define OMAP_UHH_HOSTCONFIG_INCR4_BURST_EN (1 << 2)
  99. #define OMAP_UHH_HOSTCONFIG_INCR8_BURST_EN (1 << 3)
  100. #define OMAP_UHH_HOSTCONFIG_INCR16_BURST_EN (1 << 4)
  101. #define OMAP_UHH_HOSTCONFIG_INCRX_ALIGN_EN (1 << 5)
  102. #define OMAP_UHH_HOSTCONFIG_P1_CONNECT_STATUS (1 << 8)
  103. #define OMAP_UHH_HOSTCONFIG_P2_CONNECT_STATUS (1 << 9)
  104. #define OMAP_UHH_HOSTCONFIG_P3_CONNECT_STATUS (1 << 10)
  105. #define OMAP_UHH_DEBUG_CSR (0x44)
  106. /* EHCI Register Set */
  107. #define EHCI_INSNREG04 (0xA0)
  108. #define EHCI_INSNREG04_DISABLE_UNSUSPEND (1 << 5)
  109. #define EHCI_INSNREG05_ULPI (0xA4)
  110. #define EHCI_INSNREG05_ULPI_CONTROL_SHIFT 31
  111. #define EHCI_INSNREG05_ULPI_PORTSEL_SHIFT 24
  112. #define EHCI_INSNREG05_ULPI_OPSEL_SHIFT 22
  113. #define EHCI_INSNREG05_ULPI_REGADD_SHIFT 16
  114. #define EHCI_INSNREG05_ULPI_EXTREGADD_SHIFT 8
  115. #define EHCI_INSNREG05_ULPI_WRDATA_SHIFT 0
  116. /*-------------------------------------------------------------------------*/
  117. static inline void ehci_omap_writel(void __iomem *base, u32 reg, u32 val)
  118. {
  119. __raw_writel(val, base + reg);
  120. }
  121. static inline u32 ehci_omap_readl(void __iomem *base, u32 reg)
  122. {
  123. return __raw_readl(base + reg);
  124. }
  125. static inline void ehci_omap_writeb(void __iomem *base, u8 reg, u8 val)
  126. {
  127. __raw_writeb(val, base + reg);
  128. }
  129. static inline u8 ehci_omap_readb(void __iomem *base, u8 reg)
  130. {
  131. return __raw_readb(base + reg);
  132. }
  133. /*-------------------------------------------------------------------------*/
  134. struct ehci_hcd_omap {
  135. struct ehci_hcd *ehci;
  136. struct device *dev;
  137. struct clk *usbhost_ick;
  138. struct clk *usbhost2_120m_fck;
  139. struct clk *usbhost1_48m_fck;
  140. struct clk *usbtll_fck;
  141. struct clk *usbtll_ick;
  142. /* FIXME the following two workarounds are
  143. * board specific not silicon-specific so these
  144. * should be moved to board-file instead.
  145. *
  146. * Maybe someone from TI will know better which
  147. * board is affected and needs the workarounds
  148. * to be applied
  149. */
  150. /* gpio for resetting phy */
  151. int reset_gpio_port[OMAP3_HS_USB_PORTS];
  152. /* phy reset workaround */
  153. int phy_reset;
  154. /* desired phy_mode: TLL, PHY */
  155. enum ehci_hcd_omap_mode port_mode[OMAP3_HS_USB_PORTS];
  156. void __iomem *uhh_base;
  157. void __iomem *tll_base;
  158. void __iomem *ehci_base;
  159. /* Regulators for USB PHYs.
  160. * Each PHY can have a separate regulator.
  161. */
  162. struct regulator *regulator[OMAP3_HS_USB_PORTS];
  163. };
  164. /*-------------------------------------------------------------------------*/
  165. static void omap_usb_utmi_init(struct ehci_hcd_omap *omap, u8 tll_channel_mask)
  166. {
  167. unsigned reg;
  168. int i;
  169. /* Program the 3 TLL channels upfront */
  170. for (i = 0; i < OMAP_TLL_CHANNEL_COUNT; i++) {
  171. reg = ehci_omap_readl(omap->tll_base, OMAP_TLL_CHANNEL_CONF(i));
  172. /* Disable AutoIdle, BitStuffing and use SDR Mode */
  173. reg &= ~(OMAP_TLL_CHANNEL_CONF_UTMIAUTOIDLE
  174. | OMAP_TLL_CHANNEL_CONF_ULPINOBITSTUFF
  175. | OMAP_TLL_CHANNEL_CONF_ULPIDDRMODE);
  176. ehci_omap_writel(omap->tll_base, OMAP_TLL_CHANNEL_CONF(i), reg);
  177. }
  178. /* Program Common TLL register */
  179. reg = ehci_omap_readl(omap->tll_base, OMAP_TLL_SHARED_CONF);
  180. reg |= (OMAP_TLL_SHARED_CONF_FCLK_IS_ON
  181. | OMAP_TLL_SHARED_CONF_USB_DIVRATION
  182. | OMAP_TLL_SHARED_CONF_USB_180D_SDR_EN);
  183. reg &= ~OMAP_TLL_SHARED_CONF_USB_90D_DDR_EN;
  184. ehci_omap_writel(omap->tll_base, OMAP_TLL_SHARED_CONF, reg);
  185. /* Enable channels now */
  186. for (i = 0; i < OMAP_TLL_CHANNEL_COUNT; i++) {
  187. reg = ehci_omap_readl(omap->tll_base, OMAP_TLL_CHANNEL_CONF(i));
  188. /* Enable only the reg that is needed */
  189. if (!(tll_channel_mask & 1<<i))
  190. continue;
  191. reg |= OMAP_TLL_CHANNEL_CONF_CHANEN;
  192. ehci_omap_writel(omap->tll_base, OMAP_TLL_CHANNEL_CONF(i), reg);
  193. ehci_omap_writeb(omap->tll_base,
  194. OMAP_TLL_ULPI_SCRATCH_REGISTER(i), 0xbe);
  195. dev_dbg(omap->dev, "ULPI_SCRATCH_REG[ch=%d]= 0x%02x\n",
  196. i+1, ehci_omap_readb(omap->tll_base,
  197. OMAP_TLL_ULPI_SCRATCH_REGISTER(i)));
  198. }
  199. }
  200. /*-------------------------------------------------------------------------*/
  201. static void omap_ehci_soft_phy_reset(struct ehci_hcd_omap *omap, u8 port)
  202. {
  203. unsigned long timeout = jiffies + msecs_to_jiffies(1000);
  204. unsigned reg = 0;
  205. reg = ULPI_FUNC_CTRL_RESET
  206. /* FUNCTION_CTRL_SET register */
  207. | (ULPI_SET(ULPI_FUNC_CTRL) << EHCI_INSNREG05_ULPI_REGADD_SHIFT)
  208. /* Write */
  209. | (2 << EHCI_INSNREG05_ULPI_OPSEL_SHIFT)
  210. /* PORTn */
  211. | ((port + 1) << EHCI_INSNREG05_ULPI_PORTSEL_SHIFT)
  212. /* start ULPI access*/
  213. | (1 << EHCI_INSNREG05_ULPI_CONTROL_SHIFT);
  214. ehci_omap_writel(omap->ehci_base, EHCI_INSNREG05_ULPI, reg);
  215. /* Wait for ULPI access completion */
  216. while ((ehci_omap_readl(omap->ehci_base, EHCI_INSNREG05_ULPI)
  217. & (1 << EHCI_INSNREG05_ULPI_CONTROL_SHIFT))) {
  218. cpu_relax();
  219. if (time_after(jiffies, timeout)) {
  220. dev_dbg(omap->dev, "phy reset operation timed out\n");
  221. break;
  222. }
  223. }
  224. }
  225. /* omap_start_ehc
  226. * - Start the TI USBHOST controller
  227. */
  228. static int omap_start_ehc(struct ehci_hcd_omap *omap, struct usb_hcd *hcd)
  229. {
  230. unsigned long timeout = jiffies + msecs_to_jiffies(1000);
  231. u8 tll_ch_mask = 0;
  232. unsigned reg = 0;
  233. int ret = 0;
  234. dev_dbg(omap->dev, "starting TI EHCI USB Controller\n");
  235. /* Enable Clocks for USBHOST */
  236. omap->usbhost_ick = clk_get(omap->dev, "usbhost_ick");
  237. if (IS_ERR(omap->usbhost_ick)) {
  238. ret = PTR_ERR(omap->usbhost_ick);
  239. goto err_host_ick;
  240. }
  241. clk_enable(omap->usbhost_ick);
  242. omap->usbhost2_120m_fck = clk_get(omap->dev, "usbhost_120m_fck");
  243. if (IS_ERR(omap->usbhost2_120m_fck)) {
  244. ret = PTR_ERR(omap->usbhost2_120m_fck);
  245. goto err_host_120m_fck;
  246. }
  247. clk_enable(omap->usbhost2_120m_fck);
  248. omap->usbhost1_48m_fck = clk_get(omap->dev, "usbhost_48m_fck");
  249. if (IS_ERR(omap->usbhost1_48m_fck)) {
  250. ret = PTR_ERR(omap->usbhost1_48m_fck);
  251. goto err_host_48m_fck;
  252. }
  253. clk_enable(omap->usbhost1_48m_fck);
  254. if (omap->phy_reset) {
  255. /* Refer: ISSUE1 */
  256. if (gpio_is_valid(omap->reset_gpio_port[0])) {
  257. gpio_request(omap->reset_gpio_port[0],
  258. "USB1 PHY reset");
  259. gpio_direction_output(omap->reset_gpio_port[0], 0);
  260. }
  261. if (gpio_is_valid(omap->reset_gpio_port[1])) {
  262. gpio_request(omap->reset_gpio_port[1],
  263. "USB2 PHY reset");
  264. gpio_direction_output(omap->reset_gpio_port[1], 0);
  265. }
  266. /* Hold the PHY in RESET for enough time till DIR is high */
  267. udelay(10);
  268. }
  269. /* Configure TLL for 60Mhz clk for ULPI */
  270. omap->usbtll_fck = clk_get(omap->dev, "usbtll_fck");
  271. if (IS_ERR(omap->usbtll_fck)) {
  272. ret = PTR_ERR(omap->usbtll_fck);
  273. goto err_tll_fck;
  274. }
  275. clk_enable(omap->usbtll_fck);
  276. omap->usbtll_ick = clk_get(omap->dev, "usbtll_ick");
  277. if (IS_ERR(omap->usbtll_ick)) {
  278. ret = PTR_ERR(omap->usbtll_ick);
  279. goto err_tll_ick;
  280. }
  281. clk_enable(omap->usbtll_ick);
  282. /* perform TLL soft reset, and wait until reset is complete */
  283. ehci_omap_writel(omap->tll_base, OMAP_USBTLL_SYSCONFIG,
  284. OMAP_USBTLL_SYSCONFIG_SOFTRESET);
  285. /* Wait for TLL reset to complete */
  286. while (!(ehci_omap_readl(omap->tll_base, OMAP_USBTLL_SYSSTATUS)
  287. & OMAP_USBTLL_SYSSTATUS_RESETDONE)) {
  288. cpu_relax();
  289. if (time_after(jiffies, timeout)) {
  290. dev_dbg(omap->dev, "operation timed out\n");
  291. ret = -EINVAL;
  292. goto err_sys_status;
  293. }
  294. }
  295. dev_dbg(omap->dev, "TLL RESET DONE\n");
  296. /* (1<<3) = no idle mode only for initial debugging */
  297. ehci_omap_writel(omap->tll_base, OMAP_USBTLL_SYSCONFIG,
  298. OMAP_USBTLL_SYSCONFIG_ENAWAKEUP |
  299. OMAP_USBTLL_SYSCONFIG_SIDLEMODE |
  300. OMAP_USBTLL_SYSCONFIG_CACTIVITY);
  301. /* Put UHH in NoIdle/NoStandby mode */
  302. reg = ehci_omap_readl(omap->uhh_base, OMAP_UHH_SYSCONFIG);
  303. reg |= (OMAP_UHH_SYSCONFIG_ENAWAKEUP
  304. | OMAP_UHH_SYSCONFIG_SIDLEMODE
  305. | OMAP_UHH_SYSCONFIG_CACTIVITY
  306. | OMAP_UHH_SYSCONFIG_MIDLEMODE);
  307. reg &= ~OMAP_UHH_SYSCONFIG_AUTOIDLE;
  308. ehci_omap_writel(omap->uhh_base, OMAP_UHH_SYSCONFIG, reg);
  309. reg = ehci_omap_readl(omap->uhh_base, OMAP_UHH_HOSTCONFIG);
  310. /* setup ULPI bypass and burst configurations */
  311. reg |= (OMAP_UHH_HOSTCONFIG_INCR4_BURST_EN
  312. | OMAP_UHH_HOSTCONFIG_INCR8_BURST_EN
  313. | OMAP_UHH_HOSTCONFIG_INCR16_BURST_EN);
  314. reg &= ~OMAP_UHH_HOSTCONFIG_INCRX_ALIGN_EN;
  315. if (omap->port_mode[0] == EHCI_HCD_OMAP_MODE_UNKNOWN)
  316. reg &= ~OMAP_UHH_HOSTCONFIG_P1_CONNECT_STATUS;
  317. if (omap->port_mode[1] == EHCI_HCD_OMAP_MODE_UNKNOWN)
  318. reg &= ~OMAP_UHH_HOSTCONFIG_P2_CONNECT_STATUS;
  319. if (omap->port_mode[2] == EHCI_HCD_OMAP_MODE_UNKNOWN)
  320. reg &= ~OMAP_UHH_HOSTCONFIG_P3_CONNECT_STATUS;
  321. /* Bypass the TLL module for PHY mode operation */
  322. if (cpu_is_omap3430() && (omap_rev() <= OMAP3430_REV_ES2_1)) {
  323. dev_dbg(omap->dev, "OMAP3 ES version <= ES2.1\n");
  324. if ((omap->port_mode[0] == EHCI_HCD_OMAP_MODE_PHY) ||
  325. (omap->port_mode[1] == EHCI_HCD_OMAP_MODE_PHY) ||
  326. (omap->port_mode[2] == EHCI_HCD_OMAP_MODE_PHY))
  327. reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_BYPASS;
  328. else
  329. reg |= OMAP_UHH_HOSTCONFIG_ULPI_BYPASS;
  330. } else {
  331. dev_dbg(omap->dev, "OMAP3 ES version > ES2.1\n");
  332. if (omap->port_mode[0] == EHCI_HCD_OMAP_MODE_PHY)
  333. reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS;
  334. else if (omap->port_mode[0] == EHCI_HCD_OMAP_MODE_TLL)
  335. reg |= OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS;
  336. if (omap->port_mode[1] == EHCI_HCD_OMAP_MODE_PHY)
  337. reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS;
  338. else if (omap->port_mode[1] == EHCI_HCD_OMAP_MODE_TLL)
  339. reg |= OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS;
  340. if (omap->port_mode[2] == EHCI_HCD_OMAP_MODE_PHY)
  341. reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_P3_BYPASS;
  342. else if (omap->port_mode[2] == EHCI_HCD_OMAP_MODE_TLL)
  343. reg |= OMAP_UHH_HOSTCONFIG_ULPI_P3_BYPASS;
  344. }
  345. ehci_omap_writel(omap->uhh_base, OMAP_UHH_HOSTCONFIG, reg);
  346. dev_dbg(omap->dev, "UHH setup done, uhh_hostconfig=%x\n", reg);
  347. /*
  348. * An undocumented "feature" in the OMAP3 EHCI controller,
  349. * causes suspended ports to be taken out of suspend when
  350. * the USBCMD.Run/Stop bit is cleared (for example when
  351. * we do ehci_bus_suspend).
  352. * This breaks suspend-resume if the root-hub is allowed
  353. * to suspend. Writing 1 to this undocumented register bit
  354. * disables this feature and restores normal behavior.
  355. */
  356. ehci_omap_writel(omap->ehci_base, EHCI_INSNREG04,
  357. EHCI_INSNREG04_DISABLE_UNSUSPEND);
  358. if ((omap->port_mode[0] == EHCI_HCD_OMAP_MODE_TLL) ||
  359. (omap->port_mode[1] == EHCI_HCD_OMAP_MODE_TLL) ||
  360. (omap->port_mode[2] == EHCI_HCD_OMAP_MODE_TLL)) {
  361. if (omap->port_mode[0] == EHCI_HCD_OMAP_MODE_TLL)
  362. tll_ch_mask |= OMAP_TLL_CHANNEL_1_EN_MASK;
  363. if (omap->port_mode[1] == EHCI_HCD_OMAP_MODE_TLL)
  364. tll_ch_mask |= OMAP_TLL_CHANNEL_2_EN_MASK;
  365. if (omap->port_mode[2] == EHCI_HCD_OMAP_MODE_TLL)
  366. tll_ch_mask |= OMAP_TLL_CHANNEL_3_EN_MASK;
  367. /* Enable UTMI mode for required TLL channels */
  368. omap_usb_utmi_init(omap, tll_ch_mask);
  369. }
  370. if (omap->phy_reset) {
  371. /* Refer ISSUE1:
  372. * Hold the PHY in RESET for enough time till
  373. * PHY is settled and ready
  374. */
  375. udelay(10);
  376. if (gpio_is_valid(omap->reset_gpio_port[0]))
  377. gpio_set_value(omap->reset_gpio_port[0], 1);
  378. if (gpio_is_valid(omap->reset_gpio_port[1]))
  379. gpio_set_value(omap->reset_gpio_port[1], 1);
  380. }
  381. /* Soft reset the PHY using PHY reset command over ULPI */
  382. if (omap->port_mode[0] == EHCI_HCD_OMAP_MODE_PHY)
  383. omap_ehci_soft_phy_reset(omap, 0);
  384. if (omap->port_mode[1] == EHCI_HCD_OMAP_MODE_PHY)
  385. omap_ehci_soft_phy_reset(omap, 1);
  386. return 0;
  387. err_sys_status:
  388. clk_disable(omap->usbtll_ick);
  389. clk_put(omap->usbtll_ick);
  390. err_tll_ick:
  391. clk_disable(omap->usbtll_fck);
  392. clk_put(omap->usbtll_fck);
  393. err_tll_fck:
  394. clk_disable(omap->usbhost1_48m_fck);
  395. clk_put(omap->usbhost1_48m_fck);
  396. if (omap->phy_reset) {
  397. if (gpio_is_valid(omap->reset_gpio_port[0]))
  398. gpio_free(omap->reset_gpio_port[0]);
  399. if (gpio_is_valid(omap->reset_gpio_port[1]))
  400. gpio_free(omap->reset_gpio_port[1]);
  401. }
  402. err_host_48m_fck:
  403. clk_disable(omap->usbhost2_120m_fck);
  404. clk_put(omap->usbhost2_120m_fck);
  405. err_host_120m_fck:
  406. clk_disable(omap->usbhost_ick);
  407. clk_put(omap->usbhost_ick);
  408. err_host_ick:
  409. return ret;
  410. }
  411. static void omap_stop_ehc(struct ehci_hcd_omap *omap, struct usb_hcd *hcd)
  412. {
  413. unsigned long timeout = jiffies + msecs_to_jiffies(100);
  414. dev_dbg(omap->dev, "stopping TI EHCI USB Controller\n");
  415. /* Reset OMAP modules for insmod/rmmod to work */
  416. ehci_omap_writel(omap->uhh_base, OMAP_UHH_SYSCONFIG,
  417. OMAP_UHH_SYSCONFIG_SOFTRESET);
  418. while (!(ehci_omap_readl(omap->uhh_base, OMAP_UHH_SYSSTATUS)
  419. & (1 << 0))) {
  420. cpu_relax();
  421. if (time_after(jiffies, timeout))
  422. dev_dbg(omap->dev, "operation timed out\n");
  423. }
  424. while (!(ehci_omap_readl(omap->uhh_base, OMAP_UHH_SYSSTATUS)
  425. & (1 << 1))) {
  426. cpu_relax();
  427. if (time_after(jiffies, timeout))
  428. dev_dbg(omap->dev, "operation timed out\n");
  429. }
  430. while (!(ehci_omap_readl(omap->uhh_base, OMAP_UHH_SYSSTATUS)
  431. & (1 << 2))) {
  432. cpu_relax();
  433. if (time_after(jiffies, timeout))
  434. dev_dbg(omap->dev, "operation timed out\n");
  435. }
  436. ehci_omap_writel(omap->tll_base, OMAP_USBTLL_SYSCONFIG, (1 << 1));
  437. while (!(ehci_omap_readl(omap->tll_base, OMAP_USBTLL_SYSSTATUS)
  438. & (1 << 0))) {
  439. cpu_relax();
  440. if (time_after(jiffies, timeout))
  441. dev_dbg(omap->dev, "operation timed out\n");
  442. }
  443. if (omap->usbtll_fck != NULL) {
  444. clk_disable(omap->usbtll_fck);
  445. clk_put(omap->usbtll_fck);
  446. omap->usbtll_fck = NULL;
  447. }
  448. if (omap->usbhost_ick != NULL) {
  449. clk_disable(omap->usbhost_ick);
  450. clk_put(omap->usbhost_ick);
  451. omap->usbhost_ick = NULL;
  452. }
  453. if (omap->usbhost1_48m_fck != NULL) {
  454. clk_disable(omap->usbhost1_48m_fck);
  455. clk_put(omap->usbhost1_48m_fck);
  456. omap->usbhost1_48m_fck = NULL;
  457. }
  458. if (omap->usbhost2_120m_fck != NULL) {
  459. clk_disable(omap->usbhost2_120m_fck);
  460. clk_put(omap->usbhost2_120m_fck);
  461. omap->usbhost2_120m_fck = NULL;
  462. }
  463. if (omap->usbtll_ick != NULL) {
  464. clk_disable(omap->usbtll_ick);
  465. clk_put(omap->usbtll_ick);
  466. omap->usbtll_ick = NULL;
  467. }
  468. if (omap->phy_reset) {
  469. if (gpio_is_valid(omap->reset_gpio_port[0]))
  470. gpio_free(omap->reset_gpio_port[0]);
  471. if (gpio_is_valid(omap->reset_gpio_port[1]))
  472. gpio_free(omap->reset_gpio_port[1]);
  473. }
  474. dev_dbg(omap->dev, "Clock to USB host has been disabled\n");
  475. }
  476. /*-------------------------------------------------------------------------*/
  477. static const struct hc_driver ehci_omap_hc_driver;
  478. /* configure so an HC device and id are always provided */
  479. /* always called with process context; sleeping is OK */
  480. /**
  481. * ehci_hcd_omap_probe - initialize TI-based HCDs
  482. *
  483. * Allocates basic resources for this USB host controller, and
  484. * then invokes the start() method for the HCD associated with it
  485. * through the hotplug entry's driver_data.
  486. */
  487. static int ehci_hcd_omap_probe(struct platform_device *pdev)
  488. {
  489. struct ehci_hcd_omap_platform_data *pdata = pdev->dev.platform_data;
  490. struct ehci_hcd_omap *omap;
  491. struct resource *res;
  492. struct usb_hcd *hcd;
  493. int irq = platform_get_irq(pdev, 0);
  494. int ret = -ENODEV;
  495. int i;
  496. char supply[7];
  497. if (!pdata) {
  498. dev_dbg(&pdev->dev, "missing platform_data\n");
  499. goto err_pdata;
  500. }
  501. if (usb_disabled())
  502. goto err_disabled;
  503. omap = kzalloc(sizeof(*omap), GFP_KERNEL);
  504. if (!omap) {
  505. ret = -ENOMEM;
  506. goto err_disabled;
  507. }
  508. hcd = usb_create_hcd(&ehci_omap_hc_driver, &pdev->dev,
  509. dev_name(&pdev->dev));
  510. if (!hcd) {
  511. dev_dbg(&pdev->dev, "failed to create hcd with err %d\n", ret);
  512. ret = -ENOMEM;
  513. goto err_create_hcd;
  514. }
  515. platform_set_drvdata(pdev, omap);
  516. omap->dev = &pdev->dev;
  517. omap->phy_reset = pdata->phy_reset;
  518. omap->reset_gpio_port[0] = pdata->reset_gpio_port[0];
  519. omap->reset_gpio_port[1] = pdata->reset_gpio_port[1];
  520. omap->reset_gpio_port[2] = pdata->reset_gpio_port[2];
  521. omap->port_mode[0] = pdata->port_mode[0];
  522. omap->port_mode[1] = pdata->port_mode[1];
  523. omap->port_mode[2] = pdata->port_mode[2];
  524. omap->ehci = hcd_to_ehci(hcd);
  525. omap->ehci->sbrn = 0x20;
  526. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  527. hcd->rsrc_start = res->start;
  528. hcd->rsrc_len = resource_size(res);
  529. hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
  530. if (!hcd->regs) {
  531. dev_err(&pdev->dev, "EHCI ioremap failed\n");
  532. ret = -ENOMEM;
  533. goto err_ioremap;
  534. }
  535. /* we know this is the memory we want, no need to ioremap again */
  536. omap->ehci->caps = hcd->regs;
  537. omap->ehci_base = hcd->regs;
  538. res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
  539. omap->uhh_base = ioremap(res->start, resource_size(res));
  540. if (!omap->uhh_base) {
  541. dev_err(&pdev->dev, "UHH ioremap failed\n");
  542. ret = -ENOMEM;
  543. goto err_uhh_ioremap;
  544. }
  545. res = platform_get_resource(pdev, IORESOURCE_MEM, 2);
  546. omap->tll_base = ioremap(res->start, resource_size(res));
  547. if (!omap->tll_base) {
  548. dev_err(&pdev->dev, "TLL ioremap failed\n");
  549. ret = -ENOMEM;
  550. goto err_tll_ioremap;
  551. }
  552. /* get ehci regulator and enable */
  553. for (i = 0 ; i < OMAP3_HS_USB_PORTS ; i++) {
  554. if (omap->port_mode[i] != EHCI_HCD_OMAP_MODE_PHY) {
  555. omap->regulator[i] = NULL;
  556. continue;
  557. }
  558. snprintf(supply, sizeof(supply), "hsusb%d", i);
  559. omap->regulator[i] = regulator_get(omap->dev, supply);
  560. if (IS_ERR(omap->regulator[i])) {
  561. omap->regulator[i] = NULL;
  562. dev_dbg(&pdev->dev,
  563. "failed to get ehci port%d regulator\n", i);
  564. } else {
  565. regulator_enable(omap->regulator[i]);
  566. }
  567. }
  568. ret = omap_start_ehc(omap, hcd);
  569. if (ret) {
  570. dev_dbg(&pdev->dev, "failed to start ehci\n");
  571. goto err_start;
  572. }
  573. omap->ehci->regs = hcd->regs
  574. + HC_LENGTH(readl(&omap->ehci->caps->hc_capbase));
  575. dbg_hcs_params(omap->ehci, "reset");
  576. dbg_hcc_params(omap->ehci, "reset");
  577. /* cache this readonly data; minimize chip reads */
  578. omap->ehci->hcs_params = readl(&omap->ehci->caps->hcs_params);
  579. ret = usb_add_hcd(hcd, irq, IRQF_DISABLED | IRQF_SHARED);
  580. if (ret) {
  581. dev_dbg(&pdev->dev, "failed to add hcd with err %d\n", ret);
  582. goto err_add_hcd;
  583. }
  584. /* root ports should always stay powered */
  585. ehci_port_power(omap->ehci, 1);
  586. return 0;
  587. err_add_hcd:
  588. omap_stop_ehc(omap, hcd);
  589. err_start:
  590. for (i = 0 ; i < OMAP3_HS_USB_PORTS ; i++) {
  591. if (omap->regulator[i]) {
  592. regulator_disable(omap->regulator[i]);
  593. regulator_put(omap->regulator[i]);
  594. }
  595. }
  596. iounmap(omap->tll_base);
  597. err_tll_ioremap:
  598. iounmap(omap->uhh_base);
  599. err_uhh_ioremap:
  600. iounmap(hcd->regs);
  601. err_ioremap:
  602. usb_put_hcd(hcd);
  603. err_create_hcd:
  604. kfree(omap);
  605. err_disabled:
  606. err_pdata:
  607. return ret;
  608. }
  609. /* may be called without controller electrically present */
  610. /* may be called with controller, bus, and devices active */
  611. /**
  612. * ehci_hcd_omap_remove - shutdown processing for EHCI HCDs
  613. * @pdev: USB Host Controller being removed
  614. *
  615. * Reverses the effect of usb_ehci_hcd_omap_probe(), first invoking
  616. * the HCD's stop() method. It is always called from a thread
  617. * context, normally "rmmod", "apmd", or something similar.
  618. */
  619. static int ehci_hcd_omap_remove(struct platform_device *pdev)
  620. {
  621. struct ehci_hcd_omap *omap = platform_get_drvdata(pdev);
  622. struct usb_hcd *hcd = ehci_to_hcd(omap->ehci);
  623. int i;
  624. usb_remove_hcd(hcd);
  625. omap_stop_ehc(omap, hcd);
  626. iounmap(hcd->regs);
  627. for (i = 0 ; i < OMAP3_HS_USB_PORTS ; i++) {
  628. if (omap->regulator[i]) {
  629. regulator_disable(omap->regulator[i]);
  630. regulator_put(omap->regulator[i]);
  631. }
  632. }
  633. iounmap(omap->tll_base);
  634. iounmap(omap->uhh_base);
  635. usb_put_hcd(hcd);
  636. kfree(omap);
  637. return 0;
  638. }
  639. static void ehci_hcd_omap_shutdown(struct platform_device *pdev)
  640. {
  641. struct ehci_hcd_omap *omap = platform_get_drvdata(pdev);
  642. struct usb_hcd *hcd = ehci_to_hcd(omap->ehci);
  643. if (hcd->driver->shutdown)
  644. hcd->driver->shutdown(hcd);
  645. }
  646. static struct platform_driver ehci_hcd_omap_driver = {
  647. .probe = ehci_hcd_omap_probe,
  648. .remove = ehci_hcd_omap_remove,
  649. .shutdown = ehci_hcd_omap_shutdown,
  650. /*.suspend = ehci_hcd_omap_suspend, */
  651. /*.resume = ehci_hcd_omap_resume, */
  652. .driver = {
  653. .name = "ehci-omap",
  654. }
  655. };
  656. /*-------------------------------------------------------------------------*/
  657. static const struct hc_driver ehci_omap_hc_driver = {
  658. .description = hcd_name,
  659. .product_desc = "OMAP-EHCI Host Controller",
  660. .hcd_priv_size = sizeof(struct ehci_hcd),
  661. /*
  662. * generic hardware linkage
  663. */
  664. .irq = ehci_irq,
  665. .flags = HCD_MEMORY | HCD_USB2,
  666. /*
  667. * basic lifecycle operations
  668. */
  669. .reset = ehci_init,
  670. .start = ehci_run,
  671. .stop = ehci_stop,
  672. .shutdown = ehci_shutdown,
  673. /*
  674. * managing i/o requests and associated device resources
  675. */
  676. .urb_enqueue = ehci_urb_enqueue,
  677. .urb_dequeue = ehci_urb_dequeue,
  678. .endpoint_disable = ehci_endpoint_disable,
  679. .endpoint_reset = ehci_endpoint_reset,
  680. /*
  681. * scheduling support
  682. */
  683. .get_frame_number = ehci_get_frame,
  684. /*
  685. * root hub support
  686. */
  687. .hub_status_data = ehci_hub_status_data,
  688. .hub_control = ehci_hub_control,
  689. .bus_suspend = ehci_bus_suspend,
  690. .bus_resume = ehci_bus_resume,
  691. .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
  692. };
  693. MODULE_ALIAS("platform:omap-ehci");
  694. MODULE_AUTHOR("Texas Instruments, Inc.");
  695. MODULE_AUTHOR("Felipe Balbi <felipe.balbi@nokia.com>");