mx51: fix usb clock support
authorArnaud Patard (Rtp) <arnaud.patard@rtp-net.org>
Mon, 20 Dec 2010 15:48:58 +0000 (16:48 +0100)
committerSascha Hauer <s.hauer@pengutronix.de>
Mon, 3 Jan 2011 09:20:23 +0000 (10:20 +0100)
Current code doesn't really enable the usb clocks so if they're disabled
when booting linux, the kernel/machine will hang as soon as someone is trying
to read a usb register

Signed-off-by: Arnaud Patard <arnaud.patard@rtp-net.org>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
arch/arm/mach-mx5/clock-mx51-mx53.c
drivers/usb/host/ehci-mxc.c

index 9fc65bbc9d7713cc2a674fbb22cd41d237161014..2f9eae213094fa9432ce3cb4d6e8d2da72f83a12 100644 (file)
@@ -954,6 +954,41 @@ static struct clk usboh3_clk = {
        .parent = &pll2_sw_clk,
        .get_rate = clk_usboh3_get_rate,
        .set_parent = clk_usboh3_set_parent,
+       .enable = _clk_ccgr_enable,
+       .disable = _clk_ccgr_disable,
+       .enable_reg = MXC_CCM_CCGR2,
+       .enable_shift = MXC_CCM_CCGRx_CG14_OFFSET,
+};
+
+static struct clk usb_ahb_clk = {
+       .parent = &ipg_clk,
+       .enable = _clk_ccgr_enable,
+       .disable = _clk_ccgr_disable,
+       .enable_reg = MXC_CCM_CCGR2,
+       .enable_shift = MXC_CCM_CCGRx_CG13_OFFSET,
+};
+
+static int clk_usb_phy1_set_parent(struct clk *clk, struct clk *parent)
+{
+       u32 reg;
+
+       reg = __raw_readl(MXC_CCM_CSCMR1) & ~MXC_CCM_CSCMR1_USB_PHY_CLK_SEL;
+
+       if (parent == &pll3_sw_clk)
+               reg |= 1 << MXC_CCM_CSCMR1_USB_PHY_CLK_SEL_OFFSET;
+
+       __raw_writel(reg, MXC_CCM_CSCMR1);
+
+       return 0;
+}
+
+static struct clk usb_phy1_clk = {
+       .parent = &pll3_sw_clk,
+       .set_parent = clk_usb_phy1_set_parent,
+       .enable = _clk_ccgr_enable,
+       .enable_reg = MXC_CCM_CCGR2,
+       .enable_shift = MXC_CCM_CCGRx_CG0_OFFSET,
+       .disable = _clk_ccgr_disable,
 };
 
 /* eCSPI */
@@ -1094,9 +1129,12 @@ static struct clk_lookup mx51_lookups[] = {
        _REGISTER_CLOCK("imx-i2c.1", NULL, i2c2_clk)
        _REGISTER_CLOCK("imx-i2c.2", NULL, hsi2c_clk)
        _REGISTER_CLOCK("mxc-ehci.0", "usb", usboh3_clk)
-       _REGISTER_CLOCK("mxc-ehci.0", "usb_ahb", ahb_clk)
+       _REGISTER_CLOCK("mxc-ehci.0", "usb_ahb", usb_ahb_clk)
+       _REGISTER_CLOCK("mxc-ehci.0", "usb_phy1", usb_phy1_clk)
        _REGISTER_CLOCK("mxc-ehci.1", "usb", usboh3_clk)
-       _REGISTER_CLOCK("mxc-ehci.1", "usb_ahb", ahb_clk)
+       _REGISTER_CLOCK("mxc-ehci.1", "usb_ahb", usb_ahb_clk)
+       _REGISTER_CLOCK("mxc-ehci.2", "usb", usboh3_clk)
+       _REGISTER_CLOCK("mxc-ehci.2", "usb_ahb", usb_ahb_clk)
        _REGISTER_CLOCK("fsl-usb2-udc", "usb", usboh3_clk)
        _REGISTER_CLOCK("fsl-usb2-udc", "usb_ahb", ahb_clk)
        _REGISTER_CLOCK("imx-keypad.0", NULL, kpp_clk)
@@ -1170,6 +1208,9 @@ int __init mx51_clocks_init(unsigned long ckil, unsigned long osc,
        mx51_revision();
        clk_disable(&iim_clk);
 
+       /* move usb_phy_clk to 24MHz */
+       clk_set_parent(&usb_phy1_clk, &osc_clk);
+
        /* set the usboh3_clk parent to pll2_sw_clk */
        clk_set_parent(&usboh3_clk, &pll2_sw_clk);
 
index bce85055019a190d3d835fd0386d8a8cd7f4e746..a22d2df769a9b41a9a51bfd9e46f252572586d3b 100644 (file)
@@ -28,7 +28,7 @@
 #define ULPI_VIEWPORT_OFFSET   0x170
 
 struct ehci_mxc_priv {
-       struct clk *usbclk, *ahbclk;
+       struct clk *usbclk, *ahbclk, *phy1clk;
        struct usb_hcd *hcd;
 };
 
@@ -168,17 +168,6 @@ static int ehci_mxc_drv_probe(struct platform_device *pdev)
                goto err_ioremap;
        }
 
-       /* call platform specific init function */
-       if (pdata->init) {
-               ret = pdata->init(pdev);
-               if (ret) {
-                       dev_err(dev, "platform init failed\n");
-                       goto err_init;
-               }
-               /* platforms need some time to settle changed IO settings */
-               mdelay(10);
-       }
-
        /* enable clocks */
        priv->usbclk = clk_get(dev, "usb");
        if (IS_ERR(priv->usbclk)) {
@@ -196,6 +185,28 @@ static int ehci_mxc_drv_probe(struct platform_device *pdev)
                clk_enable(priv->ahbclk);
        }
 
+       /* "dr" device has its own clock */
+       if (pdev->id == 0) {
+               priv->phy1clk = clk_get(dev, "usb_phy1");
+               if (IS_ERR(priv->phy1clk)) {
+                       ret = PTR_ERR(priv->phy1clk);
+                       goto err_clk_phy;
+               }
+               clk_enable(priv->phy1clk);
+       }
+
+
+       /* call platform specific init function */
+       if (pdata->init) {
+               ret = pdata->init(pdev);
+               if (ret) {
+                       dev_err(dev, "platform init failed\n");
+                       goto err_init;
+               }
+               /* platforms need some time to settle changed IO settings */
+               mdelay(10);
+       }
+
        /* setup specific usb hw */
        ret = mxc_initialize_usb_hw(pdev->id, pdata->flags);
        if (ret < 0)
@@ -230,6 +241,11 @@ err_add:
        if (pdata && pdata->exit)
                pdata->exit(pdev);
 err_init:
+       if (priv->phy1clk) {
+               clk_disable(priv->phy1clk);
+               clk_put(priv->phy1clk);
+       }
+err_clk_phy:
        if (priv->ahbclk) {
                clk_disable(priv->ahbclk);
                clk_put(priv->ahbclk);
@@ -273,6 +289,10 @@ static int __exit ehci_mxc_drv_remove(struct platform_device *pdev)
                clk_disable(priv->ahbclk);
                clk_put(priv->ahbclk);
        }
+       if (priv->phy1clk) {
+               clk_disable(priv->phy1clk);
+               clk_put(priv->phy1clk);
+       }
 
        kfree(priv);