]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - drivers/mtd/spi/spansion.c
sf: spansion: add support for S25FL129P_64K
[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 /* S25FLxx-specific commands */
35 #define CMD_S25FLXX_READ        0x03    /* Read Data Bytes */
36 #define CMD_S25FLXX_FAST_READ   0x0b    /* Read Data Bytes at Higher Speed */
37 #define CMD_S25FLXX_READID      0x90    /* Read Manufacture ID and Device ID */
38 #define CMD_S25FLXX_WREN        0x06    /* Write Enable */
39 #define CMD_S25FLXX_WRDI        0x04    /* Write Disable */
40 #define CMD_S25FLXX_RDSR        0x05    /* Read Status Register */
41 #define CMD_S25FLXX_WRSR        0x01    /* Write Status Register */
42 #define CMD_S25FLXX_PP          0x02    /* Page Program */
43 #define CMD_S25FLXX_SE          0xd8    /* Sector Erase */
44 #define CMD_S25FLXX_BE          0xc7    /* Bulk Erase */
45 #define CMD_S25FLXX_DP          0xb9    /* Deep Power-down */
46 #define CMD_S25FLXX_RES         0xab    /* Release from DP, and Read Signature */
47
48 #define SPSN_ID_S25FL008A       0x0213
49 #define SPSN_ID_S25FL016A       0x0214
50 #define SPSN_ID_S25FL032A       0x0215
51 #define SPSN_ID_S25FL064A       0x0216
52 #define SPSN_ID_S25FL128P       0x2018
53 #define SPSN_EXT_ID_S25FL128P_256KB     0x0300
54 #define SPSN_EXT_ID_S25FL128P_64KB      0x0301
55 #define SPSN_EXT_ID_S25FL032P           0x4d00
56 #define SPSN_EXT_ID_S25FL129P           0x4d01
57
58 struct spansion_spi_flash_params {
59         u16 idcode1;
60         u16 idcode2;
61         u16 page_size;
62         u16 pages_per_sector;
63         u16 nr_sectors;
64         const char *name;
65 };
66
67 static const struct spansion_spi_flash_params spansion_spi_flash_table[] = {
68         {
69                 .idcode1 = SPSN_ID_S25FL008A,
70                 .idcode2 = 0,
71                 .page_size = 256,
72                 .pages_per_sector = 256,
73                 .nr_sectors = 16,
74                 .name = "S25FL008A",
75         },
76         {
77                 .idcode1 = SPSN_ID_S25FL016A,
78                 .idcode2 = 0,
79                 .page_size = 256,
80                 .pages_per_sector = 256,
81                 .nr_sectors = 32,
82                 .name = "S25FL016A",
83         },
84         {
85                 .idcode1 = SPSN_ID_S25FL032A,
86                 .idcode2 = 0,
87                 .page_size = 256,
88                 .pages_per_sector = 256,
89                 .nr_sectors = 64,
90                 .name = "S25FL032A",
91         },
92         {
93                 .idcode1 = SPSN_ID_S25FL064A,
94                 .idcode2 = 0,
95                 .page_size = 256,
96                 .pages_per_sector = 256,
97                 .nr_sectors = 128,
98                 .name = "S25FL064A",
99         },
100         {
101                 .idcode1 = SPSN_ID_S25FL128P,
102                 .idcode2 = SPSN_EXT_ID_S25FL128P_64KB,
103                 .page_size = 256,
104                 .pages_per_sector = 256,
105                 .nr_sectors = 256,
106                 .name = "S25FL128P_64K",
107         },
108         {
109                 .idcode1 = SPSN_ID_S25FL128P,
110                 .idcode2 = SPSN_EXT_ID_S25FL128P_256KB,
111                 .page_size = 256,
112                 .pages_per_sector = 1024,
113                 .nr_sectors = 64,
114                 .name = "S25FL128P_256K",
115         },
116         {
117                 .idcode1 = SPSN_ID_S25FL032A,
118                 .idcode2 = SPSN_EXT_ID_S25FL032P,
119                 .page_size = 256,
120                 .pages_per_sector = 256,
121                 .nr_sectors = 64,
122                 .name = "S25FL032P",
123         },
124         {
125                 .idcode1 = SPSN_ID_S25FL128P,
126                 .idcode2 = SPSN_EXT_ID_S25FL129P,
127                 .page_size = 256,
128                 .pages_per_sector = 256,
129                 .nr_sectors = 256,
130                 .name = "S25FL129P_64K",
131         },
132 };
133
134 static int spansion_erase(struct spi_flash *flash, u32 offset, size_t len)
135 {
136         return spi_flash_cmd_erase(flash, CMD_S25FLXX_SE, offset, len);
137 }
138
139 struct spi_flash *spi_flash_probe_spansion(struct spi_slave *spi, u8 *idcode)
140 {
141         const struct spansion_spi_flash_params *params;
142         struct spi_flash *flash;
143         unsigned int i;
144         unsigned short jedec, ext_jedec;
145
146         jedec = idcode[1] << 8 | idcode[2];
147         ext_jedec = idcode[3] << 8 | idcode[4];
148
149         for (i = 0; i < ARRAY_SIZE(spansion_spi_flash_table); i++) {
150                 params = &spansion_spi_flash_table[i];
151                 if (params->idcode1 == jedec) {
152                         if (params->idcode2 == ext_jedec)
153                                 break;
154                 }
155         }
156
157         if (i == ARRAY_SIZE(spansion_spi_flash_table)) {
158                 debug("SF: Unsupported SPANSION ID %04x %04x\n", jedec, ext_jedec);
159                 return NULL;
160         }
161
162         flash = malloc(sizeof(*flash));
163         if (!flash) {
164                 debug("SF: Failed to allocate memory\n");
165                 return NULL;
166         }
167
168         flash->spi = spi;
169         flash->name = params->name;
170
171         flash->write = spi_flash_cmd_write_multi;
172         flash->erase = spansion_erase;
173         flash->read = spi_flash_cmd_read_fast;
174         flash->page_size = params->page_size;
175         flash->sector_size = params->page_size * params->pages_per_sector;
176         flash->size = flash->sector_size * params->nr_sectors;
177
178         return flash;
179 }