Debian Codegraph @

thirdparty/analogdevicesinc/no-OS/drivers/ad9523/ad9523.c

raw symbols SCIP
1 /***************************************************************************//**
2 * @file AD9523.c
3 * @brief Implementation of AD9523 Driver.
4 * @author ACozma([email protected])
5 ********************************************************************************
6 * Copyright 2012-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
41 /******************************************************************************/
42 /***************************** Include Files **********************************/
43 /******************************************************************************/
44 #include "ad9523.h"
45
46 /******************************************************************************/
47 /************************ Local variables and types ***************************/
48 /******************************************************************************/
49 struct ad9523_state
50 {
51 ad9523_platform_data *pdata;
52 uint32_t vcxo_freq;
53 uint32_t vco_freq;
54 uint32_t vco_out_freq[3];
55 uint8_t vco_out_map[14];
56 }ad9523_st;
57
58 enum
59 {
60 AD9523_VCO1,
61 AD9523_VCO2,
62 AD9523_VCXO,
63 AD9523_NUM_CLK_SRC,
64 };
65
66 /* Helpers to avoid excess line breaks */
67 #define AD_IFE(_pde, _a, _b) ((pdata->_pde) ? _a : _b)
68 #define AD_IF(_pde, _a) AD_IFE(_pde, _a, 0)
69
70 /***************************************************************************//**
71 * @brief Reads the value of the selected register.
72 *
73 * @param registerAddress - The address of the register to read.
74 *
75 * @return registerValue - The register's value or negative error code.
76 *******************************************************************************/
77 int32_t ad9523_spi_read(spi_device *dev,
78 uint32_t reg_addr,
79 uint32_t *reg_data)
80 {
81 uint8_t buf[3];
82 int32_t ret = 0;
83 uint8_t index;
84
85 *reg_data = 0;
86 for(index = 0; index < AD9523_TRANSF_LEN(reg_addr); index++)
87 {
88 buf[0] = 0x80 | (reg_addr >> 8);
89 buf[1] = reg_addr & 0xFF;
90 buf[2] = 0x00;
91 ret |= ad_spi_xfer(dev, buf, 3);
92 reg_addr--;
93 *reg_data <<= 8;
94 *reg_data |= buf[2];
95 }
96
97 return ret;
98 }
99
100 /***************************************************************************//**
101 * @brief Writes a value to the selected register.
102 *
103 * @param registerAddress - The address of the register to write to.
104 * @param registerValue - The value to write to the register.
105 *
106 * @return Returns 0 in case of success or negative error code.
107 *******************************************************************************/
108 int32_t ad9523_spi_write(spi_device *dev,
109 uint32_t reg_addr,
110 uint32_t reg_data)
111 {
112 uint8_t buf[3];
113 int32_t ret = 0;
114 uint8_t index;
115
116 for(index = 0; index < AD9523_TRANSF_LEN(reg_addr); index++)
117 {
118 buf[0] = reg_addr >> 8;
119 buf[1] = reg_addr & 0xFF;
120 buf[2] = (reg_data >> ((AD9523_TRANSF_LEN(reg_addr) - index - 1) * 8)) & 0xFF;
121 ret |= ad_spi_xfer(dev, buf, 3);
122 reg_addr--;
123 }
124
125 return ret;
126 }
127
128 /***************************************************************************//**
129 * @brief Updates the AD9523 configuration
130 *
131 * @return Returns 0 in case of success or negative error code.
132 *******************************************************************************/
133 int32_t ad9523_io_update(spi_device *dev)
134 {
135 return ad9523_spi_write(dev, AD9523_IO_UPDATE, AD9523_IO_UPDATE_EN);
136 }
137
138 /***************************************************************************//**
139 * @brief Sets the clock provider for selected channel.
140 *
141 * @param ch - Selected channel.
142 * @param out - Selected clock provider.
143 *
144 * @return Returns 0 in case of success or negative error code.
145 *******************************************************************************/
146 int32_t ad9523_vco_out_map(spi_device *dev,
147 uint32_t ch,
148 uint32_t out)
149 {
150 struct ad9523_state *st = &ad9523_st;
151 int32_t ret;
152 uint32_t mask;
153 uint32_t reg_data;
154
155 switch (ch) {
156 case 0 ... 3:
157 ret = ad9523_spi_read(dev, AD9523_PLL1_OUTPUT_CHANNEL_CTRL, &reg_data);
158 if (ret < 0)
159 break;
160 mask = AD9523_PLL1_OUTP_CH_CTRL_VCXO_SRC_SEL_CH0 << ch;
161 if (out) {
162 reg_data |= mask;
163 out = AD9523_VCXO;
164 } else {
165 reg_data &= ~mask;
166 }
167 ret = ad9523_spi_write(dev,
168 AD9523_PLL1_OUTPUT_CHANNEL_CTRL, reg_data);
169 break;
170 case 4 ... 6:
171 ret = ad9523_spi_read(dev, AD9523_PLL1_OUTPUT_CTRL, &reg_data);
172 if (ret < 0)
173 break;
174 mask = AD9523_PLL1_OUTP_CTRL_VCO_DIV_SEL_CH4_M2 << (ch - 4);
175 if (out)
176 reg_data |= mask;
177 else
178 reg_data &= ~mask;
179 ret = ad9523_spi_write(dev, AD9523_PLL1_OUTPUT_CTRL, reg_data);
180 break;
181 case 7 ... 9:
182 ret = ad9523_spi_read(dev, AD9523_PLL1_OUTPUT_CHANNEL_CTRL, &reg_data);
183 if (ret < 0)
184 break;
185 mask = AD9523_PLL1_OUTP_CH_CTRL_VCO_DIV_SEL_CH7_M2 << (ch - 7);
186 if (out)
187 reg_data |= mask;
188 else
189 reg_data &= ~mask;
190 ret = ad9523_spi_write(dev,
191 AD9523_PLL1_OUTPUT_CHANNEL_CTRL, reg_data);
192 break;
193 default:
194 return 0;
195 }
196
197 st->vco_out_map[ch] = out;
198
199 return ret;
200 }
201
202 /***************************************************************************//**
203 * @brief Updates the AD9523 configuration.
204 *
205 * @return Returns 0 in case of success or negative error code.
206 *******************************************************************************/
207
208 // vco calibration on default setup may not work (as it is a buffered write)
209 // calibration requires all registers to be written (not in hold registers) first.
210
211 int32_t ad9523_calibrate(spi_device *dev)
212 {
213 uint32_t reg_data;
214 uint32_t timeout;
215
216 ad9523_spi_write(dev, AD9523_PLL2_VCO_CTRL, AD9523_PLL2_VCO_CALIBRATE);
217 ad9523_io_update(dev);
218
219 timeout = 0;
220 while (timeout < 100)
221 {
222 mdelay(1);
223 timeout = timeout + 1;
224 ad9523_spi_read(dev, AD9523_READBACK_1, &reg_data);
225 if ((reg_data & 0x1) == 0x0)
226 break;
227 }
228 ad9523_spi_read(dev, AD9523_READBACK_1, &reg_data);
229 if ((reg_data & 0x1) != 0x0)
230 {
231 ad_printf("AD9523: VCO calibration failed (%x)!\n", reg_data);
232 return(-1);
233 }
234
235 return(0);
236 }
237
238 /***************************************************************************//**
239 * @brief Updates the AD9523 configuration.
240 *
241 * @return Returns 0 in case of success or negative error code.
242 *******************************************************************************/
243
244 // status
245 // calibration requires all registers to be written (not in hold registers) first.
246
247 int32_t ad9523_status(spi_device *dev, ad9523_platform_data *pdata)
248 {
249 int32_t ret;
250 uint32_t reg_data;
251 uint32_t status;
252 uint32_t timeout;
253
254 status = 0;
255
256 // vcxo + pll2 must always be okay- (is it not?)
257
258 status = status | AD9523_READBACK_0_STAT_VCXO;
259 status = status | AD9523_READBACK_0_STAT_PLL2_LD;
260
261 if (pdata->pll1_bypass_en == 0)
262 {
263 status = status | AD9523_READBACK_0_STAT_PLL2_REF_CLK;
264 status = status | AD9523_READBACK_0_STAT_PLL2_FB_CLK;
265 status = status | AD9523_READBACK_0_STAT_REF_TEST;
266 status = status | AD9523_READBACK_0_STAT_REFB;
267 status = status | AD9523_READBACK_0_STAT_REFA;
268 status = status | AD9523_READBACK_0_STAT_PLL1_LD;
269 }
270
271 timeout = 0;
272 while (timeout < 100)
273 {
274 mdelay(1);
275 timeout = timeout + 1;
276 ad9523_spi_read(dev, AD9523_READBACK_0, &reg_data);
277 if ((reg_data & status) == status)
278 break;
279 }
280
281 ret = 0;
282 if ((reg_data & AD9523_READBACK_0_STAT_VCXO) != AD9523_READBACK_0_STAT_VCXO)
283 {
284 ad_printf("AD9523: VCXO status errors (%x)!\n", reg_data);
285 ret = -1;
286 }
287 if ((reg_data & AD9523_READBACK_0_STAT_PLL2_LD) != AD9523_READBACK_0_STAT_PLL2_LD)
288 {
289 ad_printf("AD9523: PLL2 NOT locked (%x)!\n", reg_data);
290 ret = -1;
291 }
292 return(ret);
293 }
294
295 /***************************************************************************//**
296 * @brief Updates the AD9523 configuration.
297 *
298 * @return Returns 0 in case of success or negative error code.
299 *******************************************************************************/
300 int32_t ad9523_sync(spi_device *dev)
301 {
302 int32_t ret, tmp;
303 uint32_t reg_data;
304
305 ret = ad9523_spi_read(dev, AD9523_STATUS_SIGNALS, &reg_data);
306 if (ret < 0)
307 return ret;
308
309 tmp = reg_data;
310 tmp |= AD9523_STATUS_SIGNALS_SYNC_MAN_CTRL;
311
312 ret = ad9523_spi_write(dev, AD9523_STATUS_SIGNALS, tmp);
313 if (ret < 0)
314 return ret;
315
316 ad9523_io_update(dev);
317 tmp &= ~AD9523_STATUS_SIGNALS_SYNC_MAN_CTRL;
318
319 ret = ad9523_spi_write(dev, AD9523_STATUS_SIGNALS, tmp);
320 if (ret < 0)
321 return ret;
322
323 return ad9523_io_update(dev);
324
325 }
326
327 /***************************************************************************//**
328 * @brief Initialize the AD9523 data structure with the default register values.
329 *
330 * @return Always return 0.
331 *******************************************************************************/
332 int32_t ad9523_init(ad9523_platform_data *pdata) {
333
334 uint32_t i = 0;
335
336 pdata->vcxo_freq = 0;
337 pdata->spi3wire = 0;
338
339 /* Differential/ Single-Ended Input Configuration */
340 pdata->refa_diff_rcv_en = 0;
341 pdata->refb_diff_rcv_en = 0;
342 pdata->zd_in_diff_en = 0;
343 pdata->osc_in_diff_en = 0;
344
345 /*
346 * Valid if differential input disabled
347 * if not true defaults to pos input
348 */
349 pdata->refa_cmos_neg_inp_en = 0;
350 pdata->refb_cmos_neg_inp_en = 0;
351 pdata->zd_in_cmos_neg_inp_en = 0;
352 pdata->osc_in_cmos_neg_inp_en = 0;
353
354 /* PLL1 Setting */
355 pdata->refa_r_div = 1;
356 pdata->refb_r_div = 1;
357 pdata->pll1_feedback_div = 1;
358 pdata->pll1_charge_pump_current_nA = 0;
359 pdata->zero_delay_mode_internal_en = 0;
360 pdata->osc_in_feedback_en = 0;
361 pdata->pll1_bypass_en = 1;
362 pdata->pll1_loop_filter_rzero = 1;
363
364 /* Reference */
365 pdata->ref_mode = 0;
366
367 /* PLL2 Setting */
368 pdata->pll2_charge_pump_current_nA = 0;
369 pdata->pll2_ndiv_a_cnt = 0;
370 pdata->pll2_ndiv_b_cnt = 4;
371 pdata->pll2_freq_doubler_en = 0;
372 pdata->pll2_r2_div = 0;
373 pdata->pll2_vco_diff_m1 = 0; /* 3..5 */
374 pdata->pll2_vco_diff_m2 = 0; /* 3..5 */
375
376 /* Loop Filter PLL2 */
377 pdata->rpole2 = 0;
378 pdata->rzero = 0;
379 pdata->cpole1 = 0;
380 pdata->rzero_bypass_en = 0;
381
382 /* Output Channel Configuration */
383 for (i=0; i < pdata->num_channels; i++) {
384 (&pdata->channels[i])->channel_num = 0;
385 (&pdata->channels[i])->divider_output_invert_en = 0;
386 (&pdata->channels[i])->sync_ignore_en = 0;
387 (&pdata->channels[i])->low_power_mode_en = 0;
388 (&pdata->channels[i])->use_alt_clock_src = 0;
389 (&pdata->channels[i])->output_dis = 0;
390 (&pdata->channels[i])->driver_mode = LVPECL_8mA;
391 (&pdata->channels[i])->divider_phase = 0;
392 (&pdata->channels[i])->channel_divider = 0;
393 }
394 return 0;
395 }
396
397
398 /***************************************************************************//**
399 * @brief Setup the AD9523 device.
400 *
401 * @return Returns 0 in case of success or negative error code.
402 *******************************************************************************/
403 int32_t ad9523_setup(spi_device *dev,
404 ad9523_platform_data *pdata)
405
406 {
407 struct ad9523_state *st = &ad9523_st;
408 ad9523_channel_spec *chan;
409 uint32_t active_mask = 0;
410 int32_t ret, i;
411 uint32_t reg_data;
412 uint32_t version_id;
413
414 ret = ad9523_spi_write(dev, AD9523_SERIAL_PORT_CONFIG,
415 AD9523_SER_CONF_SOFT_RESET |
416 (pdata->spi3wire ? 0 :
417 AD9523_SER_CONF_SDO_ACTIVE));
418 if (ret < 0)
419 return ret;
420 mdelay(1);
421
422 ret = ad9523_spi_write(dev, AD9523_READBACK_CTRL,
423 AD9523_READBACK_CTRL_READ_BUFFERED);
424 if (ret < 0)
425 return ret;
426
427 ret = ad9523_io_update(dev);
428 if (ret < 0)
429 return ret;
430
431 ret = ad9523_spi_read(dev, AD9523_EEPROM_CUSTOMER_VERSION_ID, &version_id);
432 if (ret < 0)
433 return ret;
434
435 ret = ad9523_spi_write(dev, AD9523_EEPROM_CUSTOMER_VERSION_ID, 0xAD95);
436 if (ret < 0)
437 return ret;
438
439 ret = ad9523_spi_read(dev, AD9523_EEPROM_CUSTOMER_VERSION_ID, &reg_data);
440 if (ret < 0)
441 return ret;
442
443 if (reg_data != 0xAD95) {
444 ad_printf("AD9523: SPI write-verify failed (0x%X)!\n\r", reg_data);
445 return -1;
446 }
447
448 ret = ad9523_spi_write(dev, AD9523_EEPROM_CUSTOMER_VERSION_ID, version_id);
449 if (ret < 0)
450 return ret;
451
452 /*
453 * PLL1 Setup
454 */
455 ret = ad9523_spi_write(dev, AD9523_PLL1_REF_A_DIVIDER,
456 pdata->refa_r_div);
457 if (ret < 0)
458 return ret;
459
460 ret = ad9523_spi_write(dev, AD9523_PLL1_REF_B_DIVIDER,
461 pdata->refb_r_div);
462 if (ret < 0)
463 return ret;
464
465 ret = ad9523_spi_write(dev, AD9523_PLL1_FEEDBACK_DIVIDER,
466 pdata->pll1_feedback_div);
467 if (ret < 0)
468 return ret;
469
470 ret = ad9523_spi_write(dev, AD9523_PLL1_CHARGE_PUMP_CTRL,
471 AD_IFE(pll1_bypass_en, AD9523_PLL1_CHARGE_PUMP_TRISTATE,
472 AD9523_PLL1_CHARGE_PUMP_CURRENT_nA(pdata->
473 pll1_charge_pump_current_nA) |
474 AD9523_PLL1_CHARGE_PUMP_MODE_NORMAL |
475 AD9523_PLL1_BACKLASH_PW_MIN));
476 if (ret < 0)
477 return ret;
478
479 ret = ad9523_spi_write(dev, AD9523_PLL1_INPUT_RECEIVERS_CTRL,
480 AD_IFE(pll1_bypass_en, AD9523_PLL1_REFA_REFB_PWR_CTRL_EN |
481 AD_IF(osc_in_diff_en, AD9523_PLL1_OSC_IN_DIFF_EN) |
482 AD_IF(osc_in_cmos_neg_inp_en, AD9523_PLL1_OSC_IN_CMOS_NEG_INP_EN),
483 AD_IF(refa_diff_rcv_en, AD9523_PLL1_REFA_RCV_EN) |
484 AD_IF(refb_diff_rcv_en, AD9523_PLL1_REFB_RCV_EN) |
485 AD_IF(osc_in_diff_en, AD9523_PLL1_OSC_IN_DIFF_EN) |
486 AD_IF(osc_in_cmos_neg_inp_en,
487 AD9523_PLL1_OSC_IN_CMOS_NEG_INP_EN) |
488 AD_IF(refa_diff_rcv_en, AD9523_PLL1_REFA_DIFF_RCV_EN) |
489 AD_IF(refb_diff_rcv_en, AD9523_PLL1_REFB_DIFF_RCV_EN)));
490 if (ret < 0)
491 return ret;
492
493 ret = ad9523_spi_write(dev, AD9523_PLL1_REF_CTRL,
494 AD_IFE(pll1_bypass_en, AD9523_PLL1_BYPASS_FEEDBACK_DIV_EN |
495 AD9523_PLL1_ZERO_DELAY_MODE_INT,
496 AD_IF(zd_in_diff_en, AD9523_PLL1_ZD_IN_DIFF_EN) |
497 AD_IF(zd_in_cmos_neg_inp_en,
498 AD9523_PLL1_ZD_IN_CMOS_NEG_INP_EN) |
499 AD_IF(zero_delay_mode_internal_en,
500 AD9523_PLL1_ZERO_DELAY_MODE_INT) |
501 AD_IF(osc_in_feedback_en, AD9523_PLL1_OSC_IN_PLL_FEEDBACK_EN) |
502 AD_IF(refa_cmos_neg_inp_en, AD9523_PLL1_REFA_CMOS_NEG_INP_EN) |
503 AD_IF(refb_cmos_neg_inp_en, AD9523_PLL1_REFB_CMOS_NEG_INP_EN)));
504 if (ret < 0)
505 return ret;
506
507 ret = ad9523_spi_write(dev, AD9523_PLL1_MISC_CTRL,
508 AD9523_PLL1_REFB_INDEP_DIV_CTRL_EN |
509 AD9523_PLL1_REF_MODE(pdata->ref_mode));
510 if (ret < 0)
511 return ret;
512
513 ret = ad9523_spi_write(dev, AD9523_PLL1_LOOP_FILTER_CTRL,
514 AD9523_PLL1_LOOP_FILTER_RZERO(pdata->pll1_loop_filter_rzero));
515 if (ret < 0)
516 return ret;
517
518 /*
519 * PLL2 Setup
520 */
521
522 ret = ad9523_spi_write(dev, AD9523_PLL2_CHARGE_PUMP,
523 AD9523_PLL2_CHARGE_PUMP_CURRENT_nA(pdata->
524 pll2_charge_pump_current_nA));
525 if (ret < 0)
526 return ret;
527
528 ret = ad9523_spi_write(dev, AD9523_PLL2_FEEDBACK_DIVIDER_AB,
529 AD9523_PLL2_FB_NDIV_A_CNT(pdata->pll2_ndiv_a_cnt) |
530 AD9523_PLL2_FB_NDIV_B_CNT(pdata->pll2_ndiv_b_cnt));
531 if (ret < 0)
532 return ret;
533
534 ret = ad9523_spi_write(dev, AD9523_PLL2_CTRL,
535 AD9523_PLL2_CHARGE_PUMP_MODE_NORMAL |
536 AD9523_PLL2_BACKLASH_CTRL_EN |
537 AD_IF(pll2_freq_doubler_en, AD9523_PLL2_FREQ_DOUBLER_EN));
538 if (ret < 0)
539 return ret;
540
541 st->vco_freq = (pdata->vcxo_freq * (pdata->pll2_freq_doubler_en ? 2 : 1)
542 / pdata->pll2_r2_div) * AD9523_PLL2_FB_NDIV(pdata->
543 pll2_ndiv_a_cnt, pdata->pll2_ndiv_b_cnt);
544
545 ret = ad9523_spi_write(dev, AD9523_PLL2_VCO_CTRL,
546 AD9523_PLL2_VCO_CALIBRATE);
547 if (ret < 0)
548 return ret;
549
550 ret = ad9523_spi_write(dev, AD9523_PLL2_VCO_DIVIDER,
551 AD9523_PLL2_VCO_DIV_M1(pdata->pll2_vco_diff_m1) |
552 AD9523_PLL2_VCO_DIV_M2(pdata->pll2_vco_diff_m2) |
553 AD_IFE(pll2_vco_diff_m1, 0,
554 AD9523_PLL2_VCO_DIV_M1_PWR_DOWN_EN) |
555 AD_IFE(pll2_vco_diff_m2, 0,
556 AD9523_PLL2_VCO_DIV_M2_PWR_DOWN_EN));
557 if (ret < 0)
558 return ret;
559
560 if (pdata->pll2_vco_diff_m1)
561 st->vco_out_freq[AD9523_VCO1] =
562 st->vco_freq / pdata->pll2_vco_diff_m1;
563
564 if (pdata->pll2_vco_diff_m2)
565 st->vco_out_freq[AD9523_VCO2] =
566 st->vco_freq / pdata->pll2_vco_diff_m2;
567
568 st->vco_out_freq[AD9523_VCXO] = pdata->vcxo_freq;
569
570 ret = ad9523_spi_write(dev, AD9523_PLL2_R2_DIVIDER,
571 AD9523_PLL2_R2_DIVIDER_VAL(pdata->pll2_r2_div));
572 if (ret < 0)
573 return ret;
574
575 ret = ad9523_spi_write(dev, AD9523_PLL2_LOOP_FILTER_CTRL,
576 AD9523_PLL2_LOOP_FILTER_CPOLE1(pdata->cpole1) |
577 AD9523_PLL2_LOOP_FILTER_RZERO(pdata->rzero) |
578 AD9523_PLL2_LOOP_FILTER_RPOLE2(pdata->rpole2) |
579 AD_IF(rzero_bypass_en,
580 AD9523_PLL2_LOOP_FILTER_RZERO_BYPASS_EN));
581 if (ret < 0)
582 return ret;
583
584 for (i = 0; i < pdata->num_channels; i++) {
585 chan = &pdata->channels[i];
586 if (chan->channel_num < AD9523_NUM_CHAN) {
587 active_mask |= (1 << chan->channel_num);
588 ret = ad9523_spi_write(dev,
589 AD9523_CHANNEL_CLOCK_DIST(chan->channel_num),
590 AD9523_CLK_DIST_DRIVER_MODE(chan->driver_mode) |
591 AD9523_CLK_DIST_DIV(chan->channel_divider) |
592 AD9523_CLK_DIST_DIV_PHASE(chan->divider_phase) |
593 (chan->sync_ignore_en ?
594 AD9523_CLK_DIST_IGNORE_SYNC_EN : 0) |
595 (chan->divider_output_invert_en ?
596 AD9523_CLK_DIST_INV_DIV_OUTPUT_EN : 0) |
597 (chan->low_power_mode_en ?
598 AD9523_CLK_DIST_LOW_PWR_MODE_EN : 0) |
599 (chan->output_dis ?
600 AD9523_CLK_DIST_PWR_DOWN_EN : 0));
601 if (ret < 0)
602 return ret;
603
604 ret = ad9523_vco_out_map(dev, chan->channel_num,
605 chan->use_alt_clock_src);
606 if (ret < 0)
607 return ret;
608 }
609 }
610
611 for(i = 0; i < AD9523_NUM_CHAN; i++)
612 {
613 if(!(active_mask & (1 << i)))
614 {
615 ad9523_spi_write(dev,
616 AD9523_CHANNEL_CLOCK_DIST(i),
617 AD9523_CLK_DIST_DRIVER_MODE(TRISTATE) |
618 AD9523_CLK_DIST_PWR_DOWN_EN);
619 }
620 }
621
622 ret = ad9523_spi_write(dev, AD9523_POWER_DOWN_CTRL, 0);
623 if (ret < 0)
624 return ret;
625
626 ret = ad9523_spi_write(dev, AD9523_STATUS_SIGNALS,
627 AD9523_STATUS_MONITOR_01_PLL12_LOCKED);
628 if (ret < 0)
629 return ret;
630
631 ret = ad9523_io_update(dev);
632 if (ret < 0)
633 return ret;
634
635 ret = ad9523_sync(dev);
636 if (ret < 0)
637 return ret;
638
639 ad9523_spi_write(dev, AD9523_READBACK_CTRL, 0x0);
640 ad9523_io_update(dev);
641 ad9523_calibrate(dev);
642 ad9523_sync(dev);
643
644 return(ad9523_status(dev, pdata));
645 }