lkml.org 
[lkml]   [2021]   [Jun]   [3]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    From
    SubjectRE: [PATCH] driver: adc: ltc2497: return directly after reading the adc conversion value
    Date


    > -----Original Message-----
    > From: Jonathan Cameron <jic23@kernel.org>
    > Sent: Friday, June 4, 2021 12:20 AM
    > To: Li, Meng <Meng.Li@windriver.com>
    > Cc: lars@metafoo.de; Michael.Hennerich@analog.com;
    > pmeerw@pmeerw.net; u.kleine-koenig@pengutronix.de; linux-
    > kernel@vger.kernel.org; linux-iio@vger.kernel.org
    > Subject: Re: [PATCH] driver: adc: ltc2497: return directly after reading the adc
    > conversion value
    >
    > [Please note: This e-mail is from an EXTERNAL e-mail address]
    >
    > On Tue, 1 Jun 2021 17:28:05 +0800
    > Meng.Li@windriver.com wrote:
    >
    > > 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.
    >
    > Version change logs go below the --- as we don't want to preserve them
    > forever in the git history.
    >
    > I may have lost track of the discussion, but I thought the idea was that
    > perhaps the longer time period would remove the need for the early return?
    >

    No!
    I think the ret is essential.
    Because when call i2c_master_recv() to receive data from chip, there is a stop bit sent to chip at the last step.
    When the chip receive the stop bit, it will start the next conversion operation.
    So, if we send any command on I2C bus when the chip is in conversion status, there will be a i2c error occurred.

    Thanks,
    Limeng

    > Thanks,
    >
    > Jonathan
    > >
    > > 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;

    \
     
     \ /
      Last update: 2021-06-04 04:18    [W:16.468 / U:0.024 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site