From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_2 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 33A64C433EF for ; Sat, 18 Sep 2021 18:19:30 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D548161108 for ; Sat, 18 Sep 2021 18:19:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org D548161108 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=b2fCVFMPxDfJ5bmOygeBLg9RrkcWj9Ncklvpt8HnwJQ=; b=2JTIwrNP2agri+ 38+c24wyNxXIUJtuwOplmwcZdXE6OR4TV0rTtzhEs+0CG9jnqERsjiiyF0Dl7vyqc6hKhyb3Br7mg Jr7fIi7BdnB3TP4gVuvjBzVbIdib3H1UrU7gMW/WX5bnpSOkFyimuDAmXrvP/zMp6xdPeU1pIUgE1 e2NVIt1h5qs5p1v/Ct5P0MbnDZ8gWsiW3GIPkk6wOHllvOTBtOV3+LqJTC/lfN9C3rNCKQKcpszu4 RlqXHLxa78uQ9ivA/9YFWs6yKcOqoIwjpX+yCeZP7R3FNsNDJ88GcB0qcT8MEP2SDmTltR2GBFr7S amIMkY6so+imk74IfOkQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mReu2-00GCxu-OE; Sat, 18 Sep 2021 18:17:30 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mRety-00GCx3-Qb; Sat, 18 Sep 2021 18:17:28 +0000 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 C5C4460EB6; Sat, 18 Sep 2021 18:17:20 +0000 (UTC) Date: Sat, 18 Sep 2021 19:20:59 +0100 From: Jonathan Cameron To: Hui Liu Cc: , , , , , , , , , , , , , , , Subject: Re: [PATCH] iio: mtk-auxadc: update case IIO_CHAN_INFO_PROCESSED Message-ID: <20210918192059.4c13d157@jic23-huawei> In-Reply-To: <20210914130901.1716-2-hui.liu@mediatek.com> References: <20210914130901.1716-1-hui.liu@mediatek.com> <20210914130901.1716-2-hui.liu@mediatek.com> X-Mailer: Claws Mail 4.0.0 (GTK+ 3.24.30; x86_64-pc-linux-gnu) MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210918_111726_939327_11ABA209 X-CRM114-Status: GOOD ( 25.07 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Tue, 14 Sep 2021 21:09:01 +0800 Hui Liu wrote: > Convert raw data to processed data. > > Fixes: ace4cdfe67be ("iio: adc: mt2701: Add Mediatek auxadc driver for > mt2701.") > Signed-off-by: Hui Liu Hi Hui Liu This fix is obviously correct but I think we can improve it a little. 1) Add a bit more detail to the patch description. Perhaps change it to something like Previously the driver did not apply the scaling necessary to take the voltage range of this ADC into account. 2) If you change to *val = *val * VOLTAGE_FULL_RANGE; *val2 = 12; return IIO_VAL_FRACTIONAL_LOG2; then you should get a more precise answer. (Please check that though!) This might be an issue if you have consumers drivers though that can not cope with this particular type. If so please state that in the patch description and add a comment to the code to say that so we don't end up 'improving' this in future without taking those consumers into account. Thanks, Jonathan > --- > drivers/iio/adc/mt6577_auxadc.c | 8 ++++++++ > 1 file changed, 8 insertions(+) > > diff --git a/drivers/iio/adc/mt6577_auxadc.c b/drivers/iio/adc/mt6577_auxadc.c > index 79c1dd68b909..d4fccd52ef08 100644 > --- a/drivers/iio/adc/mt6577_auxadc.c > +++ b/drivers/iio/adc/mt6577_auxadc.c > @@ -82,6 +82,10 @@ static const struct iio_chan_spec mt6577_auxadc_iio_channels[] = { > MT6577_AUXADC_CHANNEL(15), > }; > > +/* For Voltage calculation */ > +#define VOLTAGE_FULL_RANGE 1500 /* VA voltage */ > +#define AUXADC_PRECISE 4096 /* 12 bits */ > + > static int mt_auxadc_get_cali_data(int rawdata, bool enable_cali) > { > return rawdata; > @@ -191,6 +195,10 @@ static int mt6577_auxadc_read_raw(struct iio_dev *indio_dev, > } > if (adc_dev->dev_comp->sample_data_cali) > *val = mt_auxadc_get_cali_data(*val, true); > + > + /* Convert adc raw data to voltage: 0 - 1500 mV */ > + *val = *val * VOLTAGE_FULL_RANGE / AUXADC_PRECISE; > + > return IIO_VAL_INT; > > default: _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel