tusb6010.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151
  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. void 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;
  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 unknown mode %i\n", musb_mode);
  556. }
  557. musb_writel(tbase, TUSB_PHY_OTG_CTRL,
  558. TUSB_PHY_OTG_CTRL_WRPROTECT | phy_otg_ctrl);
  559. musb_writel(tbase, TUSB_PHY_OTG_CTRL_ENABLE,
  560. TUSB_PHY_OTG_CTRL_WRPROTECT | phy_otg_ena);
  561. musb_writel(tbase, TUSB_DEV_CONF, dev_conf);
  562. otg_stat = musb_readl(tbase, TUSB_DEV_OTG_STAT);
  563. if ((musb_mode == MUSB_PERIPHERAL) &&
  564. !(otg_stat & TUSB_DEV_OTG_STAT_ID_STATUS))
  565. INFO("Cannot be peripheral with mini-A cable "
  566. "otg_stat: %08x\n", otg_stat);
  567. }
  568. static inline unsigned long
  569. tusb_otg_ints(struct musb *musb, u32 int_src, void __iomem *tbase)
  570. {
  571. u32 otg_stat = musb_readl(tbase, TUSB_DEV_OTG_STAT);
  572. unsigned long idle_timeout = 0;
  573. /* ID pin */
  574. if ((int_src & TUSB_INT_SRC_ID_STATUS_CHNG)) {
  575. int default_a;
  576. if (is_otg_enabled(musb))
  577. default_a = !(otg_stat & TUSB_DEV_OTG_STAT_ID_STATUS);
  578. else
  579. default_a = is_host_enabled(musb);
  580. DBG(2, "Default-%c\n", default_a ? 'A' : 'B');
  581. musb->xceiv.default_a = default_a;
  582. tusb_source_power(musb, default_a);
  583. /* Don't allow idling immediately */
  584. if (default_a)
  585. idle_timeout = jiffies + (HZ * 3);
  586. }
  587. /* VBUS state change */
  588. if (int_src & TUSB_INT_SRC_VBUS_SENSE_CHNG) {
  589. /* B-dev state machine: no vbus ~= disconnect */
  590. if ((is_otg_enabled(musb) && !musb->xceiv.default_a)
  591. || !is_host_enabled(musb)) {
  592. #ifdef CONFIG_USB_MUSB_HDRC_HCD
  593. /* ? musb_root_disconnect(musb); */
  594. musb->port1_status &=
  595. ~(USB_PORT_STAT_CONNECTION
  596. | USB_PORT_STAT_ENABLE
  597. | USB_PORT_STAT_LOW_SPEED
  598. | USB_PORT_STAT_HIGH_SPEED
  599. | USB_PORT_STAT_TEST
  600. );
  601. #endif
  602. if (otg_stat & TUSB_DEV_OTG_STAT_SESS_END) {
  603. DBG(1, "Forcing disconnect (no interrupt)\n");
  604. if (musb->xceiv.state != OTG_STATE_B_IDLE) {
  605. /* INTR_DISCONNECT can hide... */
  606. musb->xceiv.state = OTG_STATE_B_IDLE;
  607. musb->int_usb |= MUSB_INTR_DISCONNECT;
  608. }
  609. musb->is_active = 0;
  610. }
  611. DBG(2, "vbus change, %s, otg %03x\n",
  612. otg_state_string(musb), otg_stat);
  613. idle_timeout = jiffies + (1 * HZ);
  614. schedule_work(&musb->irq_work);
  615. } else /* A-dev state machine */ {
  616. DBG(2, "vbus change, %s, otg %03x\n",
  617. otg_state_string(musb), otg_stat);
  618. switch (musb->xceiv.state) {
  619. case OTG_STATE_A_IDLE:
  620. DBG(2, "Got SRP, turning on VBUS\n");
  621. musb_set_vbus(musb, 1);
  622. /* CONNECT can wake if a_wait_bcon is set */
  623. if (musb->a_wait_bcon != 0)
  624. musb->is_active = 0;
  625. else
  626. musb->is_active = 1;
  627. /*
  628. * OPT FS A TD.4.6 needs few seconds for
  629. * A_WAIT_VRISE
  630. */
  631. idle_timeout = jiffies + (2 * HZ);
  632. break;
  633. case OTG_STATE_A_WAIT_VRISE:
  634. /* ignore; A-session-valid < VBUS_VALID/2,
  635. * we monitor this with the timer
  636. */
  637. break;
  638. case OTG_STATE_A_WAIT_VFALL:
  639. /* REVISIT this irq triggers during short
  640. * spikes caused by enumeration ...
  641. */
  642. if (musb->vbuserr_retry) {
  643. musb->vbuserr_retry--;
  644. tusb_source_power(musb, 1);
  645. } else {
  646. musb->vbuserr_retry
  647. = VBUSERR_RETRY_COUNT;
  648. tusb_source_power(musb, 0);
  649. }
  650. break;
  651. default:
  652. break;
  653. }
  654. }
  655. }
  656. /* OTG timer expiration */
  657. if (int_src & TUSB_INT_SRC_OTG_TIMEOUT) {
  658. u8 devctl;
  659. DBG(4, "%s timer, %03x\n", otg_state_string(musb), otg_stat);
  660. switch (musb->xceiv.state) {
  661. case OTG_STATE_A_WAIT_VRISE:
  662. /* VBUS has probably been valid for a while now,
  663. * but may well have bounced out of range a bit
  664. */
  665. devctl = musb_readb(musb->mregs, MUSB_DEVCTL);
  666. if (otg_stat & TUSB_DEV_OTG_STAT_VBUS_VALID) {
  667. if ((devctl & MUSB_DEVCTL_VBUS)
  668. != MUSB_DEVCTL_VBUS) {
  669. DBG(2, "devctl %02x\n", devctl);
  670. break;
  671. }
  672. musb->xceiv.state = OTG_STATE_A_WAIT_BCON;
  673. musb->is_active = 0;
  674. idle_timeout = jiffies
  675. + msecs_to_jiffies(musb->a_wait_bcon);
  676. } else {
  677. /* REVISIT report overcurrent to hub? */
  678. ERR("vbus too slow, devctl %02x\n", devctl);
  679. tusb_source_power(musb, 0);
  680. }
  681. break;
  682. case OTG_STATE_A_WAIT_BCON:
  683. if (musb->a_wait_bcon != 0)
  684. idle_timeout = jiffies
  685. + msecs_to_jiffies(musb->a_wait_bcon);
  686. break;
  687. case OTG_STATE_A_SUSPEND:
  688. break;
  689. case OTG_STATE_B_WAIT_ACON:
  690. break;
  691. default:
  692. break;
  693. }
  694. }
  695. schedule_work(&musb->irq_work);
  696. return idle_timeout;
  697. }
  698. static irqreturn_t tusb_interrupt(int irq, void *__hci)
  699. {
  700. struct musb *musb = __hci;
  701. void __iomem *tbase = musb->ctrl_base;
  702. unsigned long flags, idle_timeout = 0;
  703. u32 int_mask, int_src;
  704. spin_lock_irqsave(&musb->lock, flags);
  705. /* Mask all interrupts to allow using both edge and level GPIO irq */
  706. int_mask = musb_readl(tbase, TUSB_INT_MASK);
  707. musb_writel(tbase, TUSB_INT_MASK, ~TUSB_INT_MASK_RESERVED_BITS);
  708. int_src = musb_readl(tbase, TUSB_INT_SRC) & ~TUSB_INT_SRC_RESERVED_BITS;
  709. DBG(3, "TUSB IRQ %08x\n", int_src);
  710. musb->int_usb = (u8) int_src;
  711. /* Acknowledge wake-up source interrupts */
  712. if (int_src & TUSB_INT_SRC_DEV_WAKEUP) {
  713. u32 reg;
  714. u32 i;
  715. if (tusb_get_revision(musb) == TUSB_REV_30)
  716. tusb_wbus_quirk(musb, 0);
  717. /* there are issues re-locking the PLL on wakeup ... */
  718. /* work around issue 8 */
  719. for (i = 0xf7f7f7; i > 0xf7f7f7 - 1000; i--) {
  720. musb_writel(tbase, TUSB_SCRATCH_PAD, 0);
  721. musb_writel(tbase, TUSB_SCRATCH_PAD, i);
  722. reg = musb_readl(tbase, TUSB_SCRATCH_PAD);
  723. if (reg == i)
  724. break;
  725. DBG(6, "TUSB NOR not ready\n");
  726. }
  727. /* work around issue 13 (2nd half) */
  728. tusb_set_clock_source(musb, 1);
  729. reg = musb_readl(tbase, TUSB_PRCM_WAKEUP_SOURCE);
  730. musb_writel(tbase, TUSB_PRCM_WAKEUP_CLEAR, reg);
  731. if (reg & ~TUSB_PRCM_WNORCS) {
  732. musb->is_active = 1;
  733. schedule_work(&musb->irq_work);
  734. }
  735. DBG(3, "wake %sactive %02x\n",
  736. musb->is_active ? "" : "in", reg);
  737. /* REVISIT host side TUSB_PRCM_WHOSTDISCON, TUSB_PRCM_WBUS */
  738. }
  739. if (int_src & TUSB_INT_SRC_USB_IP_CONN)
  740. del_timer(&musb_idle_timer);
  741. /* OTG state change reports (annoyingly) not issued by Mentor core */
  742. if (int_src & (TUSB_INT_SRC_VBUS_SENSE_CHNG
  743. | TUSB_INT_SRC_OTG_TIMEOUT
  744. | TUSB_INT_SRC_ID_STATUS_CHNG))
  745. idle_timeout = tusb_otg_ints(musb, int_src, tbase);
  746. /* TX dma callback must be handled here, RX dma callback is
  747. * handled in tusb_omap_dma_cb.
  748. */
  749. if ((int_src & TUSB_INT_SRC_TXRX_DMA_DONE)) {
  750. u32 dma_src = musb_readl(tbase, TUSB_DMA_INT_SRC);
  751. u32 real_dma_src = musb_readl(tbase, TUSB_DMA_INT_MASK);
  752. DBG(3, "DMA IRQ %08x\n", dma_src);
  753. real_dma_src = ~real_dma_src & dma_src;
  754. if (tusb_dma_omap() && real_dma_src) {
  755. int tx_source = (real_dma_src & 0xffff);
  756. int i;
  757. for (i = 1; i <= 15; i++) {
  758. if (tx_source & (1 << i)) {
  759. DBG(3, "completing ep%i %s\n", i, "tx");
  760. musb_dma_completion(musb, i, 1);
  761. }
  762. }
  763. }
  764. musb_writel(tbase, TUSB_DMA_INT_CLEAR, dma_src);
  765. }
  766. /* EP interrupts. In OCP mode tusb6010 mirrors the MUSB interrupts */
  767. if (int_src & (TUSB_INT_SRC_USB_IP_TX | TUSB_INT_SRC_USB_IP_RX)) {
  768. u32 musb_src = musb_readl(tbase, TUSB_USBIP_INT_SRC);
  769. musb_writel(tbase, TUSB_USBIP_INT_CLEAR, musb_src);
  770. musb->int_rx = (((musb_src >> 16) & 0xffff) << 1);
  771. musb->int_tx = (musb_src & 0xffff);
  772. } else {
  773. musb->int_rx = 0;
  774. musb->int_tx = 0;
  775. }
  776. if (int_src & (TUSB_INT_SRC_USB_IP_TX | TUSB_INT_SRC_USB_IP_RX | 0xff))
  777. musb_interrupt(musb);
  778. /* Acknowledge TUSB interrupts. Clear only non-reserved bits */
  779. musb_writel(tbase, TUSB_INT_SRC_CLEAR,
  780. int_src & ~TUSB_INT_MASK_RESERVED_BITS);
  781. musb_platform_try_idle(musb, idle_timeout);
  782. musb_writel(tbase, TUSB_INT_MASK, int_mask);
  783. spin_unlock_irqrestore(&musb->lock, flags);
  784. return IRQ_HANDLED;
  785. }
  786. static int dma_off;
  787. /*
  788. * Enables TUSB6010. Caller must take care of locking.
  789. * REVISIT:
  790. * - Check what is unnecessary in MGC_HdrcStart()
  791. */
  792. void musb_platform_enable(struct musb *musb)
  793. {
  794. void __iomem *tbase = musb->ctrl_base;
  795. /* Setup TUSB6010 main interrupt mask. Enable all interrupts except SOF.
  796. * REVISIT: Enable and deal with TUSB_INT_SRC_USB_IP_SOF */
  797. musb_writel(tbase, TUSB_INT_MASK, TUSB_INT_SRC_USB_IP_SOF);
  798. /* Setup TUSB interrupt, disable DMA and GPIO interrupts */
  799. musb_writel(tbase, TUSB_USBIP_INT_MASK, 0);
  800. musb_writel(tbase, TUSB_DMA_INT_MASK, 0x7fffffff);
  801. musb_writel(tbase, TUSB_GPIO_INT_MASK, 0x1ff);
  802. /* Clear all subsystem interrups */
  803. musb_writel(tbase, TUSB_USBIP_INT_CLEAR, 0x7fffffff);
  804. musb_writel(tbase, TUSB_DMA_INT_CLEAR, 0x7fffffff);
  805. musb_writel(tbase, TUSB_GPIO_INT_CLEAR, 0x1ff);
  806. /* Acknowledge pending interrupt(s) */
  807. musb_writel(tbase, TUSB_INT_SRC_CLEAR, ~TUSB_INT_MASK_RESERVED_BITS);
  808. /* Only 0 clock cycles for minimum interrupt de-assertion time and
  809. * interrupt polarity active low seems to work reliably here */
  810. musb_writel(tbase, TUSB_INT_CTRL_CONF,
  811. TUSB_INT_CTRL_CONF_INT_RELCYC(0));
  812. set_irq_type(musb->nIrq, IRQ_TYPE_LEVEL_LOW);
  813. /* maybe force into the Default-A OTG state machine */
  814. if (!(musb_readl(tbase, TUSB_DEV_OTG_STAT)
  815. & TUSB_DEV_OTG_STAT_ID_STATUS))
  816. musb_writel(tbase, TUSB_INT_SRC_SET,
  817. TUSB_INT_SRC_ID_STATUS_CHNG);
  818. if (is_dma_capable() && dma_off)
  819. printk(KERN_WARNING "%s %s: dma not reactivated\n",
  820. __FILE__, __func__);
  821. else
  822. dma_off = 1;
  823. }
  824. /*
  825. * Disables TUSB6010. Caller must take care of locking.
  826. */
  827. void musb_platform_disable(struct musb *musb)
  828. {
  829. void __iomem *tbase = musb->ctrl_base;
  830. /* FIXME stop DMA, IRQs, timers, ... */
  831. /* disable all IRQs */
  832. musb_writel(tbase, TUSB_INT_MASK, ~TUSB_INT_MASK_RESERVED_BITS);
  833. musb_writel(tbase, TUSB_USBIP_INT_MASK, 0x7fffffff);
  834. musb_writel(tbase, TUSB_DMA_INT_MASK, 0x7fffffff);
  835. musb_writel(tbase, TUSB_GPIO_INT_MASK, 0x1ff);
  836. del_timer(&musb_idle_timer);
  837. if (is_dma_capable() && !dma_off) {
  838. printk(KERN_WARNING "%s %s: dma still active\n",
  839. __FILE__, __func__);
  840. dma_off = 1;
  841. }
  842. }
  843. /*
  844. * Sets up TUSB6010 CPU interface specific signals and registers
  845. * Note: Settings optimized for OMAP24xx
  846. */
  847. static void __init tusb_setup_cpu_interface(struct musb *musb)
  848. {
  849. void __iomem *tbase = musb->ctrl_base;
  850. /*
  851. * Disable GPIO[5:0] pullups (used as output DMA requests)
  852. * Don't disable GPIO[7:6] as they are needed for wake-up.
  853. */
  854. musb_writel(tbase, TUSB_PULLUP_1_CTRL, 0x0000003F);
  855. /* Disable all pullups on NOR IF, DMAREQ0 and DMAREQ1 */
  856. musb_writel(tbase, TUSB_PULLUP_2_CTRL, 0x01FFFFFF);
  857. /* Turn GPIO[5:0] to DMAREQ[5:0] signals */
  858. musb_writel(tbase, TUSB_GPIO_CONF, TUSB_GPIO_CONF_DMAREQ(0x3f));
  859. /* Burst size 16x16 bits, all six DMA requests enabled, DMA request
  860. * de-assertion time 2 system clocks p 62 */
  861. musb_writel(tbase, TUSB_DMA_REQ_CONF,
  862. TUSB_DMA_REQ_CONF_BURST_SIZE(2) |
  863. TUSB_DMA_REQ_CONF_DMA_REQ_EN(0x3f) |
  864. TUSB_DMA_REQ_CONF_DMA_REQ_ASSER(2));
  865. /* Set 0 wait count for synchronous burst access */
  866. musb_writel(tbase, TUSB_WAIT_COUNT, 1);
  867. }
  868. static int __init tusb_start(struct musb *musb)
  869. {
  870. void __iomem *tbase = musb->ctrl_base;
  871. int ret = 0;
  872. unsigned long flags;
  873. u32 reg;
  874. if (musb->board_set_power)
  875. ret = musb->board_set_power(1);
  876. if (ret != 0) {
  877. printk(KERN_ERR "tusb: Cannot enable TUSB6010\n");
  878. return ret;
  879. }
  880. spin_lock_irqsave(&musb->lock, flags);
  881. if (musb_readl(tbase, TUSB_PROD_TEST_RESET) !=
  882. TUSB_PROD_TEST_RESET_VAL) {
  883. printk(KERN_ERR "tusb: Unable to detect TUSB6010\n");
  884. goto err;
  885. }
  886. ret = tusb_print_revision(musb);
  887. if (ret < 2) {
  888. printk(KERN_ERR "tusb: Unsupported TUSB6010 revision %i\n",
  889. ret);
  890. goto err;
  891. }
  892. /* The uint bit for "USB non-PDR interrupt enable" has to be 1 when
  893. * NOR FLASH interface is used */
  894. musb_writel(tbase, TUSB_VLYNQ_CTRL, 8);
  895. /* Select PHY free running 60MHz as a system clock */
  896. tusb_set_clock_source(musb, 1);
  897. /* VBus valid timer 1us, disable DFT/Debug and VLYNQ clocks for
  898. * power saving, enable VBus detect and session end comparators,
  899. * enable IDpullup, enable VBus charging */
  900. musb_writel(tbase, TUSB_PRCM_MNGMT,
  901. TUSB_PRCM_MNGMT_VBUS_VALID_TIMER(0xa) |
  902. TUSB_PRCM_MNGMT_VBUS_VALID_FLT_EN |
  903. TUSB_PRCM_MNGMT_OTG_SESS_END_EN |
  904. TUSB_PRCM_MNGMT_OTG_VBUS_DET_EN |
  905. TUSB_PRCM_MNGMT_OTG_ID_PULLUP);
  906. tusb_setup_cpu_interface(musb);
  907. /* simplify: always sense/pullup ID pins, as if in OTG mode */
  908. reg = musb_readl(tbase, TUSB_PHY_OTG_CTRL_ENABLE);
  909. reg |= TUSB_PHY_OTG_CTRL_WRPROTECT | TUSB_PHY_OTG_CTRL_OTG_ID_PULLUP;
  910. musb_writel(tbase, TUSB_PHY_OTG_CTRL_ENABLE, reg);
  911. reg = musb_readl(tbase, TUSB_PHY_OTG_CTRL);
  912. reg |= TUSB_PHY_OTG_CTRL_WRPROTECT | TUSB_PHY_OTG_CTRL_OTG_ID_PULLUP;
  913. musb_writel(tbase, TUSB_PHY_OTG_CTRL, reg);
  914. spin_unlock_irqrestore(&musb->lock, flags);
  915. return 0;
  916. err:
  917. spin_unlock_irqrestore(&musb->lock, flags);
  918. if (musb->board_set_power)
  919. musb->board_set_power(0);
  920. return -ENODEV;
  921. }
  922. int __init musb_platform_init(struct musb *musb)
  923. {
  924. struct platform_device *pdev;
  925. struct resource *mem;
  926. void __iomem *sync;
  927. int ret;
  928. pdev = to_platform_device(musb->controller);
  929. /* dma address for async dma */
  930. mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  931. musb->async = mem->start;
  932. /* dma address for sync dma */
  933. mem = platform_get_resource(pdev, IORESOURCE_MEM, 1);
  934. if (!mem) {
  935. pr_debug("no sync dma resource?\n");
  936. return -ENODEV;
  937. }
  938. musb->sync = mem->start;
  939. sync = ioremap(mem->start, mem->end - mem->start + 1);
  940. if (!sync) {
  941. pr_debug("ioremap for sync failed\n");
  942. return -ENOMEM;
  943. }
  944. musb->sync_va = sync;
  945. /* Offsets from base: VLYNQ at 0x000, MUSB regs at 0x400,
  946. * FIFOs at 0x600, TUSB at 0x800
  947. */
  948. musb->mregs += TUSB_BASE_OFFSET;
  949. ret = tusb_start(musb);
  950. if (ret) {
  951. printk(KERN_ERR "Could not start tusb6010 (%d)\n",
  952. ret);
  953. return -ENODEV;
  954. }
  955. musb->isr = tusb_interrupt;
  956. if (is_host_enabled(musb))
  957. musb->board_set_vbus = tusb_source_power;
  958. if (is_peripheral_enabled(musb))
  959. musb->xceiv.set_power = tusb_draw_power;
  960. setup_timer(&musb_idle_timer, musb_do_idle, (unsigned long) musb);
  961. return ret;
  962. }
  963. int musb_platform_exit(struct musb *musb)
  964. {
  965. del_timer_sync(&musb_idle_timer);
  966. if (musb->board_set_power)
  967. musb->board_set_power(0);
  968. iounmap(musb->sync_va);
  969. return 0;
  970. }