aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb
diff options
context:
space:
mode:
authorFelipe Balbi <balbi@ti.com>2011-11-24 08:46:26 -0500
committerFelipe Balbi <balbi@ti.com>2012-08-09 05:34:46 -0400
commit032ec49f5351e9cb242b1a1c367d14415043ab95 (patch)
treec23887e0302e4fa10a5ee6501a85e69bbd802475 /drivers/usb
parent4f3e8d263d34e52e75b5adfa14811467d3033d8e (diff)
usb: musb: drop useless board_mode usage
we are compiling the driver always with full OTG capabilities, so that board_mode trick becomes useless. Signed-off-by: Felipe Balbi <balbi@ti.com>
Diffstat (limited to 'drivers/usb')
-rw-r--r--drivers/usb/musb/am35x.c24
-rw-r--r--drivers/usb/musb/blackfin.c37
-rw-r--r--drivers/usb/musb/da8xx.c24
-rw-r--r--drivers/usb/musb/davinci.c32
-rw-r--r--drivers/usb/musb/musb_core.c210
-rw-r--r--drivers/usb/musb/musb_core.h5
-rw-r--r--drivers/usb/musb/musb_dsps.c26
-rw-r--r--drivers/usb/musb/musb_gadget.c83
-rw-r--r--drivers/usb/musb/musb_virthub.c13
-rw-r--r--drivers/usb/musb/omap2430.c11
-rw-r--r--drivers/usb/musb/tusb6010.c28
11 files changed, 159 insertions, 334 deletions
diff --git a/drivers/usb/musb/am35x.c b/drivers/usb/musb/am35x.c
index 7a95ab87ac00..9fbe73688037 100644
--- a/drivers/usb/musb/am35x.c
+++ b/drivers/usb/musb/am35x.c
@@ -107,9 +107,8 @@ static void am35x_musb_enable(struct musb *musb)
107 musb_writel(reg_base, CORE_INTR_MASK_SET_REG, AM35X_INTR_USB_MASK); 107 musb_writel(reg_base, CORE_INTR_MASK_SET_REG, AM35X_INTR_USB_MASK);
108 108
109 /* Force the DRVVBUS IRQ so we can start polling for ID change. */ 109 /* Force the DRVVBUS IRQ so we can start polling for ID change. */
110 if (is_otg_enabled(musb)) 110 musb_writel(reg_base, CORE_INTR_SRC_SET_REG,
111 musb_writel(reg_base, CORE_INTR_SRC_SET_REG, 111 AM35X_INTR_DRVVBUS << AM35X_INTR_USB_SHIFT);
112 AM35X_INTR_DRVVBUS << AM35X_INTR_USB_SHIFT);
113} 112}
114 113
115/* 114/*
@@ -173,9 +172,6 @@ static void otg_timer(unsigned long _musb)
173 MUSB_INTR_VBUSERROR << AM35X_INTR_USB_SHIFT); 172 MUSB_INTR_VBUSERROR << AM35X_INTR_USB_SHIFT);
174 break; 173 break;
175 case OTG_STATE_B_IDLE: 174 case OTG_STATE_B_IDLE:
176 if (!is_peripheral_enabled(musb))
177 break;
178
179 devctl = musb_readb(mregs, MUSB_DEVCTL); 175 devctl = musb_readb(mregs, MUSB_DEVCTL);
180 if (devctl & MUSB_DEVCTL_BDEVICE) 176 if (devctl & MUSB_DEVCTL_BDEVICE)
181 mod_timer(&otg_workaround, jiffies + POLL_SECONDS * HZ); 177 mod_timer(&otg_workaround, jiffies + POLL_SECONDS * HZ);
@@ -192,9 +188,6 @@ static void am35x_musb_try_idle(struct musb *musb, unsigned long timeout)
192{ 188{
193 static unsigned long last_timer; 189 static unsigned long last_timer;
194 190
195 if (!is_otg_enabled(musb))
196 return;
197
198 if (timeout == 0) 191 if (timeout == 0)
199 timeout = jiffies + msecs_to_jiffies(3); 192 timeout = jiffies + msecs_to_jiffies(3);
200 193
@@ -271,8 +264,7 @@ static irqreturn_t am35x_musb_interrupt(int irq, void *hci)
271 u8 devctl = musb_readb(mregs, MUSB_DEVCTL); 264 u8 devctl = musb_readb(mregs, MUSB_DEVCTL);
272 int err; 265 int err;
273 266
274 err = is_host_enabled(musb) && (musb->int_usb & 267 err = musb->int_usb & MUSB_INTR_VBUSERROR;
275 MUSB_INTR_VBUSERROR);
276 if (err) { 268 if (err) {
277 /* 269 /*
278 * The Mentor core doesn't debounce VBUS as needed 270 * The Mentor core doesn't debounce VBUS as needed
@@ -289,7 +281,7 @@ static irqreturn_t am35x_musb_interrupt(int irq, void *hci)
289 musb->xceiv->state = OTG_STATE_A_WAIT_VFALL; 281 musb->xceiv->state = OTG_STATE_A_WAIT_VFALL;
290 mod_timer(&otg_workaround, jiffies + POLL_SECONDS * HZ); 282 mod_timer(&otg_workaround, jiffies + POLL_SECONDS * HZ);
291 WARNING("VBUS error workaround (delay coming)\n"); 283 WARNING("VBUS error workaround (delay coming)\n");
292 } else if (is_host_enabled(musb) && drvvbus) { 284 } else if (drvvbus) {
293 MUSB_HST_MODE(musb); 285 MUSB_HST_MODE(musb);
294 otg->default_a = 1; 286 otg->default_a = 1;
295 musb->xceiv->state = OTG_STATE_A_WAIT_VRISE; 287 musb->xceiv->state = OTG_STATE_A_WAIT_VRISE;
@@ -326,7 +318,7 @@ eoi:
326 } 318 }
327 319
328 /* Poll for ID change */ 320 /* Poll for ID change */
329 if (is_otg_enabled(musb) && musb->xceiv->state == OTG_STATE_B_IDLE) 321 if (musb->xceiv->state == OTG_STATE_B_IDLE)
330 mod_timer(&otg_workaround, jiffies + POLL_SECONDS * HZ); 322 mod_timer(&otg_workaround, jiffies + POLL_SECONDS * HZ);
331 323
332 spin_unlock_irqrestore(&musb->lock, flags); 324 spin_unlock_irqrestore(&musb->lock, flags);
@@ -369,8 +361,7 @@ static int am35x_musb_init(struct musb *musb)
369 if (IS_ERR_OR_NULL(musb->xceiv)) 361 if (IS_ERR_OR_NULL(musb->xceiv))
370 return -ENODEV; 362 return -ENODEV;
371 363
372 if (is_host_enabled(musb)) 364 setup_timer(&otg_workaround, otg_timer, (unsigned long) musb);
373 setup_timer(&otg_workaround, otg_timer, (unsigned long) musb);
374 365
375 /* Reset the musb */ 366 /* Reset the musb */
376 if (data->reset) 367 if (data->reset)
@@ -400,8 +391,7 @@ static int am35x_musb_exit(struct musb *musb)
400 struct musb_hdrc_platform_data *plat = dev->platform_data; 391 struct musb_hdrc_platform_data *plat = dev->platform_data;
401 struct omap_musb_board_data *data = plat->board_data; 392 struct omap_musb_board_data *data = plat->board_data;
402 393
403 if (is_host_enabled(musb)) 394 del_timer_sync(&otg_workaround);
404 del_timer_sync(&otg_workaround);
405 395
406 /* Shutdown the on-chip PHY and its PLL. */ 396 /* Shutdown the on-chip PHY and its PLL. */
407 if (data->set_phy_power) 397 if (data->set_phy_power)
diff --git a/drivers/usb/musb/blackfin.c b/drivers/usb/musb/blackfin.c
index 428e6aa3e78a..54f1b98b74de 100644
--- a/drivers/usb/musb/blackfin.c
+++ b/drivers/usb/musb/blackfin.c
@@ -184,8 +184,8 @@ static irqreturn_t blackfin_interrupt(int irq, void *__hci)
184 } 184 }
185 185
186 /* Start sampling ID pin, when plug is removed from MUSB */ 186 /* Start sampling ID pin, when plug is removed from MUSB */
187 if ((is_otg_enabled(musb) && (musb->xceiv->state == OTG_STATE_B_IDLE 187 if ((musb->xceiv->state == OTG_STATE_B_IDLE
188 || musb->xceiv->state == OTG_STATE_A_WAIT_BCON)) || 188 || musb->xceiv->state == OTG_STATE_A_WAIT_BCON) ||
189 (musb->int_usb & MUSB_INTR_DISCONNECT && is_host_active(musb))) { 189 (musb->int_usb & MUSB_INTR_DISCONNECT && is_host_active(musb))) {
190 mod_timer(&musb_conn_timer, jiffies + TIMER_DELAY); 190 mod_timer(&musb_conn_timer, jiffies + TIMER_DELAY);
191 musb->a_wait_bcon = TIMER_DELAY; 191 musb->a_wait_bcon = TIMER_DELAY;
@@ -228,18 +228,13 @@ static void musb_conn_timer_handler(unsigned long _musb)
228 228
229 val = MUSB_INTR_SUSPEND | MUSB_INTR_VBUSERROR; 229 val = MUSB_INTR_SUSPEND | MUSB_INTR_VBUSERROR;
230 musb_writeb(musb->mregs, MUSB_INTRUSB, val); 230 musb_writeb(musb->mregs, MUSB_INTRUSB, val);
231 if (is_otg_enabled(musb)) 231 musb->xceiv->state = OTG_STATE_B_IDLE;
232 musb->xceiv->state = OTG_STATE_B_IDLE;
233 else
234 musb_writeb(musb->mregs, MUSB_POWER, MUSB_POWER_HSENAB);
235 } 232 }
236 mod_timer(&musb_conn_timer, jiffies + TIMER_DELAY); 233 mod_timer(&musb_conn_timer, jiffies + TIMER_DELAY);
237 break; 234 break;
238 case OTG_STATE_B_IDLE: 235 case OTG_STATE_B_IDLE:
239 236 /*
240 if (!is_peripheral_enabled(musb)) 237 * Start a new session. It seems that MUSB needs taking
241 break;
242 /* Start a new session. It seems that MUSB needs taking
243 * some time to recognize the type of the plug inserted? 238 * some time to recognize the type of the plug inserted?
244 */ 239 */
245 val = musb_readw(musb->mregs, MUSB_DEVCTL); 240 val = musb_readw(musb->mregs, MUSB_DEVCTL);
@@ -295,10 +290,7 @@ static void musb_conn_timer_handler(unsigned long _musb)
295 290
296static void bfin_musb_enable(struct musb *musb) 291static void bfin_musb_enable(struct musb *musb)
297{ 292{
298 if (!is_otg_enabled(musb) && is_host_enabled(musb)) { 293 /* REVISIT is this really correct ? */
299 mod_timer(&musb_conn_timer, jiffies + TIMER_DELAY);
300 musb->a_wait_bcon = TIMER_DELAY;
301 }
302} 294}
303 295
304static void bfin_musb_disable(struct musb *musb) 296static void bfin_musb_disable(struct musb *musb)
@@ -323,12 +315,6 @@ static int bfin_musb_set_power(struct usb_phy *x, unsigned mA)
323 return 0; 315 return 0;
324} 316}
325 317
326static void bfin_musb_try_idle(struct musb *musb, unsigned long timeout)
327{
328 if (!is_otg_enabled(musb) && is_host_enabled(musb))
329 mod_timer(&musb_conn_timer, jiffies + TIMER_DELAY);
330}
331
332static int bfin_musb_vbus_status(struct musb *musb) 318static int bfin_musb_vbus_status(struct musb *musb)
333{ 319{
334 return 0; 320 return 0;
@@ -424,12 +410,10 @@ static int bfin_musb_init(struct musb *musb)
424 410
425 bfin_musb_reg_init(musb); 411 bfin_musb_reg_init(musb);
426 412
427 if (is_host_enabled(musb)) { 413 setup_timer(&musb_conn_timer, musb_conn_timer_handler,
428 setup_timer(&musb_conn_timer, 414 (unsigned long) musb);
429 musb_conn_timer_handler, (unsigned long) musb); 415
430 } 416 musb->xceiv->set_power = bfin_musb_set_power;
431 if (is_peripheral_enabled(musb))
432 musb->xceiv->set_power = bfin_musb_set_power;
433 417
434 musb->isr = blackfin_interrupt; 418 musb->isr = blackfin_interrupt;
435 musb->double_buffer_not_ok = true; 419 musb->double_buffer_not_ok = true;
@@ -454,7 +438,6 @@ static const struct musb_platform_ops bfin_ops = {
454 .disable = bfin_musb_disable, 438 .disable = bfin_musb_disable,
455 439
456 .set_mode = bfin_musb_set_mode, 440 .set_mode = bfin_musb_set_mode,
457 .try_idle = bfin_musb_try_idle,
458 441
459 .vbus_status = bfin_musb_vbus_status, 442 .vbus_status = bfin_musb_vbus_status,
460 .set_vbus = bfin_musb_set_vbus, 443 .set_vbus = bfin_musb_set_vbus,
diff --git a/drivers/usb/musb/da8xx.c b/drivers/usb/musb/da8xx.c
index 0f9fcec4e1d3..4e4df9d2eee2 100644
--- a/drivers/usb/musb/da8xx.c
+++ b/drivers/usb/musb/da8xx.c
@@ -155,9 +155,8 @@ static void da8xx_musb_enable(struct musb *musb)
155 musb_writel(reg_base, DA8XX_USB_INTR_MASK_SET_REG, mask); 155 musb_writel(reg_base, DA8XX_USB_INTR_MASK_SET_REG, mask);
156 156
157 /* Force the DRVVBUS IRQ so we can start polling for ID change. */ 157 /* Force the DRVVBUS IRQ so we can start polling for ID change. */
158 if (is_otg_enabled(musb)) 158 musb_writel(reg_base, DA8XX_USB_INTR_SRC_SET_REG,
159 musb_writel(reg_base, DA8XX_USB_INTR_SRC_SET_REG, 159 DA8XX_INTR_DRVVBUS << DA8XX_INTR_USB_SHIFT);
160 DA8XX_INTR_DRVVBUS << DA8XX_INTR_USB_SHIFT);
161} 160}
162 161
163/** 162/**
@@ -231,9 +230,6 @@ static void otg_timer(unsigned long _musb)
231 MUSB_INTR_VBUSERROR << DA8XX_INTR_USB_SHIFT); 230 MUSB_INTR_VBUSERROR << DA8XX_INTR_USB_SHIFT);
232 break; 231 break;
233 case OTG_STATE_B_IDLE: 232 case OTG_STATE_B_IDLE:
234 if (!is_peripheral_enabled(musb))
235 break;
236
237 /* 233 /*
238 * There's no ID-changed IRQ, so we have no good way to tell 234 * There's no ID-changed IRQ, so we have no good way to tell
239 * when to switch to the A-Default state machine (by setting 235 * when to switch to the A-Default state machine (by setting
@@ -263,9 +259,6 @@ static void da8xx_musb_try_idle(struct musb *musb, unsigned long timeout)
263{ 259{
264 static unsigned long last_timer; 260 static unsigned long last_timer;
265 261
266 if (!is_otg_enabled(musb))
267 return;
268
269 if (timeout == 0) 262 if (timeout == 0)
270 timeout = jiffies + msecs_to_jiffies(3); 263 timeout = jiffies + msecs_to_jiffies(3);
271 264
@@ -333,8 +326,7 @@ static irqreturn_t da8xx_musb_interrupt(int irq, void *hci)
333 u8 devctl = musb_readb(mregs, MUSB_DEVCTL); 326 u8 devctl = musb_readb(mregs, MUSB_DEVCTL);
334 int err; 327 int err;
335 328
336 err = is_host_enabled(musb) && (musb->int_usb & 329 err = musb->int_usb & USB_INTR_VBUSERROR;
337 MUSB_INTR_VBUSERROR);
338 if (err) { 330 if (err) {
339 /* 331 /*
340 * The Mentor core doesn't debounce VBUS as needed 332 * The Mentor core doesn't debounce VBUS as needed
@@ -351,7 +343,7 @@ static irqreturn_t da8xx_musb_interrupt(int irq, void *hci)
351 musb->xceiv->state = OTG_STATE_A_WAIT_VFALL; 343 musb->xceiv->state = OTG_STATE_A_WAIT_VFALL;
352 mod_timer(&otg_workaround, jiffies + POLL_SECONDS * HZ); 344 mod_timer(&otg_workaround, jiffies + POLL_SECONDS * HZ);
353 WARNING("VBUS error workaround (delay coming)\n"); 345 WARNING("VBUS error workaround (delay coming)\n");
354 } else if (is_host_enabled(musb) && drvvbus) { 346 } else if (drvvbus) {
355 MUSB_HST_MODE(musb); 347 MUSB_HST_MODE(musb);
356 otg->default_a = 1; 348 otg->default_a = 1;
357 musb->xceiv->state = OTG_STATE_A_WAIT_VRISE; 349 musb->xceiv->state = OTG_STATE_A_WAIT_VRISE;
@@ -382,7 +374,7 @@ static irqreturn_t da8xx_musb_interrupt(int irq, void *hci)
382 musb_writel(reg_base, DA8XX_USB_END_OF_INTR_REG, 0); 374 musb_writel(reg_base, DA8XX_USB_END_OF_INTR_REG, 0);
383 375
384 /* Poll for ID change */ 376 /* Poll for ID change */
385 if (is_otg_enabled(musb) && musb->xceiv->state == OTG_STATE_B_IDLE) 377 if (musb->xceiv->state == OTG_STATE_B_IDLE)
386 mod_timer(&otg_workaround, jiffies + POLL_SECONDS * HZ); 378 mod_timer(&otg_workaround, jiffies + POLL_SECONDS * HZ);
387 379
388 spin_unlock_irqrestore(&musb->lock, flags); 380 spin_unlock_irqrestore(&musb->lock, flags);
@@ -430,8 +422,7 @@ static int da8xx_musb_init(struct musb *musb)
430 if (IS_ERR_OR_NULL(musb->xceiv)) 422 if (IS_ERR_OR_NULL(musb->xceiv))
431 goto fail; 423 goto fail;
432 424
433 if (is_host_enabled(musb)) 425 setup_timer(&otg_workaround, otg_timer, (unsigned long)musb);
434 setup_timer(&otg_workaround, otg_timer, (unsigned long)musb);
435 426
436 /* Reset the controller */ 427 /* Reset the controller */
437 musb_writel(reg_base, DA8XX_USB_CTRL_REG, DA8XX_SOFT_RESET_MASK); 428 musb_writel(reg_base, DA8XX_USB_CTRL_REG, DA8XX_SOFT_RESET_MASK);
@@ -454,8 +445,7 @@ fail:
454 445
455static int da8xx_musb_exit(struct musb *musb) 446static int da8xx_musb_exit(struct musb *musb)
456{ 447{
457 if (is_host_enabled(musb)) 448 del_timer_sync(&otg_workaround);
458 del_timer_sync(&otg_workaround);
459 449
460 phy_off(); 450 phy_off();
461 451
diff --git a/drivers/usb/musb/davinci.c b/drivers/usb/musb/davinci.c
index 472c8b42d38b..8805f809175c 100644
--- a/drivers/usb/musb/davinci.c
+++ b/drivers/usb/musb/davinci.c
@@ -115,8 +115,7 @@ static void davinci_musb_enable(struct musb *musb)
115 dma_off = 0; 115 dma_off = 0;
116 116
117 /* force a DRVVBUS irq so we can start polling for ID change */ 117 /* force a DRVVBUS irq so we can start polling for ID change */
118 if (is_otg_enabled(musb)) 118 musb_writel(musb->ctrl_base, DAVINCI_USB_INT_SET_REG,
119 musb_writel(musb->ctrl_base, DAVINCI_USB_INT_SET_REG,
120 DAVINCI_INTR_DRVVBUS << DAVINCI_USB_USBINT_SHIFT); 119 DAVINCI_INTR_DRVVBUS << DAVINCI_USB_USBINT_SHIFT);
121} 120}
122 121
@@ -234,10 +233,8 @@ static void otg_timer(unsigned long _musb)
234 MUSB_INTR_VBUSERROR << DAVINCI_USB_USBINT_SHIFT); 233 MUSB_INTR_VBUSERROR << DAVINCI_USB_USBINT_SHIFT);
235 break; 234 break;
236 case OTG_STATE_B_IDLE: 235 case OTG_STATE_B_IDLE:
237 if (!is_peripheral_enabled(musb)) 236 /*
238 break; 237 * There's no ID-changed IRQ, so we have no good way to tell
239
240 /* There's no ID-changed IRQ, so we have no good way to tell
241 * when to switch to the A-Default state machine (by setting 238 * when to switch to the A-Default state machine (by setting
242 * the DEVCTL.SESSION flag). 239 * the DEVCTL.SESSION flag).
243 * 240 *
@@ -315,8 +312,7 @@ static irqreturn_t davinci_musb_interrupt(int irq, void *__hci)
315 u8 devctl = musb_readb(mregs, MUSB_DEVCTL); 312 u8 devctl = musb_readb(mregs, MUSB_DEVCTL);
316 int err = musb->int_usb & MUSB_INTR_VBUSERROR; 313 int err = musb->int_usb & MUSB_INTR_VBUSERROR;
317 314
318 err = is_host_enabled(musb) 315 err = musb->int_usb & MUSB_INTR_VBUSERROR;
319 && (musb->int_usb & MUSB_INTR_VBUSERROR);
320 if (err) { 316 if (err) {
321 /* The Mentor core doesn't debounce VBUS as needed 317 /* The Mentor core doesn't debounce VBUS as needed
322 * to cope with device connect current spikes. This 318 * to cope with device connect current spikes. This
@@ -332,7 +328,7 @@ static irqreturn_t davinci_musb_interrupt(int irq, void *__hci)
332 musb->xceiv->state = OTG_STATE_A_WAIT_VFALL; 328 musb->xceiv->state = OTG_STATE_A_WAIT_VFALL;
333 mod_timer(&otg_workaround, jiffies + POLL_SECONDS * HZ); 329 mod_timer(&otg_workaround, jiffies + POLL_SECONDS * HZ);
334 WARNING("VBUS error workaround (delay coming)\n"); 330 WARNING("VBUS error workaround (delay coming)\n");
335 } else if (is_host_enabled(musb) && drvvbus) { 331 } else if (drvvbus) {
336 MUSB_HST_MODE(musb); 332 MUSB_HST_MODE(musb);
337 otg->default_a = 1; 333 otg->default_a = 1;
338 musb->xceiv->state = OTG_STATE_A_WAIT_VRISE; 334 musb->xceiv->state = OTG_STATE_A_WAIT_VRISE;
@@ -365,8 +361,7 @@ static irqreturn_t davinci_musb_interrupt(int irq, void *__hci)
365 musb_writel(tibase, DAVINCI_USB_EOI_REG, 0); 361 musb_writel(tibase, DAVINCI_USB_EOI_REG, 0);
366 362
367 /* poll for ID change */ 363 /* poll for ID change */
368 if (is_otg_enabled(musb) 364 if (musb->xceiv->state == OTG_STATE_B_IDLE)
369 && musb->xceiv->state == OTG_STATE_B_IDLE)
370 mod_timer(&otg_workaround, jiffies + POLL_SECONDS * HZ); 365 mod_timer(&otg_workaround, jiffies + POLL_SECONDS * HZ);
371 366
372 spin_unlock_irqrestore(&musb->lock, flags); 367 spin_unlock_irqrestore(&musb->lock, flags);
@@ -397,8 +392,7 @@ static int davinci_musb_init(struct musb *musb)
397 if (revision == 0) 392 if (revision == 0)
398 goto fail; 393 goto fail;
399 394
400 if (is_host_enabled(musb)) 395 setup_timer(&otg_workaround, otg_timer, (unsigned long) musb);
401 setup_timer(&otg_workaround, otg_timer, (unsigned long) musb);
402 396
403 davinci_musb_source_power(musb, 0, 1); 397 davinci_musb_source_power(musb, 0, 1);
404 398
@@ -419,12 +413,7 @@ static int davinci_musb_init(struct musb *musb)
419 if (cpu_is_davinci_dm355()) { 413 if (cpu_is_davinci_dm355()) {
420 u32 deepsleep = __raw_readl(DM355_DEEPSLEEP); 414 u32 deepsleep = __raw_readl(DM355_DEEPSLEEP);
421 415
422 if (is_host_enabled(musb)) { 416 deepsleep &= ~DRVVBUS_FORCE;
423 deepsleep &= ~DRVVBUS_OVERRIDE;
424 } else {
425 deepsleep &= ~DRVVBUS_FORCE;
426 deepsleep |= DRVVBUS_OVERRIDE;
427 }
428 __raw_writel(deepsleep, DM355_DEEPSLEEP); 417 __raw_writel(deepsleep, DM355_DEEPSLEEP);
429 } 418 }
430 419
@@ -453,8 +442,7 @@ unregister:
453 442
454static int davinci_musb_exit(struct musb *musb) 443static int davinci_musb_exit(struct musb *musb)
455{ 444{
456 if (is_host_enabled(musb)) 445 del_timer_sync(&otg_workaround);
457 del_timer_sync(&otg_workaround);
458 446
459 /* force VBUS off */ 447 /* force VBUS off */
460 if (cpu_is_davinci_dm355()) { 448 if (cpu_is_davinci_dm355()) {
@@ -468,7 +456,7 @@ static int davinci_musb_exit(struct musb *musb)
468 davinci_musb_source_power(musb, 0 /*off*/, 1); 456 davinci_musb_source_power(musb, 0 /*off*/, 1);
469 457
470 /* delay, to avoid problems with module reload */ 458 /* delay, to avoid problems with module reload */
471 if (is_host_enabled(musb) && musb->xceiv->otg->default_a) { 459 if (musb->xceiv->otg->default_a) {
472 int maxdelay = 30; 460 int maxdelay = 30;
473 u8 devctl, warn = 0; 461 u8 devctl, warn = 0;
474 462
diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
index 65b3f5310922..3d9b64707ba3 100644
--- a/drivers/usb/musb/musb_core.c
+++ b/drivers/usb/musb/musb_core.c
@@ -649,8 +649,7 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb,
649 break; 649 break;
650 case OTG_STATE_B_PERIPHERAL: 650 case OTG_STATE_B_PERIPHERAL:
651 musb_g_suspend(musb); 651 musb_g_suspend(musb);
652 musb->is_active = is_otg_enabled(musb) 652 musb->is_active = otg->gadget->b_hnp_enable;
653 && otg->gadget->b_hnp_enable;
654 if (musb->is_active) { 653 if (musb->is_active) {
655 musb->xceiv->state = OTG_STATE_B_WAIT_ACON; 654 musb->xceiv->state = OTG_STATE_B_WAIT_ACON;
656 dev_dbg(musb->controller, "HNP: Setting timer for b_ase0_brst\n"); 655 dev_dbg(musb->controller, "HNP: Setting timer for b_ase0_brst\n");
@@ -666,8 +665,7 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb,
666 break; 665 break;
667 case OTG_STATE_A_HOST: 666 case OTG_STATE_A_HOST:
668 musb->xceiv->state = OTG_STATE_A_SUSPEND; 667 musb->xceiv->state = OTG_STATE_A_SUSPEND;
669 musb->is_active = is_otg_enabled(musb) 668 musb->is_active = otg->host->b_hnp_enable;
670 && otg->host->b_hnp_enable;
671 break; 669 break;
672 case OTG_STATE_B_HOST: 670 case OTG_STATE_B_HOST:
673 /* Transition to B_PERIPHERAL, see 6.8.2.6 p 44 */ 671 /* Transition to B_PERIPHERAL, see 6.8.2.6 p 44 */
@@ -755,7 +753,7 @@ b_host:
755 case OTG_STATE_A_SUSPEND: 753 case OTG_STATE_A_SUSPEND:
756 usb_hcd_resume_root_hub(musb_to_hcd(musb)); 754 usb_hcd_resume_root_hub(musb_to_hcd(musb));
757 musb_root_disconnect(musb); 755 musb_root_disconnect(musb);
758 if (musb->a_wait_bcon != 0 && is_otg_enabled(musb)) 756 if (musb->a_wait_bcon != 0)
759 musb_platform_try_idle(musb, jiffies 757 musb_platform_try_idle(musb, jiffies
760 + msecs_to_jiffies(musb->a_wait_bcon)); 758 + msecs_to_jiffies(musb->a_wait_bcon));
761 break; 759 break;
@@ -931,25 +929,16 @@ void musb_start(struct musb *musb)
931 devctl = musb_readb(regs, MUSB_DEVCTL); 929 devctl = musb_readb(regs, MUSB_DEVCTL);
932 devctl &= ~MUSB_DEVCTL_SESSION; 930 devctl &= ~MUSB_DEVCTL_SESSION;
933 931
934 if (is_otg_enabled(musb)) { 932 /* session started after:
935 /* session started after: 933 * (a) ID-grounded irq, host mode;
936 * (a) ID-grounded irq, host mode; 934 * (b) vbus present/connect IRQ, peripheral mode;
937 * (b) vbus present/connect IRQ, peripheral mode; 935 * (c) peripheral initiates, using SRP
938 * (c) peripheral initiates, using SRP 936 */
939 */ 937 if ((devctl & MUSB_DEVCTL_VBUS) == MUSB_DEVCTL_VBUS)
940 if ((devctl & MUSB_DEVCTL_VBUS) == MUSB_DEVCTL_VBUS) 938 musb->is_active = 1;
941 musb->is_active = 1; 939 else
942 else
943 devctl |= MUSB_DEVCTL_SESSION;
944
945 } else if (is_host_enabled(musb)) {
946 /* assume ID pin is hard-wired to ground */
947 devctl |= MUSB_DEVCTL_SESSION; 940 devctl |= MUSB_DEVCTL_SESSION;
948 941
949 } else /* peripheral is enabled */ {
950 if ((devctl & MUSB_DEVCTL_VBUS) == MUSB_DEVCTL_VBUS)
951 musb->is_active = 1;
952 }
953 musb_platform_enable(musb); 942 musb_platform_enable(musb);
954 musb_writeb(regs, MUSB_DEVCTL, devctl); 943 musb_writeb(regs, MUSB_DEVCTL, devctl);
955} 944}
@@ -1013,8 +1002,6 @@ static void musb_shutdown(struct platform_device *pdev)
1013 musb_generic_disable(musb); 1002 musb_generic_disable(musb);
1014 spin_unlock_irqrestore(&musb->lock, flags); 1003 spin_unlock_irqrestore(&musb->lock, flags);
1015 1004
1016 if (!is_otg_enabled(musb) && is_host_enabled(musb))
1017 usb_remove_hcd(musb_to_hcd(musb));
1018 musb_writeb(musb->mregs, MUSB_DEVCTL, 0); 1005 musb_writeb(musb->mregs, MUSB_DEVCTL, 0);
1019 musb_platform_exit(musb); 1006 musb_platform_exit(musb);
1020 1007
@@ -1885,6 +1872,7 @@ musb_init_controller(struct device *dev, int nIrq, void __iomem *ctrl)
1885 int status; 1872 int status;
1886 struct musb *musb; 1873 struct musb *musb;
1887 struct musb_hdrc_platform_data *plat = dev->platform_data; 1874 struct musb_hdrc_platform_data *plat = dev->platform_data;
1875 struct usb_hcd *hcd;
1888 1876
1889 /* The driver might handle more features than the board; OK. 1877 /* The driver might handle more features than the board; OK.
1890 * Fail when the board needs a feature that's not enabled. 1878 * Fail when the board needs a feature that's not enabled.
@@ -1907,7 +1895,6 @@ musb_init_controller(struct device *dev, int nIrq, void __iomem *ctrl)
1907 pm_runtime_enable(musb->controller); 1895 pm_runtime_enable(musb->controller);
1908 1896
1909 spin_lock_init(&musb->lock); 1897 spin_lock_init(&musb->lock);
1910 musb->board_mode = plat->mode;
1911 musb->board_set_power = plat->set_power; 1898 musb->board_set_power = plat->set_power;
1912 musb->min_power = plat->min_power; 1899 musb->min_power = plat->min_power;
1913 musb->ops = plat->platform_ops; 1900 musb->ops = plat->platform_ops;
@@ -1978,7 +1965,7 @@ musb_init_controller(struct device *dev, int nIrq, void __iomem *ctrl)
1978 goto fail3; 1965 goto fail3;
1979 } 1966 }
1980 musb->nIrq = nIrq; 1967 musb->nIrq = nIrq;
1981/* FIXME this handles wakeup irqs wrong */ 1968 /* FIXME this handles wakeup irqs wrong */
1982 if (enable_irq_wake(nIrq) == 0) { 1969 if (enable_irq_wake(nIrq) == 0) {
1983 musb->irq_wake = 1; 1970 musb->irq_wake = 1;
1984 device_init_wakeup(dev, 1); 1971 device_init_wakeup(dev, 1);
@@ -1987,58 +1974,25 @@ musb_init_controller(struct device *dev, int nIrq, void __iomem *ctrl)
1987 } 1974 }
1988 1975
1989 /* host side needs more setup */ 1976 /* host side needs more setup */
1990 if (is_host_enabled(musb)) { 1977 hcd = musb_to_hcd(musb);
1991 struct usb_hcd *hcd = musb_to_hcd(musb); 1978 otg_set_host(musb->xceiv->otg, &hcd->self);
1992 1979 hcd->self.otg_port = 1;
1993 otg_set_host(musb->xceiv->otg, &hcd->self); 1980 musb->xceiv->otg->host = &hcd->self;
1994 1981 hcd->power_budget = 2 * (plat->power ? : 250);
1995 if (is_otg_enabled(musb)) 1982
1996 hcd->self.otg_port = 1; 1983 /* program PHY to use external vBus if required */
1997 musb->xceiv->otg->host = &hcd->self; 1984 if (plat->extvbus) {
1998 hcd->power_budget = 2 * (plat->power ? : 250); 1985 u8 busctl = musb_read_ulpi_buscontrol(musb->mregs);
1999 1986 busctl |= MUSB_ULPI_USE_EXTVBUS;
2000 /* program PHY to use external vBus if required */ 1987 musb_write_ulpi_buscontrol(musb->mregs, busctl);
2001 if (plat->extvbus) {
2002 u8 busctl = musb_read_ulpi_buscontrol(musb->mregs);
2003 busctl |= MUSB_ULPI_USE_EXTVBUS;
2004 musb_write_ulpi_buscontrol(musb->mregs, busctl);
2005 }
2006 } 1988 }
2007 1989
2008 /* For the host-only role, we can activate right away. 1990 MUSB_DEV_MODE(musb);
2009 * (We expect the ID pin to be forcibly grounded!!) 1991 musb->xceiv->otg->default_a = 0;
2010 * Otherwise, wait till the gadget driver hooks up. 1992 musb->xceiv->state = OTG_STATE_B_IDLE;
2011 */
2012 if (!is_otg_enabled(musb) && is_host_enabled(musb)) {
2013 struct usb_hcd *hcd = musb_to_hcd(musb);
2014
2015 MUSB_HST_MODE(musb);
2016 musb->xceiv->otg->default_a = 1;
2017 musb->xceiv->state = OTG_STATE_A_IDLE;
2018
2019 status = usb_add_hcd(musb_to_hcd(musb), 0, 0);
2020
2021 hcd->self.uses_pio_for_control = 1;
2022 dev_dbg(musb->controller, "%s mode, status %d, devctl %02x %c\n",
2023 "HOST", status,
2024 musb_readb(musb->mregs, MUSB_DEVCTL),
2025 (musb_readb(musb->mregs, MUSB_DEVCTL)
2026 & MUSB_DEVCTL_BDEVICE
2027 ? 'B' : 'A'));
2028
2029 } else /* peripheral is enabled */ {
2030 MUSB_DEV_MODE(musb);
2031 musb->xceiv->otg->default_a = 0;
2032 musb->xceiv->state = OTG_STATE_B_IDLE;
2033
2034 status = musb_gadget_setup(musb);
2035 1993
2036 dev_dbg(musb->controller, "%s mode, status %d, dev%02x\n", 1994 status = musb_gadget_setup(musb);
2037 is_otg_enabled(musb) ? "OTG" : "PERIPHERAL",
2038 status,
2039 musb_readb(musb->mregs, MUSB_DEVCTL));
2040 1995
2041 }
2042 if (status < 0) 1996 if (status < 0)
2043 goto fail3; 1997 goto fail3;
2044 1998
@@ -2054,28 +2008,13 @@ musb_init_controller(struct device *dev, int nIrq, void __iomem *ctrl)
2054 2008
2055 pm_runtime_put(musb->controller); 2009 pm_runtime_put(musb->controller);
2056 2010
2057 dev_info(dev, "USB %s mode controller at %p using %s, IRQ %d\n",
2058 ({char *s;
2059 switch (musb->board_mode) {
2060 case MUSB_HOST: s = "Host"; break;
2061 case MUSB_PERIPHERAL: s = "Peripheral"; break;
2062 default: s = "OTG"; break;
2063 }; s; }),
2064 ctrl,
2065 (is_dma_capable() && musb->dma_controller)
2066 ? "DMA" : "PIO",
2067 musb->nIrq);
2068
2069 return 0; 2011 return 0;
2070 2012
2071fail5: 2013fail5:
2072 musb_exit_debugfs(musb); 2014 musb_exit_debugfs(musb);
2073 2015
2074fail4: 2016fail4:
2075 if (!is_otg_enabled(musb) && is_host_enabled(musb)) 2017 musb_gadget_cleanup(musb);
2076 usb_remove_hcd(musb_to_hcd(musb));
2077 else
2078 musb_gadget_cleanup(musb);
2079 2018
2080fail3: 2019fail3:
2081 pm_runtime_put_sync(musb->controller); 2020 pm_runtime_put_sync(musb->controller);
@@ -2166,11 +2105,9 @@ static void musb_save_context(struct musb *musb)
2166 void __iomem *musb_base = musb->mregs; 2105 void __iomem *musb_base = musb->mregs;
2167 void __iomem *epio; 2106 void __iomem *epio;
2168 2107
2169 if (is_host_enabled(musb)) { 2108 musb->context.frame = musb_readw(musb_base, MUSB_FRAME);
2170 musb->context.frame = musb_readw(musb_base, MUSB_FRAME); 2109 musb->context.testmode = musb_readb(musb_base, MUSB_TESTMODE);
2171 musb->context.testmode = musb_readb(musb_base, MUSB_TESTMODE); 2110 musb->context.busctl = musb_read_ulpi_buscontrol(musb->mregs);
2172 musb->context.busctl = musb_read_ulpi_buscontrol(musb->mregs);
2173 }
2174 musb->context.power = musb_readb(musb_base, MUSB_POWER); 2111 musb->context.power = musb_readb(musb_base, MUSB_POWER);
2175 musb->context.intrtxe = musb_readw(musb_base, MUSB_INTRTXE); 2112 musb->context.intrtxe = musb_readw(musb_base, MUSB_INTRTXE);
2176 musb->context.intrrxe = musb_readw(musb_base, MUSB_INTRRXE); 2113 musb->context.intrrxe = musb_readw(musb_base, MUSB_INTRRXE);
@@ -2209,30 +2146,29 @@ static void musb_save_context(struct musb *musb)
2209 musb->context.index_regs[i].rxfifosz = 2146 musb->context.index_regs[i].rxfifosz =
2210 musb_read_rxfifosz(musb_base); 2147 musb_read_rxfifosz(musb_base);
2211 } 2148 }
2212 if (is_host_enabled(musb)) { 2149
2213 musb->context.index_regs[i].txtype = 2150 musb->context.index_regs[i].txtype =
2214 musb_readb(epio, MUSB_TXTYPE); 2151 musb_readb(epio, MUSB_TXTYPE);
2215 musb->context.index_regs[i].txinterval = 2152 musb->context.index_regs[i].txinterval =
2216 musb_readb(epio, MUSB_TXINTERVAL); 2153 musb_readb(epio, MUSB_TXINTERVAL);
2217 musb->context.index_regs[i].rxtype = 2154 musb->context.index_regs[i].rxtype =
2218 musb_readb(epio, MUSB_RXTYPE); 2155 musb_readb(epio, MUSB_RXTYPE);
2219 musb->context.index_regs[i].rxinterval = 2156 musb->context.index_regs[i].rxinterval =
2220 musb_readb(epio, MUSB_RXINTERVAL); 2157 musb_readb(epio, MUSB_RXINTERVAL);
2221 2158
2222 musb->context.index_regs[i].txfunaddr = 2159 musb->context.index_regs[i].txfunaddr =
2223 musb_read_txfunaddr(musb_base, i); 2160 musb_read_txfunaddr(musb_base, i);
2224 musb->context.index_regs[i].txhubaddr = 2161 musb->context.index_regs[i].txhubaddr =
2225 musb_read_txhubaddr(musb_base, i); 2162 musb_read_txhubaddr(musb_base, i);
2226 musb->context.index_regs[i].txhubport = 2163 musb->context.index_regs[i].txhubport =
2227 musb_read_txhubport(musb_base, i); 2164 musb_read_txhubport(musb_base, i);
2228 2165
2229 musb->context.index_regs[i].rxfunaddr = 2166 musb->context.index_regs[i].rxfunaddr =
2230 musb_read_rxfunaddr(musb_base, i); 2167 musb_read_rxfunaddr(musb_base, i);
2231 musb->context.index_regs[i].rxhubaddr = 2168 musb->context.index_regs[i].rxhubaddr =
2232 musb_read_rxhubaddr(musb_base, i); 2169 musb_read_rxhubaddr(musb_base, i);
2233 musb->context.index_regs[i].rxhubport = 2170 musb->context.index_regs[i].rxhubport =
2234 musb_read_rxhubport(musb_base, i); 2171 musb_read_rxhubport(musb_base, i);
2235 }
2236 } 2172 }
2237} 2173}
2238 2174
@@ -2243,11 +2179,9 @@ static void musb_restore_context(struct musb *musb)
2243 void __iomem *ep_target_regs; 2179 void __iomem *ep_target_regs;
2244 void __iomem *epio; 2180 void __iomem *epio;
2245 2181
2246 if (is_host_enabled(musb)) { 2182 musb_writew(musb_base, MUSB_FRAME, musb->context.frame);
2247 musb_writew(musb_base, MUSB_FRAME, musb->context.frame); 2183 musb_writeb(musb_base, MUSB_TESTMODE, musb->context.testmode);
2248 musb_writeb(musb_base, MUSB_TESTMODE, musb->context.testmode); 2184 musb_write_ulpi_buscontrol(musb->mregs, musb->context.busctl);
2249 musb_write_ulpi_buscontrol(musb->mregs, musb->context.busctl);
2250 }
2251 musb_writeb(musb_base, MUSB_POWER, musb->context.power); 2185 musb_writeb(musb_base, MUSB_POWER, musb->context.power);
2252 musb_writew(musb_base, MUSB_INTRTXE, musb->context.intrtxe); 2186 musb_writew(musb_base, MUSB_INTRTXE, musb->context.intrtxe);
2253 musb_writew(musb_base, MUSB_INTRRXE, musb->context.intrrxe); 2187 musb_writew(musb_base, MUSB_INTRRXE, musb->context.intrrxe);
@@ -2286,33 +2220,31 @@ static void musb_restore_context(struct musb *musb)
2286 musb->context.index_regs[i].rxfifoadd); 2220 musb->context.index_regs[i].rxfifoadd);
2287 } 2221 }
2288 2222
2289 if (is_host_enabled(musb)) { 2223 musb_writeb(epio, MUSB_TXTYPE,
2290 musb_writeb(epio, MUSB_TXTYPE,
2291 musb->context.index_regs[i].txtype); 2224 musb->context.index_regs[i].txtype);
2292 musb_writeb(epio, MUSB_TXINTERVAL, 2225 musb_writeb(epio, MUSB_TXINTERVAL,
2293 musb->context.index_regs[i].txinterval); 2226 musb->context.index_regs[i].txinterval);
2294 musb_writeb(epio, MUSB_RXTYPE, 2227 musb_writeb(epio, MUSB_RXTYPE,
2295 musb->context.index_regs[i].rxtype); 2228 musb->context.index_regs[i].rxtype);
2296 musb_writeb(epio, MUSB_RXINTERVAL, 2229 musb_writeb(epio, MUSB_RXINTERVAL,
2297 2230
2298 musb->context.index_regs[i].rxinterval); 2231 musb->context.index_regs[i].rxinterval);
2299 musb_write_txfunaddr(musb_base, i, 2232 musb_write_txfunaddr(musb_base, i,
2300 musb->context.index_regs[i].txfunaddr); 2233 musb->context.index_regs[i].txfunaddr);
2301 musb_write_txhubaddr(musb_base, i, 2234 musb_write_txhubaddr(musb_base, i,
2302 musb->context.index_regs[i].txhubaddr); 2235 musb->context.index_regs[i].txhubaddr);
2303 musb_write_txhubport(musb_base, i, 2236 musb_write_txhubport(musb_base, i,
2304 musb->context.index_regs[i].txhubport); 2237 musb->context.index_regs[i].txhubport);
2305 2238
2306 ep_target_regs = 2239 ep_target_regs =
2307 musb_read_target_reg_base(i, musb_base); 2240 musb_read_target_reg_base(i, musb_base);
2308 2241
2309 musb_write_rxfunaddr(ep_target_regs, 2242 musb_write_rxfunaddr(ep_target_regs,
2310 musb->context.index_regs[i].rxfunaddr); 2243 musb->context.index_regs[i].rxfunaddr);
2311 musb_write_rxhubaddr(ep_target_regs, 2244 musb_write_rxhubaddr(ep_target_regs,
2312 musb->context.index_regs[i].rxhubaddr); 2245 musb->context.index_regs[i].rxhubaddr);
2313 musb_write_rxhubport(ep_target_regs, 2246 musb_write_rxhubport(ep_target_regs,
2314 musb->context.index_regs[i].rxhubport); 2247 musb->context.index_regs[i].rxhubport);
2315 }
2316 } 2248 }
2317 musb_writeb(musb_base, MUSB_INDEX, musb->context.index); 2249 musb_writeb(musb_base, MUSB_INDEX, musb->context.index);
2318} 2250}
diff --git a/drivers/usb/musb/musb_core.h b/drivers/usb/musb/musb_core.h
index 8bb324dddd17..5dab2daddf7f 100644
--- a/drivers/usb/musb/musb_core.h
+++ b/drivers/usb/musb/musb_core.h
@@ -71,10 +71,6 @@ struct musb_ep;
71#include <linux/usb/hcd.h> 71#include <linux/usb/hcd.h>
72#include "musb_host.h" 72#include "musb_host.h"
73 73
74#define is_peripheral_enabled(musb) ((musb)->board_mode != MUSB_HOST)
75#define is_host_enabled(musb) ((musb)->board_mode != MUSB_PERIPHERAL)
76#define is_otg_enabled(musb) ((musb)->board_mode == MUSB_OTG)
77
78/* NOTE: otg and peripheral-only state machines start at B_IDLE. 74/* NOTE: otg and peripheral-only state machines start at B_IDLE.
79 * OTG or host-only go to A_IDLE when ID is sensed. 75 * OTG or host-only go to A_IDLE when ID is sensed.
80 */ 76 */
@@ -376,7 +372,6 @@ struct musb {
376 u16 epmask; 372 u16 epmask;
377 u8 nr_endpoints; 373 u8 nr_endpoints;
378 374
379 u8 board_mode; /* enum musb_mode */
380 int (*board_set_power)(int state); 375 int (*board_set_power)(int state);
381 376
382 u8 min_power; /* vbus for periph, in mA/2 */ 377 u8 min_power; /* vbus for periph, in mA/2 */
diff --git a/drivers/usb/musb/musb_dsps.c b/drivers/usb/musb/musb_dsps.c
index 217808d9fbe1..51ff1bbff381 100644
--- a/drivers/usb/musb/musb_dsps.c
+++ b/drivers/usb/musb/musb_dsps.c
@@ -137,9 +137,8 @@ static void dsps_musb_enable(struct musb *musb)
137 dsps_writel(reg_base, wrp->epintr_set, epmask); 137 dsps_writel(reg_base, wrp->epintr_set, epmask);
138 dsps_writel(reg_base, wrp->coreintr_set, coremask); 138 dsps_writel(reg_base, wrp->coreintr_set, coremask);
139 /* Force the DRVVBUS IRQ so we can start polling for ID change. */ 139 /* Force the DRVVBUS IRQ so we can start polling for ID change. */
140 if (is_otg_enabled(musb)) 140 dsps_writel(reg_base, wrp->coreintr_set,
141 dsps_writel(reg_base, wrp->coreintr_set, 141 (1 << wrp->drvvbus) << wrp->usb_shift);
142 (1 << wrp->drvvbus) << wrp->usb_shift);
143} 142}
144 143
145/** 144/**
@@ -200,9 +199,6 @@ static void otg_timer(unsigned long _musb)
200 MUSB_INTR_VBUSERROR << wrp->usb_shift); 199 MUSB_INTR_VBUSERROR << wrp->usb_shift);
201 break; 200 break;
202 case OTG_STATE_B_IDLE: 201 case OTG_STATE_B_IDLE:
203 if (!is_peripheral_enabled(musb))
204 break;
205
206 devctl = dsps_readb(mregs, MUSB_DEVCTL); 202 devctl = dsps_readb(mregs, MUSB_DEVCTL);
207 if (devctl & MUSB_DEVCTL_BDEVICE) 203 if (devctl & MUSB_DEVCTL_BDEVICE)
208 mod_timer(&glue->timer, 204 mod_timer(&glue->timer,
@@ -223,9 +219,6 @@ static void dsps_musb_try_idle(struct musb *musb, unsigned long timeout)
223 struct dsps_glue *glue = platform_get_drvdata(pdev); 219 struct dsps_glue *glue = platform_get_drvdata(pdev);
224 static unsigned long last_timer; 220 static unsigned long last_timer;
225 221
226 if (!is_otg_enabled(musb))
227 return;
228
229 if (timeout == 0) 222 if (timeout == 0)
230 timeout = jiffies + msecs_to_jiffies(3); 223 timeout = jiffies + msecs_to_jiffies(3);
231 224
@@ -293,7 +286,7 @@ static irqreturn_t dsps_interrupt(int irq, void *hci)
293 * value but DEVCTL.BDEVICE is invalid without DEVCTL.SESSION set. 286 * value but DEVCTL.BDEVICE is invalid without DEVCTL.SESSION set.
294 * Also, DRVVBUS pulses for SRP (but not at 5V) ... 287 * Also, DRVVBUS pulses for SRP (but not at 5V) ...
295 */ 288 */
296 if ((usbintr & MUSB_INTR_BABBLE) && is_host_enabled(musb)) 289 if (usbintr & MUSB_INTR_BABBLE)
297 pr_info("CAUTION: musb: Babble Interrupt Occured\n"); 290 pr_info("CAUTION: musb: Babble Interrupt Occured\n");
298 291
299 if (usbintr & ((1 << wrp->drvvbus) << wrp->usb_shift)) { 292 if (usbintr & ((1 << wrp->drvvbus) << wrp->usb_shift)) {
@@ -302,8 +295,7 @@ static irqreturn_t dsps_interrupt(int irq, void *hci)
302 u8 devctl = dsps_readb(mregs, MUSB_DEVCTL); 295 u8 devctl = dsps_readb(mregs, MUSB_DEVCTL);
303 int err; 296 int err;
304 297
305 err = is_host_enabled(musb) && (musb->int_usb & 298 err = musb->int_usb & MUSB_INTR_VBUSERROR;
306 MUSB_INTR_VBUSERROR);
307 if (err) { 299 if (err) {
308 /* 300 /*
309 * The Mentor core doesn't debounce VBUS as needed 301 * The Mentor core doesn't debounce VBUS as needed
@@ -321,7 +313,7 @@ static irqreturn_t dsps_interrupt(int irq, void *hci)
321 mod_timer(&glue->timer, 313 mod_timer(&glue->timer,
322 jiffies + wrp->poll_seconds * HZ); 314 jiffies + wrp->poll_seconds * HZ);
323 WARNING("VBUS error workaround (delay coming)\n"); 315 WARNING("VBUS error workaround (delay coming)\n");
324 } else if (is_host_enabled(musb) && drvvbus) { 316 } else if (drvvbus) {
325 musb->is_active = 1; 317 musb->is_active = 1;
326 MUSB_HST_MODE(musb); 318 MUSB_HST_MODE(musb);
327 musb->xceiv->otg->default_a = 1; 319 musb->xceiv->otg->default_a = 1;
@@ -352,7 +344,7 @@ static irqreturn_t dsps_interrupt(int irq, void *hci)
352 dsps_writel(reg_base, wrp->eoi, 1); 344 dsps_writel(reg_base, wrp->eoi, 1);
353 345
354 /* Poll for ID change */ 346 /* Poll for ID change */
355 if (is_otg_enabled(musb) && musb->xceiv->state == OTG_STATE_B_IDLE) 347 if (musb->xceiv->state == OTG_STATE_B_IDLE)
356 mod_timer(&glue->timer, jiffies + wrp->poll_seconds * HZ); 348 mod_timer(&glue->timer, jiffies + wrp->poll_seconds * HZ);
357 349
358 spin_unlock_irqrestore(&musb->lock, flags); 350 spin_unlock_irqrestore(&musb->lock, flags);
@@ -388,8 +380,7 @@ static int dsps_musb_init(struct musb *musb)
388 goto err0; 380 goto err0;
389 } 381 }
390 382
391 if (is_host_enabled(musb)) 383 setup_timer(&glue->timer, otg_timer, (unsigned long) musb);
392 setup_timer(&glue->timer, otg_timer, (unsigned long) musb);
393 384
394 /* Reset the musb */ 385 /* Reset the musb */
395 dsps_writel(reg_base, wrp->control, (1 << wrp->reset)); 386 dsps_writel(reg_base, wrp->control, (1 << wrp->reset));
@@ -423,8 +414,7 @@ static int dsps_musb_exit(struct musb *musb)
423 struct platform_device *pdev = to_platform_device(dev->parent); 414 struct platform_device *pdev = to_platform_device(dev->parent);
424 struct dsps_glue *glue = platform_get_drvdata(pdev); 415 struct dsps_glue *glue = platform_get_drvdata(pdev);
425 416
426 if (is_host_enabled(musb)) 417 del_timer_sync(&glue->timer);
427 del_timer_sync(&glue->timer);
428 418
429 /* Shutdown the on-chip PHY and its PLL. */ 419 /* Shutdown the on-chip PHY and its PLL. */
430 if (data->set_phy_power) 420 if (data->set_phy_power)
diff --git a/drivers/usb/musb/musb_gadget.c b/drivers/usb/musb/musb_gadget.c
index 5c4392b02169..7fb060d91282 100644
--- a/drivers/usb/musb/musb_gadget.c
+++ b/drivers/usb/musb/musb_gadget.c
@@ -1864,8 +1864,7 @@ int __devinit musb_gadget_setup(struct musb *musb)
1864 musb->g.dev.release = musb_gadget_release; 1864 musb->g.dev.release = musb_gadget_release;
1865 musb->g.name = musb_driver_name; 1865 musb->g.name = musb_driver_name;
1866 1866
1867 if (is_otg_enabled(musb)) 1867 musb->g.is_otg = 1;
1868 musb->g.is_otg = 1;
1869 1868
1870 musb_g_init_endpoints(musb); 1869 musb_g_init_endpoints(musb);
1871 1870
@@ -1911,11 +1910,14 @@ static int musb_gadget_start(struct usb_gadget *g,
1911{ 1910{
1912 struct musb *musb = gadget_to_musb(g); 1911 struct musb *musb = gadget_to_musb(g);
1913 struct usb_otg *otg = musb->xceiv->otg; 1912 struct usb_otg *otg = musb->xceiv->otg;
1913 struct usb_hcd *hcd = musb_to_hcd(musb);
1914 unsigned long flags; 1914 unsigned long flags;
1915 int retval = -EINVAL; 1915 int retval = 0;
1916 1916
1917 if (driver->max_speed < USB_SPEED_HIGH) 1917 if (driver->max_speed < USB_SPEED_HIGH) {
1918 goto err0; 1918 retval = -EINVAL;
1919 goto err;
1920 }
1919 1921
1920 pm_runtime_get_sync(musb->controller); 1922 pm_runtime_get_sync(musb->controller);
1921 1923
@@ -1929,49 +1931,30 @@ static int musb_gadget_start(struct usb_gadget *g,
1929 1931
1930 otg_set_peripheral(otg, &musb->g); 1932 otg_set_peripheral(otg, &musb->g);
1931 musb->xceiv->state = OTG_STATE_B_IDLE; 1933 musb->xceiv->state = OTG_STATE_B_IDLE;
1932
1933 /*
1934 * FIXME this ignores the softconnect flag. Drivers are
1935 * allowed hold the peripheral inactive until for example
1936 * userspace hooks up printer hardware or DSP codecs, so
1937 * hosts only see fully functional devices.
1938 */
1939
1940 if (!is_otg_enabled(musb))
1941 musb_start(musb);
1942
1943 spin_unlock_irqrestore(&musb->lock, flags); 1934 spin_unlock_irqrestore(&musb->lock, flags);
1944 1935
1945 if (is_otg_enabled(musb)) { 1936 /* REVISIT: funcall to other code, which also
1946 struct usb_hcd *hcd = musb_to_hcd(musb); 1937 * handles power budgeting ... this way also
1947 1938 * ensures HdrcStart is indirectly called.
1948 dev_dbg(musb->controller, "OTG startup...\n"); 1939 */
1940 retval = usb_add_hcd(hcd, 0, 0);
1941 if (retval < 0) {
1942 dev_dbg(musb->controller, "add_hcd failed, %d\n", retval);
1943 goto err;
1944 }
1949 1945
1950 /* REVISIT: funcall to other code, which also 1946 if ((musb->xceiv->last_event == USB_EVENT_ID)
1951 * handles power budgeting ... this way also 1947 && otg->set_vbus)
1952 * ensures HdrcStart is indirectly called. 1948 otg_set_vbus(otg, 1);
1953 */
1954 retval = usb_add_hcd(musb_to_hcd(musb), 0, 0);
1955 if (retval < 0) {
1956 dev_dbg(musb->controller, "add_hcd failed, %d\n", retval);
1957 goto err2;
1958 }
1959 1949
1960 if ((musb->xceiv->last_event == USB_EVENT_ID) 1950 hcd->self.uses_pio_for_control = 1;
1961 && otg->set_vbus)
1962 otg_set_vbus(otg, 1);
1963 1951
1964 hcd->self.uses_pio_for_control = 1;
1965 }
1966 if (musb->xceiv->last_event == USB_EVENT_NONE) 1952 if (musb->xceiv->last_event == USB_EVENT_NONE)
1967 pm_runtime_put(musb->controller); 1953 pm_runtime_put(musb->controller);
1968 1954
1969 return 0; 1955 return 0;
1970 1956
1971err2: 1957err:
1972 if (!is_otg_enabled(musb))
1973 musb_stop(musb);
1974err0:
1975 return retval; 1958 return retval;
1976} 1959}
1977 1960
@@ -2049,16 +2032,12 @@ static int musb_gadget_stop(struct usb_gadget *g,
2049 musb_platform_try_idle(musb, 0); 2032 musb_platform_try_idle(musb, 0);
2050 spin_unlock_irqrestore(&musb->lock, flags); 2033 spin_unlock_irqrestore(&musb->lock, flags);
2051 2034
2052 if (is_otg_enabled(musb)) { 2035 usb_remove_hcd(musb_to_hcd(musb));
2053 usb_remove_hcd(musb_to_hcd(musb)); 2036 /*
2054 /* FIXME we need to be able to register another 2037 * FIXME we need to be able to register another
2055 * gadget driver here and have everything work; 2038 * gadget driver here and have everything work;
2056 * that currently misbehaves. 2039 * that currently misbehaves.
2057 */ 2040 */
2058 }
2059
2060 if (!is_otg_enabled(musb))
2061 musb_stop(musb);
2062 2041
2063 pm_runtime_put(musb->controller); 2042 pm_runtime_put(musb->controller);
2064 2043
@@ -2220,13 +2199,11 @@ __acquires(musb->lock)
2220 if (devctl & MUSB_DEVCTL_BDEVICE) { 2199 if (devctl & MUSB_DEVCTL_BDEVICE) {
2221 musb->xceiv->state = OTG_STATE_B_PERIPHERAL; 2200 musb->xceiv->state = OTG_STATE_B_PERIPHERAL;
2222 musb->g.is_a_peripheral = 0; 2201 musb->g.is_a_peripheral = 0;
2223 } else if (is_otg_enabled(musb)) { 2202 } else {
2224 musb->xceiv->state = OTG_STATE_A_PERIPHERAL; 2203 musb->xceiv->state = OTG_STATE_A_PERIPHERAL;
2225 musb->g.is_a_peripheral = 1; 2204 musb->g.is_a_peripheral = 1;
2226 } else 2205 }
2227 WARN_ON(1);
2228 2206
2229 /* start with default limits on VBUS power draw */ 2207 /* start with default limits on VBUS power draw */
2230 (void) musb_gadget_vbus_draw(&musb->g, 2208 (void) musb_gadget_vbus_draw(&musb->g, 8);
2231 is_otg_enabled(musb) ? 8 : 100);
2232} 2209}
diff --git a/drivers/usb/musb/musb_virthub.c b/drivers/usb/musb/musb_virthub.c
index 22ec3e379980..f70579154ded 100644
--- a/drivers/usb/musb/musb_virthub.c
+++ b/drivers/usb/musb/musb_virthub.c
@@ -81,8 +81,7 @@ static void musb_port_suspend(struct musb *musb, bool do_suspend)
81 switch (musb->xceiv->state) { 81 switch (musb->xceiv->state) {
82 case OTG_STATE_A_HOST: 82 case OTG_STATE_A_HOST:
83 musb->xceiv->state = OTG_STATE_A_SUSPEND; 83 musb->xceiv->state = OTG_STATE_A_SUSPEND;
84 musb->is_active = is_otg_enabled(musb) 84 musb->is_active = otg->host->b_hnp_enable;
85 && otg->host->b_hnp_enable;
86 if (musb->is_active) 85 if (musb->is_active)
87 mod_timer(&musb->otg_timer, jiffies 86 mod_timer(&musb->otg_timer, jiffies
88 + msecs_to_jiffies( 87 + msecs_to_jiffies(
@@ -91,8 +90,7 @@ static void musb_port_suspend(struct musb *musb, bool do_suspend)
91 break; 90 break;
92 case OTG_STATE_B_HOST: 91 case OTG_STATE_B_HOST:
93 musb->xceiv->state = OTG_STATE_B_WAIT_ACON; 92 musb->xceiv->state = OTG_STATE_B_WAIT_ACON;
94 musb->is_active = is_otg_enabled(musb) 93 musb->is_active = otg->host->b_hnp_enable;
95 && otg->host->b_hnp_enable;
96 musb_platform_try_idle(musb, 0); 94 musb_platform_try_idle(musb, 0);
97 break; 95 break;
98 default: 96 default:
@@ -190,8 +188,7 @@ void musb_root_disconnect(struct musb *musb)
190 188
191 switch (musb->xceiv->state) { 189 switch (musb->xceiv->state) {
192 case OTG_STATE_A_SUSPEND: 190 case OTG_STATE_A_SUSPEND:
193 if (is_otg_enabled(musb) 191 if (otg->host->b_hnp_enable) {
194 && otg->host->b_hnp_enable) {
195 musb->xceiv->state = OTG_STATE_A_PERIPHERAL; 192 musb->xceiv->state = OTG_STATE_A_PERIPHERAL;
196 musb->g.is_a_peripheral = 1; 193 musb->g.is_a_peripheral = 1;
197 break; 194 break;
@@ -273,7 +270,7 @@ int musb_hub_control(
273 musb_port_suspend(musb, false); 270 musb_port_suspend(musb, false);
274 break; 271 break;
275 case USB_PORT_FEAT_POWER: 272 case USB_PORT_FEAT_POWER:
276 if (!(is_otg_enabled(musb) && hcd->self.is_b_host)) 273 if (!hcd->self.is_b_host)
277 musb_platform_set_vbus(musb, 0); 274 musb_platform_set_vbus(musb, 0);
278 break; 275 break;
279 case USB_PORT_FEAT_C_CONNECTION: 276 case USB_PORT_FEAT_C_CONNECTION:
@@ -369,7 +366,7 @@ int musb_hub_control(
369 * initialization logic, e.g. for OTG, or change any 366 * initialization logic, e.g. for OTG, or change any
370 * logic relating to VBUS power-up. 367 * logic relating to VBUS power-up.
371 */ 368 */
372 if (!(is_otg_enabled(musb) && hcd->self.is_b_host)) 369 if (!hcd->self.is_b_host)
373 musb_start(musb); 370 musb_start(musb);
374 break; 371 break;
375 case USB_PORT_FEAT_RESET: 372 case USB_PORT_FEAT_RESET:
diff --git a/drivers/usb/musb/omap2430.c b/drivers/usb/musb/omap2430.c
index 392fc7a488f2..e32aff9920f2 100644
--- a/drivers/usb/musb/omap2430.c
+++ b/drivers/usb/musb/omap2430.c
@@ -258,7 +258,7 @@ static void omap_musb_set_mailbox(struct omap2430_glue *glue)
258 otg->default_a = true; 258 otg->default_a = true;
259 musb->xceiv->state = OTG_STATE_A_IDLE; 259 musb->xceiv->state = OTG_STATE_A_IDLE;
260 musb->xceiv->last_event = USB_EVENT_ID; 260 musb->xceiv->last_event = USB_EVENT_ID;
261 if (!is_otg_enabled(musb) || musb->gadget_driver) { 261 if (musb->gadget_driver) {
262 pm_runtime_get_sync(dev); 262 pm_runtime_get_sync(dev);
263 usb_phy_init(musb->xceiv); 263 usb_phy_init(musb->xceiv);
264 omap2430_musb_set_vbus(musb, 1); 264 omap2430_musb_set_vbus(musb, 1);
@@ -281,11 +281,10 @@ static void omap_musb_set_mailbox(struct omap2430_glue *glue)
281 dev_dbg(dev, "VBUS Disconnect\n"); 281 dev_dbg(dev, "VBUS Disconnect\n");
282 282
283 musb->xceiv->last_event = USB_EVENT_NONE; 283 musb->xceiv->last_event = USB_EVENT_NONE;
284 if (is_otg_enabled(musb) || is_peripheral_enabled(musb)) 284 if (musb->gadget_driver) {
285 if (musb->gadget_driver) { 285 pm_runtime_mark_last_busy(dev);
286 pm_runtime_mark_last_busy(dev); 286 pm_runtime_put_autosuspend(dev);
287 pm_runtime_put_autosuspend(dev); 287 }
288 }
289 288
290 if (data->interface_type == MUSB_INTERFACE_UTMI) { 289 if (data->interface_type == MUSB_INTERFACE_UTMI) {
291 if (musb->xceiv->otg->set_vbus) 290 if (musb->xceiv->otg->set_vbus)
diff --git a/drivers/usb/musb/tusb6010.c b/drivers/usb/musb/tusb6010.c
index 4073a6fa2633..1d0c090be78c 100644
--- a/drivers/usb/musb/tusb6010.c
+++ b/drivers/usb/musb/tusb6010.c
@@ -437,14 +437,13 @@ static void musb_do_idle(unsigned long _musb)
437 if (is_host_active(musb) && (musb->port1_status >> 16)) 437 if (is_host_active(musb) && (musb->port1_status >> 16))
438 goto done; 438 goto done;
439 439
440 if (is_peripheral_enabled(musb) && !musb->gadget_driver) { 440 if (!musb->gadget_driver) {
441 wakeups = 0; 441 wakeups = 0;
442 } else { 442 } else {
443 wakeups = TUSB_PRCM_WHOSTDISCON 443 wakeups = TUSB_PRCM_WHOSTDISCON
444 | TUSB_PRCM_WBUS 444 | TUSB_PRCM_WBUS
445 | TUSB_PRCM_WVBUS; 445 | TUSB_PRCM_WVBUS;
446 if (is_otg_enabled(musb)) 446 wakeups |= TUSB_PRCM_WID;
447 wakeups |= TUSB_PRCM_WID;
448 } 447 }
449 tusb_allow_idle(musb, wakeups); 448 tusb_allow_idle(musb, wakeups);
450 } 449 }
@@ -582,21 +581,12 @@ static void tusb_musb_set_vbus(struct musb *musb, int is_on)
582 * 581 *
583 * Note that if a mini-A cable is plugged in the ID line will stay down as 582 * Note that if a mini-A cable is plugged in the ID line will stay down as
584 * the weak ID pull-up is not able to pull the ID up. 583 * the weak ID pull-up is not able to pull the ID up.
585 *
586 * REVISIT: It would be possible to add support for changing between host
587 * and peripheral modes in non-OTG configurations by reconfiguring hardware
588 * and then setting musb->board_mode. For now, only support OTG mode.
589 */ 584 */
590static int tusb_musb_set_mode(struct musb *musb, u8 musb_mode) 585static int tusb_musb_set_mode(struct musb *musb, u8 musb_mode)
591{ 586{
592 void __iomem *tbase = musb->ctrl_base; 587 void __iomem *tbase = musb->ctrl_base;
593 u32 otg_stat, phy_otg_ctrl, phy_otg_ena, dev_conf; 588 u32 otg_stat, phy_otg_ctrl, phy_otg_ena, dev_conf;
594 589
595 if (musb->board_mode != MUSB_OTG) {
596 ERR("Changing mode currently only supported in OTG mode\n");
597 return -EINVAL;
598 }
599
600 otg_stat = musb_readl(tbase, TUSB_DEV_OTG_STAT); 590 otg_stat = musb_readl(tbase, TUSB_DEV_OTG_STAT);
601 phy_otg_ctrl = musb_readl(tbase, TUSB_PHY_OTG_CTRL); 591 phy_otg_ctrl = musb_readl(tbase, TUSB_PHY_OTG_CTRL);
602 phy_otg_ena = musb_readl(tbase, TUSB_PHY_OTG_CTRL_ENABLE); 592 phy_otg_ena = musb_readl(tbase, TUSB_PHY_OTG_CTRL_ENABLE);
@@ -652,10 +642,7 @@ tusb_otg_ints(struct musb *musb, u32 int_src, void __iomem *tbase)
652 if ((int_src & TUSB_INT_SRC_ID_STATUS_CHNG)) { 642 if ((int_src & TUSB_INT_SRC_ID_STATUS_CHNG)) {
653 int default_a; 643 int default_a;
654 644
655 if (is_otg_enabled(musb)) 645 default_a = !(otg_stat & TUSB_DEV_OTG_STAT_ID_STATUS);
656 default_a = !(otg_stat & TUSB_DEV_OTG_STAT_ID_STATUS);
657 else
658 default_a = is_host_enabled(musb);
659 dev_dbg(musb->controller, "Default-%c\n", default_a ? 'A' : 'B'); 646 dev_dbg(musb->controller, "Default-%c\n", default_a ? 'A' : 'B');
660 otg->default_a = default_a; 647 otg->default_a = default_a;
661 tusb_musb_set_vbus(musb, default_a); 648 tusb_musb_set_vbus(musb, default_a);
@@ -669,8 +656,7 @@ tusb_otg_ints(struct musb *musb, u32 int_src, void __iomem *tbase)
669 if (int_src & TUSB_INT_SRC_VBUS_SENSE_CHNG) { 656 if (int_src & TUSB_INT_SRC_VBUS_SENSE_CHNG) {
670 657
671 /* B-dev state machine: no vbus ~= disconnect */ 658 /* B-dev state machine: no vbus ~= disconnect */
672 if ((is_otg_enabled(musb) && !otg->default_a) 659 if (!otg->default_a) {
673 || !is_host_enabled(musb)) {
674 /* ? musb_root_disconnect(musb); */ 660 /* ? musb_root_disconnect(musb); */
675 musb->port1_status &= 661 musb->port1_status &=
676 ~(USB_PORT_STAT_CONNECTION 662 ~(USB_PORT_STAT_CONNECTION
@@ -1119,10 +1105,8 @@ static int tusb_musb_init(struct musb *musb)
1119 } 1105 }
1120 musb->isr = tusb_musb_interrupt; 1106 musb->isr = tusb_musb_interrupt;
1121 1107
1122 if (is_peripheral_enabled(musb)) { 1108 musb->xceiv->set_power = tusb_draw_power;
1123 musb->xceiv->set_power = tusb_draw_power; 1109 the_musb = musb;
1124 the_musb = musb;
1125 }
1126 1110
1127 setup_timer(&musb_idle_timer, musb_do_idle, (unsigned long) musb); 1111 setup_timer(&musb_idle_timer, musb_do_idle, (unsigned long) musb);
1128 1112