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 | |
Mingkai Hu | 6805e4b | 2009-03-31 14:09:41 +0800 | [diff] [blame] | 34 | struct spansion_spi_flash_params { |
| 35 | u16 idcode1; |
| 36 | u16 idcode2; |
Mingkai Hu | 6805e4b | 2009-03-31 14:09:41 +0800 | [diff] [blame] | 37 | u16 pages_per_sector; |
| 38 | u16 nr_sectors; |
| 39 | const char *name; |
| 40 | }; |
| 41 | |
Mingkai Hu | 6805e4b | 2009-03-31 14:09:41 +0800 | [diff] [blame] | 42 | static const struct spansion_spi_flash_params spansion_spi_flash_table[] = { |
| 43 | { |
Mike Frysinger | 7d72b80 | 2012-01-28 16:32:18 -0800 | [diff] [blame] | 44 | .idcode1 = 0x0213, |
Mingkai Hu | 6805e4b | 2009-03-31 14:09:41 +0800 | [diff] [blame] | 45 | .idcode2 = 0, |
Mingkai Hu | 6805e4b | 2009-03-31 14:09:41 +0800 | [diff] [blame] | 46 | .pages_per_sector = 256, |
| 47 | .nr_sectors = 16, |
| 48 | .name = "S25FL008A", |
| 49 | }, |
| 50 | { |
Mike Frysinger | 7d72b80 | 2012-01-28 16:32:18 -0800 | [diff] [blame] | 51 | .idcode1 = 0x0214, |
Mingkai Hu | 6805e4b | 2009-03-31 14:09:41 +0800 | [diff] [blame] | 52 | .idcode2 = 0, |
Mingkai Hu | 6805e4b | 2009-03-31 14:09:41 +0800 | [diff] [blame] | 53 | .pages_per_sector = 256, |
| 54 | .nr_sectors = 32, |
| 55 | .name = "S25FL016A", |
| 56 | }, |
| 57 | { |
Mike Frysinger | 7d72b80 | 2012-01-28 16:32:18 -0800 | [diff] [blame] | 58 | .idcode1 = 0x0215, |
Mingkai Hu | 6805e4b | 2009-03-31 14:09:41 +0800 | [diff] [blame] | 59 | .idcode2 = 0, |
Mingkai Hu | 6805e4b | 2009-03-31 14:09:41 +0800 | [diff] [blame] | 60 | .pages_per_sector = 256, |
| 61 | .nr_sectors = 64, |
| 62 | .name = "S25FL032A", |
| 63 | }, |
| 64 | { |
Mike Frysinger | 7d72b80 | 2012-01-28 16:32:18 -0800 | [diff] [blame] | 65 | .idcode1 = 0x0216, |
Mingkai Hu | 6805e4b | 2009-03-31 14:09:41 +0800 | [diff] [blame] | 66 | .idcode2 = 0, |
Mingkai Hu | 6805e4b | 2009-03-31 14:09:41 +0800 | [diff] [blame] | 67 | .pages_per_sector = 256, |
| 68 | .nr_sectors = 128, |
| 69 | .name = "S25FL064A", |
| 70 | }, |
| 71 | { |
Mike Frysinger | 7d72b80 | 2012-01-28 16:32:18 -0800 | [diff] [blame] | 72 | .idcode1 = 0x2018, |
| 73 | .idcode2 = 0x0301, |
Mingkai Hu | 6805e4b | 2009-03-31 14:09:41 +0800 | [diff] [blame] | 74 | .pages_per_sector = 256, |
| 75 | .nr_sectors = 256, |
| 76 | .name = "S25FL128P_64K", |
| 77 | }, |
| 78 | { |
Mike Frysinger | 7d72b80 | 2012-01-28 16:32:18 -0800 | [diff] [blame] | 79 | .idcode1 = 0x2018, |
| 80 | .idcode2 = 0x0300, |
Mingkai Hu | 6805e4b | 2009-03-31 14:09:41 +0800 | [diff] [blame] | 81 | .pages_per_sector = 1024, |
| 82 | .nr_sectors = 64, |
| 83 | .name = "S25FL128P_256K", |
| 84 | }, |
David Jander | ff0dc2c | 2010-08-23 15:12:16 +0200 | [diff] [blame] | 85 | { |
Mike Frysinger | 7d72b80 | 2012-01-28 16:32:18 -0800 | [diff] [blame] | 86 | .idcode1 = 0x0215, |
| 87 | .idcode2 = 0x4d00, |
David Jander | ff0dc2c | 2010-08-23 15:12:16 +0200 | [diff] [blame] | 88 | .pages_per_sector = 256, |
| 89 | .nr_sectors = 64, |
| 90 | .name = "S25FL032P", |
| 91 | }, |
Shaohui Xie | 9445ce0 | 2011-04-20 20:07:11 +0000 | [diff] [blame] | 92 | { |
Marek Vasut | e90f7bd | 2012-08-28 15:13:37 +0000 | [diff] [blame] | 93 | .idcode1 = 0x0216, |
| 94 | .idcode2 = 0x4d00, |
| 95 | .pages_per_sector = 256, |
| 96 | .nr_sectors = 128, |
| 97 | .name = "S25FL064P", |
| 98 | }, |
| 99 | { |
Mike Frysinger | 7d72b80 | 2012-01-28 16:32:18 -0800 | [diff] [blame] | 100 | .idcode1 = 0x2018, |
| 101 | .idcode2 = 0x4d01, |
Shaohui Xie | 9445ce0 | 2011-04-20 20:07:11 +0000 | [diff] [blame] | 102 | .pages_per_sector = 256, |
| 103 | .nr_sectors = 256, |
Jagannadha Sutradharudu Teki | 6fd1000 | 2013-06-14 21:03:51 +0530 | [diff] [blame] | 104 | .name = "S25FL129P_64K/S25FL128S_64K", |
Shaohui Xie | 9445ce0 | 2011-04-20 20:07:11 +0000 | [diff] [blame] | 105 | }, |
Michal Simek | 4a4cb4e | 2012-08-14 13:11:22 +0200 | [diff] [blame] | 106 | { |
Jagannadha Sutradharudu Teki | 4e994c1 | 2012-09-14 20:46:11 +0530 | [diff] [blame] | 107 | .idcode1 = 0x0219, |
Michal Simek | 4a4cb4e | 2012-08-14 13:11:22 +0200 | [diff] [blame] | 108 | .idcode2 = 0x4d01, |
| 109 | .pages_per_sector = 256, |
| 110 | .nr_sectors = 512, |
Jagannadha Sutradharudu Teki | 59120ca | 2013-05-25 23:03:11 +0530 | [diff] [blame] | 111 | .name = "S25FL256S_64K", |
Michal Simek | 4a4cb4e | 2012-08-14 13:11:22 +0200 | [diff] [blame] | 112 | }, |
Mingkai Hu | 6805e4b | 2009-03-31 14:09:41 +0800 | [diff] [blame] | 113 | }; |
| 114 | |
Mingkai Hu | 6805e4b | 2009-03-31 14:09:41 +0800 | [diff] [blame] | 115 | struct spi_flash *spi_flash_probe_spansion(struct spi_slave *spi, u8 *idcode) |
| 116 | { |
| 117 | const struct spansion_spi_flash_params *params; |
Mike Frysinger | b06afa7 | 2011-06-28 07:38:10 +0000 | [diff] [blame] | 118 | struct spi_flash *flash; |
Mingkai Hu | 6805e4b | 2009-03-31 14:09:41 +0800 | [diff] [blame] | 119 | unsigned int i; |
| 120 | unsigned short jedec, ext_jedec; |
Mingkai Hu | 6805e4b | 2009-03-31 14:09:41 +0800 | [diff] [blame] | 121 | |
Mike Frysinger | 0dcdbb1 | 2009-03-28 06:41:09 -0400 | [diff] [blame] | 122 | jedec = idcode[1] << 8 | idcode[2]; |
| 123 | ext_jedec = idcode[3] << 8 | idcode[4]; |
Mingkai Hu | 6805e4b | 2009-03-31 14:09:41 +0800 | [diff] [blame] | 124 | |
| 125 | for (i = 0; i < ARRAY_SIZE(spansion_spi_flash_table); i++) { |
| 126 | params = &spansion_spi_flash_table[i]; |
| 127 | if (params->idcode1 == jedec) { |
| 128 | if (params->idcode2 == ext_jedec) |
| 129 | break; |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | if (i == ARRAY_SIZE(spansion_spi_flash_table)) { |
| 134 | debug("SF: Unsupported SPANSION ID %04x %04x\n", jedec, ext_jedec); |
| 135 | return NULL; |
| 136 | } |
| 137 | |
Simon Glass | c0f87dd | 2013-03-11 06:08:03 +0000 | [diff] [blame] | 138 | flash = spi_flash_alloc_base(spi, params->name); |
Mike Frysinger | b06afa7 | 2011-06-28 07:38:10 +0000 | [diff] [blame] | 139 | if (!flash) { |
Mingkai Hu | 6805e4b | 2009-03-31 14:09:41 +0800 | [diff] [blame] | 140 | debug("SF: Failed to allocate memory\n"); |
| 141 | return NULL; |
| 142 | } |
| 143 | |
Mike Frysinger | a4ed3b6 | 2012-03-04 22:56:52 -0500 | [diff] [blame] | 144 | flash->page_size = 256; |
| 145 | flash->sector_size = 256 * params->pages_per_sector; |
Mike Frysinger | b06afa7 | 2011-06-28 07:38:10 +0000 | [diff] [blame] | 146 | flash->size = flash->sector_size * params->nr_sectors; |
Mingkai Hu | 6805e4b | 2009-03-31 14:09:41 +0800 | [diff] [blame] | 147 | |
Mike Frysinger | b06afa7 | 2011-06-28 07:38:10 +0000 | [diff] [blame] | 148 | return flash; |
Mingkai Hu | 6805e4b | 2009-03-31 14:09:41 +0800 | [diff] [blame] | 149 | } |