usb: musb: da8xx: Call earlier clk_prepare_enable()
authorAlexandre Bailon <abailon@baylibre.com>
Mon, 21 Nov 2016 14:59:30 +0000 (08:59 -0600)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 21 Nov 2016 16:35:37 +0000 (17:35 +0100)
The first attempt to read a register may fail because the clock may not
be enabled, and then the probe of musb driver will fail.
Call clk_prepare_enable() before the first register read.

Signed-off-by: Alexandre Bailon <abailon@baylibre.com>
Signed-off-by: Bin Liu <b-liu@ti.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/musb/da8xx.c

index f205a0381fcc62aac5ba6f5d306d1cddac8331e5..373b61786fe00074783ae3e01749d780075fb220 100644 (file)
@@ -369,6 +369,12 @@ static int da8xx_musb_init(struct musb *musb)
 
        musb->mregs += DA8XX_MENTOR_CORE_OFFSET;
 
+       ret = clk_prepare_enable(glue->clk);
+       if (ret) {
+               dev_err(glue->dev, "failed to enable clock\n");
+               return ret;
+       }
+
        /* Returns zero if e.g. not clocked */
        rev = musb_readl(reg_base, DA8XX_USB_REVISION_REG);
        if (!rev)
@@ -380,12 +386,6 @@ static int da8xx_musb_init(struct musb *musb)
                goto fail;
        }
 
-       ret = clk_prepare_enable(glue->clk);
-       if (ret) {
-               dev_err(glue->dev, "failed to enable clock\n");
-               goto fail;
-       }
-
        setup_timer(&otg_workaround, otg_timer, (unsigned long)musb);
 
        /* Reset the controller */
@@ -395,7 +395,7 @@ static int da8xx_musb_init(struct musb *musb)
        ret = phy_init(glue->phy);
        if (ret) {
                dev_err(glue->dev, "Failed to init phy.\n");
-               goto err_phy_init;
+               goto fail;
        }
 
        ret = phy_power_on(glue->phy);
@@ -415,9 +415,8 @@ static int da8xx_musb_init(struct musb *musb)
 
 err_phy_power_on:
        phy_exit(glue->phy);
-err_phy_init:
-       clk_disable_unprepare(glue->clk);
 fail:
+       clk_disable_unprepare(glue->clk);
        return ret;
 }