Carl-Daniel Hailfinger | d6cbf76 | 2008-05-13 14:58:23 +0000 | [diff] [blame] | 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. |
Carl-Daniel Hailfinger | d6cbf76 | 2008-05-13 14:58:23 +0000 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | #ifndef __SPI_H__ |
| 17 | #define __SPI_H__ 1 |
| 18 | |
| 19 | /* |
| 20 | * Contains the generic SPI headers |
| 21 | */ |
| 22 | |
Nico Huber | 0ecbacb | 2017-10-14 16:50:43 +0200 | [diff] [blame] | 23 | #define JEDEC_MAX_ADDR_LEN 0x04 |
| 24 | |
Carl-Daniel Hailfinger | d6cbf76 | 2008-05-13 14:58:23 +0000 | [diff] [blame] | 25 | /* Read Electronic ID */ |
| 26 | #define JEDEC_RDID 0x9f |
| 27 | #define JEDEC_RDID_OUTSIZE 0x01 |
Carl-Daniel Hailfinger | dc1cda1 | 2010-05-28 17:07:57 +0000 | [diff] [blame] | 28 | /* INSIZE may be 0x04 for some chips*/ |
Carl-Daniel Hailfinger | d6cbf76 | 2008-05-13 14:58:23 +0000 | [diff] [blame] | 29 | #define JEDEC_RDID_INSIZE 0x03 |
| 30 | |
Konstantin Grudnev | 3d8868c | 2019-07-23 00:48:54 +0300 | [diff] [blame] | 31 | /* Some ST M95X model */ |
| 32 | #define ST_M95_RDID 0x83 |
| 33 | #define ST_M95_RDID_3BA_OUTSIZE 0x04 /* 8b op, 24bit addr where size >64KiB */ |
| 34 | #define ST_M95_RDID_2BA_OUTSIZE 0x03 /* 8b op, 16bit addr where size <=64KiB */ |
| 35 | #define ST_M95_RDID_OUTSIZE_MAX 0x04 /* ST_M95_RDID_3BA_OUTSIZE */ |
| 36 | #define ST_M95_RDID_INSIZE 0x03 |
| 37 | |
Stefan Tauner | 57794ac | 2012-12-29 15:04:20 +0000 | [diff] [blame] | 38 | /* Some Atmel AT25F* models have bit 3 as don't care bit in commands */ |
| 39 | #define AT25F_RDID 0x15 /* 0x15 or 0x1d */ |
| 40 | #define AT25F_RDID_OUTSIZE 0x01 |
| 41 | #define AT25F_RDID_INSIZE 0x02 |
Carl-Daniel Hailfinger | 0faf03e | 2008-11-28 23:47:55 +0000 | [diff] [blame] | 42 | |
Carl-Daniel Hailfinger | 14e50ac | 2008-11-28 01:25:00 +0000 | [diff] [blame] | 43 | /* Read Electronic Manufacturer Signature */ |
| 44 | #define JEDEC_REMS 0x90 |
| 45 | #define JEDEC_REMS_OUTSIZE 0x04 |
| 46 | #define JEDEC_REMS_INSIZE 0x02 |
| 47 | |
Stefan Tauner | ac1b4c8 | 2012-02-17 14:51:04 +0000 | [diff] [blame] | 48 | /* Read Serial Flash Discoverable Parameters (SFDP) */ |
| 49 | #define JEDEC_SFDP 0x5a |
| 50 | #define JEDEC_SFDP_OUTSIZE 0x05 /* 8b op, 24b addr, 8b dummy */ |
| 51 | /* JEDEC_SFDP_INSIZE : any length */ |
| 52 | |
Carl-Daniel Hailfinger | 42c5497 | 2008-05-15 03:19:49 +0000 | [diff] [blame] | 53 | /* Read Electronic Signature */ |
| 54 | #define JEDEC_RES 0xab |
| 55 | #define JEDEC_RES_OUTSIZE 0x04 |
Carl-Daniel Hailfinger | dc1cda1 | 2010-05-28 17:07:57 +0000 | [diff] [blame] | 56 | /* INSIZE may be 0x02 for some chips*/ |
Carl-Daniel Hailfinger | 42c5497 | 2008-05-15 03:19:49 +0000 | [diff] [blame] | 57 | #define JEDEC_RES_INSIZE 0x01 |
| 58 | |
Carl-Daniel Hailfinger | d6cbf76 | 2008-05-13 14:58:23 +0000 | [diff] [blame] | 59 | /* Write Enable */ |
| 60 | #define JEDEC_WREN 0x06 |
| 61 | #define JEDEC_WREN_OUTSIZE 0x01 |
| 62 | #define JEDEC_WREN_INSIZE 0x00 |
| 63 | |
| 64 | /* Write Disable */ |
| 65 | #define JEDEC_WRDI 0x04 |
| 66 | #define JEDEC_WRDI_OUTSIZE 0x01 |
| 67 | #define JEDEC_WRDI_INSIZE 0x00 |
| 68 | |
| 69 | /* Chip Erase 0x60 is supported by Macronix/SST chips. */ |
| 70 | #define JEDEC_CE_60 0x60 |
| 71 | #define JEDEC_CE_60_OUTSIZE 0x01 |
| 72 | #define JEDEC_CE_60_INSIZE 0x00 |
| 73 | |
Stefan Tauner | 3c0fcd0 | 2012-09-21 12:46:56 +0000 | [diff] [blame] | 74 | /* Chip Erase 0x62 is supported by Atmel AT25F chips. */ |
| 75 | #define JEDEC_CE_62 0x62 |
| 76 | #define JEDEC_CE_62_OUTSIZE 0x01 |
| 77 | #define JEDEC_CE_62_INSIZE 0x00 |
| 78 | |
Peter Stuge | f83221b | 2008-07-07 06:38:51 +0000 | [diff] [blame] | 79 | /* Chip Erase 0xc7 is supported by SST/ST/EON/Macronix chips. */ |
Carl-Daniel Hailfinger | d6cbf76 | 2008-05-13 14:58:23 +0000 | [diff] [blame] | 80 | #define JEDEC_CE_C7 0xc7 |
| 81 | #define JEDEC_CE_C7_OUTSIZE 0x01 |
| 82 | #define JEDEC_CE_C7_INSIZE 0x00 |
| 83 | |
Stefan Tauner | 94b39b4 | 2012-10-27 00:06:02 +0000 | [diff] [blame] | 84 | /* Block Erase 0x50 is supported by Atmel AT26DF chips. */ |
| 85 | #define JEDEC_BE_50 0x50 |
| 86 | #define JEDEC_BE_50_OUTSIZE 0x04 |
| 87 | #define JEDEC_BE_50_INSIZE 0x00 |
| 88 | |
Carl-Daniel Hailfinger | d54ef6e | 2008-11-15 13:55:43 +0000 | [diff] [blame] | 89 | /* Block Erase 0x52 is supported by SST and old Atmel chips. */ |
Carl-Daniel Hailfinger | d6cbf76 | 2008-05-13 14:58:23 +0000 | [diff] [blame] | 90 | #define JEDEC_BE_52 0x52 |
| 91 | #define JEDEC_BE_52_OUTSIZE 0x04 |
| 92 | #define JEDEC_BE_52_INSIZE 0x00 |
| 93 | |
Stefan Tauner | 94b39b4 | 2012-10-27 00:06:02 +0000 | [diff] [blame] | 94 | /* Block Erase 0x81 is supported by Atmel AT26DF chips. */ |
| 95 | #define JEDEC_BE_81 0x81 |
| 96 | #define JEDEC_BE_81_OUTSIZE 0x04 |
| 97 | #define JEDEC_BE_81_INSIZE 0x00 |
| 98 | |
Nikolay Nikolaev | 6f59b0b | 2013-06-28 21:29:51 +0000 | [diff] [blame] | 99 | /* Block Erase 0xc4 is supported by Micron chips. */ |
| 100 | #define JEDEC_BE_C4 0xc4 |
| 101 | #define JEDEC_BE_C4_OUTSIZE 0x04 |
| 102 | #define JEDEC_BE_C4_INSIZE 0x00 |
| 103 | |
Carl-Daniel Hailfinger | d6cbf76 | 2008-05-13 14:58:23 +0000 | [diff] [blame] | 104 | /* Block Erase 0xd8 is supported by EON/Macronix chips. */ |
| 105 | #define JEDEC_BE_D8 0xd8 |
| 106 | #define JEDEC_BE_D8_OUTSIZE 0x04 |
| 107 | #define JEDEC_BE_D8_INSIZE 0x00 |
| 108 | |
Sean Nelson | 5643c07 | 2010-01-19 03:23:07 +0000 | [diff] [blame] | 109 | /* Block Erase 0xd7 is supported by PMC chips. */ |
| 110 | #define JEDEC_BE_D7 0xd7 |
| 111 | #define JEDEC_BE_D7_OUTSIZE 0x04 |
| 112 | #define JEDEC_BE_D7_INSIZE 0x00 |
| 113 | |
Carl-Daniel Hailfinger | d6cbf76 | 2008-05-13 14:58:23 +0000 | [diff] [blame] | 114 | /* Sector Erase 0x20 is supported by Macronix/SST chips. */ |
| 115 | #define JEDEC_SE 0x20 |
| 116 | #define JEDEC_SE_OUTSIZE 0x04 |
| 117 | #define JEDEC_SE_INSIZE 0x00 |
| 118 | |
Nikolay Nikolaev | 579f1e0 | 2013-06-28 21:28:37 +0000 | [diff] [blame] | 119 | /* Page Erase 0xDB */ |
| 120 | #define JEDEC_PE 0xDB |
| 121 | #define JEDEC_PE_OUTSIZE 0x04 |
| 122 | #define JEDEC_PE_INSIZE 0x00 |
| 123 | |
Carl-Daniel Hailfinger | d6cbf76 | 2008-05-13 14:58:23 +0000 | [diff] [blame] | 124 | /* Read Status Register */ |
| 125 | #define JEDEC_RDSR 0x05 |
| 126 | #define JEDEC_RDSR_OUTSIZE 0x01 |
| 127 | #define JEDEC_RDSR_INSIZE 0x01 |
Stefan Tauner | 5e695ab | 2012-05-06 17:03:40 +0000 | [diff] [blame] | 128 | |
Nikolai Artemiev | 9de3f87 | 2021-10-20 22:32:25 +1100 | [diff] [blame] | 129 | /* Read Status Register 2 */ |
| 130 | #define JEDEC_RDSR2 0x35 |
| 131 | #define JEDEC_RDSR2_OUTSIZE 0x01 |
| 132 | #define JEDEC_RDSR2_INSIZE 0x01 |
| 133 | |
Sergii Dmytruk | 0b2e7dd | 2021-12-19 18:37:51 +0200 | [diff] [blame] | 134 | /* Read Status Register 3 */ |
| 135 | #define JEDEC_RDSR3 0x15 |
| 136 | #define JEDEC_RDSR3_OUTSIZE 0x01 |
| 137 | #define JEDEC_RDSR3_INSIZE 0x01 |
| 138 | |
Stefan Tauner | 5e695ab | 2012-05-06 17:03:40 +0000 | [diff] [blame] | 139 | /* Status Register Bits */ |
| 140 | #define SPI_SR_WIP (0x01 << 0) |
| 141 | #define SPI_SR_WEL (0x01 << 1) |
| 142 | #define SPI_SR_AAI (0x01 << 6) |
Carl-Daniel Hailfinger | d6cbf76 | 2008-05-13 14:58:23 +0000 | [diff] [blame] | 143 | |
Jason Wang | a3f04be | 2008-11-28 21:36:51 +0000 | [diff] [blame] | 144 | /* Write Status Enable */ |
| 145 | #define JEDEC_EWSR 0x50 |
| 146 | #define JEDEC_EWSR_OUTSIZE 0x01 |
| 147 | #define JEDEC_EWSR_INSIZE 0x00 |
| 148 | |
Carl-Daniel Hailfinger | d6cbf76 | 2008-05-13 14:58:23 +0000 | [diff] [blame] | 149 | /* Write Status Register */ |
| 150 | #define JEDEC_WRSR 0x01 |
| 151 | #define JEDEC_WRSR_OUTSIZE 0x02 |
| 152 | #define JEDEC_WRSR_INSIZE 0x00 |
Nikolai Artemiev | 9de3f87 | 2021-10-20 22:32:25 +1100 | [diff] [blame] | 153 | |
| 154 | /* Write Status Register 2 */ |
| 155 | #define JEDEC_WRSR2 0x31 |
| 156 | #define JEDEC_WRSR2_OUTSIZE 0x02 |
| 157 | #define JEDEC_WRSR2_INSIZE 0x00 |
Carl-Daniel Hailfinger | d6cbf76 | 2008-05-13 14:58:23 +0000 | [diff] [blame] | 158 | |
Sergii Dmytruk | 0b2e7dd | 2021-12-19 18:37:51 +0200 | [diff] [blame] | 159 | /* Write Status Register 3 */ |
| 160 | #define JEDEC_WRSR3 0x11 |
| 161 | #define JEDEC_WRSR3_OUTSIZE 0x02 |
| 162 | #define JEDEC_WRSR3_INSIZE 0x00 |
| 163 | |
Sergii Dmytruk | 3d728e7 | 2021-11-27 15:14:27 +0200 | [diff] [blame] | 164 | /* Read Security Register */ |
| 165 | #define JEDEC_RDSCUR 0x2b |
| 166 | #define JEDEC_RDSCUR_OUTSIZE 0x01 |
| 167 | #define JEDEC_RDSCUR_INSIZE 0x01 |
| 168 | |
| 169 | /* Write Security Register */ |
| 170 | #define JEDEC_WRSCUR 0x2f |
| 171 | #define JEDEC_WRSCUR_OUTSIZE 0x01 |
| 172 | #define JEDEC_WRSCUR_INSIZE 0x00 |
| 173 | |
Sergii Dmytruk | bd72a47 | 2022-07-24 17:11:05 +0300 | [diff] [blame^] | 174 | /* Read Configuration Register */ |
| 175 | #define JEDEC_RDCR 0x15 |
| 176 | #define JEDEC_RDCR_OUTSIZE 0x01 |
| 177 | #define JEDEC_RDCR_INSIZE 0x01 |
| 178 | |
Nico Huber | 7e3c81a | 2017-10-14 18:56:50 +0200 | [diff] [blame] | 179 | /* Enter 4-byte Address Mode */ |
| 180 | #define JEDEC_ENTER_4_BYTE_ADDR_MODE 0xB7 |
| 181 | |
| 182 | /* Exit 4-byte Address Mode */ |
| 183 | #define JEDEC_EXIT_4_BYTE_ADDR_MODE 0xE9 |
| 184 | |
| 185 | /* Write Extended Address Register */ |
| 186 | #define JEDEC_WRITE_EXT_ADDR_REG 0xC5 |
Nico Huber | 9bb8a32 | 2022-05-24 15:07:34 +0200 | [diff] [blame] | 187 | #define ALT_WRITE_EXT_ADDR_REG_17 0x17 |
Nico Huber | 7e3c81a | 2017-10-14 18:56:50 +0200 | [diff] [blame] | 188 | |
| 189 | /* Read Extended Address Register */ |
| 190 | #define JEDEC_READ_EXT_ADDR_REG 0xC8 |
Nico Huber | 9bb8a32 | 2022-05-24 15:07:34 +0200 | [diff] [blame] | 191 | #define ALT_READ_EXT_ADDR_REG_16 0x16 |
Nico Huber | 7e3c81a | 2017-10-14 18:56:50 +0200 | [diff] [blame] | 192 | |
Carl-Daniel Hailfinger | d6cbf76 | 2008-05-13 14:58:23 +0000 | [diff] [blame] | 193 | /* Read the memory */ |
| 194 | #define JEDEC_READ 0x03 |
| 195 | #define JEDEC_READ_OUTSIZE 0x04 |
| 196 | /* JEDEC_READ_INSIZE : any length */ |
| 197 | |
Nico Huber | 93db6e1 | 2018-09-30 01:18:43 +0200 | [diff] [blame] | 198 | /* Read the memory (with delay after sending address) */ |
| 199 | #define JEDEC_READ_FAST 0x0b |
| 200 | |
Carl-Daniel Hailfinger | d6cbf76 | 2008-05-13 14:58:23 +0000 | [diff] [blame] | 201 | /* Write memory byte */ |
Carl-Daniel Hailfinger | d99b8d3 | 2010-07-29 16:32:24 +0000 | [diff] [blame] | 202 | #define JEDEC_BYTE_PROGRAM 0x02 |
Carl-Daniel Hailfinger | d6cbf76 | 2008-05-13 14:58:23 +0000 | [diff] [blame] | 203 | #define JEDEC_BYTE_PROGRAM_OUTSIZE 0x05 |
| 204 | #define JEDEC_BYTE_PROGRAM_INSIZE 0x00 |
| 205 | |
Carl-Daniel Hailfinger | 9c62d11 | 2010-06-20 10:41:35 +0000 | [diff] [blame] | 206 | /* Write AAI word (SST25VF080B) */ |
Carl-Daniel Hailfinger | d99b8d3 | 2010-07-29 16:32:24 +0000 | [diff] [blame] | 207 | #define JEDEC_AAI_WORD_PROGRAM 0xad |
| 208 | #define JEDEC_AAI_WORD_PROGRAM_OUTSIZE 0x06 |
| 209 | #define JEDEC_AAI_WORD_PROGRAM_CONT_OUTSIZE 0x03 |
| 210 | #define JEDEC_AAI_WORD_PROGRAM_INSIZE 0x00 |
Carl-Daniel Hailfinger | 9c62d11 | 2010-06-20 10:41:35 +0000 | [diff] [blame] | 211 | |
Nico Huber | 7e3c81a | 2017-10-14 18:56:50 +0200 | [diff] [blame] | 212 | /* Read the memory with 4-byte address |
| 213 | From ANY mode (3-bytes or 4-bytes) it works with 4-byte address */ |
| 214 | #define JEDEC_READ_4BA 0x13 |
| 215 | |
Nico Huber | 93db6e1 | 2018-09-30 01:18:43 +0200 | [diff] [blame] | 216 | /* Read the memory with 4-byte address (and delay after sending address) |
| 217 | From ANY mode (3-bytes or 4-bytes) it works with 4-byte address */ |
| 218 | #define JEDEC_READ_4BA_FAST 0x0c |
| 219 | |
Nico Huber | 7e3c81a | 2017-10-14 18:56:50 +0200 | [diff] [blame] | 220 | /* Write memory byte with 4-byte address |
| 221 | From ANY mode (3-bytes or 4-bytes) it works with 4-byte address */ |
| 222 | #define JEDEC_BYTE_PROGRAM_4BA 0x12 |
| 223 | |
Carl-Daniel Hailfinger | 3e9dbea | 2009-05-13 11:40:08 +0000 | [diff] [blame] | 224 | /* Error codes */ |
Carl-Daniel Hailfinger | 5cca01f | 2009-11-24 00:20:03 +0000 | [diff] [blame] | 225 | #define SPI_GENERIC_ERROR -1 |
Carl-Daniel Hailfinger | 3e9dbea | 2009-05-13 11:40:08 +0000 | [diff] [blame] | 226 | #define SPI_INVALID_OPCODE -2 |
| 227 | #define SPI_INVALID_ADDRESS -3 |
Carl-Daniel Hailfinger | 142e30f | 2009-07-14 10:26:56 +0000 | [diff] [blame] | 228 | #define SPI_INVALID_LENGTH -4 |
Nico Huber | c3b02dc | 2023-08-12 01:13:45 +0200 | [diff] [blame] | 229 | #define SPI_FLASHPROG_BUG -5 |
Carl-Daniel Hailfinger | eb0e7fc | 2010-08-18 15:12:43 +0000 | [diff] [blame] | 230 | #define SPI_PROGRAMMER_ERROR -6 |
Carl-Daniel Hailfinger | 3e9dbea | 2009-05-13 11:40:08 +0000 | [diff] [blame] | 231 | |
Carl-Daniel Hailfinger | d6cbf76 | 2008-05-13 14:58:23 +0000 | [diff] [blame] | 232 | #endif /* !__SPI_H__ */ |