Callisto4Bootloader: drivers/flexspi_nor_flash.h Source File

Callisto4Bootloader

flexspi_nor_flash.h
Go to the documentation of this file.
1 /*
2 * Copyright 2014-2015 Freescale Semiconductor, Inc.
3 * Copyright 2016-2018 NXP
4 * All rights reserved.
5 *
6 * SPDX-License-Identifier: BSD-3-Clause
7 *
8 */
9
10 #ifndef __FLEXSPI_NOR_FLASH_H__
11 #define __FLEXSPI_NOR_FLASH_H__
12
13 #include <fsl_flexspi.h>
14 #include "fsl_common.h"
15 #include "bootloader_common.h"
16
17 /* */
18 #define NOR_CMD_INDEX_READ CMD_INDEX_READ
19 #define NOR_CMD_INDEX_READSTATUS CMD_INDEX_READSTATUS
20 #define NOR_CMD_INDEX_WRITEENABLE CMD_INDEX_WRITEENABLE
21 #define NOR_CMD_INDEX_ERASESECTOR 3
22 #define NOR_CMD_INDEX_PAGEPROGRAM CMD_INDEX_WRITE
23 #define NOR_CMD_INDEX_CHIPERASE 5
24 #define NOR_CMD_INDEX_DUMMY 6
25 #define NOR_CMD_INDEX_ERASEBLOCK 7
26
27 #define NOR_CMD_LUT_SEQ_IDX_READ CMD_LUT_SEQ_IDX_READ
28 #define NOR_CMD_LUT_SEQ_IDX_READSTATUS \
29 CMD_LUT_SEQ_IDX_READSTATUS
30 #define NOR_CMD_LUT_SEQ_IDX_READSTATUS_XPI \
31 2
32 #define NOR_CMD_LUT_SEQ_IDX_WRITEENABLE \
33 CMD_LUT_SEQ_IDX_WRITEENABLE
34 #define NOR_CMD_LUT_SEQ_IDX_WRITEENABLE_XPI \
35 4
36 #define NOR_CMD_LUT_SEQ_IDX_ERASESECTOR 5
37 #define NOR_CMD_LUT_SEQ_IDX_ERASEBLOCK 8
38 #define NOR_CMD_LUT_SEQ_IDX_PAGEPROGRAM \
39 CMD_LUT_SEQ_IDX_WRITE
40 #define NOR_CMD_LUT_SEQ_IDX_CHIPERASE 11
41 #define NOR_CMD_LUT_SEQ_IDX_READ_SFDP 13
42 #define NOR_CMD_LUT_SEQ_IDX_RESTORE_NOCMD \
43 14
44 #define NOR_CMD_LUT_SEQ_IDX_EXIT_NOCMD \
45 15
46
47 /* FlexSPI NOR status */
48 enum _flexspi_nor_status
49 {
50 kStatus_FLEXSPINOR_ProgramFail = MAKE_STATUS(kStatusGroup_FLEXSPINOR, 0),
51 kStatus_FLEXSPINOR_EraseSectorFail = MAKE_STATUS(kStatusGroup_FLEXSPINOR, 1),
52 kStatus_FLEXSPINOR_EraseAllFail = MAKE_STATUS(kStatusGroup_FLEXSPINOR, 2),
53 kStatus_FLEXSPINOR_WaitTimeout = MAKE_STATUS(kStatusGroup_FLEXSPINOR, 3),
54 kStatus_FlexSPINOR_NotSupported = MAKE_STATUS(kStatusGroup_FLEXSPINOR, 4), // Status for PageSize overflow
55 kStatus_FlexSPINOR_WriteAlignmentError = MAKE_STATUS(kStatusGroup_FLEXSPINOR, 5),
56 kStatus_FlexSPINOR_CommandFailure =
57 MAKE_STATUS(kStatusGroup_FLEXSPINOR, 6),
58 kStatus_FlexSPINOR_SFDP_NotFound = MAKE_STATUS(kStatusGroup_FLEXSPINOR, 7),
59 kStatus_FLEXSPINOR_Unsupported_SFDP_Version =
60 MAKE_STATUS(kStatusGroup_FLEXSPINOR, 8),
61 kStatus_FLEXSPINOR_Flash_NotFound = MAKE_STATUS(kStatusGroup_FLEXSPINOR, 9),
62 kStatus_FLEXSPINOR_DTRRead_DummyProbeFailed =
63 MAKE_STATUS(kStatusGroup_FLEXSPINOR, 10),
64 };
65
66 enum
67 {
68 kSerialNorCfgOption_Tag = 0x0c,
69 kSerialNorCfgOption_DeviceType_ReadSFDP_SDR = 0,
70 kSerialNorCfgOption_DeviceType_ReadSFDP_DDR = 1,
71 kSerialNorCfgOption_DeviceType_HyperFLASH1V8 = 2,
72 kSerialNorCfgOption_DeviceType_HyperFLASH3V0 = 3,
73 kSerialNorCfgOption_DeviceType_MacronixOctalDDR = 4,
74 kSerialNorCfgOption_DeviceType_MacronixOctalSDR = 5,
75 kSerialNorCfgOption_DeviceType_MicronOctalDDR = 6,
76 kSerialNorCfgOption_DeviceType_MicronOctalSDR = 7,
77 kSerialNorCfgOption_DeviceType_AdestoOctalDDR = 8,
78 kSerialNorCfgOption_DeviceType_AdestoOctalSDR = 9,
79 };
80
81 enum
82 {
83 kSerialNorQuadMode_NotConfig = 0,
84 kSerialNorQuadMode_StatusReg1_Bit6 = 1,
85 kSerialNorQuadMode_StatusReg2_Bit1 = 2,
86 kSerialNorQuadMode_StatusReg2_Bit7 = 3,
87 kSerialNorQuadMode_StatusReg2_Bit1_0x31 = 4,
88 };
89
90 enum
91 {
92 kSerialNorEnhanceMode_Disabled = 0,
93 kSerialNorEnhanceMode_0_4_4_Mode = 1,
94 kSerialNorEnhanceMode_0_8_8_Mode = 2,
95 kSerialNorEnhanceMode_DataOrderSwapped = 3,
96 kSerialNorEnhanceMode_2ndPinMux = 4,
97 };
98
99 enum
100 {
101 kSerialNorConnection_SinglePortA,
102 kSerialNorConnection_Parallel,
103 kSerialNorConnection_SinglePortB,
104 kSerialNorConnection_BothPorts
105 };
106
107 /*
108 * Serial NOR Configuration Option
109 */
110 typedef struct _serial_nor_config_option
111 {
112 union
113 {
114 struct
115 {
116 uint32_t max_freq : 4;
117 uint32_t misc_mode : 4;
118 uint32_t quad_mode_setting : 4;
119 uint32_t cmd_pads : 4;
120 uint32_t query_pads : 4;
121 uint32_t device_type : 4;
122 uint32_t option_size : 4;
123 uint32_t tag : 4;
124 } B;
125 uint32_t U;
126 } option0;
127
128 union
129 {
130 struct
131 {
132 uint32_t dummy_cycles : 8;
133 uint32_t status_override : 8;
134 uint32_t pinmux_group : 4;
135 uint32_t dqs_pinmux_group : 4;
136 uint32_t drive_strength : 4;
137 uint32_t flash_connection : 4;
138 } B;
140 uint32_t U;
141 } option1;
142
143 } serial_nor_config_option_t;
144
145 typedef union
146 {
147 struct
148 {
149 uint8_t por_mode;
150 uint8_t current_mode;
151 uint8_t exit_no_cmd_sequence;
152 uint8_t restore_sequence;
153 } B;
154 uint32_t U;
155 } flash_run_context_t;
156
157 enum
158 {
159 kRestoreSequence_None = 0,
160 kRestoreSequence_HW_Reset = 1,
161 kRestoreSequence_4QPI_FF = 2,
162 kRestoreSequence_5QPI_FF = 3,
163 kRestoreSequence_8QPI_FF = 4,
164 kRestoreSequence_Send_F0 = 5,
165 kRestoreSequence_Send_66_99 = 6,
166 kRestoreSequence_Send_6699_9966 = 7,
167 kRestoreSequence_Send_06_FF, // Adesto EcoXIP
168 };
169
170 enum
171 {
172 kFlashInstMode_ExtendedSpi = 0x00,
173 kFlashInstMode_0_4_4_SDR = 0x01,
174 kFlashInstMode_0_4_4_DDR = 0x02,
175 kFlashInstMode_QPI_SDR = 0x41,
176 kFlashInstMode_QPI_DDR = 0x42,
177 kFlashInstMode_OPI_SDR = 0x81,
178 kFlashInstMode_OPI_DDR = 0x82,
179 };
180
181 /*
182 * Serial NOR configuration block
183 */
184 typedef struct _flexspi_nor_config
185 {
186 flexspi_mem_config_t memConfig;
187 uint32_t pageSize;
188 uint32_t sectorSize;
189 uint8_t ipcmdSerialClkFreq;
190 uint8_t isUniformBlockSize;
191 uint8_t isDataOrderSwapped;
192 uint8_t reserved0[1];
193 uint8_t serialNorType;
194 uint8_t needExitNoCmdMode;
195 uint8_t halfClkForNonReadCmd;
196 uint8_t needRestoreNoCmdMode;
197 uint32_t blockSize;
198 uint32_t reserve2[11];
199 } flexspi_nor_config_t;
200
201 #ifdef __cplusplus
202 extern "C" {
203 #endif
204
206 status_t flexspi_nor_flash_init(uint32_t instance, flexspi_nor_config_t *config);
207
209 status_t flexspi_nor_flash_page_program(uint32_t instance,
210 flexspi_nor_config_t *config,
211 uint32_t dstAddr,
212 const uint32_t *src);
213
215 status_t flexspi_nor_flash_erase_all(uint32_t instance, flexspi_nor_config_t *config);
216
218 status_t flexspi_nor_flash_erase_sector(uint32_t instance, flexspi_nor_config_t *config, uint32_t address);
219
221 status_t flexspi_nor_flash_erase_block(uint32_t instance, flexspi_nor_config_t *config, uint32_t address);
222
224 status_t flexspi_nor_get_config(uint32_t instance, flexspi_nor_config_t *config, serial_nor_config_option_t *option);
225
227 status_t flexspi_nor_flash_erase(uint32_t instance, flexspi_nor_config_t *config, uint32_t start, uint32_t length);
228
230 status_t flexspi_nor_flash_read(
231 uint32_t instance, flexspi_nor_config_t *config, uint32_t *dst, uint32_t start, uint32_t bytes);
232
234 extern status_t flexspi_nor_write_persistent(const uint32_t data);
235
237 extern status_t flexspi_nor_read_persistent(uint32_t *data);
238
240 status_t flexspi_nor_restore_spi_protocol(uint32_t instance,
241 flexspi_nor_config_t *config,
242 flash_run_context_t *run_ctx);
243
244 #ifdef __cplusplus
245 }
246 #endif
247
248 #endif // __FLEXSPI_NOR_FLASH_H__
kSerialNorConnection_BothPorts
Definition: flexspi_nor_flash.h:104
_serial_nor_config_option::option0
union _serial_nor_config_option::@75 option0
kFlashInstMode_0_4_4_SDR
Definition: flexspi_nor_flash.h:173
flexspi_nor_flash_page_program
status_t flexspi_nor_flash_page_program(uint32_t instance, flexspi_nor_config_t *config, uint32_t dstAddr, const uint32_t *src)
Program data to Serial NOR via FlexSPI.
_flexspi_nor_config::ipcmdSerialClkFreq
uint8_t ipcmdSerialClkFreq
Clock frequency for IP command.
Definition: flexspi_nor_flash.h:189
fsl_flexspi.h
kStatus_FLEXSPINOR_DTRRead_DummyProbeFailed
Status for DDR Read dummy probe failure.
Definition: flexspi_nor_flash.h:62
flexspi_nor_flash_read
status_t flexspi_nor_flash_read(uint32_t instance, flexspi_nor_config_t *config, uint32_t *dst, uint32_t start, uint32_t bytes)
Read data from Serial NOR.
serial_nor_config_option_t
struct _serial_nor_config_option serial_nor_config_option_t
_flexspi_nor_config::halfClkForNonReadCmd
uint8_t halfClkForNonReadCmd
Half the Serial Clock for non-read command: true/false.
Definition: flexspi_nor_flash.h:195
kRestoreSequence_Send_6699_9966
Definition: flexspi_nor_flash.h:166
_flexspi_nor_config::reserved0
uint8_t reserved0[1]
Reserved for future use.
Definition: flexspi_nor_flash.h:192
kSerialNorCfgOption_DeviceType_HyperFLASH3V0
Definition: flexspi_nor_flash.h:72
kFlashInstMode_0_4_4_DDR
Definition: flexspi_nor_flash.h:174
kStatus_FLEXSPINOR_Unsupported_SFDP_Version
Status for Unrecognized SFDP version.
Definition: flexspi_nor_flash.h:59
kFlashInstMode_QPI_DDR
Definition: flexspi_nor_flash.h:176
kSerialNorQuadMode_StatusReg2_Bit7
Definition: flexspi_nor_flash.h:86
kSerialNorCfgOption_Tag
Definition: flexspi_nor_flash.h:68
_flexspi_nor_config::blockSize
uint32_t blockSize
Block size.
Definition: flexspi_nor_flash.h:197
kSerialNorCfgOption_DeviceType_MacronixOctalSDR
Definition: flexspi_nor_flash.h:74
kFlashInstMode_OPI_DDR
Definition: flexspi_nor_flash.h:178
_flexspi_nor_config::serialNorType
uint8_t serialNorType
Serial NOR Flash type: 0/1/2/3.
Definition: flexspi_nor_flash.h:193
bootloader_common.h
kStatus_FLEXSPINOR_ProgramFail
Status for Page programming failure.
Definition: flexspi_nor_flash.h:50
_serial_nor_config_option::option1
union _serial_nor_config_option::@76 option1
flash_run_context_t::restore_sequence
uint8_t restore_sequence
Definition: flexspi_nor_flash.h:152
kStatus_FlexSPINOR_NotSupported
Definition: flexspi_nor_flash.h:54
kStatus_FLEXSPINOR_WaitTimeout
Status for timeout.
Definition: flexspi_nor_flash.h:53
kSerialNorCfgOption_DeviceType_ReadSFDP_DDR
Definition: flexspi_nor_flash.h:70
kStatus_FlexSPINOR_SFDP_NotFound
Status for SFDP read failure.
Definition: flexspi_nor_flash.h:58
kSerialNorCfgOption_DeviceType_AdestoOctalDDR
Definition: flexspi_nor_flash.h:77
kSerialNorCfgOption_DeviceType_HyperFLASH1V8
Definition: flexspi_nor_flash.h:71
flexspi_nor_config_t
struct _flexspi_nor_config flexspi_nor_config_t
flash_run_context_t
Definition: flexspi_nor_flash.h:145
_flexspi_nor_config::needExitNoCmdMode
uint8_t needExitNoCmdMode
Need to exit NoCmd mode before other IP command.
Definition: flexspi_nor_flash.h:194
_flexspi_nor_config::needRestoreNoCmdMode
uint8_t needRestoreNoCmdMode
Need to Restore NoCmd mode after IP commmand execution.
Definition: flexspi_nor_flash.h:196
kSerialNorConnection_SinglePortB
Definition: flexspi_nor_flash.h:103
_serial_nor_config_option::misc_mode
uint32_t misc_mode
miscellaneous mode
Definition: flexspi_nor_flash.h:117
_serial_nor_config_option::device_type
uint32_t device_type
Device type.
Definition: flexspi_nor_flash.h:121
kStatus_FLEXSPINOR_EraseAllFail
Status for Chip Erase failure.
Definition: flexspi_nor_flash.h:52
_serial_nor_config_option::U
uint32_t U
Definition: flexspi_nor_flash.h:125
kSerialNorConnection_SinglePortA
Definition: flexspi_nor_flash.h:101
kSerialNorConnection_Parallel
Definition: flexspi_nor_flash.h:102
_flexspi_nor_config::isUniformBlockSize
uint8_t isUniformBlockSize
Sector/Block size is the same.
Definition: flexspi_nor_flash.h:190
flexspi_nor_flash_erase
status_t flexspi_nor_flash_erase(uint32_t instance, flexspi_nor_config_t *config, uint32_t start, uint32_t length)
Erase Flash Region specified by address and length.
kRestoreSequence_HW_Reset
Definition: flexspi_nor_flash.h:160
kRestoreSequence_4QPI_FF
Definition: flexspi_nor_flash.h:161
flexspi_nor_flash_erase_all
status_t flexspi_nor_flash_erase_all(uint32_t instance, flexspi_nor_config_t *config)
Erase all the Serial NOR devices connected on FlexSPI.
flexspi_nor_flash_erase_sector
status_t flexspi_nor_flash_erase_sector(uint32_t instance, flexspi_nor_config_t *config, uint32_t address)
Erase one sector specified by address.
_serial_nor_config_option::cmd_pads
uint32_t cmd_pads
Command pads.
Definition: flexspi_nor_flash.h:119
_flexspi_nor_config::pageSize
uint32_t pageSize
Page size of Serial NOR.
Definition: flexspi_nor_flash.h:187
kSerialNorEnhanceMode_Disabled
Definition: flexspi_nor_flash.h:92
_serial_nor_config_option::flash_connection
uint32_t flash_connection
Definition: flexspi_nor_flash.h:137
_flexspi_nor_status
_flexspi_nor_status
Definition: flexspi_nor_flash.h:48
kSerialNorEnhanceMode_2ndPinMux
Definition: flexspi_nor_flash.h:96
flexspi_nor_flash_erase_block
status_t flexspi_nor_flash_erase_block(uint32_t instance, flexspi_nor_config_t *config, uint32_t address)
Erase one block specified by address.
flash_run_context_t::por_mode
uint8_t por_mode
Definition: flexspi_nor_flash.h:149
flexspi_nor_restore_spi_protocol
status_t flexspi_nor_restore_spi_protocol(uint32_t instance, flexspi_nor_config_t *config, flash_run_context_t *run_ctx)
Restore Flash to SPI protocol.
kFlashInstMode_ExtendedSpi
Definition: flexspi_nor_flash.h:172
_serial_nor_config_option::option_size
uint32_t option_size
Option size, in terms of uint32_t, size = (option_size + 1) * 4.
Definition: flexspi_nor_flash.h:122
kStatus_FlexSPINOR_CommandFailure
Status for Erase/Program Verify Error.
Definition: flexspi_nor_flash.h:56
_serial_nor_config_option::tag
uint32_t tag
Tag, must be 0x0E.
Definition: flexspi_nor_flash.h:123
kSerialNorCfgOption_DeviceType_MacronixOctalDDR
Definition: flexspi_nor_flash.h:73
kSerialNorEnhanceMode_0_8_8_Mode
Definition: flexspi_nor_flash.h:94
_serial_nor_config_option::B
struct _serial_nor_config_option::@75::@77 B
flexspi_nor_get_config
status_t flexspi_nor_get_config(uint32_t instance, flexspi_nor_config_t *config, serial_nor_config_option_t *option)
Get FlexSPI NOR Configuration Block based on specified option.
_flexspi_nor_config::memConfig
flexspi_mem_config_t memConfig
Common memory configuration info via FlexSPI.
Definition: flexspi_nor_flash.h:186
_serial_nor_config_option::query_pads
uint32_t query_pads
SFDP read pads.
Definition: flexspi_nor_flash.h:120
flash_run_context_t::current_mode
uint8_t current_mode
Definition: flexspi_nor_flash.h:150
kRestoreSequence_Send_66_99
Definition: flexspi_nor_flash.h:165
kRestoreSequence_Send_F0
Definition: flexspi_nor_flash.h:164
flexspi_nor_flash_init
status_t flexspi_nor_flash_init(uint32_t instance, flexspi_nor_config_t *config)
Initialize Serial NOR devices via FlexSPI.
kFlashInstMode_OPI_SDR
Definition: flexspi_nor_flash.h:177
kStatus_FlexSPINOR_WriteAlignmentError
Status for Alignement error.
Definition: flexspi_nor_flash.h:55
_serial_nor_config_option::dummy_cycles
uint32_t dummy_cycles
Dummy cycles before read.
Definition: flexspi_nor_flash.h:132
kSerialNorEnhanceMode_DataOrderSwapped
Definition: flexspi_nor_flash.h:95
kRestoreSequence_None
Definition: flexspi_nor_flash.h:159
kStatus_FLEXSPINOR_EraseSectorFail
Status for Sector Erase failure.
Definition: flexspi_nor_flash.h:51
kSerialNorCfgOption_DeviceType_MicronOctalSDR
Definition: flexspi_nor_flash.h:76
kRestoreSequence_5QPI_FF
Definition: flexspi_nor_flash.h:162
kSerialNorCfgOption_DeviceType_AdestoOctalSDR
Definition: flexspi_nor_flash.h:78
kStatusGroup_FLEXSPINOR
FlexSPINOR status group number.
Definition: bootloader_common.h:123
_flexspi_nor_config::isDataOrderSwapped
uint8_t isDataOrderSwapped
Data order (D0, D1, D2, D3) is swapped (D1,D0, D3, D2)
Definition: flexspi_nor_flash.h:191
kSerialNorQuadMode_StatusReg1_Bit6
Definition: flexspi_nor_flash.h:84
_flexspi_nor_config::sectorSize
uint32_t sectorSize
Sector size of Serial NOR.
Definition: flexspi_nor_flash.h:188
flexspi_nor_write_persistent
status_t flexspi_nor_write_persistent(const uint32_t data)
Write FlexSPI persistent content.
_serial_nor_config_option::drive_strength
uint32_t drive_strength
The Drive Strength of FlexSPI Pads.
Definition: flexspi_nor_flash.h:136
kSerialNorCfgOption_DeviceType_MicronOctalDDR
Definition: flexspi_nor_flash.h:75
_serial_nor_config_option::pinmux_group
uint32_t pinmux_group
The pinmux group selection.
Definition: flexspi_nor_flash.h:134
flexspi_nor_read_persistent
status_t flexspi_nor_read_persistent(uint32_t *data)
Read FlexSPI persistent content.
kSerialNorQuadMode_StatusReg2_Bit1_0x31
Definition: flexspi_nor_flash.h:87
_serial_nor_config_option::quad_mode_setting
uint32_t quad_mode_setting
Quad mode setting.
Definition: flexspi_nor_flash.h:118
kSerialNorQuadMode_NotConfig
Definition: flexspi_nor_flash.h:83
kSerialNorEnhanceMode_0_4_4_Mode
Definition: flexspi_nor_flash.h:93
kRestoreSequence_Send_06_FF
Definition: flexspi_nor_flash.h:167
_serial_nor_config_option
Definition: flexspi_nor_flash.h:110
_serial_nor_config_option::dqs_pinmux_group
uint32_t dqs_pinmux_group
The DQS Pinmux Group Selection.
Definition: flexspi_nor_flash.h:135
_flexspi_nor_config::reserve2
uint32_t reserve2[11]
Reserved for future use.
Definition: flexspi_nor_flash.h:198
kStatus_FLEXSPINOR_Flash_NotFound
Status for Flash detection failure.
Definition: flexspi_nor_flash.h:61
_FlexSPIConfig
FlexSPI Memory Configuration Block.
Definition: fsl_flexspi.h:191
kFlashInstMode_QPI_SDR
Definition: flexspi_nor_flash.h:175
flash_run_context_t::U
uint32_t U
Definition: flexspi_nor_flash.h:154
kRestoreSequence_8QPI_FF
Definition: flexspi_nor_flash.h:163
kSerialNorQuadMode_StatusReg2_Bit1
Definition: flexspi_nor_flash.h:85
_flexspi_nor_config
Definition: flexspi_nor_flash.h:184
flash_run_context_t::exit_no_cmd_sequence
uint8_t exit_no_cmd_sequence
Definition: flexspi_nor_flash.h:151
_serial_nor_config_option::status_override
uint32_t status_override
Override status register value during device mode configuration.
Definition: flexspi_nor_flash.h:133
kSerialNorCfgOption_DeviceType_ReadSFDP_SDR
Definition: flexspi_nor_flash.h:69
_serial_nor_config_option::max_freq
uint32_t max_freq
Maximum supported Frequency.
Definition: flexspi_nor_flash.h:116