Support imx8m composite mux
Subsystems (3)
cover Support imx8m composite mux
The mux ops for i.MX8M composite clk needs to be specialized. In order to reduce the code duplication we need to make public some interface and write a specific function in the mux ops. Those patches implement the behavior
Michael Trimarchi (2):
clk: clk-mux: Make public the clk_fetch_parent_index
clk: imx: add mux ops for i.MX8M composite clk
drivers/clk/clk-mux.c | 5 ++-- drivers/clk/imx/clk-composite-8m.c | 37 +++++++++++++++++++++++++++++- include/linux/clk-provider.h | 1 + 3 files changed, 39 insertions(+), 4 deletions(-)
Signature · 1 line
2.43.0
PATCH 1/2 clk: clk-mux: Make public the clk_fetch_parent_index
Make public the clk_fetch_parent_index and rename it. This allow us to be reused in driver specialization
--- drivers/clk/clk-mux.c | 5 ++--- include/linux/clk-provider.h | 1 + 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/clk/clk-mux.c +2 -3
@@ -102,8 +102,7 @@ u8 clk_mux_get_parent(struct clk *clk)return clk_mux_val_to_index (clk, mux->table, mux->flags, val); } -static int clk_fetch_parent_index (struct clk *clk, -struct clk *parent) +int clk_mux_fetch_parent_index (struct clk *clk,struct clk *parent) {struct clk_mux *mux =to_clk_mux (clk);
@@ -127,7 +126,7 @@ static int clk_mux_set_parent(struct clk *clk, struct clk *parent)u32 val;u32 reg; - index =clk_fetch_parent_index (clk, parent); + index =clk_mux_fetch_parent_index (clk, parent);if (index <0 ) {log_err ("Could not fetch index\n" );return index;
include/linux/clk-provider.h +1 -0
@@ -74,6 +74,7 @@ struct clk_mux {#define to_clk_mux (_clk) container_of(_clk, struct clk_mux, clk)extern const struct clk_ops clk_mux_ops;u8 clk_mux_get_parent (struct clk *clk); +int clk_mux_fetch_parent_index (struct clk *clk,struct clk *parent);/** * clk_mux_index_to_val() - Convert the parent index to the register value
Signature · 1 line
2.43.0
PATCH 2/2 clk: imx: add mux ops for i.MX8M composite clk
In reply to Michael TrimarchiUpstream Linux commit f90b68d6c8b0.
The CORE/BUS root slice has following design, simplied graph:
The difference is core not have pre_div block.
A composite core/bus clk has 8 inputs for mux to select, saying clk[0-7].
It support target(smart) interface and normal interface. Target interface is exported for programmer easy to configure ccm root. Normal interface is also exported, but we not use it in our driver, because it will introduce more complexity compared with target interface.
The normal interface simplified as below:
SEL_A GA
+--+ +-+
| +->+ +------+
CLK[0-7]--->+ | +-+ |
| | | +----v---+ +----+
| +--+ |pre_diva+----> | +---------+
| +--------+ |mux +--+post_div |
| +--+ |pre_divb+--->+ | +---------+
| | | +----^---+ +----+
+--->+ | +-+ |
| +->+ +------+
+--+ +-+
SEL_B GBThe mux in the upper pic is not the target interface MUX, target interface MUX is hiding SEL_A and SEL_B. When you choose clk[0-7], you are actually writing SEL_A or SEL_B depends on the internal counter which will also control the internal "mux".
The target interface simplified as below which is used by Linux Kernel:
CLK[0-7]--->MUX-->Gate-->pre_div-->post_div
A requirement of the Target Interface's software is that the target clock source is active, it means when setting SEL_A, the current input clk to SEL_A must be active, same to SEL_B.
We touch target interface, but hardware logic actually also need configure normal interface.
There will be system hang, when doing the following steps:
The initial state:
SEL_A/SEL_B are both sourcing from clk0, the internal counter choose SEL_A.
1. switch mux from clk0 to clk1
The hardware logic will choose SEL_B and configure SEL_B to clk1. SEL_A no changed.
2. gate off clk0
Disable clk0, then the input to SEL_A is off.
3. switch from clk1 to clk2
The hardware logic will choose SEL_A and configure SEL_A to clk2, however the current SEL_A input clk0 is off, the system hang.
The solution to fix the issue is in step 1, write twice to target interface MUX, it will make SEL_A/SEL_B both sources from clk1, then no need to care about the state of clk0. And finally system performs well.
--- drivers/clk/imx/clk-composite-8m.c | 37 +++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-)
drivers/clk/imx/clk-composite-8m.c +36 -1
@@ -117,6 +117,41 @@ static const struct clk_ops imx8m_clk_composite_divider_ops = { .set_rate = imx8m_clk_composite_divider_set_rate, }; +static int imx8m_clk_mux_set_parent (struct clk *clk,struct clk *parent) +{ +struct clk_mux *mux =to_clk_mux (clk); +int index; +u32 val; +u32 reg; + + index =clk_mux_fetch_parent_index (clk, parent); +if (index <0 ) { +log_err ("Could not fetch index\n" ); +return index; + } + + val =clk_mux_index_to_val (mux->table, mux->flags, index); + + reg =readl (mux->reg); + reg &= ~(mux->mask << mux->shift); + val = val << mux->shift; + reg |= val; + +/* +* write twice to make sure non-target interface +* SEL_A/B point the same clk input. +*/ +writel (reg, mux->reg); +writel (reg, mux->reg); + +return 0 ; +} + +const struct clk_ops imx8m_clk_mux_ops = { + .get_rate = clk_generic_get_rate, + .set_parent = imx8m_clk_mux_set_parent, +}; + struct clk *imx8m_clk_composite_flags(const char *name, const char * const *parent_names, int num_parents, void __iomem *reg,
@@ -155,7 +190,7 @@ struct clk *imx8m_clk_composite_flags(const char *name, clk =clk_register_composite (NULL , name, parent_names, num_parents, - &mux->clk, &clk_mux_ops, &div->clk, + &mux->clk, &imx8m_clk_mux_ops, &div->clk, &imx8m_clk_composite_divider_ops, &gate->clk, &clk_gate_ops, flags);if (IS_ERR (clk))
Signature · 1 line
2.43.0
Fabio Estevam
reviewerRe: [PATCH 2/2] clk: imx: add mux ops for i.MX8M composite clk
Hi Michael,
Quoted 2 lines · Michael Trimarchi
Upstream Linux commit
f90b68d6c8b0.
....
Quoted 52 lines
The CORE/BUS root slice has following design, simplied graph:
The difference is core not havepre_divblock.
A composite core/bus clk has 8 inputs for mux to select, saying clk[0-7].It support target(smart) interface and normal interface. Target interface is exported for programmer easy to configure ccm root. Normal interface is also exported, but we not use it in our driver, because it will introduce more complexity compared with target interface.
The normal interface simplified as below:
SEL_A GA +--+ +-+ | +->+ +------+ CLK[0-7]--->+ | +-+ | | | | +----v---+ +----+ | +--+ |pre_diva+----> | +---------+ | +--------+ |mux +--+post_div | | +--+ |pre_divb+--->+ | +---------+ | | | +----^---+ +----+ +--->+ | +-+ | | +->+ +------+ +--+ +-+ SEL_B GBThe mux in the upper pic is not the target interface MUX, target interface MUX is hiding
SEL_AandSEL_B. When you choose clk[0-7], you are actually writingSEL_AorSEL_Bdepends on the internal counter which will also control the internal "mux".The target interface simplified as below which is used by Linux Kernel:
CLK[0-7]--->MUX-->Gate-->pre_div-->post_divA requirement of the Target Interface's software is that the target clock source is active, it means when setting
SEL_A, the current input clk toSEL_Amust be active, same toSEL_B.We touch target interface, but hardware logic actually also need configure normal interface.
There will be system hang, when doing the following steps:
The initial state:
SEL_A/SEL_B are both sourcing from clk0, the internal counter chooseSEL_A.
1. switch mux from clk0 to clk1
The hardware logic will chooseSEL_Band configureSEL_Bto clk1.SEL_Ano changed.
2. gate off clk0
Disable clk0, then the input toSEL_Ais off.
3. switch from clk1 to clk2
The hardware logic will chooseSEL_Aand configureSEL_Ato clk2, however the currentSEL_Ainput clk0 is off, the system hang.
Quoted 4 lines
The solution to fix the issue is in step 1, write twice to target interface MUX, it will make SEL_A/SEL_B both sources from clk1, then no need to care about the state of clk0. And finally system performs well.
Shouldn't this also contain the original kernel commit author's Signed-off-by?
Quoted 1 line
Signed-off-by Michael Trimarchi <[email protected]>
Re: [PATCH 2/2] clk: imx: add mux ops for i.MX8M composite clk
Hi Fabio
Quoted 61 lines · Fabio Estevam
Hi Michael,
Quoted 2 lines · Michael Trimarchi
Upstream Linux commit
f90b68d6c8b0.....
Quoted 52 lines
The CORE/BUS root slice has following design, simplied graph:
The difference is core not havepre_divblock.
A composite core/bus clk has 8 inputs for mux to select, saying clk[0-7].It support target(smart) interface and normal interface. Target interface is exported for programmer easy to configure ccm root. Normal interface is also exported, but we not use it in our driver, because it will introduce more complexity compared with target interface.
The normal interface simplified as below:
SEL_A GA +--+ +-+ | +->+ +------+ CLK[0-7]--->+ | +-+ | | | | +----v---+ +----+ | +--+ |pre_diva+----> | +---------+ | +--------+ |mux +--+post_div | | +--+ |pre_divb+--->+ | +---------+ | | | +----^---+ +----+ +--->+ | +-+ | | +->+ +------+ +--+ +-+ SEL_B GBThe mux in the upper pic is not the target interface MUX, target interface MUX is hiding
SEL_AandSEL_B. When you choose clk[0-7], you are actually writingSEL_AorSEL_Bdepends on the internal counter which will also control the internal "mux".The target interface simplified as below which is used by Linux Kernel:
CLK[0-7]--->MUX-->Gate-->pre_div-->post_divA requirement of the Target Interface's software is that the target clock source is active, it means when setting
SEL_A, the current input clk toSEL_Amust be active, same toSEL_B.We touch target interface, but hardware logic actually also need configure normal interface.
There will be system hang, when doing the following steps:
The initial state:
SEL_A/SEL_B are both sourcing from clk0, the internal counter chooseSEL_A.
1. switch mux from clk0 to clk1
The hardware logic will chooseSEL_Band configureSEL_Bto clk1.SEL_Ano changed.
2. gate off clk0
Disable clk0, then the input toSEL_Ais off.
3. switch from clk1 to clk2
The hardware logic will chooseSEL_Aand configureSEL_Ato clk2, however the currentSEL_Ainput clk0 is off, the system hang.
Quoted 8 lines
Quoted 4 lines
The solution to fix the issue is in step 1, write twice to target interface MUX, it will make SEL_A/SEL_B both sources from clk1, then no need to care about the state of clk0. And finally system performs well.
Shouldn't this also contain the original kernel commit author's Signed-off-by?
Quoted 1 line
Signed-off-by Michael Trimarchi <[email protected]>
Fine to me to add. I made a mistake. Let's wait on other reviews
Michael