blob: 5740a5623b3e20251034a190fd33255814bfee7c [file] [log] [blame]
Stefan Roese8a316c92005-08-01 16:49:12 +02001/*
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 Denk1a459662013-07-08 09:37:19 +02008 * SPDX-License-Identifier: GPL-2.0+
Stefan Roese8a316c92005-08-01 16:49:12 +02009 */
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 Roeseb36df562010-09-09 19:18:00 +020019#include <asm/ppc4xx.h>
Stefan Roese8a316c92005-08-01 16:49:12 +020020#include <asm/processor.h>
Stefan Roese8a805df2010-09-16 14:01:53 +020021#include <asm/io.h>
Stefan Roese8a316c92005-08-01 16:49:12 +020022
23#undef DEBUG
24#ifdef DEBUG
25#define DEBUGF(x...) printf(x)
26#else
27#define DEBUGF(x...)
28#endif /* DEBUG */
29
30#define BOOT_SMALL_FLASH 32 /* 00100000 */
31#define FLASH_ONBD_N 2 /* 00000010 */
32#define FLASH_SRAM_SEL 1 /* 00000001 */
33
34#define BOOT_SMALL_FLASH_VAL 4
35#define FLASH_ONBD_N_VAL 2
36#define FLASH_SRAM_SEL_VAL 1
37
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020038static unsigned long flash_addr_table[8][CONFIG_SYS_MAX_FLASH_BANKS] = {
Stefan Roese8a316c92005-08-01 16:49:12 +020039 {0xffc00000, 0xffe00000, 0xff880000}, /* 0:000: configuraton 3 */
40 {0xffc00000, 0xffe00000, 0xff800000}, /* 1:001: configuraton 4 */
41 {0xffc00000, 0xffe00000, 0x00000000}, /* 2:010: configuraton 7 */
42 {0xffc00000, 0xffe00000, 0x00000000}, /* 3:011: configuraton 8 */
43 {0xff800000, 0xffa00000, 0xfff80000}, /* 4:100: configuraton 1 */
44 {0xff800000, 0xffa00000, 0xfff00000}, /* 5:101: configuraton 2 */
45 {0xffc00000, 0xffe00000, 0x00000000}, /* 6:110: configuraton 5 */
46 {0xffc00000, 0xffe00000, 0x00000000} /* 7:111: configuraton 6 */
47};
48
49/*
50 * include common flash code (for amcc boards)
51 */
52#include "../common/flash.c"
53
54/*-----------------------------------------------------------------------
55 * Functions
56 */
57static ulong flash_get_size(vu_long * addr, flash_info_t * info);
58
Stefan Roese8a805df2010-09-16 14:01:53 +020059/*
60 * Override the weak default mapping function with a board specific one
61 */
62u32 flash_get_bank_size(int cs, int idx)
63{
64 u8 reg = in_8((void *)CONFIG_SYS_FPGA_BASE);
65
66 if ((reg & BOOT_SMALL_FLASH) && !(reg & FLASH_ONBD_N)) {
67 /*
68 * cs0: small flash (512KiB)
69 * cs2: 2 * big flash (2 * 2MiB)
70 */
71 if (cs == 0)
72 return flash_info[2].size;
73 if (cs == 2)
74 return flash_info[0].size + flash_info[1].size;
75 } else {
76 /*
77 * cs0: 2 * big flash (2 * 2MiB)
78 * cs2: small flash (512KiB)
79 */
80 if (cs == 0)
81 return flash_info[0].size + flash_info[1].size;
82 if (cs == 2)
83 return flash_info[2].size;
84 }
85
86 return 0;
87}
88
Stefan Roese8a316c92005-08-01 16:49:12 +020089unsigned long flash_init(void)
90{
91 unsigned long total_b = 0;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020092 unsigned long size_b[CONFIG_SYS_MAX_FLASH_BANKS];
93 unsigned char *fpga_base = (unsigned char *)CONFIG_SYS_FPGA_BASE;
Stefan Roese8a316c92005-08-01 16:49:12 +020094 unsigned char switch_status;
95 unsigned short index = 0;
96 int i;
97
98 /* read FPGA base register FPGA_REG0 */
99 switch_status = *fpga_base;
100
101 /* check the bitmap of switch status */
102 if (switch_status & BOOT_SMALL_FLASH) {
103 index += BOOT_SMALL_FLASH_VAL;
104 }
105 if (switch_status & FLASH_ONBD_N) {
106 index += FLASH_ONBD_N_VAL;
107 }
108 if (switch_status & FLASH_SRAM_SEL) {
109 index += FLASH_SRAM_SEL_VAL;
110 }
111
112 DEBUGF("\n");
113 DEBUGF("FLASH: Index: %d\n", index);
114
115 /* Init: no FLASHes known */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200116 for (i = 0; i < CONFIG_SYS_MAX_FLASH_BANKS; ++i) {
Stefan Roese8a316c92005-08-01 16:49:12 +0200117 flash_info[i].flash_id = FLASH_UNKNOWN;
118 flash_info[i].sector_count = -1;
119 flash_info[i].size = 0;
120
121 /* check whether the address is 0 */
122 if (flash_addr_table[index][i] == 0) {
123 continue;
124 }
125
126 /* call flash_get_size() to initialize sector address */
127 size_b[i] = flash_get_size((vu_long *)
128 flash_addr_table[index][i],
129 &flash_info[i]);
130 flash_info[i].size = size_b[i];
131 if (flash_info[i].flash_id == FLASH_UNKNOWN) {
132 printf("## Unknown FLASH on Bank %d - Size = 0x%08lx = %ld MB\n",
133 i, size_b[i], size_b[i] << 20);
134 flash_info[i].sector_count = -1;
135 flash_info[i].size = 0;
136 }
137
138 /* Monitor protection ON by default */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200139 (void)flash_protect(FLAG_PROTECT_SET, CONFIG_SYS_MONITOR_BASE,
140 CONFIG_SYS_MONITOR_BASE + CONFIG_SYS_MONITOR_LEN - 1,
Stefan Roese8a316c92005-08-01 16:49:12 +0200141 &flash_info[2]);
Jean-Christophe PLAGNIOL-VILLARD5a1aceb2008-09-10 22:48:04 +0200142#ifdef CONFIG_ENV_IS_IN_FLASH
Jean-Christophe PLAGNIOL-VILLARD0e8d1582008-09-10 22:48:06 +0200143 (void)flash_protect(FLAG_PROTECT_SET, CONFIG_ENV_ADDR,
144 CONFIG_ENV_ADDR + CONFIG_ENV_SECT_SIZE - 1,
Stefan Roese8a316c92005-08-01 16:49:12 +0200145 &flash_info[2]);
Jean-Christophe PLAGNIOL-VILLARD0e8d1582008-09-10 22:48:06 +0200146 (void)flash_protect(FLAG_PROTECT_SET, CONFIG_ENV_ADDR_REDUND,
147 CONFIG_ENV_ADDR_REDUND + CONFIG_ENV_SECT_SIZE - 1,
Stefan Roese8a316c92005-08-01 16:49:12 +0200148 &flash_info[2]);
149#endif
150
151 total_b += flash_info[i].size;
152 }
153
154 return total_b;
155}