Debian Codegraph @

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

raw symbols SCIP
1 /***************************************************************************//**
2 * @file ad7768.c
3 * @brief Implementation of AD7768 Driver.
4 * @author DBogdan ([email protected])
5 ********************************************************************************
6 * Copyright 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 /***************************** Include Files **********************************/
42 /******************************************************************************/
43 #include <stdio.h>
44 #include <stdlib.h>
45 #include "platform_drivers.h"
46 #include "ad7768.h"
47
48 const uint8_t standard_pin_ctrl_mode_sel[3][4] = {
49 // MCLK/1, MCLK/2, MCLK/4, MCLK/8
50 {0x0, 0x1, 0x2, 0x3}, // Eco
51 {0x4, 0x5, 0x6, 0x7}, // Median
52 {0x8, 0x9, 0xA, 0xB}, // Fast
53 };
54
55 const uint8_t one_shot_pin_ctrl_mode_sel[3][4] = {
56 // MCLK/1, MCLK/2, MCLK/4, MCLK/8
57 {0xC, 0xFF, 0xFF, 0xFF}, // Eco
58 {0xD, 0xFF, 0xFF, 0xFF}, // Median
59 {0xF, 0xE, 0xFF, 0xFF}, // Fast
60 };
61
62 /**
63 * SPI read from device.
64 * @param dev - The device structure.
65 * @param reg_addr - The register address.
66 * @param reg_data - The register data.
67 * @return 0 in case of success, negative error code otherwise.
68 */
69 int32_t ad7768_spi_read(ad7768_dev *dev,
70 uint8_t reg_addr,
71 uint8_t *reg_data)
72 {
73 uint8_t buf[2];
74 int32_t ret;
75
76 buf[0] = 0x80 | (reg_addr & 0x7F);
77 buf[1] = 0x00;
78 ret = spi_write_and_read(&dev->spi_dev, buf, 2);
79
80 buf[0] = 0x80 | (reg_addr & 0x7F);
81 buf[1] = 0x00;
82 ret = spi_write_and_read(&dev->spi_dev, buf, 2);
83 *reg_data = buf[1];
84
85 return ret;
86 }
87
88 /**
89 * SPI write to device.
90 * @param dev - The device structure.
91 * @param reg_addr - The register address.
92 * @param reg_data - The register data.
93 * @return 0 in case of success, negative error code otherwise.
94 */
95 int32_t ad7768_spi_write(ad7768_dev *dev,
96 uint8_t reg_addr,
97 uint8_t reg_data)
98 {
99 uint8_t buf[2];
100 int32_t ret;
101
102 buf[0] = (reg_addr & 0x7F);
103 buf[1] = reg_data;
104 ret = spi_write_and_read(&dev->spi_dev, buf, 2);
105
106 return ret;
107 }
108
109 /**
110 * SPI read from device using a mask.
111 * @param dev - The device structure.
112 * @param reg_addr - The register address.
113 * @param mask - The mask.
114 * @param data - The register data.
115 * @return 0 in case of success, negative error code otherwise.
116 */
117 int32_t ad7768_spi_read_mask(ad7768_dev *dev,
118 uint8_t reg_addr,
119 uint8_t mask,
120 uint8_t *data)
121 {
122 uint8_t reg_data;
123 int32_t ret;
124
125 ret = ad7768_spi_read(dev, reg_addr, &reg_data);
126 *data = (reg_data & mask);
127
128 return ret;
129 }
130
131 /**
132 * SPI write to device using a mask.
133 * @param dev - The device structure.
134 * @param reg_addr - The register address.
135 * @param mask - The mask.
136 * @param data - The register data.
137 * @return 0 in case of success, negative error code otherwise.
138 */
139 int32_t ad7768_spi_write_mask(ad7768_dev *dev,
140 uint8_t reg_addr,
141 uint8_t mask,
142 uint8_t data)
143 {
144 uint8_t reg_data;
145 int32_t ret;
146
147 ret = ad7768_spi_read(dev, reg_addr, &reg_data);
148 reg_data &= ~mask;
149 reg_data |= data;
150 ret |= ad7768_spi_write(dev, reg_addr, reg_data);
151
152 return ret;
153 }
154
155 /**
156 * Set the device sleep mode.
157 * @param dev - The device structure.
158 * @param mode - The device sleep mode.
159 * Accepted values: AD7768_ACTIVE
160 * AD7768_SLEEP
161 * @return 0 in case of success, negative error code otherwise.
162 */
163 int32_t ad7768_set_sleep_mode(ad7768_dev *dev,
164 ad7768_sleep_mode mode)
165 {
166 ad7768_spi_write_mask(dev,
167 AD7768_REG_PWR_MODE,
168 AD7768_PWR_MODE_SLEEP_MODE,
169 (mode ? AD7768_PWR_MODE_SLEEP_MODE : 0));
170 dev->sleep_mode = mode;
171
172 return 0;
173 }
174
175 /**
176 * Get the device sleep mode.
177 * @param dev - The device structure.
178 * @param mode - The device sleep mode.
179 * @return 0 in case of success, negative error code otherwise.
180 */
181 int32_t ad7768_get_sleep_mode(ad7768_dev *dev,
182 ad7768_sleep_mode *mode)
183 {
184 *mode = dev->sleep_mode;
185
186 return 0;
187 }
188
189 /**
190 * Internal set MODEx pins function.
191 * @param dev - The device structure.
192 * @param state - The state of the MODEx pins.
193 * @return 0 in case of success, negative error code otherwise.
194 */
195 int32_t ad7768_set_mode_pins(ad7768_dev *dev,
196 uint8_t state)
197 {
198 int32_t ret;
199
200 if ((dev->gpio_mode0 >= 0) && (dev->gpio_mode1 >= 0) &&
201 (dev->gpio_mode2 >= 0) && (dev->gpio_mode3 >= 0)) {
202 ret = gpio_set_value(&dev->gpio_dev,
203 dev->gpio_mode0,
204 ((state & 0x01) >> 0));
205 ret |= gpio_set_value(&dev->gpio_dev,
206 dev->gpio_mode1,
207 ((state & 0x02) >> 1));
208 ret |= gpio_set_value(&dev->gpio_dev,
209 dev->gpio_mode2,
210 ((state & 0x04) >> 2));
211 ret |= gpio_set_value(&dev->gpio_dev,
212 dev->gpio_mode3,
213 ((state & 0x08) >> 3));
214 } else {
215 printf ("MODE GPIOs are not defined.");
216 ret = -1;
217 }
218
219 return ret;
220 }
221
222 /**
223 * Set the device power mode.
224 * @param dev - The device structure.
225 * @param mode - The device power mode.
226 * Accepted values: AD7768_ECO
227 * AD7768_MEDIAN
228 * AD7768_FAST
229 * @return 0 in case of success, negative error code otherwise.
230 */
231 int32_t ad7768_set_power_mode(ad7768_dev *dev,
232 ad7768_power_mode mode)
233 {
234 uint8_t mode_pins_state;
235
236 if (dev->pin_spi_ctrl == AD7768_SPI_CTRL) {
237 ad7768_spi_write_mask(dev,
238 AD7768_REG_PWR_MODE,
239 AD7768_PWR_MODE_POWER_MODE(0x3),
240 AD7768_PWR_MODE_POWER_MODE(mode));
241 dev->power_mode = mode;
242 } else {
243 if (dev->conv_op == AD7768_STANDARD_CONV)
244 mode_pins_state =
245 standard_pin_ctrl_mode_sel[mode][dev->dclk_div];
246 else
247 mode_pins_state =
248 one_shot_pin_ctrl_mode_sel[mode][dev->dclk_div];
249 if (mode_pins_state != 0xFF) {
250 dev->power_mode = mode;
251 ad7768_set_mode_pins(dev, mode_pins_state);
252 }
253 else {
254 printf("Invalid Power Mode for the current configuration.");
255
256 return -1;
257 }
258 }
259
260 return 0;
261 }
262
263 /**
264 * Get the device power mode.
265 * @param dev - The device structure.
266 * @param mode - The device power mode.
267 * @return 0 in case of success, negative error code otherwise.
268 */
269 int32_t ad7768_get_power_mode(ad7768_dev *dev,
270 ad7768_power_mode *mode)
271 {
272 *mode = dev->power_mode;
273
274 return 0;
275 }
276
277 /**
278 * Set the MCLK divider.
279 * @param dev - The device structure.
280 * @param clk_div - The MCLK divider.
281 * Accepted values: AD7768_MCLK_DIV_32
282 * AD7768_MCLK_DIV_8
283 * AD7768_MCLK_DIV_4
284 * @return 0 in case of success, negative error code otherwise.
285 */
286 int32_t ad7768_set_mclk_div(ad7768_dev *dev,
287 ad7768_mclk_div clk_div)
288 {
289 ad7768_spi_write_mask(dev,
290 AD7768_REG_PWR_MODE,
291 AD7768_PWR_MODE_MCLK_DIV(0x3),
292 AD7768_PWR_MODE_MCLK_DIV(clk_div));
293 dev->mclk_div = clk_div;
294
295 return 0;
296 }
297
298 /**
299 * Get the MCLK divider.
300 * @param dev - The device structure.
301 * @param mode - The MCLK divider.
302 * @return 0 in case of success, negative error code otherwise.
303 */
304 int32_t ad7768_get_mclk_div(ad7768_dev *dev,
305 ad7768_mclk_div *clk_div)
306 {
307 *clk_div = dev->mclk_div;
308
309 return 0;
310 }
311
312 /**
313 * Set the DCLK divider.
314 * @param dev - The device structure.
315 * @param clk_div - The DCLK divider.
316 * Accepted values: AD7768_DCLK_DIV_1
317 * AD7768_DCLK_DIV_2
318 * AD7768_DCLK_DIV_4
319 * AD7768_DCLK_DIV_8
320 * @return 0 in case of success, negative error code otherwise.
321 */
322 int32_t ad7768_set_dclk_div(ad7768_dev *dev,
323 ad7768_dclk_div clk_div)
324 {
325 uint8_t mode_pins_state;
326
327 if (dev->pin_spi_ctrl == AD7768_SPI_CTRL) {
328 ad7768_spi_write_mask(dev,
329 AD7768_REG_INTERFACE_CFG,
330 AD7768_INTERFACE_CFG_DCLK_DIV(0x3),
331 AD7768_INTERFACE_CFG_DCLK_DIV(clk_div));
332 dev->dclk_div = clk_div;
333 } else {
334 if (dev->conv_op == AD7768_STANDARD_CONV)
335 mode_pins_state =
336 standard_pin_ctrl_mode_sel[dev->power_mode][clk_div];
337 else
338 mode_pins_state =
339 one_shot_pin_ctrl_mode_sel[dev->power_mode][clk_div];
340 if (mode_pins_state != 0xFF) {
341 dev->dclk_div = clk_div;
342 ad7768_set_mode_pins(dev, mode_pins_state);
343 }
344 else {
345 printf("Invalid DCLK_DIV for the current configuration.");
346
347 return -1;
348 }
349 }
350
351 return 0;
352 }
353
354 /**
355 * Get the DCLK divider.
356 * @param dev - The device structure.
357 * @param clk_div - The DCLK divider.
358 * @return 0 in case of success, negative error code otherwise.
359 */
360 int32_t ad7768_get_dclk_div(ad7768_dev *dev,
361 ad7768_dclk_div *clk_div)
362 {
363 *clk_div = dev->dclk_div;
364
365 return 0;
366 }
367
368
369 /**
370 * Set the conversion operation mode.
371 * @param dev - The device structure.
372 * @param conv_op - The conversion operation mode.
373 * Accepted values: AD7768_STANDARD_CONV
374 * AD7768_ONE_SHOT_CONV
375 * @return 0 in case of success, negative error code otherwise.
376 */
377 int32_t ad7768_set_conv_op(ad7768_dev *dev,
378 ad7768_conv_op conv_op)
379 {
380 uint8_t mode_pins_state;
381
382 if (dev->pin_spi_ctrl == AD7768_SPI_CTRL) {
383 ad7768_spi_write_mask(dev,
384 AD7768_REG_DATA_CTRL,
385 AD7768_DATA_CTRL_SINGLE_SHOT_EN,
386 conv_op ? AD7768_DATA_CTRL_SINGLE_SHOT_EN : 0);
387 dev->conv_op = conv_op;
388 } else {
389 if (conv_op == AD7768_STANDARD_CONV)
390 mode_pins_state =
391 standard_pin_ctrl_mode_sel[dev->power_mode][dev->dclk_div];
392 else
393 mode_pins_state =
394 one_shot_pin_ctrl_mode_sel[dev->power_mode][dev->dclk_div];
395 if (mode_pins_state != 0xFF) {
396 dev->conv_op = conv_op;
397 ad7768_set_mode_pins(dev, mode_pins_state);
398 }
399 else {
400 printf("Invalid Conversion Operation for the current configuration.");
401
402 return -1;
403 }
404 }
405
406 return 0;
407 }
408
409 /**
410 * Get the conversion operation mode.
411 * @param dev - The device structure.
412 * @param conv_op - The conversion operation mode.
413 * @return 0 in case of success, negative error code otherwise.
414 */
415 int32_t ad7768_get_conv_op(ad7768_dev *dev,
416 ad7768_conv_op *conv_op)
417 {
418 *conv_op = dev->conv_op;
419
420 return 0;
421 }
422
423 /**
424 * Set the CRC selection.
425 * @param dev - The device structure.
426 * @param crc_sel - The CRC selection.
427 * Accepted values: AD7768_NO_CRC
428 * AD7768_CRC_4
429 * AD7768_CRC_16
430 * @return 0 in case of success, negative error code otherwise.
431 */
432 int32_t ad7768_set_crc_sel(ad7768_dev *dev,
433 ad7768_crc_sel crc_sel)
434 {
435 ad7768_spi_write_mask(dev,
436 AD7768_REG_INTERFACE_CFG,
437 AD7768_INTERFACE_CFG_CRC_SEL(0x3),
438 AD7768_INTERFACE_CFG_CRC_SEL(crc_sel));
439 dev->crc_sel = crc_sel;
440
441 return 0;
442 }
443
444 /**
445 * Get the CRC selection.
446 * @param dev - The device structure.
447 * @param crc_sel - The CRC selection.
448 * @return 0 in case of success, negative error code otherwise.
449 */
450 int32_t ad7768_get_crc_sel(ad7768_dev *dev,
451 ad7768_crc_sel *crc_sel)
452 {
453 *crc_sel = dev->crc_sel;
454
455 return 0;
456 }
457
458 /**
459 * Set the channel state.
460 * @param dev - The device structure.
461 * @param ch - The channel number.
462 * Accepted values: AD7768_CH0
463 * AD7768_CH1
464 * AD7768_CH2
465 * AD7768_CH3
466 * AD7768_CH4
467 * AD7768_CH5
468 * AD7768_CH6
469 * AD7768_CH7
470 * @param state - The channel state.
471 * Accepted values: AD7768_ENABLED
472 * AD7768_STANDBY
473 * @return 0 in case of success, negative error code otherwise.
474 */
475 int32_t ad7768_set_ch_state(ad7768_dev *dev,
476 ad7768_ch ch,
477 ad7768_ch_state state)
478 {
479 ad7768_spi_write_mask(dev,
480 AD7768_REG_CH_STANDBY,
481 AD7768_CH_STANDBY(ch),
482 state ? AD7768_CH_STANDBY(ch) : 0);
483 dev->ch_state[ch] = state;
484
485 return 0;
486 }
487
488 /**
489 * Get the channel state.
490 * @param dev - The device structure.
491 * @param ch - The channel number.
492 * Accepted values: AD7768_CH0
493 * AD7768_CH1
494 * AD7768_CH2
495 * AD7768_CH3
496 * AD7768_CH4
497 * AD7768_CH5
498 * AD7768_CH6
499 * AD7768_CH7
500 * @param state - The channel state.
501 * @return 0 in case of success, negative error code otherwise.
502 */
503 int32_t ad7768_get_ch_state(ad7768_dev *dev,
504 ad7768_ch ch,
505 ad7768_ch_state *state)
506 {
507 *state = dev->ch_state[ch];
508
509 return 0;
510 }
511
512 /**
513 * Set the mode configuration.
514 * @param dev - The device structure.
515 * @param mode - The channel mode.
516 * Accepted values: AD7768_MODE_A
517 * AD7768_MODE_B
518 * @param filt_type - The filter type.
519 * Accepted values: AD7768_FILTER_WIDEBAND
520 * AD7768_FILTER_SINC,
521 * @param dec_rate - The decimation rate.
522 * Accepted values: AD7768_DEC_X32
523 * AD7768_DEC_X64
524 * AD7768_DEC_X128
525 * AD7768_DEC_X256
526 * AD7768_DEC_X512
527 * AD7768_DEC_X1024
528 * @return 0 in case of success, negative error code otherwise.
529 */
530 int32_t ad7768_set_mode_config(ad7768_dev *dev,
531 ad7768_ch_mode mode,
532 ad7768_filt_type filt_type,
533 ad7768_dec_rate dec_rate)
534 {
535 uint8_t reg_val;
536
537 reg_val = ((filt_type == AD7768_FILTER_SINC) ? AD7768_CH_MODE_FILTER_TYPE : 0) |
538 AD7768_CH_MODE_DEC_RATE(dec_rate);
539 if (mode == AD7768_MODE_A) {
540 ad7768_spi_write(dev, AD7768_REG_CH_MODE_A, reg_val);
541 } else {
542 ad7768_spi_write(dev, AD7768_REG_CH_MODE_B, reg_val);
543 }
544 dev->filt_type[mode] = filt_type;
545 dev->dec_rate[mode] = dec_rate;
546
547 return 0;
548 }
549
550 /**
551 * Get the mode configuration.
552 * @param dev - The device structure.
553 * @param mode - The channel mode.
554 * @param filt_type - The filter type.
555 * @param dec_rate - The decimation rate.
556 * @return 0 in case of success, negative error code otherwise.
557 */
558 int32_t ad7768_get_mode_config(ad7768_dev *dev,
559 ad7768_ch_mode mode,
560 ad7768_filt_type *filt_type,
561 ad7768_dec_rate *dec_rate)
562 {
563 *filt_type = dev->filt_type[mode];
564 *dec_rate = dev->dec_rate[mode];
565
566 return 0;
567 }
568
569 /**
570 * Set the channel mode.
571 * @param dev - The device structure.
572 * @param ch - The channel number.
573 * Accepted values: AD7768_CH0
574 * AD7768_CH1
575 * AD7768_CH2
576 * AD7768_CH3
577 * AD7768_CH4
578 * AD7768_CH5
579 * AD7768_CH6
580 * AD7768_CH7
581 * @param mode - The channel mode.
582 * Accepted values: AD7768_MODE_A
583 * AD7768_MODE_B
584 * @return 0 in case of success, negative error code otherwise.
585 */
586 int32_t ad7768_set_ch_mode(ad7768_dev *dev,
587 ad7768_ch ch,
588 ad7768_ch_mode mode)
589 {
590 ad7768_spi_write_mask(dev,
591 AD7768_REG_CH_MODE_SEL,
592 AD7768_CH_MODE(ch),
593 mode ? AD7768_CH_MODE(ch) : 0);
594 dev->ch_mode[ch] = mode;
595
596 return 0;
597 }
598
599 /**
600 * Get the channel mode.
601 * @param dev - The device structure.
602 * @param ch - The channel number.
603 * Accepted values: AD7768_CH0
604 * AD7768_CH1
605 * AD7768_CH2
606 * AD7768_CH3
607 * AD7768_CH4
608 * AD7768_CH5
609 * AD7768_CH6
610 * AD7768_CH7
611 * @param mode - The channel mode.
612 * @return 0 in case of success, negative error code otherwise.
613 */
614 int32_t ad7768_get_ch_mode(ad7768_dev *dev,
615 ad7768_ch ch,
616 ad7768_ch_mode *mode)
617 {
618 *mode = dev->ch_mode[ch];
619
620 return 0;
621 }
622
623 /**
624 * Initialize the device.
625 * @param device - The device structure.
626 * @param init_param - The structure that contains the device initial
627 * parameters.
628 * @return 0 in case of success, negative error code otherwise.
629 */
630 int32_t ad7768_setup(ad7768_dev **device,
631 ad7768_init_param init_param)
632 {
633 ad7768_dev *dev;
634 int32_t ret;
635
636 dev = (ad7768_dev *)malloc(sizeof(*dev));
637 if (!dev) {
638 return -1;
639 }
640
641 dev->spi_dev.chip_select = init_param.spi_chip_select;
642 dev->spi_dev.mode = init_param.spi_mode;
643 dev->spi_dev.device_id = init_param.spi_device_id;
644 dev->spi_dev.type = init_param.spi_type;
645 ret = spi_init(&dev->spi_dev);
646
647 dev->gpio_dev.device_id = init_param.gpio_device_id;
648 dev->gpio_dev.type = init_param.gpio_type;
649 ret |= gpio_init(&dev->gpio_dev);
650
651 dev->pin_spi_input_value = init_param.pin_spi_input_value;
652
653 dev->pin_spi_ctrl = dev->pin_spi_input_value ?
654 AD7768_SPI_CTRL : AD7768_PIN_CTRL;
655
656 dev->gpio_reset = init_param.gpio_reset;
657 dev->gpio_reset_value = init_param.gpio_reset_value;
658
659 dev->gpio_mode0 = init_param.gpio_mode0;
660 dev->gpio_mode1 = init_param.gpio_mode1;
661 dev->gpio_mode2 = init_param.gpio_mode2;
662 dev->gpio_mode3 = init_param.gpio_mode3;
663
664 if (dev->gpio_reset >= 0) {
665 ret |= gpio_set_direction(&dev->gpio_dev,
666 dev->gpio_reset, GPIO_OUT);
667 ret |= gpio_set_value(&dev->gpio_dev,
668 dev->gpio_reset,
669 dev->gpio_reset_value);
670 }
671
672 if (dev->gpio_mode0 >= 0) {
673 ret |= gpio_set_direction(&dev->gpio_dev,
674 dev->gpio_mode0, GPIO_OUT);
675 }
676 if (dev->gpio_mode1 >= 0) {
677 ret |= gpio_set_direction(&dev->gpio_dev,
678 dev->gpio_mode1, GPIO_OUT);
679 }
680 if (dev->gpio_mode2 >= 0) {
681 ret |= gpio_set_direction(&dev->gpio_dev,
682 dev->gpio_mode2, GPIO_OUT);
683 }
684 if (dev->gpio_mode3 >= 0) {
685 ret |= gpio_set_direction(&dev->gpio_dev,
686 dev->gpio_mode3, GPIO_OUT);
687 }
688
689 dev->sleep_mode = init_param.sleep_mode;
690 dev->mclk_div = init_param.mclk_div;
691 dev->crc_sel = init_param.crc_sel;
692 if (dev->pin_spi_ctrl == AD7768_SPI_CTRL) {
693 ad7768_set_sleep_mode(dev, dev->sleep_mode);
694 ad7768_set_mclk_div(dev, dev->mclk_div);
695 ad7768_set_crc_sel(dev, dev->crc_sel);
696 }
697
698 dev->power_mode = init_param.power_mode;
699 dev->dclk_div = init_param.dclk_div;
700 dev->conv_op = init_param.conv_op;
701 ad7768_set_power_mode(dev, dev->power_mode);
702 ad7768_set_dclk_div(dev, dev->dclk_div);
703 ad7768_set_conv_op(dev, dev->conv_op);
704
705 *device = dev;
706
707 if (!ret)
708 printf("AD7768 successfully initialized\n");
709
710 return ret;
711 }