]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
clk: at91: clk-generated: select absolute closest rate
authorLudovic Desroches <ludovic.desroches@microchip.com>
Fri, 17 Nov 2017 06:50:21 +0000 (14:50 +0800)
committerTom Rini <trini@konsulko.com>
Thu, 30 Nov 2017 03:30:50 +0000 (22:30 -0500)
To get the same behavior as the Linux driver, instead of selecting
the closest inferior rate, select the closest inferior or superior
rate

Signed-off-by: Ludovic Desroches <ludovic.desroches@microchip.com>
Signed-off-by: Wenyou Yang <wenyou.yang@microchip.com>
drivers/clk/at91/clk-generated.c

index 8c9a3cb053aa041db211c24b577169ce7960c429..461b5b2c9ad3da263fe9b544f3b475a3a582a069 100644 (file)
@@ -98,9 +98,7 @@ static ulong generic_clk_set_rate(struct clk *clk, ulong rate)
 
                for (div = 1; div < GENERATED_MAX_DIV + 2; div++) {
                        tmp_rate = DIV_ROUND_CLOSEST(parent_rate, div);
-                       if (rate < tmp_rate)
-                               continue;
-                       tmp_diff = rate - tmp_rate;
+                       tmp_diff = abs(rate - tmp_rate);
 
                        if (best_diff < 0 || best_diff > tmp_diff) {
                                best_rate = tmp_rate;