From nobody Sun Jun 14 07:36:49 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 CCEC837FF67; Fri, 1 May 2026 09:15:21 +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=1777626921; cv=none; b=Hns7PYb2IW+Rm52v+XejdsVP2WkfPCCqbur1RstZkBNSOOan4z44hPxaNuzSXzlMilvvuSbZuiru4jXs0N7XbO7QLzmUo3/XNXb7TBuqaxmMIzWkJVFW2m/OJnFZJuhx3kxUkYBEo4zVmK/MsAx3kxCAlcR88KwlXd+/2NYWKc8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777626921; c=relaxed/simple; bh=NV+pb6nkEs/Kb/1eTRMnTHalM7wi/b80qqdCmx/U20E=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Iq6JNxL2xksrQDBl8H6qZRhHxQYRKFyLV0WunQynA1GPSIiZvHsXWTj/645zkZWKlE3TdTsG+08GlUbxa+Fg0Lsxv6HU+chVmFUyCk8EcSb+c8+OOO+Mv9EsI34cV+qLcG6z9VeK77UlmC2C2HyeMVwquLQD4WKmjk3z5q3xgck= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=L4J1Hyr0; 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="L4J1Hyr0" Received: by smtp.kernel.org (Postfix) with ESMTPS id 92492C2BCC4; Fri, 1 May 2026 09:15:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777626921; bh=NV+pb6nkEs/Kb/1eTRMnTHalM7wi/b80qqdCmx/U20E=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=L4J1Hyr08mvHpESb8fiv0lyEeWCsDoNbUuwZehu5NPKW5MM0Sl2vjQcBvBP4T1Tfk J+Zkc1mCag7UC8Ig7VTc4B2neIvEUSzTfq5GO5weL3qlCPDMX3t8C1NorsgVSBBFEO XFKpAVuGS0AONRodMrBqq8MJ2+6sijjTEiwIQyfD28ECvfNJw30hvQJivjh101r0oG WYQsB/dYgF1w84RnnVJsrky7OI3k8YYTVTEatpr3tY+gEarFhxG31GKUokYIoRwj2S DvYl4G9g5xAsFvSl6mCM8E0ifQagUeOsjFQQyeenDBHF5NbHfrv4vruT3kfAUwNo+n +f5H5ppJPDljA== 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 82F3EFF885A; Fri, 1 May 2026 09:15:21 +0000 (UTC) From: Rodrigo Alencar via B4 Relay Date: Fri, 01 May 2026 10:14:54 +0100 Subject: [PATCH v5 01/12] 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: <20260501-ad5686-fixes-v5-1-0b2f45488418@analog.com> References: <20260501-ad5686-fixes-v5-0-0b2f45488418@analog.com> In-Reply-To: <20260501-ad5686-fixes-v5-0-0b2f45488418@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=1777626920; l=1845; i=rodrigo.alencar@analog.com; s=default; h=from:subject:message-id; bh=ACFFNXIkeDLRrCLvd6fNW7RHjZhA5Kd+3kUIKJGbV70=; b=Lpp7uuafosV47S63MBj747UaEkDxUqPV5uLczxRsfRHLS/eqHigbOCHGVeDdlM4EgKmfTOAqC lYA+lOZxciuCAn3JPy6+iTiRcr973Ye3ftMDo1L66cdEEH7+R6PPYJm 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") Reviewed-by: Andy Shevchenko 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..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 Sun Jun 14 07:36:49 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 CF71437FF6F; Fri, 1 May 2026 09:15:21 +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=1777626921; cv=none; b=TvGEsA1cZDEkAFjNMtvensa7uhWyC/G93pWDMcIhLYqXqmTZp2cvIQ9OUC4gVywmbMjt1XRhum7RbcQz+Cj60Ws9yCseqEkx/BRg61mrynpcnAFejPjhrTUmTe9mQO9wTiDg/DgM+QfBRkHCq3BeBl1UeO7IbCRc3gjoMu+vygs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777626921; c=relaxed/simple; bh=7Mc0VNRZ1CCHsXaSFdFIyxqQMqScXwRjdBvOyAElbig=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=WbhZbcRG7waOC1em3VmY63auywILUAOxN0/MtexILtKMYFiQLFpMru26rlwyIDrmGdmTzUvnxE5C2Y//7+rB3rMML4V2RtX5q1XsHYjDXeK4a8Gox/4GU6W1qBxbFTfw2AMrf6SrRCpPJY6fEWMv3JBFpWwrZEZJ1VbU9gXa8DM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=hQveHJeW; 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="hQveHJeW" Received: by smtp.kernel.org (Postfix) with ESMTPS id A11D3C2BCB7; Fri, 1 May 2026 09:15:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777626921; bh=7Mc0VNRZ1CCHsXaSFdFIyxqQMqScXwRjdBvOyAElbig=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=hQveHJeWX3JMkDXI41dqGm/vBF3I8Fu1Q0ZhUmaIcD6co1eGPTlNmS5W799Z+6RV9 x+trZzM2RND2YhAHWi6S92qEhZsbd5teo19JARKFclpvt/FqjANj+YijgW1yJmtecn jbH19cRwGbnYax3AU4UT6S5TNRN2yT8lI22MHZm0dAxRNcIwj+pz2HW7hjKEicAgVI nrsAVVwzBbDjMMDoId2ajurr6kTqjwiAMGEmiqoeHSQ0dMZeZqUpSwAinSU9DqKWj3 8axf+i5Pl6VvAsq8ZfJI7TY5dprB+avBYi/ctng5D8p1XOVRu86cgIAf9Qj/2Z2c72 jHxcHeIGvfNLw== 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 9260DCD3425; Fri, 1 May 2026 09:15:21 +0000 (UTC) From: Rodrigo Alencar via B4 Relay Date: Fri, 01 May 2026 10:14:55 +0100 Subject: [PATCH v5 02/12] 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: <20260501-ad5686-fixes-v5-2-0b2f45488418@analog.com> References: <20260501-ad5686-fixes-v5-0-0b2f45488418@analog.com> In-Reply-To: <20260501-ad5686-fixes-v5-0-0b2f45488418@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=1777626920; l=1063; i=rodrigo.alencar@analog.com; s=default; h=from:subject:message-id; bh=vDIfN7HwJer2abOZhavJmea2PyXmNcae90gQrhX9MT8=; b=oKohw32tW9ASvgh5T6o/jb6ynGJ27HhUPEqPzkgqpKGImCUSgVlotVfHy9UohhJnopoBE5H/V 5maxAZB29fnBL6doR+usU/SeuGMKMQ8TKOKPppcBa42JQoGVLlOl7Tu 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") Reviewed-by: Andy Shevchenko 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 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 Sun Jun 14 07:36:49 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 D43B237FF71; Fri, 1 May 2026 09:15:21 +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=1777626921; cv=none; b=WFgOs/fjyGIZZvZaripwIJJzFTu9D22fWgfCquu4yHJsWjLpuXUD5Ij34akNJ6VHAZCOjMJeiF7GHW1koX5ReAzsREVgwc1vlIxUJ1asAYBi79XQFtU6XcuRmgIV2ReuCv9b7WeKykk4TWG4M8s94c6CcphNhMGuLrerqaCXpDw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777626921; c=relaxed/simple; bh=l6b0m/8tpPZhcd1xoUPK+UYPNIMKo+diyowWW/xZ9TA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ocYkhJ0CLcxkj3YdMw/Bz8/JkgTTFf2n77PaBBigD3oH19mVhX1ddnCye3c6FY/D5gFAWRLAV3+Rce52qpGBSWr3f9sbBi0mFSZ/XyFGNXniCscF091udDf6O0YFyjLDcHspLen07p5qkqHgfj84SKdQAJdJwsh9mDs4z/I/X3E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ru4rnU4V; 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="ru4rnU4V" Received: by smtp.kernel.org (Postfix) with ESMTPS id AA6D7C2BCC9; Fri, 1 May 2026 09:15:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777626921; bh=l6b0m/8tpPZhcd1xoUPK+UYPNIMKo+diyowWW/xZ9TA=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=ru4rnU4VAsE6hKgj3JABIie2fnCCoGks0AzoRuy0sjHtH79DsX0Q/IJG2Ctg24QOr VJD0u2B8Z2oy9qdfeBsYCsjvfuYucZY2frweT9weKSN8OCPYqxFxqdq+bwzRT0jUnk o13MxmYlaW2QvFaj3WS921su0miRHEnvLORvFvs9JsQLr4N9SFpTX03iWvoXfPQLNB YSQ5NhJqUACP1okKRRlyl2onQyQD5vmJ9ZOREPPAnIySz4GtEZxhYeLnpyO1NDUHDV Uy39ZlByn80Q5eDdY5WzdyPYyAcpwfUGOMETmWThiLncuYhYHoZCJULN1k+pt1k1nK svvLMH6xZYVwg== 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 A072BCD3424; Fri, 1 May 2026 09:15:21 +0000 (UTC) From: Rodrigo Alencar via B4 Relay Date: Fri, 01 May 2026 10:14:56 +0100 Subject: [PATCH v5 03/12] 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: <20260501-ad5686-fixes-v5-3-0b2f45488418@analog.com> References: <20260501-ad5686-fixes-v5-0-0b2f45488418@analog.com> In-Reply-To: <20260501-ad5686-fixes-v5-0-0b2f45488418@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=1777626920; l=1395; i=rodrigo.alencar@analog.com; s=default; h=from:subject:message-id; bh=WJ9grwmFpTnUy61Cm75lOSuLfVSZ+oTAauaTKqq2DP4=; b=68nFv47I5pcDUHxg+UGKwxmp77qDy0Gjc8ap2htaEMP6i1VoyOchiYDtHVj+WyZ3hvTftdR6M 1FS4Lw/IlzvAD40Jmv6u/NaWx2tLSwPBS+TWOOkaFEUJH/1vPYbdQNe 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") Reviewed-by: Andy Shevchenko 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 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 Sun Jun 14 07:36:49 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 E999537FF59; Fri, 1 May 2026 09:15:21 +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=1777626922; cv=none; b=PXzXQFFFkSNJDHNKw/9QM26o1vLaEE3dj0uWGAxf0jzUrxy2m0v1aR1QbexoiRtNAIXA1aU3cTyBhcFvYja8idX9QWB7FjtRW3h2zTvuy90A6+eW3qk9Sasv3NxjZOZwsGGy9vEpbLl6g1d036Ff0TQZdXve9oGPrsFrxRT+YRE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777626922; c=relaxed/simple; bh=/vz/Et57/ETkKqO/2fI8BIAP8N2wyHZmnMQrgdd/wog=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=KdFzlmuoGnOpszMFu0roes+H5hZqKU+uct+wArikAR/Nt3HrGspLAGTBMl5fCzaxeRtgAXV4tztOe8x74cVVolHFHovgmOQJ48oogqHMLDeKzljj7XFA5SkqbU+TAF1KRSxR2OqyZ2cf9NlxTFjVOjx6F3wxls2CXH+AYTqgt8g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=QU/RPUFG; 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="QU/RPUFG" Received: by smtp.kernel.org (Postfix) with ESMTPS id BAAEEC2BCF4; Fri, 1 May 2026 09:15:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777626921; bh=/vz/Et57/ETkKqO/2fI8BIAP8N2wyHZmnMQrgdd/wog=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=QU/RPUFGSc4B1RHYe99LbqTfgb/8OwLAXUv2buGqe0/7kfs1bvZzav+GQwNKE8eoP 3YtGJbWXUC3ASrEUm8WIt/PhIQ9zaYyd0bHNHbEuO9rdHN8Z1Noxic+o0ol7vTKNgq X3a8DBuLH1sOc+SHbs9RUpXZwqtFiv3QhCS6S66gk55r8HQih82m67T47eh3LK8/cR Of/klaktTNatgO5HZg3Cet7V4cwVSAzP2lCKky2E8paUUOwPNCmLHh7QZth6udCW9o vEKnvESibwiQzRQ1FbPav5IoALq1vI936QMWSVTU5BwaEGVXGnQY1WAaZbL9WobyOs iAMWgVDV22zOg== 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 B07F8FF885A; Fri, 1 May 2026 09:15:21 +0000 (UTC) From: Rodrigo Alencar via B4 Relay Date: Fri, 01 May 2026 10:14:57 +0100 Subject: [PATCH v5 04/12] 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: <20260501-ad5686-fixes-v5-4-0b2f45488418@analog.com> References: <20260501-ad5686-fixes-v5-0-0b2f45488418@analog.com> In-Reply-To: <20260501-ad5686-fixes-v5-0-0b2f45488418@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=1777626920; l=4523; i=rodrigo.alencar@analog.com; s=default; h=from:subject:message-id; bh=W7kLkmqYDobLBwqnuuqx8gF9sREn36byIbemRQVPp+E=; b=5nhT/9K6wJDAnvGlUYMjh+DiE1zRsg09lPbdQx0qhhet7cVMnQ3V8VNNdyclP6pVcXtynxss1 jgLsI8hhYj5D/lc3IqAZDd9lH6/XiRHa2If5jwlPsw6kGPaxjJwkpP/ 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 | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/drivers/iio/dac/ad5686.c b/drivers/iio/dac/ad5686.c index 69358dd66cbc..c607251b82a0 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; @@ -488,9 +499,18 @@ int ad5686_probe(struct device *dev, has_external_vref =3D ret !=3D -ENODEV; st->vref_mv =3D has_external_vref ? ret / 1000 : st->chip_info->int_vref_= mv; =20 + /* Initialize masks to all ones provided the max shift (last channel) */ + shift =3D ad5686_pd_mask_shift(&st->chip_info->channels[st->chip_info->nu= m_channels - 1]); + st->pwr_down_mask =3D GENMASK(shift + 1, 0); + st->pwr_down_mode =3D GENMASK(shift + 1, 0); + /* 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)); + 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 Sun Jun 14 07:36:49 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 F2EA637FF77; Fri, 1 May 2026 09:15:21 +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=1777626922; cv=none; b=bmbERS2O14oQ52yILxO22gzVnOqvl/CKUp0OctSzfqh5q1UMlk6heeqDOXxTxVsWo1qbeACTLp26USDeHDQmQfv5fwvbr4mvaCN2vS7rhn0FfT5YqOQZaH0Hk0pJY5HgQS/UxY0WHFhaoVvYgn06zTSl4f+dei9LfyQ5FWTMVUQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777626922; c=relaxed/simple; bh=2NX37FxL9knRW0AxFSKITixceRH+H+70lUhrh0NjoeM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=C5XH6WfoGCv0HEUH6MtE1k6+VmcMakGpZBWwbqQ0sPEx7IJfzLuuNQuhG3SepcHHEWrzMTbmcgUF3SBP7mhlB6jHjLcgcMsqLiqz9Lst082k+uKHM/3s/c+YUU9P7Z2rymefE1RQcSwYWdKr3ik0fwP4sFjimv8g5+p8tnQw6Oc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=cGnH6/rW; 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="cGnH6/rW" Received: by smtp.kernel.org (Postfix) with ESMTPS id C7606C2BCFB; Fri, 1 May 2026 09:15:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777626921; bh=2NX37FxL9knRW0AxFSKITixceRH+H+70lUhrh0NjoeM=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=cGnH6/rWQiTzRNspA7cAtRXrdaam1AnD2QRe5bYnafymhbF3rkU81+udDGFDIDXn2 xrVFHBBw1OpBOZtPbD6BRhlDDAKrXHg/7aXjm6OKb6x2hOSYPecCIgwXN+BpOqsm6M jxBHbq1YiHshqtZs3rhjGTvZp2Q1pns0evXi46zk3LkykgfHMJgBP4s+awqUfrX7X0 ITFJVEJC/uVhhGHa/Vndf7Db24zusJWOE2tGtXZ8yNeuwEK3FoacCmZtyk3+f0GU1m rNze1vhR3VvcL08Frq9QoiS00VaozLI3basCW9vkGIIiDr5DjlU/Le/n0WGxe4yEuy QjsL43ccf2+1w== 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 C00AACD13DF; Fri, 1 May 2026 09:15:21 +0000 (UTC) From: Rodrigo Alencar via B4 Relay Date: Fri, 01 May 2026 10:14:58 +0100 Subject: [PATCH v5 05/12] 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: <20260501-ad5686-fixes-v5-5-0b2f45488418@analog.com> References: <20260501-ad5686-fixes-v5-0-0b2f45488418@analog.com> In-Reply-To: <20260501-ad5686-fixes-v5-0-0b2f45488418@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=1777626920; l=2872; i=rodrigo.alencar@analog.com; s=default; h=from:subject:message-id; bh=fT+WGMtNMPeUhUax2FW9XspbCkjX+ZahzFFizGq24EQ=; b=ypfv+gqVz0Zrhw2QrGhO/MTT+ySLc0fvW39LA7jxca1tN3ong/HRN80jwxb8dJQZ76loCBi/O RwFCkMQFTsODg0P0VUo2oLG+sNJglgUnYNeZjBf223toddPnF3g5RBf 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. Reviewed-by: Andy Shevchenko Signed-off-by: Rodrigo Alencar --- drivers/iio/dac/ad5686-spi.c | 9 +++++++-- drivers/iio/dac/ad5686.c | 13 ++++++------- drivers/iio/dac/ad5686.h | 5 ++--- drivers/iio/dac/ad5696-i2c.c | 10 +++++++--- 4 files changed, 22 insertions(+), 15 deletions(-) diff --git a/drivers/iio/dac/ad5686-spi.c b/drivers/iio/dac/ad5686-spi.c index df8619e0c092..cec784b617e6 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 c607251b82a0..572dcc918ef2 100644 --- a/drivers/iio/dac/ad5686.c +++ b/drivers/iio/dac/ad5686.c @@ -5,17 +5,16 @@ * Copyright 2011 Analog Devices Inc. */ =20 -#include -#include -#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..20f04b74d831 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 Sun Jun 14 07:36:49 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 2EFF03806CA; Fri, 1 May 2026 09:15:22 +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=1777626922; cv=none; b=dDmC7M3rTUDIoMRkhoVPJ0vPfKGh1CuMgDmOSFhQXrwxNCdGTQfcM7KFX56Zq9vNAqB1g7IThci6pxXhRbgiCuwDTVFaKCTpOTu0/80X1iC/LxLS4TSoWdoZohUpL9rYSVL0UrO/FbWAIzpw71EpN1BpO7weMHdy/3d3pBIQxq8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777626922; c=relaxed/simple; bh=cUU49IwGzqomXwO+cbWgn3tRrnMtke2zHDK1OHMoFXs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=YUoWWzxy9QyM0Xi2X3uArAsPmWjAD8q9UoFMNfnpUCpWA9/uEeFu33wvd16+zInSU98/PlB11KKKOUym6jM6qOQ3KMkXiSqn1X/Ik9c8qqQJB+HnnTRCV3f+8nbwxyIccY8mlHHCttRVELhEaPP53VxtoFHqjeJp+7A5zItDyoM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Z4YRMg5+; 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="Z4YRMg5+" Received: by smtp.kernel.org (Postfix) with ESMTPS id D8246C2BCF7; Fri, 1 May 2026 09:15:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777626921; bh=cUU49IwGzqomXwO+cbWgn3tRrnMtke2zHDK1OHMoFXs=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=Z4YRMg5+f7gkAPMmsen3SNFWKFYvCYpywQCfKd7eCkHC89cCVOivCSqSfVJ+KhPXt a6CDhDTm4sy4me8xweOmxGiehH6b5yCkV5vUAFogRNkITFT6yepYlLKoTXeL0QrNb2 t7EQCsU+4oIyxZhsxKHkggbA0NH0nEZr/9JOh3tNpaZ8ZHfwLWMvZ3h/K4GBeVu+BP u47C2+oiAYRlYV9TGa+WEFh5jxMBeevFETo2EptWr+9rU/Cp9fOYSZWo7a2jwSuL2Q la92uyH4UHcuEfno8vPIFAXQ0feFpYMFKnZG2+hmg/qtmHN4NSP1nY51x2MAseIlv4 A87QxdzyaPn8g== 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 CF43DCD3427; Fri, 1 May 2026 09:15:21 +0000 (UTC) From: Rodrigo Alencar via B4 Relay Date: Fri, 01 May 2026 10:14:59 +0100 Subject: [PATCH v5 06/12] 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: <20260501-ad5686-fixes-v5-6-0b2f45488418@analog.com> References: <20260501-ad5686-fixes-v5-0-0b2f45488418@analog.com> In-Reply-To: <20260501-ad5686-fixes-v5-0-0b2f45488418@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=1777626920; l=2960; i=rodrigo.alencar@analog.com; s=default; h=from:subject:message-id; bh=pwWvV2HjzWSFMct9O8d223hNHPcXUCQE4vnfDjAN1E0=; b=+LXCEt41Ma5NmA7SWmewLgCuweMyMqgBUAi+WsqzN6bCSEQ25KPku+lky7HaZrXN9NJS3e80u LTioCDlF4FnCaLkvmbtfpiQZganOkX5IWLCuUWeo4iDtu27vNoVUpc+ 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 572dcc918ef2..d9bab8d7bcb0 100644 --- a/drivers/iio/dac/ad5686.c +++ b/drivers/iio/dac/ad5686.c @@ -112,10 +112,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; } @@ -296,7 +292,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, @@ -418,24 +414,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, @@ -536,11 +532,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 Sun Jun 14 07:36:49 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 0F6733803F0; Fri, 1 May 2026 09:15:22 +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=1777626922; cv=none; b=L/CvLWfwRdmfGw+kvl07BODl2SS6H3lmdMqfRIW22orMxt4CR1J8wS2kJ09KJcUlS3JE3zgKzC5oaWss48H0a3IWe/+5mKvu4PXTZlxOf2IiGDezSKrOvoi6V6P6I4l0gNXvFqLIsRLYahYlZtyVDXXO3weqokoCIbhN8eqoJCc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777626922; c=relaxed/simple; bh=qwor6eqL+Nf7UrW6yM1+y0e/H4Z5XJhyYOftaA7ZZmw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=n9+1ZHyRBd/rJDLu8qTKnFjYfCNFDr7tXex+783xpPzWOiTeicO7MR+isJ9VuZTTslw1jA2LTNOVoXrhcpelMMilk+uC+IrhwOhy+227HcqLoZyp68nAgYxpwEZ6ve9Pxp9mAVw+0WaP7N1ehK5JS5VlVVbI/gHgPqDcpatvosQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=dIw9j1ml; 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="dIw9j1ml" Received: by smtp.kernel.org (Postfix) with ESMTPS id E6B9CC2BD00; Fri, 1 May 2026 09:15:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777626921; bh=qwor6eqL+Nf7UrW6yM1+y0e/H4Z5XJhyYOftaA7ZZmw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=dIw9j1mlaJgE1cK7PcE2Ujhwdi7a2SHXQZykf2P6+Wh3ikCVsOg+L8o8938xB1VIL /qwHaAIwDmOh3oYy6IlPx2KFEFkzDAhXUVAAQieuZt3J25F/EIwjcfP5ZkC8HO89V4 Jp5GpzcN2JmGRWVpnbRLNUd3KEidADzwZ7OfYneFQ+bWWXSrd0P+5m8YAgu1mufXOV BylCDXtCdkWOCsFCEtu79eEwv0MmxQ+1CCaLsYfHOIHr/ch+JOGkQJL+D4flfQXMOF QF4lUDj53gVRxHxzNCHC0JYMcsG9Qsk9Kxc/Hjn9JjCet8jNBWudQt4eWqtW+Iyfet ms5EcBjjwN+tQ== 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 DF789CD13DF; Fri, 1 May 2026 09:15:21 +0000 (UTC) From: Rodrigo Alencar via B4 Relay Date: Fri, 01 May 2026 10:15:00 +0100 Subject: [PATCH v5 07/12] 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: <20260501-ad5686-fixes-v5-7-0b2f45488418@analog.com> References: <20260501-ad5686-fixes-v5-0-0b2f45488418@analog.com> In-Reply-To: <20260501-ad5686-fixes-v5-0-0b2f45488418@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=1777626920; l=20169; i=rodrigo.alencar@analog.com; s=default; h=from:subject:message-id; bh=1QYKftpV2+S7o7DEsZ7rYCT7DL6ul4T0W/aHgGajg74=; b=kwoYQftha6OSura+xyBv6DUiWg1+5iJ9dp2R8yhKb2eePKKNuzFeHw7TkG4Sk4l0sr6b+mma5 pUNq4uxrEv1CNuwdb1gnUThtStgKPpRSN9aUD1hfStO9u14V3jrWJap 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. Reviewed-by: Andy Shevchenko 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 cec784b617e6..5cf60a6e19d1 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 d9bab8d7bcb0..4bcabdbaf1d8 100644 --- a/drivers/iio/dac/ad5686.c +++ b/drivers/iio/dac/ad5686.c @@ -215,7 +215,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), \ } @@ -266,205 +266,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) { @@ -484,8 +451,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 20f04b74d831..e15b01d0b768 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 Sun Jun 14 07:36:49 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 2EF383806C6; Fri, 1 May 2026 09:15:22 +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=1777626922; cv=none; b=kpdBbePo+tNNAoB2sIvH6gWkpi2EEWklCLQIGqzyomCrjATXRaHl/4jD2d7M7LDBirHEmqTmU8pkdYa0C+bDViM20tDJrGmmh9DS09VGWjV2qbqIhUHPVOwoYIU2AMy8SPdQ6phMJ0yeU5uJdiskZ2xmqDX1h2sh1eY4c4VLK5Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777626922; c=relaxed/simple; bh=5OQ30KArxmdJ4d84VYLW3NcLCUWs3NbxBmlSWwWqBIk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=jvPc8e2P07XzmuXG8z9tJ/u2lf2QiUbdzPQMjO12IKoQx4U9FxNc7mSx0hnlFPAiIiwmZ8TF7JSC/2Ramcp2wqGtW3p5neUnpXKS/FhE41+p0N3eM1n7ijk4CosGQVr+9+hHw3EARGtozwGBmE7N4Bh8NKpirgxZu7jgG4xwyFY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Sa45h8Ub; 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="Sa45h8Ub" Received: by smtp.kernel.org (Postfix) with ESMTPS id 008EAC2BCC4; Fri, 1 May 2026 09:15:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777626922; bh=5OQ30KArxmdJ4d84VYLW3NcLCUWs3NbxBmlSWwWqBIk=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=Sa45h8UbLgmP6B08h7moumnFX6vQjWuLfT4SMtmGbxBsKTtL1pf8lTY0PlfF+Mda/ cbp/Phzorq8Dtz17esa2NxR/xm5wzZTAzAO6shvUqCOuSDME/7TyuibRTnyn6RdZuz KBe1stAaMQZ1OQFsJgGDZeKe1iUa3UmTVF2Ni/e6lK9V2/mlN5rTOUXQFauOAcNs0+ oNJGXQxnPCDRl95HEo/1dgPxfCEqmmlegxhMdmqDs5U8DPt+r+b/JLBFMWZNWr+Inl codFdAbj8n448Rz2c8tZF4e5ydZyjWdsECFuKDttRoXberF5wQndbswXPHYwLVEdvz rWQmDIQjJjmMg== 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 EEF77CD3424; Fri, 1 May 2026 09:15:21 +0000 (UTC) From: Rodrigo Alencar via B4 Relay Date: Fri, 01 May 2026 10:15:01 +0100 Subject: [PATCH v5 08/12] 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: <20260501-ad5686-fixes-v5-8-0b2f45488418@analog.com> References: <20260501-ad5686-fixes-v5-0-0b2f45488418@analog.com> In-Reply-To: <20260501-ad5686-fixes-v5-0-0b2f45488418@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=1777626920; l=1909; i=rodrigo.alencar@analog.com; s=default; h=from:subject:message-id; bh=wFk8LhEhsvyl3awicLq5nznLuet66NPWLXqtRqBdDRo=; b=DrYx688xizfhl8205GXJZ7snmn2tUiX3LoCWbk8I3qTD6EYy/MyHGTV6UcFUaQh43ku6Pthoa +h0PsWZN7LwBEzoVNvY6UV9dxo25/czJ1dE6d4JogWCq+xhn/RI2M9G 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. Reviewed-by: Andy Shevchenko 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 5cf60a6e19d1..9493511d9e7f 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 Sun Jun 14 07:36:49 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 291713806C3; Fri, 1 May 2026 09:15:22 +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=1777626922; cv=none; b=g+EBAFnnxEoeDi8ZVXYAollTez94XheFKVSxXWaZj5hH0mU1F8Gk9Nqh7ULldv75Tgl6bhp7d4njCCG7UbFC4J9G4Zon+8MOchZZxLRlaoZIT4hvwQ+Tfgw5OPd6R2WRjiDvYs1nMcic4OQTJLyyuz1R1YSLrZL69sQYAgPQMGw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777626922; c=relaxed/simple; bh=fsH1jPF6Bh/zdH62+5u0lhafUJIHMmkjNiDxO+DqKUw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=BT1oIZnCWS5GR0Tef+KkoBe2x3LpMKDKLnst1u7vM1SFAqJ4jxKV00yebCY6B6BE/fq8pR+gZMPzA/RZPgBdjr/FrFTdlAVAsvog+ckVREqySQ8jeg04OsSVlATIwMgtx8ITVdaBgZH/ZtLwNFCP1QVqiLeNNkSj9V2bhg+gdFE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=KzZhja0Q; 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="KzZhja0Q" Received: by smtp.kernel.org (Postfix) with ESMTPS id 0F029C2BCC6; Fri, 1 May 2026 09:15:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777626922; bh=fsH1jPF6Bh/zdH62+5u0lhafUJIHMmkjNiDxO+DqKUw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=KzZhja0QJ74GVZPix2avt7C/RkEdsMMAp8Nhc9jLqF3TxsiI9JOWRkraLEKQHKboy 3Af7Q9i+Pjby0kW/asy91khWUdMn7Aw95FgR3T8ut0AFL/u6LEeUGt1LBpcLf16/A5 9YUJT7p6W+VHoPAEc8NlxE/lmwiBKQoOVWLMB3IJXECabgZJhfA/eM3cAnMUV7dxC2 fdNdptDnpvyjO0npOodKP3X4tEZ5tPVf96Ex+VaatL833Gs9FJoUJkt6EYc0pqeL4f ewTYRcGKao2EoOyU2Mg3xROeVgLxDVzsKS3p8ZLTdCQTR2RPJ7wRPKtw3NtJ1buG6C M3ZISoaV75u1g== 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 086E0CD3425; Fri, 1 May 2026 09:15:22 +0000 (UTC) From: Rodrigo Alencar via B4 Relay Date: Fri, 01 May 2026 10:15:02 +0100 Subject: [PATCH v5 09/12] iio: dac: ad5686: add helpers to handle powerdown masks 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: <20260501-ad5686-fixes-v5-9-0b2f45488418@analog.com> References: <20260501-ad5686-fixes-v5-0-0b2f45488418@analog.com> In-Reply-To: <20260501-ad5686-fixes-v5-0-0b2f45488418@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=1777626920; l=4174; i=rodrigo.alencar@analog.com; s=default; h=from:subject:message-id; bh=LfdwOv6cXWsUcCzXJnTuYHrsc0qYNTRQXLs9jOjn8go=; b=gNPrM9AripfmxspgYnrMtaO/ZssbPQtrXIE9LUZxPJY+ntbITju2c/wMvHkfu9d1ijs79PZzi qWjZCCg5syLCDTcDpsVllaGLBY3YJUCtwhfcdasQmmct7FpL8zSi3GF 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 ad5686_pd_field_set() and ad5686_pd_field_get() helpers to cleanup powerdown mask control. Define AD5686_PD_* constants, like AD5686_PD_MSK to hold powerdown mask value for a single channel. Signed-off-by: Rodrigo Alencar Reviewed-by: Andy Shevchenko --- drivers/iio/dac/ad5686.c | 43 +++++++++++++++++++++++++++---------------- drivers/iio/dac/ad5686.h | 5 +++++ 2 files changed, 32 insertions(+), 16 deletions(-) diff --git a/drivers/iio/dac/ad5686.c b/drivers/iio/dac/ad5686.c index 4bcabdbaf1d8..4b279d46948d 100644 --- a/drivers/iio/dac/ad5686.c +++ b/drivers/iio/dac/ad5686.c @@ -33,26 +33,39 @@ static inline unsigned int ad5686_pd_mask_shift(const s= truct iio_chan_spec *chan return __ffs(chan->address) * 2; } =20 +static inline void ad5686_pd_field_set(const struct iio_chan_spec *chan, + unsigned int *pd, unsigned int val) +{ + unsigned int shift =3D ad5686_pd_mask_shift(chan); + + *pd &=3D ~(AD5686_PD_MSK << shift); + *pd |=3D (val & AD5686_PD_MSK) << shift; +} + +static inline unsigned int ad5686_pd_field_get(const struct iio_chan_spec = *chan, + unsigned int pd) +{ + unsigned int shift =3D ad5686_pd_mask_shift(chan); + + return (pd >> shift) & AD5686_PD_MSK; +} + 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 >> shift) & 0x3) - 1; + return ad5686_pd_field_get(chan, st->pwr_down_mode) - 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); - - st->pwr_down_mode &=3D ~(0x3 << shift); - st->pwr_down_mode |=3D (mode + 1) << shift; + ad5686_pd_field_set(chan, &st->pwr_down_mode, mode + 1); =20 return 0; } @@ -67,10 +80,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 << shift))); + return sysfs_emit(buf, "%d\n", + !!ad5686_pd_field_get(chan, st->pwr_down_mask)); } =20 static ssize_t ad5686_write_dac_powerdown(struct iio_dev *indio_dev, @@ -91,10 +104,8 @@ static ssize_t ad5686_write_dac_powerdown(struct iio_de= v *indio_dev, =20 guard(mutex)(&st->lock); =20 - if (readin) - st->pwr_down_mask |=3D 0x3 << ad5686_pd_mask_shift(chan); - else - st->pwr_down_mask &=3D ~(0x3 << ad5686_pd_mask_shift(chan)); + ad5686_pd_field_set(chan, &st->pwr_down_mask, + readin ? AD5686_PD_PWR_DOWN : AD5686_PD_PWR_UP); =20 switch (st->chip_info->regmap_type) { case AD5310_REGMAP: @@ -467,10 +478,10 @@ int ad5686_probe(struct device *dev, =20 /* Set all the power down mode for all channels to 1K pulldown */ 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; + ad5686_pd_field_set(&st->chip_info->channels[i], + &st->pwr_down_mask, AD5686_PD_PWR_UP); + ad5686_pd_field_set(&st->chip_info->channels[i], + &st->pwr_down_mode, AD5686_PD_1K_TO_GND); } =20 indio_dev->name =3D name; diff --git a/drivers/iio/dac/ad5686.h b/drivers/iio/dac/ad5686.h index caadc7403da1..6b7142fbade2 100644 --- a/drivers/iio/dac/ad5686.h +++ b/drivers/iio/dac/ad5686.h @@ -47,6 +47,11 @@ #define AD5683_REF_BIT_MSK BIT(12) #define AD5686_REF_BIT_MSK BIT(0) =20 +#define AD5686_PD_MSK GENMASK(1, 0) + +#define AD5686_PD_1K_TO_GND 0x1 +#define AD5686_PD_PWR_UP 0x0 +#define AD5686_PD_PWR_DOWN AD5686_PD_MSK =20 enum ad5686_regmap_type { AD5310_REGMAP, --=20 2.43.0 From nobody Sun Jun 14 07:36:49 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 3B3183806CD; Fri, 1 May 2026 09:15:22 +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=1777626922; cv=none; b=kyF5D+FAVYONzwsUbv3fq7fh8LI1MzC8JFw9Y9vY1AgTi+3ZVGJdUbwtdNUAAsGYyWWrVoqNZocDiv/a4d0waxzOHEv5OoCxARcNmhFCvDs8zfSGiRgSoAtPUAU5dnYGewiKQAdZryTiGsbPa278yYSC+zWiYDY/xPjC+CVvz2A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777626922; c=relaxed/simple; bh=Xjb4oT1rIEJBQqYZOCf/Z9YGzi3v5IEN6e4xXhW065w=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=dee+Q1odAiQb9qNV0FjBgKRRujUyDOabE0jiF8ugC+roBYxGkjycgPQjGocthG4bq1E9g4597yqwY4fsUMAMsK2CwLdryfVAiJGQEXzipMgsDz5l7lbW3uPGdso3r1ewsSxDB9qIcI8AqSW7sSjRc5uOnb/vr2zDf4xVTJpDN/A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=HzMUr4OP; 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="HzMUr4OP" Received: by smtp.kernel.org (Postfix) with ESMTPS id 1FDAAC2BCB7; Fri, 1 May 2026 09:15:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777626922; bh=Xjb4oT1rIEJBQqYZOCf/Z9YGzi3v5IEN6e4xXhW065w=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=HzMUr4OPtZsYiExu5UPO3a/6cJeTinq8iBSa1gbDjGzYQ5oaeizTcmdj6/ea3q6JN s9duLnAA8dES/jsi45boQ/YKQWhxcDEB+PWIvGPkBM60Y6RZqt/Rp/evia/wOSGtNo r8OWCyH5GfN7II0X/qLSty8QrDe7/5n5Va1AZlF4pLY683mzqThZOE40vtDeiMR0db tmMHzx4ij9XDJyP6BhLBNpXan8MIxPJ/OLW8qwyIFaOwSQ0LrU+W1xIt/YQl9C+31v f8/FXT695hMf6YWP6nc5HiT+hNc8xacs8zZHUSdOMA6OLx9YWSmyWPNYxnzgTkf1UV UBiXYrpAjPWxw== 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 1806AFF885A; Fri, 1 May 2026 09:15:22 +0000 (UTC) From: Rodrigo Alencar via B4 Relay Date: Fri, 01 May 2026 10:15:03 +0100 Subject: [PATCH v5 10/12] 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: <20260501-ad5686-fixes-v5-10-0b2f45488418@analog.com> References: <20260501-ad5686-fixes-v5-0-0b2f45488418@analog.com> In-Reply-To: <20260501-ad5686-fixes-v5-0-0b2f45488418@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=1777626920; l=6721; i=rodrigo.alencar@analog.com; s=default; h=from:subject:message-id; bh=U3hde+Gs2+xhRnKuTyBE9op/VIcH5/Q3HwJnTL418lc=; b=3KYy2+L0lcS/pD5fX7/70h8urw8PNKLa/uZ4xHhyOX0sNpd+clA5O/Bl6YObvGkw+zJGTG3+4 u443ehlKYSiBXrOAl9+Qa5fRVXA6F0TK5mbUODTYInexiP3MzId2PR9 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 consume 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. Powerdown masks initialization is simplified as *_control_sync() masks outs any unused bits for the single-channel case. 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 | 94 +++++++++++++++++++++++++++-----------------= ---- drivers/iio/dac/ad5686.h | 7 ++-- 2 files changed, 59 insertions(+), 42 deletions(-) diff --git a/drivers/iio/dac/ad5686.c b/drivers/iio/dac/ad5686.c index 4b279d46948d..b94efa6de16e 100644 --- a/drivers/iio/dac/ad5686.c +++ b/drivers/iio/dac/ad5686.c @@ -6,6 +6,7 @@ */ =20 #include +#include #include #include #include @@ -13,6 +14,7 @@ #include #include #include +#include =20 #include =20 @@ -24,6 +26,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 & AD5686_PD_MSK) | + 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 & AD5686_PD_MSK) | + 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) @@ -95,8 +115,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) @@ -109,32 +129,34 @@ static ssize_t ad5686_write_dac_powerdown(struct iio_= dev *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, @@ -448,9 +470,6 @@ 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; int ret, i; =20 indio_dev =3D devm_iio_device_alloc(dev, sizeof(*st)); @@ -468,13 +487,12 @@ 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 - /* Initialize masks to all ones provided the max shift (last channel) */ - shift =3D ad5686_pd_mask_shift(&st->chip_info->channels[st->chip_info->nu= m_channels - 1]); - st->pwr_down_mask =3D GENMASK(shift + 1, 0); - st->pwr_down_mode =3D GENMASK(shift + 1, 0); + /* Initialize masks to all ones */ + st->pwr_down_mask =3D ~0U; + st->pwr_down_mode =3D ~0U; =20 /* Set all the power down mode for all channels to 1K pulldown */ for (i =3D 0; i < st->chip_info->num_channels; i++) { @@ -496,29 +514,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 6b7142fbade2..dc1961b8c15e 100644 --- a/drivers/iio/dac/ad5686.h +++ b/drivers/iio/dac/ad5686.h @@ -44,9 +44,12 @@ #define AD5686_CMD_READBACK_ENABLE_V2 0x5 =20 #define AD5310_REF_BIT_MSK BIT(8) -#define AD5683_REF_BIT_MSK BIT(12) -#define AD5686_REF_BIT_MSK BIT(0) +#define AD5310_PD_MSK GENMASK(10, 9) =20 +#define AD5683_REF_BIT_MSK BIT(12) +#define AD5683_PD_MSK GENMASK(14, 13) + +#define AD5686_REF_BIT_MSK BIT(0) #define AD5686_PD_MSK GENMASK(1, 0) =20 #define AD5686_PD_1K_TO_GND 0x1 --=20 2.43.0 From nobody Sun Jun 14 07:36:49 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 4BADE3815D0; Fri, 1 May 2026 09:15:22 +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=1777626922; cv=none; b=d/13C/9mQeELGT6bgTQsE2JAqGgOwk37fjIlWZ+XEXYQHPW+M1VY3SyE/UgsLacA71dX2yfpk8inhUcU1iEy6eeDJPAqoODjexgmpS47u4p478fBF/Khxr1L0puxjgzp+FWiaZe7W6Fx8VbLB6NW/E2xC6XuHEFx+ampBGsPHZ4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777626922; c=relaxed/simple; bh=u8zu46aZYFGibuKEYjYUVhjHGlkJ1ASQ/l0RlSN+kho=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=JCVZVZH85dSzD1cTV9Pw5x/V8dSC8CKtE4W4hXPKCdr4CblUpsis0iNqSxY8M2wIFaVH/3eLNwx45FU2sduiCuKbn0UL3LYrNQ1oGdw126fqqUM6DQG1EyjImGqn6ltgqaL21HRPxGpD5JU06VIwCa8yB2lk9ZnylTZb5hALzL8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=gu+Q1ZHe; 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="gu+Q1ZHe" Received: by smtp.kernel.org (Postfix) with ESMTPS id 2EC2EC2BCF5; Fri, 1 May 2026 09:15:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777626922; bh=u8zu46aZYFGibuKEYjYUVhjHGlkJ1ASQ/l0RlSN+kho=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=gu+Q1ZHeAdc8Doi/Ug6SyUy+XFt9gkngw9Gmq/WCMYUvF0xMlRzBrD9FZaSGXujQ8 l4fPHiD6AEv1jZgFb7dZBsv/20YIuaa+WVnuTS029nOxkKcKVRuQOal32vzurqiRPM 7+ynlnlXfO0JztsyQeRYO9zPIrjPWIRs5i0B/ZP5V1LAEHDLCSKfcg5+l91s4Or6yN 0ZTKdU9TKuO4msCBja46eC6GVFQ7SpMvXGwf65Gy2ze+l0nbrfnI+4ZBtuQzrcA2ZN j5gF5udGOLCTyXAvCFmMPbgB1fK4oENqG1tez/pl5MFGWdwpmogxUq/Tzgrk+LGoiI 0YF5VhfHFSFSg== 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 26953CD3425; Fri, 1 May 2026 09:15:22 +0000 (UTC) From: Rodrigo Alencar via B4 Relay Date: Fri, 01 May 2026 10:15:04 +0100 Subject: [PATCH v5 11/12] 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: <20260501-ad5686-fixes-v5-11-0b2f45488418@analog.com> References: <20260501-ad5686-fixes-v5-0-0b2f45488418@analog.com> In-Reply-To: <20260501-ad5686-fixes-v5-0-0b2f45488418@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=1777626920; l=1894; i=rodrigo.alencar@analog.com; s=default; h=from:subject:message-id; bh=4+83aSZnpGuEadPYOq6kP/k+cVfg4F573+ewfHsOtHM=; b=0uKj2q4RMxiArBN662T2FQfLHUT0FdxCGMqWT7et1w85st4AjaNFVgA3ZlHLNgbWp6aQY2MBr 578Is4rapb1A1MadikRGAGs6/4Ocyu3zUoH65yQOOdBg1ZgBpAB99i0 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. Reviewed-by: Andy Shevchenko 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 dc1961b8c15e..4c38dd43d4bb 100644 --- a/drivers/iio/dac/ad5686.h +++ b/drivers/iio/dac/ad5686.h @@ -71,12 +71,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; @@ -114,16 +113,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 Sun Jun 14 07:36:49 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 58FD83815E8; Fri, 1 May 2026 09:15:22 +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=1777626922; cv=none; b=DeaDnHEvxoHMBZDaSIij04gEWN8tm1AkYpnyMB/t0EHk25L7Q7HN6+ofhkpv3B1PBUkWmfZzVR3vVd1qgoa2OgNMOp2ZrMvZTxNAqpyuEBE0cOiYNTuLEl2/XVWsCj1ikG7vxwzHjc6PrrZH0xr/29cttvOuAD0O3j55X1MOwgY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777626922; c=relaxed/simple; bh=FjmjF5sRlW0vvlgaR9iIiuIzxWP3S/xJbLbY0+BIlv0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=GHVLY2OPRBYrxHj0LUXizsBZUhUO3Y22OOU/5Up+DyBJfJNiOyYgEVBzJQ5SH5sqvXmfuhM6YS08OyZoRuky6gGdhA94o9Al+eMSXef9y6EYRuGuX5JZFtjBsuhP384HPYCm/JKLvuoOkzSkmW3PrknUu39cAHmT9qJyaXhn74U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=IWRoI4gl; 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="IWRoI4gl" Received: by smtp.kernel.org (Postfix) with ESMTPS id 3D44DC2BCF6; Fri, 1 May 2026 09:15:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777626922; bh=FjmjF5sRlW0vvlgaR9iIiuIzxWP3S/xJbLbY0+BIlv0=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=IWRoI4glfMgmE4zyR4EbUNxrmIV2y1pVQ2RBo1nOygQuVnI1O95yUCOfsXzzw69Xp Fr/Os5wxPm+2mmUw04gqJ5YL0hFVuYljn7SsfGRzNUdKdRTMbEkia8CDqxMMI4pujT V51TftyZKE7j+LFEGbK6qwndRzZJD1lEK7ORFlx5uWMpCyz3CH4egFDUvGLmHmFp33 QNEv+ECbopQdj7yCDgXo/03amwbA6CMHnsM8GGPvOBr5hvSM1cDkSaCD5w7IOp42z/ E4uWBnAGU2lcgSIwDXUrwbrALsgxR2s8RHJsYidqot+zIr1eWUzF7wCRE93y20JL7p +MaXjclJJZSxw== 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 3669BCD3424; Fri, 1 May 2026 09:15:22 +0000 (UTC) From: Rodrigo Alencar via B4 Relay Date: Fri, 01 May 2026 10:15:05 +0100 Subject: [PATCH v5 12/12] 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: <20260501-ad5686-fixes-v5-12-0b2f45488418@analog.com> References: <20260501-ad5686-fixes-v5-0-0b2f45488418@analog.com> In-Reply-To: <20260501-ad5686-fixes-v5-0-0b2f45488418@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=1777626920; l=7630; i=rodrigo.alencar@analog.com; s=default; h=from:subject:message-id; bh=R3ZcXIDA8Ei+0XBUOZtKsoDqu9PKMLX4OLhx5MnXzf0=; b=pNzgcwNp6mfiNpncULm36VVKS69kFTxBX/7rHcHR1QHxsF2V8jXQUyPCCN9T3yMxnN+gQ1T6K R49neFVqGSvAimE0e1uA8M4Mv1T8xWagrtarYcyM/EvenzgvjZ89+xu 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. Reviewed-by: Andy Shevchenko 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 9493511d9e7f..7409624b954b 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 b94efa6de16e..8ebd1d4c73d4 100644 --- a/drivers/iio/dac/ad5686.c +++ b/drivers/iio/dac/ad5686.c @@ -30,18 +30,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 & AD5686_PD_MSK) | - 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 & AD5686_PD_MSK) | + 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 & AD5686_PD_MSK) | - 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 & AD5686_PD_MSK) | + 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) @@ -148,7 +148,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; @@ -171,7 +171,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; @@ -201,10 +201,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: @@ -465,8 +463,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; @@ -479,8 +476,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"); @@ -524,8 +520,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 4c38dd43d4bb..51fb5a8cb756 100644 --- a/drivers/iio/dac/ad5686.h +++ b/drivers/iio/dac/ad5686.h @@ -64,10 +64,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 @@ -115,6 +120,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 @@ -126,11 +132,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 @@ -149,8 +154,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 e15b01d0b768..6250c227293c 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