aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafał Miłecki <rafal@milecki.pl>2017-12-29 08:48:02 -0500
committerMark Brown <broonie@kernel.org>2018-01-03 06:39:16 -0500
commit3a41092709a14c8efc84571deacc95a24b7fd6b3 (patch)
tree992a37e28aa08a89441ff708581e0dd394aaea20
parent4fbd8d194f06c8a3fd2af1ce560ddb31f7ec8323 (diff)
spi: bcm53xx: simplify reading SPI data
This commit makes transfer function use spi_transfer_is_last to determine if currently processed transfer is the last one. Thanks to that we finally set hardware registers properly and it makes controller behave the way it's expected to. This allows simplifying read function which can now simply start reading from the slot 0 instead of the last saved offset. It has been successfully tested using spi_write_then_read. Moreover this change fixes handling messages with two writing transfers. It's important for SPI flash devices as their drivers commonly use one transfer for a command and another one for data. Signed-off-by: Rafał Miłecki <rafal@milecki.pl> Signed-off-by: Mark Brown <broonie@kernel.org>
-rw-r--r--drivers/spi/spi-bcm53xx.c26
1 files changed, 10 insertions, 16 deletions
diff --git a/drivers/spi/spi-bcm53xx.c b/drivers/spi/spi-bcm53xx.c
index 6e409eabe1c9..d02ceb7a29d1 100644
--- a/drivers/spi/spi-bcm53xx.c
+++ b/drivers/spi/spi-bcm53xx.c
@@ -27,8 +27,6 @@ struct bcm53xxspi {
27 struct bcma_device *core; 27 struct bcma_device *core;
28 struct spi_master *master; 28 struct spi_master *master;
29 void __iomem *mmio_base; 29 void __iomem *mmio_base;
30
31 size_t read_offset;
32 bool bspi; /* Boot SPI mode with memory mapping */ 30 bool bspi; /* Boot SPI mode with memory mapping */
33}; 31};
34 32
@@ -172,8 +170,6 @@ static void bcm53xxspi_buf_write(struct bcm53xxspi *b53spi, u8 *w_buf,
172 170
173 if (!cont) 171 if (!cont)
174 bcm53xxspi_write(b53spi, B53SPI_MSPI_WRITE_LOCK, 0); 172 bcm53xxspi_write(b53spi, B53SPI_MSPI_WRITE_LOCK, 0);
175
176 b53spi->read_offset = len;
177} 173}
178 174
179static void bcm53xxspi_buf_read(struct bcm53xxspi *b53spi, u8 *r_buf, 175static void bcm53xxspi_buf_read(struct bcm53xxspi *b53spi, u8 *r_buf,
@@ -182,10 +178,10 @@ static void bcm53xxspi_buf_read(struct bcm53xxspi *b53spi, u8 *r_buf,
182 u32 tmp; 178 u32 tmp;
183 int i; 179 int i;
184 180
185 for (i = 0; i < b53spi->read_offset + len; i++) { 181 for (i = 0; i < len; i++) {
186 tmp = B53SPI_CDRAM_CONT | B53SPI_CDRAM_PCS_DISABLE_ALL | 182 tmp = B53SPI_CDRAM_CONT | B53SPI_CDRAM_PCS_DISABLE_ALL |
187 B53SPI_CDRAM_PCS_DSCK; 183 B53SPI_CDRAM_PCS_DSCK;
188 if (!cont && i == b53spi->read_offset + len - 1) 184 if (!cont && i == len - 1)
189 tmp &= ~B53SPI_CDRAM_CONT; 185 tmp &= ~B53SPI_CDRAM_CONT;
190 tmp &= ~0x1; 186 tmp &= ~0x1;
191 /* Command Register File */ 187 /* Command Register File */
@@ -194,8 +190,7 @@ static void bcm53xxspi_buf_read(struct bcm53xxspi *b53spi, u8 *r_buf,
194 190
195 /* Set queue pointers */ 191 /* Set queue pointers */
196 bcm53xxspi_write(b53spi, B53SPI_MSPI_NEWQP, 0); 192 bcm53xxspi_write(b53spi, B53SPI_MSPI_NEWQP, 0);
197 bcm53xxspi_write(b53spi, B53SPI_MSPI_ENDQP, 193 bcm53xxspi_write(b53spi, B53SPI_MSPI_ENDQP, len - 1);
198 b53spi->read_offset + len - 1);
199 194
200 if (cont) 195 if (cont)
201 bcm53xxspi_write(b53spi, B53SPI_MSPI_WRITE_LOCK, 1); 196 bcm53xxspi_write(b53spi, B53SPI_MSPI_WRITE_LOCK, 1);
@@ -214,13 +209,11 @@ static void bcm53xxspi_buf_read(struct bcm53xxspi *b53spi, u8 *r_buf,
214 bcm53xxspi_write(b53spi, B53SPI_MSPI_WRITE_LOCK, 0); 209 bcm53xxspi_write(b53spi, B53SPI_MSPI_WRITE_LOCK, 0);
215 210
216 for (i = 0; i < len; ++i) { 211 for (i = 0; i < len; ++i) {
217 int offset = b53spi->read_offset + i; 212 u16 reg = B53SPI_MSPI_RXRAM + 4 * (1 + i * 2);
218 213
219 /* Data stored in the transmit register file LSB */ 214 /* Data stored in the transmit register file LSB */
220 r_buf[i] = (u8)bcm53xxspi_read(b53spi, B53SPI_MSPI_RXRAM + 4 * (1 + offset * 2)); 215 r_buf[i] = (u8)bcm53xxspi_read(b53spi, reg);
221 } 216 }
222
223 b53spi->read_offset = 0;
224} 217}
225 218
226static int bcm53xxspi_transfer_one(struct spi_master *master, 219static int bcm53xxspi_transfer_one(struct spi_master *master,
@@ -238,7 +231,8 @@ static int bcm53xxspi_transfer_one(struct spi_master *master,
238 left = t->len; 231 left = t->len;
239 while (left) { 232 while (left) {
240 size_t to_write = min_t(size_t, 16, left); 233 size_t to_write = min_t(size_t, 16, left);
241 bool cont = left - to_write > 0; 234 bool cont = !spi_transfer_is_last(master, t) ||
235 left - to_write > 0;
242 236
243 bcm53xxspi_buf_write(b53spi, buf, to_write, cont); 237 bcm53xxspi_buf_write(b53spi, buf, to_write, cont);
244 left -= to_write; 238 left -= to_write;
@@ -250,9 +244,9 @@ static int bcm53xxspi_transfer_one(struct spi_master *master,
250 buf = (u8 *)t->rx_buf; 244 buf = (u8 *)t->rx_buf;
251 left = t->len; 245 left = t->len;
252 while (left) { 246 while (left) {
253 size_t to_read = min_t(size_t, 16 - b53spi->read_offset, 247 size_t to_read = min_t(size_t, 16, left);
254 left); 248 bool cont = !spi_transfer_is_last(master, t) ||
255 bool cont = left - to_read > 0; 249 left - to_read > 0;
256 250
257 bcm53xxspi_buf_read(b53spi, buf, to_read, cont); 251 bcm53xxspi_buf_read(b53spi, buf, to_read, cont);
258 left -= to_read; 252 left -= to_read;