blob: 328d39a2ddb361d6aa03c1306d99903a4d7fff72 [file] [log] [blame]
Ronald G. Minnich1f4d6532004-09-30 16:37:01 +00001/*
Uwe Hermannd1107642007-08-29 17:52:32 +00002 * This file is part of the flashrom project.
Ronald G. Minnich1f4d6532004-09-30 16:37:01 +00003 *
Uwe Hermannd22a1d42007-09-09 20:21:05 +00004 * Copyright (C) 2000 Silicon Integrated System Corporation
Adam Jurkowski411d7c12009-11-25 15:04:28 +00005 * Copyright (C) 2009 Kontron Modular Computers
Sean Nelson51c83fb2010-01-20 20:55:53 +00006 * Copyright (C) 2009 Sean Nelson <audiohacked@gmail.com>
Ronald G. Minnich1f4d6532004-09-30 16:37:01 +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.
Ronald G. Minnich1f4d6532004-09-30 16:37:01 +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.
Ronald G. Minnich1f4d6532004-09-30 16:37:01 +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
Ronald G. Minnich1f4d6532004-09-30 16:37:01 +000021 */
22
Uwe Hermannd1107642007-08-29 17:52:32 +000023/* Adapted from the Intel FW hub stuff for 82802ax parts. */
24
Adam Jurkowski411d7c12009-11-25 15:04:28 +000025#include <stdlib.h>
26#include <string.h>
Ronald G. Minnich1f4d6532004-09-30 16:37:01 +000027#include "flash.h"
Sean Nelson14ba6682010-02-26 05:48:29 +000028#include "chipdrivers.h"
Ronald G. Minnich1f4d6532004-09-30 16:37:01 +000029
Carl-Daniel Hailfingerd0fc9462009-05-11 14:01:17 +000030int check_sst_fwhub_block_lock(struct flashchip *flash, int offset)
31{
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +000032 chipaddr registers = flash->virtual_registers;
Carl-Daniel Hailfingerd0fc9462009-05-11 14:01:17 +000033 uint8_t blockstatus;
34
35 blockstatus = chip_readb(registers + offset + 2);
36 printf_debug("Lock status for 0x%06x (size 0x%06x) is %02x, ",
37 offset, flash->page_size, blockstatus);
38 switch (blockstatus & 0x3) {
39 case 0x0:
40 printf_debug("full access\n");
41 break;
42 case 0x1:
43 printf_debug("write locked\n");
44 break;
45 case 0x2:
46 printf_debug("locked open\n");
47 break;
48 case 0x3:
49 printf_debug("write locked down\n");
50 break;
51 }
52 /* Return content of the write_locked bit */
53 return blockstatus & 0x1;
54}
55
56int clear_sst_fwhub_block_lock(struct flashchip *flash, int offset)
57{
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +000058 chipaddr registers = flash->virtual_registers;
Carl-Daniel Hailfingerd0fc9462009-05-11 14:01:17 +000059 uint8_t blockstatus;
60
61 blockstatus = check_sst_fwhub_block_lock(flash, offset);
62
63 if (blockstatus) {
64 printf_debug("Trying to clear lock for 0x%06x... ", offset)
65 chip_writeb(0, registers + offset + 2);
66
67 blockstatus = check_sst_fwhub_block_lock(flash, offset);
68 printf_debug("%s\n", (blockstatus) ? "failed" : "OK");
69 }
70
71 return blockstatus;
72}
73
Carl-Daniel Hailfinger81449a22010-03-15 03:48:42 +000074int printlock_sst_fwhub(struct flashchip *flash)
Ronald G. Minnich1f4d6532004-09-30 16:37:01 +000075{
Carl-Daniel Hailfingerd0fc9462009-05-11 14:01:17 +000076 int i;
77
Carl-Daniel Hailfingerd0fc9462009-05-11 14:01:17 +000078 for (i = 0; i < flash->total_size * 1024; i += flash->page_size)
79 check_sst_fwhub_block_lock(flash, i);
80
Carl-Daniel Hailfinger81449a22010-03-15 03:48:42 +000081 return 0;
Ronald G. Minnich1f4d6532004-09-30 16:37:01 +000082}
83
Sean Nelsonccf7a2a2010-03-16 03:09:10 +000084int unlock_sst_fwhub(struct flashchip *flash)
Ronald G. Minnich1f4d6532004-09-30 16:37:01 +000085{
Sean Nelsonccf7a2a2010-03-16 03:09:10 +000086 int i, ret=0;
Ronald G. Minnich1f4d6532004-09-30 16:37:01 +000087
Sean Nelsonccf7a2a2010-03-16 03:09:10 +000088 for (i = 0; i < flash->total_size * 1024; i += flash->page_size)
89 {
90 if (clear_sst_fwhub_block_lock(flash, i))
91 {
92 msg_cdbg("Warning: Unlock Failed for block 0x%06x\n", i);
93 ret++;
Stefan Reinauerb7c83232008-03-16 19:44:13 +000094 }
95 }
Sean Nelsonccf7a2a2010-03-16 03:09:10 +000096 return ret;
Ronald G. Minnich1f4d6532004-09-30 16:37:01 +000097}
98