blob: ce73be0e3410fb9e796fb4e12b60c1765daa0f82 [file] [log] [blame]
Ronald G. Minniche3dad012004-02-10 21:34:18 +00001/*
2 * pm49fl004.c: driver for Pm49FL004 flash models.
3 *
4 *
5 * Copyright 2004 Tyan 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 */
23
24#include <stdio.h>
25#include "flash.h"
26#include "jedec.h"
27#include "pm49fl004.h"
28
29#define AUTO_PGRM 0x10
30#define CHIP_ERASE 0x30
31#define RESET 0xFF
32#define READ_ID 0x90
33
Ronald G. Minniche3dad012004-02-10 21:34:18 +000034static __inline__ int erase_block_49fl004 ( volatile unsigned char * bios ,unsigned long address)
35{
36 volatile unsigned char *Temp;
37
38 Temp = bios + 0x5555; /* set up address to be C000:5555h */
39 *Temp = 0xAA; /* write data 0xAA to the address */
40 myusec_delay(10);
41 Temp = bios + 0x2AAA; /* set up address to be C000:2AAAh */
42 *Temp = 0x55; /* write data 0x55 to the address */
43 myusec_delay(10);
44 Temp = bios + 0x5555; /* set up address to be C000:5555h */
45 *Temp = 0x80; /* write data 0x80 to the address */
46 myusec_delay(10);
47 Temp = bios + 0x5555; /* set up address to be C000:5555h */
48 *Temp = 0xAA; /* write data 0xAA to the address */
49 myusec_delay(10);
50 Temp = bios + 0x2AAA; /* set up address to be C000:2AAAh */
51 *Temp = 0x55; /* write data 0x55 to the address */
52 myusec_delay(10);
53 Temp = bios + address; /* set up address to be C000:5555h */
54 *Temp = 0x50; /* write data 0x55 to the address */
55
56 /* wait for Toggle bit ready */
57 toggle_ready_jedec(bios);
58
59 return(0);
60}
61static __inline__ int write_block_49fl004(volatile char * bios,
62 unsigned char * src,
63 volatile unsigned char * dst,
64 unsigned int page_size)
65{
66 int i;
67 volatile char *Temp;
68
69 for (i = 0; i < page_size; i++) {
70 if (*dst != 0xff) {
71 printf("FATAL: dst %p not erased (val 0x%x\n", dst, *dst);
72 return(-1);
73 }
74 /* transfer data from source to destination */
75 if (*src == 0xFF) {
76 dst++, src++;
77 /* If the data is 0xFF, don't program it */
78 continue;
79 }
80 Temp = (bios + 0x5555);
81 *Temp = 0xAA;
82 Temp = bios + 0x2AAA;
83 *Temp = 0x55;
84 Temp = bios + 0x5555;
85 *Temp = 0xA0;
86 *dst = *src;
87 toggle_ready_jedec(bios);
88 if (*dst != *src)
89 printf("BAD! dst 0x%lx val 0x%x src 0x%x\n",
90 (unsigned long)dst, *dst, *src);
91 dst++, src++;
92 }
93
94 return(0);
95}
96
97int probe_49fl004 (struct flashchip * flash)
98{
99 volatile char * bios = flash->virt_addr;
100 unsigned char id1, id2;
101
102 *(volatile char *) (bios + 0x5555) = 0xAA;
103 myusec_delay(10);
104 *(volatile char *) (bios + 0x2AAA) = 0x55;
105 myusec_delay(10);
106 *(volatile char *) (bios + 0x5555) = 0x90;
107
108 myusec_delay(10);
109
110 id1 = *(volatile unsigned char *) bios;
111 id2 = *(volatile unsigned char *) (bios + 0x01);
112
113 *(volatile char *) (bios + 0x5555) = 0xAA;
114 *(volatile char *) (bios + 0x2AAA) = 0x55;
115 *(volatile char *) (bios + 0x5555) = 0xF0;
116
117 myusec_delay(10);
118
119 printf("%s: id1 0x%x, id2 0x%x\n", __FUNCTION__, id1, id2);
120
121 if (id1 == flash->manufacture_id && id2 == flash->model_id)
122 return 1;
123
124 return 0;
125}
126
127int erase_49fl004 (struct flashchip * flash)
128{
129 volatile unsigned char * bios = flash->virt_addr;
130 volatile unsigned char *Temp;
131
132 Temp = bios + 0x5555; /* set up address to be C000:5555h */
133 *Temp = 0xAA; /* write data 0xAA to the address */
134 myusec_delay(10);
135 Temp = bios + 0x2AAA; /* set up address to be C000:2AAAh */
136 *Temp = 0x55; /* write data 0x55 to the address */
137 myusec_delay(10);
138 Temp = bios + 0x5555; /* set up address to be C000:5555h */
139 *Temp = 0x80; /* write data 0x80 to the address */
140 myusec_delay(10);
141 Temp = bios + 0x5555; /* set up address to be C000:5555h */
142 *Temp = 0xAA; /* write data 0xAA to the address */
143 myusec_delay(10);
144 Temp = bios + 0x2AAA; /* set up address to be C000:2AAAh */
145 *Temp = 0x55; /* write data 0x55 to the address */
146 myusec_delay(10);
147 Temp = bios + 0x5555; /* set up address to be C000:5555h */
148 *Temp = 0x10; /* write data 0x10 to the address */
149
150
151 /* wait for Toggle bit ready */
152 toggle_ready_jedec(bios);
153
154 return(0);
155}
156
157int write_49fl004 (struct flashchip * flash, unsigned char * buf)
158{
159 int i;
160 int total_size = flash->total_size * 1024, page_size = flash->page_size;
161 volatile char * bios = flash->virt_addr;
162
Ronald G. Minniche3dad012004-02-10 21:34:18 +0000163 printf ("Programming Page: ");
164 for (i = 0; i < total_size/page_size; i++) {
165 /* erase the page before programming */
166 erase_block_49fl004(bios, i * page_size);
167
168 /* write to the sector */
169 printf ("%04d at address: 0x%08x", i, i * page_size);
170 write_block_49fl004(bios, buf + i * page_size, bios + i * page_size,
Ollie Lhof36ad4f2004-03-18 20:31:54 +0000171 page_size);
Ronald G. Minniche3dad012004-02-10 21:34:18 +0000172 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");
173 fflush(stdout);
174 }
175 printf("\n");
176
Ronald G. Minniche3dad012004-02-10 21:34:18 +0000177 return(0);
178}