blob: e79415afbf4e2b9433de5c3d1808bc7683c428b6 [file] [log] [blame]
Rudolf Marek47eff6b2012-04-14 22:51:40 +00001/*
2 * This file is part of the flashrom project.
3 *
4 * Copyright (C) 2000 Silicon Integrated System Corporation
5 * Copyright (C) 2012 Rudolf Marek <r.marek@assembler.cz>
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22#include "flash.h"
23#include "chipdrivers.h"
24
25/*
26 * WARNING!
27 * This chip uses the standard JEDEC addresses in 16-bit mode as word
28 * addresses. In byte mode, 0xAAA has to be used instead of 0x555 and
29 * 0x555 instead of 0x2AA. Do *not* blindly replace with standard JEDEC
30 * functions.
31 */
32
33/* chunksize is 1 */
34int write_en29lv640b(struct flashctx *flash, uint8_t *src, unsigned int start,
35 unsigned int len)
36{
37 int i;
38 chipaddr bios = flash->virtual_memory;
39 chipaddr dst = flash->virtual_memory + start;
40
41 for (i = 0; i < len; i += 2) {
42 chip_writeb(flash, 0xAA, bios + 0xAAA);
43 chip_writeb(flash, 0x55, bios + 0x555);
44 chip_writeb(flash, 0xA0, bios + 0xAAA);
45
46 /* Transfer data from source to destination. */
47 chip_writew(flash, (*src) | ((*(src + 1)) << 8 ), dst);
48 toggle_ready_jedec(flash, dst);
49#if 0
50 /* We only want to print something in the error case. */
51 msg_cerr("Value in the flash at address 0x%lx = %#x, want %#x\n",
52 (dst - bios), chip_readb(flash, dst), *src);
53#endif
54 dst += 2;
55 src += 2;
56 }
57
58 /* FIXME: Ignore errors for now. */
59 return 0;
60}
61
62int probe_en29lv640b(struct flashctx *flash)
63{
64 chipaddr bios = flash->virtual_memory;
65 uint16_t id1, id2;
66
67 chip_writeb(flash, 0xAA, bios + 0xAAA);
68 chip_writeb(flash, 0x55, bios + 0x555);
69 chip_writeb(flash, 0x90, bios + 0xAAA);
70
71 programmer_delay(10);
72
73 id1 = chip_readb(flash, bios + 0x200);
74 id1 |= (chip_readb(flash, bios) << 8);
75
76 id2 = chip_readb(flash, bios + 0x02);
77
78 chip_writeb(flash, 0xF0, bios + 0xAAA);
79
80 programmer_delay(10);
81
82 msg_cdbg("%s: id1 0x%04x, id2 0x%04x\n", __func__, id1, id2);
83
Carl-Daniel Hailfinger5a7cb842012-08-25 01:17:58 +000084 if (id1 == flash->chip->manufacture_id && id2 == flash->chip->model_id)
Rudolf Marek47eff6b2012-04-14 22:51:40 +000085 return 1;
86
87 return 0;
88}
89
90int erase_en29lv640b(struct flashctx *flash)
91{
92 chipaddr bios = flash->virtual_memory;
93
94 chip_writeb(flash, 0xAA, bios + 0xAAA);
95 chip_writeb(flash, 0x55, bios + 0x555);
96 chip_writeb(flash, 0x80, bios + 0xAAA);
97
98 chip_writeb(flash, 0xAA, bios + 0xAAA);
99 chip_writeb(flash, 0x55, bios + 0x555);
100 chip_writeb(flash, 0x10, bios + 0xAAA);
101
102 programmer_delay(10);
103 toggle_ready_jedec(flash, bios);
104
105 /* FIXME: Check the status register for errors. */
106 return 0;
107}
108
109int block_erase_en29lv640b(struct flashctx *flash, unsigned int start,
110 unsigned int len)
111{
112 chipaddr bios = flash->virtual_memory;
113 chipaddr dst = bios + start;
114
115 chip_writeb(flash, 0xAA, bios + 0xAAA);
116 chip_writeb(flash, 0x55, bios + 0x555);
117 chip_writeb(flash, 0x80, bios + 0xAAA);
118
119 chip_writeb(flash, 0xAA, bios + 0xAAA);
120 chip_writeb(flash, 0x55, bios + 0x555);
121 chip_writeb(flash, 0x30, dst);
122
123 programmer_delay(10);
124 toggle_ready_jedec(flash, bios);
125
126 /* FIXME: Check the status register for errors. */
127 return 0;
128}
129
130int block_erase_chip_en29lv640b(struct flashctx *flash, unsigned int address,
131 unsigned int blocklen)
132{
Carl-Daniel Hailfinger5a7cb842012-08-25 01:17:58 +0000133 if ((address != 0) || (blocklen != flash->chip->total_size * 1024)) {
Rudolf Marek47eff6b2012-04-14 22:51:40 +0000134 msg_cerr("%s called with incorrect arguments\n", __func__);
135 return -1;
136 }
137 return erase_en29lv640b(flash);
138}