Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

clk: mediatek: clk-gate: Refactor mtk_clk_register_gate to use mtk_gate struct

MT8196 uses a HW voter for gate enable/disable control, with
set/clr/sta registers located in a separate regmap. Refactor
mtk_clk_register_gate() to take a struct mtk_gate, and add a pointer to
it in struct mtk_clk_gate. This allows reuse of the static gate data
(including HW voter register offsets) without adding extra function
arguments, and removes redundant duplication in the runtime data struct.

Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Reviewed-by: Chen-Yu Tsai <wenst@chromium.org>
Signed-off-by: Laura Nao <laura.nao@collabora.com>
Signed-off-by: Stephen Boyd <sboyd@kernel.org>

authored by

Laura Nao and committed by
Stephen Boyd
8ceff24a be899992

+19 -33
+19 -33
drivers/clk/mediatek/clk-gate.c
··· 17 17 struct mtk_clk_gate { 18 18 struct clk_hw hw; 19 19 struct regmap *regmap; 20 - int set_ofs; 21 - int clr_ofs; 22 - int sta_ofs; 23 - u8 bit; 20 + const struct mtk_gate *gate; 24 21 }; 25 22 26 23 static inline struct mtk_clk_gate *to_mtk_clk_gate(struct clk_hw *hw) ··· 30 33 struct mtk_clk_gate *cg = to_mtk_clk_gate(hw); 31 34 u32 val; 32 35 33 - regmap_read(cg->regmap, cg->sta_ofs, &val); 36 + regmap_read(cg->regmap, cg->gate->regs->sta_ofs, &val); 34 37 35 - return val & BIT(cg->bit); 38 + return val & BIT(cg->gate->shift); 36 39 } 37 40 38 41 static int mtk_cg_bit_is_cleared(struct clk_hw *hw) ··· 49 52 { 50 53 struct mtk_clk_gate *cg = to_mtk_clk_gate(hw); 51 54 52 - regmap_write(cg->regmap, cg->set_ofs, BIT(cg->bit)); 55 + regmap_write(cg->regmap, cg->gate->regs->set_ofs, BIT(cg->gate->shift)); 53 56 } 54 57 55 58 static void mtk_cg_clr_bit(struct clk_hw *hw) 56 59 { 57 60 struct mtk_clk_gate *cg = to_mtk_clk_gate(hw); 58 61 59 - regmap_write(cg->regmap, cg->clr_ofs, BIT(cg->bit)); 62 + regmap_write(cg->regmap, cg->gate->regs->clr_ofs, BIT(cg->gate->shift)); 60 63 } 61 64 62 65 static void mtk_cg_set_bit_no_setclr(struct clk_hw *hw) 63 66 { 64 67 struct mtk_clk_gate *cg = to_mtk_clk_gate(hw); 65 68 66 - regmap_set_bits(cg->regmap, cg->sta_ofs, BIT(cg->bit)); 69 + regmap_set_bits(cg->regmap, cg->gate->regs->sta_ofs, 70 + BIT(cg->gate->shift)); 67 71 } 68 72 69 73 static void mtk_cg_clr_bit_no_setclr(struct clk_hw *hw) 70 74 { 71 75 struct mtk_clk_gate *cg = to_mtk_clk_gate(hw); 72 76 73 - regmap_clear_bits(cg->regmap, cg->sta_ofs, BIT(cg->bit)); 77 + regmap_clear_bits(cg->regmap, cg->gate->regs->sta_ofs, 78 + BIT(cg->gate->shift)); 74 79 } 75 80 76 81 static int mtk_cg_enable(struct clk_hw *hw) ··· 151 152 }; 152 153 EXPORT_SYMBOL_GPL(mtk_clk_gate_ops_no_setclr_inv); 153 154 154 - static struct clk_hw *mtk_clk_register_gate(struct device *dev, const char *name, 155 - const char *parent_name, 156 - struct regmap *regmap, int set_ofs, 157 - int clr_ofs, int sta_ofs, u8 bit, 158 - const struct clk_ops *ops, 159 - unsigned long flags) 155 + static struct clk_hw *mtk_clk_register_gate(struct device *dev, 156 + const struct mtk_gate *gate, 157 + struct regmap *regmap) 160 158 { 161 159 struct mtk_clk_gate *cg; 162 160 int ret; ··· 163 167 if (!cg) 164 168 return ERR_PTR(-ENOMEM); 165 169 166 - init.name = name; 167 - init.flags = flags | CLK_SET_RATE_PARENT; 168 - init.parent_names = parent_name ? &parent_name : NULL; 169 - init.num_parents = parent_name ? 1 : 0; 170 - init.ops = ops; 170 + init.name = gate->name; 171 + init.flags = gate->flags | CLK_SET_RATE_PARENT; 172 + init.parent_names = gate->parent_name ? &gate->parent_name : NULL; 173 + init.num_parents = gate->parent_name ? 1 : 0; 174 + init.ops = gate->ops; 171 175 172 176 cg->regmap = regmap; 173 - cg->set_ofs = set_ofs; 174 - cg->clr_ofs = clr_ofs; 175 - cg->sta_ofs = sta_ofs; 176 - cg->bit = bit; 177 - 177 + cg->gate = gate; 178 178 cg->hw.init = &init; 179 179 180 180 ret = clk_hw_register(dev, &cg->hw); ··· 220 228 continue; 221 229 } 222 230 223 - hw = mtk_clk_register_gate(dev, gate->name, gate->parent_name, 224 - regmap, 225 - gate->regs->set_ofs, 226 - gate->regs->clr_ofs, 227 - gate->regs->sta_ofs, 228 - gate->shift, gate->ops, 229 - gate->flags); 231 + hw = mtk_clk_register_gate(dev, gate, regmap); 230 232 231 233 if (IS_ERR(hw)) { 232 234 pr_err("Failed to register clk %s: %pe\n", gate->name,