stmicro.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /*
  2. * (C) Copyright 2000-2002
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * Copyright 2008, Network Appliance Inc.
  6. * Jason McMullan <mcmullan@netapp.com>
  7. *
  8. * Copyright (C) 2004-2007 Freescale Semiconductor, Inc.
  9. * TsiChung Liew (Tsi-Chung.Liew@freescale.com)
  10. *
  11. * See file CREDITS for list of people who contributed to this
  12. * project.
  13. *
  14. * This program is free software; you can redistribute it and/or
  15. * modify it under the terms of the GNU General Public License as
  16. * published by the Free Software Foundation; either version 2 of
  17. * the License, or (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; if not, write to the Free Software
  26. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  27. * MA 02111-1307 USA
  28. */
  29. #include <common.h>
  30. #include <malloc.h>
  31. #include <spi_flash.h>
  32. #include "spi_flash_internal.h"
  33. /* M25Pxx-specific commands */
  34. #define CMD_M25PXX_RES 0xab /* Release from DP, and Read Signature */
  35. struct stmicro_spi_flash_params {
  36. u16 id;
  37. u16 pages_per_sector;
  38. u16 nr_sectors;
  39. const char *name;
  40. };
  41. static const struct stmicro_spi_flash_params stmicro_spi_flash_table[] = {
  42. {
  43. .id = 0x2011,
  44. .pages_per_sector = 128,
  45. .nr_sectors = 4,
  46. .name = "M25P10",
  47. },
  48. {
  49. .id = 0x2015,
  50. .pages_per_sector = 256,
  51. .nr_sectors = 32,
  52. .name = "M25P16",
  53. },
  54. {
  55. .id = 0x2012,
  56. .pages_per_sector = 256,
  57. .nr_sectors = 4,
  58. .name = "M25P20",
  59. },
  60. {
  61. .id = 0x2016,
  62. .pages_per_sector = 256,
  63. .nr_sectors = 64,
  64. .name = "M25P32",
  65. },
  66. {
  67. .id = 0x2013,
  68. .pages_per_sector = 256,
  69. .nr_sectors = 8,
  70. .name = "M25P40",
  71. },
  72. {
  73. .id = 0x2017,
  74. .pages_per_sector = 256,
  75. .nr_sectors = 128,
  76. .name = "M25P64",
  77. },
  78. {
  79. .id = 0x2014,
  80. .pages_per_sector = 256,
  81. .nr_sectors = 16,
  82. .name = "M25P80",
  83. },
  84. {
  85. .id = 0x2018,
  86. .pages_per_sector = 1024,
  87. .nr_sectors = 64,
  88. .name = "M25P128",
  89. },
  90. {
  91. .id = 0xba16,
  92. .pages_per_sector = 256,
  93. .nr_sectors = 64,
  94. .name = "N25Q32",
  95. },
  96. {
  97. .id = 0xbb16,
  98. .pages_per_sector = 256,
  99. .nr_sectors = 64,
  100. .name = "N25Q32A",
  101. },
  102. {
  103. .id = 0xba17,
  104. .pages_per_sector = 256,
  105. .nr_sectors = 128,
  106. .name = "N25Q064",
  107. },
  108. {
  109. .id = 0xbb17,
  110. .pages_per_sector = 256,
  111. .nr_sectors = 128,
  112. .name = "N25Q64A",
  113. },
  114. {
  115. .id = 0xba18,
  116. .pages_per_sector = 256,
  117. .nr_sectors = 256,
  118. .name = "N25Q128",
  119. },
  120. {
  121. .id = 0xbb18,
  122. .pages_per_sector = 256,
  123. .nr_sectors = 256,
  124. .name = "N25Q128A",
  125. },
  126. {
  127. .id = 0xba19,
  128. .pages_per_sector = 256,
  129. .nr_sectors = 512,
  130. .name = "N25Q256",
  131. },
  132. {
  133. .id = 0xbb19,
  134. .pages_per_sector = 256,
  135. .nr_sectors = 512,
  136. .name = "N25Q256A",
  137. },
  138. };
  139. struct spi_flash *spi_flash_probe_stmicro(struct spi_slave *spi, u8 * idcode)
  140. {
  141. const struct stmicro_spi_flash_params *params;
  142. struct spi_flash *flash;
  143. unsigned int i;
  144. u16 id;
  145. if (idcode[0] == 0xff) {
  146. i = spi_flash_cmd(spi, CMD_M25PXX_RES,
  147. idcode, 4);
  148. if (i)
  149. return NULL;
  150. if ((idcode[3] & 0xf0) == 0x10) {
  151. idcode[0] = 0x20;
  152. idcode[1] = 0x20;
  153. idcode[2] = idcode[3] + 1;
  154. } else
  155. return NULL;
  156. }
  157. id = ((idcode[1] << 8) | idcode[2]);
  158. for (i = 0; i < ARRAY_SIZE(stmicro_spi_flash_table); i++) {
  159. params = &stmicro_spi_flash_table[i];
  160. if (params->id == id) {
  161. break;
  162. }
  163. }
  164. if (i == ARRAY_SIZE(stmicro_spi_flash_table)) {
  165. debug("SF: Unsupported STMicro ID %04x\n", id);
  166. return NULL;
  167. }
  168. flash = spi_flash_alloc_base(spi, params->name);
  169. if (!flash) {
  170. debug("SF: Failed to allocate memory\n");
  171. return NULL;
  172. }
  173. flash->page_size = 256;
  174. flash->sector_size = 256 * params->pages_per_sector;
  175. flash->size = flash->sector_size * params->nr_sectors;
  176. return flash;
  177. }