2
* (C) Copyright 2000-2004
3
* Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5
* SPDX-License-Identifier: GPL-2.0+
10
#if defined(CONFIG_NIOS)
16
#define SECTSZ (64 * 1024)
17
flash_info_t flash_info[CONFIG_SYS_MAX_FLASH_BANKS];
19
/*----------------------------------------------------------------------*/
20
unsigned long flash_init (void)
24
flash_info_t *fli = &flash_info[0];
26
fli->size = CONFIG_SYS_FLASH_SIZE;
27
fli->sector_count = CONFIG_SYS_MAX_FLASH_SECT;
28
fli->flash_id = FLASH_MAN_AMD + FLASH_AMDLV065D;
30
addr = CONFIG_SYS_FLASH_BASE;
31
for (i = 0; i < fli->sector_count; ++i) {
37
return (CONFIG_SYS_FLASH_SIZE);
39
/*--------------------------------------------------------------------*/
40
void flash_print_info (flash_info_t * info)
46
printf (" Size: %ld KB in %d Sectors\n",
47
info->size >> 10, info->sector_count);
48
printf (" Sector Start Addresses:");
49
for (i = 0; i < info->sector_count; ++i) {
51
/* Check if whole sector is erased */
53
addr = (unsigned long *) info->start[i];
54
for (k = 0; k < SECTSZ/sizeof(unsigned long); k++) {
55
if ( readl(addr++) != (unsigned long)-1) {
67
info->protect[i] ? "RO " : " ");
72
/*-------------------------------------------------------------------*/
75
int flash_erase (flash_info_t * info, int s_first, int s_last)
77
unsigned char *addr = (unsigned char *) info->start[0];
82
/* Some sanity checking */
83
if ((s_first < 0) || (s_first > s_last)) {
84
printf ("- no sectors to erase\n");
89
for (sect = s_first; sect <= s_last; ++sect) {
90
if (info->protect[sect]) {
95
printf ("- Warning: %d protected sectors will not be erased!\n",
101
/* It's ok to erase multiple sectors provided we don't delay more
102
* than 50 usec between cmds ... at which point the erase time-out
103
* occurs. So don't go and put printf() calls in the loop ... it
104
* won't be very helpful ;-)
106
for (sect = s_first; sect <= s_last; sect++) {
107
if (info->protect[sect] == 0) { /* not protected */
108
addr2 = (unsigned char *) info->start[sect];
114
writeb (0x30, addr2);
115
/* Now just wait for 0xff & provide some user
116
* feedback while we wait.
118
start = get_timer (0);
119
while ( readb (addr2) != 0xff) {
120
udelay (1000 * 1000);
122
if (get_timer (start) > CONFIG_SYS_FLASH_ERASE_TOUT) {
123
printf ("timeout\n");
133
/*-----------------------------------------------------------------------
134
* Copy memory to flash, returns:
137
* 2 - Flash not erased
140
int write_buff (flash_info_t * info, uchar * src, ulong addr, ulong cnt)
143
vu_char *cmd = (vu_char *) info->start[0];
144
vu_char *dst = (vu_char *) addr;
149
/* Check for sufficient erase */
151
if ((readb (dst) & b) != b) {
152
printf ("%02x : %02x\n", readb (dst), b);
162
start = get_timer (0);
163
while (readb (dst) != b) {
164
if (get_timer (start) > CONFIG_SYS_FLASH_WRITE_TOUT) {