Lines Matching +full:vref +full:- +full:p

1 // SPDX-License-Identifier: GPL-2.0-only
103 #define AD3552R_REG_ADDR_CH_DAC_16B(ch) (0x2C - (1 - ch) * 2)
108 #define AD3552R_REG_ADDR_CH_INPUT_16B(ch) (0x36 - (1 - ch) * 2)
112 #define AD3552R_REG_ADDR_CH_DAC_24B(ch) (0x3D - (1 - ch) * 3)
117 #define AD3552R_REG_ADDR_CH_INPUT_24B(ch) (0x4B - (1 - ch) * 3)
134 /* Internal source with Vref I/O floating */
136 /* Internal source with Vref I/O at 2.5V */
138 /* External source with Vref I/O as input */
154 /* Range from -5 V to 5 V. Requires Rfb2x connection */
156 /* Range from -10 V to 10 V. Requires Rfb4x connection */
164 [AD3552R_CH_OUTPUT_RANGE_NEG_5__5V] = {-5000, 5000},
165 [AD3552R_CH_OUTPUT_RANGE_NEG_10__10V] = {-10000, 10000}
177 /* Range from -2.5 V to 7.5 V. Requires Rfb2x connection */
179 /* Range from -5 V to 5 V. Requires Rfb2x connection */
188 [AD3542R_CH_OUTPUT_RANGE_NEG_2P5__7P5V] = {-2500, 7500},
189 [AD3542R_CH_OUTPUT_RANGE_NEG_5__5V] = {-5000, 5000}
212 /* - Direct register values */
213 /* From 0-3 */
216 * 0 -> Internal Vref, vref_io pin floating (default)
217 * 1 -> Internal Vref, vref_io driven by internal vref
218 * 2 or 3 -> External Vref
233 * Over-rider the range selector in order to manually set the output
247 /* Channel select. When set allow Input -> DAC and Mask -> DAC */
259 u8 p; member
292 /* 0 -> reg addr, 1->ch0 mask, 2->ch1 mask */
348 return spi_write_then_read(dac->spi, buf, 1, data, len); in ad3552r_transfer()
351 return spi_write_then_read(dac->spi, buf, len + 1, NULL, 0); in ad3552r_transfer()
450 u8 ch = chan->channel; in ad3552r_read_raw()
454 mutex_lock(&dac->lock); in ad3552r_read_raw()
457 mutex_unlock(&dac->lock); in ad3552r_read_raw()
463 mutex_lock(&dac->lock); in ad3552r_read_raw()
466 mutex_unlock(&dac->lock); in ad3552r_read_raw()
473 *val = dac->ch_data[ch].scale_int; in ad3552r_read_raw()
474 *val2 = dac->ch_data[ch].scale_dec; in ad3552r_read_raw()
477 *val = dac->ch_data[ch].offset_int; in ad3552r_read_raw()
478 *val2 = dac->ch_data[ch].offset_dec; in ad3552r_read_raw()
481 return -EINVAL; in ad3552r_read_raw()
494 mutex_lock(&dac->lock); in ad3552r_write_raw()
498 AD3552R_REG_ADDR_CH_DAC_24B(chan->channel), in ad3552r_write_raw()
503 chan->channel, !val); in ad3552r_write_raw()
506 err = -EINVAL; in ad3552r_write_raw()
509 mutex_unlock(&dac->lock); in ad3552r_write_raw()
541 if (!dac->gpio_ldac) { in ad3552r_write_all_channels()
550 if (dac->gpio_ldac) in ad3552r_write_all_channels()
551 return ad3552r_trigger_hw_ldac(dac->gpio_ldac); in ad3552r_write_all_channels()
576 if (dac->gpio_ldac) in ad3552r_write_codes()
577 return ad3552r_trigger_hw_ldac(dac->gpio_ldac); in ad3552r_write_codes()
582 static irqreturn_t ad3552r_trigger_handler(int irq, void *p) in ad3552r_trigger_handler() argument
584 struct iio_poll_func *pf = p; in ad3552r_trigger_handler()
585 struct iio_dev *indio_dev = pf->indio_dev; in ad3552r_trigger_handler()
586 struct iio_buffer *buf = indio_dev->buffer; in ad3552r_trigger_handler()
597 mutex_lock(&dac->lock); in ad3552r_trigger_handler()
598 ad3552r_write_codes(dac, *indio_dev->active_scan_mask, buff); in ad3552r_trigger_handler()
599 mutex_unlock(&dac->lock); in ad3552r_trigger_handler()
601 iio_trigger_notify_done(indio_dev->trig); in ad3552r_trigger_handler()
622 return -ENODEV; in ad3552r_check_scratch_pad()
633 return -ENODEV; in ad3552r_check_scratch_pad()
648 err = ad3552r_read_reg(addr->dac, addr->addr, &val); in ad3552r_read_reg_wrapper()
661 dac->gpio_reset = devm_gpiod_get_optional(&dac->spi->dev, "reset", in ad3552r_reset()
663 if (IS_ERR(dac->gpio_reset)) in ad3552r_reset()
664 return dev_err_probe(&dac->spi->dev, PTR_ERR(dac->gpio_reset), in ad3552r_reset()
667 if (dac->gpio_reset) { in ad3552r_reset()
670 gpiod_set_value_cansleep(dac->gpio_reset, 1); in ad3552r_reset()
691 dev_err(&dac->spi->dev, "Error while resetting"); in ad3552r_reset()
702 dev_err(&dac->spi->dev, "Error while resetting"); in ad3552r_reset()
715 s64 vref, tmp, common, offset, gn, gp; in ad3552r_get_custom_range() local
719 * Vmax = 2.5 - [(GainP + Offset / 1024) * 2.5 * Rfb * 1.03] in ad3552r_get_custom_range()
722 vref = 2500; in ad3552r_get_custom_range()
724 common = 2575 * dac->ch_data[i].rfb; in ad3552r_get_custom_range()
725 offset = dac->ch_data[i].gain_offset; in ad3552r_get_custom_range()
727 gn = gains_scaling_table[dac->ch_data[i].n]; in ad3552r_get_custom_range()
730 *v_max = vref + tmp; in ad3552r_get_custom_range()
732 gp = gains_scaling_table[dac->ch_data[i].p]; in ad3552r_get_custom_range()
733 tmp = (1024 * gp - AD3552R_GAIN_SCALE * offset) * common; in ad3552r_get_custom_range()
735 *v_min = vref - tmp; in ad3552r_get_custom_range()
743 if (dac->ch_data[ch].range_override) { in ad3552r_calc_gain_and_offset()
747 idx = dac->ch_data[ch].range; in ad3552r_calc_gain_and_offset()
748 if (dac->chip_id == AD3542R_ID) { in ad3552r_calc_gain_and_offset()
767 span = v_max - v_min; in ad3552r_calc_gain_and_offset()
768 dac->ch_data[ch].scale_int = div_s64_rem(span, 65536, &rem); in ad3552r_calc_gain_and_offset()
770 dac->ch_data[ch].scale_dec = DIV_ROUND_CLOSEST((s64)rem * 1000000, in ad3552r_calc_gain_and_offset()
773 dac->ch_data[ch].offset_int = div_s64_rem(v_min * 65536, span, &rem); in ad3552r_calc_gain_and_offset()
775 dac->ch_data[ch].offset_dec = div_s64(tmp, span); in ad3552r_calc_gain_and_offset()
796 return -EINVAL; in ad3552r_find_range()
803 struct device *dev = &dac->spi->dev; in ad3552r_configure_custom_gain()
811 "custom-output-range-config"); in ad3552r_configure_custom_gain()
814 "mandatory custom-output-range-config property missing\n"); in ad3552r_configure_custom_gain()
815 return -EINVAL; in ad3552r_configure_custom_gain()
818 dac->ch_data[ch].range_override = 1; in ad3552r_configure_custom_gain()
821 err = fwnode_property_read_u32(gain_child, "adi,gain-scaling-p", &val); in ad3552r_configure_custom_gain()
823 dev_err(dev, "mandatory adi,gain-scaling-p property missing\n"); in ad3552r_configure_custom_gain()
827 dac->ch_data[ch].p = val; in ad3552r_configure_custom_gain()
829 err = fwnode_property_read_u32(gain_child, "adi,gain-scaling-n", &val); in ad3552r_configure_custom_gain()
831 dev_err(dev, "mandatory adi,gain-scaling-n property missing\n"); in ad3552r_configure_custom_gain()
835 dac->ch_data[ch].n = val; in ad3552r_configure_custom_gain()
837 err = fwnode_property_read_u32(gain_child, "adi,rfb-ohms", &val); in ad3552r_configure_custom_gain()
839 dev_err(dev, "mandatory adi,rfb-ohms property missing\n"); in ad3552r_configure_custom_gain()
842 dac->ch_data[ch].rfb = val; in ad3552r_configure_custom_gain()
844 err = fwnode_property_read_u32(gain_child, "adi,gain-offset", &val); in ad3552r_configure_custom_gain()
846 dev_err(dev, "mandatory adi,gain-offset property missing\n"); in ad3552r_configure_custom_gain()
849 dac->ch_data[ch].gain_offset = val; in ad3552r_configure_custom_gain()
882 struct device *dev = &dac->spi->dev; in ad3552r_configure_device()
884 struct regulator *vref; in ad3552r_configure_device() local
888 dac->gpio_ldac = devm_gpiod_get_optional(dev, "ldac", GPIOD_OUT_HIGH); in ad3552r_configure_device()
889 if (IS_ERR(dac->gpio_ldac)) in ad3552r_configure_device()
890 return dev_err_probe(dev, PTR_ERR(dac->gpio_ldac), in ad3552r_configure_device()
893 vref = devm_regulator_get_optional(dev, "vref"); in ad3552r_configure_device()
894 if (IS_ERR(vref)) { in ad3552r_configure_device()
895 if (PTR_ERR(vref) != -ENODEV) in ad3552r_configure_device()
896 return dev_err_probe(dev, PTR_ERR(vref), in ad3552r_configure_device()
897 "Error getting vref"); in ad3552r_configure_device()
899 if (device_property_read_bool(dev, "adi,vref-out-en")) in ad3552r_configure_device()
904 err = regulator_enable(vref); in ad3552r_configure_device()
906 dev_err(dev, "Failed to enable external vref supply\n"); in ad3552r_configure_device()
910 err = devm_add_action_or_reset(dev, ad3552r_reg_disable, vref); in ad3552r_configure_device()
912 regulator_disable(vref); in ad3552r_configure_device()
916 voltage = regulator_get_voltage(vref); in ad3552r_configure_device()
917 if (voltage > 2500000 + delta || voltage < 2500000 - delta) { in ad3552r_configure_device()
918 dev_warn(dev, "vref-supply must be 2.5V"); in ad3552r_configure_device()
919 return -EINVAL; in ad3552r_configure_device()
931 err = device_property_read_u32(dev, "adi,sdo-drive-strength", &val); in ad3552r_configure_device()
934 dev_err(dev, "adi,sdo-drive-strength must be less than 4\n"); in ad3552r_configure_device()
935 return -EINVAL; in ad3552r_configure_device()
946 dac->num_ch = device_get_child_node_count(dev); in ad3552r_configure_device()
947 if (!dac->num_ch) { in ad3552r_configure_device()
949 return -ENODEV; in ad3552r_configure_device()
961 err = -EINVAL; in ad3552r_configure_device()
965 if (fwnode_property_present(child, "adi,output-range-microvolt")) { in ad3552r_configure_device()
967 "adi,output-range-microvolt", in ad3552r_configure_device()
972 "adi,output-range-microvolt property could not be parsed\n"); in ad3552r_configure_device()
976 err = ad3552r_find_range(dac->chip_id, vals); in ad3552r_configure_device()
979 "Invalid adi,output-range-microvolt value\n"); in ad3552r_configure_device()
989 dac->ch_data[ch].range = val; in ad3552r_configure_device()
990 } else if (dac->chip_id == AD3542R_ID) { in ad3552r_configure_device()
992 "adi,output-range-microvolt is required for ad3542r\n"); in ad3552r_configure_device()
993 err = -EINVAL; in ad3552r_configure_device()
1002 dac->enabled_ch |= BIT(ch); in ad3552r_configure_device()
1008 dac->channels[cnt] = AD3552R_CH_DAC(ch); in ad3552r_configure_device()
1014 for_each_clear_bit(ch, &dac->enabled_ch, AD3552R_NUM_CH) { in ad3552r_configure_device()
1021 dac->num_ch = cnt; in ad3552r_configure_device()
1037 dev_err(&dac->spi->dev, "Reset failed\n"); in ad3552r_init()
1043 dev_err(&dac->spi->dev, "Scratch pad test failed\n"); in ad3552r_init()
1049 dev_err(&dac->spi->dev, "Fail read PRODUCT_ID_L\n"); in ad3552r_init()
1056 dev_err(&dac->spi->dev, "Fail read PRODUCT_ID_H\n"); in ad3552r_init()
1061 if (id != dac->chip_id) { in ad3552r_init()
1062 dev_err(&dac->spi->dev, "Product id not matching\n"); in ad3552r_init()
1063 return -ENODEV; in ad3552r_init()
1076 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*dac)); in ad3552r_probe()
1078 return -ENOMEM; in ad3552r_probe()
1081 dac->spi = spi; in ad3552r_probe()
1082 dac->chip_id = id->driver_data; in ad3552r_probe()
1084 mutex_init(&dac->lock); in ad3552r_probe()
1091 if (dac->chip_id == AD3552R_ID) in ad3552r_probe()
1092 indio_dev->name = "ad3552r"; in ad3552r_probe()
1094 indio_dev->name = "ad3542r"; in ad3552r_probe()
1095 indio_dev->dev.parent = &spi->dev; in ad3552r_probe()
1096 indio_dev->info = &ad3552r_iio_info; in ad3552r_probe()
1097 indio_dev->num_channels = dac->num_ch; in ad3552r_probe()
1098 indio_dev->channels = dac->channels; in ad3552r_probe()
1099 indio_dev->modes = INDIO_DIRECT_MODE; in ad3552r_probe()
1101 err = devm_iio_triggered_buffer_setup_ext(&indio_dev->dev, indio_dev, NULL, in ad3552r_probe()
1109 return devm_iio_device_register(&spi->dev, indio_dev); in ad3552r_probe()