2 * am29f040.c: driver for programming AMD am29f040b models
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 * AMD Am29F040B data sheet
31 static __inline__ int erase_sector_29f040b(volatile uint8_t *bios,
32 unsigned long address)
34 *(bios + 0x555) = 0xAA;
35 *(bios + 0x2AA) = 0x55;
36 *(bios + 0x555) = 0x80;
37 *(bios + 0x555) = 0xAA;
38 *(bios + 0x2AA) = 0x55;
39 *(bios + address) = 0x30;
43 /* wait for Toggle bit ready */
44 toggle_ready_jedec(bios + address);
49 static __inline__ int write_sector_29f040b(volatile uint8_t *bios,
51 volatile uint8_t *dst,
52 unsigned int page_size)
56 for (i = 0; i < page_size; i++) {
57 if ((i & 0xfff) == 0xfff)
58 printf("0x%08lx", (unsigned long)dst -
61 *(bios + 0x555) = 0xAA;
62 *(bios + 0x2AA) = 0x55;
63 *(bios + 0x555) = 0xA0;
66 /* wait for Toggle bit ready */
67 toggle_ready_jedec(bios);
69 if ((i & 0xfff) == 0xfff)
70 printf("\b\b\b\b\b\b\b\b\b\b");
76 int probe_29f040b(struct flashchip *flash)
78 volatile uint8_t *bios = flash->virtual_memory;
81 *(bios + 0x555) = 0xAA;
82 *(bios + 0x2AA) = 0x55;
83 *(bios + 0x555) = 0x90;
92 printf_debug("%s: id1 0x%x, id2 0x%x\n", __FUNCTION__, id1, id2);
93 if (id1 == flash->manufacture_id && id2 == flash->model_id)
99 int erase_29f040b(struct flashchip *flash)
101 volatile uint8_t *bios = flash->virtual_memory;
103 *(bios + 0x555) = 0xAA;
104 *(bios + 0x2AA) = 0x55;
105 *(bios + 0x555) = 0x80;
106 *(bios + 0x555) = 0xAA;
107 *(bios + 0x2AA) = 0x55;
108 *(bios + 0x555) = 0x10;
111 toggle_ready_jedec(bios);
116 int write_29f040b(struct flashchip *flash, uint8_t *buf)
119 int total_size = flash->total_size * 1024;
120 int page_size = flash->page_size;
121 volatile uint8_t *bios = flash->virtual_memory;
123 printf("Programming page ");
124 for (i = 0; i < total_size / page_size; i++) {
125 /* erase the page before programming */
126 erase_sector_29f040b(bios, i * page_size);
128 /* write to the sector */
129 printf("%04d at address: ", i);
130 write_sector_29f040b(bios, buf + i * page_size,
131 bios + i * page_size, page_size);
132 printf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b");