blob: 2f153db6043284686e8e20496b79bb6c3a4d9c52 [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{
Ollie Lho73eca802004-03-19 22:10:07 +000033 volatile char * bios = flash->virt_addr;
34 unsigned char id1, id2;
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000035
Ollie Lho73eca802004-03-19 22:10:07 +000036 *(volatile char *) (bios + 0x5555) = 0xAA;
37 myusec_delay(10);
38 *(volatile char *) (bios + 0x2AAA) = 0x55;
39 myusec_delay(10);
40 *(volatile char *) (bios + 0x5555) = 0x90;
41 myusec_delay(10);
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000042
Ollie Lho73eca802004-03-19 22:10:07 +000043 id1 = *(volatile unsigned char *) bios;
44 id2 = *(volatile unsigned char *) (bios + 0x01);
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000045
Ollie Lho73eca802004-03-19 22:10:07 +000046 *(volatile char *) (bios + 0x5555) = 0xAA;
47 myusec_delay(10);
48 *(volatile char *) (bios + 0x2AAA) = 0x55;
49 myusec_delay(10);
50 *(volatile char *) (bios + 0x5555) = 0xF0;
51 myusec_delay(10);
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000052
Ronald G. Minnichd4228fd2003-02-28 17:21:38 +000053 printf("%s: id1 0x%x, id2 0x%x\n", __FUNCTION__, id1, id2);
Ollie Lho73eca802004-03-19 22:10:07 +000054 if (id1 == flash->manufacture_id && id2 == flash->model_id)
55 return 1;
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000056
Ollie Lho73eca802004-03-19 22:10:07 +000057 return 0;
58}
59
60int erase_sector_jedec (volatile char * bios, unsigned int page)
61{
62 /* Chip erase function does not exist for LPC mode on 49lf040.
63 * Erase sector-by-sector instead. */
64 volatile unsigned char *Temp;
65
66 /* Issue the Sector Erase command to 40LF040 */
67 Temp = bios + 0x5555; /* set up address to be C000:5555h */
68 *Temp = 0xAA; /* write data 0xAA to the address */
69 myusec_delay(10);
70 Temp = bios + 0x2AAA; /* set up address to be C000:2AAAh */
71 *Temp = 0x55; /* write data 0x55 to the address */
72 myusec_delay(10);
73 Temp = bios + 0x5555; /* set up address to be C000:5555h */
74 *Temp = 0x80; /* write data 0x80 to the address */
75 myusec_delay(10);
76 Temp = bios + 0x5555; /* set up address to be C000:5555h */
77 *Temp = 0xAA; /* write data 0xAA to the address */
78 myusec_delay(10);
79 Temp = bios + 0x2AAA; /* set up address to be C000:2AAAh */
80 *Temp = 0x55; /* write data 0x55 to the address */
81 myusec_delay(10);
82 Temp = bios + page; /* set up address to be the current sector */
83 *Temp = 0x30; /* write data 0x30 to the address */
84
85 /* wait for Toggle bit ready */
86 toggle_ready_jedec(bios);
87
88 return(0);
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000089}
90
91int erase_jedec (struct flashchip * flash)
92{
Ollie Lho73eca802004-03-19 22:10:07 +000093 volatile unsigned char * bios = flash->virt_addr;
94 volatile unsigned char *Temp;
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000095
Ollie Lho73eca802004-03-19 22:10:07 +000096 /* Issue the Sector Erase command to 39SF020 */
97 Temp = bios + 0x5555; /* set up address to be C000:5555h */
98 *Temp = 0xAA; /* write data 0xAA to the address */
Ronald G. Minnichef5779d2002-01-29 20:18:02 +000099 myusec_delay(10);
Ollie Lho73eca802004-03-19 22:10:07 +0000100 Temp = bios + 0x2AAA; /* set up address to be C000:2AAAh */
101 *Temp = 0x55; /* write data 0x55 to the address */
102 myusec_delay(10);
103 Temp = bios + 0x5555; /* set up address to be C000:5555h */
104 *Temp = 0x80; /* write data 0x80 to the address */
105 myusec_delay(10);
106 Temp = bios + 0x5555; /* set up address to be C000:5555h */
107 *Temp = 0xAA; /* write data 0xAA to the address */
108 myusec_delay(10);
109 Temp = bios + 0x2AAA; /* set up address to be C000:2AAAh */
110 *Temp = 0x55; /* write data 0x55 to the address */
111 myusec_delay(10);
112 Temp = bios + 0x5555; /* set up address to be C000:5555h */
113 *Temp = 0x10; /* write data 0x55 to the address */
114 myusec_delay(10);
115
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +0000116 toggle_ready_jedec(bios);
Ronald G. Minnicheaab50b2003-09-12 22:41:53 +0000117
118 return(0);
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +0000119}
120
Ronald G. Minnicheaab50b2003-09-12 22:41:53 +0000121int write_jedec (struct flashchip * flash, unsigned char * buf)
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +0000122{
123 int i;
124 int total_size = flash->total_size *1024, page_size = flash->page_size;
Ronald G. Minnich56439422002-09-06 16:58:14 +0000125 volatile unsigned char * bios = flash->virt_addr;
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +0000126
127 erase_jedec (flash);
Ronald G. Minnich56439422002-09-06 16:58:14 +0000128 if (*bios != (unsigned char ) 0xff) {
129 printf("ERASE FAILED\n");
130 return -1;
131 }
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +0000132 printf ("Programming Page: ");
133 for (i = 0; i < total_size/page_size; i++) {
134 printf ("%04d at address: 0x%08x", i, i * page_size);
135 write_page_jedec(bios, buf + i * page_size, bios + i * page_size,
136 page_size);
137 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");
138 }
139 printf("\n");
140 protect_jedec (bios);
Ronald G. Minnicheaab50b2003-09-12 22:41:53 +0000141
142 return(0);
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +0000143}