Lines Matching +full:refout +full:- +full:avss

1 // SPDX-License-Identifier: GPL-2.0+
7 * AD7172-2/AD7172-4/AD7173-8/AD7175-2
8 * AD7175-8/AD7176-2/AD7177-2
18 #include <linux/clk-provider.h>
147 (pin2) < st->info->num_voltage_in && \
148 (pin2) >= st->info->num_voltage_in_div)
172 /* ((AVDD1 − AVSS)/5) */
221 24845000, 24845000, 20725000, 20725000, /* 0-3 */
222 15564000, 13841000, 10390000, 10390000, /* 4-7 */
223 4994000, 2499000, 1000000, 500000, /* 8-11 */
224 395500, 200000, 100000, 59890, /* 12-15 */
225 49920, 20000, 16660, 10000, /* 16-19 */
226 5000, 2500, 2500, /* 20-22 */
230 12422360, 12422360, 12422360, 12422360, /* 0-3 */
231 10362690, 10362690, 7782100, 6290530, /* 4-7 */
232 5194800, 2496900, 1007600, 499900, /* 8-11 */
233 390600, 200300, 100000, 59750, /* 12-15 */
234 49840, 20000, 16650, 10000, /* 16-19 */
235 5000, 2500, 1250, /* 20-22 */
239 6211000, 6211000, 6211000, 6211000, 6211000, 6211000, 5181000, 4444000, /* 0-7 */
240 3115000, 2597000, 1007000, 503800, 381000, 200300, 100500, 59520, /* 8-15 */
241 49680, 20010, 16333, 10000, 5000, 2500, 1250, /* 16-22 */
245 50000000, 41667000, 31250000, 27778000, /* 0-3 */
246 20833000, 17857000, 12500000, 10000000, /* 4-7 */
247 5000000, 2500000, 1000000, 500000, /* 8-11 */
248 397500, 200000, 100000, 59920, /* 12-15 */
249 49960, 20000, 16666, 10000, /* 16-19 */
369 .name = "ad7172-2",
385 .name = "ad7172-4",
400 .name = "ad7173-8",
416 .name = "ad7175-2",
432 .name = "ad7175-8",
449 .name = "ad7176-2",
462 .name = "ad7177-2",
481 [AD7173_SETUP_REF_SEL_INT_REF] = "refout-avss",
486 "ext-clk", "xtal"
532 regmap_update_bits(st->reg_gpiocon_regmap, AD7173_REG_GPIO, mask, ~mask); in ad7173_gpio_disable()
538 struct device *dev = &st->sd.spi->dev; in ad7173_gpio_init()
542 st->reg_gpiocon_regmap = devm_regmap_init_spi(st->sd.spi, &ad7173_regmap_config); in ad7173_gpio_init()
543 ret = PTR_ERR_OR_ZERO(st->reg_gpiocon_regmap); in ad7173_gpio_init()
548 regmap_update_bits(st->reg_gpiocon_regmap, AD7173_REG_GPIO, mask, mask); in ad7173_gpio_init()
555 gpio_regmap.regmap = st->reg_gpiocon_regmap; in ad7173_gpio_init()
556 gpio_regmap.ngpio = st->info->num_gpios; in ad7173_gpio_init()
558 if (st->info->higher_gpio_bits) in ad7173_gpio_init()
563 st->gpio_regmap = devm_gpio_regmap_register(dev, &gpio_regmap); in ad7173_gpio_init()
564 ret = PTR_ERR_OR_ZERO(st->gpio_regmap); in ad7173_gpio_init()
566 return dev_err_probe(dev, ret, "Unable to init gpio-regmap\n"); in ad7173_gpio_init()
591 ida_destroy(&st->cfg_slots_status); in ad7173_ida_destroy()
596 memset64(st->config_cnts, 0, st->info->num_configs); in ad7173_reset_usage_cnts()
597 st->config_usage_counter = 0; in ad7173_reset_usage_cnts()
608 for (i = 0; i < st->num_channels; i++) { in ad7173_find_live_config()
609 cfg_aux = &st->channels[i].cfg; in ad7173_find_live_config()
611 if (cfg_aux->live && in ad7173_find_live_config()
612 !memcmp(&cfg->config_props, &cfg_aux->config_props, cmp_size)) in ad7173_find_live_config()
623 for (i = 1; i < st->info->num_configs; i++) in ad7173_free_config_slot_lru()
624 if (st->config_cnts[i] < st->config_cnts[lru_position]) in ad7173_free_config_slot_lru()
627 for (i = 0; i < st->num_channels; i++) in ad7173_free_config_slot_lru()
628 if (st->channels[i].cfg.cfg_slot == lru_position) in ad7173_free_config_slot_lru()
629 st->channels[i].cfg.live = false; in ad7173_free_config_slot_lru()
631 ida_free(&st->cfg_slots_status, lru_position); in ad7173_free_config_slot_lru()
632 return ida_alloc(&st->cfg_slots_status, GFP_KERNEL); in ad7173_free_config_slot_lru()
642 free_cfg_slot = ida_alloc_range(&st->cfg_slots_status, 0, in ad7173_load_config()
643 st->info->num_configs - 1, GFP_KERNEL); in ad7173_load_config()
647 cfg->cfg_slot = free_cfg_slot; in ad7173_load_config()
648 config = FIELD_PREP(AD7173_SETUP_REF_SEL_MASK, cfg->ref_sel); in ad7173_load_config()
650 if (cfg->bipolar) in ad7173_load_config()
653 if (cfg->input_buf) in ad7173_load_config()
656 ret = ad_sd_write_reg(&st->sd, AD7173_REG_SETUP(free_cfg_slot), 2, config); in ad7173_load_config()
660 return ad_sd_write_reg(&st->sd, AD7173_REG_FILTER(free_cfg_slot), 2, in ad7173_load_config()
661 AD7173_FILTER_ODR0_MASK & cfg->odr); in ad7173_load_config()
666 struct ad7173_channel_config *cfg = &st->channels[addr].cfg; in ad7173_config_channel()
670 if (!cfg->live) { in ad7173_config_channel()
673 cfg->cfg_slot = live_cfg->cfg_slot; in ad7173_config_channel()
678 cfg->live = true; in ad7173_config_channel()
682 if (st->config_usage_counter == U64_MAX) in ad7173_config_channel()
685 st->config_usage_counter++; in ad7173_config_channel()
686 st->config_cnts[cfg->cfg_slot] = st->config_usage_counter; in ad7173_config_channel()
702 FIELD_PREP(AD7173_CH_SETUP_SEL_MASK, st->channels[channel].cfg.cfg_slot) | in ad7173_set_channel()
703 st->channels[channel].ain; in ad7173_set_channel()
705 return ad_sd_write_reg(&st->sd, AD7173_REG_CH(channel), 2, val); in ad7173_set_channel()
713 st->adc_mode &= ~AD7173_ADC_MODE_MODE_MASK; in ad7173_set_mode()
714 st->adc_mode |= FIELD_PREP(AD7173_ADC_MODE_MODE_MASK, mode); in ad7173_set_mode()
716 return ad_sd_write_reg(&st->sd, AD7173_REG_ADC_MODE, 2, st->adc_mode); in ad7173_set_mode()
722 unsigned int interface_mode = st->interface_mode; in ad7173_append_status()
727 ret = ad_sd_write_reg(&st->sd, AD7173_REG_INTERFACE_MODE, 2, interface_mode); in ad7173_append_status()
731 st->interface_mode = interface_mode; in ad7173_append_status()
742 for (i = 0; i < st->num_channels; i++) { in ad7173_disable_all()
772 struct device *dev = &st->sd.spi->dev; in ad7173_setup()
779 ret = spi_write_then_read(st->sd.spi, buf, sizeof(buf), NULL, 0); in ad7173_setup()
786 ret = ad_sd_read_reg(&st->sd, AD7173_REG_ID, 2, &id); in ad7173_setup()
791 if (id != st->info->id) in ad7173_setup()
793 id, st->info->id); in ad7173_setup()
795 st->adc_mode |= AD7173_ADC_MODE_SING_CYC; in ad7173_setup()
796 st->interface_mode = 0x0; in ad7173_setup()
798 st->config_usage_counter = 0; in ad7173_setup()
799 st->config_cnts = devm_kcalloc(dev, st->info->num_configs, in ad7173_setup()
800 sizeof(*st->config_cnts), GFP_KERNEL); in ad7173_setup()
801 if (!st->config_cnts) in ad7173_setup()
802 return -ENOMEM; in ad7173_setup()
805 return ad7173_disable_all(&st->sd); in ad7173_setup()
815 vref = regulator_get_voltage(st->regulators[0].consumer); in ad7173_get_ref_voltage_milli()
819 vref = regulator_get_voltage(st->regulators[1].consumer); in ad7173_get_ref_voltage_milli()
827 vref = regulator_get_voltage(st->regulators[2].consumer); in ad7173_get_ref_voltage_milli()
831 return -EINVAL; in ad7173_get_ref_voltage_milli()
845 struct ad7173_channel *ch = &st->channels[chan->address]; in ad7173_read_raw()
859 switch (chan->type) { in ad7173_read_raw()
864 *val2 = chan->scan_type.realbits; in ad7173_read_raw()
867 *val = ad7173_get_ref_voltage_milli(st, ch->cfg.ref_sel); in ad7173_read_raw()
868 *val2 = chan->scan_type.realbits - !!(ch->cfg.bipolar); in ad7173_read_raw()
870 if (chan->channel < st->info->num_voltage_in_div) in ad7173_read_raw()
874 *val = ad7173_get_ref_voltage_milli(st, ch->cfg.ref_sel); in ad7173_read_raw()
876 *val2 = chan->scan_type.realbits - ch->cfg.bipolar; in ad7173_read_raw()
879 return -EINVAL; in ad7173_read_raw()
883 switch (chan->type) { in ad7173_read_raw()
885 /* 0 Kelvin -> raw sample */ in ad7173_read_raw()
886 temp = -ABSOLUTE_ZERO_MILLICELSIUS; in ad7173_read_raw()
888 temp <<= chan->scan_type.realbits; in ad7173_read_raw()
892 *val = -temp; in ad7173_read_raw()
896 *val = -BIT(chan->scan_type.realbits - 1); in ad7173_read_raw()
899 return -EINVAL; in ad7173_read_raw()
902 reg = st->channels[chan->address].cfg.odr; in ad7173_read_raw()
904 *val = st->info->sinc5_data_rates[reg] / MILLI; in ad7173_read_raw()
905 *val2 = (st->info->sinc5_data_rates[reg] % MILLI) * (MICRO / MILLI); in ad7173_read_raw()
909 return -EINVAL; in ad7173_read_raw()
944 for (i = st->info->odr_start_value; i < st->info->num_sinc5_data_rates - 1; i++) in ad7173_write_raw()
945 if (freq >= st->info->sinc5_data_rates[i]) in ad7173_write_raw()
948 cfg = &st->channels[chan->address].cfg; in ad7173_write_raw()
949 cfg->odr = i; in ad7173_write_raw()
950 cfg->live = false; in ad7173_write_raw()
954 ret = -EINVAL; in ad7173_write_raw()
968 for (i = 0; i < indio_dev->num_channels; i++) { in ad7173_update_scan_mode()
970 ret = ad7173_set_channel(&st->sd, i); in ad7173_update_scan_mode()
972 ret = ad_sd_write_reg(&st->sd, AD7173_REG_CH(i), 2, 0); in ad7173_update_scan_mode()
995 return ad_sd_read_reg(&st->sd, reg, reg_size, readval); in ad7173_debug_reg_access()
997 return ad_sd_write_reg(&st->sd, reg, reg_size, writeval); in ad7173_debug_reg_access()
1047 regulator_bulk_disable(ARRAY_SIZE(st->regulators), st->regulators); in ad7173_disable_regulators()
1060 st->adc_mode &= ~AD7173_ADC_MODE_CLOCKSEL_MASK; in ad7173_sel_clk()
1061 st->adc_mode |= FIELD_PREP(AD7173_ADC_MODE_CLOCKSEL_MASK, clk_sel); in ad7173_sel_clk()
1062 ret = ad_sd_write_reg(&st->sd, AD7173_REG_ADC_MODE, 0x2, st->adc_mode); in ad7173_sel_clk()
1072 return st->info->clock / HZ_PER_KHZ; in ad7173_clk_recalc_rate()
1080 clk_sel = FIELD_GET(AD7173_ADC_MODE_CLOCKSEL_MASK, st->adc_mode); in ad7173_clk_output_is_enabled()
1108 struct device *dev = indio_dev->dev.parent; in ad7173_register_clk_provider()
1119 st->int_clk_hw.init = &init; in ad7173_register_clk_provider()
1120 ret = devm_clk_hw_register(dev, &st->int_clk_hw); in ad7173_register_clk_provider()
1125 &st->int_clk_hw); in ad7173_register_clk_provider()
1131 struct device *dev = &st->sd.spi->dev; in ad4111_validate_current_ain()
1133 if (!st->info->has_current_inputs) in ad4111_validate_current_ain()
1134 return dev_err_probe(dev, -EINVAL, in ad4111_validate_current_ain()
1136 st->info->name); in ad4111_validate_current_ain()
1139 return dev_err_probe(dev, -EINVAL, in ad4111_validate_current_ain()
1140 "For current channels single-channel must be <[0-3]>\n"); in ad4111_validate_current_ain()
1148 struct device *dev = &st->sd.spi->dev; in ad7173_validate_voltage_ain_inputs()
1151 /* (AVDD1-AVSS)/5 power supply monitoring */ in ad7173_validate_voltage_ain_inputs()
1153 st->info->has_pow_supply_monitoring) in ad7173_validate_voltage_ain_inputs()
1157 (ain0 == AD4111_VINCOM_INPUT && st->info->has_vincom_input); in ad7173_validate_voltage_ain_inputs()
1159 (ain1 == AD4111_VINCOM_INPUT && st->info->has_vincom_input); in ad7173_validate_voltage_ain_inputs()
1161 if ((ain0 >= st->info->num_voltage_in && !special_input0) || in ad7173_validate_voltage_ain_inputs()
1162 (ain1 >= st->info->num_voltage_in && !special_input1)) { in ad7173_validate_voltage_ain_inputs()
1164 return dev_err_probe(dev, -EINVAL, in ad7173_validate_voltage_ain_inputs()
1165 "VINCOM not supported for %s\n", st->info->name); in ad7173_validate_voltage_ain_inputs()
1167 return dev_err_probe(dev, -EINVAL, in ad7173_validate_voltage_ain_inputs()
1174 return dev_err_probe(dev, -EINVAL, in ad7173_validate_voltage_ain_inputs()
1178 ((ain0 >= st->info->num_voltage_in_div) != in ad7173_validate_voltage_ain_inputs()
1179 (ain1 >= st->info->num_voltage_in_div))) in ad7173_validate_voltage_ain_inputs()
1180 return dev_err_probe(dev, -EINVAL, in ad7173_validate_voltage_ain_inputs()
1189 struct device *dev = &st->sd.spi->dev; in ad7173_validate_reference()
1192 if (ref_sel == AD7173_SETUP_REF_SEL_INT_REF && !st->info->has_int_ref) in ad7173_validate_reference()
1193 return dev_err_probe(dev, -EINVAL, in ad7173_validate_reference()
1196 if (ref_sel == AD7173_SETUP_REF_SEL_EXT_REF2 && !st->info->has_ref2) in ad7173_validate_reference()
1197 return dev_err_probe(dev, -EINVAL, in ad7173_validate_reference()
1212 struct device *dev = indio_dev->dev.parent; in ad7173_fw_parse_channel_config()
1219 if (st->info->has_temp) in ad7173_fw_parse_channel_config()
1223 return dev_err_probe(dev, -ENODATA, "No channels specified\n"); in ad7173_fw_parse_channel_config()
1225 if (num_channels > st->info->num_channels) in ad7173_fw_parse_channel_config()
1226 return dev_err_probe(dev, -EINVAL, in ad7173_fw_parse_channel_config()
1228 st->info->num_channels); in ad7173_fw_parse_channel_config()
1230 indio_dev->num_channels = num_channels; in ad7173_fw_parse_channel_config()
1231 st->num_channels = num_channels; in ad7173_fw_parse_channel_config()
1233 chan_arr = devm_kcalloc(dev, sizeof(*indio_dev->channels), in ad7173_fw_parse_channel_config()
1234 st->num_channels, GFP_KERNEL); in ad7173_fw_parse_channel_config()
1236 return -ENOMEM; in ad7173_fw_parse_channel_config()
1238 chans_st_arr = devm_kcalloc(dev, st->num_channels, sizeof(*st->channels), in ad7173_fw_parse_channel_config()
1241 return -ENOMEM; in ad7173_fw_parse_channel_config()
1243 indio_dev->channels = chan_arr; in ad7173_fw_parse_channel_config()
1244 st->channels = chans_st_arr; in ad7173_fw_parse_channel_config()
1246 if (st->info->has_temp) { in ad7173_fw_parse_channel_config()
1249 chan_st_priv->ain = in ad7173_fw_parse_channel_config()
1252 chan_st_priv->cfg.bipolar = false; in ad7173_fw_parse_channel_config()
1253 chan_st_priv->cfg.input_buf = st->info->has_input_buf; in ad7173_fw_parse_channel_config()
1254 chan_st_priv->cfg.ref_sel = AD7173_SETUP_REF_SEL_INT_REF; in ad7173_fw_parse_channel_config()
1255 st->adc_mode |= AD7173_ADC_MODE_REF_EN; in ad7173_fw_parse_channel_config()
1256 if (st->info->data_reg_only_16bit) in ad7173_fw_parse_channel_config()
1268 ret = fwnode_property_read_u32_array(child, "diff-channels", in ad7173_fw_parse_channel_config()
1271 ret = fwnode_property_read_u32(child, "single-channel", in ad7173_fw_parse_channel_config()
1275 "Channel must define one of diff-channels or single-channel.\n"); in ad7173_fw_parse_channel_config()
1277 is_current_chan = fwnode_property_read_bool(child, "adi,current-channel"); in ad7173_fw_parse_channel_config()
1279 chan->differential = true; in ad7173_fw_parse_channel_config()
1287 if (!chan->differential) { in ad7173_fw_parse_channel_config()
1289 "common-mode-channel", ain + 1); in ad7173_fw_parse_channel_config()
1292 "common-mode-channel must be defined for single-ended channels.\n"); in ad7173_fw_parse_channel_config()
1300 "adi,reference-select", in ad7173_fw_parse_channel_config()
1313 st->adc_mode |= AD7173_ADC_MODE_REF_EN; in ad7173_fw_parse_channel_config()
1314 chan_st_priv->cfg.ref_sel = ref_sel; in ad7173_fw_parse_channel_config()
1316 chan->address = chan_index; in ad7173_fw_parse_channel_config()
1317 chan->scan_index = chan_index; in ad7173_fw_parse_channel_config()
1318 chan->channel = ain[0]; in ad7173_fw_parse_channel_config()
1319 chan_st_priv->chan_reg = chan_index; in ad7173_fw_parse_channel_config()
1320 chan_st_priv->cfg.input_buf = st->info->has_input_buf; in ad7173_fw_parse_channel_config()
1321 chan_st_priv->cfg.odr = 0; in ad7173_fw_parse_channel_config()
1323 chan_st_priv->cfg.bipolar = fwnode_property_read_bool(child, "bipolar"); in ad7173_fw_parse_channel_config()
1324 if (chan_st_priv->cfg.bipolar) in ad7173_fw_parse_channel_config()
1325 chan->info_mask_separate |= BIT(IIO_CHAN_INFO_OFFSET); in ad7173_fw_parse_channel_config()
1328 chan->type = IIO_CURRENT; in ad7173_fw_parse_channel_config()
1329 chan->differential = false; in ad7173_fw_parse_channel_config()
1330 chan->channel2 = 0; in ad7173_fw_parse_channel_config()
1331 chan_st_priv->ain = ad4111_current_channel_config[ain[0]]; in ad7173_fw_parse_channel_config()
1333 chan_st_priv->cfg.input_buf = st->info->has_input_buf; in ad7173_fw_parse_channel_config()
1334 chan->channel2 = ain[1]; in ad7173_fw_parse_channel_config()
1335 chan_st_priv->ain = AD7173_CH_ADDRESS(ain[0], ain[1]); in ad7173_fw_parse_channel_config()
1338 if (st->info->data_reg_only_16bit) in ad7173_fw_parse_channel_config()
1349 struct device *dev = indio_dev->dev.parent; in ad7173_fw_parse_device_config()
1352 st->regulators[0].supply = ad7173_ref_sel_str[AD7173_SETUP_REF_SEL_EXT_REF]; in ad7173_fw_parse_device_config()
1353 st->regulators[1].supply = ad7173_ref_sel_str[AD7173_SETUP_REF_SEL_EXT_REF2]; in ad7173_fw_parse_device_config()
1354 st->regulators[2].supply = ad7173_ref_sel_str[AD7173_SETUP_REF_SEL_AVDD1_AVSS]; in ad7173_fw_parse_device_config()
1362 ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(st->regulators), in ad7173_fw_parse_device_config()
1363 st->regulators); in ad7173_fw_parse_device_config()
1367 ret = regulator_bulk_enable(ARRAY_SIZE(st->regulators), st->regulators); in ad7173_fw_parse_device_config()
1376 ret = device_property_match_property_string(dev, "clock-names", in ad7173_fw_parse_device_config()
1380 st->adc_mode |= FIELD_PREP(AD7173_ADC_MODE_CLOCKSEL_MASK, in ad7173_fw_parse_device_config()
1384 st->adc_mode |= FIELD_PREP(AD7173_ADC_MODE_CLOCKSEL_MASK, in ad7173_fw_parse_device_config()
1386 st->ext_clk = devm_clk_get(dev, ad7173_clk_sel[ret]); in ad7173_fw_parse_device_config()
1387 if (IS_ERR(st->ext_clk)) in ad7173_fw_parse_device_config()
1388 return dev_err_probe(dev, PTR_ERR(st->ext_clk), in ad7173_fw_parse_device_config()
1391 ret = clk_prepare_enable(st->ext_clk); in ad7173_fw_parse_device_config()
1397 st->ext_clk); in ad7173_fw_parse_device_config()
1413 struct device *dev = &spi->dev; in ad7173_probe()
1420 return -ENOMEM; in ad7173_probe()
1423 st->info = spi_get_device_match_data(spi); in ad7173_probe()
1424 if (!st->info) in ad7173_probe()
1425 return -ENODEV; in ad7173_probe()
1427 ida_init(&st->cfg_slots_status); in ad7173_probe()
1432 indio_dev->name = st->info->name; in ad7173_probe()
1433 indio_dev->modes = INDIO_DIRECT_MODE; in ad7173_probe()
1434 indio_dev->info = &ad7173_info; in ad7173_probe()
1436 spi->mode = SPI_MODE_3; in ad7173_probe()
1439 ad7173_sigma_delta_info.num_slots = st->info->num_configs; in ad7173_probe()
1440 ret = ad_sd_init(&st->sd, indio_dev, spi, &ad7173_sigma_delta_info); in ad7173_probe()
1473 { .compatible = "adi,ad7172-2", .data = &ad7172_2_device_info },
1474 { .compatible = "adi,ad7172-4", .data = &ad7172_4_device_info },
1475 { .compatible = "adi,ad7173-8", .data = &ad7173_8_device_info },
1476 { .compatible = "adi,ad7175-2", .data = &ad7175_2_device_info },
1477 { .compatible = "adi,ad7175-8", .data = &ad7175_8_device_info },
1478 { .compatible = "adi,ad7176-2", .data = &ad7176_2_device_info },
1479 { .compatible = "adi,ad7177-2", .data = &ad7177_2_device_info },
1491 { "ad7172-2", (kernel_ulong_t)&ad7172_2_device_info },
1492 { "ad7172-4", (kernel_ulong_t)&ad7172_4_device_info },
1493 { "ad7173-8", (kernel_ulong_t)&ad7173_8_device_info },
1494 { "ad7175-2", (kernel_ulong_t)&ad7175_2_device_info },
1495 { "ad7175-8", (kernel_ulong_t)&ad7175_8_device_info },
1496 { "ad7176-2", (kernel_ulong_t)&ad7176_2_device_info },
1497 { "ad7177-2", (kernel_ulong_t)&ad7177_2_device_info },
1513 MODULE_AUTHOR("Lars-Peter Clausen <lars@metafo.de>");