omap2430.c 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. /*
  2. * Copyright (C) 2005-2007 by Texas Instruments
  3. * Some code has been taken from tusb6010.c
  4. * Copyrights for that are attributable to:
  5. * Copyright (C) 2006 Nokia Corporation
  6. * Tony Lindgren <tony@atomide.com>
  7. *
  8. * This file is part of the Inventra Controller Driver for Linux.
  9. *
  10. * The Inventra Controller Driver for Linux is free software; you
  11. * can redistribute it and/or modify it under the terms of the GNU
  12. * General Public License version 2 as published by the Free Software
  13. * Foundation.
  14. *
  15. * The Inventra Controller Driver for Linux is distributed in
  16. * the hope that it will be useful, but WITHOUT ANY WARRANTY;
  17. * without even the implied warranty of MERCHANTABILITY or
  18. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
  19. * License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with The Inventra Controller Driver for Linux ; if not,
  23. * write to the Free Software Foundation, Inc., 59 Temple Place,
  24. * Suite 330, Boston, MA 02111-1307 USA
  25. *
  26. */
  27. #include <linux/module.h>
  28. #include <linux/kernel.h>
  29. #include <linux/sched.h>
  30. #include <linux/init.h>
  31. #include <linux/list.h>
  32. #include <linux/clk.h>
  33. #include <linux/io.h>
  34. #include <asm/mach-types.h>
  35. #include <mach/hardware.h>
  36. #include <plat/mux.h>
  37. #include "musb_core.h"
  38. #include "omap2430.h"
  39. #ifdef CONFIG_ARCH_OMAP3430
  40. #define get_cpu_rev() 2
  41. #endif
  42. static struct timer_list musb_idle_timer;
  43. static void musb_do_idle(unsigned long _musb)
  44. {
  45. struct musb *musb = (void *)_musb;
  46. unsigned long flags;
  47. #ifdef CONFIG_USB_MUSB_HDRC_HCD
  48. u8 power;
  49. #endif
  50. u8 devctl;
  51. spin_lock_irqsave(&musb->lock, flags);
  52. devctl = musb_readb(musb->mregs, MUSB_DEVCTL);
  53. switch (musb->xceiv->state) {
  54. case OTG_STATE_A_WAIT_BCON:
  55. devctl &= ~MUSB_DEVCTL_SESSION;
  56. musb_writeb(musb->mregs, MUSB_DEVCTL, devctl);
  57. devctl = musb_readb(musb->mregs, MUSB_DEVCTL);
  58. if (devctl & MUSB_DEVCTL_BDEVICE) {
  59. musb->xceiv->state = OTG_STATE_B_IDLE;
  60. MUSB_DEV_MODE(musb);
  61. } else {
  62. musb->xceiv->state = OTG_STATE_A_IDLE;
  63. MUSB_HST_MODE(musb);
  64. }
  65. break;
  66. #ifdef CONFIG_USB_MUSB_HDRC_HCD
  67. case OTG_STATE_A_SUSPEND:
  68. /* finish RESUME signaling? */
  69. if (musb->port1_status & MUSB_PORT_STAT_RESUME) {
  70. power = musb_readb(musb->mregs, MUSB_POWER);
  71. power &= ~MUSB_POWER_RESUME;
  72. DBG(1, "root port resume stopped, power %02x\n", power);
  73. musb_writeb(musb->mregs, MUSB_POWER, power);
  74. musb->is_active = 1;
  75. musb->port1_status &= ~(USB_PORT_STAT_SUSPEND
  76. | MUSB_PORT_STAT_RESUME);
  77. musb->port1_status |= USB_PORT_STAT_C_SUSPEND << 16;
  78. usb_hcd_poll_rh_status(musb_to_hcd(musb));
  79. /* NOTE: it might really be A_WAIT_BCON ... */
  80. musb->xceiv->state = OTG_STATE_A_HOST;
  81. }
  82. break;
  83. #endif
  84. #ifdef CONFIG_USB_MUSB_HDRC_HCD
  85. case OTG_STATE_A_HOST:
  86. devctl = musb_readb(musb->mregs, MUSB_DEVCTL);
  87. if (devctl & MUSB_DEVCTL_BDEVICE)
  88. musb->xceiv->state = OTG_STATE_B_IDLE;
  89. else
  90. musb->xceiv->state = OTG_STATE_A_WAIT_BCON;
  91. #endif
  92. default:
  93. break;
  94. }
  95. spin_unlock_irqrestore(&musb->lock, flags);
  96. }
  97. void musb_platform_try_idle(struct musb *musb, unsigned long timeout)
  98. {
  99. unsigned long default_timeout = jiffies + msecs_to_jiffies(3);
  100. static unsigned long last_timer;
  101. if (timeout == 0)
  102. timeout = default_timeout;
  103. /* Never idle if active, or when VBUS timeout is not set as host */
  104. if (musb->is_active || ((musb->a_wait_bcon == 0)
  105. && (musb->xceiv->state == OTG_STATE_A_WAIT_BCON))) {
  106. DBG(4, "%s active, deleting timer\n", otg_state_string(musb));
  107. del_timer(&musb_idle_timer);
  108. last_timer = jiffies;
  109. return;
  110. }
  111. if (time_after(last_timer, timeout)) {
  112. if (!timer_pending(&musb_idle_timer))
  113. last_timer = timeout;
  114. else {
  115. DBG(4, "Longer idle timer already pending, ignoring\n");
  116. return;
  117. }
  118. }
  119. last_timer = timeout;
  120. DBG(4, "%s inactive, for idle timer for %lu ms\n",
  121. otg_state_string(musb),
  122. (unsigned long)jiffies_to_msecs(timeout - jiffies));
  123. mod_timer(&musb_idle_timer, timeout);
  124. }
  125. void musb_platform_enable(struct musb *musb)
  126. {
  127. }
  128. void musb_platform_disable(struct musb *musb)
  129. {
  130. }
  131. static void omap_set_vbus(struct musb *musb, int is_on)
  132. {
  133. u8 devctl;
  134. /* HDRC controls CPEN, but beware current surges during device
  135. * connect. They can trigger transient overcurrent conditions
  136. * that must be ignored.
  137. */
  138. devctl = musb_readb(musb->mregs, MUSB_DEVCTL);
  139. if (is_on) {
  140. musb->is_active = 1;
  141. musb->xceiv->default_a = 1;
  142. musb->xceiv->state = OTG_STATE_A_WAIT_VRISE;
  143. devctl |= MUSB_DEVCTL_SESSION;
  144. MUSB_HST_MODE(musb);
  145. } else {
  146. musb->is_active = 0;
  147. /* NOTE: we're skipping A_WAIT_VFALL -> A_IDLE and
  148. * jumping right to B_IDLE...
  149. */
  150. musb->xceiv->default_a = 0;
  151. musb->xceiv->state = OTG_STATE_B_IDLE;
  152. devctl &= ~MUSB_DEVCTL_SESSION;
  153. MUSB_DEV_MODE(musb);
  154. }
  155. musb_writeb(musb->mregs, MUSB_DEVCTL, devctl);
  156. DBG(1, "VBUS %s, devctl %02x "
  157. /* otg %3x conf %08x prcm %08x */ "\n",
  158. otg_state_string(musb),
  159. musb_readb(musb->mregs, MUSB_DEVCTL));
  160. }
  161. static int musb_platform_resume(struct musb *musb);
  162. int musb_platform_set_mode(struct musb *musb, u8 musb_mode)
  163. {
  164. u8 devctl = musb_readb(musb->mregs, MUSB_DEVCTL);
  165. devctl |= MUSB_DEVCTL_SESSION;
  166. musb_writeb(musb->mregs, MUSB_DEVCTL, devctl);
  167. return 0;
  168. }
  169. int __init musb_platform_init(struct musb *musb, void *board_data)
  170. {
  171. u32 l;
  172. struct omap_musb_board_data *data = board_data;
  173. #if defined(CONFIG_ARCH_OMAP2430)
  174. omap_cfg_reg(AE5_2430_USB0HS_STP);
  175. #endif
  176. /* We require some kind of external transceiver, hooked
  177. * up through ULPI. TWL4030-family PMICs include one,
  178. * which needs a driver, drivers aren't always needed.
  179. */
  180. musb->xceiv = otg_get_transceiver();
  181. if (!musb->xceiv) {
  182. pr_err("HS USB OTG: no transceiver configured\n");
  183. return -ENODEV;
  184. }
  185. musb_platform_resume(musb);
  186. l = musb_readl(musb->mregs, OTG_SYSCONFIG);
  187. l &= ~ENABLEWAKEUP; /* disable wakeup */
  188. l &= ~NOSTDBY; /* remove possible nostdby */
  189. l |= SMARTSTDBY; /* enable smart standby */
  190. l &= ~AUTOIDLE; /* disable auto idle */
  191. l &= ~NOIDLE; /* remove possible noidle */
  192. l |= SMARTIDLE; /* enable smart idle */
  193. /*
  194. * MUSB AUTOIDLE don't work in 3430.
  195. * Workaround by Richard Woodruff/TI
  196. */
  197. if (!cpu_is_omap3430())
  198. l |= AUTOIDLE; /* enable auto idle */
  199. musb_writel(musb->mregs, OTG_SYSCONFIG, l);
  200. l = musb_readl(musb->mregs, OTG_INTERFSEL);
  201. if (data->interface_type == MUSB_INTERFACE_UTMI) {
  202. /* OMAP4 uses Internal PHY GS70 which uses UTMI interface */
  203. l &= ~ULPI_12PIN; /* Disable ULPI */
  204. l |= UTMI_8BIT; /* Enable UTMI */
  205. } else {
  206. l |= ULPI_12PIN;
  207. }
  208. musb_writel(musb->mregs, OTG_INTERFSEL, l);
  209. pr_debug("HS USB OTG: revision 0x%x, sysconfig 0x%02x, "
  210. "sysstatus 0x%x, intrfsel 0x%x, simenable 0x%x\n",
  211. musb_readl(musb->mregs, OTG_REVISION),
  212. musb_readl(musb->mregs, OTG_SYSCONFIG),
  213. musb_readl(musb->mregs, OTG_SYSSTATUS),
  214. musb_readl(musb->mregs, OTG_INTERFSEL),
  215. musb_readl(musb->mregs, OTG_SIMENABLE));
  216. if (is_host_enabled(musb))
  217. musb->board_set_vbus = omap_set_vbus;
  218. setup_timer(&musb_idle_timer, musb_do_idle, (unsigned long) musb);
  219. return 0;
  220. }
  221. #ifdef CONFIG_PM
  222. void musb_platform_save_context(struct musb *musb,
  223. struct musb_context_registers *musb_context)
  224. {
  225. musb_context->otg_sysconfig = musb_readl(musb->mregs, OTG_SYSCONFIG);
  226. musb_context->otg_forcestandby = musb_readl(musb->mregs, OTG_FORCESTDBY);
  227. }
  228. void musb_platform_restore_context(struct musb *musb,
  229. struct musb_context_registers *musb_context)
  230. {
  231. musb_writel(musb->mregs, OTG_SYSCONFIG, musb_context->otg_sysconfig);
  232. musb_writel(musb->mregs, OTG_FORCESTDBY, musb_context->otg_forcestandby);
  233. }
  234. #endif
  235. static int musb_platform_suspend(struct musb *musb)
  236. {
  237. u32 l;
  238. if (!musb->clock)
  239. return 0;
  240. /* in any role */
  241. l = musb_readl(musb->mregs, OTG_FORCESTDBY);
  242. l |= ENABLEFORCE; /* enable MSTANDBY */
  243. musb_writel(musb->mregs, OTG_FORCESTDBY, l);
  244. l = musb_readl(musb->mregs, OTG_SYSCONFIG);
  245. l |= ENABLEWAKEUP; /* enable wakeup */
  246. musb_writel(musb->mregs, OTG_SYSCONFIG, l);
  247. otg_set_suspend(musb->xceiv, 1);
  248. if (musb->set_clock)
  249. musb->set_clock(musb->clock, 0);
  250. else
  251. clk_disable(musb->clock);
  252. return 0;
  253. }
  254. static int musb_platform_resume(struct musb *musb)
  255. {
  256. u32 l;
  257. if (!musb->clock)
  258. return 0;
  259. otg_set_suspend(musb->xceiv, 0);
  260. if (musb->set_clock)
  261. musb->set_clock(musb->clock, 1);
  262. else
  263. clk_enable(musb->clock);
  264. l = musb_readl(musb->mregs, OTG_SYSCONFIG);
  265. l &= ~ENABLEWAKEUP; /* disable wakeup */
  266. musb_writel(musb->mregs, OTG_SYSCONFIG, l);
  267. l = musb_readl(musb->mregs, OTG_FORCESTDBY);
  268. l &= ~ENABLEFORCE; /* disable MSTANDBY */
  269. musb_writel(musb->mregs, OTG_FORCESTDBY, l);
  270. return 0;
  271. }
  272. int musb_platform_exit(struct musb *musb)
  273. {
  274. musb_platform_suspend(musb);
  275. return 0;
  276. }