1 /* 2 * Common SPI flash Interface 3 * 4 * Copyright (C) 2008 Atmel Corporation 5 * Copyright (C) 2013 Jagannadha Sutradharudu Teki, Xilinx Inc. 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 12 * version 2 as published by the Free Software Foundation. 13 */ 14 15 #ifndef _SPI_FLASH_H_ 16 #define _SPI_FLASH_H_ 17 18 #include <spi.h> 19 #include <linux/types.h> 20 #include <linux/compiler.h> 21 22 /* Enum list - Extended read commands */ 23 enum spi_read_cmds { 24 ARRAY_SLOW = 1 << 0, 25 DUAL_OUTPUT_FAST = 1 << 1, 26 DUAL_IO_FAST = 1 << 2, 27 }; 28 #define RD_EXTN ARRAY_SLOW | DUAL_OUTPUT_FAST | DUAL_IO_FAST 29 30 /** 31 * struct spi_flash - SPI flash structure 32 * 33 * @spi: SPI slave 34 * @name: Name of SPI flash 35 * @size: Total flash size 36 * @page_size: Write (page) size 37 * @sector_size: Sector size 38 * @erase_size: Erase size 39 * @bank_read_cmd: Bank read cmd 40 * @bank_write_cmd: Bank write cmd 41 * @bank_curr: Current flash bank 42 * @poll_cmd: Poll cmd - for flash erase/program 43 * @erase_cmd: Erase cmd 4K, 32K, 64K 44 * @read_cmd: Read cmd - Array Fast and Extn read 45 * @memory_map: Address of read-only SPI flash access 46 * @read: Flash read ops: Read len bytes at offset into buf 47 * Supported cmds: Fast Array Read 48 * @write: Flash write ops: Write len bytes from buf into offeset 49 * Supported cmds: Page Program 50 * @erase: Flash erase ops: Erase len bytes from offset 51 * Supported cmds: Sector erase 4K, 32K, 64K 52 * return 0 - Sucess, 1 - Failure 53 */ 54 struct spi_flash { 55 struct spi_slave *spi; 56 const char *name; 57 58 u32 size; 59 u32 page_size; 60 u32 sector_size; 61 u32 erase_size; 62 #ifdef CONFIG_SPI_FLASH_BAR 63 u8 bank_read_cmd; 64 u8 bank_write_cmd; 65 u8 bank_curr; 66 #endif 67 u8 poll_cmd; 68 u8 erase_cmd; 69 u8 read_cmd; 70 71 void *memory_map; 72 int (*read)(struct spi_flash *flash, u32 offset, size_t len, void *buf); 73 int (*write)(struct spi_flash *flash, u32 offset, size_t len, 74 const void *buf); 75 int (*erase)(struct spi_flash *flash, u32 offset, size_t len); 76 }; 77 78 struct spi_flash *spi_flash_probe(unsigned int bus, unsigned int cs, 79 unsigned int max_hz, unsigned int spi_mode); 80 81 /** 82 * Set up a new SPI flash from an fdt node 83 * 84 * @param blob Device tree blob 85 * @param slave_node Pointer to this SPI slave node in the device tree 86 * @param spi_node Cached pointer to the SPI interface this node belongs 87 * to 88 * @return 0 if ok, -1 on error 89 */ 90 struct spi_flash *spi_flash_probe_fdt(const void *blob, int slave_node, 91 int spi_node); 92 93 void spi_flash_free(struct spi_flash *flash); 94 95 static inline int spi_flash_read(struct spi_flash *flash, u32 offset, 96 size_t len, void *buf) 97 { 98 return flash->read(flash, offset, len, buf); 99 } 100 101 static inline int spi_flash_write(struct spi_flash *flash, u32 offset, 102 size_t len, const void *buf) 103 { 104 return flash->write(flash, offset, len, buf); 105 } 106 107 static inline int spi_flash_erase(struct spi_flash *flash, u32 offset, 108 size_t len) 109 { 110 return flash->erase(flash, offset, len); 111 } 112 113 void spi_boot(void) __noreturn; 114 115 #endif /* _SPI_FLASH_H_ */ 116