From patchwork Wed Jun 21 06:26:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: George Stark X-Patchwork-Id: 13286710 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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 62B82EB64DD for ; Wed, 21 Jun 2023 06:28:06 +0000 (UTC) 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:Date:Subject:CC:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=AjxOcTBfr00BooFD5PoP27/p62oFZh4KAvm1wAP3Qys=; b=JOQUfZtGVywIw6 JOFG90CqNXuuxlOLsB0cbd6EfbHN6ANcfn/hpjqia8iHufiBOnp8WwXBFfgYqKtIMnOSaNE+8bJH8 g/bYWBtMW7E30PNIkclc1aWIdacVw5gK94gjQ4yr8QSlOJ8gkHoNMvPK1xfmXaEzFllu7tlQuyLRx 7SaHpJaVinQJ5bHY63NQf+4sBGYjZg1uR2Q4LDpbsTpA4xsVncR2YOeW56Uc5uLshRSzLaNihoBRZ LUgkLQ45bphdOUu42Z2q9xXSH5DD3VWxk5YQ5q/D6Pqn8uB1480RKI7yOtgsl1QGFaCQ3vWiwwbWU J4jrfGIyY4qT/fXAv3UQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qBrJg-00DPj0-0P; Wed, 21 Jun 2023 06:27:44 +0000 Received: from mx.sberdevices.ru ([45.89.227.171]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qBrJa-00DPgk-1Q; Wed, 21 Jun 2023 06:27:42 +0000 Received: from s-lin-edge02.sberdevices.ru (localhost [127.0.0.1]) by mx.sberdevices.ru (Postfix) with ESMTP id 1E9B35FD5F; Wed, 21 Jun 2023 09:27:35 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sberdevices.ru; s=mail; t=1687328855; bh=1HCYzQCWt+fRi1jUgBj1XLHgZN68PTMiptoPlI6IIWk=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type; b=PMlBL9RC8nMPIi5Kr5U9w97+BUgNfviyi54qKXXimeW+pRY/sFgGmqO9f/8ysXWcB VC9oGlrxC0B7K4DPMg4hfQwINDjCnAvFNWJwpOIXoYDCXtl6qoJoJWW7QkYXPFAg2Q scDZNVCQzNTnaY08NI5wuRFFJ7BNHeuWJsgpbMMeL/osJdzXwQ84hiYTcxHbaUsIcz 2IwHetI79PUWQQ+nYFN09uyYpqvfFKDLZplHQVkbFXNnk4fLfwNIMk1YqxBYThirYz oJxy+V6706Bbt+KJJ/StoiTw0kKJ8OoZtWgXPVx7/zhyNjE6XXYN5BuqXXr7WIOubp WriTf1lvp5VtA== Received: from p-i-exch-sc-m01.sberdevices.ru (p-i-exch-sc-m01.sberdevices.ru [172.16.192.107]) by mx.sberdevices.ru (Postfix) with ESMTP; Wed, 21 Jun 2023 09:27:34 +0300 (MSK) From: George Stark To: , , , , , , , , CC: , , , , , George Stark Subject: [PATCH v1 1/3] meson saradc: code refactoring Date: Wed, 21 Jun 2023 09:26:08 +0300 Message-ID: <20230621062715.455652-2-gnstark@sberdevices.ru> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230621062715.455652-1-gnstark@sberdevices.ru> References: <20230621062715.455652-1-gnstark@sberdevices.ru> MIME-Version: 1.0 X-Originating-IP: [100.64.160.123] X-ClientProxiedBy: p-i-exch-sc-m01.sberdevices.ru (172.16.192.107) To p-i-exch-sc-m01.sberdevices.ru (172.16.192.107) X-KSMG-Rule-ID: 4 X-KSMG-Message-Action: clean X-KSMG-AntiSpam-Status: not scanned, disabled by settings X-KSMG-AntiSpam-Interceptor-Info: not scanned X-KSMG-AntiPhishing: not scanned, disabled by settings X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 1.1.2.30, bases: 2023/06/20 23:30:00 #21539802 X-KSMG-AntiVirus-Status: Clean, skipped X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230620_232738_993732_48B88975 X-CRM114-Status: GOOD ( 13.53 ) X-BeenThere: linux-amlogic@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-amlogic" Errors-To: linux-amlogic-bounces+linux-amlogic=archiver.kernel.org@lists.infradead.org - remove channel array double definition - add channel index enum - move enums declaration before variables declaration - move meson_sar_adc_set_chan7_mux routine upper Signed-off-by: George Stark --- drivers/iio/adc/meson_saradc.c | 97 ++++++++++++++++------------------ 1 file changed, 46 insertions(+), 51 deletions(-) diff --git a/drivers/iio/adc/meson_saradc.c b/drivers/iio/adc/meson_saradc.c index 18937a262af6..42f0389e123d 100644 --- a/drivers/iio/adc/meson_saradc.c +++ b/drivers/iio/adc/meson_saradc.c @@ -189,9 +189,8 @@ .datasheet_name = "SAR_ADC_CH"#_chan, \ } -#define MESON_SAR_ADC_TEMP_CHAN(_chan) { \ +#define MESON_SAR_ADC_TEMP_CHAN() { \ .type = IIO_TEMP, \ - .channel = _chan, \ .address = MESON_SAR_ADC_VOLTAGE_AND_TEMP_CHANNEL, \ .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ BIT(IIO_CHAN_INFO_AVERAGE_RAW), \ @@ -202,31 +201,6 @@ .datasheet_name = "TEMP_SENSOR", \ } -static const struct iio_chan_spec meson_sar_adc_iio_channels[] = { - MESON_SAR_ADC_CHAN(0), - MESON_SAR_ADC_CHAN(1), - MESON_SAR_ADC_CHAN(2), - MESON_SAR_ADC_CHAN(3), - MESON_SAR_ADC_CHAN(4), - MESON_SAR_ADC_CHAN(5), - MESON_SAR_ADC_CHAN(6), - MESON_SAR_ADC_CHAN(7), - IIO_CHAN_SOFT_TIMESTAMP(8), -}; - -static const struct iio_chan_spec meson_sar_adc_and_temp_iio_channels[] = { - MESON_SAR_ADC_CHAN(0), - MESON_SAR_ADC_CHAN(1), - MESON_SAR_ADC_CHAN(2), - MESON_SAR_ADC_CHAN(3), - MESON_SAR_ADC_CHAN(4), - MESON_SAR_ADC_CHAN(5), - MESON_SAR_ADC_CHAN(6), - MESON_SAR_ADC_CHAN(7), - MESON_SAR_ADC_TEMP_CHAN(8), - IIO_CHAN_SOFT_TIMESTAMP(9), -}; - enum meson_sar_adc_avg_mode { NO_AVERAGING = 0x0, MEAN_AVERAGING = 0x1, @@ -249,6 +223,31 @@ enum meson_sar_adc_chan7_mux_sel { CHAN7_MUX_CH7_INPUT = 0x7, }; +enum meson_sar_adc_channel_index { + INDEX_CHAN_0, + INDEX_CHAN_1, + INDEX_CHAN_2, + INDEX_CHAN_3, + INDEX_CHAN_4, + INDEX_CHAN_5, + INDEX_CHAN_6, + INDEX_CHAN_7, + INDEX_CHAN_SOFT_TIMESTAMP, +}; + +static const struct iio_chan_spec meson_sar_adc_iio_channels[] = { + MESON_SAR_ADC_CHAN(INDEX_CHAN_0), + MESON_SAR_ADC_CHAN(INDEX_CHAN_1), + MESON_SAR_ADC_CHAN(INDEX_CHAN_2), + MESON_SAR_ADC_CHAN(INDEX_CHAN_3), + MESON_SAR_ADC_CHAN(INDEX_CHAN_4), + MESON_SAR_ADC_CHAN(INDEX_CHAN_5), + MESON_SAR_ADC_CHAN(INDEX_CHAN_6), + MESON_SAR_ADC_CHAN(INDEX_CHAN_7), + IIO_CHAN_SOFT_TIMESTAMP(INDEX_CHAN_SOFT_TIMESTAMP), + MESON_SAR_ADC_TEMP_CHAN(), /* must be the last item */ +}; + struct meson_sar_adc_param { bool has_bl30_integration; unsigned long clock_rate; @@ -338,6 +337,19 @@ static int meson_sar_adc_wait_busy_clear(struct iio_dev *indio_dev) 1, 10000); } +static void meson_sar_adc_set_chan7_mux(struct iio_dev *indio_dev, + enum meson_sar_adc_chan7_mux_sel sel) +{ + struct meson_sar_adc_priv *priv = iio_priv(indio_dev); + u32 regval; + + regval = FIELD_PREP(MESON_SAR_ADC_REG3_CTRL_CHAN7_MUX_SEL_MASK, sel); + regmap_update_bits(priv->regmap, MESON_SAR_ADC_REG3, + MESON_SAR_ADC_REG3_CTRL_CHAN7_MUX_SEL_MASK, regval); + + usleep_range(10, 20); +} + static int meson_sar_adc_read_raw_sample(struct iio_dev *indio_dev, const struct iio_chan_spec *chan, int *val) @@ -434,19 +446,6 @@ static void meson_sar_adc_enable_channel(struct iio_dev *indio_dev, } } -static void meson_sar_adc_set_chan7_mux(struct iio_dev *indio_dev, - enum meson_sar_adc_chan7_mux_sel sel) -{ - struct meson_sar_adc_priv *priv = iio_priv(indio_dev); - u32 regval; - - regval = FIELD_PREP(MESON_SAR_ADC_REG3_CTRL_CHAN7_MUX_SEL_MASK, sel); - regmap_update_bits(priv->regmap, MESON_SAR_ADC_REG3, - MESON_SAR_ADC_REG3_CTRL_CHAN7_MUX_SEL_MASK, regval); - - usleep_range(10, 20); -} - static void meson_sar_adc_start_sample_engine(struct iio_dev *indio_dev) { struct meson_sar_adc_priv *priv = iio_priv(indio_dev); @@ -1016,7 +1015,7 @@ static int meson_sar_adc_calib(struct iio_dev *indio_dev) meson_sar_adc_set_chan7_mux(indio_dev, CHAN7_MUX_VDD_DIV4); usleep_range(10, 20); ret = meson_sar_adc_get_sample(indio_dev, - &indio_dev->channels[7], + &indio_dev->channels[INDEX_CHAN_7], MEAN_AVERAGING, EIGHT_SAMPLES, &value0); if (ret < 0) goto out; @@ -1024,7 +1023,7 @@ static int meson_sar_adc_calib(struct iio_dev *indio_dev) meson_sar_adc_set_chan7_mux(indio_dev, CHAN7_MUX_VDD_MUL3_DIV4); usleep_range(10, 20); ret = meson_sar_adc_get_sample(indio_dev, - &indio_dev->channels[7], + &indio_dev->channels[INDEX_CHAN_7], MEAN_AVERAGING, EIGHT_SAMPLES, &value1); if (ret < 0) goto out; @@ -1242,15 +1241,11 @@ static int meson_sar_adc_probe(struct platform_device *pdev) return ret; } - if (priv->temperature_sensor_calibrated) { - indio_dev->channels = meson_sar_adc_and_temp_iio_channels; - indio_dev->num_channels = - ARRAY_SIZE(meson_sar_adc_and_temp_iio_channels); - } else { - indio_dev->channels = meson_sar_adc_iio_channels; - indio_dev->num_channels = - ARRAY_SIZE(meson_sar_adc_iio_channels); - } + indio_dev->channels = meson_sar_adc_iio_channels; + indio_dev->num_channels = ARRAY_SIZE(meson_sar_adc_iio_channels); + // last item is temp channel + if (!priv->temperature_sensor_calibrated) + indio_dev->num_channels--; ret = meson_sar_adc_init(indio_dev); if (ret) From patchwork Wed Jun 21 06:26:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: George Stark X-Patchwork-Id: 13286711 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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 1999CEB64D7 for ; Wed, 21 Jun 2023 06:28:08 +0000 (UTC) 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:Date:Subject:CC:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=RAcEd9ZJqHL9h5IuKJ7jVC87x5BQk+Qmx47r/jIQ5eA=; b=kkB8LYPAAxFCzY e0tszVOSAOIYSsbzUcMkvYva4xxsMwRjLHCgExG6/Q3a0lFdRHGjh/ZxN0b6JbFJmVi5xCDVi5xN6 S7h1yDgOeBVnfx04iSYZ0YPTr0beeO0MXYEjK7fgT3a/awLni/cw6zGOeANGdDK2YVQ3BS4WgwTgU cTKg4tE4LNC2vn9Uu0e/LQt4/EpSFhdw4kBivU6+lEeao72YkGhnuYYOQMTDsXTmoYr8KDWmfmb5m QJqk1JS6dsrYivu+LQk2oCIYBV/yUL6aVt6KInyL6AL2Nx4fsKqUJTJOS2OajQUdBABL1g2QLyuvP Rg+EyES7dNC2QFiK5iiA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qBrJj-00DPkY-1n; Wed, 21 Jun 2023 06:27:47 +0000 Received: from mx.sberdevices.ru ([45.89.227.171]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qBrJa-00DPh2-2r; Wed, 21 Jun 2023 06:27:43 +0000 Received: from s-lin-edge02.sberdevices.ru (localhost [127.0.0.1]) by mx.sberdevices.ru (Postfix) with ESMTP id C4C645FD60; Wed, 21 Jun 2023 09:27:35 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sberdevices.ru; s=mail; t=1687328855; bh=YQ2V6XFLUgswbRr9qW2w1qbMLzV+8NemKwLTVnCTW20=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type; b=P0RFbgc1pyUJ+agr3Fgq7ek7/svzYSn2J7N/OS6uTcZg3B2a3hwDtBp3UxcU8q6C/ l9pVg5ImyYIR9AAxNXQXS52aA+jUJdlXNTYIZBOtshfy00OCyYV4EdqmHBkW/G3Swy IukM5IA8dgn1ha9uNv8TsLQ2RHNYvG+CnaDCe67Aqe6XzFvoqnwweXrd/KDLccrrv1 l8WPnwsu/9F9vQMyukKr0DfRSSZFL12ixfY8TTAHdEt7GxfowuUmjuH7/vHQoRki59 kLrG/ffRzaJEwQm0zAhP7YWY3rSEpmd5+6P1UvHswnO+gD3xszicSOy1ZB+NBVDjre vuVpuXmi3CRmA== Received: from p-i-exch-sc-m01.sberdevices.ru (p-i-exch-sc-m01.sberdevices.ru [172.16.192.107]) by mx.sberdevices.ru (Postfix) with ESMTP; Wed, 21 Jun 2023 09:27:35 +0300 (MSK) From: George Stark To: , , , , , , , , CC: , , , , , George Stark Subject: [PATCH v1 2/3] meson saradc: add channel labels Date: Wed, 21 Jun 2023 09:26:09 +0300 Message-ID: <20230621062715.455652-3-gnstark@sberdevices.ru> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230621062715.455652-1-gnstark@sberdevices.ru> References: <20230621062715.455652-1-gnstark@sberdevices.ru> MIME-Version: 1.0 X-Originating-IP: [100.64.160.123] X-ClientProxiedBy: p-i-exch-sc-m01.sberdevices.ru (172.16.192.107) To p-i-exch-sc-m01.sberdevices.ru (172.16.192.107) X-KSMG-Rule-ID: 4 X-KSMG-Message-Action: clean X-KSMG-AntiSpam-Status: not scanned, disabled by settings X-KSMG-AntiSpam-Interceptor-Info: not scanned X-KSMG-AntiPhishing: not scanned, disabled by settings X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 1.1.2.30, bases: 2023/06/20 23:30:00 #21539802 X-KSMG-AntiVirus-Status: Clean, skipped X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230620_232739_119998_CE52CFEE X-CRM114-Status: UNSURE ( 9.24 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-amlogic@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-amlogic" Errors-To: linux-amlogic-bounces+linux-amlogic=archiver.kernel.org@lists.infradead.org patch adds channel attribute 'label' with channel name Signed-off-by: George Stark --- drivers/iio/adc/meson_saradc.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/iio/adc/meson_saradc.c b/drivers/iio/adc/meson_saradc.c index 42f0389e123d..66d6f527122c 100644 --- a/drivers/iio/adc/meson_saradc.c +++ b/drivers/iio/adc/meson_saradc.c @@ -1044,8 +1044,20 @@ static int meson_sar_adc_calib(struct iio_dev *indio_dev) return ret; } +static int read_label(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + char *label) +{ + if (chan->type == IIO_TEMP) + return sprintf(label, "%s\n", "temp-sensor"); + if (chan->type == IIO_VOLTAGE) + return sprintf(label, "channel-%d\n", chan->channel); + return 0; +} + static const struct iio_info meson_sar_adc_iio_info = { .read_raw = meson_sar_adc_iio_info_read_raw, + .read_label = read_label, }; static const struct meson_sar_adc_param meson_sar_adc_meson8_param = { From patchwork Wed Jun 21 06:26:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: George Stark X-Patchwork-Id: 13286712 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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 36292EB64DC for ; Wed, 21 Jun 2023 06:28:21 +0000 (UTC) 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:Date:Subject:CC:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=RYbW+x21uNU4ci9ZkzPwVRCSXEhg20kqhJ9UgT1JTLI=; b=ARTh926gwO3hQy J6MZ/5q2lCJhY8Mokym2OGaqnFqJR4SMZDgxyU/zWXwqj8/PCkIdjfLwsRk0RIOkf3qRShJmCPL9P UQmj8taQj3lLKTpNmHnC0qMrs85kk6vKauqE8e22CXES/kQ411mryFQcFHNLHsE+zKH6I3BcQgFmv 5m3VFKgZ3SNbUY2ZhpR6rqn7vd88JhElZaYOV8U475/0wUllC4Itzid1qnM4GMWogJvDUUT9Sc3i+ jIIPRzQ7WpTezMhB1pFVIhJ4la/Qg7qYrMa0QJ9vSd4TwwuTL4ZrD0F1X8SjriXwtXddv+w/XYAFa 3vwcy474oyr+w/O/nQzQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qBrJw-00DPp3-08; Wed, 21 Jun 2023 06:28:00 +0000 Received: from mx.sberdevices.ru ([45.89.227.171]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qBrJb-00DPh5-1v; Wed, 21 Jun 2023 06:27:43 +0000 Received: from s-lin-edge02.sberdevices.ru (localhost [127.0.0.1]) by mx.sberdevices.ru (Postfix) with ESMTP id 851195FD61; Wed, 21 Jun 2023 09:27:36 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sberdevices.ru; s=mail; t=1687328856; bh=iYMidsTDXcTCWyifw1vWsk3ddCRuBC/523lS3FYIPhA=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type; b=d91jAQnp+1oOd7EG36ECRbKu2NluxoeVSEEiTUd+3ULMtQv2z3CSczX/CHzaCeLhF XDHWa9jh8ooov05wqJE2FPhTyVl9fZXyAoSwZOLkntZBr7H0V8Q3B0FIghnZQTIU30 eTP4UJpzwSvbsES98TfHRxOR4sTRhatLEWh5+QQwCOhQao9qvd+XNzOoikgn48pYdm /qTyR8V9GOqkVEvS45goJtDNIzoRUL5ZIeXS5t8qH2yoWqQuCFlW1Hk8M78wfRJxyp rC0GkQiqWJUvEcOvIk1VM/GNGl9g3oQBxaY1fjo5wkpubxch1GqrgJ6qCmC/qyu8Zy Clvf2m+/oSxuQ== Received: from p-i-exch-sc-m01.sberdevices.ru (p-i-exch-sc-m01.sberdevices.ru [172.16.192.107]) by mx.sberdevices.ru (Postfix) with ESMTP; Wed, 21 Jun 2023 09:27:36 +0300 (MSK) From: George Stark To: , , , , , , , , CC: , , , , , George Stark Subject: [PATCH v1 3/3] meson saradc: support reading from channel7 mux inputs Date: Wed, 21 Jun 2023 09:26:10 +0300 Message-ID: <20230621062715.455652-4-gnstark@sberdevices.ru> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230621062715.455652-1-gnstark@sberdevices.ru> References: <20230621062715.455652-1-gnstark@sberdevices.ru> MIME-Version: 1.0 X-Originating-IP: [100.64.160.123] X-ClientProxiedBy: p-i-exch-sc-m01.sberdevices.ru (172.16.192.107) To p-i-exch-sc-m01.sberdevices.ru (172.16.192.107) X-KSMG-Rule-ID: 4 X-KSMG-Message-Action: clean X-KSMG-AntiSpam-Status: not scanned, disabled by settings X-KSMG-AntiSpam-Interceptor-Info: not scanned X-KSMG-AntiPhishing: not scanned, disabled by settings X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 1.1.2.30, bases: 2023/06/20 23:30:00 #21539802 X-KSMG-AntiVirus-Status: Clean, skipped X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230620_232739_998133_5FDEBC8E X-CRM114-Status: GOOD ( 15.73 ) X-BeenThere: linux-amlogic@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-amlogic" Errors-To: linux-amlogic-bounces+linux-amlogic=archiver.kernel.org@lists.infradead.org meson saradc channel 7 is connected to muxer that can switch channel input to well-known sources like Vdd, GND and several Vdd dividers. This patch adds iio channel for every mux input. Signed-off-by: George Stark --- drivers/iio/adc/meson_saradc.c | 65 +++++++++++++++++++++++++++++++--- 1 file changed, 61 insertions(+), 4 deletions(-) diff --git a/drivers/iio/adc/meson_saradc.c b/drivers/iio/adc/meson_saradc.c index 66d6f527122c..c4f350b4523e 100644 --- a/drivers/iio/adc/meson_saradc.c +++ b/drivers/iio/adc/meson_saradc.c @@ -163,6 +163,7 @@ #define MESON_SAR_ADC_MAX_FIFO_SIZE 32 #define MESON_SAR_ADC_TIMEOUT 100 /* ms */ #define MESON_SAR_ADC_VOLTAGE_AND_TEMP_CHANNEL 6 +#define MESON_SAR_ADC_VOLTAGE_AND_MUX_CHANNEL 7 #define MESON_SAR_ADC_TEMP_OFFSET 27 /* temperature sensor calibration information in eFuse */ @@ -201,6 +202,19 @@ .datasheet_name = "TEMP_SENSOR", \ } +#define MESON_SAR_ADC_MUX(_chan, _sel) { \ + .type = IIO_VOLTAGE, \ + .channel = _chan, \ + .indexed = 1, \ + .address = MESON_SAR_ADC_VOLTAGE_AND_MUX_CHANNEL, \ + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ + BIT(IIO_CHAN_INFO_AVERAGE_RAW), \ + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ + .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_CALIBBIAS) | \ + BIT(IIO_CHAN_INFO_CALIBSCALE), \ + .datasheet_name = "SAR_ADC_MUX_"#_sel, \ +} + enum meson_sar_adc_avg_mode { NO_AVERAGING = 0x0, MEAN_AVERAGING = 0x1, @@ -233,6 +247,27 @@ enum meson_sar_adc_channel_index { INDEX_CHAN_6, INDEX_CHAN_7, INDEX_CHAN_SOFT_TIMESTAMP, + INDEX_MUX_0_VSS, + INDEX_MUX_1_VDD_DIV4, + INDEX_MUX_2_VDD_DIV2, + INDEX_MUX_3_VDD_MUL3_DIV4, + INDEX_MUX_4_VDD, +}; + +static enum meson_sar_adc_chan7_mux_sel chan7_mux_values[] = { + CHAN7_MUX_VSS, + CHAN7_MUX_VDD_DIV4, + CHAN7_MUX_VDD_DIV2, + CHAN7_MUX_VDD_MUL3_DIV4, + CHAN7_MUX_VDD, +}; + +static const char * const chan7_mux_names[] = { + "gnd", + "0.25vdd", + "0.5vdd", + "0.75vdd", + "vdd", }; static const struct iio_chan_spec meson_sar_adc_iio_channels[] = { @@ -245,6 +280,11 @@ static const struct iio_chan_spec meson_sar_adc_iio_channels[] = { MESON_SAR_ADC_CHAN(INDEX_CHAN_6), MESON_SAR_ADC_CHAN(INDEX_CHAN_7), IIO_CHAN_SOFT_TIMESTAMP(INDEX_CHAN_SOFT_TIMESTAMP), + MESON_SAR_ADC_MUX(INDEX_MUX_0_VSS, 0), + MESON_SAR_ADC_MUX(INDEX_MUX_1_VDD_DIV4, 1), + MESON_SAR_ADC_MUX(INDEX_MUX_2_VDD_DIV2, 2), + MESON_SAR_ADC_MUX(INDEX_MUX_3_VDD_MUL3_DIV4, 3), + MESON_SAR_ADC_MUX(INDEX_MUX_4_VDD, 4), MESON_SAR_ADC_TEMP_CHAN(), /* must be the last item */ }; @@ -284,6 +324,7 @@ struct meson_sar_adc_priv { bool temperature_sensor_calibrated; u8 temperature_sensor_coefficient; u16 temperature_sensor_adc_val; + enum meson_sar_adc_chan7_mux_sel chan7_mux_sel; }; static const struct regmap_config meson_sar_adc_regmap_config_gxbb = { @@ -348,6 +389,8 @@ static void meson_sar_adc_set_chan7_mux(struct iio_dev *indio_dev, MESON_SAR_ADC_REG3_CTRL_CHAN7_MUX_SEL_MASK, regval); usleep_range(10, 20); + + priv->chan7_mux_sel = sel; } static int meson_sar_adc_read_raw_sample(struct iio_dev *indio_dev, @@ -443,6 +486,15 @@ static void meson_sar_adc_enable_channel(struct iio_dev *indio_dev, regmap_update_bits(priv->regmap, MESON_SAR_ADC_DELTA_10, MESON_SAR_ADC_DELTA_10_TEMP_SEL, regval); + } else if (chan->address == MESON_SAR_ADC_VOLTAGE_AND_MUX_CHANNEL) { + enum meson_sar_adc_chan7_mux_sel sel; + + if (chan->channel == INDEX_CHAN_7) + sel = CHAN7_MUX_CH7_INPUT; + else + sel = chan7_mux_values[chan->channel - INDEX_MUX_0_VSS]; + if (sel != priv->chan7_mux_sel) + meson_sar_adc_set_chan7_mux(indio_dev, sel); } } @@ -1015,7 +1067,7 @@ static int meson_sar_adc_calib(struct iio_dev *indio_dev) meson_sar_adc_set_chan7_mux(indio_dev, CHAN7_MUX_VDD_DIV4); usleep_range(10, 20); ret = meson_sar_adc_get_sample(indio_dev, - &indio_dev->channels[INDEX_CHAN_7], + &indio_dev->channels[INDEX_MUX_1_VDD_DIV4], MEAN_AVERAGING, EIGHT_SAMPLES, &value0); if (ret < 0) goto out; @@ -1023,7 +1075,7 @@ static int meson_sar_adc_calib(struct iio_dev *indio_dev) meson_sar_adc_set_chan7_mux(indio_dev, CHAN7_MUX_VDD_MUL3_DIV4); usleep_range(10, 20); ret = meson_sar_adc_get_sample(indio_dev, - &indio_dev->channels[INDEX_CHAN_7], + &indio_dev->channels[INDEX_MUX_3_VDD_MUL3_DIV4], MEAN_AVERAGING, EIGHT_SAMPLES, &value1); if (ret < 0) goto out; @@ -1050,8 +1102,13 @@ static int read_label(struct iio_dev *indio_dev, { if (chan->type == IIO_TEMP) return sprintf(label, "%s\n", "temp-sensor"); - if (chan->type == IIO_VOLTAGE) - return sprintf(label, "channel-%d\n", chan->channel); + if (chan->type == IIO_VOLTAGE) { + if (chan->channel <= INDEX_CHAN_7) + return sprintf(label, "channel-%d\n", chan->channel); + if (chan->channel >= INDEX_MUX_0_VSS) + return sprintf(label, "%s\n", + chan7_mux_names[chan->channel - INDEX_MUX_0_VSS]); + } return 0; }