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 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 char *bios, unsigned int page)
65 volatile unsigned char *Temp;
67 /* Issue the Sector Erase command */
68 Temp = bios + 0x5555; /* set up address to be BASE:5555h */
69 *Temp = 0xAA; /* write data 0xAA to the address */
71 Temp = bios + 0x2AAA; /* set up address to be BASE:2AAAh */
72 *Temp = 0x55; /* write data 0x55 to the address */
74 Temp = bios + 0x5555; /* set up address to be BASE:5555h */
75 *Temp = 0x80; /* write data 0x80 to the address */
77 Temp = bios + 0x5555; /* set up address to be BASE:5555h */
78 *Temp = 0xAA; /* write data 0xAA to the address */
80 Temp = bios + 0x2AAA; /* set up address to be BASE:2AAAh */
81 *Temp = 0x55; /* write data 0x55 to the address */
83 Temp = bios + page; /* set up address to be the current sector */
84 *Temp = 0x30; /* write data 0x30 to the address */
87 /* wait for Toggle bit ready */
88 toggle_ready_jedec(bios);
93 int erase_chip_jedec(struct flashchip *flash)
95 volatile unsigned char *bios = flash->virt_addr;
96 volatile unsigned char *Temp;
98 /* Issue the JEDEC Chip Erase command */
99 Temp = bios + 0x5555; /* set up address to be BASE:5555h */
100 *Temp = 0xAA; /* write data 0xAA to the address */
102 Temp = bios + 0x2AAA; /* set up address to be BASE:2AAAh */
103 *Temp = 0x55; /* write data 0x55 to the address */
105 Temp = bios + 0x5555; /* set up address to be BASE:5555h */
106 *Temp = 0x80; /* write data 0x80 to the address */
108 Temp = bios + 0x5555; /* set up address to be BASE:5555h */
109 *Temp = 0xAA; /* write data 0xAA to the address */
111 Temp = bios + 0x2AAA; /* set up address to be BASE:2AAAh */
112 *Temp = 0x55; /* write data 0x55 to the address */
114 Temp = bios + 0x5555; /* set up address to be BASEy:5555h */
115 *Temp = 0x10; /* write data 0x10 to the address */
118 toggle_ready_jedec(bios);
123 void write_page_jedec(volatile char *bios, char *src, volatile char *dst,
128 /* Issue JEDEC Data Unprotect comand */
129 *(volatile char *) (bios + 0x5555) = 0xAA;
130 *(volatile char *) (bios + 0x2AAA) = 0x55;
131 *(volatile char *) (bios + 0x5555) = 0xA0;
133 for (i = 0; i < page_size; i++) {
134 /* transfer data from source to destination */
139 toggle_ready_jedec(dst - 1);
142 int wirte_byte_program_jedec(volatile unsigned char *bios, unsigned char *src,
143 volatile unsigned char *dst)
145 volatile unsigned char *Temp;
148 printf("FATAL: dst %p not erased (val 0x%x)\n",
152 /* transfer data from source to destination */
155 /* If the data is 0xFF, don't program it */
158 /* Issue JEDEC Byte Program command */
159 Temp = bios + 0x5555;
161 Temp = bios + 0x2AAA;
163 Temp = bios + 0x5555;
166 toggle_ready_jedec(bios);
168 printf("BAD! dst 0x%lx val 0x%x src 0x%x\n",
169 (unsigned long) dst, *dst, *src);
174 int write_sector_jedec(volatile unsigned char *bios, unsigned char *src,
175 volatile unsigned char *dst,
176 unsigned int page_size)
180 for (i = 0; i < page_size; i++) {
181 wirte_byte_program_jedec(bios, src, dst);
187 int write_jedec(struct flashchip *flash, unsigned char *buf)
190 int total_size = flash->total_size * 1024;
191 int page_size = flash->page_size;
192 volatile unsigned char *bios = flash->virt_addr;
194 erase_chip_jedec(flash);
195 if (*bios != (unsigned char) 0xff) {
196 printf("ERASE FAILED\n");
199 printf("Programming Page: ");
200 for (i = 0; i < total_size / page_size; i++) {
201 printf("%04d at address: 0x%08x", i, i * page_size);
202 write_page_jedec(bios, buf + i * page_size,
203 bios + i * page_size, page_size);
204 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");