From nobody Sat Feb 7 11:31:22 2026 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 A2A891E9906; Wed, 14 Jan 2026 12:47:27 +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=1768394849; cv=none; b=K5SYG8QGIRaVz1XMKYE/rnDzqHR2vcJ/i7HJBBLYQkQEN5S676nj0aByirqJk6NV4H0qQ7fx+XJwI+4hOjk4+miwHwAeLL9joeR10jo1Vly8LYxeyIg/VTGoP7aO1cLcqg4hvLTeRo3NSPEKDezXqd3PnidLiFTDCuW4Yak9I0c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768394849; c=relaxed/simple; bh=/aHVDIXnr9itAbftGWN9dNkwxevji0IAr7PgxJgrugw=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=PEIwI67rZJ+0cE4FwZxkUu0o8mAjDUh+WXPPBxy2mQ+u618L0opa05ii/3dmB5niGl+vfuC3p1AdCxPsyxtqV4ygpsCwN3MT39AOIvBySPIRoqcZamq/hjCU2726LwYEbWCx7Kwm7IGOkmJ+RTpRA3zJ5pipLEpfwlsfg5lGkqQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine 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=o4ymhQ1h; arc=none smtp.client-ip=148.163.135.77 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine 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="o4ymhQ1h" Received: from pps.filterd (m0375855.ppops.net [127.0.0.1]) by mx0b-00128a01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 60EC4i653765687; Wed, 14 Jan 2026 07:47:10 -0500 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=wHArj f0L12rAIUZsT8hem0qoTjAAzWIlJC2MoZKot8o=; b=o4ymhQ1hvKKEwZqsCsz9i wTJX79bgTJXotUCpfif5m3sfoJNZDQA6ezgAbqStqfNvMlUkzFqt+HykeD3lV7q0 2JTwiujXhi7I93RXA/J8V8JPM0U6wi5cSrS86IOipqQtMTVKGY4uM+6boSGoQwPA o+aFcP9WMTYKLfhG88laGZLHsF5DLQQqNKNzYbszrCbgTRB+tKGX15LZVv3kRhK4 Hw329FzkzZbAvle2DhA+i6pNn2807nDBib8jaYJ9oXLt1UZ23uPJvP9KtVDWMPTA y8QYwxm0Uhtj029rY83EGRwTxeDPPMoW+R0t4qRzzKw9L9prPiF1iKkTCIUJxt/b A== Received: from nwd2mta4.analog.com ([137.71.173.58]) by mx0b-00128a01.pphosted.com (PPS) with ESMTPS id 4bpau08gnx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 14 Jan 2026 07:47:09 -0500 (EST) 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 60ECl8lv061457 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 14 Jan 2026 07:47:08 -0500 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.1748.37; Wed, 14 Jan 2026 07:47:08 -0500 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.1748.37; Wed, 14 Jan 2026 07:47:08 -0500 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.1748.37 via Frontend Transport; Wed, 14 Jan 2026 07:47:08 -0500 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 60ECkqCu001731; Wed, 14 Jan 2026 07:46:54 -0500 From: Jonathan Santos To: , , CC: Jonathan Santos , , , , , , , , , , , Krzysztof Kozlowski Subject: [PATCH v6 1/5] dt-bindings: iio: adc: ad7768-1: add new supported parts Date: Wed, 14 Jan 2026 06:26:39 -0300 Message-ID: <3eefef5a7f41d15513101b00db65b1f769cdcc3c.1768350772.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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ADIRuleOP-NewSCL: Rule Triggered X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwMTE0MDEwNiBTYWx0ZWRfXwrrWnO8wNCFU cVo732ewyhg8lVz6UwaCU5COMYglc30+1nFsfU4md2p3iPAOTGiYQiLdT9kQXSpf0JyRRey5vcq btvyZnaH6/VLe6Bkj/GXcCAXE2q5Eh4U8Ddg/KvF3e2D2988jFcbsgHHJCh2ASkEnMBOUd4IF5A nkoIwUDyt36OFSzhCgplWfXtKut2bgwAwaaPEMN3Gp6+cwh6hLOndm4piQccOH+Wbs0XciNlFHl 5eV728yCJArJyc2YX0TqNptoetsk7PrTb8w+CmErKHs1LKS71YhKmVfne+CzytwkWzMFp37T8Ch hmTyR6Tc8VTYtdbvHjuesFkFdKIq5ARYkQ8UAEe/L99LNr7PQBaAlD39psLBIjGuEjyEgN8jOec je1RcFMja8kPHAOUfQLACcOUbuYKkyDSF3TsFC/8z5l+t4pAaGm61kZNbecLk9S/BVUIXLqq4d6 CrY2bQs7i8o9voRw+Vg== X-Authority-Analysis: v=2.4 cv=YcWwJgRf c=1 sm=1 tr=0 ts=6967904d cx=c_pps a=3WNzaoukacrqR9RwcOSAdA==:117 a=3WNzaoukacrqR9RwcOSAdA==:17 a=IkcTkHD0fZMA:10 a=vUbySO9Y5rIA:10 a=VkNPw1HP01LnGYTKEx00:22 a=VwQbUJbxAAAA:8 a=gAnH3GRIAAAA:8 a=gEfo2CItAAAA:8 a=EUspDBNiAAAA:8 a=W-COrTu4jwGsOlXsrW0A:9 a=3ZKOabzyN94A:10 a=QEXdDO2ut3YA:10 a=sptkURWiP4Gy88Gu7hUp:22 X-Proofpoint-ORIG-GUID: g0gd2atMvcpLIHiND-ER7wpjxwCvI5Hk X-Proofpoint-GUID: g0gd2atMvcpLIHiND-ER7wpjxwCvI5Hk X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1121,Hydra:6.1.9,FMLib:17.12.100.49 definitions=2026-01-14_04,2026-01-09_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 malwarescore=0 lowpriorityscore=0 adultscore=0 clxscore=1015 priorityscore=1501 phishscore=0 bulkscore=0 spamscore=0 suspectscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2512120000 definitions=main-2601140106 Add compatibles for supported parts in the ad7768-1 family: ADAQ7767-1, ADAQ7768-1 and ADAQ7769-1 Add property and checks for AFF gain, supported by ADAQ7767-1 and ADAQ7769-1, and for PGA gain, supported by ADAQ7768-1 and ADAQ7769-1: adi,aaf-gain-bp pga-gpios Reviewed-by: Krzysztof Kozlowski Signed-off-by: Jonathan Santos --- v6 Changes: * None. v5 Changes: * None. v4 Changes: * Inspired by [1], Included pga-gpios property for parts that support PGA g= ain. Before we were using the internal gpio controller to manage the PGA pins, but still exposing the controller for external use (causing possible conf= licts). Using pga-gpios we can let the consumer define the pins to be used for PG= A, even from the internal gpio controller (but not limited by that). The pro= blem with that approach is the deadlock described in the last patch from this = set. v3 Changes: * Renamed adi,gain-milli to adi,aaf-gain-bp. Now it represents basis points (one hundredth of a percent) as suggested by Krzysztof. Description was adjusted. Note: permille (1/1000) was also suggested as unit for this property. v2 Changes: * adi,aaf-gain property renamed to adi,gain-milli. Description was=20 simplified. * default value add to adi,gain-milli. [1]: https://lore.kernel.org/linux-iio/318c31e023ebe30cc99b8743e87e869bf5e1= f12b.1760984107.git.marcelo.schmitt@analog.com/ --- .../bindings/iio/adc/adi,ad7768-1.yaml | 64 +++++++++++++++++-- 1 file changed, 60 insertions(+), 4 deletions(-) diff --git a/Documentation/devicetree/bindings/iio/adc/adi,ad7768-1.yaml b/= Documentation/devicetree/bindings/iio/adc/adi,ad7768-1.yaml index c06d0fc791d3..dfa2d7fa9fb3 100644 --- a/Documentation/devicetree/bindings/iio/adc/adi,ad7768-1.yaml +++ b/Documentation/devicetree/bindings/iio/adc/adi,ad7768-1.yaml @@ -4,18 +4,26 @@ $id: http://devicetree.org/schemas/iio/adc/adi,ad7768-1.yaml# $schema: http://devicetree.org/meta-schemas/core.yaml# =20 -title: Analog Devices AD7768-1 ADC device driver +title: Analog Devices AD7768-1 ADC family =20 maintainers: - Michael Hennerich =20 description: | - Datasheet at: - https://www.analog.com/media/en/technical-documentation/data-sheets/ad= 7768-1.pdf + Analog Devices AD7768-1 24-Bit Single Channel Low Power sigma-delta ADC = family + + https://www.analog.com/media/en/technical-documentation/data-sheets/ad77= 68-1.pdf + https://www.analog.com/media/en/technical-documentation/data-sheets/adaq= 7767-1.pdf + https://www.analog.com/media/en/technical-documentation/data-sheets/adaq= 7768-1.pdf + https://www.analog.com/media/en/technical-documentation/data-sheets/adaq= 7769-1.pdf =20 properties: compatible: - const: adi,ad7768-1 + enum: + - adi,ad7768-1 + - adi,adaq7767-1 + - adi,adaq7768-1 + - adi,adaq7769-1 =20 reg: maxItems: 1 @@ -58,6 +66,25 @@ properties: description: ADC reference voltage supply =20 + adi,aaf-gain-bp: + description: | + Specifies the gain applied by the Analog Anti-Aliasing Filter (AAF) + to the ADC input in basis points (one hundredth of a percent). + The hardware gain is determined by which input pin(s) the signal go= es + through into the AAF. The possible connections are: + * For the ADAQ7767-1: Input connected to IN1=C2=B1, IN2=C2=B1 or IN= 3=C2=B1. + * For the ADAQ7769-1: OUT_PGA pin connected to IN1_AAF+, IN2_AAF+, + or IN3_AAF+. + enum: [1430, 3640, 10000] + default: 10000 + + pga-gpios: + description: + GAIN 0, GAIN1 and GAIN2 pins for gain selection. For devices that ha= ve + PGA configuration input pins, pga-gpios must be defined. + minItems: 3 + maxItems: 3 + adi,sync-in-gpios: maxItems: 1 description: @@ -147,6 +174,35 @@ patternProperties: allOf: - $ref: /schemas/spi/spi-peripheral-props.yaml# =20 + # AAF Gain property only applies to ADAQ7767-1 and ADAQ7769-1 devices + - if: + properties: + compatible: + contains: + enum: + - adi,adaq7767-1 + - adi,adaq7769-1 + then: + required: + - adi,aaf-gain-bp + else: + properties: + adi,aaf-gain-bp: false + + - if: + properties: + compatible: + contains: + enum: + - adi,adaq7768-1 + - adi,adaq7769-1 + then: + required: + - pga-gpios + else: + properties: + pga-gpios: false + unevaluatedProperties: false =20 examples: --=20 2.34.1 From nobody Sat Feb 7 11:31:22 2026 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 427602FBDED; Wed, 14 Jan 2026 12:47:36 +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=1768394857; cv=none; b=cIlf+JuY6QMN5FmhjMvYzRKiXhiC//r0c2sHleVIn6jaYtKXMuYkvfnh5yxFDzVuB9tK7RBvrGVqKiG0/uRCcjZ1J+KgcGo8DItil+n0QBuccssHgL0h9Ye0LfBlyuSpGTupyqKcizYr+8oO5Vx0tqBp3JZnMUnRh8C9PA+0Jqs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768394857; c=relaxed/simple; bh=N/11nlZzOdockDQaFZW5Rdr4vtB/arlHCIpSQ+MWE78=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=IsWxs+NVFBJEEGQw+H29yhp0NTOPyrzw9oPiddmw6eyK3HBMxl7zDoUn+AngLeUux1OV4R8SreWEiPBk29332UcUYcSBPaM0Djd8Kkim1hGSXXBhKsxFRtJ0nSRl2ujwkjHY1VCO4T+NAzHVRhwBBHHmhnIuH14h3P1ebQ0H6Bc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine 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=XaeCnoDQ; arc=none smtp.client-ip=148.163.135.77 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine 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="XaeCnoDQ" Received: from pps.filterd (m0375855.ppops.net [127.0.0.1]) by mx0b-00128a01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 60EC4qjR3765808; Wed, 14 Jan 2026 07:47:20 -0500 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=DXV1a QaDqn5yaYi4yvFFKZs+mfBl6Wh0rlvHoChQFH8=; b=XaeCnoDQXDMED7nBnRP6/ rrqpbGtKYFAcv36Z9BfpYA4GIYJfZhbExpTliu4vOfHhgXgdsLdkmGDuBTxoymDX AYMW7H+Wd7EHPzHmIb0B4C1INPQjaMfFaTyJfK0zQoUmxWSrdiXNrq3xKWyRc9zS BZrPrBL/2ZyKF6MlSUvZU9mYl0qO8rGLCh35MFI1X5czqhKNLGC6eB6d8A9zrAIm qYwm1vE3rgdbHWiXj88qzBL4uyjSOoWU0OqIsy1Q+byzR0QqRvTLkdhTGUvphdXV SMjLFRSD6bf8dEuuoPfTNLKtkN4ynG1u36XGrN8YK6ZroHjR2DewCPoAzPUFE1FH w== Received: from nwd2mta4.analog.com ([137.71.173.58]) by mx0b-00128a01.pphosted.com (PPS) with ESMTPS id 4bpau08gr2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 14 Jan 2026 07:47:19 -0500 (EST) 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 60EClIFN061478 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 14 Jan 2026 07:47:18 -0500 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.1748.37; Wed, 14 Jan 2026 07:47:18 -0500 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.1748.37 via Frontend Transport; Wed, 14 Jan 2026 07:47:18 -0500 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 60ECl4E0001737; Wed, 14 Jan 2026 07:47:07 -0500 From: Jonathan Santos To: , , CC: Jonathan Santos , , , , , , , , , , Subject: [PATCH v6 2/5] iio: adc: ad7768-1: introduce chip info for future multidevice support Date: Wed, 14 Jan 2026 06:26:52 -0300 Message-ID: <1db015b432fc7473c55f888875af30cc6b241405.1768350772.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: AW1haW4tMjYwMTE0MDEwNiBTYWx0ZWRfX5qzrNf5+n26x WhzvJ0o8PECePyRRjyxIevzkN58PZpwvotKDFlw7+WzRtiuw1AdcPs2JaO7sYHJnNcq0Ez/zEue 8TaCIR3gFYHlPvBm6qiMXKxF64UzrYWRclEYUpEbYYj3mRCfrbz5KDcpkbRPL1Z8q0kJTug6smT pnHeCWW2ndC66zd3FXxY9lC9iog7oBOjCrEIw4FcVkd6KsbuVfRNLGRW1IEwbcxAcMCO5TRtNxX XP15nte9/TLfHaRZukEae4vcdacL+uSNpBdZ/gOBHqasprp3GZtSnRc0a8siVPpP90ZgnvnBiXq ClVC9xBZ+++epm2QAZM6DTwQUH86GYl9o3jeS9HEvYe2nppaDhEhkCl82ctkcECuwFWwNu8eBRS LWBRZiUOsVXxyxRGfb6sXO5KgL/qGCBKJoQzzSd/TtTDFR75l1w/LS67HXT1KcVcsRifp2OQ94x W+SDsD4RlPoJr3VjZlA== X-Authority-Analysis: v=2.4 cv=YcWwJgRf c=1 sm=1 tr=0 ts=69679057 cx=c_pps a=3WNzaoukacrqR9RwcOSAdA==:117 a=3WNzaoukacrqR9RwcOSAdA==:17 a=vUbySO9Y5rIA:10 a=VkNPw1HP01LnGYTKEx00:22 a=gAnH3GRIAAAA:8 a=52dTr-yYBLopz0kQKhgA:9 X-Proofpoint-ORIG-GUID: jrSIeQ56iXocgoz_faa7I8-x2dd1RgRq X-Proofpoint-GUID: jrSIeQ56iXocgoz_faa7I8-x2dd1RgRq X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1121,Hydra:6.1.9,FMLib:17.12.100.49 definitions=2026-01-14_04,2026-01-09_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 malwarescore=0 lowpriorityscore=0 adultscore=0 clxscore=1015 priorityscore=1501 phishscore=0 bulkscore=0 spamscore=0 suspectscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2512120000 definitions=main-2601140106 Content-Type: text/plain; charset="utf-8" Add Chip info struct in SPI device to store channel information for each supported part. Signed-off-by: Jonathan Santos --- v6 Changes: * None. v5 Changes: * None. v4 Changes: * Dropped chip info check and moved the st->chip assignment early in the probe function. * Addressed indentation inconsistencies in AD7768_CHAN macro. v3 Changes: * ad7768_channel_masks removed along with available_masks element in ad7768_chip_info struct. It does not add anything for single channels, so not needed, at least for now. * fixed inconsistency in spaces before \ in AD7768_CHAN macro. v2 Changes: * removed AD7768_CHAN_INFO_NONE macro. * reordered fields in ad7768_chip_info struct. * removed trailing comma. --- drivers/iio/adc/ad7768-1.c | 64 ++++++++++++++++++++++++-------------- 1 file changed, 41 insertions(+), 23 deletions(-) diff --git a/drivers/iio/adc/ad7768-1.c b/drivers/iio/adc/ad7768-1.c index d96802b7847a..89b0ca8f584c 100644 --- a/drivers/iio/adc/ad7768-1.c +++ b/drivers/iio/adc/ad7768-1.c @@ -213,6 +213,12 @@ static const struct iio_scan_type ad7768_scan_type[] = =3D { }, }; =20 +struct ad7768_chip_info { + const char *name; + const struct iio_chan_spec *channel_spec; + int num_channels; +}; + struct ad7768_state { struct spi_device *spi; struct regmap *regmap; @@ -234,6 +240,7 @@ struct ad7768_state { struct gpio_desc *gpio_reset; const char *labels[AD7768_MAX_CHANNELS]; struct gpio_chip gpiochip; + const struct ad7768_chip_info *chip; bool en_spi_sync; /* * DMA (thus cache coherency maintenance) may require the @@ -748,24 +755,28 @@ static const struct iio_chan_spec_ext_info ad7768_ext= _info[] =3D { { } }; =20 +#define AD7768_CHAN(_idx, _msk_avail) \ +{ \ + .type =3D IIO_VOLTAGE, \ + .info_mask_separate_available =3D _msk_avail, \ + .info_mask_separate =3D BIT(IIO_CHAN_INFO_RAW), \ + .info_mask_shared_by_type =3D BIT(IIO_CHAN_INFO_SCALE) | \ + BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY) | \ + BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), \ + .info_mask_shared_by_type_available =3D BIT(IIO_CHAN_INFO_OVERSAMPLING_RA= TIO), \ + .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 _idx, \ + .scan_index =3D _idx, \ + .has_ext_scan_type =3D 1, \ + .ext_scan_type =3D ad7768_scan_type, \ + .num_ext_scan_type =3D ARRAY_SIZE(ad7768_scan_type), \ +} + 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_LOW_PASS_FILTER_3DB_FREQUENCY) | - 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), - }, + AD7768_CHAN(0, 0), }; =20 static int ad7768_read_raw(struct iio_dev *indio_dev, @@ -1321,6 +1332,12 @@ static int ad7768_register_regulators(struct device = *dev, struct ad7768_state *s return 0; } =20 +static const struct ad7768_chip_info ad7768_chip_info =3D { + .name =3D "ad7768-1", + .channel_spec =3D ad7768_channels, + .num_channels =3D ARRAY_SIZE(ad7768_channels), +}; + static int ad7768_probe(struct spi_device *spi) { struct ad7768_state *st; @@ -1347,6 +1364,7 @@ static int ad7768_probe(struct spi_device *spi) return ret; } =20 + st->chip =3D spi_get_device_match_data(spi); st->spi =3D spi; =20 st->regmap =3D devm_regmap_init_spi(spi, &ad7768_regmap_config); @@ -1371,9 +1389,9 @@ static int ad7768_probe(struct spi_device *spi) =20 st->mclk_freq =3D clk_get_rate(st->mclk); =20 - indio_dev->channels =3D ad7768_channels; - indio_dev->num_channels =3D ARRAY_SIZE(ad7768_channels); - indio_dev->name =3D spi_get_device_id(spi)->name; + indio_dev->channels =3D st->chip->channel_spec; + indio_dev->num_channels =3D st->chip->num_channels; + indio_dev->name =3D st->chip->name; indio_dev->info =3D &ad7768_info; indio_dev->modes =3D INDIO_DIRECT_MODE; =20 @@ -1390,7 +1408,7 @@ static int ad7768_probe(struct spi_device *spi) =20 init_completion(&st->completion); =20 - ret =3D ad7768_set_channel_label(indio_dev, ARRAY_SIZE(ad7768_channels)); + ret =3D ad7768_set_channel_label(indio_dev, st->chip->num_channels); if (ret) return ret; =20 @@ -1409,13 +1427,13 @@ static int ad7768_probe(struct spi_device *spi) } =20 static const struct spi_device_id ad7768_id_table[] =3D { - { "ad7768-1", 0 }, + { "ad7768-1", (kernel_ulong_t)&ad7768_chip_info }, { } }; MODULE_DEVICE_TABLE(spi, ad7768_id_table); =20 static const struct of_device_id ad7768_of_match[] =3D { - { .compatible =3D "adi,ad7768-1" }, + { .compatible =3D "adi,ad7768-1", .data =3D &ad7768_chip_info }, { } }; MODULE_DEVICE_TABLE(of, ad7768_of_match); --=20 2.34.1 From nobody Sat Feb 7 11:31:22 2026 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 5EDA7396D04; Wed, 14 Jan 2026 12:47:46 +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=1768394868; cv=none; b=HVq+hC4vy2sLTZTMT7HL0d/hPIT6TrsgYkeyMuRbfzAPjuuOa8kbMCVNIonAZOW/lhLS7WAVvWT3rLxQ/F2jF897SQc9C726hJHRQBgbQUCZa38r5Fx4FwntGCZvMXBfi0WmSIOxgCSr73RZUNpNYz0LRBzxdhL/X2LBUilSdBE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768394868; c=relaxed/simple; bh=H5o1lngnkgid4Mct3Ao0a0z5WstH3Z+sWEyVtXwo6Mg=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=jCL5sO/zsUVqTnclxx4GUa6WtYlKV4Lb2zuQRsjhc0amdWb3xmL0mwbW7glxt+TL+o8thu31X96CQ4VQRBmpWhoXGSjTbc4kwgkkj4FqXiLqZ4jvYVNZgAm1k7xPoTJpA0ZPNjasPxNsi/g/mdxN/tq26tPGMLkU9oF6fQ+11Ig= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine 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=g96PgUI6; arc=none smtp.client-ip=148.163.135.77 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine 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="g96PgUI6" Received: from pps.filterd (m0375855.ppops.net [127.0.0.1]) by mx0b-00128a01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 60EC4sF03765846; Wed, 14 Jan 2026 07:47:31 -0500 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=Xfhrp qJOi/7CdNnnDIaYpQSCvUDQAHJGt8dk+WvpmHU=; b=g96PgUI6vc9G5YclUifen OWOesu2bIjtPVd7iKE1GsNeFjzEB5J5kRs7JiCispC1WDHmbES048pgeudj8sIpE sDoOAslx1bJUl/C2a1iJVzhYG1JtAHmPvI5hFKcNqk1HBO/iTA9EJkI+14j0vw2i lrUaccAbSViq/wInvehqpSphzWF2QV7aohAnMWMInvUCdFQBxNEcHPUCV7+1IKv/ 1Ra0upmJ8cLXLfkHNEUWeWCLmX1XuC94ALuGM8TQimsifytRuCBvnwUBSjnMEiyP TZHjWYkkfFYMuc3PRvzLWfBS0o1qEZ1TEQVIXwG1IdAkNlbjFEHmVVrEgUBUcUMS A== Received: from nwd2mta4.analog.com ([137.71.173.58]) by mx0b-00128a01.pphosted.com (PPS) with ESMTPS id 4bpau08gse-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 14 Jan 2026 07:47:31 -0500 (EST) 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 60EClUvv061487 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 14 Jan 2026 07:47:30 -0500 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.1748.37; Wed, 14 Jan 2026 07:47:30 -0500 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.1748.37 via Frontend Transport; Wed, 14 Jan 2026 07:47:30 -0500 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 60EClEsu001741; Wed, 14 Jan 2026 07:47:17 -0500 From: Jonathan Santos To: , , CC: Jonathan Santos , , , , , , , , , , Subject: [PATCH v6 3/5] units: add conversion macros for percentage related units Date: Wed, 14 Jan 2026 06:27:03 -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: AW1haW4tMjYwMTE0MDEwNiBTYWx0ZWRfX+ZFvT/pUBQQy ph3CtbcKkSxw8cUW/brOjKjn5fhDlgAjOS/csLTcTKBKyTaXQSoR3FP2042vwFteWNoeY43jnui sC6EtLT+IbkwC3emW0HCtDbBey3JHhXXvQR5/cCuc0v32++wLMe2hNz8blnp4Cw207eVeFtWTUw nQuUAjN6VrFeP1+VU2bfSSyA3sokdJb7zvD743hnXKir7lFA00edYhdy/aP3vk98qMgW+OQXEpP JCwt1KuiS45tJPojefMcwJg6RzSBlIF7oM5Ymv9OZCxJfmI96QmunJVY2eR7no/TFRxA0ORGyOF Ed8SO2ZMhBPItf/6BS15w1+SKUEVQvPxAE8AFI0HmNHREfpD+ZnYKcpbnUmA3JTFCIeCr7L20v0 q015b3z+g/cQWt1ieEp5YMojZXgX8GwVX4CP9/JAycFwAX2NYIxm4sFNHg7aSAihvqTeFlUC8ZR WUZwcD6PN11tmF2omhw== X-Authority-Analysis: v=2.4 cv=YcWwJgRf c=1 sm=1 tr=0 ts=69679063 cx=c_pps a=3WNzaoukacrqR9RwcOSAdA==:117 a=3WNzaoukacrqR9RwcOSAdA==:17 a=vUbySO9Y5rIA:10 a=VkNPw1HP01LnGYTKEx00:22 a=gAnH3GRIAAAA:8 a=1YHlEUoW5VistbXv4qEA:9 X-Proofpoint-ORIG-GUID: cidquhaKtVSdI7q6pfrgHxmZMgPAze9H X-Proofpoint-GUID: cidquhaKtVSdI7q6pfrgHxmZMgPAze9H X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1121,Hydra:6.1.9,FMLib:17.12.100.49 definitions=2026-01-14_04,2026-01-09_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 malwarescore=0 lowpriorityscore=0 adultscore=0 clxscore=1015 priorityscore=1501 phishscore=0 bulkscore=0 spamscore=0 suspectscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2512120000 definitions=main-2601140106 Content-Type: text/plain; charset="utf-8" Add macros to convert between ratio and percentage related units, including percent (1/100), permille (1/1,000), permyriad (1/10,000, also equivalent to one Basis point) and per cent mille (1/100,000). Those are Used for precise fractional calculations in engineering, finance, and measurement applications. Signed-off-by: Jonathan Santos Reviewed-by: Andy Shevchenko --- v6 Changes: * Use Pattern PER* for all percentage-related macros. BASIS_POINTS is now PERMYRIAD. * Include macros for Per mille and per cent mille units. v5 Changes: * Included PERCENT macro along with BASIS_POINTS. * Adjusted commit description and comment in the code to add more context a= nd examples. v4 Changes: * New patch. --- include/linux/units.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/include/linux/units.h b/include/linux/units.h index 00e15de33eca..3471c5a38dcf 100644 --- a/include/linux/units.h +++ b/include/linux/units.h @@ -21,6 +21,25 @@ #define PICO 1000000000000ULL #define FEMTO 1000000000000000ULL =20 +/* + * Percentage and related scaling units + * + * These macros define scaling factors used to convert between ratio and + * percentage-based representations with different decimal resolutions. + * They are used for precise fractional calculations in engineering, finan= ce, + * and measurement applications. + * + * Examples: + * 1% =3D 0.01 =3D 1 / PERCENT + * 0.1% =3D 0.001 =3D 1 / PERMILLE + * 0.01% =3D 0.0001 =3D 1 / PERMYRIAD (1 basis point) + * 0.001% =3D 0.00001 =3D 1 / PERCENTMILLE + */ +#define PERCENT 100 +#define PERMILLE 1000 +#define PERMYRIAD 10000 +#define PERCENTMILLE 100000 + #define NANOHZ_PER_HZ 1000000000UL #define MICROHZ_PER_HZ 1000000UL #define MILLIHZ_PER_HZ 1000UL --=20 2.34.1 From nobody Sat Feb 7 11:31:22 2026 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 226391E9906; Wed, 14 Jan 2026 12:47:55 +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=1768394877; cv=none; b=Jxj+XLUYGxuW++zO2EacQMVLmoODriqqsJG1HjmX1TVZa6fTULATY7E8MrDznBzBj/deqkRPTabNEqAxsKqVp0rKzTNNwrx52+gPypesWrE5IDMvb9Vyq2SFJY660AYu2HMNmjOhG66mBsQAKWQoDXwn6S9mE2byvIhSZzRiZc0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768394877; c=relaxed/simple; bh=PfvJLNmlPJU8Oi+kzJjBTvnoeegXBesJSFfOJ8XOxfk=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=UNz1KCVmPebLmLehVejK7SSEmRm4upakt+Kwjn2q/yk6L+6fanzo5yHA2w7VSyOUrP4Vg9qgIg50zYCuZ3VfUs76MoW54z8PjyiMBEh1Ujai0r0JWhGFZzFj7gFlDw6vOW8EP6KzD9MIMc2Tp2dsZFiONPJ+phmI9Skr0n5zOSs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine 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=IYfbXMuq; arc=none smtp.client-ip=148.163.135.77 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine 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="IYfbXMuq" Received: from pps.filterd (m0375855.ppops.net [127.0.0.1]) by mx0b-00128a01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 60EC4rIY3765826; Wed, 14 Jan 2026 07:47:41 -0500 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=6D0bS Zm+OlF4YbzRJvG/SKJGuECiZnyrhnTGLIA6ibo=; b=IYfbXMuqrMF6wj1EMZwJc Ba1vyWUSvnaKbpUoSokrwWxb65NrQoX1yKLJ56h38m7GuxPk0fsYjIc8XOTcloS9 MPZbt+ZCiUG4Tz1aIIq1Rasp4k78IHV7TPak0mxHoJPbZIbYPoKk06uB8Dh0IozT j2riq8n9VUtoyIcbSLs7hptohcXv5q5wxFM1f+7E88h5CS1JrRwpQalaC4X3tpbM 3Pw/RiDYB34HdVPWIMvwnBdQdiFMtCkzsloknPkgXLO9G7Q3IxYOpeZveYMth0RC pOttYRtZGTDUi8NzvuenNi6zkg/EBNXG8xjCnjFsNiLKDC8qWVfwmNq/Byi+MttE Q== Received: from nwd2mta4.analog.com ([137.71.173.58]) by mx0b-00128a01.pphosted.com (PPS) with ESMTPS id 4bpau08gtu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 14 Jan 2026 07:47:41 -0500 (EST) 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 60EClew8061496 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 14 Jan 2026 07:47:40 -0500 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.1748.37; Wed, 14 Jan 2026 07:47:40 -0500 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.1748.37; Wed, 14 Jan 2026 07:47:40 -0500 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.1748.37 via Frontend Transport; Wed, 14 Jan 2026 07:47:40 -0500 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 60EClOnl001744; Wed, 14 Jan 2026 07:47:26 -0500 From: Jonathan Santos To: , , CC: Jonathan Santos , , , , , , , , , , Subject: [PATCH v6 4/5] iio: adc: ad7768-1: refactor ad7768_write_raw() Date: Wed, 14 Jan 2026 06:27:14 -0300 Message-ID: <496dc9c83900c7edc104d3bf3419b7fdf66c4199.1768350772.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: AW1haW4tMjYwMTE0MDEwNiBTYWx0ZWRfX67tDZAn2AxiM H994tlSCygB0cY+yWdHOs99sRXnCVWg2VDmNolNuT5zsDAIgn+ZIr0Xgke19qVPJNcxYmcZeeQt FfrPYeGYvWKs8d5LHRENrqbltFGyPvmFII2k8kWky/1xlJTOTutephQQpkDdN+6HfeCU46xVmb8 /kwHy+kYfRgd4Ibqq1EDKxaenJmuc6NAawkOG1EneatdRyz5JO3daGql8ilKKGkOAhm5/1EViIa 4SMbn2jwRtndBe6KKhA1503f9c/SeW2eanTi3Uy2Ld3yc0ZIZgtkFl25I/u9G4RHi1WTjY0ruFr A7FiVuRq446kRnRwm+Yfn8VOl1lL/6umf4LVGzap/1ZRS0XHGqqrD5bXX+Emm6uUf9ZHPjMOIwW oXBY4eILguI4rkItxPZXe3+CEh+GsMOwkCAb11sDElQbi4UgG/I6YOjXehl1G/igkT6Mu2FF8Bv Q5/EfUoh2qqFG5/d4DA== X-Authority-Analysis: v=2.4 cv=YcWwJgRf c=1 sm=1 tr=0 ts=6967906d cx=c_pps a=3WNzaoukacrqR9RwcOSAdA==:117 a=3WNzaoukacrqR9RwcOSAdA==:17 a=vUbySO9Y5rIA:10 a=VkNPw1HP01LnGYTKEx00:22 a=gAnH3GRIAAAA:8 a=ADg9w4Aar0HM7KgavYQA:9 X-Proofpoint-ORIG-GUID: X7n-wY0TLAFRrfyUuKxFTydb9a_z9wnn X-Proofpoint-GUID: X7n-wY0TLAFRrfyUuKxFTydb9a_z9wnn X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1121,Hydra:6.1.9,FMLib:17.12.100.49 definitions=2026-01-14_04,2026-01-09_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 malwarescore=0 lowpriorityscore=0 adultscore=0 clxscore=1015 priorityscore=1501 phishscore=0 bulkscore=0 spamscore=0 suspectscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2512120000 definitions=main-2601140106 Content-Type: text/plain; charset="utf-8" Squash __ad7768_write_raw() back to ad7768_write_raw() to allow the addition of new attributes without requiring a direct mode claim. Signed-off-by: Jonathan Santos --- v6 Changes: * None. v5 Changes: * new patch suggested by Jonathan Cameron to allow attributes without=20 the direct mode claim, necessary for fixing the deadlock issue reported in v4. --- drivers/iio/adc/ad7768-1.c | 50 ++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/drivers/iio/adc/ad7768-1.c b/drivers/iio/adc/ad7768-1.c index 89b0ca8f584c..bd4b2e090c5b 100644 --- a/drivers/iio/adc/ad7768-1.c +++ b/drivers/iio/adc/ad7768-1.c @@ -742,6 +742,19 @@ static int ad7768_get_filter_type_attr(struct iio_dev = *dev, return ad7768_filter_regval_to_type[FIELD_GET(mask, mode)]; } =20 +static int ad7768_update_dec_rate(struct iio_dev *dev, unsigned int dec_ra= te) +{ + struct ad7768_state *st =3D iio_priv(dev); + int ret; + + ret =3D ad7768_configure_dig_fil(dev, st->filter_type, dec_rate); + if (ret) + return ret; + + /* Update sampling frequency */ + return ad7768_set_freq(st, st->samp_freq); +} + static const struct iio_enum ad7768_filter_type_iio_enum =3D { .items =3D ad7768_filter_enum, .num_items =3D ARRAY_SIZE(ad7768_filter_enum), @@ -867,44 +880,33 @@ 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); + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; =20 + ret =3D ad7768_set_freq(st, val); + iio_device_release_direct(indio_dev); + return ret; case IIO_CHAN_INFO_OVERSAMPLING_RATIO: - ret =3D ad7768_configure_dig_fil(indio_dev, st->filter_type, val); - if (ret) - return ret; + if (!iio_device_claim_direct(indio_dev)) + return -EBUSY; =20 - /* Update sampling frequency */ - return ad7768_set_freq(st, st->samp_freq); + ret =3D ad7768_update_dec_rate(indio_dev, val); + iio_device_release_direct(indio_dev); + return ret; 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) { --=20 2.34.1 From nobody Sat Feb 7 11:31:22 2026 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 134AD397AB0; Wed, 14 Jan 2026 12:48:09 +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=1768394891; cv=none; b=Noev737cNrlqCBN9yQTNAoZUmHEfYSvkARhGNE2fasVbbnJTVErs05UbzYJKmiOVeMyngvKjntL5OUtJkX8y4tpfqBqEZweazkkBeW5F6IYgJez2z+Ou4afOPL/khFLJ7k3VrgtnjujKEcA+p8cFfzBH0hORD/zDKDIJzsKKxAQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768394891; c=relaxed/simple; bh=2WkxNpDn1vZbwmh9nJ7gZ7poSADRrQ2NKNtchf0sVW8=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Ss7/BY2u7qTXcAiMfgK0/W3o+5aVNHxnKQ2fXwiklY6h6bHyq0XrGmm2C4WUL8iNLS9FddWVU0D3FlU7YRmvtv1+ZNSDD+s6ERqo+Pz/AWEa9Pmas1WUcN7fU5UT3ZE0sPB3/e5Z6LifYK2d+jPFzeG+umLYLjQQWrUgDWpE6I4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine 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=U5iqCfhO; arc=none smtp.client-ip=148.163.135.77 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine 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="U5iqCfhO" Received: from pps.filterd (m0375855.ppops.net [127.0.0.1]) by mx0b-00128a01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 60EC4i6V3765687; Wed, 14 Jan 2026 07:47:54 -0500 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=bZmFk r8xxYxE/pWn/umV3IQU4FChqsl/TJL5v2dP19s=; b=U5iqCfhOXURNcteMp/7cs hiuVqCAy/mEYFaonYTN82hIHusT19bBL0UxgQBsuMJiSvxBa8ARx16NIQR7fFWeq 3++zap8SwAMXtPQI9wR3vvEaO/sLcWh+pqTRjiPF94sxuqiEENoj2CuZoaLXs8sv ISqPmbZ+CAL4fFVS8QDkUJq/a88tplxYzaJ/YGWTBR2uveIT+lUv29NXtPPWZvyb 9p5wN6s/TPt/Ilng8jQkjds86MQp1D/WPhlbiYiCujyPQZkeMt4ZZdw/eIe+8RT2 mX7JkVBEwvl1Fp3Jp7iyenfHoE3d5HWMGVhlL5aBFKcUR2v893uwcmaWWo//dHEL g== Received: from nwd2mta4.analog.com ([137.71.173.58]) by mx0b-00128a01.pphosted.com (PPS) with ESMTPS id 4bpau08gve-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 14 Jan 2026 07:47:53 -0500 (EST) Received: from ASHBMBX9.ad.analog.com (ASHBMBX9.ad.analog.com [10.64.17.10]) by nwd2mta4.analog.com (8.14.7/8.14.7) with ESMTP id 60EClqp9061511 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 14 Jan 2026 07:47:52 -0500 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.1748.37; Wed, 14 Jan 2026 07:47:52 -0500 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.1748.37; Wed, 14 Jan 2026 07:47:52 -0500 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.1748.37 via Frontend Transport; Wed, 14 Jan 2026 07:47:52 -0500 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 60EClcnl001748; Wed, 14 Jan 2026 07:47:40 -0500 From: Jonathan Santos To: , , CC: Jonathan Santos , , , , , , , , , , Subject: [PATCH v6 5/5] iio: adc: ad7768-1: add support for ADAQ776x-1 ADC Family Date: Wed, 14 Jan 2026 06:27:29 -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: AW1haW4tMjYwMTE0MDEwNiBTYWx0ZWRfX7BFwnMfkgx9d x8SpT/5mdWudB0cSDSArNQFPdO3mjpvx3e6yKNRxXUEVtJm5oCWDQFsCWcHdttYi9dLcaih7Md0 wsGnqh9xPJsX1yoByfP78I8K+SRXtSMgEWQ3wY2gY4Ra5dz3EC7xarZqYqsfMXS3m1pszLLRERs Ixl1BsUN6owhwMDvuskXVo5swDHj8YiiyGtnKdSd1IW5MkNSRofq0hldxyEIrNGhy9hOPvI3R/J IQYzzhPYptdO8a0qwRDOd56/+cuHZJ4YDVW+uhm8rhfXbrD6t0isx6LUN0u9Jb7SRNCpF5Y2pLG CcQfhAYqaDU5rFtWwaDYIfogfP39Ss7hQmE9syR5NxpIY4cfh7YXS0N/H0sobZ/1srm080dqCdr WIAJSQK8ZPlmr3yYsey0NGlHWL7v4ij17rRY+8DPhJwe7XFwra5+nRD58603QvOJcIZDW9A/WCC DQ6/gtGroNvZVWb0epA== X-Authority-Analysis: v=2.4 cv=YcWwJgRf c=1 sm=1 tr=0 ts=6967907a cx=c_pps a=3WNzaoukacrqR9RwcOSAdA==:117 a=3WNzaoukacrqR9RwcOSAdA==:17 a=vUbySO9Y5rIA:10 a=VkNPw1HP01LnGYTKEx00:22 a=gAnH3GRIAAAA:8 a=OY_cmHL8cwcxf5wYxqQA:9 X-Proofpoint-ORIG-GUID: VXbU4SweE-iJquaFw_50DeJbJgkg53Tk X-Proofpoint-GUID: VXbU4SweE-iJquaFw_50DeJbJgkg53Tk X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1121,Hydra:6.1.9,FMLib:17.12.100.49 definitions=2026-01-14_04,2026-01-09_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 malwarescore=0 lowpriorityscore=0 adultscore=0 clxscore=1015 priorityscore=1501 phishscore=0 bulkscore=0 spamscore=0 suspectscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2512120000 definitions=main-2601140106 Content-Type: text/plain; charset="utf-8" Add support for ADAQ7767/68/69-1 series, which includes PGIA and Anti-aliasing filter (AAF) gains. Unlike the AD7768-1, they do not provide a VCM regulator interface. The PGA gain is configured in run-time through the scale attribute, if supported by the device. PGA is controlled by GPIOs provided in the device tree. The AAF gain is defined by hardware connections and should be specified in the device tree. Signed-off-by: Jonathan Santos --- v6 Changes: * Refactored ad7768_parse_aaf_gain() to improve cleanliness and readability. v5 Changes: * Write scale attribute without direct mode claim to avoid deadlock when using GPIOs from the device's own controller. v4 Changes: * replaced shift_right() with '>>' operator in the ad7768_fill_scale_tbl() function. * Refactored ad7768_parse_aaf_gain () as requested. * renamed ad7768_register_regulators() to ad7768_register_vcm_regulator() to better reflect its purpose (not sure if this is ok to do). * Replaced u64_fract with u32_fract -> after reviewing the numbers again, I realized that u32_fract is sufficient for these calculations. * addressed minor suggestions. * Adopted a new approach to manage the PGA GPIOs, using pga-gpios property. This avoids possible conflicts when the internal gpio controller is used externally (and also allows hardwiring, as soon as the gpio interface=20 supports it). However, using GPIOs from the device's own controller causes a deadlock when claiming direct mode in the ad7768_gpio_get() function. This happens because the direct mode remains locked by the ad7768_write_r= aw() function. I have kept this approach for now to discuss a way around this problem. It would be good to have the flexibility provided by pga-gpios=20 property. v3 Changes: * Fixed trailing comma issues. * Addressed other minor issues related to dead code, variable declaration, etc. * removed unnecessary comments and relocating some local variables. * replaced mutex_init() with devm_mutex_init(). * adopted different variables for the input and output of=20 rational_best_approximation(). Also used a u64_fract for the inputs, but=20 kept the unsigned long for the outputs, because could not create a unsign= ed long fraction number type. * ad7768_set_pga_gain(): removed the pgia enable check, relying on the regmap cache. * Moved aaf gain parsing to its own function, and now returning after warning to avoid setting a variable when it shouldn't (avoid confusion). * AAF gain is now in basis point units, so related multipliers and dividers are adjusted accordingly. v2 Changes: * Added more details to the commit message. * Some devices does not provide VCM regulator, so a new field in the chip info struct was added to indicate this. * Added 'select RATIONAL' to Kconfig. Kernel test robot pointed out compilation error due to undefined reference to=20 rational_best_approximation(). * Added lock to protect PGA value access. * precision in the PGA calculation is now dependent of the channel sign (signed or unsigned). * went back to the original scale computation: (st->vref_uv * 2) / 2^n instead of st->vref_uv / 2^(n-1). * rewrote AAF gain check and replaced error returns with warnings. I the AAF gain is not provided, a default value is used. * Addressed other minor suggestions. --- drivers/iio/adc/Kconfig | 1 + drivers/iio/adc/ad7768-1.c | 311 ++++++++++++++++++++++++++++++++++++- 2 files changed, 308 insertions(+), 4 deletions(-) diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig index b4295aa415bf..60038ae8dfc4 100644 --- a/drivers/iio/adc/Kconfig +++ b/drivers/iio/adc/Kconfig @@ -411,6 +411,7 @@ config AD7768_1 depends on SPI select REGULATOR select REGMAP_SPI + select RATIONAL select IIO_BUFFER select IIO_TRIGGER select IIO_TRIGGERED_BUFFER diff --git a/drivers/iio/adc/ad7768-1.c b/drivers/iio/adc/ad7768-1.c index bd4b2e090c5b..980c079ab41a 100644 --- a/drivers/iio/adc/ad7768-1.c +++ b/drivers/iio/adc/ad7768-1.c @@ -6,6 +6,7 @@ */ #include #include +#include #include #include #include @@ -14,8 +15,12 @@ #include #include #include +#include +#include #include #include +#include +#include #include #include #include @@ -107,10 +112,15 @@ =20 #define AD7768_VCM_OFF 0x07 =20 +#define ADAQ776X_GAIN_MAX_NANO (128 * NANO) +#define ADAQ776X_MAX_GAIN_MODES 8 + #define AD7768_TRIGGER_SOURCE_SYNC_IDX 0 =20 #define AD7768_MAX_CHANNELS 1 =20 +#define ADAQ7768_PGA_PINS 3 + enum ad7768_conv_mode { AD7768_CONTINUOUS, AD7768_ONE_SHOT, @@ -153,6 +163,51 @@ enum ad7768_scan_type { AD7768_SCAN_TYPE_HIGH_SPEED, }; =20 +enum { + AD7768_PGA_GAIN_0, + AD7768_PGA_GAIN_1, + AD7768_PGA_GAIN_2, + AD7768_PGA_GAIN_3, + AD7768_PGA_GAIN_4, + AD7768_PGA_GAIN_5, + AD7768_PGA_GAIN_6, + AD7768_PGA_GAIN_7, +}; + +enum { + AD7768_AAF_IN1, + AD7768_AAF_IN2, + AD7768_AAF_IN3, +}; + +/* PGA and AAF gains in V/V */ +static const int adaq7768_gains[] =3D { + [AD7768_PGA_GAIN_0] =3D 325, /* 0.325 */ + [AD7768_PGA_GAIN_1] =3D 650, /* 0.650 */ + [AD7768_PGA_GAIN_2] =3D 1300, /* 1.300 */ + [AD7768_PGA_GAIN_3] =3D 2600, /* 2.600 */ + [AD7768_PGA_GAIN_4] =3D 5200, /* 5.200 */ + [AD7768_PGA_GAIN_5] =3D 10400, /* 10.400 */ + [AD7768_PGA_GAIN_6] =3D 20800, /* 20.800 */ +}; + +static const int adaq7769_gains[] =3D { + [AD7768_PGA_GAIN_0] =3D 1000, /* 1.000 */ + [AD7768_PGA_GAIN_1] =3D 2000, /* 2.000 */ + [AD7768_PGA_GAIN_2] =3D 4000, /* 4.000 */ + [AD7768_PGA_GAIN_3] =3D 8000, /* 8.000 */ + [AD7768_PGA_GAIN_4] =3D 16000, /* 16.000 */ + [AD7768_PGA_GAIN_5] =3D 32000, /* 32.000 */ + [AD7768_PGA_GAIN_6] =3D 64000, /* 64.000 */ + [AD7768_PGA_GAIN_7] =3D 128000, /* 128.000 */ +}; + +static const int ad7768_aaf_gains_bp[] =3D { + [AD7768_AAF_IN1] =3D 10000, /* 1.000 */ + [AD7768_AAF_IN2] =3D 3640, /* 0.364 */ + [AD7768_AAF_IN3] =3D 1430, /* 0.143 */ +}; + /* -3dB cutoff frequency multipliers (relative to ODR) for each filter typ= e. */ static const int ad7768_filter_3db_odr_multiplier[] =3D { [AD7768_FILTER_SINC5] =3D 204, /* 0.204 */ @@ -217,6 +272,13 @@ struct ad7768_chip_info { const char *name; const struct iio_chan_spec *channel_spec; int num_channels; + const int *pga_gains; + int num_pga_modes; + int default_pga_mode; + int pgia_mode2pin_offset; + bool has_pga; + bool has_variable_aaf; + bool has_vcm_regulator; }; =20 struct ad7768_state { @@ -234,14 +296,19 @@ struct ad7768_state { unsigned int samp_freq; unsigned int samp_freq_avail[ARRAY_SIZE(ad7768_mclk_div_rates)]; unsigned int samp_freq_avail_len; + unsigned int pga_gain_mode; + unsigned int aaf_gain; + int scale_tbl[ADAQ776X_MAX_GAIN_MODES][2]; struct completion completion; struct iio_trigger *trig; + struct gpio_descs *pga_gpios; struct gpio_desc *gpio_sync_in; struct gpio_desc *gpio_reset; const char *labels[AD7768_MAX_CHANNELS]; struct gpio_chip gpiochip; const struct ad7768_chip_info *chip; bool en_spi_sync; + struct mutex pga_lock; /* protect device internal state (PGA) */ /* * DMA (thus cache coherency maintenance) may require the * transfer buffers to live in their own cache lines. @@ -464,6 +531,42 @@ static int ad7768_reg_access(struct iio_dev *indio_dev, return ret; } =20 +static void ad7768_fill_scale_tbl(struct iio_dev *dev) +{ + struct ad7768_state *st =3D iio_priv(dev); + const struct iio_scan_type *scan_type; + int val, val2, tmp0, tmp1, i; + struct u32_fract fract; + unsigned long n, d; + u64 tmp2; + + scan_type =3D iio_get_current_scan_type(dev, &dev->channels[0]); + if (scan_type->sign =3D=3D 's') + val2 =3D scan_type->realbits - 1; + else + val2 =3D scan_type->realbits; + + for (i =3D 0; i < st->chip->num_pga_modes; i++) { + /* Convert gain to a fraction format */ + fract.numerator =3D st->chip->pga_gains[i]; + fract.denominator =3D MILLI; + if (st->chip->has_variable_aaf) { + fract.numerator *=3D ad7768_aaf_gains_bp[st->aaf_gain]; + fract.denominator *=3D PERMYRIAD; + } + + rational_best_approximation(fract.numerator, fract.denominator, + INT_MAX, INT_MAX, &n, &d); + + val =3D mult_frac(st->vref_uv, d, n); + /* Would multiply by NANO here, but value is already in milli */ + tmp2 =3D ((u64)val * MICRO) >> val2; + tmp0 =3D div_u64_rem(tmp2, NANO, &tmp1); + st->scale_tbl[i][0] =3D tmp0; /* Integer part */ + st->scale_tbl[i][1] =3D abs(tmp1); /* Fractional part */ + } +} + static int ad7768_set_sinc3_dec_rate(struct ad7768_state *st, unsigned int dec_rate) { @@ -565,12 +668,66 @@ static int ad7768_configure_dig_fil(struct iio_dev *d= ev, st->oversampling_ratio =3D ad7768_dec_rate_values[dec_rate_idx]; } =20 + /* Update scale table: scale values vary according to the precision */ + ad7768_fill_scale_tbl(dev); + ad7768_fill_samp_freq_tbl(st); =20 /* A sync-in pulse is required after every configuration change */ return ad7768_send_sync_pulse(st); } =20 +static int ad7768_setup_pga(struct device *dev, struct ad7768_state *st) +{ + st->pga_gpios =3D devm_gpiod_get_array(dev, "pga", GPIOD_OUT_LOW); + if (IS_ERR(st->pga_gpios)) + return dev_err_probe(dev, PTR_ERR(st->pga_gpios), + "Failed to get PGA gpios.\n"); + + if (st->pga_gpios->ndescs !=3D ADAQ7768_PGA_PINS) + return dev_err_probe(dev, -EINVAL, + "Expected %d GPIOs for PGA control.\n", + ADAQ7768_PGA_PINS); + return 0; +} + +static int ad7768_calc_pga_gain(struct ad7768_state *st, int gain_int, + int gain_fract, int precision) +{ + u64 gain_nano; + u32 tmp; + + gain_nano =3D gain_int * NANO + gain_fract; + gain_nano =3D clamp(gain_nano, 0, ADAQ776X_GAIN_MAX_NANO); + tmp =3D DIV_ROUND_CLOSEST_ULL(gain_nano << precision, NANO); + gain_nano =3D DIV_ROUND_CLOSEST(st->vref_uv, tmp); + if (st->chip->has_variable_aaf) + gain_nano =3D DIV_ROUND_CLOSEST_ULL(gain_nano * PERMYRIAD, + ad7768_aaf_gains_bp[st->aaf_gain]); + + return find_closest(gain_nano, st->chip->pga_gains, + (int)st->chip->num_pga_modes); +} + +static int ad7768_set_pga_gain(struct ad7768_state *st, + int gain_mode) +{ + int pgia_pins_value =3D abs(gain_mode - st->chip->pgia_mode2pin_offset); + DECLARE_BITMAP(bitmap, ADAQ7768_PGA_PINS) =3D { }; + int ret; + + guard(mutex)(&st->pga_lock); + + bitmap_write(bitmap, pgia_pins_value, 0, ADAQ7768_PGA_PINS); + ret =3D gpiod_multi_set_value_cansleep(st->pga_gpios, bitmap); + if (ret) + return ret; + + st->pga_gain_mode =3D gain_mode; + + return 0; +} + static int ad7768_gpio_direction_input(struct gpio_chip *chip, unsigned in= t offset) { struct iio_dev *indio_dev =3D gpiochip_get_data(chip); @@ -792,6 +949,10 @@ static const struct iio_chan_spec ad7768_channels[] = =3D { AD7768_CHAN(0, 0), }; =20 +static const struct iio_chan_spec adaq776x_channels[] =3D { + AD7768_CHAN(0, BIT(IIO_CHAN_INFO_SCALE)), +}; + static int ad7768_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val, int *val2, long info) @@ -819,7 +980,19 @@ static int ad7768_read_raw(struct iio_dev *indio_dev, return IIO_VAL_INT; =20 case IIO_CHAN_INFO_SCALE: - *val =3D (st->vref_uv * 2) / 1000; + if (st->chip->has_pga) { + guard(mutex)(&st->pga_lock); + + *val =3D st->scale_tbl[st->pga_gain_mode][0]; + *val2 =3D st->scale_tbl[st->pga_gain_mode][1]; + return IIO_VAL_INT_PLUS_NANO; + } + + temp =3D (st->vref_uv * 2) / 1000; + if (st->chip->has_variable_aaf) + temp =3D (temp * PERMYRIAD) / ad7768_aaf_gains_bp[st->aaf_gain]; + + *val =3D temp; *val2 =3D scan_type->realbits; =20 return IIO_VAL_FRACTIONAL_LOG2; @@ -875,18 +1048,39 @@ static int ad7768_read_avail(struct iio_dev *indio_d= ev, *length =3D st->samp_freq_avail_len; *type =3D IIO_VAL_INT; return IIO_AVAIL_LIST; + case IIO_CHAN_INFO_SCALE: + *vals =3D (int *)st->scale_tbl; + *length =3D st->chip->num_pga_modes * 2; + *type =3D IIO_VAL_INT_PLUS_NANO; + return IIO_AVAIL_LIST; default: return -EINVAL; } } =20 +static int ad7768_write_raw_get_fmt(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, long mask) +{ + switch (mask) { + case IIO_CHAN_INFO_SCALE: + return IIO_VAL_INT_PLUS_NANO; + default: + return IIO_VAL_INT_PLUS_MICRO; + } +} + 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); + const struct iio_scan_type *scan_type; int 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_SAMP_FREQ: if (!iio_device_claim_direct(indio_dev)) @@ -902,6 +1096,21 @@ static int ad7768_write_raw(struct iio_dev *indio_dev, ret =3D ad7768_update_dec_rate(indio_dev, val); iio_device_release_direct(indio_dev); return ret; + case IIO_CHAN_INFO_SCALE: { + int gain_mode; + + if (!st->chip->has_pga) + return -EOPNOTSUPP; + + if (scan_type->sign =3D=3D 's') + gain_mode =3D ad7768_calc_pga_gain(st, val, val2, + scan_type->realbits - 1); + else + gain_mode =3D ad7768_calc_pga_gain(st, val, val2, + scan_type->realbits); + + return ad7768_set_pga_gain(st, gain_mode); + } default: return -EINVAL; } @@ -928,6 +1137,7 @@ static const struct iio_info ad7768_info =3D { .read_raw =3D &ad7768_read_raw, .read_avail =3D &ad7768_read_avail, .write_raw =3D &ad7768_write_raw, + .write_raw_get_fmt =3D &ad7768_write_raw_get_fmt, .read_label =3D ad7768_read_label, .get_current_scan_type =3D &ad7768_get_current_scan_type, .debugfs_reg_access =3D &ad7768_reg_access, @@ -1311,8 +1521,9 @@ static const struct regulator_desc vcm_desc =3D { .owner =3D THIS_MODULE, }; =20 -static int ad7768_register_regulators(struct device *dev, struct ad7768_st= ate *st, - struct iio_dev *indio_dev) +static int ad7768_register_vcm_regulator(struct device *dev, + struct ad7768_state *st, + struct iio_dev *indio_dev) { struct regulator_config config =3D { .dev =3D dev, @@ -1334,10 +1545,77 @@ static int ad7768_register_regulators(struct device= *dev, struct ad7768_state *s return 0; } =20 +static int ad7768_parse_aaf_gain(struct device *dev, struct ad7768_state *= st) +{ + u32 val; + int ret; + + ret =3D device_property_read_u32(dev, "adi,aaf-gain-bp", &val); + if (ret =3D=3D -EINVAL) { + /* If controllable, use default */ + if (st->chip->has_variable_aaf) + st->aaf_gain =3D AD7768_AAF_IN1; + return 0; + } + if (ret) + return dev_err_probe(dev, ret, "Failed to get AAF gain value\n"); + + if (!st->chip->has_variable_aaf) + return dev_err_probe(dev, -EOPNOTSUPP, + "AAF gain provided, but not supported for %s\n", st->chip->name); + + switch (val) { + case 10000: + st->aaf_gain =3D AD7768_AAF_IN1; + break; + case 3640: + st->aaf_gain =3D AD7768_AAF_IN2; + break; + case 1430: + st->aaf_gain =3D AD7768_AAF_IN3; + break; + default: + return dev_err_probe(dev, -EINVAL, "Invalid firmware provided AAF gain\n= "); + } + + return 0; +} + static const struct ad7768_chip_info ad7768_chip_info =3D { .name =3D "ad7768-1", .channel_spec =3D ad7768_channels, .num_channels =3D ARRAY_SIZE(ad7768_channels), + .has_vcm_regulator =3D true, +}; + +static const struct ad7768_chip_info adaq7767_chip_info =3D { + .name =3D "adaq7767-1", + .channel_spec =3D ad7768_channels, + .num_channels =3D ARRAY_SIZE(ad7768_channels), + .has_variable_aaf =3D true, +}; + +static const struct ad7768_chip_info adaq7768_chip_info =3D { + .name =3D "adaq7768-1", + .channel_spec =3D adaq776x_channels, + .num_channels =3D ARRAY_SIZE(adaq776x_channels), + .pga_gains =3D adaq7768_gains, + .default_pga_mode =3D AD7768_PGA_GAIN_2, + .num_pga_modes =3D ARRAY_SIZE(adaq7768_gains), + .pgia_mode2pin_offset =3D 6, + .has_pga =3D true, +}; + +static const struct ad7768_chip_info adaq7769_chip_info =3D { + .name =3D "adaq7769-1", + .channel_spec =3D adaq776x_channels, + .num_channels =3D ARRAY_SIZE(adaq776x_channels), + .pga_gains =3D adaq7769_gains, + .default_pga_mode =3D AD7768_PGA_GAIN_0, + .num_pga_modes =3D ARRAY_SIZE(adaq7769_gains), + .pgia_mode2pin_offset =3D 0, + .has_pga =3D true, + .has_variable_aaf =3D true, }; =20 static int ad7768_probe(struct spi_device *spi) @@ -1398,7 +1676,13 @@ static int ad7768_probe(struct spi_device *spi) indio_dev->modes =3D INDIO_DIRECT_MODE; =20 /* Register VCM output regulator */ - ret =3D ad7768_register_regulators(&spi->dev, st, indio_dev); + if (st->chip->has_vcm_regulator) { + ret =3D ad7768_register_vcm_regulator(&spi->dev, st, indio_dev); + if (ret) + return ret; + } + + ret =3D ad7768_parse_aaf_gain(&spi->dev, st); if (ret) return ret; =20 @@ -1409,6 +1693,19 @@ static int ad7768_probe(struct spi_device *spi) } =20 init_completion(&st->completion); + ret =3D devm_mutex_init(&spi->dev, &st->pga_lock); + if (ret) + return ret; + + if (st->chip->has_pga) { + ret =3D ad7768_setup_pga(&spi->dev, st); + if (ret) + return ret; + + ret =3D ad7768_set_pga_gain(st, st->chip->default_pga_mode); + if (ret) + return ret; + } =20 ret =3D ad7768_set_channel_label(indio_dev, st->chip->num_channels); if (ret) @@ -1430,12 +1727,18 @@ static int ad7768_probe(struct spi_device *spi) =20 static const struct spi_device_id ad7768_id_table[] =3D { { "ad7768-1", (kernel_ulong_t)&ad7768_chip_info }, + { "adaq7767-1", (kernel_ulong_t)&adaq7767_chip_info }, + { "adaq7768-1", (kernel_ulong_t)&adaq7768_chip_info }, + { "adaq7769-1", (kernel_ulong_t)&adaq7769_chip_info }, { } }; MODULE_DEVICE_TABLE(spi, ad7768_id_table); =20 static const struct of_device_id ad7768_of_match[] =3D { { .compatible =3D "adi,ad7768-1", .data =3D &ad7768_chip_info }, + { .compatible =3D "adi,adaq7767-1", .data =3D &adaq7767_chip_info }, + { .compatible =3D "adi,adaq7768-1", .data =3D &adaq7768_chip_info }, + { .compatible =3D "adi,adaq7769-1", .data =3D &adaq7769_chip_info }, { } }; MODULE_DEVICE_TABLE(of, ad7768_of_match); --=20 2.34.1