Devicetree
 help / color / mirror / Atom feed
From: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
To: "David Lechner (TI)" <dlechner@baylibre.com>
Cc: "Nuno Sá" <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>,
	"Chris Hall" <c-hall@ti.com>, "Patrick Edwards" <pedwards@ti.com>,
	"Kurt Borja" <kuurtb@gmail.com>,
	"Nguyen Minh Tien" <zizuzacker@gmail.com>,
	linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v4 6/8] iio: adc: add ti-ads112c14 driver
Date: Mon, 20 Jul 2026 00:42:18 +0100	[thread overview]
Message-ID: <20260720004218.4e010404@jic23-huawei> (raw)
In-Reply-To: <20260720000805.41022604@jic23-huawei>

On Mon, 20 Jul 2026 00:08:05 +0100
Jonathan Cameron <jonathan.cameron@oss.qualcomm.com> wrote:

> On Tue, 14 Jul 2026 18:21:28 -0500
> "David Lechner (TI)" <dlechner@baylibre.com> wrote:
> 
> > Add a new driver for the TI ADS112C14/ADS122C14 ADC chips.
> > 
> > This first step is adding a very basic driver that only supports power
> > on/reset and reading the system monitor channels.
> > 
> > ADS112C14_SYS_MON_CHANNEL_SHORT is the last channel rather than being in
> > logical order by address to keep the voltage channels together and in
> > case we find we need to add variants of this channel with different
> > voltage reference later.
> > 
> > Signed-off-by: David Lechner (TI) <dlechner@baylibre.com>  
> I think sashiko is sending us on a wild goose chase on this one.
> 
> "When ads112c14_single_conversion() calls i2c_smbus_read_i2c_block_data(), it
> returns the number of bytes read upon success. A short read (e.g. 1 or 2 bytes)
> would return a positive value, bypassing the (ret < 0) error check in
> ads112c14_read_raw()."
> 
> An i2c_smbus_read_i2c_block_data() response doesn't contain a length
> unlike i2c_smbus_read_block_data() which does. 
> 
> Maybe there is a controller driver out there that messes with block[0]
> rather than returning an error on failure to do the read part of
> the sequence. I checked a few and didn't find one.
> 
> It might make sense to make it clear this doesn't happen by
> adding checks in the i2c core.  One to consider after the other
> ones on my list!
> 
> However, one small related comment inline about keeping postive
> return values meaning success as local as possible in the code!
> 

I'm having a perhaps optimistic go at tweaking this to resolve remaining
tiny issues and avoid need for a v5.

Tweak here is:
diff --git a/drivers/iio/adc/ti-ads112c14.c b/drivers/iio/adc/ti-ads112c14.c
index a69c595ab518..bc0fd6839b72 100644
--- a/drivers/iio/adc/ti-ads112c14.c
+++ b/drivers/iio/adc/ti-ads112c14.c
@@ -322,9 +322,13 @@ static int ads112c14_single_conversion(struct ads112c14_data *data,
        if (ret)
                return ret;
 
-       return i2c_smbus_read_i2c_block_data(client, ADS112C14_CMD_RDATA,
-                                            BITS_TO_BYTES(data->chip_info->resolution_bits),
-                                            buf);
+       ret = i2c_smbus_read_i2c_block_data(client, ADS112C14_CMD_RDATA,
+                                           BITS_TO_BYTES(data->chip_info->resolution_bits),
+                                           buf);
+       if (ret < 0)
+               return ret;
+
+       return 0;
 }
 
 static int ads112c14_read_raw(struct iio_dev *indio_dev,
@@ -355,7 +359,7 @@ static int ads112c14_read_raw(struct iio_dev *indio_dev,
                        return -EBUSY;
 
                ret = ads112c14_single_conversion(data, chan, buf);
-               if (ret < 0)
+               if (ret)
                        return ret;
 
                switch (data->chip_info->resolution_bits) {


> Jonathan
> 
> 
> 
> 
> > diff --git a/drivers/iio/adc/ti-ads112c14.c b/drivers/iio/adc/ti-ads112c14.c
> > new file mode 100644
> > index 000000000000..a69c595ab518
> > --- /dev/null
> > +++ b/drivers/iio/adc/ti-ads112c14.c  
> 
> ...
> 
> > +
> > +static int ads112c14_single_conversion(struct ads112c14_data *data,
> > +				       const struct iio_chan_spec *chan,
> > +				       u8 *buf)
> > +{
> > +	struct i2c_client *client = to_i2c_client(regmap_get_device(data->regmap));
> > +	u32 reg_val;
> > +	int ret;
> > +
> > +	if (chan->channel < ADS112C14_SYS_MON_CHANNEL_BASE) {
> > +		/* Not implemented yet. */
> > +		return -EINVAL;
> > +	} else {
> > +		ret = ads112c14_prepare_sys_mon_channel(data, chan);
> > +		if (ret)
> > +			return ret;
> > +	}
> > +
> > +	ret = regmap_write(data->regmap, ADS112C14_REG_CONVERSION_CTRL,
> > +			   ADS112C14_CONVERSION_CTRL_START);
> > +	if (ret)
> > +		return ret;
> > +
> > +	ret = regmap_read_poll_timeout(data->regmap,
> > +				       ADS112C14_REG_STATUS_MSB, reg_val,
> > +				       FIELD_GET(ADS112C14_STATUS_MSB_DRDY, reg_val),
> > +				       1 * USEC_PER_MSEC, 100 * USEC_PER_MSEC);
> > +	if (ret)
> > +		return ret;
> > +
> > +	return i2c_smbus_read_i2c_block_data(client, ADS112C14_CMD_RDATA,
> > +					     BITS_TO_BYTES(data->chip_info->resolution_bits),
> > +					     buf);  
> With all that stuff above about this not returning short, I'd still be tempted to do
> an if (ret < 0) return ret; return 0; sequence in here so we don't propogate
> confusing positive returns beyond where we can see their source.
> 
> Having done that make the outer check if (ret) 
> 
> 
> > +}  
> 


  reply	other threads:[~2026-07-19 23:42 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-14 23:21 [PATCH v4 0/8] iio: adc: new ti-ads112c14 driver David Lechner
2026-07-14 23:21 ` [PATCH v4 1/8] dt-bindings: iio: adc: Add reference-sources property David Lechner
2026-07-14 23:21 ` [PATCH v4 2/8] dt-bindings: iio: adc: Add excitation current sources properties David Lechner
2026-07-14 23:21 ` [PATCH v4 3/8] dt-bindings: iio: adc: Add burn-out current properties David Lechner
2026-07-14 23:21 ` [PATCH v4 4/8] dt-bindings: iio: adc: add input-chopping property David Lechner (TI)
2026-07-15 16:01   ` Conor Dooley
2026-07-14 23:21 ` [PATCH v4 5/8] dt-bindings: iio: adc: add ti,ads122c14 David Lechner (TI)
2026-07-14 23:43   ` sashiko-bot
2026-07-15  0:16   ` David Lechner
2026-07-19 23:39   ` Jonathan Cameron
2026-07-14 23:21 ` [PATCH v4 6/8] iio: adc: add ti-ads112c14 driver David Lechner (TI)
2026-07-14 23:43   ` sashiko-bot
2026-07-19 23:08   ` Jonathan Cameron
2026-07-19 23:42     ` Jonathan Cameron [this message]
2026-07-14 23:21 ` [PATCH v4 7/8] iio: adc: ti-ads112c14: implement gain on internal short SYS_MON channel David Lechner (TI)
2026-07-14 23:21 ` [PATCH v4 8/8] iio: adc: ti-ads112c14: add measurement channel support David Lechner (TI)
2026-07-15  0:05   ` sashiko-bot
2026-07-19 23:18   ` Jonathan Cameron
2026-07-19 23:47 ` [PATCH v4 0/8] iio: adc: new ti-ads112c14 driver Jonathan Cameron

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=20260720004218.4e010404@jic23-huawei \
    --to=jonathan.cameron@oss.qualcomm.com \
    --cc=andy@kernel.org \
    --cc=c-hall@ti.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=krzk+dt@kernel.org \
    --cc=kuurtb@gmail.com \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nuno.sa@analog.com \
    --cc=pedwards@ti.com \
    --cc=robh@kernel.org \
    --cc=zizuzacker@gmail.com \
    /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