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
93 .offset = -(1 << (ADS8688_REALBITS - 1)),
98 .offset = -(1 << (ADS8688_REALBITS - 1)),
103 .offset = -(1 << (ADS8688_REALBITS - 1)),
124 ads8688_range_def[0].scale * st->vref_mv, in ads8688_show_scales()
125 ads8688_range_def[1].scale * st->vref_mv, in ads8688_show_scales()
126 ads8688_range_def[2].scale * st->vref_mv); in ads8688_show_scales()
194 st->data[0].d32 = cpu_to_be32(tmp); in ads8688_prog_write()
196 return spi_write(st->spi, &st->data[0].d8[1], 3); in ads8688_prog_write()
206 st->data[0].d32 = cpu_to_be32(tmp); in ads8688_reset()
208 return spi_write(st->spi, &st->data[0].d8[0], 4); in ads8688_reset()
218 .tx_buf = &st->data[0].d8[0], in ads8688_read()
222 .tx_buf = &st->data[1].d8[0], in ads8688_read()
223 .rx_buf = &st->data[1].d8[0], in ads8688_read()
230 st->data[0].d32 = cpu_to_be32(tmp); in ads8688_read()
234 st->data[1].d32 = cpu_to_be32(tmp); in ads8688_read()
236 ret = spi_sync_transfer(st->spi, t, ARRAY_SIZE(t)); in ads8688_read()
240 return be32_to_cpu(st->data[1].d32) & 0xffff; in ads8688_read()
252 mutex_lock(&st->lock); in ads8688_read_raw()
255 ret = ads8688_read(indio_dev, chan->channel); in ads8688_read_raw()
256 mutex_unlock(&st->lock); in ads8688_read_raw()
262 scale_mv = st->vref_mv; in ads8688_read_raw()
263 scale_mv *= ads8688_range_def[st->range[chan->channel]].scale; in ads8688_read_raw()
266 mutex_unlock(&st->lock); in ads8688_read_raw()
269 offset = ads8688_range_def[st->range[chan->channel]].offset; in ads8688_read_raw()
271 mutex_unlock(&st->lock); in ads8688_read_raw()
274 mutex_unlock(&st->lock); in ads8688_read_raw()
276 return -EINVAL; in ads8688_read_raw()
285 tmp = ADS8688_PROG_REG_RANGE_CH(chan->channel); in ads8688_write_reg_range()
296 int ret = -EINVAL, i, offset = 0; in ads8688_write_raw()
298 mutex_lock(&st->lock); in ads8688_write_raw()
301 /* If the offset is 0 the ±2.5 * VREF mode is not available */ in ads8688_write_raw()
302 offset = ads8688_range_def[st->range[chan->channel]].offset; in ads8688_write_raw()
303 if (offset == 0 && val2 == ads8688_range_def[0].scale * st->vref_mv) { in ads8688_write_raw()
304 mutex_unlock(&st->lock); in ads8688_write_raw()
305 return -EINVAL; in ads8688_write_raw()
310 if (val2 == ads8688_range_def[i].scale * st->vref_mv && in ads8688_write_raw()
320 * 0 and -(1 << (ADS8688_REALBITS - 1)) in ads8688_write_raw()
324 mutex_unlock(&st->lock); in ads8688_write_raw()
325 return -EINVAL; in ads8688_write_raw()
329 * If the device are in ±2.5 * VREF mode, it's not allowed to in ads8688_write_raw()
333 st->range[chan->channel] == ADS8688_PLUSMINUS25VREF) { in ads8688_write_raw()
334 mutex_unlock(&st->lock); in ads8688_write_raw()
335 return -EINVAL; in ads8688_write_raw()
338 scale = ads8688_range_def[st->range[chan->channel]].scale; in ads8688_write_raw()
352 st->range[chan->channel] = ads8688_range_def[i].range; in ads8688_write_raw()
354 mutex_unlock(&st->lock); in ads8688_write_raw()
370 return -EINVAL; in ads8688_write_raw_get_fmt()
380 static irqreturn_t ads8688_trigger_handler(int irq, void *p) in ads8688_trigger_handler() argument
382 struct iio_poll_func *pf = p; in ads8688_trigger_handler()
383 struct iio_dev *indio_dev = pf->indio_dev; in ads8688_trigger_handler()
388 for (i = 0; i < indio_dev->masklength; i++) { in ads8688_trigger_handler()
389 if (!test_bit(i, indio_dev->active_scan_mask)) in ads8688_trigger_handler()
398 iio_trigger_notify_done(indio_dev->trig); in ads8688_trigger_handler()
420 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); in ads8688_probe()
422 return -ENOMEM; in ads8688_probe()
426 st->reg = devm_regulator_get_optional(&spi->dev, "vref"); in ads8688_probe()
427 if (!IS_ERR(st->reg)) { in ads8688_probe()
428 ret = regulator_enable(st->reg); in ads8688_probe()
432 ret = regulator_get_voltage(st->reg); in ads8688_probe()
436 st->vref_mv = ret / 1000; in ads8688_probe()
439 st->vref_mv = ADS8688_VREF_MV; in ads8688_probe()
442 st->chip_info = &ads8688_chip_info_tbl[spi_get_device_id(spi)->driver_data]; in ads8688_probe()
444 spi->mode = SPI_MODE_1; in ads8688_probe()
448 st->spi = spi; in ads8688_probe()
450 indio_dev->name = spi_get_device_id(spi)->name; in ads8688_probe()
451 indio_dev->modes = INDIO_DIRECT_MODE; in ads8688_probe()
452 indio_dev->channels = st->chip_info->channels; in ads8688_probe()
453 indio_dev->num_channels = st->chip_info->num_channels; in ads8688_probe()
454 indio_dev->info = &ads8688_info; in ads8688_probe()
458 mutex_init(&st->lock); in ads8688_probe()
462 dev_err(&spi->dev, "iio triggered buffer setup failed\n"); in ads8688_probe()
476 if (!IS_ERR(st->reg)) in ads8688_probe()
477 regulator_disable(st->reg); in ads8688_probe()
490 if (!IS_ERR(st->reg)) in ads8688_remove()
491 regulator_disable(st->reg); in ads8688_remove()