Lines Matching +full:vref +full:- +full:p
1 // SPDX-License-Identifier: GPL-2.0-only
175 /* This driver only needs to write 8-bit registers */ in max11410_write_reg()
177 return -EINVAL; in max11410_write_reg()
179 return regmap_write(st->regmap, reg, val); in max11410_write_reg()
188 ret = regmap_bulk_read(st->regmap, reg, &st->scan.data, 3); in max11410_read_reg()
192 *val = get_unaligned_be24(&st->scan.data); in max11410_read_reg()
196 return regmap_read(st->regmap, reg, val); in max11410_read_reg()
204 return st->avdd; in max11410_get_vrefp()
206 return st->vrefp[refsel]; in max11410_get_vrefp()
215 return st->vrefn[refsel]; in max11410_get_vrefn()
238 switch (iio_attr->address) { in max11410_notch_en_show()
249 return -EINVAL; in max11410_notch_en_show()
270 switch (iio_attr->address) { in max11410_notch_en_store()
285 ret = regmap_clear_bits(state->regmap, MAX11410_REG_FILTER, in max11410_notch_en_store()
288 ret = regmap_set_bits(state->regmap, MAX11410_REG_FILTER, in max11410_notch_en_store()
305 ret = regmap_read(state->regmap, MAX11410_REG_FILTER, ®); in in_voltage_filter2_notch_center_show()
311 max11410_sampling_len[MAX11410_FILTER_SINC4] - 1); in in_voltage_filter2_notch_center_show()
346 return -EINVAL; in max11410_set_input_mux()
355 struct max11410_channel_config cfg = st->channels[chan->address]; in max11410_configure_channel()
359 if (chan->differential) in max11410_configure_channel()
360 ret = max11410_set_input_mux(st, chan->channel, chan->channel2); in max11410_configure_channel()
362 ret = max11410_set_input_mux(st, chan->channel, in max11410_configure_channel()
372 ret = regmap_update_bits(st->regmap, MAX11410_REG_CTRL, in max11410_configure_channel()
382 ret = regmap_write(st->regmap, MAX11410_REG_PGA, regval); in max11410_configure_channel()
401 if (st->irq > 0) in max11410_sample()
402 reinit_completion(&st->completion); in max11410_sample()
410 if (st->irq > 0) { in max11410_sample()
412 ret = wait_for_completion_timeout(&st->completion, in max11410_sample()
415 return -ETIMEDOUT; in max11410_sample()
445 scale -= regulator_get_voltage(vrefn) / 1000; in max11410_get_scale()
458 struct max11410_channel_config cfg = state->channels[chan->address]; in max11410_read_raw()
464 *val2 = chan->scan_type.realbits; in max11410_read_raw()
468 *val = -BIT(chan->scan_type.realbits - 1); in max11410_read_raw()
478 mutex_lock(&state->lock); in max11410_read_raw()
482 mutex_unlock(&state->lock); in max11410_read_raw()
493 ret = regmap_read(state->regmap, MAX11410_REG_FILTER, ®_val); in max11410_read_raw()
500 rate = max11410_sampling_len[filter] - 1; in max11410_read_raw()
507 return -EINVAL; in max11410_read_raw()
520 scale_avail = st->channels[chan->address].scale_avail; in max11410_write_raw()
522 return -EOPNOTSUPP; in max11410_write_raw()
526 return -EINVAL; in max11410_write_raw()
537 st->channels[chan->address].gain = clamp_val(gain, 0, 7); in max11410_write_raw()
547 mutex_lock(&st->lock); in max11410_write_raw()
549 ret = regmap_read(st->regmap, MAX11410_REG_FILTER, ®_val); in max11410_write_raw()
561 ret = -EINVAL; in max11410_write_raw()
565 ret = regmap_write_bits(st->regmap, MAX11410_REG_FILTER, in max11410_write_raw()
569 mutex_unlock(&st->lock); in max11410_write_raw()
574 return -EINVAL; in max11410_write_raw()
589 ret = regmap_read(st->regmap, MAX11410_REG_FILTER, ®_val); in max11410_read_avail()
601 cfg = st->channels[chan->address]; in max11410_read_avail()
604 return -EINVAL; in max11410_read_avail()
612 return -EINVAL; in max11410_read_avail()
622 static irqreturn_t max11410_trigger_handler(int irq, void *p) in max11410_trigger_handler() argument
624 struct iio_poll_func *pf = p; in max11410_trigger_handler()
625 struct iio_dev *indio_dev = pf->indio_dev; in max11410_trigger_handler()
629 ret = max11410_read_reg(st, MAX11410_REG_DATA0, &st->scan.data); in max11410_trigger_handler()
631 dev_err(&indio_dev->dev, "cannot read data\n"); in max11410_trigger_handler()
635 iio_push_to_buffers_with_timestamp(indio_dev, &st->scan, in max11410_trigger_handler()
639 iio_trigger_notify_done(indio_dev->trig); in max11410_trigger_handler()
649 scan_ch = ffs(*indio_dev->active_scan_mask) - 1; in max11410_buffer_postenable()
651 ret = max11410_configure_channel(st, &indio_dev->channels[scan_ch]); in max11410_buffer_postenable()
685 iio_trigger_poll_nested(st->trig); in max11410_interrupt()
687 complete(&st->completion); in max11410_interrupt()
696 struct device *dev = &st->spi_dev->dev; in max11410_parse_channels()
708 return dev_err_probe(&indio_dev->dev, -ENODEV, in max11410_parse_channels()
715 return -ENOMEM; in max11410_parse_channels()
717 st->channels = devm_kcalloc(dev, num_ch, sizeof(*st->channels), in max11410_parse_channels()
719 if (!st->channels) in max11410_parse_channels()
720 return -ENOMEM; in max11410_parse_channels()
724 if (fwnode_property_present(child, "diff-channels")) { in max11410_parse_channels()
726 "diff-channels", in max11410_parse_channels()
742 return dev_err_probe(&indio_dev->dev, -EINVAL, in max11410_parse_channels()
747 cfg = &st->channels[chan_idx]; in max11410_parse_channels()
752 return dev_err_probe(&indio_dev->dev, -EINVAL, in max11410_parse_channels()
758 return dev_err_probe(&indio_dev->dev, -EINVAL, in max11410_parse_channels()
759 …"Invalid VREF configuration for %s, either specify corresponding VREF regulators or change adi,ref… in max11410_parse_channels()
763 fwnode_property_read_u32(child, "adi,input-mode", &sig_path); in max11410_parse_channels()
765 return dev_err_probe(&indio_dev->dev, -EINVAL, in max11410_parse_channels()
766 "Invalid adi,input-mode value for %s, should be less than %d.\n", in max11410_parse_channels()
769 fwnode_property_read_u32(child, "settling-time-us", in max11410_parse_channels()
770 &cfg->settling_time_us); in max11410_parse_channels()
771 cfg->bipolar = fwnode_property_read_bool(child, "bipolar"); in max11410_parse_channels()
772 cfg->buffered_vrefp = fwnode_property_read_bool(child, "adi,buffered-vrefp"); in max11410_parse_channels()
773 cfg->buffered_vrefn = fwnode_property_read_bool(child, "adi,buffered-vrefn"); in max11410_parse_channels()
774 cfg->refsel = reference; in max11410_parse_channels()
775 cfg->sig_path = sig_path; in max11410_parse_channels()
776 cfg->gain = 0; in max11410_parse_channels()
782 cfg->scale_avail = devm_kcalloc(dev, MAX11410_SCALE_AVAIL_SIZE * 2, in max11410_parse_channels()
783 sizeof(*cfg->scale_avail), in max11410_parse_channels()
785 if (!cfg->scale_avail) in max11410_parse_channels()
786 return -ENOMEM; in max11410_parse_channels()
790 cfg->scale_avail[2 * i] = scale >> i; in max11410_parse_channels()
791 cfg->scale_avail[2 * i + 1] = chanspec.scan_type.realbits; in max11410_parse_channels()
809 indio_dev->num_channels = chan_idx + 1; in max11410_parse_channels()
810 indio_dev->channels = channels; in max11410_parse_channels()
821 struct regulator **vref, in max11410_init_vref() argument
828 if (PTR_ERR(reg) == -ENODEV) { in max11410_init_vref()
829 *vref = NULL; in max11410_init_vref()
839 *vref = reg; in max11410_init_vref()
866 ret = regmap_write_bits(st->regmap, MAX11410_REG_FILTER, in max11410_self_calibrate()
877 ret = regmap_write_bits(st->regmap, MAX11410_REG_PGA, in max11410_self_calibrate()
886 ret = regmap_write_bits(st->regmap, MAX11410_REG_PGA, in max11410_self_calibrate()
897 ret = regmap_write_bits(st->regmap, MAX11410_REG_PGA, in max11410_self_calibrate()
902 ret = regmap_write_bits(st->regmap, MAX11410_REG_FILTER, in max11410_self_calibrate()
907 return regmap_write_bits(st->regmap, MAX11410_REG_PGA, in max11410_self_calibrate()
917 struct device *dev = &spi->dev; in max11410_probe()
925 return -ENOMEM; in max11410_probe()
928 st->spi_dev = spi; in max11410_probe()
929 init_completion(&st->completion); in max11410_probe()
930 mutex_init(&st->lock); in max11410_probe()
932 indio_dev->name = "max11410"; in max11410_probe()
933 indio_dev->modes = INDIO_DIRECT_MODE; in max11410_probe()
934 indio_dev->info = &max11410_info; in max11410_probe()
936 st->regmap = devm_regmap_init_spi(spi, ®map_config); in max11410_probe()
937 if (IS_ERR(st->regmap)) in max11410_probe()
938 return dev_err_probe(dev, PTR_ERR(st->regmap), in max11410_probe()
941 ret = max11410_init_vref(dev, &st->avdd, "avdd"); in max11410_probe()
946 ret = max11410_init_vref(dev, &st->vrefp[i], vrefp_regs[i]); in max11410_probe()
950 ret = max11410_init_vref(dev, &st->vrefn[i], vrefn_regs[i]); in max11410_probe()
967 st->irq = irqs[0]; in max11410_probe()
968 ret = regmap_write(st->regmap, MAX11410_REG_GPIO_CTRL(0), in max11410_probe()
971 st->irq = irqs[1]; in max11410_probe()
972 ret = regmap_write(st->regmap, MAX11410_REG_GPIO_CTRL(1), in max11410_probe()
974 } else if (spi->irq > 0) { in max11410_probe()
975 return dev_err_probe(dev, -ENODEV, in max11410_probe()
982 ret = regmap_set_bits(st->regmap, MAX11410_REG_CTRL, in max11410_probe()
993 if (st->irq > 0) { in max11410_probe()
994 st->trig = devm_iio_trigger_alloc(dev, "%s-dev%d", in max11410_probe()
995 indio_dev->name, in max11410_probe()
997 if (!st->trig) in max11410_probe()
998 return -ENOMEM; in max11410_probe()
1000 st->trig->ops = &max11410_trigger_ops; in max11410_probe()
1001 ret = devm_iio_trigger_register(dev, st->trig); in max11410_probe()
1005 ret = devm_request_threaded_irq(dev, st->irq, NULL, in max11410_probe()