Lines Matching +full:output +full:- +full:range +full:- +full:microvolts

1 // SPDX-License-Identifier: GPL-2.0-only
5 * Copyright 2019-2020 Analog Devices Inc.
65 * struct ad5766_chip_info - chip specific information
93 * struct ad5766_state - driver instance specific data
98 * @crt_range: Current selected output range
101 * 0 - Normal operation, 1 - Power down
135 [AD5766_VOLTAGE_RANGE_M20V_0V] = {-20, 0},
136 [AD5766_VOLTAGE_RANGE_M16V_to_0V] = {-16, 0},
137 [AD5766_VOLTAGE_RANGE_M10V_to_0V] = {-10, 0},
138 [AD5766_VOLTAGE_RANGE_M12V_to_14V] = {-12, 14},
139 [AD5766_VOLTAGE_RANGE_M16V_to_10V] = {-16, 10},
140 [AD5766_VOLTAGE_RANGE_M10V_to_6V] = {-10, 6},
141 [AD5766_VOLTAGE_RANGE_M5V_to_5V] = {-5, 5},
142 [AD5766_VOLTAGE_RANGE_M10V_to_10V] = {-10, 10},
150 .tx_buf = &st->data[0].d32, in __ad5766_spi_read()
155 .tx_buf = &st->data[1].d32, in __ad5766_spi_read()
156 .rx_buf = &st->data[2].d32, in __ad5766_spi_read()
162 st->data[0].d32 = AD5766_CMD_READBACK_REG(dac); in __ad5766_spi_read()
163 st->data[1].d32 = AD5766_CMD_NOP_MUX_OUT; in __ad5766_spi_read()
165 ret = spi_sync_transfer(st->spi, xfers, ARRAY_SIZE(xfers)); in __ad5766_spi_read()
169 *val = st->data[2].w16[1]; in __ad5766_spi_read()
176 st->data[0].b8[0] = command; in __ad5766_spi_write()
177 put_unaligned_be16(data, &st->data[0].b8[1]); in __ad5766_spi_write()
179 return spi_write(st->spi, &st->data[0].b8[0], 3); in __ad5766_spi_write()
187 mutex_lock(&st->lock); in ad5766_read()
189 mutex_unlock(&st->lock); in ad5766_read()
199 mutex_lock(&st->lock); in ad5766_write()
201 mutex_unlock(&st->lock); in ad5766_write()
210 if (st->gpio_reset) { in ad5766_reset()
211 gpiod_set_value_cansleep(st->gpio_reset, 1); in ad5766_reset()
213 gpiod_set_value_cansleep(st->gpio_reset, 0); in ad5766_reset()
241 ret = ad5766_read(indio_dev, chan->address, val); in ad5766_read_raw()
247 *val = ad5766_span_tbl[st->crt_range].min; in ad5766_read_raw()
251 *val = ad5766_span_tbl[st->crt_range].max - in ad5766_read_raw()
252 ad5766_span_tbl[st->crt_range].min; in ad5766_read_raw()
253 *val2 = st->chip_info->channels[0].scan_type.realbits; in ad5766_read_raw()
257 return -EINVAL; in ad5766_read_raw()
270 const int max_val = GENMASK(chan->scan_type.realbits - 1, 0); in ad5766_write_raw()
273 return -EINVAL; in ad5766_write_raw()
274 val <<= chan->scan_type.shift; in ad5766_write_raw()
275 return ad5766_write(indio_dev, chan->address, val); in ad5766_write_raw()
278 return -EINVAL; in ad5766_write_raw()
293 source = st->dither_source & AD5766_DITHER_SOURCE_MASK(chan->channel); in ad5766_get_dither_source()
294 source = source >> (chan->channel * 2); in ad5766_get_dither_source()
295 source -= 1; in ad5766_get_dither_source()
308 st->dither_source &= ~AD5766_DITHER_SOURCE_MASK(chan->channel); in ad5766_set_dither_source()
309 st->dither_source |= AD5766_DITHER_SOURCE(chan->channel, source); in ad5766_set_dither_source()
311 val = FIELD_GET(AD5766_LOWER_WORD_SPI_MASK, st->dither_source); in ad5766_set_dither_source()
316 val = FIELD_GET(AD5766_UPPER_WORD_SPI_MASK, st->dither_source); in ad5766_set_dither_source()
327 scale = st->dither_scale & AD5766_DITHER_SCALE_MASK(chan->channel); in ad5766_get_dither_scale()
329 return (scale >> (chan->channel * 2)); in ad5766_get_dither_scale()
340 st->dither_scale &= ~AD5766_DITHER_SCALE_MASK(chan->channel); in ad5766_set_dither_scale()
341 st->dither_scale |= AD5766_DITHER_SCALE(chan->channel, scale); in ad5766_set_dither_scale()
343 val = FIELD_GET(AD5766_LOWER_WORD_SPI_MASK, st->dither_scale); in ad5766_set_dither_scale()
347 val = FIELD_GET(AD5766_UPPER_WORD_SPI_MASK, st->dither_scale); in ad5766_set_dither_scale()
369 !(st->dither_enable & BIT(chan->channel))); in ad5766_read_ext()
373 !!(st->dither_invert & BIT(chan->channel))); in ad5766_read_ext()
379 return -EINVAL; in ad5766_read_ext()
398 st->dither_enable &= ~AD5766_DITHER_ENABLE_MASK(chan->channel); in ad5766_write_ext()
399 st->dither_enable |= AD5766_DITHER_ENABLE(chan->channel, in ad5766_write_ext()
402 st->dither_enable); in ad5766_write_ext()
405 st->dither_invert &= ~AD5766_DITHER_INVERT_MASK(chan->channel); in ad5766_write_ext()
406 st->dither_invert |= AD5766_DITHER_INVERT(chan->channel, in ad5766_write_ext()
409 st->dither_invert); in ad5766_write_ext()
415 return -EINVAL; in ad5766_write_ext()
446 .output = 1, \
457 .shift = 16 - (_bits), \
500 ret = device_property_read_u32_array(&st->spi->dev, in ad5766_get_output_range()
501 "output-range-microvolts", in ad5766_get_output_range()
513 st->crt_range = i; in ad5766_get_output_range()
518 return -EINVAL; in ad5766_get_output_range()
536 st->dither_enable = GENMASK(15, 0); in ad5766_default_setup()
538 st->dither_enable); in ad5766_default_setup()
542 st->dither_source = 0; in ad5766_default_setup()
544 st->dither_source |= AD5766_DITHER_SOURCE(i, 0); in ad5766_default_setup()
545 val = FIELD_GET(AD5766_LOWER_WORD_SPI_MASK, st->dither_source); in ad5766_default_setup()
550 val = FIELD_GET(AD5766_UPPER_WORD_SPI_MASK, st->dither_source); in ad5766_default_setup()
555 st->dither_scale = 0; in ad5766_default_setup()
556 val = FIELD_GET(AD5766_LOWER_WORD_SPI_MASK, st->dither_scale); in ad5766_default_setup()
561 val = FIELD_GET(AD5766_UPPER_WORD_SPI_MASK, st->dither_scale); in ad5766_default_setup()
566 st->dither_invert = 0; in ad5766_default_setup()
567 ret = __ad5766_spi_write(st, AD5766_CMD_INV_DITHER, st->dither_invert); in ad5766_default_setup()
571 return __ad5766_spi_write(st, AD5766_CMD_SPAN_REG, st->crt_range); in ad5766_default_setup()
577 struct iio_dev *indio_dev = pf->indio_dev; in ad5766_trigger_handler()
578 struct iio_buffer *buffer = indio_dev->buffer; in ad5766_trigger_handler()
588 mutex_lock(&st->lock); in ad5766_trigger_handler()
589 for_each_set_bit(ch, indio_dev->active_scan_mask, in ad5766_trigger_handler()
590 st->chip_info->num_channels - 1) in ad5766_trigger_handler()
594 *indio_dev->active_scan_mask); in ad5766_trigger_handler()
595 mutex_unlock(&st->lock); in ad5766_trigger_handler()
598 iio_trigger_notify_done(indio_dev->trig); in ad5766_trigger_handler()
610 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); in ad5766_probe()
612 return -ENOMEM; in ad5766_probe()
615 mutex_init(&st->lock); in ad5766_probe()
617 st->spi = spi; in ad5766_probe()
618 type = spi_get_device_id(spi)->driver_data; in ad5766_probe()
619 st->chip_info = &ad5766_chip_infos[type]; in ad5766_probe()
621 indio_dev->channels = st->chip_info->channels; in ad5766_probe()
622 indio_dev->num_channels = st->chip_info->num_channels; in ad5766_probe()
623 indio_dev->info = &ad5766_info; in ad5766_probe()
624 indio_dev->name = spi_get_device_id(spi)->name; in ad5766_probe()
625 indio_dev->modes = INDIO_DIRECT_MODE; in ad5766_probe()
627 st->gpio_reset = devm_gpiod_get_optional(&st->spi->dev, "reset", in ad5766_probe()
629 if (IS_ERR(st->gpio_reset)) in ad5766_probe()
630 return PTR_ERR(st->gpio_reset); in ad5766_probe()
637 ret = devm_iio_triggered_buffer_setup_ext(&spi->dev, indio_dev, NULL, in ad5766_probe()
645 return devm_iio_device_register(&spi->dev, indio_dev); in ad5766_probe()
672 MODULE_AUTHOR("Denis-Gabriel Gheorghescu <denis.gheorghescu@analog.com>");