Lines Matching +full:avdd1 +full:- +full:supply
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>
146 (pin2) < st->info->num_voltage_in && \
147 (pin2) >= st->info->num_voltage_in_div)
171 /* ((AVDD1 − AVSS)/5) */
219 24845000, 24845000, 20725000, 20725000, /* 0-3 */
220 15564000, 13841000, 10390000, 10390000, /* 4-7 */
221 4994000, 2499000, 1000000, 500000, /* 8-11 */
222 395500, 200000, 100000, 59890, /* 12-15 */
223 49920, 20000, 16660, 10000, /* 16-19 */
224 5000, 2500, 2500, /* 20-22 */
228 12422360, 12422360, 12422360, 12422360, /* 0-3 */
229 10362690, 10362690, 7782100, 6290530, /* 4-7 */
230 5194800, 2496900, 1007600, 499900, /* 8-11 */
231 390600, 200300, 100000, 59750, /* 12-15 */
232 49840, 20000, 16650, 10000, /* 16-19 */
233 5000, 2500, 1250, /* 20-22 */
237 6211000, 6211000, 6211000, 6211000, 6211000, 6211000, 5181000, 4444000, /* 0-7 */
238 3115000, 2597000, 1007000, 503800, 381000, 200300, 100500, 59520, /* 8-15 */
239 49680, 20010, 16333, 10000, 5000, 2500, 1250, /* 16-22 */
243 50000000, 41667000, 31250000, 27778000, /* 0-3 */
244 20833000, 17857000, 12500000, 10000000, /* 4-7 */
245 5000000, 2500000, 1000000, 500000, /* 8-11 */
246 397500, 200000, 100000, 59920, /* 12-15 */
247 49960, 20000, 16666, 10000, /* 16-19 */
349 .name = "ad7172-2",
365 .name = "ad7172-4",
380 .name = "ad7173-8",
396 .name = "ad7175-2",
412 .name = "ad7175-8",
429 .name = "ad7176-2",
442 .name = "ad7177-2",
461 [AD7173_SETUP_REF_SEL_INT_REF] = "refout-avss",
466 "ext-clk", "xtal"
512 regmap_update_bits(st->reg_gpiocon_regmap, AD7173_REG_GPIO, mask, ~mask); in ad7173_gpio_disable()
518 struct device *dev = &st->sd.spi->dev; in ad7173_gpio_init()
522 st->reg_gpiocon_regmap = devm_regmap_init_spi(st->sd.spi, &ad7173_regmap_config); in ad7173_gpio_init()
523 ret = PTR_ERR_OR_ZERO(st->reg_gpiocon_regmap); in ad7173_gpio_init()
528 regmap_update_bits(st->reg_gpiocon_regmap, AD7173_REG_GPIO, mask, mask); in ad7173_gpio_init()
535 gpio_regmap.regmap = st->reg_gpiocon_regmap; in ad7173_gpio_init()
536 gpio_regmap.ngpio = st->info->num_gpios; in ad7173_gpio_init()
538 if (st->info->higher_gpio_bits) in ad7173_gpio_init()
543 st->gpio_regmap = devm_gpio_regmap_register(dev, &gpio_regmap); in ad7173_gpio_init()
544 ret = PTR_ERR_OR_ZERO(st->gpio_regmap); in ad7173_gpio_init()
546 return dev_err_probe(dev, ret, "Unable to init gpio-regmap\n"); in ad7173_gpio_init()
571 ida_destroy(&st->cfg_slots_status); in ad7173_ida_destroy()
576 memset64(st->config_cnts, 0, st->info->num_configs); in ad7173_reset_usage_cnts()
577 st->config_usage_counter = 0; in ad7173_reset_usage_cnts()
588 for (i = 0; i < st->num_channels; i++) { in ad7173_find_live_config()
589 cfg_aux = &st->channels[i].cfg; in ad7173_find_live_config()
591 if (cfg_aux->live && in ad7173_find_live_config()
592 !memcmp(&cfg->config_props, &cfg_aux->config_props, cmp_size)) in ad7173_find_live_config()
603 for (i = 1; i < st->info->num_configs; i++) in ad7173_free_config_slot_lru()
604 if (st->config_cnts[i] < st->config_cnts[lru_position]) in ad7173_free_config_slot_lru()
607 for (i = 0; i < st->num_channels; i++) in ad7173_free_config_slot_lru()
608 if (st->channels[i].cfg.cfg_slot == lru_position) in ad7173_free_config_slot_lru()
609 st->channels[i].cfg.live = false; in ad7173_free_config_slot_lru()
611 ida_free(&st->cfg_slots_status, lru_position); in ad7173_free_config_slot_lru()
612 return ida_alloc(&st->cfg_slots_status, GFP_KERNEL); in ad7173_free_config_slot_lru()
622 free_cfg_slot = ida_alloc_range(&st->cfg_slots_status, 0, in ad7173_load_config()
623 st->info->num_configs - 1, GFP_KERNEL); in ad7173_load_config()
627 cfg->cfg_slot = free_cfg_slot; in ad7173_load_config()
628 config = FIELD_PREP(AD7173_SETUP_REF_SEL_MASK, cfg->ref_sel); in ad7173_load_config()
630 if (cfg->bipolar) in ad7173_load_config()
633 if (cfg->input_buf) in ad7173_load_config()
636 ret = ad_sd_write_reg(&st->sd, AD7173_REG_SETUP(free_cfg_slot), 2, config); in ad7173_load_config()
640 return ad_sd_write_reg(&st->sd, AD7173_REG_FILTER(free_cfg_slot), 2, in ad7173_load_config()
641 AD7173_FILTER_ODR0_MASK & cfg->odr); in ad7173_load_config()
646 struct ad7173_channel_config *cfg = &st->channels[addr].cfg; in ad7173_config_channel()
650 if (!cfg->live) { in ad7173_config_channel()
653 cfg->cfg_slot = live_cfg->cfg_slot; in ad7173_config_channel()
658 cfg->live = true; in ad7173_config_channel()
662 if (st->config_usage_counter == U64_MAX) in ad7173_config_channel()
665 st->config_usage_counter++; in ad7173_config_channel()
666 st->config_cnts[cfg->cfg_slot] = st->config_usage_counter; in ad7173_config_channel()
682 FIELD_PREP(AD7173_CH_SETUP_SEL_MASK, st->channels[channel].cfg.cfg_slot) | in ad7173_set_channel()
683 st->channels[channel].ain; in ad7173_set_channel()
685 return ad_sd_write_reg(&st->sd, AD7173_REG_CH(channel), 2, val); in ad7173_set_channel()
693 st->adc_mode &= ~AD7173_ADC_MODE_MODE_MASK; in ad7173_set_mode()
694 st->adc_mode |= FIELD_PREP(AD7173_ADC_MODE_MODE_MASK, mode); in ad7173_set_mode()
696 return ad_sd_write_reg(&st->sd, AD7173_REG_ADC_MODE, 2, st->adc_mode); in ad7173_set_mode()
702 unsigned int interface_mode = st->interface_mode; in ad7173_append_status()
707 ret = ad_sd_write_reg(&st->sd, AD7173_REG_INTERFACE_MODE, 2, interface_mode); in ad7173_append_status()
711 st->interface_mode = interface_mode; in ad7173_append_status()
722 for (i = 0; i < st->num_channels; i++) { in ad7173_disable_all()
752 struct device *dev = &st->sd.spi->dev; in ad7173_setup()
759 ret = spi_write_then_read(st->sd.spi, buf, sizeof(buf), NULL, 0); in ad7173_setup()
766 ret = ad_sd_read_reg(&st->sd, AD7173_REG_ID, 2, &id); in ad7173_setup()
771 if (id != st->info->id) in ad7173_setup()
773 id, st->info->id); in ad7173_setup()
775 st->adc_mode |= AD7173_ADC_MODE_SING_CYC; in ad7173_setup()
776 st->interface_mode = 0x0; in ad7173_setup()
778 st->config_usage_counter = 0; in ad7173_setup()
779 st->config_cnts = devm_kcalloc(dev, st->info->num_configs, in ad7173_setup()
780 sizeof(*st->config_cnts), GFP_KERNEL); in ad7173_setup()
781 if (!st->config_cnts) in ad7173_setup()
782 return -ENOMEM; in ad7173_setup()
785 return ad7173_disable_all(&st->sd); in ad7173_setup()
795 vref = regulator_get_voltage(st->regulators[0].consumer); in ad7173_get_ref_voltage_milli()
799 vref = regulator_get_voltage(st->regulators[1].consumer); in ad7173_get_ref_voltage_milli()
807 vref = regulator_get_voltage(st->regulators[2].consumer); in ad7173_get_ref_voltage_milli()
811 return -EINVAL; in ad7173_get_ref_voltage_milli()
825 struct ad7173_channel *ch = &st->channels[chan->address]; in ad7173_read_raw()
839 switch (chan->type) { in ad7173_read_raw()
844 *val2 = chan->scan_type.realbits; in ad7173_read_raw()
847 *val = ad7173_get_ref_voltage_milli(st, ch->cfg.ref_sel); in ad7173_read_raw()
848 *val2 = chan->scan_type.realbits - !!(ch->cfg.bipolar); in ad7173_read_raw()
850 if (chan->channel < st->info->num_voltage_in_div) in ad7173_read_raw()
854 *val = ad7173_get_ref_voltage_milli(st, ch->cfg.ref_sel); in ad7173_read_raw()
856 *val2 = chan->scan_type.realbits - ch->cfg.bipolar; in ad7173_read_raw()
859 return -EINVAL; in ad7173_read_raw()
863 switch (chan->type) { in ad7173_read_raw()
865 /* 0 Kelvin -> raw sample */ in ad7173_read_raw()
866 temp = -ABSOLUTE_ZERO_MILLICELSIUS; in ad7173_read_raw()
868 temp <<= chan->scan_type.realbits; in ad7173_read_raw()
872 *val = -temp; in ad7173_read_raw()
876 *val = -BIT(chan->scan_type.realbits - 1); in ad7173_read_raw()
879 return -EINVAL; in ad7173_read_raw()
882 reg = st->channels[chan->address].cfg.odr; in ad7173_read_raw()
884 *val = st->info->sinc5_data_rates[reg] / MILLI; in ad7173_read_raw()
885 *val2 = (st->info->sinc5_data_rates[reg] % MILLI) * (MICRO / MILLI); in ad7173_read_raw()
889 return -EINVAL; in ad7173_read_raw()
924 for (i = st->info->odr_start_value; i < st->info->num_sinc5_data_rates - 1; i++) in ad7173_write_raw()
925 if (freq >= st->info->sinc5_data_rates[i]) in ad7173_write_raw()
928 cfg = &st->channels[chan->address].cfg; in ad7173_write_raw()
929 cfg->odr = i; in ad7173_write_raw()
930 cfg->live = false; in ad7173_write_raw()
934 ret = -EINVAL; in ad7173_write_raw()
948 for (i = 0; i < indio_dev->num_channels; i++) { in ad7173_update_scan_mode()
950 ret = ad7173_set_channel(&st->sd, i); in ad7173_update_scan_mode()
952 ret = ad_sd_write_reg(&st->sd, AD7173_REG_CH(i), 2, 0); in ad7173_update_scan_mode()
975 return ad_sd_read_reg(&st->sd, reg, reg_size, readval); in ad7173_debug_reg_access()
977 return ad_sd_write_reg(&st->sd, reg, reg_size, writeval); in ad7173_debug_reg_access()
1020 regulator_bulk_disable(ARRAY_SIZE(st->regulators), st->regulators); in ad7173_disable_regulators()
1033 st->adc_mode &= ~AD7173_ADC_MODE_CLOCKSEL_MASK; in ad7173_sel_clk()
1034 st->adc_mode |= FIELD_PREP(AD7173_ADC_MODE_CLOCKSEL_MASK, clk_sel); in ad7173_sel_clk()
1035 ret = ad_sd_write_reg(&st->sd, AD7173_REG_ADC_MODE, 0x2, st->adc_mode); in ad7173_sel_clk()
1045 return st->info->clock / HZ_PER_KHZ; in ad7173_clk_recalc_rate()
1053 clk_sel = FIELD_GET(AD7173_ADC_MODE_CLOCKSEL_MASK, st->adc_mode); in ad7173_clk_output_is_enabled()
1081 struct device *dev = indio_dev->dev.parent; in ad7173_register_clk_provider()
1092 st->int_clk_hw.init = &init; in ad7173_register_clk_provider()
1093 ret = devm_clk_hw_register(dev, &st->int_clk_hw); in ad7173_register_clk_provider()
1098 &st->int_clk_hw); in ad7173_register_clk_provider()
1104 struct device *dev = &st->sd.spi->dev; in ad4111_validate_current_ain()
1106 if (!st->info->has_current_inputs) in ad4111_validate_current_ain()
1107 return dev_err_probe(dev, -EINVAL, in ad4111_validate_current_ain()
1109 st->info->name); in ad4111_validate_current_ain()
1112 return dev_err_probe(dev, -EINVAL, in ad4111_validate_current_ain()
1113 "For current channels single-channel must be <[0-3]>\n"); in ad4111_validate_current_ain()
1121 struct device *dev = &st->sd.spi->dev; in ad7173_validate_voltage_ain_inputs()
1124 /* (AVDD1-AVSS)/5 power supply monitoring */ in ad7173_validate_voltage_ain_inputs()
1126 st->info->has_pow_supply_monitoring) in ad7173_validate_voltage_ain_inputs()
1130 (ain0 == AD4111_VINCOM_INPUT && st->info->has_vincom_input); in ad7173_validate_voltage_ain_inputs()
1132 (ain1 == AD4111_VINCOM_INPUT && st->info->has_vincom_input); in ad7173_validate_voltage_ain_inputs()
1134 if ((ain0 >= st->info->num_voltage_in && !special_input0) || in ad7173_validate_voltage_ain_inputs()
1135 (ain1 >= st->info->num_voltage_in && !special_input1)) { in ad7173_validate_voltage_ain_inputs()
1137 return dev_err_probe(dev, -EINVAL, in ad7173_validate_voltage_ain_inputs()
1138 "VINCOM not supported for %s\n", st->info->name); in ad7173_validate_voltage_ain_inputs()
1140 return dev_err_probe(dev, -EINVAL, in ad7173_validate_voltage_ain_inputs()
1147 return dev_err_probe(dev, -EINVAL, in ad7173_validate_voltage_ain_inputs()
1151 ((ain0 >= st->info->num_voltage_in_div) != in ad7173_validate_voltage_ain_inputs()
1152 (ain1 >= st->info->num_voltage_in_div))) in ad7173_validate_voltage_ain_inputs()
1153 return dev_err_probe(dev, -EINVAL, in ad7173_validate_voltage_ain_inputs()
1162 struct device *dev = &st->sd.spi->dev; in ad7173_validate_reference()
1165 if (ref_sel == AD7173_SETUP_REF_SEL_INT_REF && !st->info->has_int_ref) in ad7173_validate_reference()
1166 return dev_err_probe(dev, -EINVAL, in ad7173_validate_reference()
1169 if (ref_sel == AD7173_SETUP_REF_SEL_EXT_REF2 && !st->info->has_ref2) in ad7173_validate_reference()
1170 return dev_err_probe(dev, -EINVAL, in ad7173_validate_reference()
1185 struct device *dev = indio_dev->dev.parent; in ad7173_fw_parse_channel_config()
1192 if (st->info->has_temp) in ad7173_fw_parse_channel_config()
1196 return dev_err_probe(dev, -ENODATA, "No channels specified\n"); in ad7173_fw_parse_channel_config()
1198 if (num_channels > st->info->num_channels) in ad7173_fw_parse_channel_config()
1199 return dev_err_probe(dev, -EINVAL, in ad7173_fw_parse_channel_config()
1201 st->info->num_channels); in ad7173_fw_parse_channel_config()
1203 indio_dev->num_channels = num_channels; in ad7173_fw_parse_channel_config()
1204 st->num_channels = num_channels; in ad7173_fw_parse_channel_config()
1206 chan_arr = devm_kcalloc(dev, sizeof(*indio_dev->channels), in ad7173_fw_parse_channel_config()
1207 st->num_channels, GFP_KERNEL); in ad7173_fw_parse_channel_config()
1209 return -ENOMEM; in ad7173_fw_parse_channel_config()
1211 chans_st_arr = devm_kcalloc(dev, st->num_channels, sizeof(*st->channels), in ad7173_fw_parse_channel_config()
1214 return -ENOMEM; in ad7173_fw_parse_channel_config()
1216 indio_dev->channels = chan_arr; in ad7173_fw_parse_channel_config()
1217 st->channels = chans_st_arr; in ad7173_fw_parse_channel_config()
1219 if (st->info->has_temp) { in ad7173_fw_parse_channel_config()
1222 chan_st_priv->ain = in ad7173_fw_parse_channel_config()
1225 chan_st_priv->cfg.bipolar = false; in ad7173_fw_parse_channel_config()
1226 chan_st_priv->cfg.input_buf = st->info->has_input_buf; in ad7173_fw_parse_channel_config()
1227 chan_st_priv->cfg.ref_sel = AD7173_SETUP_REF_SEL_INT_REF; in ad7173_fw_parse_channel_config()
1228 st->adc_mode |= AD7173_ADC_MODE_REF_EN; in ad7173_fw_parse_channel_config()
1239 ret = fwnode_property_read_u32_array(child, "diff-channels", in ad7173_fw_parse_channel_config()
1242 ret = fwnode_property_read_u32(child, "single-channel", in ad7173_fw_parse_channel_config()
1246 "Channel must define one of diff-channels or single-channel.\n"); in ad7173_fw_parse_channel_config()
1248 is_current_chan = fwnode_property_read_bool(child, "adi,current-channel"); in ad7173_fw_parse_channel_config()
1250 chan->differential = true; in ad7173_fw_parse_channel_config()
1258 if (!chan->differential) { in ad7173_fw_parse_channel_config()
1260 "common-mode-channel", ain + 1); in ad7173_fw_parse_channel_config()
1263 "common-mode-channel must be defined for single-ended channels.\n"); in ad7173_fw_parse_channel_config()
1271 "adi,reference-select", in ad7173_fw_parse_channel_config()
1284 st->adc_mode |= AD7173_ADC_MODE_REF_EN; in ad7173_fw_parse_channel_config()
1285 chan_st_priv->cfg.ref_sel = ref_sel; in ad7173_fw_parse_channel_config()
1287 chan->address = chan_index; in ad7173_fw_parse_channel_config()
1288 chan->scan_index = chan_index; in ad7173_fw_parse_channel_config()
1289 chan->channel = ain[0]; in ad7173_fw_parse_channel_config()
1290 chan_st_priv->chan_reg = chan_index; in ad7173_fw_parse_channel_config()
1291 chan_st_priv->cfg.input_buf = st->info->has_input_buf; in ad7173_fw_parse_channel_config()
1292 chan_st_priv->cfg.odr = 0; in ad7173_fw_parse_channel_config()
1294 chan_st_priv->cfg.bipolar = fwnode_property_read_bool(child, "bipolar"); in ad7173_fw_parse_channel_config()
1295 if (chan_st_priv->cfg.bipolar) in ad7173_fw_parse_channel_config()
1296 chan->info_mask_separate |= BIT(IIO_CHAN_INFO_OFFSET); in ad7173_fw_parse_channel_config()
1299 chan->type = IIO_CURRENT; in ad7173_fw_parse_channel_config()
1300 chan->differential = false; in ad7173_fw_parse_channel_config()
1301 chan->channel2 = 0; in ad7173_fw_parse_channel_config()
1302 chan_st_priv->ain = ad4111_current_channel_config[ain[0]]; in ad7173_fw_parse_channel_config()
1304 chan_st_priv->cfg.input_buf = st->info->has_input_buf; in ad7173_fw_parse_channel_config()
1305 chan->channel2 = ain[1]; in ad7173_fw_parse_channel_config()
1306 chan_st_priv->ain = AD7173_CH_ADDRESS(ain[0], ain[1]); in ad7173_fw_parse_channel_config()
1317 struct device *dev = indio_dev->dev.parent; in ad7173_fw_parse_device_config()
1320 st->regulators[0].supply = ad7173_ref_sel_str[AD7173_SETUP_REF_SEL_EXT_REF]; in ad7173_fw_parse_device_config()
1321 st->regulators[1].supply = ad7173_ref_sel_str[AD7173_SETUP_REF_SEL_EXT_REF2]; in ad7173_fw_parse_device_config()
1322 st->regulators[2].supply = ad7173_ref_sel_str[AD7173_SETUP_REF_SEL_AVDD1_AVSS]; in ad7173_fw_parse_device_config()
1327 * setting attributes so if any channel uses a dummy supply the driver in ad7173_fw_parse_device_config()
1330 ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(st->regulators), in ad7173_fw_parse_device_config()
1331 st->regulators); in ad7173_fw_parse_device_config()
1335 ret = regulator_bulk_enable(ARRAY_SIZE(st->regulators), st->regulators); in ad7173_fw_parse_device_config()
1344 ret = device_property_match_property_string(dev, "clock-names", in ad7173_fw_parse_device_config()
1348 st->adc_mode |= FIELD_PREP(AD7173_ADC_MODE_CLOCKSEL_MASK, in ad7173_fw_parse_device_config()
1352 st->adc_mode |= FIELD_PREP(AD7173_ADC_MODE_CLOCKSEL_MASK, in ad7173_fw_parse_device_config()
1354 st->ext_clk = devm_clk_get(dev, ad7173_clk_sel[ret]); in ad7173_fw_parse_device_config()
1355 if (IS_ERR(st->ext_clk)) in ad7173_fw_parse_device_config()
1356 return dev_err_probe(dev, PTR_ERR(st->ext_clk), in ad7173_fw_parse_device_config()
1359 ret = clk_prepare_enable(st->ext_clk); in ad7173_fw_parse_device_config()
1365 st->ext_clk); in ad7173_fw_parse_device_config()
1381 struct device *dev = &spi->dev; in ad7173_probe()
1388 return -ENOMEM; in ad7173_probe()
1391 st->info = spi_get_device_match_data(spi); in ad7173_probe()
1392 if (!st->info) in ad7173_probe()
1393 return -ENODEV; in ad7173_probe()
1395 ida_init(&st->cfg_slots_status); in ad7173_probe()
1400 indio_dev->name = st->info->name; in ad7173_probe()
1401 indio_dev->modes = INDIO_DIRECT_MODE; in ad7173_probe()
1402 indio_dev->info = &ad7173_info; in ad7173_probe()
1404 spi->mode = SPI_MODE_3; in ad7173_probe()
1407 ad7173_sigma_delta_info.num_slots = st->info->num_configs; in ad7173_probe()
1408 ret = ad_sd_init(&st->sd, indio_dev, spi, &ad7173_sigma_delta_info); in ad7173_probe()
1440 { .compatible = "adi,ad7172-2", .data = &ad7172_2_device_info },
1441 { .compatible = "adi,ad7172-4", .data = &ad7172_4_device_info },
1442 { .compatible = "adi,ad7173-8", .data = &ad7173_8_device_info },
1443 { .compatible = "adi,ad7175-2", .data = &ad7175_2_device_info },
1444 { .compatible = "adi,ad7175-8", .data = &ad7175_8_device_info },
1445 { .compatible = "adi,ad7176-2", .data = &ad7176_2_device_info },
1446 { .compatible = "adi,ad7177-2", .data = &ad7177_2_device_info },
1457 { "ad7172-2", (kernel_ulong_t)&ad7172_2_device_info },
1458 { "ad7172-4", (kernel_ulong_t)&ad7172_4_device_info },
1459 { "ad7173-8", (kernel_ulong_t)&ad7173_8_device_info },
1460 { "ad7175-2", (kernel_ulong_t)&ad7175_2_device_info },
1461 { "ad7175-8", (kernel_ulong_t)&ad7175_8_device_info },
1462 { "ad7176-2", (kernel_ulong_t)&ad7176_2_device_info },
1463 { "ad7177-2", (kernel_ulong_t)&ad7177_2_device_info },
1479 MODULE_AUTHOR("Lars-Peter Clausen <lars@metafo.de>");