From patchwork Thu Aug 12 02:23:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hui Liu X-Patchwork-Id: 496796 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=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, UNPARSEABLE_RELAY, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham 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 94EA2C432BE for ; Thu, 12 Aug 2021 02:24:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6C9C76109F for ; Thu, 12 Aug 2021 02:24:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233436AbhHLCYp (ORCPT ); Wed, 11 Aug 2021 22:24:45 -0400 Received: from mailgw02.mediatek.com ([210.61.82.184]:49086 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S230035AbhHLCYp (ORCPT ); Wed, 11 Aug 2021 22:24:45 -0400 X-UUID: dff4adfb4c0a4c4e9e72d73158659c83-20210812 X-UUID: dff4adfb4c0a4c4e9e72d73158659c83-20210812 Received: from mtkmbs10n1.mediatek.inc [(172.21.101.34)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 751955085; Thu, 12 Aug 2021 10:24:17 +0800 Received: from mtkcas07.mediatek.inc (172.21.101.84) by mtkmbs07n2.mediatek.inc (172.21.101.141) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 12 Aug 2021 10:24:16 +0800 Received: from localhost.localdomain (10.17.3.153) by mtkcas07.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Thu, 12 Aug 2021 10:24:15 +0800 From: Hui Liu To: , , , CC: , , , , , , , , , , , , Subject: [PATCH 1/2] iio: mtk-auxadc: add support IIO_CHAN_INFO_RAW case Date: Thu, 12 Aug 2021 10:23:41 +0800 Message-ID: <20210812022342.29092-1-hui.liu@mediatek.com> X-Mailer: git-send-email 2.18.0 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Add support IIO_CHAN_INFO_RAW case. Signed-off-by: Hui Liu --- drivers/iio/adc/mt6577_auxadc.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/drivers/iio/adc/mt6577_auxadc.c b/drivers/iio/adc/mt6577_auxadc.c index 79c1dd68b909..e995d43287b2 100644 --- a/drivers/iio/adc/mt6577_auxadc.c +++ b/drivers/iio/adc/mt6577_auxadc.c @@ -60,7 +60,8 @@ static const struct mtk_auxadc_compatible mt6765_compat = { .type = IIO_VOLTAGE, \ .indexed = 1, \ .channel = (idx), \ - .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED), \ + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ + BIT(IIO_CHAN_INFO_PROCESSED), \ } static const struct iio_chan_spec mt6577_auxadc_iio_channels[] = { @@ -181,6 +182,19 @@ static int mt6577_auxadc_read_raw(struct iio_dev *indio_dev, struct mt6577_auxadc_device *adc_dev = iio_priv(indio_dev); switch (info) { + case IIO_CHAN_INFO_RAW: + *val = mt6577_auxadc_read(indio_dev, chan); + if (*val < 0) { + dev_notice(indio_dev->dev.parent, + "failed to sample data on channel[%d]\n", + chan->channel); + return *val; + } + if (adc_dev->dev_comp->sample_data_cali) + *val = mt_auxadc_get_cali_data(*val, true); + + return IIO_VAL_INT; + case IIO_CHAN_INFO_PROCESSED: *val = mt6577_auxadc_read(indio_dev, chan); if (*val < 0) { From patchwork Thu Aug 12 02:23:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hui Liu X-Patchwork-Id: 496216 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=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, UNPARSEABLE_RELAY, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham 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 DB75CC43214 for ; Thu, 12 Aug 2021 02:24:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A800760551 for ; Thu, 12 Aug 2021 02:24:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233549AbhHLCYq (ORCPT ); Wed, 11 Aug 2021 22:24:46 -0400 Received: from mailgw01.mediatek.com ([60.244.123.138]:56084 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S229729AbhHLCYp (ORCPT ); Wed, 11 Aug 2021 22:24:45 -0400 X-UUID: fec819cb61bf4a4bb39af694e654bd07-20210812 X-UUID: fec819cb61bf4a4bb39af694e654bd07-20210812 Received: from mtkcas10.mediatek.inc [(172.21.101.39)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 998655441; Thu, 12 Aug 2021 10:24:18 +0800 Received: from mtkcas07.mediatek.inc (172.21.101.84) by mtkmbs07n1.mediatek.inc (172.21.101.16) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 12 Aug 2021 10:24:17 +0800 Received: from localhost.localdomain (10.17.3.153) by mtkcas07.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Thu, 12 Aug 2021 10:24:16 +0800 From: Hui Liu To: , , , CC: , , , , , , , , , , , , Subject: [PATCH 2/2] iio: mtk-auxadc: update case IIO_CHAN_INFO_PROCESSED Date: Thu, 12 Aug 2021 10:23:42 +0800 Message-ID: <20210812022342.29092-2-hui.liu@mediatek.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20210812022342.29092-1-hui.liu@mediatek.com> References: <20210812022342.29092-1-hui.liu@mediatek.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Covert raw data to processed data. Signed-off-by: Hui Liu --- 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 e995d43287b2..cda03a653269 100644 --- a/drivers/iio/adc/mt6577_auxadc.c +++ b/drivers/iio/adc/mt6577_auxadc.c @@ -83,6 +83,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; @@ -205,6 +209,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: