flash.h 23.2 KB
Newer Older
1
/*
2
 * This file is part of the flashrom project.
3
 *
4 5
 * Copyright (C) 2000 Silicon Integrated System Corporation
 * Copyright (C) 2000 Ronald G. Minnich <rminnich@gmail.com>
6
 * Copyright (C) 2005-2009 coresystems GmbH
7
 * Copyright (C) 2006-2009 Carl-Daniel Hailfinger
8
 *
9 10 11 12
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
13
 *
14 15 16 17
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
18
 *
19 20 21
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
22 23
 */

Ronald G. Minnich's avatar
Ronald G. Minnich committed
24 25 26
#ifndef __FLASH_H__
#define __FLASH_H__ 1

27
#if defined(__GLIBC__)
28
#include <sys/io.h>
29
#endif
30
#include <unistd.h>
31
#include <stdint.h>
32
#include <stdio.h>
33
#include <pci/pci.h>
34

35 36 37 38 39 40 41 42
/* for iopl and outb under Solaris */
#if defined (__sun) && (defined(__i386) || defined(__amd64))
#include <strings.h>
#include <sys/sysi86.h>
#include <sys/psw.h>
#include <asm/sunddi.h>
#endif

Stefan Reinauer's avatar
Stefan Reinauer committed
43 44 45 46
#if (defined(__MACH__) && defined(__APPLE__))
#define __DARWIN__
#endif

47
#if defined(__FreeBSD__) || defined(__DragonFly__)
48 49 50 51 52 53 54 55 56 57
  #include <machine/cpufunc.h>
  #define off64_t off_t
  #define lseek64 lseek
  #define OUTB(x, y) do { u_int tmp = (y); outb(tmp, (x)); } while (0)
  #define OUTW(x, y) do { u_int tmp = (y); outw(tmp, (x)); } while (0)
  #define OUTL(x, y) do { u_int tmp = (y); outl(tmp, (x)); } while (0)
  #define INB(x) __extension__ ({ u_int tmp = (x); inb(tmp); })
  #define INW(x) __extension__ ({ u_int tmp = (x); inw(tmp); })
  #define INL(x) __extension__ ({ u_int tmp = (x); inl(tmp); })
#else
Stefan Reinauer's avatar
Stefan Reinauer committed
58 59 60 61 62
#if defined(__DARWIN__)
    #include <DirectIO/darwinio.h>
    #define off64_t off_t
    #define lseek64 lseek
#endif
63 64 65 66 67 68 69 70 71
#if defined (__sun) && (defined(__i386) || defined(__amd64))
  /* Note different order for outb */
  #define OUTB(x,y) outb(y, x)
  #define OUTW(x,y) outw(y, x)
  #define OUTL(x,y) outl(y, x)
  #define INB  inb
  #define INW  inw
  #define INL  inl
#else
72 73 74 75 76 77 78
  #define OUTB outb
  #define OUTW outw
  #define OUTL outl
  #define INB  inb
  #define INW  inw
  #define INL  inl
#endif
79
#endif
80

81 82
typedef unsigned long chipaddr;

83 84
enum programmer {
	PROGRAMMER_INTERNAL,
85
#if DUMMY_SUPPORT == 1
86
	PROGRAMMER_DUMMY,
87 88
#endif
#if NIC3COM_SUPPORT == 1
89
	PROGRAMMER_NIC3COM,
90 91
#endif
#if DRKAISER_SUPPORT == 1
92
	PROGRAMMER_DRKAISER,
93 94
#endif
#if SATASII_SUPPORT == 1
95
	PROGRAMMER_SATASII,
96
#endif
97
	PROGRAMMER_IT87SPI,
98
#if FT2232_SPI_SUPPORT == 1
99
	PROGRAMMER_FT2232SPI,
100
#endif
101
#if SERPROG_SUPPORT == 1
102
	PROGRAMMER_SERPROG,
103
#endif
104
	PROGRAMMER_INVALID /* This must always be the last entry. */
105 106 107
};

extern enum programmer programmer;
108 109 110 111 112 113 114 115

struct programmer_entry {
	const char *vendor;
	const char *name;

	int (*init) (void);
	int (*shutdown) (void);

Uwe Hermann's avatar
Uwe Hermann committed
116 117
	void * (*map_flash_region) (const char *descr, unsigned long phys_addr,
				    size_t len);
118 119
	void (*unmap_flash_region) (void *virt_addr, size_t len);

120 121 122
	void (*chip_writeb) (uint8_t val, chipaddr addr);
	void (*chip_writew) (uint16_t val, chipaddr addr);
	void (*chip_writel) (uint32_t val, chipaddr addr);
123
	void (*chip_writen) (uint8_t *buf, chipaddr addr, size_t len);
124 125 126
	uint8_t (*chip_readb) (const chipaddr addr);
	uint16_t (*chip_readw) (const chipaddr addr);
	uint32_t (*chip_readl) (const chipaddr addr);
127
	void (*chip_readn) (uint8_t *buf, const chipaddr addr, size_t len);
128
	void (*delay) (int usecs);
129 130 131 132
};

extern const struct programmer_entry programmer_table[];

133 134 135 136 137 138 139 140
int programmer_init(void);
int programmer_shutdown(void);
void *programmer_map_flash_region(const char *descr, unsigned long phys_addr,
				  size_t len);
void programmer_unmap_flash_region(void *virt_addr, size_t len);
void chip_writeb(uint8_t val, chipaddr addr);
void chip_writew(uint16_t val, chipaddr addr);
void chip_writel(uint32_t val, chipaddr addr);
141
void chip_writen(uint8_t *buf, chipaddr addr, size_t len);
142 143 144
uint8_t chip_readb(const chipaddr addr);
uint16_t chip_readw(const chipaddr addr);
uint32_t chip_readl(const chipaddr addr);
145
void chip_readn(uint8_t *buf, const chipaddr addr, size_t len);
146
void programmer_delay(int usecs);
147

148 149
#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))

150
enum chipbustype {
151
	CHIP_BUSTYPE_NONE	= 0,
152 153 154 155 156 157 158 159
	CHIP_BUSTYPE_PARALLEL	= 1 << 0,
	CHIP_BUSTYPE_LPC	= 1 << 1,
	CHIP_BUSTYPE_FWH	= 1 << 2,
	CHIP_BUSTYPE_SPI	= 1 << 3,
	CHIP_BUSTYPE_NONSPI	= CHIP_BUSTYPE_PARALLEL | CHIP_BUSTYPE_LPC | CHIP_BUSTYPE_FWH,
	CHIP_BUSTYPE_UNKNOWN	= CHIP_BUSTYPE_PARALLEL | CHIP_BUSTYPE_LPC | CHIP_BUSTYPE_FWH | CHIP_BUSTYPE_SPI,
};

160 161 162 163 164 165 166 167 168 169 170
/*
 * How many different contiguous runs of erase blocks with one size each do
 * we have for a given erase function?
 */
#define NUM_ERASEREGIONS 5

/*
 * How many different erase functions do we have per chip?
 */
#define NUM_ERASEFUNCTIONS 5

171
struct flashchip {
172
	const char *vendor;
173
	const char *name;
174 175 176

	enum chipbustype bustype;

177 178
	/*
	 * With 32bit manufacture_id and model_id we can cover IDs up to
179 180 181 182 183
	 * (including) the 4th bank of JEDEC JEP106W Standard Manufacturer's
	 * Identification code.
	 */
	uint32_t manufacture_id;
	uint32_t model_id;
184 185 186 187

	int total_size;
	int page_size;

188 189
	/*
	 * Indicate if flashrom has been tested with this flash chip and if
190 191 192 193
	 * everything worked correctly.
	 */
	uint32_t tested;

Uwe Hermann's avatar
Uwe Hermann committed
194
	int (*probe) (struct flashchip *flash);
195 196 197

	/* Delay after "enter/exit ID mode" commands in microseconds. */
	int probe_timing;
Uwe Hermann's avatar
Uwe Hermann committed
198
	int (*erase) (struct flashchip *flash);
199 200 201 202 203 204 205 206 207 208 209 210 211

	/*
	 * Erase blocks and associated erase function. The default entry is a
	 * chip-sized virtual block together with the chip erase function.
	 */
	struct block_eraser {
		struct eraseblock{
			unsigned int size; /* Eraseblock size */
			unsigned int count; /* Number of contiguous blocks with that size */
		} eraseblocks[NUM_ERASEREGIONS];
		int (*block_erase) (struct flashchip *flash, unsigned int blockaddr, unsigned int blocklen);
	} block_erasers[NUM_ERASEFUNCTIONS];

Uwe Hermann's avatar
Uwe Hermann committed
212
	int (*write) (struct flashchip *flash, uint8_t *buf);
213
	int (*read) (struct flashchip *flash, uint8_t *buf, int start, int len);
Ronald G. Minnich's avatar
Ronald G. Minnich committed
214

215
	/* Some flash devices have an additional register space. */
216 217
	chipaddr virtual_memory;
	chipaddr virtual_registers;
218 219
};

220 221
#define TEST_UNTESTED	0

Uwe Hermann's avatar
Uwe Hermann committed
222 223 224 225 226 227 228
#define TEST_OK_PROBE	(1 << 0)
#define TEST_OK_READ	(1 << 1)
#define TEST_OK_ERASE	(1 << 2)
#define TEST_OK_WRITE	(1 << 3)
#define TEST_OK_PR	(TEST_OK_PROBE | TEST_OK_READ)
#define TEST_OK_PRE	(TEST_OK_PROBE | TEST_OK_READ | TEST_OK_ERASE)
#define TEST_OK_PREW	(TEST_OK_PROBE | TEST_OK_READ | TEST_OK_ERASE | TEST_OK_WRITE)
229 230
#define TEST_OK_MASK	0x0f

Uwe Hermann's avatar
Uwe Hermann committed
231 232 233 234 235
#define TEST_BAD_PROBE	(1 << 4)
#define TEST_BAD_READ	(1 << 5)
#define TEST_BAD_ERASE	(1 << 6)
#define TEST_BAD_WRITE	(1 << 7)
#define TEST_BAD_PREW	(TEST_BAD_PROBE | TEST_BAD_READ | TEST_BAD_ERASE | TEST_BAD_WRITE)
236 237
#define TEST_BAD_MASK	0xf0

238 239 240 241 242 243 244 245 246 247
/* Timing used in probe routines. ZERO is -2 to differentiate between an unset
 * field and zero delay.
 * 
 * SPI devices will always have zero delay and ignore this field.
 */
#define TIMING_FIXME	-1
/* this is intentionally same value as fixme */
#define TIMING_IGNORED	-1
#define TIMING_ZERO	-2

248 249
extern struct flashchip flashchips[];

Uwe Hermann's avatar
Uwe Hermann committed
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294
struct penable {
	uint16_t vendor_id;
	uint16_t device_id;
	int status;
	const char *vendor_name;
	const char *device_name;
	int (*doit) (struct pci_dev *dev, const char *name);
};

extern const struct penable chipset_enables[];

struct board_pciid_enable {
	/* Any device, but make it sensible, like the ISA bridge. */
	uint16_t first_vendor;
	uint16_t first_device;
	uint16_t first_card_vendor;
	uint16_t first_card_device;

	/* Any device, but make it sensible, like
	 * the host bridge. May be NULL.
	 */
	uint16_t second_vendor;
	uint16_t second_device;
	uint16_t second_card_vendor;
	uint16_t second_card_device;

	/* The vendor / part name from the coreboot table. */
	const char *lb_vendor;
	const char *lb_part;

	const char *vendor_name;
	const char *board_name;

	int (*enable) (const char *name);
};

extern struct board_pciid_enable board_pciid_enables[];

struct board_info {
	const char *vendor;
	const char *name;
};

extern const struct board_info boards_ok[];
extern const struct board_info boards_bad[];
295 296
extern const struct board_info laptops_ok[];
extern const struct board_info laptops_bad[];
Uwe Hermann's avatar
Uwe Hermann committed
297

298
/* udelay.c */
299
void myusec_delay(int usecs);
300
void myusec_calibrate_delay(void);
301

302 303 304
/* pcidev.c */
#define PCI_OK 0
#define PCI_NT 1    /* Not tested */
305

306 307 308
extern uint32_t io_base_addr;
extern struct pci_access *pacc;
extern struct pci_filter filter;
309
extern struct pci_dev *pcidev_dev;
310 311 312 313 314 315 316
struct pcidev_status {
	uint16_t vendor_id;
	uint16_t device_id;
	int status;
	const char *vendor_name;
	const char *device_name;
};
317 318
uint32_t pcidev_validate(struct pci_dev *dev, uint32_t bar, struct pcidev_status *devs);
uint32_t pcidev_init(uint16_t vendor_id, uint32_t bar, struct pcidev_status *devs, char *pcidev_bdf);
319 320 321 322 323 324

/* print.c */
char *flashbuses_to_text(enum chipbustype bustype);
void print_supported_chips(void);
void print_supported_chipsets(void);
void print_supported_boards(void);
325
void print_supported_pcidevs(struct pcidev_status *devs);
Uwe Hermann's avatar
Uwe Hermann committed
326
void print_wiki_tables(void);
327

328
/* board_enable.c */
329 330
void w836xx_ext_enter(uint16_t port);
void w836xx_ext_leave(uint16_t port);
331 332 333
uint8_t sio_read(uint16_t port, uint8_t reg);
void sio_write(uint16_t port, uint8_t reg, uint8_t data);
void sio_mask(uint16_t port, uint8_t reg, uint8_t data, uint8_t mask);
334
int board_flash_enable(const char *vendor, const char *part);
335

336
/* chipset_enable.c */
337
extern enum chipbustype buses_supported;
338
int chipset_flash_enable(void);
339

340 341
extern unsigned long flashbase;

342 343 344
/* physmap.c */
void *physmap(const char *descr, unsigned long phys_addr, size_t len);
void physunmap(void *virt_addr, size_t len);
345 346
int setup_cpu_msr(int cpu);
void cleanup_cpu_msr(void);
347
#if !defined(__DARWIN__) && !defined(__FreeBSD__) && !defined(__DragonFly__)
348 349 350 351
typedef struct { uint32_t hi, lo; } msr_t;
msr_t rdmsr(int addr);
int wrmsr(int addr, msr_t msr);
#endif
352 353 354 355 356 357 358 359 360 361
#if defined(__FreeBSD__) || defined(__DragonFly__)
/* FreeBSD already has conflicting definitions for wrmsr/rdmsr. */
#undef rdmsr
#undef wrmsr
#define rdmsr freebsd_rdmsr
#define wrmsr freebsd_wrmsr
typedef struct { uint32_t hi, lo; } msr_t;
msr_t freebsd_rdmsr(int addr);
int freebsd_wrmsr(int addr, msr_t msr);
#endif
362

363
/* internal.c */
364 365 366 367
struct pci_dev *pci_dev_find_filter(struct pci_filter filter);
struct pci_dev *pci_dev_find(uint16_t vendor, uint16_t device);
struct pci_dev *pci_card_find(uint16_t vendor, uint16_t device,
			      uint16_t card_vendor, uint16_t card_device);
368
void get_io_perms(void);
369
void release_io_perms(void);
370 371
int internal_init(void);
int internal_shutdown(void);
372 373 374 375 376 377
void internal_chip_writeb(uint8_t val, chipaddr addr);
void internal_chip_writew(uint16_t val, chipaddr addr);
void internal_chip_writel(uint32_t val, chipaddr addr);
uint8_t internal_chip_readb(const chipaddr addr);
uint16_t internal_chip_readw(const chipaddr addr);
uint32_t internal_chip_readl(const chipaddr addr);
378
void internal_chip_readn(uint8_t *buf, const chipaddr addr, size_t len);
379 380 381 382 383 384
void mmio_writeb(uint8_t val, void *addr);
void mmio_writew(uint16_t val, void *addr);
void mmio_writel(uint32_t val, void *addr);
uint8_t mmio_readb(void *addr);
uint16_t mmio_readw(void *addr);
uint32_t mmio_readl(void *addr);
385
void internal_delay(int usecs);
386
int noop_shutdown(void);
387 388
void *fallback_map(const char *descr, unsigned long phys_addr, size_t len);
void fallback_unmap(void *virt_addr, size_t len);
389 390
uint8_t noop_chip_readb(const chipaddr addr);
void noop_chip_writeb(uint8_t val, chipaddr addr);
391 392
void fallback_chip_writew(uint16_t val, chipaddr addr);
void fallback_chip_writel(uint32_t val, chipaddr addr);
393
void fallback_chip_writen(uint8_t *buf, chipaddr addr, size_t len);
394 395
uint16_t fallback_chip_readw(const chipaddr addr);
uint32_t fallback_chip_readl(const chipaddr addr);
396
void fallback_chip_readn(uint8_t *buf, const chipaddr addr, size_t len);
397 398 399
#if defined(__FreeBSD__) || defined(__DragonFly__)
extern int io_fd;
#endif
400

401 402 403
/* dummyflasher.c */
int dummy_init(void);
int dummy_shutdown(void);
404 405
void *dummy_map(const char *descr, unsigned long phys_addr, size_t len);
void dummy_unmap(void *virt_addr, size_t len);
406 407 408
void dummy_chip_writeb(uint8_t val, chipaddr addr);
void dummy_chip_writew(uint16_t val, chipaddr addr);
void dummy_chip_writel(uint32_t val, chipaddr addr);
409
void dummy_chip_writen(uint8_t *buf, chipaddr addr, size_t len);
410 411 412
uint8_t dummy_chip_readb(const chipaddr addr);
uint16_t dummy_chip_readw(const chipaddr addr);
uint32_t dummy_chip_readl(const chipaddr addr);
413
void dummy_chip_readn(uint8_t *buf, const chipaddr addr, size_t len);
414
int dummy_spi_send_command(unsigned int writecnt, unsigned int readcnt,
415
		      const unsigned char *writearr, unsigned char *readarr);
416

417 418 419
/* nic3com.c */
int nic3com_init(void);
int nic3com_shutdown(void);
420 421
void nic3com_chip_writeb(uint8_t val, chipaddr addr);
uint8_t nic3com_chip_readb(const chipaddr addr);
422
extern struct pcidev_status nics_3com[];
423

424 425 426 427 428 429 430
/* drkaiser.c */
int drkaiser_init(void);
int drkaiser_shutdown(void);
void drkaiser_chip_writeb(uint8_t val, chipaddr addr);
uint8_t drkaiser_chip_readb(const chipaddr addr);
extern struct pcidev_status drkaiser_pcidev[];

431 432 433 434 435 436 437
/* satasii.c */
int satasii_init(void);
int satasii_shutdown(void);
void satasii_chip_writeb(uint8_t val, chipaddr addr);
uint8_t satasii_chip_readb(const chipaddr addr);
extern struct pcidev_status satas_sii[];

438
/* ft2232_spi.c */
439 440
#define FTDI_FT2232H 0x6010
#define FTDI_FT4232H 0x6011
441
int ft2232_spi_init(void);
442
int ft2232_spi_send_command(unsigned int writecnt, unsigned int readcnt, const unsigned char *writearr, unsigned char *readarr);
443 444 445
int ft2232_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len);
int ft2232_spi_write_256(struct flashchip *flash, uint8_t *buf);

446
/* flashrom.c */
447
extern char *programmer_param;
Uwe Hermann's avatar
Uwe Hermann committed
448
extern int verbose;
449
extern const char *flashrom_version;
Uwe Hermann's avatar
Uwe Hermann committed
450
#define printf_debug(x...) { if (verbose) printf(x); }
451
void map_flash_registers(struct flashchip *flash);
452
int read_memmapped(struct flashchip *flash, uint8_t *buf, int start, int len);
453
int erase_flash(struct flashchip *flash);
454
int min(int a, int b);
455 456 457
int max(int a, int b);
int check_erased_range(struct flashchip *flash, int start, int len);
int verify_range(struct flashchip *flash, uint8_t *cmpbuf, int start, int len, char *message);
458 459 460 461
char *strcat_realloc(char *dest, const char *src);

#define OK 0
#define NT 1    /* Not tested */
462 463

/* layout.c */
Peter Stuge's avatar
Peter Stuge committed
464
int show_id(uint8_t *bios, int size, int force);
465 466
int read_romlayout(char *name);
int find_romentry(char *name);
467
int handle_romentries(uint8_t *buffer, struct flashchip *flash);
468

Uwe Hermann's avatar
Uwe Hermann committed
469
/* cbtable.c */
Stefan Reinauer's avatar
Stefan Reinauer committed
470
int coreboot_init(void);
471
extern char *lb_part, *lb_vendor;
472
extern int partvendor_from_cbtable;
473

474
/* spi.c */
475 476 477 478 479 480 481 482
enum spi_controller {
	SPI_CONTROLLER_NONE,
	SPI_CONTROLLER_ICH7,
	SPI_CONTROLLER_ICH9,
	SPI_CONTROLLER_IT87XX,
	SPI_CONTROLLER_SB600,
	SPI_CONTROLLER_VIA,
	SPI_CONTROLLER_WBSIO,
483
#if FT2232_SPI_SUPPORT == 1
484
	SPI_CONTROLLER_FT2232,
485
#endif
486
#if DUMMY_SUPPORT == 1
487
	SPI_CONTROLLER_DUMMY,
488
#endif
489
	SPI_CONTROLLER_INVALID /* This must always be the last entry. */
490
};
491
extern const int spi_programmer_count;
492 493 494 495 496 497
struct spi_command {
	unsigned int writecnt;
	unsigned int readcnt;
	const unsigned char *writearr;
	unsigned char *readarr;
};
498 499 500
struct spi_programmer {
	int (*command)(unsigned int writecnt, unsigned int readcnt,
		   const unsigned char *writearr, unsigned char *readarr);
501
	int (*multicommand)(struct spi_command *cmds);
502 503 504 505 506

	/* Optimized functions for this programmer */
	int (*read)(struct flashchip *flash, uint8_t *buf, int start, int len);
	int (*write_256)(struct flashchip *flash, uint8_t *buf);
};
507

508
extern enum spi_controller spi_controller;
509
extern const struct spi_programmer spi_programmer[];
510
extern void *spibar;
511
int probe_spi_rdid(struct flashchip *flash);
512
int probe_spi_rdid4(struct flashchip *flash);
513
int probe_spi_rems(struct flashchip *flash);
514
int probe_spi_res(struct flashchip *flash);
515
int spi_send_command(unsigned int writecnt, unsigned int readcnt,
516
		const unsigned char *writearr, unsigned char *readarr);
517
int spi_send_multicommand(struct spi_command *cmds);
518 519
int spi_write_enable(void);
int spi_write_disable(void);
520
int spi_chip_erase_60(struct flashchip *flash);
521
int spi_chip_erase_c7(struct flashchip *flash);
522
int spi_chip_erase_60_c7(struct flashchip *flash);
523
int spi_chip_erase_d8(struct flashchip *flash);
524 525 526 527 528
int spi_block_erase_20(struct flashchip *flash, unsigned int addr, unsigned int blocklen);
int spi_block_erase_52(struct flashchip *flash, unsigned int addr, unsigned int blocklen);
int spi_block_erase_d8(struct flashchip *flash, unsigned int addr, unsigned int blocklen);
int spi_block_erase_60(struct flashchip *flash, unsigned int addr, unsigned int blocklen);
int spi_block_erase_c7(struct flashchip *flash, unsigned int addr, unsigned int blocklen);
529
int spi_chip_write_1(struct flashchip *flash, uint8_t *buf);
530
int spi_chip_write_256(struct flashchip *flash, uint8_t *buf);
531
int spi_chip_read(struct flashchip *flash, uint8_t *buf, int start, int len);
532
uint8_t spi_read_status_register(void);
533
int spi_disable_blockprotect(void);
534 535 536
int spi_byte_program(int addr, uint8_t byte);
int spi_nbyte_program(int addr, uint8_t *bytes, int len);
int spi_nbyte_read(int addr, uint8_t *bytes, int len);
537
int spi_read_chunked(struct flashchip *flash, uint8_t *buf, int start, int len, int chunksize);
538
int spi_aai_write(struct flashchip *flash, uint8_t *buf);
539
uint32_t spi_get_valid_read_addr(void);
540 541
int default_spi_send_command(unsigned int writecnt, unsigned int readcnt,
			     const unsigned char *writearr, unsigned char *readarr);
542
int default_spi_send_multicommand(struct spi_command *cmds);
543

544
/* 82802ab.c */
Uwe Hermann's avatar
Uwe Hermann committed
545 546 547
int probe_82802ab(struct flashchip *flash);
int erase_82802ab(struct flashchip *flash);
int write_82802ab(struct flashchip *flash, uint8_t *buf);
548 549

/* am29f040b.c */
Uwe Hermann's avatar
Uwe Hermann committed
550 551 552
int probe_29f040b(struct flashchip *flash);
int erase_29f040b(struct flashchip *flash);
int write_29f040b(struct flashchip *flash, uint8_t *buf);
553 554 555

/* pm29f002.c */
int write_pm29f002(struct flashchip *flash, uint8_t *buf);
556 557 558 559 560

/* en29f002a.c */
int probe_en29f002a(struct flashchip *flash);
int erase_en29f002a(struct flashchip *flash);
int write_en29f002a(struct flashchip *flash, uint8_t *buf);
561

562
/* ichspi.c */
563
int ich_init_opcodes(void);
564
int ich_spi_send_command(unsigned int writecnt, unsigned int readcnt,
565
		    const unsigned char *writearr, unsigned char *readarr);
566
int ich_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len);
567
int ich_spi_write_256(struct flashchip *flash, uint8_t * buf);
568
int ich_spi_send_multicommand(struct spi_command *cmds);
569

570 571
/* it87spi.c */
extern uint16_t it8716f_flashport;
572 573
void enter_conf_mode_ite(uint16_t port);
void exit_conf_mode_ite(uint16_t port);
574
int it87spi_init(void);
575
int it87xx_probe_spi_flash(const char *name);
576
int it8716f_spi_send_command(unsigned int writecnt, unsigned int readcnt,
577
			const unsigned char *writearr, unsigned char *readarr);
578
int it8716f_spi_chip_read(struct flashchip *flash, uint8_t *buf, int start, int len);
579
int it8716f_spi_chip_write_256(struct flashchip *flash, uint8_t *buf);
580

581
/* sb600spi.c */
582
int sb600_spi_send_command(unsigned int writecnt, unsigned int readcnt,
583
		      const unsigned char *writearr, unsigned char *readarr);
584
int sb600_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len);
585
int sb600_spi_write_1(struct flashchip *flash, uint8_t *buf);
586
extern uint8_t *sb600_spibar;
587

588
/* jedec.c */
589
uint8_t oddparity(uint8_t val);
590 591 592 593 594 595
void toggle_ready_jedec(chipaddr dst);
void data_polling_jedec(chipaddr dst, uint8_t data);
void unprotect_jedec(chipaddr bios);
void protect_jedec(chipaddr bios);
int write_byte_program_jedec(chipaddr bios, uint8_t *src,
			     chipaddr dst);
Uwe Hermann's avatar
Uwe Hermann committed
596 597 598
int probe_jedec(struct flashchip *flash);
int erase_chip_jedec(struct flashchip *flash);
int write_jedec(struct flashchip *flash, uint8_t *buf);
599 600
int erase_sector_jedec(struct flashchip *flash, unsigned int page, int pagesize);
int erase_block_jedec(struct flashchip *flash, unsigned int page, int blocksize);
601 602
int write_sector_jedec(chipaddr bios, uint8_t *src,
		       chipaddr dst, unsigned int page_size);
603

Peter Stuge's avatar
Peter Stuge committed
604 605 606 607 608
/* m29f002.c */
int erase_m29f002(struct flashchip *flash);
int write_m29f002t(struct flashchip *flash, uint8_t *buf);
int write_m29f002b(struct flashchip *flash, uint8_t *buf);

609
/* m29f400bt.c */
Uwe Hermann's avatar
Uwe Hermann committed
610 611
int probe_m29f400bt(struct flashchip *flash);
int erase_m29f400bt(struct flashchip *flash);
612
int block_erase_m29f400bt(struct flashchip *flash, int start, int len);
Uwe Hermann's avatar
Uwe Hermann committed
613
int write_m29f400bt(struct flashchip *flash, uint8_t *buf);
Stefan Reinauer's avatar
Stefan Reinauer committed
614
int write_coreboot_m29f400bt(struct flashchip *flash, uint8_t *buf);
615 616 617 618 619
void toggle_ready_m29f400bt(chipaddr dst);
void data_polling_m29f400bt(chipaddr dst, uint8_t data);
void protect_m29f400bt(chipaddr bios);
void write_page_m29f400bt(chipaddr bios, uint8_t *src,
			  chipaddr dst, int page_size);
620 621

/* mx29f002.c */
Uwe Hermann's avatar
Uwe Hermann committed
622 623 624
int probe_29f002(struct flashchip *flash);
int erase_29f002(struct flashchip *flash);
int write_29f002(struct flashchip *flash, uint8_t *buf);
625

626 627 628 629
/* pm49fl00x.c */
int probe_49fl00x(struct flashchip *flash);
int erase_49fl00x(struct flashchip *flash);
int write_49fl00x(struct flashchip *flash, uint8_t *buf);
630 631

/* sharplhf00l04.c */
Uwe Hermann's avatar
Uwe Hermann committed
632 633 634
int probe_lhf00l04(struct flashchip *flash);
int erase_lhf00l04(struct flashchip *flash);
int write_lhf00l04(struct flashchip *flash, uint8_t *buf);
635 636 637
void toggle_ready_lhf00l04(chipaddr dst);
void data_polling_lhf00l04(chipaddr dst, uint8_t data);
void protect_lhf00l04(chipaddr bios);
638 639

/* sst28sf040.c */
Uwe Hermann's avatar
Uwe Hermann committed
640 641 642
int probe_28sf040(struct flashchip *flash);
int erase_28sf040(struct flashchip *flash);
int write_28sf040(struct flashchip *flash, uint8_t *buf);
643 644

/* sst39sf020.c */
Uwe Hermann's avatar
Uwe Hermann committed
645 646
int probe_39sf020(struct flashchip *flash);
int write_39sf020(struct flashchip *flash, uint8_t *buf);
647 648

/* sst49lf040.c */
Uwe Hermann's avatar
Uwe Hermann committed
649 650
int erase_49lf040(struct flashchip *flash);
int write_49lf040(struct flashchip *flash, uint8_t *buf);
651 652

/* sst49lfxxxc.c */
Uwe Hermann's avatar
Uwe Hermann committed
653 654 655
int probe_49lfxxxc(struct flashchip *flash);
int erase_49lfxxxc(struct flashchip *flash);
int write_49lfxxxc(struct flashchip *flash, uint8_t *buf);
656 657

/* sst_fwhub.c */
Uwe Hermann's avatar
Uwe Hermann committed
658 659 660
int probe_sst_fwhub(struct flashchip *flash);
int erase_sst_fwhub(struct flashchip *flash);
int write_sst_fwhub(struct flashchip *flash, uint8_t *buf);
661

662 663 664 665 666
/* w39v040c.c */
int probe_w39v040c(struct flashchip *flash);
int erase_w39v040c(struct flashchip *flash);
int write_w39v040c(struct flashchip *flash, uint8_t *buf);

667 668 669 670 671
/* w39V080fa.c */
int probe_winbond_fwhub(struct flashchip *flash);
int erase_winbond_fwhub(struct flashchip *flash);
int write_winbond_fwhub(struct flashchip *flash, uint8_t *buf);

672
/* w29ee011.c */
Uwe Hermann's avatar
Uwe Hermann committed
673
int probe_w29ee011(struct flashchip *flash);
674

675
/* w49f002u.c */
Uwe Hermann's avatar
Uwe Hermann committed
676
int write_49f002(struct flashchip *flash, uint8_t *buf);
677

Peter Stuge's avatar
Peter Stuge committed
678 679
/* wbsio_spi.c */
int wbsio_check_for_spi(const char *name);
680
int wbsio_spi_send_command(unsigned int writecnt, unsigned int readcnt,
Uwe Hermann's avatar
Uwe Hermann committed
681
		      const unsigned char *writearr, unsigned char *readarr);
682
int wbsio_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len);
683
int wbsio_spi_write_1(struct flashchip *flash, uint8_t *buf);
Peter Stuge's avatar
Peter Stuge committed
684

685 686 687 688
/* stm50flw0x0x.c */
int probe_stm50flw0x0x(struct flashchip *flash);
int erase_stm50flw0x0x(struct flashchip *flash);
int write_stm50flw0x0x(struct flashchip *flash, uint8_t *buf);
689

690 691 692 693 694 695 696
/* serprog.c */
int serprog_init(void);
int serprog_shutdown(void);
void serprog_chip_writeb(uint8_t val, chipaddr addr);
uint8_t serprog_chip_readb(const chipaddr addr);
void serprog_chip_readn(uint8_t *buf, const chipaddr addr, size_t len);
void serprog_delay(int delay);
Uwe Hermann's avatar
Uwe Hermann committed
697

698
#endif				/* !__FLASH_H__ */