Lines Matching +full:vref +full:- +full:out +full:- +full:en
1 // SPDX-License-Identifier: GPL-2.0
54 #define LTC2688_DITHER_RAW_MAX_VAL (BIT(14) - 1)
55 #define LTC2688_CH_CALIBBIAS_MAX_VAL (BIT(14) - 1)
91 int vref; member
106 .tx_buf = st->tx_data, in ltc2688_spi_read()
111 .tx_buf = st->tx_data + 3, in ltc2688_spi_read()
112 .rx_buf = st->rx_data, in ltc2688_spi_read()
119 memcpy(st->tx_data, reg, reg_size); in ltc2688_spi_read()
121 ret = spi_sync_transfer(st->spi, xfers, ARRAY_SIZE(xfers)); in ltc2688_spi_read()
125 memcpy(val, &st->rx_data[1], val_size); in ltc2688_spi_read()
134 return spi_write(st->spi, data, count); in ltc2688_spi_write()
141 ret = regmap_read(st->regmap, LTC2688_CMD_CH_SETTING(c), ®); in ltc2688_span_get()
148 return -EIO; in ltc2688_span_get()
154 {0, 5000}, {0, 10000}, {-5000, 5000}, {-10000, 10000}, {-15000, 15000},
159 const struct ltc2688_chan *chan = &st->channels[c]; in ltc2688_scale_get()
166 fs = ltc2688_span_helper[span][1] - ltc2688_span_helper[span][0]; in ltc2688_scale_get()
167 if (chan->overrange) in ltc2688_scale_get()
170 *val = DIV_ROUND_CLOSEST(fs * st->vref, 4096); in ltc2688_scale_get()
184 *val = -32768; in ltc2688_offset_get()
202 struct ltc2688_chan *c = &st->channels[chan]; in ltc2688_dac_code_write()
206 if (!c->toggle_chan && input == LTC2688_INPUT_B) { in ltc2688_dac_code_write()
208 return -EINVAL; in ltc2688_dac_code_write()
213 mutex_lock(&st->lock); in ltc2688_dac_code_write()
215 ret = regmap_update_bits(st->regmap, LTC2688_CMD_A_B_SELECT, BIT(chan), in ltc2688_dac_code_write()
224 if (c->mode == LTC2688_MODE_DEFAULT) in ltc2688_dac_code_write()
229 ret = regmap_write(st->regmap, reg, code); in ltc2688_dac_code_write()
231 mutex_unlock(&st->lock); in ltc2688_dac_code_write()
238 struct ltc2688_chan *c = &st->channels[chan]; in ltc2688_dac_code_read()
241 mutex_lock(&st->lock); in ltc2688_dac_code_read()
242 ret = regmap_update_bits(st->regmap, LTC2688_CMD_A_B_SELECT, BIT(chan), in ltc2688_dac_code_read()
247 ret = regmap_read(st->regmap, LTC2688_CMD_CH_CODE(chan), code); in ltc2688_dac_code_read()
249 mutex_unlock(&st->lock); in ltc2688_dac_code_read()
251 if (!c->toggle_chan && input == LTC2688_INPUT_B) in ltc2688_dac_code_read()
270 return -EINVAL; in ltc2688_read_avail()
283 ret = ltc2688_dac_code_read(st, chan->channel, LTC2688_INPUT_A, in ltc2688_read_raw()
290 ret = ltc2688_offset_get(st, chan->channel, val); in ltc2688_read_raw()
296 ret = ltc2688_scale_get(st, chan->channel, val); in ltc2688_read_raw()
303 ret = regmap_read(st->regmap, in ltc2688_read_raw()
304 LTC2688_CMD_CH_OFFSET(chan->channel), val); in ltc2688_read_raw()
311 ret = regmap_read(st->regmap, in ltc2688_read_raw()
312 LTC2688_CMD_CH_GAIN(chan->channel), val); in ltc2688_read_raw()
318 return -EINVAL; in ltc2688_read_raw()
331 return -EINVAL; in ltc2688_write_raw()
333 return ltc2688_dac_code_write(st, chan->channel, in ltc2688_write_raw()
337 return -EINVAL; in ltc2688_write_raw()
339 return regmap_write(st->regmap, in ltc2688_write_raw()
340 LTC2688_CMD_CH_OFFSET(chan->channel), in ltc2688_write_raw()
343 return regmap_write(st->regmap, in ltc2688_write_raw()
344 LTC2688_CMD_CH_GAIN(chan->channel), val); in ltc2688_write_raw()
346 return -EINVAL; in ltc2688_write_raw()
356 struct ltc2688_chan *c = &st->channels[chan->channel]; in ltc2688_dither_toggle_set()
358 bool en; in ltc2688_dither_toggle_set() local
360 ret = kstrtobool(buf, &en); in ltc2688_dither_toggle_set()
364 mutex_lock(&st->lock); in ltc2688_dither_toggle_set()
365 ret = regmap_update_bits(st->regmap, LTC2688_CMD_TOGGLE_DITHER_EN, in ltc2688_dither_toggle_set()
366 BIT(chan->channel), en << chan->channel); in ltc2688_dither_toggle_set()
370 c->mode = en ? LTC2688_MODE_DITHER_TOGGLE : LTC2688_MODE_DEFAULT; in ltc2688_dither_toggle_set()
372 mutex_unlock(&st->lock); in ltc2688_dither_toggle_set()
386 ret = regmap_read(st->regmap, private, &val); in ltc2688_reg_bool_get()
390 return sysfs_emit(buf, "%u\n", !!(val & BIT(chan->channel))); in ltc2688_reg_bool_get()
400 bool en; in ltc2688_reg_bool_set() local
402 ret = kstrtobool(buf, &en); in ltc2688_reg_bool_set()
406 ret = regmap_update_bits(st->regmap, private, BIT(chan->channel), in ltc2688_reg_bool_set()
407 en << chan->channel); in ltc2688_reg_bool_set()
421 for (f = 0; f < ARRAY_SIZE(chan->dither_frequency); f++) in ltc2688_dither_freq_avail()
422 sz += sysfs_emit_at(buf, sz, "%ld ", chan->dither_frequency[f]); in ltc2688_dither_freq_avail()
424 buf[sz - 1] = '\n'; in ltc2688_dither_freq_avail()
435 const struct ltc2688_chan *c = &st->channels[chan->channel]; in ltc2688_dither_freq_get()
442 ret = regmap_read(st->regmap, LTC2688_CMD_CH_SETTING(chan->channel), in ltc2688_dither_freq_get()
448 if (freq >= ARRAY_SIZE(c->dither_frequency)) in ltc2688_dither_freq_get()
449 return -EIO; in ltc2688_dither_freq_get()
451 return sysfs_emit(buf, "%ld\n", c->dither_frequency[freq]); in ltc2688_dither_freq_get()
460 const struct ltc2688_chan *c = &st->channels[chan->channel]; in ltc2688_dither_freq_set()
466 return -EINVAL; in ltc2688_dither_freq_set()
472 for (freq = 0; freq < ARRAY_SIZE(c->dither_frequency); freq++) { in ltc2688_dither_freq_set()
473 if (val == c->dither_frequency[freq]) in ltc2688_dither_freq_set()
477 if (freq == ARRAY_SIZE(c->dither_frequency)) in ltc2688_dither_freq_set()
478 return -EINVAL; in ltc2688_dither_freq_set()
480 ret = regmap_update_bits(st->regmap, in ltc2688_dither_freq_set()
481 LTC2688_CMD_CH_SETTING(chan->channel), in ltc2688_dither_freq_set()
507 ret = ltc2688_dac_code_read(st, chan->channel, private, &val); in ltc2688_dac_input_read()
524 return -EINVAL; in ltc2688_dac_input_write()
530 ret = ltc2688_dac_code_write(st, chan->channel, private, val); in ltc2688_dac_input_write()
543 ret = regmap_read(st->regmap, LTC2688_CMD_CH_SETTING(chan->channel), in ltc2688_get_dither_phase()
557 return regmap_update_bits(st->regmap, in ltc2688_set_dither_phase()
558 LTC2688_CMD_CH_SETTING(chan->channel), in ltc2688_set_dither_phase()
571 return regmap_read(st->regmap, reg, readval); in ltc2688_reg_access()
573 return regmap_write(st->regmap, reg, writeval); in ltc2688_reg_access()
705 struct device *dev = &st->spi->dev; in ltc2688_tgp_clk_setup()
722 if (chan->toggle_chan) in ltc2688_tgp_clk_setup()
727 for (f = 0; f < ARRAY_SIZE(chan->dither_frequency); f++) in ltc2688_tgp_clk_setup()
728 chan->dither_frequency[f] = DIV_ROUND_CLOSEST(rate, ltc2688_period[f]); in ltc2688_tgp_clk_setup()
743 return -EINVAL; in ltc2688_span_lookup()
748 struct device *dev = &st->spi->dev; in ltc2688_channel_config()
761 return dev_err_probe(dev, -EINVAL, in ltc2688_channel_config()
766 chan = &st->channels[reg]; in ltc2688_channel_config()
767 if (fwnode_property_read_bool(child, "adi,toggle-mode")) { in ltc2688_channel_config()
768 chan->toggle_chan = true; in ltc2688_channel_config()
770 st->iio_chan[reg].ext_info = ltc2688_toggle_sym_ext_info; in ltc2688_channel_config()
776 &st->iio_chan[reg].info_mask_separate); in ltc2688_channel_config()
779 ret = fwnode_property_read_u32_array(child, "adi,output-range-microvolt", in ltc2688_channel_config()
792 ret = fwnode_property_read_u32(child, "adi,toggle-dither-input", in ltc2688_channel_config()
796 return dev_err_probe(dev, -EINVAL, in ltc2688_channel_config()
797 "toggle-dither-input inv value(%d)\n", in ltc2688_channel_config()
818 if (!chan->toggle_chan) { in ltc2688_channel_config()
820 st->iio_chan[reg].ext_info = ltc2688_dither_ext_info; in ltc2688_channel_config()
823 st->iio_chan[reg].ext_info = ltc2688_toggle_ext_info; in ltc2688_channel_config()
828 chan->overrange = true; in ltc2688_channel_config()
835 ret = regmap_write(st->regmap, LTC2688_CMD_CH_SETTING(reg), in ltc2688_channel_config()
845 static int ltc2688_setup(struct ltc2688_state *st, struct regulator *vref) in ltc2688_setup() argument
847 struct device *dev = &st->spi->dev; in ltc2688_setup()
860 /* bring device out of reset */ in ltc2688_setup()
863 ret = regmap_set_bits(st->regmap, LTC2688_CMD_CONFIG, in ltc2688_setup()
875 st->iio_chan = devm_kmemdup(dev, ltc2688_channels, in ltc2688_setup()
877 if (!st->iio_chan) in ltc2688_setup()
878 return -ENOMEM; in ltc2688_setup()
884 if (!vref) in ltc2688_setup()
887 return regmap_set_bits(st->regmap, LTC2688_CMD_CONFIG, in ltc2688_setup()
951 struct device *dev = &spi->dev; in ltc2688_probe()
956 return -ENOMEM; in ltc2688_probe()
959 st->spi = spi; in ltc2688_probe()
962 st->tx_data[3] = LTC2688_CMD_NOOP; in ltc2688_probe()
963 mutex_init(&st->lock); in ltc2688_probe()
965 st->regmap = devm_regmap_init(dev, <c2688_regmap_bus, st, in ltc2688_probe()
967 if (IS_ERR(st->regmap)) in ltc2688_probe()
968 return dev_err_probe(dev, PTR_ERR(st->regmap), in ltc2688_probe()
976 vref_reg = devm_regulator_get_optional(dev, "vref"); in ltc2688_probe()
978 if (PTR_ERR(vref_reg) != -ENODEV) in ltc2688_probe()
980 "Failed to get vref regulator"); in ltc2688_probe()
984 st->vref = 4096; in ltc2688_probe()
989 "Failed to enable vref regulators\n"); in ltc2688_probe()
998 return dev_err_probe(dev, ret, "Failed to get vref\n"); in ltc2688_probe()
1000 st->vref = ret / 1000; in ltc2688_probe()
1007 indio_dev->name = "ltc2688"; in ltc2688_probe()
1008 indio_dev->info = <c2688_info; in ltc2688_probe()
1009 indio_dev->modes = INDIO_DIRECT_MODE; in ltc2688_probe()
1010 indio_dev->channels = st->iio_chan; in ltc2688_probe()
1011 indio_dev->num_channels = ARRAY_SIZE(ltc2688_channels); in ltc2688_probe()