Debian Codegraph @

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

raw symbols SCIP
1 /***************************************************************************//**
2 * @file AD9528.h
3 * @brief Header file of AD9528 Driver.
4 * @author DBogdan ([email protected])
5 ********************************************************************************
6 * Copyright 2015-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 *******************************************************************************/
40 #ifndef _AD9528_H_
41 #define _AD9528_H_
42
43 /*****************************************************************************/
44 /***************************** Include Files *********************************/
45 /*****************************************************************************/
46 #include "platform_drivers.h"
47
48 /******************************************************************************/
49 /****************************** AD9528 ****************************************/
50 /******************************************************************************/
51 /* Registers */
52
53 #define AD9528_READ (1 << 15)
54 #define AD9528_WRITE (0 << 15)
55 #define AD9528_CNT(x) (((x) - 1) << 13)
56 #define AD9528_ADDR(x) ((x) & 0xFFF)
57
58 #define AD9528_1B(x) ((1 << 16) | ((x) + 0))
59 #define AD9528_2B(x) ((2 << 16) | ((x) + 1))
60 #define AD9528_3B(x) ((3 << 16) | ((x) + 2))
61 #define AD9528_4B(x) ((4 << 16) | ((x) + 3))
62 #define AD9528_TRANSF_LEN(x) ((x) >> 16)
63
64 #define AD9528_SERIAL_PORT_CONFIG AD9528_1B(0x0)
65 #define AD9528_SERIAL_PORT_CONFIG_B AD9528_1B(0x1)
66 #define AD9528_CHIP_ID AD9528_4B(0x3)
67 #define AD9528_IO_UPDATE AD9528_1B(0xF)
68
69 #define AD9528_PLL1_REF_A_DIVIDER AD9528_2B(0x100)
70 #define AD9528_PLL1_REF_B_DIVIDER AD9528_2B(0x102)
71 #define AD9528_PLL1_FEEDBACK_DIVIDER AD9528_2B(0x104)
72 #define AD9528_PLL1_CHARGE_PUMP_CTRL AD9528_2B(0x106)
73 #define AD9528_PLL1_CTRL AD9528_3B(0x108)
74
75 #define AD9528_PLL2_CHARGE_PUMP AD9528_1B(0x200)
76 #define AD9528_PLL2_FEEDBACK_DIVIDER_AB AD9528_1B(0x201)
77 #define AD9528_PLL2_CTRL AD9528_1B(0x202)
78 #define AD9528_PLL2_VCO_CTRL AD9528_1B(0x203)
79 #define AD9528_PLL2_VCO_DIVIDER AD9528_1B(0x204)
80 #define AD9528_PLL2_LOOP_FILTER_CTRL AD9528_2B(0x205)
81 #define AD9528_PLL2_R1_DIVIDER AD9528_1B(0x207)
82 #define AD9528_PLL2_N2_DIVIDER AD9528_1B(0x208)
83
84 #define AD9528_CHANNEL_OUTPUT(ch) AD9528_3B(0x300 + 3 * ch)
85 #define AD9528_CHANNEL_SYNC AD9528_1B(0x32A)
86 #define AD9528_CHANNEL_SYNC_IGNORE AD9528_2B(0x32B)
87
88 #define AD9528_SYSREF_K_DIVIDER AD9528_2B(0x400)
89 #define AD9528_SYSREF_CTRL AD9528_2B(0x402)
90
91 #define AD9528_PD_EN AD9528_1B(0x500)
92 #define AD9528_CHANNEL_PD_EN AD9528_2B(0x501)
93
94 #define AD9528_READBACK AD9528_2B(0x508)
95
96 /* AD9528_SERIAL_PORT_CONFIG */
97 #define AD9528_SER_CONF_SOFT_RESET ((1 << 0) | (1 << 7))
98 #define AD9528_SER_CONF_LSB_FIRST ((1 << 1) | (1 << 6))
99 #define AD9528_SER_CONF_ADDR_INCREMENT ((1 << 2) | (1 << 5))
100 #define AD9528_SER_CONF_SDO_ACTIVE ((1 << 3) | (1 << 4))
101
102 /* AD9528_SERIAL_PORT_CONFIG_B */
103 #define AD9528_SER_CONF_READ_BUFFERED (1 << 5)
104 #define AD9528_SER_CONF_RESET_SANS_REGMAP (1 << 2)
105
106 /* AD9528_IO_UPDATE */
107 #define AD9528_IO_UPDATE_EN (1 << 0)
108
109 /* AD9528_PLL1_CHARGE_PUMP_CTRL */
110 #define AD9528_PLL1_CHARGE_PUMP_AUTO_TRISTATE_DIS (1 << 12)
111 #define AD9528_PLL1_CHARGE_PUMP_MODE_NORMAL (3 << 8)
112 #define AD9528_PLL1_CHARGE_PUMP_MODE_PUMP_DOWN (2 << 8)
113 #define AD9528_PLL1_CHARGE_PUMP_MODE_PUMP_UP (1 << 8)
114 #define AD9528_PLL1_CHARGE_PUMP_MODE_TRISTATE (0 << 8)
115 #define AD9528_PLL1_CHARGE_PUMP_TRISTATE (1 << 7)
116 #define AD9528_PLL1_CHARGE_PUMP_CURRENT_nA(x) (((x) / 500) & 0x7F)
117
118 /* AD9528_PLL1_CTRL */
119 #define AD9528_PLL1_OSC_CTRL_FAIL_VCC_BY2_EN (1 << 18)
120 #define AD9528_PLL1_REF_MODE(x) ((x) << 16)
121 #define AD9528_PLL1_FEEDBACK_BYPASS_EN (1 << 13)
122 #define AD9528_PLL1_REFB_BYPASS_EN (1 << 12)
123 #define AD9528_PLL1_REFA_BYPASS_EN (1 << 11)
124 #define AD9528_PLL1_SOURCE_VCXO (1 << 10)
125 #define AD9528_PLL1_REFB_CMOS_NEG_INP_EN (1 << 9)
126 #define AD9528_PLL1_REFA_CMOS_NEG_INP_EN (1 << 8)
127 #define AD9528_PLL1_FREQ_DETECTOR_PD_EN (1 << 7)
128 #define AD9528_PLL1_REFB_DIFF_RCV_EN (1 << 6)
129 #define AD9528_PLL1_REFA_DIFF_RCV_EN (1 << 5)
130 #define AD9528_PLL1_REFB_RCV_EN (1 << 4)
131 #define AD9528_PLL1_REFA_RCV_EN (1 << 3)
132 #define AD9528_PLL1_VCXO_RCV_PD_EN (1 << 2)
133 #define AD9528_PLL1_OSC_IN_CMOS_NEG_INP_EN (1 << 1)
134 #define AD9528_PLL1_OSC_IN_DIFF_EN (1 << 0)
135
136 /* AD9528_PLL2_CHARGE_PUMP */
137 #define AD9528_PLL2_CHARGE_PUMP_CURRENT_nA(x) ((x) / 3500)
138
139 /* AD9528_PLL2_FEEDBACK_DIVIDER_AB */
140 #define AD9528_PLL2_FB_NDIV_A_CNT(x) (((x) & 0x3) << 6)
141 #define AD9528_PLL2_FB_NDIV_B_CNT(x) (((x) & 0x3F) << 0)
142 #define AD9528_PLL2_FB_NDIV(a, b) (4 * (b) + (a))
143
144 /* AD9528_PLL2_CTRL */
145 #define AD9528_PLL2_LOCK_DETECT_PWR_DOWN_EN (1 << 7)
146 #define AD9528_PLL2_FREQ_DOUBLER_EN (1 << 5)
147 #define AD9528_PLL2_CHARGE_PUMP_MODE_NORMAL (3 << 0)
148 #define AD9528_PLL2_CHARGE_PUMP_MODE_PUMP_DOWN (2 << 0)
149 #define AD9528_PLL2_CHARGE_PUMP_MODE_PUMP_UP (1 << 0)
150 #define AD9528_PLL2_CHARGE_PUMP_MODE_TRISTATE (0 << 0)
151
152 /* AD9528_PLL2_VCO_CTRL */
153 #define AD9528_PLL2_DOUBLER_R1_EN (1 << 4)
154 #define AD9528_PLL2_FORCE_REFERENCE_VALID (1 << 2)
155 #define AD9528_PLL2_FORCE_VCO_MIDSCALE (1 << 1)
156 #define AD9528_PLL2_VCO_CALIBRATE (1 << 0)
157
158 /* AD9528_PLL2_VCO_DIVIDER */
159 #define AD9528_PLL2_VCO_DIV_M1_PWR_DOWN_EN (1 << 3)
160 #define AD9528_PLL2_VCO_DIV_M1(x) (((x) & 0x7) << 0)
161
162 /* AD9528_PLL2_LOOP_FILTER_CTRL */
163 #define AD9528_PLL2_LOOP_FILTER_RZERO_BYPASS_EN (1 << 8)
164 #define AD9528_PLL2_LOOP_FILTER_RPOLE2(x) (((x) & 0x3) << 6)
165 #define AD9528_PLL2_LOOP_FILTER_RZERO(x) (((x) & 0x7) << 3)
166 #define AD9528_PLL2_LOOP_FILTER_CPOLE1(x) (((x) & 0x7) << 0)
167
168 /* AD9528_PLL2_R1_DIVIDER */
169 #define AD9528_PLL2_R1_DIV(x) (((x) & 0x1F) << 0)
170
171 /* AD9528_PLL2_N2_DIVIDER */
172 #define AD9528_PLL2_N2_DIV(x) ((((x) - 1) & 0xFF) << 0)
173
174 /* AD9528_CHANNEL_OUTPUT */
175 #define AD9528_CLK_DIST_DIV(x) ((((x) - 1) & 0xFF) << 16)
176 #define AD9528_CLK_DIST_DIV_REV(x) ((((x) >> 16) & 0xFF) + 1)
177 #define AD9528_CLK_DIST_DRIVER_MODE(x) (((x) & 0x3) << 13)
178 #define AD9528_CLK_DIST_DRIVER_MODE_REV(x) (((x) >> 13) & 0x3)
179 #define AD9528_CLK_DIST_DIV_PHASE(x) (((x) & 0x3F) << 8)
180 #define AD9528_CLK_DIST_DIV_PHASE_REV(x) (((x) >> 8) & 0x3F)
181 #define AD9528_CLK_DIST_CTRL(x) (((x) & 0x7) << 5)
182 #define AD9528_CLK_DIST_CTRL_REV(x) (((x) >> 5) & 0x7)
183
184 #if 0
185 /* Leftovers */
186 #define AD9528_CLK_DIST_INV_DIV_OUTPUT_EN (1 << 7)
187 #endif
188
189 /* AD9528_CHANNEL_SYNC */
190 #define AD9528_CHANNEL_SYNC_SET (1 << 0)
191
192 /* AD9528_CHANNEL_SYNC_IGNORE */
193 #define AD9528_CHANNEL_IGNORE_MASK(x) (((x) & 0x3FFF) << 0)
194 #define AD9528_CHANNEL_IGNORE_MASK_REV(x) (((x) >> 0) & 0x3FFF)
195
196 /* AD9528_SYSREF_K_DIVIDER */
197 #define AD9528_SYSREF_K_DIV(x) (((x) & 0xFFFF) << 0)
198
199 /* AD9528_SYSREF_CTRL */
200 #define AD9528_SYSREF_SOURCE(x) (((x) & 0x3) << 14)
201 #define AD9528_SYSREF_PATTERN_MODE(x) (((x) & 0x3) << 12)
202 #define AD9528_SYSREF_NSHOT_MODE(x) (((x) & 0x7) << 9)
203 #define AD9528_SYSREF_PATTERN_REQ (1 << 8)
204 #define AD9528_SYSREF_REQUEST_BY_PIN (1 << 7)
205 #define AD9528_SYSREF_PATTERN_TRIGGER_CTRL(x) (((x) & 0x3) << 5)
206 #define AD9528_SYSREF_RESAMPLER_CLK_SRC_PLL1 (1 << 4)
207 #define AD9528_SYSREF_PATTERN_CLK_SRC_PLL1 (1 << 3)
208 #define AD9528_SYSREF_TEST_MODE(x) (((x) & 0x3) << 1)
209 #define AD9528_SYSREF_RESET (1 << 0)
210
211 /* AD9528_PD_EN */
212 #define AD9528_PD_BIAS (1 << 4)
213 #define AD9528_PD_PLL2 (1 << 3)
214 #define AD9528_PD_PLL1 (1 << 2)
215 #define AD9528_PD_OUT_CLOCKS (1 << 1)
216 #define AD9528_PD_CHIP (1 << 0)
217
218 /* AD9528_CHANNEL_PD_EN */
219 #define AD9528_CHANNEL_PD_MASK(x) (((x) & 0x3FFF) << 0)
220 #define AD9528_CHANNEL_PD_MASK_REV(x) (((x) >> 0) & 0x3FFF)
221
222
223 /* AD9528_READBACK */
224 #define AD9528_IS_CALIBRATING (1 << 8)
225 #define AD9528_PLL2_OK (1 << 7)
226 #define AD9528_PLL1_OK (1 << 6)
227 #define AD9528_VCXO_OK (1 << 5)
228 #define AD9528_REFA_REFB_NOK (1 << 4)
229 #define AD9528_REFB_OK (1 << 3)
230 #define AD9528_REFA_OK (1 << 2)
231 #define AD9528_PLL2_LOCKED (1 << 1)
232 #define AD9528_PLL1_LOCKED (1 << 0)
233
234
235 #define AD9528_NUM_CHAN 14
236
237 #define AD9528_SPI_MAGIC 0x00FF05
238
239 /* Output Driver Mode */
240 #define DRIVER_MODE_LVDS 0
241 #define DRIVER_MODE_LVDS_BOOST 1
242 #define DRIVER_MODE_HSTL 2
243
244 /* Output Signal Source */
245 #define SOURCE_VCO 0
246 #define SOURCE_VCXO 1
247 #define SOURCE_SYSREF_VCO 2
248 #define SOURCE_SYSREF_VCXO 3
249 #define SOURCE_VCXO_INV 5
250 #define SOURCE_SYSREF_VCXO_INV 7
251
252 /* Reference Selection Mode */
253 #define REF_MODE_STAY_ON_REFB 0
254 #define REF_MODE_REVERT_TO_REFA 1
255 #define REF_MODE_SELECT_REFA 2
256 #define REF_MODE_SELECT_REFB 3
257 #define REF_MODE_EXT_REF 4
258
259 /* Sysref Source */
260 #define SYSREF_SRC_EXTERNAL 0
261 #define SYSREF_SRC_EXTERNAL_RESAMPLED 1
262 #define SYSREF_SRC_INTERNAL 2
263
264 /* Sysref Pattern Mode */
265 #define SYSREF_PATTERN_NSHOT 0
266 #define SYSREF_PATTERN_CONTINUOUS 1
267 #define SYSREF_PATTERN_PRBS 2
268 #define SYSREF_PATTERN_STOP 3
269
270 /* Rpole2 resistor */
271 #define RPOLE2_900_OHM 0
272 #define RPOLE2_450_OHM 1
273 #define RPOLE2_300_OHM 2
274 #define RPOLE2_225_OHM 3
275
276 /* Rzero resistor */
277 #define RZERO_3250_OHM 0
278 #define RZERO_2750_OHM 1
279 #define RZERO_2250_OHM 2
280 #define RZERO_2100_OHM 3
281 #define RZERO_3000_OHM 4
282 #define RZERO_2500_OHM 5
283 #define RZERO_2000_OHM 6
284 #define RZERO_1850_OHM 7
285
286 /* Cpole1 capacitor */
287 #define CPOLE1_0_PF 0
288 #define CPOLE1_8_PF 1
289 #define CPOLE1_16_PF 2
290 #define CPOLE1_24_PF 3
291 #define CPOLE1_32_PF 5
292 #define CPOLE1_40_PF 6
293 #define CPOLE1_48_PF 7
294
295 /******************************************************************************/
296 /************************ Types Definitions ***********************************/
297 /******************************************************************************/
298
299 /**
300 * struct ad9528_channel_spec - Output channel configuration
301 *
302 * @channel_num: Output channel number.
303 * @sync_ignore_en: Ignore chip-level SYNC signal.
304 * @output_dis: Disables, powers down the entire channel.
305 * @driver_mode: Output driver mode (logic level family).
306 * @divider_phase: Divider initial phase after a SYNC. Range 0..63
307 LSB = 1/2 of a period of the divider input clock.
308 * @channel_divider: 10-bit channel divider.
309 * @extended_name: Optional descriptive channel name.
310 */
311 typedef struct
312 {
313 unsigned channel_num;
314 unsigned char sync_ignore_en;
315 /* CH0..CH3 VCXO, CH4..CH9 VCO2 */
316 unsigned char output_dis;
317 unsigned char driver_mode;
318 unsigned char signal_source;
319 unsigned char divider_phase;
320 unsigned short channel_divider;
321 char extended_name[16];
322 } ad9528_channel_spec;
323
324 /**
325 * struct ad9528_platform_data - platform specific information
326 *
327 * @vcxo_freq: External VCXO frequency in Hz
328 * @spi3wire: SPI 3-Wire mode enable;
329 * @refa_en: REFA input enable.
330 * @refb_en: REFB input enable.
331 * @refa_diff_rcv_en: REFA differential/single-ended input selection.
332 * @refb_diff_rcv_en: REFB differential/single-ended input selection.
333 * @osc_in_diff_en: OSC differential/ single-ended input selection.
334 * @refa_cmos_neg_inp_en: REFA single-ended neg./pos. input enable.
335 * @refb_cmos_neg_inp_en: REFB single-ended neg./pos. input enable.
336 * @osc_in_cmos_neg_inp_en: OSC single-ended neg./pos. input enable.
337 * @refa_r_div: PLL1 10-bit REFA R divider.
338 * @refb_r_div: PLL1 10-bit REFB R divider.
339 * @pll1_feedback_div: PLL1 10-bit Feedback N divider.
340 * @pll1_feedback_src_vcxo: PLL1 Feedback source, True = VCXO, False = VCO
341 * @pll1_charge_pump_current_nA: Magnitude of PLL1 charge pump current (nA).
342 * @pll1_bypass_en: Bypass PLL1 - Single loop mode
343 * @ref_mode: Reference selection mode.
344 * @sysref_src: SYSREF pattern generator clock source
345 * @sysref_k_div: SYSREF pattern generator K divider
346 * @pll2_charge_pump_current_nA: Magnitude of PLL2 charge pump current (nA).
347 * @pll2_ndiv_a_cnt: PLL2 Feedback N-divider, A Counter, range 0..4.
348 * @pll2_ndiv_b_cnt: PLL2 Feedback N-divider, B Counter, range 0..63.
349 * @pll2_freq_doubler_en: PLL2 frequency doubler enable.
350 * @pll2_r1_div: PLL2 R1 divider, range 1..31.
351 * @pll2_n2_div: PLL2 N2 divider, range 1..256.
352 * @pll2_vco_diff_m1: VCO1 divider, range 3..5.
353 * @rpole2: PLL2 loop filter Rpole resistor value.
354 * @rzero: PLL2 loop filter Rzero resistor value.
355 * @cpole1: PLL2 loop filter Cpole capacitor value.
356 * @rzero_bypass_en: PLL2 loop filter Rzero bypass enable.
357 * @num_channels: Array size of struct ad9528_channel_spec.
358 * @channels: Pointer to channel array.
359 */
360 typedef struct
361 {
362 uint32_t vcxo_freq;
363 uint8_t spi3wire;
364
365 /* REFA / REFB input configuration */
366 uint8_t refa_en;
367 uint8_t refb_en;
368
369 /* Differential/ Single-Ended Input Configuration */
370 uint8_t refa_diff_rcv_en;
371 uint8_t refb_diff_rcv_en;
372 uint8_t osc_in_diff_en;
373
374 /*
375 * Valid if differential input disabled
376 * if false defaults to pos input
377 */
378 uint8_t refa_cmos_neg_inp_en;
379 uint8_t refb_cmos_neg_inp_en;
380 uint8_t osc_in_cmos_neg_inp_en;
381
382 /* PLL1 Setting */
383 uint16_t refa_r_div;
384 uint16_t refb_r_div;
385 uint16_t pll1_feedback_div;
386 uint8_t pll1_feedback_src_vcxo;
387 uint16_t pll1_charge_pump_current_nA;
388 uint8_t pll1_bypass_en;
389
390 /* Reference */
391 uint8_t ref_mode;
392 uint8_t sysref_src;
393 uint16_t sysref_k_div;
394
395 /* PLL2 Setting */
396 unsigned int pll2_charge_pump_current_nA;
397 uint8_t pll2_ndiv_a_cnt;
398 uint8_t pll2_ndiv_b_cnt;
399 uint8_t pll2_freq_doubler_en;
400 uint8_t pll2_r1_div;
401 uint8_t pll2_n2_div;
402 uint8_t pll2_vco_diff_m1; /* 3..5 */
403
404 /* Loop Filter PLL2 */
405 uint8_t rpole2;
406 uint8_t rzero;
407 uint8_t cpole1;
408 uint8_t rzero_bypass_en;
409
410 /* Output Channel Configuration */
411 int num_channels;
412 ad9528_channel_spec *channels;
413 } ad9528_platform_data;
414
415 #define ARRAY_SIZE(ar) (sizeof(ar)/sizeof(ar[0]))
416
417 /******************************************************************************/
418 /************************ Functions Declarations ******************************/
419 /******************************************************************************/
420
421 int32_t ad9528_init(ad9528_platform_data *pdata);
422 int32_t ad9528_setup(spi_device *dev, ad9528_platform_data *pdata);
423 int32_t ad9528_spi_read(spi_device *dev, uint32_t reg_addr, uint32_t *reg_data);
424 int32_t ad9528_spi_write(spi_device *dev, uint32_t reg_addr, uint32_t reg_data);
425
426 #endif // __AD9528_H__