blob: c70b37b11531ceb40cfedda279adf8cf01fd72d0 [file] [log] [blame]
Carl-Daniel Hailfingerae8afa92007-12-31 01:49:00 +00001/*
2 * This file is part of the flashrom project.
3 *
4 * Copyright (C) 2007 Carl-Daniel Hailfinger
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21/*
Mats Erik Andersson44e1a192008-09-26 13:19:02 +000022 * EN29F512 has 1C,21
23 * EN29F010 has 1C,20
24 * EN29F040A has 1C,04
25 * EN29LV010 has 1C,6E and uses short F0 reset sequence
26 * EN29LV040(A) has 1C,4F and uses short F0 reset sequence
Carl-Daniel Hailfingerae8afa92007-12-31 01:49:00 +000027 */
Mats Erik Andersson44e1a192008-09-26 13:19:02 +000028
29#include <stdio.h>
30#include <stdint.h>
31#include "flash.h"
32
Carl-Daniel Hailfingerae8afa92007-12-31 01:49:00 +000033int probe_en29f512(struct flashchip *flash)
34{
35 volatile uint8_t *bios = flash->virtual_memory;
36 uint8_t id1, id2;
37
38 *(volatile uint8_t *)(bios + 0x555) = 0xAA;
39 *(volatile uint8_t *)(bios + 0x2AA) = 0x55;
40 *(volatile uint8_t *)(bios + 0x555) = 0x90;
41
42 myusec_delay(10);
43
44 id1 = *(volatile uint8_t *)(bios + 0x100);
45 id2 = *(volatile uint8_t *)(bios + 0x101);
46
47 /* exit by writing F0 anywhere? or the code below */
48 *(volatile uint8_t *)(bios + 0x555) = 0xAA;
49 *(volatile uint8_t *)(bios + 0x2AA) = 0x55;
50 *(volatile uint8_t *)(bios + 0x555) = 0xF0;
51
Peter Stuge5cafc332009-01-25 23:52:45 +000052 printf_debug("%s: id1 0x%02x, id2 0x%02x\n", __FUNCTION__, id1, id2);
Carl-Daniel Hailfingerae8afa92007-12-31 01:49:00 +000053
54 if (id1 == flash->manufacture_id && id2 == flash->model_id)
55 return 1;
56
57 return 0;
58}
59
60/*
Mats Erik Andersson44e1a192008-09-26 13:19:02 +000061 * EN29F002AT has 1C,92
62 * EN29F002AB has 1C,97
Carl-Daniel Hailfingerae8afa92007-12-31 01:49:00 +000063 */
Mats Erik Andersson44e1a192008-09-26 13:19:02 +000064
65/* This does not seem to function properly for EN29F002NT. */
Carl-Daniel Hailfingerae8afa92007-12-31 01:49:00 +000066int probe_en29f002a(struct flashchip *flash)
67{
68 volatile uint8_t *bios = flash->virtual_memory;
69 uint8_t id1, id2;
70
71 *(volatile uint8_t *)(bios + 0x555) = 0xAA;
72 *(volatile uint8_t *)(bios + 0xAAA) = 0x55;
73 *(volatile uint8_t *)(bios + 0x555) = 0x90;
74
75 myusec_delay(10);
76
77 id1 = *(volatile uint8_t *)(bios + 0x100);
78 id2 = *(volatile uint8_t *)(bios + 0x101);
79
80 /* exit by writing F0 anywhere? or the code below */
81 *(volatile uint8_t *)(bios + 0x555) = 0xAA;
82 *(volatile uint8_t *)(bios + 0xAAA) = 0x55;
83 *(volatile uint8_t *)(bios + 0x555) = 0xF0;
84
85 printf_debug("%s: id1 0x%x, id2 0x%x\n", __FUNCTION__, id1, id2);
86
87 if (id1 == flash->manufacture_id && id2 == flash->model_id)
88 return 1;
89
90 return 0;
91}
92
Mats Erik Andersson44e1a192008-09-26 13:19:02 +000093/* The EN29F002 chip needs repeated single byte writing, no block writing. */
94int write_en29f002a(struct flashchip *flash, uint8_t *buf)
95{
96 int i;
97 int total_size = flash->total_size * 1024;
98 volatile uint8_t *bios = flash->virtual_memory;
99 volatile uint8_t *dst = bios;
100
101 // *bios = 0xF0;
102 myusec_delay(10);
103 erase_chip_jedec(flash);
104
105 printf("Programming page: ");
106 for (i = 0; i < total_size; i++) {
107 /* write to the sector */
108 if ((i & 0xfff) == 0)
109 printf("address: 0x%08lx", (unsigned long)i);
110 *(bios + 0x5555) = 0xAA;
111 *(bios + 0x2AAA) = 0x55;
112 *(bios + 0x5555) = 0xA0;
113 *dst++ = *buf++;
114
115 /* wait for Toggle bit ready */
116 toggle_ready_jedec(dst);
117
118 if ((i & 0xfff) == 0)
119 printf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b");
120 }
121
122 printf("\n");
123 return 0;
124}