Haavard Skinnemoen | 2f5bfb7 | 2008-05-16 11:10:33 +0200 | [diff] [blame] | 1 | /* |
Jagannadha Sutradharudu Teki | 25dc86a | 2013-10-02 19:38:49 +0530 | [diff] [blame] | 2 | * Common SPI flash Interface |
Haavard Skinnemoen | 2f5bfb7 | 2008-05-16 11:10:33 +0200 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 2008 Atmel Corporation |
Jagannadha Sutradharudu Teki | 25dc86a | 2013-10-02 19:38:49 +0530 | [diff] [blame] | 5 | * Copyright (C) 2013 Jagannadha Sutradharudu Teki, Xilinx Inc. |
Haavard Skinnemoen | 2f5bfb7 | 2008-05-16 11:10:33 +0200 | [diff] [blame] | 6 | * |
| 7 | * See file CREDITS for list of people who contributed to this |
| 8 | * project. |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or |
| 11 | * modify it under the terms of the GNU General Public License |
Wolfgang Denk | bd8ec7e | 2013-10-07 13:07:26 +0200 | [diff] [blame] | 12 | * version 2 as published by the Free Software Foundation. |
Haavard Skinnemoen | 2f5bfb7 | 2008-05-16 11:10:33 +0200 | [diff] [blame] | 13 | */ |
Jagannadha Sutradharudu Teki | 25dc86a | 2013-10-02 19:38:49 +0530 | [diff] [blame] | 14 | |
Haavard Skinnemoen | 2f5bfb7 | 2008-05-16 11:10:33 +0200 | [diff] [blame] | 15 | #ifndef _SPI_FLASH_H_ |
| 16 | #define _SPI_FLASH_H_ |
| 17 | |
| 18 | #include <spi.h> |
Mike Frysinger | e4c698b | 2009-11-03 11:36:39 -0500 | [diff] [blame] | 19 | #include <linux/types.h> |
Christian Riesch | 23f16a8 | 2011-12-09 09:47:35 +0000 | [diff] [blame] | 20 | #include <linux/compiler.h> |
Haavard Skinnemoen | 2f5bfb7 | 2008-05-16 11:10:33 +0200 | [diff] [blame] | 21 | |
Jagannadha Sutradharudu Teki | 243ced0 | 2014-01-12 21:38:21 +0530 | [diff] [blame] | 22 | /* sf param flags */ |
| 23 | #define SECT_4K 1 << 1 |
| 24 | #define SECT_32K 1 << 2 |
| 25 | #define E_FSR 1 << 3 |
Jagannadha Sutradharudu Teki | e0ebabc | 2014-01-11 15:13:11 +0530 | [diff] [blame] | 26 | #define WR_QPP 1 << 4 |
| 27 | |
| 28 | /* Enum list - Full read commands */ |
Jagannadha Sutradharudu Teki | 02eee9a | 2014-01-11 15:10:28 +0530 | [diff] [blame] | 29 | enum spi_read_cmds { |
| 30 | ARRAY_SLOW = 1 << 0, |
| 31 | DUAL_OUTPUT_FAST = 1 << 1, |
| 32 | DUAL_IO_FAST = 1 << 2, |
Jagannadha Sutradharudu Teki | e0ebabc | 2014-01-11 15:13:11 +0530 | [diff] [blame] | 33 | QUAD_OUTPUT_FAST = 1 << 3, |
Jagannadha Sutradharudu Teki | 4546230 | 2013-12-24 15:24:31 +0530 | [diff] [blame] | 34 | QUAD_IO_FAST = 1 << 4, |
Jagannadha Sutradharudu Teki | 02eee9a | 2014-01-11 15:10:28 +0530 | [diff] [blame] | 35 | }; |
| 36 | #define RD_EXTN ARRAY_SLOW | DUAL_OUTPUT_FAST | DUAL_IO_FAST |
Jagannadha Sutradharudu Teki | 4546230 | 2013-12-24 15:24:31 +0530 | [diff] [blame] | 37 | #define RD_FULL RD_EXTN | QUAD_OUTPUT_FAST | QUAD_IO_FAST |
Jagannadha Sutradharudu Teki | 02eee9a | 2014-01-11 15:10:28 +0530 | [diff] [blame] | 38 | |
Jagannadha Sutradharudu Teki | e84b4f6 | 2014-01-12 21:40:11 +0530 | [diff] [blame] | 39 | /* Dual SPI flash memories */ |
| 40 | enum spi_dual_flash { |
| 41 | SF_SINGLE_FLASH = 0, |
| 42 | SF_DUAL_STACKED_FLASH = 1 << 0, |
Jagannadha Sutradharudu Teki | b47b741 | 2014-01-07 00:11:35 +0530 | [diff] [blame] | 43 | SF_DUAL_PARALLEL_FLASH = 1 << 1, |
Jagannadha Sutradharudu Teki | e84b4f6 | 2014-01-12 21:40:11 +0530 | [diff] [blame] | 44 | }; |
| 45 | |
Jagannadha Sutradharudu Teki | f000ad0 | 2013-09-28 18:10:43 +0530 | [diff] [blame] | 46 | /** |
Jagannadha Sutradharudu Teki | 20e45bc | 2013-12-23 23:34:42 +0530 | [diff] [blame] | 47 | * struct spi_flash_params - SPI/QSPI flash device params structure |
| 48 | * |
| 49 | * @name: Device name ([MANUFLETTER][DEVTYPE][DENSITY][EXTRAINFO]) |
| 50 | * @jedec: Device jedec ID (0x[1byte_manuf_id][2byte_dev_id]) |
| 51 | * @ext_jedec: Device ext_jedec ID |
| 52 | * @sector_size: Sector size of this device |
| 53 | * @nr_sectors: No.of sectors on this device |
| 54 | * @e_rd_cmd: Enum list for read commands |
| 55 | * @flags: Importent param, for flash specific behaviour |
| 56 | */ |
| 57 | struct spi_flash_params { |
| 58 | const char *name; |
| 59 | u32 jedec; |
| 60 | u16 ext_jedec; |
| 61 | u32 sector_size; |
| 62 | u32 nr_sectors; |
| 63 | u8 e_rd_cmd; |
| 64 | u16 flags; |
| 65 | }; |
| 66 | |
| 67 | extern const struct spi_flash_params spi_flash_params_table[]; |
| 68 | |
| 69 | /** |
Jagannadha Sutradharudu Teki | f000ad0 | 2013-09-28 18:10:43 +0530 | [diff] [blame] | 70 | * struct spi_flash - SPI flash structure |
| 71 | * |
| 72 | * @spi: SPI slave |
| 73 | * @name: Name of SPI flash |
Jagannadha Sutradharudu Teki | b47b741 | 2014-01-07 00:11:35 +0530 | [diff] [blame] | 74 | * @dual_flash: Indicates dual flash memories - dual stacked, parallel |
| 75 | * @shift: Flash shift useful in dual parallel |
Jagannadha Sutradharudu Teki | f000ad0 | 2013-09-28 18:10:43 +0530 | [diff] [blame] | 76 | * @size: Total flash size |
| 77 | * @page_size: Write (page) size |
| 78 | * @sector_size: Sector size |
Jagannadha Sutradharudu Teki | f3b2dd8 | 2013-10-07 19:34:56 +0530 | [diff] [blame] | 79 | * @erase_size: Erase size |
Jagannadha Sutradharudu Teki | f000ad0 | 2013-09-28 18:10:43 +0530 | [diff] [blame] | 80 | * @bank_read_cmd: Bank read cmd |
| 81 | * @bank_write_cmd: Bank write cmd |
| 82 | * @bank_curr: Current flash bank |
| 83 | * @poll_cmd: Poll cmd - for flash erase/program |
| 84 | * @erase_cmd: Erase cmd 4K, 32K, 64K |
Jagannadha Sutradharudu Teki | e0ebabc | 2014-01-11 15:13:11 +0530 | [diff] [blame] | 85 | * @read_cmd: Read cmd - Array Fast, Extn read and quad read. |
| 86 | * @write_cmd: Write cmd - page and quad program. |
Jagannadha Sutradharudu Teki | ca79986 | 2014-01-11 16:50:45 +0530 | [diff] [blame] | 87 | * @dummy_byte: Dummy cycles for read operation. |
Jagannadha Sutradharudu Teki | f3b2dd8 | 2013-10-07 19:34:56 +0530 | [diff] [blame] | 88 | * @memory_map: Address of read-only SPI flash access |
Jagannadha Sutradharudu Teki | f000ad0 | 2013-09-28 18:10:43 +0530 | [diff] [blame] | 89 | * @read: Flash read ops: Read len bytes at offset into buf |
| 90 | * Supported cmds: Fast Array Read |
| 91 | * @write: Flash write ops: Write len bytes from buf into offeset |
| 92 | * Supported cmds: Page Program |
| 93 | * @erase: Flash erase ops: Erase len bytes from offset |
| 94 | * Supported cmds: Sector erase 4K, 32K, 64K |
| 95 | * return 0 - Sucess, 1 - Failure |
| 96 | */ |
Haavard Skinnemoen | 2f5bfb7 | 2008-05-16 11:10:33 +0200 | [diff] [blame] | 97 | struct spi_flash { |
| 98 | struct spi_slave *spi; |
Jagannadha Sutradharudu Teki | f000ad0 | 2013-09-28 18:10:43 +0530 | [diff] [blame] | 99 | const char *name; |
Jagannadha Sutradharudu Teki | e84b4f6 | 2014-01-12 21:40:11 +0530 | [diff] [blame] | 100 | u8 dual_flash; |
Jagannadha Sutradharudu Teki | b47b741 | 2014-01-07 00:11:35 +0530 | [diff] [blame] | 101 | u8 shift; |
Haavard Skinnemoen | 2f5bfb7 | 2008-05-16 11:10:33 +0200 | [diff] [blame] | 102 | |
Jagannadha Sutradharudu Teki | f000ad0 | 2013-09-28 18:10:43 +0530 | [diff] [blame] | 103 | u32 size; |
| 104 | u32 page_size; |
| 105 | u32 sector_size; |
| 106 | u32 erase_size; |
Jagannadha Sutradharudu Teki | c6d173d | 2013-06-19 15:33:58 +0530 | [diff] [blame] | 107 | #ifdef CONFIG_SPI_FLASH_BAR |
Jagannadha Sutradharudu Teki | f000ad0 | 2013-09-28 18:10:43 +0530 | [diff] [blame] | 108 | u8 bank_read_cmd; |
| 109 | u8 bank_write_cmd; |
| 110 | u8 bank_curr; |
Jagannadha Sutradharudu Teki | c6d173d | 2013-06-19 15:33:58 +0530 | [diff] [blame] | 111 | #endif |
Jagannadha Sutradharudu Teki | f000ad0 | 2013-09-28 18:10:43 +0530 | [diff] [blame] | 112 | u8 poll_cmd; |
| 113 | u8 erase_cmd; |
Jagannadha Sutradharudu Teki | 02eee9a | 2014-01-11 15:10:28 +0530 | [diff] [blame] | 114 | u8 read_cmd; |
Jagannadha Sutradharudu Teki | e0ebabc | 2014-01-11 15:13:11 +0530 | [diff] [blame] | 115 | u8 write_cmd; |
Jagannadha Sutradharudu Teki | ca79986 | 2014-01-11 16:50:45 +0530 | [diff] [blame] | 116 | u8 dummy_byte; |
Jagannadha Sutradharudu Teki | 750f3ac | 2013-06-21 15:56:30 +0530 | [diff] [blame] | 117 | |
Jagannadha Sutradharudu Teki | f000ad0 | 2013-09-28 18:10:43 +0530 | [diff] [blame] | 118 | void *memory_map; |
| 119 | int (*read)(struct spi_flash *flash, u32 offset, size_t len, void *buf); |
| 120 | int (*write)(struct spi_flash *flash, u32 offset, size_t len, |
| 121 | const void *buf); |
| 122 | int (*erase)(struct spi_flash *flash, u32 offset, size_t len); |
Haavard Skinnemoen | 2f5bfb7 | 2008-05-16 11:10:33 +0200 | [diff] [blame] | 123 | }; |
| 124 | |
| 125 | struct spi_flash *spi_flash_probe(unsigned int bus, unsigned int cs, |
| 126 | unsigned int max_hz, unsigned int spi_mode); |
Simon Glass | 49e9d2c | 2013-12-03 16:43:24 -0700 | [diff] [blame] | 127 | |
| 128 | /** |
| 129 | * Set up a new SPI flash from an fdt node |
| 130 | * |
| 131 | * @param blob Device tree blob |
| 132 | * @param slave_node Pointer to this SPI slave node in the device tree |
| 133 | * @param spi_node Cached pointer to the SPI interface this node belongs |
| 134 | * to |
| 135 | * @return 0 if ok, -1 on error |
| 136 | */ |
| 137 | struct spi_flash *spi_flash_probe_fdt(const void *blob, int slave_node, |
| 138 | int spi_node); |
| 139 | |
Haavard Skinnemoen | 2f5bfb7 | 2008-05-16 11:10:33 +0200 | [diff] [blame] | 140 | void spi_flash_free(struct spi_flash *flash); |
| 141 | |
| 142 | static inline int spi_flash_read(struct spi_flash *flash, u32 offset, |
| 143 | size_t len, void *buf) |
| 144 | { |
| 145 | return flash->read(flash, offset, len, buf); |
| 146 | } |
| 147 | |
| 148 | static inline int spi_flash_write(struct spi_flash *flash, u32 offset, |
| 149 | size_t len, const void *buf) |
| 150 | { |
| 151 | return flash->write(flash, offset, len, buf); |
| 152 | } |
| 153 | |
| 154 | static inline int spi_flash_erase(struct spi_flash *flash, u32 offset, |
| 155 | size_t len) |
| 156 | { |
| 157 | return flash->erase(flash, offset, len); |
| 158 | } |
| 159 | |
Christian Riesch | 23f16a8 | 2011-12-09 09:47:35 +0000 | [diff] [blame] | 160 | void spi_boot(void) __noreturn; |
| 161 | |
Haavard Skinnemoen | 2f5bfb7 | 2008-05-16 11:10:33 +0200 | [diff] [blame] | 162 | #endif /* _SPI_FLASH_H_ */ |