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.
27 #include "m29f400bt.h"
30 int probe_m29f400bt(struct flashchip *flash)
32 volatile uint8_t *bios = flash->virt_addr;
35 *(volatile uint8_t *) (bios + 0xAAA) = 0xAA;
36 *(volatile uint8_t *) (bios + 0x555) = 0x55;
37 *(volatile uint8_t *) (bios + 0xAAA) = 0x90;
41 id1 = *(volatile uint8_t *) bios;
42 id2 = *(volatile uint8_t *) (bios + 0x02);
44 *(volatile uint8_t *) (bios + 0xAAA) = 0xAA;
45 *(volatile uint8_t *) (bios + 0x555) = 0x55;
46 *(volatile uint8_t *) (bios + 0xAAA) = 0xF0;
50 printf_debug("%s: id1 0x%x, id2 0x%x\n", __FUNCTION__, id1, id2);
53 if (id1 == flash->manufacture_id && id2 == flash->model_id)
59 int erase_m29f400bt(struct flashchip *flash)
61 volatile uint8_t *bios = flash->virt_addr;
63 *(volatile uint8_t *) (bios + 0xAAA) = 0xAA;
64 *(volatile uint8_t *) (bios + 0x555) = 0x55;
65 *(volatile uint8_t *) (bios + 0xAAA) = 0x80;
67 *(volatile uint8_t *) (bios + 0xAAA) = 0xAA;
68 *(volatile uint8_t *) (bios + 0x555) = 0x55;
69 *(volatile uint8_t *) (bios + 0xAAA) = 0x10;
72 toggle_ready_m29f400bt(bios);
77 int block_erase_m29f400bt(volatile uint8_t *bios, volatile uint8_t *dst)
80 *(volatile uint8_t *) (bios + 0xAAA) = 0xAA;
81 *(volatile uint8_t *) (bios + 0x555) = 0x55;
82 *(volatile uint8_t *) (bios + 0xAAA) = 0x80;
84 *(volatile uint8_t *) (bios + 0xAAA) = 0xAA;
85 *(volatile uint8_t *) (bios + 0x555) = 0x55;
86 //*(volatile uint8_t *) (bios + 0xAAA) = 0x10;
90 toggle_ready_m29f400bt(bios);
95 int write_m29f400bt(struct flashchip *flash, uint8_t *buf)
98 int total_size = flash->total_size * 1024, page_size =
100 volatile uint8_t *bios = flash->virt_addr;
102 //erase_m29f400bt (flash);
103 printf("Programming Page:\n ");
104 /*********************************
105 *Pages for M29F400BT:
106 * 16 0x7c000 0x7ffff TOP
113 *---------------------------------
117 * 64 0x00000 0x0ffff BOTTOM
118 *********************************/
119 printf("total_size/page_size = %d\n", total_size / page_size);
120 for (i = 0; i < (total_size / page_size) - 1; i++) {
121 printf("%04d at address: 0x%08x\n", i, i * page_size);
122 block_erase_m29f400bt(bios, bios + i * page_size);
123 write_page_m29f400bt(bios, buf + i * page_size,
124 bios + i * page_size, page_size);
126 ("\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");
129 printf("%04d at address: 0x%08x\n", 7, 0x70000);
130 block_erase_m29f400bt(bios, bios + 0x70000);
131 write_page_m29f400bt(bios, buf + 0x70000, bios + 0x70000,
134 printf("%04d at address: 0x%08x\n", 8, 0x78000);
135 block_erase_m29f400bt(bios, bios + 0x78000);
136 write_page_m29f400bt(bios, buf + 0x78000, bios + 0x78000,
139 printf("%04d at address: 0x%08x\n", 9, 0x7a000);
140 block_erase_m29f400bt(bios, bios + 0x7a000);
141 write_page_m29f400bt(bios, buf + 0x7a000, bios + 0x7a000,
144 printf("%04d at address: 0x%08x\n", 10, 0x7c000);
145 block_erase_m29f400bt(bios, bios + 0x7c000);
146 write_page_m29f400bt(bios, buf + 0x7c000, bios + 0x7c000,
150 //protect_m29f400bt (bios);
155 int write_linuxbios_m29f400bt(struct flashchip *flash, uint8_t *buf)
157 volatile uint8_t *bios = flash->virt_addr;
159 printf("Programming Page:\n ");
160 /*********************************
161 *Pages for M29F400BT:
162 * 16 0x7c000 0x7ffff TOP
169 *---------------------------------
173 * 64 0x00000 0x0ffff BOTTOM
174 *********************************/
175 printf("%04d at address: 0x%08x\n", 7, 0x00000);
176 block_erase_m29f400bt(bios, bios + 0x00000);
177 write_page_m29f400bt(bios, buf + 0x00000, bios + 0x00000,
180 printf("%04d at address: 0x%08x\n", 7, 0x10000);
181 block_erase_m29f400bt(bios, bios + 0x10000);
182 write_page_m29f400bt(bios, buf + 0x10000, bios + 0x10000,
185 printf("%04d at address: 0x%08x\n", 7, 0x20000);
186 block_erase_m29f400bt(bios, bios + 0x20000);
187 write_page_m29f400bt(bios, buf + 0x20000, bios + 0x20000,
190 printf("%04d at address: 0x%08x\n", 7, 0x30000);
191 block_erase_m29f400bt(bios, bios + 0x30000);
192 write_page_m29f400bt(bios, buf + 0x30000, bios + 0x30000,
196 //protect_m29f400bt (bios);