From: Wolfram Sang <w.sang@pengutronix.de>
To: Koen Beel <koen.beel.barco@gmail.com>
Cc: Shawn Guo <shawn.guo@freescale.com>, linux-mmc@vger.kernel.org
Subject: Re: [PATCH] mxs-mmc: fix clock rate setting
Date: Wed, 6 Jul 2011 11:38:48 +0200 [thread overview]
Message-ID: <20110706093848.GC2117@pengutronix.de> (raw)
In-Reply-To: <CAHMSPgMxCqFzigAzMc7nbTB_0NyLcK3FrVDW8arKa0ip15TH3Q@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 3217 bytes --]
On Mon, Jul 04, 2011 at 12:59:29PM +0200, Koen Beel wrote:
> On Mon, Jul 4, 2011 at 12:34 PM, Wolfram Sang <w.sang@pengutronix.de> wrote:
> >
> >> > > > Well, maybe not. My colleague complained and I think he is right that we are
> >> > > > mapping div2 from the range 0 to 256 (inclusive!) to an 8-bit range. This must
> >> > > > be wrong for one value per se.
> >> > > >
> >> > > If you look at the context of the patch, you will find it's 'div2 - 1'
> >> > > than 'div2' gets written into register.
> >> >
> >> > Exactly. The '- 1' is why Koen changed the upper limit from < 256 to <= 256.
> >> > The lower limit fix is currently 'if (div2 == 0) div2 == 1', which is a 2:1
> >> > mapping. Not good, or?
> >> >
> >> So you are saying the patch is a right fix but not the most optimal
> >> one? In that case, it does not concern me. I acked it as an valid
> >> fix.
> >
> > The patches fixes a few things, but for div2, it is curing the symptoms,
> > not the cause, I think. If you look at the formula in the datasheet:
> >
> > rate = ssp / (clock_divide * (1 + clock_rate));
> >
> > In the code, the calculation of div2 is equal to '1 + clock_rate' (the 1
> > gets subtracted when the value is written to the register which is a bit
> > unfortunate; doing it earlier would reduce confusion IMO). So that can
> > never be 0, it is a divisor. We should really use DIV_ROUND_UP here.
> > Even when not dealing with 0, this seems needed. Assume:
> >
> > ssp = 57600000, wanted_rate = 25000000, div1 = 2
> >
> > will give
> >
> > div2 = int(1.152) = 1 (meaning 0 + 1, because div2 - 1 will be written)
> >
> > The rate will thus be:
> >
> > actual_rate = 57600000 / 2 * (0 + 1)
> > = 28800000
> >
> > -> too fast!
> >
> > Or did I get something wrong?
> >
> > Regards,
> >
> > Wolfram
>
> Well, right now the clock freq. is set to the minimum clock value
> reaching the requested rate.
Sorry, it gets a bit confusing: what do you mean with "right now"?
> In current implementation, the rate will
> be higher in lot's of cases (all cases where the requested clock freq.
> cannot exactly be made).
Yes.
> But the thing is, the driver now enters dev_err, and returns without
> changing anything when the clock cannot be made as low as requested.
> In that case you will almost certainly end up with a clock being even
> higher then the lowest possible. So that not good I think.
> I might be better to set the clock as low as possible not matter what
> you to after that.
Yes, might be a bit academic (who would want 4kHz ;)), but still
correct. Shawn, do you agree?
> About the rounding. I don't think rounding is good. I think it would
We do rounding already (int conversion). Just in the wrong direction.
> be better to choose between having at least the requested rate (as it
> is now; will result is somewhat higher clock then requested in many
> cases)
You want a rate faster than what the card could do?
>, or having at maximum the requested clock rate. Both have there
> problems.
If I understood you correctly, this is my DIV_ROUND_UP suggestion. Which
problems does it have?
Regards,
Wolfram
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]
next prev parent reply other threads:[~2011-07-06 9:38 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <BANLkTi==Y_MJ2H_u15DzunWusUb=GsotWg@mail.gmail.com>
2011-06-30 10:13 ` [PATCH] mxs-mmc: fix clock rate setting Koen Beel
2011-06-30 14:55 ` Wolfram Sang
2011-07-01 9:17 ` Wolfram Sang
2011-07-01 11:41 ` Sachin Nikam
2011-07-01 14:38 ` Sachin Nikam
2011-07-01 14:46 ` Wolfram Sang
2011-07-01 12:10 ` Koen Beel
2011-07-01 12:27 ` Wolfram Sang
2011-07-01 13:26 ` Koen Beel
2011-07-01 14:44 ` Wolfram Sang
2011-07-01 15:46 ` Shawn Guo
2011-07-02 13:12 ` Wolfram Sang
2011-07-03 9:28 ` Shawn Guo
2011-07-03 10:31 ` Wolfram Sang
2011-07-03 11:54 ` Shawn Guo
2011-07-04 10:34 ` Wolfram Sang
2011-07-04 10:59 ` Koen Beel
2011-07-06 9:38 ` Wolfram Sang [this message]
2011-07-06 9:53 ` Koen Beel
2011-07-06 9:58 ` Wolfram Sang
2011-07-04 10:37 ` Koen Beel
2011-07-04 11:01 ` Koen Beel
2011-07-06 9:26 ` Wolfram Sang
2011-07-09 21:04 ` Chris Ball
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=20110706093848.GC2117@pengutronix.de \
--to=w.sang@pengutronix.de \
--cc=koen.beel.barco@gmail.com \
--cc=linux-mmc@vger.kernel.org \
--cc=shawn.guo@freescale.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