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 | d79de1d | 2013-07-08 09:37:19 +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 | f000ad0 | 2013-09-28 18:10:43 +0530 | [diff] [blame] | 22 | /** |
| 23 | * struct spi_flash - SPI flash structure |
| 24 | * |
| 25 | * @spi: SPI slave |
| 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 |
| 44 | */ |
Haavard Skinnemoen | 2f5bfb7 | 2008-05-16 11:10:33 +0200 | [diff] [blame] | 45 | struct spi_flash { |
| 46 | struct spi_slave *spi; |
Jagannadha Sutradharudu Teki | f000ad0 | 2013-09-28 18:10:43 +0530 | [diff] [blame] | 47 | const char *name; |
Haavard Skinnemoen | 2f5bfb7 | 2008-05-16 11:10:33 +0200 | [diff] [blame] | 48 | |
Jagannadha Sutradharudu Teki | f000ad0 | 2013-09-28 18:10:43 +0530 | [diff] [blame] | 49 | u32 size; |
| 50 | u32 page_size; |
| 51 | u32 sector_size; |
| 52 | u32 erase_size; |
Jagannadha Sutradharudu Teki | c6d173d | 2013-06-19 15:33:58 +0530 | [diff] [blame] | 53 | #ifdef CONFIG_SPI_FLASH_BAR |
Jagannadha Sutradharudu Teki | f000ad0 | 2013-09-28 18:10:43 +0530 | [diff] [blame] | 54 | u8 bank_read_cmd; |
| 55 | u8 bank_write_cmd; |
| 56 | u8 bank_curr; |
Jagannadha Sutradharudu Teki | c6d173d | 2013-06-19 15:33:58 +0530 | [diff] [blame] | 57 | #endif |
Jagannadha Sutradharudu Teki | f000ad0 | 2013-09-28 18:10:43 +0530 | [diff] [blame] | 58 | u8 poll_cmd; |
| 59 | u8 erase_cmd; |
Jagannadha Sutradharudu Teki | 750f3ac | 2013-06-21 15:56:30 +0530 | [diff] [blame] | 60 | |
Jagannadha Sutradharudu Teki | f000ad0 | 2013-09-28 18:10:43 +0530 | [diff] [blame] | 61 | void *memory_map; |
| 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, |
| 64 | const void *buf); |
| 65 | int (*erase)(struct spi_flash *flash, u32 offset, size_t len); |
Haavard Skinnemoen | 2f5bfb7 | 2008-05-16 11:10:33 +0200 | [diff] [blame] | 66 | }; |
| 67 | |
| 68 | struct spi_flash *spi_flash_probe(unsigned int bus, unsigned int cs, |
| 69 | unsigned int max_hz, unsigned int spi_mode); |
| 70 | void spi_flash_free(struct spi_flash *flash); |
| 71 | |
| 72 | static inline int spi_flash_read(struct spi_flash *flash, u32 offset, |
| 73 | size_t len, void *buf) |
| 74 | { |
| 75 | return flash->read(flash, offset, len, buf); |
| 76 | } |
| 77 | |
| 78 | static inline int spi_flash_write(struct spi_flash *flash, u32 offset, |
| 79 | size_t len, const void *buf) |
| 80 | { |
| 81 | return flash->write(flash, offset, len, buf); |
| 82 | } |
| 83 | |
| 84 | static inline int spi_flash_erase(struct spi_flash *flash, u32 offset, |
| 85 | size_t len) |
| 86 | { |
| 87 | return flash->erase(flash, offset, len); |
| 88 | } |
| 89 | |
Christian Riesch | 23f16a8 | 2011-12-09 09:47:35 +0000 | [diff] [blame] | 90 | void spi_boot(void) __noreturn; |
| 91 | |
Haavard Skinnemoen | 2f5bfb7 | 2008-05-16 11:10:33 +0200 | [diff] [blame] | 92 | #endif /* _SPI_FLASH_H_ */ |