blob: 7b7f1e119a9478610fd84445282027412d76ccb2 [file] [log] [blame]
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +00001/*
2 * mx29f002.c: driver for MXIC MX29F002 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 * MX29F002/002N data sheet
24 *
25 * $Id$
26 */
27
28#include "flash.h"
29#include "jedec.h"
30
31int probe_29f002 (struct flashchip * flash)
32{
Ronald G. Minnichef5779d2002-01-29 20:18:02 +000033 volatile char * bios = flash->virt_addr;
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000034 unsigned char id1, id2, id3;
35
36 *(bios + 0x5555) = 0xAA;
37 *(bios + 0x2AAA) = 0x55;
38 *(bios + 0x5555) = 0x90;
39
Ronald G. Minnichef5779d2002-01-29 20:18:02 +000040 id1 = *(volatile unsigned char *) bios;
41 id2 = *(volatile unsigned char *) (bios + 0x01);
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000042
43 *bios = 0xF0;
44
Ronald G. Minnichef5779d2002-01-29 20:18:02 +000045 myusec_delay(10);
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000046
Ronald G. Minnichef5779d2002-01-29 20:18:02 +000047 printf(__FUNCTION__ "id1 %d, id2 %d\n", id1, id2);
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000048 if (id1 == flash->manufacture_id && id2 == flash->model_id)
49 return 1;
50
51 return 0;
52}
53
54int erase_29f002 (struct flashchip * flash)
55{
Ronald G. Minnichef5779d2002-01-29 20:18:02 +000056 volatile char * bios = flash->virt_addr;
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000057
58 again:
59 *(bios + 0x555) = 0xF0;
60 *(bios + 0x555) = 0xAA;
61 *(bios + 0x2AA) = 0x55;
62 *(bios + 0x555) = 0x80;
63 *(bios + 0x555) = 0xAA;
64 *(bios + 0x2AA) = 0x55;
65 *(bios + 0x555) = 0x10;
66
Ronald G. Minnichef5779d2002-01-29 20:18:02 +000067 myusec_delay(100);
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000068 toggle_ready_jedec(bios);
69
70 // while ((*bios & 0x40) != 0x40)
71 //;
72
73#if 0
74 toggle_ready_jedec(bios);
75 *(bios + 0x0ffff) = 0x30;
76 *(bios + 0x1ffff) = 0x30;
77 *(bios + 0x2ffff) = 0x30;
78 *(bios + 0x37fff) = 0x30;
79 *(bios + 0x39fff) = 0x30;
80 *(bios + 0x3bfff) = 0x30;
81#endif
82
83}
84
85int write_29f002 (struct flashchip * flash, char * buf)
86{
87 int i;
88 int total_size = flash->total_size * 1024, page_size = flash->page_size;
Ronald G. Minnichef5779d2002-01-29 20:18:02 +000089 volatile char * bios = flash->virt_addr;
90 volatile char * dst = bios, * src = buf;
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000091
92 *bios = 0xF0;
Ronald G. Minnichef5779d2002-01-29 20:18:02 +000093 myusec_delay(10);
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000094 erase_29f002(flash);
95 //*bios = 0xF0;
96#if 1
97 printf ("Programming Page: ");
98 for (i = 0; i < total_size; i++) {
99 /* write to the sector */
100 printf ("address: 0x%08lx", i);
101 *(bios + 0x5555) = 0xAA;
102 *(bios + 0x2AAA) = 0x55;
103 *(bios + 0x5555) = 0xA0;
104 *dst++ = 0x33;
105
106 /* wait for Toggle bit ready */
107 toggle_ready_jedec(dst);
108
109 printf ("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b");
110 }
111#endif
112 printf("\n");
113}