flashrom 

flashrom Svn Source Tree

Root/trunk/sst28sf040.c

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
1/*
2 * This file is part of the flashrom project.
3 *
4 * Copyright (C) 2000 Silicon Integrated System Corporation
5 * Copyright (C) 2005 coresystems GmbH <stepan@openbios.org>
6 * Copyright (C) 2009 Sean Nelson <audiohacked@gmail.com>
7 *
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.
12 *
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.
17 *
18 * 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
21 */
22
23#include "flash.h"
24#include "chipdrivers.h"
25
26#define AUTO_PG_ERASE10x20
27#define AUTO_PG_ERASE20xD0
28#define AUTO_PGRM0x10
29#define CHIP_ERASE0x30
30#define RESET0xFF
31#define READ_ID0x90
32
33int protect_28sf040(struct flashctx *flash)
34{
35chipaddr bios = flash->virtual_memory;
36
37chip_readb(flash, bios + 0x1823);
38chip_readb(flash, bios + 0x1820);
39chip_readb(flash, bios + 0x1822);
40chip_readb(flash, bios + 0x0418);
41chip_readb(flash, bios + 0x041B);
42chip_readb(flash, bios + 0x0419);
43chip_readb(flash, bios + 0x040A);
44
45return 0;
46}
47
48int unprotect_28sf040(struct flashctx *flash)
49{
50chipaddr bios = flash->virtual_memory;
51
52chip_readb(flash, bios + 0x1823);
53chip_readb(flash, bios + 0x1820);
54chip_readb(flash, bios + 0x1822);
55chip_readb(flash, bios + 0x0418);
56chip_readb(flash, bios + 0x041B);
57chip_readb(flash, bios + 0x0419);
58chip_readb(flash, bios + 0x041A);
59
60return 0;
61}
62
63int erase_sector_28sf040(struct flashctx *flash, unsigned int address,
64 unsigned int sector_size)
65{
66chipaddr bios = flash->virtual_memory;
67
68/* This command sequence is very similar to erase_block_82802ab. */
69chip_writeb(flash, AUTO_PG_ERASE1, bios);
70chip_writeb(flash, AUTO_PG_ERASE2, bios + address);
71
72/* wait for Toggle bit ready */
73toggle_ready_jedec(flash, bios);
74
75/* FIXME: Check the status register for errors. */
76return 0;
77}
78
79/* chunksize is 1 */
80int write_28sf040(struct flashctx *flash, const uint8_t *src, unsigned int start, unsigned int len)
81{
82int i;
83chipaddr bios = flash->virtual_memory;
84chipaddr dst = flash->virtual_memory + start;
85
86for (i = 0; i < len; i++) {
87/* transfer data from source to destination */
88if (*src == 0xFF) {
89dst++, src++;
90/* If the data is 0xFF, don't program it */
91continue;
92}
93/*issue AUTO PROGRAM command */
94chip_writeb(flash, AUTO_PGRM, dst);
95chip_writeb(flash, *src++, dst++);
96
97/* wait for Toggle bit ready */
98toggle_ready_jedec(flash, bios);
99}
100
101return 0;
102}
103
104static int erase_28sf040(struct flashctx *flash)
105{
106chipaddr bios = flash->virtual_memory;
107
108chip_writeb(flash, CHIP_ERASE, bios);
109chip_writeb(flash, CHIP_ERASE, bios);
110
111programmer_delay(10);
112toggle_ready_jedec(flash, bios);
113
114/* FIXME: Check the status register for errors. */
115return 0;
116}
117
118int erase_chip_28sf040(struct flashctx *flash, unsigned int addr,
119 unsigned int blocklen)
120{
121if ((addr != 0) || (blocklen != flash->chip->total_size * 1024)) {
122msg_cerr("%s called with incorrect arguments\n",
123__func__);
124return -1;
125}
126return erase_28sf040(flash);
127}

Archive Download this file

Revision: HEAD