From nobody Sat Feb 7 18:46:49 2026 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 C173182866; Wed, 8 Oct 2025 13:50:07 +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=1759931413; cv=none; b=Ht8BIVakMRUJsX37Rye3ppUBPTM575zhIbLQwGTkKv5LUJ8aUmlKDhXUgjRK6FMxqcXtFqIOlHnJ7KWmc1HfA/sDuzxCRsCJxCFbpuV0W0XOdiaxTSizyCk6spG/xy36LD6axVQNMcrbplj9gZItiDbZ0eQ2RPjmnpS7agRJ/wk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759931413; c=relaxed/simple; bh=mt6mk92G8Wp/LF9LoiJvv23Qnl+30b3PYrh3xYovCOQ=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=iG4lIz5AUIP8d8GrstAlLajjbkWnFSGukFv44gtAIkkLmmsra1nia+/oKbjfND4IpvEw3b2TTwRNqHHN8yZ86prk+rb51daeeuVAZRTPLIoSQScp3qObyoatZWOkEkcD7UgHnQQpp4lkCYp9iIoA2hmAkPOwkd/nx38OaLioAvU= 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=YIDEM6bE; 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="YIDEM6bE" 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 598DhLUD027014; Wed, 8 Oct 2025 09:50: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=IuAEW CIZinH7WwhYHqYfX3yHq02iuYjqR8hz5gpwK5w=; b=YIDEM6bEAFXi4w5jHl3D0 SXszt+KdbQNqDbLkDpKrzPKonmBcV/lAMB5wRhMxJCfkBA1INP6btxi3m3a5HwWr oB1eiPb3SqzsSPQcXp/pkck/L3MUSgxm90/Pv3+OKZv1v3ZkLluOHtWK8Xc93bqQ ZdpXvdlR196UXgzJOZYn54pDYxt3xoqM1ZAHZVLIwlVsRtHKvYo7iKFY7T8aa++X FzR+W82SWq8xHDLjjARUQcUhtNscQ3aAbnYqc95iQG2t8bkvY95m3klg6ovlmEoy jk+3W8v65YcxFy4AFavAPkLXeFyIZlLtBO0mKlM+YVWqKAAoWY3wxWOnfQY8J0ZN w== Received: from nwd2mta3.analog.com ([137.71.173.56]) by mx0a-00128a01.pphosted.com (PPS) with ESMTPS id 49ndssugg0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 08 Oct 2025 09:50:02 -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 598Do1pm034447 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 8 Oct 2025 09:50:01 -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.1748.37; Wed, 8 Oct 2025 09:50:01 -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.1748.37; Wed, 8 Oct 2025 09:50:01 -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.1748.37 via Frontend Transport; Wed, 8 Oct 2025 09:50:01 -0400 Received: from work.ad.analog.com (HYB-hERzalRezfV.ad.analog.com [10.65.205.9]) by zeus.spd.analog.com (8.15.1/8.15.1) with ESMTP id 598DnjCv023104; Wed, 8 Oct 2025 09:49:47 -0400 From: Marcelo Schmitt To: , , , , , CC: , , , , , , , , , , , , "kernel test robot" Subject: [PATCH v4 1/8] pwm: Declare waveform stubs for when PWM is not reachable Date: Wed, 8 Oct 2025 10:49:44 -0300 Message-ID: <129ff5c5b7f7be4f4f3f9cf8aa3e1957d713acb7.1759929814.git.marcelo.schmitt@analog.com> X-Mailer: git-send-email 2.39.2 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: AW1haW4tMjUxMDA4MDAwNCBTYWx0ZWRfXwTOj6bstowOt XY1ZKaaJ/bn9N54YTNBwVHv+Jxgl0t6VKNnNjKYdyV/xRrwtp9dd5axGfndCvljxQEXJKN4DYEU /HkOfY4N/+pguK1Co/CKO3ty5X5ydOKvKO7Jmh8EZmyJOHM/XZESIX7wEwjHw7UBVtUv9f3kmy3 XmtIP3BSy+gZstvmMnltNnqMKWfN/epvzsfXEz9szsjIP8E9K1u9Y67kpgkWgJoZe55+2okFPip ZiFH9O64NR/GdwlIooz3e2/JM4GiogZegXEyemk5OU34Tx/nwQUOsQ7b5sFjF3Tx3H4+uClb7tS yJnLeXa84z7EugQGe/sKf+x3G/CSnMXnEYvajc+HPFpsItW3i95m9i/i6iDM8AcDQRuprkjXpaC zW7aUQyCW57ldMLEexyH/DdCI9uZSA== X-Proofpoint-ORIG-GUID: fvzaIIYYuTt2bSUnMeuFDQE_JXvRxcwL X-Proofpoint-GUID: fvzaIIYYuTt2bSUnMeuFDQE_JXvRxcwL X-Authority-Analysis: v=2.4 cv=e4ELiKp/ c=1 sm=1 tr=0 ts=68e66c0a cx=c_pps a=PpDZqlmH/M8setHirZLBMw==:117 a=PpDZqlmH/M8setHirZLBMw==:17 a=x6icFKpwvdMA:10 a=VwQbUJbxAAAA:8 a=QyXUC8HyAAAA:8 a=gAnH3GRIAAAA:8 a=EaJPzwpAO8ApEi7CHwMA:9 a=cPQSjfK2_nFv0Q5t_7PE:22 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1117,Hydra:6.1.9,FMLib:17.12.80.40 definitions=2025-10-08_04,2025-10-06_01,2025-03-28_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 lowpriorityscore=0 impostorscore=0 suspectscore=0 adultscore=0 priorityscore=1501 clxscore=1015 phishscore=0 bulkscore=0 spamscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.19.0-2509150000 definitions=main-2510080004 Content-Type: text/plain; charset="utf-8" Previously, the PWM waveform consumer API would not be declared if CONFIG_PWM was not reachable. That caused kernel builds to fail if a consumer driver was enabled but PWM disabled. Add stubs for PWM waveform functions so client drivers that use, but don't depend on PWM, can build if PWM is disabled. Fixes: 6c5126c6406d ("pwm: Provide new consumer API functions for waveforms= ") Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-kbuild-all/202509272028.0zLNiR5w-lkp@int= el.com/ Signed-off-by: Marcelo Schmitt --- I've included this patch in this series because it should save us from being notified by 0-day about the build failure this patch fixes. From contributo= r's perspective, it's easier to have this patch together with the rest of ad4030 series. Though, no objection if kernel maintainers decide to pick it [1] th= rough the PWM tree. [1]: https://lore.kernel.org/linux-pwm/1ac0fc529e02744aacfcb9140ed597ff6088= 6f39.1759873890.git.marcelo.schmitt@analog.com/ Thanks, Marcelo include/linux/pwm.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/include/linux/pwm.h b/include/linux/pwm.h index 8cafc483db53..e79545c0cb89 100644 --- a/include/linux/pwm.h +++ b/include/linux/pwm.h @@ -501,6 +501,25 @@ struct pwm_device *devm_fwnode_pwm_get(struct device *= dev, struct fwnode_handle *fwnode, const char *con_id); #else +static inline int pwm_round_waveform_might_sleep(struct pwm_device *pwm, s= truct pwm_waveform *wf) +{ + might_sleep(); + return -EOPNOTSUPP; +} + +static inline int pwm_get_waveform_might_sleep(struct pwm_device *pwm, str= uct pwm_waveform *wf) +{ + might_sleep(); + return -EOPNOTSUPP; +} + +static inline int pwm_set_waveform_might_sleep(struct pwm_device *pwm, + const struct pwm_waveform *wf, bool exact) +{ + might_sleep(); + return -EOPNOTSUPP; +} + static inline bool pwm_might_sleep(struct pwm_device *pwm) { return true; --=20 2.39.2 From nobody Sat Feb 7 18:46:49 2026 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 3CB11286D60; Wed, 8 Oct 2025 13:50: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=1759931429; cv=none; b=HTeWl3L+S9kYwDfaAaJDyja/hbiWIIFKbGYYTcHm4vivlDhaIXP/Y6yeid+nrJRojEiXpRiCuV3zPjhn+zI9EJmTAqx5zk18BkxlZMhCOjOD65QzGHVFQsLy2v3mG1EwclCU2fMm8uD0uBNXO+IPpLUe4VvlAgebJC1CTgNW/u8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759931429; c=relaxed/simple; bh=WZ9Dsob8217rQMVY/2ETpmcz51DbclJK5tiSEfVxA3E=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=e5eMAU+RNqkyqTw95WVxtIsuu46pthbRfxxMMD5Txy7LjT62JJdVkezSJWYdkymX6Gyzk1BhPMvZP3Hf5U+f0yYSGkHSkdaC8I+MvjrmRitjIP41VSLz8JZh5HGIzU6IBoYZKMyUvN5QUvcOp95sQXM1r6QpDRBsHvyJkW3GoVs= 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=i/R8uxyo; 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="i/R8uxyo" 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 598D9EHa010582; Wed, 8 Oct 2025 09:50: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=S14ln y/Kcps9xDIlvxH1tzTzOuHDv/EVueka5mwTaCY=; b=i/R8uxyoZnesRFg+GI9FS Qe2k90MnnIwZ0ndwL+3cIR9TvPFUSnYGJMBWT/JU8z2PuncgG29MA/+xysOgP7DU D+RoE+MjwQvUec2y7lHRm6r7oiCkBEDIiHBRHXgupbtznVVsrGoVlykix12mqIoG AEHf+JadpkLur/OlzRB20wNW7sGSjW0xS45uFXfuJ8Q2MEzeDv7IMEFrT9S38Cmo VYv+hfNEWFvIilijJOiAV9t7Sx8JpH7mcq/LCfpInPWiUZYG3K50Feay48m8Nf8e z4lfois5e7xiMM7cG6Boa6OJlLvFcOgtVoTjdfb17X/ROnFVwJuypFLrUG3Ns522 Q== Received: from nwd2mta3.analog.com ([137.71.173.56]) by mx0a-00128a01.pphosted.com (PPS) with ESMTPS id 49jwe2742g-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 08 Oct 2025 09:50:21 -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 598DoIC0034526 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 8 Oct 2025 09:50: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.1748.37; Wed, 8 Oct 2025 09:50: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.1748.37; Wed, 8 Oct 2025 09:50: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.1748.37 via Frontend Transport; Wed, 8 Oct 2025 09:50:17 -0400 Received: from work.ad.analog.com (HYB-hERzalRezfV.ad.analog.com [10.65.205.9]) by zeus.spd.analog.com (8.15.1/8.15.1) with ESMTP id 598Do3qK023146; Wed, 8 Oct 2025 09:50:06 -0400 From: Marcelo Schmitt To: , , , , , CC: , , , , , , , , , , , , "Conor Dooley" Subject: [PATCH v4 2/8] dt-bindings: iio: adc: adi,ad4030: Reference spi-peripheral-props Date: Wed, 8 Oct 2025 10:50:03 -0300 Message-ID: <5dcddffbd766a41ad6ef66f03ca5e74d96392167.1759929814.git.marcelo.schmitt@analog.com> X-Mailer: git-send-email 2.39.2 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=Y7n1cxeN c=1 sm=1 tr=0 ts=68e66c1d cx=c_pps a=PpDZqlmH/M8setHirZLBMw==:117 a=PpDZqlmH/M8setHirZLBMw==:17 a=x6icFKpwvdMA:10 a=gAnH3GRIAAAA:8 a=XYAwZIGsAAAA:8 a=EfQ9L3lKGMo9VN_2EekA:9 a=E8ToXWR_bxluHZ7gmE-Z:22 a=cPQSjfK2_nFv0Q5t_7PE:22 X-Proofpoint-GUID: P-_QyPTmD5VLCTEcgKvdbHazj-spBKEf X-Proofpoint-ORIG-GUID: P-_QyPTmD5VLCTEcgKvdbHazj-spBKEf X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMDA0MDA0MyBTYWx0ZWRfX16aNxcj35UWB 0+Q2Mb/fd84Lnpl3WDgfVzarDwa3rIkOnoEIapMjpu6rqeQ6ETdVG9FOsn7ekOtbK0nyRC0tGbK wbe5DhryWPP55PPy/Yd/fRjy8xc1n8e2fvVaB5TZ7J61bpphuvczzBnOiNryt3n1+uAMJem9OQ3 dNELaVYIbLPgFf005VH8PV/efnEdCoQ/2CnVxfXwbNyJKzqKrI65p6EApSx5SaXlOlDHCQ3EoEG uoFOJ6Nct8SiUWLefuAOOjga3h4QsiX2vrFIJwdSgHKZvJ4D8omwN+hh/apRh8Ds3J/vxHie/Ta TsAI44SK3HYpJ5LYi1N9muJRCzTCflb8sq3aVyz7xR7a4vWIdnHtE4pdV03MRZTmrOdLE9b+ojo J+o1yaCTML1FmN/cbq0iCGteH0P37A== X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1117,Hydra:6.1.9,FMLib:17.12.80.40 definitions=2025-10-08_04,2025-10-06_01,2025-03-28_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 adultscore=0 spamscore=0 bulkscore=0 lowpriorityscore=0 phishscore=0 impostorscore=0 malwarescore=0 priorityscore=1501 suspectscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.19.0-2509150000 definitions=main-2510040043 Content-Type: text/plain; charset="utf-8" AD4030 and similar devices all connect to the system as SPI peripherals. Reference spi-peripheral-props so common SPI peripheral can be used from ad4030 dt-binding. Acked-by: Conor Dooley Signed-off-by: Marcelo Schmitt --- Documentation/devicetree/bindings/iio/adc/adi,ad4030.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Documentation/devicetree/bindings/iio/adc/adi,ad4030.yaml b/Do= cumentation/devicetree/bindings/iio/adc/adi,ad4030.yaml index 54e7349317b7..a8fee4062d0e 100644 --- a/Documentation/devicetree/bindings/iio/adc/adi,ad4030.yaml +++ b/Documentation/devicetree/bindings/iio/adc/adi,ad4030.yaml @@ -20,6 +20,8 @@ description: | * https://www.analog.com/media/en/technical-documentation/data-sheets/ad= 4630-24_ad4632-24.pdf * https://www.analog.com/media/en/technical-documentation/data-sheets/ad= 4630-16-4632-16.pdf =20 +$ref: /schemas/spi/spi-peripheral-props.yaml# + properties: compatible: enum: --=20 2.39.2 From nobody Sat Feb 7 18:46:49 2026 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 BFF6D16F288; Wed, 8 Oct 2025 13:50:47 +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=1759931449; cv=none; b=dIruh6YUQPoBwA1BatgGKUBxOcf5mTYuBwuPKe/VT6yUbhYRrqpHNjGYUgMWWxU9KtCx2YIThEaMWt4Ca408sxeGNYTeebSQTzv8fyK6vwZukT2OHqFQnmFVq1frXA9zk7D9TORkDiy+x4tXuF+yKLYUqJk2nDcxA+J0ZSbiGSI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759931449; c=relaxed/simple; bh=vreuyB1oJMX28dl3w587JJSbrdpOaZ848torossb2pI=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=pDSp5i6qMNczC++1lKXRNxwruOr54K7YG9FIRE9+mrIrinWw/pwz2+ZRUkRnLO3TJTcUL4LDPLp2+JH9rsBm9jYsIMN1HNkMqh4ej6El2cznCfiNJAMUsO7bYqCdmrccBWewUlv6NEoY09t7sy+Dai7PUu9OhOkOAKwqvGjHzoM= 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=SWXlKF3M; 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="SWXlKF3M" 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 598D6wjl010585; Wed, 8 Oct 2025 09:50:40 -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=/m5lg W9LZdYxB6YJs1TYPvAh9FlaVDaMUHUk0YNse/U=; b=SWXlKF3MmYYs1uxXPkVUE yOk+bLoXQ55c6qp6PHd9Odii23Ds6omvsKX4jz0t3gg4E1ma0QOEP1TndRdJx2w8 m9y34lrmKs0EcSj3tzh+F9tRwOrNpDYB0yRDkwltZrT/COeFBIRs02Ol9FKGgTm1 dMFH6/oxieg4iy8UA9YqJVcX33Ds3pooGngc3jJuhlBMW31ncKaUzw43TudjFcii 4ezYEb83hRfHp1oLDaniMDIP7FIjOnf46kQ2r3gP0mQUDWZQySYURcsWDFG3TW9U BKH7Bg7tmlZ36PdMXk0pIao/o5z3ZNOU2Ms3lUr5tBzPstQDiQDnscpQkLMnt7fP w== Received: from nwd2mta3.analog.com ([137.71.173.56]) by mx0a-00128a01.pphosted.com (PPS) with ESMTPS id 49jwe27442-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 08 Oct 2025 09:50:39 -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 598DocS1034658 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 8 Oct 2025 09:50:38 -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.1748.37; Wed, 8 Oct 2025 09:50:38 -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.1748.37 via Frontend Transport; Wed, 8 Oct 2025 09:50:38 -0400 Received: from work.ad.analog.com (HYB-hERzalRezfV.ad.analog.com [10.65.205.9]) by zeus.spd.analog.com (8.15.1/8.15.1) with ESMTP id 598DoMCX023152; Wed, 8 Oct 2025 09:50:24 -0400 From: Marcelo Schmitt To: , , , , , CC: , , , , , , , , , , , Subject: [PATCH v4 3/8] Docs: iio: ad4030: Add double PWM SPI offload doc Date: Wed, 8 Oct 2025 10:50:21 -0300 Message-ID: <30501211fb199f3322e2ec5d3fd2b0adac74f15e.1759929814.git.marcelo.schmitt@analog.com> X-Mailer: git-send-email 2.39.2 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=Y7n1cxeN c=1 sm=1 tr=0 ts=68e66c2f cx=c_pps a=PpDZqlmH/M8setHirZLBMw==:117 a=PpDZqlmH/M8setHirZLBMw==:17 a=x6icFKpwvdMA:10 a=wI1k2SEZAAAA:8 a=IpJZQVW2AAAA:8 a=gAnH3GRIAAAA:8 a=Z7BqY8bEq__jAXHbdh4A:9 a=6HWbV-4b7c7AdzY24d_u:22 a=IawgGOuG5U0WyFbmm1f5:22 a=cPQSjfK2_nFv0Q5t_7PE:22 a=poXaRoVlC6wW9_mwW8W4:22 a=pHzHmUro8NiASowvMSCR:22 a=xoEH_sTeL_Rfw54TyV31:22 X-Proofpoint-GUID: KtL50UfRmR_BybjJxFgSFaJDjQnWZT0G X-Proofpoint-ORIG-GUID: KtL50UfRmR_BybjJxFgSFaJDjQnWZT0G X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMDA0MDA0MyBTYWx0ZWRfXwgvJXXYfDDJ0 iGuT2ECtw4ZKG81w5QkpGFVfWm9WFbcEml5JM8HPpnW2xAU2H0oHhoKUNEiveQ1bV850pMr1W4v XUviZE1lb6BnwmnSpxzXMn3t4tt8ya3ffFxPuxWlTxQS4Is+fiyRajrurbIeaBYNo0EbcIFDJ/Z prlW6rNt/XpurDX41/RAtn6Qpy59SX0bKstK+9FrUyH0T0RZuZQqvxIBg+zYcxzRouRkCThXCeC DnBCM1RqMx9RzUDEvl/IZIE4KYY2zM2tZsbkuxy11QEanY+2tk78w1+KOWby/NxpvQwilhijdTn Ka5W81wK7a+5FR33CM9HqZVAygQOIf4SjW5XPHd5R5ty68pPEkCncUDhVYd5Hyzg/111RxIc+VY trmtUko0EF2oJkJ17dVatqk1n9C7TA== X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1117,Hydra:6.1.9,FMLib:17.12.80.40 definitions=2025-10-08_04,2025-10-06_01,2025-03-28_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 adultscore=0 spamscore=0 bulkscore=0 lowpriorityscore=0 phishscore=0 impostorscore=0 malwarescore=0 priorityscore=1501 suspectscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.19.0-2509150000 definitions=main-2510040043 Content-Type: text/plain; charset="utf-8" Document double PWM setup SPI offload wiring schema. Reviewed-by: David Lechner Signed-off-by: Marcelo Schmitt --- Documentation/iio/ad4030.rst | 39 ++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/Documentation/iio/ad4030.rst b/Documentation/iio/ad4030.rst index b57424b650a8..9caafa4148b0 100644 --- a/Documentation/iio/ad4030.rst +++ b/Documentation/iio/ad4030.rst @@ -92,6 +92,45 @@ Interleaved mode In this mode, both channels conversion results are bit interleaved one SDO= line. As such the wiring is the same as `One lane mode`_. =20 +SPI offload wiring +^^^^^^^^^^^^^^^^^^ + +.. code-block:: + + +-------------+ +-------------+ + | CNV |<-----+--| GPIO | + | | +--| PWM0 | + | | | | + | | +--| PWM1 | + | | | +-------------+ + | | +->| TRIGGER | + | CS |<--------| CS | + | | | | + | ADC | | SPI | + | | | | + | SDI |<--------| SDO | + | SDO |-------->| SDI | + | SCLK |<--------| SCLK | + +-------------+ +-------------+ + +In this mode, both the ``cnv-gpios`` and a ``pwms`` properties are require= d. +The ``pwms`` property specifies the PWM that is connected to the ADC CNV p= in. +The SPI offload will have a ``trigger-sources`` property to indicate the S= PI +offload (PWM) trigger source. For AD4030 and similar ADCs, there are two +possible data transfer zones for sample N. One of them (zone 1) starts aft= er the +data conversion for sample N is complete while the other one (zone 2) star= ts 9.8 +nanoseconds after the rising edge of CNV for sample N + 1. + +The configuration depicted in the above diagram is intended to perform data +transfer in zone 2. To achieve high sample rates while meeting ADC timing +requirements, an offset is added between the rising edges of PWM0 and PWM1= to +delay the SPI transfer until 9.8 nanoseconds after CNV rising edge. This +requires a specialized PWM controller that can provide such an offset. +The `AD4630-FMC HDL project`_, for example, can be configured to sample AD= 4030 +data during zone 2 data read window. + +.. _AD4630-FMC HDL project: https://analogdevicesinc.github.io/hdl/project= s/ad4630_fmc/index.html + SPI Clock mode -------------- =20 --=20 2.39.2 From nobody Sat Feb 7 18:46:49 2026 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 5EC01286408; Wed, 8 Oct 2025 13:51:01 +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=1759931462; cv=none; b=Ut1E1FTM9XIvTrhCimsYT3BHAja7w+HEbqNcc/TYUQDHuGx5I/tiUBYrXNMfIeznS/xfN+/o05tLu0b1i5mUm72YcH6tiHCG8e7meElA0zwcuyD1gAEPbnvgHSM+rOv+0AMHiLqREhIECf9bj58VVZkHGkOyHvxSl7zTEpR7rI0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759931462; c=relaxed/simple; bh=mMvQO9gUvkU4ydX38HzUe1NFpnjpQb6EoaNFMHqTHoo=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=MehVTOUq6Sp+Tpxj6mJylID8mM1iA/ISo8eCXtE/XHD3TEYjEehsTVBWuGuwh7sUQU2SVoi2EMCKE6GiVjYA69Y6OtesdTuZnuNnqAOjkOdq9xw0U7U2T1q53sMZL94XFUUpWZTJkK/s6rY38NYVGvo08DAtDqXj91RTGY5quxM= 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=XpgkCwxW; 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="XpgkCwxW" 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 598DOslm027046; Wed, 8 Oct 2025 09:50: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=1Xf3P 4FaNtw7plQ3RNniLL6fpn0T247BbYMIn6GhM7Y=; b=XpgkCwxW9qqupRpHTx5cG QwLqkRD+wsx2Ani5n6gjhg4lq4HQ+gyBgIe4olAXlR3HDNHkkhLY4KEMujfveOcx 9H/9gvEHiQj3vXXr4H1x3xTxGS+j+a6NmOaoHZ0hfVgqHJtyORi/vSGUpy0rC46/ pxV3ppwzxRXzWD+Pl9BMEP5GK106xjwPC4rM7BcghSAEu/z8J1nN4/jbra/UNp87 rdURN12ZyU/MBN4mjck6iZGD+ptGTm/E6w7HHf+PWSng6D3HY6JZaSrUty9S1r8M 1tPxx21Ft6AVN999QUWtdXoEbfLKbwRBQwyGinDkeWb9dsPTgai89SL6j5/nQQ4S w== Received: from nwd2mta3.analog.com ([137.71.173.56]) by mx0a-00128a01.pphosted.com (PPS) with ESMTPS id 49ndssugn2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 08 Oct 2025 09:50:56 -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 598DotBq034765 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 8 Oct 2025 09:50:55 -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.1748.37; Wed, 8 Oct 2025 09:50: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.1748.37 via Frontend Transport; Wed, 8 Oct 2025 09:50:55 -0400 Received: from work.ad.analog.com (HYB-hERzalRezfV.ad.analog.com [10.65.205.9]) by zeus.spd.analog.com (8.15.1/8.15.1) with ESMTP id 598DodVo023157; Wed, 8 Oct 2025 09:50:42 -0400 From: Marcelo Schmitt To: , , , , , CC: , , , , , , , , , , , , Conor Dooley Subject: [PATCH v4 4/8] dt-bindings: iio: adc: adi,ad4030: Add PWM Date: Wed, 8 Oct 2025 10:50:39 -0300 Message-ID: X-Mailer: git-send-email 2.39.2 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: AW1haW4tMjUxMDA4MDAwNCBTYWx0ZWRfX0TprBU8aneXz ojqimeL1mSfL/mCkF81JwbowU0RA+I14pZCA+Dc8Badk5nHRkdJAFJqgD3mG8fsHHPNXj8wqWdP g9rcxMOW4ZbZ6jJjz/3K+ClLiLeyU5BlDCky4Xp4Qc3DIBcekMRf7GRNb3oqWXmDgN4eDR2abY3 aRc300v59XCNk9ZiqWwzvAgZoG/YtGREpRF+s9bwY3LXA0NEB3RzoKrUJa5TgXEAs2azxr/9mQc jPUBJcKUsQDsAbt/PPLQTxa5VMrKA0FsLeGMzaUSgjRhAkkcFtnbwhs8BULndut6vxJNVRDHbip C1JsC3+/I/h44PHtdR427EWMqN+9rjYyzIcZbKCPScBS68wvXAly2g4bCq6exWHaWWJ6QKHdRZe fErrBD+EiW9og0WkA+3BYfxKU4bcUQ== X-Proofpoint-ORIG-GUID: 8TKFLgtTOfaADDRXgwp2x43nBGF2OYy1 X-Proofpoint-GUID: 8TKFLgtTOfaADDRXgwp2x43nBGF2OYy1 X-Authority-Analysis: v=2.4 cv=e4ELiKp/ c=1 sm=1 tr=0 ts=68e66c41 cx=c_pps a=PpDZqlmH/M8setHirZLBMw==:117 a=PpDZqlmH/M8setHirZLBMw==:17 a=x6icFKpwvdMA:10 a=IpJZQVW2AAAA:8 a=XYAwZIGsAAAA:8 a=gAnH3GRIAAAA:8 a=DUOLLnRY7vFq0fwDtzIA:9 a=IawgGOuG5U0WyFbmm1f5:22 a=E8ToXWR_bxluHZ7gmE-Z:22 a=cPQSjfK2_nFv0Q5t_7PE:22 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1117,Hydra:6.1.9,FMLib:17.12.80.40 definitions=2025-10-08_04,2025-10-06_01,2025-03-28_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 lowpriorityscore=0 impostorscore=0 suspectscore=0 adultscore=0 priorityscore=1501 clxscore=1015 phishscore=0 bulkscore=0 spamscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.19.0-2509150000 definitions=main-2510080004 Content-Type: text/plain; charset="utf-8" In setups designed for high speed data rate capture, a PWM is used to generate the CNV signal that issues data captures from the ADC. Document the use of a PWM for AD4030 and similar devices. Reviewed-by: David Lechner Acked-by: Conor Dooley Signed-off-by: Marcelo Schmitt --- Documentation/devicetree/bindings/iio/adc/adi,ad4030.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Documentation/devicetree/bindings/iio/adc/adi,ad4030.yaml b/Do= cumentation/devicetree/bindings/iio/adc/adi,ad4030.yaml index a8fee4062d0e..564b6f67a96e 100644 --- a/Documentation/devicetree/bindings/iio/adc/adi,ad4030.yaml +++ b/Documentation/devicetree/bindings/iio/adc/adi,ad4030.yaml @@ -64,6 +64,10 @@ properties: The Reset Input (/RST). Used for asynchronous device reset. maxItems: 1 =20 + pwms: + description: PWM signal connected to the CNV pin. + maxItems: 1 + interrupts: description: The BUSY pin is used to signal that the conversions results are avai= lable --=20 2.39.2 From nobody Sat Feb 7 18:46:49 2026 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 5C84A285C99; Wed, 8 Oct 2025 13:51:19 +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=1759931480; cv=none; b=KrSttHs5WsEg8wUZ98JNzJFPc7Ld0NrDbZeQULzfw42q5nFe/moSjdapwEx+XjllLSCRXGg6yOk8xIn5YA4dX30F0NKz7JH8NbaDPl/BVjI1OPCBwl2WVMsoP2kqQIp3OINOp6+QYYLDasi78+48CcM2YVafFaEvDL3XpC65mdY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759931480; c=relaxed/simple; bh=ZOJXlfsfVxJTguGRwIyBrAg8MqZ0wAQgxBl2uSeInXY=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=jT7FkJHPBS24iRSgG3IQO80f9BnVdDYJqRXFXAWeC2X0wfgyMYBYGugqPXW6VGrWdRvAZhaFCfhOYa4BGfWVGQW/RnM+kSLxdCXHq/AFV3OiZDwmjCev+jUiuoonM7BfITbbQvmAIS+qVJPmNeOXsS3D5gsLMOI4CK168rTuDsQ= 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=Xk0rJV3f; 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="Xk0rJV3f" 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 598D9EHn010582; Wed, 8 Oct 2025 09:51:15 -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=4m0Cl nXe/fyz6rYlHrdMykmJwSxMKyWpBGHQnbxEM6U=; b=Xk0rJV3fwtdtXDFoCm8Y5 RNoIEmIKZ9Kt5gn6cKIPm5FDAgZMlYiCtW1foTmdeA7qa3Nc6khpacvO/Mrch74I 29JBBzUrimqXlBOWeNzrRUlQVbR5GcArNjpo1rvnHOtUvUNFT0Y1J+yLah1ozibP rx/QIQCDVEcV2wOSlJCfaPomgI/eA0SLWcsaFSVQg6GOK9gCrHU3NhHAX8cJJoZT PENCULToRhxbKS1gYBirG+27qgD5X4AsZx8kzmh1IRIWArZDjVLJ4DQUv28D9C+d hOalsNBBReKA3JzMZ+TyuTD9FdTKFPP4pMyW4IPdT+uN6HaC4UCRT8j0G9Z2QTFn g== Received: from nwd2mta4.analog.com ([137.71.173.58]) by mx0a-00128a01.pphosted.com (PPS) with ESMTPS id 49jwe27473-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 08 Oct 2025 09:51:15 -0400 (EDT) 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 598DpEFB040455 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 8 Oct 2025 09:51:14 -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.1748.37; Wed, 8 Oct 2025 09:51:13 -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.1748.37; Wed, 8 Oct 2025 09:51:13 -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.1748.37 via Frontend Transport; Wed, 8 Oct 2025 09:51:13 -0400 Received: from work.ad.analog.com (HYB-hERzalRezfV.ad.analog.com [10.65.205.9]) by zeus.spd.analog.com (8.15.1/8.15.1) with ESMTP id 598DoxAq023162; Wed, 8 Oct 2025 09:51:01 -0400 From: Marcelo Schmitt To: , , , , , CC: , , , , , , , , , , , , "Andy Shevchenko" Subject: [PATCH v4 5/8] iio: adc: ad4030: Use BIT macro to improve code readability Date: Wed, 8 Oct 2025 10:50:58 -0300 Message-ID: X-Mailer: git-send-email 2.39.2 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=Y7n1cxeN c=1 sm=1 tr=0 ts=68e66c53 cx=c_pps a=3WNzaoukacrqR9RwcOSAdA==:117 a=3WNzaoukacrqR9RwcOSAdA==:17 a=x6icFKpwvdMA:10 a=VwQbUJbxAAAA:8 a=pGLkceISAAAA:8 a=gAnH3GRIAAAA:8 a=HwBGVG7bte8kWS4IyKsA:9 a=br55WurUj89AL1qEz8Q6:22 a=cPQSjfK2_nFv0Q5t_7PE:22 X-Proofpoint-GUID: Up5MICLt6SRSLzbKJodLVucN1ljuARGT X-Proofpoint-ORIG-GUID: Up5MICLt6SRSLzbKJodLVucN1ljuARGT X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMDA0MDA0MyBTYWx0ZWRfX2xdQ22z01zXG g36FJC2ncKqF5Q4abX4+VcPd3ZftkFusssdFLIKZakPvbg8S0R2oAJ4VxrG4/6fz3ychuOoU5VB nJpS1UahpLVurhHbOgvpDLTP9FKOgt4pKd6wdPS73MHmrF0F+1JDKapPBW39nD26TvLSDOsDVlQ WW75l2zrOkYry46ZmcYfh4SRhh1JKq1R8V/NkC439Z5gFTMNu2TSlAiMIIMD+iBdX3Wn1zYAnTq uEr0rQ8h6Gc3IdsCi1ZixSHtU/mtaKOOUIzBD3QnZr9mey2JrLkYQoO/cxi95TqxpN3dWiWDUaU lw9G1stObfNShPe6oyAbJy9z0XTAakmuEHswT35nqPFcF2uFkYYjP62P8sUaadpi7aCR4q23y9r SXA5xVz0JtyPxLp6fmPINZ3JQ9YBYg== X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1117,Hydra:6.1.9,FMLib:17.12.80.40 definitions=2025-10-08_04,2025-10-06_01,2025-03-28_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 adultscore=0 spamscore=0 bulkscore=0 lowpriorityscore=0 phishscore=0 impostorscore=0 malwarescore=0 priorityscore=1501 suspectscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.19.0-2509150000 definitions=main-2510040043 Content-Type: text/plain; charset="utf-8" Use BIT macro to make the list of average modes more readable. Suggested-by: Andy Shevchenko Link: https://lore.kernel.org/linux-iio/CAHp75Vfu-C3Hd0ZXTj4rxEgRe_O84cfo6j= iRCPFxZJnYrvROWQ@mail.gmail.com/ Signed-off-by: Marcelo Schmitt --- drivers/iio/adc/ad4030.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/iio/adc/ad4030.c b/drivers/iio/adc/ad4030.c index 4393160c7c77..b2847fd90271 100644 --- a/drivers/iio/adc/ad4030.c +++ b/drivers/iio/adc/ad4030.c @@ -233,9 +233,11 @@ struct ad4030_state { } =20 static const int ad4030_average_modes[] =3D { - 1, 2, 4, 8, 16, 32, 64, 128, - 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, - 65536, + BIT(0), /* No averaging/oversampling */ + BIT(1), BIT(2), BIT(3), BIT(4), /* 2 to 16 */ + BIT(5), BIT(6), BIT(7), BIT(8), /* 32 to 256 */ + BIT(9), BIT(10), BIT(11), BIT(12), /* 512 to 4096 */ + BIT(13), BIT(14), BIT(15), BIT(16), /* 8192 to 65536 */ }; =20 static int ad4030_enter_config_mode(struct ad4030_state *st) --=20 2.39.2 From nobody Sat Feb 7 18:46:49 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 38B10286420; Wed, 8 Oct 2025 13:51:42 +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=1759931505; cv=none; b=rMfUzgBlrqGSp2WM7ErsgyjJY/r1L9qfLATA2/3yjiJ7fHt1AUV7kA1Dzubo8TLkm+j4WXQk8VRhtvD7VVx/phaW8WKwH6d7zE+v6ysj8YyVUsT+q35iA7Xc4CGBupRPhQi72hqXwtZX9XUJCbgLqr/zqezPU5o4g84V0THLXO0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759931505; c=relaxed/simple; bh=VROJrv5MkKxmLnJ3y6XPzbj97aoVQ90BbOzNJfm3BxA=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=WVtKIrImtvxnC5b8BD5wHZlESgXLNxHMBgQLfVoV9gGkBJ3KSnfcS69TWQxVRtAm1l3qu3bKrQw/Lvvt2K89sBiT5nYVSmV+NCB5G3BFH97pFTvJjqBwIVWJgybMuvUzm+Sra5eifaK6ZuXLs+CQKPMGqMOZRBblx5LqCBx4m50= 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=ux6K8PR+; 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="ux6K8PR+" 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 598Brr9t001000; Wed, 8 Oct 2025 09:51:38 -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=YZKes R8t0pyJzF6KbUn4NbSoZJzBmPnxnEkvhM8GoN4=; b=ux6K8PR+vnWl6AyTafgG2 K52KcURtC6ILaDnirTwphje4I6UKkBi4SDJAMFps3ZCxOwvHi3EmlvNsQVgq11KH ef7ZUaueJLZSRISW3R3cYnPnyB0zObZzZA/f6JP4UrmkNzmqAgBkf9Bmvmztw4Jo EAoYoyuuJC5s56IN+GXImLntUDji3KDqMRREDUVgPCKfFonbbTWIhHktk1+CuCpF WDWTBzBURUGVbfut19k/5I9ZDm3ohP4XXYMrA0udj90+pYyIPA4fnXKdlVQkSIVc L8nxooOX6t3EHzJ9i2r7bfjwdmJQcoSBn3peWvXFs5M7xHTmNx6//ZNMhWB99Rl6 Q== Received: from nwd2mta3.analog.com ([137.71.173.56]) by mx0b-00128a01.pphosted.com (PPS) with ESMTPS id 49nkc6srds-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 08 Oct 2025 09:51:37 -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 598DpaLj034818 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 8 Oct 2025 09:51:36 -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.1748.37; Wed, 8 Oct 2025 09:51:36 -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.1748.37; Wed, 8 Oct 2025 09:51:35 -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.1748.37 via Frontend Transport; Wed, 8 Oct 2025 09:51:35 -0400 Received: from work.ad.analog.com (HYB-hERzalRezfV.ad.analog.com [10.65.205.9]) by zeus.spd.analog.com (8.15.1/8.15.1) with ESMTP id 598DpLEB023170; Wed, 8 Oct 2025 09:51:23 -0400 From: Marcelo Schmitt To: , , , , , CC: , , , , , , , , , , , , "Trevor Gamblin" , Axel Haslam Subject: [PATCH v4 6/8] iio: adc: ad4030: Add SPI offload support Date: Wed, 8 Oct 2025 10:51:20 -0300 Message-ID: <2bde211f1bc730ee147c9540b88339a93b2983e6.1759929814.git.marcelo.schmitt@analog.com> X-Mailer: git-send-email 2.39.2 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: mKAyVBKftDJm7CCayNvP0JnXuncsRQmq X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMDA4MDA0NyBTYWx0ZWRfX4b7Yyuim5T/A QWRL7NFE80mRuVD6WBaR3mnOa1pG4RFxIsJjuOLRg9U9Oa9gbxRHCXp6mYGfIDjBx2WNdS+fidh AJOhkTWaopNz4mt4ZY9sXony9BmjN4pds7wCQtRV/vP/3O20MbaYK6rrDuhSZy+VeRnte4MMBl1 Q29fcKcicpFBVGdW8BRIhoUZV6Wv4exZnZIG+MKuAtwTVbgXQhM4g0i4jJwgWkrBV5lgnzVaEXh SOJ4wnCfT+ofkf5gotD3NxXNdHg6lI6A3tBwPnNb//bf1u1P69gCCfitNwz6ao72Uzdf1qdUIz1 92iRLzigPQBWb2oOl54azzQrsa0pcY5o8xwEEhv2H4moq8zF3qsFSmAVQWSlGGwHcGtUDV4+ASA ZiOxl3zjedwyRXQ19oYhBSefSXuQaw== X-Proofpoint-ORIG-GUID: mKAyVBKftDJm7CCayNvP0JnXuncsRQmq X-Authority-Analysis: v=2.4 cv=CMInnBrD c=1 sm=1 tr=0 ts=68e66c69 cx=c_pps a=PpDZqlmH/M8setHirZLBMw==:117 a=PpDZqlmH/M8setHirZLBMw==:17 a=x6icFKpwvdMA:10 a=IpJZQVW2AAAA:8 a=gAnH3GRIAAAA:8 a=9Nk0bTxa6Lcm4eBWZcIA:9 a=IawgGOuG5U0WyFbmm1f5:22 a=cPQSjfK2_nFv0Q5t_7PE:22 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1117,Hydra:6.1.9,FMLib:17.12.80.40 definitions=2025-10-08_04,2025-10-06_01,2025-03-28_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 clxscore=1015 adultscore=0 malwarescore=0 bulkscore=0 lowpriorityscore=0 priorityscore=1501 spamscore=0 impostorscore=0 phishscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.19.0-2509150000 definitions=main-2510080047 Content-Type: text/plain; charset="utf-8" AD4030 and similar ADCs can capture data at sample rates up to 2 mega samples per second (MSPS). Not all SPI controllers are able to achieve such high throughputs and even when the controller is fast enough to run transfers at the required speed, it may be costly to the CPU to handle transfer data at such high sample rates. Add SPI offload support for AD4030 and similar ADCs to enable data capture at maximum sample rates. Co-developed-by: Trevor Gamblin Signed-off-by: Trevor Gamblin Co-developed-by: Axel Haslam Signed-off-by: Axel Haslam Signed-off-by: Marcelo Schmitt --- Change log v3 -> v4 - Applied code adjustments suggested to SPI offload patch. - Only select SPI_OFFLOAD_TRIGGER_PWM if (SPI_OFFLOAD && PWM). drivers/iio/adc/Kconfig | 3 + drivers/iio/adc/ad4030.c | 504 +++++++++++++++++++++++++++++++++++---- 2 files changed, 465 insertions(+), 42 deletions(-) diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig index 58a14e6833f6..1ed091b6731a 100644 --- a/drivers/iio/adc/Kconfig +++ b/drivers/iio/adc/Kconfig @@ -62,7 +62,10 @@ config AD4030 depends on GPIOLIB select REGMAP select IIO_BUFFER + select IIO_BUFFER_DMA + select IIO_BUFFER_DMAENGINE select IIO_TRIGGERED_BUFFER + select SPI_OFFLOAD_TRIGGER_PWM if (SPI_OFFLOAD && PWM) help Say yes here to build support for Analog Devices AD4030 and AD4630 high= speed SPI analog to digital converters (ADC). diff --git a/drivers/iio/adc/ad4030.c b/drivers/iio/adc/ad4030.c index b2847fd90271..bbadcda8df77 100644 --- a/drivers/iio/adc/ad4030.c +++ b/drivers/iio/adc/ad4030.c @@ -14,15 +14,25 @@ */ =20 #include +#include #include +#include +#include #include #include #include +#include +#include +#include +#include +#include #include #include +#include #include #include #include +#include =20 #define AD4030_REG_INTERFACE_CONFIG_A 0x00 #define AD4030_REG_INTERFACE_CONFIG_A_SW_RESET (BIT(0) | BIT(7)) @@ -111,6 +121,8 @@ #define AD4632_TCYC_NS 2000 #define AD4632_TCYC_ADJUSTED_NS (AD4632_TCYC_NS - AD4030_TCNVL_NS) #define AD4030_TRESET_COM_DELAY_MS 750 +/* Datasheet says 9.8ns, so use the closest integer value */ +#define AD4030_TQUIET_CNV_DELAY_NS 10 =20 enum ad4030_out_mode { AD4030_OUT_DATA_MD_DIFF, @@ -136,11 +148,13 @@ struct ad4030_chip_info { const char *name; const unsigned long *available_masks; const struct iio_chan_spec channels[AD4030_MAX_IIO_CHANNEL_NB]; + const struct iio_chan_spec offload_channels[AD4030_MAX_IIO_CHANNEL_NB]; u8 grade; u8 precision_bits; /* Number of hardware channels */ int num_voltage_inputs; unsigned int tcyc_ns; + unsigned int max_sample_rate_hz; }; =20 struct ad4030_state { @@ -153,6 +167,14 @@ struct ad4030_state { int offset_avail[3]; unsigned int avg_log2; enum ad4030_out_mode mode; + /* Offload sampling */ + struct spi_transfer offload_xfer; + struct spi_message offload_msg; + struct spi_offload *offload; + struct spi_offload_trigger *offload_trigger; + struct spi_offload_trigger_config offload_trigger_config; + struct pwm_device *cnv_trigger; + struct pwm_waveform cnv_wf; =20 /* * DMA (thus cache coherency maintenance) requires the transfer buffers @@ -209,8 +231,9 @@ struct ad4030_state { * - voltage0-voltage1 * - voltage2-voltage3 */ -#define AD4030_CHAN_DIFF(_idx, _scan_type) { \ +#define __AD4030_CHAN_DIFF(_idx, _scan_type, _offload) { \ .info_mask_shared_by_all =3D \ + (_offload ? BIT(IIO_CHAN_INFO_SAMP_FREQ) : 0) | \ BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), \ .info_mask_shared_by_all_available =3D \ BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), \ @@ -232,6 +255,12 @@ struct ad4030_state { .num_ext_scan_type =3D ARRAY_SIZE(_scan_type), \ } =20 +#define AD4030_CHAN_DIFF(_idx, _scan_type) \ + __AD4030_CHAN_DIFF(_idx, _scan_type, 0) + +#define AD4030_OFFLOAD_CHAN_DIFF(_idx, _scan_type) \ + __AD4030_CHAN_DIFF(_idx, _scan_type, 1) + static const int ad4030_average_modes[] =3D { BIT(0), /* No averaging/oversampling */ BIT(1), BIT(2), BIT(3), BIT(4), /* 2 to 16 */ @@ -240,6 +269,11 @@ static const int ad4030_average_modes[] =3D { BIT(13), BIT(14), BIT(15), BIT(16), /* 8192 to 65536 */ }; =20 +static const struct spi_offload_config ad4030_offload_config =3D { + .capability_flags =3D SPI_OFFLOAD_CAP_TRIGGER | + SPI_OFFLOAD_CAP_RX_STREAM_DMA, +}; + static int ad4030_enter_config_mode(struct ad4030_state *st) { st->tx_data[0] =3D AD4030_REG_ACCESS; @@ -453,6 +487,107 @@ static int ad4030_get_chan_calibbias(struct iio_dev *= indio_dev, } } =20 +static void ad4030_get_sampling_freq(struct ad4030_state *st, int *freq) +{ + struct spi_offload_trigger_config *config =3D &st->offload_trigger_config; + + /* + * Conversion data is fetched from the device when the offload transfer + * is triggered. Thus, provide the SPI offload trigger frequency as the + * sampling frequency. + */ + *freq =3D config->periodic.frequency_hz; +} + +static int ad4030_update_conversion_rate(struct ad4030_state *st, + unsigned int freq, unsigned int avg_log2) +{ + struct spi_offload_trigger_config *config =3D &st->offload_trigger_config; + struct pwm_waveform cnv_wf =3D { }; + u64 target =3D AD4030_TCNVH_NS; + u64 offload_period_ns; + u64 offload_offset_ns; + int ret; + + /* + * When averaging/oversampling over N samples, we fire the offload + * trigger once at every N pulses of the CNV signal. Conversely, the CNV + * signal needs to be N times faster than the offload trigger. Take that + * into account to correctly re-evaluate both the PWM waveform connected + * to CNV and the SPI offload trigger. + */ + freq <<=3D avg_log2; + + cnv_wf.period_length_ns =3D DIV_ROUND_CLOSEST(NSEC_PER_SEC, freq); + /* + * The datasheet lists a minimum time of 9.8 ns, but no maximum. If the + * rounded PWM's value is less than 10, increase the target value by 10 + * and attempt to round the waveform again, until the value is at least + * 10 ns. Use a separate variable to represent the target in case the + * rounding is severe enough to keep putting the first few results under + * the minimum 10ns condition checked by the while loop. + */ + do { + cnv_wf.duty_length_ns =3D target; + ret =3D pwm_round_waveform_might_sleep(st->cnv_trigger, &cnv_wf); + if (ret) + return ret; + target +=3D AD4030_TCNVH_NS; + } while (cnv_wf.duty_length_ns < AD4030_TCNVH_NS); + + if (!in_range(cnv_wf.period_length_ns, AD4030_TCYC_NS, INT_MAX)) + return -EINVAL; + + offload_period_ns =3D cnv_wf.period_length_ns; + /* + * Make the offload trigger period be N times longer than the CNV PWM + * period when averaging over N samples. + */ + offload_period_ns <<=3D avg_log2; + + config->periodic.frequency_hz =3D DIV_ROUND_UP_ULL(NSEC_PER_SEC, + offload_period_ns); + + /* + * The hardware does the capture on zone 2 (when SPI trigger PWM + * is used). This means that the SPI trigger signal should happen at + * tsync + tquiet_con_delay being tsync the conversion signal period + * and tquiet_con_delay 9.8ns. Hence set the PWM phase accordingly. + * + * The PWM waveform API only supports nanosecond resolution right now, + * so round this setting to the closest available value. + */ + offload_offset_ns =3D AD4030_TQUIET_CNV_DELAY_NS; + do { + config->periodic.offset_ns =3D offload_offset_ns; + ret =3D spi_offload_trigger_validate(st->offload_trigger, config); + if (ret) + return ret; + offload_offset_ns +=3D AD4030_TQUIET_CNV_DELAY_NS; + } while (config->periodic.offset_ns < AD4030_TQUIET_CNV_DELAY_NS); + + st->cnv_wf =3D cnv_wf; + + return 0; +} + +static int ad4030_set_sampling_freq(struct iio_dev *indio_dev, int freq) +{ + struct ad4030_state *st =3D iio_priv(indio_dev); + + /* + * We have no control over the sampling frequency without SPI offload + * triggering. + */ + if (!st->offload_trigger) + return -ENODEV; + + if (!in_range(freq, 1, st->chip->max_sample_rate_hz)) + return -EINVAL; + + return ad4030_update_conversion_rate(st, freq, st->avg_log2); +} + static int ad4030_set_chan_calibscale(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int gain_int, @@ -507,27 +642,6 @@ static int ad4030_set_chan_calibbias(struct iio_dev *i= ndio_dev, st->tx_data, AD4030_REG_OFFSET_BYTES_NB); } =20 -static int ad4030_set_avg_frame_len(struct iio_dev *dev, int avg_val) -{ - struct ad4030_state *st =3D iio_priv(dev); - unsigned int avg_log2 =3D ilog2(avg_val); - unsigned int last_avg_idx =3D ARRAY_SIZE(ad4030_average_modes) - 1; - int ret; - - if (avg_val < 0 || avg_val > ad4030_average_modes[last_avg_idx]) - return -EINVAL; - - ret =3D regmap_write(st->regmap, AD4030_REG_AVG, - AD4030_REG_AVG_MASK_AVG_SYNC | - FIELD_PREP(AD4030_REG_AVG_MASK_AVG_VAL, avg_log2)); - if (ret) - return ret; - - st->avg_log2 =3D avg_log2; - - return 0; -} - static bool ad4030_is_common_byte_asked(struct ad4030_state *st, unsigned int mask) { @@ -536,11 +650,10 @@ static bool ad4030_is_common_byte_asked(struct ad4030= _state *st, AD4030_DUAL_COMMON_BYTE_CHANNELS_MASK); } =20 -static int ad4030_set_mode(struct iio_dev *indio_dev, unsigned long mask) +static int ad4030_set_mode(struct ad4030_state *st, unsigned long mask, + unsigned int avg_log2) { - struct ad4030_state *st =3D iio_priv(indio_dev); - - if (st->avg_log2 > 0) { + if (avg_log2 > 0) { st->mode =3D AD4030_OUT_DATA_MD_30_AVERAGED_DIFF; } else if (ad4030_is_common_byte_asked(st, mask)) { switch (st->chip->precision_bits) { @@ -564,6 +677,49 @@ static int ad4030_set_mode(struct iio_dev *indio_dev, = unsigned long mask) st->mode); } =20 +static int ad4030_set_avg_frame_len(struct iio_dev *dev, unsigned long mas= k, int avg_val) +{ + struct ad4030_state *st =3D iio_priv(dev); + unsigned int avg_log2 =3D ilog2(avg_val); + unsigned int last_avg_idx =3D ARRAY_SIZE(ad4030_average_modes) - 1; + int freq; + int ret; + + if (avg_val < 0 || avg_val > ad4030_average_modes[last_avg_idx]) + return -EINVAL; + + ret =3D ad4030_set_mode(st, mask, avg_log2); + if (ret) + return ret; + + if (st->offload_trigger) { + /* + * The sample averaging and sampling frequency configurations + * are mutually dependent one from another. That's because the + * effective data sample rate is fCNV / 2^N, where N is the + * number of samples being averaged. + * + * When SPI offload is supported and we have control over the + * sample rate, the conversion start signal (CNV) and the SPI + * offload trigger frequencies must be re-evaluated so data is + * fetched only after 'avg_val' conversions. + */ + ad4030_get_sampling_freq(st, &freq); + ret =3D ad4030_update_conversion_rate(st, freq, avg_log2); + if (ret) + return ret; + } + + ret =3D regmap_write(st->regmap, AD4030_REG_AVG, + AD4030_REG_AVG_MASK_AVG_SYNC | + FIELD_PREP(AD4030_REG_AVG_MASK_AVG_VAL, avg_log2)); + if (ret) + return ret; + + st->avg_log2 =3D avg_log2; + return 0; +} + /* * Descramble 2 32bits numbers out of a 64bits. The bits are interleaved: * 1 bit for first number, 1 bit for the second, and so on... @@ -672,7 +828,7 @@ static int ad4030_single_conversion(struct iio_dev *ind= io_dev, struct ad4030_state *st =3D iio_priv(indio_dev); int ret; =20 - ret =3D ad4030_set_mode(indio_dev, BIT(chan->scan_index)); + ret =3D ad4030_set_mode(st, BIT(chan->scan_index), st->avg_log2); if (ret) return ret; =20 @@ -769,6 +925,13 @@ static int ad4030_read_raw_dispatch(struct iio_dev *in= dio_dev, *val =3D BIT(st->avg_log2); return IIO_VAL_INT; =20 + case IIO_CHAN_INFO_SAMP_FREQ: + if (!st->offload_trigger) + return -ENODEV; + + ad4030_get_sampling_freq(st, val); + return IIO_VAL_INT; + default: return -EINVAL; } @@ -807,7 +970,10 @@ static int ad4030_write_raw_dispatch(struct iio_dev *i= ndio_dev, return ad4030_set_chan_calibbias(indio_dev, chan, val); =20 case IIO_CHAN_INFO_OVERSAMPLING_RATIO: - return ad4030_set_avg_frame_len(indio_dev, val); + return ad4030_set_avg_frame_len(indio_dev, BIT(chan->scan_index), val); + + case IIO_CHAN_INFO_SAMP_FREQ: + return ad4030_set_sampling_freq(indio_dev, val); =20 default: return -EINVAL; @@ -869,7 +1035,11 @@ static int ad4030_get_current_scan_type(const struct = iio_dev *indio_dev, static int ad4030_update_scan_mode(struct iio_dev *indio_dev, const unsigned long *scan_mask) { - return ad4030_set_mode(indio_dev, *scan_mask); + struct ad4030_state *st =3D iio_priv(indio_dev); + + //return ad4030_set_mode(st, *scan_mask, st->avg_log2); + //return ad4030_set_mode(iio_priv(indio_dev), &scan_mask, st->avg_log2); + return ad4030_set_mode(iio_priv(indio_dev), *scan_mask, st->avg_log2); } =20 static const struct iio_info ad4030_iio_info =3D { @@ -898,6 +1068,108 @@ static const struct iio_buffer_setup_ops ad4030_buff= er_setup_ops =3D { .validate_scan_mask =3D ad4030_validate_scan_mask, }; =20 +static void ad4030_prepare_offload_msg(struct iio_dev *indio_dev) +{ + struct ad4030_state *st =3D iio_priv(indio_dev); + u8 offload_bpw; + + if (st->mode =3D=3D AD4030_OUT_DATA_MD_30_AVERAGED_DIFF) { + offload_bpw =3D 32; + } else { + offload_bpw =3D st->chip->precision_bits; + offload_bpw +=3D (st->mode =3D=3D AD4030_OUT_DATA_MD_24_DIFF_8_COM || + st->mode =3D=3D AD4030_OUT_DATA_MD_16_DIFF_8_COM) ? 8 : 0; + } + + st->offload_xfer.bits_per_word =3D offload_bpw; + st->offload_xfer.len =3D spi_bpw_to_bytes(offload_bpw); + st->offload_xfer.offload_flags =3D SPI_OFFLOAD_XFER_RX_STREAM; + spi_message_init_with_transfers(&st->offload_msg, &st->offload_xfer, 1); +} + +static int ad4030_offload_buffer_postenable(struct iio_dev *indio_dev) +{ + struct ad4030_state *st =3D iio_priv(indio_dev); + unsigned int reg_modes; + int ret, ret2; + + /* + * When data from 2 analog input channels is output through a single + * bus line (interleaved mode (LANE_MD =3D=3D 0b11)) and gets pushed thro= ugh + * DMA, extra hardware is required to do the de-interleaving. While we + * don't support such hardware configurations, disallow interleaved mode + * when using SPI offload. + */ + ret =3D regmap_read(st->regmap, AD4030_REG_MODES, ®_modes); + if (ret) + return ret; + + if (st->chip->num_voltage_inputs > 1 && + FIELD_GET(AD4030_REG_MODES_MASK_LANE_MODE, reg_modes) =3D=3D AD4030_L= ANE_MD_INTERLEAVED) + return -EINVAL; + + ret =3D regmap_write(st->regmap, AD4030_REG_EXIT_CFG_MODE, BIT(0)); + if (ret) + return ret; + + ad4030_prepare_offload_msg(indio_dev); + st->offload_msg.offload =3D st->offload; + ret =3D spi_optimize_message(st->spi, &st->offload_msg); + if (ret) + goto out_reset_mode; + + ret =3D pwm_set_waveform_might_sleep(st->cnv_trigger, &st->cnv_wf, false); + if (ret) + goto out_unoptimize; + + ret =3D spi_offload_trigger_enable(st->offload, st->offload_trigger, + &st->offload_trigger_config); + if (ret) + goto out_pwm_disable; + + return 0; + +out_pwm_disable: + pwm_disable(st->cnv_trigger); +out_unoptimize: + spi_unoptimize_message(&st->offload_msg); +out_reset_mode: + /* reenter register configuration mode */ + ret2 =3D ad4030_enter_config_mode(st); + if (ret2) + dev_err(&st->spi->dev, + "couldn't reenter register configuration mode: %d\n", + ret2); + + return ret; +} + +static int ad4030_offload_buffer_predisable(struct iio_dev *indio_dev) +{ + struct ad4030_state *st =3D iio_priv(indio_dev); + int ret; + + spi_offload_trigger_disable(st->offload, st->offload_trigger); + + pwm_disable(st->cnv_trigger); + + spi_unoptimize_message(&st->offload_msg); + + /* reenter register configuration mode */ + ret =3D ad4030_enter_config_mode(st); + if (ret) + dev_err(&st->spi->dev, + "couldn't reenter register configuration mode\n"); + + return ret; +} + +static const struct iio_buffer_setup_ops ad4030_offload_buffer_setup_ops = =3D { + .postenable =3D &ad4030_offload_buffer_postenable, + .predisable =3D &ad4030_offload_buffer_predisable, + .validate_scan_mask =3D ad4030_validate_scan_mask, +}; + static int ad4030_regulators_get(struct ad4030_state *st) { struct device *dev =3D &st->spi->dev; @@ -967,6 +1239,24 @@ static int ad4030_detect_chip_info(const struct ad403= 0_state *st) return 0; } =20 +static int ad4030_pwm_get(struct ad4030_state *st) +{ + struct device *dev =3D &st->spi->dev; + + st->cnv_trigger =3D devm_pwm_get(dev, NULL); + if (IS_ERR(st->cnv_trigger)) + return dev_err_probe(dev, PTR_ERR(st->cnv_trigger), + "Failed to get CNV PWM\n"); + + /* + * Preemptively disable the PWM, since we only want to enable it with + * the buffer. + */ + pwm_disable(st->cnv_trigger); + + return 0; +} + static int ad4030_config(struct ad4030_state *st) { int ret; @@ -994,6 +1284,31 @@ static int ad4030_config(struct ad4030_state *st) return 0; } =20 +static int ad4030_spi_offload_setup(struct iio_dev *indio_dev, + struct ad4030_state *st) +{ + struct device *dev =3D &st->spi->dev; + struct dma_chan *rx_dma; + + indio_dev->setup_ops =3D &ad4030_offload_buffer_setup_ops; + + st->offload_trigger =3D devm_spi_offload_trigger_get(dev, st->offload, + SPI_OFFLOAD_TRIGGER_PERIODIC); + if (IS_ERR(st->offload_trigger)) + return dev_err_probe(dev, PTR_ERR(st->offload_trigger), + "failed to get offload trigger\n"); + + st->offload_trigger_config.type =3D SPI_OFFLOAD_TRIGGER_PERIODIC; + + rx_dma =3D devm_spi_offload_rx_stream_request_dma_chan(dev, st->offload); + if (IS_ERR(rx_dma)) + return dev_err_probe(dev, PTR_ERR(rx_dma), + "failed to get offload RX DMA\n"); + + return devm_iio_dmaengine_buffer_setup_with_handle(dev, indio_dev, rx_dma, + IIO_BUFFER_DIRECTION_IN); +} + static int ad4030_probe(struct spi_device *spi) { struct device *dev =3D &spi->dev; @@ -1045,24 +1360,61 @@ static int ad4030_probe(struct spi_device *spi) return dev_err_probe(dev, PTR_ERR(st->cnv_gpio), "Failed to get cnv gpio\n"); =20 - /* - * One hardware channel is split in two software channels when using - * common byte mode. Add one more channel for the timestamp. - */ - indio_dev->num_channels =3D 2 * st->chip->num_voltage_inputs + 1; indio_dev->name =3D st->chip->name; indio_dev->modes =3D INDIO_DIRECT_MODE; indio_dev->info =3D &ad4030_iio_info; - indio_dev->channels =3D st->chip->channels; indio_dev->available_scan_masks =3D st->chip->available_masks; =20 - ret =3D devm_iio_triggered_buffer_setup(dev, indio_dev, - iio_pollfunc_store_time, - ad4030_trigger_handler, - &ad4030_buffer_setup_ops); - if (ret) - return dev_err_probe(dev, ret, - "Failed to setup triggered buffer\n"); + st->offload =3D devm_spi_offload_get(dev, spi, &ad4030_offload_config); + ret =3D PTR_ERR_OR_ZERO(st->offload); + if (ret && ret !=3D -ENODEV) + return dev_err_probe(dev, ret, "failed to get offload\n"); + + /* Fall back to low speed usage when no SPI offload is available. */ + if (ret =3D=3D -ENODEV) { + /* + * One hardware channel is split in two software channels when + * using common byte mode. Add one more channel for the timestamp. + */ + indio_dev->num_channels =3D 2 * st->chip->num_voltage_inputs + 1; + indio_dev->channels =3D st->chip->channels; + + ret =3D devm_iio_triggered_buffer_setup(dev, indio_dev, + iio_pollfunc_store_time, + ad4030_trigger_handler, + &ad4030_buffer_setup_ops); + if (ret) + return dev_err_probe(dev, ret, + "Failed to setup triggered buffer\n"); + } else { + /* + * One hardware channel is split in two software channels when + * using common byte mode. Offloaded SPI transfers can't support + * software timestamp so no additional timestamp channel is added. + */ + indio_dev->num_channels =3D 2 * st->chip->num_voltage_inputs; + indio_dev->channels =3D st->chip->offload_channels; + ret =3D ad4030_spi_offload_setup(indio_dev, st); + if (ret) + return dev_err_probe(dev, ret, + "Failed to setup SPI offload\n"); + + ret =3D ad4030_pwm_get(st); + if (ret) + return dev_err_probe(&spi->dev, ret, + "Failed to get PWM: %d\n", ret); + + /* + * Start with a slower sampling rate so there is some room for + * adjusting the sample averaging and the sampling frequency + * without hitting the maximum conversion rate. + */ + ret =3D ad4030_update_conversion_rate(st, st->chip->max_sample_rate_hz >= > 4, + st->avg_log2); + if (ret) + return dev_err_probe(&spi->dev, ret, + "Failed to set offload samp freq\n"); + } =20 return devm_iio_device_register(dev, indio_dev); } @@ -1100,6 +1452,23 @@ static const struct iio_scan_type ad4030_24_scan_typ= es[] =3D { }, }; =20 +static const struct iio_scan_type ad4030_24_offload_scan_types[] =3D { + [AD4030_SCAN_TYPE_NORMAL] =3D { + .sign =3D 's', + .storagebits =3D 32, + .realbits =3D 24, + .shift =3D 0, + .endianness =3D IIO_CPU, + }, + [AD4030_SCAN_TYPE_AVG] =3D { + .sign =3D 's', + .storagebits =3D 32, + .realbits =3D 30, + .shift =3D 2, + .endianness =3D IIO_CPU, + }, +}; + static const struct iio_scan_type ad4030_16_scan_types[] =3D { [AD4030_SCAN_TYPE_NORMAL] =3D { .sign =3D 's', @@ -1117,6 +1486,23 @@ static const struct iio_scan_type ad4030_16_scan_typ= es[] =3D { } }; =20 +static const struct iio_scan_type ad4030_16_offload_scan_types[] =3D { + [AD4030_SCAN_TYPE_NORMAL] =3D { + .sign =3D 's', + .storagebits =3D 32, + .realbits =3D 16, + .shift =3D 0, + .endianness =3D IIO_CPU, + }, + [AD4030_SCAN_TYPE_AVG] =3D { + .sign =3D 's', + .storagebits =3D 32, + .realbits =3D 30, + .shift =3D 2, + .endianness =3D IIO_CPU, + }, +}; + static const struct ad4030_chip_info ad4030_24_chip_info =3D { .name =3D "ad4030-24", .available_masks =3D ad4030_channel_masks, @@ -1125,10 +1511,15 @@ static const struct ad4030_chip_info ad4030_24_chip= _info =3D { AD4030_CHAN_CMO(1, 0), IIO_CHAN_SOFT_TIMESTAMP(2), }, + .offload_channels =3D { + AD4030_OFFLOAD_CHAN_DIFF(0, ad4030_24_offload_scan_types), + AD4030_CHAN_CMO(1, 0), + }, .grade =3D AD4030_REG_CHIP_GRADE_AD4030_24_GRADE, .precision_bits =3D 24, .num_voltage_inputs =3D 1, .tcyc_ns =3D AD4030_TCYC_ADJUSTED_NS, + .max_sample_rate_hz =3D 2 * HZ_PER_MHZ, }; =20 static const struct ad4030_chip_info ad4630_16_chip_info =3D { @@ -1141,10 +1532,17 @@ static const struct ad4030_chip_info ad4630_16_chip= _info =3D { AD4030_CHAN_CMO(3, 1), IIO_CHAN_SOFT_TIMESTAMP(4), }, + .offload_channels =3D { + AD4030_OFFLOAD_CHAN_DIFF(0, ad4030_16_offload_scan_types), + AD4030_OFFLOAD_CHAN_DIFF(1, ad4030_16_offload_scan_types), + AD4030_CHAN_CMO(2, 0), + AD4030_CHAN_CMO(3, 1), + }, .grade =3D AD4030_REG_CHIP_GRADE_AD4630_16_GRADE, .precision_bits =3D 16, .num_voltage_inputs =3D 2, .tcyc_ns =3D AD4030_TCYC_ADJUSTED_NS, + .max_sample_rate_hz =3D 2 * HZ_PER_MHZ, }; =20 static const struct ad4030_chip_info ad4630_24_chip_info =3D { @@ -1157,10 +1555,17 @@ static const struct ad4030_chip_info ad4630_24_chip= _info =3D { AD4030_CHAN_CMO(3, 1), IIO_CHAN_SOFT_TIMESTAMP(4), }, + .offload_channels =3D { + AD4030_OFFLOAD_CHAN_DIFF(0, ad4030_24_offload_scan_types), + AD4030_OFFLOAD_CHAN_DIFF(1, ad4030_24_offload_scan_types), + AD4030_CHAN_CMO(2, 0), + AD4030_CHAN_CMO(3, 1), + }, .grade =3D AD4030_REG_CHIP_GRADE_AD4630_24_GRADE, .precision_bits =3D 24, .num_voltage_inputs =3D 2, .tcyc_ns =3D AD4030_TCYC_ADJUSTED_NS, + .max_sample_rate_hz =3D 2 * HZ_PER_MHZ, }; =20 static const struct ad4030_chip_info ad4632_16_chip_info =3D { @@ -1173,10 +1578,17 @@ static const struct ad4030_chip_info ad4632_16_chip= _info =3D { AD4030_CHAN_CMO(3, 1), IIO_CHAN_SOFT_TIMESTAMP(4), }, + .offload_channels =3D { + AD4030_OFFLOAD_CHAN_DIFF(0, ad4030_16_offload_scan_types), + AD4030_OFFLOAD_CHAN_DIFF(1, ad4030_16_offload_scan_types), + AD4030_CHAN_CMO(2, 0), + AD4030_CHAN_CMO(3, 1), + }, .grade =3D AD4030_REG_CHIP_GRADE_AD4632_16_GRADE, .precision_bits =3D 16, .num_voltage_inputs =3D 2, .tcyc_ns =3D AD4632_TCYC_ADJUSTED_NS, + .max_sample_rate_hz =3D 500 * HZ_PER_KHZ, }; =20 static const struct ad4030_chip_info ad4632_24_chip_info =3D { @@ -1189,10 +1601,17 @@ static const struct ad4030_chip_info ad4632_24_chip= _info =3D { AD4030_CHAN_CMO(3, 1), IIO_CHAN_SOFT_TIMESTAMP(4), }, + .offload_channels =3D { + AD4030_OFFLOAD_CHAN_DIFF(0, ad4030_24_offload_scan_types), + AD4030_OFFLOAD_CHAN_DIFF(1, ad4030_24_offload_scan_types), + AD4030_CHAN_CMO(2, 0), + AD4030_CHAN_CMO(3, 1), + }, .grade =3D AD4030_REG_CHIP_GRADE_AD4632_24_GRADE, .precision_bits =3D 24, .num_voltage_inputs =3D 2, .tcyc_ns =3D AD4632_TCYC_ADJUSTED_NS, + .max_sample_rate_hz =3D 500 * HZ_PER_KHZ, }; =20 static const struct spi_device_id ad4030_id_table[] =3D { @@ -1228,3 +1647,4 @@ module_spi_driver(ad4030_driver); MODULE_AUTHOR("Esteban Blanc "); MODULE_DESCRIPTION("Analog Devices AD4630 ADC family driver"); MODULE_LICENSE("GPL"); +MODULE_IMPORT_NS("IIO_DMAENGINE_BUFFER"); --=20 2.39.2 From nobody Sat Feb 7 18:46:49 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 A977F286420; Wed, 8 Oct 2025 13:52: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=1759931535; cv=none; b=jZN++GBc15BiX4Y/XGO8ST1Yde9w6kUdhAoxlbhw4rOR95eshZBM4eYyl+S+VqN4aMsP/BoGuT1ZeKc+D7H1PQtoy05vsMYHzaf0qO85Yzzg02yMO6SvEZBRAnTCOEmIeeNyTl+Rap2MIOglakmQVN53+dRBTZo/nVP1zxOqN8Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759931535; c=relaxed/simple; bh=ugGL3yiaxZpg+452nHetHLkQw2QDEFYdeGY+4CIzkQo=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=RzSkXM/aN18mqvwV0fNdq4qxLgC+Es9oje9LyA6MNywfTXY6Sn8QEkwHs8/LL64ANPf2OiAGC5GMBxPF6188P52V3z1SDnOrq+WKMX8IY8SPI/hQGzBRLDbs9dGPCwRXbz+d54l2CdR1vKicPVmOFWyCjDcYHoqoFs3zH8lcoGs= 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=EDMlE1uc; 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="EDMlE1uc" 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 598BXgvi001077; Wed, 8 Oct 2025 09:52:08 -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=t90ZX zDw7q407kvn9IxTpa85fORT6/7Jie1q8Cpl8+E=; b=EDMlE1ucY7WIVDQK1C2zw Wrx3rOA5hQlx8kDCYaM5VxeViSTQEl6Tjj8EhQDNQusz48ecyij/qnEWAzWDTGa8 xBHyU30lRFW72kKz1KsgwCJwMwGvtEbsj8zrskbroDVvSqe8rgGHiWbQ6VrRJpTI f5T6Lu4VgZQOQvbOOX7iPCd9fk0fT2JN2JNNLC5EzvMuvH8fWmYWE83Epj73JNAN Ep1ZF3tdpv9A2VqW2QCzPXv6rvayQuRdlwvYaBtO+xd+5j11uRpHwtg22LizIqGc osP9S8MnLeczl1pdJhlK6yqpZqCV953ZQHyKqmWs5HPkDitctHDNvSotJcBlyQ4e Q== Received: from nwd2mta3.analog.com ([137.71.173.56]) by mx0b-00128a01.pphosted.com (PPS) with ESMTPS id 49nkc6srfd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 08 Oct 2025 09:52:07 -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 598Dq6KT034871 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 8 Oct 2025 09:52:06 -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.1748.37; Wed, 8 Oct 2025 09:52:06 -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.1748.37; Wed, 8 Oct 2025 09:51:52 -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.1748.37 via Frontend Transport; Wed, 8 Oct 2025 09:51:52 -0400 Received: from work.ad.analog.com (HYB-hERzalRezfV.ad.analog.com [10.65.205.9]) by zeus.spd.analog.com (8.15.1/8.15.1) with ESMTP id 598DpbQs023318; Wed, 8 Oct 2025 09:51:40 -0400 From: Marcelo Schmitt To: , , , , , CC: , , , , , , , , , , , Subject: [PATCH v4 7/8] dt-bindings: iio: adc: adi,ad4030: Add ADAQ4216 and ADAQ4224 Date: Wed, 8 Oct 2025 10:51:37 -0300 Message-ID: <7e51e036ba930284c74cf42afd53b17d49093654.1759929814.git.marcelo.schmitt@analog.com> X-Mailer: git-send-email 2.39.2 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: jtFawrqp0Vb72DWeS4R7EFZ6tb-V2Q1r X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMDA4MDA0NyBTYWx0ZWRfXzHEooKbjmzQR fVuvG/QE5j78QFhqZzSFBOTPpxvtUj2x8h0NUa1VcOxrb9MLSj5bs+0eLGpchNLJTetY4DBlG3T FAcnn8kLKzi1nSp+nby+i7AHpJGvtB62GlhdpATo/EyP//BW8aL/3jWuOcyHkVLxKnq1n7RmBIN eT72cvl1aG7M61CepAFkDFX1NxFzMyGQBIhmHitqGnRSO9qe2QD1eBXFpekf50BpEINQKCiA9Dh 1xbKarU3p3vngs2FjnEqlt21vpDBXihKPSlwPceSY1bM8kVRs1u5q8nMOBWeh0fdjsmX9ANmtKe bVek6Ml4aSeCHTSxG9Bp+z6dN7JKqC2gKzcHiPq3YyyXmqOmIvbPncZCvnn719Giwk7/248szop Qc4zajELSs5mKe5e4nwq1cqbcxlS9w== X-Proofpoint-ORIG-GUID: jtFawrqp0Vb72DWeS4R7EFZ6tb-V2Q1r X-Authority-Analysis: v=2.4 cv=CMInnBrD c=1 sm=1 tr=0 ts=68e66c88 cx=c_pps a=PpDZqlmH/M8setHirZLBMw==:117 a=PpDZqlmH/M8setHirZLBMw==:17 a=x6icFKpwvdMA:10 a=VwQbUJbxAAAA:8 a=pGLkceISAAAA:8 a=gAnH3GRIAAAA:8 a=0XOC81FH8jXXWHuWOY0A:9 a=cPQSjfK2_nFv0Q5t_7PE:22 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1117,Hydra:6.1.9,FMLib:17.12.80.40 definitions=2025-10-08_04,2025-10-06_01,2025-03-28_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 clxscore=1015 adultscore=0 malwarescore=0 bulkscore=0 lowpriorityscore=0 priorityscore=1501 spamscore=0 impostorscore=0 phishscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.19.0-2509150000 definitions=main-2510080047 Content-Type: text/plain; charset="utf-8" ADAQ4216 and ADAQ4224 are similar to AD4030 except that ADAQ devices have a PGA (programmable gain amplifier) that scales the input signal prior to it reaching the ADC inputs. The PGA is controlled through a couple of pins (A0 and A1) that set one of four possible signal gain configurations. Signed-off-by: Marcelo Schmitt --- Change log v3 -> v4 - Now only documenting GPIO setup to control ADAQ PGA pins. Pin strapped/hardwired connections to PGA pins may benefit from a "fixed-gp= ios" driver which may (or may not?) use the shared GPIO abstraction layer [1]. I= may propose support for pin-strapped/hardwired connections when I get a working fixed-gpios implementation. [1]: https://lore.kernel.org/linux-gpio/CAMRc=3DMdb_cUG+hKq8GyfUP1SYBh0p19J= +4dFG7G3JSuZTr4n8Q@mail.gmail.com/T/#t .../bindings/iio/adc/adi,ad4030.yaml | 71 +++++++++++++++++-- 1 file changed, 66 insertions(+), 5 deletions(-) diff --git a/Documentation/devicetree/bindings/iio/adc/adi,ad4030.yaml b/Do= cumentation/devicetree/bindings/iio/adc/adi,ad4030.yaml index 564b6f67a96e..d0e8452598d4 100644 --- a/Documentation/devicetree/bindings/iio/adc/adi,ad4030.yaml +++ b/Documentation/devicetree/bindings/iio/adc/adi,ad4030.yaml @@ -19,6 +19,8 @@ description: | * https://www.analog.com/media/en/technical-documentation/data-sheets/ad= 4030-24-4032-24.pdf * https://www.analog.com/media/en/technical-documentation/data-sheets/ad= 4630-24_ad4632-24.pdf * https://www.analog.com/media/en/technical-documentation/data-sheets/ad= 4630-16-4632-16.pdf + * https://www.analog.com/media/en/technical-documentation/data-sheets/ad= aq4216.pdf + * https://www.analog.com/media/en/technical-documentation/data-sheets/ad= aq4224.pdf =20 $ref: /schemas/spi/spi-peripheral-props.yaml# =20 @@ -31,6 +33,8 @@ properties: - adi,ad4630-24 - adi,ad4632-16 - adi,ad4632-24 + - adi,adaq4216 + - adi,adaq4224 =20 reg: maxItems: 1 @@ -54,6 +58,14 @@ properties: description: Internal buffered Reference. Used when ref-supply is not connected. =20 + vddh-supply: + description: + PGIA Positive Power Supply. + + vdd-fda-supply: + description: + FDA Positive Power Supply. + cnv-gpios: description: The Convert Input (CNV). It initiates the sampling conversions. @@ -64,6 +76,13 @@ properties: The Reset Input (/RST). Used for asynchronous device reset. maxItems: 1 =20 + pga-gpios: + description: + A0 and A1 pins for gain selection. For devices that have PGA configu= ration + input pins, pga-gpios should be defined. + minItems: 2 + maxItems: 2 + pwms: description: PWM signal connected to the CNV pin. maxItems: 1 @@ -86,11 +105,30 @@ required: - vio-supply - cnv-gpios =20 -oneOf: - - required: - - ref-supply - - required: - - refin-supply +allOf: + - oneOf: + - required: + - ref-supply + - required: + - refin-supply + # ADAQ devices require a gain property to indicate how hardware PGA is s= et + - if: + properties: + compatible: + contains: + pattern: ^adi,adaq + then: + required: + - vddh-supply + - vdd-fda-supply + - pga-gpios + properties: + ref-supply: false + else: + properties: + adi,pga-value: false + pga-gpios: false + =20 unevaluatedProperties: false =20 @@ -114,3 +152,26 @@ examples: reset-gpios =3D <&gpio0 1 GPIO_ACTIVE_LOW>; }; }; + - | + #include + spi { + #address-cells =3D <1>; + #size-cells =3D <0>; + + adc@0 { + compatible =3D "adi,adaq4216"; + reg =3D <0>; + spi-max-frequency =3D <80000000>; + vdd-5v-supply =3D <&supply_5V>; + vdd-1v8-supply =3D <&supply_1_8V>; + vio-supply =3D <&supply_1_8V>; + refin-supply =3D <&refin_sup>; + vddh-supply =3D <&vddh>; + vdd-fda-supply =3D <&vdd_fda>; + cnv-gpios =3D <&gpio0 0 GPIO_ACTIVE_HIGH>; + reset-gpios =3D <&gpio0 1 GPIO_ACTIVE_LOW>; + pga-gpios =3D <&gpio0 2 GPIO_ACTIVE_HIGH>, + <&gpio0 3 GPIO_ACTIVE_HIGH>; + }; + }; +... --=20 2.39.2 From nobody Sat Feb 7 18:46:49 2026 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 AAF392877DB; Wed, 8 Oct 2025 13:52:20 +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=1759931542; cv=none; b=DiUi4p12tnQA0+a21aR/itD9j8Y9Fxugf2E934lP0/brKNkUTFlvtYUb2gAWTAuHdDL37du6sNPDM4GVqKeJeG62qlyp9LVwAkPuFnd+B+ZPK81f/bdJhhNrTgSLCsQAezlXnQdv8ZnDuIRJHCiGfAlpLOD195GKLfF95Y8wVXs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759931542; c=relaxed/simple; bh=S8h6UBo5UqsmO8IBEe4FMZ46jZFBj4w5kRvorF9gz2E=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=rcmjNhvHWrND7tSCyJG8jIJvEw5p4rxun6CCBdx2MzAJrt6VqcKHq3TDONMzCEFwLRHuajf3wPBStL6vz+VvXX0Jn7fkhMnm/YlFevk/jDbvZJNazVA0rfomdXsfjpXtd2Ns1JTng7FVsnfOoiUDy0dgY9INhjFO16LarUls7Ok= 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=1by5kwqO; 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="1by5kwqO" 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 598DhLUe027014; Wed, 8 Oct 2025 09:52:16 -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=f19x1 TlkuEYqJn2t0qmHArc6hpfc97QSLjIg39uYhME=; b=1by5kwqO/TtvMmf3hnd84 CGSjfR0tEFtDnxCLxtLmltftMrqyafkQawgbofIu111AocwJmLfuM0F0vsMEHMfd vEb4Yk1GNdcsRE5kd9++p0Tdfdte/rF4ExlSA7lMNe91E7npAiOaljGoPnRKtsX5 0ibD6uZvzmdivE/0MfhLeEkYLUPxY5Uu//QnaWtok61uVX2jH39QUfcFpGhjHPUL gFn25gBGcGUyy/jvBUDiMjgW8E1+P5Wv6yZc1CooIQM8jqCFYpX3OG4vLKdiaHM+ YOOXfObbiwzS8pVaG5tIRo/nPM8yOuNzm2ITAB11uliIld+wSAAh5YO7gINHMLi3 w== Received: from nwd2mta3.analog.com ([137.71.173.56]) by mx0a-00128a01.pphosted.com (PPS) with ESMTPS id 49ndssugsw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 08 Oct 2025 09:52:15 -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 598DqE6O034890 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 8 Oct 2025 09:52:14 -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.1748.37; Wed, 8 Oct 2025 09:52:14 -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.1748.37; Wed, 8 Oct 2025 09:52:14 -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.1748.37 via Frontend Transport; Wed, 8 Oct 2025 09:52:14 -0400 Received: from work.ad.analog.com (HYB-hERzalRezfV.ad.analog.com [10.65.205.9]) by zeus.spd.analog.com (8.15.1/8.15.1) with ESMTP id 598DpxWc023325; Wed, 8 Oct 2025 09:52:02 -0400 From: Marcelo Schmitt To: , , , , , CC: , , , , , , , , , , , Subject: [PATCH v4 8/8] iio: adc: ad4030: Add support for ADAQ4216 and ADAQ4224 Date: Wed, 8 Oct 2025 10:51:59 -0300 Message-ID: <7f8a65deb597d2d26e1d1d373d70851c7cb3d3e3.1759929814.git.marcelo.schmitt@analog.com> X-Mailer: git-send-email 2.39.2 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: AW1haW4tMjUxMDA4MDAwNCBTYWx0ZWRfX9/cSN0g/7sY5 JqFnZMYO0f5cvO7dv/qhr5AmS833egmMnhqkLO5XlyyJG8eFsDpJYa23rxGDyXXpQpGbSr+1EsV a+YFFLHpg4qEkS3md2Vx0vmYdWNqIPxZs9fDz+KVYJ2yMTDXw4PRRjCLS2VY7tYDWolCwRDlfwk TFWCkGiCDBl8cBIwpD+Ly13AjOfna7nQFwwIbWwaSdUnQAyrudX3n/iScFwJLGpoXiiSd3s1qDF uEFk1PzOV8GSlPevq34nItRsDtToUi5CkJ9Zk+gXJm3ytFuzCDG/QBfS0BZ3QB93GJaIzCVuudY E0Novn0Rp/vUruzdvQgba04hEF1BDLYUMpr4lIJTh+mbAL/eAsQZaBndH1/WDvfFA1QpYqtTjxA kzIkGsVpUnlnzEJPBAcayxgYhWs9fA== X-Proofpoint-ORIG-GUID: A_uqP3zFNjF0I-PKWtiE30zSo-T2rSli X-Proofpoint-GUID: A_uqP3zFNjF0I-PKWtiE30zSo-T2rSli X-Authority-Analysis: v=2.4 cv=e4ELiKp/ c=1 sm=1 tr=0 ts=68e66c8f cx=c_pps a=PpDZqlmH/M8setHirZLBMw==:117 a=PpDZqlmH/M8setHirZLBMw==:17 a=IkcTkHD0fZMA:10 a=x6icFKpwvdMA:10 a=gAnH3GRIAAAA:8 a=vBz0w1DY-RU6HqRekHsA:9 a=3ZKOabzyN94A:10 a=QEXdDO2ut3YA:10 a=cPQSjfK2_nFv0Q5t_7PE:22 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1117,Hydra:6.1.9,FMLib:17.12.80.40 definitions=2025-10-08_04,2025-10-06_01,2025-03-28_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 lowpriorityscore=0 impostorscore=0 suspectscore=0 adultscore=0 priorityscore=1501 clxscore=1015 phishscore=0 bulkscore=0 spamscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.19.0-2509150000 definitions=main-2510080004 ADAQ4216 and ADAQ4224 are similar to AD4030, but feature a PGA circuitry that scales the analog input signal prior to it reaching the ADC. The PGA is controlled through a pair of pins (A0 and A1) whose state define the gain that is applied to the input signal. Add support for ADAQ4216 and ADAQ4224. Provide a list of PGA options through the IIO device channel scale available interface and enable control of the PGA through the channel scale interface. Signed-off-by: Marcelo Schmitt --- Change log v3 -> v4: - ADAQ support patch updated to handle the GPIO setup case only. drivers/iio/adc/ad4030.c | 211 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 207 insertions(+), 4 deletions(-) diff --git a/drivers/iio/adc/ad4030.c b/drivers/iio/adc/ad4030.c index bbadcda8df77..b371d954918f 100644 --- a/drivers/iio/adc/ad4030.c +++ b/drivers/iio/adc/ad4030.c @@ -47,6 +47,8 @@ #define AD4030_REG_CHIP_GRADE_AD4630_24_GRADE 0x00 #define AD4030_REG_CHIP_GRADE_AD4632_16_GRADE 0x05 #define AD4030_REG_CHIP_GRADE_AD4632_24_GRADE 0x02 +#define AD4030_REG_CHIP_GRADE_ADAQ4216_GRADE 0x1E +#define AD4030_REG_CHIP_GRADE_ADAQ4224_GRADE 0x1C #define AD4030_REG_CHIP_GRADE_MASK_CHIP_GRADE GENMASK(7, 3) #define AD4030_REG_SCRATCH_PAD 0x0A #define AD4030_REG_SPI_REVISION 0x0B @@ -124,6 +126,10 @@ /* Datasheet says 9.8ns, so use the closest integer value */ #define AD4030_TQUIET_CNV_DELAY_NS 10 =20 +/* HARDWARE_GAIN */ +#define ADAQ4616_PGA_PINS 2 +#define ADAQ4616_PGA_GAIN_MAX_NANO (NANO * 2 / 3) + enum ad4030_out_mode { AD4030_OUT_DATA_MD_DIFF, AD4030_OUT_DATA_MD_16_DIFF_8_COM, @@ -144,6 +150,30 @@ enum { AD4030_SCAN_TYPE_AVG, }; =20 +static const int adaq4216_hw_gains_db[] =3D { + -10, /* 1/3 V/V gain */ + -5, /* 5/9 V/V gain */ + 7, /* 20/9 V/V gain */ + 16, /* 20/3 V/V gain */ +}; + +/* + * Gains computed as fractions of 1000 so they can be expressed by integer= s. + */ +static const int adaq4216_hw_gains_vpv[] =3D { + MILLI / 3, /* 333 */ + (5 * MILLI / 9), /* 555 */ + (20 * MILLI / 9), /* 2222 */ + (20 * MILLI / 3), /* 6666 */ +}; + +static const int adaq4216_hw_gains_frac[][2] =3D { + { 1, 3 }, /* 1/3 V/V gain */ + { 5, 9 }, /* 5/9 V/V gain */ + { 20, 9 }, /* 20/9 V/V gain */ + { 20, 3 }, /* 20/3 V/V gain */ +}; + struct ad4030_chip_info { const char *name; const unsigned long *available_masks; @@ -151,6 +181,7 @@ struct ad4030_chip_info { const struct iio_chan_spec offload_channels[AD4030_MAX_IIO_CHANNEL_NB]; u8 grade; u8 precision_bits; + bool has_pga; /* Number of hardware channels */ int num_voltage_inputs; unsigned int tcyc_ns; @@ -174,7 +205,11 @@ struct ad4030_state { struct spi_offload_trigger *offload_trigger; struct spi_offload_trigger_config offload_trigger_config; struct pwm_device *cnv_trigger; + size_t scale_avail_size; struct pwm_waveform cnv_wf; + unsigned int scale_avail[ARRAY_SIZE(adaq4216_hw_gains_db)][2]; + struct gpio_descs *pga_gpios; + unsigned int pga_index; =20 /* * DMA (thus cache coherency maintenance) requires the transfer buffers @@ -231,7 +266,7 @@ struct ad4030_state { * - voltage0-voltage1 * - voltage2-voltage3 */ -#define __AD4030_CHAN_DIFF(_idx, _scan_type, _offload) { \ +#define __AD4030_CHAN_DIFF(_idx, _scan_type, _offload, _pga) { \ .info_mask_shared_by_all =3D \ (_offload ? BIT(IIO_CHAN_INFO_SAMP_FREQ) : 0) | \ BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), \ @@ -242,6 +277,7 @@ struct ad4030_state { BIT(IIO_CHAN_INFO_CALIBBIAS) | \ BIT(IIO_CHAN_INFO_RAW), \ .info_mask_separate_available =3D BIT(IIO_CHAN_INFO_CALIBBIAS) | \ + (_pga ? BIT(IIO_CHAN_INFO_SCALE) : 0) | \ BIT(IIO_CHAN_INFO_CALIBSCALE), \ .type =3D IIO_VOLTAGE, \ .indexed =3D 1, \ @@ -256,10 +292,16 @@ struct ad4030_state { } =20 #define AD4030_CHAN_DIFF(_idx, _scan_type) \ - __AD4030_CHAN_DIFF(_idx, _scan_type, 0) + __AD4030_CHAN_DIFF(_idx, _scan_type, 0, 0) =20 #define AD4030_OFFLOAD_CHAN_DIFF(_idx, _scan_type) \ - __AD4030_CHAN_DIFF(_idx, _scan_type, 1) + __AD4030_CHAN_DIFF(_idx, _scan_type, 1, 0) + +#define ADAQ4216_CHAN_DIFF(_idx, _scan_type) \ + __AD4030_CHAN_DIFF(_idx, _scan_type, 0, 1) + +#define ADAQ4216_OFFLOAD_CHAN_DIFF(_idx, _scan_type) \ + __AD4030_CHAN_DIFF(_idx, _scan_type, 1, 1) =20 static const int ad4030_average_modes[] =3D { BIT(0), /* No averaging/oversampling */ @@ -413,6 +455,65 @@ static const struct regmap_config ad4030_regmap_config= =3D { .max_register =3D AD4030_REG_DIG_ERR, }; =20 +static void ad4030_fill_scale_avail(struct ad4030_state *st) +{ + unsigned int mag_bits, int_part, fract_part, i; + u64 range; + + /* + * The maximum precision of differential channels is retrieved from the + * chip properties. The output code of differential channels is in two's + * complement format (i.e. signed), so the MSB is the sign bit and only + * (precision_bits - 1) bits express voltage magnitude. + */ + mag_bits =3D st->chip->precision_bits - 1; + + for (i =3D 0; i < ARRAY_SIZE(adaq4216_hw_gains_frac); i++) { + range =3D mult_frac(st->vref_uv, adaq4216_hw_gains_frac[i][1], + adaq4216_hw_gains_frac[i][0]); + /* + * If range were in mV, we would multiply it by NANO below. + * Though, range is in =C2=B5V so multiply it by MICRO only so the + * result after right shift and division scales output codes to + * millivolts. + */ + int_part =3D div_u64_rem(((u64)range * MICRO) >> mag_bits, NANO, &fract_= part); + st->scale_avail[i][0] =3D int_part; + st->scale_avail[i][1] =3D fract_part; + } +} + +static int ad4030_set_pga_gain(struct ad4030_state *st) +{ + DECLARE_BITMAP(bitmap, ADAQ4616_PGA_PINS) =3D { }; + + bitmap_write(bitmap, st->pga_index, 0, ADAQ4616_PGA_PINS); + + return gpiod_multi_set_value_cansleep(st->pga_gpios, bitmap); +} + +static int ad4030_set_pga(struct iio_dev *indio_dev, int gain_int, int gai= n_fract) +{ + struct ad4030_state *st =3D iio_priv(indio_dev); + unsigned int mag_bits =3D st->chip->precision_bits - 1; + u64 gain_nano, tmp; + + if (!st->pga_gpios) + return -EINVAL; + + gain_nano =3D gain_int * NANO + gain_fract; + + if (!in_range(gain_nano, 1, ADAQ4616_PGA_GAIN_MAX_NANO)) + return -EINVAL; + + tmp =3D DIV_ROUND_CLOSEST_ULL(gain_nano << mag_bits, NANO); + gain_nano =3D DIV_ROUND_CLOSEST_ULL(st->vref_uv, tmp); + st->pga_index =3D find_closest(gain_nano, adaq4216_hw_gains_vpv, + ARRAY_SIZE(adaq4216_hw_gains_vpv)); + + return ad4030_set_pga_gain(st); +} + static int ad4030_get_chan_scale(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val, @@ -432,7 +533,14 @@ static int ad4030_get_chan_scale(struct iio_dev *indio= _dev, =20 *val2 =3D scan_type->realbits; =20 - return IIO_VAL_FRACTIONAL_LOG2; + /* The LSB of the 8-bit common-mode data is always vref/256. */ + if (scan_type->realbits =3D=3D 8 || !st->chip->has_pga) + return IIO_VAL_FRACTIONAL_LOG2; + + *val =3D st->scale_avail[st->pga_index][0]; + *val2 =3D st->scale_avail[st->pga_index][1]; + + return IIO_VAL_INT_PLUS_NANO; } =20 static int ad4030_get_chan_calibscale(struct iio_dev *indio_dev, @@ -900,6 +1008,15 @@ static int ad4030_read_avail(struct iio_dev *indio_de= v, *length =3D ARRAY_SIZE(ad4030_average_modes); return IIO_AVAIL_LIST; =20 + case IIO_CHAN_INFO_SCALE: + if (st->scale_avail_size =3D=3D 1) + *vals =3D (int *)st->scale_avail[st->pga_index]; + else + *vals =3D (int *)st->scale_avail; + *length =3D st->scale_avail_size * 2; /* print int and nano part */ + *type =3D IIO_VAL_INT_PLUS_NANO; + return IIO_AVAIL_LIST; + default: return -EINVAL; } @@ -975,6 +1092,9 @@ static int ad4030_write_raw_dispatch(struct iio_dev *i= ndio_dev, case IIO_CHAN_INFO_SAMP_FREQ: return ad4030_set_sampling_freq(indio_dev, val); =20 + case IIO_CHAN_INFO_SCALE: + return ad4030_set_pga(indio_dev, val, val2); + default: return -EINVAL; } @@ -996,6 +1116,17 @@ static int ad4030_write_raw(struct iio_dev *indio_dev, return ret; } =20 +static int ad4030_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 ad4030_reg_access(struct iio_dev *indio_dev, unsigned int reg, unsigned int writeval, unsigned int *readval) { @@ -1046,6 +1177,7 @@ static const struct iio_info ad4030_iio_info =3D { .read_avail =3D ad4030_read_avail, .read_raw =3D ad4030_read_raw, .write_raw =3D ad4030_write_raw, + .write_raw_get_fmt =3D &ad4030_write_raw_get_fmt, .debugfs_reg_access =3D ad4030_reg_access, .read_label =3D ad4030_read_label, .get_current_scan_type =3D ad4030_get_current_scan_type, @@ -1309,6 +1441,25 @@ static int ad4030_spi_offload_setup(struct iio_dev *= indio_dev, IIO_BUFFER_DIRECTION_IN); } =20 +static int ad4030_setup_pga(struct device *dev, struct iio_dev *indio_dev, + struct ad4030_state *st) +{ + /* Setup GPIOs for PGA control */ + 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 ADAQ4616_PGA_PINS) + return dev_err_probe(dev, -EINVAL, + "Expected 2 GPIOs for PGA control.\n"); + + st->scale_avail_size =3D ARRAY_SIZE(adaq4216_hw_gains_db); + st->pga_index =3D 0; + + return 0; +} + static int ad4030_probe(struct spi_device *spi) { struct device *dev =3D &spi->dev; @@ -1351,6 +1502,14 @@ static int ad4030_probe(struct spi_device *spi) if (ret) return ret; =20 + if (st->chip->has_pga) { + ret =3D ad4030_setup_pga(dev, indio_dev, st); + if (ret) + return ret; + + ad4030_fill_scale_avail(st); + } + ret =3D ad4030_config(st); if (ret) return ret; @@ -1614,12 +1773,54 @@ static const struct ad4030_chip_info ad4632_24_chip= _info =3D { .max_sample_rate_hz =3D 500 * HZ_PER_KHZ, }; =20 +static const struct ad4030_chip_info adaq4216_chip_info =3D { + .name =3D "adaq4216", + .available_masks =3D ad4030_channel_masks, + .channels =3D { + ADAQ4216_CHAN_DIFF(0, ad4030_16_scan_types), + AD4030_CHAN_CMO(1, 0), + IIO_CHAN_SOFT_TIMESTAMP(2), + }, + .offload_channels =3D { + ADAQ4216_OFFLOAD_CHAN_DIFF(0, ad4030_16_offload_scan_types), + AD4030_CHAN_CMO(1, 0), + }, + .grade =3D AD4030_REG_CHIP_GRADE_ADAQ4216_GRADE, + .precision_bits =3D 16, + .has_pga =3D true, + .num_voltage_inputs =3D 1, + .tcyc_ns =3D AD4030_TCYC_ADJUSTED_NS, + .max_sample_rate_hz =3D 2 * HZ_PER_MHZ, +}; + +static const struct ad4030_chip_info adaq4224_chip_info =3D { + .name =3D "adaq4224", + .available_masks =3D ad4030_channel_masks, + .channels =3D { + ADAQ4216_CHAN_DIFF(0, ad4030_24_scan_types), + AD4030_CHAN_CMO(1, 0), + IIO_CHAN_SOFT_TIMESTAMP(2), + }, + .offload_channels =3D { + ADAQ4216_OFFLOAD_CHAN_DIFF(0, ad4030_24_offload_scan_types), + AD4030_CHAN_CMO(1, 0), + }, + .grade =3D AD4030_REG_CHIP_GRADE_ADAQ4224_GRADE, + .precision_bits =3D 24, + .has_pga =3D true, + .num_voltage_inputs =3D 1, + .tcyc_ns =3D AD4030_TCYC_ADJUSTED_NS, + .max_sample_rate_hz =3D 2 * HZ_PER_MHZ, +}; + static const struct spi_device_id ad4030_id_table[] =3D { { "ad4030-24", (kernel_ulong_t)&ad4030_24_chip_info }, { "ad4630-16", (kernel_ulong_t)&ad4630_16_chip_info }, { "ad4630-24", (kernel_ulong_t)&ad4630_24_chip_info }, { "ad4632-16", (kernel_ulong_t)&ad4632_16_chip_info }, { "ad4632-24", (kernel_ulong_t)&ad4632_24_chip_info }, + { "adaq4216", (kernel_ulong_t)&adaq4216_chip_info }, + { "adaq4224", (kernel_ulong_t)&adaq4224_chip_info }, { } }; MODULE_DEVICE_TABLE(spi, ad4030_id_table); @@ -1630,6 +1831,8 @@ static const struct of_device_id ad4030_of_match[] = =3D { { .compatible =3D "adi,ad4630-24", .data =3D &ad4630_24_chip_info }, { .compatible =3D "adi,ad4632-16", .data =3D &ad4632_16_chip_info }, { .compatible =3D "adi,ad4632-24", .data =3D &ad4632_24_chip_info }, + { .compatible =3D "adi,adaq4216", .data =3D &adaq4216_chip_info }, + { .compatible =3D "adi,adaq4224", .data =3D &adaq4224_chip_info }, { } }; MODULE_DEVICE_TABLE(of, ad4030_of_match); --=20 2.39.2