blob: 121297fc2ddae40a0043c72598eb35aca7748efa [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
30static __inline__ erase_sector_29f040b (char * bios, unsigned long address)
31{
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
45static __inline__ write_sector_29f040b(char * bios, unsigned char * src,
46 unsigned char * dst, unsigned int page_size)
47{
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{
67 char * bios = flash->virt_addr;
68 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
79 usleep(10);
80
81 if (id1 == flash->manufacture_id && id2 == flash->model_id)
82 return 1;
83
84 return 0;
85}
86
87int erase_29f040b (struct flashchip * flash)
88{
89 char * bios = flash->virt_addr;
90
91 *(bios + 0x555) = 0xAA;
92 *(bios + 0x2AA) = 0x55;
93 *(bios + 0x555) = 0x80;
94 *(bios + 0x555) = 0xAA;
95 *(bios + 0x2AA) = 0x55;
96 *(bios + 0x555) = 0x10;
97
98 usleep(10);
99 toggle_ready_jedec(bios);
100}
101
102int write_29f040b (struct flashchip * flash, char * buf)
103{
104 int i;
105 int total_size = flash->total_size * 1024, page_size = flash->page_size;
106 char * bios = flash->virt_addr;
107
108 printf ("Programming Page: ");
109 for (i = 0; i < total_size/page_size; i++) {
110 /* erase the page before programming */
111 erase_sector_29f040b(bios, i * page_size);
112
113 /* write to the sector */
114 printf ("%04d at address: ", i);
115 write_sector_29f040b(bios, buf + i * page_size, bios + i * page_size,
116 page_size);
117 printf ("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b");
118 }
119 printf("\n");
120}