2 * (C) Copyright 2000-2004
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * See file CREDITS for list of people who contributed to this
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,
26 #if defined(CONFIG_NIOS)
32 #define SECTSZ (64 * 1024)
33 flash_info_t flash_info
[CONFIG_SYS_MAX_FLASH_BANKS
];
35 /*----------------------------------------------------------------------*/
36 unsigned long flash_init (void)
40 flash_info_t
*fli
= &flash_info
[0];
42 fli
->size
= CONFIG_SYS_FLASH_SIZE
;
43 fli
->sector_count
= CONFIG_SYS_MAX_FLASH_SECT
;
44 fli
->flash_id
= FLASH_MAN_AMD
+ FLASH_AMDLV065D
;
46 addr
= CONFIG_SYS_FLASH_BASE
;
47 for (i
= 0; i
< fli
->sector_count
; ++i
) {
53 return (CONFIG_SYS_FLASH_SIZE
);
55 /*--------------------------------------------------------------------*/
56 void flash_print_info (flash_info_t
* info
)
62 printf (" Size: %ld KB in %d Sectors\n",
63 info
->size
>> 10, info
->sector_count
);
64 printf (" Sector Start Addresses:");
65 for (i
= 0; i
< info
->sector_count
; ++i
) {
67 /* Check if whole sector is erased */
69 addr
= (unsigned long *) info
->start
[i
];
70 for (k
= 0; k
< SECTSZ
/sizeof(unsigned long); k
++) {
71 if ( readl(addr
++) != (unsigned long)-1) {
83 info
->protect
[i
] ? "RO " : " ");
88 /*-------------------------------------------------------------------*/
91 int flash_erase (flash_info_t
* info
, int s_first
, int s_last
)
93 unsigned char *addr
= (unsigned char *) info
->start
[0];
98 /* Some sanity checking */
99 if ((s_first
< 0) || (s_first
> s_last
)) {
100 printf ("- no sectors to erase\n");
105 for (sect
= s_first
; sect
<= s_last
; ++sect
) {
106 if (info
->protect
[sect
]) {
111 printf ("- Warning: %d protected sectors will not be erased!\n",
117 /* It's ok to erase multiple sectors provided we don't delay more
118 * than 50 usec between cmds ... at which point the erase time-out
119 * occurs. So don't go and put printf() calls in the loop ... it
120 * won't be very helpful ;-)
122 for (sect
= s_first
; sect
<= s_last
; sect
++) {
123 if (info
->protect
[sect
] == 0) { /* not protected */
124 addr2
= (unsigned char *) info
->start
[sect
];
130 writeb (addr2
, 0x30);
131 /* Now just wait for 0xff & provide some user
132 * feedback while we wait.
134 start
= get_timer (0);
135 while ( readb (addr2
) != 0xff) {
136 udelay (1000 * 1000);
138 if (get_timer (start
) > CONFIG_SYS_FLASH_ERASE_TOUT
) {
139 printf ("timeout\n");
149 /*-----------------------------------------------------------------------
150 * Copy memory to flash, returns:
153 * 2 - Flash not erased
156 int write_buff (flash_info_t
* info
, uchar
* src
, ulong addr
, ulong cnt
)
159 vu_char
*cmd
= (vu_char
*) info
->start
[0];
160 vu_char
*dst
= (vu_char
*) addr
;
165 /* Check for sufficient erase */
167 if ((readb (dst
) & b
) != b
) {
168 printf ("%02x : %02x\n", readb (dst
), b
);
178 start
= get_timer (0);
179 while (readb (dst
) != b
) {
180 if (get_timer (start
) > CONFIG_SYS_FLASH_WRITE_TOUT
) {