0054-mtd-spi-nor-w25q256-respect-default-mode.patch 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. --- a/drivers/mtd/spi-nor/spi-nor.c
  2. +++ b/drivers/mtd/spi-nor/spi-nor.c
  3. @@ -142,20 +142,29 @@ static int read_fsr(struct spi_nor *nor)
  4. * location. Return the configuration register value.
  5. * Returns negative if error occurred.
  6. */
  7. -static int read_cr(struct spi_nor *nor)
  8. +static int _read_cr(struct spi_nor *nor, u8 reg)
  9. {
  10. int ret;
  11. u8 val;
  12. - ret = nor->read_reg(nor, SPINOR_OP_RDCR, &val, 1);
  13. + ret = nor->read_reg(nor, reg, &val, 1);
  14. if (ret < 0) {
  15. - dev_err(nor->dev, "error %d reading CR\n", ret);
  16. + dev_err(nor->dev, "error %d reading %s\n", ret,
  17. + (reg==SPINOR_OP_RDCR)?"CR":"XCR");
  18. return ret;
  19. }
  20. return val;
  21. }
  22. +static inline int read_cr(struct spi_nor *nor) {
  23. + return _read_cr(nor, SPINOR_OP_RDCR);
  24. +}
  25. +
  26. +static inline int read_xcr(struct spi_nor *nor) {
  27. + return _read_cr(nor, SPINOR_OP_RDXCR);
  28. +}
  29. +
  30. /*
  31. * Write status register 1 byte
  32. * Returns negative if error occurred.
  33. @@ -2889,9 +2898,16 @@ int spi_nor_scan(struct spi_nor *nor, co
  34. } else if (mtd->size > 0x1000000) {
  35. /* enable 4-byte addressing if the device exceeds 16MiB */
  36. nor->addr_width = 4;
  37. - if (info->flags & SPI_NOR_4B_READ_OP)
  38. - spi_nor_set_4byte_read(nor, info);
  39. - else if (JEDEC_MFR(info) == SNOR_MFR_SPANSION ||
  40. + if (info->flags & SPI_NOR_4B_READ_OP) {
  41. + if (JEDEC_MFR(info) == SNOR_MFR_WINBOND) {
  42. + ret = read_xcr(nor);
  43. + if (!(ret > 0 && (ret & XCR_DEF_4B_ADDR_MODE)))
  44. + spi_nor_set_4byte_read(nor, info);
  45. + else
  46. + set_4byte(nor, info, 1);
  47. + } else
  48. + spi_nor_set_4byte_read(nor, info);
  49. + } else if (JEDEC_MFR(info) == SNOR_MFR_SPANSION ||
  50. info->flags & SPI_NOR_4B_OPCODES)
  51. spi_nor_set_4byte_opcodes(nor, info);
  52. else
  53. --- a/include/linux/mtd/spi-nor.h
  54. +++ b/include/linux/mtd/spi-nor.h
  55. @@ -103,6 +103,7 @@
  56. #define SPINOR_OP_EN4B 0xb7 /* Enter 4-byte mode */
  57. #define SPINOR_OP_EX4B 0xe9 /* Exit 4-byte mode */
  58. #define SPINOR_OP_WREAR 0xc5 /* Write extended address register */
  59. +#define SPINOR_OP_RDXCR 0x15 /* Read extended configuration register */
  60. /* Used for Spansion flashes only. */
  61. #define SPINOR_OP_BRWR 0x17 /* Bank register write */
  62. @@ -135,6 +136,7 @@
  63. /* Configuration Register bits. */
  64. #define CR_QUAD_EN_SPAN BIT(1) /* Spansion Quad I/O */
  65. +#define XCR_DEF_4B_ADDR_MODE BIT(1) /* Winbond 4B mode default */
  66. /* Status Register 2 bits. */
  67. #define SR2_QUAD_EN_BIT7 BIT(7)