ehci-omap.c 22 KB

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