3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * SPDX-License-Identifier: GPL-2.0+
6 * Hacked for the Hymod board by Murray.Jensen@cmst.csiro.au, 20-Oct-00
11 #include <galileo/gt64260R.h>
12 #include <galileo/memory.h>
13 #include "intel_flash.h"
16 /*-----------------------------------------------------------------------
19 #define FLAG_PROTECT_SET 0x01
20 #define FLAG_PROTECT_CLEAR 0x02
23 bank_reset(flash_info_t *info, int sect)
25 bank_addr_t addrw, eaddrw;
27 addrw = (bank_addr_t)info->start[sect];
28 eaddrw = BANK_ADDR_NEXT_WORD(addrw);
30 while (addrw < eaddrw) {
32 printf(" writing reset cmd to addr 0x%08lx\n",
33 (unsigned long)addrw);
35 *addrw = BANK_CMD_RST;
41 bank_erase_init(flash_info_t *info, int sect)
43 bank_addr_t addrw, saddrw, eaddrw;
47 printf("0x%08x BANK_CMD_PROG\n", BANK_CMD_PROG);
48 printf("0x%08x BANK_CMD_ERASE1\n", BANK_CMD_ERASE1);
49 printf("0x%08x BANK_CMD_ERASE2\n", BANK_CMD_ERASE2);
50 printf("0x%08x BANK_CMD_CLR_STAT\n", BANK_CMD_CLR_STAT);
51 printf("0x%08x BANK_CMD_RST\n", BANK_CMD_RST);
52 printf("0x%08x BANK_STAT_RDY\n", BANK_STAT_RDY);
53 printf("0x%08x BANK_STAT_ERR\n", BANK_STAT_ERR);
56 saddrw = (bank_addr_t)info->start[sect];
57 eaddrw = BANK_ADDR_NEXT_WORD(saddrw);
60 printf("erasing sector %d, start addr = 0x%08lx "
61 "(bank next word addr = 0x%08lx)\n", sect,
62 (unsigned long)saddrw, (unsigned long)eaddrw);
65 /* Disable intrs which might cause a timeout here */
66 flag = disable_interrupts();
68 for (addrw = saddrw; addrw < eaddrw; addrw++) {
70 printf(" writing erase cmd to addr 0x%08lx\n",
71 (unsigned long)addrw);
73 *addrw = BANK_CMD_ERASE1;
74 *addrw = BANK_CMD_ERASE2;
77 /* re-enable interrupts if necessary */
83 bank_erase_poll(flash_info_t *info, int sect)
85 bank_addr_t addrw, saddrw, eaddrw;
88 saddrw = (bank_addr_t)info->start[sect];
89 eaddrw = BANK_ADDR_NEXT_WORD(saddrw);
94 for (addrw = saddrw; addrw < eaddrw; addrw++) {
95 bank_word_t stat = *addrw;
98 printf(" checking status at addr "
100 (unsigned long)addrw, stat);
102 if ((stat & BANK_STAT_RDY) != BANK_STAT_RDY)
104 else if ((stat & BANK_STAT_ERR) != 0) {
105 printf(" failed on sector %d "
106 "(stat = 0x%08x) at "
109 *addrw = BANK_CMD_CLR_STAT;
121 write_word_intel(bank_addr_t addr, bank_word_t value)
127 /* Disable interrupts which might cause a timeout here */
128 flag = disable_interrupts();
130 *addr = BANK_CMD_PROG;
134 /* re-enable interrupts if necessary */
140 /* data polling for D7 */
141 start = get_timer (0);
143 if (get_timer(start) > CONFIG_SYS_FLASH_WRITE_TOUT) {
148 } while ((stat & BANK_STAT_RDY) != BANK_STAT_RDY);
150 if ((stat & BANK_STAT_ERR) != 0) {
151 printf("flash program failed (stat = 0x%08lx) "
152 "at address 0x%08lx\n", (ulong)stat, (ulong)addr);
153 *addr = BANK_CMD_CLR_STAT;
158 /* reset to read mode */
159 *addr = BANK_CMD_RST;
164 /*-----------------------------------------------------------------------
168 flash_erase_intel(flash_info_t *info, int s_first, int s_last)
170 int prot, sect, haderr;
171 ulong start, now, last;
174 printf("\nflash_erase: erase %d sectors (%d to %d incl.) from\n"
175 " Bank # %d: ", s_last - s_first + 1, s_first, s_last,
176 (info - flash_info) + 1);
177 flash_print_info(info);
180 if ((s_first < 0) || (s_first > s_last)) {
181 if (info->flash_id == FLASH_UNKNOWN) {
182 printf ("- missing\n");
184 printf ("- no sectors to erase\n");
190 for (sect=s_first; sect<=s_last; ++sect) {
191 if (info->protect[sect]) {
197 printf("- Warning: %d protected sector%s will not be erased!\n",
198 prot, (prot > 1 ? "s" : ""));
201 start = get_timer (0);
205 for (sect = s_first; sect <= s_last; sect++) {
206 if (info->protect[sect] == 0) { /* not protected */
210 bank_erase_init(info, sect);
212 /* wait at least 80us - let's wait 1 ms */
215 estart = get_timer(start);
218 now = get_timer(start);
220 if (now - estart > CONFIG_SYS_FLASH_ERASE_TOUT) {
221 printf ("Timeout (sect %d)\n", sect);
227 /* show that we're waiting */
228 if ((now - last) > 1000) { /* every second */
234 sectdone = bank_erase_poll(info, sect);
249 printf (" failed\n");
253 /* reset to read mode */
254 for (sect = s_first; sect <= s_last; sect++) {
255 if (info->protect[sect] == 0) { /* not protected */
256 bank_reset(info, sect);