Lines Matching +full:excitation +full:- +full:current +full:- +full:microamp
1 // SPDX-License-Identifier: GPL-2.0
204 * Synchronize consecutive operations when doing a one-shot
386 [AD74115_ADC_RANGE_12V_BIPOLAR] = { -12000000, 12000000 },
387 [AD74115_ADC_RANGE_2_5V_BIPOLAR] = { -2500000, 2500000 },
388 [AD74115_ADC_RANGE_2_5V_NEG] = { -2500000, 0 },
391 [AD74115_ADC_RANGE_104MV_BIPOLAR] = { -104000, 104000 },
406 return -EINVAL; in _ad74115_find_tbl_index()
428 ad74115_format_reg_write(reg, val, st->reg_tx_buf); in ad74115_reg_write()
430 return spi_write(st->spi, st->reg_tx_buf, AD74115_FRAME_SIZE); in ad74115_reg_write()
435 struct device *dev = &st->spi->dev; in ad74115_crc_check()
441 return -EINVAL; in ad74115_crc_check()
452 .tx_buf = st->reg_tx_buf, in ad74115_reg_read()
453 .len = sizeof(st->reg_tx_buf), in ad74115_reg_read()
457 .rx_buf = st->reg_rx_buf, in ad74115_reg_read()
458 .len = sizeof(st->reg_rx_buf), in ad74115_reg_read()
463 ad74115_format_reg_write(AD74115_READ_SELECT_REG, reg, st->reg_tx_buf); in ad74115_reg_read()
465 ret = spi_sync_transfer(st->spi, reg_read_xfer, ARRAY_SIZE(reg_read_xfer)); in ad74115_reg_read()
469 ret = ad74115_crc_check(st, st->reg_rx_buf); in ad74115_reg_read()
473 *val = get_unaligned_be16(&st->reg_rx_buf[1]); in ad74115_reg_read()
488 return regmap_update_bits(st->regmap, AD74115_GPIO_CONFIG_X_REG(offset), in ad74115_gpio_config_set()
499 *valid_mask = st->gpio_valid_mask; in ad74115_gpio_init_valid_mask()
510 ret = regmap_read(st->regmap, AD74115_GPIO_CONFIG_X_REG(offset), &val); in ad74115_gpio_get_direction()
538 ret = regmap_read(st->regmap, AD74115_GPIO_CONFIG_X_REG(offset), &val); in ad74115_gpio_get()
548 struct device *dev = &st->spi->dev; in ad74115_gpio_set()
551 ret = regmap_update_bits(st->regmap, AD74115_GPIO_CONFIG_X_REG(offset), in ad74115_gpio_set()
569 i = len - 1; in ad74115_set_comp_debounce()
571 return regmap_update_bits(st->regmap, AD74115_DIN_CONFIG1_REG, in ad74115_set_comp_debounce()
594 return -ENOTSUPP; in ad74115_comp_gpio_set_config()
604 ret = regmap_read(st->regmap, AD74115_DIN_COMP_OUT_REG, &val); in ad74115_comp_gpio_get()
614 struct iio_dev *indio_dev = pf->indio_dev; in ad74115_trigger_handler()
618 ret = spi_sync(st->spi, &st->adc_samples_msg); in ad74115_trigger_handler()
622 iio_push_to_buffers(indio_dev, st->adc_samples_rx_buf); in ad74115_trigger_handler()
625 iio_trigger_notify_done(indio_dev->trig); in ad74115_trigger_handler()
636 iio_trigger_poll(st->trig); in ad74115_adc_data_interrupt()
638 complete(&st->adc_data_completion); in ad74115_adc_data_interrupt()
648 return regmap_update_bits(st->regmap, AD74115_ADC_CONV_CTRL_REG, mask, in ad74115_set_adc_ch_en()
655 return regmap_update_bits(st->regmap, AD74115_ADC_CONV_CTRL_REG, in ad74115_set_adc_conv_seq()
664 struct spi_transfer *xfer = st->adc_samples_xfer; in ad74115_update_scan_mode()
665 u8 *rx_buf = st->adc_samples_rx_buf; in ad74115_update_scan_mode()
666 u8 *tx_buf = st->adc_samples_tx_buf; in ad74115_update_scan_mode()
670 mutex_lock(&st->lock); in ad74115_update_scan_mode()
672 spi_message_init(&st->adc_samples_msg); in ad74115_update_scan_mode()
697 if (xfer == st->adc_samples_xfer) in ad74115_update_scan_mode()
698 xfer->rx_buf = NULL; in ad74115_update_scan_mode()
700 xfer->rx_buf = rx_buf; in ad74115_update_scan_mode()
702 xfer->tx_buf = tx_buf; in ad74115_update_scan_mode()
703 xfer->len = AD74115_FRAME_SIZE; in ad74115_update_scan_mode()
704 xfer->cs_change = 1; in ad74115_update_scan_mode()
709 spi_message_add_tail(xfer, &st->adc_samples_msg); in ad74115_update_scan_mode()
712 if (xfer != st->adc_samples_xfer) in ad74115_update_scan_mode()
717 xfer->rx_buf = rx_buf; in ad74115_update_scan_mode()
718 xfer->tx_buf = NULL; in ad74115_update_scan_mode()
719 xfer->len = AD74115_FRAME_SIZE; in ad74115_update_scan_mode()
720 xfer->cs_change = 0; in ad74115_update_scan_mode()
722 spi_message_add_tail(xfer, &st->adc_samples_msg); in ad74115_update_scan_mode()
725 mutex_unlock(&st->lock); in ad74115_update_scan_mode()
743 mutex_lock(&st->lock); in ad74115_buffer_predisable()
760 mutex_unlock(&st->lock); in ad74115_buffer_predisable()
780 ret = regmap_read(st->regmap, AD74115_ADC_CONFIG_REG, &i); in ad74115_get_adc_rate()
800 reinit_completion(&st->adc_data_completion); in _ad74115_get_adc_code()
810 if (st->irq) { in _ad74115_get_adc_code()
811 ret = wait_for_completion_timeout(&st->adc_data_completion, in _ad74115_get_adc_code()
814 return -ETIMEDOUT; in _ad74115_get_adc_code()
825 ret = regmap_read_poll_timeout(st->regmap, AD74115_LIVE_STATUS_REG, in _ad74115_get_adc_code()
835 * Although the datasheet mentions that the bit will auto-clear in _ad74115_get_adc_code()
839 ret = regmap_write_bits(st->regmap, AD74115_LIVE_STATUS_REG, in _ad74115_get_adc_code()
846 ret = regmap_read(st->regmap, ad74115_adc_ch_data_regs_tbl[channel], &uval); in _ad74115_get_adc_code()
873 mutex_lock(&st->lock); in ad74115_get_adc_code()
875 mutex_unlock(&st->lock); in ad74115_get_adc_code()
885 code--; in ad74115_adc_code_to_resistance()
888 *val2 = AD74115_ADC_CODE_MAX - code; in ad74115_adc_code_to_resistance()
897 return -EINVAL; in ad74115_set_dac_code()
901 return -EINVAL; in ad74115_set_dac_code()
903 return regmap_update_bits(st->regmap, AD74115_DIN_CONFIG2_REG, in ad74115_set_dac_code()
909 return -EINVAL; in ad74115_set_dac_code()
911 return regmap_write(st->regmap, AD74115_DAC_CODE_REG, val); in ad74115_set_dac_code()
921 return -EINVAL; in ad74115_get_dac_code()
923 ret = regmap_read(st->regmap, AD74115_DAC_ACTIVE_REG, &uval); in ad74115_get_dac_code()
943 return regmap_update_bits(st->regmap, AD74115_ADC_CONFIG_REG, in ad74115_set_adc_rate()
947 return regmap_update_bits(st->regmap, AD74115_ADC_CONFIG_REG, in ad74115_set_adc_rate()
957 ret = regmap_read(st->regmap, AD74115_OUTPUT_CONFIG_REG, &tmp); in ad74115_get_dac_rate()
972 return -EINVAL; in ad74115_get_dac_rate()
1000 return regmap_update_bits(st->regmap, AD74115_OUTPUT_CONFIG_REG, mask, tmp); in ad74115_set_dac_rate()
1007 if (chan->channel == AD74115_DAC_CH_MAIN) { in ad74115_get_dac_scale()
1008 if (chan->type == IIO_VOLTAGE) { in ad74115_get_dac_scale()
1011 if (st->dac_bipolar) in ad74115_get_dac_scale()
1020 if (st->din_threshold_mode == AD74115_DIN_THRESHOLD_MODE_AVDD) { in ad74115_get_dac_scale()
1021 *val = 196 * st->avdd_mv; in ad74115_get_dac_scale()
1035 if (chan->channel == AD74115_DAC_CH_MAIN) { in ad74115_get_dac_offset()
1036 if (chan->type == IIO_VOLTAGE && st->dac_bipolar) in ad74115_get_dac_offset()
1037 *val = -AD74115_DAC_CODE_HALF; in ad74115_get_dac_offset()
1041 if (st->din_threshold_mode == AD74115_DIN_THRESHOLD_MODE_AVDD) in ad74115_get_dac_offset()
1042 *val = -48; in ad74115_get_dac_offset()
1044 *val = -38; in ad74115_get_dac_offset()
1055 ret = regmap_read(st->regmap, AD74115_ADC_CONFIG_REG, val); in ad74115_get_adc_range()
1089 ret = ad74115_get_adc_range(st, chan->channel, &range); in ad74115_get_adc_scale()
1093 if (chan->type == IIO_RESISTANCE) in ad74115_get_adc_scale()
1099 if (chan->type == IIO_CURRENT) in ad74115_get_adc_scale()
1115 *val -= AD74115_ADC_CODE_HALF; in ad74115_get_adc_resistance_offset()
1119 if (!st->rtd_mode_4_wire) { in ad74115_get_adc_resistance_offset()
1120 /* Add 0.2 Ohm to the final result for 3-wire RTD. */ in ad74115_get_adc_resistance_offset()
1143 ret = ad74115_get_adc_range(st, chan->channel, &range); in ad74115_get_adc_offset()
1147 if (chan->type == IIO_RESISTANCE) in ad74115_get_adc_offset()
1151 *val = -AD74115_ADC_CODE_HALF; in ad74115_get_adc_offset()
1153 *val = -AD74115_ADC_CODE_MAX; in ad74115_get_adc_offset()
1169 if (chan->output) in ad74115_read_raw()
1170 return ad74115_get_dac_code(st, chan->channel, val); in ad74115_read_raw()
1172 return ad74115_get_adc_code(indio_dev, chan->channel, val); in ad74115_read_raw()
1174 ret = ad74115_get_adc_code(indio_dev, chan->channel, val); in ad74115_read_raw()
1180 if (chan->output) in ad74115_read_raw()
1185 if (chan->output) in ad74115_read_raw()
1190 if (chan->output) in ad74115_read_raw()
1193 return ad74115_get_adc_rate(st, chan->channel, val); in ad74115_read_raw()
1195 return -EINVAL; in ad74115_read_raw()
1207 if (!chan->output) in ad74115_write_raw()
1208 return -EINVAL; in ad74115_write_raw()
1210 return ad74115_set_dac_code(st, chan->channel, val); in ad74115_write_raw()
1212 if (chan->output) in ad74115_write_raw()
1215 return ad74115_set_adc_rate(st, chan->channel, val); in ad74115_write_raw()
1217 return -EINVAL; in ad74115_write_raw()
1227 if (chan->output) { in ad74115_read_avail()
1239 return -EINVAL; in ad74115_read_avail()
1249 return regmap_read(st->regmap, reg, readval); in ad74115_reg_access()
1251 return regmap_write(st->regmap, reg, writeval); in ad74115_reg_access()
1268 .scan_index = -1, \
1377 .name = "adi,gpio" __stringify(i) "-mode", \
1392 AD74115_FW_PROP_BOOL("adi,digital-input-threshold-mode-fixed",
1396 AD74115_FW_PROP_BOOL("adi,dac-bipolar", AD74115_OUTPUT_CONFIG_REG, BIT(7));
1399 AD74115_FW_PROP("adi,ch-func", AD74115_CH_FUNC_MAX,
1403 AD74115_FW_PROP_BOOL("adi,4-wire-rtd", AD74115_RTD3W4W_CONFIG_REG, BIT(3));
1406 AD74115_FW_PROP_BOOL("adi,digital-input-sink-range-high",
1410 AD74115_FW_PROP_TBL("adi,ext2-burnout-current-nanoamp",
1415 AD74115_FW_PROP_TBL("adi,ext1-burnout-current-nanoamp",
1420 AD74115_FW_PROP_TBL("adi,viout-burnout-current-nanoamp",
1425 AD74115_FW_PROP("adi,conv2-mux", 3,
1428 AD74115_FW_PROP_BOOL_NEG("adi,sense-agnd-buffer-low-power",
1430 AD74115_FW_PROP_BOOL_NEG("adi,lf-buffer-low-power",
1432 AD74115_FW_PROP_BOOL_NEG("adi,hf-buffer-low-power",
1434 AD74115_FW_PROP_BOOL_NEG("adi,ext2-buffer-low-power",
1436 AD74115_FW_PROP_BOOL_NEG("adi,ext1-buffer-low-power",
1439 AD74115_FW_PROP_BOOL("adi,comparator-invert",
1441 AD74115_FW_PROP_BOOL("adi,digital-input-debounce-mode-counter-reset",
1444 AD74115_FW_PROP_BOOL("adi,digital-input-unbuffered",
1446 AD74115_FW_PROP_BOOL("adi,digital-input-short-circuit-detection",
1448 AD74115_FW_PROP_BOOL("adi,digital-input-open-circuit-detection",
1451 AD74115_FW_PROP_BOOL("adi,dac-current-limit-low",
1454 AD74115_FW_PROP_BOOL("adi,3-wire-rtd-excitation-swap",
1456 AD74115_FW_PROP_TBL("adi,rtd-excitation-current-microamp",
1460 AD74115_FW_PROP_BOOL("adi,ext2-burnout-current-polarity-sourcing",
1462 AD74115_FW_PROP_BOOL("adi,ext1-burnout-current-polarity-sourcing",
1464 AD74115_FW_PROP_BOOL("adi,viout-burnout-current-polarity-sourcing",
1467 AD74115_FW_PROP_BOOL("adi,charge-pump",
1474 struct device *dev = &st->spi->dev; in ad74115_apply_fw_prop()
1478 if (prop->is_boolean) { in ad74115_apply_fw_prop()
1479 val = device_property_read_bool(dev, prop->name); in ad74115_apply_fw_prop()
1481 ret = device_property_read_u32(dev, prop->name, &val); in ad74115_apply_fw_prop()
1482 if (ret && prop->lookup_tbl) in ad74115_apply_fw_prop()
1483 val = prop->lookup_tbl[0]; in ad74115_apply_fw_prop()
1488 if (prop->negate) in ad74115_apply_fw_prop()
1491 if (prop->lookup_tbl) in ad74115_apply_fw_prop()
1492 ret = _ad74115_find_tbl_index(prop->lookup_tbl, in ad74115_apply_fw_prop()
1493 prop->lookup_tbl_len, val, &val); in ad74115_apply_fw_prop()
1494 else if (prop->max && val > prop->max) in ad74115_apply_fw_prop()
1495 ret = -EINVAL; in ad74115_apply_fw_prop()
1500 return dev_err_probe(dev, -EINVAL, in ad74115_apply_fw_prop()
1502 val, prop->name); in ad74115_apply_fw_prop()
1504 WARN(!prop->mask, "Prop %s mask is empty\n", prop->name); in ad74115_apply_fw_prop()
1506 val = (val << __ffs(prop->mask)) & prop->mask; in ad74115_apply_fw_prop()
1508 return regmap_update_bits(st->regmap, prop->reg, prop->mask, val); in ad74115_apply_fw_prop()
1514 const char *prop_name = "adi,conv2-range-microvolt"; in ad74115_setup_adc_conv2_range()
1519 struct device *dev = &st->spi->dev; in ad74115_setup_adc_conv2_range()
1530 return dev_err_probe(dev, -EINVAL, in ad74115_setup_adc_conv2_range()
1534 return regmap_update_bits(st->regmap, AD74115_ADC_CONFIG_REG, in ad74115_setup_adc_conv2_range()
1542 struct device *dev = &st->spi->dev; in ad74115_setup_iio_channels()
1546 indio_dev->num_channels, GFP_KERNEL); in ad74115_setup_iio_channels()
1548 return -ENOMEM; in ad74115_setup_iio_channels()
1550 indio_dev->channels = channels; in ad74115_setup_iio_channels()
1552 memcpy(channels, ad74115_channels_map[st->ch_func].channels, in ad74115_setup_iio_channels()
1553 sizeof(*channels) * ad74115_channels_map[st->ch_func].num_channels); in ad74115_setup_iio_channels()
1556 channels[0].type == IIO_VOLTAGE && !st->dac_hart_slew) { in ad74115_setup_iio_channels()
1566 struct device *dev = &st->spi->dev; in ad74115_setup_gpio_chip()
1568 if (!st->gpio_valid_mask) in ad74115_setup_gpio_chip()
1571 st->gc = (struct gpio_chip) { in ad74115_setup_gpio_chip()
1574 .base = -1, in ad74115_setup_gpio_chip()
1586 return devm_gpiochip_add_data(dev, &st->gc, st); in ad74115_setup_gpio_chip()
1591 struct device *dev = &st->spi->dev; in ad74115_setup_comp_gpio_chip()
1595 ret = regmap_read(st->regmap, AD74115_DIN_CONFIG1_REG, &val); in ad74115_setup_comp_gpio_chip()
1602 st->comp_gc = (struct gpio_chip) { in ad74115_setup_comp_gpio_chip()
1605 .base = -1, in ad74115_setup_comp_gpio_chip()
1614 return devm_gpiochip_add_data(dev, &st->comp_gc, st); in ad74115_setup_comp_gpio_chip()
1620 struct device *dev = &st->spi->dev; in ad74115_setup()
1629 indio_dev->num_channels += ad74115_channels_map[val].num_channels; in ad74115_setup()
1630 st->ch_func = val; in ad74115_setup()
1636 val = device_property_read_bool(dev, "adi,dac-hart-slew"); in ad74115_setup()
1638 st->dac_hart_slew = val; in ad74115_setup()
1640 ret = regmap_update_bits(st->regmap, AD74115_OUTPUT_CONFIG_REG, in ad74115_setup()
1653 ret = device_property_read_u32(dev, "adi,digital-input-sink-microamp", &val); in ad74115_setup()
1663 ret = regmap_update_bits(st->regmap, AD74115_DIN_CONFIG1_REG, in ad74115_setup()
1674 if (val == AD74115_DIN_THRESHOLD_MODE_AVDD && !st->avdd_mv) in ad74115_setup()
1675 return dev_err_probe(dev, -EINVAL, in ad74115_setup()
1678 st->din_threshold_mode = val; in ad74115_setup()
1684 st->dac_bipolar = val; in ad74115_setup()
1690 st->rtd_mode_4_wire = val; in ad74115_setup()
1697 ret = regmap_update_bits(st->regmap, AD74115_BURNOUT_CONFIG_REG, in ad74115_setup()
1709 ret = regmap_update_bits(st->regmap, AD74115_BURNOUT_CONFIG_REG, in ad74115_setup()
1721 ret = regmap_update_bits(st->regmap, AD74115_BURNOUT_CONFIG_REG, in ad74115_setup()
1734 st->gpio_valid_mask |= BIT(i); in ad74115_setup()
1756 struct device *dev = &st->spi->dev; in ad74115_reset()
1770 ret = regmap_write(st->regmap, AD74115_CMD_KEY_REG, in ad74115_reset()
1775 ret = regmap_write(st->regmap, AD74115_CMD_KEY_REG, in ad74115_reset()
1789 struct device *dev = &st->spi->dev; in ad74115_setup_trigger()
1792 st->irq = fwnode_irq_get_byname(dev_fwnode(dev), "adc_rdy"); in ad74115_setup_trigger()
1794 if (st->irq == -EPROBE_DEFER) in ad74115_setup_trigger()
1795 return -EPROBE_DEFER; in ad74115_setup_trigger()
1797 if (st->irq < 0) { in ad74115_setup_trigger()
1798 st->irq = 0; in ad74115_setup_trigger()
1802 ret = devm_request_irq(dev, st->irq, ad74115_adc_data_interrupt, in ad74115_setup_trigger()
1807 st->trig = devm_iio_trigger_alloc(dev, "%s-dev%d", AD74115_NAME, in ad74115_setup_trigger()
1809 if (!st->trig) in ad74115_setup_trigger()
1810 return -ENOMEM; in ad74115_setup_trigger()
1812 st->trig->ops = &ad74115_trigger_ops; in ad74115_setup_trigger()
1813 iio_trigger_set_drvdata(st->trig, st); in ad74115_setup_trigger()
1815 ret = devm_iio_trigger_register(dev, st->trig); in ad74115_setup_trigger()
1819 indio_dev->trig = iio_trigger_get(st->trig); in ad74115_setup_trigger()
1829 struct device *dev = &spi->dev; in ad74115_probe()
1836 return -ENOMEM; in ad74115_probe()
1840 st->spi = spi; in ad74115_probe()
1841 mutex_init(&st->lock); in ad74115_probe()
1842 init_completion(&st->adc_data_completion); in ad74115_probe()
1844 indio_dev->name = AD74115_NAME; in ad74115_probe()
1845 indio_dev->modes = INDIO_DIRECT_MODE; in ad74115_probe()
1846 indio_dev->info = &ad74115_info; in ad74115_probe()
1859 st->avdd_mv = ret / 1000; in ad74115_probe()
1867 st->regmap = devm_regmap_init(dev, NULL, st, &ad74115_regmap_config); in ad74115_probe()
1868 if (IS_ERR(st->regmap)) in ad74115_probe()
1869 return PTR_ERR(st->regmap); in ad74115_probe()