]> git.karo-electronics.de Git - linux-beck.git/commitdiff
clk: lpc18xx-cgu: fix potential system hang when disabling unused clocks
authorJoachim Eastwood <manabian@gmail.com>
Sat, 24 Oct 2015 16:55:24 +0000 (18:55 +0200)
committerStephen Boyd <sboyd@codeaurora.org>
Mon, 26 Oct 2015 19:36:58 +0000 (12:36 -0700)
The clock consumer (CCU) of the CGU must be able to check if a CGU
base clock is really running since access to the CCU registers
requires a running base clock. Access with a disabled base clock will
cause the system to hang. Fix this issue by adding code that check if
the parent clock is running in the is_enabled clk_ops callback. Since
certain clocks can be cascaded this must be added to all clock gates.

The hang would occur if the boot ROM or boot loader didn't setup and
enable the USB0 clock. Then when the clk framework tried to access
the CCU register it would hang the system.

Signed-off-by: Joachim Eastwood <manabian@gmail.com>
Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
drivers/clk/nxp/clk-lpc18xx-cgu.c

index e0a3cb8970ab5b68e24dbb2fbcbb45f13d0ae0b3..c924572fc9bc1296b6c7353ff0b39d8ed92ead62 100644 (file)
@@ -480,6 +480,42 @@ static const struct clk_ops lpc18xx_pll1_ops = {
        .recalc_rate = lpc18xx_pll1_recalc_rate,
 };
 
+static int lpc18xx_cgu_gate_enable(struct clk_hw *hw)
+{
+       return clk_gate_ops.enable(hw);
+}
+
+static void lpc18xx_cgu_gate_disable(struct clk_hw *hw)
+{
+       clk_gate_ops.disable(hw);
+}
+
+static int lpc18xx_cgu_gate_is_enabled(struct clk_hw *hw)
+{
+       const struct clk_hw *parent;
+
+       /*
+        * The consumer of base clocks needs know if the
+        * base clock is really enabled before it can be
+        * accessed. It is therefore necessary to verify
+        * this all the way up.
+        */
+       parent = clk_hw_get_parent(hw);
+       if (!parent)
+               return 0;
+
+       if (!clk_hw_is_enabled(parent))
+               return 0;
+
+       return clk_gate_ops.is_enabled(hw);
+}
+
+static const struct clk_ops lpc18xx_gate_ops = {
+       .enable = lpc18xx_cgu_gate_enable,
+       .disable = lpc18xx_cgu_gate_disable,
+       .is_enabled = lpc18xx_cgu_gate_is_enabled,
+};
+
 static struct lpc18xx_cgu_pll_clk lpc18xx_cgu_src_clk_plls[] = {
        LPC1XX_CGU_CLK_PLL(PLL0USB,     pll0_src_ids, pll0_ops),
        LPC1XX_CGU_CLK_PLL(PLL0AUDIO,   pll0_src_ids, pll0_ops),
@@ -510,7 +546,7 @@ static struct clk *lpc18xx_cgu_register_div(struct lpc18xx_cgu_src_clk_div *clk,
        return clk_register_composite(NULL, name, parents, clk->n_parents,
                                      &clk->mux.hw, &clk_mux_ops,
                                      &clk->div.hw, &clk_divider_ops,
-                                     &clk->gate.hw, &clk_gate_ops, 0);
+                                     &clk->gate.hw, &lpc18xx_gate_ops, 0);
 }
 
 
@@ -538,7 +574,7 @@ static struct clk *lpc18xx_register_base_clk(struct lpc18xx_cgu_base_clk *clk,
        return clk_register_composite(NULL, name, parents, clk->n_parents,
                                      &clk->mux.hw, &clk_mux_ops,
                                      NULL,  NULL,
-                                     &clk->gate.hw, &clk_gate_ops, 0);
+                                     &clk->gate.hw, &lpc18xx_gate_ops, 0);
 }
 
 
@@ -557,7 +593,7 @@ static struct clk *lpc18xx_cgu_register_pll(struct lpc18xx_cgu_pll_clk *clk,
        return clk_register_composite(NULL, name, parents, clk->n_parents,
                                      &clk->mux.hw, &clk_mux_ops,
                                      &clk->pll.hw, clk->pll_ops,
-                                     &clk->gate.hw, &clk_gate_ops, 0);
+                                     &clk->gate.hw, &lpc18xx_gate_ops, 0);
 }
 
 static void __init lpc18xx_cgu_register_source_clks(struct device_node *np,