TsiChung Liew | 7b7a869 | 2008-08-06 16:08:41 -0500 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2000-2002 |
| 3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 4 | * |
| 5 | * Copyright 2008, Network Appliance Inc. |
| 6 | * Jason McMullan <mcmullan@netapp.com> |
| 7 | * |
| 8 | * Copyright (C) 2004-2007 Freescale Semiconductor, Inc. |
| 9 | * TsiChung Liew (Tsi-Chung.Liew@freescale.com) |
| 10 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame^] | 11 | * SPDX-License-Identifier: GPL-2.0+ |
TsiChung Liew | 7b7a869 | 2008-08-06 16:08:41 -0500 | [diff] [blame] | 12 | */ |
| 13 | |
| 14 | #include <common.h> |
| 15 | #include <malloc.h> |
| 16 | #include <spi_flash.h> |
| 17 | |
| 18 | #include "spi_flash_internal.h" |
| 19 | |
| 20 | /* M25Pxx-specific commands */ |
TsiChung Liew | 7b7a869 | 2008-08-06 16:08:41 -0500 | [diff] [blame] | 21 | #define CMD_M25PXX_RES 0xab /* Release from DP, and Read Signature */ |
| 22 | |
TsiChung Liew | 7b7a869 | 2008-08-06 16:08:41 -0500 | [diff] [blame] | 23 | struct stmicro_spi_flash_params { |
Stephan Linz | 63ff6a6 | 2012-08-02 20:47:29 +0200 | [diff] [blame] | 24 | u16 id; |
TsiChung Liew | 7b7a869 | 2008-08-06 16:08:41 -0500 | [diff] [blame] | 25 | u16 pages_per_sector; |
| 26 | u16 nr_sectors; |
| 27 | const char *name; |
| 28 | }; |
| 29 | |
TsiChung Liew | 7b7a869 | 2008-08-06 16:08:41 -0500 | [diff] [blame] | 30 | static const struct stmicro_spi_flash_params stmicro_spi_flash_table[] = { |
| 31 | { |
Stephan Linz | 63ff6a6 | 2012-08-02 20:47:29 +0200 | [diff] [blame] | 32 | .id = 0x2011, |
Thomas Chou | 12c2e3b | 2010-04-30 21:11:20 +0800 | [diff] [blame] | 33 | .pages_per_sector = 128, |
| 34 | .nr_sectors = 4, |
| 35 | .name = "M25P10", |
| 36 | }, |
| 37 | { |
Stephan Linz | 63ff6a6 | 2012-08-02 20:47:29 +0200 | [diff] [blame] | 38 | .id = 0x2015, |
TsiChung Liew | 7b7a869 | 2008-08-06 16:08:41 -0500 | [diff] [blame] | 39 | .pages_per_sector = 256, |
| 40 | .nr_sectors = 32, |
| 41 | .name = "M25P16", |
| 42 | }, |
| 43 | { |
Stephan Linz | 63ff6a6 | 2012-08-02 20:47:29 +0200 | [diff] [blame] | 44 | .id = 0x2012, |
TsiChung Liew | 7b7a869 | 2008-08-06 16:08:41 -0500 | [diff] [blame] | 45 | .pages_per_sector = 256, |
| 46 | .nr_sectors = 4, |
| 47 | .name = "M25P20", |
| 48 | }, |
| 49 | { |
Stephan Linz | 63ff6a6 | 2012-08-02 20:47:29 +0200 | [diff] [blame] | 50 | .id = 0x2016, |
TsiChung Liew | 7b7a869 | 2008-08-06 16:08:41 -0500 | [diff] [blame] | 51 | .pages_per_sector = 256, |
| 52 | .nr_sectors = 64, |
| 53 | .name = "M25P32", |
| 54 | }, |
| 55 | { |
Stephan Linz | 63ff6a6 | 2012-08-02 20:47:29 +0200 | [diff] [blame] | 56 | .id = 0x2013, |
TsiChung Liew | 7b7a869 | 2008-08-06 16:08:41 -0500 | [diff] [blame] | 57 | .pages_per_sector = 256, |
| 58 | .nr_sectors = 8, |
| 59 | .name = "M25P40", |
| 60 | }, |
| 61 | { |
Stephan Linz | 63ff6a6 | 2012-08-02 20:47:29 +0200 | [diff] [blame] | 62 | .id = 0x2017, |
TsiChung Liew | 7b7a869 | 2008-08-06 16:08:41 -0500 | [diff] [blame] | 63 | .pages_per_sector = 256, |
| 64 | .nr_sectors = 128, |
| 65 | .name = "M25P64", |
| 66 | }, |
| 67 | { |
Stephan Linz | 63ff6a6 | 2012-08-02 20:47:29 +0200 | [diff] [blame] | 68 | .id = 0x2014, |
TsiChung Liew | 7b7a869 | 2008-08-06 16:08:41 -0500 | [diff] [blame] | 69 | .pages_per_sector = 256, |
| 70 | .nr_sectors = 16, |
| 71 | .name = "M25P80", |
| 72 | }, |
| 73 | { |
Stephan Linz | 63ff6a6 | 2012-08-02 20:47:29 +0200 | [diff] [blame] | 74 | .id = 0x2018, |
TsiChung Liew | 7b7a869 | 2008-08-06 16:08:41 -0500 | [diff] [blame] | 75 | .pages_per_sector = 1024, |
| 76 | .nr_sectors = 64, |
| 77 | .name = "M25P128", |
| 78 | }, |
Jérôme Carretero | b54d1f2 | 2012-04-08 10:55:55 +0000 | [diff] [blame] | 79 | { |
Jagannadha Sutradharudu Teki | c75c921 | 2013-01-29 17:13:36 +0530 | [diff] [blame] | 80 | .id = 0xba16, |
| 81 | .pages_per_sector = 256, |
| 82 | .nr_sectors = 64, |
| 83 | .name = "N25Q32", |
| 84 | }, |
| 85 | { |
Jagannadha Sutradharudu Teki | b1431da | 2013-01-29 17:13:37 +0530 | [diff] [blame] | 86 | .id = 0xbb16, |
| 87 | .pages_per_sector = 256, |
| 88 | .nr_sectors = 64, |
| 89 | .name = "N25Q32A", |
| 90 | }, |
| 91 | { |
Jagannadha Sutradharudu Teki | 3981d02 | 2012-12-12 04:48:56 +0000 | [diff] [blame] | 92 | .id = 0xba17, |
| 93 | .pages_per_sector = 256, |
| 94 | .nr_sectors = 128, |
| 95 | .name = "N25Q064", |
| 96 | }, |
| 97 | { |
Jagannadha Sutradharudu Teki | f785fcb | 2013-01-23 18:21:45 +0530 | [diff] [blame] | 98 | .id = 0xbb17, |
| 99 | .pages_per_sector = 256, |
| 100 | .nr_sectors = 128, |
| 101 | .name = "N25Q64A", |
| 102 | }, |
| 103 | { |
Stephan Linz | 6ad6c6d | 2012-08-02 20:47:30 +0200 | [diff] [blame] | 104 | .id = 0xba18, |
| 105 | .pages_per_sector = 256, |
| 106 | .nr_sectors = 256, |
| 107 | .name = "N25Q128", |
| 108 | }, |
| 109 | { |
Michal Simek | d945ce9 | 2012-08-10 14:21:46 +0200 | [diff] [blame] | 110 | .id = 0xbb18, |
| 111 | .pages_per_sector = 256, |
| 112 | .nr_sectors = 256, |
| 113 | .name = "N25Q128A", |
| 114 | }, |
| 115 | { |
Stephan Linz | 63ff6a6 | 2012-08-02 20:47:29 +0200 | [diff] [blame] | 116 | .id = 0xba19, |
Jérôme Carretero | b54d1f2 | 2012-04-08 10:55:55 +0000 | [diff] [blame] | 117 | .pages_per_sector = 256, |
| 118 | .nr_sectors = 512, |
| 119 | .name = "N25Q256", |
| 120 | }, |
Jagannadha Sutradharudu Teki | d62ef56 | 2013-01-29 17:13:38 +0530 | [diff] [blame] | 121 | { |
| 122 | .id = 0xbb19, |
| 123 | .pages_per_sector = 256, |
| 124 | .nr_sectors = 512, |
| 125 | .name = "N25Q256A", |
| 126 | }, |
Jagannadha Sutradharudu Teki | 0569f3b | 2013-04-16 20:18:29 +0530 | [diff] [blame] | 127 | { |
| 128 | .id = 0xba20, |
| 129 | .pages_per_sector = 256, |
| 130 | .nr_sectors = 1024, |
| 131 | .name = "N25Q512", |
| 132 | }, |
Jagannadha Sutradharudu Teki | fd60c0a | 2013-04-16 20:20:12 +0530 | [diff] [blame] | 133 | { |
| 134 | .id = 0xbb20, |
| 135 | .pages_per_sector = 256, |
| 136 | .nr_sectors = 1024, |
| 137 | .name = "N25Q512A", |
| 138 | }, |
Jagannadha Sutradharudu Teki | 221cb08 | 2013-04-16 20:22:48 +0530 | [diff] [blame] | 139 | { |
| 140 | .id = 0xba21, |
| 141 | .pages_per_sector = 256, |
| 142 | .nr_sectors = 2048, |
| 143 | .name = "N25Q1024", |
| 144 | }, |
Jagannadha Sutradharudu Teki | 4e29043 | 2013-04-16 20:23:48 +0530 | [diff] [blame] | 145 | { |
| 146 | .id = 0xbb21, |
| 147 | .pages_per_sector = 256, |
| 148 | .nr_sectors = 2048, |
| 149 | .name = "N25Q1024A", |
| 150 | }, |
TsiChung Liew | 7b7a869 | 2008-08-06 16:08:41 -0500 | [diff] [blame] | 151 | }; |
| 152 | |
TsiChung Liew | 7b7a869 | 2008-08-06 16:08:41 -0500 | [diff] [blame] | 153 | struct spi_flash *spi_flash_probe_stmicro(struct spi_slave *spi, u8 * idcode) |
| 154 | { |
| 155 | const struct stmicro_spi_flash_params *params; |
Mike Frysinger | b06afa7 | 2011-06-28 07:38:10 +0000 | [diff] [blame] | 156 | struct spi_flash *flash; |
TsiChung Liew | 7b7a869 | 2008-08-06 16:08:41 -0500 | [diff] [blame] | 157 | unsigned int i; |
Stephan Linz | 63ff6a6 | 2012-08-02 20:47:29 +0200 | [diff] [blame] | 158 | u16 id; |
TsiChung Liew | 7b7a869 | 2008-08-06 16:08:41 -0500 | [diff] [blame] | 159 | |
Thomas Chou | 12c2e3b | 2010-04-30 21:11:20 +0800 | [diff] [blame] | 160 | if (idcode[0] == 0xff) { |
| 161 | i = spi_flash_cmd(spi, CMD_M25PXX_RES, |
| 162 | idcode, 4); |
| 163 | if (i) |
| 164 | return NULL; |
| 165 | if ((idcode[3] & 0xf0) == 0x10) { |
| 166 | idcode[0] = 0x20; |
| 167 | idcode[1] = 0x20; |
| 168 | idcode[2] = idcode[3] + 1; |
| 169 | } else |
| 170 | return NULL; |
| 171 | } |
| 172 | |
Stephan Linz | 63ff6a6 | 2012-08-02 20:47:29 +0200 | [diff] [blame] | 173 | id = ((idcode[1] << 8) | idcode[2]); |
| 174 | |
TsiChung Liew | 7b7a869 | 2008-08-06 16:08:41 -0500 | [diff] [blame] | 175 | for (i = 0; i < ARRAY_SIZE(stmicro_spi_flash_table); i++) { |
| 176 | params = &stmicro_spi_flash_table[i]; |
Stephan Linz | 63ff6a6 | 2012-08-02 20:47:29 +0200 | [diff] [blame] | 177 | if (params->id == id) { |
TsiChung Liew | 7b7a869 | 2008-08-06 16:08:41 -0500 | [diff] [blame] | 178 | break; |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | if (i == ARRAY_SIZE(stmicro_spi_flash_table)) { |
Stephan Linz | 63ff6a6 | 2012-08-02 20:47:29 +0200 | [diff] [blame] | 183 | debug("SF: Unsupported STMicro ID %04x\n", id); |
TsiChung Liew | 7b7a869 | 2008-08-06 16:08:41 -0500 | [diff] [blame] | 184 | return NULL; |
| 185 | } |
| 186 | |
Simon Glass | c0f87dd | 2013-03-11 06:08:03 +0000 | [diff] [blame] | 187 | flash = spi_flash_alloc_base(spi, params->name); |
Mike Frysinger | b06afa7 | 2011-06-28 07:38:10 +0000 | [diff] [blame] | 188 | if (!flash) { |
TsiChung Liew | 7b7a869 | 2008-08-06 16:08:41 -0500 | [diff] [blame] | 189 | debug("SF: Failed to allocate memory\n"); |
| 190 | return NULL; |
| 191 | } |
| 192 | |
Mike Frysinger | a4ed3b6 | 2012-03-04 22:56:52 -0500 | [diff] [blame] | 193 | flash->page_size = 256; |
| 194 | flash->sector_size = 256 * params->pages_per_sector; |
Mike Frysinger | b06afa7 | 2011-06-28 07:38:10 +0000 | [diff] [blame] | 195 | flash->size = flash->sector_size * params->nr_sectors; |
TsiChung Liew | 7b7a869 | 2008-08-06 16:08:41 -0500 | [diff] [blame] | 196 | |
Jagannadha Sutradharudu Teki | 615a156 | 2013-06-21 15:56:30 +0530 | [diff] [blame] | 197 | /* for >= 512MiB flashes, use flag status instead of read_status */ |
| 198 | if (flash->size >= 0x4000000) |
| 199 | flash->poll_cmd = CMD_FLAG_STATUS; |
| 200 | |
Mike Frysinger | b06afa7 | 2011-06-28 07:38:10 +0000 | [diff] [blame] | 201 | return flash; |
TsiChung Liew | 7b7a869 | 2008-08-06 16:08:41 -0500 | [diff] [blame] | 202 | } |