tusb6010.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154
  1. /*
  2. * TUSB6010 USB 2.0 OTG Dual Role controller
  3. *
  4. * Copyright (C) 2006 Nokia Corporation
  5. * Jarkko Nikula <jarkko.nikula@nokia.com>
  6. * Tony Lindgren <tony@atomide.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. *
  12. * Notes:
  13. * - Driver assumes that interface to external host (main CPU) is
  14. * configured for NOR FLASH interface instead of VLYNQ serial
  15. * interface.
  16. */
  17. #include <linux/module.h>
  18. #include <linux/kernel.h>
  19. #include <linux/errno.h>
  20. #include <linux/init.h>
  21. #include <linux/usb.h>
  22. #include <linux/irq.h>
  23. #include <linux/platform_device.h>
  24. #include "musb_core.h"
  25. static void tusb_source_power(struct musb *musb, int is_on);
  26. #define TUSB_REV_MAJOR(reg_val) ((reg_val >> 4) & 0xf)
  27. #define TUSB_REV_MINOR(reg_val) (reg_val & 0xf)
  28. /*
  29. * Checks the revision. We need to use the DMA register as 3.0 does not
  30. * have correct versions for TUSB_PRCM_REV or TUSB_INT_CTRL_REV.
  31. */
  32. u8 tusb_get_revision(struct musb *musb)
  33. {
  34. void __iomem *tbase = musb->ctrl_base;
  35. u32 die_id;
  36. u8 rev;
  37. rev = musb_readl(tbase, TUSB_DMA_CTRL_REV) & 0xff;
  38. if (TUSB_REV_MAJOR(rev) == 3) {
  39. die_id = TUSB_DIDR1_HI_CHIP_REV(musb_readl(tbase,
  40. TUSB_DIDR1_HI));
  41. if (die_id >= TUSB_DIDR1_HI_REV_31)
  42. rev |= 1;
  43. }
  44. return rev;
  45. }
  46. static int __init tusb_print_revision(struct musb *musb)
  47. {
  48. void __iomem *tbase = musb->ctrl_base;
  49. u8 rev;
  50. rev = tusb_get_revision(musb);
  51. pr_info("tusb: %s%i.%i %s%i.%i %s%i.%i %s%i.%i %s%i %s%i.%i\n",
  52. "prcm",
  53. TUSB_REV_MAJOR(musb_readl(tbase, TUSB_PRCM_REV)),
  54. TUSB_REV_MINOR(musb_readl(tbase, TUSB_PRCM_REV)),
  55. "int",
  56. TUSB_REV_MAJOR(musb_readl(tbase, TUSB_INT_CTRL_REV)),
  57. TUSB_REV_MINOR(musb_readl(tbase, TUSB_INT_CTRL_REV)),
  58. "gpio",
  59. TUSB_REV_MAJOR(musb_readl(tbase, TUSB_GPIO_REV)),
  60. TUSB_REV_MINOR(musb_readl(tbase, TUSB_GPIO_REV)),
  61. "dma",
  62. TUSB_REV_MAJOR(musb_readl(tbase, TUSB_DMA_CTRL_REV)),
  63. TUSB_REV_MINOR(musb_readl(tbase, TUSB_DMA_CTRL_REV)),
  64. "dieid",
  65. TUSB_DIDR1_HI_CHIP_REV(musb_readl(tbase, TUSB_DIDR1_HI)),
  66. "rev",
  67. TUSB_REV_MAJOR(rev), TUSB_REV_MINOR(rev));
  68. return tusb_get_revision(musb);
  69. }
  70. #define WBUS_QUIRK_MASK (TUSB_PHY_OTG_CTRL_TESTM2 | TUSB_PHY_OTG_CTRL_TESTM1 \
  71. | TUSB_PHY_OTG_CTRL_TESTM0)
  72. /*
  73. * Workaround for spontaneous WBUS wake-up issue #2 for tusb3.0.
  74. * Disables power detection in PHY for the duration of idle.
  75. */
  76. static void tusb_wbus_quirk(struct musb *musb, int enabled)
  77. {
  78. void __iomem *tbase = musb->ctrl_base;
  79. static u32 phy_otg_ctrl, phy_otg_ena;
  80. u32 tmp;
  81. if (enabled) {
  82. phy_otg_ctrl = musb_readl(tbase, TUSB_PHY_OTG_CTRL);
  83. phy_otg_ena = musb_readl(tbase, TUSB_PHY_OTG_CTRL_ENABLE);
  84. tmp = TUSB_PHY_OTG_CTRL_WRPROTECT
  85. | phy_otg_ena | WBUS_QUIRK_MASK;
  86. musb_writel(tbase, TUSB_PHY_OTG_CTRL, tmp);
  87. tmp = phy_otg_ena & ~WBUS_QUIRK_MASK;
  88. tmp |= TUSB_PHY_OTG_CTRL_WRPROTECT | TUSB_PHY_OTG_CTRL_TESTM2;
  89. musb_writel(tbase, TUSB_PHY_OTG_CTRL_ENABLE, tmp);
  90. DBG(2, "Enabled tusb wbus quirk ctrl %08x ena %08x\n",
  91. musb_readl(tbase, TUSB_PHY_OTG_CTRL),
  92. musb_readl(tbase, TUSB_PHY_OTG_CTRL_ENABLE));
  93. } else if (musb_readl(tbase, TUSB_PHY_OTG_CTRL_ENABLE)
  94. & TUSB_PHY_OTG_CTRL_TESTM2) {
  95. tmp = TUSB_PHY_OTG_CTRL_WRPROTECT | phy_otg_ctrl;
  96. musb_writel(tbase, TUSB_PHY_OTG_CTRL, tmp);
  97. tmp = TUSB_PHY_OTG_CTRL_WRPROTECT | phy_otg_ena;
  98. musb_writel(tbase, TUSB_PHY_OTG_CTRL_ENABLE, tmp);
  99. DBG(2, "Disabled tusb wbus quirk ctrl %08x ena %08x\n",
  100. musb_readl(tbase, TUSB_PHY_OTG_CTRL),
  101. musb_readl(tbase, TUSB_PHY_OTG_CTRL_ENABLE));
  102. phy_otg_ctrl = 0;
  103. phy_otg_ena = 0;
  104. }
  105. }
  106. /*
  107. * TUSB 6010 may use a parallel bus that doesn't support byte ops;
  108. * so both loading and unloading FIFOs need explicit byte counts.
  109. */
  110. static inline void
  111. tusb_fifo_write_unaligned(void __iomem *fifo, const u8 *buf, u16 len)
  112. {
  113. u32 val;
  114. int i;
  115. if (len > 4) {
  116. for (i = 0; i < (len >> 2); i++) {
  117. memcpy(&val, buf, 4);
  118. musb_writel(fifo, 0, val);
  119. buf += 4;
  120. }
  121. len %= 4;
  122. }
  123. if (len > 0) {
  124. /* Write the rest 1 - 3 bytes to FIFO */
  125. memcpy(&val, buf, len);
  126. musb_writel(fifo, 0, val);
  127. }
  128. }
  129. static inline void tusb_fifo_read_unaligned(void __iomem *fifo,
  130. void __iomem *buf, u16 len)
  131. {
  132. u32 val;
  133. int i;
  134. if (len > 4) {
  135. for (i = 0; i < (len >> 2); i++) {
  136. val = musb_readl(fifo, 0);
  137. memcpy(buf, &val, 4);
  138. buf += 4;
  139. }
  140. len %= 4;
  141. }
  142. if (len > 0) {
  143. /* Read the rest 1 - 3 bytes from FIFO */
  144. val = musb_readl(fifo, 0);
  145. memcpy(buf, &val, len);
  146. }
  147. }
  148. void musb_write_fifo(struct musb_hw_ep *hw_ep, u16 len, const u8 *buf)
  149. {
  150. void __iomem *ep_conf = hw_ep->conf;
  151. void __iomem *fifo = hw_ep->fifo;
  152. u8 epnum = hw_ep->epnum;
  153. prefetch(buf);
  154. DBG(4, "%cX ep%d fifo %p count %d buf %p\n",
  155. 'T', epnum, fifo, len, buf);
  156. if (epnum)
  157. musb_writel(ep_conf, TUSB_EP_TX_OFFSET,
  158. TUSB_EP_CONFIG_XFR_SIZE(len));
  159. else
  160. musb_writel(ep_conf, 0, TUSB_EP0_CONFIG_DIR_TX |
  161. TUSB_EP0_CONFIG_XFR_SIZE(len));
  162. if (likely((0x01 & (unsigned long) buf) == 0)) {
  163. /* Best case is 32bit-aligned destination address */
  164. if ((0x02 & (unsigned long) buf) == 0) {
  165. if (len >= 4) {
  166. writesl(fifo, buf, len >> 2);
  167. buf += (len & ~0x03);
  168. len &= 0x03;
  169. }
  170. } else {
  171. if (len >= 2) {
  172. u32 val;
  173. int i;
  174. /* Cannot use writesw, fifo is 32-bit */
  175. for (i = 0; i < (len >> 2); i++) {
  176. val = (u32)(*(u16 *)buf);
  177. buf += 2;
  178. val |= (*(u16 *)buf) << 16;
  179. buf += 2;
  180. musb_writel(fifo, 0, val);
  181. }
  182. len &= 0x03;
  183. }
  184. }
  185. }
  186. if (len > 0)
  187. tusb_fifo_write_unaligned(fifo, buf, len);
  188. }
  189. void musb_read_fifo(struct musb_hw_ep *hw_ep, u16 len, u8 *buf)
  190. {
  191. void __iomem *ep_conf = hw_ep->conf;
  192. void __iomem *fifo = hw_ep->fifo;
  193. u8 epnum = hw_ep->epnum;
  194. DBG(4, "%cX ep%d fifo %p count %d buf %p\n",
  195. 'R', epnum, fifo, len, buf);
  196. if (epnum)
  197. musb_writel(ep_conf, TUSB_EP_RX_OFFSET,
  198. TUSB_EP_CONFIG_XFR_SIZE(len));
  199. else
  200. musb_writel(ep_conf, 0, TUSB_EP0_CONFIG_XFR_SIZE(len));
  201. if (likely((0x01 & (unsigned long) buf) == 0)) {
  202. /* Best case is 32bit-aligned destination address */
  203. if ((0x02 & (unsigned long) buf) == 0) {
  204. if (len >= 4) {
  205. readsl(fifo, buf, len >> 2);
  206. buf += (len & ~0x03);
  207. len &= 0x03;
  208. }
  209. } else {
  210. if (len >= 2) {
  211. u32 val;
  212. int i;
  213. /* Cannot use readsw, fifo is 32-bit */
  214. for (i = 0; i < (len >> 2); i++) {
  215. val = musb_readl(fifo, 0);
  216. *(u16 *)buf = (u16)(val & 0xffff);
  217. buf += 2;
  218. *(u16 *)buf = (u16)(val >> 16);
  219. buf += 2;
  220. }
  221. len &= 0x03;
  222. }
  223. }
  224. }
  225. if (len > 0)
  226. tusb_fifo_read_unaligned(fifo, buf, len);
  227. }
  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 = container_of(x, struct musb, xceiv);
  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;
  929. int ret;
  930. pdev = to_platform_device(musb->controller);
  931. /* dma address for async dma */
  932. mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  933. musb->async = mem->start;
  934. /* dma address for sync dma */
  935. mem = platform_get_resource(pdev, IORESOURCE_MEM, 1);
  936. if (!mem) {
  937. pr_debug("no sync dma resource?\n");
  938. return -ENODEV;
  939. }
  940. musb->sync = mem->start;
  941. sync = ioremap(mem->start, mem->end - mem->start + 1);
  942. if (!sync) {
  943. pr_debug("ioremap for sync failed\n");
  944. return -ENOMEM;
  945. }
  946. musb->sync_va = sync;
  947. /* Offsets from base: VLYNQ at 0x000, MUSB regs at 0x400,
  948. * FIFOs at 0x600, TUSB at 0x800
  949. */
  950. musb->mregs += TUSB_BASE_OFFSET;
  951. ret = tusb_start(musb);
  952. if (ret) {
  953. printk(KERN_ERR "Could not start tusb6010 (%d)\n",
  954. ret);
  955. return -ENODEV;
  956. }
  957. musb->isr = tusb_interrupt;
  958. if (is_host_enabled(musb))
  959. musb->board_set_vbus = tusb_source_power;
  960. if (is_peripheral_enabled(musb))
  961. musb->xceiv.set_power = tusb_draw_power;
  962. setup_timer(&musb_idle_timer, musb_do_idle, (unsigned long) musb);
  963. return ret;
  964. }
  965. int musb_platform_exit(struct musb *musb)
  966. {
  967. del_timer_sync(&musb_idle_timer);
  968. if (musb->board_set_power)
  969. musb->board_set_power(0);
  970. iounmap(musb->sync_va);
  971. return 0;
  972. }