blob: f409fec59138376b29b172be2c7334a71fa75d7b [file] [log] [blame]
Ronald G. Minnichb1934902002-06-11 19:15:55 +00001/*
2 * m29f400bt.c: driver for programming JEDEC standard flash parts
3 *
4 *
5 * Copyright 2000 Silicon Integrated System Corporation
6 *
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.
11 *
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.
16 *
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.
20 *
21 *
22 * Reference:
23 *
Ronald G. Minnichb1934902002-06-11 19:15:55 +000024 */
25
26#include "flash.h"
Ronald G. Minnichb1934902002-06-11 19:15:55 +000027
Uwe Hermann51582f22007-08-23 10:20:40 +000028void protect_m29f400bt(volatile uint8_t *bios)
29{
30 *(volatile uint8_t *)(bios + 0xAAA) = 0xAA;
31 *(volatile uint8_t *)(bios + 0x555) = 0x55;
32 *(volatile uint8_t *)(bios + 0xAAA) = 0xA0;
33
34 usleep(200);
35}
36
37void write_page_m29f400bt(volatile uint8_t *bios, uint8_t *src,
38 volatile uint8_t *dst, int page_size)
39{
40 int i;
41
42 for (i = 0; i < page_size; i++) {
43 *(volatile uint8_t *)(bios + 0xAAA) = 0xAA;
44 *(volatile uint8_t *)(bios + 0x555) = 0x55;
45 *(volatile uint8_t *)(bios + 0xAAA) = 0xA0;
46
47 /* transfer data from source to destination */
48 *dst = *src;
49 //*(volatile char *) (bios) = 0xF0;
50 //usleep(5);
Uwe Hermannfd374142007-08-23 15:20:38 +000051 toggle_ready_jedec(dst);
Uwe Hermann51582f22007-08-23 10:20:40 +000052 printf
53 ("Value in the flash at address %p = %#x, want %#x\n",
54 (uint8_t *) (dst - bios), *dst, *src);
55 dst++;
56 src++;
57 }
58}
59
Ollie Lho761bf1b2004-03-20 16:46:10 +000060int probe_m29f400bt(struct flashchip *flash)
Ronald G. Minnichb1934902002-06-11 19:15:55 +000061{
Stefan Reinauerce532972007-05-23 17:20:56 +000062 volatile uint8_t *bios = flash->virtual_memory;
Ollie Lho184a4042005-11-26 21:55:36 +000063 uint8_t id1, id2;
Ronald G. Minnichb1934902002-06-11 19:15:55 +000064
Uwe Hermanna7e05482007-05-09 10:17:44 +000065 *(volatile uint8_t *)(bios + 0xAAA) = 0xAA;
66 *(volatile uint8_t *)(bios + 0x555) = 0x55;
67 *(volatile uint8_t *)(bios + 0xAAA) = 0x90;
Ronald G. Minnichb1934902002-06-11 19:15:55 +000068
69 myusec_delay(10);
70
Uwe Hermanna7e05482007-05-09 10:17:44 +000071 id1 = *(volatile uint8_t *)bios;
72 id2 = *(volatile uint8_t *)(bios + 0x02);
Ronald G. Minnichb1934902002-06-11 19:15:55 +000073
Uwe Hermanna7e05482007-05-09 10:17:44 +000074 *(volatile uint8_t *)(bios + 0xAAA) = 0xAA;
75 *(volatile uint8_t *)(bios + 0x555) = 0x55;
76 *(volatile uint8_t *)(bios + 0xAAA) = 0xF0;
Ronald G. Minnichb1934902002-06-11 19:15:55 +000077
78 myusec_delay(10);
Ronald G. Minnichd4228fd2003-02-28 17:21:38 +000079
Ollie Lho184a4042005-11-26 21:55:36 +000080 printf_debug("%s: id1 0x%x, id2 0x%x\n", __FUNCTION__, id1, id2);
Ronald G. Minnichd4228fd2003-02-28 17:21:38 +000081
Ronald G. Minnichb1934902002-06-11 19:15:55 +000082 if (id1 == flash->manufacture_id && id2 == flash->model_id)
83 return 1;
84
85 return 0;
86}
87
Ollie Lho761bf1b2004-03-20 16:46:10 +000088int erase_m29f400bt(struct flashchip *flash)
Ronald G. Minnichb1934902002-06-11 19:15:55 +000089{
Stefan Reinauerce532972007-05-23 17:20:56 +000090 volatile uint8_t *bios = flash->virtual_memory;
Ronald G. Minnichb1934902002-06-11 19:15:55 +000091
Uwe Hermanna7e05482007-05-09 10:17:44 +000092 *(volatile uint8_t *)(bios + 0xAAA) = 0xAA;
93 *(volatile uint8_t *)(bios + 0x555) = 0x55;
94 *(volatile uint8_t *)(bios + 0xAAA) = 0x80;
Ronald G. Minnichb1934902002-06-11 19:15:55 +000095
Uwe Hermanna7e05482007-05-09 10:17:44 +000096 *(volatile uint8_t *)(bios + 0xAAA) = 0xAA;
97 *(volatile uint8_t *)(bios + 0x555) = 0x55;
98 *(volatile uint8_t *)(bios + 0xAAA) = 0x10;
Ronald G. Minnichb1934902002-06-11 19:15:55 +000099
100 myusec_delay(10);
Uwe Hermannfd374142007-08-23 15:20:38 +0000101 toggle_ready_jedec(bios);
Ronald G. Minnicheaab50b2003-09-12 22:41:53 +0000102
Uwe Hermannffec5f32007-08-23 16:08:21 +0000103 return 0;
Ronald G. Minnichb1934902002-06-11 19:15:55 +0000104}
105
Ollie Lho184a4042005-11-26 21:55:36 +0000106int block_erase_m29f400bt(volatile uint8_t *bios, volatile uint8_t *dst)
Ronald G. Minnichb1934902002-06-11 19:15:55 +0000107{
108
Uwe Hermanna7e05482007-05-09 10:17:44 +0000109 *(volatile uint8_t *)(bios + 0xAAA) = 0xAA;
110 *(volatile uint8_t *)(bios + 0x555) = 0x55;
111 *(volatile uint8_t *)(bios + 0xAAA) = 0x80;
Ronald G. Minnichb1934902002-06-11 19:15:55 +0000112
Uwe Hermanna7e05482007-05-09 10:17:44 +0000113 *(volatile uint8_t *)(bios + 0xAAA) = 0xAA;
114 *(volatile uint8_t *)(bios + 0x555) = 0x55;
Ollie Lho184a4042005-11-26 21:55:36 +0000115 //*(volatile uint8_t *) (bios + 0xAAA) = 0x10;
Ollie Lho761bf1b2004-03-20 16:46:10 +0000116 *dst = 0x30;
Ronald G. Minnichb1934902002-06-11 19:15:55 +0000117
118 myusec_delay(10);
Uwe Hermannfd374142007-08-23 15:20:38 +0000119 toggle_ready_jedec(bios);
Ronald G. Minnicheaab50b2003-09-12 22:41:53 +0000120
Uwe Hermannffec5f32007-08-23 16:08:21 +0000121 return 0;
Ronald G. Minnichb1934902002-06-11 19:15:55 +0000122}
123
Ollie Lho184a4042005-11-26 21:55:36 +0000124int write_m29f400bt(struct flashchip *flash, uint8_t *buf)
Ronald G. Minnichb1934902002-06-11 19:15:55 +0000125{
126 int i;
Uwe Hermanna7e05482007-05-09 10:17:44 +0000127 int total_size = flash->total_size * 1024;
128 int page_size = flash->page_size;
Stefan Reinauerce532972007-05-23 17:20:56 +0000129 volatile uint8_t *bios = flash->virtual_memory;
Ronald G. Minnichb1934902002-06-11 19:15:55 +0000130
131 //erase_m29f400bt (flash);
Ollie Lho761bf1b2004-03-20 16:46:10 +0000132 printf("Programming Page:\n ");
Ronald G. Minnichb1934902002-06-11 19:15:55 +0000133 /*********************************
134 *Pages for M29F400BT:
135 * 16 0x7c000 0x7ffff TOP
136 * 8 0x7a000 0x7bfff
137 * 8 0x78000 0x79fff
138 * 32 0x70000 0x77fff
139 * 64 0x60000 0x6ffff
140 * 64 0x50000 0x5ffff
141 * 64 0x40000 0x4ffff
142 *---------------------------------
143 * 64 0x30000 0x3ffff
144 * 64 0x20000 0x2ffff
145 * 64 0x10000 0x1ffff
146 * 64 0x00000 0x0ffff BOTTOM
147 *********************************/
Ollie Lho761bf1b2004-03-20 16:46:10 +0000148 printf("total_size/page_size = %d\n", total_size / page_size);
149 for (i = 0; i < (total_size / page_size) - 1; i++) {
Ronald G. Minnichb1934902002-06-11 19:15:55 +0000150 printf("%04d at address: 0x%08x\n", i, i * page_size);
151 block_erase_m29f400bt(bios, bios + i * page_size);
Ollie Lho761bf1b2004-03-20 16:46:10 +0000152 write_page_m29f400bt(bios, buf + i * page_size,
153 bios + i * page_size, page_size);
Uwe Hermanna7e05482007-05-09 10:17:44 +0000154 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");
Ronald G. Minnichb1934902002-06-11 19:15:55 +0000155 }
156
Ollie Lho761bf1b2004-03-20 16:46:10 +0000157 printf("%04d at address: 0x%08x\n", 7, 0x70000);
158 block_erase_m29f400bt(bios, bios + 0x70000);
Uwe Hermanna7e05482007-05-09 10:17:44 +0000159 write_page_m29f400bt(bios, buf + 0x70000, bios + 0x70000, 32 * 1024);
Ollie Lho761bf1b2004-03-20 16:46:10 +0000160
161 printf("%04d at address: 0x%08x\n", 8, 0x78000);
162 block_erase_m29f400bt(bios, bios + 0x78000);
Uwe Hermanna7e05482007-05-09 10:17:44 +0000163 write_page_m29f400bt(bios, buf + 0x78000, bios + 0x78000, 8 * 1024);
Ollie Lho761bf1b2004-03-20 16:46:10 +0000164
165 printf("%04d at address: 0x%08x\n", 9, 0x7a000);
166 block_erase_m29f400bt(bios, bios + 0x7a000);
Uwe Hermanna7e05482007-05-09 10:17:44 +0000167 write_page_m29f400bt(bios, buf + 0x7a000, bios + 0x7a000, 8 * 1024);
Ollie Lho761bf1b2004-03-20 16:46:10 +0000168
169 printf("%04d at address: 0x%08x\n", 10, 0x7c000);
170 block_erase_m29f400bt(bios, bios + 0x7c000);
Uwe Hermanna7e05482007-05-09 10:17:44 +0000171 write_page_m29f400bt(bios, buf + 0x7c000, bios + 0x7c000, 16 * 1024);
Ollie Lho761bf1b2004-03-20 16:46:10 +0000172
Ronald G. Minnichb1934902002-06-11 19:15:55 +0000173 printf("\n");
174 //protect_m29f400bt (bios);
Ronald G. Minnicheaab50b2003-09-12 22:41:53 +0000175
Uwe Hermannffec5f32007-08-23 16:08:21 +0000176 return 0;
Ronald G. Minnichb1934902002-06-11 19:15:55 +0000177}
178
Ollie Lho184a4042005-11-26 21:55:36 +0000179int write_linuxbios_m29f400bt(struct flashchip *flash, uint8_t *buf)
Ronald G. Minnichb1934902002-06-11 19:15:55 +0000180{
Stefan Reinauerce532972007-05-23 17:20:56 +0000181 volatile uint8_t *bios = flash->virtual_memory;
Ronald G. Minnichb1934902002-06-11 19:15:55 +0000182
Ollie Lho761bf1b2004-03-20 16:46:10 +0000183 printf("Programming Page:\n ");
Ronald G. Minnichb1934902002-06-11 19:15:55 +0000184 /*********************************
185 *Pages for M29F400BT:
186 * 16 0x7c000 0x7ffff TOP
187 * 8 0x7a000 0x7bfff
188 * 8 0x78000 0x79fff
189 * 32 0x70000 0x77fff
190 * 64 0x60000 0x6ffff
191 * 64 0x50000 0x5ffff
192 * 64 0x40000 0x4ffff
193 *---------------------------------
194 * 64 0x30000 0x3ffff
195 * 64 0x20000 0x2ffff
196 * 64 0x10000 0x1ffff
197 * 64 0x00000 0x0ffff BOTTOM
198 *********************************/
Ollie Lho761bf1b2004-03-20 16:46:10 +0000199 printf("%04d at address: 0x%08x\n", 7, 0x00000);
200 block_erase_m29f400bt(bios, bios + 0x00000);
Uwe Hermanna7e05482007-05-09 10:17:44 +0000201 write_page_m29f400bt(bios, buf + 0x00000, bios + 0x00000, 64 * 1024);
Ollie Lho761bf1b2004-03-20 16:46:10 +0000202
203 printf("%04d at address: 0x%08x\n", 7, 0x10000);
204 block_erase_m29f400bt(bios, bios + 0x10000);
Uwe Hermanna7e05482007-05-09 10:17:44 +0000205 write_page_m29f400bt(bios, buf + 0x10000, bios + 0x10000, 64 * 1024);
Ollie Lho761bf1b2004-03-20 16:46:10 +0000206
207 printf("%04d at address: 0x%08x\n", 7, 0x20000);
208 block_erase_m29f400bt(bios, bios + 0x20000);
Uwe Hermanna7e05482007-05-09 10:17:44 +0000209 write_page_m29f400bt(bios, buf + 0x20000, bios + 0x20000, 64 * 1024);
Ollie Lho761bf1b2004-03-20 16:46:10 +0000210
211 printf("%04d at address: 0x%08x\n", 7, 0x30000);
212 block_erase_m29f400bt(bios, bios + 0x30000);
Uwe Hermanna7e05482007-05-09 10:17:44 +0000213 write_page_m29f400bt(bios, buf + 0x30000, bios + 0x30000, 64 * 1024);
Ollie Lho761bf1b2004-03-20 16:46:10 +0000214
Ronald G. Minnichb1934902002-06-11 19:15:55 +0000215 printf("\n");
216 //protect_m29f400bt (bios);
Ronald G. Minnicheaab50b2003-09-12 22:41:53 +0000217
Uwe Hermannffec5f32007-08-23 16:08:21 +0000218 return 0;
Ronald G. Minnichb1934902002-06-11 19:15:55 +0000219}