Lines Matching +full:3 +full:- +full:channel
1 // SPDX-License-Identifier: GPL-2.0+
54 #define AD7124_SILICON_REV_MSK GENMASK(3, 0)
73 #define AD7124_CONFIG_REF_SEL_MSK GENMASK(4, 3)
112 1, 2, 3, 3, 2, 1, 3, 3, 1, 2, 2, 2, 2,
114 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3,
115 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
116 3, 3, 3, 3, 3
119 static const int ad7124_master_clk_freq_hz[3] = {
180 .name = "ad7124-4",
185 .name = "ad7124-8",
201 diff_new = abs(val - array[i]); in ad7124_find_closest_match()
220 ret = ad_sd_read_reg(&st->sd, addr, bytes, &readval); in ad7124_spi_write_mask()
227 return ad_sd_write_reg(&st->sd, addr, bytes, readval); in ad7124_spi_write_mask()
235 st->adc_control &= ~AD7124_ADC_CTRL_MODE_MSK; in ad7124_set_mode()
236 st->adc_control |= AD7124_ADC_CTRL_MODE(mode); in ad7124_set_mode()
238 return ad_sd_write_reg(&st->sd, AD7124_ADC_CONTROL, 2, st->adc_control); in ad7124_set_mode()
241 static int ad7124_set_channel(struct ad_sigma_delta *sd, unsigned int channel) in ad7124_set_channel() argument
246 val = st->channel_config[channel].ain | AD7124_CHANNEL_EN(1) | in ad7124_set_channel()
247 AD7124_CHANNEL_SETUP(channel); in ad7124_set_channel()
249 return ad_sd_write_reg(&st->sd, AD7124_CHANNEL(channel), 2, val); in ad7124_set_channel()
263 unsigned int channel, in ad7124_set_channel_odr() argument
269 fclk = clk_get_rate(st->mclk); in ad7124_set_channel_odr()
283 ret = ad7124_spi_write_mask(st, AD7124_FILTER(channel), in ad7124_set_channel_odr()
285 AD7124_FILTER_FS(odr_sel_bits), 3); in ad7124_set_channel_odr()
289 st->channel_config[channel].odr = in ad7124_set_channel_odr()
296 unsigned int channel, in ad7124_set_channel_gain() argument
304 ret = ad7124_spi_write_mask(st, AD7124_CONFIG(channel), in ad7124_set_channel_gain()
310 st->channel_config[channel].pga_bits = res; in ad7124_set_channel_gain()
316 unsigned int channel) in ad7124_get_3db_filter_freq() argument
320 fadc = st->channel_config[channel].odr; in ad7124_get_3db_filter_freq()
322 switch (st->channel_config[channel].filter_type) { in ad7124_get_3db_filter_freq()
328 return -EINVAL; in ad7124_get_3db_filter_freq()
333 unsigned int channel, in ad7124_set_3db_filter_freq() argument
352 if (st->channel_config[channel].filter_type != new_filter) { in ad7124_set_3db_filter_freq()
355 st->channel_config[channel].filter_type = new_filter; in ad7124_set_3db_filter_freq()
356 ret = ad7124_spi_write_mask(st, AD7124_FILTER(channel), in ad7124_set_3db_filter_freq()
359 3); in ad7124_set_3db_filter_freq()
364 return ad7124_set_channel_odr(st, channel, new_odr); in ad7124_set_3db_filter_freq()
380 /* After the conversion is performed, disable the channel */ in ad7124_read_raw()
381 ret = ad_sd_write_reg(&st->sd, in ad7124_read_raw()
382 AD7124_CHANNEL(chan->address), 2, in ad7124_read_raw()
383 st->channel_config[chan->address].ain | in ad7124_read_raw()
390 idx = st->channel_config[chan->address].pga_bits; in ad7124_read_raw()
391 *val = st->channel_config[chan->address].vref_mv; in ad7124_read_raw()
392 if (st->channel_config[chan->address].bipolar) in ad7124_read_raw()
393 *val2 = chan->scan_type.realbits - 1 + idx; in ad7124_read_raw()
395 *val2 = chan->scan_type.realbits + idx; in ad7124_read_raw()
399 if (st->channel_config[chan->address].bipolar) in ad7124_read_raw()
400 *val = -(1 << (chan->scan_type.realbits - 1)); in ad7124_read_raw()
406 *val = st->channel_config[chan->address].odr; in ad7124_read_raw()
410 *val = ad7124_get_3db_filter_freq(st, chan->scan_index); in ad7124_read_raw()
413 return -EINVAL; in ad7124_read_raw()
427 return -EINVAL; in ad7124_write_raw()
429 return ad7124_set_channel_odr(st, chan->address, val); in ad7124_write_raw()
432 return -EINVAL; in ad7124_write_raw()
434 if (st->channel_config[chan->address].bipolar) in ad7124_write_raw()
435 full_scale = 1 << (chan->scan_type.realbits - 1); in ad7124_write_raw()
437 full_scale = 1 << chan->scan_type.realbits; in ad7124_write_raw()
439 vref = st->channel_config[chan->address].vref_mv * 1000000LL; in ad7124_write_raw()
443 return ad7124_set_channel_gain(st, chan->address, gain); in ad7124_write_raw()
446 return -EINVAL; in ad7124_write_raw()
448 return ad7124_set_3db_filter_freq(st, chan->address, val); in ad7124_write_raw()
450 return -EINVAL; in ad7124_write_raw()
463 return -EINVAL; in ad7124_reg_access()
466 ret = ad_sd_read_reg(&st->sd, reg, ad7124_reg_size[reg], in ad7124_reg_access()
469 ret = ad_sd_write_reg(&st->sd, reg, ad7124_reg_size[reg], in ad7124_reg_access()
500 ret = ad_sd_reset(&st->sd, 64); in ad7124_soft_reset()
506 ret = ad_sd_read_reg(&st->sd, AD7124_STATUS, 1, &readval); in ad7124_soft_reset()
515 } while (--timeout); in ad7124_soft_reset()
517 dev_err(&st->sd.spi->dev, "Soft reset failed\n"); in ad7124_soft_reset()
519 return -EIO; in ad7124_soft_reset()
527 ret = ad_sd_read_reg(&st->sd, AD7124_ID, 1, &readval); in ad7124_check_chip_id()
534 if (chip_id != st->chip_info->chip_id) { in ad7124_check_chip_id()
535 dev_err(&st->sd.spi->dev, in ad7124_check_chip_id()
537 st->chip_info->chip_id, chip_id); in ad7124_check_chip_id()
538 return -ENODEV; in ad7124_check_chip_id()
542 dev_err(&st->sd.spi->dev, in ad7124_check_chip_id()
544 return -ENODEV; in ad7124_check_chip_id()
553 unsigned int refsel = st->channel_config[channel_number].refsel; in ad7124_init_channel_vref()
559 if (IS_ERR(st->vref[refsel])) { in ad7124_init_channel_vref()
560 dev_err(&st->sd.spi->dev, in ad7124_init_channel_vref()
563 return PTR_ERR(st->vref[refsel]); in ad7124_init_channel_vref()
565 st->channel_config[channel_number].vref_mv = in ad7124_init_channel_vref()
566 regulator_get_voltage(st->vref[refsel]); in ad7124_init_channel_vref()
568 st->channel_config[channel_number].vref_mv /= 1000; in ad7124_init_channel_vref()
571 st->channel_config[channel_number].vref_mv = 2500; in ad7124_init_channel_vref()
572 st->adc_control &= ~AD7124_ADC_CTRL_REF_EN_MSK; in ad7124_init_channel_vref()
573 st->adc_control |= AD7124_ADC_CTRL_REF_EN(1); in ad7124_init_channel_vref()
574 return ad_sd_write_reg(&st->sd, AD7124_ADC_CONTROL, in ad7124_init_channel_vref()
575 2, st->adc_control); in ad7124_init_channel_vref()
577 dev_err(&st->sd.spi->dev, "Invalid reference %d\n", refsel); in ad7124_init_channel_vref()
578 return -EINVAL; in ad7124_init_channel_vref()
591 unsigned int ain[2], channel = 0, tmp; in ad7124_of_parse_channel_config() local
594 st->num_channels = of_get_available_child_count(np); in ad7124_of_parse_channel_config()
595 if (!st->num_channels) { in ad7124_of_parse_channel_config()
596 dev_err(indio_dev->dev.parent, "no channel children\n"); in ad7124_of_parse_channel_config()
597 return -ENODEV; in ad7124_of_parse_channel_config()
600 chan = devm_kcalloc(indio_dev->dev.parent, st->num_channels, in ad7124_of_parse_channel_config()
603 return -ENOMEM; in ad7124_of_parse_channel_config()
605 chan_config = devm_kcalloc(indio_dev->dev.parent, st->num_channels, in ad7124_of_parse_channel_config()
608 return -ENOMEM; in ad7124_of_parse_channel_config()
610 indio_dev->channels = chan; in ad7124_of_parse_channel_config()
611 indio_dev->num_channels = st->num_channels; in ad7124_of_parse_channel_config()
612 st->channel_config = chan_config; in ad7124_of_parse_channel_config()
615 ret = of_property_read_u32(child, "reg", &channel); in ad7124_of_parse_channel_config()
619 ret = of_property_read_u32_array(child, "diff-channels", in ad7124_of_parse_channel_config()
624 st->channel_config[channel].ain = AD7124_CHANNEL_AINP(ain[0]) | in ad7124_of_parse_channel_config()
626 st->channel_config[channel].bipolar = in ad7124_of_parse_channel_config()
629 ret = of_property_read_u32(child, "adi,reference-select", &tmp); in ad7124_of_parse_channel_config()
631 st->channel_config[channel].refsel = AD7124_INT_REF; in ad7124_of_parse_channel_config()
633 st->channel_config[channel].refsel = tmp; in ad7124_of_parse_channel_config()
635 st->channel_config[channel].buf_positive = in ad7124_of_parse_channel_config()
636 of_property_read_bool(child, "adi,buffered-positive"); in ad7124_of_parse_channel_config()
637 st->channel_config[channel].buf_negative = in ad7124_of_parse_channel_config()
638 of_property_read_bool(child, "adi,buffered-negative"); in ad7124_of_parse_channel_config()
640 chan[channel] = ad7124_channel_template; in ad7124_of_parse_channel_config()
641 chan[channel].address = channel; in ad7124_of_parse_channel_config()
642 chan[channel].scan_index = channel; in ad7124_of_parse_channel_config()
643 chan[channel].channel = ain[0]; in ad7124_of_parse_channel_config()
644 chan[channel].channel2 = ain[1]; in ad7124_of_parse_channel_config()
659 fclk = clk_get_rate(st->mclk); in ad7124_setup()
661 return -EINVAL; in ad7124_setup()
668 ret = clk_set_rate(st->mclk, fclk); in ad7124_setup()
674 st->adc_control &= ~AD7124_ADC_CTRL_PWR_MSK; in ad7124_setup()
675 st->adc_control |= AD7124_ADC_CTRL_PWR(power_mode); in ad7124_setup()
676 ret = ad_sd_write_reg(&st->sd, AD7124_ADC_CONTROL, 2, st->adc_control); in ad7124_setup()
680 for (i = 0; i < st->num_channels; i++) { in ad7124_setup()
681 val = st->channel_config[i].ain | AD7124_CHANNEL_SETUP(i); in ad7124_setup()
682 ret = ad_sd_write_reg(&st->sd, AD7124_CHANNEL(i), 2, val); in ad7124_setup()
690 tmp = (st->channel_config[i].buf_positive << 1) + in ad7124_setup()
691 st->channel_config[i].buf_negative; in ad7124_setup()
693 val = AD7124_CONFIG_BIPOLAR(st->channel_config[i].bipolar) | in ad7124_setup()
694 AD7124_CONFIG_REF_SEL(st->channel_config[i].refsel) | in ad7124_setup()
696 ret = ad_sd_write_reg(&st->sd, AD7124_CONFIG(i), 2, val); in ad7124_setup()
717 info = of_device_get_match_data(&spi->dev); in ad7124_probe()
719 return -ENODEV; in ad7124_probe()
721 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); in ad7124_probe()
723 return -ENOMEM; in ad7124_probe()
727 st->chip_info = info; in ad7124_probe()
729 ad_sd_init(&st->sd, indio_dev, spi, &ad7124_sigma_delta_info); in ad7124_probe()
733 indio_dev->name = st->chip_info->name; in ad7124_probe()
734 indio_dev->modes = INDIO_DIRECT_MODE; in ad7124_probe()
735 indio_dev->info = &ad7124_info; in ad7124_probe()
737 ret = ad7124_of_parse_channel_config(indio_dev, spi->dev.of_node); in ad7124_probe()
741 for (i = 0; i < ARRAY_SIZE(st->vref); i++) { in ad7124_probe()
745 st->vref[i] = devm_regulator_get_optional(&spi->dev, in ad7124_probe()
747 if (PTR_ERR(st->vref[i]) == -ENODEV) in ad7124_probe()
749 else if (IS_ERR(st->vref[i])) in ad7124_probe()
750 return PTR_ERR(st->vref[i]); in ad7124_probe()
752 ret = regulator_enable(st->vref[i]); in ad7124_probe()
757 st->mclk = devm_clk_get(&spi->dev, "mclk"); in ad7124_probe()
758 if (IS_ERR(st->mclk)) { in ad7124_probe()
759 ret = PTR_ERR(st->mclk); in ad7124_probe()
763 ret = clk_prepare_enable(st->mclk); in ad7124_probe()
785 dev_err(&spi->dev, "Failed to register iio device\n"); in ad7124_probe()
794 clk_disable_unprepare(st->mclk); in ad7124_probe()
796 for (i = ARRAY_SIZE(st->vref) - 1; i >= 0; i--) { in ad7124_probe()
797 if (!IS_ERR_OR_NULL(st->vref[i])) in ad7124_probe()
798 regulator_disable(st->vref[i]); in ad7124_probe()
812 clk_disable_unprepare(st->mclk); in ad7124_remove()
814 for (i = ARRAY_SIZE(st->vref) - 1; i >= 0; i--) { in ad7124_remove()
815 if (!IS_ERR_OR_NULL(st->vref[i])) in ad7124_remove()
816 regulator_disable(st->vref[i]); in ad7124_remove()
823 { .compatible = "adi,ad7124-4",
825 { .compatible = "adi,ad7124-8",