Skip to content

Commit a6a70a6

Browse files
AngeloGioacchino Del Regnobebarino
authored andcommitted
clk: mediatek: clk-mux: Support custom parent indices for muxes
Add support for customized parent indices for MediaTek muxes: this is necessary for the case in which we want to exclude some clocks from a mux's parent clocks list, where the exclusions are not from the very bottom of the list but either in the middle or the beginning. Example: - MUX1 (all parents) - parent1; idx=0 - parent2; idx=1 - parent3; idx=2 - MUX1 (wanted parents) - parent1; idx=0 - parent3; idx=2 To achieve that add a `parent_index` array pointer to struct mtk_mux, then in .set_parent(), .get_parent() callbacks check if this array was populated and eventually get the index from that. Also, to avoid updating all clock drivers for all SoCs, rename the "main" macro to __GATE_CLR_SET_UPD_FLAGS (so, `__` was added) and add the new member to it; furthermore, GATE_CLK_SET_UPD_FLAGS has been reintroduced as being fully compatible with the older version. The new parent_index can be specified with the new `_INDEXED` variants of the MUX_GATE_CLR_SET_UPD_xxxx macros. Reviewed-by: Alexandre Mergnat <[email protected]> Reviewed-by: Chen-Yu Tsai <[email protected]> Signed-off-by: AngeloGioacchino Del Regno <[email protected]> Link: https://lore.kernel.org/r/[email protected] Tested-by: Fei Shao <[email protected]> Reviewed-by: Fei Shao <[email protected]> Signed-off-by: Stephen Boyd <[email protected]>
1 parent 616eceb commit a6a70a6

File tree

2 files changed

+53
-4
lines changed

2 files changed

+53
-4
lines changed

drivers/clk/mediatek/clk-mux.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,17 @@ static u8 mtk_clk_mux_get_parent(struct clk_hw *hw)
8989
regmap_read(mux->regmap, mux->data->mux_ofs, &val);
9090
val = (val >> mux->data->mux_shift) & mask;
9191

92+
if (mux->data->parent_index) {
93+
int i;
94+
95+
for (i = 0; i < mux->data->num_parents; i++)
96+
if (mux->data->parent_index[i] == val)
97+
return i;
98+
99+
/* Not found: return an impossible index to generate error */
100+
return mux->data->num_parents + 1;
101+
}
102+
92103
return val;
93104
}
94105

@@ -104,6 +115,9 @@ static int mtk_clk_mux_set_parent_setclr_lock(struct clk_hw *hw, u8 index)
104115
else
105116
__acquire(mux->lock);
106117

118+
if (mux->data->parent_index)
119+
index = mux->data->parent_index[index];
120+
107121
regmap_read(mux->regmap, mux->data->mux_ofs, &orig);
108122
val = (orig & ~(mask << mux->data->mux_shift))
109123
| (index << mux->data->mux_shift);

drivers/clk/mediatek/clk-mux.h

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ struct mtk_mux {
2121
int id;
2222
const char *name;
2323
const char * const *parent_names;
24+
const u8 *parent_index;
2425
unsigned int flags;
2526

2627
u32 mux_ofs;
@@ -37,9 +38,10 @@ struct mtk_mux {
3738
signed char num_parents;
3839
};
3940

40-
#define GATE_CLR_SET_UPD_FLAGS(_id, _name, _parents, _mux_ofs, \
41-
_mux_set_ofs, _mux_clr_ofs, _shift, _width, \
42-
_gate, _upd_ofs, _upd, _flags, _ops) { \
41+
#define __GATE_CLR_SET_UPD_FLAGS(_id, _name, _parents, _paridx, \
42+
_num_parents, _mux_ofs, _mux_set_ofs, \
43+
_mux_clr_ofs, _shift, _width, _gate, _upd_ofs, \
44+
_upd, _flags, _ops) { \
4345
.id = _id, \
4446
.name = _name, \
4547
.mux_ofs = _mux_ofs, \
@@ -51,11 +53,28 @@ struct mtk_mux {
5153
.gate_shift = _gate, \
5254
.upd_shift = _upd, \
5355
.parent_names = _parents, \
54-
.num_parents = ARRAY_SIZE(_parents), \
56+
.parent_index = _paridx, \
57+
.num_parents = _num_parents, \
5558
.flags = _flags, \
5659
.ops = &_ops, \
5760
}
5861

62+
#define GATE_CLR_SET_UPD_FLAGS(_id, _name, _parents, _mux_ofs, \
63+
_mux_set_ofs, _mux_clr_ofs, _shift, _width, \
64+
_gate, _upd_ofs, _upd, _flags, _ops) \
65+
__GATE_CLR_SET_UPD_FLAGS(_id, _name, _parents, \
66+
NULL, ARRAY_SIZE(_parents), _mux_ofs, \
67+
_mux_set_ofs, _mux_clr_ofs, _shift, _width, \
68+
_gate, _upd_ofs, _upd, _flags, _ops) \
69+
70+
#define GATE_CLR_SET_UPD_FLAGS_INDEXED(_id, _name, _parents, _paridx, \
71+
_mux_ofs, _mux_set_ofs, _mux_clr_ofs, _shift, \
72+
_width, _gate, _upd_ofs, _upd, _flags, _ops) \
73+
__GATE_CLR_SET_UPD_FLAGS(_id, _name, _parents, \
74+
_paridx, ARRAY_SIZE(_paridx), _mux_ofs, \
75+
_mux_set_ofs, _mux_clr_ofs, _shift, _width, \
76+
_gate, _upd_ofs, _upd, _flags, _ops) \
77+
5978
extern const struct clk_ops mtk_mux_clr_set_upd_ops;
6079
extern const struct clk_ops mtk_mux_gate_clr_set_upd_ops;
6180

@@ -67,6 +86,14 @@ extern const struct clk_ops mtk_mux_gate_clr_set_upd_ops;
6786
_gate, _upd_ofs, _upd, _flags, \
6887
mtk_mux_gate_clr_set_upd_ops)
6988

89+
#define MUX_GATE_CLR_SET_UPD_FLAGS_INDEXED(_id, _name, _parents, \
90+
_paridx, _mux_ofs, _mux_set_ofs, _mux_clr_ofs, \
91+
_shift, _width, _gate, _upd_ofs, _upd, _flags) \
92+
GATE_CLR_SET_UPD_FLAGS_INDEXED(_id, _name, _parents, \
93+
_paridx, _mux_ofs, _mux_set_ofs, _mux_clr_ofs, \
94+
_shift, _width, _gate, _upd_ofs, _upd, _flags, \
95+
mtk_mux_gate_clr_set_upd_ops)
96+
7097
#define MUX_GATE_CLR_SET_UPD(_id, _name, _parents, _mux_ofs, \
7198
_mux_set_ofs, _mux_clr_ofs, _shift, _width, \
7299
_gate, _upd_ofs, _upd) \
@@ -75,6 +102,14 @@ extern const struct clk_ops mtk_mux_gate_clr_set_upd_ops;
75102
_width, _gate, _upd_ofs, _upd, \
76103
CLK_SET_RATE_PARENT)
77104

105+
#define MUX_GATE_CLR_SET_UPD_INDEXED(_id, _name, _parents, _paridx, \
106+
_mux_ofs, _mux_set_ofs, _mux_clr_ofs, _shift, \
107+
_width, _gate, _upd_ofs, _upd) \
108+
MUX_GATE_CLR_SET_UPD_FLAGS_INDEXED(_id, _name, \
109+
_parents, _paridx, _mux_ofs, _mux_set_ofs, \
110+
_mux_clr_ofs, _shift, _width, _gate, _upd_ofs, \
111+
_upd, CLK_SET_RATE_PARENT)
112+
78113
#define MUX_CLR_SET_UPD(_id, _name, _parents, _mux_ofs, \
79114
_mux_set_ofs, _mux_clr_ofs, _shift, _width, \
80115
_upd_ofs, _upd) \

0 commit comments

Comments
 (0)