deadbat-alternate.patch
[u-boot-openmoko/mini2440.git] / board / esd / cpci405 / flash.c
blobe766895bb06eb185726536ec07329f7cbdc3e024
1 /*
2 * (C) Copyright 2001-2003
3 * Stefan Roese, esd gmbh germany, stefan.roese@esd-electronics.com
5 * See file CREDITS for list of people who contributed to this
6 * project.
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 * MA 02111-1307 USA
24 #include <common.h>
25 #include <ppc4xx.h>
26 #include <asm/processor.h>
29 * include common flash code (for esd boards)
31 #include "../common/flash.c"
33 /*-----------------------------------------------------------------------
34 * Functions
36 static ulong flash_get_size (vu_long * addr, flash_info_t * info);
37 static void flash_get_offsets (ulong base, flash_info_t * info);
39 /*-----------------------------------------------------------------------
42 unsigned long calc_size(unsigned long size)
44 switch (size) {
45 case 1 << 20:
46 return 0;
47 case 2 << 20:
48 return 1;
49 case 4 << 20:
50 return 2;
51 case 8 << 20:
52 return 3;
53 case 16 << 20:
54 return 4;
55 default:
56 return 0;
61 unsigned long flash_init (void)
63 unsigned long size_b0, size_b1;
64 int i;
65 uint pbcr;
66 unsigned long base_b0, base_b1;
68 /* Init: no FLASHes known */
69 for (i = 0; i < CFG_MAX_FLASH_BANKS; ++i) {
70 flash_info[i].flash_id = FLASH_UNKNOWN;
73 /* Static FLASH Bank configuration here - FIXME XXX */
75 base_b0 = FLASH_BASE0_PRELIM;
76 size_b0 = flash_get_size ((vu_long *) base_b0, &flash_info[0]);
78 if (flash_info[0].flash_id == FLASH_UNKNOWN) {
79 printf ("## Unknown FLASH on Bank 0 - Size = 0x%08lx = %ld MB\n",
80 size_b0, size_b0 << 20);
83 base_b1 = FLASH_BASE1_PRELIM;
84 size_b1 = flash_get_size ((vu_long *) base_b1, &flash_info[1]);
86 /* Re-do sizing to get full correct info */
88 if (size_b1) {
89 if (size_b1 < (1 << 20)) {
90 /* minimum CS size on PPC405GP is 1MB !!! */
91 size_b1 = 1 << 20;
93 base_b1 = -size_b1;
94 mtdcr (ebccfga, pb0cr);
95 pbcr = mfdcr (ebccfgd);
96 mtdcr (ebccfga, pb0cr);
97 pbcr = (pbcr & 0x0001ffff) | base_b1 | (calc_size(size_b1) << 17);
98 mtdcr (ebccfgd, pbcr);
99 #if 0 /* test-only */
100 printf("size_b1=%x base_b1=%x pb1cr = %x\n",
101 size_b1, base_b1, pbcr); /* test-only */
102 #endif
105 if (size_b0) {
106 if (size_b0 < (1 << 20)) {
107 /* minimum CS size on PPC405GP is 1MB !!! */
108 size_b0 = 1 << 20;
110 base_b0 = base_b1 - size_b0;
111 mtdcr (ebccfga, pb1cr);
112 pbcr = mfdcr (ebccfgd);
113 mtdcr (ebccfga, pb1cr);
114 pbcr = (pbcr & 0x0001ffff) | base_b0 | (calc_size(size_b0) << 17);
115 mtdcr (ebccfgd, pbcr);
116 #if 0 /* test-only */
117 printf("size_b0=%x base_b0=%x pb0cr = %x\n",
118 size_b0, base_b0, pbcr); /* test-only */
119 #endif
122 size_b0 = flash_get_size ((vu_long *) base_b0, &flash_info[0]);
124 flash_get_offsets (base_b0, &flash_info[0]);
126 /* monitor protection ON by default */
127 flash_protect (FLAG_PROTECT_SET,
128 base_b0 + size_b0 - monitor_flash_len,
129 base_b0 + size_b0 - 1, &flash_info[0]);
131 if (size_b1) {
132 /* Re-do sizing to get full correct info */
133 size_b1 = flash_get_size ((vu_long *) base_b1, &flash_info[1]);
135 flash_get_offsets (base_b1, &flash_info[1]);
137 /* monitor protection ON by default */
138 flash_protect (FLAG_PROTECT_SET,
139 base_b1 + size_b1 - monitor_flash_len,
140 base_b1 + size_b1 - 1, &flash_info[1]);
141 /* monitor protection OFF by default (one is enough) */
142 flash_protect (FLAG_PROTECT_CLEAR,
143 base_b0 + size_b0 - monitor_flash_len,
144 base_b0 + size_b0 - 1, &flash_info[0]);
145 } else {
146 flash_info[1].flash_id = FLASH_UNKNOWN;
147 flash_info[1].sector_count = -1;
150 flash_info[0].size = size_b0;
151 flash_info[1].size = size_b1;
153 return (size_b0 + size_b1);