xref: /aosp_15_r20/external/flashrom/w29ee011.c (revision 0d6140be3aa665ecc836e8907834fcd3e3b018fc)
1 /*
2  * This file is part of the flashrom project.
3  *
4  * Copyright (C) 2007 Markus Boas <[email protected]>
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 
17 #include <string.h>
18 #include <stdbool.h>
19 
20 #include "flash.h"
21 #include "chipdrivers.h"
22 
w29ee011_can_override(const char * const chip_name,const char * const override_chip)23 bool w29ee011_can_override(const char *const chip_name, const char *const override_chip)
24 {
25 	if (!override_chip || strcmp(override_chip, chip_name)) {
26 		msg_cdbg("Old Winbond W29* probe method disabled because "
27 			 "the probing sequence puts the AMIC A49LF040A in "
28 			 "a funky state. Use 'flashrom -c %s' if you "
29 			 "have a board with such a chip.\n", chip_name);
30 		return false;
31 	}
32 
33 	return true;
34 }
35 
36 /* According to the Winbond W29EE011, W29EE012, W29C010M, W29C011A
37  * datasheets this is the only valid probe function for those chips.
38  */
probe_w29ee011(struct flashctx * flash)39 int probe_w29ee011(struct flashctx *flash)
40 {
41 	chipaddr bios = flash->virtual_memory;
42 	uint8_t id1, id2;
43 
44 	/* Issue JEDEC Product ID Entry command */
45 	chip_writeb(flash, 0xAA, bios + 0x5555);
46 	programmer_delay(flash, 10);
47 	chip_writeb(flash, 0x55, bios + 0x2AAA);
48 	programmer_delay(flash, 10);
49 	chip_writeb(flash, 0x80, bios + 0x5555);
50 	programmer_delay(flash, 10);
51 	chip_writeb(flash, 0xAA, bios + 0x5555);
52 	programmer_delay(flash, 10);
53 	chip_writeb(flash, 0x55, bios + 0x2AAA);
54 	programmer_delay(flash, 10);
55 	chip_writeb(flash, 0x60, bios + 0x5555);
56 	programmer_delay(flash, 10);
57 
58 	/* Read product ID */
59 	id1 = chip_readb(flash, bios);
60 	id2 = chip_readb(flash, bios + 0x01);
61 
62 	/* Issue JEDEC Product ID Exit command */
63 	chip_writeb(flash, 0xAA, bios + 0x5555);
64 	programmer_delay(flash, 10);
65 	chip_writeb(flash, 0x55, bios + 0x2AAA);
66 	programmer_delay(flash, 10);
67 	chip_writeb(flash, 0xF0, bios + 0x5555);
68 	programmer_delay(flash, 10);
69 
70 	msg_cdbg("%s: id1 0x%02x, id2 0x%02x\n", __func__, id1, id2);
71 
72 	if (id1 == flash->chip->manufacture_id && id2 == flash->chip->model_id)
73 		return 1;
74 
75 	return 0;
76 }
77