winbond.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. * Copyright 2008, Network Appliance Inc.
  3. * Author: Jason McMullan <mcmullan <at> netapp.com>
  4. * Licensed under the GPL-2 or later.
  5. */
  6. #include <common.h>
  7. #include <malloc.h>
  8. #include <spi_flash.h>
  9. #include "spi_flash_internal.h"
  10. struct winbond_spi_flash_params {
  11. uint16_t id;
  12. uint16_t nr_blocks;
  13. const char *name;
  14. };
  15. static const struct winbond_spi_flash_params winbond_spi_flash_table[] = {
  16. {
  17. .id = 0x2014,
  18. .nr_blocks = 16,
  19. .name = "W25P80",
  20. },
  21. {
  22. .id = 0x2015,
  23. .nr_blocks = 32,
  24. .name = "W25P16",
  25. },
  26. {
  27. .id = 0x2016,
  28. .nr_blocks = 64,
  29. .name = "W25P32",
  30. },
  31. {
  32. .id = 0x3013,
  33. .nr_blocks = 8,
  34. .name = "W25X40",
  35. },
  36. {
  37. .id = 0x3015,
  38. .nr_blocks = 32,
  39. .name = "W25X16",
  40. },
  41. {
  42. .id = 0x3016,
  43. .nr_blocks = 64,
  44. .name = "W25X32",
  45. },
  46. {
  47. .id = 0x3017,
  48. .nr_blocks = 128,
  49. .name = "W25X64",
  50. },
  51. {
  52. .id = 0x4014,
  53. .nr_blocks = 16,
  54. .name = "W25Q80BL",
  55. },
  56. {
  57. .id = 0x4015,
  58. .nr_blocks = 32,
  59. .name = "W25Q16",
  60. },
  61. {
  62. .id = 0x4016,
  63. .nr_blocks = 64,
  64. .name = "W25Q32",
  65. },
  66. {
  67. .id = 0x4017,
  68. .nr_blocks = 128,
  69. .name = "W25Q64",
  70. },
  71. {
  72. .id = 0x4018,
  73. .nr_blocks = 256,
  74. .name = "W25Q128",
  75. },
  76. {
  77. .id = 0x4019,
  78. .nr_blocks = 512,
  79. .name = "W25Q256",
  80. },
  81. {
  82. .id = 0x5014,
  83. .nr_blocks = 16,
  84. .name = "W25Q80BW",
  85. },
  86. {
  87. .id = 0x6016,
  88. .nr_blocks = 64,
  89. .name = "W25Q32DW",
  90. },
  91. {
  92. .id = 0x6017,
  93. .nr_blocks = 128,
  94. .name = "W25Q64DW",
  95. },
  96. };
  97. struct spi_flash *spi_flash_probe_winbond(struct spi_slave *spi, u8 *idcode)
  98. {
  99. const struct winbond_spi_flash_params *params;
  100. struct spi_flash *flash;
  101. unsigned int i;
  102. for (i = 0; i < ARRAY_SIZE(winbond_spi_flash_table); i++) {
  103. params = &winbond_spi_flash_table[i];
  104. if (params->id == ((idcode[1] << 8) | idcode[2]))
  105. break;
  106. }
  107. if (i == ARRAY_SIZE(winbond_spi_flash_table)) {
  108. debug("SF: Unsupported Winbond ID %02x%02x\n",
  109. idcode[1], idcode[2]);
  110. return NULL;
  111. }
  112. flash = spi_flash_alloc_base(spi, params->name);
  113. if (!flash) {
  114. debug("SF: Failed to allocate memory\n");
  115. return NULL;
  116. }
  117. flash->page_size = 256;
  118. flash->sector_size = (idcode[1] == 0x20) ? 65536 : 4096;
  119. flash->size = 4096 * 16 * params->nr_blocks;
  120. return flash;
  121. }