Skip to content

Commit

Permalink
rtc: m41t80: fix m41t80_sqw_round_rate return value
Browse files Browse the repository at this point in the history
Previously it was returning the best of
32768, 8192, 1024, 64, 2, 0

Now, best of
32768, 8192, 4096, 2048, 1024, 512, 256, 128,
64, 32, 16, 8, 4, 2, 1, 0

Signed-off-by: Troy Kisky <[email protected]>
Signed-off-by: Alexandre Belloni <[email protected]>
  • Loading branch information
tkisky authored and alexandrebelloni committed Nov 8, 2017
1 parent de6042d commit c8384bb
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions drivers/rtc/rtc-m41t80.c
Original file line number Diff line number Diff line change
Expand Up @@ -468,18 +468,13 @@ static unsigned long m41t80_sqw_recalc_rate(struct clk_hw *hw,
static long m41t80_sqw_round_rate(struct clk_hw *hw, unsigned long rate,
unsigned long *prate)
{
int i, freq = M41T80_SQW_MAX_FREQ;

if (freq <= rate)
return freq;

for (i = 2; i <= ilog2(M41T80_SQW_MAX_FREQ); i++) {
freq /= 1 << i;
if (freq <= rate)
return freq;
}

return 0;
if (rate >= M41T80_SQW_MAX_FREQ)
return M41T80_SQW_MAX_FREQ;
if (rate >= M41T80_SQW_MAX_FREQ / 4)
return M41T80_SQW_MAX_FREQ / 4;
if (!rate)
return 0;
return 1 << ilog2(rate);
}

static int m41t80_sqw_set_rate(struct clk_hw *hw, unsigned long rate,
Expand Down

0 comments on commit c8384bb

Please sign in to comment.