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