Skip to content

Commit 0ffe0ce

Browse files
H Hartley SweetenDavid Woodhouse
authored andcommitted
mtd: sst25l: fix multi-part messages with broken spi masters
Some SPI masters (ep93xx) have limitations when using the SFRMOUT signal for the spi device chip select. The SFRMOUT signal is only asserted as long as the spi transmit fifo contains data. As soon as the last bit is clocked into the receive fifo it gets deasserted. The functions sst25l_status and sst25l_match_device use the API function spi_write_then_read to write a command to the flash then read the response back. This API function creates a two part spi message for the write then read. When this message is transferred the SFRMOUT signal ends up getting deasserted after the command phase. This causes the command to get aborted by the device so the read phase returns invalid data. By changing sst25l_status and sst25l_match_device to use a single transfer synchronous message, the SFRMOUT signal stays asserted during the entire message so the correct data always gets returned. This change will have no effect on SPI masters which use a chip select mechanism (GPIO's, etc.) which does stay asserted correctly. As a bonus, the single transfer synchronous messages complete faster than multi-part messages. Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com> Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
1 parent 46f3e88 commit 0ffe0ce

1 file changed

Lines changed: 33 additions & 24 deletions

File tree

‎drivers/mtd/devices/sst25l.c‎

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,25 @@ static struct flash_info __initdata sst25l_flash_info[] = {
7373

7474
static int sst25l_status(struct sst25l_flash *flash, int *status)
7575
{
76-
unsigned char command, response;
76+
struct spi_message m;
77+
struct spi_transfer t;
78+
unsigned char cmd_resp[2];
7779
int err;
7880

79-
command = SST25L_CMD_RDSR;
80-
err = spi_write_then_read(flash->spi, &command, 1, &response, 1);
81+
spi_message_init(&m);
82+
memset(&t, 0, sizeof(struct spi_transfer));
83+
84+
cmd_resp[0] = SST25L_CMD_RDSR;
85+
cmd_resp[1] = 0xff;
86+
t.tx_buf = cmd_resp;
87+
t.rx_buf = cmd_resp;
88+
t.len = sizeof(cmd_resp);
89+
spi_message_add_tail(&t, &m);
90+
err = spi_sync(flash->spi, &m);
8191
if (err < 0)
8292
return err;
8393

84-
*status = response;
94+
*status = cmd_resp[1];
8595
return 0;
8696
}
8797

@@ -328,33 +338,32 @@ static int sst25l_write(struct mtd_info *mtd, loff_t to, size_t len,
328338
static struct flash_info *__init sst25l_match_device(struct spi_device *spi)
329339
{
330340
struct flash_info *flash_info = NULL;
331-
unsigned char command[4], response;
341+
struct spi_message m;
342+
struct spi_transfer t;
343+
unsigned char cmd_resp[6];
332344
int i, err;
333345
uint16_t id;
334346

335-
command[0] = SST25L_CMD_READ_ID;
336-
command[1] = 0;
337-
command[2] = 0;
338-
command[3] = 0;
339-
err = spi_write_then_read(spi, command, sizeof(command), &response, 1);
340-
if (err < 0) {
341-
dev_err(&spi->dev, "error reading device id msb\n");
342-
return NULL;
343-
}
344-
345-
id = response << 8;
346-
347-
command[0] = SST25L_CMD_READ_ID;
348-
command[1] = 0;
349-
command[2] = 0;
350-
command[3] = 1;
351-
err = spi_write_then_read(spi, command, sizeof(command), &response, 1);
347+
spi_message_init(&m);
348+
memset(&t, 0, sizeof(struct spi_transfer));
349+
350+
cmd_resp[0] = SST25L_CMD_READ_ID;
351+
cmd_resp[1] = 0;
352+
cmd_resp[2] = 0;
353+
cmd_resp[3] = 0;
354+
cmd_resp[4] = 0xff;
355+
cmd_resp[5] = 0xff;
356+
t.tx_buf = cmd_resp;
357+
t.rx_buf = cmd_resp;
358+
t.len = sizeof(cmd_resp);
359+
spi_message_add_tail(&t, &m);
360+
err = spi_sync(spi, &m);
352361
if (err < 0) {
353-
dev_err(&spi->dev, "error reading device id lsb\n");
362+
dev_err(&spi->dev, "error reading device id\n");
354363
return NULL;
355364
}
356365

357-
id |= response;
366+
id = (cmd_resp[4] << 8) | cmd_resp[5];
358367

359368
for (i = 0; i < ARRAY_SIZE(sst25l_flash_info); i++)
360369
if (sst25l_flash_info[i].device_id == id)

0 commit comments

Comments
 (0)