Skip to content

Commit 31a42c2

Browse files
pinchartlbebarino
authored andcommitted
clk: mediatek: mux: Update parent at enable time
The mux clocks don't always correctly take the new parent into account when the parent is updated while the clock is disabled. Set the update bit when enabling the clock to force an update of the mux. Signed-off-by: Laurent Pinchart <[email protected]> Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Weiyi Lu <[email protected]> Signed-off-by: Stephen Boyd <[email protected]>
1 parent 6df3c6d commit 31a42c2

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

drivers/clk/mediatek/clk-mux.c

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,33 @@ static inline struct mtk_clk_mux *to_mtk_clk_mux(struct clk_hw *hw)
2020
static int mtk_clk_mux_enable_setclr(struct clk_hw *hw)
2121
{
2222
struct mtk_clk_mux *mux = to_mtk_clk_mux(hw);
23+
unsigned long flags = 0;
2324

24-
return regmap_write(mux->regmap, mux->data->clr_ofs,
25-
BIT(mux->data->gate_shift));
25+
if (mux->lock)
26+
spin_lock_irqsave(mux->lock, flags);
27+
else
28+
__acquire(mux->lock);
29+
30+
regmap_write(mux->regmap, mux->data->clr_ofs,
31+
BIT(mux->data->gate_shift));
32+
33+
/*
34+
* If the parent has been changed when the clock was disabled, it will
35+
* not be effective yet. Set the update bit to ensure the mux gets
36+
* updated.
37+
*/
38+
if (mux->reparent && mux->data->upd_shift >= 0) {
39+
regmap_write(mux->regmap, mux->data->upd_ofs,
40+
BIT(mux->data->upd_shift));
41+
mux->reparent = false;
42+
}
43+
44+
if (mux->lock)
45+
spin_unlock_irqrestore(mux->lock, flags);
46+
else
47+
__release(mux->lock);
48+
49+
return 0;
2650
}
2751

2852
static void mtk_clk_mux_disable_setclr(struct clk_hw *hw)
@@ -77,9 +101,11 @@ static int mtk_clk_mux_set_parent_setclr_lock(struct clk_hw *hw, u8 index)
77101
regmap_write(mux->regmap, mux->data->set_ofs,
78102
index << mux->data->mux_shift);
79103

80-
if (mux->data->upd_shift >= 0)
104+
if (mux->data->upd_shift >= 0) {
81105
regmap_write(mux->regmap, mux->data->upd_ofs,
82106
BIT(mux->data->upd_shift));
107+
mux->reparent = true;
108+
}
83109
}
84110

85111
if (mux->lock)

drivers/clk/mediatek/clk-mux.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ struct mtk_clk_mux {
1414
struct regmap *regmap;
1515
const struct mtk_mux *data;
1616
spinlock_t *lock;
17+
bool reparent;
1718
};
1819

1920
struct mtk_mux {

0 commit comments

Comments
 (0)