* [PATCH] iio: ltc2497: Fix reading conversion results
@ 2022-08-15 9:16 Denys Zagorui
2022-08-20 12:06 ` Jonathan Cameron
0 siblings, 1 reply; 4+ messages in thread
From: Denys Zagorui @ 2022-08-15 9:16 UTC (permalink / raw)
To: Meng.Li, jic23
Cc: lars, Michael.Hennerich, linux-iio, linux-kernel,
Uwe Kleine-König
From: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
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>
Tested-by: Denys Zagorui <dzagorui@cisco.com>
---
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
index f7c786f37ceb..78b93c99cc47 100644
--- 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.
+ */
+ if (ddata->addr_prev == address)
+ return 0;
}
ret = i2c_smbus_write_byte(st->client,
--
2.28.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] iio: ltc2497: Fix reading conversion results
2022-08-15 9:16 [PATCH] iio: ltc2497: Fix reading conversion results Denys Zagorui
@ 2022-08-20 12:06 ` Jonathan Cameron
2022-09-12 10:46 ` Uwe Kleine-König
0 siblings, 1 reply; 4+ messages in thread
From: Jonathan Cameron @ 2022-08-20 12:06 UTC (permalink / raw)
To: Denys Zagorui
Cc: Meng.Li, lars, Michael.Hennerich, linux-iio, linux-kernel,
Uwe Kleine-König
On Mon, 15 Aug 2022 09:16:47 +0000
Denys Zagorui <dzagorui@cisco.com> wrote:
> From: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
>
> 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.
That's rather nasty.
Could we add a cheeky sleep in the other path to ensure there is always
time for the conversion to be done? Not ideal, but might ensure
there isn't a known problem path without introducing much complexity.
>
> 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>
> Tested-by: Denys Zagorui <dzagorui@cisco.com>
> ---
> 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
> index f7c786f37ceb..78b93c99cc47 100644
> --- 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.
> + */
> + if (ddata->addr_prev == address)
> + return 0;
> }
>
> ret = i2c_smbus_write_byte(st->client,
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] iio: ltc2497: Fix reading conversion results
2022-08-20 12:06 ` Jonathan Cameron
@ 2022-09-12 10:46 ` Uwe Kleine-König
2022-09-18 14:22 ` Jonathan Cameron
0 siblings, 1 reply; 4+ messages in thread
From: Uwe Kleine-König @ 2022-09-12 10:46 UTC (permalink / raw)
To: Jonathan Cameron
Cc: Denys Zagorui, Meng.Li, lars, Michael.Hennerich, linux-iio,
linux-kernel
[-- Attachment #1: Type: text/plain, Size: 1074 bytes --]
On Sat, Aug 20, 2022 at 01:06:48PM +0100, Jonathan Cameron wrote:
> On Mon, 15 Aug 2022 09:16:47 +0000
> Denys Zagorui <dzagorui@cisco.com> wrote:
>
> > From: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> >
> > 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.
>
> That's rather nasty.
>
> Could we add a cheeky sleep in the other path to ensure there is always
> time for the conversion to be done? Not ideal, but might ensure
> there isn't a known problem path without introducing much complexity.
FTR: While the patch was originally authored by me, I don't currently
have access to a machine with that chip. So currently there will be no
incentive on my side to address this feedback.
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 --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] iio: ltc2497: Fix reading conversion results
2022-09-12 10:46 ` Uwe Kleine-König
@ 2022-09-18 14:22 ` Jonathan Cameron
0 siblings, 0 replies; 4+ messages in thread
From: Jonathan Cameron @ 2022-09-18 14:22 UTC (permalink / raw)
To: Uwe Kleine-König
Cc: Denys Zagorui, Meng.Li, lars, Michael.Hennerich, linux-iio,
linux-kernel
On Mon, 12 Sep 2022 12:46:31 +0200
Uwe Kleine-König <u.kleine-koenig@pengutronix.de> wrote:
> On Sat, Aug 20, 2022 at 01:06:48PM +0100, Jonathan Cameron wrote:
> > On Mon, 15 Aug 2022 09:16:47 +0000
> > Denys Zagorui <dzagorui@cisco.com> wrote:
> >
> > > From: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> > >
> > > 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.
> >
> > That's rather nasty.
> >
> > Could we add a cheeky sleep in the other path to ensure there is always
> > time for the conversion to be done? Not ideal, but might ensure
> > there isn't a known problem path without introducing much complexity.
>
> FTR: While the patch was originally authored by me, I don't currently
> have access to a machine with that chip. So currently there will be no
> incentive on my side to address this feedback.
I'm not keen to keep changes to this driver queued up on improving this patch.
Hence applied to the togreg branch of iio.git and I'll push that out as testing
shortly for the autobuilders to poke at it.
I have also marked it for stable.
Thanks,
Jonathan
>
> Best regards
> Uwe
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-09-18 14:22 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-08-15 9:16 [PATCH] iio: ltc2497: Fix reading conversion results Denys Zagorui
2022-08-20 12:06 ` Jonathan Cameron
2022-09-12 10:46 ` Uwe Kleine-König
2022-09-18 14:22 ` Jonathan Cameron
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox