winbond.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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 = 0x3013,
  18. .nr_blocks = 8,
  19. .name = "W25X40",
  20. },
  21. {
  22. .id = 0x3015,
  23. .nr_blocks = 32,
  24. .name = "W25X16",
  25. },
  26. {
  27. .id = 0x3016,
  28. .nr_blocks = 64,
  29. .name = "W25X32",
  30. },
  31. {
  32. .id = 0x3017,
  33. .nr_blocks = 128,
  34. .name = "W25X64",
  35. },
  36. {
  37. .id = 0x4014,
  38. .nr_blocks = 16,
  39. .name = "W25Q80BL",
  40. },
  41. {
  42. .id = 0x4015,
  43. .nr_blocks = 32,
  44. .name = "W25Q16",
  45. },
  46. {
  47. .id = 0x4016,
  48. .nr_blocks = 64,
  49. .name = "W25Q32",
  50. },
  51. {
  52. .id = 0x4017,
  53. .nr_blocks = 128,
  54. .name = "W25Q64",
  55. },
  56. {
  57. .id = 0x4018,
  58. .nr_blocks = 256,
  59. .name = "W25Q128",
  60. },
  61. {
  62. .id = 0x5014,
  63. .nr_blocks = 128,
  64. .name = "W25Q80",
  65. },
  66. {
  67. .id = 0x6017,
  68. .nr_blocks = 128,
  69. .name = "W25Q64DW",
  70. },
  71. };
  72. struct spi_flash *spi_flash_probe_winbond(struct spi_slave *spi, u8 *idcode)
  73. {
  74. const struct winbond_spi_flash_params *params;
  75. struct spi_flash *flash;
  76. unsigned int i;
  77. for (i = 0; i < ARRAY_SIZE(winbond_spi_flash_table); i++) {
  78. params = &winbond_spi_flash_table[i];
  79. if (params->id == ((idcode[1] << 8) | idcode[2]))
  80. break;
  81. }
  82. if (i == ARRAY_SIZE(winbond_spi_flash_table)) {
  83. debug("SF: Unsupported Winbond ID %02x%02x\n",
  84. idcode[1], idcode[2]);
  85. return NULL;
  86. }
  87. flash = spi_flash_alloc_base(spi, params->name);
  88. if (!flash) {
  89. debug("SF: Failed to allocate memory\n");
  90. return NULL;
  91. }
  92. flash->page_size = 256;
  93. flash->sector_size = 4096;
  94. flash->size = 4096 * 16 * params->nr_blocks;
  95. return flash;
  96. }