spansion.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /*
  2. * Copyright (C) 2009 Freescale Semiconductor, Inc.
  3. *
  4. * Author: Mingkai Hu (Mingkai.hu@freescale.com)
  5. * Based on stmicro.c by Wolfgang Denk (wd@denx.de),
  6. * TsiChung Liew (Tsi-Chung.Liew@freescale.com),
  7. * and Jason McMullan (mcmullan@netapp.com)
  8. *
  9. * See file CREDITS for list of people who contributed to this
  10. * project.
  11. *
  12. * This program is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU General Public License as
  14. * published by the Free Software Foundation; either version 2 of
  15. * the License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; if not, write to the Free Software
  24. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  25. * MA 02111-1307 USA
  26. */
  27. #include <common.h>
  28. #include <malloc.h>
  29. #include <spi_flash.h>
  30. #include "spi_flash_internal.h"
  31. /* S25FLxx-specific commands */
  32. #define CMD_S25FLXX_READ 0x03 /* Read Data Bytes */
  33. #define CMD_S25FLXX_FAST_READ 0x0b /* Read Data Bytes at Higher Speed */
  34. #define CMD_S25FLXX_READID 0x90 /* Read Manufacture ID and Device ID */
  35. #define CMD_S25FLXX_WREN 0x06 /* Write Enable */
  36. #define CMD_S25FLXX_WRDI 0x04 /* Write Disable */
  37. #define CMD_S25FLXX_RDSR 0x05 /* Read Status Register */
  38. #define CMD_S25FLXX_WRSR 0x01 /* Write Status Register */
  39. #define CMD_S25FLXX_PP 0x02 /* Page Program */
  40. #define CMD_S25FLXX_SE 0xd8 /* Sector Erase */
  41. #define CMD_S25FLXX_BE 0xc7 /* Bulk Erase */
  42. #define CMD_S25FLXX_DP 0xb9 /* Deep Power-down */
  43. #define CMD_S25FLXX_RES 0xab /* Release from DP, and Read Signature */
  44. #define SPSN_ID_S25FL008A 0x0213
  45. #define SPSN_ID_S25FL016A 0x0214
  46. #define SPSN_ID_S25FL032A 0x0215
  47. #define SPSN_ID_S25FL064A 0x0216
  48. #define SPSN_ID_S25FL128P 0x2018
  49. #define SPSN_EXT_ID_S25FL128P_256KB 0x0300
  50. #define SPSN_EXT_ID_S25FL128P_64KB 0x0301
  51. #define SPSN_EXT_ID_S25FL032P 0x4d00
  52. struct spansion_spi_flash_params {
  53. u16 idcode1;
  54. u16 idcode2;
  55. u16 page_size;
  56. u16 pages_per_sector;
  57. u16 nr_sectors;
  58. const char *name;
  59. };
  60. static const struct spansion_spi_flash_params spansion_spi_flash_table[] = {
  61. {
  62. .idcode1 = SPSN_ID_S25FL008A,
  63. .idcode2 = 0,
  64. .page_size = 256,
  65. .pages_per_sector = 256,
  66. .nr_sectors = 16,
  67. .name = "S25FL008A",
  68. },
  69. {
  70. .idcode1 = SPSN_ID_S25FL016A,
  71. .idcode2 = 0,
  72. .page_size = 256,
  73. .pages_per_sector = 256,
  74. .nr_sectors = 32,
  75. .name = "S25FL016A",
  76. },
  77. {
  78. .idcode1 = SPSN_ID_S25FL032A,
  79. .idcode2 = 0,
  80. .page_size = 256,
  81. .pages_per_sector = 256,
  82. .nr_sectors = 64,
  83. .name = "S25FL032A",
  84. },
  85. {
  86. .idcode1 = SPSN_ID_S25FL064A,
  87. .idcode2 = 0,
  88. .page_size = 256,
  89. .pages_per_sector = 256,
  90. .nr_sectors = 128,
  91. .name = "S25FL064A",
  92. },
  93. {
  94. .idcode1 = SPSN_ID_S25FL128P,
  95. .idcode2 = SPSN_EXT_ID_S25FL128P_64KB,
  96. .page_size = 256,
  97. .pages_per_sector = 256,
  98. .nr_sectors = 256,
  99. .name = "S25FL128P_64K",
  100. },
  101. {
  102. .idcode1 = SPSN_ID_S25FL128P,
  103. .idcode2 = SPSN_EXT_ID_S25FL128P_256KB,
  104. .page_size = 256,
  105. .pages_per_sector = 1024,
  106. .nr_sectors = 64,
  107. .name = "S25FL128P_256K",
  108. },
  109. {
  110. .idcode1 = SPSN_ID_S25FL032A,
  111. .idcode2 = SPSN_EXT_ID_S25FL032P,
  112. .page_size = 256,
  113. .pages_per_sector = 256,
  114. .nr_sectors = 64,
  115. .name = "S25FL032P",
  116. },
  117. };
  118. static int spansion_erase(struct spi_flash *flash, u32 offset, size_t len)
  119. {
  120. return spi_flash_cmd_erase(flash, CMD_S25FLXX_SE, offset, len);
  121. }
  122. struct spi_flash *spi_flash_probe_spansion(struct spi_slave *spi, u8 *idcode)
  123. {
  124. const struct spansion_spi_flash_params *params;
  125. struct spi_flash *flash;
  126. unsigned int i;
  127. unsigned short jedec, ext_jedec;
  128. jedec = idcode[1] << 8 | idcode[2];
  129. ext_jedec = idcode[3] << 8 | idcode[4];
  130. for (i = 0; i < ARRAY_SIZE(spansion_spi_flash_table); i++) {
  131. params = &spansion_spi_flash_table[i];
  132. if (params->idcode1 == jedec) {
  133. if (params->idcode2 == ext_jedec)
  134. break;
  135. }
  136. }
  137. if (i == ARRAY_SIZE(spansion_spi_flash_table)) {
  138. debug("SF: Unsupported SPANSION ID %04x %04x\n", jedec, ext_jedec);
  139. return NULL;
  140. }
  141. flash = malloc(sizeof(*flash));
  142. if (!flash) {
  143. debug("SF: Failed to allocate memory\n");
  144. return NULL;
  145. }
  146. flash->spi = spi;
  147. flash->name = params->name;
  148. flash->write = spi_flash_cmd_write_multi;
  149. flash->erase = spansion_erase;
  150. flash->read = spi_flash_cmd_read_fast;
  151. flash->page_size = params->page_size;
  152. flash->sector_size = params->page_size * params->pages_per_sector;
  153. flash->size = flash->sector_size * params->nr_sectors;
  154. return flash;
  155. }