spansion.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. struct spansion_spi_flash_params {
  32. u16 idcode1;
  33. u16 idcode2;
  34. u16 pages_per_sector;
  35. u16 nr_sectors;
  36. const char *name;
  37. };
  38. static const struct spansion_spi_flash_params spansion_spi_flash_table[] = {
  39. {
  40. .idcode1 = 0x0213,
  41. .idcode2 = 0,
  42. .pages_per_sector = 256,
  43. .nr_sectors = 16,
  44. .name = "S25FL008A",
  45. },
  46. {
  47. .idcode1 = 0x0214,
  48. .idcode2 = 0,
  49. .pages_per_sector = 256,
  50. .nr_sectors = 32,
  51. .name = "S25FL016A",
  52. },
  53. {
  54. .idcode1 = 0x0215,
  55. .idcode2 = 0,
  56. .pages_per_sector = 256,
  57. .nr_sectors = 64,
  58. .name = "S25FL032A",
  59. },
  60. {
  61. .idcode1 = 0x0216,
  62. .idcode2 = 0,
  63. .pages_per_sector = 256,
  64. .nr_sectors = 128,
  65. .name = "S25FL064A",
  66. },
  67. {
  68. .idcode1 = 0x2018,
  69. .idcode2 = 0x0301,
  70. .pages_per_sector = 256,
  71. .nr_sectors = 256,
  72. .name = "S25FL128P_64K",
  73. },
  74. {
  75. .idcode1 = 0x2018,
  76. .idcode2 = 0x0300,
  77. .pages_per_sector = 1024,
  78. .nr_sectors = 64,
  79. .name = "S25FL128P_256K",
  80. },
  81. {
  82. .idcode1 = 0x0215,
  83. .idcode2 = 0x4d00,
  84. .pages_per_sector = 256,
  85. .nr_sectors = 64,
  86. .name = "S25FL032P",
  87. },
  88. {
  89. .idcode1 = 0x0216,
  90. .idcode2 = 0x4d00,
  91. .pages_per_sector = 256,
  92. .nr_sectors = 128,
  93. .name = "S25FL064P",
  94. },
  95. {
  96. .idcode1 = 0x2018,
  97. .idcode2 = 0x4d01,
  98. .pages_per_sector = 256,
  99. .nr_sectors = 256,
  100. .name = "S25FL129P_64K/S25FL128S",
  101. },
  102. {
  103. .idcode1 = 0x0219,
  104. .idcode2 = 0x4d01,
  105. .pages_per_sector = 256,
  106. .nr_sectors = 512,
  107. .name = "S25FL256S_64K",
  108. },
  109. };
  110. struct spi_flash *spi_flash_probe_spansion(struct spi_slave *spi, u8 *idcode)
  111. {
  112. const struct spansion_spi_flash_params *params;
  113. struct spi_flash *flash;
  114. unsigned int i;
  115. unsigned short jedec, ext_jedec;
  116. jedec = idcode[1] << 8 | idcode[2];
  117. ext_jedec = idcode[3] << 8 | idcode[4];
  118. for (i = 0; i < ARRAY_SIZE(spansion_spi_flash_table); i++) {
  119. params = &spansion_spi_flash_table[i];
  120. if (params->idcode1 == jedec) {
  121. if (params->idcode2 == ext_jedec)
  122. break;
  123. }
  124. }
  125. if (i == ARRAY_SIZE(spansion_spi_flash_table)) {
  126. debug("SF: Unsupported SPANSION ID %04x %04x\n", jedec, ext_jedec);
  127. return NULL;
  128. }
  129. flash = spi_flash_alloc_base(spi, params->name);
  130. if (!flash) {
  131. debug("SF: Failed to allocate memory\n");
  132. return NULL;
  133. }
  134. flash->page_size = 256;
  135. flash->sector_size = 256 * params->pages_per_sector;
  136. flash->size = flash->sector_size * params->nr_sectors;
  137. return flash;
  138. }