linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] driver: adc: ltc2497: return directly after reading the adc conversion value
@ 2021-06-01  9:28 Meng.Li
  2021-06-03 16:20 ` Jonathan Cameron
  0 siblings, 1 reply; 18+ messages in thread
From: Meng.Li @ 2021-06-01  9:28 UTC (permalink / raw)
  To: lars, Michael.Hennerich, jic23, pmeerw, u.kleine-koenig
  Cc: linux-kernel, linux-iio, meng.li

From: Meng Li <Meng.Li@windriver.com>

When read adc conversion value with below command:
cat /sys/.../iio:device0/in_voltage0-voltage1_raw
There is an error reported as below:
ltc2497 0-0014: i2c transfer failed: -EREMOTEIO
This i2c transfer issue is introduced by commit 69548b7c2c4f ("iio:
adc: ltc2497: split protocol independent part in a separate module").
When extract the common code into ltc2497-core.c, it change the
code logic of function ltc2497core_read(). With wrong reading
sequence, the action of enable adc channel is sent to chip again
during adc channel is in conversion status. In this way, there is
no ack from chip, and then cause i2c transfer failed.
In order to keep the code logic is the same with original ideal,
it is need to return direct after reading the adc conversion value.

v2:
According to ltc2497 datasheet, the max value of conversion time is
149.9 ms. So, add 20% to the 150msecs so that there is enough time
for data conversion.

Fixes: 69548b7c2c4f ("iio: adc: ltc2497: split protocol independent part in a separate module ")
Cc: stable@vger.kernel.org
Signed-off-by: Meng Li <Meng.Li@windriver.com>
---
 drivers/iio/adc/ltc2497.c | 2 ++
 drivers/iio/adc/ltc2497.h | 2 +-
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/iio/adc/ltc2497.c b/drivers/iio/adc/ltc2497.c
index 1adddf5a88a9..fd5a66860a47 100644
--- a/drivers/iio/adc/ltc2497.c
+++ b/drivers/iio/adc/ltc2497.c
@@ -41,6 +41,8 @@ static int ltc2497_result_and_measure(struct ltc2497core_driverdata *ddata,
 		}
 
 		*val = (be32_to_cpu(st->buf) >> 14) - (1 << 17);
+
+		return ret;
 	}
 
 	ret = i2c_smbus_write_byte(st->client,
diff --git a/drivers/iio/adc/ltc2497.h b/drivers/iio/adc/ltc2497.h
index d0b42dd6b8ad..e451930837d8 100644
--- a/drivers/iio/adc/ltc2497.h
+++ b/drivers/iio/adc/ltc2497.h
@@ -2,7 +2,7 @@
 
 #define LTC2497_ENABLE			0xA0
 #define LTC2497_CONFIG_DEFAULT		LTC2497_ENABLE
-#define LTC2497_CONVERSION_TIME_MS	150ULL
+#define LTC2497_CONVERSION_TIME_MS	180ULL
 
 struct ltc2497core_driverdata {
 	struct regulator *ref;
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 18+ messages in thread
* [PATCH] driver: adc: ltc2497: return directly after reading the adc conversion value
@ 2021-05-12  4:57 Meng.Li
  2021-05-18 17:46 ` Jonathan Cameron
  2021-05-19  9:21 ` Uwe Kleine-König
  0 siblings, 2 replies; 18+ messages in thread
From: Meng.Li @ 2021-05-12  4:57 UTC (permalink / raw)
  To: lars, Michael.Hennerich, jic23, pmeerw, u.kleine-koenig
  Cc: linux-kernel, linux-iio, meng.li

From: Meng Li <Meng.Li@windriver.com>

When read adc conversion value with below command:
cat /sys/.../iio:device0/in_voltage0-voltage1_raw
There is an error reported as below:
ltc2497 0-0014: i2c transfer failed: -EREMOTEIO
This i2c transfer issue is introduced by commit 69548b7c2c4f ("iio:
adc: ltc2497: split protocol independent part in a separate module").
When extract the common code into ltc2497-core.c, it change the
code logic of function ltc2497core_read(). With wrong reading
sequence, the action of enable adc channel is sent to chip again
during adc channel is in conversion status. In this way, there is
no ack from chip, and then cause i2c transfer failed.
In order to keep the code logic is the same with original ideal,
it is need to return direct after reading the adc conversion value.

Fixes: 69548b7c2c4f ("iio: adc: ltc2497: split protocol independent part in a separate module ")
Cc: stable@vger.kernel.org
Signed-off-by: Meng Li <Meng.Li@windriver.com>
---
 drivers/iio/adc/ltc2497.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/iio/adc/ltc2497.c b/drivers/iio/adc/ltc2497.c
index 1adddf5a88a9..fd5a66860a47 100644
--- a/drivers/iio/adc/ltc2497.c
+++ b/drivers/iio/adc/ltc2497.c
@@ -41,6 +41,8 @@ static int ltc2497_result_and_measure(struct ltc2497core_driverdata *ddata,
 		}
 
 		*val = (be32_to_cpu(st->buf) >> 14) - (1 << 17);
+
+		return ret;
 	}
 
 	ret = i2c_smbus_write_byte(st->client,
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2021-06-04  9:32 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
  -- 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

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).