blob: 07d185fd2f4bc8602e1d2ef15baa98c843dd9da2 [file] [log] [blame]
Stefan Roese363330b2005-08-04 17:09:16 +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 *
8 * See file CREDITS for list of people who contributed to this
9 * project.
10 *
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.
15 *
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.
20 *
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,
24 * MA 02111-1307 USA
25 */
26
27/*
28 * Modified 4/5/2001
29 * Wait for completion of each sector erase command issued
30 * 4/5/2001
31 * Chris Hallinan - DS4.COM, Inc. - clh@net1plus.com
32 */
33
34#include <common.h>
Stefan Roese247e9d72010-09-09 19:18:00 +020035#include <asm/ppc4xx.h>
Stefan Roese363330b2005-08-04 17:09:16 +020036#include <asm/processor.h>
Stefan Roese247e9d72010-09-09 19:18:00 +020037#include <asm/ppc440.h>
Stefan Roese363330b2005-08-04 17:09:16 +020038#include "bamboo.h"
39
40#undef DEBUG
41
42#ifdef DEBUG
43#define DEBUGF(x...) printf(x)
44#else
45#define DEBUGF(x...)
46#endif /* DEBUG */
47
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020048flash_info_t flash_info[CONFIG_SYS_MAX_FLASH_BANKS]; /* info for FLASH chips */
Stefan Roese363330b2005-08-04 17:09:16 +020049
50/*
51 * Mark big flash bank (16 bit instead of 8 bit access) in address with bit 0
52 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020053static unsigned long flash_addr_table[][CONFIG_SYS_MAX_FLASH_BANKS] = {
Stefan Roese363330b2005-08-04 17:09:16 +020054 {0x87800001, 0xFFF00000, 0xFFF80000}, /* 0:boot from small flash */
55 {0x00000000, 0x00000000, 0x00000000}, /* 1:boot from pci 66 */
Stefan Roesec7698642007-06-01 15:19:29 +020056 {0x87800001, 0x00000000, 0x00000000}, /* 0:boot from nand flash */
Stefan Roese797d8572005-08-11 17:56:56 +020057 {0x87F00000, 0x87F80000, 0xFFC00001}, /* 3:boot from big flash 33*/
58 {0x87F00000, 0x87F80000, 0xFFC00001}, /* 4:boot from big flash 66*/
Stefan Roese363330b2005-08-04 17:09:16 +020059 {0x00000000, 0x00000000, 0x00000000}, /* 5:boot from */
60 {0x00000000, 0x00000000, 0x00000000}, /* 6:boot from pci 66 */
61 {0x00000000, 0x00000000, 0x00000000}, /* 7:boot from */
Stefan Roese797d8572005-08-11 17:56:56 +020062 {0x87C00001, 0xFFF00000, 0xFFF80000}, /* 0:boot from small flash */
Stefan Roese363330b2005-08-04 17:09:16 +020063};
64
65/*
66 * include common flash code (for amcc boards)
67 */
68#include "../common/flash.c"
69
70/*-----------------------------------------------------------------------
71 * Functions
72 */
73static ulong flash_get_size(vu_long * addr, flash_info_t * info);
74static int write_word(flash_info_t * info, ulong dest, ulong data);
75
76/*-----------------------------------------------------------------------
77 */
78
79unsigned long flash_init(void)
80{
81 unsigned long total_b = 0;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020082 unsigned long size_b[CONFIG_SYS_MAX_FLASH_BANKS];
Stefan Roese363330b2005-08-04 17:09:16 +020083 unsigned short index = 0;
84 int i;
85 unsigned long val;
86 unsigned long ebc_boot_size;
87 unsigned long boot_selection;
88
Stefan Roese95ca5fa2010-09-11 09:31:43 +020089 mfsdr(SDR0_PINSTP, val);
Stefan Roese363330b2005-08-04 17:09:16 +020090 index = (val & SDR0_PSTRP0_BOOTSTRAP_MASK) >> 29;
91
92 if ((index == 5) || (index == 7)) {
93 /*
94 * Boot Settings in IIC EEprom address 0xA8 or 0xA4
95 * Read Serial Device Strap Register1 in PPC440EP
96 */
Stefan Roese918010a2009-09-09 16:25:29 +020097 mfsdr(SDR0_SDSTP1, val);
Stefan Roese363330b2005-08-04 17:09:16 +020098 boot_selection = val & SDR0_SDSTP1_BOOT_SEL_MASK;
99 ebc_boot_size = val & SDR0_SDSTP1_EBC_ROM_BS_MASK;
100
101 switch(boot_selection) {
102 case SDR0_SDSTP1_BOOT_SEL_EBC:
103 switch(ebc_boot_size) {
104 case SDR0_SDSTP1_EBC_ROM_BS_16BIT:
105 index = 3;
106 break;
107 case SDR0_SDSTP1_EBC_ROM_BS_8BIT:
108 index = 0;
109 break;
110 }
111 break;
112
113 case SDR0_SDSTP1_BOOT_SEL_PCI:
114 index = 1;
115 break;
116
117 case SDR0_SDSTP1_BOOT_SEL_NDFC:
118 index = 2;
119 break;
120 }
Stefan Roese797d8572005-08-11 17:56:56 +0200121 } else if (index == 0) {
122 if (in8(FPGA_SETTING_REG) & FPGA_SET_REG_OP_CODE_FLASH_ABOVE) {
123 index = 8; /* sram below op code flash -> new index 8 */
124 }
Stefan Roese363330b2005-08-04 17:09:16 +0200125 }
126
127 DEBUGF("\n");
128 DEBUGF("FLASH: Index: %d\n", index);
129
130 /* Init: no FLASHes known */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200131 for (i = 0; i < CONFIG_SYS_MAX_FLASH_BANKS; ++i) {
Stefan Roese363330b2005-08-04 17:09:16 +0200132 flash_info[i].flash_id = FLASH_UNKNOWN;
133 flash_info[i].sector_count = -1;
134 flash_info[i].size = 0;
135
136 /* check whether the address is 0 */
Stefan Roesec7698642007-06-01 15:19:29 +0200137 if (flash_addr_table[index][i] == 0)
Stefan Roese363330b2005-08-04 17:09:16 +0200138 continue;
Stefan Roese363330b2005-08-04 17:09:16 +0200139
Stefan Roesec7698642007-06-01 15:19:29 +0200140 DEBUGF("Detection bank %d...\n", i);
Stefan Roese363330b2005-08-04 17:09:16 +0200141 /* call flash_get_size() to initialize sector address */
142 size_b[i] = flash_get_size((vu_long *) flash_addr_table[index][i],
143 &flash_info[i]);
144 flash_info[i].size = size_b[i];
145 if (flash_info[i].flash_id == FLASH_UNKNOWN) {
146 printf("## Unknown FLASH on Bank %d - Size = 0x%08lx = %ld MB\n",
147 i, size_b[i], size_b[i] << 20);
148 flash_info[i].sector_count = -1;
149 flash_info[i].size = 0;
150 }
151
152 /* Monitor protection ON by default */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200153 (void)flash_protect(FLAG_PROTECT_SET, CONFIG_SYS_MONITOR_BASE,
154 CONFIG_SYS_MONITOR_BASE + CONFIG_SYS_MONITOR_LEN - 1,
Stefan Roese363330b2005-08-04 17:09:16 +0200155 &flash_info[i]);
Jean-Christophe PLAGNIOL-VILLARD53db4cd2008-09-10 22:48:04 +0200156#if defined(CONFIG_ENV_IS_IN_FLASH)
Jean-Christophe PLAGNIOL-VILLARD7e1cda62008-09-10 22:48:06 +0200157 (void)flash_protect(FLAG_PROTECT_SET, CONFIG_ENV_ADDR,
158 CONFIG_ENV_ADDR + CONFIG_ENV_SECT_SIZE - 1,
Stefan Roese363330b2005-08-04 17:09:16 +0200159 &flash_info[i]);
Jean-Christophe PLAGNIOL-VILLARD7e1cda62008-09-10 22:48:06 +0200160#if defined(CONFIG_ENV_IS_IN_FLASH) && defined(CONFIG_ENV_ADDR_REDUND)
161 (void)flash_protect(FLAG_PROTECT_SET, CONFIG_ENV_ADDR_REDUND,
162 CONFIG_ENV_ADDR_REDUND + CONFIG_ENV_SECT_SIZE - 1,
Stefan Roese363330b2005-08-04 17:09:16 +0200163 &flash_info[i]);
164#endif
165#endif
166
167 total_b += flash_info[i].size;
168 }
169
170 return total_b;
171}