Debian Codegraph @

thirdparty/analogdevicesinc/no-OS_local/platform_bladerf2/dac_core.h

raw symbols SCIP
1 /***************************************************************************//**
2 * @file dac_core.h
3 * @brief Header file of DAC Core Driver.
4 * @author DBogdan ([email protected])
5 ********************************************************************************
6 * Copyright 2013(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 DAC_CORE_API_H_
40 #define DAC_CORE_API_H_
41
42 /******************************************************************************/
43 /***************************** Include Files **********************************/
44 /******************************************************************************/
45 #include "ad9361.h"
46
47 /******************************************************************************/
48 /********************** Macros and Constants Definitions **********************/
49 /******************************************************************************/
50 #define DAC_REG_VERSION 0x0000
51 #define DAC_VERSION(x) (((x) & 0xffffffff) << 0)
52 #define VERSION_IS(x,y,z) ((x) << 16 | (y) << 8 | (z))
53 #define DAC_REG_ID 0x0004
54 #define DAC_ID(x) (((x) & 0xffffffff) << 0)
55 #define DAC_REG_SCRATCH 0x0008
56 #define DAC_SCRATCH(x) (((x) & 0xffffffff) << 0)
57
58 #define PCORE_VERSION_MAJOR(version) (version >> 16)
59
60 #define DAC_REG_RSTN 0x0040
61 #define DAC_RSTN (1 << 0)
62 #define DAC_MMCM_RSTN (1 << 1)
63
64 #define DAC_REG_RATECNTRL 0x004C
65 #define DAC_RATE(x) (((x) & 0xFF) << 0)
66 #define DAC_TO_RATE(x) (((x) >> 0) & 0xFF)
67
68 #define DAC_REG_CNTRL_1 0x0044
69 #define DAC_ENABLE (1 << 0) /* v7.0 */
70 #define DAC_SYNC (1 << 0) /* v8.0 */
71
72 #define DAC_REG_CNTRL_2 0x0048
73 #define DAC_PAR_TYPE (1 << 7)
74 #define DAC_PAR_ENB (1 << 6)
75 #define DAC_R1_MODE (1 << 5)
76 #define DAC_DATA_FORMAT (1 << 4)
77 #define DAC_DATA_SEL(x) (((x) & 0xF) << 0) /* v7.0 */
78 #define DAC_TO_DATA_SEL(x) (((x) >> 0) & 0xF) /* v7.0 */
79
80 #define DAC_REG_VDMA_FRMCNT 0x0084
81 #define DAC_VDMA_FRMCNT(x) (((x) & 0xFFFFFFFF) << 0)
82 #define DAC_TO_VDMA_FRMCNT(x) (((x) >> 0) & 0xFFFFFFFF)
83
84 #define DAC_REG_VDMA_STATUS 0x0088
85 #define DAC_VDMA_OVF (1 << 1)
86 #define DAC_VDMA_UNF (1 << 0)
87
88 enum dds_data_select {
89 DATA_SEL_DDS,
90 DATA_SEL_SED,
91 DATA_SEL_DMA,
92 DATA_SEL_ZERO, /* OUTPUT 0 */
93 DATA_SEL_PN7,
94 DATA_SEL_PN15,
95 DATA_SEL_PN23,
96 DATA_SEL_PN31,
97 DATA_SEL_LB, /* loopback data (ADC) */
98 DATA_SEL_PNXX, /* (Device specific) */
99 };
100
101 #define DAC_REG_CHAN_CNTRL_1_IIOCHAN(x) (0x0400 + ((x) >> 1) * 0x40 + ((x) & 1) * 0x8)
102 #define DAC_DDS_SCALE(x) (((x) & 0xFFFF) << 0)
103 #define DAC_TO_DDS_SCALE(x) (((x) >> 0) & 0xFFFF)
104
105 #define DAC_REG_CHAN_CNTRL_2_IIOCHAN(x) (0x0404 + ((x) >> 1) * 0x40 + ((x) & 1) * 0x8)
106 #define DAC_DDS_INIT(x) (((x) & 0xFFFF) << 16)
107 #define DAC_TO_DDS_INIT(x) (((x) >> 16) & 0xFFFF)
108 #define DAC_DDS_INCR(x) (((x) & 0xFFFF) << 0)
109 #define DAC_TO_DDS_INCR(x) (((x) >> 0) & 0xFFFF)
110
111 #define DDS_CHAN_TX1_I_F1 0
112 #define DDS_CHAN_TX1_I_F2 1
113 #define DDS_CHAN_TX1_Q_F1 2
114 #define DDS_CHAN_TX1_Q_F2 3
115 #define DDS_CHAN_TX2_I_F1 4
116 #define DDS_CHAN_TX2_I_F2 5
117 #define DDS_CHAN_TX2_Q_F1 6
118 #define DDS_CHAN_TX2_Q_F2 7
119
120 #define AXI_DMAC_REG_IRQ_MASK 0x80
121 #define AXI_DMAC_REG_IRQ_PENDING 0x84
122 #define AXI_DMAC_REG_IRQ_SOURCE 0x88
123
124 #define AXI_DMAC_REG_CTRL 0x400
125 #define AXI_DMAC_REG_TRANSFER_ID 0x404
126 #define AXI_DMAC_REG_START_TRANSFER 0x408
127 #define AXI_DMAC_REG_FLAGS 0x40c
128 #define AXI_DMAC_REG_DEST_ADDRESS 0x410
129 #define AXI_DMAC_REG_SRC_ADDRESS 0x414
130 #define AXI_DMAC_REG_X_LENGTH 0x418
131 #define AXI_DMAC_REG_Y_LENGTH 0x41c
132 #define AXI_DMAC_REG_DEST_STRIDE 0x420
133 #define AXI_DMAC_REG_SRC_STRIDE 0x424
134 #define AXI_DMAC_REG_TRANSFER_DONE 0x428
135 #define AXI_DMAC_REG_ACTIVE_TRANSFER_ID 0x42c
136 #define AXI_DMAC_REG_STATUS 0x430
137 #define AXI_DMAC_REG_CURRENT_DEST_ADDR 0x434
138 #define AXI_DMAC_REG_CURRENT_SRC_ADDR 0x438
139 #define AXI_DMAC_REG_DBG0 0x43c
140 #define AXI_DMAC_REG_DBG1 0x440
141
142 #define AXI_DMAC_CTRL_ENABLE (1 << 0)
143 #define AXI_DMAC_CTRL_PAUSE (1 << 1)
144
145 #define AXI_DMAC_IRQ_SOT (1 << 0)
146 #define AXI_DMAC_IRQ_EOT (1 << 1)
147
148 struct dds_state
149 {
150 uint32_t cached_freq[8];
151 uint32_t cached_phase[8];
152 int32_t cached_scale[8];
153 uint32_t *dac_clk;
154 uint32_t pcore_version;
155 uint32_t num_dds_channels;
156 bool enable;
157 bool rx2tx2;
158 };
159
160 #define DAC_REG_CHAN_CNTRL_6(c) (0x0414 + (c) * 0x40)
161 #define DAC_IQCOR_ENB (1 << 2) /* v8.0 */
162
163 #define DAC_REG_CHAN_CNTRL_7(c) (0x0418 + (c) * 0x40) /* v8.0 */
164 #define DAC_DAC_DDS_SEL(x) (((x) & 0xF) << 0)
165 #define DAC_TO_DAC_DDS_SEL(x) (((x) >> 0) & 0xF)
166
167 #define DAC_REG_CHAN_CNTRL_8(c) (0x041C + (c) * 0x40) /* v8.0 */
168 #define DAC_IQCOR_COEFF_1(x) (((x) & 0xFFFF) << 16)
169 #define DAC_TO_IQCOR_COEFF_1(x) (((x) >> 16) & 0xFFFF)
170 #define DAC_IQCOR_COEFF_2(x) (((x) & 0xFFFF) << 0)
171 #define DAC_TO_IQCOR_COEFF_2(x) (((x) >> 0) & 0xFFFF)
172
173 /******************************************************************************/
174 /************************ Functions Declarations ******************************/
175 /******************************************************************************/
176
177 int dac_init(struct ad9361_rf_phy *phy, uint8_t data_sel, uint8_t config_dma);
178 int dds_set_frequency(struct ad9361_rf_phy *phy, uint32_t chan, uint32_t freq);
179 int dds_set_phase(struct ad9361_rf_phy *phy, uint32_t chan, uint32_t phase);
180 int dds_set_scale(struct ad9361_rf_phy *phy, uint32_t chan, int32_t scale_micro_units);
181 int dds_update(struct ad9361_rf_phy *phy);
182 int dac_datasel(struct ad9361_rf_phy *phy, int32_t chan, enum dds_data_select sel);
183 int32_t dds_set_calib_scale(struct ad9361_rf_phy *phy,
184 uint32_t chan,
185 int32_t val,
186 int32_t val2);
187 int32_t dds_get_calib_scale(struct ad9361_rf_phy *phy,
188 uint32_t chan,
189 int32_t *val,
190 int32_t *val2);
191 int32_t dds_set_calib_phase(struct ad9361_rf_phy *phy,
192 uint32_t chan,
193 int32_t val,
194 int32_t val2);
195 int32_t dds_get_calib_phase(struct ad9361_rf_phy *phy,
196 uint32_t chan,
197 int32_t *val,
198 int32_t *val2);
199 #endif