summaryrefslogtreecommitdiff
path: root/src/include/spi_flash.h
diff options
context:
space:
mode:
authorStefan Reinauer <reinauer@chromium.org>2012-05-10 11:27:32 -0700
committerStefan Reinauer <stefan.reinauer@coreboot.org>2012-05-10 23:52:44 +0200
commit1c56d9b1029b344b92bc1cd1acb2fe52ce0c0e2d (patch)
tree81db0d753447c2e0f8fd196ef9ba74b142baeb64 /src/include/spi_flash.h
parent43105d6a5a4898386e35c4fdccdf643b95faef98 (diff)
downloadcoreboot-1c56d9b1029b344b92bc1cd1acb2fe52ce0c0e2d.tar.xz
Add SPI flash driver
This driver is taken from u-boot and adapted to match coreboot. It still contains some hacks and is ICH specific at places. Change-Id: I97dd8096f7db3b62f8f4f4e4d08bdee10d88f689 Signed-off-by: Patrick Georgi <patrick@georgi-clan.de> Reviewed-on: http://review.coreboot.org/997 Tested-by: build bot (Jenkins) Reviewed-by: Ronald G. Minnich <rminnich@gmail.com>
Diffstat (limited to 'src/include/spi_flash.h')
-rw-r--r--src/include/spi_flash.h91
1 files changed, 91 insertions, 0 deletions
diff --git a/src/include/spi_flash.h b/src/include/spi_flash.h
new file mode 100644
index 0000000000..2a1dcd4632
--- /dev/null
+++ b/src/include/spi_flash.h
@@ -0,0 +1,91 @@
+/*
+ * Interface to SPI flash
+ *
+ * Copyright (C) 2008 Atmel Corporation
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * 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.
+ *
+ * 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., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+#ifndef _SPI_FLASH_H_
+#define _SPI_FLASH_H_
+
+#include <stdint.h>
+#include <stddef.h>
+#include <console/console.h>
+#include <spi.h>
+
+/**
+ * container_of - cast a member of a structure out to the containing structure
+ * @ptr: the pointer to the member.
+ * @type: the type of the container struct this is embedded in.
+ * @member: the name of the member within the struct.
+ *
+ */
+#define container_of(ptr, type, member) ({ \
+ const typeof( ((type *)0)->member ) *__mptr = (ptr); \
+ (type *)( (char *)__mptr - offsetof(type,member) );})
+
+#define min(a, b) ((a)<(b)?(a):(b))
+
+#define CONFIG_ICH_SPI
+#ifdef CONFIG_ICH_SPI
+#define CONTROLLER_PAGE_LIMIT 64
+#else
+/* any number larger than 4K would do, actually */
+#define CONTROLLER_PAGE_LIMIT ((int)(~0U>>1))
+#endif
+
+struct spi_flash {
+ struct spi_slave *spi;
+
+ const char *name;
+
+ u32 size;
+
+ u32 sector_size;
+
+ int (*read)(struct spi_flash *flash, u32 offset,
+ size_t len, void *buf);
+ int (*write)(struct spi_flash *flash, u32 offset,
+ size_t len, const void *buf);
+ int (*erase)(struct spi_flash *flash, u32 offset,
+ size_t len);
+};
+
+struct spi_flash *spi_flash_probe(unsigned int bus, unsigned int cs,
+ unsigned int max_hz, unsigned int spi_mode);
+void spi_flash_free(struct spi_flash *flash);
+
+static inline int spi_flash_read(struct spi_flash *flash, u32 offset,
+ size_t len, void *buf)
+{
+ return flash->read(flash, offset, len, buf);
+}
+
+static inline int spi_flash_write(struct spi_flash *flash, u32 offset,
+ size_t len, const void *buf)
+{
+ return flash->write(flash, offset, len, buf);
+}
+
+static inline int spi_flash_erase(struct spi_flash *flash, u32 offset,
+ size_t len)
+{
+ return flash->erase(flash, offset, len);
+}
+
+#endif /* _SPI_FLASH_H_ */