blob: 52de1843026fbfc741de70cc2486127286dfc22c [file] [log] [blame]
Stefan Reinauer1c56d9b2012-05-10 11:27:32 -07001/*
2 * Interface to SPI flash
3 *
4 * Copyright (C) 2008 Atmel Corporation
5 *
Stefan Reinauer1c56d9b2012-05-10 11:27:32 -07006 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * version 2 as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Paul Menzela8ae1c62013-02-20 13:21:20 +010012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Stefan Reinauer1c56d9b2012-05-10 11:27:32 -070013 * GNU General Public License for more details.
Stefan Reinauer1c56d9b2012-05-10 11:27:32 -070014 */
15#ifndef _SPI_FLASH_H_
16#define _SPI_FLASH_H_
17
18#include <stdint.h>
19#include <stddef.h>
20#include <console/console.h>
Zheng Bao600784e2013-02-07 17:30:23 +080021#include <spi-generic.h>
Dan Ehrenberga5aac762015-01-08 10:29:19 -080022#include <boot/coreboot_tables.h>
Stefan Reinauer1c56d9b2012-05-10 11:27:32 -070023
Stefan Reinauer1c56d9b2012-05-10 11:27:32 -070024struct spi_flash {
25 struct spi_slave *spi;
26
27 const char *name;
28
29 u32 size;
30
31 u32 sector_size;
32
Dan Ehrenberga5aac762015-01-08 10:29:19 -080033 u8 erase_cmd;
34
Duncan Lauriefb032392015-01-15 15:28:46 -080035 u8 status_cmd;
36
Aaron Durbina3565ae2015-05-14 14:46:59 -050037 /* All callbacks return 0 on success and != 0 on error. */
Stefan Reinauer1c56d9b2012-05-10 11:27:32 -070038 int (*read)(struct spi_flash *flash, u32 offset,
39 size_t len, void *buf);
40 int (*write)(struct spi_flash *flash, u32 offset,
41 size_t len, const void *buf);
42 int (*erase)(struct spi_flash *flash, u32 offset,
43 size_t len);
Duncan Lauriefb032392015-01-15 15:28:46 -080044 int (*status)(struct spi_flash *flash, u8 *reg);
Stefan Reinauer1c56d9b2012-05-10 11:27:32 -070045};
46
Gabe Black1e187352014-03-27 20:37:03 -070047struct spi_flash *spi_flash_probe(unsigned int bus, unsigned int cs);
Stefan Reinauer1c56d9b2012-05-10 11:27:32 -070048
Dan Ehrenberga5aac762015-01-08 10:29:19 -080049void lb_spi_flash(struct lb_header *header);
50
Stefan Reinauer1c56d9b2012-05-10 11:27:32 -070051#endif /* _SPI_FLASH_H_ */