Debian Codegraph @

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

raw symbols SCIP
1 /***************************************************************************//**
2 * @file spi_engine.h
3 * @brief Header file of SPI Engine Driver.
4 * @author DBogdan ([email protected])
5 ********************************************************************************
6 * Copyright 2016(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_ENGINE_H_
40 #define SPI_ENGINE_H_
41
42 /******************************************************************************/
43 /********************** Macros and Constants Definitions **********************/
44 /******************************************************************************/
45 #define BIT(x) (1UL << (x))
46
47 #define SPI_ENGINE_VERSION_MAJOR(x) ((x >> 16) & 0xff)
48 #define SPI_ENGINE_VERSION_MINOR(x) ((x >> 8) & 0xff)
49 #define SPI_ENGINE_VERSION_PATCH(x) (x & 0xff)
50
51 #define SPI_ENGINE_REG_VERSION 0x00
52
53 #define SPI_ENGINE_REG_RESET 0x40
54
55 #define SPI_ENGINE_REG_INT_ENABLE 0x80
56 #define SPI_ENGINE_REG_INT_PENDING 0x84
57 #define SPI_ENGINE_REG_INT_SOURCE 0x88
58
59 #define SPI_ENGINE_REG_SYNC_ID 0xc0
60
61 #define SPI_ENGINE_REG_CMD_FIFO_ROOM 0xd0
62 #define SPI_ENGINE_REG_SDO_FIFO_ROOM 0xd4
63 #define SPI_ENGINE_REG_SDI_FIFO_LEVEL 0xd8
64
65 #define SPI_ENGINE_REG_CMD_FIFO 0xe0
66 #define SPI_ENGINE_REG_SDO_DATA_FIFO 0xe4
67 #define SPI_ENGINE_REG_SDI_DATA_FIFO 0xe8
68 #define SPI_ENGINE_REG_SDI_DATA_FIFO_PEEK 0xec
69
70 #define SPI_ENGINE_REG_OFFLOAD_CTRL(x) (0x100 + (0x20 * x))
71 #define SPI_ENGINE_REG_OFFLOAD_STATUS(x) (0x104 + (0x20 * x))
72 #define SPI_ENGINE_REG_OFFLOAD_RESET(x) (0x108 + (0x20 * x))
73 #define SPI_ENGINE_REG_OFFLOAD_CMD_MEM(x) (0x110 + (0x20 * x))
74 #define SPI_ENGINE_REG_OFFLOAD_SDO_MEM(x) (0x114 + (0x20 * x))
75
76 #define SPI_ENGINE_INT_CMD_ALMOST_EMPTY BIT(0)
77 #define SPI_ENGINE_INT_SDO_ALMOST_EMPTY BIT(1)
78 #define SPI_ENGINE_INT_SDI_ALMOST_FULL BIT(2)
79 #define SPI_ENGINE_INT_SYNC BIT(3)
80
81 #define SPI_ENGINE_OFFLOAD_CTRL_ENABLE BIT(0)
82 #define SPI_ENGINE_OFFLOAD_STATUS_ENABLED BIT(0)
83
84 #define SPI_ENGINE_CONFIG_CPHA BIT(0)
85 #define SPI_ENGINE_CONFIG_CPOL BIT(1)
86 #define SPI_ENGINE_CONFIG_3WIRE BIT(2)
87
88 #define SPI_ENGINE_INST_TRANSFER 0x0
89 #define SPI_ENGINE_INST_ASSERT 0x1
90 #define SPI_ENGINE_INST_WRITE 0x2
91 #define SPI_ENGINE_INST_MISC 0x3
92
93 #define SPI_ENGINE_CMD_REG_CLK_DIV 0x0
94 #define SPI_ENGINE_CMD_REG_CONFIG 0x1
95
96 #define SPI_ENGINE_MISC_SYNC 0x0
97 #define SPI_ENGINE_MISC_SLEEP 0x1
98
99 #define SPI_ENGINE_CMD(inst, arg1, arg2) \
100 (((inst) << 12) | ((arg1) << 8) | (arg2))
101
102 #define SPI_ENGINE_CMD_TRANSFER(write, read, n) \
103 SPI_ENGINE_CMD(SPI_ENGINE_INST_TRANSFER, ((read) << 1 | (write)), (n))
104 #define SPI_ENGINE_CMD_ASSERT(delay, cs) \
105 SPI_ENGINE_CMD(SPI_ENGINE_INST_ASSERT, (delay), (cs))
106 #define SPI_ENGINE_CMD_WRITE(reg, val) \
107 SPI_ENGINE_CMD(SPI_ENGINE_INST_WRITE, (reg), (val))
108 #define SPI_ENGINE_CMD_SLEEP(delay) \
109 SPI_ENGINE_CMD(SPI_ENGINE_INST_MISC, SPI_ENGINE_MISC_SLEEP, (delay))
110 #define SPI_ENGINE_CMD_SYNC(id) \
111 SPI_ENGINE_CMD(SPI_ENGINE_INST_MISC, SPI_ENGINE_MISC_SYNC, (id))
112
113 #define min(x, y) (((x) < (y)) ? (x) : (y))
114 #define max(x, y) (((x) > (y)) ? (x) : (y))
115
116 /******************************************************************************/
117 /*************************** Types Declarations *******************************/
118 /******************************************************************************/
119 typedef struct {
120 uint8_t chip_select;
121 uint8_t cs_change;
122 uint32_t spi_clk;
123 uint32_t spi_config;
124 uint8_t tx_length;
125 uint8_t *tx_buf;
126 uint8_t rx_length;
127 uint8_t *rx_buf;
128 } spi_message;
129
130 typedef struct {
131 uint32_t length;
132 uint16_t instructions[];
133 } spi_engine_program;
134
135 typedef struct {
136 uint32_t baseaddr;
137 uint32_t spi_ref_clk;
138 uint8_t cmd_length;
139 uint16_t *cmd_buf;
140 uint32_t sync_id;
141 uint32_t completed_id;
142 uint32_t int_enable;
143 spi_message *msg;
144 spi_engine_program *p;
145 } spi_engine;
146
147 /******************************************************************************/
148 /************************ Functions Declarations ******************************/
149 /******************************************************************************/
150 int32_t spi_engine_write(uint32_t reg_addr,
151 uint32_t reg_data);
152 int32_t spi_engine_setup(uint32_t baseaddr);
153 int32_t spi_engine_transfer_one_message(spi_message *msg);
154 void spi_engine_offload_enable(uint8_t enable);
155 int32_t spi_engine_offload_load_msg(spi_message *msg);
156 int32_t spi_engine_write_and_read(uint8_t ss,
157 uint8_t *data,
158 uint8_t bytes_number);
159 #endif