2 * (C) Copyright 2000-2005
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * See file CREDITS for list of people who contributed to this
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.
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.
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,
26 * Wait for completion of each sector erase command issued
28 * Chris Hallinan - DS4.COM, Inc. - clh@net1plus.com
33 #include <asm/processor.h>
37 #define DEBUGF(x...) printf(x)
43 * include common flash code (for amcc boards)
45 #include "../common/flash.c"
47 /*-----------------------------------------------------------------------
50 static ulong flash_get_size(vu_long * addr, flash_info_t * info);
51 static void flash_get_offsets(ulong base, flash_info_t * info);
53 unsigned long flash_init(void)
55 unsigned long size_b0, size_b1;
58 unsigned long base_b0, base_b1;
60 /* Init: no FLASHes known */
61 for (i = 0; i < CFG_MAX_FLASH_BANKS; ++i) {
62 flash_info[i].flash_id = FLASH_UNKNOWN;
65 /* Static FLASH Bank configuration here - FIXME XXX */
68 flash_get_size((vu_long *) FLASH_BASE0_PRELIM, &flash_info[0]);
70 if (flash_info[0].flash_id == FLASH_UNKNOWN) {
71 printf("## Unknown FLASH on Bank 0 - Size = 0x%08lx = %ld MB\n",
72 size_b0, size_b0 << 20);
76 if (CFG_MAX_FLASH_BANKS == 1) {
78 flash_get_offsets(FLASH_BASE0_PRELIM, &flash_info[0]);
80 /* Monitor protection ON by default */
81 (void)flash_protect(FLAG_PROTECT_SET,
83 CFG_MONITOR_BASE + CFG_MONITOR_LEN - 1,
85 #ifdef CONFIG_ENV_IS_IN_FLASH
86 (void)flash_protect(FLAG_PROTECT_SET, CONFIG_ENV_ADDR,
87 CONFIG_ENV_ADDR + CONFIG_ENV_SECT_SIZE - 1,
89 (void)flash_protect(FLAG_PROTECT_SET, CONFIG_ENV_ADDR_REDUND,
90 CONFIG_ENV_ADDR_REDUND + CONFIG_ENV_SECT_SIZE - 1,
95 flash_info[0].size = size_b0;
99 flash_get_size((vu_long *) FLASH_BASE1_PRELIM,
102 /* Re-do sizing to get full correct info */
105 mtdcr(ebccfga, pb0cr);
106 pbcr = mfdcr(ebccfgd);
107 mtdcr(ebccfga, pb0cr);
110 (pbcr & 0x0001ffff) | base_b1 |
111 (((size_b1 / 1024 / 1024) - 1) << 17);
112 mtdcr(ebccfgd, pbcr);
113 /* printf("pb1cr = %x\n", pbcr); */
117 mtdcr(ebccfga, pb1cr);
118 pbcr = mfdcr(ebccfgd);
119 mtdcr(ebccfga, pb1cr);
120 base_b0 = base_b1 - size_b0;
122 (pbcr & 0x0001ffff) | base_b0 |
123 (((size_b0 / 1024 / 1024) - 1) << 17);
124 mtdcr(ebccfgd, pbcr);
125 /* printf("pb0cr = %x\n", pbcr); */
128 size_b0 = flash_get_size((vu_long *) base_b0, &flash_info[0]);
130 flash_get_offsets(base_b0, &flash_info[0]);
132 /* monitor protection ON by default */
133 (void)flash_protect(FLAG_PROTECT_SET,
134 base_b0 + size_b0 - monitor_flash_len,
135 base_b0 + size_b0 - 1, &flash_info[0]);
138 /* Re-do sizing to get full correct info */
140 flash_get_size((vu_long *) base_b1, &flash_info[1]);
142 flash_get_offsets(base_b1, &flash_info[1]);
144 /* monitor protection ON by default */
145 (void)flash_protect(FLAG_PROTECT_SET,
148 base_b1 + size_b1 - 1,
150 /* monitor protection OFF by default (one is enough) */
151 (void)flash_protect(FLAG_PROTECT_CLEAR,
154 base_b0 + size_b0 - 1,
157 flash_info[1].flash_id = FLASH_UNKNOWN;
158 flash_info[1].sector_count = -1;
161 flash_info[0].size = size_b0;
162 flash_info[1].size = size_b1;
164 return (size_b0 + size_b1);
168 static void flash_get_offsets(ulong base, flash_info_t * info)
172 /* set up sector start address table */
173 if (((info->flash_id & FLASH_VENDMASK) == FLASH_MAN_SST) ||
174 (info->flash_id == FLASH_AM040)) {
175 for (i = 0; i < info->sector_count; i++)
176 info->start[i] = base + (i * 0x00010000);
178 if (info->flash_id & FLASH_BTYPE) {
179 /* set sector offsets for bottom boot block type */
180 info->start[0] = base + 0x00000000;
181 info->start[1] = base + 0x00004000;
182 info->start[2] = base + 0x00006000;
183 info->start[3] = base + 0x00008000;
184 for (i = 4; i < info->sector_count; i++) {
186 base + (i * 0x00010000) - 0x00030000;
189 /* set sector offsets for top boot block type */
190 i = info->sector_count - 1;
191 info->start[i--] = base + info->size - 0x00004000;
192 info->start[i--] = base + info->size - 0x00006000;
193 info->start[i--] = base + info->size - 0x00008000;
194 for (; i >= 0; i--) {
195 info->start[i] = base + i * 0x00010000;