Commit 5585f731 authored by Dinh Nguyen's avatar Dinh Nguyen Committed by Mike Turquette

clk: socfpga: Fix integer overflow in clock calculation

Use 64-bit integer for calculating clock rate. Also use do_div for the
64-bit division.
Signed-off-by: default avatarGraham Moore <grmoore@altera.com>
Signed-off-by: default avatarDinh Nguyen <dinguyen@altera.com>
Cc: Steffen Trumtrar <s.trumtrar@pengutronix.de>
Signed-off-by: default avatarMike Turquette <mturquette@linaro.org>
parent 2c97ec58
...@@ -44,7 +44,8 @@ static unsigned long clk_pll_recalc_rate(struct clk_hw *hwclk, ...@@ -44,7 +44,8 @@ static unsigned long clk_pll_recalc_rate(struct clk_hw *hwclk,
unsigned long parent_rate) unsigned long parent_rate)
{ {
struct socfpga_pll *socfpgaclk = to_socfpga_clk(hwclk); struct socfpga_pll *socfpgaclk = to_socfpga_clk(hwclk);
unsigned long divf, divq, vco_freq, reg; unsigned long divf, divq, reg;
unsigned long long vco_freq;
unsigned long bypass; unsigned long bypass;
reg = readl(socfpgaclk->hw.reg); reg = readl(socfpgaclk->hw.reg);
...@@ -54,8 +55,9 @@ static unsigned long clk_pll_recalc_rate(struct clk_hw *hwclk, ...@@ -54,8 +55,9 @@ static unsigned long clk_pll_recalc_rate(struct clk_hw *hwclk,
divf = (reg & SOCFPGA_PLL_DIVF_MASK) >> SOCFPGA_PLL_DIVF_SHIFT; divf = (reg & SOCFPGA_PLL_DIVF_MASK) >> SOCFPGA_PLL_DIVF_SHIFT;
divq = (reg & SOCFPGA_PLL_DIVQ_MASK) >> SOCFPGA_PLL_DIVQ_SHIFT; divq = (reg & SOCFPGA_PLL_DIVQ_MASK) >> SOCFPGA_PLL_DIVQ_SHIFT;
vco_freq = parent_rate * (divf + 1); vco_freq = (unsigned long long)parent_rate * (divf + 1);
return vco_freq / (1 + divq); do_div(vco_freq, (1 + divq));
return (unsigned long)vco_freq;
} }
static struct clk_ops clk_pll_ops = { static struct clk_ops clk_pll_ops = {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment