coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
spi_flash_internal.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 /*
4  * SPI flash internal definitions
5  */
6 
7 #ifndef SPI_FLASH_INTERNAL_H
8 #define SPI_FLASH_INTERNAL_H
9 
10 /* Common commands */
11 #define CMD_READ_ID 0x9f
12 
13 #define CMD_READ_ARRAY_SLOW 0x03
14 #define CMD_READ_ARRAY_FAST 0x0b
15 #define CMD_READ_ARRAY_LEGACY 0xe8
16 
17 #define CMD_READ_FAST_DUAL_OUTPUT 0x3b
18 #define CMD_READ_FAST_DUAL_IO 0xbb
19 
20 #define CMD_READ_STATUS 0x05
21 #define CMD_WRITE_ENABLE 0x06
22 
23 #define CMD_BLOCK_ERASE 0xD8
24 
25 #define CMD_EXIT_4BYTE_ADDR_MODE 0xe9
26 
27 /* Common status */
28 #define STATUS_WIP 0x01
29 
30 /* Send a single-byte command to the device and read the response */
31 int spi_flash_cmd(const struct spi_slave *spi, u8 cmd, void *response, size_t len);
32 
33 /*
34  * Send a multi-byte command to the device followed by (optional)
35  * data. Used for programming the flash array, etc.
36  */
37 int spi_flash_cmd_write(const struct spi_slave *spi, const u8 *cmd,
38  size_t cmd_len, const void *data, size_t data_len);
39 
40 /* Send a command to the device and wait for some bit to clear itself. */
41 int spi_flash_cmd_poll_bit(const struct spi_flash *flash, unsigned long timeout,
42  u8 cmd, u8 poll_bit);
43 
44 /*
45  * Send the read status command to the device and wait for the wip
46  * (write-in-progress) bit to clear itself.
47  */
48 int spi_flash_cmd_wait_ready(const struct spi_flash *flash, unsigned long timeout);
49 
50 /* Erase sectors. */
51 int spi_flash_cmd_erase(const struct spi_flash *flash, u32 offset, size_t len);
52 
53 /* Read status register. */
54 int spi_flash_cmd_status(const struct spi_flash *flash, u8 *reg);
55 
56 /* Write to flash utilizing page program semantics. */
57 int spi_flash_cmd_write_page_program(const struct spi_flash *flash, u32 offset,
58  size_t len, const void *buf);
59 
60 /* Read len bytes into buf at offset. */
61 int spi_flash_cmd_read(const struct spi_flash *flash, u32 offset, size_t len, void *buf);
62 
63 /* Release from deep sleep an provide alternative rdid information. */
64 int stmicro_release_deep_sleep_identify(const struct spi_slave *spi, u8 *idcode);
65 
67  /* rdid command constructs 2x 16-bit id using the following method
68  * for matching after reading 5 bytes (1st byte is manuf id):
69  * id[0] = (id[1] << 8) | id[2]
70  * id[1] = (id[3] << 8) | id[4]
71  */
72  uint16_t id[2];
73  /* Log based 2 total number of sectors. */
76  uint16_t fast_read_dual_io_support : 1; /* 1-2-2 read */
78  /* Block protection. Currently used by Winbond. */
81 };
82 
84  uint8_t erase_cmd; /* Sector Erase */
85  uint8_t status_cmd; /* Read Status Register */
86  uint8_t pp_cmd; /* Page program command, if supported. */
87  uint8_t wren_cmd; /* Write Enable command. */
88  struct spi_flash_ops ops;
89 };
90 
91 /* Vendor info represents a common set of organization and commands by a given
92  * vendor. One can implement multiple sets from a single vendor by having
93  * separate objects. */
96  uint8_t page_size_shift : 4; /* if page programming oriented. */
97  /* Log based 2 sector size */
100  const struct spi_flash_part_id *ids;
101  uint16_t match_id_mask[2]; /* matching bytes of the id for this set*/
104  /* Returns 0 on success. !0 otherwise. */
105  int (*after_probe)(const struct spi_flash *flash);
106 };
107 
108 /* Manufacturer-specific probe information */
109 extern const struct spi_flash_vendor_info spi_flash_adesto_vi;
110 extern const struct spi_flash_vendor_info spi_flash_amic_vi;
111 extern const struct spi_flash_vendor_info spi_flash_atmel_vi;
112 extern const struct spi_flash_vendor_info spi_flash_eon_vi;
114 extern const struct spi_flash_vendor_info spi_flash_macronix_vi;
115 /* Probing order matters between the spansion sequence. */
118 extern const struct spi_flash_vendor_info spi_flash_spansion_vi;
119 extern const struct spi_flash_vendor_info spi_flash_sst_ai_vi;
120 extern const struct spi_flash_vendor_info spi_flash_sst_vi;
121 extern const struct spi_flash_vendor_info spi_flash_stmicro1_vi;
122 extern const struct spi_flash_vendor_info spi_flash_stmicro2_vi;
123 extern const struct spi_flash_vendor_info spi_flash_stmicro3_vi;
124 extern const struct spi_flash_vendor_info spi_flash_stmicro4_vi;
125 extern const struct spi_flash_vendor_info spi_flash_winbond_vi;
126 
127 /* Page Programming Command Set with 0x20 Sector Erase command. */
129 /* Page Programming Command Set with 0xd8 Sector Erase command. */
131 
132 #endif /* SPI_FLASH_INTERNAL_H */
static size_t offset
Definition: flashconsole.c:16
static uint8_t * buf
Definition: uart.c:7
const struct spi_flash_ops_descriptor spi_flash_pp_0xd8_sector_desc
Definition: spi_flash.c:806
const struct spi_flash_vendor_info spi_flash_winbond_vi
Definition: winbond.c:557
int stmicro_release_deep_sleep_identify(const struct spi_slave *spi, u8 *idcode)
Definition: stmicro.c:195
int spi_flash_cmd_write_page_program(const struct spi_flash *flash, u32 offset, size_t len, const void *buf)
Definition: spi_flash.c:281
const struct spi_flash_vendor_info spi_flash_stmicro4_vi
Definition: stmicro.c:243
const struct spi_flash_vendor_info spi_flash_amic_vi
Definition: amic.c:71
const struct spi_flash_vendor_info spi_flash_adesto_vi
Definition: adesto.c:91
const struct spi_flash_vendor_info spi_flash_atmel_vi
Definition: atmel.c:61
int spi_flash_cmd_read(const struct spi_flash *flash, u32 offset, size_t len, void *buf)
Definition: spi_flash.c:142
const struct spi_flash_vendor_info spi_flash_stmicro1_vi
Definition: stmicro.c:213
const struct spi_flash_vendor_info spi_flash_sst_ai_vi
Definition: sst.c:241
int spi_flash_cmd_erase(const struct spi_flash *flash, u32 offset, size_t len)
Definition: spi_flash.c:228
const struct spi_flash_vendor_info spi_flash_spansion_ext2_vi
Definition: spansion.c:128
const struct spi_flash_vendor_info spi_flash_stmicro3_vi
Definition: stmicro.c:233
const struct spi_flash_ops_descriptor spi_flash_pp_0x20_sector_desc
Definition: spi_flash.c:793
const struct spi_flash_vendor_info spi_flash_spansion_vi
Definition: spansion.c:139
int spi_flash_cmd_wait_ready(const struct spi_flash *flash, unsigned long timeout)
Definition: spi_flash.c:221
const struct spi_flash_vendor_info spi_flash_gigadevice_vi
Definition: gigadevice.c:115
const struct spi_flash_vendor_info spi_flash_spansion_ext1_vi
Definition: spansion.c:117
const struct spi_flash_vendor_info spi_flash_macronix_vi
Definition: macronix.c:143
int spi_flash_cmd(const struct spi_slave *spi, u8 cmd, void *response, size_t len)
Definition: spi_flash.c:107
const struct spi_flash_vendor_info spi_flash_sst_vi
Definition: sst.c:251
const struct spi_flash_vendor_info spi_flash_eon_vi
Definition: eon.c:152
int spi_flash_cmd_write(const struct spi_slave *spi, const u8 *cmd, size_t cmd_len, const void *data, size_t data_len)
Definition: spi_flash.c:122
int spi_flash_cmd_status(const struct spi_flash *flash, u8 *reg)
Definition: spi_flash.c:276
int spi_flash_cmd_poll_bit(const struct spi_flash *flash, unsigned long timeout, u8 cmd, u8 poll_bit)
Definition: spi_flash.c:190
const struct spi_flash_vendor_info spi_flash_stmicro2_vi
Definition: stmicro.c:223
unsigned short uint16_t
Definition: stdint.h:11
uint32_t u32
Definition: stdint.h:51
uint8_t u8
Definition: stdint.h:45
unsigned char uint8_t
Definition: stdint.h:8
struct spi_flash_ops ops
uint16_t protection_granularity_shift
uint16_t fast_read_dual_output_support
uint16_t fast_read_dual_io_support
const struct spi_flash_protection_ops * prot_ops
const struct spi_flash_part_id * ids
const struct spi_flash_ops_descriptor * desc
int(* after_probe)(const struct spi_flash *flash)