Lines Matching +full:vref +full:- +full:p
1 // SPDX-License-Identifier: GPL-2.0-only
44 * enum ads8688_range - ADS8688 reference voltage range
45 * @ADS8688_PLUSMINUS25VREF: Device is configured for input range ±2.5 * VREF
46 * @ADS8688_PLUSMINUS125VREF: Device is configured for input range ±1.25 * VREF
47 * @ADS8688_PLUSMINUS0625VREF: Device is configured for input range ±0.625 * VREF
48 * @ADS8688_PLUS25VREF: Device is configured for input range 0 - 2.5 * VREF
49 * @ADS8688_PLUS125VREF: Device is configured for input range 0 - 1.25 * VREF
92 .offset = -(1 << (ADS8688_REALBITS - 1)),
97 .offset = -(1 << (ADS8688_REALBITS - 1)),
102 .offset = -(1 << (ADS8688_REALBITS - 1)),
123 ads8688_range_def[0].scale * st->vref_mv, in ads8688_show_scales()
124 ads8688_range_def[1].scale * st->vref_mv, in ads8688_show_scales()
125 ads8688_range_def[2].scale * st->vref_mv); in ads8688_show_scales()
193 st->data[0].d32 = cpu_to_be32(tmp); in ads8688_prog_write()
195 return spi_write(st->spi, &st->data[0].d8[1], 3); in ads8688_prog_write()
205 st->data[0].d32 = cpu_to_be32(tmp); in ads8688_reset()
207 return spi_write(st->spi, &st->data[0].d8[0], 4); in ads8688_reset()
217 .tx_buf = &st->data[0].d8[0], in ads8688_read()
221 .tx_buf = &st->data[1].d8[0], in ads8688_read()
222 .rx_buf = &st->data[1].d8[0], in ads8688_read()
229 st->data[0].d32 = cpu_to_be32(tmp); in ads8688_read()
233 st->data[1].d32 = cpu_to_be32(tmp); in ads8688_read()
235 ret = spi_sync_transfer(st->spi, t, ARRAY_SIZE(t)); in ads8688_read()
239 return be32_to_cpu(st->data[1].d32) & 0xffff; in ads8688_read()
251 mutex_lock(&st->lock); in ads8688_read_raw()
254 ret = ads8688_read(indio_dev, chan->channel); in ads8688_read_raw()
255 mutex_unlock(&st->lock); in ads8688_read_raw()
261 scale_mv = st->vref_mv; in ads8688_read_raw()
262 scale_mv *= ads8688_range_def[st->range[chan->channel]].scale; in ads8688_read_raw()
265 mutex_unlock(&st->lock); in ads8688_read_raw()
268 offset = ads8688_range_def[st->range[chan->channel]].offset; in ads8688_read_raw()
270 mutex_unlock(&st->lock); in ads8688_read_raw()
273 mutex_unlock(&st->lock); in ads8688_read_raw()
275 return -EINVAL; in ads8688_read_raw()
284 tmp = ADS8688_PROG_REG_RANGE_CH(chan->channel); in ads8688_write_reg_range()
295 int ret = -EINVAL, i, offset = 0; in ads8688_write_raw()
297 mutex_lock(&st->lock); in ads8688_write_raw()
300 /* If the offset is 0 the ±2.5 * VREF mode is not available */ in ads8688_write_raw()
301 offset = ads8688_range_def[st->range[chan->channel]].offset; in ads8688_write_raw()
302 if (offset == 0 && val2 == ads8688_range_def[0].scale * st->vref_mv) { in ads8688_write_raw()
303 mutex_unlock(&st->lock); in ads8688_write_raw()
304 return -EINVAL; in ads8688_write_raw()
309 if (val2 == ads8688_range_def[i].scale * st->vref_mv && in ads8688_write_raw()
319 * 0 and -(1 << (ADS8688_REALBITS - 1)) in ads8688_write_raw()
323 mutex_unlock(&st->lock); in ads8688_write_raw()
324 return -EINVAL; in ads8688_write_raw()
328 * If the device are in ±2.5 * VREF mode, it's not allowed to in ads8688_write_raw()
332 st->range[chan->channel] == ADS8688_PLUSMINUS25VREF) { in ads8688_write_raw()
333 mutex_unlock(&st->lock); in ads8688_write_raw()
334 return -EINVAL; in ads8688_write_raw()
337 scale = ads8688_range_def[st->range[chan->channel]].scale; in ads8688_write_raw()
351 st->range[chan->channel] = ads8688_range_def[i].range; in ads8688_write_raw()
353 mutex_unlock(&st->lock); in ads8688_write_raw()
369 return -EINVAL; in ads8688_write_raw_get_fmt()
379 static irqreturn_t ads8688_trigger_handler(int irq, void *p) in ads8688_trigger_handler() argument
381 struct iio_poll_func *pf = p; in ads8688_trigger_handler()
382 struct iio_dev *indio_dev = pf->indio_dev; in ads8688_trigger_handler()
395 iio_trigger_notify_done(indio_dev->trig); in ads8688_trigger_handler()
417 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); in ads8688_probe()
419 return -ENOMEM; in ads8688_probe()
423 ret = devm_regulator_get_enable_read_voltage(&spi->dev, "vref"); in ads8688_probe()
424 if (ret < 0 && ret != -ENODEV) in ads8688_probe()
427 st->vref_mv = ret == -ENODEV ? ADS8688_VREF_MV : ret / 1000; in ads8688_probe()
429 st->chip_info = &ads8688_chip_info_tbl[spi_get_device_id(spi)->driver_data]; in ads8688_probe()
431 spi->mode = SPI_MODE_1; in ads8688_probe()
433 st->spi = spi; in ads8688_probe()
435 indio_dev->name = spi_get_device_id(spi)->name; in ads8688_probe()
436 indio_dev->modes = INDIO_DIRECT_MODE; in ads8688_probe()
437 indio_dev->channels = st->chip_info->channels; in ads8688_probe()
438 indio_dev->num_channels = st->chip_info->num_channels; in ads8688_probe()
439 indio_dev->info = &ads8688_info; in ads8688_probe()
443 mutex_init(&st->lock); in ads8688_probe()
445 ret = devm_iio_triggered_buffer_setup(&spi->dev, indio_dev, NULL, in ads8688_probe()
448 return dev_err_probe(&spi->dev, ret, in ads8688_probe()
451 return devm_iio_device_register(&spi->dev, indio_dev); in ads8688_probe()