3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * (C) Copyright 2002 Jun Gu <jung@artesyncp.com>
6 * Add support for Am29F016D and dynamic switch setting.
8 * See file CREDITS for list of people who contributed to this
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License as
13 * published by the Free Software Foundation; either version 2 of
14 * the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
29 * Wait for completion of each sector erase command issued
31 * Chris Hallinan - DS4.COM, Inc. - clh@net1plus.com
35 #include <asm/ppc4xx.h>
36 #include <asm/processor.h>
41 #define DEBUGF(x...) printf(x)
46 #define BOOT_SMALL_FLASH 32 /* 00100000 */
47 #define FLASH_ONBD_N 2 /* 00000010 */
48 #define FLASH_SRAM_SEL 1 /* 00000001 */
50 #define BOOT_SMALL_FLASH_VAL 4
51 #define FLASH_ONBD_N_VAL 2
52 #define FLASH_SRAM_SEL_VAL 1
54 static unsigned long flash_addr_table[8][CONFIG_SYS_MAX_FLASH_BANKS] = {
55 {0xffc00000, 0xffe00000, 0xff880000}, /* 0:000: configuraton 3 */
56 {0xffc00000, 0xffe00000, 0xff800000}, /* 1:001: configuraton 4 */
57 {0xffc00000, 0xffe00000, 0x00000000}, /* 2:010: configuraton 7 */
58 {0xffc00000, 0xffe00000, 0x00000000}, /* 3:011: configuraton 8 */
59 {0xff800000, 0xffa00000, 0xfff80000}, /* 4:100: configuraton 1 */
60 {0xff800000, 0xffa00000, 0xfff00000}, /* 5:101: configuraton 2 */
61 {0xffc00000, 0xffe00000, 0x00000000}, /* 6:110: configuraton 5 */
62 {0xffc00000, 0xffe00000, 0x00000000} /* 7:111: configuraton 6 */
66 * include common flash code (for amcc boards)
68 #include "../common/flash.c"
70 /*-----------------------------------------------------------------------
73 static ulong flash_get_size(vu_long * addr, flash_info_t * info);
76 * Override the weak default mapping function with a board specific one
78 u32 flash_get_bank_size(int cs, int idx)
80 u8 reg = in_8((void *)CONFIG_SYS_FPGA_BASE);
82 if ((reg & BOOT_SMALL_FLASH) && !(reg & FLASH_ONBD_N)) {
84 * cs0: small flash (512KiB)
85 * cs2: 2 * big flash (2 * 2MiB)
88 return flash_info[2].size;
90 return flash_info[0].size + flash_info[1].size;
93 * cs0: 2 * big flash (2 * 2MiB)
94 * cs2: small flash (512KiB)
97 return flash_info[0].size + flash_info[1].size;
99 return flash_info[2].size;
105 unsigned long flash_init(void)
107 unsigned long total_b = 0;
108 unsigned long size_b[CONFIG_SYS_MAX_FLASH_BANKS];
109 unsigned char *fpga_base = (unsigned char *)CONFIG_SYS_FPGA_BASE;
110 unsigned char switch_status;
111 unsigned short index = 0;
114 /* read FPGA base register FPGA_REG0 */
115 switch_status = *fpga_base;
117 /* check the bitmap of switch status */
118 if (switch_status & BOOT_SMALL_FLASH) {
119 index += BOOT_SMALL_FLASH_VAL;
121 if (switch_status & FLASH_ONBD_N) {
122 index += FLASH_ONBD_N_VAL;
124 if (switch_status & FLASH_SRAM_SEL) {
125 index += FLASH_SRAM_SEL_VAL;
129 DEBUGF("FLASH: Index: %d\n", index);
131 /* Init: no FLASHes known */
132 for (i = 0; i < CONFIG_SYS_MAX_FLASH_BANKS; ++i) {
133 flash_info[i].flash_id = FLASH_UNKNOWN;
134 flash_info[i].sector_count = -1;
135 flash_info[i].size = 0;
137 /* check whether the address is 0 */
138 if (flash_addr_table[index][i] == 0) {
142 /* call flash_get_size() to initialize sector address */
143 size_b[i] = flash_get_size((vu_long *)
144 flash_addr_table[index][i],
146 flash_info[i].size = size_b[i];
147 if (flash_info[i].flash_id == FLASH_UNKNOWN) {
148 printf("## Unknown FLASH on Bank %d - Size = 0x%08lx = %ld MB\n",
149 i, size_b[i], size_b[i] << 20);
150 flash_info[i].sector_count = -1;
151 flash_info[i].size = 0;
154 /* Monitor protection ON by default */
155 (void)flash_protect(FLAG_PROTECT_SET, CONFIG_SYS_MONITOR_BASE,
156 CONFIG_SYS_MONITOR_BASE + CONFIG_SYS_MONITOR_LEN - 1,
158 #ifdef CONFIG_ENV_IS_IN_FLASH
159 (void)flash_protect(FLAG_PROTECT_SET, CONFIG_ENV_ADDR,
160 CONFIG_ENV_ADDR + CONFIG_ENV_SECT_SIZE - 1,
162 (void)flash_protect(FLAG_PROTECT_SET, CONFIG_ENV_ADDR_REDUND,
163 CONFIG_ENV_ADDR_REDUND + CONFIG_ENV_SECT_SIZE - 1,
167 total_b += flash_info[i].size;