From nobody Tue Dec 16 07:32:59 2025 Received: from mx0a-00128a01.pphosted.com (mx0a-00128a01.pphosted.com [148.163.135.77]) (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 7E822221294; Thu, 8 May 2025 17:03:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.135.77 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746723814; cv=none; b=pdN9rfs653gGJcC865ZzHv9K69bNxvZTxwZczEtkBTn+ZKGu9N8gtMSqk92uBI+fo0rtI02hDu0SLDooCUuL1TJyrCB6xixptPYMgBxMN1f2dOW9hGrQi+cdAR1qFqUCl91F/Hd6cYLLgzHCWOQ0FkD20fhrXWIQhrVkLTHF144= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746723814; c=relaxed/simple; bh=QEBDyAlC6IBFJ3sx3/iYLUcQz4JHeHxm6pFUeaRv22c=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=qisAdlORVOFT/sAK4T6m/qAUivzIVs8V+fteXQsiONEpnqJGERfvI+tN75OIqFADaXwes8D/ckXjAltmt9NNHFzUXd11B0h3j2TxXEeriOFhTAlhi6kfr8JhOWV2t+1upEySYzYoRbOVIb6ggs6IeALlNNOgUrIJlvcXzxEf14Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=analog.com; spf=pass smtp.mailfrom=analog.com; dkim=pass (2048-bit key) header.d=analog.com header.i=@analog.com header.b=eyoCpGm7; arc=none smtp.client-ip=148.163.135.77 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=analog.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=analog.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=analog.com header.i=@analog.com header.b="eyoCpGm7" Received: from pps.filterd (m0167088.ppops.net [127.0.0.1]) by mx0a-00128a01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 548DMfSq013536; Thu, 8 May 2025 13:03:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=analog.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=DKIM; bh=Qifrm 1q1nVUMq8tY1XfT1vophS/+sIv9dTAlLT6FCfM=; b=eyoCpGm7xXmwMyq/QP4kl Jfsrn5rRlGCwMvUPvuSl6kh6MeCUXGMazjpFJiaxgm6PVBX+HZK2kp0rbSL6Gmym BJ1iW5Pg3B2k7kXWbbdf4c6vqgrZsCyX0b0fo8i56ZOc9cbxngoBkGfmAAjdPdMM X02esnwUhi+2ssviwEqviYkjgxN50sJup+B70zX+m7tgvpfVs4g5PSYratiJz82z /bK56V+TCdgz2dtVR14H0f67CRIflAigYPt+sd/wTXFtqg2PZq+AJ9dDfNimYsZZ QSOd8DvPBNGbLkbMSCT7f/F22QjqHGtCigSg8S1cTipuSnVmNZe2IIlM8iHur4fM w== Received: from nwd2mta4.analog.com ([137.71.173.58]) by mx0a-00128a01.pphosted.com (PPS) with ESMTPS id 46gpct32a0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 May 2025 13:03:23 -0400 (EDT) Received: from ASHBMBX8.ad.analog.com (ASHBMBX8.ad.analog.com [10.64.17.5]) by nwd2mta4.analog.com (8.14.7/8.14.7) with ESMTP id 548H3M6j022695 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 8 May 2025 13:03:22 -0400 Received: from ASHBMBX8.ad.analog.com (10.64.17.5) by ASHBMBX8.ad.analog.com (10.64.17.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.14; Thu, 8 May 2025 13:03:22 -0400 Received: from zeus.spd.analog.com (10.66.68.11) by ashbmbx8.ad.analog.com (10.64.17.5) with Microsoft SMTP Server id 15.2.986.14 via Frontend Transport; Thu, 8 May 2025 13:03:21 -0400 Received: from JSANTO12-L01.ad.analog.com ([10.65.60.206]) by zeus.spd.analog.com (8.15.1/8.15.1) with ESMTP id 548H35du015862; Thu, 8 May 2025 13:03:07 -0400 From: Jonathan Santos To: , , , CC: Jonathan Santos , , , , , , , , , , , , , , , Subject: [PATCH v7 01/12] iio: adc: ad7768-1: reorganize driver headers Date: Thu, 8 May 2025 14:03:04 -0300 Message-ID: <1f7677d31a0165cb30d7eb3b4d613e1337937f9a.1746662899.git.Jonathan.Santos@analog.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ADIRuleOP-NewSCL: Rule Triggered X-Authority-Analysis: v=2.4 cv=J/eq7BnS c=1 sm=1 tr=0 ts=681ce3db cx=c_pps a=3WNzaoukacrqR9RwcOSAdA==:117 a=3WNzaoukacrqR9RwcOSAdA==:17 a=dt9VzEwgFbYA:10 a=gAnH3GRIAAAA:8 a=hyw8zsYP-pVXasy_sKEA:9 X-Proofpoint-GUID: pfZypD94Ri7p9AEVVOv93fgQCUQ6_WAA X-Proofpoint-ORIG-GUID: pfZypD94Ri7p9AEVVOv93fgQCUQ6_WAA X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUwNTA4MDE0OSBTYWx0ZWRfXytbYS8ufM41p eyyFrEkIIT5N1vQx7UdOD6x51KQDEirk9hQfdsMQyIJW1NYHW+PWsF6PiBI++EPUxktG5KJCfyX v84dcwa08yRHZc5iyZK+qwQVR/yEOMTrhl7AcaTZc671SRZVV0gPBH9uxMdEm38CGib3GLd+U2m agwFiJf9jAL8C75qJikVwkQILCjx0mUXSuSWfayT4ozbi8jGMnNwiQuxZk5PyP6ETR5o3gEB+dI qDQOxGvndii9ETNjdVaszzZJGIlsT4XsxzTkImOpickIEpO+iZZfcrmLMiC5DTXpOAfYHHp3uL+ 65yPbB1PjJK45z5wI1RXnYVeDB5U0gBwGYcgRBRoOOvqk+7DWOVGEA53naPphVOf02215xbfDNX pe9hx2wJOlkD+3uUQdFmfCFHOw2COrQtn1QB1OOFjwffT+aECAutOqfGPECvJz7sl7a1waUH X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1099,Hydra:6.0.736,FMLib:17.12.80.40 definitions=2025-05-08_05,2025-05-08_02,2025-02-21_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 impostorscore=0 adultscore=0 lowpriorityscore=0 mlxlogscore=585 priorityscore=1501 bulkscore=0 phishscore=0 malwarescore=0 spamscore=0 mlxscore=0 clxscore=1015 classifier=spam authscore=0 authtc=n/a authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.19.0-2504070000 definitions=main-2505080149 Content-Type: text/plain; charset="utf-8" Remove kernel.h since it adds a lot of unnecessary dependencies. Add specific headers to ensure all functions and macros used in the driver are directly declared. Signed-off-by: Jonathan Santos Reviewed-by: Andy Shevchenko Suggested-by: ? --- v7 Changes: * New patch. --- drivers/iio/adc/ad7768-1.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/iio/adc/ad7768-1.c b/drivers/iio/adc/ad7768-1.c index 09e4ab76e2b6..e90bb5d50076 100644 --- a/drivers/iio/adc/ad7768-1.c +++ b/drivers/iio/adc/ad7768-1.c @@ -4,13 +4,15 @@ * * Copyright 2017 Analog Devices Inc. */ +#include #include #include +#include #include #include #include #include -#include +#include #include #include #include --=20 2.34.1 From nobody Tue Dec 16 07:32:59 2025 Received: from mx0a-00128a01.pphosted.com (mx0a-00128a01.pphosted.com [148.163.135.77]) (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 9DBD827EC97; Thu, 8 May 2025 17:03:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.135.77 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746723829; cv=none; b=Bmmj7T58eGj5AjVMACqdY6SbRQeG95VtVQwsNVMyiAosgGp01jn8MMSCHIs66tEMDvANR7UiJCoi5sCrdXxQcjR1UNorZ9J6Fz8BwtU6klM2B1isQw+mz4JieYvViRrj62krJl3v/sNhfL6O2sDvz2naIggZnSJhev6PMOZcgQE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746723829; c=relaxed/simple; bh=m3I58HrDmlvoGElzpdwpTEUidcNDsJw1DG5TAUtrYD8=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=BkRCZuub+vLfwJoqrz8um611r9SxrRosF58YWweBW0UDA6Q4TitCeRmRw4lo1CS15dAKbriuEwW6fX1GvdhOqmt784g6ci8sKWvsloyxrcTmMDdlZT8tUzvuSSYTOeITdl6/wzbpI76vs/Bx/+YY6Vth2vaMLVozk26R4yhljWw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=analog.com; spf=pass smtp.mailfrom=analog.com; dkim=pass (2048-bit key) header.d=analog.com header.i=@analog.com header.b=r+yXw4CT; arc=none smtp.client-ip=148.163.135.77 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=analog.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=analog.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=analog.com header.i=@analog.com header.b="r+yXw4CT" Received: from pps.filterd (m0167089.ppops.net [127.0.0.1]) by mx0a-00128a01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 548D9RS7023987; Thu, 8 May 2025 13:03:34 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=analog.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=DKIM; bh=2ezEa LB2hRO8T2W7HKZXEHo+sGui8Nd3NnjVrK7761c=; b=r+yXw4CTtzcfysUPrWblm KfW/ZEHVcWFCT4XJWwBihxcpntaqy5YOhO9TTQpKtnwgu91Lga6QxoMIr48amlgy pkLUXjD4vtXQctlBPbT52qoVRNaPVLmGY+6YmV0EOKUodltMTphg6ZaCw/lJU4Qr y0p3u1Exy/TvOvbwUSfkTwbwjxFAOO0MHNSa8BtmIVmDcosF+1fRRIULICEPK25W 7F+ud4nidEUbO/2pVeaWbqS2TWcXfaVnstnCcCbmOeye0piXn2HfaRATxcfHaBSG Y1PYk2pQVYyf/xrotdxjLiD/6seX/IjN3GQYoUXGpF9bdo9nkJM8G51iGiq7nH6o A== Received: from nwd2mta4.analog.com ([137.71.173.58]) by mx0a-00128a01.pphosted.com (PPS) with ESMTPS id 46gpctb1gk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 May 2025 13:03:33 -0400 (EDT) Received: from ASHBMBX8.ad.analog.com (ASHBMBX8.ad.analog.com [10.64.17.5]) by nwd2mta4.analog.com (8.14.7/8.14.7) with ESMTP id 548H3WpT022701 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 8 May 2025 13:03:32 -0400 Received: from ASHBCASHYB4.ad.analog.com (10.64.17.132) by ASHBMBX8.ad.analog.com (10.64.17.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.14; Thu, 8 May 2025 13:03:32 -0400 Received: from ASHBMBX8.ad.analog.com (10.64.17.5) by ASHBCASHYB4.ad.analog.com (10.64.17.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.14; Thu, 8 May 2025 13:03:32 -0400 Received: from zeus.spd.analog.com (10.66.68.11) by ashbmbx8.ad.analog.com (10.64.17.5) with Microsoft SMTP Server id 15.2.986.14 via Frontend Transport; Thu, 8 May 2025 13:03:32 -0400 Received: from JSANTO12-L01.ad.analog.com ([10.65.60.206]) by zeus.spd.analog.com (8.15.1/8.15.1) with ESMTP id 548H3HLF015866; Thu, 8 May 2025 13:03:20 -0400 From: Jonathan Santos To: , , , CC: Jonathan Santos , , , , , , , , , , , , , , , Subject: [PATCH v7 02/12] dt-bindings: trigger-source: add generic GPIO trigger source Date: Thu, 8 May 2025 14:03:17 -0300 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ADIRuleOP-NewSCL: Rule Triggered X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUwNTA4MDE0OSBTYWx0ZWRfX/8QaHkh6Puc5 hT6h3VdAVis3oftVPWaPcyC0+WWRgpTGxQD/FH9nVuTh7N6JwVPcAv8V82k0JcnMLg9lvcuOwUJ gSEe3T1PHPqaBe7Rfbp2cfd7ZnzxgV67U2KU7WYdy8wseDkXgP7oVbduAjcbBu3riYuhSKL9hkw tzNDy/kfksQxn3etpWwImYU2ILZeZu4jiz7WM9I97GYUoQWD9TbfNKGLL5hVlKUmGaigQBkofT1 kC1u8FVia6fIDvjlYHAODqZwMeKaygel2cLG92RENyX5cSQppb31DcR1OCbanpzo/y9VFRUVepG NZeHdVS9iZq9Td8NxfBpMFQXdxFEer7nRscsoG8le5EM4gkuTtjKvuPrSbYhNzOeuV9DSVqi02o FctiQFVDzYp/WSsvdzgP8MGsPzOGI083XIhitXRBiyOzio/XakUBOJf6l05epNgscPwKSwPi X-Authority-Analysis: v=2.4 cv=Ur5jN/wB c=1 sm=1 tr=0 ts=681ce3e5 cx=c_pps a=3WNzaoukacrqR9RwcOSAdA==:117 a=3WNzaoukacrqR9RwcOSAdA==:17 a=dt9VzEwgFbYA:10 a=VwQbUJbxAAAA:8 a=IpJZQVW2AAAA:8 a=gEfo2CItAAAA:8 a=NEAV23lmAAAA:8 a=gAnH3GRIAAAA:8 a=T3kYclMwKmv6rGiKBMkA:9 a=IawgGOuG5U0WyFbmm1f5:22 a=sptkURWiP4Gy88Gu7hUp:22 X-Proofpoint-GUID: lQJ-CaoQtafZnJJwe4hhuYsBL6BbWAB- X-Proofpoint-ORIG-GUID: lQJ-CaoQtafZnJJwe4hhuYsBL6BbWAB- X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1099,Hydra:6.0.736,FMLib:17.12.80.40 definitions=2025-05-08_05,2025-05-08_02,2025-02-21_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 suspectscore=0 adultscore=0 bulkscore=0 malwarescore=0 priorityscore=1501 spamscore=0 impostorscore=0 lowpriorityscore=0 mlxlogscore=999 clxscore=1015 phishscore=0 classifier=spam authscore=0 authtc=n/a authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.19.0-2504070000 definitions=main-2505080149 Content-Type: text/plain; charset="utf-8" Inspired by pwm-trigger, create a new binding for using a GPIO line as a trigger source. Link: https://lore.kernel.org/linux-iio/20250207-dlech-mainline-spi-engine-= offload-2-v8-3-e48a489be48c@baylibre.com/ Reviewed-by: David Lechner Signed-off-by: Jonathan Santos Acked-by: Conor Dooley Acked-by: David Lechner Reviewed-by: Linus Walleij --- v7 Changes: * File added to MAINTAINERS and Made trigger source generic to include both= pwm and gpio. v6 Changes: * Changed description. * Fixed typos and replaced GPIO pin with GPIO line. * Added link reference for pwm-trigger. v5 Changes: * New patch in v5. --- .../bindings/trigger-source/gpio-trigger.yaml | 40 +++++++++++++++++++ MAINTAINERS | 3 +- 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 Documentation/devicetree/bindings/trigger-source/gpio-t= rigger.yaml diff --git a/Documentation/devicetree/bindings/trigger-source/gpio-trigger.= yaml b/Documentation/devicetree/bindings/trigger-source/gpio-trigger.yaml new file mode 100644 index 000000000000..1331d153ee82 --- /dev/null +++ b/Documentation/devicetree/bindings/trigger-source/gpio-trigger.yaml @@ -0,0 +1,40 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/trigger-source/gpio-trigger.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Generic trigger source using GPIO + +description: A GPIO used as a trigger source. + +maintainers: + - Jonathan Santos + +properties: + compatible: + const: gpio-trigger + + '#trigger-source-cells': + const: 0 + + gpios: + maxItems: 1 + description: GPIO to be used as a trigger source. + +required: + - compatible + - '#trigger-source-cells' + - gpios + +additionalProperties: false + +examples: + - | + #include + + trigger { + compatible =3D "gpio-trigger"; + #trigger-source-cells =3D <0>; + gpios =3D <&gpio1 15 GPIO_ACTIVE_HIGH>; + }; diff --git a/MAINTAINERS b/MAINTAINERS index 01079a189c93..9b2e9a9dd8bc 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -24569,9 +24569,10 @@ W: https://github.com/srcres258/linux-doc T: git git://github.com/srcres258/linux-doc.git doc-zh-tw F: Documentation/translations/zh_TW/ =20 -TRIGGER SOURCE - PWM +TRIGGER SOURCE M: David Lechner S: Maintained +F: Documentation/devicetree/bindings/trigger-source/gpio-trigger.yaml F: Documentation/devicetree/bindings/trigger-source/pwm-trigger.yaml =20 TRUSTED SECURITY MODULE (TSM) ATTESTATION REPORTS --=20 2.34.1 From nobody Tue Dec 16 07:32:59 2025 Received: from mx0a-00128a01.pphosted.com (mx0a-00128a01.pphosted.com [148.163.135.77]) (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 B6B61284674; Thu, 8 May 2025 17:04:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.135.77 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746723844; cv=none; b=BG34h4aixRvpQDMlBnQnluu8Kt1+uijhNgV+AuSFLsaDPJk7iwfrsBf7eEDlUUeLKfZ5zGe92Wy5iJeKYaL2QiUW/Kdo11BaucG4jv0UwkVPPrkXVgHkk+uIGdJWg1n0nGWzPLJnb/GwhQDlzpBgSmUmDueBG7VPWlrw6IsVAoA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746723844; c=relaxed/simple; bh=FDdd3AzrvUKmvLBkPDtbL6SCjhIbc5fPyIcAhFnKBpM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=e7jn4K/SsGitN9bu1yMU0GXA47M8ndjdYQFfeI0ASdoguLvvVCvlPSUgaOm3rNH054/on26/AQEu8T0jQBvGA1YSZYEdy2hOZyWqgu/c6K0eqeLQa7GudY/oIaXbGZwYeY28X8Ug+EONrfW2U7WLV7HgAucaiC1h6FWvA4bv5QQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=analog.com; spf=pass smtp.mailfrom=analog.com; dkim=pass (2048-bit key) header.d=analog.com header.i=@analog.com header.b=JEmNOtsm; arc=none smtp.client-ip=148.163.135.77 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=analog.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=analog.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=analog.com header.i=@analog.com header.b="JEmNOtsm" Received: from pps.filterd (m0167089.ppops.net [127.0.0.1]) by mx0a-00128a01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 548Dgah6024375; Thu, 8 May 2025 13:03:52 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=analog.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=DKIM; bh=IuPLc b9P+beIj1G6fiMTPEuvJta118pZjYBj/kP3X8M=; b=JEmNOtsmwfmxX3eCRdWwV AqBukvU+/o2jvbq7RWWzBl5GZDe7j0Y11F12j3sT3uN/04rmk2kjSgIUm/mFSg+6 6M4Q+LDTFUdCYrNjzT9wqXabe9m/ygB5FU5PkJFMBp3IgDccWD6tCjxgeRDneObx 51SJ1xEZxFD0bkvIODFZnsY0j2ouZW4sp5uGLuEghsJs0zgqfB677WRWoEMmTvc1 5+zHsFaUzLpC760/FbslNdL0zRReuTcUTUWHlxJD5UpJw7XprAVrPH76WKyroyGX c4ZqpZv0Raods4uWua6uRoWNPrqHI8mqRcOBks48oi/p6xWa4OB3jSwCQAu3vwYL w== Received: from nwd2mta4.analog.com ([137.71.173.58]) by mx0a-00128a01.pphosted.com (PPS) with ESMTPS id 46gpctb1k3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 May 2025 13:03:52 -0400 (EDT) Received: from ASHBMBX8.ad.analog.com (ASHBMBX8.ad.analog.com [10.64.17.5]) by nwd2mta4.analog.com (8.14.7/8.14.7) with ESMTP id 548H3onG022704 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 8 May 2025 13:03:50 -0400 Received: from ASHBMBX8.ad.analog.com (10.64.17.5) by ASHBMBX8.ad.analog.com (10.64.17.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.14; Thu, 8 May 2025 13:03:50 -0400 Received: from zeus.spd.analog.com (10.66.68.11) by ashbmbx8.ad.analog.com (10.64.17.5) with Microsoft SMTP Server id 15.2.986.14 via Frontend Transport; Thu, 8 May 2025 13:03:50 -0400 Received: from JSANTO12-L01.ad.analog.com ([10.65.60.206]) by zeus.spd.analog.com (8.15.1/8.15.1) with ESMTP id 548H3UIo015870; Thu, 8 May 2025 13:03:32 -0400 From: Jonathan Santos To: , , , CC: Jonathan Santos , , , , , , , , , , , , , , , , David Lechner Subject: [PATCH v7 03/12] dt-bindings: iio: adc: ad7768-1: add trigger-sources property Date: Thu, 8 May 2025 14:03:30 -0300 Message-ID: <731196750f27eee0bad5493647edb2f67a05a6e2.1746662899.git.Jonathan.Santos@analog.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ADIRuleOP-NewSCL: Rule Triggered X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUwNTA4MDE0OSBTYWx0ZWRfXyhwS/cPNM80o ZjKvJ1RkCraSngaw5dq/X5gYqdCCE6D83jE80JCyJr6LPaHiz7zf56U83PnaEvpjJ5SPm9Dx4sF +wiRH3holthMjhNq+7pNaooaukKqVK3qWCvX1k6fmvlwkJTfY8Tzjm754FfQSLRVTvIg3aYnqnd cq8ekbKGRPnnbDZiVzk/s66tZji9vm2rPVMVMkFfUljbWz/6A0SLi3/edXY5xVAAbV0UJdjIhsf pSY6Cuc9mO9jmu0Xzsh7RadK8uxYyCtCW7AZRY9v02iLoyO6y0A8dST5RnlHxYxXWo/LLUOMjxu mq7RkKhYI8jXsAB9LiIUtV/3ZTcV8dgG6zI+ypExWifUU7IB6sdA2D6Afv+gPMhdAYo81BzuLFX QWvTtvgu7ZYyLq3O7FTPBBecrOF7Uejm199wImR2qpK34xm80JxzHKibcBPhlo9NuNw34Ueq X-Authority-Analysis: v=2.4 cv=Ur5jN/wB c=1 sm=1 tr=0 ts=681ce3f8 cx=c_pps a=3WNzaoukacrqR9RwcOSAdA==:117 a=3WNzaoukacrqR9RwcOSAdA==:17 a=dt9VzEwgFbYA:10 a=gAnH3GRIAAAA:8 a=3yuoaRSoAAAA:8 a=Lq6TyEz25fwpf9jyvVMA:9 a=2SAQt7U6PxkJVs8Pt8Bp:22 X-Proofpoint-GUID: ym0iId0qNCsicHxIMpF2_1m_-vZ8JExB X-Proofpoint-ORIG-GUID: ym0iId0qNCsicHxIMpF2_1m_-vZ8JExB X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1099,Hydra:6.0.736,FMLib:17.12.80.40 definitions=2025-05-08_05,2025-05-08_02,2025-02-21_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 suspectscore=0 adultscore=0 bulkscore=0 malwarescore=0 priorityscore=1501 spamscore=0 impostorscore=0 lowpriorityscore=0 mlxlogscore=999 clxscore=1011 phishscore=0 classifier=spam authscore=0 authtc=n/a authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.19.0-2504070000 definitions=main-2505080149 Content-Type: text/plain; charset="utf-8" In addition to GPIO synchronization, The AD7768-1 also supports synchronization over SPI, which use is recommended when the GPIO cannot provide a pulse synchronous with the base MCLK signal. It consists of looping back the SYNC_OUT to the SYNC_IN pin and send a command via SPI to trigger the synchronization. Introduce the 'trigger-sources' property to enable SPI-based synchronization via SYNC_OUT pin, along with additional optional entries for GPIO3 and DRDY pins. Also create #trigger-source-cells property to differentiate the trigger sources provided by the ADC. To improve readability, create a adi,ad7768-1.h header with the macros for the cell values. While at it, add description to the interrupts property. Reviewed-by: David Lechner Signed-off-by: Jonathan Santos Acked-by: Conor Dooley --- v7 Changes: * added new file to the MAINTAINERS entry. * Made interrupts description more concise. * Added dependencies to constrain the use of trigger-sources and adi,sync-in-gpios properties at the same time. v6 Changes: * Removed references to offload. * Changed trigger-sources-cells description. Each cell value indicates a gpio line from the ADC. * Added adi,ad7768-1.h header with macros for the trigger source cells. * Removed offload trigger entry from trigger-sources. v5 Changes: * Include START pin and DRDY in the trigger-sources description. * Fixed "#trigger-source-cells" value and description. * sync-in-gpios is represented in the trigger-sources property. v4 Changes: * none v3 Changes: * Fixed dt-bindings errors. * Trigger-source is set as an alternative to sync-in-gpios, so we don't break the previous ABI. * increased maxItems from trigger-sources to 2. v2 Changes: * Patch added as replacement for adi,sync-in-spi patch. * addressed the request for a description to interrupts property. --- .../bindings/iio/adc/adi,ad7768-1.yaml | 39 ++++++++++++++++++- MAINTAINERS | 1 + include/dt-bindings/iio/adc/adi,ad7768-1.h | 10 +++++ 3 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 include/dt-bindings/iio/adc/adi,ad7768-1.h diff --git a/Documentation/devicetree/bindings/iio/adc/adi,ad7768-1.yaml b/= Documentation/devicetree/bindings/iio/adc/adi,ad7768-1.yaml index 3ce59d4d065f..9a6df931edc3 100644 --- a/Documentation/devicetree/bindings/iio/adc/adi,ad7768-1.yaml +++ b/Documentation/devicetree/bindings/iio/adc/adi,ad7768-1.yaml @@ -26,7 +26,26 @@ properties: clock-names: const: mclk =20 + trigger-sources: + $ref: /schemas/types.yaml#/definitions/phandle-array + minItems: 1 + maxItems: 2 + description: | + A list of phandles referencing trigger source providers. Each entry + represents a trigger source for the ADC: + + - First entry specifies the device responsible for driving the + synchronization (SYNC_IN) pin, as an alternative to adi,sync-in-= gpios. + This can be a `gpio-trigger` or another `ad7768-1` device. If the + device's own SYNC_OUT pin is internally connected to its SYNC_IN= pin, + reference the device itself or omit this property. + - Second entry optionally defines a GPIO3 pin used as a START sign= al trigger. + + Use the accompanying trigger source cell to identify the type of eac= h entry. + interrupts: + description: + DRDY (Data Ready) pin, which signals conversion results are availabl= e. maxItems: 1 =20 '#address-cells': @@ -57,6 +76,15 @@ properties: "#io-channel-cells": const: 1 =20 + "#trigger-source-cells": + description: | + Cell indicates the trigger output signal: 0 =3D SYNC_OUT, 1 =3D GPIO= 3, + 2 =3D DRDY. + + For better readability, macros for these values are available in + dt-bindings/iio/adc/adi,ad7768-1.h. + const: 1 + required: - compatible - reg @@ -65,7 +93,16 @@ required: - vref-supply - spi-cpol - spi-cpha - - adi,sync-in-gpios + +dependencies: + adi,sync-in-gpios: + not: + required: + - trigger-sources + trigger-sources: + not: + required: + - adi,sync-in-gpios =20 patternProperties: "^channel@([0-9]|1[0-5])$": diff --git a/MAINTAINERS b/MAINTAINERS index 9b2e9a9dd8bc..be07926f6666 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1426,6 +1426,7 @@ S: Supported W: https://ez.analog.com/linux-software-drivers F: Documentation/devicetree/bindings/iio/adc/adi,ad7768-1.yaml F: drivers/iio/adc/ad7768-1.c +F: include/dt-bindings/iio/adc/adi,ad7768-1.h =20 ANALOG DEVICES INC AD7780 DRIVER M: Michael Hennerich diff --git a/include/dt-bindings/iio/adc/adi,ad7768-1.h b/include/dt-bindin= gs/iio/adc/adi,ad7768-1.h new file mode 100644 index 000000000000..34d92856a50b --- /dev/null +++ b/include/dt-bindings/iio/adc/adi,ad7768-1.h @@ -0,0 +1,10 @@ +/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */ + +#ifndef _DT_BINDINGS_ADI_AD7768_1_H +#define _DT_BINDINGS_ADI_AD7768_1_H + +#define AD7768_TRIGGER_SOURCE_SYNC_OUT 0 +#define AD7768_TRIGGER_SOURCE_GPIO3 1 +#define AD7768_TRIGGER_SOURCE_DRDY 2 + +#endif /* _DT_BINDINGS_ADI_AD7768_1_H */ --=20 2.34.1 From nobody Tue Dec 16 07:32:59 2025 Received: from mx0b-00128a01.pphosted.com (mx0a-00128a01.pphosted.com [148.163.135.77]) (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 E4F8F2853E0; Thu, 8 May 2025 17:04:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.135.77 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746723854; cv=none; b=GhSRHtkN7C8M3bZOjel0my73sj5ZMnfAou97hoCE9LAaVdbz2bNUNhV964vSAbEjsvDqZaVpHKOButkn95R88gzelZObzUBVKyTesWfcQIW7Xym+Cr0N/jgwDi01nkMstR99N95FldWXGezU65XmezGuosfk/mZeXWNKKHeTya4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746723854; c=relaxed/simple; bh=xKQoZ3FPpX0PdrITeGIukchMaZdVP8KH0O/FZPGgEKI=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ZvoxXcQDyYnYGIj/W2A/t2VEps/M/foaMLdGuMyqd03dYQ8jHwxlfmKG6ucz9rcp6knOBrr2j91bDPVIUeFEQNPy2VFB5aRfR97ZWMj0UXfR4Zv2LxXpxCaG71vfM1pcZAz6npML9T8Eurc74aXJmV9agJfMutMLaVq2tW1lEAk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=analog.com; spf=pass smtp.mailfrom=analog.com; dkim=pass (2048-bit key) header.d=analog.com header.i=@analog.com header.b=1N9mH6hk; arc=none smtp.client-ip=148.163.135.77 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=analog.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=analog.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=analog.com header.i=@analog.com header.b="1N9mH6hk" Received: from pps.filterd (m0375855.ppops.net [127.0.0.1]) by mx0b-00128a01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 548FSacW000730; Thu, 8 May 2025 13:04:05 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=analog.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=DKIM; bh=SJMoR KwboMh3dxngT7wJepVe84DuCSbqfN8MDEU+Tnc=; b=1N9mH6hke4IHelFDCDfyK 6n814cY+7DQmjl7YEfPX+tXbyHOSyAi4ksB6eyp+ZGmQ6PJoiOWEbDit74eCE5vw SLT2b+FKfbdN0On/qMclyDlo5bZVs150nBqb8TBM/jrOUfWqzX4G15WjSU800Od0 GTn9v87LA1CVKoLcFf+Cg+H1WkZaJLI9QzLGzwqQrbWAI/kLpiggq0YOBynMAial +DbfYxSMSHe3miGidx8wuqNiTrT4N21VV/m69OfDXIdGku6n2Tdvw40fhYEBefpo R5Yl1dITaeWoB0WgRXDsnRE4XcPg3S55PcVNLX7kc4ADsuBjPQVrffOdvXRhfdF7 g== Received: from nwd2mta4.analog.com ([137.71.173.58]) by mx0b-00128a01.pphosted.com (PPS) with ESMTPS id 46gy9q8d5w-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 May 2025 13:04:04 -0400 (EDT) Received: from ASHBMBX8.ad.analog.com (ASHBMBX8.ad.analog.com [10.64.17.5]) by nwd2mta4.analog.com (8.14.7/8.14.7) with ESMTP id 548H43XS022722 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 8 May 2025 13:04:03 -0400 Received: from ASHBMBX8.ad.analog.com (10.64.17.5) by ASHBMBX8.ad.analog.com (10.64.17.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.14; Thu, 8 May 2025 13:04:03 -0400 Received: from zeus.spd.analog.com (10.66.68.11) by ashbmbx8.ad.analog.com (10.64.17.5) with Microsoft SMTP Server id 15.2.986.14 via Frontend Transport; Thu, 8 May 2025 13:04:03 -0400 Received: from JSANTO12-L01.ad.analog.com ([10.65.60.206]) by zeus.spd.analog.com (8.15.1/8.15.1) with ESMTP id 548H3lBj015877; Thu, 8 May 2025 13:03:49 -0400 From: Jonathan Santos To: , , , CC: Jonathan Santos , , , , , , , , , , , , , , , , Bartosz Golaszewski Subject: [PATCH v7 04/12] dt-bindings: iio: adc: ad7768-1: Document GPIO controller Date: Thu, 8 May 2025 14:03:46 -0300 Message-ID: <1bd3ae9a4f0bc1296d97aae7db7b068ba7c462c9.1746662899.git.Jonathan.Santos@analog.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ADIRuleOP-NewSCL: Rule Triggered X-Proofpoint-GUID: ZoVT6cwPOsMk6vPvxBBA5Ww9Ixase4Zh X-Authority-Analysis: v=2.4 cv=f/ZIBPyM c=1 sm=1 tr=0 ts=681ce404 cx=c_pps a=3WNzaoukacrqR9RwcOSAdA==:117 a=3WNzaoukacrqR9RwcOSAdA==:17 a=dt9VzEwgFbYA:10 a=KKAkSRfTAAAA:8 a=VwQbUJbxAAAA:8 a=gAnH3GRIAAAA:8 a=FDCdkw0c5cjSjuxHnEwA:9 a=cvBusfyB2V15izCimMoJ:22 X-Proofpoint-ORIG-GUID: ZoVT6cwPOsMk6vPvxBBA5Ww9Ixase4Zh X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUwNTA4MDE0OSBTYWx0ZWRfXw6fECl81X7xR cXkoff0gdLL42g+hNvEiYHb937Tpv6yzqgt7IL9CpLTaLEZTbPGSJ/Tj0wAnhwXyZZLpZQE2viJ Nx0/yRh8tewzslCOCNhWsEATx+p7ir9s4KSkgkVLB49ouKefCGb3MEgusP048o71kSP7jm4RyKy mjLmnt3Mxks3fErDNrieeAiDG96EaDNvdtIYTE67+qJoeTjhOsoC8yaKmSRvxgc0iVcaQLx1vEi nF5ZEzZBlr8JLvpUK03O8bN4FW2AcuRPFNeQ+JOV6GBGyahdE747nC7AI06Q6lW70yRS0VTPG1Y /eGhE164OxF2Ofuqb2nCBggYC4hU3/aXTUuoX0xigF0kEDQbg5oXmTsgpvfA4MxpFggbOLf1mA2 uNlRo+MNr0oUcT5el5qFrLGaA7Cjka9tWW6MRA6yheGW6WOpQJ++umaJjc3Fyfys6zsRCGw3 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1099,Hydra:6.0.736,FMLib:17.12.80.40 definitions=2025-05-08_05,2025-05-08_02,2025-02-21_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 malwarescore=0 adultscore=0 mlxscore=0 impostorscore=0 suspectscore=0 priorityscore=1501 phishscore=0 bulkscore=0 lowpriorityscore=0 spamscore=0 mlxlogscore=999 classifier=spam authscore=0 authtc=n/a authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.19.0-2504070000 definitions=main-2505080149 Content-Type: text/plain; charset="utf-8" The AD7768-1 ADC exports four bidirectional GPIOs accessible via register map. Document GPIO properties necessary to enable GPIO controller for this device. Acked-by: Bartosz Golaszewski Reviewed-by: Linus Walleij Reviewed-by: Rob Herring (Arm) Signed-off-by: Jonathan Santos --- v7 Changes: * none. v6 Changes: * none. v5 Changes: * none. v4 Changes: * none. v3 Changes: * none. v2 Changes: * New --- .../devicetree/bindings/iio/adc/adi,ad7768-1.yaml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Documentation/devicetree/bindings/iio/adc/adi,ad7768-1.yaml b/= Documentation/devicetree/bindings/iio/adc/adi,ad7768-1.yaml index 9a6df931edc3..18f93586fcdf 100644 --- a/Documentation/devicetree/bindings/iio/adc/adi,ad7768-1.yaml +++ b/Documentation/devicetree/bindings/iio/adc/adi,ad7768-1.yaml @@ -85,6 +85,14 @@ properties: dt-bindings/iio/adc/adi,ad7768-1.h. const: 1 =20 + gpio-controller: true + + "#gpio-cells": + const: 2 + description: | + The first cell is for the GPIO number: 0 to 3. + The second cell takes standard GPIO flags. + required: - compatible - reg @@ -142,6 +150,8 @@ examples: spi-max-frequency =3D <2000000>; spi-cpol; spi-cpha; + gpio-controller; + #gpio-cells =3D <2>; vref-supply =3D <&adc_vref>; interrupts =3D <25 IRQ_TYPE_EDGE_RISING>; interrupt-parent =3D <&gpio>; --=20 2.34.1 From nobody Tue Dec 16 07:32:59 2025 Received: from mx0b-00128a01.pphosted.com (mx0a-00128a01.pphosted.com [148.163.135.77]) (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 2525027EC97; Thu, 8 May 2025 17:04:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.135.77 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746723868; cv=none; b=kkxguXjQsg1LkbQwU8V31WIR3eo3ujzJLt5Bf8CPKyL9vMzQQC8fQWuwADDpF/uMsgaczEbpPZYDC64f9zetS5cox3BvNaYW3R/i0lUieSnInND+SlyvPZqh1xM8kkuhO8cTNEJqI6MxyDtEmlBGy3YVYVrBBdF1RfG1XiAkzf4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746723868; c=relaxed/simple; bh=QUx4DkfRGNvgTQEGfSV3o7rJVu41RqTvUh+gXUHUmI0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=E4xyjdIPx+9VoQFfob+XVh3xnXF2GSoCtzgfxj8Dmjl55Hs1g9+woNMxdRe1dmcNP9rvmYY0uNpa7fqx+tkN/NFOhEgh7uTGNFicalgUoFtyy8nMFOMdaO93mUKdpzKJppVw0/dQg4XpCSjJnTpaE4uxipRqWjgvD49Ara4NwMw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=analog.com; spf=pass smtp.mailfrom=analog.com; dkim=pass (2048-bit key) header.d=analog.com header.i=@analog.com header.b=R+2uRi9z; arc=none smtp.client-ip=148.163.135.77 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=analog.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=analog.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=analog.com header.i=@analog.com header.b="R+2uRi9z" Received: from pps.filterd (m0375855.ppops.net [127.0.0.1]) by mx0b-00128a01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 548FSacc000730; Thu, 8 May 2025 13:04:18 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=analog.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=DKIM; bh=2cP5F VzGyD6F84yq+AftavMjlbUCQBvGasgEENghFQQ=; b=R+2uRi9zOW/hN9QeaCxOF HKE6mOHVCBRkgczezkjd4BIb9XdFZk5vhNXuHYPIQ5t1EtcQQXwjocbsCCIxfUjz s7f+tOAqA40zk0CVTGZ4C/dOX5IJ6hagPNUVGJBsFb9IVVPIz7b5uni3L1yEWVpg j3eA3CDz/gPfD5sNDxr1lXyS2CH4xEnopEEPlVIabTZpZhpii2RKK1IvaVTN8/lS Iyz7oECQYA0ga+p0hP34+9VHlcxTUAtrJvY+oYAcBx4JDQXRY+pN6tqiguGkiY77 AzcMpoD+yZj9FcHhmlHWlPqUTyue5Ds4WjwCYGhZ4N5VSmkjbpziDIalvnJIDoPo A== Received: from nwd2mta4.analog.com ([137.71.173.58]) by mx0b-00128a01.pphosted.com (PPS) with ESMTPS id 46gy9q8d7f-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 May 2025 13:04:17 -0400 (EDT) Received: from ASHBMBX8.ad.analog.com (ASHBMBX8.ad.analog.com [10.64.17.5]) by nwd2mta4.analog.com (8.14.7/8.14.7) with ESMTP id 548H4GEi022758 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 8 May 2025 13:04:16 -0400 Received: from ASHBMBX8.ad.analog.com (10.64.17.5) by ASHBMBX8.ad.analog.com (10.64.17.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.14; Thu, 8 May 2025 13:04:16 -0400 Received: from zeus.spd.analog.com (10.66.68.11) by ashbmbx8.ad.analog.com (10.64.17.5) with Microsoft SMTP Server id 15.2.986.14 via Frontend Transport; Thu, 8 May 2025 13:04:16 -0400 Received: from JSANTO12-L01.ad.analog.com ([10.65.60.206]) by zeus.spd.analog.com (8.15.1/8.15.1) with ESMTP id 548H3xcB015885; Thu, 8 May 2025 13:04:02 -0400 From: Jonathan Santos To: , , , CC: Jonathan Santos , , , , , , , , , , , , , , , , Conor Dooley Subject: [PATCH v7 05/12] dt-bindings: iio: adc: ad7768-1: document regulator provider property Date: Thu, 8 May 2025 14:03:59 -0300 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ADIRuleOP-NewSCL: Rule Triggered X-Proofpoint-GUID: 5MKn3SDCtthx4Yar1O74cbw1OZ6jXVRk X-Authority-Analysis: v=2.4 cv=f/ZIBPyM c=1 sm=1 tr=0 ts=681ce411 cx=c_pps a=3WNzaoukacrqR9RwcOSAdA==:117 a=3WNzaoukacrqR9RwcOSAdA==:17 a=dt9VzEwgFbYA:10 a=XYAwZIGsAAAA:8 a=gAnH3GRIAAAA:8 a=J1-tWBq05h-qFn0eaeUA:9 a=E8ToXWR_bxluHZ7gmE-Z:22 X-Proofpoint-ORIG-GUID: 5MKn3SDCtthx4Yar1O74cbw1OZ6jXVRk X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUwNTA4MDE0OSBTYWx0ZWRfXyIxgBmjrEjB9 vKgakGVyYs6rneoEYkFPJQw2MuqcOrpRPgKqwJwslYDsZfJvp2Fm78Gn2AA5Kcob6UO1T1J+fLh nIYW6gLEyjkvgBVgxUMA6Tsj7vP7kQfOcw9jpZadDYcD4z2k8U4nj3yOWOCbRejCFeMyAJ0fFVA v3RVhtTm+qO5+CnSTdMw0jPSw/OFk4gFXESdeRR64zdExo/sNbsg/SMJmtimXFc0hHKn2StbFk+ T/pYWmzG7xOe+li6YR114Bg8OxCnipl7gBA/QqPYYJj0W2hFx9U7vlcEiXQGNOruJbljCnKtgDq lj6Z74yYJuWsrzj0o4vjqxyi4BOLtbSS5JV/Pp8iDBYTqLC0pY32GkMeDFab7GsrY5rICDRx4VW Uq1YPENdrz76NZnK4/2cuXken+kxqqW1zyvFGsZgPDvQ9PFAUxr0Dya/oQM1fTNRRQjuNUqX X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1099,Hydra:6.0.736,FMLib:17.12.80.40 definitions=2025-05-08_05,2025-05-08_02,2025-02-21_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 malwarescore=0 adultscore=0 mlxscore=0 impostorscore=0 suspectscore=0 priorityscore=1501 phishscore=0 bulkscore=0 lowpriorityscore=0 spamscore=0 mlxlogscore=999 classifier=spam authscore=0 authtc=n/a authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.19.0-2504070000 definitions=main-2505080149 Content-Type: text/plain; charset="utf-8" The AD7768-1 provides a buffered common-mode voltage output on the VCM pin that can be used to bias analog input signals. Add regulators property to enable the use of the VCM output, referenced here as vcm-output, by any other device. Acked-by: Conor Dooley Signed-off-by: Jonathan Santos --- v7 Changes: * none. v6 Changes: * None. v5 Changes: * removed `regulator-min-microvolt` and `regulator-max-microvolt`.=20 v4 Changes: * replace "vcm_output" property name for "vcm-output".=20 v3 Changes: * VCM is now provided as a regulator within the device, instead of a=20 custom property. v2 Changes: * New patch in v2. --- .../bindings/iio/adc/adi,ad7768-1.yaml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Documentation/devicetree/bindings/iio/adc/adi,ad7768-1.yaml b/= Documentation/devicetree/bindings/iio/adc/adi,ad7768-1.yaml index 18f93586fcdf..c06d0fc791d3 100644 --- a/Documentation/devicetree/bindings/iio/adc/adi,ad7768-1.yaml +++ b/Documentation/devicetree/bindings/iio/adc/adi,ad7768-1.yaml @@ -66,6 +66,19 @@ properties: in any way, for example if the filter decimation rate changes. As the line is active low, it should be marked GPIO_ACTIVE_LOW. =20 + regulators: + type: object + description: + list of regulators provided by this controller. + + properties: + vcm-output: + $ref: /schemas/regulator/regulator.yaml# + type: object + unevaluatedProperties: false + + additionalProperties: false + reset-gpios: maxItems: 1 =20 @@ -167,6 +180,12 @@ examples: reg =3D <0>; label =3D "channel_0"; }; + + regulators { + vcm_reg: vcm-output { + regulator-name =3D "ad7768-1-vcm"; + }; + }; }; }; ... --=20 2.34.1 From nobody Tue Dec 16 07:32:59 2025 Received: from mx0a-00128a01.pphosted.com (mx0a-00128a01.pphosted.com [148.163.135.77]) (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 E2322286431; Thu, 8 May 2025 17:04:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.135.77 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746723873; cv=none; b=dCK6N+YbHB7ufnJcJfIH9KfoWniCd4n4l8eY2qkPyNCwDUeQf5TutWOqLKk8lqc7xUUKmyp13N/PpJUlNInbxQKVvbk4BXWoPRubnsAABodz9ijbC5n3XO+RYtj4JX7czRFlMOPlmSdZRz08GhsBgF3jikmqekJvVYuzRMvFp1Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746723873; c=relaxed/simple; bh=DhuNtQzbQhCnom9EJRpJrTUUJJ0NN0NXH0T5CAnr7D0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=fL7J1P6p1poPwpO1u+qOHCqKJvmma0m1dteJUs4cN6LrgklsCr+CXT9ineKMTI1bBzuYM0+9xCX1cyS3Ckx34Tj5tAwx5lcRp+REdm40YuockwfyUMf7SfGvQbhJcMVKODzC+6rX58nh1X5xvvni0MSLy0DG6NVeQxmBGFayOwo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=analog.com; spf=pass smtp.mailfrom=analog.com; dkim=pass (2048-bit key) header.d=analog.com header.i=@analog.com header.b=s+KGomUQ; arc=none smtp.client-ip=148.163.135.77 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=analog.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=analog.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=analog.com header.i=@analog.com header.b="s+KGomUQ" Received: from pps.filterd (m0167089.ppops.net [127.0.0.1]) by mx0a-00128a01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 548Dh17w023915; Thu, 8 May 2025 13:04:28 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=analog.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=DKIM; bh=mPaIc kpZdJAKLhwpv5vLy81wUhLhiPrB1ozUXZs/S2U=; b=s+KGomUQEhVRU4nyKxLAL 7wm4JMOwimwaV+nCuj6KhrVto1id60JFw3FAfMWExppdFUb3iTXlbIBm2pe2Gqsu 8NbatIOuOdXFpjryQ77a5TQuyshiR9qX5Yxlvm58L6FY64v+b+fT29ZG9kvw8r7e oyNerR6sCNPapGxr/XRZzBGOTuEpbTUe4Bxmln72r8T6wk/o8Qxa+GngekCqZI5h m/qVc2I99ch57SzXw3jUdD7Mbl4B3vSITaLv0zoUPK4Q1PuRmUHQlhBLgtQ0Yp1P uYARm8hJC5CHAzXyebvYPElMlbnywfqa8c/JQnHBzfo2mEMOufd3s2GpYC/EHAl3 g== Received: from nwd2mta3.analog.com ([137.71.173.56]) by mx0a-00128a01.pphosted.com (PPS) with ESMTPS id 46gpctb1qe-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 May 2025 13:04:28 -0400 (EDT) Received: from ASHBMBX9.ad.analog.com (ASHBMBX9.ad.analog.com [10.64.17.10]) by nwd2mta3.analog.com (8.14.7/8.14.7) with ESMTP id 548H4Qr1052751 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 8 May 2025 13:04:26 -0400 Received: from ASHBCASHYB4.ad.analog.com (10.64.17.132) by ASHBMBX9.ad.analog.com (10.64.17.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.14; Thu, 8 May 2025 13:04:26 -0400 Received: from ASHBMBX8.ad.analog.com (10.64.17.5) by ASHBCASHYB4.ad.analog.com (10.64.17.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.14; Thu, 8 May 2025 13:04:26 -0400 Received: from zeus.spd.analog.com (10.66.68.11) by ashbmbx8.ad.analog.com (10.64.17.5) with Microsoft SMTP Server id 15.2.986.14 via Frontend Transport; Thu, 8 May 2025 13:04:26 -0400 Received: from JSANTO12-L01.ad.analog.com ([10.65.60.206]) by zeus.spd.analog.com (8.15.1/8.15.1) with ESMTP id 548H4CUD015889; Thu, 8 May 2025 13:04:14 -0400 From: Jonathan Santos To: , , , CC: Jonathan Santos , , , , , , , , , , , , , , , Subject: [PATCH v7 06/12] iio: adc: ad7768-1: add regulator to control VCM output Date: Thu, 8 May 2025 14:04:12 -0300 Message-ID: <70b0a3b31ae5b4cbeff7b776e2e528c9df41529e.1746662899.git.Jonathan.Santos@analog.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ADIRuleOP-NewSCL: Rule Triggered X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUwNTA4MDE0OSBTYWx0ZWRfXxMrR/2+hXp0W D/wRfotBcdww1qgAN/b//rsisaIlcYdSa8roeOiDCmGaBKUapi/q6uKhezapEi1iTVBMC8YnBBX jYjZ72SxcFk3OyxOBfFq3BcTgbe62RMB86TgTeZne+Yyk/J2h+ZV9H5TG2/QEGg5aO1orJ+qd9m hDb01bExM9rFBrG0epgeW5FBlZ9yUKIW1LW6sYQeWU/hM81xqSggKEVBe32n9sY97+g+8MqUGnY BSWb5TtVDuM1QWqWd5ENfQfkFfJBBT8JgrWoFOHTN3aaUM0a65Y6OT6DjCTO/Iu+IUH2iv9kCqJ EdekNHXPHS/mfHX7KF0JjWzygY+slvulH8r6Q+K2jx5jatKWU7hb+Ic7GYLvJmYBgGrQCm+XGJ8 rjOR89erXGv01tDn4QQgmXq6X9iYnlWI6/VmHyb37MOW1XShN2+swpizg95/K1tQ/22cIZOX X-Authority-Analysis: v=2.4 cv=Ur5jN/wB c=1 sm=1 tr=0 ts=681ce41c cx=c_pps a=PpDZqlmH/M8setHirZLBMw==:117 a=PpDZqlmH/M8setHirZLBMw==:17 a=dt9VzEwgFbYA:10 a=gAnH3GRIAAAA:8 a=IpJZQVW2AAAA:8 a=lA8crIeKp1-K9khhi1AA:9 a=IawgGOuG5U0WyFbmm1f5:22 X-Proofpoint-GUID: OI6ldSp2aEyTPWO-cbCbNvkUxa2-b-Fe X-Proofpoint-ORIG-GUID: OI6ldSp2aEyTPWO-cbCbNvkUxa2-b-Fe X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1099,Hydra:6.0.736,FMLib:17.12.80.40 definitions=2025-05-08_05,2025-05-08_02,2025-02-21_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 suspectscore=0 adultscore=6 bulkscore=0 malwarescore=0 priorityscore=1501 spamscore=0 impostorscore=0 lowpriorityscore=0 mlxlogscore=999 clxscore=1015 phishscore=0 classifier=spam authscore=0 authtc=n/a authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.19.0-2504070000 definitions=main-2505080149 Content-Type: text/plain; charset="utf-8" The VCM output voltage can be used as a common-mode voltage within the amplifier preconditioning circuits external to the AD7768-1. This change allows the user to configure VCM output using the regulator framework. Acked-by: Marcelo Schmitt Reviewed-by: David Lechner Signed-off-by: Jonathan Santos --- v7 Changes: * removed dead code. * removed of.h header. * removed explicit casting in the clamp function. v6 Changes: * Rearranged iio_device_release_direct() calls to avoid some gotos. * removed of_match_ptr() from regulator_desc. * Addressed other nits. v5 Changes: * enforce AD7768_REG_ANALOG2_VCM macro argument evaluation. * switched to the new iio_device_claim/release_direct() functions. v4 Changes: * Added iio_device_claim_direct_mode() to regulator callbacks to avoid regi= ster access while in buffered mode. * Changed regulator name to "ad7768-1-vcm". * When regulator enable is called, it will set the last voltage selector co= nfigured. * Disabled regulator before configuring it. * Addressed other nits. v3 Changes: * Register VCM output via the regulator framework for improved flexibility and external integration. v2 Changes: * VCM output support is now defined by a devicetree property, instead of=20 and IIO attribute. --- drivers/iio/adc/Kconfig | 1 + drivers/iio/adc/ad7768-1.c | 159 +++++++++++++++++++++++++++++++++++++ 2 files changed, 160 insertions(+) diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig index ad06cf556785..8dc4cc4c25af 100644 --- a/drivers/iio/adc/Kconfig +++ b/drivers/iio/adc/Kconfig @@ -329,6 +329,7 @@ config AD7766 config AD7768_1 tristate "Analog Devices AD7768-1 ADC driver" depends on SPI + select REGULATOR select REGMAP_SPI select IIO_BUFFER select IIO_TRIGGER diff --git a/drivers/iio/adc/ad7768-1.c b/drivers/iio/adc/ad7768-1.c index e90bb5d50076..cd5ce774df72 100644 --- a/drivers/iio/adc/ad7768-1.c +++ b/drivers/iio/adc/ad7768-1.c @@ -13,9 +13,11 @@ #include #include #include +#include #include #include #include +#include #include #include =20 @@ -82,6 +84,12 @@ #define AD7768_CONV_MODE_MSK GENMASK(2, 0) #define AD7768_CONV_MODE(x) FIELD_PREP(AD7768_CONV_MODE_MSK, x) =20 +/* AD7768_REG_ANALOG2 */ +#define AD7768_REG_ANALOG2_VCM_MSK GENMASK(2, 0) +#define AD7768_REG_ANALOG2_VCM(x) FIELD_PREP(AD7768_REG_ANALOG2_VCM_MSK, (= x)) + +#define AD7768_VCM_OFF 0x07 + enum ad7768_conv_mode { AD7768_CONTINUOUS, AD7768_ONE_SHOT, @@ -159,6 +167,8 @@ struct ad7768_state { struct regmap *regmap; struct regmap *regmap24; struct regulator *vref; + struct regulator_dev *vcm_rdev; + unsigned int vcm_output_sel; struct clk *mclk; unsigned int mclk_freq; unsigned int samp_freq; @@ -646,6 +656,150 @@ static int ad7768_triggered_buffer_alloc(struct iio_d= ev *indio_dev) &ad7768_buffer_ops); } =20 +static int ad7768_vcm_enable(struct regulator_dev *rdev) +{ + struct iio_dev *indio_dev =3D rdev_get_drvdata(rdev); + struct ad7768_state *st =3D iio_priv(indio_dev); + int ret, regval; + + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; + + /* To enable, set the last selected output */ + regval =3D AD7768_REG_ANALOG2_VCM(st->vcm_output_sel + 1); + ret =3D regmap_update_bits(st->regmap, AD7768_REG_ANALOG2, + AD7768_REG_ANALOG2_VCM_MSK, regval); + iio_device_release_direct(indio_dev); + + return ret; +} + +static int ad7768_vcm_disable(struct regulator_dev *rdev) +{ + struct iio_dev *indio_dev =3D rdev_get_drvdata(rdev); + struct ad7768_state *st =3D iio_priv(indio_dev); + int ret; + + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; + + ret =3D regmap_update_bits(st->regmap, AD7768_REG_ANALOG2, + AD7768_REG_ANALOG2_VCM_MSK, AD7768_VCM_OFF); + iio_device_release_direct(indio_dev); + + return ret; +} + +static int ad7768_vcm_is_enabled(struct regulator_dev *rdev) +{ + struct iio_dev *indio_dev =3D rdev_get_drvdata(rdev); + struct ad7768_state *st =3D iio_priv(indio_dev); + int ret, val; + + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; + + ret =3D regmap_read(st->regmap, AD7768_REG_ANALOG2, &val); + iio_device_release_direct(indio_dev); + if (ret) + return ret; + + return FIELD_GET(AD7768_REG_ANALOG2_VCM_MSK, val) !=3D AD7768_VCM_OFF; +} + +static int ad7768_set_voltage_sel(struct regulator_dev *rdev, + unsigned int selector) +{ + unsigned int regval =3D AD7768_REG_ANALOG2_VCM(selector + 1); + struct iio_dev *indio_dev =3D rdev_get_drvdata(rdev); + struct ad7768_state *st =3D iio_priv(indio_dev); + int ret; + + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; + + ret =3D regmap_update_bits(st->regmap, AD7768_REG_ANALOG2, + AD7768_REG_ANALOG2_VCM_MSK, regval); + iio_device_release_direct(indio_dev); + if (ret) + return ret; + + st->vcm_output_sel =3D selector; + + return 0; +} + +static int ad7768_get_voltage_sel(struct regulator_dev *rdev) +{ + struct iio_dev *indio_dev =3D rdev_get_drvdata(rdev); + struct ad7768_state *st =3D iio_priv(indio_dev); + int ret, val; + + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; + + ret =3D regmap_read(st->regmap, AD7768_REG_ANALOG2, &val); + iio_device_release_direct(indio_dev); + if (ret) + return ret; + + val =3D FIELD_GET(AD7768_REG_ANALOG2_VCM_MSK, val); + + return clamp(val, 1, rdev->desc->n_voltages) - 1; +} + +static const struct regulator_ops vcm_regulator_ops =3D { + .enable =3D ad7768_vcm_enable, + .disable =3D ad7768_vcm_disable, + .is_enabled =3D ad7768_vcm_is_enabled, + .list_voltage =3D regulator_list_voltage_table, + .set_voltage_sel =3D ad7768_set_voltage_sel, + .get_voltage_sel =3D ad7768_get_voltage_sel, +}; + +static const unsigned int vcm_voltage_table[] =3D { + 2500000, + 2050000, + 1650000, + 1900000, + 1100000, + 900000, +}; + +static const struct regulator_desc vcm_desc =3D { + .name =3D "ad7768-1-vcm", + .of_match =3D "vcm-output", + .regulators_node =3D "regulators", + .n_voltages =3D ARRAY_SIZE(vcm_voltage_table), + .volt_table =3D vcm_voltage_table, + .ops =3D &vcm_regulator_ops, + .type =3D REGULATOR_VOLTAGE, + .owner =3D THIS_MODULE, +}; + +static int ad7768_register_regulators(struct device *dev, struct ad7768_st= ate *st, + struct iio_dev *indio_dev) +{ + struct regulator_config config =3D { + .dev =3D dev, + .driver_data =3D indio_dev, + }; + int ret; + + /* Disable the regulator before registering it */ + ret =3D regmap_update_bits(st->regmap, AD7768_REG_ANALOG2, + AD7768_REG_ANALOG2_VCM_MSK, AD7768_VCM_OFF); + if (ret) + return ret; + + st->vcm_rdev =3D devm_regulator_register(dev, &vcm_desc, &config); + if (IS_ERR(st->vcm_rdev)) + return dev_err_probe(dev, PTR_ERR(st->vcm_rdev), + "failed to register VCM regulator\n"); + + return 0; +} + static int ad7768_probe(struct spi_device *spi) { struct ad7768_state *st; @@ -710,6 +864,11 @@ static int ad7768_probe(struct spi_device *spi) indio_dev->info =3D &ad7768_info; indio_dev->modes =3D INDIO_DIRECT_MODE; =20 + /* Register VCM output regulator */ + ret =3D ad7768_register_regulators(&spi->dev, st, indio_dev); + if (ret) + return ret; + ret =3D ad7768_setup(st); if (ret < 0) { dev_err(&spi->dev, "AD7768 setup failed\n"); --=20 2.34.1 From nobody Tue Dec 16 07:32:59 2025 Received: from mx0a-00128a01.pphosted.com (mx0a-00128a01.pphosted.com [148.163.135.77]) (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 2045C221294; Thu, 8 May 2025 17:05:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.135.77 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746723904; cv=none; b=T+fZwjV5u+9iaLDWUt50XtHaSAGScwZ/Ghui6oefCn0zDT3swx+b7rVawc4pOd2nHz9HfrT3EEdWMsRpcL+T/tTm3sKDdNkYdUWc6FKWOEeBxRGrZNCtNAmP3OpUkIPYTG440O9IqL2MfOvZUh4HzopMkDy5UASKoge/l1Op99E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746723904; c=relaxed/simple; bh=mnLm4h1NuX44LptWL2u5xumNR9aGw6kS0ZCb5a6T7nc=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=BEf+4/kFyDRWbHSWeKUapk7ossrmvFC8sp1nQnnVQm8Z2X3F6gUEytClBpYIiKEsjcQCGUFPq4DD/6SDPIgFL0+TKcZjH0E4rK7Dgi2rWBkS/93hS1abwEECBEmc4Mfb8WsmLhu7WKM7h8DWGiWm5tWlcTSMkutLI6M7PWYjCgg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=analog.com; spf=pass smtp.mailfrom=analog.com; dkim=pass (2048-bit key) header.d=analog.com header.i=@analog.com header.b=A26aCX3E; arc=none smtp.client-ip=148.163.135.77 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=analog.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=analog.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=analog.com header.i=@analog.com header.b="A26aCX3E" Received: from pps.filterd (m0167088.ppops.net [127.0.0.1]) by mx0a-00128a01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 548DMfTA013536; Thu, 8 May 2025 13:04:48 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=analog.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=DKIM; bh=o5Job 2JeyPQC0+XMuUHl3+TmLceDbOT7m+Hu2nKm7qo=; b=A26aCX3Ef3CD60hA0YdPo ze9S+6rCJiVWBRcs7bBfLw3XA7mW7hOUa/gSx83ie7v4yOCeZUaCu7n9pUBt3X0g WpjCmlpLZeEaPbRcjSJ+cdMEtoYx4PoMasY6/8ophzHf0DE3mjufOd2YYHnMf5mw 7hWbLKzXS0zE/l/rJBcptx7Ldz6MIiL48oI+m7OSQQvJ/RLnSZPH0u+aJ5DVqtGn fJt0HpPunlmCxYnrdnYnHj+HbQVIgtrF1oivaH1dc8ZQJhatYteYMX5Xpn7KXcHe 4m+LCAKIvNOTrNZ1NFy8h+kANamJ6j9XgOI8hZLFy1gH1apwqo/H27XQVPlc71kR A== Received: from nwd2mta4.analog.com ([137.71.173.58]) by mx0a-00128a01.pphosted.com (PPS) with ESMTPS id 46gpct32hd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 May 2025 13:04:48 -0400 (EDT) Received: from ASHBMBX8.ad.analog.com (ASHBMBX8.ad.analog.com [10.64.17.5]) by nwd2mta4.analog.com (8.14.7/8.14.7) with ESMTP id 548H4ldt022812 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 8 May 2025 13:04:47 -0400 Received: from ASHBMBX8.ad.analog.com (10.64.17.5) by ASHBMBX8.ad.analog.com (10.64.17.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.14; Thu, 8 May 2025 13:04:46 -0400 Received: from zeus.spd.analog.com (10.66.68.11) by ashbmbx8.ad.analog.com (10.64.17.5) with Microsoft SMTP Server id 15.2.986.14 via Frontend Transport; Thu, 8 May 2025 13:04:46 -0400 Received: from JSANTO12-L01.ad.analog.com ([10.65.60.206]) by zeus.spd.analog.com (8.15.1/8.15.1) with ESMTP id 548H4UGL015893; Thu, 8 May 2025 13:04:32 -0400 From: Jonathan Santos To: , , , CC: Sergiu Cuciurean , , , , , , , , , , , , , , , , Bartosz Golaszewski , Jonathan Santos Subject: [PATCH v7 07/12] iio: adc: ad7768-1: Add GPIO controller support Date: Thu, 8 May 2025 14:04:30 -0300 Message-ID: <0ce451f62aa22a5f6261c15516695c681bff60b0.1746662899.git.Jonathan.Santos@analog.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ADIRuleOP-NewSCL: Rule Triggered X-Authority-Analysis: v=2.4 cv=J/eq7BnS c=1 sm=1 tr=0 ts=681ce430 cx=c_pps a=3WNzaoukacrqR9RwcOSAdA==:117 a=3WNzaoukacrqR9RwcOSAdA==:17 a=dt9VzEwgFbYA:10 a=gAnH3GRIAAAA:8 a=KKAkSRfTAAAA:8 a=ItmwtGPuVRerelARzv0A:9 a=cvBusfyB2V15izCimMoJ:22 X-Proofpoint-GUID: 4O3wrjHrzreQgrqNfxkznS5coj3RiI7j X-Proofpoint-ORIG-GUID: 4O3wrjHrzreQgrqNfxkznS5coj3RiI7j X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUwNTA4MDE0OSBTYWx0ZWRfX7ZwSWJJuxq2p BX9w/VuDvD3Otc58qi36/IZclGfLAggOWY1spEYdsPlZiLPKhY9BnSCSGx2FEtPJ687hfhVZtJy QEpO5ZKQIoshNZaADq8XVakJWxJ4psYyHnlyWxB8SuLSP55CAQC1z1LaGHZmTjaTzm9OdSu2sUP YQJdZUchQrRVvg+fW9gXDlJkcsNpUE46Up4m6PCVH2tHk+O4g8WhB7PqW27ltLtfzkc/yUeJqGc kgp8sDWbnx3lAgf55Y6Rnp8LpFnkDefgQrcls3a3rz755T2/wMcHQJU55fAL9Zu9706LGV5iVyG 0IxwzrNkUlVp5S0kq2U/7OTtQiMmlpGQObypK4cf0eRhnkfTMXvpJNYSHRe9JFXNY1srOHphFOU J9+sxfn2zmFhZTQLNrrooOdyY4NeDXfkEBe/mCx00+xjOnae8+JEbkmjncsRCjzRhPDou4RS X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1099,Hydra:6.0.736,FMLib:17.12.80.40 definitions=2025-05-08_05,2025-05-08_02,2025-02-21_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 impostorscore=0 adultscore=0 lowpriorityscore=0 mlxlogscore=999 priorityscore=1501 bulkscore=0 phishscore=0 malwarescore=0 spamscore=0 mlxscore=0 clxscore=1015 classifier=spam authscore=0 authtc=n/a authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.19.0-2504070000 definitions=main-2505080149 Content-Type: text/plain; charset="utf-8" From: Sergiu Cuciurean The AD7768-1 has the ability to control other local hardware (such as gain stages),to power down other blocks in the signal chain, or read local status signals over the SPI interface. Add direct mode conditional locks in the gpio callbacks to prevent register access when the device is in buffered mode. This change exports the AD7768-1's four gpios and makes them accessible at an upper layer. Reviewed-by: Marcelo Schmitt Acked-by: Bartosz Golaszewski Reviewed-by: Linus Walleij Signed-off-by: Sergiu Cuciurean Co-developed-by: Jonathan Santos Signed-off-by: Jonathan Santos --- v7 Changes: * moved gpiochip field in the ad7768_state struct. * replaced regmap_update_bits() for regmap_assign_bits() in the gpio_set() = function. * other nits. * removed gpio.h header. v6 Changes: * Replaced deprecated .set callback with .set_rv. v5 Changes: * Use the new new iio_device_claim/release_direct() functions. * replaced gpiochip_add_data() for devm_gpiochip_add_data(). v4 Changes: * Mentioned in the commit message that we cannot tweak the GPIO controller when the device is not in direct mode. v3 Changes: * Fixed SoB order. * Added missing iio_device_release_direct_mode(). * Simplified some regmap writes. * Removed ad7768_gpio_request() callback. * Fixed line wrapping. v2 Changes: * Replaced mutex for iio_device_claim_direct_mode(). * Use gpio-controller property to conditionally enable the GPIO support. * OBS: when the GPIO is configured as output, we should read=20 the current state value from AD7768_REG_GPIO_WRITE. --- drivers/iio/adc/ad7768-1.c | 140 ++++++++++++++++++++++++++++++++++++- 1 file changed, 138 insertions(+), 2 deletions(-) diff --git a/drivers/iio/adc/ad7768-1.c b/drivers/iio/adc/ad7768-1.c index cd5ce774df72..d0366d570c14 100644 --- a/drivers/iio/adc/ad7768-1.c +++ b/drivers/iio/adc/ad7768-1.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -88,6 +89,16 @@ #define AD7768_REG_ANALOG2_VCM_MSK GENMASK(2, 0) #define AD7768_REG_ANALOG2_VCM(x) FIELD_PREP(AD7768_REG_ANALOG2_VCM_MSK, (= x)) =20 +/* AD7768_REG_GPIO_CONTROL */ +#define AD7768_GPIO_UNIVERSAL_EN BIT(7) +#define AD7768_GPIO_CONTROL_MSK GENMASK(3, 0) + +/* AD7768_REG_GPIO_WRITE */ +#define AD7768_GPIO_WRITE_MSK GENMASK(3, 0) + +/* AD7768_REG_GPIO_READ */ +#define AD7768_GPIO_READ_MSK GENMASK(3, 0) + #define AD7768_VCM_OFF 0x07 =20 enum ad7768_conv_mode { @@ -177,6 +188,7 @@ struct ad7768_state { struct gpio_desc *gpio_sync_in; struct gpio_desc *gpio_reset; const char *labels[ARRAY_SIZE(ad7768_channels)]; + struct gpio_chip gpiochip; /* * DMA (thus cache coherency maintenance) may require the * transfer buffers to live in their own cache lines. @@ -355,6 +367,122 @@ static int ad7768_set_dig_fil(struct ad7768_state *st, return 0; } =20 +static int ad7768_gpio_direction_input(struct gpio_chip *chip, unsigned in= t offset) +{ + struct iio_dev *indio_dev =3D gpiochip_get_data(chip); + struct ad7768_state *st =3D iio_priv(indio_dev); + int ret; + + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; + + ret =3D regmap_clear_bits(st->regmap, AD7768_REG_GPIO_CONTROL, + BIT(offset)); + iio_device_release_direct(indio_dev); + + return ret; +} + +static int ad7768_gpio_direction_output(struct gpio_chip *chip, + unsigned int offset, int value) +{ + struct iio_dev *indio_dev =3D gpiochip_get_data(chip); + struct ad7768_state *st =3D iio_priv(indio_dev); + int ret; + + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; + + ret =3D regmap_set_bits(st->regmap, AD7768_REG_GPIO_CONTROL, + BIT(offset)); + iio_device_release_direct(indio_dev); + + return ret; +} + +static int ad7768_gpio_get(struct gpio_chip *chip, unsigned int offset) +{ + struct iio_dev *indio_dev =3D gpiochip_get_data(chip); + struct ad7768_state *st =3D iio_priv(indio_dev); + unsigned int val; + int ret; + + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; + + ret =3D regmap_read(st->regmap, AD7768_REG_GPIO_CONTROL, &val); + if (ret) + goto err_release; + + /* + * If the GPIO is configured as an output, read the current value from + * AD7768_REG_GPIO_WRITE. Otherwise, read the input value from + * AD7768_REG_GPIO_READ. + */ + if (val & BIT(offset)) + ret =3D regmap_read(st->regmap, AD7768_REG_GPIO_WRITE, &val); + else + ret =3D regmap_read(st->regmap, AD7768_REG_GPIO_READ, &val); + if (ret) + goto err_release; + + ret =3D !!(val & BIT(offset)); +err_release: + iio_device_release_direct(indio_dev); + + return ret; +} + +static int ad7768_gpio_set(struct gpio_chip *chip, unsigned int offset, in= t value) +{ + struct iio_dev *indio_dev =3D gpiochip_get_data(chip); + struct ad7768_state *st =3D iio_priv(indio_dev); + unsigned int val; + int ret; + + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; + + ret =3D regmap_read(st->regmap, AD7768_REG_GPIO_CONTROL, &val); + if (ret) + goto err_release; + + if (val & BIT(offset)) + ret =3D regmap_assign_bits(st->regmap, AD7768_REG_GPIO_WRITE, + BIT(offset), value); + +err_release: + iio_device_release_direct(indio_dev); + + return ret; +} + +static int ad7768_gpio_init(struct iio_dev *indio_dev) +{ + struct ad7768_state *st =3D iio_priv(indio_dev); + int ret; + + ret =3D regmap_write(st->regmap, AD7768_REG_GPIO_CONTROL, + AD7768_GPIO_UNIVERSAL_EN); + if (ret) + return ret; + + st->gpiochip =3D (struct gpio_chip) { + .label =3D "ad7768_1_gpios", + .base =3D -1, + .ngpio =3D 4, + .parent =3D &st->spi->dev, + .can_sleep =3D true, + .direction_input =3D ad7768_gpio_direction_input, + .direction_output =3D ad7768_gpio_direction_output, + .get =3D ad7768_gpio_get, + .set_rv =3D ad7768_gpio_set, + .owner =3D THIS_MODULE, + }; + + return devm_gpiochip_add_data(&st->spi->dev, &st->gpiochip, indio_dev); +} + static int ad7768_set_freq(struct ad7768_state *st, unsigned int freq) { @@ -496,8 +624,9 @@ static const struct iio_info ad7768_info =3D { .debugfs_reg_access =3D &ad7768_reg_access, }; =20 -static int ad7768_setup(struct ad7768_state *st) +static int ad7768_setup(struct iio_dev *indio_dev) { + struct ad7768_state *st =3D iio_priv(indio_dev); int ret; =20 st->gpio_reset =3D devm_gpiod_get_optional(&st->spi->dev, "reset", @@ -530,6 +659,13 @@ static int ad7768_setup(struct ad7768_state *st) if (IS_ERR(st->gpio_sync_in)) return PTR_ERR(st->gpio_sync_in); =20 + /* Only create a Chip GPIO if flagged for it */ + if (device_property_read_bool(&st->spi->dev, "gpio-controller")) { + ret =3D ad7768_gpio_init(indio_dev); + if (ret) + return ret; + } + /* Set the default sampling frequency to 32000 kSPS */ return ad7768_set_freq(st, 32000); } @@ -869,7 +1005,7 @@ static int ad7768_probe(struct spi_device *spi) if (ret) return ret; =20 - ret =3D ad7768_setup(st); + ret =3D ad7768_setup(indio_dev); if (ret < 0) { dev_err(&spi->dev, "AD7768 setup failed\n"); return ret; --=20 2.34.1 From nobody Tue Dec 16 07:32:59 2025 Received: from mx0a-00128a01.pphosted.com (mx0a-00128a01.pphosted.com [148.163.135.77]) (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 4B1662868A4; Thu, 8 May 2025 17:05:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.135.77 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746723914; cv=none; b=Bu3uB8NgDYN0KLZkONITXhfD0xqRM+zneELGYdv4ML8+pDj7akvhDGWTaL0RG+fqqwn08G16nhTr4W+VntMqegu4GRhPh3unFMxj+60XNIO9a09mPYZ1hCXwDCdeJqeCNj50MjfURsR5ssJSd1oSnie3KhK362dL1pxXCCeqXcI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746723914; c=relaxed/simple; bh=dVSjHaB0v3xEEDYuqQyrQu4x1C8hzgi7YTyOrXNAsgM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=hTJs+1r8HLZp3ovscZMK3pZ5x6SPu53ctY+QJA2ZqENzuj37RInsbNKCsKlQVEYYKj0i1xwILg9gJCs+ZEStEbxOz2cQZrEy1o8R89k/sQmsmwqMwzIww/h+BeRzf9lbepz1jlcZgwleZBX+Epe07xHCyx8PMbeNa7LJHSveHTs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=analog.com; spf=pass smtp.mailfrom=analog.com; dkim=pass (2048-bit key) header.d=analog.com header.i=@analog.com header.b=wvimP3yS; arc=none smtp.client-ip=148.163.135.77 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=analog.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=analog.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=analog.com header.i=@analog.com header.b="wvimP3yS" Received: from pps.filterd (m0167089.ppops.net [127.0.0.1]) by mx0a-00128a01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 548DgahP024375; Thu, 8 May 2025 13:05:03 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=analog.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=DKIM; bh=TZTlR BOutcSwBnSGVRkukpscb9id0CRdjKFiAfpFwy8=; b=wvimP3yS/Q9T8Pjcyeew8 ngZp9HoLBdcASSaTBSimdyf7S9GHofvVC9B2r3jPD1e1dWcmFMyIu0UZZ0ADgsKj qc6eHrFws5GjuD+OxB2PMlVB7GU6WxofO5YOk8sHoOafNo6qirY9vYWXvIBEqn4i g4cdrYV2i3PmaLkhmWZ1oqOv6f5bRxoQP3lwF1UjAJ4UV+E4N9a2oCG039VJmh6G cwWyjPcapPERjPksafniSVqPW1qq/FUBpH0lvJLYu5aOv20R5b9pqdcuVrq96m21 pyEdsC5BUaMQJZ7eiyJAVtFJbQFXiNBRNh8kMznontKOhKhlmbPpFpQgK5g0g2/+ w== Received: from nwd2mta3.analog.com ([137.71.173.56]) by mx0a-00128a01.pphosted.com (PPS) with ESMTPS id 46gpctb1up-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 May 2025 13:05:03 -0400 (EDT) Received: from ASHBMBX9.ad.analog.com (ASHBMBX9.ad.analog.com [10.64.17.10]) by nwd2mta3.analog.com (8.14.7/8.14.7) with ESMTP id 548H520f052826 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 8 May 2025 13:05:02 -0400 Received: from ASHBMBX8.ad.analog.com (10.64.17.5) by ASHBMBX9.ad.analog.com (10.64.17.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.14; Thu, 8 May 2025 13:05:02 -0400 Received: from zeus.spd.analog.com (10.66.68.11) by ashbmbx8.ad.analog.com (10.64.17.5) with Microsoft SMTP Server id 15.2.986.14 via Frontend Transport; Thu, 8 May 2025 13:05:01 -0400 Received: from JSANTO12-L01.ad.analog.com ([10.65.60.206]) by zeus.spd.analog.com (8.15.1/8.15.1) with ESMTP id 548H4hFu015898; Thu, 8 May 2025 13:04:45 -0400 From: Jonathan Santos To: , , , CC: Jonathan Santos , , , , , , , , , , , , , , , , David Lechner Subject: [PATCH v7 08/12] iio: adc: ad7768-1: add multiple scan types to support 16-bits mode Date: Thu, 8 May 2025 14:04:42 -0300 Message-ID: <8b8f861422b15b1316a1513cd66abc544ab8c5bd.1746662899.git.Jonathan.Santos@analog.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ADIRuleOP-NewSCL: Rule Triggered X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUwNTA4MDE0OSBTYWx0ZWRfX5ksu0T4mSgwm Csy1oapg6AQi5qqgFtKhOvPStCFfg5Pin3qxiqUBGbdm1fdf87E+qP/WLwupnHs8CHvrTgUMUOQ zIvawvbCk1D72Tjy0Squ28F1Klz2Ui6qFdRYI3X0uBMGi2vVgqhKPM5GV0yV55IkyL+U93UHqsg su+I9ev1keHyKNBuh/flU67xwk1F9vfN/xNBe3RLKjYddPSlmIaBPLb0B3dsBzrBJeewIYvAQql 7eG8lJZdbiYo6ugne2GJPEVJ+Ph0CnPnxUslYAZf9HGo1+m3SSCIPRERK2AVKhDbQSDabCQVARk JUOfpU3HIH59x2ytLC3AeKV5z7FHXxGG6+IXm4gxZqDkvK3CifEC6iuEniJxP6WkyPe82drEyFX WhlMRqfZOOiZqdGKrZQOnAlelQ9sh55DvYTm6HFwWgjjnLs50mK2II3vSST16yJ6mdzEqprM X-Authority-Analysis: v=2.4 cv=Ur5jN/wB c=1 sm=1 tr=0 ts=681ce43f cx=c_pps a=PpDZqlmH/M8setHirZLBMw==:117 a=PpDZqlmH/M8setHirZLBMw==:17 a=dt9VzEwgFbYA:10 a=gAnH3GRIAAAA:8 a=ajdmHsczAAAA:8 a=TVenB2Com6UDTqQwcj8A:9 a=Cd2TjbhyRiE6FbCepFud:22 X-Proofpoint-GUID: FpkG8LFMNVPMMivMfLTAO1-KXX5Y_Zgh X-Proofpoint-ORIG-GUID: FpkG8LFMNVPMMivMfLTAO1-KXX5Y_Zgh X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1099,Hydra:6.0.736,FMLib:17.12.80.40 definitions=2025-05-08_05,2025-05-08_02,2025-02-21_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 suspectscore=0 adultscore=0 bulkscore=0 malwarescore=0 priorityscore=1501 spamscore=0 impostorscore=0 lowpriorityscore=0 mlxlogscore=999 clxscore=1015 phishscore=0 classifier=spam authscore=0 authtc=n/a authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.19.0-2504070000 definitions=main-2505080149 Content-Type: text/plain; charset="utf-8" When the device is configured to decimation x8, only possible in the sinc5 filter, output data is reduced to 16-bits in order to support 1 MHz of sampling frequency due to clock limitation. Use multiple scan types feature to enable the driver to switch scan type at runtime, making it possible to support both 24-bit and 16-bit resolution. Reviewed-by: Marcelo Schmitt Reviewed-by: David Lechner Signed-off-by: Jonathan Santos --- v7 Changes: * Added TODO comment to use spi_bpw_to_bytes() helper function. * Minor commit description changes. v6 Changes: * None. v5 Changes: * None. v4 Changes: * None. v3 Changes: * Decreased storagebits to 16 for AD7768_SCAN_TYPE_HIGH_SPEED scan type. v2 Changes: * Included the ".shift" value back to scan_type. * Changed the number of bytes from regmap_read instead of shifting the=20 ADC sample value when the word size is lower (16-bits). --- drivers/iio/adc/ad7768-1.c | 75 +++++++++++++++++++++++++++++++++----- 1 file changed, 65 insertions(+), 10 deletions(-) diff --git a/drivers/iio/adc/ad7768-1.c b/drivers/iio/adc/ad7768-1.c index d0366d570c14..19b9744dfd1b 100644 --- a/drivers/iio/adc/ad7768-1.c +++ b/drivers/iio/adc/ad7768-1.c @@ -140,6 +140,15 @@ struct ad7768_clk_configuration { enum ad7768_pwrmode pwrmode; }; =20 +enum ad7768_scan_type { + AD7768_SCAN_TYPE_NORMAL, + AD7768_SCAN_TYPE_HIGH_SPEED, +}; + +static const int ad7768_mclk_div_rates[] =3D { + 16, 8, 4, 2, +}; + static const struct ad7768_clk_configuration ad7768_clk_config[] =3D { { AD7768_MCLK_DIV_2, AD7768_DEC_RATE_8, 16, AD7768_FAST_MODE }, { AD7768_MCLK_DIV_2, AD7768_DEC_RATE_16, 32, AD7768_FAST_MODE }, @@ -154,6 +163,22 @@ static const struct ad7768_clk_configuration ad7768_cl= k_config[] =3D { { AD7768_MCLK_DIV_16, AD7768_DEC_RATE_1024, 16384, AD7768_ECO_MODE }, }; =20 +static const struct iio_scan_type ad7768_scan_type[] =3D { + [AD7768_SCAN_TYPE_NORMAL] =3D { + .sign =3D 's', + .realbits =3D 24, + .storagebits =3D 32, + .shift =3D 8, + .endianness =3D IIO_BE, + }, + [AD7768_SCAN_TYPE_HIGH_SPEED] =3D { + .sign =3D 's', + .realbits =3D 16, + .storagebits =3D 16, + .endianness =3D IIO_BE, + }, +}; + static const struct iio_chan_spec ad7768_channels[] =3D { { .type =3D IIO_VOLTAGE, @@ -163,13 +188,9 @@ static const struct iio_chan_spec ad7768_channels[] = =3D { .indexed =3D 1, .channel =3D 0, .scan_index =3D 0, - .scan_type =3D { - .sign =3D 's', - .realbits =3D 24, - .storagebits =3D 32, - .shift =3D 8, - .endianness =3D IIO_BE, - }, + .has_ext_scan_type =3D 1, + .ext_scan_type =3D ad7768_scan_type, + .num_ext_scan_type =3D ARRAY_SIZE(ad7768_scan_type), }, }; =20 @@ -182,6 +203,7 @@ struct ad7768_state { unsigned int vcm_output_sel; struct clk *mclk; unsigned int mclk_freq; + unsigned int dec_rate; unsigned int samp_freq; struct completion completion; struct iio_trigger *trig; @@ -301,6 +323,15 @@ static int ad7768_scan_direct(struct iio_dev *indio_de= v) if (ret) return ret; =20 + /* + * When the decimation rate is set to x8, the ADC data precision is + * reduced from 24 bits to 16 bits. Since the AD7768_REG_ADC_DATA + * register provides 24-bit data, the precision is reduced by + * right-shifting the read value by 8 bits. + */ + if (st->dec_rate =3D=3D 8) + readval >>=3D 8; + /* * Any SPI configuration of the AD7768-1 can only be * performed in continuous conversion mode. @@ -517,6 +548,8 @@ static int ad7768_set_freq(struct ad7768_state *st, if (ret < 0) return ret; =20 + st->dec_rate =3D ad7768_clk_config[idx].clk_div / + ad7768_mclk_div_rates[ad7768_clk_config[idx].mclk_div]; st->samp_freq =3D DIV_ROUND_CLOSEST(st->mclk_freq, ad7768_clk_config[idx].clk_div); =20 @@ -550,8 +583,13 @@ static int ad7768_read_raw(struct iio_dev *indio_dev, int *val, int *val2, long info) { struct ad7768_state *st =3D iio_priv(indio_dev); + const struct iio_scan_type *scan_type; int scale_uv, ret; =20 + scan_type =3D iio_get_current_scan_type(indio_dev, chan); + if (IS_ERR(scan_type)) + return PTR_ERR(scan_type); + switch (info) { case IIO_CHAN_INFO_RAW: if (!iio_device_claim_direct(indio_dev)) @@ -562,7 +600,7 @@ static int ad7768_read_raw(struct iio_dev *indio_dev, iio_device_release_direct(indio_dev); if (ret < 0) return ret; - *val =3D sign_extend32(ret, chan->scan_type.realbits - 1); + *val =3D sign_extend32(ret, scan_type->realbits - 1); =20 return IIO_VAL_INT; =20 @@ -572,7 +610,7 @@ static int ad7768_read_raw(struct iio_dev *indio_dev, return scale_uv; =20 *val =3D (scale_uv * 2) / 1000; - *val2 =3D chan->scan_type.realbits; + *val2 =3D scan_type->realbits; =20 return IIO_VAL_FRACTIONAL_LOG2; =20 @@ -616,11 +654,21 @@ static const struct attribute_group ad7768_group =3D { .attrs =3D ad7768_attributes, }; =20 +static int ad7768_get_current_scan_type(const struct iio_dev *indio_dev, + const struct iio_chan_spec *chan) +{ + struct ad7768_state *st =3D iio_priv(indio_dev); + + return st->dec_rate =3D=3D 8 ? AD7768_SCAN_TYPE_HIGH_SPEED : + AD7768_SCAN_TYPE_NORMAL; +} + static const struct iio_info ad7768_info =3D { .attrs =3D &ad7768_group, .read_raw =3D &ad7768_read_raw, .write_raw =3D &ad7768_write_raw, .read_label =3D ad7768_read_label, + .get_current_scan_type =3D &ad7768_get_current_scan_type, .debugfs_reg_access =3D &ad7768_reg_access, }; =20 @@ -675,9 +723,16 @@ static irqreturn_t ad7768_trigger_handler(int irq, voi= d *p) struct iio_poll_func *pf =3D p; struct iio_dev *indio_dev =3D pf->indio_dev; struct ad7768_state *st =3D iio_priv(indio_dev); + const struct iio_scan_type *scan_type; int ret; =20 - ret =3D spi_read(st->spi, &st->data.scan.chan, 3); + scan_type =3D iio_get_current_scan_type(indio_dev, &indio_dev->channels[0= ]); + if (IS_ERR(scan_type)) + goto out; + + /* TODO: Use spi_bpw_to_bytes() helper function. */ + ret =3D spi_read(st->spi, &st->data.scan.chan, + BITS_TO_BYTES(scan_type->realbits)); if (ret < 0) goto out; =20 --=20 2.34.1 From nobody Tue Dec 16 07:32:59 2025 Received: from mx0b-00128a01.pphosted.com (mx0a-00128a01.pphosted.com [148.163.135.77]) (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 BD8D2283C93; Thu, 8 May 2025 17:05:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.135.77 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746723928; cv=none; b=HoVdpDq6sQH6vuZIDPT/bPkCzJkGDg92UOwlt/KNxV7HiRSyiRJvRxotwDrilyCaoR+ES1glUqMm9/mZDoqXs1KcwPIWgidbi23fK3MZD2XSpQeZ8mFgLwj4xsrbD9Mw5e3lFjCE2N4FH80gmtd+fDlSoXZ+IUBR30GFugi5Q74= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746723928; c=relaxed/simple; bh=G90WR2iPUbB/W0xxHWC286PHvT2KYqOZov7+GEl2tCg=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=LQErCKvIAFd6m93uOM87xfru+WPy0lcsPZmSQdoh6DGRv4krrHPLNxaCGkxF1Qq/ABHL/uEzz185xs1Y1YZbmhu9bZr64ulrBzIUWMmY50+Mm3EaIiYH0YfKwHSSToodenfTLQvAm/CfNhNPbibU1GJUvnlG/QK2oPQWfU1wlhc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=analog.com; spf=pass smtp.mailfrom=analog.com; dkim=pass (2048-bit key) header.d=analog.com header.i=@analog.com header.b=B/TuC4Nw; arc=none smtp.client-ip=148.163.135.77 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=analog.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=analog.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=analog.com header.i=@analog.com header.b="B/TuC4Nw" Received: from pps.filterd (m0375855.ppops.net [127.0.0.1]) by mx0b-00128a01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 548FSXA8000696; Thu, 8 May 2025 13:05:19 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=analog.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=DKIM; bh=kaPzF 3pSzBLf/mhOa3+GrQFfbAo4BL/PV1KBCk+lUEw=; b=B/TuC4NwOtqM2Ma5d3ayH Xi5voPAwaAeEOH84oi1b37lWKze7KrnKYpA4s0azHsWacX6BFKvEp/S2BUbWtbYp +ZGp0H74dbu8CW7Tvq7tCXq939MT7wqofCFK2yUS9TxLN9mYH9G/tQ42QaTeJSHn ZbpcPYxp1ZmAwSFyCDVWMcvMjSsU2siu6Wriq5P/XtJNVAs35g1R/M4DG33zCePF VUJGtgaGVy/g6fO1d2lZ0WhXSfl96BGvdTGAiNI6SEOT1ojo8//I+DJxnpgWFpkS zRdcHtidNPYBDY0WsAcbtMtKwiEOdYrjLgGbAs1cbKwGUuTGuxFuLjsF4Qv9EZyA Q== Received: from nwd2mta3.analog.com ([137.71.173.56]) by mx0b-00128a01.pphosted.com (PPS) with ESMTPS id 46gy9q8ddr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 May 2025 13:05:19 -0400 (EDT) Received: from ASHBMBX9.ad.analog.com (ASHBMBX9.ad.analog.com [10.64.17.10]) by nwd2mta3.analog.com (8.14.7/8.14.7) with ESMTP id 548H5I2V052870 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 8 May 2025 13:05:18 -0400 Received: from ASHBCASHYB4.ad.analog.com (10.64.17.132) by ASHBMBX9.ad.analog.com (10.64.17.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.14; Thu, 8 May 2025 13:05:18 -0400 Received: from ASHBMBX8.ad.analog.com (10.64.17.5) by ASHBCASHYB4.ad.analog.com (10.64.17.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.14; Thu, 8 May 2025 13:05:17 -0400 Received: from zeus.spd.analog.com (10.66.68.11) by ashbmbx8.ad.analog.com (10.64.17.5) with Microsoft SMTP Server id 15.2.986.14 via Frontend Transport; Thu, 8 May 2025 13:05:17 -0400 Received: from JSANTO12-L01.ad.analog.com ([10.65.60.206]) by zeus.spd.analog.com (8.15.1/8.15.1) with ESMTP id 548H51Lf015902; Thu, 8 May 2025 13:05:04 -0400 From: Jonathan Santos To: , , , CC: Jonathan Santos , , , , , , , , , , , , , , , Subject: [PATCH v7 09/12] iio: adc: ad7768-1: add support for Synchronization over SPI Date: Thu, 8 May 2025 14:04:59 -0300 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: 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 X-ADIRuleOP-NewSCL: Rule Triggered X-Proofpoint-GUID: tb4FY0le8AE3yPyCUnsXLgMry3FueU6n X-Authority-Analysis: v=2.4 cv=f/ZIBPyM c=1 sm=1 tr=0 ts=681ce44f cx=c_pps a=PpDZqlmH/M8setHirZLBMw==:117 a=PpDZqlmH/M8setHirZLBMw==:17 a=IkcTkHD0fZMA:10 a=dt9VzEwgFbYA:10 a=gAnH3GRIAAAA:8 a=iJ8I5K2Yu_XRBJMqjaQA:9 a=3ZKOabzyN94A:10 a=QEXdDO2ut3YA:10 X-Proofpoint-ORIG-GUID: tb4FY0le8AE3yPyCUnsXLgMry3FueU6n X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUwNTA4MDE0OSBTYWx0ZWRfX3qEjZXLRZTXY aSoIk2LUVrP6KtXAJJg+H+yOkzACmsIElbNxTVPDbVIklbtdfLG6gqSe+nCzBxWsbqvDv5WVaWG wL4gqPlivAkvgkI3P+UPfcgszc2jgn6q+3R86hLOXpudbfp7qvYniQDTi5Wl/Lb5bh4f40EW1b7 fqs2kt/d/acYNPyeQMMWlIwNPehSE2zr8GIFUAMY74TjnYJs3E47UR/Ou2EqMDp99NI3b3fLBJP 2vc7BDtkg2yx5DPZ/0LKm1py7CV0P3zh3dTm1IlFED4PaLD5CzOjTkJDY6BSip73p4zoFprhVir 157rcUemOk2Ts41p/PkeaswnmuKDP1X90YJ0siez9cC0wtdAnip7zVQOnWXC9BazYRrlg0qnbo2 o8XHkGavP7FfNQFZGfW9RWqsvzv21nD3sLqyET1QtlistDkLCQ90dGXsYi+Aul53EMWsW5yL X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1099,Hydra:6.0.736,FMLib:17.12.80.40 definitions=2025-05-08_05,2025-05-08_02,2025-02-21_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 malwarescore=0 adultscore=0 mlxscore=0 impostorscore=0 suspectscore=0 priorityscore=1501 phishscore=0 bulkscore=0 lowpriorityscore=0 spamscore=0 mlxlogscore=999 classifier=spam authscore=0 authtc=n/a authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.19.0-2504070000 definitions=main-2505080149 The synchronization method using GPIO requires the generated pulse to be truly synchronous with the base MCLK signal. When it is not possible to do that in hardware, the datasheet recommends using synchronization over SPI, where the generated pulse is already synchronous with MCLK. This requires the SYNC_OUT pin to be connected to the SYNC_IN pin. Use trigger-sources property to enable device synchronization over SPI and multi-device synchronization while replacing sync-in-gpios property. Signed-off-by: Jonathan Santos --- v7 Changes: * Added delay in the synchronization pulse via GPIO. * replaced device_property_present() for fwnode_property_present(). * Refactored ad7768_trigger_sources_get_sync() to avoid excessive jumps. * Self triggering is enabled only when the trigger-sources property is not defined. Added TODO to support other trigger sources when the subsyst= em is available. v6 Changes: * Created macro for the SYNC index from trigger-sources. * Check trigger source by the compatible string (and the dev node for the self triggering). * Check nargs before accessing the args array. * Use `trigger-sources` as an alternative to `adi,sync-in-gpios` (now optional), instead of replacing it.=20 v5 Changes: * Allow omitting trigger-sources property. * include gpio-trigger to trigger-sources to replace adi,sync-in-gpios property. * Read trigger-sources cell value to differentiate the trigger type. v4 Changes: * None. v3 Changes: * Fixed args.fwnode leakage in the trigger-sources parsing. * Synchronization over spi is enabled when the trigger-sources references the own device. * Synchronization is kept within the device, and return error if the gpio is not defined and the trigger-sources reference does not match the current device.=20 v2 Changes: * Synchronization via SPI is enabled when the Sync GPIO is not defined. * now trigger-sources property indicates the synchronization provider or main device. The main device will be used to drive the SYNC_IN when requested (via GPIO or SPI). --- drivers/iio/adc/ad7768-1.c | 111 +++++++++++++++++++++++++++++++++++-- 1 file changed, 105 insertions(+), 6 deletions(-) diff --git a/drivers/iio/adc/ad7768-1.c b/drivers/iio/adc/ad7768-1.c index 19b9744dfd1b..cdcc77ca04fa 100644 --- a/drivers/iio/adc/ad7768-1.c +++ b/drivers/iio/adc/ad7768-1.c @@ -29,6 +29,8 @@ #include #include =20 +#include + /* AD7768 registers definition */ #define AD7768_REG_CHIP_TYPE 0x3 #define AD7768_REG_PROD_ID_L 0x4 @@ -101,6 +103,8 @@ =20 #define AD7768_VCM_OFF 0x07 =20 +#define AD7768_TRIGGER_SOURCE_SYNC_IDX 0 + enum ad7768_conv_mode { AD7768_CONTINUOUS, AD7768_ONE_SHOT, @@ -209,6 +213,7 @@ struct ad7768_state { struct iio_trigger *trig; struct gpio_desc *gpio_sync_in; struct gpio_desc *gpio_reset; + bool en_spi_sync; const char *labels[ARRAY_SIZE(ad7768_channels)]; struct gpio_chip gpiochip; /* @@ -296,6 +301,27 @@ static const struct regmap_config ad7768_regmap24_conf= ig =3D { .max_register =3D AD7768_REG24_COEFF_DATA, }; =20 +static int ad7768_send_sync_pulse(struct ad7768_state *st) +{ + if (st->en_spi_sync) + return regmap_write(st->regmap, AD7768_REG_SYNC_RESET, 0x00); + + /* + * The datasheet specifies a minimum SYNC_IN pulse width of 1.5 =C3=97 Tm= clk, + * where Tmclk is the MCLK period. The supported MCLK frequencies range + * from 0.6 MHz to 17 MHz, which corresponds to a minimum SYNC_IN pulse + * width of approximately 2.5 =C2=B5s in the worst-case scenario (0.6 MHz= ). + * + * Add a delay to ensure the pulse width is always sufficient to + * trigger synchronization. + */ + gpiod_set_value_cansleep(st->gpio_sync_in, 1); + fsleep(3); + gpiod_set_value_cansleep(st->gpio_sync_in, 0); + + return 0; +} + static int ad7768_set_mode(struct ad7768_state *st, enum ad7768_conv_mode mode) { @@ -392,10 +418,7 @@ static int ad7768_set_dig_fil(struct ad7768_state *st, return ret; =20 /* A sync-in pulse is required every time the filter dec rate changes */ - gpiod_set_value(st->gpio_sync_in, 1); - gpiod_set_value(st->gpio_sync_in, 0); - - return 0; + return ad7768_send_sync_pulse(st); } =20 static int ad7768_gpio_direction_input(struct gpio_chip *chip, unsigned in= t offset) @@ -672,6 +695,71 @@ static const struct iio_info ad7768_info =3D { .debugfs_reg_access =3D &ad7768_reg_access, }; =20 +static struct gpio_desc *ad7768_trigger_source_get_gpio(struct device *dev, + struct fwnode_handle *fwnode) +{ + if (!fwnode_device_is_compatible(fwnode, "gpio-trigger")) + return ERR_PTR(-EINVAL); + + return devm_fwnode_gpiod_get_index(dev, fwnode, NULL, 0, + GPIOD_OUT_LOW, "sync-in"); +} + +static int ad7768_trigger_sources_get_sync(struct device *dev, + struct ad7768_state *st) +{ + struct fwnode_reference_args args; + struct fwnode_handle *fwnode =3D dev_fwnode(dev); + int ret; + + /* + * The AD7768-1 allows two primary methods for driving the SYNC_IN pin + * to synchronize one or more devices: + * 1. Using an external GPIO. + * 2. Using a SPI command, where the SYNC_OUT pin generates a + * synchronization pulse that drives the SYNC_IN pin. + */ + if (!fwnode_property_present(fwnode, "trigger-sources")) { + /* + * In the absence of trigger-sources property, enable self + * synchronization over SPI (SYNC_OUT). + */ + st->en_spi_sync =3D true; + return 0; + } + + ret =3D fwnode_property_get_reference_args(fwnode, + "trigger-sources", + "#trigger-source-cells", + 0, + AD7768_TRIGGER_SOURCE_SYNC_IDX, + &args); + if (ret) + return ret; + + fwnode =3D args.fwnode; + /* + * First, try getting the GPIO trigger source and fallback to + * synchronization over SPI in case of failure. + */ + st->gpio_sync_in =3D ad7768_trigger_source_get_gpio(dev, fwnode); + if (!IS_ERR(st->gpio_sync_in)) + goto out_put_node; + + /* + * TODO: Support the other cases when we have a trigger subsystem to + * reliably handle other types of devices as trigger sources. + * + * For now, return an error message. For self triggering, omit the + * trigger-sources property. + */ + ret =3D dev_err_probe(dev, -EOPNOTSUPP, "Invalid synchronization trigger = source\n"); + +out_put_node: + fwnode_handle_put(args.fwnode); + return ret; +} + static int ad7768_setup(struct iio_dev *indio_dev) { struct ad7768_state *st =3D iio_priv(indio_dev); @@ -702,11 +790,22 @@ static int ad7768_setup(struct iio_dev *indio_dev) return ret; } =20 - st->gpio_sync_in =3D devm_gpiod_get(&st->spi->dev, "adi,sync-in", - GPIOD_OUT_LOW); + /* For backwards compatibility, try the adi,sync-in-gpios property */ + st->gpio_sync_in =3D devm_gpiod_get_optional(&st->spi->dev, "adi,sync-in", + GPIOD_OUT_LOW); if (IS_ERR(st->gpio_sync_in)) return PTR_ERR(st->gpio_sync_in); =20 + /* + * If the synchronization is not defined by adi,sync-in-gpios, try the + * trigger-sources. + */ + if (!st->gpio_sync_in) { + ret =3D ad7768_trigger_sources_get_sync(&st->spi->dev, st); + if (ret) + return ret; + } + /* Only create a Chip GPIO if flagged for it */ if (device_property_read_bool(&st->spi->dev, "gpio-controller")) { ret =3D ad7768_gpio_init(indio_dev); --=20 2.34.1 From nobody Tue Dec 16 07:32:59 2025 Received: from mx0a-00128a01.pphosted.com (mx0a-00128a01.pphosted.com [148.163.135.77]) (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 1BEB5283C93; Thu, 8 May 2025 17:05:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.135.77 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746723942; cv=none; b=XchL+rIjGPuyEAxbPF7891srigq1BWx9Ny9cTAM5IAmaRqcVxeVlhxuU23rSqtizyvX3fIjZY7A00r3Pn9mwLxjAypLmDWzbh/CuCf1mu5lLteMlqX2cLVk7KVNwiSpFDHPkxchwHxtItr2n9g2stY3vwyvVUU4bKiWv/MeOHTI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746723942; c=relaxed/simple; bh=11K8eQH1eCNfHvIvazgosscnvLkPqyoal/rCyssY8Mw=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=XXM/S8PJlGn9nm2t8to3A48fqSZVFZ4OQ6EF00YaSKqzjnwbaIVcQ5q/LA84FdrN9nP8Jw3gqp6e3ieMu+o7fgdNjDZywV2QnlPuKAHMJh/94I0lZ3q3srWi83KT43zW13W0isS655YOQIJpaea7mz0vjn+0YA+GSTKWwh4j2uo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=analog.com; spf=pass smtp.mailfrom=analog.com; dkim=pass (2048-bit key) header.d=analog.com header.i=@analog.com header.b=sFSXpM0q; arc=none smtp.client-ip=148.163.135.77 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=analog.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=analog.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=analog.com header.i=@analog.com header.b="sFSXpM0q" Received: from pps.filterd (m0167089.ppops.net [127.0.0.1]) by mx0a-00128a01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 548Dw4gF024036; Thu, 8 May 2025 13:05:32 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=analog.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=DKIM; bh=Q9+bt ezNVe+9C3g3AsDDaflOhF4LX9zDCtFjqNOdbWI=; b=sFSXpM0qmz+OMsD/qXcN3 U9Rt39f+iHpqTy/gP/+PakLFBUZNLdMaU7e7V+WeRBMuLMQXc4WK0TGgr0sVe38j 7nJOHNOk906LYA8652DN64/w5FRY3V/DDG6kGVmyxy6+JRYcRHdROWNxryYKJ3YB RbtzRpYMfsSFTH8wHyt80Vvofx9OeKKh+9oBDNUk6EtLFIFJXM90V8DbCUjbf9t1 tOzQyZ+nMhLaOspdsVfQf48TSpXxME6r7l+cOSoBlzbpvLmPaFjtToKztcet29V6 xkxZOXusBOI1MnVTqMQd+bsdSk5lpSTpydr1tBV41gpUFTxhw2fpDZeAFu1hWF78 g== Received: from nwd2mta3.analog.com ([137.71.173.56]) by mx0a-00128a01.pphosted.com (PPS) with ESMTPS id 46gpctb1xm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 May 2025 13:05:31 -0400 (EDT) Received: from ASHBMBX9.ad.analog.com (ASHBMBX9.ad.analog.com [10.64.17.10]) by nwd2mta3.analog.com (8.14.7/8.14.7) with ESMTP id 548H5Ukn052912 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 8 May 2025 13:05:30 -0400 Received: from ASHBCASHYB5.ad.analog.com (10.64.17.133) by ASHBMBX9.ad.analog.com (10.64.17.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.14; Thu, 8 May 2025 13:05:30 -0400 Received: from ASHBMBX8.ad.analog.com (10.64.17.5) by ASHBCASHYB5.ad.analog.com (10.64.17.133) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.14; Thu, 8 May 2025 13:05:30 -0400 Received: from zeus.spd.analog.com (10.66.68.11) by ashbmbx8.ad.analog.com (10.64.17.5) with Microsoft SMTP Server id 15.2.986.14 via Frontend Transport; Thu, 8 May 2025 13:05:30 -0400 Received: from JSANTO12-L01.ad.analog.com ([10.65.60.206]) by zeus.spd.analog.com (8.15.1/8.15.1) with ESMTP id 548H5Ecu015945; Thu, 8 May 2025 13:05:16 -0400 From: Jonathan Santos To: , , , CC: Jonathan Santos , , , , , , , , , , , , , , , Subject: [PATCH v7 10/12] iio: adc: ad7768-1: replace manual attribute declaration Date: Thu, 8 May 2025 14:05:13 -0300 Message-ID: <7987725e62f53c4b2cf74dacced0a47ad055f4a9.1746662899.git.Jonathan.Santos@analog.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ADIRuleOP-NewSCL: Rule Triggered X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUwNTA4MDE0OSBTYWx0ZWRfX0RdoiycH5vKQ mZUz2aWjgGfaUeszcurqgOseTDMAz820u1HtSciISsHxYHGxQW7T1QWAevVdATlq0yXC5iOkpqJ pTyaKDpcpfzZvwLLdIq6xFnMXDy6nw8oNtkioK+UVfA4YDSNt19iq2F+C/rgg3ty2xTLiblc+ts h/1W8UH8w+oATbtx8/LVvX5nOuUZPLNMNz486cfCABM/N2v8kItccJJClHpB/inmr86bS7rORDJ mICdF+7zXap9VrGSR8Zz7QDXveUJ8+KdZfmGmJYtTwCHETGL0aTTgGjYNr0qYEPwaHcqYgPs2Xq YQyFBgWWV+Hh6wGT6RqfGLlbaMKKCOh0CzlBZMi6xndWYNPaJj2e4bFVHEQB1MAquEzf4a76Q/T Dp4QhoEmHxlbRNDLUt//pmS2KuC/GZg+Fik95bOhtuikESmV2vpsS7+Mas4cX10XwYIA6dA1 X-Authority-Analysis: v=2.4 cv=Ur5jN/wB c=1 sm=1 tr=0 ts=681ce45c cx=c_pps a=PpDZqlmH/M8setHirZLBMw==:117 a=PpDZqlmH/M8setHirZLBMw==:17 a=dt9VzEwgFbYA:10 a=IpJZQVW2AAAA:8 a=gAnH3GRIAAAA:8 a=L6hIjVXnctlZ6DB8sOoA:9 a=IawgGOuG5U0WyFbmm1f5:22 X-Proofpoint-GUID: 1gR7seJV48ZfjXcoYlkHd8jVegA7VOUN X-Proofpoint-ORIG-GUID: 1gR7seJV48ZfjXcoYlkHd8jVegA7VOUN X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1099,Hydra:6.0.736,FMLib:17.12.80.40 definitions=2025-05-08_05,2025-05-08_02,2025-02-21_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 suspectscore=0 adultscore=0 bulkscore=0 malwarescore=0 priorityscore=1501 spamscore=0 impostorscore=0 lowpriorityscore=0 mlxlogscore=999 clxscore=1015 phishscore=0 classifier=spam authscore=0 authtc=n/a authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.19.0-2504070000 definitions=main-2505080149 Content-Type: text/plain; charset="utf-8" Use read_avail callback from struct iio_info to replace the manual declaration of sampling_frequency_available attribute. Reviewed-by: David Lechner Reviewed-by: Marcelo Schmitt Signed-off-by: Jonathan Santos --- v7 Changes: * Iteractor changed to unsigned in the ad7768_fill_samp_freq_tbl() function. v6 Changes: * none. v5 Changes: * none. v4 Changes: * Added ad7768_fill_samp_freq_tbl() helper function. * Sampling frequency table is precomputed at probe. v3 Changes: * New patch in v3. --- drivers/iio/adc/ad7768-1.c | 63 +++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 32 deletions(-) diff --git a/drivers/iio/adc/ad7768-1.c b/drivers/iio/adc/ad7768-1.c index cdcc77ca04fa..260eed41e504 100644 --- a/drivers/iio/adc/ad7768-1.c +++ b/drivers/iio/adc/ad7768-1.c @@ -189,6 +189,7 @@ static const struct iio_chan_spec ad7768_channels[] =3D= { .info_mask_separate =3D BIT(IIO_CHAN_INFO_RAW), .info_mask_shared_by_type =3D BIT(IIO_CHAN_INFO_SCALE), .info_mask_shared_by_all =3D BIT(IIO_CHAN_INFO_SAMP_FREQ), + .info_mask_shared_by_all_available =3D BIT(IIO_CHAN_INFO_SAMP_FREQ), .indexed =3D 1, .channel =3D 0, .scan_index =3D 0, @@ -209,6 +210,7 @@ struct ad7768_state { unsigned int mclk_freq; unsigned int dec_rate; unsigned int samp_freq; + unsigned int samp_freq_avail[ARRAY_SIZE(ad7768_clk_config)]; struct completion completion; struct iio_trigger *trig; struct gpio_desc *gpio_sync_in; @@ -322,6 +324,15 @@ static int ad7768_send_sync_pulse(struct ad7768_state = *st) return 0; } =20 +static void ad7768_fill_samp_freq_tbl(struct ad7768_state *st) +{ + unsigned int i; + + for (i =3D 0; i < ARRAY_SIZE(ad7768_clk_config); i++) + st->samp_freq_avail[i] =3D DIV_ROUND_CLOSEST(st->mclk_freq, + ad7768_clk_config[i].clk_div); +} + static int ad7768_set_mode(struct ad7768_state *st, enum ad7768_conv_mode mode) { @@ -579,28 +590,6 @@ static int ad7768_set_freq(struct ad7768_state *st, return 0; } =20 -static ssize_t ad7768_sampling_freq_avail(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - struct iio_dev *indio_dev =3D dev_to_iio_dev(dev); - struct ad7768_state *st =3D iio_priv(indio_dev); - unsigned int freq; - int i, len =3D 0; - - for (i =3D 0; i < ARRAY_SIZE(ad7768_clk_config); i++) { - freq =3D DIV_ROUND_CLOSEST(st->mclk_freq, - ad7768_clk_config[i].clk_div); - len +=3D scnprintf(buf + len, PAGE_SIZE - len, "%d ", freq); - } - - buf[len - 1] =3D '\n'; - - return len; -} - -static IIO_DEV_ATTR_SAMP_FREQ_AVAIL(ad7768_sampling_freq_avail); - static int ad7768_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val, int *val2, long info) @@ -646,6 +635,24 @@ static int ad7768_read_raw(struct iio_dev *indio_dev, return -EINVAL; } =20 +static int ad7768_read_avail(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + const int **vals, int *type, int *length, + long info) +{ + struct ad7768_state *st =3D iio_priv(indio_dev); + + switch (info) { + case IIO_CHAN_INFO_SAMP_FREQ: + *vals =3D (int *)st->samp_freq_avail; + *length =3D ARRAY_SIZE(ad7768_clk_config); + *type =3D IIO_VAL_INT; + return IIO_AVAIL_LIST; + default: + return -EINVAL; + } +} + static int ad7768_write_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int val, int val2, long info) @@ -668,15 +675,6 @@ static int ad7768_read_label(struct iio_dev *indio_dev, return sprintf(label, "%s\n", st->labels[chan->channel]); } =20 -static struct attribute *ad7768_attributes[] =3D { - &iio_dev_attr_sampling_frequency_available.dev_attr.attr, - NULL -}; - -static const struct attribute_group ad7768_group =3D { - .attrs =3D ad7768_attributes, -}; - static int ad7768_get_current_scan_type(const struct iio_dev *indio_dev, const struct iio_chan_spec *chan) { @@ -687,8 +685,8 @@ static int ad7768_get_current_scan_type(const struct ii= o_dev *indio_dev, } =20 static const struct iio_info ad7768_info =3D { - .attrs =3D &ad7768_group, .read_raw =3D &ad7768_read_raw, + .read_avail =3D &ad7768_read_avail, .write_raw =3D &ad7768_write_raw, .read_label =3D ad7768_read_label, .get_current_scan_type =3D &ad7768_get_current_scan_type, @@ -1147,6 +1145,7 @@ static int ad7768_probe(struct spi_device *spi) return PTR_ERR(st->mclk); =20 st->mclk_freq =3D clk_get_rate(st->mclk); + ad7768_fill_samp_freq_tbl(st); =20 indio_dev->channels =3D ad7768_channels; indio_dev->num_channels =3D ARRAY_SIZE(ad7768_channels); --=20 2.34.1 From nobody Tue Dec 16 07:32:59 2025 Received: from mx0b-00128a01.pphosted.com (mx0a-00128a01.pphosted.com [148.163.135.77]) (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 31449283C93; Thu, 8 May 2025 17:05:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.135.77 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746723962; cv=none; b=TidP6yEX9ZBw7FwIlI5HzC+crgdy5Q19tIzFK1933ekd/fDU6TsdifXxcisodSFZN/XEUfSXBrfh/5JOp0vzGqghQ8D3DWiLIYACqX+Zr/CZS7ymGG+T5sMxyRpCW2iooaAEL6q84hJb5yKwegDRmYkpf4Csi0RW/VH5B8OIgwg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746723962; c=relaxed/simple; bh=HBuU66S3VTq8i7o8eklJa2hkCmWyLRvco9Ii+S60nsA=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=MuqZBBPsPZVxtJx/NrOMnt0Ul1sGU+QX4lZAN7UpjzS6eFqOB284m/B+LeQsp7mnMFOh9hiUQ6aecK7+AjGQnxnWBtuP91sy1P0BmV9CJvVMzoG0pTmm8LkvhpKCSkWbk6IWC7ubAF8X2mSGdetVA2DecoIXeOElhLZHz7n0eUc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=analog.com; spf=pass smtp.mailfrom=analog.com; dkim=pass (2048-bit key) header.d=analog.com header.i=@analog.com header.b=zdLInItu; arc=none smtp.client-ip=148.163.135.77 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=analog.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=analog.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=analog.com header.i=@analog.com header.b="zdLInItu" Received: from pps.filterd (m0375855.ppops.net [127.0.0.1]) by mx0b-00128a01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 548FSXAD000696; Thu, 8 May 2025 13:05:43 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=analog.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=DKIM; bh=SS+Fb mOiFC7N0sPyXObj+cKQUUs11jhkykrBVHjB0XE=; b=zdLInItusKlyEUQpFkbbo ZtYOY4uUfiirK9XwqrMvrHgX5Nzo/I3PcVoyPSbGEr7VNSwqlAQeGbueZJjW/HdG AulRNpuD0VLvVpAEPqp0wjEaPY0svu5Zd+UlxIoWeb60vnvl6DdH8NxL6lUW37RG dXsXoROmfQ+UKPGldVzctsPU7qxIdYJ67RhIzfiDTfJxsqPNFIL8rY/udrqLgJ0i ajFcgupdK3ZeUxzo12n7FDQ35O9743AFyG32Rey1EF2daE9tw649edgh5auG1v1D xDo+0akUeZ0U74TZTn1hCHr2MMm+yCyTVmTlcGft4ltIv0jbVYrZqsSWYPXff7ay w== Received: from nwd2mta3.analog.com ([137.71.173.56]) by mx0b-00128a01.pphosted.com (PPS) with ESMTPS id 46gy9q8dff-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 May 2025 13:05:42 -0400 (EDT) Received: from ASHBMBX8.ad.analog.com (ASHBMBX8.ad.analog.com [10.64.17.5]) by nwd2mta3.analog.com (8.14.7/8.14.7) with ESMTP id 548H5f2b052952 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 8 May 2025 13:05:41 -0400 Received: from ASHBCASHYB5.ad.analog.com (10.64.17.133) by ASHBMBX8.ad.analog.com (10.64.17.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.14; Thu, 8 May 2025 13:05:41 -0400 Received: from ASHBMBX8.ad.analog.com (10.64.17.5) by ASHBCASHYB5.ad.analog.com (10.64.17.133) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.14; Thu, 8 May 2025 13:05:41 -0400 Received: from zeus.spd.analog.com (10.66.68.11) by ashbmbx8.ad.analog.com (10.64.17.5) with Microsoft SMTP Server id 15.2.986.14 via Frontend Transport; Thu, 8 May 2025 13:05:41 -0400 Received: from JSANTO12-L01.ad.analog.com ([10.65.60.206]) by zeus.spd.analog.com (8.15.1/8.15.1) with ESMTP id 548H5QhQ015951; Thu, 8 May 2025 13:05:29 -0400 From: Jonathan Santos To: , , , CC: Jonathan Santos , , , , , , , , , , , , , , , , "Pop Paul" Subject: [PATCH v7 11/12] iio: adc: ad7768-1: add filter type and oversampling ratio attributes Date: Thu, 8 May 2025 14:05:26 -0300 Message-ID: <2180d8774a2fdef3900f86fbc8f25886503df479.1746662899.git.Jonathan.Santos@analog.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ADIRuleOP-NewSCL: Rule Triggered X-Proofpoint-GUID: KgNR3SMqWZc7U9nZJbFnipxcFMD7ceu7 X-Authority-Analysis: v=2.4 cv=f/ZIBPyM c=1 sm=1 tr=0 ts=681ce466 cx=c_pps a=PpDZqlmH/M8setHirZLBMw==:117 a=PpDZqlmH/M8setHirZLBMw==:17 a=dt9VzEwgFbYA:10 a=IpJZQVW2AAAA:8 a=gAnH3GRIAAAA:8 a=EP7K-5VxzDsVkbtTEdQA:9 a=IawgGOuG5U0WyFbmm1f5:22 X-Proofpoint-ORIG-GUID: KgNR3SMqWZc7U9nZJbFnipxcFMD7ceu7 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUwNTA4MDE0OSBTYWx0ZWRfXx50DYk3HO/Z/ Tg0HBx5rXtM3HQEowVywfHsKomfbTh8nJgoRQ9A+jxsKz4BTp5jcqtUVYKKryMYJAarc7BgL8iv 9lvKSfUO83tBU728xJrBB4oxmFJZkjt+y9J50Yy0mxCytrhm1hl621HYdfd87JgXSvWeKntzfp9 TJKxf2+q2sBSJ6I3xZP5abF/81+FID9R9tKdffcqcL1aFdBgZxPKnDIOOqgoFNv0w5BVhcQ5kDp V27TA7vC1rGqiy6/94eTEv1p5RhonbyM905sXeJe3aObjjt6hf+AIH4/6XPpy1zIBeWc2qWiJeH vaiPCcG0MlmgYlIaWAGRPVh7tSxoE/2cw2mEqWCedus09k4As4JpJ9xzptbKLkSo5RTGbwIx32g aTkzAoxB+MwLlO7rjlMERp7g5PaIGKw2vyVLMPFToVgYgYjEldDWNA+Ylif/Qh6ri5NA3yxr X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1099,Hydra:6.0.736,FMLib:17.12.80.40 definitions=2025-05-08_05,2025-05-08_02,2025-02-21_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 malwarescore=0 adultscore=0 mlxscore=0 impostorscore=0 suspectscore=0 priorityscore=1501 phishscore=0 bulkscore=0 lowpriorityscore=0 spamscore=0 mlxlogscore=999 classifier=spam authscore=0 authtc=n/a authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.19.0-2504070000 definitions=main-2505080149 Content-Type: text/plain; charset="utf-8" Separate filter type and decimation rate from the sampling frequency attribute. The new filter type attribute enables sinc3, sinc3+rej60 and wideband filters, which were previously unavailable. Previously, combining decimation and MCLK divider in the sampling frequency obscured performance trade-offs. Lower MCLK divider settings increase power usage, while lower decimation rates reduce precision by decreasing averaging. By creating an oversampling attribute, which controls the decimation, users gain finer control over performance. The addition of those attributes allows a wider range of sampling frequencies and more access to the device features. Sampling frequency table is updated after every digital filter parameter change. Changes in the sampling frequency are not allowed anymore while in buffered mode. Reviewed-by: David Lechner Co-developed-by: Pop Paul Signed-off-by: Pop Paul Signed-off-by: Jonathan Santos --- v7 Changes: * Refactor code to avoid forward declarations. * replaced clamp_t() for clamp(); * Mentioned that sampling frequency changes is not allowed in buffered mode. * removed 60Hz rejection enable from the filter mask and create AD7768_DIG_FIL_EN_60HZ_REJ for it. * addressed other nits. v6 Changes: * Made sinc3 decimation rate calculation clearer as requested. * Renamed some filter functions to clarify the purpose. * Other nits. v5 Changes: * Addressed some nits. * Use the new new iio_device_claim/release_direct() functions. v4 Changes: * Sampling frequency table is dynamically updated after every filter configuration. v3 Changes: * removed unused variables. * included sinc3+rej60 filter type. * oversampling_ratio moved to info_mask_shared_by_type. * reordered functions to avoid forward declaration. * simplified regmap writes. * Removed locking. * replaced some helper functions for direct regmap_update_bits calls. * Addressed other nits. v2 Changes: * Decimation_rate attribute replaced for oversampling_ratio. --- drivers/iio/adc/ad7768-1.c | 391 +++++++++++++++++++++++++++++-------- 1 file changed, 306 insertions(+), 85 deletions(-) diff --git a/drivers/iio/adc/ad7768-1.c b/drivers/iio/adc/ad7768-1.c index 260eed41e504..28998cb02761 100644 --- a/drivers/iio/adc/ad7768-1.c +++ b/drivers/iio/adc/ad7768-1.c @@ -21,6 +21,8 @@ #include #include #include +#include +#include =20 #include #include @@ -78,6 +80,7 @@ #define AD7768_PWR_PWRMODE(x) FIELD_PREP(AD7768_PWR_PWRMODE_MSK, x) =20 /* AD7768_REG_DIGITAL_FILTER */ +#define AD7768_DIG_FIL_EN_60HZ_REJ BIT(7) #define AD7768_DIG_FIL_FIL_MSK GENMASK(6, 4) #define AD7768_DIG_FIL_FIL(x) FIELD_PREP(AD7768_DIG_FIL_FIL_MSK, x) #define AD7768_DIG_FIL_DEC_MSK GENMASK(2, 0) @@ -105,6 +108,8 @@ =20 #define AD7768_TRIGGER_SOURCE_SYNC_IDX 0 =20 +#define AD7768_MAX_CHANNELS 1 + enum ad7768_conv_mode { AD7768_CONTINUOUS, AD7768_ONE_SHOT, @@ -126,22 +131,20 @@ enum ad7768_mclk_div { AD7768_MCLK_DIV_2 }; =20 -enum ad7768_dec_rate { - AD7768_DEC_RATE_32 =3D 0, - AD7768_DEC_RATE_64 =3D 1, - AD7768_DEC_RATE_128 =3D 2, - AD7768_DEC_RATE_256 =3D 3, - AD7768_DEC_RATE_512 =3D 4, - AD7768_DEC_RATE_1024 =3D 5, - AD7768_DEC_RATE_8 =3D 9, - AD7768_DEC_RATE_16 =3D 10 +enum ad7768_filter_type { + AD7768_FILTER_SINC5, + AD7768_FILTER_SINC3, + AD7768_FILTER_WIDEBAND, + AD7768_FILTER_SINC3_REJ60, }; =20 -struct ad7768_clk_configuration { - enum ad7768_mclk_div mclk_div; - enum ad7768_dec_rate dec_rate; - unsigned int clk_div; - enum ad7768_pwrmode pwrmode; +enum ad7768_filter_regval { + AD7768_FILTER_REGVAL_SINC5 =3D 0, + AD7768_FILTER_REGVAL_SINC5_X8 =3D 1, + AD7768_FILTER_REGVAL_SINC5_X16 =3D 2, + AD7768_FILTER_REGVAL_SINC3 =3D 3, + AD7768_FILTER_REGVAL_WIDEBAND =3D 4, + AD7768_FILTER_REGVAL_SINC3_REJ60 =3D 11, }; =20 enum ad7768_scan_type { @@ -153,18 +156,39 @@ static const int ad7768_mclk_div_rates[] =3D { 16, 8, 4, 2, }; =20 -static const struct ad7768_clk_configuration ad7768_clk_config[] =3D { - { AD7768_MCLK_DIV_2, AD7768_DEC_RATE_8, 16, AD7768_FAST_MODE }, - { AD7768_MCLK_DIV_2, AD7768_DEC_RATE_16, 32, AD7768_FAST_MODE }, - { AD7768_MCLK_DIV_2, AD7768_DEC_RATE_32, 64, AD7768_FAST_MODE }, - { AD7768_MCLK_DIV_2, AD7768_DEC_RATE_64, 128, AD7768_FAST_MODE }, - { AD7768_MCLK_DIV_2, AD7768_DEC_RATE_128, 256, AD7768_FAST_MODE }, - { AD7768_MCLK_DIV_4, AD7768_DEC_RATE_128, 512, AD7768_MED_MODE }, - { AD7768_MCLK_DIV_4, AD7768_DEC_RATE_256, 1024, AD7768_MED_MODE }, - { AD7768_MCLK_DIV_4, AD7768_DEC_RATE_512, 2048, AD7768_MED_MODE }, - { AD7768_MCLK_DIV_4, AD7768_DEC_RATE_1024, 4096, AD7768_MED_MODE }, - { AD7768_MCLK_DIV_8, AD7768_DEC_RATE_1024, 8192, AD7768_MED_MODE }, - { AD7768_MCLK_DIV_16, AD7768_DEC_RATE_1024, 16384, AD7768_ECO_MODE }, +static const int ad7768_dec_rate_values[8] =3D { + 8, 16, 32, 64, 128, 256, 512, 1024, +}; + +/* Decimation Rate range for each filter type */ +static const int ad7768_dec_rate_range[][3] =3D { + [AD7768_FILTER_SINC5] =3D { 8, 8, 1024 }, + [AD7768_FILTER_SINC3] =3D { 32, 32, 163840 }, + [AD7768_FILTER_WIDEBAND] =3D { 32, 32, 1024 }, + [AD7768_FILTER_SINC3_REJ60] =3D { 32, 32, 163840 }, +}; + +/* + * The AD7768-1 supports three primary filter types: + * Sinc5, Sinc3, and Wideband. + * However, the filter register values can also encode additional paramete= rs + * such as decimation rates and 60Hz rejection. This utility array separat= es + * the filter type from these parameters. + */ +static const int ad7768_filter_regval_to_type[] =3D { + [AD7768_FILTER_REGVAL_SINC5] =3D AD7768_FILTER_SINC5, + [AD7768_FILTER_REGVAL_SINC5_X8] =3D AD7768_FILTER_SINC5, + [AD7768_FILTER_REGVAL_SINC5_X16] =3D AD7768_FILTER_SINC5, + [AD7768_FILTER_REGVAL_SINC3] =3D AD7768_FILTER_SINC3, + [AD7768_FILTER_REGVAL_WIDEBAND] =3D AD7768_FILTER_WIDEBAND, + [AD7768_FILTER_REGVAL_SINC3_REJ60] =3D AD7768_FILTER_SINC3_REJ60, +}; + +static const char * const ad7768_filter_enum[] =3D { + [AD7768_FILTER_SINC5] =3D "sinc5", + [AD7768_FILTER_SINC3] =3D "sinc3", + [AD7768_FILTER_WIDEBAND] =3D "wideband", + [AD7768_FILTER_SINC3_REJ60] =3D "sinc3+rej60" }; =20 static const struct iio_scan_type ad7768_scan_type[] =3D { @@ -183,22 +207,6 @@ static const struct iio_scan_type ad7768_scan_type[] = =3D { }, }; =20 -static const struct iio_chan_spec ad7768_channels[] =3D { - { - .type =3D IIO_VOLTAGE, - .info_mask_separate =3D BIT(IIO_CHAN_INFO_RAW), - .info_mask_shared_by_type =3D BIT(IIO_CHAN_INFO_SCALE), - .info_mask_shared_by_all =3D BIT(IIO_CHAN_INFO_SAMP_FREQ), - .info_mask_shared_by_all_available =3D BIT(IIO_CHAN_INFO_SAMP_FREQ), - .indexed =3D 1, - .channel =3D 0, - .scan_index =3D 0, - .has_ext_scan_type =3D 1, - .ext_scan_type =3D ad7768_scan_type, - .num_ext_scan_type =3D ARRAY_SIZE(ad7768_scan_type), - }, -}; - struct ad7768_state { struct spi_device *spi; struct regmap *regmap; @@ -208,15 +216,18 @@ struct ad7768_state { unsigned int vcm_output_sel; struct clk *mclk; unsigned int mclk_freq; - unsigned int dec_rate; + unsigned int mclk_div; + unsigned int oversampling_ratio; + enum ad7768_filter_type filter_type; unsigned int samp_freq; - unsigned int samp_freq_avail[ARRAY_SIZE(ad7768_clk_config)]; + unsigned int samp_freq_avail[ARRAY_SIZE(ad7768_mclk_div_rates)]; + unsigned int samp_freq_avail_len; struct completion completion; struct iio_trigger *trig; struct gpio_desc *gpio_sync_in; struct gpio_desc *gpio_reset; bool en_spi_sync; - const char *labels[ARRAY_SIZE(ad7768_channels)]; + const char *labels[AD7768_MAX_CHANNELS]; struct gpio_chip gpiochip; /* * DMA (thus cache coherency maintenance) may require the @@ -326,11 +337,36 @@ static int ad7768_send_sync_pulse(struct ad7768_state= *st) =20 static void ad7768_fill_samp_freq_tbl(struct ad7768_state *st) { - unsigned int i; + unsigned int i, freq_filtered, len =3D 0; + + freq_filtered =3D DIV_ROUND_CLOSEST(st->mclk_freq, st->oversampling_ratio= ); + for (i =3D 0; i < ARRAY_SIZE(ad7768_mclk_div_rates); i++) { + st->samp_freq_avail[len] =3D DIV_ROUND_CLOSEST(freq_filtered, + ad7768_mclk_div_rates[i]); + /* Sampling frequency cannot be lower than the minimum of 50 SPS */ + if (st->samp_freq_avail[len] >=3D 50) + len++; + } + + st->samp_freq_avail_len =3D len; +} + +static int ad7768_set_mclk_div(struct ad7768_state *st, unsigned int mclk_= div) +{ + unsigned int mclk_div_value; + + mclk_div_value =3D AD7768_PWR_MCLK_DIV(mclk_div); + /* + * Set power mode based on mclk_div value. + * ECO_MODE is only recommended for MCLK_DIV 16 + */ + mclk_div_value |=3D mclk_div > AD7768_MCLK_DIV_16 ? + AD7768_PWR_PWRMODE(AD7768_FAST_MODE) : + AD7768_PWR_PWRMODE(AD7768_ECO_MODE); =20 - for (i =3D 0; i < ARRAY_SIZE(ad7768_clk_config); i++) - st->samp_freq_avail[i] =3D DIV_ROUND_CLOSEST(st->mclk_freq, - ad7768_clk_config[i].clk_div); + return regmap_update_bits(st->regmap, AD7768_REG_POWER_CLOCK, + AD7768_PWR_MCLK_DIV_MSK | AD7768_PWR_PWRMODE_MSK, + mclk_div_value); } =20 static int ad7768_set_mode(struct ad7768_state *st, @@ -366,7 +402,7 @@ static int ad7768_scan_direct(struct iio_dev *indio_dev) * register provides 24-bit data, the precision is reduced by * right-shifting the read value by 8 bits. */ - if (st->dec_rate =3D=3D 8) + if (st->oversampling_ratio =3D=3D 8) readval >>=3D 8; =20 /* @@ -413,22 +449,110 @@ static int ad7768_reg_access(struct iio_dev *indio_d= ev, return ret; } =20 -static int ad7768_set_dig_fil(struct ad7768_state *st, - enum ad7768_dec_rate dec_rate) +static int ad7768_set_sinc3_dec_rate(struct ad7768_state *st, + unsigned int dec_rate) { - unsigned int mode; + unsigned int max_dec_rate; + u8 dec_rate_reg[2]; + u16 regval; int ret; =20 - if (dec_rate =3D=3D AD7768_DEC_RATE_8 || dec_rate =3D=3D AD7768_DEC_RATE_= 16) - mode =3D AD7768_DIG_FIL_FIL(dec_rate); - else - mode =3D AD7768_DIG_FIL_DEC_RATE(dec_rate); + /* + * Maximum dec_rate is limited by the MCLK_DIV value and by the ODR. + * The edge case is for MCLK_DIV =3D 2, ODR =3D 50 SPS. + * max_dec_rate <=3D MCLK / (2 * 50) + */ + max_dec_rate =3D st->mclk_freq / 100; + dec_rate =3D clamp(dec_rate, 32, max_dec_rate); + /* + * Calculate the equivalent value to sinc3 decimation ratio + * to be written on the SINC3_DEC_RATE register: + * Value =3D (DEC_RATE / 32) -1 + */ + dec_rate =3D DIV_ROUND_UP(dec_rate, 32) - 1; =20 - ret =3D regmap_write(st->regmap, AD7768_REG_DIGITAL_FILTER, mode); - if (ret < 0) + /* + * The SINC3_DEC_RATE value is a 13-bit value split across two + * registers: MSB [12:8] and LSB [7:0]. Prepare the 13-bit value using + * FIELD_PREP and store it with the right endianness in dec_rate_reg. + */ + regval =3D FIELD_PREP(GENMASK(12, 0), dec_rate); + put_unaligned_be16(regval, dec_rate_reg); + ret =3D regmap_bulk_write(st->regmap, AD7768_REG_SINC3_DEC_RATE_MSB, + dec_rate_reg, 2); + if (ret) return ret; =20 - /* A sync-in pulse is required every time the filter dec rate changes */ + st->oversampling_ratio =3D (dec_rate + 1) * 32; + + return 0; +} + +static int ad7768_configure_dig_fil(struct iio_dev *dev, + enum ad7768_filter_type filter_type, + unsigned int dec_rate) +{ + struct ad7768_state *st =3D iio_priv(dev); + unsigned int dec_rate_idx, dig_filter_regval; + int ret; + + switch (filter_type) { + case AD7768_FILTER_SINC3: + dig_filter_regval =3D AD7768_DIG_FIL_FIL(AD7768_FILTER_REGVAL_SINC3); + break; + case AD7768_FILTER_SINC3_REJ60: + dig_filter_regval =3D AD7768_DIG_FIL_FIL(AD7768_FILTER_REGVAL_SINC3) | + AD7768_DIG_FIL_EN_60HZ_REJ; + break; + case AD7768_FILTER_WIDEBAND: + /* Skip decimations 8 and 16, not supported by the wideband filter */ + dec_rate_idx =3D find_closest(dec_rate, &ad7768_dec_rate_values[2], + ARRAY_SIZE(ad7768_dec_rate_values) - 2); + dig_filter_regval =3D AD7768_DIG_FIL_FIL(AD7768_FILTER_REGVAL_WIDEBAND) | + AD7768_DIG_FIL_DEC_RATE(dec_rate_idx); + /* Correct the index offset */ + dec_rate_idx +=3D 2; + break; + case AD7768_FILTER_SINC5: + dec_rate_idx =3D find_closest(dec_rate, ad7768_dec_rate_values, + ARRAY_SIZE(ad7768_dec_rate_values)); + + /* + * Decimations 8 (idx 0) and 16 (idx 1) are set in the + * FILTER[6:4] field. The other decimations are set in the + * DEC_RATE[2:0] field, and the idx needs to be offsetted by two. + */ + if (dec_rate_idx =3D=3D 0) + dig_filter_regval =3D AD7768_DIG_FIL_FIL(AD7768_FILTER_REGVAL_SINC5_X8); + else if (dec_rate_idx =3D=3D 1) + dig_filter_regval =3D AD7768_DIG_FIL_FIL(AD7768_FILTER_REGVAL_SINC5_X16= ); + else + dig_filter_regval =3D AD7768_DIG_FIL_FIL(AD7768_FILTER_REGVAL_SINC5) | + AD7768_DIG_FIL_DEC_RATE(dec_rate_idx - 2); + break; + } + + ret =3D regmap_write(st->regmap, AD7768_REG_DIGITAL_FILTER, dig_filter_re= gval); + if (ret) + return ret; + + st->filter_type =3D filter_type; + /* + * The decimation for SINC3 filters are configured in different + * registers. + */ + if (filter_type =3D=3D AD7768_FILTER_SINC3 || + filter_type =3D=3D AD7768_FILTER_SINC3_REJ60) { + ret =3D ad7768_set_sinc3_dec_rate(st, dec_rate); + if (ret) + return ret; + } else { + st->oversampling_ratio =3D ad7768_dec_rate_values[dec_rate_idx]; + } + + ad7768_fill_samp_freq_tbl(st); + + /* A sync-in pulse is required after every configuration change */ return ad7768_send_sync_pulse(st); } =20 @@ -551,45 +675,102 @@ static int ad7768_gpio_init(struct iio_dev *indio_de= v) static int ad7768_set_freq(struct ad7768_state *st, unsigned int freq) { - unsigned int diff_new, diff_old, pwr_mode, i, idx; + unsigned int diff_new, diff_old, i, idx; int res, ret; =20 + freq =3D clamp(freq, 50, 1024000); diff_old =3D U32_MAX; idx =3D 0; =20 - res =3D DIV_ROUND_CLOSEST(st->mclk_freq, freq); + if (freq =3D=3D 0) + return -EINVAL; + + res =3D DIV_ROUND_CLOSEST(st->mclk_freq, freq * st->oversampling_ratio); =20 /* Find the closest match for the desired sampling frequency */ - for (i =3D 0; i < ARRAY_SIZE(ad7768_clk_config); i++) { - diff_new =3D abs(res - ad7768_clk_config[i].clk_div); + for (i =3D 0; i < ARRAY_SIZE(ad7768_mclk_div_rates); i++) { + diff_new =3D abs(res - ad7768_mclk_div_rates[i]); if (diff_new < diff_old) { diff_old =3D diff_new; idx =3D i; } } =20 - /* - * Set both the mclk_div and pwrmode with a single write to the - * POWER_CLOCK register - */ - pwr_mode =3D AD7768_PWR_MCLK_DIV(ad7768_clk_config[idx].mclk_div) | - AD7768_PWR_PWRMODE(ad7768_clk_config[idx].pwrmode); - ret =3D regmap_write(st->regmap, AD7768_REG_POWER_CLOCK, pwr_mode); - if (ret < 0) + /* Set both the mclk_div and pwrmode */ + ret =3D ad7768_set_mclk_div(st, idx); + if (ret) return ret; =20 - ret =3D ad7768_set_dig_fil(st, ad7768_clk_config[idx].dec_rate); - if (ret < 0) + st->samp_freq =3D DIV_ROUND_CLOSEST(st->mclk_freq, + ad7768_mclk_div_rates[idx] * st->oversampling_ratio); + + /* A sync-in pulse is required after every configuration change */ + return ad7768_send_sync_pulse(st); +} + +static int ad7768_set_filter_type_attr(struct iio_dev *dev, + const struct iio_chan_spec *chan, + unsigned int filter) +{ + struct ad7768_state *st =3D iio_priv(dev); + int ret; + + ret =3D ad7768_configure_dig_fil(dev, filter, st->oversampling_ratio); + if (ret) return ret; =20 - st->dec_rate =3D ad7768_clk_config[idx].clk_div / - ad7768_mclk_div_rates[ad7768_clk_config[idx].mclk_div]; - st->samp_freq =3D DIV_ROUND_CLOSEST(st->mclk_freq, - ad7768_clk_config[idx].clk_div); + /* Update sampling frequency */ + return ad7768_set_freq(st, st->samp_freq); +} =20 - return 0; +static int ad7768_get_filter_type_attr(struct iio_dev *dev, + const struct iio_chan_spec *chan) +{ + struct ad7768_state *st =3D iio_priv(dev); + int ret; + unsigned int mode, mask; + + ret =3D regmap_read(st->regmap, AD7768_REG_DIGITAL_FILTER, &mode); + if (ret) + return ret; + + mask =3D AD7768_DIG_FIL_EN_60HZ_REJ | AD7768_DIG_FIL_FIL_MSK; + /* From the register value, get the corresponding filter type */ + return ad7768_filter_regval_to_type[FIELD_GET(mask, mode)]; } =20 +static const struct iio_enum ad7768_filter_type_iio_enum =3D { + .items =3D ad7768_filter_enum, + .num_items =3D ARRAY_SIZE(ad7768_filter_enum), + .set =3D ad7768_set_filter_type_attr, + .get =3D ad7768_get_filter_type_attr, +}; + +static const struct iio_chan_spec_ext_info ad7768_ext_info[] =3D { + IIO_ENUM("filter_type", IIO_SHARED_BY_ALL, &ad7768_filter_type_iio_enum), + IIO_ENUM_AVAILABLE("filter_type", IIO_SHARED_BY_ALL, &ad7768_filter_type_= iio_enum), + { } +}; + +static const struct iio_chan_spec ad7768_channels[] =3D { + { + .type =3D IIO_VOLTAGE, + .info_mask_separate =3D BIT(IIO_CHAN_INFO_RAW), + .info_mask_shared_by_type =3D BIT(IIO_CHAN_INFO_SCALE) | + BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), + .info_mask_shared_by_type_available =3D BIT(IIO_CHAN_INFO_OVERSAMPLING_R= ATIO), + .info_mask_shared_by_all =3D BIT(IIO_CHAN_INFO_SAMP_FREQ), + .info_mask_shared_by_all_available =3D BIT(IIO_CHAN_INFO_SAMP_FREQ), + .ext_info =3D ad7768_ext_info, + .indexed =3D 1, + .channel =3D 0, + .scan_index =3D 0, + .has_ext_scan_type =3D 1, + .ext_scan_type =3D ad7768_scan_type, + .num_ext_scan_type =3D ARRAY_SIZE(ad7768_scan_type), + }, +}; + static int ad7768_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val, int *val2, long info) @@ -629,6 +810,11 @@ static int ad7768_read_raw(struct iio_dev *indio_dev, case IIO_CHAN_INFO_SAMP_FREQ: *val =3D st->samp_freq; =20 + return IIO_VAL_INT; + + case IIO_CHAN_INFO_OVERSAMPLING_RATIO: + *val =3D st->oversampling_ratio; + return IIO_VAL_INT; } =20 @@ -643,9 +829,13 @@ static int ad7768_read_avail(struct iio_dev *indio_dev, struct ad7768_state *st =3D iio_priv(indio_dev); =20 switch (info) { + case IIO_CHAN_INFO_OVERSAMPLING_RATIO: + *vals =3D (int *)ad7768_dec_rate_range[st->filter_type]; + *type =3D IIO_VAL_INT; + return IIO_AVAIL_RANGE; case IIO_CHAN_INFO_SAMP_FREQ: *vals =3D (int *)st->samp_freq_avail; - *length =3D ARRAY_SIZE(ad7768_clk_config); + *length =3D st->samp_freq_avail_len; *type =3D IIO_VAL_INT; return IIO_AVAIL_LIST; default: @@ -653,20 +843,44 @@ static int ad7768_read_avail(struct iio_dev *indio_de= v, } } =20 -static int ad7768_write_raw(struct iio_dev *indio_dev, - struct iio_chan_spec const *chan, - int val, int val2, long info) +static int __ad7768_write_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int val, int val2, long info) { struct ad7768_state *st =3D iio_priv(indio_dev); + int ret; =20 switch (info) { case IIO_CHAN_INFO_SAMP_FREQ: return ad7768_set_freq(st, val); + + case IIO_CHAN_INFO_OVERSAMPLING_RATIO: + ret =3D ad7768_configure_dig_fil(indio_dev, st->filter_type, val); + if (ret) + return ret; + + /* Update sampling frequency */ + return ad7768_set_freq(st, st->samp_freq); default: return -EINVAL; } } =20 +static int ad7768_write_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int val, int val2, long info) +{ + int ret; + + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; + + ret =3D __ad7768_write_raw(indio_dev, chan, val, val2, info); + iio_device_release_direct(indio_dev); + + return ret; +} + static int ad7768_read_label(struct iio_dev *indio_dev, const struct iio_chan_spec *chan, char *label) { @@ -680,7 +894,7 @@ static int ad7768_get_current_scan_type(const struct ii= o_dev *indio_dev, { struct ad7768_state *st =3D iio_priv(indio_dev); =20 - return st->dec_rate =3D=3D 8 ? AD7768_SCAN_TYPE_HIGH_SPEED : + return st->oversampling_ratio =3D=3D 8 ? AD7768_SCAN_TYPE_HIGH_SPEED : AD7768_SCAN_TYPE_NORMAL; } =20 @@ -811,6 +1025,14 @@ static int ad7768_setup(struct iio_dev *indio_dev) return ret; } =20 + /* + * Set Default Digital Filter configuration: + * SINC5 filter with x32 Decimation rate + */ + ret =3D ad7768_configure_dig_fil(indio_dev, AD7768_FILTER_SINC5, 32); + if (ret) + return ret; + /* Set the default sampling frequency to 32000 kSPS */ return ad7768_set_freq(st, 32000); } @@ -1145,7 +1367,6 @@ static int ad7768_probe(struct spi_device *spi) return PTR_ERR(st->mclk); =20 st->mclk_freq =3D clk_get_rate(st->mclk); - ad7768_fill_samp_freq_tbl(st); =20 indio_dev->channels =3D ad7768_channels; indio_dev->num_channels =3D ARRAY_SIZE(ad7768_channels); --=20 2.34.1 From nobody Tue Dec 16 07:32:59 2025 Received: from mx0a-00128a01.pphosted.com (mx0a-00128a01.pphosted.com [148.163.135.77]) (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 2C200284B26; Thu, 8 May 2025 17:06:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.135.77 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746723974; cv=none; b=jO0G8yboPypzYTRsCzZr4pwU0pJ97OljcR+k1Zc2iOmZjTO8FmMjfumGyHyD9z0f60QgDuBE3jnfhlQlsbdxrYg6XIwnBvBWUn0mOFK55wvUsnFneM7aRe5q4Oi7hdnxrV+FwLRlcCJ7FA/xhZhquPSqIbCxHRUzO3rZjTZ8Ixk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746723974; c=relaxed/simple; bh=5oB5XuQUAHY+iWIu7xO2YXp0L1tqVZjkQtTZeLmmlko=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=SmPIkFLvBQBJVmjtdt2JwtlrQxNCTIoeszWn6rSrp8r2lb4049zRj+4jLEnE1gYPFDHWGqSGI6wnfDSBGfTO3lk1EcjRNrwPKCNAosh6IDrVWzQdN57beK1t3ojQFTjblrDYnCfgqbMs3NUbv4ckQw2kUmvzFfY14PrQpCmcTIA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=analog.com; spf=pass smtp.mailfrom=analog.com; dkim=pass (2048-bit key) header.d=analog.com header.i=@analog.com header.b=mHpPycDp; arc=none smtp.client-ip=148.163.135.77 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=analog.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=analog.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=analog.com header.i=@analog.com header.b="mHpPycDp" Received: from pps.filterd (m0167088.ppops.net [127.0.0.1]) by mx0a-00128a01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 548DMfTV013536; Thu, 8 May 2025 13:05:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=analog.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=DKIM; bh=Vr42C 2tcFtKYH/kR/TkyurniNImfA3S11wrHsfaGJBo=; b=mHpPycDp3WCq0j73JnV5V bDf1ZvaBYfSJDo29Q/EDaB2dx5e9uONiYE7CfnXsMpGHq/KFoLypErBo4lFRd1V0 nIHsBTz6RFTbajndr5oUrDzxnObBeBcHLbx6C7TkNFUh6L37QgnZKj135fee1niQ 07rIlvA0uEOUYo7f+2PR4loUxHoc+TVjQzkr80iyQS/n3cmr9Vm6YIROS8Kg2W4L 7EeMk94sZ6q+dEosC4UzWDFukOm3uLus3wsUbFg5m+qmZIFJDKGKkjR6TCj36xpW jK9aUBGgQFp21vrR8Jc2SrB3Z0ACvh+Ke0rv7YDoo65ysggtewc0oyRCrc11gJ/+ w== Received: from nwd2mta3.analog.com ([137.71.173.56]) by mx0a-00128a01.pphosted.com (PPS) with ESMTPS id 46gpct32qc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 May 2025 13:05:57 -0400 (EDT) Received: from ASHBMBX8.ad.analog.com (ASHBMBX8.ad.analog.com [10.64.17.5]) by nwd2mta3.analog.com (8.14.7/8.14.7) with ESMTP id 548H5ujR052999 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 8 May 2025 13:05:56 -0400 Received: from ASHBMBX8.ad.analog.com (10.64.17.5) by ASHBMBX8.ad.analog.com (10.64.17.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.14; Thu, 8 May 2025 13:05:55 -0400 Received: from zeus.spd.analog.com (10.66.68.11) by ashbmbx8.ad.analog.com (10.64.17.5) with Microsoft SMTP Server id 15.2.986.14 via Frontend Transport; Thu, 8 May 2025 13:05:55 -0400 Received: from JSANTO12-L01.ad.analog.com ([10.65.60.206]) by zeus.spd.analog.com (8.15.1/8.15.1) with ESMTP id 548H5drA015955; Thu, 8 May 2025 13:05:42 -0400 From: Jonathan Santos To: , , , CC: Jonathan Santos , , , , , , , , , , , , , , , Subject: [PATCH v7 12/12] iio: adc: ad7768-1: add low pass -3dB cutoff attribute Date: Thu, 8 May 2025 14:05:39 -0300 Message-ID: <4a8b85097213311851a710df7c036c124c7862ed.1746662899.git.Jonathan.Santos@analog.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ADIRuleOP-NewSCL: Rule Triggered X-Authority-Analysis: v=2.4 cv=J/eq7BnS c=1 sm=1 tr=0 ts=681ce475 cx=c_pps a=PpDZqlmH/M8setHirZLBMw==:117 a=PpDZqlmH/M8setHirZLBMw==:17 a=dt9VzEwgFbYA:10 a=gAnH3GRIAAAA:8 a=IpJZQVW2AAAA:8 a=ZkoTrUv0hqWFqrPu6skA:9 a=IawgGOuG5U0WyFbmm1f5:22 X-Proofpoint-GUID: lCYsiY6ywWlXGcoOtBfEO-AjC8Mk7FP8 X-Proofpoint-ORIG-GUID: lCYsiY6ywWlXGcoOtBfEO-AjC8Mk7FP8 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUwNTA4MDE0OSBTYWx0ZWRfX0QsmtxVLUXOQ wV1O9049CiB+oZqL86wZUfnYjSeyHmSKEWsq0cUqtIdX6guPNwKXbRmXDBOPLOelLSrF5wdty0S 97wVtvrhC0tU2fmCs+KqY9+67oQTCiLVwP2UdThK8hQ+TWPdaMPtlAiHDSVqOKMh2J87nPNyVtG ehbIfFHNRbVBSpGPGKuifaZr1ikV66F+oeXYdDurOROpeERv0qzOH/x2G2GbIHSBIio/C0Q2zWV ukWurbS9DL+YKKV9t4gY3NhdCst/NkblMgKhVsoT2b9WsuG7hVntkIodwMfGGerP53n7cPJ96B1 PI7sN4oBgW+V3M2XD18GtEOaKgI1y1A1p1llDegaKWJ0zLvQNriFrgZFyKryqkuDBHrIJrXqSzy pp/iR0FFeXCzYM6mxO0xbVRa82jR4P6Aul4w1g1+xBgLqvGR+sF7BaXbJ0E5MCRDeEiaq9+A X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1099,Hydra:6.0.736,FMLib:17.12.80.40 definitions=2025-05-08_05,2025-05-08_02,2025-02-21_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 impostorscore=0 adultscore=0 lowpriorityscore=0 mlxlogscore=999 priorityscore=1501 bulkscore=0 phishscore=0 malwarescore=0 spamscore=0 mlxscore=0 clxscore=1015 classifier=spam authscore=0 authtc=n/a authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.19.0-2504070000 definitions=main-2505080149 Content-Type: text/plain; charset="utf-8" Ad7768-1 has a different -3db frequency multiplier depending on the filter type configured. The cutoff frequency also varies according to the current ODR. Add a readonly low pass -3dB frequency cutoff attribute to clarify to the user which bandwidth is being allowed depending on the filter configurations. Reviewed-by: Marcelo Schmitt Reviewed-by: David Lechner Signed-off-by: Jonathan Santos --- v7 Changes: * None v6 Changes: * None v5 Changes: * None v4 Changes: * None v3 Changes: * None v2 Changes: * New patch in v2. --- drivers/iio/adc/ad7768-1.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/drivers/iio/adc/ad7768-1.c b/drivers/iio/adc/ad7768-1.c index 28998cb02761..335612bce3bd 100644 --- a/drivers/iio/adc/ad7768-1.c +++ b/drivers/iio/adc/ad7768-1.c @@ -152,6 +152,17 @@ enum ad7768_scan_type { AD7768_SCAN_TYPE_HIGH_SPEED, }; =20 +/* + * -3dB cutoff frequency multipliers (relative to ODR) for + * each filter type. Values are multiplied by 1000. + */ +static const int ad7768_filter_3db_odr_multiplier[] =3D { + [AD7768_FILTER_SINC5] =3D 204, + [AD7768_FILTER_SINC3] =3D 262, + [AD7768_FILTER_SINC3_REJ60] =3D 262, + [AD7768_FILTER_WIDEBAND] =3D 433, +}; + static const int ad7768_mclk_div_rates[] =3D { 16, 8, 4, 2, }; @@ -757,7 +768,8 @@ static const struct iio_chan_spec ad7768_channels[] =3D= { .type =3D IIO_VOLTAGE, .info_mask_separate =3D BIT(IIO_CHAN_INFO_RAW), .info_mask_shared_by_type =3D BIT(IIO_CHAN_INFO_SCALE) | - BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), + BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO) | + BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY), .info_mask_shared_by_type_available =3D BIT(IIO_CHAN_INFO_OVERSAMPLING_R= ATIO), .info_mask_shared_by_all =3D BIT(IIO_CHAN_INFO_SAMP_FREQ), .info_mask_shared_by_all_available =3D BIT(IIO_CHAN_INFO_SAMP_FREQ), @@ -777,7 +789,7 @@ static int ad7768_read_raw(struct iio_dev *indio_dev, { struct ad7768_state *st =3D iio_priv(indio_dev); const struct iio_scan_type *scan_type; - int scale_uv, ret; + int scale_uv, ret, temp; =20 scan_type =3D iio_get_current_scan_type(indio_dev, chan); if (IS_ERR(scan_type)) @@ -815,6 +827,12 @@ static int ad7768_read_raw(struct iio_dev *indio_dev, case IIO_CHAN_INFO_OVERSAMPLING_RATIO: *val =3D st->oversampling_ratio; =20 + return IIO_VAL_INT; + + case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY: + temp =3D st->samp_freq * ad7768_filter_3db_odr_multiplier[st->filter_typ= e]; + *val =3D DIV_ROUND_CLOSEST(temp, 1000); + return IIO_VAL_INT; } =20 --=20 2.34.1