2 * m29f400bt.c: driver for programming JEDEC standard flash parts
5 * Copyright 2000 Silicon Integrated System Corporation
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 void toggle_ready_m29f400bt(volatile uint8_t *dst)
35 while (i++ < 0xFFFFFF) {
44 void data_polling_m29f400bt(volatile uint8_t *dst, uint8_t data)
51 while (i++ < 0xFFFFFF) {
59 void protect_m29f400bt(volatile uint8_t *bios)
61 *(volatile uint8_t *)(bios + 0xAAA) = 0xAA;
62 *(volatile uint8_t *)(bios + 0x555) = 0x55;
63 *(volatile uint8_t *)(bios + 0xAAA) = 0xA0;
68 void write_page_m29f400bt(volatile uint8_t *bios, uint8_t *src,
69 volatile uint8_t *dst, int page_size)
73 for (i = 0; i < page_size; i++) {
74 *(volatile uint8_t *)(bios + 0xAAA) = 0xAA;
75 *(volatile uint8_t *)(bios + 0x555) = 0x55;
76 *(volatile uint8_t *)(bios + 0xAAA) = 0xA0;
78 /* transfer data from source to destination */
80 //*(volatile char *) (bios) = 0xF0;
82 toggle_ready_m29f400bt(dst);
84 ("Value in the flash at address %p = %#x, want %#x\n",
85 (uint8_t *) (dst - bios), *dst, *src);
91 int probe_m29f400bt(struct flashchip *flash)
93 volatile uint8_t *bios = flash->virtual_memory;
96 *(volatile uint8_t *)(bios + 0xAAA) = 0xAA;
97 *(volatile uint8_t *)(bios + 0x555) = 0x55;
98 *(volatile uint8_t *)(bios + 0xAAA) = 0x90;
102 id1 = *(volatile uint8_t *)bios;
103 id2 = *(volatile uint8_t *)(bios + 0x02);
105 *(volatile uint8_t *)(bios + 0xAAA) = 0xAA;
106 *(volatile uint8_t *)(bios + 0x555) = 0x55;
107 *(volatile uint8_t *)(bios + 0xAAA) = 0xF0;
111 printf_debug("%s: id1 0x%x, id2 0x%x\n", __FUNCTION__, id1, id2);
113 if (id1 == flash->manufacture_id && id2 == flash->model_id)
119 int erase_m29f400bt(struct flashchip *flash)
121 volatile uint8_t *bios = flash->virtual_memory;
123 *(volatile uint8_t *)(bios + 0xAAA) = 0xAA;
124 *(volatile uint8_t *)(bios + 0x555) = 0x55;
125 *(volatile uint8_t *)(bios + 0xAAA) = 0x80;
127 *(volatile uint8_t *)(bios + 0xAAA) = 0xAA;
128 *(volatile uint8_t *)(bios + 0x555) = 0x55;
129 *(volatile uint8_t *)(bios + 0xAAA) = 0x10;
132 toggle_ready_m29f400bt(bios);
137 int block_erase_m29f400bt(volatile uint8_t *bios, volatile uint8_t *dst)
140 *(volatile uint8_t *)(bios + 0xAAA) = 0xAA;
141 *(volatile uint8_t *)(bios + 0x555) = 0x55;
142 *(volatile uint8_t *)(bios + 0xAAA) = 0x80;
144 *(volatile uint8_t *)(bios + 0xAAA) = 0xAA;
145 *(volatile uint8_t *)(bios + 0x555) = 0x55;
146 //*(volatile uint8_t *) (bios + 0xAAA) = 0x10;
150 toggle_ready_m29f400bt(bios);
155 int write_m29f400bt(struct flashchip *flash, uint8_t *buf)
158 int total_size = flash->total_size * 1024;
159 int page_size = flash->page_size;
160 volatile uint8_t *bios = flash->virtual_memory;
162 //erase_m29f400bt (flash);
163 printf("Programming Page:\n ");
164 /*********************************
165 *Pages for M29F400BT:
166 * 16 0x7c000 0x7ffff TOP
173 *---------------------------------
177 * 64 0x00000 0x0ffff BOTTOM
178 *********************************/
179 printf("total_size/page_size = %d\n", total_size / page_size);
180 for (i = 0; i < (total_size / page_size) - 1; i++) {
181 printf("%04d at address: 0x%08x\n", i, i * page_size);
182 block_erase_m29f400bt(bios, bios + i * page_size);
183 write_page_m29f400bt(bios, buf + i * page_size,
184 bios + i * page_size, page_size);
185 printf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b");
188 printf("%04d at address: 0x%08x\n", 7, 0x70000);
189 block_erase_m29f400bt(bios, bios + 0x70000);
190 write_page_m29f400bt(bios, buf + 0x70000, bios + 0x70000, 32 * 1024);
192 printf("%04d at address: 0x%08x\n", 8, 0x78000);
193 block_erase_m29f400bt(bios, bios + 0x78000);
194 write_page_m29f400bt(bios, buf + 0x78000, bios + 0x78000, 8 * 1024);
196 printf("%04d at address: 0x%08x\n", 9, 0x7a000);
197 block_erase_m29f400bt(bios, bios + 0x7a000);
198 write_page_m29f400bt(bios, buf + 0x7a000, bios + 0x7a000, 8 * 1024);
200 printf("%04d at address: 0x%08x\n", 10, 0x7c000);
201 block_erase_m29f400bt(bios, bios + 0x7c000);
202 write_page_m29f400bt(bios, buf + 0x7c000, bios + 0x7c000, 16 * 1024);
205 //protect_m29f400bt (bios);
210 int write_linuxbios_m29f400bt(struct flashchip *flash, uint8_t *buf)
212 volatile uint8_t *bios = flash->virtual_memory;
214 printf("Programming Page:\n ");
215 /*********************************
216 *Pages for M29F400BT:
217 * 16 0x7c000 0x7ffff TOP
224 *---------------------------------
228 * 64 0x00000 0x0ffff BOTTOM
229 *********************************/
230 printf("%04d at address: 0x%08x\n", 7, 0x00000);
231 block_erase_m29f400bt(bios, bios + 0x00000);
232 write_page_m29f400bt(bios, buf + 0x00000, bios + 0x00000, 64 * 1024);
234 printf("%04d at address: 0x%08x\n", 7, 0x10000);
235 block_erase_m29f400bt(bios, bios + 0x10000);
236 write_page_m29f400bt(bios, buf + 0x10000, bios + 0x10000, 64 * 1024);
238 printf("%04d at address: 0x%08x\n", 7, 0x20000);
239 block_erase_m29f400bt(bios, bios + 0x20000);
240 write_page_m29f400bt(bios, buf + 0x20000, bios + 0x20000, 64 * 1024);
242 printf("%04d at address: 0x%08x\n", 7, 0x30000);
243 block_erase_m29f400bt(bios, bios + 0x30000);
244 write_page_m29f400bt(bios, buf + 0x30000, bios + 0x30000, 64 * 1024);
247 //protect_m29f400bt (bios);