From nobody Fri Oct 3 20:23:02 2025 Received: from out-179.mta0.migadu.com (out-179.mta0.migadu.com [91.218.175.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 66E873A1CD for ; Tue, 26 Aug 2025 00:10:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756167013; cv=none; b=betgDybfr0OpgizLF8zcNqcrNzfqmc89LySa9TxAmTFLoHuYNmvsvcEBjI5oqqDMPRpgkMotEvWk5zb+z1Y2H7G/BWfVuE+UAGVh+ZhZkM07l1iHuFDMKoV+yyKdrMOqcJszrcQ+92HBEgBYzBE9+0udgAJDfpMsDTPh+KsV2v4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756167013; c=relaxed/simple; bh=Hc7VeX3O33EahJN9GMeBmCtHLDZ+kZemn/sSV1xh9+Y=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=hACGo48WZoxPJY0cigGlDXA3azQBqRs8vgmAYzWvxiUnVo5s+X88FOdEs0XnBdSyaw99jbdGAOoYcO7hdJ8xqUf2TM/NiQTK8ReO6neOOqKy8Ec/ljmC+q1xAU4+SlCgf8/G8dDTq/jMjwi7abZqRqh01Py3m+iZpY9zKGwf/xE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=kernel.org; spf=pass smtp.mailfrom=linux.dev; arc=none smtp.client-ip=91.218.175.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Ben Collins Date: Mon, 25 Aug 2025 20:10:03 -0400 Subject: [PATCH v7 1/5] iio: core: Add IIO_VAL_EMPTY type Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250825-mcp9600-iir-v7-1-2ba676a52589@kernel.org> References: <20250825-mcp9600-iir-v7-0-2ba676a52589@kernel.org> In-Reply-To: <20250825-mcp9600-iir-v7-0-2ba676a52589@kernel.org> To: Jonathan Cameron , David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Andy Shevchenko , Antoniu Miclaus , Lars-Peter Clausen , Michael Hennerich Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Ben Collins X-Migadu-Flow: FLOW_OUT In certain situations it may be necessary to return nothing when reading an attribute. For example, when a driver has a filter_type of "none" it should not print any information for frequency or available frequencies. Signed-off-by: Ben Collins --- drivers/iio/industrialio-core.c | 1 + include/linux/iio/types.h | 1 + 2 files changed, 2 insertions(+) diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-cor= e.c index 159d6c5ca3cec3f5c37ee9b85ef1681cca36f5c7..e4ff5b940223ab58bf61b394cc9= 357cd3674cfda 100644 --- a/drivers/iio/industrialio-core.c +++ b/drivers/iio/industrialio-core.c @@ -702,6 +702,7 @@ static ssize_t __iio_format_value(char *buf, size_t off= set, unsigned int type, case IIO_VAL_INT_64: tmp2 =3D (s64)((((u64)vals[1]) << 32) | (u32)vals[0]); return sysfs_emit_at(buf, offset, "%lld", tmp2); + case IIO_VAL_EMPTY: default: return 0; } diff --git a/include/linux/iio/types.h b/include/linux/iio/types.h index ad2761efcc8315e1f9907d2a7159447fb463333e..261745c2d94e582bcca1a2abb29= 7436e8314c930 100644 --- a/include/linux/iio/types.h +++ b/include/linux/iio/types.h @@ -32,6 +32,7 @@ enum iio_event_info { #define IIO_VAL_FRACTIONAL 10 #define IIO_VAL_FRACTIONAL_LOG2 11 #define IIO_VAL_CHAR 12 +#define IIO_VAL_EMPTY 13 =20 enum iio_available_type { IIO_AVAIL_LIST, --=20 2.39.5 From nobody Fri Oct 3 20:23:02 2025 Received: from out-188.mta0.migadu.com (out-188.mta0.migadu.com [91.218.175.188]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D6BA41CD2C for ; Tue, 26 Aug 2025 00:10:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.188 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756167014; cv=none; b=q0abjkHih4nervpgzglxH7M0C+oA9MFDyNYCUtNz1Uud0LsBmO/QEjmVKwUBFkpY6LrMq3BkI1gpR1jH2jeP229mQBEvC/T7AyiQb7AulJjBcv5K3JyKJKfjjUFAqT8jR0BE2/PWtI7szoV8TAyOPjJQ5g0y1XxP3ZsxcmCo3ws= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756167014; c=relaxed/simple; bh=+MzvFeNJiDEBQ1mrqEG/peSy4HJ1qlP2TRscSwtRZmA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=LpMJuXjnwuKtcHWN5J1FaUMvsl4BYhHFLnI/JPK0jiw6ISfLMNAG+0UDD6Epr2OzRafxSrzlhS4/hpL4F38sxCujJ35KB3MQLeZel01yz7YYoq4SXJktrRqG+hWo40DVwHo/nXPTK8EMUqrT5TlTRjW/gmv4/mHIw2LBb8hk9MI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=kernel.org; spf=pass smtp.mailfrom=linux.dev; arc=none smtp.client-ip=91.218.175.188 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Ben Collins Date: Mon, 25 Aug 2025 20:10:04 -0400 Subject: [PATCH v7 2/5] ABI: sysfs-bus-iio: Disambiguate usage for filter_type "none" Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250825-mcp9600-iir-v7-2-2ba676a52589@kernel.org> References: <20250825-mcp9600-iir-v7-0-2ba676a52589@kernel.org> In-Reply-To: <20250825-mcp9600-iir-v7-0-2ba676a52589@kernel.org> To: Jonathan Cameron , David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Andy Shevchenko , Antoniu Miclaus , Lars-Peter Clausen , Michael Hennerich Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Ben Collins X-Migadu-Flow: FLOW_OUT When a filter_type is "none", there really is no useful information that can be presented from sampling and frequency attributes. This is especially true when the driver supports more than one filter_type, since the information would be ambiguous. Suggest returning IIO_VAL_EMPTY for this case. Signed-off-by: Ben Collins --- Documentation/ABI/testing/sysfs-bus-iio | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Documentation/ABI/testing/sysfs-bus-iio b/Documentation/ABI/te= sting/sysfs-bus-iio index 7e31b8cd49b32ea5b58bd99afc2e8105314d7a39..df42a4040530ee96096b998bebc= 8a08b4fb2d78f 100644 --- a/Documentation/ABI/testing/sysfs-bus-iio +++ b/Documentation/ABI/testing/sysfs-bus-iio @@ -2276,7 +2276,11 @@ Description: Reading returns a list with the possible filter modes. Options for the attribute: =20 - * "none" - Filter is disabled/bypassed. + * "none" - Filter is disabled/bypassed. When set in the + filter_type attribute, a driver should return IIO_VAL_EMPTY + when reading sampling and frequency related attributes of + this filter, and return -EINVAL when trying to write these + attributes. * "sinc1" - The digital sinc1 filter. Fast 1st conversion time. Poor noise performance. * "sinc3" - The digital sinc3 filter. Moderate 1st --=20 2.39.5 From nobody Fri Oct 3 20:23:02 2025 Received: from out-180.mta0.migadu.com (out-180.mta0.migadu.com [91.218.175.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 73A3714A0B5 for ; Tue, 26 Aug 2025 00:10:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756167016; cv=none; b=sWOMGnpq2zm1hzhNmg9tq78Ak/AHZDnmnOYvkSQ2GeGmjgDC8KvHV6zpXamEKA9wdK/bflMuo+dNDb1reYFYT02Bhu1V8prhbBljbawPODx5bdlazPeDqtS0kXX29n15SFGADr9b7q5VrzKWyB24pJWf8dffnl6Kz1U1pN4Alrw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756167016; c=relaxed/simple; bh=RBP2bAVNx5seH1yUO0VlfPQUrADaOVCOGVTtcjc/7aM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=uhZ3S7ENJA5XBfb0Bgff2hW/pRTReq2Jxx+XAbTX3R6fytRsbBfWd5igUcciJ7+YvsnkDp85BjrJbd5w7SjCsOdQaDrbx/IxJtRton21DVZIAWfi26bWSQCAAUouD1mBkC5+CeArZBV7OT1qRH/5D1/lEQrNwB2b7V7sPKoGhfs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=kernel.org; spf=pass smtp.mailfrom=linux.dev; arc=none smtp.client-ip=91.218.175.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Ben Collins Date: Mon, 25 Aug 2025 20:10:05 -0400 Subject: [PATCH v7 3/5] ABI: sysfs-bus-iio: Document "ema" filter_type Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250825-mcp9600-iir-v7-3-2ba676a52589@kernel.org> References: <20250825-mcp9600-iir-v7-0-2ba676a52589@kernel.org> In-Reply-To: <20250825-mcp9600-iir-v7-0-2ba676a52589@kernel.org> To: Jonathan Cameron , David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Andy Shevchenko , Antoniu Miclaus , Lars-Peter Clausen , Michael Hennerich Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Ben Collins X-Migadu-Flow: FLOW_OUT Exponential Moving Average (EMA) is a first-order IIR filter. This is a common IIR algorithm used in mcp9600 and others. Signed-off-by: Ben Collins --- Documentation/ABI/testing/sysfs-bus-iio | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-bus-iio b/Documentation/ABI/te= sting/sysfs-bus-iio index df42a4040530ee96096b998bebc8a08b4fb2d78f..4e30f1db0a930f021cf07e5553d= 35a3feffddcc2 100644 --- a/Documentation/ABI/testing/sysfs-bus-iio +++ b/Documentation/ABI/testing/sysfs-bus-iio @@ -2281,6 +2281,8 @@ Description: when reading sampling and frequency related attributes of this filter, and return -EINVAL when trying to write these attributes. + * "ema" - Exponential Moving Average (EMA) is a first-order + Infinite Impulse Response (IIR) filter. * "sinc1" - The digital sinc1 filter. Fast 1st conversion time. Poor noise performance. * "sinc3" - The digital sinc3 filter. Moderate 1st --=20 2.39.5 From nobody Fri Oct 3 20:23:02 2025 Received: from out-183.mta0.migadu.com (out-183.mta0.migadu.com [91.218.175.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C7F511A316E for ; Tue, 26 Aug 2025 00:10:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.183 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756167018; cv=none; b=sjrNIPlqecFIwvUJ693VWJ/aK7wpqeW7BQ2OMQDYqlDbK1az4S/VFxGzrPmdlJ0M2JiFc/Gyn42nIjgykie5FZpPgF00Q6N2mplCT97HJqgyCrkVsQII8Nz/rlZHWMoHe3feFuQ3LvWWEhMYi+0JN5QKBwhh6pKaA1oQ+fkATzQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756167018; c=relaxed/simple; bh=KvB7AcGV2UhZn8qkyG31dPsX3MoMzJ4VsYwV8BaWMPg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=lD5IHatQLIKSGVBj76q9A+joDHLk++uy9rACqITFdPUtXvidFbD3Iug+ZTIXboz01Y2PhrVjN4pBesWcD4/UGIYxLDzsqFFvBqtxPqwPsS74CylfebGzy4PgjX7OctVSbudpknif3zEogN7+fsRyH4gKjGCOBF00neFi+Yv62lo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=kernel.org; spf=pass smtp.mailfrom=linux.dev; arc=none smtp.client-ip=91.218.175.183 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Ben Collins Date: Mon, 25 Aug 2025 20:10:06 -0400 Subject: [PATCH v7 4/5] iio: mcp9600: Add support for IIR filter Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250825-mcp9600-iir-v7-4-2ba676a52589@kernel.org> References: <20250825-mcp9600-iir-v7-0-2ba676a52589@kernel.org> In-Reply-To: <20250825-mcp9600-iir-v7-0-2ba676a52589@kernel.org> To: Jonathan Cameron , David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Andy Shevchenko , Antoniu Miclaus , Lars-Peter Clausen , Michael Hennerich Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Ben Collins X-Migadu-Flow: FLOW_OUT MCP9600 supports an IIR filter with 7 levels. Add IIR attribute to allow get/set of this value. Use filter_type[none, ema] for enabling the IIR filter. Signed-off-by: Ben Collins --- drivers/iio/temperature/mcp9600.c | 147 ++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 147 insertions(+) diff --git a/drivers/iio/temperature/mcp9600.c b/drivers/iio/temperature/mc= p9600.c index aa42c2b1a369edbd36e0d6d6d1738ed0069fd990..d3309e30628ae5cdc7437840395= 2ba285990f4c0 100644 --- a/drivers/iio/temperature/mcp9600.c +++ b/drivers/iio/temperature/mcp9600.c @@ -31,6 +31,7 @@ #define MCP9600_STATUS_ALERT(x) BIT(x) #define MCP9600_SENSOR_CFG 0x05 #define MCP9600_SENSOR_TYPE_MASK GENMASK(6, 4) +#define MCP9600_FILTER_MASK GENMASK(2, 0) #define MCP9600_ALERT_CFG1 0x08 #define MCP9600_ALERT_CFG(x) (MCP9600_ALERT_CFG1 + (x - 1)) #define MCP9600_ALERT_CFG_ENABLE BIT(0) @@ -94,6 +95,27 @@ static const int mcp9600_tc_types[] =3D { [THERMOCOUPLE_TYPE_R] =3D 'R', }; =20 +enum mcp9600_filter { + MCP9600_FILTER_TYPE_NONE, + MCP9600_FILTER_TYPE_EMA, +}; + +static const char * const mcp9600_filter_type[] =3D { + [MCP9600_FILTER_TYPE_NONE] =3D "none", + [MCP9600_FILTER_TYPE_EMA] =3D "ema", +}; + +static const int mcp_iir_coefficients_avail[7][2] =3D { + /* Level 0 is no filter */ + { 0, 524549 }, + { 0, 243901 }, + { 0, 119994 }, + { 0, 59761 }, + { 0, 29851 }, + { 0, 14922 }, + { 0, 7461 }, +}; + static const struct iio_event_spec mcp9600_events[] =3D { { .type =3D IIO_EV_TYPE_THRESH, @@ -119,6 +141,8 @@ struct mcp_chip_info { struct mcp9600_data { struct i2c_client *client; u32 thermocouple_type; + int filter_level; + int filter_enabled; }; =20 static int mcp9600_config(struct mcp9600_data *data) @@ -129,6 +153,9 @@ static int mcp9600_config(struct mcp9600_data *data) =20 cfg =3D FIELD_PREP(MCP9600_SENSOR_TYPE_MASK, mcp9600_type_map[data->thermocouple_type]); + /* The chip understands 0 as "none", and 1-7 as ema filter levels. */ + if (data->filter_enabled) + FIELD_MODIFY(MCP9600_FILTER_MASK, &cfg, data->filter_level + 1); =20 ret =3D i2c_smbus_write_byte_data(client, MCP9600_SENSOR_CFG, cfg); if (ret < 0) { @@ -146,7 +173,11 @@ static int mcp9600_config(struct mcp9600_data *data) .address =3D MCP9600_HOT_JUNCTION, \ .info_mask_separate =3D BIT(IIO_CHAN_INFO_RAW) | \ BIT(IIO_CHAN_INFO_THERMOCOUPLE_TYPE) | \ + BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY) | \ BIT(IIO_CHAN_INFO_SCALE), \ + .info_mask_separate_available =3D \ + BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY), \ + .ext_info =3D mcp9600_ext_filter, \ .event_spec =3D &mcp9600_events[hj_ev_spec_off], \ .num_event_specs =3D hj_num_ev, \ }, \ @@ -162,6 +193,57 @@ static int mcp9600_config(struct mcp9600_data *data) }, \ } =20 +static int mcp9600_get_filter(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan) +{ + struct mcp9600_data *data =3D iio_priv(indio_dev); + + return data->filter_enabled ? MCP9600_FILTER_TYPE_EMA : + MCP9600_FILTER_TYPE_NONE; +} + +static int mcp9600_set_filter(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + unsigned int mode) +{ + struct mcp9600_data *data =3D iio_priv(indio_dev); + int new_type; + + switch (mode) { + case MCP9600_FILTER_TYPE_NONE: + new_type =3D 0; + break; + + case MCP9600_FILTER_TYPE_EMA: + new_type =3D 1; + break; + + default: + return -EINVAL; + } + + /* Do not reset the filter if we don't need to. */ + if (data->filter_enabled =3D=3D new_type) + return 0; + + data->filter_enabled =3D new_type; + return mcp9600_config(data); +} + +static const struct iio_enum mcp9600_filter_enum =3D { + .items =3D mcp9600_filter_type, + .num_items =3D ARRAY_SIZE(mcp9600_filter_type), + .get =3D mcp9600_get_filter, + .set =3D mcp9600_set_filter, +}; + +static const struct iio_chan_spec_ext_info mcp9600_ext_filter[] =3D { + IIO_ENUM("filter_type", IIO_SHARED_BY_ALL, &mcp9600_filter_enum), + IIO_ENUM_AVAILABLE("filter_type", IIO_SHARED_BY_ALL, + &mcp9600_filter_enum), + { } +}; + static const struct iio_chan_spec mcp9600_channels[][2] =3D { MCP9600_CHANNELS(0, 0, 0, 0), /* Alerts: - - - - */ MCP9600_CHANNELS(1, 0, 0, 0), /* Alerts: 1 - - - */ @@ -216,6 +298,69 @@ static int mcp9600_read_raw(struct iio_dev *indio_dev, case IIO_CHAN_INFO_THERMOCOUPLE_TYPE: *val =3D mcp9600_tc_types[data->thermocouple_type]; return IIO_VAL_CHAR; + case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY: + if (!data->filter_enabled) + return IIO_VAL_EMPTY; + + *val =3D mcp_iir_coefficients_avail[data->filter_level][0]; + *val2 =3D mcp_iir_coefficients_avail[data->filter_level][1]; + return IIO_VAL_INT_PLUS_MICRO; + default: + return -EINVAL; + } +} + +static int mcp9600_read_avail(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + const int **vals, int *type, int *length, + long mask) +{ + struct mcp9600_data *data =3D iio_priv(indio_dev); + + switch (mask) { + case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY: + if (!data->filter_enabled) { + *type =3D IIO_VAL_EMPTY; + return IIO_AVAIL_LIST; + } + + *vals =3D (int *)mcp_iir_coefficients_avail; + *length =3D 2 * ARRAY_SIZE(mcp_iir_coefficients_avail); + *type =3D IIO_VAL_INT_PLUS_MICRO; + return IIO_AVAIL_LIST; + default: + return -EINVAL; + } +} + +static int mcp9600_write_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int val, int val2, long mask) +{ + struct mcp9600_data *data =3D iio_priv(indio_dev); + int i; + + switch (mask) { + case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY: + if (!data->filter_enabled) + return -EINVAL; + + for (i =3D 0; i < ARRAY_SIZE(mcp_iir_coefficients_avail); i++) { + if (mcp_iir_coefficients_avail[i][0] =3D=3D val && + mcp_iir_coefficients_avail[i][1] =3D=3D val2) + break; + } + + if (i =3D=3D ARRAY_SIZE(mcp_iir_coefficients_avail)) + return -EINVAL; + + /* Do not reset the filter if there's no change. */ + if (data->filter_level =3D=3D i) + return 0; + + data->filter_level =3D i; + return mcp9600_config(data); + default: return -EINVAL; } @@ -358,6 +503,8 @@ static int mcp9600_write_thresh(struct iio_dev *indio_d= ev, =20 static const struct iio_info mcp9600_info =3D { .read_raw =3D mcp9600_read_raw, + .read_avail =3D mcp9600_read_avail, + .write_raw =3D mcp9600_write_raw, .read_event_config =3D mcp9600_read_event_config, .write_event_config =3D mcp9600_write_event_config, .read_event_value =3D mcp9600_read_thresh, --=20 2.39.5 From nobody Fri Oct 3 20:23:02 2025 Received: from out-183.mta0.migadu.com (out-183.mta0.migadu.com [91.218.175.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 37C3F1AC88A for ; Tue, 26 Aug 2025 00:10:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.183 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756167018; cv=none; b=RLRW9CO0h0JnGNKHyFYqIJ5qKF9g4qP49ulsoEHJslKjmRx9GGK6ahfcoZB+cTM4NsA2M9tDTXq4HXLOFaZ9Xbe+WiADUWa0PZcpJ6+SA488uaJQQfUC/OHXqfFJIsKlqR2tSYsvUK+QQpKoKLFqXDswjKr2A2ERgv39T0AcyPg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756167018; c=relaxed/simple; bh=LaEU8eD4+oPJdKQmwQsYgoZaN/CtBhdsRi6A/cby/us=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=eexF1vKh6C6eeOXpXWNJmoWqN0Ubut5LeleT6TJNVDlcbEDdTqGdyX40EicK1nUrOV917jGewAUmVkgmC0WpRyfvs/R44HEYvu0TGDBXcjja6/D+nDCNWyDzjd6dsaSKBB+yuIJGpyLIMu5f9sj12DEjpvrmsHOMpeduTJr5AOc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=kernel.org; spf=pass smtp.mailfrom=linux.dev; arc=none smtp.client-ip=91.218.175.183 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Ben Collins Date: Mon, 25 Aug 2025 20:10:07 -0400 Subject: [PATCH v7 5/5] iio: ad4080: Rework filter_type "none" logic Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250825-mcp9600-iir-v7-5-2ba676a52589@kernel.org> References: <20250825-mcp9600-iir-v7-0-2ba676a52589@kernel.org> In-Reply-To: <20250825-mcp9600-iir-v7-0-2ba676a52589@kernel.org> To: Jonathan Cameron , David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Andy Shevchenko , Antoniu Miclaus , Lars-Peter Clausen , Michael Hennerich Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Ben Collins X-Migadu-Flow: FLOW_OUT The filter_type logic for "none" needed to be reworked to be more general. As documented, return IIO_VAL_EMPTY for sampling rates in "none" type and EINVAL when there's an attempt to write a rate for "none" type. Signed-off-by: Ben Collins --- drivers/iio/adc/ad4080.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/drivers/iio/adc/ad4080.c b/drivers/iio/adc/ad4080.c index 6e61787ed3213fe4332bd92b938a7a717dada99f..c7408b9703731ee5d4229a85ffa= 91ea64b233cd9 100644 --- a/drivers/iio/adc/ad4080.c +++ b/drivers/iio/adc/ad4080.c @@ -154,8 +154,6 @@ static const int ad4080_dec_rate_avail[] =3D { 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, }; =20 -static const int ad4080_dec_rate_none[] =3D { 1 }; - static const char * const ad4080_power_supplies[] =3D { "vdd33", "vdd11", "vddldo", "iovdd", "vrefin", }; @@ -268,13 +266,13 @@ static int ad4080_read_raw(struct iio_dev *indio_dev, *val =3D st->clk_rate; return IIO_VAL_INT; case IIO_CHAN_INFO_OVERSAMPLING_RATIO: - if (st->filter_type =3D=3D FILTER_NONE) { - *val =3D 1; - } else { - *val =3D ad4080_get_dec_rate(indio_dev, chan); - if (*val < 0) - return *val; - } + if (st->filter_type =3D=3D FILTER_NONE) + return IIO_VAL_EMPTY; + + *val =3D ad4080_get_dec_rate(indio_dev, chan); + if (*val < 0) + return *val; + return IIO_VAL_INT; default: return -EINVAL; @@ -289,7 +287,7 @@ static int ad4080_write_raw(struct iio_dev *indio_dev, =20 switch (mask) { case IIO_CHAN_INFO_OVERSAMPLING_RATIO: - if (st->filter_type =3D=3D FILTER_NONE && val > 1) + if (st->filter_type =3D=3D FILTER_NONE) return -EINVAL; =20 return ad4080_set_dec_rate(indio_dev, chan, val); @@ -376,17 +374,16 @@ static int ad4080_read_avail(struct iio_dev *indio_de= v, case IIO_CHAN_INFO_OVERSAMPLING_RATIO: switch (st->filter_type) { case FILTER_NONE: - *vals =3D ad4080_dec_rate_none; - *length =3D ARRAY_SIZE(ad4080_dec_rate_none); + *type =3D IIO_VAL_EMPTY; break; default: *vals =3D ad4080_dec_rate_avail; *length =3D st->filter_type >=3D SINC_5 ? (ARRAY_SIZE(ad4080_dec_rate_avail) - 2) : ARRAY_SIZE(ad4080_dec_rate_avail); + *type =3D IIO_VAL_INT; break; } - *type =3D IIO_VAL_INT; return IIO_AVAIL_LIST; default: return -EINVAL; --=20 2.39.5