Carl-Daniel Hailfinger | ae8afa9 | 2007-12-31 01:49:00 +0000 | [diff] [blame] | 1 | /* |
| 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 Andersson | 44e1a19 | 2008-09-26 13:19:02 +0000 | [diff] [blame] | 22 | * 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 Hailfinger | ae8afa9 | 2007-12-31 01:49:00 +0000 | [diff] [blame] | 27 | */ |
Mats Erik Andersson | 44e1a19 | 2008-09-26 13:19:02 +0000 | [diff] [blame] | 28 | |
Mats Erik Andersson | 44e1a19 | 2008-09-26 13:19:02 +0000 | [diff] [blame] | 29 | #include "flash.h" |
| 30 | |
Carl-Daniel Hailfinger | ae8afa9 | 2007-12-31 01:49:00 +0000 | [diff] [blame] | 31 | int probe_en29f512(struct flashchip *flash) |
| 32 | { |
Carl-Daniel Hailfinger | 5820f42 | 2009-05-16 21:22:56 +0000 | [diff] [blame] | 33 | chipaddr bios = flash->virtual_memory; |
Carl-Daniel Hailfinger | ae8afa9 | 2007-12-31 01:49:00 +0000 | [diff] [blame] | 34 | uint8_t id1, id2; |
| 35 | |
Carl-Daniel Hailfinger | 0472f3d | 2009-03-06 22:26:00 +0000 | [diff] [blame] | 36 | chip_writeb(0xAA, bios + 0x555); |
| 37 | chip_writeb(0x55, bios + 0x2AA); |
| 38 | chip_writeb(0x90, bios + 0x555); |
Carl-Daniel Hailfinger | ae8afa9 | 2007-12-31 01:49:00 +0000 | [diff] [blame] | 39 | |
Carl-Daniel Hailfinger | ca8bfc6 | 2009-06-05 17:48:08 +0000 | [diff] [blame] | 40 | programmer_delay(10); |
Carl-Daniel Hailfinger | ae8afa9 | 2007-12-31 01:49:00 +0000 | [diff] [blame] | 41 | |
Carl-Daniel Hailfinger | 0472f3d | 2009-03-06 22:26:00 +0000 | [diff] [blame] | 42 | id1 = chip_readb(bios + 0x100); |
| 43 | id2 = chip_readb(bios + 0x101); |
Carl-Daniel Hailfinger | ae8afa9 | 2007-12-31 01:49:00 +0000 | [diff] [blame] | 44 | |
| 45 | /* exit by writing F0 anywhere? or the code below */ |
Carl-Daniel Hailfinger | 0472f3d | 2009-03-06 22:26:00 +0000 | [diff] [blame] | 46 | chip_writeb(0xAA, bios + 0x555); |
| 47 | chip_writeb(0x55, bios + 0x2AA); |
| 48 | chip_writeb(0xF0, bios + 0x555); |
Carl-Daniel Hailfinger | ae8afa9 | 2007-12-31 01:49:00 +0000 | [diff] [blame] | 49 | |
Peter Stuge | 5cafc33 | 2009-01-25 23:52:45 +0000 | [diff] [blame] | 50 | printf_debug("%s: id1 0x%02x, id2 0x%02x\n", __FUNCTION__, id1, id2); |
Carl-Daniel Hailfinger | ae8afa9 | 2007-12-31 01:49:00 +0000 | [diff] [blame] | 51 | |
| 52 | if (id1 == flash->manufacture_id && id2 == flash->model_id) |
| 53 | return 1; |
| 54 | |
| 55 | return 0; |
| 56 | } |
| 57 | |
| 58 | /* |
Mats Erik Andersson | 44e1a19 | 2008-09-26 13:19:02 +0000 | [diff] [blame] | 59 | * EN29F002AT has 1C,92 |
| 60 | * EN29F002AB has 1C,97 |
Carl-Daniel Hailfinger | ae8afa9 | 2007-12-31 01:49:00 +0000 | [diff] [blame] | 61 | */ |
Mats Erik Andersson | 44e1a19 | 2008-09-26 13:19:02 +0000 | [diff] [blame] | 62 | |
| 63 | /* This does not seem to function properly for EN29F002NT. */ |
Carl-Daniel Hailfinger | ae8afa9 | 2007-12-31 01:49:00 +0000 | [diff] [blame] | 64 | int probe_en29f002a(struct flashchip *flash) |
| 65 | { |
Carl-Daniel Hailfinger | 5820f42 | 2009-05-16 21:22:56 +0000 | [diff] [blame] | 66 | chipaddr bios = flash->virtual_memory; |
Carl-Daniel Hailfinger | ae8afa9 | 2007-12-31 01:49:00 +0000 | [diff] [blame] | 67 | uint8_t id1, id2; |
| 68 | |
Carl-Daniel Hailfinger | 0472f3d | 2009-03-06 22:26:00 +0000 | [diff] [blame] | 69 | chip_writeb(0xAA, bios + 0x555); |
| 70 | chip_writeb(0x55, bios + 0xAAA); |
| 71 | chip_writeb(0x90, bios + 0x555); |
Carl-Daniel Hailfinger | ae8afa9 | 2007-12-31 01:49:00 +0000 | [diff] [blame] | 72 | |
Carl-Daniel Hailfinger | ca8bfc6 | 2009-06-05 17:48:08 +0000 | [diff] [blame] | 73 | programmer_delay(10); |
Carl-Daniel Hailfinger | ae8afa9 | 2007-12-31 01:49:00 +0000 | [diff] [blame] | 74 | |
Carl-Daniel Hailfinger | 0472f3d | 2009-03-06 22:26:00 +0000 | [diff] [blame] | 75 | id1 = chip_readb(bios + 0x100); |
| 76 | id2 = chip_readb(bios + 0x101); |
Carl-Daniel Hailfinger | ae8afa9 | 2007-12-31 01:49:00 +0000 | [diff] [blame] | 77 | |
| 78 | /* exit by writing F0 anywhere? or the code below */ |
Carl-Daniel Hailfinger | 0472f3d | 2009-03-06 22:26:00 +0000 | [diff] [blame] | 79 | chip_writeb(0xAA, bios + 0x555); |
| 80 | chip_writeb(0x55, bios + 0xAAA); |
| 81 | chip_writeb(0xF0, bios + 0x555); |
Carl-Daniel Hailfinger | ae8afa9 | 2007-12-31 01:49:00 +0000 | [diff] [blame] | 82 | |
| 83 | printf_debug("%s: id1 0x%x, id2 0x%x\n", __FUNCTION__, id1, id2); |
| 84 | |
| 85 | if (id1 == flash->manufacture_id && id2 == flash->model_id) |
| 86 | return 1; |
| 87 | |
| 88 | return 0; |
| 89 | } |
| 90 | |
Mats Erik Andersson | 44e1a19 | 2008-09-26 13:19:02 +0000 | [diff] [blame] | 91 | /* The EN29F002 chip needs repeated single byte writing, no block writing. */ |
| 92 | int write_en29f002a(struct flashchip *flash, uint8_t *buf) |
| 93 | { |
| 94 | int i; |
| 95 | int total_size = flash->total_size * 1024; |
Carl-Daniel Hailfinger | 5820f42 | 2009-05-16 21:22:56 +0000 | [diff] [blame] | 96 | chipaddr bios = flash->virtual_memory; |
| 97 | chipaddr dst = bios; |
Mats Erik Andersson | 44e1a19 | 2008-09-26 13:19:02 +0000 | [diff] [blame] | 98 | |
Carl-Daniel Hailfinger | 5820f42 | 2009-05-16 21:22:56 +0000 | [diff] [blame] | 99 | //chip_writeb(0xF0, bios); |
Carl-Daniel Hailfinger | ca8bfc6 | 2009-06-05 17:48:08 +0000 | [diff] [blame] | 100 | programmer_delay(10); |
Mats Erik Andersson | 44e1a19 | 2008-09-26 13:19:02 +0000 | [diff] [blame] | 101 | erase_chip_jedec(flash); |
| 102 | |
| 103 | printf("Programming page: "); |
| 104 | for (i = 0; i < total_size; i++) { |
| 105 | /* write to the sector */ |
| 106 | if ((i & 0xfff) == 0) |
| 107 | printf("address: 0x%08lx", (unsigned long)i); |
Carl-Daniel Hailfinger | 0472f3d | 2009-03-06 22:26:00 +0000 | [diff] [blame] | 108 | chip_writeb(0xAA, bios + 0x5555); |
| 109 | chip_writeb(0x55, bios + 0x2AAA); |
| 110 | chip_writeb(0xA0, bios + 0x5555); |
| 111 | chip_writeb(*buf++, dst++); |
Mats Erik Andersson | 44e1a19 | 2008-09-26 13:19:02 +0000 | [diff] [blame] | 112 | |
| 113 | /* wait for Toggle bit ready */ |
| 114 | toggle_ready_jedec(dst); |
| 115 | |
| 116 | if ((i & 0xfff) == 0) |
| 117 | printf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"); |
| 118 | } |
| 119 | |
| 120 | printf("\n"); |
| 121 | return 0; |
| 122 | } |