blob: bfa4ecae9b409ae605ba68e5c9ed4b3a08d7d37b [file] [log] [blame]
Ronald G. Minnicheaab50b2003-09-12 22:41:53 +00001/*
2 * msys_doc.c: driver for programming m-systems doc devices
3 *
4 *
5 * Copyright 2003 Niki W. Waibel <niki.waibel@gmx.net>
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 <unistd.h>
26#include "flash.h"
27#include "msys_doc.h"
28
29
30
31
32
33static int doc_wait(volatile char *bios, int timeout);
34static unsigned char doc_read_chipid(volatile char *bios);
35static unsigned char doc_read_docstatus(volatile char *bios);
36static unsigned char doc_read_cdsncontrol(volatile char *bios);
37static void doc_write_cdsncontrol(volatile char *bios, unsigned char data);
38
39
40
41
42
43int
44probe_md2802(struct flashchip * flash)
45{
46 volatile char *bios = flash->virt_addr;
47 unsigned char chipid;
48#ifndef MSYSTEMS_DOC_NO_55AA_CHECKING
49 unsigned char id_0x55, id_0xAA;
50#endif /* !MSYSTEMS_DOC_NO_55AA_CHECKING */
51 int i, toggle_a, toggle_b;
52
53 printf("%s:\n", __FUNCTION__);
54 printf("%s: *******************************\n", __FUNCTION__);
55 printf("%s: * THIS IS A PRE ALPHA VERSION *\n", __FUNCTION__);
56 printf("%s: * IN THE DEVELOPEMENT *********\n", __FUNCTION__);
57 printf("%s: * PROCESS RIGHT NOW. **********\n", __FUNCTION__);
58 printf("%s: *******************************\n", __FUNCTION__);
59 printf("%s: * IF YOU ARE NOT A DEVELOPER **\n", __FUNCTION__);
60 printf("%s: * THEN DO NOT TRY TO READ OR **\n", __FUNCTION__);
61 printf("%s: * WRITE TO THIS DEVICE ********\n", __FUNCTION__);
62 printf("%s: *******************************\n", __FUNCTION__);
63 printf("%s:\n", __FUNCTION__);
64
65 printf("%s: switching off reset mode ...\n", __FUNCTION__);
66 doc_write(0x85, bios, DOCControl);
67 doc_write(0x85, bios, DOCControl);
68 doc_read_4nop(bios);
69 if(doc_wait(bios, 5000))
70 return(-1);
71 printf("%s: switching off reset mode ... done\n", __FUNCTION__);
72 printf("%s:\n", __FUNCTION__);
73
74 printf("%s: switching off write protection ...\n", __FUNCTION__);
75 doc_write_cdsncontrol(bios, doc_read_cdsncontrol(bios)&(~0x08));
76 printf("%s: switching off write protection ... done\n", __FUNCTION__);
77 printf("%s:\n", __FUNCTION__);
78
79
80 chipid = doc_read_chipid(bios);
81#ifndef MSYSTEMS_DOC_NO_55AA_CHECKING
82 id_0x55 = doc_read(bios, IPL_0x0000);
83 id_0xAA = doc_read(bios, IPL_0x0001);
84#endif /* !MSYSTEMS_DOC_NO_55AA_CHECKING */
85 printf("%s: IPL_0x0000: 0x%02x\n", __FUNCTION__, id_0x55);
86 printf("%s: IPL_0x0001: 0x%02x\n", __FUNCTION__, id_0xAA);
87 printf("%s: IPL_0x0002: 0x%02x\n", __FUNCTION__,
88 doc_read(bios, IPL_0x0002));
89 printf("%s: IPL_0x0003: 0x%02x\n", __FUNCTION__,
90 doc_read(bios, IPL_0x0003));
91 printf("%s:\n", __FUNCTION__);
92 printf("%s: ChipID: 0x%02x\n", __FUNCTION__, chipid);
93 printf("%s: DOCStatus: 0x%02x\n", __FUNCTION__,
94 doc_read_docstatus(bios));
95 printf("%s: FloorSelect: 0x%02x\n", __FUNCTION__,
96 doc_read(bios, FloorSelect));
97 printf("%s: CDSNControl: 0x%02x\n", __FUNCTION__,
98 doc_read_cdsncontrol(bios));
99 printf("%s: CDSNDeviceSelect: 0x%02x\n", __FUNCTION__,
100 doc_read(bios, CDSNDeviceSelect));
101 printf("%s: ECCConfiguration: 0x%02x\n", __FUNCTION__,
102 doc_read(bios, ECCConfiguration));
103 printf("%s: CDSNSlowIO: 0x%02x\n", __FUNCTION__,
104 doc_read(bios, CDSNSlowIO));
105 printf("%s: ECCSyndrome0: 0x%02x\n", __FUNCTION__,
106 doc_read(bios, ECCSyndrome0));
107 printf("%s: ECCSyndrome1: 0x%02x\n", __FUNCTION__,
108 doc_read(bios, ECCSyndrome1));
109 printf("%s: ECCSyndrome2: 0x%02x\n", __FUNCTION__,
110 doc_read(bios, ECCSyndrome2));
111 printf("%s: ECCSyndrome3: 0x%02x\n", __FUNCTION__,
112 doc_read(bios, ECCSyndrome3));
113 printf("%s: ECCSyndrome4: 0x%02x\n", __FUNCTION__,
114 doc_read(bios, ECCSyndrome4));
115 printf("%s: ECCSyndrome5: 0x%02x\n", __FUNCTION__,
116 doc_read(bios, ECCSyndrome5));
117 printf("%s: AliasResolution: 0x%02x\n", __FUNCTION__,
118 doc_read(bios, AliasResolution));
119 printf("%s: ConfigurationInput: 0x%02x\n", __FUNCTION__,
120 doc_read(bios, ConfigurationInput));
121 printf("%s: ReadPipelineInitialization: 0x%02x\n", __FUNCTION__,
122 doc_read(bios, ReadPipelineInitialization));
123 printf("%s: LastDataRead: 0x%02x\n", __FUNCTION__,
124 doc_read(bios, LastDataRead));
125 printf("%s:\n", __FUNCTION__);
126
127 printf("%s: checking ECCConfiguration toggle bit\n", __FUNCTION__);
128 printf("%s:", __FUNCTION__);
129 toggle_a = toggle_b = 0;
130 for(i=0; i<10; i++)
131 {
132 unsigned char toggle = doc_toggle(bios);
133
134 printf(" 0x%02x", toggle);
135
136 if(i%2)
137 toggle_a += toggle;
138 else
139 toggle_b += toggle;
140 } /* for(i=0; i<10; i++) */
141 printf("\n%s: toggle result: %d/%d\n", __FUNCTION__, toggle_a, toggle_b);
142
143 if(chipid == flash->model_id
144 && ((toggle_a==5 && toggle_b==0)||(toggle_a==0 && toggle_b==5))
145#ifndef MSYSTEMS_DOC_NO_55AA_CHECKING
146 && id_0x55 == 0x55 && id_0xAA == 0xaa
147#endif /* !MSYSTEMS_DOC_NO_55AA_CHECKING */
148 )
149 {
150 return(1);
151 }
152
153 return(0);
154} /* int probe_md2802(struct flashchip *flash) */
155
156
157
158int
159read_md2802(struct flashchip *flash, unsigned char *buf)
160{
161
162 return(0);
163} /* int read_md2802(struct flashchip *flash, unsigned char *buf) */
164
165
166
167int
168erase_md2802(struct flashchip *flash)
169{
170 volatile char *bios = flash->virt_addr;
171
172 return(1);
173 *(volatile char *)(bios + 0x5555) = 0xAA;
174 *(volatile char *)(bios + 0x2AAA) = 0x55;
175 *(volatile char *)(bios + 0x5555) = 0x80;
176
177 *(volatile char *)(bios + 0x5555) = 0xAA;
178 *(volatile char *)(bios + 0x2AAA) = 0x55;
179 *(volatile char *)(bios + 0x5555) = 0x10;
180} /* int erase_md2802(struct flashchip *flash) */
181
182
183
184int
185write_md2802(struct flashchip *flash, unsigned char *buf)
186{
187 int i;
188 int total_size = flash->total_size *1024, page_size = flash->page_size;
189 volatile unsigned char * bios = flash->virt_addr;
190
191 return(1);
192 erase_md2802 (flash);
193 if (*bios != (unsigned char ) 0xff) {
194 printf("ERASE FAILED\n");
195 return -1;
196 }
197 printf ("Programming Page: ");
198 for (i = 0; i < total_size/page_size; i++) {
199 printf ("%04d at address: 0x%08x", i, i * page_size);
200 //write_page_md2802(bios, buf + i * page_size, bios + i * page_size, page_size);
201 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");
202 }
203 printf("\n");
204 //protect_md2802(bios);
Ronald G. Minnicheaab50b2003-09-12 22:41:53 +0000205
206} /* int write_md2802(struct flashchip *flash, char *buf) */
207
208
209
210
211
212
213/*
214 wait timeout msec for doc to become ready
215 return:
216 0: ready
217 -1: timeout expired
218*/
219static int
220doc_wait(volatile char *bios, int timeout)
221{
222 int i = 20;
223
224 doc_read_4nop(bios);
225
226 while(_doc_busy(bios) && (i != 0))
227 {
228 usleep(timeout*1000/20);
229 i--;
230 }
231
232 doc_read_2nop(bios);
233
234 if(_doc_busy(bios))
235 {
236 doc_read_2nop(bios);
237 return(-1);
238 }
239
240 return(0);
241} /* static int doc_wait(volatile char *bios, int timeout) */
242
243
244
245static unsigned char
246doc_read_docstatus(volatile char *bios)
247{
248 doc_read(bios, CDSNSlowIO);
249 doc_read_2nop(bios);
250
251 return(doc_read(bios, _DOCStatus));
252} /* static unsigned char doc_read_docstatus(volatile char *bios) */
253
254
255
256static unsigned char
257doc_read_chipid(volatile char *bios)
258{
259 doc_read(bios, CDSNSlowIO);
260 doc_read_2nop(bios);
261
262 return(doc_read(bios, _ChipID));
263} /* static unsigned char doc_read_chipid(volatile char *bios) */
264
265
266
267static unsigned char
268doc_read_cdsncontrol(volatile char *bios)
269{
270 unsigned char value;
271
272 /* the delays might be necessary when reading the busy bit,
273 but because a read to this reg reads the busy bit
274 anyway we better do this delays... */
275 doc_read_4nop(bios);
276 value = doc_read(bios, _CDSNControl);
277 doc_read_2nop(bios);
278
279 return(value);
280} /* static unsigned char doc_read_chipid(volatile char *bios) */
281
282
283
284static void
285doc_write_cdsncontrol(volatile char *bios, unsigned char data)
286{
287 doc_write(data, bios, _CDSNControl);
288 doc_read_4nop(bios);
289} /* static void doc_write_chipid(volatile char *bios, unsigned char data) */