aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoachim Eastwood <manabian@gmail.com>2015-10-24 12:55:24 -0400
committerStephen Boyd <sboyd@codeaurora.org>2015-10-26 15:36:58 -0400
commitc23a5847695dbda865fdb032a25b7f95a1438042 (patch)
treefc5370c5fb1d4b89fe178addfcfc89fad5edc3ed
parent2a9a06f98f26654d3b07482319ea0be276689f0b (diff)
clk: lpc18xx-cgu: fix potential system hang when disabling unused clocks
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>
-rw-r--r--drivers/clk/nxp/clk-lpc18xx-cgu.c42
1 files changed, 39 insertions, 3 deletions
diff --git a/drivers/clk/nxp/clk-lpc18xx-cgu.c b/drivers/clk/nxp/clk-lpc18xx-cgu.c
index e0a3cb8970ab..c924572fc9bc 100644
--- a/drivers/clk/nxp/clk-lpc18xx-cgu.c
+++ b/drivers/clk/nxp/clk-lpc18xx-cgu.c
@@ -480,6 +480,42 @@ static const struct clk_ops lpc18xx_pll1_ops = {
480 .recalc_rate = lpc18xx_pll1_recalc_rate, 480 .recalc_rate = lpc18xx_pll1_recalc_rate,
481}; 481};
482 482
483static int lpc18xx_cgu_gate_enable(struct clk_hw *hw)
484{
485 return clk_gate_ops.enable(hw);
486}
487
488static void lpc18xx_cgu_gate_disable(struct clk_hw *hw)
489{
490 clk_gate_ops.disable(hw);
491}
492
493static int lpc18xx_cgu_gate_is_enabled(struct clk_hw *hw)
494{
495 const struct clk_hw *parent;
496
497 /*
498 * The consumer of base clocks needs know if the
499 * base clock is really enabled before it can be
500 * accessed. It is therefore necessary to verify
501 * this all the way up.
502 */
503 parent = clk_hw_get_parent(hw);
504 if (!parent)
505 return 0;
506
507 if (!clk_hw_is_enabled(parent))
508 return 0;
509
510 return clk_gate_ops.is_enabled(hw);
511}
512
513static const struct clk_ops lpc18xx_gate_ops = {
514 .enable = lpc18xx_cgu_gate_enable,
515 .disable = lpc18xx_cgu_gate_disable,
516 .is_enabled = lpc18xx_cgu_gate_is_enabled,
517};
518
483static struct lpc18xx_cgu_pll_clk lpc18xx_cgu_src_clk_plls[] = { 519static struct lpc18xx_cgu_pll_clk lpc18xx_cgu_src_clk_plls[] = {
484 LPC1XX_CGU_CLK_PLL(PLL0USB, pll0_src_ids, pll0_ops), 520 LPC1XX_CGU_CLK_PLL(PLL0USB, pll0_src_ids, pll0_ops),
485 LPC1XX_CGU_CLK_PLL(PLL0AUDIO, pll0_src_ids, pll0_ops), 521 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,
510 return clk_register_composite(NULL, name, parents, clk->n_parents, 546 return clk_register_composite(NULL, name, parents, clk->n_parents,
511 &clk->mux.hw, &clk_mux_ops, 547 &clk->mux.hw, &clk_mux_ops,
512 &clk->div.hw, &clk_divider_ops, 548 &clk->div.hw, &clk_divider_ops,
513 &clk->gate.hw, &clk_gate_ops, 0); 549 &clk->gate.hw, &lpc18xx_gate_ops, 0);
514} 550}
515 551
516 552
@@ -538,7 +574,7 @@ static struct clk *lpc18xx_register_base_clk(struct lpc18xx_cgu_base_clk *clk,
538 return clk_register_composite(NULL, name, parents, clk->n_parents, 574 return clk_register_composite(NULL, name, parents, clk->n_parents,
539 &clk->mux.hw, &clk_mux_ops, 575 &clk->mux.hw, &clk_mux_ops,
540 NULL, NULL, 576 NULL, NULL,
541 &clk->gate.hw, &clk_gate_ops, 0); 577 &clk->gate.hw, &lpc18xx_gate_ops, 0);
542} 578}
543 579
544 580
@@ -557,7 +593,7 @@ static struct clk *lpc18xx_cgu_register_pll(struct lpc18xx_cgu_pll_clk *clk,
557 return clk_register_composite(NULL, name, parents, clk->n_parents, 593 return clk_register_composite(NULL, name, parents, clk->n_parents,
558 &clk->mux.hw, &clk_mux_ops, 594 &clk->mux.hw, &clk_mux_ops,
559 &clk->pll.hw, clk->pll_ops, 595 &clk->pll.hw, clk->pll_ops,
560 &clk->gate.hw, &clk_gate_ops, 0); 596 &clk->gate.hw, &lpc18xx_gate_ops, 0);
561} 597}
562 598
563static void __init lpc18xx_cgu_register_source_clks(struct device_node *np, 599static void __init lpc18xx_cgu_register_source_clks(struct device_node *np,