blob: 2daeef134551f8fc0b0e66c66bbf4d29d9b5ff1e [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.
Rudolf Marek47eff6b2012-04-14 22:51:40 +000016 */
17
18#include "flash.h"
19#include "chipdrivers.h"
20
21/*
22 * WARNING!
23 * This chip uses the standard JEDEC addresses in 16-bit mode as word
24 * addresses. In byte mode, 0xAAA has to be used instead of 0x555 and
25 * 0x555 instead of 0x2AA. Do *not* blindly replace with standard JEDEC
26 * functions.
27 */
28
29/* chunksize is 1 */
Mark Marshallf20b7be2014-05-09 21:16:21 +000030int write_en29lv640b(struct flashctx *flash, const uint8_t *src, unsigned int start, unsigned int len)
Rudolf Marek47eff6b2012-04-14 22:51:40 +000031{
Nico Huber519be662018-12-23 20:03:35 +010032 unsigned int i;
Rudolf Marek47eff6b2012-04-14 22:51:40 +000033 chipaddr bios = flash->virtual_memory;
34 chipaddr dst = flash->virtual_memory + start;
35
36 for (i = 0; i < len; i += 2) {
37 chip_writeb(flash, 0xAA, bios + 0xAAA);
38 chip_writeb(flash, 0x55, bios + 0x555);
39 chip_writeb(flash, 0xA0, bios + 0xAAA);
40
41 /* Transfer data from source to destination. */
42 chip_writew(flash, (*src) | ((*(src + 1)) << 8 ), dst);
43 toggle_ready_jedec(flash, dst);
44#if 0
45 /* We only want to print something in the error case. */
46 msg_cerr("Value in the flash at address 0x%lx = %#x, want %#x\n",
47 (dst - bios), chip_readb(flash, dst), *src);
48#endif
49 dst += 2;
50 src += 2;
Richard Hughes842d6782021-01-15 09:48:12 +000051 flashprog_progress_add(flash, 2);
Rudolf Marek47eff6b2012-04-14 22:51:40 +000052 }
53
54 /* FIXME: Ignore errors for now. */
55 return 0;
56}
57
58int probe_en29lv640b(struct flashctx *flash)
59{
60 chipaddr bios = flash->virtual_memory;
61 uint16_t id1, id2;
62
63 chip_writeb(flash, 0xAA, bios + 0xAAA);
64 chip_writeb(flash, 0x55, bios + 0x555);
65 chip_writeb(flash, 0x90, bios + 0xAAA);
66
67 programmer_delay(10);
68
69 id1 = chip_readb(flash, bios + 0x200);
70 id1 |= (chip_readb(flash, bios) << 8);
71
72 id2 = chip_readb(flash, bios + 0x02);
73
74 chip_writeb(flash, 0xF0, bios + 0xAAA);
75
76 programmer_delay(10);
77
78 msg_cdbg("%s: id1 0x%04x, id2 0x%04x\n", __func__, id1, id2);
79
Carl-Daniel Hailfinger5a7cb842012-08-25 01:17:58 +000080 if (id1 == flash->chip->manufacture_id && id2 == flash->chip->model_id)
Rudolf Marek47eff6b2012-04-14 22:51:40 +000081 return 1;
82
83 return 0;
84}