blob: a274f62b9c4eefc693919ab7992e5b85d6101883 [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 */
Mark Marshallf20b7be2014-05-09 21:16:21 +000034int write_en29lv640b(struct flashctx *flash, const uint8_t *src, unsigned int start, unsigned int len)
Rudolf Marek47eff6b2012-04-14 22:51:40 +000035{
36 int i;
37 chipaddr bios = flash->virtual_memory;
38 chipaddr dst = flash->virtual_memory + start;
39
40 for (i = 0; i < len; i += 2) {
41 chip_writeb(flash, 0xAA, bios + 0xAAA);
42 chip_writeb(flash, 0x55, bios + 0x555);
43 chip_writeb(flash, 0xA0, bios + 0xAAA);
44
45 /* Transfer data from source to destination. */
46 chip_writew(flash, (*src) | ((*(src + 1)) << 8 ), dst);
47 toggle_ready_jedec(flash, dst);
48#if 0
49 /* We only want to print something in the error case. */
50 msg_cerr("Value in the flash at address 0x%lx = %#x, want %#x\n",
51 (dst - bios), chip_readb(flash, dst), *src);
52#endif
53 dst += 2;
54 src += 2;
55 }
56
57 /* FIXME: Ignore errors for now. */
58 return 0;
59}
60
61int probe_en29lv640b(struct flashctx *flash)
62{
63 chipaddr bios = flash->virtual_memory;
64 uint16_t id1, id2;
65
66 chip_writeb(flash, 0xAA, bios + 0xAAA);
67 chip_writeb(flash, 0x55, bios + 0x555);
68 chip_writeb(flash, 0x90, bios + 0xAAA);
69
70 programmer_delay(10);
71
72 id1 = chip_readb(flash, bios + 0x200);
73 id1 |= (chip_readb(flash, bios) << 8);
74
75 id2 = chip_readb(flash, bios + 0x02);
76
77 chip_writeb(flash, 0xF0, bios + 0xAAA);
78
79 programmer_delay(10);
80
81 msg_cdbg("%s: id1 0x%04x, id2 0x%04x\n", __func__, id1, id2);
82
Carl-Daniel Hailfinger5a7cb842012-08-25 01:17:58 +000083 if (id1 == flash->chip->manufacture_id && id2 == flash->chip->model_id)
Rudolf Marek47eff6b2012-04-14 22:51:40 +000084 return 1;
85
86 return 0;
87}
88
Stefan Taunerf2756fa2014-06-01 02:21:02 +000089static int erase_chip_shifted_jedec(struct flashctx *flash)
Rudolf Marek47eff6b2012-04-14 22:51:40 +000090{
91 chipaddr bios = flash->virtual_memory;
92
93 chip_writeb(flash, 0xAA, bios + 0xAAA);
94 chip_writeb(flash, 0x55, bios + 0x555);
95 chip_writeb(flash, 0x80, bios + 0xAAA);
96
97 chip_writeb(flash, 0xAA, bios + 0xAAA);
98 chip_writeb(flash, 0x55, bios + 0x555);
99 chip_writeb(flash, 0x10, bios + 0xAAA);
100
101 programmer_delay(10);
102 toggle_ready_jedec(flash, bios);
103
104 /* FIXME: Check the status register for errors. */
105 return 0;
106}
107
Stefan Taunerf2756fa2014-06-01 02:21:02 +0000108int erase_block_shifted_jedec(struct flashctx *flash, unsigned int start, unsigned int len)
Rudolf Marek47eff6b2012-04-14 22:51:40 +0000109{
110 chipaddr bios = flash->virtual_memory;
111 chipaddr dst = bios + start;
112
113 chip_writeb(flash, 0xAA, bios + 0xAAA);
114 chip_writeb(flash, 0x55, bios + 0x555);
115 chip_writeb(flash, 0x80, bios + 0xAAA);
116
117 chip_writeb(flash, 0xAA, bios + 0xAAA);
118 chip_writeb(flash, 0x55, bios + 0x555);
119 chip_writeb(flash, 0x30, dst);
120
121 programmer_delay(10);
122 toggle_ready_jedec(flash, bios);
123
124 /* FIXME: Check the status register for errors. */
125 return 0;
126}
127
Stefan Taunerf2756fa2014-06-01 02:21:02 +0000128int erase_chip_block_shifted_jedec(struct flashctx *flash, unsigned int address, unsigned int blocklen)
Rudolf Marek47eff6b2012-04-14 22:51:40 +0000129{
Carl-Daniel Hailfinger5a7cb842012-08-25 01:17:58 +0000130 if ((address != 0) || (blocklen != flash->chip->total_size * 1024)) {
Rudolf Marek47eff6b2012-04-14 22:51:40 +0000131 msg_cerr("%s called with incorrect arguments\n", __func__);
132 return -1;
133 }
Stefan Taunerf2756fa2014-06-01 02:21:02 +0000134 return erase_chip_shifted_jedec(flash);
Rudolf Marek47eff6b2012-04-14 22:51:40 +0000135}