| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
#ifndef SPI_FLASH_INTERNAL_H |
| 8 |
#define SPI_FLASH_INTERNAL_H |
| 9 |
|
| 10 |
#include <types.h> |
| 11 |
|
| 12 |
|
| 13 |
#define CMD_READ_ID 0x9f |
| 14 |
|
| 15 |
#define CMD_READ_ARRAY_SLOW 0x03 |
| 16 |
#define CMD_READ_ARRAY_FAST 0x0b |
| 17 |
#define CMD_READ_ARRAY_LEGACY 0xe8 |
| 18 |
|
| 19 |
#define CMD_READ_FAST_DUAL_OUTPUT 0x3b |
| 20 |
#define CMD_READ_FAST_DUAL_IO 0xbb |
| 21 |
|
| 22 |
#define CMD_READ_STATUS 0x05 |
| 23 |
#define CMD_WRITE_ENABLE 0x06 |
| 24 |
|
| 25 |
#define CMD_ENTER_4BYTE_ADDR_MODE 0xb7 |
| 26 |
|
| 27 |
#define CMD_BLOCK_ERASE 0xD8 |
| 28 |
|
| 29 |
#define CMD_EXIT_4BYTE_ADDR_MODE 0xe9 |
| 30 |
|
| 31 |
|
| 32 |
#define STATUS_WIP 0x01 |
| 33 |
|
| 34 |
|
| 35 |
int spi_flash_cmd(const struct spi_slave *spi, u8 cmd, void *response, size_t len); |
| 36 |
|
| 37 |
|
| 38 |
int spi_flash_cmd_multi(const struct spi_slave *spi, const u8 *dout, size_t bytes_out, |
| 39 |
void *din, size_t bytes_in); |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
int spi_flash_cmd_write(const struct spi_slave *spi, const u8 *cmd, |
| 46 |
size_t cmd_len, const void *data, size_t data_len); |
| 47 |
|
| 48 |
|
| 49 |
int spi_flash_cmd_poll_bit(const struct spi_flash *flash, unsigned long timeout, |
| 50 |
u8 cmd, u8 poll_bit); |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
int spi_flash_cmd_wait_ready(const struct spi_flash *flash, unsigned long timeout); |
| 57 |
|
| 58 |
|
| 59 |
int spi_flash_cmd_erase(const struct spi_flash *flash, u32 offset, size_t len); |
| 60 |
|
| 61 |
|
| 62 |
int spi_flash_cmd_status(const struct spi_flash *flash, u8 *reg); |
| 63 |
|
| 64 |
|
| 65 |
int spi_flash_cmd_write_page_program(const struct spi_flash *flash, u32 offset, |
| 66 |
size_t len, const void *buf); |
| 67 |
|
| 68 |
|
| 69 |
int spi_flash_cmd_read(const struct spi_flash *flash, u32 offset, size_t len, void *buf); |
| 70 |
|
| 71 |
|
| 72 |
int stmicro_release_deep_sleep_identify(const struct spi_slave *spi, u8 *idcode); |
| 73 |
|
| 74 |
struct spi_flash_part_id { |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
uint16_t id[2]; |
| 81 |
|
| 82 |
uint16_t nr_sectors_shift : 4; |
| 83 |
uint16_t fast_read_dual_output_support : 1; |
| 84 |
uint16_t fast_read_dual_io_support : 1; |
| 85 |
uint16_t _reserved_for_flags : 2; |
| 86 |
|
| 87 |
uint16_t protection_granularity_shift : 5; |
| 88 |
uint16_t bp_bits : 3; |
| 89 |
}; |
| 90 |
|
| 91 |
struct spi_flash_ops_descriptor { |
| 92 |
uint8_t erase_cmd; |
| 93 |
uint8_t status_cmd; |
| 94 |
uint8_t pp_cmd; |
| 95 |
uint8_t wren_cmd; |
| 96 |
struct spi_flash_ops ops; |
| 97 |
}; |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
struct spi_flash_vendor_info { |
| 103 |
uint8_t id; |
| 104 |
uint8_t page_size_shift : 4; |
| 105 |
|
| 106 |
uint8_t sector_size_kib_shift : 4; |
| 107 |
uint16_t nr_part_ids; |
| 108 |
const struct spi_flash_part_id *ids; |
| 109 |
uint16_t match_id_mask[2]; |
| 110 |
const struct spi_flash_ops_descriptor *desc; |
| 111 |
const struct spi_flash_protection_ops *prot_ops; |
| 112 |
|
| 113 |
int (*after_probe)(const struct spi_flash *flash); |
| 114 |
}; |
| 115 |
|
| 116 |
|
| 117 |
extern const struct spi_flash_vendor_info spi_flash_adesto_vi; |
| 118 |
extern const struct spi_flash_vendor_info spi_flash_amic_vi; |
| 119 |
extern const struct spi_flash_vendor_info spi_flash_atmel_vi; |
| 120 |
extern const struct spi_flash_vendor_info spi_flash_eon_vi; |
| 121 |
extern const struct spi_flash_vendor_info spi_flash_gigadevice_vi; |
| 122 |
extern const struct spi_flash_vendor_info spi_flash_macronix_vi; |
| 123 |
|
| 124 |
extern const struct spi_flash_vendor_info spi_flash_spansion_ext1_vi; |
| 125 |
extern const struct spi_flash_vendor_info spi_flash_spansion_ext2_vi; |
| 126 |
extern const struct spi_flash_vendor_info spi_flash_spansion_vi; |
| 127 |
extern const struct spi_flash_vendor_info spi_flash_sst_ai_vi; |
| 128 |
extern const struct spi_flash_vendor_info spi_flash_sst_vi; |
| 129 |
extern const struct spi_flash_vendor_info spi_flash_stmicro1_vi; |
| 130 |
extern const struct spi_flash_vendor_info spi_flash_stmicro2_vi; |
| 131 |
extern const struct spi_flash_vendor_info spi_flash_stmicro3_vi; |
| 132 |
extern const struct spi_flash_vendor_info spi_flash_stmicro4_vi; |
| 133 |
extern const struct spi_flash_vendor_info spi_flash_winbond_vi; |
| 134 |
extern const struct spi_flash_vendor_info spi_flash_issi_vi; |
| 135 |
|
| 136 |
|
| 137 |
extern const struct spi_flash_ops_descriptor spi_flash_pp_0x20_sector_desc; |
| 138 |
|
| 139 |
extern const struct spi_flash_ops_descriptor spi_flash_pp_0xd8_sector_desc; |
| 140 |
|
| 141 |
struct sfdp_rpmc_info { |
| 142 |
bool flash_hardening; |
| 143 |
enum { |
| 144 |
SFDP_RPMC_COUNTER_BITS_32 = 0, |
| 145 |
SFDP_RPMC_COUNTER_BITS_RESERVED = 1, |
| 146 |
} monotonic_counter_size; |
| 147 |
enum { |
| 148 |
SFDP_RPMC_POLL_OP2_EXTENDED_STATUS = 0, |
| 149 |
SFDP_RPMC_POLL_READ_STATUS = 1, |
| 150 |
} busy_polling_method; |
| 151 |
uint8_t number_of_counters; |
| 152 |
uint8_t op1_write_command; |
| 153 |
uint8_t op2_read_command; |
| 154 |
uint64_t update_rate_s; |
| 155 |
uint64_t read_counter_polling_delay_us; |
| 156 |
uint64_t write_counter_polling_short_delay_us; |
| 157 |
uint64_t write_counter_polling_long_delay_us; |
| 158 |
}; |
| 159 |
|
| 160 |
|
| 161 |
enum cb_err spi_flash_get_sfdp_rpmc(const struct spi_flash *flash, |
| 162 |
struct sfdp_rpmc_info *rpmc_info); |
| 163 |
|
| 164 |
|
| 165 |
void spi_flash_fill_rpmc_caps(struct spi_flash *flash); |
| 166 |
|
| 167 |
#endif |