blob: 208119c5f06e74342e85e3991deacb10f248967f [file] [log] [blame]
Vipin KUMARa6e34f72010-01-15 19:15:45 +05301/*
2 * (C) Copyright 2009
Vipin KUMARf3fcf922012-05-07 13:00:19 +05303 * Vipin Kumar, ST Microelectronics, vipin.kumar@st.com.
Vipin KUMARa6e34f72010-01-15 19:15:45 +05304 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
Vipin KUMARa6e34f72010-01-15 19:15:45 +05306 */
7
8#include <common.h>
9#include <flash.h>
10#include <linux/err.h>
Vipin KUMARf3fcf922012-05-07 13:00:19 +053011#include <linux/mtd/st_smi.h>
Vipin KUMARa6e34f72010-01-15 19:15:45 +053012
13#include <asm/io.h>
14#include <asm/arch/hardware.h>
Vipin KUMARa6e34f72010-01-15 19:15:45 +053015
16#if !defined(CONFIG_SYS_NO_FLASH)
17
18static struct smi_regs *const smicntl =
19 (struct smi_regs * const)CONFIG_SYS_SMI_BASE;
20static ulong bank_base[CONFIG_SYS_MAX_FLASH_BANKS] =
21 CONFIG_SYS_FLASH_ADDR_BASE;
22flash_info_t flash_info[CONFIG_SYS_MAX_FLASH_BANKS];
23
Armando Visconti6d6d23c2012-05-07 13:00:27 +053024/* data structure to maintain flash ids from different vendors */
25struct flash_device {
26 char *name;
27 u8 erase_cmd;
28 u32 device_id;
29 u32 pagesize;
30 unsigned long sectorsize;
31 unsigned long size_in_bytes;
32};
33
34#define FLASH_ID(n, es, id, psize, ssize, size) \
35{ \
36 .name = n, \
37 .erase_cmd = es, \
38 .device_id = id, \
39 .pagesize = psize, \
40 .sectorsize = ssize, \
41 .size_in_bytes = size \
42}
43
44/*
45 * List of supported flash devices.
46 * Currently the erase_cmd field is not used in this driver.
47 */
48static struct flash_device flash_devices[] = {
49 FLASH_ID("st m25p16" , 0xd8, 0x00152020, 0x100, 0x10000, 0x200000),
50 FLASH_ID("st m25p32" , 0xd8, 0x00162020, 0x100, 0x10000, 0x400000),
51 FLASH_ID("st m25p64" , 0xd8, 0x00172020, 0x100, 0x10000, 0x800000),
52 FLASH_ID("st m25p128" , 0xd8, 0x00182020, 0x100, 0x40000, 0x1000000),
53 FLASH_ID("st m25p05" , 0xd8, 0x00102020, 0x80 , 0x8000 , 0x10000),
54 FLASH_ID("st m25p10" , 0xd8, 0x00112020, 0x80 , 0x8000 , 0x20000),
55 FLASH_ID("st m25p20" , 0xd8, 0x00122020, 0x100, 0x10000, 0x40000),
56 FLASH_ID("st m25p40" , 0xd8, 0x00132020, 0x100, 0x10000, 0x80000),
57 FLASH_ID("st m25p80" , 0xd8, 0x00142020, 0x100, 0x10000, 0x100000),
58 FLASH_ID("st m45pe10" , 0xd8, 0x00114020, 0x100, 0x10000, 0x20000),
59 FLASH_ID("st m45pe20" , 0xd8, 0x00124020, 0x100, 0x10000, 0x40000),
60 FLASH_ID("st m45pe40" , 0xd8, 0x00134020, 0x100, 0x10000, 0x80000),
61 FLASH_ID("st m45pe80" , 0xd8, 0x00144020, 0x100, 0x10000, 0x100000),
62 FLASH_ID("sp s25fl004" , 0xd8, 0x00120201, 0x100, 0x10000, 0x80000),
63 FLASH_ID("sp s25fl008" , 0xd8, 0x00130201, 0x100, 0x10000, 0x100000),
64 FLASH_ID("sp s25fl016" , 0xd8, 0x00140201, 0x100, 0x10000, 0x200000),
65 FLASH_ID("sp s25fl032" , 0xd8, 0x00150201, 0x100, 0x10000, 0x400000),
66 FLASH_ID("sp s25fl064" , 0xd8, 0x00160201, 0x100, 0x10000, 0x800000),
67 FLASH_ID("mac 25l512" , 0xd8, 0x001020C2, 0x010, 0x10000, 0x10000),
68 FLASH_ID("mac 25l1005" , 0xd8, 0x001120C2, 0x010, 0x10000, 0x20000),
69 FLASH_ID("mac 25l2005" , 0xd8, 0x001220C2, 0x010, 0x10000, 0x40000),
70 FLASH_ID("mac 25l4005" , 0xd8, 0x001320C2, 0x010, 0x10000, 0x80000),
71 FLASH_ID("mac 25l4005a" , 0xd8, 0x001320C2, 0x010, 0x10000, 0x80000),
72 FLASH_ID("mac 25l8005" , 0xd8, 0x001420C2, 0x010, 0x10000, 0x100000),
73 FLASH_ID("mac 25l1605" , 0xd8, 0x001520C2, 0x100, 0x10000, 0x200000),
74 FLASH_ID("mac 25l1605a" , 0xd8, 0x001520C2, 0x010, 0x10000, 0x200000),
75 FLASH_ID("mac 25l3205" , 0xd8, 0x001620C2, 0x100, 0x10000, 0x400000),
76 FLASH_ID("mac 25l3205a" , 0xd8, 0x001620C2, 0x100, 0x10000, 0x400000),
77 FLASH_ID("mac 25l6405" , 0xd8, 0x001720C2, 0x100, 0x10000, 0x800000),
Armando Visconti92640772012-05-07 13:00:30 +053078 FLASH_ID("wbd w25q128" , 0xd8, 0x001840EF, 0x100, 0x10000, 0x1000000),
Vipin KUMARa6e34f72010-01-15 19:15:45 +053079};
80
81/*
82 * smi_wait_xfer_finish - Wait until TFF is set in status register
83 * @timeout: timeout in milliseconds
84 *
85 * Wait until TFF is set in status register
86 */
Amit Virdi5c16c542012-05-07 13:00:20 +053087static int smi_wait_xfer_finish(int timeout)
Vipin KUMARa6e34f72010-01-15 19:15:45 +053088{
Amit Virdib5992fa2012-05-07 13:00:29 +053089 ulong start = get_timer(0);
90
91 while (get_timer(start) < timeout) {
Vipin KUMARa6e34f72010-01-15 19:15:45 +053092 if (readl(&smicntl->smi_sr) & TFF)
Amit Virdi5c16c542012-05-07 13:00:20 +053093 return 0;
Amit Virdib5992fa2012-05-07 13:00:29 +053094
95 /* Try after 10 ms */
96 udelay(10);
97 };
Amit Virdi5c16c542012-05-07 13:00:20 +053098
99 return -1;
Vipin KUMARa6e34f72010-01-15 19:15:45 +0530100}
101
102/*
103 * smi_read_id - Read flash id
104 * @info: flash_info structure pointer
105 * @banknum: bank number
106 *
107 * Read the flash id present at bank #banknum
108 */
109static unsigned int smi_read_id(flash_info_t *info, int banknum)
110{
111 unsigned int value;
112
113 writel(readl(&smicntl->smi_cr1) | SW_MODE, &smicntl->smi_cr1);
114 writel(READ_ID, &smicntl->smi_tr);
115 writel((banknum << BANKSEL_SHIFT) | SEND | TX_LEN_1 | RX_LEN_3,
116 &smicntl->smi_cr2);
Vipin KUMARf3fcf922012-05-07 13:00:19 +0530117
Amit Virdi5c16c542012-05-07 13:00:20 +0530118 if (smi_wait_xfer_finish(XFER_FINISH_TOUT))
119 return -EIO;
Vipin KUMARa6e34f72010-01-15 19:15:45 +0530120
121 value = (readl(&smicntl->smi_rr) & 0x00FFFFFF);
122
123 writel(readl(&smicntl->smi_sr) & ~TFF, &smicntl->smi_sr);
124 writel(readl(&smicntl->smi_cr1) & ~SW_MODE, &smicntl->smi_cr1);
125
126 return value;
127}
128
129/*
130 * flash_get_size - Detect the SMI flash by reading the ID.
131 * @base: Base address of the flash area bank #banknum
132 * @banknum: Bank number
133 *
134 * Detect the SMI flash by reading the ID. Initializes the flash_info structure
135 * with size, sector count etc.
136 */
137static ulong flash_get_size(ulong base, int banknum)
138{
139 flash_info_t *info = &flash_info[banknum];
Amit Virdi69fcb552012-05-07 13:00:22 +0530140 int value;
Vipin KUMARa6e34f72010-01-15 19:15:45 +0530141 int i;
142
143 value = smi_read_id(info, banknum);
Amit Virdi69fcb552012-05-07 13:00:22 +0530144
145 if (value < 0) {
146 printf("Flash id could not be read\n");
147 return 0;
148 }
149
Armando Visconti6d6d23c2012-05-07 13:00:27 +0530150 /* Matches chip-id to entire list of 'serial-nor flash' ids */
151 for (i = 0; i < ARRAY_SIZE(flash_devices); i++) {
152 if (flash_devices[i].device_id == value) {
153 info->size = flash_devices[i].size_in_bytes;
154 info->flash_id = value;
155 info->start[0] = base;
156 info->sector_count =
157 info->size/flash_devices[i].sectorsize;
Vipin KUMARa6e34f72010-01-15 19:15:45 +0530158
Armando Visconti6d6d23c2012-05-07 13:00:27 +0530159 return info->size;
Vipin KUMARa6e34f72010-01-15 19:15:45 +0530160 }
161 }
162
Armando Visconti6d6d23c2012-05-07 13:00:27 +0530163 return 0;
Vipin KUMARa6e34f72010-01-15 19:15:45 +0530164}
165
166/*
167 * smi_read_sr - Read status register of SMI
168 * @bank: bank number
169 *
170 * This routine will get the status register of the flash chip present at the
171 * given bank
172 */
Amit Virdi69fcb552012-05-07 13:00:22 +0530173static int smi_read_sr(int bank)
Vipin KUMARa6e34f72010-01-15 19:15:45 +0530174{
Shiraz Hashima59c7b32012-05-07 13:00:24 +0530175 u32 ctrlreg1, val;
Vipin KUMARa6e34f72010-01-15 19:15:45 +0530176
177 /* store the CTRL REG1 state */
178 ctrlreg1 = readl(&smicntl->smi_cr1);
179
180 /* Program SMI in HW Mode */
181 writel(readl(&smicntl->smi_cr1) & ~(SW_MODE | WB_MODE),
182 &smicntl->smi_cr1);
183
184 /* Performing a RSR instruction in HW mode */
185 writel((bank << BANKSEL_SHIFT) | RD_STATUS_REG, &smicntl->smi_cr2);
186
Amit Virdi5c16c542012-05-07 13:00:20 +0530187 if (smi_wait_xfer_finish(XFER_FINISH_TOUT))
188 return -1;
Vipin KUMARa6e34f72010-01-15 19:15:45 +0530189
Shiraz Hashima59c7b32012-05-07 13:00:24 +0530190 val = readl(&smicntl->smi_sr);
191
Vipin KUMARa6e34f72010-01-15 19:15:45 +0530192 /* Restore the CTRL REG1 state */
193 writel(ctrlreg1, &smicntl->smi_cr1);
194
Shiraz Hashima59c7b32012-05-07 13:00:24 +0530195 return val;
Vipin KUMARa6e34f72010-01-15 19:15:45 +0530196}
197
198/*
199 * smi_wait_till_ready - Wait till last operation is over.
200 * @bank: bank number shifted.
201 * @timeout: timeout in milliseconds.
202 *
203 * This routine checks for WIP(write in progress)bit in Status register(SMSR-b0)
204 * The routine checks for #timeout loops, each at interval of 1 milli-second.
205 * If successful the routine returns 0.
206 */
207static int smi_wait_till_ready(int bank, int timeout)
208{
Amit Virdi69fcb552012-05-07 13:00:22 +0530209 int sr;
Amit Virdib5992fa2012-05-07 13:00:29 +0530210 ulong start = get_timer(0);
Vipin KUMARa6e34f72010-01-15 19:15:45 +0530211
212 /* One chip guarantees max 5 msec wait here after page writes,
213 but potentially three seconds (!) after page erase. */
Amit Virdib5992fa2012-05-07 13:00:29 +0530214 while (get_timer(start) < timeout) {
Vipin KUMARa6e34f72010-01-15 19:15:45 +0530215 sr = smi_read_sr(bank);
Vipin Kumara5ad7cc2012-05-07 13:00:25 +0530216 if ((sr >= 0) && (!(sr & WIP_BIT)))
Vipin KUMARa6e34f72010-01-15 19:15:45 +0530217 return 0;
218
Amit Virdib5992fa2012-05-07 13:00:29 +0530219 /* Try again after 10 usec */
220 udelay(10);
Amit Virdi69fcb552012-05-07 13:00:22 +0530221 } while (timeout--);
222
Vipin KUMARa6e34f72010-01-15 19:15:45 +0530223 printf("SMI controller is still in wait, timeout=%d\n", timeout);
224 return -EIO;
225}
226
227/*
228 * smi_write_enable - Enable the flash to do write operation
229 * @bank: bank number
230 *
231 * Set write enable latch with Write Enable command.
232 * Returns negative if error occurred.
233 */
234static int smi_write_enable(int bank)
235{
236 u32 ctrlreg1;
Amit Virdib5992fa2012-05-07 13:00:29 +0530237 u32 start;
Vipin KUMARa6e34f72010-01-15 19:15:45 +0530238 int timeout = WMODE_TOUT;
Amit Virdi69fcb552012-05-07 13:00:22 +0530239 int sr;
Vipin KUMARa6e34f72010-01-15 19:15:45 +0530240
241 /* Store the CTRL REG1 state */
242 ctrlreg1 = readl(&smicntl->smi_cr1);
243
244 /* Program SMI in H/W Mode */
245 writel(readl(&smicntl->smi_cr1) & ~SW_MODE, &smicntl->smi_cr1);
246
247 /* Give the Flash, Write Enable command */
248 writel((bank << BANKSEL_SHIFT) | WE, &smicntl->smi_cr2);
249
Amit Virdi5c16c542012-05-07 13:00:20 +0530250 if (smi_wait_xfer_finish(XFER_FINISH_TOUT))
251 return -1;
Vipin KUMARa6e34f72010-01-15 19:15:45 +0530252
253 /* Restore the CTRL REG1 state */
254 writel(ctrlreg1, &smicntl->smi_cr1);
255
Amit Virdib5992fa2012-05-07 13:00:29 +0530256 start = get_timer(0);
257 while (get_timer(start) < timeout) {
Amit Virdi69fcb552012-05-07 13:00:22 +0530258 sr = smi_read_sr(bank);
Vipin Kumara5ad7cc2012-05-07 13:00:25 +0530259 if ((sr >= 0) && (sr & (1 << (bank + WM_SHIFT))))
Amit Virdi69fcb552012-05-07 13:00:22 +0530260 return 0;
Vipin KUMARa6e34f72010-01-15 19:15:45 +0530261
Amit Virdib5992fa2012-05-07 13:00:29 +0530262 /* Try again after 10 usec */
263 udelay(10);
264 };
Vipin KUMARa6e34f72010-01-15 19:15:45 +0530265
266 return -1;
267}
268
269/*
270 * smi_init - SMI initialization routine
271 *
272 * SMI initialization routine. Sets SMI control register1.
273 */
Vipin KUMARf3fcf922012-05-07 13:00:19 +0530274void smi_init(void)
Vipin KUMARa6e34f72010-01-15 19:15:45 +0530275{
276 /* Setting the fast mode values. SMI working at 166/4 = 41.5 MHz */
277 writel(HOLD1 | FAST_MODE | BANK_EN | DSEL_TIME | PRESCAL4,
278 &smicntl->smi_cr1);
279}
280
281/*
282 * smi_sector_erase - Erase flash sector
283 * @info: flash_info structure pointer
284 * @sector: sector number
285 *
286 * Set write enable latch with Write Enable command.
287 * Returns negative if error occurred.
288 */
289static int smi_sector_erase(flash_info_t *info, unsigned int sector)
290{
291 int bank;
292 unsigned int sect_add;
293 unsigned int instruction;
294
295 switch (info->start[0]) {
296 case SMIBANK0_BASE:
297 bank = BANK0;
298 break;
299 case SMIBANK1_BASE:
300 bank = BANK1;
301 break;
302 case SMIBANK2_BASE:
303 bank = BANK2;
304 break;
305 case SMIBANK3_BASE:
306 bank = BANK3;
307 break;
308 default:
309 return -1;
310 }
311
312 sect_add = sector * (info->size / info->sector_count);
313 instruction = ((sect_add >> 8) & 0x0000FF00) | SECTOR_ERASE;
314
315 writel(readl(&smicntl->smi_sr) & ~(ERF1 | ERF2), &smicntl->smi_sr);
316
Armando Viscontiae3e0cc2012-05-07 13:00:26 +0530317 /* Wait until finished previous write command. */
318 if (smi_wait_till_ready(bank, CONFIG_SYS_FLASH_ERASE_TOUT))
319 return -EBUSY;
Vipin KUMARa6e34f72010-01-15 19:15:45 +0530320
Armando Viscontiae3e0cc2012-05-07 13:00:26 +0530321 /* Send write enable, before erase commands. */
322 if (smi_write_enable(bank))
323 return -EIO;
Vipin KUMARa6e34f72010-01-15 19:15:45 +0530324
Armando Viscontiae3e0cc2012-05-07 13:00:26 +0530325 /* Put SMI in SW mode */
326 writel(readl(&smicntl->smi_cr1) | SW_MODE, &smicntl->smi_cr1);
Vipin KUMARa6e34f72010-01-15 19:15:45 +0530327
Armando Viscontiae3e0cc2012-05-07 13:00:26 +0530328 /* Send Sector Erase command in SW Mode */
329 writel(instruction, &smicntl->smi_tr);
330 writel((bank << BANKSEL_SHIFT) | SEND | TX_LEN_4,
Vipin KUMARa6e34f72010-01-15 19:15:45 +0530331 &smicntl->smi_cr2);
Armando Viscontiae3e0cc2012-05-07 13:00:26 +0530332 if (smi_wait_xfer_finish(XFER_FINISH_TOUT))
333 return -EIO;
Vipin KUMARa6e34f72010-01-15 19:15:45 +0530334
Armando Viscontiae3e0cc2012-05-07 13:00:26 +0530335 if (smi_wait_till_ready(bank, CONFIG_SYS_FLASH_ERASE_TOUT))
336 return -EBUSY;
Vipin KUMARa6e34f72010-01-15 19:15:45 +0530337
Armando Viscontiae3e0cc2012-05-07 13:00:26 +0530338 /* Put SMI in HW mode */
339 writel(readl(&smicntl->smi_cr1) & ~SW_MODE,
Vipin KUMARa6e34f72010-01-15 19:15:45 +0530340 &smicntl->smi_cr1);
341
Armando Viscontiae3e0cc2012-05-07 13:00:26 +0530342 return 0;
Vipin KUMARa6e34f72010-01-15 19:15:45 +0530343}
344
345/*
346 * smi_write - Write to SMI flash
347 * @src_addr: source buffer
348 * @dst_addr: destination buffer
Stefan Roese185b3b72012-02-02 13:25:45 +0100349 * @length: length to write in bytes
Vipin KUMARa6e34f72010-01-15 19:15:45 +0530350 * @bank: bank base address
351 *
352 * Write to SMI flash
353 */
354static int smi_write(unsigned int *src_addr, unsigned int *dst_addr,
355 unsigned int length, ulong bank_addr)
356{
Stefan Roese185b3b72012-02-02 13:25:45 +0100357 u8 *src_addr8 = (u8 *)src_addr;
358 u8 *dst_addr8 = (u8 *)dst_addr;
Vipin KUMARa6e34f72010-01-15 19:15:45 +0530359 int banknum;
Stefan Roese185b3b72012-02-02 13:25:45 +0100360 int i;
Vipin KUMARa6e34f72010-01-15 19:15:45 +0530361
362 switch (bank_addr) {
363 case SMIBANK0_BASE:
364 banknum = BANK0;
Vipin KUMARa6e34f72010-01-15 19:15:45 +0530365 break;
366 case SMIBANK1_BASE:
367 banknum = BANK1;
Vipin KUMARa6e34f72010-01-15 19:15:45 +0530368 break;
369 case SMIBANK2_BASE:
370 banknum = BANK2;
Vipin KUMARa6e34f72010-01-15 19:15:45 +0530371 break;
372 case SMIBANK3_BASE:
373 banknum = BANK3;
Vipin KUMARa6e34f72010-01-15 19:15:45 +0530374 break;
375 default:
376 return -1;
377 }
378
379 if (smi_wait_till_ready(banknum, CONFIG_SYS_FLASH_WRITE_TOUT))
380 return -EBUSY;
381
382 /* Set SMI in Hardware Mode */
383 writel(readl(&smicntl->smi_cr1) & ~SW_MODE, &smicntl->smi_cr1);
384
385 if (smi_write_enable(banknum))
386 return -EIO;
387
388 /* Perform the write command */
Stefan Roese185b3b72012-02-02 13:25:45 +0100389 for (i = 0; i < length; i += 4) {
Vipin KUMARa6e34f72010-01-15 19:15:45 +0530390 if (((ulong) (dst_addr) % SFLASH_PAGE_SIZE) == 0) {
391 if (smi_wait_till_ready(banknum,
392 CONFIG_SYS_FLASH_WRITE_TOUT))
393 return -EBUSY;
394
395 if (smi_write_enable(banknum))
396 return -EIO;
397 }
398
Stefan Roese185b3b72012-02-02 13:25:45 +0100399 if (length < 4) {
400 int k;
401
402 /*
403 * Handle special case, where length < 4 (redundant env)
404 */
405 for (k = 0; k < length; k++)
406 *dst_addr8++ = *src_addr8++;
407 } else {
408 /* Normal 32bit write */
409 *dst_addr++ = *src_addr++;
410 }
Vipin KUMARa6e34f72010-01-15 19:15:45 +0530411
412 if ((readl(&smicntl->smi_sr) & (ERF1 | ERF2)))
413 return -EIO;
414 }
415
416 if (smi_wait_till_ready(banknum, CONFIG_SYS_FLASH_WRITE_TOUT))
417 return -EBUSY;
418
419 writel(readl(&smicntl->smi_sr) & ~(WCF), &smicntl->smi_sr);
420
421 return 0;
422}
423
424/*
425 * write_buff - Write to SMI flash
426 * @info: flash info structure
427 * @src: source buffer
428 * @dest_addr: destination buffer
429 * @length: length to write in words
430 *
431 * Write to SMI flash
432 */
433int write_buff(flash_info_t *info, uchar *src, ulong dest_addr, ulong length)
434{
435 return smi_write((unsigned int *)src, (unsigned int *)dest_addr,
Stefan Roese185b3b72012-02-02 13:25:45 +0100436 length, info->start[0]);
Vipin KUMARa6e34f72010-01-15 19:15:45 +0530437}
438
439/*
440 * flash_init - SMI flash initialization
441 *
442 * SMI flash initialization
443 */
444unsigned long flash_init(void)
445{
446 unsigned long size = 0;
447 int i, j;
448
449 smi_init();
450
451 for (i = 0; i < CONFIG_SYS_MAX_FLASH_BANKS; i++) {
452 flash_info[i].flash_id = FLASH_UNKNOWN;
453 size += flash_info[i].size = flash_get_size(bank_base[i], i);
454 }
455
456 for (j = 0; j < CONFIG_SYS_MAX_FLASH_BANKS; j++) {
457 for (i = 1; i < flash_info[j].sector_count; i++)
458 flash_info[j].start[i] =
459 flash_info[j].start[i - 1] +
460 flash_info->size / flash_info->sector_count;
461
462 }
463
464 return size;
465}
466
467/*
468 * flash_print_info - Print SMI flash information
469 *
470 * Print SMI flash information
471 */
472void flash_print_info(flash_info_t *info)
473{
474 int i;
475 if (info->flash_id == FLASH_UNKNOWN) {
476 puts("missing or unknown FLASH type\n");
477 return;
478 }
Armando Visconticf9026d2012-05-07 13:00:28 +0530479
480 if (info->size >= 0x100000)
481 printf(" Size: %ld MB in %d Sectors\n",
482 info->size >> 20, info->sector_count);
483 else
484 printf(" Size: %ld KB in %d Sectors\n",
485 info->size >> 10, info->sector_count);
Vipin KUMARa6e34f72010-01-15 19:15:45 +0530486
487 puts(" Sector Start Addresses:");
488 for (i = 0; i < info->sector_count; ++i) {
489#ifdef CONFIG_SYS_FLASH_EMPTY_INFO
490 int size;
491 int erased;
492 u32 *flash;
493
494 /*
495 * Check if whole sector is erased
496 */
497 size = (info->size) / (info->sector_count);
498 flash = (u32 *) info->start[i];
499 size = size / sizeof(int);
500
501 while ((size--) && (*flash++ == ~0))
502 ;
503
504 size++;
505 if (size)
506 erased = 0;
507 else
508 erased = 1;
509
510 if ((i % 5) == 0)
511 printf("\n");
512
513 printf(" %08lX%s%s",
514 info->start[i],
515 erased ? " E" : " ", info->protect[i] ? "RO " : " ");
516#else
517 if ((i % 5) == 0)
518 printf("\n ");
519 printf(" %08lX%s",
520 info->start[i], info->protect[i] ? " (RO) " : " ");
521#endif
522 }
523 putc('\n');
524 return;
525}
526
527/*
528 * flash_erase - Erase SMI flash
529 *
530 * Erase SMI flash
531 */
532int flash_erase(flash_info_t *info, int s_first, int s_last)
533{
534 int rcode = 0;
535 int prot = 0;
536 flash_sect_t sect;
537
Vipin KUMARa6e34f72010-01-15 19:15:45 +0530538 if ((s_first < 0) || (s_first > s_last)) {
539 puts("- no sectors to erase\n");
540 return 1;
541 }
542
543 for (sect = s_first; sect <= s_last; ++sect) {
544 if (info->protect[sect])
545 prot++;
546 }
547 if (prot) {
548 printf("- Warning: %d protected sectors will not be erased!\n",
549 prot);
550 } else {
551 putc('\n');
552 }
553
554 for (sect = s_first; sect <= s_last; sect++) {
555 if (info->protect[sect] == 0) {
556 if (smi_sector_erase(info, sect))
557 rcode = 1;
558 else
559 putc('.');
560 }
561 }
562 puts(" done\n");
563 return rcode;
564}
565#endif