public inbox for linux-mmc@vger.kernel.org
 help / color / mirror / Atom feed
From: Simon Horman <horms@verge.net.au>
To: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
Cc: linux-mmc@vger.kernel.org, Chris Ball <cjb@laptop.org>,
	Magnus Damm <magnus.damm@gmail.com>,
	Paul Mundt <lethal@linux-sh.org>,
	Cao Minh Hiep <hiepcm@gmail.com>
Subject: Re: [PATCH 1/2] mmc: sh_mmcif: double clock speed
Date: Mon, 26 Mar 2012 11:21:54 +0900	[thread overview]
Message-ID: <20120326022154.GB6860@verge.net.au> (raw)
In-Reply-To: <Pine.LNX.4.64.1203241845060.19427@axis700.grange>

On Sat, Mar 24, 2012 at 06:56:16PM +0100, Guennadi Liakhovetski wrote:
> Hi Simon
> 
> On Wed, 21 Mar 2012, Simon Horman wrote:
> 
> > This corrects an off-by one error when calculating the clock divisor.
> > The code previously assumed that for example a divisor of 2 is
> > set using a value of 0001 (the inverse of 1/2), a divisor of 4 is
> > set using a value of 0010 (the inverse of 1/4) etc.. However, the correct
> > values are 0000, 0001, etc...
> > 
> > The use of DIV_ROUND_UP() was suggested by Guennadi Liakhovetski to avoid
> > understating the divisor by one in the case where the host clock is not a
> > binary power of the MMCIF clock.
> 
> The patch looks good, but the commit message is not quite right. Cases of 
> host->clk / clk != 2^n are handled by using fls(x - 1) instead of fls(x) - 
> 1, as you initially suggested. DIV_ROUND_UP() is needed for divisions with 
> a residue. E.g., for host clock 13MHz, target clock 3MHz you want a 
> divisor of 5, resulting in 2 << 16, not 4, resulting in 1 << 16. With this 
> fixed
> 
> Acked-by: Guennadi Liakhovetski <g.liakhovetski@gmx.de>

Hi Guennadi, how about this?:

Correct an off-by one error when calculating the clock divisor in cases
where the host clock is a power of two of the target clock.  Previously the
divisor was one greater than the correct value in these cases leading to
the clock being set at half the desired speed.

Thanks to Guennadi Liakhovetski for working with me on
the logic for this change.

> > The use of DIV_ROUND_UP() was suggested by Guennadi Liakhovetski to avoid
> > understating the divisor by one in the case where the host clock is not a
> > binary power of the MMCIF clock.
> 
> The patch looks good, but the commit message is not quite right. Cases of 
> host->clk / clk != 2^n are handled by using fls(x - 1) instead of fls(x) - 
> 1, as you initially suggested. DIV_ROUND_UP() is needed for divisions with 
> a residue. E.g., for host clock 13MHz, target clock 3MHz you want a 
> divisor of 5, resulting in 2 << 16, not 4, resulting in 1 << 16. With this 
> fixed
> 
> Acked-by: Guennadi Liakhovetski <g.liakhovetski@gmx.de>

> Thanks
> Guennadi
> 
> > 
> > Cc: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
> > Tested-by: Cao Minh Hiep <hiepcm@gmail.com>
> > Signed-off-by: Simon Horman <horms@verge.net.au>
> > ---
> >  drivers/mmc/host/sh_mmcif.c |    3 ++-
> >  1 files changed, 2 insertions(+), 1 deletions(-)
> > 
> > diff --git a/drivers/mmc/host/sh_mmcif.c b/drivers/mmc/host/sh_mmcif.c
> > index 8057bf3..5014bc4 100644
> > --- a/drivers/mmc/host/sh_mmcif.c
> > +++ b/drivers/mmc/host/sh_mmcif.c
> > @@ -453,7 +453,8 @@ static void sh_mmcif_clock_control(struct sh_mmcif_host *host, unsigned int clk)
> >  		sh_mmcif_bitset(host, MMCIF_CE_CLK_CTRL, CLK_SUP_PCLK);
> >  	else
> >  		sh_mmcif_bitset(host, MMCIF_CE_CLK_CTRL, CLK_CLEAR &
> > -				((fls(host->clk / clk) - 1) << 16));
> > +				((fls(DIV_ROUND_UP(host->clk,
> > +						   clk) - 1) - 1) << 16));
> >  
> >  	sh_mmcif_bitset(host, MMCIF_CE_CLK_CTRL, CLK_ENABLE);
> >  }
> > -- 
> > 1.7.6.3
> > 
> 
> ---
> Guennadi Liakhovetski, Ph.D.
> Freelance Open-Source Software Developer
> http://www.open-technology.de/
> 

  reply	other threads:[~2012-03-26  2:21 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-21  9:02 [PATCH 0/2] MMCIF Clock Fixes Simon Horman
2012-03-21  9:02 ` [PATCH 1/2] mmc: sh_mmcif: double clock speed Simon Horman
2012-03-24 17:56   ` Guennadi Liakhovetski
2012-03-26  2:21     ` Simon Horman [this message]
2012-03-21  9:02 ` [PATCH 2/2] mmc: sh_mmcif: mmc->f_max should be half of the bus clock Simon Horman
2012-03-24 18:06   ` Guennadi Liakhovetski
     [not found]     ` <20120325223033.GA6860@verge.net.au>
2012-03-26  5:45       ` Yusuke Goda
2012-03-26  5:52         ` Simon Horman
2012-03-26  6:04           ` Yusuke Goda
2012-03-26  6:17           ` Magnus Damm
2012-03-26  7:04             ` Guennadi Liakhovetski
2012-03-27  7:53               ` Guennadi Liakhovetski
2012-03-27  8:14                 ` Simon Horman
2012-03-27  1:43             ` Simon Horman
2012-03-27  2:46               ` Magnus Damm
2012-03-27  3:20                 ` Chris Ball
2012-03-27  4:02                   ` Magnus Damm
2012-03-27  6:01                     ` Simon Horman
2012-03-27  6:37                       ` Magnus Damm
2012-03-27  7:12                         ` Simon Horman

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=20120326022154.GB6860@verge.net.au \
    --to=horms@verge.net.au \
    --cc=cjb@laptop.org \
    --cc=g.liakhovetski@gmx.de \
    --cc=hiepcm@gmail.com \
    --cc=lethal@linux-sh.org \
    --cc=linux-mmc@vger.kernel.org \
    --cc=magnus.damm@gmail.com \
    /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