blob: bb4a874ab190dec15eadd1250db4cd6ab181b734 [file] [log] [blame]
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +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
Ronald G. Minnicheaab50b2003-09-12 22:41:53 +000027#include <stdio.h>
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000028#include "flash.h"
29#include "jedec.h"
30
31int probe_jedec (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;
35
Ronald G. Minnichef5779d2002-01-29 20:18:02 +000036 *(volatile char *) (bios + 0x5555) = 0xAA;
37 *(volatile char *) (bios + 0x2AAA) = 0x55;
38 *(volatile char *) (bios + 0x5555) = 0x90;
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000039
Ronald G. Minnichef5779d2002-01-29 20:18:02 +000040 myusec_delay(10);
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000041
Ronald G. Minnichef5779d2002-01-29 20:18:02 +000042 id1 = *(volatile unsigned char *) bios;
43 id2 = *(volatile unsigned char *) (bios + 0x01);
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000044
Ronald G. Minnichef5779d2002-01-29 20:18:02 +000045 *(volatile char *) (bios + 0x5555) = 0xAA;
46 *(volatile char *) (bios + 0x2AAA) = 0x55;
47 *(volatile char *) (bios + 0x5555) = 0xF0;
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000048
Ronald G. Minnichef5779d2002-01-29 20:18:02 +000049 myusec_delay(10);
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000050
Ronald G. Minnichd4228fd2003-02-28 17:21:38 +000051 printf("%s: id1 0x%x, id2 0x%x\n", __FUNCTION__, id1, id2);
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000052 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{
Ronald G. Minnichef5779d2002-01-29 20:18:02 +000060 volatile char * bios = flash->virt_addr;
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000061
Ronald G. Minnichef5779d2002-01-29 20:18:02 +000062 *(volatile char *) (bios + 0x5555) = 0xAA;
63 *(volatile char *) (bios + 0x2AAA) = 0x55;
64 *(volatile char *) (bios + 0x5555) = 0x80;
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000065
Ronald G. Minnichef5779d2002-01-29 20:18:02 +000066 *(volatile char *) (bios + 0x5555) = 0xAA;
67 *(volatile char *) (bios + 0x2AAA) = 0x55;
68 *(volatile char *) (bios + 0x5555) = 0x10;
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000069
Ronald G. Minnichef5779d2002-01-29 20:18:02 +000070 myusec_delay(10);
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000071 toggle_ready_jedec(bios);
Ronald G. Minnicheaab50b2003-09-12 22:41:53 +000072
73 return(0);
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000074}
75
Ronald G. Minnicheaab50b2003-09-12 22:41:53 +000076int write_jedec (struct flashchip * flash, unsigned char * buf)
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000077{
78 int i;
79 int total_size = flash->total_size *1024, page_size = flash->page_size;
Ronald G. Minnich56439422002-09-06 16:58:14 +000080 volatile unsigned char * bios = flash->virt_addr;
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000081
82 erase_jedec (flash);
Ronald G. Minnich56439422002-09-06 16:58:14 +000083 if (*bios != (unsigned char ) 0xff) {
84 printf("ERASE FAILED\n");
85 return -1;
86 }
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000087 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);
Ronald G. Minnicheaab50b2003-09-12 22:41:53 +000096
97 return(0);
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000098}