| 1 | /* |
|---|
| 2 | * This file is part of the flashrom project. |
|---|
| 3 | * |
|---|
| 4 | * Copyright (C) 2000 Silicon Integrated System Corporation |
|---|
| 5 | * Copyright (C) 2005-2007 coresystems GmbH |
|---|
| 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 | static int write_lockbits_block_49lfxxxc(struct flashctx *flash, |
|---|
| 27 | unsigned long address, |
|---|
| 28 | unsigned char bits) |
|---|
| 29 | { |
|---|
| 30 | unsigned long lock = flash->virtual_registers + address + 2; |
|---|
| 31 | msg_cdbg("lockbits at address=0x%08lx is 0x%01x\n", lock, |
|---|
| 32 | chip_readb(flash, lock)); |
|---|
| 33 | chip_writeb(flash, bits, lock); |
|---|
| 34 | |
|---|
| 35 | return 0; |
|---|
| 36 | } |
|---|
| 37 | |
|---|
| 38 | static int write_lockbits_49lfxxxc(struct flashctx *flash, unsigned char bits) |
|---|
| 39 | { |
|---|
| 40 | chipaddr registers = flash->virtual_registers; |
|---|
| 41 | unsigned int i, left = flash->chip->total_size * 1024; |
|---|
| 42 | unsigned long address; |
|---|
| 43 | |
|---|
| 44 | msg_cdbg("\nbios=0x%08lx\n", registers); |
|---|
| 45 | for (i = 0; left > 65536; i++, left -= 65536) { |
|---|
| 46 | write_lockbits_block_49lfxxxc(flash, i * 65536, bits); |
|---|
| 47 | } |
|---|
| 48 | address = i * 65536; |
|---|
| 49 | write_lockbits_block_49lfxxxc(flash, address, bits); |
|---|
| 50 | address += 32768; |
|---|
| 51 | write_lockbits_block_49lfxxxc(flash, address, bits); |
|---|
| 52 | address += 8192; |
|---|
| 53 | write_lockbits_block_49lfxxxc(flash, address, bits); |
|---|
| 54 | address += 8192; |
|---|
| 55 | write_lockbits_block_49lfxxxc(flash, address, bits); |
|---|
| 56 | |
|---|
| 57 | return 0; |
|---|
| 58 | } |
|---|
| 59 | |
|---|
| 60 | int unlock_49lfxxxc(struct flashctx *flash) |
|---|
| 61 | { |
|---|
| 62 | return write_lockbits_49lfxxxc(flash, 0); |
|---|
| 63 | } |
|---|
| 64 | |
|---|
| 65 | int erase_sector_49lfxxxc(struct flashctx *flash, unsigned int address, |
|---|
| 66 | unsigned int sector_size) |
|---|
| 67 | { |
|---|
| 68 | uint8_t status; |
|---|
| 69 | chipaddr bios = flash->virtual_memory; |
|---|
| 70 | |
|---|
| 71 | chip_writeb(flash, 0x30, bios); |
|---|
| 72 | chip_writeb(flash, 0xD0, bios + address); |
|---|
| 73 | |
|---|
| 74 | status = wait_82802ab(flash); |
|---|
| 75 | print_status_82802ab(status); |
|---|
| 76 | |
|---|
| 77 | /* FIXME: Check the status register for errors. */ |
|---|
| 78 | return 0; |
|---|
| 79 | } |
|---|