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).
78 * rx_buf: 1 dummy response, 8 channel responses, plus 64-bit timestamp
125 st->tx_buf[cmds++] = cpu_to_be16(ADC108S102_CMD(bit)); in adc108s102_update_scan_mode()
128 st->tx_buf[cmds++] = 0x00; in adc108s102_update_scan_mode()
131 st->ring_xfer.tx_buf = &st->tx_buf[0]; in adc108s102_update_scan_mode()
132 st->ring_xfer.rx_buf = &st->rx_buf[0]; in adc108s102_update_scan_mode()
133 st->ring_xfer.len = cmds * sizeof(st->tx_buf[0]); in adc108s102_update_scan_mode()
135 spi_message_init_with_transfers(&st->ring_msg, &st->ring_xfer, 1); in adc108s102_update_scan_mode()
140 static irqreturn_t adc108s102_trigger_handler(int irq, void *p) in adc108s102_trigger_handler() argument
142 struct iio_poll_func *pf = p; in adc108s102_trigger_handler()
143 struct iio_dev *indio_dev = pf->indio_dev; in adc108s102_trigger_handler()
147 ret = spi_sync(st->spi, &st->ring_msg); in adc108s102_trigger_handler()
153 (u8 *)&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 st->reg = devm_regulator_get(&spi->dev, "vref"); in adc108s102_probe()
234 if (IS_ERR(st->reg)) in adc108s102_probe()
235 return PTR_ERR(st->reg); in adc108s102_probe()
237 ret = regulator_enable(st->reg); in adc108s102_probe()
239 dev_err(&spi->dev, "Cannot enable vref regulator\n"); in adc108s102_probe()
243 ret = regulator_get_voltage(st->reg); in adc108s102_probe()
245 dev_err(&spi->dev, "vref get voltage failed\n"); in adc108s102_probe()
249 st->va_millivolt = ret / 1000; in adc108s102_probe()
253 st->spi = spi; in adc108s102_probe()
255 indio_dev->name = spi->modalias; in adc108s102_probe()
256 indio_dev->modes = INDIO_DIRECT_MODE; in adc108s102_probe()
257 indio_dev->channels = adc108s102_channels; in adc108s102_probe()
258 indio_dev->num_channels = ARRAY_SIZE(adc108s102_channels); in adc108s102_probe()
259 indio_dev->info = &adc108s102_info; in adc108s102_probe()
262 st->scan_single_xfer.tx_buf = st->tx_buf; in adc108s102_probe()
263 st->scan_single_xfer.rx_buf = st->rx_buf; in adc108s102_probe()
264 st->scan_single_xfer.len = 2 * sizeof(st->tx_buf[0]); in adc108s102_probe()
266 spi_message_init_with_transfers(&st->scan_single_msg, in adc108s102_probe()
267 &st->scan_single_xfer, 1); in adc108s102_probe()
276 dev_err(&spi->dev, "Failed to register IIO device\n"); in adc108s102_probe()
285 regulator_disable(st->reg); in adc108s102_probe()
298 regulator_disable(st->reg); in adc108s102_remove()