linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Simon Horman <horms@verge.net.au>
To: Geert Uytterhoeven <geert+renesas@glider.be>
Cc: Mark Brown <broonie@kernel.org>,
	linux-spi@vger.kernel.org, linux-sh@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] spi: rspi: Round up division to avoid slave overclocking
Date: Mon, 26 May 2014 10:41:41 +0900	[thread overview]
Message-ID: <20140526014140.GH31096@verge.net.au> (raw)
In-Reply-To: <1400782055-19609-1-git-send-email-geert+renesas@glider.be>

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
> 

  reply	other threads:[~2014-05-26  1:41 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-22 18:07 [PATCH] spi: rspi: Round up division to avoid slave overclocking Geert Uytterhoeven
2014-05-26  1:41 ` Simon Horman [this message]
     [not found] ` <1400782055-19609-1-git-send-email-geert+renesas-gXvu3+zWzMSzQB+pC5nmwQ@public.gmane.org>
2014-05-26 13:30   ` Mark Brown

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=20140526014140.GH31096@verge.net.au \
    --to=horms@verge.net.au \
    --cc=broonie@kernel.org \
    --cc=geert+renesas@glider.be \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sh@vger.kernel.org \
    --cc=linux-spi@vger.kernel.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).