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.
18 #include <linux/types.h>
20 #ifndef CONFIG_SF_DEFAULT_SPEED
21 # define CONFIG_SF_DEFAULT_SPEED 1000000
23 #ifndef CONFIG_SF_DEFAULT_MODE
24 # define CONFIG_SF_DEFAULT_MODE SPI_MODE_3
26 #ifndef CONFIG_SF_DEFAULT_CS
27 # define CONFIG_SF_DEFAULT_CS 0
29 #ifndef CONFIG_SF_DEFAULT_BUS
30 # define CONFIG_SF_DEFAULT_BUS 0
36 * struct spi_flash - SPI flash structure
39 * @name: Name of SPI flash
40 * @dual_flash: Indicates dual flash memories - dual stacked, parallel
41 * @shift: Flash shift useful in dual parallel
42 * @size: Total flash size
43 * @page_size: Write (page) size
44 * @sector_size: Sector size
45 * @erase_size: Erase size
46 * @bank_read_cmd: Bank read cmd
47 * @bank_write_cmd: Bank write cmd
48 * @bank_curr: Current flash bank
49 * @poll_cmd: Poll cmd - for flash erase/program
50 * @erase_cmd: Erase cmd 4K, 32K, 64K
51 * @read_cmd: Read cmd - Array Fast, Extn read and quad read.
52 * @write_cmd: Write cmd - page and quad program.
53 * @dummy_byte: Dummy cycles for read operation.
54 * @memory_map: Address of read-only SPI flash access
55 * @read: Flash read ops: Read len bytes at offset into buf
56 * Supported cmds: Fast Array Read
57 * @write: Flash write ops: Write len bytes from buf into offset
58 * Supported cmds: Page Program
59 * @erase: Flash erase ops: Erase len bytes from offset
60 * Supported cmds: Sector erase 4K, 32K, 64K
61 * return 0 - Success, 1 - Failure
64 struct spi_slave *spi;
73 #ifdef CONFIG_SPI_FLASH_BAR
85 int (*read)(struct spi_flash *flash, u32 offset, size_t len, void *buf);
86 int (*write)(struct spi_flash *flash, u32 offset, size_t len,
88 int (*erase)(struct spi_flash *flash, u32 offset, size_t len);
91 struct spi_flash *spi_flash_probe(unsigned int bus, unsigned int cs,
92 unsigned int max_hz, unsigned int spi_mode);
95 * Set up a new SPI flash from an fdt node
97 * @param blob Device tree blob
98 * @param slave_node Pointer to this SPI slave node in the device tree
99 * @param spi_node Cached pointer to the SPI interface this node belongs
101 * @return 0 if ok, -1 on error
103 struct spi_flash *spi_flash_probe_fdt(const void *blob, int slave_node,
106 void spi_flash_free(struct spi_flash *flash);
108 static inline int spi_flash_read(struct spi_flash *flash, u32 offset,
109 size_t len, void *buf)
111 return flash->read(flash, offset, len, buf);
114 static inline int spi_flash_write(struct spi_flash *flash, u32 offset,
115 size_t len, const void *buf)
117 return flash->write(flash, offset, len, buf);
120 static inline int spi_flash_erase(struct spi_flash *flash, u32 offset,
123 return flash->erase(flash, offset, len);
126 void spi_boot(void) __noreturn;
127 void spi_spl_load_image(uint32_t offs, unsigned int size, void *vdst);
129 #endif /* _SPI_FLASH_H_ */