Library files for AD5592R

Dependents:   EVAL-AD5592R

Committer:
EndaKilgarriff
Date:
Mon Jun 15 13:58:03 2020 +0000
Revision:
1:2ad195e1455b
AD5592R Initial Commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
EndaKilgarriff 1:2ad195e1455b 1 /***************************************************************************//**
EndaKilgarriff 1:2ad195e1455b 2 * @file ad5593r.c
EndaKilgarriff 1:2ad195e1455b 3 * @brief Implementation of AD5593R driver.
EndaKilgarriff 1:2ad195e1455b 4 * @author Mircea Caprioru (mircea.caprioru@analog.com)
EndaKilgarriff 1:2ad195e1455b 5 ********************************************************************************
EndaKilgarriff 1:2ad195e1455b 6 * Copyright 2018, 2020(c) Analog Devices, Inc.
EndaKilgarriff 1:2ad195e1455b 7 *
EndaKilgarriff 1:2ad195e1455b 8 * All rights reserved.
EndaKilgarriff 1:2ad195e1455b 9 *
EndaKilgarriff 1:2ad195e1455b 10 * Redistribution and use in source and binary forms, with or without
EndaKilgarriff 1:2ad195e1455b 11 * modification, are permitted provided that the following conditions are met:
EndaKilgarriff 1:2ad195e1455b 12 * - Redistributions of source code must retain the above copyright
EndaKilgarriff 1:2ad195e1455b 13 * notice, this list of conditions and the following disclaimer.
EndaKilgarriff 1:2ad195e1455b 14 * - Redistributions in binary form must reproduce the above copyright
EndaKilgarriff 1:2ad195e1455b 15 * notice, this list of conditions and the following disclaimer in
EndaKilgarriff 1:2ad195e1455b 16 * the documentation and/or other materials provided with the
EndaKilgarriff 1:2ad195e1455b 17 * distribution.
EndaKilgarriff 1:2ad195e1455b 18 * - Neither the name of Analog Devices, Inc. nor the names of its
EndaKilgarriff 1:2ad195e1455b 19 * contributors may be used to endorse or promote products derived
EndaKilgarriff 1:2ad195e1455b 20 * from this software without specific prior written permission.
EndaKilgarriff 1:2ad195e1455b 21 * - The use of this software may or may not infringe the patent rights
EndaKilgarriff 1:2ad195e1455b 22 * of one or more patent holders. This license does not release you
EndaKilgarriff 1:2ad195e1455b 23 * from the requirement that you obtain separate licenses from these
EndaKilgarriff 1:2ad195e1455b 24 * patent holders to use this software.
EndaKilgarriff 1:2ad195e1455b 25 * - Use of the software either in source or binary form, must be run
EndaKilgarriff 1:2ad195e1455b 26 * on or directly connected to an Analog Devices Inc. component.
EndaKilgarriff 1:2ad195e1455b 27 *
EndaKilgarriff 1:2ad195e1455b 28 * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
EndaKilgarriff 1:2ad195e1455b 29 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
EndaKilgarriff 1:2ad195e1455b 30 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
EndaKilgarriff 1:2ad195e1455b 31 * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
EndaKilgarriff 1:2ad195e1455b 32 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
EndaKilgarriff 1:2ad195e1455b 33 * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
EndaKilgarriff 1:2ad195e1455b 34 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
EndaKilgarriff 1:2ad195e1455b 35 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
EndaKilgarriff 1:2ad195e1455b 36 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
EndaKilgarriff 1:2ad195e1455b 37 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
EndaKilgarriff 1:2ad195e1455b 38 *******************************************************************************/
EndaKilgarriff 1:2ad195e1455b 39
EndaKilgarriff 1:2ad195e1455b 40 #include "ad5592r-base.h"
EndaKilgarriff 1:2ad195e1455b 41 #include "error.h"
EndaKilgarriff 1:2ad195e1455b 42 #include "ad5593r.h"
EndaKilgarriff 1:2ad195e1455b 43
EndaKilgarriff 1:2ad195e1455b 44 #define AD5593R_MODE_CONF (0 << 4)
EndaKilgarriff 1:2ad195e1455b 45 #define AD5593R_MODE_DAC_WRITE (1 << 4)
EndaKilgarriff 1:2ad195e1455b 46 #define AD5593R_MODE_ADC_READBACK (4 << 4)
EndaKilgarriff 1:2ad195e1455b 47 #define AD5593R_MODE_DAC_READBACK (5 << 4)
EndaKilgarriff 1:2ad195e1455b 48 #define AD5593R_MODE_GPIO_READBACK (6 << 4)
EndaKilgarriff 1:2ad195e1455b 49 #define AD5593R_MODE_REG_READBACK (7 << 4)
EndaKilgarriff 1:2ad195e1455b 50
EndaKilgarriff 1:2ad195e1455b 51 #define STOP_BIT 1
EndaKilgarriff 1:2ad195e1455b 52 #define RESTART_BIT 0
EndaKilgarriff 1:2ad195e1455b 53 #define AD5593R_ADC_VALUES_BUFF_SIZE 18
EndaKilgarriff 1:2ad195e1455b 54
EndaKilgarriff 1:2ad195e1455b 55 const struct ad5592r_rw_ops ad5593r_rw_ops = {
EndaKilgarriff 1:2ad195e1455b 56 .write_dac = ad5593r_write_dac,
EndaKilgarriff 1:2ad195e1455b 57 .read_adc = ad5593r_read_adc,
EndaKilgarriff 1:2ad195e1455b 58 .multi_read_adc= ad5593r_multi_read_adc,
EndaKilgarriff 1:2ad195e1455b 59 .reg_write = ad5593r_reg_write,
EndaKilgarriff 1:2ad195e1455b 60 .reg_read = ad5593r_reg_read,
EndaKilgarriff 1:2ad195e1455b 61 .gpio_read = ad5593r_gpio_read,
EndaKilgarriff 1:2ad195e1455b 62 };
EndaKilgarriff 1:2ad195e1455b 63
EndaKilgarriff 1:2ad195e1455b 64 /**
EndaKilgarriff 1:2ad195e1455b 65 * Write DAC channel.
EndaKilgarriff 1:2ad195e1455b 66 *
EndaKilgarriff 1:2ad195e1455b 67 * @param dev - The device structure.
EndaKilgarriff 1:2ad195e1455b 68 * @param chan - The channel number.
EndaKilgarriff 1:2ad195e1455b 69 * @param value - DAC value
EndaKilgarriff 1:2ad195e1455b 70 * @return 0 in case of success, negative error code otherwise
EndaKilgarriff 1:2ad195e1455b 71 */
EndaKilgarriff 1:2ad195e1455b 72 int32_t ad5593r_write_dac(struct ad5592r_dev *dev, uint8_t chan,
EndaKilgarriff 1:2ad195e1455b 73 uint16_t value)
EndaKilgarriff 1:2ad195e1455b 74 {
EndaKilgarriff 1:2ad195e1455b 75 uint8_t data[3];
EndaKilgarriff 1:2ad195e1455b 76
EndaKilgarriff 1:2ad195e1455b 77 if (!dev)
EndaKilgarriff 1:2ad195e1455b 78 return FAILURE;
EndaKilgarriff 1:2ad195e1455b 79
EndaKilgarriff 1:2ad195e1455b 80 data[0] = AD5593R_MODE_DAC_WRITE | chan;
EndaKilgarriff 1:2ad195e1455b 81 data[1] = (value >> 8) & 0xF ;
EndaKilgarriff 1:2ad195e1455b 82 data[2] = value & 0xFF;
EndaKilgarriff 1:2ad195e1455b 83
EndaKilgarriff 1:2ad195e1455b 84 return i2c_write(dev->i2c, data, sizeof(data), STOP_BIT);
EndaKilgarriff 1:2ad195e1455b 85 }
EndaKilgarriff 1:2ad195e1455b 86
EndaKilgarriff 1:2ad195e1455b 87 /**
EndaKilgarriff 1:2ad195e1455b 88 * Read ADC channel.
EndaKilgarriff 1:2ad195e1455b 89 *
EndaKilgarriff 1:2ad195e1455b 90 * @param dev - The device structure.
EndaKilgarriff 1:2ad195e1455b 91 * @param chan - The channel number.
EndaKilgarriff 1:2ad195e1455b 92 * @param value - ADC value
EndaKilgarriff 1:2ad195e1455b 93 * @return 0 in case of success, negative error code otherwise
EndaKilgarriff 1:2ad195e1455b 94 */
EndaKilgarriff 1:2ad195e1455b 95 int32_t ad5593r_read_adc(struct ad5592r_dev *dev, uint8_t chan,
EndaKilgarriff 1:2ad195e1455b 96 uint16_t *value)
EndaKilgarriff 1:2ad195e1455b 97 {
EndaKilgarriff 1:2ad195e1455b 98 int32_t ret;
EndaKilgarriff 1:2ad195e1455b 99 uint8_t data[3];
EndaKilgarriff 1:2ad195e1455b 100 uint16_t temp;
EndaKilgarriff 1:2ad195e1455b 101
EndaKilgarriff 1:2ad195e1455b 102 if (!dev)
EndaKilgarriff 1:2ad195e1455b 103 return FAILURE;
EndaKilgarriff 1:2ad195e1455b 104
EndaKilgarriff 1:2ad195e1455b 105 temp = BIT(chan);
EndaKilgarriff 1:2ad195e1455b 106
EndaKilgarriff 1:2ad195e1455b 107 data[0] = AD5593R_MODE_CONF | AD5592R_REG_ADC_SEQ;
EndaKilgarriff 1:2ad195e1455b 108 data[1] = temp >> 8;
EndaKilgarriff 1:2ad195e1455b 109 data[2] = temp & 0xFF;
EndaKilgarriff 1:2ad195e1455b 110
EndaKilgarriff 1:2ad195e1455b 111 ret = i2c_write(dev->i2c, data, sizeof(data), STOP_BIT);
EndaKilgarriff 1:2ad195e1455b 112 if (ret < 0)
EndaKilgarriff 1:2ad195e1455b 113 return ret;
EndaKilgarriff 1:2ad195e1455b 114
EndaKilgarriff 1:2ad195e1455b 115 data[0] = AD5593R_MODE_ADC_READBACK;
EndaKilgarriff 1:2ad195e1455b 116 ret = i2c_write(dev->i2c, data, 1, STOP_BIT);
EndaKilgarriff 1:2ad195e1455b 117 if (ret < 0)
EndaKilgarriff 1:2ad195e1455b 118 return ret;
EndaKilgarriff 1:2ad195e1455b 119
EndaKilgarriff 1:2ad195e1455b 120 ret = i2c_read(dev->i2c, data, 2, STOP_BIT);
EndaKilgarriff 1:2ad195e1455b 121 if (ret < 0)
EndaKilgarriff 1:2ad195e1455b 122 return ret;
EndaKilgarriff 1:2ad195e1455b 123
EndaKilgarriff 1:2ad195e1455b 124 *value = (uint16_t)((data[0] & 0x0F) << 8) + data[1];
EndaKilgarriff 1:2ad195e1455b 125
EndaKilgarriff 1:2ad195e1455b 126 return 0;
EndaKilgarriff 1:2ad195e1455b 127 }
EndaKilgarriff 1:2ad195e1455b 128
EndaKilgarriff 1:2ad195e1455b 129 /**
EndaKilgarriff 1:2ad195e1455b 130 * Read Multiple ADC Channels.
EndaKilgarriff 1:2ad195e1455b 131 *
EndaKilgarriff 1:2ad195e1455b 132 * @param dev - The device structure.
EndaKilgarriff 1:2ad195e1455b 133 * @param chans - The ADC channels to be readback
EndaKilgarriff 1:2ad195e1455b 134 * @param values - ADC value array
EndaKilgarriff 1:2ad195e1455b 135 * @return 0 in case of success, negative error code otherwise
EndaKilgarriff 1:2ad195e1455b 136 */
EndaKilgarriff 1:2ad195e1455b 137 int32_t ad5593r_multi_read_adc(struct ad5592r_dev *dev, uint16_t chans,
EndaKilgarriff 1:2ad195e1455b 138 uint16_t *values)
EndaKilgarriff 1:2ad195e1455b 139 {
EndaKilgarriff 1:2ad195e1455b 140 uint8_t data[AD5593R_ADC_VALUES_BUFF_SIZE], i;
EndaKilgarriff 1:2ad195e1455b 141 int32_t ret;
EndaKilgarriff 1:2ad195e1455b 142 uint8_t samples;
EndaKilgarriff 1:2ad195e1455b 143
EndaKilgarriff 1:2ad195e1455b 144 if (!dev)
EndaKilgarriff 1:2ad195e1455b 145 return FAILURE;
EndaKilgarriff 1:2ad195e1455b 146
EndaKilgarriff 1:2ad195e1455b 147 samples = hweight8(chans);
EndaKilgarriff 1:2ad195e1455b 148
EndaKilgarriff 1:2ad195e1455b 149 data[0] = AD5593R_MODE_CONF | AD5592R_REG_ADC_SEQ;
EndaKilgarriff 1:2ad195e1455b 150 data[1] = chans >> 8;
EndaKilgarriff 1:2ad195e1455b 151 data[2] = chans & 0xFF;
EndaKilgarriff 1:2ad195e1455b 152
EndaKilgarriff 1:2ad195e1455b 153 ret = i2c_write(dev->i2c, data, 3, STOP_BIT);
EndaKilgarriff 1:2ad195e1455b 154 if (ret < 0)
EndaKilgarriff 1:2ad195e1455b 155 return ret;
EndaKilgarriff 1:2ad195e1455b 156
EndaKilgarriff 1:2ad195e1455b 157 data[0] = AD5593R_MODE_ADC_READBACK;
EndaKilgarriff 1:2ad195e1455b 158 ret = i2c_write(dev->i2c, data, 1, RESTART_BIT);
EndaKilgarriff 1:2ad195e1455b 159 if (ret < 0)
EndaKilgarriff 1:2ad195e1455b 160 return ret;
EndaKilgarriff 1:2ad195e1455b 161
EndaKilgarriff 1:2ad195e1455b 162 ret = i2c_read(dev->i2c, data, (2 * samples), STOP_BIT);
EndaKilgarriff 1:2ad195e1455b 163 if (ret < 0)
EndaKilgarriff 1:2ad195e1455b 164 return ret;
EndaKilgarriff 1:2ad195e1455b 165
EndaKilgarriff 1:2ad195e1455b 166 for (i = 0; i < samples; i++) {
EndaKilgarriff 1:2ad195e1455b 167 values[i] = ((uint16_t)(((data[2 * i] & 0xFF) << 8) + data[(2 * i) + 1]));
EndaKilgarriff 1:2ad195e1455b 168 }
EndaKilgarriff 1:2ad195e1455b 169
EndaKilgarriff 1:2ad195e1455b 170 return 0;
EndaKilgarriff 1:2ad195e1455b 171 }
EndaKilgarriff 1:2ad195e1455b 172
EndaKilgarriff 1:2ad195e1455b 173 /**
EndaKilgarriff 1:2ad195e1455b 174 * Write register.
EndaKilgarriff 1:2ad195e1455b 175 *
EndaKilgarriff 1:2ad195e1455b 176 * @param dev - The device structure.
EndaKilgarriff 1:2ad195e1455b 177 * @param reg - The register address.
EndaKilgarriff 1:2ad195e1455b 178 * @param value - register value
EndaKilgarriff 1:2ad195e1455b 179 * @return 0 in case of success, negative error code otherwise
EndaKilgarriff 1:2ad195e1455b 180 */
EndaKilgarriff 1:2ad195e1455b 181 int32_t ad5593r_reg_write(struct ad5592r_dev *dev, uint8_t reg,
EndaKilgarriff 1:2ad195e1455b 182 uint16_t value)
EndaKilgarriff 1:2ad195e1455b 183 {
EndaKilgarriff 1:2ad195e1455b 184 int32_t ret;
EndaKilgarriff 1:2ad195e1455b 185 uint8_t data[3];
EndaKilgarriff 1:2ad195e1455b 186
EndaKilgarriff 1:2ad195e1455b 187 if (!dev)
EndaKilgarriff 1:2ad195e1455b 188 return FAILURE;
EndaKilgarriff 1:2ad195e1455b 189
EndaKilgarriff 1:2ad195e1455b 190 data[0] = AD5593R_MODE_CONF | reg;
EndaKilgarriff 1:2ad195e1455b 191 data[1] = value >> 8;
EndaKilgarriff 1:2ad195e1455b 192 data[2] = value;
EndaKilgarriff 1:2ad195e1455b 193
EndaKilgarriff 1:2ad195e1455b 194 ret = i2c_write(dev->i2c, data,sizeof(data), STOP_BIT);
EndaKilgarriff 1:2ad195e1455b 195
EndaKilgarriff 1:2ad195e1455b 196 if (reg == AD5592R_REG_RESET && ret < 0) {
EndaKilgarriff 1:2ad195e1455b 197 return SUCCESS;
EndaKilgarriff 1:2ad195e1455b 198 }
EndaKilgarriff 1:2ad195e1455b 199
EndaKilgarriff 1:2ad195e1455b 200 return ret;
EndaKilgarriff 1:2ad195e1455b 201 }
EndaKilgarriff 1:2ad195e1455b 202
EndaKilgarriff 1:2ad195e1455b 203 /**
EndaKilgarriff 1:2ad195e1455b 204 * Read register.
EndaKilgarriff 1:2ad195e1455b 205 *
EndaKilgarriff 1:2ad195e1455b 206 * @param dev - The device structure.
EndaKilgarriff 1:2ad195e1455b 207 * @param reg - The register address.
EndaKilgarriff 1:2ad195e1455b 208 * @param value - register value
EndaKilgarriff 1:2ad195e1455b 209 * @return 0 in case of success, negative error code otherwise
EndaKilgarriff 1:2ad195e1455b 210 */
EndaKilgarriff 1:2ad195e1455b 211 int32_t ad5593r_reg_read(struct ad5592r_dev *dev, uint8_t reg,
EndaKilgarriff 1:2ad195e1455b 212 uint16_t *value)
EndaKilgarriff 1:2ad195e1455b 213 {
EndaKilgarriff 1:2ad195e1455b 214 int32_t ret;
EndaKilgarriff 1:2ad195e1455b 215 uint8_t data[2];
EndaKilgarriff 1:2ad195e1455b 216
EndaKilgarriff 1:2ad195e1455b 217 if (!dev)
EndaKilgarriff 1:2ad195e1455b 218 return FAILURE;
EndaKilgarriff 1:2ad195e1455b 219
EndaKilgarriff 1:2ad195e1455b 220 data[0] = AD5593R_MODE_REG_READBACK | reg;
EndaKilgarriff 1:2ad195e1455b 221
EndaKilgarriff 1:2ad195e1455b 222 ret = i2c_write(dev->i2c, data, 1, STOP_BIT);
EndaKilgarriff 1:2ad195e1455b 223 if (ret < 0)
EndaKilgarriff 1:2ad195e1455b 224 return ret;
EndaKilgarriff 1:2ad195e1455b 225
EndaKilgarriff 1:2ad195e1455b 226 ret = i2c_read(dev->i2c, data, sizeof(data), STOP_BIT);
EndaKilgarriff 1:2ad195e1455b 227 if (ret < 0)
EndaKilgarriff 1:2ad195e1455b 228 return ret;
EndaKilgarriff 1:2ad195e1455b 229
EndaKilgarriff 1:2ad195e1455b 230 *value = (uint16_t) (data[0] << 8) + data[1];
EndaKilgarriff 1:2ad195e1455b 231
EndaKilgarriff 1:2ad195e1455b 232 return 0;
EndaKilgarriff 1:2ad195e1455b 233 }
EndaKilgarriff 1:2ad195e1455b 234
EndaKilgarriff 1:2ad195e1455b 235 /**
EndaKilgarriff 1:2ad195e1455b 236 * Read GPIOs.
EndaKilgarriff 1:2ad195e1455b 237 *
EndaKilgarriff 1:2ad195e1455b 238 * @param dev - The device structure.
EndaKilgarriff 1:2ad195e1455b 239 * @param value - GPIOs value.
EndaKilgarriff 1:2ad195e1455b 240 * @return 0 in case of success, negative error code otherwise
EndaKilgarriff 1:2ad195e1455b 241 */
EndaKilgarriff 1:2ad195e1455b 242 int32_t ad5593r_gpio_read(struct ad5592r_dev *dev, uint8_t *value)
EndaKilgarriff 1:2ad195e1455b 243 {
EndaKilgarriff 1:2ad195e1455b 244 int32_t ret;
EndaKilgarriff 1:2ad195e1455b 245 uint8_t data[2];
EndaKilgarriff 1:2ad195e1455b 246
EndaKilgarriff 1:2ad195e1455b 247 if (!dev)
EndaKilgarriff 1:2ad195e1455b 248 return FAILURE;
EndaKilgarriff 1:2ad195e1455b 249
EndaKilgarriff 1:2ad195e1455b 250 data[0] = AD5593R_MODE_GPIO_READBACK;
EndaKilgarriff 1:2ad195e1455b 251 ret = i2c_write(dev->i2c, data, 1, STOP_BIT);
EndaKilgarriff 1:2ad195e1455b 252 if (ret < 0)
EndaKilgarriff 1:2ad195e1455b 253 return ret;
EndaKilgarriff 1:2ad195e1455b 254
EndaKilgarriff 1:2ad195e1455b 255 ret = i2c_read(dev->i2c, data, sizeof(data), STOP_BIT);
EndaKilgarriff 1:2ad195e1455b 256 if (ret < 0)
EndaKilgarriff 1:2ad195e1455b 257 return ret;
EndaKilgarriff 1:2ad195e1455b 258
EndaKilgarriff 1:2ad195e1455b 259 *value = data[1];
EndaKilgarriff 1:2ad195e1455b 260
EndaKilgarriff 1:2ad195e1455b 261 return 0;
EndaKilgarriff 1:2ad195e1455b 262 }
EndaKilgarriff 1:2ad195e1455b 263
EndaKilgarriff 1:2ad195e1455b 264 /**
EndaKilgarriff 1:2ad195e1455b 265 * Initialize AD5593r device.
EndaKilgarriff 1:2ad195e1455b 266 *
EndaKilgarriff 1:2ad195e1455b 267 * @param dev - The device structure.
EndaKilgarriff 1:2ad195e1455b 268 * @param init_param - The initial parameters of the device.
EndaKilgarriff 1:2ad195e1455b 269 * @return 0 in case of success, negative error code otherwise
EndaKilgarriff 1:2ad195e1455b 270 */
EndaKilgarriff 1:2ad195e1455b 271 int32_t ad5593r_init(struct ad5592r_dev *dev,
EndaKilgarriff 1:2ad195e1455b 272 struct ad5592r_init_param *init_param)
EndaKilgarriff 1:2ad195e1455b 273 {
EndaKilgarriff 1:2ad195e1455b 274 int32_t ret;
EndaKilgarriff 1:2ad195e1455b 275 uint16_t temp_reg_val;
EndaKilgarriff 1:2ad195e1455b 276
EndaKilgarriff 1:2ad195e1455b 277 if (!dev)
EndaKilgarriff 1:2ad195e1455b 278 return FAILURE;
EndaKilgarriff 1:2ad195e1455b 279
EndaKilgarriff 1:2ad195e1455b 280 dev->ops = &ad5593r_rw_ops;
EndaKilgarriff 1:2ad195e1455b 281
EndaKilgarriff 1:2ad195e1455b 282 ret = ad5592r_software_reset(dev);
EndaKilgarriff 1:2ad195e1455b 283 if (ret < 0)
EndaKilgarriff 1:2ad195e1455b 284 return ret;
EndaKilgarriff 1:2ad195e1455b 285
EndaKilgarriff 1:2ad195e1455b 286 ret = ad5592r_set_channel_modes(dev);
EndaKilgarriff 1:2ad195e1455b 287 if (ret < 0)
EndaKilgarriff 1:2ad195e1455b 288 return ret;
EndaKilgarriff 1:2ad195e1455b 289
EndaKilgarriff 1:2ad195e1455b 290 if(init_param->int_ref) {
EndaKilgarriff 1:2ad195e1455b 291 ret = ad5593r_reg_read(dev, AD5592R_REG_PD, &temp_reg_val);
EndaKilgarriff 1:2ad195e1455b 292 if (ret < 0)
EndaKilgarriff 1:2ad195e1455b 293 return ret;
EndaKilgarriff 1:2ad195e1455b 294 temp_reg_val |= AD5592R_REG_PD_EN_REF;
EndaKilgarriff 1:2ad195e1455b 295
EndaKilgarriff 1:2ad195e1455b 296 return ad5593r_reg_write(dev, AD5592R_REG_PD, temp_reg_val);
EndaKilgarriff 1:2ad195e1455b 297 }
EndaKilgarriff 1:2ad195e1455b 298
EndaKilgarriff 1:2ad195e1455b 299 return ret;
EndaKilgarriff 1:2ad195e1455b 300 }