From patchwork Tue Sep 28 13:31:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 12522797 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 236FCC43219 for ; Tue, 28 Sep 2021 13:34:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0E6796127C for ; Tue, 28 Sep 2021 13:34:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241435AbhI1Nfr (ORCPT ); Tue, 28 Sep 2021 09:35:47 -0400 Received: from relay3-d.mail.gandi.net ([217.70.183.195]:46527 "EHLO relay3-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241334AbhI1NfO (ORCPT ); Tue, 28 Sep 2021 09:35:14 -0400 Received: (Authenticated sender: miquel.raynal@bootlin.com) by relay3-d.mail.gandi.net (Postfix) with ESMTPSA id 854B36000F; Tue, 28 Sep 2021 13:33:32 +0000 (UTC) From: Miquel Raynal To: Jonathan Cameron , Lars-Peter Clausen , Lee Jones Cc: Peter Meerwald-Stadler , Rob Herring , Dmitry Torokhov , bcousson@baylibre.com, Tony Lindgren , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-omap@vger.kernel.org, Thomas Petazzoni , Vignesh Raghavendra , Lokesh Vutla , Tero Kristo , Ryan Barnett , Grygorii Strashko , Jason Reeder , , Miquel Raynal , Jonathan Cameron Subject: [PATCH v4 44/48] iio: adc: ti_am335x_adc: Add the scale information Date: Tue, 28 Sep 2021 15:31:39 +0200 Message-Id: <20210928133143.157329-45-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210928133143.157329-1-miquel.raynal@bootlin.com> References: <20210928133143.157329-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org Without the scale, the values returned to the user are just a picture of the input voltage against the full scale range of the ADC. We need to provide the actual conversion factor to get milli-Volts values. Signed-off-by: Miquel Raynal Acked-by: Jonathan Cameron --- drivers/iio/adc/ti_am335x_adc.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/drivers/iio/adc/ti_am335x_adc.c b/drivers/iio/adc/ti_am335x_adc.c index e7dba10b29b4..867690b6c2dd 100644 --- a/drivers/iio/adc/ti_am335x_adc.c +++ b/drivers/iio/adc/ti_am335x_adc.c @@ -417,6 +417,7 @@ static int tiadc_channel_init(struct device *dev, struct iio_dev *indio_dev, chan->indexed = 1; chan->channel = adc_dev->channel_line[i]; chan->info_mask_separate = BIT(IIO_CHAN_INFO_RAW); + chan->info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE); chan->datasheet_name = chan_name_ain[chan->channel]; chan->scan_index = i; chan->scan_type.sign = 'u'; @@ -441,6 +442,23 @@ static int tiadc_read_raw(struct iio_dev *indio_dev, unsigned long timeout; int ret; + switch (mask) { + case IIO_CHAN_INFO_RAW: + break; + case IIO_CHAN_INFO_SCALE: + switch (chan->type) { + case IIO_VOLTAGE: + *val = 1800; + *val2 = chan->scan_type.realbits; + return IIO_VAL_FRACTIONAL_LOG2; + default: + return -EINVAL; + } + break; + default: + return -EINVAL; + } + if (iio_buffer_enabled(indio_dev)) return -EBUSY;