From nobody Wed Jun 17 06:11:08 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 5F405306D26; Mon, 27 Apr 2026 11:30:11 +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=1777289411; cv=none; b=MEmeo7W095cD3b93T2fDcgMmXD+T7bz6MeIzDChp0lCuKxhPKbs6a84bcrLoQJR7mn2z2hlwQRgrk8wIwCO8BHRfI5qqyH37L3u7LLnhbr9+jvYD3oubo8LL6zVqhAjQ6ypqTvqo6zw9WuxwI8fgNctU4ZX7shHIrc0uTxfxjko= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777289411; c=relaxed/simple; bh=w0XGwELR3xciDLIHcBkj4Shl2CS+SlLGPOLI5Qn/iG4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=PuC6Wvvi+CYt5j5AKp/TIagXce2KLf1C+ASjDlaot8lwkjLs5tOkLp/eitlZ9tLszvWsFkwaiBtHiiETisyGvKcM2m3m3hBQsqKfdhrXhutjN9VquQ/rgxpuetNm+Xgoniosqzyo98H/pdHPeIEth5z2U6A9Yskf5QOLVVzr454= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=fCPWyBY0; 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="fCPWyBY0" Received: by smtp.kernel.org (Postfix) with ESMTPS id 0B5CAC2BCB6; Mon, 27 Apr 2026 11:30:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777289411; bh=w0XGwELR3xciDLIHcBkj4Shl2CS+SlLGPOLI5Qn/iG4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=fCPWyBY0v4WdwqFRA533/SfIz0YIb2U4z6w/xtKiwrlhN+kurbocdZhPKT05wVDFO 3OwBQgiNAzUfJMeTCW0SWcLBNtKq1YkTiCu6Sr9Q1vn5GOgiFjfmigPldnx5mZiyye LsJlDZbu7Wjq64NdceaMu7hoM7FsqhAFbAqBPXWbIiqGEtvH/qDy9xsFiVBHdLsdr4 6hpH8uhWHKQTXWwsEW/TDM2Zw/zlARy9uNeE+8ILVt8M8ypWN7szuHwltWxMGD/9E2 ReqI28OO1PAyCtb8auZJBZX84VCpDZALf/HLx2z7cINW1Czb2lOJilRjbzDpnqBDFS tNPYkOtwB6bJg== 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 EE6F7FF8861; Mon, 27 Apr 2026 11:30:10 +0000 (UTC) From: Rodrigo Alencar via B4 Relay Date: Mon, 27 Apr 2026 12:30:08 +0100 Subject: [PATCH v2 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: <20260427-ad5686-fixes-v2-1-188e05199368@analog.com> References: <20260427-ad5686-fixes-v2-0-188e05199368@analog.com> In-Reply-To: <20260427-ad5686-fixes-v2-0-188e05199368@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=1777289409; l=1787; i=rodrigo.alencar@analog.com; s=default; h=from:subject:message-id; bh=xzPfTOvqELCSXjM2q6f7n3lj/43Dt23++PuhGryImaI=; b=/VSNs5CjaTaSZrcComveElieZt3qqqjmLcEMRGuWauxKdCNfqeu4zlQjmTuDUrNtn3TmiU1Pw FuQWajvkCCoCMLfD5XvgQmc+gMCEOe6ejh3eUmiR/B6dVR+d2eHM/b2 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 --- 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..3b48ddf8dd3c 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 06:11:08 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 5F47B307494; Mon, 27 Apr 2026 11:30:11 +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=1777289411; cv=none; b=M1vuzWNCyr4QAXZz77nuaGj0cYQGwUBUV3mhwsNLYAGf9jo2OYF1St79P3uqTvzGrddyqWNVE32goUanrVn+p90/6EbHsuccZ1RcFyY+A8qxIU14ssgbbUEvaBLAc9GhSDJ1vmHskk3aReyK0BuRdPPVW6UsqVM3eLBHSk80Mbw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777289411; c=relaxed/simple; bh=+kEuOTi6HFt1h6pe8+FJT8nRA6d52Eomg+JJe+vbkhk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=EqACrjw4Ldls0aVo+ij4Awkra5AmOtDT9LM+HKKqA1OvdANu/wCHKHjZWPOXlE+qZbPKtHKqnAlw6OX6Jxm7rWG1wzW8zuMKS/1YPzMJbzUIKxzJN0CNj98fk71A7hs3JaD/GuL7FH9wHdzYni2p0rGtAdOaaXdd3KB/on0bdLQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=TIkBTQDW; 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="TIkBTQDW" Received: by smtp.kernel.org (Postfix) with ESMTPS id 1B07BC2BCB9; Mon, 27 Apr 2026 11:30:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777289411; bh=+kEuOTi6HFt1h6pe8+FJT8nRA6d52Eomg+JJe+vbkhk=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=TIkBTQDWyOPti9CNaPpvV482GmZZoqSaPWyoFXVN2CPF7T9jid6PJwPQsvKMiePv0 MK7oqR8rNzjRCZsHOAeQEDjHyURkkLvWVmWbA1PQUC7YxhVEhwp7NPou27gnUv98fV EAPv6kG0stdT2BL10aaTKzwlX4EFzL2/mAKVeyBvWpWLD43RbxVbymMO6VtipCQwbz Q5hq58P5hQfJwZeAdciHVggc6jk2XcxJxLH8/0YRpzdpy9ZUqHdgU7C2/0iVXrShso RkS3berQdxPOOxtrkKL+E857J9AIX9UYt6ZN24zut0GbZu4Q3NSey16DWcJ/o6DcCB 4LxwypN7+UpOA== 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 09860FF8862; Mon, 27 Apr 2026 11:30:11 +0000 (UTC) From: Rodrigo Alencar via B4 Relay Date: Mon, 27 Apr 2026 12:30:09 +0100 Subject: [PATCH v2 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: <20260427-ad5686-fixes-v2-2-188e05199368@analog.com> References: <20260427-ad5686-fixes-v2-0-188e05199368@analog.com> In-Reply-To: <20260427-ad5686-fixes-v2-0-188e05199368@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=1777289409; l=1003; i=rodrigo.alencar@analog.com; s=default; h=from:subject:message-id; bh=e/fvywK2NRINysG0ft35kgBAMfBvOW51G7Ogdkjn8kM=; b=enBRO36oR0s2lj0Zmbklbhkh4k1yLnafIVWlpe+YoRjC6j6seW/C6zMNGXDIzdKapAPgU3BEV 3lAXmU10de7BUErzRCg6ZvGAymaanuuzCA0ZsoaiIk/MqSlaEiAmGVt 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 --- 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 3b48ddf8dd3c..24f928ea2b91 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 06:11:08 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 40BC72F25F4; Mon, 27 Apr 2026 11:30:11 +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=1777289411; cv=none; b=EtOB25/OKvHZWnULrqoa00d5b58/M37CUYXsxzRG0Wroa0aIHZ060/BAWj2HTMKbtxsqufSEUNekgQGC55MmR8NQlKS0C8bUU91/vgfnQ6aaIVkr/zsqXppI+Ev3zCMWg9nicpw9PnJ/0mRo4hf387v4Xqlsq5XHEnQopMNH+0o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777289411; c=relaxed/simple; bh=ln2xDqNwzgp1IlNe5nNZRvuJhnMixrpbcxGzvS2tsWQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=fCvgNvUr0zIKrWTp+Nr2Fekrc5tyLoP0UGUXDug30eNaSfveLbzqnkrWevabnk21Ya+CdQmqzJFzcsmxDyCw2HXi5s+ziPe21lOfZ8ptwEOmW2kczAyS5wpTWAhYKejHzRAiquZcSCtUWmRRCs4nIXCRbHilVNjkRgnYlfIrvxs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=MxfaYK1l; 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="MxfaYK1l" Received: by smtp.kernel.org (Postfix) with ESMTPS id 21AABC2BCC4; Mon, 27 Apr 2026 11:30:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777289411; bh=ln2xDqNwzgp1IlNe5nNZRvuJhnMixrpbcxGzvS2tsWQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=MxfaYK1lTzn9i2SqANMj2GgtYmmocnEmvr2lGQhobFOQSEvTizvkZ06ThMuza4wc2 xhbIl2Y10sVxgCabTsEZEWFpWFeOo+RA4gvIEszZHYrmjwxwIoArr7tQUmt7SLfO+l P/ei9FojJZ3KSdjYLzcUm2t0C7RCo14XUmo01A5wrQMvD5devbtEqUQjHJ2Zxo+yXZ pQXutLxoZmDvXeHF0+tq1bDyJCM1TXfQuN/EBxpJVku1axKzrFnOvrR2O6wBCSPwbF 2BFtJeFdz9NTV+3hm2eaelPJrkWe0WyYIMf1dUuqAQagLIVGvdcHdxNApzIcyrdlIL fhrF7Ca/WIVTg== 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 18610FF885E; Mon, 27 Apr 2026 11:30:11 +0000 (UTC) From: Rodrigo Alencar via B4 Relay Date: Mon, 27 Apr 2026 12:30:10 +0100 Subject: [PATCH v2 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: <20260427-ad5686-fixes-v2-3-188e05199368@analog.com> References: <20260427-ad5686-fixes-v2-0-188e05199368@analog.com> In-Reply-To: <20260427-ad5686-fixes-v2-0-188e05199368@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=1777289409; l=1335; i=rodrigo.alencar@analog.com; s=default; h=from:subject:message-id; bh=3ewgFdIgEvpo865lUj9Vjv8qanWqzVP1oPspiMSNexs=; b=aUnu6PXrDBJdtmqke/3iJAh6vJ7wQb1/WmPh5SwEGqVDFHa+tieebNadQlWURqhRY8axvbBnP mlL8KFOxLwlCLMBXIr7dOlYtt+hRBCLst3I4ekyy4cHTJ7GDRtris3f 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 --- 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 24f928ea2b91..aa17ed6aee43 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 06:11:08 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 5F37D306B3D; Mon, 27 Apr 2026 11:30:11 +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=1777289411; cv=none; b=Wwcj4snQ23OW1PM/pnUacXmvKv6PbKbRbds7oxKNgabj8RPfQXD4lIL3uiKPwYyi9oEhks5DMV86IoCw+eLNIPe9a1V1ShJvKUxXOqqymGsLyLU6iQcmvAjvXhOEVSnlEYEd9qxWplNMcStMGUwI8PqydDzbTf5TQRnGVYZyKco= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777289411; c=relaxed/simple; bh=iyMNsK1uMGrss40DTPVzzB/Il46+maCHBWAPBt/65Ns=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=YPH/cCmw1rXgXlEkION4/IKDrw71nfk0w4i9CPupB7LHJxXg7xsw/F/AK4B7YksnjxuPmT7DhOLPWRUiWg+JGdYiKCR7/lBW3zqlQ0XGU0cW+c9Id9PySAYPSwkfFy55HMX/SAoYWEESQiYsipbo5FY4aDd6pH9GZdFvq7lXYw8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=skIgXcZw; 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="skIgXcZw" Received: by smtp.kernel.org (Postfix) with ESMTPS id 2E3C5C2BCF4; Mon, 27 Apr 2026 11:30:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777289411; bh=iyMNsK1uMGrss40DTPVzzB/Il46+maCHBWAPBt/65Ns=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=skIgXcZwUv5x2casEAJDVzxn2YlQYmT9Vq5oJBQba7hVDaz+BP/HDb5wCKqqlrlsN P4OOACUAyH4ydRexIIb67Sru0B3WlXDEbuvrYIRH1K462bK5YNMWsY5kuf2oBJCDes H7vLf7w7miDShYNAhqduF5oIRaulf87ixHm9aR08o8JCwF9g0pqePXNNSpex76vkZI tau+aGVduC8uykZZTPwQZVpdiOTPIUY+/39FNXCc28i3XTKGho5LAfB5qURzGnHdTr oktC0LYgOnzOWoagcffyIUnzNFbtDUVdYwqc9FCrDzDneVhgfOOt1pWlWsNsowzgYW OvjOT9tb9Kx4w== 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 2634CFF8869; Mon, 27 Apr 2026 11:30:11 +0000 (UTC) From: Rodrigo Alencar via B4 Relay Date: Mon, 27 Apr 2026 12:30:11 +0100 Subject: [PATCH v2 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: <20260427-ad5686-fixes-v2-4-188e05199368@analog.com> References: <20260427-ad5686-fixes-v2-0-188e05199368@analog.com> In-Reply-To: <20260427-ad5686-fixes-v2-0-188e05199368@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=1777289409; l=4280; i=rodrigo.alencar@analog.com; s=default; h=from:subject:message-id; bh=acuSxge759Siv46fsodaR2Kel6j0QHpComH6u5zV1qI=; b=/ERIT0DbuTnUOcIJOE5d3V8q+BPV52h3q+Qrm4NVkFZKcEwKRkfX/XhURyckBTSfbKJZXQiyr 3qSQR4x6ROJAIxT+Cp1e82P6MMfwLvbagk7q16ZC96++mdy+hX9sh2b 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 --- 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 aa17ed6aee43..04a5568f2cbe 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 06:11:08 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 5E6A4306B37; Mon, 27 Apr 2026 11:30:11 +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=1777289411; cv=none; b=c/JtCCx4udoFfXP6cpp0Npl5o72tfRvwMmsmbtjzYIsC6FIkVP5SArTdJYEtSYkgQzrJoipR0tNpawfeBpnRlJBkFiEQYLRkHfvfClBSFzYcpm0idAIiC/36Ly/45xlXNpHfrvOoo52TurEUqjs1pRWbfYuGicUsXgHbFFvKcbQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777289411; c=relaxed/simple; bh=to1DlBvvsDfODvKTGcPUX3C16OWZxp1KCwh1nPJ9t1I=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=FmoXb+z0p/6S1yEwquj3yP/4AtCHLuS/JEcOw9lqnCrBvyC15bD/zfrnPWD2Sim5MwzGmi1vCGTVv+xu6rS1e8cxGZHEVRSJMyT7Q9Ma80AoKdvUP+hbhqwjcM0YUCEZJqQBnxB7D+sWiedym5h67nDXfUgCYqLnwVgsGtDKE0U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=fsUgDUPs; 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="fsUgDUPs" Received: by smtp.kernel.org (Postfix) with ESMTPS id 3E6BCC2BCF6; Mon, 27 Apr 2026 11:30:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777289411; bh=to1DlBvvsDfODvKTGcPUX3C16OWZxp1KCwh1nPJ9t1I=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=fsUgDUPsqps4laWhqwcL9g5rPcADhgtivBPDAHh80SbxgVFSW59Jta6adg7ooQ9rB MJ4n10+4CsMZfHBYjNpNBaXzNR7tMxm7QoZm/7hXWJilRGU0oyClhP9/UTd0Lh2gg6 vjztD7bhPSR6RdLC3kbrw4EwAGlo8rXi0zNaaBflP1t34M6S3tLchJt8HUHqKyoe+X Mcj5WEesnx+b5sQXaS0Bc26041a1ao05W12YitTORURekH4edjDtvGnakHSF0WkzO2 5FhCzDFzmHLgRqEJ7t55Tf5TKgOdDJ2UJm3Bh0k1FuYzpE4smqXsJcmI+N312GdOaX igL317ZiLPSoQ== 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 359E5FF8860; Mon, 27 Apr 2026 11:30:11 +0000 (UTC) From: Rodrigo Alencar via B4 Relay Date: Mon, 27 Apr 2026 12:30:12 +0100 Subject: [PATCH v2 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: <20260427-ad5686-fixes-v2-5-188e05199368@analog.com> References: <20260427-ad5686-fixes-v2-0-188e05199368@analog.com> In-Reply-To: <20260427-ad5686-fixes-v2-0-188e05199368@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=1777289409; l=2747; i=rodrigo.alencar@analog.com; s=default; h=from:subject:message-id; bh=23N6CMy0ZGzlml35g5mJ5f2Y96WQ2ZUtKNwc+4DLMxE=; b=sug1Sc68YYrTulNLjgKeXlu7sVqCuS6Tok+wbtGvrByxSqrYGutuamKFKMPb12Sb0JxUIwO09 vGXXNenO1MyA8hUAVgu8IDgv3l/158DRX7GX22GqSUXejdiXiifZndh 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 --- 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 04a5568f2cbe..2c1692097c0c 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 06:11:08 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 7CD4D30BB8D; Mon, 27 Apr 2026 11:30:11 +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=1777289411; cv=none; b=bzjYg+fBG9RWo17zjdi3RvJ2YMAs3DTiH2N2yCMQ3JkBR5ruExdXYrQB17/wAnOCjSpqecCPn4LsS5qJ1IkQCJYaBUpYpjBoBW0M9if6j9konMcowwqhqseJpnkFQQ3SBPoINPjcmf80hevqf0z2bCfbZf9DfNARviZfR3A8TYY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777289411; c=relaxed/simple; bh=ljmE1rWpKZCn3pxvkkd3tXDkCzv8bTgE+KAX4BqGjzA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=HtxYRckcdC9o69vmkWZdSzJvvSQ77QldIUR5fPaASCCDxOdd1hfD3EG74HJ4EHuahWBlsrBY2I4Tdm+yZuiNy0f7CisBrVvQ9FRERAMTO/t6q9ul56hb3Y70S9lDnp5tuVae30hHad3uU6ZVPZZuN4zxC3VJymIu3bzqNUD/cvg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=G7330ZBn; 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="G7330ZBn" Received: by smtp.kernel.org (Postfix) with ESMTPS id 4FDC8C2BCF5; Mon, 27 Apr 2026 11:30:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777289411; bh=ljmE1rWpKZCn3pxvkkd3tXDkCzv8bTgE+KAX4BqGjzA=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=G7330ZBnGLRGThB227HGDYPkybgLcIaovi2tcyr3zjvI6jZ0Je3ocaYZZ086F8+sc RI+SzOoKU/X3hkq8tap0X2zibY1uVN+xJ2RNPJfGPNXtdkEYQqT4BFy0pjDCd4+lJy QjxUnIr1p4hXFWgfslzVx5KvTWVDEFvlPetQV5xbY8ioFf5XkgSYWAlAE81kIgRnKS /bx4kerd+IgtknZDtxDMLsbcxIaIEYh5JzOK+rwpU+pGvk6MRytYSNgXcurvTZRcyd nXJmGNaLqZf/rVugzPWQMRXGvVXBgedK/lu2WldatFBLoLZgfk8V+2+4Ll6WXthokN UKK7ctOzpdwQQ== 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 44AF1FF8861; Mon, 27 Apr 2026 11:30:11 +0000 (UTC) From: Rodrigo Alencar via B4 Relay Date: Mon, 27 Apr 2026 12:30:13 +0100 Subject: [PATCH v2 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: <20260427-ad5686-fixes-v2-6-188e05199368@analog.com> References: <20260427-ad5686-fixes-v2-0-188e05199368@analog.com> In-Reply-To: <20260427-ad5686-fixes-v2-0-188e05199368@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=1777289409; l=2960; i=rodrigo.alencar@analog.com; s=default; h=from:subject:message-id; bh=5pwGj1cw0fpuxn2ieaGg3QNQN8ARYGCB2EEt3sxkuHg=; b=LJH3ER6HfxTaBmUvcbQCgjhk4w4r3VsEN/i858nGAZBlaX/FLSpjUbof5FTR2BltshWmjXaUC weAsagyTrZUAMPdtZSdYB5o4Gw5jusjxg0a/xskHnfs6ZeHQyTbbnXI 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 2c1692097c0c..53d58f0af16e 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 06:11:08 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 80DB130C368; Mon, 27 Apr 2026 11:30:11 +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=1777289411; cv=none; b=i/9Vu7ZBKuRB66Lu3LaZrawAIT2cagzmFWkDJQz7ghv3J1/FDDKnAy5XYGh+8XWh795Av9cKOx4rSDqwHOtJFWEGUWbq4vOC0iwTfIKKA46g1hFdbCC+NLNFuuFDoYqiY5Ga2vGXRqadw2CGPLfqE3FRegYi8PQlr2OiOMCBcTU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777289411; c=relaxed/simple; bh=4NadKil5Xb89XzgJIZNGfejBl6IFFPM6murYJfR8woo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=EWOA6gH/4CpxzyX6m1ZjNzS1ci2gtkYPhA+ErymiOHBe8wv3O5MwFowsnD68+3TdZpR04nmG74WZDG2MkFRj6z0Zn1+X+vY78HCwtHWK0U9jTT4/Os/o+GGnXScLQoWeDzD6yOw+gQCPW8ECUaXOwQCOO9o6ZSNel0gKVihOjcs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=dKJ4UAkA; 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="dKJ4UAkA" Received: by smtp.kernel.org (Postfix) with ESMTPS id 60332C19425; Mon, 27 Apr 2026 11:30:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777289411; bh=4NadKil5Xb89XzgJIZNGfejBl6IFFPM6murYJfR8woo=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=dKJ4UAkArFRfafRtzsXQkQXG22j69XGMThoSG0iagYIdkO3Fwkt53VhCY9iAmQNpw IgbO4tNTPk0pCkVVmmxJnuhH5rKcrOCrX0V6F7s+gfT7BMleTnBn0AtYSIjqcXV7g6 upmlxAWOHACNMxJRtCVIDO6fF8SY/w+mMYWWVE5tBmTVKpE5UdCFRtVY7LKhr20zlF z5rgDXLRlCIpUw6hakU9YmgvY0tkWIj37wwB7J/QVWMsxK0as4kqsWRXizbk6EbZLu hhifMHFdT7Tt5TmNV2eIPCzKp4Hqe+GEywLxPlVhpYltdReXUKfQ/b4NJnUfGKBWlc XLogoH5m6/UDA== 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 55BA9FF8862; Mon, 27 Apr 2026 11:30:11 +0000 (UTC) From: Rodrigo Alencar via B4 Relay Date: Mon, 27 Apr 2026 12:30:14 +0100 Subject: [PATCH v2 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: <20260427-ad5686-fixes-v2-7-188e05199368@analog.com> References: <20260427-ad5686-fixes-v2-0-188e05199368@analog.com> In-Reply-To: <20260427-ad5686-fixes-v2-0-188e05199368@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=1777289409; l=20109; i=rodrigo.alencar@analog.com; s=default; h=from:subject:message-id; bh=5F2kqpIHg79J4z7pn/4goA0WSi1cQeZoSTUmEVSSpTA=; b=GgqqU03C+jaCinz0O/1+EvwbZEgNt2yDJeVVehMCj8Vnqcq7JG8kyGLHvLuuMS3GqxCW87S+l 4umKwXxa/svCnUN1YWWnkirxmKSfDlukOBPUBOw9tu3kyk4Q96RSxrz 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 --- 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 53d58f0af16e..4015ffdf7ad4 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 06:11:08 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 86A7030DED0; Mon, 27 Apr 2026 11:30:11 +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=1777289411; cv=none; b=Z9Doeuh6BkhUCmIW9kFAwWmLrsReyl91CYsQvwhnhYfCpQeaTkzVQ0qET1fLU9G/C+/ZLsmy2hcwYhQVXUEPmzu8nlmjfw7OFVLEVF1AAgQjv/iVh1unjro0/rbFOyfEUMFe/j+vNH7ut67tWSTBNcYNYugkQWx2vC4JpFOGdN0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777289411; c=relaxed/simple; bh=zRqZGudlCy/r9rTbDAr1hiuQyH3vkLVcQSg7ikAa438=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=DnOVEInLN6Fg6+3m1+I+MBoBwPAhNZVIFQZYVfAY1SJSjgNcHWSuIK8EtZ/DSd1dLeYHIC14HpEaFvCuA7jomMMm7jvcotmzi5g+ZsxvuGjrsXuphqJ2/rjLLVsAgzKspli0g+D2FHg0hCu6BLuGSdwNJEgppVobKFlymNeDvok= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=pp8dFxKH; 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="pp8dFxKH" Received: by smtp.kernel.org (Postfix) with ESMTPS id 69F93C2BCB8; Mon, 27 Apr 2026 11:30:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777289411; bh=zRqZGudlCy/r9rTbDAr1hiuQyH3vkLVcQSg7ikAa438=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=pp8dFxKHBT7W5W6QPIrr3+Y+DfbKg121UipEI46y0J47G/XxtuT2gH1j1PMOBT1/X ZBJZxJIKK4Cnp/2gtogweQk3djTBO/7I/cLPTaLYGKVswwp7eil+LL0MFdDJYTctnn Y3aaNnR/SLbZm5udUmdtnJ4U0yDvMxi9+54GjXDDAk0BUvlKyBTEiqbC7qOHdC1ZDe PR9RvIxPDFQ/YnbH85Y1DeyRIMuGIG6kN5XcHfjKXxgOdwn4EeFr29S+v1disAQAgA H6J7QcRZHzNmy5GpsOT2I1k67rASlcvSAbqo0iq+0sxDWF/HV4PXA9W4iqYeJYTXs7 wSbYaUU6vQrgQ== 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 6425DFF8868; Mon, 27 Apr 2026 11:30:11 +0000 (UTC) From: Rodrigo Alencar via B4 Relay Date: Mon, 27 Apr 2026 12:30:15 +0100 Subject: [PATCH v2 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: <20260427-ad5686-fixes-v2-8-188e05199368@analog.com> References: <20260427-ad5686-fixes-v2-0-188e05199368@analog.com> In-Reply-To: <20260427-ad5686-fixes-v2-0-188e05199368@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=1777289409; l=1849; i=rodrigo.alencar@analog.com; s=default; h=from:subject:message-id; bh=LohyswX/WbRmKSz4Qx5zIV8Oktgz71bUWV/iKlpzTJk=; b=l0IDiXlVjGpoZlV+TZpBhzBxtO2XtlhJJ+NalLFHpr35fQ+FlP5tRCYD7lqkayLZsMGrudWKp 5/zV3zLPCDRCEM/1eKg8l7Xky3HW8PKAn0wjtT0SeXnt7hoGQHBwyAX 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 --- 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 06:11:08 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 A2F9830F53C; Mon, 27 Apr 2026 11:30:11 +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=1777289411; cv=none; b=ep/4RNvyVHt+C9anqGwlaNvKa0tlAk1ELJnuyXGTSQ0zGUf5wHa2VvSlgutEx5STWkvgOgP9JjG8VH2/JFaH6Cl2SZD2aeFlhqYNDx7DU5NhskzZySItbeWVGQQwL6s7qBTljjSTs6nQB9Vjbrd4PRusVLzUXWVXrCpaw9Mo/T4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777289411; c=relaxed/simple; bh=jMib/WOFiQHoFWDXmXvyA6UrBWhB2iB4pGhoZ3py4YE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=YxVfJ4JoMvKLEdOIYOmDX8G3JM3Bwr4BP14fq8H/8A8SqtbXWnWnfRj0TzFBwu2SLh4IyNPd5pxmoN3ZM13/m2UHfeTVz2ryY4kRLWmgboJhShL43KrN1lJfucdLhd+UwNZ2zYoL3V4UnogU2HjwRDKy7Nu/xECIvj/v5qr7YhY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=moXIfGlJ; 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="moXIfGlJ" Received: by smtp.kernel.org (Postfix) with ESMTPS id 7B423C4AF0C; Mon, 27 Apr 2026 11:30:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777289411; bh=jMib/WOFiQHoFWDXmXvyA6UrBWhB2iB4pGhoZ3py4YE=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=moXIfGlJhqrarPAA+ZoV6rfIbfR63xmvKFwu8dnNTQ1Wd6NEQN/p5FWl72Q92eZk9 W/zdJ22Kw8Xp/90xkbGNYAlQ/jyOR3IYp5UMp+0dNNUDGdDfLJZkiB6xbPE2lDjAmE EKMSHewHZ9m7z9zjIyxKxF5WGFkuPfYsV+cyUb74m15UpSXAJtpg87hbyDzPrV7TJH NK68tNFBaDMrpiKGtcZJDq5gyguco4sAfbSuPNSyBVXZlCDw4RH4gTJsdnxh1YyvYa w4tVv0grFAeI/XxUYLrc0BUloMzaeUO4VlLv5+H+olxSgX4Of7rtoORqeC+aCvOrDI Da4r2zuD9FJTQ== 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 739BAFF885E; Mon, 27 Apr 2026 11:30:11 +0000 (UTC) From: Rodrigo Alencar via B4 Relay Date: Mon, 27 Apr 2026 12:30:16 +0100 Subject: [PATCH v2 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: <20260427-ad5686-fixes-v2-9-188e05199368@analog.com> References: <20260427-ad5686-fixes-v2-0-188e05199368@analog.com> In-Reply-To: <20260427-ad5686-fixes-v2-0-188e05199368@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=1777289409; l=5998; i=rodrigo.alencar@analog.com; s=default; h=from:subject:message-id; bh=sT9BG2GqX9ItoGMVmC63eJnF+SV+2dtWheJKq6CSLM0=; b=gfw4JwNaJIThf32QO785j++OBidNH+N2I/jHfs6QU8d5wsUPyxhNgMms5ecoOYNWnDoa1a0fR XD8SVdzRUMKB2LbLkEUbaxuzipMowfihpagAo3bKbM3TO/bGxsTBWPQ 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 --- drivers/iio/dac/ad5686.c | 88 ++++++++++++++++++++++++++++----------------= ---- drivers/iio/dac/ad5686.h | 2 ++ 2 files changed, 54 insertions(+), 36 deletions(-) diff --git a/drivers/iio/dac/ad5686.c b/drivers/iio/dac/ad5686.c index 4015ffdf7ad4..c5795141f483 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..2f5c1f2c67bf 100644 --- a/drivers/iio/dac/ad5686.h +++ b/drivers/iio/dac/ad5686.h @@ -44,7 +44,9 @@ #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 06:11:08 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 A5EC430F927; Mon, 27 Apr 2026 11:30:11 +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=1777289411; cv=none; b=ueXfzvE4Qhu10HPCVQdciKmhpA8DomuFG7neICcc+2B0hwRYzArIfIzCyiQk+dWygVbfpSAvP8MpIYXvsdrKoD5XCVrSACHeMNZ5I5ePaptfFCN+T+2xHRGA4G8o2wP471wjdnMHHEYdxYYYRVqha0GQ4efSyFtjgHBlA0wSzMI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777289411; c=relaxed/simple; bh=zdzr8vwzfwb8lBqeeDr1+g5aNqFY82b23F5+tM1U38w=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=RLYUfACXbxo8nYBcFuPl30jN99TVgTNw9AvleWRr68A3wxK7FVGCPm9c1yA4GpsJUDnH7Fby9Oo9XyItPiUXjOLMGbdTJSBTqmtfnWEmjRBL8WMv1PS0G7igivi9ENhrTw8+CygYzpd7iAe/NlvqCQ/wXsqyqv4Wr6o79Xg6uj0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=kY+MRAAp; 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="kY+MRAAp" Received: by smtp.kernel.org (Postfix) with ESMTPS id 89BEFC2BCC6; Mon, 27 Apr 2026 11:30:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777289411; bh=zdzr8vwzfwb8lBqeeDr1+g5aNqFY82b23F5+tM1U38w=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=kY+MRAAp1jxALERd7938dML55l9nllKSSsf8h7ORcK8jG9y8lhYhLbqpuz1WGHRnC BPg3oMROKzkfIxwzceIz+yOQ0I7plxnxqukm4mY/pmRQxjdBp62d9oPwoZ1/31SwBw QpehDYKsBxGEa3yIms+UalNWs7rKef/jKN017hvTXfyHndWwGdnNPoszjsd4UsUVoL tTZ0vAujRwXP+bSknR4Msn0dqQHo0blUKoh5PBgHwHEk28bPHxbf9auw1eeTbyrNe+ ZDb7zy/w8Ks9ABJN2tGQmyrQWpw52RYstoynEfeoisb2nKcRxBh2E0dzgDVGn3vUut avuE53HkLgfNQ== 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 827C2FF8860; Mon, 27 Apr 2026 11:30:11 +0000 (UTC) From: Rodrigo Alencar via B4 Relay Date: Mon, 27 Apr 2026 12:30:17 +0100 Subject: [PATCH v2 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: <20260427-ad5686-fixes-v2-10-188e05199368@analog.com> References: <20260427-ad5686-fixes-v2-0-188e05199368@analog.com> In-Reply-To: <20260427-ad5686-fixes-v2-0-188e05199368@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=1777289409; l=1834; i=rodrigo.alencar@analog.com; s=default; h=from:subject:message-id; bh=/J1GoS+jTlzr+L+zdp8CVtiFjI0oGT5Ng1SIGuun7io=; b=mHNo4fFFOzzn4xJl0p9wDHczrAk098qoCOFbUozuSC2yogo3PYs1vzduLfxeYGrDnujDjXZFM 508d2Jvq2I5DuWf1+xwyDUNZCl8Ml3FvghtkXm/erugNxVPw8mglNLw 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 --- 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 2f5c1f2c67bf..135935265c10 100644 --- a/drivers/iio/dac/ad5686.h +++ b/drivers/iio/dac/ad5686.h @@ -65,12 +65,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; @@ -108,16 +107,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 06:11:08 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 BACE93101B2; Mon, 27 Apr 2026 11:30:11 +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=1777289411; cv=none; b=u8i04Q/5Rk4MaXCHB+u+0tCdtNVqbPMBhV2O3AaMyPcGCcit9i53UPqXaqnCBLo3kLzOBCMKAPtnDwFL9fxZ7LX2blHPlbc+Ox9Llp2d9D6onyhcQehzX0P/vQTlzIfmK6eRrXag+wnGLZux4tY/ejslqZAcdxCnySX5fXkqG/w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777289411; c=relaxed/simple; bh=Ya5b8JUnh3ROyyCKsdXfkxwx/rYeawxvskRC/+waVOo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=rHLuWW3me8qH2atK9cHVVwzPc5qPnLrJGOH6C/3QxSztM+BITQntcOeelLCwEFlI4anQYDqfJmmyRSHhDDwCIrFKcCae3/KkrkSPD0by3hkDfmjJAVstupciCFLWzldLnVP1MGGNneGGbT95ciYzJ1EcxvGIJKRgh7SlPFjGUy8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=GmPyQgWz; 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="GmPyQgWz" Received: by smtp.kernel.org (Postfix) with ESMTPS id 99CA4C2BCC7; Mon, 27 Apr 2026 11:30:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777289411; bh=Ya5b8JUnh3ROyyCKsdXfkxwx/rYeawxvskRC/+waVOo=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=GmPyQgWz6XfeovebVJiySiKxZ+V3G2EeaVBx7dKEdL9gPaj0zyc61m6xre1+gResI 1Il5BA/K7Kh7VoiGh2T+1zFqFqOEaMhBMj3qvn+TinKZXzgbTn1Dg0hfWoJc0GygFN mAOQIq65gMbiSMZ1Env1YepcjhI7S8BwLIfRzLNwDiIJX1+W0rV2Gf54p8M+r4wCFk TwjI9givrujQ/4t2bxE+RiuVYbfH57ojId+m8FDX7C7Y9RlauyWwg+slcXxR56rINJ innKUy3Ldqk6LPowBhVDS+ny8S6I4OWcQN7vn9oYHQ1ejhCoM1zKk+Y7brziTrFFCm xejxAcRlYzV7Q== 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 921CEFF8862; Mon, 27 Apr 2026 11:30:11 +0000 (UTC) From: Rodrigo Alencar via B4 Relay Date: Mon, 27 Apr 2026 12:30:18 +0100 Subject: [PATCH v2 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: <20260427-ad5686-fixes-v2-11-188e05199368@analog.com> References: <20260427-ad5686-fixes-v2-0-188e05199368@analog.com> In-Reply-To: <20260427-ad5686-fixes-v2-0-188e05199368@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=1777289409; l=7506; i=rodrigo.alencar@analog.com; s=default; h=from:subject:message-id; bh=DYC+4U2A6nqOoRlz+vKu6DEnzb52BHbonqf8rGIDB8c=; b=ZmPyYuAwMsxiTBZRAW2+miZMOB+BqaMIBsRlIJZCNcbOmDM5aszWBHDwBYM8IUYUgg+p7ZupP C0RiTeR5BYgBnQyRQ0PwGgqz9A/yZr3alB9FVUmMWkqU/JEQk2qQLIF 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 --- 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 c5795141f483..05b0857364bb 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 135935265c10..a9d9472425a7 100644 --- a/drivers/iio/dac/ad5686.h +++ b/drivers/iio/dac/ad5686.h @@ -58,10 +58,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 @@ -109,6 +114,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 @@ -120,11 +126,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 @@ -143,8 +148,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