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