ehci-omap.c 21 KB

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