Skip to content

Commit 7c5a256

Browse files
bijudasgeertu
authored andcommitted
clk: renesas: rzg2l: Add support to handle MUX clocks
Add support to handle mux clocks in order to select a clock source from multiple sources. Signed-off-by: Biju Das <[email protected]> Reviewed-by: Lad Prabhakar <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Geert Uytterhoeven <[email protected]>
1 parent 3ae4087 commit 7c5a256

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

drivers/clk/renesas/rzg2l-cpg.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,26 @@ rzg2l_cpg_div_clk_register(const struct cpg_core_clk *core,
130130
return clk_hw->clk;
131131
}
132132

133+
static struct clk * __init
134+
rzg2l_cpg_mux_clk_register(const struct cpg_core_clk *core,
135+
void __iomem *base,
136+
struct rzg2l_cpg_priv *priv)
137+
{
138+
const struct clk_hw *clk_hw;
139+
140+
clk_hw = devm_clk_hw_register_mux(priv->dev, core->name,
141+
core->parent_names, core->num_parents,
142+
core->flag,
143+
base + GET_REG_OFFSET(core->conf),
144+
GET_SHIFT(core->conf),
145+
GET_WIDTH(core->conf),
146+
core->mux_flags, &priv->rmw_lock);
147+
if (IS_ERR(clk_hw))
148+
return ERR_CAST(clk_hw);
149+
150+
return clk_hw->clk;
151+
}
152+
133153
struct pll_clk {
134154
struct clk_hw hw;
135155
unsigned int conf;
@@ -288,6 +308,9 @@ rzg2l_cpg_register_core_clk(const struct cpg_core_clk *core,
288308
clk = rzg2l_cpg_div_clk_register(core, priv->clks,
289309
priv->base, priv);
290310
break;
311+
case CLK_TYPE_MUX:
312+
clk = rzg2l_cpg_mux_clk_register(core, priv->base, priv);
313+
break;
291314
default:
292315
goto fail;
293316
}

drivers/clk/renesas/rzg2l-cpg.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
#define DIVPL3A DDIV_PACK(CPG_PL3A_DDIV, 0, 3)
2525
#define DIVPL3B DDIV_PACK(CPG_PL3A_DDIV, 4, 3)
2626

27+
#define SEL_PLL_PACK(offset, bitpos, size) \
28+
(((offset) << 20) | ((bitpos) << 12) | ((size) << 8))
29+
2730
/**
2831
* Definitions of CPG Core Clocks
2932
*
@@ -43,6 +46,7 @@ struct cpg_core_clk {
4346
const struct clk_div_table *dtable;
4447
const char * const *parent_names;
4548
int flag;
49+
int mux_flags;
4650
int num_parents;
4751
};
4852

@@ -54,6 +58,9 @@ enum clk_types {
5458

5559
/* Clock with divider */
5660
CLK_TYPE_DIV,
61+
62+
/* Clock with clock source selector */
63+
CLK_TYPE_MUX,
5764
};
5865

5966
#define DEF_TYPE(_name, _id, _type...) \
@@ -69,6 +76,11 @@ enum clk_types {
6976
#define DEF_DIV(_name, _id, _parent, _conf, _dtable, _flag) \
7077
DEF_TYPE(_name, _id, CLK_TYPE_DIV, .conf = _conf, \
7178
.parent = _parent, .dtable = _dtable, .flag = _flag)
79+
#define DEF_MUX(_name, _id, _conf, _parent_names, _num_parents, _flag, \
80+
_mux_flags) \
81+
DEF_TYPE(_name, _id, CLK_TYPE_MUX, .conf = _conf, \
82+
.parent_names = _parent_names, .num_parents = _num_parents, \
83+
.flag = _flag, .mux_flags = _mux_flags)
7284

7385
/**
7486
* struct rzg2l_mod_clk - Module Clocks definitions

0 commit comments

Comments
 (0)