ohci-omap3.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735
  1. /*
  2. * ohci-omap3.c - driver for OHCI on OMAP3 and later processors
  3. *
  4. * Bus Glue for OMAP3 USBHOST 3 port OHCI controller
  5. * This controller is also used in later OMAPs and AM35x chips
  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. * Based on ehci-omap.c and some other ohci glue layers
  12. *
  13. * This program is free software; you can redistribute it and/or modify
  14. * it under the terms of the GNU General Public License as published by
  15. * the Free Software Foundation; either version 2 of the License, or
  16. * (at your option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License
  24. * along with this program; if not, write to the Free Software
  25. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  26. *
  27. * TODO (last updated Mar 10th, 2010):
  28. * - add kernel-doc
  29. * - Factor out code common to EHCI to a separate file
  30. * - Make EHCI and OHCI coexist together
  31. * - needs newer silicon versions to actually work
  32. * - the last one to be loaded currently steps on the other's toes
  33. * - Add hooks for configuring transceivers, etc. at init/exit
  34. * - Add aggressive clock-management code
  35. */
  36. #include <linux/platform_device.h>
  37. #include <linux/clk.h>
  38. #include <plat/usb.h>
  39. /*
  40. * OMAP USBHOST Register addresses: VIRTUAL ADDRESSES
  41. * Use ohci_omap_readl()/ohci_omap_writel() functions
  42. */
  43. /* TLL Register Set */
  44. #define OMAP_USBTLL_REVISION (0x00)
  45. #define OMAP_USBTLL_SYSCONFIG (0x10)
  46. #define OMAP_USBTLL_SYSCONFIG_CACTIVITY (1 << 8)
  47. #define OMAP_USBTLL_SYSCONFIG_SIDLEMODE (1 << 3)
  48. #define OMAP_USBTLL_SYSCONFIG_ENAWAKEUP (1 << 2)
  49. #define OMAP_USBTLL_SYSCONFIG_SOFTRESET (1 << 1)
  50. #define OMAP_USBTLL_SYSCONFIG_AUTOIDLE (1 << 0)
  51. #define OMAP_USBTLL_SYSSTATUS (0x14)
  52. #define OMAP_USBTLL_SYSSTATUS_RESETDONE (1 << 0)
  53. #define OMAP_USBTLL_IRQSTATUS (0x18)
  54. #define OMAP_USBTLL_IRQENABLE (0x1C)
  55. #define OMAP_TLL_SHARED_CONF (0x30)
  56. #define OMAP_TLL_SHARED_CONF_USB_90D_DDR_EN (1 << 6)
  57. #define OMAP_TLL_SHARED_CONF_USB_180D_SDR_EN (1 << 5)
  58. #define OMAP_TLL_SHARED_CONF_USB_DIVRATION (1 << 2)
  59. #define OMAP_TLL_SHARED_CONF_FCLK_REQ (1 << 1)
  60. #define OMAP_TLL_SHARED_CONF_FCLK_IS_ON (1 << 0)
  61. #define OMAP_TLL_CHANNEL_CONF(num) (0x040 + 0x004 * num)
  62. #define OMAP_TLL_CHANNEL_CONF_FSLSMODE_SHIFT 24
  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_CHANMODE_FSLS (1 << 1)
  68. #define OMAP_TLL_CHANNEL_CONF_CHANEN (1 << 0)
  69. #define OMAP_TLL_CHANNEL_COUNT 3
  70. /* UHH Register Set */
  71. #define OMAP_UHH_REVISION (0x00)
  72. #define OMAP_UHH_SYSCONFIG (0x10)
  73. #define OMAP_UHH_SYSCONFIG_MIDLEMODE (1 << 12)
  74. #define OMAP_UHH_SYSCONFIG_CACTIVITY (1 << 8)
  75. #define OMAP_UHH_SYSCONFIG_SIDLEMODE (1 << 3)
  76. #define OMAP_UHH_SYSCONFIG_ENAWAKEUP (1 << 2)
  77. #define OMAP_UHH_SYSCONFIG_SOFTRESET (1 << 1)
  78. #define OMAP_UHH_SYSCONFIG_AUTOIDLE (1 << 0)
  79. #define OMAP_UHH_SYSSTATUS (0x14)
  80. #define OMAP_UHH_SYSSTATUS_UHHRESETDONE (1 << 0)
  81. #define OMAP_UHH_SYSSTATUS_OHCIRESETDONE (1 << 1)
  82. #define OMAP_UHH_SYSSTATUS_EHCIRESETDONE (1 << 2)
  83. #define OMAP_UHH_HOSTCONFIG (0x40)
  84. #define OMAP_UHH_HOSTCONFIG_ULPI_BYPASS (1 << 0)
  85. #define OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS (1 << 0)
  86. #define OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS (1 << 11)
  87. #define OMAP_UHH_HOSTCONFIG_ULPI_P3_BYPASS (1 << 12)
  88. #define OMAP_UHH_HOSTCONFIG_INCR4_BURST_EN (1 << 2)
  89. #define OMAP_UHH_HOSTCONFIG_INCR8_BURST_EN (1 << 3)
  90. #define OMAP_UHH_HOSTCONFIG_INCR16_BURST_EN (1 << 4)
  91. #define OMAP_UHH_HOSTCONFIG_INCRX_ALIGN_EN (1 << 5)
  92. #define OMAP_UHH_HOSTCONFIG_P1_CONNECT_STATUS (1 << 8)
  93. #define OMAP_UHH_HOSTCONFIG_P2_CONNECT_STATUS (1 << 9)
  94. #define OMAP_UHH_HOSTCONFIG_P3_CONNECT_STATUS (1 << 10)
  95. #define OMAP_UHH_DEBUG_CSR (0x44)
  96. /*-------------------------------------------------------------------------*/
  97. static inline void ohci_omap_writel(void __iomem *base, u32 reg, u32 val)
  98. {
  99. __raw_writel(val, base + reg);
  100. }
  101. static inline u32 ohci_omap_readl(void __iomem *base, u32 reg)
  102. {
  103. return __raw_readl(base + reg);
  104. }
  105. static inline void ohci_omap_writeb(void __iomem *base, u8 reg, u8 val)
  106. {
  107. __raw_writeb(val, base + reg);
  108. }
  109. static inline u8 ohci_omap_readb(void __iomem *base, u8 reg)
  110. {
  111. return __raw_readb(base + reg);
  112. }
  113. /*-------------------------------------------------------------------------*/
  114. struct ohci_hcd_omap3 {
  115. struct ohci_hcd *ohci;
  116. struct device *dev;
  117. struct clk *usbhost_ick;
  118. struct clk *usbhost2_120m_fck;
  119. struct clk *usbhost1_48m_fck;
  120. struct clk *usbtll_fck;
  121. struct clk *usbtll_ick;
  122. /* port_mode: TLL/PHY, 2/3/4/6-PIN, DP-DM/DAT-SE0 */
  123. enum ohci_omap3_port_mode port_mode[OMAP3_HS_USB_PORTS];
  124. void __iomem *uhh_base;
  125. void __iomem *tll_base;
  126. void __iomem *ohci_base;
  127. unsigned es2_compatibility:1;
  128. };
  129. /*-------------------------------------------------------------------------*/
  130. static void ohci_omap3_clock_power(struct ohci_hcd_omap3 *omap, int on)
  131. {
  132. if (on) {
  133. clk_enable(omap->usbtll_ick);
  134. clk_enable(omap->usbtll_fck);
  135. clk_enable(omap->usbhost_ick);
  136. clk_enable(omap->usbhost1_48m_fck);
  137. clk_enable(omap->usbhost2_120m_fck);
  138. } else {
  139. clk_disable(omap->usbhost2_120m_fck);
  140. clk_disable(omap->usbhost1_48m_fck);
  141. clk_disable(omap->usbhost_ick);
  142. clk_disable(omap->usbtll_fck);
  143. clk_disable(omap->usbtll_ick);
  144. }
  145. }
  146. static int ohci_omap3_init(struct usb_hcd *hcd)
  147. {
  148. dev_dbg(hcd->self.controller, "starting OHCI controller\n");
  149. return ohci_init(hcd_to_ohci(hcd));
  150. }
  151. /*-------------------------------------------------------------------------*/
  152. static int ohci_omap3_start(struct usb_hcd *hcd)
  153. {
  154. struct ohci_hcd *ohci = hcd_to_ohci(hcd);
  155. int ret;
  156. /*
  157. * RemoteWakeupConnected has to be set explicitly before
  158. * calling ohci_run. The reset value of RWC is 0.
  159. */
  160. ohci->hc_control = OHCI_CTRL_RWC;
  161. writel(OHCI_CTRL_RWC, &ohci->regs->control);
  162. ret = ohci_run(ohci);
  163. if (ret < 0) {
  164. dev_err(hcd->self.controller, "can't start\n");
  165. ohci_stop(hcd);
  166. }
  167. return ret;
  168. }
  169. /*-------------------------------------------------------------------------*/
  170. /*
  171. * convert the port-mode enum to a value we can use in the FSLSMODE
  172. * field of USBTLL_CHANNEL_CONF
  173. */
  174. static unsigned ohci_omap3_fslsmode(enum ohci_omap3_port_mode mode)
  175. {
  176. switch (mode) {
  177. case OMAP_OHCI_PORT_MODE_UNUSED:
  178. case OMAP_OHCI_PORT_MODE_PHY_6PIN_DATSE0:
  179. return 0x0;
  180. case OMAP_OHCI_PORT_MODE_PHY_6PIN_DPDM:
  181. return 0x1;
  182. case OMAP_OHCI_PORT_MODE_PHY_3PIN_DATSE0:
  183. return 0x2;
  184. case OMAP_OHCI_PORT_MODE_PHY_4PIN_DPDM:
  185. return 0x3;
  186. case OMAP_OHCI_PORT_MODE_TLL_6PIN_DATSE0:
  187. return 0x4;
  188. case OMAP_OHCI_PORT_MODE_TLL_6PIN_DPDM:
  189. return 0x5;
  190. case OMAP_OHCI_PORT_MODE_TLL_3PIN_DATSE0:
  191. return 0x6;
  192. case OMAP_OHCI_PORT_MODE_TLL_4PIN_DPDM:
  193. return 0x7;
  194. case OMAP_OHCI_PORT_MODE_TLL_2PIN_DATSE0:
  195. return 0xA;
  196. case OMAP_OHCI_PORT_MODE_TLL_2PIN_DPDM:
  197. return 0xB;
  198. default:
  199. pr_warning("Invalid port mode, using default\n");
  200. return 0x0;
  201. }
  202. }
  203. static void ohci_omap3_tll_config(struct ohci_hcd_omap3 *omap)
  204. {
  205. u32 reg;
  206. int i;
  207. /* Program TLL SHARED CONF */
  208. reg = ohci_omap_readl(omap->tll_base, OMAP_TLL_SHARED_CONF);
  209. reg &= ~OMAP_TLL_SHARED_CONF_USB_90D_DDR_EN;
  210. reg &= ~OMAP_TLL_SHARED_CONF_USB_180D_SDR_EN;
  211. reg |= OMAP_TLL_SHARED_CONF_USB_DIVRATION;
  212. reg |= OMAP_TLL_SHARED_CONF_FCLK_IS_ON;
  213. ohci_omap_writel(omap->tll_base, OMAP_TLL_SHARED_CONF, reg);
  214. /* Program each TLL channel */
  215. /*
  216. * REVISIT: Only the 3-pin and 4-pin PHY modes have
  217. * actually been tested.
  218. */
  219. for (i = 0; i < OMAP_TLL_CHANNEL_COUNT; i++) {
  220. /* Enable only those channels that are actually used */
  221. if (omap->port_mode[i] == OMAP_OHCI_PORT_MODE_UNUSED)
  222. continue;
  223. reg = ohci_omap_readl(omap->tll_base, OMAP_TLL_CHANNEL_CONF(i));
  224. reg |= ohci_omap3_fslsmode(omap->port_mode[i])
  225. << OMAP_TLL_CHANNEL_CONF_FSLSMODE_SHIFT;
  226. reg |= OMAP_TLL_CHANNEL_CONF_CHANMODE_FSLS;
  227. reg |= OMAP_TLL_CHANNEL_CONF_CHANEN;
  228. ohci_omap_writel(omap->tll_base, OMAP_TLL_CHANNEL_CONF(i), reg);
  229. }
  230. }
  231. /* omap3_start_ohci
  232. * - Start the TI USBHOST controller
  233. */
  234. static int omap3_start_ohci(struct ohci_hcd_omap3 *omap, struct usb_hcd *hcd)
  235. {
  236. unsigned long timeout = jiffies + msecs_to_jiffies(1000);
  237. u32 reg = 0;
  238. int ret = 0;
  239. dev_dbg(omap->dev, "starting TI OHCI USB Controller\n");
  240. /* Get all the clock handles we need */
  241. omap->usbhost_ick = clk_get(omap->dev, "usbhost_ick");
  242. if (IS_ERR(omap->usbhost_ick)) {
  243. dev_err(omap->dev, "could not get usbhost_ick\n");
  244. ret = PTR_ERR(omap->usbhost_ick);
  245. goto err_host_ick;
  246. }
  247. omap->usbhost2_120m_fck = clk_get(omap->dev, "usbhost_120m_fck");
  248. if (IS_ERR(omap->usbhost2_120m_fck)) {
  249. dev_err(omap->dev, "could not get usbhost_120m_fck\n");
  250. ret = PTR_ERR(omap->usbhost2_120m_fck);
  251. goto err_host_120m_fck;
  252. }
  253. omap->usbhost1_48m_fck = clk_get(omap->dev, "usbhost_48m_fck");
  254. if (IS_ERR(omap->usbhost1_48m_fck)) {
  255. dev_err(omap->dev, "could not get usbhost_48m_fck\n");
  256. ret = PTR_ERR(omap->usbhost1_48m_fck);
  257. goto err_host_48m_fck;
  258. }
  259. omap->usbtll_fck = clk_get(omap->dev, "usbtll_fck");
  260. if (IS_ERR(omap->usbtll_fck)) {
  261. dev_err(omap->dev, "could not get usbtll_fck\n");
  262. ret = PTR_ERR(omap->usbtll_fck);
  263. goto err_tll_fck;
  264. }
  265. omap->usbtll_ick = clk_get(omap->dev, "usbtll_ick");
  266. if (IS_ERR(omap->usbtll_ick)) {
  267. dev_err(omap->dev, "could not get usbtll_ick\n");
  268. ret = PTR_ERR(omap->usbtll_ick);
  269. goto err_tll_ick;
  270. }
  271. /* Now enable all the clocks in the correct order */
  272. ohci_omap3_clock_power(omap, 1);
  273. /* perform TLL soft reset, and wait until reset is complete */
  274. ohci_omap_writel(omap->tll_base, OMAP_USBTLL_SYSCONFIG,
  275. OMAP_USBTLL_SYSCONFIG_SOFTRESET);
  276. /* Wait for TLL reset to complete */
  277. while (!(ohci_omap_readl(omap->tll_base, OMAP_USBTLL_SYSSTATUS)
  278. & OMAP_USBTLL_SYSSTATUS_RESETDONE)) {
  279. cpu_relax();
  280. if (time_after(jiffies, timeout)) {
  281. dev_dbg(omap->dev, "operation timed out\n");
  282. ret = -EINVAL;
  283. goto err_sys_status;
  284. }
  285. }
  286. dev_dbg(omap->dev, "TLL reset done\n");
  287. /* (1<<3) = no idle mode only for initial debugging */
  288. ohci_omap_writel(omap->tll_base, OMAP_USBTLL_SYSCONFIG,
  289. OMAP_USBTLL_SYSCONFIG_ENAWAKEUP |
  290. OMAP_USBTLL_SYSCONFIG_SIDLEMODE |
  291. OMAP_USBTLL_SYSCONFIG_CACTIVITY);
  292. /* Put UHH in NoIdle/NoStandby mode */
  293. reg = ohci_omap_readl(omap->uhh_base, OMAP_UHH_SYSCONFIG);
  294. reg |= (OMAP_UHH_SYSCONFIG_ENAWAKEUP
  295. | OMAP_UHH_SYSCONFIG_SIDLEMODE
  296. | OMAP_UHH_SYSCONFIG_CACTIVITY
  297. | OMAP_UHH_SYSCONFIG_MIDLEMODE);
  298. reg &= ~OMAP_UHH_SYSCONFIG_AUTOIDLE;
  299. reg &= ~OMAP_UHH_SYSCONFIG_SOFTRESET;
  300. ohci_omap_writel(omap->uhh_base, OMAP_UHH_SYSCONFIG, reg);
  301. reg = ohci_omap_readl(omap->uhh_base, OMAP_UHH_HOSTCONFIG);
  302. /* setup ULPI bypass and burst configurations */
  303. reg |= (OMAP_UHH_HOSTCONFIG_INCR4_BURST_EN
  304. | OMAP_UHH_HOSTCONFIG_INCR8_BURST_EN
  305. | OMAP_UHH_HOSTCONFIG_INCR16_BURST_EN);
  306. reg &= ~OMAP_UHH_HOSTCONFIG_INCRX_ALIGN_EN;
  307. /*
  308. * REVISIT: Pi_CONNECT_STATUS controls MStandby
  309. * assertion and Swakeup generation - let us not
  310. * worry about this for now. OMAP HWMOD framework
  311. * might take care of this later. If not, we can
  312. * update these registers when adding aggressive
  313. * clock management code.
  314. *
  315. * For now, turn off all the Pi_CONNECT_STATUS bits
  316. *
  317. if (omap->port_mode[0] == OMAP_OHCI_PORT_MODE_UNUSED)
  318. reg &= ~OMAP_UHH_HOSTCONFIG_P1_CONNECT_STATUS;
  319. if (omap->port_mode[1] == OMAP_OHCI_PORT_MODE_UNUSED)
  320. reg &= ~OMAP_UHH_HOSTCONFIG_P2_CONNECT_STATUS;
  321. if (omap->port_mode[2] == OMAP_OHCI_PORT_MODE_UNUSED)
  322. reg &= ~OMAP_UHH_HOSTCONFIG_P3_CONNECT_STATUS;
  323. */
  324. reg &= ~OMAP_UHH_HOSTCONFIG_P1_CONNECT_STATUS;
  325. reg &= ~OMAP_UHH_HOSTCONFIG_P2_CONNECT_STATUS;
  326. reg &= ~OMAP_UHH_HOSTCONFIG_P3_CONNECT_STATUS;
  327. if (omap->es2_compatibility) {
  328. /*
  329. * All OHCI modes need to go through the TLL,
  330. * unlike in the EHCI case. So use UTMI mode
  331. * for all ports for OHCI, on ES2.x silicon
  332. */
  333. dev_dbg(omap->dev, "OMAP3 ES version <= ES2.1\n");
  334. reg |= OMAP_UHH_HOSTCONFIG_ULPI_BYPASS;
  335. } else {
  336. dev_dbg(omap->dev, "OMAP3 ES version > ES2.1\n");
  337. if (omap->port_mode[0] == OMAP_OHCI_PORT_MODE_UNUSED)
  338. reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS;
  339. else
  340. reg |= OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS;
  341. if (omap->port_mode[1] == OMAP_OHCI_PORT_MODE_UNUSED)
  342. reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS;
  343. else
  344. reg |= OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS;
  345. if (omap->port_mode[2] == OMAP_OHCI_PORT_MODE_UNUSED)
  346. reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_P3_BYPASS;
  347. else
  348. reg |= OMAP_UHH_HOSTCONFIG_ULPI_P3_BYPASS;
  349. }
  350. ohci_omap_writel(omap->uhh_base, OMAP_UHH_HOSTCONFIG, reg);
  351. dev_dbg(omap->dev, "UHH setup done, uhh_hostconfig=%x\n", reg);
  352. ohci_omap3_tll_config(omap);
  353. return 0;
  354. err_sys_status:
  355. ohci_omap3_clock_power(omap, 0);
  356. clk_put(omap->usbtll_ick);
  357. err_tll_ick:
  358. clk_put(omap->usbtll_fck);
  359. err_tll_fck:
  360. clk_put(omap->usbhost1_48m_fck);
  361. err_host_48m_fck:
  362. clk_put(omap->usbhost2_120m_fck);
  363. err_host_120m_fck:
  364. clk_put(omap->usbhost_ick);
  365. err_host_ick:
  366. return ret;
  367. }
  368. static void omap3_stop_ohci(struct ohci_hcd_omap3 *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 USBHOST for insmod/rmmod to work */
  373. ohci_omap_writel(omap->uhh_base, OMAP_UHH_SYSCONFIG,
  374. OMAP_UHH_SYSCONFIG_SOFTRESET);
  375. while (!(ohci_omap_readl(omap->uhh_base, OMAP_UHH_SYSSTATUS)
  376. & OMAP_UHH_SYSSTATUS_UHHRESETDONE)) {
  377. cpu_relax();
  378. if (time_after(jiffies, timeout))
  379. dev_dbg(omap->dev, "operation timed out\n");
  380. }
  381. while (!(ohci_omap_readl(omap->uhh_base, OMAP_UHH_SYSSTATUS)
  382. & OMAP_UHH_SYSSTATUS_OHCIRESETDONE)) {
  383. cpu_relax();
  384. if (time_after(jiffies, timeout))
  385. dev_dbg(omap->dev, "operation timed out\n");
  386. }
  387. while (!(ohci_omap_readl(omap->uhh_base, OMAP_UHH_SYSSTATUS)
  388. & OMAP_UHH_SYSSTATUS_EHCIRESETDONE)) {
  389. cpu_relax();
  390. if (time_after(jiffies, timeout))
  391. dev_dbg(omap->dev, "operation timed out\n");
  392. }
  393. ohci_omap_writel(omap->tll_base, OMAP_USBTLL_SYSCONFIG, (1 << 1));
  394. while (!(ohci_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. ohci_omap3_clock_power(omap, 0);
  401. if (omap->usbtll_fck != NULL) {
  402. clk_put(omap->usbtll_fck);
  403. omap->usbtll_fck = NULL;
  404. }
  405. if (omap->usbhost_ick != NULL) {
  406. clk_put(omap->usbhost_ick);
  407. omap->usbhost_ick = NULL;
  408. }
  409. if (omap->usbhost1_48m_fck != NULL) {
  410. clk_put(omap->usbhost1_48m_fck);
  411. omap->usbhost1_48m_fck = NULL;
  412. }
  413. if (omap->usbhost2_120m_fck != NULL) {
  414. clk_put(omap->usbhost2_120m_fck);
  415. omap->usbhost2_120m_fck = NULL;
  416. }
  417. if (omap->usbtll_ick != NULL) {
  418. clk_put(omap->usbtll_ick);
  419. omap->usbtll_ick = NULL;
  420. }
  421. dev_dbg(omap->dev, "Clock to USB host has been disabled\n");
  422. }
  423. /*-------------------------------------------------------------------------*/
  424. static const struct hc_driver ohci_omap3_hc_driver = {
  425. .description = hcd_name,
  426. .product_desc = "OMAP3 OHCI Host Controller",
  427. .hcd_priv_size = sizeof(struct ohci_hcd),
  428. /*
  429. * generic hardware linkage
  430. */
  431. .irq = ohci_irq,
  432. .flags = HCD_USB11 | HCD_MEMORY,
  433. /*
  434. * basic lifecycle operations
  435. */
  436. .reset = ohci_omap3_init,
  437. .start = ohci_omap3_start,
  438. .stop = ohci_stop,
  439. .shutdown = ohci_shutdown,
  440. /*
  441. * managing i/o requests and associated device resources
  442. */
  443. .urb_enqueue = ohci_urb_enqueue,
  444. .urb_dequeue = ohci_urb_dequeue,
  445. .endpoint_disable = ohci_endpoint_disable,
  446. /*
  447. * scheduling support
  448. */
  449. .get_frame_number = ohci_get_frame,
  450. /*
  451. * root hub support
  452. */
  453. .hub_status_data = ohci_hub_status_data,
  454. .hub_control = ohci_hub_control,
  455. #ifdef CONFIG_PM
  456. .bus_suspend = ohci_bus_suspend,
  457. .bus_resume = ohci_bus_resume,
  458. #endif
  459. .start_port_reset = ohci_start_port_reset,
  460. };
  461. /*-------------------------------------------------------------------------*/
  462. /*
  463. * configure so an HC device and id are always provided
  464. * always called with process context; sleeping is OK
  465. */
  466. /**
  467. * ohci_hcd_omap3_probe - initialize OMAP-based HCDs
  468. *
  469. * Allocates basic resources for this USB host controller, and
  470. * then invokes the start() method for the HCD associated with it
  471. * through the hotplug entry's driver_data.
  472. */
  473. static int __devinit ohci_hcd_omap3_probe(struct platform_device *pdev)
  474. {
  475. struct ohci_hcd_omap_platform_data *pdata = pdev->dev.platform_data;
  476. struct ohci_hcd_omap3 *omap;
  477. struct resource *res;
  478. struct usb_hcd *hcd;
  479. int ret = -ENODEV;
  480. int irq;
  481. if (usb_disabled())
  482. goto err_disabled;
  483. if (!pdata) {
  484. dev_dbg(&pdev->dev, "missing platform_data\n");
  485. goto err_pdata;
  486. }
  487. irq = platform_get_irq(pdev, 0);
  488. omap = kzalloc(sizeof(*omap), GFP_KERNEL);
  489. if (!omap) {
  490. ret = -ENOMEM;
  491. goto err_disabled;
  492. }
  493. hcd = usb_create_hcd(&ohci_omap3_hc_driver, &pdev->dev,
  494. dev_name(&pdev->dev));
  495. if (!hcd) {
  496. ret = -ENOMEM;
  497. goto err_create_hcd;
  498. }
  499. platform_set_drvdata(pdev, omap);
  500. omap->dev = &pdev->dev;
  501. omap->port_mode[0] = pdata->port_mode[0];
  502. omap->port_mode[1] = pdata->port_mode[1];
  503. omap->port_mode[2] = pdata->port_mode[2];
  504. omap->es2_compatibility = pdata->es2_compatibility;
  505. omap->ohci = hcd_to_ohci(hcd);
  506. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  507. hcd->rsrc_start = res->start;
  508. hcd->rsrc_len = resource_size(res);
  509. hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
  510. if (!hcd->regs) {
  511. dev_err(&pdev->dev, "OHCI ioremap failed\n");
  512. ret = -ENOMEM;
  513. goto err_ioremap;
  514. }
  515. res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
  516. omap->uhh_base = ioremap(res->start, resource_size(res));
  517. if (!omap->uhh_base) {
  518. dev_err(&pdev->dev, "UHH ioremap failed\n");
  519. ret = -ENOMEM;
  520. goto err_uhh_ioremap;
  521. }
  522. res = platform_get_resource(pdev, IORESOURCE_MEM, 2);
  523. omap->tll_base = ioremap(res->start, resource_size(res));
  524. if (!omap->tll_base) {
  525. dev_err(&pdev->dev, "TLL ioremap failed\n");
  526. ret = -ENOMEM;
  527. goto err_tll_ioremap;
  528. }
  529. ret = omap3_start_ohci(omap, hcd);
  530. if (ret) {
  531. dev_dbg(&pdev->dev, "failed to start ohci\n");
  532. goto err_start;
  533. }
  534. ohci_hcd_init(omap->ohci);
  535. ret = usb_add_hcd(hcd, irq, IRQF_DISABLED);
  536. if (ret) {
  537. dev_dbg(&pdev->dev, "failed to add hcd with err %d\n", ret);
  538. goto err_add_hcd;
  539. }
  540. return 0;
  541. err_add_hcd:
  542. omap3_stop_ohci(omap, hcd);
  543. err_start:
  544. iounmap(omap->tll_base);
  545. err_tll_ioremap:
  546. iounmap(omap->uhh_base);
  547. err_uhh_ioremap:
  548. iounmap(hcd->regs);
  549. err_ioremap:
  550. usb_put_hcd(hcd);
  551. err_create_hcd:
  552. kfree(omap);
  553. err_pdata:
  554. err_disabled:
  555. return ret;
  556. }
  557. /*
  558. * may be called without controller electrically present
  559. * may be called with controller, bus, and devices active
  560. */
  561. /**
  562. * ohci_hcd_omap3_remove - shutdown processing for OHCI HCDs
  563. * @pdev: USB Host Controller being removed
  564. *
  565. * Reverses the effect of ohci_hcd_omap3_probe(), first invoking
  566. * the HCD's stop() method. It is always called from a thread
  567. * context, normally "rmmod", "apmd", or something similar.
  568. */
  569. static int __devexit ohci_hcd_omap3_remove(struct platform_device *pdev)
  570. {
  571. struct ohci_hcd_omap3 *omap = platform_get_drvdata(pdev);
  572. struct usb_hcd *hcd = ohci_to_hcd(omap->ohci);
  573. usb_remove_hcd(hcd);
  574. omap3_stop_ohci(omap, hcd);
  575. iounmap(hcd->regs);
  576. iounmap(omap->tll_base);
  577. iounmap(omap->uhh_base);
  578. usb_put_hcd(hcd);
  579. kfree(omap);
  580. return 0;
  581. }
  582. static void ohci_hcd_omap3_shutdown(struct platform_device *pdev)
  583. {
  584. struct ohci_hcd_omap3 *omap = platform_get_drvdata(pdev);
  585. struct usb_hcd *hcd = ohci_to_hcd(omap->ohci);
  586. if (hcd->driver->shutdown)
  587. hcd->driver->shutdown(hcd);
  588. }
  589. static struct platform_driver ohci_hcd_omap3_driver = {
  590. .probe = ohci_hcd_omap3_probe,
  591. .remove = __devexit_p(ohci_hcd_omap3_remove),
  592. .shutdown = ohci_hcd_omap3_shutdown,
  593. .driver = {
  594. .name = "ohci-omap3",
  595. },
  596. };
  597. MODULE_ALIAS("platform:ohci-omap3");
  598. MODULE_AUTHOR("Anand Gadiyar <gadiyar@ti.com>");