1 /* 2 * Copyright 2021 NXP 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 * 6 */ 7 8 9 /*! 10 * @file fspi_api.h 11 * @brief This file contains the FlexSPI/FSPI API to communicate 12 * to attached Slave device. 13 * @addtogroup FSPI_API 14 * @{ 15 */ 16 17 #ifndef FSPI_API_H 18 #define FSPI_API_H 19 20 #if DEBUG_FLEXSPI 21 #define SZ_57M 0x3900000u 22 #endif 23 24 /*! 25 * Basic set of APIs. 26 */ 27 28 /*! 29 * @details AHB read/IP Read, decision to be internal to API 30 * Minimum Read size = 1Byte 31 * @param[in] src_off source offset from where data to read from flash 32 * @param[out] des Destination location where data needs to be copied 33 * @param[in] len length in Bytes,where 1-word=4-bytes/32-bits 34 * 35 * @return XSPI_SUCCESS or error code 36 */ 37 int xspi_read(uint32_t src_off, uint32_t *des, uint32_t len); 38 /*! 39 * @details Sector erase, Minimum size 40 * 256KB(0x40000)/128KB(0x20000)/64K(0x10000)/4K(0x1000) 41 * depending upon flash, Calls xspi_wren() internally 42 * @param[out] erase_offset Destination erase location on flash which 43 * has to be erased, needs to be multiple of 0x40000/0x20000/0x10000 44 * @param[in] erase_len length in bytes in Hex like 0x100000 for 1MB, minimum 45 * erase size is 1 sector(0x40000/0x20000/0x10000) 46 * 47 * @return XSPI_SUCCESS or error code 48 */ 49 int xspi_sector_erase(uint32_t erase_offset, uint32_t erase_len); 50 /*! 51 * @details IP write, For writing data to flash, calls xspi_wren() internally. 52 * Single/multiple page write can start @any offset, but performance will be low 53 * due to ERRATA 54 * @param[out] dst_off Destination location on flash where data needs to 55 * be written 56 * @param[in] src source offset from where data to be read 57 * @param[in] len length in bytes,where 1-word=4-bytes/32-bits 58 * 59 * @return XSPI_SUCCESS or error code 60 */ 61 int xspi_write(uint32_t dst_off, void *src, uint32_t len); 62 /*! 63 * @details fspi_init, Init function. 64 * @param[in] uint32_t base_reg_addr 65 * @param[in] uint32_t flash_start_addr 66 * 67 * @return XSPI_SUCCESS or error code 68 */ 69 int fspi_init(uint32_t base_reg_addr, uint32_t flash_start_addr); 70 /*! 71 * @details is_flash_busy, Check if any erase or write or lock is 72 * pending on flash/slave 73 * @param[in] void 74 * 75 * @return TRUE/FLASE 76 */ 77 bool is_flash_busy(void); 78 79 /*! 80 * Advanced set of APIs. 81 */ 82 83 /*! 84 * @details Write enable, to be used by advance users only. 85 * Step 1 for sending write commands to flash. 86 * @param[in] dst_off destination offset where data will be written 87 * 88 * @return XSPI_SUCCESS or error code 89 */ 90 int xspi_wren(uint32_t dst_off); 91 /*! 92 * @details AHB read, meaning direct memory mapped access to flash, 93 * Minimum Read size = 1Byte 94 * @param[in] src_off source offset from where data to read from flash, 95 * needs to be word aligned 96 * @param[out] des Destination location where data needs to be copied 97 * @param[in] len length in Bytes,where 1-word=4-bytes/32-bits 98 * 99 * @return XSPI_SUCCESS or error code 100 */ 101 int xspi_ahb_read(uint32_t src_off, uint32_t *des, uint32_t len); 102 /*! 103 * @details IP read, READ via RX buffer from flash, minimum READ size = 1Byte 104 * @param[in] src_off source offset from where data to be read from flash 105 * @param[out] des Destination location where data needs to be copied 106 * @param[in] len length in Bytes,where 1-word=4-bytes/32-bits 107 * 108 * @return XSPI_SUCCESS or error code 109 */ 110 int xspi_ip_read(uint32_t src_off, uint32_t *des, uint32_t len); 111 /*! 112 * @details CHIP erase, Erase complete chip in one go 113 * 114 * @return XSPI_SUCCESS or error code 115 */ 116 int xspi_bulk_erase(void); 117 118 /*! 119 * Add test cases to confirm flash read/erase/write functionality. 120 */ 121 void fspi_test(uint32_t fspi_test_addr, uint32_t size, int extra); 122 #endif /* FSPI_API_H */ 123