Lines Matching +full:viout +full:- +full:burnout +full:- +full:current +full:- +full:polarity +full:- +full:sourcing

1 // SPDX-License-Identifier: GPL-2.0
205 * Synchronize consecutive operations when doing a one-shot
387 [AD74115_ADC_RANGE_12V_BIPOLAR] = { -12000000, 12000000 },
388 [AD74115_ADC_RANGE_2_5V_BIPOLAR] = { -2500000, 2500000 },
389 [AD74115_ADC_RANGE_2_5V_NEG] = { -2500000, 0 },
392 [AD74115_ADC_RANGE_104MV_BIPOLAR] = { -104000, 104000 },
407 return -EINVAL; in _ad74115_find_tbl_index()
429 ad74115_format_reg_write(reg, val, st->reg_tx_buf); in ad74115_reg_write()
431 return spi_write(st->spi, st->reg_tx_buf, AD74115_FRAME_SIZE); in ad74115_reg_write()
436 struct device *dev = &st->spi->dev; in ad74115_crc_check()
442 return -EINVAL; in ad74115_crc_check()
453 .tx_buf = st->reg_tx_buf, in ad74115_reg_read()
454 .len = sizeof(st->reg_tx_buf), in ad74115_reg_read()
458 .rx_buf = st->reg_rx_buf, in ad74115_reg_read()
459 .len = sizeof(st->reg_rx_buf), in ad74115_reg_read()
464 ad74115_format_reg_write(AD74115_READ_SELECT_REG, reg, st->reg_tx_buf); in ad74115_reg_read()
466 ret = spi_sync_transfer(st->spi, reg_read_xfer, ARRAY_SIZE(reg_read_xfer)); in ad74115_reg_read()
470 ret = ad74115_crc_check(st, st->reg_rx_buf); in ad74115_reg_read()
474 *val = get_unaligned_be16(&st->reg_rx_buf[1]); in ad74115_reg_read()
489 return regmap_update_bits(st->regmap, AD74115_GPIO_CONFIG_X_REG(offset), in ad74115_gpio_config_set()
500 *valid_mask = st->gpio_valid_mask; in ad74115_gpio_init_valid_mask()
511 ret = regmap_read(st->regmap, AD74115_GPIO_CONFIG_X_REG(offset), &val); in ad74115_gpio_get_direction()
539 ret = regmap_read(st->regmap, AD74115_GPIO_CONFIG_X_REG(offset), &val); in ad74115_gpio_get()
549 struct device *dev = &st->spi->dev; in ad74115_gpio_set()
552 ret = regmap_update_bits(st->regmap, AD74115_GPIO_CONFIG_X_REG(offset), in ad74115_gpio_set()
570 i = len - 1; in ad74115_set_comp_debounce()
572 return regmap_update_bits(st->regmap, AD74115_DIN_CONFIG1_REG, in ad74115_set_comp_debounce()
595 return -ENOTSUPP; in ad74115_comp_gpio_set_config()
605 ret = regmap_read(st->regmap, AD74115_DIN_COMP_OUT_REG, &val); in ad74115_comp_gpio_get()
615 struct iio_dev *indio_dev = pf->indio_dev; in ad74115_trigger_handler()
619 ret = spi_sync(st->spi, &st->adc_samples_msg); in ad74115_trigger_handler()
623 iio_push_to_buffers(indio_dev, st->adc_samples_rx_buf); in ad74115_trigger_handler()
626 iio_trigger_notify_done(indio_dev->trig); in ad74115_trigger_handler()
637 iio_trigger_poll(st->trig); in ad74115_adc_data_interrupt()
639 complete(&st->adc_data_completion); in ad74115_adc_data_interrupt()
649 return regmap_update_bits(st->regmap, AD74115_ADC_CONV_CTRL_REG, mask, in ad74115_set_adc_ch_en()
656 return regmap_update_bits(st->regmap, AD74115_ADC_CONV_CTRL_REG, in ad74115_set_adc_conv_seq()
665 struct spi_transfer *xfer = st->adc_samples_xfer; in ad74115_update_scan_mode()
666 u8 *rx_buf = st->adc_samples_rx_buf; in ad74115_update_scan_mode()
667 u8 *tx_buf = st->adc_samples_tx_buf; in ad74115_update_scan_mode()
671 mutex_lock(&st->lock); in ad74115_update_scan_mode()
673 spi_message_init(&st->adc_samples_msg); in ad74115_update_scan_mode()
698 if (xfer == st->adc_samples_xfer) in ad74115_update_scan_mode()
699 xfer->rx_buf = NULL; in ad74115_update_scan_mode()
701 xfer->rx_buf = rx_buf; in ad74115_update_scan_mode()
703 xfer->tx_buf = tx_buf; in ad74115_update_scan_mode()
704 xfer->len = AD74115_FRAME_SIZE; in ad74115_update_scan_mode()
705 xfer->cs_change = 1; in ad74115_update_scan_mode()
710 spi_message_add_tail(xfer, &st->adc_samples_msg); in ad74115_update_scan_mode()
713 if (xfer != st->adc_samples_xfer) in ad74115_update_scan_mode()
718 xfer->rx_buf = rx_buf; in ad74115_update_scan_mode()
719 xfer->tx_buf = NULL; in ad74115_update_scan_mode()
720 xfer->len = AD74115_FRAME_SIZE; in ad74115_update_scan_mode()
721 xfer->cs_change = 0; in ad74115_update_scan_mode()
723 spi_message_add_tail(xfer, &st->adc_samples_msg); in ad74115_update_scan_mode()
726 mutex_unlock(&st->lock); in ad74115_update_scan_mode()
744 mutex_lock(&st->lock); in ad74115_buffer_predisable()
761 mutex_unlock(&st->lock); in ad74115_buffer_predisable()
781 ret = regmap_read(st->regmap, AD74115_ADC_CONFIG_REG, &i); in ad74115_get_adc_rate()
801 reinit_completion(&st->adc_data_completion); in _ad74115_get_adc_code()
811 if (st->irq) { in _ad74115_get_adc_code()
812 ret = wait_for_completion_timeout(&st->adc_data_completion, in _ad74115_get_adc_code()
815 return -ETIMEDOUT; in _ad74115_get_adc_code()
826 ret = regmap_read_poll_timeout(st->regmap, AD74115_LIVE_STATUS_REG, in _ad74115_get_adc_code()
836 * Although the datasheet mentions that the bit will auto-clear in _ad74115_get_adc_code()
840 ret = regmap_write_bits(st->regmap, AD74115_LIVE_STATUS_REG, in _ad74115_get_adc_code()
847 ret = regmap_read(st->regmap, ad74115_adc_ch_data_regs_tbl[channel], &uval); in _ad74115_get_adc_code()
874 mutex_lock(&st->lock); in ad74115_get_adc_code()
876 mutex_unlock(&st->lock); in ad74115_get_adc_code()
886 code--; in ad74115_adc_code_to_resistance()
889 *val2 = AD74115_ADC_CODE_MAX - code; in ad74115_adc_code_to_resistance()
898 return -EINVAL; in ad74115_set_dac_code()
902 return -EINVAL; in ad74115_set_dac_code()
904 return regmap_update_bits(st->regmap, AD74115_DIN_CONFIG2_REG, in ad74115_set_dac_code()
910 return -EINVAL; in ad74115_set_dac_code()
912 return regmap_write(st->regmap, AD74115_DAC_CODE_REG, val); in ad74115_set_dac_code()
922 return -EINVAL; in ad74115_get_dac_code()
924 ret = regmap_read(st->regmap, AD74115_DAC_ACTIVE_REG, &uval); in ad74115_get_dac_code()
944 return regmap_update_bits(st->regmap, AD74115_ADC_CONFIG_REG, in ad74115_set_adc_rate()
948 return regmap_update_bits(st->regmap, AD74115_ADC_CONFIG_REG, in ad74115_set_adc_rate()
958 ret = regmap_read(st->regmap, AD74115_OUTPUT_CONFIG_REG, &tmp); in ad74115_get_dac_rate()
973 return -EINVAL; in ad74115_get_dac_rate()
1001 return regmap_update_bits(st->regmap, AD74115_OUTPUT_CONFIG_REG, mask, tmp); in ad74115_set_dac_rate()
1008 if (chan->channel == AD74115_DAC_CH_MAIN) { in ad74115_get_dac_scale()
1009 if (chan->type == IIO_VOLTAGE) { in ad74115_get_dac_scale()
1012 if (st->dac_bipolar) in ad74115_get_dac_scale()
1021 if (st->din_threshold_mode == AD74115_DIN_THRESHOLD_MODE_AVDD) { in ad74115_get_dac_scale()
1022 *val = 196 * st->avdd_mv; in ad74115_get_dac_scale()
1036 if (chan->channel == AD74115_DAC_CH_MAIN) { in ad74115_get_dac_offset()
1037 if (chan->type == IIO_VOLTAGE && st->dac_bipolar) in ad74115_get_dac_offset()
1038 *val = -AD74115_DAC_CODE_HALF; in ad74115_get_dac_offset()
1042 if (st->din_threshold_mode == AD74115_DIN_THRESHOLD_MODE_AVDD) in ad74115_get_dac_offset()
1043 *val = -48; in ad74115_get_dac_offset()
1045 *val = -38; in ad74115_get_dac_offset()
1056 ret = regmap_read(st->regmap, AD74115_ADC_CONFIG_REG, val); in ad74115_get_adc_range()
1090 ret = ad74115_get_adc_range(st, chan->channel, &range); in ad74115_get_adc_scale()
1094 if (chan->type == IIO_RESISTANCE) in ad74115_get_adc_scale()
1100 if (chan->type == IIO_CURRENT) in ad74115_get_adc_scale()
1116 *val -= AD74115_ADC_CODE_HALF; in ad74115_get_adc_resistance_offset()
1120 if (!st->rtd_mode_4_wire) { in ad74115_get_adc_resistance_offset()
1121 /* Add 0.2 Ohm to the final result for 3-wire RTD. */ in ad74115_get_adc_resistance_offset()
1144 ret = ad74115_get_adc_range(st, chan->channel, &range); in ad74115_get_adc_offset()
1148 if (chan->type == IIO_RESISTANCE) in ad74115_get_adc_offset()
1152 *val = -AD74115_ADC_CODE_HALF; in ad74115_get_adc_offset()
1154 *val = -AD74115_ADC_CODE_MAX; in ad74115_get_adc_offset()
1170 if (chan->output) in ad74115_read_raw()
1171 return ad74115_get_dac_code(st, chan->channel, val); in ad74115_read_raw()
1173 return ad74115_get_adc_code(indio_dev, chan->channel, val); in ad74115_read_raw()
1175 ret = ad74115_get_adc_code(indio_dev, chan->channel, val); in ad74115_read_raw()
1181 if (chan->output) in ad74115_read_raw()
1186 if (chan->output) in ad74115_read_raw()
1191 if (chan->output) in ad74115_read_raw()
1194 return ad74115_get_adc_rate(st, chan->channel, val); in ad74115_read_raw()
1196 return -EINVAL; in ad74115_read_raw()
1208 if (!chan->output) in ad74115_write_raw()
1209 return -EINVAL; in ad74115_write_raw()
1211 return ad74115_set_dac_code(st, chan->channel, val); in ad74115_write_raw()
1213 if (chan->output) in ad74115_write_raw()
1216 return ad74115_set_adc_rate(st, chan->channel, val); in ad74115_write_raw()
1218 return -EINVAL; in ad74115_write_raw()
1228 if (chan->output) { in ad74115_read_avail()
1240 return -EINVAL; in ad74115_read_avail()
1250 return regmap_read(st->regmap, reg, readval); in ad74115_reg_access()
1252 return regmap_write(st->regmap, reg, writeval); in ad74115_reg_access()
1269 .scan_index = -1, \
1378 .name = "adi,gpio" __stringify(i) "-mode", \
1393 AD74115_FW_PROP_BOOL("adi,digital-input-threshold-mode-fixed",
1397 AD74115_FW_PROP_BOOL("adi,dac-bipolar", AD74115_OUTPUT_CONFIG_REG, BIT(7));
1400 AD74115_FW_PROP("adi,ch-func", AD74115_CH_FUNC_MAX,
1404 AD74115_FW_PROP_BOOL("adi,4-wire-rtd", AD74115_RTD3W4W_CONFIG_REG, BIT(3));
1407 AD74115_FW_PROP_BOOL("adi,digital-input-sink-range-high",
1411 AD74115_FW_PROP_TBL("adi,ext2-burnout-current-nanoamp",
1416 AD74115_FW_PROP_TBL("adi,ext1-burnout-current-nanoamp",
1421 AD74115_FW_PROP_TBL("adi,viout-burnout-current-nanoamp",
1426 AD74115_FW_PROP("adi,conv2-mux", 3,
1429 AD74115_FW_PROP_BOOL_NEG("adi,sense-agnd-buffer-low-power",
1431 AD74115_FW_PROP_BOOL_NEG("adi,lf-buffer-low-power",
1433 AD74115_FW_PROP_BOOL_NEG("adi,hf-buffer-low-power",
1435 AD74115_FW_PROP_BOOL_NEG("adi,ext2-buffer-low-power",
1437 AD74115_FW_PROP_BOOL_NEG("adi,ext1-buffer-low-power",
1440 AD74115_FW_PROP_BOOL("adi,comparator-invert",
1442 AD74115_FW_PROP_BOOL("adi,digital-input-debounce-mode-counter-reset",
1445 AD74115_FW_PROP_BOOL("adi,digital-input-unbuffered",
1447 AD74115_FW_PROP_BOOL("adi,digital-input-short-circuit-detection",
1449 AD74115_FW_PROP_BOOL("adi,digital-input-open-circuit-detection",
1452 AD74115_FW_PROP_BOOL("adi,dac-current-limit-low",
1455 AD74115_FW_PROP_BOOL("adi,3-wire-rtd-excitation-swap",
1457 AD74115_FW_PROP_TBL("adi,rtd-excitation-current-microamp",
1461 AD74115_FW_PROP_BOOL("adi,ext2-burnout-current-polarity-sourcing",
1463 AD74115_FW_PROP_BOOL("adi,ext1-burnout-current-polarity-sourcing",
1465 AD74115_FW_PROP_BOOL("adi,viout-burnout-current-polarity-sourcing",
1468 AD74115_FW_PROP_BOOL("adi,charge-pump",
1475 struct device *dev = &st->spi->dev; in ad74115_apply_fw_prop()
1479 if (prop->is_boolean) { in ad74115_apply_fw_prop()
1480 val = device_property_read_bool(dev, prop->name); in ad74115_apply_fw_prop()
1482 ret = device_property_read_u32(dev, prop->name, &val); in ad74115_apply_fw_prop()
1483 if (ret && prop->lookup_tbl) in ad74115_apply_fw_prop()
1484 val = prop->lookup_tbl[0]; in ad74115_apply_fw_prop()
1489 if (prop->negate) in ad74115_apply_fw_prop()
1492 if (prop->lookup_tbl) in ad74115_apply_fw_prop()
1493 ret = _ad74115_find_tbl_index(prop->lookup_tbl, in ad74115_apply_fw_prop()
1494 prop->lookup_tbl_len, val, &val); in ad74115_apply_fw_prop()
1495 else if (prop->max && val > prop->max) in ad74115_apply_fw_prop()
1496 ret = -EINVAL; in ad74115_apply_fw_prop()
1501 return dev_err_probe(dev, -EINVAL, in ad74115_apply_fw_prop()
1503 val, prop->name); in ad74115_apply_fw_prop()
1505 WARN(!prop->mask, "Prop %s mask is empty\n", prop->name); in ad74115_apply_fw_prop()
1507 val = (val << __ffs(prop->mask)) & prop->mask; in ad74115_apply_fw_prop()
1509 return regmap_update_bits(st->regmap, prop->reg, prop->mask, val); in ad74115_apply_fw_prop()
1515 const char *prop_name = "adi,conv2-range-microvolt"; in ad74115_setup_adc_conv2_range()
1520 struct device *dev = &st->spi->dev; in ad74115_setup_adc_conv2_range()
1531 return dev_err_probe(dev, -EINVAL, in ad74115_setup_adc_conv2_range()
1535 return regmap_update_bits(st->regmap, AD74115_ADC_CONFIG_REG, in ad74115_setup_adc_conv2_range()
1543 struct device *dev = &st->spi->dev; in ad74115_setup_iio_channels()
1547 indio_dev->num_channels, GFP_KERNEL); in ad74115_setup_iio_channels()
1549 return -ENOMEM; in ad74115_setup_iio_channels()
1551 indio_dev->channels = channels; in ad74115_setup_iio_channels()
1553 memcpy(channels, ad74115_channels_map[st->ch_func].channels, in ad74115_setup_iio_channels()
1554 sizeof(*channels) * ad74115_channels_map[st->ch_func].num_channels); in ad74115_setup_iio_channels()
1557 channels[0].type == IIO_VOLTAGE && !st->dac_hart_slew) { in ad74115_setup_iio_channels()
1567 struct device *dev = &st->spi->dev; in ad74115_setup_gpio_chip()
1569 if (!st->gpio_valid_mask) in ad74115_setup_gpio_chip()
1572 st->gc = (struct gpio_chip) { in ad74115_setup_gpio_chip()
1575 .base = -1, in ad74115_setup_gpio_chip()
1587 return devm_gpiochip_add_data(dev, &st->gc, st); in ad74115_setup_gpio_chip()
1592 struct device *dev = &st->spi->dev; in ad74115_setup_comp_gpio_chip()
1596 ret = regmap_read(st->regmap, AD74115_DIN_CONFIG1_REG, &val); in ad74115_setup_comp_gpio_chip()
1603 st->comp_gc = (struct gpio_chip) { in ad74115_setup_comp_gpio_chip()
1606 .base = -1, in ad74115_setup_comp_gpio_chip()
1615 return devm_gpiochip_add_data(dev, &st->comp_gc, st); in ad74115_setup_comp_gpio_chip()
1621 struct device *dev = &st->spi->dev; in ad74115_setup()
1630 indio_dev->num_channels += ad74115_channels_map[val].num_channels; in ad74115_setup()
1631 st->ch_func = val; in ad74115_setup()
1637 val = device_property_read_bool(dev, "adi,dac-hart-slew"); in ad74115_setup()
1639 st->dac_hart_slew = val; in ad74115_setup()
1641 ret = regmap_update_bits(st->regmap, AD74115_OUTPUT_CONFIG_REG, in ad74115_setup()
1654 ret = device_property_read_u32(dev, "adi,digital-input-sink-microamp", &val); in ad74115_setup()
1664 ret = regmap_update_bits(st->regmap, AD74115_DIN_CONFIG1_REG, in ad74115_setup()
1676 ret = regulator_get_voltage(st->avdd); in ad74115_setup()
1680 st->avdd_mv = ret / 1000; in ad74115_setup()
1683 st->din_threshold_mode = val; in ad74115_setup()
1689 st->dac_bipolar = val; in ad74115_setup()
1695 st->rtd_mode_4_wire = val; in ad74115_setup()
1702 ret = regmap_update_bits(st->regmap, AD74115_BURNOUT_CONFIG_REG, in ad74115_setup()
1714 ret = regmap_update_bits(st->regmap, AD74115_BURNOUT_CONFIG_REG, in ad74115_setup()
1726 ret = regmap_update_bits(st->regmap, AD74115_BURNOUT_CONFIG_REG, in ad74115_setup()
1739 st->gpio_valid_mask |= BIT(i); in ad74115_setup()
1761 struct device *dev = &st->spi->dev; in ad74115_reset()
1775 ret = regmap_write(st->regmap, AD74115_CMD_KEY_REG, in ad74115_reset()
1780 ret = regmap_write(st->regmap, AD74115_CMD_KEY_REG, in ad74115_reset()
1799 struct device *dev = &st->spi->dev; in ad74115_setup_trigger()
1802 st->irq = fwnode_irq_get_byname(dev_fwnode(dev), "adc_rdy"); in ad74115_setup_trigger()
1804 if (st->irq == -EPROBE_DEFER) in ad74115_setup_trigger()
1805 return -EPROBE_DEFER; in ad74115_setup_trigger()
1807 if (st->irq < 0) { in ad74115_setup_trigger()
1808 st->irq = 0; in ad74115_setup_trigger()
1812 ret = devm_request_irq(dev, st->irq, ad74115_adc_data_interrupt, in ad74115_setup_trigger()
1817 st->trig = devm_iio_trigger_alloc(dev, "%s-dev%d", AD74115_NAME, in ad74115_setup_trigger()
1819 if (!st->trig) in ad74115_setup_trigger()
1820 return -ENOMEM; in ad74115_setup_trigger()
1822 st->trig->ops = &ad74115_trigger_ops; in ad74115_setup_trigger()
1823 iio_trigger_set_drvdata(st->trig, st); in ad74115_setup_trigger()
1825 ret = devm_iio_trigger_register(dev, st->trig); in ad74115_setup_trigger()
1829 indio_dev->trig = iio_trigger_get(st->trig); in ad74115_setup_trigger()
1839 struct device *dev = &spi->dev; in ad74115_probe()
1846 return -ENOMEM; in ad74115_probe()
1850 st->spi = spi; in ad74115_probe()
1851 mutex_init(&st->lock); in ad74115_probe()
1852 init_completion(&st->adc_data_completion); in ad74115_probe()
1854 indio_dev->name = AD74115_NAME; in ad74115_probe()
1855 indio_dev->modes = INDIO_DIRECT_MODE; in ad74115_probe()
1856 indio_dev->info = &ad74115_info; in ad74115_probe()
1858 st->avdd = devm_regulator_get(dev, "avdd"); in ad74115_probe()
1859 if (IS_ERR(st->avdd)) in ad74115_probe()
1860 return PTR_ERR(st->avdd); in ad74115_probe()
1862 ret = regulator_enable(st->avdd); in ad74115_probe()
1868 ret = devm_add_action_or_reset(dev, ad74115_regulator_disable, st->avdd); in ad74115_probe()
1877 st->regmap = devm_regmap_init(dev, NULL, st, &ad74115_regmap_config); in ad74115_probe()
1878 if (IS_ERR(st->regmap)) in ad74115_probe()
1879 return PTR_ERR(st->regmap); in ad74115_probe()