blob: bb4a874ab190dec15eadd1250db4cd6ab181b734 [file] [log] [blame]
rminnich8d3ff912003-10-25 17:01:29 +00001/*
2 * jedec.c: driver for programming JEDEC standard flash parts
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 *
24 * $Id$
25 */
26
27#include <stdio.h>
28#include "flash.h"
29#include "jedec.h"
30
31int probe_jedec (struct flashchip * flash)
32{
33 volatile char * bios = flash->virt_addr;
34 unsigned char id1, id2;
35
36 *(volatile char *) (bios + 0x5555) = 0xAA;
37 *(volatile char *) (bios + 0x2AAA) = 0x55;
38 *(volatile char *) (bios + 0x5555) = 0x90;
39
40 myusec_delay(10);
41
42 id1 = *(volatile unsigned char *) bios;
43 id2 = *(volatile unsigned char *) (bios + 0x01);
44
45 *(volatile char *) (bios + 0x5555) = 0xAA;
46 *(volatile char *) (bios + 0x2AAA) = 0x55;
47 *(volatile char *) (bios + 0x5555) = 0xF0;
48
49 myusec_delay(10);
50
51 printf("%s: id1 0x%x, id2 0x%x\n", __FUNCTION__, id1, id2);
52 if (id1 == flash->manufacture_id && id2 == flash->model_id)
53 return 1;
54
55 return 0;
56}
57
58int erase_jedec (struct flashchip * flash)
59{
60 volatile char * bios = flash->virt_addr;
61
62 *(volatile char *) (bios + 0x5555) = 0xAA;
63 *(volatile char *) (bios + 0x2AAA) = 0x55;
64 *(volatile char *) (bios + 0x5555) = 0x80;
65
66 *(volatile char *) (bios + 0x5555) = 0xAA;
67 *(volatile char *) (bios + 0x2AAA) = 0x55;
68 *(volatile char *) (bios + 0x5555) = 0x10;
69
70 myusec_delay(10);
71 toggle_ready_jedec(bios);
72
73 return(0);
74}
75
76int write_jedec (struct flashchip * flash, unsigned char * buf)
77{
78 int i;
79 int total_size = flash->total_size *1024, page_size = flash->page_size;
80 volatile unsigned char * bios = flash->virt_addr;
81
82 erase_jedec (flash);
83 if (*bios != (unsigned char ) 0xff) {
84 printf("ERASE FAILED\n");
85 return -1;
86 }
87 printf ("Programming Page: ");
88 for (i = 0; i < total_size/page_size; i++) {
89 printf ("%04d at address: 0x%08x", i, i * page_size);
90 write_page_jedec(bios, buf + i * page_size, bios + i * page_size,
91 page_size);
92 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");
93 }
94 printf("\n");
95 protect_jedec (bios);
96
97 return(0);
98}