1 /*
2  * Copyright 2018-2020 NXP
3  * All rights reserved.
4  *
5  * SPDX-License-Identifier: BSD-3-Clause
6  */
7 
8 #ifndef __FSL_NAND_FLASH_H__
9 #define __FSL_NAND_FLASH_H__
10 
11 #include "fsl_common.h"
12 
13 /*!
14  * @addtogroup nand_flash_component
15  * @{
16  */
17 
18 /*******************************************************************************
19  * Definitions
20  ******************************************************************************/
21 
22 /*! @brief NAND Flash Config block structure */
23 typedef struct _nand_config
24 {
25     void *memControlConfig; /*!< memory controller configuration, should be assigned to specific controller
26                                configuration structure pointer.*/
27     void *driverBaseAddr;   /*! Driver Base address. */
28 } nand_config_t;
29 
30 /*!@brief NAND Flash handle info*/
31 typedef struct _nand_handle
32 {
33     /*------------Common parameters used for normal nand flash controller operation ----------*/
34     void *driverBaseAddr;          /*! Driver Base address. */
35     uint8_t vendorType;            /*!< vendor type */
36     uint32_t bytesInPageDataArea;  /*!< Bytes in page data area .*/
37     uint32_t bytesInPageSpareArea; /*!< Bytes in page spare area .*/
38     uint32_t pagesInBlock;         /*!< Pages in each block. */
39     uint32_t blocksInPlane;        /*!< blocks in each plane. */
40     uint32_t planesInDevice;       /*!< planes in each device .*/
41     /*------------Specific parameters used for specific nand flash controller ----------*/
42     void *deviceSpecific; /*!< Device specific control parameter */
43 } nand_handle_t;
44 
45 /*******************************************************************************
46  * API
47  ******************************************************************************/
48 
49 #ifdef __cplusplus
50 extern "C" {
51 #endif
52 
53 /*!
54  * @name NAND FLASH Driver
55  * @{
56  */
57 
58 /*!
59  * @brief Initialize NAND FLASH devices.
60  *
61  *  This function initialize NAND Flash controller and NAND Flash.
62  *
63  * @param config    Nand flash configuration.
64  *        The "memControlConfig" and "driverBaseAddr" are controller specific structure.
65  *        please set those two parameter with your Nand controller configuration structure type pointer.
66  *        such as for SEMC:
67  *  @code
68  *        semc_mem_nand_config_t semcNandconfig =
69  *        {
70  *            .....
71  *        }
72  *        nand_config_t config =
73  *        {
74  *            .memControlConfig = (void *)&semcNandconfig;
75  *            .driverBaseAddr   = (void *)SEMC;
76  *        }
77  *  @endcode
78  * @param handle    The NAND Flash handler.
79  * @retval execution status
80  */
81 status_t Nand_Flash_Init(nand_config_t *config, nand_handle_t *handle);
82 
83 /*!
84  * @brief Read page data from NAND Flash.
85  *
86  * @param handle    The NAND Flash handler.
87  * @param pageIndex  Nand flash page index, range from 0 ~ xxx.
88  * @param buffer  Nand flash buffer to read data to.
89  * @param length  Nand flash read length.
90  * @retval execution status
91  */
92 status_t Nand_Flash_Read_Page(nand_handle_t *handle, uint32_t pageIndex, uint8_t *buffer, uint32_t length);
93 
94 /*!
95  * @brief Read page partial data from NAND Flash.
96  *
97  * @param handle    The NAND Flash handler.
98  * @param pageIndex  Nand flash page index, range from 0 ~ xxx.
99  * @param offset_bytes Offset to start read the page data.
100  * @param buffer  Nand flash buffer to read data to.
101  * @param length  Nand flash read length.
102  * @retval execution status
103  */
104 status_t Nand_Flash_Read_Page_Partial(
105     nand_handle_t *handle, uint32_t pageIndex, uint32_t offset_bytes, uint8_t *buffer, uint32_t length);
106 
107 /*!
108  * @brief Program page data to NAND Flash.
109  *
110  * @param handle    The NAND Flash handler.
111  * @param pageIndex  Nand flash page index, range from 0 ~ xxx.
112  * @param src  The data to be programed to the page.
113  * @param length  Nand flash read length.
114  * @retval execution status
115  */
116 status_t Nand_Flash_Page_Program(nand_handle_t *handle, uint32_t pageIndex, const uint8_t *src, uint32_t length);
117 
118 /*!
119  * @brief Erase block NAND Flash.
120  *
121  * @param handle    The NAND Flash handler.
122  * @param blockIndex  Nand flash block index to be erased, range from 0 ~ xxx.
123  * @retval execution status
124  */
125 status_t Nand_Flash_Erase_Block(nand_handle_t *handle, uint32_t blockIndex);
126 
127 /*! @} */
128 
129 #ifdef __cplusplus
130 }
131 #endif
132 /*! @} */
133 #endif /* __FSL_NAND_FLASH_H__ */
134