Mingkai Hu | 6805e4b | 2009-03-31 14:09:41 +0800 | [diff] [blame] | 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 */ |
Mingkai Hu | 6805e4b | 2009-03-31 14:09:41 +0800 | [diff] [blame] | 35 | #define CMD_S25FLXX_SE 0xd8 /* Sector Erase */ |
| 36 | #define CMD_S25FLXX_BE 0xc7 /* Bulk Erase */ |
Mingkai Hu | 6805e4b | 2009-03-31 14:09:41 +0800 | [diff] [blame] | 37 | |
Mingkai Hu | 6805e4b | 2009-03-31 14:09:41 +0800 | [diff] [blame] | 38 | struct spansion_spi_flash_params { |
| 39 | u16 idcode1; |
| 40 | u16 idcode2; |
| 41 | u16 page_size; |
| 42 | u16 pages_per_sector; |
| 43 | u16 nr_sectors; |
| 44 | const char *name; |
| 45 | }; |
| 46 | |
Mingkai Hu | 6805e4b | 2009-03-31 14:09:41 +0800 | [diff] [blame] | 47 | static const struct spansion_spi_flash_params spansion_spi_flash_table[] = { |
| 48 | { |
Mike Frysinger | 7d72b80 | 2012-01-28 16:32:18 -0800 | [diff] [blame] | 49 | .idcode1 = 0x0213, |
Mingkai Hu | 6805e4b | 2009-03-31 14:09:41 +0800 | [diff] [blame] | 50 | .idcode2 = 0, |
| 51 | .page_size = 256, |
| 52 | .pages_per_sector = 256, |
| 53 | .nr_sectors = 16, |
| 54 | .name = "S25FL008A", |
| 55 | }, |
| 56 | { |
Mike Frysinger | 7d72b80 | 2012-01-28 16:32:18 -0800 | [diff] [blame] | 57 | .idcode1 = 0x0214, |
Mingkai Hu | 6805e4b | 2009-03-31 14:09:41 +0800 | [diff] [blame] | 58 | .idcode2 = 0, |
| 59 | .page_size = 256, |
| 60 | .pages_per_sector = 256, |
| 61 | .nr_sectors = 32, |
| 62 | .name = "S25FL016A", |
| 63 | }, |
| 64 | { |
Mike Frysinger | 7d72b80 | 2012-01-28 16:32:18 -0800 | [diff] [blame] | 65 | .idcode1 = 0x0215, |
Mingkai Hu | 6805e4b | 2009-03-31 14:09:41 +0800 | [diff] [blame] | 66 | .idcode2 = 0, |
| 67 | .page_size = 256, |
| 68 | .pages_per_sector = 256, |
| 69 | .nr_sectors = 64, |
| 70 | .name = "S25FL032A", |
| 71 | }, |
| 72 | { |
Mike Frysinger | 7d72b80 | 2012-01-28 16:32:18 -0800 | [diff] [blame] | 73 | .idcode1 = 0x0216, |
Mingkai Hu | 6805e4b | 2009-03-31 14:09:41 +0800 | [diff] [blame] | 74 | .idcode2 = 0, |
| 75 | .page_size = 256, |
| 76 | .pages_per_sector = 256, |
| 77 | .nr_sectors = 128, |
| 78 | .name = "S25FL064A", |
| 79 | }, |
| 80 | { |
Mike Frysinger | 7d72b80 | 2012-01-28 16:32:18 -0800 | [diff] [blame] | 81 | .idcode1 = 0x2018, |
| 82 | .idcode2 = 0x0301, |
Mingkai Hu | 6805e4b | 2009-03-31 14:09:41 +0800 | [diff] [blame] | 83 | .page_size = 256, |
| 84 | .pages_per_sector = 256, |
| 85 | .nr_sectors = 256, |
| 86 | .name = "S25FL128P_64K", |
| 87 | }, |
| 88 | { |
Mike Frysinger | 7d72b80 | 2012-01-28 16:32:18 -0800 | [diff] [blame] | 89 | .idcode1 = 0x2018, |
| 90 | .idcode2 = 0x0300, |
Mingkai Hu | 6805e4b | 2009-03-31 14:09:41 +0800 | [diff] [blame] | 91 | .page_size = 256, |
| 92 | .pages_per_sector = 1024, |
| 93 | .nr_sectors = 64, |
| 94 | .name = "S25FL128P_256K", |
| 95 | }, |
David Jander | ff0dc2c | 2010-08-23 15:12:16 +0200 | [diff] [blame] | 96 | { |
Mike Frysinger | 7d72b80 | 2012-01-28 16:32:18 -0800 | [diff] [blame] | 97 | .idcode1 = 0x0215, |
| 98 | .idcode2 = 0x4d00, |
David Jander | ff0dc2c | 2010-08-23 15:12:16 +0200 | [diff] [blame] | 99 | .page_size = 256, |
| 100 | .pages_per_sector = 256, |
| 101 | .nr_sectors = 64, |
| 102 | .name = "S25FL032P", |
| 103 | }, |
Shaohui Xie | 9445ce0 | 2011-04-20 20:07:11 +0000 | [diff] [blame] | 104 | { |
Mike Frysinger | 7d72b80 | 2012-01-28 16:32:18 -0800 | [diff] [blame] | 105 | .idcode1 = 0x2018, |
| 106 | .idcode2 = 0x4d01, |
Shaohui Xie | 9445ce0 | 2011-04-20 20:07:11 +0000 | [diff] [blame] | 107 | .page_size = 256, |
| 108 | .pages_per_sector = 256, |
| 109 | .nr_sectors = 256, |
| 110 | .name = "S25FL129P_64K", |
| 111 | }, |
Mingkai Hu | 6805e4b | 2009-03-31 14:09:41 +0800 | [diff] [blame] | 112 | }; |
| 113 | |
Mike Frysinger | f8f0757 | 2011-04-12 01:51:29 -0400 | [diff] [blame] | 114 | static int spansion_erase(struct spi_flash *flash, u32 offset, size_t len) |
Mingkai Hu | 6805e4b | 2009-03-31 14:09:41 +0800 | [diff] [blame] | 115 | { |
Richard Retanubun | 4e6a515 | 2011-02-16 16:37:22 -0500 | [diff] [blame] | 116 | return spi_flash_cmd_erase(flash, CMD_S25FLXX_SE, offset, len); |
Mingkai Hu | 6805e4b | 2009-03-31 14:09:41 +0800 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | struct spi_flash *spi_flash_probe_spansion(struct spi_slave *spi, u8 *idcode) |
| 120 | { |
| 121 | const struct spansion_spi_flash_params *params; |
Mike Frysinger | b06afa7 | 2011-06-28 07:38:10 +0000 | [diff] [blame] | 122 | struct spi_flash *flash; |
Mingkai Hu | 6805e4b | 2009-03-31 14:09:41 +0800 | [diff] [blame] | 123 | unsigned int i; |
| 124 | unsigned short jedec, ext_jedec; |
Mingkai Hu | 6805e4b | 2009-03-31 14:09:41 +0800 | [diff] [blame] | 125 | |
Mike Frysinger | 0dcdbb1 | 2009-03-28 06:41:09 -0400 | [diff] [blame] | 126 | jedec = idcode[1] << 8 | idcode[2]; |
| 127 | ext_jedec = idcode[3] << 8 | idcode[4]; |
Mingkai Hu | 6805e4b | 2009-03-31 14:09:41 +0800 | [diff] [blame] | 128 | |
| 129 | for (i = 0; i < ARRAY_SIZE(spansion_spi_flash_table); i++) { |
| 130 | params = &spansion_spi_flash_table[i]; |
| 131 | if (params->idcode1 == jedec) { |
| 132 | if (params->idcode2 == ext_jedec) |
| 133 | break; |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | if (i == ARRAY_SIZE(spansion_spi_flash_table)) { |
| 138 | debug("SF: Unsupported SPANSION ID %04x %04x\n", jedec, ext_jedec); |
| 139 | return NULL; |
| 140 | } |
| 141 | |
Mike Frysinger | b06afa7 | 2011-06-28 07:38:10 +0000 | [diff] [blame] | 142 | flash = malloc(sizeof(*flash)); |
| 143 | if (!flash) { |
Mingkai Hu | 6805e4b | 2009-03-31 14:09:41 +0800 | [diff] [blame] | 144 | debug("SF: Failed to allocate memory\n"); |
| 145 | return NULL; |
| 146 | } |
| 147 | |
Mike Frysinger | b06afa7 | 2011-06-28 07:38:10 +0000 | [diff] [blame] | 148 | flash->spi = spi; |
| 149 | flash->name = params->name; |
Mingkai Hu | 6805e4b | 2009-03-31 14:09:41 +0800 | [diff] [blame] | 150 | |
Mike Frysinger | b06afa7 | 2011-06-28 07:38:10 +0000 | [diff] [blame] | 151 | flash->write = spi_flash_cmd_write_multi; |
| 152 | flash->erase = spansion_erase; |
| 153 | flash->read = spi_flash_cmd_read_fast; |
| 154 | flash->page_size = params->page_size; |
| 155 | flash->sector_size = params->page_size * params->pages_per_sector; |
| 156 | flash->size = flash->sector_size * params->nr_sectors; |
Mingkai Hu | 6805e4b | 2009-03-31 14:09:41 +0800 | [diff] [blame] | 157 | |
Mike Frysinger | b06afa7 | 2011-06-28 07:38:10 +0000 | [diff] [blame] | 158 | return flash; |
Mingkai Hu | 6805e4b | 2009-03-31 14:09:41 +0800 | [diff] [blame] | 159 | } |