lib/smbios: Improve Type9
[coreboot2.git] / src / drivers / spi / spi_flash_internal.h
blob131c32bec8698cfba988b2b8010a0a0549a99138
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 /*
4 * SPI flash internal definitions
5 */
7 #ifndef SPI_FLASH_INTERNAL_H
8 #define SPI_FLASH_INTERNAL_H
10 #include <types.h>
12 /* Common commands */
13 #define CMD_READ_ID 0x9f
15 #define CMD_READ_ARRAY_SLOW 0x03
16 #define CMD_READ_ARRAY_FAST 0x0b
17 #define CMD_READ_ARRAY_LEGACY 0xe8
19 #define CMD_READ_FAST_DUAL_OUTPUT 0x3b
20 #define CMD_READ_FAST_DUAL_IO 0xbb
22 #define CMD_READ_STATUS 0x05
23 #define CMD_WRITE_ENABLE 0x06
25 #define CMD_BLOCK_ERASE 0xD8
27 #define CMD_EXIT_4BYTE_ADDR_MODE 0xe9
29 /* Common status */
30 #define STATUS_WIP 0x01
32 /* Send a single-byte command to the device and read the response */
33 int spi_flash_cmd(const struct spi_slave *spi, u8 cmd, void *response, size_t len);
36 * Send a multi-byte command to the device followed by (optional)
37 * data. Used for programming the flash array, etc.
39 int spi_flash_cmd_write(const struct spi_slave *spi, const u8 *cmd,
40 size_t cmd_len, const void *data, size_t data_len);
42 /* Send a command to the device and wait for some bit to clear itself. */
43 int spi_flash_cmd_poll_bit(const struct spi_flash *flash, unsigned long timeout,
44 u8 cmd, u8 poll_bit);
47 * Send the read status command to the device and wait for the wip
48 * (write-in-progress) bit to clear itself.
50 int spi_flash_cmd_wait_ready(const struct spi_flash *flash, unsigned long timeout);
52 /* Erase sectors. */
53 int spi_flash_cmd_erase(const struct spi_flash *flash, u32 offset, size_t len);
55 /* Read status register. */
56 int spi_flash_cmd_status(const struct spi_flash *flash, u8 *reg);
58 /* Write to flash utilizing page program semantics. */
59 int spi_flash_cmd_write_page_program(const struct spi_flash *flash, u32 offset,
60 size_t len, const void *buf);
62 /* Read len bytes into buf at offset. */
63 int spi_flash_cmd_read(const struct spi_flash *flash, u32 offset, size_t len, void *buf);
65 /* Release from deep sleep an provide alternative rdid information. */
66 int stmicro_release_deep_sleep_identify(const struct spi_slave *spi, u8 *idcode);
68 struct spi_flash_part_id {
69 /* rdid command constructs 2x 16-bit id using the following method
70 * for matching after reading 5 bytes (1st byte is manuf id):
71 * id[0] = (id[1] << 8) | id[2]
72 * id[1] = (id[3] << 8) | id[4]
74 uint16_t id[2];
75 /* Log based 2 total number of sectors. */
76 uint16_t nr_sectors_shift : 4;
77 uint16_t fast_read_dual_output_support : 1; /* 1-1-2 read */
78 uint16_t fast_read_dual_io_support : 1; /* 1-2-2 read */
79 uint16_t _reserved_for_flags : 2;
80 /* Block protection. Currently used by Winbond. */
81 uint16_t protection_granularity_shift : 5;
82 uint16_t bp_bits : 3;
85 struct spi_flash_ops_descriptor {
86 uint8_t erase_cmd; /* Sector Erase */
87 uint8_t status_cmd; /* Read Status Register */
88 uint8_t pp_cmd; /* Page program command, if supported. */
89 uint8_t wren_cmd; /* Write Enable command. */
90 struct spi_flash_ops ops;
93 /* Vendor info represents a common set of organization and commands by a given
94 * vendor. One can implement multiple sets from a single vendor by having
95 * separate objects. */
96 struct spi_flash_vendor_info {
97 uint8_t id;
98 uint8_t page_size_shift : 4; /* if page programming oriented. */
99 /* Log based 2 sector size */
100 uint8_t sector_size_kib_shift : 4;
101 uint16_t nr_part_ids;
102 const struct spi_flash_part_id *ids;
103 uint16_t match_id_mask[2]; /* matching bytes of the id for this set*/
104 const struct spi_flash_ops_descriptor *desc;
105 const struct spi_flash_protection_ops *prot_ops;
106 /* Returns 0 on success. !0 otherwise. */
107 int (*after_probe)(const struct spi_flash *flash);
110 /* Manufacturer-specific probe information */
111 extern const struct spi_flash_vendor_info spi_flash_adesto_vi;
112 extern const struct spi_flash_vendor_info spi_flash_amic_vi;
113 extern const struct spi_flash_vendor_info spi_flash_atmel_vi;
114 extern const struct spi_flash_vendor_info spi_flash_eon_vi;
115 extern const struct spi_flash_vendor_info spi_flash_gigadevice_vi;
116 extern const struct spi_flash_vendor_info spi_flash_macronix_vi;
117 /* Probing order matters between the Spansion sequence. */
118 extern const struct spi_flash_vendor_info spi_flash_spansion_ext1_vi;
119 extern const struct spi_flash_vendor_info spi_flash_spansion_ext2_vi;
120 extern const struct spi_flash_vendor_info spi_flash_spansion_vi;
121 extern const struct spi_flash_vendor_info spi_flash_sst_ai_vi;
122 extern const struct spi_flash_vendor_info spi_flash_sst_vi;
123 extern const struct spi_flash_vendor_info spi_flash_stmicro1_vi;
124 extern const struct spi_flash_vendor_info spi_flash_stmicro2_vi;
125 extern const struct spi_flash_vendor_info spi_flash_stmicro3_vi;
126 extern const struct spi_flash_vendor_info spi_flash_stmicro4_vi;
127 extern const struct spi_flash_vendor_info spi_flash_winbond_vi;
128 extern const struct spi_flash_vendor_info spi_flash_issi_vi;
130 /* Page Programming Command Set with 0x20 Sector Erase command. */
131 extern const struct spi_flash_ops_descriptor spi_flash_pp_0x20_sector_desc;
132 /* Page Programming Command Set with 0xd8 Sector Erase command. */
133 extern const struct spi_flash_ops_descriptor spi_flash_pp_0xd8_sector_desc;
135 #endif /* SPI_FLASH_INTERNAL_H */