From nobody Wed Jun 17 01:34:37 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 34520330D23; Tue, 28 Apr 2026 17:02:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777395739; cv=none; b=t8jsYJYGRpQLgv52t1OhZIh+lifag1H3E44+WiGIPDiLMtJPCG9yBhu+PCmu2jlf92DzMRRxrQ4WkoGm05ok5hisDa9uvWakYi2NLneqauIlY0Sm3sDnw2zd0Jkd4RPgGDsKmW/qjyIrq0Die8q47P8Xz41D6uTjO1muwhZMVc8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777395739; c=relaxed/simple; bh=rxfu7XMJ7z3UzfD8sKx/uhY/Eiv1RvvXgati5CCfXv8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=PK2nHPZ26qZqOK4gpEHGrplm556B9bW6Km+CSPalHY/cSlv4PdE3Uy7D6rdQtJGDlA4TPg5jo++eqpiwYZ49iPQiXBllEUjVhskmnCyZrdCB1bnO9CdozIAlalqEuwFcg9cY7tQLecbAQ8cBpiHQL9bVqvZLTzbn8kvN80zGBP0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=UzwZ4reQ; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="UzwZ4reQ" Received: by smtp.kernel.org (Postfix) with ESMTPS id D8F1AC2BCB7; Tue, 28 Apr 2026 17:02:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777395738; bh=rxfu7XMJ7z3UzfD8sKx/uhY/Eiv1RvvXgati5CCfXv8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=UzwZ4reQvb57FCwtHWmmiIBi8UzP7fRoxsZ0ITdM1Fe+GZwlInSLvSP50sLge4imK KTKj+rh8pOTBOJ0oFOr4okyO3xRr7d5QsNXDEBm1KNPuPqjSXOZLlwfD2G3mQTAYDd SQ1w/jvY4CZetbdC7TEjXCvCmSs7ii8qmzfR1H6WW10CKxJR7EoZD9oxNRcf5sIuKJ PtsNWuZp3amXtR6A7NsfnEsG/qWK+JJC8TtsMbu0iFUZ3wSXd51tg/LHzEBpuocZ7g s2OOn7W3ewbjtX/jorO1pgi52JP9vf9SBciHQGwA7+wNvVfmtCMFj4MOONF2N/Ewl2 NdgyYc9DgLXBw== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id C7A5CFF886D; Tue, 28 Apr 2026 17:02:18 +0000 (UTC) From: Rodrigo Alencar via B4 Relay Date: Tue, 28 Apr 2026 18:02:16 +0100 Subject: [PATCH v3 01/11] iio: dac: ad5686: fix ref bit initialization for single-channel parts Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260428-ad5686-fixes-v3-1-9cff7bd67a15@analog.com> References: <20260428-ad5686-fixes-v3-0-9cff7bd67a15@analog.com> In-Reply-To: <20260428-ad5686-fixes-v3-0-9cff7bd67a15@analog.com> To: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Stefan Popa , Jonathan Cameron , Greg Kroah-Hartman , Michael Auchter , Jonathan Cameron Cc: Lars-Peter Clausen , Michael Hennerich , Jonathan Cameron , David Lechner , Andy Shevchenko , Rodrigo Alencar X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1777395737; l=1785; i=rodrigo.alencar@analog.com; s=default; h=from:subject:message-id; bh=Nconrz7dK97kTaVAe2gd8GJ1K9ckwdIVrWzVZiHhK/A=; b=MVAnyZdg6ffA2JMYIaahewQ/h8qr1iLw1tkGlLl88y14KGgLexsjSRojXFdLbpylDaFfUrcIK QtMYX1WIbc8BYdrgxpJWqMxmmogrFcSk5r/vjrQJv8oFEeftPe7kl1J X-Developer-Key: i=rodrigo.alencar@analog.com; a=ed25519; pk=ULeHbgU/OYh/PG/4anHDfLgldFItQHAhOktYRVLMFRo= X-Endpoint-Received: by B4 Relay for rodrigo.alencar@analog.com/default with auth_id=561 X-Original-From: Rodrigo Alencar Reply-To: rodrigo.alencar@analog.com From: Rodrigo Alencar The reference bit position was ignored when writing the register at the probe() function (!!val was used). When such bit is 1, internal voltage reference is disabled so that an external one can be used. For multi-channel devices, bit 0 of the Internal Reference Setup command behaves the same way, so AD5686_REF_BIT_MSK is created. The issue exists since support for single-channel devices were first introduced. Fixes: be1b24d24541 ("iio:dac:ad5686: Add AD5691R/AD5692R/AD5693/AD5693R su= pport") Signed-off-by: Rodrigo Alencar Reviewed-by: Andy Shevchenko --- drivers/iio/dac/ad5686.c | 6 +++--- drivers/iio/dac/ad5686.h | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/iio/dac/ad5686.c b/drivers/iio/dac/ad5686.c index 9a384c50929b..1fc54c38b629 100644 --- a/drivers/iio/dac/ad5686.c +++ b/drivers/iio/dac/ad5686.c @@ -511,7 +511,7 @@ int ad5686_probe(struct device *dev, break; case AD5686_REGMAP: cmd =3D AD5686_CMD_INTERNAL_REFER_SETUP; - ref_bit_msk =3D 0; + ref_bit_msk =3D AD5686_REF_BIT_MSK; break; case AD5693_REGMAP: cmd =3D AD5686_CMD_CONTROL_REG; @@ -522,9 +522,9 @@ int ad5686_probe(struct device *dev, return -EINVAL; } =20 - val =3D (has_external_vref | ref_bit_msk); + val =3D has_external_vref ? ref_bit_msk : 0; =20 - ret =3D st->write(st, cmd, 0, !!val); + ret =3D st->write(st, cmd, 0, val); if (ret) return ret; =20 diff --git a/drivers/iio/dac/ad5686.h b/drivers/iio/dac/ad5686.h index e7d36bae3e59..36e16c5c4581 100644 --- a/drivers/iio/dac/ad5686.h +++ b/drivers/iio/dac/ad5686.h @@ -46,6 +46,7 @@ =20 #define AD5310_REF_BIT_MSK BIT(8) #define AD5683_REF_BIT_MSK BIT(12) +#define AD5686_REF_BIT_MSK BIT(0) #define AD5693_REF_BIT_MSK BIT(12) =20 /** --=20 2.43.0 From nobody Wed Jun 17 01:34:37 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 3448232E128; Tue, 28 Apr 2026 17:02:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777395739; cv=none; b=qjeN6igP5y12gvnsvYPpFhcm62HjFL4TY4IVt2QNK584inVTj75gm3ASNIvzRFOKNUBSmSImCZB1TRC0GehW1dow2KoUxr4DSJWW033wBYry3f0ZQfpzCb4GcOm50lhpD4kiWVdJEIS8bbrp1RuTf3Z1pWGjLPn6S/R1LoyS6aY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777395739; c=relaxed/simple; bh=KmgA9JgsrbAO17H+F7bCU2SdGapgodBy3ZR8O7nYaAk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=cWwmBlZKCkuaoJtb6x97VU35TcHC2q6zlu4Bfz/3noJGI/l9pA0CnITi1ZvSpRSExzGgJOODTdH26X10RjZjr+4gd86T9JM7go0hSpO8ctX4wMSs2uiYY7lY6BX6vjTXzeA16rHCQROYsEhgv3wCSWdoKvJ8SHMe3uhbvPLnX1E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=rtFmo4nG; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="rtFmo4nG" Received: by smtp.kernel.org (Postfix) with ESMTPS id E6702C2BCB5; Tue, 28 Apr 2026 17:02:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777395739; bh=KmgA9JgsrbAO17H+F7bCU2SdGapgodBy3ZR8O7nYaAk=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=rtFmo4nGH4dC6TG3WtWT2605+NZViTMdO+8dFRPZ50Z4lQaMJyYb/yGUTN/kD2O1g 9OGvCl9wqnOtb8IwKuW4iooUQ4qVSwkQPfm6jm4/QCAxHA7z013l+yBRg1h53PqQ7R 0/B//rHP0tAV1TzJcN+vw1o7/UzY1kVFjWFkPJzIqGU+3G5jyj4RYGc3u20nQomKcp AP0vryipIro3qYZ3DicfDr2G5sNc7EH4lsJYJxXOfJap2yNidGpCdyPQPrC2XNJuuH X6GXU0RIpsDQFXM2qcpI7nYvWhOKKJMUBgVB8A3XbkSND8oNE+knthU37jJwHGsJ5c Be7Gw9ZdTSlqg== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id D4F5AFF8876; Tue, 28 Apr 2026 17:02:18 +0000 (UTC) From: Rodrigo Alencar via B4 Relay Date: Tue, 28 Apr 2026 18:02:17 +0100 Subject: [PATCH v3 02/11] iio: dac: ad5686: fix input raw value check Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260428-ad5686-fixes-v3-2-9cff7bd67a15@analog.com> References: <20260428-ad5686-fixes-v3-0-9cff7bd67a15@analog.com> In-Reply-To: <20260428-ad5686-fixes-v3-0-9cff7bd67a15@analog.com> To: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Stefan Popa , Jonathan Cameron , Greg Kroah-Hartman , Michael Auchter , Jonathan Cameron Cc: Lars-Peter Clausen , Michael Hennerich , Jonathan Cameron , David Lechner , Andy Shevchenko , Rodrigo Alencar X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1777395737; l=1003; i=rodrigo.alencar@analog.com; s=default; h=from:subject:message-id; bh=THkmIKMHt3NPcgwfwdWS9HSyAjZViHV2lms1HDMm1Nw=; b=0TPOt5FDyt3qU3Hin50HwrK8+Pwv9Rjop7sHBTj5kUJz8tdx1bXgV9vpVa1+OnPp1H2SuGSLG zWJsmDzyQlPBkDeEBByFXkzfaAZ+zLNk5tZuzQUvLp/E6CXjlWJbGRH X-Developer-Key: i=rodrigo.alencar@analog.com; a=ed25519; pk=ULeHbgU/OYh/PG/4anHDfLgldFItQHAhOktYRVLMFRo= X-Endpoint-Received: by B4 Relay for rodrigo.alencar@analog.com/default with auth_id=561 X-Original-From: Rodrigo Alencar Reply-To: rodrigo.alencar@analog.com From: Rodrigo Alencar Fix range check for input raw value, which is off by one, i.e., for a 10-bit DAC the max valid value is 1023, but 1 << 10 equals 1024, which passes the previous check, allowing an out-of-range write. The issue exists since the ad5686 driver was first introduced. Fixes: c2f37c8dcadc ("iio: dac: New driver for AD5686R, AD5685R, AD5684R Di= gital to analog converters") Signed-off-by: Rodrigo Alencar Reviewed-by: Andy Shevchenko --- drivers/iio/dac/ad5686.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/iio/dac/ad5686.c b/drivers/iio/dac/ad5686.c index 1fc54c38b629..076fe8b8bd85 100644 --- a/drivers/iio/dac/ad5686.c +++ b/drivers/iio/dac/ad5686.c @@ -154,7 +154,7 @@ static int ad5686_write_raw(struct iio_dev *indio_dev, =20 switch (mask) { case IIO_CHAN_INFO_RAW: - if (val > (1 << chan->scan_type.realbits) || val < 0) + if (val >=3D (1 << chan->scan_type.realbits) || val < 0) return -EINVAL; =20 mutex_lock(&st->lock); --=20 2.43.0 From nobody Wed Jun 17 01:34:37 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 345A1330D28; Tue, 28 Apr 2026 17:02:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777395739; cv=none; b=J9dG7Jz5rOx2DrV5gAwqXxyv9isAxbt9q9bGYzuLdXnyHO4lPTKUizUJlnfTanmsRsXXrefEnYjGuwSQKffcP2l356enwn8HYg/GiwxRl9d3u13qjpW6eR+Bc3OrbpOwx1WKDu7wU7VOKaTWNnx2CPmnCwgqdvj62pYJBwy+8x4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777395739; c=relaxed/simple; bh=0JziPPaM9IDT6KUt7vyo/k6/XjAkaCDxmpkh7SxX7QI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=bI/NDfDMJBHVc9x80rLXKGaLFJVVeaWk+g75CHLeAlnhArR2IIxZ1hEx50hWOLb6E72UfY00Fsl5TBNz3Pczes5uWLR4aQoiq+B6MM8HALnzDku8xk8bCh0Jpa4tfcftn1HXYDtPrEw4KoU2WIgt1dVVS5axpiFAkZlAwX6OlAQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=hMYF5PoD; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="hMYF5PoD" Received: by smtp.kernel.org (Postfix) with ESMTPS id F0733C2BCC4; Tue, 28 Apr 2026 17:02:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777395739; bh=0JziPPaM9IDT6KUt7vyo/k6/XjAkaCDxmpkh7SxX7QI=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=hMYF5PoD/u/QgnlbakhFdGdkWMq1Lmoh3SDQ7wFPj6DEXjA63rDhVLf7r/f8wwJx8 +yB0MFIjicRqNuOuvewHMo5m7AEQR1g0ca37i/DNstTxKJgQT3iFNH5I47TSxGG/Vz xcAJJRXg3/qGt4suWZSDabIoORNSGFkxG9MRR+nic33gBQnl5TqMOBAJeTxiU+ss5N Cwr7GtkaMyaKMJGjR4m5itrIkNfK/Y6c5aXiUoPzNC4Z3YaSFhKyVUhKvaB7pRC6N7 oPrvVG4fhWCaaJQkKRoKAIJ0kjiUofQSoo8IHmtDMvG9ph55SctXjVz3ebBjpIHjw/ gbfkT3fYip4Tg== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id E3F64FF885A; Tue, 28 Apr 2026 17:02:18 +0000 (UTC) From: Rodrigo Alencar via B4 Relay Date: Tue, 28 Apr 2026 18:02:18 +0100 Subject: [PATCH v3 03/11] iio: dac: ad5686: acquire lock when doing powerdown control Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260428-ad5686-fixes-v3-3-9cff7bd67a15@analog.com> References: <20260428-ad5686-fixes-v3-0-9cff7bd67a15@analog.com> In-Reply-To: <20260428-ad5686-fixes-v3-0-9cff7bd67a15@analog.com> To: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Stefan Popa , Jonathan Cameron , Greg Kroah-Hartman , Michael Auchter , Jonathan Cameron Cc: Lars-Peter Clausen , Michael Hennerich , Jonathan Cameron , David Lechner , Andy Shevchenko , Rodrigo Alencar X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1777395737; l=1335; i=rodrigo.alencar@analog.com; s=default; h=from:subject:message-id; bh=1oS02JnTrI5wiIzSz+QkF/MekEEwrISkavx8yLsCZCI=; b=U4qQdQd8KE5MMad2EyvQU7MgouJ7TgeDBvOU8hzO3bV2BdfaahgesjuoWCg5hqhiRGLVYAOvd 5WhZ6l++EZmB3UgOvy4lu89E+AvwWf9fe8s0u444nmfdkAeh9qxWc++ X-Developer-Key: i=rodrigo.alencar@analog.com; a=ed25519; pk=ULeHbgU/OYh/PG/4anHDfLgldFItQHAhOktYRVLMFRo= X-Endpoint-Received: by B4 Relay for rodrigo.alencar@analog.com/default with auth_id=561 X-Original-From: Rodrigo Alencar Reply-To: rodrigo.alencar@analog.com From: Rodrigo Alencar Protect write access of pwr_down_mode and pwr_down_mask fields with existing mutex lock. Each channel exposes their own attributes for controlling powerdown modes and powerdown state. This fixes potential race conditions as those functions perform non-atomic read-modify-write operations to those pwr_down_* fields. This issue exists since the ad5686 driver was first introduced. Fixes: c2f37c8dcadc ("iio: dac: New driver for AD5686R, AD5685R, AD5684R Di= gital to analog converters") Signed-off-by: Rodrigo Alencar Reviewed-by: Andy Shevchenko --- drivers/iio/dac/ad5686.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/iio/dac/ad5686.c b/drivers/iio/dac/ad5686.c index 076fe8b8bd85..69358dd66cbc 100644 --- a/drivers/iio/dac/ad5686.c +++ b/drivers/iio/dac/ad5686.c @@ -39,6 +39,8 @@ static int ad5686_set_powerdown_mode(struct iio_dev *indi= o_dev, { struct ad5686_state *st =3D iio_priv(indio_dev); =20 + guard(mutex)(&st->lock); + st->pwr_down_mode &=3D ~(0x3 << (chan->channel * 2)); st->pwr_down_mode |=3D ((mode + 1) << (chan->channel * 2)); =20 @@ -77,6 +79,8 @@ static ssize_t ad5686_write_dac_powerdown(struct iio_dev = *indio_dev, if (ret) return ret; =20 + guard(mutex)(&st->lock); + if (readin) st->pwr_down_mask |=3D (0x3 << (chan->channel * 2)); else --=20 2.43.0 From nobody Wed Jun 17 01:34:37 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 3436C31A7F6; Tue, 28 Apr 2026 17:02:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777395739; cv=none; b=svZ1JrBMB2anIyL5ZGcQzYXflhGsIBugT5EYRpygsa304WvlKbvnFfSoXAWHSCtWUUhASrNBG8CWwibhShxa82qjZJixA3c0NYyDfS/J+HJssZJoPziKVfKdZmxAoJj8i5AULnBle/+xvjp9VTlpf6oXq8m/Vh5xlXhnqNZQ5VE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777395739; c=relaxed/simple; bh=d6bxSpQnPzAhUfpXFkl4ed0Xj2EaJ5VoyGZHGKMSqXU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=kbosh3v9v3Y6Nhbo+X0u0+i6gf4g0th2lBnoKp4uxYqFLYE/vFFC7f+uOfWdIAFU8wKxTjUYshXhdQVr9+Pslb3iUT+JZTUGDZ/bcain/dZNFptwqK0bK9w3htzlGcLeJB/EDalRGdMtHD4BkaeMRqGel0TtluDDsGOTCEfCqyA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=S14sxr+w; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="S14sxr+w" Received: by smtp.kernel.org (Postfix) with ESMTPS id 09931C2BCC9; Tue, 28 Apr 2026 17:02:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777395739; bh=d6bxSpQnPzAhUfpXFkl4ed0Xj2EaJ5VoyGZHGKMSqXU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=S14sxr+wFwMUBNTnwmCAoH8fTKvx4AaZjx8B6U+JTVq63Rp+q8Z1ZBJ4Dvm6bfjxp 2LH47qWJyjwTGvgVS+Rb1LBVi5cKXqX6ye0aGgVTGkOls78UYjCgoPaOpiK+xAGQM9 JWfdg4B8VHt1GoNJtGtytceB8GXu1LSCbijcUOmFHyDQWRVvcG6GS9BlyjJ8E+sJT+ XDEVMVzNhQGNgB6/ql8hTwu+DeLH6NWvdArdqUmmTkoBnOCCiKkYr81a4+51IpE8cX q2tqHgCPH7PG9vo6waMzy9i79XsTHzIjYvAJnEnygMaZRXyyXhNJf67Fa6C9Q+exF0 ThbtFqoQ8L8Aw== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id F3C30FF8878; Tue, 28 Apr 2026 17:02:18 +0000 (UTC) From: Rodrigo Alencar via B4 Relay Date: Tue, 28 Apr 2026 18:02:19 +0100 Subject: [PATCH v3 04/11] iio: dac: ad5686: fix powerdown control on dual-channel devices Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260428-ad5686-fixes-v3-4-9cff7bd67a15@analog.com> References: <20260428-ad5686-fixes-v3-0-9cff7bd67a15@analog.com> In-Reply-To: <20260428-ad5686-fixes-v3-0-9cff7bd67a15@analog.com> To: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Stefan Popa , Jonathan Cameron , Greg Kroah-Hartman , Michael Auchter , Jonathan Cameron Cc: Lars-Peter Clausen , Michael Hennerich , Jonathan Cameron , David Lechner , Andy Shevchenko , Rodrigo Alencar X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1777395737; l=4274; i=rodrigo.alencar@analog.com; s=default; h=from:subject:message-id; bh=swK7HWPRTiDnxfKdBPmwx4vSDCtY2pSzF0OqooQD2i4=; b=RfpQ/Hwv6XLTi5jXXmp3SBUwviWtkJprrU6TDNoohQYhakp7uwzDs9ROpKxA89c494XHyFa4z dhQArrBm8hiCp7BUPEccfj9Tm03ZsAUW68aGCBfk7IPaFWf4g3uENdD X-Developer-Key: i=rodrigo.alencar@analog.com; a=ed25519; pk=ULeHbgU/OYh/PG/4anHDfLgldFItQHAhOktYRVLMFRo= X-Endpoint-Received: by B4 Relay for rodrigo.alencar@analog.com/default with auth_id=561 X-Original-From: Rodrigo Alencar Reply-To: rodrigo.alencar@analog.com From: Rodrigo Alencar Fix powerdown control by using a proper bit shift for the powerdown mask values. During initialization, powerdown bits are initialized so that unused bits are set to 1 and the correct bit shift is used. Dual-channel devices use one-hot encoding in the address and that reflects on the position of the powerdown bits, which are not channel-index based for that case. Quad-channel devices also use one-hot encoding for the channel address but the result of log2(address) coincides with the channel index value. The issue was introduced when first adding support for dual-channel devices, which overlooked powerdown control differences. Fixes: 7dc8faeab3e3 ("iio: dac: ad5686: add support for AD5338R") Signed-off-by: Rodrigo Alencar Reviewed-by: Andy Shevchenko --- drivers/iio/dac/ad5686.c | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/drivers/iio/dac/ad5686.c b/drivers/iio/dac/ad5686.c index 69358dd66cbc..b31d0ec5415c 100644 --- a/drivers/iio/dac/ad5686.c +++ b/drivers/iio/dac/ad5686.c @@ -25,24 +25,35 @@ static const char * const ad5686_powerdown_modes[] =3D { "three_state" }; =20 +static inline unsigned int ad5686_pd_mask_shift(const struct iio_chan_spec= *chan) +{ + if (chan->channel =3D=3D chan->address) + return chan->channel * 2; + + /* one-hot encoding is used in dual/quad channel devices */ + return __ffs(chan->address) * 2; +} + static int ad5686_get_powerdown_mode(struct iio_dev *indio_dev, const struct iio_chan_spec *chan) { + unsigned int shift =3D ad5686_pd_mask_shift(chan); struct ad5686_state *st =3D iio_priv(indio_dev); =20 - return ((st->pwr_down_mode >> (chan->channel * 2)) & 0x3) - 1; + return ((st->pwr_down_mode >> shift) & 0x3) - 1; } =20 static int ad5686_set_powerdown_mode(struct iio_dev *indio_dev, const struct iio_chan_spec *chan, unsigned int mode) { + unsigned int shift =3D ad5686_pd_mask_shift(chan); struct ad5686_state *st =3D iio_priv(indio_dev); =20 guard(mutex)(&st->lock); =20 - st->pwr_down_mode &=3D ~(0x3 << (chan->channel * 2)); - st->pwr_down_mode |=3D ((mode + 1) << (chan->channel * 2)); + st->pwr_down_mode &=3D ~(0x3 << shift); + st->pwr_down_mode |=3D (mode + 1) << shift; =20 return 0; } @@ -57,10 +68,10 @@ static const struct iio_enum ad5686_powerdown_mode_enum= =3D { static ssize_t ad5686_read_dac_powerdown(struct iio_dev *indio_dev, uintptr_t private, const struct iio_chan_spec *chan, char *buf) { + unsigned int shift =3D ad5686_pd_mask_shift(chan); struct ad5686_state *st =3D iio_priv(indio_dev); =20 - return sysfs_emit(buf, "%d\n", !!(st->pwr_down_mask & - (0x3 << (chan->channel * 2)))); + return sysfs_emit(buf, "%d\n", !!(st->pwr_down_mask & (0x3 << shift))); } =20 static ssize_t ad5686_write_dac_powerdown(struct iio_dev *indio_dev, @@ -82,9 +93,9 @@ static ssize_t ad5686_write_dac_powerdown(struct iio_dev = *indio_dev, guard(mutex)(&st->lock); =20 if (readin) - st->pwr_down_mask |=3D (0x3 << (chan->channel * 2)); + st->pwr_down_mask |=3D 0x3 << ad5686_pd_mask_shift(chan); else - st->pwr_down_mask &=3D ~(0x3 << (chan->channel * 2)); + st->pwr_down_mask &=3D ~(0x3 << ad5686_pd_mask_shift(chan)); =20 switch (st->chip_info->regmap_type) { case AD5310_REGMAP: @@ -464,7 +475,7 @@ int ad5686_probe(struct device *dev, { struct ad5686_state *st; struct iio_dev *indio_dev; - unsigned int val, ref_bit_msk; + unsigned int val, ref_bit_msk, shift; bool has_external_vref; u8 cmd; int ret, i; @@ -489,8 +500,14 @@ int ad5686_probe(struct device *dev, st->vref_mv =3D has_external_vref ? ret / 1000 : st->chip_info->int_vref_= mv; =20 /* Set all the power down mode for all channels to 1K pulldown */ - for (i =3D 0; i < st->chip_info->num_channels; i++) - st->pwr_down_mode |=3D (0x01 << (i * 2)); + st->pwr_down_mode =3D ~0U; + st->pwr_down_mask =3D ~0U; + for (i =3D 0; i < st->chip_info->num_channels; i++) { + shift =3D ad5686_pd_mask_shift(&st->chip_info->channels[i]); + st->pwr_down_mask &=3D ~(0x3 << shift); /* powered up state */ + st->pwr_down_mode &=3D ~(0x3 << shift); + st->pwr_down_mode |=3D 0x01 << shift; + } =20 indio_dev->name =3D name; indio_dev->info =3D &ad5686_info; --=20 2.43.0 From nobody Wed Jun 17 01:34:37 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 5CFCE33F394; Tue, 28 Apr 2026 17:02:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777395739; cv=none; b=FWEJ3mc8f8oPP/RBVAG7iSsMKj+IUly0tiN+v2VJgG/iBctBNqsomLThZCIPJEkfwf6OpJ4P5aqR/IcN7TGT2HbFPcUXUX4g3OIUj28nyk95QHAM4WvPL9eET9NK6S1VpHe8QgeCJF/s3nd1oai/fNYMVvD/8arlOA/W16gzW4c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777395739; c=relaxed/simple; bh=Di0rbJjBZ7+zxgWtmdtHMDMcDJL6I9cq5JtCT0X0Y2w=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=O7hUBaSdlZ6PePnhLOzXVofNWDtozN3s9vEcfQBYBiPlvfwk3usoUfuZ/3F4gIci8dmTwtL3vKkQbrtuSMYEYX9VVBFcTfp3qaYtCWvbmELoV0HD6QAAANJwjsOYo/vdtPIfoDpRMfNlFlsyfWaSJXdYyquc/1xpFp7rbM26lSo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=k+S3tcQs; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="k+S3tcQs" Received: by smtp.kernel.org (Postfix) with ESMTPS id 18215C2BCF5; Tue, 28 Apr 2026 17:02:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777395739; bh=Di0rbJjBZ7+zxgWtmdtHMDMcDJL6I9cq5JtCT0X0Y2w=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=k+S3tcQsYdTOnB3jXhGQaxqjZE621cDa3xloWqpznF9kOX45usJZZXbgoxPa8aVQ9 tjV5YJgCqQvr+X6FurWXpuaWtc7pxrbYQAP8YrYzFYbgsehgM93RKkpJl8MmUbBPbA nC2fz+99G5IhkDoE1oikqYEzQ+pfIxUrfTMP6rLyXargcgY6xOK33vScoJjWgf3k/3 UQkyLaMOWqkNH/POiPJbdGZJ4xt1BPr+twBYpeitTXRmntQ7MXI8iTp4w9D+pGLsGC Xmxwy4euVPZzhjTtpjPkgkxOfj6O/XE1yiSxpl13+WMyqiD2NiEefHWnTYyvE5/uyJ o9djRCg+O5ivQ== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0E5FEFF886F; Tue, 28 Apr 2026 17:02:19 +0000 (UTC) From: Rodrigo Alencar via B4 Relay Date: Tue, 28 Apr 2026 18:02:20 +0100 Subject: [PATCH v3 05/11] iio: dac: ad5686: refactor include headers Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260428-ad5686-fixes-v3-5-9cff7bd67a15@analog.com> References: <20260428-ad5686-fixes-v3-0-9cff7bd67a15@analog.com> In-Reply-To: <20260428-ad5686-fixes-v3-0-9cff7bd67a15@analog.com> To: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Stefan Popa , Jonathan Cameron , Greg Kroah-Hartman , Michael Auchter , Jonathan Cameron Cc: Lars-Peter Clausen , Michael Hennerich , Jonathan Cameron , David Lechner , Andy Shevchenko , Rodrigo Alencar X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1777395737; l=2747; i=rodrigo.alencar@analog.com; s=default; h=from:subject:message-id; bh=/NgJQWWQpqiJn15++sviD7O4LcVLZHbwU27WAPG7JPY=; b=emxNeb+hCenwPsJSuNPqLVudkqZppR+16jo6SgXqy9uV7Kvl1Xp0Gss6n/XiwQZy9gKXcfvhw EoXNZLg6hh7BTwI6TDEi7HOiQpEzYeksUIulUwFCYxj07QZ7EAwTn9X X-Developer-Key: i=rodrigo.alencar@analog.com; a=ed25519; pk=ULeHbgU/OYh/PG/4anHDfLgldFItQHAhOktYRVLMFRo= X-Endpoint-Received: by B4 Relay for rodrigo.alencar@analog.com/default with auth_id=561 X-Original-From: Rodrigo Alencar Reply-To: rodrigo.alencar@analog.com From: Rodrigo Alencar Apply IWYU principle, replacing unused/generic headers for specific/missing headers. The resulting include directive lists are sorted accordingly. Signed-off-by: Rodrigo Alencar Reviewed-by: Andy Shevchenko --- drivers/iio/dac/ad5686-spi.c | 9 +++++++-- drivers/iio/dac/ad5686.c | 11 ++++------- drivers/iio/dac/ad5686.h | 5 ++--- drivers/iio/dac/ad5696-i2c.c | 10 +++++++--- 4 files changed, 20 insertions(+), 15 deletions(-) diff --git a/drivers/iio/dac/ad5686-spi.c b/drivers/iio/dac/ad5686-spi.c index df8619e0c092..695125238633 100644 --- a/drivers/iio/dac/ad5686-spi.c +++ b/drivers/iio/dac/ad5686-spi.c @@ -8,11 +8,16 @@ * Copyright 2018 Analog Devices Inc. */ =20 -#include "ad5686.h" - +#include +#include +#include #include #include =20 +#include + +#include "ad5686.h" + static int ad5686_spi_write(struct ad5686_state *st, u8 cmd, u8 addr, u16 val) { diff --git a/drivers/iio/dac/ad5686.c b/drivers/iio/dac/ad5686.c index b31d0ec5415c..70d61ed29aa8 100644 --- a/drivers/iio/dac/ad5686.c +++ b/drivers/iio/dac/ad5686.c @@ -5,17 +5,14 @@ * Copyright 2011 Analog Devices Inc. */ =20 -#include -#include -#include +#include +#include +#include #include -#include -#include -#include #include +#include =20 #include -#include =20 #include "ad5686.h" =20 diff --git a/drivers/iio/dac/ad5686.h b/drivers/iio/dac/ad5686.h index 36e16c5c4581..d08160e7fad9 100644 --- a/drivers/iio/dac/ad5686.h +++ b/drivers/iio/dac/ad5686.h @@ -8,10 +8,9 @@ #ifndef __DRIVERS_IIO_DAC_AD5686_H__ #define __DRIVERS_IIO_DAC_AD5686_H__ =20 -#include -#include +#include #include -#include +#include =20 #include =20 diff --git a/drivers/iio/dac/ad5696-i2c.c b/drivers/iio/dac/ad5696-i2c.c index d3327bca0e07..e7e1b8a6fc71 100644 --- a/drivers/iio/dac/ad5696-i2c.c +++ b/drivers/iio/dac/ad5696-i2c.c @@ -7,10 +7,14 @@ * Copyright 2018 Analog Devices Inc. */ =20 -#include "ad5686.h" - -#include +#include #include +#include +#include + +#include + +#include "ad5686.h" =20 static int ad5686_i2c_read(struct ad5686_state *st, u8 addr) { --=20 2.43.0 From nobody Wed Jun 17 01:34:37 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 5D32133F583; Tue, 28 Apr 2026 17:02:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777395739; cv=none; b=bNxtLF9muLR4LSBlZ0QR3qv6vgqR+N0sln/NDqYgDn3Gclx7Q2YZd51vgHvEHnpgM+g+KhdeThdysmyQ9b8W66wmoK5jaB950a78gZRVD/WmHFiqbDeI40ahsfT9sh+ak2IYRTcWUto8zVdxm53CSNvmB+sfNWdjMKj3ze5IV/w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777395739; c=relaxed/simple; bh=djcPNxbNfy3bJRQr8vChsl30pwwZRUMm6V9DBRBUyag=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=V+heLJoEzrjQnYcBIgoFYqz58rLiGEeGhYPS8BggdGOEvwMlWwoILTIzkNBuI420wYhoXujHZx1Jht91MuEk6YsVzExN+EBoW3wA6+JVKgNtoCTXvSEgEAvOrx+eMxZTJ1CoJvopCdUs8gRmiyaX4+go+IWbSR6KF09RF2TnDqs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=pfi6ZPvX; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="pfi6ZPvX" Received: by smtp.kernel.org (Postfix) with ESMTPS id 25649C2BCC6; Tue, 28 Apr 2026 17:02:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777395739; bh=djcPNxbNfy3bJRQr8vChsl30pwwZRUMm6V9DBRBUyag=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=pfi6ZPvX9kOtSmEGESYjHeDH+fAm3cee2AjSxCkHyzQfdExsxZ7bBnkJg6lEuh8GX iK0P26cNsM1pM2bc9CiCZ2Lw9+ZlCLY1r8o9UpyctZUHC5b5WFzn2GCvzQ28rA/F0D 8S/I4t2LMyEJnVWc1dlzwhQv1aS9RpOfBGgQTUysagSj+mGc3QN/EiXFaOBDDEkFM1 n2tImIuBzTvGZt1YQGSRgt650LFewMdvMz6qmEWJiXGBRig16RHghvlUI9NlEsWO/z /AT/THXOFZwdRlJIds7ZDPDfd+Hz/2aM1TeCfbEn/MH3MD5HrB2udpvbxYMJqmojeS xu2CRv5OOeJeA== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1B924FF886D; Tue, 28 Apr 2026 17:02:19 +0000 (UTC) From: Rodrigo Alencar via B4 Relay Date: Tue, 28 Apr 2026 18:02:21 +0100 Subject: [PATCH v3 06/11] iio: dac: ad5686: remove redundant register definition Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260428-ad5686-fixes-v3-6-9cff7bd67a15@analog.com> References: <20260428-ad5686-fixes-v3-0-9cff7bd67a15@analog.com> In-Reply-To: <20260428-ad5686-fixes-v3-0-9cff7bd67a15@analog.com> To: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Stefan Popa , Jonathan Cameron , Greg Kroah-Hartman , Michael Auchter , Jonathan Cameron Cc: Lars-Peter Clausen , Michael Hennerich , Jonathan Cameron , David Lechner , Andy Shevchenko , Rodrigo Alencar , Andy Shevchenko X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1777395737; l=2960; i=rodrigo.alencar@analog.com; s=default; h=from:subject:message-id; bh=EgOnw3105tfWfYxA7GBWXyqUxPPqPUYs6s70jlrL3cg=; b=JCYKIwSBG+89jl2lsfcBsCx311H8iRVMs62dsgdt+fSI2Okisw6l8wrnP9K+KuLjyUrdh+V8v wTNoePQkSB/Cll+3CWI4UXWFtMhfkj29B1CtNREdLxPwwi8pBpn69ND X-Developer-Key: i=rodrigo.alencar@analog.com; a=ed25519; pk=ULeHbgU/OYh/PG/4anHDfLgldFItQHAhOktYRVLMFRo= X-Endpoint-Received: by B4 Relay for rodrigo.alencar@analog.com/default with auth_id=561 X-Original-From: Rodrigo Alencar Reply-To: rodrigo.alencar@analog.com From: Rodrigo Alencar AD5683_REGMAP and AD5693_REGMAP behave the same way in the common code, and that is because they target single channel devices from the same sub-family. There is no reason to separate them and it will make things simpler when refactoring the chip info table. Reviewed-by: Andy Shevchenko Signed-off-by: Rodrigo Alencar --- drivers/iio/dac/ad5686.c | 19 +++++-------------- drivers/iio/dac/ad5686.h | 2 -- 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/drivers/iio/dac/ad5686.c b/drivers/iio/dac/ad5686.c index 70d61ed29aa8..780967571b09 100644 --- a/drivers/iio/dac/ad5686.c +++ b/drivers/iio/dac/ad5686.c @@ -110,10 +110,6 @@ static ssize_t ad5686_write_dac_powerdown(struct iio_d= ev *indio_dev, if (chan->channel > 0x7) address =3D 0x8; break; - case AD5693_REGMAP: - shift =3D 13; - ref_bit_msk =3D AD5693_REF_BIT_MSK; - break; default: return -EINVAL; } @@ -294,7 +290,7 @@ static const struct ad5686_chip_info ad5686_chip_info_t= bl[] =3D { .channels =3D ad5311r_channels, .int_vref_mv =3D 2500, .num_channels =3D 1, - .regmap_type =3D AD5693_REGMAP, + .regmap_type =3D AD5683_REGMAP, }, [ID_AD5337R] =3D { .channels =3D ad5337r_channels, @@ -416,24 +412,24 @@ static const struct ad5686_chip_info ad5686_chip_info= _tbl[] =3D { .channels =3D ad5691r_channels, .int_vref_mv =3D 2500, .num_channels =3D 1, - .regmap_type =3D AD5693_REGMAP, + .regmap_type =3D AD5683_REGMAP, }, [ID_AD5692R] =3D { .channels =3D ad5692r_channels, .int_vref_mv =3D 2500, .num_channels =3D 1, - .regmap_type =3D AD5693_REGMAP, + .regmap_type =3D AD5683_REGMAP, }, [ID_AD5693] =3D { .channels =3D ad5693_channels, .num_channels =3D 1, - .regmap_type =3D AD5693_REGMAP, + .regmap_type =3D AD5683_REGMAP, }, [ID_AD5693R] =3D { .channels =3D ad5693_channels, .int_vref_mv =3D 2500, .num_channels =3D 1, - .regmap_type =3D AD5693_REGMAP, + .regmap_type =3D AD5683_REGMAP, }, [ID_AD5694] =3D { .channels =3D ad5684_channels, @@ -531,11 +527,6 @@ int ad5686_probe(struct device *dev, cmd =3D AD5686_CMD_INTERNAL_REFER_SETUP; ref_bit_msk =3D AD5686_REF_BIT_MSK; break; - case AD5693_REGMAP: - cmd =3D AD5686_CMD_CONTROL_REG; - ref_bit_msk =3D AD5693_REF_BIT_MSK; - st->use_internal_vref =3D !has_external_vref; - break; default: return -EINVAL; } diff --git a/drivers/iio/dac/ad5686.h b/drivers/iio/dac/ad5686.h index d08160e7fad9..af15994c01ad 100644 --- a/drivers/iio/dac/ad5686.h +++ b/drivers/iio/dac/ad5686.h @@ -46,7 +46,6 @@ #define AD5310_REF_BIT_MSK BIT(8) #define AD5683_REF_BIT_MSK BIT(12) #define AD5686_REF_BIT_MSK BIT(0) -#define AD5693_REF_BIT_MSK BIT(12) =20 /** * ad5686_supported_device_ids: @@ -89,7 +88,6 @@ enum ad5686_regmap_type { AD5310_REGMAP, AD5683_REGMAP, AD5686_REGMAP, - AD5693_REGMAP }; =20 struct ad5686_state; --=20 2.43.0 From nobody Wed Jun 17 01:34:37 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 5C23B33F377; Tue, 28 Apr 2026 17:02:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777395739; cv=none; b=SNjA/IvHv6C+gB+sKHGtDTW/frvs0uEhELXO0IOT9UulSGSJYt95hg2YIS33RH76aum+oBhALmfBgr1RK6pYvolNml6TCKpF8ino9hSNI3dN78/o/nUj+261TlFNiqRF/RGj47KZAV6zFkt/QA7YgzCTJP23Pb9Hs3v+nldkpr4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777395739; c=relaxed/simple; bh=eSXmJXAvr6Pg8geRmG4XmKvBDaIVHNCv4/MolNNTsJs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=KmDn9CjHvh/v3vDfJSzf2Ty7uvtwWDuME2Vn+8wslK52VsZ7C22gmJRAnmsNqXiXEIqLhRp3r4r6xZthTP0wjHhssHnzc0KwgtRou0eX2auDwTWIxuQSUnJDz/K7SGq/vHGoqDIDDAaSUEYE8M4h9NJ/rgWBvwJftvSyEzFYdtE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=E7igIMUy; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="E7igIMUy" Received: by smtp.kernel.org (Postfix) with ESMTPS id 351C0C2BCFC; Tue, 28 Apr 2026 17:02:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777395739; bh=eSXmJXAvr6Pg8geRmG4XmKvBDaIVHNCv4/MolNNTsJs=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=E7igIMUyRKHEF9cNaRPzWtnbwtNt0jJznoj32+CRU4Q3Gpze1j9jSRw1X9Bu8rO4o 9p9E1NlJsifOrZUaHGvZuIMNGv1qkMMXqJP1wJhmbImgWoDbpYKC64dDASL9IgixFK JOvs6f1hrAjqrzOn8rwcMOV2rhke4eKSWZLNHd2+O36bMmnijf3bIxuWWjRnYXcn1z 3Kg8n+W/HVjQ9dAi5yXusbJIwT1sqyqYSQDJkdajmnivNS6J/Ppey4FypjxZL/i4BD 8Wox1W9MzuGX4/Ub7roiX3sCCDkEMBR++wFwRNXDfEAlSMXKoXp1XJsd0RUNVptpgU mp4M4pyuPHEGQ== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2B190FF8877; Tue, 28 Apr 2026 17:02:19 +0000 (UTC) From: Rodrigo Alencar via B4 Relay Date: Tue, 28 Apr 2026 18:02:22 +0100 Subject: [PATCH v3 07/11] iio: dac: ad5686: drop enum id Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260428-ad5686-fixes-v3-7-9cff7bd67a15@analog.com> References: <20260428-ad5686-fixes-v3-0-9cff7bd67a15@analog.com> In-Reply-To: <20260428-ad5686-fixes-v3-0-9cff7bd67a15@analog.com> To: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Stefan Popa , Jonathan Cameron , Greg Kroah-Hartman , Michael Auchter , Jonathan Cameron Cc: Lars-Peter Clausen , Michael Hennerich , Jonathan Cameron , David Lechner , Andy Shevchenko , Rodrigo Alencar X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1777395737; l=20109; i=rodrigo.alencar@analog.com; s=default; h=from:subject:message-id; bh=AYN+/yvV55vPOioI2KX1zdrVxctf1gNKhBfp3+fXQ7U=; b=RgL27kQU9Hh6Lkn3AaLlhvrmMA8ENSPuCuel8f8SsRsBU5+Zkzutx7DQnhHvK+EABDuFt84qq 8z51EaHyxrlAS4QfAawG3QddIh02qd+74lxLJOAu6LaoB5dc5z1x+rQ X-Developer-Key: i=rodrigo.alencar@analog.com; a=ed25519; pk=ULeHbgU/OYh/PG/4anHDfLgldFItQHAhOktYRVLMFRo= X-Endpoint-Received: by B4 Relay for rodrigo.alencar@analog.com/default with auth_id=561 X-Original-From: Rodrigo Alencar Reply-To: rodrigo.alencar@analog.com From: Rodrigo Alencar Split chip info table into separate structs and expose them to the spi i2c drivers. That is the preferrable approach and allows for the drivers to have knowledge of the device info before the common probe function gets called. Those chip info structs may be shared by SPI and I2C driver variants. Channel declaration definitions are grouped according to channel count and DECLARE_AD5693_CHANNELS() macro is renamed to DECLARE_AD5683_CHANNELS() to match the regmap_type enum. Use spi_get_device_match_data() and i2c_get_match_data() to get chip info struct reference, passing it as parameter to the core probe function. Signed-off-by: Rodrigo Alencar Reviewed-by: Andy Shevchenko --- drivers/iio/dac/ad5686-spi.c | 38 +++-- drivers/iio/dac/ad5686.c | 358 ++++++++++++++++++++-------------------= ---- drivers/iio/dac/ad5686.h | 66 ++++---- drivers/iio/dac/ad5696-i2c.c | 65 ++++---- 4 files changed, 241 insertions(+), 286 deletions(-) diff --git a/drivers/iio/dac/ad5686-spi.c b/drivers/iio/dac/ad5686-spi.c index 695125238633..73e6c998add0 100644 --- a/drivers/iio/dac/ad5686-spi.c +++ b/drivers/iio/dac/ad5686-spi.c @@ -94,29 +94,27 @@ static int ad5686_spi_read(struct ad5686_state *st, u8 = addr) =20 static int ad5686_spi_probe(struct spi_device *spi) { - const struct spi_device_id *id =3D spi_get_device_id(spi); - - return ad5686_probe(&spi->dev, id->driver_data, id->name, - ad5686_spi_write, ad5686_spi_read); + return ad5686_probe(&spi->dev, spi_get_device_match_data(spi), + spi->modalias, ad5686_spi_write, ad5686_spi_read); } =20 static const struct spi_device_id ad5686_spi_id[] =3D { - {"ad5310r", ID_AD5310R}, - {"ad5672r", ID_AD5672R}, - {"ad5674r", ID_AD5674R}, - {"ad5676", ID_AD5676}, - {"ad5676r", ID_AD5676R}, - {"ad5679r", ID_AD5679R}, - {"ad5681r", ID_AD5681R}, - {"ad5682r", ID_AD5682R}, - {"ad5683", ID_AD5683}, - {"ad5683r", ID_AD5683R}, - {"ad5684", ID_AD5684}, - {"ad5684r", ID_AD5684R}, - {"ad5685", ID_AD5685R}, /* Does not exist */ - {"ad5685r", ID_AD5685R}, - {"ad5686", ID_AD5686}, - {"ad5686r", ID_AD5686R}, + { "ad5310r", (kernel_ulong_t)&ad5310r_chip_info }, + { "ad5672r", (kernel_ulong_t)&ad5672r_chip_info }, + { "ad5674r", (kernel_ulong_t)&ad5674r_chip_info }, + { "ad5676", (kernel_ulong_t)&ad5676_chip_info }, + { "ad5676r", (kernel_ulong_t)&ad5676r_chip_info }, + { "ad5679r", (kernel_ulong_t)&ad5679r_chip_info }, + { "ad5681r", (kernel_ulong_t)&ad5681r_chip_info }, + { "ad5682r", (kernel_ulong_t)&ad5682r_chip_info }, + { "ad5683", (kernel_ulong_t)&ad5683_chip_info }, + { "ad5683r", (kernel_ulong_t)&ad5683r_chip_info }, + { "ad5684", (kernel_ulong_t)&ad5684_chip_info }, + { "ad5684r", (kernel_ulong_t)&ad5684r_chip_info }, + { "ad5685", (kernel_ulong_t)&ad5685r_chip_info }, /* Does not exist */ + { "ad5685r", (kernel_ulong_t)&ad5685r_chip_info }, + { "ad5686", (kernel_ulong_t)&ad5686_chip_info }, + { "ad5686r", (kernel_ulong_t)&ad5686r_chip_info }, { } }; MODULE_DEVICE_TABLE(spi, ad5686_spi_id); diff --git a/drivers/iio/dac/ad5686.c b/drivers/iio/dac/ad5686.c index 780967571b09..ce0fcb4db065 100644 --- a/drivers/iio/dac/ad5686.c +++ b/drivers/iio/dac/ad5686.c @@ -213,7 +213,7 @@ static const struct iio_chan_spec_ext_info ad5686_ext_i= nfo[] =3D { .ext_info =3D ad5686_ext_info, \ } =20 -#define DECLARE_AD5693_CHANNELS(name, bits, _shift) \ +#define DECLARE_AD5683_CHANNELS(name, bits, _shift) \ static const struct iio_chan_spec name[] =3D { \ AD5868_CHANNEL(0, 0, bits, _shift), \ } @@ -264,205 +264,172 @@ static const struct iio_chan_spec name[] =3D { \ AD5868_CHANNEL(15, 15, bits, _shift), \ } =20 -DECLARE_AD5693_CHANNELS(ad5310r_channels, 10, 2); -DECLARE_AD5693_CHANNELS(ad5311r_channels, 10, 6); +/* single-channel */ +DECLARE_AD5683_CHANNELS(ad5310r_channels, 10, 2); +DECLARE_AD5683_CHANNELS(ad5311r_channels, 10, 6); +DECLARE_AD5683_CHANNELS(ad5681r_channels, 12, 4); +DECLARE_AD5683_CHANNELS(ad5682r_channels, 14, 2); +DECLARE_AD5683_CHANNELS(ad5683r_channels, 16, 0); + +/* dual-channel */ DECLARE_AD5338_CHANNELS(ad5337r_channels, 8, 8); DECLARE_AD5338_CHANNELS(ad5338r_channels, 10, 6); -DECLARE_AD5676_CHANNELS(ad5672_channels, 12, 4); -DECLARE_AD5679_CHANNELS(ad5674r_channels, 12, 4); -DECLARE_AD5676_CHANNELS(ad5676_channels, 16, 0); -DECLARE_AD5679_CHANNELS(ad5679r_channels, 16, 0); -DECLARE_AD5686_CHANNELS(ad5684_channels, 12, 4); -DECLARE_AD5686_CHANNELS(ad5685r_channels, 14, 2); -DECLARE_AD5686_CHANNELS(ad5686_channels, 16, 0); -DECLARE_AD5693_CHANNELS(ad5693_channels, 16, 0); -DECLARE_AD5693_CHANNELS(ad5692r_channels, 14, 2); -DECLARE_AD5693_CHANNELS(ad5691r_channels, 12, 4); =20 -static const struct ad5686_chip_info ad5686_chip_info_tbl[] =3D { - [ID_AD5310R] =3D { - .channels =3D ad5310r_channels, - .int_vref_mv =3D 2500, - .num_channels =3D 1, - .regmap_type =3D AD5310_REGMAP, - }, - [ID_AD5311R] =3D { - .channels =3D ad5311r_channels, - .int_vref_mv =3D 2500, - .num_channels =3D 1, - .regmap_type =3D AD5683_REGMAP, - }, - [ID_AD5337R] =3D { - .channels =3D ad5337r_channels, - .int_vref_mv =3D 2500, - .num_channels =3D 2, - .regmap_type =3D AD5686_REGMAP, - }, - [ID_AD5338R] =3D { - .channels =3D ad5338r_channels, - .int_vref_mv =3D 2500, - .num_channels =3D 2, - .regmap_type =3D AD5686_REGMAP, - }, - [ID_AD5671R] =3D { - .channels =3D ad5672_channels, - .int_vref_mv =3D 2500, - .num_channels =3D 8, - .regmap_type =3D AD5686_REGMAP, - }, - [ID_AD5672R] =3D { - .channels =3D ad5672_channels, - .int_vref_mv =3D 2500, - .num_channels =3D 8, - .regmap_type =3D AD5686_REGMAP, - }, - [ID_AD5673R] =3D { - .channels =3D ad5674r_channels, - .int_vref_mv =3D 2500, - .num_channels =3D 16, - .regmap_type =3D AD5686_REGMAP, - }, - [ID_AD5674R] =3D { - .channels =3D ad5674r_channels, - .int_vref_mv =3D 2500, - .num_channels =3D 16, - .regmap_type =3D AD5686_REGMAP, - }, - [ID_AD5675R] =3D { - .channels =3D ad5676_channels, - .int_vref_mv =3D 2500, - .num_channels =3D 8, - .regmap_type =3D AD5686_REGMAP, - }, - [ID_AD5676] =3D { - .channels =3D ad5676_channels, - .num_channels =3D 8, - .regmap_type =3D AD5686_REGMAP, - }, - [ID_AD5676R] =3D { - .channels =3D ad5676_channels, - .int_vref_mv =3D 2500, - .num_channels =3D 8, - .regmap_type =3D AD5686_REGMAP, - }, - [ID_AD5677R] =3D { - .channels =3D ad5679r_channels, - .int_vref_mv =3D 2500, - .num_channels =3D 16, - .regmap_type =3D AD5686_REGMAP, - }, - [ID_AD5679R] =3D { - .channels =3D ad5679r_channels, - .int_vref_mv =3D 2500, - .num_channels =3D 16, - .regmap_type =3D AD5686_REGMAP, - }, - [ID_AD5681R] =3D { - .channels =3D ad5691r_channels, - .int_vref_mv =3D 2500, - .num_channels =3D 1, - .regmap_type =3D AD5683_REGMAP, - }, - [ID_AD5682R] =3D { - .channels =3D ad5692r_channels, - .int_vref_mv =3D 2500, - .num_channels =3D 1, - .regmap_type =3D AD5683_REGMAP, - }, - [ID_AD5683] =3D { - .channels =3D ad5693_channels, - .num_channels =3D 1, - .regmap_type =3D AD5683_REGMAP, - }, - [ID_AD5683R] =3D { - .channels =3D ad5693_channels, - .int_vref_mv =3D 2500, - .num_channels =3D 1, - .regmap_type =3D AD5683_REGMAP, - }, - [ID_AD5684] =3D { - .channels =3D ad5684_channels, - .num_channels =3D 4, - .regmap_type =3D AD5686_REGMAP, - }, - [ID_AD5684R] =3D { - .channels =3D ad5684_channels, - .int_vref_mv =3D 2500, - .num_channels =3D 4, - .regmap_type =3D AD5686_REGMAP, - }, - [ID_AD5685R] =3D { - .channels =3D ad5685r_channels, - .int_vref_mv =3D 2500, - .num_channels =3D 4, - .regmap_type =3D AD5686_REGMAP, - }, - [ID_AD5686] =3D { - .channels =3D ad5686_channels, - .num_channels =3D 4, - .regmap_type =3D AD5686_REGMAP, - }, - [ID_AD5686R] =3D { - .channels =3D ad5686_channels, - .int_vref_mv =3D 2500, - .num_channels =3D 4, - .regmap_type =3D AD5686_REGMAP, - }, - [ID_AD5691R] =3D { - .channels =3D ad5691r_channels, - .int_vref_mv =3D 2500, - .num_channels =3D 1, - .regmap_type =3D AD5683_REGMAP, - }, - [ID_AD5692R] =3D { - .channels =3D ad5692r_channels, - .int_vref_mv =3D 2500, - .num_channels =3D 1, - .regmap_type =3D AD5683_REGMAP, - }, - [ID_AD5693] =3D { - .channels =3D ad5693_channels, - .num_channels =3D 1, - .regmap_type =3D AD5683_REGMAP, - }, - [ID_AD5693R] =3D { - .channels =3D ad5693_channels, - .int_vref_mv =3D 2500, - .num_channels =3D 1, - .regmap_type =3D AD5683_REGMAP, - }, - [ID_AD5694] =3D { - .channels =3D ad5684_channels, - .num_channels =3D 4, - .regmap_type =3D AD5686_REGMAP, - }, - [ID_AD5694R] =3D { - .channels =3D ad5684_channels, - .int_vref_mv =3D 2500, - .num_channels =3D 4, - .regmap_type =3D AD5686_REGMAP, - }, - [ID_AD5695R] =3D { - .channels =3D ad5685r_channels, - .int_vref_mv =3D 2500, - .num_channels =3D 4, - .regmap_type =3D AD5686_REGMAP, - }, - [ID_AD5696] =3D { - .channels =3D ad5686_channels, - .num_channels =3D 4, - .regmap_type =3D AD5686_REGMAP, - }, - [ID_AD5696R] =3D { - .channels =3D ad5686_channels, - .int_vref_mv =3D 2500, - .num_channels =3D 4, - .regmap_type =3D AD5686_REGMAP, - }, +/* quad-channel */ +DECLARE_AD5686_CHANNELS(ad5684r_channels, 12, 4); +DECLARE_AD5686_CHANNELS(ad5685r_channels, 14, 2); +DECLARE_AD5686_CHANNELS(ad5686r_channels, 16, 0); + +/* 8-channel */ +DECLARE_AD5676_CHANNELS(ad5672r_channels, 12, 4); +DECLARE_AD5676_CHANNELS(ad5676r_channels, 16, 0); + +/* 16-channel */ +DECLARE_AD5679_CHANNELS(ad5674r_channels, 12, 4); +DECLARE_AD5679_CHANNELS(ad5679r_channels, 16, 0); + +const struct ad5686_chip_info ad5310r_chip_info =3D { + .channels =3D ad5310r_channels, + .int_vref_mv =3D 2500, + .num_channels =3D 1, + .regmap_type =3D AD5310_REGMAP, }; +EXPORT_SYMBOL_NS_GPL(ad5310r_chip_info, "IIO_AD5686"); + +const struct ad5686_chip_info ad5311r_chip_info =3D { + .channels =3D ad5311r_channels, + .int_vref_mv =3D 2500, + .num_channels =3D 1, + .regmap_type =3D AD5683_REGMAP, +}; +EXPORT_SYMBOL_NS_GPL(ad5311r_chip_info, "IIO_AD5686"); + +const struct ad5686_chip_info ad5681r_chip_info =3D { + .channels =3D ad5681r_channels, + .int_vref_mv =3D 2500, + .num_channels =3D 1, + .regmap_type =3D AD5683_REGMAP, +}; +EXPORT_SYMBOL_NS_GPL(ad5681r_chip_info, "IIO_AD5686"); + +const struct ad5686_chip_info ad5682r_chip_info =3D { + .channels =3D ad5682r_channels, + .int_vref_mv =3D 2500, + .num_channels =3D 1, + .regmap_type =3D AD5683_REGMAP, +}; +EXPORT_SYMBOL_NS_GPL(ad5682r_chip_info, "IIO_AD5686"); + +const struct ad5686_chip_info ad5683_chip_info =3D { + .channels =3D ad5683r_channels, + .num_channels =3D 1, + .regmap_type =3D AD5683_REGMAP, +}; +EXPORT_SYMBOL_NS_GPL(ad5683_chip_info, "IIO_AD5686"); + +const struct ad5686_chip_info ad5683r_chip_info =3D { + .channels =3D ad5683r_channels, + .int_vref_mv =3D 2500, + .num_channels =3D 1, + .regmap_type =3D AD5683_REGMAP, +}; +EXPORT_SYMBOL_NS_GPL(ad5683r_chip_info, "IIO_AD5686"); + +const struct ad5686_chip_info ad5337r_chip_info =3D { + .channels =3D ad5337r_channels, + .int_vref_mv =3D 2500, + .num_channels =3D 2, + .regmap_type =3D AD5686_REGMAP, +}; +EXPORT_SYMBOL_NS_GPL(ad5337r_chip_info, "IIO_AD5686"); + +const struct ad5686_chip_info ad5338r_chip_info =3D { + .channels =3D ad5338r_channels, + .int_vref_mv =3D 2500, + .num_channels =3D 2, + .regmap_type =3D AD5686_REGMAP, +}; +EXPORT_SYMBOL_NS_GPL(ad5338r_chip_info, "IIO_AD5686"); + +const struct ad5686_chip_info ad5684_chip_info =3D { + .channels =3D ad5684r_channels, + .num_channels =3D 4, + .regmap_type =3D AD5686_REGMAP, +}; +EXPORT_SYMBOL_NS_GPL(ad5684_chip_info, "IIO_AD5686"); + +const struct ad5686_chip_info ad5684r_chip_info =3D { + .channels =3D ad5684r_channels, + .int_vref_mv =3D 2500, + .num_channels =3D 4, + .regmap_type =3D AD5686_REGMAP, +}; +EXPORT_SYMBOL_NS_GPL(ad5684r_chip_info, "IIO_AD5686"); + +const struct ad5686_chip_info ad5685r_chip_info =3D { + .channels =3D ad5685r_channels, + .int_vref_mv =3D 2500, + .num_channels =3D 4, + .regmap_type =3D AD5686_REGMAP, +}; +EXPORT_SYMBOL_NS_GPL(ad5685r_chip_info, "IIO_AD5686"); + +const struct ad5686_chip_info ad5686_chip_info =3D { + .channels =3D ad5686r_channels, + .num_channels =3D 4, + .regmap_type =3D AD5686_REGMAP, +}; +EXPORT_SYMBOL_NS_GPL(ad5686_chip_info, "IIO_AD5686"); + +const struct ad5686_chip_info ad5686r_chip_info =3D { + .channels =3D ad5686r_channels, + .int_vref_mv =3D 2500, + .num_channels =3D 4, + .regmap_type =3D AD5686_REGMAP, +}; +EXPORT_SYMBOL_NS_GPL(ad5686r_chip_info, "IIO_AD5686"); + +const struct ad5686_chip_info ad5672r_chip_info =3D { + .channels =3D ad5672r_channels, + .int_vref_mv =3D 2500, + .num_channels =3D 8, + .regmap_type =3D AD5686_REGMAP, +}; +EXPORT_SYMBOL_NS_GPL(ad5672r_chip_info, "IIO_AD5686"); + +const struct ad5686_chip_info ad5676_chip_info =3D { + .channels =3D ad5676r_channels, + .num_channels =3D 8, + .regmap_type =3D AD5686_REGMAP, +}; +EXPORT_SYMBOL_NS_GPL(ad5676_chip_info, "IIO_AD5686"); + +const struct ad5686_chip_info ad5676r_chip_info =3D { + .channels =3D ad5676r_channels, + .int_vref_mv =3D 2500, + .num_channels =3D 8, + .regmap_type =3D AD5686_REGMAP, +}; +EXPORT_SYMBOL_NS_GPL(ad5676r_chip_info, "IIO_AD5686"); + +const struct ad5686_chip_info ad5674r_chip_info =3D { + .channels =3D ad5674r_channels, + .int_vref_mv =3D 2500, + .num_channels =3D 16, + .regmap_type =3D AD5686_REGMAP, +}; +EXPORT_SYMBOL_NS_GPL(ad5674r_chip_info, "IIO_AD5686"); + +const struct ad5686_chip_info ad5679r_chip_info =3D { + .channels =3D ad5679r_channels, + .int_vref_mv =3D 2500, + .num_channels =3D 16, + .regmap_type =3D AD5686_REGMAP, +}; +EXPORT_SYMBOL_NS_GPL(ad5679r_chip_info, "IIO_AD5686"); =20 int ad5686_probe(struct device *dev, - enum ad5686_supported_device_ids chip_type, + const struct ad5686_chip_info *chip_info, const char *name, ad5686_write_func write, ad5686_read_func read) { @@ -482,8 +449,7 @@ int ad5686_probe(struct device *dev, st->dev =3D dev; st->write =3D write; st->read =3D read; - - st->chip_info =3D &ad5686_chip_info_tbl[chip_type]; + st->chip_info =3D chip_info; =20 ret =3D devm_regulator_get_enable_read_voltage(dev, "vcc"); if (ret < 0 && ret !=3D -ENODEV) diff --git a/drivers/iio/dac/ad5686.h b/drivers/iio/dac/ad5686.h index af15994c01ad..caadc7403da1 100644 --- a/drivers/iio/dac/ad5686.h +++ b/drivers/iio/dac/ad5686.h @@ -47,42 +47,6 @@ #define AD5683_REF_BIT_MSK BIT(12) #define AD5686_REF_BIT_MSK BIT(0) =20 -/** - * ad5686_supported_device_ids: - */ -enum ad5686_supported_device_ids { - ID_AD5310R, - ID_AD5311R, - ID_AD5337R, - ID_AD5338R, - ID_AD5671R, - ID_AD5672R, - ID_AD5673R, - ID_AD5674R, - ID_AD5675R, - ID_AD5676, - ID_AD5676R, - ID_AD5677R, - ID_AD5679R, - ID_AD5681R, - ID_AD5682R, - ID_AD5683, - ID_AD5683R, - ID_AD5684, - ID_AD5684R, - ID_AD5685R, - ID_AD5686, - ID_AD5686R, - ID_AD5691R, - ID_AD5692R, - ID_AD5693, - ID_AD5693R, - ID_AD5694, - ID_AD5694R, - ID_AD5695R, - ID_AD5696, - ID_AD5696R, -}; =20 enum ad5686_regmap_type { AD5310_REGMAP, @@ -112,6 +76,34 @@ struct ad5686_chip_info { enum ad5686_regmap_type regmap_type; }; =20 +/* single-channel instances */ +extern const struct ad5686_chip_info ad5310r_chip_info; +extern const struct ad5686_chip_info ad5311r_chip_info; +extern const struct ad5686_chip_info ad5681r_chip_info; +extern const struct ad5686_chip_info ad5682r_chip_info; +extern const struct ad5686_chip_info ad5683_chip_info; +extern const struct ad5686_chip_info ad5683r_chip_info; + +/* dual-channel instances */ +extern const struct ad5686_chip_info ad5337r_chip_info; +extern const struct ad5686_chip_info ad5338r_chip_info; + +/* quad-channel instances */ +extern const struct ad5686_chip_info ad5684_chip_info; +extern const struct ad5686_chip_info ad5684r_chip_info; +extern const struct ad5686_chip_info ad5685r_chip_info; +extern const struct ad5686_chip_info ad5686_chip_info; +extern const struct ad5686_chip_info ad5686r_chip_info; + +/* 8-channel instances */ +extern const struct ad5686_chip_info ad5672r_chip_info; +extern const struct ad5686_chip_info ad5676_chip_info; +extern const struct ad5686_chip_info ad5676r_chip_info; + +/* 16-channel instances */ +extern const struct ad5686_chip_info ad5674r_chip_info; +extern const struct ad5686_chip_info ad5679r_chip_info; + /** * struct ad5686_state - driver instance specific data * @spi: spi_device @@ -149,7 +141,7 @@ struct ad5686_state { =20 =20 int ad5686_probe(struct device *dev, - enum ad5686_supported_device_ids chip_type, + const struct ad5686_chip_info *chip_info, const char *name, ad5686_write_func write, ad5686_read_func read); =20 diff --git a/drivers/iio/dac/ad5696-i2c.c b/drivers/iio/dac/ad5696-i2c.c index e7e1b8a6fc71..fd047c01f8f6 100644 --- a/drivers/iio/dac/ad5696-i2c.c +++ b/drivers/iio/dac/ad5696-i2c.c @@ -64,47 +64,46 @@ static int ad5686_i2c_write(struct ad5686_state *st, =20 static int ad5686_i2c_probe(struct i2c_client *i2c) { - const struct i2c_device_id *id =3D i2c_client_get_device_id(i2c); - return ad5686_probe(&i2c->dev, id->driver_data, id->name, - ad5686_i2c_write, ad5686_i2c_read); + return ad5686_probe(&i2c->dev, i2c_get_match_data(i2c), + i2c->name, ad5686_i2c_write, ad5686_i2c_read); } =20 static const struct i2c_device_id ad5686_i2c_id[] =3D { - {"ad5311r", ID_AD5311R}, - {"ad5337r", ID_AD5337R}, - {"ad5338r", ID_AD5338R}, - {"ad5671r", ID_AD5671R}, - {"ad5673r", ID_AD5673R}, - {"ad5675r", ID_AD5675R}, - {"ad5677r", ID_AD5677R}, - {"ad5691r", ID_AD5691R}, - {"ad5692r", ID_AD5692R}, - {"ad5693", ID_AD5693}, - {"ad5693r", ID_AD5693R}, - {"ad5694", ID_AD5694}, - {"ad5694r", ID_AD5694R}, - {"ad5695r", ID_AD5695R}, - {"ad5696", ID_AD5696}, - {"ad5696r", ID_AD5696R}, + { "ad5311r", (kernel_ulong_t)&ad5311r_chip_info }, + { "ad5337r", (kernel_ulong_t)&ad5337r_chip_info }, + { "ad5338r", (kernel_ulong_t)&ad5338r_chip_info }, + { "ad5671r", (kernel_ulong_t)&ad5672r_chip_info }, + { "ad5673r", (kernel_ulong_t)&ad5674r_chip_info }, + { "ad5675r", (kernel_ulong_t)&ad5676r_chip_info }, + { "ad5677r", (kernel_ulong_t)&ad5679r_chip_info }, + { "ad5691r", (kernel_ulong_t)&ad5681r_chip_info }, + { "ad5692r", (kernel_ulong_t)&ad5682r_chip_info }, + { "ad5693", (kernel_ulong_t)&ad5683_chip_info }, + { "ad5693r", (kernel_ulong_t)&ad5683r_chip_info }, + { "ad5694", (kernel_ulong_t)&ad5684_chip_info }, + { "ad5694r", (kernel_ulong_t)&ad5684r_chip_info }, + { "ad5695r", (kernel_ulong_t)&ad5685r_chip_info }, + { "ad5696", (kernel_ulong_t)&ad5686_chip_info }, + { "ad5696r", (kernel_ulong_t)&ad5686r_chip_info }, { } }; MODULE_DEVICE_TABLE(i2c, ad5686_i2c_id); =20 static const struct of_device_id ad5686_of_match[] =3D { - { .compatible =3D "adi,ad5311r" }, - { .compatible =3D "adi,ad5337r" }, - { .compatible =3D "adi,ad5338r" }, - { .compatible =3D "adi,ad5671r" }, - { .compatible =3D "adi,ad5675r" }, - { .compatible =3D "adi,ad5691r" }, - { .compatible =3D "adi,ad5692r" }, - { .compatible =3D "adi,ad5693" }, - { .compatible =3D "adi,ad5693r" }, - { .compatible =3D "adi,ad5694" }, - { .compatible =3D "adi,ad5694r" }, - { .compatible =3D "adi,ad5695r" }, - { .compatible =3D "adi,ad5696" }, - { .compatible =3D "adi,ad5696r" }, + { .compatible =3D "adi,ad5311r", .data =3D &ad5311r_chip_info }, + { .compatible =3D "adi,ad5337r", .data =3D &ad5337r_chip_info }, + { .compatible =3D "adi,ad5338r", .data =3D &ad5338r_chip_info }, + { .compatible =3D "adi,ad5671r", .data =3D &ad5672r_chip_info }, + { .compatible =3D "adi,ad5675r", .data =3D &ad5676r_chip_info }, + { .compatible =3D "adi,ad5691r", .data =3D &ad5681r_chip_info }, + { .compatible =3D "adi,ad5692r", .data =3D &ad5682r_chip_info }, + { .compatible =3D "adi,ad5693", .data =3D &ad5683_chip_info }, + { .compatible =3D "adi,ad5693r", .data =3D &ad5683r_chip_info }, + { .compatible =3D "adi,ad5694", .data =3D &ad5684_chip_info }, + { .compatible =3D "adi,ad5694r", .data =3D &ad5684r_chip_info }, + { .compatible =3D "adi,ad5695r", .data =3D &ad5685r_chip_info }, + { .compatible =3D "adi,ad5696", .data =3D &ad5686_chip_info }, + { .compatible =3D "adi,ad5696r", .data =3D &ad5686r_chip_info }, { } }; MODULE_DEVICE_TABLE(of, ad5686_of_match); --=20 2.43.0 From nobody Wed Jun 17 01:34:37 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 6E16133F5B4; Tue, 28 Apr 2026 17:02:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777395739; cv=none; b=Nkb7g8aHS/I1gXaDvaFSdeDEAUMXz02Isjki+XEPZpMzdCntRu6CPgEVNeuKFCqq/LxMJD8fR7vM2NziI948YdoFt5eL29U0LWgMGyad9HmLW321oGJ16DLdArZcck5ZzlkNcUNQLbgbm6vw0YXny9pocOfAVFyH2HHZxUK/2C0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777395739; c=relaxed/simple; bh=zRqZGudlCy/r9rTbDAr1hiuQyH3vkLVcQSg7ikAa438=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=YNW+tQo4xK3yzkPd28LTO/VY/6p5g8MLQbMgNX2LHvWt1D/2McodVcYsliR0UtPWXom0/yn7IDL4gXAHDUy4qj5FqZFYcNYzbrLu0D5bA76KHDMYtBttAvegLpw/g+AJJ66e0uXwt+cKXyWu9zRvEeLE3o9xvyHw7HhYCkh8sb0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=evxGXUel; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="evxGXUel" Received: by smtp.kernel.org (Postfix) with ESMTPS id 479A3C2BCB9; Tue, 28 Apr 2026 17:02:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777395739; bh=zRqZGudlCy/r9rTbDAr1hiuQyH3vkLVcQSg7ikAa438=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=evxGXUelscqDuLtHvqHLxABvSH/ZVFf/H8q09TS1y7R9Qj31rnBspOSz5Mi9T+/GP 3zQVcGxWMhxCR/R+691XXwhp9vGsPbLvejfJlpnIuZsGJHoDpwnSrjZlIWF8gZ+pwd k/j3mSuPtb2RkGtckVdN4G2CypLLSq8cisS1ajB7XF0xBWp4/6fN6ofAUJVWi6TlDQ eSDQIPeU8EIlM1pGSnBAl7j/eA3uSkYUfl860MfU29Op6i0th6AgX6CNpeWrAq1O/4 /GlvEIeS6lRYMlFkLEhMDw2OgE9SHJ9BvDcul1nvi/t6hFyqMW4vffoUMFrodYLvwl yDKQoISdzpMYg== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3A6BFFF885A; Tue, 28 Apr 2026 17:02:19 +0000 (UTC) From: Rodrigo Alencar via B4 Relay Date: Tue, 28 Apr 2026 18:02:23 +0100 Subject: [PATCH v3 08/11] iio: dac: ad5686: add of_match table to the spi driver Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260428-ad5686-fixes-v3-8-9cff7bd67a15@analog.com> References: <20260428-ad5686-fixes-v3-0-9cff7bd67a15@analog.com> In-Reply-To: <20260428-ad5686-fixes-v3-0-9cff7bd67a15@analog.com> To: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Stefan Popa , Jonathan Cameron , Greg Kroah-Hartman , Michael Auchter , Jonathan Cameron Cc: Lars-Peter Clausen , Michael Hennerich , Jonathan Cameron , David Lechner , Andy Shevchenko , Rodrigo Alencar X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1777395737; l=1849; i=rodrigo.alencar@analog.com; s=default; h=from:subject:message-id; bh=LohyswX/WbRmKSz4Qx5zIV8Oktgz71bUWV/iKlpzTJk=; b=i19UJ2ZBfO6R7+G27NkSInwJS1nD24UQPSwnQnG0hMD1j0ZYFsuKjVoF8dQ7Pi5CyvAHqtCxf VOEoVem4Zo2B/fhf/bNS8qPb63aVBR7ka0YLhZbd/3AFRjQ6YCM5Txz X-Developer-Key: i=rodrigo.alencar@analog.com; a=ed25519; pk=ULeHbgU/OYh/PG/4anHDfLgldFItQHAhOktYRVLMFRo= X-Endpoint-Received: by B4 Relay for rodrigo.alencar@analog.com/default with auth_id=561 X-Original-From: Rodrigo Alencar Reply-To: rodrigo.alencar@analog.com From: Rodrigo Alencar Add of_match table for the SPI device variants to be consistent with the AD5696 I2C driver. Signed-off-by: Rodrigo Alencar Reviewed-by: Andy Shevchenko --- drivers/iio/dac/ad5686-spi.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/drivers/iio/dac/ad5686-spi.c b/drivers/iio/dac/ad5686-spi.c index 73e6c998add0..8fef0e6d33ff 100644 --- a/drivers/iio/dac/ad5686-spi.c +++ b/drivers/iio/dac/ad5686-spi.c @@ -119,9 +119,30 @@ static const struct spi_device_id ad5686_spi_id[] =3D { }; MODULE_DEVICE_TABLE(spi, ad5686_spi_id); =20 +static const struct of_device_id ad5686_of_match[] =3D { + { .compatible =3D "adi,ad5310r", .data =3D &ad5310r_chip_info }, + { .compatible =3D "adi,ad5672r", .data =3D &ad5672r_chip_info }, + { .compatible =3D "adi,ad5674r", .data =3D &ad5674r_chip_info }, + { .compatible =3D "adi,ad5676", .data =3D &ad5676_chip_info }, + { .compatible =3D "adi,ad5676r", .data =3D &ad5676r_chip_info }, + { .compatible =3D "adi,ad5679r", .data =3D &ad5679r_chip_info }, + { .compatible =3D "adi,ad5681r", .data =3D &ad5681r_chip_info }, + { .compatible =3D "adi,ad5682r", .data =3D &ad5682r_chip_info }, + { .compatible =3D "adi,ad5683", .data =3D &ad5683_chip_info }, + { .compatible =3D "adi,ad5683r", .data =3D &ad5683r_chip_info }, + { .compatible =3D "adi,ad5684", .data =3D &ad5684_chip_info }, + { .compatible =3D "adi,ad5684r", .data =3D &ad5684r_chip_info }, + { .compatible =3D "adi,ad5685r", .data =3D &ad5685r_chip_info }, + { .compatible =3D "adi,ad5686", .data =3D &ad5686_chip_info }, + { .compatible =3D "adi,ad5686r", .data =3D &ad5686r_chip_info }, + { } +}; +MODULE_DEVICE_TABLE(of, ad5686_of_match); + static struct spi_driver ad5686_spi_driver =3D { .driver =3D { .name =3D "ad5686", + .of_match_table =3D ad5686_of_match, }, .probe =3D ad5686_spi_probe, .id_table =3D ad5686_spi_id, --=20 2.43.0 From nobody Wed Jun 17 01:34:37 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 6D6F533F595; Tue, 28 Apr 2026 17:02:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777395739; cv=none; b=ejuSjecgVOGxvKPT6BdkS0NPbwiLLK5TnpsqUqVhJdlWZ9Q8OslWQ46UaAnPHsivVb53ZrGq8W35jCet9QDJO0nbJgm3T3GfCXE++DdpYFcR2JYAG2vUL9ulvdyEgJtKn0neA2LGmXaUN39nPFBJ9xG75fxjaQgdbSIXTFymor4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777395739; c=relaxed/simple; bh=krVf7p9/XSPfP4ZSXyTzfe8GH35a+0rXDoreKCFWalU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ewnO4iwa3Og9ysUcKQAXLviuM7GpThZMLT1nZ8ULBer3OK6oRgVBfrQ/XF38hPGOfPtJ9CgKZR77/smOuXsDtz8Pdy0aWd4Ki89157DRgfHxtvjfvgdpm9YaEcRL0U+g9JMs1jzaG8yYZU9hr0JtQ6u0MQ6DYB51FopLEVjO7lE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=TCEYzCod; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="TCEYzCod" Received: by smtp.kernel.org (Postfix) with ESMTPS id 505CBC2BCF4; Tue, 28 Apr 2026 17:02:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777395739; bh=krVf7p9/XSPfP4ZSXyTzfe8GH35a+0rXDoreKCFWalU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=TCEYzCodqnOyok4lr0w++nzAR1pI7/WSJxwlShZpgIoPB6qlaf5krnSAnLay7u0BS sRW7E2pkJTQR81P4OuY1jYSz/YVw535KP4jJv0h4HgS2Ky9OM693JEyCQ/dvOt6/CS 31JXe1LdjLMJgOGlZGtbGqgyLDA7kcCZIV7wp2hezLYOJYPt6KbCsZrpAulcoM/bb8 NylhTgT4KFsJAKVb2MljtepqEKCgL6JWX+oCWJDRHSrwNrJCWh2NUJ2rJhE8+cEWXD pyv0+v/+vKd9MMdpMla9hJYCqbVvShpkVVbb5fjqSbpAKY8MAJ7Dx8k0njbDgCfD5m dA9lJkgA1tBzw== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 49EF2FF8878; Tue, 28 Apr 2026 17:02:19 +0000 (UTC) From: Rodrigo Alencar via B4 Relay Date: Tue, 28 Apr 2026 18:02:24 +0100 Subject: [PATCH v3 09/11] iio: dac: ad5686: add control_sync() for single-channel devices Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260428-ad5686-fixes-v3-9-9cff7bd67a15@analog.com> References: <20260428-ad5686-fixes-v3-0-9cff7bd67a15@analog.com> In-Reply-To: <20260428-ad5686-fixes-v3-0-9cff7bd67a15@analog.com> To: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Stefan Popa , Jonathan Cameron , Greg Kroah-Hartman , Michael Auchter , Jonathan Cameron Cc: Lars-Peter Clausen , Michael Hennerich , Jonathan Cameron , David Lechner , Andy Shevchenko , Rodrigo Alencar X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1777395737; l=6004; i=rodrigo.alencar@analog.com; s=default; h=from:subject:message-id; bh=mlPsPJGibSn9jC1Ml4iLk03xG0zqfBHDGLMjfkzY0iQ=; b=js4HiExFXCHo96955rM5EBJ0tge7QwFCjlAg19mEciZxCDqMs7PVHehnoXdhSCQ9tmcyO1J5c iV1pwrMxXuxCW6nxk1FMDEi33m94P+ATkBOKLMWiMl4V2Ie5wxadHuN X-Developer-Key: i=rodrigo.alencar@analog.com; a=ed25519; pk=ULeHbgU/OYh/PG/4anHDfLgldFItQHAhOktYRVLMFRo= X-Endpoint-Received: by B4 Relay for rodrigo.alencar@analog.com/default with auth_id=561 X-Original-From: Rodrigo Alencar Reply-To: rodrigo.alencar@analog.com From: Rodrigo Alencar Create ad5310_control_sync() and ad5683_control_sync() functions that properly consumes the mask definitions with FIELD_PREP(). This allows to reuse a function that updates the control register with cached values, without relying on confusing logic that depends on st->use_internal_vref, which is initialized earlier in ad5686_probe() because it is also applicable to the AD5686_REGMAP case, removing the need for the has_external_vref. The change cleans up ad5686_write_dac_powerdown() and ad5686_probe(), organizing the code for feature extension, e.g. gain control support for single-channel devices. Signed-off-by: Rodrigo Alencar Reviewed-by: Andy Shevchenko --- drivers/iio/dac/ad5686.c | 88 ++++++++++++++++++++++++++++----------------= ---- drivers/iio/dac/ad5686.h | 4 +++ 2 files changed, 56 insertions(+), 36 deletions(-) diff --git a/drivers/iio/dac/ad5686.c b/drivers/iio/dac/ad5686.c index ce0fcb4db065..73a3178ac2b8 100644 --- a/drivers/iio/dac/ad5686.c +++ b/drivers/iio/dac/ad5686.c @@ -6,11 +6,13 @@ */ =20 #include +#include #include #include #include #include #include +#include =20 #include =20 @@ -22,6 +24,24 @@ static const char * const ad5686_powerdown_modes[] =3D { "three_state" }; =20 +static int ad5310_control_sync(struct ad5686_state *st) +{ + unsigned int pd_val =3D st->pwr_down_mask & st->pwr_down_mode; + + return st->write(st, AD5686_CMD_CONTROL_REG, 0, + FIELD_PREP(AD5310_PD_MSK, pd_val) | + FIELD_PREP(AD5310_REF_BIT_MSK, st->use_internal_vref ? 0 : 1)); +} + +static int ad5683_control_sync(struct ad5686_state *st) +{ + unsigned int pd_val =3D st->pwr_down_mask & st->pwr_down_mode; + + return st->write(st, AD5686_CMD_CONTROL_REG, 0, + FIELD_PREP(AD5683_PD_MSK, pd_val) | + FIELD_PREP(AD5683_REF_BIT_MSK, st->use_internal_vref ? 0 : 1)); +} + static inline unsigned int ad5686_pd_mask_shift(const struct iio_chan_spec= *chan) { if (chan->channel =3D=3D chan->address) @@ -80,8 +100,8 @@ static ssize_t ad5686_write_dac_powerdown(struct iio_dev= *indio_dev, bool readin; int ret; struct ad5686_state *st =3D iio_priv(indio_dev); - unsigned int val, ref_bit_msk; - u8 shift, address =3D 0; + unsigned int val; + u8 address; =20 ret =3D kstrtobool(buf, &readin); if (ret) @@ -96,32 +116,34 @@ static ssize_t ad5686_write_dac_powerdown(struct iio_d= ev *indio_dev, =20 switch (st->chip_info->regmap_type) { case AD5310_REGMAP: - shift =3D 9; - ref_bit_msk =3D AD5310_REF_BIT_MSK; + ret =3D ad5310_control_sync(st); + if (ret) + return ret; break; case AD5683_REGMAP: - shift =3D 13; - ref_bit_msk =3D AD5683_REF_BIT_MSK; + ret =3D ad5683_control_sync(st); + if (ret) + return ret; break; case AD5686_REGMAP: - shift =3D 0; - ref_bit_msk =3D 0; /* AD5674R/AD5679R have 16 channels and 2 powerdown registers */ - if (chan->channel > 0x7) + val =3D st->pwr_down_mask & st->pwr_down_mode; + if (chan->channel > 0x7) { address =3D 0x8; + val =3D upper_16_bits(val); + } else { + address =3D 0x0; + val =3D lower_16_bits(val); + } + ret =3D st->write(st, AD5686_CMD_POWERDOWN_DAC, address, val); + if (ret) + return ret; break; default: return -EINVAL; } =20 - val =3D ((st->pwr_down_mask & st->pwr_down_mode) << shift); - if (!st->use_internal_vref) - val |=3D ref_bit_msk; - - ret =3D st->write(st, AD5686_CMD_POWERDOWN_DAC, - address, val >> (address * 2)); - - return ret ? ret : len; + return len; } =20 static int ad5686_read_raw(struct iio_dev *indio_dev, @@ -435,9 +457,7 @@ int ad5686_probe(struct device *dev, { struct ad5686_state *st; struct iio_dev *indio_dev; - unsigned int val, ref_bit_msk, shift; - bool has_external_vref; - u8 cmd; + unsigned int shift; int ret, i; =20 indio_dev =3D devm_iio_device_alloc(dev, sizeof(*st)); @@ -455,8 +475,8 @@ int ad5686_probe(struct device *dev, if (ret < 0 && ret !=3D -ENODEV) return ret; =20 - has_external_vref =3D ret !=3D -ENODEV; - st->vref_mv =3D has_external_vref ? ret / 1000 : st->chip_info->int_vref_= mv; + st->use_internal_vref =3D ret =3D=3D -ENODEV; + st->vref_mv =3D st->use_internal_vref ? st->chip_info->int_vref_mv : ret = / 1000; =20 /* Set all the power down mode for all channels to 1K pulldown */ st->pwr_down_mode =3D ~0U; @@ -480,29 +500,25 @@ int ad5686_probe(struct device *dev, =20 switch (st->chip_info->regmap_type) { case AD5310_REGMAP: - cmd =3D AD5686_CMD_CONTROL_REG; - ref_bit_msk =3D AD5310_REF_BIT_MSK; - st->use_internal_vref =3D !has_external_vref; + ret =3D ad5310_control_sync(st); + if (ret) + return ret; break; case AD5683_REGMAP: - cmd =3D AD5686_CMD_CONTROL_REG; - ref_bit_msk =3D AD5683_REF_BIT_MSK; - st->use_internal_vref =3D !has_external_vref; + ret =3D ad5683_control_sync(st); + if (ret) + return ret; break; case AD5686_REGMAP: - cmd =3D AD5686_CMD_INTERNAL_REFER_SETUP; - ref_bit_msk =3D AD5686_REF_BIT_MSK; + ret =3D st->write(st, AD5686_CMD_INTERNAL_REFER_SETUP, 0, + st->use_internal_vref ? 0 : AD5686_REF_BIT_MSK); + if (ret) + return ret; break; default: return -EINVAL; } =20 - val =3D has_external_vref ? ref_bit_msk : 0; - - ret =3D st->write(st, cmd, 0, val); - if (ret) - return ret; - return devm_iio_device_register(dev, indio_dev); } EXPORT_SYMBOL_NS_GPL(ad5686_probe, "IIO_AD5686"); diff --git a/drivers/iio/dac/ad5686.h b/drivers/iio/dac/ad5686.h index caadc7403da1..09c87e15c37e 100644 --- a/drivers/iio/dac/ad5686.h +++ b/drivers/iio/dac/ad5686.h @@ -44,7 +44,11 @@ #define AD5686_CMD_READBACK_ENABLE_V2 0x5 =20 #define AD5310_REF_BIT_MSK BIT(8) +#define AD5310_PD_MSK GENMASK(10, 9) + #define AD5683_REF_BIT_MSK BIT(12) +#define AD5683_PD_MSK GENMASK(14, 13) + #define AD5686_REF_BIT_MSK BIT(0) =20 =20 --=20 2.43.0 From nobody Wed Jun 17 01:34:37 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 818C437BE7A; Tue, 28 Apr 2026 17:02:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777395739; cv=none; b=jqYhX14po4QV9SjIgu9/kS1sL1uj1loi+rkdax0QQEqoI5Fyyuzp17u+0G1/yU08EoFlyQfvgVRfr/i2arhbx2HIkZdyZeML6FMxLJ8nAWiYhCjXFYLHuzgLAVOAU8ifwZlv4wyBQUd+7zkhHJS9bIB7VBKslgKr5YDxoIK4IC8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777395739; c=relaxed/simple; bh=V6CuhK8550wHphiPFsN/M/PZ433ya4x50SU0y3UZ/BY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=leRFyPeh4yakvyCRUuTCJtSQTNjPKbaI1d+XdkIbbW8VupIczoEXSkP6nQ6CVktyxAiO939kAHuVrMZOWOWxjGcE+9Fg+FFiuGYw0dDW4tDye96MdW77NzF7VehF14P3FOsP21dPHsk/1CXNnNYaqkM8JnasVOwpPxDWG0qYfbA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=kS4WEWWf; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="kS4WEWWf" Received: by smtp.kernel.org (Postfix) with ESMTPS id 62D3EC2BCAF; Tue, 28 Apr 2026 17:02:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777395739; bh=V6CuhK8550wHphiPFsN/M/PZ433ya4x50SU0y3UZ/BY=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=kS4WEWWfmEPJK1A2cZp06Qq2x/8S2MYTCsNKmd6Xh+0ckvdDYp+tYouhurlT8yRtq LEAVs2QHRsEMtMHB3WpTmZUA9G8f21Xey9O0yoCIzfrzTEpdOjwTbKWmzXVY1UuF1w 8KFqguNpCBphdo87XEoH0wEyuT5D3ZePYgxVJoISdadh5Hp5kS3T2Rx6iUBu10jkLX vfNUvCIKorBes+i5YXx/S/WDsEpNsnQTWBeNyLJdfY6zjhTyFPgGDcrAGHEK38tHp4 VEH8nfKv5zKnmX7LZicMXK0cgB2VcdxhnoJfxpvloO/byWj9ppZ8QrPzM40Ik2fzo/ UlyeWXDKk/jKQ== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5A790FF886D; Tue, 28 Apr 2026 17:02:19 +0000 (UTC) From: Rodrigo Alencar via B4 Relay Date: Tue, 28 Apr 2026 18:02:25 +0100 Subject: [PATCH v3 10/11] iio: dac: ad5686: cleanup doc header of local structs Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260428-ad5686-fixes-v3-10-9cff7bd67a15@analog.com> References: <20260428-ad5686-fixes-v3-0-9cff7bd67a15@analog.com> In-Reply-To: <20260428-ad5686-fixes-v3-0-9cff7bd67a15@analog.com> To: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Stefan Popa , Jonathan Cameron , Greg Kroah-Hartman , Michael Auchter , Jonathan Cameron Cc: Lars-Peter Clausen , Michael Hennerich , Jonathan Cameron , David Lechner , Andy Shevchenko , Rodrigo Alencar X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1777395737; l=1834; i=rodrigo.alencar@analog.com; s=default; h=from:subject:message-id; bh=NQb3AgGGQZ59yKcVrlDP4JkvUat0ii8BBIGlKfXjgXQ=; b=dznFO1UTA8q8kEGQr+xs5PB5JG31tevNm6X0SgD3uXlujb/oxl3mPEmErOFlkcSrCH89bs4fU 5mIayNeYr5dBMrO2zZEvrITqUeMk+hpqatfjzyAUZW/NlXIm+l1lUgV X-Developer-Key: i=rodrigo.alencar@analog.com; a=ed25519; pk=ULeHbgU/OYh/PG/4anHDfLgldFItQHAhOktYRVLMFRo= X-Endpoint-Received: by B4 Relay for rodrigo.alencar@analog.com/default with auth_id=561 X-Original-From: Rodrigo Alencar Reply-To: rodrigo.alencar@analog.com From: Rodrigo Alencar Review documentation comment header for ad5686_chip_info and ad5686_state. Update variable names and description and remove unnecessary blank line between comment and struct declaration. Signed-off-by: Rodrigo Alencar Reviewed-by: Andy Shevchenko --- drivers/iio/dac/ad5686.h | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/drivers/iio/dac/ad5686.h b/drivers/iio/dac/ad5686.h index 09c87e15c37e..48b2b60001b0 100644 --- a/drivers/iio/dac/ad5686.h +++ b/drivers/iio/dac/ad5686.h @@ -67,12 +67,11 @@ typedef int (*ad5686_read_func)(struct ad5686_state *st= , u8 addr); =20 /** * struct ad5686_chip_info - chip specific information - * @int_vref_mv: AD5620/40/60: the internal reference voltage + * @int_vref_mv: the internal reference voltage * @num_channels: number of channels * @channel: channel specification * @regmap_type: register map layout variant */ - struct ad5686_chip_info { u16 int_vref_mv; unsigned int num_channels; @@ -110,16 +109,16 @@ extern const struct ad5686_chip_info ad5679r_chip_inf= o; =20 /** * struct ad5686_state - driver instance specific data - * @spi: spi_device + * @dev: device instance * @chip_info: chip model specific constants, available modes etc * @vref_mv: actual reference voltage used * @pwr_down_mask: power down mask * @pwr_down_mode: current power down mode * @use_internal_vref: set to true if the internal reference voltage is us= ed - * @lock lock to protect the data buffer during regmap ops - * @data: spi transfer buffers + * @lock: lock to protect access to state fields, which includes + * the data buffer during regmap ops + * @data: transfer buffers */ - struct ad5686_state { struct device *dev; const struct ad5686_chip_info *chip_info; --=20 2.43.0 From nobody Wed Jun 17 01:34:37 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 8EAC437BE94; Tue, 28 Apr 2026 17:02:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777395739; cv=none; b=CO9CsSU82psqXtShAWPrivFGQQd+nFHdGMLlpSOuRmEkdYGKIwkKMevK/3vOz3zPGM5dNjMhHXXpc3lG/5jV4vWKFcVXMoF4TuysFfVAgojU3xCHeLl2evWy8njqO/aIOpO2bdjoWtIFyJA1U73UyNI1Knxx8uSZdpD0ZZ9KLGY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777395739; c=relaxed/simple; bh=1YHwJW/F/aGnBCrK+QuoJQ5y3VVjuauCA31FONbyLx8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=PNbgyN6EcWSHUomVL/70FCaZV5GCA5U7ULEk06oTAuP8h7RzP9GvsJqiwjGiMgFFXZ6RWBjLOX/BIoT3q8ULeQJAsNG4CecLtWJ2clMLyY8zqBuI6RUGhu+ne1AVLwHoE9LVPEgmn7fRQ4k83zYXYSXgaL/uivUWcCuK2hIWLi4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=frUxCMt2; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="frUxCMt2" Received: by smtp.kernel.org (Postfix) with ESMTPS id 71D88C2BCB5; Tue, 28 Apr 2026 17:02:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777395739; bh=1YHwJW/F/aGnBCrK+QuoJQ5y3VVjuauCA31FONbyLx8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=frUxCMt2QOMgtLByZ5aZGpayk7uVkJ3ESWrobDa30xydUw99l6oIpCcHKw540AU16 F92C+dgI/Svu3HPxBtl3USkrEaS7J3S14RT7vHXJq6xBAC16YseiKuPS8+Eh8nDWkY r49aqWRe7VhcSh2ETuP6LBUMwgf9kt2sdhAxrtUDA372uNnpB30/bH/ELizClFtyHM mhB4opQq9O54VSzl2+Ft5fBcqxPz9wttmUvzLoo93XX461bA0fdsFwOK0y+asL8ot0 qGTjrm4//FMRVwCTIPLbR8rF2+3N+YwAGX1ohzn3WsCuMZj7rOgk8QerU5B7Y3daeF 0L3oMKcx2+vSw== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6B7E4FF886F; Tue, 28 Apr 2026 17:02:19 +0000 (UTC) From: Rodrigo Alencar via B4 Relay Date: Tue, 28 Apr 2026 18:02:26 +0100 Subject: [PATCH v3 11/11] iio: dac: ad5686: create bus ops struct Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260428-ad5686-fixes-v3-11-9cff7bd67a15@analog.com> References: <20260428-ad5686-fixes-v3-0-9cff7bd67a15@analog.com> In-Reply-To: <20260428-ad5686-fixes-v3-0-9cff7bd67a15@analog.com> To: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Stefan Popa , Jonathan Cameron , Greg Kroah-Hartman , Michael Auchter , Jonathan Cameron Cc: Lars-Peter Clausen , Michael Hennerich , Jonathan Cameron , David Lechner , Andy Shevchenko , Rodrigo Alencar X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1777395737; l=7506; i=rodrigo.alencar@analog.com; s=default; h=from:subject:message-id; bh=5iWTiJTqvvtzMa3UXQUfEyAQq2H0OecTkzq4mBOSHMs=; b=V5vtNJuknFPCyirq0ytkSmxQ5gKFq8nIFaBLEJ3JhaL3iBayfy3OzRROGOTGivWrrrn1+L1z1 Z5+u3RWeAv3BHU6I/s3Zu9Bj49sn1GDMWatXpnosor+aXD/q3Rlvc70 X-Developer-Key: i=rodrigo.alencar@analog.com; a=ed25519; pk=ULeHbgU/OYh/PG/4anHDfLgldFItQHAhOktYRVLMFRo= X-Endpoint-Received: by B4 Relay for rodrigo.alencar@analog.com/default with auth_id=561 X-Original-From: Rodrigo Alencar Reply-To: rodrigo.alencar@analog.com From: Rodrigo Alencar Create struct with bus operations, which will be used to extend bus implementation features. Auxiliary functions ad5686_write() and ad5686_read() are created and ad5686_probe() now receives an ops struct pointer rather than individual read and write functions. Signed-off-by: Rodrigo Alencar Reviewed-by: Andy Shevchenko --- drivers/iio/dac/ad5686-spi.c | 7 ++++++- drivers/iio/dac/ad5686.c | 32 ++++++++++++++------------------ drivers/iio/dac/ad5686.h | 29 +++++++++++++++++++++-------- drivers/iio/dac/ad5696-i2c.c | 7 ++++++- 4 files changed, 47 insertions(+), 28 deletions(-) diff --git a/drivers/iio/dac/ad5686-spi.c b/drivers/iio/dac/ad5686-spi.c index 8fef0e6d33ff..857b9e4f54ab 100644 --- a/drivers/iio/dac/ad5686-spi.c +++ b/drivers/iio/dac/ad5686-spi.c @@ -92,10 +92,15 @@ static int ad5686_spi_read(struct ad5686_state *st, u8 = addr) return be32_to_cpu(st->data[2].d32); } =20 +static const struct ad5686_bus_ops ad5686_spi_ops =3D { + .write =3D ad5686_spi_write, + .read =3D ad5686_spi_read, +}; + static int ad5686_spi_probe(struct spi_device *spi) { return ad5686_probe(&spi->dev, spi_get_device_match_data(spi), - spi->modalias, ad5686_spi_write, ad5686_spi_read); + spi->modalias, &ad5686_spi_ops); } =20 static const struct spi_device_id ad5686_spi_id[] =3D { diff --git a/drivers/iio/dac/ad5686.c b/drivers/iio/dac/ad5686.c index 73a3178ac2b8..690f2fe2ffdf 100644 --- a/drivers/iio/dac/ad5686.c +++ b/drivers/iio/dac/ad5686.c @@ -28,18 +28,18 @@ static int ad5310_control_sync(struct ad5686_state *st) { unsigned int pd_val =3D st->pwr_down_mask & st->pwr_down_mode; =20 - return st->write(st, AD5686_CMD_CONTROL_REG, 0, - FIELD_PREP(AD5310_PD_MSK, pd_val) | - FIELD_PREP(AD5310_REF_BIT_MSK, st->use_internal_vref ? 0 : 1)); + return ad5686_write(st, AD5686_CMD_CONTROL_REG, 0, + FIELD_PREP(AD5310_PD_MSK, pd_val) | + FIELD_PREP(AD5310_REF_BIT_MSK, st->use_internal_vref ? 0 : 1)); } =20 static int ad5683_control_sync(struct ad5686_state *st) { unsigned int pd_val =3D st->pwr_down_mask & st->pwr_down_mode; =20 - return st->write(st, AD5686_CMD_CONTROL_REG, 0, - FIELD_PREP(AD5683_PD_MSK, pd_val) | - FIELD_PREP(AD5683_REF_BIT_MSK, st->use_internal_vref ? 0 : 1)); + return ad5686_write(st, AD5686_CMD_CONTROL_REG, 0, + FIELD_PREP(AD5683_PD_MSK, pd_val) | + FIELD_PREP(AD5683_REF_BIT_MSK, st->use_internal_vref ? 0 : 1)); } =20 static inline unsigned int ad5686_pd_mask_shift(const struct iio_chan_spec= *chan) @@ -135,7 +135,7 @@ static ssize_t ad5686_write_dac_powerdown(struct iio_de= v *indio_dev, address =3D 0x0; val =3D lower_16_bits(val); } - ret =3D st->write(st, AD5686_CMD_POWERDOWN_DAC, address, val); + ret =3D ad5686_write(st, AD5686_CMD_POWERDOWN_DAC, address, val); if (ret) return ret; break; @@ -158,7 +158,7 @@ static int ad5686_read_raw(struct iio_dev *indio_dev, switch (m) { case IIO_CHAN_INFO_RAW: mutex_lock(&st->lock); - ret =3D st->read(st, chan->address); + ret =3D ad5686_read(st, chan->address); mutex_unlock(&st->lock); if (ret < 0) return ret; @@ -188,10 +188,8 @@ static int ad5686_write_raw(struct iio_dev *indio_dev, return -EINVAL; =20 mutex_lock(&st->lock); - ret =3D st->write(st, - AD5686_CMD_WRITE_INPUT_N_UPDATE_N, - chan->address, - val << chan->scan_type.shift); + ret =3D ad5686_write(st, AD5686_CMD_WRITE_INPUT_N_UPDATE_N, + chan->address, val << chan->scan_type.shift); mutex_unlock(&st->lock); break; default: @@ -452,8 +450,7 @@ EXPORT_SYMBOL_NS_GPL(ad5679r_chip_info, "IIO_AD5686"); =20 int ad5686_probe(struct device *dev, const struct ad5686_chip_info *chip_info, - const char *name, ad5686_write_func write, - ad5686_read_func read) + const char *name, const struct ad5686_bus_ops *ops) { struct ad5686_state *st; struct iio_dev *indio_dev; @@ -467,8 +464,7 @@ int ad5686_probe(struct device *dev, st =3D iio_priv(indio_dev); =20 st->dev =3D dev; - st->write =3D write; - st->read =3D read; + st->ops =3D ops; st->chip_info =3D chip_info; =20 ret =3D devm_regulator_get_enable_read_voltage(dev, "vcc"); @@ -510,8 +506,8 @@ int ad5686_probe(struct device *dev, return ret; break; case AD5686_REGMAP: - ret =3D st->write(st, AD5686_CMD_INTERNAL_REFER_SETUP, 0, - st->use_internal_vref ? 0 : AD5686_REF_BIT_MSK); + ret =3D ad5686_write(st, AD5686_CMD_INTERNAL_REFER_SETUP, 0, + st->use_internal_vref ? 0 : AD5686_REF_BIT_MSK); if (ret) return ret; break; diff --git a/drivers/iio/dac/ad5686.h b/drivers/iio/dac/ad5686.h index 48b2b60001b0..ea3ee43015c1 100644 --- a/drivers/iio/dac/ad5686.h +++ b/drivers/iio/dac/ad5686.h @@ -60,10 +60,15 @@ enum ad5686_regmap_type { =20 struct ad5686_state; =20 -typedef int (*ad5686_write_func)(struct ad5686_state *st, - u8 cmd, u8 addr, u16 val); - -typedef int (*ad5686_read_func)(struct ad5686_state *st, u8 addr); +/** + * struct ad5686_bus_ops - bus specific read/write operations + * @read: read a register value at the given address + * @write: write a command, address and value to the device + */ +struct ad5686_bus_ops { + int (*read)(struct ad5686_state *st, u8 addr); + int (*write)(struct ad5686_state *st, u8 cmd, u8 addr, u16 val); +}; =20 /** * struct ad5686_chip_info - chip specific information @@ -111,6 +116,7 @@ extern const struct ad5686_chip_info ad5679r_chip_info; * struct ad5686_state - driver instance specific data * @dev: device instance * @chip_info: chip model specific constants, available modes etc + * @ops: bus specific operations * @vref_mv: actual reference voltage used * @pwr_down_mask: power down mask * @pwr_down_mode: current power down mode @@ -122,11 +128,10 @@ extern const struct ad5686_chip_info ad5679r_chip_inf= o; struct ad5686_state { struct device *dev; const struct ad5686_chip_info *chip_info; + const struct ad5686_bus_ops *ops; unsigned short vref_mv; unsigned int pwr_down_mask; unsigned int pwr_down_mode; - ad5686_write_func write; - ad5686_read_func read; bool use_internal_vref; struct mutex lock; =20 @@ -145,8 +150,16 @@ struct ad5686_state { =20 int ad5686_probe(struct device *dev, const struct ad5686_chip_info *chip_info, - const char *name, ad5686_write_func write, - ad5686_read_func read); + const char *name, const struct ad5686_bus_ops *ops); =20 +static inline int ad5686_write(struct ad5686_state *st, u8 cmd, u8 addr, u= 16 val) +{ + return st->ops->write(st, cmd, addr, val); +} + +static inline int ad5686_read(struct ad5686_state *st, u8 addr) +{ + return st->ops->read(st, addr); +} =20 #endif /* __DRIVERS_IIO_DAC_AD5686_H__ */ diff --git a/drivers/iio/dac/ad5696-i2c.c b/drivers/iio/dac/ad5696-i2c.c index fd047c01f8f6..30c48d937a38 100644 --- a/drivers/iio/dac/ad5696-i2c.c +++ b/drivers/iio/dac/ad5696-i2c.c @@ -62,10 +62,15 @@ static int ad5686_i2c_write(struct ad5686_state *st, return (ret !=3D 3) ? -EIO : 0; } =20 +static const struct ad5686_bus_ops ad5686_i2c_ops =3D { + .write =3D ad5686_i2c_write, + .read =3D ad5686_i2c_read, +}; + static int ad5686_i2c_probe(struct i2c_client *i2c) { return ad5686_probe(&i2c->dev, i2c_get_match_data(i2c), - i2c->name, ad5686_i2c_write, ad5686_i2c_read); + i2c->name, &ad5686_i2c_ops); } =20 static const struct i2c_device_id ad5686_i2c_id[] =3D { --=20 2.43.0