ehci-omap.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155
  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-2010 Texas Instruments, Inc.
  8. * Author: Vikram Pandita <vikram.pandita@ti.com>
  9. * Author: Anand Gadiyar <gadiyar@ti.com>
  10. *
  11. * Copyright (C) 2009 Nokia Corporation
  12. * Contact: Felipe Balbi <felipe.balbi@nokia.com>
  13. *
  14. * Based on "ehci-fsl.c" and "ehci-au1xxx.c" ehci glue layers
  15. *
  16. * This program is free software; you can redistribute it and/or modify
  17. * it under the terms of the GNU General Public License as published by
  18. * the Free Software Foundation; either version 2 of the License, or
  19. * (at your option) any later version.
  20. *
  21. * This program is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. * GNU General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU General Public License
  27. * along with this program; if not, write to the Free Software
  28. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  29. *
  30. * TODO (last updated Nov 21, 2010):
  31. * - add kernel-doc
  32. * - enable AUTOIDLE
  33. * - add suspend/resume
  34. * - move workarounds to board-files
  35. * - factor out code common to OHCI
  36. * - add HSIC and TLL support
  37. * - convert to use hwmod and runtime PM
  38. */
  39. #include <linux/platform_device.h>
  40. #include <linux/clk.h>
  41. #include <linux/gpio.h>
  42. #include <linux/regulator/consumer.h>
  43. #include <linux/slab.h>
  44. #include <linux/usb/ulpi.h>
  45. #include <plat/usb.h>
  46. /*
  47. * OMAP USBHOST Register addresses: VIRTUAL ADDRESSES
  48. * Use ehci_omap_readl()/ehci_omap_writel() functions
  49. */
  50. /* TLL Register Set */
  51. #define OMAP_USBTLL_REVISION (0x00)
  52. #define OMAP_USBTLL_SYSCONFIG (0x10)
  53. #define OMAP_USBTLL_SYSCONFIG_CACTIVITY (1 << 8)
  54. #define OMAP_USBTLL_SYSCONFIG_SIDLEMODE (1 << 3)
  55. #define OMAP_USBTLL_SYSCONFIG_ENAWAKEUP (1 << 2)
  56. #define OMAP_USBTLL_SYSCONFIG_SOFTRESET (1 << 1)
  57. #define OMAP_USBTLL_SYSCONFIG_AUTOIDLE (1 << 0)
  58. #define OMAP_USBTLL_SYSSTATUS (0x14)
  59. #define OMAP_USBTLL_SYSSTATUS_RESETDONE (1 << 0)
  60. #define OMAP_USBTLL_IRQSTATUS (0x18)
  61. #define OMAP_USBTLL_IRQENABLE (0x1C)
  62. #define OMAP_TLL_SHARED_CONF (0x30)
  63. #define OMAP_TLL_SHARED_CONF_USB_90D_DDR_EN (1 << 6)
  64. #define OMAP_TLL_SHARED_CONF_USB_180D_SDR_EN (1 << 5)
  65. #define OMAP_TLL_SHARED_CONF_USB_DIVRATION (1 << 2)
  66. #define OMAP_TLL_SHARED_CONF_FCLK_REQ (1 << 1)
  67. #define OMAP_TLL_SHARED_CONF_FCLK_IS_ON (1 << 0)
  68. #define OMAP_TLL_CHANNEL_CONF(num) (0x040 + 0x004 * num)
  69. #define OMAP_TLL_CHANNEL_CONF_ULPINOBITSTUFF (1 << 11)
  70. #define OMAP_TLL_CHANNEL_CONF_ULPI_ULPIAUTOIDLE (1 << 10)
  71. #define OMAP_TLL_CHANNEL_CONF_UTMIAUTOIDLE (1 << 9)
  72. #define OMAP_TLL_CHANNEL_CONF_ULPIDDRMODE (1 << 8)
  73. #define OMAP_TLL_CHANNEL_CONF_CHANEN (1 << 0)
  74. #define OMAP_TLL_ULPI_FUNCTION_CTRL(num) (0x804 + 0x100 * num)
  75. #define OMAP_TLL_ULPI_INTERFACE_CTRL(num) (0x807 + 0x100 * num)
  76. #define OMAP_TLL_ULPI_OTG_CTRL(num) (0x80A + 0x100 * num)
  77. #define OMAP_TLL_ULPI_INT_EN_RISE(num) (0x80D + 0x100 * num)
  78. #define OMAP_TLL_ULPI_INT_EN_FALL(num) (0x810 + 0x100 * num)
  79. #define OMAP_TLL_ULPI_INT_STATUS(num) (0x813 + 0x100 * num)
  80. #define OMAP_TLL_ULPI_INT_LATCH(num) (0x814 + 0x100 * num)
  81. #define OMAP_TLL_ULPI_DEBUG(num) (0x815 + 0x100 * num)
  82. #define OMAP_TLL_ULPI_SCRATCH_REGISTER(num) (0x816 + 0x100 * num)
  83. #define OMAP_TLL_CHANNEL_COUNT 3
  84. #define OMAP_TLL_CHANNEL_1_EN_MASK (1 << 0)
  85. #define OMAP_TLL_CHANNEL_2_EN_MASK (1 << 1)
  86. #define OMAP_TLL_CHANNEL_3_EN_MASK (1 << 2)
  87. /* UHH Register Set */
  88. #define OMAP_UHH_REVISION (0x00)
  89. #define OMAP_UHH_SYSCONFIG (0x10)
  90. #define OMAP_UHH_SYSCONFIG_MIDLEMODE (1 << 12)
  91. #define OMAP_UHH_SYSCONFIG_CACTIVITY (1 << 8)
  92. #define OMAP_UHH_SYSCONFIG_SIDLEMODE (1 << 3)
  93. #define OMAP_UHH_SYSCONFIG_ENAWAKEUP (1 << 2)
  94. #define OMAP_UHH_SYSCONFIG_SOFTRESET (1 << 1)
  95. #define OMAP_UHH_SYSCONFIG_AUTOIDLE (1 << 0)
  96. #define OMAP_UHH_SYSSTATUS (0x14)
  97. #define OMAP_UHH_HOSTCONFIG (0x40)
  98. #define OMAP_UHH_HOSTCONFIG_ULPI_BYPASS (1 << 0)
  99. #define OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS (1 << 0)
  100. #define OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS (1 << 11)
  101. #define OMAP_UHH_HOSTCONFIG_ULPI_P3_BYPASS (1 << 12)
  102. #define OMAP_UHH_HOSTCONFIG_INCR4_BURST_EN (1 << 2)
  103. #define OMAP_UHH_HOSTCONFIG_INCR8_BURST_EN (1 << 3)
  104. #define OMAP_UHH_HOSTCONFIG_INCR16_BURST_EN (1 << 4)
  105. #define OMAP_UHH_HOSTCONFIG_INCRX_ALIGN_EN (1 << 5)
  106. #define OMAP_UHH_HOSTCONFIG_P1_CONNECT_STATUS (1 << 8)
  107. #define OMAP_UHH_HOSTCONFIG_P2_CONNECT_STATUS (1 << 9)
  108. #define OMAP_UHH_HOSTCONFIG_P3_CONNECT_STATUS (1 << 10)
  109. /* OMAP4-specific defines */
  110. #define OMAP4_UHH_SYSCONFIG_IDLEMODE_CLEAR (3 << 2)
  111. #define OMAP4_UHH_SYSCONFIG_NOIDLE (1 << 2)
  112. #define OMAP4_UHH_SYSCONFIG_STDBYMODE_CLEAR (3 << 4)
  113. #define OMAP4_UHH_SYSCONFIG_NOSTDBY (1 << 4)
  114. #define OMAP4_UHH_SYSCONFIG_SOFTRESET (1 << 0)
  115. #define OMAP4_P1_MODE_CLEAR (3 << 16)
  116. #define OMAP4_P1_MODE_TLL (1 << 16)
  117. #define OMAP4_P1_MODE_HSIC (3 << 16)
  118. #define OMAP4_P2_MODE_CLEAR (3 << 18)
  119. #define OMAP4_P2_MODE_TLL (1 << 18)
  120. #define OMAP4_P2_MODE_HSIC (3 << 18)
  121. #define OMAP_REV2_TLL_CHANNEL_COUNT 2
  122. #define OMAP_UHH_DEBUG_CSR (0x44)
  123. /* EHCI Register Set */
  124. #define EHCI_INSNREG04 (0xA0)
  125. #define EHCI_INSNREG04_DISABLE_UNSUSPEND (1 << 5)
  126. #define EHCI_INSNREG05_ULPI (0xA4)
  127. #define EHCI_INSNREG05_ULPI_CONTROL_SHIFT 31
  128. #define EHCI_INSNREG05_ULPI_PORTSEL_SHIFT 24
  129. #define EHCI_INSNREG05_ULPI_OPSEL_SHIFT 22
  130. #define EHCI_INSNREG05_ULPI_REGADD_SHIFT 16
  131. #define EHCI_INSNREG05_ULPI_EXTREGADD_SHIFT 8
  132. #define EHCI_INSNREG05_ULPI_WRDATA_SHIFT 0
  133. /* Values of UHH_REVISION - Note: these are not given in the TRM */
  134. #define OMAP_EHCI_REV1 0x00000010 /* OMAP3 */
  135. #define OMAP_EHCI_REV2 0x50700100 /* OMAP4 */
  136. #define is_omap_ehci_rev1(x) (x->omap_ehci_rev == OMAP_EHCI_REV1)
  137. #define is_omap_ehci_rev2(x) (x->omap_ehci_rev == OMAP_EHCI_REV2)
  138. #define is_ehci_phy_mode(x) (x == EHCI_HCD_OMAP_MODE_PHY)
  139. #define is_ehci_tll_mode(x) (x == EHCI_HCD_OMAP_MODE_TLL)
  140. #define is_ehci_hsic_mode(x) (x == EHCI_HCD_OMAP_MODE_HSIC)
  141. /*-------------------------------------------------------------------------*/
  142. static inline void ehci_omap_writel(void __iomem *base, u32 reg, u32 val)
  143. {
  144. __raw_writel(val, base + reg);
  145. }
  146. static inline u32 ehci_omap_readl(void __iomem *base, u32 reg)
  147. {
  148. return __raw_readl(base + reg);
  149. }
  150. static inline void ehci_omap_writeb(void __iomem *base, u8 reg, u8 val)
  151. {
  152. __raw_writeb(val, base + reg);
  153. }
  154. static inline u8 ehci_omap_readb(void __iomem *base, u8 reg)
  155. {
  156. return __raw_readb(base + reg);
  157. }
  158. /*-------------------------------------------------------------------------*/
  159. struct ehci_hcd_omap {
  160. struct ehci_hcd *ehci;
  161. struct device *dev;
  162. struct clk *usbhost_ick;
  163. struct clk *usbhost_hs_fck;
  164. struct clk *usbhost_fs_fck;
  165. struct clk *usbtll_fck;
  166. struct clk *usbtll_ick;
  167. struct clk *xclk60mhsp1_ck;
  168. struct clk *xclk60mhsp2_ck;
  169. struct clk *utmi_p1_fck;
  170. struct clk *usbhost_p1_fck;
  171. struct clk *usbtll_p1_fck;
  172. struct clk *utmi_p2_fck;
  173. struct clk *usbhost_p2_fck;
  174. struct clk *usbtll_p2_fck;
  175. /* FIXME the following two workarounds are
  176. * board specific not silicon-specific so these
  177. * should be moved to board-file instead.
  178. *
  179. * Maybe someone from TI will know better which
  180. * board is affected and needs the workarounds
  181. * to be applied
  182. */
  183. /* gpio for resetting phy */
  184. int reset_gpio_port[OMAP3_HS_USB_PORTS];
  185. /* phy reset workaround */
  186. int phy_reset;
  187. /* IP revision */
  188. u32 omap_ehci_rev;
  189. /* desired phy_mode: TLL, PHY */
  190. enum ehci_hcd_omap_mode port_mode[OMAP3_HS_USB_PORTS];
  191. void __iomem *uhh_base;
  192. void __iomem *tll_base;
  193. void __iomem *ehci_base;
  194. /* Regulators for USB PHYs.
  195. * Each PHY can have a separate regulator.
  196. */
  197. struct regulator *regulator[OMAP3_HS_USB_PORTS];
  198. };
  199. /*-------------------------------------------------------------------------*/
  200. static void omap_usb_utmi_init(struct ehci_hcd_omap *omap, u8 tll_channel_mask,
  201. u8 tll_channel_count)
  202. {
  203. unsigned reg;
  204. int i;
  205. /* Program the 3 TLL channels upfront */
  206. for (i = 0; i < tll_channel_count; i++) {
  207. reg = ehci_omap_readl(omap->tll_base, OMAP_TLL_CHANNEL_CONF(i));
  208. /* Disable AutoIdle, BitStuffing and use SDR Mode */
  209. reg &= ~(OMAP_TLL_CHANNEL_CONF_UTMIAUTOIDLE
  210. | OMAP_TLL_CHANNEL_CONF_ULPINOBITSTUFF
  211. | OMAP_TLL_CHANNEL_CONF_ULPIDDRMODE);
  212. ehci_omap_writel(omap->tll_base, OMAP_TLL_CHANNEL_CONF(i), reg);
  213. }
  214. /* Program Common TLL register */
  215. reg = ehci_omap_readl(omap->tll_base, OMAP_TLL_SHARED_CONF);
  216. reg |= (OMAP_TLL_SHARED_CONF_FCLK_IS_ON
  217. | OMAP_TLL_SHARED_CONF_USB_DIVRATION
  218. | OMAP_TLL_SHARED_CONF_USB_180D_SDR_EN);
  219. reg &= ~OMAP_TLL_SHARED_CONF_USB_90D_DDR_EN;
  220. ehci_omap_writel(omap->tll_base, OMAP_TLL_SHARED_CONF, reg);
  221. /* Enable channels now */
  222. for (i = 0; i < tll_channel_count; i++) {
  223. reg = ehci_omap_readl(omap->tll_base, OMAP_TLL_CHANNEL_CONF(i));
  224. /* Enable only the reg that is needed */
  225. if (!(tll_channel_mask & 1<<i))
  226. continue;
  227. reg |= OMAP_TLL_CHANNEL_CONF_CHANEN;
  228. ehci_omap_writel(omap->tll_base, OMAP_TLL_CHANNEL_CONF(i), reg);
  229. ehci_omap_writeb(omap->tll_base,
  230. OMAP_TLL_ULPI_SCRATCH_REGISTER(i), 0xbe);
  231. dev_dbg(omap->dev, "ULPI_SCRATCH_REG[ch=%d]= 0x%02x\n",
  232. i+1, ehci_omap_readb(omap->tll_base,
  233. OMAP_TLL_ULPI_SCRATCH_REGISTER(i)));
  234. }
  235. }
  236. /*-------------------------------------------------------------------------*/
  237. static void omap_ehci_soft_phy_reset(struct ehci_hcd_omap *omap, u8 port)
  238. {
  239. unsigned long timeout = jiffies + msecs_to_jiffies(1000);
  240. unsigned reg = 0;
  241. reg = ULPI_FUNC_CTRL_RESET
  242. /* FUNCTION_CTRL_SET register */
  243. | (ULPI_SET(ULPI_FUNC_CTRL) << EHCI_INSNREG05_ULPI_REGADD_SHIFT)
  244. /* Write */
  245. | (2 << EHCI_INSNREG05_ULPI_OPSEL_SHIFT)
  246. /* PORTn */
  247. | ((port + 1) << EHCI_INSNREG05_ULPI_PORTSEL_SHIFT)
  248. /* start ULPI access*/
  249. | (1 << EHCI_INSNREG05_ULPI_CONTROL_SHIFT);
  250. ehci_omap_writel(omap->ehci_base, EHCI_INSNREG05_ULPI, reg);
  251. /* Wait for ULPI access completion */
  252. while ((ehci_omap_readl(omap->ehci_base, EHCI_INSNREG05_ULPI)
  253. & (1 << EHCI_INSNREG05_ULPI_CONTROL_SHIFT))) {
  254. cpu_relax();
  255. if (time_after(jiffies, timeout)) {
  256. dev_dbg(omap->dev, "phy reset operation timed out\n");
  257. break;
  258. }
  259. }
  260. }
  261. /* omap_start_ehc
  262. * - Start the TI USBHOST controller
  263. */
  264. static int omap_start_ehc(struct ehci_hcd_omap *omap, struct usb_hcd *hcd)
  265. {
  266. unsigned long timeout = jiffies + msecs_to_jiffies(1000);
  267. u8 tll_ch_mask = 0;
  268. unsigned reg = 0;
  269. int ret = 0;
  270. dev_dbg(omap->dev, "starting TI EHCI USB Controller\n");
  271. /* Enable Clocks for USBHOST */
  272. omap->usbhost_ick = clk_get(omap->dev, "usbhost_ick");
  273. if (IS_ERR(omap->usbhost_ick)) {
  274. ret = PTR_ERR(omap->usbhost_ick);
  275. goto err_host_ick;
  276. }
  277. clk_enable(omap->usbhost_ick);
  278. omap->usbhost_hs_fck = clk_get(omap->dev, "hs_fck");
  279. if (IS_ERR(omap->usbhost_hs_fck)) {
  280. ret = PTR_ERR(omap->usbhost_hs_fck);
  281. goto err_host_120m_fck;
  282. }
  283. clk_enable(omap->usbhost_hs_fck);
  284. omap->usbhost_fs_fck = clk_get(omap->dev, "fs_fck");
  285. if (IS_ERR(omap->usbhost_fs_fck)) {
  286. ret = PTR_ERR(omap->usbhost_fs_fck);
  287. goto err_host_48m_fck;
  288. }
  289. clk_enable(omap->usbhost_fs_fck);
  290. if (omap->phy_reset) {
  291. /* Refer: ISSUE1 */
  292. if (gpio_is_valid(omap->reset_gpio_port[0])) {
  293. gpio_request(omap->reset_gpio_port[0],
  294. "USB1 PHY reset");
  295. gpio_direction_output(omap->reset_gpio_port[0], 0);
  296. }
  297. if (gpio_is_valid(omap->reset_gpio_port[1])) {
  298. gpio_request(omap->reset_gpio_port[1],
  299. "USB2 PHY reset");
  300. gpio_direction_output(omap->reset_gpio_port[1], 0);
  301. }
  302. /* Hold the PHY in RESET for enough time till DIR is high */
  303. udelay(10);
  304. }
  305. /* Configure TLL for 60Mhz clk for ULPI */
  306. omap->usbtll_fck = clk_get(omap->dev, "usbtll_fck");
  307. if (IS_ERR(omap->usbtll_fck)) {
  308. ret = PTR_ERR(omap->usbtll_fck);
  309. goto err_tll_fck;
  310. }
  311. clk_enable(omap->usbtll_fck);
  312. omap->usbtll_ick = clk_get(omap->dev, "usbtll_ick");
  313. if (IS_ERR(omap->usbtll_ick)) {
  314. ret = PTR_ERR(omap->usbtll_ick);
  315. goto err_tll_ick;
  316. }
  317. clk_enable(omap->usbtll_ick);
  318. omap->omap_ehci_rev = ehci_omap_readl(omap->uhh_base,
  319. OMAP_UHH_REVISION);
  320. dev_dbg(omap->dev, "OMAP UHH_REVISION 0x%x\n",
  321. omap->omap_ehci_rev);
  322. /*
  323. * Enable per-port clocks as needed (newer controllers only).
  324. * - External ULPI clock for PHY mode
  325. * - Internal clocks for TLL and HSIC modes (TODO)
  326. */
  327. if (is_omap_ehci_rev2(omap)) {
  328. switch (omap->port_mode[0]) {
  329. case EHCI_HCD_OMAP_MODE_PHY:
  330. omap->xclk60mhsp1_ck = clk_get(omap->dev,
  331. "xclk60mhsp1_ck");
  332. if (IS_ERR(omap->xclk60mhsp1_ck)) {
  333. ret = PTR_ERR(omap->xclk60mhsp1_ck);
  334. dev_err(omap->dev,
  335. "Unable to get Port1 ULPI clock\n");
  336. }
  337. omap->utmi_p1_fck = clk_get(omap->dev,
  338. "utmi_p1_gfclk");
  339. if (IS_ERR(omap->utmi_p1_fck)) {
  340. ret = PTR_ERR(omap->utmi_p1_fck);
  341. dev_err(omap->dev,
  342. "Unable to get utmi_p1_fck\n");
  343. }
  344. ret = clk_set_parent(omap->utmi_p1_fck,
  345. omap->xclk60mhsp1_ck);
  346. if (ret != 0) {
  347. dev_err(omap->dev,
  348. "Unable to set P1 f-clock\n");
  349. }
  350. break;
  351. case EHCI_HCD_OMAP_MODE_TLL:
  352. omap->xclk60mhsp1_ck = clk_get(omap->dev,
  353. "init_60m_fclk");
  354. if (IS_ERR(omap->xclk60mhsp1_ck)) {
  355. ret = PTR_ERR(omap->xclk60mhsp1_ck);
  356. dev_err(omap->dev,
  357. "Unable to get Port1 ULPI clock\n");
  358. }
  359. omap->utmi_p1_fck = clk_get(omap->dev,
  360. "utmi_p1_gfclk");
  361. if (IS_ERR(omap->utmi_p1_fck)) {
  362. ret = PTR_ERR(omap->utmi_p1_fck);
  363. dev_err(omap->dev,
  364. "Unable to get utmi_p1_fck\n");
  365. }
  366. ret = clk_set_parent(omap->utmi_p1_fck,
  367. omap->xclk60mhsp1_ck);
  368. if (ret != 0) {
  369. dev_err(omap->dev,
  370. "Unable to set P1 f-clock\n");
  371. }
  372. omap->usbhost_p1_fck = clk_get(omap->dev,
  373. "usb_host_hs_utmi_p1_clk");
  374. if (IS_ERR(omap->usbhost_p1_fck)) {
  375. ret = PTR_ERR(omap->usbhost_p1_fck);
  376. dev_err(omap->dev,
  377. "Unable to get HOST PORT 1 clk\n");
  378. } else {
  379. clk_enable(omap->usbhost_p1_fck);
  380. }
  381. omap->usbtll_p1_fck = clk_get(omap->dev,
  382. "usb_tll_hs_usb_ch0_clk");
  383. if (IS_ERR(omap->usbtll_p1_fck)) {
  384. ret = PTR_ERR(omap->usbtll_p1_fck);
  385. dev_err(omap->dev,
  386. "Unable to get TLL CH0 clk\n");
  387. } else {
  388. clk_enable(omap->usbtll_p1_fck);
  389. }
  390. break;
  391. /* TODO */
  392. default:
  393. break;
  394. }
  395. switch (omap->port_mode[1]) {
  396. case EHCI_HCD_OMAP_MODE_PHY:
  397. omap->xclk60mhsp2_ck = clk_get(omap->dev,
  398. "xclk60mhsp2_ck");
  399. if (IS_ERR(omap->xclk60mhsp2_ck)) {
  400. ret = PTR_ERR(omap->xclk60mhsp2_ck);
  401. dev_err(omap->dev,
  402. "Unable to get Port2 ULPI clock\n");
  403. }
  404. omap->utmi_p2_fck = clk_get(omap->dev,
  405. "utmi_p2_gfclk");
  406. if (IS_ERR(omap->utmi_p2_fck)) {
  407. ret = PTR_ERR(omap->utmi_p2_fck);
  408. dev_err(omap->dev,
  409. "Unable to get utmi_p2_fck\n");
  410. }
  411. ret = clk_set_parent(omap->utmi_p2_fck,
  412. omap->xclk60mhsp2_ck);
  413. if (ret != 0) {
  414. dev_err(omap->dev,
  415. "Unable to set P2 f-clock\n");
  416. }
  417. break;
  418. case EHCI_HCD_OMAP_MODE_TLL:
  419. omap->xclk60mhsp2_ck = clk_get(omap->dev,
  420. "init_60m_fclk");
  421. if (IS_ERR(omap->xclk60mhsp2_ck)) {
  422. ret = PTR_ERR(omap->xclk60mhsp2_ck);
  423. dev_err(omap->dev,
  424. "Unable to get Port2 ULPI clock\n");
  425. }
  426. omap->utmi_p2_fck = clk_get(omap->dev,
  427. "utmi_p2_gfclk");
  428. if (IS_ERR(omap->utmi_p2_fck)) {
  429. ret = PTR_ERR(omap->utmi_p2_fck);
  430. dev_err(omap->dev,
  431. "Unable to get utmi_p2_fck\n");
  432. }
  433. ret = clk_set_parent(omap->utmi_p2_fck,
  434. omap->xclk60mhsp2_ck);
  435. if (ret != 0) {
  436. dev_err(omap->dev,
  437. "Unable to set P2 f-clock\n");
  438. }
  439. omap->usbhost_p2_fck = clk_get(omap->dev,
  440. "usb_host_hs_utmi_p2_clk");
  441. if (IS_ERR(omap->usbhost_p2_fck)) {
  442. ret = PTR_ERR(omap->usbhost_p2_fck);
  443. dev_err(omap->dev,
  444. "Unable to get HOST PORT 2 clk\n");
  445. } else {
  446. clk_enable(omap->usbhost_p2_fck);
  447. }
  448. omap->usbtll_p2_fck = clk_get(omap->dev,
  449. "usb_tll_hs_usb_ch1_clk");
  450. if (IS_ERR(omap->usbtll_p2_fck)) {
  451. ret = PTR_ERR(omap->usbtll_p2_fck);
  452. dev_err(omap->dev,
  453. "Unable to get TLL CH1 clk\n");
  454. } else {
  455. clk_enable(omap->usbtll_p2_fck);
  456. }
  457. break;
  458. /* TODO */
  459. default:
  460. break;
  461. }
  462. }
  463. /* perform TLL soft reset, and wait until reset is complete */
  464. ehci_omap_writel(omap->tll_base, OMAP_USBTLL_SYSCONFIG,
  465. OMAP_USBTLL_SYSCONFIG_SOFTRESET);
  466. /* Wait for TLL reset to complete */
  467. while (!(ehci_omap_readl(omap->tll_base, OMAP_USBTLL_SYSSTATUS)
  468. & OMAP_USBTLL_SYSSTATUS_RESETDONE)) {
  469. cpu_relax();
  470. if (time_after(jiffies, timeout)) {
  471. dev_dbg(omap->dev, "operation timed out\n");
  472. ret = -EINVAL;
  473. goto err_sys_status;
  474. }
  475. }
  476. dev_dbg(omap->dev, "TLL RESET DONE\n");
  477. /* (1<<3) = no idle mode only for initial debugging */
  478. ehci_omap_writel(omap->tll_base, OMAP_USBTLL_SYSCONFIG,
  479. OMAP_USBTLL_SYSCONFIG_ENAWAKEUP |
  480. OMAP_USBTLL_SYSCONFIG_SIDLEMODE |
  481. OMAP_USBTLL_SYSCONFIG_CACTIVITY);
  482. /* Put UHH in NoIdle/NoStandby mode */
  483. reg = ehci_omap_readl(omap->uhh_base, OMAP_UHH_SYSCONFIG);
  484. if (is_omap_ehci_rev1(omap)) {
  485. reg |= (OMAP_UHH_SYSCONFIG_ENAWAKEUP
  486. | OMAP_UHH_SYSCONFIG_SIDLEMODE
  487. | OMAP_UHH_SYSCONFIG_CACTIVITY
  488. | OMAP_UHH_SYSCONFIG_MIDLEMODE);
  489. reg &= ~OMAP_UHH_SYSCONFIG_AUTOIDLE;
  490. } else if (is_omap_ehci_rev2(omap)) {
  491. reg &= ~OMAP4_UHH_SYSCONFIG_IDLEMODE_CLEAR;
  492. reg |= OMAP4_UHH_SYSCONFIG_NOIDLE;
  493. reg &= ~OMAP4_UHH_SYSCONFIG_STDBYMODE_CLEAR;
  494. reg |= OMAP4_UHH_SYSCONFIG_NOSTDBY;
  495. }
  496. ehci_omap_writel(omap->uhh_base, OMAP_UHH_SYSCONFIG, reg);
  497. reg = ehci_omap_readl(omap->uhh_base, OMAP_UHH_HOSTCONFIG);
  498. /* setup ULPI bypass and burst configurations */
  499. reg |= (OMAP_UHH_HOSTCONFIG_INCR4_BURST_EN
  500. | OMAP_UHH_HOSTCONFIG_INCR8_BURST_EN
  501. | OMAP_UHH_HOSTCONFIG_INCR16_BURST_EN);
  502. reg &= ~OMAP_UHH_HOSTCONFIG_INCRX_ALIGN_EN;
  503. if (is_omap_ehci_rev1(omap)) {
  504. if (omap->port_mode[0] == EHCI_HCD_OMAP_MODE_UNKNOWN)
  505. reg &= ~OMAP_UHH_HOSTCONFIG_P1_CONNECT_STATUS;
  506. if (omap->port_mode[1] == EHCI_HCD_OMAP_MODE_UNKNOWN)
  507. reg &= ~OMAP_UHH_HOSTCONFIG_P2_CONNECT_STATUS;
  508. if (omap->port_mode[2] == EHCI_HCD_OMAP_MODE_UNKNOWN)
  509. reg &= ~OMAP_UHH_HOSTCONFIG_P3_CONNECT_STATUS;
  510. /* Bypass the TLL module for PHY mode operation */
  511. if (cpu_is_omap3430() && (omap_rev() <= OMAP3430_REV_ES2_1)) {
  512. dev_dbg(omap->dev, "OMAP3 ES version <= ES2.1\n");
  513. if (is_ehci_phy_mode(omap->port_mode[0]) ||
  514. is_ehci_phy_mode(omap->port_mode[1]) ||
  515. is_ehci_phy_mode(omap->port_mode[2]))
  516. reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_BYPASS;
  517. else
  518. reg |= OMAP_UHH_HOSTCONFIG_ULPI_BYPASS;
  519. } else {
  520. dev_dbg(omap->dev, "OMAP3 ES version > ES2.1\n");
  521. if (is_ehci_phy_mode(omap->port_mode[0]))
  522. reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS;
  523. else if (is_ehci_tll_mode(omap->port_mode[0]))
  524. reg |= OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS;
  525. if (is_ehci_phy_mode(omap->port_mode[1]))
  526. reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS;
  527. else if (is_ehci_tll_mode(omap->port_mode[1]))
  528. reg |= OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS;
  529. if (is_ehci_phy_mode(omap->port_mode[2]))
  530. reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_P3_BYPASS;
  531. else if (is_ehci_tll_mode(omap->port_mode[2]))
  532. reg |= OMAP_UHH_HOSTCONFIG_ULPI_P3_BYPASS;
  533. }
  534. } else if (is_omap_ehci_rev2(omap)) {
  535. /* Clear port mode fields for PHY mode*/
  536. reg &= ~OMAP4_P1_MODE_CLEAR;
  537. reg &= ~OMAP4_P2_MODE_CLEAR;
  538. if (is_ehci_tll_mode(omap->port_mode[0]))
  539. reg |= OMAP4_P1_MODE_TLL;
  540. else if (is_ehci_hsic_mode(omap->port_mode[0]))
  541. reg |= OMAP4_P1_MODE_HSIC;
  542. if (is_ehci_tll_mode(omap->port_mode[1]))
  543. reg |= OMAP4_P2_MODE_TLL;
  544. else if (is_ehci_hsic_mode(omap->port_mode[1]))
  545. reg |= OMAP4_P2_MODE_HSIC;
  546. }
  547. ehci_omap_writel(omap->uhh_base, OMAP_UHH_HOSTCONFIG, reg);
  548. dev_dbg(omap->dev, "UHH setup done, uhh_hostconfig=%x\n", reg);
  549. /*
  550. * An undocumented "feature" in the OMAP3 EHCI controller,
  551. * causes suspended ports to be taken out of suspend when
  552. * the USBCMD.Run/Stop bit is cleared (for example when
  553. * we do ehci_bus_suspend).
  554. * This breaks suspend-resume if the root-hub is allowed
  555. * to suspend. Writing 1 to this undocumented register bit
  556. * disables this feature and restores normal behavior.
  557. */
  558. ehci_omap_writel(omap->ehci_base, EHCI_INSNREG04,
  559. EHCI_INSNREG04_DISABLE_UNSUSPEND);
  560. if ((omap->port_mode[0] == EHCI_HCD_OMAP_MODE_TLL) ||
  561. (omap->port_mode[1] == EHCI_HCD_OMAP_MODE_TLL) ||
  562. (omap->port_mode[2] == EHCI_HCD_OMAP_MODE_TLL)) {
  563. if (omap->port_mode[0] == EHCI_HCD_OMAP_MODE_TLL)
  564. tll_ch_mask |= OMAP_TLL_CHANNEL_1_EN_MASK;
  565. if (omap->port_mode[1] == EHCI_HCD_OMAP_MODE_TLL)
  566. tll_ch_mask |= OMAP_TLL_CHANNEL_2_EN_MASK;
  567. if (omap->port_mode[2] == EHCI_HCD_OMAP_MODE_TLL)
  568. tll_ch_mask |= OMAP_TLL_CHANNEL_3_EN_MASK;
  569. /* Enable UTMI mode for required TLL channels */
  570. omap_usb_utmi_init(omap, tll_ch_mask, OMAP_TLL_CHANNEL_COUNT);
  571. }
  572. if (omap->phy_reset) {
  573. /* Refer ISSUE1:
  574. * Hold the PHY in RESET for enough time till
  575. * PHY is settled and ready
  576. */
  577. udelay(10);
  578. if (gpio_is_valid(omap->reset_gpio_port[0]))
  579. gpio_set_value(omap->reset_gpio_port[0], 1);
  580. if (gpio_is_valid(omap->reset_gpio_port[1]))
  581. gpio_set_value(omap->reset_gpio_port[1], 1);
  582. }
  583. /* Soft reset the PHY using PHY reset command over ULPI */
  584. if (omap->port_mode[0] == EHCI_HCD_OMAP_MODE_PHY)
  585. omap_ehci_soft_phy_reset(omap, 0);
  586. if (omap->port_mode[1] == EHCI_HCD_OMAP_MODE_PHY)
  587. omap_ehci_soft_phy_reset(omap, 1);
  588. return 0;
  589. err_sys_status:
  590. if (omap->usbtll_p2_fck != NULL) {
  591. clk_disable(omap->usbtll_p2_fck);
  592. clk_put(omap->usbtll_p2_fck);
  593. }
  594. if (omap->usbhost_p2_fck != NULL) {
  595. clk_disable(omap->usbhost_p2_fck);
  596. clk_put(omap->usbhost_p2_fck);
  597. }
  598. if (omap->usbtll_p1_fck != NULL) {
  599. clk_disable(omap->usbtll_p1_fck);
  600. clk_put(omap->usbtll_p1_fck);
  601. }
  602. if (omap->usbhost_p1_fck != NULL) {
  603. clk_disable(omap->usbhost_p1_fck);
  604. clk_put(omap->usbhost_p1_fck);
  605. }
  606. clk_disable(omap->utmi_p2_fck);
  607. clk_put(omap->utmi_p2_fck);
  608. clk_disable(omap->xclk60mhsp2_ck);
  609. clk_put(omap->xclk60mhsp2_ck);
  610. clk_disable(omap->utmi_p1_fck);
  611. clk_put(omap->utmi_p1_fck);
  612. clk_disable(omap->xclk60mhsp1_ck);
  613. clk_put(omap->xclk60mhsp1_ck);
  614. clk_disable(omap->usbtll_ick);
  615. clk_put(omap->usbtll_ick);
  616. err_tll_ick:
  617. clk_disable(omap->usbtll_fck);
  618. clk_put(omap->usbtll_fck);
  619. err_tll_fck:
  620. clk_disable(omap->usbhost_fs_fck);
  621. clk_put(omap->usbhost_fs_fck);
  622. if (omap->phy_reset) {
  623. if (gpio_is_valid(omap->reset_gpio_port[0]))
  624. gpio_free(omap->reset_gpio_port[0]);
  625. if (gpio_is_valid(omap->reset_gpio_port[1]))
  626. gpio_free(omap->reset_gpio_port[1]);
  627. }
  628. err_host_48m_fck:
  629. clk_disable(omap->usbhost_hs_fck);
  630. clk_put(omap->usbhost_hs_fck);
  631. err_host_120m_fck:
  632. clk_disable(omap->usbhost_ick);
  633. clk_put(omap->usbhost_ick);
  634. err_host_ick:
  635. return ret;
  636. }
  637. static void omap_stop_ehc(struct ehci_hcd_omap *omap, struct usb_hcd *hcd)
  638. {
  639. unsigned long timeout = jiffies + msecs_to_jiffies(100);
  640. dev_dbg(omap->dev, "stopping TI EHCI USB Controller\n");
  641. /* Reset OMAP modules for insmod/rmmod to work */
  642. ehci_omap_writel(omap->uhh_base, OMAP_UHH_SYSCONFIG,
  643. is_omap_ehci_rev2(omap) ?
  644. OMAP4_UHH_SYSCONFIG_SOFTRESET :
  645. OMAP_UHH_SYSCONFIG_SOFTRESET);
  646. while (!(ehci_omap_readl(omap->uhh_base, OMAP_UHH_SYSSTATUS)
  647. & (1 << 0))) {
  648. cpu_relax();
  649. if (time_after(jiffies, timeout))
  650. dev_dbg(omap->dev, "operation timed out\n");
  651. }
  652. while (!(ehci_omap_readl(omap->uhh_base, OMAP_UHH_SYSSTATUS)
  653. & (1 << 1))) {
  654. cpu_relax();
  655. if (time_after(jiffies, timeout))
  656. dev_dbg(omap->dev, "operation timed out\n");
  657. }
  658. while (!(ehci_omap_readl(omap->uhh_base, OMAP_UHH_SYSSTATUS)
  659. & (1 << 2))) {
  660. cpu_relax();
  661. if (time_after(jiffies, timeout))
  662. dev_dbg(omap->dev, "operation timed out\n");
  663. }
  664. ehci_omap_writel(omap->tll_base, OMAP_USBTLL_SYSCONFIG, (1 << 1));
  665. while (!(ehci_omap_readl(omap->tll_base, OMAP_USBTLL_SYSSTATUS)
  666. & (1 << 0))) {
  667. cpu_relax();
  668. if (time_after(jiffies, timeout))
  669. dev_dbg(omap->dev, "operation timed out\n");
  670. }
  671. if (omap->usbtll_fck != NULL) {
  672. clk_disable(omap->usbtll_fck);
  673. clk_put(omap->usbtll_fck);
  674. omap->usbtll_fck = NULL;
  675. }
  676. if (omap->usbhost_ick != NULL) {
  677. clk_disable(omap->usbhost_ick);
  678. clk_put(omap->usbhost_ick);
  679. omap->usbhost_ick = NULL;
  680. }
  681. if (omap->usbhost_fs_fck != NULL) {
  682. clk_disable(omap->usbhost_fs_fck);
  683. clk_put(omap->usbhost_fs_fck);
  684. omap->usbhost_fs_fck = NULL;
  685. }
  686. if (omap->usbhost_hs_fck != NULL) {
  687. clk_disable(omap->usbhost_hs_fck);
  688. clk_put(omap->usbhost_hs_fck);
  689. omap->usbhost_hs_fck = NULL;
  690. }
  691. if (omap->usbtll_ick != NULL) {
  692. clk_disable(omap->usbtll_ick);
  693. clk_put(omap->usbtll_ick);
  694. omap->usbtll_ick = NULL;
  695. }
  696. if (is_omap_ehci_rev2(omap)) {
  697. if (omap->xclk60mhsp1_ck != NULL) {
  698. clk_disable(omap->xclk60mhsp1_ck);
  699. clk_put(omap->xclk60mhsp1_ck);
  700. omap->xclk60mhsp1_ck = NULL;
  701. }
  702. if (omap->utmi_p1_fck != NULL) {
  703. clk_disable(omap->utmi_p1_fck);
  704. clk_put(omap->utmi_p1_fck);
  705. omap->utmi_p1_fck = NULL;
  706. }
  707. if (omap->xclk60mhsp2_ck != NULL) {
  708. clk_disable(omap->xclk60mhsp2_ck);
  709. clk_put(omap->xclk60mhsp2_ck);
  710. omap->xclk60mhsp2_ck = NULL;
  711. }
  712. if (omap->utmi_p2_fck != NULL) {
  713. clk_disable(omap->utmi_p2_fck);
  714. clk_put(omap->utmi_p2_fck);
  715. omap->utmi_p2_fck = NULL;
  716. }
  717. if (omap->usbtll_p2_fck != NULL) {
  718. clk_disable(omap->usbtll_p2_fck);
  719. clk_put(omap->usbtll_p2_fck);
  720. omap->usbtll_p2_fck = NULL;
  721. }
  722. if (omap->usbhost_p2_fck != NULL) {
  723. clk_disable(omap->usbhost_p2_fck);
  724. clk_put(omap->usbhost_p2_fck);
  725. omap->usbhost_p2_fck = NULL;
  726. }
  727. if (omap->usbtll_p1_fck != NULL) {
  728. clk_disable(omap->usbtll_p1_fck);
  729. clk_put(omap->usbtll_p1_fck);
  730. omap->usbtll_p1_fck = NULL;
  731. }
  732. if (omap->usbhost_p1_fck != NULL) {
  733. clk_disable(omap->usbhost_p1_fck);
  734. clk_put(omap->usbhost_p1_fck);
  735. omap->usbhost_p1_fck = NULL;
  736. }
  737. }
  738. if (omap->phy_reset) {
  739. if (gpio_is_valid(omap->reset_gpio_port[0]))
  740. gpio_free(omap->reset_gpio_port[0]);
  741. if (gpio_is_valid(omap->reset_gpio_port[1]))
  742. gpio_free(omap->reset_gpio_port[1]);
  743. }
  744. dev_dbg(omap->dev, "Clock to USB host has been disabled\n");
  745. }
  746. /*-------------------------------------------------------------------------*/
  747. static const struct hc_driver ehci_omap_hc_driver;
  748. /* configure so an HC device and id are always provided */
  749. /* always called with process context; sleeping is OK */
  750. /**
  751. * ehci_hcd_omap_probe - initialize TI-based HCDs
  752. *
  753. * Allocates basic resources for this USB host controller, and
  754. * then invokes the start() method for the HCD associated with it
  755. * through the hotplug entry's driver_data.
  756. */
  757. static int ehci_hcd_omap_probe(struct platform_device *pdev)
  758. {
  759. struct ehci_hcd_omap_platform_data *pdata = pdev->dev.platform_data;
  760. struct ehci_hcd_omap *omap;
  761. struct resource *res;
  762. struct usb_hcd *hcd;
  763. int irq = platform_get_irq(pdev, 0);
  764. int ret = -ENODEV;
  765. int i;
  766. char supply[7];
  767. if (!pdata) {
  768. dev_dbg(&pdev->dev, "missing platform_data\n");
  769. goto err_pdata;
  770. }
  771. if (usb_disabled())
  772. goto err_disabled;
  773. omap = kzalloc(sizeof(*omap), GFP_KERNEL);
  774. if (!omap) {
  775. ret = -ENOMEM;
  776. goto err_disabled;
  777. }
  778. hcd = usb_create_hcd(&ehci_omap_hc_driver, &pdev->dev,
  779. dev_name(&pdev->dev));
  780. if (!hcd) {
  781. dev_err(&pdev->dev, "failed to create hcd with err %d\n", ret);
  782. ret = -ENOMEM;
  783. goto err_create_hcd;
  784. }
  785. platform_set_drvdata(pdev, omap);
  786. omap->dev = &pdev->dev;
  787. omap->phy_reset = pdata->phy_reset;
  788. omap->reset_gpio_port[0] = pdata->reset_gpio_port[0];
  789. omap->reset_gpio_port[1] = pdata->reset_gpio_port[1];
  790. omap->reset_gpio_port[2] = pdata->reset_gpio_port[2];
  791. omap->port_mode[0] = pdata->port_mode[0];
  792. omap->port_mode[1] = pdata->port_mode[1];
  793. omap->port_mode[2] = pdata->port_mode[2];
  794. omap->ehci = hcd_to_ehci(hcd);
  795. omap->ehci->sbrn = 0x20;
  796. res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "ehci");
  797. hcd->rsrc_start = res->start;
  798. hcd->rsrc_len = resource_size(res);
  799. hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
  800. if (!hcd->regs) {
  801. dev_err(&pdev->dev, "EHCI ioremap failed\n");
  802. ret = -ENOMEM;
  803. goto err_ioremap;
  804. }
  805. /* we know this is the memory we want, no need to ioremap again */
  806. omap->ehci->caps = hcd->regs;
  807. omap->ehci_base = hcd->regs;
  808. res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "uhh");
  809. omap->uhh_base = ioremap(res->start, resource_size(res));
  810. if (!omap->uhh_base) {
  811. dev_err(&pdev->dev, "UHH ioremap failed\n");
  812. ret = -ENOMEM;
  813. goto err_uhh_ioremap;
  814. }
  815. res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "tll");
  816. omap->tll_base = ioremap(res->start, resource_size(res));
  817. if (!omap->tll_base) {
  818. dev_err(&pdev->dev, "TLL ioremap failed\n");
  819. ret = -ENOMEM;
  820. goto err_tll_ioremap;
  821. }
  822. /* get ehci regulator and enable */
  823. for (i = 0 ; i < OMAP3_HS_USB_PORTS ; i++) {
  824. if (omap->port_mode[i] != EHCI_HCD_OMAP_MODE_PHY) {
  825. omap->regulator[i] = NULL;
  826. continue;
  827. }
  828. snprintf(supply, sizeof(supply), "hsusb%d", i);
  829. omap->regulator[i] = regulator_get(omap->dev, supply);
  830. if (IS_ERR(omap->regulator[i])) {
  831. omap->regulator[i] = NULL;
  832. dev_dbg(&pdev->dev,
  833. "failed to get ehci port%d regulator\n", i);
  834. } else {
  835. regulator_enable(omap->regulator[i]);
  836. }
  837. }
  838. ret = omap_start_ehc(omap, hcd);
  839. if (ret) {
  840. dev_err(&pdev->dev, "failed to start ehci with err %d\n", ret);
  841. goto err_start;
  842. }
  843. omap->ehci->regs = hcd->regs
  844. + HC_LENGTH(readl(&omap->ehci->caps->hc_capbase));
  845. dbg_hcs_params(omap->ehci, "reset");
  846. dbg_hcc_params(omap->ehci, "reset");
  847. /* cache this readonly data; minimize chip reads */
  848. omap->ehci->hcs_params = readl(&omap->ehci->caps->hcs_params);
  849. ret = usb_add_hcd(hcd, irq, IRQF_DISABLED | IRQF_SHARED);
  850. if (ret) {
  851. dev_err(&pdev->dev, "failed to add hcd with err %d\n", ret);
  852. goto err_add_hcd;
  853. }
  854. /* root ports should always stay powered */
  855. ehci_port_power(omap->ehci, 1);
  856. return 0;
  857. err_add_hcd:
  858. omap_stop_ehc(omap, hcd);
  859. err_start:
  860. for (i = 0 ; i < OMAP3_HS_USB_PORTS ; i++) {
  861. if (omap->regulator[i]) {
  862. regulator_disable(omap->regulator[i]);
  863. regulator_put(omap->regulator[i]);
  864. }
  865. }
  866. iounmap(omap->tll_base);
  867. err_tll_ioremap:
  868. iounmap(omap->uhh_base);
  869. err_uhh_ioremap:
  870. iounmap(hcd->regs);
  871. err_ioremap:
  872. usb_put_hcd(hcd);
  873. err_create_hcd:
  874. kfree(omap);
  875. err_disabled:
  876. err_pdata:
  877. return ret;
  878. }
  879. /* may be called without controller electrically present */
  880. /* may be called with controller, bus, and devices active */
  881. /**
  882. * ehci_hcd_omap_remove - shutdown processing for EHCI HCDs
  883. * @pdev: USB Host Controller being removed
  884. *
  885. * Reverses the effect of usb_ehci_hcd_omap_probe(), first invoking
  886. * the HCD's stop() method. It is always called from a thread
  887. * context, normally "rmmod", "apmd", or something similar.
  888. */
  889. static int ehci_hcd_omap_remove(struct platform_device *pdev)
  890. {
  891. struct ehci_hcd_omap *omap = platform_get_drvdata(pdev);
  892. struct usb_hcd *hcd = ehci_to_hcd(omap->ehci);
  893. int i;
  894. usb_remove_hcd(hcd);
  895. omap_stop_ehc(omap, hcd);
  896. iounmap(hcd->regs);
  897. for (i = 0 ; i < OMAP3_HS_USB_PORTS ; i++) {
  898. if (omap->regulator[i]) {
  899. regulator_disable(omap->regulator[i]);
  900. regulator_put(omap->regulator[i]);
  901. }
  902. }
  903. iounmap(omap->tll_base);
  904. iounmap(omap->uhh_base);
  905. usb_put_hcd(hcd);
  906. kfree(omap);
  907. return 0;
  908. }
  909. static void ehci_hcd_omap_shutdown(struct platform_device *pdev)
  910. {
  911. struct ehci_hcd_omap *omap = platform_get_drvdata(pdev);
  912. struct usb_hcd *hcd = ehci_to_hcd(omap->ehci);
  913. if (hcd->driver->shutdown)
  914. hcd->driver->shutdown(hcd);
  915. }
  916. static struct platform_driver ehci_hcd_omap_driver = {
  917. .probe = ehci_hcd_omap_probe,
  918. .remove = ehci_hcd_omap_remove,
  919. .shutdown = ehci_hcd_omap_shutdown,
  920. /*.suspend = ehci_hcd_omap_suspend, */
  921. /*.resume = ehci_hcd_omap_resume, */
  922. .driver = {
  923. .name = "ehci-omap",
  924. }
  925. };
  926. /*-------------------------------------------------------------------------*/
  927. static const struct hc_driver ehci_omap_hc_driver = {
  928. .description = hcd_name,
  929. .product_desc = "OMAP-EHCI Host Controller",
  930. .hcd_priv_size = sizeof(struct ehci_hcd),
  931. /*
  932. * generic hardware linkage
  933. */
  934. .irq = ehci_irq,
  935. .flags = HCD_MEMORY | HCD_USB2,
  936. /*
  937. * basic lifecycle operations
  938. */
  939. .reset = ehci_init,
  940. .start = ehci_run,
  941. .stop = ehci_stop,
  942. .shutdown = ehci_shutdown,
  943. /*
  944. * managing i/o requests and associated device resources
  945. */
  946. .urb_enqueue = ehci_urb_enqueue,
  947. .urb_dequeue = ehci_urb_dequeue,
  948. .endpoint_disable = ehci_endpoint_disable,
  949. .endpoint_reset = ehci_endpoint_reset,
  950. /*
  951. * scheduling support
  952. */
  953. .get_frame_number = ehci_get_frame,
  954. /*
  955. * root hub support
  956. */
  957. .hub_status_data = ehci_hub_status_data,
  958. .hub_control = ehci_hub_control,
  959. .bus_suspend = ehci_bus_suspend,
  960. .bus_resume = ehci_bus_resume,
  961. .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
  962. };
  963. MODULE_ALIAS("platform:omap-ehci");
  964. MODULE_AUTHOR("Texas Instruments, Inc.");
  965. MODULE_AUTHOR("Felipe Balbi <felipe.balbi@nokia.com>");