From nobody Fri Jun 19 07:51:08 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A42F73431F5; Sun, 26 Apr 2026 08:38:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777192699; cv=none; b=oLCxJuzKWR8KuYCutDPBdttxmKBjwzmUtlgcOtngrRcF+GJwOmwOX07hGxsAnq7ORlTOr5/rmoFUnGa8ZZjWDMp/ugNu/dN1Z7XZrvRLIJb9O5DEAn8V2EpHYok+ptE+4K7BM5DlixcC0Cd3OXJGPgUqx89Bwt91qGSv6yA1RjU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777192699; c=relaxed/simple; bh=zkw/jX97Bkte0ssy8r+Xi+ICKzcrw1tjRGX9BTbOXa0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=felpxaSEnLbuq6vJeBXaKSH0sP9lyGGq9TCaDmnQ8sl2MkUmlUyQdLzg/Sbn5zJCpZESj5LMHClbX5MiWLGgiY8pYBH277DkgKlko0tC3QleDlHG/u0O1KeMrTrgB2oLGOwTPl1dxRWj7Z2JL0y1VSgeLLTJJoSGUs0vX5X9DVw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=VPkE0l5c; 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="VPkE0l5c" Received: by smtp.kernel.org (Postfix) with ESMTPS id 70A0EC2BCB6; Sun, 26 Apr 2026 08:38:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777192699; bh=zkw/jX97Bkte0ssy8r+Xi+ICKzcrw1tjRGX9BTbOXa0=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=VPkE0l5cTIoLqXV4tq9k76yK25962qDgmqKrnC0oxqlt62R0zguFxwMw019FYMSOA grFqNwlzolfCHoEJest1a93vCVI/uvvBEjvNcaPbOSf5JD4Da+IpIXkCBnjKN/r5v9 pB99GEEshP6y1YKS9RmUy9VvCZudF8Jjc1ctCiJW67Ve1KJWWGaMtYOpqLGv/jgepG JZnPVfxtA3Y1wQEiJY6JG/5K3Fso+zqpKOPlOBqWm9465uGtDDLhqMyhseVGG7A41d wjy17bha6/iWAcnhLfSG/eLtX1bGG1WlXPq4A66wLIz6pgxOcpTxAV/xcAYe+fVpwv LHHYg3PJK9zpA== 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 5F15FFF885E; Sun, 26 Apr 2026 08:38:19 +0000 (UTC) From: Rodrigo Alencar via B4 Relay Date: Sun, 26 Apr 2026 09:38:02 +0100 Subject: [PATCH 01/10] 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: <20260426-ad5686-fixes-v1-1-7c946a77794e@analog.com> References: <20260426-ad5686-fixes-v1-0-7c946a77794e@analog.com> In-Reply-To: <20260426-ad5686-fixes-v1-0-7c946a77794e@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=1777192698; l=2747; i=rodrigo.alencar@analog.com; s=default; h=from:subject:message-id; bh=hG+QZ88Yrv665s9LlxVFcq35xRZvWWlXJCiMyN4Qw5g=; b=DM1T8ZuD23Muz8Xsehs+Z421temOK40/kC1CjDGq0mZqR3hLh5xak7JxTTc5pvnUHl4KzD1ti ceknXzRzxzTDTt8xQpVmc1broR4YaNrQ8Jg851EHnes15EGDgS2qkMR 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 list is sorted accordingly. 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, 20 insertions(+), 17 deletions(-) diff --git a/drivers/iio/dac/ad5686-spi.c b/drivers/iio/dac/ad5686-spi.c index df8619e0c092..695125238633 100644 --- a/drivers/iio/dac/ad5686-spi.c +++ b/drivers/iio/dac/ad5686-spi.c @@ -8,11 +8,16 @@ * Copyright 2018 Analog Devices Inc. */ =20 -#include "ad5686.h" - +#include +#include +#include #include #include =20 +#include + +#include "ad5686.h" + static int ad5686_spi_write(struct ad5686_state *st, u8 cmd, u8 addr, u16 val) { diff --git a/drivers/iio/dac/ad5686.c b/drivers/iio/dac/ad5686.c index 9a384c50929b..1a6eb3832f22 100644 --- a/drivers/iio/dac/ad5686.c +++ b/drivers/iio/dac/ad5686.c @@ -5,17 +5,12 @@ * Copyright 2011 Analog Devices Inc. */ =20 -#include -#include -#include +#include +#include +#include #include -#include -#include -#include #include - -#include -#include +#include =20 #include "ad5686.h" =20 diff --git a/drivers/iio/dac/ad5686.h b/drivers/iio/dac/ad5686.h index e7d36bae3e59..3fcc792ea656 100644 --- a/drivers/iio/dac/ad5686.h +++ b/drivers/iio/dac/ad5686.h @@ -8,10 +8,9 @@ #ifndef __DRIVERS_IIO_DAC_AD5686_H__ #define __DRIVERS_IIO_DAC_AD5686_H__ =20 -#include -#include +#include #include -#include +#include =20 #include =20 diff --git a/drivers/iio/dac/ad5696-i2c.c b/drivers/iio/dac/ad5696-i2c.c index d3327bca0e07..e7e1b8a6fc71 100644 --- a/drivers/iio/dac/ad5696-i2c.c +++ b/drivers/iio/dac/ad5696-i2c.c @@ -7,10 +7,14 @@ * Copyright 2018 Analog Devices Inc. */ =20 -#include "ad5686.h" - -#include +#include #include +#include +#include + +#include + +#include "ad5686.h" =20 static int ad5686_i2c_read(struct ad5686_state *st, u8 addr) { --=20 2.43.0 From nobody Fri Jun 19 07:51:08 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A427E342C98; Sun, 26 Apr 2026 08:38:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777192699; cv=none; b=utum5MdbYuS/vd6eGwxCz8DnKGtZsOFhbuaDA7cd5Gupdqs8ILnStP/kAqHRSzgcfiinqB4g9Qk+GkcCPehONaJrkd2yB7KQ4+daUkpM1yekc+C4sTk8fP+lUZF9QvvPzCKBhtp+sm0HqbvpcFz9BniaUJKlA6C+16tfALP6Psk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777192699; c=relaxed/simple; bh=cbuDm6FVS9j6IEsNVeVUYIKUme8sTUk+D87Au/xl8Rc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=MyheFiujdG0v+jlVmxgG+SC2klj75NOKv4Gs1ns3onVLLYWYKbHYXJw0C0jybEkaMWjITpJgeQZzsWrEicRzBTGKYFDRZ0rz1YrCxiX7GlrvcdLHuv84h7zVTjk8K8g7GC8HFNVKhe60HD/xzk/idgNGI3C4zAodXPDT2LDjU5M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=rqyrQICO; 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="rqyrQICO" Received: by smtp.kernel.org (Postfix) with ESMTPS id 79F77C2BCB7; Sun, 26 Apr 2026 08:38:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777192699; bh=cbuDm6FVS9j6IEsNVeVUYIKUme8sTUk+D87Au/xl8Rc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=rqyrQICOIdaVsYg7z6nQslqnU+Ln+Bis8dcebCRidtJ86qeWTUwVPEXRC2yh6IdI7 HEaR4mIkpRw2meQpx8QHX1X/+en0eb6/EsVnJU1Bx15UeYb/7VdWb4Fq2teCO8nzh9 6XqFGGHrMYjBaBSmA+JV2q7CbAhynVNX5jrr/8XPxOAUmt9XWPyC5e3wBL2L3Fzjos kNSg+sDlMeVDIC3DGWYGc55yzpa6E1j34M8Qtu7Cdhc1dGtoQ7chCncvI+DEPxvrNk 1uax934WIc9veW2wnCt5OKL3a6zRj6GsVl75Y9CQuZmxRd+I/NvUh5EkuP0dNkQ4SO GXjnM92K5dkvA== 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 6DEC2FF8860; Sun, 26 Apr 2026 08:38:19 +0000 (UTC) From: Rodrigo Alencar via B4 Relay Date: Sun, 26 Apr 2026 09:38:03 +0100 Subject: [PATCH 02/10] 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: <20260426-ad5686-fixes-v1-2-7c946a77794e@analog.com> References: <20260426-ad5686-fixes-v1-0-7c946a77794e@analog.com> In-Reply-To: <20260426-ad5686-fixes-v1-0-7c946a77794e@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=1777192698; l=2906; i=rodrigo.alencar@analog.com; s=default; h=from:subject:message-id; bh=QmKdjj798uhH4/it8tuOBgAkAWAuRLHliOPg7NhnXgA=; b=SyJia5ZWYXpGSbDtGx8UA+ZVcjL0prrrMJcGu3Fktt60dCqSNHfuj9XhaeC8Z66KKDgS8ZD5u +5bjusfsKVnDCLAibqCeTNYEwUVi6tuTksK9aqw7RXfL5ZK3OweSmms 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 1a6eb3832f22..0bc925bd827e 100644 --- a/drivers/iio/dac/ad5686.c +++ b/drivers/iio/dac/ad5686.c @@ -93,10 +93,6 @@ static ssize_t ad5686_write_dac_powerdown(struct iio_dev= *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; } @@ -277,7 +273,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, @@ -399,24 +395,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, @@ -508,11 +504,6 @@ int ad5686_probe(struct device *dev, cmd =3D AD5686_CMD_INTERNAL_REFER_SETUP; ref_bit_msk =3D 0; 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 3fcc792ea656..fe6482e84178 100644 --- a/drivers/iio/dac/ad5686.h +++ b/drivers/iio/dac/ad5686.h @@ -45,7 +45,6 @@ =20 #define AD5310_REF_BIT_MSK BIT(8) #define AD5683_REF_BIT_MSK BIT(12) -#define AD5693_REF_BIT_MSK BIT(12) =20 /** * ad5686_supported_device_ids: @@ -88,7 +87,6 @@ enum ad5686_regmap_type { AD5310_REGMAP, AD5683_REGMAP, AD5686_REGMAP, - AD5693_REGMAP }; =20 struct ad5686_state; --=20 2.43.0 From nobody Fri Jun 19 07:51:08 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B1A55343D63; Sun, 26 Apr 2026 08:38:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777192699; cv=none; b=Mb+tuRge/86LwX04gflvhhikJTJp63QVfXxAz8+C4Qajt0IPf8SEysaiO3eWgctFcMscxl8co9iY+1scQVBgkaKnklhFuHGgJFD1GODMZD/a4fkcIrPd6eMUY0h9jHVbbYvuWgGo5L221XtfYRxPCs7T6Rpu3bWZicD1BwLYA6I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777192699; c=relaxed/simple; bh=uE8TmryrUOflYH5PKjhmfXEjv2OTwIKio6fARjd8UiE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=XZqlq96SidrSoq+Uw8M+kn7CRakCjoQnNJX48Fd7EL3HKwHCNFmGValBtTncZKQZMOR+54+u5y253FUdELmYKrayJJOQ6o4M4MIYG4/cylbeeIGpw1tpn4L85vImQrwJDVYD7rdPpPlcs89SioEymb+/2SDznj6YFKi8BpTIj9U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=pSXhrmeI; 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="pSXhrmeI" Received: by smtp.kernel.org (Postfix) with ESMTPS id 8B1B6C2BCC4; Sun, 26 Apr 2026 08:38:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777192699; bh=uE8TmryrUOflYH5PKjhmfXEjv2OTwIKio6fARjd8UiE=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=pSXhrmeI3vbV9vMFWzUwDMD5ElMhPxbqAXkKHPaQuqhm3w+z9DPknjWzn5rxuPQju noNZOJXrRGrhjREPRdqYQrXiL/zFujo8zaoXdQK7HLIxdGnxBQOVQsfVrmFGuta924 LXNxCXbhM0lsT0mfYCf/8cIXBahlUr0NkpgVoiBCZr23mYBBope8YTWTD6z/VLgGLm QuiPXAkkAj+t1v7kC5oQcY8+D0aasen8vOGzfhAoOiMnCsZZFgPmD3M+i65Hkdp8mm ephgRg2mLieMbIEcBvcdakX2zV9nLJLCO7eyGuYrzBchFTb6LtgcU6OIUMqdWvtaSw 2grYTfRcXFR3A== 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 7E65EFF885C; Sun, 26 Apr 2026 08:38:19 +0000 (UTC) From: Rodrigo Alencar via B4 Relay Date: Sun, 26 Apr 2026 09:38:04 +0100 Subject: [PATCH 03/10] 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: <20260426-ad5686-fixes-v1-3-7c946a77794e@analog.com> References: <20260426-ad5686-fixes-v1-0-7c946a77794e@analog.com> In-Reply-To: <20260426-ad5686-fixes-v1-0-7c946a77794e@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=1777192698; l=20111; i=rodrigo.alencar@analog.com; s=default; h=from:subject:message-id; bh=5/IuQQzNLZeXhN4RtzsUsWY1u/5PqJquyZo5/jKN+rQ=; b=rvVc7b4PrRL3BCUvvFXco01qlXZULUq21Zho6BFXn6b/FuuHBug10RSDf0LaarlKeLetTZ6f/ O/PLhYl52ChDCT8E1QK0Romx+/PHSJZFZQqLxatXE7dkeFkQ/+Cfamn 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 common probe function. Signed-off-by: Rodrigo Alencar --- drivers/iio/dac/ad5686-spi.c | 38 +++-- drivers/iio/dac/ad5686.c | 358 ++++++++++++++++++++-------------------= ---- drivers/iio/dac/ad5686.h | 66 ++++---- drivers/iio/dac/ad5696-i2c.c | 65 ++++---- 4 files changed, 241 insertions(+), 286 deletions(-) diff --git a/drivers/iio/dac/ad5686-spi.c b/drivers/iio/dac/ad5686-spi.c index 695125238633..73e6c998add0 100644 --- a/drivers/iio/dac/ad5686-spi.c +++ b/drivers/iio/dac/ad5686-spi.c @@ -94,29 +94,27 @@ static int ad5686_spi_read(struct ad5686_state *st, u8 = addr) =20 static int ad5686_spi_probe(struct spi_device *spi) { - const struct spi_device_id *id =3D spi_get_device_id(spi); - - return ad5686_probe(&spi->dev, id->driver_data, id->name, - ad5686_spi_write, ad5686_spi_read); + return ad5686_probe(&spi->dev, spi_get_device_match_data(spi), + spi->modalias, ad5686_spi_write, ad5686_spi_read); } =20 static const struct spi_device_id ad5686_spi_id[] =3D { - {"ad5310r", ID_AD5310R}, - {"ad5672r", ID_AD5672R}, - {"ad5674r", ID_AD5674R}, - {"ad5676", ID_AD5676}, - {"ad5676r", ID_AD5676R}, - {"ad5679r", ID_AD5679R}, - {"ad5681r", ID_AD5681R}, - {"ad5682r", ID_AD5682R}, - {"ad5683", ID_AD5683}, - {"ad5683r", ID_AD5683R}, - {"ad5684", ID_AD5684}, - {"ad5684r", ID_AD5684R}, - {"ad5685", ID_AD5685R}, /* Does not exist */ - {"ad5685r", ID_AD5685R}, - {"ad5686", ID_AD5686}, - {"ad5686r", ID_AD5686R}, + { "ad5310r", (kernel_ulong_t)&ad5310r_chip_info }, + { "ad5672r", (kernel_ulong_t)&ad5672r_chip_info }, + { "ad5674r", (kernel_ulong_t)&ad5674r_chip_info }, + { "ad5676", (kernel_ulong_t)&ad5676_chip_info }, + { "ad5676r", (kernel_ulong_t)&ad5676r_chip_info }, + { "ad5679r", (kernel_ulong_t)&ad5679r_chip_info }, + { "ad5681r", (kernel_ulong_t)&ad5681r_chip_info }, + { "ad5682r", (kernel_ulong_t)&ad5682r_chip_info }, + { "ad5683", (kernel_ulong_t)&ad5683_chip_info }, + { "ad5683r", (kernel_ulong_t)&ad5683r_chip_info }, + { "ad5684", (kernel_ulong_t)&ad5684_chip_info }, + { "ad5684r", (kernel_ulong_t)&ad5684r_chip_info }, + { "ad5685", (kernel_ulong_t)&ad5685r_chip_info }, /* Does not exist */ + { "ad5685r", (kernel_ulong_t)&ad5685r_chip_info }, + { "ad5686", (kernel_ulong_t)&ad5686_chip_info }, + { "ad5686r", (kernel_ulong_t)&ad5686r_chip_info }, { } }; MODULE_DEVICE_TABLE(spi, ad5686_spi_id); diff --git a/drivers/iio/dac/ad5686.c b/drivers/iio/dac/ad5686.c index 0bc925bd827e..e67faef91164 100644 --- a/drivers/iio/dac/ad5686.c +++ b/drivers/iio/dac/ad5686.c @@ -196,7 +196,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), \ } @@ -247,205 +247,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) { @@ -465,8 +432,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 fe6482e84178..6e3552c92e4b 100644 --- a/drivers/iio/dac/ad5686.h +++ b/drivers/iio/dac/ad5686.h @@ -46,42 +46,6 @@ #define AD5310_REF_BIT_MSK BIT(8) #define AD5683_REF_BIT_MSK BIT(12) =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, @@ -111,6 +75,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 @@ -148,7 +140,7 @@ struct ad5686_state { =20 =20 int ad5686_probe(struct device *dev, - enum ad5686_supported_device_ids chip_type, + const struct ad5686_chip_info *chip_info, const char *name, ad5686_write_func write, ad5686_read_func read); =20 diff --git a/drivers/iio/dac/ad5696-i2c.c b/drivers/iio/dac/ad5696-i2c.c index e7e1b8a6fc71..fd047c01f8f6 100644 --- a/drivers/iio/dac/ad5696-i2c.c +++ b/drivers/iio/dac/ad5696-i2c.c @@ -64,47 +64,46 @@ static int ad5686_i2c_write(struct ad5686_state *st, =20 static int ad5686_i2c_probe(struct i2c_client *i2c) { - const struct i2c_device_id *id =3D i2c_client_get_device_id(i2c); - return ad5686_probe(&i2c->dev, id->driver_data, id->name, - ad5686_i2c_write, ad5686_i2c_read); + return ad5686_probe(&i2c->dev, i2c_get_match_data(i2c), + i2c->name, ad5686_i2c_write, ad5686_i2c_read); } =20 static const struct i2c_device_id ad5686_i2c_id[] =3D { - {"ad5311r", ID_AD5311R}, - {"ad5337r", ID_AD5337R}, - {"ad5338r", ID_AD5338R}, - {"ad5671r", ID_AD5671R}, - {"ad5673r", ID_AD5673R}, - {"ad5675r", ID_AD5675R}, - {"ad5677r", ID_AD5677R}, - {"ad5691r", ID_AD5691R}, - {"ad5692r", ID_AD5692R}, - {"ad5693", ID_AD5693}, - {"ad5693r", ID_AD5693R}, - {"ad5694", ID_AD5694}, - {"ad5694r", ID_AD5694R}, - {"ad5695r", ID_AD5695R}, - {"ad5696", ID_AD5696}, - {"ad5696r", ID_AD5696R}, + { "ad5311r", (kernel_ulong_t)&ad5311r_chip_info }, + { "ad5337r", (kernel_ulong_t)&ad5337r_chip_info }, + { "ad5338r", (kernel_ulong_t)&ad5338r_chip_info }, + { "ad5671r", (kernel_ulong_t)&ad5672r_chip_info }, + { "ad5673r", (kernel_ulong_t)&ad5674r_chip_info }, + { "ad5675r", (kernel_ulong_t)&ad5676r_chip_info }, + { "ad5677r", (kernel_ulong_t)&ad5679r_chip_info }, + { "ad5691r", (kernel_ulong_t)&ad5681r_chip_info }, + { "ad5692r", (kernel_ulong_t)&ad5682r_chip_info }, + { "ad5693", (kernel_ulong_t)&ad5683_chip_info }, + { "ad5693r", (kernel_ulong_t)&ad5683r_chip_info }, + { "ad5694", (kernel_ulong_t)&ad5684_chip_info }, + { "ad5694r", (kernel_ulong_t)&ad5684r_chip_info }, + { "ad5695r", (kernel_ulong_t)&ad5685r_chip_info }, + { "ad5696", (kernel_ulong_t)&ad5686_chip_info }, + { "ad5696r", (kernel_ulong_t)&ad5686r_chip_info }, { } }; MODULE_DEVICE_TABLE(i2c, ad5686_i2c_id); =20 static const struct of_device_id ad5686_of_match[] =3D { - { .compatible =3D "adi,ad5311r" }, - { .compatible =3D "adi,ad5337r" }, - { .compatible =3D "adi,ad5338r" }, - { .compatible =3D "adi,ad5671r" }, - { .compatible =3D "adi,ad5675r" }, - { .compatible =3D "adi,ad5691r" }, - { .compatible =3D "adi,ad5692r" }, - { .compatible =3D "adi,ad5693" }, - { .compatible =3D "adi,ad5693r" }, - { .compatible =3D "adi,ad5694" }, - { .compatible =3D "adi,ad5694r" }, - { .compatible =3D "adi,ad5695r" }, - { .compatible =3D "adi,ad5696" }, - { .compatible =3D "adi,ad5696r" }, + { .compatible =3D "adi,ad5311r", .data =3D &ad5311r_chip_info }, + { .compatible =3D "adi,ad5337r", .data =3D &ad5337r_chip_info }, + { .compatible =3D "adi,ad5338r", .data =3D &ad5338r_chip_info }, + { .compatible =3D "adi,ad5671r", .data =3D &ad5672r_chip_info }, + { .compatible =3D "adi,ad5675r", .data =3D &ad5676r_chip_info }, + { .compatible =3D "adi,ad5691r", .data =3D &ad5681r_chip_info }, + { .compatible =3D "adi,ad5692r", .data =3D &ad5682r_chip_info }, + { .compatible =3D "adi,ad5693", .data =3D &ad5683_chip_info }, + { .compatible =3D "adi,ad5693r", .data =3D &ad5683r_chip_info }, + { .compatible =3D "adi,ad5694", .data =3D &ad5684_chip_info }, + { .compatible =3D "adi,ad5694r", .data =3D &ad5684r_chip_info }, + { .compatible =3D "adi,ad5695r", .data =3D &ad5685r_chip_info }, + { .compatible =3D "adi,ad5696", .data =3D &ad5686_chip_info }, + { .compatible =3D "adi,ad5696r", .data =3D &ad5686r_chip_info }, { } }; MODULE_DEVICE_TABLE(of, ad5686_of_match); --=20 2.43.0 From nobody Fri Jun 19 07:51:08 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BFD71343D72; Sun, 26 Apr 2026 08:38:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777192699; cv=none; b=SmW/EIAU5ZhSTGUft0aGCAxPPleA0JPwpfknjimWkmkBun5RpU6a1G03XUc/getf2vcN9TalpoNt3gufRMqjQdGMHbQ8fdhRN/i/Zo5+RuaEIyGFDboYwGNrN6X3OrGbX25+niphMUSjif3c+f46yfcRvzoNxlsfVUY5+9ulefs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777192699; c=relaxed/simple; bh=zRqZGudlCy/r9rTbDAr1hiuQyH3vkLVcQSg7ikAa438=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=R+b4B9Z+z45QStmqWsqm9wUgDH6Itd5dN+CwCTjp3xkeulKccTLRU1154shJHj/nyS4cwtiQokC4a0jJhqGA+QBss01WEtniR/Xu38Y3LXrIFE1BVNuJxGGTE/hWUiZwGJU3PVoTDVvdI3vs0oq1niUeip2c6d5s0irJLG+6esY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=tsYIXxK0; 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="tsYIXxK0" Received: by smtp.kernel.org (Postfix) with ESMTPS id 980B0C2BCC9; Sun, 26 Apr 2026 08:38:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777192699; bh=zRqZGudlCy/r9rTbDAr1hiuQyH3vkLVcQSg7ikAa438=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=tsYIXxK0wBIyMz36Bi2r9q90gkqSM/bLD9pK7pED6hUF8oy1U721+cimffeY1wm+I W+rlPEMzMyg+GwxD7kSroMU5meXqOq1Qv99dj4+36QooItcnyqttetXFeyFXRuHRlr XZ3EEhyYzhNNvw0oUzkAJJCnLijEZ6echLCPFng+QRGoQHM5LwhD+Qzy+b2yp43lNn IAmSwzA7Xc0ikTAF9z3izy0e1iuvjnEZhhYXaGatM58bx2/6v1dXU8CGy6mJtPWabb gKz04MAH/Td09Vt8LN8Gqn/rFxYAMPBxvI/uBiTPpPRrKDd51KvIa1YaX8UP5afaBT m2kwpRXeU+big== 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 8DF72FF885D; Sun, 26 Apr 2026 08:38:19 +0000 (UTC) From: Rodrigo Alencar via B4 Relay Date: Sun, 26 Apr 2026 09:38:05 +0100 Subject: [PATCH 04/10] 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: <20260426-ad5686-fixes-v1-4-7c946a77794e@analog.com> References: <20260426-ad5686-fixes-v1-0-7c946a77794e@analog.com> In-Reply-To: <20260426-ad5686-fixes-v1-0-7c946a77794e@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=1777192698; l=1849; i=rodrigo.alencar@analog.com; s=default; h=from:subject:message-id; bh=LohyswX/WbRmKSz4Qx5zIV8Oktgz71bUWV/iKlpzTJk=; b=7HwBKUdGOdQdhtZQKTASaUcJpnz53KiHbPi2FvHiwwP2umeCEJVd9RA/Sn4AUIz5JnBA1lmFJ EXQXP46kYG5AhKxRp8dZeSXFAkmpX1CyuNXlbFhmeiOFjHvKc2OCk/6 X-Developer-Key: i=rodrigo.alencar@analog.com; a=ed25519; pk=ULeHbgU/OYh/PG/4anHDfLgldFItQHAhOktYRVLMFRo= X-Endpoint-Received: by B4 Relay for rodrigo.alencar@analog.com/default with auth_id=561 X-Original-From: Rodrigo Alencar Reply-To: rodrigo.alencar@analog.com From: Rodrigo Alencar Add of_match table for the SPI device variants to be consistent with the AD5696 I2C driver. Signed-off-by: Rodrigo Alencar --- drivers/iio/dac/ad5686-spi.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/drivers/iio/dac/ad5686-spi.c b/drivers/iio/dac/ad5686-spi.c index 73e6c998add0..8fef0e6d33ff 100644 --- a/drivers/iio/dac/ad5686-spi.c +++ b/drivers/iio/dac/ad5686-spi.c @@ -119,9 +119,30 @@ static const struct spi_device_id ad5686_spi_id[] =3D { }; MODULE_DEVICE_TABLE(spi, ad5686_spi_id); =20 +static const struct of_device_id ad5686_of_match[] =3D { + { .compatible =3D "adi,ad5310r", .data =3D &ad5310r_chip_info }, + { .compatible =3D "adi,ad5672r", .data =3D &ad5672r_chip_info }, + { .compatible =3D "adi,ad5674r", .data =3D &ad5674r_chip_info }, + { .compatible =3D "adi,ad5676", .data =3D &ad5676_chip_info }, + { .compatible =3D "adi,ad5676r", .data =3D &ad5676r_chip_info }, + { .compatible =3D "adi,ad5679r", .data =3D &ad5679r_chip_info }, + { .compatible =3D "adi,ad5681r", .data =3D &ad5681r_chip_info }, + { .compatible =3D "adi,ad5682r", .data =3D &ad5682r_chip_info }, + { .compatible =3D "adi,ad5683", .data =3D &ad5683_chip_info }, + { .compatible =3D "adi,ad5683r", .data =3D &ad5683r_chip_info }, + { .compatible =3D "adi,ad5684", .data =3D &ad5684_chip_info }, + { .compatible =3D "adi,ad5684r", .data =3D &ad5684r_chip_info }, + { .compatible =3D "adi,ad5685r", .data =3D &ad5685r_chip_info }, + { .compatible =3D "adi,ad5686", .data =3D &ad5686_chip_info }, + { .compatible =3D "adi,ad5686r", .data =3D &ad5686r_chip_info }, + { } +}; +MODULE_DEVICE_TABLE(of, ad5686_of_match); + static struct spi_driver ad5686_spi_driver =3D { .driver =3D { .name =3D "ad5686", + .of_match_table =3D ad5686_of_match, }, .probe =3D ad5686_spi_probe, .id_table =3D ad5686_spi_id, --=20 2.43.0 From nobody Fri Jun 19 07:51:08 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CA0CB3446CE; Sun, 26 Apr 2026 08:38:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777192699; cv=none; b=AqMng6LZv/wKFTkEVFOSoizQwLJ1w1YNuu2rye8EzRa7y/wc7MMH6fpTAQri5WtY9CW/cX4YF3ypIXGYHo64qX9hunDUqIWfmA9ZudLDkyqxCfpTquVQVrM5s0dohHgEbDMA/P/xSgCnL2PuYrAJ9C4YBJcmzK7Rxr9si5ce8Kc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777192699; c=relaxed/simple; bh=QGNNtbE9rzWeyjGHb0lguGX2RFlZafDnG+4RP3YBs+4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=tEYPnvq2/O/nT7zMDYFtR22HJT+l5tI5fLC9pr9qJkTyeX57LYcwhXw9AXWlz+dkcjb7OPxOkfOubDihvFHygXO884b8fbEo9hJBDL2RfKC5oNMhH0gNVFMevfQYHZvBDqUQwdj369gY2iibwmEnLEVyP/8lAnDmhAv+mqvvc/c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=PdyjatgZ; 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="PdyjatgZ" Received: by smtp.kernel.org (Postfix) with ESMTPS id A62B8C2BCC7; Sun, 26 Apr 2026 08:38:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777192699; bh=QGNNtbE9rzWeyjGHb0lguGX2RFlZafDnG+4RP3YBs+4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=PdyjatgZ3IodB5KfhB7VyDgSO9F+ooV2A5Ks2Cq0+RTKaQBGKmXkCt5k/BRmyAcDZ ZACAaV/KLV98K6DReNbxWMlHmlMGutuAEvF9LC3OS+WHRtFjN7TWoxZI2plfesl8II ZrTZk65abW8+qni0MOeZ2TcohJzk5t7nrQNQklJsPX8EWSh6rDpXvjfpntbZ6ye/f0 inctX2Blsz8jpx3QQ61KvE2QxyXrEsCWhpw2DmNxDxY9QfKf8KMya1UOQSOZTT1Aba LArxmCVpOv8MNUzbgoOyvKVl8hmrPGzPAin24MTifQd/48BO7F2C5LeM084VRHaZca qNuZ26dzXOwpw== 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 9EE56FF8864; Sun, 26 Apr 2026 08:38:19 +0000 (UTC) From: Rodrigo Alencar via B4 Relay Date: Sun, 26 Apr 2026 09:38:06 +0100 Subject: [PATCH 05/10] 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: <20260426-ad5686-fixes-v1-5-7c946a77794e@analog.com> References: <20260426-ad5686-fixes-v1-0-7c946a77794e@analog.com> In-Reply-To: <20260426-ad5686-fixes-v1-0-7c946a77794e@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=1777192698; l=6149; i=rodrigo.alencar@analog.com; s=default; h=from:subject:message-id; bh=Fe+7DBfbc1bOX4qMy68JsRmkBHqJ6mp1cO2Eqei1XHc=; b=YKgGCL8qNTRYxCPahU84dgzrya0V2VS6zttmce+j85KanIQCPFngA6HD6Y5eE+dKEEB05x9wF Or4p2xif5MYALtguMYWGtECksGU60GaOhwDA7eTZAeexsHbdYXkNwUV 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 For single-channel parts the control register is used to enable the internal voltage reference and perform powerdown control. The reference enable bit position was ignored when writing the register at the probe function (!!val was used). This patch adds a control_sync() function that properly consumes the mask definitions with FIELD_PREP(). As further cleanup, the created functions and definitions are also used in ad5686_write_dac_powerdown(). Some local variables ended up being unused (so removed) and st->use_internal_vref is initialized earlier in probe, because it is also applicable to the AD5686_REGMAP case. Fixes: be1b24d24541 ("iio:dac:ad5686: Add AD5691R/AD5692R/AD5693/AD5693R su= pport") Signed-off-by: Rodrigo Alencar --- drivers/iio/dac/ad5686.c | 89 ++++++++++++++++++++++++++++----------------= ---- drivers/iio/dac/ad5686.h | 3 +- 2 files changed, 54 insertions(+), 38 deletions(-) diff --git a/drivers/iio/dac/ad5686.c b/drivers/iio/dac/ad5686.c index e67faef91164..843e425f656f 100644 --- a/drivers/iio/dac/ad5686.c +++ b/drivers/iio/dac/ad5686.c @@ -6,11 +6,13 @@ */ =20 #include +#include #include #include #include #include #include +#include =20 #include "ad5686.h" =20 @@ -20,6 +22,24 @@ static const char * const ad5686_powerdown_modes[] =3D { "three_state" }; =20 +static int ad5310_control_sync(struct ad5686_state *st) +{ + unsigned int pd_val =3D st->pwr_down_mask & st->pwr_down_mode; + + return st->write(st, AD5686_CMD_CONTROL_REG, 0, + FIELD_PREP(AD5310_PD_MSK, pd_val) | + FIELD_PREP(AD5310_REF_BIT_MSK, st->use_internal_vref ? 0 : 1)); +} + +static int ad5683_control_sync(struct ad5686_state *st) +{ + unsigned int pd_val =3D st->pwr_down_mask & st->pwr_down_mode; + + return st->write(st, AD5686_CMD_CONTROL_REG, 0, + FIELD_PREP(AD5683_PD_MSK, pd_val) | + FIELD_PREP(AD5683_REF_BIT_MSK, st->use_internal_vref ? 0 : 1)); +} + static int ad5686_get_powerdown_mode(struct iio_dev *indio_dev, const struct iio_chan_spec *chan) { @@ -65,8 +85,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) @@ -79,32 +99,34 @@ static ssize_t ad5686_write_dac_powerdown(struct iio_de= v *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, @@ -416,11 +438,8 @@ int ad5686_probe(struct device *dev, const char *name, ad5686_write_func write, ad5686_read_func read) { - struct ad5686_state *st; struct iio_dev *indio_dev; - unsigned int val, ref_bit_msk; - bool has_external_vref; - u8 cmd; + struct ad5686_state *st; int ret, i; =20 indio_dev =3D devm_iio_device_alloc(dev, sizeof(*st)); @@ -438,8 +457,8 @@ int ad5686_probe(struct device *dev, if (ret < 0 && ret !=3D -ENODEV) return ret; =20 - has_external_vref =3D ret !=3D -ENODEV; - st->vref_mv =3D has_external_vref ? ret / 1000 : st->chip_info->int_vref_= mv; + st->use_internal_vref =3D ret =3D=3D -ENODEV; + st->vref_mv =3D st->use_internal_vref ? st->chip_info->int_vref_mv : ret = / 1000; =20 /* Set all the power down mode for all channels to 1K pulldown */ for (i =3D 0; i < st->chip_info->num_channels; i++) @@ -457,29 +476,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 0; + ret =3D st->write(st, AD5686_CMD_INTERNAL_REFER_SETUP, 0, + st->use_internal_vref ? 0 : 1); + if (ret) + return ret; break; default: return -EINVAL; } =20 - val =3D (has_external_vref | ref_bit_msk); - - 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 6e3552c92e4b..7004d0d1d97a 100644 --- a/drivers/iio/dac/ad5686.h +++ b/drivers/iio/dac/ad5686.h @@ -44,8 +44,9 @@ #define AD5686_CMD_READBACK_ENABLE_V2 0x5 =20 #define AD5310_REF_BIT_MSK BIT(8) +#define AD5310_PD_MSK GENMASK(10, 9) #define AD5683_REF_BIT_MSK BIT(12) - +#define AD5683_PD_MSK GENMASK(14, 13) =20 enum ad5686_regmap_type { AD5310_REGMAP, --=20 2.43.0 From nobody Fri Jun 19 07:51:08 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D7824344DAA; Sun, 26 Apr 2026 08:38:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777192699; cv=none; b=JXPCer5VliElPsXUkJoKHY+suORB4xAQwDMY18pUaCDDGVu0PmjUg/E+6r2ecHBOAi8AQoyXeiRvU3aUA8qwNuh7gQ15F+eRQsyxQ1bwY+pptpopNOiy92+d7CDkWw0z6ROOL81+pTdnaM8yiT/YzkPQWNe+lJCloS7oI9hjqE0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777192699; c=relaxed/simple; bh=I2c3TyrIl5LtLuANO5k33UekJxZJPWps6rrDC331JCs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ru5XLu+hK0ELOOkEo/frdOGkSe9K5i02Q2nTVzKo1A3ePHncypMxrZAmtGvfd6jTTA/CzfhpYssrishmkc7QMf1v8UGxYG88nZHbGmCC96Jk8RVX/SZJYOPlf4Q3fYPyi2oE0vjxO/+yK+S9BGp1HGh8BbJ9NB2XwD3NcCcOFsk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=mIz8sxgv; 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="mIz8sxgv" Received: by smtp.kernel.org (Postfix) with ESMTPS id BADAFC2BCF6; Sun, 26 Apr 2026 08:38:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777192699; bh=I2c3TyrIl5LtLuANO5k33UekJxZJPWps6rrDC331JCs=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=mIz8sxgvFdsD5omZi73FcOuGpy4C8/+3E49p4bpDJVT/OlizW7fPLT3JuS2bht/CR YUpPIPak+bB1lJpme+drK5BepfkXGjSH9uZlw34E1km1lq0nh4KDKuiipn79Lt8eF2 A32HeAba/FfL4hv/jSXLbS6IQNJbJU4Tuu5K0VHoKZo4ITKZsc2TCDNZKhOuRnWl6t H30OixUabp1068YBNFLg1fbt6Lf31xIdj+fZWIUurwJnGMEUjpW/b9dAZ8Rnm+r2MU K2bJAryFDQZWj8wF62e03k6st+EFvf9eBpmkkysHI3aVCsSjpZ6+qC74ZVIPyyCCIr PLLGXqXSsmHng== 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 B0FC3FF885D; Sun, 26 Apr 2026 08:38:19 +0000 (UTC) From: Rodrigo Alencar via B4 Relay Date: Sun, 26 Apr 2026 09:38:07 +0100 Subject: [PATCH 06/10] 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: <20260426-ad5686-fixes-v1-6-7c946a77794e@analog.com> References: <20260426-ad5686-fixes-v1-0-7c946a77794e@analog.com> In-Reply-To: <20260426-ad5686-fixes-v1-0-7c946a77794e@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=1777192698; l=2949; i=rodrigo.alencar@analog.com; s=default; h=from:subject:message-id; bh=zkyMJeMfxk74OfFs+GS146KNXFlUAIQgn0Fr+aKUZsY=; b=8WchA4kzK/7Jq3ZSKrqZTJ7mS6QkRD38FBenREA9Pn86YGL4ePKkg8gvErmEo+/UJs7oWeo9/ ibQDk3mDDA0BcqJDLHR7wjA+XLKHPxR9phTjPsqm6bB7h2G8dwgvPya 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 access of pwr_down_mode and pwr_down_mask fields with existing mutex lock. This issue exists since the ad5686 driver was first introduced. Acquire mutex with guard(mutex)() throughout for consistency, which allows for early returns, facilitating the review of further changes. Fixes: c2f37c8dcadc ("iio: dac: New driver for AD5686R, AD5685R, AD5684R Di= gital to analog converters") Signed-off-by: Rodrigo Alencar --- drivers/iio/dac/ad5686.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/drivers/iio/dac/ad5686.c b/drivers/iio/dac/ad5686.c index 843e425f656f..c7d5ee344a6f 100644 --- a/drivers/iio/dac/ad5686.c +++ b/drivers/iio/dac/ad5686.c @@ -45,6 +45,8 @@ static int ad5686_get_powerdown_mode(struct iio_dev *indi= o_dev, { struct ad5686_state *st =3D iio_priv(indio_dev); =20 + guard(mutex)(&st->lock); + return ((st->pwr_down_mode >> (chan->channel * 2)) & 0x3) - 1; } =20 @@ -54,6 +56,7 @@ 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 @@ -72,6 +75,8 @@ static ssize_t ad5686_read_dac_powerdown(struct iio_dev *= indio_dev, { struct ad5686_state *st =3D iio_priv(indio_dev); =20 + guard(mutex)(&st->lock); + return sysfs_emit(buf, "%d\n", !!(st->pwr_down_mask & (0x3 << (chan->channel * 2)))); } @@ -92,6 +97,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 @@ -138,11 +145,11 @@ static int ad5686_read_raw(struct iio_dev *indio_dev, struct ad5686_state *st =3D iio_priv(indio_dev); int ret; =20 + guard(mutex)(&st->lock); + switch (m) { case IIO_CHAN_INFO_RAW: - mutex_lock(&st->lock); ret =3D st->read(st, chan->address); - mutex_unlock(&st->lock); if (ret < 0) return ret; *val =3D (ret >> chan->scan_type.shift) & @@ -163,25 +170,19 @@ static int ad5686_write_raw(struct iio_dev *indio_dev, long mask) { struct ad5686_state *st =3D iio_priv(indio_dev); - int ret; + + guard(mutex)(&st->lock); =20 switch (mask) { case IIO_CHAN_INFO_RAW: if (val > (1 << chan->scan_type.realbits) || val < 0) 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); - mutex_unlock(&st->lock); - break; + return st->write(st, AD5686_CMD_WRITE_INPUT_N_UPDATE_N, + chan->address, val << chan->scan_type.shift); default: - ret =3D -EINVAL; + return -EINVAL; } - - return ret; } =20 static const struct iio_info ad5686_info =3D { --=20 2.43.0 From nobody Fri Jun 19 07:51:08 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E60A634575A; Sun, 26 Apr 2026 08:38:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777192700; cv=none; b=IpXBsh/UeRzm3pTmbzUw2MgpVvhVTdVKGA6yUbd3+Hmknwxm89HhMUsITk/JLDhV/1fqxTx0ASM8gkO2z8lTVWKFO70qk+sZ00JnQFdFa4Q875lMp5ALZvYqyosarqyj1HQadhZ4529BRL1H/XlQ/TbBNRNO+ED5IM7C9YE88Ho= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777192700; c=relaxed/simple; bh=Jut4q3rZbXMuUUVZSOZS22edwkDgNuXE/S+1GijfoNY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=fY6M9EX26VyBezyOEZ2AP1OywF35Vj0BInEOSOy2Un9I+uYIlZwYLxDGIlviWKfy4aAEcBHsO5RB2gnvlL8/0kcgipNyI277FXXRFccCgVvQ48V1ddFzGYp/HsRkX4ThPGkreBnamAZZRVZo4KteWkh7qdFO6rCjbb7/mu+ojzQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Fm17ppf3; 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="Fm17ppf3" Received: by smtp.kernel.org (Postfix) with ESMTPS id C8437C2BCAF; Sun, 26 Apr 2026 08:38:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777192699; bh=Jut4q3rZbXMuUUVZSOZS22edwkDgNuXE/S+1GijfoNY=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=Fm17ppf3nPemaJ+1nOBYmdhPnDpyCYta0kyBDKq9lJuZdNyANrAL58TVFjBQQClcM DUTF3VsYvegbHyEmtVm1H4LKfK9uCYDRsgspKmsyANOr3BPvFaR0iguP/TxIofM3hc i4rwsY62MAOgcxDzUzPPlkp4m9BX1Rod3zgh1Umiihi1IaZfcm+M8eAfbxo0ZefZve qovn/83O57pyLfstAZ5NyOjGYDWXaOhDevVOhH+pN+eCUNx1DgI41sZ/dGOi/+nMjE LOaWCjpPBjL0am/GHs/aDJWKl8/sQE1b1xjhdfzsIsqecPXRteoRy36xoy6u6AePmC gvUIktAo1Ji7g== 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 C0EC9FF885E; Sun, 26 Apr 2026 08:38:19 +0000 (UTC) From: Rodrigo Alencar via B4 Relay Date: Sun, 26 Apr 2026 09:38:08 +0100 Subject: [PATCH 07/10] 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: <20260426-ad5686-fixes-v1-7-7c946a77794e@analog.com> References: <20260426-ad5686-fixes-v1-0-7c946a77794e@analog.com> In-Reply-To: <20260426-ad5686-fixes-v1-0-7c946a77794e@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=1777192698; l=4409; i=rodrigo.alencar@analog.com; s=default; h=from:subject:message-id; bh=MWg9tSw53gQgdeZxF8M2GSlQfNQfJl0ORghHPgSvvWw=; b=SgsvL/F+6oFskjs/1WBg1nVGhxlBfv5s6cEyZqTd6vE4MsWMiPYdGv2deM/RwK4Yxu+bqm5Am 4hsFaKjfeZLCgKWyMAZmo9blVk3VJfYyyfIVzsvxV/LJxCP6Gn/38Y8 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 | 38 ++++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/drivers/iio/dac/ad5686.c b/drivers/iio/dac/ad5686.c index c7d5ee344a6f..040a24c62c9a 100644 --- a/drivers/iio/dac/ad5686.c +++ b/drivers/iio/dac/ad5686.c @@ -40,25 +40,36 @@ static int ad5683_control_sync(struct ad5686_state *st) 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) +{ + 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 guard(mutex)(&st->lock); =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); - 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; } @@ -73,12 +84,12 @@ 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 guard(mutex)(&st->lock); =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, @@ -100,9 +111,9 @@ static ssize_t ad5686_write_dac_powerdown(struct iio_de= v *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: @@ -441,7 +452,8 @@ int ad5686_probe(struct device *dev, { struct iio_dev *indio_dev; struct ad5686_state *st; - int ret, i; + unsigned int i, shift; + int ret; =20 indio_dev =3D devm_iio_device_alloc(dev, sizeof(*st)); if (indio_dev =3D=3D NULL) @@ -462,8 +474,14 @@ int ad5686_probe(struct device *dev, st->vref_mv =3D st->use_internal_vref ? st->chip_info->int_vref_mv : ret = / 1000; =20 /* Set all the power down mode for all channels to 1K pulldown */ - for (i =3D 0; i < st->chip_info->num_channels; i++) - st->pwr_down_mode |=3D (0x01 << (i * 2)); + st->pwr_down_mode =3D ~0U; + st->pwr_down_mask =3D ~0U; + for (i =3D 0; i < st->chip_info->num_channels; i++) { + shift =3D ad5686_pd_mask_shift(&st->chip_info->channels[i]); + st->pwr_down_mask &=3D ~(0x3 << shift); /* powered up state */ + st->pwr_down_mode &=3D ~(0x3 << shift); + st->pwr_down_mode |=3D (0x01 << shift); + } =20 indio_dev->name =3D name; indio_dev->info =3D &ad5686_info; --=20 2.43.0 From nobody Fri Jun 19 07:51:08 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F3453345CC0; Sun, 26 Apr 2026 08:38:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777192700; cv=none; b=CBcHYL+03VN5BJmiUEkgOnHfIRoshz7zlXDkj/LZPqnImzpADBdoLDGCsCE4NQaP+yyYvqC0pAMoTKJHvmvQC+/2vLO3zjBFmFwD0tvZ+io+jwoEPMhPcbs4le0yxmHSX44IFWYAXLFSYIBlDWut7YlK/45BWH9XZe5XJvZfL0o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777192700; c=relaxed/simple; bh=n1am3Rm9SzJWF+Azvyj1tHTTsTsQ3pwzcWn8m+vf0Z4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=LUFXSck7GmkdRtqPgSC7kb6a5lEJRTGYBcYoKktooXD2ATXASptaQWe3w/mX+T9JbFKsJvJwx8A9rAeQbRYgaUseu5JnKwXg5wnABzO3+gHopHnNrnzif6q9LTyCpzCZ4Em1U07lkLlzoeWjuRck1t9t+o67+OhaXdVybscYQzI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=jqoVZo3R; 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="jqoVZo3R" Received: by smtp.kernel.org (Postfix) with ESMTPS id D8684C2BCB6; Sun, 26 Apr 2026 08:38:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777192699; bh=n1am3Rm9SzJWF+Azvyj1tHTTsTsQ3pwzcWn8m+vf0Z4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=jqoVZo3R/pSqIW1VmuJPjy4zAKsDNpHsG1tg/JfYi0bUu3cPmgICfcbRxsGMPKsn/ 8SSmwII6gqtre9+H14bJYi/qyejmh++GKK5mzUL68hFlWDcxZMrBGj+owjaIs/6Xoy eRSdq06GjSv8QmVn3+nOT+HOroIaqVojHSIxbpm/yPA1/JvV8DN7mF4KNB6BjBYUct pU8/lSfVaNDqnEl8D7VkkcqlcFREOtCixLy8E9Jugb5EzEWgKU7d1BcLvvXHLR6cSi RKOh+z50S0lNBZWSklhuwkIfLgtf7f8jeqdrWNC/tTAwAGMtG3GQp9/Eq+PWbXi9hl O8mIq8SAUOkeg== 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 D12CBFF885D; Sun, 26 Apr 2026 08:38:19 +0000 (UTC) From: Rodrigo Alencar via B4 Relay Date: Sun, 26 Apr 2026 09:38:09 +0100 Subject: [PATCH 08/10] 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: <20260426-ad5686-fixes-v1-8-7c946a77794e@analog.com> References: <20260426-ad5686-fixes-v1-0-7c946a77794e@analog.com> In-Reply-To: <20260426-ad5686-fixes-v1-0-7c946a77794e@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=1777192698; l=1053; i=rodrigo.alencar@analog.com; s=default; h=from:subject:message-id; bh=Jyqj3+FFKyypdm39jK5VmyJy5lEuvWoM3X8faV9LnaQ=; b=J5VdC3SHKabbzhvICo8tYevq7BRLLWVqWZ3f9aqHns8S2D7KAC0WikGTH7VKArqdonMt1rbpW gyG88+gu0leD+oMUTrOAa0WpB1KnHzVdHwNbmrQFfxSnBjEogV60WvB 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 Use in_range() to fix range check for input raw value, which is off by one, i.e., for a 10-bit DAC the max valid value is 1023, but 1 << 10 equals 1024, which passes the previous check, allowing an out-of-range write. The issue exists since the ad5686 driver was first introduced. Fixes: c2f37c8dcadc ("iio: dac: New driver for AD5686R, AD5685R, AD5684R Di= gital to analog converters") Signed-off-by: Rodrigo Alencar --- drivers/iio/dac/ad5686.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/iio/dac/ad5686.c b/drivers/iio/dac/ad5686.c index 040a24c62c9a..ab498ec2ed5c 100644 --- a/drivers/iio/dac/ad5686.c +++ b/drivers/iio/dac/ad5686.c @@ -186,7 +186,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 (!in_range(val, 0, 1 << chan->scan_type.realbits)) return -EINVAL; =20 return st->write(st, AD5686_CMD_WRITE_INPUT_N_UPDATE_N, --=20 2.43.0 From nobody Fri Jun 19 07:51:08 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0EEFF345CCD; Sun, 26 Apr 2026 08:38:20 +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=1777192700; cv=none; b=iHoGqApH5SPczqslSEAUJWiPkvt0IWKfOx0I8aVlZSqxWvLHZYDsWxE4C6NiTWNsY0ExvUNNgqE1Oum68cCu4mmL9gZuQjObECPrIJXJ0FVAtIWTrRA0cUhZrzsov/s4jzEYRjLCduSTWEooaVfFVjr96a2avOAqR0HZNzw5NcQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777192700; c=relaxed/simple; bh=Cbm0UPTOuxFCb3mealagbDc9JbENivgWyAX23J8Thuc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=PCH8YZp2TlSJumK/dcDSapNRsxj22Zsx5hYYlxhNlBf9r+xcvXCY5/C7EogmCE0iME3qaGpBEKgXv2IgrVrMQ270l/dQXK/22se3jV96Q1S3WhP733QNtXvE2Rdl0hdVl1IQ2aVYJZ5wJ3hy7EqVlUaovdI/BhFl4GQzMGrQxC4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=qXzvuXaQ; 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="qXzvuXaQ" Received: by smtp.kernel.org (Postfix) with ESMTPS id E8AA0C2BCC4; Sun, 26 Apr 2026 08:38:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777192699; bh=Cbm0UPTOuxFCb3mealagbDc9JbENivgWyAX23J8Thuc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=qXzvuXaQJMUJ7aHAuomYxtm06Zx1ceVVxyrOTVwdbeeOYFc/LlyAnrXHgM+mD6yR4 cNlT+Se8Y2BhJVoqC2IKqz440HG6pxPJjWdkryP0+9mabNOGJ+Nk04+5V4qKE55xGH enjusVzvol5u9oI02QmZ1HLTkMh8l/un4zfkhi1Yl/Tw/vMLHgdBnv+pWc6U0u89+3 puejRhLDTmJLOOOOOXNYLJg4CxbBSqAcbxxlC9OUYUck6KMMI5ogp8RXFLkaeRyL/T CuOGk8f4CbaeduWESfer25U0Qhqwr78QYvr+rX6P2taK1NNVDeBJ0xLMAhjavCUjWC tKPdg6u6Gg9bQ== 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 E10F3FF8860; Sun, 26 Apr 2026 08:38:19 +0000 (UTC) From: Rodrigo Alencar via B4 Relay Date: Sun, 26 Apr 2026 09:38:10 +0100 Subject: [PATCH 09/10] 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: <20260426-ad5686-fixes-v1-9-7c946a77794e@analog.com> References: <20260426-ad5686-fixes-v1-0-7c946a77794e@analog.com> In-Reply-To: <20260426-ad5686-fixes-v1-0-7c946a77794e@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=1777192698; l=1834; i=rodrigo.alencar@analog.com; s=default; h=from:subject:message-id; bh=c0BEZ1A0gywVZfdklIC/KEzn/5Gdqo24dUnmHYw5Cxg=; b=NF9zuAarSReVuhrh5bh3ca6e5Kf+m8duh0w3KuYSZyn/jvnDWaMEqhP1BdtVQT4xph/Y5+mx5 hrp3V7hSCSSDLoB6UxhlfCP+FjfexNL2+3MwpCPqHn9J9xUHyVyHN47 X-Developer-Key: i=rodrigo.alencar@analog.com; a=ed25519; pk=ULeHbgU/OYh/PG/4anHDfLgldFItQHAhOktYRVLMFRo= X-Endpoint-Received: by B4 Relay for rodrigo.alencar@analog.com/default with auth_id=561 X-Original-From: Rodrigo Alencar Reply-To: rodrigo.alencar@analog.com From: Rodrigo Alencar Review documentation comment header for ad5686_chip_info and ad5686_state. Update variable names and description and remove unnecessary blank line between comment and struct declaration. Signed-off-by: Rodrigo Alencar --- drivers/iio/dac/ad5686.h | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/drivers/iio/dac/ad5686.h b/drivers/iio/dac/ad5686.h index 7004d0d1d97a..8043cb4ab3cf 100644 --- a/drivers/iio/dac/ad5686.h +++ b/drivers/iio/dac/ad5686.h @@ -63,12 +63,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; @@ -106,16 +105,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 Fri Jun 19 07:51:08 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1F690346AFD; Sun, 26 Apr 2026 08:38:20 +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=1777192700; cv=none; b=dlefY5qlZz0WOsk9chpLTdt4M3LggJfsYO2piqKu2M9z9U9zDV/KKTCreqTppfAxoYd4nnZiZP+M9CdB4tmKpvPv23uJRmbDIjEJB67LF4cRcIHu07FoE+WriVfQnQmz+kzcoVQTy83o0G8zVHRkfq6LTIGknG20bIEtkRpIW5s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777192700; c=relaxed/simple; bh=z66o5gdYmR1MofyPIGVtT4R/6Zfmb/l909tCLhQH504=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=TETswkr9wXN4T2x5FYqhstkUV443i8pQ5nfXqa1xYUFoccgCL6WQCYipZAs8Z0WwT4LpC+voAHFC8AUfLMj/3taOBAwVgNrG4Ngm+VD1Hp82lP+OJpgsbP3SJT0GByrenYynTUMEd+U7Vs3UKIWe1aVINwoCTuGwhziN8MLs1zc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=uDdaq1KP; 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="uDdaq1KP" Received: by smtp.kernel.org (Postfix) with ESMTPS id 04F13C2BCB9; Sun, 26 Apr 2026 08:38:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777192700; bh=z66o5gdYmR1MofyPIGVtT4R/6Zfmb/l909tCLhQH504=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=uDdaq1KP4YIAMPc1ec0U/ZjduyUTk08oYoJAEZgaRpE0p9TePoCLiWv8Q5oiHbVb0 P6iCO8Hrahg8wmUr2hyM9nrKhpbDsj8gKzd6sGWgEmUBwYT9nx4tBDOfeXaEuoNk/F ACgLFldARX7KOaMO+sudgT3k1nImrdFqoXTH4XtqFZRrQjc4kPpZbvU8NHDmYztZ4T LtLTlkuyHrB93muUIQN7t22LV82mEOAc+s8Dr+I0Apc6CTJGF6ixgL/RIszXlWs68y hjCQs+42GHA83GJaRGMpH3dqI8Kw885mfT4SQ2QTiN9OfBUQPsiippx286M948IkXA Ti7pemYi6JF6w== 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 F0946FF885D; Sun, 26 Apr 2026 08:38:19 +0000 (UTC) From: Rodrigo Alencar via B4 Relay Date: Sun, 26 Apr 2026 09:38:11 +0100 Subject: [PATCH 10/10] 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: <20260426-ad5686-fixes-v1-10-7c946a77794e@analog.com> References: <20260426-ad5686-fixes-v1-0-7c946a77794e@analog.com> In-Reply-To: <20260426-ad5686-fixes-v1-0-7c946a77794e@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=1777192698; l=7468; i=rodrigo.alencar@analog.com; s=default; h=from:subject:message-id; bh=bK22PGl2VrIUK5DK/y4pieYUa43QpgH09CHKivfjINY=; b=fVu1ipzQHekJ35CkveskcP//upkXsT8pz8qUtzglNFfXSoUGVqH6vUCAXfCi91JDzJGPdeBsg ORarXJIj8WPCcvtkyQoemDxaMxS88IVGFe5I9Se3EUyLV/EPULnlQbi X-Developer-Key: i=rodrigo.alencar@analog.com; a=ed25519; pk=ULeHbgU/OYh/PG/4anHDfLgldFItQHAhOktYRVLMFRo= X-Endpoint-Received: by B4 Relay for rodrigo.alencar@analog.com/default with auth_id=561 X-Original-From: Rodrigo Alencar Reply-To: rodrigo.alencar@analog.com From: Rodrigo Alencar Create struct with bus operations, which will be used to extend bus implementation features. Auxiliary functions ad5686_write() and ad5686_read() are created and ad5686_probe() now receives an ops struct pointer rather than individual read and write functions. Signed-off-by: Rodrigo Alencar --- drivers/iio/dac/ad5686-spi.c | 7 ++++++- drivers/iio/dac/ad5686.c | 30 ++++++++++++++---------------- drivers/iio/dac/ad5686.h | 29 +++++++++++++++++++++-------- drivers/iio/dac/ad5696-i2c.c | 7 ++++++- 4 files changed, 47 insertions(+), 26 deletions(-) diff --git a/drivers/iio/dac/ad5686-spi.c b/drivers/iio/dac/ad5686-spi.c index 8fef0e6d33ff..857b9e4f54ab 100644 --- a/drivers/iio/dac/ad5686-spi.c +++ b/drivers/iio/dac/ad5686-spi.c @@ -92,10 +92,15 @@ static int ad5686_spi_read(struct ad5686_state *st, u8 = addr) return be32_to_cpu(st->data[2].d32); } =20 +static const struct ad5686_bus_ops ad5686_spi_ops =3D { + .write =3D ad5686_spi_write, + .read =3D ad5686_spi_read, +}; + static int ad5686_spi_probe(struct spi_device *spi) { return ad5686_probe(&spi->dev, spi_get_device_match_data(spi), - spi->modalias, ad5686_spi_write, ad5686_spi_read); + spi->modalias, &ad5686_spi_ops); } =20 static const struct spi_device_id ad5686_spi_id[] =3D { diff --git a/drivers/iio/dac/ad5686.c b/drivers/iio/dac/ad5686.c index ab498ec2ed5c..490faed85976 100644 --- a/drivers/iio/dac/ad5686.c +++ b/drivers/iio/dac/ad5686.c @@ -26,18 +26,18 @@ static int ad5310_control_sync(struct ad5686_state *st) { unsigned int pd_val =3D st->pwr_down_mask & st->pwr_down_mode; =20 - return st->write(st, AD5686_CMD_CONTROL_REG, 0, - FIELD_PREP(AD5310_PD_MSK, pd_val) | - FIELD_PREP(AD5310_REF_BIT_MSK, st->use_internal_vref ? 0 : 1)); + return ad5686_write(st, AD5686_CMD_CONTROL_REG, 0, + FIELD_PREP(AD5310_PD_MSK, pd_val) | + FIELD_PREP(AD5310_REF_BIT_MSK, st->use_internal_vref ? 0 : 1)); } =20 static int ad5683_control_sync(struct ad5686_state *st) { unsigned int pd_val =3D st->pwr_down_mask & st->pwr_down_mode; =20 - return st->write(st, AD5686_CMD_CONTROL_REG, 0, - FIELD_PREP(AD5683_PD_MSK, pd_val) | - FIELD_PREP(AD5683_REF_BIT_MSK, st->use_internal_vref ? 0 : 1)); + return ad5686_write(st, AD5686_CMD_CONTROL_REG, 0, + FIELD_PREP(AD5683_PD_MSK, pd_val) | + FIELD_PREP(AD5683_REF_BIT_MSK, st->use_internal_vref ? 0 : 1)); } =20 static inline unsigned int ad5686_pd_mask_shift(const struct iio_chan_spec= *chan) @@ -136,7 +136,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; @@ -160,7 +160,7 @@ static int ad5686_read_raw(struct iio_dev *indio_dev, =20 switch (m) { case IIO_CHAN_INFO_RAW: - ret =3D st->read(st, chan->address); + ret =3D ad5686_read(st, chan->address); if (ret < 0) return ret; *val =3D (ret >> chan->scan_type.shift) & @@ -189,8 +189,8 @@ static int ad5686_write_raw(struct iio_dev *indio_dev, if (!in_range(val, 0, 1 << chan->scan_type.realbits)) return -EINVAL; =20 - return st->write(st, AD5686_CMD_WRITE_INPUT_N_UPDATE_N, - chan->address, val << chan->scan_type.shift); + return ad5686_write(st, AD5686_CMD_WRITE_INPUT_N_UPDATE_N, + chan->address, val << chan->scan_type.shift); default: return -EINVAL; } @@ -447,8 +447,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 iio_dev *indio_dev; struct ad5686_state *st; @@ -462,8 +461,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"); @@ -505,8 +503,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 : 1); + ret =3D ad5686_write(st, AD5686_CMD_INTERNAL_REFER_SETUP, 0, + st->use_internal_vref ? 0 : 1); if (ret) return ret; break; diff --git a/drivers/iio/dac/ad5686.h b/drivers/iio/dac/ad5686.h index 8043cb4ab3cf..679831881ae2 100644 --- a/drivers/iio/dac/ad5686.h +++ b/drivers/iio/dac/ad5686.h @@ -56,10 +56,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 @@ -107,6 +112,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 @@ -118,11 +124,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 @@ -141,8 +146,16 @@ struct ad5686_state { =20 int ad5686_probe(struct device *dev, const struct ad5686_chip_info *chip_info, - const char *name, ad5686_write_func write, - ad5686_read_func read); + const char *name, const struct ad5686_bus_ops *ops); =20 +static inline int ad5686_write(struct ad5686_state *st, u8 cmd, u8 addr, u= 16 val) +{ + return st->ops->write(st, cmd, addr, val); +} + +static inline int ad5686_read(struct ad5686_state *st, u8 addr) +{ + return st->ops->read(st, addr); +} =20 #endif /* __DRIVERS_IIO_DAC_AD5686_H__ */ diff --git a/drivers/iio/dac/ad5696-i2c.c b/drivers/iio/dac/ad5696-i2c.c index fd047c01f8f6..30c48d937a38 100644 --- a/drivers/iio/dac/ad5696-i2c.c +++ b/drivers/iio/dac/ad5696-i2c.c @@ -62,10 +62,15 @@ static int ad5686_i2c_write(struct ad5686_state *st, return (ret !=3D 3) ? -EIO : 0; } =20 +static const struct ad5686_bus_ops ad5686_i2c_ops =3D { + .write =3D ad5686_i2c_write, + .read =3D ad5686_i2c_read, +}; + static int ad5686_i2c_probe(struct i2c_client *i2c) { return ad5686_probe(&i2c->dev, i2c_get_match_data(i2c), - i2c->name, ad5686_i2c_write, ad5686_i2c_read); + i2c->name, &ad5686_i2c_ops); } =20 static const struct i2c_device_id ad5686_i2c_id[] =3D { --=20 2.43.0