aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/musb/am35x.c
diff options
context:
space:
mode:
authorFelipe Balbi <balbi@ti.com>2010-12-02 02:57:08 -0500
committerFelipe Balbi <balbi@ti.com>2010-12-10 03:21:24 -0500
commit0349176120aa3024e96ae4fd7dc0e0181dc55f52 (patch)
treeefdcef1542f835f98a53507f0a8f73f5c9736012 /drivers/usb/musb/am35x.c
parent3b7029670d39d22f288ece95254e9ba5ceddd6ba (diff)
usb: musb: move clock handling to glue layer
musb core doesn't need to know about platform specific details. So start moving clock handling to platform glue layer and make musb core agnostic about that. Signed-off-by: Felipe Balbi <balbi@ti.com>
Diffstat (limited to 'drivers/usb/musb/am35x.c')
-rw-r--r--drivers/usb/musb/am35x.c91
1 files changed, 57 insertions, 34 deletions
diff --git a/drivers/usb/musb/am35x.c b/drivers/usb/musb/am35x.c
index e372c87f37e..e4e571bf9ba 100644
--- a/drivers/usb/musb/am35x.c
+++ b/drivers/usb/musb/am35x.c
@@ -85,6 +85,8 @@
85struct am35x_glue { 85struct am35x_glue {
86 struct device *dev; 86 struct device *dev;
87 struct platform_device *musb; 87 struct platform_device *musb;
88 struct clk *phy_clk;
89 struct clk *clk;
88}; 90};
89 91
90static inline void phy_on(void) 92static inline void phy_on(void)
@@ -402,34 +404,18 @@ static int am35x_musb_init(struct musb *musb)
402{ 404{
403 void __iomem *reg_base = musb->ctrl_base; 405 void __iomem *reg_base = musb->ctrl_base;
404 u32 rev, lvl_intr, sw_reset; 406 u32 rev, lvl_intr, sw_reset;
405 int status;
406 407
407 musb->mregs += USB_MENTOR_CORE_OFFSET; 408 musb->mregs += USB_MENTOR_CORE_OFFSET;
408 409
409 clk_enable(musb->clock);
410 DBG(2, "musb->clock=%lud\n", clk_get_rate(musb->clock));
411
412 musb->phy_clock = clk_get(musb->controller, "fck");
413 if (IS_ERR(musb->phy_clock)) {
414 status = PTR_ERR(musb->phy_clock);
415 goto exit0;
416 }
417 clk_enable(musb->phy_clock);
418 DBG(2, "musb->phy_clock=%lud\n", clk_get_rate(musb->phy_clock));
419
420 /* Returns zero if e.g. not clocked */ 410 /* Returns zero if e.g. not clocked */
421 rev = musb_readl(reg_base, USB_REVISION_REG); 411 rev = musb_readl(reg_base, USB_REVISION_REG);
422 if (!rev) { 412 if (!rev)
423 status = -ENODEV; 413 return -ENODEV;
424 goto exit1;
425 }
426 414
427 usb_nop_xceiv_register(); 415 usb_nop_xceiv_register();
428 musb->xceiv = otg_get_transceiver(); 416 musb->xceiv = otg_get_transceiver();
429 if (!musb->xceiv) { 417 if (!musb->xceiv)
430 status = -ENODEV; 418 return -ENODEV;
431 goto exit1;
432 }
433 419
434 if (is_host_enabled(musb)) 420 if (is_host_enabled(musb))
435 setup_timer(&otg_workaround, otg_timer, (unsigned long) musb); 421 setup_timer(&otg_workaround, otg_timer, (unsigned long) musb);
@@ -459,13 +445,8 @@ static int am35x_musb_init(struct musb *musb)
459 lvl_intr = omap_ctrl_readl(AM35XX_CONTROL_LVL_INTR_CLEAR); 445 lvl_intr = omap_ctrl_readl(AM35XX_CONTROL_LVL_INTR_CLEAR);
460 lvl_intr |= AM35XX_USBOTGSS_INT_CLR; 446 lvl_intr |= AM35XX_USBOTGSS_INT_CLR;
461 omap_ctrl_writel(lvl_intr, AM35XX_CONTROL_LVL_INTR_CLEAR); 447 omap_ctrl_writel(lvl_intr, AM35XX_CONTROL_LVL_INTR_CLEAR);
448
462 return 0; 449 return 0;
463exit1:
464 clk_disable(musb->phy_clock);
465 clk_put(musb->phy_clock);
466exit0:
467 clk_disable(musb->clock);
468 return status;
469} 450}
470 451
471static int am35x_musb_exit(struct musb *musb) 452static int am35x_musb_exit(struct musb *musb)
@@ -478,11 +459,6 @@ static int am35x_musb_exit(struct musb *musb)
478 otg_put_transceiver(musb->xceiv); 459 otg_put_transceiver(musb->xceiv);
479 usb_nop_xceiv_unregister(); 460 usb_nop_xceiv_unregister();
480 461
481 clk_disable(musb->clock);
482
483 clk_disable(musb->phy_clock);
484 clk_put(musb->phy_clock);
485
486 return 0; 462 return 0;
487} 463}
488 464
@@ -551,6 +527,9 @@ static int __init am35x_probe(struct platform_device *pdev)
551 struct platform_device *musb; 527 struct platform_device *musb;
552 struct am35x_glue *glue; 528 struct am35x_glue *glue;
553 529
530 struct clk *phy_clk;
531 struct clk *clk;
532
554 int ret = -ENOMEM; 533 int ret = -ENOMEM;
555 534
556 glue = kzalloc(sizeof(*glue), GFP_KERNEL); 535 glue = kzalloc(sizeof(*glue), GFP_KERNEL);
@@ -565,12 +544,40 @@ static int __init am35x_probe(struct platform_device *pdev)
565 goto err1; 544 goto err1;
566 } 545 }
567 546
547 phy_clk = clk_get(&pdev->dev, "fck");
548 if (IS_ERR(phy_clk)) {
549 dev_err(&pdev->dev, "failed to get PHY clock\n");
550 ret = PTR_ERR(phy_clk);
551 goto err2;
552 }
553
554 clk = clk_get(&pdev->dev, "ick");
555 if (IS_ERR(clk)) {
556 dev_err(&pdev->dev, "failed to get clock\n");
557 ret = PTR_ERR(clk);
558 goto err3;
559 }
560
561 ret = clk_enable(phy_clk);
562 if (ret) {
563 dev_err(&pdev->dev, "failed to enable PHY clock\n");
564 goto err4;
565 }
566
567 ret = clk_enable(clk);
568 if (ret) {
569 dev_err(&pdev->dev, "failed to enable clock\n");
570 goto err5;
571 }
572
568 musb->dev.parent = &pdev->dev; 573 musb->dev.parent = &pdev->dev;
569 musb->dev.dma_mask = &am35x_dmamask; 574 musb->dev.dma_mask = &am35x_dmamask;
570 musb->dev.coherent_dma_mask = am35x_dmamask; 575 musb->dev.coherent_dma_mask = am35x_dmamask;
571 576
572 glue->dev = &pdev->dev; 577 glue->dev = &pdev->dev;
573 glue->musb = musb; 578 glue->musb = musb;
579 glue->phy_clk = phy_clk;
580 glue->clk = clk;
574 581
575 pdata->platform_ops = &am35x_ops; 582 pdata->platform_ops = &am35x_ops;
576 583
@@ -580,23 +587,35 @@ static int __init am35x_probe(struct platform_device *pdev)
580 pdev->num_resources); 587 pdev->num_resources);
581 if (ret) { 588 if (ret) {
582 dev_err(&pdev->dev, "failed to add resources\n"); 589 dev_err(&pdev->dev, "failed to add resources\n");
583 goto err2; 590 goto err6;
584 } 591 }
585 592
586 ret = platform_device_add_data(musb, pdata, sizeof(*pdata)); 593 ret = platform_device_add_data(musb, pdata, sizeof(*pdata));
587 if (ret) { 594 if (ret) {
588 dev_err(&pdev->dev, "failed to add platform_data\n"); 595 dev_err(&pdev->dev, "failed to add platform_data\n");
589 goto err2; 596 goto err6;
590 } 597 }
591 598
592 ret = platform_device_add(musb); 599 ret = platform_device_add(musb);
593 if (ret) { 600 if (ret) {
594 dev_err(&pdev->dev, "failed to register musb device\n"); 601 dev_err(&pdev->dev, "failed to register musb device\n");
595 goto err2; 602 goto err6;
596 } 603 }
597 604
598 return 0; 605 return 0;
599 606
607err6:
608 clk_disable(clk);
609
610err5:
611 clk_disable(phy_clk);
612
613err4:
614 clk_put(clk);
615
616err3:
617 clk_put(phy_clk);
618
600err2: 619err2:
601 platform_device_put(musb); 620 platform_device_put(musb);
602 621
@@ -613,6 +632,10 @@ static int __exit am35x_remove(struct platform_device *pdev)
613 632
614 platform_device_del(glue->musb); 633 platform_device_del(glue->musb);
615 platform_device_put(glue->musb); 634 platform_device_put(glue->musb);
635 clk_disable(glue->clk);
636 clk_disable(glue->phy_clk);
637 clk_put(glue->clk);
638 clk_put(glue->phy_clk);
616 kfree(glue); 639 kfree(glue);
617 640
618 return 0; 641 return 0;