blob: b42581a70f80a48e9590608835dcce33dbf92518 [file] [log] [blame]
Rajeshwari Shinde22ea9342013-01-22 20:30:18 +00001/*
2 * Gigadevice SPI flash driver
3 * Copyright 2013, Samsung Electronics Co., Ltd.
4 * Author: Banajit Goswami <banajit.g@samsung.com>
5 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02006 * SPDX-License-Identifier: GPL-2.0+
Rajeshwari Shinde22ea9342013-01-22 20:30:18 +00007 */
8
9#include <common.h>
10#include <malloc.h>
11#include <spi_flash.h>
12
13#include "spi_flash_internal.h"
14
15struct gigadevice_spi_flash_params {
16 uint16_t id;
17 uint16_t nr_blocks;
18 const char *name;
19};
20
21static 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
34struct 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 Tekidc221ac2013-07-29 22:43:57 +053048 idcode[1], idcode[2]);
Rajeshwari Shinde22ea9342013-01-22 20:30:18 +000049 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}