From patchwork Sun Mar 16 13:50:03 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Winchenbach X-Patchwork-Id: 14018439 Received: from out-09.pe-a.jellyfish.systems (out-09.pe-a.jellyfish.systems [198.54.127.69]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A8FA11AAE13; Sun, 16 Mar 2025 14:00:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.54.127.69 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742133604; cv=none; b=Py7brnQyH2s+52S1mFo9Xqxz4R0Vtm6SOg0i3q5nSiCmih6/R6WrkSK54RDsIOUDlwH2hrABxKEFdp+ltON46/ZrkELbyTNBeEGGT3dNoQ/eZhrg84i3DbDVXaRlIZnjjXdSxJI4xhOjzlOFvY85CdOjCkZuTA3+ur2Uozj4lZw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742133604; c=relaxed/simple; bh=EdJSBFycHciE/hpVez5MYlDu+bm8+MG1UwWwOySVc74=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=OiNmbkWnhOqSGdGysQJ5lwE7XTNc6NbbNScqYgAaFqtS26iWkFrelSMhbjyGNWSudyCdEbxNPmC5O0QbyhUfr/nITtA0xfByB8POY99HZxZqV3kk+a7tUlKTz/WAi7HbJmQ2wJx1a6VERO2g9zY+KZV2Of+76Ya+hLdxYseHWCk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=framepointer.org; spf=pass smtp.mailfrom=framepointer.org; dkim=pass (2048-bit key) header.d=framepointer.org header.i=@framepointer.org header.b=i48D6J6F; arc=none smtp.client-ip=198.54.127.69 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=framepointer.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=framepointer.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=framepointer.org header.i=@framepointer.org header.b="i48D6J6F" Received: from prod-lbout-phx.jellyfish.systems (new-01-3.privateemail.com [66.29.159.56]) by pe-a.jellyfish.systems (Postfix) with ESMTPA id 4ZFzyc2ZsFz9sHW; Sun, 16 Mar 2025 13:50:48 +0000 (UTC) Received: from MTA-12.privateemail.com (unknown [10.50.14.28]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by NEW-01-3.privateemail.com (Postfix) with ESMTPS id 4ZFzyc1tHDz2Sd0Q; Sun, 16 Mar 2025 09:50:48 -0400 (EDT) Received: from mta-12.privateemail.com (localhost [127.0.0.1]) by mta-12.privateemail.com (Postfix) with ESMTP id 4ZFzyc0Srhz3hhRs; Sun, 16 Mar 2025 09:50:48 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=framepointer.org; s=default; t=1742133048; bh=EdJSBFycHciE/hpVez5MYlDu+bm8+MG1UwWwOySVc74=; h=From:To:Cc:Subject:Date:From; b=i48D6J6FjsPyzGnezRHbIbjsCzbTu6hXJic0KAaSRGHfTyM11Tnmrb1WcpQI++E5X heWJtySyaR/bGXcXYWvghkIR1pK59WQTXEKdnCzN0o+zJVi4Oxk8EQKed5+ZN/GmUq rsIGQvnK5kXqa9x9GkLV2+lR7eanm6oGzmdpprtnDA+lFzDv41lSMTsOkPWZRTk5YG qgENqTYXwUYRfrrjD1xPWA58Qn8gDhG2t0ugJj2DFbbmkfPMf4jJmldfKlyeUpGOOa 7MrCZnTrVnWpUt3Fu3n5zfGuwgSE7+1M8C/xK5Q7ojAyiV7jY0uioog80HdOQ5mNeh C4vnrl/a4otVA== Received: from 65YTFL3.secure.tethers.com (unknown [152.44.190.141]) by mta-12.privateemail.com (Postfix) with ESMTPA; Sun, 16 Mar 2025 09:50:33 -0400 (EDT) From: Sam Winchenbach To: linux-kernel@vger.kernel.org Cc: lars@metafoo.de, Michael.Hennerich@analog.com, antoniu.miclaus@analog.com, jic23@kernel.org, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, sam.winchenbach@framepointer.org, bpellegrino@arka.org, Sam Winchenbach Subject: [PATCH v7 1/6] dt-bindings: iio: filter: Add lpf/hpf freq margins Date: Sun, 16 Mar 2025 09:50:03 -0400 Message-ID: <20250316135008.155304-1-sam.winchenbach@framepointer.org> X-Mailer: git-send-email 2.48.1 Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Virus-Scanned: ClamAV using ClamSMTP From: Sam Winchenbach Adds two properties to add a margin when automatically finding the corner frequencies. Signed-off-by: Sam Winchenbach --- .../bindings/iio/filter/adi,admv8818.yaml | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Documentation/devicetree/bindings/iio/filter/adi,admv8818.yaml b/Documentation/devicetree/bindings/iio/filter/adi,admv8818.yaml index b77e855bd594..ff0cb553e871 100644 --- a/Documentation/devicetree/bindings/iio/filter/adi,admv8818.yaml +++ b/Documentation/devicetree/bindings/iio/filter/adi,admv8818.yaml @@ -44,6 +44,24 @@ properties: '#clock-cells': const: 0 + adi,lpf-margin-mhz: + description: + Sets the minimum distance between the fundamental frequency of `rf_in` + and the corner frequency of the low-pass, output filter when operated in + 'auto' mode. The selected low-pass corner frequency will be greater than, + or equal to, `rf_in` + `lpf-margin-hz`. If not setting is found that + satisfies this relationship the filter will be put into 'bypass'. + default: 0 + + adi,hpf-margin-mhz: + description: + Sets the minimum distance between the fundamental frequency of `rf_in` + and the corner frequency of the high-pass, input filter when operated in + 'auto' mode. The selected high-pass corner frequency will be less than, + or equal to, `rf_in` - `hpf-margin-hz`. If not setting is found that + satisfies this relationship the filter will be put into 'bypass'. + default: 0 + required: - compatible - reg @@ -61,6 +79,8 @@ examples: spi-max-frequency = <10000000>; clocks = <&admv8818_rfin>; clock-names = "rf_in"; + adi,lpf-margin-mhz = <300>; + adi,hpf-margin-mhz = <300>; }; }; ... From patchwork Sun Mar 16 13:50:04 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Winchenbach X-Patchwork-Id: 14018434 Received: from out-09.pe-a.jellyfish.systems (out-09.pe-a.jellyfish.systems [198.54.127.69]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E2CB825771; Sun, 16 Mar 2025 13:51:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.54.127.69 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742133069; cv=none; b=ZvQJFxZhD5cai49gCl21eYCOvqp8p5bADFIYQC59wnbgxYaKoUAaIWg066M8c+ghc6oOo/arjJZ+jCtrFEglc1iCPHgLNwoSzFDXJY02BFdUl1vHGXV0IjZgL5mHTI0vSgJw+DH31A2l7qWKdXiU7ku2FqoiEJPlHRkbyeN/AXA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742133069; c=relaxed/simple; bh=rPlob9E1zdI1JHOhKrKRb7F75yfM4CIfwUErUMLk0/g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IjMHwaAKDCTXCAnO9+qgA1zJHpsutHUPzYhJVucOVXF2Xuz5FL3/IU+vbGx50JsjDjal7PMvitYpwqwdjLUaHYvuAG6UTbMlDFzreb6OmYpy4rxaSvASTxf2kVWgObKk0bEkSl6oxJlAhY62xiAdrsr/kGk5T04khLpYC3KTeog= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=framepointer.org; spf=pass smtp.mailfrom=framepointer.org; dkim=pass (2048-bit key) header.d=framepointer.org header.i=@framepointer.org header.b=cE7YNbtf; arc=none smtp.client-ip=198.54.127.69 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=framepointer.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=framepointer.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=framepointer.org header.i=@framepointer.org header.b="cE7YNbtf" Received: from prod-lbout-phx.jellyfish.systems (new-01-3.privateemail.com [66.29.159.56]) by pe-a.jellyfish.systems (Postfix) with ESMTPA id 4ZFzyw3HkPz9sNZ; Sun, 16 Mar 2025 13:51:04 +0000 (UTC) Received: from MTA-12.privateemail.com (unknown [10.50.14.28]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by NEW-01-3.privateemail.com (Postfix) with ESMTPS id 4ZFzyw2RH8z2Sd0Q; Sun, 16 Mar 2025 09:51:04 -0400 (EDT) Received: from mta-12.privateemail.com (localhost [127.0.0.1]) by mta-12.privateemail.com (Postfix) with ESMTP id 4ZFzyw13hWz3hhS4; Sun, 16 Mar 2025 09:51:04 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=framepointer.org; s=default; t=1742133064; bh=rPlob9E1zdI1JHOhKrKRb7F75yfM4CIfwUErUMLk0/g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cE7YNbtf7CXeSuAU9ViVYj/Z02d4KIbvtp5Kf9RlwfZVZEAwUyHQD4E2HdNTsKC2W 4rFFXlZ+0oosKtnnzPEGCUiisxuVcX14HCX2lLKGuaEVQf5yIMdbWviVeVyOX6IWqi Q83TvHZUZyShdR/4UiXrJ1rMAS/6ff/ukM7w1cOZnxrkIk6j3PaTto1hy0pjpw8IBK vqPtD3uurGLsQZ5mDKsIZ7gYvvjPFyHlFAx06479hcoSJVpC7Q69YLwy7VQ6MNPaJ5 MoSydEY7aYrPMQo5AAQp/laKbQzlzyPNsXYP3hVhEbGkGhr4jlb4SNYWRQ8e7qrsup PZ6eRfD31DZjA== Received: from 65YTFL3.secure.tethers.com (unknown [152.44.190.141]) by mta-12.privateemail.com (Postfix) with ESMTPA; Sun, 16 Mar 2025 09:50:48 -0400 (EDT) From: Sam Winchenbach To: linux-kernel@vger.kernel.org Cc: lars@metafoo.de, Michael.Hennerich@analog.com, antoniu.miclaus@analog.com, jic23@kernel.org, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, sam.winchenbach@framepointer.org, bpellegrino@arka.org, Sam Winchenbach Subject: [PATCH v7 2/6] iio: filter: admv8818: fix band 4, state 15 Date: Sun, 16 Mar 2025 09:50:04 -0400 Message-ID: <20250316135008.155304-2-sam.winchenbach@framepointer.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250316135008.155304-1-sam.winchenbach@framepointer.org> References: <20250316135008.155304-1-sam.winchenbach@framepointer.org> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Virus-Scanned: ClamAV using ClamSMTP From: Sam Winchenbach Corrects the upper range of LPF Band 4 from 18.5 GHz to 18.85 GHz per the ADMV8818 datasheet Fixes: f34fe888ad05 ("iio:filter:admv8818: add support for ADMV8818") Signed-off-by: Sam Winchenbach --- drivers/iio/filter/admv8818.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/iio/filter/admv8818.c b/drivers/iio/filter/admv8818.c index d85b7d3de866..3d8740caa145 100644 --- a/drivers/iio/filter/admv8818.c +++ b/drivers/iio/filter/admv8818.c @@ -103,7 +103,7 @@ static const unsigned long long freq_range_lpf[4][2] = { {2050000000ULL, 3850000000ULL}, {3350000000ULL, 7250000000ULL}, {7000000000, 13000000000}, - {12550000000, 18500000000} + {12550000000, 18850000000} }; static const struct regmap_config admv8818_regmap_config = { From patchwork Sun Mar 16 13:50:05 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Winchenbach X-Patchwork-Id: 14018437 Received: from out-16.pe-a.jellyfish.systems (out-16.pe-a.jellyfish.systems [198.54.127.94]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BAC2E19D8B2; Sun, 16 Mar 2025 14:00:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.54.127.94 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742133602; cv=none; b=h/6LaJkS+U3bqWv5KHYErg/dLpOSpDK+61lh+QyKpt59zdX5f327NAAkopUZIuF9yZ7KOHtZ7R3/yy3cnzMiMlnNTM3Z5AkgNEz0fchLueEjBVYyjf6qf++75JXmPtNs58OB9bPax9uCsLMwqgbOCOz4RkbZu9gaZ/4clGljwZQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742133602; c=relaxed/simple; bh=Vl/ufIx096MHZv77qSr5S9QTJLYNLRDfBf1wjhPvv50=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VuR3+KvnOmy31OWyd84Tb8Y8npxljNRic8d13vfE7oU3rf6ZgHFXuyLmvI3tT7wo7RQm/sQpO0blWHnOq4DaFNX2CfwxmgIFvzBGdHKTH4IDF0u61KHRHXtbY8pxlqzRPhJFEC84c2z6+0r10nd25WY2Rtk44baMhQS5nS8+KtQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=framepointer.org; spf=pass smtp.mailfrom=framepointer.org; dkim=pass (2048-bit key) header.d=framepointer.org header.i=@framepointer.org header.b=WyHgp+LF; arc=none smtp.client-ip=198.54.127.94 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=framepointer.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=framepointer.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=framepointer.org header.i=@framepointer.org header.b="WyHgp+LF" Received: from prod-lbout-phx.jellyfish.systems (new-01-3.privateemail.com [66.29.159.56]) by pe-a.jellyfish.systems (Postfix) with ESMTPA id 4ZFzzD5NLsz4wPf; Sun, 16 Mar 2025 13:51:20 +0000 (UTC) Received: from MTA-12.privateemail.com (unknown [10.50.14.28]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by NEW-01-3.privateemail.com (Postfix) with ESMTPS id 4ZFzzD3Xykz2Sd0R; Sun, 16 Mar 2025 09:51:20 -0400 (EDT) Received: from mta-12.privateemail.com (localhost [127.0.0.1]) by mta-12.privateemail.com (Postfix) with ESMTP id 4ZFzzD2DWTz3hhRq; Sun, 16 Mar 2025 09:51:20 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=framepointer.org; s=default; t=1742133080; bh=Vl/ufIx096MHZv77qSr5S9QTJLYNLRDfBf1wjhPvv50=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WyHgp+LF3FCdjDcLDKhvZ858YlY7AjpkvUIvI66t1fDxP3ZqfO9ascCQVtd0wZIC/ z58AdDPuU7SL3QFHIqLv/KyrVx7e8pTHxctKYF7sbpmi12DPNtxxsF9WNR9rF5ejhP Nu/gQjk4UhAuqV6/cLgI9I3Y0+c/jKMXiHZZh1Rz2f0HmxVSx161WKZqWl8Hk6Xax/ fXE8A5GXPNtaZoXT2ybTD58el/gqDpE5NFHXd2THqsM6FBBkIDQzHQSADm7A0K7fit ymt6JfrbFWiak6hDznRkVIhokiWH7Mke99JyvzbjNSEsS6CmFoSQd2Lb8yC0jX31G8 5R7YE+n6IwfEA== Received: from 65YTFL3.secure.tethers.com (unknown [152.44.190.141]) by mta-12.privateemail.com (Postfix) with ESMTPA; Sun, 16 Mar 2025 09:51:04 -0400 (EDT) From: Sam Winchenbach To: linux-kernel@vger.kernel.org Cc: lars@metafoo.de, Michael.Hennerich@analog.com, antoniu.miclaus@analog.com, jic23@kernel.org, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, sam.winchenbach@framepointer.org, bpellegrino@arka.org, Sam Winchenbach Subject: [PATCH v7 3/6] iio: filter: admv8818: fix integer overflow Date: Sun, 16 Mar 2025 09:50:05 -0400 Message-ID: <20250316135008.155304-3-sam.winchenbach@framepointer.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250316135008.155304-1-sam.winchenbach@framepointer.org> References: <20250316135008.155304-1-sam.winchenbach@framepointer.org> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Virus-Scanned: ClamAV using ClamSMTP From: Sam Winchenbach HZ_PER_MHZ is only unsigned long. This math overflows, leading to incorrect results. Fixes: f34fe888ad05 ("iio:filter:admv8818: add support for ADMV8818") Signed-off-by: Sam Winchenbach --- drivers/iio/filter/admv8818.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/iio/filter/admv8818.c b/drivers/iio/filter/admv8818.c index 3d8740caa145..cd3aff9a2f7b 100644 --- a/drivers/iio/filter/admv8818.c +++ b/drivers/iio/filter/admv8818.c @@ -154,7 +154,7 @@ static int __admv8818_hpf_select(struct admv8818_state *st, u64 freq) } /* Close HPF frequency gap between 12 and 12.5 GHz */ - if (freq >= 12000 * HZ_PER_MHZ && freq <= 12500 * HZ_PER_MHZ) { + if (freq >= 12000ULL * HZ_PER_MHZ && freq < 12500ULL * HZ_PER_MHZ) { hpf_band = 3; hpf_step = 15; } From patchwork Sun Mar 16 13:50:06 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Winchenbach X-Patchwork-Id: 14018435 Received: from out-09.pe-a.jellyfish.systems (out-09.pe-a.jellyfish.systems [198.54.127.69]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 04F9825771; Sun, 16 Mar 2025 13:51:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.54.127.69 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742133100; cv=none; b=OlrmIhWxB8YiF/iU07qL24qI4QoY0YEaH56m2m3IL0YTrCvV89LVYsNgRuxziAjtv8r5h0Ss+xkCn75GZ8ujDHDEERknLTA+hDczfqs75E1Mdr75mnFjK3DedMch8toH34XNOB2wwA6V7XVA88ODSCpiuAdrN0og1ZF7cDlNSW0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742133100; c=relaxed/simple; bh=lbveR3VtflLRRBefMZ/4I2yX3acj1xk1d7M799GMM5k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mw5e0qUuecwI1a5ww8Caixw/SQp9h/3tIBozwJt5hiME0a9Z+EXfyj9lP8giMNmjYU0FR0Wx8zgd+ussCjm4YqMnK7eZ4kPxxPaZH/wRx8utX9KXCPxh0a56wl9AqJu7EU5gKFCWLyfYaTuJZGdfTGIL/v3Pl+LZ+W0rWIRsXlQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=framepointer.org; spf=pass smtp.mailfrom=framepointer.org; dkim=pass (2048-bit key) header.d=framepointer.org header.i=@framepointer.org header.b=rI/EO4/B; arc=none smtp.client-ip=198.54.127.69 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=framepointer.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=framepointer.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=framepointer.org header.i=@framepointer.org header.b="rI/EO4/B" Received: from prod-lbout-phx.jellyfish.systems (new-01-3.privateemail.com [66.29.159.56]) by pe-a.jellyfish.systems (Postfix) with ESMTPA id 4ZFzzX6S9Hz9sNZ; Sun, 16 Mar 2025 13:51:36 +0000 (UTC) Received: from MTA-12.privateemail.com (unknown [10.50.14.28]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by NEW-01-3.privateemail.com (Postfix) with ESMTPS id 4ZFzzX5HzNz2Sd0Q; Sun, 16 Mar 2025 09:51:36 -0400 (EDT) Received: from mta-12.privateemail.com (localhost [127.0.0.1]) by mta-12.privateemail.com (Postfix) with ESMTP id 4ZFzzX3rzKz3hhTs; Sun, 16 Mar 2025 09:51:36 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=framepointer.org; s=default; t=1742133096; bh=lbveR3VtflLRRBefMZ/4I2yX3acj1xk1d7M799GMM5k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rI/EO4/BO3lmt5pg1WfJM2BGS4ZM4QtE+95hzyrVNHDEzRNSR+putEYiDOdiRX0c+ m/oEBTuM5oor2sQVVGd6h5IfiDM5seF863Smqk0QME1De/ki4sfFzI9tpLTkxVJoQn qxuRXTYbqDI+KaUQvejTWssxYWGjlsjw3WLs549FC/hpHOGkDkYpOpH8vkcIK6zc+V VY8urZ1tznAzbeq8TpEdlUWFUaSVHCLsMiUzwy9KYQsPMAkv5ikLpV/7rle9CJUgpC XhrqXQ6Sr6mpGJjejwBVjw3+yByg71sXvqV89aBafdu3OoS489gN5zTMpMFP4C3pvP C8jfJkncpIRFg== Received: from 65YTFL3.secure.tethers.com (unknown [152.44.190.141]) by mta-12.privateemail.com (Postfix) with ESMTPA; Sun, 16 Mar 2025 09:51:20 -0400 (EDT) From: Sam Winchenbach To: linux-kernel@vger.kernel.org Cc: lars@metafoo.de, Michael.Hennerich@analog.com, antoniu.miclaus@analog.com, jic23@kernel.org, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, sam.winchenbach@framepointer.org, bpellegrino@arka.org, Sam Winchenbach Subject: [PATCH v7 4/6] iio: filter: admv8818: fix range calculation Date: Sun, 16 Mar 2025 09:50:06 -0400 Message-ID: <20250316135008.155304-4-sam.winchenbach@framepointer.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250316135008.155304-1-sam.winchenbach@framepointer.org> References: <20250316135008.155304-1-sam.winchenbach@framepointer.org> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Virus-Scanned: ClamAV using ClamSMTP From: Sam Winchenbach Search for the minimum error while ensuring that the LPF corner frequency is greater than the target, and the HPF corner frequency is lower than the target This fixes issues where the range calculations were suboptimal. Add two new DTS properties to set the margin between the input frequency and the calculated corner frequency Below is a generated table of the differences between the old algorithm and the new. This is a sweep from 0 to 20 GHz in 10 MHz steps. === HPF === freq = 1750 MHz, 3db: bypass => 1750 MHz freq = 3400 MHz, 3db: 3310 => 3400 MHz freq = 3410 MHz, 3db: 3310 => 3400 MHz freq = 3420 MHz, 3db: 3310 => 3400 MHz freq = 3660 MHz, 3db: 3550 => 3656 MHz freq = 6600 MHz, 3db: 6479 => 6600 MHz freq = 6610 MHz, 3db: 6479 => 6600 MHz freq = 6620 MHz, 3db: 6479 => 6600 MHz freq = 6630 MHz, 3db: 6479 => 6600 MHz freq = 6640 MHz, 3db: 6479 => 6600 MHz freq = 6650 MHz, 3db: 6479 => 6600 MHz freq = 6660 MHz, 3db: 6479 => 6600 MHz freq = 6670 MHz, 3db: 6479 => 6600 MHz freq = 6680 MHz, 3db: 6479 => 6600 MHz freq = 6690 MHz, 3db: 6479 => 6600 MHz freq = 6700 MHz, 3db: 6479 => 6600 MHz freq = 6710 MHz, 3db: 6479 => 6600 MHz freq = 6720 MHz, 3db: 6479 => 6600 MHz freq = 6730 MHz, 3db: 6479 => 6600 MHz freq = 6960 MHz, 3db: 6736 => 6960 MHz freq = 6970 MHz, 3db: 6736 => 6960 MHz freq = 6980 MHz, 3db: 6736 => 6960 MHz freq = 6990 MHz, 3db: 6736 => 6960 MHz freq = 7320 MHz, 3db: 7249 => 7320 MHz freq = 7330 MHz, 3db: 7249 => 7320 MHz freq = 7340 MHz, 3db: 7249 => 7320 MHz freq = 7350 MHz, 3db: 7249 => 7320 MHz freq = 7360 MHz, 3db: 7249 => 7320 MHz freq = 7370 MHz, 3db: 7249 => 7320 MHz freq = 7380 MHz, 3db: 7249 => 7320 MHz freq = 7390 MHz, 3db: 7249 => 7320 MHz freq = 7400 MHz, 3db: 7249 => 7320 MHz freq = 7410 MHz, 3db: 7249 => 7320 MHz freq = 7420 MHz, 3db: 7249 => 7320 MHz freq = 7430 MHz, 3db: 7249 => 7320 MHz freq = 7440 MHz, 3db: 7249 => 7320 MHz freq = 7450 MHz, 3db: 7249 => 7320 MHz freq = 7460 MHz, 3db: 7249 => 7320 MHz freq = 7470 MHz, 3db: 7249 => 7320 MHz freq = 7480 MHz, 3db: 7249 => 7320 MHz freq = 7490 MHz, 3db: 7249 => 7320 MHz freq = 7500 MHz, 3db: 7249 => 7320 MHz freq = 12500 MHz, 3db: 12000 => 12500 MHz === LPF === freq = 2050 MHz, 3db: bypass => 2050 MHz freq = 2170 MHz, 3db: 2290 => 2170 MHz freq = 2290 MHz, 3db: 2410 => 2290 MHz freq = 2410 MHz, 3db: 2530 => 2410 MHz freq = 2530 MHz, 3db: 2650 => 2530 MHz freq = 2650 MHz, 3db: 2770 => 2650 MHz freq = 2770 MHz, 3db: 2890 => 2770 MHz freq = 2890 MHz, 3db: 3010 => 2890 MHz freq = 3010 MHz, 3db: 3130 => 3010 MHz freq = 3130 MHz, 3db: 3250 => 3130 MHz freq = 3250 MHz, 3db: 3370 => 3250 MHz freq = 3260 MHz, 3db: 3370 => 3350 MHz freq = 3270 MHz, 3db: 3370 => 3350 MHz freq = 3280 MHz, 3db: 3370 => 3350 MHz freq = 3290 MHz, 3db: 3370 => 3350 MHz freq = 3300 MHz, 3db: 3370 => 3350 MHz freq = 3310 MHz, 3db: 3370 => 3350 MHz freq = 3320 MHz, 3db: 3370 => 3350 MHz freq = 3330 MHz, 3db: 3370 => 3350 MHz freq = 3340 MHz, 3db: 3370 => 3350 MHz freq = 3350 MHz, 3db: 3370 => 3350 MHz freq = 3370 MHz, 3db: 3490 => 3370 MHz freq = 3490 MHz, 3db: 3610 => 3490 MHz freq = 3610 MHz, 3db: 3730 => 3610 MHz freq = 3730 MHz, 3db: 3850 => 3730 MHz freq = 3850 MHz, 3db: 3870 => 3850 MHz freq = 3870 MHz, 3db: 4130 => 3870 MHz freq = 4130 MHz, 3db: 4390 => 4130 MHz freq = 4390 MHz, 3db: 4650 => 4390 MHz freq = 4650 MHz, 3db: 4910 => 4650 MHz freq = 4910 MHz, 3db: 5170 => 4910 MHz freq = 5170 MHz, 3db: 5430 => 5170 MHz freq = 5430 MHz, 3db: 5690 => 5430 MHz freq = 5690 MHz, 3db: 5950 => 5690 MHz freq = 5950 MHz, 3db: 6210 => 5950 MHz freq = 6210 MHz, 3db: 6470 => 6210 MHz freq = 6470 MHz, 3db: 6730 => 6470 MHz freq = 6730 MHz, 3db: 6990 => 6730 MHz freq = 6990 MHz, 3db: 7250 => 6990 MHz freq = 7000 MHz, 3db: 7250 => 7000 MHz freq = 7250 MHz, 3db: 7400 => 7250 MHz freq = 7400 MHz, 3db: 7800 => 7400 MHz freq = 7800 MHz, 3db: 8200 => 7800 MHz freq = 8200 MHz, 3db: 8600 => 8200 MHz freq = 8600 MHz, 3db: 9000 => 8600 MHz freq = 9000 MHz, 3db: 9400 => 9000 MHz freq = 9400 MHz, 3db: 9800 => 9400 MHz freq = 9800 MHz, 3db: 10200 => 9800 MHz freq = 10200 MHz, 3db: 10600 => 10200 MHz freq = 10600 MHz, 3db: 11000 => 10600 MHz freq = 11000 MHz, 3db: 11400 => 11000 MHz freq = 11400 MHz, 3db: 11800 => 11400 MHz freq = 11800 MHz, 3db: 12200 => 11800 MHz freq = 12200 MHz, 3db: 12600 => 12200 MHz freq = 12210 MHz, 3db: 12600 => 12550 MHz freq = 12220 MHz, 3db: 12600 => 12550 MHz freq = 12230 MHz, 3db: 12600 => 12550 MHz freq = 12240 MHz, 3db: 12600 => 12550 MHz freq = 12250 MHz, 3db: 12600 => 12550 MHz freq = 12260 MHz, 3db: 12600 => 12550 MHz freq = 12270 MHz, 3db: 12600 => 12550 MHz freq = 12280 MHz, 3db: 12600 => 12550 MHz freq = 12290 MHz, 3db: 12600 => 12550 MHz freq = 12300 MHz, 3db: 12600 => 12550 MHz freq = 12310 MHz, 3db: 12600 => 12550 MHz freq = 12320 MHz, 3db: 12600 => 12550 MHz freq = 12330 MHz, 3db: 12600 => 12550 MHz freq = 12340 MHz, 3db: 12600 => 12550 MHz freq = 12350 MHz, 3db: 12600 => 12550 MHz freq = 12360 MHz, 3db: 12600 => 12550 MHz freq = 12370 MHz, 3db: 12600 => 12550 MHz freq = 12380 MHz, 3db: 12600 => 12550 MHz freq = 12390 MHz, 3db: 12600 => 12550 MHz freq = 12400 MHz, 3db: 12600 => 12550 MHz freq = 12410 MHz, 3db: 12600 => 12550 MHz freq = 12420 MHz, 3db: 12600 => 12550 MHz freq = 12430 MHz, 3db: 12600 => 12550 MHz freq = 12440 MHz, 3db: 12600 => 12550 MHz freq = 12450 MHz, 3db: 12600 => 12550 MHz freq = 12460 MHz, 3db: 12600 => 12550 MHz freq = 12470 MHz, 3db: 12600 => 12550 MHz freq = 12480 MHz, 3db: 12600 => 12550 MHz freq = 12490 MHz, 3db: 12600 => 12550 MHz freq = 12500 MHz, 3db: 12600 => 12550 MHz freq = 12510 MHz, 3db: 12600 => 12550 MHz freq = 12520 MHz, 3db: 12600 => 12550 MHz freq = 12530 MHz, 3db: 12600 => 12550 MHz freq = 12540 MHz, 3db: 12600 => 12550 MHz freq = 12550 MHz, 3db: 12600 => 12550 MHz freq = 12600 MHz, 3db: 13000 => 12600 MHz freq = 12610 MHz, 3db: 13000 => 12970 MHz freq = 12620 MHz, 3db: 13000 => 12970 MHz freq = 12630 MHz, 3db: 13000 => 12970 MHz freq = 12640 MHz, 3db: 13000 => 12970 MHz freq = 12650 MHz, 3db: 13000 => 12970 MHz freq = 12660 MHz, 3db: 13000 => 12970 MHz freq = 12670 MHz, 3db: 13000 => 12970 MHz freq = 12680 MHz, 3db: 13000 => 12970 MHz freq = 12690 MHz, 3db: 13000 => 12970 MHz freq = 12700 MHz, 3db: 13000 => 12970 MHz freq = 12710 MHz, 3db: 13000 => 12970 MHz freq = 12720 MHz, 3db: 13000 => 12970 MHz freq = 12730 MHz, 3db: 13000 => 12970 MHz freq = 12740 MHz, 3db: 13000 => 12970 MHz freq = 12750 MHz, 3db: 13000 => 12970 MHz freq = 12760 MHz, 3db: 13000 => 12970 MHz freq = 12770 MHz, 3db: 13000 => 12970 MHz freq = 12780 MHz, 3db: 13000 => 12970 MHz freq = 12790 MHz, 3db: 13000 => 12970 MHz freq = 12800 MHz, 3db: 13000 => 12970 MHz freq = 12810 MHz, 3db: 13000 => 12970 MHz freq = 12820 MHz, 3db: 13000 => 12970 MHz freq = 12830 MHz, 3db: 13000 => 12970 MHz freq = 12840 MHz, 3db: 13000 => 12970 MHz freq = 12850 MHz, 3db: 13000 => 12970 MHz freq = 12860 MHz, 3db: 13000 => 12970 MHz freq = 12870 MHz, 3db: 13000 => 12970 MHz freq = 12880 MHz, 3db: 13000 => 12970 MHz freq = 12890 MHz, 3db: 13000 => 12970 MHz freq = 12900 MHz, 3db: 13000 => 12970 MHz freq = 12910 MHz, 3db: 13000 => 12970 MHz freq = 12920 MHz, 3db: 13000 => 12970 MHz freq = 12930 MHz, 3db: 13000 => 12970 MHz freq = 12940 MHz, 3db: 13000 => 12970 MHz freq = 12950 MHz, 3db: 13000 => 12970 MHz freq = 12960 MHz, 3db: 13000 => 12970 MHz freq = 12970 MHz, 3db: 13000 => 12970 MHz freq = 13000 MHz, 3db: 13390 => 13000 MHz freq = 13390 MHz, 3db: 13810 => 13390 MHz freq = 13810 MHz, 3db: 14230 => 13810 MHz freq = 14230 MHz, 3db: 14650 => 14230 MHz freq = 14650 MHz, 3db: 15070 => 14650 MHz freq = 15070 MHz, 3db: 15490 => 15070 MHz freq = 15490 MHz, 3db: 15910 => 15490 MHz freq = 15910 MHz, 3db: 16330 => 15910 MHz freq = 16330 MHz, 3db: 16750 => 16330 MHz freq = 16750 MHz, 3db: 17170 => 16750 MHz freq = 17170 MHz, 3db: 17590 => 17170 MHz freq = 17590 MHz, 3db: 18010 => 17590 MHz freq = 18010 MHz, 3db: 18430 => 18010 MHz freq = 18430 MHz, 3db: 18850 => 18430 MHz freq = 18850 MHz, 3db: bypass => 18850 MHz Fixes: f34fe888ad05 ("iio:filter:admv8818: add support for ADMV8818") Signed-off-by: Sam Winchenbach --- drivers/iio/filter/admv8818.c | 205 +++++++++++++++++++++++++--------- 1 file changed, 152 insertions(+), 53 deletions(-) diff --git a/drivers/iio/filter/admv8818.c b/drivers/iio/filter/admv8818.c index cd3aff9a2f7b..380e119b3cf5 100644 --- a/drivers/iio/filter/admv8818.c +++ b/drivers/iio/filter/admv8818.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -70,6 +71,16 @@ #define ADMV8818_HPF_WR0_MSK GENMASK(7, 4) #define ADMV8818_LPF_WR0_MSK GENMASK(3, 0) +#define ADMV8818_BAND_BYPASS 0 +#define ADMV8818_BAND_MIN 1 +#define ADMV8818_BAND_MAX 4 +#define ADMV8818_BAND_CORNER_LOW 0 +#define ADMV8818_BAND_CORNER_HIGH 1 + +#define ADMV8818_STATE_MIN 0 +#define ADMV8818_STATE_MAX 15 +#define ADMV8818_NUM_STATES 16 + enum { ADMV8818_BW_FREQ, ADMV8818_CENTER_FREQ @@ -90,16 +101,20 @@ struct admv8818_state { struct mutex lock; unsigned int filter_mode; u64 cf_hz; + u64 lpf_margin_hz; + u64 hpf_margin_hz; }; -static const unsigned long long freq_range_hpf[4][2] = { +static const unsigned long long freq_range_hpf[5][2] = { + {0ULL, 0ULL}, /* bypass */ {1750000000ULL, 3550000000ULL}, {3400000000ULL, 7250000000ULL}, {6600000000, 12000000000}, {12500000000, 19900000000} }; -static const unsigned long long freq_range_lpf[4][2] = { +static const unsigned long long freq_range_lpf[5][2] = { + {U64_MAX, U64_MAX}, /* bypass */ {2050000000ULL, 3850000000ULL}, {3350000000ULL, 7250000000ULL}, {7000000000, 13000000000}, @@ -121,44 +136,59 @@ static const char * const admv8818_modes[] = { static int __admv8818_hpf_select(struct admv8818_state *st, u64 freq) { - unsigned int hpf_step = 0, hpf_band = 0, i, j; - u64 freq_step; - int ret; + int band, state, ret; + unsigned int hpf_state = ADMV8818_STATE_MIN, hpf_band = ADMV8818_BAND_BYPASS; + u64 freq_error, min_freq_error, freq_corner, freq_step; - if (freq < freq_range_hpf[0][0]) + if (freq < freq_range_hpf[ADMV8818_BAND_MIN][ADMV8818_BAND_CORNER_LOW]) goto hpf_write; - if (freq > freq_range_hpf[3][1]) { - hpf_step = 15; - hpf_band = 4; - + if (freq >= freq_range_hpf[ADMV8818_BAND_MAX][ADMV8818_BAND_CORNER_HIGH]) { + hpf_state = ADMV8818_STATE_MAX; + hpf_band = ADMV8818_BAND_MAX; goto hpf_write; } - for (i = 0; i < 4; i++) { - freq_step = div_u64((freq_range_hpf[i][1] - - freq_range_hpf[i][0]), 15); + /* Close HPF frequency gap between 12 and 12.5 GHz */ + if (freq >= 12000ULL * HZ_PER_MHZ && freq < 12500ULL * HZ_PER_MHZ) { + hpf_state = ADMV8818_STATE_MAX; + hpf_band = 3; + goto hpf_write; + } - if (freq > freq_range_hpf[i][0] && - (freq < freq_range_hpf[i][1] + freq_step)) { - hpf_band = i + 1; + min_freq_error = U64_MAX; + for (band = ADMV8818_BAND_MIN; band <= ADMV8818_BAND_MAX; band++) { + /* + * This (and therefore all other ranges) have a corner + * frequency higher than the target frequency. + */ + if (freq_range_hpf[band][ADMV8818_BAND_CORNER_LOW] > freq) + break; - for (j = 1; j <= 16; j++) { - if (freq < (freq_range_hpf[i][0] + (freq_step * j))) { - hpf_step = j - 1; - break; - } + freq_step = freq_range_hpf[band][ADMV8818_BAND_CORNER_HIGH] - + freq_range_hpf[band][ADMV8818_BAND_CORNER_LOW]; + freq_step = div_u64(freq_step, ADMV8818_NUM_STATES - 1); + + for (state = ADMV8818_STATE_MIN; state <= ADMV8818_STATE_MAX; state++) { + freq_corner = freq_range_hpf[band][ADMV8818_BAND_CORNER_LOW] + + freq_step * state; + + /* + * This (and therefore all other states) have a corner + * frequency higher than the target frequency. + */ + if (freq_corner > freq) + break; + + freq_error = freq - freq_corner; + if (freq_error < min_freq_error) { + min_freq_error = freq_error; + hpf_state = state; + hpf_band = band; } - break; } } - /* Close HPF frequency gap between 12 and 12.5 GHz */ - if (freq >= 12000ULL * HZ_PER_MHZ && freq < 12500ULL * HZ_PER_MHZ) { - hpf_band = 3; - hpf_step = 15; - } - hpf_write: ret = regmap_update_bits(st->regmap, ADMV8818_REG_WR0_SW, ADMV8818_SW_IN_SET_WR0_MSK | @@ -170,7 +200,7 @@ static int __admv8818_hpf_select(struct admv8818_state *st, u64 freq) return regmap_update_bits(st->regmap, ADMV8818_REG_WR0_FILTER, ADMV8818_HPF_WR0_MSK, - FIELD_PREP(ADMV8818_HPF_WR0_MSK, hpf_step)); + FIELD_PREP(ADMV8818_HPF_WR0_MSK, hpf_state)); } static int admv8818_hpf_select(struct admv8818_state *st, u64 freq) @@ -186,31 +216,52 @@ static int admv8818_hpf_select(struct admv8818_state *st, u64 freq) static int __admv8818_lpf_select(struct admv8818_state *st, u64 freq) { - unsigned int lpf_step = 0, lpf_band = 0, i, j; - u64 freq_step; - int ret; + int band, state, ret; + unsigned int lpf_state = ADMV8818_STATE_MIN, lpf_band = ADMV8818_BAND_BYPASS; + u64 freq_error, min_freq_error, freq_corner, freq_step; - if (freq > freq_range_lpf[3][1]) + if (freq > freq_range_lpf[ADMV8818_BAND_MAX][ADMV8818_BAND_CORNER_HIGH]) goto lpf_write; - if (freq < freq_range_lpf[0][0]) { - lpf_band = 1; - + if (freq < freq_range_lpf[ADMV8818_BAND_MIN][ADMV8818_BAND_CORNER_LOW]) { + lpf_state = ADMV8818_STATE_MIN; + lpf_band = ADMV8818_BAND_MIN; goto lpf_write; } - for (i = 0; i < 4; i++) { - if (freq > freq_range_lpf[i][0] && freq < freq_range_lpf[i][1]) { - lpf_band = i + 1; - freq_step = div_u64((freq_range_lpf[i][1] - freq_range_lpf[i][0]), 15); + min_freq_error = U64_MAX; + for (band = ADMV8818_BAND_MAX; band >= ADMV8818_BAND_MIN; --band) { + /* + * At this point the highest corner frequency of + * all remaining ranges is below the target. + * LPF corner should be >= the target. + */ + if (freq > freq_range_lpf[band][ADMV8818_BAND_CORNER_HIGH]) + break; + + freq_step = freq_range_lpf[band][ADMV8818_BAND_CORNER_HIGH] - + freq_range_lpf[band][ADMV8818_BAND_CORNER_LOW]; + freq_step = div_u64(freq_step, ADMV8818_NUM_STATES - 1); + + for (state = ADMV8818_STATE_MAX; state >= ADMV8818_STATE_MIN; --state) { - for (j = 0; j <= 15; j++) { - if (freq < (freq_range_lpf[i][0] + (freq_step * j))) { - lpf_step = j; - break; - } + freq_corner = freq_range_lpf[band][ADMV8818_BAND_CORNER_LOW] + + state * freq_step; + + /* + * At this point all other states in range will + * place the corner frequency below the target + * LPF corner should >= the target. + */ + if (freq > freq_corner) + break; + + freq_error = freq_corner - freq; + if (freq_error < min_freq_error) { + min_freq_error = freq_error; + lpf_state = state; + lpf_band = band; } - break; } } @@ -225,7 +276,7 @@ static int __admv8818_lpf_select(struct admv8818_state *st, u64 freq) return regmap_update_bits(st->regmap, ADMV8818_REG_WR0_FILTER, ADMV8818_LPF_WR0_MSK, - FIELD_PREP(ADMV8818_LPF_WR0_MSK, lpf_step)); + FIELD_PREP(ADMV8818_LPF_WR0_MSK, lpf_state)); } static int admv8818_lpf_select(struct admv8818_state *st, u64 freq) @@ -242,16 +293,28 @@ static int admv8818_lpf_select(struct admv8818_state *st, u64 freq) static int admv8818_rfin_band_select(struct admv8818_state *st) { int ret; + u64 hpf_corner_target, lpf_corner_target; st->cf_hz = clk_get_rate(st->clkin); + /* Check for underflow */ + if (st->cf_hz > st->hpf_margin_hz) + hpf_corner_target = st->cf_hz - st->hpf_margin_hz; + else + hpf_corner_target = 0; + + /* Check for overflow */ + lpf_corner_target = st->cf_hz + st->lpf_margin_hz; + if (lpf_corner_target < st->cf_hz) + lpf_corner_target = U64_MAX; + mutex_lock(&st->lock); - ret = __admv8818_hpf_select(st, st->cf_hz); + ret = __admv8818_hpf_select(st, hpf_corner_target); if (ret) goto exit; - ret = __admv8818_lpf_select(st, st->cf_hz); + ret = __admv8818_lpf_select(st, lpf_corner_target); exit: mutex_unlock(&st->lock); return ret; @@ -278,8 +341,11 @@ static int __admv8818_read_hpf_freq(struct admv8818_state *st, u64 *hpf_freq) hpf_state = FIELD_GET(ADMV8818_HPF_WR0_MSK, data); - *hpf_freq = div_u64(freq_range_hpf[hpf_band - 1][1] - freq_range_hpf[hpf_band - 1][0], 15); - *hpf_freq = freq_range_hpf[hpf_band - 1][0] + (*hpf_freq * hpf_state); + *hpf_freq = freq_range_hpf[hpf_band][ADMV8818_BAND_CORNER_HIGH] - + freq_range_hpf[hpf_band][ADMV8818_BAND_CORNER_LOW]; + *hpf_freq = div_u64(*hpf_freq, ADMV8818_NUM_STATES - 1); + *hpf_freq = freq_range_hpf[hpf_band][ADMV8818_BAND_CORNER_LOW] + + (*hpf_freq * hpf_state); return ret; } @@ -316,8 +382,11 @@ static int __admv8818_read_lpf_freq(struct admv8818_state *st, u64 *lpf_freq) lpf_state = FIELD_GET(ADMV8818_LPF_WR0_MSK, data); - *lpf_freq = div_u64(freq_range_lpf[lpf_band - 1][1] - freq_range_lpf[lpf_band - 1][0], 15); - *lpf_freq = freq_range_lpf[lpf_band - 1][0] + (*lpf_freq * lpf_state); + *lpf_freq = freq_range_lpf[lpf_band][ADMV8818_BAND_CORNER_HIGH] - + freq_range_lpf[lpf_band][ADMV8818_BAND_CORNER_LOW]; + *lpf_freq = div_u64(*lpf_freq, ADMV8818_NUM_STATES - 1); + *lpf_freq = freq_range_lpf[lpf_band][ADMV8818_BAND_CORNER_LOW] + + (*lpf_freq * lpf_state); return ret; } @@ -641,6 +710,32 @@ static int admv8818_clk_setup(struct admv8818_state *st) return devm_add_action_or_reset(&spi->dev, admv8818_clk_notifier_unreg, st); } +static int admv8818_read_properties(struct admv8818_state *st) +{ + struct spi_device *spi = st->spi; + u32 mhz; + int ret; + + ret = device_property_read_u32(&spi->dev, "adi,lpf-margin-mhz", &mhz); + if (ret == 0) + st->lpf_margin_hz = (u64)mhz * HZ_PER_MHZ; + else if (ret == -EINVAL) + st->lpf_margin_hz = 0; + else + return ret; + + + ret = device_property_read_u32(&spi->dev, "adi,hpf-margin-mhz", &mhz); + if (ret == 0) + st->hpf_margin_hz = (u64)mhz * HZ_PER_MHZ; + else if (ret == -EINVAL) + st->hpf_margin_hz = 0; + else if (ret < 0) + return ret; + + return 0; +} + static int admv8818_probe(struct spi_device *spi) { struct iio_dev *indio_dev; @@ -672,6 +767,10 @@ static int admv8818_probe(struct spi_device *spi) mutex_init(&st->lock); + ret = admv8818_read_properties(st); + if (ret) + return ret; + ret = admv8818_init(st); if (ret) return ret; From patchwork Sun Mar 16 13:50:07 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Winchenbach X-Patchwork-Id: 14018438 Received: from out-10.pe-a.jellyfish.systems (out-10.pe-a.jellyfish.systems [198.54.127.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9B7471AAA2F; Sun, 16 Mar 2025 14:00:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.54.127.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742133603; cv=none; b=W+pRwGy6pa4DhbPXqRSJE/Ob/8fcl1Y0Pg1+nQlwHPGeM+Bl6zxSLQZz8KJDC5CFg03uGY9sWULh6PAWS/EjsGb6M+r4k/hs+uX5g7DGa/oMHwr4kvar5mdpopLLPqveF/I422czo+p8iLP+HmZUyJLc/Q0XGMgahK07BiZAUF0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742133603; c=relaxed/simple; bh=ljc3oesl2r1E8aZ9fXFZUkkJvxGlE5eoRSoQ7GRd9BI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fIccF/1e5W1iG7je1/tBAmB6h/bBe5IRbQn3u8aOn3dp7CTNMi4H4JGrKzNhZM07j7NIPNxeVCmWTq72SSoqc6XOhXcP6uWZe4xVab1C0Dt5fmMoEDb6yQqHmAHv0DiLbCrhyxJUObNAuJtVBwWMc9wqawBrHzTMqfanWp7/DzM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=framepointer.org; spf=pass smtp.mailfrom=framepointer.org; dkim=pass (2048-bit key) header.d=framepointer.org header.i=@framepointer.org header.b=W6mUAXpG; arc=none smtp.client-ip=198.54.127.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=framepointer.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=framepointer.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=framepointer.org header.i=@framepointer.org header.b="W6mUAXpG" Received: from prod-lbout-phx.jellyfish.systems (new-01-3.privateemail.com [66.29.159.56]) by pe-a.jellyfish.systems (Postfix) with ESMTPA id 4ZFzzr6ZFZz9sSS; Sun, 16 Mar 2025 13:51:52 +0000 (UTC) Received: from MTA-12.privateemail.com (unknown [10.50.14.28]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by NEW-01-3.privateemail.com (Postfix) with ESMTPS id 4ZFzzr5jLlz2Sd0Q; Sun, 16 Mar 2025 09:51:52 -0400 (EDT) Received: from mta-12.privateemail.com (localhost [127.0.0.1]) by mta-12.privateemail.com (Postfix) with ESMTP id 4ZFzzr4Mv1z3hhS4; Sun, 16 Mar 2025 09:51:52 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=framepointer.org; s=default; t=1742133112; bh=ljc3oesl2r1E8aZ9fXFZUkkJvxGlE5eoRSoQ7GRd9BI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=W6mUAXpGW8eKDsk3RQqQf1r5sfZB1CoTtBbxRLZD63/fIA8qfKnmaH56gbUup/McR TsshCVehpJ4BjwfGTIrocewkeLKZR5PhYYaBY+a/w2vYkr4u1CpPY4m7oZyOE41djE kPqnJY/yq1jRZJUI6/UVyEepEUZXRb57PWxDZumxb+WrqFaR43qsOi5AUdBJF9ntnm pz7lqrkUFtTxceofxLH4Jo7m5l/FrDFkzTSjhv89C8XaIlzyW9BNlkDxN+G0DiPp/x KX0YW634bPJOL3VYaPnMGYf3v9D+PzfCEJp9Tz2YXXDfR4D0tHr0sMSK3dEJC+XKLp FYIuBHY/QyBlg== Received: from 65YTFL3.secure.tethers.com (unknown [152.44.190.141]) by mta-12.privateemail.com (Postfix) with ESMTPA; Sun, 16 Mar 2025 09:51:36 -0400 (EDT) From: Sam Winchenbach To: linux-kernel@vger.kernel.org Cc: lars@metafoo.de, Michael.Hennerich@analog.com, antoniu.miclaus@analog.com, jic23@kernel.org, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, sam.winchenbach@framepointer.org, bpellegrino@arka.org, Sam Winchenbach Subject: [PATCH v7 5/6] iio: core: Add support for writing 64 bit attrs Date: Sun, 16 Mar 2025 09:50:07 -0400 Message-ID: <20250316135008.155304-5-sam.winchenbach@framepointer.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250316135008.155304-1-sam.winchenbach@framepointer.org> References: <20250316135008.155304-1-sam.winchenbach@framepointer.org> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Virus-Scanned: ClamAV using ClamSMTP From: Sam Winchenbach Prior to this patch it was only possible to read 64 bit integers. Signed-off-by: Sam Winchenbach --- drivers/iio/industrialio-core.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c index a2117ad1337d..b2436b8f3eea 100644 --- a/drivers/iio/industrialio-core.c +++ b/drivers/iio/industrialio-core.c @@ -965,8 +965,10 @@ static ssize_t iio_write_channel_info(struct device *dev, struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); int ret, fract_mult = 100000; int integer, fract = 0; + long long integer64; bool is_char = false; bool scale_db = false; + bool is_64bit = false; /* Assumes decimal - precision based on number of digits */ if (!indio_dev->info->write_raw) @@ -990,6 +992,9 @@ static ssize_t iio_write_channel_info(struct device *dev, case IIO_VAL_CHAR: is_char = true; break; + case IIO_VAL_INT_64: + is_64bit = true; + break; default: return -EINVAL; } @@ -1000,6 +1005,13 @@ static ssize_t iio_write_channel_info(struct device *dev, if (sscanf(buf, "%c", &ch) != 1) return -EINVAL; integer = ch; + } else if (is_64bit) { + ret = kstrtoll(buf, 0, &integer64); + if (ret) + return ret; + + fract = (int)(integer64 >> 32); + integer = (int)(integer64 & 0xFFFFFFFF); } else { ret = __iio_str_to_fixpoint(buf, fract_mult, &integer, &fract, scale_db); From patchwork Sun Mar 16 13:50:08 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Winchenbach X-Patchwork-Id: 14018436 Received: from out-16.pe-a.jellyfish.systems (out-16.pe-a.jellyfish.systems [198.54.127.94]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C8DF025771; Sun, 16 Mar 2025 13:52:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.54.127.94 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742133133; cv=none; b=o+t0p9FY9e0KmSXS98gNg5D90z8x2DAUjs4RnEc4H4z5PvE2GADIaIDWE5iPUe9hc8yYS7SPbHl8CHuBTxAECZSQCuZk+s5JiQgMzzhxU8ET8BtTBX4jCD3EzStv3Pu9DvMkRldUrxBw4GaIf2Y3pGmUXtdTEGLupN/2JmIiRYA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742133133; c=relaxed/simple; bh=1SiD7gk+5xuC4ORw4uMLtYSs0AGjK7z7UEPewOOQSLE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UVGbKOZdrMBkgWCZXpdRu5SIs4gWRUlO2rq/EKuu9lysEgn5VAFU0Dzmac/+ZyspLrXLupL0P9iNvoEjztFpO1XxtCk3W8TrBG77PSDWygaxW7l4zqjBGgkjuzEqOzbP0cKwuslbIrwSO0w9Dsk9HRZTrTAnD3LV66oxOYCx2Ts= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=framepointer.org; spf=pass smtp.mailfrom=framepointer.org; dkim=pass (2048-bit key) header.d=framepointer.org header.i=@framepointer.org header.b=Rf1esN3p; arc=none smtp.client-ip=198.54.127.94 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=framepointer.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=framepointer.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=framepointer.org header.i=@framepointer.org header.b="Rf1esN3p" Received: from prod-lbout-phx.jellyfish.systems (new-01-3.privateemail.com [66.29.159.56]) by pe-a.jellyfish.systems (Postfix) with ESMTPA id 4ZG0086Jr2z4wSq; Sun, 16 Mar 2025 13:52:08 +0000 (UTC) Received: from MTA-12.privateemail.com (unknown [10.50.14.28]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by NEW-01-3.privateemail.com (Postfix) with ESMTPS id 4ZG0085ygZz2Sd0Q; Sun, 16 Mar 2025 09:52:08 -0400 (EDT) Received: from mta-12.privateemail.com (localhost [127.0.0.1]) by mta-12.privateemail.com (Postfix) with ESMTP id 4ZG0084mNqz3hhV5; Sun, 16 Mar 2025 09:52:08 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=framepointer.org; s=default; t=1742133128; bh=1SiD7gk+5xuC4ORw4uMLtYSs0AGjK7z7UEPewOOQSLE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Rf1esN3piRyXtg+VzuzssDJokUZP+TSrlTQrJqoRcO7Y8f7MVwn4OU1SPc+2SJQ87 4WJzEGjbK/kqGoKsXbrjRF0Yvx5S32EkforDG+8xqB+Q140HcvMoI8+b/W14Xb8f1x ma3qoInV9nwegtYOsM/GD0SOzjzilgR8bDu6TIPT53RQIWNFTwTe6WTiNEsVENQdzy RO5blupLRRSzX2PI141/TxEvcLmrTqiLKQgL7mPccVJRbM4j1i1+LyrM9rb5dy7s89 4QwJgK7FgMwWAbRznjLUBQueS2Fan6RtA/1pPt4NODfhvqVQU0R0MP7+aDSW6fob6q HmwJHrOtQmKEw== Received: from 65YTFL3.secure.tethers.com (unknown [152.44.190.141]) by mta-12.privateemail.com (Postfix) with ESMTPA; Sun, 16 Mar 2025 09:51:52 -0400 (EDT) From: Sam Winchenbach To: linux-kernel@vger.kernel.org Cc: lars@metafoo.de, Michael.Hennerich@analog.com, antoniu.miclaus@analog.com, jic23@kernel.org, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, sam.winchenbach@framepointer.org, bpellegrino@arka.org, Sam Winchenbach Subject: [PATCH v7 6/6] iio: filter: admv8818: Support frequencies >= 2^32 Date: Sun, 16 Mar 2025 09:50:08 -0400 Message-ID: <20250316135008.155304-6-sam.winchenbach@framepointer.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250316135008.155304-1-sam.winchenbach@framepointer.org> References: <20250316135008.155304-1-sam.winchenbach@framepointer.org> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Virus-Scanned: ClamAV using ClamSMTP From: Brian Pellegrino This patch allows writing u64 values to the ADMV8818's high and low-pass filter frequencies. It includes the following changes: - Rejects negative frequencies in admv8818_write_raw. - Adds a write_raw_get_fmt function to admv8818's iio_info, returning IIO_VAL_INT_64 for the high and low-pass filter 3dB frequency channels. Fixes: f34fe888ad05 ("iio:filter:admv8818: add support for ADMV8818") Signed-off-by: Brian Pellegrino Signed-off-by: Sam Winchenbach --- drivers/iio/filter/admv8818.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/drivers/iio/filter/admv8818.c b/drivers/iio/filter/admv8818.c index 380e119b3cf5..cc8ce0fe74e7 100644 --- a/drivers/iio/filter/admv8818.c +++ b/drivers/iio/filter/admv8818.c @@ -402,6 +402,19 @@ static int admv8818_read_lpf_freq(struct admv8818_state *st, u64 *lpf_freq) return ret; } +static int admv8818_write_raw_get_fmt(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + long mask) +{ + switch (mask) { + case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY: + case IIO_CHAN_INFO_HIGH_PASS_FILTER_3DB_FREQUENCY: + return IIO_VAL_INT_64; + default: + return -EINVAL; + } +} + static int admv8818_write_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int val, int val2, long info) @@ -410,6 +423,9 @@ static int admv8818_write_raw(struct iio_dev *indio_dev, u64 freq = ((u64)val2 << 32 | (u32)val); + if ((s64)freq < 0) + return -EINVAL; + switch (info) { case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY: return admv8818_lpf_select(st, freq); @@ -571,6 +587,7 @@ static int admv8818_set_mode(struct iio_dev *indio_dev, static const struct iio_info admv8818_info = { .write_raw = admv8818_write_raw, + .write_raw_get_fmt = admv8818_write_raw_get_fmt, .read_raw = admv8818_read_raw, .debugfs_reg_access = &admv8818_reg_access, };