* [PATCH] spi: rspi: Round up division to avoid slave overclocking
@ 2014-05-22 18:07 Geert Uytterhoeven
2014-05-26 1:41 ` Simon Horman
[not found] ` <1400782055-19609-1-git-send-email-geert+renesas-gXvu3+zWzMSzQB+pC5nmwQ@public.gmane.org>
0 siblings, 2 replies; 3+ messages in thread
From: Geert Uytterhoeven @ 2014-05-22 18:07 UTC (permalink / raw)
To: Mark Brown, Simon Horman
Cc: linux-spi-u79uwXL29TY76Z2rM5mHXA, linux-sh-u79uwXL29TY76Z2rM5mHXA,
linux-kernel-u79uwXL29TY76Z2rM5mHXA, Geert Uytterhoeven
The calculation of the bit rate divider used a standard C division, which
rounds down the quotient. This may lead to a higher bitrate than requested.
Round up to avoid this.
E.g. on Koelsch, the SPI flash (configured for 30 MHz) was driven at 48.75
MHz. After this patch it's driven at a safe 24.375 MHz.
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
Simon: I think you want this in renesas-backports.
drivers/spi/spi-rspi.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/drivers/spi/spi-rspi.c b/drivers/spi/spi-rspi.c
index 1fb0ad213324..5639f9529e0b 100644
--- a/drivers/spi/spi-rspi.c
+++ b/drivers/spi/spi-rspi.c
@@ -266,7 +266,8 @@ static int rspi_set_config_register(struct rspi_data *rspi, int access_size)
rspi_write8(rspi, rspi->sppcr, RSPI_SPPCR);
/* Sets transfer bit rate */
- spbr = clk_get_rate(rspi->clk) / (2 * rspi->max_speed_hz) - 1;
+ spbr = DIV_ROUND_UP(clk_get_rate(rspi->clk),
+ 2 * rspi->max_speed_hz) - 1;
rspi_write8(rspi, clamp(spbr, 0, 255), RSPI_SPBR);
/* Disable dummy transmission, set 16-bit word access, 1 frame */
@@ -302,7 +303,8 @@ static int rspi_rz_set_config_register(struct rspi_data *rspi, int access_size)
rspi_write8(rspi, rspi->sppcr, RSPI_SPPCR);
/* Sets transfer bit rate */
- spbr = clk_get_rate(rspi->clk) / (2 * rspi->max_speed_hz) - 1;
+ spbr = DIV_ROUND_UP(clk_get_rate(rspi->clk),
+ 2 * rspi->max_speed_hz) - 1;
rspi_write8(rspi, clamp(spbr, 0, 255), RSPI_SPBR);
/* Disable dummy transmission, set byte access */
@@ -335,7 +337,7 @@ static int qspi_set_config_register(struct rspi_data *rspi, int access_size)
rspi_write8(rspi, rspi->sppcr, RSPI_SPPCR);
/* Sets transfer bit rate */
- spbr = clk_get_rate(rspi->clk) / (2 * rspi->max_speed_hz);
+ spbr = DIV_ROUND_UP(clk_get_rate(rspi->clk), 2 * rspi->max_speed_hz);
rspi_write8(rspi, clamp(spbr, 0, 255), RSPI_SPBR);
/* Disable dummy transmission, set byte access */
--
1.9.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] spi: rspi: Round up division to avoid slave overclocking
2014-05-22 18:07 [PATCH] spi: rspi: Round up division to avoid slave overclocking Geert Uytterhoeven
@ 2014-05-26 1:41 ` Simon Horman
[not found] ` <1400782055-19609-1-git-send-email-geert+renesas-gXvu3+zWzMSzQB+pC5nmwQ@public.gmane.org>
1 sibling, 0 replies; 3+ messages in thread
From: Simon Horman @ 2014-05-26 1:41 UTC (permalink / raw)
To: Geert Uytterhoeven; +Cc: Mark Brown, linux-spi, linux-sh, linux-kernel
On Thu, May 22, 2014 at 08:07:35PM +0200, Geert Uytterhoeven wrote:
> The calculation of the bit rate divider used a standard C division, which
> rounds down the quotient. This may lead to a higher bitrate than requested.
> Round up to avoid this.
>
> E.g. on Koelsch, the SPI flash (configured for 30 MHz) was driven at 48.75
> MHz. After this patch it's driven at a safe 24.375 MHz.
>
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
> ---
> Simon: I think you want this in renesas-backports.
Thanks, I'll backport it once its been accepted by Mark.
> drivers/spi/spi-rspi.c | 8 +++++---
> 1 file changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/spi/spi-rspi.c b/drivers/spi/spi-rspi.c
> index 1fb0ad213324..5639f9529e0b 100644
> --- a/drivers/spi/spi-rspi.c
> +++ b/drivers/spi/spi-rspi.c
> @@ -266,7 +266,8 @@ static int rspi_set_config_register(struct rspi_data *rspi, int access_size)
> rspi_write8(rspi, rspi->sppcr, RSPI_SPPCR);
>
> /* Sets transfer bit rate */
> - spbr = clk_get_rate(rspi->clk) / (2 * rspi->max_speed_hz) - 1;
> + spbr = DIV_ROUND_UP(clk_get_rate(rspi->clk),
> + 2 * rspi->max_speed_hz) - 1;
> rspi_write8(rspi, clamp(spbr, 0, 255), RSPI_SPBR);
>
> /* Disable dummy transmission, set 16-bit word access, 1 frame */
> @@ -302,7 +303,8 @@ static int rspi_rz_set_config_register(struct rspi_data *rspi, int access_size)
> rspi_write8(rspi, rspi->sppcr, RSPI_SPPCR);
>
> /* Sets transfer bit rate */
> - spbr = clk_get_rate(rspi->clk) / (2 * rspi->max_speed_hz) - 1;
> + spbr = DIV_ROUND_UP(clk_get_rate(rspi->clk),
> + 2 * rspi->max_speed_hz) - 1;
> rspi_write8(rspi, clamp(spbr, 0, 255), RSPI_SPBR);
>
> /* Disable dummy transmission, set byte access */
> @@ -335,7 +337,7 @@ static int qspi_set_config_register(struct rspi_data *rspi, int access_size)
> rspi_write8(rspi, rspi->sppcr, RSPI_SPPCR);
>
> /* Sets transfer bit rate */
> - spbr = clk_get_rate(rspi->clk) / (2 * rspi->max_speed_hz);
> + spbr = DIV_ROUND_UP(clk_get_rate(rspi->clk), 2 * rspi->max_speed_hz);
> rspi_write8(rspi, clamp(spbr, 0, 255), RSPI_SPBR);
>
> /* Disable dummy transmission, set byte access */
> --
> 1.9.1
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] spi: rspi: Round up division to avoid slave overclocking
[not found] ` <1400782055-19609-1-git-send-email-geert+renesas-gXvu3+zWzMSzQB+pC5nmwQ@public.gmane.org>
@ 2014-05-26 13:30 ` Mark Brown
0 siblings, 0 replies; 3+ messages in thread
From: Mark Brown @ 2014-05-26 13:30 UTC (permalink / raw)
To: Geert Uytterhoeven
Cc: Simon Horman, linux-spi-u79uwXL29TY76Z2rM5mHXA,
linux-sh-u79uwXL29TY76Z2rM5mHXA,
linux-kernel-u79uwXL29TY76Z2rM5mHXA
[-- Attachment #1: Type: text/plain, Size: 266 bytes --]
On Thu, May 22, 2014 at 08:07:35PM +0200, Geert Uytterhoeven wrote:
> The calculation of the bit rate divider used a standard C division, which
> rounds down the quotient. This may lead to a higher bitrate than requested.
> Round up to avoid this.
Applied, thanks.
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2014-05-26 13:30 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-05-22 18:07 [PATCH] spi: rspi: Round up division to avoid slave overclocking Geert Uytterhoeven
2014-05-26 1:41 ` Simon Horman
[not found] ` <1400782055-19609-1-git-send-email-geert+renesas-gXvu3+zWzMSzQB+pC5nmwQ@public.gmane.org>
2014-05-26 13:30 ` Mark Brown
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).