1 From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <zajec5@gmail.com>
2 Subject: [PATCH] mtd: m25p80: use single SPI message for writing data
4 Content-Type: text/plain; charset=UTF-8
5 Content-Transfer-Encoding: 8bit
7 On all 3 tested Northstar devices with following flash memories:
8 mx25l6405d (8192 Kbytes)
9 mx25l12805d (16384 Kbytes)
10 mx25l25635e (32768 Kbytes)
11 I noticed writing to be broken. Not a single bit was changed leaving all
14 This is most likely some problem related to the SPI controller or its
15 driver. Using a single SPI message seems to workaround this. Of course
16 it's not perfect solution as copying whole data into a new buffer makes
19 Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
22 --- a/drivers/mtd/devices/m25p80.c
23 +++ b/drivers/mtd/devices/m25p80.c
24 @@ -78,6 +78,7 @@ static void m25p80_write(struct spi_nor
26 struct m25p *flash = nor->priv;
27 struct spi_device *spi = flash->spi;
28 + u8 *command = kzalloc(MAX_CMD_SIZE + len, GFP_KERNEL);
29 struct spi_transfer t[2] = {};
31 int cmd_sz = m25p_cmdsz(nor);
32 @@ -87,20 +88,19 @@ static void m25p80_write(struct spi_nor
33 if (nor->program_opcode == SPINOR_OP_AAI_WP && nor->sst_write_second)
36 - flash->command[0] = nor->program_opcode;
37 - m25p_addr2cmd(nor, to, flash->command);
38 + command[0] = nor->program_opcode;
39 + m25p_addr2cmd(nor, to, command);
40 + memcpy(&command[cmd_sz], buf, len);
42 - t[0].tx_buf = flash->command;
44 + t[0].tx_buf = command;
45 + t[0].len = cmd_sz + len;
46 spi_message_add_tail(&t[0], &m);
50 - spi_message_add_tail(&t[1], &m);
54 *retlen += m.actual_length - cmd_sz;
59 static inline unsigned int m25p80_rx_nbits(struct spi_nor *nor)