linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: boris.brezillon@free-electrons.com (Boris Brezillon)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 2/2] clk: at91: usb: fix at91sam9x5 recalc, round and set rate
Date: Fri, 7 Nov 2014 18:58:35 +0100	[thread overview]
Message-ID: <20141107185835.1fd3871a@bbrezillon> (raw)
In-Reply-To: <20141107175139.GF4068@piout.net>

On Fri, 7 Nov 2014 18:51:39 +0100
Alexandre Belloni <alexandre.belloni@free-electrons.com> wrote:

> On 05/11/2014 at 10:33:15 +0100, Boris Brezillon wrote :
> > First check for rate == 0 in set_rate and round_rate to avoid div by zero.
> > Then, in order to get the closest rate, round all divisions to the closest
> > result instead of rounding them down.
> > 
> > Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
> > ---
> >  drivers/clk/at91/clk-usb.c | 29 +++++++++++++++++------------
> >  1 file changed, 17 insertions(+), 12 deletions(-)
> > 
> > diff --git a/drivers/clk/at91/clk-usb.c b/drivers/clk/at91/clk-usb.c
> > index 5b3b63c..7980e8c 100644
> > --- a/drivers/clk/at91/clk-usb.c
> > +++ b/drivers/clk/at91/clk-usb.c
> > @@ -52,7 +52,8 @@ static unsigned long at91sam9x5_clk_usb_recalc_rate(struct clk_hw *hw,
> >  
> >  	tmp = pmc_read(pmc, AT91_PMC_USB);
> >  	usbdiv = (tmp & AT91_PMC_OHCIUSBDIV) >> SAM9X5_USB_DIV_SHIFT;
> > -	return parent_rate / (usbdiv + 1);
> > +
> > +	return DIV_ROUND_CLOSEST(parent_rate, (usbdiv + 1));
> >  }
> >  
> >  static long at91sam9x5_clk_usb_round_rate(struct clk_hw *hw, unsigned long rate,
> > @@ -62,19 +63,19 @@ static long at91sam9x5_clk_usb_round_rate(struct clk_hw *hw, unsigned long rate,
> >  	unsigned long bestrate;
> >  	unsigned long tmp;
> >  
> > +	if (!rate)
> > +		return DIV_ROUND_CLOSEST(*parent_rate, SAM9X5_USB_MAX_DIV + 1);
> > +
> 
> Maybe I'm missing something but I would return -EINVAL here.

That's what I did at first, but just realized maybe 0 is a valid
request and we should try to be as close as possible to 0.

Anyway, I'm not really convinced we need that, so I can drop it.

> 
> >  	if (rate >= *parent_rate)
> >  		return *parent_rate;
> >  
> > -	div = *parent_rate / rate;
> > -	if (div >= SAM9X5_USB_MAX_DIV)
> > -		return *parent_rate / (SAM9X5_USB_MAX_DIV + 1);
> > +	div = DIV_ROUND_CLOSEST(*parent_rate, rate);
> > +	if (div > SAM9X5_USB_MAX_DIV + 1)
> > +		div = SAM9X5_USB_MAX_DIV + 1;
> > +	else if (!div)
> > +		div = 1;
> 
> In that case, you are also screwed, I would return -EINVAL.

Well, actually that cannot happen, because I already tested
rate >= *parent_rate.
I'll remove that line.



-- 
Boris Brezillon, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com

  reply	other threads:[~2014-11-07 17:58 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-05  9:33 [PATCH 0/2] clk: at91: usb: rate calculation fixes Boris Brezillon
2014-11-05  9:33 ` [PATCH 1/2] clk: at91: usb: fix at91rm9200 round and set rate Boris Brezillon
2014-11-05 13:12   ` Andreas Henriksson
2014-11-05  9:33 ` [PATCH 2/2] clk: at91: usb: fix at91sam9x5 recalc, " Boris Brezillon
2014-11-07 17:51   ` Alexandre Belloni
2014-11-07 17:58     ` Boris Brezillon [this message]
2014-11-05 17:13 ` [PATCH 0/2] clk: at91: usb: rate calculation fixes Nicolas Ferre
2014-11-05 18:12   ` Boris Brezillon
2014-11-13 10:59 ` Nicolas Ferre
2014-11-14 18:12   ` 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=20141107185835.1fd3871a@bbrezillon \
    --to=boris.brezillon@free-electrons.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).