]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - drivers/mtd/spi/gigadevice.c
Merge branch 'master' of git://git.denx.de/u-boot-mpc5xxx
[karo-tx-uboot.git] / drivers / mtd / spi / gigadevice.c
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
25 #include <common.h>
26 #include <malloc.h>
27 #include <spi_flash.h>
28
29 #include "spi_flash_internal.h"
30
31 struct gigadevice_spi_flash_params {
32         uint16_t        id;
33         uint16_t        nr_blocks;
34         const char      *name;
35 };
36
37 static const struct gigadevice_spi_flash_params gigadevice_spi_flash_table[] = {
38         {
39                 .id                     = 0x6016,
40                 .nr_blocks              = 64,
41                 .name                   = "GD25LQ",
42         },
43         {
44                 .id                     = 0x4017,
45                 .nr_blocks              = 128,
46                 .name                   = "GD25Q64B",
47         },
48 };
49
50 struct spi_flash *spi_flash_probe_gigadevice(struct spi_slave *spi, u8 *idcode)
51 {
52         const struct gigadevice_spi_flash_params *params;
53         struct spi_flash *flash;
54         unsigned int i;
55
56         for (i = 0; i < ARRAY_SIZE(gigadevice_spi_flash_table); i++) {
57                 params = &gigadevice_spi_flash_table[i];
58                 if (params->id == ((idcode[1] << 8) | idcode[2]))
59                         break;
60         }
61
62         if (i == ARRAY_SIZE(gigadevice_spi_flash_table)) {
63                 debug("SF: Unsupported Gigadevice ID %02x%02x\n",
64                                 idcode[1], idcode[2]);
65                 return NULL;
66         }
67
68         flash = spi_flash_alloc_base(spi, params->name);
69         if (!flash) {
70                 debug("SF: Failed to allocate memory\n");
71                 return NULL;
72         }
73         /* page_size */
74         flash->page_size = 256;
75         /* sector_size = page_size * pages_per_sector */
76         flash->sector_size = flash->page_size * 16;
77         /* size = sector_size * sector_per_block * number of blocks */
78         flash->size = flash->sector_size * 16 * params->nr_blocks;
79
80         return flash;
81 }