Lines Matching +full:adc +full:- +full:use +full:- +full:res
1 // SPDX-License-Identifier: GPL-2.0-only
3 * TI ADC108S102 SPI ADC driver
5 * Copyright (c) 2013-2015 Intel Corporation.
12 * The communication with ADC chip is via the SPI bus (mode 3).
29 * In case of ACPI, we use the hard-wired 5000 mV of the Galileo and IOT2000
31 * via the vref-supply regulator.
36 * Defining the ADC resolution being 12 bits, we can use the same driver for
38 * chips. The ADC108S102 effectively returns a 12-bit result with the 2
39 * least-significant bits unset.
45 * 16-bit SPI command format:
47 * [13:11] 3-bit channel address
53 * 16-bit SPI response format:
55 * [11:0] 12-bit ADC sample (for ADC108S102, [1:0] will always be 0).
57 #define ADC108S102_RES_DATA(res) ((u16)res & GENMASK(11, 0)) argument
124 st->tx_buf[cmds++] = cpu_to_be16(ADC108S102_CMD(bit)); in adc108s102_update_scan_mode()
127 st->tx_buf[cmds++] = 0x00; in adc108s102_update_scan_mode()
130 st->ring_xfer.tx_buf = &st->tx_buf[0]; in adc108s102_update_scan_mode()
131 st->ring_xfer.rx_buf = &st->rx_buf[0]; in adc108s102_update_scan_mode()
132 st->ring_xfer.len = cmds * sizeof(st->tx_buf[0]); in adc108s102_update_scan_mode()
134 spi_message_init_with_transfers(&st->ring_msg, &st->ring_xfer, 1); in adc108s102_update_scan_mode()
142 struct iio_dev *indio_dev = pf->indio_dev; in adc108s102_trigger_handler()
146 ret = spi_sync(st->spi, &st->ring_msg); in adc108s102_trigger_handler()
152 &st->rx_buf[1], in adc108s102_trigger_handler()
153 st->ring_xfer.len - sizeof(st->rx_buf[1]), in adc108s102_trigger_handler()
157 iio_trigger_notify_done(indio_dev->trig); in adc108s102_trigger_handler()
166 st->tx_buf[0] = cpu_to_be16(ADC108S102_CMD(ch)); in adc108s102_scan_direct()
167 ret = spi_sync(st->spi, &st->scan_single_msg); in adc108s102_scan_direct()
172 return be16_to_cpu(st->rx_buf[1]); in adc108s102_scan_direct()
188 ret = adc108s102_scan_direct(st, chan->address); in adc108s102_read_raw()
199 if (chan->type != IIO_VOLTAGE) in adc108s102_read_raw()
202 *val = st->va_millivolt; in adc108s102_read_raw()
203 *val2 = chan->scan_type.realbits; in adc108s102_read_raw()
210 return -EINVAL; in adc108s102_read_raw()
224 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); in adc108s102_probe()
226 return -ENOMEM; in adc108s102_probe()
230 if (ACPI_COMPANION(&spi->dev)) { in adc108s102_probe()
231 st->va_millivolt = ADC108S102_VA_MV_ACPI_DEFAULT; in adc108s102_probe()
233 ret = devm_regulator_get_enable_read_voltage(&spi->dev, "vref"); in adc108s102_probe()
235 return dev_err_probe(&spi->dev, ret, "failed get vref voltage\n"); in adc108s102_probe()
237 st->va_millivolt = ret / 1000; in adc108s102_probe()
240 st->spi = spi; in adc108s102_probe()
242 indio_dev->name = spi->modalias; in adc108s102_probe()
243 indio_dev->modes = INDIO_DIRECT_MODE; in adc108s102_probe()
244 indio_dev->channels = adc108s102_channels; in adc108s102_probe()
245 indio_dev->num_channels = ARRAY_SIZE(adc108s102_channels); in adc108s102_probe()
246 indio_dev->info = &adc108s102_info; in adc108s102_probe()
249 st->scan_single_xfer.tx_buf = st->tx_buf; in adc108s102_probe()
250 st->scan_single_xfer.rx_buf = st->rx_buf; in adc108s102_probe()
251 st->scan_single_xfer.len = 2 * sizeof(st->tx_buf[0]); in adc108s102_probe()
253 spi_message_init_with_transfers(&st->scan_single_msg, in adc108s102_probe()
254 &st->scan_single_xfer, 1); in adc108s102_probe()
256 ret = devm_iio_triggered_buffer_setup(&spi->dev, indio_dev, NULL, in adc108s102_probe()
262 ret = devm_iio_device_register(&spi->dev, indio_dev); in adc108s102_probe()
264 dev_err(&spi->dev, "Failed to register IIO device\n"); in adc108s102_probe()