gigadevice.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * Gigadevice SPI flash driver
  3. * Copyright 2013, Samsung Electronics Co., Ltd.
  4. * Author: Banajit Goswami <banajit.g@samsung.com>
  5. *
  6. * See file CREDITS for list of people who contributed to this
  7. * project.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License as
  11. * published by the Free Software Foundation; either version 2 of
  12. * the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  22. * MA 02111-1307 USA
  23. */
  24. #include <common.h>
  25. #include <malloc.h>
  26. #include <spi_flash.h>
  27. #include "spi_flash_internal.h"
  28. struct gigadevice_spi_flash_params {
  29. uint16_t id;
  30. uint16_t nr_blocks;
  31. const char *name;
  32. };
  33. static const struct gigadevice_spi_flash_params gigadevice_spi_flash_table[] = {
  34. {
  35. .id = 0x6016,
  36. .nr_blocks = 64,
  37. .name = "GD25LQ",
  38. },
  39. {
  40. .id = 0x4017,
  41. .nr_blocks = 128,
  42. .name = "GD25Q64B",
  43. },
  44. };
  45. struct spi_flash *spi_flash_probe_gigadevice(struct spi_slave *spi, u8 *idcode)
  46. {
  47. const struct gigadevice_spi_flash_params *params;
  48. struct spi_flash *flash;
  49. unsigned int i;
  50. for (i = 0; i < ARRAY_SIZE(gigadevice_spi_flash_table); i++) {
  51. params = &gigadevice_spi_flash_table[i];
  52. if (params->id == ((idcode[1] << 8) | idcode[2]))
  53. break;
  54. }
  55. if (i == ARRAY_SIZE(gigadevice_spi_flash_table)) {
  56. debug("SF: Unsupported Gigadevice ID %02x%02x\n",
  57. idcode[1], idcode[2]);
  58. return NULL;
  59. }
  60. flash = spi_flash_alloc_base(spi, params->name);
  61. if (!flash) {
  62. debug("SF: Failed to allocate memory\n");
  63. return NULL;
  64. }
  65. /* page_size */
  66. flash->page_size = 256;
  67. /* sector_size = page_size * pages_per_sector */
  68. flash->sector_size = flash->page_size * 16;
  69. /* size = sector_size * sector_per_block * number of blocks */
  70. flash->size = flash->sector_size * 16 * params->nr_blocks;
  71. return flash;
  72. }