From: Jarkko Nikula <jarkko.nikula@linux.intel.com>
To: Flavio Suligoi <f.suligoi@asem.it>,
Daniel Mack <daniel@zonque.org>,
Haojian Zhuang <haojian.zhuang@gmail.com>,
Robert Jarzmik <robert.jarzmik@free.fr>,
Mark Brown <broonie@kernel.org>
Cc: linux-arm-kernel@lists.infradead.org, linux-spi@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] spi: pxa2xx: fix SCR (divisor) calculation
Date: Fri, 12 Apr 2019 15:35:38 +0300 [thread overview]
Message-ID: <729d9db2-de3e-e64c-862d-db8a25775b02@linux.intel.com> (raw)
In-Reply-To: <1555054339-17096-1-git-send-email-f.suligoi@asem.it>
On 4/12/19 10:32 AM, Flavio Suligoi wrote:
> Calculate the divisor for the SCR (Serial Clock Rate), avoiding
> that the SSP transmission rate can be greater than the device rate.
>
> When the division between the SSP clock and the device rate generates
> a reminder, we have to increment by one the divisor.
> In this way the resulting SSP clock will never be greater than the
> device SPI max frequency.
>
> For example, with:
>
> - ssp_clk = 50 MHz
> - dev freq = 15 MHz
>
> without this patch the SSP clock will be greater than 15 MHz:
>
> - 25 MHz for PXA25x_SSP and CE4100_SSP
> - 16,56 MHz for the others
>
> Instead, with this patch, we have in both case an SSP clock of 12.5MHz,
> so the max rate of the SPI device clock is respected.
>
> Signed-off-by: Flavio Suligoi <f.suligoi@asem.it>
> Reviewed-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>
> ---
>
> v2: - simplify the code using "DIV_ROUND_UP"
> v1: - first version
>
> drivers/spi/spi-pxa2xx.c | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/spi/spi-pxa2xx.c b/drivers/spi/spi-pxa2xx.c
> index f7068cc..a35fdcb 100644
> --- a/drivers/spi/spi-pxa2xx.c
> +++ b/drivers/spi/spi-pxa2xx.c
> @@ -884,10 +884,14 @@ static unsigned int ssp_get_clk_div(struct driver_data *drv_data, int rate)
>
> rate = min_t(int, ssp_clk, rate);
>
> + /*
> + * Calculate the divisor for the SCR (Serial Clock Rate), avoiding
> + * that the SSP transmission rate can be greater than the device rate
> + */
> if (ssp->type == PXA25x_SSP || ssp->type == CE4100_SSP)
> - return (ssp_clk / (2 * rate) - 1) & 0xff;
> + return (DIV_ROUND_UP(ssp_clk, 2 * rate) - 1) & 0xff;
> else
> - return (ssp_clk / rate - 1) & 0xfff;
> + return (DIV_ROUND_UP(ssp_clk, rate) - 1) & 0xfff;
> }
>
Reviewed-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>
next prev parent reply other threads:[~2019-04-12 12:35 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-12 7:32 [PATCH v2] spi: pxa2xx: fix SCR (divisor) calculation Flavio Suligoi
2019-04-12 12:35 ` Jarkko Nikula [this message]
2019-04-15 8:53 ` Applied "spi: pxa2xx: fix SCR (divisor) calculation" to the spi tree Mark Brown
2019-05-02 2:18 ` 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=729d9db2-de3e-e64c-862d-db8a25775b02@linux.intel.com \
--to=jarkko.nikula@linux.intel.com \
--cc=broonie@kernel.org \
--cc=daniel@zonque.org \
--cc=f.suligoi@asem.it \
--cc=haojian.zhuang@gmail.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-spi@vger.kernel.org \
--cc=robert.jarzmik@free.fr \
/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).