RTEMS 6.1-rc5
Loading...
Searching...
No Matches
zynq-qspi-flash-defs.h
1/*
2 * Copyright (C) 2024 Contemporary Software
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
17 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
23 * POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#if !defined(_ZYNQ_QSPI_FLASH_DEFS_H_)
27#define _ZYNQ_QSPI_FLASH_DEFS_H_
28
29#include <dev/spi/zynq-qspi-flash.h>
30
31#define ZQSPI_QSPI_BASE 0xE000D000
32
33/*
34 * Flash commands.
35 */
36
37#define ZQSPI_FLASH_COMMAND_SIZE 1
38#if ZQSPI_FLASH_4BYTE_ADDRESSING
39 #define ZQSPI_FLASH_ADDRESS_SIZE 4
40 #define ZQSPI_FLASH_WRITE_CMD 0x12
41 #if ZQSPI_FLASH_FAST_READ
42 #define ZQSPI_FLASH_READ_CMD 0x0c
43 #else
44 #define ZQSPI_FLASH_READ_CMD 0x13
45 #endif
46 #define ZQSPI_FLASH_SEC_ERASE_CMD 0xDC
47#else
48 #define ZQSPI_FLASH_ADDRESS_SIZE 3
49 #define ZQSPI_FLASH_WRITE_CMD 0x02
50 #if ZQSPI_FLASH_FAST_READ
51 #define ZQSPI_FLASH_READ_CMD 0x0b
52 #else
53 #define ZQSPI_FLASH_READ_CMD 0x03
54 #endif
55 #define ZQSPI_FLASH_SEC_ERASE_CMD 0xD8
56#endif
57
58#define ZQSPI_FLASH_READ_CONFIG_CMD 0x35
59#define ZQSPI_FLASH_WRITE_STATUS_CMD 0x01
60#define ZQSPI_FLASH_WRITE_DISABLE_CMD 0x04
61#define ZQSPI_FLASH_READ_STATUS_CMD 0x05
62#define ZQSPI_FLASH_WRITE_DISABLE_CMD 0x04
63#define ZQSPI_FLASH_WRITE_ENABLE_CMD 0x06
64#define ZQSPI_FLASH_BULK_ERASE_CMD 0xC7
65#define ZQSPI_FLASH_READ_ID 0x9F
66
67#define ZQSPI_FLASH_READ_STATUS_FLAG_CMD 0x05
68
69/*
70 * QSPI registers.
71 */
72#define ZQSPI_QSPI_REG_CONFIG 0x00000000
73#define ZQSPI_QSPI_REG_INTR_STATUS 0x00000004
74#define ZQSPI_QSPI_REG_INTR_ENABLE 0x00000008
75#define ZQSPI_QSPI_REG_INTR_DISABLE 0x0000000c
76#define ZQSPI_QSPI_REG_INTR_MASK 0x00000010
77#define ZQSPI_QSPI_REG_EN 0x00000014
78#define ZQSPI_QSPI_REG_DELAY 0x00000018
79#define ZQSPI_QSPI_REG_TXD0 0x0000001c
80#define ZQSPI_QSPI_REG_RX_DATA 0x00000020
81#define ZQSPI_QSPI_REG_SLAVE_IDLE_COUNT 0x00000024
82#define ZQSPI_QSPI_REG_TX_THRES 0x00000028
83#define ZQSPI_QSPI_REG_RX_THRES 0x0000002c
84#define ZQSPI_QSPI_REG_GPIO 0x00000030
85#define ZQSPI_QSPI_REG_LPBK_DLY_ADJ 0x00000038
86#define ZQSPI_QSPI_REG_TXD1 0x00000080
87#define ZQSPI_QSPI_REG_TXD2 0x00000084
88#define ZQSPI_QSPI_REG_TXD3 0x00000088
89#define ZQSPI_QSPI_REG_LSPI_CFG 0x000000a0
90#define ZQSPI_QSPI_REG_LSPI_STS 0x000000a4
91#define ZQSPI_QSPI_REG_MOD_ID 0x000000fc
92
93/*
94 * TX FIFO depth in words.
95 */
96#define ZQSPI_QSPI_FIFO_DEPTH (63)
97
98/*
99 * Control register.
100 */
101#define ZQSPI_QSPI_CR_HOLDB_DR (1 << 19)
102#define ZQSPI_QSPI_CR_MANSTRT (1 << 16)
103#define ZQSPI_QSPI_CR_MANSTRTEN (1 << 15)
104#define ZQSPI_QSPI_CR_SSFORCE (1 << 14)
105#define ZQSPI_QSPI_CR_PCS (1 << 10)
106#define ZQSPI_QSPI_CR_BAUD_RATE_DIV_2 (0 << 3)
107#define ZQSPI_QSPI_CR_BAUD_RATE_DIV_4 (1 << 3)
108#define ZQSPI_QSPI_CR_BAUD_RATE_DIV_8 (2 << 3)
109#define ZQSPI_QSPI_CR_MODE_SEL (1 << 0)
110
111/*
112 * Fast clock rate of 100MHz for fast reads.
113 */
114#define ZQSPI_QSPI_CR_BAUD_RATE_FAST ZQSPI_QSPI_CR_BAUD_RATE_DIV_2
115
116/*
117 * Status register.
118 */
119#define ZQSPI_QSPI_IXR_TXUF (1 << 6)
120#define ZQSPI_QSPI_IXR_RXFULL (1 << 5)
121#define ZQSPI_QSPI_IXR_RXNEMPTY (1 << 4)
122#define ZQSPI_QSPI_IXR_TXFULL (1 << 3)
123#define ZQSPI_QSPI_IXR_TXOW (1 << 2)
124#define ZQSPI_QSPI_INTR_RXOVR (1 << 0)
125
126/*
127 * Enable register.
128 */
129#define ZQSPI_QSPI_EN_SPI_ENABLE (1 << 0)
130
131/*
132 * Clock rate is 200MHz and 50MHz is the normal rate and 100MHz the fast rate.
133 */
134#if FLASH_FAST_READ
135 #define ZQSPI_QSPI_CR_BAUD_RATE ZQSPI_QSPI_CR_BAUD_RATE_DIV_2
136#else
137 #define ZQSPI_QSPI_CR_BAUD_RATE ZQSPI_QSPI_CR_BAUD_RATE_DIV_4
138#endif
139
140/*
141 * Flash Status bits.
142 */
143#define ZQSPI_FLASH_SR_WIP (1 << 0)
144#define ZQSPI_FLASH_SR_WEL (1 << 1)
145#define ZQSPI_FLASH_SR_BP0 (1 << 2)
146#define ZQSPI_FLASH_SR_BP1 (1 << 3)
147#define ZQSPI_FLASH_SR_BP2 (1 << 4)
148#define ZQSPI_FLASH_SR_E_ERR (1 << 5)
149#define ZQSPI_FLASH_SR_P_ERR (1 << 6)
150#define ZQSPI_FLASH_SR_SRWD (1 << 7)
151
152
153void zqspi_write_unlock(zqspiflash *driver);
154
155void zqspi_write_lock(zqspiflash *driver);
156
157zqspi_error zqspi_transfer(zqspi_transfer_buffer* transfer, bool *initialised);
158
159void zqspi_transfer_intr(zqspiflash *driver);
160
161#endif /* _ZYNQ_QSPI_FLASH_DEFS_H_ */
Definition: zynq-qspi-flash.h:92
Definition: zynq-qspi-flash.h:113