blob: b7c57eb256bcc974c637799dc41368dfaa98c1b5 [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
Ronald G. Minnicheaab50b2003-09-12 22:41:53 +000028#include <stdio.h>
Andrew Ipf0126ce2002-10-16 06:58:05 +000029#include "flash.h"
30#include "jedec.h"
Ronald G. Minnicheaab50b2003-09-12 22:41:53 +000031#include "w49f002u.h"
Andrew Ipf0126ce2002-10-16 06:58:05 +000032
33int probe_49f002 (struct flashchip * flash)
34{
35 volatile char * bios = flash->virt_addr;
Ronald G. Minnicheaab50b2003-09-12 22:41:53 +000036 unsigned char id1, id2;
Andrew Ipf0126ce2002-10-16 06:58:05 +000037
38 *(bios + 0x5555) = 0xAA;
39 *(bios + 0x2AAA) = 0x55;
40 *(bios + 0x5555) = 0x90;
41
42 id1 = *(volatile unsigned char *) bios;
43 id2 = *(volatile unsigned char *) (bios + 0x01);
44
45 *bios = 0xF0;
46
47 myusec_delay(10);
48
Ronald G. Minnichd4228fd2003-02-28 17:21:38 +000049 printf("%s: id1 0x%x, id2 0x%x\n", __FUNCTION__, id1, id2);
50
Andrew Ipf0126ce2002-10-16 06:58:05 +000051 if (id1 == flash->manufacture_id && id2 == flash->model_id)
52 return 1;
53
54 return 0;
55}
56
57int erase_49f002 (struct flashchip * flash)
58{
59 volatile char * bios = flash->virt_addr;
60
Andrew Ipf0126ce2002-10-16 06:58:05 +000061 *(bios + 0x5555) = 0xAA;
62 *(bios + 0x2AAA) = 0x55;
63 *(bios + 0x5555) = 0x80;
64 *(bios + 0x5555) = 0xAA;
65 *(bios + 0x2AAA) = 0x55;
66 *(bios + 0x5555) = 0x10;
67
68 myusec_delay(100);
69 toggle_ready_jedec(bios);
70
71 // while ((*bios & 0x40) != 0x40)
72 //;
73
74#if 0
75 toggle_ready_jedec(bios);
76 *(bios + 0x0ffff) = 0x30;
77 *(bios + 0x1ffff) = 0x30;
78 *(bios + 0x2ffff) = 0x30;
79 *(bios + 0x37fff) = 0x30;
80 *(bios + 0x39fff) = 0x30;
81 *(bios + 0x3bfff) = 0x30;
82#endif
83
Ronald G. Minnicheaab50b2003-09-12 22:41:53 +000084 return(0);
Andrew Ipf0126ce2002-10-16 06:58:05 +000085}
86
Ronald G. Minnicheaab50b2003-09-12 22:41:53 +000087int write_49f002 (struct flashchip * flash, unsigned char * buf)
Andrew Ipf0126ce2002-10-16 06:58:05 +000088{
89 int i;
Ronald G. Minnicheaab50b2003-09-12 22:41:53 +000090 int total_size = flash->total_size * 1024;
Andrew Ipf0126ce2002-10-16 06:58:05 +000091 volatile char * bios = flash->virt_addr;
Ronald G. Minnicheaab50b2003-09-12 22:41:53 +000092 volatile char * dst = bios;
Andrew Ipf0126ce2002-10-16 06:58:05 +000093
94 *bios = 0xF0;
95 myusec_delay(10);
96 erase_49f002(flash);
97 //*bios = 0xF0;
98#if 1
99 printf ("Programming Page: ");
100 for (i = 0; i < total_size; i++) {
101 /* write to the sector */
Ronald G. Minnichceec4202003-07-25 04:37:41 +0000102 if ((i & 0xfff) == 0)
Ronald G. Minnicheaab50b2003-09-12 22:41:53 +0000103 printf ("address: 0x%08lx", (unsigned long)i);
Andrew Ipf0126ce2002-10-16 06:58:05 +0000104 *(bios + 0x5555) = 0xAA;
105 *(bios + 0x2AAA) = 0x55;
106 *(bios + 0x5555) = 0xA0;
107 *dst++ = *buf++;
108
109 /* wait for Toggle bit ready */
110 toggle_ready_jedec(dst);
111
Ronald G. Minnichceec4202003-07-25 04:37:41 +0000112 if ((i & 0xfff) == 0)
113 printf ("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b");
Andrew Ipf0126ce2002-10-16 06:58:05 +0000114 }
115#endif
116 printf("\n");
Ronald G. Minnicheaab50b2003-09-12 22:41:53 +0000117
118 return(0);
Andrew Ipf0126ce2002-10-16 06:58:05 +0000119}