2 * Copyright (C) 2009 Freescale Semiconductor, Inc.
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)
9 * See file CREDITS for list of people who contributed to this
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.
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.
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,
30 #include <spi_flash.h>
32 #include "spi_flash_internal.h"
34 struct spansion_spi_flash_params
{
42 static const struct spansion_spi_flash_params spansion_spi_flash_table
[] = {
46 .pages_per_sector
= 256,
53 .pages_per_sector
= 256,
60 .pages_per_sector
= 256,
67 .pages_per_sector
= 256,
74 .pages_per_sector
= 256,
76 .name
= "S25FL128P_64K",
81 .pages_per_sector
= 1024,
83 .name
= "S25FL128P_256K",
88 .pages_per_sector
= 256,
95 .pages_per_sector
= 256,
97 .name
= "S25FL129P_64K",
102 .pages_per_sector
= 256,
108 struct spi_flash
*spi_flash_probe_spansion(struct spi_slave
*spi
, u8
*idcode
)
110 const struct spansion_spi_flash_params
*params
;
111 struct spi_flash
*flash
;
113 unsigned short jedec
, ext_jedec
;
115 jedec
= idcode
[1] << 8 | idcode
[2];
116 ext_jedec
= idcode
[3] << 8 | idcode
[4];
118 for (i
= 0; i
< ARRAY_SIZE(spansion_spi_flash_table
); i
++) {
119 params
= &spansion_spi_flash_table
[i
];
120 if (params
->idcode1
== jedec
) {
121 if (params
->idcode2
== ext_jedec
)
126 if (i
== ARRAY_SIZE(spansion_spi_flash_table
)) {
127 debug("SF: Unsupported SPANSION ID %04x %04x\n", jedec
, ext_jedec
);
131 flash
= malloc(sizeof(*flash
));
133 debug("SF: Failed to allocate memory\n");
138 flash
->name
= params
->name
;
140 flash
->write
= spi_flash_cmd_write_multi
;
141 flash
->erase
= spi_flash_cmd_erase
;
142 flash
->read
= spi_flash_cmd_read_fast
;
143 flash
->page_size
= 256;
144 flash
->sector_size
= 256 * params
->pages_per_sector
;
145 flash
->size
= flash
->sector_size
* params
->nr_sectors
;