All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] spi/rockchip: Round up clock rate divisor to err on the safe side
@ 2015-03-26 23:30 ` Julius Werner
  0 siblings, 0 replies; 10+ messages in thread
From: Julius Werner @ 2015-03-26 23:30 UTC (permalink / raw)
  To: Mark Brown
  Cc: Mark Rutland, Heiko Stuebner, addy ke, Doug Anderson, devicetree,
	linux-spi, linux-kernel, Julius Werner

The Rockchip SPI driver currently calculates its clock rate divisor by
integer dividing the parent rate by the target rate, and then rounding
the result up to the next even number (since the divisor must be
even).

Clock rate divisors should always be rounded up, so that the resulting
frequency is lower or equal to the target. This is correctly done in the
second step here but not in the first, so we still have a risk of
exceeding the desired target frequency (e.g. setting spi-max-frequency
to 40000000 with a parent clock of 99000000 could lead to a divisor of
99000000 / 40000000 == 2 (which is even) that then results in an
effective frequency of 99000000 / 2 == 49500000 (potentially exceeding
the flash chip's specifications).

This patch changes the division to round up to fix this problem.

Signed-off-by: Julius Werner <jwerner@chromium.org>
---
 drivers/spi/spi-rockchip.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/spi/spi-rockchip.c b/drivers/spi/spi-rockchip.c
index 1a777dc..5e4e52c 100644
--- a/drivers/spi/spi-rockchip.c
+++ b/drivers/spi/spi-rockchip.c
@@ -519,7 +519,7 @@ static void rockchip_spi_config(struct rockchip_spi *rs)
 	}
 
 	/* div doesn't support odd number */
-	div = max_t(u32, rs->max_freq / rs->speed, 1);
+	div = DIV_ROUND_UP(rs->max_freq, rs->speed);
 	div = (div + 1) & 0xfffe;
 
 	writel_relaxed(cr0, rs->regs + ROCKCHIP_SPI_CTRLR0);
-- 
2.1.2


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

end of thread, other threads:[~2015-03-27  0:46 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-26 23:30 [PATCH 1/2] spi/rockchip: Round up clock rate divisor to err on the safe side Julius Werner
2015-03-26 23:30 ` Julius Werner
2015-03-26 23:30 ` [PATCH 2/2] spi/rockchip: Add device tree property to configure Rx Sample Delay Julius Werner
2015-03-26 23:30   ` Julius Werner
2015-03-27  0:29   ` Doug Anderson
2015-03-27  0:29     ` Doug Anderson
2015-03-27  0:27 ` [PATCH 1/2] spi/rockchip: Round up clock rate divisor to err on the safe side Doug Anderson
2015-03-27  0:27   ` Doug Anderson
2015-03-27  0:46 ` Mark Brown
2015-03-27  0:46   ` Mark Brown

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.