David Hendricks | d1c55d7 | 2010-08-24 15:14:19 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the flashrom project. |
| 3 | * |
| 4 | * Copyright (C) 2010 Google Inc. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 19 | */ |
| 20 | |
David Hendricks | f7924d1 | 2010-06-10 21:26:44 -0700 | [diff] [blame] | 21 | #include <stdlib.h> |
| 22 | #include <string.h> |
| 23 | |
| 24 | #include "flash.h" |
| 25 | #include "flashchips.h" |
| 26 | #include "chipdrivers.h" |
Louis Yung-Chieh Lo | 52aa930 | 2010-09-06 10:45:02 +0800 | [diff] [blame] | 27 | #include "spi.h" |
David Hendricks | 23cd778 | 2010-08-25 12:42:38 -0700 | [diff] [blame] | 28 | #include "writeprotect.h" |
David Hendricks | f7924d1 | 2010-06-10 21:26:44 -0700 | [diff] [blame] | 29 | |
Louis Yung-Chieh Lo | 96222b1 | 2010-11-01 11:48:11 +0800 | [diff] [blame] | 30 | /* When update flash's status register, it takes few time to erase register. |
| 31 | * After surveying some flash vendor specs, such as Winbond, MXIC, EON, |
| 32 | * all of their update time are less than 20ms. After refering the spi25.c, |
| 33 | * use 100ms delay. |
| 34 | */ |
| 35 | #define WRITE_STATUS_REGISTER_DELAY 100 * 1000 /* unit: us */ |
| 36 | |
Louis Yung-Chieh Lo | 165b464 | 2010-11-26 16:35:26 +0800 | [diff] [blame] | 37 | /* Mask to extract SRP0 and range bits in status register. |
| 38 | * SRP0: bit 7 |
| 39 | * range(BP2-BP0): bit 4-2 |
| 40 | */ |
| 41 | #define MASK_WP_AREA (0x9C) |
| 42 | |
David Hendricks | f7924d1 | 2010-06-10 21:26:44 -0700 | [diff] [blame] | 43 | /* |
| 44 | * The following procedures rely on look-up tables to match the user-specified |
| 45 | * range with the chip's supported ranges. This turned out to be the most |
| 46 | * elegant approach since diferent flash chips use different levels of |
| 47 | * granularity and methods to determine protected ranges. In other words, |
| 48 | * be stupid and simple since clever arithmetic will not for many chips. |
| 49 | */ |
| 50 | |
| 51 | struct wp_range { |
| 52 | unsigned int start; /* starting address */ |
| 53 | unsigned int len; /* len */ |
| 54 | }; |
| 55 | |
| 56 | enum bit_state { |
| 57 | OFF = 0, |
| 58 | ON = 1, |
Louis Yung-Chieh Lo | edd3930 | 2011-11-10 15:43:06 +0800 | [diff] [blame] | 59 | X = -1 /* don't care. Must be bigger than max # of bp. */ |
David Hendricks | f7924d1 | 2010-06-10 21:26:44 -0700 | [diff] [blame] | 60 | }; |
| 61 | |
| 62 | struct w25q_range { |
| 63 | enum bit_state sec; /* if 1, bp[2:0] describe sectors */ |
| 64 | enum bit_state tb; /* top/bottom select */ |
Louis Yung-Chieh Lo | edd3930 | 2011-11-10 15:43:06 +0800 | [diff] [blame] | 65 | int bp; /* block protect bitfield */ |
David Hendricks | f7924d1 | 2010-06-10 21:26:44 -0700 | [diff] [blame] | 66 | struct wp_range range; |
| 67 | }; |
| 68 | |
David Hendricks | 57566ed | 2010-08-16 18:24:45 -0700 | [diff] [blame] | 69 | struct w25q_range en25f40_ranges[] = { |
| 70 | { X, X, 0, {0, 0} }, /* none */ |
| 71 | { 0, 0, 0x1, {0x000000, 504 * 1024} }, |
| 72 | { 0, 0, 0x2, {0x000000, 496 * 1024} }, |
| 73 | { 0, 0, 0x3, {0x000000, 480 * 1024} }, |
| 74 | { 0, 0, 0x4, {0x000000, 448 * 1024} }, |
| 75 | { 0, 0, 0x5, {0x000000, 384 * 1024} }, |
| 76 | { 0, 0, 0x6, {0x000000, 256 * 1024} }, |
| 77 | { 0, 0, 0x7, {0x000000, 512 * 1024} }, |
| 78 | }; |
| 79 | |
David Hendricks | e185bf2 | 2011-05-24 15:34:18 -0700 | [diff] [blame] | 80 | struct w25q_range en25q40_ranges[] = { |
| 81 | { 0, 0, 0, {0, 0} }, /* none */ |
| 82 | { 0, 0, 0x1, {0x000000, 504 * 1024} }, |
| 83 | { 0, 0, 0x2, {0x000000, 496 * 1024} }, |
| 84 | { 0, 0, 0x3, {0x000000, 480 * 1024} }, |
| 85 | |
| 86 | { 0, 1, 0x0, {0x000000, 448 * 1024} }, |
| 87 | { 0, 1, 0x1, {0x000000, 384 * 1024} }, |
| 88 | { 0, 1, 0x2, {0x000000, 256 * 1024} }, |
| 89 | { 0, 1, 0x3, {0x000000, 512 * 1024} }, |
| 90 | }; |
| 91 | |
| 92 | struct w25q_range en25q80_ranges[] = { |
| 93 | { 0, 0, 0, {0, 0} }, /* none */ |
| 94 | { 0, 0, 0x1, {0x000000, 1016 * 1024} }, |
| 95 | { 0, 0, 0x2, {0x000000, 1008 * 1024} }, |
| 96 | { 0, 0, 0x3, {0x000000, 992 * 1024} }, |
| 97 | { 0, 0, 0x4, {0x000000, 960 * 1024} }, |
| 98 | { 0, 0, 0x5, {0x000000, 896 * 1024} }, |
| 99 | { 0, 0, 0x6, {0x000000, 768 * 1024} }, |
| 100 | { 0, 0, 0x7, {0x000000, 1024 * 1024} }, |
| 101 | }; |
| 102 | |
| 103 | struct w25q_range en25q32_ranges[] = { |
| 104 | { 0, 0, 0, {0, 0} }, /* none */ |
| 105 | { 0, 0, 0x1, {0x000000, 4032 * 1024} }, |
| 106 | { 0, 0, 0x2, {0x000000, 3968 * 1024} }, |
| 107 | { 0, 0, 0x3, {0x000000, 3840 * 1024} }, |
| 108 | { 0, 0, 0x4, {0x000000, 3584 * 1024} }, |
| 109 | { 0, 0, 0x5, {0x000000, 3072 * 1024} }, |
| 110 | { 0, 0, 0x6, {0x000000, 2048 * 1024} }, |
| 111 | { 0, 0, 0x7, {0x000000, 4096 * 1024} }, |
| 112 | |
| 113 | { 0, 1, 0, {0, 0} }, /* none */ |
| 114 | { 0, 1, 0x1, {0x010000, 4032 * 1024} }, |
| 115 | { 0, 1, 0x2, {0x020000, 3968 * 1024} }, |
| 116 | { 0, 1, 0x3, {0x040000, 3840 * 1024} }, |
| 117 | { 0, 1, 0x4, {0x080000, 3584 * 1024} }, |
| 118 | { 0, 1, 0x5, {0x100000, 3072 * 1024} }, |
| 119 | { 0, 1, 0x6, {0x200000, 2048 * 1024} }, |
| 120 | { 0, 1, 0x7, {0x000000, 4096 * 1024} }, |
| 121 | }; |
| 122 | |
| 123 | struct w25q_range en25q64_ranges[] = { |
| 124 | { 0, 0, 0, {0, 0} }, /* none */ |
| 125 | { 0, 0, 0x1, {0x000000, 8128 * 1024} }, |
| 126 | { 0, 0, 0x2, {0x000000, 8064 * 1024} }, |
| 127 | { 0, 0, 0x3, {0x000000, 7936 * 1024} }, |
| 128 | { 0, 0, 0x4, {0x000000, 7680 * 1024} }, |
| 129 | { 0, 0, 0x5, {0x000000, 7168 * 1024} }, |
| 130 | { 0, 0, 0x6, {0x000000, 6144 * 1024} }, |
| 131 | { 0, 0, 0x7, {0x000000, 8192 * 1024} }, |
| 132 | |
| 133 | { 0, 1, 0, {0, 0} }, /* none */ |
| 134 | { 0, 1, 0x1, {0x010000, 8128 * 1024} }, |
| 135 | { 0, 1, 0x2, {0x020000, 8064 * 1024} }, |
| 136 | { 0, 1, 0x3, {0x040000, 7936 * 1024} }, |
| 137 | { 0, 1, 0x4, {0x080000, 7680 * 1024} }, |
| 138 | { 0, 1, 0x5, {0x100000, 7168 * 1024} }, |
| 139 | { 0, 1, 0x6, {0x200000, 6144 * 1024} }, |
| 140 | { 0, 1, 0x7, {0x000000, 8192 * 1024} }, |
| 141 | }; |
| 142 | |
| 143 | struct w25q_range en25q128_ranges[] = { |
| 144 | { 0, 0, 0, {0, 0} }, /* none */ |
| 145 | { 0, 0, 0x1, {0x000000, 16320 * 1024} }, |
| 146 | { 0, 0, 0x2, {0x000000, 16256 * 1024} }, |
| 147 | { 0, 0, 0x3, {0x000000, 16128 * 1024} }, |
| 148 | { 0, 0, 0x4, {0x000000, 15872 * 1024} }, |
| 149 | { 0, 0, 0x5, {0x000000, 15360 * 1024} }, |
| 150 | { 0, 0, 0x6, {0x000000, 14336 * 1024} }, |
| 151 | { 0, 0, 0x7, {0x000000, 16384 * 1024} }, |
| 152 | |
| 153 | { 0, 1, 0, {0, 0} }, /* none */ |
| 154 | { 0, 1, 0x1, {0x010000, 16320 * 1024} }, |
| 155 | { 0, 1, 0x2, {0x020000, 16256 * 1024} }, |
| 156 | { 0, 1, 0x3, {0x040000, 16128 * 1024} }, |
| 157 | { 0, 1, 0x4, {0x080000, 15872 * 1024} }, |
| 158 | { 0, 1, 0x5, {0x100000, 15360 * 1024} }, |
| 159 | { 0, 1, 0x6, {0x200000, 14336 * 1024} }, |
| 160 | { 0, 1, 0x7, {0x000000, 16384 * 1024} }, |
| 161 | }; |
| 162 | |
David Hendricks | f8f00c7 | 2011-02-01 12:39:46 -0800 | [diff] [blame] | 163 | /* mx25l1005 ranges also work for the mx25l1005c */ |
| 164 | static struct w25q_range mx25l1005_ranges[] = { |
| 165 | { X, X, 0, {0, 0} }, /* none */ |
| 166 | { X, X, 0x1, {0x010000, 64 * 1024} }, |
| 167 | { X, X, 0x2, {0x000000, 128 * 1024} }, |
| 168 | { X, X, 0x3, {0x000000, 128 * 1024} }, |
| 169 | }; |
| 170 | |
| 171 | static struct w25q_range mx25l2005_ranges[] = { |
| 172 | { X, X, 0, {0, 0} }, /* none */ |
| 173 | { X, X, 0x1, {0x030000, 64 * 1024} }, |
| 174 | { X, X, 0x2, {0x020000, 128 * 1024} }, |
| 175 | { X, X, 0x3, {0x000000, 256 * 1024} }, |
| 176 | }; |
| 177 | |
| 178 | static struct w25q_range mx25l4005_ranges[] = { |
| 179 | { X, X, 0, {0, 0} }, /* none */ |
| 180 | { X, X, 0x1, {0x070000, 64 * 1 * 1024} }, /* block 7 */ |
| 181 | { X, X, 0x2, {0x060000, 64 * 2 * 1024} }, /* blocks 6-7 */ |
| 182 | { X, X, 0x3, {0x040000, 64 * 4 * 1024} }, /* blocks 4-7 */ |
| 183 | { X, X, 0x4, {0x000000, 512 * 1024} }, |
| 184 | { X, X, 0x5, {0x000000, 512 * 1024} }, |
| 185 | { X, X, 0x6, {0x000000, 512 * 1024} }, |
| 186 | { X, X, 0x7, {0x000000, 512 * 1024} }, |
| 187 | }; |
| 188 | |
| 189 | static struct w25q_range mx25l8005_ranges[] = { |
| 190 | { X, X, 0, {0, 0} }, /* none */ |
| 191 | { X, X, 0x1, {0x0f0000, 64 * 1 * 1024} }, /* block 15 */ |
| 192 | { X, X, 0x2, {0x0e0000, 64 * 2 * 1024} }, /* blocks 14-15 */ |
| 193 | { X, X, 0x3, {0x0c0000, 64 * 4 * 1024} }, /* blocks 12-15 */ |
| 194 | { X, X, 0x4, {0x080000, 64 * 8 * 1024} }, /* blocks 8-15 */ |
| 195 | { X, X, 0x5, {0x000000, 1024 * 1024} }, |
| 196 | { X, X, 0x6, {0x000000, 1024 * 1024} }, |
| 197 | { X, X, 0x7, {0x000000, 1024 * 1024} }, |
| 198 | }; |
| 199 | |
| 200 | #if 0 |
| 201 | /* FIXME: mx25l1605 has the same IDs as the mx25l1605d */ |
| 202 | static struct w25q_range mx25l1605_ranges[] = { |
| 203 | { X, X, 0, {0, 0} }, /* none */ |
| 204 | { X, X, 0x1, {0x1f0000, 64 * 1024} }, /* block 31 */ |
| 205 | { X, X, 0x2, {0x1e0000, 128 * 1024} }, /* blocks 30-31 */ |
| 206 | { X, X, 0x3, {0x1c0000, 256 * 1024} }, /* blocks 28-31 */ |
| 207 | { X, X, 0x4, {0x180000, 512 * 1024} }, /* blocks 24-31 */ |
| 208 | { X, X, 0x4, {0x100000, 1024 * 1024} }, /* blocks 16-31 */ |
| 209 | { X, X, 0x6, {0x000000, 2048 * 1024} }, |
| 210 | { X, X, 0x7, {0x000000, 2048 * 1024} }, |
| 211 | }; |
| 212 | #endif |
| 213 | |
| 214 | #if 0 |
| 215 | /* FIXME: mx25l6405 has the same IDs as the mx25l6405d */ |
| 216 | static struct w25q_range mx25l6405_ranges[] = { |
| 217 | { X, 0, 0, {0, 0} }, /* none */ |
| 218 | { X, 0, 0x1, {0x7f0000, 64 * 1 * 1024} }, /* block 127 */ |
| 219 | { X, 0, 0x2, {0x7e0000, 64 * 2 * 1024} }, /* blocks 126-127 */ |
| 220 | { X, 0, 0x3, {0x7c0000, 64 * 4 * 1024} }, /* blocks 124-127 */ |
| 221 | { X, 0, 0x4, {0x780000, 64 * 8 * 1024} }, /* blocks 120-127 */ |
| 222 | { X, 0, 0x5, {0x700000, 64 * 16 * 1024} }, /* blocks 112-127 */ |
| 223 | { X, 0, 0x6, {0x600000, 64 * 32 * 1024} }, /* blocks 96-127 */ |
| 224 | { X, 0, 0x7, {0x400000, 64 * 64 * 1024} }, /* blocks 64-127 */ |
| 225 | |
| 226 | { X, 1, 0x0, {0x000000, 8192 * 1024} }, |
| 227 | { X, 1, 0x1, {0x000000, 8192 * 1024} }, |
| 228 | { X, 1, 0x2, {0x000000, 8192 * 1024} }, |
| 229 | { X, 1, 0x3, {0x000000, 8192 * 1024} }, |
| 230 | { X, 1, 0x4, {0x000000, 8192 * 1024} }, |
| 231 | { X, 1, 0x5, {0x000000, 8192 * 1024} }, |
| 232 | { X, 1, 0x6, {0x000000, 8192 * 1024} }, |
| 233 | { X, 1, 0x7, {0x000000, 8192 * 1024} }, |
| 234 | }; |
| 235 | #endif |
| 236 | |
| 237 | static struct w25q_range mx25l1605d_ranges[] = { |
| 238 | { X, 0, 0, {0, 0} }, /* none */ |
| 239 | { X, 0, 0x1, {0x1f0000, 64 * 1 * 1024} }, /* block 31 */ |
| 240 | { X, 0, 0x2, {0x1e0000, 64 * 2 * 1024} }, /* blocks 30-31 */ |
| 241 | { X, 0, 0x3, {0x1c0000, 64 * 4 * 1024} }, /* blocks 28-31 */ |
| 242 | { X, 0, 0x4, {0x180000, 64 * 8 * 1024} }, /* blocks 24-31 */ |
| 243 | { X, 0, 0x5, {0x100000, 64 * 16 * 1024} }, /* blocks 16-31 */ |
| 244 | { X, 0, 0x6, {0x000000, 64 * 32 * 1024} }, /* blocks 0-31 */ |
| 245 | { X, 0, 0x7, {0x000000, 64 * 32 * 1024} }, /* blocks 0-31 */ |
| 246 | |
| 247 | { X, 1, 0x0, {0x000000, 2048 * 1024} }, |
| 248 | { X, 1, 0x1, {0x000000, 2048 * 1024} }, |
| 249 | { X, 1, 0x2, {0x000000, 64 * 16 * 1024} }, /* blocks 0-15 */ |
| 250 | { X, 1, 0x3, {0x000000, 64 * 24 * 1024} }, /* blocks 0-23 */ |
| 251 | { X, 1, 0x4, {0x000000, 64 * 28 * 1024} }, /* blocks 0-27 */ |
| 252 | { X, 1, 0x5, {0x000000, 64 * 30 * 1024} }, /* blocks 0-29 */ |
| 253 | { X, 1, 0x6, {0x000000, 64 * 31 * 1024} }, /* blocks 0-30 */ |
| 254 | { X, 1, 0x7, {0x000000, 64 * 32 * 1024} }, /* blocks 0-31 */ |
| 255 | }; |
| 256 | |
| 257 | /* FIXME: Is there an mx25l3205 (without a trailing letter)? */ |
David Hendricks | ac72e36 | 2010-08-16 18:20:03 -0700 | [diff] [blame] | 258 | static struct w25q_range mx25l3205d_ranges[] = { |
| 259 | { X, 0, 0, {0, 0} }, /* none */ |
| 260 | { X, 0, 0x1, {0x3f0000, 64 * 1024} }, |
| 261 | { X, 0, 0x2, {0x3e0000, 128 * 1024} }, |
| 262 | { X, 0, 0x3, {0x3c0000, 256 * 1024} }, |
| 263 | { X, 0, 0x4, {0x380000, 512 * 1024} }, |
| 264 | { X, 0, 0x5, {0x300000, 1024 * 1024} }, |
| 265 | { X, 0, 0x6, {0x200000, 2048 * 1024} }, |
| 266 | { X, 0, 0x7, {0x000000, 4096 * 1024} }, |
| 267 | |
| 268 | { X, 1, 0x0, {0x000000, 4096 * 1024} }, |
| 269 | { X, 1, 0x1, {0x000000, 2048 * 1024} }, |
| 270 | { X, 1, 0x2, {0x000000, 3072 * 1024} }, |
| 271 | { X, 1, 0x3, {0x000000, 3584 * 1024} }, |
| 272 | { X, 1, 0x4, {0x000000, 3840 * 1024} }, |
| 273 | { X, 1, 0x5, {0x000000, 3968 * 1024} }, |
| 274 | { X, 1, 0x6, {0x000000, 4032 * 1024} }, |
| 275 | { X, 1, 0x7, {0x000000, 4096 * 1024} }, |
| 276 | }; |
| 277 | |
David Hendricks | 1c9bc9c | 2011-07-20 15:25:44 -0700 | [diff] [blame] | 278 | #if 0 |
| 279 | /* FIXME: MX25L6405D has same ID as MX25L6406 */ |
David Hendricks | f8f00c7 | 2011-02-01 12:39:46 -0800 | [diff] [blame] | 280 | static struct w25q_range mx25l6405d_ranges[] = { |
| 281 | { X, 0, 0, {0, 0} }, /* none */ |
| 282 | { X, 0, 0x1, {0x7e0000, 2 * 64 * 1024} }, /* blocks 126-127 */ |
| 283 | { X, 0, 0x2, {0x7c0000, 4 * 64 * 1024} }, /* blocks 124-127 */ |
| 284 | { X, 0, 0x3, {0x780000, 8 * 64 * 1024} }, /* blocks 120-127 */ |
| 285 | { X, 0, 0x4, {0x700000, 16 * 64 * 1024} }, /* blocks 112-127 */ |
| 286 | { X, 0, 0x5, {0x600000, 32 * 64 * 1024} }, /* blocks 96-127 */ |
| 287 | { X, 0, 0x6, {0x400000, 64 * 64 * 1024} }, /* blocks 64-127 */ |
| 288 | { X, 0, 0x7, {0x000000, 64 * 128 * 1024} }, /* blocks 0-127 */ |
| 289 | |
| 290 | { X, 1, 0x0, {0x000000, 8192 * 1024} }, |
| 291 | { X, 1, 0x1, {0x000000, 64 * 64 * 1024} }, /* blocks 0-63 */ |
| 292 | { X, 1, 0x2, {0x000000, 64 * 96 * 1024} }, /* blocks 0-95 */ |
| 293 | { X, 1, 0x3, {0x000000, 64 * 112 * 1024} }, /* blocks 0-111 */ |
| 294 | { X, 1, 0x4, {0x000000, 64 * 120 * 1024} }, /* blocks 0-119 */ |
| 295 | { X, 1, 0x5, {0x000000, 64 * 124 * 1024} }, /* blocks 0-123 */ |
| 296 | { X, 1, 0x6, {0x000000, 64 * 126 * 1024} }, /* blocks 0-125 */ |
| 297 | { X, 1, 0x7, {0x000000, 64 * 128 * 1024} }, /* blocks 0-127 */ |
| 298 | }; |
David Hendricks | 1c9bc9c | 2011-07-20 15:25:44 -0700 | [diff] [blame] | 299 | #endif |
| 300 | |
| 301 | /* FIXME: MX25L6406 has same ID as MX25L6405D */ |
| 302 | static struct w25q_range mx25l6406e_ranges[] = { |
| 303 | { X, 0, 0, {0, 0} }, /* none */ |
| 304 | { X, 0, 0x1, {0x7e0000, 64 * 2 * 1024} }, /* blocks 126-127 */ |
| 305 | { X, 0, 0x2, {0x7c0000, 64 * 4 * 1024} }, /* blocks 124-127 */ |
| 306 | { X, 0, 0x3, {0x7a0000, 64 * 8 * 1024} }, /* blocks 120-127 */ |
| 307 | { X, 0, 0x4, {0x700000, 64 * 16 * 1024} }, /* blocks 112-127 */ |
| 308 | { X, 0, 0x5, {0x600000, 64 * 32 * 1024} }, /* blocks 96-127 */ |
| 309 | { X, 0, 0x6, {0x400000, 64 * 64 * 1024} }, /* blocks 64-127 */ |
| 310 | { X, 0, 0x7, {0x000000, 64 * 128 * 1024} }, /* all */ |
| 311 | |
| 312 | { X, 1, 0x0, {0x000000, 64 * 128 * 1024} }, /* all */ |
| 313 | { X, 1, 0x1, {0x000000, 64 * 64 * 1024} }, /* blocks 0-63 */ |
| 314 | { X, 1, 0x2, {0x000000, 64 * 96 * 1024} }, /* blocks 0-95 */ |
| 315 | { X, 1, 0x3, {0x000000, 64 * 112 * 1024} }, /* blocks 0-111 */ |
| 316 | { X, 1, 0x4, {0x000000, 64 * 120 * 1024} }, /* blocks 0-119 */ |
| 317 | { X, 1, 0x5, {0x000000, 64 * 124 * 1024} }, /* blocks 0-123 */ |
| 318 | { X, 1, 0x6, {0x000000, 64 * 126 * 1024} }, /* blocks 0-125 */ |
| 319 | { X, 1, 0x7, {0x000000, 64 * 128 * 1024} }, /* all */ |
| 320 | }; |
David Hendricks | f8f00c7 | 2011-02-01 12:39:46 -0800 | [diff] [blame] | 321 | |
David Hendricks | bfa624b | 2012-07-24 12:47:59 -0700 | [diff] [blame] | 322 | static struct w25q_range n25q064_ranges[] = { |
| 323 | { X, 0, 0, {0, 0} }, /* none */ |
| 324 | |
| 325 | { 0, 0, 0x1, {0x7f0000, 64 * 1024} }, /* block 127 */ |
| 326 | { 0, 0, 0x2, {0x7e0000, 2 * 64 * 1024} }, /* blocks 126-127 */ |
| 327 | { 0, 0, 0x3, {0x7c0000, 4 * 64 * 1024} }, /* blocks 124-127 */ |
| 328 | { 0, 0, 0x4, {0x780000, 8 * 64 * 1024} }, /* blocks 120-127 */ |
| 329 | { 0, 0, 0x5, {0x700000, 16 * 64 * 1024} }, /* blocks 112-127 */ |
| 330 | { 0, 0, 0x6, {0x600000, 32 * 64 * 1024} }, /* blocks 96-127 */ |
| 331 | { 0, 0, 0x7, {0x400000, 64 * 64 * 1024} }, /* blocks 64-127 */ |
| 332 | |
| 333 | { 1, 0, 0x1, {0x000000, 64 * 1024} }, /* block 0 */ |
| 334 | { 1, 0, 0x2, {0x000000, 2 * 64 * 1024} }, /* blocks 0-1 */ |
| 335 | { 1, 0, 0x3, {0x000000, 4 * 64 * 1024} }, /* blocks 0-3 */ |
| 336 | { 1, 0, 0x4, {0x000000, 8 * 64 * 1024} }, /* blocks 0-7 */ |
| 337 | { 1, 0, 0x5, {0x000000, 16 * 64 * 1024} }, /* blocks 0-15 */ |
| 338 | { 1, 0, 0x6, {0x000000, 32 * 64 * 1024} }, /* blocks 0-31 */ |
| 339 | { 1, 0, 0x7, {0x000000, 64 * 64 * 1024} }, /* blocks 0-63 */ |
| 340 | |
| 341 | { X, 1, 0x0, {0x000000, 128 * 64 * 1024} }, /* all */ |
| 342 | { X, 1, 0x1, {0x000000, 128 * 64 * 1024} }, /* all */ |
| 343 | { X, 1, 0x2, {0x000000, 128 * 64 * 1024} }, /* all */ |
| 344 | { X, 1, 0x3, {0x000000, 128 * 64 * 1024} }, /* all */ |
| 345 | { X, 1, 0x4, {0x000000, 128 * 64 * 1024} }, /* all */ |
| 346 | { X, 1, 0x5, {0x000000, 128 * 64 * 1024} }, /* all */ |
| 347 | { X, 1, 0x6, {0x000000, 128 * 64 * 1024} }, /* all */ |
| 348 | { X, 1, 0x7, {0x000000, 128 * 64 * 1024} }, /* all */ |
| 349 | }; |
| 350 | |
David Hendricks | f7924d1 | 2010-06-10 21:26:44 -0700 | [diff] [blame] | 351 | static struct w25q_range w25q16_ranges[] = { |
| 352 | { X, X, 0, {0, 0} }, /* none */ |
| 353 | { 0, 0, 0x1, {0x1f0000, 64 * 1024} }, |
| 354 | { 0, 0, 0x2, {0x1e0000, 128 * 1024} }, |
| 355 | { 0, 0, 0x3, {0x1c0000, 256 * 1024} }, |
| 356 | { 0, 0, 0x4, {0x180000, 512 * 1024} }, |
| 357 | { 0, 0, 0x5, {0x100000, 1024 * 1024} }, |
| 358 | |
| 359 | { 0, 1, 0x1, {0x000000, 64 * 1024} }, |
| 360 | { 0, 1, 0x2, {0x000000, 128 * 1024} }, |
| 361 | { 0, 1, 0x3, {0x000000, 256 * 1024} }, |
| 362 | { 0, 1, 0x4, {0x000000, 512 * 1024} }, |
| 363 | { 0, 1, 0x5, {0x000000, 1024 * 1024} }, |
| 364 | { X, X, 0x6, {0x000000, 2048 * 1024} }, |
| 365 | { X, X, 0x7, {0x000000, 2048 * 1024} }, |
| 366 | |
| 367 | { 1, 0, 0x1, {0x1ff000, 4 * 1024} }, |
| 368 | { 1, 0, 0x2, {0x1fe000, 8 * 1024} }, |
| 369 | { 1, 0, 0x3, {0x1fc000, 16 * 1024} }, |
| 370 | { 1, 0, 0x4, {0x1f8000, 32 * 1024} }, |
| 371 | { 1, 0, 0x5, {0x1f8000, 32 * 1024} }, |
| 372 | |
| 373 | { 1, 1, 0x1, {0x000000, 4 * 1024} }, |
| 374 | { 1, 1, 0x2, {0x000000, 8 * 1024} }, |
| 375 | { 1, 1, 0x3, {0x000000, 16 * 1024} }, |
| 376 | { 1, 1, 0x4, {0x000000, 32 * 1024} }, |
| 377 | { 1, 1, 0x5, {0x000000, 32 * 1024} }, |
| 378 | }; |
| 379 | |
| 380 | static struct w25q_range w25q32_ranges[] = { |
| 381 | { X, X, 0, {0, 0} }, /* none */ |
| 382 | { 0, 0, 0x1, {0x3f0000, 64 * 1024} }, |
| 383 | { 0, 0, 0x2, {0x3e0000, 128 * 1024} }, |
| 384 | { 0, 0, 0x3, {0x3c0000, 256 * 1024} }, |
| 385 | { 0, 0, 0x4, {0x380000, 512 * 1024} }, |
| 386 | { 0, 0, 0x5, {0x300000, 1024 * 1024} }, |
David Hendricks | 05653ff | 2010-06-15 16:05:12 -0700 | [diff] [blame] | 387 | { 0, 0, 0x6, {0x200000, 2048 * 1024} }, |
David Hendricks | f7924d1 | 2010-06-10 21:26:44 -0700 | [diff] [blame] | 388 | |
| 389 | { 0, 1, 0x1, {0x000000, 64 * 1024} }, |
| 390 | { 0, 1, 0x2, {0x000000, 128 * 1024} }, |
| 391 | { 0, 1, 0x3, {0x000000, 256 * 1024} }, |
| 392 | { 0, 1, 0x4, {0x000000, 512 * 1024} }, |
| 393 | { 0, 1, 0x5, {0x000000, 1024 * 1024} }, |
| 394 | { 0, 1, 0x6, {0x000000, 2048 * 1024} }, |
| 395 | { X, X, 0x7, {0x000000, 4096 * 1024} }, |
| 396 | |
| 397 | { 1, 0, 0x1, {0x3ff000, 4 * 1024} }, |
| 398 | { 1, 0, 0x2, {0x3fe000, 8 * 1024} }, |
| 399 | { 1, 0, 0x3, {0x3fc000, 16 * 1024} }, |
| 400 | { 1, 0, 0x4, {0x3f8000, 32 * 1024} }, |
| 401 | { 1, 0, 0x5, {0x3f8000, 32 * 1024} }, |
| 402 | |
| 403 | { 1, 1, 0x1, {0x000000, 4 * 1024} }, |
| 404 | { 1, 1, 0x2, {0x000000, 8 * 1024} }, |
| 405 | { 1, 1, 0x3, {0x000000, 16 * 1024} }, |
| 406 | { 1, 1, 0x4, {0x000000, 32 * 1024} }, |
| 407 | { 1, 1, 0x5, {0x000000, 32 * 1024} }, |
| 408 | }; |
| 409 | |
| 410 | static struct w25q_range w25q80_ranges[] = { |
| 411 | { X, X, 0, {0, 0} }, /* none */ |
| 412 | { 0, 0, 0x1, {0x0f0000, 64 * 1024} }, |
| 413 | { 0, 0, 0x2, {0x0e0000, 128 * 1024} }, |
| 414 | { 0, 0, 0x3, {0x0c0000, 256 * 1024} }, |
| 415 | { 0, 0, 0x4, {0x080000, 512 * 1024} }, |
| 416 | |
| 417 | { 0, 1, 0x1, {0x000000, 64 * 1024} }, |
| 418 | { 0, 1, 0x2, {0x000000, 128 * 1024} }, |
| 419 | { 0, 1, 0x3, {0x000000, 256 * 1024} }, |
| 420 | { 0, 1, 0x4, {0x000000, 512 * 1024} }, |
David Hendricks | 05653ff | 2010-06-15 16:05:12 -0700 | [diff] [blame] | 421 | { X, X, 0x6, {0x000000, 1024 * 1024} }, |
| 422 | { X, X, 0x7, {0x000000, 1024 * 1024} }, |
David Hendricks | f7924d1 | 2010-06-10 21:26:44 -0700 | [diff] [blame] | 423 | |
| 424 | { 1, 0, 0x1, {0x1ff000, 4 * 1024} }, |
| 425 | { 1, 0, 0x2, {0x1fe000, 8 * 1024} }, |
| 426 | { 1, 0, 0x3, {0x1fc000, 16 * 1024} }, |
| 427 | { 1, 0, 0x4, {0x1f8000, 32 * 1024} }, |
| 428 | { 1, 0, 0x5, {0x1f8000, 32 * 1024} }, |
| 429 | |
| 430 | { 1, 1, 0x1, {0x000000, 4 * 1024} }, |
| 431 | { 1, 1, 0x2, {0x000000, 8 * 1024} }, |
| 432 | { 1, 1, 0x3, {0x000000, 16 * 1024} }, |
| 433 | { 1, 1, 0x4, {0x000000, 32 * 1024} }, |
| 434 | { 1, 1, 0x5, {0x000000, 32 * 1024} }, |
| 435 | }; |
| 436 | |
David Hendricks | 2c4a76c | 2010-06-28 14:00:43 -0700 | [diff] [blame] | 437 | static struct w25q_range w25q64_ranges[] = { |
| 438 | { X, X, 0, {0, 0} }, /* none */ |
| 439 | |
| 440 | { 0, 0, 0x1, {0x7e0000, 128 * 1024} }, |
| 441 | { 0, 0, 0x2, {0x7c0000, 256 * 1024} }, |
| 442 | { 0, 0, 0x3, {0x780000, 512 * 1024} }, |
| 443 | { 0, 0, 0x4, {0x700000, 1024 * 1024} }, |
| 444 | { 0, 0, 0x5, {0x600000, 2048 * 1024} }, |
| 445 | { 0, 0, 0x6, {0x400000, 4096 * 1024} }, |
| 446 | |
| 447 | { 0, 1, 0x1, {0x000000, 128 * 1024} }, |
| 448 | { 0, 1, 0x2, {0x000000, 256 * 1024} }, |
| 449 | { 0, 1, 0x3, {0x000000, 512 * 1024} }, |
| 450 | { 0, 1, 0x4, {0x000000, 1024 * 1024} }, |
| 451 | { 0, 1, 0x5, {0x000000, 2048 * 1024} }, |
| 452 | { 0, 1, 0x6, {0x000000, 4096 * 1024} }, |
| 453 | { X, X, 0x7, {0x000000, 8192 * 1024} }, |
| 454 | |
| 455 | { 1, 0, 0x1, {0x7ff000, 4 * 1024} }, |
| 456 | { 1, 0, 0x2, {0x7fe000, 8 * 1024} }, |
| 457 | { 1, 0, 0x3, {0x7fc000, 16 * 1024} }, |
| 458 | { 1, 0, 0x4, {0x7f8000, 32 * 1024} }, |
| 459 | { 1, 0, 0x5, {0x7f8000, 32 * 1024} }, |
| 460 | |
| 461 | { 1, 1, 0x1, {0x000000, 4 * 1024} }, |
| 462 | { 1, 1, 0x2, {0x000000, 8 * 1024} }, |
| 463 | { 1, 1, 0x3, {0x000000, 16 * 1024} }, |
| 464 | { 1, 1, 0x4, {0x000000, 32 * 1024} }, |
| 465 | { 1, 1, 0x5, {0x000000, 32 * 1024} }, |
| 466 | }; |
| 467 | |
Louis Yung-Chieh Lo | 232951f | 2010-09-16 11:30:00 +0800 | [diff] [blame] | 468 | struct w25q_range w25x10_ranges[] = { |
| 469 | { X, X, 0, {0, 0} }, /* none */ |
| 470 | { 0, 0, 0x1, {0x010000, 64 * 1024} }, |
| 471 | { 0, 1, 0x1, {0x000000, 64 * 1024} }, |
| 472 | { X, X, 0x2, {0x000000, 128 * 1024} }, |
| 473 | { X, X, 0x3, {0x000000, 128 * 1024} }, |
| 474 | }; |
| 475 | |
| 476 | struct w25q_range w25x20_ranges[] = { |
| 477 | { X, X, 0, {0, 0} }, /* none */ |
| 478 | { 0, 0, 0x1, {0x030000, 64 * 1024} }, |
| 479 | { 0, 0, 0x2, {0x020000, 128 * 1024} }, |
| 480 | { 0, 1, 0x1, {0x000000, 64 * 1024} }, |
| 481 | { 0, 1, 0x2, {0x000000, 128 * 1024} }, |
| 482 | { 0, X, 0x3, {0x000000, 256 * 1024} }, |
| 483 | }; |
| 484 | |
David Hendricks | 470ca95 | 2010-08-13 14:01:53 -0700 | [diff] [blame] | 485 | struct w25q_range w25x40_ranges[] = { |
| 486 | { X, X, 0, {0, 0} }, /* none */ |
| 487 | { 0, 0, 0x1, {0x070000, 64 * 1024} }, |
| 488 | { 0, 0, 0x2, {0x060000, 128 * 1024} }, |
| 489 | { 0, 0, 0x3, {0x040000, 256 * 1024} }, |
| 490 | { 0, 1, 0x1, {0x000000, 64 * 1024} }, |
| 491 | { 0, 1, 0x2, {0x000000, 128 * 1024} }, |
| 492 | { 0, 1, 0x3, {0x000000, 256 * 1024} }, |
| 493 | { 0, X, 0x4, {0x000000, 512 * 1024} }, |
| 494 | }; |
| 495 | |
Louis Yung-Chieh Lo | 232951f | 2010-09-16 11:30:00 +0800 | [diff] [blame] | 496 | struct w25q_range w25x80_ranges[] = { |
| 497 | { X, X, 0, {0, 0} }, /* none */ |
| 498 | { 0, 0, 0x1, {0x0F0000, 64 * 1024} }, |
| 499 | { 0, 0, 0x2, {0x0E0000, 128 * 1024} }, |
| 500 | { 0, 0, 0x3, {0x0C0000, 256 * 1024} }, |
| 501 | { 0, 0, 0x4, {0x080000, 512 * 1024} }, |
| 502 | { 0, 1, 0x1, {0x000000, 64 * 1024} }, |
| 503 | { 0, 1, 0x2, {0x000000, 128 * 1024} }, |
| 504 | { 0, 1, 0x3, {0x000000, 256 * 1024} }, |
| 505 | { 0, 1, 0x4, {0x000000, 512 * 1024} }, |
| 506 | { 0, X, 0x5, {0x000000, 1024 * 1024} }, |
| 507 | { 0, X, 0x6, {0x000000, 1024 * 1024} }, |
| 508 | { 0, X, 0x7, {0x000000, 1024 * 1024} }, |
| 509 | }; |
| 510 | |
Shawn Nematbakhsh | 9e8ef49 | 2012-09-01 21:58:03 -0700 | [diff] [blame] | 511 | static struct w25q_range gd25q64_ranges[] = { |
| 512 | { X, X, 0, {0, 0} }, /* none */ |
| 513 | { 0, 0, 0x1, {0x7e0000, 128 * 1024} }, |
| 514 | { 0, 0, 0x2, {0x7c0000, 256 * 1024} }, |
| 515 | { 0, 0, 0x3, {0x780000, 512 * 1024} }, |
| 516 | { 0, 0, 0x4, {0x700000, 1024 * 1024} }, |
| 517 | { 0, 0, 0x5, {0x600000, 2048 * 1024} }, |
| 518 | { 0, 0, 0x6, {0x400000, 4096 * 1024} }, |
| 519 | |
| 520 | { 0, 1, 0x1, {0x000000, 128 * 1024} }, |
| 521 | { 0, 1, 0x2, {0x000000, 256 * 1024} }, |
| 522 | { 0, 1, 0x3, {0x000000, 512 * 1024} }, |
| 523 | { 0, 1, 0x4, {0x000000, 1024 * 1024} }, |
| 524 | { 0, 1, 0x5, {0x000000, 2048 * 1024} }, |
| 525 | { 0, 1, 0x6, {0x000000, 4096 * 1024} }, |
| 526 | { X, X, 0x7, {0x000000, 8192 * 1024} }, |
| 527 | |
| 528 | { 1, 0, 0x1, {0x7ff000, 4 * 1024} }, |
| 529 | { 1, 0, 0x2, {0x7fe000, 8 * 1024} }, |
| 530 | { 1, 0, 0x3, {0x7fc000, 16 * 1024} }, |
| 531 | { 1, 0, 0x4, {0x7f8000, 32 * 1024} }, |
| 532 | { 1, 0, 0x5, {0x7f8000, 32 * 1024} }, |
| 533 | { 1, 0, 0x6, {0x7f8000, 32 * 1024} }, |
| 534 | |
| 535 | { 1, 1, 0x1, {0x000000, 4 * 1024} }, |
| 536 | { 1, 1, 0x2, {0x000000, 8 * 1024} }, |
| 537 | { 1, 1, 0x3, {0x000000, 16 * 1024} }, |
| 538 | { 1, 1, 0x4, {0x000000, 32 * 1024} }, |
| 539 | { 1, 1, 0x5, {0x000000, 32 * 1024} }, |
| 540 | { 1, 1, 0x6, {0x000000, 32 * 1024} }, |
| 541 | }; |
| 542 | |
Louis Yung-Chieh Lo | c8ec715 | 2012-09-17 17:38:35 +0800 | [diff] [blame^] | 543 | static struct w25q_range a25l040_ranges[] = { |
| 544 | { X, X, 0x0, {0, 0} }, /* none */ |
| 545 | { X, X, 0x1, {0x70000, 64 * 1024} }, |
| 546 | { X, X, 0x2, {0x60000, 128 * 1024} }, |
| 547 | { X, X, 0x3, {0x40000, 256 * 1024} }, |
| 548 | { X, X, 0x4, {0x00000, 512 * 1024} }, |
| 549 | { X, X, 0x5, {0x00000, 512 * 1024} }, |
| 550 | { X, X, 0x6, {0x00000, 512 * 1024} }, |
| 551 | { X, X, 0x7, {0x00000, 512 * 1024} }, |
| 552 | }; |
| 553 | |
Louis Yung-Chieh Lo | a92e8b2 | 2010-10-08 13:31:27 +0800 | [diff] [blame] | 554 | /* Given a flash chip, this function returns its range table. */ |
| 555 | static int w25_range_table(const struct flashchip *flash, |
| 556 | struct w25q_range **w25q_ranges, |
| 557 | int *num_entries) |
David Hendricks | f7924d1 | 2010-06-10 21:26:44 -0700 | [diff] [blame] | 558 | { |
Louis Yung-Chieh Lo | a92e8b2 | 2010-10-08 13:31:27 +0800 | [diff] [blame] | 559 | *w25q_ranges = 0; |
| 560 | *num_entries = 0; |
David Hendricks | f7924d1 | 2010-06-10 21:26:44 -0700 | [diff] [blame] | 561 | |
David Hendricks | d494b0a | 2010-08-16 16:28:50 -0700 | [diff] [blame] | 562 | switch (flash->manufacture_id) { |
| 563 | case WINBOND_NEX_ID: |
| 564 | switch(flash->model_id) { |
David Hendricks | c801adb | 2010-12-09 16:58:56 -0800 | [diff] [blame] | 565 | case WINBOND_NEX_W25X10: |
Louis Yung-Chieh Lo | a92e8b2 | 2010-10-08 13:31:27 +0800 | [diff] [blame] | 566 | *w25q_ranges = w25x10_ranges; |
| 567 | *num_entries = ARRAY_SIZE(w25x10_ranges); |
Louis Yung-Chieh Lo | 232951f | 2010-09-16 11:30:00 +0800 | [diff] [blame] | 568 | break; |
David Hendricks | c801adb | 2010-12-09 16:58:56 -0800 | [diff] [blame] | 569 | case WINBOND_NEX_W25X20: |
Louis Yung-Chieh Lo | a92e8b2 | 2010-10-08 13:31:27 +0800 | [diff] [blame] | 570 | *w25q_ranges = w25x20_ranges; |
| 571 | *num_entries = ARRAY_SIZE(w25x20_ranges); |
Louis Yung-Chieh Lo | 232951f | 2010-09-16 11:30:00 +0800 | [diff] [blame] | 572 | break; |
David Hendricks | c801adb | 2010-12-09 16:58:56 -0800 | [diff] [blame] | 573 | case WINBOND_NEX_W25X40: |
Louis Yung-Chieh Lo | a92e8b2 | 2010-10-08 13:31:27 +0800 | [diff] [blame] | 574 | *w25q_ranges = w25x40_ranges; |
| 575 | *num_entries = ARRAY_SIZE(w25x40_ranges); |
David Hendricks | d494b0a | 2010-08-16 16:28:50 -0700 | [diff] [blame] | 576 | break; |
David Hendricks | c801adb | 2010-12-09 16:58:56 -0800 | [diff] [blame] | 577 | case WINBOND_NEX_W25X80: |
Louis Yung-Chieh Lo | a92e8b2 | 2010-10-08 13:31:27 +0800 | [diff] [blame] | 578 | *w25q_ranges = w25x80_ranges; |
| 579 | *num_entries = ARRAY_SIZE(w25x80_ranges); |
Louis Yung-Chieh Lo | 232951f | 2010-09-16 11:30:00 +0800 | [diff] [blame] | 580 | break; |
David Hendricks | c801adb | 2010-12-09 16:58:56 -0800 | [diff] [blame] | 581 | case WINBOND_NEX_W25Q80: |
Louis Yung-Chieh Lo | a92e8b2 | 2010-10-08 13:31:27 +0800 | [diff] [blame] | 582 | *w25q_ranges = w25q80_ranges; |
| 583 | *num_entries = ARRAY_SIZE(w25q80_ranges); |
David Hendricks | d494b0a | 2010-08-16 16:28:50 -0700 | [diff] [blame] | 584 | break; |
David Hendricks | c801adb | 2010-12-09 16:58:56 -0800 | [diff] [blame] | 585 | case WINBOND_NEX_W25Q16: |
Louis Yung-Chieh Lo | a92e8b2 | 2010-10-08 13:31:27 +0800 | [diff] [blame] | 586 | *w25q_ranges = w25q16_ranges; |
| 587 | *num_entries = ARRAY_SIZE(w25q16_ranges); |
David Hendricks | d494b0a | 2010-08-16 16:28:50 -0700 | [diff] [blame] | 588 | break; |
David Hendricks | c801adb | 2010-12-09 16:58:56 -0800 | [diff] [blame] | 589 | case WINBOND_NEX_W25Q32: |
Louis Yung-Chieh Lo | 469707f | 2012-05-18 16:38:37 +0800 | [diff] [blame] | 590 | case WINBOND_NEX_W25Q32DW: |
Louis Yung-Chieh Lo | a92e8b2 | 2010-10-08 13:31:27 +0800 | [diff] [blame] | 591 | *w25q_ranges = w25q32_ranges; |
| 592 | *num_entries = ARRAY_SIZE(w25q32_ranges); |
David Hendricks | d494b0a | 2010-08-16 16:28:50 -0700 | [diff] [blame] | 593 | break; |
David Hendricks | c801adb | 2010-12-09 16:58:56 -0800 | [diff] [blame] | 594 | case WINBOND_NEX_W25Q64: |
Louis Yung-Chieh Lo | a92e8b2 | 2010-10-08 13:31:27 +0800 | [diff] [blame] | 595 | *w25q_ranges = w25q64_ranges; |
| 596 | *num_entries = ARRAY_SIZE(w25q64_ranges); |
David Hendricks | d494b0a | 2010-08-16 16:28:50 -0700 | [diff] [blame] | 597 | break; |
| 598 | default: |
| 599 | msg_cerr("%s() %d: WINBOND flash chip mismatch (0x%04x)" |
| 600 | ", aborting\n", __func__, __LINE__, |
| 601 | flash->model_id); |
| 602 | return -1; |
| 603 | } |
David Hendricks | 2c4a76c | 2010-06-28 14:00:43 -0700 | [diff] [blame] | 604 | break; |
David Hendricks | 57566ed | 2010-08-16 18:24:45 -0700 | [diff] [blame] | 605 | case EON_ID_NOPREFIX: |
| 606 | switch (flash->model_id) { |
David Hendricks | c801adb | 2010-12-09 16:58:56 -0800 | [diff] [blame] | 607 | case EON_EN25F40: |
Louis Yung-Chieh Lo | a92e8b2 | 2010-10-08 13:31:27 +0800 | [diff] [blame] | 608 | *w25q_ranges = en25f40_ranges; |
| 609 | *num_entries = ARRAY_SIZE(en25f40_ranges); |
David Hendricks | 57566ed | 2010-08-16 18:24:45 -0700 | [diff] [blame] | 610 | break; |
David Hendricks | e185bf2 | 2011-05-24 15:34:18 -0700 | [diff] [blame] | 611 | case EON_EN25Q40: |
| 612 | *w25q_ranges = en25q40_ranges; |
| 613 | *num_entries = ARRAY_SIZE(en25q40_ranges); |
| 614 | break; |
| 615 | case EON_EN25Q80: |
| 616 | *w25q_ranges = en25q80_ranges; |
| 617 | *num_entries = ARRAY_SIZE(en25q80_ranges); |
| 618 | break; |
| 619 | case EON_EN25Q32: |
| 620 | *w25q_ranges = en25q32_ranges; |
| 621 | *num_entries = ARRAY_SIZE(en25q32_ranges); |
| 622 | break; |
| 623 | case EON_EN25Q64: |
| 624 | *w25q_ranges = en25q64_ranges; |
| 625 | *num_entries = ARRAY_SIZE(en25q64_ranges); |
| 626 | break; |
| 627 | case EON_EN25Q128: |
| 628 | *w25q_ranges = en25q128_ranges; |
| 629 | *num_entries = ARRAY_SIZE(en25q128_ranges); |
| 630 | break; |
David Hendricks | 57566ed | 2010-08-16 18:24:45 -0700 | [diff] [blame] | 631 | default: |
| 632 | msg_cerr("%s():%d: EON flash chip mismatch (0x%04x)" |
| 633 | ", aborting\n", __func__, __LINE__, |
| 634 | flash->model_id); |
| 635 | return -1; |
| 636 | } |
| 637 | break; |
David Hendricks | c801adb | 2010-12-09 16:58:56 -0800 | [diff] [blame] | 638 | case MACRONIX_ID: |
David Hendricks | ac72e36 | 2010-08-16 18:20:03 -0700 | [diff] [blame] | 639 | switch (flash->model_id) { |
David Hendricks | f8f00c7 | 2011-02-01 12:39:46 -0800 | [diff] [blame] | 640 | case MACRONIX_MX25L1005: |
| 641 | *w25q_ranges = mx25l1005_ranges; |
| 642 | *num_entries = ARRAY_SIZE(mx25l1005_ranges); |
| 643 | break; |
| 644 | case MACRONIX_MX25L2005: |
| 645 | *w25q_ranges = mx25l2005_ranges; |
| 646 | *num_entries = ARRAY_SIZE(mx25l2005_ranges); |
| 647 | break; |
| 648 | case MACRONIX_MX25L4005: |
| 649 | *w25q_ranges = mx25l4005_ranges; |
| 650 | *num_entries = ARRAY_SIZE(mx25l4005_ranges); |
| 651 | break; |
| 652 | case MACRONIX_MX25L8005: |
| 653 | *w25q_ranges = mx25l8005_ranges; |
| 654 | *num_entries = ARRAY_SIZE(mx25l8005_ranges); |
| 655 | break; |
| 656 | case MACRONIX_MX25L1605: |
| 657 | /* FIXME: MX25L1605 and MX25L1605D have different write |
| 658 | * protection capabilities, but share IDs */ |
| 659 | *w25q_ranges = mx25l1605d_ranges; |
| 660 | *num_entries = ARRAY_SIZE(mx25l1605d_ranges); |
| 661 | break; |
David Hendricks | c801adb | 2010-12-09 16:58:56 -0800 | [diff] [blame] | 662 | case MACRONIX_MX25L3205: |
Louis Yung-Chieh Lo | a92e8b2 | 2010-10-08 13:31:27 +0800 | [diff] [blame] | 663 | *w25q_ranges = mx25l3205d_ranges; |
| 664 | *num_entries = ARRAY_SIZE(mx25l3205d_ranges); |
David Hendricks | ac72e36 | 2010-08-16 18:20:03 -0700 | [diff] [blame] | 665 | break; |
David Hendricks | f8f00c7 | 2011-02-01 12:39:46 -0800 | [diff] [blame] | 666 | case MACRONIX_MX25L6405: |
David Hendricks | 1c9bc9c | 2011-07-20 15:25:44 -0700 | [diff] [blame] | 667 | /* FIXME: MX25L64* chips have mixed capabilities and |
| 668 | share IDs */ |
| 669 | *w25q_ranges = mx25l6406e_ranges; |
| 670 | *num_entries = ARRAY_SIZE(mx25l6406e_ranges); |
David Hendricks | f8f00c7 | 2011-02-01 12:39:46 -0800 | [diff] [blame] | 671 | break; |
David Hendricks | ac72e36 | 2010-08-16 18:20:03 -0700 | [diff] [blame] | 672 | default: |
| 673 | msg_cerr("%s():%d: MXIC flash chip mismatch (0x%04x)" |
| 674 | ", aborting\n", __func__, __LINE__, |
| 675 | flash->model_id); |
| 676 | return -1; |
| 677 | } |
| 678 | break; |
David Hendricks | bfa624b | 2012-07-24 12:47:59 -0700 | [diff] [blame] | 679 | case ST_ID: |
| 680 | switch(flash->model_id) { |
| 681 | case ST_N25Q064__1E: |
| 682 | case ST_N25Q064__3E: |
| 683 | *w25q_ranges = n25q064_ranges; |
| 684 | *num_entries = ARRAY_SIZE(n25q064_ranges); |
| 685 | break; |
| 686 | default: |
| 687 | msg_cerr("%s() %d: Micron flash chip mismatch" |
| 688 | " (0x%04x), aborting\n", __func__, __LINE__, |
| 689 | flash->model_id); |
| 690 | return -1; |
| 691 | } |
| 692 | break; |
Bryan Freed | 9a0051f | 2012-05-22 16:06:09 -0700 | [diff] [blame] | 693 | case GIGADEVICE_ID: |
| 694 | switch(flash->model_id) { |
| 695 | case GIGADEVICE_GD25LQ32: |
| 696 | *w25q_ranges = w25q32_ranges; |
| 697 | *num_entries = ARRAY_SIZE(w25q32_ranges); |
| 698 | break; |
Shawn Nematbakhsh | 9e8ef49 | 2012-09-01 21:58:03 -0700 | [diff] [blame] | 699 | case GIGADEVICE_GD25Q64: |
| 700 | *w25q_ranges = gd25q64_ranges; |
| 701 | *num_entries = ARRAY_SIZE(gd25q64_ranges); |
| 702 | break; |
| 703 | /* TODO(shawnn): add support for other GD parts */ |
Bryan Freed | 9a0051f | 2012-05-22 16:06:09 -0700 | [diff] [blame] | 704 | default: |
| 705 | msg_cerr("%s() %d: GigaDevice flash chip mismatch" |
| 706 | " (0x%04x), aborting\n", __func__, __LINE__, |
| 707 | flash->model_id); |
| 708 | return -1; |
| 709 | } |
| 710 | break; |
Louis Yung-Chieh Lo | c8ec715 | 2012-09-17 17:38:35 +0800 | [diff] [blame^] | 711 | case AMIC_ID_NOPREFIX: |
| 712 | switch(flash->model_id) { |
| 713 | case AMIC_A25L040: |
| 714 | *w25q_ranges = a25l040_ranges; |
| 715 | *num_entries = ARRAY_SIZE(a25l040_ranges); |
| 716 | break; |
| 717 | default: |
| 718 | msg_cerr("%s() %d: AMIC flash chip mismatch" |
| 719 | " (0x%04x), aborting\n", __func__, __LINE__, |
| 720 | flash->model_id); |
| 721 | return -1; |
| 722 | } |
| 723 | break; |
David Hendricks | f7924d1 | 2010-06-10 21:26:44 -0700 | [diff] [blame] | 724 | default: |
David Hendricks | d494b0a | 2010-08-16 16:28:50 -0700 | [diff] [blame] | 725 | msg_cerr("%s: flash vendor (0x%x) not found, aborting\n", |
| 726 | __func__, flash->manufacture_id); |
David Hendricks | f7924d1 | 2010-06-10 21:26:44 -0700 | [diff] [blame] | 727 | return -1; |
| 728 | } |
| 729 | |
Louis Yung-Chieh Lo | a92e8b2 | 2010-10-08 13:31:27 +0800 | [diff] [blame] | 730 | return 0; |
| 731 | } |
| 732 | |
| 733 | int w25_range_to_status(const struct flashchip *flash, |
| 734 | unsigned int start, unsigned int len, |
| 735 | struct w25q_status *status) |
| 736 | { |
| 737 | struct w25q_range *w25q_ranges; |
| 738 | int i, range_found = 0; |
| 739 | int num_entries; |
| 740 | |
| 741 | if (w25_range_table(flash, &w25q_ranges, &num_entries)) return -1; |
David Hendricks | f7924d1 | 2010-06-10 21:26:44 -0700 | [diff] [blame] | 742 | for (i = 0; i < num_entries; i++) { |
| 743 | struct wp_range *r = &w25q_ranges[i].range; |
| 744 | |
| 745 | msg_cspew("comparing range 0x%x 0x%x / 0x%x 0x%x\n", |
| 746 | start, len, r->start, r->len); |
| 747 | if ((start == r->start) && (len == r->len)) { |
David Hendricks | d494b0a | 2010-08-16 16:28:50 -0700 | [diff] [blame] | 748 | status->bp0 = w25q_ranges[i].bp & 1; |
| 749 | status->bp1 = w25q_ranges[i].bp >> 1; |
| 750 | status->bp2 = w25q_ranges[i].bp >> 2; |
| 751 | status->tb = w25q_ranges[i].tb; |
| 752 | status->sec = w25q_ranges[i].sec; |
David Hendricks | f7924d1 | 2010-06-10 21:26:44 -0700 | [diff] [blame] | 753 | |
| 754 | range_found = 1; |
| 755 | break; |
| 756 | } |
| 757 | } |
| 758 | |
| 759 | if (!range_found) { |
| 760 | msg_cerr("matching range not found\n"); |
| 761 | return -1; |
| 762 | } |
David Hendricks | d494b0a | 2010-08-16 16:28:50 -0700 | [diff] [blame] | 763 | return 0; |
| 764 | } |
| 765 | |
Louis Yung-Chieh Lo | a92e8b2 | 2010-10-08 13:31:27 +0800 | [diff] [blame] | 766 | int w25_status_to_range(const struct flashchip *flash, |
| 767 | const struct w25q_status *status, |
| 768 | unsigned int *start, unsigned int *len) |
| 769 | { |
| 770 | struct w25q_range *w25q_ranges; |
| 771 | int i, status_found = 0; |
| 772 | int num_entries; |
| 773 | |
| 774 | if (w25_range_table(flash, &w25q_ranges, &num_entries)) return -1; |
| 775 | for (i = 0; i < num_entries; i++) { |
| 776 | int bp; |
Louis Yung-Chieh Lo | edd3930 | 2011-11-10 15:43:06 +0800 | [diff] [blame] | 777 | int table_bp, table_tb, table_sec; |
Louis Yung-Chieh Lo | a92e8b2 | 2010-10-08 13:31:27 +0800 | [diff] [blame] | 778 | |
| 779 | bp = status->bp0 | (status->bp1 << 1) | (status->bp2 << 2); |
| 780 | msg_cspew("comparing 0x%x 0x%x / 0x%x 0x%x / 0x%x 0x%x\n", |
| 781 | bp, w25q_ranges[i].bp, |
| 782 | status->tb, w25q_ranges[i].tb, |
| 783 | status->sec, w25q_ranges[i].sec); |
Louis Yung-Chieh Lo | edd3930 | 2011-11-10 15:43:06 +0800 | [diff] [blame] | 784 | table_bp = w25q_ranges[i].bp; |
| 785 | table_tb = w25q_ranges[i].tb; |
| 786 | table_sec = w25q_ranges[i].sec; |
| 787 | if ((bp == table_bp || table_bp == X) && |
| 788 | (status->tb == table_tb || table_tb == X) && |
| 789 | (status->sec == table_sec || table_sec == X)) { |
Louis Yung-Chieh Lo | a92e8b2 | 2010-10-08 13:31:27 +0800 | [diff] [blame] | 790 | *start = w25q_ranges[i].range.start; |
| 791 | *len = w25q_ranges[i].range.len; |
| 792 | |
| 793 | status_found = 1; |
| 794 | break; |
| 795 | } |
| 796 | } |
| 797 | |
| 798 | if (!status_found) { |
| 799 | msg_cerr("matching status not found\n"); |
| 800 | return -1; |
| 801 | } |
| 802 | return 0; |
| 803 | } |
| 804 | |
Louis Yung-Chieh Lo | 52aa930 | 2010-09-06 10:45:02 +0800 | [diff] [blame] | 805 | /* Since most chips we use must be WREN-ed before WRSR, |
| 806 | * we copy a write status function here before we have a good solution. */ |
| 807 | static int spi_write_status_register_WREN(int status) |
| 808 | { |
| 809 | int result; |
| 810 | struct spi_command cmds[] = { |
| 811 | { |
| 812 | /* FIXME: WRSR requires either EWSR or WREN depending on chip type. */ |
| 813 | .writecnt = JEDEC_WREN_OUTSIZE, |
| 814 | .writearr = (const unsigned char[]){ JEDEC_WREN }, |
| 815 | .readcnt = 0, |
| 816 | .readarr = NULL, |
| 817 | }, { |
| 818 | .writecnt = JEDEC_WRSR_OUTSIZE, |
| 819 | .writearr = (const unsigned char[]){ JEDEC_WRSR, (unsigned char) status }, |
| 820 | .readcnt = 0, |
| 821 | .readarr = NULL, |
| 822 | }, { |
| 823 | .writecnt = 0, |
| 824 | .writearr = NULL, |
| 825 | .readcnt = 0, |
| 826 | .readarr = NULL, |
| 827 | }}; |
| 828 | |
| 829 | result = spi_send_multicommand(cmds); |
| 830 | if (result) { |
| 831 | msg_cerr("%s failed during command execution\n", |
| 832 | __func__); |
| 833 | } |
Louis Yung-Chieh Lo | 96222b1 | 2010-11-01 11:48:11 +0800 | [diff] [blame] | 834 | |
| 835 | /* WRSR performs a self-timed erase before the changes take effect. */ |
| 836 | programmer_delay(WRITE_STATUS_REGISTER_DELAY); |
| 837 | |
Louis Yung-Chieh Lo | 52aa930 | 2010-09-06 10:45:02 +0800 | [diff] [blame] | 838 | return result; |
| 839 | } |
| 840 | |
Louis Yung-Chieh Lo | 165b464 | 2010-11-26 16:35:26 +0800 | [diff] [blame] | 841 | /* Given a [start, len], this function calls w25_range_to_status() to convert |
| 842 | * it to flash-chip-specific range bits, then sets into status register. |
| 843 | */ |
David Hendricks | 9104083 | 2011-07-08 20:01:09 -0700 | [diff] [blame] | 844 | static int w25_set_range(const struct flashchip *flash, |
David Hendricks | d494b0a | 2010-08-16 16:28:50 -0700 | [diff] [blame] | 845 | unsigned int start, unsigned int len) |
| 846 | { |
| 847 | struct w25q_status status; |
Louis Yung-Chieh Lo | 165b464 | 2010-11-26 16:35:26 +0800 | [diff] [blame] | 848 | int tmp = 0; |
| 849 | int expected = 0; |
David Hendricks | d494b0a | 2010-08-16 16:28:50 -0700 | [diff] [blame] | 850 | |
| 851 | memset(&status, 0, sizeof(status)); |
| 852 | tmp = spi_read_status_register(); |
| 853 | memcpy(&status, &tmp, 1); |
| 854 | msg_cdbg("%s: old status: 0x%02x\n", __func__, tmp); |
| 855 | |
Louis Yung-Chieh Lo | a92e8b2 | 2010-10-08 13:31:27 +0800 | [diff] [blame] | 856 | if (w25_range_to_status(flash, start, len, &status)) return -1; |
David Hendricks | f7924d1 | 2010-06-10 21:26:44 -0700 | [diff] [blame] | 857 | |
| 858 | msg_cdbg("status.busy: %x\n", status.busy); |
| 859 | msg_cdbg("status.wel: %x\n", status.wel); |
| 860 | msg_cdbg("status.bp0: %x\n", status.bp0); |
| 861 | msg_cdbg("status.bp1: %x\n", status.bp1); |
| 862 | msg_cdbg("status.bp2: %x\n", status.bp2); |
| 863 | msg_cdbg("status.tb: %x\n", status.tb); |
| 864 | msg_cdbg("status.sec: %x\n", status.sec); |
| 865 | msg_cdbg("status.srp0: %x\n", status.srp0); |
| 866 | |
Louis Yung-Chieh Lo | 165b464 | 2010-11-26 16:35:26 +0800 | [diff] [blame] | 867 | memcpy(&expected, &status, sizeof(status)); |
| 868 | spi_write_status_register_WREN(expected); |
David Hendricks | f7924d1 | 2010-06-10 21:26:44 -0700 | [diff] [blame] | 869 | |
Louis Yung-Chieh Lo | 165b464 | 2010-11-26 16:35:26 +0800 | [diff] [blame] | 870 | tmp = spi_read_status_register(); |
| 871 | msg_cdbg("%s: new status: 0x%02x\n", __func__, tmp); |
| 872 | if ((tmp & MASK_WP_AREA) == (expected & MASK_WP_AREA)) { |
Louis Yung-Chieh Lo | 165b464 | 2010-11-26 16:35:26 +0800 | [diff] [blame] | 873 | return 0; |
| 874 | } else { |
David Hendricks | c801adb | 2010-12-09 16:58:56 -0800 | [diff] [blame] | 875 | msg_cerr("expected=0x%02x, but actual=0x%02x.\n", |
Louis Yung-Chieh Lo | 165b464 | 2010-11-26 16:35:26 +0800 | [diff] [blame] | 876 | expected, tmp); |
| 877 | return 1; |
| 878 | } |
David Hendricks | f7924d1 | 2010-06-10 21:26:44 -0700 | [diff] [blame] | 879 | } |
| 880 | |
Louis Yung-Chieh Lo | 165b464 | 2010-11-26 16:35:26 +0800 | [diff] [blame] | 881 | /* Print out the current status register value with human-readable text. */ |
David Hendricks | 9104083 | 2011-07-08 20:01:09 -0700 | [diff] [blame] | 882 | static int w25_wp_status(const struct flashchip *flash) |
Louis Yung-Chieh Lo | a92e8b2 | 2010-10-08 13:31:27 +0800 | [diff] [blame] | 883 | { |
| 884 | struct w25q_status status; |
| 885 | int tmp; |
David Hendricks | ce8ded3 | 2010-10-08 11:23:38 -0700 | [diff] [blame] | 886 | unsigned int start, len; |
Louis Yung-Chieh Lo | a92e8b2 | 2010-10-08 13:31:27 +0800 | [diff] [blame] | 887 | int ret = 0; |
| 888 | |
Louis Yung-Chieh Lo | 165b464 | 2010-11-26 16:35:26 +0800 | [diff] [blame] | 889 | memset(&status, 0, sizeof(status)); |
Louis Yung-Chieh Lo | a92e8b2 | 2010-10-08 13:31:27 +0800 | [diff] [blame] | 890 | tmp = spi_read_status_register(); |
| 891 | /* FIXME: this is NOT endian-free copy. */ |
| 892 | memcpy(&status, &tmp, 1); |
| 893 | msg_cinfo("WP: status: 0x%02x\n", tmp); |
| 894 | msg_cinfo("WP: status.srp0: %x\n", status.srp0); |
| 895 | msg_cinfo("WP: write protect is %s.\n", |
| 896 | status.srp0 ? "enabled" : "disabled"); |
| 897 | |
| 898 | msg_cinfo("WP: write protect range: "); |
| 899 | if (w25_status_to_range(flash, &status, &start, &len)) { |
| 900 | msg_cinfo("(cannot resolve the range)\n"); |
| 901 | ret = -1; |
| 902 | } else { |
| 903 | msg_cinfo("start=0x%08x, len=0x%08x\n", start, len); |
| 904 | } |
| 905 | |
| 906 | return ret; |
| 907 | } |
| 908 | |
Louis Yung-Chieh Lo | 165b464 | 2010-11-26 16:35:26 +0800 | [diff] [blame] | 909 | /* Set/clear the SRP0 bit in the status register. */ |
David Hendricks | 9104083 | 2011-07-08 20:01:09 -0700 | [diff] [blame] | 910 | static int w25_set_srp0(const struct flashchip *flash, int enable) |
David Hendricks | f7924d1 | 2010-06-10 21:26:44 -0700 | [diff] [blame] | 911 | { |
| 912 | struct w25q_status status; |
| 913 | int tmp = 0; |
Louis Yung-Chieh Lo | 165b464 | 2010-11-26 16:35:26 +0800 | [diff] [blame] | 914 | int expected = 0; |
David Hendricks | f7924d1 | 2010-06-10 21:26:44 -0700 | [diff] [blame] | 915 | |
| 916 | memset(&status, 0, sizeof(status)); |
| 917 | tmp = spi_read_status_register(); |
Louis Yung-Chieh Lo | 165b464 | 2010-11-26 16:35:26 +0800 | [diff] [blame] | 918 | /* FIXME: this is NOT endian-free copy. */ |
David Hendricks | f7924d1 | 2010-06-10 21:26:44 -0700 | [diff] [blame] | 919 | memcpy(&status, &tmp, 1); |
| 920 | msg_cdbg("%s: old status: 0x%02x\n", __func__, tmp); |
| 921 | |
Louis Yung-Chieh Lo | c19d3c5 | 2010-10-08 11:59:16 +0800 | [diff] [blame] | 922 | status.srp0 = enable ? 1 : 0; |
Louis Yung-Chieh Lo | 165b464 | 2010-11-26 16:35:26 +0800 | [diff] [blame] | 923 | memcpy(&expected, &status, sizeof(status)); |
| 924 | spi_write_status_register_WREN(expected); |
| 925 | |
| 926 | tmp = spi_read_status_register(); |
| 927 | msg_cdbg("%s: new status: 0x%02x\n", __func__, tmp); |
| 928 | if ((tmp & MASK_WP_AREA) != (expected & MASK_WP_AREA)) |
| 929 | return 1; |
David Hendricks | f7924d1 | 2010-06-10 21:26:44 -0700 | [diff] [blame] | 930 | |
| 931 | return 0; |
| 932 | } |
| 933 | |
David Hendricks | 9104083 | 2011-07-08 20:01:09 -0700 | [diff] [blame] | 934 | static int w25_enable_writeprotect(const struct flashchip *flash) |
Louis Yung-Chieh Lo | c19d3c5 | 2010-10-08 11:59:16 +0800 | [diff] [blame] | 935 | { |
| 936 | int ret; |
| 937 | |
| 938 | ret = w25_set_srp0(flash, 1); |
David Hendricks | c801adb | 2010-12-09 16:58:56 -0800 | [diff] [blame] | 939 | if (ret) |
| 940 | msg_cerr("%s(): error=%d.\n", __func__, ret); |
Louis Yung-Chieh Lo | c19d3c5 | 2010-10-08 11:59:16 +0800 | [diff] [blame] | 941 | return ret; |
| 942 | } |
| 943 | |
David Hendricks | 9104083 | 2011-07-08 20:01:09 -0700 | [diff] [blame] | 944 | static int w25_disable_writeprotect(const struct flashchip *flash) |
Louis Yung-Chieh Lo | c19d3c5 | 2010-10-08 11:59:16 +0800 | [diff] [blame] | 945 | { |
| 946 | int ret; |
| 947 | |
| 948 | ret = w25_set_srp0(flash, 0); |
David Hendricks | c801adb | 2010-12-09 16:58:56 -0800 | [diff] [blame] | 949 | if (ret) |
| 950 | msg_cerr("%s(): error=%d.\n", __func__, ret); |
Louis Yung-Chieh Lo | c19d3c5 | 2010-10-08 11:59:16 +0800 | [diff] [blame] | 951 | return ret; |
| 952 | } |
| 953 | |
David Hendricks | 9104083 | 2011-07-08 20:01:09 -0700 | [diff] [blame] | 954 | static int w25_list_ranges(const struct flashchip *flash) |
David Hendricks | 0f7f538 | 2011-02-11 18:12:31 -0800 | [diff] [blame] | 955 | { |
| 956 | struct w25q_range *w25q_ranges; |
| 957 | int i, num_entries; |
| 958 | |
| 959 | if (w25_range_table(flash, &w25q_ranges, &num_entries)) return -1; |
| 960 | for (i = 0; i < num_entries; i++) { |
| 961 | msg_cinfo("start: 0x%06x, length: 0x%06x\n", |
| 962 | w25q_ranges[i].range.start, |
| 963 | w25q_ranges[i].range.len); |
| 964 | } |
| 965 | |
| 966 | return 0; |
| 967 | } |
| 968 | |
David Hendricks | f7924d1 | 2010-06-10 21:26:44 -0700 | [diff] [blame] | 969 | struct wp wp_w25 = { |
David Hendricks | 0f7f538 | 2011-02-11 18:12:31 -0800 | [diff] [blame] | 970 | .list_ranges = w25_list_ranges, |
David Hendricks | f7924d1 | 2010-06-10 21:26:44 -0700 | [diff] [blame] | 971 | .set_range = w25_set_range, |
| 972 | .enable = w25_enable_writeprotect, |
Louis Yung-Chieh Lo | c19d3c5 | 2010-10-08 11:59:16 +0800 | [diff] [blame] | 973 | .disable = w25_disable_writeprotect, |
Louis Yung-Chieh Lo | a92e8b2 | 2010-10-08 13:31:27 +0800 | [diff] [blame] | 974 | .wp_status = w25_wp_status, |
David Hendricks | f7924d1 | 2010-06-10 21:26:44 -0700 | [diff] [blame] | 975 | }; |