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