fspi_api.h 3.54 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*
 * Copyright 2021 NXP
 *
 * SPDX-License-Identifier: BSD-3-Clause
 *
 */


/*!
 * @file	fspi_api.h
 * @brief	This file contains the FlexSPI/FSPI API to communicate
 *		to attached Slave device.
 * @addtogroup	FSPI_API
 * @{
 */

#ifndef FSPI_API_H
#define FSPI_API_H

#if DEBUG_FLEXSPI
#define SZ_57M			0x3900000u
#endif

/*!
 * Basic set of APIs.
 */

/*!
 * @details AHB read/IP Read, decision to be internal to API
 * Minimum Read size = 1Byte
 * @param[in] src_off source offset from where data to read from flash
 * @param[out] des Destination location where data needs to be copied
 * @param[in] len length in Bytes,where 1-word=4-bytes/32-bits
 *
 * @return XSPI_SUCCESS or error code
 */
int xspi_read(uint32_t src_off, uint32_t *des, uint32_t len);
/*!
 * @details Sector erase, Minimum size
 * 256KB(0x40000)/128KB(0x20000)/64K(0x10000)/4K(0x1000)
 * depending upon flash, Calls xspi_wren() internally
 * @param[out] erase_offset Destination erase location on flash which
 * has to be erased, needs to be multiple of 0x40000/0x20000/0x10000
 * @param[in] erase_len length in bytes in Hex like 0x100000 for 1MB, minimum
 * erase size is 1 sector(0x40000/0x20000/0x10000)
 *
 * @return XSPI_SUCCESS or error code
 */
int xspi_sector_erase(uint32_t erase_offset, uint32_t erase_len);
/*!
 * @details IP write, For writing data to flash, calls xspi_wren() internally.
 * Single/multiple page write can start @any offset, but performance will be low
 * due to ERRATA
 * @param[out] dst_off Destination location on flash where data needs to
 * be written
 * @param[in] src source offset from where data to be read
 * @param[in] len length in bytes,where 1-word=4-bytes/32-bits
 *
 * @return XSPI_SUCCESS or error code
 */
int xspi_write(uint32_t dst_off, void *src, uint32_t len);
/*!
 * @details fspi_init, Init function.
 * @param[in] uint32_t base_reg_addr
 * @param[in] uint32_t flash_start_addr
 *
 * @return XSPI_SUCCESS or error code
 */
int fspi_init(uint32_t base_reg_addr, uint32_t flash_start_addr);
/*!
 * @details is_flash_busy, Check if any erase or write or lock is
 * pending on flash/slave
 * @param[in] void
 *
 * @return TRUE/FLASE
 */
bool is_flash_busy(void);

/*!
 * Advanced set of APIs.
 */

/*!
 * @details Write enable, to be used by advance users only.
 * Step 1 for sending write commands to flash.
 * @param[in] dst_off destination offset where data will be written
 *
 * @return XSPI_SUCCESS or error code
 */
int xspi_wren(uint32_t dst_off);
/*!
 * @details AHB read, meaning direct memory mapped access to flash,
 * Minimum Read size = 1Byte
 * @param[in] src_off source offset from where data to read from flash,
 * needs to be word aligned
 * @param[out] des Destination location where data needs to be copied
 * @param[in] len length in Bytes,where 1-word=4-bytes/32-bits
 *
 * @return XSPI_SUCCESS or error code
 */
int xspi_ahb_read(uint32_t src_off, uint32_t *des, uint32_t len);
/*!
 * @details IP read, READ via RX buffer from flash, minimum READ size = 1Byte
 * @param[in] src_off source offset from where data to be read from flash
 * @param[out] des Destination location where data needs to be copied
 * @param[in] len length in Bytes,where 1-word=4-bytes/32-bits
 *
 * @return XSPI_SUCCESS or error code
 */
int xspi_ip_read(uint32_t src_off, uint32_t *des, uint32_t len);
/*!
 * @details CHIP erase, Erase complete chip in one go
 *
 * @return XSPI_SUCCESS or error code
 */
int xspi_bulk_erase(void);

/*!
 * Add test cases to confirm flash read/erase/write functionality.
 */
void fspi_test(uint32_t fspi_test_addr, uint32_t size, int extra);
#endif /* FSPI_API_H */