Debian Codegraph @

thirdparty/analogdevicesinc/no-OS/adaq7980-sdz/spi_engine.h

raw symbols SCIP
1 /***************************************************************************//**
2 * @file spi.h
3 * @brief Header file of SPI Engine Driver.
4 * @author ADI
5 ********************************************************************************
6 * Copyright 2017(c) Analog Devices, Inc.
7 *
8 * All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions are met:
12 * - Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * - Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the
17 * distribution.
18 * - Neither the name of Analog Devices, Inc. nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
21 * - The use of this software may or may not infringe the patent rights
22 * of one or more patent holders. This license does not release you
23 * from the requirement that you obtain separate licenses from these
24 * patent holders to use this software.
25 * - Use of the software either in source or binary form, must be run
26 * on or directly connected to an Analog Devices Inc. component.
27 *
28 * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
29 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
30 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
31 * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
32 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
33 * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
34 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
35 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
36 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 *******************************************************************************/
39 #ifndef SPI_H_
40 #define SPI_H_
41
42
43 /******************************************************************************/
44 /********************** Macros and Constants Definitions **********************/
45 /******************************************************************************/
46 /******************************************************************************/
47 #define BIT(x) (1UL << (x))
48
49 #define SPI_ENGINE_VERSION_MAJOR(x) ((x >> 16) & 0xff)
50 #define SPI_ENGINE_VERSION_MINOR(x) ((x >> 8) & 0xff)
51 #define SPI_ENGINE_VERSION_PATCH(x) (x & 0xff)
52
53 #define SPI_ENGINE_REG_VERSION 0x00
54
55 #define SPI_ENGINE_REG_DATA_WIDTH 0x0C
56
57 #define SPI_ENGINE_REG_RESET 0x40
58
59 #define SPI_ENGINE_REG_INT_ENABLE 0x80
60 #define SPI_ENGINE_REG_INT_PENDING 0x84
61 #define SPI_ENGINE_REG_INT_SOURCE 0x88
62
63 #define SPI_ENGINE_REG_SYNC_ID 0xc0
64
65 #define SPI_ENGINE_REG_CMD_FIFO_ROOM 0xd0
66 #define SPI_ENGINE_REG_SDO_FIFO_ROOM 0xd4
67 #define SPI_ENGINE_REG_SDI_FIFO_LEVEL 0xd8
68
69 #define SPI_ENGINE_REG_CMD_FIFO 0xe0
70 #define SPI_ENGINE_REG_SDO_DATA_FIFO 0xe4
71 #define SPI_ENGINE_REG_SDI_DATA_FIFO 0xe8
72 #define SPI_ENGINE_REG_SDI_DATA_FIFO_PEEK 0xec
73
74 #define SPI_ENGINE_REG_OFFLOAD_CTRL(x) (0x100 + (0x20 * x))
75 #define SPI_ENGINE_REG_OFFLOAD_STATUS(x) (0x104 + (0x20 * x))
76 #define SPI_ENGINE_REG_OFFLOAD_RESET(x) (0x108 + (0x20 * x))
77 #define SPI_ENGINE_REG_OFFLOAD_CMD_MEM(x) (0x110 + (0x20 * x))
78 #define SPI_ENGINE_REG_OFFLOAD_SDO_MEM(x) (0x114 + (0x20 * x))
79
80 #define SPI_ENGINE_INT_CMD_ALMOST_EMPTY BIT(0)
81 #define SPI_ENGINE_INT_SDO_ALMOST_EMPTY BIT(1)
82 #define SPI_ENGINE_INT_SDI_ALMOST_FULL BIT(2)
83 #define SPI_ENGINE_INT_SYNC BIT(3)
84
85 #define SPI_ENGINE_OFFLOAD_CTRL_ENABLE BIT(0)
86 #define SPI_ENGINE_OFFLOAD_STATUS_ENABLED BIT(0)
87
88 #define SPI_ENGINE_CONFIG_CPHA BIT(0)
89 #define SPI_ENGINE_CONFIG_CPOL BIT(1)
90 #define SPI_ENGINE_CONFIG_3WIRE BIT(2)
91
92 #define SPI_ENGINE_INST_TRANSFER 0x0
93 #define SPI_ENGINE_INST_ASSERT 0x1
94 #define SPI_ENGINE_INST_WRITE 0x2
95 #define SPI_ENGINE_INST_MISC 0x3
96
97 #define SPI_ENGINE_CMD_REG_CLK_DIV 0x0
98 #define SPI_ENGINE_CMD_REG_CONFIG 0x1
99
100 #define SPI_ENGINE_MISC_SYNC 0x0
101 #define SPI_ENGINE_MISC_SLEEP 0x1
102
103 #define SPI_ENGINE_CMD(inst, arg1, arg2) \
104 (((inst) << 12) | ((arg1) << 8) | (arg2))
105
106 #define SPI_ENGINE_CMD_TRANSFER(write, read, n) \
107 SPI_ENGINE_CMD(SPI_ENGINE_INST_TRANSFER, ((read) << 1 | (write)), (n))
108 #define SPI_ENGINE_CMD_ASSERT(delay, cs) \
109 SPI_ENGINE_CMD(SPI_ENGINE_INST_ASSERT, (delay), (cs))
110 #define SPI_ENGINE_CMD_WRITE(reg, val) \
111 SPI_ENGINE_CMD(SPI_ENGINE_INST_WRITE, (reg), (val))
112 #define SPI_ENGINE_CMD_SLEEP(delay) \
113 SPI_ENGINE_CMD(SPI_ENGINE_INST_MISC, SPI_ENGINE_MISC_SLEEP, (delay))
114 #define SPI_ENGINE_CMD_SYNC(id) \
115 SPI_ENGINE_CMD(SPI_ENGINE_INST_MISC, SPI_ENGINE_MISC_SYNC, (id))
116
117
118 #define DMAC_REG_IRQ_MASK 0x80
119 #define DMAC_REG_IRQ_PENDING 0x84
120 #define DMAC_REG_IRQ_SOURCE 0x88
121
122 #define DMAC_REG_CTRL 0x400
123 #define DMAC_REG_TRANSFER_ID 0x404
124 #define DMAC_REG_START_TRANSFER 0x408
125 #define DMAC_REG_FLAGS 0x40c
126 #define DMAC_REG_DEST_ADDRESS 0x410
127 #define DMAC_REG_SRC_ADDRESS 0x414
128 #define DMAC_REG_X_LENGTH 0x418
129 #define DMAC_REG_Y_LENGTH 0x41c
130 #define DMAC_REG_DEST_STRIDE 0x420
131 #define DMAC_REG_SRC_STRIDE 0x424
132 #define DMAC_REG_TRANSFER_DONE 0x428
133 #define DMAC_REG_ACTIVE_TRANSFER_ID 0x42c
134 #define DMAC_REG_STATUS 0x430
135 #define DMAC_REG_CURRENT_DEST_ADDR 0x434
136 #define DMAC_REG_CURRENT_SRC_ADDR 0x438
137 #define DMAC_REG_DBG0 0x43c
138 #define DMAC_REG_DBG1 0x440
139
140 #define DMAC_CTRL_ENABLE (1 << 0)
141 #define DMAC_CTRL_PAUSE (1 << 1)
142
143 #define DMAC_IRQ_SOT (1 << 0)
144 #define DMAC_IRQ_EOT (1 << 1)
145
146
147 #define CS_DEASSERT 0 << 28
148
149 #define CS_ASSERT 1 << 28
150
151 #define SLEEP_CMD 2 << 28
152 #define SLEEP(x) (SLEEP_CMD | (x & ( ~(0xF << 28) )))
153
154 #define TRANSFER_R_CMD 3 << 28
155 #define TRANSFER_R(x) (TRANSFER_R_CMD | (x & 0xF))
156
157 #define TRANSFER_W_CMD 4 << 28
158 #define TRANSFER_W(x) (TRANSFER_W_CMD | (x & 0xF))
159
160 #define TRANSFER_R_W_CMD 5 << 28
161 #define TRANSFER_R_W(x) (TRANSFER_R_W_CMD | (x & 0xF))
162
163 /******************************************************************************/
164 /*************************** Types Declarations *******************************/
165 /******************************************************************************/
166
167 typedef struct {
168 uint32_t spi_baseaddr;
169 uint8_t chip_select;
170 uint8_t spi_config;
171 uint32_t spi_clk_hz;
172 uint32_t ref_clk_hz;
173 uint32_t clk_div;
174 uint32_t rx_length;
175 uint32_t tx_length;
176 uint8_t spi_offload_rx_support_en;
177 uint32_t spi_offload_rx_dma_baseaddr;
178 uint32_t rx_dma_startaddr;
179 uint8_t spi_offload_tx_support_en;
180 uint32_t spi_offload_tx_dma_baseaddr;
181 uint32_t tx_dma_startaddr;
182 uint8_t offload_configured;
183 uint8_t data_width;
184 } spi_dev;
185
186 typedef struct {
187 uint32_t spi_baseaddr;
188 uint8_t chip_select;
189 uint8_t spi_config;
190 uint32_t spi_clk_hz;
191 uint32_t ref_clk_hz;
192 uint8_t spi_offload_rx_support_en;
193 uint32_t spi_offload_rx_dma_baseaddr;
194 uint8_t spi_offload_tx_support_en;
195 uint32_t spi_offload_tx_dma_baseaddr;
196 } spi_init_param;
197
198 typedef struct {
199 uint32_t tx_buf_addr;
200 uint32_t rx_buf_addr;
201 uint32_t *spi_msg_cmds;
202 uint8_t msg_cmd_len;
203 } spi_msg;
204
205
206 typedef struct {
207 uint32_t cmd_fifo_len;
208 uint16_t cmd_fifo[];
209 } spi_transfer_fifo;
210
211 /******************************************************************************/
212 /************************ Functions Declarations ******************************/
213 /******************************************************************************/
214
215 int32_t spi_eng_write(spi_dev *dev,
216 uint32_t reg_addr,
217 uint32_t ui32data);
218
219 int32_t spi_eng_read(spi_dev *dev,
220 uint32_t reg_addr,
221 uint32_t *reg_data);
222
223 int32_t spi_eng_dma_write(spi_dev *dev,
224 uint32_t reg_addr,
225 uint32_t reg_data);
226
227 int32_t spi_eng_dma_read(spi_dev *dev,
228 uint32_t reg_addr,
229 uint32_t *reg_data);
230
231
232 int32_t spi_eng_setup(spi_dev **device,
233 spi_init_param init_param);
234
235 int32_t spi_eng_offload_load_msg(spi_dev *dev, spi_msg *msg);
236
237 int32_t spi_eng_transfer_message(spi_dev *dev, spi_msg *msg);
238
239 int32_t spi_eng_transfer_multiple_msgs(spi_dev *dev, uint8_t no_of_messages);
240
241 #endif // SPI_H_