brcm2708: update 4.1 patches
[openwrt/openwrt.git] / target / linux / brcm2708 / patches-4.1 / 0176-spi-bcm2835-fix-overflow-in-calculation-of-transfer-.patch
1 From 3604c2a5b623829c9127d312813f3427531ebfcd Mon Sep 17 00:00:00 2001
2 From: Martin Sperl <kernel@martin.sperl.org>
3 Date: Wed, 29 Jul 2015 07:34:10 +0000
4 Subject: [PATCH 176/222] spi: bcm2835: fix overflow in calculation of transfer
5 time
6
7 This resulted in the use of polling mode when other approaches
8 (dma or interrupts) would have been more appropriate.
9
10 Happened for transfers longer than 477 bytes.
11
12 Reported-by: Noralf Tronnes <noralf@tronnes.org>
13 Signed-off-by: Martin Sperl <kernel@martin.sperl.org>
14 Signed-off-by: Mark Brown <broonie@kernel.org>
15 (cherry picked from commit 0122a5183088e3117bb9c8fbe248914efb502f3f)
16 ---
17 drivers/spi/spi-bcm2835.c | 10 ++++++----
18 1 file changed, 6 insertions(+), 4 deletions(-)
19
20 --- a/drivers/spi/spi-bcm2835.c
21 +++ b/drivers/spi/spi-bcm2835.c
22 @@ -480,7 +480,7 @@ static int bcm2835_spi_transfer_one_poll
23 struct spi_device *spi,
24 struct spi_transfer *tfr,
25 u32 cs,
26 - unsigned long xfer_time_us)
27 + unsigned long long xfer_time_us)
28 {
29 struct bcm2835_spi *bs = spi_master_get_devdata(master);
30 unsigned long timeout;
31 @@ -531,7 +531,8 @@ static int bcm2835_spi_transfer_one(stru
32 {
33 struct bcm2835_spi *bs = spi_master_get_devdata(master);
34 unsigned long spi_hz, clk_hz, cdiv;
35 - unsigned long spi_used_hz, xfer_time_us;
36 + unsigned long spi_used_hz;
37 + unsigned long long xfer_time_us;
38 u32 cs = bcm2835_rd(bs, BCM2835_SPI_CS);
39
40 /* set clock */
41 @@ -573,9 +574,10 @@ static int bcm2835_spi_transfer_one(stru
42 bs->rx_len = tfr->len;
43
44 /* calculate the estimated time in us the transfer runs */
45 - xfer_time_us = tfr->len
46 + xfer_time_us = (unsigned long long)tfr->len
47 * 9 /* clocks/byte - SPI-HW waits 1 clock after each byte */
48 - * 1000000 / spi_used_hz;
49 + * 1000000;
50 + do_div(xfer_time_us, spi_used_hz);
51
52 /* for short requests run polling*/
53 if (xfer_time_us <= BCM2835_SPI_POLLING_LIMIT_US)