wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2000 |
| 3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 4 | * |
| 5 | * See file CREDITS for list of people who contributed to this |
| 6 | * project. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License as |
| 10 | * published by the Free Software Foundation; either version 2 of |
| 11 | * the License, or (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 21 | * MA 02111-1307 USA |
| 22 | */ |
| 23 | |
| 24 | #include <common.h> |
| 25 | #include <mpc8xx.h> |
| 26 | |
Wolfgang Denk | d0bb8d4 | 2011-11-04 15:55:38 +0000 | [diff] [blame^] | 27 | flash_info_t flash_info[CONFIG_SYS_MAX_FLASH_BANKS]; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 28 | |
| 29 | /*----------------------------------------------------------------------- |
| 30 | * Functions |
| 31 | */ |
Wolfgang Denk | d0bb8d4 | 2011-11-04 15:55:38 +0000 | [diff] [blame^] | 32 | static ulong flash_get_size(vu_long *addr, flash_info_t *info); |
| 33 | static int write_word(flash_info_t *info, ulong dest, ulong data); |
| 34 | static void flash_get_offsets(ulong base, flash_info_t *info); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 35 | |
| 36 | /*----------------------------------------------------------------------- |
| 37 | */ |
| 38 | |
Wolfgang Denk | d0bb8d4 | 2011-11-04 15:55:38 +0000 | [diff] [blame^] | 39 | unsigned long flash_init(void) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 40 | { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 41 | volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 42 | volatile memctl8xx_t *memctl = &immap->im_memctl; |
| 43 | unsigned long size_b0, size_b1; |
| 44 | int i; |
| 45 | |
| 46 | /* Init: no FLASHes known */ |
Wolfgang Denk | d0bb8d4 | 2011-11-04 15:55:38 +0000 | [diff] [blame^] | 47 | for (i = 0; i < CONFIG_SYS_MAX_FLASH_BANKS; ++i) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 48 | flash_info[i].flash_id = FLASH_UNKNOWN; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 49 | |
| 50 | /* Static FLASH Bank configuration here - FIXME XXX */ |
| 51 | |
| 52 | size_b0 = flash_get_size((vu_long *)FLASH_BASE0_PRELIM, &flash_info[0]); |
| 53 | |
| 54 | if (flash_info[0].flash_id == FLASH_UNKNOWN) { |
Wolfgang Denk | d0bb8d4 | 2011-11-04 15:55:38 +0000 | [diff] [blame^] | 55 | printf("## Unknown FLASH on Bank 0 - Size = 0x%08lx = %ld MB\n", |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 56 | size_b0, size_b0<<20); |
| 57 | } |
| 58 | |
| 59 | size_b1 = flash_get_size((vu_long *)FLASH_BASE1_PRELIM, &flash_info[1]); |
| 60 | |
| 61 | if (size_b1 > size_b0) { |
Wolfgang Denk | d0bb8d4 | 2011-11-04 15:55:38 +0000 | [diff] [blame^] | 62 | printf("## ERROR: " |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 63 | "Bank 1 (0x%08lx = %ld MB) > Bank 0 (0x%08lx = %ld MB)\n", |
| 64 | size_b1, size_b1<<20, |
| 65 | size_b0, size_b0<<20 |
| 66 | ); |
| 67 | flash_info[0].flash_id = FLASH_UNKNOWN; |
| 68 | flash_info[1].flash_id = FLASH_UNKNOWN; |
| 69 | flash_info[0].sector_count = -1; |
| 70 | flash_info[1].sector_count = -1; |
| 71 | flash_info[0].size = 0; |
| 72 | flash_info[1].size = 0; |
Wolfgang Denk | d0bb8d4 | 2011-11-04 15:55:38 +0000 | [diff] [blame^] | 73 | return 0; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | /* Remap FLASH according to real size */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 77 | memctl->memc_or0 = CONFIG_SYS_OR_TIMING_FLASH | (-size_b0 & 0xFFFF8000); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 78 | #ifdef CONFIG_FLASH_16BIT |
Wolfgang Denk | d0bb8d4 | 2011-11-04 15:55:38 +0000 | [diff] [blame^] | 79 | memctl->memc_br0 = (CONFIG_SYS_FLASH_BASE & BR_BA_MSK) | |
| 80 | BR_MS_GPCM | BR_V | BR_PS_16; /* 16 Bit data port */ |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 81 | #else |
Wolfgang Denk | d0bb8d4 | 2011-11-04 15:55:38 +0000 | [diff] [blame^] | 82 | memctl->memc_br0 = (CONFIG_SYS_FLASH_BASE & BR_BA_MSK) | |
| 83 | BR_MS_GPCM | BR_V; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 84 | #endif |
| 85 | |
| 86 | /* Re-do sizing to get full correct info */ |
Wolfgang Denk | d0bb8d4 | 2011-11-04 15:55:38 +0000 | [diff] [blame^] | 87 | size_b0 = flash_get_size((vu_long *)CONFIG_SYS_FLASH_BASE, |
| 88 | &flash_info[0]); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 89 | |
Wolfgang Denk | d0bb8d4 | 2011-11-04 15:55:38 +0000 | [diff] [blame^] | 90 | flash_get_offsets(CONFIG_SYS_FLASH_BASE, &flash_info[0]); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 91 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 92 | #if CONFIG_SYS_MONITOR_BASE >= CONFIG_SYS_FLASH_BASE |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 93 | /* monitor protection ON by default */ |
| 94 | flash_protect(FLAG_PROTECT_SET, |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 95 | CONFIG_SYS_MONITOR_BASE, |
| 96 | CONFIG_SYS_MONITOR_BASE+monitor_flash_len-1, |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 97 | &flash_info[0]); |
| 98 | #endif |
| 99 | |
| 100 | if (size_b1) { |
Wolfgang Denk | d0bb8d4 | 2011-11-04 15:55:38 +0000 | [diff] [blame^] | 101 | memctl->memc_or1 = CONFIG_SYS_OR_TIMING_FLASH | |
| 102 | (-size_b1 & 0xFFFF8000); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 103 | #ifdef CONFIG_FLASH_16BIT |
Wolfgang Denk | d0bb8d4 | 2011-11-04 15:55:38 +0000 | [diff] [blame^] | 104 | memctl->memc_br1 = ((CONFIG_SYS_FLASH_BASE + size_b0) & |
| 105 | BR_BA_MSK) | BR_MS_GPCM | BR_V | BR_PS_16; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 106 | #else |
Wolfgang Denk | d0bb8d4 | 2011-11-04 15:55:38 +0000 | [diff] [blame^] | 107 | memctl->memc_br1 = ((CONFIG_SYS_FLASH_BASE + size_b0) & |
| 108 | BR_BA_MSK) | BR_MS_GPCM | BR_V; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 109 | #endif |
| 110 | |
| 111 | /* Re-do sizing to get full correct info */ |
Wolfgang Denk | d0bb8d4 | 2011-11-04 15:55:38 +0000 | [diff] [blame^] | 112 | size_b1 = flash_get_size((vu_long *)(CONFIG_SYS_FLASH_BASE + |
| 113 | size_b0), &flash_info[1]); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 114 | |
Wolfgang Denk | d0bb8d4 | 2011-11-04 15:55:38 +0000 | [diff] [blame^] | 115 | flash_get_offsets(CONFIG_SYS_FLASH_BASE + size_b0, |
| 116 | &flash_info[1]); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 117 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 118 | #if CONFIG_SYS_MONITOR_BASE >= CONFIG_SYS_FLASH_BASE |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 119 | /* monitor protection ON by default */ |
| 120 | flash_protect(FLAG_PROTECT_SET, |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 121 | CONFIG_SYS_MONITOR_BASE, |
| 122 | CONFIG_SYS_MONITOR_BASE+monitor_flash_len-1, |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 123 | &flash_info[1]); |
| 124 | #endif |
| 125 | } else { |
| 126 | memctl->memc_br1 = 0; /* invalidate bank */ |
| 127 | |
| 128 | flash_info[1].flash_id = FLASH_UNKNOWN; |
| 129 | flash_info[1].sector_count = -1; |
| 130 | } |
| 131 | |
| 132 | flash_info[0].size = size_b0; |
| 133 | flash_info[1].size = size_b1; |
| 134 | |
Wolfgang Denk | d0bb8d4 | 2011-11-04 15:55:38 +0000 | [diff] [blame^] | 135 | return size_b0 + size_b1; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | /*----------------------------------------------------------------------- |
| 139 | */ |
Wolfgang Denk | d0bb8d4 | 2011-11-04 15:55:38 +0000 | [diff] [blame^] | 140 | static void flash_get_offsets(ulong base, flash_info_t *info) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 141 | { |
| 142 | int i; |
| 143 | |
Wolfgang Denk | d0bb8d4 | 2011-11-04 15:55:38 +0000 | [diff] [blame^] | 144 | if (info->flash_id == FLASH_UNKNOWN) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 145 | return; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 146 | |
| 147 | if ((info->flash_id & FLASH_VENDMASK) == FLASH_MAN_SST) { |
Wolfgang Denk | d0bb8d4 | 2011-11-04 15:55:38 +0000 | [diff] [blame^] | 148 | for (i = 0; i < info->sector_count; i++) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 149 | info->start[i] = base + (i * 0x00002000); |
Wolfgang Denk | d0bb8d4 | 2011-11-04 15:55:38 +0000 | [diff] [blame^] | 150 | |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 151 | return; |
| 152 | } |
| 153 | |
| 154 | /* set up sector start address table */ |
| 155 | if (info->flash_id & FLASH_BTYPE) { |
| 156 | /* set sector offsets for bottom boot block type */ |
| 157 | #ifdef CONFIG_FLASH_16BIT |
| 158 | info->start[0] = base + 0x00000000; |
| 159 | info->start[1] = base + 0x00004000; |
| 160 | info->start[2] = base + 0x00006000; |
| 161 | info->start[3] = base + 0x00008000; |
Wolfgang Denk | d0bb8d4 | 2011-11-04 15:55:38 +0000 | [diff] [blame^] | 162 | for (i = 4; i < info->sector_count; i++) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 163 | info->start[i] = base + (i * 0x00010000) - 0x00030000; |
| 164 | #else |
| 165 | info->start[0] = base + 0x00000000; |
| 166 | info->start[1] = base + 0x00008000; |
| 167 | info->start[2] = base + 0x0000C000; |
| 168 | info->start[3] = base + 0x00010000; |
Wolfgang Denk | d0bb8d4 | 2011-11-04 15:55:38 +0000 | [diff] [blame^] | 169 | for (i = 4; i < info->sector_count; i++) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 170 | info->start[i] = base + (i * 0x00020000) - 0x00060000; |
| 171 | #endif |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 172 | } else { |
| 173 | /* set sector offsets for top boot block type */ |
| 174 | i = info->sector_count - 1; |
| 175 | info->start[i--] = base + info->size - 0x00008000; |
| 176 | info->start[i--] = base + info->size - 0x0000C000; |
| 177 | info->start[i--] = base + info->size - 0x00010000; |
Wolfgang Denk | d0bb8d4 | 2011-11-04 15:55:38 +0000 | [diff] [blame^] | 178 | for (; i >= 0; i--) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 179 | info->start[i] = base + i * 0x00020000; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 180 | } |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | /*----------------------------------------------------------------------- |
| 184 | */ |
Wolfgang Denk | d0bb8d4 | 2011-11-04 15:55:38 +0000 | [diff] [blame^] | 185 | void flash_print_info(flash_info_t *info) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 186 | { |
| 187 | int i; |
| 188 | |
| 189 | if (info->flash_id == FLASH_UNKNOWN) { |
Wolfgang Denk | d0bb8d4 | 2011-11-04 15:55:38 +0000 | [diff] [blame^] | 190 | printf("missing or unknown FLASH type\n"); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 191 | return; |
| 192 | } |
| 193 | |
| 194 | switch (info->flash_id & FLASH_VENDMASK) { |
Wolfgang Denk | d0bb8d4 | 2011-11-04 15:55:38 +0000 | [diff] [blame^] | 195 | case FLASH_MAN_AMD: |
| 196 | printf("AMD "); |
| 197 | break; |
| 198 | case FLASH_MAN_FUJ: |
| 199 | printf("FUJITSU "); |
| 200 | break; |
| 201 | case FLASH_MAN_SST: |
| 202 | printf("SST "); |
| 203 | break; |
| 204 | case FLASH_MAN_STM: |
| 205 | printf("STM "); |
| 206 | break; |
| 207 | default: |
| 208 | printf("Unknown Vendor "); |
| 209 | break; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | switch (info->flash_id & FLASH_TYPEMASK) { |
Wolfgang Denk | d0bb8d4 | 2011-11-04 15:55:38 +0000 | [diff] [blame^] | 213 | case FLASH_AM400B: |
| 214 | printf("AM29LV400B (4 Mbit, bottom boot sect)\n"); |
| 215 | break; |
| 216 | case FLASH_AM400T: |
| 217 | printf("AM29LV400T (4 Mbit, top boot sector)\n"); |
| 218 | break; |
| 219 | case FLASH_AM800B: |
| 220 | printf("AM29LV800B (8 Mbit, bottom boot sect)\n"); |
| 221 | break; |
| 222 | case FLASH_AM800T: |
| 223 | printf("AM29LV800T (8 Mbit, top boot sector)\n"); |
| 224 | break; |
| 225 | case FLASH_AM160B: |
| 226 | printf("AM29LV160B (16 Mbit, bottom boot sect)\n"); |
| 227 | break; |
| 228 | case FLASH_AM160T: |
| 229 | printf("AM29LV160T (16 Mbit, top boot sector)\n"); |
| 230 | break; |
| 231 | case FLASH_AM320B: |
| 232 | printf("AM29LV320B (32 Mbit, bottom boot sect)\n"); |
| 233 | break; |
| 234 | case FLASH_AM320T: |
| 235 | printf("AM29LV320T (32 Mbit, top boot sector)\n"); |
| 236 | break; |
| 237 | case FLASH_SST200A: |
| 238 | printf("39xF200A (2M = 128K x 16)\n"); |
| 239 | break; |
| 240 | case FLASH_SST400A: |
| 241 | printf("39xF400A (4M = 256K x 16)\n"); |
| 242 | break; |
| 243 | case FLASH_SST800A: |
| 244 | printf("39xF800A (8M = 512K x 16)\n"); |
| 245 | break; |
| 246 | case FLASH_STM800AB: |
| 247 | printf("M29W800AB (8M = 512K x 16)\n"); |
| 248 | break; |
| 249 | default: |
| 250 | printf("Unknown Chip Type\n"); |
| 251 | break; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 252 | } |
| 253 | |
Wolfgang Denk | d0bb8d4 | 2011-11-04 15:55:38 +0000 | [diff] [blame^] | 254 | printf(" Size: %ld MB in %d Sectors\n", |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 255 | info->size >> 20, info->sector_count); |
| 256 | |
Wolfgang Denk | d0bb8d4 | 2011-11-04 15:55:38 +0000 | [diff] [blame^] | 257 | printf(" Sector Start Addresses:"); |
| 258 | for (i = 0; i < info->sector_count; ++i) { |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 259 | if ((i % 5) == 0) |
Wolfgang Denk | d0bb8d4 | 2011-11-04 15:55:38 +0000 | [diff] [blame^] | 260 | printf("\n "); |
| 261 | printf(" %08lX%s", |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 262 | info->start[i], |
| 263 | info->protect[i] ? " (RO)" : " " |
| 264 | ); |
| 265 | } |
Wolfgang Denk | d0bb8d4 | 2011-11-04 15:55:38 +0000 | [diff] [blame^] | 266 | printf("\n"); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 267 | return; |
| 268 | } |
| 269 | |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 270 | /* |
| 271 | * The following code cannot be run from FLASH! |
| 272 | */ |
| 273 | |
Wolfgang Denk | d0bb8d4 | 2011-11-04 15:55:38 +0000 | [diff] [blame^] | 274 | static ulong flash_get_size(vu_long *addr, flash_info_t *info) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 275 | { |
| 276 | short i; |
| 277 | ulong value; |
| 278 | ulong base = (ulong)addr; |
| 279 | |
| 280 | /* Write auto select command: read Manufacturer ID */ |
| 281 | #ifdef CONFIG_FLASH_16BIT |
Wolfgang Denk | d0bb8d4 | 2011-11-04 15:55:38 +0000 | [diff] [blame^] | 282 | vu_short *s_addr = (vu_short *)addr; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 283 | s_addr[0x5555] = 0x00AA; |
| 284 | s_addr[0x2AAA] = 0x0055; |
| 285 | s_addr[0x5555] = 0x0090; |
| 286 | value = s_addr[0]; |
| 287 | value = value|(value<<16); |
| 288 | #else |
| 289 | addr[0x5555] = 0x00AA00AA; |
| 290 | addr[0x2AAA] = 0x00550055; |
| 291 | addr[0x5555] = 0x00900090; |
| 292 | value = addr[0]; |
| 293 | #endif |
| 294 | |
| 295 | switch (value) { |
| 296 | case AMD_MANUFACT: |
| 297 | info->flash_id = FLASH_MAN_AMD; |
| 298 | break; |
| 299 | case FUJ_MANUFACT: |
| 300 | info->flash_id = FLASH_MAN_FUJ; |
| 301 | break; |
| 302 | case SST_MANUFACT: |
| 303 | info->flash_id = FLASH_MAN_SST; |
| 304 | break; |
| 305 | case STM_MANUFACT: |
| 306 | info->flash_id = FLASH_MAN_STM; |
| 307 | break; |
| 308 | default: |
| 309 | info->flash_id = FLASH_UNKNOWN; |
| 310 | info->sector_count = 0; |
| 311 | info->size = 0; |
Wolfgang Denk | d0bb8d4 | 2011-11-04 15:55:38 +0000 | [diff] [blame^] | 312 | return 0; /* no or unknown flash */ |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 313 | } |
| 314 | #ifdef CONFIG_FLASH_16BIT |
| 315 | value = s_addr[1]; |
| 316 | value = value|(value<<16); |
| 317 | #else |
| 318 | value = addr[1]; /* device ID */ |
| 319 | #endif |
| 320 | |
| 321 | switch (value) { |
| 322 | case AMD_ID_LV400T: |
| 323 | info->flash_id += FLASH_AM400T; |
| 324 | info->sector_count = 11; |
| 325 | info->size = 0x00100000; |
| 326 | break; /* => 1 MB */ |
| 327 | |
| 328 | case AMD_ID_LV400B: |
| 329 | info->flash_id += FLASH_AM400B; |
| 330 | info->sector_count = 11; |
| 331 | info->size = 0x00100000; |
| 332 | break; /* => 1 MB */ |
| 333 | |
| 334 | case AMD_ID_LV800T: |
| 335 | info->flash_id += FLASH_AM800T; |
| 336 | info->sector_count = 19; |
| 337 | info->size = 0x00200000; |
| 338 | break; /* => 2 MB */ |
| 339 | |
| 340 | case AMD_ID_LV800B: |
| 341 | info->flash_id += FLASH_AM800B; |
| 342 | #ifdef CONFIG_FLASH_16BIT |
| 343 | info->sector_count = 19; |
| 344 | info->size = 0x00100000; /* => 1 MB */ |
| 345 | #else |
| 346 | info->sector_count = 19; |
| 347 | info->size = 0x00200000; /* => 2 MB */ |
| 348 | #endif |
| 349 | break; |
| 350 | |
| 351 | case AMD_ID_LV160T: |
| 352 | info->flash_id += FLASH_AM160T; |
| 353 | info->sector_count = 35; |
| 354 | info->size = 0x00400000; |
| 355 | break; /* => 4 MB */ |
| 356 | |
| 357 | case AMD_ID_LV160B: |
| 358 | info->flash_id += FLASH_AM160B; |
| 359 | #ifdef CONFIG_FLASH_16BIT |
| 360 | info->sector_count = 35; |
| 361 | info->size = 0x00200000; /* => 2 MB */ |
| 362 | #else |
| 363 | info->sector_count = 35; |
| 364 | info->size = 0x00400000; /* => 4 MB */ |
| 365 | #endif |
| 366 | |
| 367 | break; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 368 | case SST_ID_xF200A: |
| 369 | info->flash_id += FLASH_SST200A; |
Wolfgang Denk | d0bb8d4 | 2011-11-04 15:55:38 +0000 | [diff] [blame^] | 370 | info->sector_count = 64; /* 39xF200A (2M = 128K x 16) */ |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 371 | info->size = 0x00080000; |
| 372 | break; |
| 373 | case SST_ID_xF400A: |
| 374 | info->flash_id += FLASH_SST400A; |
Wolfgang Denk | d0bb8d4 | 2011-11-04 15:55:38 +0000 | [diff] [blame^] | 375 | info->sector_count = 128; /* 39xF400A (4M = 256K x 16) */ |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 376 | info->size = 0x00100000; |
| 377 | break; |
| 378 | case SST_ID_xF800A: |
| 379 | info->flash_id += FLASH_SST800A; |
Wolfgang Denk | d0bb8d4 | 2011-11-04 15:55:38 +0000 | [diff] [blame^] | 380 | info->sector_count = 256; /* 39xF800A (8M = 512K x 16) */ |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 381 | info->size = 0x00200000; |
| 382 | break; /* => 2 MB */ |
| 383 | case STM_ID_x800AB: |
| 384 | info->flash_id += FLASH_STM800AB; |
| 385 | info->sector_count = 19; |
| 386 | info->size = 0x00200000; |
| 387 | break; /* => 2 MB */ |
| 388 | default: |
| 389 | info->flash_id = FLASH_UNKNOWN; |
Wolfgang Denk | d0bb8d4 | 2011-11-04 15:55:38 +0000 | [diff] [blame^] | 390 | return 0; /* => no or unknown flash */ |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 391 | |
| 392 | } |
| 393 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 394 | if (info->sector_count > CONFIG_SYS_MAX_FLASH_SECT) { |
Wolfgang Denk | d0bb8d4 | 2011-11-04 15:55:38 +0000 | [diff] [blame^] | 395 | printf("** ERROR: sector count %d > max (%d) **\n", |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 396 | info->sector_count, CONFIG_SYS_MAX_FLASH_SECT); |
| 397 | info->sector_count = CONFIG_SYS_MAX_FLASH_SECT; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 398 | } |
| 399 | |
| 400 | if ((info->flash_id & FLASH_VENDMASK) == FLASH_MAN_SST) { |
Wolfgang Denk | d0bb8d4 | 2011-11-04 15:55:38 +0000 | [diff] [blame^] | 401 | for (i = 0; i < info->sector_count; i++) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 402 | info->start[i] = base + (i * 0x00002000); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 403 | } else { /* AMD and Fujitsu types */ |
| 404 | /* set up sector start address table */ |
| 405 | if (info->flash_id & FLASH_BTYPE) { |
Wolfgang Denk | d0bb8d4 | 2011-11-04 15:55:38 +0000 | [diff] [blame^] | 406 | /* set sector offsets for bottom boot block type */ |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 407 | #ifdef CONFIG_FLASH_16BIT |
| 408 | |
| 409 | info->start[0] = base + 0x00000000; |
| 410 | info->start[1] = base + 0x00004000; |
| 411 | info->start[2] = base + 0x00006000; |
| 412 | info->start[3] = base + 0x00008000; |
Wolfgang Denk | d0bb8d4 | 2011-11-04 15:55:38 +0000 | [diff] [blame^] | 413 | for (i = 4; i < info->sector_count; i++) |
| 414 | info->start[i] = base + |
| 415 | (i * 0x00010000) - 0x00030000; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 416 | #else |
| 417 | info->start[0] = base + 0x00000000; |
| 418 | info->start[1] = base + 0x00008000; |
| 419 | info->start[2] = base + 0x0000C000; |
| 420 | info->start[3] = base + 0x00010000; |
Wolfgang Denk | d0bb8d4 | 2011-11-04 15:55:38 +0000 | [diff] [blame^] | 421 | for (i = 4; i < info->sector_count; i++) |
| 422 | info->start[i] = base + |
| 423 | (i * 0x00020000) - 0x00060000; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 424 | #endif |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 425 | } else { |
Wolfgang Denk | d0bb8d4 | 2011-11-04 15:55:38 +0000 | [diff] [blame^] | 426 | /* set sector offsets for top boot block type */ |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 427 | i = info->sector_count - 1; |
| 428 | info->start[i--] = base + info->size - 0x00008000; |
| 429 | info->start[i--] = base + info->size - 0x0000C000; |
| 430 | info->start[i--] = base + info->size - 0x00010000; |
Wolfgang Denk | d0bb8d4 | 2011-11-04 15:55:38 +0000 | [diff] [blame^] | 431 | for (; i >= 0; i--) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 432 | info->start[i] = base + i * 0x00020000; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 433 | } |
| 434 | |
| 435 | /* check for protected sectors */ |
| 436 | for (i = 0; i < info->sector_count; i++) { |
Wolfgang Denk | d0bb8d4 | 2011-11-04 15:55:38 +0000 | [diff] [blame^] | 437 | /* |
| 438 | * read sector protection at sector address: |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 439 | * (A7 .. A0) = 0x02 |
| 440 | * D0 = 1 if protected |
| 441 | */ |
| 442 | #ifdef CONFIG_FLASH_16BIT |
| 443 | s_addr = (volatile unsigned short *)(info->start[i]); |
| 444 | info->protect[i] = s_addr[2] & 1; |
| 445 | #else |
| 446 | addr = (volatile unsigned long *)(info->start[i]); |
| 447 | info->protect[i] = addr[2] & 1; |
| 448 | #endif |
| 449 | } |
| 450 | } |
| 451 | |
| 452 | /* |
| 453 | * Prevent writes to uninitialized FLASH. |
| 454 | */ |
| 455 | if (info->flash_id != FLASH_UNKNOWN) { |
| 456 | #ifdef CONFIG_FLASH_16BIT |
| 457 | s_addr = (volatile unsigned short *)(info->start[0]); |
| 458 | *s_addr = 0x00F0; /* reset bank */ |
| 459 | #else |
| 460 | addr = (volatile unsigned long *)info->start[0]; |
| 461 | *addr = 0x00F000F0; /* reset bank */ |
| 462 | #endif |
| 463 | |
| 464 | } |
Wolfgang Denk | d0bb8d4 | 2011-11-04 15:55:38 +0000 | [diff] [blame^] | 465 | return info->size; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 466 | } |
| 467 | |
Wolfgang Denk | d0bb8d4 | 2011-11-04 15:55:38 +0000 | [diff] [blame^] | 468 | int flash_erase(flash_info_t *info, int s_first, int s_last) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 469 | { |
Wolfgang Denk | d0bb8d4 | 2011-11-04 15:55:38 +0000 | [diff] [blame^] | 470 | vu_long *addr = (vu_long *)(info->start[0]); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 471 | int flag, prot, sect; |
| 472 | ulong start, now, last; |
| 473 | #ifdef CONFIG_FLASH_16BIT |
Wolfgang Denk | d0bb8d4 | 2011-11-04 15:55:38 +0000 | [diff] [blame^] | 474 | vu_short *s_addr = (vu_short *)addr; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 475 | #endif |
| 476 | |
| 477 | if ((s_first < 0) || (s_first > s_last)) { |
Wolfgang Denk | d0bb8d4 | 2011-11-04 15:55:38 +0000 | [diff] [blame^] | 478 | if (info->flash_id == FLASH_UNKNOWN) |
| 479 | printf("- missing\n"); |
| 480 | else |
| 481 | printf("- no sectors to erase\n"); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 482 | return 1; |
| 483 | } |
| 484 | /*#ifndef CONFIG_FLASH_16BIT |
| 485 | ulong type; |
| 486 | type = (info->flash_id & FLASH_VENDMASK); |
| 487 | if ((type != FLASH_MAN_SST) && (type != FLASH_MAN_STM)) { |
| 488 | printf ("Can't erase unknown flash type %08lx - aborted\n", |
| 489 | info->flash_id); |
| 490 | return; |
| 491 | } |
| 492 | #endif*/ |
| 493 | prot = 0; |
Wolfgang Denk | d0bb8d4 | 2011-11-04 15:55:38 +0000 | [diff] [blame^] | 494 | for (sect = s_first; sect <= s_last; ++sect) { |
| 495 | if (info->protect[sect]) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 496 | prot++; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 497 | } |
| 498 | |
| 499 | if (prot) { |
Wolfgang Denk | d0bb8d4 | 2011-11-04 15:55:38 +0000 | [diff] [blame^] | 500 | printf("- Warning: %d protected sectors will not be erased!\n", |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 501 | prot); |
| 502 | } else { |
Wolfgang Denk | d0bb8d4 | 2011-11-04 15:55:38 +0000 | [diff] [blame^] | 503 | printf("\n"); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 504 | } |
| 505 | |
Wolfgang Denk | d0bb8d4 | 2011-11-04 15:55:38 +0000 | [diff] [blame^] | 506 | start = get_timer(0); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 507 | last = start; |
| 508 | /* Start erase on unprotected sectors */ |
Wolfgang Denk | d0bb8d4 | 2011-11-04 15:55:38 +0000 | [diff] [blame^] | 509 | for (sect = s_first; sect <= s_last; sect++) { |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 510 | if (info->protect[sect] == 0) { /* not protected */ |
| 511 | #ifdef CONFIG_FLASH_16BIT |
Wolfgang Denk | d0bb8d4 | 2011-11-04 15:55:38 +0000 | [diff] [blame^] | 512 | vu_short *s_sect_addr = (vu_short *)(info->start[sect]); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 513 | #else |
Wolfgang Denk | d0bb8d4 | 2011-11-04 15:55:38 +0000 | [diff] [blame^] | 514 | vu_long *sect_addr = (vu_long *)(info->start[sect]); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 515 | #endif |
Wolfgang Denk | d0bb8d4 | 2011-11-04 15:55:38 +0000 | [diff] [blame^] | 516 | /* Disable interrupts which might cause a timeout */ |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 517 | flag = disable_interrupts(); |
| 518 | |
| 519 | #ifdef CONFIG_FLASH_16BIT |
| 520 | |
| 521 | /*printf("\ns_sect_addr=%x",s_sect_addr);*/ |
| 522 | s_addr[0x5555] = 0x00AA; |
| 523 | s_addr[0x2AAA] = 0x0055; |
| 524 | s_addr[0x5555] = 0x0080; |
| 525 | s_addr[0x5555] = 0x00AA; |
| 526 | s_addr[0x2AAA] = 0x0055; |
| 527 | s_sect_addr[0] = 0x0030; |
| 528 | #else |
| 529 | addr[0x5555] = 0x00AA00AA; |
| 530 | addr[0x2AAA] = 0x00550055; |
| 531 | addr[0x5555] = 0x00800080; |
| 532 | addr[0x5555] = 0x00AA00AA; |
| 533 | addr[0x2AAA] = 0x00550055; |
| 534 | sect_addr[0] = 0x00300030; |
| 535 | #endif |
| 536 | /* re-enable interrupts if necessary */ |
| 537 | if (flag) |
| 538 | enable_interrupts(); |
| 539 | |
| 540 | /* wait at least 80us - let's wait 1 ms */ |
Wolfgang Denk | d0bb8d4 | 2011-11-04 15:55:38 +0000 | [diff] [blame^] | 541 | udelay(1000); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 542 | |
| 543 | #ifdef CONFIG_FLASH_16BIT |
| 544 | while ((s_sect_addr[0] & 0x0080) != 0x0080) { |
| 545 | #else |
| 546 | while ((sect_addr[0] & 0x00800080) != 0x00800080) { |
| 547 | #endif |
Wolfgang Denk | d0bb8d4 | 2011-11-04 15:55:38 +0000 | [diff] [blame^] | 548 | now = get_timer(start); |
| 549 | if (now > CONFIG_SYS_FLASH_ERASE_TOUT) { |
| 550 | printf("Timeout\n"); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 551 | return 1; |
| 552 | } |
Wolfgang Denk | d0bb8d4 | 2011-11-04 15:55:38 +0000 | [diff] [blame^] | 553 | /* show every second that we're waiting */ |
| 554 | if ((now - last) > 1000) { |
| 555 | putc('.'); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 556 | last = now; |
| 557 | } |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | /* reset to read mode */ |
| 563 | addr = (volatile unsigned long *)info->start[0]; |
| 564 | #ifdef CONFIG_FLASH_16BIT |
| 565 | s_addr[0] = 0x00F0; /* reset bank */ |
| 566 | #else |
| 567 | addr[0] = 0x00F000F0; /* reset bank */ |
| 568 | #endif |
| 569 | |
Wolfgang Denk | d0bb8d4 | 2011-11-04 15:55:38 +0000 | [diff] [blame^] | 570 | printf(" done\n"); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 571 | return 0; |
| 572 | } |
| 573 | |
| 574 | /*----------------------------------------------------------------------- |
| 575 | * Copy memory to flash, returns: |
| 576 | * 0 - OK |
| 577 | * 1 - write timeout |
| 578 | * 2 - Flash not erased |
| 579 | * 4 - Flash not identified |
| 580 | */ |
| 581 | |
Wolfgang Denk | d0bb8d4 | 2011-11-04 15:55:38 +0000 | [diff] [blame^] | 582 | int write_buff(flash_info_t *info, uchar *src, ulong addr, ulong cnt) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 583 | { |
| 584 | ulong cp, wp, data; |
| 585 | int i, l, rc; |
| 586 | |
Wolfgang Denk | d0bb8d4 | 2011-11-04 15:55:38 +0000 | [diff] [blame^] | 587 | if (info->flash_id == FLASH_UNKNOWN) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 588 | return 4; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 589 | |
| 590 | wp = (addr & ~3); /* get lower word aligned address */ |
| 591 | |
| 592 | /* |
| 593 | * handle unaligned start bytes |
| 594 | */ |
Wolfgang Denk | d0bb8d4 | 2011-11-04 15:55:38 +0000 | [diff] [blame^] | 595 | l = addr - wp; |
| 596 | |
| 597 | if (l != 0) { |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 598 | data = 0; |
Wolfgang Denk | d0bb8d4 | 2011-11-04 15:55:38 +0000 | [diff] [blame^] | 599 | for (i = 0, cp = wp; i < l; ++i, ++cp) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 600 | data = (data << 8) | (*(uchar *)cp); |
Wolfgang Denk | d0bb8d4 | 2011-11-04 15:55:38 +0000 | [diff] [blame^] | 601 | |
| 602 | for (; i < 4 && cnt > 0; ++i) { |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 603 | data = (data << 8) | *src++; |
| 604 | --cnt; |
| 605 | ++cp; |
| 606 | } |
Wolfgang Denk | d0bb8d4 | 2011-11-04 15:55:38 +0000 | [diff] [blame^] | 607 | for (; cnt == 0 && i < 4; ++i, ++cp) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 608 | data = (data << 8) | (*(uchar *)cp); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 609 | |
Wolfgang Denk | d0bb8d4 | 2011-11-04 15:55:38 +0000 | [diff] [blame^] | 610 | rc = write_word(info, wp, data); |
| 611 | |
| 612 | if (rc != 0) |
| 613 | return rc; |
| 614 | |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 615 | wp += 4; |
| 616 | } |
| 617 | |
| 618 | /* |
| 619 | * handle word aligned part |
| 620 | */ |
| 621 | while (cnt >= 4) { |
| 622 | data = 0; |
Wolfgang Denk | d0bb8d4 | 2011-11-04 15:55:38 +0000 | [diff] [blame^] | 623 | for (i = 0; i < 4; ++i) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 624 | data = (data << 8) | *src++; |
Wolfgang Denk | d0bb8d4 | 2011-11-04 15:55:38 +0000 | [diff] [blame^] | 625 | |
| 626 | rc = write_word(info, wp, data); |
| 627 | if (rc != 0) |
| 628 | return rc; |
| 629 | |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 630 | wp += 4; |
| 631 | cnt -= 4; |
| 632 | } |
| 633 | |
Wolfgang Denk | d0bb8d4 | 2011-11-04 15:55:38 +0000 | [diff] [blame^] | 634 | if (cnt == 0) |
| 635 | return 0; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 636 | |
| 637 | /* |
| 638 | * handle unaligned tail bytes |
| 639 | */ |
| 640 | data = 0; |
Wolfgang Denk | d0bb8d4 | 2011-11-04 15:55:38 +0000 | [diff] [blame^] | 641 | for (i = 0, cp = wp; i < 4 && cnt > 0; ++i, ++cp) { |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 642 | data = (data << 8) | *src++; |
| 643 | --cnt; |
| 644 | } |
Wolfgang Denk | d0bb8d4 | 2011-11-04 15:55:38 +0000 | [diff] [blame^] | 645 | for (; i < 4; ++i, ++cp) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 646 | data = (data << 8) | (*(uchar *)cp); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 647 | |
Wolfgang Denk | d0bb8d4 | 2011-11-04 15:55:38 +0000 | [diff] [blame^] | 648 | return write_word(info, wp, data); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 649 | } |
| 650 | |
| 651 | /*----------------------------------------------------------------------- |
| 652 | * Write a word to Flash, returns: |
| 653 | * 0 - OK |
| 654 | * 1 - write timeout |
| 655 | * 2 - Flash not erased |
| 656 | */ |
Wolfgang Denk | d0bb8d4 | 2011-11-04 15:55:38 +0000 | [diff] [blame^] | 657 | static int write_word(flash_info_t *info, ulong dest, ulong data) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 658 | { |
Wolfgang Denk | d0bb8d4 | 2011-11-04 15:55:38 +0000 | [diff] [blame^] | 659 | vu_long *addr = (vu_long *)(info->start[0]); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 660 | |
| 661 | #ifdef CONFIG_FLASH_16BIT |
| 662 | vu_short high_data; |
| 663 | vu_short low_data; |
Wolfgang Denk | d0bb8d4 | 2011-11-04 15:55:38 +0000 | [diff] [blame^] | 664 | vu_short *s_addr = (vu_short *)addr; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 665 | #endif |
| 666 | ulong start; |
| 667 | int flag; |
| 668 | |
| 669 | /* Check if Flash is (sufficiently) erased */ |
Wolfgang Denk | d0bb8d4 | 2011-11-04 15:55:38 +0000 | [diff] [blame^] | 670 | if ((*((vu_long *)dest) & data) != data) |
| 671 | return 2; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 672 | |
| 673 | #ifdef CONFIG_FLASH_16BIT |
| 674 | /* Write the 16 higher-bits */ |
| 675 | /* Disable interrupts which might cause a timeout here */ |
| 676 | flag = disable_interrupts(); |
| 677 | |
| 678 | high_data = ((data>>16) & 0x0000ffff); |
| 679 | |
| 680 | s_addr[0x5555] = 0x00AA; |
| 681 | s_addr[0x2AAA] = 0x0055; |
| 682 | s_addr[0x5555] = 0x00A0; |
| 683 | |
| 684 | *((vu_short *)dest) = high_data; |
| 685 | |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 686 | /* re-enable interrupts if necessary */ |
| 687 | if (flag) |
| 688 | enable_interrupts(); |
| 689 | |
| 690 | /* data polling for D7 */ |
Wolfgang Denk | d0bb8d4 | 2011-11-04 15:55:38 +0000 | [diff] [blame^] | 691 | start = get_timer(0); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 692 | while ((*((vu_short *)dest) & 0x0080) != (high_data & 0x0080)) { |
Wolfgang Denk | d0bb8d4 | 2011-11-04 15:55:38 +0000 | [diff] [blame^] | 693 | if (get_timer(start) > CONFIG_SYS_FLASH_WRITE_TOUT) |
| 694 | return 1; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 695 | } |
| 696 | |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 697 | /* Write the 16 lower-bits */ |
| 698 | #endif |
| 699 | |
| 700 | /* Disable interrupts which might cause a timeout here */ |
| 701 | flag = disable_interrupts(); |
| 702 | #ifdef CONFIG_FLASH_16BIT |
| 703 | dest += 0x2; |
| 704 | low_data = (data & 0x0000ffff); |
| 705 | |
| 706 | s_addr[0x5555] = 0x00AA; |
| 707 | s_addr[0x2AAA] = 0x0055; |
| 708 | s_addr[0x5555] = 0x00A0; |
| 709 | *((vu_short *)dest) = low_data; |
| 710 | |
| 711 | #else |
| 712 | addr[0x5555] = 0x00AA00AA; |
| 713 | addr[0x2AAA] = 0x00550055; |
| 714 | addr[0x5555] = 0x00A000A0; |
| 715 | *((vu_long *)dest) = data; |
| 716 | #endif |
| 717 | |
| 718 | /* re-enable interrupts if necessary */ |
| 719 | if (flag) |
| 720 | enable_interrupts(); |
| 721 | |
| 722 | /* data polling for D7 */ |
Wolfgang Denk | d0bb8d4 | 2011-11-04 15:55:38 +0000 | [diff] [blame^] | 723 | start = get_timer(0); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 724 | |
| 725 | #ifdef CONFIG_FLASH_16BIT |
| 726 | while ((*((vu_short *)dest) & 0x0080) != (low_data & 0x0080)) { |
| 727 | #else |
| 728 | while ((*((vu_long *)dest) & 0x00800080) != (data & 0x00800080)) { |
| 729 | #endif |
| 730 | |
Wolfgang Denk | d0bb8d4 | 2011-11-04 15:55:38 +0000 | [diff] [blame^] | 731 | if (get_timer(start) > CONFIG_SYS_FLASH_WRITE_TOUT) |
| 732 | return 1; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 733 | } |
Wolfgang Denk | d0bb8d4 | 2011-11-04 15:55:38 +0000 | [diff] [blame^] | 734 | return 0; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 735 | } |