diff mbox series

[U-Boot,1/2] clk: at91: clk-generated: select absolute closest rate

Message ID 20171117065022.10609-2-wenyou.yang@microchip.com
State Accepted
Commit eb1ed2b19befecdfeddb394e6174bb2198f2a49b
Delegated to: Tom Rini
Headers show
Series clk: at91: clk-generated: Improvement | expand

Commit Message

Wenyou Yang Nov. 17, 2017, 6:50 a.m. UTC
From: Ludovic Desroches <ludovic.desroches@microchip.com>

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 | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

Comments

Tom Rini Nov. 30, 2017, 3:35 p.m. UTC | #1
On Fri, Nov 17, 2017 at 02:50:21PM +0800, Wenyou Yang wrote:

> From: Ludovic Desroches <ludovic.desroches@microchip.com>
> 
> 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>

Applied to u-boot/master, thanks!
diff mbox series

Patch

diff --git a/drivers/clk/at91/clk-generated.c b/drivers/clk/at91/clk-generated.c
index 8c9a3cb053..461b5b2c9a 100644
--- a/drivers/clk/at91/clk-generated.c
+++ b/drivers/clk/at91/clk-generated.c
@@ -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;