Skip to contentSkip to conversation

iio: adc: add max11410 adc driver

PATCH Superseded Ibrahim Tilki 3 participants 8 messages Aug 11, 2022 – Aug 20, 2022

Subsystems (3)

v3 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

v3 cover iio: adc: add max11410 adc driver

I added filter enable attributes for 50Hz and 60Hz FIR filters. Disabling both will set filter to sinc4, allowing higher sampling rates.

Regards,
Ibrahim

Note: No sign-off tag for David as he was unreachable when the initial patch was sent.

Changelog:
since v3:
- prefix defines with MAX11410_
- group vref regulators
- use builtin iio_validate_scan_mask_onehot
- validate iio trigger
- move scan data into state struct
- require vrefn regulator in DT if used by any channel
- don't require irq for triggered buffer
- remove filter sysfs attr and ABI documentation
- add in_voltage_filter[0-1]_notch_{center,en} attrs

since v2:
- remove bit position shifting, use field_prep instead
- reduce the amount of reg writes in max11410_configure_channel
- add error checking in max11410_parse_channels
- remove some unneeded blank lines and minor style fixes
- remove scan data assignment in max11410_trigger_handler

Ibrahim Tilki (2):
iio: adc: add max11410 adc driver
dt-bindings: iio: adc: add adi,max11410.yaml

 .../bindings/iio/adc/adi,max11410.yaml        | 165 +++
 drivers/iio/adc/Kconfig                       |  13 +
 drivers/iio/adc/Makefile                      |   1 +
 drivers/iio/adc/max11410.c                    | 954 ++++++++++++++++++
 4 files changed, 1133 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/adc/adi,max11410.yaml
 create mode 100644 drivers/iio/adc/max11410.c
Signature · 1 line
2.36.1
#1 lore raw

PATCH v3 1/2 iio: adc: add max11410 adc driver

Adding support for max11410 24-bit, 1.9ksps delta-sigma adc which has 3 differential reference and 10 differential channel inputs. Inputs and references can be buffered internally. Inputs can also be amplified with internal PGA.

Device has four digital filter modes: FIR50/60, FIR50, FIR60 and SINC4. FIR 50Hz and 60Hz rejections can be enabled/disabled separately. Digital filter selection affects sampling frequency range so driver has to consider the configured filter when configuring sampling frequency.

---
 drivers/iio/adc/Kconfig    |  13 +
 drivers/iio/adc/Makefile   |   1 +
 drivers/iio/adc/max11410.c | 954 +++++++++++++++++++++++++++++++++++++
 3 files changed, 968 insertions(+)
 create mode 100644 drivers/iio/adc/max11410.c
drivers/iio/adc/Kconfig +13 -0
index 71ab0a06a..eccb8d139 100644
@@ -654,6 +654,19 @@ config MAX1118
 	  To compile this driver as a module, choose M here: the module will be
 	  called max1118.
 
+config MAX11410
+	tristate "Analog Devices MAX11410 ADC driver"
+	depends on SPI
+	select REGMAP_SPI
+	select IIO_BUFFER
+	select IIO_TRIGGER
+	select IIO_TRIGGERED_BUFFER
+	help
+	  Say yes here to build support for Analog Devices MAX11410 ADCs.
+
+	  To compile this driver as a module, choose M here: the module will be
+	  called max11410.
+
 config MAX1241
 	tristate "Maxim max1241 ADC driver"
 	depends on SPI_MASTER
drivers/iio/adc/Makefile +1 -0
index 39d806f6d..679cc3c05 100644
@@ -61,6 +61,7 @@ obj-$(CONFIG_LTC2497) += ltc2497.o ltc2497-core.o
 obj-$(CONFIG_MAX1027) += max1027.o
 obj-$(CONFIG_MAX11100) += max11100.o
 obj-$(CONFIG_MAX1118) += max1118.o
+obj-$(CONFIG_MAX11410) += max11410.o
 obj-$(CONFIG_MAX1241) += max1241.o
 obj-$(CONFIG_MAX1363) += max1363.o
 obj-$(CONFIG_MAX9611) += max9611.o
drivers/iio/adc/max11410.c new file +954 -0

954 lines not on this page · raw message

Signature · 1 line
2.36.1
maintainer
#2 lore raw
Quoted 5 lines · On Thu, 11 Aug 2022 13:42:42 +0000 Ibrahim Tilki <[email protected]>…

Adding support for max11410 24-bit, 1.9ksps delta-sigma adc which has 3 differential reference and 10 differential channel inputs. Inputs and references can be buffered internally. Inputs can also be amplified with internal PGA.

Quoted 7 lines

Device has four digital filter modes: FIR50/60, FIR50, FIR60 and SINC4. FIR 50Hz and 60Hz rejections can be enabled/disabled separately. Digital filter selection affects sampling frequency range so driver has to consider the configured filter when configuring sampling frequency.

Hi

Line length is a bit random currently. Rough set of rules I'd go by:
1) If it doesn't hurt readability stay under 80 chars, but don't overwrap.
2) If there is a string someone might grep for, long lines are fine.
3) Try to keep under 100 chars in any case. (you are fine on this)

unfortunately I got confused and gave you some misleading feedback on v2. Short version is: ADC drivers do not present HARDWAREGAIN as it has no relevant meaning for them. They present only SCALE (and maybe CALIBSCALE if there are tuning values to be tweaked). The driver is then expected to work out the right settings of PGAs etc to achieve the requested scale value.

drivers/iio/adc/max11410.c line 1

Quoted 7 lines
drivers/iio/adc/max11410.c new file +1 -0
new file mode 100644
index 000000000..383cef3a0
@@ -0,0 +1,954 @@
+// SPDX-License-Identifier: GPL-2.0-only

No copyright notice? Unusual for such a big piece of work.

drivers/iio/adc/max11410.c line 78

Quoted 11 lines
drivers/iio/adc/max11410.c new file +11 -0
+
+static const u8 max11410_sampling_len[] = {
+	[MAX11410_FILTER_FIR5060] = 5,
+	[MAX11410_FILTER_FIR50] = 6,
+	[MAX11410_FILTER_FIR60] = 6,
+	[MAX11410_FILTER_SINC4] = 10,
+};
+
+static const int max11410_sampling_rates[4][10][2] = {
+	[MAX11410_FILTER_FIR5060] = {
+		{1, 100000},

{ 1, 100000 }, throughout to match most common kernel style.
We don't always bother fixing this in old code, because it creates a lot of noise, but good to get it right in new code.

Quoted 40 lines
drivers/iio/adc/max11410.c new file +36 -0
+		{2, 100000},
+		{4, 200000},
+		{8, 400000},
+		{16, 800000}
+	},
+	[MAX11410_FILTER_FIR50] = {
+		{1, 300000},
+		{2, 700000},
+		{5, 300000},
+		{10, 700000},
+		{21, 300000},
+		{40}
+	},
+	[MAX11410_FILTER_FIR60] = {
+		{1, 300000},
+		{2, 700000},
+		{5, 300000},
+		{10, 700000},
+		{21, 300000},
+		{40}
+	},
+	[MAX11410_FILTER_SINC4] = {
+		{4},
+		{10},
+		{20},
+		{40},
+		{60},
+		{120},
+		{240},
+		{480},
+		{960},
+		{1920}
+	}
+};
 
 
 
 
+static ssize_t max11410_notch_en_store(struct device *dev,
+				       struct device_attribute *devattr,

drivers/iio/adc/max11410.c

Quoted 10 lines
drivers/iio/adc/max11410.c new file +10 -0
+				       const char *buf, size_t count)
+{
+	struct iio_dev *indio_dev = dev_get_drvdata(dev);
+	struct max11410_state *state = iio_priv(indio_dev);
+	struct iio_dev_attr *iio_attr = to_iio_dev_attr(devattr);
+	unsigned int filter_bit;
+	int ret;
+
+	filter_bit = iio_attr->address == 0 ? MAX11410_FILTER_50HZ : MAX11410_FILTER_60HZ;
+	if (sysfs_streq(buf, "0"))

Tend to use kstrtobool() for cases like this. It's a little more generous in what it accepts. Documentation can carry on saying 0 or 1 though and we print 0 or 1 as most appropriate values for this attribute.

Quoted 15 lines
drivers/iio/adc/max11410.c new file +15 -0
+		ret = regmap_set_bits(state->regmap, MAX11410_REG_FILTER, filter_bit);
+	else if (sysfs_streq(buf, "1"))
+		ret = regmap_clear_bits(state->regmap, MAX11410_REG_FILTER, filter_bit);
+	else
+		return -EINVAL;
+
+	if (ret)
+		return ret;
+
+	return count;
+}
+
+static IIO_CONST_ATTR(in_voltage_filter0_notch_center, "50");
+static IIO_CONST_ATTR(in_voltage_filter1_notch_center, "60");
+

drivers/iio/adc/max11410.c line 311

Quoted 10 lines
drivers/iio/adc/max11410.c new file +10 -0
+static IIO_DEVICE_ATTR(in_voltage_filter0_notch_en, 0644,
+		       max11410_notch_en_show, max11410_notch_en_store, 0);
+static IIO_DEVICE_ATTR(in_voltage_filter1_notch_en, 0644,
+		       max11410_notch_en_show, max11410_notch_en_store, 1);
+
+static struct attribute *max11410_attributes[] = {
+	&iio_const_attr_in_voltage_filter0_notch_center.dev_attr.attr,
+	&iio_const_attr_in_voltage_filter1_notch_center.dev_attr.attr,
+	&iio_dev_attr_in_voltage_filter0_notch_en.dev_attr.attr,
+	&iio_dev_attr_in_voltage_filter1_notch_en.dev_attr.attr,

As mentioned in reply to cover letter this is all new, so please provide ABI documentatio to cover it.
I'm not fully comfortable with the approach of getting sinc4 if nothing else is configured but perhaps that makes sense. I'm a bit surprised that the hardware doesn't allow both the sinc4 and the FIR filters as would seem logical to get rid of Mains and sampling frequency associated noise.

We could take advantage of the fact that IIO ABI allows any file write
to effect any other (needed as we can't always describe complex dependencies and hence have additional attrs
in_voltage_filter2_notch_en (if you turn both the fir filters off you get this.
if you turn this on, then turn off).
in_voltage_filter2_notch_centre which matches the sampling frequency (I think!)

That might be clearer than implicit control of that filter?

Quoted 30 lines
drivers/iio/adc/max11410.c new file +29 -0
+	NULL
+};
+
 
+static int max11410_configure_channel(struct max11410_state *st,
+				      struct iio_chan_spec const *chan)
+{
+	int ret;
+	unsigned int regval;
+	struct max11410_channel_config cfg = st->channels[chan->address];
+
+	if (chan->differential)
+		ret = max11410_set_input_mux(st, chan->channel, chan->channel2);
+	else
+		ret = max11410_set_input_mux(st, chan->channel, MAX11410_AINN_GND);
+
+	if (ret)
+		return ret;
+
+	regval = FIELD_PREP(MAX11410_CTRL_VREFP_BUF_BIT, cfg.buffered_vrefp) |
+		 FIELD_PREP(MAX11410_CTRL_VREFN_BUF_BIT, cfg.buffered_vrefn) |
+		 FIELD_PREP(MAX11410_CTRL_REFSEL_MASK, cfg.refsel) |
+		 FIELD_PREP(MAX11410_CTRL_UNIPOLAR_BIT, !cfg.bipolar);
+	ret = regmap_update_bits(st->regmap, MAX11410_REG_CTRL,
+				 MAX11410_CTRL_REFSEL_MASK | MAX11410_CTRL_VREFN_BUF_BIT |
+				 MAX11410_CTRL_VREFN_BUF_BIT | MAX11410_CTRL_UNIPOLAR_BIT,
+				 regval);
+	if (ret)
+		return ret;
+

drivers/iio/adc/max11410.c line 362

Quoted 10 lines
drivers/iio/adc/max11410.c new file +10 -0
+	regval = FIELD_PREP(MAX11410_PGA_SIG_PATH_MASK, cfg.sig_path) |
+		 FIELD_PREP(MAX11410_PGA_GAIN_MASK, cfg.gain);
+	ret = regmap_write(st->regmap, MAX11410_REG_PGA, regval);
+	if (ret)
+		return ret;
+
+	if (cfg.settling_time_us)
+		fsleep(cfg.settling_time_us);
+
+	return ret;

return 0; Can't get here with any other value, so good to make that explicit.

Quoted 39 lines
drivers/iio/adc/max11410.c new file +39 -0
+}
+
+static int max11410_read_raw(struct iio_dev *indio_dev,
+			     struct iio_chan_spec const *chan,
+			     int *val, int *val2, long info)
+{
+	int ret, reg_val, filter, rate;
+	struct regulator *vrefp, *vrefn;
+	struct max11410_state *state = iio_priv(indio_dev);
+	struct max11410_channel_config cfg = state->channels[chan->address];
+
+	switch (info) {
+	case IIO_CHAN_INFO_SCALE:
+		vrefp = max11410_get_vrefp(state, cfg.refsel);
+		if (!vrefp) {
+			/* We should never get here */
+			return -ENODEV;
+		}
+
+		*val = regulator_get_voltage(vrefp) / 1000;
+		vrefn = max11410_get_vrefn(state, cfg.refsel);
+		if (vrefn)
+			*val -= regulator_get_voltage(vrefn) / 1000;
+
+		if (cfg.bipolar)
+			*val *= 2;
+
+		*val = *val >> cfg.gain;
+
+		*val2 = chan->scan_type.realbits;
+		return IIO_VAL_FRACTIONAL_LOG2;
+	case IIO_CHAN_INFO_OFFSET:
+		if (cfg.bipolar)
+			*val = -BIT(chan->scan_type.realbits - 1);
+		else
+			*val = 0;
+
+		return IIO_VAL_INT;
+	case IIO_CHAN_INFO_RAW:

drivers/iio/adc/max11410.c line 411

Quoted 10 lines
drivers/iio/adc/max11410.c new file +10 -0
+		ret = iio_device_claim_direct_mode(indio_dev);
+		if (ret)
+			return ret;
+
+		mutex_lock(&state->lock);
+
+		ret = max11410_configure_channel(state, chan);
+
+		if (!ret)
+			ret = max11410_sample(state, &reg_val);

Perhaps pull out these few lines of code as a helper so as to avoid the nasty if (!ret) handling.
max11410_read_channel() or something like that.

drivers/iio/adc/max11410.c line 424

Quoted 13 lines
drivers/iio/adc/max11410.c new file +13 -0
+
+		mutex_unlock(&state->lock);
+
+		iio_device_release_direct_mode(indio_dev);
+
+		if (ret)
+			return ret;
+
+		*val = reg_val;
+
+		return IIO_VAL_INT;
+	case IIO_CHAN_INFO_HARDWAREGAIN:
+		*val = BIT(cfg.gain);

See below. This shouldn't exist for an ADC driver.

Quoted 20 lines
drivers/iio/adc/max11410.c new file +20 -0
+		return IIO_VAL_INT;
+	case IIO_CHAN_INFO_SAMP_FREQ:
+		ret = regmap_read(state->regmap, MAX11410_REG_FILTER, &reg_val);
+		if (ret)
+			return ret;
+
+		filter = FIELD_GET(MAX11410_FILTER_LINEF_MASK, reg_val);
+		rate = reg_val & MAX11410_FILTER_RATE_MASK;
+		if (rate >= max11410_sampling_len[filter])
+			rate = max11410_sampling_len[filter] - 1;
+
+		*val = max11410_sampling_rates[filter][rate][0];
+		*val2 = max11410_sampling_rates[filter][rate][1];
+
+		return IIO_VAL_INT_PLUS_MICRO;
+	}
+	return -EINVAL;
+}
+
+static const int max11410_hwgain_list[] = {1, 2, 4, 8, 16, 32, 64, 128};

drivers/iio/adc/max11410.c line 454

Quoted 10 lines
drivers/iio/adc/max11410.c new file +10 -0
+
+static int max11410_write_raw(struct iio_dev *indio_dev,
+			      struct iio_chan_spec const *chan,
+			      int val, int val2, long mask)
+{
+	int i, ret, reg_val, filter;
+	struct max11410_state *st = iio_priv(indio_dev);
+
+	switch (mask) {
+	case IIO_CHAN_INFO_HARDWAREGAIN:

Ah. I gave a misleading response to discussion on previous patch as I misunderstood your question. Sorry about that! Just checked back on the v2 thread because I was surprised to see this here.

We shouldn't be using hardwaregain at all in this driver. Instead we should be computing the available _scale values for the various settings of hardware gain and making _scale controllable.

Hardware gain is intended for usecases where the gain is not directly on the channel value being measured (e.g. on the ADC used to measure a pulse on a time of flight sensor - the scale is on the voltage, not distance which is derived from the timing of those pulses). Userspace software as a result doesn't understand the use of hardware gain you have here. It does tend to understand using writable _SCALE.

It is more complex to write the code for scale, but it is an easier interface for userspace to use as it needs to change one value, not change something seemingly unrelated then notice the change in _scale which is what it cares about. You will need to provide an available_scale and that will require runtime computation based on the reference voltage. Sometimes it's better to just precompute that in probe() rather than doing it dynamically later.

Quoted 46 lines
drivers/iio/adc/max11410.c new file +46 -0
+		for (i = 0; i < ARRAY_SIZE(max11410_hwgain_list); ++i) {
+			if (val == max11410_hwgain_list[i])
+				break;
+		}
+		if (i == ARRAY_SIZE(max11410_hwgain_list))
+			return -EINVAL;
+
+		st->channels[chan->address].gain = i;
+
+		return 0;
+	case IIO_CHAN_INFO_SAMP_FREQ:
+		mutex_lock(&st->lock);
+
+		ret = regmap_read(st->regmap, MAX11410_REG_FILTER, &reg_val);
+		if (ret)
+			goto out;
+
+		filter = FIELD_GET(MAX11410_FILTER_LINEF_MASK, reg_val);
+
+		for (i = 0; i < max11410_sampling_len[filter]; ++i) {
+			if (val == max11410_sampling_rates[filter][i][0] &&
+			    val2 == max11410_sampling_rates[filter][i][1])
+				break;
+		}
+		if (i == max11410_sampling_len[filter]) {
+			ret = -EINVAL;
+			goto out;
+		}
+
+		ret = iio_device_claim_direct_mode(indio_dev);
+		if (ret)
+			goto out;
+
+		ret = regmap_write_bits(st->regmap, MAX11410_REG_FILTER,
+					MAX11410_FILTER_RATE_MASK, i);
+		iio_device_release_direct_mode(indio_dev);
+
+out:
+		mutex_unlock(&st->lock);
+
+		return ret;
+	default:
+		return -EINVAL;
+	}
+}
+

drivers/iio/adc/max11410.c line 565

Quoted 10 lines
drivers/iio/adc/max11410.c new file +7 -0
 
 
 
+
+static int max11410_buffer_postenable(struct iio_dev *indio_dev)
+{
+	int scan_ch, ret;
+	struct max11410_state *st = iio_priv(indio_dev);
+
+	/* Configure GPIO1 of MAX11410 as interrupt output. */

I'd missed this before, but it's come up for some other drivers in the meantime..

This will follow through to the binding, but it's very hard to retrofit support for different interrupt lines being wired. Much easier to add that now. Alternative is having the binding be flexible but check and reject interrupt wirings the driver doesn't know about yet.

Quoted 19 lines
drivers/iio/adc/max11410.c new file +18 -0
+	ret = max11410_write_reg(st, MAX11410_REG_GP1_CTRL, MAX11410_GP1_CTRL_INTRB);
+	if (ret)
+		return ret;
+
+	scan_ch = ffs(*indio_dev->active_scan_mask) - 1;
+
+	ret = max11410_configure_channel(st, &indio_dev->channels[scan_ch]);
+	if (ret)
+		return ret;
+
+	/* Start continuous conversion. */
+	return max11410_write_reg(st, MAX11410_REG_CONV_START, MAX11410_CONV_TYPE_CONTINUOUS);
+}
+
 
+static int max11410_parse_channels(struct max11410_state *st,
+				   struct iio_dev *indio_dev)
+{
+	struct iio_chan_spec *channels;

drivers/iio/adc/max11410.c line 624

Quoted 10 lines
drivers/iio/adc/max11410.c new file +10 -0
+	struct fwnode_handle *child;
+	struct max11410_channel_config *cfg;
+	struct device *dev = &st->spi_dev->dev;
+	const char *node_name;
+	unsigned int num_ch;
+	u32 inputs[2];
+	u32 reference, sig_path;
+	int chan_idx = 0;
+	int ret;
+	struct iio_chan_spec chanspec = chanspec_template;

Where it doesn't hurt grouping for readability, slight preference for reverse xmas tree.

drivers/iio/adc/max11410.c line 636

Quoted 12 lines
drivers/iio/adc/max11410.c new file +12 -0
+
+	num_ch = device_get_child_node_count(dev);
+	if (num_ch == 0)
+		return dev_err_probe(&indio_dev->dev,
+				     -ENODEV,
+				     "FW has no channels defined\n");
+
+	/* Reserve space for soft timestamp channel */
+	num_ch++;
+	channels = devm_kcalloc(dev, num_ch,
+				sizeof(struct iio_chan_spec),
+				GFP_KERNEL);

overwrapped. That fits nicely on one fewer lines.

drivers/iio/adc/max11410.c line 641

Quoted 5 lines
drivers/iio/adc/max11410.c new file +5 -0
+	if (!channels)
+		return -ENOMEM;
+
+	st->channels = devm_kcalloc(dev, num_ch,
+				    sizeof(struct max11410_channel_config),

sizeof(*st->channels) preferred for cases like this.

Quoted 3 lines
drivers/iio/adc/max11410.c new file +3 -0
+				    GFP_KERNEL);
+	if (!st->channels)
+		return -ENOMEM;

...

drivers/iio/adc/max11410.c line 753

Quoted 11 lines
drivers/iio/adc/max11410.c new file +10 -0
+}
 
+
+static int max11410_init_vref(struct device *dev,
+			      struct regulator **vref,
+			      const char *id)
+{
+	int ret;
+	struct regulator *reg;
+
+	reg = devm_regulator_get_optional(dev, id);

You need to separate handling of -ENODEV which indicates that a regulator is not specified from other errors which you do not want to hid. e.g. -EPROBE_DEFER
which just indicates we need to wait for some other driver to load
and then retry this one.

Quoted 43 lines
drivers/iio/adc/max11410.c new file +42 -0
+	if (IS_ERR(reg)) {
+		*vref = NULL;
+		return 0;
+	}
+	ret = regulator_enable(reg);
+	if (ret)
+		return dev_err_probe(dev, ret,
+				     "Failed to enable regulator %s\n", id);
+
+	*vref = reg;
+	return devm_add_action_or_reset(dev, max11410_disable_reg, reg);
+}
+
 
+
+static int max11410_probe(struct spi_device *spi)
+{
+	struct max11410_state *st;
+	struct iio_dev *indio_dev;
+	struct device *dev = &spi->dev;
+	const char *vrefp_regs[] = { "vref0p", "vref1p", "vref2p" };
+	const char *vrefn_regs[] = { "vref0n", "vref1n", "vref2n" };
+	int ret;
+	int i;
+
+	indio_dev = devm_iio_device_alloc(dev, sizeof(*st));
+	if (!indio_dev)
+		return -ENOMEM;
+
+	st = iio_priv(indio_dev);
+	st->spi_dev = spi;
+	init_completion(&st->completion);
+	mutex_init(&st->lock);
+
+	indio_dev->name = "max11410";
+	indio_dev->modes = INDIO_DIRECT_MODE;
+	indio_dev->info = &max11410_info;
+
+	st->regmap = devm_regmap_init_spi(spi, &regmap_config);
+	if (IS_ERR(st->regmap))
+		return dev_err_probe(dev, PTR_ERR(st->regmap),
+				     "regmap initialization failed\n");
+

drivers/iio/adc/max11410.c line 862

Quoted 10 lines
drivers/iio/adc/max11410.c new file +10 -0
+	st->avdd = devm_regulator_get(dev, "avdd");
+	if (IS_ERR(st->avdd))
+		return dev_err_probe(dev, PTR_ERR(st->avdd),
+				     "avdd-supply is required.\n");
+
+	ret = regulator_enable(st->avdd);
+	if (ret)
+		return ret;
+
+	ret = devm_add_action_or_reset(dev, max11410_disable_reg, st->avdd);

FYI. It probably won't land before this but there is a series adding devm_regulator_enable() under review that would replace this (and 100s more instances in IIO).

Quoted 23 lines
drivers/iio/adc/max11410.c new file +23 -0
+	if (ret)
+		return ret;
+
+	for (i = 0; i < ARRAY_SIZE(vrefp_regs); i++) {
+		ret = max11410_init_vref(dev, &st->vrefp[i], vrefp_regs[i]);
+		if (ret)
+			return ret;
+
+		ret = max11410_init_vref(dev, &st->vrefn[i], vrefn_regs[i]);
+		if (ret)
+			return ret;
+	}
+
+	/*
+	 * Regulators must be configured before parsing channels for
+	 * validating "adi,reference" property of each channel.
+	 */
+	ret = max11410_parse_channels(st, indio_dev);
+	if (ret)
+		return ret;
+
+	ret = regmap_set_bits(st->regmap, MAX11410_REG_CTRL, MAX11410_CTRL_FORMAT_BIT);
+	if (ret)

drivers/iio/adc/max11410.c line 895

Quoted 10 lines
drivers/iio/adc/max11410.c new file +10 -0
+		return ret;
+
+	st->trig = devm_iio_trigger_alloc(dev, "%s-dev%d",
+					  indio_dev->name,
+					  iio_device_id(indio_dev));
+	if (!st->trig)
+		return -ENOMEM;
+
+	st->trig->ops = &max11410_trigger_ops;
+	ret = devm_iio_trigger_register(dev, st->trig);

You register a trigger that might not have an irq to drive it? That's unusual and I think pointless - move the trigger allocation down to under the if (spi->irq > 0 ) block.

drivers/iio/adc/max11410.c line 902

Quoted 7 lines
drivers/iio/adc/max11410.c new file +7 -0
+	if (ret)
+		return ret;
+
+	indio_dev->trig = iio_trigger_get(st->trig);
+
+	ret = devm_iio_triggered_buffer_setup(dev, indio_dev,
+					      NULL,

NULL, fits on previous line so move it up.
I'm reading backwards and got bored at this point, but check for other similar cases.

drivers/iio/adc/max11410.c line 913

Quoted 11 lines
drivers/iio/adc/max11410.c new file +11 -0
+					      &max11410_trigger_handler,
+					      &max11410_buffer_ops);
+	if (ret)
+		return ret;
+
+	if (spi->irq > 0) {
+		ret = devm_request_threaded_irq(dev, spi->irq,
+						NULL,
+						&max11410_interrupt,
+						IRQF_ONESHOT,
+						"max11410", indio_dev);

overwrapped. Perhaps keep the two callbacks on one line given that NULL can go on either the line above or the one below where you have it.

		ret = devm_request_threaded_irq(dev, spi->irq,
						NULL, &max11410_interrupt,
						IRQF_ONESHOT,
						"max11410", indio_dev);

drivers/iio/adc/max11410.c line 566

Quoted 4 lines
drivers/iio/adc/max11410.c new file +4 -0
+		if (ret)
+			return ret;
+
+		ret = max11410_write_reg(st, MAX11410_REG_GP1_CTRL, MAX11410_GP1_CTRL_INTRB);

No loss of readability by adding line breaks as

drivers/iio/adc/max11410.c

Quoted 1 line
drivers/iio/adc/max11410.c new file +1 -0
+		ret = max11410_write_reg(st, MAX11410_REG_GP1_CTRL,
					 MAX11410_GP1_CTRL_INTRB);
Quoted 10 lines
drivers/iio/adc/max11410.c new file +10 -0
+		if (ret)
+			return ret;
+	}
+
+	ret = max11410_self_calibrate(st);
+	if (ret)
+		return dev_err_probe(dev, ret, "cannot perform device self calibration\n");
+
+	return devm_iio_device_register(dev, indio_dev);
+}
#3 lore raw

PATCH v3 2/2 dt-bindings: iio: adc: add adi,max11410.yaml

In reply to Ibrahim Tilki

Adding devicetree binding documentation for max11410 adc.

---
 .../bindings/iio/adc/adi,max11410.yaml        | 165 ++++++++++++++++++
 1 file changed, 165 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/adc/adi,max11410.yaml
Documentation/devicetree/bindings/iio/adc/adi,max11410.yaml new file +165 -0
new file mode 100644
index 000000000..a782bfcaf
@@ -0,0 +1,165 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+# Copyright 2022 Analog Devices Inc.
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/adc/adi,max11410.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Analog Devices MAX11410 ADC device driver
+
+maintainers:
+  - Ibrahim Tilki <[email protected]>
+
+description: |
+  Bindings for the Analog Devices MAX11410 ADC device. Datasheet can be
+  found here:
+    https://datasheets.maximintegrated.com/en/ds/MAX11410.pdf
+
+properties:
+  compatible:
+    enum:
+      - adi,max11410
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+  '#address-cells':
+    const: 1
+
+  '#size-cells':
+    const: 0
+
+  avdd-supply:
+    description: Necessarry avdd supply. Used as reference when no explicit reference supplied.
+
+  vref0p-supply:
+    description: vref0p supply can be used as reference for conversion.
+
+  vref1p-supply:
+    description: vref1p supply can be used as reference for conversion.
+
+  vref2p-supply:
+    description: vref2p supply can be used as reference for conversion.
+
+  vref0n-supply:
+    description: vref0n supply can be used as reference for conversion.
+
+  vref1n-supply:
+    description: vref1n supply can be used as reference for conversion.
+
+  vref2n-supply:
+    description: vref2n supply can be used as reference for conversion.
+
+  spi-max-frequency:
+    maximum: 8000000
+
+required:
+  - compatible
+  - reg
+  - avdd-supply
+
+patternProperties:
+  "^channel(@[0-9a-f]+)?$":
+    $ref: "adc.yaml"
+    type: object
+    description: Represents the external channels which are connected to the ADC.
+
+    properties:
+      reg:
+        description: The channel number in single-ended mode.
+        minimum: 0
+        maximum: 10
+
+      adi,reference:
+        description: |
+          Select the reference source to use when converting on
+          the specific channel. Valid values are:
+          0: VREF0P/VREF0N
+          1: VREF1P/VREF1N
+          2: VREF2P/VREF2N
+          3: AVDD/AGND
+          4: VREF0P/AGND
+          5: VREF1P/AGND
+          6: VREF2P/AGND
+          If this field is left empty, AVDD/AGND is selected.
+        $ref: /schemas/types.yaml#/definitions/uint32
+        enum: [0, 1, 2, 3, 4, 5, 6]
+        default: 3
+
+      adi,input-mode:
+        description: |
+          Select signal path of input channels. When PGA path is selected,
+          hardwaregain property is enabled for channel. Valid values are:
+          0: Buffered, low-power, unity-gain path (default)
+          1: Bypass path
+          2: PGA path
+        $ref: /schemas/types.yaml#/definitions/uint32
+        enum: [0, 1, 2]
+        default: 0
+
+      diff-channels: true
+
+      bipolar: true
+
+      settling-time-us: true
+
+      adi,buffered-vrefp:
+        description: Enable buffered mode for positive reference.
+        type: boolean
+
+      adi,buffered-vrefn:
+        description: Enable buffered mode for negative reference.
+        type: boolean
+
+    required:
+      - reg
+
+    additionalProperties: false
+
+additionalProperties: false
+
+examples:
+  - |
+    spi {
+      #address-cells = <1>;
+      #size-cells = <0>;
+
+      adc@0 {
+        compatible = "adi,max11410";
+        reg = <0>;
+        spi-max-frequency = <8000000>;
+        interrupts = <25 2>;
+        interrupt-parent = <&gpio>;
+
+        avdd-supply = <&adc_avdd>;
+
+        vref1p-supply = <&adc_vref1p>;
+        vref1n-supply = <&adc_vref1n>;
+
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        channel@0 {
+          reg = <0>;
+        };
+
+        channel@1 {
+          reg = <1>;
+          diff-channels = <2 3>;
+          adi,reference = <1>;
+          bipolar;
+          settling-time-us = <100000>;
+        };
+
+        channel@2 {
+          reg = <2>;
+          diff-channels = <7 9>;
+          adi,reference = <5>;
+          adi,input-mode = <2>;
+          settling-time-us = <50000>;
+        };
+      };
+    };
Signature · 1 line
2.36.1
maintainer
#4 lore raw

Re: [PATCH v3 2/2] dt-bindings: iio: adc: add adi,max11410.yaml

Quoted 4 lines · On Thu, 11 Aug 2022 13:42:43 +0000 Ibrahim Tilki <[email protected]>…

Adding devicetree binding documentation for max11410 adc.

As a general rule, prefer to see review on list.
Whilst Analog folk are usually good at doing reviews properly some other companies have been known to add reviewed-by tags without doing a proper job of review. Hence we prefer to hear from the reviewer on the public list if possible, even if it's a quick note to say what sort of review they have done (general correctness / check against datasheet / detailed subsystem interaction review etc) as that reduces the focus others may put on the same areas.

I regularly do this wrong in Huawei code btw as we still do more review before posting than we perhaps should :)

A few comments inline. Biggest is the interrupts description needing to be more general to avoid us having problems if we extend it in future to cover the other possible pin.

Quoted 28 lines
---
 .../bindings/iio/adc/adi,max11410.yaml        | 165 ++++++++++++++++++
 1 file changed, 165 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/adc/adi,max11410.yaml
Documentation/devicetree/bindings/iio/adc/adi,max11410.yaml new file +17 -0
new file mode 100644
index 000000000..a782bfcaf
@@ -0,0 +1,165 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+# Copyright 2022 Analog Devices Inc.
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/adc/adi,max11410.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Analog Devices MAX11410 ADC device driver
+
+maintainers:
+  - Ibrahim Tilki <[email protected]>
+
+description: |
+  Bindings for the Analog Devices MAX11410 ADC device. Datasheet can be
+  found here:
+    https://datasheets.maximintegrated.com/en/ds/MAX11410.pdf
+

Documentation/devicetree/bindings/iio/adc/adi,max11410.yaml line 27

Quoted 10 lines
Documentation/devicetree/bindings/iio/adc/adi,max11410.yaml new file +10 -0
+properties:
+  compatible:
+    enum:
+      - adi,max11410
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1

There are at least two possible pins, so this binding needs to take into account which one / ones are wired. Hence you need interrupt-names and the driver needs to route things appropriately or at very least give a clear 'I don't support GPIO0 usage' error message.

Quoted 37 lines
Documentation/devicetree/bindings/iio/adc/adi,max11410.yaml new file +37 -0
+
+  '#address-cells':
+    const: 1
+
+  '#size-cells':
+    const: 0
+
+  avdd-supply:
+    description: Necessarry avdd supply. Used as reference when no explicit reference supplied.
+
+  vref0p-supply:
+    description: vref0p supply can be used as reference for conversion.
+
+  vref1p-supply:
+    description: vref1p supply can be used as reference for conversion.
+
+  vref2p-supply:
+    description: vref2p supply can be used as reference for conversion.
+
+  vref0n-supply:
+    description: vref0n supply can be used as reference for conversion.
+
+  vref1n-supply:
+    description: vref1n supply can be used as reference for conversion.
+
+  vref2n-supply:
+    description: vref2n supply can be used as reference for conversion.
+
+  spi-max-frequency:
+    maximum: 8000000
+
+required:
+  - compatible
+  - reg
+  - avdd-supply
+
+patternProperties:

Documentation/devicetree/bindings/iio/adc/adi,max11410.yaml line 74

Quoted 10 lines
Documentation/devicetree/bindings/iio/adc/adi,max11410.yaml new file +10 -0
+  "^channel(@[0-9a-f]+)?$":
+    $ref: "adc.yaml"
+    type: object
+    description: Represents the external channels which are connected to the ADC.
+
+    properties:
+      reg:
+        description: The channel number in single-ended mode.
+        minimum: 0
+        maximum: 10

the @ address seems to allow more than 0 to 10. Perhaps need to bring those inline and make them both hex? Curious. What's the 11th channel if max isn't 9?

Quoted 11 lines
Documentation/devicetree/bindings/iio/adc/adi,max11410.yaml new file +11 -0
+
+      adi,reference:
+        description: |
+          Select the reference source to use when converting on
+          the specific channel. Valid values are:
+          0: VREF0P/VREF0N
+          1: VREF1P/VREF1N
+          2: VREF2P/VREF2N
+          3: AVDD/AGND
+          4: VREF0P/AGND
+          5: VREF1P/AGND

Documentation/devicetree/bindings/iio/adc/adi,max11410.yaml line 95

Quoted 10 lines
Documentation/devicetree/bindings/iio/adc/adi,max11410.yaml new file +10 -0
+          6: VREF2P/AGND
+          If this field is left empty, AVDD/AGND is selected.
+        $ref: /schemas/types.yaml#/definitions/uint32
+        enum: [0, 1, 2, 3, 4, 5, 6]
+        default: 3
+
+      adi,input-mode:
+        description: |
+          Select signal path of input channels. When PGA path is selected,
+          hardwaregain property is enabled for channel. Valid values are:

A binding should not mention details of what the linux driver is doing, so drop that bit about hardwaregain. Whilst bindings exist in the Linux tree they are used by various other bits of software.

Quoted 70 lines
Documentation/devicetree/bindings/iio/adc/adi,max11410.yaml new file +70 -0
+          0: Buffered, low-power, unity-gain path (default)
+          1: Bypass path
+          2: PGA path
+        $ref: /schemas/types.yaml#/definitions/uint32
+        enum: [0, 1, 2]
+        default: 0
+
+      diff-channels: true
+
+      bipolar: true
+
+      settling-time-us: true
+
+      adi,buffered-vrefp:
+        description: Enable buffered mode for positive reference.
+        type: boolean
+
+      adi,buffered-vrefn:
+        description: Enable buffered mode for negative reference.
+        type: boolean
+
+    required:
+      - reg
+
+    additionalProperties: false
+
+additionalProperties: false
+
+examples:
+  - |
+    spi {
+      #address-cells = <1>;
+      #size-cells = <0>;
+
+      adc@0 {
+        compatible = "adi,max11410";
+        reg = <0>;
+        spi-max-frequency = <8000000>;
+        interrupts = <25 2>;
+        interrupt-parent = <&gpio>;
+
+        avdd-supply = <&adc_avdd>;
+
+        vref1p-supply = <&adc_vref1p>;
+        vref1n-supply = <&adc_vref1n>;
+
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        channel@0 {
+          reg = <0>;
+        };
+
+        channel@1 {
+          reg = <1>;
+          diff-channels = <2 3>;
+          adi,reference = <1>;
+          bipolar;
+          settling-time-us = <100000>;
+        };
+
+        channel@2 {
+          reg = <2>;
+          diff-channels = <7 9>;
+          adi,reference = <5>;
+          adi,input-mode = <2>;
+          settling-time-us = <50000>;
+        };
+      };
+    };
#5 lore raw

RE: [PATCH v3 2/2] dt-bindings: iio: adc: add adi,max11410.yaml

Hello Jonathan,

We are using private GitHub repository and review our projects during Pull Request. We reviewed the MAX11410 Linux driver based on the general correctness, best practices, Linux coding style and IIO Driver implementation. The repository also contains test scripts that we can review the test coverage as well.

Best Regards,

Nurettin Bolucu
Senior MTS, Software - Istanbul Software Design Center Eski Buyukdere Cad. Maslak No.1 6th Floor 34485 Sariyer Istanbul TR

Office      90 (212) 952-5168
Mobile     90 (506) 992-7486
Web         analog.com

-----Original Message-----
From: Jonathan Cameron <[email protected]>
Sent: Sunday, August 14, 2022 18:56
To: Tilki, Ibrahim <[email protected]>
Cc: [email protected]; Sa, Nuno <[email protected]>; Bolucu, Nurettin <[email protected]>
Subject: Re: [PATCH v3 2/2] dt-bindings: iio: adc: add adi,max11410.yaml

[External]

Quoted 4 lines · On Thu, 11 Aug 2022 13:42:43 +0000 Ibrahim Tilki <[email protected]>…

Adding devicetree binding documentation for max11410 adc.

As a general rule, prefer to see review on list.
Whilst Analog folk are usually good at doing reviews properly some other companies have been known to add reviewed-by tags without doing a proper job of review. Hence we prefer to hear from the reviewer on the public list if possible, even if it's a quick note to say what sort of review they have done (general correctness / check against datasheet / detailed subsystem interaction review etc) as that reduces the focus others may put on the same areas.

I regularly do this wrong in Huawei code btw as we still do more review before posting than we perhaps should :)

A few comments inline. Biggest is the interrupts description needing to be more general to avoid us having problems if we extend it in future to cover the other possible pin.

Quoted 38 lines
---
 .../bindings/iio/adc/adi,max11410.yaml        | 165 ++++++++++++++++++
 1 file changed, 165 insertions(+)
 create mode 100644 

Documentation/devicetree/bindings/iio/adc/adi,max11410.yaml

(quoted diff) +0 -0

a/Documentation/devicetree/bindings/iio/adc/adi,max11410.yaml b/Documentation/devicetree/bindings/iio/adc/adi,max11410.yaml new file mode 100644
index 000000000..a782bfcaf

Documentation/devicetree/bindings/iio/adc/adi,max11410.yaml new file +24 -0
@@ -0,0 +1,165 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) # Copyright 2022 
+Analog Devices Inc.
+%YAML 1.2
+---
+$id: 
+https://urldefense.com/v3/__http://devicetree.org/schemas/iio/adc/adi
+,max11410.yaml*__;Iw!!A3Ni8CS0y2Y!7sok_RjOsQmX2sw37vgNw48j1VkwrSqKY0l
+gDlIAlxYUTh6-mbuZqS6ysSEQcFSTmpRIinW_-cwEpcG7BSg$
+$schema: 
+https://urldefense.com/v3/__http://devicetree.org/meta-schemas/core.y
+aml*__;Iw!!A3Ni8CS0y2Y!7sok_RjOsQmX2sw37vgNw48j1VkwrSqKY0lgDlIAlxYUTh
+6-mbuZqS6ysSEQcFSTmpRIinW_-cwEqTILbNA$
+
+title: Analog Devices MAX11410 ADC device driver
+
+maintainers:
+  - Ibrahim Tilki <[email protected]>
+
+description: |
+  Bindings for the Analog Devices MAX11410 ADC device. Datasheet can 
+be
+  found here:
+    https://datasheets.maximintegrated.com/en/ds/MAX11410.pdf
+

Documentation/devicetree/bindings/iio/adc/adi,max11410.yaml line 34

Quoted 10 lines
Documentation/devicetree/bindings/iio/adc/adi,max11410.yaml new file +10 -0
+properties:
+  compatible:
+    enum:
+      - adi,max11410
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1

There are at least two possible pins, so this binding needs to take into account which one / ones are wired. Hence you need interrupt-names and the driver needs to route things appropriately or at very least give a clear 'I don't support GPIO0 usage' error message.

Quoted 37 lines
Documentation/devicetree/bindings/iio/adc/adi,max11410.yaml new file +37 -0
+
+  '#address-cells':
+    const: 1
+
+  '#size-cells':
+    const: 0
+
+  avdd-supply:
+    description: Necessarry avdd supply. Used as reference when no explicit reference supplied.
+
+  vref0p-supply:
+    description: vref0p supply can be used as reference for conversion.
+
+  vref1p-supply:
+    description: vref1p supply can be used as reference for conversion.
+
+  vref2p-supply:
+    description: vref2p supply can be used as reference for conversion.
+
+  vref0n-supply:
+    description: vref0n supply can be used as reference for conversion.
+
+  vref1n-supply:
+    description: vref1n supply can be used as reference for conversion.
+
+  vref2n-supply:
+    description: vref2n supply can be used as reference for conversion.
+
+  spi-max-frequency:
+    maximum: 8000000
+
+required:
+  - compatible
+  - reg
+  - avdd-supply
+
+patternProperties:

Documentation/devicetree/bindings/iio/adc/adi,max11410.yaml line 74

Quoted 10 lines
Documentation/devicetree/bindings/iio/adc/adi,max11410.yaml new file +10 -0
+  "^channel(@[0-9a-f]+)?$":
+    $ref: "adc.yaml"
+    type: object
+    description: Represents the external channels which are connected to the ADC.
+
+    properties:
+      reg:
+        description: The channel number in single-ended mode.
+        minimum: 0
+        maximum: 10

the @ address seems to allow more than 0 to 10. Perhaps need to bring those inline and make them both hex? Curious. What's the 11th channel if max isn't 9?

Quoted 11 lines
Documentation/devicetree/bindings/iio/adc/adi,max11410.yaml new file +11 -0
+
+      adi,reference:
+        description: |
+          Select the reference source to use when converting on
+          the specific channel. Valid values are:
+          0: VREF0P/VREF0N
+          1: VREF1P/VREF1N
+          2: VREF2P/VREF2N
+          3: AVDD/AGND
+          4: VREF0P/AGND
+          5: VREF1P/AGND

Documentation/devicetree/bindings/iio/adc/adi,max11410.yaml line 95

Quoted 10 lines
Documentation/devicetree/bindings/iio/adc/adi,max11410.yaml new file +10 -0
+          6: VREF2P/AGND
+          If this field is left empty, AVDD/AGND is selected.
+        $ref: /schemas/types.yaml#/definitions/uint32
+        enum: [0, 1, 2, 3, 4, 5, 6]
+        default: 3
+
+      adi,input-mode:
+        description: |
+          Select signal path of input channels. When PGA path is selected,
+          hardwaregain property is enabled for channel. Valid values are:

A binding should not mention details of what the linux driver is doing, so drop that bit about hardwaregain. Whilst bindings exist in the Linux tree they are used by various other bits of software.

Quoted 70 lines
Documentation/devicetree/bindings/iio/adc/adi,max11410.yaml new file +70 -0
+          0: Buffered, low-power, unity-gain path (default)
+          1: Bypass path
+          2: PGA path
+        $ref: /schemas/types.yaml#/definitions/uint32
+        enum: [0, 1, 2]
+        default: 0
+
+      diff-channels: true
+
+      bipolar: true
+
+      settling-time-us: true
+
+      adi,buffered-vrefp:
+        description: Enable buffered mode for positive reference.
+        type: boolean
+
+      adi,buffered-vrefn:
+        description: Enable buffered mode for negative reference.
+        type: boolean
+
+    required:
+      - reg
+
+    additionalProperties: false
+
+additionalProperties: false
+
+examples:
+  - |
+    spi {
+      #address-cells = <1>;
+      #size-cells = <0>;
+
+      adc@0 {
+        compatible = "adi,max11410";
+        reg = <0>;
+        spi-max-frequency = <8000000>;
+        interrupts = <25 2>;
+        interrupt-parent = <&gpio>;
+
+        avdd-supply = <&adc_avdd>;
+
+        vref1p-supply = <&adc_vref1p>;
+        vref1n-supply = <&adc_vref1n>;
+
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        channel@0 {
+          reg = <0>;
+        };
+
+        channel@1 {
+          reg = <1>;
+          diff-channels = <2 3>;
+          adi,reference = <1>;
+          bipolar;
+          settling-time-us = <100000>;
+        };
+
+        channel@2 {
+          reg = <2>;
+          diff-channels = <7 9>;
+          adi,reference = <5>;
+          adi,input-mode = <2>;
+          settling-time-us = <50000>;
+        };
+      };
+    };
maintainer
#6 lore raw

Re: [PATCH v3 2/2] dt-bindings: iio: adc: add adi,max11410.yaml

Quoted 5 lines · Nurettin

Hello Jonathan,

We are using private GitHub repository and review our projects during Pull Request. We reviewed the MAX11410 Linux driver based on the general correctness, best practices, Linux coding style and IIO Driver implementation. The repository also contains test scripts that we can review the test coverage as well.

While nice to know, that's not much use for the upstream community who can't see what level of review etc is going on.

So probably better to drop the Reviewed-by tags from that process when upstreaming.

Thanks,

Jonathan

Quoted 242 lines

Best Regards,

Nurettin Bolucu
Senior MTS, Software - Istanbul Software Design Center Eski Buyukdere Cad. Maslak No.1 6th Floor 34485 Sariyer Istanbul TR

Office_____ 90 (212) 952-5168
Mobile____ 90 (506) 992-7486
Web________ analog.com

_ ______

-----Original Message-----
From: Jonathan Cameron <[email protected]>
Sent: Sunday, August 14, 2022 18:56
To: Tilki, Ibrahim <[email protected]>
Cc: [email protected]; Sa, Nuno <[email protected]>; Bolucu, Nurettin <[email protected]>
Subject: Re: [PATCH v3 2/2] dt-bindings: iio: adc: add adi,max11410.yaml

[External]

Quoted 4 lines · On Thu, 11 Aug 2022 13:42:43 +0000 Ibrahim Tilki <[email protected]>…

Adding devicetree binding documentation for max11410 adc.

As a general rule, prefer to see review on list.
Whilst Analog folk are usually good at doing reviews properly some other companies have been known to add reviewed-by tags without doing a proper job of review. Hence we prefer to hear from the reviewer on the public list if possible, even if it's a quick note to say what sort of review they have done (general correctness / check against datasheet / detailed subsystem interaction review etc) as that reduces the focus others may put on the same areas.

I regularly do this wrong in Huawei code btw as we still do more review before posting than we perhaps should :)

A few comments inline. Biggest is the interrupts description needing to be more general to avoid us having problems if we extend it in future to cover the other possible pin.

Quoted 38 lines
---
 .../bindings/iio/adc/adi,max11410.yaml        | 165 ++++++++++++++++++
 1 file changed, 165 insertions(+)
 create mode 100644 

Documentation/devicetree/bindings/iio/adc/adi,max11410.yaml

(quoted diff) +0 -0

a/Documentation/devicetree/bindings/iio/adc/adi,max11410.yaml b/Documentation/devicetree/bindings/iio/adc/adi,max11410.yaml new file mode 100644
index 000000000..a782bfcaf

Documentation/devicetree/bindings/iio/adc/adi,max11410.yaml new file +24 -0
@@ -0,0 +1,165 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) # Copyright 2022 
+Analog Devices Inc.
+%YAML 1.2
+---
+$id: 
+https://urldefense.com/v3/__http://devicetree.org/schemas/iio/adc/adi
+,max11410.yaml*__;Iw!!A3Ni8CS0y2Y!7sok_RjOsQmX2sw37vgNw48j1VkwrSqKY0l
+gDlIAlxYUTh6-mbuZqS6ysSEQcFSTmpRIinW_-cwEpcG7BSg$
+$schema: 
+https://urldefense.com/v3/__http://devicetree.org/meta-schemas/core.y
+aml*__;Iw!!A3Ni8CS0y2Y!7sok_RjOsQmX2sw37vgNw48j1VkwrSqKY0lgDlIAlxYUTh
+6-mbuZqS6ysSEQcFSTmpRIinW_-cwEqTILbNA$
+
+title: Analog Devices MAX11410 ADC device driver
+
+maintainers:
+  - Ibrahim Tilki <[email protected]>
+
+description: |
+  Bindings for the Analog Devices MAX11410 ADC device. Datasheet can 
+be
+  found here:
+    https://datasheets.maximintegrated.com/en/ds/MAX11410.pdf
+

Documentation/devicetree/bindings/iio/adc/adi,max11410.yaml line 34

Quoted 10 lines
Documentation/devicetree/bindings/iio/adc/adi,max11410.yaml new file +10 -0
+properties:
+  compatible:
+    enum:
+      - adi,max11410
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1  

There are at least two possible pins, so this binding needs to take into account which one / ones are wired. Hence you need interrupt-names and the driver needs to route things appropriately or at very least give a clear 'I don't support GPIO0 usage' error message.

Quoted 37 lines
Documentation/devicetree/bindings/iio/adc/adi,max11410.yaml new file +37 -0
+
+  '#address-cells':
+    const: 1
+
+  '#size-cells':
+    const: 0
+
+  avdd-supply:
+    description: Necessarry avdd supply. Used as reference when no explicit reference supplied.
+
+  vref0p-supply:
+    description: vref0p supply can be used as reference for conversion.
+
+  vref1p-supply:
+    description: vref1p supply can be used as reference for conversion.
+
+  vref2p-supply:
+    description: vref2p supply can be used as reference for conversion.
+
+  vref0n-supply:
+    description: vref0n supply can be used as reference for conversion.
+
+  vref1n-supply:
+    description: vref1n supply can be used as reference for conversion.
+
+  vref2n-supply:
+    description: vref2n supply can be used as reference for conversion.
+
+  spi-max-frequency:
+    maximum: 8000000
+
+required:
+  - compatible
+  - reg
+  - avdd-supply
+
+patternProperties:

Documentation/devicetree/bindings/iio/adc/adi,max11410.yaml line 74

Quoted 10 lines
Documentation/devicetree/bindings/iio/adc/adi,max11410.yaml new file +10 -0
+  "^channel(@[0-9a-f]+)?$":
+    $ref: "adc.yaml"
+    type: object
+    description: Represents the external channels which are connected to the ADC.
+
+    properties:
+      reg:
+        description: The channel number in single-ended mode.
+        minimum: 0
+        maximum: 10  

the @ address seems to allow more than 0 to 10. Perhaps need to bring those inline and make them both hex? Curious. What's the 11th channel if max isn't 9?

Quoted 11 lines
Documentation/devicetree/bindings/iio/adc/adi,max11410.yaml new file +11 -0
+
+      adi,reference:
+        description: |
+          Select the reference source to use when converting on
+          the specific channel. Valid values are:
+          0: VREF0P/VREF0N
+          1: VREF1P/VREF1N
+          2: VREF2P/VREF2N
+          3: AVDD/AGND
+          4: VREF0P/AGND
+          5: VREF1P/AGND

Documentation/devicetree/bindings/iio/adc/adi,max11410.yaml line 95

Quoted 10 lines
Documentation/devicetree/bindings/iio/adc/adi,max11410.yaml new file +10 -0
+          6: VREF2P/AGND
+          If this field is left empty, AVDD/AGND is selected.
+        $ref: /schemas/types.yaml#/definitions/uint32
+        enum: [0, 1, 2, 3, 4, 5, 6]
+        default: 3
+
+      adi,input-mode:
+        description: |
+          Select signal path of input channels. When PGA path is selected,
+          hardwaregain property is enabled for channel. Valid values are:  

A binding should not mention details of what the linux driver is doing, so drop that bit about hardwaregain. Whilst bindings exist in the Linux tree they are used by various other bits of software.

Quoted 70 lines
Documentation/devicetree/bindings/iio/adc/adi,max11410.yaml new file +70 -0
+          0: Buffered, low-power, unity-gain path (default)
+          1: Bypass path
+          2: PGA path
+        $ref: /schemas/types.yaml#/definitions/uint32
+        enum: [0, 1, 2]
+        default: 0
+
+      diff-channels: true
+
+      bipolar: true
+
+      settling-time-us: true
+
+      adi,buffered-vrefp:
+        description: Enable buffered mode for positive reference.
+        type: boolean
+
+      adi,buffered-vrefn:
+        description: Enable buffered mode for negative reference.
+        type: boolean
+
+    required:
+      - reg
+
+    additionalProperties: false
+
+additionalProperties: false
+
+examples:
+  - |
+    spi {
+      #address-cells = <1>;
+      #size-cells = <0>;
+
+      adc@0 {
+        compatible = "adi,max11410";
+        reg = <0>;
+        spi-max-frequency = <8000000>;
+        interrupts = <25 2>;
+        interrupt-parent = <&gpio>;
+
+        avdd-supply = <&adc_avdd>;
+
+        vref1p-supply = <&adc_vref1p>;
+        vref1n-supply = <&adc_vref1n>;
+
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        channel@0 {
+          reg = <0>;
+        };
+
+        channel@1 {
+          reg = <1>;
+          diff-channels = <2 3>;
+          adi,reference = <1>;
+          bipolar;
+          settling-time-us = <100000>;
+        };
+
+        channel@2 {
+          reg = <2>;
+          diff-channels = <7 9>;
+          adi,reference = <5>;
+          adi,input-mode = <2>;
+          settling-time-us = <50000>;
+        };
+      };
+    };  
maintainer
#7 lore raw
In reply to Ibrahim Tilki
Quoted 8 lines · On Thu, 11 Aug 2022 13:42:41 +0000 Ibrahim Tilki <[email protected]>…

I added filter enable attributes for 50Hz and 60Hz FIR filters. Disabling both will set filter to sinc4, allowing higher sampling rates.

Regards,
Ibrahim

Note: No sign-off tag for David as he was unreachable when the initial patch was sent.

Quoted 11 lines

Changelog:
since v3:
- prefix defines with MAX11410_
- group vref regulators
- use builtin iio_validate_scan_mask_onehot
- validate iio trigger
- move scan data into state struct
- require vrefn regulator in DT if used by any channel
- don't require irq for triggered buffer
- remove filter sysfs attr and ABI documentation
- add in_voltage_filter[0-1]_notch_{center,en} attrs

I'm not seeing a documentation patch for this new ABI. It's subtly different from the existing entries in Documentation/ABI/testing/sysfs-bus-iio and the _en part is new in general for filters.

I'll take a look at the rest of the code, but Docs need to be in place and reviewed before I can take the driver.

Thanks,

Jonathan

Quoted 21 lines

since v2:
- remove bit position shifting, use field_prep instead
- reduce the amount of reg writes in max11410_configure_channel
- add error checking in max11410_parse_channels
- remove some unneeded blank lines and minor style fixes
- remove scan data assignment in max11410_trigger_handler

Ibrahim Tilki (2):
iio: adc: add max11410 adc driver
dt-bindings: iio: adc: add adi,max11410.yaml

 .../bindings/iio/adc/adi,max11410.yaml        | 165 +++
 drivers/iio/adc/Kconfig                       |  13 +
 drivers/iio/adc/Makefile                      |   1 +
 drivers/iio/adc/max11410.c                    | 954 ++++++++++++++++++
 4 files changed, 1133 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/adc/adi,max11410.yaml
 create mode 100644 drivers/iio/adc/max11410.c