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>
22 #ifndef CONFIG_SF_DEFAULT_SPEED
23 # define CONFIG_SF_DEFAULT_SPEED 1000000
25 #ifndef CONFIG_SF_DEFAULT_MODE
26 # define CONFIG_SF_DEFAULT_MODE SPI_MODE_3
28 #ifndef CONFIG_SF_DEFAULT_CS
29 # define CONFIG_SF_DEFAULT_CS 0
31 #ifndef CONFIG_SF_DEFAULT_BUS
32 # define CONFIG_SF_DEFAULT_BUS 0
36 #define SECT_4K 1 << 1
37 #define SECT_32K 1 << 2
41 /* Enum list - Full read commands */
44 DUAL_OUTPUT_FAST = 1 << 1,
45 DUAL_IO_FAST = 1 << 2,
46 QUAD_OUTPUT_FAST = 1 << 3,
47 QUAD_IO_FAST = 1 << 4,
49 #define RD_EXTN ARRAY_SLOW | DUAL_OUTPUT_FAST | DUAL_IO_FAST
50 #define RD_FULL RD_EXTN | QUAD_OUTPUT_FAST | QUAD_IO_FAST
52 /* Dual SPI flash memories */
55 SF_DUAL_STACKED_FLASH = 1 << 0,
56 SF_DUAL_PARALLEL_FLASH = 1 << 1,
60 * struct spi_flash_params - SPI/QSPI flash device params structure
62 * @name: Device name ([MANUFLETTER][DEVTYPE][DENSITY][EXTRAINFO])
63 * @jedec: Device jedec ID (0x[1byte_manuf_id][2byte_dev_id])
64 * @ext_jedec: Device ext_jedec ID
65 * @sector_size: Sector size of this device
66 * @nr_sectors: No.of sectors on this device
67 * @e_rd_cmd: Enum list for read commands
68 * @flags: Important param, for flash specific behaviour
70 struct spi_flash_params {
80 extern const struct spi_flash_params spi_flash_params_table[];
83 * struct spi_flash - SPI flash structure
86 * @name: Name of SPI flash
87 * @dual_flash: Indicates dual flash memories - dual stacked, parallel
88 * @shift: Flash shift useful in dual parallel
89 * @size: Total flash size
90 * @page_size: Write (page) size
91 * @sector_size: Sector size
92 * @erase_size: Erase size
93 * @bank_read_cmd: Bank read cmd
94 * @bank_write_cmd: Bank write cmd
95 * @bank_curr: Current flash bank
96 * @poll_cmd: Poll cmd - for flash erase/program
97 * @erase_cmd: Erase cmd 4K, 32K, 64K
98 * @read_cmd: Read cmd - Array Fast, Extn read and quad read.
99 * @write_cmd: Write cmd - page and quad program.
100 * @dummy_byte: Dummy cycles for read operation.
101 * @memory_map: Address of read-only SPI flash access
102 * @read: Flash read ops: Read len bytes at offset into buf
103 * Supported cmds: Fast Array Read
104 * @write: Flash write ops: Write len bytes from buf into offset
105 * Supported cmds: Page Program
106 * @erase: Flash erase ops: Erase len bytes from offset
107 * Supported cmds: Sector erase 4K, 32K, 64K
108 * return 0 - Success, 1 - Failure
111 struct spi_slave *spi;
120 #ifdef CONFIG_SPI_FLASH_BAR
132 int (*read)(struct spi_flash *flash, u32 offset, size_t len, void *buf);
133 int (*write)(struct spi_flash *flash, u32 offset, size_t len,
135 int (*erase)(struct spi_flash *flash, u32 offset, size_t len);
138 struct spi_flash *spi_flash_probe(unsigned int bus, unsigned int cs,
139 unsigned int max_hz, unsigned int spi_mode);
142 * Set up a new SPI flash from an fdt node
144 * @param blob Device tree blob
145 * @param slave_node Pointer to this SPI slave node in the device tree
146 * @param spi_node Cached pointer to the SPI interface this node belongs
148 * @return 0 if ok, -1 on error
150 struct spi_flash *spi_flash_probe_fdt(const void *blob, int slave_node,
153 void spi_flash_free(struct spi_flash *flash);
155 static inline int spi_flash_read(struct spi_flash *flash, u32 offset,
156 size_t len, void *buf)
158 return flash->read(flash, offset, len, buf);
161 static inline int spi_flash_write(struct spi_flash *flash, u32 offset,
162 size_t len, const void *buf)
164 return flash->write(flash, offset, len, buf);
167 static inline int spi_flash_erase(struct spi_flash *flash, u32 offset,
170 return flash->erase(flash, offset, len);
173 void spi_boot(void) __noreturn;
174 void spi_spl_load_image(uint32_t offs, unsigned int size, void *vdst);
176 #endif /* _SPI_FLASH_H_ */