bcm53xx: add Linux 4.9 patches
[librecmc/librecmc.git] / target / linux / bcm53xx / patches-4.9 / 401-mtd-m25p80-use-single-SPI-message-for-writing-data.patch
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
3 MIME-Version: 1.0
4 Content-Type: text/plain; charset=UTF-8
5 Content-Transfer-Encoding: 8bit
6
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
12 bytes set to 0xff.
13
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
17 writing slower.
18
19 Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
20 ---
21
22 --- a/drivers/mtd/devices/m25p80.c
23 +++ b/drivers/mtd/devices/m25p80.c
24 @@ -78,6 +78,7 @@ static ssize_t m25p80_write(struct spi_n
25  {
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] = {};
30         struct spi_message m;
31         int cmd_sz = m25p_cmdsz(nor);
32 @@ -88,24 +89,26 @@ static ssize_t m25p80_write(struct spi_n
33         if (nor->program_opcode == SPINOR_OP_AAI_WP && nor->sst_write_second)
34                 cmd_sz = 1;
35  
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);
41  
42 -       t[0].tx_buf = flash->command;
43 -       t[0].len = cmd_sz;
44 +       t[0].tx_buf = command;
45 +       t[0].len = cmd_sz + len;
46         spi_message_add_tail(&t[0], &m);
47  
48 -       t[1].tx_buf = buf;
49 -       t[1].len = len;
50 -       spi_message_add_tail(&t[1], &m);
51 -
52         ret = spi_sync(spi, &m);
53 -       if (ret)
54 +       if (ret) {
55 +               kfree(command);
56                 return ret;
57 +       }
58  
59         ret = m.actual_length - cmd_sz;
60 -       if (ret < 0)
61 +       if (ret < 0) {
62 +               kfree(command);
63                 return -EIO;
64 +       }
65 +       kfree(command);
66         return ret;
67  }
68