Skip to contentSkip to conversation

LTC2688 support

RFC PATCH In review Nuno Sá 4 participants 21 messages Nov 11, 2021 – Dec 6, 2021

Subsystems (2)
lore
Share & tools
lore

Nuno Sá

author maintainer
#0 lore raw

cover LTC2688 support

The reason why this is a RFC is because I'm still waiting for proper HW to test this thing. The reason why I'm sending this already is because there's some non usual features which might require extra ABI. Hence, while waiting I thought we could already speed up the process in regards with the ABI.

I still pushed the driver but the intent here is not really to review it. Naturally, if someone already wants to give some feedback, that's very much appreciated :)

Now, there are three main interfaces depending on the channel mode:
1) default (no new ABI)
2) toggle mode
3) dither mode

The channel mode will be a devicetree property as it does not really make much sense to change between modes at runtime even more because the piece of HW we might want to control with a channel might be different depending on the selected mode (I'm fairly sure on this between toggle and other modes but not so sure between dither and default mode).

toggle mode special ABI:

* Toggle operation enables fast switching of a DAC output between two
different DAC codes without any SPI transaction. Two codes are set in input_a and input_b and then the output switches according to an input signal (input_a -> clk high; input_b -> clk low).

out_voltageY_input_register
- selects between input_a and input_b. After selecting one register, we can write the dac code in out_voltageY_raw.
out_voltageY_toggle_en
- Disable/Enable toggle mode. The reason why I think this one is important is because if we wanna change the 2 codes, we should first disable this, set the codes and only then enable the mode back... As I'm writing this, It kind of came to me that we can probably achieve this with out_voltageY_powerdown attr (maybe takes a bit more time to see the outputs but...)

dither mode special ABI:

* Dither operation adds a small sinusoidal wave to the digital DAC
signal path. Dithering is a signal processing technique that involves the injection of ac noise to the signal path to reduce system nonlinearities.

out_voltage0_dither_en
- Same as in toggle mode.
out_voltage0_dither_period
out_voltage0_dither_phase
- Period and phase of the signal. Only some values are valid so there's also *_available files for these. I'm not sure if we can use the more generic IIO_CHAN_INFO_PHASE and IIO_CHAN_INFO_FREQUENCY here as these parameters don't really apply to the channel output signal...
out_voltage0_input_register
- Same as in toggle mode. However in this mode the code set in the input_b register has a special meaning. It's the amplitude of the dither signal.

One special mention to the dac scale. In this part this is something that can be purely controlled by SW so that I'm allowing userspace to change it rather then having it in dts. The available scales are:

* [0 5V] -> offset 0
* [0 10V] -> offset 0
* [-5 5V] -> offset -32678
* [-10 10V] -> offset -32768
* [-15 15V] -> offset -32768

With the above, we also need to have the offset configurable and right now I'm going to some trouble to make sure the scale + offset is something valid. Honestly, I think I'm overdoing it because things can still go wrong with [0 10V] and [-5 5V] as the scales are the same here. Furthermore, there's no real arm that can be done to the HW. Is just that the readings won't match with what someone might be expecting. My plan is to just remove those checks and assume is up to userspace to make it right and not have [-10 10V] scale with 0 offset for example.

I know that I'm taking a shortcut here :) so if you prefer to only discuss this in the __real__ series, I totally get it.

https://www.analog.com/media/en/technical-documentation/data-sheets/ltc2688.pdf

- Nuno Sá

Nuno Sá (1):
iio: dac: add support for ltc2688

 drivers/iio/dac/ltc2688.c | 995 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 995 insertions(+)
 create mode 100644 drivers/iio/dac/ltc2688.c
Signature · 1 line
2.33.1
author maintainer
#1 lore raw

RFC PATCH 1/1 iio: dac: add support for ltc2688

The LTC2688 is a 16 channel, 16 bit, +-15V DAC with an integrated precission reference. It is guaranteed monotonic and has built in rail-to-rail output buffers that can source or sink up to 20 mA.

---
 drivers/iio/dac/ltc2688.c | 995 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 995 insertions(+)
 create mode 100644 drivers/iio/dac/ltc2688.c
drivers/iio/dac/ltc2688.c new file +995 -0
new file mode 100644
index 000000000000..b394701b044e
@@ -0,0 +1,995 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * LTC2688 16 channel, 16 bit Voltage Output SoftSpan DAC driver
+ *
+ * Copyright 2021 Analog Devices Inc.
+ */
+#include <linux/bitfield.h>
+#include <linux/bits.h>
+#include <linux/clk.h>
+#include <linux/device.h>
+#include <linux/gpio/consumer.h>
+#include <linux/limits.h>
+#include <linux/iio/iio.h>
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/regmap.h>
+#include <linux/regulator/consumer.h>
+#include <linux/spi/spi.h>
+#include <linux/unaligned/be_byteshift.h>
+
+#define LTC2688_DAC_CHANNELS			16
+
+#define LTC2688_CMD_CH_CODE(x)			(0x00 + (x))
+#define LTC2688_CMD_CH_SETTING(x)		(0x10 + (x))
+#define LTC2688_CMD_CH_OFFSET(x)		(0X20 + (x))
+#define LTC2688_CMD_CH_GAIN(x)			(0x30 + (x))
+#define LTC2688_CMD_CH_CODE_UPDATE(x)		(0x40 + (x))
+
+#define LTC2688_CMD_CONFIG_REG			0x70
+#define LTC2688_CMD_POWERDOWN_REG		0x71
+#define LTC2688_CMD_A_B_SELECT_REG		0x72
+#define LTC2688_CMD_TOGGLE_DITHER_EN_REG	0x74
+#define LTC2688_CMD_UPDATE_ALL			0x7C
+#define LTC2688_CMD_NOOP			0xFF
+
+#define LTC2688_READ_OPERATION			0x80
+
+/* Channel Settings */
+#define LTC2688_CH_SPAN_MSK			GENMASK(2, 0)
+#define LTC2688_CH_OVERRANGE_MSK		BIT(3)
+#define LTC2688_CH_TD_SEL_MSK			GENMASK(5, 4)
+#define LTC2688_CH_DIT_PER_MSK			GENMASK(8, 6)
+#define LTC2688_CH_DIT_PH_MSK			GENMASK(10, 9)
+#define LTC2688_CH_MODE_MSK			BIT(11)
+
+/* Configuration register */
+#define LTC2688_CONFIG_RST			BIT(15)
+#define LTC2688_CONFIG_EXT_REF			BIT(1)
+
+enum {
+	LTC2688_SPAN_RANGE_0V_5V,
+	LTC2688_SPAN_RANGE_M10V_10V,
+	LTC2688_SPAN_RANGE_M15V_15V,
+	/*
+	 * These 2 were deliberately re-arranged to be the last items as they
+	 * have the same fs and we will just return 1 in read_available.
+	 */
+	LTC2688_SPAN_RANGE_0V_10V,
+	LTC2688_SPAN_RANGE_M5V_5V,
+	LTC2688_SPAN_RANGE_MAX
+};
+
+struct ltc2688_chan {
+	int span_tbl[LTC2688_SPAN_RANGE_MAX][2];
+	bool overrange;
+	bool dither_toggle;
+	u8 offset_idx;
+};
+
+/*
+ * Helper tables to make sure the selected span is valid for the current offset
+ * and to translate the reg value to set for a specific span...
+ */
+static const int ltc2688_off_tbl[LTC2688_SPAN_RANGE_MAX] = {
+	[LTC2688_SPAN_RANGE_0V_5V] = 0,
+	[LTC2688_SPAN_RANGE_M10V_10V] = -32768,
+	[LTC2688_SPAN_RANGE_M15V_15V] = -32768,
+	[LTC2688_SPAN_RANGE_0V_10V] = 0,
+	[LTC2688_SPAN_RANGE_M5V_5V] = -32768
+};
+
+static const int ltc2688_reg_val[LTC2688_SPAN_RANGE_MAX] = {
+	[LTC2688_SPAN_RANGE_0V_5V] = 0,
+	[LTC2688_SPAN_RANGE_M10V_10V] = 3,
+	[LTC2688_SPAN_RANGE_M15V_15V] = 4,
+	[LTC2688_SPAN_RANGE_0V_10V] = 1,
+	[LTC2688_SPAN_RANGE_M5V_5V] = 2
+};
+
+struct ltc2688_state {
+	struct spi_device *spi;
+	struct regmap *regmap;
+	struct ltc2688_chan channels[LTC2688_DAC_CHANNELS];
+	int vref;
+	u8 tx_data[6] ____cacheline_aligned;
+	u8 rx_data[3];
+};
+
+static int ltc2688_spi_read(void *context, unsigned int cmd, unsigned int *val)
+{
+	struct ltc2688_state *st = context;
+	struct spi_transfer xfers[] = {
+		{
+			.tx_buf = st->tx_data,
+			.bits_per_word = 8,
+			.len = 3,
+			.cs_change = 1,
+		}, {
+			.tx_buf = st->tx_data + 3,
+			.rx_buf = st->rx_data,
+			.bits_per_word = 8,
+			.len = 3,
+		},
+	};
+	int ret;
+
+	st->tx_data[0] = cmd | LTC2688_READ_OPERATION;
+	st->tx_data[3] = LTC2688_CMD_NOOP;
+
+	ret = spi_sync_transfer(st->spi, xfers, ARRAY_SIZE(xfers));
+	if (ret)
+		return ret;
+
+	/* first byte is to be ignored */
+	*val = get_unaligned_be16(&st->rx_data[1]);
+
+	return 0;
+}
+
+static int ltc2688_spi_write(void *context, unsigned int cmd, unsigned int val)
+{
+	struct ltc2688_state *st = context;
+
+	st->tx_data[0] = cmd;
+	put_unaligned_be16(val, &st->tx_data[1]);
+
+	return spi_write(st->spi, st->tx_data, 3);
+}
+
+static int ltc2688_span_get(const struct ltc2688_state *st, int c, int *val2)
+{
+	const struct ltc2688_chan *chan = &st->channels[c];
+	int ret, reg, span;
+	u32 i;
+
+	ret = regmap_read(st->regmap, LTC2688_CMD_CH_SETTING(c), &reg);
+	if (ret)
+		return ret;
+
+	span = FIELD_GET(LTC2688_CH_SPAN_MSK, reg);
+	/* sanity check to make sure we don't get any weird value from the HW */
+	if (span >= LTC2688_SPAN_RANGE_MAX)
+		return -EIO;
+
+	/* look for correct span */
+	for (i = 0; i < ARRAY_SIZE(ltc2688_reg_val); i++)
+		if (span == ltc2688_reg_val[i])
+			break;
+
+	*val2 = chan->span_tbl[i][1];
+
+	return IIO_VAL_INT_PLUS_NANO;
+}
+
+static const int ltc2688_offset_avail[] = { -32768, 0 };
+
+static int ltc2688_span_set(const struct ltc2688_state *st, int c, int span)
+{
+	const struct ltc2688_chan *chan = &st->channels[c];
+	u32 i = ARRAY_SIZE(chan->span_tbl);
+	int off = ltc2688_offset_avail[chan->offset_idx];
+
+	while (i--) {
+		if (span == chan->span_tbl[i][1]) {
+			/*
+			 * The selected scale needs to fit  the current offset.
+			 * Note that for [0V 10V] and [-5V 5V], as the scale is
+			 * the same, we will always succeed here. Hence if
+			 * someone really wants [0 10V] and does not set the
+			 * offset to 0, then :man-shrugging:
+			 */
+			if (off == ltc2688_off_tbl[i]) {
+				break;
+			} else if (i < LTC2688_SPAN_RANGE_0V_10V) {
+				/*
+				 * At this point, only one offset is valid so we
+				 * already can assume error.
+				 */
+				dev_err(&st->spi->dev, "Offset(%d) not valid for current scale(0.%09d)\n",
+					off, span);
+				return -EPERM;
+			}
+
+			continue;
+		}
+
+		if (!i) {
+			dev_err(&st->spi->dev, "span(%d) not available\n", span);
+			return -EINVAL;
+		}
+	}
+
+	return regmap_update_bits(st->regmap, LTC2688_CMD_CH_SETTING(c),
+				  LTC2688_CH_SPAN_MSK,
+				  FIELD_PREP(LTC2688_CH_SPAN_MSK, ltc2688_reg_val[i]));
+};
+
+static int ltc2688_offset_set(struct ltc2688_state *st, int c, int off)
+{
+	struct ltc2688_chan *chan = &st->channels[c];
+
+	if (off != ltc2688_offset_avail[0] && off != ltc2688_offset_avail[1])
+		return -EINVAL;
+
+	if (off == ltc2688_offset_avail[0])
+		chan->offset_idx = 0;
+	else
+		chan->offset_idx = 1;
+
+	return 0;
+}
+
+static int ltc2688_read_avail(struct iio_dev *indio_dev,
+			      struct iio_chan_spec const *chan,
+			      const int **vals, int *type, int *length, long m)
+{
+	struct ltc2688_state *st = iio_priv(indio_dev);
+	int c = chan->channel;
+
+	switch (m) {
+	case IIO_CHAN_INFO_SCALE:
+		*vals = (const int *)st->channels[c].span_tbl;
+		*length = ARRAY_SIZE(st->channels[c].span_tbl) * 2 - 2;
+		*type = IIO_VAL_INT_PLUS_NANO;
+		return IIO_AVAIL_LIST;
+	case IIO_CHAN_INFO_OFFSET:
+		*vals = ltc2688_offset_avail;
+		*length = ARRAY_SIZE(ltc2688_offset_avail);
+		*type = IIO_VAL_INT;
+		return IIO_AVAIL_LIST;
+	default:
+		return -EINVAL;
+	};
+}
+
+static int ltc2688_read_raw(struct iio_dev *indio_dev,
+			    struct iio_chan_spec const *chan, int *val,
+			    int *val2, long m)
+{
+	struct ltc2688_state *st = iio_priv(indio_dev);
+	int ret;
+	u8 offset;
+
+	switch (m) {
+	case IIO_CHAN_INFO_RAW:
+		ret = regmap_read(st->regmap,
+				  LTC2688_CMD_CH_CODE(chan->address), val);
+		if (ret)
+			return ret;
+
+		return IIO_VAL_INT;
+	case IIO_CHAN_INFO_OFFSET:
+		offset = st->channels[chan->channel].offset_idx;
+		*val = ltc2688_offset_avail[offset];
+		return IIO_VAL_INT;
+	case IIO_CHAN_INFO_SCALE:
+		*val = 0;
+		return ltc2688_span_get(st, chan->channel, val2);
+	case IIO_CHAN_INFO_CALIBBIAS:
+		ret = regmap_read(st->regmap,
+				  LTC2688_CMD_CH_OFFSET(chan->channel), val);
+		if (ret)
+			return ret;
+
+		return IIO_VAL_INT;
+	case IIO_CHAN_INFO_CALIBSCALE:
+		ret = regmap_read(st->regmap,
+				  LTC2688_CMD_CH_GAIN(chan->channel), val);
+		if (ret)
+			return ret;
+
+		return IIO_VAL_INT;
+	default:
+		return -EINVAL;
+	}
+}
+
+static int ltc2688_write_raw_get_fmt(struct iio_dev *indio_dev,
+				     struct iio_chan_spec const *chan,
+				     long mask)
+{
+	switch (mask) {
+	case IIO_CHAN_INFO_RAW:
+	case IIO_CHAN_INFO_CALIBSCALE:
+	case IIO_CHAN_INFO_CALIBBIAS:
+	case IIO_CHAN_INFO_OFFSET:
+		return IIO_VAL_INT;
+	case IIO_CHAN_INFO_SCALE:
+		return IIO_VAL_INT_PLUS_NANO;
+	default:
+		return -EINVAL;
+	}
+}
+
+static int ltc2688_write_raw(struct iio_dev *indio_dev,
+			     struct iio_chan_spec const *chan, int val,
+			     int val2, long mask)
+{
+	struct ltc2688_state *st = iio_priv(indio_dev);
+	int cmd;
+
+	switch (mask) {
+	case IIO_CHAN_INFO_RAW:
+		if (val > U16_MAX || val < 0)
+			return -EINVAL;
+		/*
+		 * If in dither/toggle mode the dac should be updated by an
+		 * external signal and not here
+		 */
+		if (st->channels[chan->channel].dither_toggle)
+			cmd = LTC2688_CMD_CH_CODE(chan->channel);
+		else
+			cmd = LTC2688_CMD_CH_CODE_UPDATE(chan->channel);
+
+		return regmap_write(st->regmap, cmd, val);
+	case IIO_CHAN_INFO_SCALE:
+		if (val)
+			return -EINVAL;
+
+		return ltc2688_span_set(st, chan->channel, val2);
+	case IIO_CHAN_INFO_OFFSET:
+		return ltc2688_offset_set(st, chan->channel, val);
+	case IIO_CHAN_INFO_CALIBBIAS:
+		return regmap_write(st->regmap,
+				    LTC2688_CMD_CH_OFFSET(chan->channel), val);
+	case IIO_CHAN_INFO_CALIBSCALE:
+		return regmap_write(st->regmap,
+				    LTC2688_CMD_CH_GAIN(chan->channel), val);
+	default:
+		return -EINVAL;
+	}
+}
+
+enum {
+	LTC2688_DITHER_TOGGLE_ENABLE,
+	LTC2688_POWERDOWN,
+};
+
+static ssize_t ltc2688_read_ext(struct iio_dev *indio_dev,
+				uintptr_t private,
+				const struct iio_chan_spec *chan,
+				char *buf)
+{
+	struct ltc2688_state *st = iio_priv(indio_dev);
+	int ret, regval;
+	u32 reg;
+
+	switch (private) {
+	case LTC2688_DITHER_TOGGLE_ENABLE:
+		reg = LTC2688_CMD_TOGGLE_DITHER_EN_REG;
+		break;
+	case LTC2688_POWERDOWN:
+		reg = LTC2688_CMD_POWERDOWN_REG;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	ret = regmap_read(st->regmap, reg, &regval);
+	if (ret < 0)
+		return ret;
+
+	return sprintf(buf, "%u\n", !!(regval & BIT(chan->channel)));
+}
+
+static ssize_t ltc2688_write_ext(struct iio_dev *indio_dev,
+				 uintptr_t private,
+				 const struct iio_chan_spec *chan,
+				 const char *buf, size_t len)
+{
+	struct ltc2688_state *st = iio_priv(indio_dev);
+	bool en;
+	int ret;
+	u32 val = 0, reg;
+
+	ret = strtobool(buf, &en);
+	if (ret)
+		return ret;
+
+	switch (private) {
+	case LTC2688_DITHER_TOGGLE_ENABLE:
+		reg = LTC2688_CMD_TOGGLE_DITHER_EN_REG;
+		break;
+	case LTC2688_POWERDOWN:
+		reg = LTC2688_CMD_POWERDOWN_REG;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	if (en)
+		val = BIT(chan->channel);
+
+	ret = regmap_update_bits(st->regmap, reg, BIT(chan->channel), val);
+	if (ret)
+		return ret;
+
+	return len;
+}
+
+static int ltc2688_get_dither_period(struct iio_dev *dev,
+				     const struct iio_chan_spec *chan)
+{
+	struct ltc2688_state *st = iio_priv(dev);
+	int ret, regval;
+
+	ret = regmap_read(st->regmap, LTC2688_CMD_CH_SETTING(chan->channel),
+			  &regval);
+	if (ret)
+		return ret;
+
+	return FIELD_GET(LTC2688_CH_DIT_PER_MSK, regval);
+}
+
+static int ltc2688_set_dither_period(struct iio_dev *dev,
+				     const struct iio_chan_spec *chan,
+				     unsigned int period)
+{
+	struct ltc2688_state *st = iio_priv(dev);
+
+	return regmap_update_bits(st->regmap,
+				  LTC2688_CMD_CH_SETTING(chan->channel),
+				  LTC2688_CH_DIT_PER_MSK,
+				  FIELD_PREP(LTC2688_CH_DIT_PER_MSK, period));
+}
+
+static int ltc2688_get_dither_phase(struct iio_dev *dev,
+				    const struct iio_chan_spec *chan)
+{
+	struct ltc2688_state *st = iio_priv(dev);
+	int ret, regval;
+
+	ret = regmap_read(st->regmap, LTC2688_CMD_CH_SETTING(chan->channel),
+			  &regval);
+	if (ret)
+		return ret;
+
+	return FIELD_GET(LTC2688_CH_DIT_PH_MSK, regval);
+}
+
+static int ltc2688_set_dither_phase(struct iio_dev *dev,
+				    const struct iio_chan_spec *chan,
+				    unsigned int phase)
+{
+	struct ltc2688_state *st = iio_priv(dev);
+
+	return regmap_update_bits(st->regmap,
+				  LTC2688_CMD_CH_SETTING(chan->channel),
+				  LTC2688_CH_DIT_PH_MSK,
+				  FIELD_PREP(LTC2688_CH_DIT_PH_MSK, phase));
+}
+
+static int ltc2688_get_reg_select(struct iio_dev *dev,
+				  const struct iio_chan_spec *chan)
+{
+	struct ltc2688_state *st = iio_priv(dev);
+	int ret, regval;
+
+	ret = regmap_read(st->regmap, LTC2688_CMD_A_B_SELECT_REG, &regval);
+	if (ret < 0)
+		return ret;
+
+	return !!(regval & BIT(chan->channel));
+}
+
+static int ltc2688_set_reg_select(struct iio_dev *dev,
+				  const struct iio_chan_spec *chan,
+				  unsigned int reg)
+{
+	struct ltc2688_state *st = iio_priv(dev);
+
+	return regmap_update_bits(st->regmap, LTC2688_CMD_A_B_SELECT_REG,
+				  BIT(chan->channel), reg << chan->channel);
+}
+
+static int ltc2688_reg_access(struct iio_dev *indio_dev,
+			      unsigned int reg,
+			      unsigned int writeval,
+			      unsigned int *readval)
+{
+	struct ltc2688_state *st = iio_priv(indio_dev);
+
+	if (readval)
+		return regmap_read(st->regmap, reg, readval);
+	else
+		return regmap_write(st->regmap, reg, writeval);
+}
+
+static const char * const ltc2688_input_register[] = {
+	"input_a",
+	"input_b",
+};
+
+static const struct iio_enum ltc2688_input_reg_enum = {
+	.items = ltc2688_input_register,
+	.num_items = ARRAY_SIZE(ltc2688_input_register),
+	.set = ltc2688_set_reg_select,
+	.get = ltc2688_get_reg_select,
+};
+
+static const char * const ltc2688_dither_period[] = {
+	"4",
+	"8",
+	"16",
+	"32",
+	"64",
+};
+
+static const struct iio_enum ltc2688_dither_period_enum = {
+	.items = ltc2688_dither_period,
+	.num_items = ARRAY_SIZE(ltc2688_dither_period),
+	.set = ltc2688_set_dither_period,
+	.get = ltc2688_get_dither_period,
+};
+
+static const char * const ltc2688_dither_phase[] = {
+	"0",
+	"90",
+	"180",
+	"270",
+};
+
+static const struct iio_enum ltc2688_dither_phase_enum = {
+	.items = ltc2688_dither_phase,
+	.num_items = ARRAY_SIZE(ltc2688_dither_phase),
+	.set = ltc2688_set_dither_phase,
+	.get = ltc2688_get_dither_phase,
+};
+
+#define LTC2688_CHAN_EXT_INFO(_name, _what, _shared) {	\
+	.name = _name,					\
+	.read = ltc2688_read_ext,			\
+	.write = ltc2688_write_ext,			\
+	.private = _what,				\
+	.shared = _shared,				\
+}
+
+#define IIO_ENUM_AVAILABLE_SHARED(_name, _shared, _e) {	\
+	.name = (_name "_available"),			\
+	.shared = _shared,				\
+	.read = iio_enum_available_read,		\
+	.private = (uintptr_t)(_e),			\
+}
+
+static const struct iio_chan_spec_ext_info ltc2688_dither_ext_info[] = {
+	IIO_ENUM("input_register", IIO_SEPARATE, &ltc2688_input_reg_enum),
+	IIO_ENUM_AVAILABLE_SHARED("input_register",
+				  IIO_SHARED_BY_TYPE, &ltc2688_input_reg_enum),
+	IIO_ENUM("dither_period", IIO_SEPARATE, &ltc2688_dither_period_enum),
+	IIO_ENUM_AVAILABLE_SHARED("dither_period",
+				  IIO_SHARED_BY_TYPE, &ltc2688_dither_period_enum),
+	IIO_ENUM("dither_phase", IIO_SEPARATE, &ltc2688_dither_phase_enum),
+	IIO_ENUM_AVAILABLE_SHARED("dither_phase",
+				  IIO_SHARED_BY_TYPE, &ltc2688_dither_phase_enum),
+	LTC2688_CHAN_EXT_INFO("dither_en", LTC2688_DITHER_TOGGLE_ENABLE,
+			      IIO_SEPARATE),
+	LTC2688_CHAN_EXT_INFO("powerdown", LTC2688_POWERDOWN, IIO_SEPARATE),
+	{}
+};
+
+static const struct iio_chan_spec_ext_info ltc2688_toggle_ext_info[] = {
+	IIO_ENUM("input_register", IIO_SEPARATE, &ltc2688_input_reg_enum),
+	IIO_ENUM_AVAILABLE_SHARED("input_register",
+				  IIO_SHARED_BY_TYPE, &ltc2688_input_reg_enum),
+	LTC2688_CHAN_EXT_INFO("toggle_en", LTC2688_DITHER_TOGGLE_ENABLE,
+			      IIO_SEPARATE),
+	LTC2688_CHAN_EXT_INFO("powerdown", LTC2688_POWERDOWN, IIO_SEPARATE),
+	{}
+};
+
+static const struct iio_chan_spec_ext_info ltc2688_default_ext_info[] = {
+	LTC2688_CHAN_EXT_INFO("powerdown", LTC2688_POWERDOWN, IIO_SEPARATE),
+	{}
+};
+
+#define LTC2688_CHANNEL(_chan) {					\
+	.type = IIO_VOLTAGE,						\
+	.indexed = 1,							\
+	.output = 1,							\
+	.channel = (_chan),						\
+	.info_mask_separate = BIT(IIO_CHAN_INFO_CALIBSCALE) |		\
+		BIT(IIO_CHAN_INFO_SCALE) | BIT(IIO_CHAN_INFO_OFFSET) |	\
+		BIT(IIO_CHAN_INFO_CALIBBIAS) | BIT(IIO_CHAN_INFO_RAW),	\
+	.info_mask_separate_available = BIT(IIO_CHAN_INFO_SCALE),	\
+	.info_mask_shared_by_type_available = BIT(IIO_CHAN_INFO_OFFSET),\
+	.ext_info = ltc2688_default_ext_info				\
+}
+
+struct iio_chan_spec ltc2688_channels[] = {
+	LTC2688_CHANNEL(0),
+	LTC2688_CHANNEL(1),
+	LTC2688_CHANNEL(2),
+	LTC2688_CHANNEL(3),
+	LTC2688_CHANNEL(4),
+	LTC2688_CHANNEL(5),
+	LTC2688_CHANNEL(6),
+	LTC2688_CHANNEL(7),
+	LTC2688_CHANNEL(8),
+	LTC2688_CHANNEL(9),
+	LTC2688_CHANNEL(10),
+	LTC2688_CHANNEL(11),
+	LTC2688_CHANNEL(12),
+	LTC2688_CHANNEL(13),
+	LTC2688_CHANNEL(14),
+	LTC2688_CHANNEL(15),
+};
+
+enum {
+	LTC2688_CHAN_MODE_TOGGLE,
+	LTC2688_CHAN_MODE_DITHER
+};
+
+enum {
+	LTC2688_CHAN_TD_TGP1,
+	LTC2688_CHAN_TD_TGP2,
+	LTC2688_CHAN_TD_TGP3,
+	LTC2688_CHAN_TD_MAX
+};
+
+static const char * const ltc2688_clk_names[LTC2688_CHAN_TD_MAX] = {
+	"TGP1", "TGP2", "TGP3"
+};
+
+static void ltc2688_clk_disable(void *clk)
+{
+	clk_disable_unprepare(clk);
+}
+
+static int ltc2688_clk_setup(const struct ltc2688_state *st, unsigned long mask)
+{
+	u32 bit;
+	int ret;
+
+	for_each_set_bit(bit, &mask, ARRAY_SIZE(ltc2688_clk_names)) {
+		struct clk *clk;
+		/*
+		 * If a TGP pin is set, then we need to provide a valid clock at
+		 * the pin.
+		 */
+		clk = devm_clk_get(&st->spi->dev, ltc2688_clk_names[bit]);
+		if (IS_ERR(clk))
+			return dev_err_probe(&st->spi->dev, PTR_ERR(clk),
+					     "failed to get clk: %s\n",
+					     ltc2688_clk_names[bit]);
+
+		ret = clk_prepare_enable(clk);
+		if (ret)
+			return dev_err_probe(&st->spi->dev, ret,
+					     "failed to enable clk: %s\n",
+					     ltc2688_clk_names[bit]);
+
+		ret = devm_add_action_or_reset(&st->spi->dev,
+					       ltc2688_clk_disable, clk);
+		if (ret)
+			return ret;
+	}
+
+	return 0;
+}
+
+static int ltc2688_channel_config(struct ltc2688_state *st)
+{
+	struct fwnode_handle *fwnode = dev_fwnode(&st->spi->dev), *child;
+	u32 reg, clk_input, mode, val, mask;
+	unsigned long clk_msk = 0;
+	int ret;
+
+	fwnode_for_each_available_child_node(fwnode, child) {
+		struct ltc2688_chan *chan;
+
+		ret = fwnode_property_read_u32(child, "reg", &reg);
+		if (ret) {
+			fwnode_handle_put(child);
+			return dev_err_probe(&st->spi->dev, ret,
+					     "Failed to get reg property\n");
+		} else if (reg >= LTC2688_DAC_CHANNELS) {
+			fwnode_handle_put(child);
+			return dev_err_probe(&st->spi->dev, -EINVAL,
+					     "reg >= %d\n", LTC2688_DAC_CHANNELS);
+		}
+
+		chan = &st->channels[reg];
+		ret = fwnode_property_read_u32(child, "adi,mode", &mode);
+		if (!ret) {
+			if (mode > LTC2688_CHAN_MODE_DITHER) {
+				fwnode_handle_put(child);
+				return dev_err_probe(&st->spi->dev, -EINVAL,
+						     "chan mode inv value(%d)\n",
+						     mode);
+			}
+
+			chan->dither_toggle = true;
+			if (mode == LTC2688_CHAN_MODE_TOGGLE) {
+				ltc2688_channels[reg].ext_info = ltc2688_toggle_ext_info;
+			} else {
+				ltc2688_channels[reg].ext_info = ltc2688_dither_ext_info;
+				/* enable dither mode */
+				mask = LTC2688_CH_MODE_MSK;
+				val = BIT(11);
+			}
+		}
+
+		ret = fwnode_property_read_u32(child, "adi,toggle-dither-input",
+					       &clk_input);
+		if (!ret) {
+			if (clk_input > LTC2688_CHAN_TD_TGP3) {
+				fwnode_handle_put(child);
+				return dev_err_probe(&st->spi->dev, -EINVAL,
+						     "toggle-dither-input inv value(%d)\n",
+						     clk_input);
+			}
+
+			clk_msk |= BIT(clk_input);
+			mask |= LTC2688_CH_TD_SEL_MSK;
+			/*
+			 * 0 means software toggle which we are not supporting
+			 * for now. Hence the +1
+			 */
+			val |= FIELD_PREP(LTC2688_CH_TD_SEL_MSK, clk_input + 1);
+		} else if (chan->dither_toggle) {
+			/*
+			 * As sw_toggle is not supported, we need to make sure
+			 * a valid input is selected if toggle/dither mode is
+			 * requested
+			 */
+			return dev_err_probe(&st->spi->dev, -EINVAL,
+					     "toggle-dither set but no toggle-dither-input\n");
+		}
+
+		chan->overrange = fwnode_property_read_bool(child,
+							    "adi,overrange");
+		if (chan->overrange) {
+			val |= LTC2688_CH_OVERRANGE_MSK;
+			mask |= BIT(3);
+		}
+
+		if (!mask)
+			continue;
+
+		ret = regmap_update_bits(st->regmap,
+					 LTC2688_CMD_CH_SETTING(reg), mask,
+					 val);
+		if (ret) {
+			fwnode_handle_put(child);
+			return dev_err_probe(&st->spi->dev, -EINVAL,
+					     "failed to set chan settings\n");
+		}
+
+		mask = 0;
+		val = 0;
+	}
+
+	return ltc2688_clk_setup(st, clk_msk);
+}
+
+static const int ltc2688_span_helper[LTC2688_SPAN_RANGE_MAX][2] = {
+	{0, 5000}, {-10000, 10000}, {-15000, 15000}, {0, 10000}, {-5000, 5000},
+};
+
+static int ltc2688_get_full_scale(const struct ltc2688_chan *chan, int idx)
+{
+	int fs = ltc2688_span_helper[idx][1] - ltc2688_span_helper[idx][0];
+
+	if (chan->overrange)
+		fs = mult_frac(fs, 105, 100);
+
+	return fs;
+}
+
+static void ltc2688_span_avail_compute(struct ltc2688_state *st)
+{
+	u32 c, i;
+
+	for (c = 0; c < ARRAY_SIZE(st->channels); c++) {
+		struct ltc2688_chan *chan = &st->channels[c];
+
+		for (i = 0; i < ARRAY_SIZE(chan->span_tbl); i++) {
+			u32 fs, s;
+
+			fs = ltc2688_get_full_scale(chan, i);
+			/* we will return IIO_VAL_INT_PLUS_NANO */
+			s = DIV_ROUND_CLOSEST_ULL(st->vref * fs * 1000000000ULL,
+						  4096 * 1 << 16);
+
+			chan->span_tbl[i][1] = s;
+			/* default offset is 0 */
+			chan->offset_idx = 1;
+		}
+	}
+}
+
+static int ltc2688_setup(struct ltc2688_state *st, struct regulator *vref)
+{
+	struct gpio_desc *gpio;
+	int ret;
+
+	gpio = devm_gpiod_get_optional(&st->spi->dev, "reset", GPIOD_OUT_HIGH);
+	if (IS_ERR(gpio))
+		return dev_err_probe(&st->spi->dev, PTR_ERR(gpio),
+				     "Failed to get reset gpio");
+
+	if (gpio) {
+		usleep_range(1000, 1200);
+		/* bring device out of reset */
+		gpiod_set_value_cansleep(gpio, 0);
+	} else {
+		ret = regmap_update_bits(st->regmap, LTC2688_CMD_CONFIG_REG,
+					 LTC2688_CONFIG_RST,
+					 LTC2688_CONFIG_RST);
+		if (ret < 0)
+			return ret;
+	}
+
+	usleep_range(10000, 12000);
+	ret = ltc2688_channel_config(st);
+	if (ret < 0)
+		return ret;
+
+	if (vref) {
+		ret = regmap_update_bits(st->regmap, LTC2688_CMD_CONFIG_REG,
+					 LTC2688_CONFIG_EXT_REF, BIT(1));
+		if (ret < 0)
+			return ret;
+	}
+
+	ltc2688_span_avail_compute(st);
+	return 0;
+}
+
+static void ltc2688_disable_regulator(void *regulator)
+{
+	regulator_disable(regulator);
+}
+
+static int ltc2688_regulator_supply_get(const struct ltc2688_state *st,
+					const char *name)
+{
+	struct regulator *reg;
+	int ret;
+
+	reg = devm_regulator_get(&st->spi->dev, name);
+	if (IS_ERR(reg))
+		return dev_err_probe(&st->spi->dev, PTR_ERR(reg),
+				     "Failed to get %s regulator\n", name);
+
+	ret = regulator_enable(reg);
+	if (ret)
+		return dev_err_probe(&st->spi->dev, ret,
+				     "Failed to enable %s regulator\n", name);
+
+	return devm_add_action_or_reset(&st->spi->dev,
+					ltc2688_disable_regulator, reg);
+}
+
+static bool ltc2688_reg_readable(struct device *dev, unsigned int cmd)
+{
+	switch (cmd | LTC2688_READ_OPERATION) {
+	case 0x80 ... 0xBF:
+		return true;
+	case 0xF0 ... 0xFE:
+		return true;
+	default:
+		return false;
+	}
+}
+
+static bool ltc2688_reg_writable(struct device *dev, unsigned int cmd)
+{
+	if (cmd <= LTC2688_CMD_UPDATE_ALL)
+		return true;
+
+	return false;
+}
+
+static const struct regmap_config ltc2688_regmap_config = {
+	.reg_read = ltc2688_spi_read,
+	.reg_write = ltc2688_spi_write,
+	.readable_reg = ltc2688_reg_readable,
+	.writeable_reg = ltc2688_reg_writable,
+	/* ignoring the no op command */
+	.max_register = U16_MAX - 1
+};
+
+static const struct iio_info ltc2688_info = {
+	.write_raw = ltc2688_write_raw,
+	.read_raw = ltc2688_read_raw,
+	.write_raw_get_fmt = ltc2688_write_raw_get_fmt,
+	.read_avail = ltc2688_read_avail,
+	.debugfs_reg_access = ltc2688_reg_access,
+};
+
+static int ltc2688_probe(struct spi_device *spi)
+{
+	struct ltc2688_state *st;
+	struct iio_dev *indio_dev;
+	struct regulator *vref_reg;
+	int ret;
+
+	indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st));
+	if (!indio_dev)
+		return -ENOMEM;
+
+	st = iio_priv(indio_dev);
+	st->spi = spi;
+
+	st->regmap = devm_regmap_init(&spi->dev, NULL, st, &ltc2688_regmap_config);
+	if (IS_ERR(st->regmap))
+		return dev_err_probe(&spi->dev, PTR_ERR(st->regmap),
+				     "Failed to init regmap");
+
+	ret = ltc2688_regulator_supply_get(st, "vcc");
+	if (ret)
+		return ret;
+
+	ret = ltc2688_regulator_supply_get(st, "iovcc");
+	if (ret)
+		return ret;
+
+	vref_reg = devm_regulator_get_optional(&spi->dev, "vref");
+	if (!IS_ERR(vref_reg)) {
+		ret = regulator_enable(vref_reg);
+		if (ret)
+			return dev_err_probe(&spi->dev, ret,
+					     "Failed to enable vref regulators\n");
+
+		ret = devm_add_action_or_reset(&spi->dev,
+					       ltc2688_disable_regulator,
+					       vref_reg);
+		if (ret)
+			return ret;
+
+		ret = regulator_get_voltage(vref_reg);
+		if (ret < 0)
+			return dev_err_probe(&spi->dev, ret,
+					     "Failed to get vref\n");
+
+		st->vref = ret / 1000;
+	} else {
+		if (PTR_ERR(vref_reg) != -ENODEV)
+			return dev_err_probe(&spi->dev, PTR_ERR(vref_reg),
+					     "Failed to get vref regulator");
+
+		vref_reg = NULL;
+		/* internal reference */
+		st->vref = 4096;
+	}
+
+	indio_dev->name = "ltc2688";
+	indio_dev->info = &ltc2688_info;
+	indio_dev->modes = INDIO_DIRECT_MODE;
+	indio_dev->channels = ltc2688_channels;
+	indio_dev->num_channels = ARRAY_SIZE(ltc2688_channels);
+
+	ret = ltc2688_setup(st, vref_reg);
+	if (ret < 0)
+		return ret;
+
+	return devm_iio_device_register(&st->spi->dev, indio_dev);
+}
+
+static const struct of_device_id ltc2688_of_id[] = {
+	{ .compatible = "adi,ltc2688" },
+	{}
+};
+MODULE_DEVICE_TABLE(of, ltc2688_of_id);
+
+static const struct spi_device_id ltc2688_id[] = {
+	{ "ltc2688" },
+	{}
+};
+MODULE_DEVICE_TABLE(spi, ltc2688_id);
+
+static struct spi_driver ltc2688_driver = {
+	.driver = {
+		.name = "ltc2688",
+		.of_match_table = ltc2688_of_id,
+	},
+	.probe = ltc2688_probe,
+	.id_table = ltc2688_id,
+};
+module_spi_driver(ltc2688_driver);
+
+MODULE_AUTHOR("Nuno Sá <[email protected]>");
+MODULE_DESCRIPTION("Analog Devices LTC2688 DAC");
+MODULE_LICENSE("GPL");
Signature · 1 line
2.33.1
#2 lore raw

Re: [RFC PATCH 1/1] iio: dac: add support for ltc2688

Quoted 3 lines · Nuno Sá

The LTC2688 is a 16 channel, 16 bit, +-15V DAC with an integrated precission reference. It is guaranteed monotonic and has built in

precision

Quoted 1 line

rail-to-rail output buffers that can source or sink up to 20 mA.

It's in good shape, several comments below, though.

...

drivers/iio/dac/ltc2688.c line 56

Quoted 7 lines
drivers/iio/dac/ltc2688.c new file +7 -0
+enum {
+       LTC2688_SPAN_RANGE_0V_5V,
+       LTC2688_SPAN_RANGE_M10V_10V,
+       LTC2688_SPAN_RANGE_M15V_15V,
+       /*
+        * These 2 were deliberately re-arranged to be the last items as they
+        * have the same fs and we will just return 1 in read_available.

WTH "fs" mean?

Quoted 5 lines
drivers/iio/dac/ltc2688.c new file +5 -0
+        */
+       LTC2688_SPAN_RANGE_0V_10V,
+       LTC2688_SPAN_RANGE_M5V_5V,
+       LTC2688_SPAN_RANGE_MAX
+};

...

drivers/iio/dac/ltc2688.c line 79

Quoted 7 lines
drivers/iio/dac/ltc2688.c new file +6 -0
+static const int ltc2688_off_tbl[LTC2688_SPAN_RANGE_MAX] = {
+       [LTC2688_SPAN_RANGE_0V_5V] = 0,
+       [LTC2688_SPAN_RANGE_M10V_10V] = -32768,
+       [LTC2688_SPAN_RANGE_M15V_15V] = -32768,
 
+       [LTC2688_SPAN_RANGE_0V_10V] = 0,
+       [LTC2688_SPAN_RANGE_M5V_5V] = -32768

+ Comma

Isn't it more natural to move them up by two lines?

drivers/iio/dac/ltc2688.c line 87

Quoted 8 lines
drivers/iio/dac/ltc2688.c new file +8 -0
+};
+
+static const int ltc2688_reg_val[LTC2688_SPAN_RANGE_MAX] = {
+       [LTC2688_SPAN_RANGE_0V_5V] = 0,
+       [LTC2688_SPAN_RANGE_M10V_10V] = 3,
+       [LTC2688_SPAN_RANGE_M15V_15V] = 4,
+       [LTC2688_SPAN_RANGE_0V_10V] = 1,
+       [LTC2688_SPAN_RANGE_M5V_5V] = 2

As per above.

Quoted 1 line

+};

...

drivers/iio/dac/ltc2688.c line 173

Quoted 7 lines
drivers/iio/dac/ltc2688.c new file +6 -0
+static int ltc2688_span_set(const struct ltc2688_state *st, int c, int span)
+{
+       const struct ltc2688_chan *chan = &st->channels[c];
+       u32 i = ARRAY_SIZE(chan->span_tbl);
+       int off = ltc2688_offset_avail[chan->offset_idx];
 
+       while (i--) {

Can ARRAY_SIZE() give 0?
If not, do {} while (--i); looks more natural.

drivers/iio/dac/ltc2688.c line 184

Quoted 12 lines
drivers/iio/dac/ltc2688.c new file +11 -0
+               if (span == chan->span_tbl[i][1]) {
+                       /*
+                        * The selected scale needs to fit  the current offset.
+                        * Note that for [0V 10V] and [-5V 5V], as the scale is
+                        * the same, we will always succeed here. Hence if
+                        * someone really wants [0 10V] and does not set the
+                        * offset to 0, then :man-shrugging:
+                        */
+                       if (off == ltc2688_off_tbl[i]) {
+                               break;
 
+                       } else if (i < LTC2688_SPAN_RANGE_0V_10V) {

Redundant 'else'.

drivers/iio/dac/ltc2688.c line 194

Quoted 10 lines
drivers/iio/dac/ltc2688.c new file +9 -0
+                               /*
+                                * At this point, only one offset is valid so we
+                                * already can assume error.
+                                */
+                               dev_err(&st->spi->dev, "Offset(%d) not valid for current scale(0.%09d)\n",
+                                       off, span);
+                               return -EPERM;
+                       }
 
+                       continue;

Redundant, see below.

drivers/iio/dac/ltc2688.c line 200

Quoted 6 lines
drivers/iio/dac/ltc2688.c new file +5 -0
+               }
 
+               if (!i) {
+                       dev_err(&st->spi->dev, "span(%d) not available\n", span);
+                       return -EINVAL;
+               }

This is invariant to the loop.

Quoted 6 lines
drivers/iio/dac/ltc2688.c new file +6 -0
+       }
+
+       return regmap_update_bits(st->regmap, LTC2688_CMD_CH_SETTING(c),
+                                 LTC2688_CH_SPAN_MSK,
+                                 FIELD_PREP(LTC2688_CH_SPAN_MSK, ltc2688_reg_val[i]));
+};

...

Review

Quoted 2 lines
(quoted diff) +2 -0
+       if (off != ltc2688_offset_avail[0] && off != ltc2688_offset_avail[1])
+               return -EINVAL;

Extra condition, See below.

drivers/iio/dac/ltc2688.c line 217

Quoted 3 lines
drivers/iio/dac/ltc2688.c new file +3 -0
+       if (off == ltc2688_offset_avail[0])
+               chan->offset_idx = 0;
+       else

else if

Quoted 1 line

+ chan->offset_idx = 1;

else
return -EINVAL;

...

drivers/iio/dac/ltc2688.c line 370

Quoted 2 lines
drivers/iio/dac/ltc2688.c new file +2 -0
+       ret = regmap_read(st->regmap, reg, &regval);
+       if (ret < 0)

Is it the first time you tested explicitly for a negative result?

Quoted 1 line

+ return ret;

...

Quoted 1 line

+ return sprintf(buf, "%u\n", !!(regval & BIT(chan->channel)));

sysfs_emit() ?

Quoted 1 line

+}

...

drivers/iio/dac/ltc2688.c line 384

Quoted 4 lines
drivers/iio/dac/ltc2688.c new file +4 -0
+       struct ltc2688_state *st = iio_priv(indio_dev);
+       bool en;
+       int ret;
+       u32 val = 0, reg;

Reversed xmas tree order ?

Quoted 1 line

+ ret = strtobool(buf, &en);

kstrtobool()

...

drivers/iio/dac/ltc2688.c line 158

Quoted 3 lines
drivers/iio/dac/ltc2688.c new file +3 -0
+       if (ret)
+               return ret;
+               break;

What does this mean?

...

drivers/iio/dac/ltc2688.c line 516

Quoted 5 lines
drivers/iio/dac/ltc2688.c new file +5 -0
+       "4",
+       "8",
+       "16",
+       "32",
+       "64",

One line?

...

drivers/iio/dac/ltc2688.c line 530

Quoted 4 lines
drivers/iio/dac/ltc2688.c new file +4 -0
+       "0",
+       "90",
+       "180",
+       "270",

Ditto.

...

drivers/iio/dac/ltc2688.c line 620

Quoted 3 lines
drivers/iio/dac/ltc2688.c new file +3 -0
+enum {
+       LTC2688_CHAN_MODE_TOGGLE,
+       LTC2688_CHAN_MODE_DITHER

+ Comma.

Quoted 1 line

+};

...

drivers/iio/dac/ltc2688.c line 631

Quoted 2 lines
drivers/iio/dac/ltc2688.c new file +2 -0
+static const char * const ltc2688_clk_names[LTC2688_CHAN_TD_MAX] = {
+       "TGP1", "TGP2", "TGP3"

In this notation, + comma.

Quoted 1 line

+};

...

drivers/iio/dac/ltc2688.c line 645

Quoted 2 lines
drivers/iio/dac/ltc2688.c new file +2 -0
+       for_each_set_bit(bit, &mask, ARRAY_SIZE(ltc2688_clk_names)) {
+               struct clk *clk;

+ blank line

Quoted 6 lines
drivers/iio/dac/ltc2688.c new file +5 -0
+               /*
+                * If a TGP pin is set, then we need to provide a valid clock at
+                * the pin.
+                */
 
+       }

...

drivers/iio/dac/ltc2688.c line 685

Quoted 9 lines
drivers/iio/dac/ltc2688.c new file +8 -0
+       fwnode_for_each_available_child_node(fwnode, child) {
+               struct ltc2688_chan *chan;
+
+               ret = fwnode_property_read_u32(child, "reg", &reg);
+               if (ret) {
+                       fwnode_handle_put(child);
 
+                       return dev_err_probe(&st->spi->dev, ret,
+                                            "Failed to get reg property\n");

One line.

Quoted 1 line

+ } else if (reg >= LTC2688_DAC_CHANNELS) {

Redundant 'else'.

drivers/iio/dac/ltc2688.c line 689

Quoted 4 lines
drivers/iio/dac/ltc2688.c new file +3 -0
+                       fwnode_handle_put(child);
+                       return dev_err_probe(&st->spi->dev, -EINVAL,
 
+                                            "reg >= %d\n", LTC2688_DAC_CHANNELS);

The message is cryptic. Decrypt it for the user.

Quoted 17 lines
drivers/iio/dac/ltc2688.c new file +17 -0
+               }
+
+               chan = &st->channels[reg];
+               ret = fwnode_property_read_u32(child, "adi,mode", &mode);
+               if (!ret) {
+                       if (mode > LTC2688_CHAN_MODE_DITHER) {
+                               fwnode_handle_put(child);
+                               return dev_err_probe(&st->spi->dev, -EINVAL,
+                                                    "chan mode inv value(%d)\n",
+                                                    mode);
+                       }
+
+                       chan->dither_toggle = true;
+                       if (mode == LTC2688_CHAN_MODE_TOGGLE) {
+                               ltc2688_channels[reg].ext_info = ltc2688_toggle_ext_info;
+                       } else {
+                               ltc2688_channels[reg].ext_info = ltc2688_dither_ext_info;

drivers/iio/dac/ltc2688.c line 715

Quoted 10 lines
drivers/iio/dac/ltc2688.c new file +9 -0
+                               /* enable dither mode */
+                               mask = LTC2688_CH_MODE_MSK;
+                               val = BIT(11);
+                       }
+               }
+
+               ret = fwnode_property_read_u32(child, "adi,toggle-dither-input",
+                                              &clk_input);
 
+               if (!ret) {

if (ret) {
if ...
} else {
...
}

drivers/iio/dac/ltc2688.c line 727

Quoted 12 lines
drivers/iio/dac/ltc2688.c new file +12 -0
+                       if (clk_input > LTC2688_CHAN_TD_TGP3) {
+                               fwnode_handle_put(child);
+                               return dev_err_probe(&st->spi->dev, -EINVAL,
+                                                    "toggle-dither-input inv value(%d)\n",
+                                                    clk_input);
+                       }
+
+                       clk_msk |= BIT(clk_input);
+                       mask |= LTC2688_CH_TD_SEL_MSK;
+                       /*
+                        * 0 means software toggle which we are not supporting
+                        * for now. Hence the +1

In all multi-line comments miseed (grammatical) period.

Quoted 4 lines
drivers/iio/dac/ltc2688.c new file +4 -0
+                        */
+                       val |= FIELD_PREP(LTC2688_CH_TD_SEL_MSK, clk_input + 1);
+               } else if (chan->dither_toggle) {
+                       /*

drivers/iio/dac/ltc2688.c line 741

Quoted 10 lines
drivers/iio/dac/ltc2688.c new file +9 -0
+                        * As sw_toggle is not supported, we need to make sure
+                        * a valid input is selected if toggle/dither mode is
+                        * requested
+                        */
+                       return dev_err_probe(&st->spi->dev, -EINVAL,
+                                            "toggle-dither set but no toggle-dither-input\n");
+               }
 
+               chan->overrange = fwnode_property_read_bool(child,
+                                                           "adi,overrange");

One line?

Quoted 20 lines
drivers/iio/dac/ltc2688.c new file +20 -0
+               if (chan->overrange) {
+                       val |= LTC2688_CH_OVERRANGE_MSK;
+                       mask |= BIT(3);
+               }
+
+               if (!mask)
+                       continue;
+
+               ret = regmap_update_bits(st->regmap,
+                                        LTC2688_CMD_CH_SETTING(reg), mask,
+                                        val);
+               if (ret) {
+                       fwnode_handle_put(child);
+                       return dev_err_probe(&st->spi->dev, -EINVAL,
+                                            "failed to set chan settings\n");
+               }
+
+               mask = 0;
+               val = 0;
+       }

...

drivers/iio/dac/ltc2688.c line 777

Quoted 6 lines
drivers/iio/dac/ltc2688.c new file +6 -0
+       int fs = ltc2688_span_helper[idx][1] - ltc2688_span_helper[idx][0];
+
+       if (chan->overrange)
+               fs = mult_frac(fs, 105, 100);
+
+       return fs;

if (...)
return ...
?

...

Quoted 1 line

+ u32 c, i;

In one case you use int or unsigned int if I'm not mistaken, here out of a sudden u32. Why? Please, be consistent over the code.

...

drivers/iio/dac/ltc2688.c line 793

Quoted 3 lines
drivers/iio/dac/ltc2688.c new file +3 -0
+                       /* we will return IIO_VAL_INT_PLUS_NANO */
+                       s = DIV_ROUND_CLOSEST_ULL(st->vref * fs * 1000000000ULL,
+                                                 4096 * 1 << 16);

Can you make use of one of the SI prefixes here? (See unit.h)

...

drivers/iio/dac/ltc2688.c line 811

Quoted 6 lines
drivers/iio/dac/ltc2688.c new file +5 -0
+       gpio = devm_gpiod_get_optional(&st->spi->dev, "reset", GPIOD_OUT_HIGH);
+       if (IS_ERR(gpio))
+               return dev_err_probe(&st->spi->dev, PTR_ERR(gpio),
+                                    "Failed to get reset gpio");
 
+

Redundant blank line.

drivers/iio/dac/ltc2688.c line 816

Quoted 6 lines
drivers/iio/dac/ltc2688.c new file +5 -0
+       if (gpio) {
+               usleep_range(1000, 1200);
+               /* bring device out of reset */
+               gpiod_set_value_cansleep(gpio, 0);
 
+       } else {

I'm wondering why 'else'? Can't it be both? Why not?

drivers/iio/dac/ltc2688.c line 824

Quoted 8 lines
drivers/iio/dac/ltc2688.c new file +8 -0
+               ret = regmap_update_bits(st->regmap, LTC2688_CMD_CONFIG_REG,
+                                        LTC2688_CONFIG_RST,
+                                        LTC2688_CONFIG_RST);
+               if (ret < 0)
+                       return ret;
+       }
+
+       usleep_range(10000, 12000);

+ blank line, so the reader won't be confused about the function of this sleep.

drivers/iio/dac/ltc2688.c line 832

Quoted 8 lines
drivers/iio/dac/ltc2688.c new file +8 -0
+       ret = ltc2688_channel_config(st);
+       if (ret < 0)
+               return ret;
+
+       if (vref) {
+               ret = regmap_update_bits(st->regmap, LTC2688_CMD_CONFIG_REG,
+                                        LTC2688_CONFIG_EXT_REF, BIT(1));
+               if (ret < 0)

These ' < 0' parts are inconsistent over the code.

Quoted 6 lines
drivers/iio/dac/ltc2688.c new file +6 -0
+                       return ret;
+       }
+
+       ltc2688_span_avail_compute(st);
+       return 0;
+}

...

drivers/iio/dac/ltc2688.c line 891

Quoted 2 lines
drivers/iio/dac/ltc2688.c new file +2 -0
+       /* ignoring the no op command */
+       .max_register = U16_MAX - 1

Really?! Have you ever considered what burden you bring with this to one who accidentally or on purpose tries to dump registers via debugfs?

...

Quoted 1 line

+ st->regmap = devm_regmap_init(&spi->dev, NULL, st, &ltc2688_regmap_config);

I'm wondering why it's not a regmap SPI?

Quoted 3 lines
drivers/iio/dac/ltc2688.c new file +3 -0
+       if (IS_ERR(st->regmap))
+               return dev_err_probe(&spi->dev, PTR_ERR(st->regmap),
+                                    "Failed to init regmap");

...

drivers/iio/dac/ltc2688.c line 927

Quoted 7 lines
drivers/iio/dac/ltc2688.c new file +7 -0
+       ret = ltc2688_regulator_supply_get(st, "vcc");
+       if (ret)
+               return ret;
+
+       ret = ltc2688_regulator_supply_get(st, "iovcc");
+       if (ret)
+               return ret;

Can bulk regulators be used?

...

Quoted 1 line

+ st->vref = ret / 1000;

Make use of unit.h

--
With Best Regards,
Andy Shevchenko

author maintainer
#3 lore raw

RE: [RFC PATCH 1/1] iio: dac: add support for ltc2688

Hi Andy,

Thanks for the preliminary review...

Quoted 29 lines

From: Andy Shevchenko <[email protected]>
Sent: Thursday, November 11, 2021 2:49 PM
To: Sa, Nuno <[email protected]>
Cc: linux-iio <[email protected]>; Jonathan Cameron <[email protected]>
Subject: Re: [RFC PATCH 1/1] iio: dac: add support for ltc2688

[External]

Quoted 3 lines · Nuno Sá

The LTC2688 is a 16 channel, 16 bit, +-15V DAC with an integrated precission reference. It is guaranteed monotonic and has built in

precision

Quoted 1 line

rail-to-rail output buffers that can source or sink up to 20 mA.

It's in good shape, several comments below, though.

...

drivers/iio/dac/ltc2688.c

Quoted 6 lines
drivers/iio/dac/ltc2688.c new file +6 -0
+enum {
+       LTC2688_SPAN_RANGE_0V_5V,
+       LTC2688_SPAN_RANGE_M10V_10V,
+       LTC2688_SPAN_RANGE_M15V_15V,
+       /*
+        * These 2 were deliberately re-arranged to be the last items as
Quoted 4 lines

they

Quoted 1 line

+ * have the same fs and we will just return 1 in read_available.

WTH "fs" mean?

full scale... will spell it out

Quoted 13 lines
Quoted 5 lines
drivers/iio/dac/ltc2688.c new file +5 -0
+        */
+       LTC2688_SPAN_RANGE_0V_10V,
+       LTC2688_SPAN_RANGE_M5V_5V,
+       LTC2688_SPAN_RANGE_MAX
+};

...

Quoted 4 lines
drivers/iio/dac/ltc2688.c new file +4 -0
+static const int ltc2688_off_tbl[LTC2688_SPAN_RANGE_MAX] = {
+       [LTC2688_SPAN_RANGE_0V_5V] = 0,
+       [LTC2688_SPAN_RANGE_M10V_10V] = -32768,
+       [LTC2688_SPAN_RANGE_M15V_15V] = -32768,
Quoted 6 lines

drivers/iio/dac/ltc2688.c line 79

Quoted 2 lines
drivers/iio/dac/ltc2688.c new file +2 -0
+       [LTC2688_SPAN_RANGE_0V_10V] = 0,
+       [LTC2688_SPAN_RANGE_M5V_5V] = -32768

+ Comma

Isn't it more natural to move them up by two lines?

There's a reason for this to be ordered like this. Anyways, as I said in the cover letter I will probably remove all of these things used to validate scale + offset pairs. I think is a bit overdone...

Quoted 17 lines

drivers/iio/dac/ltc2688.c line 87

Quoted 8 lines
drivers/iio/dac/ltc2688.c new file +8 -0
+};
+
+static const int ltc2688_reg_val[LTC2688_SPAN_RANGE_MAX] = {
+       [LTC2688_SPAN_RANGE_0V_5V] = 0,
+       [LTC2688_SPAN_RANGE_M10V_10V] = 3,
+       [LTC2688_SPAN_RANGE_M15V_15V] = 4,
+       [LTC2688_SPAN_RANGE_0V_10V] = 1,
+       [LTC2688_SPAN_RANGE_M5V_5V] = 2

As per above.

Quoted 1 line

+};

...

Quoted 1 line

+static int ltc2688_span_set(const struct ltc2688_state *st, int c, int

span)

Quoted 8 lines

drivers/iio/dac/ltc2688.c line 173

Quoted 6 lines
drivers/iio/dac/ltc2688.c new file +5 -0
+{
+       const struct ltc2688_chan *chan = &st->channels[c];
+       u32 i = ARRAY_SIZE(chan->span_tbl);
+       int off = ltc2688_offset_avail[chan->offset_idx];
 
+       while (i--) {

Can ARRAY_SIZE() give 0?

nope

Quoted 1 line

If not, do {} while (--i); looks more natural.

can do like that

Quoted 11 lines
Quoted 10 lines
drivers/iio/dac/ltc2688.c new file +10 -0
+               if (span == chan->span_tbl[i][1]) {
+                       /*
+                        * The selected scale needs to fit  the current offset.
+                        * Note that for [0V 10V] and [-5V 5V], as the scale is
+                        * the same, we will always succeed here. Hence if
+                        * someone really wants [0 10V] and does not set the
+                        * offset to 0, then :man-shrugging:
+                        */
+                       if (off == ltc2688_off_tbl[i]) {
+                               break;
Quoted 3 lines
Quoted 1 line

+ } else if (i < LTC2688_SPAN_RANGE_0V_10V) {

Redundant 'else'.

Why? Note that I really (where possible) want to make a distinction between the errors... Again, I will probably remove this part and only match 'if (span == chan->span_tbl[i][1])'

Quoted 5 lines

drivers/iio/dac/ltc2688.c

Quoted 5 lines
drivers/iio/dac/ltc2688.c new file +5 -0
+                               /*
+                                * At this point, only one offset is valid so we
+                                * already can assume error.
+                                */
+                               dev_err(&st->spi->dev, "Offset(%d) not valid for
Quoted 8 lines

current scale(0.%09d)\n",

drivers/iio/dac/ltc2688.c line 194

Quoted 5 lines
drivers/iio/dac/ltc2688.c new file +4 -0
+                                       off, span);
+                               return -EPERM;
+                       }
 
+                       continue;

Redundant, see below.

true, but at this point I already know that doing the next if (!i) is not really needed. But yeah, less lines of code

Quoted 32 lines

drivers/iio/dac/ltc2688.c

Quoted 5 lines
drivers/iio/dac/ltc2688.c new file +3 -0
+               }
 
+               if (!i) {
+                       dev_err(&st->spi->dev, "span(%d) not available\n",

span);

Review

Quoted 2 lines
(quoted diff) +2 -0
+                       return -EINVAL;
+               }

This is invariant to the loop.

drivers/iio/dac/ltc2688.c line 431

Quoted 3 lines
drivers/iio/dac/ltc2688.c new file +3 -0
+       }
+
+       return regmap_update_bits(st->regmap,

LTC2688_CMD_CH_SETTING(c),

Review

Quoted 2 lines
(quoted diff) +2 -0
+                                 LTC2688_CH_SPAN_MSK,
+                                 FIELD_PREP(LTC2688_CH_SPAN_MSK,

ltc2688_reg_val[i]));

Quoted 1 line

+};

...

Quoted 1 line

+ if (off != ltc2688_offset_avail[0] && off !=

ltc2688_offset_avail[1])

Quoted 1 line

+ return -EINVAL;

Extra condition, See below.

drivers/iio/dac/ltc2688.c line 217

Quoted 3 lines
drivers/iio/dac/ltc2688.c new file +3 -0
+       if (off == ltc2688_offset_avail[0])
+               chan->offset_idx = 0;
+       else
Quoted 6 lines

else if

Quoted 1 line

+ chan->offset_idx = 1;

else
return -EINVAL;

sure...

Quoted 6 lines

...

drivers/iio/dac/ltc2688.c line 370

Quoted 2 lines
drivers/iio/dac/ltc2688.c new file +2 -0
+       ret = regmap_read(st->regmap, reg, &regval);
+       if (ret < 0)

Is it the first time you tested explicitly for a negative result?

should not be like this...

Quoted 7 lines
Quoted 1 line

+ return ret;

...

Quoted 1 line

+ return sprintf(buf, "%u\n", !!(regval & BIT(chan->channel)));

sysfs_emit() ?

definetly...

Quoted 10 lines
Quoted 1 line

+}

...

drivers/iio/dac/ltc2688.c line 384

Quoted 4 lines
drivers/iio/dac/ltc2688.c new file +4 -0
+       struct ltc2688_state *st = iio_priv(indio_dev);
+       bool en;
+       int ret;
+       u32 val = 0, reg;

Reversed xmas tree order ?

sure

Quoted 4 lines
Quoted 2 lines

+ ret = strtobool(buf, &en);

kstrtobool()

sure

Quoted 8 lines

...

drivers/iio/dac/ltc2688.c line 158

Quoted 3 lines
drivers/iio/dac/ltc2688.c new file +3 -0
+       if (ret)
+               return ret;
+               break;

What does this mean?

means I was sleeping...

Quoted 9 lines

...

drivers/iio/dac/ltc2688.c line 516

Quoted 5 lines
drivers/iio/dac/ltc2688.c new file +5 -0
+       "4",
+       "8",
+       "16",
+       "32",
+       "64",

One line?

yes

Quoted 54 lines

...

drivers/iio/dac/ltc2688.c line 530

Quoted 4 lines
drivers/iio/dac/ltc2688.c new file +4 -0
+       "0",
+       "90",
+       "180",
+       "270",

Ditto.

...

drivers/iio/dac/ltc2688.c line 620

Quoted 3 lines
drivers/iio/dac/ltc2688.c new file +3 -0
+enum {
+       LTC2688_CHAN_MODE_TOGGLE,
+       LTC2688_CHAN_MODE_DITHER

+ Comma.

Quoted 1 line

+};

...

Quoted 1 line

+static const char * const

ltc2688_clk_names[LTC2688_CHAN_TD_MAX] = {

Quoted 1 line

+ "TGP1", "TGP2", "TGP3"

In this notation, + comma.

Quoted 1 line

+};

...

Quoted 1 line

+ for_each_set_bit(bit, &mask, ARRAY_SIZE(ltc2688_clk_names))

{

Quoted 1 line

+ struct clk *clk;

+ blank line

Quoted 6 lines
drivers/iio/dac/ltc2688.c new file +5 -0
+               /*
+                * If a TGP pin is set, then we need to provide a valid clock at
+                * the pin.
+                */
 
+       }

...

Quoted 6 lines
drivers/iio/dac/ltc2688.c new file +6 -0
+       fwnode_for_each_available_child_node(fwnode, child) {
+               struct ltc2688_chan *chan;
+
+               ret = fwnode_property_read_u32(child, "reg", &reg);
+               if (ret) {
+                       fwnode_handle_put(child);
Quoted 8 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+                       return dev_err_probe(&st->spi->dev, ret,
+                                            "Failed to get reg property\n");

One line.

Quoted 1 line

+ } else if (reg >= LTC2688_DAC_CHANNELS) {

Redundant 'else'.

Do you mean?

if (ret)
...

if (reg >= LTC2688_DAC_CHANNELS)
....

Quoted 37 lines

drivers/iio/dac/ltc2688.c line 689

Quoted 4 lines
drivers/iio/dac/ltc2688.c new file +3 -0
+                       fwnode_handle_put(child);
+                       return dev_err_probe(&st->spi->dev, -EINVAL,
 
+                                            "reg >= %d\n", LTC2688_DAC_CHANNELS);

The message is cryptic. Decrypt it for the user.

drivers/iio/dac/ltc2688.c

Quoted 4 lines
drivers/iio/dac/ltc2688.c new file +4 -0
+               }
+
+               chan = &st->channels[reg];
+               ret = fwnode_property_read_u32(child, "adi,mode",

&mode);

drivers/iio/dac/ltc2688.c

Quoted 11 lines
drivers/iio/dac/ltc2688.c new file +11 -0
+               if (!ret) {
+                       if (mode > LTC2688_CHAN_MODE_DITHER) {
+                               fwnode_handle_put(child);
+                               return dev_err_probe(&st->spi->dev, -EINVAL,
+                                                    "chan mode inv value(%d)\n",
+                                                    mode);
+                       }
+
+                       chan->dither_toggle = true;
+                       if (mode == LTC2688_CHAN_MODE_TOGGLE) {
+                               ltc2688_channels[reg].ext_info =

ltc2688_toggle_ext_info;

Review

Quoted 2 lines
(quoted diff) +2 -0
+                       } else {
+                               ltc2688_channels[reg].ext_info =

ltc2688_dither_ext_info;

drivers/iio/dac/ltc2688.c

Quoted 7 lines
drivers/iio/dac/ltc2688.c new file +7 -0
+                               /* enable dither mode */
+                               mask = LTC2688_CH_MODE_MSK;
+                               val = BIT(11);
+                       }
+               }
+
+               ret = fwnode_property_read_u32(child, "adi,toggle-dither-

input",

Quoted 1 line

+ &clk_input);

Quoted 7 lines
Quoted 1 line

+ if (!ret) {

if (ret) {
if ...
} else {
...
}

sure

Quoted 26 lines

drivers/iio/dac/ltc2688.c line 727

Quoted 12 lines
drivers/iio/dac/ltc2688.c new file +12 -0
+                       if (clk_input > LTC2688_CHAN_TD_TGP3) {
+                               fwnode_handle_put(child);
+                               return dev_err_probe(&st->spi->dev, -EINVAL,
+                                                    "toggle-dither-input inv value(%d)\n",
+                                                    clk_input);
+                       }
+
+                       clk_msk |= BIT(clk_input);
+                       mask |= LTC2688_CH_TD_SEL_MSK;
+                       /*
+                        * 0 means software toggle which we are not supporting
+                        * for now. Hence the +1

In all multi-line comments miseed (grammatical) period.

Review

Quoted 2 lines
(quoted diff) +2 -0
+                        */
+                       val |= FIELD_PREP(LTC2688_CH_TD_SEL_MSK, clk_input

+ 1);

drivers/iio/dac/ltc2688.c

Quoted 8 lines
drivers/iio/dac/ltc2688.c new file +8 -0
+               } else if (chan->dither_toggle) {
+                       /*
+                        * As sw_toggle is not supported, we need to make sure
+                        * a valid input is selected if toggle/dither mode is
+                        * requested
+                        */
+                       return dev_err_probe(&st->spi->dev, -EINVAL,
+                                            "toggle-dither set but no toggle-dither-
Quoted 7 lines

input\n");

drivers/iio/dac/ltc2688.c line 741

Quoted 4 lines
drivers/iio/dac/ltc2688.c new file +3 -0
+               }
 
+               chan->overrange = fwnode_property_read_bool(child,
+                                                           "adi,overrange");

One line?

It will pass the 80 col limit. AFAIR, Jonathan prefers to keep it when it does not hurt readability...

Quoted 25 lines
Quoted 20 lines
drivers/iio/dac/ltc2688.c new file +20 -0
+               if (chan->overrange) {
+                       val |= LTC2688_CH_OVERRANGE_MSK;
+                       mask |= BIT(3);
+               }
+
+               if (!mask)
+                       continue;
+
+               ret = regmap_update_bits(st->regmap,
+                                        LTC2688_CMD_CH_SETTING(reg), mask,
+                                        val);
+               if (ret) {
+                       fwnode_handle_put(child);
+                       return dev_err_probe(&st->spi->dev, -EINVAL,
+                                            "failed to set chan settings\n");
+               }
+
+               mask = 0;
+               val = 0;
+       }

...

Quoted 1 line

+ int fs = ltc2688_span_helper[idx][1] -

ltc2688_span_helper[idx][0];

Quoted 9 lines

drivers/iio/dac/ltc2688.c line 777

Quoted 5 lines
drivers/iio/dac/ltc2688.c new file +5 -0
+
+       if (chan->overrange)
+               fs = mult_frac(fs, 105, 100);
+
+       return fs;

if (...)
return ...
?

Yes...

Quoted 6 lines

...

Quoted 1 line

+ u32 c, i;

In one case you use int or unsigned int if I'm not mistaken, here out of a sudden u32. Why? Please, be consistent over the code.

I will check that...

Quoted 8 lines

...

Review

Quoted 2 lines
(quoted diff) +2 -0
+                       /* we will return IIO_VAL_INT_PLUS_NANO */
+                       s = DIV_ROUND_CLOSEST_ULL(st->vref * fs *

1000000000ULL,

Quoted 1 line

+ 4096 * 1 << 16);

Can you make use of one of the SI prefixes here? (See unit.h)

Sure

Quoted 12 lines

...

Quoted 1 line

+ gpio = devm_gpiod_get_optional(&st->spi->dev, "reset",

GPIOD_OUT_HIGH);

drivers/iio/dac/ltc2688.c line 811

Quoted 5 lines
drivers/iio/dac/ltc2688.c new file +4 -0
+       if (IS_ERR(gpio))
+               return dev_err_probe(&st->spi->dev, PTR_ERR(gpio),
+                                    "Failed to get reset gpio");
 
+

Redundant blank line.

Quoted 8 lines

drivers/iio/dac/ltc2688.c line 816

Quoted 6 lines
drivers/iio/dac/ltc2688.c new file +5 -0
+       if (gpio) {
+               usleep_range(1000, 1200);
+               /* bring device out of reset */
+               gpiod_set_value_cansleep(gpio, 0);
 
+       } else {

I'm wondering why 'else'? Can't it be both? Why not?

Well, if we have the reset pin, then we reset using it. If there's no pin, we use the SW reset. It's a common pattern that we already use for example in the ADIS devices.

Quoted 19 lines
Quoted 1 line

+ ret = regmap_update_bits(st->regmap,

LTC2688_CMD_CONFIG_REG,

drivers/iio/dac/ltc2688.c line 824

Quoted 7 lines
drivers/iio/dac/ltc2688.c new file +7 -0
+                                        LTC2688_CONFIG_RST,
+                                        LTC2688_CONFIG_RST);
+               if (ret < 0)
+                       return ret;
+       }
+
+       usleep_range(10000, 12000);

+ blank line, so the reader won't be confused about the function of this sleep.

drivers/iio/dac/ltc2688.c

Quoted 6 lines
drivers/iio/dac/ltc2688.c new file +6 -0
+       ret = ltc2688_channel_config(st);
+       if (ret < 0)
+               return ret;
+
+       if (vref) {
+               ret = regmap_update_bits(st->regmap,
Quoted 5 lines

LTC2688_CMD_CONFIG_REG,

drivers/iio/dac/ltc2688.c line 832

Quoted 2 lines
drivers/iio/dac/ltc2688.c new file +2 -0
+                                        LTC2688_CONFIG_EXT_REF, BIT(1));
+               if (ret < 0)

These ' < 0' parts are inconsistent over the code.

Yes, I will fix that...

Quoted 9 lines
Quoted 6 lines
drivers/iio/dac/ltc2688.c new file +6 -0
+                       return ret;
+       }
+
+       ltc2688_span_avail_compute(st);
+       return 0;
+}

...

Quoted 6 lines

drivers/iio/dac/ltc2688.c line 891

Quoted 2 lines
drivers/iio/dac/ltc2688.c new file +2 -0
+       /* ignoring the no op command */
+       .max_register = U16_MAX - 1

Really?! Have you ever considered what burden you bring with this to one who accidentally or on purpose tries to dump registers via debugfs?

Ups, this is completely wrong!! It should be U8_MAX...

Quoted 6 lines

...

Quoted 1 line

+ st->regmap = devm_regmap_init(&spi->dev, NULL, st,

&ltc2688_regmap_config);

I'm wondering why it's not a regmap SPI?

The problem is on the read side... In the first transfer we write the command/register to read, then we need to release the CS pin so that the device executes the command, and only then we read the data. AFAIK, the regmap spi implementation won't work like this. I think CS is kept asserted the whole time...

Quoted 14 lines
Quoted 3 lines
drivers/iio/dac/ltc2688.c new file +3 -0
+       if (IS_ERR(st->regmap))
+               return dev_err_probe(&spi->dev, PTR_ERR(st->regmap),
+                                    "Failed to init regmap");

...

drivers/iio/dac/ltc2688.c line 927

Quoted 7 lines
drivers/iio/dac/ltc2688.c new file +7 -0
+       ret = ltc2688_regulator_supply_get(st, "vcc");
+       if (ret)
+               return ret;
+
+       ret = ltc2688_regulator_supply_get(st, "iovcc");
+       if (ret)
+               return ret;
Quoted 1 line

Can bulk regulators be used?

Hmm, I need to check but I think so... There's no ordering requirement here

Quoted 6 lines

...

Quoted 1 line

+ st->vref = ret / 1000;

Make use of unit.h

- Nuno Sá

#4 lore raw

Re: [RFC PATCH 1/1] iio: dac: add support for ltc2688

Quoted 4 lines · Nuno
Quoted 4 lines

From: Andy Shevchenko <[email protected]>
Sent: Thursday, November 11, 2021 2:49 PM
On Thu, Nov 11, 2021 at 1:01 PM Nuno Sá <[email protected]> wrote:

...

Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
drivers/iio/dac/ltc2688.c new file +4 -0
+static const int ltc2688_off_tbl[LTC2688_SPAN_RANGE_MAX] = {
+       [LTC2688_SPAN_RANGE_0V_5V] = 0,
+       [LTC2688_SPAN_RANGE_M10V_10V] = -32768,
+       [LTC2688_SPAN_RANGE_M15V_15V] = -32768,
Quoted 8 lines
Quoted 6 lines

drivers/iio/dac/ltc2688.c line 79

Quoted 2 lines
drivers/iio/dac/ltc2688.c new file +2 -0
+       [LTC2688_SPAN_RANGE_0V_10V] = 0,
+       [LTC2688_SPAN_RANGE_M5V_5V] = -32768

+ Comma

Isn't it more natural to move them up by two lines?

There's a reason for this to be ordered like this.

I understand that for enum, but here it doesn't make any sense to me since you are addressing them by indices.

Quoted 5 lines

Anyways,
as I said in the cover letter I will probably remove all of these things used to validate scale + offset pairs. I think is a bit overdone...

Quoted 1 line
Quoted 1 line

+};

...

Quoted 9 lines
Quoted 6 lines

drivers/iio/dac/ltc2688.c line 184

Quoted 4 lines
drivers/iio/dac/ltc2688.c new file +3 -0
+                       if (off == ltc2688_off_tbl[i]) {
+                               break;
 
+                       } else if (i < LTC2688_SPAN_RANGE_0V_10V) {

Redundant 'else'.

Why? Note that I really (where possible) want to make a distinction between the errors...

while () {
if ()

    ...
    break;
  } else {
    ...

}
}

Isn't it obvious?

Same with

if ()
return
else
...

Quoted 1 line
Quoted 1 line
Quoted 1 line

+ }

...

Quoted 13 lines
Quoted 4 lines
Quoted 3 lines
drivers/iio/dac/ltc2688.c new file +3 -0
+               ret = fwnode_property_read_u32(child, "reg", &reg);
+               if (ret) {
+                       fwnode_handle_put(child);
Quoted 8 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+                       return dev_err_probe(&st->spi->dev, ret,
+                                            "Failed to get reg property\n");

One line.

Quoted 1 line

+ } else if (reg >= LTC2688_DAC_CHANNELS) {

Redundant 'else'.

Quoted 7 lines

Do you mean?

if (ret)
...

if (reg >= LTC2688_DAC_CHANNELS)
....

Yes.

Quoted 1 line
Quoted 1 line
Quoted 1 line

+ }

...

Quoted 7 lines
Quoted 4 lines

drivers/iio/dac/ltc2688.c line 741

Quoted 2 lines
drivers/iio/dac/ltc2688.c new file +2 -0
+               chan->overrange = fwnode_property_read_bool(child,
+                                                           "adi,overrange");

One line?

It will pass the 80 col limit. AFAIR, Jonathan prefers to keep it when it does not hurt readability...

I believe it will increase readability being located on one line.

...

Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
drivers/iio/dac/ltc2688.c new file +4 -0
+       if (gpio) {
+               usleep_range(1000, 1200);
+               /* bring device out of reset */
+               gpiod_set_value_cansleep(gpio, 0);
Quoted 7 lines
Quoted 3 lines
Quoted 1 line

+ } else {

I'm wondering why 'else'? Can't it be both? Why not?

Well, if we have the reset pin, then we reset using it. If there's no pin, we use the SW reset. It's a common pattern that we already use for example in the ADIS devices.

Perhaps a comment in the code is needed.

Quoted 7 lines
Quoted 7 lines
Quoted 1 line

+ ret = regmap_update_bits(st->regmap,

LTC2688_CMD_CONFIG_REG,

Quoted 5 lines
drivers/iio/dac/ltc2688.c new file +5 -0
+                                        LTC2688_CONFIG_RST,
+                                        LTC2688_CONFIG_RST);
+               if (ret < 0)
+                       return ret;
+       }

...

Quoted 8 lines
Quoted 6 lines

drivers/iio/dac/ltc2688.c line 891

Quoted 2 lines
drivers/iio/dac/ltc2688.c new file +2 -0
+       /* ignoring the no op command */
+       .max_register = U16_MAX - 1

Really?! Have you ever considered what burden you bring with this to one who accidentally or on purpose tries to dump registers via debugfs?

Ups, this is completely wrong!! It should be U8_MAX...

Ah, that explains!

...

Quoted 9 lines
Quoted 4 lines
Quoted 1 line

+ st->regmap = devm_regmap_init(&spi->dev, NULL, st,

&ltc2688_regmap_config);

I'm wondering why it's not a regmap SPI?

The problem is on the read side... In the first transfer we write the command/register to read, then we need to release the CS pin so that the device executes the command, and only then we read the data. AFAIK, the regmap spi implementation won't work like this. I think CS is kept asserted the whole time...

I believe it's configurable, no? Like the cs_change flag somewhere. Can you double check?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
author maintainer
#5 lore raw

RE: [RFC PATCH 1/1] iio: dac: add support for ltc2688

Quoted 30 lines

-----Original Message-----
From: Andy Shevchenko <[email protected]>
Sent: Thursday, November 11, 2021 3:42 PM
To: Sa, Nuno <[email protected]>
Cc: linux-iio <[email protected]>; Jonathan Cameron <[email protected]>
Subject: Re: [RFC PATCH 1/1] iio: dac: add support for ltc2688

[External]

Quoted 4 lines · Nuno
Quoted 4 lines

From: Andy Shevchenko <[email protected]>
Sent: Thursday, November 11, 2021 2:49 PM
On Thu, Nov 11, 2021 at 1:01 PM Nuno Sá <[email protected]> wrote:

...

Quoted 1 line
Quoted 1 line
Quoted 1 line

+static const int ltc2688_off_tbl[LTC2688_SPAN_RANGE_MAX] =

{

Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
drivers/iio/dac/ltc2688.c new file +5 -0
+       [LTC2688_SPAN_RANGE_0V_5V] = 0,
+       [LTC2688_SPAN_RANGE_M10V_10V] = -32768,
+       [LTC2688_SPAN_RANGE_M15V_15V] = -32768,
 
+       [LTC2688_SPAN_RANGE_0V_10V] = 0,
+       [LTC2688_SPAN_RANGE_M5V_5V] = -32768
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

+ Comma

Isn't it more natural to move them up by two lines?

There's a reason for this to be ordered like this.

I understand that for enum, but here it doesn't make any sense to me since you are addressing them by indices.

Yeah, right... If we keep this, I will do as you suggested

Quoted 20 lines
Quoted 5 lines

Anyways,
as I said in the cover letter I will probably remove all of these things used to validate scale + offset pairs. I think is a bit overdone...

Quoted 1 line
Quoted 1 line

+};

...

Quoted 9 lines
Quoted 6 lines

drivers/iio/dac/ltc2688.c line 184

Quoted 4 lines
drivers/iio/dac/ltc2688.c new file +3 -0
+                       if (off == ltc2688_off_tbl[i]) {
+                               break;
 
+                       } else if (i < LTC2688_SPAN_RANGE_0V_10V) {

Redundant 'else'.

Why? Note that I really (where possible) want to make a distinction between the errors...

while () {
if ()

Quoted 8 lines
    ...
    break;
  } else {
    ...

}
}

Isn't it obvious?

Ah ok, I see know what you mean (and yes, it is obvious; for my shame)...

if ()
break

if ()
return -EPERM

As we do the break, the else becomes irrelevant

Quoted 6 lines

Same with

if ()
return
else
...

yeah yeah...

Quoted 34 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

+ }

...

Quoted 13 lines
Quoted 4 lines
Quoted 3 lines
drivers/iio/dac/ltc2688.c new file +3 -0
+               ret = fwnode_property_read_u32(child, "reg", &reg);
+               if (ret) {
+                       fwnode_handle_put(child);
Quoted 8 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+                       return dev_err_probe(&st->spi->dev, ret,
+                                            "Failed to get reg property\n");

One line.

Quoted 1 line

+ } else if (reg >= LTC2688_DAC_CHANNELS) {

Redundant 'else'.

Quoted 7 lines

Do you mean?

if (ret)
...

if (reg >= LTC2688_DAC_CHANNELS)
....

Yes.

Quoted 1 line
Quoted 1 line
Quoted 1 line

+ }

...

Quoted 3 lines
Quoted 3 lines
Quoted 2 lines
drivers/iio/dac/ltc2688.c new file +2 -0
+               chan->overrange = fwnode_property_read_bool(child,
+                                                           "adi,overrange");
Quoted 6 lines
Quoted 4 lines
Quoted 1 line

One line?

It will pass the 80 col limit. AFAIR, Jonathan prefers to keep it when it does not hurt readability...

I believe it will increase readability being located on one line.

I mean, this is perfectly aligned with the open "(", so it's a pretty normal pattern. Anyways, I'm more than happy to move this into a one liner and just use the 100 limit. But let's see what Jonathan has to say because I do not want to move back and forward...

Quoted 9 lines

...

Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
drivers/iio/dac/ltc2688.c new file +5 -0
+       if (gpio) {
+               usleep_range(1000, 1200);
+               /* bring device out of reset */
+               gpiod_set_value_cansleep(gpio, 0);
 
+       } else {
Quoted 8 lines
Quoted 4 lines
Quoted 1 line

I'm wondering why 'else'? Can't it be both? Why not?

Well, if we have the reset pin, then we reset using it. If there's no pin, we use the SW reset. It's a common pattern that we already

use

Quoted 1 line

for example in the ADIS devices.

Perhaps a comment in the code is needed.

can do that...

Quoted 31 lines
Quoted 7 lines
Quoted 7 lines
Quoted 1 line

+ ret = regmap_update_bits(st->regmap,

LTC2688_CMD_CONFIG_REG,

Quoted 5 lines
drivers/iio/dac/ltc2688.c new file +5 -0
+                                        LTC2688_CONFIG_RST,
+                                        LTC2688_CONFIG_RST);
+               if (ret < 0)
+                       return ret;
+       }

...

Quoted 4 lines
Quoted 4 lines

drivers/iio/dac/ltc2688.c line 891

Quoted 2 lines
drivers/iio/dac/ltc2688.c new file +2 -0
+       /* ignoring the no op command */
+       .max_register = U16_MAX - 1

Really?! Have you ever considered what burden you bring with this

to

Quoted 4 lines
Quoted 2 lines

one who accidentally or on purpose tries to dump registers via debugfs?

Ups, this is completely wrong!! It should be U8_MAX...

Ah, that explains!

...

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

+ st->regmap = devm_regmap_init(&spi->dev, NULL, st,

&ltc2688_regmap_config);

I'm wondering why it's not a regmap SPI?

The problem is on the read side... In the first transfer we write the

command/register

Quoted 8 lines
Quoted 1 line

to read, then we need to release the CS pin so that the device

executes the command,

Quoted 1 line

and only then we read the data. AFAIK, the regmap spi

implementation won't work like

Quoted 1 line

this. I think CS is kept asserted the whole time...

I believe it's configurable, no? Like the cs_change flag somewhere. Can you double check?

Don't think we can... The read part just calls:
https://elixir.bootlin.com/linux/latest/source/drivers/base/regmap/regmap-spi.c#L98
and has no control over the spi transfer bits...

- Nuno Sá

maintainer
#6 lore raw

Re: [RFC PATCH 1/1] iio: dac: add support for ltc2688

Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
Quoted 6 lines

drivers/iio/dac/ltc2688.c line 741

Quoted 4 lines
drivers/iio/dac/ltc2688.c new file +2 -0
+               chan->overrange = fwnode_property_read_bool(child,
+                                                           "adi,overrange");  

One line?

It will pass the 80 col limit. AFAIR, Jonathan prefers to keep it when it does not hurt readability...

Quoted 6 lines
Quoted 1 line

I believe it will increase readability being located on one line.

I mean, this is perfectly aligned with the open "(", so it's a pretty normal pattern. Anyways, I'm more than happy to move this into a one liner and just use the 100 limit. But let's see what Jonathan has to say because I do not want to move back and forward...

Here it happens to be particularly ugly because of the short first parameter, so I'm fine with a longer line for this one.

Quoted 11 lines
Quoted 11 lines
Quoted 6 lines
Quoted 4 lines
Quoted 1 line

+ st->regmap = devm_regmap_init(&spi->dev, NULL, st,

&ltc2688_regmap_config);

I'm wondering why it's not a regmap SPI?

The problem is on the read side... In the first transfer we write the

command/register

Quoted 1 line

to read, then we need to release the CS pin so that the device

executes the command,

Quoted 1 line

and only then we read the data. AFAIK, the regmap spi

implementation won't work like

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

this. I think CS is kept asserted the whole time...

I believe it's configurable, no? Like the cs_change flag somewhere. Can you double check?

Don't think we can... The read part just calls:
https://elixir.bootlin.com/linux/latest/source/drivers/base/regmap/regmap-spi.c#L98
and has no control over the spi transfer bits...

Feature to add then or a custom regmap_bus if you want to keep it in the driver.

J

Quoted 2 lines

- Nuno Sá

author maintainer
#7 lore raw

RE: [RFC PATCH 1/1] iio: dac: add support for ltc2688

Quoted 28 lines

-----Original Message-----
From: Jonathan Cameron <[email protected]>
Sent: Friday, November 12, 2021 4:23 PM
To: Sa, Nuno <[email protected]>
Cc: Andy Shevchenko <[email protected]>; linux-iio <[email protected]>
Subject: Re: [RFC PATCH 1/1] iio: dac: add support for ltc2688

[External]

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

+ chan->overrange =

fwnode_property_read_bool(child,

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

+ "adi,overrange");

One line?

It will pass the 80 col limit. AFAIR, Jonathan prefers to keep it

when it

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

does not hurt readability...

I believe it will increase readability being located on one line.

I mean, this is perfectly aligned with the open "(", so it's a pretty normal pattern. Anyways, I'm more than happy to move this into a

Quoted 8 lines

one

Quoted 2 lines

liner and just use the 100 limit. But let's see what Jonathan has to say because I do not want to move back and forward...

Here it happens to be particularly ugly because of the short first parameter,
so I'm fine with a longer line for this one.

Ok then...

Quoted 20 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

+ st->regmap = devm_regmap_init(&spi->dev, NULL, st,

&ltc2688_regmap_config);

I'm wondering why it's not a regmap SPI?

The problem is on the read side... In the first transfer we write

the

Quoted 12 lines
Quoted 9 lines

command/register

Quoted 1 line

to read, then we need to release the CS pin so that the device

executes the command,

Quoted 1 line

and only then we read the data. AFAIK, the regmap spi

implementation won't work like

Quoted 1 line

this. I think CS is kept asserted the whole time...

I believe it's configurable, no? Like the cs_change flag somewhere. Can you double check?

Don't think we can... The read part just calls:

Quoted 8 lines

https://urldefense.com/v3/__https://elixir.bootlin.com/linux/latest/s
ource/drivers/base/regmap/regmap- spi.c*L98__;Iw!!A3Ni8CS0y2Y!orMauLgKQzcdnc3Mh7DBQY9nGq9sgf8jl KRBR8IOHhKMT2tdkLj9AyvIHDPYmA$

Quoted 1 line

and has no control over the spi transfer bits...

Feature to add then or a custom regmap_bus if you want to keep it in the driver.

Hmm I see what you mean with the custom bus. We can actually make use of more regmap infrastructure if I just define my regmap_bus in the driver. Thanks for the tip!

- Nuno Sá

maintainer
#8 lore raw
In reply to Nuno Sá

On Thu, 11 Nov 2021 12:00:42 +0100
Nuno Sá <[email protected]> wrote:

Hi Nuno,

Quoted 5 lines

The reason why this is a RFC is because I'm still waiting for proper HW to test this thing. The reason why I'm sending this already is because there's some non usual features which might require extra ABI. Hence, while waiting I thought we could already speed up the process in regards with the ABI.

Wise move as this is an unusual beast :)

Quoted 11 lines

I still pushed the driver but the intent here is not really to review it. Naturally, if someone already wants to give some feedback, that's very much appreciated :)

Now, there are three main interfaces depending on the channel mode:
1) default (no new ABI)
2) toggle mode
3) dither mode

Quoted 5 lines

The channel mode will be a devicetree property as it does not really make much sense to change between modes at runtime even more because the piece of HW we might want to control with a channel might be different depending on the selected mode (I'm fairly sure on this between toggle and other modes but not so sure between dither and default mode).

I agree on toggle vs dither definitely being different, but normal you could implement either as software toggle, or dither with a 0 magnitude sine wave. So might not be worth implementing default mode at all. No harm in doing so though if there are advantages to having it.

Quoted 8 lines

toggle mode special ABI:

* Toggle operation enables fast switching of a DAC output between two
different DAC codes without any SPI transaction. Two codes are set in input_a and input_b and then the output switches according to an input signal (input_a -> clk high; input_b -> clk low).

Quoted 10 lines

out_voltageY_input_register
- selects between input_a and input_b. After selecting one register, we can write the dac code in out_voltageY_raw.
out_voltageY_toggle_en
- Disable/Enable toggle mode. The reason why I think this one is important is because if we wanna change the 2 codes, we should first disable this, set the codes and only then enable the mode back... As I'm writing this, It kind of came to me that we can probably achieve this with out_voltageY_powerdown attr (maybe takes a bit more time to see the outputs but...)

Hmm. These corner cases always take a bit of figuring out. What you have here is a bit 'device specific' for my liking.

So there is precedence for ABI in this area, on the frequency devices but only for devices we still haven't moved out of staging. For those we needed a means to define selectable phases for PSK - where the selection was either software or, much like here, a selection pin.

out_altvotage0_phase0 etc

so I guess the equivalent here would be
out_voltageY_raw0
out_voltageY_raw1
and the selection would be via something like out_voltageY_symbol (0 or 1 in this case). - note this is only relevant if you have the software toggle. Any enable needed for setting can be done as part of the write sequence for the raw0 / raw1 and should ideally not be exposed to userspace (controls that require manual sequencing tend to be hard to use / document).

However, I'm not 100% sure it really maps to this case. What do you think?

I'm not sure if whether a channel is in toggle mode is a circuit thing or not.. (and hence DT or userspace control?)
Can see that even in a case where you did want to use external controls to pick the values, you might also want to override from software... Given there is a software toggle I guess we can use that as override. Actually that raises the question of what the point in having normal mode is? Can we just implement that as a software toggle toggle mode? One less thing to worry about if we can.

There is also the question of whether selection of which toggle pin is used should be a dt thing or a userspace control...

Quoted 8 lines

dither mode special ABI:

* Dither operation adds a small sinusoidal wave to the digital DAC
signal path. Dithering is a signal processing technique that involves the injection of ac noise to the signal path to reduce system nonlinearities.

This is a complex feature to describe as (if I read it correctly) we have a dither clocked from an external pin, or in theory from software. That clock frequency must match the dither. Realistically that means it is a clock in our control or we have to match the period below to the frequency of that clock.

Quoted 8 lines

out_voltage0_dither_en
- Same as in toggle mode.
out_voltage0_dither_period
out_voltage0_dither_phase
- Period and phase of the signal. Only some values are valid so there's also *_available files for these. I'm not sure if we can use the more generic IIO_CHAN_INFO_PHASE and IIO_CHAN_INFO_FREQUENCY here as these parameters don't really apply to the channel output signal..

Possibly not helpful to do so, but you could describe the channel as an out_altvoltage channel that happens to have a significant offset (the DC level) and phase, frequency etc as for a normal altvoltage channel.

That would hide the intention here though so perhaps not a good plan even if it ensures we end up with standard ABI.

Quoted 4 lines

out_voltage0_input_register
- Same as in toggle mode. However in this mode the code set in the input_b register has a special meaning. It's the amplitude of the dither signal.

Don't do that - provide a direct attribute representing the value of register_b and when it is written implicitly switch to the right register. Any ABI that requires a sequence of events is hard to use.

Quoted 11 lines

One special mention to the dac scale. In this part this is something that can be purely controlled by SW so that I'm allowing userspace to change it rather then having it in dts. The available scales are:

* [0 5V] -> offset 0
* [0 10V] -> offset 0
* [-5 5V] -> offset -32678
* [-10 10V] -> offset -32768
* [-15 15V] -> offset -32768

Quoted 8 lines

With the above, we also need to have the offset configurable and right now I'm going to some trouble to make sure the scale + offset is something valid. Honestly, I think I'm overdoing it because things can still go wrong with [0 10V] and [-5 5V] as the scales are the same here. Furthermore, there's no real arm that can be done to the HW. Is just that the readings won't match with what someone might be expecting. My plan is to just remove those checks and assume is up to userspace to make it right and not have [-10 10V] scale with 0 offset for example.

So this is something we've debated a few times in the past. There is a fairly strong argument for output devices that the range is a characteristic of the circuit. At the very least it makes sense to restrict it in DT even if we allow safe forms of tweaking in the driver. For an initial driver, I'd just have it in DT.

Jonathan

Quoted 3 lines

I know that I'm taking a shortcut here :) so if you prefer to only discuss this in the __real__ series, I totally get it.

It's a fine short cut to take - I send out RFCs all the time for similar open questions!

Jonathan

Quoted 12 lines

https://www.analog.com/media/en/technical-documentation/data-sheets/ltc2688.pdf

- Nuno Sá

Nuno Sá (1):
iio: dac: add support for ltc2688

 drivers/iio/dac/ltc2688.c | 995 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 995 insertions(+)
 create mode 100644 drivers/iio/dac/ltc2688.c
author maintainer
#9 lore raw

Hi Jonathan,

Thanks for your inputs...

Quoted 42 lines

From: Jonathan Cameron <[email protected]>
Sent: Friday, November 12, 2021 5:15 PM
To: Sa, Nuno <[email protected]>
Cc: [email protected]
Subject: Re: [RFC PATCH 0/1] LTC2688 support

[External]

On Thu, 11 Nov 2021 12:00:42 +0100
Nuno Sá <[email protected]> wrote:

Hi Nuno,

Quoted 3 lines

The reason why this is a RFC is because I'm still waiting for proper HW to test this thing. The reason why I'm sending this already is because there's some non usual features which might require extra ABI.

Hence,

Quoted 1 line

while waiting I thought we could already speed up the process in

regards

Quoted 1 line

with the ABI.

Wise move as this is an unusual beast :)

Quoted 3 lines

I still pushed the driver but the intent here is not really to review it. Naturally, if someone already wants to give some feedback, that's

very

Quoted 4 lines

much appreciated :)

Now, there are three main interfaces depending on the channel

mode:

Quoted 6 lines

1) default (no new ABI)
2) toggle mode
3) dither mode

The channel mode will be a devicetree property as it does not really make much sense to change between modes at runtime even more

because the

Quoted 1 line

piece of HW we might want to control with a channel might be

different

Quoted 1 line

depending on the selected mode (I'm fairly sure on this between

Quoted 8 lines

toggle

Quoted 1 line

and other modes but not so sure between dither and default mode).

I agree on toggle vs dither definitely being different, but normal you could implement either as software toggle, or dither with a 0 magnitude
sine wave. So might not be worth implementing default mode at all. No harm in doing so though if there are advantages to having it.

My feeling is that we could probably have dither as the "default mode". More on this below...

Quoted 39 lines
Quoted 4 lines

toggle mode special ABI:

* Toggle operation enables fast switching of a DAC output between

two

Quoted 1 line

different DAC codes without any SPI transaction. Two codes are set

in

Quoted 1 line

input_a and input_b and then the output switches according to an

input

Quoted 4 lines

signal (input_a -> clk high; input_b -> clk low).

out_voltageY_input_register
- selects between input_a and input_b. After selecting one register,

we

Quoted 4 lines

can write the dac code in out_voltageY_raw.
out_voltageY_toggle_en
- Disable/Enable toggle mode. The reason why I think this one is important is because if we wanna change the 2 codes, we should

first

Quoted 3 lines

disable this, set the codes and only then enable the mode back... As I'm writing this, It kind of came to me that we can probably achieve this with out_voltageY_powerdown attr (maybe takes a bit

more

Quoted 1 line

time to see the outputs but...)

Hmm. These corner cases always take a bit of figuring out. What you have
here is a bit 'device specific' for my liking.

So there is precedence for ABI in this area, on the frequency devices but only
for devices we still haven't moved out of staging. For those we needed a means
to define selectable phases for PSK - where the selection was either software or,
much like here, a selection pin.

out_altvotage0_phase0 etc

Quoted 12 lines

so I guess the equivalent here would be out_voltageY_raw0
out_voltageY_raw1
and the selection would be via something like out_voltageY_symbol (0 or 1 in this case). - note this is only relevant if you have the software toggle. Any enable needed for setting
can be done as part of the write sequence for the raw0 / raw1 and should
ideally not be exposed to userspace (controls that require manual sequencing
tend to be hard to use / document).

Yeah, I thought about that. I was even thinking in having something like *_amplitude for dither mode. In some cases, where we might be left in some non obvious state (eg: moved the select register to input b and then we failed to set the code;), I prefer to leave things as flexible as possible for userspace. But I agree it adds up more complexity and in this case, I can just always go to 'input_a' when writing 'raw0'...

Quoted 2 lines

However, I'm not 100% sure it really maps to this case. What do you think?

I think it can work. Though out_voltageY_symbol probably needs to be shared by type to be coherent with what we might have with TGPx. Note the sw_toggle register has a bit mask of the channels we want to toggle which means we can toggle multiple channels at the same time. It works the same with TGPx if you map multiple channels to the same pin.

There's also the question on how to handle this if a TGPx is provided? I guess it will just override the pin... But most likely having them both at the same time will lead to non desired results (unless we have a way to gate/ungate the clocks)...

Quoted 3 lines

I'm not sure if whether a channel is in toggle mode is a circuit thing or not..
(and hence DT or userspace control?)

The only reason I can think off to have it as DT is that toggle mode seems to be for more specific use cases so I guess the HW we want to control ( and connect to a toggle enabled channel) will be different.

I'm also not seeing an use case for ping ponging between the modes mostly because of the above...

Quoted 9 lines

Can see that even in a case where you did want to use external controls to
pick the values, you might also want to override from software... Given there is a software toggle I guess we can use that as override. Actually that raises the question of what the point in having normal mode is?
Can we just implement that as a software toggle toggle mode? One less thing to
worry about if we can.

I did thought about the sw_toggle thing (it's something that is only valid for channels in dither/toggle mode). My reasoning was that either

1) I did not supported it and made the TGPx selection mandatory (in case dither/toggle mode enabled) or
2) I did support it and hence the pins are not really mandatory.

I went with 1) because, honestly, I'm not seeing the point of having these modes and use sw toggle (at least on a production system). However, if we want to get rid of the default mode and have it as the dither mode, I agree we need sw_toggle because If someone just wants to use the channel without any dithering, we can't have an hard requirement to provide a external TGPx. Moreover, if the default channel will be a dither capable one, we need to provide full functionality and hence, sw_toggle.

As I stated before, I'm just not sure on how to handle things if a TGPx is also provided. Maybe they should be mutual exclusive? I mean, if someone tries to toggle a channel with a mapped TGPx we return some error code?

Quoted 3 lines

There is also the question of whether selection of which toggle pin is used
should be a dt thing or a userspace control...

Well, this definitely means some HW wiring to have the external signals and I'm not sure if there's any added valuable in being able to change the external signal at runtime?

Quoted 9 lines
Quoted 8 lines

dither mode special ABI:

* Dither operation adds a small sinusoidal wave to the digital DAC
signal path. Dithering is a signal processing technique that involves the injection of ac noise to the signal path to reduce system nonlinearities.

Quoted 7 lines

This is a complex feature to describe as (if I read it correctly) we have a dither clocked from an external pin, or in theory from software. That clock
frequency must match the dither. Realistically that means it is a clock in our control or we have to match the period below to the frequency of that
clock.

Yeah, the frequency of the dither signal is fsig = fclk / N, where N can only
be: [4 8 16 32 64]. So, we kind of just have these available options for the signal frequency and fclk is something we can control and know (assuming we have TGPx mapping which I'm bundling with a clk).

The only quirk with having this with frequency rather than raw N is to handle the sw_toggle where we have no idea about fclk? We could also think of this attr as some kind of decimation...

Quoted 9 lines
Quoted 5 lines

out_voltage0_dither_en
- Same as in toggle mode.
out_voltage0_dither_period
out_voltage0_dither_phase
- Period and phase of the signal. Only some values are valid so

there's

Quoted 2 lines

also *_available files for these. I'm not sure if we can use the more generic IIO_CHAN_INFO_PHASE and IIO_CHAN_INFO_FREQUENCY

here as these

Quoted 8 lines
Quoted 1 line

parameters don't really apply to the channel output signal..

Possibly not helpful to do so, but you could describe the channel as an out_altvoltage channel that happens to have a significant offset (the DC
level) and phase, frequency etc as for a normal altvoltage channel. That would hide the intention here though so perhaps not a good plan even if it ensures we end up with standard ABI.

I think altvoltage might not be optimal here because the phase and frequency are really not characteristics of the output signal of the channel.

Quoted 7 lines
Quoted 4 lines

out_voltage0_input_register
- Same as in toggle mode. However in this mode the code set in the input_b register has a special meaning. It's the amplitude of the dither signal.

Don't do that - provide a direct attribute representing the value of register_b and when it is written implicitly switch to the right register. Any ABI that requires a sequence of events is hard to use.

I guess we can just use the same raw1 attr here? Even though, in dither mode this has special meaning (it is the amplitude)...

Quoted 22 lines
Quoted 6 lines

One special mention to the dac scale. In this part this is something that can be purely controlled by SW so that I'm allowing userspace to change it rather then having it in dts. The available scales are:

Quoted 7 lines

* [0 5V] -> offset 0
* [0 10V] -> offset 0
* [-5 5V] -> offset -32678
* [-10 10V] -> offset -32768
* [-15 15V] -> offset -32768

With the above, we also need to have the offset configurable and

right

Quoted 4 lines

now I'm going to some trouble to make sure the scale + offset is something valid. Honestly, I think I'm overdoing it because things can still go wrong with [0 10V] and [-5 5V] as the scales are the same here. Furthermore, there's no real arm that can be done to the HW.

Is

Quoted 1 line

just that the readings won't match with what someone might be

expecting.

Quoted 1 line

My plan is to just remove those checks and assume is up to

Quoted 9 lines

userspace to

Quoted 1 line

make it right and not have [-10 10V] scale with 0 offset for example.

So this is something we've debated a few times in the past. There is a fairly strong argument for output devices that the range is a characteristic of the circuit. At the very least it makes sense to restrict it in DT even if we allow safe forms of tweaking in the driver. For an initial driver, I'd just have it in DT.

No complaints against that and makes things way simpler to handle.

- Nuno Sá

maintainer
#10 lore raw
Quoted 117 lines · Nuno

Hi Jonathan,

Thanks for your inputs...

Quoted 42 lines

From: Jonathan Cameron <[email protected]>
Sent: Friday, November 12, 2021 5:15 PM
To: Sa, Nuno <[email protected]>
Cc: [email protected]
Subject: Re: [RFC PATCH 0/1] LTC2688 support

[External]

On Thu, 11 Nov 2021 12:00:42 +0100
Nuno Sá <[email protected]> wrote:

Hi Nuno,

Quoted 3 lines

The reason why this is a RFC is because I'm still waiting for proper HW to test this thing. The reason why I'm sending this already is because there's some non usual features which might require extra ABI.

Hence,

Quoted 1 line

while waiting I thought we could already speed up the process in

regards

Quoted 1 line

with the ABI.

Wise move as this is an unusual beast :)

Quoted 3 lines

I still pushed the driver but the intent here is not really to review it. Naturally, if someone already wants to give some feedback, that's

very

Quoted 4 lines

much appreciated :)

Now, there are three main interfaces depending on the channel

mode:

Quoted 6 lines

1) default (no new ABI)
2) toggle mode
3) dither mode

The channel mode will be a devicetree property as it does not really make much sense to change between modes at runtime even more

because the

Quoted 1 line

piece of HW we might want to control with a channel might be

different

Quoted 1 line

depending on the selected mode (I'm fairly sure on this between

Quoted 8 lines

toggle

Quoted 1 line

and other modes but not so sure between dither and default mode).

I agree on toggle vs dither definitely being different, but normal you could implement either as software toggle, or dither with a 0 magnitude
sine wave. So might not be worth implementing default mode at all. No harm in doing so though if there are advantages to having it.

My feeling is that we could probably have dither as the "default mode". More on this below...

Quoted 39 lines
Quoted 4 lines

toggle mode special ABI:

* Toggle operation enables fast switching of a DAC output between

two

Quoted 1 line

different DAC codes without any SPI transaction. Two codes are set

in

Quoted 1 line

input_a and input_b and then the output switches according to an

input

Quoted 4 lines

signal (input_a -> clk high; input_b -> clk low).

out_voltageY_input_register
- selects between input_a and input_b. After selecting one register,

we

Quoted 4 lines

can write the dac code in out_voltageY_raw.
out_voltageY_toggle_en
- Disable/Enable toggle mode. The reason why I think this one is important is because if we wanna change the 2 codes, we should

first

Quoted 3 lines

disable this, set the codes and only then enable the mode back... As I'm writing this, It kind of came to me that we can probably achieve this with out_voltageY_powerdown attr (maybe takes a bit

more

Quoted 1 line

time to see the outputs but...)

Hmm. These corner cases always take a bit of figuring out. What you have
here is a bit 'device specific' for my liking.

So there is precedence for ABI in this area, on the frequency devices but only
for devices we still haven't moved out of staging. For those we needed a means
to define selectable phases for PSK - where the selection was either software or,
much like here, a selection pin.

out_altvotage0_phase0 etc

Quoted 12 lines

so I guess the equivalent here would be out_voltageY_raw0
out_voltageY_raw1
and the selection would be via something like out_voltageY_symbol (0 or 1 in this case). - note this is only relevant if you have the software toggle. Any enable needed for setting
can be done as part of the write sequence for the raw0 / raw1 and should
ideally not be exposed to userspace (controls that require manual sequencing
tend to be hard to use / document).

Yeah, I thought about that. I was even thinking in having something like *_amplitude for dither mode. In some cases, where we might be left in some non obvious state (eg: moved the select register to input b and then we failed to set the code;), I prefer to leave things as flexible as possible for userspace. But I agree it adds up more complexity and in this case, I can just always go to 'input_a' when writing 'raw0'...

Quoted 5 lines
Quoted 2 lines

However, I'm not 100% sure it really maps to this case. What do you think?

I think it can work. Though out_voltageY_symbol probably needs to be shared by type to be coherent with what we might have with TGPx.

That's fine.

Quoted 2 lines

Note the sw_toggle register has a bit mask of the channels we want to toggle which means we can toggle multiple channels at the same time.

Using that wired up to buffer mode might make sense. You'd provide multiple buffers and allow channels to be selected into one of them at a time. Each buffer is then tied to a different toggle (TGP0, TGP1, etc)

The same could be true for the software toggle. It'll get a bit fiddly though.

Perhaps this is an advanced feature to think about later...

Quoted 7 lines

It works the same with TGPx if you map multiple channels to the same pin.

There's also the question on how to handle this if a TGPx is provided? I guess it will just override the pin... But most likely having them both at the same time will lead to non desired results (unless we have a way to gate/ungate the clocks)...

I don't follow this bit. You mean TGPx and software toggle. As far as I can tell it's an either/or thing per channel.

Quoted 11 lines
Quoted 4 lines

I'm not sure if whether a channel is in toggle mode is a circuit thing or not..
(and hence DT or userspace control?)

The only reason I can think off to have it as DT is that toggle mode seems to be for more specific use cases so I guess the HW we want to control ( and connect to a toggle enabled channel) will be different.

I'm also not seeing an use case for ping ponging between the modes mostly because of the above...

Only use I can see is to reduce traffic if you happen to be switching between two sets of DAC outputs repeatedly. If there wasn't an LDAC pin I'd suspect this was there to enable simultaneous updates but we have that anyway. Maybe if the LDAC isn't wired this could be used to provide similar functionality? If that's the case, we could just leave it as a possible TODO if anyone wants it in future...
I think you could use the TGPx to provide controlled switching of sets of channels. Maybe that's something useful?

Quoted 26 lines
Quoted 10 lines

Can see that even in a case where you did want to use external controls to
pick the values, you might also want to override from software... Given there is a software toggle I guess we can use that as override. Actually that raises the question of what the point in having normal mode is?
Can we just implement that as a software toggle toggle mode? One less thing to
worry about if we can.

I did thought about the sw_toggle thing (it's something that is only valid for channels in dither/toggle mode). My reasoning was that either

1) I did not supported it and made the TGPx selection mandatory (in case dither/toggle mode enabled) or
2) I did support it and hence the pins are not really mandatory.

I went with 1) because, honestly, I'm not seeing the point of having these modes and use sw toggle (at least on a production system). However, if we want to get rid of the default mode and have it as the dither mode, I agree we need sw_toggle because If someone just wants to use the channel without any dithering, we can't have an hard requirement to provide a external TGPx. Moreover, if the default channel will be a dither capable one, we need to provide full functionality and hence, sw_toggle.

Quoted 3 lines

As I stated before, I'm just not sure on how to handle things if a TGPx is also provided. Maybe they should be mutual exclusive? I mean, if someone tries to toggle a channel with a mapped TGPx we return some error code?

Given the mapping of TGPx to channel is a software control I think ultimately you'd want to expose that - one way I can think of doing that is via the buffer interface.

4x buffers. One of each TGP0,1,2 and SW toggle. Enable the channels you want for a given 'buffer' and then they will switch together based on the data in the buffer. If the buffer has a series of toggling values then it's simple - if not then after each toggle the buffer would need to preload the next value. The snag there is that you'd need to know a toggle occurred and if the toggle pins are wired to somewhere other than our host I'm not sure how you would know that in general? (could wire the same TGPx signal to an interrupt on the host controller but seems unlikely).

Whether software toggle is worth bothering when we have LDAC to control simultaneous DAC updates isn't clear to me. I guess it's fewer writes if we happen to be cycling between values. Perhaps you are right and that feature is just for debug.

Quoted 8 lines
Quoted 4 lines

There is also the question of whether selection of which toggle pin is used
should be a dt thing or a userspace control...

Well, this definitely means some HW wiring to have the external signals and I'm not sure if there's any added valuable in being able to change the external signal at runtime?

Whilst I can conjecture reasons to do this, you may well be right - real usecases will know which signal groups they want to control together.

Quoted 18 lines
Quoted 10 lines
Quoted 9 lines

dither mode special ABI:

* Dither operation adds a small sinusoidal wave to the digital DAC
signal path. Dithering is a signal processing technique that involves the injection of ac noise to the signal path to reduce system nonlinearities.

Quoted 7 lines

This is a complex feature to describe as (if I read it correctly) we have a dither clocked from an external pin, or in theory from software. That clock
frequency must match the dither. Realistically that means it is a clock in our control or we have to match the period below to the frequency of that
clock.

Quoted 8 lines

Yeah, the frequency of the dither signal is fsig = fclk / N, where N can only
be: [4 8 16 32 64]. So, we kind of just have these available options for the signal frequency and fclk is something we can control and know (assuming we have TGPx mapping which I'm bundling with a clk).

The only quirk with having this with frequency rather than raw N is to handle the sw_toggle where we have no idea about fclk? We could also think of this attr as some kind of decimation...

Does seems unlikely anyone would use dither with a sw toggle. Perhaps best plan here is to not support that combination.

As to the clock, these are about controlling a sine wave frequency. I'm not sure decimation fits as a model. (figure 19)

Given you know the input clock, perhaps present this as something like out_voltage0_dither_frequency

I don't thing dithers are always this simple, so probably want to be specific its a sine wave so maybe we need
out_voltage0_dither_type 'sine'

We used to have some DDS chips in staging but looks like they all got dropped due to end of time Those had various waveforms and IIRC all we came up with was descriptive terms + frequencies and magnitudes.

Quoted 19 lines
Quoted 10 lines
Quoted 6 lines

out_voltage0_dither_en
- Same as in toggle mode.
out_voltage0_dither_period
out_voltage0_dither_phase
- Period and phase of the signal. Only some values are valid so

there's

Quoted 2 lines

also *_available files for these. I'm not sure if we can use the more generic IIO_CHAN_INFO_PHASE and IIO_CHAN_INFO_FREQUENCY

here as these

Quoted 8 lines
Quoted 1 line

parameters don't really apply to the channel output signal..

Possibly not helpful to do so, but you could describe the channel as an out_altvoltage channel that happens to have a significant offset (the DC
level) and phase, frequency etc as for a normal altvoltage channel. That would hide the intention here though so perhaps not a good plan even if it ensures we end up with standard ABI.

Quoted 2 lines

I think altvoltage might not be optimal here because the phase and frequency are really not characteristics of the output signal of the channel.

Well they kind of are if you set the magnitude high enough - but I get your point. That's not how they are intended to be used.

Quoted 11 lines
Quoted 8 lines
Quoted 5 lines

out_voltage0_input_register
- Same as in toggle mode. However in this mode the code set in the input_b register has a special meaning. It's the amplitude of the dither signal.

Don't do that - provide a direct attribute representing the value of register_b and when it is written implicitly switch to the right register. Any ABI that requires a sequence of events is hard to use.

I guess we can just use the same raw1 attr here? Even though, in dither mode this has special meaning (it is the amplitude)...

I was thinking toggle mode here. This interface doesn't work for dither. in that case there is just
out_voltage0_raw for the DC part and
out_voltage0_dither_raw for the dither amplitude. Assumption being same scaling as I don't really want to support multiple scale factors if we can avoid it.

Quoted 26 lines
Quoted 26 lines
Quoted 7 lines

One special mention to the dac scale. In this part this is something that can be purely controlled by SW so that I'm allowing userspace to change it rather then having it in dts. The available scales are:

Quoted 7 lines

* [0 5V] -> offset 0
* [0 10V] -> offset 0
* [-5 5V] -> offset -32678
* [-10 10V] -> offset -32768
* [-15 15V] -> offset -32768

With the above, we also need to have the offset configurable and

right

Quoted 4 lines

now I'm going to some trouble to make sure the scale + offset is something valid. Honestly, I think I'm overdoing it because things can still go wrong with [0 10V] and [-5 5V] as the scales are the same here. Furthermore, there's no real arm that can be done to the HW.

Is

Quoted 1 line

just that the readings won't match with what someone might be

expecting.

Quoted 1 line

My plan is to just remove those checks and assume is up to

userspace to

Quoted 1 line

make it right and not have [-10 10V] scale with 0 offset for example.

Quoted 8 lines
Quoted 6 lines

So this is something we've debated a few times in the past. There is a fairly strong argument for output devices that the range is a characteristic of the circuit. At the very least it makes sense to restrict it in DT even if we allow safe forms of tweaking in the driver. For an initial driver, I'd just have it in DT.

No complaints against that and makes things way simpler to handle.

Great.

Quoted 3 lines

- Nuno Sá

So conclusions.. Hmm. Not strong ones yet, but for dither mode at least I think you want to link particular channels to a TGPx choice

out_voltage0_raw out_voltage0_raw_available ( nice to have on DACs) out_voltage0_scale
out_voltage0_dither_raw out_voltage0_dither_raw_available out_voltage0_dither_frequency out_voltage0_dither_frequency_available out_voltage0_dither_phase out_voltage0_dither_phase_available

Toggle mode is less clear to me but symbol approach plus TGPx in DT maybe works You could allow for software override to set the symbol. Interface to unset it being to write an empty string to _symbol. Maybe leave that for now.

out_voltage0_raw0
out_voltage0_raw1
out_voltage0_scale
out_voltage0_symbol

Perhaps that's enough for an initial driver and we can think more or complex corner cases after that is in place?

Jonathan

author maintainer
#11 lore raw
Quoted 183 lines

-----Original Message-----
From: Jonathan Cameron <[email protected]>
Sent: Sunday, November 21, 2021 1:18 PM
To: Sa, Nuno <[email protected]>
Cc: [email protected]
Subject: Re: [RFC PATCH 0/1] LTC2688 support

[External]

Quoted 18 lines · Nuno

Hi Jonathan,

Thanks for your inputs...

Quoted 14 lines

From: Jonathan Cameron <[email protected]>
Sent: Friday, November 12, 2021 5:15 PM
To: Sa, Nuno <[email protected]>
Cc: [email protected]
Subject: Re: [RFC PATCH 0/1] LTC2688 support

[External]

On Thu, 11 Nov 2021 12:00:42 +0100
Nuno Sá <[email protected]> wrote:

Hi Nuno,

Quoted 1 line

The reason why this is a RFC is because I'm still waiting for proper

HW

Quoted 1 line
Quoted 1 line
Quoted 1 line

to test this thing. The reason why I'm sending this already is

because

Quoted 10 lines
Quoted 10 lines
Quoted 1 line

there's some non usual features which might require extra ABI.

Hence,

Quoted 1 line

while waiting I thought we could already speed up the process in

regards

Quoted 1 line

with the ABI.

Wise move as this is an unusual beast :)

Quoted 2 lines

I still pushed the driver but the intent here is not really to review

it.

Quoted 1 line
Quoted 1 line
Quoted 1 line

Naturally, if someone already wants to give some feedback,

that's

Quoted 11 lines
Quoted 11 lines

very

Quoted 4 lines

much appreciated :)

Now, there are three main interfaces depending on the channel

mode:

Quoted 5 lines

1) default (no new ABI)
2) toggle mode
3) dither mode

The channel mode will be a devicetree property as it does not

really

Quoted 1 line
Quoted 1 line
Quoted 1 line

make much sense to change between modes at runtime even

more

Quoted 6 lines
Quoted 6 lines

because the

Quoted 1 line

piece of HW we might want to control with a channel might be

different

Quoted 1 line

depending on the selected mode (I'm fairly sure on this between

toggle

Quoted 1 line

and other modes but not so sure between dither and default

mode).

Quoted 2 lines
Quoted 2 lines

I agree on toggle vs dither definitely being different, but normal

you

Quoted 3 lines
Quoted 3 lines

could implement either as software toggle, or dither with a 0 magnitude
sine wave. So might not be worth implementing default mode at

all.

Quoted 3 lines
Quoted 1 line

No harm in doing so though if there are advantages to having it.

My feeling is that we could probably have dither as the "default

mode".

Quoted 6 lines

More on this below...

Quoted 4 lines
Quoted 4 lines

toggle mode special ABI:

* Toggle operation enables fast switching of a DAC output

between

Quoted 2 lines
Quoted 2 lines

two

Quoted 1 line

different DAC codes without any SPI transaction. Two codes are

set

Quoted 2 lines
Quoted 2 lines

in

Quoted 1 line

input_a and input_b and then the output switches according to

an

Quoted 5 lines
Quoted 5 lines

input

Quoted 4 lines

signal (input_a -> clk high; input_b -> clk low).

out_voltageY_input_register
- selects between input_a and input_b. After selecting one

register,

Quoted 5 lines
Quoted 5 lines

we

Quoted 4 lines

can write the dac code in out_voltageY_raw.
out_voltageY_toggle_en
- Disable/Enable toggle mode. The reason why I think this one is important is because if we wanna change the 2 codes, we

should

Quoted 2 lines
Quoted 2 lines

first

Quoted 1 line

disable this, set the codes and only then enable the mode

back...

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

As I'm writing this, It kind of came to me that we can probably achieve this with out_voltageY_powerdown attr (maybe takes a

bit

Quoted 4 lines
Quoted 4 lines

more

Quoted 1 line

time to see the outputs but...)

Hmm. These corner cases always take a bit of figuring out. What

you

Quoted 4 lines
Quoted 4 lines

have
here is a bit 'device specific' for my liking.

So there is precedence for ABI in this area, on the frequency

devices

Quoted 4 lines
Quoted 4 lines

but only
for devices we still haven't moved out of staging. For those we needed a means
to define selectable phases for PSK - where the selection was

either

Quoted 18 lines
Quoted 5 lines

software or,
much like here, a selection pin.

out_altvotage0_phase0 etc

Quoted 12 lines

so I guess the equivalent here would be out_voltageY_raw0
out_voltageY_raw1
and the selection would be via something like out_voltageY_symbol (0 or 1 in this case). - note this is only relevant if you have the software toggle. Any enable needed for setting
can be done as part of the write sequence for the raw0 / raw1 and should
ideally not be exposed to userspace (controls that require manual sequencing
tend to be hard to use / document).

Quoted 1 line

Yeah, I thought about that. I was even thinking in having something

like

Quoted 2 lines

*_amplitude for dither mode. In some cases, where we might be left in some non obvious state (eg: moved the select register to input b

and

Quoted 5 lines

then we failed to set the code;), I prefer to leave things as flexible as possible for userspace. But I agree it adds up more complexity and in this case, I can just always go to 'input_a' when writing 'raw0'...

Quoted 1 line

However, I'm not 100% sure it really maps to this case. What do

you

Quoted 3 lines
Quoted 1 line

think?

I think it can work. Though out_voltageY_symbol probably needs to

be

Quoted 1 line

shared by type to be coherent with what we might have with TGPx.

That's fine.

Quoted 1 line

Note the sw_toggle register has a bit mask of the channels we want

to

Quoted 1 line

toggle which means we can toggle multiple channels at the same

time.

Using that wired up to buffer mode might make sense. You'd provide multiple
buffers and allow channels to be selected into one of them at a time. Each
buffer is then tied to a different toggle (TGP0, TGP1, etc)

The same could be true for the software toggle. It'll get a bit fiddly though.

Perhaps this is an advanced feature to think about later...

Quoted 1 line

It works the same with TGPx if you map multiple channels to the

same

Quoted 2 lines

pin.

Quoted 8 lines
Quoted 4 lines

There's also the question on how to handle this if a TGPx is provided? I guess it will just override the pin... But most likely having them both at the same time will lead to non desired results (unless we have a way to gate/ungate the clocks)...

I don't follow this bit. You mean TGPx and software toggle. As far as I can
tell it's an either/or thing per channel.

Here I meant that if we have a TGPx pin bundled to some channel(s) we do not want to also dance with the sw_toggle bit of that channel. Ultimately, that's on the user responsibility but we could also add some guards I guess. I'm not sure if it's an either/or thing per channel... IIUC, we spoke about making dither and default mode the same. That might complicate things a bit as:

1) We should not force a user to specify a TGPx pin for those channels (since it can also work with dithering disabled).
2) Because of 1), we should also support sw_toggle for these channels since someone might want to enable dither mode (at runtime) and the TGPx pin was not given. Hence, we need to have a way to update the DAC using the sw_toggle.

Did I understood things wrong? One thing that comes to my mind, is to return error (eg: EPERM or ENOTSUPP) if someone tries to enable dither mode and no TGPx pin was selected for that channel? Hence, we do not need to add the sw_toggle ABI (out_voltage_symbol) for the default/dither mode. Or maybe even better, we just expose the dither ABI if a TGPx pin is given over dt (I try to explain the toggle/dither modes below; that might help you in understanding my reasoning here)?

Alternatively, we just keep the approach I have in this RFC and we keep the 3 different modes (being mode a dt property; in the current state I'm using a boolean to say a channel Is in toggle mode)... Maybe with the difference that we allow sw_toggle for toggle enabled channels.

Quoted 16 lines
Quoted 2 lines
Quoted 2 lines

I'm not sure if whether a channel is in toggle mode is a circuit thing

or

Quoted 4 lines
Quoted 2 lines

not..
(and hence DT or userspace control?)

The only reason I can think off to have it as DT is that toggle mode

seems

Quoted 1 line

to be for more specific use cases so I guess the HW we want to

control (

Quoted 3 lines

and connect to a toggle enabled channel) will be different.

I'm also not seeing an use case for ping ponging between the modes

mostly

Quoted 1 line

because of the above...

Quoted 11 lines

Only use I can see is to reduce traffic if you happen to be switching between
two sets of DAC outputs repeatedly. If there wasn't an LDAC pin I'd suspect
this was there to enable simultaneous updates but we have that anyway.
Maybe if the LDAC isn't wired this could be used to provide similar functionality? If that's the case, we could just leave it as a possible TODO if anyone wants it in future...
I think you could use the TGPx to provide controlled switching of sets of channels. Maybe that's something useful?

Hmm, I think LDAC is something else. The LDAC pin updates all 16 channels with the value of the input register (which I assume is INPUT_A) independent of them being in dither/toggle mode. Honestly, I'm not even sure of how thing would work if someone plays with LDAC + channels in dither/toggle mode. I think extra care would be needed...

So, TGPx pins are indeed used to control set of channels. But note that these pins (as sw_toggle) are only meaningful if the channel is in dither or toggle mode (the channel bit in the toggle/dither enable register has to be set):

* In toggle mode we have two set of input registers: INPUT_A and INPUT_B and we toggle between these two values. If we wire a TGPx pin and bundle it to a toggle enabled channel, when the input signal is high, we output INPUT_A and INPUT_B when the signal is low. We can mimic the same behavior by writing 1/0 to the sw_toggle register.
* In dither mode, things are slightly different as INPUT_B is the value for the sinusoidal amplitude. And if we have an external signal on a TGPx pin, the dac channel is updated on the rising edge of the signal. Again, we can mimic the same behavior with the sw_toggle register.

So, for dither mode, I'm not really seeing why someone would want to use the sw_toggle. Even for toggle mode, I have my doubts but I can more easily see it.

Quoted 47 lines
Quoted 5 lines
Quoted 5 lines

Can see that even in a case where you did want to use external controls to
pick the values, you might also want to override from software... Given there is a software toggle I guess we can use that as

override.

Quoted 7 lines
Quoted 5 lines

Actually that raises the question of what the point in having normal mode is?
Can we just implement that as a software toggle toggle mode? One less thing to
worry about if we can.

I did thought about the sw_toggle thing (it's something that is only

valid

Quoted 3 lines

for channels in dither/toggle mode). My reasoning was that either

1) I did not supported it and made the TGPx selection mandatory (in

case

Quoted 4 lines

dither/toggle mode enabled) or
2) I did support it and hence the pins are not really mandatory.

I went with 1) because, honestly, I'm not seeing the point of having

these

Quoted 1 line

modes and use sw toggle (at least on a production system).

However, if we

Quoted 1 line

want to get rid of the default mode and have it as the dither mode, I

agree

Quoted 1 line

we need sw_toggle because If someone just wants to use the

channel

Quoted 1 line

without any dithering, we can't have an hard requirement to provide

a

Quoted 1 line

external TGPx. Moreover, if the default channel will be a dither

capable

Quoted 3 lines

one, we need to provide full functionality and hence, sw_toggle.

As I stated before, I'm just not sure on how to handle things if a TGPx

is

Quoted 1 line

also provided. Maybe they should be mutual exclusive? I mean, if

someone

Quoted 1 line

tries to toggle a channel with a mapped TGPx we return some error

code?

Given the mapping of TGPx to channel is a software control I think ultimately
you'd want to expose that - one way I can think of doing that is via the buffer interface.

Quoted 14 lines

4x buffers. One of each TGP0,1,2 and SW toggle. Enable the channels you
want for a given 'buffer' and then they will switch together based on the
data in the buffer. If the buffer has a series of toggling values then it's simple - if not then after each toggle the buffer would need to preload
the next value. The snag there is that you'd need to know a toggle occurred
and if the toggle pins are wired to somewhere other than our host I'm not sure
how you would know that in general? (could wire the same TGPx signal to an
interrupt on the host controller but seems unlikely).

Honestly I think that we would be probably over engineering things with this even though I get your point. OTOH, as you said, the triggering would be very hacky to handle and that might already tell us something :)

Quoted 3 lines

Whether software toggle is worth bothering when we have LDAC to control
simultaneous DAC updates isn't clear to me. I guess it's fewer writes

Hopefully I could make it clear that sw_toggle is something else than LDAC :)

Quoted 49 lines

if we happen to be cycling between values. Perhaps you are right and that
feature is just for debug.

Quoted 2 lines
Quoted 2 lines

There is also the question of whether selection of which toggle pin

is

Quoted 4 lines
Quoted 2 lines

used
should be a dt thing or a userspace control...

Well, this definitely means some HW wiring to have the external

signals and

Quoted 2 lines

I'm not sure if there's any added valuable in being able to change the external signal at runtime?

Whilst I can conjecture reasons to do this, you may well be right - real usecases will know which signal groups they want to control together.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

dither mode special ABI:

* Dither operation adds a small sinusoidal wave to the digital DAC
signal path. Dithering is a signal processing technique that

involves

Quoted 5 lines
Quoted 5 lines
Quoted 3 lines

the injection of ac noise to the signal path to reduce system nonlinearities.

This is a complex feature to describe as (if I read it correctly) we

have

Quoted 1 line
Quoted 1 line

a dither clocked from an external pin, or in theory from software.

That

Quoted 2 lines
Quoted 2 lines

clock
frequency must match the dither. Realistically that means it is a

clock

Quoted 1 line
Quoted 1 line

in our control or we have to match the period below to the

frequency

Quoted 4 lines
Quoted 2 lines

of that
clock.

Yeah, the frequency of the dither signal is fsig = fclk / N, where N can

only

Quoted 1 line

be: [4 8 16 32 64]. So, we kind of just have these available options for

the

Quoted 1 line

signal frequency and fclk is something we can control and know

(assuming

Quoted 2 lines

we have TGPx mapping which I'm bundling with a clk).

Quoted 7 lines
Quoted 2 lines

The only quirk with having this with frequency rather than raw N is to handle the sw_toggle where we have no idea about fclk? We

could also

Quoted 1 line

think of this attr as some kind of decimation...

Does seems unlikely anyone would use dither with a sw toggle. Perhaps best plan here is to not support that combination.

Agree... But there are some subtleties that we need to settle about the channel default mode as I raised in my previous comments.

Quoted 64 lines

As to the clock, these are about controlling a sine wave frequency. I'm not sure
decimation fits as a model. (figure 19)

Given you know the input clock, perhaps present this as something like out_voltage0_dither_frequency

I don't thing dithers are always this simple, so probably want to be specific its
a sine wave so maybe we need
out_voltage0_dither_type 'sine'

We used to have some DDS chips in staging but looks like they all got dropped due
to end of time Those had various waveforms and IIRC all we came up with was
descriptive terms + frequencies and magnitudes.

Quoted 8 lines
Quoted 8 lines
Quoted 6 lines

out_voltage0_dither_en
- Same as in toggle mode.
out_voltage0_dither_period
out_voltage0_dither_phase
- Period and phase of the signal. Only some values are valid so

there's

Quoted 1 line

also *_available files for these. I'm not sure if we can use the

more

Quoted 1 line
Quoted 1 line
Quoted 1 line

generic IIO_CHAN_INFO_PHASE and

IIO_CHAN_INFO_FREQUENCY

Quoted 4 lines
Quoted 4 lines

here as these

Quoted 1 line

parameters don't really apply to the channel output signal..

Possibly not helpful to do so, but you could describe the channel as

an

Quoted 1 line
Quoted 1 line

out_altvoltage channel that happens to have a significant offset

(the

Quoted 3 lines
Quoted 3 lines

DC
level) and phase, frequency etc as for a normal altvoltage channel. That would hide the intention here though so perhaps not a good

plan

Quoted 3 lines
Quoted 1 line

even if it ensures we end up with standard ABI.

I think altvoltage might not be optimal here because the phase and

frequency

Quoted 1 line

are really not characteristics of the output signal of the channel.

Well they kind of are if you set the magnitude high enough - but I get your
point. That's not how they are intended to be used.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

out_voltage0_input_register
- Same as in toggle mode. However in this mode the code set in

the

Quoted 4 lines
Quoted 4 lines
Quoted 2 lines

input_b register has a special meaning. It's the amplitude of the dither signal.

Don't do that - provide a direct attribute representing the value of register_b and when it is written implicitly switch to the right

register.

Quoted 3 lines
Quoted 1 line

Any ABI that requires a sequence of events is hard to use.

I guess we can just use the same raw1 attr here? Even though, in

dither

Quoted 8 lines
Quoted 1 line

mode this has special meaning (it is the amplitude)...

I was thinking toggle mode here. This interface doesn't work for dither. in that case there is just
out_voltage0_raw for the DC part and
out_voltage0_dither_raw for the dither amplitude. Assumption being same scaling
as I don't really want to support multiple scale factors if we can avoid it.

I'm fairly sure it is the same scaling....

Quoted 45 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

One special mention to the dac scale. In this part this is something that can be purely controlled by SW so that I'm allowing

userspace to

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

change it rather then having it in dts. The available scales are:

* [0 5V] -> offset 0
* [0 10V] -> offset 0
* [-5 5V] -> offset -32678
* [-10 10V] -> offset -32768
* [-15 15V] -> offset -32768

With the above, we also need to have the offset configurable

and

Quoted 3 lines
Quoted 3 lines

right

Quoted 2 lines

now I'm going to some trouble to make sure the scale + offset is something valid. Honestly, I think I'm overdoing it because things

can

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

still go wrong with [0 10V] and [-5 5V] as the scales are the same here. Furthermore, there's no real arm that can be done to the

HW.

Quoted 6 lines
Quoted 6 lines

Is

Quoted 1 line

just that the readings won't match with what someone might be

expecting.

Quoted 1 line

My plan is to just remove those checks and assume is up to

userspace to

Quoted 1 line

make it right and not have [-10 10V] scale with 0 offset for

example.

Quoted 3 lines
Quoted 3 lines

So this is something we've debated a few times in the past. There is a fairly strong argument for output devices that the range

is

Quoted 2 lines
Quoted 2 lines

a characteristic of the circuit. At the very least it makes sense to restrict it in DT even if we allow safe forms of tweaking in the

driver.

Quoted 4 lines
Quoted 2 lines

For an initial driver, I'd just have it in DT.

No complaints against that and makes things way simpler to handle.

Great.

Quoted 1 line
Quoted 8 lines
Quoted 2 lines

- Nuno Sá

So conclusions.. Hmm. Not strong ones yet, but for dither mode at least
I think you want to link particular channels to a TGPx choice

out_voltage0_raw out_voltage0_raw_available ( nice to have on DACs)

I guess here you mean 'IIO_AVAIL_RANGE'?

Quoted 15 lines

out_voltage0_scale
out_voltage0_dither_raw
out_voltage0_dither_raw_available
out_voltage0_dither_frequency
out_voltage0_dither_frequency_available
out_voltage0_dither_phase
out_voltage0_dither_phase_available

Toggle mode is less clear to me but symbol approach plus TGPx in DT maybe works
You could allow for software override to set the symbol. Interface to unset
it being to write an empty string to _symbol. Maybe leave that for now.

Quoted 4 lines

out_voltage0_raw0
out_voltage0_raw1
out_voltage0_scale
out_voltage0_symbol

Well, in short, I do agree with this ABI. And actually, for toggle mode, I think this is more or less what we will have. For dither/default mode, there's still the questions I raised above... Maybe, at the end, we will end up with 3 different ABI's...

I would only add this to the ABI:
* out_voltage0_dither_en
* out_voltage0_toggle_en

Because if someone wants to change, let's say the dither frequency, the best way to update things is to first disable dithering, update all the stuff, and then enable it again...

- Nuno Sá

author maintainer
#12 lore raw
Quoted 215 lines

-----Original Message-----
From: Sa, Nuno <[email protected]>
Sent: Tuesday, November 30, 2021 3:43 PM
To: Jonathan Cameron <[email protected]>
Cc: [email protected]
Subject: RE: [RFC PATCH 0/1] LTC2688 support

[External]

Quoted 7 lines

-----Original Message-----
From: Jonathan Cameron <[email protected]>
Sent: Sunday, November 21, 2021 1:18 PM
To: Sa, Nuno <[email protected]>
Cc: [email protected]
Subject: Re: [RFC PATCH 0/1] LTC2688 support

Quoted 23 lines

[External]

Quoted 18 lines · Nuno

Hi Jonathan,

Thanks for your inputs...

Quoted 14 lines

From: Jonathan Cameron <[email protected]>
Sent: Friday, November 12, 2021 5:15 PM
To: Sa, Nuno <[email protected]>
Cc: [email protected]
Subject: Re: [RFC PATCH 0/1] LTC2688 support

[External]

On Thu, 11 Nov 2021 12:00:42 +0100
Nuno Sá <[email protected]> wrote:

Hi Nuno,

Quoted 1 line

The reason why this is a RFC is because I'm still waiting for

proper

Quoted 6 lines

HW

Quoted 1 line
Quoted 1 line
Quoted 1 line

to test this thing. The reason why I'm sending this already is

because

Quoted 3 lines
Quoted 3 lines
Quoted 1 line

there's some non usual features which might require extra ABI.

Hence,

Quoted 1 line

while waiting I thought we could already speed up the process

in

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

regards

Quoted 1 line

with the ABI.

Wise move as this is an unusual beast :)

Quoted 2 lines

I still pushed the driver but the intent here is not really to

review

Quoted 8 lines

it.

Quoted 1 line
Quoted 1 line
Quoted 1 line

Naturally, if someone already wants to give some feedback,

that's

Quoted 5 lines
Quoted 5 lines

very

Quoted 4 lines

much appreciated :)

Now, there are three main interfaces depending on the

channel

Quoted 13 lines
Quoted 6 lines
Quoted 6 lines

mode:

Quoted 5 lines

1) default (no new ABI)
2) toggle mode
3) dither mode

The channel mode will be a devicetree property as it does not

really

Quoted 1 line
Quoted 1 line
Quoted 1 line

make much sense to change between modes at runtime even

more

Quoted 4 lines
Quoted 4 lines

because the

Quoted 1 line

piece of HW we might want to control with a channel might be

different

Quoted 1 line

depending on the selected mode (I'm fairly sure on this

between

Quoted 25 lines
Quoted 2 lines
Quoted 2 lines

toggle

Quoted 1 line

and other modes but not so sure between dither and default

mode).

Quoted 2 lines
Quoted 2 lines

I agree on toggle vs dither definitely being different, but normal

you

Quoted 3 lines
Quoted 3 lines

could implement either as software toggle, or dither with a 0 magnitude
sine wave. So might not be worth implementing default mode at

all.

Quoted 3 lines
Quoted 1 line

No harm in doing so though if there are advantages to having it.

My feeling is that we could probably have dither as the "default

mode".

Quoted 6 lines

More on this below...

Quoted 4 lines
Quoted 4 lines

toggle mode special ABI:

* Toggle operation enables fast switching of a DAC output

between

Quoted 2 lines
Quoted 2 lines

two

Quoted 1 line

different DAC codes without any SPI transaction. Two codes are

set

Quoted 1 line
Quoted 1 line

in

Quoted 12 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

input_a and input_b and then the output switches according to

an

Quoted 5 lines
Quoted 5 lines

input

Quoted 4 lines

signal (input_a -> clk high; input_b -> clk low).

out_voltageY_input_register
- selects between input_a and input_b. After selecting one

register,

Quoted 4 lines
Quoted 4 lines

we

Quoted 3 lines

can write the dac code in out_voltageY_raw.
out_voltageY_toggle_en
- Disable/Enable toggle mode. The reason why I think this one

is

Quoted 7 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

important is because if we wanna change the 2 codes, we

should

Quoted 2 lines
Quoted 2 lines

first

Quoted 1 line

disable this, set the codes and only then enable the mode

back...

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

As I'm writing this, It kind of came to me that we can probably achieve this with out_voltageY_powerdown attr (maybe

takes a

Quoted 9 lines

bit

Quoted 4 lines
Quoted 4 lines

more

Quoted 1 line

time to see the outputs but...)

Hmm. These corner cases always take a bit of figuring out. What

you

Quoted 3 lines
Quoted 3 lines

have
here is a bit 'device specific' for my liking.

Quoted 20 lines
Quoted 1 line
Quoted 1 line

So there is precedence for ABI in this area, on the frequency

devices

Quoted 4 lines
Quoted 4 lines

but only
for devices we still haven't moved out of staging. For those we needed a means
to define selectable phases for PSK - where the selection was

either

Quoted 13 lines
Quoted 13 lines

software or,
much like here, a selection pin.

out_altvotage0_phase0 etc

so I guess the equivalent here would be out_voltageY_raw0
out_voltageY_raw1
and the selection would be via something like out_voltageY_symbol (0 or 1 in this case). - note this is only relevant if you have the software toggle. Any enable needed for setting
can be done as part of the write sequence for the raw0 / raw1

and

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

should
ideally not be exposed to userspace (controls that require

manual

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

sequencing
tend to be hard to use / document).

Yeah, I thought about that. I was even thinking in having something

like

Quoted 1 line

*_amplitude for dither mode. In some cases, where we might be

left

Quoted 3 lines
Quoted 1 line

in some non obvious state (eg: moved the select register to input b

and

Quoted 1 line

then we failed to set the code;), I prefer to leave things as flexible

as

Quoted 1 line
Quoted 1 line

possible for userspace. But I agree it adds up more complexity and

in

Quoted 9 lines
Quoted 3 lines

this case, I can just always go to 'input_a' when writing 'raw0'...

Quoted 1 line

However, I'm not 100% sure it really maps to this case. What do

you

Quoted 3 lines
Quoted 1 line

think?

I think it can work. Though out_voltageY_symbol probably needs to

be

Quoted 1 line

shared by type to be coherent with what we might have with

TGPx.

Quoted 4 lines

That's fine.

Quoted 1 line

Note the sw_toggle register has a bit mask of the channels we

want

Quoted 5 lines

to

Quoted 1 line

toggle which means we can toggle multiple channels at the same

time.

Using that wired up to buffer mode might make sense. You'd

provide

Quoted 5 lines

multiple
buffers and allow channels to be selected into one of them at a time. Each
buffer is then tied to a different toggle (TGP0, TGP1, etc)

Quoted 10 lines

The same could be true for the software toggle. It'll get a bit fiddly though.

Perhaps this is an advanced feature to think about later...

Quoted 1 line

It works the same with TGPx if you map multiple channels to the

same

Quoted 3 lines

pin.

There's also the question on how to handle this if a TGPx is

provided?

Quoted 1 line
Quoted 1 line

I guess it will just override the pin... But most likely having them

both

Quoted 2 lines
Quoted 2 lines

at the same time will lead to non desired results (unless we have a way to gate/ungate the clocks)...

Quoted 8 lines
Quoted 4 lines

I don't follow this bit. You mean TGPx and software toggle. As far as I can
tell it's an either/or thing per channel.

Here I meant that if we have a TGPx pin bundled to some channel(s) we
do not want to also dance with the sw_toggle bit of that channel.

Just a note on this. After starting my tests with the device, I can actually say that if we have a TGPx set in the channel settings register, the device will pretty much ignore the sw_toggle settings for that channel. I could see that the output voltage was not toggling at all. As soon as I removed the TGPx setting, then dancing with the sw_toggle started to work. So, for the HW this is not really an issue as it just ignores the sw_toggle. On a SW perspective, I'm still not sure if I just ignore this and write whatever the user sets or if I return some error code in the case a user tries to toggle a channel with a binded TGPx. The first one is appealing as it makes the code much simpler while OTHO it might make sense to be verbose here otherwise the user might think something is happening when it isn't...

Anyways, I would argue that if someone has a pin wired, it's highly unlikely that he cares about sw_toggling...

- Nuno Sá

maintainer
#13 lore raw
Quoted 222 lines · Nuno
Quoted 213 lines

-----Original Message-----
From: Sa, Nuno <[email protected]>
Sent: Tuesday, November 30, 2021 3:43 PM
To: Jonathan Cameron <[email protected]>
Cc: [email protected]
Subject: RE: [RFC PATCH 0/1] LTC2688 support

[External]

Quoted 7 lines

-----Original Message-----
From: Jonathan Cameron <[email protected]>
Sent: Sunday, November 21, 2021 1:18 PM
To: Sa, Nuno <[email protected]>
Cc: [email protected]
Subject: Re: [RFC PATCH 0/1] LTC2688 support

Quoted 23 lines

[External]

Quoted 18 lines · Nuno

Hi Jonathan,

Thanks for your inputs...

Quoted 14 lines

From: Jonathan Cameron <[email protected]>
Sent: Friday, November 12, 2021 5:15 PM
To: Sa, Nuno <[email protected]>
Cc: [email protected]
Subject: Re: [RFC PATCH 0/1] LTC2688 support

[External]

On Thu, 11 Nov 2021 12:00:42 +0100
Nuno Sá <[email protected]> wrote:

Hi Nuno,

Quoted 1 line

The reason why this is a RFC is because I'm still waiting for

proper

Quoted 6 lines

HW

Quoted 1 line
Quoted 1 line
Quoted 1 line

to test this thing. The reason why I'm sending this already is

because

Quoted 3 lines
Quoted 3 lines
Quoted 1 line

there's some non usual features which might require extra ABI.

Hence,

Quoted 1 line

while waiting I thought we could already speed up the process

in

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

regards

Quoted 1 line

with the ABI.

Wise move as this is an unusual beast :)

Quoted 2 lines

I still pushed the driver but the intent here is not really to

review

Quoted 8 lines

it.

Quoted 1 line
Quoted 1 line
Quoted 1 line

Naturally, if someone already wants to give some feedback,

that's

Quoted 5 lines
Quoted 5 lines

very

Quoted 4 lines

much appreciated :)

Now, there are three main interfaces depending on the

channel

Quoted 13 lines
Quoted 6 lines
Quoted 6 lines

mode:

Quoted 5 lines

1) default (no new ABI)
2) toggle mode
3) dither mode

The channel mode will be a devicetree property as it does not

really

Quoted 1 line
Quoted 1 line
Quoted 1 line

make much sense to change between modes at runtime even

more

Quoted 4 lines
Quoted 4 lines

because the

Quoted 1 line

piece of HW we might want to control with a channel might be

different

Quoted 1 line

depending on the selected mode (I'm fairly sure on this

between

Quoted 25 lines
Quoted 2 lines
Quoted 2 lines

toggle

Quoted 1 line

and other modes but not so sure between dither and default

mode).

Quoted 2 lines
Quoted 2 lines

I agree on toggle vs dither definitely being different, but normal

you

Quoted 3 lines
Quoted 3 lines

could implement either as software toggle, or dither with a 0 magnitude
sine wave. So might not be worth implementing default mode at

all.

Quoted 3 lines
Quoted 1 line

No harm in doing so though if there are advantages to having it.

My feeling is that we could probably have dither as the "default

mode".

Quoted 6 lines

More on this below...

Quoted 4 lines
Quoted 4 lines

toggle mode special ABI:

* Toggle operation enables fast switching of a DAC output

between

Quoted 2 lines
Quoted 2 lines

two

Quoted 1 line

different DAC codes without any SPI transaction. Two codes are

set

Quoted 1 line
Quoted 1 line

in

Quoted 12 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

input_a and input_b and then the output switches according to

an

Quoted 5 lines
Quoted 5 lines

input

Quoted 4 lines

signal (input_a -> clk high; input_b -> clk low).

out_voltageY_input_register
- selects between input_a and input_b. After selecting one

register,

Quoted 4 lines
Quoted 4 lines

we

Quoted 3 lines

can write the dac code in out_voltageY_raw.
out_voltageY_toggle_en
- Disable/Enable toggle mode. The reason why I think this one

is

Quoted 7 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

important is because if we wanna change the 2 codes, we

should

Quoted 2 lines
Quoted 2 lines

first

Quoted 1 line

disable this, set the codes and only then enable the mode

back...

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

As I'm writing this, It kind of came to me that we can probably achieve this with out_voltageY_powerdown attr (maybe

takes a

Quoted 9 lines

bit

Quoted 4 lines
Quoted 4 lines

more

Quoted 1 line

time to see the outputs but...)

Hmm. These corner cases always take a bit of figuring out. What

you

Quoted 3 lines
Quoted 3 lines

have
here is a bit 'device specific' for my liking.

Quoted 20 lines
Quoted 1 line
Quoted 1 line

So there is precedence for ABI in this area, on the frequency

devices

Quoted 4 lines
Quoted 4 lines

but only
for devices we still haven't moved out of staging. For those we needed a means
to define selectable phases for PSK - where the selection was

either

Quoted 13 lines
Quoted 13 lines

software or,
much like here, a selection pin.

out_altvotage0_phase0 etc

so I guess the equivalent here would be out_voltageY_raw0
out_voltageY_raw1
and the selection would be via something like out_voltageY_symbol (0 or 1 in this case). - note this is only relevant if you have the software toggle. Any enable needed for setting
can be done as part of the write sequence for the raw0 / raw1

and

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

should
ideally not be exposed to userspace (controls that require

manual

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

sequencing
tend to be hard to use / document).

Yeah, I thought about that. I was even thinking in having something

like

Quoted 1 line

*_amplitude for dither mode. In some cases, where we might be

left

Quoted 3 lines
Quoted 1 line

in some non obvious state (eg: moved the select register to input b

and

Quoted 1 line

then we failed to set the code;), I prefer to leave things as flexible

as

Quoted 1 line
Quoted 1 line

possible for userspace. But I agree it adds up more complexity and

in

Quoted 9 lines
Quoted 3 lines

this case, I can just always go to 'input_a' when writing 'raw0'...

Quoted 1 line

However, I'm not 100% sure it really maps to this case. What do

you

Quoted 3 lines
Quoted 1 line

think?

I think it can work. Though out_voltageY_symbol probably needs to

be

Quoted 1 line

shared by type to be coherent with what we might have with

TGPx.

Quoted 4 lines

That's fine.

Quoted 1 line

Note the sw_toggle register has a bit mask of the channels we

want

Quoted 5 lines

to

Quoted 1 line

toggle which means we can toggle multiple channels at the same

time.

Using that wired up to buffer mode might make sense. You'd

provide

Quoted 5 lines

multiple
buffers and allow channels to be selected into one of them at a time. Each
buffer is then tied to a different toggle (TGP0, TGP1, etc)

Quoted 10 lines

The same could be true for the software toggle. It'll get a bit fiddly though.

Perhaps this is an advanced feature to think about later...

Quoted 1 line

It works the same with TGPx if you map multiple channels to the

same

Quoted 3 lines

pin.

There's also the question on how to handle this if a TGPx is

provided?

Quoted 1 line
Quoted 1 line

I guess it will just override the pin... But most likely having them

both

Quoted 2 lines
Quoted 2 lines

at the same time will lead to non desired results (unless we have a way to gate/ungate the clocks)...

Quoted 8 lines
Quoted 4 lines

I don't follow this bit. You mean TGPx and software toggle. As far as I can
tell it's an either/or thing per channel.

Here I meant that if we have a TGPx pin bundled to some channel(s) we
do not want to also dance with the sw_toggle bit of that channel.

Quoted 11 lines

Just a note on this. After starting my tests with the device, I can actually say that if we have a TGPx set in the channel settings register, the device will pretty much ignore the sw_toggle settings for that channel. I could see that the output voltage was not toggling at all. As soon as I removed the TGPx setting, then dancing with the sw_toggle started to work. So, for the HW this is not really an issue as it just ignores the sw_toggle. On a SW perspective, I'm still not sure if I just ignore this and write whatever the user sets or if I return some error code in the case a user tries to toggle a channel with a binded TGPx. The first one is appealing as it makes the code much simpler while OTHO it might make sense to be verbose here otherwise the user might think something is happening when it isn't...

If we are in a static configuration (see below) then just don't expose the software toggle control. Not having a big red button to press is the best way to tell userspace to not press the big red button...

Quoted 3 lines

Anyways, I would argue that if someone has a pin wired, it's highly unlikely that he cares about sw_toggling...

I'd agree if there was one to one mapping from TGPx to channel. Given it's highly configurable, they 'might' want to set the mapping differently at runtime. I'm fine if we don't support that option until someone asks though.

Jonathan

Quoted 3 lines

- Nuno Sá

author maintainer
#14 lore raw
Quoted 284 lines

From: Jonathan Cameron <[email protected]>
Sent: Sunday, December 5, 2021 7:04 PM
To: Sa, Nuno <[email protected]>
Cc: [email protected]
Subject: Re: [RFC PATCH 0/1] LTC2688 support

[External]

Quoted 38 lines · Nuno
Quoted 38 lines

-----Original Message-----
From: Sa, Nuno <[email protected]>
Sent: Tuesday, November 30, 2021 3:43 PM
To: Jonathan Cameron <[email protected]>
Cc: [email protected]
Subject: RE: [RFC PATCH 0/1] LTC2688 support

[External]

Quoted 27 lines

-----Original Message-----
From: Jonathan Cameron <[email protected]>
Sent: Sunday, November 21, 2021 1:18 PM
To: Sa, Nuno <[email protected]>
Cc: [email protected]
Subject: Re: [RFC PATCH 0/1] LTC2688 support

[External]

Quoted 15 lines · Nuno

Hi Jonathan,

Thanks for your inputs...

Quoted 11 lines

From: Jonathan Cameron <[email protected]>
Sent: Friday, November 12, 2021 5:15 PM
To: Sa, Nuno <[email protected]>
Cc: [email protected]
Subject: Re: [RFC PATCH 0/1] LTC2688 support

[External]

On Thu, 11 Nov 2021 12:00:42 +0100
Nuno Sá <[email protected]> wrote:

Quoted 8 lines
Quoted 8 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Hi Nuno,

Quoted 1 line

The reason why this is a RFC is because I'm still waiting for

proper

Quoted 4 lines

HW

Quoted 1 line
Quoted 1 line
Quoted 1 line

to test this thing. The reason why I'm sending this already is

because

Quoted 1 line
Quoted 1 line
Quoted 1 line

there's some non usual features which might require extra

ABI.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Hence,

Quoted 1 line

while waiting I thought we could already speed up the

process

Quoted 16 lines
Quoted 16 lines

in

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

regards

Quoted 1 line

with the ABI.

Wise move as this is an unusual beast :)

Quoted 2 lines

I still pushed the driver but the intent here is not really to

review

Quoted 7 lines

it.

Quoted 1 line
Quoted 1 line
Quoted 1 line

Naturally, if someone already wants to give some feedback,

that's

Quoted 4 lines
Quoted 4 lines

very

Quoted 3 lines

much appreciated :)

Quoted 8 lines
Quoted 8 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

Now, there are three main interfaces depending on the

channel

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

mode:

Quoted 5 lines

1) default (no new ABI)
2) toggle mode
3) dither mode

The channel mode will be a devicetree property as it does

not

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

really

Quoted 1 line
Quoted 1 line
Quoted 1 line

make much sense to change between modes at runtime

even

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

more

Quoted 2 lines
Quoted 2 lines

because the

Quoted 1 line

piece of HW we might want to control with a channel might

be

Quoted 5 lines
Quoted 5 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

different

Quoted 1 line

depending on the selected mode (I'm fairly sure on this

between

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

toggle

Quoted 1 line

and other modes but not so sure between dither and

default

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

mode).

Quoted 2 lines
Quoted 2 lines

I agree on toggle vs dither definitely being different, but

normal

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

you

Quoted 3 lines
Quoted 3 lines

could implement either as software toggle, or dither with a 0 magnitude
sine wave. So might not be worth implementing default

mode at

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

all.

Quoted 1 line
Quoted 1 line

No harm in doing so though if there are advantages to having

it.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 2 lines

My feeling is that we could probably have dither as the "default

mode".

Quoted 3 lines

More on this below...

Quoted 1 line
Quoted 1 line
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

toggle mode special ABI:

* Toggle operation enables fast switching of a DAC output

between

Quoted 2 lines
Quoted 2 lines

two

Quoted 1 line

different DAC codes without any SPI transaction. Two codes

are

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

set

Quoted 2 lines
Quoted 2 lines

in

Quoted 1 line

input_a and input_b and then the output switches

according to

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

an

Quoted 5 lines
Quoted 5 lines

input

Quoted 4 lines

signal (input_a -> clk high; input_b -> clk low).

out_voltageY_input_register
- selects between input_a and input_b. After selecting one

register,

Quoted 4 lines
Quoted 4 lines

we

Quoted 3 lines

can write the dac code in out_voltageY_raw.
out_voltageY_toggle_en
- Disable/Enable toggle mode. The reason why I think this

one

Quoted 7 lines
Quoted 7 lines

is

Quoted 6 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

important is because if we wanna change the 2 codes, we

should

Quoted 2 lines
Quoted 2 lines

first

Quoted 1 line

disable this, set the codes and only then enable the mode

back...

Quoted 1 line
Quoted 1 line
Quoted 1 line

As I'm writing this, It kind of came to me that we can

probably

Quoted 7 lines
Quoted 7 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

achieve this with out_voltageY_powerdown attr (maybe

takes a

Quoted 5 lines

bit

Quoted 4 lines
Quoted 4 lines

more

Quoted 1 line

time to see the outputs but...)

Hmm. These corner cases always take a bit of figuring out.

What

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

you

Quoted 4 lines
Quoted 4 lines

have
here is a bit 'device specific' for my liking.

So there is precedence for ABI in this area, on the frequency

devices

Quoted 2 lines
Quoted 2 lines

but only
for devices we still haven't moved out of staging. For those

we

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 2 lines
Quoted 2 lines

needed a means
to define selectable phases for PSK - where the selection was

either

Quoted 3 lines
Quoted 3 lines

software or,
much like here, a selection pin.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

out_altvotage0_phase0 etc

so I guess the equivalent here would be out_voltageY_raw0
out_voltageY_raw1
and the selection would be via something like out_voltageY_symbol (0 or 1 in this case). - note this is only relevant if you have the software toggle. Any enable needed

for

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

setting
can be done as part of the write sequence for the raw0 /

raw1

Quoted 8 lines
Quoted 8 lines

and

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

should
ideally not be exposed to userspace (controls that require

manual

Quoted 4 lines
Quoted 4 lines
Quoted 2 lines

sequencing
tend to be hard to use / document).

Yeah, I thought about that. I was even thinking in having

something

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

like

Quoted 1 line

*_amplitude for dither mode. In some cases, where we might

be

Quoted 2 lines
Quoted 2 lines

left

Quoted 1 line
Quoted 1 line

in some non obvious state (eg: moved the select register to

input b

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

and

Quoted 1 line

then we failed to set the code;), I prefer to leave things as

flexible

Quoted 2 lines
Quoted 2 lines

as

Quoted 1 line
Quoted 1 line

possible for userspace. But I agree it adds up more complexity

and

Quoted 4 lines
Quoted 4 lines

in

Quoted 3 lines
Quoted 3 lines

this case, I can just always go to 'input_a' when writing 'raw0'...

Quoted 1 line

However, I'm not 100% sure it really maps to this case. What

do

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

you

Quoted 3 lines
Quoted 1 line

think?

I think it can work. Though out_voltageY_symbol probably

needs to

Quoted 10 lines
Quoted 10 lines
Quoted 2 lines

be

Quoted 1 line

shared by type to be coherent with what we might have with

TGPx.

Quoted 4 lines

That's fine.

Quoted 1 line

Note the sw_toggle register has a bit mask of the channels we

want

Quoted 2 lines

to

Quoted 1 line

toggle which means we can toggle multiple channels at the

same

Quoted 6 lines
Quoted 6 lines
Quoted 3 lines

time.

Using that wired up to buffer mode might make sense. You'd

provide

Quoted 2 lines

multiple
buffers and allow channels to be selected into one of them at a

time.

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

Each
buffer is then tied to a different toggle (TGP0, TGP1, etc)

The same could be true for the software toggle. It'll get a bit

fiddly

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

though.

Perhaps this is an advanced feature to think about later...

Quoted 1 line

It works the same with TGPx if you map multiple channels to

the

Quoted 8 lines
Quoted 8 lines
Quoted 4 lines

same

Quoted 3 lines

pin.

There's also the question on how to handle this if a TGPx is

provided?

Quoted 1 line
Quoted 1 line

I guess it will just override the pin... But most likely having them

both

Quoted 1 line
Quoted 1 line

at the same time will lead to non desired results (unless we

have a

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 1 line

way to gate/ungate the clocks)...

I don't follow this bit. You mean TGPx and software toggle. As far

as I

Quoted 5 lines
Quoted 5 lines
Quoted 3 lines

can
tell it's an either/or thing per channel.

Here I meant that if we have a TGPx pin bundled to some

channel(s)

Quoted 4 lines
Quoted 2 lines

we
do not want to also dance with the sw_toggle bit of that channel.

Just a note on this. After starting my tests with the device, I can

actually

Quoted 1 line

say that if we have a TGPx set in the channel settings register, the

device

Quoted 1 line

will pretty much ignore the sw_toggle settings for that channel. I

could

Quoted 1 line

see that the output voltage was not toggling at all. As soon as I

removed

Quoted 1 line

the TGPx setting, then dancing with the sw_toggle started to work.

So, for

Quoted 1 line

the HW this is not really an issue as it just ignores the sw_toggle. On a

SW

Quoted 1 line

perspective, I'm still not sure if I just ignore this and write whatever

the

Quoted 1 line

user sets or if I return some error code in the case a user tries to

toggle

Quoted 1 line

a channel with a binded TGPx. The first one is appealing as it makes

the

Quoted 1 line

code much simpler while OTHO it might make sense to be verbose

here

Quoted 8 lines
Quoted 1 line

otherwise the user might think something is happening when it

isn't...

If we are in a static configuration (see below) then just don't expose the
software toggle control. Not having a big red button to press is the best way to
tell userspace to not press the big red button...

Hmm, I get your point and that's valid if I have the sw_toggle as a per channel attribute. Right now, I'm doing it as shared_by_type. The reason is the sw_toggling is done by writing 1/0 in the toggle register and that register is a bitmask being the mask 16bits wide. This allows you to toggle channels at the same time in the same way you can do it if, say, you map 2,3 or more channels to the same TGPx pin.

However, I'm also not happy for having this as shared_by_type attr. One of my complains is that it makes it look like a dither capable channel will also support this (and we already agreed that sw_toggle does not make sense for dither mode; so do not expose it). For instance the output of 'iio_attr' on a dither enabled channel is:

```
root@analog:~# iio_attr -c ltc2688 voltage0
dev 'ltc2688', channel 'voltage0' (output), attr 'calibbias', value '0'
dev 'ltc2688', channel 'voltage0' (output), attr 'calibscale', value '0'
dev 'ltc2688', channel 'voltage0' (output), attr 'dither_en', value '0'
dev 'ltc2688', channel 'voltage0' (output), attr 'dither_frequency', value '32768'
dev 'ltc2688', channel 'voltage0' (output), attr 'dither_frequency_available', value '32768 16384 8192 4096 2048'
dev 'ltc2688', channel 'voltage0' (output), attr 'dither_phase', value '0'
dev 'ltc2688', channel 'voltage0' (output), attr 'dither_phase_available', value '0 90 180 270'
dev 'ltc2688', channel 'voltage0' (output), attr 'dither_raw', value '0'
dev 'ltc2688', channel 'voltage0' (output), attr 'dither_raw_available', value '[0 1 65535]'
dev 'ltc2688', channel 'voltage0' (output), attr 'offset', value '0'
dev 'ltc2688', channel 'voltage0' (output), attr 'powerdown', value '0'
dev 'ltc2688', channel 'voltage0' (output), attr 'raw', value '0'
dev 'ltc2688', channel 'voltage0' (output), attr 'raw_available', value '[0 1 65535]'
dev 'ltc2688', channel 'voltage0' (output), attr 'scale', value '0.076293945'
dev 'ltc2688', channel 'voltage0' (output), attr 'symbol', value '0'
```

So you can see that symbol attr which does not make sense to be there. And it's definitely not something wrong in the iio_attr app as the attr is shared by type.

Also, as you suggested, not having the symbol attr when it does not make sense to have it also makes a lot of sense to me and that is one more plus point to have this as a per channel thing.

Anyways, I will probably send the patch with things as I have now so you can have a felling of how it looks like. Unless you already tell me to just not have it as a shared_by_type attr (which I'm getting more and more convinced on my own; I guess I just need an extra push :D).

- Nuno Sá

#15 lore raw
Quoted 294 lines · Nuno
Quoted 284 lines

From: Jonathan Cameron <[email protected]>
Sent: Sunday, December 5, 2021 7:04 PM
To: Sa, Nuno <[email protected]>
Cc: [email protected]
Subject: Re: [RFC PATCH 0/1] LTC2688 support

[External]

Quoted 38 lines · Nuno
Quoted 38 lines

-----Original Message-----
From: Sa, Nuno <[email protected]>
Sent: Tuesday, November 30, 2021 3:43 PM
To: Jonathan Cameron <[email protected]>
Cc: [email protected]
Subject: RE: [RFC PATCH 0/1] LTC2688 support

[External]

Quoted 27 lines

-----Original Message-----
From: Jonathan Cameron <[email protected]>
Sent: Sunday, November 21, 2021 1:18 PM
To: Sa, Nuno <[email protected]>
Cc: [email protected]
Subject: Re: [RFC PATCH 0/1] LTC2688 support

[External]

Quoted 15 lines · Nuno

Hi Jonathan,

Thanks for your inputs...

Quoted 11 lines

From: Jonathan Cameron <[email protected]>
Sent: Friday, November 12, 2021 5:15 PM
To: Sa, Nuno <[email protected]>
Cc: [email protected]
Subject: Re: [RFC PATCH 0/1] LTC2688 support

[External]

On Thu, 11 Nov 2021 12:00:42 +0100
Nuno Sá <[email protected]> wrote:

Quoted 8 lines
Quoted 8 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Hi Nuno,

Quoted 1 line

The reason why this is a RFC is because I'm still waiting for

proper

Quoted 4 lines

HW

Quoted 1 line
Quoted 1 line
Quoted 1 line

to test this thing. The reason why I'm sending this already is

because

Quoted 1 line
Quoted 1 line
Quoted 1 line

there's some non usual features which might require extra

ABI.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Hence,

Quoted 1 line

while waiting I thought we could already speed up the

process

Quoted 16 lines
Quoted 16 lines

in

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

regards

Quoted 1 line

with the ABI.

Wise move as this is an unusual beast :)

Quoted 2 lines

I still pushed the driver but the intent here is not really to

review

Quoted 7 lines

it.

Quoted 1 line
Quoted 1 line
Quoted 1 line

Naturally, if someone already wants to give some feedback,

that's

Quoted 4 lines
Quoted 4 lines

very

Quoted 3 lines

much appreciated :)

Quoted 8 lines
Quoted 8 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

Now, there are three main interfaces depending on the

channel

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

mode:

Quoted 5 lines

1) default (no new ABI)
2) toggle mode
3) dither mode

The channel mode will be a devicetree property as it does

not

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

really

Quoted 1 line
Quoted 1 line
Quoted 1 line

make much sense to change between modes at runtime

even

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

more

Quoted 2 lines
Quoted 2 lines

because the

Quoted 1 line

piece of HW we might want to control with a channel might

be

Quoted 5 lines
Quoted 5 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

different

Quoted 1 line

depending on the selected mode (I'm fairly sure on this

between

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

toggle

Quoted 1 line

and other modes but not so sure between dither and

default

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

mode).

Quoted 2 lines
Quoted 2 lines

I agree on toggle vs dither definitely being different, but

normal

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

you

Quoted 3 lines
Quoted 3 lines

could implement either as software toggle, or dither with a 0 magnitude
sine wave. So might not be worth implementing default

mode at

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

all.

Quoted 1 line
Quoted 1 line

No harm in doing so though if there are advantages to having

it.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 2 lines

My feeling is that we could probably have dither as the "default

mode".

Quoted 3 lines

More on this below...

Quoted 1 line
Quoted 1 line
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

toggle mode special ABI:

* Toggle operation enables fast switching of a DAC output

between

Quoted 2 lines
Quoted 2 lines

two

Quoted 1 line

different DAC codes without any SPI transaction. Two codes

are

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

set

Quoted 2 lines
Quoted 2 lines

in

Quoted 1 line

input_a and input_b and then the output switches

according to

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

an

Quoted 5 lines
Quoted 5 lines

input

Quoted 4 lines

signal (input_a -> clk high; input_b -> clk low).

out_voltageY_input_register
- selects between input_a and input_b. After selecting one

register,

Quoted 4 lines
Quoted 4 lines

we

Quoted 3 lines

can write the dac code in out_voltageY_raw.
out_voltageY_toggle_en
- Disable/Enable toggle mode. The reason why I think this

one

Quoted 7 lines
Quoted 7 lines

is

Quoted 6 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

important is because if we wanna change the 2 codes, we

should

Quoted 2 lines
Quoted 2 lines

first

Quoted 1 line

disable this, set the codes and only then enable the mode

back...

Quoted 1 line
Quoted 1 line
Quoted 1 line

As I'm writing this, It kind of came to me that we can

probably

Quoted 7 lines
Quoted 7 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

achieve this with out_voltageY_powerdown attr (maybe

takes a

Quoted 5 lines

bit

Quoted 4 lines
Quoted 4 lines

more

Quoted 1 line

time to see the outputs but...)

Hmm. These corner cases always take a bit of figuring out.

What

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

you

Quoted 4 lines
Quoted 4 lines

have
here is a bit 'device specific' for my liking.

So there is precedence for ABI in this area, on the frequency

devices

Quoted 2 lines
Quoted 2 lines

but only
for devices we still haven't moved out of staging. For those

we

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 2 lines
Quoted 2 lines

needed a means
to define selectable phases for PSK - where the selection was

either

Quoted 3 lines
Quoted 3 lines

software or,
much like here, a selection pin.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

out_altvotage0_phase0 etc

so I guess the equivalent here would be out_voltageY_raw0
out_voltageY_raw1
and the selection would be via something like out_voltageY_symbol (0 or 1 in this case). - note this is only relevant if you have the software toggle. Any enable needed

for

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

setting
can be done as part of the write sequence for the raw0 /

raw1

Quoted 8 lines
Quoted 8 lines

and

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

should
ideally not be exposed to userspace (controls that require

manual

Quoted 4 lines
Quoted 4 lines
Quoted 2 lines

sequencing
tend to be hard to use / document).

Yeah, I thought about that. I was even thinking in having

something

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

like

Quoted 1 line

*_amplitude for dither mode. In some cases, where we might

be

Quoted 2 lines
Quoted 2 lines

left

Quoted 1 line
Quoted 1 line

in some non obvious state (eg: moved the select register to

input b

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

and

Quoted 1 line

then we failed to set the code;), I prefer to leave things as

flexible

Quoted 2 lines
Quoted 2 lines

as

Quoted 1 line
Quoted 1 line

possible for userspace. But I agree it adds up more complexity

and

Quoted 4 lines
Quoted 4 lines

in

Quoted 3 lines
Quoted 3 lines

this case, I can just always go to 'input_a' when writing 'raw0'...

Quoted 1 line

However, I'm not 100% sure it really maps to this case. What

do

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

you

Quoted 3 lines
Quoted 1 line

think?

I think it can work. Though out_voltageY_symbol probably

needs to

Quoted 10 lines
Quoted 10 lines
Quoted 2 lines

be

Quoted 1 line

shared by type to be coherent with what we might have with

TGPx.

Quoted 4 lines

That's fine.

Quoted 1 line

Note the sw_toggle register has a bit mask of the channels we

want

Quoted 2 lines

to

Quoted 1 line

toggle which means we can toggle multiple channels at the

same

Quoted 6 lines
Quoted 6 lines
Quoted 3 lines

time.

Using that wired up to buffer mode might make sense. You'd

provide

Quoted 2 lines

multiple
buffers and allow channels to be selected into one of them at a

time.

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

Each
buffer is then tied to a different toggle (TGP0, TGP1, etc)

The same could be true for the software toggle. It'll get a bit

fiddly

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

though.

Perhaps this is an advanced feature to think about later...

Quoted 1 line

It works the same with TGPx if you map multiple channels to

the

Quoted 8 lines
Quoted 8 lines
Quoted 4 lines

same

Quoted 3 lines

pin.

There's also the question on how to handle this if a TGPx is

provided?

Quoted 1 line
Quoted 1 line

I guess it will just override the pin... But most likely having them

both

Quoted 1 line
Quoted 1 line

at the same time will lead to non desired results (unless we

have a

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 1 line

way to gate/ungate the clocks)...

I don't follow this bit. You mean TGPx and software toggle. As far

as I

Quoted 5 lines
Quoted 5 lines
Quoted 3 lines

can
tell it's an either/or thing per channel.

Here I meant that if we have a TGPx pin bundled to some

channel(s)

Quoted 4 lines
Quoted 2 lines

we
do not want to also dance with the sw_toggle bit of that channel.

Just a note on this. After starting my tests with the device, I can

actually

Quoted 1 line

say that if we have a TGPx set in the channel settings register, the

device

Quoted 1 line

will pretty much ignore the sw_toggle settings for that channel. I

could

Quoted 1 line

see that the output voltage was not toggling at all. As soon as I

removed

Quoted 1 line

the TGPx setting, then dancing with the sw_toggle started to work.

So, for

Quoted 1 line

the HW this is not really an issue as it just ignores the sw_toggle. On a

SW

Quoted 1 line

perspective, I'm still not sure if I just ignore this and write whatever

the

Quoted 1 line

user sets or if I return some error code in the case a user tries to

toggle

Quoted 1 line

a channel with a binded TGPx. The first one is appealing as it makes

the

Quoted 1 line

code much simpler while OTHO it might make sense to be verbose

here

Quoted 8 lines
Quoted 1 line

otherwise the user might think something is happening when it

isn't...

If we are in a static configuration (see below) then just don't expose the
software toggle control. Not having a big red button to press is the best way to
tell userspace to not press the big red button...

Quoted 6 lines

Hmm, I get your point and that's valid if I have the sw_toggle as a per channel attribute. Right now, I'm doing it as shared_by_type. The reason is the sw_toggling is done by writing 1/0 in the toggle register and that register is a bitmask being the mask 16bits wide. This allows you to toggle channels at the same time in the same way you can do it if, say, you map 2,3 or more channels to the same TGPx pin.

Hmm. That will be tricky to support in a remotely 'general' way.

Quoted 29 lines

However, I'm also not happy for having this as shared_by_type attr. One of my complains is that it makes it look like a dither capable channel will also support this (and we already agreed that sw_toggle does not make sense for dither mode; so do not expose it). For instance the output of 'iio_attr' on a dither enabled channel is:

```
root@analog:~# iio_attr -c ltc2688 voltage0
dev 'ltc2688', channel 'voltage0' (output), attr 'calibbias', value '0'
dev 'ltc2688', channel 'voltage0' (output), attr 'calibscale', value '0'
dev 'ltc2688', channel 'voltage0' (output), attr 'dither_en', value '0'
dev 'ltc2688', channel 'voltage0' (output), attr 'dither_frequency', value '32768'
dev 'ltc2688', channel 'voltage0' (output), attr 'dither_frequency_available', value '32768 16384 8192 4096 2048'
dev 'ltc2688', channel 'voltage0' (output), attr 'dither_phase', value '0'
dev 'ltc2688', channel 'voltage0' (output), attr 'dither_phase_available', value '0 90 180 270'
dev 'ltc2688', channel 'voltage0' (output), attr 'dither_raw', value '0'
dev 'ltc2688', channel 'voltage0' (output), attr 'dither_raw_available', value '[0 1 65535]'
dev 'ltc2688', channel 'voltage0' (output), attr 'offset', value '0'
dev 'ltc2688', channel 'voltage0' (output), attr 'powerdown', value '0'
dev 'ltc2688', channel 'voltage0' (output), attr 'raw', value '0'
dev 'ltc2688', channel 'voltage0' (output), attr 'raw_available', value '[0 1 65535]'
dev 'ltc2688', channel 'voltage0' (output), attr 'scale', value '0.076293945'
dev 'ltc2688', channel 'voltage0' (output), attr 'symbol', value '0'
```

So you can see that symbol attr which does not make sense to be there. And it's definitely not something wrong in the iio_attr app as the attr is shared by type.

Quoted 8 lines

Also, as you suggested, not having the symbol attr when it does not make sense to have it also makes a lot of sense to me and that is one more plus point to have this as a per channel thing.

Anyways, I will probably send the patch with things as I have now so you can have a felling of how it looks like. Unless you already tell me to just not have it as a shared_by_type attr (which I'm getting more and more convinced on my own; I guess I just need an extra push :D).

Shared by type indeed doesn't work as it's a subset - however we would need a means to indicate what subset is used if we want to allow single write
to toggle multiple. Mind you - the moment we get to multiple channels
this should probably be using the chrdev route rather than sysfs and I'm not sure how that would map to this at all.

So for now maybe take the view that software control of this is a weird feature anyway so make it per channel?

Jonathan

Quoted 2 lines

- Nuno Sá

author maintainer
#16 lore raw
Quoted 414 lines

-----Original Message-----
From: Jonathan Cameron <[email protected]>
Sent: Monday, December 6, 2021 2:10 PM
To: Sa, Nuno <[email protected]>
Cc: Jonathan Cameron <[email protected]>; [email protected]
Subject: Re: [RFC PATCH 0/1] LTC2688 support

[External]

Quoted 44 lines · Nuno
Quoted 44 lines

From: Jonathan Cameron <[email protected]>
Sent: Sunday, December 5, 2021 7:04 PM
To: Sa, Nuno <[email protected]>
Cc: [email protected]
Subject: Re: [RFC PATCH 0/1] LTC2688 support

[External]

Quoted 33 lines · Nuno
Quoted 33 lines

-----Original Message-----
From: Sa, Nuno <[email protected]>
Sent: Tuesday, November 30, 2021 3:43 PM
To: Jonathan Cameron <[email protected]>
Cc: [email protected]
Subject: RE: [RFC PATCH 0/1] LTC2688 support

[External]

Quoted 22 lines

-----Original Message-----
From: Jonathan Cameron <[email protected]>
Sent: Sunday, November 21, 2021 1:18 PM
To: Sa, Nuno <[email protected]>
Cc: [email protected]
Subject: Re: [RFC PATCH 0/1] LTC2688 support

[External]

Quoted 10 lines · Nuno

Hi Jonathan,

Thanks for your inputs...

Quoted 6 lines

From: Jonathan Cameron <[email protected]>
Sent: Friday, November 12, 2021 5:15 PM
To: Sa, Nuno <[email protected]>
Cc: [email protected]
Subject: Re: [RFC PATCH 0/1] LTC2688 support

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

[External]

On Thu, 11 Nov 2021 12:00:42 +0100 Nuno Sá <[email protected]> wrote:

Hi Nuno,

Quoted 1 line

The reason why this is a RFC is because I'm still waiting

for

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

proper

Quoted 2 lines

HW

Quoted 1 line
Quoted 1 line
Quoted 1 line

to test this thing. The reason why I'm sending this

already is

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

because

Quoted 1 line
Quoted 1 line
Quoted 1 line

there's some non usual features which might require

extra

Quoted 4 lines
Quoted 4 lines

ABI.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Hence,

Quoted 1 line

while waiting I thought we could already speed up the

process

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

in

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

regards

Quoted 1 line

with the ABI.

Wise move as this is an unusual beast :)

Quoted 2 lines

I still pushed the driver but the intent here is not really

to

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

review

Quoted 2 lines

it.

Quoted 1 line
Quoted 1 line
Quoted 1 line

Naturally, if someone already wants to give some

feedback,

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

that's

Quoted 4 lines
Quoted 4 lines

very

Quoted 3 lines

much appreciated :)

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

Now, there are three main interfaces depending on the

channel

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

mode:

Quoted 5 lines

1) default (no new ABI)
2) toggle mode
3) dither mode

The channel mode will be a devicetree property as it

does

Quoted 7 lines
Quoted 7 lines

not

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

really

Quoted 1 line
Quoted 1 line
Quoted 1 line

make much sense to change between modes at runtime

even

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

more

Quoted 2 lines
Quoted 2 lines

because the

Quoted 1 line

piece of HW we might want to control with a channel

might

Quoted 5 lines
Quoted 5 lines

be

Quoted 4 lines
Quoted 4 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

different

Quoted 1 line

depending on the selected mode (I'm fairly sure on this

between

Quoted 1 line
Quoted 1 line
Quoted 1 line

toggle

Quoted 8 lines
Quoted 8 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

and other modes but not so sure between dither and

default

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

mode).

Quoted 2 lines
Quoted 2 lines

I agree on toggle vs dither definitely being different, but

normal

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

you

Quoted 1 line
Quoted 1 line

could implement either as software toggle, or dither with

a 0

Quoted 5 lines
Quoted 5 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

magnitude
sine wave. So might not be worth implementing default

mode at

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

all.

Quoted 1 line
Quoted 1 line

No harm in doing so though if there are advantages to

having

Quoted 3 lines
Quoted 3 lines

it.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

My feeling is that we could probably have dither as the

"default

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

mode".

Quoted 6 lines

More on this below...

Quoted 4 lines
Quoted 4 lines

toggle mode special ABI:

* Toggle operation enables fast switching of a DAC

output

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

between

Quoted 2 lines
Quoted 2 lines

two

Quoted 1 line

different DAC codes without any SPI transaction. Two

codes

Quoted 11 lines
Quoted 11 lines

are

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

set

Quoted 2 lines
Quoted 2 lines

in

Quoted 1 line

input_a and input_b and then the output switches

according to

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

an

Quoted 5 lines
Quoted 5 lines

input

Quoted 4 lines

signal (input_a -> clk high; input_b -> clk low).

out_voltageY_input_register
- selects between input_a and input_b. After selecting

one

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

register,

Quoted 4 lines
Quoted 4 lines

we

Quoted 3 lines

can write the dac code in out_voltageY_raw.
out_voltageY_toggle_en
- Disable/Enable toggle mode. The reason why I think

this

Quoted 3 lines
Quoted 3 lines

one

Quoted 2 lines
Quoted 2 lines

is

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

important is because if we wanna change the 2 codes,

we

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

should

Quoted 2 lines
Quoted 2 lines

first

Quoted 1 line

disable this, set the codes and only then enable the

mode

Quoted 4 lines
Quoted 4 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

back...

Quoted 1 line
Quoted 1 line
Quoted 1 line

As I'm writing this, It kind of came to me that we can

probably

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

achieve this with out_voltageY_powerdown attr

(maybe

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

takes a

Quoted 4 lines

bit

Quoted 3 lines
Quoted 3 lines

more

Quoted 1 line

time to see the outputs but...)

Quoted 7 lines
Quoted 7 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

Hmm. These corner cases always take a bit of figuring out.

What

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

you

Quoted 4 lines
Quoted 4 lines

have
here is a bit 'device specific' for my liking.

So there is precedence for ABI in this area, on the

frequency

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

devices

Quoted 2 lines
Quoted 2 lines

but only
for devices we still haven't moved out of staging. For

those

Quoted 3 lines
Quoted 3 lines

we

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

needed a means
to define selectable phases for PSK - where the selection

was

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

either

Quoted 10 lines
Quoted 10 lines

software or,
much like here, a selection pin.

out_altvotage0_phase0 etc

so I guess the equivalent here would be out_voltageY_raw0
out_voltageY_raw1
and the selection would be via something like out_voltageY_symbol (0 or 1 in this case). - note this is

only

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

relevant if you have the software toggle. Any enable

needed

Quoted 7 lines
Quoted 7 lines

for

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

setting
can be done as part of the write sequence for the raw0 /

raw1

Quoted 3 lines
Quoted 3 lines

and

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

should
ideally not be exposed to userspace (controls that require

Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
Quoted 5 lines

manual

Quoted 4 lines
Quoted 4 lines
Quoted 2 lines

sequencing
tend to be hard to use / document).

Yeah, I thought about that. I was even thinking in having

something

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

like

Quoted 1 line

*_amplitude for dither mode. In some cases, where we

might

Quoted 9 lines
Quoted 9 lines

be

Quoted 2 lines
Quoted 2 lines

left

Quoted 1 line
Quoted 1 line

in some non obvious state (eg: moved the select register to

input b

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

and

Quoted 1 line

then we failed to set the code;), I prefer to leave things as

flexible

Quoted 2 lines
Quoted 2 lines

as

Quoted 1 line
Quoted 1 line

possible for userspace. But I agree it adds up more

complexity

Quoted 3 lines
Quoted 3 lines

and

Quoted 2 lines
Quoted 2 lines

in

Quoted 1 line
Quoted 1 line

this case, I can just always go to 'input_a' when writing

'raw0'...

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

However, I'm not 100% sure it really maps to this case.

What

Quoted 8 lines
Quoted 8 lines

do

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

you

Quoted 3 lines
Quoted 1 line

think?

I think it can work. Though out_voltageY_symbol probably

needs to

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

be

Quoted 1 line

shared by type to be coherent with what we might have

with

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

TGPx.

Quoted 4 lines

That's fine.

Quoted 1 line

Note the sw_toggle register has a bit mask of the channels

we

Quoted 10 lines
Quoted 10 lines
Quoted 3 lines
Quoted 3 lines

want

Quoted 2 lines

to

Quoted 1 line

toggle which means we can toggle multiple channels at the

same

Quoted 6 lines
Quoted 6 lines
Quoted 3 lines

time.

Using that wired up to buffer mode might make sense. You'd

provide

Quoted 2 lines

multiple
buffers and allow channels to be selected into one of them at

a

Quoted 11 lines
Quoted 11 lines

time.

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

Each
buffer is then tied to a different toggle (TGP0, TGP1, etc)

The same could be true for the software toggle. It'll get a bit

fiddly

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

though.

Perhaps this is an advanced feature to think about later...

Quoted 1 line

It works the same with TGPx if you map multiple channels

to

Quoted 7 lines
Quoted 7 lines

the

Quoted 6 lines
Quoted 6 lines
Quoted 4 lines

same

Quoted 3 lines

pin.

There's also the question on how to handle this if a TGPx is

provided?

Quoted 1 line
Quoted 1 line

I guess it will just override the pin... But most likely having

them

Quoted 5 lines
Quoted 5 lines
Quoted 2 lines
Quoted 2 lines

both

Quoted 1 line
Quoted 1 line

at the same time will lead to non desired results (unless we

have a

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 1 line

way to gate/ungate the clocks)...

I don't follow this bit. You mean TGPx and software toggle. As

far

Quoted 9 lines
Quoted 9 lines

as I

Quoted 5 lines
Quoted 5 lines
Quoted 3 lines

can
tell it's an either/or thing per channel.

Here I meant that if we have a TGPx pin bundled to some

channel(s)

Quoted 2 lines
Quoted 2 lines

we
do not want to also dance with the sw_toggle bit of that

channel.

Quoted 10 lines
Quoted 10 lines
Quoted 2 lines

Just a note on this. After starting my tests with the device, I can

actually

Quoted 1 line

say that if we have a TGPx set in the channel settings register, the

device

Quoted 1 line

will pretty much ignore the sw_toggle settings for that channel. I

could

Quoted 1 line

see that the output voltage was not toggling at all. As soon as I

removed

Quoted 1 line

the TGPx setting, then dancing with the sw_toggle started to

work.

Quoted 2 lines
Quoted 2 lines

So, for

Quoted 1 line

the HW this is not really an issue as it just ignores the sw_toggle.

On a

Quoted 2 lines
Quoted 2 lines

SW

Quoted 1 line

perspective, I'm still not sure if I just ignore this and write

whatever

Quoted 4 lines
Quoted 4 lines

the

Quoted 1 line

user sets or if I return some error code in the case a user tries to

toggle

Quoted 1 line

a channel with a binded TGPx. The first one is appealing as it

makes

Quoted 2 lines
Quoted 2 lines

the

Quoted 1 line

code much simpler while OTHO it might make sense to be

verbose

Quoted 5 lines
Quoted 5 lines

here

Quoted 1 line

otherwise the user might think something is happening when it

isn't...

If we are in a static configuration (see below) then just don't

expose

Quoted 8 lines
Quoted 4 lines

the
software toggle control. Not having a big red button to press is the best way to
tell userspace to not press the big red button...

Hmm, I get your point and that's valid if I have the sw_toggle as a per channel attribute. Right now, I'm doing it as shared_by_type. The

reason is

Quoted 1 line

the sw_toggling is done by writing 1/0 in the toggle register and that

register

Quoted 1 line

is a bitmask being the mask 16bits wide. This allows you to toggle

channels

Quoted 1 line

at the same time in the same way you can do it if, say, you map 2,3 or

more

Quoted 1 line

channels to the same TGPx pin.

Hmm. That will be tricky to support in a remotely 'general' way.

Quoted 2 lines

However, I'm also not happy for having this as shared_by_type attr.

One of

Quoted 1 line

my complains is that it makes it look like a dither capable channel will

also

Quoted 1 line

support this (and we already agreed that sw_toggle does not make

sense

Quoted 9 lines

for dither mode; so do not expose it). For instance the output of 'iio_attr' on a dither enabled channel is:

```

root@analog:~# iio_attr -c ltc2688 voltage0
dev 'ltc2688', channel 'voltage0' (output), attr 'calibbias', value '0'
dev 'ltc2688', channel 'voltage0' (output), attr 'calibscale', value '0'
dev 'ltc2688', channel 'voltage0' (output), attr 'dither_en', value '0'
dev 'ltc2688', channel 'voltage0' (output), attr 'dither_frequency',

value '32768'

Quoted 1 line

dev 'ltc2688', channel 'voltage0' (output), attr

'dither_frequency_available', value '32768 16384 8192 4096 2048'

Quoted 2 lines

dev 'ltc2688', channel 'voltage0' (output), attr 'dither_phase', value '0' dev 'ltc2688', channel 'voltage0' (output), attr

'dither_phase_available', value '0 90 180 270'

Quoted 2 lines

dev 'ltc2688', channel 'voltage0' (output), attr 'dither_raw', value '0' dev 'ltc2688', channel 'voltage0' (output), attr 'dither_raw_available',

value '[0 1 65535]'

Quoted 4 lines

dev 'ltc2688', channel 'voltage0' (output), attr 'offset', value '0' dev 'ltc2688', channel 'voltage0' (output), attr 'powerdown', value '0' dev 'ltc2688', channel 'voltage0' (output), attr 'raw', value '0' dev 'ltc2688', channel 'voltage0' (output), attr 'raw_available', value

'[0 1 65535]'

Quoted 1 line

dev 'ltc2688', channel 'voltage0' (output), attr 'scale', value

'0.076293945'

Quoted 4 lines

dev 'ltc2688', channel 'voltage0' (output), attr 'symbol', value '0' ```

So you can see that symbol attr which does not make sense to be

there. And it's

Quoted 1 line

definitely not something wrong in the iio_attr app as the attr is

shared by type.

Quoted 2 lines

Also, as you suggested, not having the symbol attr when it does not

make sense

Quoted 1 line

to have it also makes a lot of sense to me and that is one more plus

point to have

Quoted 3 lines

this as a per channel thing.

Anyways, I will probably send the patch with things as I have now so

you can

Quoted 1 line

have a felling of how it looks like. Unless you already tell me to just

not have it

Quoted 1 line

as a shared_by_type attr (which I'm getting more and more

convinced on my own;

Quoted 1 line

I guess I just need an extra push :D).

Quoted 8 lines

Shared by type indeed doesn't work as it's a subset - however we would need
a means to indicate what subset is used if we want to allow single write
to toggle multiple. Mind you - the moment we get to multiple
channels
this should probably be using the chrdev route rather than sysfs and I'm
not sure how that would map to this at all.

If someone really wants to toggle multiple channels through SW, one route would also be to use TGPx (mapping it to multiple channels) and use some of the host GPIOs to control the pin. Not nice as we would still need to provide a dummy clock to make the driver "happy" but it would be a possible workaround. This would only fail if all TGPx are already allocated for dither channels but that's very unlikely. OTHO, if we are doing the toggle through SW maybe our timings are not that strict so toggling all the channels in a loop is not that bad...

Well, this is just wondering and playing "if" games so better to keep it simple and worry about this if such a usecase ever pops up.

Quoted 3 lines

So for now maybe take the view that software control of this is a weird feature
anyway so make it per channel?

Agreed, will make it per channel and only expose it if a TGPx mapping is not present. I was leaning in that direction anyways :).

- Nuno Sá

maintainer
#17 lore raw
In reply to Sa, Nuno

On Tue, 30 Nov 2021 14:43:25 +0000
"Sa, Nuno" <[email protected]> wrote:

Hi Nuno

Hopefully I've not lost the plot on this!

Quoted 211 lines
Quoted 181 lines

-----Original Message-----
From: Jonathan Cameron <[email protected]>
Sent: Sunday, November 21, 2021 1:18 PM
To: Sa, Nuno <[email protected]>
Cc: [email protected]
Subject: Re: [RFC PATCH 0/1] LTC2688 support

[External]

Quoted 18 lines · Nuno

Hi Jonathan,

Thanks for your inputs...

Quoted 14 lines

From: Jonathan Cameron <[email protected]>
Sent: Friday, November 12, 2021 5:15 PM
To: Sa, Nuno <[email protected]>
Cc: [email protected]
Subject: Re: [RFC PATCH 0/1] LTC2688 support

[External]

On Thu, 11 Nov 2021 12:00:42 +0100
Nuno Sá <[email protected]> wrote:

Hi Nuno,

Quoted 1 line

The reason why this is a RFC is because I'm still waiting for proper

HW

Quoted 1 line
Quoted 1 line
Quoted 1 line

to test this thing. The reason why I'm sending this already is

because

Quoted 10 lines
Quoted 10 lines
Quoted 1 line

there's some non usual features which might require extra ABI.

Hence,

Quoted 1 line

while waiting I thought we could already speed up the process in

regards

Quoted 1 line

with the ABI.

Wise move as this is an unusual beast :)

Quoted 2 lines

I still pushed the driver but the intent here is not really to review

it.

Quoted 1 line
Quoted 1 line
Quoted 1 line

Naturally, if someone already wants to give some feedback,

that's

Quoted 11 lines
Quoted 11 lines

very

Quoted 4 lines

much appreciated :)

Now, there are three main interfaces depending on the channel

mode:

Quoted 5 lines

1) default (no new ABI)
2) toggle mode
3) dither mode

The channel mode will be a devicetree property as it does not

really

Quoted 1 line
Quoted 1 line
Quoted 1 line

make much sense to change between modes at runtime even

more

Quoted 6 lines
Quoted 6 lines

because the

Quoted 1 line

piece of HW we might want to control with a channel might be

different

Quoted 1 line

depending on the selected mode (I'm fairly sure on this between

toggle

Quoted 1 line

and other modes but not so sure between dither and default

mode).

Quoted 2 lines
Quoted 2 lines

I agree on toggle vs dither definitely being different, but normal

you

Quoted 3 lines
Quoted 3 lines

could implement either as software toggle, or dither with a 0 magnitude
sine wave. So might not be worth implementing default mode at

all.

Quoted 3 lines
Quoted 1 line

No harm in doing so though if there are advantages to having it.

My feeling is that we could probably have dither as the "default

mode".

Quoted 6 lines

More on this below...

Quoted 4 lines
Quoted 4 lines

toggle mode special ABI:

* Toggle operation enables fast switching of a DAC output

between

Quoted 2 lines
Quoted 2 lines

two

Quoted 1 line

different DAC codes without any SPI transaction. Two codes are

set

Quoted 2 lines
Quoted 2 lines

in

Quoted 1 line

input_a and input_b and then the output switches according to

an

Quoted 5 lines
Quoted 5 lines

input

Quoted 4 lines

signal (input_a -> clk high; input_b -> clk low).

out_voltageY_input_register
- selects between input_a and input_b. After selecting one

register,

Quoted 5 lines
Quoted 5 lines

we

Quoted 4 lines

can write the dac code in out_voltageY_raw.
out_voltageY_toggle_en
- Disable/Enable toggle mode. The reason why I think this one is important is because if we wanna change the 2 codes, we

should

Quoted 2 lines
Quoted 2 lines

first

Quoted 1 line

disable this, set the codes and only then enable the mode

back...

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

As I'm writing this, It kind of came to me that we can probably achieve this with out_voltageY_powerdown attr (maybe takes a

bit

Quoted 4 lines
Quoted 4 lines

more

Quoted 1 line

time to see the outputs but...)

Hmm. These corner cases always take a bit of figuring out. What

you

Quoted 4 lines
Quoted 4 lines

have
here is a bit 'device specific' for my liking.

So there is precedence for ABI in this area, on the frequency

devices

Quoted 4 lines
Quoted 4 lines

but only
for devices we still haven't moved out of staging. For those we needed a means
to define selectable phases for PSK - where the selection was

either

Quoted 18 lines
Quoted 5 lines

software or,
much like here, a selection pin.

out_altvotage0_phase0 etc

Quoted 12 lines

so I guess the equivalent here would be out_voltageY_raw0
out_voltageY_raw1
and the selection would be via something like out_voltageY_symbol (0 or 1 in this case). - note this is only relevant if you have the software toggle. Any enable needed for setting
can be done as part of the write sequence for the raw0 / raw1 and should
ideally not be exposed to userspace (controls that require manual sequencing
tend to be hard to use / document).

Quoted 1 line

Yeah, I thought about that. I was even thinking in having something

like

Quoted 2 lines

*_amplitude for dither mode. In some cases, where we might be left in some non obvious state (eg: moved the select register to input b

and

Quoted 5 lines

then we failed to set the code;), I prefer to leave things as flexible as possible for userspace. But I agree it adds up more complexity and in this case, I can just always go to 'input_a' when writing 'raw0'...

Quoted 1 line

However, I'm not 100% sure it really maps to this case. What do

you

Quoted 3 lines
Quoted 1 line

think?

I think it can work. Though out_voltageY_symbol probably needs to

be

Quoted 1 line

shared by type to be coherent with what we might have with TGPx.

That's fine.

Quoted 1 line

Note the sw_toggle register has a bit mask of the channels we want

to

Quoted 1 line

toggle which means we can toggle multiple channels at the same

time.

Using that wired up to buffer mode might make sense. You'd provide multiple
buffers and allow channels to be selected into one of them at a time. Each
buffer is then tied to a different toggle (TGP0, TGP1, etc)

The same could be true for the software toggle. It'll get a bit fiddly though.

Perhaps this is an advanced feature to think about later...

Quoted 1 line

It works the same with TGPx if you map multiple channels to the

same

Quoted 2 lines

pin.

Quoted 8 lines
Quoted 4 lines

There's also the question on how to handle this if a TGPx is provided? I guess it will just override the pin... But most likely having them both at the same time will lead to non desired results (unless we have a way to gate/ungate the clocks)...

I don't follow this bit. You mean TGPx and software toggle. As far as I can
tell it's an either/or thing per channel.

Here I meant that if we have a TGPx pin bundled to some channel(s) we do not want to also dance with the sw_toggle bit of that channel. Ultimately, that's on the user responsibility but we could also add some guards I guess. I'm not sure if it's an either/or thing per channel... IIUC, we spoke about making dither and default mode the same. That might complicate things a bit as:

1) We should not force a user to specify a TGPx pin for those channels (since it can also work with dithering disabled).
2) Because of 1), we should also support sw_toggle for these channels since someone might want to enable dither mode (at runtime) and the TGPx pin was not given. Hence, we need to have a way to update the DAC using the sw_toggle.

Did I understood things wrong? One thing that comes to my mind, is to return error (eg: EPERM or ENOTSUPP) if someone tries to enable dither mode and no TGPx pin was selected for that channel? Hence, we do not need to add the sw_toggle ABI (out_voltage_symbol) for the default/dither mode. Or maybe even better, we just expose the dither ABI if a TGPx pin is given over dt (I try to explain the toggle/dither modes below; that might help you in understanding my reasoning here)?

Quoted 4 lines

Alternatively, we just keep the approach I have in this RFC and we keep the 3 different modes (being mode a dt property; in the current state I'm using a boolean to say a channel Is in toggle mode)... Maybe with the difference that we allow sw_toggle for toggle enabled channels.

The corner I'm not clear on is what we do if for example all TGPx pins are specified in DT. Is the mapping from channel to TGPx things in toggle mode always a function of the external circuit or do we want to make it runtime controllable?

I'm absolutely fine if we just make it a dt property - particularly as those TGPx pins may well not be visible to the host processor.

We probably do want to provide some options in dt for what they might be connnected to on the host. I'm guessing potentially a gpio, or a clk?

You could also wire them to a non general purpose output pin - but that would be really hard to describe in a generic fashion.

Quoted 29 lines
Quoted 17 lines
Quoted 3 lines
Quoted 3 lines

I'm not sure if whether a channel is in toggle mode is a circuit thing

or

Quoted 4 lines
Quoted 2 lines

not..
(and hence DT or userspace control?)

The only reason I can think off to have it as DT is that toggle mode

seems

Quoted 1 line

to be for more specific use cases so I guess the HW we want to

control (

Quoted 3 lines

and connect to a toggle enabled channel) will be different.

I'm also not seeing an use case for ping ponging between the modes

mostly

Quoted 1 line

because of the above...

Quoted 11 lines

Only use I can see is to reduce traffic if you happen to be switching between
two sets of DAC outputs repeatedly. If there wasn't an LDAC pin I'd suspect
this was there to enable simultaneous updates but we have that anyway.
Maybe if the LDAC isn't wired this could be used to provide similar functionality? If that's the case, we could just leave it as a possible TODO if anyone wants it in future...
I think you could use the TGPx to provide controlled switching of sets of channels. Maybe that's something useful?

Quoted 5 lines

Hmm, I think LDAC is something else. The LDAC pin updates all 16 channels with the value of the input register (which I assume is INPUT_A) independent of them being in dither/toggle mode. Honestly, I'm not even sure of how thing would work if someone plays with LDAC + channels in dither/toggle mode. I think extra care would be needed...

My guess was as that in toggle mode at least, LDAC would update the DACs to reflect the 'current' toggle registers, but I'm not totally sure.

Quoted 4 lines

So, TGPx pins are indeed used to control set of channels. But note that these pins (as sw_toggle) are only meaningful if the channel is in dither or toggle mode (the channel bit in the toggle/dither enable register has to be set):

Agreed, though note that we could ensure we always were in one of these modes if it made sense from software point of view.

Quoted 6 lines

* In toggle mode we have two set of input registers: INPUT_A and INPUT_B and we toggle between these two values. If we wire a TGPx pin and bundle it to a toggle enabled channel, when the input signal is high, we output INPUT_A and INPUT_B when the signal is low. We can mimic the same behavior by writing 1/0 to the sw_toggle register.

There are different ways you could use this facility if you assume the TGPx pins are wired to the host processor rather than something out of our control.

You could use it for double buffering for example - so update INPUT_B, then toggle, update INPUT_A then toggle etc.
Or you could assume it's for mass mode switching - so there are only two values that will ever be set and these reflect something in the external circuits. We might not even have software control / visibility of which state is active.

Quoted 7 lines

* In dither mode, things are slightly different as INPUT_B is the value for the sinusoidal amplitude. And if we have an external signal on a TGPx pin, the dac channel is updated on the rising edge of the signal. Again, we can mimic the same behavior with the sw_toggle register.

So, for dither mode, I'm not really seeing why someone would want to use the sw_toggle. Even for toggle mode, I have my doubts but I can more easily see it.

Does seem unlikely for dither mode as you'd need a huge amount of bus traffic to basically provide a bad clock signal. Toggle I can also sort of see being useful with sw_toggle - but suspect real usecase for that is the one where the host processor isn't controlling the toggle..

Quoted 63 lines
Quoted 48 lines
Quoted 6 lines
Quoted 6 lines

Can see that even in a case where you did want to use external controls to
pick the values, you might also want to override from software... Given there is a software toggle I guess we can use that as

override.

Quoted 7 lines
Quoted 5 lines

Actually that raises the question of what the point in having normal mode is?
Can we just implement that as a software toggle toggle mode? One less thing to
worry about if we can.

I did thought about the sw_toggle thing (it's something that is only

valid

Quoted 3 lines

for channels in dither/toggle mode). My reasoning was that either

1) I did not supported it and made the TGPx selection mandatory (in

case

Quoted 4 lines

dither/toggle mode enabled) or
2) I did support it and hence the pins are not really mandatory.

I went with 1) because, honestly, I'm not seeing the point of having

these

Quoted 1 line

modes and use sw toggle (at least on a production system).

However, if we

Quoted 1 line

want to get rid of the default mode and have it as the dither mode, I

agree

Quoted 1 line

we need sw_toggle because If someone just wants to use the

channel

Quoted 1 line

without any dithering, we can't have an hard requirement to provide

a

Quoted 1 line

external TGPx. Moreover, if the default channel will be a dither

capable

Quoted 3 lines

one, we need to provide full functionality and hence, sw_toggle.

As I stated before, I'm just not sure on how to handle things if a TGPx

is

Quoted 1 line

also provided. Maybe they should be mutual exclusive? I mean, if

someone

Quoted 1 line

tries to toggle a channel with a mapped TGPx we return some error

code?

Given the mapping of TGPx to channel is a software control I think ultimately
you'd want to expose that - one way I can think of doing that is via the buffer interface.

Quoted 14 lines

4x buffers. One of each TGP0,1,2 and SW toggle. Enable the channels you
want for a given 'buffer' and then they will switch together based on the
data in the buffer. If the buffer has a series of toggling values then it's simple - if not then after each toggle the buffer would need to preload
the next value. The snag there is that you'd need to know a toggle occurred
and if the toggle pins are wired to somewhere other than our host I'm not sure
how you would know that in general? (could wire the same TGPx signal to an
interrupt on the host controller but seems unlikely).

Quoted 3 lines

Honestly I think that we would be probably over engineering things with this even though I get your point. OTOH, as you said, the triggering would be very hacky to handle and that might already tell us something :)

It may well make sense to only implement a subset but it is often useful to walk through what a more sophisticated feature set might look like as then we don't accidentally rule it out.

Quoted 133 lines
Quoted 4 lines

Whether software toggle is worth bothering when we have LDAC to control
simultaneous DAC updates isn't clear to me. I guess it's fewer writes

Hopefully I could make it clear that sw_toggle is something else than LDAC :)

Quoted 49 lines

if we happen to be cycling between values. Perhaps you are right and that
feature is just for debug.

Quoted 2 lines
Quoted 2 lines

There is also the question of whether selection of which toggle pin

is

Quoted 4 lines
Quoted 2 lines

used
should be a dt thing or a userspace control...

Well, this definitely means some HW wiring to have the external

signals and

Quoted 2 lines

I'm not sure if there's any added valuable in being able to change the external signal at runtime?

Whilst I can conjecture reasons to do this, you may well be right - real usecases will know which signal groups they want to control together.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

dither mode special ABI:

* Dither operation adds a small sinusoidal wave to the digital DAC
signal path. Dithering is a signal processing technique that

involves

Quoted 5 lines
Quoted 5 lines
Quoted 3 lines

the injection of ac noise to the signal path to reduce system nonlinearities.

This is a complex feature to describe as (if I read it correctly) we

have

Quoted 1 line
Quoted 1 line

a dither clocked from an external pin, or in theory from software.

That

Quoted 2 lines
Quoted 2 lines

clock
frequency must match the dither. Realistically that means it is a

clock

Quoted 1 line
Quoted 1 line

in our control or we have to match the period below to the

frequency

Quoted 4 lines
Quoted 2 lines

of that
clock.

Yeah, the frequency of the dither signal is fsig = fclk / N, where N can

only

Quoted 1 line

be: [4 8 16 32 64]. So, we kind of just have these available options for

the

Quoted 1 line

signal frequency and fclk is something we can control and know

(assuming

Quoted 2 lines

we have TGPx mapping which I'm bundling with a clk).

Quoted 7 lines
Quoted 2 lines

The only quirk with having this with frequency rather than raw N is to handle the sw_toggle where we have no idea about fclk? We

could also

Quoted 1 line

think of this attr as some kind of decimation...

Does seems unlikely anyone would use dither with a sw toggle. Perhaps best plan here is to not support that combination.

Agree... But there are some subtleties that we need to settle about the channel default mode as I raised in my previous comments.

Quoted 66 lines

As to the clock, these are about controlling a sine wave frequency. I'm not sure
decimation fits as a model. (figure 19)

Given you know the input clock, perhaps present this as something like out_voltage0_dither_frequency

I don't thing dithers are always this simple, so probably want to be specific its
a sine wave so maybe we need
out_voltage0_dither_type 'sine'

We used to have some DDS chips in staging but looks like they all got dropped due
to end of time Those had various waveforms and IIRC all we came up with was
descriptive terms + frequencies and magnitudes.

Quoted 8 lines
Quoted 8 lines
Quoted 6 lines

out_voltage0_dither_en
- Same as in toggle mode.
out_voltage0_dither_period
out_voltage0_dither_phase
- Period and phase of the signal. Only some values are valid so

there's

Quoted 1 line

also *_available files for these. I'm not sure if we can use the

more

Quoted 1 line
Quoted 1 line
Quoted 1 line

generic IIO_CHAN_INFO_PHASE and

IIO_CHAN_INFO_FREQUENCY

Quoted 4 lines
Quoted 4 lines

here as these

Quoted 1 line

parameters don't really apply to the channel output signal..

Possibly not helpful to do so, but you could describe the channel as

an

Quoted 1 line
Quoted 1 line

out_altvoltage channel that happens to have a significant offset

(the

Quoted 3 lines
Quoted 3 lines

DC
level) and phase, frequency etc as for a normal altvoltage channel. That would hide the intention here though so perhaps not a good

plan

Quoted 3 lines
Quoted 1 line

even if it ensures we end up with standard ABI.

I think altvoltage might not be optimal here because the phase and

frequency

Quoted 1 line

are really not characteristics of the output signal of the channel.

Well they kind of are if you set the magnitude high enough - but I get your
point. That's not how they are intended to be used.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

out_voltage0_input_register
- Same as in toggle mode. However in this mode the code set in

the

Quoted 4 lines
Quoted 4 lines
Quoted 2 lines

input_b register has a special meaning. It's the amplitude of the dither signal.

Don't do that - provide a direct attribute representing the value of register_b and when it is written implicitly switch to the right

register.

Quoted 3 lines
Quoted 1 line

Any ABI that requires a sequence of events is hard to use.

I guess we can just use the same raw1 attr here? Even though, in

dither

Quoted 1 line

mode this has special meaning (it is the amplitude)...

Quoted 8 lines
Quoted 6 lines

I was thinking toggle mode here. This interface doesn't work for dither. in that case there is just
out_voltage0_raw for the DC part and
out_voltage0_dither_raw for the dither amplitude. Assumption being same scaling
as I don't really want to support multiple scale factors if we can avoid it.

I'm fairly sure it is the same scaling....

As long as it's a simple factor, just hit it with a 'small adjusting tool' until it does have the same scaling. We do that in a few similar cases IIRC as sometimes things like this dither input have lower resolution.

If it's the same scaling then you won't have to hit it at all ;)

Quoted 48 lines
Quoted 48 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

One special mention to the dac scale. In this part this is something that can be purely controlled by SW so that I'm allowing

userspace to

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

change it rather then having it in dts. The available scales are:

* [0 5V] -> offset 0
* [0 10V] -> offset 0
* [-5 5V] -> offset -32678
* [-10 10V] -> offset -32768
* [-15 15V] -> offset -32768

With the above, we also need to have the offset configurable

and

Quoted 3 lines
Quoted 3 lines

right

Quoted 2 lines

now I'm going to some trouble to make sure the scale + offset is something valid. Honestly, I think I'm overdoing it because things

can

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

still go wrong with [0 10V] and [-5 5V] as the scales are the same here. Furthermore, there's no real arm that can be done to the

HW.

Quoted 6 lines
Quoted 6 lines

Is

Quoted 1 line

just that the readings won't match with what someone might be

expecting.

Quoted 1 line

My plan is to just remove those checks and assume is up to

userspace to

Quoted 1 line

make it right and not have [-10 10V] scale with 0 offset for

example.

Quoted 3 lines
Quoted 3 lines

So this is something we've debated a few times in the past. There is a fairly strong argument for output devices that the range

is

Quoted 2 lines
Quoted 2 lines

a characteristic of the circuit. At the very least it makes sense to restrict it in DT even if we allow safe forms of tweaking in the

driver.

Quoted 4 lines
Quoted 2 lines

For an initial driver, I'd just have it in DT.

No complaints against that and makes things way simpler to handle.

Great.

Quoted 3 lines

- Nuno Sá

Quoted 8 lines
Quoted 6 lines

So conclusions.. Hmm. Not strong ones yet, but for dither mode at least
I think you want to link particular channels to a TGPx choice

out_voltage0_raw out_voltage0_raw_available ( nice to have on DACs)

I guess here you mean 'IIO_AVAIL_RANGE'?

No, I mean providing the read_avail() callback and setting BIT(IIO_INFO_RAW) in info_mask_separate_available

That's how we provide range for a channel except in some unusual corner cases and the internal interface for that is used when a DAC is being used via the consumer interface (so some other driver wants to set it's output).

Quoted 21 lines
Quoted 16 lines

out_voltage0_scale
out_voltage0_dither_raw
out_voltage0_dither_raw_available
out_voltage0_dither_frequency
out_voltage0_dither_frequency_available
out_voltage0_dither_phase
out_voltage0_dither_phase_available

Toggle mode is less clear to me but symbol approach plus TGPx in DT maybe works
You could allow for software override to set the symbol. Interface to unset
it being to write an empty string to _symbol. Maybe leave that for now.

Quoted 4 lines

out_voltage0_raw0
out_voltage0_raw1
out_voltage0_scale
out_voltage0_symbol

Quoted 4 lines

Well, in short, I do agree with this ABI. And actually, for toggle mode, I think this is more or less what we will have. For dither/default mode, there's still the questions I raised above... Maybe, at the end, we will end up with 3 different ABI's...

Certainly possible. Nice to avoid if we can, but not if it means stretching things too far.

Quoted 8 lines

I would only add this to the ABI:
* out_voltage0_dither_en
* out_voltage0_toggle_en

Because if someone wants to change, let's say the dither frequency, the best way to update things is to first disable dithering, update all the stuff, and then enable it again...

I'll go with 'maybe' for these. The use for changing things doesn't make sense to me unless we have multiple things to change at once. If it's just the frequency it would be more intuitive to have a write to that attribute do the disable, set value and enable dithering again without needing to do a dance with the interface.

I'm not sure when updating needs to be done atomically across the various variables (so would need to be done under a single disable / enable sequence.

Quoted 2 lines

- Nuno Sá

author maintainer
#18 lore raw
Quoted 9 lines

-----Original Message-----
From: Jonathan Cameron <[email protected]>
Sent: Sunday, December 5, 2021 7:01 PM
To: Sa, Nuno <[email protected]>
Cc: [email protected]
Subject: Re: [RFC PATCH 0/1] LTC2688 support

Quoted 8 lines

[External]

On Tue, 30 Nov 2021 14:43:25 +0000
"Sa, Nuno" <[email protected]> wrote:

Hi Nuno

Hopefully I've not lost the plot on this!

Not really. I had some days off so this was also set on hold from my side.

Quoted 274 lines
Quoted 22 lines
Quoted 22 lines

-----Original Message-----
From: Jonathan Cameron <[email protected]>
Sent: Sunday, November 21, 2021 1:18 PM
To: Sa, Nuno <[email protected]>
Cc: [email protected]
Subject: Re: [RFC PATCH 0/1] LTC2688 support

[External]

Quoted 10 lines · Nuno

Hi Jonathan,

Thanks for your inputs...

Quoted 6 lines

From: Jonathan Cameron <[email protected]>
Sent: Friday, November 12, 2021 5:15 PM
To: Sa, Nuno <[email protected]>
Cc: [email protected]
Subject: Re: [RFC PATCH 0/1] LTC2688 support

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

[External]

On Thu, 11 Nov 2021 12:00:42 +0100
Nuno Sá <[email protected]> wrote:

Hi Nuno,

Quoted 1 line

The reason why this is a RFC is because I'm still waiting for

proper

Quoted 4 lines
Quoted 4 lines

HW

Quoted 1 line
Quoted 1 line
Quoted 1 line

to test this thing. The reason why I'm sending this already is

because

Quoted 1 line
Quoted 1 line
Quoted 1 line

there's some non usual features which might require extra

ABI.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Hence,

Quoted 1 line

while waiting I thought we could already speed up the

process in

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

regards

Quoted 1 line

with the ABI.

Wise move as this is an unusual beast :)

Quoted 2 lines

I still pushed the driver but the intent here is not really to

review

Quoted 8 lines
Quoted 8 lines

it.

Quoted 1 line
Quoted 1 line
Quoted 1 line

Naturally, if someone already wants to give some feedback,

that's

Quoted 5 lines
Quoted 5 lines

very

Quoted 4 lines

much appreciated :)

Now, there are three main interfaces depending on the

channel

Quoted 8 lines
Quoted 8 lines
Quoted 6 lines
Quoted 6 lines

mode:

Quoted 5 lines

1) default (no new ABI)
2) toggle mode
3) dither mode

The channel mode will be a devicetree property as it does not

really

Quoted 1 line
Quoted 1 line
Quoted 1 line

make much sense to change between modes at runtime

even

Quoted 3 lines
Quoted 3 lines

more

Quoted 2 lines
Quoted 2 lines

because the

Quoted 1 line

piece of HW we might want to control with a channel might

be

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

different

Quoted 1 line

depending on the selected mode (I'm fairly sure on this

between

Quoted 9 lines
Quoted 9 lines
Quoted 2 lines
Quoted 2 lines

toggle

Quoted 1 line

and other modes but not so sure between dither and default

mode).

Quoted 2 lines
Quoted 2 lines

I agree on toggle vs dither definitely being different, but normal

you

Quoted 3 lines
Quoted 3 lines

could implement either as software toggle, or dither with a 0 magnitude
sine wave. So might not be worth implementing default mode

at

Quoted 8 lines
Quoted 8 lines

all.

Quoted 3 lines
Quoted 1 line

No harm in doing so though if there are advantages to having it.

My feeling is that we could probably have dither as the "default

mode".

Quoted 3 lines

More on this below...

Quoted 1 line
Quoted 1 line
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

toggle mode special ABI:

* Toggle operation enables fast switching of a DAC output

between

Quoted 2 lines
Quoted 2 lines

two

Quoted 1 line

different DAC codes without any SPI transaction. Two codes

are

Quoted 3 lines
Quoted 3 lines

set

Quoted 2 lines
Quoted 2 lines

in

Quoted 1 line

input_a and input_b and then the output switches according

to

Quoted 11 lines
Quoted 11 lines

an

Quoted 5 lines
Quoted 5 lines

input

Quoted 4 lines

signal (input_a -> clk high; input_b -> clk low).

out_voltageY_input_register
- selects between input_a and input_b. After selecting one

register,

Quoted 4 lines
Quoted 4 lines

we

Quoted 3 lines

can write the dac code in out_voltageY_raw.
out_voltageY_toggle_en
- Disable/Enable toggle mode. The reason why I think this

one is

Quoted 6 lines
Quoted 6 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

important is because if we wanna change the 2 codes, we

should

Quoted 2 lines
Quoted 2 lines

first

Quoted 1 line

disable this, set the codes and only then enable the mode

back...

Quoted 1 line
Quoted 1 line
Quoted 1 line

As I'm writing this, It kind of came to me that we can

probably

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

achieve this with out_voltageY_powerdown attr (maybe

takes a

Quoted 5 lines
Quoted 5 lines

bit

Quoted 4 lines
Quoted 4 lines

more

Quoted 1 line

time to see the outputs but...)

Hmm. These corner cases always take a bit of figuring out.

What

Quoted 14 lines
Quoted 14 lines

you

Quoted 4 lines
Quoted 4 lines

have
here is a bit 'device specific' for my liking.

So there is precedence for ABI in this area, on the frequency

devices

Quoted 4 lines
Quoted 4 lines

but only
for devices we still haven't moved out of staging. For those we needed a means
to define selectable phases for PSK - where the selection was

either

Quoted 3 lines
Quoted 3 lines

software or,
much like here, a selection pin.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

out_altvotage0_phase0 etc

so I guess the equivalent here would be out_voltageY_raw0
out_voltageY_raw1
and the selection would be via something like out_voltageY_symbol (0 or 1 in this case). - note this is only relevant if you have the software toggle. Any enable needed

for

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

setting
can be done as part of the write sequence for the raw0 / raw1

and

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

should
ideally not be exposed to userspace (controls that require

manual

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines

sequencing
tend to be hard to use / document).

Yeah, I thought about that. I was even thinking in having

something

Quoted 2 lines
Quoted 2 lines

like

Quoted 1 line

*_amplitude for dither mode. In some cases, where we might be

left

Quoted 1 line
Quoted 1 line
Quoted 1 line

in some non obvious state (eg: moved the select register to input

b

Quoted 2 lines
Quoted 2 lines

and

Quoted 1 line

then we failed to set the code;), I prefer to leave things as

flexible as

Quoted 1 line
Quoted 1 line
Quoted 1 line

possible for userspace. But I agree it adds up more complexity

and in

Quoted 7 lines
Quoted 7 lines
Quoted 3 lines

this case, I can just always go to 'input_a' when writing 'raw0'...

Quoted 1 line

However, I'm not 100% sure it really maps to this case. What do

you

Quoted 3 lines
Quoted 1 line

think?

I think it can work. Though out_voltageY_symbol probably needs

to

Quoted 2 lines
Quoted 2 lines

be

Quoted 1 line

shared by type to be coherent with what we might have with

TGPx.

Quoted 4 lines
Quoted 4 lines

That's fine.

Quoted 1 line

Note the sw_toggle register has a bit mask of the channels we

want

Quoted 5 lines
Quoted 5 lines

to

Quoted 1 line

toggle which means we can toggle multiple channels at the same

time.

Using that wired up to buffer mode might make sense. You'd

provide

Quoted 2 lines
Quoted 2 lines

multiple
buffers and allow channels to be selected into one of them at a

time.

Quoted 6 lines
Quoted 6 lines

Each
buffer is then tied to a different toggle (TGP0, TGP1, etc)

The same could be true for the software toggle. It'll get a bit fiddly though.

Quoted 7 lines
Quoted 7 lines

Perhaps this is an advanced feature to think about later...

Quoted 1 line

It works the same with TGPx if you map multiple channels to the

same

Quoted 3 lines

pin.

There's also the question on how to handle this if a TGPx is

provided?

Quoted 1 line
Quoted 1 line
Quoted 1 line

I guess it will just override the pin... But most likely having them

both

Quoted 1 line
Quoted 1 line
Quoted 1 line

at the same time will lead to non desired results (unless we have

a

Quoted 2 lines
Quoted 2 lines
Quoted 1 line

way to gate/ungate the clocks)...

I don't follow this bit. You mean TGPx and software toggle. As far

as I

Quoted 5 lines
Quoted 3 lines

can
tell it's an either/or thing per channel.

Here I meant that if we have a TGPx pin bundled to some channel(s)

we

Quoted 1 line

do not want to also dance with the sw_toggle bit of that channel.

Ultimately,

Quoted 1 line

that's on the user responsibility but we could also add some guards I

guess.

Quoted 1 line

I'm not sure if it's an either/or thing per channel... IIUC, we spoke

about

Quoted 1 line

making dither and default mode the same. That might complicate

things a bit

Quoted 3 lines

as:

1) We should not force a user to specify a TGPx pin for those

channels (since

Quoted 2 lines

it can also work with dithering disabled).
2) Because of 1), we should also support sw_toggle for these

channels since

Quoted 1 line

someone might want to enable dither mode (at runtime) and the

TGPx pin was

Quoted 1 line

not given. Hence, we need to have a way to update the DAC using

the sw_toggle.

Quoted 2 lines

Did I understood things wrong? One thing that comes to my mind, is

to return

Quoted 1 line

error (eg: EPERM or ENOTSUPP) if someone tries to enable dither

mode and

Quoted 1 line

no TGPx pin was selected for that channel? Hence, we do not need

to add

Quoted 1 line

the sw_toggle ABI (out_voltage_symbol) for the default/dither

mode. Or

Quoted 1 line

maybe even better, we just expose the dither ABI if a TGPx pin is

given over

Quoted 1 line

dt (I try to explain the toggle/dither modes below; that might help

you in

Quoted 3 lines

understanding my reasoning here)?

Alternatively, we just keep the approach I have in this RFC and we

keep the

Quoted 1 line

3 different modes (being mode a dt property; in the current state I'm

using

Quoted 1 line

a boolean to say a channel Is in toggle mode)... Maybe with the

difference

Quoted 1 line

that we allow sw_toggle for toggle enabled channels.

The corner I'm not clear on is what we do if for example all TGPx pins are
specified in DT. Is the mapping from channel to TGPx things in toggle mode
always a function of the external circuit or do we want to make it runtime
controllable?

Quoted 6 lines

I'm absolutely fine if we just make it a dt property - particularly as those TGPx pins may well not be visible to the host processor.

We probably do want to provide some options in dt for what they might be
connnected to on the host. I'm guessing potentially a gpio, or a clk?

For each TGPx pin (from the point you bind it to some channel), I'm actually making it mandatory to have a clock (the reasoning being, if you say some channel is controlled over TGPx [being for toggle or dither mode], you need to have some input at the pin).

I might not be doing it in the way you're thinking but you can have a look in the actual series :) ...

Quoted 51 lines

You could also wire them to a non general purpose output pin - but that
would be really hard to describe in a generic fashion.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

I'm not sure if whether a channel is in toggle mode is a circuit

thing

Quoted 11 lines
Quoted 11 lines

or

Quoted 4 lines
Quoted 2 lines

not..
(and hence DT or userspace control?)

The only reason I can think off to have it as DT is that toggle mode

seems

Quoted 1 line

to be for more specific use cases so I guess the HW we want to

control (

Quoted 3 lines

and connect to a toggle enabled channel) will be different.

I'm also not seeing an use case for ping ponging between the

modes

Quoted 15 lines
Quoted 14 lines

mostly

Quoted 1 line

because of the above...

Only use I can see is to reduce traffic if you happen to be switching between
two sets of DAC outputs repeatedly. If there wasn't an LDAC pin I'd suspect
this was there to enable simultaneous updates but we have that anyway.
Maybe if the LDAC isn't wired this could be used to provide similar functionality? If that's the case, we could just leave it as a possible TODO if anyone wants it in future...
I think you could use the TGPx to provide controlled switching of sets of channels. Maybe that's something useful?

Quoted 1 line

Hmm, I think LDAC is something else. The LDAC pin updates all 16

channels

Quoted 1 line

with the value of the input register (which I assume is INPUT_A)

independent

Quoted 1 line

of them being in dither/toggle mode. Honestly, I'm not even sure of

how

Quoted 1 line

thing would work if someone plays with LDAC + channels in

dither/toggle

Quoted 1 line

mode. I think extra care would be needed...

My guess was as that in toggle mode at least, LDAC would update the DACs to
reflect the 'current' toggle registers, but I'm not totally sure.

Quoted 2 lines

So, TGPx pins are indeed used to control set of channels. But note

that these

Quoted 8 lines
Quoted 1 line

pins (as sw_toggle) are only meaningful if the channel is in dither or

toggle

Quoted 1 line

mode (the channel bit in the toggle/dither enable register has to be

set):

Agreed, though note that we could ensure we always were in one of these modes
if it made sense from software point of view.

Probably not because I can easily see users just wanting to have channels operating in the default mode...

Quoted 37 lines
Quoted 2 lines

* In toggle mode we have two set of input registers: INPUT_A and

INPUT_B

Quoted 1 line

and we toggle between these two values. If we wire a TGPx pin and

bundle

Quoted 1 line

it to a toggle enabled channel, when the input signal is high, we

output INPUT_A

Quoted 1 line

and INPUT_B when the signal is low. We can mimic the same

behavior by writing

Quoted 1 line

1/0 to the sw_toggle register.

There are different ways you could use this facility if you assume the TGPx pins
are wired to the host processor rather than something out of our control.

You could use it for double buffering for example - so update INPUT_B, then toggle,
update INPUT_A then toggle etc.
Or you could assume it's for mass mode switching - so there are only two values
that will ever be set and these reflect something in the external circuits. We
might not even have software control / visibility of which state is active.

Quoted 1 line

* In dither mode, things are slightly different as INPUT_B is the value

for the

Quoted 1 line

sinusoidal amplitude. And if we have an external signal on a TGPx

pin, the dac

Quoted 1 line

channel is updated on the rising edge of the signal. Again, we can

mimic the same

Quoted 3 lines

behavior with the sw_toggle register.

So, for dither mode, I'm not really seeing why someone would want

to use the

Quoted 1 line

sw_toggle. Even for toggle mode, I have my doubts but I can more

Quoted 8 lines

easily see it.

Does seem unlikely for dither mode as you'd need a huge amount of bus traffic
to basically provide a bad clock signal. Toggle I can also sort of see being useful with sw_toggle - but suspect real usecase for that is the one
where the host processor isn't controlling the toggle..

Agreed (that's also my feeling)...

Quoted 260 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Can see that even in a case where you did want to use external controls to
pick the values, you might also want to override from

software...

Quoted 3 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line

Given there is a software toggle I guess we can use that as

override.

Quoted 1 line
Quoted 1 line

Actually that raises the question of what the point in having

normal

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

mode is?
Can we just implement that as a software toggle toggle mode?

One

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines

less thing to
worry about if we can.

I did thought about the sw_toggle thing (it's something that is

only

Quoted 2 lines
Quoted 2 lines

valid

Quoted 1 line

for channels in dither/toggle mode). My reasoning was that

either

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

1) I did not supported it and made the TGPx selection mandatory

(in

Quoted 5 lines
Quoted 5 lines

case

Quoted 4 lines

dither/toggle mode enabled) or
2) I did support it and hence the pins are not really mandatory.

I went with 1) because, honestly, I'm not seeing the point of

having

Quoted 4 lines
Quoted 4 lines

these

Quoted 1 line

modes and use sw toggle (at least on a production system).

However, if we

Quoted 1 line

want to get rid of the default mode and have it as the dither

mode, I

Quoted 4 lines
Quoted 4 lines

agree

Quoted 1 line

we need sw_toggle because If someone just wants to use the

channel

Quoted 1 line

without any dithering, we can't have an hard requirement to

provide

Quoted 6 lines
Quoted 6 lines

a

Quoted 1 line

external TGPx. Moreover, if the default channel will be a dither

capable

Quoted 3 lines

one, we need to provide full functionality and hence, sw_toggle.

As I stated before, I'm just not sure on how to handle things if a

TGPx

Quoted 4 lines
Quoted 4 lines

is

Quoted 1 line

also provided. Maybe they should be mutual exclusive? I mean, if

someone

Quoted 1 line

tries to toggle a channel with a mapped TGPx we return some

error

Quoted 8 lines
Quoted 8 lines

code?

Given the mapping of TGPx to channel is a software control I think ultimately
you'd want to expose that - one way I can think of doing that is via the buffer interface.

4x buffers. One of each TGP0,1,2 and SW toggle. Enable the

channels

Quoted 2 lines
Quoted 2 lines

you
want for a given 'buffer' and then they will switch together based

on

Quoted 7 lines
Quoted 7 lines

the
data in the buffer. If the buffer has a series of toggling values then it's simple - if not then after each toggle the buffer would need to preload
the next value. The snag there is that you'd need to know a toggle occurred
and if the toggle pins are wired to somewhere other than our host

I'm

Quoted 2 lines
Quoted 2 lines

not sure
how you would know that in general? (could wire the same TGPx

signal

Quoted 4 lines
Quoted 2 lines

to an
interrupt on the host controller but seems unlikely).

Honestly I think that we would be probably over engineering things

with

Quoted 1 line

this even though I get your point. OTOH, as you said, the triggering

would

Quoted 1 line

be very hacky to handle and that might already tell us something :)

It may well make sense to only implement a subset but it is often useful
to walk through what a more sophisticated feature set might look like as then we don't accidentally rule it out.

Quoted 2 lines
Quoted 2 lines

Whether software toggle is worth bothering when we have LDAC

to

Quoted 2 lines
Quoted 2 lines

control
simultaneous DAC updates isn't clear to me. I guess it's fewer

writes

Quoted 2 lines

Hopefully I could make it clear that sw_toggle is something else than

LDAC :)

Quoted 2 lines
Quoted 2 lines

if we happen to be cycling between values. Perhaps you are right

and

Quoted 5 lines
Quoted 5 lines

that
feature is just for debug.

Quoted 2 lines
Quoted 2 lines

There is also the question of whether selection of which toggle

pin

Quoted 7 lines
Quoted 7 lines

is

Quoted 4 lines
Quoted 2 lines

used
should be a dt thing or a userspace control...

Well, this definitely means some HW wiring to have the external

signals and

Quoted 1 line

I'm not sure if there's any added valuable in being able to change

the

Quoted 3 lines
Quoted 3 lines
Quoted 1 line

external signal at runtime?

Whilst I can conjecture reasons to do this, you may well be right -

real

Quoted 1 line
Quoted 1 line

usecases will know which signal groups they want to control

together.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

dither mode special ABI:

* Dither operation adds a small sinusoidal wave to the digital

DAC

Quoted 9 lines
Quoted 9 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

signal path. Dithering is a signal processing technique that

involves

Quoted 5 lines
Quoted 5 lines
Quoted 3 lines

the injection of ac noise to the signal path to reduce system nonlinearities.

This is a complex feature to describe as (if I read it correctly) we

have

Quoted 1 line
Quoted 1 line

a dither clocked from an external pin, or in theory from

software.

Quoted 10 lines
Quoted 10 lines

That

Quoted 2 lines
Quoted 2 lines

clock
frequency must match the dither. Realistically that means it is a

clock

Quoted 1 line
Quoted 1 line

in our control or we have to match the period below to the

frequency

Quoted 4 lines
Quoted 2 lines

of that
clock.

Yeah, the frequency of the dither signal is fsig = fclk / N, where N

can

Quoted 2 lines
Quoted 2 lines

only

Quoted 1 line

be: [4 8 16 32 64]. So, we kind of just have these available options

for

Quoted 6 lines
Quoted 6 lines

the

Quoted 1 line

signal frequency and fclk is something we can control and know

(assuming

Quoted 3 lines

we have TGPx mapping which I'm bundling with a clk).

The only quirk with having this with frequency rather than raw N

is

Quoted 9 lines
Quoted 6 lines
Quoted 1 line

to handle the sw_toggle where we have no idea about fclk? We

could also

Quoted 1 line

think of this attr as some kind of decimation...

Does seems unlikely anyone would use dither with a sw toggle. Perhaps best plan here is to not support that combination.

Agree... But there are some subtleties that we need to settle about the channel default mode as I raised in my previous

comments.

Quoted 2 lines
Quoted 2 lines

As to the clock, these are about controlling a sine wave frequency.

I'm

Quoted 4 lines
Quoted 4 lines

not sure
decimation fits as a model. (figure 19)

Given you know the input clock, perhaps present this as something

like

Quoted 8 lines
Quoted 8 lines

out_voltage0_dither_frequency

I don't thing dithers are always this simple, so probably want to be specific its
a sine wave so maybe we need
out_voltage0_dither_type 'sine'

We used to have some DDS chips in staging but looks like they all

got

Quoted 2 lines
Quoted 2 lines

dropped due
to end of time Those had various waveforms and IIRC all we came

up

Quoted 10 lines
Quoted 10 lines

with was
descriptive terms + frequencies and magnitudes.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

out_voltage0_dither_en
- Same as in toggle mode.
out_voltage0_dither_period out_voltage0_dither_phase
- Period and phase of the signal. Only some values are valid

so

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

there's

Quoted 1 line

also *_available files for these. I'm not sure if we can use

the

Quoted 7 lines
Quoted 7 lines

more

Quoted 1 line
Quoted 1 line
Quoted 1 line

generic IIO_CHAN_INFO_PHASE and

IIO_CHAN_INFO_FREQUENCY

Quoted 4 lines
Quoted 4 lines

here as these

Quoted 1 line

parameters don't really apply to the channel output signal..

Possibly not helpful to do so, but you could describe the

channel as

Quoted 5 lines
Quoted 5 lines

an

Quoted 1 line
Quoted 1 line

out_altvoltage channel that happens to have a significant offset

(the

Quoted 2 lines
Quoted 2 lines

DC
level) and phase, frequency etc as for a normal altvoltage

channel.

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

That would hide the intention here though so perhaps not a

good

Quoted 4 lines
Quoted 4 lines

plan

Quoted 3 lines
Quoted 1 line

even if it ensures we end up with standard ABI.

I think altvoltage might not be optimal here because the phase

and

Quoted 4 lines
Quoted 4 lines

frequency

Quoted 1 line

are really not characteristics of the output signal of the channel.

Well they kind of are if you set the magnitude high enough - but I

get

Quoted 6 lines
Quoted 6 lines

your
point. That's not how they are intended to be used.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

out_voltage0_input_register
- Same as in toggle mode. However in this mode the code set

in

Quoted 2 lines
Quoted 2 lines

the

Quoted 1 line
Quoted 1 line
Quoted 1 line

input_b register has a special meaning. It's the amplitude of

the

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 1 line

dither signal.

Don't do that - provide a direct attribute representing the value

of

Quoted 9 lines
Quoted 9 lines
Quoted 1 line
Quoted 1 line

register_b and when it is written implicitly switch to the right

register.

Quoted 3 lines
Quoted 1 line

Any ABI that requires a sequence of events is hard to use.

I guess we can just use the same raw1 attr here? Even though, in

dither

Quoted 1 line

mode this has special meaning (it is the amplitude)...

I was thinking toggle mode here. This interface doesn't work for

dither.

Quoted 3 lines
Quoted 3 lines

in that case there is just
out_voltage0_raw for the DC part and out_voltage0_dither_raw for the dither amplitude. Assumption

being

Quoted 2 lines
Quoted 2 lines

same scaling
as I don't really want to support multiple scale factors if we can

avoid it.

Quoted 1 line
Quoted 7 lines
Quoted 1 line

I'm fairly sure it is the same scaling....

As long as it's a simple factor, just hit it with a 'small adjusting tool' until it does have the same scaling. We do that in a few similar cases IIRC as sometimes things like this dither input have lower resolution.

If it's the same scaling then you won't have to hit it at all ;)

Hmm, I went to confirm this and I'm not so sure since our range here is not the full 16bits but rather 13bits (2 LSB are to be set to 0). I will have to look at this more carefully.

Quoted 65 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

One special mention to the dac scale. In this part this is

something

Quoted 10 lines
Quoted 10 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

that can be purely controlled by SW so that I'm allowing

userspace to

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

change it rather then having it in dts. The available scales are:

* [0 5V] -> offset 0
* [0 10V] -> offset 0
* [-5 5V] -> offset -32678
* [-10 10V] -> offset -32768
* [-15 15V] -> offset -32768

Quoted 4 lines
Quoted 4 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

With the above, we also need to have the offset configurable

and

Quoted 2 lines
Quoted 2 lines

right

Quoted 1 line

now I'm going to some trouble to make sure the scale + offset

is

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

something valid. Honestly, I think I'm overdoing it because

things

Quoted 2 lines
Quoted 2 lines

can

Quoted 1 line
Quoted 1 line
Quoted 1 line

still go wrong with [0 10V] and [-5 5V] as the scales are the

same

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

here. Furthermore, there's no real arm that can be done to

the

Quoted 3 lines
Quoted 3 lines

HW.

Quoted 2 lines
Quoted 2 lines

Is

Quoted 1 line

just that the readings won't match with what someone might

be

Quoted 8 lines
Quoted 8 lines
Quoted 4 lines
Quoted 4 lines

expecting.

Quoted 1 line

My plan is to just remove those checks and assume is up to

userspace to

Quoted 1 line

make it right and not have [-10 10V] scale with 0 offset for

example.

Quoted 3 lines
Quoted 3 lines

So this is something we've debated a few times in the past. There is a fairly strong argument for output devices that the

range

Quoted 8 lines
Quoted 8 lines

is

Quoted 2 lines
Quoted 2 lines

a characteristic of the circuit. At the very least it makes sense to restrict it in DT even if we allow safe forms of tweaking in the

driver.

Quoted 4 lines
Quoted 2 lines

For an initial driver, I'd just have it in DT.

No complaints against that and makes things way simpler to

handle.

Quoted 4 lines
Quoted 4 lines

Great.

Quoted 3 lines

- Nuno Sá

Quoted 8 lines
Quoted 6 lines

So conclusions.. Hmm. Not strong ones yet, but for dither mode at least
I think you want to link particular channels to a TGPx choice

out_voltage0_raw out_voltage0_raw_available ( nice to have on DACs)

I guess here you mean 'IIO_AVAIL_RANGE'?

Quoted 7 lines

No, I mean providing the read_avail() callback and setting BIT(IIO_INFO_RAW) in info_mask_separate_available

That's how we provide range for a channel except in some unusual corner cases and the internal interface for that is used when a DAC is being used via the consumer interface (so some other driver wants to set it's output).

Yeah, I know :). I was just meaning 'IIO_AVAIL_RANGE' over 'IIO_AVAIL_LIST'. I guess that was already obvious to you :).

Quoted 46 lines
Quoted 10 lines
Quoted 10 lines

out_voltage0_scale
out_voltage0_dither_raw
out_voltage0_dither_raw_available
out_voltage0_dither_frequency
out_voltage0_dither_frequency_available
out_voltage0_dither_phase
out_voltage0_dither_phase_available

Toggle mode is less clear to me but symbol approach plus TGPx in

DT

Quoted 2 lines
Quoted 2 lines

maybe works
You could allow for software override to set the symbol. Interface

to

Quoted 10 lines
Quoted 8 lines

unset
it being to write an empty string to _symbol. Maybe leave that for now.

out_voltage0_raw0
out_voltage0_raw1
out_voltage0_scale
out_voltage0_symbol

Well, in short, I do agree with this ABI. And actually, for toggle mode,

I think

Quoted 1 line

this is more or less what we will have. For dither/default mode,

there's still

Quoted 1 line

the questions I raised above... Maybe, at the end, we will end up

with 3 different

Quoted 1 line

ABI's...

Certainly possible. Nice to avoid if we can, but not if it means stretching
things too far.

Quoted 6 lines

I would only add this to the ABI:
* out_voltage0_dither_en
* out_voltage0_toggle_en

Because if someone wants to change, let's say the dither frequency,

the best way

Quoted 1 line

to update things is to first disable dithering, update all the stuff, and

then enable

Quoted 1 line

it again...

Quoted 8 lines

I'll go with 'maybe' for these. The use for changing things doesn't make sense to me
unless we have multiple things to change at once. If it's just the frequency it
would be more intuitive to have a write to that attribute do the disable, set value
and enable dithering again without needing to do a dance with the interface.

Yeah and that is something that can happen here (and probably the most likely situation). For dither mode, you disable it, then you might want to change all the parameters of your dither (amplitude, phase and frequency) and then enable it again.

For toggle mode, this means, disabling it, updating input_a and input_b and enable it again.

Anyways, I think we already have some discussion that enables me to send the first version of this and we can continue from there. If all goes well, it should be out by the end of the week.

- Nuno Sá

#19 lore raw
Quoted 296 lines · Nuno
Quoted 7 lines

-----Original Message-----
From: Jonathan Cameron <[email protected]>
Sent: Sunday, December 5, 2021 7:01 PM
To: Sa, Nuno <[email protected]>
Cc: [email protected]
Subject: Re: [RFC PATCH 0/1] LTC2688 support

Quoted 8 lines

[External]

On Tue, 30 Nov 2021 14:43:25 +0000
"Sa, Nuno" <[email protected]> wrote:

Hi Nuno

Hopefully I've not lost the plot on this!

Not really. I had some days off so this was also set on hold from my side.

Quoted 277 lines
Quoted 22 lines
Quoted 22 lines

-----Original Message-----
From: Jonathan Cameron <[email protected]>
Sent: Sunday, November 21, 2021 1:18 PM
To: Sa, Nuno <[email protected]>
Cc: [email protected]
Subject: Re: [RFC PATCH 0/1] LTC2688 support

[External]

Quoted 10 lines · Nuno

Hi Jonathan,

Thanks for your inputs...

Quoted 6 lines

From: Jonathan Cameron <[email protected]>
Sent: Friday, November 12, 2021 5:15 PM
To: Sa, Nuno <[email protected]>
Cc: [email protected]
Subject: Re: [RFC PATCH 0/1] LTC2688 support

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

[External]

On Thu, 11 Nov 2021 12:00:42 +0100
Nuno Sá <[email protected]> wrote:

Hi Nuno,

Quoted 1 line

The reason why this is a RFC is because I'm still waiting for

proper

Quoted 4 lines
Quoted 4 lines

HW

Quoted 1 line
Quoted 1 line
Quoted 1 line

to test this thing. The reason why I'm sending this already is

because

Quoted 1 line
Quoted 1 line
Quoted 1 line

there's some non usual features which might require extra

ABI.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Hence,

Quoted 1 line

while waiting I thought we could already speed up the

process in

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

regards

Quoted 1 line

with the ABI.

Wise move as this is an unusual beast :)

Quoted 2 lines

I still pushed the driver but the intent here is not really to

review

Quoted 8 lines
Quoted 8 lines

it.

Quoted 1 line
Quoted 1 line
Quoted 1 line

Naturally, if someone already wants to give some feedback,

that's

Quoted 5 lines
Quoted 5 lines

very

Quoted 4 lines

much appreciated :)

Now, there are three main interfaces depending on the

channel

Quoted 8 lines
Quoted 8 lines
Quoted 6 lines
Quoted 6 lines

mode:

Quoted 5 lines

1) default (no new ABI)
2) toggle mode
3) dither mode

The channel mode will be a devicetree property as it does not

really

Quoted 1 line
Quoted 1 line
Quoted 1 line

make much sense to change between modes at runtime

even

Quoted 3 lines
Quoted 3 lines

more

Quoted 2 lines
Quoted 2 lines

because the

Quoted 1 line

piece of HW we might want to control with a channel might

be

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

different

Quoted 1 line

depending on the selected mode (I'm fairly sure on this

between

Quoted 9 lines
Quoted 9 lines
Quoted 2 lines
Quoted 2 lines

toggle

Quoted 1 line

and other modes but not so sure between dither and default

mode).

Quoted 2 lines
Quoted 2 lines

I agree on toggle vs dither definitely being different, but normal

you

Quoted 3 lines
Quoted 3 lines

could implement either as software toggle, or dither with a 0 magnitude
sine wave. So might not be worth implementing default mode

at

Quoted 8 lines
Quoted 8 lines

all.

Quoted 3 lines
Quoted 1 line

No harm in doing so though if there are advantages to having it.

My feeling is that we could probably have dither as the "default

mode".

Quoted 3 lines

More on this below...

Quoted 1 line
Quoted 1 line
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

toggle mode special ABI:

* Toggle operation enables fast switching of a DAC output

between

Quoted 2 lines
Quoted 2 lines

two

Quoted 1 line

different DAC codes without any SPI transaction. Two codes

are

Quoted 3 lines
Quoted 3 lines

set

Quoted 2 lines
Quoted 2 lines

in

Quoted 1 line

input_a and input_b and then the output switches according

to

Quoted 11 lines
Quoted 11 lines

an

Quoted 5 lines
Quoted 5 lines

input

Quoted 4 lines

signal (input_a -> clk high; input_b -> clk low).

out_voltageY_input_register
- selects between input_a and input_b. After selecting one

register,

Quoted 4 lines
Quoted 4 lines

we

Quoted 3 lines

can write the dac code in out_voltageY_raw.
out_voltageY_toggle_en
- Disable/Enable toggle mode. The reason why I think this

one is

Quoted 6 lines
Quoted 6 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

important is because if we wanna change the 2 codes, we

should

Quoted 2 lines
Quoted 2 lines

first

Quoted 1 line

disable this, set the codes and only then enable the mode

back...

Quoted 1 line
Quoted 1 line
Quoted 1 line

As I'm writing this, It kind of came to me that we can

probably

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

achieve this with out_voltageY_powerdown attr (maybe

takes a

Quoted 5 lines
Quoted 5 lines

bit

Quoted 4 lines
Quoted 4 lines

more

Quoted 1 line

time to see the outputs but...)

Hmm. These corner cases always take a bit of figuring out.

What

Quoted 14 lines
Quoted 14 lines

you

Quoted 4 lines
Quoted 4 lines

have
here is a bit 'device specific' for my liking.

So there is precedence for ABI in this area, on the frequency

devices

Quoted 4 lines
Quoted 4 lines

but only
for devices we still haven't moved out of staging. For those we needed a means
to define selectable phases for PSK - where the selection was

either

Quoted 3 lines
Quoted 3 lines

software or,
much like here, a selection pin.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

out_altvotage0_phase0 etc

so I guess the equivalent here would be out_voltageY_raw0
out_voltageY_raw1
and the selection would be via something like out_voltageY_symbol (0 or 1 in this case). - note this is only relevant if you have the software toggle. Any enable needed

for

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

setting
can be done as part of the write sequence for the raw0 / raw1

and

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

should
ideally not be exposed to userspace (controls that require

manual

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines

sequencing
tend to be hard to use / document).

Yeah, I thought about that. I was even thinking in having

something

Quoted 2 lines
Quoted 2 lines

like

Quoted 1 line

*_amplitude for dither mode. In some cases, where we might be

left

Quoted 1 line
Quoted 1 line
Quoted 1 line

in some non obvious state (eg: moved the select register to input

b

Quoted 2 lines
Quoted 2 lines

and

Quoted 1 line

then we failed to set the code;), I prefer to leave things as

flexible as

Quoted 1 line
Quoted 1 line
Quoted 1 line

possible for userspace. But I agree it adds up more complexity

and in

Quoted 7 lines
Quoted 7 lines
Quoted 3 lines

this case, I can just always go to 'input_a' when writing 'raw0'...

Quoted 1 line

However, I'm not 100% sure it really maps to this case. What do

you

Quoted 3 lines
Quoted 1 line

think?

I think it can work. Though out_voltageY_symbol probably needs

to

Quoted 2 lines
Quoted 2 lines

be

Quoted 1 line

shared by type to be coherent with what we might have with

TGPx.

Quoted 4 lines
Quoted 4 lines

That's fine.

Quoted 1 line

Note the sw_toggle register has a bit mask of the channels we

want

Quoted 5 lines
Quoted 5 lines

to

Quoted 1 line

toggle which means we can toggle multiple channels at the same

time.

Using that wired up to buffer mode might make sense. You'd

provide

Quoted 2 lines
Quoted 2 lines

multiple
buffers and allow channels to be selected into one of them at a

time.

Quoted 6 lines
Quoted 6 lines

Each
buffer is then tied to a different toggle (TGP0, TGP1, etc)

The same could be true for the software toggle. It'll get a bit fiddly though.

Quoted 7 lines
Quoted 7 lines

Perhaps this is an advanced feature to think about later...

Quoted 1 line

It works the same with TGPx if you map multiple channels to the

same

Quoted 3 lines

pin.

There's also the question on how to handle this if a TGPx is

provided?

Quoted 1 line
Quoted 1 line
Quoted 1 line

I guess it will just override the pin... But most likely having them

both

Quoted 1 line
Quoted 1 line
Quoted 1 line

at the same time will lead to non desired results (unless we have

a

Quoted 2 lines
Quoted 2 lines
Quoted 1 line

way to gate/ungate the clocks)...

I don't follow this bit. You mean TGPx and software toggle. As far

as I

Quoted 5 lines
Quoted 3 lines

can
tell it's an either/or thing per channel.

Here I meant that if we have a TGPx pin bundled to some channel(s)

we

Quoted 1 line

do not want to also dance with the sw_toggle bit of that channel.

Ultimately,

Quoted 1 line

that's on the user responsibility but we could also add some guards I

guess.

Quoted 1 line

I'm not sure if it's an either/or thing per channel... IIUC, we spoke

about

Quoted 1 line

making dither and default mode the same. That might complicate

things a bit

Quoted 3 lines

as:

1) We should not force a user to specify a TGPx pin for those

channels (since

Quoted 2 lines

it can also work with dithering disabled).
2) Because of 1), we should also support sw_toggle for these

channels since

Quoted 1 line

someone might want to enable dither mode (at runtime) and the

TGPx pin was

Quoted 1 line

not given. Hence, we need to have a way to update the DAC using

the sw_toggle.

Quoted 2 lines

Did I understood things wrong? One thing that comes to my mind, is

to return

Quoted 1 line

error (eg: EPERM or ENOTSUPP) if someone tries to enable dither

mode and

Quoted 1 line

no TGPx pin was selected for that channel? Hence, we do not need

to add

Quoted 1 line

the sw_toggle ABI (out_voltage_symbol) for the default/dither

mode. Or

Quoted 1 line

maybe even better, we just expose the dither ABI if a TGPx pin is

given over

Quoted 1 line

dt (I try to explain the toggle/dither modes below; that might help

you in

Quoted 3 lines

understanding my reasoning here)?

Alternatively, we just keep the approach I have in this RFC and we

keep the

Quoted 1 line

3 different modes (being mode a dt property; in the current state I'm

using

Quoted 1 line

a boolean to say a channel Is in toggle mode)... Maybe with the

difference

Quoted 1 line

that we allow sw_toggle for toggle enabled channels.

The corner I'm not clear on is what we do if for example all TGPx pins are
specified in DT. Is the mapping from channel to TGPx things in toggle mode
always a function of the external circuit or do we want to make it runtime
controllable?

I'm absolutely fine if we just make it a dt property - particularly as those TGPx pins may well not be visible to the host processor.

Quoted 8 lines
Quoted 3 lines

We probably do want to provide some options in dt for what they might be
connnected to on the host. I'm guessing potentially a gpio, or a clk?

For each TGPx pin (from the point you bind it to some channel), I'm actually making it mandatory to have a clock (the reasoning being, if you say some channel is controlled over TGPx [being for toggle or dither mode], you need to have some input at the pin).

I'm not really sure what the usecases behind toggle are... Using a clock with dither makes sense, but toggle might not be fixed frequency but driven by some other type of event.

Still we don't have to support every usecase in an initial driver. Stick to a clock and see what requests you get for other input types later.

Quoted 4 lines

I might not be doing it in the way you're thinking but you can have a look in the actual series :) ...

...

Quoted 12 lines
Quoted 12 lines
Quoted 8 lines
Quoted 6 lines

So conclusions.. Hmm. Not strong ones yet, but for dither mode at least
I think you want to link particular channels to a TGPx choice

out_voltage0_raw out_voltage0_raw_available ( nice to have on DACs)

I guess here you mean 'IIO_AVAIL_RANGE'?

No, I mean providing the read_avail() callback and setting BIT(IIO_INFO_RAW) in info_mask_separate_available

Quoted 7 lines
Quoted 4 lines

That's how we provide range for a channel except in some unusual corner cases and the internal interface for that is used when a DAC is being used via the consumer interface (so some other driver wants to set it's output).

Yeah, I know :). I was just meaning 'IIO_AVAIL_RANGE' over 'IIO_AVAIL_LIST'. I guess that was already obvious to you :).

Ah. Got you. I'd forgotten about that - indeed IIO_AVAIL_RANGE

Quoted 61 lines
Quoted 47 lines
Quoted 11 lines
Quoted 11 lines

out_voltage0_scale
out_voltage0_dither_raw
out_voltage0_dither_raw_available
out_voltage0_dither_frequency
out_voltage0_dither_frequency_available
out_voltage0_dither_phase
out_voltage0_dither_phase_available

Toggle mode is less clear to me but symbol approach plus TGPx in

DT

Quoted 2 lines
Quoted 2 lines

maybe works
You could allow for software override to set the symbol. Interface

to

Quoted 10 lines
Quoted 8 lines

unset
it being to write an empty string to _symbol. Maybe leave that for now.

out_voltage0_raw0
out_voltage0_raw1
out_voltage0_scale
out_voltage0_symbol

Well, in short, I do agree with this ABI. And actually, for toggle mode,

I think

Quoted 1 line

this is more or less what we will have. For dither/default mode,

there's still

Quoted 1 line

the questions I raised above... Maybe, at the end, we will end up

with 3 different

Quoted 1 line

ABI's...

Certainly possible. Nice to avoid if we can, but not if it means stretching
things too far.

Quoted 6 lines

I would only add this to the ABI:
* out_voltage0_dither_en
* out_voltage0_toggle_en

Because if someone wants to change, let's say the dither frequency,

the best way

Quoted 1 line

to update things is to first disable dithering, update all the stuff, and

then enable

Quoted 1 line

it again...

Quoted 8 lines

I'll go with 'maybe' for these. The use for changing things doesn't make sense to me
unless we have multiple things to change at once. If it's just the frequency it
would be more intuitive to have a write to that attribute do the disable, set value
and enable dithering again without needing to do a dance with the interface.

Yeah and that is something that can happen here (and probably the most likely situation). For dither mode, you disable it, then you might want to change all the parameters of your dither (amplitude, phase and frequency) and then enable it again.

Quoted 7 lines

For toggle mode, this means, disabling it, updating input_a and input_b and enable it again.

Anyways, I think we already have some discussion that enables me to send the first version of this and we can continue from there. If all goes well, it should be out by the end of the week.

Great,

Jonathan

author maintainer
#20 lore raw
Quoted 356 lines

From: Jonathan Cameron <[email protected]>
Sent: Monday, December 6, 2021 2:16 PM
To: Sa, Nuno <[email protected]>
Cc: Jonathan Cameron <[email protected]>; [email protected]
Subject: Re: [RFC PATCH 0/1] LTC2688 support

[External]

Quoted 12 lines · Nuno
Quoted 12 lines

-----Original Message-----
From: Jonathan Cameron <[email protected]>
Sent: Sunday, December 5, 2021 7:01 PM
To: Sa, Nuno <[email protected]>
Cc: [email protected]
Subject: Re: [RFC PATCH 0/1] LTC2688 support

[External]

On Tue, 30 Nov 2021 14:43:25 +0000
"Sa, Nuno" <[email protected]> wrote:

Quoted 40 lines
Quoted 3 lines

Hi Nuno

Hopefully I've not lost the plot on this!

Not really. I had some days off so this was also set on hold from my side.

Quoted 33 lines
Quoted 22 lines
Quoted 22 lines

-----Original Message-----
From: Jonathan Cameron <[email protected]>
Sent: Sunday, November 21, 2021 1:18 PM
To: Sa, Nuno <[email protected]>
Cc: [email protected]
Subject: Re: [RFC PATCH 0/1] LTC2688 support

[External]

Quoted 10 lines · Nuno

Hi Jonathan,

Thanks for your inputs...

Quoted 6 lines

From: Jonathan Cameron <[email protected]>
Sent: Friday, November 12, 2021 5:15 PM
To: Sa, Nuno <[email protected]>
Cc: [email protected]
Subject: Re: [RFC PATCH 0/1] LTC2688 support

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

[External]

On Thu, 11 Nov 2021 12:00:42 +0100
Nuno Sá <[email protected]> wrote:

Hi Nuno,

Quoted 1 line

The reason why this is a RFC is because I'm still waiting for

proper

Quoted 2 lines
Quoted 2 lines

HW

Quoted 1 line
Quoted 1 line
Quoted 1 line

to test this thing. The reason why I'm sending this already

is

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

because

Quoted 1 line
Quoted 1 line
Quoted 1 line

there's some non usual features which might require

extra

Quoted 7 lines
Quoted 7 lines

ABI.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Hence,

Quoted 1 line

while waiting I thought we could already speed up the

process in

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

regards

Quoted 1 line

with the ABI.

Quoted 7 lines
Quoted 7 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

Wise move as this is an unusual beast :)

Quoted 2 lines

I still pushed the driver but the intent here is not really to

review

Quoted 2 lines
Quoted 2 lines

it.

Quoted 1 line
Quoted 1 line
Quoted 1 line

Naturally, if someone already wants to give some

feedback,

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

that's

Quoted 4 lines
Quoted 4 lines

very

Quoted 3 lines

much appreciated :)

Quoted 8 lines
Quoted 8 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

Now, there are three main interfaces depending on the

channel

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

mode:

Quoted 5 lines

1) default (no new ABI)
2) toggle mode
3) dither mode

The channel mode will be a devicetree property as it does

not

Quoted 6 lines
Quoted 6 lines
Quoted 2 lines
Quoted 2 lines

really

Quoted 1 line
Quoted 1 line
Quoted 1 line

make much sense to change between modes at runtime

even

Quoted 3 lines
Quoted 3 lines

more

Quoted 2 lines
Quoted 2 lines

because the

Quoted 1 line

piece of HW we might want to control with a channel

might

Quoted 6 lines
Quoted 6 lines

be

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

different

Quoted 1 line

depending on the selected mode (I'm fairly sure on this

between

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

toggle

Quoted 1 line

and other modes but not so sure between dither and

default

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

mode).

Quoted 2 lines
Quoted 2 lines

I agree on toggle vs dither definitely being different, but

normal

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

you

Quoted 1 line
Quoted 1 line

could implement either as software toggle, or dither with a

0

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

magnitude
sine wave. So might not be worth implementing default

mode

Quoted 3 lines
Quoted 3 lines

at

Quoted 2 lines
Quoted 2 lines

all.

Quoted 1 line
Quoted 1 line

No harm in doing so though if there are advantages to

having it.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

My feeling is that we could probably have dither as the

"default

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

mode".

Quoted 6 lines

More on this below...

Quoted 4 lines
Quoted 4 lines

toggle mode special ABI:

* Toggle operation enables fast switching of a DAC output

between

Quoted 2 lines
Quoted 2 lines

two

Quoted 1 line

different DAC codes without any SPI transaction. Two

codes

Quoted 4 lines
Quoted 4 lines

are

Quoted 3 lines
Quoted 3 lines

set

Quoted 2 lines
Quoted 2 lines

in

Quoted 1 line

input_a and input_b and then the output switches

according

Quoted 7 lines
Quoted 7 lines

to

Quoted 6 lines
Quoted 6 lines

an

Quoted 5 lines
Quoted 5 lines

input

Quoted 4 lines

signal (input_a -> clk high; input_b -> clk low).

out_voltageY_input_register
- selects between input_a and input_b. After selecting

one

Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
Quoted 5 lines

register,

Quoted 4 lines
Quoted 4 lines

we

Quoted 3 lines

can write the dac code in out_voltageY_raw.
out_voltageY_toggle_en
- Disable/Enable toggle mode. The reason why I think this

one is

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

important is because if we wanna change the 2 codes,

we

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

should

Quoted 2 lines
Quoted 2 lines

first

Quoted 1 line

disable this, set the codes and only then enable the

mode

Quoted 9 lines
Quoted 9 lines
Quoted 2 lines
Quoted 2 lines

back...

Quoted 1 line
Quoted 1 line
Quoted 1 line

As I'm writing this, It kind of came to me that we can

probably

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

achieve this with out_voltageY_powerdown attr (maybe

takes a

Quoted 4 lines
Quoted 4 lines

bit

Quoted 3 lines
Quoted 3 lines

more

Quoted 1 line

time to see the outputs but...)

Quoted 7 lines
Quoted 7 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

Hmm. These corner cases always take a bit of figuring out.

What

Quoted 5 lines
Quoted 5 lines

you

Quoted 4 lines
Quoted 4 lines

have
here is a bit 'device specific' for my liking.

So there is precedence for ABI in this area, on the

frequency

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

devices

Quoted 2 lines
Quoted 2 lines

but only
for devices we still haven't moved out of staging. For those

we

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

needed a means
to define selectable phases for PSK - where the selection

was

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

either

Quoted 3 lines
Quoted 3 lines

software or,
much like here, a selection pin.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

out_altvotage0_phase0 etc

so I guess the equivalent here would be out_voltageY_raw0
out_voltageY_raw1
and the selection would be via something like out_voltageY_symbol (0 or 1 in this case). - note this is only relevant if you have the software toggle. Any enable

needed

Quoted 3 lines
Quoted 3 lines

for

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

setting
can be done as part of the write sequence for the raw0 /

raw1

Quoted 11 lines
Quoted 11 lines

and

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

should
ideally not be exposed to userspace (controls that require

manual

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines

sequencing
tend to be hard to use / document).

Yeah, I thought about that. I was even thinking in having

something

Quoted 2 lines
Quoted 2 lines

like

Quoted 1 line

*_amplitude for dither mode. In some cases, where we might

be

Quoted 2 lines
Quoted 2 lines

left

Quoted 1 line
Quoted 1 line
Quoted 1 line

in some non obvious state (eg: moved the select register to

input

Quoted 7 lines
Quoted 7 lines

b

Quoted 2 lines
Quoted 2 lines

and

Quoted 1 line

then we failed to set the code;), I prefer to leave things as

flexible as

Quoted 1 line
Quoted 1 line
Quoted 1 line

possible for userspace. But I agree it adds up more complexity

and in

Quoted 1 line
Quoted 1 line
Quoted 1 line

this case, I can just always go to 'input_a' when writing

'raw0'...

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

However, I'm not 100% sure it really maps to this case.

What do

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

you

Quoted 3 lines
Quoted 1 line

think?

I think it can work. Though out_voltageY_symbol probably

needs

Quoted 8 lines
Quoted 8 lines

to

Quoted 2 lines
Quoted 2 lines

be

Quoted 1 line

shared by type to be coherent with what we might have with

TGPx.

Quoted 4 lines
Quoted 4 lines

That's fine.

Quoted 1 line

Note the sw_toggle register has a bit mask of the channels

we

Quoted 3 lines
Quoted 3 lines

want

Quoted 2 lines
Quoted 2 lines

to

Quoted 1 line

toggle which means we can toggle multiple channels at the

same

Quoted 11 lines
Quoted 11 lines
Quoted 3 lines
Quoted 3 lines

time.

Using that wired up to buffer mode might make sense. You'd

provide

Quoted 2 lines
Quoted 2 lines

multiple
buffers and allow channels to be selected into one of them at a

time.

Quoted 4 lines
Quoted 4 lines

Each
buffer is then tied to a different toggle (TGP0, TGP1, etc)

The same could be true for the software toggle. It'll get a bit

fiddly

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

though.

Perhaps this is an advanced feature to think about later...

Quoted 1 line

It works the same with TGPx if you map multiple channels to

the

Quoted 6 lines
Quoted 6 lines
Quoted 4 lines
Quoted 4 lines

same

Quoted 3 lines

pin.

There's also the question on how to handle this if a TGPx is

provided?

Quoted 1 line
Quoted 1 line
Quoted 1 line

I guess it will just override the pin... But most likely having

them

Quoted 2 lines
Quoted 2 lines

both

Quoted 1 line
Quoted 1 line
Quoted 1 line

at the same time will lead to non desired results (unless we

have

Quoted 3 lines
Quoted 3 lines

a

Quoted 2 lines
Quoted 2 lines
Quoted 1 line

way to gate/ungate the clocks)...

I don't follow this bit. You mean TGPx and software toggle. As

far

Quoted 6 lines
Quoted 6 lines

as I

Quoted 5 lines
Quoted 3 lines

can
tell it's an either/or thing per channel.

Here I meant that if we have a TGPx pin bundled to some

channel(s)

Quoted 4 lines
Quoted 4 lines

we

Quoted 1 line

do not want to also dance with the sw_toggle bit of that channel.

Ultimately,

Quoted 1 line

that's on the user responsibility but we could also add some

guards I

Quoted 7 lines
Quoted 7 lines

guess.

Quoted 1 line

I'm not sure if it's an either/or thing per channel... IIUC, we spoke

about

Quoted 1 line

making dither and default mode the same. That might complicate

things a bit

Quoted 2 lines

as:

Quoted 8 lines
Quoted 8 lines
Quoted 1 line

1) We should not force a user to specify a TGPx pin for those

channels (since

Quoted 2 lines

it can also work with dithering disabled).
2) Because of 1), we should also support sw_toggle for these

channels since

Quoted 1 line

someone might want to enable dither mode (at runtime) and the

TGPx pin was

Quoted 1 line

not given. Hence, we need to have a way to update the DAC

using

Quoted 3 lines
Quoted 3 lines

the sw_toggle.

Quoted 2 lines

Did I understood things wrong? One thing that comes to my

mind, is

Quoted 4 lines
Quoted 4 lines

to return

Quoted 1 line

error (eg: EPERM or ENOTSUPP) if someone tries to enable dither

mode and

Quoted 1 line

no TGPx pin was selected for that channel? Hence, we do not

need

Quoted 6 lines
Quoted 6 lines

to add

Quoted 1 line

the sw_toggle ABI (out_voltage_symbol) for the default/dither

mode. Or

Quoted 1 line

maybe even better, we just expose the dither ABI if a TGPx pin is

given over

Quoted 1 line

dt (I try to explain the toggle/dither modes below; that might

help

Quoted 4 lines
Quoted 4 lines

you in

Quoted 3 lines

understanding my reasoning here)?

Alternatively, we just keep the approach I have in this RFC and

we

Quoted 2 lines
Quoted 2 lines

keep the

Quoted 1 line

3 different modes (being mode a dt property; in the current state

I'm

Quoted 6 lines
Quoted 6 lines

using

Quoted 1 line

a boolean to say a channel Is in toggle mode)... Maybe with the

difference

Quoted 1 line

that we allow sw_toggle for toggle enabled channels.

The corner I'm not clear on is what we do if for example all TGPx

pins

Quoted 2 lines
Quoted 2 lines

are
specified in DT. Is the mapping from channel to TGPx things in

toggle

Quoted 8 lines
Quoted 8 lines

mode
always a function of the external circuit or do we want to make it runtime
controllable?

I'm absolutely fine if we just make it a dt property - particularly as those TGPx pins may well not be visible to the host processor.

Quoted 6 lines
Quoted 3 lines

We probably do want to provide some options in dt for what they might be
connnected to on the host. I'm guessing potentially a gpio, or a clk?

For each TGPx pin (from the point you bind it to some channel), I'm actually making it mandatory to have a clock (the reasoning being, if

Quoted 8 lines

you

Quoted 1 line

say some channel is controlled over TGPx [being for toggle or dither

mode],

Quoted 1 line

you need to have some input at the pin).

I'm not really sure what the usecases behind toggle are... Using a clock with dither makes sense, but toggle might not be fixed frequency but driven by some other type of event.

Taken from the datasheet (usecases for toggle mode):
"Examples include injection of a small ac bias, or independently switching between on and off states". A clock seems to fit even though I get your point that it might not fit all usecases for this. In that case, maybe sw_toggle can be enough :).

Anyways, agreed that we do not have to support all the stuff at the very beginning and it's probably a bad idea specially in cases like this where we are not sure about all possible usecases.

- Nuno Sá