tusb6010.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171
  1. /*
  2. * TUSB6010 USB 2.0 OTG Dual Role controller
  3. *
  4. * Copyright (C) 2006 Nokia Corporation
  5. * Tony Lindgren <tony@atomide.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. *
  11. * Notes:
  12. * - Driver assumes that interface to external host (main CPU) is
  13. * configured for NOR FLASH interface instead of VLYNQ serial
  14. * interface.
  15. */
  16. #include <linux/module.h>
  17. #include <linux/kernel.h>
  18. #include <linux/errno.h>
  19. #include <linux/init.h>
  20. #include <linux/usb.h>
  21. #include <linux/irq.h>
  22. #include <linux/platform_device.h>
  23. #include "musb_core.h"
  24. static void tusb_source_power(struct musb *musb, int is_on);
  25. #define TUSB_REV_MAJOR(reg_val) ((reg_val >> 4) & 0xf)
  26. #define TUSB_REV_MINOR(reg_val) (reg_val & 0xf)
  27. /*
  28. * Checks the revision. We need to use the DMA register as 3.0 does not
  29. * have correct versions for TUSB_PRCM_REV or TUSB_INT_CTRL_REV.
  30. */
  31. u8 tusb_get_revision(struct musb *musb)
  32. {
  33. void __iomem *tbase = musb->ctrl_base;
  34. u32 die_id;
  35. u8 rev;
  36. rev = musb_readl(tbase, TUSB_DMA_CTRL_REV) & 0xff;
  37. if (TUSB_REV_MAJOR(rev) == 3) {
  38. die_id = TUSB_DIDR1_HI_CHIP_REV(musb_readl(tbase,
  39. TUSB_DIDR1_HI));
  40. if (die_id >= TUSB_DIDR1_HI_REV_31)
  41. rev |= 1;
  42. }
  43. return rev;
  44. }
  45. static int __init tusb_print_revision(struct musb *musb)
  46. {
  47. void __iomem *tbase = musb->ctrl_base;
  48. u8 rev;
  49. rev = tusb_get_revision(musb);
  50. pr_info("tusb: %s%i.%i %s%i.%i %s%i.%i %s%i.%i %s%i %s%i.%i\n",
  51. "prcm",
  52. TUSB_REV_MAJOR(musb_readl(tbase, TUSB_PRCM_REV)),
  53. TUSB_REV_MINOR(musb_readl(tbase, TUSB_PRCM_REV)),
  54. "int",
  55. TUSB_REV_MAJOR(musb_readl(tbase, TUSB_INT_CTRL_REV)),
  56. TUSB_REV_MINOR(musb_readl(tbase, TUSB_INT_CTRL_REV)),
  57. "gpio",
  58. TUSB_REV_MAJOR(musb_readl(tbase, TUSB_GPIO_REV)),
  59. TUSB_REV_MINOR(musb_readl(tbase, TUSB_GPIO_REV)),
  60. "dma",
  61. TUSB_REV_MAJOR(musb_readl(tbase, TUSB_DMA_CTRL_REV)),
  62. TUSB_REV_MINOR(musb_readl(tbase, TUSB_DMA_CTRL_REV)),
  63. "dieid",
  64. TUSB_DIDR1_HI_CHIP_REV(musb_readl(tbase, TUSB_DIDR1_HI)),
  65. "rev",
  66. TUSB_REV_MAJOR(rev), TUSB_REV_MINOR(rev));
  67. return tusb_get_revision(musb);
  68. }
  69. #define WBUS_QUIRK_MASK (TUSB_PHY_OTG_CTRL_TESTM2 | TUSB_PHY_OTG_CTRL_TESTM1 \
  70. | TUSB_PHY_OTG_CTRL_TESTM0)
  71. /*
  72. * Workaround for spontaneous WBUS wake-up issue #2 for tusb3.0.
  73. * Disables power detection in PHY for the duration of idle.
  74. */
  75. static void tusb_wbus_quirk(struct musb *musb, int enabled)
  76. {
  77. void __iomem *tbase = musb->ctrl_base;
  78. static u32 phy_otg_ctrl, phy_otg_ena;
  79. u32 tmp;
  80. if (enabled) {
  81. phy_otg_ctrl = musb_readl(tbase, TUSB_PHY_OTG_CTRL);
  82. phy_otg_ena = musb_readl(tbase, TUSB_PHY_OTG_CTRL_ENABLE);
  83. tmp = TUSB_PHY_OTG_CTRL_WRPROTECT
  84. | phy_otg_ena | WBUS_QUIRK_MASK;
  85. musb_writel(tbase, TUSB_PHY_OTG_CTRL, tmp);
  86. tmp = phy_otg_ena & ~WBUS_QUIRK_MASK;
  87. tmp |= TUSB_PHY_OTG_CTRL_WRPROTECT | TUSB_PHY_OTG_CTRL_TESTM2;
  88. musb_writel(tbase, TUSB_PHY_OTG_CTRL_ENABLE, tmp);
  89. DBG(2, "Enabled tusb wbus quirk ctrl %08x ena %08x\n",
  90. musb_readl(tbase, TUSB_PHY_OTG_CTRL),
  91. musb_readl(tbase, TUSB_PHY_OTG_CTRL_ENABLE));
  92. } else if (musb_readl(tbase, TUSB_PHY_OTG_CTRL_ENABLE)
  93. & TUSB_PHY_OTG_CTRL_TESTM2) {
  94. tmp = TUSB_PHY_OTG_CTRL_WRPROTECT | phy_otg_ctrl;
  95. musb_writel(tbase, TUSB_PHY_OTG_CTRL, tmp);
  96. tmp = TUSB_PHY_OTG_CTRL_WRPROTECT | phy_otg_ena;
  97. musb_writel(tbase, TUSB_PHY_OTG_CTRL_ENABLE, tmp);
  98. DBG(2, "Disabled tusb wbus quirk ctrl %08x ena %08x\n",
  99. musb_readl(tbase, TUSB_PHY_OTG_CTRL),
  100. musb_readl(tbase, TUSB_PHY_OTG_CTRL_ENABLE));
  101. phy_otg_ctrl = 0;
  102. phy_otg_ena = 0;
  103. }
  104. }
  105. /*
  106. * TUSB 6010 may use a parallel bus that doesn't support byte ops;
  107. * so both loading and unloading FIFOs need explicit byte counts.
  108. */
  109. static inline void
  110. tusb_fifo_write_unaligned(void __iomem *fifo, const u8 *buf, u16 len)
  111. {
  112. u32 val;
  113. int i;
  114. if (len > 4) {
  115. for (i = 0; i < (len >> 2); i++) {
  116. memcpy(&val, buf, 4);
  117. musb_writel(fifo, 0, val);
  118. buf += 4;
  119. }
  120. len %= 4;
  121. }
  122. if (len > 0) {
  123. /* Write the rest 1 - 3 bytes to FIFO */
  124. memcpy(&val, buf, len);
  125. musb_writel(fifo, 0, val);
  126. }
  127. }
  128. static inline void tusb_fifo_read_unaligned(void __iomem *fifo,
  129. void __iomem *buf, u16 len)
  130. {
  131. u32 val;
  132. int i;
  133. if (len > 4) {
  134. for (i = 0; i < (len >> 2); i++) {
  135. val = musb_readl(fifo, 0);
  136. memcpy(buf, &val, 4);
  137. buf += 4;
  138. }
  139. len %= 4;
  140. }
  141. if (len > 0) {
  142. /* Read the rest 1 - 3 bytes from FIFO */
  143. val = musb_readl(fifo, 0);
  144. memcpy(buf, &val, len);
  145. }
  146. }
  147. void musb_write_fifo(struct musb_hw_ep *hw_ep, u16 len, const u8 *buf)
  148. {
  149. void __iomem *ep_conf = hw_ep->conf;
  150. void __iomem *fifo = hw_ep->fifo;
  151. u8 epnum = hw_ep->epnum;
  152. prefetch(buf);
  153. DBG(4, "%cX ep%d fifo %p count %d buf %p\n",
  154. 'T', epnum, fifo, len, buf);
  155. if (epnum)
  156. musb_writel(ep_conf, TUSB_EP_TX_OFFSET,
  157. TUSB_EP_CONFIG_XFR_SIZE(len));
  158. else
  159. musb_writel(ep_conf, 0, TUSB_EP0_CONFIG_DIR_TX |
  160. TUSB_EP0_CONFIG_XFR_SIZE(len));
  161. if (likely((0x01 & (unsigned long) buf) == 0)) {
  162. /* Best case is 32bit-aligned destination address */
  163. if ((0x02 & (unsigned long) buf) == 0) {
  164. if (len >= 4) {
  165. writesl(fifo, buf, len >> 2);
  166. buf += (len & ~0x03);
  167. len &= 0x03;
  168. }
  169. } else {
  170. if (len >= 2) {
  171. u32 val;
  172. int i;
  173. /* Cannot use writesw, fifo is 32-bit */
  174. for (i = 0; i < (len >> 2); i++) {
  175. val = (u32)(*(u16 *)buf);
  176. buf += 2;
  177. val |= (*(u16 *)buf) << 16;
  178. buf += 2;
  179. musb_writel(fifo, 0, val);
  180. }
  181. len &= 0x03;
  182. }
  183. }
  184. }
  185. if (len > 0)
  186. tusb_fifo_write_unaligned(fifo, buf, len);
  187. }
  188. void musb_read_fifo(struct musb_hw_ep *hw_ep, u16 len, u8 *buf)
  189. {
  190. void __iomem *ep_conf = hw_ep->conf;
  191. void __iomem *fifo = hw_ep->fifo;
  192. u8 epnum = hw_ep->epnum;
  193. DBG(4, "%cX ep%d fifo %p count %d buf %p\n",
  194. 'R', epnum, fifo, len, buf);
  195. if (epnum)
  196. musb_writel(ep_conf, TUSB_EP_RX_OFFSET,
  197. TUSB_EP_CONFIG_XFR_SIZE(len));
  198. else
  199. musb_writel(ep_conf, 0, TUSB_EP0_CONFIG_XFR_SIZE(len));
  200. if (likely((0x01 & (unsigned long) buf) == 0)) {
  201. /* Best case is 32bit-aligned destination address */
  202. if ((0x02 & (unsigned long) buf) == 0) {
  203. if (len >= 4) {
  204. readsl(fifo, buf, len >> 2);
  205. buf += (len & ~0x03);
  206. len &= 0x03;
  207. }
  208. } else {
  209. if (len >= 2) {
  210. u32 val;
  211. int i;
  212. /* Cannot use readsw, fifo is 32-bit */
  213. for (i = 0; i < (len >> 2); i++) {
  214. val = musb_readl(fifo, 0);
  215. *(u16 *)buf = (u16)(val & 0xffff);
  216. buf += 2;
  217. *(u16 *)buf = (u16)(val >> 16);
  218. buf += 2;
  219. }
  220. len &= 0x03;
  221. }
  222. }
  223. }
  224. if (len > 0)
  225. tusb_fifo_read_unaligned(fifo, buf, len);
  226. }
  227. static struct musb *the_musb;
  228. #ifdef CONFIG_USB_GADGET_MUSB_HDRC
  229. /* This is used by gadget drivers, and OTG transceiver logic, allowing
  230. * at most mA current to be drawn from VBUS during a Default-B session
  231. * (that is, while VBUS exceeds 4.4V). In Default-A (including pure host
  232. * mode), or low power Default-B sessions, something else supplies power.
  233. * Caller must take care of locking.
  234. */
  235. static int tusb_draw_power(struct otg_transceiver *x, unsigned mA)
  236. {
  237. struct musb *musb = the_musb;
  238. void __iomem *tbase = musb->ctrl_base;
  239. u32 reg;
  240. /*
  241. * Keep clock active when enabled. Note that this is not tied to
  242. * drawing VBUS, as with OTG mA can be less than musb->min_power.
  243. */
  244. if (musb->set_clock) {
  245. if (mA)
  246. musb->set_clock(musb->clock, 1);
  247. else
  248. musb->set_clock(musb->clock, 0);
  249. }
  250. /* tps65030 seems to consume max 100mA, with maybe 60mA available
  251. * (measured on one board) for things other than tps and tusb.
  252. *
  253. * Boards sharing the CPU clock with CLKIN will need to prevent
  254. * certain idle sleep states while the USB link is active.
  255. *
  256. * REVISIT we could use VBUS to supply only _one_ of { 1.5V, 3.3V }.
  257. * The actual current usage would be very board-specific. For now,
  258. * it's simpler to just use an aggregate (also board-specific).
  259. */
  260. if (x->default_a || mA < (musb->min_power << 1))
  261. mA = 0;
  262. reg = musb_readl(tbase, TUSB_PRCM_MNGMT);
  263. if (mA) {
  264. musb->is_bus_powered = 1;
  265. reg |= TUSB_PRCM_MNGMT_15_SW_EN | TUSB_PRCM_MNGMT_33_SW_EN;
  266. } else {
  267. musb->is_bus_powered = 0;
  268. reg &= ~(TUSB_PRCM_MNGMT_15_SW_EN | TUSB_PRCM_MNGMT_33_SW_EN);
  269. }
  270. musb_writel(tbase, TUSB_PRCM_MNGMT, reg);
  271. DBG(2, "draw max %d mA VBUS\n", mA);
  272. return 0;
  273. }
  274. #else
  275. #define tusb_draw_power NULL
  276. #endif
  277. /* workaround for issue 13: change clock during chip idle
  278. * (to be fixed in rev3 silicon) ... symptoms include disconnect
  279. * or looping suspend/resume cycles
  280. */
  281. static void tusb_set_clock_source(struct musb *musb, unsigned mode)
  282. {
  283. void __iomem *tbase = musb->ctrl_base;
  284. u32 reg;
  285. reg = musb_readl(tbase, TUSB_PRCM_CONF);
  286. reg &= ~TUSB_PRCM_CONF_SYS_CLKSEL(0x3);
  287. /* 0 = refclk (clkin, XI)
  288. * 1 = PHY 60 MHz (internal PLL)
  289. * 2 = not supported
  290. * 3 = what?
  291. */
  292. if (mode > 0)
  293. reg |= TUSB_PRCM_CONF_SYS_CLKSEL(mode & 0x3);
  294. musb_writel(tbase, TUSB_PRCM_CONF, reg);
  295. /* FIXME tusb6010_platform_retime(mode == 0); */
  296. }
  297. /*
  298. * Idle TUSB6010 until next wake-up event; NOR access always wakes.
  299. * Other code ensures that we idle unless we're connected _and_ the
  300. * USB link is not suspended ... and tells us the relevant wakeup
  301. * events. SW_EN for voltage is handled separately.
  302. */
  303. void tusb_allow_idle(struct musb *musb, u32 wakeup_enables)
  304. {
  305. void __iomem *tbase = musb->ctrl_base;
  306. u32 reg;
  307. if ((wakeup_enables & TUSB_PRCM_WBUS)
  308. && (tusb_get_revision(musb) == TUSB_REV_30))
  309. tusb_wbus_quirk(musb, 1);
  310. tusb_set_clock_source(musb, 0);
  311. wakeup_enables |= TUSB_PRCM_WNORCS;
  312. musb_writel(tbase, TUSB_PRCM_WAKEUP_MASK, ~wakeup_enables);
  313. /* REVISIT writeup of WID implies that if WID set and ID is grounded,
  314. * TUSB_PHY_OTG_CTRL.TUSB_PHY_OTG_CTRL_OTG_ID_PULLUP must be cleared.
  315. * Presumably that's mostly to save power, hence WID is immaterial ...
  316. */
  317. reg = musb_readl(tbase, TUSB_PRCM_MNGMT);
  318. /* issue 4: when driving vbus, use hipower (vbus_det) comparator */
  319. if (is_host_active(musb)) {
  320. reg |= TUSB_PRCM_MNGMT_OTG_VBUS_DET_EN;
  321. reg &= ~TUSB_PRCM_MNGMT_OTG_SESS_END_EN;
  322. } else {
  323. reg |= TUSB_PRCM_MNGMT_OTG_SESS_END_EN;
  324. reg &= ~TUSB_PRCM_MNGMT_OTG_VBUS_DET_EN;
  325. }
  326. reg |= TUSB_PRCM_MNGMT_PM_IDLE | TUSB_PRCM_MNGMT_DEV_IDLE;
  327. musb_writel(tbase, TUSB_PRCM_MNGMT, reg);
  328. DBG(6, "idle, wake on %02x\n", wakeup_enables);
  329. }
  330. /*
  331. * Updates cable VBUS status. Caller must take care of locking.
  332. */
  333. int musb_platform_get_vbus_status(struct musb *musb)
  334. {
  335. void __iomem *tbase = musb->ctrl_base;
  336. u32 otg_stat, prcm_mngmt;
  337. int ret = 0;
  338. otg_stat = musb_readl(tbase, TUSB_DEV_OTG_STAT);
  339. prcm_mngmt = musb_readl(tbase, TUSB_PRCM_MNGMT);
  340. /* Temporarily enable VBUS detection if it was disabled for
  341. * suspend mode. Unless it's enabled otg_stat and devctl will
  342. * not show correct VBUS state.
  343. */
  344. if (!(prcm_mngmt & TUSB_PRCM_MNGMT_OTG_VBUS_DET_EN)) {
  345. u32 tmp = prcm_mngmt;
  346. tmp |= TUSB_PRCM_MNGMT_OTG_VBUS_DET_EN;
  347. musb_writel(tbase, TUSB_PRCM_MNGMT, tmp);
  348. otg_stat = musb_readl(tbase, TUSB_DEV_OTG_STAT);
  349. musb_writel(tbase, TUSB_PRCM_MNGMT, prcm_mngmt);
  350. }
  351. if (otg_stat & TUSB_DEV_OTG_STAT_VBUS_VALID)
  352. ret = 1;
  353. return ret;
  354. }
  355. static struct timer_list musb_idle_timer;
  356. static void musb_do_idle(unsigned long _musb)
  357. {
  358. struct musb *musb = (void *)_musb;
  359. unsigned long flags;
  360. spin_lock_irqsave(&musb->lock, flags);
  361. switch (musb->xceiv->state) {
  362. case OTG_STATE_A_WAIT_BCON:
  363. if ((musb->a_wait_bcon != 0)
  364. && (musb->idle_timeout == 0
  365. || time_after(jiffies, musb->idle_timeout))) {
  366. DBG(4, "Nothing connected %s, turning off VBUS\n",
  367. otg_state_string(musb));
  368. }
  369. /* FALLTHROUGH */
  370. case OTG_STATE_A_IDLE:
  371. tusb_source_power(musb, 0);
  372. default:
  373. break;
  374. }
  375. if (!musb->is_active) {
  376. u32 wakeups;
  377. /* wait until khubd handles port change status */
  378. if (is_host_active(musb) && (musb->port1_status >> 16))
  379. goto done;
  380. #ifdef CONFIG_USB_GADGET_MUSB_HDRC
  381. if (is_peripheral_enabled(musb) && !musb->gadget_driver)
  382. wakeups = 0;
  383. else {
  384. wakeups = TUSB_PRCM_WHOSTDISCON
  385. | TUSB_PRCM_WBUS
  386. | TUSB_PRCM_WVBUS;
  387. if (is_otg_enabled(musb))
  388. wakeups |= TUSB_PRCM_WID;
  389. }
  390. #else
  391. wakeups = TUSB_PRCM_WHOSTDISCON | TUSB_PRCM_WBUS;
  392. #endif
  393. tusb_allow_idle(musb, wakeups);
  394. }
  395. done:
  396. spin_unlock_irqrestore(&musb->lock, flags);
  397. }
  398. /*
  399. * Maybe put TUSB6010 into idle mode mode depending on USB link status,
  400. * like "disconnected" or "suspended". We'll be woken out of it by
  401. * connect, resume, or disconnect.
  402. *
  403. * Needs to be called as the last function everywhere where there is
  404. * register access to TUSB6010 because of NOR flash wake-up.
  405. * Caller should own controller spinlock.
  406. *
  407. * Delay because peripheral enables D+ pullup 3msec after SE0, and
  408. * we don't want to treat that full speed J as a wakeup event.
  409. * ... peripherals must draw only suspend current after 10 msec.
  410. */
  411. void musb_platform_try_idle(struct musb *musb, unsigned long timeout)
  412. {
  413. unsigned long default_timeout = jiffies + msecs_to_jiffies(3);
  414. static unsigned long last_timer;
  415. if (timeout == 0)
  416. timeout = default_timeout;
  417. /* Never idle if active, or when VBUS timeout is not set as host */
  418. if (musb->is_active || ((musb->a_wait_bcon == 0)
  419. && (musb->xceiv->state == OTG_STATE_A_WAIT_BCON))) {
  420. DBG(4, "%s active, deleting timer\n", otg_state_string(musb));
  421. del_timer(&musb_idle_timer);
  422. last_timer = jiffies;
  423. return;
  424. }
  425. if (time_after(last_timer, timeout)) {
  426. if (!timer_pending(&musb_idle_timer))
  427. last_timer = timeout;
  428. else {
  429. DBG(4, "Longer idle timer already pending, ignoring\n");
  430. return;
  431. }
  432. }
  433. last_timer = timeout;
  434. DBG(4, "%s inactive, for idle timer for %lu ms\n",
  435. otg_state_string(musb),
  436. (unsigned long)jiffies_to_msecs(timeout - jiffies));
  437. mod_timer(&musb_idle_timer, timeout);
  438. }
  439. /* ticks of 60 MHz clock */
  440. #define DEVCLOCK 60000000
  441. #define OTG_TIMER_MS(msecs) ((msecs) \
  442. ? (TUSB_DEV_OTG_TIMER_VAL((DEVCLOCK/1000)*(msecs)) \
  443. | TUSB_DEV_OTG_TIMER_ENABLE) \
  444. : 0)
  445. static void tusb_source_power(struct musb *musb, int is_on)
  446. {
  447. void __iomem *tbase = musb->ctrl_base;
  448. u32 conf, prcm, timer;
  449. u8 devctl;
  450. /* HDRC controls CPEN, but beware current surges during device
  451. * connect. They can trigger transient overcurrent conditions
  452. * that must be ignored.
  453. */
  454. prcm = musb_readl(tbase, TUSB_PRCM_MNGMT);
  455. conf = musb_readl(tbase, TUSB_DEV_CONF);
  456. devctl = musb_readb(musb->mregs, MUSB_DEVCTL);
  457. if (is_on) {
  458. if (musb->set_clock)
  459. musb->set_clock(musb->clock, 1);
  460. timer = OTG_TIMER_MS(OTG_TIME_A_WAIT_VRISE);
  461. musb->xceiv->default_a = 1;
  462. musb->xceiv->state = OTG_STATE_A_WAIT_VRISE;
  463. devctl |= MUSB_DEVCTL_SESSION;
  464. conf |= TUSB_DEV_CONF_USB_HOST_MODE;
  465. MUSB_HST_MODE(musb);
  466. } else {
  467. u32 otg_stat;
  468. timer = 0;
  469. /* If ID pin is grounded, we want to be a_idle */
  470. otg_stat = musb_readl(tbase, TUSB_DEV_OTG_STAT);
  471. if (!(otg_stat & TUSB_DEV_OTG_STAT_ID_STATUS)) {
  472. switch (musb->xceiv->state) {
  473. case OTG_STATE_A_WAIT_VRISE:
  474. case OTG_STATE_A_WAIT_BCON:
  475. musb->xceiv->state = OTG_STATE_A_WAIT_VFALL;
  476. break;
  477. case OTG_STATE_A_WAIT_VFALL:
  478. musb->xceiv->state = OTG_STATE_A_IDLE;
  479. break;
  480. default:
  481. musb->xceiv->state = OTG_STATE_A_IDLE;
  482. }
  483. musb->is_active = 0;
  484. musb->xceiv->default_a = 1;
  485. MUSB_HST_MODE(musb);
  486. } else {
  487. musb->is_active = 0;
  488. musb->xceiv->default_a = 0;
  489. musb->xceiv->state = OTG_STATE_B_IDLE;
  490. MUSB_DEV_MODE(musb);
  491. }
  492. devctl &= ~MUSB_DEVCTL_SESSION;
  493. conf &= ~TUSB_DEV_CONF_USB_HOST_MODE;
  494. if (musb->set_clock)
  495. musb->set_clock(musb->clock, 0);
  496. }
  497. prcm &= ~(TUSB_PRCM_MNGMT_15_SW_EN | TUSB_PRCM_MNGMT_33_SW_EN);
  498. musb_writel(tbase, TUSB_PRCM_MNGMT, prcm);
  499. musb_writel(tbase, TUSB_DEV_OTG_TIMER, timer);
  500. musb_writel(tbase, TUSB_DEV_CONF, conf);
  501. musb_writeb(musb->mregs, MUSB_DEVCTL, devctl);
  502. DBG(1, "VBUS %s, devctl %02x otg %3x conf %08x prcm %08x\n",
  503. otg_state_string(musb),
  504. musb_readb(musb->mregs, MUSB_DEVCTL),
  505. musb_readl(tbase, TUSB_DEV_OTG_STAT),
  506. conf, prcm);
  507. }
  508. /*
  509. * Sets the mode to OTG, peripheral or host by changing the ID detection.
  510. * Caller must take care of locking.
  511. *
  512. * Note that if a mini-A cable is plugged in the ID line will stay down as
  513. * the weak ID pull-up is not able to pull the ID up.
  514. *
  515. * REVISIT: It would be possible to add support for changing between host
  516. * and peripheral modes in non-OTG configurations by reconfiguring hardware
  517. * and then setting musb->board_mode. For now, only support OTG mode.
  518. */
  519. int musb_platform_set_mode(struct musb *musb, u8 musb_mode)
  520. {
  521. void __iomem *tbase = musb->ctrl_base;
  522. u32 otg_stat, phy_otg_ctrl, phy_otg_ena, dev_conf;
  523. if (musb->board_mode != MUSB_OTG) {
  524. ERR("Changing mode currently only supported in OTG mode\n");
  525. return -EINVAL;
  526. }
  527. otg_stat = musb_readl(tbase, TUSB_DEV_OTG_STAT);
  528. phy_otg_ctrl = musb_readl(tbase, TUSB_PHY_OTG_CTRL);
  529. phy_otg_ena = musb_readl(tbase, TUSB_PHY_OTG_CTRL_ENABLE);
  530. dev_conf = musb_readl(tbase, TUSB_DEV_CONF);
  531. switch (musb_mode) {
  532. #ifdef CONFIG_USB_MUSB_HDRC_HCD
  533. case MUSB_HOST: /* Disable PHY ID detect, ground ID */
  534. phy_otg_ctrl &= ~TUSB_PHY_OTG_CTRL_OTG_ID_PULLUP;
  535. phy_otg_ena |= TUSB_PHY_OTG_CTRL_OTG_ID_PULLUP;
  536. dev_conf |= TUSB_DEV_CONF_ID_SEL;
  537. dev_conf &= ~TUSB_DEV_CONF_SOFT_ID;
  538. break;
  539. #endif
  540. #ifdef CONFIG_USB_GADGET_MUSB_HDRC
  541. case MUSB_PERIPHERAL: /* Disable PHY ID detect, keep ID pull-up on */
  542. phy_otg_ctrl |= TUSB_PHY_OTG_CTRL_OTG_ID_PULLUP;
  543. phy_otg_ena |= TUSB_PHY_OTG_CTRL_OTG_ID_PULLUP;
  544. dev_conf |= (TUSB_DEV_CONF_ID_SEL | TUSB_DEV_CONF_SOFT_ID);
  545. break;
  546. #endif
  547. #ifdef CONFIG_USB_MUSB_OTG
  548. case MUSB_OTG: /* Use PHY ID detection */
  549. phy_otg_ctrl |= TUSB_PHY_OTG_CTRL_OTG_ID_PULLUP;
  550. phy_otg_ena |= TUSB_PHY_OTG_CTRL_OTG_ID_PULLUP;
  551. dev_conf &= ~(TUSB_DEV_CONF_ID_SEL | TUSB_DEV_CONF_SOFT_ID);
  552. break;
  553. #endif
  554. default:
  555. DBG(2, "Trying to set mode %i\n", musb_mode);
  556. return -EINVAL;
  557. }
  558. musb_writel(tbase, TUSB_PHY_OTG_CTRL,
  559. TUSB_PHY_OTG_CTRL_WRPROTECT | phy_otg_ctrl);
  560. musb_writel(tbase, TUSB_PHY_OTG_CTRL_ENABLE,
  561. TUSB_PHY_OTG_CTRL_WRPROTECT | phy_otg_ena);
  562. musb_writel(tbase, TUSB_DEV_CONF, dev_conf);
  563. otg_stat = musb_readl(tbase, TUSB_DEV_OTG_STAT);
  564. if ((musb_mode == MUSB_PERIPHERAL) &&
  565. !(otg_stat & TUSB_DEV_OTG_STAT_ID_STATUS))
  566. INFO("Cannot be peripheral with mini-A cable "
  567. "otg_stat: %08x\n", otg_stat);
  568. return 0;
  569. }
  570. static inline unsigned long
  571. tusb_otg_ints(struct musb *musb, u32 int_src, void __iomem *tbase)
  572. {
  573. u32 otg_stat = musb_readl(tbase, TUSB_DEV_OTG_STAT);
  574. unsigned long idle_timeout = 0;
  575. /* ID pin */
  576. if ((int_src & TUSB_INT_SRC_ID_STATUS_CHNG)) {
  577. int default_a;
  578. if (is_otg_enabled(musb))
  579. default_a = !(otg_stat & TUSB_DEV_OTG_STAT_ID_STATUS);
  580. else
  581. default_a = is_host_enabled(musb);
  582. DBG(2, "Default-%c\n", default_a ? 'A' : 'B');
  583. musb->xceiv->default_a = default_a;
  584. tusb_source_power(musb, default_a);
  585. /* Don't allow idling immediately */
  586. if (default_a)
  587. idle_timeout = jiffies + (HZ * 3);
  588. }
  589. /* VBUS state change */
  590. if (int_src & TUSB_INT_SRC_VBUS_SENSE_CHNG) {
  591. /* B-dev state machine: no vbus ~= disconnect */
  592. if ((is_otg_enabled(musb) && !musb->xceiv->default_a)
  593. || !is_host_enabled(musb)) {
  594. #ifdef CONFIG_USB_MUSB_HDRC_HCD
  595. /* ? musb_root_disconnect(musb); */
  596. musb->port1_status &=
  597. ~(USB_PORT_STAT_CONNECTION
  598. | USB_PORT_STAT_ENABLE
  599. | USB_PORT_STAT_LOW_SPEED
  600. | USB_PORT_STAT_HIGH_SPEED
  601. | USB_PORT_STAT_TEST
  602. );
  603. #endif
  604. if (otg_stat & TUSB_DEV_OTG_STAT_SESS_END) {
  605. DBG(1, "Forcing disconnect (no interrupt)\n");
  606. if (musb->xceiv->state != OTG_STATE_B_IDLE) {
  607. /* INTR_DISCONNECT can hide... */
  608. musb->xceiv->state = OTG_STATE_B_IDLE;
  609. musb->int_usb |= MUSB_INTR_DISCONNECT;
  610. }
  611. musb->is_active = 0;
  612. }
  613. DBG(2, "vbus change, %s, otg %03x\n",
  614. otg_state_string(musb), otg_stat);
  615. idle_timeout = jiffies + (1 * HZ);
  616. schedule_work(&musb->irq_work);
  617. } else /* A-dev state machine */ {
  618. DBG(2, "vbus change, %s, otg %03x\n",
  619. otg_state_string(musb), otg_stat);
  620. switch (musb->xceiv->state) {
  621. case OTG_STATE_A_IDLE:
  622. DBG(2, "Got SRP, turning on VBUS\n");
  623. musb_set_vbus(musb, 1);
  624. /* CONNECT can wake if a_wait_bcon is set */
  625. if (musb->a_wait_bcon != 0)
  626. musb->is_active = 0;
  627. else
  628. musb->is_active = 1;
  629. /*
  630. * OPT FS A TD.4.6 needs few seconds for
  631. * A_WAIT_VRISE
  632. */
  633. idle_timeout = jiffies + (2 * HZ);
  634. break;
  635. case OTG_STATE_A_WAIT_VRISE:
  636. /* ignore; A-session-valid < VBUS_VALID/2,
  637. * we monitor this with the timer
  638. */
  639. break;
  640. case OTG_STATE_A_WAIT_VFALL:
  641. /* REVISIT this irq triggers during short
  642. * spikes caused by enumeration ...
  643. */
  644. if (musb->vbuserr_retry) {
  645. musb->vbuserr_retry--;
  646. tusb_source_power(musb, 1);
  647. } else {
  648. musb->vbuserr_retry
  649. = VBUSERR_RETRY_COUNT;
  650. tusb_source_power(musb, 0);
  651. }
  652. break;
  653. default:
  654. break;
  655. }
  656. }
  657. }
  658. /* OTG timer expiration */
  659. if (int_src & TUSB_INT_SRC_OTG_TIMEOUT) {
  660. u8 devctl;
  661. DBG(4, "%s timer, %03x\n", otg_state_string(musb), otg_stat);
  662. switch (musb->xceiv->state) {
  663. case OTG_STATE_A_WAIT_VRISE:
  664. /* VBUS has probably been valid for a while now,
  665. * but may well have bounced out of range a bit
  666. */
  667. devctl = musb_readb(musb->mregs, MUSB_DEVCTL);
  668. if (otg_stat & TUSB_DEV_OTG_STAT_VBUS_VALID) {
  669. if ((devctl & MUSB_DEVCTL_VBUS)
  670. != MUSB_DEVCTL_VBUS) {
  671. DBG(2, "devctl %02x\n", devctl);
  672. break;
  673. }
  674. musb->xceiv->state = OTG_STATE_A_WAIT_BCON;
  675. musb->is_active = 0;
  676. idle_timeout = jiffies
  677. + msecs_to_jiffies(musb->a_wait_bcon);
  678. } else {
  679. /* REVISIT report overcurrent to hub? */
  680. ERR("vbus too slow, devctl %02x\n", devctl);
  681. tusb_source_power(musb, 0);
  682. }
  683. break;
  684. case OTG_STATE_A_WAIT_BCON:
  685. if (musb->a_wait_bcon != 0)
  686. idle_timeout = jiffies
  687. + msecs_to_jiffies(musb->a_wait_bcon);
  688. break;
  689. case OTG_STATE_A_SUSPEND:
  690. break;
  691. case OTG_STATE_B_WAIT_ACON:
  692. break;
  693. default:
  694. break;
  695. }
  696. }
  697. schedule_work(&musb->irq_work);
  698. return idle_timeout;
  699. }
  700. static irqreturn_t tusb_interrupt(int irq, void *__hci)
  701. {
  702. struct musb *musb = __hci;
  703. void __iomem *tbase = musb->ctrl_base;
  704. unsigned long flags, idle_timeout = 0;
  705. u32 int_mask, int_src;
  706. spin_lock_irqsave(&musb->lock, flags);
  707. /* Mask all interrupts to allow using both edge and level GPIO irq */
  708. int_mask = musb_readl(tbase, TUSB_INT_MASK);
  709. musb_writel(tbase, TUSB_INT_MASK, ~TUSB_INT_MASK_RESERVED_BITS);
  710. int_src = musb_readl(tbase, TUSB_INT_SRC) & ~TUSB_INT_SRC_RESERVED_BITS;
  711. DBG(3, "TUSB IRQ %08x\n", int_src);
  712. musb->int_usb = (u8) int_src;
  713. /* Acknowledge wake-up source interrupts */
  714. if (int_src & TUSB_INT_SRC_DEV_WAKEUP) {
  715. u32 reg;
  716. u32 i;
  717. if (tusb_get_revision(musb) == TUSB_REV_30)
  718. tusb_wbus_quirk(musb, 0);
  719. /* there are issues re-locking the PLL on wakeup ... */
  720. /* work around issue 8 */
  721. for (i = 0xf7f7f7; i > 0xf7f7f7 - 1000; i--) {
  722. musb_writel(tbase, TUSB_SCRATCH_PAD, 0);
  723. musb_writel(tbase, TUSB_SCRATCH_PAD, i);
  724. reg = musb_readl(tbase, TUSB_SCRATCH_PAD);
  725. if (reg == i)
  726. break;
  727. DBG(6, "TUSB NOR not ready\n");
  728. }
  729. /* work around issue 13 (2nd half) */
  730. tusb_set_clock_source(musb, 1);
  731. reg = musb_readl(tbase, TUSB_PRCM_WAKEUP_SOURCE);
  732. musb_writel(tbase, TUSB_PRCM_WAKEUP_CLEAR, reg);
  733. if (reg & ~TUSB_PRCM_WNORCS) {
  734. musb->is_active = 1;
  735. schedule_work(&musb->irq_work);
  736. }
  737. DBG(3, "wake %sactive %02x\n",
  738. musb->is_active ? "" : "in", reg);
  739. /* REVISIT host side TUSB_PRCM_WHOSTDISCON, TUSB_PRCM_WBUS */
  740. }
  741. if (int_src & TUSB_INT_SRC_USB_IP_CONN)
  742. del_timer(&musb_idle_timer);
  743. /* OTG state change reports (annoyingly) not issued by Mentor core */
  744. if (int_src & (TUSB_INT_SRC_VBUS_SENSE_CHNG
  745. | TUSB_INT_SRC_OTG_TIMEOUT
  746. | TUSB_INT_SRC_ID_STATUS_CHNG))
  747. idle_timeout = tusb_otg_ints(musb, int_src, tbase);
  748. /* TX dma callback must be handled here, RX dma callback is
  749. * handled in tusb_omap_dma_cb.
  750. */
  751. if ((int_src & TUSB_INT_SRC_TXRX_DMA_DONE)) {
  752. u32 dma_src = musb_readl(tbase, TUSB_DMA_INT_SRC);
  753. u32 real_dma_src = musb_readl(tbase, TUSB_DMA_INT_MASK);
  754. DBG(3, "DMA IRQ %08x\n", dma_src);
  755. real_dma_src = ~real_dma_src & dma_src;
  756. if (tusb_dma_omap() && real_dma_src) {
  757. int tx_source = (real_dma_src & 0xffff);
  758. int i;
  759. for (i = 1; i <= 15; i++) {
  760. if (tx_source & (1 << i)) {
  761. DBG(3, "completing ep%i %s\n", i, "tx");
  762. musb_dma_completion(musb, i, 1);
  763. }
  764. }
  765. }
  766. musb_writel(tbase, TUSB_DMA_INT_CLEAR, dma_src);
  767. }
  768. /* EP interrupts. In OCP mode tusb6010 mirrors the MUSB interrupts */
  769. if (int_src & (TUSB_INT_SRC_USB_IP_TX | TUSB_INT_SRC_USB_IP_RX)) {
  770. u32 musb_src = musb_readl(tbase, TUSB_USBIP_INT_SRC);
  771. musb_writel(tbase, TUSB_USBIP_INT_CLEAR, musb_src);
  772. musb->int_rx = (((musb_src >> 16) & 0xffff) << 1);
  773. musb->int_tx = (musb_src & 0xffff);
  774. } else {
  775. musb->int_rx = 0;
  776. musb->int_tx = 0;
  777. }
  778. if (int_src & (TUSB_INT_SRC_USB_IP_TX | TUSB_INT_SRC_USB_IP_RX | 0xff))
  779. musb_interrupt(musb);
  780. /* Acknowledge TUSB interrupts. Clear only non-reserved bits */
  781. musb_writel(tbase, TUSB_INT_SRC_CLEAR,
  782. int_src & ~TUSB_INT_MASK_RESERVED_BITS);
  783. musb_platform_try_idle(musb, idle_timeout);
  784. musb_writel(tbase, TUSB_INT_MASK, int_mask);
  785. spin_unlock_irqrestore(&musb->lock, flags);
  786. return IRQ_HANDLED;
  787. }
  788. static int dma_off;
  789. /*
  790. * Enables TUSB6010. Caller must take care of locking.
  791. * REVISIT:
  792. * - Check what is unnecessary in MGC_HdrcStart()
  793. */
  794. void musb_platform_enable(struct musb *musb)
  795. {
  796. void __iomem *tbase = musb->ctrl_base;
  797. /* Setup TUSB6010 main interrupt mask. Enable all interrupts except SOF.
  798. * REVISIT: Enable and deal with TUSB_INT_SRC_USB_IP_SOF */
  799. musb_writel(tbase, TUSB_INT_MASK, TUSB_INT_SRC_USB_IP_SOF);
  800. /* Setup TUSB interrupt, disable DMA and GPIO interrupts */
  801. musb_writel(tbase, TUSB_USBIP_INT_MASK, 0);
  802. musb_writel(tbase, TUSB_DMA_INT_MASK, 0x7fffffff);
  803. musb_writel(tbase, TUSB_GPIO_INT_MASK, 0x1ff);
  804. /* Clear all subsystem interrups */
  805. musb_writel(tbase, TUSB_USBIP_INT_CLEAR, 0x7fffffff);
  806. musb_writel(tbase, TUSB_DMA_INT_CLEAR, 0x7fffffff);
  807. musb_writel(tbase, TUSB_GPIO_INT_CLEAR, 0x1ff);
  808. /* Acknowledge pending interrupt(s) */
  809. musb_writel(tbase, TUSB_INT_SRC_CLEAR, ~TUSB_INT_MASK_RESERVED_BITS);
  810. /* Only 0 clock cycles for minimum interrupt de-assertion time and
  811. * interrupt polarity active low seems to work reliably here */
  812. musb_writel(tbase, TUSB_INT_CTRL_CONF,
  813. TUSB_INT_CTRL_CONF_INT_RELCYC(0));
  814. set_irq_type(musb->nIrq, IRQ_TYPE_LEVEL_LOW);
  815. /* maybe force into the Default-A OTG state machine */
  816. if (!(musb_readl(tbase, TUSB_DEV_OTG_STAT)
  817. & TUSB_DEV_OTG_STAT_ID_STATUS))
  818. musb_writel(tbase, TUSB_INT_SRC_SET,
  819. TUSB_INT_SRC_ID_STATUS_CHNG);
  820. if (is_dma_capable() && dma_off)
  821. printk(KERN_WARNING "%s %s: dma not reactivated\n",
  822. __FILE__, __func__);
  823. else
  824. dma_off = 1;
  825. }
  826. /*
  827. * Disables TUSB6010. Caller must take care of locking.
  828. */
  829. void musb_platform_disable(struct musb *musb)
  830. {
  831. void __iomem *tbase = musb->ctrl_base;
  832. /* FIXME stop DMA, IRQs, timers, ... */
  833. /* disable all IRQs */
  834. musb_writel(tbase, TUSB_INT_MASK, ~TUSB_INT_MASK_RESERVED_BITS);
  835. musb_writel(tbase, TUSB_USBIP_INT_MASK, 0x7fffffff);
  836. musb_writel(tbase, TUSB_DMA_INT_MASK, 0x7fffffff);
  837. musb_writel(tbase, TUSB_GPIO_INT_MASK, 0x1ff);
  838. del_timer(&musb_idle_timer);
  839. if (is_dma_capable() && !dma_off) {
  840. printk(KERN_WARNING "%s %s: dma still active\n",
  841. __FILE__, __func__);
  842. dma_off = 1;
  843. }
  844. }
  845. /*
  846. * Sets up TUSB6010 CPU interface specific signals and registers
  847. * Note: Settings optimized for OMAP24xx
  848. */
  849. static void __init tusb_setup_cpu_interface(struct musb *musb)
  850. {
  851. void __iomem *tbase = musb->ctrl_base;
  852. /*
  853. * Disable GPIO[5:0] pullups (used as output DMA requests)
  854. * Don't disable GPIO[7:6] as they are needed for wake-up.
  855. */
  856. musb_writel(tbase, TUSB_PULLUP_1_CTRL, 0x0000003F);
  857. /* Disable all pullups on NOR IF, DMAREQ0 and DMAREQ1 */
  858. musb_writel(tbase, TUSB_PULLUP_2_CTRL, 0x01FFFFFF);
  859. /* Turn GPIO[5:0] to DMAREQ[5:0] signals */
  860. musb_writel(tbase, TUSB_GPIO_CONF, TUSB_GPIO_CONF_DMAREQ(0x3f));
  861. /* Burst size 16x16 bits, all six DMA requests enabled, DMA request
  862. * de-assertion time 2 system clocks p 62 */
  863. musb_writel(tbase, TUSB_DMA_REQ_CONF,
  864. TUSB_DMA_REQ_CONF_BURST_SIZE(2) |
  865. TUSB_DMA_REQ_CONF_DMA_REQ_EN(0x3f) |
  866. TUSB_DMA_REQ_CONF_DMA_REQ_ASSER(2));
  867. /* Set 0 wait count for synchronous burst access */
  868. musb_writel(tbase, TUSB_WAIT_COUNT, 1);
  869. }
  870. static int __init tusb_start(struct musb *musb)
  871. {
  872. void __iomem *tbase = musb->ctrl_base;
  873. int ret = 0;
  874. unsigned long flags;
  875. u32 reg;
  876. if (musb->board_set_power)
  877. ret = musb->board_set_power(1);
  878. if (ret != 0) {
  879. printk(KERN_ERR "tusb: Cannot enable TUSB6010\n");
  880. return ret;
  881. }
  882. spin_lock_irqsave(&musb->lock, flags);
  883. if (musb_readl(tbase, TUSB_PROD_TEST_RESET) !=
  884. TUSB_PROD_TEST_RESET_VAL) {
  885. printk(KERN_ERR "tusb: Unable to detect TUSB6010\n");
  886. goto err;
  887. }
  888. ret = tusb_print_revision(musb);
  889. if (ret < 2) {
  890. printk(KERN_ERR "tusb: Unsupported TUSB6010 revision %i\n",
  891. ret);
  892. goto err;
  893. }
  894. /* The uint bit for "USB non-PDR interrupt enable" has to be 1 when
  895. * NOR FLASH interface is used */
  896. musb_writel(tbase, TUSB_VLYNQ_CTRL, 8);
  897. /* Select PHY free running 60MHz as a system clock */
  898. tusb_set_clock_source(musb, 1);
  899. /* VBus valid timer 1us, disable DFT/Debug and VLYNQ clocks for
  900. * power saving, enable VBus detect and session end comparators,
  901. * enable IDpullup, enable VBus charging */
  902. musb_writel(tbase, TUSB_PRCM_MNGMT,
  903. TUSB_PRCM_MNGMT_VBUS_VALID_TIMER(0xa) |
  904. TUSB_PRCM_MNGMT_VBUS_VALID_FLT_EN |
  905. TUSB_PRCM_MNGMT_OTG_SESS_END_EN |
  906. TUSB_PRCM_MNGMT_OTG_VBUS_DET_EN |
  907. TUSB_PRCM_MNGMT_OTG_ID_PULLUP);
  908. tusb_setup_cpu_interface(musb);
  909. /* simplify: always sense/pullup ID pins, as if in OTG mode */
  910. reg = musb_readl(tbase, TUSB_PHY_OTG_CTRL_ENABLE);
  911. reg |= TUSB_PHY_OTG_CTRL_WRPROTECT | TUSB_PHY_OTG_CTRL_OTG_ID_PULLUP;
  912. musb_writel(tbase, TUSB_PHY_OTG_CTRL_ENABLE, reg);
  913. reg = musb_readl(tbase, TUSB_PHY_OTG_CTRL);
  914. reg |= TUSB_PHY_OTG_CTRL_WRPROTECT | TUSB_PHY_OTG_CTRL_OTG_ID_PULLUP;
  915. musb_writel(tbase, TUSB_PHY_OTG_CTRL, reg);
  916. spin_unlock_irqrestore(&musb->lock, flags);
  917. return 0;
  918. err:
  919. spin_unlock_irqrestore(&musb->lock, flags);
  920. if (musb->board_set_power)
  921. musb->board_set_power(0);
  922. return -ENODEV;
  923. }
  924. int __init musb_platform_init(struct musb *musb)
  925. {
  926. struct platform_device *pdev;
  927. struct resource *mem;
  928. void __iomem *sync = NULL;
  929. int ret;
  930. usb_nop_xceiv_register();
  931. musb->xceiv = otg_get_transceiver();
  932. if (!musb->xceiv)
  933. return -ENODEV;
  934. pdev = to_platform_device(musb->controller);
  935. /* dma address for async dma */
  936. mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  937. musb->async = mem->start;
  938. /* dma address for sync dma */
  939. mem = platform_get_resource(pdev, IORESOURCE_MEM, 1);
  940. if (!mem) {
  941. pr_debug("no sync dma resource?\n");
  942. ret = -ENODEV;
  943. goto done;
  944. }
  945. musb->sync = mem->start;
  946. sync = ioremap(mem->start, mem->end - mem->start + 1);
  947. if (!sync) {
  948. pr_debug("ioremap for sync failed\n");
  949. ret = -ENOMEM;
  950. goto done;
  951. }
  952. musb->sync_va = sync;
  953. /* Offsets from base: VLYNQ at 0x000, MUSB regs at 0x400,
  954. * FIFOs at 0x600, TUSB at 0x800
  955. */
  956. musb->mregs += TUSB_BASE_OFFSET;
  957. ret = tusb_start(musb);
  958. if (ret) {
  959. printk(KERN_ERR "Could not start tusb6010 (%d)\n",
  960. ret);
  961. goto done;
  962. }
  963. musb->isr = tusb_interrupt;
  964. if (is_host_enabled(musb))
  965. musb->board_set_vbus = tusb_source_power;
  966. if (is_peripheral_enabled(musb)) {
  967. musb->xceiv->set_power = tusb_draw_power;
  968. the_musb = musb;
  969. }
  970. setup_timer(&musb_idle_timer, musb_do_idle, (unsigned long) musb);
  971. done:
  972. if (ret < 0) {
  973. if (sync)
  974. iounmap(sync);
  975. usb_nop_xceiv_unregister();
  976. }
  977. return ret;
  978. }
  979. int musb_platform_exit(struct musb *musb)
  980. {
  981. del_timer_sync(&musb_idle_timer);
  982. the_musb = NULL;
  983. if (musb->board_set_power)
  984. musb->board_set_power(0);
  985. iounmap(musb->sync_va);
  986. usb_nop_xceiv_unregister();
  987. return 0;
  988. }