Lines Matching +full:manual +full:- +full:span +full:- +full:operation +full:- +full:config
1 // SPDX-License-Identifier: GPL-2.0
3 * LTC2664 4 channel, 12-/16-Bit Voltage Output SoftSpan DAC driver
4 * LTC2672 5 channel, 12-/16-Bit Current Output Softspan DAC driver
92 /* span code of the channel */
93 u8 span; member
115 { -5000, 5000 },
116 { -10000, 10000 },
117 { -2500, 2500 },
134 const struct ltc2664_chan *chan = &st->channels[c]; in ltc2664_scale_get()
135 const int (*span_helper)[2] = st->chip_info->span_helper; in ltc2664_scale_get()
136 int span, fs; in ltc2664_scale_get() local
138 span = chan->span; in ltc2664_scale_get()
139 if (span < 0) in ltc2664_scale_get()
140 return span; in ltc2664_scale_get()
142 fs = span_helper[span][1] - span_helper[span][0]; in ltc2664_scale_get()
144 return fs * st->vref_mv / 2500; in ltc2664_scale_get()
149 const struct ltc2664_chan *chan = &st->channels[c]; in ltc2672_scale_get()
150 int span, fs; in ltc2672_scale_get() local
152 span = chan->span - 1; in ltc2672_scale_get()
153 if (span < 0) in ltc2672_scale_get()
154 return span; in ltc2672_scale_get()
156 fs = 1000 * st->vref_mv; in ltc2672_scale_get()
158 if (span == LTC2672_MAX_SPAN) in ltc2672_scale_get()
159 return mul_u64_u32_div(4800, fs, st->rfsadj_ohms); in ltc2672_scale_get()
161 return mul_u64_u32_div(LTC2672_SCALE_MULTIPLIER(span), fs, st->rfsadj_ohms); in ltc2672_scale_get()
166 const struct ltc2664_chan *chan = &st->channels[c]; in ltc2664_offset_get()
167 int span; in ltc2664_offset_get() local
169 span = chan->span; in ltc2664_offset_get()
170 if (span < 0) in ltc2664_offset_get()
171 return span; in ltc2664_offset_get()
173 if (st->chip_info->span_helper[span][0] < 0) in ltc2664_offset_get()
174 return -32768; in ltc2664_offset_get()
182 struct ltc2664_chan *c = &st->channels[chan]; in ltc2664_dac_code_write()
185 guard(mutex)(&st->lock); in ltc2664_dac_code_write()
187 if (c->toggle_chan) { in ltc2664_dac_code_write()
188 ret = regmap_write(st->regmap, LTC2664_CMD_TOGGLE_SEL, in ltc2664_dac_code_write()
197 if (st->toggle_sel & BIT(chan)) in ltc2664_dac_code_write()
202 ret = regmap_write(st->regmap, reg, code); in ltc2664_dac_code_write()
206 c->raw[input] = code; in ltc2664_dac_code_write()
208 if (c->toggle_chan) { in ltc2664_dac_code_write()
209 ret = regmap_write(st->regmap, LTC2664_CMD_TOGGLE_SEL, in ltc2664_dac_code_write()
210 st->toggle_sel); in ltc2664_dac_code_write()
221 guard(mutex)(&st->lock); in ltc2664_dac_code_read()
222 *code = st->channels[chan].raw[input]; in ltc2664_dac_code_read()
239 return -EINVAL; in ltc2664_read_avail()
251 ltc2664_dac_code_read(st, chan->channel, LTC2664_INPUT_A, val); in ltc2664_read_raw()
255 *val = st->chip_info->offset_get(st, chan->channel); in ltc2664_read_raw()
259 *val = st->chip_info->scale_get(st, chan->channel); in ltc2664_read_raw()
264 return -EINVAL; in ltc2664_read_raw()
277 return -EINVAL; in ltc2664_write_raw()
279 return ltc2664_dac_code_write(st, chan->channel, in ltc2664_write_raw()
282 return -EINVAL; in ltc2664_write_raw()
294 guard(mutex)(&st->lock); in ltc2664_reg_bool_get()
297 val = st->channels[chan->channel].powerdown; in ltc2664_reg_bool_get()
303 val = !!(st->toggle_sel & BIT(chan->channel)); in ltc2664_reg_bool_get()
307 val = st->global_toggle; in ltc2664_reg_bool_get()
311 return -EINVAL; in ltc2664_reg_bool_get()
328 guard(mutex)(&st->lock); in ltc2664_reg_bool_set()
331 ret = regmap_write(st->regmap, in ltc2664_reg_bool_set()
332 en ? LTC2664_CMD_POWER_DOWN_N(chan->channel) : in ltc2664_reg_bool_set()
333 LTC2664_CMD_UPDATE_N(chan->channel), en); in ltc2664_reg_bool_set()
337 st->channels[chan->channel].powerdown = en; in ltc2664_reg_bool_set()
342 st->toggle_sel |= BIT(chan->channel); in ltc2664_reg_bool_set()
344 st->toggle_sel &= ~BIT(chan->channel); in ltc2664_reg_bool_set()
346 ret = regmap_write(st->regmap, LTC2664_CMD_TOGGLE_SEL, in ltc2664_reg_bool_set()
347 st->toggle_sel); in ltc2664_reg_bool_set()
353 ret = regmap_write(st->regmap, LTC2664_CMD_GLOBAL_TOGGLE, en); in ltc2664_reg_bool_set()
357 st->global_toggle = en; in ltc2664_reg_bool_set()
361 return -EINVAL; in ltc2664_reg_bool_set()
378 ltc2664_dac_code_read(st, chan->channel, private, &val); in ltc2664_dac_input_read()
393 return -EINVAL; in ltc2664_dac_input_write()
399 ret = ltc2664_dac_code_write(st, chan->channel, private, val); in ltc2664_dac_input_write()
414 return -EOPNOTSUPP; in ltc2664_reg_access()
416 return regmap_write(st->regmap, reg, writeval); in ltc2664_reg_access()
495 const struct ltc2664_chip_info *chip_info = st->chip_info; in ltc2664_set_span()
496 const int (*span_helper)[2] = chip_info->span_helper; in ltc2664_set_span()
497 int span, ret; in ltc2664_set_span() local
499 for (span = 0; span < chip_info->num_span; span++) { in ltc2664_set_span()
500 if (min == span_helper[span][0] && max == span_helper[span][1]) in ltc2664_set_span()
504 if (span == chip_info->num_span) in ltc2664_set_span()
505 return -EINVAL; in ltc2664_set_span()
507 ret = regmap_write(st->regmap, LTC2664_CMD_SPAN_N(chan), span); in ltc2664_set_span()
511 return span; in ltc2664_set_span()
516 const struct ltc2664_chip_info *chip_info = st->chip_info; in ltc2664_channel_config()
517 struct device *dev = &st->spi->dev; in ltc2664_channel_config()
522 ret = device_property_read_u32(dev, "adi,manual-span-operation-config", in ltc2664_channel_config()
525 if (!chip_info->manual_span_support) in ltc2664_channel_config()
526 return dev_err_probe(dev, -EINVAL, in ltc2664_channel_config()
527 "adi,manual-span-operation-config not supported\n"); in ltc2664_channel_config()
530 return dev_err_probe(dev, -EINVAL, in ltc2664_channel_config()
531 "adi,manual-span-operation-config not in range\n"); in ltc2664_channel_config()
534 st->rfsadj_ohms = 20000; in ltc2664_channel_config()
535 ret = device_property_read_u32(dev, "adi,rfsadj-ohms", &st->rfsadj_ohms); in ltc2664_channel_config()
537 if (!chip_info->rfsadj_support) in ltc2664_channel_config()
538 return dev_err_probe(dev, -EINVAL, in ltc2664_channel_config()
539 "adi,rfsadj-ohms not supported\n"); in ltc2664_channel_config()
541 if (st->rfsadj_ohms < 19000 || st->rfsadj_ohms > 41000) in ltc2664_channel_config()
542 return dev_err_probe(dev, -EINVAL, in ltc2664_channel_config()
543 "adi,rfsadj-ohms not in range\n"); in ltc2664_channel_config()
554 if (reg >= chip_info->num_channels) in ltc2664_channel_config()
555 return dev_err_probe(dev, -EINVAL, in ltc2664_channel_config()
557 chip_info->num_channels); in ltc2664_channel_config()
559 chan = &st->channels[reg]; in ltc2664_channel_config()
561 if (fwnode_property_read_bool(child, "adi,toggle-mode")) { in ltc2664_channel_config()
562 chan->toggle_chan = true; in ltc2664_channel_config()
564 st->iio_channels[reg].ext_info = ltc2664_toggle_sym_ext_info; in ltc2664_channel_config()
571 &st->iio_channels[reg].info_mask_separate); in ltc2664_channel_config()
574 chan->raw[0] = ltc2664_mspan_lut[mspan][1]; in ltc2664_channel_config()
575 chan->raw[1] = ltc2664_mspan_lut[mspan][1]; in ltc2664_channel_config()
577 chan->span = ltc2664_mspan_lut[mspan][0]; in ltc2664_channel_config()
579 ret = fwnode_property_read_u32_array(child, "output-range-microvolt", in ltc2664_channel_config()
585 "Failed to set span\n"); in ltc2664_channel_config()
586 chan->span = ret; in ltc2664_channel_config()
589 ret = fwnode_property_read_u32_array(child, "output-range-microamp", in ltc2664_channel_config()
595 "Failed to set span\n"); in ltc2664_channel_config()
596 chan->span = ret; in ltc2664_channel_config()
605 const struct ltc2664_chip_info *chip_info = st->chip_info; in ltc2664_setup()
610 gpio = devm_gpiod_get_optional(&st->spi->dev, "reset", GPIOD_OUT_HIGH); in ltc2664_setup()
612 return dev_err_probe(&st->spi->dev, PTR_ERR(gpio), in ltc2664_setup()
623 st->iio_channels = devm_kcalloc(&st->spi->dev, in ltc2664_setup()
624 chip_info->num_channels, in ltc2664_setup()
627 if (!st->iio_channels) in ltc2664_setup()
628 return -ENOMEM; in ltc2664_setup()
630 for (i = 0; i < chip_info->num_channels; i++) { in ltc2664_setup()
631 st->iio_channels[i] = ltc2664_channel_template; in ltc2664_setup()
632 st->iio_channels[i].type = chip_info->measurement_type; in ltc2664_setup()
633 st->iio_channels[i].channel = i; in ltc2664_setup()
640 return regmap_set_bits(st->regmap, LTC2664_CMD_CONFIG, LTC2664_REF_DISABLE); in ltc2664_setup()
658 static const char * const regulators[] = { "vcc", "iovcc", "v-neg" }; in ltc2664_probe()
660 struct device *dev = &spi->dev; in ltc2664_probe()
667 return -ENOMEM; in ltc2664_probe()
670 st->spi = spi; in ltc2664_probe()
674 return -ENODEV; in ltc2664_probe()
676 st->chip_info = chip_info; in ltc2664_probe()
678 mutex_init(&st->lock); in ltc2664_probe()
680 st->regmap = devm_regmap_init_spi(spi, <c2664_regmap_config); in ltc2664_probe()
681 if (IS_ERR(st->regmap)) in ltc2664_probe()
682 return dev_err_probe(dev, PTR_ERR(st->regmap), in ltc2664_probe()
691 if (ret < 0 && ret != -ENODEV) in ltc2664_probe()
694 st->vref_mv = ret > 0 ? ret / 1000 : chip_info->internal_vref_mv; in ltc2664_probe()
700 indio_dev->name = chip_info->name; in ltc2664_probe()
701 indio_dev->info = <c2664_info; in ltc2664_probe()
702 indio_dev->modes = INDIO_DIRECT_MODE; in ltc2664_probe()
703 indio_dev->channels = st->iio_channels; in ltc2664_probe()
704 indio_dev->num_channels = chip_info->num_channels; in ltc2664_probe()