Add support for ST M25P80 chips to flashrom. Detection was tested.
[coreboot.git] / util / flashrom / flash.h
1 /*
2  * This file is part of the flashrom project.
3  *
4  * Copyright (C) 2000 Silicon Integrated System Corporation
5  * Copyright (C) 2000 Ronald G. Minnich <rminnich@gmail.com>
6  * Copyright (C) 2005-2007 coresystems GmbH <stepan@coresystems.de>
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 #ifndef __FLASH_H__
24 #define __FLASH_H__ 1
25
26 #if defined(__GLIBC__)
27 #include <sys/io.h>
28 #endif
29 #include <unistd.h>
30 #include <stdint.h>
31 #include <stdio.h>
32
33 struct flashchip {
34         const char *name;
35         int manufacture_id;
36         int model_id;
37
38         int total_size;
39         int page_size;
40
41         int (*probe) (struct flashchip *flash);
42         int (*erase) (struct flashchip *flash);
43         int (*write) (struct flashchip *flash, uint8_t *buf);
44         int (*read) (struct flashchip *flash, uint8_t *buf);
45
46         /* Some flash devices have an additional register space. */
47         volatile uint8_t *virtual_memory;
48         volatile uint8_t *virtual_registers;
49 };
50
51 extern struct flashchip flashchips[];
52
53 /*
54  * Please keep this list sorted alphabetically by manufacturer. The first
55  * entry of each section should be the manufacturer ID, followed by the
56  * list of devices from that manufacturer (sorted by device IDs).
57  *
58  * All LPC/FWH parts (parallel flash) have 8-bit device IDs.
59  * All SPI parts have 16-bit device IDs.
60  */
61
62 #define ALLIANCE_ID             0x52    /* Alliance */
63
64 #define AMD_ID                  0x01    /* AMD */
65 #define AM_29F040B              0xA4
66 #define AM_29LV040B             0x4F
67 #define AM_29F016D              0xAD
68
69 #define AMIC_ID                 0x37    /* AMIC */
70
71 #define ASD_ID                  0x25    /* ASD */
72 #define ASD_AE49F2008           0x52
73
74 #define ATMEL_ID                0x1F    /* Atmel */
75 #define AT_29C040A              0xA4
76 #define AT_29C020               0xDA
77 #define AT_49F002N              0x07    /* for AT49F002(N)  */
78 #define AT_49F002NT             0x08    /* for AT49F002(N)T */
79
80 #define CATALYST_ID             0x31    /* Catalyst */
81
82 #define EMST_ID                 0x8C    /* EMST / EFST */
83 #define EMST_F49B002UA          0x00
84
85 /*
86  * EN25 chips are SPI, first byte of device ID is memory type,
87  * second byte of device ID is log(bitsize)-9.
88  */
89 #define EON_ID                  0x1C    /* EON */
90 #define EN_25B05                0x2010  /* 2^19 kbit or 2^16 kByte */
91 #define EN_25B10                0x2011
92 #define EN_25B20                0x2012
93 #define EN_25B40                0x2013
94 #define EN_25B80                0x2014
95 #define EN_25B16                0x2015
96 #define EN_25B32                0x2016
97
98 #define FUJITSU_ID              0x04    /* Fujitsu */
99 #define MBM29F400TC             0x23
100
101 #define HYUNDAI_ID              0xAD    /* Hyundai */
102
103 #define IMT_ID                  0x7F    /* IMT */
104
105 #define INTEL_ID                0x89    /* Intel */
106
107 #define ISSI_ID                 0xD5    /* ISSI */
108
109 #define MSYSTEMS_ID             0x156F  /* M-Systems */
110 #define MSYSTEMS_MD2200         0xDB
111 #define MSYSTEMS_MD2800         0x30    /* hmm -- both 0x30 */
112 #define MSYSTEMS_MD2802         0x30    /* hmm -- both 0x30 */
113
114 /*
115  * MX25 chips are SPI, first byte of device ID is memory type,
116  * second byte of device ID is log(bitsize)-9.
117  */
118 #define MX_ID                   0xC2    /* Macronix (MX) */
119 #define MX_25L512               0x2010  /* 2^19 kbit or 2^16 kByte */
120 #define MX_25L1005              0x2011
121 #define MX_25L2005              0x2012
122 #define MX_25L4005              0x2013  /* MX25L4005{,A} */
123 #define MX_25L8005              0x2014
124 #define MX_25L1605              0x2015  /* MX25L1605{,A,D} */
125 #define MX_25L3205              0x2016  /* MX25L3205{,A} */
126 #define MX_25L6405              0x2017  /* MX25L3205{,D} */
127 #define MX_25L1635D             0x2415
128 #define MX_25L3235D             0x2416
129 #define MX_29F002               0xB0
130
131 #define PMC_ID                  0x9D    /* PMC */
132 #define PMC_49FL002             0x6D
133 #define PMC_49FL004             0x6E
134
135 #define SHARP_ID                0xB0    /* Sharp */
136 #define SHARP_LHF00L04          0xCF
137
138 /*
139  * SST25 chips are SPI, first byte of device ID is memory type, second
140  * byte of device ID is related to log(bitsize) at least for some chips.
141  */
142 #define SST_ID                  0xBF    /* SST */
143 #define SST_25WF512             0x2501
144 #define SST_25WF010             0x2502
145 #define SST_25WF020             0x2503
146 #define SST_25WF040             0x2504
147 #define SST_25VF016B            0x2541
148 #define SST_25VF032B            0x254A
149 #define SST_25VF040B            0x258D
150 #define SST_25VF080B            0x258E
151 #define SST_29EE020A            0x10
152 #define SST_28SF040             0x04
153 #define SST_39SF010             0xB5
154 #define SST_39SF020             0xB6
155 #define SST_39SF040             0xB7
156 #define SST_39VF020             0xD6
157 #define SST_49LF040B            0x50
158 #define SST_49LF040             0x51
159 #define SST_49LF020A            0x52
160 #define SST_49LF080A            0x5B
161 #define SST_49LF002A            0x57
162 #define SST_49LF003A            0x1B
163 #define SST_49LF004A            0x60
164 #define SST_49LF008A            0x5A
165 #define SST_49LF004C            0x54
166 #define SST_49LF008C            0x59
167 #define SST_49LF016C            0x5C
168 #define SST_49LF160C            0x4C
169
170 /*
171  * ST25P chips are SPI, first byte of device ID is memory type, second
172  * byte of device ID is related to log(bitsize) at least for some chips.
173  */
174 #define ST_ID                   0x20    /* ST */
175 #define ST_M25P80               0x2014
176 #define ST_M50FLW040A           0x08
177 #define ST_M50FLW040B           0x28
178 #define ST_M50FLW080A           0x80
179 #define ST_M50FLW080B           0x81
180 #define ST_M50FW040             0x2C
181 #define ST_M50FW080             0x2D
182 #define ST_M50FW016             0x2E
183 #define ST_M50LPW116            0x30
184 #define ST_M29F002B             0x34
185 #define ST_M29F002T             0xB0    /* M29F002T / M29F002NT */
186 #define ST_M29F400BT            0xD5
187 #define ST_M29F040B             0xE2
188 #define ST_M29W010B             0x23
189 #define ST_M29W040B             0xE3
190
191 #define SYNCMOS_ID              0x40    /* SyncMOS and Mosel Vitelic */
192 #define S29C51001T              0x01
193 #define S29C51002T              0x02
194 #define S29C51004T              0x03
195 #define S29C31004T              0x63
196
197 #define TI_ID                   0x97    /* Texas Instruments */
198
199 #define WINBOND_ID              0xDA    /* Winbond */
200 #define W_29C011                0xC1
201 #define W_29C020C               0x45
202 #define W_29C040P               0x46
203 #define W_29EE011               0xC1
204 #define W_39V040FA              0x34
205 #define W_39V040A               0x3D
206 #define W_39V040B               0x54
207 #define W_39V080A               0xD0
208 #define W_49F002U               0x0B
209 #define W_49V002A               0xB0
210 #define W_49V002FA              0x32
211
212 /* udelay.c */
213 void myusec_delay(int time);
214 void myusec_calibrate_delay();
215
216 /* PCI handling for board/chipset_enable */
217 struct pci_access *pacc;
218 struct pci_dev *pci_dev_find(uint16_t vendor, uint16_t device);
219 struct pci_dev *pci_card_find(uint16_t vendor, uint16_t device,
220                               uint16_t card_vendor, uint16_t card_device);
221
222 /* board_enable.c */
223 int board_flash_enable(const char *vendor, const char *part);
224
225 /* chipset_enable.c */
226 int chipset_flash_enable(void);
227
228 /* Physical memory mapping device */
229 #if defined (__sun) && (defined(__i386) || defined(__amd64))
230 #  define MEM_DEV "/dev/xsvc"
231 #else
232 #  define MEM_DEV "/dev/mem"
233 #endif
234
235 extern int fd_mem;
236
237 /* debug.c */
238 extern int verbose;
239 #define printf_debug(x...) { if (verbose) printf(x); }
240
241 /* flashrom.c */
242 int map_flash_registers(struct flashchip *flash);
243
244 /* layout.c */
245 int show_id(uint8_t *bios, int size);
246 int read_romlayout(char *name);
247 int find_romentry(char *name);
248 int handle_romentries(uint8_t *buffer, uint8_t *content);
249
250 /* lbtable.c */
251 int linuxbios_init(void);
252 extern char *lb_part, *lb_vendor;
253
254 /* spi.c */
255 int probe_spi(struct flashchip *flash);
256 int it87xx_probe_spi_flash(const char *name);
257 int generic_spi_command(unsigned int writecnt, unsigned int readcnt, const unsigned char *writearr, unsigned char *readarr);
258 void generic_spi_write_enable();
259 void generic_spi_write_disable();
260 int generic_spi_chip_erase(struct flashchip *flash);
261 int generic_spi_chip_write(struct flashchip *flash, uint8_t *buf);
262
263 /* 82802ab.c */
264 int probe_82802ab(struct flashchip *flash);
265 int erase_82802ab(struct flashchip *flash);
266 int write_82802ab(struct flashchip *flash, uint8_t *buf);
267
268 /* am29f040b.c */
269 int probe_29f040b(struct flashchip *flash);
270 int erase_29f040b(struct flashchip *flash);
271 int write_29f040b(struct flashchip *flash, uint8_t *buf);
272
273 /* jedec.c */
274 void toggle_ready_jedec(volatile uint8_t *dst);
275 void data_polling_jedec(volatile uint8_t *dst, uint8_t data);
276 void unprotect_jedec(volatile uint8_t *bios);
277 void protect_jedec(volatile uint8_t *bios);
278 int write_byte_program_jedec(volatile uint8_t *bios, uint8_t *src,
279                              volatile uint8_t *dst);
280 int probe_jedec(struct flashchip *flash);
281 int erase_chip_jedec(struct flashchip *flash);
282 int write_jedec(struct flashchip *flash, uint8_t *buf);
283 int erase_sector_jedec(volatile uint8_t *bios, unsigned int page);
284 int erase_block_jedec(volatile uint8_t *bios, unsigned int page);
285 int write_sector_jedec(volatile uint8_t *bios, uint8_t *src,
286                        volatile uint8_t *dst, unsigned int page_size);
287
288 /* m29f400bt.c */
289 int probe_m29f400bt(struct flashchip *flash);
290 int erase_m29f400bt(struct flashchip *flash);
291 int block_erase_m29f400bt(volatile uint8_t *bios,
292                                  volatile uint8_t *dst);
293 int write_m29f400bt(struct flashchip *flash, uint8_t *buf);
294 int write_linuxbios_m29f400bt(struct flashchip *flash, uint8_t *buf);
295 void toggle_ready_m29f400bt(volatile uint8_t *dst);
296 void data_polling_m29f400bt(volatile uint8_t *dst, uint8_t data);
297 void protect_m29f400bt(volatile uint8_t *bios);
298 void write_page_m29f400bt(volatile uint8_t *bios, uint8_t *src,
299                           volatile uint8_t *dst, int page_size);
300
301 /* mx29f002.c */
302 int probe_29f002(struct flashchip *flash);
303 int erase_29f002(struct flashchip *flash);
304 int write_29f002(struct flashchip *flash, uint8_t *buf);
305
306 /* pm49fl004.c */
307 int probe_49fl004(struct flashchip *flash);
308 int erase_49fl004(struct flashchip *flash);
309 int write_49fl004(struct flashchip *flash, uint8_t *buf);
310
311 /* sharplhf00l04.c */
312 int probe_lhf00l04(struct flashchip *flash);
313 int erase_lhf00l04(struct flashchip *flash);
314 int write_lhf00l04(struct flashchip *flash, uint8_t *buf);
315 void toggle_ready_lhf00l04(volatile uint8_t *dst);
316 void data_polling_lhf00l04(volatile uint8_t *dst, uint8_t data);
317 void protect_lhf00l04(volatile uint8_t *bios);
318
319 /* sst28sf040.c */
320 int probe_28sf040(struct flashchip *flash);
321 int erase_28sf040(struct flashchip *flash);
322 int write_28sf040(struct flashchip *flash, uint8_t *buf);
323
324 /* sst39sf020.c */
325 int probe_39sf020(struct flashchip *flash);
326 int write_39sf020(struct flashchip *flash, uint8_t *buf);
327
328 /* sst49lf040.c */
329 int erase_49lf040(struct flashchip *flash);
330 int write_49lf040(struct flashchip *flash, uint8_t *buf);
331
332 /* sst49lfxxxc.c */
333 int probe_49lfxxxc(struct flashchip *flash);
334 int erase_49lfxxxc(struct flashchip *flash);
335 int write_49lfxxxc(struct flashchip *flash, uint8_t *buf);
336
337 /* sst_fwhub.c */
338 int probe_sst_fwhub(struct flashchip *flash);
339 int erase_sst_fwhub(struct flashchip *flash);
340 int write_sst_fwhub(struct flashchip *flash, uint8_t *buf);
341
342 /* w29ee011.c */
343 int probe_w29ee011(struct flashchip *flash);
344
345 /* w49f002u.c */
346 int write_49f002(struct flashchip *flash, uint8_t *buf);
347
348 #endif                          /* !__FLASH_H__ */