Lines Matching +full:vref +full:- +full:p
1 // SPDX-License-Identifier: GPL-2.0-only
5 * Copyright (c) 2013-2015 Intel Corporation.
29 * In case of ACPI, we use the hard-wired 5000 mV of the Galileo and IOT2000
31 * via the vref-supply regulator.
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).
124 st->tx_buf[cmds++] = cpu_to_be16(ADC108S102_CMD(bit));
127 st->tx_buf[cmds++] = 0x00;
130 st->ring_xfer.tx_buf = &st->tx_buf[0];
131 st->ring_xfer.rx_buf = &st->rx_buf[0];
132 st->ring_xfer.len = cmds * sizeof(st->tx_buf[0]);
134 spi_message_init_with_transfers(&st->ring_msg, &st->ring_xfer, 1);
139 static irqreturn_t adc108s102_trigger_handler(int irq, void *p)
141 struct iio_poll_func *pf = p;
142 struct iio_dev *indio_dev = pf->indio_dev;
146 ret = spi_sync(st->spi, &st->ring_msg);
152 &st->rx_buf[1],
153 st->ring_xfer.len - sizeof(st->rx_buf[1]),
157 iio_trigger_notify_done(indio_dev->trig);
166 st->tx_buf[0] = cpu_to_be16(ADC108S102_CMD(ch));
167 ret = spi_sync(st->spi, &st->scan_single_msg);
172 return be16_to_cpu(st->rx_buf[1]);
185 return -EBUSY;
187 ret = adc108s102_scan_direct(st, chan->address);
198 if (chan->type != IIO_VOLTAGE)
201 *val = st->va_millivolt;
202 *val2 = chan->scan_type.realbits;
209 return -EINVAL;
223 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st));
225 return -ENOMEM;
229 if (ACPI_COMPANION(&spi->dev)) {
230 st->va_millivolt = ADC108S102_VA_MV_ACPI_DEFAULT;
232 ret = devm_regulator_get_enable_read_voltage(&spi->dev, "vref");
234 return dev_err_probe(&spi->dev, ret, "failed get vref voltage\n");
236 st->va_millivolt = ret / 1000;
239 st->spi = spi;
241 indio_dev->name = spi->modalias;
242 indio_dev->modes = INDIO_DIRECT_MODE;
243 indio_dev->channels = adc108s102_channels;
244 indio_dev->num_channels = ARRAY_SIZE(adc108s102_channels);
245 indio_dev->info = &adc108s102_info;
248 st->scan_single_xfer.tx_buf = st->tx_buf;
249 st->scan_single_xfer.rx_buf = st->rx_buf;
250 st->scan_single_xfer.len = 2 * sizeof(st->tx_buf[0]);
252 spi_message_init_with_transfers(&st->scan_single_msg,
253 &st->scan_single_xfer, 1);
255 ret = devm_iio_triggered_buffer_setup(&spi->dev, indio_dev, NULL,
261 ret = devm_iio_device_register(&spi->dev, indio_dev);
263 dev_err(&spi->dev, "Failed to register IIO device\n");