clk: sprd: check its parent status before reading gate clock
authorChunyan Zhang <chunyan.zhang@unisoc.com>
Wed, 27 May 2020 05:36:35 +0000 (13:36 +0800)
committerStephen Boyd <sboyd@kernel.org>
Wed, 27 May 2020 06:41:14 +0000 (23:41 -0700)
Some clocks only can be accessed if their parent is enabled. mipi_csi_xx
clocks on SC9863A are an examples. We have to ensure the parent clock is
enabled when reading those clocks.

Signed-off-by: Chunyan Zhang <chunyan.zhang@unisoc.com>
Link: https://lkml.kernel.org/r/20200527053638.31439-2-zhang.lyra@gmail.com
Signed-off-by: Stephen Boyd <sboyd@kernel.org>
drivers/clk/sprd/gate.c
drivers/clk/sprd/gate.h

index 574cfc116bbcd82f7403d7b00f371e37d611b2bf..56e1714b541eff1d6a59cd313810fe41d8b055c9 100644 (file)
@@ -94,8 +94,15 @@ static int sprd_gate_is_enabled(struct clk_hw *hw)
 {
        struct sprd_gate *sg = hw_to_sprd_gate(hw);
        struct sprd_clk_common *common = &sg->common;
+       struct clk_hw *parent;
        unsigned int reg;
 
+       if (sg->flags & SPRD_GATE_NON_AON) {
+               parent = clk_hw_get_parent(hw);
+               if (!parent || !clk_hw_is_enabled(parent))
+                       return 0;
+       }
+
        regmap_read(common->regmap, common->reg, &reg);
 
        if (sg->flags & CLK_GATE_SET_TO_DISABLE)
index b55817869367fe87694bf75ba8b73326bb13d15d..e738dafa4fe910fa96b617fc782551dc3f2806c8 100644 (file)
@@ -19,6 +19,15 @@ struct sprd_gate {
        struct sprd_clk_common  common;
 };
 
+/*
+ * sprd_gate->flags is used for:
+ * CLK_GATE_SET_TO_DISABLE     BIT(0)
+ * CLK_GATE_HIWORD_MASK                BIT(1)
+ * CLK_GATE_BIG_ENDIAN         BIT(2)
+ * so we define new flags from BIT(3)
+ */
+#define SPRD_GATE_NON_AON BIT(3) /* not alway powered on, check before read */
+
 #define SPRD_SC_GATE_CLK_HW_INIT_FN(_struct, _name, _parent, _reg,     \
                                    _sc_offset, _enable_mask, _flags,   \
                                    _gate_flags, _udelay, _ops, _fn)    \