]> git.ipfire.org Git - people/ms/u-boot.git/blame - board/lpc2292sodimm/flash.c
rename CFG_ macros to CONFIG_SYS
[people/ms/u-boot.git] / board / lpc2292sodimm / flash.c
CommitLineData
6bd2447e
GJ
1/*
2 * (C) Copyright 2006 Embedded Artists AB <www.embeddedartists.com>
3 *
b0d8f5bf
PP
4 * Modified to use the routines in cpu/arm720t/lpc2292/flash.c by
5 * Gary Jennejohn <garyj@denx,de>
6 *
6bd2447e
GJ
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of
10 * the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
20 * MA 02111-1307 USA
21 */
22
23#include <common.h>
24#include <asm/arch/hardware.h>
25
6bd2447e
GJ
26#define SST_BASEADDR 0x80000000
27#define SST_ADDR1 ((volatile ushort*)(SST_BASEADDR + (0x5555 << 1)))
28#define SST_ADDR2 ((volatile ushort*)(SST_BASEADDR + (0x2AAA << 1)))
29
30
6d0f6bcf 31flash_info_t flash_info[CONFIG_SYS_MAX_FLASH_BANKS];
6bd2447e 32
b0d8f5bf
PP
33extern int lpc2292_copy_buffer_to_flash(flash_info_t *, ulong);
34extern int lpc2292_flash_erase(flash_info_t *, int, int);
35extern int lpc2292_write_buff (flash_info_t *, uchar *, ulong, ulong);
6bd2447e
GJ
36
37/*-----------------------------------------------------------------------
38 *
39 */
40void write_word_sst(ulong addr, ushort data)
41{
42 ushort tmp;
43
44 *SST_ADDR1 = 0x00AA;
45 *SST_ADDR2 = 0x0055;
46 *SST_ADDR1 = 0x00A0;
47 *((volatile ushort*)addr) = data;
48 /* do data polling */
49 do {
50 tmp = *((volatile ushort*)addr);
51 } while (tmp != data);
52}
53
54/*-----------------------------------------------------------------------
55 */
56
57ulong flash_init (void)
58{
59 int j, k;
60 ulong size = 0;
61 ulong flashbase = 0;
62
63 flash_info[0].flash_id = (PHILIPS_LPC2292 & FLASH_VENDMASK);
64 flash_info[0].size = 0x003E000; /* 256 - 8 KB */
65 flash_info[0].sector_count = 17;
66 memset (flash_info[0].protect, 0, 17);
67 flashbase = 0x00000000;
68 for (j = 0, k = 0; j < 8; j++, k++) {
69 flash_info[0].start[k] = flashbase;
70 flashbase += 0x00002000;
71 }
72 for (j = 0; j < 2; j++, k++) {
73 flash_info[0].start[k] = flashbase;
74 flashbase += 0x00010000;
75 }
76 for (j = 0; j < 7; j++, k++) {
77 flash_info[0].start[k] = flashbase;
78 flashbase += 0x00002000;
f8db84f1 79 }
6bd2447e
GJ
80 size += flash_info[0].size;
81
82 flash_info[1].flash_id = (SST_MANUFACT & FLASH_VENDMASK);
83 flash_info[1].size = 0x00200000; /* 2 MB */
84 flash_info[1].sector_count = 512;
85 memset (flash_info[1].protect, 0, 512);
86 flashbase = SST_BASEADDR;
87 for (j=0; j<512; j++) {
88 flash_info[1].start[j] = flashbase;
89 flashbase += 0x1000; /* 4 KB sectors */
90 }
91 size += flash_info[1].size;
92
93 /* Protect monitor and environment sectors */
94 flash_protect (FLAG_PROTECT_SET,
95 0x0,
96 0x0 + monitor_flash_len - 1,
97 &flash_info[0]);
98
99 flash_protect (FLAG_PROTECT_SET,
0e8d1586
JCPV
100 CONFIG_ENV_ADDR,
101 CONFIG_ENV_ADDR + CONFIG_ENV_SIZE - 1,
6bd2447e
GJ
102 &flash_info[0]);
103
104 return size;
105}
106
107/*-----------------------------------------------------------------------
108 */
109void flash_print_info (flash_info_t * info)
110{
111 int i;
112 int erased = 0;
113 unsigned long j;
114 unsigned long count;
115 unsigned char *p;
116
117 switch (info->flash_id & FLASH_VENDMASK) {
118 case (SST_MANUFACT & FLASH_VENDMASK):
119 printf("SST: ");
120 break;
121 case (PHILIPS_LPC2292 & FLASH_VENDMASK):
122 printf("Philips: ");
123 break;
124 default:
125 printf ("Unknown Vendor ");
126 break;
127 }
128
129 printf (" Size: %ld KB in %d Sectors\n",
130 info->size >> 10, info->sector_count);
131
132 printf (" Sector Start Addresses:");
133 for (i = 0; i < info->sector_count; i++) {
134 if ((i % 5) == 0) {
135 printf ("\n ");
136 }
137 if (i < (info->sector_count - 1)) {
138 count = info->start[i+1] - info->start[i];
139 }
140 else {
141 count = info->start[0] + info->size - info->start[i];
142 }
143 p = (unsigned char*)(info->start[i]);
144 erased = 1;
145 for (j = 0; j < count; j++) {
146 if (*p != 0xFF) {
147 erased = 0;
148 break;
149 }
150 p++;
151 }
152 printf (" %08lX%s%s", info->start[i], info->protect[i] ? " RO" : " ",
153 erased ? " E" : " ");
154 }
155 printf ("\n");
156}
157
6bd2447e
GJ
158int flash_erase_sst (flash_info_t * info, int s_first, int s_last)
159{
160 int i;
161
162 for (i = s_first; i <= s_last; i++) {
163 *SST_ADDR1 = 0x00AA;
164 *SST_ADDR2 = 0x0055;
165 *SST_ADDR1 = 0x0080;
166 *SST_ADDR1 = 0x00AA;
167 *SST_ADDR2 = 0x0055;
168 *((volatile ushort*)(info->start[i])) = 0x0030;
169 /* wait for erase to finish */
170 udelay(25000);
171 }
172
173 return ERR_OK;
174}
175
176int flash_erase (flash_info_t * info, int s_first, int s_last)
177{
178 switch (info->flash_id & FLASH_VENDMASK) {
179 case (SST_MANUFACT & FLASH_VENDMASK):
f8db84f1 180 return flash_erase_sst(info, s_first, s_last);
6bd2447e 181 case (PHILIPS_LPC2292 & FLASH_VENDMASK):
b0d8f5bf 182 return lpc2292_flash_erase(info, s_first, s_last);
6bd2447e
GJ
183 default:
184 return ERR_PROTECTED;
185 }
186 return ERR_PROTECTED;
187}
188
189/*-----------------------------------------------------------------------
190 * Copy memory to flash.
191 *
192 * cnt is in bytes
193 */
194
195int write_buff_sst (flash_info_t * info, uchar * src, ulong addr, ulong cnt)
196{
197 ushort tmp;
198 ulong i;
199 uchar* src_org;
200 uchar* dst_org;
201 ulong cnt_org = cnt;
202 int ret = ERR_OK;
203
204 src_org = src;
205 dst_org = (uchar*)addr;
206
207 if (addr & 1) { /* if odd address */
208 tmp = *((uchar*)(addr - 1)); /* little endian */
209 tmp |= (*src << 8);
210 write_word_sst(addr - 1, tmp);
211 addr += 1;
212 cnt -= 1;
213 src++;
214 }
215 while (cnt > 1) {
216 tmp = ((*(src+1)) << 8) + (*src); /* little endian */
217 write_word_sst(addr, tmp);
218 addr += 2;
219 src += 2;
220 cnt -= 2;
221 }
222 if (cnt > 0) {
223 tmp = (*((uchar*)(addr + 1))) << 8;
224 tmp |= *src;
225 write_word_sst(addr, tmp);
226 }
227
228 for (i = 0; i < cnt_org; i++) {
229 if (*dst_org != *src_org) {
230 printf("Write failed. Byte %lX differs\n", i);
231 ret = ERR_PROG_ERROR;
232 break;
233 }
234 dst_org++;
235 src_org++;
236 }
237
6bd2447e
GJ
238 return ret;
239}
240
6bd2447e
GJ
241int write_buff (flash_info_t * info, uchar * src, ulong addr, ulong cnt)
242{
243 switch (info->flash_id & FLASH_VENDMASK) {
244 case (SST_MANUFACT & FLASH_VENDMASK):
f8db84f1 245 return write_buff_sst(info, src, addr, cnt);
6bd2447e 246 case (PHILIPS_LPC2292 & FLASH_VENDMASK):
b0d8f5bf 247 return lpc2292_write_buff(info, src, addr, cnt);
6bd2447e
GJ
248 default:
249 return ERR_PROG_ERROR;
250 }
251 return ERR_PROG_ERROR;
252}