2 * This file is part of the flashrom project.
4 * Copyright (C) 2000 Silicon Integrated System Corporation
5 * Copyright (C) 2005 coresystems GmbH <stepan@openbios.org>
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 #define AUTO_PG_ERASE1 0x20
27 #define AUTO_PG_ERASE2 0xD0
28 #define AUTO_PGRM 0x10
29 #define CHIP_ERASE 0x30
33 static __inline__ void protect_28sf040(volatile uint8_t *bios)
35 /* ask compiler not to optimize this */
38 tmp = *(volatile uint8_t *)(bios + 0x1823);
39 tmp = *(volatile uint8_t *)(bios + 0x1820);
40 tmp = *(volatile uint8_t *)(bios + 0x1822);
41 tmp = *(volatile uint8_t *)(bios + 0x0418);
42 tmp = *(volatile uint8_t *)(bios + 0x041B);
43 tmp = *(volatile uint8_t *)(bios + 0x0419);
44 tmp = *(volatile uint8_t *)(bios + 0x040A);
47 static __inline__ void unprotect_28sf040(volatile uint8_t *bios)
49 /* ask compiler not to optimize this */
52 tmp = *(volatile uint8_t *)(bios + 0x1823);
53 tmp = *(volatile uint8_t *)(bios + 0x1820);
54 tmp = *(volatile uint8_t *)(bios + 0x1822);
55 tmp = *(volatile uint8_t *)(bios + 0x0418);
56 tmp = *(volatile uint8_t *)(bios + 0x041B);
57 tmp = *(volatile uint8_t *)(bios + 0x0419);
58 tmp = *(volatile uint8_t *)(bios + 0x041A);
61 static __inline__ int erase_sector_28sf040(volatile uint8_t *bios,
62 unsigned long address)
64 *bios = AUTO_PG_ERASE1;
65 *(bios + address) = AUTO_PG_ERASE2;
67 /* wait for Toggle bit ready */
68 toggle_ready_jedec(bios);
73 static __inline__ int write_sector_28sf040(volatile uint8_t *bios,
75 volatile uint8_t *dst,
76 unsigned int page_size)
80 for (i = 0; i < page_size; i++) {
81 /* transfer data from source to destination */
84 /* If the data is 0xFF, don't program it */
87 /*issue AUTO PROGRAM command */
91 /* wait for Toggle bit ready */
92 toggle_ready_jedec(bios);
98 int probe_28sf040(struct flashchip *flash)
100 volatile uint8_t *bios = flash->virtual_memory;
108 id1 = *(volatile uint8_t *)bios;
110 id2 = *(volatile uint8_t *)(bios + 0x01);
115 printf_debug("%s: id1 0x%x, id2 0x%x\n", __FUNCTION__, id1, id2);
116 if (id1 == flash->manufacture_id && id2 == flash->model_id)
122 int erase_28sf040(struct flashchip *flash)
124 volatile uint8_t *bios = flash->virtual_memory;
126 unprotect_28sf040(bios);
129 protect_28sf040(bios);
132 toggle_ready_jedec(bios);
137 int write_28sf040(struct flashchip *flash, uint8_t *buf)
140 int total_size = flash->total_size * 1024;
141 int page_size = flash->page_size;
142 volatile uint8_t *bios = flash->virtual_memory;
144 unprotect_28sf040(bios);
146 printf("Programming page: ");
147 for (i = 0; i < total_size / page_size; i++) {
148 /* erase the page before programming */
149 erase_sector_28sf040(bios, i * page_size);
151 /* write to the sector */
152 printf("%04d at address: 0x%08x", i, i * page_size);
153 write_sector_28sf040(bios, buf + i * page_size,
154 bios + i * page_size, page_size);
155 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");
159 protect_28sf040(bios);