0019-mtd-spi-nor-fix-support-of-Macronix-memories.patch 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. From 4e094634d1995e279f8bc5eb92463295cb894c76 Mon Sep 17 00:00:00 2001
  2. From: Cyrille Pitchen <cyrille.pitchen@atmel.com>
  3. Date: Fri, 8 Jan 2016 17:02:16 +0100
  4. Subject: [PATCH 19/33] mtd: spi-nor: fix support of Macronix memories
  5. This patch fixes the support of Macronix memories. Especially we avoid
  6. updating the Status Register when not needed as the Quad Enable (QE) bit
  7. is a non-volatile bit.
  8. Also we add comments to explain why we use some Fast Read op codes rather
  9. than others.
  10. Signed-off-by: Cyrille Pitchen <cyrille.pitchen@atmel.com>
  11. ---
  12. drivers/mtd/spi-nor/spi-nor.c | 81 ++++++++++++++++++++++++++++++++++++++-----
  13. 1 file changed, 72 insertions(+), 9 deletions(-)
  14. diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c
  15. index 889af12..1b1f5a6 100644
  16. --- a/drivers/mtd/spi-nor/spi-nor.c
  17. +++ b/drivers/mtd/spi-nor/spi-nor.c
  18. @@ -1107,6 +1107,11 @@ static int macronix_quad_enable(struct spi_nor *nor)
  19. val = read_sr(nor);
  20. if (val < 0)
  21. return val;
  22. +
  23. + if (likely(val & SR_QUAD_EN_MX))
  24. + return 0;
  25. + dev_warn(nor->dev, "Macronix Quad mode disabled, enable it\n");
  26. +
  27. write_enable(nor);
  28. write_sr(nor, val | SR_QUAD_EN_MX);
  29. @@ -1161,21 +1166,73 @@ static int spansion_quad_enable(struct spi_nor *nor)
  30. return 0;
  31. }
  32. +static int macronix_set_quad_mode(struct spi_nor *nor)
  33. +{
  34. + int status;
  35. +
  36. + /* Check whether the QPI mode is enabled. */
  37. + if (nor->read_proto == SNOR_PROTO_4_4_4) {
  38. + /*
  39. + * Since the QPI mode is enabled, the Quad Enabled (QE)
  40. + * non-volatile bit is already set.
  41. + * However in QPI mode, only the Fast Read 1-4-4 (0xeb)
  42. + * op code is supported.
  43. + * WARNING: we should take care about the performance
  44. + * enhance toggling bits P0-P7 written during the
  45. + * dummy/mode cycles to avoid entering the continuous
  46. + * read (performance enhance) mode by mistake!
  47. + */
  48. + nor->read_opcode = SPINOR_OP_READ_1_4_4;
  49. + return 0;
  50. + }
  51. +
  52. + /*
  53. + * The QPI mode is disabled but we still need to set the QE bit:
  54. + * this disables the reset and write protect features and
  55. + * frees the associated pins so they can be used as the 3rd
  56. + * and 4th I/O lines required by Quad SPI commands.
  57. + * Also we'd rather use the Fast Read 1-1-4 (0x6b) op code than
  58. + * the Fast Read 1-4-4 (0xeb) op code so we don't care about
  59. + * entering the continuous read mode by mistake if some
  60. + * performance enhance toggling bits P0-P7 were written during
  61. + * dummy/mode cycles.
  62. + */
  63. + status = macronix_quad_enable(nor);
  64. + if (status) {
  65. + dev_err(nor->dev, "Macronix quad-read not enabled\n");
  66. + return status;
  67. + }
  68. + nor->read_proto = SNOR_PROTO_1_1_4;
  69. + nor->read_opcode = SPINOR_OP_READ_1_1_4;
  70. + return 0;
  71. +}
  72. +
  73. +/*
  74. + * For both Macronix Dual and Single modes, we don't care about the value of
  75. + * the Quad Enabled (QE) bit since the memory still replies to Dual or Single
  76. + * SPI commands.
  77. + */
  78. +
  79. +static int macronix_set_dual_mode(struct spi_nor *nor)
  80. +{
  81. + nor->read_proto = SNOR_PROTO_1_1_2;
  82. + nor->read_opcode = SPINOR_OP_READ_1_1_2;
  83. + return 0;
  84. +}
  85. +
  86. +static int macronix_set_single_mode(struct spi_nor *nor)
  87. +{
  88. + nor->read_proto = SNOR_PROTO_1_1_1;
  89. + return 0;
  90. +}
  91. +
  92. static int set_quad_mode(struct spi_nor *nor, const struct flash_info *info)
  93. {
  94. int status;
  95. switch (JEDEC_MFR(info)) {
  96. case SNOR_MFR_MACRONIX:
  97. - status = macronix_quad_enable(nor);
  98. - if (status) {
  99. - dev_err(nor->dev, "Macronix quad-read not enabled\n");
  100. - return -EINVAL;
  101. - }
  102. - /* Check whether Macronix QPI mode is enabled. */
  103. - if (nor->read_proto != SNOR_PROTO_4_4_4)
  104. - nor->read_proto = SNOR_PROTO_1_1_4;
  105. - break;
  106. + return macronix_set_quad_mode(nor);
  107. case SNOR_MFR_MICRON:
  108. /* Check whether Micron Quad mode is enabled. */
  109. @@ -1203,6 +1260,9 @@ static int set_quad_mode(struct spi_nor *nor, const struct flash_info *info)
  110. static int set_dual_mode(struct spi_nor *nor, const struct flash_info *info)
  111. {
  112. switch (JEDEC_MFR(info)) {
  113. + case SNOR_MFR_MACRONIX:
  114. + return macronix_set_dual_mode(nor);
  115. +
  116. case SNOR_MFR_MICRON:
  117. /* Check whether Micron Dual mode is enabled. */
  118. if (nor->read_proto != SNOR_PROTO_2_2_2)
  119. @@ -1221,6 +1281,9 @@ static int set_dual_mode(struct spi_nor *nor, const struct flash_info *info)
  120. static int set_single_mode(struct spi_nor *nor, const struct flash_info *info)
  121. {
  122. switch (JEDEC_MFR(info)) {
  123. + case SNOR_MFR_MACRONIX:
  124. + return macronix_set_single_mode(nor);
  125. +
  126. default:
  127. nor->read_proto = SNOR_PROTO_1_1_1;
  128. break;
  129. --
  130. 2.8.1