Lines Matching +full:refin +full:- +full:supply

1 // SPDX-License-Identifier: GPL-2.0-only
5 * Copyright 2011-2012 Analog Devices Inc.
30 #define AD7793_REG_COMM 0 /* Communications Register (WO, 8-bit) */
31 #define AD7793_REG_STAT 0 /* Status Register (RO, 8-bit) */
32 #define AD7793_REG_MODE 1 /* Mode Register (RW, 16-bit */
33 #define AD7793_REG_CONF 2 /* Configuration Register (RW, 16-bit) */
34 #define AD7793_REG_DATA 3 /* Data Register (RO, 16-/24-bit) */
35 #define AD7793_REG_ID 4 /* ID Register (RO, 8-bit) */
36 #define AD7793_REG_IO 5 /* IO Register (RO, 8-bit) */
37 #define AD7793_REG_OFFSET 6 /* Offset Register (RW, 16-bit
38 * (AD7792)/24-bit (AD7793)) */
39 #define AD7793_REG_FULLSALE 7 /* Full-Scale Register
40 * (RW, 16-bit (AD7792)/24-bit (AD7793)) */
65 #define AD7793_MODE_PWRDN 3 /* Power-Down Mode */
66 #define AD7793_MODE_CAL_INT_ZERO 4 /* Internal Zero-Scale Calibration */
67 #define AD7793_MODE_CAL_INT_FULL 5 /* Internal Full-Scale Calibration */
68 #define AD7793_MODE_CAL_SYS_ZERO 6 /* System Zero-Scale Calibration */
69 #define AD7793_MODE_CAL_SYS_FULL 7 /* System Full-Scale Calibration */
90 #define AD7793_CH_AIN1P_AIN1M 0 /* AIN1(+) - AIN1(-) */
91 #define AD7793_CH_AIN2P_AIN2M 1 /* AIN2(+) - AIN2(-) */
92 #define AD7793_CH_AIN3P_AIN3M 2 /* AIN3(+) - AIN3(-) */
93 #define AD7793_CH_AIN1M_AIN1M 3 /* AIN1(-) - AIN1(-) */
97 #define AD7795_CH_AIN4P_AIN4M 4 /* AIN4(+) - AIN4(-) */
98 #define AD7795_CH_AIN5P_AIN5M 5 /* AIN5(+) - AIN5(-) */
99 #define AD7795_CH_AIN6P_AIN6M 6 /* AIN6(+) - AIN6(-) */
100 #define AD7795_CH_AIN1M_AIN1M 8 /* AIN1(-) - AIN1(-) */
185 st->conf &= ~AD7793_CONF_CHAN_MASK; in ad7793_set_channel()
186 st->conf |= AD7793_CONF_CHAN(channel); in ad7793_set_channel()
188 return ad_sd_write_reg(&st->sd, AD7793_REG_CONF, 2, st->conf); in ad7793_set_channel()
196 st->mode &= ~AD7793_MODE_SEL_MASK; in ad7793_set_mode()
197 st->mode |= AD7793_MODE_SEL(mode); in ad7793_set_mode()
199 return ad_sd_write_reg(&st->sd, AD7793_REG_MODE, 2, st->mode); in ad7793_set_mode()
222 return ad_sd_calibrate_all(&st->sd, ad7793_calib_arr, in ad7793_calibrate_all()
229 if ((pdata->current_source_direction == AD7793_IEXEC1_IEXEC2_IOUT1 || in ad7793_check_platform_data()
230 pdata->current_source_direction == AD7793_IEXEC1_IEXEC2_IOUT2) && in ad7793_check_platform_data()
231 ((pdata->exitation_current != AD7793_IX_10uA) && in ad7793_check_platform_data()
232 (pdata->exitation_current != AD7793_IX_210uA))) in ad7793_check_platform_data()
233 return -EINVAL; in ad7793_check_platform_data()
235 if (!(st->chip_info->flags & AD7793_FLAG_HAS_CLKSEL) && in ad7793_check_platform_data()
236 pdata->clock_src != AD7793_CLK_SRC_INT) in ad7793_check_platform_data()
237 return -EINVAL; in ad7793_check_platform_data()
239 if (!(st->chip_info->flags & AD7793_FLAG_HAS_REFSEL) && in ad7793_check_platform_data()
240 pdata->refsel != AD7793_REFSEL_REFIN1) in ad7793_check_platform_data()
241 return -EINVAL; in ad7793_check_platform_data()
243 if (!(st->chip_info->flags & AD7793_FLAG_HAS_VBIAS) && in ad7793_check_platform_data()
244 pdata->bias_voltage != AD7793_BIAS_VOLTAGE_DISABLED) in ad7793_check_platform_data()
245 return -EINVAL; in ad7793_check_platform_data()
247 if (!(st->chip_info->flags & AD7793_HAS_EXITATION_CURRENT) && in ad7793_check_platform_data()
248 pdata->exitation_current != AD7793_IX_DISABLED) in ad7793_check_platform_data()
249 return -EINVAL; in ad7793_check_platform_data()
268 ret = ad_sd_reset(&st->sd, 32); in ad7793_setup()
274 ret = ad_sd_read_reg(&st->sd, AD7793_REG_ID, 1, &id); in ad7793_setup()
280 if (id != st->chip_info->id) { in ad7793_setup()
281 ret = -ENODEV; in ad7793_setup()
282 dev_err(&st->sd.spi->dev, "device ID query failed\n"); in ad7793_setup()
286 st->mode = AD7793_MODE_RATE(1); in ad7793_setup()
287 st->conf = 0; in ad7793_setup()
289 if (st->chip_info->flags & AD7793_FLAG_HAS_CLKSEL) in ad7793_setup()
290 st->mode |= AD7793_MODE_CLKSRC(pdata->clock_src); in ad7793_setup()
291 if (st->chip_info->flags & AD7793_FLAG_HAS_REFSEL) in ad7793_setup()
292 st->conf |= AD7793_CONF_REFSEL(pdata->refsel); in ad7793_setup()
293 if (st->chip_info->flags & AD7793_FLAG_HAS_VBIAS) in ad7793_setup()
294 st->conf |= AD7793_CONF_VBIAS(pdata->bias_voltage); in ad7793_setup()
295 if (pdata->buffered || !(st->chip_info->flags & AD7793_FLAG_HAS_BUFFER)) in ad7793_setup()
296 st->conf |= AD7793_CONF_BUF; in ad7793_setup()
297 if (pdata->boost_enable && in ad7793_setup()
298 (st->chip_info->flags & AD7793_FLAG_HAS_VBIAS)) in ad7793_setup()
299 st->conf |= AD7793_CONF_BOOST; in ad7793_setup()
300 if (pdata->burnout_current) in ad7793_setup()
301 st->conf |= AD7793_CONF_BO_EN; in ad7793_setup()
302 if (pdata->unipolar) in ad7793_setup()
303 st->conf |= AD7793_CONF_UNIPOLAR; in ad7793_setup()
305 if (!(st->chip_info->flags & AD7793_FLAG_HAS_GAIN)) in ad7793_setup()
306 st->conf |= AD7793_CONF_GAIN(7); in ad7793_setup()
308 ret = ad7793_set_mode(&st->sd, AD_SD_MODE_IDLE); in ad7793_setup()
312 ret = ad7793_set_channel(&st->sd, 0); in ad7793_setup()
316 if (st->chip_info->flags & AD7793_HAS_EXITATION_CURRENT) { in ad7793_setup()
317 ret = ad_sd_write_reg(&st->sd, AD7793_REG_IO, 1, in ad7793_setup()
318 pdata->exitation_current | in ad7793_setup()
319 (pdata->current_source_direction << 2)); in ad7793_setup()
329 for (i = 0; i < ARRAY_SIZE(st->scale_avail); i++) { in ad7793_setup()
331 >> (st->chip_info->channels[0].scan_type.realbits - in ad7793_setup()
332 (!!(st->conf & AD7793_CONF_UNIPOLAR) ? 0 : 1)); in ad7793_setup()
335 st->scale_avail[i][1] = do_div(scale_uv, 100000000) * 10; in ad7793_setup()
336 st->scale_avail[i][0] = scale_uv; in ad7793_setup()
341 dev_err(&st->sd.spi->dev, "setup failed\n"); in ad7793_setup()
366 *vals = (int *)st->scale_avail; in ad7793_read_avail()
369 *length = ARRAY_SIZE(st->scale_avail) * 2; in ad7793_read_avail()
373 return -EINVAL; in ad7793_read_avail()
404 bool unipolar = !!(st->conf & AD7793_CONF_UNIPOLAR); in ad7793_read_raw()
415 switch (chan->type) { in ad7793_read_raw()
417 if (chan->differential) { in ad7793_read_raw()
418 *val = st-> in ad7793_read_raw()
419 scale_avail[(st->conf >> 8) & 0x7][0]; in ad7793_read_raw()
420 *val2 = st-> in ad7793_read_raw()
421 scale_avail[(st->conf >> 8) & 0x7][1]; in ad7793_read_raw()
432 return -EINVAL; in ad7793_read_raw()
435 scale_uv >>= (chan->scan_type.realbits - (unipolar ? 0 : 1)); in ad7793_read_raw()
441 *val = -(1 << (chan->scan_type.realbits - 1)); in ad7793_read_raw()
446 if (chan->type == IIO_TEMP) { in ad7793_read_raw()
450 shift = chan->scan_type.realbits - (unipolar ? 0 : 1); in ad7793_read_raw()
453 *val -= offset; in ad7793_read_raw()
457 *val = st->chip_info in ad7793_read_raw()
458 ->sample_freq_avail[AD7793_MODE_RATE(st->mode)]; in ad7793_read_raw()
461 return -EINVAL; in ad7793_read_raw()
480 ret = -EINVAL; in ad7793_write_raw()
481 for (i = 0; i < ARRAY_SIZE(st->scale_avail); i++) in ad7793_write_raw()
482 if (val2 == st->scale_avail[i][1]) { in ad7793_write_raw()
484 tmp = st->conf; in ad7793_write_raw()
485 st->conf &= ~AD7793_CONF_GAIN(-1); in ad7793_write_raw()
486 st->conf |= AD7793_CONF_GAIN(i); in ad7793_write_raw()
488 if (tmp == st->conf) in ad7793_write_raw()
491 ad_sd_write_reg(&st->sd, AD7793_REG_CONF, in ad7793_write_raw()
492 sizeof(st->conf), st->conf); in ad7793_write_raw()
499 ret = -EINVAL; in ad7793_write_raw()
504 if (val == st->chip_info->sample_freq_avail[i]) in ad7793_write_raw()
508 ret = -EINVAL; in ad7793_write_raw()
512 st->mode &= ~AD7793_MODE_RATE(-1); in ad7793_write_raw()
513 st->mode |= AD7793_MODE_RATE(i); in ad7793_write_raw()
514 ad_sd_write_reg(&st->sd, AD7793_REG_MODE, sizeof(st->mode), in ad7793_write_raw()
515 st->mode); in ad7793_write_raw()
518 ret = -EINVAL; in ad7793_write_raw()
553 .differential = (_channel2 == -1 ? 0 : 1), \
589 __AD7793_CHANNEL(_si, 0, -1, _address, _bits, \
596 __AD7793_CHANNEL(_si, _channel, -1, _address, _bits, \
597 _storagebits, _shift, "supply", IIO_VOLTAGE, \
773 const struct ad7793_platform_data *pdata = spi->dev.platform_data; in ad7793_probe()
779 dev_err(&spi->dev, "no platform data?\n"); in ad7793_probe()
780 return -ENODEV; in ad7793_probe()
783 if (!spi->irq) { in ad7793_probe()
784 dev_err(&spi->dev, "no IRQ?\n"); in ad7793_probe()
785 return -ENODEV; in ad7793_probe()
788 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); in ad7793_probe()
790 return -ENOMEM; in ad7793_probe()
794 ad_sd_init(&st->sd, indio_dev, spi, &ad7793_sigma_delta_info); in ad7793_probe()
796 if (pdata->refsel != AD7793_REFSEL_INTERNAL) { in ad7793_probe()
797 ret = devm_regulator_get_enable_read_voltage(&spi->dev, "refin"); in ad7793_probe()
803 vref_mv = 1170; /* Build-in ref */ in ad7793_probe()
806 st->chip_info = in ad7793_probe()
807 &ad7793_chip_info_tbl[spi_get_device_id(spi)->driver_data]; in ad7793_probe()
809 indio_dev->name = spi_get_device_id(spi)->name; in ad7793_probe()
810 indio_dev->modes = INDIO_DIRECT_MODE; in ad7793_probe()
811 indio_dev->channels = st->chip_info->channels; in ad7793_probe()
812 indio_dev->num_channels = st->chip_info->num_channels; in ad7793_probe()
813 indio_dev->info = st->chip_info->iio_info; in ad7793_probe()
815 ret = devm_ad_sd_setup_buffer_and_trigger(&spi->dev, indio_dev); in ad7793_probe()
823 return devm_iio_device_register(&spi->dev, indio_dev); in ad7793_probe()