Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Michael Schwingen | 73d044d | 2007-12-07 23:35:02 +0100 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2007 |
| 4 | * Michael Schwingen, <michael@schwingen.org> |
| 5 | * |
| 6 | * based in great part on jedec_probe.c from linux kernel: |
| 7 | * (C) 2000 Red Hat. GPL'd. |
| 8 | * Occasionally maintained by Thayne Harbaugh tharbaugh at lnxi dot com |
Michael Schwingen | 73d044d | 2007-12-07 23:35:02 +0100 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | /* The DEBUG define must be before common to enable debugging */ |
| 12 | /*#define DEBUG*/ |
| 13 | |
Simon Glass | 8e20188 | 2020-05-10 11:39:54 -0600 | [diff] [blame] | 14 | #include <flash.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 15 | #include <log.h> |
Michael Schwingen | 73d044d | 2007-12-07 23:35:02 +0100 | [diff] [blame] | 16 | #include <asm/processor.h> |
| 17 | #include <asm/io.h> |
| 18 | #include <asm/byteorder.h> |
Michael Schwingen | 73d044d | 2007-12-07 23:35:02 +0100 | [diff] [blame] | 19 | |
| 20 | #define P_ID_AMD_STD CFI_CMDSET_AMD_LEGACY |
| 21 | |
Michael Schwingen | 73d044d | 2007-12-07 23:35:02 +0100 | [diff] [blame] | 22 | /* AMD */ |
Stefan Roese | 4ef1f67 | 2008-07-08 12:57:14 +0200 | [diff] [blame] | 23 | #define AM29DL800BB 0x22CB |
Michael Schwingen | 73d044d | 2007-12-07 23:35:02 +0100 | [diff] [blame] | 24 | #define AM29DL800BT 0x224A |
| 25 | |
David Müller | e8e8fc0 | 2010-12-21 10:09:56 +0100 | [diff] [blame] | 26 | #define AM29F400BB 0x22AB |
Michael Schwingen | 73d044d | 2007-12-07 23:35:02 +0100 | [diff] [blame] | 27 | #define AM29F800BB 0x2258 |
| 28 | #define AM29F800BT 0x22D6 |
| 29 | #define AM29LV400BB 0x22BA |
| 30 | #define AM29LV400BT 0x22B9 |
| 31 | #define AM29LV800BB 0x225B |
| 32 | #define AM29LV800BT 0x22DA |
| 33 | #define AM29LV160DT 0x22C4 |
| 34 | #define AM29LV160DB 0x2249 |
| 35 | #define AM29F017D 0x003D |
| 36 | #define AM29F016D 0x00AD |
| 37 | #define AM29F080 0x00D5 |
| 38 | #define AM29F040 0x00A4 |
| 39 | #define AM29LV040B 0x004F |
| 40 | #define AM29F032B 0x0041 |
| 41 | #define AM29F002T 0x00B0 |
| 42 | |
| 43 | /* SST */ |
| 44 | #define SST39LF800 0x2781 |
| 45 | #define SST39LF160 0x2782 |
| 46 | #define SST39VF1601 0x234b |
| 47 | #define SST39LF512 0x00D4 |
| 48 | #define SST39LF010 0x00D5 |
| 49 | #define SST39LF020 0x00D6 |
| 50 | #define SST39LF040 0x00D7 |
| 51 | #define SST39SF010A 0x00B5 |
| 52 | #define SST39SF020A 0x00B6 |
| 53 | |
David Müller (ELSOFT AG) | fe548c3 | 2012-02-06 09:42:54 +0100 | [diff] [blame] | 54 | /* STM */ |
| 55 | #define STM29F400BB 0x00D6 |
| 56 | |
Niklaus Giger | f447f71 | 2009-07-22 17:13:24 +0200 | [diff] [blame] | 57 | /* MXIC */ |
| 58 | #define MX29LV040 0x004F |
| 59 | |
| 60 | /* WINBOND */ |
| 61 | #define W39L040A 0x00D6 |
| 62 | |
| 63 | /* AMIC */ |
| 64 | #define A29L040 0x0092 |
| 65 | |
| 66 | /* EON */ |
| 67 | #define EN29LV040A 0x004F |
Michael Schwingen | 73d044d | 2007-12-07 23:35:02 +0100 | [diff] [blame] | 68 | |
| 69 | /* |
| 70 | * Unlock address sets for AMD command sets. |
| 71 | * Intel command sets use the MTD_UADDR_UNNECESSARY. |
| 72 | * Each identifier, except MTD_UADDR_UNNECESSARY, and |
| 73 | * MTD_UADDR_NO_SUPPORT must be defined below in unlock_addrs[]. |
| 74 | * MTD_UADDR_NOT_SUPPORTED must be 0 so that structure |
| 75 | * initialization need not require initializing all of the |
| 76 | * unlock addresses for all bit widths. |
| 77 | */ |
| 78 | enum uaddr { |
| 79 | MTD_UADDR_NOT_SUPPORTED = 0, /* data width not supported */ |
| 80 | MTD_UADDR_0x0555_0x02AA, |
| 81 | MTD_UADDR_0x0555_0x0AAA, |
| 82 | MTD_UADDR_0x5555_0x2AAA, |
| 83 | MTD_UADDR_0x0AAA_0x0555, |
| 84 | MTD_UADDR_DONT_CARE, /* Requires an arbitrary address */ |
| 85 | MTD_UADDR_UNNECESSARY, /* Does not require any address */ |
| 86 | }; |
| 87 | |
Michael Schwingen | 73d044d | 2007-12-07 23:35:02 +0100 | [diff] [blame] | 88 | struct unlock_addr { |
| 89 | u32 addr1; |
| 90 | u32 addr2; |
| 91 | }; |
| 92 | |
Michael Schwingen | 73d044d | 2007-12-07 23:35:02 +0100 | [diff] [blame] | 93 | /* |
| 94 | * I don't like the fact that the first entry in unlock_addrs[] |
| 95 | * exists, but is for MTD_UADDR_NOT_SUPPORTED - and, therefore, |
| 96 | * should not be used. The problem is that structures with |
| 97 | * initializers have extra fields initialized to 0. It is _very_ |
| 98 | * desireable to have the unlock address entries for unsupported |
| 99 | * data widths automatically initialized - that means that |
| 100 | * MTD_UADDR_NOT_SUPPORTED must be 0 and the first entry here |
| 101 | * must go unused. |
| 102 | */ |
| 103 | static const struct unlock_addr unlock_addrs[] = { |
| 104 | [MTD_UADDR_NOT_SUPPORTED] = { |
| 105 | .addr1 = 0xffff, |
| 106 | .addr2 = 0xffff |
| 107 | }, |
| 108 | |
| 109 | [MTD_UADDR_0x0555_0x02AA] = { |
| 110 | .addr1 = 0x0555, |
| 111 | .addr2 = 0x02aa |
| 112 | }, |
| 113 | |
| 114 | [MTD_UADDR_0x0555_0x0AAA] = { |
| 115 | .addr1 = 0x0555, |
| 116 | .addr2 = 0x0aaa |
| 117 | }, |
| 118 | |
| 119 | [MTD_UADDR_0x5555_0x2AAA] = { |
| 120 | .addr1 = 0x5555, |
| 121 | .addr2 = 0x2aaa |
| 122 | }, |
| 123 | |
| 124 | [MTD_UADDR_0x0AAA_0x0555] = { |
| 125 | .addr1 = 0x0AAA, |
| 126 | .addr2 = 0x0555 |
| 127 | }, |
| 128 | |
| 129 | [MTD_UADDR_DONT_CARE] = { |
| 130 | .addr1 = 0x0000, /* Doesn't matter which address */ |
| 131 | .addr2 = 0x0000 /* is used - must be last entry */ |
| 132 | }, |
| 133 | |
| 134 | [MTD_UADDR_UNNECESSARY] = { |
| 135 | .addr1 = 0x0000, |
| 136 | .addr2 = 0x0000 |
| 137 | } |
| 138 | }; |
| 139 | |
Michael Schwingen | 73d044d | 2007-12-07 23:35:02 +0100 | [diff] [blame] | 140 | struct amd_flash_info { |
| 141 | const __u16 mfr_id; |
| 142 | const __u16 dev_id; |
| 143 | const char *name; |
| 144 | const int DevSize; |
| 145 | const int NumEraseRegions; |
| 146 | const int CmdSet; |
| 147 | const __u8 uaddr[4]; /* unlock addrs for 8, 16, 32, 64 */ |
| 148 | const ulong regions[6]; |
| 149 | }; |
| 150 | |
| 151 | #define ERASEINFO(size,blocks) (size<<8)|(blocks-1) |
| 152 | |
| 153 | #define SIZE_64KiB 16 |
| 154 | #define SIZE_128KiB 17 |
| 155 | #define SIZE_256KiB 18 |
| 156 | #define SIZE_512KiB 19 |
| 157 | #define SIZE_1MiB 20 |
| 158 | #define SIZE_2MiB 21 |
| 159 | #define SIZE_4MiB 22 |
| 160 | #define SIZE_8MiB 23 |
| 161 | |
| 162 | static const struct amd_flash_info jedec_table[] = { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 163 | #ifdef CONFIG_SYS_FLASH_LEGACY_256Kx8 |
Michael Schwingen | 73d044d | 2007-12-07 23:35:02 +0100 | [diff] [blame] | 164 | { |
Stefan Roese | c8b0312 | 2009-01-29 11:21:38 +0100 | [diff] [blame] | 165 | .mfr_id = (u16)SST_MANUFACT, |
Michael Schwingen | 73d044d | 2007-12-07 23:35:02 +0100 | [diff] [blame] | 166 | .dev_id = SST39LF020, |
| 167 | .name = "SST 39LF020", |
Stefan Roese | 5543171 | 2007-12-08 08:25:09 +0100 | [diff] [blame] | 168 | .uaddr = { |
Michael Schwingen | 73d044d | 2007-12-07 23:35:02 +0100 | [diff] [blame] | 169 | [0] = MTD_UADDR_0x5555_0x2AAA /* x8 */ |
| 170 | }, |
| 171 | .DevSize = SIZE_256KiB, |
| 172 | .CmdSet = P_ID_AMD_STD, |
| 173 | .NumEraseRegions= 1, |
| 174 | .regions = { |
| 175 | ERASEINFO(0x01000,64), |
| 176 | } |
Stefan Roese | 5543171 | 2007-12-08 08:25:09 +0100 | [diff] [blame] | 177 | }, |
Michael Schwingen | 73d044d | 2007-12-07 23:35:02 +0100 | [diff] [blame] | 178 | #endif |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 179 | #ifdef CONFIG_SYS_FLASH_LEGACY_512Kx8 |
Michael Schwingen | 73d044d | 2007-12-07 23:35:02 +0100 | [diff] [blame] | 180 | { |
Stefan Roese | c8b0312 | 2009-01-29 11:21:38 +0100 | [diff] [blame] | 181 | .mfr_id = (u16)AMD_MANUFACT, |
Michael Schwingen | 73d044d | 2007-12-07 23:35:02 +0100 | [diff] [blame] | 182 | .dev_id = AM29LV040B, |
| 183 | .name = "AMD AM29LV040B", |
| 184 | .uaddr = { |
| 185 | [0] = MTD_UADDR_0x0555_0x02AA /* x8 */ |
| 186 | }, |
| 187 | .DevSize = SIZE_512KiB, |
| 188 | .CmdSet = P_ID_AMD_STD, |
| 189 | .NumEraseRegions= 1, |
| 190 | .regions = { |
| 191 | ERASEINFO(0x10000,8), |
| 192 | } |
| 193 | }, |
| 194 | { |
Stefan Roese | c8b0312 | 2009-01-29 11:21:38 +0100 | [diff] [blame] | 195 | .mfr_id = (u16)SST_MANUFACT, |
Michael Schwingen | 73d044d | 2007-12-07 23:35:02 +0100 | [diff] [blame] | 196 | .dev_id = SST39LF040, |
| 197 | .name = "SST 39LF040", |
Stefan Roese | 5543171 | 2007-12-08 08:25:09 +0100 | [diff] [blame] | 198 | .uaddr = { |
Michael Schwingen | 73d044d | 2007-12-07 23:35:02 +0100 | [diff] [blame] | 199 | [0] = MTD_UADDR_0x5555_0x2AAA /* x8 */ |
| 200 | }, |
| 201 | .DevSize = SIZE_512KiB, |
| 202 | .CmdSet = P_ID_AMD_STD, |
| 203 | .NumEraseRegions= 1, |
| 204 | .regions = { |
| 205 | ERASEINFO(0x01000,128), |
| 206 | } |
Stefan Roese | 5543171 | 2007-12-08 08:25:09 +0100 | [diff] [blame] | 207 | }, |
Niklaus Giger | 29194e8 | 2008-12-08 17:24:08 +0100 | [diff] [blame] | 208 | { |
Stefan Roese | c8b0312 | 2009-01-29 11:21:38 +0100 | [diff] [blame] | 209 | .mfr_id = (u16)STM_MANUFACT, |
Niklaus Giger | 29194e8 | 2008-12-08 17:24:08 +0100 | [diff] [blame] | 210 | .dev_id = STM_ID_M29W040B, |
| 211 | .name = "ST Micro M29W040B", |
| 212 | .uaddr = { |
| 213 | [0] = MTD_UADDR_0x0555_0x02AA /* x8 */ |
| 214 | }, |
| 215 | .DevSize = SIZE_512KiB, |
| 216 | .CmdSet = P_ID_AMD_STD, |
| 217 | .NumEraseRegions= 1, |
| 218 | .regions = { |
| 219 | ERASEINFO(0x10000,8), |
| 220 | } |
| 221 | }, |
Niklaus Giger | f447f71 | 2009-07-22 17:13:24 +0200 | [diff] [blame] | 222 | { |
| 223 | .mfr_id = (u16)MX_MANUFACT, |
| 224 | .dev_id = MX29LV040, |
| 225 | .name = "MXIC MX29LV040", |
| 226 | .uaddr = { |
| 227 | [0] = MTD_UADDR_0x0555_0x02AA /* x8 */ |
| 228 | }, |
| 229 | .DevSize = SIZE_512KiB, |
| 230 | .CmdSet = P_ID_AMD_STD, |
| 231 | .NumEraseRegions= 1, |
| 232 | .regions = { |
| 233 | ERASEINFO(0x10000, 8), |
| 234 | } |
| 235 | }, |
| 236 | { |
| 237 | .mfr_id = (u16)WINB_MANUFACT, |
| 238 | .dev_id = W39L040A, |
| 239 | .name = "WINBOND W39L040A", |
| 240 | .uaddr = { |
| 241 | [0] = MTD_UADDR_0x5555_0x2AAA /* x8 */ |
| 242 | }, |
| 243 | .DevSize = SIZE_512KiB, |
| 244 | .CmdSet = P_ID_AMD_STD, |
| 245 | .NumEraseRegions= 1, |
| 246 | .regions = { |
| 247 | ERASEINFO(0x10000, 8), |
| 248 | } |
| 249 | }, |
| 250 | { |
| 251 | .mfr_id = (u16)AMIC_MANUFACT, |
| 252 | .dev_id = A29L040, |
| 253 | .name = "AMIC A29L040", |
| 254 | .uaddr = { |
| 255 | [0] = MTD_UADDR_0x0555_0x02AA /* x8 */ |
| 256 | }, |
| 257 | .DevSize = SIZE_512KiB, |
| 258 | .CmdSet = P_ID_AMD_STD, |
| 259 | .NumEraseRegions= 1, |
| 260 | .regions = { |
| 261 | ERASEINFO(0x10000, 8), |
| 262 | } |
| 263 | }, |
| 264 | { |
| 265 | .mfr_id = (u16)EON_MANUFACT, |
| 266 | .dev_id = EN29LV040A, |
| 267 | .name = "EON EN29LV040A", |
| 268 | .uaddr = { |
| 269 | [0] = MTD_UADDR_0x0555_0x02AA /* x8 */ |
| 270 | }, |
| 271 | .DevSize = SIZE_512KiB, |
| 272 | .CmdSet = P_ID_AMD_STD, |
| 273 | .NumEraseRegions= 1, |
| 274 | .regions = { |
| 275 | ERASEINFO(0x10000, 8), |
| 276 | } |
| 277 | }, |
Michael Schwingen | 73d044d | 2007-12-07 23:35:02 +0100 | [diff] [blame] | 278 | #endif |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 279 | #ifdef CONFIG_SYS_FLASH_LEGACY_512Kx16 |
Tor Krill | 7f2a305 | 2008-03-28 11:29:10 +0100 | [diff] [blame] | 280 | { |
Stefan Roese | c8b0312 | 2009-01-29 11:21:38 +0100 | [diff] [blame] | 281 | .mfr_id = (u16)AMD_MANUFACT, |
David Müller | e8e8fc0 | 2010-12-21 10:09:56 +0100 | [diff] [blame] | 282 | .dev_id = AM29F400BB, |
| 283 | .name = "AMD AM29F400BB", |
| 284 | .uaddr = { |
| 285 | [1] = MTD_UADDR_0x0555_0x02AA /* x16 */ |
| 286 | }, |
| 287 | .DevSize = SIZE_512KiB, |
| 288 | .CmdSet = CFI_CMDSET_AMD_LEGACY, |
| 289 | .NumEraseRegions= 4, |
| 290 | .regions = { |
| 291 | ERASEINFO(0x04000, 1), |
| 292 | ERASEINFO(0x02000, 2), |
| 293 | ERASEINFO(0x08000, 1), |
| 294 | ERASEINFO(0x10000, 7), |
| 295 | } |
| 296 | }, |
| 297 | { |
| 298 | .mfr_id = (u16)AMD_MANUFACT, |
Tor Krill | 7f2a305 | 2008-03-28 11:29:10 +0100 | [diff] [blame] | 299 | .dev_id = AM29LV400BB, |
| 300 | .name = "AMD AM29LV400BB", |
| 301 | .uaddr = { |
| 302 | [1] = MTD_UADDR_0x0555_0x02AA /* x16 */ |
| 303 | }, |
| 304 | .DevSize = SIZE_512KiB, |
| 305 | .CmdSet = CFI_CMDSET_AMD_LEGACY, |
| 306 | .NumEraseRegions= 4, |
| 307 | .regions = { |
| 308 | ERASEINFO(0x04000,1), |
| 309 | ERASEINFO(0x02000,2), |
| 310 | ERASEINFO(0x08000,1), |
| 311 | ERASEINFO(0x10000,7), |
| 312 | } |
| 313 | }, |
Guennadi Liakhovetski | 504e9d1 | 2008-08-05 15:36:39 +0200 | [diff] [blame] | 314 | { |
Stefan Roese | c8b0312 | 2009-01-29 11:21:38 +0100 | [diff] [blame] | 315 | .mfr_id = (u16)AMD_MANUFACT, |
Guennadi Liakhovetski | 504e9d1 | 2008-08-05 15:36:39 +0200 | [diff] [blame] | 316 | .dev_id = AM29LV800BB, |
| 317 | .name = "AMD AM29LV800BB", |
| 318 | .uaddr = { |
| 319 | [1] = MTD_UADDR_0x0555_0x02AA /* x16 */ |
| 320 | }, |
| 321 | .DevSize = SIZE_1MiB, |
| 322 | .CmdSet = CFI_CMDSET_AMD_LEGACY, |
| 323 | .NumEraseRegions= 4, |
| 324 | .regions = { |
| 325 | ERASEINFO(0x04000, 1), |
| 326 | ERASEINFO(0x02000, 2), |
| 327 | ERASEINFO(0x08000, 1), |
| 328 | ERASEINFO(0x10000, 15), |
| 329 | } |
| 330 | }, |
David Müller (ELSOFT AG) | fe548c3 | 2012-02-06 09:42:54 +0100 | [diff] [blame] | 331 | { |
Dirk Eibach | 892de18 | 2014-11-13 19:21:13 +0100 | [diff] [blame] | 332 | .mfr_id = (u16)AMD_MANUFACT, |
| 333 | .dev_id = AM29LV800BT, |
| 334 | .name = "AMD AM29LV800BT", |
| 335 | .uaddr = { |
| 336 | [1] = MTD_UADDR_0x0555_0x02AA /* x16 */ |
| 337 | }, |
| 338 | .DevSize = SIZE_1MiB, |
| 339 | .CmdSet = CFI_CMDSET_AMD_LEGACY, |
| 340 | .NumEraseRegions= 4, |
| 341 | .regions = { |
| 342 | ERASEINFO(0x10000, 15), |
| 343 | ERASEINFO(0x08000, 1), |
| 344 | ERASEINFO(0x02000, 2), |
| 345 | ERASEINFO(0x04000, 1), |
| 346 | } |
| 347 | }, |
| 348 | { |
| 349 | .mfr_id = (u16)MX_MANUFACT, |
| 350 | .dev_id = AM29LV800BT, |
| 351 | .name = "MXIC MX29LV800BT", |
| 352 | .uaddr = { |
| 353 | [1] = MTD_UADDR_0x0555_0x02AA /* x16 */ |
| 354 | }, |
| 355 | .DevSize = SIZE_1MiB, |
| 356 | .CmdSet = CFI_CMDSET_AMD_LEGACY, |
| 357 | .NumEraseRegions= 4, |
| 358 | .regions = { |
| 359 | ERASEINFO(0x10000, 15), |
| 360 | ERASEINFO(0x08000, 1), |
| 361 | ERASEINFO(0x02000, 2), |
| 362 | ERASEINFO(0x04000, 1), |
| 363 | } |
| 364 | }, |
| 365 | { |
| 366 | .mfr_id = (u16)EON_ALT_MANU, |
| 367 | .dev_id = AM29LV800BT, |
| 368 | .name = "EON EN29LV800BT", |
| 369 | .uaddr = { |
| 370 | [1] = MTD_UADDR_0x0555_0x02AA /* x16 */ |
| 371 | }, |
| 372 | .DevSize = SIZE_1MiB, |
| 373 | .CmdSet = CFI_CMDSET_AMD_LEGACY, |
| 374 | .NumEraseRegions= 4, |
| 375 | .regions = { |
| 376 | ERASEINFO(0x10000, 15), |
| 377 | ERASEINFO(0x08000, 1), |
| 378 | ERASEINFO(0x02000, 2), |
| 379 | ERASEINFO(0x04000, 1), |
| 380 | } |
| 381 | }, |
| 382 | { |
David Müller (ELSOFT AG) | fe548c3 | 2012-02-06 09:42:54 +0100 | [diff] [blame] | 383 | .mfr_id = (u16)STM_MANUFACT, |
| 384 | .dev_id = STM29F400BB, |
| 385 | .name = "ST Micro M29F400BB", |
| 386 | .uaddr = { |
| 387 | [1] = MTD_UADDR_0x0555_0x02AA /* x16 */ |
| 388 | }, |
| 389 | .DevSize = SIZE_512KiB, |
| 390 | .CmdSet = CFI_CMDSET_AMD_LEGACY, |
| 391 | .NumEraseRegions = 4, |
| 392 | .regions = { |
| 393 | ERASEINFO(0x04000, 1), |
| 394 | ERASEINFO(0x02000, 2), |
| 395 | ERASEINFO(0x08000, 1), |
| 396 | ERASEINFO(0x10000, 7), |
| 397 | } |
| 398 | }, |
Tor Krill | 7f2a305 | 2008-03-28 11:29:10 +0100 | [diff] [blame] | 399 | #endif |
Michael Schwingen | 73d044d | 2007-12-07 23:35:02 +0100 | [diff] [blame] | 400 | }; |
| 401 | |
Michael Schwingen | 73d044d | 2007-12-07 23:35:02 +0100 | [diff] [blame] | 402 | static inline void fill_info(flash_info_t *info, const struct amd_flash_info *jedec_entry, ulong base) |
| 403 | { |
| 404 | int i,j; |
| 405 | int sect_cnt; |
| 406 | int size_ratio; |
| 407 | int total_size; |
| 408 | enum uaddr uaddr_idx; |
| 409 | |
| 410 | size_ratio = info->portwidth / info->chipwidth; |
| 411 | |
| 412 | debug("Found JEDEC Flash: %s\n", jedec_entry->name); |
| 413 | info->vendor = jedec_entry->CmdSet; |
| 414 | /* Todo: do we need device-specific timeouts? */ |
| 415 | info->erase_blk_tout = 30000; |
| 416 | info->buffer_write_tout = 1000; |
| 417 | info->write_tout = 100; |
| 418 | info->name = jedec_entry->name; |
| 419 | |
| 420 | /* copy unlock addresses from device table to CFI info struct. This |
| 421 | is just here because the addresses are in the table anyway - if |
| 422 | the flash is not detected due to wrong unlock addresses, |
| 423 | flash_detect_legacy would have to try all of them before we even |
| 424 | get here. */ |
| 425 | switch(info->chipwidth) { |
| 426 | case FLASH_CFI_8BIT: |
| 427 | uaddr_idx = jedec_entry->uaddr[0]; |
| 428 | break; |
| 429 | case FLASH_CFI_16BIT: |
| 430 | uaddr_idx = jedec_entry->uaddr[1]; |
| 431 | break; |
| 432 | case FLASH_CFI_32BIT: |
| 433 | uaddr_idx = jedec_entry->uaddr[2]; |
| 434 | break; |
| 435 | default: |
| 436 | uaddr_idx = MTD_UADDR_NOT_SUPPORTED; |
| 437 | break; |
| 438 | } |
| 439 | |
| 440 | debug("unlock address index %d\n", uaddr_idx); |
| 441 | info->addr_unlock1 = unlock_addrs[uaddr_idx].addr1; |
| 442 | info->addr_unlock2 = unlock_addrs[uaddr_idx].addr2; |
Marek Vasut | 0e94ad8 | 2011-10-21 14:17:11 +0000 | [diff] [blame] | 443 | debug("unlock addresses are 0x%lx/0x%lx\n", |
| 444 | info->addr_unlock1, info->addr_unlock2); |
Michael Schwingen | 73d044d | 2007-12-07 23:35:02 +0100 | [diff] [blame] | 445 | |
| 446 | sect_cnt = 0; |
| 447 | total_size = 0; |
| 448 | for (i = 0; i < jedec_entry->NumEraseRegions; i++) { |
| 449 | ulong erase_region_size = jedec_entry->regions[i] >> 8; |
| 450 | ulong erase_region_count = (jedec_entry->regions[i] & 0xff) + 1; |
| 451 | |
| 452 | total_size += erase_region_size * erase_region_count; |
Marek Vasut | 0e94ad8 | 2011-10-21 14:17:11 +0000 | [diff] [blame] | 453 | debug("erase_region_count = %ld erase_region_size = %ld\n", |
Michael Schwingen | 73d044d | 2007-12-07 23:35:02 +0100 | [diff] [blame] | 454 | erase_region_count, erase_region_size); |
| 455 | for (j = 0; j < erase_region_count; j++) { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 456 | if (sect_cnt >= CONFIG_SYS_MAX_FLASH_SECT) { |
Michael Schwingen | 73d044d | 2007-12-07 23:35:02 +0100 | [diff] [blame] | 457 | printf("ERROR: too many flash sectors\n"); |
| 458 | break; |
| 459 | } |
| 460 | info->start[sect_cnt] = base; |
| 461 | base += (erase_region_size * size_ratio); |
| 462 | sect_cnt++; |
| 463 | } |
| 464 | } |
| 465 | info->sector_count = sect_cnt; |
| 466 | info->size = total_size * size_ratio; |
| 467 | } |
| 468 | |
| 469 | /*----------------------------------------------------------------------- |
| 470 | * match jedec ids against table. If a match is found, fill flash_info entry |
| 471 | */ |
| 472 | int jedec_flash_match(flash_info_t *info, ulong base) |
| 473 | { |
| 474 | int ret = 0; |
| 475 | int i; |
| 476 | ulong mask = 0xFFFF; |
| 477 | if (info->chipwidth == 1) |
| 478 | mask = 0xFF; |
| 479 | |
| 480 | for (i = 0; i < ARRAY_SIZE(jedec_table); i++) { |
| 481 | if ((jedec_table[i].mfr_id & mask) == (info->manufacturer_id & mask) && |
| 482 | (jedec_table[i].dev_id & mask) == (info->device_id & mask)) { |
| 483 | fill_info(info, &jedec_table[i], base); |
| 484 | ret = 1; |
| 485 | break; |
| 486 | } |
| 487 | } |
| 488 | return ret; |
| 489 | } |