From patchwork Wed May 24 00:01:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: George Stark X-Patchwork-Id: 13253156 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 5D37FC7EE26 for ; Wed, 24 May 2023 00:02:18 +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: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:In-Reply-To:References: List-Owner; bh=1m2J5kukA3w4GF7E78wnhUqkIedLbVorhFSCnKbt7yU=; b=BwgJGRddYAL32x u7Hc0UxgU6DDesjaj8Up8jOTIB0u9yg2GPr9k1VVAwmI1LaPW8zLA3cCY+wfB/R5f0KsLduk7NRJ1 7PHpWgzhXmAacPDIFAnegPvKj4CN3gcOJtnHzS/jwdfaXLtqne6jZCfNzw3RUwZzXXlPsOPAztPec DZ4RMwsurwD88hHgASgCXkB5ZJsQMKHjoBcSDMuHbeT/MxfigHdUaBw8xi52ugx5rY8nA1FltyIdT qwYWkZiivEdtfJQmYp0aj771R3gBKUUXOJevAh+Xn3twv71i+oa2vOBjyHXk46ZaXO98vEDgGe/rG 2d1yyOmiGmka+CCfrCUA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1q1bwv-00BrPU-0t; Wed, 24 May 2023 00:01:53 +0000 Received: from mx.sberdevices.ru ([45.89.227.171]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1q1bwp-00BrOF-1v; Wed, 24 May 2023 00:01:50 +0000 Received: from s-lin-edge02.sberdevices.ru (localhost [127.0.0.1]) by mx.sberdevices.ru (Postfix) with ESMTP id 6B18B5FD03; Wed, 24 May 2023 03:01:39 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sberdevices.ru; s=mail; t=1684886499; bh=axVJ7641uXabYayO/3wTwP3lkBTzWLtoTnUTKuJMnlU=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type; b=N6Dn84VO8YczLUkTXu1/6KwcMcOKfsCHELP7x2SJ4mj8q9TdMGlZEIraS3Mi4DHzB 2Zp4RAVgmCp/ZFW4MaBjMvD3k7PseFKJMtsJXxQdJUBkcutFURW64Fi3uxWqKQUWOS EGWjnerpyp2Od6HiiriocffF3q0chriYYjDKgIvwOLl//DaA+/JO+oB5D0noGvYUfy 4xTT1V28WmZ6YIwo8GZ/K/W5EqOSUcj7z4PfHbiwrcEBDIYD2dIvMfYHiRD3ickzIt PvSobGwPaaxhEbKm8VBkV3CaAaAPpxo2FR/lYMdjxBg72sFgoCtWpaTyP8AgZhgFrH +EB2MFhAkG8eQ== Received: from S-MS-EXCH01.sberdevices.ru (S-MS-EXCH01.sberdevices.ru [172.16.1.4]) by mx.sberdevices.ru (Postfix) with ESMTP; Wed, 24 May 2023 03:01:36 +0300 (MSK) From: George Stark To: , , , , , , , , CC: , , , , , George Stark Subject: [PATCH v1] meson saradc: add iio device attrib to switch channel 7 mux Date: Wed, 24 May 2023 03:01:11 +0300 Message-ID: <20230524000111.14370-1-gnstark@sberdevices.ru> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 X-Originating-IP: [172.16.1.6] X-ClientProxiedBy: S-MS-EXCH02.sberdevices.ru (172.16.1.5) To S-MS-EXCH01.sberdevices.ru (172.16.1.4) 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/05/23 21:43:00 #21378639 X-KSMG-AntiVirus-Status: Clean, skipped X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230523_170148_351257_8AA70080 X-CRM114-Status: GOOD ( 14.39 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Patch adds two sysfs nodes: chan7_mux to set mux state and chan7_mux_available to show available mux states. Mux can be used to debug and calibrate adc by switching and measuring well-known inputs like gnd, vdd etc. Signed-off-by: George Stark --- drivers/iio/adc/meson_saradc.c | 66 ++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/drivers/iio/adc/meson_saradc.c b/drivers/iio/adc/meson_saradc.c index e05e51900c35..77ef2b55f6f4 100644 --- a/drivers/iio/adc/meson_saradc.c +++ b/drivers/iio/adc/meson_saradc.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -320,6 +321,7 @@ struct meson_sar_adc_priv { bool temperature_sensor_calibrated; u8 temperature_sensor_coefficient; u16 temperature_sensor_adc_val; + u8 chan7_mux_sel; }; static const struct regmap_config meson_sar_adc_regmap_config_gxbb = { @@ -483,6 +485,7 @@ static void meson_sar_adc_set_chan7_mux(struct iio_dev *indio_dev, regmap_update_bits(priv->regmap, MESON_SAR_ADC_REG3, MESON_SAR_ADC_REG3_CTRL_CHAN7_MUX_SEL_MASK, regval); + priv->chan7_mux_sel = sel; usleep_range(10, 20); } @@ -1130,8 +1133,71 @@ static int meson_sar_adc_calib(struct iio_dev *indio_dev) return ret; } +static const char * const chan7_vol[] = { + "gnd", + "vdd/4", + "vdd/2", + "vdd*3/4", + "vdd", + "ch7_input", +}; + +static ssize_t chan7_mux_show(struct device *dev, struct device_attribute *attr, + char *buf) +{ + struct iio_dev *indio_dev = dev_to_iio_dev(dev); + struct meson_sar_adc_priv *priv = iio_priv(indio_dev); + unsigned int index = priv->chan7_mux_sel; + + if (index >= ARRAY_SIZE(chan7_vol)) + index = ARRAY_SIZE(chan7_vol) - 1; + + return sysfs_emit(buf, "%s\n", chan7_vol[index]); +} + +static ssize_t chan7_mux_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + struct iio_dev *indio_dev = dev_to_iio_dev(dev); + int i; + + for (i = 0; i < ARRAY_SIZE(chan7_vol); i++) + if (!strcmp(chan7_vol[i], buf)) { + meson_sar_adc_set_chan7_mux(indio_dev, i); + return count; + } + + return -EINVAL; +} + +static ssize_t chan7_mux_available_show(struct device *dev, struct device_attribute *attr, + char *buf) +{ + int i, len = 0; + + for (i = 0; i < ARRAY_SIZE(chan7_vol); i++) + len += sysfs_emit_at(buf, len, "%s ", chan7_vol[i]); + + return len; +} + +static IIO_DEVICE_ATTR_RW(chan7_mux, -1); +static IIO_DEVICE_ATTR_RO(chan7_mux_available, -1); + +static struct attribute *meson_sar_adc_attrs[] = { + &iio_dev_attr_chan7_mux_available.dev_attr.attr, + &iio_dev_attr_chan7_mux.dev_attr.attr, + NULL, +}; + +static const struct attribute_group meson_sar_adc_attr_group = { + .attrs = meson_sar_adc_attrs, +}; + static const struct iio_info meson_sar_adc_iio_info = { .read_raw = meson_sar_adc_iio_info_read_raw, + .attrs = &meson_sar_adc_attr_group, }; static const struct meson_sar_adc_param meson_sar_adc_meson8_param = {