From: Grant Likely <grant.likely-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org>
To: thomas.koeller-x9WYMywdo8BF6kxbq+BtvQ@public.gmane.org
Cc: Sudhakar Rajashekhara <sudhakar.raj-l0cyMroinI0@public.gmane.org>,
Kevin Hilman
<khilman-1D3HCaltpLuhEniVeURVKkEOCMrvLtNR@public.gmane.org>,
Sandeep Paulraj <s-paulraj-l0cyMroinI0@public.gmane.org>,
Philby John <pjohn-k0rHJ+Hhz/SB+jHODAdFcQ@public.gmane.org>,
spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org,
davinci-linux-open-source-VycZQUHpC/Nq7ICLvS4PUAC/G2K4zDHf@public.gmane.org
Subject: Re: [PATCH] DaVinci SPI: Fix SPI clock prescale factor computation
Date: Mon, 26 Apr 2010 09:06:11 -0600 [thread overview]
Message-ID: <k2zfa686aa41004260806r691e1880i2a80b102c108be5a@mail.gmail.com> (raw)
In-Reply-To: <1272272505-5021-2-git-send-email-thomas.koeller-x9WYMywdo8BF6kxbq+BtvQ@public.gmane.org>
On Mon, Apr 26, 2010 at 3:01 AM, <thomas.koeller-x9WYMywdo8BF6kxbq+BtvQ@public.gmane.org> wrote:
> From: Thomas Koeller <thomas.koeller-x9WYMywdo8BF6kxbq+BtvQ@public.gmane.org>
>
> Computation of the clock prescaler value returned bogus results if
> the requested SPI clock was impossible to set. It now sets either
> the maximum or minimum clock frequency, as appropriate.
>
> Signed-off-by: Thomas Koeller <thomas.koeller-x9WYMywdo8BF6kxbq+BtvQ@public.gmane.org>
> ---
> drivers/spi/davinci_spi.c | 12 +++++++++---
> 1 files changed, 9 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/spi/davinci_spi.c b/drivers/spi/davinci_spi.c
> index 956f617..02e1a76 100644
> --- a/drivers/spi/davinci_spi.c
> +++ b/drivers/spi/davinci_spi.c
> @@ -153,7 +153,7 @@ static int davinci_spi_setup_transfer(struct spi_device *spi,
> struct davinci_spi *davinci_spi;
> struct davinci_spi_platform_data *pdata;
> u8 bits_per_word = 0;
> - u32 hz = 0, prescale;
> + u32 hz = 0, prescale = 0, clkspeed;
>
> davinci_spi = spi_master_get_devdata(spi->master);
> pdata = davinci_spi->pdata;
> @@ -190,10 +190,16 @@ static int davinci_spi_setup_transfer(struct spi_device *spi,
> set_fmt_bits(davinci_spi->base, bits_per_word & 0x1f,
> spi->chip_select);
>
> - prescale = ((clk_get_rate(davinci_spi->clk) / hz) - 1) & 0xff;
> + clkspeed = clk_get_rate(davinci_spi->clk);
> + if (hz > clkspeed / 2)
> + prescale = 1 << 8;
> + if (hz < clkspeed / 256)
> + prescale = 255 << 8;
> + if (!prescale)
> + prescale = ((clkspeed / hz - 1) << 8) & 0x0000ff00;
Is be appropriate to WARN_ON() or WARN_ONCE() when the clamp condition
occurs? Particularly the condition where the minimum clock speed is
higher that the requested clock.
I'd also consider an if / else if / else structure for readability and clarity.
g.
------------------------------------------------------------------------------
next prev parent reply other threads:[~2010-04-26 15:06 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <871veaksca.fsf@deeprootsystems.com>
[not found] ` <871veaksca.fsf-1D3HCaltpLuhEniVeURVKkEOCMrvLtNR@public.gmane.org>
2010-04-26 9:01 ` [PATCH] DaVinci SPI: Fix SPI clock prescale factor computation thomas.koeller-x9WYMywdo8BF6kxbq+BtvQ
2010-04-26 9:01 ` thomas.koeller-x9WYMywdo8BF6kxbq+BtvQ
[not found] ` <1272272505-5021-2-git-send-email-thomas.koeller-x9WYMywdo8BF6kxbq+BtvQ@public.gmane.org>
2010-04-26 15:06 ` Grant Likely [this message]
[not found] ` <k2zfa686aa41004260806r691e1880i2a80b102c108be5a-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-05-31 14:33 ` thomas.koeller-x9WYMywdo8BF6kxbq+BtvQ
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=k2zfa686aa41004260806r691e1880i2a80b102c108be5a@mail.gmail.com \
--to=grant.likely-s3s/wqlpoipyb63q8fvjnq@public.gmane.org \
--cc=davinci-linux-open-source-VycZQUHpC/Nq7ICLvS4PUAC/G2K4zDHf@public.gmane.org \
--cc=khilman-1D3HCaltpLuhEniVeURVKkEOCMrvLtNR@public.gmane.org \
--cc=pjohn-k0rHJ+Hhz/SB+jHODAdFcQ@public.gmane.org \
--cc=s-paulraj-l0cyMroinI0@public.gmane.org \
--cc=spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org \
--cc=sudhakar.raj-l0cyMroinI0@public.gmane.org \
--cc=thomas.koeller-x9WYMywdo8BF6kxbq+BtvQ@public.gmane.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).