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 | * |
David Hendricks | d1c55d7 | 2010-08-24 15:14:19 -0700 | [diff] [blame] | 16 | */ |
| 17 | |
David Hendricks | f7924d1 | 2010-06-10 21:26:44 -0700 | [diff] [blame] | 18 | #include <stdlib.h> |
| 19 | #include <string.h> |
Edward O'Callaghan | b4300ca | 2019-09-03 16:15:21 +1000 | [diff] [blame] | 20 | #include <strings.h> |
David Hendricks | f7924d1 | 2010-06-10 21:26:44 -0700 | [diff] [blame] | 21 | |
| 22 | #include "flash.h" |
| 23 | #include "flashchips.h" |
| 24 | #include "chipdrivers.h" |
Louis Yung-Chieh Lo | 52aa930 | 2010-09-06 10:45:02 +0800 | [diff] [blame] | 25 | #include "spi.h" |
David Hendricks | 23cd778 | 2010-08-25 12:42:38 -0700 | [diff] [blame] | 26 | #include "writeprotect.h" |
David Hendricks | f7924d1 | 2010-06-10 21:26:44 -0700 | [diff] [blame] | 27 | |
David Hendricks | 1c09f80 | 2012-10-03 11:03:48 -0700 | [diff] [blame] | 28 | /* |
David Hendricks | f7924d1 | 2010-06-10 21:26:44 -0700 | [diff] [blame] | 29 | * The following procedures rely on look-up tables to match the user-specified |
| 30 | * range with the chip's supported ranges. This turned out to be the most |
| 31 | * elegant approach since diferent flash chips use different levels of |
| 32 | * granularity and methods to determine protected ranges. In other words, |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 33 | * be stupid and simple since clever arithmetic will not work for many chips. |
David Hendricks | f7924d1 | 2010-06-10 21:26:44 -0700 | [diff] [blame] | 34 | */ |
| 35 | |
| 36 | struct wp_range { |
| 37 | unsigned int start; /* starting address */ |
| 38 | unsigned int len; /* len */ |
| 39 | }; |
| 40 | |
| 41 | enum bit_state { |
| 42 | OFF = 0, |
| 43 | ON = 1, |
Louis Yung-Chieh Lo | edd3930 | 2011-11-10 15:43:06 +0800 | [diff] [blame] | 44 | X = -1 /* don't care. Must be bigger than max # of bp. */ |
David Hendricks | f7924d1 | 2010-06-10 21:26:44 -0700 | [diff] [blame] | 45 | }; |
| 46 | |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 47 | /* |
| 48 | * Generic write-protection schema for 25-series SPI flash chips. This assumes |
| 49 | * there is a status register that contains one or more consecutive bits which |
| 50 | * determine which address range is protected. |
| 51 | */ |
| 52 | |
| 53 | struct status_register_layout { |
| 54 | int bp0_pos; /* position of BP0 */ |
| 55 | int bp_bits; /* number of block protect bits */ |
| 56 | int srp_pos; /* position of status register protect enable bit */ |
| 57 | }; |
| 58 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 59 | /* |
| 60 | * The following ranges and functions are useful for representing the |
| 61 | * writeprotect schema in which there are typically 5 bits of |
| 62 | * relevant information stored in status register 1: |
| 63 | * m.sec: This bit indicates the units (sectors vs. blocks) |
| 64 | * m.tb: The top-bottom bit indicates if the affected range is at the top of |
| 65 | * the flash memory's address space or at the bottom. |
| 66 | * bp: Bitmask representing the number of affected sectors/blocks. |
| 67 | */ |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 68 | struct wp_range_descriptor { |
Edward O'Callaghan | 9c4c9a5 | 2019-12-04 18:18:01 +1100 | [diff] [blame] | 69 | struct modifier_bits m; |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 70 | unsigned int bp; /* block protect bitfield */ |
| 71 | struct wp_range range; |
| 72 | }; |
| 73 | |
Edward O'Callaghan | c69f6b8 | 2019-12-05 16:49:21 +1100 | [diff] [blame] | 74 | struct w25q_status { |
| 75 | /* this maps to register layout -- do not change ordering */ |
| 76 | unsigned char busy : 1; |
| 77 | unsigned char wel : 1; |
| 78 | unsigned char bp0 : 1; |
| 79 | unsigned char bp1 : 1; |
| 80 | unsigned char bp2 : 1; |
| 81 | unsigned char tb : 1; |
| 82 | unsigned char sec : 1; |
| 83 | unsigned char srp0 : 1; |
| 84 | } __attribute__ ((packed)); |
| 85 | |
| 86 | /* Status register for large flash layouts with 4 BP bits */ |
| 87 | struct w25q_status_large { |
| 88 | unsigned char busy : 1; |
| 89 | unsigned char wel : 1; |
| 90 | unsigned char bp0 : 1; |
| 91 | unsigned char bp1 : 1; |
| 92 | unsigned char bp2 : 1; |
| 93 | unsigned char bp3 : 1; |
| 94 | unsigned char tb : 1; |
| 95 | unsigned char srp0 : 1; |
| 96 | } __attribute__ ((packed)); |
| 97 | |
| 98 | struct w25q_status_2 { |
| 99 | unsigned char srp1 : 1; |
| 100 | unsigned char qe : 1; |
| 101 | unsigned char rsvd : 6; |
| 102 | } __attribute__ ((packed)); |
| 103 | |
| 104 | int w25_range_to_status(const struct flashctx *flash, |
| 105 | unsigned int start, unsigned int len, |
| 106 | struct w25q_status *status); |
| 107 | int w25_status_to_range(const struct flashctx *flash, |
| 108 | const struct w25q_status *status, |
| 109 | unsigned int *start, unsigned int *len); |
| 110 | |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 111 | /* |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 112 | * Mask to extract write-protect enable and range bits |
| 113 | * Status register 1: |
| 114 | * SRP0: bit 7 |
| 115 | * range(BP2-BP0): bit 4-2 |
Duncan Laurie | 1801f7c | 2019-01-09 18:02:51 -0800 | [diff] [blame] | 116 | * range(BP3-BP0): bit 5-2 (large chips) |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 117 | * Status register 2: |
| 118 | * SRP1: bit 1 |
| 119 | */ |
| 120 | #define MASK_WP_AREA (0x9C) |
Duncan Laurie | 1801f7c | 2019-01-09 18:02:51 -0800 | [diff] [blame] | 121 | #define MASK_WP_AREA_LARGE (0x9C) |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 122 | #define MASK_WP2_AREA (0x01) |
| 123 | |
Edward O'Callaghan | 3b99650 | 2020-04-12 20:46:51 +1000 | [diff] [blame] | 124 | static struct wp_range_descriptor en25f40_ranges[] = { |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 125 | { .m = { .sec = X, .tb = X }, 0, {0, 0} }, /* none */ |
| 126 | { .m = { .sec = 0, .tb = 0 }, 0x1, {0x000000, 504 * 1024} }, |
| 127 | { .m = { .sec = 0, .tb = 0 }, 0x2, {0x000000, 496 * 1024} }, |
| 128 | { .m = { .sec = 0, .tb = 0 }, 0x3, {0x000000, 480 * 1024} }, |
| 129 | { .m = { .sec = 0, .tb = 0 }, 0x4, {0x000000, 448 * 1024} }, |
| 130 | { .m = { .sec = 0, .tb = 0 }, 0x5, {0x000000, 384 * 1024} }, |
| 131 | { .m = { .sec = 0, .tb = 0 }, 0x6, {0x000000, 256 * 1024} }, |
| 132 | { .m = { .sec = 0, .tb = 0 }, 0x7, {0x000000, 512 * 1024} }, |
David Hendricks | 57566ed | 2010-08-16 18:24:45 -0700 | [diff] [blame] | 133 | }; |
| 134 | |
Edward O'Callaghan | 3b99650 | 2020-04-12 20:46:51 +1000 | [diff] [blame] | 135 | static struct wp_range_descriptor en25q40_ranges[] = { |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 136 | { .m = { .sec = 0, .tb = 0 }, 0, {0, 0} }, /* none */ |
| 137 | { .m = { .sec = 0, .tb = 0 }, 0x1, {0x000000, 504 * 1024} }, |
| 138 | { .m = { .sec = 0, .tb = 0 }, 0x2, {0x000000, 496 * 1024} }, |
| 139 | { .m = { .sec = 0, .tb = 0 }, 0x3, {0x000000, 480 * 1024} }, |
David Hendricks | e185bf2 | 2011-05-24 15:34:18 -0700 | [diff] [blame] | 140 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 141 | { .m = { .sec = 0, .tb = 1 }, 0x0, {0x000000, 448 * 1024} }, |
| 142 | { .m = { .sec = 0, .tb = 1 }, 0x1, {0x000000, 384 * 1024} }, |
| 143 | { .m = { .sec = 0, .tb = 1 }, 0x2, {0x000000, 256 * 1024} }, |
| 144 | { .m = { .sec = 0, .tb = 1 }, 0x3, {0x000000, 512 * 1024} }, |
David Hendricks | e185bf2 | 2011-05-24 15:34:18 -0700 | [diff] [blame] | 145 | }; |
| 146 | |
Edward O'Callaghan | 3b99650 | 2020-04-12 20:46:51 +1000 | [diff] [blame] | 147 | static struct wp_range_descriptor en25q80_ranges[] = { |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 148 | { .m = { .sec = 0, .tb = 0 }, 0, {0, 0} }, /* none */ |
| 149 | { .m = { .sec = 0, .tb = 0 }, 0x1, {0x000000, 1016 * 1024} }, |
| 150 | { .m = { .sec = 0, .tb = 0 }, 0x2, {0x000000, 1008 * 1024} }, |
| 151 | { .m = { .sec = 0, .tb = 0 }, 0x3, {0x000000, 992 * 1024} }, |
| 152 | { .m = { .sec = 0, .tb = 0 }, 0x4, {0x000000, 960 * 1024} }, |
| 153 | { .m = { .sec = 0, .tb = 0 }, 0x5, {0x000000, 896 * 1024} }, |
| 154 | { .m = { .sec = 0, .tb = 0 }, 0x6, {0x000000, 768 * 1024} }, |
| 155 | { .m = { .sec = 0, .tb = 0 }, 0x7, {0x000000, 1024 * 1024} }, |
David Hendricks | e185bf2 | 2011-05-24 15:34:18 -0700 | [diff] [blame] | 156 | }; |
| 157 | |
Edward O'Callaghan | 3b99650 | 2020-04-12 20:46:51 +1000 | [diff] [blame] | 158 | static struct wp_range_descriptor en25q32_ranges[] = { |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 159 | { .m = { .sec = 0, .tb = 0 }, 0, {0, 0} }, /* none */ |
| 160 | { .m = { .sec = 0, .tb = 0 }, 0x1, {0x000000, 4032 * 1024} }, |
| 161 | { .m = { .sec = 0, .tb = 0 }, 0x2, {0x000000, 3968 * 1024} }, |
| 162 | { .m = { .sec = 0, .tb = 0 }, 0x3, {0x000000, 3840 * 1024} }, |
| 163 | { .m = { .sec = 0, .tb = 0 }, 0x4, {0x000000, 3584 * 1024} }, |
| 164 | { .m = { .sec = 0, .tb = 0 }, 0x5, {0x000000, 3072 * 1024} }, |
| 165 | { .m = { .sec = 0, .tb = 0 }, 0x6, {0x000000, 2048 * 1024} }, |
| 166 | { .m = { .sec = 0, .tb = 0 }, 0x7, {0x000000, 4096 * 1024} }, |
David Hendricks | e185bf2 | 2011-05-24 15:34:18 -0700 | [diff] [blame] | 167 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 168 | { .m = { .sec = 0, .tb = 1 }, 0, {0, 0} }, /* none */ |
| 169 | { .m = { .sec = 0, .tb = 1 }, 0x1, {0x010000, 4032 * 1024} }, |
| 170 | { .m = { .sec = 0, .tb = 1 }, 0x2, {0x020000, 3968 * 1024} }, |
| 171 | { .m = { .sec = 0, .tb = 1 }, 0x3, {0x040000, 3840 * 1024} }, |
| 172 | { .m = { .sec = 0, .tb = 1 }, 0x4, {0x080000, 3584 * 1024} }, |
| 173 | { .m = { .sec = 0, .tb = 1 }, 0x5, {0x100000, 3072 * 1024} }, |
| 174 | { .m = { .sec = 0, .tb = 1 }, 0x6, {0x200000, 2048 * 1024} }, |
| 175 | { .m = { .sec = 0, .tb = 1 }, 0x7, {0x000000, 4096 * 1024} }, |
David Hendricks | e185bf2 | 2011-05-24 15:34:18 -0700 | [diff] [blame] | 176 | }; |
| 177 | |
Edward O'Callaghan | 3b99650 | 2020-04-12 20:46:51 +1000 | [diff] [blame] | 178 | static struct wp_range_descriptor en25q64_ranges[] = { |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 179 | { .m = { .sec = 0, .tb = 0 }, 0, {0, 0} }, /* none */ |
| 180 | { .m = { .sec = 0, .tb = 0 }, 0x1, {0x000000, 8128 * 1024} }, |
| 181 | { .m = { .sec = 0, .tb = 0 }, 0x2, {0x000000, 8064 * 1024} }, |
| 182 | { .m = { .sec = 0, .tb = 0 }, 0x3, {0x000000, 7936 * 1024} }, |
| 183 | { .m = { .sec = 0, .tb = 0 }, 0x4, {0x000000, 7680 * 1024} }, |
| 184 | { .m = { .sec = 0, .tb = 0 }, 0x5, {0x000000, 7168 * 1024} }, |
| 185 | { .m = { .sec = 0, .tb = 0 }, 0x6, {0x000000, 6144 * 1024} }, |
| 186 | { .m = { .sec = 0, .tb = 0 }, 0x7, {0x000000, 8192 * 1024} }, |
David Hendricks | e185bf2 | 2011-05-24 15:34:18 -0700 | [diff] [blame] | 187 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 188 | { .m = { .sec = 0, .tb = 1 }, 0, {0, 0} }, /* none */ |
| 189 | { .m = { .sec = 0, .tb = 1 }, 0x1, {0x010000, 8128 * 1024} }, |
| 190 | { .m = { .sec = 0, .tb = 1 }, 0x2, {0x020000, 8064 * 1024} }, |
| 191 | { .m = { .sec = 0, .tb = 1 }, 0x3, {0x040000, 7936 * 1024} }, |
| 192 | { .m = { .sec = 0, .tb = 1 }, 0x4, {0x080000, 7680 * 1024} }, |
| 193 | { .m = { .sec = 0, .tb = 1 }, 0x5, {0x100000, 7168 * 1024} }, |
| 194 | { .m = { .sec = 0, .tb = 1 }, 0x6, {0x200000, 6144 * 1024} }, |
| 195 | { .m = { .sec = 0, .tb = 1 }, 0x7, {0x000000, 8192 * 1024} }, |
David Hendricks | e185bf2 | 2011-05-24 15:34:18 -0700 | [diff] [blame] | 196 | }; |
| 197 | |
Edward O'Callaghan | 3b99650 | 2020-04-12 20:46:51 +1000 | [diff] [blame] | 198 | static struct wp_range_descriptor en25q128_ranges[] = { |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 199 | { .m = { .sec = 0, .tb = 0 }, 0, {0, 0} }, /* none */ |
| 200 | { .m = { .sec = 0, .tb = 0 }, 0x1, {0x000000, 16320 * 1024} }, |
| 201 | { .m = { .sec = 0, .tb = 0 }, 0x2, {0x000000, 16256 * 1024} }, |
| 202 | { .m = { .sec = 0, .tb = 0 }, 0x3, {0x000000, 16128 * 1024} }, |
| 203 | { .m = { .sec = 0, .tb = 0 }, 0x4, {0x000000, 15872 * 1024} }, |
| 204 | { .m = { .sec = 0, .tb = 0 }, 0x5, {0x000000, 15360 * 1024} }, |
| 205 | { .m = { .sec = 0, .tb = 0 }, 0x6, {0x000000, 14336 * 1024} }, |
| 206 | { .m = { .sec = 0, .tb = 0 }, 0x7, {0x000000, 16384 * 1024} }, |
David Hendricks | e185bf2 | 2011-05-24 15:34:18 -0700 | [diff] [blame] | 207 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 208 | { .m = { .sec = 0, .tb = 1 }, 0, {0, 0} }, /* none */ |
| 209 | { .m = { .sec = 0, .tb = 1 }, 0x1, {0x010000, 16320 * 1024} }, |
| 210 | { .m = { .sec = 0, .tb = 1 }, 0x2, {0x020000, 16256 * 1024} }, |
| 211 | { .m = { .sec = 0, .tb = 1 }, 0x3, {0x040000, 16128 * 1024} }, |
| 212 | { .m = { .sec = 0, .tb = 1 }, 0x4, {0x080000, 15872 * 1024} }, |
| 213 | { .m = { .sec = 0, .tb = 1 }, 0x5, {0x100000, 15360 * 1024} }, |
| 214 | { .m = { .sec = 0, .tb = 1 }, 0x6, {0x200000, 14336 * 1024} }, |
| 215 | { .m = { .sec = 0, .tb = 1 }, 0x7, {0x000000, 16384 * 1024} }, |
David Hendricks | e185bf2 | 2011-05-24 15:34:18 -0700 | [diff] [blame] | 216 | }; |
| 217 | |
Edward O'Callaghan | 3b99650 | 2020-04-12 20:46:51 +1000 | [diff] [blame] | 218 | static struct wp_range_descriptor en25s64_ranges[] = { |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 219 | { .m = { .sec = 0, .tb = 0 }, 0, {0, 0} }, /* none */ |
| 220 | { .m = { .sec = 0, .tb = 0 }, 0x1, {0x000000, 8064 * 1024} }, |
| 221 | { .m = { .sec = 0, .tb = 0 }, 0x2, {0x000000, 7936 * 1024} }, |
| 222 | { .m = { .sec = 0, .tb = 0 }, 0x3, {0x000000, 7680 * 1024} }, |
| 223 | { .m = { .sec = 0, .tb = 0 }, 0x4, {0x000000, 7168 * 1024} }, |
| 224 | { .m = { .sec = 0, .tb = 0 }, 0x5, {0x000000, 6144 * 1024} }, |
| 225 | { .m = { .sec = 0, .tb = 0 }, 0x6, {0x000000, 4096 * 1024} }, |
| 226 | { .m = { .sec = 0, .tb = 0 }, 0x7, {0x000000, 8192 * 1024} }, |
Marc Jones | b2f9002 | 2014-04-29 17:37:23 -0600 | [diff] [blame] | 227 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 228 | { .m = { .sec = 0, .tb = 1 }, 0, {0, 0} }, /* none */ |
| 229 | { .m = { .sec = 0, .tb = 1 }, 0x1, {0x7e0000, 128 * 1024} }, |
| 230 | { .m = { .sec = 0, .tb = 1 }, 0x2, {0x7c0000, 256 * 1024} }, |
| 231 | { .m = { .sec = 0, .tb = 1 }, 0x3, {0x780000, 512 * 1024} }, |
| 232 | { .m = { .sec = 0, .tb = 1 }, 0x4, {0x700000, 1024 * 1024} }, |
| 233 | { .m = { .sec = 0, .tb = 1 }, 0x5, {0x600000, 2048 * 1024} }, |
| 234 | { .m = { .sec = 0, .tb = 1 }, 0x6, {0x400000, 4096 * 1024} }, |
| 235 | { .m = { .sec = 0, .tb = 1 }, 0x7, {0x000000, 8192 * 1024} }, |
Marc Jones | b2f9002 | 2014-04-29 17:37:23 -0600 | [diff] [blame] | 236 | }; |
| 237 | |
David Hendricks | f8f00c7 | 2011-02-01 12:39:46 -0800 | [diff] [blame] | 238 | /* mx25l1005 ranges also work for the mx25l1005c */ |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 239 | static struct wp_range_descriptor mx25l1005_ranges[] = { |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 240 | { .m = { .sec = X, .tb = X }, 0, {0, 0} }, /* none */ |
| 241 | { .m = { .sec = X, .tb = X }, 0x1, {0x010000, 64 * 1024} }, |
| 242 | { .m = { .sec = X, .tb = X }, 0x2, {0x000000, 128 * 1024} }, |
| 243 | { .m = { .sec = X, .tb = X }, 0x3, {0x000000, 128 * 1024} }, |
David Hendricks | f8f00c7 | 2011-02-01 12:39:46 -0800 | [diff] [blame] | 244 | }; |
| 245 | |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 246 | static struct wp_range_descriptor mx25l2005_ranges[] = { |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 247 | { .m = { .sec = X, .tb = X }, 0, {0, 0} }, /* none */ |
| 248 | { .m = { .sec = X, .tb = X }, 0x1, {0x030000, 64 * 1024} }, |
| 249 | { .m = { .sec = X, .tb = X }, 0x2, {0x020000, 128 * 1024} }, |
| 250 | { .m = { .sec = X, .tb = X }, 0x3, {0x000000, 256 * 1024} }, |
David Hendricks | f8f00c7 | 2011-02-01 12:39:46 -0800 | [diff] [blame] | 251 | }; |
| 252 | |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 253 | static struct wp_range_descriptor mx25l4005_ranges[] = { |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 254 | { .m = { .sec = X, .tb = X }, 0, {0, 0} }, /* none */ |
| 255 | { .m = { .sec = X, .tb = X }, 0x1, {0x070000, 64 * 1 * 1024} }, /* block 7 */ |
| 256 | { .m = { .sec = X, .tb = X }, 0x2, {0x060000, 64 * 2 * 1024} }, /* blocks 6-7 */ |
| 257 | { .m = { .sec = X, .tb = X }, 0x3, {0x040000, 64 * 4 * 1024} }, /* blocks 4-7 */ |
| 258 | { .m = { .sec = X, .tb = X }, 0x4, {0x000000, 512 * 1024} }, |
| 259 | { .m = { .sec = X, .tb = X }, 0x5, {0x000000, 512 * 1024} }, |
| 260 | { .m = { .sec = X, .tb = X }, 0x6, {0x000000, 512 * 1024} }, |
| 261 | { .m = { .sec = X, .tb = X }, 0x7, {0x000000, 512 * 1024} }, |
David Hendricks | f8f00c7 | 2011-02-01 12:39:46 -0800 | [diff] [blame] | 262 | }; |
| 263 | |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 264 | static struct wp_range_descriptor mx25l8005_ranges[] = { |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 265 | { .m = { .sec = X, .tb = X }, 0, {0, 0} }, /* none */ |
| 266 | { .m = { .sec = X, .tb = X }, 0x1, {0x0f0000, 64 * 1 * 1024} }, /* block 15 */ |
| 267 | { .m = { .sec = X, .tb = X }, 0x2, {0x0e0000, 64 * 2 * 1024} }, /* blocks 14-15 */ |
| 268 | { .m = { .sec = X, .tb = X }, 0x3, {0x0c0000, 64 * 4 * 1024} }, /* blocks 12-15 */ |
| 269 | { .m = { .sec = X, .tb = X }, 0x4, {0x080000, 64 * 8 * 1024} }, /* blocks 8-15 */ |
| 270 | { .m = { .sec = X, .tb = X }, 0x5, {0x000000, 1024 * 1024} }, |
| 271 | { .m = { .sec = X, .tb = X }, 0x6, {0x000000, 1024 * 1024} }, |
| 272 | { .m = { .sec = X, .tb = X }, 0x7, {0x000000, 1024 * 1024} }, |
David Hendricks | f8f00c7 | 2011-02-01 12:39:46 -0800 | [diff] [blame] | 273 | }; |
| 274 | |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 275 | static struct wp_range_descriptor mx25l1605d_ranges[] = { |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 276 | { .m = { .sec = X, .tb = 0 }, 0, {0, 0} }, /* none */ |
| 277 | { .m = { .sec = X, .tb = 0 }, 0x1, {0x1f0000, 64 * 1 * 1024} }, /* block 31 */ |
| 278 | { .m = { .sec = X, .tb = 0 }, 0x2, {0x1e0000, 64 * 2 * 1024} }, /* blocks 30-31 */ |
| 279 | { .m = { .sec = X, .tb = 0 }, 0x3, {0x1c0000, 64 * 4 * 1024} }, /* blocks 28-31 */ |
| 280 | { .m = { .sec = X, .tb = 0 }, 0x4, {0x180000, 64 * 8 * 1024} }, /* blocks 24-31 */ |
| 281 | { .m = { .sec = X, .tb = 0 }, 0x5, {0x100000, 64 * 16 * 1024} }, /* blocks 16-31 */ |
| 282 | { .m = { .sec = X, .tb = 0 }, 0x6, {0x000000, 64 * 32 * 1024} }, /* blocks 0-31 */ |
| 283 | { .m = { .sec = X, .tb = 0 }, 0x7, {0x000000, 64 * 32 * 1024} }, /* blocks 0-31 */ |
David Hendricks | f8f00c7 | 2011-02-01 12:39:46 -0800 | [diff] [blame] | 284 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 285 | { .m = { .sec = X, .tb = 1 }, 0x0, {0x000000, 2048 * 1024} }, |
| 286 | { .m = { .sec = X, .tb = 1 }, 0x1, {0x000000, 2048 * 1024} }, |
| 287 | { .m = { .sec = X, .tb = 1 }, 0x2, {0x000000, 64 * 16 * 1024} }, /* blocks 0-15 */ |
| 288 | { .m = { .sec = X, .tb = 1 }, 0x3, {0x000000, 64 * 24 * 1024} }, /* blocks 0-23 */ |
| 289 | { .m = { .sec = X, .tb = 1 }, 0x4, {0x000000, 64 * 28 * 1024} }, /* blocks 0-27 */ |
| 290 | { .m = { .sec = X, .tb = 1 }, 0x5, {0x000000, 64 * 30 * 1024} }, /* blocks 0-29 */ |
| 291 | { .m = { .sec = X, .tb = 1 }, 0x6, {0x000000, 64 * 31 * 1024} }, /* blocks 0-30 */ |
| 292 | { .m = { .sec = X, .tb = 1 }, 0x7, {0x000000, 64 * 32 * 1024} }, /* blocks 0-31 */ |
David Hendricks | f8f00c7 | 2011-02-01 12:39:46 -0800 | [diff] [blame] | 293 | }; |
| 294 | |
| 295 | /* FIXME: Is there an mx25l3205 (without a trailing letter)? */ |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 296 | static struct wp_range_descriptor mx25l3205d_ranges[] = { |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 297 | { .m = { .sec = X, .tb = 0 }, 0, {0, 0} }, /* none */ |
| 298 | { .m = { .sec = X, .tb = 0 }, 0x1, {0x3f0000, 64 * 1024} }, |
| 299 | { .m = { .sec = X, .tb = 0 }, 0x2, {0x3e0000, 128 * 1024} }, |
| 300 | { .m = { .sec = X, .tb = 0 }, 0x3, {0x3c0000, 256 * 1024} }, |
| 301 | { .m = { .sec = X, .tb = 0 }, 0x4, {0x380000, 512 * 1024} }, |
| 302 | { .m = { .sec = X, .tb = 0 }, 0x5, {0x300000, 1024 * 1024} }, |
| 303 | { .m = { .sec = X, .tb = 0 }, 0x6, {0x200000, 2048 * 1024} }, |
| 304 | { .m = { .sec = X, .tb = 0 }, 0x7, {0x000000, 4096 * 1024} }, |
David Hendricks | ac72e36 | 2010-08-16 18:20:03 -0700 | [diff] [blame] | 305 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 306 | { .m = { .sec = X, .tb = 1 }, 0x0, {0x000000, 4096 * 1024} }, |
| 307 | { .m = { .sec = X, .tb = 1 }, 0x1, {0x000000, 2048 * 1024} }, |
| 308 | { .m = { .sec = X, .tb = 1 }, 0x2, {0x000000, 3072 * 1024} }, |
| 309 | { .m = { .sec = X, .tb = 1 }, 0x3, {0x000000, 3584 * 1024} }, |
| 310 | { .m = { .sec = X, .tb = 1 }, 0x4, {0x000000, 3840 * 1024} }, |
| 311 | { .m = { .sec = X, .tb = 1 }, 0x5, {0x000000, 3968 * 1024} }, |
| 312 | { .m = { .sec = X, .tb = 1 }, 0x6, {0x000000, 4032 * 1024} }, |
| 313 | { .m = { .sec = X, .tb = 1 }, 0x7, {0x000000, 4096 * 1024} }, |
David Hendricks | ac72e36 | 2010-08-16 18:20:03 -0700 | [diff] [blame] | 314 | }; |
| 315 | |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 316 | static struct wp_range_descriptor mx25u3235e_ranges[] = { |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 317 | { .m = { .sec = X, .tb = 0 }, 0, {0, 0} }, /* none */ |
| 318 | { .m = { .sec = 0, .tb = 0 }, 0x1, {0x3f0000, 64 * 1024} }, |
| 319 | { .m = { .sec = 0, .tb = 0 }, 0x2, {0x3e0000, 128 * 1024} }, |
| 320 | { .m = { .sec = 0, .tb = 0 }, 0x3, {0x3c0000, 256 * 1024} }, |
| 321 | { .m = { .sec = 0, .tb = 0 }, 0x4, {0x380000, 512 * 1024} }, |
| 322 | { .m = { .sec = 0, .tb = 0 }, 0x5, {0x300000, 1024 * 1024} }, |
| 323 | { .m = { .sec = 0, .tb = 0 }, 0x6, {0x200000, 2048 * 1024} }, |
| 324 | { .m = { .sec = 0, .tb = 0 }, 0x7, {0x000000, 4096 * 1024} }, |
Vincent Palatin | 87e092a | 2013-02-28 15:46:14 -0800 | [diff] [blame] | 325 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 326 | { .m = { .sec = 0, .tb = 1 }, 0x0, {0x000000, 4096 * 1024} }, |
| 327 | { .m = { .sec = 0, .tb = 1 }, 0x1, {0x000000, 2048 * 1024} }, |
| 328 | { .m = { .sec = 0, .tb = 1 }, 0x2, {0x000000, 3072 * 1024} }, |
| 329 | { .m = { .sec = 0, .tb = 1 }, 0x3, {0x000000, 3584 * 1024} }, |
| 330 | { .m = { .sec = 0, .tb = 1 }, 0x4, {0x000000, 3840 * 1024} }, |
| 331 | { .m = { .sec = 0, .tb = 1 }, 0x5, {0x000000, 3968 * 1024} }, |
| 332 | { .m = { .sec = 0, .tb = 1 }, 0x6, {0x000000, 4032 * 1024} }, |
| 333 | { .m = { .sec = 0, .tb = 1 }, 0x7, {0x000000, 4096 * 1024} }, |
Vincent Palatin | 87e092a | 2013-02-28 15:46:14 -0800 | [diff] [blame] | 334 | }; |
| 335 | |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 336 | static struct wp_range_descriptor mx25u6435e_ranges[] = { |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 337 | { .m = { .sec = X, .tb = 0 }, 0, {0, 0} }, /* none */ |
| 338 | { .m = { .sec = 0, .tb = 0 }, 0x1, {0x7f0000, 1 * 64 * 1024} }, /* block 127 */ |
| 339 | { .m = { .sec = 0, .tb = 0 }, 0x2, {0x7e0000, 2 * 64 * 1024} }, /* blocks 126-127 */ |
| 340 | { .m = { .sec = 0, .tb = 0 }, 0x3, {0x7c0000, 4 * 64 * 1024} }, /* blocks 124-127 */ |
| 341 | { .m = { .sec = 0, .tb = 0 }, 0x4, {0x780000, 8 * 64 * 1024} }, /* blocks 120-127 */ |
| 342 | { .m = { .sec = 0, .tb = 0 }, 0x5, {0x700000, 16 * 64 * 1024} }, /* blocks 112-127 */ |
| 343 | { .m = { .sec = 0, .tb = 0 }, 0x6, {0x600000, 32 * 64 * 1024} }, /* blocks 96-127 */ |
| 344 | { .m = { .sec = 0, .tb = 0 }, 0x7, {0x400000, 64 * 64 * 1024} }, /* blocks 64-127 */ |
Jongpil | 66a9649 | 2014-08-14 17:59:06 +0900 | [diff] [blame] | 345 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 346 | { .m = { .sec = 0, .tb = 1 }, 0x0, {0x000000, 64 * 64 * 1024} }, /* blocks 0-63 */ |
| 347 | { .m = { .sec = 0, .tb = 1 }, 0x1, {0x000000, 96 * 64 * 1024} }, /* blocks 0-95 */ |
| 348 | { .m = { .sec = 0, .tb = 1 }, 0x2, {0x000000, 112 * 64 * 1024} }, /* blocks 0-111 */ |
| 349 | { .m = { .sec = 0, .tb = 1 }, 0x3, {0x000000, 120 * 64 * 1024} }, /* blocks 0-119 */ |
| 350 | { .m = { .sec = 0, .tb = 1 }, 0x4, {0x000000, 124 * 64 * 1024} }, /* blocks 0-123 */ |
| 351 | { .m = { .sec = 0, .tb = 1 }, 0x5, {0x000000, 126 * 64 * 1024} }, /* blocks 0-125 */ |
| 352 | { .m = { .sec = 0, .tb = 1 }, 0x6, {0x000000, 127 * 64 * 1024} }, /* blocks 0-126 */ |
| 353 | { .m = { .sec = 0, .tb = 1 }, 0x7, {0x000000, 128 * 64 * 1024} }, /* blocks 0-127 */ |
Jongpil | 66a9649 | 2014-08-14 17:59:06 +0900 | [diff] [blame] | 354 | }; |
| 355 | |
Karthikeyan Ramasubramanian | fb166b7 | 2019-06-24 12:38:55 -0600 | [diff] [blame] | 356 | #define MX25U12835E_TB (1 << 3) |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 357 | static struct wp_range_descriptor mx25u12835e_tb0_ranges[] = { |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 358 | { .m = { .sec = X, .tb = X }, 0, {0, 0} }, /* none */ |
| 359 | { .m = { .sec = 0, .tb = 0 }, 0x1, {0xff0000, 1 * 64 * 1024} }, /* block 255 */ |
| 360 | { .m = { .sec = 0, .tb = 0 }, 0x2, {0xfe0000, 2 * 64 * 1024} }, /* blocks 254-255 */ |
| 361 | { .m = { .sec = 0, .tb = 0 }, 0x3, {0xfc0000, 4 * 64 * 1024} }, /* blocks 252-255 */ |
| 362 | { .m = { .sec = 0, .tb = 0 }, 0x4, {0xf80000, 8 * 64 * 1024} }, /* blocks 248-255 */ |
| 363 | { .m = { .sec = 0, .tb = 0 }, 0x5, {0xf00000, 16 * 64 * 1024} }, /* blocks 240-255 */ |
| 364 | { .m = { .sec = 0, .tb = 0 }, 0x6, {0xe00000, 32 * 64 * 1024} }, /* blocks 224-255 */ |
| 365 | { .m = { .sec = 0, .tb = 0 }, 0x7, {0xc00000, 64 * 64 * 1024} }, /* blocks 192-255 */ |
| 366 | { .m = { .sec = 0, .tb = 0 }, 0x8, {0x800000, 128 * 64 * 1024} }, /* blocks 128-255 */ |
| 367 | { .m = { .sec = 0, .tb = 0 }, 0x9, {0x000000, 256 * 64 * 1024} }, /* blocks all */ |
| 368 | { .m = { .sec = 0, .tb = 0 }, 0xa, {0x000000, 256 * 64 * 1024} }, /* blocks all */ |
| 369 | { .m = { .sec = 0, .tb = 0 }, 0xb, {0x000000, 256 * 64 * 1024} }, /* blocks all */ |
| 370 | { .m = { .sec = 0, .tb = 0 }, 0xc, {0x000000, 256 * 64 * 1024} }, /* blocks all */ |
| 371 | { .m = { .sec = 0, .tb = 0 }, 0xd, {0x000000, 256 * 64 * 1024} }, /* blocks all */ |
| 372 | { .m = { .sec = 0, .tb = 0 }, 0xe, {0x000000, 256 * 64 * 1024} }, /* blocks all */ |
| 373 | { .m = { .sec = 0, .tb = 0 }, 0xf, {0x000000, 256 * 64 * 1024} }, /* blocks all */ |
Karthikeyan Ramasubramanian | fb166b7 | 2019-06-24 12:38:55 -0600 | [diff] [blame] | 374 | }; |
Alex Lu | 831c609 | 2017-11-02 23:19:34 -0700 | [diff] [blame] | 375 | |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 376 | static struct wp_range_descriptor mx25u12835e_tb1_ranges[] = { |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 377 | { .m = { .sec = 0, .tb = 1 }, 0x1, {0x000000, 1 * 64 * 1024} }, /* block 0 */ |
| 378 | { .m = { .sec = 0, .tb = 1 }, 0x2, {0x000000, 2 * 64 * 1024} }, /* blocks 0-1 */ |
| 379 | { .m = { .sec = 0, .tb = 1 }, 0x3, {0x000000, 4 * 64 * 1024} }, /* blocks 0-3 */ |
| 380 | { .m = { .sec = 0, .tb = 1 }, 0x4, {0x000000, 8 * 64 * 1024} }, /* blocks 0-7 */ |
| 381 | { .m = { .sec = 0, .tb = 1 }, 0x5, {0x000000, 16 * 64 * 1024} }, /* blocks 0-15 */ |
| 382 | { .m = { .sec = 0, .tb = 1 }, 0x6, {0x000000, 32 * 64 * 1024} }, /* blocks 0-31 */ |
| 383 | { .m = { .sec = 0, .tb = 1 }, 0x7, {0x000000, 64 * 64 * 1024} }, /* blocks 0-63 */ |
| 384 | { .m = { .sec = 0, .tb = 1 }, 0x8, {0x000000, 128 * 64 * 1024} }, /* blocks 0-127 */ |
| 385 | { .m = { .sec = 0, .tb = 1 }, 0x9, {0x000000, 256 * 64 * 1024} }, /* blocks all */ |
| 386 | { .m = { .sec = 0, .tb = 1 }, 0xa, {0x000000, 256 * 64 * 1024} }, /* blocks all */ |
| 387 | { .m = { .sec = 0, .tb = 1 }, 0xb, {0x000000, 256 * 64 * 1024} }, /* blocks all */ |
| 388 | { .m = { .sec = 0, .tb = 1 }, 0xc, {0x000000, 256 * 64 * 1024} }, /* blocks all */ |
| 389 | { .m = { .sec = 0, .tb = 1 }, 0xd, {0x000000, 256 * 64 * 1024} }, /* blocks all */ |
| 390 | { .m = { .sec = 0, .tb = 1 }, 0xe, {0x000000, 256 * 64 * 1024} }, /* blocks all */ |
| 391 | { .m = { .sec = 0, .tb = 1 }, 0xf, {0x000000, 256 * 64 * 1024} }, /* blocks all */ |
Alex Lu | 831c609 | 2017-11-02 23:19:34 -0700 | [diff] [blame] | 392 | }; |
| 393 | |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 394 | static struct wp_range_descriptor n25q064_ranges[] = { |
David Hendricks | fe9123b | 2015-04-21 13:18:31 -0700 | [diff] [blame] | 395 | /* |
| 396 | * Note: For N25Q064, sec (usually in bit position 6) is called BP3 |
| 397 | * (block protect bit 3). It is only useful when all blocks are to |
| 398 | * be write-protected. |
| 399 | */ |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 400 | { .m = { .sec = 0, .tb = 0 }, 0, {0, 0} }, /* none */ |
David Hendricks | bfa624b | 2012-07-24 12:47:59 -0700 | [diff] [blame] | 401 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 402 | { .m = { .sec = 0, .tb = 0 }, 0x1, {0x7f0000, 64 * 1024} }, /* block 127 */ |
| 403 | { .m = { .sec = 0, .tb = 0 }, 0x2, {0x7e0000, 2 * 64 * 1024} }, /* blocks 126-127 */ |
| 404 | { .m = { .sec = 0, .tb = 0 }, 0x3, {0x7c0000, 4 * 64 * 1024} }, /* blocks 124-127 */ |
| 405 | { .m = { .sec = 0, .tb = 0 }, 0x4, {0x780000, 8 * 64 * 1024} }, /* blocks 120-127 */ |
| 406 | { .m = { .sec = 0, .tb = 0 }, 0x5, {0x700000, 16 * 64 * 1024} }, /* blocks 112-127 */ |
| 407 | { .m = { .sec = 0, .tb = 0 }, 0x6, {0x600000, 32 * 64 * 1024} }, /* blocks 96-127 */ |
| 408 | { .m = { .sec = 0, .tb = 0 }, 0x7, {0x400000, 64 * 64 * 1024} }, /* blocks 64-127 */ |
David Hendricks | bfa624b | 2012-07-24 12:47:59 -0700 | [diff] [blame] | 409 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 410 | { .m = { .sec = 0, .tb = 1 }, 0x1, {0x000000, 64 * 1024} }, /* block 0 */ |
| 411 | { .m = { .sec = 0, .tb = 1 }, 0x2, {0x000000, 2 * 64 * 1024} }, /* blocks 0-1 */ |
| 412 | { .m = { .sec = 0, .tb = 1 }, 0x3, {0x000000, 4 * 64 * 1024} }, /* blocks 0-3 */ |
| 413 | { .m = { .sec = 0, .tb = 1 }, 0x4, {0x000000, 8 * 64 * 1024} }, /* blocks 0-7 */ |
| 414 | { .m = { .sec = 0, .tb = 1 }, 0x5, {0x000000, 16 * 64 * 1024} }, /* blocks 0-15 */ |
| 415 | { .m = { .sec = 0, .tb = 1 }, 0x6, {0x000000, 32 * 64 * 1024} }, /* blocks 0-31 */ |
| 416 | { .m = { .sec = 0, .tb = 1 }, 0x7, {0x000000, 64 * 64 * 1024} }, /* blocks 0-63 */ |
David Hendricks | bfa624b | 2012-07-24 12:47:59 -0700 | [diff] [blame] | 417 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 418 | { .m = { .sec = X, .tb = 1 }, 0x0, {0x000000, 128 * 64 * 1024} }, /* all */ |
| 419 | { .m = { .sec = X, .tb = 1 }, 0x1, {0x000000, 128 * 64 * 1024} }, /* all */ |
| 420 | { .m = { .sec = X, .tb = 1 }, 0x2, {0x000000, 128 * 64 * 1024} }, /* all */ |
| 421 | { .m = { .sec = X, .tb = 1 }, 0x3, {0x000000, 128 * 64 * 1024} }, /* all */ |
| 422 | { .m = { .sec = X, .tb = 1 }, 0x4, {0x000000, 128 * 64 * 1024} }, /* all */ |
| 423 | { .m = { .sec = X, .tb = 1 }, 0x5, {0x000000, 128 * 64 * 1024} }, /* all */ |
| 424 | { .m = { .sec = X, .tb = 1 }, 0x6, {0x000000, 128 * 64 * 1024} }, /* all */ |
| 425 | { .m = { .sec = X, .tb = 1 }, 0x7, {0x000000, 128 * 64 * 1024} }, /* all */ |
David Hendricks | bfa624b | 2012-07-24 12:47:59 -0700 | [diff] [blame] | 426 | }; |
| 427 | |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 428 | static struct wp_range_descriptor w25q16_ranges[] = { |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 429 | { .m = { .sec = X, .tb = X }, 0, {0, 0} }, /* none */ |
| 430 | { .m = { .sec = 0, .tb = 0 }, 0x1, {0x1f0000, 64 * 1024} }, |
| 431 | { .m = { .sec = 0, .tb = 0 }, 0x2, {0x1e0000, 128 * 1024} }, |
| 432 | { .m = { .sec = 0, .tb = 0 }, 0x3, {0x1c0000, 256 * 1024} }, |
| 433 | { .m = { .sec = 0, .tb = 0 }, 0x4, {0x180000, 512 * 1024} }, |
| 434 | { .m = { .sec = 0, .tb = 0 }, 0x5, {0x100000, 1024 * 1024} }, |
David Hendricks | f7924d1 | 2010-06-10 21:26:44 -0700 | [diff] [blame] | 435 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 436 | { .m = { .sec = 0, .tb = 1 }, 0x1, {0x000000, 64 * 1024} }, |
| 437 | { .m = { .sec = 0, .tb = 1 }, 0x2, {0x000000, 128 * 1024} }, |
| 438 | { .m = { .sec = 0, .tb = 1 }, 0x3, {0x000000, 256 * 1024} }, |
| 439 | { .m = { .sec = 0, .tb = 1 }, 0x4, {0x000000, 512 * 1024} }, |
| 440 | { .m = { .sec = 0, .tb = 1 }, 0x5, {0x000000, 1024 * 1024} }, |
| 441 | { .m = { .sec = X, .tb = X }, 0x6, {0x000000, 2048 * 1024} }, |
| 442 | { .m = { .sec = X, .tb = X }, 0x7, {0x000000, 2048 * 1024} }, |
David Hendricks | f7924d1 | 2010-06-10 21:26:44 -0700 | [diff] [blame] | 443 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 444 | { .m = { .sec = 1, .tb = 0 }, 0x1, {0x1ff000, 4 * 1024} }, |
| 445 | { .m = { .sec = 1, .tb = 0 }, 0x2, {0x1fe000, 8 * 1024} }, |
| 446 | { .m = { .sec = 1, .tb = 0 }, 0x3, {0x1fc000, 16 * 1024} }, |
| 447 | { .m = { .sec = 1, .tb = 0 }, 0x4, {0x1f8000, 32 * 1024} }, |
| 448 | { .m = { .sec = 1, .tb = 0 }, 0x5, {0x1f8000, 32 * 1024} }, |
David Hendricks | f7924d1 | 2010-06-10 21:26:44 -0700 | [diff] [blame] | 449 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 450 | { .m = { .sec = 1, .tb = 1 }, 0x1, {0x000000, 4 * 1024} }, |
| 451 | { .m = { .sec = 1, .tb = 1 }, 0x2, {0x000000, 8 * 1024} }, |
| 452 | { .m = { .sec = 1, .tb = 1 }, 0x3, {0x000000, 16 * 1024} }, |
| 453 | { .m = { .sec = 1, .tb = 1 }, 0x4, {0x000000, 32 * 1024} }, |
| 454 | { .m = { .sec = 1, .tb = 1 }, 0x5, {0x000000, 32 * 1024} }, |
David Hendricks | f7924d1 | 2010-06-10 21:26:44 -0700 | [diff] [blame] | 455 | }; |
| 456 | |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 457 | static struct wp_range_descriptor w25q32_ranges[] = { |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 458 | { .m = { .sec = X, .tb = X }, 0, {0, 0} }, /* none */ |
| 459 | { .m = { .sec = 0, .tb = 0 }, 0x1, {0x3f0000, 64 * 1024} }, |
| 460 | { .m = { .sec = 0, .tb = 0 }, 0x2, {0x3e0000, 128 * 1024} }, |
| 461 | { .m = { .sec = 0, .tb = 0 }, 0x3, {0x3c0000, 256 * 1024} }, |
| 462 | { .m = { .sec = 0, .tb = 0 }, 0x4, {0x380000, 512 * 1024} }, |
| 463 | { .m = { .sec = 0, .tb = 0 }, 0x5, {0x300000, 1024 * 1024} }, |
| 464 | { .m = { .sec = 0, .tb = 0 }, 0x6, {0x200000, 2048 * 1024} }, |
David Hendricks | f7924d1 | 2010-06-10 21:26:44 -0700 | [diff] [blame] | 465 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 466 | { .m = { .sec = 0, .tb = 1 }, 0x1, {0x000000, 64 * 1024} }, |
| 467 | { .m = { .sec = 0, .tb = 1 }, 0x2, {0x000000, 128 * 1024} }, |
| 468 | { .m = { .sec = 0, .tb = 1 }, 0x3, {0x000000, 256 * 1024} }, |
| 469 | { .m = { .sec = 0, .tb = 1 }, 0x4, {0x000000, 512 * 1024} }, |
| 470 | { .m = { .sec = 0, .tb = 1 }, 0x5, {0x000000, 1024 * 1024} }, |
| 471 | { .m = { .sec = 0, .tb = 1 }, 0x6, {0x000000, 2048 * 1024} }, |
| 472 | { .m = { .sec = X, .tb = X }, 0x7, {0x000000, 4096 * 1024} }, |
David Hendricks | f7924d1 | 2010-06-10 21:26:44 -0700 | [diff] [blame] | 473 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 474 | { .m = { .sec = 1, .tb = 0 }, 0x1, {0x3ff000, 4 * 1024} }, |
| 475 | { .m = { .sec = 1, .tb = 0 }, 0x2, {0x3fe000, 8 * 1024} }, |
| 476 | { .m = { .sec = 1, .tb = 0 }, 0x3, {0x3fc000, 16 * 1024} }, |
| 477 | { .m = { .sec = 1, .tb = 0 }, 0x4, {0x3f8000, 32 * 1024} }, |
| 478 | { .m = { .sec = 1, .tb = 0 }, 0x5, {0x3f8000, 32 * 1024} }, |
David Hendricks | f7924d1 | 2010-06-10 21:26:44 -0700 | [diff] [blame] | 479 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 480 | { .m = { .sec = 1, .tb = 1 }, 0x1, {0x000000, 4 * 1024} }, |
| 481 | { .m = { .sec = 1, .tb = 1 }, 0x2, {0x000000, 8 * 1024} }, |
| 482 | { .m = { .sec = 1, .tb = 1 }, 0x3, {0x000000, 16 * 1024} }, |
| 483 | { .m = { .sec = 1, .tb = 1 }, 0x4, {0x000000, 32 * 1024} }, |
| 484 | { .m = { .sec = 1, .tb = 1 }, 0x5, {0x000000, 32 * 1024} }, |
David Hendricks | f7924d1 | 2010-06-10 21:26:44 -0700 | [diff] [blame] | 485 | }; |
| 486 | |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 487 | static struct wp_range_descriptor w25q80_ranges[] = { |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 488 | { .m = { .sec = X, .tb = X }, 0, {0, 0} }, /* none */ |
| 489 | { .m = { .sec = 0, .tb = 0 }, 0x1, {0x0f0000, 64 * 1024} }, |
| 490 | { .m = { .sec = 0, .tb = 0 }, 0x2, {0x0e0000, 128 * 1024} }, |
| 491 | { .m = { .sec = 0, .tb = 0 }, 0x3, {0x0c0000, 256 * 1024} }, |
| 492 | { .m = { .sec = 0, .tb = 0 }, 0x4, {0x080000, 512 * 1024} }, |
David Hendricks | f7924d1 | 2010-06-10 21:26:44 -0700 | [diff] [blame] | 493 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 494 | { .m = { .sec = 0, .tb = 1 }, 0x1, {0x000000, 64 * 1024} }, |
| 495 | { .m = { .sec = 0, .tb = 1 }, 0x2, {0x000000, 128 * 1024} }, |
| 496 | { .m = { .sec = 0, .tb = 1 }, 0x3, {0x000000, 256 * 1024} }, |
| 497 | { .m = { .sec = 0, .tb = 1 }, 0x4, {0x000000, 512 * 1024} }, |
| 498 | { .m = { .sec = X, .tb = X }, 0x6, {0x000000, 1024 * 1024} }, |
| 499 | { .m = { .sec = X, .tb = X }, 0x7, {0x000000, 1024 * 1024} }, |
David Hendricks | f7924d1 | 2010-06-10 21:26:44 -0700 | [diff] [blame] | 500 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 501 | { .m = { .sec = 1, .tb = 0 }, 0x1, {0x1ff000, 4 * 1024} }, |
| 502 | { .m = { .sec = 1, .tb = 0 }, 0x2, {0x1fe000, 8 * 1024} }, |
| 503 | { .m = { .sec = 1, .tb = 0 }, 0x3, {0x1fc000, 16 * 1024} }, |
| 504 | { .m = { .sec = 1, .tb = 0 }, 0x4, {0x1f8000, 32 * 1024} }, |
| 505 | { .m = { .sec = 1, .tb = 0 }, 0x5, {0x1f8000, 32 * 1024} }, |
David Hendricks | f7924d1 | 2010-06-10 21:26:44 -0700 | [diff] [blame] | 506 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 507 | { .m = { .sec = 1, .tb = 1 }, 0x1, {0x000000, 4 * 1024} }, |
| 508 | { .m = { .sec = 1, .tb = 1 }, 0x2, {0x000000, 8 * 1024} }, |
| 509 | { .m = { .sec = 1, .tb = 1 }, 0x3, {0x000000, 16 * 1024} }, |
| 510 | { .m = { .sec = 1, .tb = 1 }, 0x4, {0x000000, 32 * 1024} }, |
| 511 | { .m = { .sec = 1, .tb = 1 }, 0x5, {0x000000, 32 * 1024} }, |
David Hendricks | f7924d1 | 2010-06-10 21:26:44 -0700 | [diff] [blame] | 512 | }; |
| 513 | |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 514 | static struct wp_range_descriptor w25q64_ranges[] = { |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 515 | { .m = { .sec = X, .tb = X }, 0, {0, 0} }, /* none */ |
David Hendricks | 2c4a76c | 2010-06-28 14:00:43 -0700 | [diff] [blame] | 516 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 517 | { .m = { .sec = 0, .tb = 0 }, 0x1, {0x7e0000, 128 * 1024} }, |
| 518 | { .m = { .sec = 0, .tb = 0 }, 0x2, {0x7c0000, 256 * 1024} }, |
| 519 | { .m = { .sec = 0, .tb = 0 }, 0x3, {0x780000, 512 * 1024} }, |
| 520 | { .m = { .sec = 0, .tb = 0 }, 0x4, {0x700000, 1024 * 1024} }, |
| 521 | { .m = { .sec = 0, .tb = 0 }, 0x5, {0x600000, 2048 * 1024} }, |
| 522 | { .m = { .sec = 0, .tb = 0 }, 0x6, {0x400000, 4096 * 1024} }, |
David Hendricks | 2c4a76c | 2010-06-28 14:00:43 -0700 | [diff] [blame] | 523 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 524 | { .m = { .sec = 0, .tb = 1 }, 0x1, {0x000000, 128 * 1024} }, |
| 525 | { .m = { .sec = 0, .tb = 1 }, 0x2, {0x000000, 256 * 1024} }, |
| 526 | { .m = { .sec = 0, .tb = 1 }, 0x3, {0x000000, 512 * 1024} }, |
| 527 | { .m = { .sec = 0, .tb = 1 }, 0x4, {0x000000, 1024 * 1024} }, |
| 528 | { .m = { .sec = 0, .tb = 1 }, 0x5, {0x000000, 2048 * 1024} }, |
| 529 | { .m = { .sec = 0, .tb = 1 }, 0x6, {0x000000, 4096 * 1024} }, |
| 530 | { .m = { .sec = X, .tb = X }, 0x7, {0x000000, 8192 * 1024} }, |
David Hendricks | 2c4a76c | 2010-06-28 14:00:43 -0700 | [diff] [blame] | 531 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 532 | { .m = { .sec = 1, .tb = 0 }, 0x1, {0x7ff000, 4 * 1024} }, |
| 533 | { .m = { .sec = 1, .tb = 0 }, 0x2, {0x7fe000, 8 * 1024} }, |
| 534 | { .m = { .sec = 1, .tb = 0 }, 0x3, {0x7fc000, 16 * 1024} }, |
| 535 | { .m = { .sec = 1, .tb = 0 }, 0x4, {0x7f8000, 32 * 1024} }, |
| 536 | { .m = { .sec = 1, .tb = 0 }, 0x5, {0x7f8000, 32 * 1024} }, |
David Hendricks | 2c4a76c | 2010-06-28 14:00:43 -0700 | [diff] [blame] | 537 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 538 | { .m = { .sec = 1, .tb = 1 }, 0x1, {0x000000, 4 * 1024} }, |
| 539 | { .m = { .sec = 1, .tb = 1 }, 0x2, {0x000000, 8 * 1024} }, |
| 540 | { .m = { .sec = 1, .tb = 1 }, 0x3, {0x000000, 16 * 1024} }, |
| 541 | { .m = { .sec = 1, .tb = 1 }, 0x4, {0x000000, 32 * 1024} }, |
| 542 | { .m = { .sec = 1, .tb = 1 }, 0x5, {0x000000, 32 * 1024} }, |
David Hendricks | 2c4a76c | 2010-06-28 14:00:43 -0700 | [diff] [blame] | 543 | }; |
| 544 | |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 545 | static struct wp_range_descriptor w25rq128_cmp0_ranges[] = { |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 546 | { .m = { .sec = X, .tb = X }, 0, {0, 0} }, /* NONE */ |
Ramya Vijaykumar | e6a7ca8 | 2015-05-12 14:27:29 +0530 | [diff] [blame] | 547 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 548 | { .m = { .sec = 0, .tb = 0 }, 0x1, {0xfc0000, 256 * 1024} }, /* Upper 1/64 */ |
| 549 | { .m = { .sec = 0, .tb = 0 }, 0x2, {0xf80000, 512 * 1024} }, /* Upper 1/32 */ |
| 550 | { .m = { .sec = 0, .tb = 0 }, 0x3, {0xf00000, 1024 * 1024} }, /* Upper 1/16 */ |
| 551 | { .m = { .sec = 0, .tb = 0 }, 0x4, {0xe00000, 2048 * 1024} }, /* Upper 1/8 */ |
| 552 | { .m = { .sec = 0, .tb = 0 }, 0x5, {0xc00000, 4096 * 1024} }, /* Upper 1/4 */ |
| 553 | { .m = { .sec = 0, .tb = 0 }, 0x6, {0x800000, 8192 * 1024} }, /* Upper 1/2 */ |
Ramya Vijaykumar | e6a7ca8 | 2015-05-12 14:27:29 +0530 | [diff] [blame] | 554 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 555 | { .m = { .sec = 0, .tb = 1 }, 0x1, {0x000000, 256 * 1024} }, /* Lower 1/64 */ |
| 556 | { .m = { .sec = 0, .tb = 1 }, 0x2, {0x000000, 512 * 1024} }, /* Lower 1/32 */ |
| 557 | { .m = { .sec = 0, .tb = 1 }, 0x3, {0x000000, 1024 * 1024} }, /* Lower 1/16 */ |
| 558 | { .m = { .sec = 0, .tb = 1 }, 0x4, {0x000000, 2048 * 1024} }, /* Lower 1/8 */ |
| 559 | { .m = { .sec = 0, .tb = 1 }, 0x5, {0x000000, 4096 * 1024} }, /* Lower 1/4 */ |
| 560 | { .m = { .sec = 0, .tb = 1 }, 0x6, {0x000000, 8192 * 1024} }, /* Lower 1/2 */ |
Ramya Vijaykumar | e6a7ca8 | 2015-05-12 14:27:29 +0530 | [diff] [blame] | 561 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 562 | { .m = { .sec = X, .tb = X }, 0x7, {0x000000, 16384 * 1024} }, /* ALL */ |
Ramya Vijaykumar | e6a7ca8 | 2015-05-12 14:27:29 +0530 | [diff] [blame] | 563 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 564 | { .m = { .sec = 1, .tb = 0 }, 0x1, {0xfff000, 4 * 1024} }, /* Upper 1/4096 */ |
| 565 | { .m = { .sec = 1, .tb = 0 }, 0x2, {0xffe000, 8 * 1024} }, /* Upper 1/2048 */ |
| 566 | { .m = { .sec = 1, .tb = 0 }, 0x3, {0xffc000, 16 * 1024} }, /* Upper 1/1024 */ |
| 567 | { .m = { .sec = 1, .tb = 0 }, 0x4, {0xff8000, 32 * 1024} }, /* Upper 1/512 */ |
| 568 | { .m = { .sec = 1, .tb = 0 }, 0x5, {0xff8000, 32 * 1024} }, /* Upper 1/512 */ |
Duncan Laurie | ed32d7b | 2015-05-27 11:28:18 -0700 | [diff] [blame] | 569 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 570 | { .m = { .sec = 1, .tb = 1 }, 0x1, {0x000000, 4 * 1024} }, /* Lower 1/4096 */ |
| 571 | { .m = { .sec = 1, .tb = 1 }, 0x2, {0x000000, 8 * 1024} }, /* Lower 1/2048 */ |
| 572 | { .m = { .sec = 1, .tb = 1 }, 0x3, {0x000000, 16 * 1024} }, /* Lower 1/1024 */ |
| 573 | { .m = { .sec = 1, .tb = 1 }, 0x4, {0x000000, 32 * 1024} }, /* Lower 1/512 */ |
| 574 | { .m = { .sec = 1, .tb = 1 }, 0x5, {0x000000, 32 * 1024} }, /* Lower 1/512 */ |
Duncan Laurie | ed32d7b | 2015-05-27 11:28:18 -0700 | [diff] [blame] | 575 | }; |
| 576 | |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 577 | static struct wp_range_descriptor w25rq128_cmp1_ranges[] = { |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 578 | { .m = { .sec = X, .tb = X }, 0x0, {0x000000, 16 * 1024 * 1024} }, /* ALL */ |
Duncan Laurie | ed32d7b | 2015-05-27 11:28:18 -0700 | [diff] [blame] | 579 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 580 | { .m = { .sec = 0, .tb = 0 }, 0x1, {0x000000, 16128 * 1024} }, /* Lower 63/64 */ |
| 581 | { .m = { .sec = 0, .tb = 0 }, 0x2, {0x000000, 15872 * 1024} }, /* Lower 31/32 */ |
| 582 | { .m = { .sec = 0, .tb = 0 }, 0x3, {0x000000, 15 * 1024 * 1024} }, /* Lower 15/16 */ |
| 583 | { .m = { .sec = 0, .tb = 0 }, 0x4, {0x000000, 14 * 1024 * 1024} }, /* Lower 7/8 */ |
| 584 | { .m = { .sec = 0, .tb = 0 }, 0x5, {0x000000, 12 * 1024 * 1024} }, /* Lower 3/4 */ |
| 585 | { .m = { .sec = 0, .tb = 0 }, 0x6, {0x000000, 8 * 1024 * 1024} }, /* Lower 1/2 */ |
Duncan Laurie | ed32d7b | 2015-05-27 11:28:18 -0700 | [diff] [blame] | 586 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 587 | { .m = { .sec = 0, .tb = 1 }, 0x1, {0x040000, 16128 * 1024} }, /* Upper 63/64 */ |
| 588 | { .m = { .sec = 0, .tb = 1 }, 0x2, {0x080000, 15872 * 1024} }, /* Upper 31/32 */ |
| 589 | { .m = { .sec = 0, .tb = 1 }, 0x3, {0x100000, 15 * 1024 * 1024} }, /* Upper 15/16 */ |
| 590 | { .m = { .sec = 0, .tb = 1 }, 0x4, {0x200000, 14 * 1024 * 1024} }, /* Upper 7/8 */ |
| 591 | { .m = { .sec = 0, .tb = 1 }, 0x5, {0x400000, 12 * 1024 * 1024} }, /* Upper 3/4 */ |
| 592 | { .m = { .sec = 0, .tb = 1 }, 0x6, {0x800000, 8 * 1024 * 1024} }, /* Upper 1/2 */ |
Duncan Laurie | ed32d7b | 2015-05-27 11:28:18 -0700 | [diff] [blame] | 593 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 594 | { .m = { .sec = X, .tb = X }, 0x7, {0x000000, 0} }, /* NONE */ |
Duncan Laurie | ed32d7b | 2015-05-27 11:28:18 -0700 | [diff] [blame] | 595 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 596 | { .m = { .sec = 1, .tb = 0 }, 0x1, {0x000000, 16380 * 1024} }, /* Lower 4095/4096 */ |
| 597 | { .m = { .sec = 1, .tb = 0 }, 0x2, {0x000000, 16376 * 1024} }, /* Lower 2048/2048 */ |
| 598 | { .m = { .sec = 1, .tb = 0 }, 0x3, {0x000000, 16368 * 1024} }, /* Lower 1023/1024 */ |
| 599 | { .m = { .sec = 1, .tb = 0 }, 0x4, {0x000000, 16352 * 1024} }, /* Lower 511/512 */ |
| 600 | { .m = { .sec = 1, .tb = 0 }, 0x5, {0x000000, 16352 * 1024} }, /* Lower 511/512 */ |
Duncan Laurie | ed32d7b | 2015-05-27 11:28:18 -0700 | [diff] [blame] | 601 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 602 | { .m = { .sec = 1, .tb = 1 }, 0x1, {0x001000, 16380 * 1024} }, /* Upper 4095/4096 */ |
| 603 | { .m = { .sec = 1, .tb = 1 }, 0x2, {0x002000, 16376 * 1024} }, /* Upper 2047/2048 */ |
| 604 | { .m = { .sec = 1, .tb = 1 }, 0x3, {0x004000, 16368 * 1024} }, /* Upper 1023/1024 */ |
| 605 | { .m = { .sec = 1, .tb = 1 }, 0x4, {0x008000, 16352 * 1024} }, /* Upper 511/512 */ |
| 606 | { .m = { .sec = 1, .tb = 1 }, 0x5, {0x008000, 16352 * 1024} }, /* Upper 511/512 */ |
Ramya Vijaykumar | e6a7ca8 | 2015-05-12 14:27:29 +0530 | [diff] [blame] | 607 | }; |
| 608 | |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 609 | static struct wp_range_descriptor w25rq256_cmp0_ranges[] = { |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 610 | { .m = { .sec = X, .tb = X }, 0x0, {0x0000000, 0x0000000} }, /* NONE */ |
Duncan Laurie | 1801f7c | 2019-01-09 18:02:51 -0800 | [diff] [blame] | 611 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 612 | { .m = { .sec = X, .tb = 0 }, 0x1, {0x1ff0000, 64 * 1 * 1024} }, /* Upper 1/512 */ |
| 613 | { .m = { .sec = X, .tb = 0 }, 0x2, {0x1fe0000, 64 * 2 * 1024} }, /* Upper 1/256 */ |
| 614 | { .m = { .sec = X, .tb = 0 }, 0x3, {0x1fc0000, 64 * 4 * 1024} }, /* Upper 1/128 */ |
| 615 | { .m = { .sec = X, .tb = 0 }, 0x4, {0x1f80000, 64 * 8 * 1024} }, /* Upper 1/64 */ |
| 616 | { .m = { .sec = X, .tb = 0 }, 0x5, {0x1f00000, 64 * 16 * 1024} }, /* Upper 1/32 */ |
| 617 | { .m = { .sec = X, .tb = 0 }, 0x6, {0x1e00000, 64 * 32 * 1024} }, /* Upper 1/16 */ |
| 618 | { .m = { .sec = X, .tb = 0 }, 0x7, {0x1c00000, 64 * 64 * 1024} }, /* Upper 1/8 */ |
| 619 | { .m = { .sec = X, .tb = 0 }, 0x8, {0x1800000, 64 * 128 * 1024} }, /* Upper 1/4 */ |
| 620 | { .m = { .sec = X, .tb = 0 }, 0x9, {0x1000000, 64 * 256 * 1024} }, /* Upper 1/2 */ |
Duncan Laurie | 1801f7c | 2019-01-09 18:02:51 -0800 | [diff] [blame] | 621 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 622 | { .m = { .sec = X, .tb = 1 }, 0x1, {0x0000000, 64 * 1 * 1024} }, /* Lower 1/512 */ |
| 623 | { .m = { .sec = X, .tb = 1 }, 0x2, {0x0000000, 64 * 2 * 1024} }, /* Lower 1/256 */ |
| 624 | { .m = { .sec = X, .tb = 1 }, 0x3, {0x0000000, 64 * 4 * 1024} }, /* Lower 1/128 */ |
| 625 | { .m = { .sec = X, .tb = 1 }, 0x4, {0x0000000, 64 * 8 * 1024} }, /* Lower 1/64 */ |
| 626 | { .m = { .sec = X, .tb = 1 }, 0x5, {0x0000000, 64 * 16 * 1024} }, /* Lower 1/32 */ |
| 627 | { .m = { .sec = X, .tb = 1 }, 0x6, {0x0000000, 64 * 32 * 1024} }, /* Lower 1/16 */ |
| 628 | { .m = { .sec = X, .tb = 1 }, 0x7, {0x0000000, 64 * 64 * 1024} }, /* Lower 1/8 */ |
| 629 | { .m = { .sec = X, .tb = 1 }, 0x8, {0x0000000, 64 * 128 * 1024} }, /* Lower 1/4 */ |
| 630 | { .m = { .sec = X, .tb = 1 }, 0x9, {0x0000000, 64 * 256 * 1024} }, /* Lower 1/2 */ |
Duncan Laurie | 1801f7c | 2019-01-09 18:02:51 -0800 | [diff] [blame] | 631 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 632 | { .m = { .sec = X, .tb = X }, 0xa, {0x0000000, 64 * 512 * 1024} }, /* ALL */ |
| 633 | { .m = { .sec = X, .tb = X }, 0xb, {0x0000000, 64 * 512 * 1024} }, /* ALL */ |
| 634 | { .m = { .sec = X, .tb = X }, 0xc, {0x0000000, 64 * 512 * 1024} }, /* ALL */ |
| 635 | { .m = { .sec = X, .tb = X }, 0xd, {0x0000000, 64 * 512 * 1024} }, /* ALL */ |
| 636 | { .m = { .sec = X, .tb = X }, 0xe, {0x0000000, 64 * 512 * 1024} }, /* ALL */ |
| 637 | { .m = { .sec = X, .tb = X }, 0xf, {0x0000000, 64 * 512 * 1024} }, /* ALL */ |
Duncan Laurie | 1801f7c | 2019-01-09 18:02:51 -0800 | [diff] [blame] | 638 | }; |
| 639 | |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 640 | static struct wp_range_descriptor w25rq256_cmp1_ranges[] = { |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 641 | { .m = { .sec = X, .tb = X }, 0x0, {0x0000000, 64 * 512 * 1024} }, /* ALL */ |
Duncan Laurie | 1801f7c | 2019-01-09 18:02:51 -0800 | [diff] [blame] | 642 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 643 | { .m = { .sec = X, .tb = 0 }, 0x1, {0x0000000, 64 * 511 * 1024} }, /* Lower 511/512 */ |
| 644 | { .m = { .sec = X, .tb = 0 }, 0x2, {0x0000000, 64 * 510 * 1024} }, /* Lower 255/256 */ |
| 645 | { .m = { .sec = X, .tb = 0 }, 0x3, {0x0000000, 64 * 508 * 1024} }, /* Lower 127/128 */ |
| 646 | { .m = { .sec = X, .tb = 0 }, 0x4, {0x0000000, 64 * 504 * 1024} }, /* Lower 63/64 */ |
| 647 | { .m = { .sec = X, .tb = 0 }, 0x5, {0x0000000, 64 * 496 * 1024} }, /* Lower 31/32 */ |
| 648 | { .m = { .sec = X, .tb = 0 }, 0x6, {0x0000000, 64 * 480 * 1024} }, /* Lower 15/16 */ |
| 649 | { .m = { .sec = X, .tb = 0 }, 0x7, {0x0000000, 64 * 448 * 1024} }, /* Lower 7/8 */ |
| 650 | { .m = { .sec = X, .tb = 0 }, 0x8, {0x0000000, 64 * 384 * 1024} }, /* Lower 3/4 */ |
| 651 | { .m = { .sec = X, .tb = 0 }, 0x9, {0x0000000, 64 * 256 * 1024} }, /* Lower 1/2 */ |
Duncan Laurie | 1801f7c | 2019-01-09 18:02:51 -0800 | [diff] [blame] | 652 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 653 | { .m = { .sec = X, .tb = 1 }, 0x1, {0x0010000, 64 * 511 * 1024} }, /* Upper 511/512 */ |
| 654 | { .m = { .sec = X, .tb = 1 }, 0x2, {0x0020000, 64 * 510 * 1024} }, /* Upper 255/256 */ |
| 655 | { .m = { .sec = X, .tb = 1 }, 0x3, {0x0040000, 64 * 508 * 1024} }, /* Upper 127/128 */ |
| 656 | { .m = { .sec = X, .tb = 1 }, 0x4, {0x0080000, 64 * 504 * 1024} }, /* Upper 63/64 */ |
| 657 | { .m = { .sec = X, .tb = 1 }, 0x5, {0x0100000, 64 * 496 * 1024} }, /* Upper 31/32 */ |
| 658 | { .m = { .sec = X, .tb = 1 }, 0x6, {0x0200000, 64 * 480 * 1024} }, /* Upper 15/16 */ |
| 659 | { .m = { .sec = X, .tb = 1 }, 0x7, {0x0400000, 64 * 448 * 1024} }, /* Upper 7/8 */ |
| 660 | { .m = { .sec = X, .tb = 1 }, 0x8, {0x0800000, 64 * 384 * 1024} }, /* Upper 3/4 */ |
| 661 | { .m = { .sec = X, .tb = 1 }, 0x9, {0x1000000, 64 * 256 * 1024} }, /* Upper 1/2 */ |
Duncan Laurie | 1801f7c | 2019-01-09 18:02:51 -0800 | [diff] [blame] | 662 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 663 | { .m = { .sec = X, .tb = X }, 0xa, {0x0000000, 0x0000000} }, /* NONE */ |
| 664 | { .m = { .sec = X, .tb = X }, 0xb, {0x0000000, 0x0000000} }, /* NONE */ |
| 665 | { .m = { .sec = X, .tb = X }, 0xc, {0x0000000, 0x0000000} }, /* NONE */ |
| 666 | { .m = { .sec = X, .tb = X }, 0xd, {0x0000000, 0x0000000} }, /* NONE */ |
| 667 | { .m = { .sec = X, .tb = X }, 0xe, {0x0000000, 0x0000000} }, /* NONE */ |
| 668 | { .m = { .sec = X, .tb = X }, 0xf, {0x0000000, 0x0000000} }, /* NONE */ |
Duncan Laurie | 1801f7c | 2019-01-09 18:02:51 -0800 | [diff] [blame] | 669 | }; |
| 670 | |
Edward O'Callaghan | 3b99650 | 2020-04-12 20:46:51 +1000 | [diff] [blame] | 671 | static struct wp_range_descriptor w25x10_ranges[] = { |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 672 | { .m = { .sec = X, .tb = X }, 0, {0, 0} }, /* none */ |
| 673 | { .m = { .sec = 0, .tb = 0 }, 0x1, {0x010000, 64 * 1024} }, |
| 674 | { .m = { .sec = 0, .tb = 1 }, 0x1, {0x000000, 64 * 1024} }, |
| 675 | { .m = { .sec = X, .tb = X }, 0x2, {0x000000, 128 * 1024} }, |
| 676 | { .m = { .sec = X, .tb = X }, 0x3, {0x000000, 128 * 1024} }, |
Louis Yung-Chieh Lo | 232951f | 2010-09-16 11:30:00 +0800 | [diff] [blame] | 677 | }; |
| 678 | |
Edward O'Callaghan | 3b99650 | 2020-04-12 20:46:51 +1000 | [diff] [blame] | 679 | static struct wp_range_descriptor w25x20_ranges[] = { |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 680 | { .m = { .sec = X, .tb = X }, 0, {0, 0} }, /* none */ |
| 681 | { .m = { .sec = 0, .tb = 0 }, 0x1, {0x030000, 64 * 1024} }, |
| 682 | { .m = { .sec = 0, .tb = 0 }, 0x2, {0x020000, 128 * 1024} }, |
| 683 | { .m = { .sec = 0, .tb = 1 }, 0x1, {0x000000, 64 * 1024} }, |
| 684 | { .m = { .sec = 0, .tb = 1 }, 0x2, {0x000000, 128 * 1024} }, |
| 685 | { .m = { .sec = 0, .tb = X }, 0x3, {0x000000, 256 * 1024} }, |
Louis Yung-Chieh Lo | 232951f | 2010-09-16 11:30:00 +0800 | [diff] [blame] | 686 | }; |
| 687 | |
Edward O'Callaghan | 3b99650 | 2020-04-12 20:46:51 +1000 | [diff] [blame] | 688 | static struct wp_range_descriptor w25x40_ranges[] = { |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 689 | { .m = { .sec = X, .tb = X }, 0, {0, 0} }, /* none */ |
| 690 | { .m = { .sec = 0, .tb = 0 }, 0x1, {0x070000, 64 * 1024} }, |
| 691 | { .m = { .sec = 0, .tb = 0 }, 0x2, {0x060000, 128 * 1024} }, |
| 692 | { .m = { .sec = 0, .tb = 0 }, 0x3, {0x040000, 256 * 1024} }, |
| 693 | { .m = { .sec = 0, .tb = 1 }, 0x1, {0x000000, 64 * 1024} }, |
| 694 | { .m = { .sec = 0, .tb = 1 }, 0x2, {0x000000, 128 * 1024} }, |
| 695 | { .m = { .sec = 0, .tb = 1 }, 0x3, {0x000000, 256 * 1024} }, |
| 696 | { .m = { .sec = 0, .tb = X }, 0x4, {0x000000, 512 * 1024} }, |
| 697 | { .m = { .sec = 0, .tb = X }, 0x5, {0x000000, 512 * 1024} }, |
| 698 | { .m = { .sec = 0, .tb = X }, 0x6, {0x000000, 512 * 1024} }, |
| 699 | { .m = { .sec = 0, .tb = X }, 0x7, {0x000000, 512 * 1024} }, |
David Hendricks | 470ca95 | 2010-08-13 14:01:53 -0700 | [diff] [blame] | 700 | }; |
| 701 | |
Edward O'Callaghan | 3b99650 | 2020-04-12 20:46:51 +1000 | [diff] [blame] | 702 | static struct wp_range_descriptor w25x80_ranges[] = { |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 703 | { .m = { .sec = X, .tb = X }, 0, {0, 0} }, /* none */ |
| 704 | { .m = { .sec = 0, .tb = 0 }, 0x1, {0x0F0000, 64 * 1024} }, |
| 705 | { .m = { .sec = 0, .tb = 0 }, 0x2, {0x0E0000, 128 * 1024} }, |
| 706 | { .m = { .sec = 0, .tb = 0 }, 0x3, {0x0C0000, 256 * 1024} }, |
| 707 | { .m = { .sec = 0, .tb = 0 }, 0x4, {0x080000, 512 * 1024} }, |
| 708 | { .m = { .sec = 0, .tb = 1 }, 0x1, {0x000000, 64 * 1024} }, |
| 709 | { .m = { .sec = 0, .tb = 1 }, 0x2, {0x000000, 128 * 1024} }, |
| 710 | { .m = { .sec = 0, .tb = 1 }, 0x3, {0x000000, 256 * 1024} }, |
| 711 | { .m = { .sec = 0, .tb = 1 }, 0x4, {0x000000, 512 * 1024} }, |
| 712 | { .m = { .sec = 0, .tb = X }, 0x5, {0x000000, 1024 * 1024} }, |
| 713 | { .m = { .sec = 0, .tb = X }, 0x6, {0x000000, 1024 * 1024} }, |
| 714 | { .m = { .sec = 0, .tb = X }, 0x7, {0x000000, 1024 * 1024} }, |
Louis Yung-Chieh Lo | 232951f | 2010-09-16 11:30:00 +0800 | [diff] [blame] | 715 | }; |
| 716 | |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 717 | static struct wp_range_descriptor gd25q40_cmp0_ranges[] = { |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 718 | { .m = { .sec = X, .tb = X }, 0, {0, 0} }, /* None */ |
| 719 | { .m = { .sec = 0, .tb = 0 }, 0x1, {0x070000, 64 * 1024} }, |
| 720 | { .m = { .sec = 0, .tb = 0 }, 0x2, {0x060000, 128 * 1024} }, |
| 721 | { .m = { .sec = 0, .tb = 0 }, 0x3, {0x040000, 256 * 1024} }, |
| 722 | { .m = { .sec = 0, .tb = 1 }, 0x1, {0x000000, 64 * 1024} }, |
| 723 | { .m = { .sec = 0, .tb = 1 }, 0x2, {0x000000, 128 * 1024} }, |
| 724 | { .m = { .sec = 0, .tb = 1 }, 0x3, {0x000000, 256 * 1024} }, |
| 725 | { .m = { .sec = 0, .tb = X }, 0x4, {0x000000, 512 * 1024} }, /* All */ |
| 726 | { .m = { .sec = 0, .tb = X }, 0x5, {0x000000, 512 * 1024} }, /* All */ |
| 727 | { .m = { .sec = 0, .tb = X }, 0x6, {0x000000, 512 * 1024} }, /* All */ |
| 728 | { .m = { .sec = 0, .tb = X }, 0x7, {0x000000, 512 * 1024} }, /* All */ |
| 729 | { .m = { .sec = 1, .tb = 0 }, 0x1, {0x07F000, 4 * 1024} }, |
| 730 | { .m = { .sec = 1, .tb = 0 }, 0x2, {0x07E000, 8 * 1024} }, |
| 731 | { .m = { .sec = 1, .tb = 0 }, 0x3, {0x07C000, 16 * 1024} }, |
| 732 | { .m = { .sec = 1, .tb = 0 }, 0x4, {0x078000, 32 * 1024} }, |
| 733 | { .m = { .sec = 1, .tb = 0 }, 0x5, {0x078000, 32 * 1024} }, |
| 734 | { .m = { .sec = 1, .tb = 0 }, 0x6, {0x078000, 32 * 1024} }, |
| 735 | { .m = { .sec = 1, .tb = 1 }, 0x1, {0x000000, 4 * 1024} }, |
| 736 | { .m = { .sec = 1, .tb = 1 }, 0x2, {0x000000, 8 * 1024} }, |
| 737 | { .m = { .sec = 1, .tb = 1 }, 0x3, {0x000000, 16 * 1024} }, |
| 738 | { .m = { .sec = 1, .tb = 1 }, 0x4, {0x000000, 32 * 1024} }, |
| 739 | { .m = { .sec = 1, .tb = 1 }, 0x5, {0x000000, 32 * 1024} }, |
| 740 | { .m = { .sec = 1, .tb = 1 }, 0x6, {0x000000, 32 * 1024} }, |
| 741 | { .m = { .sec = 1, .tb = X }, 0x7, {0x000000, 512 * 1024} }, /* All */ |
Martin Roth | f3c3d5f | 2017-04-28 14:56:41 -0600 | [diff] [blame] | 742 | }; |
| 743 | |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 744 | static struct wp_range_descriptor gd25q40_cmp1_ranges[] = { |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 745 | { .m = { .sec = X, .tb = X }, 0x0, {0x000000, 512 * 1024} }, /* ALL */ |
| 746 | { .m = { .sec = 0, .tb = 0 }, 0x1, {0x000000, 448 * 1024} }, |
| 747 | { .m = { .sec = 0, .tb = 0 }, 0x2, {0x000000, 384 * 1024} }, |
| 748 | { .m = { .sec = 0, .tb = 0 }, 0x3, {0x000000, 256 * 1024} }, |
Martin Roth | f3c3d5f | 2017-04-28 14:56:41 -0600 | [diff] [blame] | 749 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 750 | { .m = { .sec = 0, .tb = 1 }, 0x1, {0x010000, 448 * 1024} }, |
| 751 | { .m = { .sec = 0, .tb = 1 }, 0x2, {0x020000, 384 * 1024} }, |
| 752 | { .m = { .sec = 0, .tb = 1 }, 0x3, {0x040000, 256 * 1024} }, |
Martin Roth | f3c3d5f | 2017-04-28 14:56:41 -0600 | [diff] [blame] | 753 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 754 | { .m = { .sec = 0, .tb = X }, 0x4, {0x000000, 0} }, /* None */ |
| 755 | { .m = { .sec = 0, .tb = X }, 0x5, {0x000000, 0} }, /* None */ |
| 756 | { .m = { .sec = 0, .tb = X }, 0x6, {0x000000, 0} }, /* None */ |
| 757 | { .m = { .sec = 0, .tb = X }, 0x7, {0x000000, 0} }, /* None */ |
Martin Roth | f3c3d5f | 2017-04-28 14:56:41 -0600 | [diff] [blame] | 758 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 759 | { .m = { .sec = 1, .tb = 0 }, 0x1, {0x000000, 508 * 1024} }, |
| 760 | { .m = { .sec = 1, .tb = 0 }, 0x2, {0x000000, 504 * 1024} }, |
| 761 | { .m = { .sec = 1, .tb = 0 }, 0x3, {0x000000, 496 * 1024} }, |
| 762 | { .m = { .sec = 1, .tb = 0 }, 0x4, {0x000000, 480 * 1024} }, |
| 763 | { .m = { .sec = 1, .tb = 0 }, 0x5, {0x000000, 480 * 1024} }, |
| 764 | { .m = { .sec = 1, .tb = 0 }, 0x6, {0x000000, 480 * 1024} }, |
Martin Roth | f3c3d5f | 2017-04-28 14:56:41 -0600 | [diff] [blame] | 765 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 766 | { .m = { .sec = 1, .tb = 1 }, 0x1, {0x001000, 508 * 1024} }, |
| 767 | { .m = { .sec = 1, .tb = 1 }, 0x2, {0x002000, 504 * 1024} }, |
| 768 | { .m = { .sec = 1, .tb = 1 }, 0x3, {0x004000, 496 * 1024} }, |
| 769 | { .m = { .sec = 1, .tb = 1 }, 0x4, {0x008000, 480 * 1024} }, |
| 770 | { .m = { .sec = 1, .tb = 1 }, 0x5, {0x008000, 480 * 1024} }, |
| 771 | { .m = { .sec = 1, .tb = 1 }, 0x6, {0x008000, 480 * 1024} }, |
Martin Roth | f3c3d5f | 2017-04-28 14:56:41 -0600 | [diff] [blame] | 772 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 773 | { .m = { .sec = 1, .tb = X }, 0x7, {0x000000, 0} }, /* None */ |
Martin Roth | f3c3d5f | 2017-04-28 14:56:41 -0600 | [diff] [blame] | 774 | }; |
| 775 | |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 776 | static struct wp_range_descriptor gd25q64_ranges[] = { |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 777 | { .m = { .sec = X, .tb = X }, 0, {0, 0} }, /* none */ |
| 778 | { .m = { .sec = 0, .tb = 0 }, 0x1, {0x7e0000, 128 * 1024} }, |
| 779 | { .m = { .sec = 0, .tb = 0 }, 0x2, {0x7c0000, 256 * 1024} }, |
| 780 | { .m = { .sec = 0, .tb = 0 }, 0x3, {0x780000, 512 * 1024} }, |
| 781 | { .m = { .sec = 0, .tb = 0 }, 0x4, {0x700000, 1024 * 1024} }, |
| 782 | { .m = { .sec = 0, .tb = 0 }, 0x5, {0x600000, 2048 * 1024} }, |
| 783 | { .m = { .sec = 0, .tb = 0 }, 0x6, {0x400000, 4096 * 1024} }, |
Shawn Nematbakhsh | 9e8ef49 | 2012-09-01 21:58:03 -0700 | [diff] [blame] | 784 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 785 | { .m = { .sec = 0, .tb = 1 }, 0x1, {0x000000, 128 * 1024} }, |
| 786 | { .m = { .sec = 0, .tb = 1 }, 0x2, {0x000000, 256 * 1024} }, |
| 787 | { .m = { .sec = 0, .tb = 1 }, 0x3, {0x000000, 512 * 1024} }, |
| 788 | { .m = { .sec = 0, .tb = 1 }, 0x4, {0x000000, 1024 * 1024} }, |
| 789 | { .m = { .sec = 0, .tb = 1 }, 0x5, {0x000000, 2048 * 1024} }, |
| 790 | { .m = { .sec = 0, .tb = 1 }, 0x6, {0x000000, 4096 * 1024} }, |
| 791 | { .m = { .sec = X, .tb = X }, 0x7, {0x000000, 8192 * 1024} }, |
Shawn Nematbakhsh | 9e8ef49 | 2012-09-01 21:58:03 -0700 | [diff] [blame] | 792 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 793 | { .m = { .sec = 1, .tb = 0 }, 0x1, {0x7ff000, 4 * 1024} }, |
| 794 | { .m = { .sec = 1, .tb = 0 }, 0x2, {0x7fe000, 8 * 1024} }, |
| 795 | { .m = { .sec = 1, .tb = 0 }, 0x3, {0x7fc000, 16 * 1024} }, |
| 796 | { .m = { .sec = 1, .tb = 0 }, 0x4, {0x7f8000, 32 * 1024} }, |
| 797 | { .m = { .sec = 1, .tb = 0 }, 0x5, {0x7f8000, 32 * 1024} }, |
| 798 | { .m = { .sec = 1, .tb = 0 }, 0x6, {0x7f8000, 32 * 1024} }, |
Shawn Nematbakhsh | 9e8ef49 | 2012-09-01 21:58:03 -0700 | [diff] [blame] | 799 | |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 800 | { .m = { .sec = 1, .tb = 1 }, 0x1, {0x000000, 4 * 1024} }, |
| 801 | { .m = { .sec = 1, .tb = 1 }, 0x2, {0x000000, 8 * 1024} }, |
| 802 | { .m = { .sec = 1, .tb = 1 }, 0x3, {0x000000, 16 * 1024} }, |
| 803 | { .m = { .sec = 1, .tb = 1 }, 0x4, {0x000000, 32 * 1024} }, |
| 804 | { .m = { .sec = 1, .tb = 1 }, 0x5, {0x000000, 32 * 1024} }, |
| 805 | { .m = { .sec = 1, .tb = 1 }, 0x6, {0x000000, 32 * 1024} }, |
Shawn Nematbakhsh | 9e8ef49 | 2012-09-01 21:58:03 -0700 | [diff] [blame] | 806 | }; |
| 807 | |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 808 | static struct wp_range_descriptor a25l040_ranges[] = { |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 809 | { .m = { .sec = X, .tb = X }, 0x0, {0, 0} }, /* none */ |
| 810 | { .m = { .sec = X, .tb = X }, 0x1, {0x70000, 64 * 1024} }, |
| 811 | { .m = { .sec = X, .tb = X }, 0x2, {0x60000, 128 * 1024} }, |
| 812 | { .m = { .sec = X, .tb = X }, 0x3, {0x40000, 256 * 1024} }, |
| 813 | { .m = { .sec = X, .tb = X }, 0x4, {0x00000, 512 * 1024} }, |
| 814 | { .m = { .sec = X, .tb = X }, 0x5, {0x00000, 512 * 1024} }, |
| 815 | { .m = { .sec = X, .tb = X }, 0x6, {0x00000, 512 * 1024} }, |
| 816 | { .m = { .sec = X, .tb = X }, 0x7, {0x00000, 512 * 1024} }, |
Louis Yung-Chieh Lo | c8ec715 | 2012-09-17 17:38:35 +0800 | [diff] [blame] | 817 | }; |
| 818 | |
Nikolai Artemiev | 423ab80 | 2021-04-06 16:55:48 +1000 | [diff] [blame] | 819 | static struct wp_range_descriptor gd25q32_cmp0_ranges[] = { |
| 820 | /* none, bp4 and bp3 => don't care */ |
| 821 | { { }, 0x00, {0, 0} }, |
| 822 | { { }, 0x08, {0, 0} }, |
| 823 | { { }, 0x10, {0, 0} }, |
| 824 | { { }, 0x18, {0, 0} }, |
| 825 | |
| 826 | { { }, 0x01, {0x3f0000, 64 * 1024} }, |
| 827 | { { }, 0x02, {0x3e0000, 128 * 1024} }, |
| 828 | { { }, 0x03, {0x3c0000, 256 * 1024} }, |
| 829 | { { }, 0x04, {0x380000, 512 * 1024} }, |
| 830 | { { }, 0x05, {0x300000, 1024 * 1024} }, |
| 831 | { { }, 0x06, {0x200000, 2048 * 1024} }, |
| 832 | |
| 833 | { { }, 0x09, {0x000000, 64 * 1024} }, |
| 834 | { { }, 0x0a, {0x000000, 128 * 1024} }, |
| 835 | { { }, 0x0b, {0x000000, 256 * 1024} }, |
| 836 | { { }, 0x0c, {0x000000, 512 * 1024} }, |
| 837 | { { }, 0x0d, {0x000000, 1024 * 1024} }, |
| 838 | { { }, 0x0e, {0x000000, 2048 * 1024} }, |
| 839 | |
| 840 | /* all, bp4 and bp3 => don't care */ |
| 841 | { { }, 0x07, {0x000000, 4096 * 1024} }, |
| 842 | { { }, 0x0f, {0x000000, 4096 * 1024} }, |
| 843 | { { }, 0x17, {0x000000, 4096 * 1024} }, |
| 844 | { { }, 0x1f, {0x000000, 4096 * 1024} }, |
| 845 | |
| 846 | { { }, 0x11, {0x3ff000, 4 * 1024} }, |
| 847 | { { }, 0x12, {0x3fe000, 8 * 1024} }, |
| 848 | { { }, 0x13, {0x3fc000, 16 * 1024} }, |
| 849 | { { }, 0x14, {0x3f8000, 32 * 1024} }, /* bp0 => don't care */ |
| 850 | { { }, 0x15, {0x3f8000, 32 * 1024} }, /* bp0 => don't care */ |
| 851 | { { }, 0x16, {0x3f8000, 32 * 1024} }, |
| 852 | |
| 853 | { { }, 0x19, {0x000000, 4 * 1024} }, |
| 854 | { { }, 0x1a, {0x000000, 8 * 1024} }, |
| 855 | { { }, 0x1b, {0x000000, 16 * 1024} }, |
| 856 | { { }, 0x1c, {0x000000, 32 * 1024} }, /* bp0 => don't care */ |
| 857 | { { }, 0x1d, {0x000000, 32 * 1024} }, /* bp0 => don't care */ |
| 858 | { { }, 0x1e, {0x000000, 32 * 1024} }, |
| 859 | }; |
| 860 | |
| 861 | static struct wp_range_descriptor gd25q32_cmp1_ranges[] = { |
| 862 | /* All, bp4 and bp3 => don't care */ |
| 863 | { { }, 0x00, {0x000000, 4096 * 1024} }, /* All */ |
| 864 | { { }, 0x08, {0x000000, 4096 * 1024} }, |
| 865 | { { }, 0x10, {0x000000, 4096 * 1024} }, |
| 866 | { { }, 0x18, {0x000000, 4096 * 1024} }, |
| 867 | |
| 868 | { { }, 0x01, {0x000000, 4032 * 1024} }, |
| 869 | { { }, 0x02, {0x000000, 3968 * 1024} }, |
| 870 | { { }, 0x03, {0x000000, 3840 * 1024} }, |
| 871 | { { }, 0x04, {0x000000, 3584 * 1024} }, |
| 872 | { { }, 0x05, {0x000000, 3 * 1024 * 1024} }, |
| 873 | { { }, 0x06, {0x000000, 2 * 1024 * 1024} }, |
| 874 | |
| 875 | { { }, 0x09, {0x010000, 4032 * 1024} }, |
| 876 | { { }, 0x0a, {0x020000, 3968 * 1024} }, |
| 877 | { { }, 0x0b, {0x040000, 3840 * 1024} }, |
| 878 | { { }, 0x0c, {0x080000, 3584 * 1024} }, |
| 879 | { { }, 0x0d, {0x100000, 3 * 1024 * 1024} }, |
| 880 | { { }, 0x0e, {0x200000, 2 * 1024 * 1024} }, |
| 881 | |
| 882 | /* None, bp4 and bp3 => don't care */ |
| 883 | { { }, 0x07, {0, 0} }, /* None */ |
| 884 | { { }, 0x0f, {0, 0} }, |
| 885 | { { }, 0x17, {0, 0} }, |
| 886 | { { }, 0x1f, {0, 0} }, |
| 887 | |
| 888 | { { }, 0x11, {0x000000, 4092 * 1024} }, |
| 889 | { { }, 0x12, {0x000000, 4088 * 1024} }, |
| 890 | { { }, 0x13, {0x000000, 4080 * 1024} }, |
| 891 | { { }, 0x14, {0x000000, 4064 * 1024} }, /* bp0 => don't care */ |
| 892 | { { }, 0x15, {0x000000, 4064 * 1024} }, /* bp0 => don't care */ |
| 893 | { { }, 0x16, {0x000000, 4064 * 1024} }, |
| 894 | |
| 895 | { { }, 0x19, {0x001000, 4092 * 1024} }, |
| 896 | { { }, 0x1a, {0x002000, 4088 * 1024} }, |
| 897 | { { }, 0x1b, {0x040000, 4080 * 1024} }, |
| 898 | { { }, 0x1c, {0x080000, 4064 * 1024} }, /* bp0 => don't care */ |
| 899 | { { }, 0x1d, {0x080000, 4064 * 1024} }, /* bp0 => don't care */ |
| 900 | { { }, 0x1e, {0x080000, 4064 * 1024} }, |
| 901 | }; |
| 902 | |
| 903 | static struct status_register_layout gd25q32_sr1 = { |
| 904 | /* TODO: map second status register */ |
| 905 | .bp0_pos = 2, .bp_bits = 5, .srp_pos = 7 |
| 906 | }; |
| 907 | |
| 908 | static struct wp_range_descriptor gd25q128_cmp0_ranges[] = { |
| 909 | /* none, bp4 and bp3 => don't care, others = 0 */ |
| 910 | { { .tb = 0 }, 0x00, {0, 0} }, |
| 911 | { { .tb = 0 }, 0x08, {0, 0} }, |
| 912 | { { .tb = 0 }, 0x10, {0, 0} }, |
| 913 | { { .tb = 0 }, 0x18, {0, 0} }, |
| 914 | |
| 915 | { { .tb = 0 }, 0x01, {0xfc0000, 256 * 1024} }, |
| 916 | { { .tb = 0 }, 0x02, {0xf80000, 512 * 1024} }, |
| 917 | { { .tb = 0 }, 0x03, {0xf00000, 1024 * 1024} }, |
| 918 | { { .tb = 0 }, 0x04, {0xe00000, 2048 * 1024} }, |
| 919 | { { .tb = 0 }, 0x05, {0xc00000, 4096 * 1024} }, |
| 920 | { { .tb = 0 }, 0x06, {0x800000, 8192 * 1024} }, |
| 921 | |
| 922 | { { .tb = 0 }, 0x09, {0x000000, 256 * 1024} }, |
| 923 | { { .tb = 0 }, 0x0a, {0x000000, 512 * 1024} }, |
| 924 | { { .tb = 0 }, 0x0b, {0x000000, 1024 * 1024} }, |
| 925 | { { .tb = 0 }, 0x0c, {0x000000, 2048 * 1024} }, |
| 926 | { { .tb = 0 }, 0x0d, {0x000000, 4096 * 1024} }, |
| 927 | { { .tb = 0 }, 0x0e, {0x000000, 8192 * 1024} }, |
| 928 | |
| 929 | /* all, bp4 and bp3 => don't care, others = 1 */ |
| 930 | { { .tb = 0 }, 0x07, {0x000000, 16384 * 1024} }, |
| 931 | { { .tb = 0 }, 0x0f, {0x000000, 16384 * 1024} }, |
| 932 | { { .tb = 0 }, 0x17, {0x000000, 16384 * 1024} }, |
| 933 | { { .tb = 0 }, 0x1f, {0x000000, 16384 * 1024} }, |
| 934 | |
| 935 | { { .tb = 0 }, 0x11, {0xfff000, 4 * 1024} }, |
| 936 | { { .tb = 0 }, 0x12, {0xffe000, 8 * 1024} }, |
| 937 | { { .tb = 0 }, 0x13, {0xffc000, 16 * 1024} }, |
| 938 | { { .tb = 0 }, 0x14, {0xff8000, 32 * 1024} }, /* bp0 => don't care */ |
| 939 | { { .tb = 0 }, 0x15, {0xff8000, 32 * 1024} }, /* bp0 => don't care */ |
| 940 | |
| 941 | { { .tb = 0 }, 0x19, {0x000000, 4 * 1024} }, |
| 942 | { { .tb = 0 }, 0x1a, {0x000000, 8 * 1024} }, |
| 943 | { { .tb = 0 }, 0x1b, {0x000000, 16 * 1024} }, |
| 944 | { { .tb = 0 }, 0x1c, {0x000000, 32 * 1024} }, /* bp0 => don't care */ |
| 945 | { { .tb = 0 }, 0x1d, {0x000000, 32 * 1024} }, /* bp0 => don't care */ |
| 946 | { { .tb = 0 }, 0x1e, {0x000000, 32 * 1024} }, |
| 947 | }; |
| 948 | |
| 949 | static struct wp_range_descriptor gd25q128_cmp1_ranges[] = { |
| 950 | /* none, bp4 and bp3 => don't care, others = 0 */ |
| 951 | { { .tb = 1 }, 0x00, {0x000000, 16384 * 1024} }, |
| 952 | { { .tb = 1 }, 0x08, {0x000000, 16384 * 1024} }, |
| 953 | { { .tb = 1 }, 0x10, {0x000000, 16384 * 1024} }, |
| 954 | { { .tb = 1 }, 0x18, {0x000000, 16384 * 1024} }, |
| 955 | |
| 956 | { { .tb = 1 }, 0x01, {0x000000, 16128 * 1024} }, |
| 957 | { { .tb = 1 }, 0x02, {0x000000, 15872 * 1024} }, |
| 958 | { { .tb = 1 }, 0x03, {0x000000, 15360 * 1024} }, |
| 959 | { { .tb = 1 }, 0x04, {0x000000, 14336 * 1024} }, |
| 960 | { { .tb = 1 }, 0x05, {0x000000, 12288 * 1024} }, |
| 961 | { { .tb = 1 }, 0x06, {0x000000, 8192 * 1024} }, |
| 962 | |
| 963 | { { .tb = 1 }, 0x09, {0x000000, 16128 * 1024} }, |
| 964 | { { .tb = 1 }, 0x0a, {0x000000, 15872 * 1024} }, |
| 965 | { { .tb = 1 }, 0x0b, {0x000000, 15360 * 1024} }, |
| 966 | { { .tb = 1 }, 0x0c, {0x000000, 14336 * 1024} }, |
| 967 | { { .tb = 1 }, 0x0d, {0x000000, 12288 * 1024} }, |
| 968 | { { .tb = 1 }, 0x0e, {0x000000, 8192 * 1024} }, |
| 969 | |
| 970 | /* none, bp4 and bp3 => don't care, others = 1 */ |
| 971 | { { .tb = 1 }, 0x07, {0x000000, 16384 * 1024} }, |
| 972 | { { .tb = 1 }, 0x08, {0x000000, 16384 * 1024} }, |
| 973 | { { .tb = 1 }, 0x0f, {0x000000, 16384 * 1024} }, |
| 974 | { { .tb = 1 }, 0x17, {0x000000, 16384 * 1024} }, |
| 975 | { { .tb = 1 }, 0x1f, {0x000000, 16384 * 1024} }, |
| 976 | |
| 977 | { { .tb = 1 }, 0x11, {0x000000, 16380 * 1024} }, |
| 978 | { { .tb = 1 }, 0x12, {0x000000, 16376 * 1024} }, |
| 979 | { { .tb = 1 }, 0x13, {0x000000, 16368 * 1024} }, |
| 980 | { { .tb = 1 }, 0x14, {0x000000, 16352 * 1024} }, /* bp0 => don't care */ |
| 981 | { { .tb = 1 }, 0x15, {0x000000, 16352 * 1024} }, /* bp0 => don't care */ |
| 982 | |
| 983 | { { .tb = 1 }, 0x19, {0x001000, 16380 * 1024} }, |
| 984 | { { .tb = 1 }, 0x1a, {0x002000, 16376 * 1024} }, |
| 985 | { { .tb = 1 }, 0x1b, {0x004000, 16368 * 1024} }, |
| 986 | { { .tb = 1 }, 0x1c, {0x008000, 16352 * 1024} }, /* bp0 => don't care */ |
| 987 | { { .tb = 1 }, 0x1d, {0x008000, 16352 * 1024} }, /* bp0 => don't care */ |
| 988 | { { .tb = 1 }, 0x1e, {0x008000, 16352 * 1024} }, |
| 989 | }; |
| 990 | |
| 991 | static struct status_register_layout gd25q128_sr1 = { |
| 992 | /* TODO: map second and third status registers */ |
| 993 | .bp0_pos = 2, .bp_bits = 5, .srp_pos = 7 |
| 994 | }; |
| 995 | |
| 996 | /* FIXME: MX25L6406 has same ID as MX25L6405D */ |
| 997 | static struct wp_range_descriptor mx25l6406e_ranges[] = { |
| 998 | { { }, 0, {0, 0} }, /* none */ |
| 999 | { { }, 0x1, {0x7e0000, 64 * 2 * 1024} }, /* blocks 126-127 */ |
| 1000 | { { }, 0x2, {0x7c0000, 64 * 4 * 1024} }, /* blocks 124-127 */ |
| 1001 | { { }, 0x3, {0x7a0000, 64 * 8 * 1024} }, /* blocks 120-127 */ |
| 1002 | { { }, 0x4, {0x700000, 64 * 16 * 1024} }, /* blocks 112-127 */ |
| 1003 | { { }, 0x5, {0x600000, 64 * 32 * 1024} }, /* blocks 96-127 */ |
| 1004 | { { }, 0x6, {0x400000, 64 * 64 * 1024} }, /* blocks 64-127 */ |
| 1005 | |
| 1006 | { { }, 0x7, {0x000000, 64 * 128 * 1024} }, /* all */ |
| 1007 | { { }, 0x8, {0x000000, 64 * 128 * 1024} }, /* all */ |
| 1008 | { { }, 0x9, {0x000000, 64 * 64 * 1024} }, /* blocks 0-63 */ |
| 1009 | { { }, 0xa, {0x000000, 64 * 96 * 1024} }, /* blocks 0-95 */ |
| 1010 | { { }, 0xb, {0x000000, 64 * 112 * 1024} }, /* blocks 0-111 */ |
| 1011 | { { }, 0xc, {0x000000, 64 * 120 * 1024} }, /* blocks 0-119 */ |
| 1012 | { { }, 0xd, {0x000000, 64 * 124 * 1024} }, /* blocks 0-123 */ |
| 1013 | { { }, 0xe, {0x000000, 64 * 126 * 1024} }, /* blocks 0-125 */ |
| 1014 | { { }, 0xf, {0x000000, 64 * 128 * 1024} }, /* all */ |
| 1015 | }; |
| 1016 | |
| 1017 | static struct status_register_layout mx25l6406e_sr1 = { |
| 1018 | .bp0_pos = 2, .bp_bits = 4, .srp_pos = 7 |
| 1019 | }; |
| 1020 | |
| 1021 | static struct wp_range_descriptor mx25l6495f_tb0_ranges[] = { |
| 1022 | { { }, 0, {0, 0} }, /* none */ |
| 1023 | { { }, 0x1, {0x7f0000, 64 * 1 * 1024} }, /* block 127 */ |
| 1024 | { { }, 0x2, {0x7e0000, 64 * 2 * 1024} }, /* blocks 126-127 */ |
| 1025 | { { }, 0x3, {0x7c0000, 64 * 4 * 1024} }, /* blocks 124-127 */ |
| 1026 | |
| 1027 | { { }, 0x4, {0x780000, 64 * 8 * 1024} }, /* blocks 120-127 */ |
| 1028 | { { }, 0x5, {0x700000, 64 * 16 * 1024} }, /* blocks 112-127 */ |
| 1029 | { { }, 0x6, {0x600000, 64 * 32 * 1024} }, /* blocks 96-127 */ |
| 1030 | { { }, 0x7, {0x400000, 64 * 64 * 1024} }, /* blocks 64-127 */ |
| 1031 | { { }, 0x8, {0x000000, 64 * 128 * 1024} }, /* all */ |
| 1032 | { { }, 0x9, {0x000000, 64 * 128 * 1024} }, /* all */ |
| 1033 | { { }, 0xa, {0x000000, 64 * 128 * 1024} }, /* all */ |
| 1034 | { { }, 0xb, {0x000000, 64 * 128 * 1024} }, /* all */ |
| 1035 | { { }, 0xc, {0x000000, 64 * 128 * 1024} }, /* all */ |
| 1036 | { { }, 0xd, {0x000000, 64 * 128 * 1024} }, /* all */ |
| 1037 | { { }, 0xe, {0x000000, 64 * 128 * 1024} }, /* all */ |
| 1038 | { { }, 0xf, {0x000000, 64 * 128 * 1024} }, /* all */ |
| 1039 | }; |
| 1040 | |
| 1041 | static struct wp_range_descriptor mx25l6495f_tb1_ranges[] = { |
| 1042 | { { }, 0, {0, 0} }, /* none */ |
| 1043 | { { }, 0x1, {0x000000, 64 * 1 * 1024} }, /* block 0 */ |
| 1044 | { { }, 0x2, {0x000000, 64 * 2 * 1024} }, /* blocks 0-1 */ |
| 1045 | { { }, 0x3, {0x000000, 64 * 4 * 1024} }, /* blocks 0-3 */ |
| 1046 | { { }, 0x4, {0x000000, 64 * 8 * 1024} }, /* blocks 0-7 */ |
| 1047 | { { }, 0x5, {0x000000, 64 * 16 * 1024} }, /* blocks 0-15 */ |
| 1048 | { { }, 0x6, {0x000000, 64 * 32 * 1024} }, /* blocks 0-31 */ |
| 1049 | { { }, 0x7, {0x000000, 64 * 64 * 1024} }, /* blocks 0-63 */ |
| 1050 | { { }, 0x8, {0x000000, 64 * 128 * 1024} }, /* all */ |
| 1051 | { { }, 0x9, {0x000000, 64 * 128 * 1024} }, /* all */ |
| 1052 | { { }, 0xa, {0x000000, 64 * 128 * 1024} }, /* all */ |
| 1053 | { { }, 0xb, {0x000000, 64 * 128 * 1024} }, /* all */ |
| 1054 | { { }, 0xc, {0x000000, 64 * 128 * 1024} }, /* all */ |
| 1055 | { { }, 0xd, {0x000000, 64 * 128 * 1024} }, /* all */ |
| 1056 | { { }, 0xe, {0x000000, 64 * 128 * 1024} }, /* all */ |
| 1057 | { { }, 0xf, {0x000000, 64 * 128 * 1024} }, /* all */ |
| 1058 | }; |
| 1059 | |
| 1060 | static struct status_register_layout mx25l6495f_sr1 = { |
| 1061 | .bp0_pos = 2, .bp_bits = 4, .srp_pos = 7 |
| 1062 | }; |
| 1063 | |
| 1064 | static struct wp_range_descriptor mx25l25635f_tb0_ranges[] = { |
| 1065 | { { }, 0, {0, 0} }, /* none */ |
| 1066 | { { }, 0x1, {0x1ff0000, 64 * 1 * 1024} }, /* block 511 */ |
| 1067 | { { }, 0x2, {0x1fe0000, 64 * 2 * 1024} }, /* blocks 510-511 */ |
| 1068 | { { }, 0x3, {0x1fc0000, 64 * 4 * 1024} }, /* blocks 508-511 */ |
| 1069 | { { }, 0x4, {0x1f80000, 64 * 8 * 1024} }, /* blocks 504-511 */ |
| 1070 | { { }, 0x5, {0x1f00000, 64 * 16 * 1024} }, /* blocks 496-511 */ |
| 1071 | { { }, 0x6, {0x1e00000, 64 * 32 * 1024} }, /* blocks 480-511 */ |
| 1072 | { { }, 0x7, {0x1c00000, 64 * 64 * 1024} }, /* blocks 448-511 */ |
| 1073 | { { }, 0x8, {0x1800000, 64 * 128 * 1024} }, /* blocks 384-511 */ |
| 1074 | { { }, 0x9, {0x1000000, 64 * 256 * 1024} }, /* blocks 256-511 */ |
| 1075 | { { }, 0xa, {0x0000000, 64 * 512 * 1024} }, /* all */ |
| 1076 | { { }, 0xb, {0x0000000, 64 * 512 * 1024} }, /* all */ |
| 1077 | { { }, 0xc, {0x0000000, 64 * 512 * 1024} }, /* all */ |
| 1078 | { { }, 0xd, {0x0000000, 64 * 512 * 1024} }, /* all */ |
| 1079 | { { }, 0xe, {0x0000000, 64 * 512 * 1024} }, /* all */ |
| 1080 | { { }, 0xf, {0x0000000, 64 * 512 * 1024} }, /* all */ |
| 1081 | }; |
| 1082 | |
| 1083 | static struct wp_range_descriptor mx25l25635f_tb1_ranges[] = { |
| 1084 | { { }, 0, {0, 0} }, /* none */ |
| 1085 | { { }, 0x1, {0x000000, 64 * 1 * 1024} }, /* block 0 */ |
| 1086 | { { }, 0x2, {0x000000, 64 * 2 * 1024} }, /* blocks 0-1 */ |
| 1087 | { { }, 0x3, {0x000000, 64 * 4 * 1024} }, /* blocks 0-3 */ |
| 1088 | { { }, 0x4, {0x000000, 64 * 8 * 1024} }, /* blocks 0-7 */ |
| 1089 | { { }, 0x5, {0x000000, 64 * 16 * 1024} }, /* blocks 0-15 */ |
| 1090 | { { }, 0x6, {0x000000, 64 * 32 * 1024} }, /* blocks 0-31 */ |
| 1091 | { { }, 0x7, {0x000000, 64 * 64 * 1024} }, /* blocks 0-63 */ |
| 1092 | { { }, 0x8, {0x000000, 64 * 128 * 1024} }, /* blocks 0-127 */ |
| 1093 | { { }, 0x9, {0x000000, 64 * 256 * 1024} }, /* blocks 0-255 */ |
| 1094 | { { }, 0xa, {0x000000, 64 * 512 * 1024} }, /* all */ |
| 1095 | { { }, 0xb, {0x000000, 64 * 512 * 1024} }, /* all */ |
| 1096 | { { }, 0xc, {0x000000, 64 * 512 * 1024} }, /* all */ |
| 1097 | { { }, 0xd, {0x000000, 64 * 512 * 1024} }, /* all */ |
| 1098 | { { }, 0xe, {0x000000, 64 * 512 * 1024} }, /* all */ |
| 1099 | { { }, 0xf, {0x000000, 64 * 512 * 1024} }, /* all */ |
| 1100 | }; |
| 1101 | |
| 1102 | static struct status_register_layout mx25l25635f_sr1 = { |
| 1103 | .bp0_pos = 2, .bp_bits = 4, .srp_pos = 7 |
| 1104 | }; |
| 1105 | |
| 1106 | static struct wp_range_descriptor s25fs128s_ranges[] = { |
| 1107 | { { .tb = 1 }, 0, {0, 0} }, /* none */ |
| 1108 | { { .tb = 1 }, 0x1, {0x000000, 256 * 1024} }, /* lower 64th */ |
| 1109 | { { .tb = 1 }, 0x2, {0x000000, 512 * 1024} }, /* lower 32nd */ |
| 1110 | { { .tb = 1 }, 0x3, {0x000000, 1024 * 1024} }, /* lower 16th */ |
| 1111 | { { .tb = 1 }, 0x4, {0x000000, 2048 * 1024} }, /* lower 8th */ |
| 1112 | { { .tb = 1 }, 0x5, {0x000000, 4096 * 1024} }, /* lower 4th */ |
| 1113 | { { .tb = 1 }, 0x6, {0x000000, 8192 * 1024} }, /* lower half */ |
| 1114 | { { .tb = 1 }, 0x7, {0x000000, 16384 * 1024} }, /* all */ |
| 1115 | |
| 1116 | { { .tb = 0 }, 0, {0, 0} }, /* none */ |
| 1117 | { { .tb = 0 }, 0x1, {0xfc0000, 256 * 1024} }, /* upper 64th */ |
| 1118 | { { .tb = 0 }, 0x2, {0xf80000, 512 * 1024} }, /* upper 32nd */ |
| 1119 | { { .tb = 0 }, 0x3, {0xf00000, 1024 * 1024} }, /* upper 16th */ |
| 1120 | { { .tb = 0 }, 0x4, {0xe00000, 2048 * 1024} }, /* upper 8th */ |
| 1121 | { { .tb = 0 }, 0x5, {0xc00000, 4096 * 1024} }, /* upper 4th */ |
| 1122 | { { .tb = 0 }, 0x6, {0x800000, 8192 * 1024} }, /* upper half */ |
| 1123 | { { .tb = 0 }, 0x7, {0x000000, 16384 * 1024} }, /* all */ |
| 1124 | }; |
| 1125 | |
| 1126 | static struct status_register_layout s25fs128s_sr1 = { |
| 1127 | .bp0_pos = 2, .bp_bits = 3, .srp_pos = 7 |
| 1128 | }; |
| 1129 | |
| 1130 | |
| 1131 | static struct wp_range_descriptor s25fl256s_ranges[] = { |
| 1132 | { { .tb = 1 }, 0, {0, 0} }, /* none */ |
| 1133 | { { .tb = 1 }, 0x1, {0x000000, 512 * 1024} }, /* lower 64th */ |
| 1134 | { { .tb = 1 }, 0x2, {0x000000, 1024 * 1024} }, /* lower 32nd */ |
| 1135 | { { .tb = 1 }, 0x3, {0x000000, 2048 * 1024} }, /* lower 16th */ |
| 1136 | { { .tb = 1 }, 0x4, {0x000000, 4096 * 1024} }, /* lower 8th */ |
| 1137 | { { .tb = 1 }, 0x5, {0x000000, 8192 * 1024} }, /* lower 4th */ |
| 1138 | { { .tb = 1 }, 0x6, {0x000000, 16384 * 1024} }, /* lower half */ |
| 1139 | { { .tb = 1 }, 0x7, {0x000000, 32768 * 1024} }, /* all */ |
| 1140 | |
| 1141 | { { .tb = 0 }, 0, {0, 0} }, /* none */ |
| 1142 | { { .tb = 0 }, 0x1, {0x1f80000, 512 * 1024} }, /* upper 64th */ |
| 1143 | { { .tb = 0 }, 0x2, {0x1f00000, 1024 * 1024} }, /* upper 32nd */ |
| 1144 | { { .tb = 0 }, 0x3, {0x1e00000, 2048 * 1024} }, /* upper 16th */ |
| 1145 | { { .tb = 0 }, 0x4, {0x1c00000, 4096 * 1024} }, /* upper 8th */ |
| 1146 | { { .tb = 0 }, 0x5, {0x1800000, 8192 * 1024} }, /* upper 4th */ |
| 1147 | { { .tb = 0 }, 0x6, {0x1000000, 16384 * 1024} }, /* upper half */ |
| 1148 | { { .tb = 0 }, 0x7, {0x000000, 32768 * 1024} }, /* all */ |
| 1149 | }; |
| 1150 | |
| 1151 | static struct status_register_layout s25fl256s_sr1 = { |
| 1152 | .bp0_pos = 2, .bp_bits = 3, .srp_pos = 7 |
| 1153 | }; |
| 1154 | |
| 1155 | |
Nikolai Artemiev | 9daffd9 | 2021-04-06 16:54:46 +1000 | [diff] [blame] | 1156 | static int range_table(const struct flashctx *flash, |
| 1157 | struct wp_range_descriptor **descrs, |
| 1158 | int *num_entries); |
| 1159 | |
Nikolai Artemiev | 9d3980e | 2021-03-30 22:26:37 +1100 | [diff] [blame] | 1160 | struct wp *get_wp_for_flashchip(const struct flashchip *chip) { |
| 1161 | // FIXME: The .wp field should be deleted from from struct flashchip |
| 1162 | // completly, but linux_mtd and cros_ec still assign their own values |
| 1163 | // to it. When they are cleaned up we can delete this. |
| 1164 | if(chip->wp) return chip->wp; |
| 1165 | |
| 1166 | switch (chip->manufacture_id) { |
| 1167 | case WINBOND_NEX_ID: |
| 1168 | switch(chip->model_id) { |
| 1169 | case WINBOND_NEX_W25X10: |
| 1170 | case WINBOND_NEX_W25X20: |
| 1171 | case WINBOND_NEX_W25X40: |
| 1172 | case WINBOND_NEX_W25X80: |
| 1173 | case WINBOND_NEX_W25Q128_V_M: |
| 1174 | return &wp_w25; |
| 1175 | case WINBOND_NEX_W25Q80_V: |
| 1176 | case WINBOND_NEX_W25Q16_V: |
| 1177 | case WINBOND_NEX_W25Q32_V: |
| 1178 | case WINBOND_NEX_W25Q32_W: |
| 1179 | case WINBOND_NEX_W25Q32JW: |
| 1180 | case WINBOND_NEX_W25Q64_V: |
| 1181 | case WINBOND_NEX_W25Q64_W: |
| 1182 | // W25Q64JW does not have a range table entry, but the flashchip |
| 1183 | // set .wp to wp_25q, so keep it here until the issue is resolved |
| 1184 | case WINBOND_NEX_W25Q64JW: |
| 1185 | case WINBOND_NEX_W25Q128_DTR: |
| 1186 | case WINBOND_NEX_W25Q128_V: |
| 1187 | case WINBOND_NEX_W25Q128_W: |
| 1188 | return &wp_w25q; |
| 1189 | case WINBOND_NEX_W25Q256_V: |
| 1190 | case WINBOND_NEX_W25Q256JV_M: |
| 1191 | return &wp_w25q_large; |
| 1192 | } |
| 1193 | break; |
| 1194 | case EON_ID_NOPREFIX: |
| 1195 | switch (chip->model_id) { |
| 1196 | case EON_EN25F40: |
| 1197 | case EON_EN25Q40: |
| 1198 | case EON_EN25Q80: |
| 1199 | case EON_EN25Q32: |
| 1200 | case EON_EN25Q64: |
| 1201 | case EON_EN25Q128: |
| 1202 | case EON_EN25QH128: |
| 1203 | case EON_EN25S64: |
| 1204 | return &wp_w25; |
| 1205 | } |
| 1206 | break; |
| 1207 | case MACRONIX_ID: |
| 1208 | switch (chip->model_id) { |
| 1209 | case MACRONIX_MX25L1005: |
| 1210 | case MACRONIX_MX25L2005: |
| 1211 | case MACRONIX_MX25L4005: |
| 1212 | case MACRONIX_MX25L8005: |
| 1213 | case MACRONIX_MX25L1605: |
| 1214 | case MACRONIX_MX25L3205: |
| 1215 | case MACRONIX_MX25U3235E: |
| 1216 | case MACRONIX_MX25U6435E: |
| 1217 | return &wp_w25; |
| 1218 | case MACRONIX_MX25U12835E: |
| 1219 | return &wp_w25q_large; |
| 1220 | case MACRONIX_MX25L6405: |
| 1221 | case MACRONIX_MX25L6495F: |
| 1222 | case MACRONIX_MX25L25635F: |
| 1223 | return &wp_generic; |
| 1224 | } |
| 1225 | break; |
| 1226 | case ST_ID: |
| 1227 | switch(chip->model_id) { |
| 1228 | case ST_N25Q064__1E: |
| 1229 | case ST_N25Q064__3E: |
| 1230 | return &wp_w25; |
| 1231 | } |
| 1232 | break; |
| 1233 | case GIGADEVICE_ID: |
| 1234 | switch(chip->model_id) { |
| 1235 | case GIGADEVICE_GD25LQ32: |
| 1236 | // GD25Q40 does not have a .wp field in flashchips.c, but |
| 1237 | // it is in the w25 range table function, so note it here |
| 1238 | // until the issue is resolved: |
| 1239 | // case GIGADEVICE_GD25Q40: |
| 1240 | case GIGADEVICE_GD25Q64: |
| 1241 | case GIGADEVICE_GD25LQ64: |
Nikolai Artemiev | 9d3980e | 2021-03-30 22:26:37 +1100 | [diff] [blame] | 1242 | case GIGADEVICE_GD25Q128: |
| 1243 | return &wp_w25; |
| 1244 | case GIGADEVICE_GD25Q256D: |
| 1245 | return &wp_w25q_large; |
Nikolai Artemiev | 9d3980e | 2021-03-30 22:26:37 +1100 | [diff] [blame] | 1246 | case GIGADEVICE_GD25LQ128CD: |
| 1247 | case GIGADEVICE_GD25Q32: |
| 1248 | return &wp_generic; |
| 1249 | } |
| 1250 | break; |
| 1251 | case AMIC_ID_NOPREFIX: |
| 1252 | switch(chip->model_id) { |
| 1253 | case AMIC_A25L040: |
| 1254 | return &wp_w25; |
| 1255 | } |
| 1256 | break; |
| 1257 | case ATMEL_ID: |
| 1258 | switch(chip->model_id) { |
| 1259 | case ATMEL_AT25SF128A: |
| 1260 | case ATMEL_AT25SL128A: |
| 1261 | return &wp_w25q; |
| 1262 | } |
| 1263 | break; |
| 1264 | case PROGMANUF_ID: |
| 1265 | switch(chip->model_id) { |
| 1266 | case PROGDEV_ID: |
| 1267 | return &wp_w25; |
| 1268 | } |
| 1269 | break; |
| 1270 | case SPANSION_ID: |
| 1271 | switch (chip->model_id) { |
| 1272 | case SPANSION_S25FS128S_L: |
| 1273 | case SPANSION_S25FS128S_S: |
| 1274 | case SPANSION_S25FL256S_UL: |
| 1275 | case SPANSION_S25FL256S_US: |
| 1276 | // SPANSION_S25FL128S_UL does not have a range table entry, |
| 1277 | // but its flashchip set .wp to wp_generic, so keep it here |
| 1278 | // until the issue resolved |
| 1279 | case SPANSION_S25FL128S_UL: |
| 1280 | // SPANSION_S25FL128S_US does not have a range table entry, |
| 1281 | // but its flashchip set .wp to wp_generic, so keep it here |
| 1282 | // until the issue resolved |
| 1283 | case SPANSION_S25FL128S_US: |
| 1284 | return &wp_generic; |
| 1285 | } |
| 1286 | break; |
| 1287 | } |
| 1288 | |
| 1289 | |
| 1290 | return NULL; |
| 1291 | } |
| 1292 | |
Duncan Laurie | ed32d7b | 2015-05-27 11:28:18 -0700 | [diff] [blame] | 1293 | /* FIXME: Move to spi25.c if it's a JEDEC standard opcode */ |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 1294 | static uint8_t w25q_read_status_register_2(const struct flashctx *flash) |
Duncan Laurie | ed32d7b | 2015-05-27 11:28:18 -0700 | [diff] [blame] | 1295 | { |
| 1296 | static const unsigned char cmd[JEDEC_RDSR_OUTSIZE] = { 0x35 }; |
| 1297 | unsigned char readarr[2]; |
| 1298 | int ret; |
| 1299 | |
Edward O'Callaghan | 70f3e8f | 2020-12-21 12:50:52 +1100 | [diff] [blame] | 1300 | if (flash->chip->read_status) { |
| 1301 | msg_cdbg("RDSR2 failed! cmd=0x35 unimpl for opaque chips\n"); |
| 1302 | return 0; |
| 1303 | } |
| 1304 | |
Duncan Laurie | ed32d7b | 2015-05-27 11:28:18 -0700 | [diff] [blame] | 1305 | /* Read Status Register */ |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 1306 | ret = spi_send_command(flash, sizeof(cmd), sizeof(readarr), cmd, readarr); |
Duncan Laurie | ed32d7b | 2015-05-27 11:28:18 -0700 | [diff] [blame] | 1307 | if (ret) { |
| 1308 | /* |
| 1309 | * FIXME: make this a benign failure for now in case we are |
| 1310 | * unable to execute the opcode |
| 1311 | */ |
| 1312 | msg_cdbg("RDSR2 failed!\n"); |
| 1313 | readarr[0] = 0x00; |
| 1314 | } |
| 1315 | |
| 1316 | return readarr[0]; |
| 1317 | } |
| 1318 | |
Karthikeyan Ramasubramanian | fb166b7 | 2019-06-24 12:38:55 -0600 | [diff] [blame] | 1319 | /* FIXME: Move to spi25.c if it's a JEDEC standard opcode */ |
Edward O'Callaghan | df43e90 | 2020-11-13 23:08:26 +1100 | [diff] [blame] | 1320 | static uint8_t mx25l_read_config_register(const struct flashctx *flash) |
Karthikeyan Ramasubramanian | fb166b7 | 2019-06-24 12:38:55 -0600 | [diff] [blame] | 1321 | { |
| 1322 | static const unsigned char cmd[JEDEC_RDSR_OUTSIZE] = { 0x15 }; |
| 1323 | unsigned char readarr[2]; /* leave room for dummy byte */ |
| 1324 | int ret; |
| 1325 | |
Edward O'Callaghan | 70f3e8f | 2020-12-21 12:50:52 +1100 | [diff] [blame] | 1326 | if (flash->chip->read_status) { |
| 1327 | msg_cdbg("RDCR failed! cmd=0x15 unimpl for opaque chips\n"); |
| 1328 | return 0; |
| 1329 | } |
| 1330 | |
Karthikeyan Ramasubramanian | fb166b7 | 2019-06-24 12:38:55 -0600 | [diff] [blame] | 1331 | ret = spi_send_command(flash, sizeof(cmd), sizeof(readarr), cmd, readarr); |
| 1332 | if (ret) { |
| 1333 | msg_cdbg("RDCR failed!\n"); |
| 1334 | readarr[0] = 0x00; |
| 1335 | } |
| 1336 | |
| 1337 | return readarr[0]; |
| 1338 | } |
| 1339 | |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 1340 | int w25_range_to_status(const struct flashctx *flash, |
Louis Yung-Chieh Lo | a92e8b2 | 2010-10-08 13:31:27 +0800 | [diff] [blame] | 1341 | unsigned int start, unsigned int len, |
| 1342 | struct w25q_status *status) |
| 1343 | { |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 1344 | struct wp_range_descriptor *descrs; |
Louis Yung-Chieh Lo | a92e8b2 | 2010-10-08 13:31:27 +0800 | [diff] [blame] | 1345 | int i, range_found = 0; |
| 1346 | int num_entries; |
| 1347 | |
Nikolai Artemiev | 9daffd9 | 2021-04-06 16:54:46 +1000 | [diff] [blame] | 1348 | if (range_table(flash, &descrs, &num_entries)) |
Edward O'Callaghan | bea239e | 2019-12-04 14:42:54 +1100 | [diff] [blame] | 1349 | return -1; |
| 1350 | |
David Hendricks | f7924d1 | 2010-06-10 21:26:44 -0700 | [diff] [blame] | 1351 | for (i = 0; i < num_entries; i++) { |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 1352 | struct wp_range *r = &descrs[i].range; |
David Hendricks | f7924d1 | 2010-06-10 21:26:44 -0700 | [diff] [blame] | 1353 | |
| 1354 | msg_cspew("comparing range 0x%x 0x%x / 0x%x 0x%x\n", |
| 1355 | start, len, r->start, r->len); |
| 1356 | if ((start == r->start) && (len == r->len)) { |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 1357 | status->bp0 = descrs[i].bp & 1; |
| 1358 | status->bp1 = descrs[i].bp >> 1; |
| 1359 | status->bp2 = descrs[i].bp >> 2; |
| 1360 | status->tb = descrs[i].m.tb; |
| 1361 | status->sec = descrs[i].m.sec; |
David Hendricks | f7924d1 | 2010-06-10 21:26:44 -0700 | [diff] [blame] | 1362 | |
| 1363 | range_found = 1; |
| 1364 | break; |
| 1365 | } |
| 1366 | } |
| 1367 | |
| 1368 | if (!range_found) { |
Edward O'Callaghan | 3be63e0 | 2020-03-27 14:44:24 +1100 | [diff] [blame] | 1369 | msg_cerr("%s: matching range not found\n", __func__); |
David Hendricks | f7924d1 | 2010-06-10 21:26:44 -0700 | [diff] [blame] | 1370 | return -1; |
| 1371 | } |
Edward O'Callaghan | bea239e | 2019-12-04 14:42:54 +1100 | [diff] [blame] | 1372 | |
David Hendricks | d494b0a | 2010-08-16 16:28:50 -0700 | [diff] [blame] | 1373 | return 0; |
| 1374 | } |
| 1375 | |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 1376 | int w25_status_to_range(const struct flashctx *flash, |
Louis Yung-Chieh Lo | a92e8b2 | 2010-10-08 13:31:27 +0800 | [diff] [blame] | 1377 | const struct w25q_status *status, |
| 1378 | unsigned int *start, unsigned int *len) |
| 1379 | { |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 1380 | struct wp_range_descriptor *descrs; |
Louis Yung-Chieh Lo | a92e8b2 | 2010-10-08 13:31:27 +0800 | [diff] [blame] | 1381 | int i, status_found = 0; |
| 1382 | int num_entries; |
| 1383 | |
Nikolai Artemiev | 9daffd9 | 2021-04-06 16:54:46 +1000 | [diff] [blame] | 1384 | if (range_table(flash, &descrs, &num_entries)) |
Edward O'Callaghan | bea239e | 2019-12-04 14:42:54 +1100 | [diff] [blame] | 1385 | return -1; |
| 1386 | |
Louis Yung-Chieh Lo | a92e8b2 | 2010-10-08 13:31:27 +0800 | [diff] [blame] | 1387 | for (i = 0; i < num_entries; i++) { |
| 1388 | int bp; |
Louis Yung-Chieh Lo | edd3930 | 2011-11-10 15:43:06 +0800 | [diff] [blame] | 1389 | int table_bp, table_tb, table_sec; |
Louis Yung-Chieh Lo | a92e8b2 | 2010-10-08 13:31:27 +0800 | [diff] [blame] | 1390 | |
| 1391 | bp = status->bp0 | (status->bp1 << 1) | (status->bp2 << 2); |
| 1392 | msg_cspew("comparing 0x%x 0x%x / 0x%x 0x%x / 0x%x 0x%x\n", |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 1393 | bp, descrs[i].bp, |
| 1394 | status->tb, descrs[i].m.tb, |
| 1395 | status->sec, descrs[i].m.sec); |
| 1396 | table_bp = descrs[i].bp; |
| 1397 | table_tb = descrs[i].m.tb; |
| 1398 | table_sec = descrs[i].m.sec; |
Louis Yung-Chieh Lo | edd3930 | 2011-11-10 15:43:06 +0800 | [diff] [blame] | 1399 | if ((bp == table_bp || table_bp == X) && |
| 1400 | (status->tb == table_tb || table_tb == X) && |
| 1401 | (status->sec == table_sec || table_sec == X)) { |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 1402 | *start = descrs[i].range.start; |
| 1403 | *len = descrs[i].range.len; |
Louis Yung-Chieh Lo | a92e8b2 | 2010-10-08 13:31:27 +0800 | [diff] [blame] | 1404 | |
| 1405 | status_found = 1; |
| 1406 | break; |
| 1407 | } |
| 1408 | } |
| 1409 | |
| 1410 | if (!status_found) { |
| 1411 | msg_cerr("matching status not found\n"); |
| 1412 | return -1; |
| 1413 | } |
Edward O'Callaghan | bea239e | 2019-12-04 14:42:54 +1100 | [diff] [blame] | 1414 | |
Louis Yung-Chieh Lo | a92e8b2 | 2010-10-08 13:31:27 +0800 | [diff] [blame] | 1415 | return 0; |
| 1416 | } |
| 1417 | |
Louis Yung-Chieh Lo | 165b464 | 2010-11-26 16:35:26 +0800 | [diff] [blame] | 1418 | /* Given a [start, len], this function calls w25_range_to_status() to convert |
| 1419 | * it to flash-chip-specific range bits, then sets into status register. |
| 1420 | */ |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 1421 | static int w25_set_range(const struct flashctx *flash, |
David Hendricks | d494b0a | 2010-08-16 16:28:50 -0700 | [diff] [blame] | 1422 | unsigned int start, unsigned int len) |
| 1423 | { |
| 1424 | struct w25q_status status; |
Louis Yung-Chieh Lo | 165b464 | 2010-11-26 16:35:26 +0800 | [diff] [blame] | 1425 | int tmp = 0; |
| 1426 | int expected = 0; |
David Hendricks | d494b0a | 2010-08-16 16:28:50 -0700 | [diff] [blame] | 1427 | |
| 1428 | memset(&status, 0, sizeof(status)); |
Nikolai Artemiev | 48b424b | 2021-04-06 14:12:02 +1000 | [diff] [blame] | 1429 | tmp = spi_read_status_register(flash); |
David Hendricks | d494b0a | 2010-08-16 16:28:50 -0700 | [diff] [blame] | 1430 | memcpy(&status, &tmp, 1); |
| 1431 | msg_cdbg("%s: old status: 0x%02x\n", __func__, tmp); |
| 1432 | |
Edward O'Callaghan | bea239e | 2019-12-04 14:42:54 +1100 | [diff] [blame] | 1433 | if (w25_range_to_status(flash, start, len, &status)) |
| 1434 | return -1; |
David Hendricks | f7924d1 | 2010-06-10 21:26:44 -0700 | [diff] [blame] | 1435 | |
| 1436 | msg_cdbg("status.busy: %x\n", status.busy); |
| 1437 | msg_cdbg("status.wel: %x\n", status.wel); |
| 1438 | msg_cdbg("status.bp0: %x\n", status.bp0); |
| 1439 | msg_cdbg("status.bp1: %x\n", status.bp1); |
| 1440 | msg_cdbg("status.bp2: %x\n", status.bp2); |
| 1441 | msg_cdbg("status.tb: %x\n", status.tb); |
| 1442 | msg_cdbg("status.sec: %x\n", status.sec); |
| 1443 | msg_cdbg("status.srp0: %x\n", status.srp0); |
| 1444 | |
Louis Yung-Chieh Lo | 165b464 | 2010-11-26 16:35:26 +0800 | [diff] [blame] | 1445 | memcpy(&expected, &status, sizeof(status)); |
Nikolai Artemiev | 48b424b | 2021-04-06 14:12:02 +1000 | [diff] [blame] | 1446 | spi_write_status_register(flash, expected); |
David Hendricks | f7924d1 | 2010-06-10 21:26:44 -0700 | [diff] [blame] | 1447 | |
Nikolai Artemiev | 48b424b | 2021-04-06 14:12:02 +1000 | [diff] [blame] | 1448 | tmp = spi_read_status_register(flash); |
Louis Yung-Chieh Lo | 165b464 | 2010-11-26 16:35:26 +0800 | [diff] [blame] | 1449 | msg_cdbg("%s: new status: 0x%02x\n", __func__, tmp); |
Edward O'Callaghan | 2672fb9 | 2019-12-04 14:47:58 +1100 | [diff] [blame] | 1450 | if ((tmp & MASK_WP_AREA) != (expected & MASK_WP_AREA)) { |
David Hendricks | c801adb | 2010-12-09 16:58:56 -0800 | [diff] [blame] | 1451 | msg_cerr("expected=0x%02x, but actual=0x%02x.\n", |
Louis Yung-Chieh Lo | 165b464 | 2010-11-26 16:35:26 +0800 | [diff] [blame] | 1452 | expected, tmp); |
| 1453 | return 1; |
| 1454 | } |
Edward O'Callaghan | 2672fb9 | 2019-12-04 14:47:58 +1100 | [diff] [blame] | 1455 | |
| 1456 | return 0; |
David Hendricks | f7924d1 | 2010-06-10 21:26:44 -0700 | [diff] [blame] | 1457 | } |
| 1458 | |
Louis Yung-Chieh Lo | 165b464 | 2010-11-26 16:35:26 +0800 | [diff] [blame] | 1459 | /* Print out the current status register value with human-readable text. */ |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 1460 | static int w25_wp_status(const struct flashctx *flash) |
Louis Yung-Chieh Lo | a92e8b2 | 2010-10-08 13:31:27 +0800 | [diff] [blame] | 1461 | { |
| 1462 | struct w25q_status status; |
| 1463 | int tmp; |
David Hendricks | ce8ded3 | 2010-10-08 11:23:38 -0700 | [diff] [blame] | 1464 | unsigned int start, len; |
Louis Yung-Chieh Lo | a92e8b2 | 2010-10-08 13:31:27 +0800 | [diff] [blame] | 1465 | int ret = 0; |
| 1466 | |
Louis Yung-Chieh Lo | 165b464 | 2010-11-26 16:35:26 +0800 | [diff] [blame] | 1467 | memset(&status, 0, sizeof(status)); |
Nikolai Artemiev | 48b424b | 2021-04-06 14:12:02 +1000 | [diff] [blame] | 1468 | tmp = spi_read_status_register(flash); |
Louis Yung-Chieh Lo | a92e8b2 | 2010-10-08 13:31:27 +0800 | [diff] [blame] | 1469 | memcpy(&status, &tmp, 1); |
| 1470 | msg_cinfo("WP: status: 0x%02x\n", tmp); |
| 1471 | msg_cinfo("WP: status.srp0: %x\n", status.srp0); |
| 1472 | msg_cinfo("WP: write protect is %s.\n", |
| 1473 | status.srp0 ? "enabled" : "disabled"); |
| 1474 | |
| 1475 | msg_cinfo("WP: write protect range: "); |
| 1476 | if (w25_status_to_range(flash, &status, &start, &len)) { |
| 1477 | msg_cinfo("(cannot resolve the range)\n"); |
| 1478 | ret = -1; |
| 1479 | } else { |
| 1480 | msg_cinfo("start=0x%08x, len=0x%08x\n", start, len); |
| 1481 | } |
| 1482 | |
| 1483 | return ret; |
| 1484 | } |
| 1485 | |
Duncan Laurie | 1801f7c | 2019-01-09 18:02:51 -0800 | [diff] [blame] | 1486 | static int w25q_large_range_to_status(const struct flashctx *flash, |
| 1487 | unsigned int start, unsigned int len, |
| 1488 | struct w25q_status_large *status) |
| 1489 | { |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 1490 | struct wp_range_descriptor *descrs; |
Duncan Laurie | 1801f7c | 2019-01-09 18:02:51 -0800 | [diff] [blame] | 1491 | int i, range_found = 0; |
| 1492 | int num_entries; |
| 1493 | |
Nikolai Artemiev | 9daffd9 | 2021-04-06 16:54:46 +1000 | [diff] [blame] | 1494 | if (range_table(flash, &descrs, &num_entries)) |
Duncan Laurie | 1801f7c | 2019-01-09 18:02:51 -0800 | [diff] [blame] | 1495 | return -1; |
Edward O'Callaghan | bea239e | 2019-12-04 14:42:54 +1100 | [diff] [blame] | 1496 | |
Duncan Laurie | 1801f7c | 2019-01-09 18:02:51 -0800 | [diff] [blame] | 1497 | for (i = 0; i < num_entries; i++) { |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 1498 | struct wp_range *r = &descrs[i].range; |
Duncan Laurie | 1801f7c | 2019-01-09 18:02:51 -0800 | [diff] [blame] | 1499 | |
| 1500 | msg_cspew("comparing range 0x%x 0x%x / 0x%x 0x%x\n", |
| 1501 | start, len, r->start, r->len); |
| 1502 | if ((start == r->start) && (len == r->len)) { |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 1503 | status->bp0 = descrs[i].bp & 1; |
| 1504 | status->bp1 = descrs[i].bp >> 1; |
| 1505 | status->bp2 = descrs[i].bp >> 2; |
| 1506 | status->bp3 = descrs[i].bp >> 3; |
Karthikeyan Ramasubramanian | fb166b7 | 2019-06-24 12:38:55 -0600 | [diff] [blame] | 1507 | /* |
| 1508 | * For MX25U12835E chip, Top/Bottom (T/B) bit is not |
| 1509 | * part of status register and in that bit position is |
| 1510 | * Quad Enable (QE) |
| 1511 | */ |
| 1512 | if (flash->chip->manufacture_id != MACRONIX_ID || |
| 1513 | flash->chip->model_id != MACRONIX_MX25U12835E) |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 1514 | status->tb = descrs[i].m.tb; |
Duncan Laurie | 1801f7c | 2019-01-09 18:02:51 -0800 | [diff] [blame] | 1515 | |
| 1516 | range_found = 1; |
| 1517 | break; |
| 1518 | } |
| 1519 | } |
| 1520 | |
| 1521 | if (!range_found) { |
Edward O'Callaghan | 3be63e0 | 2020-03-27 14:44:24 +1100 | [diff] [blame] | 1522 | msg_cerr("%s: matching range not found\n", __func__); |
Duncan Laurie | 1801f7c | 2019-01-09 18:02:51 -0800 | [diff] [blame] | 1523 | return -1; |
| 1524 | } |
Edward O'Callaghan | bea239e | 2019-12-04 14:42:54 +1100 | [diff] [blame] | 1525 | |
Duncan Laurie | 1801f7c | 2019-01-09 18:02:51 -0800 | [diff] [blame] | 1526 | return 0; |
| 1527 | } |
| 1528 | |
| 1529 | static int w25_large_status_to_range(const struct flashctx *flash, |
| 1530 | const struct w25q_status_large *status, |
| 1531 | unsigned int *start, unsigned int *len) |
| 1532 | { |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 1533 | struct wp_range_descriptor *descrs; |
Duncan Laurie | 1801f7c | 2019-01-09 18:02:51 -0800 | [diff] [blame] | 1534 | int i, status_found = 0; |
| 1535 | int num_entries; |
| 1536 | |
Nikolai Artemiev | 9daffd9 | 2021-04-06 16:54:46 +1000 | [diff] [blame] | 1537 | if (range_table(flash, &descrs, &num_entries)) |
Duncan Laurie | 1801f7c | 2019-01-09 18:02:51 -0800 | [diff] [blame] | 1538 | return -1; |
Edward O'Callaghan | bea239e | 2019-12-04 14:42:54 +1100 | [diff] [blame] | 1539 | |
Duncan Laurie | 1801f7c | 2019-01-09 18:02:51 -0800 | [diff] [blame] | 1540 | for (i = 0; i < num_entries; i++) { |
| 1541 | int bp; |
| 1542 | int table_bp, table_tb; |
| 1543 | |
| 1544 | bp = status->bp0 | (status->bp1 << 1) | (status->bp2 << 2) | |
| 1545 | (status->bp3 << 3); |
| 1546 | msg_cspew("comparing 0x%x 0x%x / 0x%x 0x%x\n", |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 1547 | bp, descrs[i].bp, |
| 1548 | status->tb, descrs[i].m.tb); |
| 1549 | table_bp = descrs[i].bp; |
| 1550 | table_tb = descrs[i].m.tb; |
Duncan Laurie | 1801f7c | 2019-01-09 18:02:51 -0800 | [diff] [blame] | 1551 | if ((bp == table_bp || table_bp == X) && |
| 1552 | (status->tb == table_tb || table_tb == X)) { |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 1553 | *start = descrs[i].range.start; |
| 1554 | *len = descrs[i].range.len; |
Duncan Laurie | 1801f7c | 2019-01-09 18:02:51 -0800 | [diff] [blame] | 1555 | |
| 1556 | status_found = 1; |
| 1557 | break; |
| 1558 | } |
| 1559 | } |
| 1560 | |
| 1561 | if (!status_found) { |
| 1562 | msg_cerr("matching status not found\n"); |
| 1563 | return -1; |
| 1564 | } |
Edward O'Callaghan | bea239e | 2019-12-04 14:42:54 +1100 | [diff] [blame] | 1565 | |
Duncan Laurie | 1801f7c | 2019-01-09 18:02:51 -0800 | [diff] [blame] | 1566 | return 0; |
| 1567 | } |
| 1568 | |
| 1569 | /* Given a [start, len], this function calls w25_range_to_status() to convert |
| 1570 | * it to flash-chip-specific range bits, then sets into status register. |
| 1571 | * Returns 0 if successful, -1 on error, and 1 if reading back was different. |
| 1572 | */ |
| 1573 | static int w25q_large_set_range(const struct flashctx *flash, |
| 1574 | unsigned int start, unsigned int len) |
| 1575 | { |
| 1576 | struct w25q_status_large status; |
| 1577 | int tmp; |
| 1578 | int expected = 0; |
| 1579 | |
| 1580 | memset(&status, 0, sizeof(status)); |
Nikolai Artemiev | 48b424b | 2021-04-06 14:12:02 +1000 | [diff] [blame] | 1581 | tmp = spi_read_status_register(flash); |
Duncan Laurie | 1801f7c | 2019-01-09 18:02:51 -0800 | [diff] [blame] | 1582 | memcpy(&status, &tmp, 1); |
| 1583 | msg_cdbg("%s: old status: 0x%02x\n", __func__, tmp); |
| 1584 | |
| 1585 | if (w25q_large_range_to_status(flash, start, len, &status)) |
| 1586 | return -1; |
| 1587 | |
| 1588 | msg_cdbg("status.busy: %x\n", status.busy); |
| 1589 | msg_cdbg("status.wel: %x\n", status.wel); |
| 1590 | msg_cdbg("status.bp0: %x\n", status.bp0); |
| 1591 | msg_cdbg("status.bp1: %x\n", status.bp1); |
| 1592 | msg_cdbg("status.bp2: %x\n", status.bp2); |
| 1593 | msg_cdbg("status.bp3: %x\n", status.bp3); |
| 1594 | msg_cdbg("status.tb: %x\n", status.tb); |
| 1595 | msg_cdbg("status.srp0: %x\n", status.srp0); |
| 1596 | |
| 1597 | memcpy(&expected, &status, sizeof(status)); |
Nikolai Artemiev | 48b424b | 2021-04-06 14:12:02 +1000 | [diff] [blame] | 1598 | spi_write_status_register(flash, expected); |
Duncan Laurie | 1801f7c | 2019-01-09 18:02:51 -0800 | [diff] [blame] | 1599 | |
Nikolai Artemiev | 48b424b | 2021-04-06 14:12:02 +1000 | [diff] [blame] | 1600 | tmp = spi_read_status_register(flash); |
Duncan Laurie | 1801f7c | 2019-01-09 18:02:51 -0800 | [diff] [blame] | 1601 | msg_cdbg("%s: new status: 0x%02x\n", __func__, tmp); |
Edward O'Callaghan | 2672fb9 | 2019-12-04 14:47:58 +1100 | [diff] [blame] | 1602 | if ((tmp & MASK_WP_AREA_LARGE) != (expected & MASK_WP_AREA_LARGE)) { |
Duncan Laurie | 1801f7c | 2019-01-09 18:02:51 -0800 | [diff] [blame] | 1603 | msg_cerr("expected=0x%02x, but actual=0x%02x.\n", |
| 1604 | expected, tmp); |
| 1605 | return 1; |
| 1606 | } |
Edward O'Callaghan | 2672fb9 | 2019-12-04 14:47:58 +1100 | [diff] [blame] | 1607 | |
| 1608 | return 0; |
Duncan Laurie | 1801f7c | 2019-01-09 18:02:51 -0800 | [diff] [blame] | 1609 | } |
| 1610 | |
| 1611 | static int w25q_large_wp_status(const struct flashctx *flash) |
| 1612 | { |
| 1613 | struct w25q_status_large sr1; |
| 1614 | struct w25q_status_2 sr2; |
| 1615 | uint8_t tmp[2]; |
| 1616 | unsigned int start, len; |
| 1617 | int ret = 0; |
| 1618 | |
| 1619 | memset(&sr1, 0, sizeof(sr1)); |
Nikolai Artemiev | 48b424b | 2021-04-06 14:12:02 +1000 | [diff] [blame] | 1620 | tmp[0] = spi_read_status_register(flash); |
Duncan Laurie | 1801f7c | 2019-01-09 18:02:51 -0800 | [diff] [blame] | 1621 | memcpy(&sr1, &tmp[0], 1); |
| 1622 | |
| 1623 | memset(&sr2, 0, sizeof(sr2)); |
| 1624 | tmp[1] = w25q_read_status_register_2(flash); |
| 1625 | memcpy(&sr2, &tmp[1], 1); |
| 1626 | |
| 1627 | msg_cinfo("WP: status: 0x%02x%02x\n", tmp[1], tmp[0]); |
| 1628 | msg_cinfo("WP: status.srp0: %x\n", sr1.srp0); |
| 1629 | msg_cinfo("WP: status.srp1: %x\n", sr2.srp1); |
| 1630 | msg_cinfo("WP: write protect is %s.\n", |
| 1631 | (sr1.srp0 || sr2.srp1) ? "enabled" : "disabled"); |
| 1632 | |
| 1633 | msg_cinfo("WP: write protect range: "); |
| 1634 | if (w25_large_status_to_range(flash, &sr1, &start, &len)) { |
| 1635 | msg_cinfo("(cannot resolve the range)\n"); |
| 1636 | ret = -1; |
| 1637 | } else { |
| 1638 | msg_cinfo("start=0x%08x, len=0x%08x\n", start, len); |
| 1639 | } |
| 1640 | |
| 1641 | return ret; |
| 1642 | } |
| 1643 | |
Louis Yung-Chieh Lo | 165b464 | 2010-11-26 16:35:26 +0800 | [diff] [blame] | 1644 | /* Set/clear the SRP0 bit in the status register. */ |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 1645 | static int w25_set_srp0(const struct flashctx *flash, int enable) |
David Hendricks | f7924d1 | 2010-06-10 21:26:44 -0700 | [diff] [blame] | 1646 | { |
| 1647 | struct w25q_status status; |
| 1648 | int tmp = 0; |
Louis Yung-Chieh Lo | 165b464 | 2010-11-26 16:35:26 +0800 | [diff] [blame] | 1649 | int expected = 0; |
David Hendricks | f7924d1 | 2010-06-10 21:26:44 -0700 | [diff] [blame] | 1650 | |
| 1651 | memset(&status, 0, sizeof(status)); |
Nikolai Artemiev | 48b424b | 2021-04-06 14:12:02 +1000 | [diff] [blame] | 1652 | tmp = spi_read_status_register(flash); |
Louis Yung-Chieh Lo | 165b464 | 2010-11-26 16:35:26 +0800 | [diff] [blame] | 1653 | /* FIXME: this is NOT endian-free copy. */ |
David Hendricks | f7924d1 | 2010-06-10 21:26:44 -0700 | [diff] [blame] | 1654 | memcpy(&status, &tmp, 1); |
| 1655 | msg_cdbg("%s: old status: 0x%02x\n", __func__, tmp); |
| 1656 | |
Louis Yung-Chieh Lo | c19d3c5 | 2010-10-08 11:59:16 +0800 | [diff] [blame] | 1657 | status.srp0 = enable ? 1 : 0; |
Louis Yung-Chieh Lo | 165b464 | 2010-11-26 16:35:26 +0800 | [diff] [blame] | 1658 | memcpy(&expected, &status, sizeof(status)); |
Nikolai Artemiev | 48b424b | 2021-04-06 14:12:02 +1000 | [diff] [blame] | 1659 | spi_write_status_register(flash, expected); |
Louis Yung-Chieh Lo | 165b464 | 2010-11-26 16:35:26 +0800 | [diff] [blame] | 1660 | |
Nikolai Artemiev | 48b424b | 2021-04-06 14:12:02 +1000 | [diff] [blame] | 1661 | tmp = spi_read_status_register(flash); |
Louis Yung-Chieh Lo | 165b464 | 2010-11-26 16:35:26 +0800 | [diff] [blame] | 1662 | msg_cdbg("%s: new status: 0x%02x\n", __func__, tmp); |
| 1663 | if ((tmp & MASK_WP_AREA) != (expected & MASK_WP_AREA)) |
| 1664 | return 1; |
David Hendricks | f7924d1 | 2010-06-10 21:26:44 -0700 | [diff] [blame] | 1665 | |
| 1666 | return 0; |
| 1667 | } |
| 1668 | |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 1669 | static int w25_enable_writeprotect(const struct flashctx *flash, |
David Hendricks | 1c09f80 | 2012-10-03 11:03:48 -0700 | [diff] [blame] | 1670 | enum wp_mode wp_mode) |
Louis Yung-Chieh Lo | c19d3c5 | 2010-10-08 11:59:16 +0800 | [diff] [blame] | 1671 | { |
| 1672 | int ret; |
| 1673 | |
Edward O'Callaghan | ca44e5c | 2019-12-04 14:23:54 +1100 | [diff] [blame] | 1674 | if (wp_mode != WP_MODE_HARDWARE) { |
David Hendricks | 1c09f80 | 2012-10-03 11:03:48 -0700 | [diff] [blame] | 1675 | msg_cerr("%s(): unsupported write-protect mode\n", __func__); |
| 1676 | return 1; |
| 1677 | } |
| 1678 | |
Edward O'Callaghan | ca44e5c | 2019-12-04 14:23:54 +1100 | [diff] [blame] | 1679 | ret = w25_set_srp0(flash, 1); |
David Hendricks | c801adb | 2010-12-09 16:58:56 -0800 | [diff] [blame] | 1680 | if (ret) |
| 1681 | msg_cerr("%s(): error=%d.\n", __func__, ret); |
Louis Yung-Chieh Lo | c19d3c5 | 2010-10-08 11:59:16 +0800 | [diff] [blame] | 1682 | return ret; |
| 1683 | } |
| 1684 | |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 1685 | static int w25_disable_writeprotect(const struct flashctx *flash) |
Louis Yung-Chieh Lo | c19d3c5 | 2010-10-08 11:59:16 +0800 | [diff] [blame] | 1686 | { |
| 1687 | int ret; |
| 1688 | |
| 1689 | ret = w25_set_srp0(flash, 0); |
David Hendricks | c801adb | 2010-12-09 16:58:56 -0800 | [diff] [blame] | 1690 | if (ret) |
| 1691 | msg_cerr("%s(): error=%d.\n", __func__, ret); |
Edward O'Callaghan | bea239e | 2019-12-04 14:42:54 +1100 | [diff] [blame] | 1692 | |
Louis Yung-Chieh Lo | c19d3c5 | 2010-10-08 11:59:16 +0800 | [diff] [blame] | 1693 | return ret; |
| 1694 | } |
| 1695 | |
Nikolai Artemiev | 3b666da | 2021-04-06 16:59:01 +1000 | [diff] [blame] | 1696 | static int list_ranges(const struct flashctx *flash) |
David Hendricks | 0f7f538 | 2011-02-11 18:12:31 -0800 | [diff] [blame] | 1697 | { |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 1698 | struct wp_range_descriptor *descrs; |
David Hendricks | 0f7f538 | 2011-02-11 18:12:31 -0800 | [diff] [blame] | 1699 | int i, num_entries; |
| 1700 | |
Nikolai Artemiev | 9daffd9 | 2021-04-06 16:54:46 +1000 | [diff] [blame] | 1701 | if (range_table(flash, &descrs, &num_entries)) |
Edward O'Callaghan | bea239e | 2019-12-04 14:42:54 +1100 | [diff] [blame] | 1702 | return -1; |
| 1703 | |
David Hendricks | 0f7f538 | 2011-02-11 18:12:31 -0800 | [diff] [blame] | 1704 | for (i = 0; i < num_entries; i++) { |
| 1705 | msg_cinfo("start: 0x%06x, length: 0x%06x\n", |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 1706 | descrs[i].range.start, |
| 1707 | descrs[i].range.len); |
David Hendricks | 0f7f538 | 2011-02-11 18:12:31 -0800 | [diff] [blame] | 1708 | } |
| 1709 | |
| 1710 | return 0; |
| 1711 | } |
| 1712 | |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 1713 | static int w25q_wp_status(const struct flashctx *flash) |
David Hendricks | 1c09f80 | 2012-10-03 11:03:48 -0700 | [diff] [blame] | 1714 | { |
| 1715 | struct w25q_status sr1; |
| 1716 | struct w25q_status_2 sr2; |
David Hendricks | f1bd880 | 2012-10-30 11:37:57 -0700 | [diff] [blame] | 1717 | uint8_t tmp[2]; |
David Hendricks | 1c09f80 | 2012-10-03 11:03:48 -0700 | [diff] [blame] | 1718 | unsigned int start, len; |
| 1719 | int ret = 0; |
| 1720 | |
| 1721 | memset(&sr1, 0, sizeof(sr1)); |
Nikolai Artemiev | 48b424b | 2021-04-06 14:12:02 +1000 | [diff] [blame] | 1722 | tmp[0] = spi_read_status_register(flash); |
David Hendricks | f1bd880 | 2012-10-30 11:37:57 -0700 | [diff] [blame] | 1723 | memcpy(&sr1, &tmp[0], 1); |
David Hendricks | 1c09f80 | 2012-10-03 11:03:48 -0700 | [diff] [blame] | 1724 | |
David Hendricks | f1bd880 | 2012-10-30 11:37:57 -0700 | [diff] [blame] | 1725 | memset(&sr2, 0, sizeof(sr2)); |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 1726 | tmp[1] = w25q_read_status_register_2(flash); |
David Hendricks | f1bd880 | 2012-10-30 11:37:57 -0700 | [diff] [blame] | 1727 | memcpy(&sr2, &tmp[1], 1); |
| 1728 | |
| 1729 | msg_cinfo("WP: status: 0x%02x%02x\n", tmp[1], tmp[0]); |
David Hendricks | 1c09f80 | 2012-10-03 11:03:48 -0700 | [diff] [blame] | 1730 | msg_cinfo("WP: status.srp0: %x\n", sr1.srp0); |
| 1731 | msg_cinfo("WP: status.srp1: %x\n", sr2.srp1); |
| 1732 | msg_cinfo("WP: write protect is %s.\n", |
| 1733 | (sr1.srp0 || sr2.srp1) ? "enabled" : "disabled"); |
| 1734 | |
| 1735 | msg_cinfo("WP: write protect range: "); |
| 1736 | if (w25_status_to_range(flash, &sr1, &start, &len)) { |
| 1737 | msg_cinfo("(cannot resolve the range)\n"); |
| 1738 | ret = -1; |
| 1739 | } else { |
| 1740 | msg_cinfo("start=0x%08x, len=0x%08x\n", start, len); |
| 1741 | } |
| 1742 | |
| 1743 | return ret; |
| 1744 | } |
| 1745 | |
| 1746 | /* |
| 1747 | * W25Q adds an optional byte to the standard WRSR opcode. If /CS is |
| 1748 | * de-asserted after the first byte, then it acts like a JEDEC-standard |
| 1749 | * WRSR command. if /CS is asserted, then the next data byte is written |
| 1750 | * into status register 2. |
| 1751 | */ |
| 1752 | #define W25Q_WRSR_OUTSIZE 0x03 |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 1753 | static int w25q_write_status_register_WREN(const struct flashctx *flash, uint8_t s1, uint8_t s2) |
David Hendricks | 1c09f80 | 2012-10-03 11:03:48 -0700 | [diff] [blame] | 1754 | { |
| 1755 | int result; |
| 1756 | struct spi_command cmds[] = { |
| 1757 | { |
| 1758 | /* FIXME: WRSR requires either EWSR or WREN depending on chip type. */ |
| 1759 | .writecnt = JEDEC_WREN_OUTSIZE, |
| 1760 | .writearr = (const unsigned char[]){ JEDEC_WREN }, |
| 1761 | .readcnt = 0, |
| 1762 | .readarr = NULL, |
| 1763 | }, { |
| 1764 | .writecnt = W25Q_WRSR_OUTSIZE, |
| 1765 | .writearr = (const unsigned char[]){ JEDEC_WRSR, s1, s2 }, |
| 1766 | .readcnt = 0, |
| 1767 | .readarr = NULL, |
| 1768 | }, { |
| 1769 | .writecnt = 0, |
| 1770 | .writearr = NULL, |
| 1771 | .readcnt = 0, |
| 1772 | .readarr = NULL, |
| 1773 | }}; |
| 1774 | |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 1775 | result = spi_send_multicommand(flash, cmds); |
David Hendricks | 1c09f80 | 2012-10-03 11:03:48 -0700 | [diff] [blame] | 1776 | if (result) { |
| 1777 | msg_cerr("%s failed during command execution\n", |
| 1778 | __func__); |
| 1779 | } |
| 1780 | |
| 1781 | /* WRSR performs a self-timed erase before the changes take effect. */ |
David Hendricks | 6082404 | 2014-12-11 17:22:06 -0800 | [diff] [blame] | 1782 | programmer_delay(100 * 1000); |
David Hendricks | 1c09f80 | 2012-10-03 11:03:48 -0700 | [diff] [blame] | 1783 | |
| 1784 | return result; |
| 1785 | } |
| 1786 | |
| 1787 | /* |
| 1788 | * Set/clear the SRP1 bit in status register 2. |
| 1789 | * FIXME: make this more generic if other chips use the same SR2 layout |
| 1790 | */ |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 1791 | static int w25q_set_srp1(const struct flashctx *flash, int enable) |
David Hendricks | 1c09f80 | 2012-10-03 11:03:48 -0700 | [diff] [blame] | 1792 | { |
| 1793 | struct w25q_status sr1; |
| 1794 | struct w25q_status_2 sr2; |
| 1795 | uint8_t tmp, expected; |
| 1796 | |
Nikolai Artemiev | 48b424b | 2021-04-06 14:12:02 +1000 | [diff] [blame] | 1797 | tmp = spi_read_status_register(flash); |
David Hendricks | 1c09f80 | 2012-10-03 11:03:48 -0700 | [diff] [blame] | 1798 | memcpy(&sr1, &tmp, 1); |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 1799 | tmp = w25q_read_status_register_2(flash); |
David Hendricks | 1c09f80 | 2012-10-03 11:03:48 -0700 | [diff] [blame] | 1800 | memcpy(&sr2, &tmp, 1); |
| 1801 | |
| 1802 | msg_cdbg("%s: old status 2: 0x%02x\n", __func__, tmp); |
| 1803 | |
| 1804 | sr2.srp1 = enable ? 1 : 0; |
| 1805 | |
| 1806 | memcpy(&expected, &sr2, 1); |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 1807 | w25q_write_status_register_WREN(flash, *((uint8_t *)&sr1), *((uint8_t *)&sr2)); |
David Hendricks | 1c09f80 | 2012-10-03 11:03:48 -0700 | [diff] [blame] | 1808 | |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 1809 | tmp = w25q_read_status_register_2(flash); |
David Hendricks | 1c09f80 | 2012-10-03 11:03:48 -0700 | [diff] [blame] | 1810 | msg_cdbg("%s: new status 2: 0x%02x\n", __func__, tmp); |
| 1811 | if ((tmp & MASK_WP2_AREA) != (expected & MASK_WP2_AREA)) |
| 1812 | return 1; |
| 1813 | |
| 1814 | return 0; |
| 1815 | } |
| 1816 | |
| 1817 | enum wp_mode get_wp_mode(const char *mode_str) |
| 1818 | { |
| 1819 | enum wp_mode wp_mode = WP_MODE_UNKNOWN; |
| 1820 | |
| 1821 | if (!strcasecmp(mode_str, "hardware")) |
| 1822 | wp_mode = WP_MODE_HARDWARE; |
| 1823 | else if (!strcasecmp(mode_str, "power_cycle")) |
| 1824 | wp_mode = WP_MODE_POWER_CYCLE; |
| 1825 | else if (!strcasecmp(mode_str, "permanent")) |
| 1826 | wp_mode = WP_MODE_PERMANENT; |
| 1827 | |
| 1828 | return wp_mode; |
| 1829 | } |
| 1830 | |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 1831 | static int w25q_disable_writeprotect(const struct flashctx *flash, |
David Hendricks | 1c09f80 | 2012-10-03 11:03:48 -0700 | [diff] [blame] | 1832 | enum wp_mode wp_mode) |
| 1833 | { |
| 1834 | int ret = 1; |
David Hendricks | 1c09f80 | 2012-10-03 11:03:48 -0700 | [diff] [blame] | 1835 | struct w25q_status_2 sr2; |
| 1836 | uint8_t tmp; |
| 1837 | |
| 1838 | switch (wp_mode) { |
| 1839 | case WP_MODE_HARDWARE: |
| 1840 | ret = w25_set_srp0(flash, 0); |
| 1841 | break; |
| 1842 | case WP_MODE_POWER_CYCLE: |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 1843 | tmp = w25q_read_status_register_2(flash); |
David Hendricks | 1c09f80 | 2012-10-03 11:03:48 -0700 | [diff] [blame] | 1844 | memcpy(&sr2, &tmp, 1); |
| 1845 | if (sr2.srp1) { |
| 1846 | msg_cerr("%s(): must disconnect power to disable " |
| 1847 | "write-protection\n", __func__); |
| 1848 | } else { |
| 1849 | ret = 0; |
| 1850 | } |
| 1851 | break; |
| 1852 | case WP_MODE_PERMANENT: |
| 1853 | msg_cerr("%s(): cannot disable permanent write-protection\n", |
| 1854 | __func__); |
| 1855 | break; |
| 1856 | default: |
| 1857 | msg_cerr("%s(): invalid mode specified\n", __func__); |
| 1858 | break; |
| 1859 | } |
| 1860 | |
| 1861 | if (ret) |
| 1862 | msg_cerr("%s(): error=%d.\n", __func__, ret); |
Edward O'Callaghan | bea239e | 2019-12-04 14:42:54 +1100 | [diff] [blame] | 1863 | |
David Hendricks | 1c09f80 | 2012-10-03 11:03:48 -0700 | [diff] [blame] | 1864 | return ret; |
| 1865 | } |
| 1866 | |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 1867 | static int w25q_disable_writeprotect_default(const struct flashctx *flash) |
David Hendricks | 1c09f80 | 2012-10-03 11:03:48 -0700 | [diff] [blame] | 1868 | { |
| 1869 | return w25q_disable_writeprotect(flash, WP_MODE_HARDWARE); |
| 1870 | } |
| 1871 | |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 1872 | static int w25q_enable_writeprotect(const struct flashctx *flash, |
David Hendricks | 1c09f80 | 2012-10-03 11:03:48 -0700 | [diff] [blame] | 1873 | enum wp_mode wp_mode) |
| 1874 | { |
| 1875 | int ret = 1; |
| 1876 | struct w25q_status sr1; |
| 1877 | struct w25q_status_2 sr2; |
| 1878 | uint8_t tmp; |
| 1879 | |
| 1880 | switch (wp_mode) { |
| 1881 | case WP_MODE_HARDWARE: |
| 1882 | if (w25q_disable_writeprotect(flash, WP_MODE_POWER_CYCLE)) { |
| 1883 | msg_cerr("%s(): cannot disable power cycle WP mode\n", |
| 1884 | __func__); |
| 1885 | break; |
| 1886 | } |
| 1887 | |
Nikolai Artemiev | 48b424b | 2021-04-06 14:12:02 +1000 | [diff] [blame] | 1888 | tmp = spi_read_status_register(flash); |
David Hendricks | 1c09f80 | 2012-10-03 11:03:48 -0700 | [diff] [blame] | 1889 | memcpy(&sr1, &tmp, 1); |
| 1890 | if (sr1.srp0) |
| 1891 | ret = 0; |
| 1892 | else |
| 1893 | ret = w25_set_srp0(flash, 1); |
| 1894 | |
| 1895 | break; |
| 1896 | case WP_MODE_POWER_CYCLE: |
| 1897 | if (w25q_disable_writeprotect(flash, WP_MODE_HARDWARE)) { |
| 1898 | msg_cerr("%s(): cannot disable hardware WP mode\n", |
| 1899 | __func__); |
| 1900 | break; |
| 1901 | } |
| 1902 | |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 1903 | tmp = w25q_read_status_register_2(flash); |
David Hendricks | 1c09f80 | 2012-10-03 11:03:48 -0700 | [diff] [blame] | 1904 | memcpy(&sr2, &tmp, 1); |
| 1905 | if (sr2.srp1) |
| 1906 | ret = 0; |
| 1907 | else |
| 1908 | ret = w25q_set_srp1(flash, 1); |
| 1909 | |
| 1910 | break; |
| 1911 | case WP_MODE_PERMANENT: |
Nikolai Artemiev | 48b424b | 2021-04-06 14:12:02 +1000 | [diff] [blame] | 1912 | tmp = spi_read_status_register(flash); |
David Hendricks | 1c09f80 | 2012-10-03 11:03:48 -0700 | [diff] [blame] | 1913 | memcpy(&sr1, &tmp, 1); |
| 1914 | if (sr1.srp0 == 0) { |
| 1915 | ret = w25_set_srp0(flash, 1); |
| 1916 | if (ret) { |
David Hendricks | f1bd880 | 2012-10-30 11:37:57 -0700 | [diff] [blame] | 1917 | msg_perr("%s(): cannot enable SRP0 for " |
David Hendricks | 1c09f80 | 2012-10-03 11:03:48 -0700 | [diff] [blame] | 1918 | "permanent WP\n", __func__); |
| 1919 | break; |
| 1920 | } |
| 1921 | } |
| 1922 | |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 1923 | tmp = w25q_read_status_register_2(flash); |
David Hendricks | 1c09f80 | 2012-10-03 11:03:48 -0700 | [diff] [blame] | 1924 | memcpy(&sr2, &tmp, 1); |
| 1925 | if (sr2.srp1 == 0) { |
| 1926 | ret = w25q_set_srp1(flash, 1); |
| 1927 | if (ret) { |
David Hendricks | f1bd880 | 2012-10-30 11:37:57 -0700 | [diff] [blame] | 1928 | msg_perr("%s(): cannot enable SRP1 for " |
David Hendricks | 1c09f80 | 2012-10-03 11:03:48 -0700 | [diff] [blame] | 1929 | "permanent WP\n", __func__); |
| 1930 | break; |
| 1931 | } |
| 1932 | } |
| 1933 | |
| 1934 | break; |
David Hendricks | f1bd880 | 2012-10-30 11:37:57 -0700 | [diff] [blame] | 1935 | default: |
| 1936 | msg_perr("%s(): invalid mode %d\n", __func__, wp_mode); |
| 1937 | break; |
David Hendricks | 1c09f80 | 2012-10-03 11:03:48 -0700 | [diff] [blame] | 1938 | } |
| 1939 | |
| 1940 | if (ret) |
| 1941 | msg_cerr("%s(): error=%d.\n", __func__, ret); |
| 1942 | return ret; |
| 1943 | } |
| 1944 | |
| 1945 | /* W25P, W25X, and many flash chips from various vendors */ |
David Hendricks | f7924d1 | 2010-06-10 21:26:44 -0700 | [diff] [blame] | 1946 | struct wp wp_w25 = { |
Nikolai Artemiev | 3b666da | 2021-04-06 16:59:01 +1000 | [diff] [blame] | 1947 | .list_ranges = list_ranges, |
David Hendricks | f7924d1 | 2010-06-10 21:26:44 -0700 | [diff] [blame] | 1948 | .set_range = w25_set_range, |
| 1949 | .enable = w25_enable_writeprotect, |
Louis Yung-Chieh Lo | c19d3c5 | 2010-10-08 11:59:16 +0800 | [diff] [blame] | 1950 | .disable = w25_disable_writeprotect, |
Louis Yung-Chieh Lo | a92e8b2 | 2010-10-08 13:31:27 +0800 | [diff] [blame] | 1951 | .wp_status = w25_wp_status, |
David Hendricks | 1c09f80 | 2012-10-03 11:03:48 -0700 | [diff] [blame] | 1952 | |
| 1953 | }; |
| 1954 | |
| 1955 | /* W25Q series has features such as a second status register and SFDP */ |
| 1956 | struct wp wp_w25q = { |
Nikolai Artemiev | 3b666da | 2021-04-06 16:59:01 +1000 | [diff] [blame] | 1957 | .list_ranges = list_ranges, |
David Hendricks | 1c09f80 | 2012-10-03 11:03:48 -0700 | [diff] [blame] | 1958 | .set_range = w25_set_range, |
| 1959 | .enable = w25q_enable_writeprotect, |
| 1960 | /* |
| 1961 | * By default, disable hardware write-protection. We may change |
| 1962 | * this later if we want to add fine-grained write-protect disable |
| 1963 | * as a command-line option. |
| 1964 | */ |
| 1965 | .disable = w25q_disable_writeprotect_default, |
| 1966 | .wp_status = w25q_wp_status, |
David Hendricks | f7924d1 | 2010-06-10 21:26:44 -0700 | [diff] [blame] | 1967 | }; |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 1968 | |
Duncan Laurie | 1801f7c | 2019-01-09 18:02:51 -0800 | [diff] [blame] | 1969 | /* W25Q large series has 4 block-protect bits */ |
| 1970 | struct wp wp_w25q_large = { |
Nikolai Artemiev | 3b666da | 2021-04-06 16:59:01 +1000 | [diff] [blame] | 1971 | .list_ranges = list_ranges, |
Duncan Laurie | 1801f7c | 2019-01-09 18:02:51 -0800 | [diff] [blame] | 1972 | .set_range = w25q_large_set_range, |
| 1973 | .enable = w25q_enable_writeprotect, |
| 1974 | /* |
| 1975 | * By default, disable hardware write-protection. We may change |
| 1976 | * this later if we want to add fine-grained write-protect disable |
| 1977 | * as a command-line option. |
| 1978 | */ |
| 1979 | .disable = w25q_disable_writeprotect_default, |
| 1980 | .wp_status = w25q_large_wp_status, |
| 1981 | }; |
| 1982 | |
Nikolai Artemiev | 33b9106 | 2021-04-06 16:34:10 +1000 | [diff] [blame] | 1983 | static int get_sr1_layout( |
| 1984 | const struct flashctx *flash, struct status_register_layout *sr1) |
Nikolai Artemiev | 9221c8a | 2021-04-06 15:59:35 +1000 | [diff] [blame] | 1985 | { |
| 1986 | switch (flash->chip->manufacture_id) { |
| 1987 | case GIGADEVICE_ID: |
| 1988 | switch(flash->chip->model_id) { |
| 1989 | |
| 1990 | case GIGADEVICE_GD25Q32: |
Nikolai Artemiev | 33b9106 | 2021-04-06 16:34:10 +1000 | [diff] [blame] | 1991 | *sr1 = gd25q32_sr1; |
Nikolai Artemiev | 9221c8a | 2021-04-06 15:59:35 +1000 | [diff] [blame] | 1992 | return 0; |
| 1993 | case GIGADEVICE_GD25LQ128CD: |
Nikolai Artemiev | 33b9106 | 2021-04-06 16:34:10 +1000 | [diff] [blame] | 1994 | *sr1 = gd25q128_sr1; |
Nikolai Artemiev | 9221c8a | 2021-04-06 15:59:35 +1000 | [diff] [blame] | 1995 | return 0; |
| 1996 | } |
| 1997 | break; |
| 1998 | case MACRONIX_ID: |
| 1999 | switch (flash->chip->model_id) { |
| 2000 | case MACRONIX_MX25L6405: |
Nikolai Artemiev | 33b9106 | 2021-04-06 16:34:10 +1000 | [diff] [blame] | 2001 | *sr1 = mx25l6406e_sr1; |
Nikolai Artemiev | 9221c8a | 2021-04-06 15:59:35 +1000 | [diff] [blame] | 2002 | return 0; |
| 2003 | case MACRONIX_MX25L6495F: |
Nikolai Artemiev | 33b9106 | 2021-04-06 16:34:10 +1000 | [diff] [blame] | 2004 | *sr1 = mx25l6495f_sr1; |
Nikolai Artemiev | 9221c8a | 2021-04-06 15:59:35 +1000 | [diff] [blame] | 2005 | return 0; |
| 2006 | case MACRONIX_MX25L25635F: |
Nikolai Artemiev | 33b9106 | 2021-04-06 16:34:10 +1000 | [diff] [blame] | 2007 | *sr1 = mx25l25635f_sr1; |
Nikolai Artemiev | 9221c8a | 2021-04-06 15:59:35 +1000 | [diff] [blame] | 2008 | return 0; |
| 2009 | } |
| 2010 | break; |
| 2011 | case SPANSION_ID: |
| 2012 | switch (flash->chip->model_id) { |
| 2013 | case SPANSION_S25FS128S_L: |
| 2014 | case SPANSION_S25FS128S_S: |
Nikolai Artemiev | 33b9106 | 2021-04-06 16:34:10 +1000 | [diff] [blame] | 2015 | *sr1 = s25fs128s_sr1; |
Nikolai Artemiev | 9221c8a | 2021-04-06 15:59:35 +1000 | [diff] [blame] | 2016 | return 0; |
| 2017 | case SPANSION_S25FL256S_UL: |
| 2018 | case SPANSION_S25FL256S_US: |
Nikolai Artemiev | 33b9106 | 2021-04-06 16:34:10 +1000 | [diff] [blame] | 2019 | *sr1 = s25fl256s_sr1; |
Nikolai Artemiev | 9221c8a | 2021-04-06 15:59:35 +1000 | [diff] [blame] | 2020 | return 0; |
| 2021 | } |
| 2022 | break; |
| 2023 | } |
| 2024 | |
| 2025 | return 1; |
| 2026 | } |
| 2027 | |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2028 | /* Given a flash chip, this function returns its writeprotect info. */ |
Nikolai Artemiev | 9daffd9 | 2021-04-06 16:54:46 +1000 | [diff] [blame] | 2029 | static int range_table(const struct flashctx *flash, |
Nikolai Artemiev | 9221c8a | 2021-04-06 15:59:35 +1000 | [diff] [blame] | 2030 | struct wp_range_descriptor **descrs, |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2031 | int *num_entries) |
| 2032 | { |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2033 | *num_entries = 0; |
| 2034 | |
Patrick Georgi | f3fa299 | 2017-02-02 16:24:44 +0100 | [diff] [blame] | 2035 | switch (flash->chip->manufacture_id) { |
Nikolai Artemiev | 4b50b5a | 2021-04-06 16:52:34 +1000 | [diff] [blame] | 2036 | case AMIC_ID_NOPREFIX: |
| 2037 | switch(flash->chip->model_id) { |
| 2038 | case AMIC_A25L040: |
| 2039 | *descrs = a25l040_ranges; |
| 2040 | *num_entries = ARRAY_SIZE(a25l040_ranges); |
| 2041 | break; |
| 2042 | default: |
| 2043 | msg_cerr("%s() %d: AMIC flash chip mismatch" |
| 2044 | " (0x%04x), aborting\n", __func__, __LINE__, |
| 2045 | flash->chip->model_id); |
| 2046 | return -1; |
| 2047 | } |
| 2048 | break; |
| 2049 | case ATMEL_ID: |
| 2050 | switch(flash->chip->model_id) { |
| 2051 | case ATMEL_AT25SF128A: |
| 2052 | case ATMEL_AT25SL128A: |
| 2053 | if (w25q_read_status_register_2(flash) & (1 << 6)) { |
| 2054 | /* CMP == 1 */ |
| 2055 | *descrs = w25rq128_cmp1_ranges; |
| 2056 | *num_entries = ARRAY_SIZE(w25rq128_cmp1_ranges); |
| 2057 | } else { |
| 2058 | /* CMP == 0 */ |
| 2059 | *descrs = w25rq128_cmp0_ranges; |
| 2060 | *num_entries = ARRAY_SIZE(w25rq128_cmp0_ranges); |
| 2061 | } |
| 2062 | break; |
| 2063 | default: |
| 2064 | msg_cerr("%s() %d: Atmel flash chip mismatch" |
| 2065 | " (0x%04x), aborting\n", __func__, __LINE__, |
| 2066 | flash->chip->model_id); |
| 2067 | return -1; |
| 2068 | } |
| 2069 | break; |
Nikolai Artemiev | 06afe3e | 2021-04-06 16:40:29 +1000 | [diff] [blame] | 2070 | case WINBOND_NEX_ID: |
| 2071 | switch(flash->chip->model_id) { |
| 2072 | case WINBOND_NEX_W25X10: |
| 2073 | *descrs = w25x10_ranges; |
| 2074 | *num_entries = ARRAY_SIZE(w25x10_ranges); |
| 2075 | break; |
| 2076 | case WINBOND_NEX_W25X20: |
| 2077 | *descrs = w25x20_ranges; |
| 2078 | *num_entries = ARRAY_SIZE(w25x20_ranges); |
| 2079 | break; |
| 2080 | case WINBOND_NEX_W25X40: |
| 2081 | *descrs = w25x40_ranges; |
| 2082 | *num_entries = ARRAY_SIZE(w25x40_ranges); |
| 2083 | break; |
| 2084 | case WINBOND_NEX_W25X80: |
| 2085 | *descrs = w25x80_ranges; |
| 2086 | *num_entries = ARRAY_SIZE(w25x80_ranges); |
| 2087 | break; |
| 2088 | case WINBOND_NEX_W25Q80_V: |
| 2089 | *descrs = w25q80_ranges; |
| 2090 | *num_entries = ARRAY_SIZE(w25q80_ranges); |
| 2091 | break; |
| 2092 | case WINBOND_NEX_W25Q16_V: |
| 2093 | *descrs = w25q16_ranges; |
| 2094 | *num_entries = ARRAY_SIZE(w25q16_ranges); |
| 2095 | break; |
| 2096 | case WINBOND_NEX_W25Q32_V: |
| 2097 | case WINBOND_NEX_W25Q32_W: |
| 2098 | case WINBOND_NEX_W25Q32JW: |
| 2099 | *descrs = w25q32_ranges; |
| 2100 | *num_entries = ARRAY_SIZE(w25q32_ranges); |
| 2101 | break; |
| 2102 | case WINBOND_NEX_W25Q64_V: |
| 2103 | case WINBOND_NEX_W25Q64_W: |
| 2104 | *descrs = w25q64_ranges; |
| 2105 | *num_entries = ARRAY_SIZE(w25q64_ranges); |
| 2106 | break; |
| 2107 | case WINBOND_NEX_W25Q128_DTR: |
| 2108 | case WINBOND_NEX_W25Q128_V_M: |
| 2109 | case WINBOND_NEX_W25Q128_V: |
| 2110 | case WINBOND_NEX_W25Q128_W: |
| 2111 | if (w25q_read_status_register_2(flash) & (1 << 6)) { |
| 2112 | /* CMP == 1 */ |
| 2113 | *descrs = w25rq128_cmp1_ranges; |
| 2114 | *num_entries = ARRAY_SIZE(w25rq128_cmp1_ranges); |
| 2115 | } else { |
| 2116 | /* CMP == 0 */ |
| 2117 | *descrs = w25rq128_cmp0_ranges; |
| 2118 | *num_entries = ARRAY_SIZE(w25rq128_cmp0_ranges); |
| 2119 | } |
| 2120 | break; |
| 2121 | case WINBOND_NEX_W25Q256_V: |
| 2122 | case WINBOND_NEX_W25Q256JV_M: |
| 2123 | if (w25q_read_status_register_2(flash) & (1 << 6)) { |
| 2124 | /* CMP == 1 */ |
| 2125 | *descrs = w25rq256_cmp1_ranges; |
| 2126 | *num_entries = ARRAY_SIZE(w25rq256_cmp1_ranges); |
| 2127 | } else { |
| 2128 | /* CMP == 0 */ |
| 2129 | *descrs = w25rq256_cmp0_ranges; |
| 2130 | *num_entries = ARRAY_SIZE(w25rq256_cmp0_ranges); |
| 2131 | } |
| 2132 | break; |
| 2133 | default: |
| 2134 | msg_cerr("%s() %d: WINBOND flash chip mismatch (0x%04x)" |
| 2135 | ", aborting\n", __func__, __LINE__, |
| 2136 | flash->chip->model_id); |
| 2137 | return -1; |
| 2138 | } |
| 2139 | break; |
| 2140 | |
Nikolai Artemiev | 12a84fa | 2021-04-06 16:41:56 +1000 | [diff] [blame] | 2141 | case EON_ID_NOPREFIX: |
| 2142 | switch (flash->chip->model_id) { |
| 2143 | case EON_EN25F40: |
| 2144 | *descrs = en25f40_ranges; |
| 2145 | *num_entries = ARRAY_SIZE(en25f40_ranges); |
| 2146 | break; |
| 2147 | case EON_EN25Q40: |
| 2148 | *descrs = en25q40_ranges; |
| 2149 | *num_entries = ARRAY_SIZE(en25q40_ranges); |
| 2150 | break; |
| 2151 | case EON_EN25Q80: |
| 2152 | *descrs = en25q80_ranges; |
| 2153 | *num_entries = ARRAY_SIZE(en25q80_ranges); |
| 2154 | break; |
| 2155 | case EON_EN25Q32: |
| 2156 | *descrs = en25q32_ranges; |
| 2157 | *num_entries = ARRAY_SIZE(en25q32_ranges); |
| 2158 | break; |
| 2159 | case EON_EN25Q64: |
| 2160 | *descrs = en25q64_ranges; |
| 2161 | *num_entries = ARRAY_SIZE(en25q64_ranges); |
| 2162 | break; |
| 2163 | case EON_EN25Q128: |
| 2164 | *descrs = en25q128_ranges; |
| 2165 | *num_entries = ARRAY_SIZE(en25q128_ranges); |
| 2166 | break; |
| 2167 | case EON_EN25QH128: |
| 2168 | if (w25q_read_status_register_2(flash) & (1 << 6)) { |
| 2169 | /* CMP == 1 */ |
| 2170 | *descrs = w25rq128_cmp1_ranges; |
| 2171 | *num_entries = ARRAY_SIZE(w25rq128_cmp1_ranges); |
| 2172 | } else { |
| 2173 | /* CMP == 0 */ |
| 2174 | *descrs = w25rq128_cmp0_ranges; |
| 2175 | *num_entries = ARRAY_SIZE(w25rq128_cmp0_ranges); |
| 2176 | } |
| 2177 | break; |
| 2178 | case EON_EN25S64: |
| 2179 | *descrs = en25s64_ranges; |
| 2180 | *num_entries = ARRAY_SIZE(en25s64_ranges); |
| 2181 | break; |
| 2182 | default: |
| 2183 | msg_cerr("%s():%d: EON flash chip mismatch (0x%04x)" |
| 2184 | ", aborting\n", __func__, __LINE__, |
| 2185 | flash->chip->model_id); |
| 2186 | return -1; |
| 2187 | } |
| 2188 | break; |
| 2189 | |
David Hendricks | af3944a | 2014-07-28 18:37:40 -0700 | [diff] [blame] | 2190 | case GIGADEVICE_ID: |
Patrick Georgi | f3fa299 | 2017-02-02 16:24:44 +0100 | [diff] [blame] | 2191 | switch(flash->chip->model_id) { |
David Hendricks | 1e9d7ca | 2016-03-14 15:50:34 -0700 | [diff] [blame] | 2192 | |
David Hendricks | af3944a | 2014-07-28 18:37:40 -0700 | [diff] [blame] | 2193 | case GIGADEVICE_GD25Q32: { |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 2194 | uint8_t sr1 = w25q_read_status_register_2(flash); |
David Hendricks | 1e9d7ca | 2016-03-14 15:50:34 -0700 | [diff] [blame] | 2195 | |
David Hendricks | af3944a | 2014-07-28 18:37:40 -0700 | [diff] [blame] | 2196 | if (!(sr1 & (1 << 6))) { /* CMP == 0 */ |
Nikolai Artemiev | 9221c8a | 2021-04-06 15:59:35 +1000 | [diff] [blame] | 2197 | *descrs = &gd25q32_cmp0_ranges[0]; |
David Hendricks | af3944a | 2014-07-28 18:37:40 -0700 | [diff] [blame] | 2198 | *num_entries = ARRAY_SIZE(gd25q32_cmp0_ranges); |
| 2199 | } else { /* CMP == 1 */ |
Nikolai Artemiev | 9221c8a | 2021-04-06 15:59:35 +1000 | [diff] [blame] | 2200 | *descrs = &gd25q32_cmp1_ranges[0]; |
David Hendricks | af3944a | 2014-07-28 18:37:40 -0700 | [diff] [blame] | 2201 | *num_entries = ARRAY_SIZE(gd25q32_cmp1_ranges); |
| 2202 | } |
| 2203 | |
| 2204 | break; |
David Hendricks | 1e9d7ca | 2016-03-14 15:50:34 -0700 | [diff] [blame] | 2205 | } |
Aaron Durbin | 6c957d7 | 2018-08-20 09:31:01 -0600 | [diff] [blame] | 2206 | case GIGADEVICE_GD25LQ128CD: { |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 2207 | uint8_t sr1 = w25q_read_status_register_2(flash); |
David Hendricks | 1e9d7ca | 2016-03-14 15:50:34 -0700 | [diff] [blame] | 2208 | |
| 2209 | if (!(sr1 & (1 << 6))) { /* CMP == 0 */ |
Nikolai Artemiev | 9221c8a | 2021-04-06 15:59:35 +1000 | [diff] [blame] | 2210 | *descrs = &gd25q128_cmp0_ranges[0]; |
David Hendricks | 1e9d7ca | 2016-03-14 15:50:34 -0700 | [diff] [blame] | 2211 | *num_entries = ARRAY_SIZE(gd25q128_cmp0_ranges); |
| 2212 | } else { /* CMP == 1 */ |
Nikolai Artemiev | 9221c8a | 2021-04-06 15:59:35 +1000 | [diff] [blame] | 2213 | *descrs = &gd25q128_cmp1_ranges[0]; |
David Hendricks | 1e9d7ca | 2016-03-14 15:50:34 -0700 | [diff] [blame] | 2214 | *num_entries = ARRAY_SIZE(gd25q128_cmp1_ranges); |
| 2215 | } |
| 2216 | |
| 2217 | break; |
David Hendricks | af3944a | 2014-07-28 18:37:40 -0700 | [diff] [blame] | 2218 | } |
Nikolai Artemiev | acada71 | 2021-04-06 16:50:04 +1000 | [diff] [blame] | 2219 | case GIGADEVICE_GD25LQ32: |
| 2220 | *descrs = w25q32_ranges; |
| 2221 | *num_entries = ARRAY_SIZE(w25q32_ranges); |
| 2222 | break; |
| 2223 | case GIGADEVICE_GD25Q40: |
| 2224 | if (w25q_read_status_register_2(flash) & (1 << 6)) { |
| 2225 | /* CMP == 1 */ |
| 2226 | *descrs = gd25q40_cmp1_ranges; |
| 2227 | *num_entries = ARRAY_SIZE(gd25q40_cmp1_ranges); |
| 2228 | } else { |
| 2229 | *descrs = gd25q40_cmp0_ranges; |
| 2230 | *num_entries = ARRAY_SIZE(gd25q40_cmp0_ranges); |
| 2231 | } |
| 2232 | break; |
| 2233 | case GIGADEVICE_GD25Q64: |
| 2234 | case GIGADEVICE_GD25LQ64: |
| 2235 | *descrs = gd25q64_ranges; |
| 2236 | *num_entries = ARRAY_SIZE(gd25q64_ranges); |
| 2237 | break; |
| 2238 | case GIGADEVICE_GD25Q128: |
| 2239 | if (w25q_read_status_register_2(flash) & (1 << 6)) { |
| 2240 | /* CMP == 1 */ |
| 2241 | *descrs = w25rq128_cmp1_ranges; |
| 2242 | *num_entries = ARRAY_SIZE(w25rq128_cmp1_ranges); |
| 2243 | } else { |
| 2244 | /* CMP == 0 */ |
| 2245 | *descrs = w25rq128_cmp0_ranges; |
| 2246 | *num_entries = ARRAY_SIZE(w25rq128_cmp0_ranges); |
| 2247 | } |
| 2248 | break; |
| 2249 | case GIGADEVICE_GD25Q256D: |
| 2250 | *descrs = w25rq256_cmp0_ranges; |
| 2251 | *num_entries = ARRAY_SIZE(w25rq256_cmp0_ranges); |
| 2252 | break; |
David Hendricks | af3944a | 2014-07-28 18:37:40 -0700 | [diff] [blame] | 2253 | default: |
| 2254 | msg_cerr("%s() %d: GigaDevice flash chip mismatch" |
| 2255 | " (0x%04x), aborting\n", __func__, __LINE__, |
Patrick Georgi | f3fa299 | 2017-02-02 16:24:44 +0100 | [diff] [blame] | 2256 | flash->chip->model_id); |
David Hendricks | af3944a | 2014-07-28 18:37:40 -0700 | [diff] [blame] | 2257 | return -1; |
| 2258 | } |
| 2259 | break; |
David Hendricks | 83541d3 | 2014-07-15 20:58:21 -0700 | [diff] [blame] | 2260 | case MACRONIX_ID: |
Patrick Georgi | f3fa299 | 2017-02-02 16:24:44 +0100 | [diff] [blame] | 2261 | switch (flash->chip->model_id) { |
David Hendricks | 83541d3 | 2014-07-15 20:58:21 -0700 | [diff] [blame] | 2262 | case MACRONIX_MX25L6405: |
| 2263 | /* FIXME: MX25L64* chips have mixed capabilities and |
| 2264 | share IDs */ |
Nikolai Artemiev | 9221c8a | 2021-04-06 15:59:35 +1000 | [diff] [blame] | 2265 | *descrs = &mx25l6406e_ranges[0]; |
David Hendricks | 83541d3 | 2014-07-15 20:58:21 -0700 | [diff] [blame] | 2266 | *num_entries = ARRAY_SIZE(mx25l6406e_ranges); |
| 2267 | break; |
David Hendricks | c349609 | 2014-11-13 17:20:55 -0800 | [diff] [blame] | 2268 | case MACRONIX_MX25L6495F: { |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 2269 | uint8_t cr = mx25l_read_config_register(flash); |
David Hendricks | c349609 | 2014-11-13 17:20:55 -0800 | [diff] [blame] | 2270 | |
David Hendricks | c349609 | 2014-11-13 17:20:55 -0800 | [diff] [blame] | 2271 | if (!(cr & (1 << 3))) { /* T/B == 0 */ |
Nikolai Artemiev | 9221c8a | 2021-04-06 15:59:35 +1000 | [diff] [blame] | 2272 | *descrs = &mx25l6495f_tb0_ranges[0]; |
David Hendricks | c349609 | 2014-11-13 17:20:55 -0800 | [diff] [blame] | 2273 | *num_entries = ARRAY_SIZE(mx25l6495f_tb0_ranges); |
| 2274 | } else { /* T/B == 1 */ |
Nikolai Artemiev | 9221c8a | 2021-04-06 15:59:35 +1000 | [diff] [blame] | 2275 | *descrs = &mx25l6495f_tb1_ranges[0]; |
David Hendricks | c349609 | 2014-11-13 17:20:55 -0800 | [diff] [blame] | 2276 | *num_entries = ARRAY_SIZE(mx25l6495f_tb1_ranges); |
| 2277 | } |
| 2278 | break; |
| 2279 | } |
Vic Yang | 848bfd1 | 2018-03-23 10:24:07 -0700 | [diff] [blame] | 2280 | case MACRONIX_MX25L25635F: { |
| 2281 | uint8_t cr = mx25l_read_config_register(flash); |
| 2282 | |
Vic Yang | 848bfd1 | 2018-03-23 10:24:07 -0700 | [diff] [blame] | 2283 | if (!(cr & (1 << 3))) { /* T/B == 0 */ |
Nikolai Artemiev | 9221c8a | 2021-04-06 15:59:35 +1000 | [diff] [blame] | 2284 | *descrs = &mx25l25635f_tb0_ranges[0]; |
Vic Yang | 848bfd1 | 2018-03-23 10:24:07 -0700 | [diff] [blame] | 2285 | *num_entries = ARRAY_SIZE(mx25l25635f_tb0_ranges); |
| 2286 | } else { /* T/B == 1 */ |
Nikolai Artemiev | 9221c8a | 2021-04-06 15:59:35 +1000 | [diff] [blame] | 2287 | *descrs = &mx25l25635f_tb1_ranges[0]; |
Vic Yang | 848bfd1 | 2018-03-23 10:24:07 -0700 | [diff] [blame] | 2288 | *num_entries = ARRAY_SIZE(mx25l25635f_tb1_ranges); |
| 2289 | } |
| 2290 | break; |
Nikolai Artemiev | 0e560ae | 2021-04-06 16:45:00 +1000 | [diff] [blame] | 2291 | } |
| 2292 | case MACRONIX_MX25L1005: |
| 2293 | *descrs = mx25l1005_ranges; |
| 2294 | *num_entries = ARRAY_SIZE(mx25l1005_ranges); |
| 2295 | break; |
| 2296 | case MACRONIX_MX25L2005: |
| 2297 | *descrs = mx25l2005_ranges; |
| 2298 | *num_entries = ARRAY_SIZE(mx25l2005_ranges); |
| 2299 | break; |
| 2300 | case MACRONIX_MX25L4005: |
| 2301 | *descrs = mx25l4005_ranges; |
| 2302 | *num_entries = ARRAY_SIZE(mx25l4005_ranges); |
| 2303 | break; |
| 2304 | case MACRONIX_MX25L8005: |
| 2305 | *descrs = mx25l8005_ranges; |
| 2306 | *num_entries = ARRAY_SIZE(mx25l8005_ranges); |
| 2307 | break; |
| 2308 | case MACRONIX_MX25L1605: |
| 2309 | /* FIXME: MX25L1605 and MX25L1605D have different write |
| 2310 | * protection capabilities, but share IDs */ |
| 2311 | *descrs = mx25l1605d_ranges; |
| 2312 | *num_entries = ARRAY_SIZE(mx25l1605d_ranges); |
| 2313 | break; |
| 2314 | case MACRONIX_MX25L3205: |
| 2315 | *descrs = mx25l3205d_ranges; |
| 2316 | *num_entries = ARRAY_SIZE(mx25l3205d_ranges); |
| 2317 | break; |
| 2318 | case MACRONIX_MX25U3235E: |
| 2319 | *descrs = mx25u3235e_ranges; |
| 2320 | *num_entries = ARRAY_SIZE(mx25u3235e_ranges); |
| 2321 | break; |
| 2322 | case MACRONIX_MX25U6435E: |
| 2323 | *descrs = mx25u6435e_ranges; |
| 2324 | *num_entries = ARRAY_SIZE(mx25u6435e_ranges); |
| 2325 | break; |
| 2326 | case MACRONIX_MX25U12835E: { |
| 2327 | uint8_t cr = mx25l_read_config_register(flash); |
| 2328 | if (cr & MX25U12835E_TB) { /* T/B == 1 */ |
| 2329 | *descrs = mx25u12835e_tb1_ranges; |
| 2330 | *num_entries = ARRAY_SIZE(mx25u12835e_tb1_ranges); |
| 2331 | } else { /* T/B == 0 */ |
| 2332 | *descrs = mx25u12835e_tb0_ranges; |
| 2333 | *num_entries = ARRAY_SIZE(mx25u12835e_tb0_ranges); |
| 2334 | } |
| 2335 | } |
| 2336 | break; |
David Hendricks | 83541d3 | 2014-07-15 20:58:21 -0700 | [diff] [blame] | 2337 | default: |
| 2338 | msg_cerr("%s():%d: MXIC flash chip mismatch (0x%04x)" |
| 2339 | ", aborting\n", __func__, __LINE__, |
Patrick Georgi | f3fa299 | 2017-02-02 16:24:44 +0100 | [diff] [blame] | 2340 | flash->chip->model_id); |
David Hendricks | 83541d3 | 2014-07-15 20:58:21 -0700 | [diff] [blame] | 2341 | return -1; |
| 2342 | } |
| 2343 | break; |
Nikolai Artemiev | 158b370 | 2021-04-06 16:46:06 +1000 | [diff] [blame] | 2344 | case ST_ID: |
| 2345 | switch(flash->chip->model_id) { |
| 2346 | case ST_N25Q064__1E: |
| 2347 | case ST_N25Q064__3E: |
| 2348 | *descrs = n25q064_ranges; |
| 2349 | *num_entries = ARRAY_SIZE(n25q064_ranges); |
| 2350 | break; |
| 2351 | default: |
| 2352 | msg_cerr("%s() %d: Micron flash chip mismatch" |
| 2353 | " (0x%04x), aborting\n", __func__, __LINE__, |
| 2354 | flash->chip->model_id); |
| 2355 | return -1; |
| 2356 | } |
| 2357 | break; |
David Hendricks | a988485 | 2014-12-11 15:31:12 -0800 | [diff] [blame] | 2358 | case SPANSION_ID: |
Patrick Georgi | f3fa299 | 2017-02-02 16:24:44 +0100 | [diff] [blame] | 2359 | switch (flash->chip->model_id) { |
David Hendricks | a988485 | 2014-12-11 15:31:12 -0800 | [diff] [blame] | 2360 | case SPANSION_S25FS128S_L: |
| 2361 | case SPANSION_S25FS128S_S: { |
Nikolai Artemiev | 9221c8a | 2021-04-06 15:59:35 +1000 | [diff] [blame] | 2362 | *descrs = s25fs128s_ranges; |
David Hendricks | 148a4bf | 2015-03-13 21:02:42 -0700 | [diff] [blame] | 2363 | *num_entries = ARRAY_SIZE(s25fs128s_ranges); |
David Hendricks | a988485 | 2014-12-11 15:31:12 -0800 | [diff] [blame] | 2364 | break; |
| 2365 | } |
David Hendricks | c694bb8 | 2015-02-25 14:52:17 -0800 | [diff] [blame] | 2366 | case SPANSION_S25FL256S_UL: |
| 2367 | case SPANSION_S25FL256S_US: { |
Nikolai Artemiev | 9221c8a | 2021-04-06 15:59:35 +1000 | [diff] [blame] | 2368 | *descrs = s25fl256s_ranges; |
David Hendricks | 148a4bf | 2015-03-13 21:02:42 -0700 | [diff] [blame] | 2369 | *num_entries = ARRAY_SIZE(s25fl256s_ranges); |
David Hendricks | c694bb8 | 2015-02-25 14:52:17 -0800 | [diff] [blame] | 2370 | break; |
| 2371 | } |
David Hendricks | a988485 | 2014-12-11 15:31:12 -0800 | [diff] [blame] | 2372 | default: |
| 2373 | msg_cerr("%s():%d Spansion flash chip mismatch (0x%04x)" |
Patrick Georgi | f3fa299 | 2017-02-02 16:24:44 +0100 | [diff] [blame] | 2374 | ", aborting\n", __func__, __LINE__, |
| 2375 | flash->chip->model_id); |
David Hendricks | a988485 | 2014-12-11 15:31:12 -0800 | [diff] [blame] | 2376 | return -1; |
| 2377 | } |
| 2378 | break; |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2379 | default: |
| 2380 | msg_cerr("%s: flash vendor (0x%x) not found, aborting\n", |
Patrick Georgi | f3fa299 | 2017-02-02 16:24:44 +0100 | [diff] [blame] | 2381 | __func__, flash->chip->manufacture_id); |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2382 | return -1; |
| 2383 | } |
| 2384 | |
| 2385 | return 0; |
| 2386 | } |
| 2387 | |
Nikolai Artemiev | 9b0c3ec | 2021-04-06 15:56:36 +1000 | [diff] [blame] | 2388 | /* Determines if special s25f-specific functions need to be used to access a |
| 2389 | * given chip's modifier bits. Very much a hard-coded special case hack, but it |
| 2390 | * is also very easy to replace once a proper abstraction for accessing |
| 2391 | * specific modifier bits is added. */ |
| 2392 | static int use_s25f_modifier_bits(const struct flashctx *flash) |
| 2393 | { |
| 2394 | bool model_match = |
| 2395 | flash->chip->model_id == SPANSION_S25FS128S_L || |
| 2396 | flash->chip->model_id == SPANSION_S25FS128S_S || |
| 2397 | flash->chip->model_id == SPANSION_S25FL256S_UL || |
| 2398 | flash->chip->model_id == SPANSION_S25FL256S_US; |
| 2399 | return (flash->chip->manufacture_id == SPANSION_ID) && model_match; |
| 2400 | } |
| 2401 | |
Nikolai Artemiev | 33b9106 | 2021-04-06 16:34:10 +1000 | [diff] [blame] | 2402 | static uint8_t generic_get_bp_mask(struct status_register_layout sr1) |
Marco Chen | 9d5bddb | 2020-02-11 17:12:56 +0800 | [diff] [blame] | 2403 | { |
Nikolai Artemiev | 33b9106 | 2021-04-06 16:34:10 +1000 | [diff] [blame] | 2404 | return ((1 << (sr1.bp0_pos + sr1.bp_bits)) - 1) ^ \ |
| 2405 | ((1 << sr1.bp0_pos) - 1); |
Marco Chen | 9d5bddb | 2020-02-11 17:12:56 +0800 | [diff] [blame] | 2406 | } |
| 2407 | |
Nikolai Artemiev | 33b9106 | 2021-04-06 16:34:10 +1000 | [diff] [blame] | 2408 | static uint8_t generic_get_status_check_mask(struct status_register_layout sr1) |
Marco Chen | 9d5bddb | 2020-02-11 17:12:56 +0800 | [diff] [blame] | 2409 | { |
Nikolai Artemiev | 33b9106 | 2021-04-06 16:34:10 +1000 | [diff] [blame] | 2410 | return generic_get_bp_mask(sr1) | 1 << sr1.srp_pos; |
Marco Chen | 9d5bddb | 2020-02-11 17:12:56 +0800 | [diff] [blame] | 2411 | } |
| 2412 | |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2413 | /* Given a [start, len], this function finds a block protect bit combination |
| 2414 | * (if possible) and sets the corresponding bits in "status". Remaining bits |
| 2415 | * are preserved. */ |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 2416 | static int generic_range_to_status(const struct flashctx *flash, |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2417 | unsigned int start, unsigned int len, |
Marco Chen | 9d5bddb | 2020-02-11 17:12:56 +0800 | [diff] [blame] | 2418 | uint8_t *status, uint8_t *check_mask) |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2419 | { |
Nikolai Artemiev | 33b9106 | 2021-04-06 16:34:10 +1000 | [diff] [blame] | 2420 | struct status_register_layout sr1; |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 2421 | struct wp_range_descriptor *r; |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2422 | int i, range_found = 0, num_entries; |
| 2423 | uint8_t bp_mask; |
| 2424 | |
Nikolai Artemiev | 33b9106 | 2021-04-06 16:34:10 +1000 | [diff] [blame] | 2425 | if (get_sr1_layout(flash, &sr1)) |
Nikolai Artemiev | 9221c8a | 2021-04-06 15:59:35 +1000 | [diff] [blame] | 2426 | return -1; |
| 2427 | |
Nikolai Artemiev | 9daffd9 | 2021-04-06 16:54:46 +1000 | [diff] [blame] | 2428 | if (range_table(flash, &r, &num_entries)) |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2429 | return -1; |
| 2430 | |
Nikolai Artemiev | 33b9106 | 2021-04-06 16:34:10 +1000 | [diff] [blame] | 2431 | bp_mask = generic_get_bp_mask(sr1); |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2432 | |
Nikolai Artemiev | 9221c8a | 2021-04-06 15:59:35 +1000 | [diff] [blame] | 2433 | for (i = 0; i < num_entries; i++, r++) { |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2434 | msg_cspew("comparing range 0x%x 0x%x / 0x%x 0x%x\n", |
| 2435 | start, len, r->range.start, r->range.len); |
| 2436 | if ((start == r->range.start) && (len == r->range.len)) { |
| 2437 | *status &= ~(bp_mask); |
Nikolai Artemiev | 33b9106 | 2021-04-06 16:34:10 +1000 | [diff] [blame] | 2438 | *status |= r->bp << (sr1.bp0_pos); |
David Hendricks | 148a4bf | 2015-03-13 21:02:42 -0700 | [diff] [blame] | 2439 | |
Nikolai Artemiev | 9b0c3ec | 2021-04-06 15:56:36 +1000 | [diff] [blame] | 2440 | if (use_s25f_modifier_bits(flash)) { |
| 2441 | if (s25f_set_modifier_bits(flash, &r->m) < 0) { |
Edward O'Callaghan | 0b662c1 | 2021-01-22 00:30:24 +1100 | [diff] [blame] | 2442 | msg_cerr("error setting modifier bits for range.\n"); |
David Hendricks | 148a4bf | 2015-03-13 21:02:42 -0700 | [diff] [blame] | 2443 | return -1; |
| 2444 | } |
| 2445 | } |
| 2446 | |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2447 | range_found = 1; |
| 2448 | break; |
| 2449 | } |
| 2450 | } |
| 2451 | |
| 2452 | if (!range_found) { |
Edward O'Callaghan | 3be63e0 | 2020-03-27 14:44:24 +1100 | [diff] [blame] | 2453 | msg_cerr("%s: matching range not found\n", __func__); |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2454 | return -1; |
| 2455 | } |
Edward O'Callaghan | bea239e | 2019-12-04 14:42:54 +1100 | [diff] [blame] | 2456 | |
Nikolai Artemiev | 33b9106 | 2021-04-06 16:34:10 +1000 | [diff] [blame] | 2457 | *check_mask = generic_get_status_check_mask(sr1); |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2458 | return 0; |
| 2459 | } |
| 2460 | |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 2461 | static int generic_status_to_range(const struct flashctx *flash, |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2462 | const uint8_t sr1, unsigned int *start, unsigned int *len) |
| 2463 | { |
Nikolai Artemiev | 33b9106 | 2021-04-06 16:34:10 +1000 | [diff] [blame] | 2464 | struct status_register_layout sr1_layout; |
Edward O'Callaghan | e146f9a | 2019-12-05 14:27:24 +1100 | [diff] [blame] | 2465 | struct wp_range_descriptor *r; |
Duncan Laurie | 04ca117 | 2015-03-12 09:25:34 -0700 | [diff] [blame] | 2466 | int num_entries, i, status_found = 0; |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2467 | uint8_t sr1_bp; |
Edward O'Callaghan | 9c4c9a5 | 2019-12-04 18:18:01 +1100 | [diff] [blame] | 2468 | struct modifier_bits m; |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2469 | |
Nikolai Artemiev | 33b9106 | 2021-04-06 16:34:10 +1000 | [diff] [blame] | 2470 | if (get_sr1_layout(flash, &sr1_layout)) |
Nikolai Artemiev | 9221c8a | 2021-04-06 15:59:35 +1000 | [diff] [blame] | 2471 | return -1; |
| 2472 | |
Nikolai Artemiev | 9daffd9 | 2021-04-06 16:54:46 +1000 | [diff] [blame] | 2473 | if (range_table(flash, &r, &num_entries)) |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2474 | return -1; |
| 2475 | |
David Hendricks | 148a4bf | 2015-03-13 21:02:42 -0700 | [diff] [blame] | 2476 | /* modifier bits may be compared more than once, so get them here */ |
Nikolai Artemiev | 9b0c3ec | 2021-04-06 15:56:36 +1000 | [diff] [blame] | 2477 | if (use_s25f_modifier_bits(flash) && s25f_get_modifier_bits(flash, &m) < 0) |
| 2478 | return -1; |
David Hendricks | 148a4bf | 2015-03-13 21:02:42 -0700 | [diff] [blame] | 2479 | |
Nikolai Artemiev | 33b9106 | 2021-04-06 16:34:10 +1000 | [diff] [blame] | 2480 | sr1_bp = (sr1 >> sr1_layout.bp0_pos) & ((1 << sr1_layout.bp_bits) - 1); |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2481 | |
Nikolai Artemiev | 9221c8a | 2021-04-06 15:59:35 +1000 | [diff] [blame] | 2482 | for (i = 0; i < num_entries; i++, r++) { |
Nikolai Artemiev | 9b0c3ec | 2021-04-06 15:56:36 +1000 | [diff] [blame] | 2483 | if (use_s25f_modifier_bits(flash)) { |
David Hendricks | 148a4bf | 2015-03-13 21:02:42 -0700 | [diff] [blame] | 2484 | if (memcmp(&m, &r->m, sizeof(m))) |
| 2485 | continue; |
| 2486 | } |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2487 | msg_cspew("comparing 0x%02x 0x%02x\n", sr1_bp, r->bp); |
| 2488 | if (sr1_bp == r->bp) { |
| 2489 | *start = r->range.start; |
| 2490 | *len = r->range.len; |
| 2491 | status_found = 1; |
| 2492 | break; |
| 2493 | } |
| 2494 | } |
| 2495 | |
| 2496 | if (!status_found) { |
| 2497 | msg_cerr("matching status not found\n"); |
| 2498 | return -1; |
| 2499 | } |
Edward O'Callaghan | bea239e | 2019-12-04 14:42:54 +1100 | [diff] [blame] | 2500 | |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2501 | return 0; |
| 2502 | } |
| 2503 | |
| 2504 | /* Given a [start, len], this function calls generic_range_to_status() to |
| 2505 | * convert it to flash-chip-specific range bits, then sets into status register. |
| 2506 | */ |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 2507 | static int generic_set_range(const struct flashctx *flash, |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2508 | unsigned int start, unsigned int len) |
| 2509 | { |
Marco Chen | 9d5bddb | 2020-02-11 17:12:56 +0800 | [diff] [blame] | 2510 | uint8_t status, expected, check_mask; |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2511 | |
Nikolai Artemiev | 48b424b | 2021-04-06 14:12:02 +1000 | [diff] [blame] | 2512 | status = spi_read_status_register(flash); |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2513 | msg_cdbg("%s: old status: 0x%02x\n", __func__, status); |
| 2514 | |
| 2515 | expected = status; /* preserve non-bp bits */ |
Marco Chen | 9d5bddb | 2020-02-11 17:12:56 +0800 | [diff] [blame] | 2516 | if (generic_range_to_status(flash, start, len, &expected, &check_mask)) |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2517 | return -1; |
| 2518 | |
Nikolai Artemiev | 48b424b | 2021-04-06 14:12:02 +1000 | [diff] [blame] | 2519 | spi_write_status_register(flash, expected); |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2520 | |
Nikolai Artemiev | 48b424b | 2021-04-06 14:12:02 +1000 | [diff] [blame] | 2521 | status = spi_read_status_register(flash); |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2522 | msg_cdbg("%s: new status: 0x%02x\n", __func__, status); |
Marco Chen | 9d5bddb | 2020-02-11 17:12:56 +0800 | [diff] [blame] | 2523 | if ((status & check_mask) != (expected & check_mask)) { |
| 2524 | msg_cerr("expected=0x%02x, but actual=0x%02x. check mask=0x%02x\n", |
| 2525 | expected, status, check_mask); |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2526 | return 1; |
| 2527 | } |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2528 | return 0; |
| 2529 | } |
| 2530 | |
| 2531 | /* Set/clear the status regsiter write protect bit in SR1. */ |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 2532 | static int generic_set_srp0(const struct flashctx *flash, int enable) |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2533 | { |
Marco Chen | 9d5bddb | 2020-02-11 17:12:56 +0800 | [diff] [blame] | 2534 | uint8_t status, expected, check_mask; |
Nikolai Artemiev | 33b9106 | 2021-04-06 16:34:10 +1000 | [diff] [blame] | 2535 | struct status_register_layout sr1; |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2536 | |
Nikolai Artemiev | 33b9106 | 2021-04-06 16:34:10 +1000 | [diff] [blame] | 2537 | if (get_sr1_layout(flash, &sr1)) |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2538 | return -1; |
| 2539 | |
Nikolai Artemiev | 48b424b | 2021-04-06 14:12:02 +1000 | [diff] [blame] | 2540 | expected = spi_read_status_register(flash); |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2541 | msg_cdbg("%s: old status: 0x%02x\n", __func__, expected); |
| 2542 | |
| 2543 | if (enable) |
Nikolai Artemiev | 33b9106 | 2021-04-06 16:34:10 +1000 | [diff] [blame] | 2544 | expected |= 1 << sr1.srp_pos; |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2545 | else |
Nikolai Artemiev | 33b9106 | 2021-04-06 16:34:10 +1000 | [diff] [blame] | 2546 | expected &= ~(1 << sr1.srp_pos); |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2547 | |
Nikolai Artemiev | 48b424b | 2021-04-06 14:12:02 +1000 | [diff] [blame] | 2548 | spi_write_status_register(flash, expected); |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2549 | |
Nikolai Artemiev | 48b424b | 2021-04-06 14:12:02 +1000 | [diff] [blame] | 2550 | status = spi_read_status_register(flash); |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2551 | msg_cdbg("%s: new status: 0x%02x\n", __func__, status); |
Marco Chen | 9d5bddb | 2020-02-11 17:12:56 +0800 | [diff] [blame] | 2552 | |
Nikolai Artemiev | 33b9106 | 2021-04-06 16:34:10 +1000 | [diff] [blame] | 2553 | check_mask = generic_get_status_check_mask(sr1); |
Marco Chen | 9d5bddb | 2020-02-11 17:12:56 +0800 | [diff] [blame] | 2554 | msg_cdbg("%s: check mask: 0x%02x\n", __func__, check_mask); |
| 2555 | if ((status & check_mask) != (expected & check_mask)) { |
| 2556 | msg_cerr("expected=0x%02x, but actual=0x%02x. check mask=0x%02x\n", |
| 2557 | expected, status, check_mask); |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2558 | return -1; |
Marco Chen | 9d5bddb | 2020-02-11 17:12:56 +0800 | [diff] [blame] | 2559 | } |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2560 | |
| 2561 | return 0; |
| 2562 | } |
| 2563 | |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 2564 | static int generic_enable_writeprotect(const struct flashctx *flash, |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2565 | enum wp_mode wp_mode) |
| 2566 | { |
| 2567 | int ret; |
| 2568 | |
Edward O'Callaghan | ca44e5c | 2019-12-04 14:23:54 +1100 | [diff] [blame] | 2569 | if (wp_mode != WP_MODE_HARDWARE) { |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2570 | msg_cerr("%s(): unsupported write-protect mode\n", __func__); |
| 2571 | return 1; |
| 2572 | } |
| 2573 | |
Edward O'Callaghan | ca44e5c | 2019-12-04 14:23:54 +1100 | [diff] [blame] | 2574 | ret = generic_set_srp0(flash, 1); |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2575 | if (ret) |
| 2576 | msg_cerr("%s(): error=%d.\n", __func__, ret); |
Edward O'Callaghan | ca44e5c | 2019-12-04 14:23:54 +1100 | [diff] [blame] | 2577 | |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2578 | return ret; |
| 2579 | } |
| 2580 | |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 2581 | static int generic_disable_writeprotect(const struct flashctx *flash) |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2582 | { |
| 2583 | int ret; |
| 2584 | |
| 2585 | ret = generic_set_srp0(flash, 0); |
| 2586 | if (ret) |
| 2587 | msg_cerr("%s(): error=%d.\n", __func__, ret); |
Edward O'Callaghan | bea239e | 2019-12-04 14:42:54 +1100 | [diff] [blame] | 2588 | |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2589 | return ret; |
| 2590 | } |
| 2591 | |
Edward O'Callaghan | a3edcb2 | 2019-12-05 14:30:50 +1100 | [diff] [blame] | 2592 | static int wp_context_status(const struct flashctx *flash) |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2593 | { |
| 2594 | uint8_t sr1; |
| 2595 | unsigned int start, len; |
| 2596 | int ret = 0; |
Nikolai Artemiev | 33b9106 | 2021-04-06 16:34:10 +1000 | [diff] [blame] | 2597 | struct status_register_layout sr1_layout; |
Nikolai Artemiev | 9221c8a | 2021-04-06 15:59:35 +1000 | [diff] [blame] | 2598 | int wp_en; |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2599 | |
Nikolai Artemiev | 33b9106 | 2021-04-06 16:34:10 +1000 | [diff] [blame] | 2600 | if (get_sr1_layout(flash, &sr1_layout)) |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2601 | return -1; |
| 2602 | |
Nikolai Artemiev | 48b424b | 2021-04-06 14:12:02 +1000 | [diff] [blame] | 2603 | sr1 = spi_read_status_register(flash); |
Nikolai Artemiev | 33b9106 | 2021-04-06 16:34:10 +1000 | [diff] [blame] | 2604 | wp_en = (sr1 >> sr1_layout.srp_pos) & 1; |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2605 | |
| 2606 | msg_cinfo("WP: status: 0x%04x\n", sr1); |
| 2607 | msg_cinfo("WP: status.srp0: %x\n", wp_en); |
| 2608 | /* FIXME: SRP1 is not really generic, but we probably should print |
| 2609 | * it anyway to have consistent output. #legacycruft */ |
| 2610 | msg_cinfo("WP: status.srp1: %x\n", 0); |
| 2611 | msg_cinfo("WP: write protect is %s.\n", |
| 2612 | wp_en ? "enabled" : "disabled"); |
| 2613 | |
| 2614 | msg_cinfo("WP: write protect range: "); |
| 2615 | if (generic_status_to_range(flash, sr1, &start, &len)) { |
| 2616 | msg_cinfo("(cannot resolve the range)\n"); |
| 2617 | ret = -1; |
| 2618 | } else { |
| 2619 | msg_cinfo("start=0x%08x, len=0x%08x\n", start, len); |
| 2620 | } |
| 2621 | |
| 2622 | return ret; |
| 2623 | } |
| 2624 | |
| 2625 | struct wp wp_generic = { |
Nikolai Artemiev | 3b666da | 2021-04-06 16:59:01 +1000 | [diff] [blame] | 2626 | .list_ranges = list_ranges, |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2627 | .set_range = generic_set_range, |
| 2628 | .enable = generic_enable_writeprotect, |
| 2629 | .disable = generic_disable_writeprotect, |
Edward O'Callaghan | a3edcb2 | 2019-12-05 14:30:50 +1100 | [diff] [blame] | 2630 | .wp_status = wp_context_status, |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 2631 | }; |