Flashrom

Flashrom Svn Source Tree

Root/trunk/sst28sf040.c

  • Property svn:keywords set to Author Date Id Revision
  • Property svn:eol-style set to native
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, uint8_t *src, unsigned int start,
81 unsigned int len)
82{
83int i;
84chipaddr bios = flash->virtual_memory;
85chipaddr dst = flash->virtual_memory + start;
86
87for (i = 0; i < len; i++) {
88/* transfer data from source to destination */
89if (*src == 0xFF) {
90dst++, src++;
91/* If the data is 0xFF, don't program it */
92continue;
93}
94/*issue AUTO PROGRAM command */
95chip_writeb(flash, AUTO_PGRM, dst);
96chip_writeb(flash, *src++, dst++);
97
98/* wait for Toggle bit ready */
99toggle_ready_jedec(flash, bios);
100}
101
102return 0;
103}
104
105static int erase_28sf040(struct flashctx *flash)
106{
107chipaddr bios = flash->virtual_memory;
108
109chip_writeb(flash, CHIP_ERASE, bios);
110chip_writeb(flash, CHIP_ERASE, bios);
111
112programmer_delay(10);
113toggle_ready_jedec(flash, bios);
114
115/* FIXME: Check the status register for errors. */
116return 0;
117}
118
119int erase_chip_28sf040(struct flashctx *flash, unsigned int addr,
120 unsigned int blocklen)
121{
122if ((addr != 0) || (blocklen != flash->total_size * 1024)) {
123msg_cerr("%s called with incorrect arguments\n",
124__func__);
125return -1;
126}
127return erase_28sf040(flash);
128}
129

Archive Download this file

Revision: HEAD