]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - include/spi_flash.h
223e4420a5ea5f56c69527a74104af04cb3c4691
[karo-tx-uboot.git] / include / spi_flash.h
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 <linux/types.h>
19
20 #ifndef CONFIG_SF_DEFAULT_SPEED
21 # define CONFIG_SF_DEFAULT_SPEED        1000000
22 #endif
23 #ifndef CONFIG_SF_DEFAULT_MODE
24 # define CONFIG_SF_DEFAULT_MODE         SPI_MODE_3
25 #endif
26 #ifndef CONFIG_SF_DEFAULT_CS
27 # define CONFIG_SF_DEFAULT_CS           0
28 #endif
29 #ifndef CONFIG_SF_DEFAULT_BUS
30 # define CONFIG_SF_DEFAULT_BUS          0
31 #endif
32
33 struct spi_slave;
34
35 /**
36  * struct spi_flash - SPI flash structure
37  *
38  * @spi:                SPI slave
39  * @name:               Name of SPI flash
40  * @dual_flash: Indicates dual flash memories - dual stacked, parallel
41  * @shift:              Flash shift useful in dual parallel
42  * @size:               Total flash size
43  * @page_size:          Write (page) size
44  * @sector_size:        Sector size
45  * @erase_size: Erase size
46  * @bank_read_cmd:      Bank read cmd
47  * @bank_write_cmd:     Bank write cmd
48  * @bank_curr:          Current flash bank
49  * @poll_cmd:           Poll cmd - for flash erase/program
50  * @erase_cmd:          Erase cmd 4K, 32K, 64K
51  * @read_cmd:           Read cmd - Array Fast, Extn read and quad read.
52  * @write_cmd:          Write cmd - page and quad program.
53  * @dummy_byte: Dummy cycles for read operation.
54  * @memory_map: Address of read-only SPI flash access
55  * @read:               Flash read ops: Read len bytes at offset into buf
56  *                      Supported cmds: Fast Array Read
57  * @write:              Flash write ops: Write len bytes from buf into offset
58  *                      Supported cmds: Page Program
59  * @erase:              Flash erase ops: Erase len bytes from offset
60  *                      Supported cmds: Sector erase 4K, 32K, 64K
61  * return 0 - Success, 1 - Failure
62  */
63 struct spi_flash {
64         struct spi_slave *spi;
65         const char *name;
66         u8 dual_flash;
67         u8 shift;
68
69         u32 size;
70         u32 page_size;
71         u32 sector_size;
72         u32 erase_size;
73 #ifdef CONFIG_SPI_FLASH_BAR
74         u8 bank_read_cmd;
75         u8 bank_write_cmd;
76         u8 bank_curr;
77 #endif
78         u8 poll_cmd;
79         u8 erase_cmd;
80         u8 read_cmd;
81         u8 write_cmd;
82         u8 dummy_byte;
83
84         void *memory_map;
85         int (*read)(struct spi_flash *flash, u32 offset, size_t len, void *buf);
86         int (*write)(struct spi_flash *flash, u32 offset, size_t len,
87                         const void *buf);
88         int (*erase)(struct spi_flash *flash, u32 offset, size_t len);
89 };
90
91 struct spi_flash *spi_flash_probe(unsigned int bus, unsigned int cs,
92                 unsigned int max_hz, unsigned int spi_mode);
93
94 /**
95  * Set up a new SPI flash from an fdt node
96  *
97  * @param blob          Device tree blob
98  * @param slave_node    Pointer to this SPI slave node in the device tree
99  * @param spi_node      Cached pointer to the SPI interface this node belongs
100  *                      to
101  * @return 0 if ok, -1 on error
102  */
103 struct spi_flash *spi_flash_probe_fdt(const void *blob, int slave_node,
104                                       int spi_node);
105
106 void spi_flash_free(struct spi_flash *flash);
107
108 static inline int spi_flash_read(struct spi_flash *flash, u32 offset,
109                 size_t len, void *buf)
110 {
111         return flash->read(flash, offset, len, buf);
112 }
113
114 static inline int spi_flash_write(struct spi_flash *flash, u32 offset,
115                 size_t len, const void *buf)
116 {
117         return flash->write(flash, offset, len, buf);
118 }
119
120 static inline int spi_flash_erase(struct spi_flash *flash, u32 offset,
121                 size_t len)
122 {
123         return flash->erase(flash, offset, len);
124 }
125
126 void spi_boot(void) __noreturn;
127 void spi_spl_load_image(uint32_t offs, unsigned int size, void *vdst);
128
129 #endif /* _SPI_FLASH_H_ */