1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 /***************************************************************************
4 * Copyright (C) 2005 by Dominic Rath *
5 * Dominic.Rath@gmx.de *
6 ***************************************************************************/
8 #ifndef OPENOCD_FLASH_NOR_CFI_H
9 #define OPENOCD_FLASH_NOR_CFI_H
11 #define CFI_STATUS_POLL_MASK_DQ5_DQ6_DQ7 0xE0 /* DQ5..DQ7 */
12 #define CFI_STATUS_POLL_MASK_DQ6_DQ7 0xC0 /* DQ6..DQ7 */
14 struct cfi_flash_bank
{
20 enum target_endianness endianness
;
23 uint16_t manufacturer
;
28 /* identification string */
34 /* device-system interface */
39 uint8_t word_write_timeout_typ
;
40 uint8_t buf_write_timeout_typ
;
41 uint8_t block_erase_timeout_typ
;
42 uint8_t chip_erase_timeout_typ
;
43 uint8_t word_write_timeout_max
;
44 uint8_t buf_write_timeout_max
;
45 uint8_t block_erase_timeout_max
;
46 uint8_t chip_erase_timeout_max
;
48 uint8_t status_poll_mask
;
52 uint16_t interface_desc
;
53 uint16_t max_buf_write_size
;
54 uint8_t num_erase_regions
;
55 uint32_t *erase_region_info
;
60 /* calculated timeouts */
61 unsigned word_write_timeout
;
62 unsigned buf_write_timeout
;
63 unsigned block_erase_timeout
;
64 unsigned chip_erase_timeout
;
66 /* memory accessors */
67 int (*write_mem
)(struct flash_bank
*bank
, target_addr_t addr
,
68 uint32_t count
, const uint8_t *buffer
);
69 int (*read_mem
)(struct flash_bank
*bank
, target_addr_t addr
,
70 uint32_t count
, uint8_t *buffer
);
73 /* Intel primary extended query table
74 * as defined for the Advanced+ Boot Block Flash Memory (C3)
75 * and used by the linux kernel cfi driver (as of 2.6.14)
77 struct cfi_intel_pri_ext
{
79 uint8_t major_version
;
80 uint8_t minor_version
;
81 uint32_t feature_support
;
82 uint8_t suspend_cmd_support
;
83 uint16_t blk_status_reg_mask
;
86 uint8_t num_protection_fields
;
87 uint16_t prot_reg_addr
;
88 uint8_t fact_prot_reg_size
;
89 uint8_t user_prot_reg_size
;
93 /* Spansion primary extended query table as defined for and used by
94 * the linux kernel cfi driver (as of 2.6.15)
96 struct cfi_spansion_pri_ext
{
98 uint8_t major_version
;
99 uint8_t minor_version
;
100 uint8_t silicon_revision
; /* bits 1-0: Address Sensitive Unlock */
101 uint8_t erase_suspend
;
103 uint8_t tmp_blk_unprotected
;
104 uint8_t blk_prot_unprot
;
105 uint8_t simultaneous_ops
;
111 int _reversed_geometry
;
116 /* Atmel primary extended query table as defined for and used by
117 * the linux kernel cfi driver (as of 2.6.20+)
119 struct cfi_atmel_pri_ext
{
121 uint8_t major_version
;
122 uint8_t minor_version
;
131 CFI_UNLOCK_5555_2AAA
,
134 struct cfi_unlock_addresses
{
142 void (*fixup
)(struct flash_bank
*bank
, const void *param
);
146 int cfi_erase(struct flash_bank
*bank
, unsigned int first
, unsigned int last
);
147 int cfi_protect(struct flash_bank
*bank
, int set
, unsigned int first
,
149 int cfi_probe(struct flash_bank
*bank
);
150 int cfi_auto_probe(struct flash_bank
*bank
);
151 int cfi_protect_check(struct flash_bank
*bank
);
152 int cfi_get_info(struct flash_bank
*bank
, struct command_invocation
*cmd
);
153 int cfi_flash_bank_cmd(struct flash_bank
*bank
, unsigned int argc
, const char **argv
);
155 uint32_t cfi_flash_address(struct flash_bank
*bank
, int sector
, uint32_t offset
);
156 int cfi_spansion_unlock_seq(struct flash_bank
*bank
);
157 int cfi_send_command(struct flash_bank
*bank
, uint8_t cmd
, uint32_t address
);
158 int cfi_write_word(struct flash_bank
*bank
, uint8_t *word
, uint32_t address
);
159 int cfi_spansion_wait_status_busy(struct flash_bank
*bank
, int timeout
);
160 int cfi_reset(struct flash_bank
*bank
);
162 int cfi_target_read_memory(struct flash_bank
*bank
, target_addr_t addr
,
163 uint32_t count
, uint8_t *buffer
);
165 #define CFI_MFR_AMD 0x0001
166 #define CFI_MFR_FUJITSU 0x0004
167 #define CFI_MFR_ATMEL 0x001F
168 #define CFI_MFR_ST 0x0020 /* STMicroelectronics */
169 #define CFI_MFR_AMIC 0x0037
170 #define CFI_MFR_SST 0x00BF
171 #define CFI_MFR_MX 0x00C2
172 #define CFI_MFR_EON 0x007F
174 #define CFI_MFR_ANY 0xffff
175 #define CFI_ID_ANY 0xffff
177 #define CFI_MAX_BUS_WIDTH 4
178 #define CFI_MAX_CHIP_WIDTH 4
180 #endif /* OPENOCD_FLASH_NOR_CFI_H */