From: brezillonboris@gmail.com (Boris BREZILLON)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v3 4/4] clk: at91: optimization of the set_rate callback
Date: Tue, 11 Mar 2014 10:00:35 +0100 [thread overview]
Message-ID: <1394528435-23734-5-git-send-email-b.brezillon.dev@gmail.com> (raw)
In-Reply-To: <1394528435-23734-1-git-send-email-b.brezillon.dev@gmail.com>
From: Jean-Jacques Hiblot <jjhiblot@traphandler.com>
Signed-off-by: Boris BREZILLON <b.brezillon@overkiz.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@traphandler.com>
---
drivers/clk/at91/clk-programmable.c | 38 ++++++++---------------------------
1 file changed, 8 insertions(+), 30 deletions(-)
diff --git a/drivers/clk/at91/clk-programmable.c b/drivers/clk/at91/clk-programmable.c
index 7bcc725..62e2509 100644
--- a/drivers/clk/at91/clk-programmable.c
+++ b/drivers/clk/at91/clk-programmable.c
@@ -139,43 +139,21 @@ static int clk_programmable_set_rate(struct clk_hw *hw, unsigned long rate,
struct clk_programmable *prog = to_clk_programmable(hw);
struct at91_pmc *pmc = prog->pmc;
const struct clk_programmable_layout *layout = prog->layout;
- unsigned long best_rate = parent_rate;
- unsigned long best_diff;
- unsigned long new_diff;
- unsigned long cur_rate;
+ unsigned long div = parent_rate / rate;
int shift = 0;
u32 tmp = pmc_read(pmc, AT91_PMC_PCKR(prog->id)) &
~(PROG_PRES_MASK << layout->pres_shift);
- if (rate > parent_rate)
- return parent_rate;
- else
- best_diff = parent_rate - rate;
+ if (!div)
+ return -EINVAL;
- if (!best_diff) {
- pmc_write(pmc, AT91_PMC_PCKR(prog->id), tmp | shift);
- return 0;
- }
-
- for (shift = 1; shift < PROG_PRES_MASK; shift++) {
- cur_rate = parent_rate >> shift;
-
- if (cur_rate > rate)
- new_diff = cur_rate - rate;
- else
- new_diff = rate - cur_rate;
-
- if (!new_diff)
- break;
+ shift = fls(div) - 1;
- if (new_diff < best_diff) {
- best_diff = new_diff;
- best_rate = cur_rate;
- }
+ if (div != (1<<shift))
+ return -EINVAL;
- if (rate > cur_rate)
- break;
- }
+ if (shift >= PROG_PRES_MASK)
+ return -EINVAL;
pmc_write(pmc, AT91_PMC_PCKR(prog->id),
tmp | (shift << layout->pres_shift));
--
1.7.9.5
WARNING: multiple messages have this Message-ID (diff)
From: Boris BREZILLON <brezillonboris@gmail.com>
To: Mike Turquette <mturquette@linaro.org>
Cc: Jean-Jacques Hiblot <jjhiblot@traphandler.com>,
Nicolas Ferre <nicolas.ferre@atmel.com>,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org,
Boris BREZILLON <b.brezillon@overkiz.com>
Subject: [PATCH v3 4/4] clk: at91: optimization of the set_rate callback
Date: Tue, 11 Mar 2014 10:00:35 +0100 [thread overview]
Message-ID: <1394528435-23734-5-git-send-email-b.brezillon.dev@gmail.com> (raw)
In-Reply-To: <1394528435-23734-1-git-send-email-b.brezillon.dev@gmail.com>
From: Jean-Jacques Hiblot <jjhiblot@traphandler.com>
Signed-off-by: Boris BREZILLON <b.brezillon@overkiz.com>
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@traphandler.com>
---
drivers/clk/at91/clk-programmable.c | 38 ++++++++---------------------------
1 file changed, 8 insertions(+), 30 deletions(-)
diff --git a/drivers/clk/at91/clk-programmable.c b/drivers/clk/at91/clk-programmable.c
index 7bcc725..62e2509 100644
--- a/drivers/clk/at91/clk-programmable.c
+++ b/drivers/clk/at91/clk-programmable.c
@@ -139,43 +139,21 @@ static int clk_programmable_set_rate(struct clk_hw *hw, unsigned long rate,
struct clk_programmable *prog = to_clk_programmable(hw);
struct at91_pmc *pmc = prog->pmc;
const struct clk_programmable_layout *layout = prog->layout;
- unsigned long best_rate = parent_rate;
- unsigned long best_diff;
- unsigned long new_diff;
- unsigned long cur_rate;
+ unsigned long div = parent_rate / rate;
int shift = 0;
u32 tmp = pmc_read(pmc, AT91_PMC_PCKR(prog->id)) &
~(PROG_PRES_MASK << layout->pres_shift);
- if (rate > parent_rate)
- return parent_rate;
- else
- best_diff = parent_rate - rate;
+ if (!div)
+ return -EINVAL;
- if (!best_diff) {
- pmc_write(pmc, AT91_PMC_PCKR(prog->id), tmp | shift);
- return 0;
- }
-
- for (shift = 1; shift < PROG_PRES_MASK; shift++) {
- cur_rate = parent_rate >> shift;
-
- if (cur_rate > rate)
- new_diff = cur_rate - rate;
- else
- new_diff = rate - cur_rate;
-
- if (!new_diff)
- break;
+ shift = fls(div) - 1;
- if (new_diff < best_diff) {
- best_diff = new_diff;
- best_rate = cur_rate;
- }
+ if (div != (1<<shift))
+ return -EINVAL;
- if (rate > cur_rate)
- break;
- }
+ if (shift >= PROG_PRES_MASK)
+ return -EINVAL;
pmc_write(pmc, AT91_PMC_PCKR(prog->id),
tmp | (shift << layout->pres_shift));
--
1.7.9.5
next prev parent reply other threads:[~2014-03-11 9:00 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-03-11 9:00 [PATCH v3 0/4] clk: at91: better support for the PCKs Boris BREZILLON
2014-03-11 9:00 ` Boris BREZILLON
2014-03-11 9:00 ` [PATCH v3 1/4] clk: at91: replace prog clk round_rate with determine_rate Boris BREZILLON
2014-03-11 9:00 ` Boris BREZILLON
2014-03-11 9:00 ` [PATCH v3 2/4] clk: at91: propagate rate change on system clks Boris BREZILLON
2014-03-11 9:00 ` Boris BREZILLON
2014-03-11 9:00 ` [PATCH v3 3/4] clk: at91: fix programmable clk irq handling Boris BREZILLON
2014-03-11 9:00 ` Boris BREZILLON
2014-03-11 9:00 ` Boris BREZILLON [this message]
2014-03-11 9:00 ` [PATCH v3 4/4] clk: at91: optimization of the set_rate callback Boris BREZILLON
2014-03-19 23:32 ` [PATCH v3 0/4] clk: at91: better support for the PCKs Mike Turquette
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=1394528435-23734-5-git-send-email-b.brezillon.dev@gmail.com \
--to=brezillonboris@gmail.com \
--cc=linux-arm-kernel@lists.infradead.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.