blob: 37f0628f0fdb0c9b631082955b813a4482878e3e [file] [log] [blame]
Yinghai Luca782972007-01-22 20:21:17 +00001/*
Uwe Hermannd1107642007-08-29 17:52:32 +00002 * This file is part of the flashrom project.
Yinghai Luca782972007-01-22 20:21:17 +00003 *
Uwe Hermannd22a1d42007-09-09 20:21:05 +00004 * Copyright (C) 2000 Silicon Integrated System Corporation
5 * Copyright (C) 2005-2007 coresystems GmbH
Sean Nelson51c83fb2010-01-20 20:55:53 +00006 * Copyright (C) 2009 Sean Nelson <audiohacked@gmail.com>
Yinghai Luca782972007-01-22 20:21:17 +00007 *
Uwe Hermannd1107642007-08-29 17:52:32 +00008 * 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.
Yinghai Luca782972007-01-22 20:21:17 +000012 *
Uwe Hermannd1107642007-08-29 17:52:32 +000013 * 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.
Yinghai Luca782972007-01-22 20:21:17 +000017 *
Uwe Hermannd1107642007-08-29 17:52:32 +000018 * 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
Yinghai Luca782972007-01-22 20:21:17 +000021 */
22
Yinghai Luca782972007-01-22 20:21:17 +000023#include "flash.h"
Sean Nelson14ba6682010-02-26 05:48:29 +000024#include "chipdrivers.h"
Yinghai Luca782972007-01-22 20:21:17 +000025
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +000026static int write_lockbits_block_49lfxxxc(struct flashctx *flash,
27 unsigned long address,
28 unsigned char bits)
Sean Nelson51c83fb2010-01-20 20:55:53 +000029{
30 unsigned long lock = flash->virtual_registers + address + 2;
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +000031 msg_cdbg("lockbits at address=0x%08lx is 0x%01x\n", lock,
32 chip_readb(flash, lock));
33 chip_writeb(flash, bits, lock);
Sean Nelson51c83fb2010-01-20 20:55:53 +000034
35 return 0;
36}
37
Carl-Daniel Hailfinger63fd9022011-12-14 22:25:15 +000038static int write_lockbits_49lfxxxc(struct flashctx *flash, unsigned char bits)
Yinghai Luca782972007-01-22 20:21:17 +000039{
Carl-Daniel Hailfinger500dd9d2009-06-05 13:30:49 +000040 chipaddr registers = flash->virtual_registers;
Stefan Taunerc69c9c82011-11-23 09:13:48 +000041 unsigned int i, left = flash->total_size * 1024;
Yinghai Luca782972007-01-22 20:21:17 +000042 unsigned long address;
43
Sean Nelsoned479d22010-03-24 23:14:32 +000044 msg_cdbg("\nbios=0x%08lx\n", registers);
Yinghai Luca782972007-01-22 20:21:17 +000045 for (i = 0; left > 65536; i++, left -= 65536) {
Carl-Daniel Hailfingerad3cc552010-07-03 11:02:10 +000046 write_lockbits_block_49lfxxxc(flash, i * 65536, bits);
Yinghai Luca782972007-01-22 20:21:17 +000047 }
48 address = i * 65536;
Carl-Daniel Hailfingerad3cc552010-07-03 11:02:10 +000049 write_lockbits_block_49lfxxxc(flash, address, bits);
Yinghai Luca782972007-01-22 20:21:17 +000050 address += 32768;
Carl-Daniel Hailfingerad3cc552010-07-03 11:02:10 +000051 write_lockbits_block_49lfxxxc(flash, address, bits);
Yinghai Luca782972007-01-22 20:21:17 +000052 address += 8192;
Carl-Daniel Hailfingerad3cc552010-07-03 11:02:10 +000053 write_lockbits_block_49lfxxxc(flash, address, bits);
Yinghai Luca782972007-01-22 20:21:17 +000054 address += 8192;
Carl-Daniel Hailfingerad3cc552010-07-03 11:02:10 +000055 write_lockbits_block_49lfxxxc(flash, address, bits);
Yinghai Luca782972007-01-22 20:21:17 +000056
Uwe Hermannffec5f32007-08-23 16:08:21 +000057 return 0;
Yinghai Luca782972007-01-22 20:21:17 +000058}
59
Carl-Daniel Hailfinger63fd9022011-12-14 22:25:15 +000060int unlock_49lfxxxc(struct flashctx *flash)
Sean Nelson6e0b9122010-02-19 00:52:10 +000061{
62 return write_lockbits_49lfxxxc(flash, 0);
63}
64
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +000065int erase_sector_49lfxxxc(struct flashctx *flash, unsigned int address,
66 unsigned int sector_size)
Yinghai Luca782972007-01-22 20:21:17 +000067{
Sean Nelson69e58112010-03-23 17:10:28 +000068 uint8_t status;
Carl-Daniel Hailfinger30f7cb22009-06-15 17:23:36 +000069 chipaddr bios = flash->virtual_memory;
Yinghai Luca782972007-01-22 20:21:17 +000070
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +000071 chip_writeb(flash, 0x30, bios);
72 chip_writeb(flash, 0xD0, bios + address);
Yinghai Luca782972007-01-22 20:21:17 +000073
Carl-Daniel Hailfingerb30a5ed2010-10-10 14:02:27 +000074 status = wait_82802ab(flash);
Stefan Reinauere8a648d2011-06-19 17:09:49 +000075 print_status_82802ab(status);
Yinghai Luca782972007-01-22 20:21:17 +000076
Carl-Daniel Hailfingerb4061f62011-06-26 17:04:16 +000077 /* FIXME: Check the status register for errors. */
Uwe Hermannffec5f32007-08-23 16:08:21 +000078 return 0;
Yinghai Luca782972007-01-22 20:21:17 +000079}