wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2001 |
| 3 | * Stefan Roese, esd gmbh germany, stefan.roese@esd-electronics.com |
| 4 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 9 | #include <asm/processor.h> |
| 10 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 11 | flash_info_t flash_info[CONFIG_SYS_MAX_FLASH_BANKS]; /* info for FLASH chips */ |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 12 | |
| 13 | /*----------------------------------------------------------------------- |
| 14 | * Functions |
| 15 | */ |
| 16 | static int write_word (flash_info_t *info, ulong dest, ulong data); |
| 17 | |
| 18 | /*----------------------------------------------------------------------- |
| 19 | */ |
| 20 | static void flash_get_offsets (ulong base, flash_info_t *info) |
| 21 | { |
| 22 | int i; |
| 23 | short n; |
| 24 | |
| 25 | /* set up sector start address table */ |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 26 | if (((info->flash_id & FLASH_VENDMASK) == FLASH_MAN_SST) || |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 27 | ((info->flash_id & FLASH_TYPEMASK) == FLASH_AM640U)) { |
| 28 | for (i = 0; i < info->sector_count; i++) |
| 29 | info->start[i] = base + (i * 0x00010000); |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 30 | } else if (((info->flash_id & FLASH_TYPEMASK) == FLASH_AMDL322B) || |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 31 | ((info->flash_id & FLASH_TYPEMASK) == FLASH_AMDL323B) || |
| 32 | ((info->flash_id & FLASH_TYPEMASK) == FLASH_AM320B) || |
| 33 | ((info->flash_id & FLASH_TYPEMASK) == FLASH_AMDL324B)) { |
| 34 | /* set sector offsets for bottom boot block type */ |
| 35 | for (i=0; i<8; ++i) { /* 8 x 8k boot sectors */ |
| 36 | info->start[i] = base; |
| 37 | base += 8 << 10; |
| 38 | } |
| 39 | while (i < info->sector_count) { /* 64k regular sectors */ |
| 40 | info->start[i] = base; |
| 41 | base += 64 << 10; |
| 42 | ++i; |
| 43 | } |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 44 | } else if (((info->flash_id & FLASH_TYPEMASK) == FLASH_AMDL322T) || |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 45 | ((info->flash_id & FLASH_TYPEMASK) == FLASH_AMDL323T) || |
| 46 | ((info->flash_id & FLASH_TYPEMASK) == FLASH_AM320T) || |
| 47 | ((info->flash_id & FLASH_TYPEMASK) == FLASH_AMDL324T)) { |
| 48 | /* set sector offsets for top boot block type */ |
| 49 | base += info->size; |
| 50 | i = info->sector_count; |
| 51 | for (n=0; n<8; ++n) { /* 8 x 8k boot sectors */ |
| 52 | base -= 8 << 10; |
| 53 | --i; |
| 54 | info->start[i] = base; |
| 55 | } |
| 56 | while (i > 0) { /* 64k regular sectors */ |
| 57 | base -= 64 << 10; |
| 58 | --i; |
| 59 | info->start[i] = base; |
| 60 | } |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 61 | } else { |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 62 | if (info->flash_id & FLASH_BTYPE) { |
| 63 | /* set sector offsets for bottom boot block type */ |
| 64 | info->start[0] = base + 0x00000000; |
| 65 | info->start[1] = base + 0x00004000; |
| 66 | info->start[2] = base + 0x00006000; |
| 67 | info->start[3] = base + 0x00008000; |
| 68 | for (i = 4; i < info->sector_count; i++) { |
| 69 | info->start[i] = base + (i * 0x00010000) - 0x00030000; |
| 70 | } |
| 71 | } else { |
| 72 | /* set sector offsets for top boot block type */ |
| 73 | i = info->sector_count - 1; |
| 74 | info->start[i--] = base + info->size - 0x00004000; |
| 75 | info->start[i--] = base + info->size - 0x00006000; |
| 76 | info->start[i--] = base + info->size - 0x00008000; |
| 77 | for (; i >= 0; i--) { |
| 78 | info->start[i] = base + i * 0x00010000; |
| 79 | } |
| 80 | } |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | /*----------------------------------------------------------------------- |
| 85 | */ |
| 86 | void flash_print_info (flash_info_t *info) |
| 87 | { |
| 88 | int i; |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 89 | int k; |
| 90 | int size; |
| 91 | int erased; |
| 92 | volatile unsigned long *flash; |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 93 | |
| 94 | if (info->flash_id == FLASH_UNKNOWN) { |
| 95 | printf ("missing or unknown FLASH type\n"); |
| 96 | return; |
| 97 | } |
| 98 | |
| 99 | switch (info->flash_id & FLASH_VENDMASK) { |
| 100 | case FLASH_MAN_AMD: printf ("AMD "); break; |
| 101 | case FLASH_MAN_FUJ: printf ("FUJITSU "); break; |
| 102 | case FLASH_MAN_SST: printf ("SST "); break; |
| 103 | case FLASH_MAN_STM: printf ("ST "); break; |
| 104 | default: printf ("Unknown Vendor "); break; |
| 105 | } |
| 106 | |
| 107 | switch (info->flash_id & FLASH_TYPEMASK) { |
| 108 | case FLASH_AM400B: printf ("AM29LV400B (4 Mbit, bottom boot sect)\n"); |
| 109 | break; |
| 110 | case FLASH_AM400T: printf ("AM29LV400T (4 Mbit, top boot sector)\n"); |
| 111 | break; |
| 112 | case FLASH_AM800B: printf ("AM29LV800B (8 Mbit, bottom boot sect)\n"); |
| 113 | break; |
| 114 | case FLASH_AM800T: printf ("AM29LV800T (8 Mbit, top boot sector)\n"); |
| 115 | break; |
| 116 | case FLASH_AM160B: printf ("AM29LV160B (16 Mbit, bottom boot sect)\n"); |
| 117 | break; |
| 118 | case FLASH_AM160T: printf ("AM29LV160T (16 Mbit, top boot sector)\n"); |
| 119 | break; |
| 120 | case FLASH_AM320T: printf ("AM29LV320T (32 M, top sector)\n"); |
| 121 | break; |
| 122 | case FLASH_AM320B: printf ("AM29LV320B (32 M, bottom sector)\n"); |
| 123 | break; |
| 124 | case FLASH_AMDL322T: printf ("AM29DL322T (32 M, top sector)\n"); |
| 125 | break; |
| 126 | case FLASH_AMDL322B: printf ("AM29DL322B (32 M, bottom sector)\n"); |
| 127 | break; |
| 128 | case FLASH_AMDL323T: printf ("AM29DL323T (32 M, top sector)\n"); |
| 129 | break; |
| 130 | case FLASH_AMDL323B: printf ("AM29DL323B (32 M, bottom sector)\n"); |
| 131 | break; |
| 132 | case FLASH_AM640U: printf ("AM29LV640D (64 M, uniform sector)\n"); |
| 133 | break; |
| 134 | case FLASH_SST800A: printf ("SST39LF/VF800 (8 Mbit, uniform sector size)\n"); |
| 135 | break; |
| 136 | case FLASH_SST160A: printf ("SST39LF/VF160 (16 Mbit, uniform sector size)\n"); |
| 137 | break; |
| 138 | case FLASH_STMW320DT: printf ("M29W320DT (32 M, top sector)\n"); |
| 139 | break; |
| 140 | default: printf ("Unknown Chip Type\n"); |
| 141 | break; |
| 142 | } |
| 143 | |
| 144 | printf (" Size: %ld MB in %d Sectors\n", |
| 145 | info->size >> 20, info->sector_count); |
| 146 | |
| 147 | printf (" Sector Start Addresses:"); |
| 148 | for (i=0; i<info->sector_count; ++i) { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 149 | #ifdef CONFIG_SYS_FLASH_EMPTY_INFO |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 150 | /* |
| 151 | * Check if whole sector is erased |
| 152 | */ |
| 153 | if (i != (info->sector_count-1)) |
| 154 | size = info->start[i+1] - info->start[i]; |
| 155 | else |
| 156 | size = info->start[0] + info->size - info->start[i]; |
| 157 | erased = 1; |
| 158 | flash = (volatile unsigned long *)info->start[i]; |
| 159 | size = size >> 2; /* divide by 4 for longword access */ |
| 160 | for (k=0; k<size; k++) |
| 161 | { |
| 162 | if (*flash++ != 0xffffffff) |
| 163 | { |
| 164 | erased = 0; |
| 165 | break; |
| 166 | } |
| 167 | } |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 168 | |
| 169 | if ((i % 5) == 0) |
| 170 | printf ("\n "); |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 171 | /* print empty and read-only info */ |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 172 | printf (" %08lX%s%s", |
| 173 | info->start[i], |
| 174 | erased ? " E" : " ", |
| 175 | info->protect[i] ? "RO " : " "); |
| 176 | #else |
| 177 | if ((i % 5) == 0) |
| 178 | printf ("\n "); |
| 179 | printf (" %08lX%s", |
| 180 | info->start[i], |
| 181 | info->protect[i] ? " (RO)" : " "); |
| 182 | #endif |
| 183 | |
| 184 | } |
| 185 | printf ("\n"); |
| 186 | return; |
| 187 | } |
| 188 | |
| 189 | /*----------------------------------------------------------------------- |
| 190 | */ |
| 191 | |
| 192 | |
| 193 | /*----------------------------------------------------------------------- |
| 194 | */ |
| 195 | |
| 196 | /* |
| 197 | * The following code cannot be run from FLASH! |
| 198 | */ |
| 199 | static ulong flash_get_size (vu_long *addr, flash_info_t *info) |
| 200 | { |
| 201 | short i; |
| 202 | short n; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 203 | CONFIG_SYS_FLASH_WORD_SIZE value; |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 204 | ulong base = (ulong)addr; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 205 | volatile CONFIG_SYS_FLASH_WORD_SIZE *addr2 = (CONFIG_SYS_FLASH_WORD_SIZE *)addr; |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 206 | |
wdenk | e55ca7e | 2004-07-01 21:40:08 +0000 | [diff] [blame] | 207 | debug("[%s, %d] Entering ...\n", __FUNCTION__, __LINE__); |
| 208 | |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 209 | /* Write auto select command: read Manufacturer ID */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 210 | addr2[CONFIG_SYS_FLASH_ADDR0] = (CONFIG_SYS_FLASH_WORD_SIZE)0x00AA00AA; |
| 211 | addr2[CONFIG_SYS_FLASH_ADDR1] = (CONFIG_SYS_FLASH_WORD_SIZE)0x00550055; |
| 212 | addr2[CONFIG_SYS_FLASH_ADDR0] = (CONFIG_SYS_FLASH_WORD_SIZE)0x00900090; |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 213 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 214 | value = addr2[CONFIG_SYS_FLASH_READ0]; |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 215 | |
| 216 | switch (value) { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 217 | case (CONFIG_SYS_FLASH_WORD_SIZE)AMD_MANUFACT: |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 218 | info->flash_id = FLASH_MAN_AMD; |
| 219 | break; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 220 | case (CONFIG_SYS_FLASH_WORD_SIZE)FUJ_MANUFACT: |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 221 | info->flash_id = FLASH_MAN_FUJ; |
| 222 | break; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 223 | case (CONFIG_SYS_FLASH_WORD_SIZE)SST_MANUFACT: |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 224 | info->flash_id = FLASH_MAN_SST; |
| 225 | break; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 226 | case (CONFIG_SYS_FLASH_WORD_SIZE)STM_MANUFACT: |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 227 | info->flash_id = FLASH_MAN_STM; |
| 228 | break; |
| 229 | default: |
| 230 | info->flash_id = FLASH_UNKNOWN; |
| 231 | info->sector_count = 0; |
| 232 | info->size = 0; |
| 233 | return (0); /* no or unknown flash */ |
| 234 | } |
| 235 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 236 | value = addr2[CONFIG_SYS_FLASH_READ1]; /* device ID */ |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 237 | |
| 238 | switch (value) { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 239 | case (CONFIG_SYS_FLASH_WORD_SIZE)AMD_ID_LV400T: |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 240 | info->flash_id += FLASH_AM400T; |
| 241 | info->sector_count = 11; |
| 242 | info->size = 0x00080000; |
| 243 | break; /* => 0.5 MB */ |
| 244 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 245 | case (CONFIG_SYS_FLASH_WORD_SIZE)AMD_ID_LV400B: |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 246 | info->flash_id += FLASH_AM400B; |
| 247 | info->sector_count = 11; |
| 248 | info->size = 0x00080000; |
| 249 | break; /* => 0.5 MB */ |
| 250 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 251 | case (CONFIG_SYS_FLASH_WORD_SIZE)AMD_ID_LV800T: |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 252 | info->flash_id += FLASH_AM800T; |
| 253 | info->sector_count = 19; |
| 254 | info->size = 0x00100000; |
| 255 | break; /* => 1 MB */ |
| 256 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 257 | case (CONFIG_SYS_FLASH_WORD_SIZE)AMD_ID_LV800B: |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 258 | info->flash_id += FLASH_AM800B; |
| 259 | info->sector_count = 19; |
| 260 | info->size = 0x00100000; |
| 261 | break; /* => 1 MB */ |
| 262 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 263 | case (CONFIG_SYS_FLASH_WORD_SIZE)AMD_ID_LV160T: |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 264 | info->flash_id += FLASH_AM160T; |
| 265 | info->sector_count = 35; |
| 266 | info->size = 0x00200000; |
| 267 | break; /* => 2 MB */ |
| 268 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 269 | case (CONFIG_SYS_FLASH_WORD_SIZE)AMD_ID_LV160B: |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 270 | info->flash_id += FLASH_AM160B; |
| 271 | info->sector_count = 35; |
| 272 | info->size = 0x00200000; |
| 273 | break; /* => 2 MB */ |
| 274 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 275 | case (CONFIG_SYS_FLASH_WORD_SIZE)STM_ID_29W320DT: |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 276 | info->flash_id += FLASH_STMW320DT; |
| 277 | info->sector_count = 67; |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 278 | info->size = 0x00400000; break; /* => 4 MB */ |
| 279 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 280 | case (CONFIG_SYS_FLASH_WORD_SIZE)AMD_ID_LV320T: |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 281 | info->flash_id += FLASH_AM320T; |
| 282 | info->sector_count = 71; |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 283 | info->size = 0x00400000; break; /* => 4 MB */ |
| 284 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 285 | case (CONFIG_SYS_FLASH_WORD_SIZE)AMD_ID_LV320B: |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 286 | info->flash_id += FLASH_AM320B; |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 287 | info->sector_count = 71; |
| 288 | info->size = 0x00400000; break; /* => 4 MB */ |
| 289 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 290 | case (CONFIG_SYS_FLASH_WORD_SIZE)AMD_ID_DL322T: |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 291 | info->flash_id += FLASH_AMDL322T; |
| 292 | info->sector_count = 71; |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 293 | info->size = 0x00400000; break; /* => 4 MB */ |
| 294 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 295 | case (CONFIG_SYS_FLASH_WORD_SIZE)AMD_ID_DL322B: |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 296 | info->flash_id += FLASH_AMDL322B; |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 297 | info->sector_count = 71; |
| 298 | info->size = 0x00400000; break; /* => 4 MB */ |
| 299 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 300 | case (CONFIG_SYS_FLASH_WORD_SIZE)AMD_ID_DL323T: |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 301 | info->flash_id += FLASH_AMDL323T; |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 302 | info->sector_count = 71; |
| 303 | info->size = 0x00400000; break; /* => 4 MB */ |
| 304 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 305 | case (CONFIG_SYS_FLASH_WORD_SIZE)AMD_ID_DL323B: |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 306 | info->flash_id += FLASH_AMDL323B; |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 307 | info->sector_count = 71; |
| 308 | info->size = 0x00400000; break; /* => 4 MB */ |
| 309 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 310 | case (CONFIG_SYS_FLASH_WORD_SIZE)AMD_ID_LV640U: |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 311 | info->flash_id += FLASH_AM640U; |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 312 | info->sector_count = 128; |
| 313 | info->size = 0x00800000; break; /* => 8 MB */ |
| 314 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 315 | case (CONFIG_SYS_FLASH_WORD_SIZE)SST_ID_xF800A: |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 316 | info->flash_id += FLASH_SST800A; |
| 317 | info->sector_count = 16; |
| 318 | info->size = 0x00100000; |
| 319 | break; /* => 1 MB */ |
| 320 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 321 | case (CONFIG_SYS_FLASH_WORD_SIZE)SST_ID_xF160A: |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 322 | info->flash_id += FLASH_SST160A; |
| 323 | info->sector_count = 32; |
| 324 | info->size = 0x00200000; |
| 325 | break; /* => 2 MB */ |
| 326 | |
| 327 | default: |
| 328 | info->flash_id = FLASH_UNKNOWN; |
| 329 | return (0); /* => no or unknown flash */ |
| 330 | |
| 331 | } |
| 332 | |
| 333 | /* set up sector start address table */ |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 334 | if (((info->flash_id & FLASH_VENDMASK) == FLASH_MAN_SST) || |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 335 | ((info->flash_id & FLASH_TYPEMASK) == FLASH_AM640U)) { |
| 336 | for (i = 0; i < info->sector_count; i++) |
| 337 | info->start[i] = base + (i * 0x00010000); |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 338 | } else if (((info->flash_id & FLASH_TYPEMASK) == FLASH_AMDL322B) || |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 339 | ((info->flash_id & FLASH_TYPEMASK) == FLASH_AMDL323B) || |
| 340 | ((info->flash_id & FLASH_TYPEMASK) == FLASH_AM320B) || |
| 341 | ((info->flash_id & FLASH_TYPEMASK) == FLASH_AMDL324B)) { |
| 342 | /* set sector offsets for bottom boot block type */ |
| 343 | for (i=0; i<8; ++i) { /* 8 x 8k boot sectors */ |
| 344 | info->start[i] = base; |
| 345 | base += 8 << 10; |
| 346 | } |
| 347 | while (i < info->sector_count) { /* 64k regular sectors */ |
| 348 | info->start[i] = base; |
| 349 | base += 64 << 10; |
| 350 | ++i; |
| 351 | } |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 352 | } else if (((info->flash_id & FLASH_TYPEMASK) == FLASH_AMDL322T) || |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 353 | ((info->flash_id & FLASH_TYPEMASK) == FLASH_AMDL323T) || |
| 354 | ((info->flash_id & FLASH_TYPEMASK) == FLASH_AM320T) || |
| 355 | ((info->flash_id & FLASH_TYPEMASK) == FLASH_AMDL324T)) { |
| 356 | /* set sector offsets for top boot block type */ |
| 357 | base += info->size; |
| 358 | i = info->sector_count; |
| 359 | for (n=0; n<8; ++n) { /* 8 x 8k boot sectors */ |
| 360 | base -= 8 << 10; |
| 361 | --i; |
| 362 | info->start[i] = base; |
| 363 | } |
| 364 | while (i > 0) { /* 64k regular sectors */ |
| 365 | base -= 64 << 10; |
| 366 | --i; |
| 367 | info->start[i] = base; |
| 368 | } |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 369 | } else if ((info->flash_id & FLASH_TYPEMASK) == FLASH_STMW320DT) { |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 370 | /* set sector offsets for top boot block type */ |
| 371 | base += info->size; |
| 372 | i = info->sector_count; |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 373 | /* 1 x 16k boot sector */ |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 374 | base -= 16 << 10; |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 375 | --i; |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 376 | info->start[i] = base; |
| 377 | /* 2 x 8k boot sectors */ |
| 378 | for (n=0; n<2; ++n) { |
| 379 | base -= 8 << 10; |
| 380 | --i; |
| 381 | info->start[i] = base; |
| 382 | } |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 383 | /* 1 x 32k boot sector */ |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 384 | base -= 32 << 10; |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 385 | --i; |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 386 | info->start[i] = base; |
| 387 | |
| 388 | while (i > 0) { /* 64k regular sectors */ |
| 389 | base -= 64 << 10; |
| 390 | --i; |
| 391 | info->start[i] = base; |
| 392 | } |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 393 | } else { |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 394 | if (info->flash_id & FLASH_BTYPE) { |
| 395 | /* set sector offsets for bottom boot block type */ |
| 396 | info->start[0] = base + 0x00000000; |
| 397 | info->start[1] = base + 0x00004000; |
| 398 | info->start[2] = base + 0x00006000; |
| 399 | info->start[3] = base + 0x00008000; |
| 400 | for (i = 4; i < info->sector_count; i++) { |
| 401 | info->start[i] = base + (i * 0x00010000) - 0x00030000; |
| 402 | } |
| 403 | } else { |
| 404 | /* set sector offsets for top boot block type */ |
| 405 | i = info->sector_count - 1; |
| 406 | info->start[i--] = base + info->size - 0x00004000; |
| 407 | info->start[i--] = base + info->size - 0x00006000; |
| 408 | info->start[i--] = base + info->size - 0x00008000; |
| 409 | for (; i >= 0; i--) { |
| 410 | info->start[i] = base + i * 0x00010000; |
| 411 | } |
| 412 | } |
| 413 | } |
| 414 | |
| 415 | /* check for protected sectors */ |
| 416 | for (i = 0; i < info->sector_count; i++) { |
| 417 | /* read sector protection at sector address, (A7 .. A0) = 0x02 */ |
| 418 | /* D0 = 1 if protected */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 419 | addr2 = (volatile CONFIG_SYS_FLASH_WORD_SIZE *)(info->start[i]); |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 420 | if ((info->flash_id & FLASH_VENDMASK) == FLASH_MAN_SST) |
| 421 | info->protect[i] = 0; |
| 422 | else |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 423 | info->protect[i] = addr2[CONFIG_SYS_FLASH_READ2] & 1; |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 424 | } |
| 425 | |
| 426 | /* |
| 427 | * Prevent writes to uninitialized FLASH. |
| 428 | */ |
| 429 | if (info->flash_id != FLASH_UNKNOWN) { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 430 | addr2 = (CONFIG_SYS_FLASH_WORD_SIZE *)info->start[0]; |
| 431 | *addr2 = (CONFIG_SYS_FLASH_WORD_SIZE)0x00F000F0; /* reset bank */ |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 432 | } |
| 433 | |
| 434 | return (info->size); |
| 435 | } |
| 436 | |
| 437 | |
| 438 | /*----------------------------------------------------------------------- |
| 439 | */ |
| 440 | |
| 441 | int flash_erase (flash_info_t *info, int s_first, int s_last) |
| 442 | { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 443 | volatile CONFIG_SYS_FLASH_WORD_SIZE *addr = (CONFIG_SYS_FLASH_WORD_SIZE *)(info->start[0]); |
| 444 | volatile CONFIG_SYS_FLASH_WORD_SIZE *addr2; |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 445 | int flag, prot, sect, l_sect; |
| 446 | ulong start, now, last; |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 447 | int i; |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 448 | |
| 449 | if ((s_first < 0) || (s_first > s_last)) { |
| 450 | if (info->flash_id == FLASH_UNKNOWN) { |
| 451 | printf ("- missing\n"); |
| 452 | } else { |
| 453 | printf ("- no sectors to erase\n"); |
| 454 | } |
| 455 | return 1; |
| 456 | } |
| 457 | |
| 458 | if (info->flash_id == FLASH_UNKNOWN) { |
| 459 | printf ("Can't erase unknown flash type - aborted\n"); |
| 460 | return 1; |
| 461 | } |
| 462 | |
| 463 | prot = 0; |
| 464 | for (sect=s_first; sect<=s_last; ++sect) { |
| 465 | if (info->protect[sect]) { |
| 466 | prot++; |
| 467 | } |
| 468 | } |
| 469 | |
| 470 | if (prot) { |
| 471 | printf ("- Warning: %d protected sectors will not be erased!\n", |
| 472 | prot); |
| 473 | } else { |
| 474 | printf ("\n"); |
| 475 | } |
| 476 | |
| 477 | l_sect = -1; |
| 478 | |
| 479 | /* Disable interrupts which might cause a timeout here */ |
| 480 | flag = disable_interrupts(); |
| 481 | |
| 482 | /* Start erase on unprotected sectors */ |
| 483 | for (sect = s_first; sect<=s_last; sect++) { |
| 484 | if (info->protect[sect] == 0) { /* not protected */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 485 | addr2 = (CONFIG_SYS_FLASH_WORD_SIZE *)(info->start[sect]); |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 486 | if ((info->flash_id & FLASH_VENDMASK) == FLASH_MAN_SST) { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 487 | addr[CONFIG_SYS_FLASH_ADDR0] = (CONFIG_SYS_FLASH_WORD_SIZE)0x00AA00AA; |
| 488 | addr[CONFIG_SYS_FLASH_ADDR1] = (CONFIG_SYS_FLASH_WORD_SIZE)0x00550055; |
| 489 | addr[CONFIG_SYS_FLASH_ADDR0] = (CONFIG_SYS_FLASH_WORD_SIZE)0x00800080; |
| 490 | addr[CONFIG_SYS_FLASH_ADDR0] = (CONFIG_SYS_FLASH_WORD_SIZE)0x00AA00AA; |
| 491 | addr[CONFIG_SYS_FLASH_ADDR1] = (CONFIG_SYS_FLASH_WORD_SIZE)0x00550055; |
| 492 | addr2[0] = (CONFIG_SYS_FLASH_WORD_SIZE)0x00500050; /* block erase */ |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 493 | for (i=0; i<50; i++) |
| 494 | udelay(1000); /* wait 1 ms */ |
| 495 | } else { |
| 496 | if (sect == s_first) { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 497 | addr[CONFIG_SYS_FLASH_ADDR0] = (CONFIG_SYS_FLASH_WORD_SIZE)0x00AA00AA; |
| 498 | addr[CONFIG_SYS_FLASH_ADDR1] = (CONFIG_SYS_FLASH_WORD_SIZE)0x00550055; |
| 499 | addr[CONFIG_SYS_FLASH_ADDR0] = (CONFIG_SYS_FLASH_WORD_SIZE)0x00800080; |
| 500 | addr[CONFIG_SYS_FLASH_ADDR0] = (CONFIG_SYS_FLASH_WORD_SIZE)0x00AA00AA; |
| 501 | addr[CONFIG_SYS_FLASH_ADDR1] = (CONFIG_SYS_FLASH_WORD_SIZE)0x00550055; |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 502 | } |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 503 | addr2[0] = (CONFIG_SYS_FLASH_WORD_SIZE)0x00300030; /* sector erase */ |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 504 | } |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 505 | l_sect = sect; |
| 506 | } |
| 507 | } |
| 508 | |
| 509 | /* re-enable interrupts if necessary */ |
| 510 | if (flag) |
| 511 | enable_interrupts(); |
| 512 | |
| 513 | /* wait at least 80us - let's wait 1 ms */ |
| 514 | udelay (1000); |
| 515 | |
| 516 | /* |
| 517 | * We wait for the last triggered sector |
| 518 | */ |
| 519 | if (l_sect < 0) |
| 520 | goto DONE; |
| 521 | |
| 522 | start = get_timer (0); |
| 523 | last = start; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 524 | addr = (CONFIG_SYS_FLASH_WORD_SIZE *)(info->start[l_sect]); |
| 525 | while ((addr[0] & (CONFIG_SYS_FLASH_WORD_SIZE)0x00800080) != (CONFIG_SYS_FLASH_WORD_SIZE)0x00800080) { |
| 526 | if ((now = get_timer(start)) > CONFIG_SYS_FLASH_ERASE_TOUT) { |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 527 | printf ("Timeout\n"); |
| 528 | return 1; |
| 529 | } |
| 530 | /* show that we're waiting */ |
| 531 | if ((now - last) > 1000) { /* every second */ |
| 532 | putc ('.'); |
| 533 | last = now; |
| 534 | } |
| 535 | } |
| 536 | |
| 537 | DONE: |
| 538 | /* reset to read mode */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 539 | addr = (CONFIG_SYS_FLASH_WORD_SIZE *)info->start[0]; |
| 540 | addr[0] = (CONFIG_SYS_FLASH_WORD_SIZE)0x00F000F0; /* reset bank */ |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 541 | |
| 542 | printf (" done\n"); |
| 543 | return 0; |
| 544 | } |
| 545 | |
| 546 | /*----------------------------------------------------------------------- |
| 547 | * Copy memory to flash, returns: |
| 548 | * 0 - OK |
| 549 | * 1 - write timeout |
| 550 | * 2 - Flash not erased |
| 551 | */ |
| 552 | |
| 553 | int write_buff (flash_info_t *info, uchar *src, ulong addr, ulong cnt) |
| 554 | { |
| 555 | ulong cp, wp, data; |
| 556 | int i, l, rc; |
| 557 | |
| 558 | wp = (addr & ~3); /* get lower word aligned address */ |
| 559 | |
| 560 | /* |
| 561 | * handle unaligned start bytes |
| 562 | */ |
| 563 | if ((l = addr - wp) != 0) { |
| 564 | data = 0; |
| 565 | for (i=0, cp=wp; i<l; ++i, ++cp) { |
wdenk | 074cff0 | 2004-02-24 00:16:43 +0000 | [diff] [blame] | 566 | #ifdef CONFIG_B2 |
| 567 | data = data | ((*(uchar *)cp)<<(8*i)); |
| 568 | #else |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 569 | data = (data << 8) | (*(uchar *)cp); |
wdenk | 074cff0 | 2004-02-24 00:16:43 +0000 | [diff] [blame] | 570 | #endif |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 571 | } |
| 572 | for (; i<4 && cnt>0; ++i) { |
wdenk | 074cff0 | 2004-02-24 00:16:43 +0000 | [diff] [blame] | 573 | #ifdef CONFIG_B2 |
| 574 | data = data | ((*src++)<<(8*i)); |
| 575 | #else |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 576 | data = (data << 8) | *src++; |
wdenk | 074cff0 | 2004-02-24 00:16:43 +0000 | [diff] [blame] | 577 | #endif |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 578 | --cnt; |
| 579 | ++cp; |
| 580 | } |
| 581 | for (; cnt==0 && i<4; ++i, ++cp) { |
wdenk | 074cff0 | 2004-02-24 00:16:43 +0000 | [diff] [blame] | 582 | #ifdef CONFIG_B2 |
| 583 | data = data | ((*(uchar *)cp)<<(8*i)); |
| 584 | #else |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 585 | data = (data << 8) | (*(uchar *)cp); |
wdenk | 074cff0 | 2004-02-24 00:16:43 +0000 | [diff] [blame] | 586 | #endif |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 587 | } |
| 588 | |
| 589 | if ((rc = write_word(info, wp, data)) != 0) { |
| 590 | return (rc); |
| 591 | } |
| 592 | wp += 4; |
| 593 | } |
| 594 | |
| 595 | /* |
| 596 | * handle word aligned part |
| 597 | */ |
| 598 | while (cnt >= 4) { |
| 599 | data = 0; |
wdenk | 074cff0 | 2004-02-24 00:16:43 +0000 | [diff] [blame] | 600 | #ifdef CONFIG_B2 |
| 601 | data = (*(ulong*)src); |
| 602 | src += 4; |
| 603 | #else |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 604 | for (i=0; i<4; ++i) { |
| 605 | data = (data << 8) | *src++; |
| 606 | } |
wdenk | 074cff0 | 2004-02-24 00:16:43 +0000 | [diff] [blame] | 607 | #endif |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 608 | if ((rc = write_word(info, wp, data)) != 0) { |
| 609 | return (rc); |
| 610 | } |
| 611 | wp += 4; |
| 612 | cnt -= 4; |
| 613 | } |
| 614 | |
| 615 | if (cnt == 0) { |
| 616 | return (0); |
| 617 | } |
| 618 | |
| 619 | /* |
| 620 | * handle unaligned tail bytes |
| 621 | */ |
| 622 | data = 0; |
| 623 | for (i=0, cp=wp; i<4 && cnt>0; ++i, ++cp) { |
wdenk | 074cff0 | 2004-02-24 00:16:43 +0000 | [diff] [blame] | 624 | #ifdef CONFIG_B2 |
| 625 | data = data | ((*src++)<<(8*i)); |
| 626 | #else |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 627 | data = (data << 8) | *src++; |
wdenk | 074cff0 | 2004-02-24 00:16:43 +0000 | [diff] [blame] | 628 | #endif |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 629 | --cnt; |
| 630 | } |
| 631 | for (; i<4; ++i, ++cp) { |
wdenk | 074cff0 | 2004-02-24 00:16:43 +0000 | [diff] [blame] | 632 | #ifdef CONFIG_B2 |
| 633 | data = data | ((*(uchar *)cp)<<(8*i)); |
| 634 | #else |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 635 | data = (data << 8) | (*(uchar *)cp); |
wdenk | 074cff0 | 2004-02-24 00:16:43 +0000 | [diff] [blame] | 636 | #endif |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 637 | } |
| 638 | |
| 639 | return (write_word(info, wp, data)); |
| 640 | } |
| 641 | |
| 642 | /*----------------------------------------------------------------------- |
| 643 | * Write a word to Flash, returns: |
| 644 | * 0 - OK |
| 645 | * 1 - write timeout |
| 646 | * 2 - Flash not erased |
| 647 | */ |
| 648 | static int write_word (flash_info_t *info, ulong dest, ulong data) |
| 649 | { |
Wolfgang Denk | 5168801 | 2009-09-11 11:28:21 +0200 | [diff] [blame] | 650 | ulong *data_ptr = &data; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 651 | volatile CONFIG_SYS_FLASH_WORD_SIZE *addr2 = (CONFIG_SYS_FLASH_WORD_SIZE *)(info->start[0]); |
| 652 | volatile CONFIG_SYS_FLASH_WORD_SIZE *dest2 = (CONFIG_SYS_FLASH_WORD_SIZE *)dest; |
Wolfgang Denk | 5168801 | 2009-09-11 11:28:21 +0200 | [diff] [blame] | 653 | volatile CONFIG_SYS_FLASH_WORD_SIZE *data2 = (CONFIG_SYS_FLASH_WORD_SIZE *)data_ptr; |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 654 | ulong start; |
| 655 | int flag; |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 656 | int i; |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 657 | |
| 658 | /* Check if Flash is (sufficiently) erased */ |
wdenk | 998eaae | 2004-04-18 19:43:36 +0000 | [diff] [blame] | 659 | if ((*((volatile ulong *)dest) & data) != data) { |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 660 | return (2); |
| 661 | } |
| 662 | /* Disable interrupts which might cause a timeout here */ |
| 663 | flag = disable_interrupts(); |
| 664 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 665 | for (i=0; i<4/sizeof(CONFIG_SYS_FLASH_WORD_SIZE); i++) |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 666 | { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 667 | addr2[CONFIG_SYS_FLASH_ADDR0] = (CONFIG_SYS_FLASH_WORD_SIZE)0x00AA00AA; |
| 668 | addr2[CONFIG_SYS_FLASH_ADDR1] = (CONFIG_SYS_FLASH_WORD_SIZE)0x00550055; |
| 669 | addr2[CONFIG_SYS_FLASH_ADDR0] = (CONFIG_SYS_FLASH_WORD_SIZE)0x00A000A0; |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 670 | |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 671 | dest2[i] = data2[i]; |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 672 | |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 673 | /* re-enable interrupts if necessary */ |
| 674 | if (flag) |
| 675 | enable_interrupts(); |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 676 | |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 677 | /* data polling for D7 */ |
| 678 | start = get_timer (0); |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 679 | while ((dest2[i] & (CONFIG_SYS_FLASH_WORD_SIZE)0x00800080) != |
| 680 | (data2[i] & (CONFIG_SYS_FLASH_WORD_SIZE)0x00800080)) { |
| 681 | if (get_timer(start) > CONFIG_SYS_FLASH_WRITE_TOUT) { |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 682 | return (1); |
| 683 | } |
| 684 | } |
| 685 | } |
wdenk | 12f3424 | 2003-09-02 22:48:03 +0000 | [diff] [blame] | 686 | |
| 687 | return (0); |
| 688 | } |
| 689 | |
| 690 | /*----------------------------------------------------------------------- |
| 691 | */ |