Skip to content

Commit 32897e6

Browse files
bijudasgeertu
authored andcommitted
clk: renesas: rzg2l: Add support to handle coupled clocks
The AXI and CHI clocks use the same register bit for controlling clock output. Add a new clock type for coupled clocks, which sets the CPG_CLKON_ETH.CLK[01]_ON bit when at least one clock is enabled, and clears the bit only when both clocks are disabled. 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 70a4af3 commit 32897e6

File tree

2 files changed

+81
-1
lines changed

2 files changed

+81
-1
lines changed

drivers/clk/renesas/rzg2l-cpg.c

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,13 +333,17 @@ rzg2l_cpg_register_core_clk(const struct cpg_core_clk *core,
333333
* @hw: handle between common and hardware-specific interfaces
334334
* @off: register offset
335335
* @bit: ON/MON bit
336+
* @enabled: soft state of the clock, if it is coupled with another clock
336337
* @priv: CPG/MSTP private data
338+
* @sibling: pointer to the other coupled clock
337339
*/
338340
struct mstp_clock {
339341
struct clk_hw hw;
340342
u16 off;
341343
u8 bit;
344+
bool enabled;
342345
struct rzg2l_cpg_priv *priv;
346+
struct mstp_clock *sibling;
343347
};
344348

345349
#define to_mod_clock(_hw) container_of(_hw, struct mstp_clock, hw)
@@ -392,11 +396,41 @@ static int rzg2l_mod_clock_endisable(struct clk_hw *hw, bool enable)
392396

393397
static int rzg2l_mod_clock_enable(struct clk_hw *hw)
394398
{
399+
struct mstp_clock *clock = to_mod_clock(hw);
400+
401+
if (clock->sibling) {
402+
struct rzg2l_cpg_priv *priv = clock->priv;
403+
unsigned long flags;
404+
bool enabled;
405+
406+
spin_lock_irqsave(&priv->rmw_lock, flags);
407+
enabled = clock->sibling->enabled;
408+
clock->enabled = true;
409+
spin_unlock_irqrestore(&priv->rmw_lock, flags);
410+
if (enabled)
411+
return 0;
412+
}
413+
395414
return rzg2l_mod_clock_endisable(hw, true);
396415
}
397416

398417
static void rzg2l_mod_clock_disable(struct clk_hw *hw)
399418
{
419+
struct mstp_clock *clock = to_mod_clock(hw);
420+
421+
if (clock->sibling) {
422+
struct rzg2l_cpg_priv *priv = clock->priv;
423+
unsigned long flags;
424+
bool enabled;
425+
426+
spin_lock_irqsave(&priv->rmw_lock, flags);
427+
enabled = clock->sibling->enabled;
428+
clock->enabled = false;
429+
spin_unlock_irqrestore(&priv->rmw_lock, flags);
430+
if (enabled)
431+
return;
432+
}
433+
400434
rzg2l_mod_clock_endisable(hw, false);
401435
}
402436

@@ -412,6 +446,9 @@ static int rzg2l_mod_clock_is_enabled(struct clk_hw *hw)
412446
return 1;
413447
}
414448

449+
if (clock->sibling)
450+
return clock->enabled;
451+
415452
value = readl(priv->base + CLK_MON_R(clock->off));
416453

417454
return value & bitmask;
@@ -423,6 +460,28 @@ static const struct clk_ops rzg2l_mod_clock_ops = {
423460
.is_enabled = rzg2l_mod_clock_is_enabled,
424461
};
425462

463+
static struct mstp_clock
464+
*rzg2l_mod_clock__get_sibling(struct mstp_clock *clock,
465+
struct rzg2l_cpg_priv *priv)
466+
{
467+
struct clk_hw *hw;
468+
unsigned int i;
469+
470+
for (i = 0; i < priv->num_mod_clks; i++) {
471+
struct mstp_clock *clk;
472+
473+
if (priv->clks[priv->num_core_clks + i] == ERR_PTR(-ENOENT))
474+
continue;
475+
476+
hw = __clk_get_hw(priv->clks[priv->num_core_clks + i]);
477+
clk = to_mod_clock(hw);
478+
if (clock->off == clk->off && clock->bit == clk->bit)
479+
return clk;
480+
}
481+
482+
return NULL;
483+
}
484+
426485
static void __init
427486
rzg2l_cpg_register_mod_clk(const struct rzg2l_mod_clk *mod,
428487
const struct rzg2l_cpg_info *info,
@@ -484,6 +543,18 @@ rzg2l_cpg_register_mod_clk(const struct rzg2l_mod_clk *mod,
484543

485544
dev_dbg(dev, "Module clock %pC at %lu Hz\n", clk, clk_get_rate(clk));
486545
priv->clks[id] = clk;
546+
547+
if (mod->is_coupled) {
548+
struct mstp_clock *sibling;
549+
550+
clock->enabled = rzg2l_mod_clock_is_enabled(&clock->hw);
551+
sibling = rzg2l_mod_clock__get_sibling(clock, priv);
552+
if (sibling) {
553+
clock->sibling = sibling;
554+
sibling->sibling = clock;
555+
}
556+
}
557+
487558
return;
488559

489560
fail:

drivers/clk/renesas/rzg2l-cpg.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,24 +93,33 @@ enum clk_types {
9393
* @parent: id of parent clock
9494
* @off: register offset
9595
* @bit: ON/MON bit
96+
* @is_coupled: flag to indicate coupled clock
9697
*/
9798
struct rzg2l_mod_clk {
9899
const char *name;
99100
unsigned int id;
100101
unsigned int parent;
101102
u16 off;
102103
u8 bit;
104+
bool is_coupled;
103105
};
104106

105-
#define DEF_MOD(_name, _id, _parent, _off, _bit) \
107+
#define DEF_MOD_BASE(_name, _id, _parent, _off, _bit, _is_coupled) \
106108
{ \
107109
.name = _name, \
108110
.id = MOD_CLK_BASE + (_id), \
109111
.parent = (_parent), \
110112
.off = (_off), \
111113
.bit = (_bit), \
114+
.is_coupled = (_is_coupled), \
112115
}
113116

117+
#define DEF_MOD(_name, _id, _parent, _off, _bit) \
118+
DEF_MOD_BASE(_name, _id, _parent, _off, _bit, false)
119+
120+
#define DEF_COUPLED(_name, _id, _parent, _off, _bit) \
121+
DEF_MOD_BASE(_name, _id, _parent, _off, _bit, true)
122+
114123
/**
115124
* struct rzg2l_reset - Reset definitions
116125
*

0 commit comments

Comments
 (0)