Debian Codegraph @

include/spi.h

raw
1 /*
2 * This file is part of the flashrom project.
3 *
4 * Copyright (C) 2007, 2008 Carl-Daniel Hailfinger
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 */
15
16 #ifndef __SPI_H__
17 #define __SPI_H__ 1
18
19 #include "flash.h"
20
21 /*
22 * Contains the generic SPI headers
23 */
24
25 #define JEDEC_MAX_ADDR_LEN 0x04
26
27 /* Read Electronic ID */
28 #define JEDEC_RDID 0x9f
29 #define JEDEC_RDID_OUTSIZE 0x01
30 /* INSIZE may be 0x04 for some chips*/
31 #define JEDEC_RDID_INSIZE 0x03
32
33 /* Some ST M95X model */
34 #define ST_M95_RDID 0x83
35 #define ST_M95_RDID_3BA_OUTSIZE 0x04 /* 8b op, 24bit addr where size >64KiB */
36 #define ST_M95_RDID_2BA_OUTSIZE 0x03 /* 8b op, 16bit addr where size <=64KiB */
37 #define ST_M95_RDID_OUTSIZE_MAX 0x04 /* ST_M95_RDID_3BA_OUTSIZE */
38 #define ST_M95_RDID_INSIZE 0x03
39
40 /* Some Atmel AT25F* models have bit 3 as don't care bit in commands */
41 #define AT25F_RDID 0x15 /* 0x15 or 0x1d */
42 #define AT25F_RDID_OUTSIZE 0x01
43 #define AT25F_RDID_INSIZE 0x02
44
45 /* Read Electronic Manufacturer Signature */
46 #define JEDEC_REMS 0x90
47 #define JEDEC_REMS_OUTSIZE 0x04
48 #define JEDEC_REMS_INSIZE 0x02
49
50 /* Read Serial Flash Discoverable Parameters (SFDP) */
51 #define JEDEC_SFDP 0x5a
52 #define JEDEC_SFDP_OUTSIZE 0x05 /* 8b op, 24b addr, 8b dummy */
53 /* JEDEC_SFDP_INSIZE : any length */
54
55 /* Read Electronic Signature */
56 #define JEDEC_RES 0xab
57 #define JEDEC_RES_OUTSIZE 0x04
58 /* INSIZE may be 0x02 for some chips*/
59 #define JEDEC_RES_INSIZE 0x01
60
61 /* Write Enable */
62 #define JEDEC_WREN 0x06
63 #define JEDEC_WREN_OUTSIZE 0x01
64 #define JEDEC_WREN_INSIZE 0x00
65
66 /* Write Disable */
67 #define JEDEC_WRDI 0x04
68 #define JEDEC_WRDI_OUTSIZE 0x01
69 #define JEDEC_WRDI_INSIZE 0x00
70
71 /* Chip Erase 0x60 is supported by Macronix/SST chips. */
72 #define JEDEC_CE_60 0x60
73 #define JEDEC_CE_60_OUTSIZE 0x01
74 #define JEDEC_CE_60_INSIZE 0x00
75
76 /* Chip Erase 0x62 is supported by Atmel AT25F chips. */
77 #define JEDEC_CE_62 0x62
78 #define JEDEC_CE_62_OUTSIZE 0x01
79 #define JEDEC_CE_62_INSIZE 0x00
80
81 /* Chip Erase 0xc7 is supported by SST/ST/EON/Macronix chips. */
82 #define JEDEC_CE_C7 0xc7
83 #define JEDEC_CE_C7_OUTSIZE 0x01
84 #define JEDEC_CE_C7_INSIZE 0x00
85
86 /* Block Erase 0x50 is supported by Atmel AT26DF chips. */
87 #define JEDEC_BE_50 0x50
88 #define JEDEC_BE_50_OUTSIZE 0x04
89 #define JEDEC_BE_50_INSIZE 0x00
90
91 /* Block Erase 0x52 is supported by SST and old Atmel chips. */
92 #define JEDEC_BE_52 0x52
93 #define JEDEC_BE_52_OUTSIZE 0x04
94 #define JEDEC_BE_52_INSIZE 0x00
95
96 /* Block Erase 0x81 is supported by Atmel AT26DF chips. */
97 #define JEDEC_BE_81 0x81
98 #define JEDEC_BE_81_OUTSIZE 0x04
99 #define JEDEC_BE_81_INSIZE 0x00
100
101 /* Block Erase 0xc4 is supported by Micron chips. */
102 #define JEDEC_BE_C4 0xc4
103 #define JEDEC_BE_C4_OUTSIZE 0x04
104 #define JEDEC_BE_C4_INSIZE 0x00
105
106 /* Block Erase 0xd8 is supported by EON/Macronix chips. */
107 #define JEDEC_BE_D8 0xd8
108 #define JEDEC_BE_D8_OUTSIZE 0x04
109 #define JEDEC_BE_D8_INSIZE 0x00
110
111 /* Block Erase 0xd7 is supported by PMC chips. */
112 #define JEDEC_BE_D7 0xd7
113 #define JEDEC_BE_D7_OUTSIZE 0x04
114 #define JEDEC_BE_D7_INSIZE 0x00
115
116 /* Block Erase 0xdc is supported by Spansion chips, takes 4 byte address */
117 #define JEDEC_BE_DC 0xdc
118 #define JEDEC_BE_DC_OUTSIZE 0x05
119 #define JEDEC_BE_DC_INSIZE 0x00
120
121 /* Sector Erase 0x20 is supported by Macronix/SST chips. */
122 #define JEDEC_SE 0x20
123 #define JEDEC_SE_OUTSIZE 0x04
124 #define JEDEC_SE_INSIZE 0x00
125
126 /* Page Erase 0xDB */
127 #define JEDEC_PE 0xDB
128 #define JEDEC_PE_OUTSIZE 0x04
129 #define JEDEC_PE_INSIZE 0x00
130
131 /* Read Status Register */
132 #define JEDEC_RDSR 0x05
133 #define JEDEC_RDSR_OUTSIZE 0x01
134 #define JEDEC_RDSR_INSIZE 0x01
135
136 /* Read Status Register 2 */
137 #define JEDEC_RDSR2 0x35
138 #define JEDEC_RDSR2_OUTSIZE 0x01
139 #define JEDEC_RDSR2_INSIZE 0x01
140
141 /* Read Status Register 3 */
142 #define JEDEC_RDSR3 0x15
143 #define JEDEC_RDSR3_OUTSIZE 0x01
144 #define JEDEC_RDSR3_INSIZE 0x01
145
146 /* Status Register Bits */
147 #define SPI_SR_WIP (0x01 << 0)
148 #define SPI_SR_WEL (0x01 << 1)
149 #define SPI_SR_ERA_ERR (0x01 << 5)
150 #define SPI_SR_AAI (0x01 << 6)
151
152 /* Write Status Enable */
153 #define JEDEC_EWSR 0x50
154 #define JEDEC_EWSR_OUTSIZE 0x01
155 #define JEDEC_EWSR_INSIZE 0x00
156
157 /* Write Status Register */
158 #define JEDEC_WRSR 0x01
159 #define JEDEC_WRSR_OUTSIZE 0x02
160 #define JEDEC_WRSR_INSIZE 0x00
161
162 /* Write Status Register 2 */
163 #define JEDEC_WRSR2 0x31
164 #define JEDEC_WRSR2_OUTSIZE 0x02
165 #define JEDEC_WRSR2_INSIZE 0x00
166
167 /* Write Status Register 3 */
168 #define JEDEC_WRSR3 0x11
169 #define JEDEC_WRSR3_OUTSIZE 0x02
170 #define JEDEC_WRSR3_INSIZE 0x00
171
172 /* Read Security Register */
173 #define JEDEC_RDSCUR 0x2b
174 #define JEDEC_RDSCUR_OUTSIZE 0x01
175 #define JEDEC_RDSCUR_INSIZE 0x01
176
177 /* Write Security Register */
178 #define JEDEC_WRSCUR 0x2f
179 #define JEDEC_WRSCUR_OUTSIZE 0x01
180 #define JEDEC_WRSCUR_INSIZE 0x00
181
182 /* Read Configuration Register */
183 #define JEDEC_RDCR 0x15
184 #define JEDEC_RDCR_OUTSIZE 0x01
185 #define JEDEC_RDCR_INSIZE 0x01
186
187 /* Enter 4-byte Address Mode */
188 #define JEDEC_ENTER_4_BYTE_ADDR_MODE 0xB7
189
190 /* Exit 4-byte Address Mode */
191 #define JEDEC_EXIT_4_BYTE_ADDR_MODE 0xE9
192
193 /* Write Extended Address Register */
194 #define JEDEC_WRITE_EXT_ADDR_REG 0xC5
195 #define ALT_WRITE_EXT_ADDR_REG_17 0x17
196
197 /* Read Extended Address Register */
198 #define JEDEC_READ_EXT_ADDR_REG 0xC8
199 #define ALT_READ_EXT_ADDR_REG_16 0x16
200
201 /* Read the memory */
202 #define JEDEC_READ 0x03
203 #define JEDEC_READ_OUTSIZE 0x04
204 /* JEDEC_READ_INSIZE : any length */
205
206 /* Read the memory (with delay after sending address) */
207 #define JEDEC_READ_FAST 0x0b
208
209 /* Write memory byte */
210 #define JEDEC_BYTE_PROGRAM 0x02
211 #define JEDEC_BYTE_PROGRAM_OUTSIZE 0x05
212 #define JEDEC_BYTE_PROGRAM_INSIZE 0x00
213
214 /* Write AAI word (SST25VF080B) */
215 #define JEDEC_AAI_WORD_PROGRAM 0xad
216 #define JEDEC_AAI_WORD_PROGRAM_OUTSIZE 0x06
217 #define JEDEC_AAI_WORD_PROGRAM_CONT_OUTSIZE 0x03
218 #define JEDEC_AAI_WORD_PROGRAM_INSIZE 0x00
219
220 /* Read the memory with 4-byte address
221 From ANY mode (3-bytes or 4-bytes) it works with 4-byte address */
222 #define JEDEC_READ_4BA 0x13
223
224 /* Read the memory with 4-byte address (and delay after sending address)
225 From ANY mode (3-bytes or 4-bytes) it works with 4-byte address */
226 #define JEDEC_READ_4BA_FAST 0x0c
227
228 /* Write memory byte with 4-byte address
229 From ANY mode (3-bytes or 4-bytes) it works with 4-byte address */
230 #define JEDEC_BYTE_PROGRAM_4BA 0x12
231
232 /* Error codes */
233 #define SPI_GENERIC_ERROR -1
234 #define SPI_INVALID_OPCODE -2
235 #define SPI_INVALID_ADDRESS -3
236 #define SPI_INVALID_LENGTH -4
237 #define SPI_FLASHROM_BUG -5
238 #define SPI_PROGRAMMER_ERROR -6
239
240 struct spi_command {
241 unsigned int writecnt;
242 unsigned int readcnt;
243 const unsigned char *writearr;
244 unsigned char *readarr;
245 };
246 #define NULL_SPI_CMD { 0, 0, NULL, NULL, }
247 int spi_send_command(const struct flashctx *flash, unsigned int writecnt, unsigned int readcnt, const unsigned char *writearr, unsigned char *readarr);
248 int spi_send_multicommand(const struct flashctx *flash, struct spi_command *cmds);
249
250 void clear_spi_id_cache(void);
251
252 #endif /* !__SPI_H__ */