Rajeshwari Shinde | 22ea934 | 2013-01-22 20:30:18 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Gigadevice SPI flash driver |
| 3 | * Copyright 2013, Samsung Electronics Co., Ltd. |
| 4 | * Author: Banajit Goswami <banajit.g@samsung.com> |
| 5 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 6 | * SPDX-License-Identifier: GPL-2.0+ |
Rajeshwari Shinde | 22ea934 | 2013-01-22 20:30:18 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <common.h> |
| 10 | #include <malloc.h> |
| 11 | #include <spi_flash.h> |
| 12 | |
| 13 | #include "spi_flash_internal.h" |
| 14 | |
| 15 | struct gigadevice_spi_flash_params { |
| 16 | uint16_t id; |
| 17 | uint16_t nr_blocks; |
| 18 | const char *name; |
| 19 | }; |
| 20 | |
| 21 | static const struct gigadevice_spi_flash_params gigadevice_spi_flash_table[] = { |
| 22 | { |
| 23 | .id = 0x6016, |
| 24 | .nr_blocks = 64, |
| 25 | .name = "GD25LQ", |
| 26 | }, |
| 27 | { |
| 28 | .id = 0x4017, |
| 29 | .nr_blocks = 128, |
| 30 | .name = "GD25Q64B", |
| 31 | }, |
| 32 | }; |
| 33 | |
| 34 | struct spi_flash *spi_flash_probe_gigadevice(struct spi_slave *spi, u8 *idcode) |
| 35 | { |
| 36 | const struct gigadevice_spi_flash_params *params; |
| 37 | struct spi_flash *flash; |
| 38 | unsigned int i; |
| 39 | |
| 40 | for (i = 0; i < ARRAY_SIZE(gigadevice_spi_flash_table); i++) { |
| 41 | params = &gigadevice_spi_flash_table[i]; |
| 42 | if (params->id == ((idcode[1] << 8) | idcode[2])) |
| 43 | break; |
| 44 | } |
| 45 | |
| 46 | if (i == ARRAY_SIZE(gigadevice_spi_flash_table)) { |
| 47 | debug("SF: Unsupported Gigadevice ID %02x%02x\n", |
Jagannadha Sutradharudu Teki | dc221ac | 2013-07-29 22:43:57 +0530 | [diff] [blame] | 48 | idcode[1], idcode[2]); |
Rajeshwari Shinde | 22ea934 | 2013-01-22 20:30:18 +0000 | [diff] [blame] | 49 | return NULL; |
| 50 | } |
| 51 | |
| 52 | flash = spi_flash_alloc_base(spi, params->name); |
| 53 | if (!flash) { |
| 54 | debug("SF: Failed to allocate memory\n"); |
| 55 | return NULL; |
| 56 | } |
| 57 | /* page_size */ |
| 58 | flash->page_size = 256; |
| 59 | /* sector_size = page_size * pages_per_sector */ |
| 60 | flash->sector_size = flash->page_size * 16; |
| 61 | /* size = sector_size * sector_per_block * number of blocks */ |
| 62 | flash->size = flash->sector_size * 16 * params->nr_blocks; |
| 63 | |
| 64 | return flash; |
| 65 | } |