* [PATCH] DaVinci SPI: Fix SPI clock prescale factor computation
[not found] ` <871veaksca.fsf-1D3HCaltpLuhEniVeURVKkEOCMrvLtNR@public.gmane.org>
@ 2010-04-26 9:01 ` thomas.koeller-x9WYMywdo8BF6kxbq+BtvQ
2010-04-26 9:01 ` thomas.koeller-x9WYMywdo8BF6kxbq+BtvQ
1 sibling, 0 replies; 4+ messages in thread
From: thomas.koeller-x9WYMywdo8BF6kxbq+BtvQ @ 2010-04-26 9:01 UTC (permalink / raw)
To: davinci-linux-open-source-VycZQUHpC/Nq7ICLvS4PUAC/G2K4zDHf,
spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f
Cc: Kevin Hilman
[PATCH] DaVinci SPI: Fix SPI clock prescale factor computation
------------------------------------------------------------------------------
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH] DaVinci SPI: Fix SPI clock prescale factor computation
[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>
1 sibling, 1 reply; 4+ messages in thread
From: thomas.koeller-x9WYMywdo8BF6kxbq+BtvQ @ 2010-04-26 9:01 UTC (permalink / raw)
To: davinci-linux-open-source-VycZQUHpC/Nq7ICLvS4PUAC/G2K4zDHf,
spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f
Cc: Sudhakar Rajashekhara, Kevin Hilman, Thomas Koeller,
Sandeep Paulraj, Philby John
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;
clear_fmt_bits(davinci_spi->base, 0x0000ff00, spi->chip_select);
- set_fmt_bits(davinci_spi->base, prescale << 8, spi->chip_select);
+ set_fmt_bits(davinci_spi->base, prescale, spi->chip_select);
return 0;
}
--
1.7.0.3
------------------------------------------------------------------------------
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] DaVinci SPI: Fix SPI clock prescale factor computation
[not found] ` <1272272505-5021-2-git-send-email-thomas.koeller-x9WYMywdo8BF6kxbq+BtvQ@public.gmane.org>
@ 2010-04-26 15:06 ` Grant Likely
[not found] ` <k2zfa686aa41004260806r691e1880i2a80b102c108be5a-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
0 siblings, 1 reply; 4+ messages in thread
From: Grant Likely @ 2010-04-26 15:06 UTC (permalink / raw)
To: thomas.koeller-x9WYMywdo8BF6kxbq+BtvQ
Cc: Sudhakar Rajashekhara, Kevin Hilman, Sandeep Paulraj, Philby John,
spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f,
davinci-linux-open-source-VycZQUHpC/Nq7ICLvS4PUAC/G2K4zDHf
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.
------------------------------------------------------------------------------
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH] DaVinci SPI: Fix SPI clock prescale factor computation
[not found] ` <k2zfa686aa41004260806r691e1880i2a80b102c108be5a-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2010-05-31 14:33 ` thomas.koeller-x9WYMywdo8BF6kxbq+BtvQ
0 siblings, 0 replies; 4+ messages in thread
From: thomas.koeller-x9WYMywdo8BF6kxbq+BtvQ @ 2010-05-31 14:33 UTC (permalink / raw)
To: spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f; +Cc: Thomas Koeller
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..5c69d78 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, 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 (WARN_ON(hz > clkspeed / 2))
+ prescale = 1 << 8;
+ else if (WARN_ON(hz < clkspeed / 256))
+ prescale = 255 << 8;
+ else
+ prescale = ((clkspeed / hz - 1) << 8) & 0x0000ff00;
clear_fmt_bits(davinci_spi->base, 0x0000ff00, spi->chip_select);
- set_fmt_bits(davinci_spi->base, prescale << 8, spi->chip_select);
+ set_fmt_bits(davinci_spi->base, prescale, spi->chip_select);
return 0;
}
--
1.7.0.3
------------------------------------------------------------------------------
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2010-05-31 14:33 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[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
[not found] ` <k2zfa686aa41004260806r691e1880i2a80b102c108be5a-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-05-31 14:33 ` thomas.koeller-x9WYMywdo8BF6kxbq+BtvQ
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).