| 1 | /*␊ |
| 2 | * This file is part of the flashrom project.␊ |
| 3 | *␊ |
| 4 | * Copyright (C) 2000 Silicon Integrated System Corporation␊ |
| 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 | #include "flash.h"␊ |
| 22 | #include "chipdrivers.h"␊ |
| 23 | ␊ |
| 24 | /* WARNING! ␊ |
| 25 | This chip uses the standard JEDEC Addresses in 16-bit mode as word␊ |
| 26 | addresses. In byte mode, 0xAAA has to be used instead of 0x555 and␊ |
| 27 | 0x555 instead of 0x2AA. Do *not* blindly replace with standard JEDEC␊ |
| 28 | functions. */␊ |
| 29 | ␊ |
| 30 | /* chunksize is 1 */␊ |
| 31 | int write_m29f400bt(struct flashctx *flash, uint8_t *src, unsigned int start,␊ |
| 32 | ␉␉ unsigned int len)␊ |
| 33 | {␊ |
| 34 | ␉int i;␊ |
| 35 | ␉chipaddr bios = flash->virtual_memory;␊ |
| 36 | ␉chipaddr dst = flash->virtual_memory + start;␊ |
| 37 | ␊ |
| 38 | ␉for (i = 0; i < len; i++) {␊ |
| 39 | ␉␉chip_writeb(flash, 0xAA, bios + 0xAAA);␊ |
| 40 | ␉␉chip_writeb(flash, 0x55, bios + 0x555);␊ |
| 41 | ␉␉chip_writeb(flash, 0xA0, bios + 0xAAA);␊ |
| 42 | ␊ |
| 43 | ␉␉/* transfer data from source to destination */␊ |
| 44 | ␉␉chip_writeb(flash, *src, dst);␊ |
| 45 | ␉␉toggle_ready_jedec(flash, dst);␊ |
| 46 | #if 0␊ |
| 47 | ␉␉/* We only want to print something in the error case. */␊ |
| 48 | ␉␉msg_cerr("Value in the flash at address 0x%lx = %#x, want %#x\n",␊ |
| 49 | ␉␉ (dst - bios), chip_readb(flash, dst), *src);␊ |
| 50 | #endif␊ |
| 51 | ␉␉dst++;␊ |
| 52 | ␉␉src++;␊ |
| 53 | ␉}␊ |
| 54 | ␊ |
| 55 | ␉/* FIXME: Ignore errors for now. */␊ |
| 56 | ␉return 0;␊ |
| 57 | }␊ |
| 58 | ␊ |
| 59 | int probe_m29f400bt(struct flashctx *flash)␊ |
| 60 | {␊ |
| 61 | ␉chipaddr bios = flash->virtual_memory;␊ |
| 62 | ␉uint8_t id1, id2;␊ |
| 63 | ␊ |
| 64 | ␉chip_writeb(flash, 0xAA, bios + 0xAAA);␊ |
| 65 | ␉chip_writeb(flash, 0x55, bios + 0x555);␊ |
| 66 | ␉chip_writeb(flash, 0x90, bios + 0xAAA);␊ |
| 67 | ␊ |
| 68 | ␉programmer_delay(10);␊ |
| 69 | ␊ |
| 70 | ␉id1 = chip_readb(flash, bios);␊ |
| 71 | ␉/* The data sheet says id2 is at (bios + 0x01) and id2 listed in␊ |
| 72 | ␉ * flash.h does not match. It should be possible to use JEDEC probe.␊ |
| 73 | ␉ */␊ |
| 74 | ␉id2 = chip_readb(flash, bios + 0x02);␊ |
| 75 | ␊ |
| 76 | ␉chip_writeb(flash, 0xAA, bios + 0xAAA);␊ |
| 77 | ␉chip_writeb(flash, 0x55, bios + 0x555);␊ |
| 78 | ␉chip_writeb(flash, 0xF0, bios + 0xAAA);␊ |
| 79 | ␊ |
| 80 | ␉programmer_delay(10);␊ |
| 81 | ␊ |
| 82 | ␉msg_cdbg("%s: id1 0x%02x, id2 0x%02x\n", __func__, id1, id2);␊ |
| 83 | ␊ |
| 84 | ␉if (id1 == flash->manufacture_id && id2 == flash->model_id)␊ |
| 85 | ␉␉return 1;␊ |
| 86 | ␊ |
| 87 | ␉return 0;␊ |
| 88 | }␊ |
| 89 | ␊ |
| 90 | int erase_m29f400bt(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 | ␊ |
| 109 | int block_erase_m29f400bt(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 | ␊ |
| 130 | int block_erase_chip_m29f400bt(struct flashctx *flash, unsigned int address,␊ |
| 131 | ␉␉␉ unsigned int blocklen)␊ |
| 132 | {␊ |
| 133 | ␉if ((address != 0) || (blocklen != flash->total_size * 1024)) {␊ |
| 134 | ␉␉msg_cerr("%s called with incorrect arguments\n",␊ |
| 135 | ␉␉␉__func__);␊ |
| 136 | ␉␉return -1;␊ |
| 137 | ␉}␊ |
| 138 | ␉return erase_m29f400bt(flash);␊ |
| 139 | }␊ |
| 140 | |