1 /*
2  * Copyright 2024 NXP
3  * All rights reserved.
4  *
5  *
6  * SPDX-License-Identifier: BSD-3-Clause
7  */
8 
9 #include "fsl_xspi.h"
10 #include "fsl_sfdp_parser.h"
11 
12 /*******************************************************************************
13  * Definitions
14  ******************************************************************************/
15 
16 #define NOR_CMD_LUT_SEQ_IDX_READ        0U  /*!< Read LUT sequence id in lookupTable stored in config block*/
17 #define NOR_CMD_LUT_SEQ_IDX_READSTATUS  1U  /*!< Read Status LUT sequence id in lookupTable stored in config block*/
18 #define NOR_CMD_LUT_SEQ_IDX_WRITESTATUS 2U  /*!< Write Status LUT sequence id in lookupTable stored in config block*/
19 #define NOR_CMD_LUT_SEQ_IDX_WRITEENABLE 3U  /*!< Write enable LUT sequence id in lookupTable stored in config block*/
20 #define NOR_CMD_LUT_SEQ_IDX_WRITECONFIG                                                                              \
21     4U                                      /*!< Write configuration LUT sequence id in lookupTable stored in config \
22                                                block*/
23 #define NOR_CMD_LUT_SEQ_IDX_ERASESECTOR 5U  /*!< Erase sector LUT sequence id in lookupTable stored in config block*/
24 #define NOR_CMD_LUT_SEQ_IDX_READCONFIG                                                                              \
25     6U                                      /*!< Read configuration LUT sequence id in lookupTable stored in config \
26                                                block*/
27 
28 #define NOR_CMD_LUT_SEQ_IDX_RESTORESPI                                                                              \
29     7U                                      /*!< Restore standard SPI mode LUT sequence id in lookupTable stored in \
30                                                config block*/
31 #define NOR_CMD_LUT_SEQ_IDX_READID                                                                                   \
32     8U                                      /*!< Read manifacture ID LUT sequence id in lookupTable stored in config \
33                                                block*/
34 #define NOR_CMD_LUT_SEQ_IDX_PAGEPROGRAM 9U  /*!< Page program LUT sequence id in lookupTable stored in config block*/
35 #define NOR_CMD_LUT_SEQ_IDX_CHIPERASE   11U /*!< Chip erase LUT sequence id in lookupTable stored in config block*/
36 #define NOR_CMD_LUT_SEQ_IDX_ERASEBLOCK  12U /*!< Block erase LUT sequence id in lookupTable stored in config block*/
37 
38 #define NOR_CMD_LUT_SEQ_IDX_ALT       (13U)
39 
40 #define NOR_CMD_LUT_SEQ_IDX_READ_SFDP                                                                          \
41     13U                                     /*!< Read SFDP information sequence id in lookupTable id stored in \
42                                                config block*/
43 #define NOR_CMD_LUT_SEQ_IDX_EXIT_NOCMD \
44     15U /*!< Exit 0-4-4/0-8-8 mode sequence id in lookupTable stored in config block*/
45 
46 /*!
47  * @brief The structure of AHB access configuration.
48  *
49  */
50 typedef struct _xspi_nor_ahb_access_config
51 {
52     bool enableAhbWrite; /*!< Enable AHB write to external NOR flash. */
53     xspi_ahbBuffer_config_t ahbBuffer0Config;  /*!< AHB buffer 0 configuration. */
54     xspi_ahbBuffer_config_t ahbBuffer1Config;  /*!< AHB buffer 1 configuration. */
55     xspi_ahbBuffer_config_t ahbBuffer2Config;  /*!< AHB buffer 2 configuration. */
56     xspi_ahbBuffer_config_t ahbBuffer3Config;  /*!< AHB buffer 3 configuration. */
57     bool enablePrefetch;   /*!< Specify if enable prefetch.  */
58 } xspi_nor_ahb_access_config_t;
59 
60 /*!
61  * @brief The structure of IP access configuration.
62  *
63  */
64 typedef struct _xspi_nor_ip_access_config
65 {
66     xspi_sfp_frad_config_t *ptrSfpFradConfig; /*!< Pointer to the variable in type of @ref xspi_sfp_mdad_config_t to
67                                         set SFP MDAD feature, set as NULL to disable SFP MDAD feature.  */
68     xspi_sfp_mdad_config_t *ptrSfpMdadConfig; /*!< Pointer to the variable in type of @ref xspi_sfp_frad_config_t to
69                                         set SFP FRAD feature, set as NULL to disable SFP FRAD feature. */
70     uint32_t ipAccessTimeoutValue;            /*!< Specify the maximum time in IPS clock cycles for XSPI to wait fro an
71                                                 ongoing write or read command to complete before terminating the command. */
72     uint32_t sfpArbitrationLockTimeoutValue;  /*!< Specify the time in IPS clock cycles before an unreleased
73                                             arbitration triggers a timeout error. */
74 } xspi_nor_ip_access_config_t;
75 
76 /*!
77  * @brief The structure of xspi memory.
78  *
79  */
80 typedef struct _xspi_memory_config
81 {
82     bool enableXspiDoze;        /*!< Enable/disable XSPI Doze mode. */
83     uint32_t *ptrCustomLut;     /*!< Pointer to the costumed LUT. */
84     xspi_pad_t numPadUsed;      /*!< Number of data pad. */
85     bool enableClknPad;         /*!< Enable/disable CLKn pad. */
86     xspi_sample_clk_config_t sampleClkConfig; /*!< Sample clock configuration. */
87     xspi_device_addr_mode_t addrMode;   /*!< Address mode of xspi. */
88     uint32_t xspiRootClk;   /*!< The frequency of xspi clock. */
89     xspi_target_group_t tgId;   /*!< Target ID used for IP access. */
90 
91     xspi_nor_ahb_access_config_t *ptrXspiNorAhbAccessConfig; /*!< Pointer to the AHB access configuration, set as NULL
92                                                         to use default settings. */
93     xspi_nor_ip_access_config_t  *ptrXspiNorIPAccessConfig; /*!< Pointer to the IP access configuration, set as NULL
94                                                         to use default settings. */
95 } xspi_memory_config_t;
96 
97 /*!
98  * @brief xspi nor flash handle.
99  */
100 typedef struct _xspi_mem_nor_handle
101 {
102     xspi_target_group_t selectedTg;  /*!< Current selected target group. */
103     xspi_device_status_reg_info_t norFlashStatusRegInfo;  /*!< Nor flash status register WIP bit information. */
104     uint8_t addrSize;   /*!< Address size. */
105     uint32_t sectorSizeInByte; /*!< Sector size in unit of byte. */
106     uint32_t memSizeInByte; /*!< Nor flash size in unit of byte. */
107     sfdp_protocol_type_t curProtocolType; /*!< Current protocol type. */
108     sfdp_octal_dtr_cmd_type_t octalDTRCmdType; /*!< Octal DTR command type. */
109     sfdp_handle_t *ptrSfdpHandle; /*!< Pointer to sfdp handle. */
110     uint32_t clkFreq; /*!< Frequency of serial flash. */
111 } xspi_mem_nor_handle_t;
112