Lines Matching +full:toggle +full:- +full:dither +full:- +full:input
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)
107 .tx_buf = st->tx_data, in ltc2688_spi_read()
112 .tx_buf = st->tx_data + 3, in ltc2688_spi_read()
113 .rx_buf = st->rx_data, in ltc2688_spi_read()
120 memcpy(st->tx_data, reg, reg_size); in ltc2688_spi_read()
122 ret = spi_sync_transfer(st->spi, xfers, ARRAY_SIZE(xfers)); in ltc2688_spi_read()
126 memcpy(val, &st->rx_data[1], val_size); in ltc2688_spi_read()
135 return spi_write(st->spi, data, count); in ltc2688_spi_write()
142 ret = regmap_read(st->regmap, LTC2688_CMD_CH_SETTING(c), ®); in ltc2688_span_get()
149 return -EIO; in ltc2688_span_get()
155 {0, 5000}, {0, 10000}, {-5000, 5000}, {-10000, 10000}, {-15000, 15000},
160 const struct ltc2688_chan *chan = &st->channels[c]; in ltc2688_scale_get()
167 fs = ltc2688_span_helper[span][1] - ltc2688_span_helper[span][0]; in ltc2688_scale_get()
168 if (chan->overrange) in ltc2688_scale_get()
171 *val = DIV_ROUND_CLOSEST(fs * st->vref, 4096); in ltc2688_scale_get()
185 *val = -32768; in ltc2688_offset_get()
200 static int ltc2688_dac_code_write(struct ltc2688_state *st, u32 chan, u32 input, in ltc2688_dac_code_write() argument
203 struct ltc2688_chan *c = &st->channels[chan]; in ltc2688_dac_code_write()
206 /* 2 LSBs set to 0 if writing dither amplitude */ in ltc2688_dac_code_write()
207 if (!c->toggle_chan && input == LTC2688_INPUT_B) { in ltc2688_dac_code_write()
209 return -EINVAL; in ltc2688_dac_code_write()
214 mutex_lock(&st->lock); in ltc2688_dac_code_write()
215 /* select the correct input register to read from */ in ltc2688_dac_code_write()
216 ret = regmap_update_bits(st->regmap, LTC2688_CMD_A_B_SELECT, BIT(chan), in ltc2688_dac_code_write()
217 input << chan); in ltc2688_dac_code_write()
222 * If in dither/toggle mode the dac should be updated by an in ltc2688_dac_code_write()
223 * external signal (or sw toggle) and not here. in ltc2688_dac_code_write()
225 if (c->mode == LTC2688_MODE_DEFAULT) in ltc2688_dac_code_write()
230 ret = regmap_write(st->regmap, reg, code); in ltc2688_dac_code_write()
232 mutex_unlock(&st->lock); in ltc2688_dac_code_write()
236 static int ltc2688_dac_code_read(struct ltc2688_state *st, u32 chan, u32 input, in ltc2688_dac_code_read() argument
239 struct ltc2688_chan *c = &st->channels[chan]; in ltc2688_dac_code_read()
242 mutex_lock(&st->lock); in ltc2688_dac_code_read()
243 ret = regmap_update_bits(st->regmap, LTC2688_CMD_A_B_SELECT, BIT(chan), in ltc2688_dac_code_read()
244 input << chan); in ltc2688_dac_code_read()
248 ret = regmap_read(st->regmap, LTC2688_CMD_CH_CODE(chan), code); in ltc2688_dac_code_read()
250 mutex_unlock(&st->lock); in ltc2688_dac_code_read()
252 if (!c->toggle_chan && input == LTC2688_INPUT_B) in ltc2688_dac_code_read()
271 return -EINVAL; in ltc2688_read_avail()
284 ret = ltc2688_dac_code_read(st, chan->channel, LTC2688_INPUT_A, in ltc2688_read_raw()
291 ret = ltc2688_offset_get(st, chan->channel, val); in ltc2688_read_raw()
297 ret = ltc2688_scale_get(st, chan->channel, val); in ltc2688_read_raw()
304 ret = regmap_read(st->regmap, in ltc2688_read_raw()
305 LTC2688_CMD_CH_OFFSET(chan->channel), val); in ltc2688_read_raw()
312 ret = regmap_read(st->regmap, in ltc2688_read_raw()
313 LTC2688_CMD_CH_GAIN(chan->channel), val); in ltc2688_read_raw()
319 return -EINVAL; in ltc2688_read_raw()
332 return -EINVAL; in ltc2688_write_raw()
334 return ltc2688_dac_code_write(st, chan->channel, in ltc2688_write_raw()
338 return -EINVAL; in ltc2688_write_raw()
340 return regmap_write(st->regmap, in ltc2688_write_raw()
341 LTC2688_CMD_CH_OFFSET(chan->channel), in ltc2688_write_raw()
344 return regmap_write(st->regmap, in ltc2688_write_raw()
345 LTC2688_CMD_CH_GAIN(chan->channel), val); in ltc2688_write_raw()
347 return -EINVAL; in ltc2688_write_raw()
357 struct ltc2688_chan *c = &st->channels[chan->channel]; in ltc2688_dither_toggle_set()
365 mutex_lock(&st->lock); in ltc2688_dither_toggle_set()
366 ret = regmap_update_bits(st->regmap, LTC2688_CMD_TOGGLE_DITHER_EN, in ltc2688_dither_toggle_set()
367 BIT(chan->channel), en << chan->channel); in ltc2688_dither_toggle_set()
371 c->mode = en ? LTC2688_MODE_DITHER_TOGGLE : LTC2688_MODE_DEFAULT; in ltc2688_dither_toggle_set()
373 mutex_unlock(&st->lock); in ltc2688_dither_toggle_set()
387 ret = regmap_read(st->regmap, private, &val); in ltc2688_reg_bool_get()
391 return sysfs_emit(buf, "%u\n", !!(val & BIT(chan->channel))); in ltc2688_reg_bool_get()
407 ret = regmap_update_bits(st->regmap, private, BIT(chan->channel), in ltc2688_reg_bool_set()
408 en << chan->channel); in ltc2688_reg_bool_set()
422 for (f = 0; f < ARRAY_SIZE(chan->dither_frequency); f++) in ltc2688_dither_freq_avail()
423 sz += sysfs_emit_at(buf, sz, "%ld ", chan->dither_frequency[f]); in ltc2688_dither_freq_avail()
425 buf[sz - 1] = '\n'; in ltc2688_dither_freq_avail()
436 const struct ltc2688_chan *c = &st->channels[chan->channel]; in ltc2688_dither_freq_get()
443 ret = regmap_read(st->regmap, LTC2688_CMD_CH_SETTING(chan->channel), in ltc2688_dither_freq_get()
449 if (freq >= ARRAY_SIZE(c->dither_frequency)) in ltc2688_dither_freq_get()
450 return -EIO; in ltc2688_dither_freq_get()
452 return sysfs_emit(buf, "%ld\n", c->dither_frequency[freq]); in ltc2688_dither_freq_get()
461 const struct ltc2688_chan *c = &st->channels[chan->channel]; in ltc2688_dither_freq_set()
467 return -EINVAL; in ltc2688_dither_freq_set()
473 for (freq = 0; freq < ARRAY_SIZE(c->dither_frequency); freq++) { in ltc2688_dither_freq_set()
474 if (val == c->dither_frequency[freq]) in ltc2688_dither_freq_set()
478 if (freq == ARRAY_SIZE(c->dither_frequency)) in ltc2688_dither_freq_set()
479 return -EINVAL; in ltc2688_dither_freq_set()
481 ret = regmap_update_bits(st->regmap, in ltc2688_dither_freq_set()
482 LTC2688_CMD_CH_SETTING(chan->channel), in ltc2688_dither_freq_set()
508 ret = ltc2688_dac_code_read(st, chan->channel, private, &val); in ltc2688_dac_input_read()
525 return -EINVAL; in ltc2688_dac_input_write()
531 ret = ltc2688_dac_code_write(st, chan->channel, private, val); in ltc2688_dac_input_write()
544 ret = regmap_read(st->regmap, LTC2688_CMD_CH_SETTING(chan->channel), in ltc2688_get_dither_phase()
558 return regmap_update_bits(st->regmap, in ltc2688_set_dither_phase()
559 LTC2688_CMD_CH_SETTING(chan->channel), in ltc2688_set_dither_phase()
572 return regmap_read(st->regmap, reg, readval); in ltc2688_reg_access()
574 return regmap_write(st->regmap, reg, writeval); in ltc2688_reg_access()
597 * For toggle mode we only expose the symbol attr (sw_toggle) in case a TGPx is
706 struct device *dev = &st->spi->dev; in ltc2688_tgp_clk_setup()
723 if (chan->toggle_chan) in ltc2688_tgp_clk_setup()
726 /* calculate available dither frequencies */ in ltc2688_tgp_clk_setup()
728 for (f = 0; f < ARRAY_SIZE(chan->dither_frequency); f++) in ltc2688_tgp_clk_setup()
729 chan->dither_frequency[f] = DIV_ROUND_CLOSEST(rate, ltc2688_period[f]); in ltc2688_tgp_clk_setup()
744 return -EINVAL; in ltc2688_span_lookup()
749 struct device *dev = &st->spi->dev; in ltc2688_channel_config()
766 return dev_err_probe(dev, -EINVAL, in ltc2688_channel_config()
772 chan = &st->channels[reg]; in ltc2688_channel_config()
773 if (fwnode_property_read_bool(child, "adi,toggle-mode")) { in ltc2688_channel_config()
774 chan->toggle_chan = true; in ltc2688_channel_config()
775 /* assume sw toggle ABI */ in ltc2688_channel_config()
776 st->iio_chan[reg].ext_info = ltc2688_toggle_sym_ext_info; in ltc2688_channel_config()
778 * Clear IIO_CHAN_INFO_RAW bit as toggle channels expose in ltc2688_channel_config()
782 &st->iio_chan[reg].info_mask_separate); in ltc2688_channel_config()
785 ret = fwnode_property_read_u32_array(child, "adi,output-range-microvolt", in ltc2688_channel_config()
792 return dev_err_probe(dev, -EINVAL, in ltc2688_channel_config()
800 ret = fwnode_property_read_u32(child, "adi,toggle-dither-input", in ltc2688_channel_config()
805 return dev_err_probe(dev, -EINVAL, in ltc2688_channel_config()
806 "toggle-dither-input inv value(%d)\n", in ltc2688_channel_config()
817 * 0 means software toggle which is the default mode. in ltc2688_channel_config()
823 * If a TGPx is given, we automatically assume a dither in ltc2688_channel_config()
824 * capable channel (unless toggle is already enabled). in ltc2688_channel_config()
825 * On top of this we just set here the dither bit in the in ltc2688_channel_config()
827 * global toggle/dither bit is enabled. in ltc2688_channel_config()
829 if (!chan->toggle_chan) { in ltc2688_channel_config()
831 st->iio_chan[reg].ext_info = ltc2688_dither_ext_info; in ltc2688_channel_config()
833 /* wait, no sw toggle after all */ in ltc2688_channel_config()
834 st->iio_chan[reg].ext_info = ltc2688_toggle_ext_info; in ltc2688_channel_config()
839 chan->overrange = true; in ltc2688_channel_config()
846 ret = regmap_write(st->regmap, LTC2688_CMD_CH_SETTING(reg), in ltc2688_channel_config()
850 return dev_err_probe(dev, -EINVAL, in ltc2688_channel_config()
860 struct device *dev = &st->spi->dev; in ltc2688_setup()
876 ret = regmap_update_bits(st->regmap, LTC2688_CMD_CONFIG, in ltc2688_setup()
889 st->iio_chan = devm_kmemdup(dev, ltc2688_channels, in ltc2688_setup()
891 if (!st->iio_chan) in ltc2688_setup()
892 return -ENOMEM; in ltc2688_setup()
901 return regmap_set_bits(st->regmap, LTC2688_CMD_CONFIG, in ltc2688_setup()
909 regulator_bulk_disable(ARRAY_SIZE(st->regulators), st->regulators); in ltc2688_disable_regulators()
971 struct device *dev = &spi->dev; in ltc2688_probe()
976 return -ENOMEM; in ltc2688_probe()
979 st->spi = spi; in ltc2688_probe()
982 st->tx_data[3] = LTC2688_CMD_NOOP; in ltc2688_probe()
983 mutex_init(&st->lock); in ltc2688_probe()
985 st->regmap = devm_regmap_init(dev, <c2688_regmap_bus, st, in ltc2688_probe()
987 if (IS_ERR(st->regmap)) in ltc2688_probe()
988 return dev_err_probe(dev, PTR_ERR(st->regmap), in ltc2688_probe()
991 st->regulators[0].supply = "vcc"; in ltc2688_probe()
992 st->regulators[1].supply = "iovcc"; in ltc2688_probe()
993 ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(st->regulators), in ltc2688_probe()
994 st->regulators); in ltc2688_probe()
998 ret = regulator_bulk_enable(ARRAY_SIZE(st->regulators), st->regulators); in ltc2688_probe()
1008 if (PTR_ERR(vref_reg) != -ENODEV) in ltc2688_probe()
1014 st->vref = 4096; in ltc2688_probe()
1030 st->vref = ret / 1000; in ltc2688_probe()
1037 indio_dev->name = "ltc2688"; in ltc2688_probe()
1038 indio_dev->info = <c2688_info; in ltc2688_probe()
1039 indio_dev->modes = INDIO_DIRECT_MODE; in ltc2688_probe()
1040 indio_dev->channels = st->iio_chan; in ltc2688_probe()
1041 indio_dev->num_channels = ARRAY_SIZE(ltc2688_channels); in ltc2688_probe()