]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - drivers/mtd/spi/spansion.c
Merge branch 'master' of git://git.denx.de/u-boot-microblaze
[karo-tx-uboot.git] / drivers / mtd / spi / spansion.c
1 /*
2  * Copyright (C) 2009 Freescale Semiconductor, Inc.
3  *
4  * Author: Mingkai Hu (Mingkai.hu@freescale.com)
5  * Based on stmicro.c by Wolfgang Denk (wd@denx.de),
6  * TsiChung Liew (Tsi-Chung.Liew@freescale.com),
7  * and  Jason McMullan (mcmullan@netapp.com)
8  *
9  * See file CREDITS for list of people who contributed to this
10  * project.
11  *
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License as
14  * published by the Free Software Foundation; either version 2 of
15  * the License, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
25  * MA 02111-1307 USA
26  */
27
28 #include <common.h>
29 #include <malloc.h>
30 #include <spi_flash.h>
31
32 #include "spi_flash_internal.h"
33
34 struct spansion_spi_flash_params {
35         u16 idcode1;
36         u16 idcode2;
37         u16 pages_per_sector;
38         u16 nr_sectors;
39         const char *name;
40 };
41
42 static const struct spansion_spi_flash_params spansion_spi_flash_table[] = {
43         {
44                 .idcode1 = 0x0213,
45                 .idcode2 = 0,
46                 .pages_per_sector = 256,
47                 .nr_sectors = 16,
48                 .name = "S25FL008A",
49         },
50         {
51                 .idcode1 = 0x0214,
52                 .idcode2 = 0,
53                 .pages_per_sector = 256,
54                 .nr_sectors = 32,
55                 .name = "S25FL016A",
56         },
57         {
58                 .idcode1 = 0x0215,
59                 .idcode2 = 0,
60                 .pages_per_sector = 256,
61                 .nr_sectors = 64,
62                 .name = "S25FL032A",
63         },
64         {
65                 .idcode1 = 0x0216,
66                 .idcode2 = 0,
67                 .pages_per_sector = 256,
68                 .nr_sectors = 128,
69                 .name = "S25FL064A",
70         },
71         {
72                 .idcode1 = 0x2018,
73                 .idcode2 = 0x0301,
74                 .pages_per_sector = 256,
75                 .nr_sectors = 256,
76                 .name = "S25FL128P_64K",
77         },
78         {
79                 .idcode1 = 0x2018,
80                 .idcode2 = 0x0300,
81                 .pages_per_sector = 1024,
82                 .nr_sectors = 64,
83                 .name = "S25FL128P_256K",
84         },
85         {
86                 .idcode1 = 0x0215,
87                 .idcode2 = 0x4d00,
88                 .pages_per_sector = 256,
89                 .nr_sectors = 64,
90                 .name = "S25FL032P",
91         },
92         {
93                 .idcode1 = 0x2018,
94                 .idcode2 = 0x4d01,
95                 .pages_per_sector = 256,
96                 .nr_sectors = 256,
97                 .name = "S25FL129P_64K",
98         },
99 };
100
101 struct spi_flash *spi_flash_probe_spansion(struct spi_slave *spi, u8 *idcode)
102 {
103         const struct spansion_spi_flash_params *params;
104         struct spi_flash *flash;
105         unsigned int i;
106         unsigned short jedec, ext_jedec;
107
108         jedec = idcode[1] << 8 | idcode[2];
109         ext_jedec = idcode[3] << 8 | idcode[4];
110
111         for (i = 0; i < ARRAY_SIZE(spansion_spi_flash_table); i++) {
112                 params = &spansion_spi_flash_table[i];
113                 if (params->idcode1 == jedec) {
114                         if (params->idcode2 == ext_jedec)
115                                 break;
116                 }
117         }
118
119         if (i == ARRAY_SIZE(spansion_spi_flash_table)) {
120                 debug("SF: Unsupported SPANSION ID %04x %04x\n", jedec, ext_jedec);
121                 return NULL;
122         }
123
124         flash = malloc(sizeof(*flash));
125         if (!flash) {
126                 debug("SF: Failed to allocate memory\n");
127                 return NULL;
128         }
129
130         flash->spi = spi;
131         flash->name = params->name;
132
133         flash->write = spi_flash_cmd_write_multi;
134         flash->erase = spi_flash_cmd_erase;
135         flash->read = spi_flash_cmd_read_fast;
136         flash->page_size = 256;
137         flash->sector_size = 256 * params->pages_per_sector;
138         flash->size = flash->sector_size * params->nr_sectors;
139
140         return flash;
141 }