2 * jedec.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.
31 int probe_jedec(struct flashchip *flash)
33 volatile unsigned char *bios = flash->virt_addr;
34 unsigned char id1, id2;
36 /* Issue JEDEC Product ID Entry command */
37 *(volatile char *) (bios + 0x5555) = 0xAA;
39 *(volatile char *) (bios + 0x2AAA) = 0x55;
41 *(volatile char *) (bios + 0x5555) = 0x90;
45 id1 = *(volatile unsigned char *) bios;
46 id2 = *(volatile unsigned char *) (bios + 0x01);
48 /* Issue JEDEC Product ID Exit command */
49 *(volatile char *) (bios + 0x5555) = 0xAA;
51 *(volatile char *) (bios + 0x2AAA) = 0x55;
53 *(volatile char *) (bios + 0x5555) = 0xF0;
56 printf("%s: id1 0x%x, id2 0x%x\n", __FUNCTION__, id1, id2);
57 if (id1 == flash->manufacture_id && id2 == flash->model_id)
63 int erase_sector_jedec(volatile unsigned char *bios, unsigned int page)
65 /* Issue the Sector Erase command */
66 *(volatile char *) (bios + 0x5555) = 0xAA;
68 *(volatile char *) (bios + 0x2AAA) = 0x55;
70 *(volatile char *) (bios + 0x5555) = 0x80;
73 *(volatile char *) (bios + 0x5555) = 0xAA;
75 *(volatile char *) (bios + 0x2AAA) = 0x55;
77 *(volatile char *) (bios + page) = 0x30;
80 /* wait for Toggle bit ready */
81 toggle_ready_jedec(bios);
86 int erase_block_jedec(volatile unsigned char *bios, unsigned int block)
88 /* Issue the Sector Erase command */
89 *(volatile char *) (bios + 0x5555) = 0xAA;
91 *(volatile char *) (bios + 0x2AAA) = 0x55;
93 *(volatile char *) (bios + 0x5555) = 0x80;
96 *(volatile char *) (bios + 0x5555) = 0xAA;
98 *(volatile char *) (bios + 0x2AAA) = 0x55;
100 *(volatile char *) (bios + block) = 0x50;
103 /* wait for Toggle bit ready */
104 toggle_ready_jedec(bios);
109 int erase_chip_jedec(struct flashchip *flash)
111 volatile unsigned char *bios = flash->virt_addr;
113 /* Issue the JEDEC Chip Erase command */
114 *(volatile char *) (bios + 0x5555) = 0xAA;
116 *(volatile char *) (bios + 0x2AAA) = 0x55;
118 *(volatile char *) (bios + 0x5555) = 0x80;
121 *(volatile char *) (bios + 0x5555) = 0xAA;
123 *(volatile char *) (bios + 0x2AAA) = 0x55;
125 *(volatile char *) (bios + 0x5555) = 0x10;
128 toggle_ready_jedec(bios);
133 int write_page_write_jedec(volatile unsigned char *bios, unsigned char *src,
134 volatile unsigned char *dst, int page_size)
138 /* Issue JEDEC Data Unprotect comand */
139 *(volatile unsigned char *) (bios + 0x5555) = 0xAA;
140 *(volatile unsigned char *) (bios + 0x2AAA) = 0x55;
141 *(volatile unsigned char *) (bios + 0x5555) = 0xA0;
143 /* transfer data from source to destination */
144 for (i = 0; i < page_size; i++) {
145 /* If the data is 0xFF, don't program it */
151 toggle_ready_jedec(dst - 1);
156 int write_byte_program_jedec(volatile unsigned char *bios, unsigned char *src,
157 volatile unsigned char *dst)
161 /* If the data is 0xFF, don't program it */
167 /* Issue JEDEC Byte Program command */
168 *(volatile unsigned char *) (bios + 0x5555) = 0xAA;
169 *(volatile unsigned char *) (bios + 0x2AAA) = 0x55;
170 *(volatile unsigned char *) (bios + 0x5555) = 0xA0;
172 /* transfer data from source to destination */
174 toggle_ready_jedec(bios);
176 if (*dst != *src && tried++ < 0x10) {
183 int write_sector_jedec(volatile unsigned char *bios, unsigned char *src,
184 volatile unsigned char *dst, unsigned int page_size)
188 for (i = 0; i < page_size; i++) {
189 write_byte_program_jedec(bios, src, dst);
196 int write_jedec(struct flashchip *flash, unsigned char *buf)
199 int total_size = flash->total_size * 1024;
200 int page_size = flash->page_size;
201 volatile unsigned char *bios = flash->virt_addr;
203 erase_chip_jedec(flash);
204 if (*bios != (unsigned char) 0xff) {
205 printf("ERASE FAILED\n");
208 printf("Programming Page: ");
209 for (i = 0; i < total_size / page_size; i++) {
210 printf("%04d at address: 0x%08x", i, i * page_size);
211 write_page_write_jedec(bios, buf + i * page_size,
212 bios + i * page_size, page_size);
213 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");