blob: a242befb26954fd96d1a9ee1f6c0defb15d10358 [file] [log] [blame]
Stefan Roese99644742005-11-29 18:18:21 +01001/*
2 * (C) Copyright 2002
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
5 * (C) Copyright 2002 Jun Gu <jung@artesyncp.com>
6 * Add support for Am29F016D and dynamic switch setting.
7 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02008 * SPDX-License-Identifier: GPL-2.0+
Stefan Roese99644742005-11-29 18:18:21 +01009 */
10
11/*
12 * Modified 4/5/2001
13 * Wait for completion of each sector erase command issued
14 * 4/5/2001
15 * Chris Hallinan - DS4.COM, Inc. - clh@net1plus.com
16 */
17
18#include <common.h>
Stefan Roese247e9d72010-09-09 19:18:00 +020019#include <asm/ppc4xx.h>
Stefan Roese99644742005-11-29 18:18:21 +010020#include <asm/processor.h>
21
22#undef DEBUG
23#ifdef DEBUG
24#define DEBUGF(x...) printf(x)
25#else
26#define DEBUGF(x...)
27#endif /* DEBUG */
28
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020029static unsigned long flash_addr_table[1][CONFIG_SYS_MAX_FLASH_BANKS] = {
Stefan Roese99644742005-11-29 18:18:21 +010030 {0xff900000, 0xff980000, 0xffc00000}, /* 0:000: configuraton 3 */
31};
32
33/*
34 * include common flash code (for amcc boards)
35 */
36#include "../common/flash.c"
37
38/*-----------------------------------------------------------------------
39 * Functions
40 */
41static ulong flash_get_size(vu_long * addr, flash_info_t * info);
42
43unsigned long flash_init(void)
44{
45 unsigned long total_b = 0;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020046 unsigned long size_b[CONFIG_SYS_MAX_FLASH_BANKS];
Stefan Roese99644742005-11-29 18:18:21 +010047 unsigned short index = 0;
48 int i;
49
50 /* read FPGA base register FPGA_REG0 */
51
52 DEBUGF("\n");
53 DEBUGF("FLASH: Index: %d\n", index);
54
55 /* Init: no FLASHes known */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020056 for (i = 0; i < CONFIG_SYS_MAX_FLASH_BANKS; ++i) {
Stefan Roese99644742005-11-29 18:18:21 +010057 flash_info[i].flash_id = FLASH_UNKNOWN;
58 flash_info[i].sector_count = -1;
59 flash_info[i].size = 0;
60
61 /* check whether the address is 0 */
62 if (flash_addr_table[index][i] == 0) {
63 continue;
64 }
65
66 /* call flash_get_size() to initialize sector address */
67 size_b[i] = flash_get_size((vu_long *)
68 flash_addr_table[index][i],
69 &flash_info[i]);
70 flash_info[i].size = size_b[i];
71 if (flash_info[i].flash_id == FLASH_UNKNOWN) {
72 printf("## Unknown FLASH on Bank %d - Size = 0x%08lx = %ld MB\n",
73 i, size_b[i], size_b[i] << 20);
74 flash_info[i].sector_count = -1;
75 flash_info[i].size = 0;
76 }
77
78 /* Monitor protection ON by default */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020079 (void)flash_protect(FLAG_PROTECT_SET, CONFIG_SYS_MONITOR_BASE,
80 CONFIG_SYS_MONITOR_BASE + CONFIG_SYS_MONITOR_LEN - 1,
Stefan Roese99644742005-11-29 18:18:21 +010081 &flash_info[2]);
Jean-Christophe PLAGNIOL-VILLARD53db4cd2008-09-10 22:48:04 +020082#ifdef CONFIG_ENV_IS_IN_FLASH
Jean-Christophe PLAGNIOL-VILLARD7e1cda62008-09-10 22:48:06 +020083 (void)flash_protect(FLAG_PROTECT_SET, CONFIG_ENV_ADDR,
84 CONFIG_ENV_ADDR + CONFIG_ENV_SECT_SIZE - 1,
Stefan Roese99644742005-11-29 18:18:21 +010085 &flash_info[2]);
Jean-Christophe PLAGNIOL-VILLARD7e1cda62008-09-10 22:48:06 +020086 (void)flash_protect(FLAG_PROTECT_SET, CONFIG_ENV_ADDR_REDUND,
87 CONFIG_ENV_ADDR_REDUND + CONFIG_ENV_SECT_SIZE - 1,
Stefan Roese99644742005-11-29 18:18:21 +010088 &flash_info[2]);
89#endif
90
91 total_b += flash_info[i].size;
92 }
93
94 return total_b;
95}