The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: "Sabau, Radu bogdan" <Radu.Sabau@analog.com>
Cc: "Lars-Peter Clausen" <lars@metafoo.de>,
	"Hennerich, Michael" <Michael.Hennerich@analog.com>,
	"David Lechner" <dlechner@baylibre.com>,
	"Sa, Nuno" <Nuno.Sa@analog.com>,
	"Andy Shevchenko" <andy@kernel.org>,
	"Rob Herring" <robh@kernel.org>,
	"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
	"Conor Dooley" <conor+dt@kernel.org>,
	"Uwe Kleine-König" <ukleinek@kernel.org>,
	"Liam Girdwood" <lgirdwood@gmail.com>,
	"Mark Brown" <broonie@kernel.org>,
	"Linus Walleij" <linusw@kernel.org>,
	"Bartosz Golaszewski" <brgl@kernel.org>,
	"Philipp Zabel" <p.zabel@pengutronix.de>,
	"Jonathan Corbet" <corbet@lwn.net>,
	"Shuah Khan" <skhan@linuxfoundation.org>,
	"linux-iio@vger.kernel.org" <linux-iio@vger.kernel.org>,
	"devicetree@vger.kernel.org" <devicetree@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"linux-pwm@vger.kernel.org" <linux-pwm@vger.kernel.org>,
	"linux-gpio@vger.kernel.org" <linux-gpio@vger.kernel.org>,
	"linux-doc@vger.kernel.org" <linux-doc@vger.kernel.org>
Subject: Re: [PATCH v9 2/6] iio: adc: ad4691: add initial driver for AD4691 family
Date: Thu, 7 May 2026 15:15:49 +0100	[thread overview]
Message-ID: <20260507151549.61e4e8fb@jic23-huawei> (raw)
In-Reply-To: <LV9PR03MB841460307B0CF4C6F267A631F73C2@LV9PR03MB8414.namprd03.prod.outlook.com>

On Thu, 7 May 2026 09:26:00 +0000
"Sabau, Radu bogdan" <Radu.Sabau@analog.com> wrote:

> Addressing Sashiko's review for initial driver's patch.
> 
> > -----Original Message-----
> > From: Radu Sabau via B4 Relay <devnull+radu.sabau.analog.com@kernel.org>
> > Sent: Thursday, April 30, 2026 1:17 PM  
> 
> ...
> 
> > diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
> > index 60038ae8dfc4..3685a03aa8dc 100644
> > --- a/drivers/iio/adc/Kconfig
> > +++ b/drivers/iio/adc/Kconfig
> > @@ -139,6 +139,17 @@ config AD4170_4
> >  	  To compile this driver as a module, choose M here: the module will be
> >  	  called ad4170-4.
> > 
> > +config AD4691
> > +	tristate "Analog Devices AD4691 Family ADC Driver"
> > +	depends on SPI  
> 
> "Should this driver also depend on REGULATOR? In ad4691_regulator_setup(),
> it relies on devm_regulator_get_enable_read_voltage() to obtain its reference
> voltage. If the kernel is compiled without CONFIG_REGULATOR, this function
> is stubbed to return -ENODEV, causing probe to fail unconditionally."
> 
> Will add "depends on REGULATOR". Without it,
> devm_regulator_get_enable_read_voltage() can be stubbed and
> return -ENODEV, making the driver unusable regardless of hardware.

If you really want to also add || COMPILE_TEST because
I want maximum build coverage and for that I don't mind if the driver
can actually probe or not.

> 
> > +	select REGMAP
> > +	help
> > +	  Say yes here to build support for Analog Devices AD4691 Family  
> 
> ...
> 
> > +};
> > +
> > +#define AD4691_CHANNEL(ch)
> > 	\
> > +	{								\
> > +		.type = IIO_VOLTAGE,					\
> > +		.indexed = 1,						\
> > +		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW)
> > 	\
> > +				    | BIT(IIO_CHAN_INFO_SAMP_FREQ),	\
> > +		.info_mask_separate_available =
> > 	\
> > +				      BIT(IIO_CHAN_INFO_SAMP_FREQ),	\
> > +		.info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SCALE),
> > 	\  
> 
> "Since ad4691_set_sampling_freq() modifies the AD4691_OSC_FREQ_REG register
> which controls the global internal oscillator frequency for the entire ADC,
> should IIO_CHAN_INFO_SAMP_FREQ be exposed as info_mask_shared_by_all
> instead of info_mask_separate? Changing the frequency for one channel
> currently seems to silently alter it for all channels."
> 
> Agreed for this commit. With no per-channel OSR in the base driver
> all channels share a single oscillator register, so info_mask_shared_by_all
> is the correct annotation. Changing accordingly. The OSR commit switches it
> back to info_mask_separate because at that point the effective rate is
> genuinely per-channel (osc_freq / osr[N]).

Don't.  That would mean an ABI change mid way through the series which we
don't want. Just add a note to the patch description.

...


> 
> > +
> > +static int ad4691_reset(struct ad4691_state *st)
> > +{
> > +	struct device *dev = regmap_get_device(st->regmap);
> > +	struct reset_control *rst;
> > +
> > +	rst = devm_reset_control_get_optional_exclusive(dev, NULL);
> > +	if (IS_ERR(rst))
> > +		return dev_err_probe(dev, PTR_ERR(rst), "Failed to get
> > reset\n");
> > +
> > +	if (rst) {
> > +		/*
> > +		 * reset_gpio_probe() already drives the pin asserted, so the
> > +		 * device is held in reset before we get here.
> > +		 * devm_reset_control_get_optional_exclusive_deasserted()
> > cannot
> > +		 * be used because it deasserts immediately without delay; the
> > +		 * datasheet (Table 5) requires a ≥300 µs reset pulse width
> > +		 * before deassertion.
> > +		 */
> > +		fsleep(300);
> > +		return reset_control_deassert(rst);  
> 
> "Could this sequence break on driver reload?
> When the driver is unloaded, the reset line remains in its deasserted state
> because there is no cleanup action to re-assert it. Upon reloading, the 300
> microsecond sleep will occur while the pin is already deasserted, meaning
> the hardware might not receive the required reset pulse.
> Should reset_control_assert() be called explicitly prior to the delay?"
> 
> Valid. reset_control_put() does not re-assert the line at unload, so
> on reload the pin is already deasserted when we enter the 300 µs sleep.
> Adding reset_control_assert(rst) before fsleep(300) to guarantee a proper
> reset pulse on every probe including reloads.

I'm not that fussed about driver reload bugs like this one but why
not fix it I guess.  Lots of cases of this in upstream code though.

> 
> > +	}
> > +  
> 
> ...
> 
> > +
> > +	st = iio_priv(indio_dev);
> > +	st->info = spi_get_device_match_data(spi);  
> 
> "Is it possible for st->info to be NULL here?
> If the driver is manually bound to a device with a non-matching name using
> the sysfs bind interface in combination with driver_override,
> spi_get_device_match_data() could return NULL, which would cause a NULL
> pointer dereference later in the probe sequence."
> 
> Agreed, will add the NULL check with -ENODEV immediately after
> spi_get_device_match_data().

Andy, you seeing this one?  Looks like we are putting these checks back in again.
Whilst anyone forcing a bind like this is onto a looser anyway we shouldn't
crash due to a null dereference.

> 
> > +
> > +	ret = devm_mutex_init(dev, &st->lock);
> > +	if (ret)
> > +		return ret;  
> 


  reply	other threads:[~2026-05-07 14:16 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20260430-ad4692-multichannel-sar-adc-driver-v9-0-33e439e4fb87@analog.com>
     [not found] ` <20260430-ad4692-multichannel-sar-adc-driver-v9-2-33e439e4fb87@analog.com>
2026-05-05 13:23   ` [PATCH v9 2/6] iio: adc: ad4691: add initial driver for AD4691 family Jonathan Cameron
2026-05-07  9:26   ` Sabau, Radu bogdan
2026-05-07 14:15     ` Jonathan Cameron [this message]
2026-05-08  4:44       ` Andy Shevchenko
2026-05-08  9:53         ` Andy Shevchenko
     [not found] ` <20260430-ad4692-multichannel-sar-adc-driver-v9-4-33e439e4fb87@analog.com>
2026-05-05 14:12   ` [PATCH v9 4/6] iio: adc: ad4691: add SPI offload support Jonathan Cameron
2026-05-05 14:28   ` Jonathan Cameron
2026-05-06  9:17     ` Sabau, Radu bogdan
2026-05-07 11:49   ` Sabau, Radu bogdan
2026-05-07 15:11     ` Jonathan Cameron
2026-05-08 11:11       ` Sabau, Radu bogdan
     [not found] ` <20260430-ad4692-multichannel-sar-adc-driver-v9-5-33e439e4fb87@analog.com>
2026-05-05 14:32   ` [PATCH v9 5/6] iio: adc: ad4691: add oversampling support Jonathan Cameron
2026-05-07 11:56   ` Sabau, Radu bogdan
2026-05-07 15:26     ` Jonathan Cameron
     [not found] ` <20260430-ad4692-multichannel-sar-adc-driver-v9-6-33e439e4fb87@analog.com>
2026-05-05 14:35   ` [PATCH v9 6/6] docs: iio: adc: ad4691: add driver documentation Jonathan Cameron
     [not found] ` <20260430-ad4692-multichannel-sar-adc-driver-v9-3-33e439e4fb87@analog.com>
     [not found]   ` <afhReLCsEdaEOT_H@ashevche-desk.local>
     [not found]     ` <LV9PR03MB841441B282275F8F36FD12C1F7312@LV9PR03MB8414.namprd03.prod.outlook.com>
2026-05-05 13:26       ` [PATCH v9 3/6] iio: adc: ad4691: add triggered buffer support Jonathan Cameron
2026-05-05 14:58         ` Andy Shevchenko
2026-05-05 16:17           ` Jonathan Cameron
2026-05-06  7:25             ` Andy Shevchenko
2026-05-06  9:01               ` Sabau, Radu bogdan
2026-05-05 14:04   ` Jonathan Cameron
2026-05-05 14:07   ` Jonathan Cameron
2026-05-07 11:37   ` Sabau, Radu bogdan
2026-05-07 14:25     ` Jonathan Cameron
2026-05-08 11:08       ` Sabau, Radu bogdan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260507151549.61e4e8fb@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=Michael.Hennerich@analog.com \
    --cc=Nuno.Sa@analog.com \
    --cc=Radu.Sabau@analog.com \
    --cc=andy@kernel.org \
    --cc=brgl@kernel.org \
    --cc=broonie@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=corbet@lwn.net \
    --cc=devicetree@vger.kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=krzk+dt@kernel.org \
    --cc=lars@metafoo.de \
    --cc=lgirdwood@gmail.com \
    --cc=linusw@kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pwm@vger.kernel.org \
    --cc=p.zabel@pengutronix.de \
    --cc=robh@kernel.org \
    --cc=skhan@linuxfoundation.org \
    --cc=ukleinek@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox