blob: 0fbf098ea6fa7d9a4c07510d04c337d720bde5de [file] [log] [blame]
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +00001/*
Uwe Hermannd1107642007-08-29 17:52:32 +00002 * This file is part of the flashrom project.
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +00003 *
Uwe Hermannd22a1d42007-09-09 20:21:05 +00004 * Copyright (C) 2000 Silicon Integrated System Corporation
5 * Copyright (C) 2005 coresystems GmbH <stepan@openbios.org>
Sean Nelson51c83fb2010-01-20 20:55:53 +00006 * Copyright (C) 2009 Sean Nelson <audiohacked@gmail.com>
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +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. Minnich5e5f75e2002-01-29 18:21:41 +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. Minnich5e5f75e2002-01-29 18:21:41 +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. Minnich5e5f75e2002-01-29 18:21:41 +000021 */
22
23#include "flash.h"
Sean Nelson14ba6682010-02-26 05:48:29 +000024#include "chipdrivers.h"
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000025
26#define AUTO_PG_ERASE1 0x20
27#define AUTO_PG_ERASE2 0xD0
Ollie Lhocf29de82004-03-18 19:40:07 +000028#define AUTO_PGRM 0x10
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000029#define CHIP_ERASE 0x30
30#define RESET 0xFF
31#define READ_ID 0x90
32
Carl-Daniel Hailfinger79e67572010-10-13 21:49:30 +000033int protect_28sf040(struct flashchip *flash)
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000034{
Carl-Daniel Hailfingerb30a5ed2010-10-10 14:02:27 +000035 chipaddr bios = flash->virtual_memory;
36
Stefan Reinauer9e72aa52009-09-16 08:18:08 +000037 chip_readb(bios + 0x1823);
38 chip_readb(bios + 0x1820);
39 chip_readb(bios + 0x1822);
40 chip_readb(bios + 0x0418);
41 chip_readb(bios + 0x041B);
42 chip_readb(bios + 0x0419);
43 chip_readb(bios + 0x040A);
Carl-Daniel Hailfinger79e67572010-10-13 21:49:30 +000044
45 return 0;
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000046}
47
Carl-Daniel Hailfinger79e67572010-10-13 21:49:30 +000048int unprotect_28sf040(struct flashchip *flash)
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000049{
Carl-Daniel Hailfingerb30a5ed2010-10-10 14:02:27 +000050 chipaddr bios = flash->virtual_memory;
51
Stefan Reinauer9e72aa52009-09-16 08:18:08 +000052 chip_readb(bios + 0x1823);
53 chip_readb(bios + 0x1820);
54 chip_readb(bios + 0x1822);
55 chip_readb(bios + 0x0418);
56 chip_readb(bios + 0x041B);
57 chip_readb(bios + 0x0419);
58 chip_readb(bios + 0x041A);
Carl-Daniel Hailfinger79e67572010-10-13 21:49:30 +000059
60 return 0;
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000061}
62
Sean Nelson51c83fb2010-01-20 20:55:53 +000063int erase_sector_28sf040(struct flashchip *flash, unsigned int address, unsigned int sector_size)
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000064{
Carl-Daniel Hailfinger30f7cb22009-06-15 17:23:36 +000065 chipaddr bios = flash->virtual_memory;
66
Carl-Daniel Hailfinger79e67572010-10-13 21:49:30 +000067 /* This command sequence is very similar to erase_block_82802ab. */
Carl-Daniel Hailfinger0472f3d2009-03-06 22:26:00 +000068 chip_writeb(AUTO_PG_ERASE1, bios);
69 chip_writeb(AUTO_PG_ERASE2, bios + address);
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000070
Carl-Daniel Hailfingerb30a5ed2010-10-10 14:02:27 +000071 /* wait for Toggle bit ready */
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000072 toggle_ready_jedec(bios);
Ronald G. Minnicheaab50b2003-09-12 22:41:53 +000073
Carl-Daniel Hailfinger30f7cb22009-06-15 17:23:36 +000074 if (check_erased_range(flash, address, sector_size)) {
Sean Nelsoned479d22010-03-24 23:14:32 +000075 msg_cerr("ERASE FAILED!\n");
Carl-Daniel Hailfinger30f7cb22009-06-15 17:23:36 +000076 return -1;
77 }
Uwe Hermannffec5f32007-08-23 16:08:21 +000078 return 0;
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000079}
80
Carl-Daniel Hailfinger75a58f92010-10-13 22:26:56 +000081/* chunksize is 1 */
82int write_28sf040(struct flashchip *flash, uint8_t *src, int start, int len)
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000083{
84 int i;
Carl-Daniel Hailfingerb30a5ed2010-10-10 14:02:27 +000085 chipaddr bios = flash->virtual_memory;
86 chipaddr dst = flash->virtual_memory + start;
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000087
Carl-Daniel Hailfingerb30a5ed2010-10-10 14:02:27 +000088 for (i = 0; i < len; i++) {
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000089 /* transfer data from source to destination */
90 if (*src == 0xFF) {
91 dst++, src++;
92 /* If the data is 0xFF, don't program it */
93 continue;
94 }
95 /*issue AUTO PROGRAM command */
Carl-Daniel Hailfinger0472f3d2009-03-06 22:26:00 +000096 chip_writeb(AUTO_PGRM, dst);
97 chip_writeb(*src++, dst++);
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000098
99 /* wait for Toggle bit ready */
100 toggle_ready_jedec(bios);
101 }
Ronald G. Minnicheaab50b2003-09-12 22:41:53 +0000102
Uwe Hermannffec5f32007-08-23 16:08:21 +0000103 return 0;
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +0000104}
105
Carl-Daniel Hailfingerad3cc552010-07-03 11:02:10 +0000106static int erase_28sf040(struct flashchip *flash)
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +0000107{
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +0000108 chipaddr bios = flash->virtual_memory;
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +0000109
Carl-Daniel Hailfinger0472f3d2009-03-06 22:26:00 +0000110 chip_writeb(CHIP_ERASE, bios);
111 chip_writeb(CHIP_ERASE, bios);
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +0000112
Carl-Daniel Hailfingerca8bfc62009-06-05 17:48:08 +0000113 programmer_delay(10);
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +0000114 toggle_ready_jedec(bios);
Ronald G. Minnicheaab50b2003-09-12 22:41:53 +0000115
Carl-Daniel Hailfinger30f7cb22009-06-15 17:23:36 +0000116 if (check_erased_range(flash, 0, flash->total_size * 1024)) {
Sean Nelsoned479d22010-03-24 23:14:32 +0000117 msg_cerr("ERASE FAILED!\n");
Carl-Daniel Hailfinger30f7cb22009-06-15 17:23:36 +0000118 return -1;
119 }
Uwe Hermannffec5f32007-08-23 16:08:21 +0000120 return 0;
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +0000121}
122
Sean Nelson51c83fb2010-01-20 20:55:53 +0000123int erase_chip_28sf040(struct flashchip *flash, unsigned int addr, unsigned int blocklen)
124{
125 if ((addr != 0) || (blocklen != flash->total_size * 1024)) {
Sean Nelsoned479d22010-03-24 23:14:32 +0000126 msg_cerr("%s called with incorrect arguments\n",
Sean Nelson51c83fb2010-01-20 20:55:53 +0000127 __func__);
128 return -1;
129 }
130 return erase_28sf040(flash);
131}