rminnich | 8d3ff91 | 2003-10-25 17:01:29 +0000 | [diff] [blame] | 1 | /* |
uwe | b25f1ea | 2007-08-29 17:52:32 +0000 | [diff] [blame] | 2 | * This file is part of the flashrom project. |
rminnich | 8d3ff91 | 2003-10-25 17:01:29 +0000 | [diff] [blame] | 3 | * |
uwe | 555dd97 | 2007-09-09 20:21:05 +0000 | [diff] [blame] | 4 | * Copyright (C) 2000 Silicon Integrated System Corporation |
| 5 | * Copyright (C) 2005 coresystems GmbH <stepan@openbios.org> |
snelson | 264e57c | 2010-01-20 20:55:53 +0000 | [diff] [blame] | 6 | * Copyright (C) 2009 Sean Nelson <audiohacked@gmail.com> |
rminnich | 8d3ff91 | 2003-10-25 17:01:29 +0000 | [diff] [blame] | 7 | * |
uwe | b25f1ea | 2007-08-29 17:52:32 +0000 | [diff] [blame] | 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. |
rminnich | 8d3ff91 | 2003-10-25 17:01:29 +0000 | [diff] [blame] | 12 | * |
uwe | b25f1ea | 2007-08-29 17:52:32 +0000 | [diff] [blame] | 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. |
rminnich | 8d3ff91 | 2003-10-25 17:01:29 +0000 | [diff] [blame] | 17 | */ |
| 18 | |
rminnich | 8d3ff91 | 2003-10-25 17:01:29 +0000 | [diff] [blame] | 19 | #include "flash.h" |
snelson | 8913d08 | 2010-02-26 05:48:29 +0000 | [diff] [blame] | 20 | #include "chipdrivers.h" |
rminnich | 8d3ff91 | 2003-10-25 17:01:29 +0000 | [diff] [blame] | 21 | |
| 22 | #define AUTO_PG_ERASE1 0x20 |
| 23 | #define AUTO_PG_ERASE2 0xD0 |
ollie | 4f630d5 | 2004-03-18 19:40:07 +0000 | [diff] [blame] | 24 | #define AUTO_PGRM 0x10 |
rminnich | 8d3ff91 | 2003-10-25 17:01:29 +0000 | [diff] [blame] | 25 | #define CHIP_ERASE 0x30 |
| 26 | #define RESET 0xFF |
| 27 | #define READ_ID 0x90 |
| 28 | |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 29 | int protect_28sf040(struct flashctx *flash) |
rminnich | 8d3ff91 | 2003-10-25 17:01:29 +0000 | [diff] [blame] | 30 | { |
hailfinger | a10a607 | 2010-10-10 14:02:27 +0000 | [diff] [blame] | 31 | chipaddr bios = flash->virtual_memory; |
| 32 | |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 33 | 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); |
hailfinger | 86bf3b5 | 2010-10-13 21:49:30 +0000 | [diff] [blame] | 40 | |
| 41 | return 0; |
rminnich | 8d3ff91 | 2003-10-25 17:01:29 +0000 | [diff] [blame] | 42 | } |
| 43 | |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 44 | int unprotect_28sf040(struct flashctx *flash) |
rminnich | 8d3ff91 | 2003-10-25 17:01:29 +0000 | [diff] [blame] | 45 | { |
hailfinger | a10a607 | 2010-10-10 14:02:27 +0000 | [diff] [blame] | 46 | chipaddr bios = flash->virtual_memory; |
| 47 | |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 48 | 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); |
hailfinger | 86bf3b5 | 2010-10-13 21:49:30 +0000 | [diff] [blame] | 55 | |
| 56 | return 0; |
rminnich | 8d3ff91 | 2003-10-25 17:01:29 +0000 | [diff] [blame] | 57 | } |
| 58 | |
Patrick Georgi | ab8353e | 2017-02-03 18:32:01 +0100 | [diff] [blame] | 59 | int erase_sector_28sf040(struct flashctx *flash, unsigned int address, |
| 60 | unsigned int sector_size) |
rminnich | 8d3ff91 | 2003-10-25 17:01:29 +0000 | [diff] [blame] | 61 | { |
hailfinger | 7af8369 | 2009-06-15 17:23:36 +0000 | [diff] [blame] | 62 | chipaddr bios = flash->virtual_memory; |
| 63 | |
hailfinger | 86bf3b5 | 2010-10-13 21:49:30 +0000 | [diff] [blame] | 64 | /* This command sequence is very similar to erase_block_82802ab. */ |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 65 | chip_writeb(flash, AUTO_PG_ERASE1, bios); |
| 66 | chip_writeb(flash, AUTO_PG_ERASE2, bios + address); |
rminnich | 8d3ff91 | 2003-10-25 17:01:29 +0000 | [diff] [blame] | 67 | |
hailfinger | a10a607 | 2010-10-10 14:02:27 +0000 | [diff] [blame] | 68 | /* wait for Toggle bit ready */ |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 69 | toggle_ready_jedec(flash, bios); |
rminnich | 8d3ff91 | 2003-10-25 17:01:29 +0000 | [diff] [blame] | 70 | |
hailfinger | ac8e318 | 2011-06-26 17:04:16 +0000 | [diff] [blame] | 71 | /* FIXME: Check the status register for errors. */ |
uwe | be4477b | 2007-08-23 16:08:21 +0000 | [diff] [blame] | 72 | return 0; |
rminnich | 8d3ff91 | 2003-10-25 17:01:29 +0000 | [diff] [blame] | 73 | } |
| 74 | |
hailfinger | 71e1bd4 | 2010-10-13 22:26:56 +0000 | [diff] [blame] | 75 | /* chunksize is 1 */ |
Patrick Georgi | ab8353e | 2017-02-03 18:32:01 +0100 | [diff] [blame] | 76 | int write_28sf040(struct flashctx *flash, const uint8_t *src, unsigned int start, unsigned int len) |
rminnich | 8d3ff91 | 2003-10-25 17:01:29 +0000 | [diff] [blame] | 77 | { |
Edward O'Callaghan | 6b75443 | 2019-08-02 17:14:16 +1000 | [diff] [blame] | 78 | unsigned int i; |
hailfinger | a10a607 | 2010-10-10 14:02:27 +0000 | [diff] [blame] | 79 | chipaddr bios = flash->virtual_memory; |
| 80 | chipaddr dst = flash->virtual_memory + start; |
rminnich | 8d3ff91 | 2003-10-25 17:01:29 +0000 | [diff] [blame] | 81 | |
hailfinger | a10a607 | 2010-10-10 14:02:27 +0000 | [diff] [blame] | 82 | for (i = 0; i < len; i++) { |
rminnich | 8d3ff91 | 2003-10-25 17:01:29 +0000 | [diff] [blame] | 83 | /* 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 Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 90 | chip_writeb(flash, AUTO_PGRM, dst); |
| 91 | chip_writeb(flash, *src++, dst++); |
rminnich | 8d3ff91 | 2003-10-25 17:01:29 +0000 | [diff] [blame] | 92 | |
| 93 | /* wait for Toggle bit ready */ |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 94 | toggle_ready_jedec(flash, bios); |
rminnich | 8d3ff91 | 2003-10-25 17:01:29 +0000 | [diff] [blame] | 95 | } |
| 96 | |
uwe | be4477b | 2007-08-23 16:08:21 +0000 | [diff] [blame] | 97 | return 0; |
rminnich | 8d3ff91 | 2003-10-25 17:01:29 +0000 | [diff] [blame] | 98 | } |
| 99 | |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 100 | static int erase_28sf040(struct flashctx *flash) |
rminnich | 8d3ff91 | 2003-10-25 17:01:29 +0000 | [diff] [blame] | 101 | { |
hailfinger | 8271963 | 2009-05-16 21:22:56 +0000 | [diff] [blame] | 102 | chipaddr bios = flash->virtual_memory; |
rminnich | 8d3ff91 | 2003-10-25 17:01:29 +0000 | [diff] [blame] | 103 | |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 104 | chip_writeb(flash, CHIP_ERASE, bios); |
| 105 | chip_writeb(flash, CHIP_ERASE, bios); |
rminnich | 8d3ff91 | 2003-10-25 17:01:29 +0000 | [diff] [blame] | 106 | |
hailfinger | e5829f6 | 2009-06-05 17:48:08 +0000 | [diff] [blame] | 107 | programmer_delay(10); |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 108 | toggle_ready_jedec(flash, bios); |
rminnich | 8d3ff91 | 2003-10-25 17:01:29 +0000 | [diff] [blame] | 109 | |
hailfinger | ac8e318 | 2011-06-26 17:04:16 +0000 | [diff] [blame] | 110 | /* FIXME: Check the status register for errors. */ |
uwe | be4477b | 2007-08-23 16:08:21 +0000 | [diff] [blame] | 111 | return 0; |
rminnich | 8d3ff91 | 2003-10-25 17:01:29 +0000 | [diff] [blame] | 112 | } |
| 113 | |
Patrick Georgi | ab8353e | 2017-02-03 18:32:01 +0100 | [diff] [blame] | 114 | int erase_chip_28sf040(struct flashctx *flash, unsigned int addr, |
| 115 | unsigned int blocklen) |
snelson | 264e57c | 2010-01-20 20:55:53 +0000 | [diff] [blame] | 116 | { |
Patrick Georgi | f3fa299 | 2017-02-02 16:24:44 +0100 | [diff] [blame] | 117 | if ((addr != 0) || (blocklen != flash->chip->total_size * 1024)) { |
snelson | fc007bb | 2010-03-24 23:14:32 +0000 | [diff] [blame] | 118 | msg_cerr("%s called with incorrect arguments\n", |
snelson | 264e57c | 2010-01-20 20:55:53 +0000 | [diff] [blame] | 119 | __func__); |
| 120 | return -1; |
| 121 | } |
| 122 | return erase_28sf040(flash); |
| 123 | } |