linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
To: "Li, Meng" <Meng.Li@windriver.com>
Cc: Jonathan Cameron <jic23@kernel.org>,
	"lars@metafoo.de" <lars@metafoo.de>,
	"Michael.Hennerich@analog.com" <Michael.Hennerich@analog.com>,
	"pmeerw@pmeerw.net" <pmeerw@pmeerw.net>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"linux-iio@vger.kernel.org" <linux-iio@vger.kernel.org>
Subject: Re: [PATCH] driver: adc: ltc2497: return directly after reading the adc conversion value
Date: Fri, 4 Jun 2021 11:32:43 +0200	[thread overview]
Message-ID: <20210604093243.fxyia23i5eq4y5c7@pengutronix.de> (raw)
In-Reply-To: <PH0PR11MB51916BF5C390C90F66385E8BF13B9@PH0PR11MB5191.namprd11.prod.outlook.com>

[-- Attachment #1: Type: text/plain, Size: 5324 bytes --]

On Fri, Jun 04, 2021 at 09:04:48AM +0000, Li, Meng wrote:
> > On Fri, Jun 04, 2021 at 09:20:43AM +0100, Jonathan Cameron wrote:
> > > On Fri, 4 Jun 2021 06:43:20 +0000
> > > "Li, Meng" <Meng.Li@windriver.com> wrote:
> > > > > On Fri, Jun 04, 2021 at 02:16:39AM +0000, Li, Meng wrote:
> > > > > > I think the ret is essential.
> > > > >
> > > > > I'd like to understand why. Currently ltc2497core_read() looks as
> > > > > follows (simplified by dropping error handling, and unrolling the
> > > > > result_and_measure callback for the i2c case):
> > > > >
> > > > > 	ltc2497core_wait_conv()
> > > > >
> > > > > 	// result_and_measure(address, NULL)
> > > > > 	i2c_smbus_write_byte(client, LTC2497_ENABLE | address);
> > > > >
> > > > > 	msleep_interruptible(LTC2497_CONVERSION_TIME_MS)
> > > > >
> > > > > 	// result_and_measure(address, val);
> > > > > 	i2c_master_recv(client, &buf, 3);
> > > > > 	i2c_smbus_write_byte(client, LTC2497_ENABLE | address);
> > > > >
> > > > >
> > > > > With the early return you suggest to introduce with your patch you
> > > > > save the last i2c_smbus_write_byte call. The data sheet indeed
> > > > > claims to start a new conversion at the stop condition.
> > > > >
> > > > > So either the reading of the conversion result and programming of
> > > > > the
> > > > > (maybe) new address has to be done in a single i2c transfer, or we
> > > > > have to do something like your patch.
> > > > >
> > > > > What I don't like about your approach is that it changes the
> > > > > semantic of the callback to result_*or*_measure which is something
> > > > > the spi variant cannot implement. With the current use of the
> > > > > function this is fine, however if at some time in the future we
> > > > > implement a bulk conversion shortcut this hurts.
> > > > >
> > > > > So I suggest to do:
> > > > >
> > > > > ---->8----
> > > > > From: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> > > > > Date: Fri, 4 Jun 2021 08:02:44 +0200
> > > > > Subject: [PATCH] iio: ltc2497: Fix reading conversion results
> > > > >
> > > > > After the result of the previous conversion is read the chip
> > > > > automatically starts a new conversion and doesn't accept new i2c
> > > > > transfers until this conversion is completed which makes the function return failure.
> > > > >
> > > > > So add an early return iff the programming of the new address isn't needed.
> > > > > Note this will not fix the problem in general, but all cases that
> > > > > are currently used. Once this changes we get the failure back, but
> > > > > this can be addressed when the need arises.
> > > > >
> > > > > Fixes: 69548b7c2c4f ("iio: adc: ltc2497: split protocol
> > > > > independent part in a separate module ")
> > > > > Reported-by: Meng Li <Meng.Li@windriver.com>
> > > > > Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> > > > > ---
> > > > >  drivers/iio/adc/ltc2497.c | 13 +++++++++++++
> > > > >  1 file changed, 13 insertions(+)
> > > > >
> > > > > diff --git a/drivers/iio/adc/ltc2497.c b/drivers/iio/adc/ltc2497.c
> > > > > --- a/drivers/iio/adc/ltc2497.c
> > > > > +++ b/drivers/iio/adc/ltc2497.c
> > > > > @@ -41,6 +41,19 @@ static int ltc2497_result_and_measure(struct
> > > > > ltc2497core_driverdata *ddata,
> > > > >  		}
> > > > >
> > > > >  		*val = (be32_to_cpu(st->buf) >> 14) - (1 << 17);
> > > > > +
> > > > > +		/*
> > > > > +		 * The part started a new conversion at the end of the above i2c
> > > > > +		 * transfer, so if the address didn't change since the last call
> > > > > +		 * everything is fine and we can return early.
> > > > > +		 * If not (which should only happen when some sort of bulk
> > > > > +		 * conversion is implemented) we have to program the new
> > > > > +		 * address. Note that this probably fails as the conversion that
> > > > > +		 * was triggered above is like not complete yet and the two
> > > > > +		 * operations have to be done in a single transfer.
> > > > > +		 */
> > >
> > > I'm a little confused by this comment.  It seems to say it will fail
> > > if we ever do have a different address?  That doesn't seem very helpful...
> > 
> > It's not a real problem in the sense that it triggers today. If you want to read
> > out (say) the channels 1, 5, 6 and 7, you could do:
> > 
> > 	start conversion for channel 1
> > 	wait for the conversion to complete
> > 	read out conversion for channel 1 and start channel 5
> > 	wait for the conversion to complete
> > 	read out conversion for channel 5 and start channel 6
> > 	wait for the conversion to complete
> > 	read out conversion for channel 6 and start channel 7
> > 	wait for the conversion to complete
> > 	read out conversion for channel 7
> 
> Have you tested above case on real hardware? Or only a inference based on data sheet?

I never had the ltc2497 in my hands, but the customer I created my
patches for uses the ltc2496 (i.e. its spi variant) and did the above
from userspace using spidev.

And I'm confident enough to claim that if your patch fixes your problem,
then mine does it, too.

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

  reply	other threads:[~2021-06-04  9:32 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-01  9:28 [PATCH] driver: adc: ltc2497: return directly after reading the adc conversion value Meng.Li
2021-06-03 16:20 ` Jonathan Cameron
2021-06-04  2:16   ` Li, Meng
2021-06-04  6:13     ` Uwe Kleine-König
2021-06-04  6:43       ` Li, Meng
2021-06-04  8:20         ` Jonathan Cameron
2021-06-04  8:53           ` Uwe Kleine-König
2021-06-04  9:04             ` Li, Meng
2021-06-04  9:32               ` Uwe Kleine-König [this message]
  -- strict thread matches above, loose matches on Subject: below --
2021-05-12  4:57 Meng.Li
2021-05-18 17:46 ` Jonathan Cameron
2021-05-19  9:21 ` Uwe Kleine-König
2021-05-21 17:01   ` Jonathan Cameron
2021-05-24  2:49     ` Li, Meng
2021-05-25  8:19       ` Jonathan Cameron
2021-05-24  2:53   ` Li, Meng
2021-05-25  8:22     ` Felix Knopf
2021-05-25 10:36       ` Li, Meng

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=20210604093243.fxyia23i5eq4y5c7@pengutronix.de \
    --to=u.kleine-koenig@pengutronix.de \
    --cc=Meng.Li@windriver.com \
    --cc=Michael.Hennerich@analog.com \
    --cc=jic23@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pmeerw@pmeerw.net \
    /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;
as well as URLs for NNTP newsgroup(s).