* [PATCH 2/3] clk: mediatek: clk-mtk: Add composite mux tables
2026-11-17 19:16 [PATCH 0/3] clk: mediatek: Model MT8196 PWM source selectors Alexandre Mergnat
2026-11-17 19:16 ` [PATCH 1/3] dt-bindings: clock: mediatek: Add MT8196 PWM muxes Alexandre Mergnat
@ 2026-11-17 19:16 ` Alexandre Mergnat
2026-11-17 19:16 ` [PATCH 3/3] clk: mediatek: Add MT8196 PWM source muxes Alexandre Mergnat
2 siblings, 0 replies; 5+ messages in thread
From: Alexandre Mergnat @ 2026-11-17 19:16 UTC (permalink / raw)
To: Stephen Boyd, Brian Masney, Jerome Brunet, Matthias Brugger,
AngeloGioacchino Del Regno, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Chen-Yu Tsai, Laura Nao
Cc: Chris Chen, linux-clk, linux-kernel, linux-arm-kernel,
linux-mediatek, devicetree, Alexandre Mergnat
Composite muxes register a generic clk_mux, which writes parent index N
as register value N unless it is given a table. struct mtk_composite
cannot pass such a table, so a composite mux cannot describe a selector
whose parent values are not contiguous, such as the MT8196 PWM source
selectors.
Let struct mtk_composite carry a table for the generic clk_mux, and add
MUX_FLAGS_INDEXED() to declare a mux with a table.
Signed-off-by: Alexandre Mergnat <amergnat@baylibre.com>
---
drivers/clk/mediatek/clk-mtk.c | 1 +
drivers/clk/mediatek/clk-mtk.h | 16 ++++++++++++++++
2 files changed, 17 insertions(+)
diff --git a/drivers/clk/mediatek/clk-mtk.c b/drivers/clk/mediatek/clk-mtk.c
index 3dfdd3a422f8..b426f7a36e68 100644
--- a/drivers/clk/mediatek/clk-mtk.c
+++ b/drivers/clk/mediatek/clk-mtk.c
@@ -239,6 +239,7 @@ static struct clk_hw *mtk_clk_register_composite(struct device *dev,
mux->shift = mc->mux_shift;
mux->lock = lock;
mux->flags = mc->mux_flags;
+ mux->table = mc->mux_table;
mux_hw = &mux->hw;
mux_ops = &clk_mux_ops;
diff --git a/drivers/clk/mediatek/clk-mtk.h b/drivers/clk/mediatek/clk-mtk.h
index 5417b9264e6d..c7822a8d015c 100644
--- a/drivers/clk/mediatek/clk-mtk.h
+++ b/drivers/clk/mediatek/clk-mtk.h
@@ -93,6 +93,7 @@ struct mtk_composite {
const char *name;
const char * const *parent_names;
const char *parent;
+ const u32 *mux_table;
unsigned flags;
uint32_t mux_reg;
@@ -161,6 +162,21 @@ struct mtk_composite {
.flags = _flags, \
}
+#define MUX_FLAGS_INDEXED(_id, _name, _parents, _table, _reg, _shift, \
+ _width, _flags) { \
+ .id = _id, \
+ .name = _name, \
+ .mux_reg = _reg, \
+ .mux_shift = _shift, \
+ .mux_width = _width, \
+ .mux_table = _table, \
+ .gate_shift = -1, \
+ .divider_shift = -1, \
+ .parent_names = _parents, \
+ .num_parents = ARRAY_SIZE(_parents), \
+ .flags = _flags, \
+ }
+
#define DIV_GATE(_id, _name, _parent, _gate_reg, _gate_shift, _div_reg, \
_div_width, _div_shift) { \
.id = _id, \
--
2.43.0
^ permalink raw reply [flat|nested] 5+ messages in thread* [PATCH 3/3] clk: mediatek: Add MT8196 PWM source muxes
2026-11-17 19:16 [PATCH 0/3] clk: mediatek: Model MT8196 PWM source selectors Alexandre Mergnat
2026-11-17 19:16 ` [PATCH 1/3] dt-bindings: clock: mediatek: Add MT8196 PWM muxes Alexandre Mergnat
2026-11-17 19:16 ` [PATCH 2/3] clk: mediatek: clk-mtk: Add composite mux tables Alexandre Mergnat
@ 2026-11-17 19:16 ` Alexandre Mergnat
2 siblings, 0 replies; 5+ messages in thread
From: Alexandre Mergnat @ 2026-11-17 19:16 UTC (permalink / raw)
To: Stephen Boyd, Brian Masney, Jerome Brunet, Matthias Brugger,
AngeloGioacchino Del Regno, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Chen-Yu Tsai, Laura Nao
Cc: Chris Chen, linux-clk, linux-kernel, linux-arm-kernel,
linux-mediatek, devicetree, Alexandre Mergnat
The four MT8196 PWM channel clocks and X16W_BCLK each have a source
selector in pericfg_ao, choosing between clk32k, clk26m and the
topckgen pwm clock. The peri_ao driver models their gates as fixed
children of the topckgen pwm clock, so when a selector picks another
input, CCF reports the wrong rate. For the channel clocks, the PWM
driver then computes wrong period and duty counters.
Model the five selectors as muxes and parent the gates on them, so
CCF reports the rate of the selected input. The selection made at
boot is kept, and consumers can change it with assigned-clock-parents.
The selectors do not forward rate requests to the topckgen pwm clock,
which all five share.
Fixes: 212779900009 ("clk: mediatek: Add MT8196 peripheral clock support")
Co-developed-by: Chris Chen <chris-qj.chen@mediatek.com>
Signed-off-by: Chris Chen <chris-qj.chen@mediatek.com>
Signed-off-by: Alexandre Mergnat <amergnat@baylibre.com>
---
drivers/clk/mediatek/clk-mt8196-peri_ao.c | 38 +++++++++++++++++++++++++++----
1 file changed, 33 insertions(+), 5 deletions(-)
diff --git a/drivers/clk/mediatek/clk-mt8196-peri_ao.c b/drivers/clk/mediatek/clk-mt8196-peri_ao.c
index f227a86c5d60..00873264c18e 100644
--- a/drivers/clk/mediatek/clk-mt8196-peri_ao.c
+++ b/drivers/clk/mediatek/clk-mt8196-peri_ao.c
@@ -85,11 +85,16 @@ static const struct mtk_gate peri_ao_clks[] = {
GATE_PERI_AO0(CLK_PERI_AO_UART4_BCLK, "peri_ao_uart4_bclk", "uart", 4),
GATE_PERI_AO0(CLK_PERI_AO_UART5_BCLK, "peri_ao_uart5_bclk", "uart", 5),
GATE_PERI_AO0(CLK_PERI_AO_PWM_X16W_HCLK, "peri_ao_pwm_x16w", "p_axi", 12),
- GATE_PERI_AO0(CLK_PERI_AO_PWM_X16W_BCLK, "peri_ao_pwm_x16w_bclk", "pwm", 13),
- GATE_PERI_AO0(CLK_PERI_AO_PWM_PWM_BCLK0, "peri_ao_pwm_pwm_bclk0", "pwm", 14),
- GATE_PERI_AO0(CLK_PERI_AO_PWM_PWM_BCLK1, "peri_ao_pwm_pwm_bclk1", "pwm", 15),
- GATE_PERI_AO0(CLK_PERI_AO_PWM_PWM_BCLK2, "peri_ao_pwm_pwm_bclk2", "pwm", 16),
- GATE_PERI_AO0(CLK_PERI_AO_PWM_PWM_BCLK3, "peri_ao_pwm_pwm_bclk3", "pwm", 17),
+ GATE_PERI_AO0(CLK_PERI_AO_PWM_X16W_BCLK, "peri_ao_pwm_x16w_bclk",
+ "peri_ao_pwm_x16w_bclk_sel", 13),
+ GATE_PERI_AO0(CLK_PERI_AO_PWM_PWM_BCLK0, "peri_ao_pwm_pwm_bclk0",
+ "peri_ao_pwm_pwm_bclk0_sel", 14),
+ GATE_PERI_AO0(CLK_PERI_AO_PWM_PWM_BCLK1, "peri_ao_pwm_pwm_bclk1",
+ "peri_ao_pwm_pwm_bclk1_sel", 15),
+ GATE_PERI_AO0(CLK_PERI_AO_PWM_PWM_BCLK2, "peri_ao_pwm_pwm_bclk2",
+ "peri_ao_pwm_pwm_bclk2_sel", 16),
+ GATE_PERI_AO0(CLK_PERI_AO_PWM_PWM_BCLK3, "peri_ao_pwm_pwm_bclk3",
+ "peri_ao_pwm_pwm_bclk3_sel", 17),
/* PERI_AO1 */
GATE_HWV_PERI_AO1(CLK_PERI_AO_SPI0_BCLK, "peri_ao_spi0_bclk", "spi0_b", 0),
GATE_HWV_PERI_AO1(CLK_PERI_AO_SPI1_BCLK, "peri_ao_spi1_bclk", "spi1_b", 2),
@@ -117,9 +122,32 @@ static const struct mtk_gate peri_ao_clks[] = {
GATE_PERI_AO2(CLK_PERI_AO_MSDC2_HCLK_WRAP, "peri_ao_msdc2_h_wrap", "peri_ao_msdc2", 13),
};
+static const char * const pwm_src_sel_parents[] = {
+ "clk32k",
+ "clk26m",
+ "pwm",
+};
+
+static const u32 pwm_src_sel_table[] = { 0, 1, 3 };
+
+static const struct mtk_composite peri_ao_muxes[] = {
+ MUX_FLAGS_INDEXED(CLK_PERI_AO_PWM_X16W_BCLK_SEL, "peri_ao_pwm_x16w_bclk_sel",
+ pwm_src_sel_parents, pwm_src_sel_table, 0x20, 6, 2, 0),
+ MUX_FLAGS_INDEXED(CLK_PERI_AO_PWM_PWM_BCLK0_SEL, "peri_ao_pwm_pwm_bclk0_sel",
+ pwm_src_sel_parents, pwm_src_sel_table, 0x20, 8, 2, 0),
+ MUX_FLAGS_INDEXED(CLK_PERI_AO_PWM_PWM_BCLK1_SEL, "peri_ao_pwm_pwm_bclk1_sel",
+ pwm_src_sel_parents, pwm_src_sel_table, 0x20, 10, 2, 0),
+ MUX_FLAGS_INDEXED(CLK_PERI_AO_PWM_PWM_BCLK2_SEL, "peri_ao_pwm_pwm_bclk2_sel",
+ pwm_src_sel_parents, pwm_src_sel_table, 0x20, 12, 2, 0),
+ MUX_FLAGS_INDEXED(CLK_PERI_AO_PWM_PWM_BCLK3_SEL, "peri_ao_pwm_pwm_bclk3_sel",
+ pwm_src_sel_parents, pwm_src_sel_table, 0x20, 14, 2, 0),
+};
+
static const struct mtk_clk_desc peri_ao_mcd = {
.clks = peri_ao_clks,
.num_clks = ARRAY_SIZE(peri_ao_clks),
+ .composite_clks = peri_ao_muxes,
+ .num_composite_clks = ARRAY_SIZE(peri_ao_muxes),
};
static const struct of_device_id of_match_clk_mt8196_peri_ao[] = {
--
2.43.0
^ permalink raw reply [flat|nested] 5+ messages in thread