blob: 3da25f127f10df3de1e352810e93c68b827d1650 [file] [log] [blame]
rminnich8d3ff912003-10-25 17:01:29 +00001/*
uweb25f1ea2007-08-29 17:52:32 +00002 * This file is part of the flashrom project.
rminnich8d3ff912003-10-25 17:01:29 +00003 *
uwe555dd972007-09-09 20:21:05 +00004 * Copyright (C) 2000 Silicon Integrated System Corporation
5 * Copyright (C) 2005 coresystems GmbH <stepan@openbios.org>
snelson264e57c2010-01-20 20:55:53 +00006 * Copyright (C) 2009 Sean Nelson <audiohacked@gmail.com>
rminnich8d3ff912003-10-25 17:01:29 +00007 *
uweb25f1ea2007-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.
rminnich8d3ff912003-10-25 17:01:29 +000012 *
uweb25f1ea2007-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.
rminnich8d3ff912003-10-25 17:01:29 +000017 */
18
rminnich8d3ff912003-10-25 17:01:29 +000019#include "flash.h"
snelson8913d082010-02-26 05:48:29 +000020#include "chipdrivers.h"
rminnich8d3ff912003-10-25 17:01:29 +000021
22#define AUTO_PG_ERASE1 0x20
23#define AUTO_PG_ERASE2 0xD0
ollie4f630d52004-03-18 19:40:07 +000024#define AUTO_PGRM 0x10
rminnich8d3ff912003-10-25 17:01:29 +000025#define CHIP_ERASE 0x30
26#define RESET 0xFF
27#define READ_ID 0x90
28
Souvik Ghoshd75cd672016-06-17 14:21:39 -070029int protect_28sf040(struct flashctx *flash)
rminnich8d3ff912003-10-25 17:01:29 +000030{
hailfingera10a6072010-10-10 14:02:27 +000031 chipaddr bios = flash->virtual_memory;
32
Souvik Ghoshd75cd672016-06-17 14:21:39 -070033 chip_readb(flash, bios + 0x1823);
34 chip_readb(flash, bios + 0x1820);
35 chip_readb(flash, bios + 0x1822);
36 chip_readb(flash, bios + 0x0418);
37 chip_readb(flash, bios + 0x041B);
38 chip_readb(flash, bios + 0x0419);
39 chip_readb(flash, bios + 0x040A);
hailfinger86bf3b52010-10-13 21:49:30 +000040
41 return 0;
rminnich8d3ff912003-10-25 17:01:29 +000042}
43
Souvik Ghoshd75cd672016-06-17 14:21:39 -070044int unprotect_28sf040(struct flashctx *flash)
rminnich8d3ff912003-10-25 17:01:29 +000045{
hailfingera10a6072010-10-10 14:02:27 +000046 chipaddr bios = flash->virtual_memory;
47
Souvik Ghoshd75cd672016-06-17 14:21:39 -070048 chip_readb(flash, bios + 0x1823);
49 chip_readb(flash, bios + 0x1820);
50 chip_readb(flash, bios + 0x1822);
51 chip_readb(flash, bios + 0x0418);
52 chip_readb(flash, bios + 0x041B);
53 chip_readb(flash, bios + 0x0419);
54 chip_readb(flash, bios + 0x041A);
hailfinger86bf3b52010-10-13 21:49:30 +000055
56 return 0;
rminnich8d3ff912003-10-25 17:01:29 +000057}
58
Patrick Georgiab8353e2017-02-03 18:32:01 +010059int erase_sector_28sf040(struct flashctx *flash, unsigned int address,
60 unsigned int sector_size)
rminnich8d3ff912003-10-25 17:01:29 +000061{
hailfinger7af83692009-06-15 17:23:36 +000062 chipaddr bios = flash->virtual_memory;
63
hailfinger86bf3b52010-10-13 21:49:30 +000064 /* This command sequence is very similar to erase_block_82802ab. */
Souvik Ghoshd75cd672016-06-17 14:21:39 -070065 chip_writeb(flash, AUTO_PG_ERASE1, bios);
66 chip_writeb(flash, AUTO_PG_ERASE2, bios + address);
rminnich8d3ff912003-10-25 17:01:29 +000067
hailfingera10a6072010-10-10 14:02:27 +000068 /* wait for Toggle bit ready */
Souvik Ghoshd75cd672016-06-17 14:21:39 -070069 toggle_ready_jedec(flash, bios);
rminnich8d3ff912003-10-25 17:01:29 +000070
hailfingerac8e3182011-06-26 17:04:16 +000071 /* FIXME: Check the status register for errors. */
uwebe4477b2007-08-23 16:08:21 +000072 return 0;
rminnich8d3ff912003-10-25 17:01:29 +000073}
74
hailfinger71e1bd42010-10-13 22:26:56 +000075/* chunksize is 1 */
Patrick Georgiab8353e2017-02-03 18:32:01 +010076int write_28sf040(struct flashctx *flash, const uint8_t *src, unsigned int start, unsigned int len)
rminnich8d3ff912003-10-25 17:01:29 +000077{
Edward O'Callaghan6b754432019-08-02 17:14:16 +100078 unsigned int i;
hailfingera10a6072010-10-10 14:02:27 +000079 chipaddr bios = flash->virtual_memory;
80 chipaddr dst = flash->virtual_memory + start;
rminnich8d3ff912003-10-25 17:01:29 +000081
hailfingera10a6072010-10-10 14:02:27 +000082 for (i = 0; i < len; i++) {
rminnich8d3ff912003-10-25 17:01:29 +000083 /* transfer data from source to destination */
84 if (*src == 0xFF) {
85 dst++, src++;
86 /* If the data is 0xFF, don't program it */
87 continue;
88 }
89 /*issue AUTO PROGRAM command */
Souvik Ghoshd75cd672016-06-17 14:21:39 -070090 chip_writeb(flash, AUTO_PGRM, dst);
91 chip_writeb(flash, *src++, dst++);
rminnich8d3ff912003-10-25 17:01:29 +000092
93 /* wait for Toggle bit ready */
Souvik Ghoshd75cd672016-06-17 14:21:39 -070094 toggle_ready_jedec(flash, bios);
rminnich8d3ff912003-10-25 17:01:29 +000095 }
96
uwebe4477b2007-08-23 16:08:21 +000097 return 0;
rminnich8d3ff912003-10-25 17:01:29 +000098}
99
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700100static int erase_28sf040(struct flashctx *flash)
rminnich8d3ff912003-10-25 17:01:29 +0000101{
hailfinger82719632009-05-16 21:22:56 +0000102 chipaddr bios = flash->virtual_memory;
rminnich8d3ff912003-10-25 17:01:29 +0000103
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700104 chip_writeb(flash, CHIP_ERASE, bios);
105 chip_writeb(flash, CHIP_ERASE, bios);
rminnich8d3ff912003-10-25 17:01:29 +0000106
hailfingere5829f62009-06-05 17:48:08 +0000107 programmer_delay(10);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700108 toggle_ready_jedec(flash, bios);
rminnich8d3ff912003-10-25 17:01:29 +0000109
hailfingerac8e3182011-06-26 17:04:16 +0000110 /* FIXME: Check the status register for errors. */
uwebe4477b2007-08-23 16:08:21 +0000111 return 0;
rminnich8d3ff912003-10-25 17:01:29 +0000112}
113
Patrick Georgiab8353e2017-02-03 18:32:01 +0100114int erase_chip_28sf040(struct flashctx *flash, unsigned int addr,
115 unsigned int blocklen)
snelson264e57c2010-01-20 20:55:53 +0000116{
Patrick Georgif3fa2992017-02-02 16:24:44 +0100117 if ((addr != 0) || (blocklen != flash->chip->total_size * 1024)) {
snelsonfc007bb2010-03-24 23:14:32 +0000118 msg_cerr("%s called with incorrect arguments\n",
snelson264e57c2010-01-20 20:55:53 +0000119 __func__);
120 return -1;
121 }
122 return erase_28sf040(flash);
123}