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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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,29 +78,30 @@ 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. + int i;
  29. spi_message_init(&m);
  30. if (nor->program_opcode == SPINOR_OP_AAI_WP && nor->sst_write_second)
  31. cmd_sz = 1;
  32. - flash->command[0] = nor->program_opcode;
  33. - m25p_addr2cmd(nor, to, flash->command);
  34. + command[0] = nor->program_opcode;
  35. + m25p_addr2cmd(nor, to, command);
  36. + memcpy(&command[cmd_sz], buf, len);
  37. - t[0].tx_buf = flash->command;
  38. - t[0].len = cmd_sz;
  39. + t[0].tx_buf = command;
  40. + t[0].len = cmd_sz + len;
  41. spi_message_add_tail(&t[0], &m);
  42. - t[1].tx_buf = buf;
  43. - t[1].len = len;
  44. - spi_message_add_tail(&t[1], &m);
  45. -
  46. spi_sync(spi, &m);
  47. *retlen += m.actual_length - cmd_sz;
  48. +
  49. + kfree(command);
  50. }
  51. static inline unsigned int m25p80_rx_nbits(struct spi_nor *nor)