blob: 887a15b359bcd438f64f50c18934fbde2e55945a [file] [log] [blame]
Andrew Ipf0126ce2002-10-16 06:58:05 +00001/*
2 * w49f002u.c: driver for Winbond 49F002U flash models
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 * W49F002U data sheet
24 *
25 * $Id
26 */
27
28#include "flash.h"
29#include "jedec.h"
30
31int probe_49f002 (struct flashchip * flash)
32{
33 volatile char * bios = flash->virt_addr;
34 unsigned char id1, id2, id3;
35
36 *(bios + 0x5555) = 0xAA;
37 *(bios + 0x2AAA) = 0x55;
38 *(bios + 0x5555) = 0x90;
39
40 id1 = *(volatile unsigned char *) bios;
41 id2 = *(volatile unsigned char *) (bios + 0x01);
42
43 *bios = 0xF0;
44
45 myusec_delay(10);
46
47 printf(__FUNCTION__ "id1 %d, id2 %d\n", id1, id2);
48 if (id1 == flash->manufacture_id && id2 == flash->model_id)
49 return 1;
50
51 return 0;
52}
53
54int erase_49f002 (struct flashchip * flash)
55{
56 volatile char * bios = flash->virt_addr;
57
58 again:
59 *(bios + 0x5555) = 0xAA;
60 *(bios + 0x2AAA) = 0x55;
61 *(bios + 0x5555) = 0x80;
62 *(bios + 0x5555) = 0xAA;
63 *(bios + 0x2AAA) = 0x55;
64 *(bios + 0x5555) = 0x10;
65
66 myusec_delay(100);
67 toggle_ready_jedec(bios);
68
69 // while ((*bios & 0x40) != 0x40)
70 //;
71
72#if 0
73 toggle_ready_jedec(bios);
74 *(bios + 0x0ffff) = 0x30;
75 *(bios + 0x1ffff) = 0x30;
76 *(bios + 0x2ffff) = 0x30;
77 *(bios + 0x37fff) = 0x30;
78 *(bios + 0x39fff) = 0x30;
79 *(bios + 0x3bfff) = 0x30;
80#endif
81
82}
83
84int write_49f002 (struct flashchip * flash, char * buf)
85{
86 int i;
87 int total_size = flash->total_size * 1024, page_size = flash->page_size;
88 volatile char * bios = flash->virt_addr;
89 volatile char * dst = bios, * src = buf;
90
91 *bios = 0xF0;
92 myusec_delay(10);
93 erase_49f002(flash);
94 //*bios = 0xF0;
95#if 1
96 printf ("Programming Page: ");
97 for (i = 0; i < total_size; i++) {
98 /* write to the sector */
99 printf ("address: 0x%08lx", i);
100 *(bios + 0x5555) = 0xAA;
101 *(bios + 0x2AAA) = 0x55;
102 *(bios + 0x5555) = 0xA0;
103 *dst++ = *buf++;
104
105 /* wait for Toggle bit ready */
106 toggle_ready_jedec(dst);
107
108 printf ("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b");
109 }
110#endif
111 printf("\n");
112}