Skip to content

Commit ff553ea

Browse files
Boris BrezillonMichael Turquette
authored andcommitted
clk: at91: usb: fix at91rm9200 round and set rate
at91rm9200_clk_usb_set_rate might fail depending on the requested rate, because the parent_rate / rate remainder is not necessarily zero. Moreover, when rounding down the calculated rate we might alter the divisor calculation and end up with an invalid divisor. To solve those problems, accept a non zero remainder, and always round division to the closest result. Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com> Reported-by: Andreas Henriksson <andreas.henriksson@endian.se> Tested-by: Andreas Henriksson <andreas.henriksson@endian.se> Acked-by: Nicolas Ferre <nicolas.ferre@atmel.com> Signed-off-by: Michael Turquette <mturquette@linaro.org>
1 parent 206c5f6 commit ff553ea

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

‎drivers/clk/at91/clk-usb.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ static long at91rm9200_clk_usb_round_rate(struct clk_hw *hw, unsigned long rate,
253253

254254
tmp_parent_rate = rate * usb->divisors[i];
255255
tmp_parent_rate = __clk_round_rate(parent, tmp_parent_rate);
256-
tmprate = tmp_parent_rate / usb->divisors[i];
256+
tmprate = DIV_ROUND_CLOSEST(tmp_parent_rate, usb->divisors[i]);
257257
if (tmprate < rate)
258258
tmpdiff = rate - tmprate;
259259
else
@@ -281,10 +281,10 @@ static int at91rm9200_clk_usb_set_rate(struct clk_hw *hw, unsigned long rate,
281281
struct at91_pmc *pmc = usb->pmc;
282282
unsigned long div;
283283

284-
if (!rate || parent_rate % rate)
284+
if (!rate)
285285
return -EINVAL;
286286

287-
div = parent_rate / rate;
287+
div = DIV_ROUND_CLOSEST(parent_rate, rate);
288288

289289
for (i = 0; i < RM9200_USB_DIV_TAB_SIZE; i++) {
290290
if (usb->divisors[i] == div) {

0 commit comments

Comments
 (0)