blob: 6dbe09f91dcc2cdab80d2f84e27538bd965317e6 [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 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02008 * SPDX-License-Identifier: GPL-2.0+
Stefan Roese363330b2005-08-04 17:09:16 +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 Roese247e9d72010-09-09 19:18:00 +020019#include <asm/ppc4xx.h>
Stefan Roese363330b2005-08-04 17:09:16 +020020#include <asm/processor.h>
Stefan Roese247e9d72010-09-09 19:18:00 +020021#include <asm/ppc440.h>
Stefan Roese363330b2005-08-04 17:09:16 +020022#include "bamboo.h"
23
24#undef DEBUG
25
26#ifdef DEBUG
27#define DEBUGF(x...) printf(x)
28#else
29#define DEBUGF(x...)
30#endif /* DEBUG */
31
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020032flash_info_t flash_info[CONFIG_SYS_MAX_FLASH_BANKS]; /* info for FLASH chips */
Stefan Roese363330b2005-08-04 17:09:16 +020033
34/*
35 * Mark big flash bank (16 bit instead of 8 bit access) in address with bit 0
36 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020037static unsigned long flash_addr_table[][CONFIG_SYS_MAX_FLASH_BANKS] = {
Stefan Roese363330b2005-08-04 17:09:16 +020038 {0x87800001, 0xFFF00000, 0xFFF80000}, /* 0:boot from small flash */
39 {0x00000000, 0x00000000, 0x00000000}, /* 1:boot from pci 66 */
Stefan Roesec7698642007-06-01 15:19:29 +020040 {0x87800001, 0x00000000, 0x00000000}, /* 0:boot from nand flash */
Stefan Roese797d8572005-08-11 17:56:56 +020041 {0x87F00000, 0x87F80000, 0xFFC00001}, /* 3:boot from big flash 33*/
42 {0x87F00000, 0x87F80000, 0xFFC00001}, /* 4:boot from big flash 66*/
Stefan Roese363330b2005-08-04 17:09:16 +020043 {0x00000000, 0x00000000, 0x00000000}, /* 5:boot from */
44 {0x00000000, 0x00000000, 0x00000000}, /* 6:boot from pci 66 */
45 {0x00000000, 0x00000000, 0x00000000}, /* 7:boot from */
Stefan Roese797d8572005-08-11 17:56:56 +020046 {0x87C00001, 0xFFF00000, 0xFFF80000}, /* 0:boot from small flash */
Stefan Roese363330b2005-08-04 17:09:16 +020047};
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);
58static int write_word(flash_info_t * info, ulong dest, ulong data);
59
60/*-----------------------------------------------------------------------
61 */
62
63unsigned long flash_init(void)
64{
65 unsigned long total_b = 0;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020066 unsigned long size_b[CONFIG_SYS_MAX_FLASH_BANKS];
Stefan Roese363330b2005-08-04 17:09:16 +020067 unsigned short index = 0;
68 int i;
69 unsigned long val;
70 unsigned long ebc_boot_size;
71 unsigned long boot_selection;
72
Stefan Roese95ca5fa2010-09-11 09:31:43 +020073 mfsdr(SDR0_PINSTP, val);
Stefan Roese363330b2005-08-04 17:09:16 +020074 index = (val & SDR0_PSTRP0_BOOTSTRAP_MASK) >> 29;
75
76 if ((index == 5) || (index == 7)) {
77 /*
78 * Boot Settings in IIC EEprom address 0xA8 or 0xA4
79 * Read Serial Device Strap Register1 in PPC440EP
80 */
Stefan Roese918010a2009-09-09 16:25:29 +020081 mfsdr(SDR0_SDSTP1, val);
Stefan Roese363330b2005-08-04 17:09:16 +020082 boot_selection = val & SDR0_SDSTP1_BOOT_SEL_MASK;
83 ebc_boot_size = val & SDR0_SDSTP1_EBC_ROM_BS_MASK;
84
85 switch(boot_selection) {
86 case SDR0_SDSTP1_BOOT_SEL_EBC:
87 switch(ebc_boot_size) {
88 case SDR0_SDSTP1_EBC_ROM_BS_16BIT:
89 index = 3;
90 break;
91 case SDR0_SDSTP1_EBC_ROM_BS_8BIT:
92 index = 0;
93 break;
94 }
95 break;
96
97 case SDR0_SDSTP1_BOOT_SEL_PCI:
98 index = 1;
99 break;
100
101 case SDR0_SDSTP1_BOOT_SEL_NDFC:
102 index = 2;
103 break;
104 }
Stefan Roese797d8572005-08-11 17:56:56 +0200105 } else if (index == 0) {
106 if (in8(FPGA_SETTING_REG) & FPGA_SET_REG_OP_CODE_FLASH_ABOVE) {
107 index = 8; /* sram below op code flash -> new index 8 */
108 }
Stefan Roese363330b2005-08-04 17:09:16 +0200109 }
110
111 DEBUGF("\n");
112 DEBUGF("FLASH: Index: %d\n", index);
113
114 /* Init: no FLASHes known */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200115 for (i = 0; i < CONFIG_SYS_MAX_FLASH_BANKS; ++i) {
Stefan Roese363330b2005-08-04 17:09:16 +0200116 flash_info[i].flash_id = FLASH_UNKNOWN;
117 flash_info[i].sector_count = -1;
118 flash_info[i].size = 0;
119
120 /* check whether the address is 0 */
Stefan Roesec7698642007-06-01 15:19:29 +0200121 if (flash_addr_table[index][i] == 0)
Stefan Roese363330b2005-08-04 17:09:16 +0200122 continue;
Stefan Roese363330b2005-08-04 17:09:16 +0200123
Stefan Roesec7698642007-06-01 15:19:29 +0200124 DEBUGF("Detection bank %d...\n", i);
Stefan Roese363330b2005-08-04 17:09:16 +0200125 /* call flash_get_size() to initialize sector address */
126 size_b[i] = flash_get_size((vu_long *) flash_addr_table[index][i],
127 &flash_info[i]);
128 flash_info[i].size = size_b[i];
129 if (flash_info[i].flash_id == FLASH_UNKNOWN) {
130 printf("## Unknown FLASH on Bank %d - Size = 0x%08lx = %ld MB\n",
131 i, size_b[i], size_b[i] << 20);
132 flash_info[i].sector_count = -1;
133 flash_info[i].size = 0;
134 }
135
136 /* Monitor protection ON by default */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200137 (void)flash_protect(FLAG_PROTECT_SET, CONFIG_SYS_MONITOR_BASE,
138 CONFIG_SYS_MONITOR_BASE + CONFIG_SYS_MONITOR_LEN - 1,
Stefan Roese363330b2005-08-04 17:09:16 +0200139 &flash_info[i]);
Jean-Christophe PLAGNIOL-VILLARD53db4cd2008-09-10 22:48:04 +0200140#if defined(CONFIG_ENV_IS_IN_FLASH)
Jean-Christophe PLAGNIOL-VILLARD7e1cda62008-09-10 22:48:06 +0200141 (void)flash_protect(FLAG_PROTECT_SET, CONFIG_ENV_ADDR,
142 CONFIG_ENV_ADDR + CONFIG_ENV_SECT_SIZE - 1,
Stefan Roese363330b2005-08-04 17:09:16 +0200143 &flash_info[i]);
Jean-Christophe PLAGNIOL-VILLARD7e1cda62008-09-10 22:48:06 +0200144#if defined(CONFIG_ENV_IS_IN_FLASH) && defined(CONFIG_ENV_ADDR_REDUND)
145 (void)flash_protect(FLAG_PROTECT_SET, CONFIG_ENV_ADDR_REDUND,
146 CONFIG_ENV_ADDR_REDUND + CONFIG_ENV_SECT_SIZE - 1,
Stefan Roese363330b2005-08-04 17:09:16 +0200147 &flash_info[i]);
148#endif
149#endif
150
151 total_b += flash_info[i].size;
152 }
153
154 return total_b;
155}