Lines Matching +full:iio +full:- +full:aux
1 // SPDX-License-Identifier: GPL-2.0-only
12 #include <linux/iio/iio.h>
13 #include <linux/iio/sysfs.h>
30 * struct ad5761_chip_info - chip specific information
31 * @int_vref: Value of the internal reference voltage in mV - 0 if external
54 * struct ad5761_state - driver instance specific data
119 st->data[0].d32 = cpu_to_be32(AD5761_ADDR(addr) | val); in _ad5761_spi_write()
121 return spi_write(st->spi, &st->data[0].d8[1], 3); in _ad5761_spi_write()
129 mutex_lock(&st->lock); in ad5761_spi_write()
131 mutex_unlock(&st->lock); in ad5761_spi_write()
141 .tx_buf = &st->data[0].d8[1], in _ad5761_spi_read()
146 .tx_buf = &st->data[1].d8[1], in _ad5761_spi_read()
147 .rx_buf = &st->data[2].d8[1], in _ad5761_spi_read()
153 st->data[0].d32 = cpu_to_be32(AD5761_ADDR(addr)); in _ad5761_spi_read()
154 st->data[1].d32 = cpu_to_be32(AD5761_ADDR(AD5761_ADDR_NOOP)); in _ad5761_spi_read()
156 ret = spi_sync_transfer(st->spi, xfers, ARRAY_SIZE(xfers)); in _ad5761_spi_read()
158 *val = be32_to_cpu(st->data[2].d32); in _ad5761_spi_read()
168 mutex_lock(&st->lock); in ad5761_spi_read()
170 mutex_unlock(&st->lock); in ad5761_spi_read()
178 u16 aux; in ad5761_spi_set_range() local
181 aux = (range & 0x7) | AD5761_CTRL_ETS; in ad5761_spi_set_range()
183 if (st->use_intref) in ad5761_spi_set_range()
184 aux |= AD5761_CTRL_USE_INTVREF; in ad5761_spi_set_range()
190 ret = _ad5761_spi_write(st, AD5761_ADDR_CTRL_WRITE_REG, aux); in ad5761_spi_set_range()
194 st->range = range; in ad5761_spi_set_range()
207 u16 aux; in ad5761_read_raw() local
211 ret = ad5761_spi_read(indio_dev, AD5761_ADDR_DAC_READ, &aux); in ad5761_read_raw()
214 *val = aux >> chan->scan_type.shift; in ad5761_read_raw()
218 *val = st->vref * ad5761_range_params[st->range].m; in ad5761_read_raw()
220 *val2 = chan->scan_type.realbits; in ad5761_read_raw()
224 *val = -(1 << chan->scan_type.realbits); in ad5761_read_raw()
225 *val *= ad5761_range_params[st->range].c; in ad5761_read_raw()
226 *val /= ad5761_range_params[st->range].m; in ad5761_read_raw()
229 return -EINVAL; in ad5761_read_raw()
239 u16 aux; in ad5761_write_raw() local
242 return -EINVAL; in ad5761_write_raw()
244 if (val2 || (val << chan->scan_type.shift) > 0xffff || val < 0) in ad5761_write_raw()
245 return -EINVAL; in ad5761_write_raw()
247 aux = val << chan->scan_type.shift; in ad5761_write_raw()
249 return ad5761_spi_write(indio_dev, AD5761_ADDR_DAC_WRITE, aux); in ad5761_write_raw()
267 .shift = 16 - (_bits), \
295 st->vref_reg = devm_regulator_get_optional(&st->spi->dev, "vref"); in ad5761_get_vref()
296 if (PTR_ERR(st->vref_reg) == -ENODEV) { in ad5761_get_vref()
298 if (!chip_info->int_vref) { in ad5761_get_vref()
299 dev_err(&st->spi->dev, in ad5761_get_vref()
301 return -EIO; in ad5761_get_vref()
304 st->use_intref = true; in ad5761_get_vref()
305 st->vref = chip_info->int_vref; in ad5761_get_vref()
309 if (IS_ERR(st->vref_reg)) { in ad5761_get_vref()
310 dev_err(&st->spi->dev, in ad5761_get_vref()
312 return PTR_ERR(st->vref_reg); in ad5761_get_vref()
315 ret = regulator_enable(st->vref_reg); in ad5761_get_vref()
317 dev_err(&st->spi->dev, in ad5761_get_vref()
322 ret = regulator_get_voltage(st->vref_reg); in ad5761_get_vref()
324 dev_err(&st->spi->dev, in ad5761_get_vref()
330 dev_warn(&st->spi->dev, in ad5761_get_vref()
332 ret = -EIO; in ad5761_get_vref()
336 st->vref = ret / 1000; in ad5761_get_vref()
337 st->use_intref = false; in ad5761_get_vref()
342 regulator_disable(st->vref_reg); in ad5761_get_vref()
343 st->vref_reg = NULL; in ad5761_get_vref()
353 &ad5761_chip_infos[spi_get_device_id(spi)->driver_data]; in ad5761_probe()
355 struct ad5761_platform_data *pdata = dev_get_platdata(&spi->dev); in ad5761_probe()
357 iio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); in ad5761_probe()
359 return -ENOMEM; in ad5761_probe()
363 st->spi = spi; in ad5761_probe()
371 voltage_range = pdata->voltage_range; in ad5761_probe()
373 mutex_init(&st->lock); in ad5761_probe()
379 iio_dev->info = &ad5761_info; in ad5761_probe()
380 iio_dev->modes = INDIO_DIRECT_MODE; in ad5761_probe()
381 iio_dev->channels = &chip_info->channel; in ad5761_probe()
382 iio_dev->num_channels = 1; in ad5761_probe()
383 iio_dev->name = spi_get_device_id(st->spi)->name; in ad5761_probe()
391 if (!IS_ERR_OR_NULL(st->vref_reg)) in ad5761_probe()
392 regulator_disable(st->vref_reg); in ad5761_probe()
404 if (!IS_ERR_OR_NULL(st->vref_reg)) in ad5761_remove()
405 regulator_disable(st->vref_reg); in ad5761_remove()