Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp446695rdb; Sat, 30 Sep 2023 10:33:03 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGmyg1AUfkGWD/kUHm0AfnmaTSpiG4IDn935P3brvHBE5iP9Fue+0euRo7uNUoBjdOTmOhv X-Received: by 2002:a05:6870:8320:b0:1dc:bccf:b840 with SMTP id p32-20020a056870832000b001dcbccfb840mr8858725oae.32.1696095183149; Sat, 30 Sep 2023 10:33:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696095183; cv=none; d=google.com; s=arc-20160816; b=A0/L90cAb6oYSy2vf4/W5gzVXUB/zs5CLBvsAqzKSWEKV1qlwKY4Ylh/+iUeSmSDj3 p8Dx60WN5ai9lqt/vf6ksdRqNwWX7srCgLKFKsjJHt0qe+uHyoLaeldQ8HOCq4O5n5Oa IcurcdujYPYPE7kdB7fZIsO3rc++fEMNA5FSM2867rymAPP+swtGgU5XLnjqYYoCQDgU gO/u5qt80/j5RBsKWRgJ5uyvdF+zEmzSwMI7WPnWEQeW27joNgScUs1+y9OX8pkzRswx AhP8YJFjbJf5YJKcPjW9CqBn2S1kxVdh1xiYjlBnmvbv6/EvqA6Kj7a8BVbbv0VAll8H qc3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=9Uy+cct46YpBFyZK+4i5ezZjhwMLVP1dYwTKEwa8mEw=; fh=0d5sezX/0QEMwMe4Rh/O7Y9fI2w/ljJ6FD1mr3Pq0xg=; b=lEIsRVjPEFNNlDFtYZyWGCtFpusBYpsrRXbuho+3/JLoVeJzsQRS85B9cxMG5z2gCS ehfKqXfxfyaexUiQDevr0POKdv8rEWnhvT1eHUEspH9Ylr34+7hK8iu+Tk71mFhPJEXZ ZpOsRZP7Qvwisk6CJHDst6ITzRwoK2qVnufG19QDn/mQ9kemNall7gX9DOByln80xPsN wMkePYyRZKYQb/E5Usn5KKd04PE6nEinnEHQEcWuiqVp14RBpQE27/u4HQUA62gPqqqU j6xp4xmCvTdeJat2Ml7rqaMZjYBAFK2bW6uwk4gyEWugjj0j+hcF4/sBAgn775MH9lcu VuBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=gkG9Zrhk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id l9-20020a654c49000000b0055785a37147si24357080pgr.590.2023.09.30.10.33.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Sep 2023 10:33:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=gkG9Zrhk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id A145380A8502; Sat, 30 Sep 2023 10:31:47 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234674AbjI3Rbg (ORCPT + 99 others); Sat, 30 Sep 2023 13:31:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50396 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233050AbjI3Rbf (ORCPT ); Sat, 30 Sep 2023 13:31:35 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2D99CE1; Sat, 30 Sep 2023 10:31:33 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2A2B8C433C7; Sat, 30 Sep 2023 17:31:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1696095092; bh=OIF3qTZzv4fmyLYYTtHMwTXoCRzHXWoRyRsQrWSbiao=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=gkG9ZrhksFsGZc9fwu+4MOLSw66E3EDZoVAihz5wLqZF2LnFUvtM+GNMIQe7p0vuJ L3lAtYDPJhKOeFapkxQk1kRVNCgCa9+y4QHMIiV0lxfN7nFuUYa4sDqk3izN0Y281U uXp5O9RwViNq4rbAaco51QsJdbKU1LENvkUjjahqAo7LVZGFaRL7iuLVTrBmCD7Vxx Tg1KCd/5MhWuJLuO2jLfGeTKpXkK+Rerh8v6b4gJkkb1U1diZNi03XjJSKE8s2BBK0 vKxTrmBTE0NMeePVI5zjKpYFMEl3vsM1+f90b5ag7JYxhilyN5M1C1FGSYKCYK4dI2 9mnvSIH9XJ8Cw== Date: Sat, 30 Sep 2023 18:31:33 +0100 From: Jonathan Cameron To: alisadariana@gmail.com Cc: Alisa-Dariana Roman , Lars-Peter Clausen , Alexandru Tachici , Michael Hennerich , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3 3/3] iio: adc: ad7192: Add fast settling support Message-ID: <20230930183117.45d311ed@jic23-huawei> In-Reply-To: <20230924215148.102491-4-alisadariana@gmail.com> References: <20230924215148.102491-1-alisadariana@gmail.com> <20230924215148.102491-4-alisadariana@gmail.com> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Sat, 30 Sep 2023 10:31:47 -0700 (PDT) On Mon, 25 Sep 2023 00:51:48 +0300 alisadariana@gmail.com wrote: > From: Alisa-Dariana Roman > > Add fast settling mode support for AD7193. > > Add fast_settling_average_factor attribute. Expose to user the current > value of the fast settling average factor. User can change the value by > writing a new one. > > Add fast_settling_average_factor_available attribute. Expose to user > possible values for the fast settling average factor. > > Signed-off-by: Alisa-Dariana Roman Hi Alisa-Dariana, Some questions inline. Jonathan > --- > .../ABI/testing/sysfs-bus-iio-adc-ad7192 | 18 +++ > drivers/iio/adc/ad7192.c | 128 ++++++++++++++++-- > 2 files changed, 134 insertions(+), 12 deletions(-) > > diff --git a/Documentation/ABI/testing/sysfs-bus-iio-adc-ad7192 b/Documentation/ABI/testing/sysfs-bus-iio-adc-ad7192 > index f8315202c8f0..780c6841b0c3 100644 > --- a/Documentation/ABI/testing/sysfs-bus-iio-adc-ad7192 > +++ b/Documentation/ABI/testing/sysfs-bus-iio-adc-ad7192 > @@ -19,6 +19,24 @@ Description: > the bridge can be disconnected (when it is not being used > using the bridge_switch_en attribute. > > +What: /sys/bus/iio/devices/iio:deviceX/fast_settling_average_factor > +KernelVersion: > +Contact: linux-iio@vger.kernel.org > +Description: > + This attribute, if available, is used to activate or deactivate > + fast settling mode and set the value of the average factor to > + 1, 2, 8 or 16. If the average factor is set to 1, the fast > + settling mode is disabled. The data from the sinc filter is > + averaged by chosen value. The averaging reduces the output data > + rate for a given FS word, however, the RMS noise improves. So I got distracted in earlier patches, and didn't read your description closely so was assuming this was some weird filter control. Despite it being described as being closely related to the sinc filter, is this just an oversampling ratio control? If it is, then you can use the standard ABI for this. Making sure to reflect changes in this on the sampling frequency as the apparent sampling frequency will reduce. > + > +What: /sys/bus/iio/devices/iio:deviceX/fast_settling_average_factor_available > +KernelVersion: > +Contact: linux-iio@vger.kernel.org > +Description: > + Reading returns a list with the possible values for the fast > + settling average factor: 1, 2, 8, 16. > + > What: /sys/bus/iio/devices/iio:deviceX/in_voltagex_sys_calibration > KernelVersion: > Contact: linux-iio@vger.kernel.org > diff --git a/drivers/iio/adc/ad7192.c b/drivers/iio/adc/ad7192.c > index 0f9d33002d35..3b7de23b024e 100644 > --- a/drivers/iio/adc/ad7192.c > +++ b/drivers/iio/adc/ad7192.c > @@ -60,6 +60,8 @@ > #define AD7192_MODE_SEL_MASK GENMASK(23, 21) /* Operation Mode Select Mask */ > #define AD7192_MODE_STA_MASK BIT(20) /* Status Register transmission Mask */ > #define AD7192_MODE_CLKSRC_MASK GENMASK(19, 18) /* Clock Source Select Mask */ > +#define AD7192_MODE_AVG_MASK GENMASK(17, 16) > + /* Fast Settling Filter Average Select Mask (AD7193 only) */ > #define AD7192_MODE_SINC3 BIT(15) /* SINC3 Filter Select */ > #define AD7192_MODE_ENPAR BIT(13) /* Parity Enable */ > #define AD7192_MODE_CLKDIV BIT(12) /* Clock divide by 2 (AD7190/2 only)*/ > @@ -182,6 +184,7 @@ struct ad7192_state { > u32 mode; > u32 conf; > u32 scale_avail[8][2]; > + u8 avg_avail[4]; > u8 gpocon; > u8 clock_sel; > struct mutex lock; /* protect sensor state */ > @@ -459,6 +462,13 @@ static int ad7192_setup(struct iio_dev *indio_dev, struct device_node *np) > st->scale_avail[i][0] = scale_uv; > } > > + if (st->chip_info->chip_id == CHIPID_AD7193) { > + st->avg_avail[0] = 1; > + st->avg_avail[1] = 2; > + st->avg_avail[2] = 8; > + st->avg_avail[3] = 16; > + } > + > return 0; > } > > @@ -483,6 +493,18 @@ static ssize_t ad7192_show_bridge_switch(struct device *dev, > FIELD_GET(AD7192_GPOCON_BPDSW, st->gpocon)); > } > > +static ssize_t ad7192_show_average_factor(struct device *dev, > + struct device_attribute *attr, > + char *buf) > +{ > + struct iio_dev *indio_dev = dev_to_iio_dev(dev); > + struct ad7192_state *st = iio_priv(indio_dev); > + u8 avg_factor_index; > + > + avg_factor_index = FIELD_GET(AD7192_MODE_AVG_MASK, st->mode); > + return sysfs_emit(buf, "%d\n", st->avg_avail[avg_factor_index]); > +} > + > static ssize_t ad7192_set(struct device *dev, > struct device_attribute *attr, > const char *buf, > @@ -491,12 +513,10 @@ static ssize_t ad7192_set(struct device *dev, > struct iio_dev *indio_dev = dev_to_iio_dev(dev); > struct ad7192_state *st = iio_priv(indio_dev); > struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); > + bool val, ret_einval; > + u8 val_avg_factor; There isn't really that much code shared between the new use of this and previous ones. I'd introduce a new callback for that particular sysfs attribute instead of changing this one. > + unsigned int i; > int ret; > - bool val; > - > - ret = kstrtobool(buf, &val); > - if (ret < 0) > - return ret; > > ret = iio_device_claim_direct_mode(indio_dev); > if (ret) > @@ -504,6 +524,10 @@ static ssize_t ad7192_set(struct device *dev, > > switch ((u32)this_attr->address) { > case AD7192_REG_GPOCON: > + ret = kstrtobool(buf, &val); > + if (ret < 0) > + return ret; > + > if (val) > st->gpocon |= AD7192_GPOCON_BPDSW; > else > @@ -512,6 +536,10 @@ static ssize_t ad7192_set(struct device *dev, > ad_sd_write_reg(&st->sd, AD7192_REG_GPOCON, 1, st->gpocon); > break; > case AD7192_REG_CONF: > + ret = kstrtobool(buf, &val); > + if (ret < 0) > + return ret; > + > if (val) > st->conf |= AD7192_CONF_ACX; > else > @@ -519,6 +547,27 @@ static ssize_t ad7192_set(struct device *dev, > > ad_sd_write_reg(&st->sd, AD7192_REG_CONF, 3, st->conf); > break; > + case AD7192_REG_MODE: > + ret = kstrtou8(buf, 10, &val_avg_factor); > + if (ret < 0) > + return ret; > + > + ret_einval = true; I'd rather this relected the positive condition. So maybe bool found = false; > + for (i = 0; i < ARRAY_SIZE(st->avg_avail); i++) { > + if (val_avg_factor == st->avg_avail[i]) { > + st->mode &= ~AD7192_MODE_AVG_MASK; > + st->mode |= FIELD_PREP(AD7192_MODE_AVG_MASK, i); > + ret_einval = false; found = true; break; > + } > + } > + > + if (ret_einval) if (!found) return -EINVAL; > + return -EINVAL; > + > + ret = ad_sd_write_reg(&st->sd, AD7192_REG_MODE, 3, st->mode); > + if (ret) > + return ret; > + break; > default: > ret = -EINVAL; > } > @@ -528,15 +577,22 @@ static ssize_t ad7192_set(struct device *dev, > return ret ? ret : len; > }