blob: f26659f96f98935efa245eab5af6829a92d3e924 [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
27#include "flash.h"
28#include "jedec.h"
29
30int probe_jedec (struct flashchip * flash)
31{
Ronald G. Minnichef5779d2002-01-29 20:18:02 +000032 volatile char * bios = flash->virt_addr;
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000033 unsigned char id1, id2;
34
Ronald G. Minnichef5779d2002-01-29 20:18:02 +000035 *(volatile char *) (bios + 0x5555) = 0xAA;
36 *(volatile char *) (bios + 0x2AAA) = 0x55;
37 *(volatile char *) (bios + 0x5555) = 0x90;
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000038
Ronald G. Minnichef5779d2002-01-29 20:18:02 +000039 myusec_delay(10);
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000040
Ronald G. Minnichef5779d2002-01-29 20:18:02 +000041 id1 = *(volatile unsigned char *) bios;
42 id2 = *(volatile unsigned char *) (bios + 0x01);
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000043
Ronald G. Minnichef5779d2002-01-29 20:18:02 +000044 *(volatile char *) (bios + 0x5555) = 0xAA;
45 *(volatile char *) (bios + 0x2AAA) = 0x55;
46 *(volatile char *) (bios + 0x5555) = 0xF0;
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000047
Ronald G. Minnichef5779d2002-01-29 20:18:02 +000048 myusec_delay(10);
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000049
Ronald G. Minnichef5779d2002-01-29 20:18:02 +000050 printf(__FUNCTION__ "id1 %d, id2 %d\n", id1, id2);
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000051 if (id1 == flash->manufacture_id && id2 == flash->model_id)
52 return 1;
53
54 return 0;
55}
56
57int erase_jedec (struct flashchip * flash)
58{
Ronald G. Minnichef5779d2002-01-29 20:18:02 +000059 volatile char * bios = flash->virt_addr;
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000060
Ronald G. Minnichef5779d2002-01-29 20:18:02 +000061 *(volatile char *) (bios + 0x5555) = 0xAA;
62 *(volatile char *) (bios + 0x2AAA) = 0x55;
63 *(volatile char *) (bios + 0x5555) = 0x80;
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000064
Ronald G. Minnichef5779d2002-01-29 20:18:02 +000065 *(volatile char *) (bios + 0x5555) = 0xAA;
66 *(volatile char *) (bios + 0x2AAA) = 0x55;
67 *(volatile char *) (bios + 0x5555) = 0x10;
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000068
Ronald G. Minnichef5779d2002-01-29 20:18:02 +000069 myusec_delay(10);
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000070 toggle_ready_jedec(bios);
71}
72
73int write_jedec (struct flashchip * flash, char * buf)
74{
75 int i;
76 int total_size = flash->total_size *1024, page_size = flash->page_size;
Ronald G. Minnich56439422002-09-06 16:58:14 +000077 volatile unsigned char * bios = flash->virt_addr;
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000078
79 erase_jedec (flash);
Ronald G. Minnich56439422002-09-06 16:58:14 +000080 if (*bios != (unsigned char ) 0xff) {
81 printf("ERASE FAILED\n");
82 return -1;
83 }
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000084 printf ("Programming Page: ");
85 for (i = 0; i < total_size/page_size; i++) {
86 printf ("%04d at address: 0x%08x", i, i * page_size);
87 write_page_jedec(bios, buf + i * page_size, bios + i * page_size,
88 page_size);
89 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");
90 }
91 printf("\n");
92 protect_jedec (bios);
93}