Debian Codegraph @

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

raw symbols SCIP
1 /***************************************************************************//**
2 * @file ad6676.h
3 * @brief Header file of AD6676 Driver.
4 * @author DBogdan ([email protected])
5 ********************************************************************************
6 * Copyright 2015(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 AD6676_H_
40 #define AD6676_H_
41
42 /******************************************************************************/
43 /********************** Macros and Constants Definitions **********************/
44 /******************************************************************************/
45 #define AD6676_SPI_CONFIG 0x000
46 #define AD6676_DEVICE_CONFIG 0x002
47 #define AD6676_CHIP_TYPE 0x003
48 #define AD6676_CHIP_ID0 0x004
49 #define AD6676_CHIP_ID1 0x005
50 #define AD6676_GRADE_REVISION 0x006
51 #define AD6676_VENDOR_ID0 0x00C
52 #define AD6676_VENDOR_ID1 0x00D
53 #define AD6676_PCBL_DONE 0x0FE
54
55 /* CONFIGURATION SETTINGS */
56 #define AD6676_FADC_0 0x100
57 #define AD6676_FADC_1 0x101
58 #define AD6676_FIF_0 0x102
59 #define AD6676_FIF_1 0x103
60 #define AD6676_BW_0 0x104
61 #define AD6676_BW_1 0x105
62 #define AD6676_LEXT 0x106
63 #define AD6676_MRGN_L 0x107
64 #define AD6676_MRGN_U 0x108
65 #define AD6676_MRGN_IF 0x109
66 #define AD6676_XSCALE_1 0x10A
67
68 /* BP SD ADC CALIBRATION/PROFILE */
69 #define AD6676_CAL_CTRL 0x115
70 #define AD6676_CAL_CMD 0x116
71 #define AD6676_CAL_DONE 0x117
72 #define AD6676_ADC_CONFIG 0x118
73 #define AD6676_FORCE_END_CAL 0x11A
74
75 /* DIGITAL SIGNAL PATH */
76 #define AD6676_DEC_MODE 0x140
77 #define AD6676_MIX1_TUNING 0x141
78 #define AD6676_MIX2_TUNING 0x142
79 #define AD6676_MIX1_INIT 0x143
80 #define AD6676_MIX2_INIT_LSB 0x144
81 #define AD6676_MIX2_INIT_MSB 0x145
82 #define AD6676_DP_CTRL 0x146
83
84 /* POWER CONTROL */
85 #define AD6676_STANDBY 0x150
86 #define AD6676_PD_DIG 0x151
87 #define AD6676_PD_PIN_CTRL 0x152
88 #define AD6676_STBY_DAC 0x250
89
90 /* ATTENUATOR */
91 #define AD6676_ATTEN_MODE 0x180
92 #define AD6676_ATTEN_VALUE_PIN0 0x181
93 #define AD6676_ATTEN_VALUE_PIN1 0x182
94 #define AD6676_ATTEN_INIT 0x183
95 #define AD6676_ATTEN_CTL 0x184
96
97 /* ADC RESET CONTROL */
98 #define AD6676_ADCRE_THRH 0x188
99 #define AD6676_ADCRE_PULSE_LEN 0x189
100 #define AD6676_ATTEN_STEP_RE 0x18A
101 #define AD6676_TIME_PER_STEP 0x18B
102
103 /* PEAK DETECTOR AND AGC FLAG CONTROL */
104 #define AD6676_ADC_UNSTABLE 0x18F
105 #define AD6676_PKTHRH0_LSB 0x193
106 #define AD6676_PKTHRH0_MSB 0x194
107 #define AD6676_PKTHRH1_LSB 0x195
108 #define AD6676_PKTHRH1_MSB 0x196
109 #define AD6676_LOWTHRH_LSB 0x197
110 #define AD6676_LOWTHRH_MSB 0x198
111 #define AD6676_DWELL_TIME_MANTISSA 0x199
112 #define AD6676_DWELL_TIME_EXP 0x19A
113 #define AD6676_FLAG0_SEL 0x19B
114 #define AD6676_FLAG1_SEL 0x19C
115 #define AD6676_EN_FLAG 0x19E
116
117 /* GPIO CONFIGURATION */
118 #define AD6676_FORCE_GPIO 0x1B0
119 #define AD6676_FORCE_GPIO_OUT 0x1B1
120 #define AD6676_FORCE_GPIO_VAL 0x1B2
121 #define AD6676_READ_GPO 0x1B3
122 #define AD6676_READ_GPI 0x1B4
123
124 /* JESD204B INTERFACE */
125 #define AD6676_DID 0x1C0
126 #define AD6676_BID 0x1C1
127 #define AD6676_L 0x1C3
128 #define AD6676_F 0x1C4
129 #define AD6676_K 0x1C5
130 #define AD6676_M 0x1C6
131 #define AD6676_S 0x1C9
132 #define AD6676_HD 0x1CA
133 #define AD6676_RES1 0x1CB
134 #define AD6676_RES2 0x1CC
135 #define AD6676_LID0 0x1D0
136 #define AD6676_LID1 0x1D1
137 #define AD6676_FCHK0 0x1D8
138 #define AD6676_FCHK1 0x1D9
139 #define AD6676_EN_LFIFO 0x1E0
140 #define AD6676_SWAP 0x1E1
141 #define AD6676_LANE_PD 0x1E2
142 #define AD6676_MIS1 0x1E3
143 #define AD6676_SYNC_PIN 0x1E4
144 #define AD6676_TEST_GEN 0x1E5
145 #define AD6676_KF_ILAS 0x1E6
146 #define AD6676_SYNCB_CTRL 0x1E7
147 #define AD6676_MIX_CTRL 0x1E8
148 #define AD6676_K_OFFSET 0x1E9
149 #define AD6676_SYSREF 0x1EA
150 #define AD6676_SER1 0x1EB
151 #define AD6676_SER2 0x1EC
152
153 #define AD6676_CLKSYN_ENABLE 0x2A0
154 #define AD6676_CLKSYN_INT_N_LSB 0x2A1
155 #define AD6676_CLKSYN_INT_N_MSB 0x2A2
156 #define AD6676_CLKSYN_LOGEN 0x2A5
157 #define AD6676_CLKSYN_VCO_BIAS 0x2AA
158 #define AD6676_CLKSYN_VCO_CAL 0x2AB
159 #define AD6676_CLKSYN_I_CP 0x2AC
160 #define AD6676_CLKSYN_CP_CAL 0x2AD
161 #define AD6676_CLKSYN_VCO_VAR 0x2B7
162 #define AD6676_CLKSYN_R_DIV 0x2BB
163 #define AD6676_CLKSYN_STATUS 0x2BC
164 #define AD6676_JESDSYN_STATUS 0x2DC
165
166 #define AD6676_SHUFFLE_THREG0 0x342
167 #define AD6676_SHUFFLE_THREG1 0x343
168
169 /*
170 * AD6676_SPI_CONFIG
171 */
172
173 #define SPI_CONF_SW_RESET (0x81)
174 #define SPI_CONF_SDIO_DIR (0x18)
175
176
177 /*
178 * AD6676_CLKSYN_STATUS, AD6676_JESDSYN_STATUS
179 */
180 #define SYN_STAT_PLL_LCK (1 << 3)
181 #define SYN_STAT_VCO_CAL_BUSY (1 << 1)
182 #define SYN_STAT_CP_CAL_DONE (1 << 0)
183
184 /*
185 * AD6676_DP_CTRL
186 */
187 #define DP_CTRL_OFFSET_BINARY (1 << 0)
188 #define DP_CTRL_TWOS_COMPLEMENT (0 << 0)
189
190 /*
191 * AD6676_TEST_GEN
192 */
193 #define TESTGENMODE_OFF 0x0
194 #define TESTGENMODE_ALT_CHECKERBOARD 0x1
195 #define TESTGENMODE_ONE_ZERO_TOGGLE 0x2
196 #define TESTGENMODE_PN23_SEQ 0x3
197 #define TESTGENMODE_PN9_SEQ 0x4
198 #define TESTGENMODE_REP_USER_PAT 0x5
199 #define TESTGENMODE_SING_USER_PAT 0x6
200 #define TESTGENMODE_RAMP 0x7
201 #define TESTGENMODE_MOD_RPAT 0x8
202 #define TESTGENMODE_JSPAT 0x10
203 #define TESTGENMODE_JTSPAT 0x11
204
205 /*
206 * AD6676_CLKSYN_R_DIV
207 */
208
209 #define R_DIV(x) ((x) << 6);
210 #define CLKSYN_R_DIV_RESERVED 0x3D
211
212 /*
213 * AD6676_CLKSYN_ENABLE
214 */
215 #define EN_EXT_CK (1 << 7)
216 #define EN_ADC_CK (1 << 6)
217 #define EN_SYNTH (1 << 5)
218 #define EN_VCO_PTAT (1 << 4)
219 #define EN_VCO_ALC (1 << 3)
220 #define EN_VCO (1 << 2)
221 #define EN_OVER_IDE_CAL (1 << 1)
222 #define EN_OVER_IDE (1 << 0)
223
224 /*
225 * AD6676_CLKSYN_LOGEN
226 */
227
228 #define RESET_CAL (1 << 3)
229
230 /*
231 * AD6676_CLKSYN_VCO_CAL
232 */
233
234 #define INIT_ALC_VALUE(x) ((x) << 4)
235 #define ALC_DIS (1 << 3)
236
237 /*
238 * AD6676_CLKSYN_CP_CAL
239 */
240 #define CP_CAL_EN (1 << 7)
241
242 /*
243 * AD6676_DEC_MODE
244 */
245
246 #define DEC_32 1
247 #define DEC_24 2
248 #define DEC_16 3
249 #define DEC_12 4
250
251 /*
252 * AD6676_CAL_CMD
253 */
254
255 #define XCMD3 (1 << 7)
256 #define XCMD2 (1 << 6)
257 #define XCMD1 (1 << 5)
258 #define XCMD0 (1 << 4)
259 #define RESON1_CAL (1 << 3)
260 #define FLASH_CAL (1 << 2)
261 #define INIT_ADC (1 << 1)
262 #define TUNE_ADC (1 << 0)
263
264 /*
265 * AD6676_SYNCB_CTRL
266 */
267 #define PD_SYSREF_RX (1 << 3)
268 #define LVDS_SYNCB (1 << 2)
269
270 /* AD6676_L */
271 #define SCR (1 << 7)
272
273 /* AD6676_FORCE_END_CAL */
274 #define FORCE_END_CAL (1 << 0)
275
276 /* AD6676_CAL_DONE */
277 #define CAL_DONE (1 << 0)
278
279 #define MHz 1000000UL
280 #define MIN_FADC 2000000000ULL /* SPS */
281 #define MIN_FADC_INT_SYNTH 2925000000ULL /* SPS REVISIT */
282 #define MAX_FADC 3200000000ULL /* SPS */
283
284 #define MIN_FIF 70000000ULL /* Hz */
285 #define MAX_FIF 450000000ULL /* Hz */
286
287 #define MIN_BW 20000000ULL /* Hz */
288 #define MAX_BW 160000000ULL /* Hz */
289
290 #define CHIPID0_AD6676 0xBB
291
292 enum {
293 ID_AD6676,
294 };
295
296 struct ad6676_jesd_conf {
297 uint8_t scrambling_en;
298 uint8_t lvds_syncb;
299 uint8_t sysref_pd;
300 uint8_t l; /* lanes */
301 uint8_t f; /* Frames per multi frame */
302 };
303
304 struct ad6676_base_conf {
305 uint32_t f_adc_hz;
306 uint32_t f_if_hz;
307 uint32_t f_if_min_hz; /* depend on Lext */
308 uint32_t f_if_max_hz; /* depend on Lext */
309 uint32_t bw_hz;
310 uint8_t bw_margin_low_mhz;
311 uint8_t bw_margin_high_mhz;
312 int8_t bw_margin_if_mhz;
313 uint8_t decimation;
314 uint8_t ext_l;
315 uint8_t attenuation;
316 uint8_t scale;
317 uint8_t use_extclk;
318 uint8_t fadc_fixed;
319 };
320
321 struct ad6676_shuffler_conf {
322 uint8_t shuffle_ctrl;
323 uint8_t shuffle_thresh;
324 };
325
326 struct ad6676_gpio {
327 int32_t adc_oen;
328 int32_t adc_sela;
329 int32_t adc_selb;
330 int32_t adc_s0;
331 int32_t adc_s1;
332 int32_t adc_resetb;
333 int32_t adc_agc1;
334 int32_t adc_agc2;
335 int32_t adc_agc3;
336 int32_t adc_agc4;
337 };
338
339 struct ad6676_platform_data {
340 struct ad6676_base_conf base;
341 struct ad6676_jesd_conf jesd;
342 struct ad6676_shuffler_conf shuffler;
343 struct ad6676_gpio gpio;
344 uint8_t spi3wire;
345 };
346
347 struct ad6676_phy {
348 struct ad6676_platform_data *pdata;
349 uint32_t ref_clk;
350 uint32_t m;
351 };
352
353 typedef struct
354 {
355 /* GPIO */
356 gpio_type gpio_type;
357 uint32_t gpio_device_id;
358 int32_t gpio_adc_oen;
359 int32_t gpio_adc_sela;
360 int32_t gpio_adc_selb;
361 int32_t gpio_adc_s0;
362 int32_t gpio_adc_s1;
363 int32_t gpio_adc_resetb;
364 int32_t gpio_adc_agc1;
365 int32_t gpio_adc_agc2;
366 int32_t gpio_adc_agc3;
367 int32_t gpio_adc_agc4;
368 /* SPI */
369 uint8_t spi_chip_select;
370 spi_mode spi_mode;
371 spi_type spi_type;
372 uint32_t spi_device_id;
373 /* Device Settings */
374 uint32_t reference_clk_rate;
375 uint8_t spi_3wire_enable;
376 /* Base Configuration */
377 uint32_t adc_frequency_hz;
378 uint32_t intermediate_frequency_hz;
379 uint32_t intermediate_frequency_min_hz;
380 uint32_t intermediate_frequency_max_hz;
381 uint32_t bandwidth_hz;
382 uint8_t bandwidth_margin_low_mhz;
383 uint8_t bandwidth_margin_high_mhz;
384 int8_t bandwidth_margin_if_mhz;
385 uint8_t decimation;
386 uint8_t external_inductance_l_nh;
387 uint8_t idac1_fullscale_adjust;
388 uint8_t use_external_clk_enable;
389 uint8_t adc_frequency_fixed_enable;
390 /* JESD Configuration */
391 uint8_t jesd_scrambling_enable;
392 uint8_t jesd_use_lvds_syncb_enable;
393 uint8_t jesd_powerdown_sysref_enable;
394 uint8_t jesd_l_lanes;
395 uint8_t jesd_f_frames_per_multiframe;
396 /* Shuffler Configuration */
397 uint8_t shuffler_control;
398 uint8_t shuffler_thresh;
399 }ad6676_init_param;
400
401 typedef struct {
402 spi_device spi_dev;
403 gpio_device gpio_dev;
404 struct ad6676_phy *phy;
405 } ad6676_dev;
406
407 /******************************************************************************/
408 /************************ Functions Declarations ******************************/
409 /******************************************************************************/
410 int32_t ad6676_spi_read(ad6676_dev *dev,
411 uint16_t reg_addr,
412 uint8_t *reg_data);
413 int32_t ad6676_spi_write(ad6676_dev *dev,
414 uint16_t reg_addr,
415 uint8_t reg_data);
416 int32_t ad6676_setup(ad6676_dev **device,
417 ad6676_init_param init_param);
418 int32_t ad6676_set_if_frequency(ad6676_dev *dev,
419 uint32_t if_freq_hz);
420 int32_t ad6676_get_if_frequency(ad6676_dev *dev,
421 uint32_t *if_freq_hz);
422 int32_t ad6676_set_if_bandwidth(ad6676_dev *dev,
423 uint32_t if_bw_hz);
424 int32_t ad6676_get_if_bandwidth(ad6676_dev *dev,
425 uint32_t *if_bw_hz);
426 int32_t ad6676_set_scale(ad6676_dev *dev,
427 uint8_t scale);
428 int32_t ad6676_get_scale(ad6676_dev *dev,
429 uint8_t *scale);
430 int32_t ad6676_set_attenuation(ad6676_dev *dev,
431 uint8_t attenuation);
432 int32_t ad6676_get_attenuation(ad6676_dev *dev,
433 uint8_t *attenuation);
434 #endif