blob: ceba046f0dae00821a53c9494fe990bf742d2a3a [file] [log] [blame]
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +00001/*
2 * am29f040.c: driver for programming AMD am29f040b models
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 * AMD Am29F040B data sheet
24 * $Id$
25 */
26
27#include "flash.h"
28#include "jedec.h"
29
Ronald G. Minnichef5779d2002-01-29 20:18:02 +000030static __inline__ erase_sector_29f040b (volatile char * bios, unsigned long address)
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000031{
32 *(bios + 0x555) = 0xAA;
33 *(bios + 0x2AA) = 0x55;
34 *(bios + 0x555) = 0x80;
35 *(bios + 0x555) = 0xAA;
36 *(bios + 0x2AA) = 0x55;
37 *(bios + address) = 0x30;
38
39 sleep(2);
40
41 /* wait for Toggle bit ready */
42 toggle_ready_jedec(bios + address);
43}
44
Ronald G. Minnichef5779d2002-01-29 20:18:02 +000045static __inline__ write_sector_29f040b(volatile char * bios, unsigned char * src,
46 volatile unsigned char * dst, unsigned int page_size)
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000047{
48 int i;
49
50 for (i = 0; i < page_size; i++) {
51 printf("0x%08x", (unsigned long) dst - (unsigned long) bios);
52
53 *(bios + 0x555) = 0xAA;
54 *(bios + 0x2AA) = 0x55;
55 *(bios + 0x555) = 0xA0;
56 *dst++ = *src++;
57
58 /* wait for Toggle bit ready */
59 toggle_ready_jedec(bios);
60
61 printf("\b\b\b\b\b\b\b\b\b\b");
62 }
63}
64
65int probe_29f040b (struct flashchip * flash)
66{
Ronald G. Minnichef5779d2002-01-29 20:18:02 +000067 volatile char * bios = flash->virt_addr;
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000068 unsigned char id1, id2;
69
70 *(bios + 0x555) = 0xAA;
71 *(bios + 0x2AA) = 0x55;
72 *(bios + 0x555) = 0x90;
73
74 id1 = *(unsigned char *) bios;
75 id2 = *(unsigned char *) (bios + 0x01);
76
77 *bios = 0xF0;
78
Ronald G. Minnichef5779d2002-01-29 20:18:02 +000079 myusec_delay(10);
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000080
Ronald G. Minnichef5779d2002-01-29 20:18:02 +000081 printf(__FUNCTION__ "id1 %d, id2 %d\n", id1, id2);
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000082 if (id1 == flash->manufacture_id && id2 == flash->model_id)
83 return 1;
84
85 return 0;
86}
87
88int erase_29f040b (struct flashchip * flash)
89{
Ronald G. Minnichef5779d2002-01-29 20:18:02 +000090 volatile char * bios = flash->virt_addr;
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000091
92 *(bios + 0x555) = 0xAA;
93 *(bios + 0x2AA) = 0x55;
94 *(bios + 0x555) = 0x80;
95 *(bios + 0x555) = 0xAA;
96 *(bios + 0x2AA) = 0x55;
97 *(bios + 0x555) = 0x10;
98
Ronald G. Minnichef5779d2002-01-29 20:18:02 +000099 myusec_delay(10);
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +0000100 toggle_ready_jedec(bios);
101}
102
103int write_29f040b (struct flashchip * flash, char * buf)
104{
105 int i;
106 int total_size = flash->total_size * 1024, page_size = flash->page_size;
Ronald G. Minnichef5779d2002-01-29 20:18:02 +0000107 volatile char * bios = flash->virt_addr;
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +0000108
109 printf ("Programming Page: ");
110 for (i = 0; i < total_size/page_size; i++) {
111 /* erase the page before programming */
112 erase_sector_29f040b(bios, i * page_size);
113
114 /* write to the sector */
115 printf ("%04d at address: ", i);
116 write_sector_29f040b(bios, buf + i * page_size, bios + i * page_size,
117 page_size);
118 printf ("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b");
119 }
120 printf("\n");
121}