public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Wenyou Yang <wenyou.yang@microchip.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 1/2] clk: at91: clk-generated: select absolute closest rate
Date: Fri, 17 Nov 2017 14:50:21 +0800	[thread overview]
Message-ID: <20171117065022.10609-2-wenyou.yang@microchip.com> (raw)
In-Reply-To: <20171117065022.10609-1-wenyou.yang@microchip.com>

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(-)

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;
-- 
2.13.0

  reply	other threads:[~2017-11-17  6:50 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-17  6:50 [U-Boot] [PATCH 0/2] clk: at91: clk-generated: Improvement Wenyou Yang
2017-11-17  6:50 ` Wenyou Yang [this message]
2017-11-30 15:35   ` [U-Boot] [U-Boot, 1/2] clk: at91: clk-generated: select absolute closest rate Tom Rini
2017-11-17  6:50 ` [U-Boot] [PATCH 2/2] clk: at91: clk-generated: fix incorrect index of clk source Wenyou Yang
2017-11-30 15:35   ` [U-Boot] [U-Boot, " Tom Rini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20171117065022.10609-2-wenyou.yang@microchip.com \
    --to=wenyou.yang@microchip.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox