| 1 | /*␊ |
| 2 | * This file is part of the flashrom project.␊ |
| 3 | *␊ |
| 4 | * Copyright (C) 2000 Silicon Integrated System Corporation␊ |
| 5 | * Copyright (C) 2005 coresystems GmbH <stepan@openbios.org>␊ |
| 6 | * Copyright (C) 2009 Sean Nelson <audiohacked@gmail.com>␊ |
| 7 | *␊ |
| 8 | * This program is free software; you can redistribute it and/or modify␊ |
| 9 | * it under the terms of the GNU General Public License as published by␊ |
| 10 | * the Free Software Foundation; either version 2 of the License, or␊ |
| 11 | * (at your option) any later version.␊ |
| 12 | *␊ |
| 13 | * This program is distributed in the hope that it will be useful,␊ |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of␊ |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the␊ |
| 16 | * GNU General Public License for more details.␊ |
| 17 | *␊ |
| 18 | * You should have received a copy of the GNU General Public License␊ |
| 19 | * along with this program; if not, write to the Free Software␊ |
| 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA␊ |
| 21 | */␊ |
| 22 | ␊ |
| 23 | #include "flash.h"␊ |
| 24 | #include "chipdrivers.h"␊ |
| 25 | ␊ |
| 26 | #define AUTO_PG_ERASE1␉␉0x20␊ |
| 27 | #define AUTO_PG_ERASE2␉␉0xD0␊ |
| 28 | #define AUTO_PGRM␉␉0x10␊ |
| 29 | #define CHIP_ERASE␉␉0x30␊ |
| 30 | #define RESET␉␉␉0xFF␊ |
| 31 | #define READ_ID␉␉␉0x90␊ |
| 32 | ␊ |
| 33 | int protect_28sf040(struct flashctx *flash)␊ |
| 34 | {␊ |
| 35 | ␉chipaddr bios = flash->virtual_memory;␊ |
| 36 | ␊ |
| 37 | ␉chip_readb(flash, bios + 0x1823);␊ |
| 38 | ␉chip_readb(flash, bios + 0x1820);␊ |
| 39 | ␉chip_readb(flash, bios + 0x1822);␊ |
| 40 | ␉chip_readb(flash, bios + 0x0418);␊ |
| 41 | ␉chip_readb(flash, bios + 0x041B);␊ |
| 42 | ␉chip_readb(flash, bios + 0x0419);␊ |
| 43 | ␉chip_readb(flash, bios + 0x040A);␊ |
| 44 | ␊ |
| 45 | ␉return 0;␊ |
| 46 | }␊ |
| 47 | ␊ |
| 48 | int unprotect_28sf040(struct flashctx *flash)␊ |
| 49 | {␊ |
| 50 | ␉chipaddr bios = flash->virtual_memory;␊ |
| 51 | ␊ |
| 52 | ␉chip_readb(flash, bios + 0x1823);␊ |
| 53 | ␉chip_readb(flash, bios + 0x1820);␊ |
| 54 | ␉chip_readb(flash, bios + 0x1822);␊ |
| 55 | ␉chip_readb(flash, bios + 0x0418);␊ |
| 56 | ␉chip_readb(flash, bios + 0x041B);␊ |
| 57 | ␉chip_readb(flash, bios + 0x0419);␊ |
| 58 | ␉chip_readb(flash, bios + 0x041A);␊ |
| 59 | ␊ |
| 60 | ␉return 0;␊ |
| 61 | }␊ |
| 62 | ␊ |
| 63 | int erase_sector_28sf040(struct flashctx *flash, unsigned int address,␊ |
| 64 | ␉␉␉ unsigned int sector_size)␊ |
| 65 | {␊ |
| 66 | ␉chipaddr bios = flash->virtual_memory;␊ |
| 67 | ␊ |
| 68 | ␉/* This command sequence is very similar to erase_block_82802ab. */␊ |
| 69 | ␉chip_writeb(flash, AUTO_PG_ERASE1, bios);␊ |
| 70 | ␉chip_writeb(flash, AUTO_PG_ERASE2, bios + address);␊ |
| 71 | ␊ |
| 72 | ␉/* wait for Toggle bit ready */␊ |
| 73 | ␉toggle_ready_jedec(flash, bios);␊ |
| 74 | ␊ |
| 75 | ␉/* FIXME: Check the status register for errors. */␊ |
| 76 | ␉return 0;␊ |
| 77 | }␊ |
| 78 | ␊ |
| 79 | /* chunksize is 1 */␊ |
| 80 | int write_28sf040(struct flashctx *flash, uint8_t *src, unsigned int start,␊ |
| 81 | ␉␉ unsigned int len)␊ |
| 82 | {␊ |
| 83 | ␉int i;␊ |
| 84 | ␉chipaddr bios = flash->virtual_memory;␊ |
| 85 | ␉chipaddr dst = flash->virtual_memory + start;␊ |
| 86 | ␊ |
| 87 | ␉for (i = 0; i < len; i++) {␊ |
| 88 | ␉␉/* transfer data from source to destination */␊ |
| 89 | ␉␉if (*src == 0xFF) {␊ |
| 90 | ␉␉␉dst++, src++;␊ |
| 91 | ␉␉␉/* If the data is 0xFF, don't program it */␊ |
| 92 | ␉␉␉continue;␊ |
| 93 | ␉␉}␊ |
| 94 | ␉␉/*issue AUTO PROGRAM command */␊ |
| 95 | ␉␉chip_writeb(flash, AUTO_PGRM, dst);␊ |
| 96 | ␉␉chip_writeb(flash, *src++, dst++);␊ |
| 97 | ␊ |
| 98 | ␉␉/* wait for Toggle bit ready */␊ |
| 99 | ␉␉toggle_ready_jedec(flash, bios);␊ |
| 100 | ␉}␊ |
| 101 | ␊ |
| 102 | ␉return 0;␊ |
| 103 | }␊ |
| 104 | ␊ |
| 105 | static int erase_28sf040(struct flashctx *flash)␊ |
| 106 | {␊ |
| 107 | ␉chipaddr bios = flash->virtual_memory;␊ |
| 108 | ␊ |
| 109 | ␉chip_writeb(flash, CHIP_ERASE, bios);␊ |
| 110 | ␉chip_writeb(flash, CHIP_ERASE, bios);␊ |
| 111 | ␊ |
| 112 | ␉programmer_delay(10);␊ |
| 113 | ␉toggle_ready_jedec(flash, bios);␊ |
| 114 | ␊ |
| 115 | ␉/* FIXME: Check the status register for errors. */␊ |
| 116 | ␉return 0;␊ |
| 117 | }␊ |
| 118 | ␊ |
| 119 | int erase_chip_28sf040(struct flashctx *flash, unsigned int addr,␊ |
| 120 | ␉␉ unsigned int blocklen)␊ |
| 121 | {␊ |
| 122 | ␉if ((addr != 0) || (blocklen != flash->total_size * 1024)) {␊ |
| 123 | ␉␉msg_cerr("%s called with incorrect arguments\n",␊ |
| 124 | ␉␉␉__func__);␊ |
| 125 | ␉␉return -1;␊ |
| 126 | ␉}␊ |
| 127 | ␉return erase_28sf040(flash);␊ |
| 128 | }␊ |
| 129 | |