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