Debian Codegraph @

thirdparty/analogdevicesinc/no-OS/drivers/ad9739a/ad9739a.h

raw symbols SCIP
1 /***************************************************************************//**
2 * @file AD9739A.h
3 * @brief Header file of AD9739A Driver.
4 * @author Bancisor Mihai
5 ********************************************************************************
6 * Copyright 2012(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 ********************************************************************************
40 * SVN Revision: $WCREV$
41 *******************************************************************************/
42 #ifndef __AD9739A_H__
43 #define __AD9739A_H__
44
45 /******************************************************************************/
46 /***************************** Include Files **********************************/
47 /******************************************************************************/
48 #include <stdint.h>
49
50 /******************************************************************************/
51 /***************************** AD9739A ****************************************/
52 /******************************************************************************/
53
54 #define AD9739A_READ (1 << 7)
55 #define AD9739A_WRITE (0 << 7)
56
57 /* Registers */
58 #define AD9739A_REG_MODE 0x00
59 #define AD9739A_REG_POWER_DOWN 0x01
60 #define AD9739A_REG_CNT_CLK_DIS 0x02
61 #define AD9739A_REG_IRQ_EN 0x03
62 #define AD9739A_REG_IRQ_REQ 0x04
63 #define AD9739A_REG_FSC_1 0x06
64 #define AD9739A_REG_FSC_2 0x07
65 #define AD9739A_REG_DEC_CNT 0x08
66 #define AD9739A_REG_LVDS_STAT1 0x0C
67 #define AD9739A_REG_LVDS_REC_CNT1 0x10
68 #define AD9739A_REG_LVDS_REC_CNT2 0x11
69 #define AD9739A_REG_LVDS_REC_CNT3 0x12
70 #define AD9739A_REG_LVDS_REC_CNT4 0x13
71 #define AD9739A_REG_LVDS_REC_CNT5 0x14
72 #define AD9739A_REG_LVDS_REC_STAT1 0x19
73 #define AD9739A_REG_LVDS_REC_STAT2 0x1A
74 #define AD9739A_REG_LVDS_REC_STAT3 0x1B
75 #define AD9739A_REG_LVDS_REC_STAT4 0x1C
76 #define AD9739A_REG_LVDS_REC_STAT9 0x21
77 #define AD9739A_REG_CROSS_CNT1 0x22
78 #define AD9739A_REG_CROSS_CNT2 0x23
79 #define AD9739A_REG_PHS_DET 0x24
80 #define AD9739A_REG_MU_DUTY 0x25
81 #define AD9739A_REG_MU_CNT1 0x26
82 #define AD9739A_REG_MU_CNT2 0x27
83 #define AD9739A_REG_MU_CNT3 0x28
84 #define AD9739A_REG_MU_CNT4 0x29
85 #define AD9739A_REG_MU_STAT1 0x2A
86 #define AD9739A_REG_PART_ID 0x35
87
88 /* AD9739A_REG_MODE definitions, address 0x00 */
89 #define AD9739A_MODE_SDIO_DIR ((1 << 7) | (1 << 0))
90 #define AD9739A_MODE_LSB ((1 << 6) | (1 << 1))
91 #define AD9739A_MODE_RESET ((1 << 5) | (1 << 2))
92
93 /* AD9739A_REG_POWER_DOWN definitions, address 0x01 */
94 #define AD9739A_POWER_DOWN_LVDS_DRVR_PD (1 << 5)
95 #define AD9739A_POWER_DOWN_LVDS_RCVR_PD (1 << 4)
96 #define AD9739A_POWER_DOWN_CLK_RCVR_PD (1 << 1)
97 #define AD9739A_POWER_DOWN_DAC_BIAS_PD (1 << 0)
98
99 /* AD9739A_REG_CNT_CLK_DIS definitions, address 0x02 */
100 #define AD9739A_CNT_CLK_DIS_CLKGEN_PD (1 << 3)
101 #define AD9739A_CNT_CLK_DIS_REC_CNT_CLK (1 << 1)
102 #define AD9739A_CNT_CLK_DIS_MU_CNT_CLK (1 << 0)
103
104 /* AD9739A_REG_IRQ_EN definitions, address 0x03 */
105 #define AD9739A_IRQ_EN_MU_LST_EN (1 << 3)
106 #define AD9739A_IRQ_EN_MU_LCK_EN (1 << 2)
107 #define AD9739A_IRQ_EN_RCV_LST_EN (1 << 1)
108 #define AD9739A_IRQ_EN_RCV_LCK_EN (1 << 0)
109
110 /* AD9739A_REG_IRQ_REQ definitions, address 0x04 */
111 #define AD9739A_IRQ_REQ_MU_LST_IRQ (1 << 3)
112 #define AD9739A_IRQ_REQ_MU_LCK_IRQ (1 << 2)
113 #define AD9739A_IRQ_REQ_RCV_LST_IRQ (1 << 1)
114 #define AD9739A_IRQ_REQ_RCV_LCK_IRQ (1 << 0)
115
116 /* AD9739A_REG_FSC_1 definitions, address 0x06 */
117 #define AD9739A_FSC_1_FSC_1(x) (((x) & 0xFF) << 0)
118
119 /* AD9739A_REG_FSC_2 definitions, address 0x07 */
120 #define AD9739A_FSC_2_FSC_2(x) (((x) & 0x3) << 0)
121 #define AD9739A_FSC_2_Sleep (1 << 7)
122
123 /* AD9739A_REG_DEC_CNT definitions, address 0x08 */
124 #define AD9739A_DEC_CNT_DAC_DEC(x) (((x) & 0x3) << 0)
125 #define AD9739A_DAC_DEC_NORMAL_BASEBAND 0 // AD9739A_DEC_CNT_DAC_DEC(x) option.
126 #define AD9739A_DAC_DEC_MIX_MODE 2 // AD9739A_DEC_CNT_DAC_DEC(x) option.
127
128 /* AD9739A_REG_LVDS_STAT1 definitions, address 0x0C */
129 #define AD9739A_LVDS_STAT1_DCI_PRE_PH0 (1 << 2)
130 #define AD9739A_LVDS_STAT1_DCI_PST_PH0 (1 << 0)
131
132 /* AD9739A_REG_LVDS_REC_CNT1 definitions, address 0x10 */
133 #define AD9739A_LVDS_REC_CNT1_RCVR_FLG_RST (1 << 2)
134 #define AD9739A_LVDS_REC_CNT1_RCVR_LOOP_ON (1 << 1)
135 #define AD9739A_LVDS_REC_CNT1_RCVR_CNT_ENA (1 << 0)
136
137 /* AD9739A_REG_LVDS_REC_CNT2 definitions, address 0x11 */
138 #define AD9739A_LVDS_REC_CNT2_SMP_DEL(x) (((x) & 0x3) << 6)
139
140 /* AD9739A_REG_LVDS_REC_CNT3 definitions, address 0x12 */
141 #define AD9739A_LVDS_REC_CNT3_SMP_DEL(x) (((x) & 0xFF) << 0)
142
143 /* AD9739A_REG_LVDS_REC_CNT4 definitions, address 0x13 */
144 #define AD9739A_LVDS_REC_CNT4_DCI_DEL(x) (((x) & 0xF) << 4)
145 #define AD9739A_LVDS_REC_CNT4_FINE_DEL_SKEW(x) (((x) & 0xF) << 0)
146
147 /* AD9739A_REG_LVDS_REC_CNT5 definitions, address 0x14 */
148 #define AD9739A_LVDS_REC_CNT5_DCI_DEL(x) (((x) & 0x3F) << 0)
149
150 /* AD9739A_REG_LVDS_REC_STAT1 definitions, address 0x19 */
151 #define AD9739A_LVDS_REC_STAT1_SMP_DEL(x) (((x) & 0x3) << 6)
152
153 /* AD9739A_REG_LVDS_REC_STAT2 definitions, address 0x1A */
154 #define AD9739A_LVDS_REC_STAT2_SMP_DEL(x) (((x) & 0xFF) << 0)
155
156 /* AD9739A_REG_LVDS_REC_STAT3 definitions, address 0x1B */
157 #define AD9739A_LVDS_REC_STAT3_DCI_DEL(x) (((x) & 0x3) << 6)
158
159 /* AD9739A_REG_LVDS_REC_STAT4 definitions, address 0x1C */
160 #define AD9739A_LVDS_REC_STAT4_DCI_DEL(x) (((x) & 0xFF) << 0)
161
162 /* AD9739A_REG_LVDS_REC_STAT9 definitions, address 0x21 */
163 #define AD9739A_LVDS_REC_STAT9_RCVR_TRK_ON (1 << 3)
164 #define AD9739A_LVDS_REC_STAT9_RCVR_FE_ON (1 << 2)
165 #define AD9739A_LVDS_REC_STAT9_RCVR_LST (1 << 1)
166 #define AD9739A_LVDS_REC_STAT9_RCVR_LCK (1 << 0)
167
168 /* AD9739A_REG_CROSS_CNT1 definitions, address 0x22 */
169 #define AD9739A_CROSS_CNT1_DIR_P (1 << 4)
170 #define AD9739A_CROSS_CNT1_CLKP_OFFSET(x) (((x) & 0xF) << 0)
171
172 /* AD9739A_REG_CROSS_CNT2 definitions, address 0x23 */
173 #define AD9739A_CROSS_CNT2_DIR_N (1 << 4)
174 #define AD9739A_CROSS_CNT2_CLKN_OFFSET(x) (((x) & 0xF) << 0)
175
176 /* AD9739A_REG_PHS_DET definitions, address 0x24 */
177 #define AD9739A_PHS_DET_CMP_BST (1 << 5)
178 #define AD9739A_PHS_DET_PHS_DET_AUTO_EN (1 << 4)
179
180 /* AD9739A_REG_MU_DUTY definitions, address 0x25 */
181 #define AD9739A_MU_DUTY_MU_DUTY_AUTO_EN (1 << 7)
182
183 /* AD9739A_REG_MU_CNT1 definitions, address 0x26 */
184 #define AD9739A_MU_CNT1_SLOPE (1 << 6)
185 #define AD9739A_MU_CNT1_MODE(x) (((x) & 0x3) << 4)
186 #define AD9739A_MU_CNT1_READ (1 << 3)
187 #define AD9739A_MU_CNT1_GAIN(x) (((x) & 0x3) << 1)
188 #define AD9739A_MU_CNT1_ENABLE (1 << 0)
189
190 /* AD9739A_REG_MU_CNT2 definitions, address 0x27 */
191 #define AD9739A_MU_CNT2_MUDEL (1 << 7)
192 #define AD9739A_MU_CNT2_SRCH_MODE(x) ((((x) & 0x3) << 5))
193 #define AD9739A_MU_CNT2_SET_PHS(x) ((((x) & 0x1F) << 0))
194
195 /* AD9739A_REG_MU_CNT3 definitions, address 0x28 */
196 #define AD9739A_MU_CNT3_MUDEL(x) ((((x) & 0xFF) << 0))
197
198 /* AD9739A_REG_MU_CNT4 definitions, address 0x29 */
199 #define AD9739A_MU_CNT4_SEARCH_TOL (1 << 7)
200 #define AD9739A_MU_CNT4_RETRY (1 << 6)
201 #define AD9739A_MU_CNT4_CONTRST (1 << 5)
202 #define AD9739A_MU_CNT4_GUARD(x) ((((x) & 0x1F) << 0))
203
204 /* AD9739A_REG_MU_STAT1 definitions, address 0x2A */
205 #define AD9739A_MU_STAT1_MU_LST (1 << 1)
206 #define AD9739A_MU_STAT1_MU_LKD (1 << 0)
207
208 /* AD9739A_REG_PART_ID definitions, address 0x35 */
209 #define AD9739A_PART_ID_PART_ID(x) ((((x) & 0xFF) << 0))
210
211 /******************************************************************************/
212 /************************ Types Definitions ***********************************/
213 /******************************************************************************/
214
215 /**
216 * struct ad9739a_platform_data - Platform specific information.
217 *
218 * @common_mode_voltage_dacclk_p: magnitude of the offset for the DACCLK_P.
219 * @common_mode_voltage_dacclk_n: magnitude of the offset for the DACCLK_N.
220
221 */
222 struct ad9739a_platform_data
223 {
224 uint8_t common_mode_voltage_dacclk_p;
225 uint8_t common_mode_voltage_dacclk_n;
226 float full_scale_current;
227 };
228
229 typedef struct
230 {
231 /* SPI */
232 uint8_t spi_chip_select;
233 spi_mode spi_mode;
234 spi_type spi_type;
235 uint32_t spi_device_id;
236 /* Device settings */
237 uint8_t common_mode_voltage_dacclk_p;
238 uint8_t common_mode_voltage_dacclk_n;
239 float full_scale_current;
240 }ad9739a_init_param;
241
242 typedef struct {
243 spi_device spi_dev;
244 struct ad9739a_platform_data *pdata;
245 } ad9739a_dev;
246
247 /******************************************************************************/
248 /************************ Functions Declarations ******************************/
249 /******************************************************************************/
250
251 /*! Writes a value to the selected register. */
252 int32_t ad9739a_write(ad9739a_dev *dev,
253 uint8_t registerAddress,
254 uint8_t registerValue);
255 /*! Reads the value of the selected register. */
256 int32_t ad9739a_read(ad9739a_dev *dev,
257 uint8_t registerAddress);
258 /*! Resets the device. */
259 int32_t ad9739a_reset(ad9739a_dev *dev);
260 /*! Powers down LVDS interface and TxDAC. */
261 int32_t ad9739a_power_down(ad9739a_dev *dev,
262 uint8_t pwrConfig);
263 /*! Sets the normal baseband mode or mix-mode. */
264 int32_t ad9739a_operation_mode(ad9739a_dev *dev,
265 uint8_t mode);
266 /*! Sets the full-scale output current for the DAC. */
267 float ad9739a_DAC_fs_current(ad9739a_dev *dev,
268 float fs_val);
269 /*! Delay for a number of fdata clock cycles. */
270 int32_t delay_fdata_cycles(uint32_t cycles);
271 /*! Initializes the AD9739A. */
272 int32_t ad9739a_setup(ad9739a_dev **device,
273 ad9739a_init_param init_param);
274
275 #endif /* __AD9739A_H__ */