iio: ltc2497: Fix reading conversion results
Subsystems (2)
PATCH 1/1 iio: ltc2497: Fix reading conversion results
From: Uwe Kleine-König <[email protected]>
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.
--- drivers/iio/adc/ltc2497.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
drivers/iio/adc/ltc2497.c +13 -0
@@ -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,
Signature · 1 line
2.28.0
Jonathan Cameron
maintainerQuoted 6 lines · On Mon, 15 Aug 2022 09:16:47 +0000 Denys Zagorui <[email protected]> wrote:
From: Uwe Kleine-König <[email protected]>
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.
Quoted 38 lines
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 <[email protected]>Signed-off-by Uwe Kleine-König <[email protected]>Tested-by Denys Zagorui <[email protected]>--- drivers/iio/adc/ltc2497.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)drivers/iio/adc/ltc2497.c +13
-0@@ -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,
Quoted 10 lines · Jonathan Cameron
Quoted 6 lines · On Mon, 15 Aug 2022 09:16:47 +0000 Denys Zagorui <[email protected]> wrote:
From: Uwe Kleine-König <[email protected]>
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.
Quoted 5 lines
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
Signature · 2 lines
Pengutronix e.K. | Uwe Kleine-König | Industrial Linux Solutions | https://www.pengutronix.de/ |
Jonathan Cameron
maintainerQuoted 13 lines · On Mon, 12 Sep 2022 12:46:31 +0200 Uwe Kleine-König…
Quoted 12 lines · Jonathan Cameron
Quoted 6 lines · On Mon, 15 Aug 2022 09:16:47 +0000 Denys Zagorui <[email protected]> wrote:
From: Uwe Kleine-König <[email protected]>
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.
Quoted 7 lines
Quoted 3 lines
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
Quoted 4 lines
Best regards
Uwe