brcm2708: Add support for raspberry pi 3 b+.
[openwrt/openwrt.git] / target / linux / bcm53xx / patches-4.4 / 084-0003-spi-bcm53xx-simplify-reading-SPI-data.patch
1 From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <rafal@milecki.pl>
2 Date: Fri, 29 Dec 2017 14:44:09 +0100
3 Subject: [PATCH] spi: bcm53xx: simplify reading SPI data
4 MIME-Version: 1.0
5 Content-Type: text/plain; charset=UTF-8
6 Content-Transfer-Encoding: 8bit
7
8 This commit makes transfer function use spi_transfer_is_last to
9 determine if currently processed transfer is the last one. Thanks to
10 that we finally set hardware registers properly and it makes controller
11 behave the way it's expected to.
12
13 This allows simplifying read function which can now simply start reading
14 from the slot 0 instead of the last saved offset. It has been
15 successfully tested using spi_write_then_read.
16
17 Moreover this change fixes handling messages with two writing transfers.
18 It's important for SPI flash devices as their drivers commonly use one
19 transfer for a command and another one for data.
20
21 Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
22 ---
23 drivers/spi/spi-bcm53xx.c | 26 ++++++++++----------------
24 1 file changed, 10 insertions(+), 16 deletions(-)
25
26 --- a/drivers/spi/spi-bcm53xx.c
27 +++ b/drivers/spi/spi-bcm53xx.c
28 @@ -27,8 +27,6 @@ struct bcm53xxspi {
29 struct bcma_device *core;
30 struct spi_master *master;
31 void __iomem *mmio_base;
32 -
33 - size_t read_offset;
34 bool bspi; /* Boot SPI mode with memory mapping */
35 };
36
37 @@ -172,8 +170,6 @@ static void bcm53xxspi_buf_write(struct
38
39 if (!cont)
40 bcm53xxspi_write(b53spi, B53SPI_MSPI_WRITE_LOCK, 0);
41 -
42 - b53spi->read_offset = len;
43 }
44
45 static void bcm53xxspi_buf_read(struct bcm53xxspi *b53spi, u8 *r_buf,
46 @@ -182,10 +178,10 @@ static void bcm53xxspi_buf_read(struct b
47 u32 tmp;
48 int i;
49
50 - for (i = 0; i < b53spi->read_offset + len; i++) {
51 + for (i = 0; i < len; i++) {
52 tmp = B53SPI_CDRAM_CONT | B53SPI_CDRAM_PCS_DISABLE_ALL |
53 B53SPI_CDRAM_PCS_DSCK;
54 - if (!cont && i == b53spi->read_offset + len - 1)
55 + if (!cont && i == len - 1)
56 tmp &= ~B53SPI_CDRAM_CONT;
57 tmp &= ~0x1;
58 /* Command Register File */
59 @@ -194,8 +190,7 @@ static void bcm53xxspi_buf_read(struct b
60
61 /* Set queue pointers */
62 bcm53xxspi_write(b53spi, B53SPI_MSPI_NEWQP, 0);
63 - bcm53xxspi_write(b53spi, B53SPI_MSPI_ENDQP,
64 - b53spi->read_offset + len - 1);
65 + bcm53xxspi_write(b53spi, B53SPI_MSPI_ENDQP, len - 1);
66
67 if (cont)
68 bcm53xxspi_write(b53spi, B53SPI_MSPI_WRITE_LOCK, 1);
69 @@ -214,13 +209,11 @@ static void bcm53xxspi_buf_read(struct b
70 bcm53xxspi_write(b53spi, B53SPI_MSPI_WRITE_LOCK, 0);
71
72 for (i = 0; i < len; ++i) {
73 - int offset = b53spi->read_offset + i;
74 + u16 reg = B53SPI_MSPI_RXRAM + 4 * (1 + i * 2);
75
76 /* Data stored in the transmit register file LSB */
77 - r_buf[i] = (u8)bcm53xxspi_read(b53spi, B53SPI_MSPI_RXRAM + 4 * (1 + offset * 2));
78 + r_buf[i] = (u8)bcm53xxspi_read(b53spi, reg);
79 }
80 -
81 - b53spi->read_offset = 0;
82 }
83
84 static int bcm53xxspi_transfer_one(struct spi_master *master,
85 @@ -238,7 +231,8 @@ static int bcm53xxspi_transfer_one(struc
86 left = t->len;
87 while (left) {
88 size_t to_write = min_t(size_t, 16, left);
89 - bool cont = left - to_write > 0;
90 + bool cont = !spi_transfer_is_last(master, t) ||
91 + left - to_write > 0;
92
93 bcm53xxspi_buf_write(b53spi, buf, to_write, cont);
94 left -= to_write;
95 @@ -250,9 +244,9 @@ static int bcm53xxspi_transfer_one(struc
96 buf = (u8 *)t->rx_buf;
97 left = t->len;
98 while (left) {
99 - size_t to_read = min_t(size_t, 16 - b53spi->read_offset,
100 - left);
101 - bool cont = left - to_read > 0;
102 + size_t to_read = min_t(size_t, 16, left);
103 + bool cont = !spi_transfer_is_last(master, t) ||
104 + left - to_read > 0;
105
106 bcm53xxspi_buf_read(b53spi, buf, to_read, cont);
107 left -= to_read;