linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: b.brezillon@overkiz.com (Boris BREZILLON)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v2 4/4] clk: at91: optimization of the determine_rate callback
Date: Wed, 05 Feb 2014 09:54:42 +0100	[thread overview]
Message-ID: <52F1FC52.1040205@overkiz.com> (raw)
In-Reply-To: <1391589458-28018-5-git-send-email-jjhiblot@traphandler.com>

Hi JJ,

I guess you're commit message is wrong: you're optimizing set_rate not 
determine_rate.

Best Regards,

Boris

On 05/02/2014 09:37, Jean-Jacques Hiblot wrote:
> 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));

  reply	other threads:[~2014-02-05  8:54 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-05  8:37 [PATCH v2 0/4] clk: at91: better support for the PCKs Jean-Jacques Hiblot
2014-02-05  8:37 ` [PATCH v2 1/4] clk: at91: replace prog clk round_rate with determine_rate Jean-Jacques Hiblot
2014-02-05  8:37 ` [PATCH v2 2/4] clk: at91: propagate rate change on system clks Jean-Jacques Hiblot
2014-02-27  0:42   ` Mike Turquette
2014-02-27  8:16     ` Boris BREZILLON
2014-02-05  8:37 ` [PATCH v2 3/4] clk: at91: fix programmable clk irq handling Jean-Jacques Hiblot
2014-02-05  8:37 ` [PATCH v2 4/4] clk: at91: optimization of the determine_rate callback Jean-Jacques Hiblot
2014-02-05  8:54   ` Boris BREZILLON [this message]
2014-02-17 15:24     ` [PATCH v2] clk: at91: optimization of the set_rate callback Jean-Jacques Hiblot

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=52F1FC52.1040205@overkiz.com \
    --to=b.brezillon@overkiz.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).