aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/musb
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/usb/musb')
-rw-r--r--drivers/usb/musb/Kconfig2
-rw-r--r--drivers/usb/musb/am35x.c66
-rw-r--r--drivers/usb/musb/blackfin.c63
-rw-r--r--drivers/usb/musb/cppi_dma.c2
-rw-r--r--drivers/usb/musb/da8xx.c58
-rw-r--r--drivers/usb/musb/davinci.c66
-rw-r--r--drivers/usb/musb/musb_core.c331
-rw-r--r--drivers/usb/musb/musb_core.h17
-rw-r--r--drivers/usb/musb/musb_debugfs.c8
-rw-r--r--drivers/usb/musb/musb_dma.h2
-rw-r--r--drivers/usb/musb/musb_dsps.c193
-rw-r--r--drivers/usb/musb/musb_gadget.c172
-rw-r--r--drivers/usb/musb/musb_host.c264
-rw-r--r--drivers/usb/musb/musb_host.h3
-rw-r--r--drivers/usb/musb/musb_virthub.c13
-rw-r--r--drivers/usb/musb/musbhsdma.c2
-rw-r--r--drivers/usb/musb/omap2430.c156
-rw-r--r--drivers/usb/musb/omap2430.h9
-rw-r--r--drivers/usb/musb/tusb6010.c56
-rw-r--r--drivers/usb/musb/tusb6010_omap.c2
-rw-r--r--drivers/usb/musb/ux500.c33
-rw-r--r--drivers/usb/musb/ux500_dma.c2
22 files changed, 866 insertions, 654 deletions
diff --git a/drivers/usb/musb/Kconfig b/drivers/usb/musb/Kconfig
index 09f685686500..23a0b7f0892d 100644
--- a/drivers/usb/musb/Kconfig
+++ b/drivers/usb/musb/Kconfig
@@ -19,7 +19,7 @@ config USB_MUSB_HDRC
19 it's being used with, including the USB peripheral role, 19 it's being used with, including the USB peripheral role,
20 or the USB host role, or both. 20 or the USB host role, or both.
21 21
22 Texas Instruments familiies using this IP include DaVinci 22 Texas Instruments families using this IP include DaVinci
23 (35x, 644x ...), OMAP 243x, OMAP 3, and TUSB 6010. 23 (35x, 644x ...), OMAP 243x, OMAP 3, and TUSB 6010.
24 24
25 Analog Devices parts using this IP include Blackfin BF54x, 25 Analog Devices parts using this IP include Blackfin BF54x,
diff --git a/drivers/usb/musb/am35x.c b/drivers/usb/musb/am35x.c
index 5d64c5b5ef52..457f25e62c51 100644
--- a/drivers/usb/musb/am35x.c
+++ b/drivers/usb/musb/am35x.c
@@ -108,9 +108,8 @@ static void am35x_musb_enable(struct musb *musb)
108 musb_writel(reg_base, CORE_INTR_MASK_SET_REG, AM35X_INTR_USB_MASK); 108 musb_writel(reg_base, CORE_INTR_MASK_SET_REG, AM35X_INTR_USB_MASK);
109 109
110 /* Force the DRVVBUS IRQ so we can start polling for ID change. */ 110 /* Force the DRVVBUS IRQ so we can start polling for ID change. */
111 if (is_otg_enabled(musb)) 111 musb_writel(reg_base, CORE_INTR_SRC_SET_REG,
112 musb_writel(reg_base, CORE_INTR_SRC_SET_REG, 112 AM35X_INTR_DRVVBUS << AM35X_INTR_USB_SHIFT);
113 AM35X_INTR_DRVVBUS << AM35X_INTR_USB_SHIFT);
114} 113}
115 114
116/* 115/*
@@ -174,9 +173,6 @@ static void otg_timer(unsigned long _musb)
174 MUSB_INTR_VBUSERROR << AM35X_INTR_USB_SHIFT); 173 MUSB_INTR_VBUSERROR << AM35X_INTR_USB_SHIFT);
175 break; 174 break;
176 case OTG_STATE_B_IDLE: 175 case OTG_STATE_B_IDLE:
177 if (!is_peripheral_enabled(musb))
178 break;
179
180 devctl = musb_readb(mregs, MUSB_DEVCTL); 176 devctl = musb_readb(mregs, MUSB_DEVCTL);
181 if (devctl & MUSB_DEVCTL_BDEVICE) 177 if (devctl & MUSB_DEVCTL_BDEVICE)
182 mod_timer(&otg_workaround, jiffies + POLL_SECONDS * HZ); 178 mod_timer(&otg_workaround, jiffies + POLL_SECONDS * HZ);
@@ -193,9 +189,6 @@ static void am35x_musb_try_idle(struct musb *musb, unsigned long timeout)
193{ 189{
194 static unsigned long last_timer; 190 static unsigned long last_timer;
195 191
196 if (!is_otg_enabled(musb))
197 return;
198
199 if (timeout == 0) 192 if (timeout == 0)
200 timeout = jiffies + msecs_to_jiffies(3); 193 timeout = jiffies + msecs_to_jiffies(3);
201 194
@@ -272,8 +265,7 @@ static irqreturn_t am35x_musb_interrupt(int irq, void *hci)
272 u8 devctl = musb_readb(mregs, MUSB_DEVCTL); 265 u8 devctl = musb_readb(mregs, MUSB_DEVCTL);
273 int err; 266 int err;
274 267
275 err = is_host_enabled(musb) && (musb->int_usb & 268 err = musb->int_usb & MUSB_INTR_VBUSERROR;
276 MUSB_INTR_VBUSERROR);
277 if (err) { 269 if (err) {
278 /* 270 /*
279 * The Mentor core doesn't debounce VBUS as needed 271 * The Mentor core doesn't debounce VBUS as needed
@@ -290,7 +282,7 @@ static irqreturn_t am35x_musb_interrupt(int irq, void *hci)
290 musb->xceiv->state = OTG_STATE_A_WAIT_VFALL; 282 musb->xceiv->state = OTG_STATE_A_WAIT_VFALL;
291 mod_timer(&otg_workaround, jiffies + POLL_SECONDS * HZ); 283 mod_timer(&otg_workaround, jiffies + POLL_SECONDS * HZ);
292 WARNING("VBUS error workaround (delay coming)\n"); 284 WARNING("VBUS error workaround (delay coming)\n");
293 } else if (is_host_enabled(musb) && drvvbus) { 285 } else if (drvvbus) {
294 MUSB_HST_MODE(musb); 286 MUSB_HST_MODE(musb);
295 otg->default_a = 1; 287 otg->default_a = 1;
296 musb->xceiv->state = OTG_STATE_A_WAIT_VRISE; 288 musb->xceiv->state = OTG_STATE_A_WAIT_VRISE;
@@ -327,7 +319,7 @@ eoi:
327 } 319 }
328 320
329 /* Poll for ID change */ 321 /* Poll for ID change */
330 if (is_otg_enabled(musb) && musb->xceiv->state == OTG_STATE_B_IDLE) 322 if (musb->xceiv->state == OTG_STATE_B_IDLE)
331 mod_timer(&otg_workaround, jiffies + POLL_SECONDS * HZ); 323 mod_timer(&otg_workaround, jiffies + POLL_SECONDS * HZ);
332 324
333 spin_unlock_irqrestore(&musb->lock, flags); 325 spin_unlock_irqrestore(&musb->lock, flags);
@@ -370,8 +362,7 @@ static int am35x_musb_init(struct musb *musb)
370 if (IS_ERR_OR_NULL(musb->xceiv)) 362 if (IS_ERR_OR_NULL(musb->xceiv))
371 return -ENODEV; 363 return -ENODEV;
372 364
373 if (is_host_enabled(musb)) 365 setup_timer(&otg_workaround, otg_timer, (unsigned long) musb);
374 setup_timer(&otg_workaround, otg_timer, (unsigned long) musb);
375 366
376 /* Reset the musb */ 367 /* Reset the musb */
377 if (data->reset) 368 if (data->reset)
@@ -401,8 +392,7 @@ static int am35x_musb_exit(struct musb *musb)
401 struct musb_hdrc_platform_data *plat = dev->platform_data; 392 struct musb_hdrc_platform_data *plat = dev->platform_data;
402 struct omap_musb_board_data *data = plat->board_data; 393 struct omap_musb_board_data *data = plat->board_data;
403 394
404 if (is_host_enabled(musb)) 395 del_timer_sync(&otg_workaround);
405 del_timer_sync(&otg_workaround);
406 396
407 /* Shutdown the on-chip PHY and its PLL. */ 397 /* Shutdown the on-chip PHY and its PLL. */
408 if (data->set_phy_power) 398 if (data->set_phy_power)
@@ -469,6 +459,7 @@ static int __devinit am35x_probe(struct platform_device *pdev)
469 struct clk *clk; 459 struct clk *clk;
470 460
471 int ret = -ENOMEM; 461 int ret = -ENOMEM;
462 int musbid;
472 463
473 glue = kzalloc(sizeof(*glue), GFP_KERNEL); 464 glue = kzalloc(sizeof(*glue), GFP_KERNEL);
474 if (!glue) { 465 if (!glue) {
@@ -476,38 +467,47 @@ static int __devinit am35x_probe(struct platform_device *pdev)
476 goto err0; 467 goto err0;
477 } 468 }
478 469
479 musb = platform_device_alloc("musb-hdrc", -1); 470 /* get the musb id */
471 musbid = musb_get_id(&pdev->dev, GFP_KERNEL);
472 if (musbid < 0) {
473 dev_err(&pdev->dev, "failed to allocate musb id\n");
474 ret = -ENOMEM;
475 goto err1;
476 }
477
478 musb = platform_device_alloc("musb-hdrc", musbid);
480 if (!musb) { 479 if (!musb) {
481 dev_err(&pdev->dev, "failed to allocate musb device\n"); 480 dev_err(&pdev->dev, "failed to allocate musb device\n");
482 goto err1; 481 goto err2;
483 } 482 }
484 483
485 phy_clk = clk_get(&pdev->dev, "fck"); 484 phy_clk = clk_get(&pdev->dev, "fck");
486 if (IS_ERR(phy_clk)) { 485 if (IS_ERR(phy_clk)) {
487 dev_err(&pdev->dev, "failed to get PHY clock\n"); 486 dev_err(&pdev->dev, "failed to get PHY clock\n");
488 ret = PTR_ERR(phy_clk); 487 ret = PTR_ERR(phy_clk);
489 goto err2; 488 goto err3;
490 } 489 }
491 490
492 clk = clk_get(&pdev->dev, "ick"); 491 clk = clk_get(&pdev->dev, "ick");
493 if (IS_ERR(clk)) { 492 if (IS_ERR(clk)) {
494 dev_err(&pdev->dev, "failed to get clock\n"); 493 dev_err(&pdev->dev, "failed to get clock\n");
495 ret = PTR_ERR(clk); 494 ret = PTR_ERR(clk);
496 goto err3; 495 goto err4;
497 } 496 }
498 497
499 ret = clk_enable(phy_clk); 498 ret = clk_enable(phy_clk);
500 if (ret) { 499 if (ret) {
501 dev_err(&pdev->dev, "failed to enable PHY clock\n"); 500 dev_err(&pdev->dev, "failed to enable PHY clock\n");
502 goto err4; 501 goto err5;
503 } 502 }
504 503
505 ret = clk_enable(clk); 504 ret = clk_enable(clk);
506 if (ret) { 505 if (ret) {
507 dev_err(&pdev->dev, "failed to enable clock\n"); 506 dev_err(&pdev->dev, "failed to enable clock\n");
508 goto err5; 507 goto err6;
509 } 508 }
510 509
510 musb->id = musbid;
511 musb->dev.parent = &pdev->dev; 511 musb->dev.parent = &pdev->dev;
512 musb->dev.dma_mask = &am35x_dmamask; 512 musb->dev.dma_mask = &am35x_dmamask;
513 musb->dev.coherent_dma_mask = am35x_dmamask; 513 musb->dev.coherent_dma_mask = am35x_dmamask;
@@ -525,38 +525,41 @@ static int __devinit am35x_probe(struct platform_device *pdev)
525 pdev->num_resources); 525 pdev->num_resources);
526 if (ret) { 526 if (ret) {
527 dev_err(&pdev->dev, "failed to add resources\n"); 527 dev_err(&pdev->dev, "failed to add resources\n");
528 goto err6; 528 goto err7;
529 } 529 }
530 530
531 ret = platform_device_add_data(musb, pdata, sizeof(*pdata)); 531 ret = platform_device_add_data(musb, pdata, sizeof(*pdata));
532 if (ret) { 532 if (ret) {
533 dev_err(&pdev->dev, "failed to add platform_data\n"); 533 dev_err(&pdev->dev, "failed to add platform_data\n");
534 goto err6; 534 goto err7;
535 } 535 }
536 536
537 ret = platform_device_add(musb); 537 ret = platform_device_add(musb);
538 if (ret) { 538 if (ret) {
539 dev_err(&pdev->dev, "failed to register musb device\n"); 539 dev_err(&pdev->dev, "failed to register musb device\n");
540 goto err6; 540 goto err7;
541 } 541 }
542 542
543 return 0; 543 return 0;
544 544
545err6: 545err7:
546 clk_disable(clk); 546 clk_disable(clk);
547 547
548err5: 548err6:
549 clk_disable(phy_clk); 549 clk_disable(phy_clk);
550 550
551err4: 551err5:
552 clk_put(clk); 552 clk_put(clk);
553 553
554err3: 554err4:
555 clk_put(phy_clk); 555 clk_put(phy_clk);
556 556
557err2: 557err3:
558 platform_device_put(musb); 558 platform_device_put(musb);
559 559
560err2:
561 musb_put_id(&pdev->dev, musbid);
562
560err1: 563err1:
561 kfree(glue); 564 kfree(glue);
562 565
@@ -568,6 +571,7 @@ static int __devexit am35x_remove(struct platform_device *pdev)
568{ 571{
569 struct am35x_glue *glue = platform_get_drvdata(pdev); 572 struct am35x_glue *glue = platform_get_drvdata(pdev);
570 573
574 musb_put_id(&pdev->dev, glue->musb->id);
571 platform_device_del(glue->musb); 575 platform_device_del(glue->musb);
572 platform_device_put(glue->musb); 576 platform_device_put(glue->musb);
573 clk_disable(glue->clk); 577 clk_disable(glue->clk);
diff --git a/drivers/usb/musb/blackfin.c b/drivers/usb/musb/blackfin.c
index b562623a8971..e8cff9bb9d23 100644
--- a/drivers/usb/musb/blackfin.c
+++ b/drivers/usb/musb/blackfin.c
@@ -185,8 +185,8 @@ static irqreturn_t blackfin_interrupt(int irq, void *__hci)
185 } 185 }
186 186
187 /* Start sampling ID pin, when plug is removed from MUSB */ 187 /* Start sampling ID pin, when plug is removed from MUSB */
188 if ((is_otg_enabled(musb) && (musb->xceiv->state == OTG_STATE_B_IDLE 188 if ((musb->xceiv->state == OTG_STATE_B_IDLE
189 || musb->xceiv->state == OTG_STATE_A_WAIT_BCON)) || 189 || musb->xceiv->state == OTG_STATE_A_WAIT_BCON) ||
190 (musb->int_usb & MUSB_INTR_DISCONNECT && is_host_active(musb))) { 190 (musb->int_usb & MUSB_INTR_DISCONNECT && is_host_active(musb))) {
191 mod_timer(&musb_conn_timer, jiffies + TIMER_DELAY); 191 mod_timer(&musb_conn_timer, jiffies + TIMER_DELAY);
192 musb->a_wait_bcon = TIMER_DELAY; 192 musb->a_wait_bcon = TIMER_DELAY;
@@ -229,18 +229,13 @@ static void musb_conn_timer_handler(unsigned long _musb)
229 229
230 val = MUSB_INTR_SUSPEND | MUSB_INTR_VBUSERROR; 230 val = MUSB_INTR_SUSPEND | MUSB_INTR_VBUSERROR;
231 musb_writeb(musb->mregs, MUSB_INTRUSB, val); 231 musb_writeb(musb->mregs, MUSB_INTRUSB, val);
232 if (is_otg_enabled(musb)) 232 musb->xceiv->state = OTG_STATE_B_IDLE;
233 musb->xceiv->state = OTG_STATE_B_IDLE;
234 else
235 musb_writeb(musb->mregs, MUSB_POWER, MUSB_POWER_HSENAB);
236 } 233 }
237 mod_timer(&musb_conn_timer, jiffies + TIMER_DELAY); 234 mod_timer(&musb_conn_timer, jiffies + TIMER_DELAY);
238 break; 235 break;
239 case OTG_STATE_B_IDLE: 236 case OTG_STATE_B_IDLE:
240 237 /*
241 if (!is_peripheral_enabled(musb)) 238 * Start a new session. It seems that MUSB needs taking
242 break;
243 /* Start a new session. It seems that MUSB needs taking
244 * some time to recognize the type of the plug inserted? 239 * some time to recognize the type of the plug inserted?
245 */ 240 */
246 val = musb_readw(musb->mregs, MUSB_DEVCTL); 241 val = musb_readw(musb->mregs, MUSB_DEVCTL);
@@ -296,10 +291,7 @@ static void musb_conn_timer_handler(unsigned long _musb)
296 291
297static void bfin_musb_enable(struct musb *musb) 292static void bfin_musb_enable(struct musb *musb)
298{ 293{
299 if (!is_otg_enabled(musb) && is_host_enabled(musb)) { 294 /* REVISIT is this really correct ? */
300 mod_timer(&musb_conn_timer, jiffies + TIMER_DELAY);
301 musb->a_wait_bcon = TIMER_DELAY;
302 }
303} 295}
304 296
305static void bfin_musb_disable(struct musb *musb) 297static void bfin_musb_disable(struct musb *musb)
@@ -324,12 +316,6 @@ static int bfin_musb_set_power(struct usb_phy *x, unsigned mA)
324 return 0; 316 return 0;
325} 317}
326 318
327static void bfin_musb_try_idle(struct musb *musb, unsigned long timeout)
328{
329 if (!is_otg_enabled(musb) && is_host_enabled(musb))
330 mod_timer(&musb_conn_timer, jiffies + TIMER_DELAY);
331}
332
333static int bfin_musb_vbus_status(struct musb *musb) 319static int bfin_musb_vbus_status(struct musb *musb)
334{ 320{
335 return 0; 321 return 0;
@@ -425,12 +411,10 @@ static int bfin_musb_init(struct musb *musb)
425 411
426 bfin_musb_reg_init(musb); 412 bfin_musb_reg_init(musb);
427 413
428 if (is_host_enabled(musb)) { 414 setup_timer(&musb_conn_timer, musb_conn_timer_handler,
429 setup_timer(&musb_conn_timer, 415 (unsigned long) musb);
430 musb_conn_timer_handler, (unsigned long) musb); 416
431 } 417 musb->xceiv->set_power = bfin_musb_set_power;
432 if (is_peripheral_enabled(musb))
433 musb->xceiv->set_power = bfin_musb_set_power;
434 418
435 musb->isr = blackfin_interrupt; 419 musb->isr = blackfin_interrupt;
436 musb->double_buffer_not_ok = true; 420 musb->double_buffer_not_ok = true;
@@ -455,7 +439,6 @@ static const struct musb_platform_ops bfin_ops = {
455 .disable = bfin_musb_disable, 439 .disable = bfin_musb_disable,
456 440
457 .set_mode = bfin_musb_set_mode, 441 .set_mode = bfin_musb_set_mode,
458 .try_idle = bfin_musb_try_idle,
459 442
460 .vbus_status = bfin_musb_vbus_status, 443 .vbus_status = bfin_musb_vbus_status,
461 .set_vbus = bfin_musb_set_vbus, 444 .set_vbus = bfin_musb_set_vbus,
@@ -472,6 +455,7 @@ static int __devinit bfin_probe(struct platform_device *pdev)
472 struct bfin_glue *glue; 455 struct bfin_glue *glue;
473 456
474 int ret = -ENOMEM; 457 int ret = -ENOMEM;
458 int musbid;
475 459
476 glue = kzalloc(sizeof(*glue), GFP_KERNEL); 460 glue = kzalloc(sizeof(*glue), GFP_KERNEL);
477 if (!glue) { 461 if (!glue) {
@@ -479,12 +463,21 @@ static int __devinit bfin_probe(struct platform_device *pdev)
479 goto err0; 463 goto err0;
480 } 464 }
481 465
482 musb = platform_device_alloc("musb-hdrc", -1); 466 /* get the musb id */
467 musbid = musb_get_id(&pdev->dev, GFP_KERNEL);
468 if (musbid < 0) {
469 dev_err(&pdev->dev, "failed to allocate musb id\n");
470 ret = -ENOMEM;
471 goto err1;
472 }
473
474 musb = platform_device_alloc("musb-hdrc", musbid);
483 if (!musb) { 475 if (!musb) {
484 dev_err(&pdev->dev, "failed to allocate musb device\n"); 476 dev_err(&pdev->dev, "failed to allocate musb device\n");
485 goto err1; 477 goto err2;
486 } 478 }
487 479
480 musb->id = musbid;
488 musb->dev.parent = &pdev->dev; 481 musb->dev.parent = &pdev->dev;
489 musb->dev.dma_mask = &bfin_dmamask; 482 musb->dev.dma_mask = &bfin_dmamask;
490 musb->dev.coherent_dma_mask = bfin_dmamask; 483 musb->dev.coherent_dma_mask = bfin_dmamask;
@@ -500,26 +493,29 @@ static int __devinit bfin_probe(struct platform_device *pdev)
500 pdev->num_resources); 493 pdev->num_resources);
501 if (ret) { 494 if (ret) {
502 dev_err(&pdev->dev, "failed to add resources\n"); 495 dev_err(&pdev->dev, "failed to add resources\n");
503 goto err2; 496 goto err3;
504 } 497 }
505 498
506 ret = platform_device_add_data(musb, pdata, sizeof(*pdata)); 499 ret = platform_device_add_data(musb, pdata, sizeof(*pdata));
507 if (ret) { 500 if (ret) {
508 dev_err(&pdev->dev, "failed to add platform_data\n"); 501 dev_err(&pdev->dev, "failed to add platform_data\n");
509 goto err2; 502 goto err3;
510 } 503 }
511 504
512 ret = platform_device_add(musb); 505 ret = platform_device_add(musb);
513 if (ret) { 506 if (ret) {
514 dev_err(&pdev->dev, "failed to register musb device\n"); 507 dev_err(&pdev->dev, "failed to register musb device\n");
515 goto err2; 508 goto err3;
516 } 509 }
517 510
518 return 0; 511 return 0;
519 512
520err2: 513err3:
521 platform_device_put(musb); 514 platform_device_put(musb);
522 515
516err2:
517 musb_put_id(&pdev->dev, musbid);
518
523err1: 519err1:
524 kfree(glue); 520 kfree(glue);
525 521
@@ -531,6 +527,7 @@ static int __devexit bfin_remove(struct platform_device *pdev)
531{ 527{
532 struct bfin_glue *glue = platform_get_drvdata(pdev); 528 struct bfin_glue *glue = platform_get_drvdata(pdev);
533 529
530 musb_put_id(&pdev->dev, glue->musb->id);
534 platform_device_del(glue->musb); 531 platform_device_del(glue->musb);
535 platform_device_put(glue->musb); 532 platform_device_put(glue->musb);
536 kfree(glue); 533 kfree(glue);
diff --git a/drivers/usb/musb/cppi_dma.c b/drivers/usb/musb/cppi_dma.c
index 8637c1f69fc3..e19da82b4782 100644
--- a/drivers/usb/musb/cppi_dma.c
+++ b/drivers/usb/musb/cppi_dma.c
@@ -1316,7 +1316,7 @@ irqreturn_t cppi_interrupt(int irq, void *dev_id)
1316} 1316}
1317 1317
1318/* Instantiate a software object representing a DMA controller. */ 1318/* Instantiate a software object representing a DMA controller. */
1319struct dma_controller *__init 1319struct dma_controller *__devinit
1320dma_controller_create(struct musb *musb, void __iomem *mregs) 1320dma_controller_create(struct musb *musb, void __iomem *mregs)
1321{ 1321{
1322 struct cppi *controller; 1322 struct cppi *controller;
diff --git a/drivers/usb/musb/da8xx.c b/drivers/usb/musb/da8xx.c
index 16798c9e6f38..ce11d20b90f4 100644
--- a/drivers/usb/musb/da8xx.c
+++ b/drivers/usb/musb/da8xx.c
@@ -156,9 +156,8 @@ static void da8xx_musb_enable(struct musb *musb)
156 musb_writel(reg_base, DA8XX_USB_INTR_MASK_SET_REG, mask); 156 musb_writel(reg_base, DA8XX_USB_INTR_MASK_SET_REG, mask);
157 157
158 /* Force the DRVVBUS IRQ so we can start polling for ID change. */ 158 /* Force the DRVVBUS IRQ so we can start polling for ID change. */
159 if (is_otg_enabled(musb)) 159 musb_writel(reg_base, DA8XX_USB_INTR_SRC_SET_REG,
160 musb_writel(reg_base, DA8XX_USB_INTR_SRC_SET_REG, 160 DA8XX_INTR_DRVVBUS << DA8XX_INTR_USB_SHIFT);
161 DA8XX_INTR_DRVVBUS << DA8XX_INTR_USB_SHIFT);
162} 161}
163 162
164/** 163/**
@@ -232,9 +231,6 @@ static void otg_timer(unsigned long _musb)
232 MUSB_INTR_VBUSERROR << DA8XX_INTR_USB_SHIFT); 231 MUSB_INTR_VBUSERROR << DA8XX_INTR_USB_SHIFT);
233 break; 232 break;
234 case OTG_STATE_B_IDLE: 233 case OTG_STATE_B_IDLE:
235 if (!is_peripheral_enabled(musb))
236 break;
237
238 /* 234 /*
239 * There's no ID-changed IRQ, so we have no good way to tell 235 * There's no ID-changed IRQ, so we have no good way to tell
240 * when to switch to the A-Default state machine (by setting 236 * when to switch to the A-Default state machine (by setting
@@ -264,9 +260,6 @@ static void da8xx_musb_try_idle(struct musb *musb, unsigned long timeout)
264{ 260{
265 static unsigned long last_timer; 261 static unsigned long last_timer;
266 262
267 if (!is_otg_enabled(musb))
268 return;
269
270 if (timeout == 0) 263 if (timeout == 0)
271 timeout = jiffies + msecs_to_jiffies(3); 264 timeout = jiffies + msecs_to_jiffies(3);
272 265
@@ -334,8 +327,7 @@ static irqreturn_t da8xx_musb_interrupt(int irq, void *hci)
334 u8 devctl = musb_readb(mregs, MUSB_DEVCTL); 327 u8 devctl = musb_readb(mregs, MUSB_DEVCTL);
335 int err; 328 int err;
336 329
337 err = is_host_enabled(musb) && (musb->int_usb & 330 err = musb->int_usb & USB_INTR_VBUSERROR;
338 MUSB_INTR_VBUSERROR);
339 if (err) { 331 if (err) {
340 /* 332 /*
341 * The Mentor core doesn't debounce VBUS as needed 333 * The Mentor core doesn't debounce VBUS as needed
@@ -352,7 +344,7 @@ static irqreturn_t da8xx_musb_interrupt(int irq, void *hci)
352 musb->xceiv->state = OTG_STATE_A_WAIT_VFALL; 344 musb->xceiv->state = OTG_STATE_A_WAIT_VFALL;
353 mod_timer(&otg_workaround, jiffies + POLL_SECONDS * HZ); 345 mod_timer(&otg_workaround, jiffies + POLL_SECONDS * HZ);
354 WARNING("VBUS error workaround (delay coming)\n"); 346 WARNING("VBUS error workaround (delay coming)\n");
355 } else if (is_host_enabled(musb) && drvvbus) { 347 } else if (drvvbus) {
356 MUSB_HST_MODE(musb); 348 MUSB_HST_MODE(musb);
357 otg->default_a = 1; 349 otg->default_a = 1;
358 musb->xceiv->state = OTG_STATE_A_WAIT_VRISE; 350 musb->xceiv->state = OTG_STATE_A_WAIT_VRISE;
@@ -383,7 +375,7 @@ static irqreturn_t da8xx_musb_interrupt(int irq, void *hci)
383 musb_writel(reg_base, DA8XX_USB_END_OF_INTR_REG, 0); 375 musb_writel(reg_base, DA8XX_USB_END_OF_INTR_REG, 0);
384 376
385 /* Poll for ID change */ 377 /* Poll for ID change */
386 if (is_otg_enabled(musb) && musb->xceiv->state == OTG_STATE_B_IDLE) 378 if (musb->xceiv->state == OTG_STATE_B_IDLE)
387 mod_timer(&otg_workaround, jiffies + POLL_SECONDS * HZ); 379 mod_timer(&otg_workaround, jiffies + POLL_SECONDS * HZ);
388 380
389 spin_unlock_irqrestore(&musb->lock, flags); 381 spin_unlock_irqrestore(&musb->lock, flags);
@@ -431,8 +423,7 @@ static int da8xx_musb_init(struct musb *musb)
431 if (IS_ERR_OR_NULL(musb->xceiv)) 423 if (IS_ERR_OR_NULL(musb->xceiv))
432 goto fail; 424 goto fail;
433 425
434 if (is_host_enabled(musb)) 426 setup_timer(&otg_workaround, otg_timer, (unsigned long)musb);
435 setup_timer(&otg_workaround, otg_timer, (unsigned long)musb);
436 427
437 /* Reset the controller */ 428 /* Reset the controller */
438 musb_writel(reg_base, DA8XX_USB_CTRL_REG, DA8XX_SOFT_RESET_MASK); 429 musb_writel(reg_base, DA8XX_USB_CTRL_REG, DA8XX_SOFT_RESET_MASK);
@@ -455,8 +446,7 @@ fail:
455 446
456static int da8xx_musb_exit(struct musb *musb) 447static int da8xx_musb_exit(struct musb *musb)
457{ 448{
458 if (is_host_enabled(musb)) 449 del_timer_sync(&otg_workaround);
459 del_timer_sync(&otg_workaround);
460 450
461 phy_off(); 451 phy_off();
462 452
@@ -490,6 +480,7 @@ static int __devinit da8xx_probe(struct platform_device *pdev)
490 struct clk *clk; 480 struct clk *clk;
491 481
492 int ret = -ENOMEM; 482 int ret = -ENOMEM;
483 int musbid;
493 484
494 glue = kzalloc(sizeof(*glue), GFP_KERNEL); 485 glue = kzalloc(sizeof(*glue), GFP_KERNEL);
495 if (!glue) { 486 if (!glue) {
@@ -497,25 +488,34 @@ static int __devinit da8xx_probe(struct platform_device *pdev)
497 goto err0; 488 goto err0;
498 } 489 }
499 490
500 musb = platform_device_alloc("musb-hdrc", -1); 491 /* get the musb id */
492 musbid = musb_get_id(&pdev->dev, GFP_KERNEL);
493 if (musbid < 0) {
494 dev_err(&pdev->dev, "failed to allocate musb id\n");
495 ret = -ENOMEM;
496 goto err1;
497 }
498
499 musb = platform_device_alloc("musb-hdrc", musbid);
501 if (!musb) { 500 if (!musb) {
502 dev_err(&pdev->dev, "failed to allocate musb device\n"); 501 dev_err(&pdev->dev, "failed to allocate musb device\n");
503 goto err1; 502 goto err2;
504 } 503 }
505 504
506 clk = clk_get(&pdev->dev, "usb20"); 505 clk = clk_get(&pdev->dev, "usb20");
507 if (IS_ERR(clk)) { 506 if (IS_ERR(clk)) {
508 dev_err(&pdev->dev, "failed to get clock\n"); 507 dev_err(&pdev->dev, "failed to get clock\n");
509 ret = PTR_ERR(clk); 508 ret = PTR_ERR(clk);
510 goto err2; 509 goto err3;
511 } 510 }
512 511
513 ret = clk_enable(clk); 512 ret = clk_enable(clk);
514 if (ret) { 513 if (ret) {
515 dev_err(&pdev->dev, "failed to enable clock\n"); 514 dev_err(&pdev->dev, "failed to enable clock\n");
516 goto err3; 515 goto err4;
517 } 516 }
518 517
518 musb->id = musbid;
519 musb->dev.parent = &pdev->dev; 519 musb->dev.parent = &pdev->dev;
520 musb->dev.dma_mask = &da8xx_dmamask; 520 musb->dev.dma_mask = &da8xx_dmamask;
521 musb->dev.coherent_dma_mask = da8xx_dmamask; 521 musb->dev.coherent_dma_mask = da8xx_dmamask;
@@ -532,32 +532,35 @@ static int __devinit da8xx_probe(struct platform_device *pdev)
532 pdev->num_resources); 532 pdev->num_resources);
533 if (ret) { 533 if (ret) {
534 dev_err(&pdev->dev, "failed to add resources\n"); 534 dev_err(&pdev->dev, "failed to add resources\n");
535 goto err4; 535 goto err5;
536 } 536 }
537 537
538 ret = platform_device_add_data(musb, pdata, sizeof(*pdata)); 538 ret = platform_device_add_data(musb, pdata, sizeof(*pdata));
539 if (ret) { 539 if (ret) {
540 dev_err(&pdev->dev, "failed to add platform_data\n"); 540 dev_err(&pdev->dev, "failed to add platform_data\n");
541 goto err4; 541 goto err5;
542 } 542 }
543 543
544 ret = platform_device_add(musb); 544 ret = platform_device_add(musb);
545 if (ret) { 545 if (ret) {
546 dev_err(&pdev->dev, "failed to register musb device\n"); 546 dev_err(&pdev->dev, "failed to register musb device\n");
547 goto err4; 547 goto err5;
548 } 548 }
549 549
550 return 0; 550 return 0;
551 551
552err4: 552err5:
553 clk_disable(clk); 553 clk_disable(clk);
554 554
555err3: 555err4:
556 clk_put(clk); 556 clk_put(clk);
557 557
558err2: 558err3:
559 platform_device_put(musb); 559 platform_device_put(musb);
560 560
561err2:
562 musb_put_id(&pdev->dev, musbid);
563
561err1: 564err1:
562 kfree(glue); 565 kfree(glue);
563 566
@@ -569,6 +572,7 @@ static int __devexit da8xx_remove(struct platform_device *pdev)
569{ 572{
570 struct da8xx_glue *glue = platform_get_drvdata(pdev); 573 struct da8xx_glue *glue = platform_get_drvdata(pdev);
571 574
575 musb_put_id(&pdev->dev, glue->musb->id);
572 platform_device_del(glue->musb); 576 platform_device_del(glue->musb);
573 platform_device_put(glue->musb); 577 platform_device_put(glue->musb);
574 clk_disable(glue->clk); 578 clk_disable(glue->clk);
diff --git a/drivers/usb/musb/davinci.c b/drivers/usb/musb/davinci.c
index 863a9b6286c3..606bfd00cde6 100644
--- a/drivers/usb/musb/davinci.c
+++ b/drivers/usb/musb/davinci.c
@@ -116,8 +116,7 @@ static void davinci_musb_enable(struct musb *musb)
116 dma_off = 0; 116 dma_off = 0;
117 117
118 /* force a DRVVBUS irq so we can start polling for ID change */ 118 /* force a DRVVBUS irq so we can start polling for ID change */
119 if (is_otg_enabled(musb)) 119 musb_writel(musb->ctrl_base, DAVINCI_USB_INT_SET_REG,
120 musb_writel(musb->ctrl_base, DAVINCI_USB_INT_SET_REG,
121 DAVINCI_INTR_DRVVBUS << DAVINCI_USB_USBINT_SHIFT); 120 DAVINCI_INTR_DRVVBUS << DAVINCI_USB_USBINT_SHIFT);
122} 121}
123 122
@@ -235,10 +234,8 @@ static void otg_timer(unsigned long _musb)
235 MUSB_INTR_VBUSERROR << DAVINCI_USB_USBINT_SHIFT); 234 MUSB_INTR_VBUSERROR << DAVINCI_USB_USBINT_SHIFT);
236 break; 235 break;
237 case OTG_STATE_B_IDLE: 236 case OTG_STATE_B_IDLE:
238 if (!is_peripheral_enabled(musb)) 237 /*
239 break; 238 * There's no ID-changed IRQ, so we have no good way to tell
240
241 /* There's no ID-changed IRQ, so we have no good way to tell
242 * when to switch to the A-Default state machine (by setting 239 * when to switch to the A-Default state machine (by setting
243 * the DEVCTL.SESSION flag). 240 * the DEVCTL.SESSION flag).
244 * 241 *
@@ -316,8 +313,7 @@ static irqreturn_t davinci_musb_interrupt(int irq, void *__hci)
316 u8 devctl = musb_readb(mregs, MUSB_DEVCTL); 313 u8 devctl = musb_readb(mregs, MUSB_DEVCTL);
317 int err = musb->int_usb & MUSB_INTR_VBUSERROR; 314 int err = musb->int_usb & MUSB_INTR_VBUSERROR;
318 315
319 err = is_host_enabled(musb) 316 err = musb->int_usb & MUSB_INTR_VBUSERROR;
320 && (musb->int_usb & MUSB_INTR_VBUSERROR);
321 if (err) { 317 if (err) {
322 /* The Mentor core doesn't debounce VBUS as needed 318 /* The Mentor core doesn't debounce VBUS as needed
323 * to cope with device connect current spikes. This 319 * to cope with device connect current spikes. This
@@ -333,7 +329,7 @@ static irqreturn_t davinci_musb_interrupt(int irq, void *__hci)
333 musb->xceiv->state = OTG_STATE_A_WAIT_VFALL; 329 musb->xceiv->state = OTG_STATE_A_WAIT_VFALL;
334 mod_timer(&otg_workaround, jiffies + POLL_SECONDS * HZ); 330 mod_timer(&otg_workaround, jiffies + POLL_SECONDS * HZ);
335 WARNING("VBUS error workaround (delay coming)\n"); 331 WARNING("VBUS error workaround (delay coming)\n");
336 } else if (is_host_enabled(musb) && drvvbus) { 332 } else if (drvvbus) {
337 MUSB_HST_MODE(musb); 333 MUSB_HST_MODE(musb);
338 otg->default_a = 1; 334 otg->default_a = 1;
339 musb->xceiv->state = OTG_STATE_A_WAIT_VRISE; 335 musb->xceiv->state = OTG_STATE_A_WAIT_VRISE;
@@ -366,8 +362,7 @@ static irqreturn_t davinci_musb_interrupt(int irq, void *__hci)
366 musb_writel(tibase, DAVINCI_USB_EOI_REG, 0); 362 musb_writel(tibase, DAVINCI_USB_EOI_REG, 0);
367 363
368 /* poll for ID change */ 364 /* poll for ID change */
369 if (is_otg_enabled(musb) 365 if (musb->xceiv->state == OTG_STATE_B_IDLE)
370 && musb->xceiv->state == OTG_STATE_B_IDLE)
371 mod_timer(&otg_workaround, jiffies + POLL_SECONDS * HZ); 366 mod_timer(&otg_workaround, jiffies + POLL_SECONDS * HZ);
372 367
373 spin_unlock_irqrestore(&musb->lock, flags); 368 spin_unlock_irqrestore(&musb->lock, flags);
@@ -398,8 +393,7 @@ static int davinci_musb_init(struct musb *musb)
398 if (revision == 0) 393 if (revision == 0)
399 goto fail; 394 goto fail;
400 395
401 if (is_host_enabled(musb)) 396 setup_timer(&otg_workaround, otg_timer, (unsigned long) musb);
402 setup_timer(&otg_workaround, otg_timer, (unsigned long) musb);
403 397
404 davinci_musb_source_power(musb, 0, 1); 398 davinci_musb_source_power(musb, 0, 1);
405 399
@@ -420,12 +414,7 @@ static int davinci_musb_init(struct musb *musb)
420 if (cpu_is_davinci_dm355()) { 414 if (cpu_is_davinci_dm355()) {
421 u32 deepsleep = __raw_readl(DM355_DEEPSLEEP); 415 u32 deepsleep = __raw_readl(DM355_DEEPSLEEP);
422 416
423 if (is_host_enabled(musb)) { 417 deepsleep &= ~DRVVBUS_FORCE;
424 deepsleep &= ~DRVVBUS_OVERRIDE;
425 } else {
426 deepsleep &= ~DRVVBUS_FORCE;
427 deepsleep |= DRVVBUS_OVERRIDE;
428 }
429 __raw_writel(deepsleep, DM355_DEEPSLEEP); 418 __raw_writel(deepsleep, DM355_DEEPSLEEP);
430 } 419 }
431 420
@@ -454,8 +443,7 @@ unregister:
454 443
455static int davinci_musb_exit(struct musb *musb) 444static int davinci_musb_exit(struct musb *musb)
456{ 445{
457 if (is_host_enabled(musb)) 446 del_timer_sync(&otg_workaround);
458 del_timer_sync(&otg_workaround);
459 447
460 /* force VBUS off */ 448 /* force VBUS off */
461 if (cpu_is_davinci_dm355()) { 449 if (cpu_is_davinci_dm355()) {
@@ -469,7 +457,7 @@ static int davinci_musb_exit(struct musb *musb)
469 davinci_musb_source_power(musb, 0 /*off*/, 1); 457 davinci_musb_source_power(musb, 0 /*off*/, 1);
470 458
471 /* delay, to avoid problems with module reload */ 459 /* delay, to avoid problems with module reload */
472 if (is_host_enabled(musb) && musb->xceiv->otg->default_a) { 460 if (musb->xceiv->otg->default_a) {
473 int maxdelay = 30; 461 int maxdelay = 30;
474 u8 devctl, warn = 0; 462 u8 devctl, warn = 0;
475 463
@@ -524,6 +512,7 @@ static int __devinit davinci_probe(struct platform_device *pdev)
524 struct clk *clk; 512 struct clk *clk;
525 513
526 int ret = -ENOMEM; 514 int ret = -ENOMEM;
515 int musbid;
527 516
528 glue = kzalloc(sizeof(*glue), GFP_KERNEL); 517 glue = kzalloc(sizeof(*glue), GFP_KERNEL);
529 if (!glue) { 518 if (!glue) {
@@ -531,25 +520,34 @@ static int __devinit davinci_probe(struct platform_device *pdev)
531 goto err0; 520 goto err0;
532 } 521 }
533 522
534 musb = platform_device_alloc("musb-hdrc", -1); 523 /* get the musb id */
524 musbid = musb_get_id(&pdev->dev, GFP_KERNEL);
525 if (musbid < 0) {
526 dev_err(&pdev->dev, "failed to allocate musb id\n");
527 ret = -ENOMEM;
528 goto err1;
529 }
530
531 musb = platform_device_alloc("musb-hdrc", musbid);
535 if (!musb) { 532 if (!musb) {
536 dev_err(&pdev->dev, "failed to allocate musb device\n"); 533 dev_err(&pdev->dev, "failed to allocate musb device\n");
537 goto err1; 534 goto err2;
538 } 535 }
539 536
540 clk = clk_get(&pdev->dev, "usb"); 537 clk = clk_get(&pdev->dev, "usb");
541 if (IS_ERR(clk)) { 538 if (IS_ERR(clk)) {
542 dev_err(&pdev->dev, "failed to get clock\n"); 539 dev_err(&pdev->dev, "failed to get clock\n");
543 ret = PTR_ERR(clk); 540 ret = PTR_ERR(clk);
544 goto err2; 541 goto err3;
545 } 542 }
546 543
547 ret = clk_enable(clk); 544 ret = clk_enable(clk);
548 if (ret) { 545 if (ret) {
549 dev_err(&pdev->dev, "failed to enable clock\n"); 546 dev_err(&pdev->dev, "failed to enable clock\n");
550 goto err3; 547 goto err4;
551 } 548 }
552 549
550 musb->id = musbid;
553 musb->dev.parent = &pdev->dev; 551 musb->dev.parent = &pdev->dev;
554 musb->dev.dma_mask = &davinci_dmamask; 552 musb->dev.dma_mask = &davinci_dmamask;
555 musb->dev.coherent_dma_mask = davinci_dmamask; 553 musb->dev.coherent_dma_mask = davinci_dmamask;
@@ -566,32 +564,35 @@ static int __devinit davinci_probe(struct platform_device *pdev)
566 pdev->num_resources); 564 pdev->num_resources);
567 if (ret) { 565 if (ret) {
568 dev_err(&pdev->dev, "failed to add resources\n"); 566 dev_err(&pdev->dev, "failed to add resources\n");
569 goto err4; 567 goto err5;
570 } 568 }
571 569
572 ret = platform_device_add_data(musb, pdata, sizeof(*pdata)); 570 ret = platform_device_add_data(musb, pdata, sizeof(*pdata));
573 if (ret) { 571 if (ret) {
574 dev_err(&pdev->dev, "failed to add platform_data\n"); 572 dev_err(&pdev->dev, "failed to add platform_data\n");
575 goto err4; 573 goto err5;
576 } 574 }
577 575
578 ret = platform_device_add(musb); 576 ret = platform_device_add(musb);
579 if (ret) { 577 if (ret) {
580 dev_err(&pdev->dev, "failed to register musb device\n"); 578 dev_err(&pdev->dev, "failed to register musb device\n");
581 goto err4; 579 goto err5;
582 } 580 }
583 581
584 return 0; 582 return 0;
585 583
586err4: 584err5:
587 clk_disable(clk); 585 clk_disable(clk);
588 586
589err3: 587err4:
590 clk_put(clk); 588 clk_put(clk);
591 589
592err2: 590err3:
593 platform_device_put(musb); 591 platform_device_put(musb);
594 592
593err2:
594 musb_put_id(&pdev->dev, musbid);
595
595err1: 596err1:
596 kfree(glue); 597 kfree(glue);
597 598
@@ -603,6 +604,7 @@ static int __devexit davinci_remove(struct platform_device *pdev)
603{ 604{
604 struct davinci_glue *glue = platform_get_drvdata(pdev); 605 struct davinci_glue *glue = platform_get_drvdata(pdev);
605 606
607 musb_put_id(&pdev->dev, glue->musb->id);
606 platform_device_del(glue->musb); 608 platform_device_del(glue->musb);
607 platform_device_put(glue->musb); 609 platform_device_put(glue->musb);
608 clk_disable(glue->clk); 610 clk_disable(glue->clk);
diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
index 26f1befb4896..bb56a0e8b23b 100644
--- a/drivers/usb/musb/musb_core.c
+++ b/drivers/usb/musb/musb_core.c
@@ -99,6 +99,8 @@
99#include <linux/prefetch.h> 99#include <linux/prefetch.h>
100#include <linux/platform_device.h> 100#include <linux/platform_device.h>
101#include <linux/io.h> 101#include <linux/io.h>
102#include <linux/idr.h>
103#include <linux/dma-mapping.h>
102 104
103#include "musb_core.h" 105#include "musb_core.h"
104 106
@@ -114,6 +116,7 @@
114 116
115#define MUSB_DRIVER_NAME "musb-hdrc" 117#define MUSB_DRIVER_NAME "musb-hdrc"
116const char musb_driver_name[] = MUSB_DRIVER_NAME; 118const char musb_driver_name[] = MUSB_DRIVER_NAME;
119static DEFINE_IDA(musb_ida);
117 120
118MODULE_DESCRIPTION(DRIVER_INFO); 121MODULE_DESCRIPTION(DRIVER_INFO);
119MODULE_AUTHOR(DRIVER_AUTHOR); 122MODULE_AUTHOR(DRIVER_AUTHOR);
@@ -130,6 +133,35 @@ static inline struct musb *dev_to_musb(struct device *dev)
130 133
131/*-------------------------------------------------------------------------*/ 134/*-------------------------------------------------------------------------*/
132 135
136int musb_get_id(struct device *dev, gfp_t gfp_mask)
137{
138 int ret;
139 int id;
140
141 ret = ida_pre_get(&musb_ida, gfp_mask);
142 if (!ret) {
143 dev_err(dev, "failed to reserve resource for id\n");
144 return -ENOMEM;
145 }
146
147 ret = ida_get_new(&musb_ida, &id);
148 if (ret < 0) {
149 dev_err(dev, "failed to allocate a new id\n");
150 return ret;
151 }
152
153 return id;
154}
155EXPORT_SYMBOL_GPL(musb_get_id);
156
157void musb_put_id(struct device *dev, int id)
158{
159
160 dev_dbg(dev, "removing id %d\n", id);
161 ida_remove(&musb_ida, id);
162}
163EXPORT_SYMBOL_GPL(musb_put_id);
164
133#ifndef CONFIG_BLACKFIN 165#ifndef CONFIG_BLACKFIN
134static int musb_ulpi_read(struct usb_phy *phy, u32 offset) 166static int musb_ulpi_read(struct usb_phy *phy, u32 offset)
135{ 167{
@@ -234,6 +266,9 @@ void musb_write_fifo(struct musb_hw_ep *hw_ep, u16 len, const u8 *src)
234 struct musb *musb = hw_ep->musb; 266 struct musb *musb = hw_ep->musb;
235 void __iomem *fifo = hw_ep->fifo; 267 void __iomem *fifo = hw_ep->fifo;
236 268
269 if (unlikely(len == 0))
270 return;
271
237 prefetch((u8 *)src); 272 prefetch((u8 *)src);
238 273
239 dev_dbg(musb->controller, "%cX ep%d fifo %p count %d buf %p\n", 274 dev_dbg(musb->controller, "%cX ep%d fifo %p count %d buf %p\n",
@@ -276,6 +311,9 @@ void musb_read_fifo(struct musb_hw_ep *hw_ep, u16 len, u8 *dst)
276 struct musb *musb = hw_ep->musb; 311 struct musb *musb = hw_ep->musb;
277 void __iomem *fifo = hw_ep->fifo; 312 void __iomem *fifo = hw_ep->fifo;
278 313
314 if (unlikely(len == 0))
315 return;
316
279 dev_dbg(musb->controller, "%cX ep%d fifo %p count %d buf %p\n", 317 dev_dbg(musb->controller, "%cX ep%d fifo %p count %d buf %p\n",
280 'R', hw_ep->epnum, fifo, len, dst); 318 'R', hw_ep->epnum, fifo, len, dst);
281 319
@@ -348,7 +386,7 @@ void musb_load_testpacket(struct musb *musb)
348/* 386/*
349 * Handles OTG hnp timeouts, such as b_ase0_brst 387 * Handles OTG hnp timeouts, such as b_ase0_brst
350 */ 388 */
351void musb_otg_timer_func(unsigned long data) 389static void musb_otg_timer_func(unsigned long data)
352{ 390{
353 struct musb *musb = (struct musb *)data; 391 struct musb *musb = (struct musb *)data;
354 unsigned long flags; 392 unsigned long flags;
@@ -643,8 +681,7 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb,
643 break; 681 break;
644 case OTG_STATE_B_PERIPHERAL: 682 case OTG_STATE_B_PERIPHERAL:
645 musb_g_suspend(musb); 683 musb_g_suspend(musb);
646 musb->is_active = is_otg_enabled(musb) 684 musb->is_active = otg->gadget->b_hnp_enable;
647 && otg->gadget->b_hnp_enable;
648 if (musb->is_active) { 685 if (musb->is_active) {
649 musb->xceiv->state = OTG_STATE_B_WAIT_ACON; 686 musb->xceiv->state = OTG_STATE_B_WAIT_ACON;
650 dev_dbg(musb->controller, "HNP: Setting timer for b_ase0_brst\n"); 687 dev_dbg(musb->controller, "HNP: Setting timer for b_ase0_brst\n");
@@ -660,8 +697,7 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb,
660 break; 697 break;
661 case OTG_STATE_A_HOST: 698 case OTG_STATE_A_HOST:
662 musb->xceiv->state = OTG_STATE_A_SUSPEND; 699 musb->xceiv->state = OTG_STATE_A_SUSPEND;
663 musb->is_active = is_otg_enabled(musb) 700 musb->is_active = otg->host->b_hnp_enable;
664 && otg->host->b_hnp_enable;
665 break; 701 break;
666 case OTG_STATE_B_HOST: 702 case OTG_STATE_B_HOST:
667 /* Transition to B_PERIPHERAL, see 6.8.2.6 p 44 */ 703 /* Transition to B_PERIPHERAL, see 6.8.2.6 p 44 */
@@ -749,7 +785,7 @@ b_host:
749 case OTG_STATE_A_SUSPEND: 785 case OTG_STATE_A_SUSPEND:
750 usb_hcd_resume_root_hub(musb_to_hcd(musb)); 786 usb_hcd_resume_root_hub(musb_to_hcd(musb));
751 musb_root_disconnect(musb); 787 musb_root_disconnect(musb);
752 if (musb->a_wait_bcon != 0 && is_otg_enabled(musb)) 788 if (musb->a_wait_bcon != 0)
753 musb_platform_try_idle(musb, jiffies 789 musb_platform_try_idle(musb, jiffies
754 + msecs_to_jiffies(musb->a_wait_bcon)); 790 + msecs_to_jiffies(musb->a_wait_bcon));
755 break; 791 break;
@@ -787,7 +823,7 @@ b_host:
787 */ 823 */
788 if (int_usb & MUSB_INTR_RESET) { 824 if (int_usb & MUSB_INTR_RESET) {
789 handled = IRQ_HANDLED; 825 handled = IRQ_HANDLED;
790 if (is_host_capable() && (devctl & MUSB_DEVCTL_HM) != 0) { 826 if ((devctl & MUSB_DEVCTL_HM) != 0) {
791 /* 827 /*
792 * Looks like non-HS BABBLE can be ignored, but 828 * Looks like non-HS BABBLE can be ignored, but
793 * HS BABBLE is an error condition. For HS the solution 829 * HS BABBLE is an error condition. For HS the solution
@@ -801,7 +837,7 @@ b_host:
801 ERR("Stopping host session -- babble\n"); 837 ERR("Stopping host session -- babble\n");
802 musb_writeb(musb->mregs, MUSB_DEVCTL, 0); 838 musb_writeb(musb->mregs, MUSB_DEVCTL, 0);
803 } 839 }
804 } else if (is_peripheral_capable()) { 840 } else {
805 dev_dbg(musb->controller, "BUS RESET as %s\n", 841 dev_dbg(musb->controller, "BUS RESET as %s\n",
806 otg_state_string(musb->xceiv->state)); 842 otg_state_string(musb->xceiv->state));
807 switch (musb->xceiv->state) { 843 switch (musb->xceiv->state) {
@@ -925,25 +961,16 @@ void musb_start(struct musb *musb)
925 devctl = musb_readb(regs, MUSB_DEVCTL); 961 devctl = musb_readb(regs, MUSB_DEVCTL);
926 devctl &= ~MUSB_DEVCTL_SESSION; 962 devctl &= ~MUSB_DEVCTL_SESSION;
927 963
928 if (is_otg_enabled(musb)) { 964 /* session started after:
929 /* session started after: 965 * (a) ID-grounded irq, host mode;
930 * (a) ID-grounded irq, host mode; 966 * (b) vbus present/connect IRQ, peripheral mode;
931 * (b) vbus present/connect IRQ, peripheral mode; 967 * (c) peripheral initiates, using SRP
932 * (c) peripheral initiates, using SRP 968 */
933 */ 969 if ((devctl & MUSB_DEVCTL_VBUS) == MUSB_DEVCTL_VBUS)
934 if ((devctl & MUSB_DEVCTL_VBUS) == MUSB_DEVCTL_VBUS) 970 musb->is_active = 1;
935 musb->is_active = 1; 971 else
936 else
937 devctl |= MUSB_DEVCTL_SESSION;
938
939 } else if (is_host_enabled(musb)) {
940 /* assume ID pin is hard-wired to ground */
941 devctl |= MUSB_DEVCTL_SESSION; 972 devctl |= MUSB_DEVCTL_SESSION;
942 973
943 } else /* peripheral is enabled */ {
944 if ((devctl & MUSB_DEVCTL_VBUS) == MUSB_DEVCTL_VBUS)
945 musb->is_active = 1;
946 }
947 musb_platform_enable(musb); 974 musb_platform_enable(musb);
948 musb_writeb(regs, MUSB_DEVCTL, devctl); 975 musb_writeb(regs, MUSB_DEVCTL, devctl);
949} 976}
@@ -1007,8 +1034,6 @@ static void musb_shutdown(struct platform_device *pdev)
1007 musb_generic_disable(musb); 1034 musb_generic_disable(musb);
1008 spin_unlock_irqrestore(&musb->lock, flags); 1035 spin_unlock_irqrestore(&musb->lock, flags);
1009 1036
1010 if (!is_otg_enabled(musb) && is_host_enabled(musb))
1011 usb_remove_hcd(musb_to_hcd(musb));
1012 musb_writeb(musb->mregs, MUSB_DEVCTL, 0); 1037 musb_writeb(musb->mregs, MUSB_DEVCTL, 0);
1013 musb_platform_exit(musb); 1038 musb_platform_exit(musb);
1014 1039
@@ -1302,7 +1327,7 @@ done:
1302 if (offset < 0) { 1327 if (offset < 0) {
1303 pr_debug("%s: mem overrun, ep %d\n", 1328 pr_debug("%s: mem overrun, ep %d\n",
1304 musb_driver_name, epn); 1329 musb_driver_name, epn);
1305 return -EINVAL; 1330 return offset;
1306 } 1331 }
1307 epn++; 1332 epn++;
1308 musb->nr_endpoints = max(epn, musb->nr_endpoints); 1333 musb->nr_endpoints = max(epn, musb->nr_endpoints);
@@ -1330,7 +1355,7 @@ static int __devinit ep_config_from_hw(struct musb *musb)
1330{ 1355{
1331 u8 epnum = 0; 1356 u8 epnum = 0;
1332 struct musb_hw_ep *hw_ep; 1357 struct musb_hw_ep *hw_ep;
1333 void *mbase = musb->mregs; 1358 void __iomem *mbase = musb->mregs;
1334 int ret = 0; 1359 int ret = 0;
1335 1360
1336 dev_dbg(musb->controller, "<== static silicon ep config\n"); 1361 dev_dbg(musb->controller, "<== static silicon ep config\n");
@@ -1571,13 +1596,10 @@ irqreturn_t musb_interrupt(struct musb *musb)
1571 /* musb_ep_select(musb->mregs, ep_num); */ 1596 /* musb_ep_select(musb->mregs, ep_num); */
1572 /* REVISIT just retval = ep->rx_irq(...) */ 1597 /* REVISIT just retval = ep->rx_irq(...) */
1573 retval = IRQ_HANDLED; 1598 retval = IRQ_HANDLED;
1574 if (devctl & MUSB_DEVCTL_HM) { 1599 if (devctl & MUSB_DEVCTL_HM)
1575 if (is_host_capable()) 1600 musb_host_rx(musb, ep_num);
1576 musb_host_rx(musb, ep_num); 1601 else
1577 } else { 1602 musb_g_rx(musb, ep_num);
1578 if (is_peripheral_capable())
1579 musb_g_rx(musb, ep_num);
1580 }
1581 } 1603 }
1582 1604
1583 reg >>= 1; 1605 reg >>= 1;
@@ -1592,13 +1614,10 @@ irqreturn_t musb_interrupt(struct musb *musb)
1592 /* musb_ep_select(musb->mregs, ep_num); */ 1614 /* musb_ep_select(musb->mregs, ep_num); */
1593 /* REVISIT just retval |= ep->tx_irq(...) */ 1615 /* REVISIT just retval |= ep->tx_irq(...) */
1594 retval = IRQ_HANDLED; 1616 retval = IRQ_HANDLED;
1595 if (devctl & MUSB_DEVCTL_HM) { 1617 if (devctl & MUSB_DEVCTL_HM)
1596 if (is_host_capable()) 1618 musb_host_tx(musb, ep_num);
1597 musb_host_tx(musb, ep_num); 1619 else
1598 } else { 1620 musb_g_tx(musb, ep_num);
1599 if (is_peripheral_capable())
1600 musb_g_tx(musb, ep_num);
1601 }
1602 } 1621 }
1603 reg >>= 1; 1622 reg >>= 1;
1604 ep_num++; 1623 ep_num++;
@@ -1634,22 +1653,16 @@ void musb_dma_completion(struct musb *musb, u8 epnum, u8 transmit)
1634 } else { 1653 } else {
1635 /* endpoints 1..15 */ 1654 /* endpoints 1..15 */
1636 if (transmit) { 1655 if (transmit) {
1637 if (devctl & MUSB_DEVCTL_HM) { 1656 if (devctl & MUSB_DEVCTL_HM)
1638 if (is_host_capable()) 1657 musb_host_tx(musb, epnum);
1639 musb_host_tx(musb, epnum); 1658 else
1640 } else { 1659 musb_g_tx(musb, epnum);
1641 if (is_peripheral_capable())
1642 musb_g_tx(musb, epnum);
1643 }
1644 } else { 1660 } else {
1645 /* receive */ 1661 /* receive */
1646 if (devctl & MUSB_DEVCTL_HM) { 1662 if (devctl & MUSB_DEVCTL_HM)
1647 if (is_host_capable()) 1663 musb_host_rx(musb, epnum);
1648 musb_host_rx(musb, epnum); 1664 else
1649 } else { 1665 musb_g_rx(musb, epnum);
1650 if (is_peripheral_capable())
1651 musb_g_rx(musb, epnum);
1652 }
1653 } 1666 }
1654 } 1667 }
1655} 1668}
@@ -1785,10 +1798,9 @@ static const struct attribute_group musb_attr_group = {
1785static void musb_irq_work(struct work_struct *data) 1798static void musb_irq_work(struct work_struct *data)
1786{ 1799{
1787 struct musb *musb = container_of(data, struct musb, irq_work); 1800 struct musb *musb = container_of(data, struct musb, irq_work);
1788 static int old_state;
1789 1801
1790 if (musb->xceiv->state != old_state) { 1802 if (musb->xceiv->state != musb->xceiv_old_state) {
1791 old_state = musb->xceiv->state; 1803 musb->xceiv_old_state = musb->xceiv->state;
1792 sysfs_notify(&musb->controller->kobj, NULL, "mode"); 1804 sysfs_notify(&musb->controller->kobj, NULL, "mode");
1793 } 1805 }
1794} 1806}
@@ -1862,15 +1874,15 @@ static void musb_free(struct musb *musb)
1862 dma_controller_destroy(c); 1874 dma_controller_destroy(c);
1863 } 1875 }
1864 1876
1865 kfree(musb); 1877 usb_put_hcd(musb_to_hcd(musb));
1866} 1878}
1867 1879
1868/* 1880/*
1869 * Perform generic per-controller initialization. 1881 * Perform generic per-controller initialization.
1870 * 1882 *
1871 * @pDevice: the controller (already clocked, etc) 1883 * @dev: the controller (already clocked, etc)
1872 * @nIrq: irq 1884 * @nIrq: IRQ number
1873 * @mregs: virtual address of controller registers, 1885 * @ctrl: virtual address of controller registers,
1874 * not yet corrected for platform-specific offsets 1886 * not yet corrected for platform-specific offsets
1875 */ 1887 */
1876static int __devinit 1888static int __devinit
@@ -1879,6 +1891,7 @@ musb_init_controller(struct device *dev, int nIrq, void __iomem *ctrl)
1879 int status; 1891 int status;
1880 struct musb *musb; 1892 struct musb *musb;
1881 struct musb_hdrc_platform_data *plat = dev->platform_data; 1893 struct musb_hdrc_platform_data *plat = dev->platform_data;
1894 struct usb_hcd *hcd;
1882 1895
1883 /* The driver might handle more features than the board; OK. 1896 /* The driver might handle more features than the board; OK.
1884 * Fail when the board needs a feature that's not enabled. 1897 * Fail when the board needs a feature that's not enabled.
@@ -1901,7 +1914,6 @@ musb_init_controller(struct device *dev, int nIrq, void __iomem *ctrl)
1901 pm_runtime_enable(musb->controller); 1914 pm_runtime_enable(musb->controller);
1902 1915
1903 spin_lock_init(&musb->lock); 1916 spin_lock_init(&musb->lock);
1904 musb->board_mode = plat->mode;
1905 musb->board_set_power = plat->set_power; 1917 musb->board_set_power = plat->set_power;
1906 musb->min_power = plat->min_power; 1918 musb->min_power = plat->min_power;
1907 musb->ops = plat->platform_ops; 1919 musb->ops = plat->platform_ops;
@@ -1972,7 +1984,7 @@ musb_init_controller(struct device *dev, int nIrq, void __iomem *ctrl)
1972 goto fail3; 1984 goto fail3;
1973 } 1985 }
1974 musb->nIrq = nIrq; 1986 musb->nIrq = nIrq;
1975/* FIXME this handles wakeup irqs wrong */ 1987 /* FIXME this handles wakeup irqs wrong */
1976 if (enable_irq_wake(nIrq) == 0) { 1988 if (enable_irq_wake(nIrq) == 0) {
1977 musb->irq_wake = 1; 1989 musb->irq_wake = 1;
1978 device_init_wakeup(dev, 1); 1990 device_init_wakeup(dev, 1);
@@ -1981,58 +1993,25 @@ musb_init_controller(struct device *dev, int nIrq, void __iomem *ctrl)
1981 } 1993 }
1982 1994
1983 /* host side needs more setup */ 1995 /* host side needs more setup */
1984 if (is_host_enabled(musb)) { 1996 hcd = musb_to_hcd(musb);
1985 struct usb_hcd *hcd = musb_to_hcd(musb); 1997 otg_set_host(musb->xceiv->otg, &hcd->self);
1986 1998 hcd->self.otg_port = 1;
1987 otg_set_host(musb->xceiv->otg, &hcd->self); 1999 musb->xceiv->otg->host = &hcd->self;
1988 2000 hcd->power_budget = 2 * (plat->power ? : 250);
1989 if (is_otg_enabled(musb)) 2001
1990 hcd->self.otg_port = 1; 2002 /* program PHY to use external vBus if required */
1991 musb->xceiv->otg->host = &hcd->self; 2003 if (plat->extvbus) {
1992 hcd->power_budget = 2 * (plat->power ? : 250); 2004 u8 busctl = musb_read_ulpi_buscontrol(musb->mregs);
1993 2005 busctl |= MUSB_ULPI_USE_EXTVBUS;
1994 /* program PHY to use external vBus if required */ 2006 musb_write_ulpi_buscontrol(musb->mregs, busctl);
1995 if (plat->extvbus) {
1996 u8 busctl = musb_read_ulpi_buscontrol(musb->mregs);
1997 busctl |= MUSB_ULPI_USE_EXTVBUS;
1998 musb_write_ulpi_buscontrol(musb->mregs, busctl);
1999 }
2000 } 2007 }
2001 2008
2002 /* For the host-only role, we can activate right away. 2009 MUSB_DEV_MODE(musb);
2003 * (We expect the ID pin to be forcibly grounded!!) 2010 musb->xceiv->otg->default_a = 0;
2004 * Otherwise, wait till the gadget driver hooks up. 2011 musb->xceiv->state = OTG_STATE_B_IDLE;
2005 */
2006 if (!is_otg_enabled(musb) && is_host_enabled(musb)) {
2007 struct usb_hcd *hcd = musb_to_hcd(musb);
2008
2009 MUSB_HST_MODE(musb);
2010 musb->xceiv->otg->default_a = 1;
2011 musb->xceiv->state = OTG_STATE_A_IDLE;
2012
2013 status = usb_add_hcd(musb_to_hcd(musb), 0, 0);
2014
2015 hcd->self.uses_pio_for_control = 1;
2016 dev_dbg(musb->controller, "%s mode, status %d, devctl %02x %c\n",
2017 "HOST", status,
2018 musb_readb(musb->mregs, MUSB_DEVCTL),
2019 (musb_readb(musb->mregs, MUSB_DEVCTL)
2020 & MUSB_DEVCTL_BDEVICE
2021 ? 'B' : 'A'));
2022
2023 } else /* peripheral is enabled */ {
2024 MUSB_DEV_MODE(musb);
2025 musb->xceiv->otg->default_a = 0;
2026 musb->xceiv->state = OTG_STATE_B_IDLE;
2027
2028 status = musb_gadget_setup(musb);
2029 2012
2030 dev_dbg(musb->controller, "%s mode, status %d, dev%02x\n", 2013 status = musb_gadget_setup(musb);
2031 is_otg_enabled(musb) ? "OTG" : "PERIPHERAL",
2032 status,
2033 musb_readb(musb->mregs, MUSB_DEVCTL));
2034 2014
2035 }
2036 if (status < 0) 2015 if (status < 0)
2037 goto fail3; 2016 goto fail3;
2038 2017
@@ -2048,28 +2027,13 @@ musb_init_controller(struct device *dev, int nIrq, void __iomem *ctrl)
2048 2027
2049 pm_runtime_put(musb->controller); 2028 pm_runtime_put(musb->controller);
2050 2029
2051 dev_info(dev, "USB %s mode controller at %p using %s, IRQ %d\n",
2052 ({char *s;
2053 switch (musb->board_mode) {
2054 case MUSB_HOST: s = "Host"; break;
2055 case MUSB_PERIPHERAL: s = "Peripheral"; break;
2056 default: s = "OTG"; break;
2057 }; s; }),
2058 ctrl,
2059 (is_dma_capable() && musb->dma_controller)
2060 ? "DMA" : "PIO",
2061 musb->nIrq);
2062
2063 return 0; 2030 return 0;
2064 2031
2065fail5: 2032fail5:
2066 musb_exit_debugfs(musb); 2033 musb_exit_debugfs(musb);
2067 2034
2068fail4: 2035fail4:
2069 if (!is_otg_enabled(musb) && is_host_enabled(musb)) 2036 musb_gadget_cleanup(musb);
2070 usb_remove_hcd(musb_to_hcd(musb));
2071 else
2072 musb_gadget_cleanup(musb);
2073 2037
2074fail3: 2038fail3:
2075 pm_runtime_put_sync(musb->controller); 2039 pm_runtime_put_sync(musb->controller);
@@ -2096,11 +2060,6 @@ fail0:
2096/* all implementations (PCI bridge to FPGA, VLYNQ, etc) should just 2060/* all implementations (PCI bridge to FPGA, VLYNQ, etc) should just
2097 * bridge to a platform device; this driver then suffices. 2061 * bridge to a platform device; this driver then suffices.
2098 */ 2062 */
2099
2100#ifndef CONFIG_MUSB_PIO_ONLY
2101static u64 *orig_dma_mask;
2102#endif
2103
2104static int __devinit musb_probe(struct platform_device *pdev) 2063static int __devinit musb_probe(struct platform_device *pdev)
2105{ 2064{
2106 struct device *dev = &pdev->dev; 2065 struct device *dev = &pdev->dev;
@@ -2119,10 +2078,6 @@ static int __devinit musb_probe(struct platform_device *pdev)
2119 return -ENOMEM; 2078 return -ENOMEM;
2120 } 2079 }
2121 2080
2122#ifndef CONFIG_MUSB_PIO_ONLY
2123 /* clobbered by use_dma=n */
2124 orig_dma_mask = dev->dma_mask;
2125#endif
2126 status = musb_init_controller(dev, irq, base); 2081 status = musb_init_controller(dev, irq, base);
2127 if (status < 0) 2082 if (status < 0)
2128 iounmap(base); 2083 iounmap(base);
@@ -2132,7 +2087,8 @@ static int __devinit musb_probe(struct platform_device *pdev)
2132 2087
2133static int __devexit musb_remove(struct platform_device *pdev) 2088static int __devexit musb_remove(struct platform_device *pdev)
2134{ 2089{
2135 struct musb *musb = dev_to_musb(&pdev->dev); 2090 struct device *dev = &pdev->dev;
2091 struct musb *musb = dev_to_musb(dev);
2136 void __iomem *ctrl_base = musb->ctrl_base; 2092 void __iomem *ctrl_base = musb->ctrl_base;
2137 2093
2138 /* this gets called on rmmod. 2094 /* this gets called on rmmod.
@@ -2145,9 +2101,9 @@ static int __devexit musb_remove(struct platform_device *pdev)
2145 2101
2146 musb_free(musb); 2102 musb_free(musb);
2147 iounmap(ctrl_base); 2103 iounmap(ctrl_base);
2148 device_init_wakeup(&pdev->dev, 0); 2104 device_init_wakeup(dev, 0);
2149#ifndef CONFIG_MUSB_PIO_ONLY 2105#ifndef CONFIG_MUSB_PIO_ONLY
2150 pdev->dev.dma_mask = orig_dma_mask; 2106 dma_set_mask(dev, *dev->parent->dma_mask);
2151#endif 2107#endif
2152 return 0; 2108 return 0;
2153} 2109}
@@ -2160,11 +2116,9 @@ static void musb_save_context(struct musb *musb)
2160 void __iomem *musb_base = musb->mregs; 2116 void __iomem *musb_base = musb->mregs;
2161 void __iomem *epio; 2117 void __iomem *epio;
2162 2118
2163 if (is_host_enabled(musb)) { 2119 musb->context.frame = musb_readw(musb_base, MUSB_FRAME);
2164 musb->context.frame = musb_readw(musb_base, MUSB_FRAME); 2120 musb->context.testmode = musb_readb(musb_base, MUSB_TESTMODE);
2165 musb->context.testmode = musb_readb(musb_base, MUSB_TESTMODE); 2121 musb->context.busctl = musb_read_ulpi_buscontrol(musb->mregs);
2166 musb->context.busctl = musb_read_ulpi_buscontrol(musb->mregs);
2167 }
2168 musb->context.power = musb_readb(musb_base, MUSB_POWER); 2122 musb->context.power = musb_readb(musb_base, MUSB_POWER);
2169 musb->context.intrtxe = musb_readw(musb_base, MUSB_INTRTXE); 2123 musb->context.intrtxe = musb_readw(musb_base, MUSB_INTRTXE);
2170 musb->context.intrrxe = musb_readw(musb_base, MUSB_INTRRXE); 2124 musb->context.intrrxe = musb_readw(musb_base, MUSB_INTRRXE);
@@ -2203,30 +2157,29 @@ static void musb_save_context(struct musb *musb)
2203 musb->context.index_regs[i].rxfifosz = 2157 musb->context.index_regs[i].rxfifosz =
2204 musb_read_rxfifosz(musb_base); 2158 musb_read_rxfifosz(musb_base);
2205 } 2159 }
2206 if (is_host_enabled(musb)) { 2160
2207 musb->context.index_regs[i].txtype = 2161 musb->context.index_regs[i].txtype =
2208 musb_readb(epio, MUSB_TXTYPE); 2162 musb_readb(epio, MUSB_TXTYPE);
2209 musb->context.index_regs[i].txinterval = 2163 musb->context.index_regs[i].txinterval =
2210 musb_readb(epio, MUSB_TXINTERVAL); 2164 musb_readb(epio, MUSB_TXINTERVAL);
2211 musb->context.index_regs[i].rxtype = 2165 musb->context.index_regs[i].rxtype =
2212 musb_readb(epio, MUSB_RXTYPE); 2166 musb_readb(epio, MUSB_RXTYPE);
2213 musb->context.index_regs[i].rxinterval = 2167 musb->context.index_regs[i].rxinterval =
2214 musb_readb(epio, MUSB_RXINTERVAL); 2168 musb_readb(epio, MUSB_RXINTERVAL);
2215 2169
2216 musb->context.index_regs[i].txfunaddr = 2170 musb->context.index_regs[i].txfunaddr =
2217 musb_read_txfunaddr(musb_base, i); 2171 musb_read_txfunaddr(musb_base, i);
2218 musb->context.index_regs[i].txhubaddr = 2172 musb->context.index_regs[i].txhubaddr =
2219 musb_read_txhubaddr(musb_base, i); 2173 musb_read_txhubaddr(musb_base, i);
2220 musb->context.index_regs[i].txhubport = 2174 musb->context.index_regs[i].txhubport =
2221 musb_read_txhubport(musb_base, i); 2175 musb_read_txhubport(musb_base, i);
2222 2176
2223 musb->context.index_regs[i].rxfunaddr = 2177 musb->context.index_regs[i].rxfunaddr =
2224 musb_read_rxfunaddr(musb_base, i); 2178 musb_read_rxfunaddr(musb_base, i);
2225 musb->context.index_regs[i].rxhubaddr = 2179 musb->context.index_regs[i].rxhubaddr =
2226 musb_read_rxhubaddr(musb_base, i); 2180 musb_read_rxhubaddr(musb_base, i);
2227 musb->context.index_regs[i].rxhubport = 2181 musb->context.index_regs[i].rxhubport =
2228 musb_read_rxhubport(musb_base, i); 2182 musb_read_rxhubport(musb_base, i);
2229 }
2230 } 2183 }
2231} 2184}
2232 2185
@@ -2237,11 +2190,9 @@ static void musb_restore_context(struct musb *musb)
2237 void __iomem *ep_target_regs; 2190 void __iomem *ep_target_regs;
2238 void __iomem *epio; 2191 void __iomem *epio;
2239 2192
2240 if (is_host_enabled(musb)) { 2193 musb_writew(musb_base, MUSB_FRAME, musb->context.frame);
2241 musb_writew(musb_base, MUSB_FRAME, musb->context.frame); 2194 musb_writeb(musb_base, MUSB_TESTMODE, musb->context.testmode);
2242 musb_writeb(musb_base, MUSB_TESTMODE, musb->context.testmode); 2195 musb_write_ulpi_buscontrol(musb->mregs, musb->context.busctl);
2243 musb_write_ulpi_buscontrol(musb->mregs, musb->context.busctl);
2244 }
2245 musb_writeb(musb_base, MUSB_POWER, musb->context.power); 2196 musb_writeb(musb_base, MUSB_POWER, musb->context.power);
2246 musb_writew(musb_base, MUSB_INTRTXE, musb->context.intrtxe); 2197 musb_writew(musb_base, MUSB_INTRTXE, musb->context.intrtxe);
2247 musb_writew(musb_base, MUSB_INTRRXE, musb->context.intrrxe); 2198 musb_writew(musb_base, MUSB_INTRRXE, musb->context.intrrxe);
@@ -2280,33 +2231,31 @@ static void musb_restore_context(struct musb *musb)
2280 musb->context.index_regs[i].rxfifoadd); 2231 musb->context.index_regs[i].rxfifoadd);
2281 } 2232 }
2282 2233
2283 if (is_host_enabled(musb)) { 2234 musb_writeb(epio, MUSB_TXTYPE,
2284 musb_writeb(epio, MUSB_TXTYPE,
2285 musb->context.index_regs[i].txtype); 2235 musb->context.index_regs[i].txtype);
2286 musb_writeb(epio, MUSB_TXINTERVAL, 2236 musb_writeb(epio, MUSB_TXINTERVAL,
2287 musb->context.index_regs[i].txinterval); 2237 musb->context.index_regs[i].txinterval);
2288 musb_writeb(epio, MUSB_RXTYPE, 2238 musb_writeb(epio, MUSB_RXTYPE,
2289 musb->context.index_regs[i].rxtype); 2239 musb->context.index_regs[i].rxtype);
2290 musb_writeb(epio, MUSB_RXINTERVAL, 2240 musb_writeb(epio, MUSB_RXINTERVAL,
2291 2241
2292 musb->context.index_regs[i].rxinterval); 2242 musb->context.index_regs[i].rxinterval);
2293 musb_write_txfunaddr(musb_base, i, 2243 musb_write_txfunaddr(musb_base, i,
2294 musb->context.index_regs[i].txfunaddr); 2244 musb->context.index_regs[i].txfunaddr);
2295 musb_write_txhubaddr(musb_base, i, 2245 musb_write_txhubaddr(musb_base, i,
2296 musb->context.index_regs[i].txhubaddr); 2246 musb->context.index_regs[i].txhubaddr);
2297 musb_write_txhubport(musb_base, i, 2247 musb_write_txhubport(musb_base, i,
2298 musb->context.index_regs[i].txhubport); 2248 musb->context.index_regs[i].txhubport);
2299 2249
2300 ep_target_regs = 2250 ep_target_regs =
2301 musb_read_target_reg_base(i, musb_base); 2251 musb_read_target_reg_base(i, musb_base);
2302 2252
2303 musb_write_rxfunaddr(ep_target_regs, 2253 musb_write_rxfunaddr(ep_target_regs,
2304 musb->context.index_regs[i].rxfunaddr); 2254 musb->context.index_regs[i].rxfunaddr);
2305 musb_write_rxhubaddr(ep_target_regs, 2255 musb_write_rxhubaddr(ep_target_regs,
2306 musb->context.index_regs[i].rxhubaddr); 2256 musb->context.index_regs[i].rxhubaddr);
2307 musb_write_rxhubport(ep_target_regs, 2257 musb_write_rxhubport(ep_target_regs,
2308 musb->context.index_regs[i].rxhubport); 2258 musb->context.index_regs[i].rxhubport);
2309 }
2310 } 2259 }
2311 musb_writeb(musb_base, MUSB_INDEX, musb->context.index); 2260 musb_writeb(musb_base, MUSB_INDEX, musb->context.index);
2312} 2261}
diff --git a/drivers/usb/musb/musb_core.h b/drivers/usb/musb/musb_core.h
index 586105b55a7c..c158aacd6de8 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 */
@@ -88,8 +84,6 @@ struct musb_ep;
88 84
89/****************************** PERIPHERAL ROLE *****************************/ 85/****************************** PERIPHERAL ROLE *****************************/
90 86
91#define is_peripheral_capable() (1)
92
93extern irqreturn_t musb_g_ep0_irq(struct musb *); 87extern irqreturn_t musb_g_ep0_irq(struct musb *);
94extern void musb_g_tx(struct musb *, u8); 88extern void musb_g_tx(struct musb *, u8);
95extern void musb_g_rx(struct musb *, u8); 89extern void musb_g_rx(struct musb *, u8);
@@ -101,8 +95,6 @@ extern void musb_g_disconnect(struct musb *);
101 95
102/****************************** HOST ROLE ***********************************/ 96/****************************** HOST ROLE ***********************************/
103 97
104#define is_host_capable() (1)
105
106extern irqreturn_t musb_h_ep0_irq(struct musb *); 98extern irqreturn_t musb_h_ep0_irq(struct musb *);
107extern void musb_host_tx(struct musb *, u8); 99extern void musb_host_tx(struct musb *, u8);
108extern void musb_host_rx(struct musb *, u8); 100extern void musb_host_rx(struct musb *, u8);
@@ -376,7 +368,6 @@ struct musb {
376 u16 epmask; 368 u16 epmask;
377 u8 nr_endpoints; 369 u8 nr_endpoints;
378 370
379 u8 board_mode; /* enum musb_mode */
380 int (*board_set_power)(int state); 371 int (*board_set_power)(int state);
381 372
382 u8 min_power; /* vbus for periph, in mA/2 */ 373 u8 min_power; /* vbus for periph, in mA/2 */
@@ -446,6 +437,10 @@ struct musb {
446#ifdef MUSB_CONFIG_PROC_FS 437#ifdef MUSB_CONFIG_PROC_FS
447 struct proc_dir_entry *proc_entry; 438 struct proc_dir_entry *proc_entry;
448#endif 439#endif
440 int xceiv_old_state;
441#ifdef CONFIG_DEBUG_FS
442 struct dentry *debugfs_root;
443#endif
449}; 444};
450 445
451static inline struct musb *gadget_to_musb(struct usb_gadget *g) 446static inline struct musb *gadget_to_musb(struct usb_gadget *g)
@@ -484,7 +479,7 @@ static inline void musb_configure_ep0(struct musb *musb)
484static inline int musb_read_fifosize(struct musb *musb, 479static inline int musb_read_fifosize(struct musb *musb,
485 struct musb_hw_ep *hw_ep, u8 epnum) 480 struct musb_hw_ep *hw_ep, u8 epnum)
486{ 481{
487 void *mbase = musb->mregs; 482 void __iomem *mbase = musb->mregs;
488 u8 reg = 0; 483 u8 reg = 0;
489 484
490 /* read from core using indexed model */ 485 /* read from core using indexed model */
@@ -526,6 +521,8 @@ extern const char musb_driver_name[];
526 521
527extern void musb_start(struct musb *musb); 522extern void musb_start(struct musb *musb);
528extern void musb_stop(struct musb *musb); 523extern void musb_stop(struct musb *musb);
524extern int musb_get_id(struct device *dev, gfp_t gfp_mask);
525extern void musb_put_id(struct device *dev, int id);
529 526
530extern void musb_write_fifo(struct musb_hw_ep *ep, u16 len, const u8 *src); 527extern void musb_write_fifo(struct musb_hw_ep *ep, u16 len, const u8 *src);
531extern void musb_read_fifo(struct musb_hw_ep *ep, u16 len, u8 *dst); 528extern void musb_read_fifo(struct musb_hw_ep *ep, u16 len, u8 *dst);
diff --git a/drivers/usb/musb/musb_debugfs.c b/drivers/usb/musb/musb_debugfs.c
index 40a37c91cc10..1d6e8af94c06 100644
--- a/drivers/usb/musb/musb_debugfs.c
+++ b/drivers/usb/musb/musb_debugfs.c
@@ -103,8 +103,6 @@ static const struct musb_register_map musb_regmap[] = {
103 { } /* Terminating Entry */ 103 { } /* Terminating Entry */
104}; 104};
105 105
106static struct dentry *musb_debugfs_root;
107
108static int musb_regdump_show(struct seq_file *s, void *unused) 106static int musb_regdump_show(struct seq_file *s, void *unused)
109{ 107{
110 struct musb *musb = s->private; 108 struct musb *musb = s->private;
@@ -241,7 +239,7 @@ int __devinit musb_init_debugfs(struct musb *musb)
241 struct dentry *file; 239 struct dentry *file;
242 int ret; 240 int ret;
243 241
244 root = debugfs_create_dir("musb", NULL); 242 root = debugfs_create_dir(dev_name(musb->controller), NULL);
245 if (!root) { 243 if (!root) {
246 ret = -ENOMEM; 244 ret = -ENOMEM;
247 goto err0; 245 goto err0;
@@ -261,7 +259,7 @@ int __devinit musb_init_debugfs(struct musb *musb)
261 goto err1; 259 goto err1;
262 } 260 }
263 261
264 musb_debugfs_root = root; 262 musb->debugfs_root = root;
265 263
266 return 0; 264 return 0;
267 265
@@ -274,5 +272,5 @@ err0:
274 272
275void /* __init_or_exit */ musb_exit_debugfs(struct musb *musb) 273void /* __init_or_exit */ musb_exit_debugfs(struct musb *musb)
276{ 274{
277 debugfs_remove_recursive(musb_debugfs_root); 275 debugfs_remove_recursive(musb->debugfs_root);
278} 276}
diff --git a/drivers/usb/musb/musb_dma.h b/drivers/usb/musb/musb_dma.h
index 3a97c4e2d4f5..24d39210d4ab 100644
--- a/drivers/usb/musb/musb_dma.h
+++ b/drivers/usb/musb/musb_dma.h
@@ -178,7 +178,7 @@ struct dma_controller {
178extern void musb_dma_completion(struct musb *musb, u8 epnum, u8 transmit); 178extern void musb_dma_completion(struct musb *musb, u8 epnum, u8 transmit);
179 179
180 180
181extern struct dma_controller *__init 181extern struct dma_controller *__devinit
182dma_controller_create(struct musb *, void __iomem *); 182dma_controller_create(struct musb *, void __iomem *);
183 183
184extern void dma_controller_destroy(struct dma_controller *); 184extern void dma_controller_destroy(struct dma_controller *);
diff --git a/drivers/usb/musb/musb_dsps.c b/drivers/usb/musb/musb_dsps.c
index c20b8776aafa..444346e1e10d 100644
--- a/drivers/usb/musb/musb_dsps.c
+++ b/drivers/usb/musb/musb_dsps.c
@@ -31,6 +31,7 @@
31 31
32#include <linux/init.h> 32#include <linux/init.h>
33#include <linux/io.h> 33#include <linux/io.h>
34#include <linux/of.h>
34#include <linux/err.h> 35#include <linux/err.h>
35#include <linux/platform_device.h> 36#include <linux/platform_device.h>
36#include <linux/dma-mapping.h> 37#include <linux/dma-mapping.h>
@@ -46,6 +47,10 @@
46 47
47#include "musb_core.h" 48#include "musb_core.h"
48 49
50#ifdef CONFIG_OF
51static const struct of_device_id musb_dsps_of_match[];
52#endif
53
49/** 54/**
50 * avoid using musb_readx()/musb_writex() as glue layer should not be 55 * avoid using musb_readx()/musb_writex() as glue layer should not be
51 * dependent on musb core layer symbols. 56 * dependent on musb core layer symbols.
@@ -106,6 +111,8 @@ struct dsps_musb_wrapper {
106 /* miscellaneous stuff */ 111 /* miscellaneous stuff */
107 u32 musb_core_offset; 112 u32 musb_core_offset;
108 u8 poll_seconds; 113 u8 poll_seconds;
114 /* number of musb instances */
115 u8 instances;
109}; 116};
110 117
111/** 118/**
@@ -113,9 +120,10 @@ struct dsps_musb_wrapper {
113 */ 120 */
114struct dsps_glue { 121struct dsps_glue {
115 struct device *dev; 122 struct device *dev;
116 struct platform_device *musb; /* child musb pdev */ 123 struct platform_device *musb[2]; /* child musb pdev */
117 const struct dsps_musb_wrapper *wrp; /* wrapper register offsets */ 124 const struct dsps_musb_wrapper *wrp; /* wrapper register offsets */
118 struct timer_list timer; /* otg_workaround timer */ 125 struct timer_list timer[2]; /* otg_workaround timer */
126 unsigned long last_timer[2]; /* last timer data for each instance */
119}; 127};
120 128
121/** 129/**
@@ -138,9 +146,8 @@ static void dsps_musb_enable(struct musb *musb)
138 dsps_writel(reg_base, wrp->epintr_set, epmask); 146 dsps_writel(reg_base, wrp->epintr_set, epmask);
139 dsps_writel(reg_base, wrp->coreintr_set, coremask); 147 dsps_writel(reg_base, wrp->coreintr_set, coremask);
140 /* Force the DRVVBUS IRQ so we can start polling for ID change. */ 148 /* Force the DRVVBUS IRQ so we can start polling for ID change. */
141 if (is_otg_enabled(musb)) 149 dsps_writel(reg_base, wrp->coreintr_set,
142 dsps_writel(reg_base, wrp->coreintr_set, 150 (1 << wrp->drvvbus) << wrp->usb_shift);
143 (1 << wrp->drvvbus) << wrp->usb_shift);
144} 151}
145 152
146/** 153/**
@@ -166,8 +173,8 @@ static void otg_timer(unsigned long _musb)
166 struct musb *musb = (void *)_musb; 173 struct musb *musb = (void *)_musb;
167 void __iomem *mregs = musb->mregs; 174 void __iomem *mregs = musb->mregs;
168 struct device *dev = musb->controller; 175 struct device *dev = musb->controller;
169 struct platform_device *pdev = to_platform_device(dev->parent); 176 struct platform_device *pdev = to_platform_device(dev);
170 struct dsps_glue *glue = platform_get_drvdata(pdev); 177 struct dsps_glue *glue = dev_get_drvdata(dev->parent);
171 const struct dsps_musb_wrapper *wrp = glue->wrp; 178 const struct dsps_musb_wrapper *wrp = glue->wrp;
172 u8 devctl; 179 u8 devctl;
173 unsigned long flags; 180 unsigned long flags;
@@ -201,12 +208,9 @@ static void otg_timer(unsigned long _musb)
201 MUSB_INTR_VBUSERROR << wrp->usb_shift); 208 MUSB_INTR_VBUSERROR << wrp->usb_shift);
202 break; 209 break;
203 case OTG_STATE_B_IDLE: 210 case OTG_STATE_B_IDLE:
204 if (!is_peripheral_enabled(musb))
205 break;
206
207 devctl = dsps_readb(mregs, MUSB_DEVCTL); 211 devctl = dsps_readb(mregs, MUSB_DEVCTL);
208 if (devctl & MUSB_DEVCTL_BDEVICE) 212 if (devctl & MUSB_DEVCTL_BDEVICE)
209 mod_timer(&glue->timer, 213 mod_timer(&glue->timer[pdev->id],
210 jiffies + wrp->poll_seconds * HZ); 214 jiffies + wrp->poll_seconds * HZ);
211 else 215 else
212 musb->xceiv->state = OTG_STATE_A_IDLE; 216 musb->xceiv->state = OTG_STATE_A_IDLE;
@@ -220,12 +224,8 @@ static void otg_timer(unsigned long _musb)
220static void dsps_musb_try_idle(struct musb *musb, unsigned long timeout) 224static void dsps_musb_try_idle(struct musb *musb, unsigned long timeout)
221{ 225{
222 struct device *dev = musb->controller; 226 struct device *dev = musb->controller;
223 struct platform_device *pdev = to_platform_device(dev->parent); 227 struct platform_device *pdev = to_platform_device(dev);
224 struct dsps_glue *glue = platform_get_drvdata(pdev); 228 struct dsps_glue *glue = dev_get_drvdata(dev->parent);
225 static unsigned long last_timer;
226
227 if (!is_otg_enabled(musb))
228 return;
229 229
230 if (timeout == 0) 230 if (timeout == 0)
231 timeout = jiffies + msecs_to_jiffies(3); 231 timeout = jiffies + msecs_to_jiffies(3);
@@ -235,22 +235,23 @@ static void dsps_musb_try_idle(struct musb *musb, unsigned long timeout)
235 musb->xceiv->state == OTG_STATE_A_WAIT_BCON)) { 235 musb->xceiv->state == OTG_STATE_A_WAIT_BCON)) {
236 dev_dbg(musb->controller, "%s active, deleting timer\n", 236 dev_dbg(musb->controller, "%s active, deleting timer\n",
237 otg_state_string(musb->xceiv->state)); 237 otg_state_string(musb->xceiv->state));
238 del_timer(&glue->timer); 238 del_timer(&glue->timer[pdev->id]);
239 last_timer = jiffies; 239 glue->last_timer[pdev->id] = jiffies;
240 return; 240 return;
241 } 241 }
242 242
243 if (time_after(last_timer, timeout) && timer_pending(&glue->timer)) { 243 if (time_after(glue->last_timer[pdev->id], timeout) &&
244 timer_pending(&glue->timer[pdev->id])) {
244 dev_dbg(musb->controller, 245 dev_dbg(musb->controller,
245 "Longer idle timer already pending, ignoring...\n"); 246 "Longer idle timer already pending, ignoring...\n");
246 return; 247 return;
247 } 248 }
248 last_timer = timeout; 249 glue->last_timer[pdev->id] = timeout;
249 250
250 dev_dbg(musb->controller, "%s inactive, starting idle timer for %u ms\n", 251 dev_dbg(musb->controller, "%s inactive, starting idle timer for %u ms\n",
251 otg_state_string(musb->xceiv->state), 252 otg_state_string(musb->xceiv->state),
252 jiffies_to_msecs(timeout - jiffies)); 253 jiffies_to_msecs(timeout - jiffies));
253 mod_timer(&glue->timer, timeout); 254 mod_timer(&glue->timer[pdev->id], timeout);
254} 255}
255 256
256static irqreturn_t dsps_interrupt(int irq, void *hci) 257static irqreturn_t dsps_interrupt(int irq, void *hci)
@@ -258,8 +259,8 @@ static irqreturn_t dsps_interrupt(int irq, void *hci)
258 struct musb *musb = hci; 259 struct musb *musb = hci;
259 void __iomem *reg_base = musb->ctrl_base; 260 void __iomem *reg_base = musb->ctrl_base;
260 struct device *dev = musb->controller; 261 struct device *dev = musb->controller;
261 struct platform_device *pdev = to_platform_device(dev->parent); 262 struct platform_device *pdev = to_platform_device(dev);
262 struct dsps_glue *glue = platform_get_drvdata(pdev); 263 struct dsps_glue *glue = dev_get_drvdata(dev->parent);
263 const struct dsps_musb_wrapper *wrp = glue->wrp; 264 const struct dsps_musb_wrapper *wrp = glue->wrp;
264 unsigned long flags; 265 unsigned long flags;
265 irqreturn_t ret = IRQ_NONE; 266 irqreturn_t ret = IRQ_NONE;
@@ -294,7 +295,7 @@ static irqreturn_t dsps_interrupt(int irq, void *hci)
294 * value but DEVCTL.BDEVICE is invalid without DEVCTL.SESSION set. 295 * value but DEVCTL.BDEVICE is invalid without DEVCTL.SESSION set.
295 * Also, DRVVBUS pulses for SRP (but not at 5V) ... 296 * Also, DRVVBUS pulses for SRP (but not at 5V) ...
296 */ 297 */
297 if ((usbintr & MUSB_INTR_BABBLE) && is_host_enabled(musb)) 298 if (usbintr & MUSB_INTR_BABBLE)
298 pr_info("CAUTION: musb: Babble Interrupt Occured\n"); 299 pr_info("CAUTION: musb: Babble Interrupt Occured\n");
299 300
300 if (usbintr & ((1 << wrp->drvvbus) << wrp->usb_shift)) { 301 if (usbintr & ((1 << wrp->drvvbus) << wrp->usb_shift)) {
@@ -303,8 +304,7 @@ static irqreturn_t dsps_interrupt(int irq, void *hci)
303 u8 devctl = dsps_readb(mregs, MUSB_DEVCTL); 304 u8 devctl = dsps_readb(mregs, MUSB_DEVCTL);
304 int err; 305 int err;
305 306
306 err = is_host_enabled(musb) && (musb->int_usb & 307 err = musb->int_usb & MUSB_INTR_VBUSERROR;
307 MUSB_INTR_VBUSERROR);
308 if (err) { 308 if (err) {
309 /* 309 /*
310 * The Mentor core doesn't debounce VBUS as needed 310 * The Mentor core doesn't debounce VBUS as needed
@@ -319,15 +319,15 @@ static irqreturn_t dsps_interrupt(int irq, void *hci)
319 */ 319 */
320 musb->int_usb &= ~MUSB_INTR_VBUSERROR; 320 musb->int_usb &= ~MUSB_INTR_VBUSERROR;
321 musb->xceiv->state = OTG_STATE_A_WAIT_VFALL; 321 musb->xceiv->state = OTG_STATE_A_WAIT_VFALL;
322 mod_timer(&glue->timer, 322 mod_timer(&glue->timer[pdev->id],
323 jiffies + wrp->poll_seconds * HZ); 323 jiffies + wrp->poll_seconds * HZ);
324 WARNING("VBUS error workaround (delay coming)\n"); 324 WARNING("VBUS error workaround (delay coming)\n");
325 } else if (is_host_enabled(musb) && drvvbus) { 325 } else if (drvvbus) {
326 musb->is_active = 1; 326 musb->is_active = 1;
327 MUSB_HST_MODE(musb); 327 MUSB_HST_MODE(musb);
328 musb->xceiv->otg->default_a = 1; 328 musb->xceiv->otg->default_a = 1;
329 musb->xceiv->state = OTG_STATE_A_WAIT_VRISE; 329 musb->xceiv->state = OTG_STATE_A_WAIT_VRISE;
330 del_timer(&glue->timer); 330 del_timer(&glue->timer[pdev->id]);
331 } else { 331 } else {
332 musb->is_active = 0; 332 musb->is_active = 0;
333 MUSB_DEV_MODE(musb); 333 MUSB_DEV_MODE(musb);
@@ -353,8 +353,9 @@ static irqreturn_t dsps_interrupt(int irq, void *hci)
353 dsps_writel(reg_base, wrp->eoi, 1); 353 dsps_writel(reg_base, wrp->eoi, 1);
354 354
355 /* Poll for ID change */ 355 /* Poll for ID change */
356 if (is_otg_enabled(musb) && musb->xceiv->state == OTG_STATE_B_IDLE) 356 if (musb->xceiv->state == OTG_STATE_B_IDLE)
357 mod_timer(&glue->timer, jiffies + wrp->poll_seconds * HZ); 357 mod_timer(&glue->timer[pdev->id],
358 jiffies + wrp->poll_seconds * HZ);
358 359
359 spin_unlock_irqrestore(&musb->lock, flags); 360 spin_unlock_irqrestore(&musb->lock, flags);
360 361
@@ -365,8 +366,8 @@ static int dsps_musb_init(struct musb *musb)
365{ 366{
366 struct device *dev = musb->controller; 367 struct device *dev = musb->controller;
367 struct musb_hdrc_platform_data *plat = dev->platform_data; 368 struct musb_hdrc_platform_data *plat = dev->platform_data;
368 struct platform_device *pdev = to_platform_device(dev->parent); 369 struct platform_device *pdev = to_platform_device(dev);
369 struct dsps_glue *glue = platform_get_drvdata(pdev); 370 struct dsps_glue *glue = dev_get_drvdata(dev->parent);
370 const struct dsps_musb_wrapper *wrp = glue->wrp; 371 const struct dsps_musb_wrapper *wrp = glue->wrp;
371 struct omap_musb_board_data *data = plat->board_data; 372 struct omap_musb_board_data *data = plat->board_data;
372 void __iomem *reg_base = musb->ctrl_base; 373 void __iomem *reg_base = musb->ctrl_base;
@@ -376,8 +377,7 @@ static int dsps_musb_init(struct musb *musb)
376 /* mentor core register starts at offset of 0x400 from musb base */ 377 /* mentor core register starts at offset of 0x400 from musb base */
377 musb->mregs += wrp->musb_core_offset; 378 musb->mregs += wrp->musb_core_offset;
378 379
379 /* NOP driver needs change if supporting dual instance */ 380 /* Get the NOP PHY */
380 usb_nop_xceiv_register();
381 musb->xceiv = usb_get_phy(USB_PHY_TYPE_USB2); 381 musb->xceiv = usb_get_phy(USB_PHY_TYPE_USB2);
382 if (IS_ERR_OR_NULL(musb->xceiv)) 382 if (IS_ERR_OR_NULL(musb->xceiv))
383 return -ENODEV; 383 return -ENODEV;
@@ -389,8 +389,7 @@ static int dsps_musb_init(struct musb *musb)
389 goto err0; 389 goto err0;
390 } 390 }
391 391
392 if (is_host_enabled(musb)) 392 setup_timer(&glue->timer[pdev->id], otg_timer, (unsigned long) musb);
393 setup_timer(&glue->timer, otg_timer, (unsigned long) musb);
394 393
395 /* Reset the musb */ 394 /* Reset the musb */
396 dsps_writel(reg_base, wrp->control, (1 << wrp->reset)); 395 dsps_writel(reg_base, wrp->control, (1 << wrp->reset));
@@ -421,11 +420,10 @@ static int dsps_musb_exit(struct musb *musb)
421 struct device *dev = musb->controller; 420 struct device *dev = musb->controller;
422 struct musb_hdrc_platform_data *plat = dev->platform_data; 421 struct musb_hdrc_platform_data *plat = dev->platform_data;
423 struct omap_musb_board_data *data = plat->board_data; 422 struct omap_musb_board_data *data = plat->board_data;
424 struct platform_device *pdev = to_platform_device(dev->parent); 423 struct platform_device *pdev = to_platform_device(dev);
425 struct dsps_glue *glue = platform_get_drvdata(pdev); 424 struct dsps_glue *glue = dev_get_drvdata(dev->parent);
426 425
427 if (is_host_enabled(musb)) 426 del_timer_sync(&glue->timer[pdev->id]);
428 del_timer_sync(&glue->timer);
429 427
430 /* Shutdown the on-chip PHY and its PLL. */ 428 /* Shutdown the on-chip PHY and its PLL. */
431 if (data->set_phy_power) 429 if (data->set_phy_power)
@@ -455,11 +453,13 @@ static int __devinit dsps_create_musb_pdev(struct dsps_glue *glue, u8 id)
455 struct device *dev = glue->dev; 453 struct device *dev = glue->dev;
456 struct platform_device *pdev = to_platform_device(dev); 454 struct platform_device *pdev = to_platform_device(dev);
457 struct musb_hdrc_platform_data *pdata = dev->platform_data; 455 struct musb_hdrc_platform_data *pdata = dev->platform_data;
456 struct device_node *np = pdev->dev.of_node;
457 struct musb_hdrc_config *config;
458 struct platform_device *musb; 458 struct platform_device *musb;
459 struct resource *res; 459 struct resource *res;
460 struct resource resources[2]; 460 struct resource resources[2];
461 char res_name[10]; 461 char res_name[10];
462 int ret; 462 int ret, musbid;
463 463
464 /* get memory resource */ 464 /* get memory resource */
465 sprintf(res_name, "musb%d", id); 465 sprintf(res_name, "musb%d", id);
@@ -484,62 +484,107 @@ static int __devinit dsps_create_musb_pdev(struct dsps_glue *glue, u8 id)
484 resources[1] = *res; 484 resources[1] = *res;
485 resources[1].name = "mc"; 485 resources[1].name = "mc";
486 486
487 /* get the musb id */
488 musbid = musb_get_id(dev, GFP_KERNEL);
489 if (musbid < 0) {
490 dev_err(dev, "failed to allocate musb id\n");
491 ret = -ENOMEM;
492 goto err0;
493 }
487 /* allocate the child platform device */ 494 /* allocate the child platform device */
488 musb = platform_device_alloc("musb-hdrc", -1); 495 musb = platform_device_alloc("musb-hdrc", musbid);
489 if (!musb) { 496 if (!musb) {
490 dev_err(dev, "failed to allocate musb device\n"); 497 dev_err(dev, "failed to allocate musb device\n");
491 ret = -ENOMEM; 498 ret = -ENOMEM;
492 goto err0; 499 goto err1;
493 } 500 }
494 501
502 musb->id = musbid;
495 musb->dev.parent = dev; 503 musb->dev.parent = dev;
496 musb->dev.dma_mask = &musb_dmamask; 504 musb->dev.dma_mask = &musb_dmamask;
497 musb->dev.coherent_dma_mask = musb_dmamask; 505 musb->dev.coherent_dma_mask = musb_dmamask;
498 506
499 glue->musb = musb; 507 glue->musb[id] = musb;
500
501 pdata->platform_ops = &dsps_ops;
502 508
503 ret = platform_device_add_resources(musb, resources, 2); 509 ret = platform_device_add_resources(musb, resources, 2);
504 if (ret) { 510 if (ret) {
505 dev_err(dev, "failed to add resources\n"); 511 dev_err(dev, "failed to add resources\n");
506 goto err1; 512 goto err2;
507 } 513 }
508 514
515 if (np) {
516 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
517 if (!pdata) {
518 dev_err(&pdev->dev,
519 "failed to allocate musb platfrom data\n");
520 ret = -ENOMEM;
521 goto err2;
522 }
523
524 config = devm_kzalloc(&pdev->dev, sizeof(*config), GFP_KERNEL);
525 if (!config) {
526 dev_err(&pdev->dev,
527 "failed to allocate musb hdrc config\n");
528 goto err2;
529 }
530
531 of_property_read_u32(np, "num-eps", (u32 *)&config->num_eps);
532 of_property_read_u32(np, "ram-bits", (u32 *)&config->ram_bits);
533 sprintf(res_name, "port%d-mode", id);
534 of_property_read_u32(np, res_name, (u32 *)&pdata->mode);
535 of_property_read_u32(np, "power", (u32 *)&pdata->power);
536 config->multipoint = of_property_read_bool(np, "multipoint");
537
538 pdata->config = config;
539 }
540
541 pdata->platform_ops = &dsps_ops;
542
509 ret = platform_device_add_data(musb, pdata, sizeof(*pdata)); 543 ret = platform_device_add_data(musb, pdata, sizeof(*pdata));
510 if (ret) { 544 if (ret) {
511 dev_err(dev, "failed to add platform_data\n"); 545 dev_err(dev, "failed to add platform_data\n");
512 goto err1; 546 goto err2;
513 } 547 }
514 548
515 ret = platform_device_add(musb); 549 ret = platform_device_add(musb);
516 if (ret) { 550 if (ret) {
517 dev_err(dev, "failed to register musb device\n"); 551 dev_err(dev, "failed to register musb device\n");
518 goto err1; 552 goto err2;
519 } 553 }
520 554
521 return 0; 555 return 0;
522 556
523err1: 557err2:
524 platform_device_put(musb); 558 platform_device_put(musb);
559err1:
560 musb_put_id(dev, musbid);
525err0: 561err0:
526 return ret; 562 return ret;
527} 563}
528 564
529static void __devexit dsps_delete_musb_pdev(struct dsps_glue *glue) 565static void dsps_delete_musb_pdev(struct dsps_glue *glue, u8 id)
530{ 566{
531 platform_device_del(glue->musb); 567 musb_put_id(glue->dev, glue->musb[id]->id);
532 platform_device_put(glue->musb); 568 platform_device_del(glue->musb[id]);
569 platform_device_put(glue->musb[id]);
533} 570}
534 571
535static int __devinit dsps_probe(struct platform_device *pdev) 572static int __devinit dsps_probe(struct platform_device *pdev)
536{ 573{
537 const struct platform_device_id *id = platform_get_device_id(pdev); 574 struct device_node *np = pdev->dev.of_node;
538 const struct dsps_musb_wrapper *wrp = 575 const struct of_device_id *match;
539 (struct dsps_musb_wrapper *)id->driver_data; 576 const struct dsps_musb_wrapper *wrp;
540 struct dsps_glue *glue; 577 struct dsps_glue *glue;
541 struct resource *iomem; 578 struct resource *iomem;
542 int ret; 579 int ret, i;
580
581 match = of_match_node(musb_dsps_of_match, np);
582 if (!match) {
583 dev_err(&pdev->dev, "fail to get matching of_match struct\n");
584 ret = -EINVAL;
585 goto err0;
586 }
587 wrp = match->data;
543 588
544 /* allocate glue */ 589 /* allocate glue */
545 glue = kzalloc(sizeof(*glue), GFP_KERNEL); 590 glue = kzalloc(sizeof(*glue), GFP_KERNEL);
@@ -576,11 +621,16 @@ static int __devinit dsps_probe(struct platform_device *pdev)
576 goto err2; 621 goto err2;
577 } 622 }
578 623
579 /* create the child platform device for first instances of musb */ 624 /* create the child platform device for all instances of musb */
580 ret = dsps_create_musb_pdev(glue, 0); 625 for (i = 0; i < wrp->instances ; i++) {
581 if (ret != 0) { 626 ret = dsps_create_musb_pdev(glue, i);
582 dev_err(&pdev->dev, "failed to create child pdev\n"); 627 if (ret != 0) {
583 goto err3; 628 dev_err(&pdev->dev, "failed to create child pdev\n");
629 /* release resources of previously created instances */
630 for (i--; i >= 0 ; i--)
631 dsps_delete_musb_pdev(glue, i);
632 goto err3;
633 }
584 } 634 }
585 635
586 return 0; 636 return 0;
@@ -598,9 +648,12 @@ err0:
598static int __devexit dsps_remove(struct platform_device *pdev) 648static int __devexit dsps_remove(struct platform_device *pdev)
599{ 649{
600 struct dsps_glue *glue = platform_get_drvdata(pdev); 650 struct dsps_glue *glue = platform_get_drvdata(pdev);
651 const struct dsps_musb_wrapper *wrp = glue->wrp;
652 int i;
601 653
602 /* delete the child platform device */ 654 /* delete the child platform device */
603 dsps_delete_musb_pdev(glue); 655 for (i = 0; i < wrp->instances ; i++)
656 dsps_delete_musb_pdev(glue, i);
604 657
605 /* disable usbss clocks */ 658 /* disable usbss clocks */
606 pm_runtime_put(&pdev->dev); 659 pm_runtime_put(&pdev->dev);
@@ -666,6 +719,7 @@ static const struct dsps_musb_wrapper ti81xx_driver_data __devinitconst = {
666 .rxep_bitmap = (0xfffe << 16), 719 .rxep_bitmap = (0xfffe << 16),
667 .musb_core_offset = 0x400, 720 .musb_core_offset = 0x400,
668 .poll_seconds = 2, 721 .poll_seconds = 2,
722 .instances = 2,
669}; 723};
670 724
671static const struct platform_device_id musb_dsps_id_table[] __devinitconst = { 725static const struct platform_device_id musb_dsps_id_table[] __devinitconst = {
@@ -677,13 +731,14 @@ static const struct platform_device_id musb_dsps_id_table[] __devinitconst = {
677}; 731};
678MODULE_DEVICE_TABLE(platform, musb_dsps_id_table); 732MODULE_DEVICE_TABLE(platform, musb_dsps_id_table);
679 733
734#ifdef CONFIG_OF
680static const struct of_device_id musb_dsps_of_match[] __devinitconst = { 735static const struct of_device_id musb_dsps_of_match[] __devinitconst = {
681 { .compatible = "musb-ti81xx", }, 736 { .compatible = "ti,musb-am33xx",
682 { .compatible = "ti,ti81xx-musb", }, 737 .data = (void *) &ti81xx_driver_data, },
683 { .compatible = "ti,am335x-musb", },
684 { }, 738 { },
685}; 739};
686MODULE_DEVICE_TABLE(of, musb_dsps_of_match); 740MODULE_DEVICE_TABLE(of, musb_dsps_of_match);
741#endif
687 742
688static struct platform_driver dsps_usbss_driver = { 743static struct platform_driver dsps_usbss_driver = {
689 .probe = dsps_probe, 744 .probe = dsps_probe,
@@ -691,7 +746,7 @@ static struct platform_driver dsps_usbss_driver = {
691 .driver = { 746 .driver = {
692 .name = "musb-dsps", 747 .name = "musb-dsps",
693 .pm = &dsps_pm_ops, 748 .pm = &dsps_pm_ops,
694 .of_match_table = musb_dsps_of_match, 749 .of_match_table = of_match_ptr(musb_dsps_of_match),
695 }, 750 },
696 .id_table = musb_dsps_id_table, 751 .id_table = musb_dsps_id_table,
697}; 752};
diff --git a/drivers/usb/musb/musb_gadget.c b/drivers/usb/musb/musb_gadget.c
index f7194cf65aba..d0b87e7b4abf 100644
--- a/drivers/usb/musb/musb_gadget.c
+++ b/drivers/usb/musb/musb_gadget.c
@@ -373,7 +373,7 @@ static void txstate(struct musb *musb, struct musb_request *req)
373 request_size = min_t(size_t, request->length - request->actual, 373 request_size = min_t(size_t, request->length - request->actual,
374 musb_ep->dma->max_len); 374 musb_ep->dma->max_len);
375 375
376 use_dma = (request->dma != DMA_ADDR_INVALID); 376 use_dma = (request->dma != DMA_ADDR_INVALID && request_size);
377 377
378 /* MUSB_TXCSR_P_ISO is still set correctly */ 378 /* MUSB_TXCSR_P_ISO is still set correctly */
379 379
@@ -644,8 +644,8 @@ static void rxstate(struct musb *musb, struct musb_request *req)
644 struct usb_request *request = &req->request; 644 struct usb_request *request = &req->request;
645 struct musb_ep *musb_ep; 645 struct musb_ep *musb_ep;
646 void __iomem *epio = musb->endpoints[epnum].regs; 646 void __iomem *epio = musb->endpoints[epnum].regs;
647 unsigned fifo_count = 0; 647 unsigned len = 0;
648 u16 len; 648 u16 fifo_count;
649 u16 csr = musb_readw(epio, MUSB_RXCSR); 649 u16 csr = musb_readw(epio, MUSB_RXCSR);
650 struct musb_hw_ep *hw_ep = &musb->endpoints[epnum]; 650 struct musb_hw_ep *hw_ep = &musb->endpoints[epnum];
651 u8 use_mode_1; 651 u8 use_mode_1;
@@ -655,7 +655,7 @@ static void rxstate(struct musb *musb, struct musb_request *req)
655 else 655 else
656 musb_ep = &hw_ep->ep_out; 656 musb_ep = &hw_ep->ep_out;
657 657
658 len = musb_ep->packet_sz; 658 fifo_count = musb_ep->packet_sz;
659 659
660 /* Check if EP is disabled */ 660 /* Check if EP is disabled */
661 if (!musb_ep->desc) { 661 if (!musb_ep->desc) {
@@ -704,15 +704,14 @@ static void rxstate(struct musb *musb, struct musb_request *req)
704 } 704 }
705 705
706 if (csr & MUSB_RXCSR_RXPKTRDY) { 706 if (csr & MUSB_RXCSR_RXPKTRDY) {
707 len = musb_readw(epio, MUSB_RXCOUNT); 707 fifo_count = musb_readw(epio, MUSB_RXCOUNT);
708 708
709 /* 709 /*
710 * Enable Mode 1 on RX transfers only when short_not_ok flag 710 * use mode 1 only if we expect data of at least ep packet_sz
711 * is set. Currently short_not_ok flag is set only from 711 * and have not yet received a short packet
712 * file_storage and f_mass_storage drivers
713 */ 712 */
714 713 if ((request->length - request->actual >= musb_ep->packet_sz) &&
715 if (request->short_not_ok && len == musb_ep->packet_sz) 714 (fifo_count >= musb_ep->packet_sz))
716 use_mode_1 = 1; 715 use_mode_1 = 1;
717 else 716 else
718 use_mode_1 = 0; 717 use_mode_1 = 0;
@@ -723,31 +722,11 @@ static void rxstate(struct musb *musb, struct musb_request *req)
723 struct dma_controller *c; 722 struct dma_controller *c;
724 struct dma_channel *channel; 723 struct dma_channel *channel;
725 int use_dma = 0; 724 int use_dma = 0;
725 int transfer_size;
726 726
727 c = musb->dma_controller; 727 c = musb->dma_controller;
728 channel = musb_ep->dma; 728 channel = musb_ep->dma;
729 729
730 /* We use DMA Req mode 0 in rx_csr, and DMA controller operates in
731 * mode 0 only. So we do not get endpoint interrupts due to DMA
732 * completion. We only get interrupts from DMA controller.
733 *
734 * We could operate in DMA mode 1 if we knew the size of the tranfer
735 * in advance. For mass storage class, request->length = what the host
736 * sends, so that'd work. But for pretty much everything else,
737 * request->length is routinely more than what the host sends. For
738 * most these gadgets, end of is signified either by a short packet,
739 * or filling the last byte of the buffer. (Sending extra data in
740 * that last pckate should trigger an overflow fault.) But in mode 1,
741 * we don't get DMA completion interrupt for short packets.
742 *
743 * Theoretically, we could enable DMAReq irq (MUSB_RXCSR_DMAMODE = 1),
744 * to get endpoint interrupt on every DMA req, but that didn't seem
745 * to work reliably.
746 *
747 * REVISIT an updated g_file_storage can set req->short_not_ok, which
748 * then becomes usable as a runtime "use mode 1" hint...
749 */
750
751 /* Experimental: Mode1 works with mass storage use cases */ 730 /* Experimental: Mode1 works with mass storage use cases */
752 if (use_mode_1) { 731 if (use_mode_1) {
753 csr |= MUSB_RXCSR_AUTOCLEAR; 732 csr |= MUSB_RXCSR_AUTOCLEAR;
@@ -764,35 +743,30 @@ static void rxstate(struct musb *musb, struct musb_request *req)
764 csr | MUSB_RXCSR_DMAMODE); 743 csr | MUSB_RXCSR_DMAMODE);
765 musb_writew(epio, MUSB_RXCSR, csr); 744 musb_writew(epio, MUSB_RXCSR, csr);
766 745
746 transfer_size = min(request->length - request->actual,
747 channel->max_len);
748 musb_ep->dma->desired_mode = 1;
749
767 } else { 750 } else {
768 if (!musb_ep->hb_mult && 751 if (!musb_ep->hb_mult &&
769 musb_ep->hw_ep->rx_double_buffered) 752 musb_ep->hw_ep->rx_double_buffered)
770 csr |= MUSB_RXCSR_AUTOCLEAR; 753 csr |= MUSB_RXCSR_AUTOCLEAR;
771 csr |= MUSB_RXCSR_DMAENAB; 754 csr |= MUSB_RXCSR_DMAENAB;
772 musb_writew(epio, MUSB_RXCSR, csr); 755 musb_writew(epio, MUSB_RXCSR, csr);
773 }
774 756
775 if (request->actual < request->length) { 757 transfer_size = min(request->length - request->actual,
776 int transfer_size = 0; 758 (unsigned)fifo_count);
777 if (use_mode_1) { 759 musb_ep->dma->desired_mode = 0;
778 transfer_size = min(request->length - request->actual,
779 channel->max_len);
780 musb_ep->dma->desired_mode = 1;
781 } else {
782 transfer_size = min(request->length - request->actual,
783 (unsigned)len);
784 musb_ep->dma->desired_mode = 0;
785 }
786
787 use_dma = c->channel_program(
788 channel,
789 musb_ep->packet_sz,
790 channel->desired_mode,
791 request->dma
792 + request->actual,
793 transfer_size);
794 } 760 }
795 761
762 use_dma = c->channel_program(
763 channel,
764 musb_ep->packet_sz,
765 channel->desired_mode,
766 request->dma
767 + request->actual,
768 transfer_size);
769
796 if (use_dma) 770 if (use_dma)
797 return; 771 return;
798 } 772 }
@@ -808,8 +782,8 @@ static void rxstate(struct musb *musb, struct musb_request *req)
808 channel = musb_ep->dma; 782 channel = musb_ep->dma;
809 783
810 /* In case first packet is short */ 784 /* In case first packet is short */
811 if (len < musb_ep->packet_sz) 785 if (fifo_count < musb_ep->packet_sz)
812 transfer_size = len; 786 transfer_size = fifo_count;
813 else if (request->short_not_ok) 787 else if (request->short_not_ok)
814 transfer_size = min(request->length - 788 transfer_size = min(request->length -
815 request->actual, 789 request->actual,
@@ -817,7 +791,7 @@ static void rxstate(struct musb *musb, struct musb_request *req)
817 else 791 else
818 transfer_size = min(request->length - 792 transfer_size = min(request->length -
819 request->actual, 793 request->actual,
820 (unsigned)len); 794 (unsigned)fifo_count);
821 795
822 csr &= ~MUSB_RXCSR_DMAMODE; 796 csr &= ~MUSB_RXCSR_DMAMODE;
823 csr |= (MUSB_RXCSR_DMAENAB | 797 csr |= (MUSB_RXCSR_DMAENAB |
@@ -845,10 +819,10 @@ static void rxstate(struct musb *musb, struct musb_request *req)
845 } 819 }
846#endif /* Mentor's DMA */ 820#endif /* Mentor's DMA */
847 821
848 fifo_count = request->length - request->actual; 822 len = request->length - request->actual;
849 dev_dbg(musb->controller, "%s OUT/RX pio fifo %d/%d, maxpacket %d\n", 823 dev_dbg(musb->controller, "%s OUT/RX pio fifo %d/%d, maxpacket %d\n",
850 musb_ep->end_point.name, 824 musb_ep->end_point.name,
851 len, fifo_count, 825 fifo_count, len,
852 musb_ep->packet_sz); 826 musb_ep->packet_sz);
853 827
854 fifo_count = min_t(unsigned, len, fifo_count); 828 fifo_count = min_t(unsigned, len, fifo_count);
@@ -901,7 +875,8 @@ static void rxstate(struct musb *musb, struct musb_request *req)
901 } 875 }
902 876
903 /* reach the end or short packet detected */ 877 /* reach the end or short packet detected */
904 if (request->actual == request->length || len < musb_ep->packet_sz) 878 if (request->actual == request->length ||
879 fifo_count < musb_ep->packet_sz)
905 musb_g_giveback(musb_ep, request, 0); 880 musb_g_giveback(musb_ep, request, 0);
906} 881}
907 882
@@ -1885,8 +1860,7 @@ int __devinit musb_gadget_setup(struct musb *musb)
1885 musb->g.dev.release = musb_gadget_release; 1860 musb->g.dev.release = musb_gadget_release;
1886 musb->g.name = musb_driver_name; 1861 musb->g.name = musb_driver_name;
1887 1862
1888 if (is_otg_enabled(musb)) 1863 musb->g.is_otg = 1;
1889 musb->g.is_otg = 1;
1890 1864
1891 musb_g_init_endpoints(musb); 1865 musb_g_init_endpoints(musb);
1892 1866
@@ -1932,11 +1906,14 @@ static int musb_gadget_start(struct usb_gadget *g,
1932{ 1906{
1933 struct musb *musb = gadget_to_musb(g); 1907 struct musb *musb = gadget_to_musb(g);
1934 struct usb_otg *otg = musb->xceiv->otg; 1908 struct usb_otg *otg = musb->xceiv->otg;
1909 struct usb_hcd *hcd = musb_to_hcd(musb);
1935 unsigned long flags; 1910 unsigned long flags;
1936 int retval = -EINVAL; 1911 int retval = 0;
1937 1912
1938 if (driver->max_speed < USB_SPEED_HIGH) 1913 if (driver->max_speed < USB_SPEED_HIGH) {
1939 goto err0; 1914 retval = -EINVAL;
1915 goto err;
1916 }
1940 1917
1941 pm_runtime_get_sync(musb->controller); 1918 pm_runtime_get_sync(musb->controller);
1942 1919
@@ -1950,49 +1927,30 @@ static int musb_gadget_start(struct usb_gadget *g,
1950 1927
1951 otg_set_peripheral(otg, &musb->g); 1928 otg_set_peripheral(otg, &musb->g);
1952 musb->xceiv->state = OTG_STATE_B_IDLE; 1929 musb->xceiv->state = OTG_STATE_B_IDLE;
1953
1954 /*
1955 * FIXME this ignores the softconnect flag. Drivers are
1956 * allowed hold the peripheral inactive until for example
1957 * userspace hooks up printer hardware or DSP codecs, so
1958 * hosts only see fully functional devices.
1959 */
1960
1961 if (!is_otg_enabled(musb))
1962 musb_start(musb);
1963
1964 spin_unlock_irqrestore(&musb->lock, flags); 1930 spin_unlock_irqrestore(&musb->lock, flags);
1965 1931
1966 if (is_otg_enabled(musb)) { 1932 /* REVISIT: funcall to other code, which also
1967 struct usb_hcd *hcd = musb_to_hcd(musb); 1933 * handles power budgeting ... this way also
1968 1934 * ensures HdrcStart is indirectly called.
1969 dev_dbg(musb->controller, "OTG startup...\n"); 1935 */
1936 retval = usb_add_hcd(hcd, 0, 0);
1937 if (retval < 0) {
1938 dev_dbg(musb->controller, "add_hcd failed, %d\n", retval);
1939 goto err;
1940 }
1970 1941
1971 /* REVISIT: funcall to other code, which also 1942 if ((musb->xceiv->last_event == USB_EVENT_ID)
1972 * handles power budgeting ... this way also 1943 && otg->set_vbus)
1973 * ensures HdrcStart is indirectly called. 1944 otg_set_vbus(otg, 1);
1974 */
1975 retval = usb_add_hcd(musb_to_hcd(musb), 0, 0);
1976 if (retval < 0) {
1977 dev_dbg(musb->controller, "add_hcd failed, %d\n", retval);
1978 goto err2;
1979 }
1980 1945
1981 if ((musb->xceiv->last_event == USB_EVENT_ID) 1946 hcd->self.uses_pio_for_control = 1;
1982 && otg->set_vbus)
1983 otg_set_vbus(otg, 1);
1984 1947
1985 hcd->self.uses_pio_for_control = 1;
1986 }
1987 if (musb->xceiv->last_event == USB_EVENT_NONE) 1948 if (musb->xceiv->last_event == USB_EVENT_NONE)
1988 pm_runtime_put(musb->controller); 1949 pm_runtime_put(musb->controller);
1989 1950
1990 return 0; 1951 return 0;
1991 1952
1992err2: 1953err:
1993 if (!is_otg_enabled(musb))
1994 musb_stop(musb);
1995err0:
1996 return retval; 1954 return retval;
1997} 1955}
1998 1956
@@ -2070,16 +2028,12 @@ static int musb_gadget_stop(struct usb_gadget *g,
2070 musb_platform_try_idle(musb, 0); 2028 musb_platform_try_idle(musb, 0);
2071 spin_unlock_irqrestore(&musb->lock, flags); 2029 spin_unlock_irqrestore(&musb->lock, flags);
2072 2030
2073 if (is_otg_enabled(musb)) { 2031 usb_remove_hcd(musb_to_hcd(musb));
2074 usb_remove_hcd(musb_to_hcd(musb)); 2032 /*
2075 /* FIXME we need to be able to register another 2033 * FIXME we need to be able to register another
2076 * gadget driver here and have everything work; 2034 * gadget driver here and have everything work;
2077 * that currently misbehaves. 2035 * that currently misbehaves.
2078 */ 2036 */
2079 }
2080
2081 if (!is_otg_enabled(musb))
2082 musb_stop(musb);
2083 2037
2084 pm_runtime_put(musb->controller); 2038 pm_runtime_put(musb->controller);
2085 2039
@@ -2241,13 +2195,11 @@ __acquires(musb->lock)
2241 if (devctl & MUSB_DEVCTL_BDEVICE) { 2195 if (devctl & MUSB_DEVCTL_BDEVICE) {
2242 musb->xceiv->state = OTG_STATE_B_PERIPHERAL; 2196 musb->xceiv->state = OTG_STATE_B_PERIPHERAL;
2243 musb->g.is_a_peripheral = 0; 2197 musb->g.is_a_peripheral = 0;
2244 } else if (is_otg_enabled(musb)) { 2198 } else {
2245 musb->xceiv->state = OTG_STATE_A_PERIPHERAL; 2199 musb->xceiv->state = OTG_STATE_A_PERIPHERAL;
2246 musb->g.is_a_peripheral = 1; 2200 musb->g.is_a_peripheral = 1;
2247 } else 2201 }
2248 WARN_ON(1);
2249 2202
2250 /* start with default limits on VBUS power draw */ 2203 /* start with default limits on VBUS power draw */
2251 (void) musb_gadget_vbus_draw(&musb->g, 2204 (void) musb_gadget_vbus_draw(&musb->g, 8);
2252 is_otg_enabled(musb) ? 8 : 100);
2253} 2205}
diff --git a/drivers/usb/musb/musb_host.c b/drivers/usb/musb/musb_host.c
index 4bb717d0bd41..d385e8a8187d 100644
--- a/drivers/usb/musb/musb_host.c
+++ b/drivers/usb/musb/musb_host.c
@@ -693,6 +693,8 @@ static void musb_ep_program(struct musb *musb, u8 epnum,
693 void __iomem *epio = hw_ep->regs; 693 void __iomem *epio = hw_ep->regs;
694 struct musb_qh *qh = musb_ep_get_qh(hw_ep, !is_out); 694 struct musb_qh *qh = musb_ep_get_qh(hw_ep, !is_out);
695 u16 packet_sz = qh->maxpacket; 695 u16 packet_sz = qh->maxpacket;
696 u8 use_dma = 1;
697 u16 csr;
696 698
697 dev_dbg(musb->controller, "%s hw%d urb %p spd%d dev%d ep%d%s " 699 dev_dbg(musb->controller, "%s hw%d urb %p spd%d dev%d ep%d%s "
698 "h_addr%02x h_port%02x bytes %d\n", 700 "h_addr%02x h_port%02x bytes %d\n",
@@ -704,9 +706,17 @@ static void musb_ep_program(struct musb *musb, u8 epnum,
704 706
705 musb_ep_select(mbase, epnum); 707 musb_ep_select(mbase, epnum);
706 708
709 if (is_out && !len) {
710 use_dma = 0;
711 csr = musb_readw(epio, MUSB_TXCSR);
712 csr &= ~MUSB_TXCSR_DMAENAB;
713 musb_writew(epio, MUSB_TXCSR, csr);
714 hw_ep->tx_channel = NULL;
715 }
716
707 /* candidate for DMA? */ 717 /* candidate for DMA? */
708 dma_controller = musb->dma_controller; 718 dma_controller = musb->dma_controller;
709 if (is_dma_capable() && epnum && dma_controller) { 719 if (use_dma && is_dma_capable() && epnum && dma_controller) {
710 dma_channel = is_out ? hw_ep->tx_channel : hw_ep->rx_channel; 720 dma_channel = is_out ? hw_ep->tx_channel : hw_ep->rx_channel;
711 if (!dma_channel) { 721 if (!dma_channel) {
712 dma_channel = dma_controller->channel_alloc( 722 dma_channel = dma_controller->channel_alloc(
@@ -813,9 +823,28 @@ static void musb_ep_program(struct musb *musb, u8 epnum,
813 if (load_count) { 823 if (load_count) {
814 /* PIO to load FIFO */ 824 /* PIO to load FIFO */
815 qh->segsize = load_count; 825 qh->segsize = load_count;
816 musb_write_fifo(hw_ep, load_count, buf); 826 if (!buf) {
827 sg_miter_start(&qh->sg_miter, urb->sg, 1,
828 SG_MITER_ATOMIC
829 | SG_MITER_FROM_SG);
830 if (!sg_miter_next(&qh->sg_miter)) {
831 dev_err(musb->controller,
832 "error: sg"
833 "list empty\n");
834 sg_miter_stop(&qh->sg_miter);
835 goto finish;
836 }
837 buf = qh->sg_miter.addr + urb->sg->offset +
838 urb->actual_length;
839 load_count = min_t(u32, load_count,
840 qh->sg_miter.length);
841 musb_write_fifo(hw_ep, load_count, buf);
842 qh->sg_miter.consumed = load_count;
843 sg_miter_stop(&qh->sg_miter);
844 } else
845 musb_write_fifo(hw_ep, load_count, buf);
817 } 846 }
818 847finish:
819 /* re-enable interrupt */ 848 /* re-enable interrupt */
820 musb_writew(mbase, MUSB_INTRTXE, int_txe); 849 musb_writew(mbase, MUSB_INTRTXE, int_txe);
821 850
@@ -882,6 +911,73 @@ static void musb_ep_program(struct musb *musb, u8 epnum,
882 } 911 }
883} 912}
884 913
914/* Schedule next QH from musb->in_bulk/out_bulk and move the current qh to
915 * the end; avoids starvation for other endpoints.
916 */
917static void musb_bulk_nak_timeout(struct musb *musb, struct musb_hw_ep *ep,
918 int is_in)
919{
920 struct dma_channel *dma;
921 struct urb *urb;
922 void __iomem *mbase = musb->mregs;
923 void __iomem *epio = ep->regs;
924 struct musb_qh *cur_qh, *next_qh;
925 u16 rx_csr, tx_csr;
926
927 musb_ep_select(mbase, ep->epnum);
928 if (is_in) {
929 dma = is_dma_capable() ? ep->rx_channel : NULL;
930
931 /* clear nak timeout bit */
932 rx_csr = musb_readw(epio, MUSB_RXCSR);
933 rx_csr |= MUSB_RXCSR_H_WZC_BITS;
934 rx_csr &= ~MUSB_RXCSR_DATAERROR;
935 musb_writew(epio, MUSB_RXCSR, rx_csr);
936
937 cur_qh = first_qh(&musb->in_bulk);
938 } else {
939 dma = is_dma_capable() ? ep->tx_channel : NULL;
940
941 /* clear nak timeout bit */
942 tx_csr = musb_readw(epio, MUSB_TXCSR);
943 tx_csr |= MUSB_TXCSR_H_WZC_BITS;
944 tx_csr &= ~MUSB_TXCSR_H_NAKTIMEOUT;
945 musb_writew(epio, MUSB_TXCSR, tx_csr);
946
947 cur_qh = first_qh(&musb->out_bulk);
948 }
949 if (cur_qh) {
950 urb = next_urb(cur_qh);
951 if (dma_channel_status(dma) == MUSB_DMA_STATUS_BUSY) {
952 dma->status = MUSB_DMA_STATUS_CORE_ABORT;
953 musb->dma_controller->channel_abort(dma);
954 urb->actual_length += dma->actual_len;
955 dma->actual_len = 0L;
956 }
957 musb_save_toggle(cur_qh, is_in, urb);
958
959 if (is_in) {
960 /* move cur_qh to end of queue */
961 list_move_tail(&cur_qh->ring, &musb->in_bulk);
962
963 /* get the next qh from musb->in_bulk */
964 next_qh = first_qh(&musb->in_bulk);
965
966 /* set rx_reinit and schedule the next qh */
967 ep->rx_reinit = 1;
968 } else {
969 /* move cur_qh to end of queue */
970 list_move_tail(&cur_qh->ring, &musb->out_bulk);
971
972 /* get the next qh from musb->out_bulk */
973 next_qh = first_qh(&musb->out_bulk);
974
975 /* set tx_reinit and schedule the next qh */
976 ep->tx_reinit = 1;
977 }
978 musb_start_urb(musb, is_in, next_qh);
979 }
980}
885 981
886/* 982/*
887 * Service the default endpoint (ep0) as host. 983 * Service the default endpoint (ep0) as host.
@@ -1116,6 +1212,7 @@ void musb_host_tx(struct musb *musb, u8 epnum)
1116 void __iomem *mbase = musb->mregs; 1212 void __iomem *mbase = musb->mregs;
1117 struct dma_channel *dma; 1213 struct dma_channel *dma;
1118 bool transfer_pending = false; 1214 bool transfer_pending = false;
1215 static bool use_sg;
1119 1216
1120 musb_ep_select(mbase, epnum); 1217 musb_ep_select(mbase, epnum);
1121 tx_csr = musb_readw(epio, MUSB_TXCSR); 1218 tx_csr = musb_readw(epio, MUSB_TXCSR);
@@ -1146,23 +1243,31 @@ void musb_host_tx(struct musb *musb, u8 epnum)
1146 status = -ETIMEDOUT; 1243 status = -ETIMEDOUT;
1147 1244
1148 } else if (tx_csr & MUSB_TXCSR_H_NAKTIMEOUT) { 1245 } else if (tx_csr & MUSB_TXCSR_H_NAKTIMEOUT) {
1149 dev_dbg(musb->controller, "TX end=%d device not responding\n", epnum); 1246 if (USB_ENDPOINT_XFER_BULK == qh->type && qh->mux == 1
1150 1247 && !list_is_singular(&musb->out_bulk)) {
1151 /* NOTE: this code path would be a good place to PAUSE a 1248 dev_dbg(musb->controller,
1152 * transfer, if there's some other (nonperiodic) tx urb 1249 "NAK timeout on TX%d ep\n", epnum);
1153 * that could use this fifo. (dma complicates it...) 1250 musb_bulk_nak_timeout(musb, hw_ep, 0);
1154 * That's already done for bulk RX transfers. 1251 } else {
1155 * 1252 dev_dbg(musb->controller,
1156 * if (bulk && qh->ring.next != &musb->out_bulk), then 1253 "TX end=%d device not responding\n", epnum);
1157 * we have a candidate... NAKing is *NOT* an error 1254 /* NOTE: this code path would be a good place to PAUSE a
1158 */ 1255 * transfer, if there's some other (nonperiodic) tx urb
1159 musb_ep_select(mbase, epnum); 1256 * that could use this fifo. (dma complicates it...)
1160 musb_writew(epio, MUSB_TXCSR, 1257 * That's already done for bulk RX transfers.
1161 MUSB_TXCSR_H_WZC_BITS 1258 *
1162 | MUSB_TXCSR_TXPKTRDY); 1259 * if (bulk && qh->ring.next != &musb->out_bulk), then
1163 return; 1260 * we have a candidate... NAKing is *NOT* an error
1261 */
1262 musb_ep_select(mbase, epnum);
1263 musb_writew(epio, MUSB_TXCSR,
1264 MUSB_TXCSR_H_WZC_BITS
1265 | MUSB_TXCSR_TXPKTRDY);
1266 }
1267 return;
1164 } 1268 }
1165 1269
1270done:
1166 if (status) { 1271 if (status) {
1167 if (dma_channel_status(dma) == MUSB_DMA_STATUS_BUSY) { 1272 if (dma_channel_status(dma) == MUSB_DMA_STATUS_BUSY) {
1168 dma->status = MUSB_DMA_STATUS_CORE_ABORT; 1273 dma->status = MUSB_DMA_STATUS_CORE_ABORT;
@@ -1332,9 +1437,38 @@ void musb_host_tx(struct musb *musb, u8 epnum)
1332 length = qh->maxpacket; 1437 length = qh->maxpacket;
1333 /* Unmap the buffer so that CPU can use it */ 1438 /* Unmap the buffer so that CPU can use it */
1334 usb_hcd_unmap_urb_for_dma(musb_to_hcd(musb), urb); 1439 usb_hcd_unmap_urb_for_dma(musb_to_hcd(musb), urb);
1335 musb_write_fifo(hw_ep, length, urb->transfer_buffer + offset); 1440
1441 /*
1442 * We need to map sg if the transfer_buffer is
1443 * NULL.
1444 */
1445 if (!urb->transfer_buffer)
1446 use_sg = true;
1447
1448 if (use_sg) {
1449 /* sg_miter_start is already done in musb_ep_program */
1450 if (!sg_miter_next(&qh->sg_miter)) {
1451 dev_err(musb->controller, "error: sg list empty\n");
1452 sg_miter_stop(&qh->sg_miter);
1453 status = -EINVAL;
1454 goto done;
1455 }
1456 urb->transfer_buffer = qh->sg_miter.addr;
1457 length = min_t(u32, length, qh->sg_miter.length);
1458 musb_write_fifo(hw_ep, length, urb->transfer_buffer);
1459 qh->sg_miter.consumed = length;
1460 sg_miter_stop(&qh->sg_miter);
1461 } else {
1462 musb_write_fifo(hw_ep, length, urb->transfer_buffer + offset);
1463 }
1464
1336 qh->segsize = length; 1465 qh->segsize = length;
1337 1466
1467 if (use_sg) {
1468 if (offset + length >= urb->transfer_buffer_length)
1469 use_sg = false;
1470 }
1471
1338 musb_ep_select(mbase, epnum); 1472 musb_ep_select(mbase, epnum);
1339 musb_writew(epio, MUSB_TXCSR, 1473 musb_writew(epio, MUSB_TXCSR,
1340 MUSB_TXCSR_H_WZC_BITS | MUSB_TXCSR_TXPKTRDY); 1474 MUSB_TXCSR_H_WZC_BITS | MUSB_TXCSR_TXPKTRDY);
@@ -1380,50 +1514,6 @@ void musb_host_tx(struct musb *musb, u8 epnum)
1380 1514
1381#endif 1515#endif
1382 1516
1383/* Schedule next QH from musb->in_bulk and move the current qh to
1384 * the end; avoids starvation for other endpoints.
1385 */
1386static void musb_bulk_rx_nak_timeout(struct musb *musb, struct musb_hw_ep *ep)
1387{
1388 struct dma_channel *dma;
1389 struct urb *urb;
1390 void __iomem *mbase = musb->mregs;
1391 void __iomem *epio = ep->regs;
1392 struct musb_qh *cur_qh, *next_qh;
1393 u16 rx_csr;
1394
1395 musb_ep_select(mbase, ep->epnum);
1396 dma = is_dma_capable() ? ep->rx_channel : NULL;
1397
1398 /* clear nak timeout bit */
1399 rx_csr = musb_readw(epio, MUSB_RXCSR);
1400 rx_csr |= MUSB_RXCSR_H_WZC_BITS;
1401 rx_csr &= ~MUSB_RXCSR_DATAERROR;
1402 musb_writew(epio, MUSB_RXCSR, rx_csr);
1403
1404 cur_qh = first_qh(&musb->in_bulk);
1405 if (cur_qh) {
1406 urb = next_urb(cur_qh);
1407 if (dma_channel_status(dma) == MUSB_DMA_STATUS_BUSY) {
1408 dma->status = MUSB_DMA_STATUS_CORE_ABORT;
1409 musb->dma_controller->channel_abort(dma);
1410 urb->actual_length += dma->actual_len;
1411 dma->actual_len = 0L;
1412 }
1413 musb_save_toggle(cur_qh, 1, urb);
1414
1415 /* move cur_qh to end of queue */
1416 list_move_tail(&cur_qh->ring, &musb->in_bulk);
1417
1418 /* get the next qh from musb->in_bulk */
1419 next_qh = first_qh(&musb->in_bulk);
1420
1421 /* set rx_reinit and schedule the next qh */
1422 ep->rx_reinit = 1;
1423 musb_start_urb(musb, 1, next_qh);
1424 }
1425}
1426
1427/* 1517/*
1428 * Service an RX interrupt for the given IN endpoint; docs cover bulk, iso, 1518 * Service an RX interrupt for the given IN endpoint; docs cover bulk, iso,
1429 * and high-bandwidth IN transfer cases. 1519 * and high-bandwidth IN transfer cases.
@@ -1442,6 +1532,8 @@ void musb_host_rx(struct musb *musb, u8 epnum)
1442 bool done = false; 1532 bool done = false;
1443 u32 status; 1533 u32 status;
1444 struct dma_channel *dma; 1534 struct dma_channel *dma;
1535 static bool use_sg;
1536 unsigned int sg_flags = SG_MITER_ATOMIC | SG_MITER_TO_SG;
1445 1537
1446 musb_ep_select(mbase, epnum); 1538 musb_ep_select(mbase, epnum);
1447 1539
@@ -1500,7 +1592,7 @@ void musb_host_rx(struct musb *musb, u8 epnum)
1500 if (usb_pipebulk(urb->pipe) 1592 if (usb_pipebulk(urb->pipe)
1501 && qh->mux == 1 1593 && qh->mux == 1
1502 && !list_is_singular(&musb->in_bulk)) { 1594 && !list_is_singular(&musb->in_bulk)) {
1503 musb_bulk_rx_nak_timeout(musb, hw_ep); 1595 musb_bulk_nak_timeout(musb, hw_ep, 1);
1504 return; 1596 return;
1505 } 1597 }
1506 musb_ep_select(mbase, epnum); 1598 musb_ep_select(mbase, epnum);
@@ -1756,10 +1848,43 @@ void musb_host_rx(struct musb *musb, u8 epnum)
1756#endif /* Mentor DMA */ 1848#endif /* Mentor DMA */
1757 1849
1758 if (!dma) { 1850 if (!dma) {
1851 unsigned int received_len;
1852
1759 /* Unmap the buffer so that CPU can use it */ 1853 /* Unmap the buffer so that CPU can use it */
1760 usb_hcd_unmap_urb_for_dma(musb_to_hcd(musb), urb); 1854 usb_hcd_unmap_urb_for_dma(musb_to_hcd(musb), urb);
1761 done = musb_host_packet_rx(musb, urb, 1855
1762 epnum, iso_err); 1856 /*
1857 * We need to map sg if the transfer_buffer is
1858 * NULL.
1859 */
1860 if (!urb->transfer_buffer) {
1861 use_sg = true;
1862 sg_miter_start(&qh->sg_miter, urb->sg, 1,
1863 sg_flags);
1864 }
1865
1866 if (use_sg) {
1867 if (!sg_miter_next(&qh->sg_miter)) {
1868 dev_err(musb->controller, "error: sg list empty\n");
1869 sg_miter_stop(&qh->sg_miter);
1870 status = -EINVAL;
1871 done = true;
1872 goto finish;
1873 }
1874 urb->transfer_buffer = qh->sg_miter.addr;
1875 received_len = urb->actual_length;
1876 qh->offset = 0x0;
1877 done = musb_host_packet_rx(musb, urb, epnum,
1878 iso_err);
1879 /* Calculate the number of bytes received */
1880 received_len = urb->actual_length -
1881 received_len;
1882 qh->sg_miter.consumed = received_len;
1883 sg_miter_stop(&qh->sg_miter);
1884 } else {
1885 done = musb_host_packet_rx(musb, urb,
1886 epnum, iso_err);
1887 }
1763 dev_dbg(musb->controller, "read %spacket\n", done ? "last " : ""); 1888 dev_dbg(musb->controller, "read %spacket\n", done ? "last " : "");
1764 } 1889 }
1765 } 1890 }
@@ -1768,6 +1893,9 @@ finish:
1768 urb->actual_length += xfer_len; 1893 urb->actual_length += xfer_len;
1769 qh->offset += xfer_len; 1894 qh->offset += xfer_len;
1770 if (done) { 1895 if (done) {
1896 if (use_sg)
1897 use_sg = false;
1898
1771 if (urb->status == -EINPROGRESS) 1899 if (urb->status == -EINPROGRESS)
1772 urb->status = status; 1900 urb->status = status;
1773 musb_advance_schedule(musb, urb, hw_ep, USB_DIR_IN); 1901 musb_advance_schedule(musb, urb, hw_ep, USB_DIR_IN);
@@ -1863,14 +1991,14 @@ static int musb_schedule(
1863 else 1991 else
1864 head = &musb->out_bulk; 1992 head = &musb->out_bulk;
1865 1993
1866 /* Enable bulk RX NAK timeout scheme when bulk requests are 1994 /* Enable bulk RX/TX NAK timeout scheme when bulk requests are
1867 * multiplexed. This scheme doen't work in high speed to full 1995 * multiplexed. This scheme doen't work in high speed to full
1868 * speed scenario as NAK interrupts are not coming from a 1996 * speed scenario as NAK interrupts are not coming from a
1869 * full speed device connected to a high speed device. 1997 * full speed device connected to a high speed device.
1870 * NAK timeout interval is 8 (128 uframe or 16ms) for HS and 1998 * NAK timeout interval is 8 (128 uframe or 16ms) for HS and
1871 * 4 (8 frame or 8ms) for FS device. 1999 * 4 (8 frame or 8ms) for FS device.
1872 */ 2000 */
1873 if (is_in && qh->dev) 2001 if (qh->dev)
1874 qh->intv_reg = 2002 qh->intv_reg =
1875 (USB_SPEED_HIGH == qh->dev->speed) ? 8 : 4; 2003 (USB_SPEED_HIGH == qh->dev->speed) ? 8 : 4;
1876 goto success; 2004 goto success;
diff --git a/drivers/usb/musb/musb_host.h b/drivers/usb/musb/musb_host.h
index 622d09fb9aba..5a9c8feec10c 100644
--- a/drivers/usb/musb/musb_host.h
+++ b/drivers/usb/musb/musb_host.h
@@ -35,6 +35,8 @@
35#ifndef _MUSB_HOST_H 35#ifndef _MUSB_HOST_H
36#define _MUSB_HOST_H 36#define _MUSB_HOST_H
37 37
38#include <linux/scatterlist.h>
39
38static inline struct usb_hcd *musb_to_hcd(struct musb *musb) 40static inline struct usb_hcd *musb_to_hcd(struct musb *musb)
39{ 41{
40 return container_of((void *) musb, struct usb_hcd, hcd_priv); 42 return container_of((void *) musb, struct usb_hcd, hcd_priv);
@@ -71,6 +73,7 @@ struct musb_qh {
71 u16 maxpacket; 73 u16 maxpacket;
72 u16 frame; /* for periodic schedule */ 74 u16 frame; /* for periodic schedule */
73 unsigned iso_idx; /* in urb->iso_frame_desc[] */ 75 unsigned iso_idx; /* in urb->iso_frame_desc[] */
76 struct sg_mapping_iter sg_miter; /* for highmem in PIO mode */
74}; 77};
75 78
76/* map from control or bulk queue head to the first qh on that ring */ 79/* map from control or bulk queue head to the first qh on that ring */
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/musbhsdma.c b/drivers/usb/musb/musbhsdma.c
index 57a608584e16..444b9ee06490 100644
--- a/drivers/usb/musb/musbhsdma.c
+++ b/drivers/usb/musb/musbhsdma.c
@@ -380,7 +380,7 @@ void dma_controller_destroy(struct dma_controller *c)
380 kfree(controller); 380 kfree(controller);
381} 381}
382 382
383struct dma_controller *__init 383struct dma_controller *__devinit
384dma_controller_create(struct musb *musb, void __iomem *base) 384dma_controller_create(struct musb *musb, void __iomem *base)
385{ 385{
386 struct musb_dma_controller *controller; 386 struct musb_dma_controller *controller;
diff --git a/drivers/usb/musb/omap2430.c b/drivers/usb/musb/omap2430.c
index 5fdb9da8dd56..a538fe17a966 100644
--- a/drivers/usb/musb/omap2430.c
+++ b/drivers/usb/musb/omap2430.c
@@ -30,10 +30,12 @@
30#include <linux/init.h> 30#include <linux/init.h>
31#include <linux/list.h> 31#include <linux/list.h>
32#include <linux/io.h> 32#include <linux/io.h>
33#include <linux/of.h>
33#include <linux/platform_device.h> 34#include <linux/platform_device.h>
34#include <linux/dma-mapping.h> 35#include <linux/dma-mapping.h>
35#include <linux/pm_runtime.h> 36#include <linux/pm_runtime.h>
36#include <linux/err.h> 37#include <linux/err.h>
38#include <linux/delay.h>
37#include <linux/usb/musb-omap.h> 39#include <linux/usb/musb-omap.h>
38 40
39#include "musb_core.h" 41#include "musb_core.h"
@@ -44,6 +46,7 @@ struct omap2430_glue {
44 struct platform_device *musb; 46 struct platform_device *musb;
45 enum omap_musb_vbus_id_status status; 47 enum omap_musb_vbus_id_status status;
46 struct work_struct omap_musb_mailbox_work; 48 struct work_struct omap_musb_mailbox_work;
49 u32 __iomem *control_otghs;
47}; 50};
48#define glue_to_musb(g) platform_get_drvdata(g->musb) 51#define glue_to_musb(g) platform_get_drvdata(g->musb)
49 52
@@ -51,6 +54,26 @@ struct omap2430_glue *_glue;
51 54
52static struct timer_list musb_idle_timer; 55static struct timer_list musb_idle_timer;
53 56
57/**
58 * omap4_usb_phy_mailbox - write to usb otg mailbox
59 * @glue: struct omap2430_glue *
60 * @val: the value to be written to the mailbox
61 *
62 * On detection of a device (ID pin is grounded), this API should be called
63 * to set AVALID, VBUSVALID and ID pin is grounded.
64 *
65 * When OMAP is connected to a host (OMAP in device mode), this API
66 * is called to set AVALID, VBUSVALID and ID pin in high impedance.
67 *
68 * XXX: This function will be removed once we have a seperate driver for
69 * control module
70 */
71static void omap4_usb_phy_mailbox(struct omap2430_glue *glue, u32 val)
72{
73 if (glue->control_otghs)
74 writel(val, glue->control_otghs);
75}
76
54static void musb_do_idle(unsigned long _musb) 77static void musb_do_idle(unsigned long _musb)
55{ 78{
56 struct musb *musb = (void *)_musb; 79 struct musb *musb = (void *)_musb;
@@ -140,7 +163,6 @@ static void omap2430_musb_set_vbus(struct musb *musb, int is_on)
140 struct usb_otg *otg = musb->xceiv->otg; 163 struct usb_otg *otg = musb->xceiv->otg;
141 u8 devctl; 164 u8 devctl;
142 unsigned long timeout = jiffies + msecs_to_jiffies(1000); 165 unsigned long timeout = jiffies + msecs_to_jiffies(1000);
143 int ret = 1;
144 /* HDRC controls CPEN, but beware current surges during device 166 /* HDRC controls CPEN, but beware current surges during device
145 * connect. They can trigger transient overcurrent conditions 167 * connect. They can trigger transient overcurrent conditions
146 * that must be ignored. 168 * that must be ignored.
@@ -150,6 +172,7 @@ static void omap2430_musb_set_vbus(struct musb *musb, int is_on)
150 172
151 if (is_on) { 173 if (is_on) {
152 if (musb->xceiv->state == OTG_STATE_A_IDLE) { 174 if (musb->xceiv->state == OTG_STATE_A_IDLE) {
175 int loops = 100;
153 /* start the session */ 176 /* start the session */
154 devctl |= MUSB_DEVCTL_SESSION; 177 devctl |= MUSB_DEVCTL_SESSION;
155 musb_writeb(musb->mregs, MUSB_DEVCTL, devctl); 178 musb_writeb(musb->mregs, MUSB_DEVCTL, devctl);
@@ -159,17 +182,18 @@ static void omap2430_musb_set_vbus(struct musb *musb, int is_on)
159 */ 182 */
160 while (musb_readb(musb->mregs, MUSB_DEVCTL) & 0x80) { 183 while (musb_readb(musb->mregs, MUSB_DEVCTL) & 0x80) {
161 184
185 mdelay(5);
162 cpu_relax(); 186 cpu_relax();
163 187
164 if (time_after(jiffies, timeout)) { 188 if (time_after(jiffies, timeout)
189 || loops-- <= 0) {
165 dev_err(musb->controller, 190 dev_err(musb->controller,
166 "configured as A device timeout"); 191 "configured as A device timeout");
167 ret = -EINVAL;
168 break; 192 break;
169 } 193 }
170 } 194 }
171 195
172 if (ret && otg->set_vbus) 196 if (otg->set_vbus)
173 otg_set_vbus(otg, 1); 197 otg_set_vbus(otg, 1);
174 } else { 198 } else {
175 musb->is_active = 1; 199 musb->is_active = 1;
@@ -245,6 +269,7 @@ EXPORT_SYMBOL_GPL(omap_musb_mailbox);
245 269
246static void omap_musb_set_mailbox(struct omap2430_glue *glue) 270static void omap_musb_set_mailbox(struct omap2430_glue *glue)
247{ 271{
272 u32 val;
248 struct musb *musb = glue_to_musb(glue); 273 struct musb *musb = glue_to_musb(glue);
249 struct device *dev = musb->controller; 274 struct device *dev = musb->controller;
250 struct musb_hdrc_platform_data *pdata = dev->platform_data; 275 struct musb_hdrc_platform_data *pdata = dev->platform_data;
@@ -258,9 +283,10 @@ static void omap_musb_set_mailbox(struct omap2430_glue *glue)
258 otg->default_a = true; 283 otg->default_a = true;
259 musb->xceiv->state = OTG_STATE_A_IDLE; 284 musb->xceiv->state = OTG_STATE_A_IDLE;
260 musb->xceiv->last_event = USB_EVENT_ID; 285 musb->xceiv->last_event = USB_EVENT_ID;
261 if (!is_otg_enabled(musb) || musb->gadget_driver) { 286 if (musb->gadget_driver) {
262 pm_runtime_get_sync(dev); 287 pm_runtime_get_sync(dev);
263 usb_phy_init(musb->xceiv); 288 val = AVALID | VBUSVALID;
289 omap4_usb_phy_mailbox(glue, val);
264 omap2430_musb_set_vbus(musb, 1); 290 omap2430_musb_set_vbus(musb, 1);
265 } 291 }
266 break; 292 break;
@@ -273,7 +299,8 @@ static void omap_musb_set_mailbox(struct omap2430_glue *glue)
273 musb->xceiv->last_event = USB_EVENT_VBUS; 299 musb->xceiv->last_event = USB_EVENT_VBUS;
274 if (musb->gadget_driver) 300 if (musb->gadget_driver)
275 pm_runtime_get_sync(dev); 301 pm_runtime_get_sync(dev);
276 usb_phy_init(musb->xceiv); 302 val = IDDIG | AVALID | VBUSVALID;
303 omap4_usb_phy_mailbox(glue, val);
277 break; 304 break;
278 305
279 case OMAP_MUSB_ID_FLOAT: 306 case OMAP_MUSB_ID_FLOAT:
@@ -281,17 +308,17 @@ static void omap_musb_set_mailbox(struct omap2430_glue *glue)
281 dev_dbg(dev, "VBUS Disconnect\n"); 308 dev_dbg(dev, "VBUS Disconnect\n");
282 309
283 musb->xceiv->last_event = USB_EVENT_NONE; 310 musb->xceiv->last_event = USB_EVENT_NONE;
284 if (is_otg_enabled(musb) || is_peripheral_enabled(musb)) 311 if (musb->gadget_driver) {
285 if (musb->gadget_driver) { 312 pm_runtime_mark_last_busy(dev);
286 pm_runtime_mark_last_busy(dev); 313 pm_runtime_put_autosuspend(dev);
287 pm_runtime_put_autosuspend(dev); 314 }
288 }
289 315
290 if (data->interface_type == MUSB_INTERFACE_UTMI) { 316 if (data->interface_type == MUSB_INTERFACE_UTMI) {
291 if (musb->xceiv->otg->set_vbus) 317 if (musb->xceiv->otg->set_vbus)
292 otg_set_vbus(musb->xceiv->otg, 0); 318 otg_set_vbus(musb->xceiv->otg, 0);
293 } 319 }
294 usb_phy_shutdown(musb->xceiv); 320 val = SESSEND | IDDIG;
321 omap4_usb_phy_mailbox(glue, val);
295 break; 322 break;
296 default: 323 default:
297 dev_dbg(dev, "ID float\n"); 324 dev_dbg(dev, "ID float\n");
@@ -366,6 +393,7 @@ err1:
366static void omap2430_musb_enable(struct musb *musb) 393static void omap2430_musb_enable(struct musb *musb)
367{ 394{
368 u8 devctl; 395 u8 devctl;
396 u32 val;
369 unsigned long timeout = jiffies + msecs_to_jiffies(1000); 397 unsigned long timeout = jiffies + msecs_to_jiffies(1000);
370 struct device *dev = musb->controller; 398 struct device *dev = musb->controller;
371 struct omap2430_glue *glue = dev_get_drvdata(dev->parent); 399 struct omap2430_glue *glue = dev_get_drvdata(dev->parent);
@@ -375,7 +403,8 @@ static void omap2430_musb_enable(struct musb *musb)
375 switch (glue->status) { 403 switch (glue->status) {
376 404
377 case OMAP_MUSB_ID_GROUND: 405 case OMAP_MUSB_ID_GROUND:
378 usb_phy_init(musb->xceiv); 406 val = AVALID | VBUSVALID;
407 omap4_usb_phy_mailbox(glue, val);
379 if (data->interface_type != MUSB_INTERFACE_UTMI) 408 if (data->interface_type != MUSB_INTERFACE_UTMI)
380 break; 409 break;
381 devctl = musb_readb(musb->mregs, MUSB_DEVCTL); 410 devctl = musb_readb(musb->mregs, MUSB_DEVCTL);
@@ -394,7 +423,8 @@ static void omap2430_musb_enable(struct musb *musb)
394 break; 423 break;
395 424
396 case OMAP_MUSB_VBUS_VALID: 425 case OMAP_MUSB_VBUS_VALID:
397 usb_phy_init(musb->xceiv); 426 val = IDDIG | AVALID | VBUSVALID;
427 omap4_usb_phy_mailbox(glue, val);
398 break; 428 break;
399 429
400 default: 430 default:
@@ -404,11 +434,14 @@ static void omap2430_musb_enable(struct musb *musb)
404 434
405static void omap2430_musb_disable(struct musb *musb) 435static void omap2430_musb_disable(struct musb *musb)
406{ 436{
437 u32 val;
407 struct device *dev = musb->controller; 438 struct device *dev = musb->controller;
408 struct omap2430_glue *glue = dev_get_drvdata(dev->parent); 439 struct omap2430_glue *glue = dev_get_drvdata(dev->parent);
409 440
410 if (glue->status != OMAP_MUSB_UNKNOWN) 441 if (glue->status != OMAP_MUSB_UNKNOWN) {
411 usb_phy_shutdown(musb->xceiv); 442 val = SESSEND | IDDIG;
443 omap4_usb_phy_mailbox(glue, val);
444 }
412} 445}
413 446
414static int omap2430_musb_exit(struct musb *musb) 447static int omap2430_musb_exit(struct musb *musb)
@@ -438,9 +471,14 @@ static u64 omap2430_dmamask = DMA_BIT_MASK(32);
438static int __devinit omap2430_probe(struct platform_device *pdev) 471static int __devinit omap2430_probe(struct platform_device *pdev)
439{ 472{
440 struct musb_hdrc_platform_data *pdata = pdev->dev.platform_data; 473 struct musb_hdrc_platform_data *pdata = pdev->dev.platform_data;
474 struct omap_musb_board_data *data;
441 struct platform_device *musb; 475 struct platform_device *musb;
442 struct omap2430_glue *glue; 476 struct omap2430_glue *glue;
477 struct device_node *np = pdev->dev.of_node;
478 struct musb_hdrc_config *config;
479 struct resource *res;
443 int ret = -ENOMEM; 480 int ret = -ENOMEM;
481 int musbid;
444 482
445 glue = devm_kzalloc(&pdev->dev, sizeof(*glue), GFP_KERNEL); 483 glue = devm_kzalloc(&pdev->dev, sizeof(*glue), GFP_KERNEL);
446 if (!glue) { 484 if (!glue) {
@@ -448,12 +486,21 @@ static int __devinit omap2430_probe(struct platform_device *pdev)
448 goto err0; 486 goto err0;
449 } 487 }
450 488
451 musb = platform_device_alloc("musb-hdrc", -1); 489 /* get the musb id */
490 musbid = musb_get_id(&pdev->dev, GFP_KERNEL);
491 if (musbid < 0) {
492 dev_err(&pdev->dev, "failed to allocate musb id\n");
493 ret = -ENOMEM;
494 goto err0;
495 }
496
497 musb = platform_device_alloc("musb-hdrc", musbid);
452 if (!musb) { 498 if (!musb) {
453 dev_err(&pdev->dev, "failed to allocate musb device\n"); 499 dev_err(&pdev->dev, "failed to allocate musb device\n");
454 goto err0; 500 goto err1;
455 } 501 }
456 502
503 musb->id = musbid;
457 musb->dev.parent = &pdev->dev; 504 musb->dev.parent = &pdev->dev;
458 musb->dev.dma_mask = &omap2430_dmamask; 505 musb->dev.dma_mask = &omap2430_dmamask;
459 musb->dev.coherent_dma_mask = omap2430_dmamask; 506 musb->dev.coherent_dma_mask = omap2430_dmamask;
@@ -462,6 +509,48 @@ static int __devinit omap2430_probe(struct platform_device *pdev)
462 glue->musb = musb; 509 glue->musb = musb;
463 glue->status = OMAP_MUSB_UNKNOWN; 510 glue->status = OMAP_MUSB_UNKNOWN;
464 511
512 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
513
514 glue->control_otghs = devm_request_and_ioremap(&pdev->dev, res);
515 if (glue->control_otghs == NULL)
516 dev_dbg(&pdev->dev, "Failed to obtain control memory\n");
517
518 if (np) {
519 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
520 if (!pdata) {
521 dev_err(&pdev->dev,
522 "failed to allocate musb platfrom data\n");
523 ret = -ENOMEM;
524 goto err1;
525 }
526
527 data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
528 if (!data) {
529 dev_err(&pdev->dev,
530 "failed to allocate musb board data\n");
531 ret = -ENOMEM;
532 goto err1;
533 }
534
535 config = devm_kzalloc(&pdev->dev, sizeof(*config), GFP_KERNEL);
536 if (!data) {
537 dev_err(&pdev->dev,
538 "failed to allocate musb hdrc config\n");
539 goto err1;
540 }
541
542 of_property_read_u32(np, "mode", (u32 *)&pdata->mode);
543 of_property_read_u32(np, "interface_type",
544 (u32 *)&data->interface_type);
545 of_property_read_u32(np, "num_eps", (u32 *)&config->num_eps);
546 of_property_read_u32(np, "ram_bits", (u32 *)&config->ram_bits);
547 of_property_read_u32(np, "power", (u32 *)&pdata->power);
548 config->multipoint = of_property_read_bool(np, "multipoint");
549
550 pdata->board_data = data;
551 pdata->config = config;
552 }
553
465 pdata->platform_ops = &omap2430_ops; 554 pdata->platform_ops = &omap2430_ops;
466 555
467 platform_set_drvdata(pdev, glue); 556 platform_set_drvdata(pdev, glue);
@@ -478,13 +567,13 @@ static int __devinit omap2430_probe(struct platform_device *pdev)
478 pdev->num_resources); 567 pdev->num_resources);
479 if (ret) { 568 if (ret) {
480 dev_err(&pdev->dev, "failed to add resources\n"); 569 dev_err(&pdev->dev, "failed to add resources\n");
481 goto err1; 570 goto err2;
482 } 571 }
483 572
484 ret = platform_device_add_data(musb, pdata, sizeof(*pdata)); 573 ret = platform_device_add_data(musb, pdata, sizeof(*pdata));
485 if (ret) { 574 if (ret) {
486 dev_err(&pdev->dev, "failed to add platform_data\n"); 575 dev_err(&pdev->dev, "failed to add platform_data\n");
487 goto err1; 576 goto err2;
488 } 577 }
489 578
490 pm_runtime_enable(&pdev->dev); 579 pm_runtime_enable(&pdev->dev);
@@ -492,14 +581,17 @@ static int __devinit omap2430_probe(struct platform_device *pdev)
492 ret = platform_device_add(musb); 581 ret = platform_device_add(musb);
493 if (ret) { 582 if (ret) {
494 dev_err(&pdev->dev, "failed to register musb device\n"); 583 dev_err(&pdev->dev, "failed to register musb device\n");
495 goto err1; 584 goto err2;
496 } 585 }
497 586
498 return 0; 587 return 0;
499 588
500err1: 589err2:
501 platform_device_put(musb); 590 platform_device_put(musb);
502 591
592err1:
593 musb_put_id(&pdev->dev, musbid);
594
503err0: 595err0:
504 return ret; 596 return ret;
505} 597}
@@ -509,8 +601,8 @@ static int __devexit omap2430_remove(struct platform_device *pdev)
509 struct omap2430_glue *glue = platform_get_drvdata(pdev); 601 struct omap2430_glue *glue = platform_get_drvdata(pdev);
510 602
511 cancel_work_sync(&glue->omap_musb_mailbox_work); 603 cancel_work_sync(&glue->omap_musb_mailbox_work);
512 platform_device_del(glue->musb); 604 musb_put_id(&pdev->dev, glue->musb->id);
513 platform_device_put(glue->musb); 605 platform_device_unregister(glue->musb);
514 606
515 return 0; 607 return 0;
516} 608}
@@ -559,12 +651,26 @@ static struct dev_pm_ops omap2430_pm_ops = {
559#define DEV_PM_OPS NULL 651#define DEV_PM_OPS NULL
560#endif 652#endif
561 653
654#ifdef CONFIG_OF
655static const struct of_device_id omap2430_id_table[] = {
656 {
657 .compatible = "ti,omap4-musb"
658 },
659 {
660 .compatible = "ti,omap3-musb"
661 },
662 {},
663};
664MODULE_DEVICE_TABLE(of, omap2430_id_table);
665#endif
666
562static struct platform_driver omap2430_driver = { 667static struct platform_driver omap2430_driver = {
563 .probe = omap2430_probe, 668 .probe = omap2430_probe,
564 .remove = __devexit_p(omap2430_remove), 669 .remove = __devexit_p(omap2430_remove),
565 .driver = { 670 .driver = {
566 .name = "musb-omap2430", 671 .name = "musb-omap2430",
567 .pm = DEV_PM_OPS, 672 .pm = DEV_PM_OPS,
673 .of_match_table = of_match_ptr(omap2430_id_table),
568 }, 674 },
569}; 675};
570 676
diff --git a/drivers/usb/musb/omap2430.h b/drivers/usb/musb/omap2430.h
index 40b3c02ae9f0..b85f3973e78c 100644
--- a/drivers/usb/musb/omap2430.h
+++ b/drivers/usb/musb/omap2430.h
@@ -49,4 +49,13 @@
49#define OTG_FORCESTDBY 0x414 49#define OTG_FORCESTDBY 0x414
50# define ENABLEFORCE (1 << 0) 50# define ENABLEFORCE (1 << 0)
51 51
52/*
53 * Control Module bit definitions
54 * XXX: Will be removed once we have a driver for control module.
55 */
56#define AVALID BIT(0)
57#define BVALID BIT(1)
58#define VBUSVALID BIT(2)
59#define SESSEND BIT(3)
60#define IDDIG BIT(4)
52#endif /* __MUSB_OMAP243X_H__ */ 61#endif /* __MUSB_OMAP243X_H__ */
diff --git a/drivers/usb/musb/tusb6010.c b/drivers/usb/musb/tusb6010.c
index 00f21dfee5d7..dc4d75ea13ad 100644
--- a/drivers/usb/musb/tusb6010.c
+++ b/drivers/usb/musb/tusb6010.c
@@ -154,7 +154,7 @@ tusb_fifo_write_unaligned(void __iomem *fifo, const u8 *buf, u16 len)
154} 154}
155 155
156static inline void tusb_fifo_read_unaligned(void __iomem *fifo, 156static inline void tusb_fifo_read_unaligned(void __iomem *fifo,
157 void __iomem *buf, u16 len) 157 void *buf, u16 len)
158{ 158{
159 u32 val; 159 u32 val;
160 int i; 160 int i;
@@ -438,14 +438,13 @@ static void musb_do_idle(unsigned long _musb)
438 if (is_host_active(musb) && (musb->port1_status >> 16)) 438 if (is_host_active(musb) && (musb->port1_status >> 16))
439 goto done; 439 goto done;
440 440
441 if (is_peripheral_enabled(musb) && !musb->gadget_driver) { 441 if (!musb->gadget_driver) {
442 wakeups = 0; 442 wakeups = 0;
443 } else { 443 } else {
444 wakeups = TUSB_PRCM_WHOSTDISCON 444 wakeups = TUSB_PRCM_WHOSTDISCON
445 | TUSB_PRCM_WBUS 445 | TUSB_PRCM_WBUS
446 | TUSB_PRCM_WVBUS; 446 | TUSB_PRCM_WVBUS;
447 if (is_otg_enabled(musb)) 447 wakeups |= TUSB_PRCM_WID;
448 wakeups |= TUSB_PRCM_WID;
449 } 448 }
450 tusb_allow_idle(musb, wakeups); 449 tusb_allow_idle(musb, wakeups);
451 } 450 }
@@ -583,21 +582,12 @@ static void tusb_musb_set_vbus(struct musb *musb, int is_on)
583 * 582 *
584 * Note that if a mini-A cable is plugged in the ID line will stay down as 583 * Note that if a mini-A cable is plugged in the ID line will stay down as
585 * the weak ID pull-up is not able to pull the ID up. 584 * the weak ID pull-up is not able to pull the ID up.
586 *
587 * REVISIT: It would be possible to add support for changing between host
588 * and peripheral modes in non-OTG configurations by reconfiguring hardware
589 * and then setting musb->board_mode. For now, only support OTG mode.
590 */ 585 */
591static int tusb_musb_set_mode(struct musb *musb, u8 musb_mode) 586static int tusb_musb_set_mode(struct musb *musb, u8 musb_mode)
592{ 587{
593 void __iomem *tbase = musb->ctrl_base; 588 void __iomem *tbase = musb->ctrl_base;
594 u32 otg_stat, phy_otg_ctrl, phy_otg_ena, dev_conf; 589 u32 otg_stat, phy_otg_ctrl, phy_otg_ena, dev_conf;
595 590
596 if (musb->board_mode != MUSB_OTG) {
597 ERR("Changing mode currently only supported in OTG mode\n");
598 return -EINVAL;
599 }
600
601 otg_stat = musb_readl(tbase, TUSB_DEV_OTG_STAT); 591 otg_stat = musb_readl(tbase, TUSB_DEV_OTG_STAT);
602 phy_otg_ctrl = musb_readl(tbase, TUSB_PHY_OTG_CTRL); 592 phy_otg_ctrl = musb_readl(tbase, TUSB_PHY_OTG_CTRL);
603 phy_otg_ena = musb_readl(tbase, TUSB_PHY_OTG_CTRL_ENABLE); 593 phy_otg_ena = musb_readl(tbase, TUSB_PHY_OTG_CTRL_ENABLE);
@@ -653,10 +643,7 @@ tusb_otg_ints(struct musb *musb, u32 int_src, void __iomem *tbase)
653 if ((int_src & TUSB_INT_SRC_ID_STATUS_CHNG)) { 643 if ((int_src & TUSB_INT_SRC_ID_STATUS_CHNG)) {
654 int default_a; 644 int default_a;
655 645
656 if (is_otg_enabled(musb)) 646 default_a = !(otg_stat & TUSB_DEV_OTG_STAT_ID_STATUS);
657 default_a = !(otg_stat & TUSB_DEV_OTG_STAT_ID_STATUS);
658 else
659 default_a = is_host_enabled(musb);
660 dev_dbg(musb->controller, "Default-%c\n", default_a ? 'A' : 'B'); 647 dev_dbg(musb->controller, "Default-%c\n", default_a ? 'A' : 'B');
661 otg->default_a = default_a; 648 otg->default_a = default_a;
662 tusb_musb_set_vbus(musb, default_a); 649 tusb_musb_set_vbus(musb, default_a);
@@ -670,8 +657,7 @@ tusb_otg_ints(struct musb *musb, u32 int_src, void __iomem *tbase)
670 if (int_src & TUSB_INT_SRC_VBUS_SENSE_CHNG) { 657 if (int_src & TUSB_INT_SRC_VBUS_SENSE_CHNG) {
671 658
672 /* B-dev state machine: no vbus ~= disconnect */ 659 /* B-dev state machine: no vbus ~= disconnect */
673 if ((is_otg_enabled(musb) && !otg->default_a) 660 if (!otg->default_a) {
674 || !is_host_enabled(musb)) {
675 /* ? musb_root_disconnect(musb); */ 661 /* ? musb_root_disconnect(musb); */
676 musb->port1_status &= 662 musb->port1_status &=
677 ~(USB_PORT_STAT_CONNECTION 663 ~(USB_PORT_STAT_CONNECTION
@@ -1120,10 +1106,8 @@ static int tusb_musb_init(struct musb *musb)
1120 } 1106 }
1121 musb->isr = tusb_musb_interrupt; 1107 musb->isr = tusb_musb_interrupt;
1122 1108
1123 if (is_peripheral_enabled(musb)) { 1109 musb->xceiv->set_power = tusb_draw_power;
1124 musb->xceiv->set_power = tusb_draw_power; 1110 the_musb = musb;
1125 the_musb = musb;
1126 }
1127 1111
1128 setup_timer(&musb_idle_timer, musb_do_idle, (unsigned long) musb); 1112 setup_timer(&musb_idle_timer, musb_do_idle, (unsigned long) musb);
1129 1113
@@ -1176,6 +1160,7 @@ static int __devinit tusb_probe(struct platform_device *pdev)
1176 struct tusb6010_glue *glue; 1160 struct tusb6010_glue *glue;
1177 1161
1178 int ret = -ENOMEM; 1162 int ret = -ENOMEM;
1163 int musbid;
1179 1164
1180 glue = kzalloc(sizeof(*glue), GFP_KERNEL); 1165 glue = kzalloc(sizeof(*glue), GFP_KERNEL);
1181 if (!glue) { 1166 if (!glue) {
@@ -1183,12 +1168,21 @@ static int __devinit tusb_probe(struct platform_device *pdev)
1183 goto err0; 1168 goto err0;
1184 } 1169 }
1185 1170
1186 musb = platform_device_alloc("musb-hdrc", -1); 1171 /* get the musb id */
1172 musbid = musb_get_id(&pdev->dev, GFP_KERNEL);
1173 if (musbid < 0) {
1174 dev_err(&pdev->dev, "failed to allocate musb id\n");
1175 ret = -ENOMEM;
1176 goto err1;
1177 }
1178
1179 musb = platform_device_alloc("musb-hdrc", musbid);
1187 if (!musb) { 1180 if (!musb) {
1188 dev_err(&pdev->dev, "failed to allocate musb device\n"); 1181 dev_err(&pdev->dev, "failed to allocate musb device\n");
1189 goto err1; 1182 goto err2;
1190 } 1183 }
1191 1184
1185 musb->id = musbid;
1192 musb->dev.parent = &pdev->dev; 1186 musb->dev.parent = &pdev->dev;
1193 musb->dev.dma_mask = &tusb_dmamask; 1187 musb->dev.dma_mask = &tusb_dmamask;
1194 musb->dev.coherent_dma_mask = tusb_dmamask; 1188 musb->dev.coherent_dma_mask = tusb_dmamask;
@@ -1204,26 +1198,29 @@ static int __devinit tusb_probe(struct platform_device *pdev)
1204 pdev->num_resources); 1198 pdev->num_resources);
1205 if (ret) { 1199 if (ret) {
1206 dev_err(&pdev->dev, "failed to add resources\n"); 1200 dev_err(&pdev->dev, "failed to add resources\n");
1207 goto err2; 1201 goto err3;
1208 } 1202 }
1209 1203
1210 ret = platform_device_add_data(musb, pdata, sizeof(*pdata)); 1204 ret = platform_device_add_data(musb, pdata, sizeof(*pdata));
1211 if (ret) { 1205 if (ret) {
1212 dev_err(&pdev->dev, "failed to add platform_data\n"); 1206 dev_err(&pdev->dev, "failed to add platform_data\n");
1213 goto err2; 1207 goto err3;
1214 } 1208 }
1215 1209
1216 ret = platform_device_add(musb); 1210 ret = platform_device_add(musb);
1217 if (ret) { 1211 if (ret) {
1218 dev_err(&pdev->dev, "failed to register musb device\n"); 1212 dev_err(&pdev->dev, "failed to register musb device\n");
1219 goto err1; 1213 goto err3;
1220 } 1214 }
1221 1215
1222 return 0; 1216 return 0;
1223 1217
1224err2: 1218err3:
1225 platform_device_put(musb); 1219 platform_device_put(musb);
1226 1220
1221err2:
1222 musb_put_id(&pdev->dev, musbid);
1223
1227err1: 1224err1:
1228 kfree(glue); 1225 kfree(glue);
1229 1226
@@ -1235,6 +1232,7 @@ static int __devexit tusb_remove(struct platform_device *pdev)
1235{ 1232{
1236 struct tusb6010_glue *glue = platform_get_drvdata(pdev); 1233 struct tusb6010_glue *glue = platform_get_drvdata(pdev);
1237 1234
1235 musb_put_id(&pdev->dev, glue->musb->id);
1238 platform_device_del(glue->musb); 1236 platform_device_del(glue->musb);
1239 platform_device_put(glue->musb); 1237 platform_device_put(glue->musb);
1240 kfree(glue); 1238 kfree(glue);
diff --git a/drivers/usb/musb/tusb6010_omap.c b/drivers/usb/musb/tusb6010_omap.c
index b67b4bc596c1..53e25968ed0c 100644
--- a/drivers/usb/musb/tusb6010_omap.c
+++ b/drivers/usb/musb/tusb6010_omap.c
@@ -662,7 +662,7 @@ void dma_controller_destroy(struct dma_controller *c)
662 kfree(tusb_dma); 662 kfree(tusb_dma);
663} 663}
664 664
665struct dma_controller *__init 665struct dma_controller *__devinit
666dma_controller_create(struct musb *musb, void __iomem *base) 666dma_controller_create(struct musb *musb, void __iomem *base)
667{ 667{
668 void __iomem *tbase = musb->ctrl_base; 668 void __iomem *tbase = musb->ctrl_base;
diff --git a/drivers/usb/musb/ux500.c b/drivers/usb/musb/ux500.c
index a8c0fadce1b0..d62a91fedc22 100644
--- a/drivers/usb/musb/ux500.c
+++ b/drivers/usb/musb/ux500.c
@@ -74,25 +74,34 @@ static int __devinit ux500_probe(struct platform_device *pdev)
74 goto err0; 74 goto err0;
75 } 75 }
76 76
77 musb = platform_device_alloc("musb-hdrc", -1); 77 /* get the musb id */
78 musbid = musb_get_id(&pdev->dev, GFP_KERNEL);
79 if (musbid < 0) {
80 dev_err(&pdev->dev, "failed to allocate musb id\n");
81 ret = -ENOMEM;
82 goto err1;
83 }
84
85 musb = platform_device_alloc("musb-hdrc", musbid);
78 if (!musb) { 86 if (!musb) {
79 dev_err(&pdev->dev, "failed to allocate musb device\n"); 87 dev_err(&pdev->dev, "failed to allocate musb device\n");
80 goto err1; 88 goto err2;
81 } 89 }
82 90
83 clk = clk_get(&pdev->dev, "usb"); 91 clk = clk_get(&pdev->dev, "usb");
84 if (IS_ERR(clk)) { 92 if (IS_ERR(clk)) {
85 dev_err(&pdev->dev, "failed to get clock\n"); 93 dev_err(&pdev->dev, "failed to get clock\n");
86 ret = PTR_ERR(clk); 94 ret = PTR_ERR(clk);
87 goto err2; 95 goto err3;
88 } 96 }
89 97
90 ret = clk_enable(clk); 98 ret = clk_enable(clk);
91 if (ret) { 99 if (ret) {
92 dev_err(&pdev->dev, "failed to enable clock\n"); 100 dev_err(&pdev->dev, "failed to enable clock\n");
93 goto err3; 101 goto err4;
94 } 102 }
95 103
104 musb->id = musbid;
96 musb->dev.parent = &pdev->dev; 105 musb->dev.parent = &pdev->dev;
97 musb->dev.dma_mask = pdev->dev.dma_mask; 106 musb->dev.dma_mask = pdev->dev.dma_mask;
98 musb->dev.coherent_dma_mask = pdev->dev.coherent_dma_mask; 107 musb->dev.coherent_dma_mask = pdev->dev.coherent_dma_mask;
@@ -109,32 +118,35 @@ static int __devinit ux500_probe(struct platform_device *pdev)
109 pdev->num_resources); 118 pdev->num_resources);
110 if (ret) { 119 if (ret) {
111 dev_err(&pdev->dev, "failed to add resources\n"); 120 dev_err(&pdev->dev, "failed to add resources\n");
112 goto err4; 121 goto err5;
113 } 122 }
114 123
115 ret = platform_device_add_data(musb, pdata, sizeof(*pdata)); 124 ret = platform_device_add_data(musb, pdata, sizeof(*pdata));
116 if (ret) { 125 if (ret) {
117 dev_err(&pdev->dev, "failed to add platform_data\n"); 126 dev_err(&pdev->dev, "failed to add platform_data\n");
118 goto err4; 127 goto err5;
119 } 128 }
120 129
121 ret = platform_device_add(musb); 130 ret = platform_device_add(musb);
122 if (ret) { 131 if (ret) {
123 dev_err(&pdev->dev, "failed to register musb device\n"); 132 dev_err(&pdev->dev, "failed to register musb device\n");
124 goto err4; 133 goto err5;
125 } 134 }
126 135
127 return 0; 136 return 0;
128 137
129err4: 138err5:
130 clk_disable(clk); 139 clk_disable(clk);
131 140
132err3: 141err4:
133 clk_put(clk); 142 clk_put(clk);
134 143
135err2: 144err3:
136 platform_device_put(musb); 145 platform_device_put(musb);
137 146
147err2:
148 musb_put_id(&pdev->dev, musbid);
149
138err1: 150err1:
139 kfree(glue); 151 kfree(glue);
140 152
@@ -146,6 +158,7 @@ static int __devexit ux500_remove(struct platform_device *pdev)
146{ 158{
147 struct ux500_glue *glue = platform_get_drvdata(pdev); 159 struct ux500_glue *glue = platform_get_drvdata(pdev);
148 160
161 musb_put_id(&pdev->dev, glue->musb->id);
149 platform_device_del(glue->musb); 162 platform_device_del(glue->musb);
150 platform_device_put(glue->musb); 163 platform_device_put(glue->musb);
151 clk_disable(glue->clk); 164 clk_disable(glue->clk);
diff --git a/drivers/usb/musb/ux500_dma.c b/drivers/usb/musb/ux500_dma.c
index d05c7fbbb703..639d58ee24f9 100644
--- a/drivers/usb/musb/ux500_dma.c
+++ b/drivers/usb/musb/ux500_dma.c
@@ -364,7 +364,7 @@ void dma_controller_destroy(struct dma_controller *c)
364 kfree(controller); 364 kfree(controller);
365} 365}
366 366
367struct dma_controller *__init 367struct dma_controller *__devinit
368dma_controller_create(struct musb *musb, void __iomem *base) 368dma_controller_create(struct musb *musb, void __iomem *base)
369{ 369{
370 struct ux500_dma_controller *controller; 370 struct ux500_dma_controller *controller;