blob: a9bbf045d4be09e3118bd20af2ae1cb3f3cf30e6 [file] [log] [blame]
Stefan Roese8a316c92005-08-01 16:49:12 +02001/*
2 * (C) Copyright 2004-2005
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>
21
22#undef DEBUG
23
24#ifdef DEBUG
25#define DEBUGF(x...) printf(x)
26#else
27#define DEBUGF(x...)
28#endif /* DEBUG */
29
30#define BOOT_SMALL_FLASH 0x40 /* 01000000 */
31#define FLASH_ONBD_N 2 /* 00000010 */
32#define FLASH_SRAM_SEL 1 /* 00000001 */
33#define FLASH_ONBD_N 2 /* 00000010 */
34#define FLASH_SRAM_SEL 1 /* 00000001 */
35
36#define BOOT_SMALL_FLASH_VAL 4
37#define FLASH_ONBD_N_VAL 2
38#define FLASH_SRAM_SEL_VAL 1
39
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020040flash_info_t flash_info[CONFIG_SYS_MAX_FLASH_BANKS]; /* info for FLASH chips */
Stefan Roese8a316c92005-08-01 16:49:12 +020041
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020042static unsigned long flash_addr_table[8][CONFIG_SYS_MAX_FLASH_BANKS] = {
Stefan Roese8a316c92005-08-01 16:49:12 +020043 {0xFF800000, 0xFF880000, 0xFFC00000}, /* 0:000: configuraton 4 */
44 {0xFF900000, 0xFF980000, 0xFFC00000}, /* 1:001: configuraton 3 */
45 {0x00000000, 0x00000000, 0x00000000}, /* 2:010: configuraton 8 */
46 {0x00000000, 0x00000000, 0x00000000}, /* 3:011: configuraton 7 */
47 {0xFFE00000, 0xFFF00000, 0xFF800000}, /* 4:100: configuraton 2 */
48 {0xFFF00000, 0xFFF80000, 0xFF800000}, /* 5:101: configuraton 1 */
49 {0x00000000, 0x00000000, 0x00000000}, /* 6:110: configuraton 6 */
50 {0x00000000, 0x00000000, 0x00000000} /* 7:111: configuraton 5 */
51};
52
53/*
54 * include common flash code (for amcc boards)
55 */
56#include "../common/flash.c"
57
58/*-----------------------------------------------------------------------
59 * Functions
60 */
61static ulong flash_get_size(vu_long * addr, flash_info_t * info);
62static int write_word(flash_info_t * info, ulong dest, ulong data);
63
64/*-----------------------------------------------------------------------
65 */
66
67unsigned long flash_init(void)
68{
69 unsigned long total_b = 0;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020070 unsigned long size_b[CONFIG_SYS_MAX_FLASH_BANKS];
71 unsigned char *fpga_base = (unsigned char *)CONFIG_SYS_FPGA_BASE;
Stefan Roese8a316c92005-08-01 16:49:12 +020072 unsigned char switch_status;
73 unsigned short index = 0;
74 int i;
75
76 /* read FPGA base register FPGA_REG0 */
77 switch_status = *fpga_base;
78
79 /* check the bitmap of switch status */
80 if (switch_status & BOOT_SMALL_FLASH) {
81 index += BOOT_SMALL_FLASH_VAL;
82 }
83 if (switch_status & FLASH_ONBD_N) {
84 index += FLASH_ONBD_N_VAL;
85 }
86 if (switch_status & FLASH_SRAM_SEL) {
87 index += FLASH_SRAM_SEL_VAL;
88 }
89
90 DEBUGF("\n");
91 DEBUGF("FLASH: Index: %d\n", index);
92
93 /* Init: no FLASHes known */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020094 for (i = 0; i < CONFIG_SYS_MAX_FLASH_BANKS; ++i) {
Stefan Roese8a316c92005-08-01 16:49:12 +020095 flash_info[i].flash_id = FLASH_UNKNOWN;
96 flash_info[i].sector_count = -1;
97 flash_info[i].size = 0;
98
99 /* check whether the address is 0 */
100 if (flash_addr_table[index][i] == 0) {
101 continue;
102 }
103
104 /* call flash_get_size() to initialize sector address */
105 size_b[i] =
106 flash_get_size((vu_long *) flash_addr_table[index][i],
107 &flash_info[i]);
108 flash_info[i].size = size_b[i];
109 if (flash_info[i].flash_id == FLASH_UNKNOWN) {
110 printf
111 ("## Unknown FLASH on Bank %d - Size = 0x%08lx = %ld MB\n",
112 i, size_b[i], size_b[i] << 20);
113 flash_info[i].sector_count = -1;
114 flash_info[i].size = 0;
115 }
116
117 /* Monitor protection ON by default */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200118 (void)flash_protect(FLAG_PROTECT_SET, CONFIG_SYS_MONITOR_BASE,
119 CONFIG_SYS_MONITOR_BASE + CONFIG_SYS_MONITOR_LEN - 1,
Stefan Roese8a316c92005-08-01 16:49:12 +0200120 &flash_info[i]);
Jean-Christophe PLAGNIOL-VILLARD5a1aceb2008-09-10 22:48:04 +0200121#ifdef CONFIG_ENV_IS_IN_FLASH
Jean-Christophe PLAGNIOL-VILLARD0e8d1582008-09-10 22:48:06 +0200122 (void)flash_protect(FLAG_PROTECT_SET, CONFIG_ENV_ADDR,
123 CONFIG_ENV_ADDR + CONFIG_ENV_SECT_SIZE - 1,
Stefan Roese8a316c92005-08-01 16:49:12 +0200124 &flash_info[i]);
Jean-Christophe PLAGNIOL-VILLARD0e8d1582008-09-10 22:48:06 +0200125 (void)flash_protect(FLAG_PROTECT_SET, CONFIG_ENV_ADDR_REDUND,
126 CONFIG_ENV_ADDR_REDUND + CONFIG_ENV_SECT_SIZE - 1,
Stefan Roese8a316c92005-08-01 16:49:12 +0200127 &flash_info[i]);
128#endif
129
130 total_b += flash_info[i].size;
131 }
132
133 return total_b;
134}