2 * 82802ab.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
30 // I need that Berkeley bit-map printer
31 void print_82802ab_status(uint8_t status)
33 printf("%s", status & 0x80 ? "Ready:" : "Busy:");
34 printf("%s", status & 0x40 ? "BE SUSPEND:" : "BE RUN/FINISH:");
35 printf("%s", status & 0x20 ? "BE ERROR:" : "BE OK:");
36 printf("%s", status & 0x10 ? "PROG ERR:" : "PROG OK:");
37 printf("%s", status & 0x8 ? "VP ERR:" : "VPP OK:");
38 printf("%s", status & 0x4 ? "PROG SUSPEND:" : "PROG RUN/FINISH:");
39 printf("%s", status & 0x2 ? "WP|TBL#|WP#,ABORT:" : "UNLOCK:");
42 int probe_82802ab(struct flashchip *flash)
44 volatile uint8_t *bios = flash->virtual_memory;
48 *(volatile uint8_t *)(bios + 0x5555) = 0xAA;
49 *(volatile uint8_t *)(bios + 0x2AAA) = 0x55;
50 *(volatile uint8_t *)(bios + 0x5555) = 0x90;
58 id1 = *(volatile uint8_t *)bios;
59 id2 = *(volatile uint8_t *)(bios + 0x01);
62 *(volatile uint8_t *)(bios + 0x5555) = 0xAA;
63 *(volatile uint8_t *)(bios + 0x2AAA) = 0x55;
64 *(volatile uint8_t *)(bios + 0x5555) = 0xF0;
68 printf_debug("%s: id1 0x%x, id2 0x%x\n", __FUNCTION__, id1, id2);
70 if (id1 != flash->manufacture_id || id2 != flash->model_id)
73 map_flash_registers(flash);
78 uint8_t wait_82802ab(volatile uint8_t *bios)
85 if ((*bios & 0x80) == 0) { // it's busy
86 while ((*bios & 0x80) == 0) ;
91 // put another command to get out of status register mode
96 id1 = *(volatile uint8_t *)bios;
97 id2 = *(volatile uint8_t *)(bios + 0x01);
99 // this is needed to jam it out of "read id" mode
100 *(volatile uint8_t *)(bios + 0x5555) = 0xAA;
101 *(volatile uint8_t *)(bios + 0x2AAA) = 0x55;
102 *(volatile uint8_t *)(bios + 0x5555) = 0xF0;
106 int erase_82802ab_block(struct flashchip *flash, int offset)
108 volatile uint8_t *bios = flash->virtual_memory + offset;
109 volatile uint8_t *wrprotect = flash->virtual_registers + offset + 2;
112 // clear status register
114 //printf("Erase at %p\n", bios);
115 // clear write protect
116 //printf("write protect is at %p\n", (wrprotect));
117 //printf("write protect is 0x%x\n", *(wrprotect));
119 //printf("write protect is 0x%x\n", *(wrprotect));
122 *(volatile uint8_t *)(bios) = 0x20;
123 *(volatile uint8_t *)(bios) = 0xd0;
125 // now let's see what the register is
126 status = wait_82802ab(flash->virtual_memory);
127 //print_82802ab_status(status);
128 printf("DONE BLOCK 0x%x\n", offset);
131 int erase_82802ab(struct flashchip *flash)
134 unsigned int total_size = flash->total_size * 1024;
136 printf("total_size is %d; flash->page_size is %d\n",
137 total_size, flash->page_size);
138 for (i = 0; i < total_size; i += flash->page_size)
139 erase_82802ab_block(flash, i);
140 printf("DONE ERASE\n");
144 void write_page_82802ab(volatile uint8_t *bios, uint8_t *src,
145 volatile uint8_t *dst, int page_size)
149 for (i = 0; i < page_size; i++) {
150 /* transfer data from source to destination */
158 int write_82802ab(struct flashchip *flash, uint8_t *buf)
161 int total_size = flash->total_size * 1024;
162 int page_size = flash->page_size;
163 volatile uint8_t *bios = flash->virtual_memory;
165 erase_82802ab(flash);
167 printf("ERASE FAILED\n");
170 printf("Programming Page: ");
171 for (i = 0; i < total_size / page_size; i++) {
172 printf("%04d at address: 0x%08x", i, i * page_size);
173 write_page_82802ab(bios, buf + i * page_size,
174 bios + i * page_size, page_size);
175 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");