Skip to content

Commit 87239ca

Browse files
prabhakarladgeertu
authored andcommitted
clk: renesas: rzv2h: Add fixed-factor module clocks with status reporting
Add support for fixed-factor module clocks that can report their enable status through the module status monitor. Introduce a new clock type, CLK_TYPE_FF_MOD_STATUS, and define the associated structure, rzv2h_ff_mod_status_clk, to manage these clocks. Implement the .is_enabled callback by reading the module status register using monitor index and bit definitions. Provide a helper macro, DEF_FIXED_MOD_STATUS, to simplify the definition of such clocks. Signed-off-by: Lad Prabhakar <[email protected]> Reviewed-by: Geert Uytterhoeven <[email protected]> Link: https://lore.kernel.org/[email protected] Signed-off-by: Geert Uytterhoeven <[email protected]>
1 parent 7aada0a commit 87239ca

File tree

2 files changed

+114
-0
lines changed

2 files changed

+114
-0
lines changed

drivers/clk/renesas/rzv2h-cpg.c

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
* @resets: Array of resets
7878
* @num_resets: Number of Module Resets in info->resets[]
7979
* @last_dt_core_clk: ID of the last Core Clock exported to DT
80+
* @ff_mod_status_ops: Fixed Factor Module Status Clock operations
8081
* @mstop_count: Array of mstop values
8182
* @rcdev: Reset controller entity
8283
*/
@@ -92,6 +93,8 @@ struct rzv2h_cpg_priv {
9293
unsigned int num_resets;
9394
unsigned int last_dt_core_clk;
9495

96+
struct clk_ops *ff_mod_status_ops;
97+
9598
atomic_t *mstop_count;
9699

97100
struct reset_controller_dev rcdev;
@@ -149,6 +152,22 @@ struct ddiv_clk {
149152

150153
#define to_ddiv_clock(_div) container_of(_div, struct ddiv_clk, div)
151154

155+
/**
156+
* struct rzv2h_ff_mod_status_clk - Fixed Factor Module Status Clock
157+
*
158+
* @priv: CPG private data
159+
* @conf: fixed mod configuration
160+
* @fix: fixed factor clock
161+
*/
162+
struct rzv2h_ff_mod_status_clk {
163+
struct rzv2h_cpg_priv *priv;
164+
struct fixed_mod_conf conf;
165+
struct clk_fixed_factor fix;
166+
};
167+
168+
#define to_rzv2h_ff_mod_status_clk(_hw) \
169+
container_of(_hw, struct rzv2h_ff_mod_status_clk, fix.hw)
170+
152171
static int rzv2h_cpg_pll_clk_is_enabled(struct clk_hw *hw)
153172
{
154173
struct pll_clk *pll_clk = to_pll(hw);
@@ -418,6 +437,65 @@ rzv2h_cpg_mux_clk_register(const struct cpg_core_clk *core,
418437
return clk_hw->clk;
419438
}
420439

440+
static int
441+
rzv2h_clk_ff_mod_status_is_enabled(struct clk_hw *hw)
442+
{
443+
struct rzv2h_ff_mod_status_clk *fix = to_rzv2h_ff_mod_status_clk(hw);
444+
struct rzv2h_cpg_priv *priv = fix->priv;
445+
u32 offset = GET_CLK_MON_OFFSET(fix->conf.mon_index);
446+
u32 bitmask = BIT(fix->conf.mon_bit);
447+
u32 val;
448+
449+
val = readl(priv->base + offset);
450+
return !!(val & bitmask);
451+
}
452+
453+
static struct clk * __init
454+
rzv2h_cpg_fixed_mod_status_clk_register(const struct cpg_core_clk *core,
455+
struct rzv2h_cpg_priv *priv)
456+
{
457+
struct rzv2h_ff_mod_status_clk *clk_hw_data;
458+
struct clk_init_data init = { };
459+
struct clk_fixed_factor *fix;
460+
const struct clk *parent;
461+
const char *parent_name;
462+
int ret;
463+
464+
WARN_DEBUG(core->parent >= priv->num_core_clks);
465+
parent = priv->clks[core->parent];
466+
if (IS_ERR(parent))
467+
return ERR_CAST(parent);
468+
469+
parent_name = __clk_get_name(parent);
470+
parent = priv->clks[core->parent];
471+
if (IS_ERR(parent))
472+
return ERR_CAST(parent);
473+
474+
clk_hw_data = devm_kzalloc(priv->dev, sizeof(*clk_hw_data), GFP_KERNEL);
475+
if (!clk_hw_data)
476+
return ERR_PTR(-ENOMEM);
477+
478+
clk_hw_data->priv = priv;
479+
clk_hw_data->conf = core->cfg.fixed_mod;
480+
481+
init.name = core->name;
482+
init.ops = priv->ff_mod_status_ops;
483+
init.flags = CLK_SET_RATE_PARENT;
484+
init.parent_names = &parent_name;
485+
init.num_parents = 1;
486+
487+
fix = &clk_hw_data->fix;
488+
fix->hw.init = &init;
489+
fix->mult = core->mult;
490+
fix->div = core->div;
491+
492+
ret = devm_clk_hw_register(priv->dev, &clk_hw_data->fix.hw);
493+
if (ret)
494+
return ERR_PTR(ret);
495+
496+
return clk_hw_data->fix.hw.clk;
497+
}
498+
421499
static struct clk
422500
*rzv2h_cpg_clk_src_twocell_get(struct of_phandle_args *clkspec,
423501
void *data)
@@ -496,6 +574,20 @@ rzv2h_cpg_register_core_clk(const struct cpg_core_clk *core,
496574
else
497575
clk = clk_hw->clk;
498576
break;
577+
case CLK_TYPE_FF_MOD_STATUS:
578+
if (!priv->ff_mod_status_ops) {
579+
priv->ff_mod_status_ops =
580+
devm_kzalloc(dev, sizeof(*priv->ff_mod_status_ops), GFP_KERNEL);
581+
if (!priv->ff_mod_status_ops) {
582+
clk = ERR_PTR(-ENOMEM);
583+
goto fail;
584+
}
585+
memcpy(priv->ff_mod_status_ops, &clk_fixed_factor_ops,
586+
sizeof(const struct clk_ops));
587+
priv->ff_mod_status_ops->is_enabled = rzv2h_clk_ff_mod_status_is_enabled;
588+
}
589+
clk = rzv2h_cpg_fixed_mod_status_clk_register(core, priv);
590+
break;
499591
case CLK_TYPE_PLL:
500592
clk = rzv2h_cpg_pll_clk_register(core, priv, &rzv2h_cpg_pll_ops);
501593
break;

drivers/clk/renesas/rzv2h-cpg.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,23 @@ struct smuxed {
9494
.width = (_width), \
9595
})
9696

97+
/**
98+
* struct fixed_mod_conf - Structure for fixed module configuration
99+
*
100+
* @mon_index: monitor index
101+
* @mon_bit: monitor bit
102+
*/
103+
struct fixed_mod_conf {
104+
u8 mon_index;
105+
u8 mon_bit;
106+
};
107+
108+
#define FIXED_MOD_CONF_PACK(_index, _bit) \
109+
((struct fixed_mod_conf){ \
110+
.mon_index = (_index), \
111+
.mon_bit = (_bit), \
112+
})
113+
97114
#define CPG_SSEL0 (0x300)
98115
#define CPG_SSEL1 (0x304)
99116
#define CPG_CDDIV0 (0x400)
@@ -152,6 +169,7 @@ struct cpg_core_clk {
152169
struct ddiv ddiv;
153170
struct pll pll;
154171
struct smuxed smux;
172+
struct fixed_mod_conf fixed_mod;
155173
} cfg;
156174
const struct clk_div_table *dtable;
157175
const char * const *parent_names;
@@ -164,6 +182,7 @@ enum clk_types {
164182
/* Generic */
165183
CLK_TYPE_IN, /* External Clock Input */
166184
CLK_TYPE_FF, /* Fixed Factor Clock */
185+
CLK_TYPE_FF_MOD_STATUS, /* Fixed Factor Clock which can report the status of module clock */
167186
CLK_TYPE_PLL,
168187
CLK_TYPE_DDIV, /* Dynamic Switching Divider */
169188
CLK_TYPE_SMUX, /* Static Mux */
@@ -179,6 +198,9 @@ enum clk_types {
179198
DEF_TYPE(_name, _id, CLK_TYPE_IN)
180199
#define DEF_FIXED(_name, _id, _parent, _mult, _div) \
181200
DEF_BASE(_name, _id, CLK_TYPE_FF, _parent, .div = _div, .mult = _mult)
201+
#define DEF_FIXED_MOD_STATUS(_name, _id, _parent, _mult, _div, _gate) \
202+
DEF_BASE(_name, _id, CLK_TYPE_FF_MOD_STATUS, _parent, .div = _div, \
203+
.mult = _mult, .cfg.fixed_mod = _gate)
182204
#define DEF_DDIV(_name, _id, _parent, _ddiv_packed, _dtable) \
183205
DEF_TYPE(_name, _id, CLK_TYPE_DDIV, \
184206
.cfg.ddiv = _ddiv_packed, \

0 commit comments

Comments
 (0)