Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp923551pxj; Fri, 4 Jun 2021 01:21:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwJFC58jCI4LXAi18k3J1/GaEMlzxAwkxsiOD+l2cNpuZIDWmxoVCjXCLStehhfE1kUo1se X-Received: by 2002:a05:6402:416:: with SMTP id q22mr3496466edv.204.1622794889034; Fri, 04 Jun 2021 01:21:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622794889; cv=none; d=google.com; s=arc-20160816; b=SNmCj7IE5MBLgmKN3qOLbCo7QX4TBGcn7ta576iz/00JzUCq1OW+nw+riHN//AfNEm 0pMY1XY+RTN470DbxcRcM4duuCLU8XF+x0NH0sknysqK7krESK2KPN7AQ2i12SwzHosm r2Jg62Sdd+C4xgTv67YNtoPeZsU/xhtdTgE+NJmIaUzQsceDyT9eRGnaX+FGEbTLgVt5 l/jg/EY7LKY0cp641gZCOZMEShRuLr55KihbubZQlVbOueNyurSNzFyD+n2/lel7Tdxi VsNcq7UJxUn8bjKRF5IoewjiZntHeqYDPn0qcITzg6MMm66/Xuyzy4sEoPOGodc8nTiT VNcQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date; bh=CPuVyMvh5Qe8amlvV+X6u1COf54VLEA6ZmB9YvyvQLM=; b=QteXjvPEjw6o+u0yAB9em4+YMKOXgIt0eQcRDko2hiKD0doVkgVbdtwH4C5vDtKbKQ 5U2ohh5SscoaZWmGphY7TNnV5qIfey3zyF+lVzt3gTwPcAH9bzfwabaPEEOu437Be4r3 owD1UXMUSsCTOepm0lIlcVVSt3JQXPP8AMqKFNBESlFYOUs+P3r+g/1QW+50mN2wxGx2 Gh4MKGs7sEbXfJErwAgoaz3iCxJGjvbfZ9yTE49HxKenq6H6ar5A2sxgVP61s+G59Dk/ A3sVb1+d4vkGXECpwVx3tGqPRMfEARhJCiQANtz44s3slNxaoSI3w7VaqLilfC1KpbWV Ek3g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bv2si4285868ejb.450.2021.06.04.01.21.03; Fri, 04 Jun 2021 01:21:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230044AbhFDIUq convert rfc822-to-8bit (ORCPT + 99 others); Fri, 4 Jun 2021 04:20:46 -0400 Received: from mail.kernel.org ([198.145.29.99]:56562 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229900AbhFDIUq (ORCPT ); Fri, 4 Jun 2021 04:20:46 -0400 Received: from jic23-huawei (cpc108967-cmbg20-2-0-cust86.5-4.cable.virginm.net [81.101.6.87]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E05F1611CC; Fri, 4 Jun 2021 08:18:57 +0000 (UTC) Date: Fri, 4 Jun 2021 09:20:43 +0100 From: Jonathan Cameron To: "Li, Meng" Cc: Uwe =?UTF-8?B?S2xlaW5lLUvDtm5pZw==?= , "lars@metafoo.de" , "Michael.Hennerich@analog.com" , "pmeerw@pmeerw.net" , "linux-kernel@vger.kernel.org" , "linux-iio@vger.kernel.org" Subject: Re: [PATCH] driver: adc: ltc2497: return directly after reading the adc conversion value Message-ID: <20210604092043.0b13f24a@jic23-huawei> In-Reply-To: References: <20210601092805.18385-1-Meng.Li@windriver.com> <20210603172025.314b5ced@jic23-huawei> <20210604061319.pbj5ptnhxfsz4cec@pengutronix.de> X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.33; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 4 Jun 2021 06:43:20 +0000 "Li, Meng" wrote: > > -----Original Message----- > > From: Uwe Kleine-König > > Sent: Friday, June 4, 2021 2:13 PM > > To: Li, Meng > > Cc: Jonathan Cameron ; lars@metafoo.de; > > Michael.Hennerich@analog.com; pmeerw@pmeerw.net; linux- > > kernel@vger.kernel.org; linux-iio@vger.kernel.org > > Subject: Re: [PATCH] driver: adc: ltc2497: return directly after reading the adc > > conversion value > > > > Hello, > > > > On Fri, Jun 04, 2021 at 02:16:39AM +0000, Li, Meng wrote: > > > > > > > > > > -----Original Message----- > > > > From: Jonathan Cameron > > > > Sent: Friday, June 4, 2021 12:20 AM > > > > To: Li, Meng > > > > 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 > > > > > > > > > > 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. > > > > As background about the choice of the .result_and_measure callback: > > A difference between the ltc2497 (i2c) and ltc2496 (spi) is that for the latter > > reading the result of the last conversion and starting a new is a single bus > > operation and the one cannot be done without the other. > > > > > > > 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. > > > > 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 > > 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 > > Signed-off-by: Uwe Kleine-König > > --- > > 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... J > > + if (ddata->addr_prev == address) > > + return 0; > > } > > > > ret = i2c_smbus_write_byte(st->client, > > > > Compared to Meng Li's patch this doesn't introduce reporting of bogus > > conversion results once we implement bulk conversion. > > > > Ok! > Understand. > I agree you to push patch to upstream and it is more reasonable that the original author to fix this issue. > > Thanks, > Limeng > > > Best regards > > Uwe > > > > -- > > Pengutronix e.K. | Uwe Kleine-König | > > Industrial Linux Solutions | https://www.pengutronix.de/ |