linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] spi: pxa2xx: fix SCR (divisor) calculation
@ 2019-04-10 12:51 Flavio Suligoi
  2019-04-10 12:51 ` [PATCH 2/2] spi: pxa2xx: use a module softdep for dw_dmac Flavio Suligoi
  2019-04-11 11:55 ` [PATCH 1/2] spi: pxa2xx: fix SCR (divisor) calculation Jarkko Nikula
  0 siblings, 2 replies; 12+ messages in thread
From: Flavio Suligoi @ 2019-04-10 12:51 UTC (permalink / raw)
  To: Daniel Mack, Haojian Zhuang, Robert Jarzmik, Mark Brown
  Cc: linux-arm-kernel, linux-spi, linux-kernel, Flavio Suligoi

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>
---
 drivers/spi/spi-pxa2xx.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/spi/spi-pxa2xx.c b/drivers/spi/spi-pxa2xx.c
index f7068cc..c9560a1 100644
--- a/drivers/spi/spi-pxa2xx.c
+++ b/drivers/spi/spi-pxa2xx.c
@@ -884,10 +884,15 @@ 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 (ssp_clk / (2 * rate) - 1 +
+			(ssp_clk % (2 * rate) ? 1 : 0)) & 0xff;
 	else
-		return (ssp_clk / rate - 1) & 0xfff;
+		return (ssp_clk / rate - 1 + (ssp_clk % rate ? 1 : 0)) & 0xfff;
 }
 
 static unsigned int pxa2xx_ssp_get_clk_div(struct driver_data *drv_data,
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2019-05-02  2:19 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-10 12:51 [PATCH 1/2] spi: pxa2xx: fix SCR (divisor) calculation Flavio Suligoi
2019-04-10 12:51 ` [PATCH 2/2] spi: pxa2xx: use a module softdep for dw_dmac Flavio Suligoi
2019-04-10 12:56   ` Mark Brown
2019-04-10 14:05     ` Flavio Suligoi
2019-04-10 15:28       ` Mark Brown
2019-04-11  7:14         ` Flavio Suligoi
2019-04-11 10:42           ` Mark Brown
2019-04-11 11:31             ` Flavio Suligoi
2019-04-12  8:53   ` Applied "spi: pxa2xx: use a module softdep for dw_dmac" to the spi tree Mark Brown
2019-05-02  2:19   ` Mark Brown
2019-04-11 11:55 ` [PATCH 1/2] spi: pxa2xx: fix SCR (divisor) calculation Jarkko Nikula
2019-04-11 13:10   ` Flavio Suligoi

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).