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,
23 * Hacked for the Hymod board by Murray.Jensen@cmst.csiro.au, 20-Oct-00
28 #include <galileo/gt64260R.h>
29 #include <galileo/memory.h>
30 #include "intel_flash.h"
33 /*-----------------------------------------------------------------------
36 #define FLAG_PROTECT_SET 0x01
37 #define FLAG_PROTECT_CLEAR 0x02
40 bank_reset(flash_info_t *info, int sect)
42 bank_addr_t addrw, eaddrw;
44 addrw = (bank_addr_t)info->start[sect];
45 eaddrw = BANK_ADDR_NEXT_WORD(addrw);
47 while (addrw < eaddrw) {
49 printf(" writing reset cmd to addr 0x%08lx\n",
50 (unsigned long)addrw);
52 *addrw = BANK_CMD_RST;
58 bank_erase_init(flash_info_t *info, int sect)
60 bank_addr_t addrw, saddrw, eaddrw;
64 printf("0x%08x BANK_CMD_PROG\n", BANK_CMD_PROG);
65 printf("0x%08x BANK_CMD_ERASE1\n", BANK_CMD_ERASE1);
66 printf("0x%08x BANK_CMD_ERASE2\n", BANK_CMD_ERASE2);
67 printf("0x%08x BANK_CMD_CLR_STAT\n", BANK_CMD_CLR_STAT);
68 printf("0x%08x BANK_CMD_RST\n", BANK_CMD_RST);
69 printf("0x%08x BANK_STAT_RDY\n", BANK_STAT_RDY);
70 printf("0x%08x BANK_STAT_ERR\n", BANK_STAT_ERR);
73 saddrw = (bank_addr_t)info->start[sect];
74 eaddrw = BANK_ADDR_NEXT_WORD(saddrw);
77 printf("erasing sector %d, start addr = 0x%08lx "
78 "(bank next word addr = 0x%08lx)\n", sect,
79 (unsigned long)saddrw, (unsigned long)eaddrw);
82 /* Disable intrs which might cause a timeout here */
83 flag = disable_interrupts();
85 for (addrw = saddrw; addrw < eaddrw; addrw++) {
87 printf(" writing erase cmd to addr 0x%08lx\n",
88 (unsigned long)addrw);
90 *addrw = BANK_CMD_ERASE1;
91 *addrw = BANK_CMD_ERASE2;
94 /* re-enable interrupts if necessary */
100 bank_erase_poll(flash_info_t *info, int sect)
102 bank_addr_t addrw, saddrw, eaddrw;
103 int sectdone, haderr;
105 saddrw = (bank_addr_t)info->start[sect];
106 eaddrw = BANK_ADDR_NEXT_WORD(saddrw);
111 for (addrw = saddrw; addrw < eaddrw; addrw++) {
112 bank_word_t stat = *addrw;
115 printf(" checking status at addr "
117 (unsigned long)addrw, stat);
119 if ((stat & BANK_STAT_RDY) != BANK_STAT_RDY)
121 else if ((stat & BANK_STAT_ERR) != 0) {
122 printf(" failed on sector %d "
123 "(stat = 0x%08x) at "
126 *addrw = BANK_CMD_CLR_STAT;
138 write_word_intel(bank_addr_t addr, bank_word_t value)
144 /* Disable interrupts which might cause a timeout here */
145 flag = disable_interrupts();
147 *addr = BANK_CMD_PROG;
151 /* re-enable interrupts if necessary */
157 /* data polling for D7 */
158 start = get_timer (0);
160 if (get_timer(start) > CONFIG_SYS_FLASH_WRITE_TOUT) {
165 } while ((stat & BANK_STAT_RDY) != BANK_STAT_RDY);
167 if ((stat & BANK_STAT_ERR) != 0) {
168 printf("flash program failed (stat = 0x%08lx) "
169 "at address 0x%08lx\n", (ulong)stat, (ulong)addr);
170 *addr = BANK_CMD_CLR_STAT;
175 /* reset to read mode */
176 *addr = BANK_CMD_RST;
181 /*-----------------------------------------------------------------------
185 flash_erase_intel(flash_info_t *info, int s_first, int s_last)
187 int prot, sect, haderr;
188 ulong start, now, last;
191 printf("\nflash_erase: erase %d sectors (%d to %d incl.) from\n"
192 " Bank # %d: ", s_last - s_first + 1, s_first, s_last,
193 (info - flash_info) + 1);
194 flash_print_info(info);
197 if ((s_first < 0) || (s_first > s_last)) {
198 if (info->flash_id == FLASH_UNKNOWN) {
199 printf ("- missing\n");
201 printf ("- no sectors to erase\n");
207 for (sect=s_first; sect<=s_last; ++sect) {
208 if (info->protect[sect]) {
214 printf("- Warning: %d protected sector%s will not be erased!\n",
215 prot, (prot > 1 ? "s" : ""));
218 start = get_timer (0);
222 for (sect = s_first; sect <= s_last; sect++) {
223 if (info->protect[sect] == 0) { /* not protected */
227 bank_erase_init(info, sect);
229 /* wait at least 80us - let's wait 1 ms */
232 estart = get_timer(start);
235 now = get_timer(start);
237 if (now - estart > CONFIG_SYS_FLASH_ERASE_TOUT) {
238 printf ("Timeout (sect %d)\n", sect);
244 /* show that we're waiting */
245 if ((now - last) > 1000) { /* every second */
251 sectdone = bank_erase_poll(info, sect);
266 printf (" failed\n");
270 /* reset to read mode */
271 for (sect = s_first; sect <= s_last; sect++) {
272 if (info->protect[sect] == 0) { /* not protected */
273 bank_reset(info, sect);