2 * Common SPI flash Interface
4 * Copyright (C) 2008 Atmel Corporation
5 * Copyright (C) 2013 Jagannadha Sutradharudu Teki, Xilinx Inc.
7 * See file CREDITS for list of people who contributed to this
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * version 2 as published by the Free Software Foundation.
19 #include <linux/types.h>
20 #include <linux/compiler.h>
23 * struct spi_flash - SPI flash structure
26 * @name: Name of SPI flash
27 * @size: Total flash size
28 * @page_size: Write (page) size
29 * @sector_size: Sector size
30 * @erase_size: Erase size
31 * @bank_read_cmd: Bank read cmd
32 * @bank_write_cmd: Bank write cmd
33 * @bank_curr: Current flash bank
34 * @poll_cmd: Poll cmd - for flash erase/program
35 * @erase_cmd: Erase cmd 4K, 32K, 64K
36 * @memory_map: Address of read-only SPI flash access
37 * @read: Flash read ops: Read len bytes at offset into buf
38 * Supported cmds: Fast Array Read
39 * @write: Flash write ops: Write len bytes from buf into offeset
40 * Supported cmds: Page Program
41 * @erase: Flash erase ops: Erase len bytes from offset
42 * Supported cmds: Sector erase 4K, 32K, 64K
43 * return 0 - Sucess, 1 - Failure
46 struct spi_slave *spi;
53 #ifdef CONFIG_SPI_FLASH_BAR
62 int (*read)(struct spi_flash *flash, u32 offset, size_t len, void *buf);
63 int (*write)(struct spi_flash *flash, u32 offset, size_t len,
65 int (*erase)(struct spi_flash *flash, u32 offset, size_t len);
68 struct spi_flash *spi_flash_probe(unsigned int bus, unsigned int cs,
69 unsigned int max_hz, unsigned int spi_mode);
72 * Set up a new SPI flash from an fdt node
74 * @param blob Device tree blob
75 * @param slave_node Pointer to this SPI slave node in the device tree
76 * @param spi_node Cached pointer to the SPI interface this node belongs
78 * @return 0 if ok, -1 on error
80 struct spi_flash *spi_flash_probe_fdt(const void *blob, int slave_node,
83 void spi_flash_free(struct spi_flash *flash);
85 static inline int spi_flash_read(struct spi_flash *flash, u32 offset,
86 size_t len, void *buf)
88 return flash->read(flash, offset, len, buf);
91 static inline int spi_flash_write(struct spi_flash *flash, u32 offset,
92 size_t len, const void *buf)
94 return flash->write(flash, offset, len, buf);
97 static inline int spi_flash_erase(struct spi_flash *flash, u32 offset,
100 return flash->erase(flash, offset, len);
103 void spi_boot(void) __noreturn;
105 #endif /* _SPI_FLASH_H_ */