soc/mediatek/mt8196: Initialize SSPM
[coreboot.git] / src / drivers / spi / spi_flash_internal.h
bloba30f58f9a597e59685e7539feb5ddff3fe572354
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);
35 /* Send a multi-byte command to the device and read the response */
36 int spi_flash_cmd_multi(const struct spi_slave *spi, const u8 *dout, size_t bytes_out,
37 void *din, size_t bytes_in);
40 * Send a multi-byte command to the device followed by (optional)
41 * data. Used for programming the flash array, etc.
43 int spi_flash_cmd_write(const struct spi_slave *spi, const u8 *cmd,
44 size_t cmd_len, const void *data, size_t data_len);
46 /* Send a command to the device and wait for some bit to clear itself. */
47 int spi_flash_cmd_poll_bit(const struct spi_flash *flash, unsigned long timeout,
48 u8 cmd, u8 poll_bit);
51 * Send the read status command to the device and wait for the wip
52 * (write-in-progress) bit to clear itself.
54 int spi_flash_cmd_wait_ready(const struct spi_flash *flash, unsigned long timeout);
56 /* Erase sectors. */
57 int spi_flash_cmd_erase(const struct spi_flash *flash, u32 offset, size_t len);
59 /* Read status register. */
60 int spi_flash_cmd_status(const struct spi_flash *flash, u8 *reg);
62 /* Write to flash utilizing page program semantics. */
63 int spi_flash_cmd_write_page_program(const struct spi_flash *flash, u32 offset,
64 size_t len, const void *buf);
66 /* Read len bytes into buf at offset. */
67 int spi_flash_cmd_read(const struct spi_flash *flash, u32 offset, size_t len, void *buf);
69 /* Release from deep sleep an provide alternative rdid information. */
70 int stmicro_release_deep_sleep_identify(const struct spi_slave *spi, u8 *idcode);
72 struct spi_flash_part_id {
73 /* rdid command constructs 2x 16-bit id using the following method
74 * for matching after reading 5 bytes (1st byte is manuf id):
75 * id[0] = (id[1] << 8) | id[2]
76 * id[1] = (id[3] << 8) | id[4]
78 uint16_t id[2];
79 /* Log based 2 total number of sectors. */
80 uint16_t nr_sectors_shift : 4;
81 uint16_t fast_read_dual_output_support : 1; /* 1-1-2 read */
82 uint16_t fast_read_dual_io_support : 1; /* 1-2-2 read */
83 uint16_t _reserved_for_flags : 2;
84 /* Block protection. Currently used by Winbond. */
85 uint16_t protection_granularity_shift : 5;
86 uint16_t bp_bits : 3;
89 struct spi_flash_ops_descriptor {
90 uint8_t erase_cmd; /* Sector Erase */
91 uint8_t status_cmd; /* Read Status Register */
92 uint8_t pp_cmd; /* Page program command, if supported. */
93 uint8_t wren_cmd; /* Write Enable command. */
94 struct spi_flash_ops ops;
97 /* Vendor info represents a common set of organization and commands by a given
98 * vendor. One can implement multiple sets from a single vendor by having
99 * separate objects. */
100 struct spi_flash_vendor_info {
101 uint8_t id;
102 uint8_t page_size_shift : 4; /* if page programming oriented. */
103 /* Log based 2 sector size */
104 uint8_t sector_size_kib_shift : 4;
105 uint16_t nr_part_ids;
106 const struct spi_flash_part_id *ids;
107 uint16_t match_id_mask[2]; /* matching bytes of the id for this set*/
108 const struct spi_flash_ops_descriptor *desc;
109 const struct spi_flash_protection_ops *prot_ops;
110 /* Returns 0 on success. !0 otherwise. */
111 int (*after_probe)(const struct spi_flash *flash);
114 /* Manufacturer-specific probe information */
115 extern const struct spi_flash_vendor_info spi_flash_adesto_vi;
116 extern const struct spi_flash_vendor_info spi_flash_amic_vi;
117 extern const struct spi_flash_vendor_info spi_flash_atmel_vi;
118 extern const struct spi_flash_vendor_info spi_flash_eon_vi;
119 extern const struct spi_flash_vendor_info spi_flash_gigadevice_vi;
120 extern const struct spi_flash_vendor_info spi_flash_macronix_vi;
121 /* Probing order matters between the Spansion sequence. */
122 extern const struct spi_flash_vendor_info spi_flash_spansion_ext1_vi;
123 extern const struct spi_flash_vendor_info spi_flash_spansion_ext2_vi;
124 extern const struct spi_flash_vendor_info spi_flash_spansion_vi;
125 extern const struct spi_flash_vendor_info spi_flash_sst_ai_vi;
126 extern const struct spi_flash_vendor_info spi_flash_sst_vi;
127 extern const struct spi_flash_vendor_info spi_flash_stmicro1_vi;
128 extern const struct spi_flash_vendor_info spi_flash_stmicro2_vi;
129 extern const struct spi_flash_vendor_info spi_flash_stmicro3_vi;
130 extern const struct spi_flash_vendor_info spi_flash_stmicro4_vi;
131 extern const struct spi_flash_vendor_info spi_flash_winbond_vi;
132 extern const struct spi_flash_vendor_info spi_flash_issi_vi;
134 /* Page Programming Command Set with 0x20 Sector Erase command. */
135 extern const struct spi_flash_ops_descriptor spi_flash_pp_0x20_sector_desc;
136 /* Page Programming Command Set with 0xd8 Sector Erase command. */
137 extern const struct spi_flash_ops_descriptor spi_flash_pp_0xd8_sector_desc;
139 struct sfdp_rpmc_info {
140 bool flash_hardening;
141 enum {
142 SFDP_RPMC_COUNTER_BITS_32 = 0,
143 SFDP_RPMC_COUNTER_BITS_RESERVED = 1,
144 } monotonic_counter_size;
145 enum {
146 SFDP_RPMC_POLL_OP2_EXTENDED_STATUS = 0,
147 SFDP_RPMC_POLL_READ_STATUS = 1,
148 } busy_polling_method;
149 uint8_t number_of_counters;
150 uint8_t op1_write_command;
151 uint8_t op2_read_command;
152 uint64_t update_rate_s;
153 uint64_t read_counter_polling_delay_us;
154 uint64_t write_counter_polling_short_delay_us;
155 uint64_t write_counter_polling_long_delay_us;
158 /* Get RPMC information from the SPI flash's SFDP table */
159 enum cb_err spi_flash_get_sfdp_rpmc(const struct spi_flash *flash,
160 struct sfdp_rpmc_info *rpmc_info);
162 /* Fill rpmc_caps field in spi_flash struct with RPMC config from SFDP */
163 void spi_flash_fill_rpmc_caps(struct spi_flash *flash);
165 #endif /* SPI_FLASH_INTERNAL_H */