Skip to content

Commit 601cb6d

Browse files
mripardbebarino
authored andcommitted
clk: socfpga: gate: Account for the divider in determine_rate
Commit 9607beb ("clk: socfpga: gate: Add a determine_rate hook") added a determine_rate implementation set to the clk_hw_determine_rate_no_reparent, but failed to account for the internal divider that wasn't used before anywhere but in recalc_rate. This led to inconsistencies between the clock rate stored in clk_core->rate and the one returned by clk_round_rate() that leverages determine_rate(). Since that driver seems to be widely used (and thus regression-prone) and not supporting rate changes (since it's missing a .set_rate implementation), we can just report the current divider programmed in the clock but not try to change it in any way. This should be good enough to fix the issues reported, and if someone ever wants to allow the divider to change then it should be easy enough using the clk-divider helpers. Link: https://lore.kernel.org/linux-clk/[email protected]/ Fixes: 9607beb ("clk: socfpga: gate: Add a determine_rate hook") Reported-by: Benedikt Spranger <[email protected]> Signed-off-by: Maxime Ripard <[email protected]> Link: https://lore.kernel.org/r/[email protected] [[email protected]: Fix hw -> hwclk] Signed-off-by: Stephen Boyd <[email protected]>
1 parent a47b44f commit 601cb6d

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

drivers/clk/socfpga/clk-gate.c

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,8 @@ static int socfpga_clk_set_parent(struct clk_hw *hwclk, u8 parent)
8787
return 0;
8888
}
8989

90-
static unsigned long socfpga_clk_recalc_rate(struct clk_hw *hwclk,
91-
unsigned long parent_rate)
90+
static u32 socfpga_clk_get_div(struct socfpga_gate_clk *socfpgaclk)
9291
{
93-
struct socfpga_gate_clk *socfpgaclk = to_socfpga_gate_clk(hwclk);
9492
u32 div = 1, val;
9593

9694
if (socfpgaclk->fixed_div)
@@ -105,12 +103,33 @@ static unsigned long socfpga_clk_recalc_rate(struct clk_hw *hwclk,
105103
div = (1 << val);
106104
}
107105

106+
return div;
107+
}
108+
109+
static unsigned long socfpga_clk_recalc_rate(struct clk_hw *hwclk,
110+
unsigned long parent_rate)
111+
{
112+
struct socfpga_gate_clk *socfpgaclk = to_socfpga_gate_clk(hwclk);
113+
u32 div = socfpga_clk_get_div(socfpgaclk);
114+
108115
return parent_rate / div;
109116
}
110117

118+
119+
static int socfpga_clk_determine_rate(struct clk_hw *hwclk,
120+
struct clk_rate_request *req)
121+
{
122+
struct socfpga_gate_clk *socfpgaclk = to_socfpga_gate_clk(hwclk);
123+
u32 div = socfpga_clk_get_div(socfpgaclk);
124+
125+
req->rate = req->best_parent_rate / div;
126+
127+
return 0;
128+
}
129+
111130
static struct clk_ops gateclk_ops = {
112131
.recalc_rate = socfpga_clk_recalc_rate,
113-
.determine_rate = clk_hw_determine_rate_no_reparent,
132+
.determine_rate = socfpga_clk_determine_rate,
114133
.get_parent = socfpga_clk_get_parent,
115134
.set_parent = socfpga_clk_set_parent,
116135
};

0 commit comments

Comments
 (0)