2 * lhf00l04.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.
22 * Reference: http://www.intel.com/design/chipsets/datashts/290658.htm
29 void toggle_ready_lhf00l04(volatile uint8_t *dst)
36 while (i++ < 0xFFFFFF) {
45 void data_polling_lhf00l04(volatile uint8_t *dst, uint8_t data)
52 while (i++ < 0xFFFFFF) {
60 void protect_lhf00l04(volatile uint8_t *bios)
62 *(volatile uint8_t *)(bios + 0x5555) = 0xAA;
63 *(volatile uint8_t *)(bios + 0x2AAA) = 0x55;
64 *(volatile uint8_t *)(bios + 0x5555) = 0xA0;
69 // I need that Berkeley bit-map printer
70 void print_lhf00l04_status(uint8_t status)
72 printf("%s", status & 0x80 ? "Ready:" : "Busy:");
73 printf("%s", status & 0x40 ? "BE SUSPEND:" : "BE RUN/FINISH:");
74 printf("%s", status & 0x20 ? "BE ERROR:" : "BE OK:");
75 printf("%s", status & 0x10 ? "PROG ERR:" : "PROG OK:");
76 printf("%s", status & 0x8 ? "VP ERR:" : "VPP OK:");
77 printf("%s", status & 0x4 ? "PROG SUSPEND:" : "PROG RUN/FINISH:");
78 printf("%s", status & 0x2 ? "WP|TBL#|WP#,ABORT:" : "UNLOCK:");
81 int probe_lhf00l04(struct flashchip *flash)
83 volatile uint8_t *bios = flash->virtual_memory;
88 *(volatile uint8_t *)(bios + 0x5555) = 0xAA;
89 *(volatile uint8_t *)(bios + 0x2AAA) = 0x55;
90 *(volatile uint8_t *)(bios + 0x5555) = 0x90;
98 id1 = *(volatile uint8_t *)bios;
99 id2 = *(volatile uint8_t *)(bios + 0x01);
102 *(volatile uint8_t *)(bios + 0x5555) = 0xAA;
103 *(volatile uint8_t *)(bios + 0x2AAA) = 0x55;
104 *(volatile uint8_t *)(bios + 0x5555) = 0xF0;
108 printf_debug("%s: id1 0x%x, id2 0x%x\n", __FUNCTION__, id1, id2);
110 if (id1 != flash->manufacture_id || id2 != flash->model_id)
113 map_flash_registers(flash);
118 uint8_t wait_lhf00l04(volatile uint8_t *bios)
125 if ((*bios & 0x80) == 0) { // it's busy
126 while ((*bios & 0x80) == 0) ;
131 // put another command to get out of status register mode
136 id1 = *(volatile uint8_t *)bios;
137 id2 = *(volatile uint8_t *)(bios + 0x01);
139 // this is needed to jam it out of "read id" mode
140 *(volatile uint8_t *)(bios + 0x5555) = 0xAA;
141 *(volatile uint8_t *)(bios + 0x2AAA) = 0x55;
142 *(volatile uint8_t *)(bios + 0x5555) = 0xF0;
146 int erase_lhf00l04_block(struct flashchip *flash, int offset)
148 volatile uint8_t *bios = flash->virtual_memory + offset;
149 volatile uint8_t *wrprotect = flash->virtual_registers + offset + 2;
152 // clear status register
154 printf("Erase at %p\n", bios);
155 status = wait_lhf00l04(flash->virtual_memory);
156 print_lhf00l04_status(status);
157 // clear write protect
158 printf("write protect is at %p\n", (wrprotect));
159 printf("write protect is 0x%x\n", *(wrprotect));
161 printf("write protect is 0x%x\n", *(wrprotect));
164 *(volatile uint8_t *)(bios) = 0x20;
165 *(volatile uint8_t *)(bios) = 0xd0;
167 // now let's see what the register is
168 status = wait_lhf00l04(flash->virtual_memory);
169 print_lhf00l04_status(status);
170 printf("DONE BLOCK 0x%x\n", offset);
173 int erase_lhf00l04(struct flashchip *flash)
176 unsigned int total_size = flash->total_size * 1024;
178 printf("total_size is %d; flash->page_size is %d\n",
179 total_size, flash->page_size);
180 for (i = 0; i < total_size; i += flash->page_size)
181 erase_lhf00l04_block(flash, i);
182 printf("DONE ERASE\n");
186 void write_page_lhf00l04(volatile uint8_t *bios, uint8_t *src,
187 volatile uint8_t *dst, int page_size)
191 for (i = 0; i < page_size; i++) {
192 /* transfer data from source to destination */
200 int write_lhf00l04(struct flashchip *flash, uint8_t *buf)
203 int total_size = flash->total_size * 1024;
204 int page_size = flash->page_size;
205 volatile uint8_t *bios = flash->virtual_memory;
207 erase_lhf00l04(flash);
209 printf("ERASE FAILED\n");
212 printf("Programming Page: ");
213 for (i = 0; i < total_size / page_size; i++) {
214 printf("%04d at address: 0x%08x", i, i * page_size);
215 write_page_lhf00l04(bios, buf + i * page_size,
216 bios + i * page_size, page_size);
217 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");
220 protect_lhf00l04(bios);