blob: 3e4e877e88e62ef2c43487a29fce48ddb91a51b2 [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}
Ollie Lho856943d2004-03-18 20:35:33 +000061
Ronald G. Minniche3dad012004-02-10 21:34:18 +000062static __inline__ int write_block_49fl004(volatile char * bios,
Ollie Lho856943d2004-03-18 20:35:33 +000063 unsigned char * src,
64 volatile unsigned char * dst,
65 unsigned int page_size)
Ronald G. Minniche3dad012004-02-10 21:34:18 +000066{
67 int i;
68 volatile char *Temp;
69
70 for (i = 0; i < page_size; i++) {
71 if (*dst != 0xff) {
72 printf("FATAL: dst %p not erased (val 0x%x\n", dst, *dst);
73 return(-1);
74 }
75 /* transfer data from source to destination */
76 if (*src == 0xFF) {
77 dst++, src++;
78 /* If the data is 0xFF, don't program it */
79 continue;
80 }
81 Temp = (bios + 0x5555);
82 *Temp = 0xAA;
83 Temp = bios + 0x2AAA;
84 *Temp = 0x55;
85 Temp = bios + 0x5555;
86 *Temp = 0xA0;
87 *dst = *src;
88 toggle_ready_jedec(bios);
89 if (*dst != *src)
90 printf("BAD! dst 0x%lx val 0x%x src 0x%x\n",
91 (unsigned long)dst, *dst, *src);
92 dst++, src++;
93 }
94
95 return(0);
96}
97
98int probe_49fl004 (struct flashchip * flash)
99{
100 volatile char * bios = flash->virt_addr;
101 unsigned char id1, id2;
102
103 *(volatile char *) (bios + 0x5555) = 0xAA;
104 myusec_delay(10);
105 *(volatile char *) (bios + 0x2AAA) = 0x55;
106 myusec_delay(10);
107 *(volatile char *) (bios + 0x5555) = 0x90;
108
109 myusec_delay(10);
110
111 id1 = *(volatile unsigned char *) bios;
112 id2 = *(volatile unsigned char *) (bios + 0x01);
113
114 *(volatile char *) (bios + 0x5555) = 0xAA;
115 *(volatile char *) (bios + 0x2AAA) = 0x55;
116 *(volatile char *) (bios + 0x5555) = 0xF0;
117
118 myusec_delay(10);
119
120 printf("%s: id1 0x%x, id2 0x%x\n", __FUNCTION__, id1, id2);
121
122 if (id1 == flash->manufacture_id && id2 == flash->model_id)
123 return 1;
124
125 return 0;
126}
127
128int erase_49fl004 (struct flashchip * flash)
129{
130 volatile unsigned char * bios = flash->virt_addr;
131 volatile unsigned char *Temp;
132
133 Temp = bios + 0x5555; /* set up address to be C000:5555h */
134 *Temp = 0xAA; /* write data 0xAA to the address */
135 myusec_delay(10);
136 Temp = bios + 0x2AAA; /* set up address to be C000:2AAAh */
137 *Temp = 0x55; /* write data 0x55 to the address */
138 myusec_delay(10);
139 Temp = bios + 0x5555; /* set up address to be C000:5555h */
140 *Temp = 0x80; /* write data 0x80 to the address */
141 myusec_delay(10);
142 Temp = bios + 0x5555; /* set up address to be C000:5555h */
143 *Temp = 0xAA; /* write data 0xAA to the address */
144 myusec_delay(10);
145 Temp = bios + 0x2AAA; /* set up address to be C000:2AAAh */
146 *Temp = 0x55; /* write data 0x55 to the address */
147 myusec_delay(10);
148 Temp = bios + 0x5555; /* set up address to be C000:5555h */
149 *Temp = 0x10; /* write data 0x10 to the address */
150
151
152 /* wait for Toggle bit ready */
153 toggle_ready_jedec(bios);
154
155 return(0);
156}
157
158int write_49fl004 (struct flashchip * flash, unsigned char * buf)
159{
160 int i;
161 int total_size = flash->total_size * 1024, page_size = flash->page_size;
162 volatile char * bios = flash->virt_addr;
163
Ronald G. Minniche3dad012004-02-10 21:34:18 +0000164 printf ("Programming Page: ");
165 for (i = 0; i < total_size/page_size; i++) {
166 /* erase the page before programming */
167 erase_block_49fl004(bios, i * page_size);
168
169 /* write to the sector */
170 printf ("%04d at address: 0x%08x", i, i * page_size);
171 write_block_49fl004(bios, buf + i * page_size, bios + i * page_size,
Ollie Lhof36ad4f2004-03-18 20:31:54 +0000172 page_size);
Ronald G. Minniche3dad012004-02-10 21:34:18 +0000173 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");
174 fflush(stdout);
175 }
176 printf("\n");
177
Ronald G. Minniche3dad012004-02-10 21:34:18 +0000178 return(0);
179}