Lines Matching +full:iio +full:- +full:consumer

1 // SPDX-License-Identifier: GPL-2.0-only
3 * Analog devices AD5764, AD5764R, AD5744, AD5744R quad-channel
16 #include <linux/regulator/consumer.h>
18 #include <linux/iio/iio.h>
19 #include <linux/iio/sysfs.h>
33 * struct ad5764_chip_info - chip specific information
34 * @int_vref: Value of the internal reference voltage in uV - 0 if external
44 * struct ad5764_state - driver instance specific data
90 .shift = 16 - (_bits), \
130 mutex_lock(&st->lock); in ad5764_write()
131 st->data[0].d32 = cpu_to_be32((reg << 16) | val); in ad5764_write()
133 ret = spi_write(st->spi, &st->data[0].d8[1], 3); in ad5764_write()
134 mutex_unlock(&st->lock); in ad5764_write()
146 .tx_buf = &st->data[0].d8[1], in ad5764_read()
150 .rx_buf = &st->data[1].d8[1], in ad5764_read()
155 mutex_lock(&st->lock); in ad5764_read()
157 st->data[0].d32 = cpu_to_be32((1 << 23) | (reg << 16)); in ad5764_read()
159 ret = spi_sync_transfer(st->spi, t, ARRAY_SIZE(t)); in ad5764_read()
161 *val = be32_to_cpu(st->data[1].d32) & 0xffff; in ad5764_read()
163 mutex_unlock(&st->lock); in ad5764_read()
172 return AD5764_REG_DATA(chan->address); in ad5764_chan_info_to_reg()
174 return AD5764_REG_OFFSET(chan->address); in ad5764_chan_info_to_reg()
176 return AD5764_REG_FINE_GAIN(chan->address); in ad5764_chan_info_to_reg()
187 const int max_val = (1 << chan->scan_type.realbits); in ad5764_write_raw()
193 return -EINVAL; in ad5764_write_raw()
194 val <<= chan->scan_type.shift; in ad5764_write_raw()
197 if (val >= 128 || val < -128) in ad5764_write_raw()
198 return -EINVAL; in ad5764_write_raw()
201 if (val >= 32 || val < -32) in ad5764_write_raw()
202 return -EINVAL; in ad5764_write_raw()
205 return -EINVAL; in ad5764_write_raw()
215 if (st->chip_info->int_vref) in ad5764_get_channel_vref()
216 return st->chip_info->int_vref; in ad5764_get_channel_vref()
218 return regulator_get_voltage(st->vref_reg[channel / 2].consumer); in ad5764_get_channel_vref()
231 reg = AD5764_REG_DATA(chan->address); in ad5764_read_raw()
235 *val >>= chan->scan_type.shift; in ad5764_read_raw()
238 reg = AD5764_REG_OFFSET(chan->address); in ad5764_read_raw()
245 reg = AD5764_REG_FINE_GAIN(chan->address); in ad5764_read_raw()
252 /* vout = 4 * vref + ((dac_code / 65536) - 0.5) */ in ad5764_read_raw()
253 vref = ad5764_get_channel_vref(st, chan->channel); in ad5764_read_raw()
258 *val2 = chan->scan_type.realbits; in ad5764_read_raw()
261 *val = -(1 << chan->scan_type.realbits) / 2; in ad5764_read_raw()
265 return -EINVAL; in ad5764_read_raw()
275 enum ad5764_type type = spi_get_device_id(spi)->driver_data; in ad5764_probe()
280 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); in ad5764_probe()
282 dev_err(&spi->dev, "Failed to allocate iio device\n"); in ad5764_probe()
283 return -ENOMEM; in ad5764_probe()
289 st->spi = spi; in ad5764_probe()
290 st->chip_info = &ad5764_chip_infos[type]; in ad5764_probe()
292 indio_dev->name = spi_get_device_id(spi)->name; in ad5764_probe()
293 indio_dev->info = &ad5764_info; in ad5764_probe()
294 indio_dev->modes = INDIO_DIRECT_MODE; in ad5764_probe()
295 indio_dev->num_channels = AD5764_NUM_CHANNELS; in ad5764_probe()
296 indio_dev->channels = st->chip_info->channels; in ad5764_probe()
298 mutex_init(&st->lock); in ad5764_probe()
300 if (st->chip_info->int_vref == 0) { in ad5764_probe()
301 st->vref_reg[0].supply = "vrefAB"; in ad5764_probe()
302 st->vref_reg[1].supply = "vrefCD"; in ad5764_probe()
304 ret = devm_regulator_bulk_get(&st->spi->dev, in ad5764_probe()
305 ARRAY_SIZE(st->vref_reg), st->vref_reg); in ad5764_probe()
307 dev_err(&spi->dev, "Failed to request vref regulators: %d\n", in ad5764_probe()
312 ret = regulator_bulk_enable(ARRAY_SIZE(st->vref_reg), in ad5764_probe()
313 st->vref_reg); in ad5764_probe()
315 dev_err(&spi->dev, "Failed to enable vref regulators: %d\n", in ad5764_probe()
323 dev_err(&spi->dev, "Failed to register iio device: %d\n", ret); in ad5764_probe()
330 if (st->chip_info->int_vref == 0) in ad5764_probe()
331 regulator_bulk_disable(ARRAY_SIZE(st->vref_reg), st->vref_reg); in ad5764_probe()
342 if (st->chip_info->int_vref == 0) in ad5764_remove()
343 regulator_bulk_disable(ARRAY_SIZE(st->vref_reg), st->vref_reg); in ad5764_remove()
365 MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");