Skip to content

Commit 063578d

Browse files
larsclausenbebarino
authored andcommitted
clk: axi-clkgen: Correctly handle nocount bit in recalc_rate()
If the nocount bit is set the divider is bypassed and the settings for the divider count should be ignored and a divider value of 1 should be assumed. Handle this correctly in the driver recalc_rate() callback. While the driver sets up the part so that the read back dividers values yield the correct result the power-on reset settings of the part might not reflect this and hence calling e.g. clk_get_rate() without prior calls to clk_set_rate() will yield the wrong result. Signed-off-by: Lars-Peter Clausen <lars@metafoo.de> Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
1 parent 4fbd8d1 commit 063578d

1 file changed

Lines changed: 24 additions & 5 deletions

File tree

‎drivers/clk/clk-axi-clkgen.c‎

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@
4040
#define MMCM_REG_FILTER1 0x4e
4141
#define MMCM_REG_FILTER2 0x4f
4242

43+
#define MMCM_CLKOUT_NOCOUNT BIT(6)
44+
45+
#define MMCM_CLK_DIV_NOCOUNT BIT(12)
46+
4347
struct axi_clkgen {
4448
void __iomem *base;
4549
struct clk_hw clk_hw;
@@ -315,12 +319,27 @@ static unsigned long axi_clkgen_recalc_rate(struct clk_hw *clk_hw,
315319
unsigned int reg;
316320
unsigned long long tmp;
317321

318-
axi_clkgen_mmcm_read(axi_clkgen, MMCM_REG_CLKOUT0_1, &reg);
319-
dout = (reg & 0x3f) + ((reg >> 6) & 0x3f);
322+
axi_clkgen_mmcm_read(axi_clkgen, MMCM_REG_CLKOUT0_2, &reg);
323+
if (reg & MMCM_CLKOUT_NOCOUNT) {
324+
dout = 1;
325+
} else {
326+
axi_clkgen_mmcm_read(axi_clkgen, MMCM_REG_CLKOUT0_1, &reg);
327+
dout = (reg & 0x3f) + ((reg >> 6) & 0x3f);
328+
}
329+
320330
axi_clkgen_mmcm_read(axi_clkgen, MMCM_REG_CLK_DIV, &reg);
321-
d = (reg & 0x3f) + ((reg >> 6) & 0x3f);
322-
axi_clkgen_mmcm_read(axi_clkgen, MMCM_REG_CLK_FB1, &reg);
323-
m = (reg & 0x3f) + ((reg >> 6) & 0x3f);
331+
if (reg & MMCM_CLK_DIV_NOCOUNT)
332+
d = 1;
333+
else
334+
d = (reg & 0x3f) + ((reg >> 6) & 0x3f);
335+
336+
axi_clkgen_mmcm_read(axi_clkgen, MMCM_REG_CLK_FB2, &reg);
337+
if (reg & MMCM_CLKOUT_NOCOUNT) {
338+
m = 1;
339+
} else {
340+
axi_clkgen_mmcm_read(axi_clkgen, MMCM_REG_CLK_FB1, &reg);
341+
m = (reg & 0x3f) + ((reg >> 6) & 0x3f);
342+
}
324343

325344
if (d == 0 || dout == 0)
326345
return 0;

0 commit comments

Comments
 (0)