eon.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * (C) Copyright 2010, ucRobotics Inc.
  3. * Author: Chong Huang <chuang@ucrobotics.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 eon_spi_flash_params {
  11. u8 idcode1;
  12. u16 nr_sectors;
  13. const char *name;
  14. };
  15. static const struct eon_spi_flash_params eon_spi_flash_table[] = {
  16. {
  17. .idcode1 = 0x16,
  18. .nr_sectors = 1024,
  19. .name = "EN25Q32B",
  20. },
  21. {
  22. .idcode1 = 0x18,
  23. .nr_sectors = 4096,
  24. .name = "EN25Q128",
  25. },
  26. };
  27. struct spi_flash *spi_flash_probe_eon(struct spi_slave *spi, u8 *idcode)
  28. {
  29. const struct eon_spi_flash_params *params;
  30. struct spi_flash *flash;
  31. unsigned int i;
  32. for (i = 0; i < ARRAY_SIZE(eon_spi_flash_table); ++i) {
  33. params = &eon_spi_flash_table[i];
  34. if (params->idcode1 == idcode[2])
  35. break;
  36. }
  37. if (i == ARRAY_SIZE(eon_spi_flash_table)) {
  38. debug("SF: Unsupported EON ID %02x\n", idcode[1]);
  39. return NULL;
  40. }
  41. flash = spi_flash_alloc_base(spi, params->name);
  42. if (!flash) {
  43. debug("SF: Failed to allocate memory\n");
  44. return NULL;
  45. }
  46. flash->page_size = 256;
  47. flash->sector_size = 256 * 16 * 16;
  48. flash->size = 256 * 16
  49. * params->nr_sectors;
  50. return flash;
  51. }