406-mtd-m25p80-use-single-SPI-message-for-writing-data.patch 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. On all 3 tested Northstar devices with following flash memories:
  7. mx25l6405d (8192 Kbytes)
  8. mx25l12805d (16384 Kbytes)
  9. mx25l25635e (32768 Kbytes)
  10. I noticed writing to be broken. Not a single bit was changed leaving all
  11. bytes set to 0xff.
  12. This is most likely some problem related to the SPI controller or its
  13. driver. Using a single SPI message seems to workaround this. Of course
  14. it's not perfect solution as copying whole data into a new buffer makes
  15. writing slower.
  16. Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
  17. ---
  18. --- a/drivers/mtd/devices/m25p80.c
  19. +++ b/drivers/mtd/devices/m25p80.c
  20. @@ -78,6 +78,7 @@ static void m25p80_write(struct spi_nor
  21. {
  22. struct m25p *flash = nor->priv;
  23. struct spi_device *spi = flash->spi;
  24. + u8 *command = kzalloc(MAX_CMD_SIZE + len, GFP_KERNEL);
  25. struct spi_transfer t[2] = {};
  26. struct spi_message m;
  27. int cmd_sz = m25p_cmdsz(nor);
  28. @@ -87,20 +88,19 @@ static void m25p80_write(struct spi_nor
  29. if (nor->program_opcode == SPINOR_OP_AAI_WP && nor->sst_write_second)
  30. cmd_sz = 1;
  31. - flash->command[0] = nor->program_opcode;
  32. - m25p_addr2cmd(nor, to, flash->command);
  33. + command[0] = nor->program_opcode;
  34. + m25p_addr2cmd(nor, to, command);
  35. + memcpy(&command[cmd_sz], buf, len);
  36. - t[0].tx_buf = flash->command;
  37. - t[0].len = cmd_sz;
  38. + t[0].tx_buf = command;
  39. + t[0].len = cmd_sz + len;
  40. spi_message_add_tail(&t[0], &m);
  41. - t[1].tx_buf = buf;
  42. - t[1].len = len;
  43. - spi_message_add_tail(&t[1], &m);
  44. -
  45. spi_sync(spi, &m);
  46. *retlen += m.actual_length - cmd_sz;
  47. +
  48. + kfree(command);
  49. }
  50. static inline unsigned int m25p80_rx_nbits(struct spi_nor *nor)