0006-sf-add-generic-support-for-4-byte-address-mode.patch 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. From fb9ed0ef6f0ba6b6535c64dcfcf45c161723e56f Mon Sep 17 00:00:00 2001
  2. From: Daniel Schwierzeck <[email protected]>
  3. Date: Tue, 6 Nov 2012 19:31:38 +0100
  4. Subject: sf: add generic support for 4-byte address mode
  5. Signed-off-by: Daniel Schwierzeck <[email protected]>
  6. --- a/drivers/mtd/spi/spi_flash.c
  7. +++ b/drivers/mtd/spi/spi_flash.c
  8. @@ -18,19 +18,35 @@
  9. static void spi_flash_addr(struct spi_flash *flash, u32 addr, u8 *cmd, u8 *cmd_len)
  10. {
  11. /* cmd[0] is actual command */
  12. - cmd[1] = addr >> 16;
  13. - cmd[2] = addr >> 8;
  14. - cmd[3] = addr >> 0;
  15. - *cmd_len = 4;
  16. + if (spi_flash_use_4byte_mode(flash)) {
  17. + cmd[1] = addr >> 24;
  18. + cmd[2] = addr >> 16;
  19. + cmd[3] = addr >> 8;
  20. + cmd[4] = addr >> 0;
  21. + *cmd_len = 5;
  22. + } else {
  23. + cmd[1] = addr >> 16;
  24. + cmd[2] = addr >> 8;
  25. + cmd[3] = addr >> 0;
  26. + *cmd_len = 4;
  27. + }
  28. }
  29. static void spi_flash_page_addr(struct spi_flash *flash, u32 page_addr, u32 byte_addr, u8 *cmd, u8 *cmd_len)
  30. {
  31. /* cmd[0] is actual command */
  32. - cmd[1] = page_addr >> 8;
  33. - cmd[2] = page_addr >> 0;
  34. - cmd[3] = byte_addr;
  35. - *cmd_len = 4;
  36. + if (spi_flash_use_4byte_mode(flash)) {
  37. + cmd[1] = page_addr >> 16;
  38. + cmd[2] = page_addr >> 8;
  39. + cmd[3] = page_addr >> 0;
  40. + cmd[4] = byte_addr;
  41. + *cmd_len = 5;
  42. + } else {
  43. + cmd[1] = page_addr >> 8;
  44. + cmd[2] = page_addr >> 0;
  45. + cmd[3] = byte_addr;
  46. + *cmd_len = 4;
  47. + }
  48. }
  49. static int spi_flash_read_write(struct spi_slave *spi,
  50. @@ -81,7 +97,7 @@ int spi_flash_cmd_write_multi(struct spi
  51. unsigned long page_addr, byte_addr, page_size;
  52. size_t chunk_len, actual;
  53. int ret;
  54. - u8 cmd[4], cmd_len;
  55. + u8 cmd[5], cmd_len;
  56. page_size = flash->page_size;
  57. page_addr = offset / page_size;
  58. @@ -99,8 +115,8 @@ int spi_flash_cmd_write_multi(struct spi
  59. spi_flash_page_addr(flash, page_addr, byte_addr, cmd, &cmd_len);
  60. - debug("PP: 0x%p => cmd = { 0x%02x 0x%02x%02x%02x } chunk_len = %zu\n",
  61. - buf + actual, cmd[0], cmd[1], cmd[2], cmd[3], chunk_len);
  62. + debug("PP: 0x%p => cmd = { 0x%02x 0x%02x%02x%02x%02x } chunk_len = %zu\n",
  63. + buf + actual, cmd[0], cmd[1], cmd[2], cmd[3], cmd[4], chunk_len);
  64. ret = spi_flash_cmd_write_enable(flash);
  65. if (ret < 0) {
  66. @@ -146,7 +162,7 @@ int spi_flash_read_common(struct spi_fla
  67. int spi_flash_cmd_read_fast(struct spi_flash *flash, u32 offset,
  68. size_t len, void *data)
  69. {
  70. - u8 cmd[5], cmd_len;
  71. + u8 cmd[6], cmd_len;
  72. cmd[0] = CMD_READ_ARRAY_FAST;
  73. spi_flash_addr(flash, offset, cmd, &cmd_len);
  74. @@ -202,7 +218,7 @@ int spi_flash_cmd_erase(struct spi_flash
  75. {
  76. u32 start, end, erase_size;
  77. int ret;
  78. - u8 cmd[4], cmd_len;
  79. + u8 cmd[5], cmd_len;
  80. erase_size = flash->sector_size;
  81. if (offset % erase_size || len % erase_size) {
  82. @@ -227,8 +243,8 @@ int spi_flash_cmd_erase(struct spi_flash
  83. spi_flash_addr(flash, offset, cmd, &cmd_len);
  84. offset += erase_size;
  85. - debug("SF: erase %2x %2x %2x %2x (%x)\n", cmd[0], cmd[1],
  86. - cmd[2], cmd[3], offset);
  87. + debug("SF: erase %2x %2x %2x %2x %2x (%x)\n", cmd[0], cmd[1],
  88. + cmd[2], cmd[3], cmd[4], offset);
  89. ret = spi_flash_cmd_write_enable(flash);
  90. if (ret)
  91. @@ -409,6 +425,12 @@ int spi_flash_probe_spl(struct spi_flash
  92. goto err_manufacturer_probe;
  93. }
  94. + ret = spi_flash_set_4byte_mode(flash);
  95. + if (ret) {
  96. + debug("SF: Failed to enable 4 byte mode: %d\n", ret);
  97. + goto err_manufacturer_probe;
  98. + }
  99. +
  100. spi_release_bus(spi);
  101. return 0;
  102. --- a/drivers/mtd/spi/spi_flash_internal.h
  103. +++ b/drivers/mtd/spi/spi_flash_internal.h
  104. @@ -97,6 +97,31 @@ int spi_flash_cmd_wait_ready(struct spi_
  105. /* Erase sectors. */
  106. int spi_flash_cmd_erase(struct spi_flash *flash, u32 offset, size_t len);
  107. +#ifdef CONFIG_SPI_FLASH_4BYTE_MODE
  108. +static inline int spi_flash_use_4byte_mode(struct spi_flash *flash)
  109. +{
  110. + return NULL != flash->set_4byte_mode;
  111. +}
  112. +
  113. +static inline int spi_flash_set_4byte_mode(struct spi_flash *flash)
  114. +{
  115. + if (spi_flash_use_4byte_mode(flash))
  116. + return flash->set_4byte_mode(flash);
  117. +
  118. + return 0;
  119. +}
  120. +#else
  121. +static inline int spi_flash_use_4byte_mode(struct spi_flash *flash)
  122. +{
  123. + return 0;
  124. +}
  125. +
  126. +static inline int spi_flash_set_4byte_mode(struct spi_flash *flash)
  127. +{
  128. + return 0;
  129. +}
  130. +#endif
  131. +
  132. /* Manufacturer-specific probe functions */
  133. int spi_flash_probe_spansion(struct spi_flash *flash, u8 *idcode);
  134. int spi_flash_probe_atmel(struct spi_flash *flash, u8 *idcode);
  135. --- a/include/spi_flash.h
  136. +++ b/include/spi_flash.h
  137. @@ -46,6 +46,9 @@ struct spi_flash {
  138. size_t len, const void *buf);
  139. int (*erase)(struct spi_flash *flash, u32 offset,
  140. size_t len);
  141. +#ifdef CONFIG_SPI_FLASH_4BYTE_MODE
  142. + int (*set_4byte_mode)(struct spi_flash *flash);
  143. +#endif
  144. };
  145. struct spi_flash *spi_flash_probe(unsigned int bus, unsigned int cs,