From nobody Mon Feb 9 03:47:23 2026 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (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 4D8532DE6F1 for ; Wed, 28 Jan 2026 15:38:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769614715; cv=none; b=MY1cUys5kMS7YcYFpcPQezFByvQ8HdU6IpVMf+orzOXaKed8WHJwvNg7HcBa/NHDhhL6LE8ShuoUomXfb107gbW+tf4gF4WXhe1jMlGB99mMUJV7GZbkQJD8Jvbw4t3nf1kHCYj/N1gsxXUnPfXylDCqQeRdp/WcElwCFwCRQLk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769614715; c=relaxed/simple; bh=RHOU9dUVe54OGDF08RNJXpmM7veA3wiGV0eWtzH1qJ0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rYRCSclPgFF/XdnJMQ6kSmqNTv08EjqX4425IcB0Wx6XYV4zgR3tWTH10yMlMVfk0NZYjEI30iUjz41YBdHy28nehNUODHtBif2c98Ex7Jq84+tP741cFwR16UwXFpGUMPJfyxH5axYphMDGzsHqd5UkV1ciLCqMBNghhtR2iIE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1vl7cg-0003op-Nh; Wed, 28 Jan 2026 16:38:26 +0100 Received: from dude04.red.stw.pengutronix.de ([2a0a:edc0:0:1101:1d::ac] helo=dude04) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vl7cg-002wSK-2P; Wed, 28 Jan 2026 16:38:26 +0100 Received: from ore by dude04 with local (Exim 4.98.2) (envelope-from ) id 1vl7cf-0000000FR9k-4BYT; Wed, 28 Jan 2026 16:38:25 +0100 From: Oleksij Rempel To: Jonathan Cameron , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: Oleksij Rempel , stable@vger.kernel.org, kernel@pengutronix.de, linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, Andy Shevchenko , David Lechner , =?UTF-8?q?Nuno=20S=C3=A1?= , David Jander Subject: [PATCH v3 1/8] iio: dac: ds4424: fix -128 rejection and refactor raw access Date: Wed, 28 Jan 2026 16:38:17 +0100 Message-ID: <20260128153824.3679187-2-o.rempel@pengutronix.de> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260128153824.3679187-1-o.rempel@pengutronix.de> References: <20260128153824.3679187-1-o.rempel@pengutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ore@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The DS442x DAC uses sign-magnitude encoding, so -128 cannot be represented. Previously, passing -128 resulted in a truncated value that programmed 0mA. Fix this by validating the input against the 7-bit magnitude limit. Additionally, refactor the raw access logic to use symmetrical bitwise operations, replacing the union structure. Fixes: d632a2bd8ffc ("iio: dac: ds4422/ds4424 dac driver") Cc: Signed-off-by: Oleksij Rempel Reviewed-by: Andy Shevchenko --- changes v3: - Remove "Rebase on top of regmap" note as this is now patch 1/8. - Add #include - Clarify 0mA sink/source behavior in comments - Remove redundant blank line in write_raw changes v2: - Replace S8_MIN/MAX checks with abs() > DS4424_DAC_MASK to enforce the correct [-127, 127] physical range. - Refactor read_raw/write_raw to use symmetrical bitwise operations, removing the custom bitfield union. - Rebase on top of regmap port --- drivers/iio/dac/ds4424.c | 55 +++++++++++++++------------------------- 1 file changed, 21 insertions(+), 34 deletions(-) diff --git a/drivers/iio/dac/ds4424.c b/drivers/iio/dac/ds4424.c index a8198ba4f98a..596ff5999271 100644 --- a/drivers/iio/dac/ds4424.c +++ b/drivers/iio/dac/ds4424.c @@ -5,6 +5,7 @@ * Copyright (C) 2017 Maxim Integrated */ =20 +#include #include #include #include @@ -19,9 +20,10 @@ #define DS4422_MAX_DAC_CHANNELS 2 #define DS4424_MAX_DAC_CHANNELS 4 =20 +#define DS4424_DAC_MASK GENMASK(6, 0) +#define DS4424_DAC_SOURCE BIT(7) + #define DS4424_DAC_ADDR(chan) ((chan) + 0xf8) -#define DS4424_SOURCE_I 1 -#define DS4424_SINK_I 0 =20 #define DS4424_CHANNEL(chan) { \ .type =3D IIO_CURRENT, \ @@ -31,22 +33,6 @@ .info_mask_separate =3D BIT(IIO_CHAN_INFO_RAW), \ } =20 -/* - * DS4424 DAC control register 8 bits - * [7] 0: to sink; 1: to source - * [6:0] steps to sink/source - * bit[7] looks like a sign bit, but the value of the register is - * not a two's complement code considering the bit[6:0] is a absolute - * distance from the zero point. - */ -union ds4424_raw_data { - struct { - u8 dx:7; - u8 source_bit:1; - }; - u8 bits; -}; - enum ds4424_device_ids { ID_DS4422, ID_DS4424, @@ -108,21 +94,21 @@ static int ds4424_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val, int *val2, long mask) { - union ds4424_raw_data raw; - int ret; + int ret, regval; =20 switch (mask) { case IIO_CHAN_INFO_RAW: - ret =3D ds4424_get_value(indio_dev, val, chan->channel); + ret =3D ds4424_get_value(indio_dev, ®val, chan->channel); if (ret < 0) { pr_err("%s : ds4424_get_value returned %d\n", __func__, ret); return ret; } - raw.bits =3D *val; - *val =3D raw.dx; - if (raw.source_bit =3D=3D DS4424_SINK_I) + + *val =3D regval & DS4424_DAC_MASK; + if (!(regval & DS4424_DAC_SOURCE)) *val =3D -*val; + return IIO_VAL_INT; =20 default: @@ -134,25 +120,26 @@ static int ds4424_write_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int val, int val2, long mask) { - union ds4424_raw_data raw; + unsigned int abs_val; =20 if (val2 !=3D 0) return -EINVAL; =20 switch (mask) { case IIO_CHAN_INFO_RAW: - if (val < S8_MIN || val > S8_MAX) + abs_val =3D abs(val); + if (abs_val > DS4424_DAC_MASK) return -EINVAL; =20 - if (val > 0) { - raw.source_bit =3D DS4424_SOURCE_I; - raw.dx =3D val; - } else { - raw.source_bit =3D DS4424_SINK_I; - raw.dx =3D -val; - } + /* + * Currents exiting the IC (Source) are positive. 0 is a valid + * value for no current flow; the direction bit (Source vs Sink) + * is treated as don't-care by the hardware at 0. + */ + if (val > 0) + abs_val |=3D DS4424_DAC_SOURCE; =20 - return ds4424_set_value(indio_dev, raw.bits, chan); + return ds4424_set_value(indio_dev, abs_val, chan); =20 default: return -EINVAL; --=20 2.47.3 From nobody Mon Feb 9 03:47:23 2026 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (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 202242DFA3A for ; Wed, 28 Jan 2026 15:38:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769614715; cv=none; b=jIepurXew39Q3NlTelsGLdvu06sKirPT4hkWOHO97RpChV8ofcvNo1fzKJMHzS+muoZEsERWyWiPUUc3Fx4/JV0bivMytq+WkQWHsNp5O/BNSXVRMj0ltWHFtngyu4cqhK4MbjBa4pHsN/PrVEkLMhMgWwYCVBkSzLBPhAMqKUo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769614715; c=relaxed/simple; bh=cLW8SrWmi7lpQKdnvAFnJeRFfADLLP7ovJP67HXlncc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GFY7D6rt+M7+LeIC67TV5r7qk5akKf4mFtNuqay0u4bhEf/eCLGfZsS3Nz8MHTLnQPEsnM2lAOvZUxctnz5SgzG1oLQ5h+RCZNO0U9AxDIbOWifsDJ/Ta6BrXBu2/w+f63vVFl1Z5A7/vZKo65K6Y3VMRhYR0Xo+6LytctGBldI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1vl7cg-0003oq-Ng; Wed, 28 Jan 2026 16:38:26 +0100 Received: from dude04.red.stw.pengutronix.de ([2a0a:edc0:0:1101:1d::ac] helo=dude04) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vl7cg-002wSL-2U; Wed, 28 Jan 2026 16:38:26 +0100 Received: from ore by dude04 with local (Exim 4.98.2) (envelope-from ) id 1vl7cg-0000000FR9u-06sZ; Wed, 28 Jan 2026 16:38:26 +0100 From: Oleksij Rempel To: Jonathan Cameron , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: Oleksij Rempel , kernel@pengutronix.de, linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, Andy Shevchenko , David Lechner , =?UTF-8?q?Nuno=20S=C3=A1?= , David Jander Subject: [PATCH v3 2/8] iio: dac: ds4424: ratelimit read errors and use device context Date: Wed, 28 Jan 2026 16:38:18 +0100 Message-ID: <20260128153824.3679187-3-o.rempel@pengutronix.de> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260128153824.3679187-1-o.rempel@pengutronix.de> References: <20260128153824.3679187-1-o.rempel@pengutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ore@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Replace pr_err() with dev_err_ratelimited() in the RAW read path to avoid log spam on repeated I2C failures and to include the device context. Use %pe to print errno names for faster debugging. Use the parent device context to identify the physical hardware causing the error. Signed-off-by: Oleksij Rempel Reviewed-by: Andy Shevchenko --- changes v3: - Use indio_dev->dev.parent to reference the physical device. - Remove redundant space in error message: "channel %d: %pe". - This patch now precedes regmap refactoring. changes v2: - Update error message - Rebase against regmap refactoring --- drivers/iio/dac/ds4424.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/iio/dac/ds4424.c b/drivers/iio/dac/ds4424.c index 596ff5999271..36286e4923af 100644 --- a/drivers/iio/dac/ds4424.c +++ b/drivers/iio/dac/ds4424.c @@ -100,8 +100,9 @@ static int ds4424_read_raw(struct iio_dev *indio_dev, case IIO_CHAN_INFO_RAW: ret =3D ds4424_get_value(indio_dev, ®val, chan->channel); if (ret < 0) { - pr_err("%s : ds4424_get_value returned %d\n", - __func__, ret); + dev_err_ratelimited(indio_dev->dev.parent, + "Failed to read channel %d: %pe\n", + chan->channel, ERR_PTR(ret)); return ret; } =20 --=20 2.47.3 From nobody Mon Feb 9 03:47:23 2026 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (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 4E1652DEA67 for ; Wed, 28 Jan 2026 15:38:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769614715; cv=none; b=eD3aGboUE395tzK7J4lZ4t2wuWXLkh9TqZuYj9+T6LOWuVgrzF8jeKc3tgtEypEAQV/YMR+2FKKVlscdq4ydk4CjVqofRHrMqJkSU7fvgyQxR9RcpFpnvNpAUB+NFN0MSRdeGyWB39C1Mji2jtAbAmDCh/C+k6Dvgxh6Y7BX84I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769614715; c=relaxed/simple; bh=HuKdx9+NgWt+Gf9a6JvbKAE5xNrIcXfGej0M3axBDjw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=M2lIs2HdeFy2l1r4P0RdogMwMXeonLhzVvaZAoJ88yxiQVzH2QcjVqBOTvwpZxgbUaDNSRLMbpEqbR1SB0GGYbFjI0OzMrVe+h8519xjdDUu0EZK3rHPWL13tkWUJZUdvGceICqxr3ui0TdSRU+fcg8aeBvPJ+6IH1xq8OCwUek= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1vl7cg-0003or-Nh; Wed, 28 Jan 2026 16:38:26 +0100 Received: from dude04.red.stw.pengutronix.de ([2a0a:edc0:0:1101:1d::ac] helo=dude04) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vl7cg-002wSM-2b; Wed, 28 Jan 2026 16:38:26 +0100 Received: from ore by dude04 with local (Exim 4.98.2) (envelope-from ) id 1vl7cg-0000000FRA4-0EAo; Wed, 28 Jan 2026 16:38:26 +0100 From: Oleksij Rempel To: Jonathan Cameron , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: Oleksij Rempel , kernel@pengutronix.de, linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, Andy Shevchenko , David Lechner , =?UTF-8?q?Nuno=20S=C3=A1?= , David Jander Subject: [PATCH v3 3/8] iio: dac: ds4424: sort headers alphabetically Date: Wed, 28 Jan 2026 16:38:19 +0100 Message-ID: <20260128153824.3679187-4-o.rempel@pengutronix.de> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260128153824.3679187-1-o.rempel@pengutronix.de> References: <20260128153824.3679187-1-o.rempel@pengutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ore@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Sort the header inclusions alphabetically. This improves readability and simplifies adding new includes in the future. Group subsystem-specific headers (linux/iio/*) separately at the end to clarify subsystem context. Signed-off-by: Oleksij Rempel Reviewed-by: Andy Shevchenko --- changes v3: - Keep linux/iio/* headers in a separate group at the end of the includes. changes v2: - new patch --- drivers/iio/dac/ds4424.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/drivers/iio/dac/ds4424.c b/drivers/iio/dac/ds4424.c index 36286e4923af..c03051dc763e 100644 --- a/drivers/iio/dac/ds4424.c +++ b/drivers/iio/dac/ds4424.c @@ -6,16 +6,17 @@ */ =20 #include +#include +#include +#include #include #include -#include #include -#include -#include -#include + +#include #include +#include #include -#include =20 #define DS4422_MAX_DAC_CHANNELS 2 #define DS4424_MAX_DAC_CHANNELS 4 --=20 2.47.3 From nobody Mon Feb 9 03:47:23 2026 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (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 E12ED2D8760 for ; Wed, 28 Jan 2026 15:38:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769614715; cv=none; b=Y5yxpBIOby0BAymrDZ/deqsAVO4OL+MtrIrBeXttorDkN79V2cYmuJ6cy1JA3jMEjgv2lkleQGIoK4y8TCfQZCwgtTsy/hH26JR2pSIzfb3mzEY5OtUKiX8Z6ywi/Hfy8Wy9nMOU4KmCVYZjwfy/9KN1xluqhPmKs+lEzdRydUg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769614715; c=relaxed/simple; bh=ilau8yL6huoGlzY1yLTbGIzny37UcmWhmrfY2LugRYA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=T7IEhRCc2J2lwZsHW8XDo+berRJ4SjYuEq8k+zgywfTFKanQw+fwU1RCgMXZY2eiQzGzKVa5hWeVKVSsnwKsdnO7s2hemImNBEbi5OzK4pdlvxtIAW0c951yZvkqtcykA9m6U+EGhuA9tZL3Iw/WK41AsT2yDlngnvzKWOxAwPY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1vl7cg-0003os-Nh; Wed, 28 Jan 2026 16:38:26 +0100 Received: from dude04.red.stw.pengutronix.de ([2a0a:edc0:0:1101:1d::ac] helo=dude04) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vl7cg-002wSO-2k; Wed, 28 Jan 2026 16:38:26 +0100 Received: from ore by dude04 with local (Exim 4.98.2) (envelope-from ) id 1vl7cg-0000000FRAE-0LUK; Wed, 28 Jan 2026 16:38:26 +0100 From: Oleksij Rempel To: Jonathan Cameron , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: Oleksij Rempel , Conor Dooley , kernel@pengutronix.de, linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, Andy Shevchenko , David Lechner , =?UTF-8?q?Nuno=20S=C3=A1?= , David Jander Subject: [PATCH v3 4/8] dt-bindings: iio: dac: maxim,ds4424: add ds4402/ds4404 Date: Wed, 28 Jan 2026 16:38:20 +0100 Message-ID: <20260128153824.3679187-5-o.rempel@pengutronix.de> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260128153824.3679187-1-o.rempel@pengutronix.de> References: <20260128153824.3679187-1-o.rempel@pengutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ore@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Add compatible strings for Maxim DS4402 and DS4404 current DACs. These devices are 5-bit variants of the DS4422/DS4424 family. Signed-off-by: Oleksij Rempel Acked-by: Conor Dooley Reviewed-by: Andy Shevchenko --- changes v3: - No changes. changes v2: - add Acked-by: Conor .. --- .../devicetree/bindings/iio/dac/maxim,ds4424.yaml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Documentation/devicetree/bindings/iio/dac/maxim,ds4424.yaml b/= Documentation/devicetree/bindings/iio/dac/maxim,ds4424.yaml index 264fa7c5fe3a..efe63e6cb55d 100644 --- a/Documentation/devicetree/bindings/iio/dac/maxim,ds4424.yaml +++ b/Documentation/devicetree/bindings/iio/dac/maxim,ds4424.yaml @@ -4,18 +4,21 @@ $id: http://devicetree.org/schemas/iio/dac/maxim,ds4424.yaml# $schema: http://devicetree.org/meta-schemas/core.yaml# =20 -title: Maxim Integrated DS4422/DS4424 7-bit Sink/Source Current DAC +title: Maxim Integrated DS4402/DS4404 and DS4422/DS4424 Current DACs =20 maintainers: - Ismail Kose =20 description: | - Datasheet publicly available at: + Datasheets publicly available at: + https://datasheets.maximintegrated.com/en/ds/DS4402-DS4404.pdf https://datasheets.maximintegrated.com/en/ds/DS4422-DS4424.pdf =20 properties: compatible: enum: + - maxim,ds4402 + - maxim,ds4404 - maxim,ds4422 - maxim,ds4424 =20 --=20 2.47.3 From nobody Mon Feb 9 03:47:23 2026 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (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 1F2352DEA6B for ; Wed, 28 Jan 2026 15:38:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769614716; cv=none; b=jwjGEd/d4/ez/b3m9uQQ1V/pEGb+J+t2xPGpAjHCzT5khHPf6kd1lG8MJkOnTp3RG4uJ+1jzxsDNcZnmHCIF1/9At1vjVDrcSRd1oWTR6zBu2EtFBHLKrKGxpUU2hCMoJGjvJwPw51F2FWMBpf1zreH7IA8Wlr9GHYorhhwVGoc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769614716; c=relaxed/simple; bh=8OlP/76Ew+hhf0/5eOzjr5oQG0D+UPVg93zLkxqIWvE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=opTFhiH7LYYLqPr26ZIfb3zugfoQLnq1aR9pfhlKpi3rNa/vM79cG9za18/IVL5dZbw73Tv/L0WVzn5W0JChzc1PybsCRMGVZcveKWw0h+irC3qVpLihqZrjHbPJ7QTp8jZwuKPZx4pd97+sVLcr11yM9/2AI1fgDaEChzqErmI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1vl7cg-0003ot-Nh; Wed, 28 Jan 2026 16:38:26 +0100 Received: from dude04.red.stw.pengutronix.de ([2a0a:edc0:0:1101:1d::ac] helo=dude04) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vl7cg-002wSR-2p; Wed, 28 Jan 2026 16:38:26 +0100 Received: from ore by dude04 with local (Exim 4.98.2) (envelope-from ) id 1vl7cg-0000000FRAO-0SOw; Wed, 28 Jan 2026 16:38:26 +0100 From: Oleksij Rempel To: Jonathan Cameron , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: Oleksij Rempel , kernel@pengutronix.de, linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, Andy Shevchenko , David Lechner , =?UTF-8?q?Nuno=20S=C3=A1?= , David Jander Subject: [PATCH v3 5/8] dt-bindings: iio: dac: maxim,ds4424: add maxim,rfs-ohms property Date: Wed, 28 Jan 2026 16:38:21 +0100 Message-ID: <20260128153824.3679187-6-o.rempel@pengutronix.de> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260128153824.3679187-1-o.rempel@pengutronix.de> References: <20260128153824.3679187-1-o.rempel@pengutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ore@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The Maxim DS4422/DS4424 and DS4402/DS4404 current DACs determine their full-scale output current via external resistors (Rfs) connected to the FSx pins. Without knowing these values, the full-scale range of the hardware is undefined. Add the 'maxim,rfs-ohms' property to describe these physical components. This property is required to provide a complete description of the hardware configuration. Signed-off-by: Oleksij Rempel Acked-by: Conor Dooley Reviewed-by: Andy Shevchenko --- changes v3: - Moved minItems and maxItems to the main property definition - Refined property description to state that values depend on chip variant and hardware requirements, deliberately avoiding specific "typical" ranges to prevent unnecessary hard-limit enforcement. - Corrected the rfs-ohms example to use a plausible value within datasheet typical range. - Removed redundant constraint definitions from the allOf logic. changes v2: - make maxim,rfs-ohms a required property as the hardware range is undefined without external resistors. - add allOf constraints to enforce 2 vs 4 items in maxim,rfs-ohms based on compatible string. - drop explicit $ref for maxim,rfs-ohms to fix dt_binding_check warning. - update example in binding to include the new required property. --- .../bindings/iio/dac/maxim,ds4424.yaml | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/Documentation/devicetree/bindings/iio/dac/maxim,ds4424.yaml b/= Documentation/devicetree/bindings/iio/dac/maxim,ds4424.yaml index efe63e6cb55d..4323df2036ac 100644 --- a/Documentation/devicetree/bindings/iio/dac/maxim,ds4424.yaml +++ b/Documentation/devicetree/bindings/iio/dac/maxim,ds4424.yaml @@ -27,9 +27,43 @@ properties: =20 vcc-supply: true =20 + maxim,rfs-ohms: + description: | + Array of resistance values in Ohms for the external Rfs resistors + connected to the FS pins. These values determine the full-scale + output current. The actual resistance depends on the chip variant + and specific hardware design requirements. + minItems: 2 + maxItems: 4 + required: - compatible - reg + - maxim,rfs-ohms + +allOf: + - if: + properties: + compatible: + contains: + enum: + - maxim,ds4402 + - maxim,ds4422 + then: + properties: + maxim,rfs-ohms: + maxItems: 2 + - if: + properties: + compatible: + contains: + enum: + - maxim,ds4404 + - maxim,ds4424 + then: + properties: + maxim,rfs-ohms: + minItems: 4 =20 additionalProperties: false =20 @@ -43,6 +77,7 @@ examples: compatible =3D "maxim,ds4424"; reg =3D <0x10>; /* When A0, A1 pins are ground */ vcc-supply =3D <&vcc_3v3>; + maxim,rfs-ohms =3D <40000>, <40000>, <40000>, <40000>; }; }; ... --=20 2.47.3 From nobody Mon Feb 9 03:47:23 2026 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (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 507EE2DB784 for ; Wed, 28 Jan 2026 15:38:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769614713; cv=none; b=PuAQyKbcfcxbHfQCgqoFqVsB0DgG1F/qpk0N74RiAJXfmG61xxMFdb67eDNVsuzMlFGEA6EoevKGKZkZgtfCpcZgk5OxaI3CAFP6dKBPGzrArYymPL6Tv23X+5lhyhnWXEcYWUFVA54Uv8XJ6l8p7UnNfmcph2eaBxlleikLq2g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769614713; c=relaxed/simple; bh=nCBX2+JdcOPR0tpAfla1hv9A6gt7UgAonRy4rQW5REw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bi23sXDH0Gn9RXHIfteOr/lUO9fX/HI5JTcR4JAehMoYB5xuQfXOCVPwsinBMEt/yGYzwkSKpQGaJbaFpsm8Sm2ibwbgidSrYWU1aI4eKlsXGPPGDqC0IHBbZJ+gd43I/kPxKzzP8B7iBOmOCXaxYLMNVELfAvCoyclB4R7pAgM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1vl7cg-0003ou-Nf; Wed, 28 Jan 2026 16:38:26 +0100 Received: from dude04.red.stw.pengutronix.de ([2a0a:edc0:0:1101:1d::ac] helo=dude04) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vl7cg-002wSU-2x; Wed, 28 Jan 2026 16:38:26 +0100 Received: from ore by dude04 with local (Exim 4.98.2) (envelope-from ) id 1vl7cg-0000000FRAZ-0ZUC; Wed, 28 Jan 2026 16:38:26 +0100 From: Oleksij Rempel To: Jonathan Cameron , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: David Jander , Oleksij Rempel , kernel@pengutronix.de, linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, Andy Shevchenko , David Lechner , =?UTF-8?q?Nuno=20S=C3=A1?= Subject: [PATCH v3 6/8] iio: dac: ds4424: add DS4402/DS4404 device IDs Date: Wed, 28 Jan 2026 16:38:22 +0100 Message-ID: <20260128153824.3679187-7-o.rempel@pengutronix.de> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260128153824.3679187-1-o.rempel@pengutronix.de> References: <20260128153824.3679187-1-o.rempel@pengutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ore@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: David Jander Add I2C/OF IDs for DS4402 and DS4404 and set the correct channel count. Follow-up changes add per-variant scaling based on external Rfs. Co-developed-by: Oleksij Rempel Signed-off-by: Oleksij Rempel Signed-off-by: David Jander Reviewed-by: Andy Shevchenko --- changes v3: - Reset author to David Jander and added Co-developed-by tag for Oleksij Rempel to clarify roles changes v2: - No changes. --- drivers/iio/dac/ds4424.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/iio/dac/ds4424.c b/drivers/iio/dac/ds4424.c index c03051dc763e..f340d491fcc1 100644 --- a/drivers/iio/dac/ds4424.c +++ b/drivers/iio/dac/ds4424.c @@ -35,6 +35,8 @@ } =20 enum ds4424_device_ids { + ID_DS4402, + ID_DS4404, ID_DS4422, ID_DS4424, }; @@ -237,6 +239,12 @@ static int ds4424_probe(struct i2c_client *client) goto fail; =20 switch (id->driver_data) { + case ID_DS4402: + indio_dev->num_channels =3D DS4422_MAX_DAC_CHANNELS; + break; + case ID_DS4404: + indio_dev->num_channels =3D DS4424_MAX_DAC_CHANNELS; + break; case ID_DS4422: indio_dev->num_channels =3D DS4422_MAX_DAC_CHANNELS; break; @@ -278,6 +286,8 @@ static void ds4424_remove(struct i2c_client *client) } =20 static const struct i2c_device_id ds4424_id[] =3D { + { "ds4402", ID_DS4402 }, + { "ds4404", ID_DS4404 }, { "ds4422", ID_DS4422 }, { "ds4424", ID_DS4424 }, { } @@ -286,6 +296,8 @@ static const struct i2c_device_id ds4424_id[] =3D { MODULE_DEVICE_TABLE(i2c, ds4424_id); =20 static const struct of_device_id ds4424_of_match[] =3D { + { .compatible =3D "maxim,ds4402" }, + { .compatible =3D "maxim,ds4404" }, { .compatible =3D "maxim,ds4422" }, { .compatible =3D "maxim,ds4424" }, { } --=20 2.47.3 From nobody Mon Feb 9 03:47:23 2026 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (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 38D9F2E2299 for ; Wed, 28 Jan 2026 15:38:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769614713; cv=none; b=Q68ECURAWohr2bZD7NkE/u8bOFLdYWduSpElxyDpLP5gbhw+BNFhpQOAplh8DfBtqYzK415I7RSU0u75+xAWr5nad8qXwVAlJG0UIMUb3YMJXwe/kCyGEx2PXbiqrjURxHwA9j/99Z5y+A2HaPKdhte1vkx7ssEI+/iufOzKV/o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769614713; c=relaxed/simple; bh=cICnMvrZpddQjj4AsMXgMuQwqiM4gYA74oqyfJsDmfM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ExUwRNTjyWhc245dZPi3/VVM8ddhVS9Wlu7QJefxn6zk1nEltEY4hTrGCSSoHqKbUtvYDxVrrt4O3ToeNBdfeqG3c+bD28PfTM7Kgw81c52bKrQTwBS8a0Ij1ZWFkea9QlXlBlPQSOicOpHYgX42/dYLvXMGDRsvAxUy/EflW9c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1vl7cg-0003ov-Ni; Wed, 28 Jan 2026 16:38:26 +0100 Received: from dude04.red.stw.pengutronix.de ([2a0a:edc0:0:1101:1d::ac] helo=dude04) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vl7cg-002wSX-33; Wed, 28 Jan 2026 16:38:26 +0100 Received: from ore by dude04 with local (Exim 4.98.2) (envelope-from ) id 1vl7cg-0000000FRAk-0h6c; Wed, 28 Jan 2026 16:38:26 +0100 From: Oleksij Rempel To: Jonathan Cameron , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: Oleksij Rempel , kernel@pengutronix.de, linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, Andy Shevchenko , David Lechner , =?UTF-8?q?Nuno=20S=C3=A1?= , David Jander Subject: [PATCH v3 7/8] iio: dac: ds4424: convert to regmap Date: Wed, 28 Jan 2026 16:38:23 +0100 Message-ID: <20260128153824.3679187-8-o.rempel@pengutronix.de> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260128153824.3679187-1-o.rempel@pengutronix.de> References: <20260128153824.3679187-1-o.rempel@pengutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ore@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Refactor the driver to use the regmap API. Replace the driver-specific mutex and manual shadow buffers with the standard regmap infrastructure for locking and caching. This ensures the cache is populated from hardware at probe, preventing state desynchronization (e.g. across suspend/resume). Define access tables to validate the different register maps of DS44x2 and DS44x4. Signed-off-by: Oleksij Rempel Reviewed-by: Andy Shevchenko Reviewed-by: Sander Vanheule --- changes v3: - Switch to REGCACHE_MAPLE to efficiently handle the sparse register map (offset 0xF8) and avoid allocating memory for the unused 0x00-0xF7 range. - Use explicit regmap_bulk_read() in probe to seed the cache with the bootloader configuration. This avoids the invalid read from address 0x00 that occurred with generic cache defaults. - Remove ds4424_verify_chip(); devm_regmap_init_i2c() and the subsequent bulk read implicitly validate the device presence. - Use regmap_bulk_write() in ds4424_suspend() to efficiently zero all channels. - Adopt fsleep() for delays and include . - Use dev_err_ratelimited() with the physical device context in the read path (incorporating feedback aimed at v2 patch 8). changes v2: - new patch --- drivers/iio/dac/Kconfig | 1 + drivers/iio/dac/ds4424.c | 171 ++++++++++++++++++++++----------------- 2 files changed, 97 insertions(+), 75 deletions(-) diff --git a/drivers/iio/dac/Kconfig b/drivers/iio/dac/Kconfig index 7cd3caec1262..dbbbc45e8718 100644 --- a/drivers/iio/dac/Kconfig +++ b/drivers/iio/dac/Kconfig @@ -408,6 +408,7 @@ config DPOT_DAC config DS4424 tristate "Maxim Integrated DS4422/DS4424 DAC driver" depends on I2C + select REGMAP_I2C help If you say yes here you get support for Maxim chips DS4422, DS4424. =20 diff --git a/drivers/iio/dac/ds4424.c b/drivers/iio/dac/ds4424.c index f340d491fcc1..9bef1c60b2eb 100644 --- a/drivers/iio/dac/ds4424.c +++ b/drivers/iio/dac/ds4424.c @@ -5,12 +5,14 @@ * Copyright (C) 2017 Maxim Integrated */ =20 +#include #include #include #include #include #include #include +#include #include =20 #include @@ -42,11 +44,8 @@ enum ds4424_device_ids { }; =20 struct ds4424_data { - struct i2c_client *client; - struct mutex lock; - uint8_t save[DS4424_MAX_DAC_CHANNELS]; + struct regmap *regmap; struct regulator *vcc_reg; - uint8_t raw[DS4424_MAX_DAC_CHANNELS]; }; =20 static const struct iio_chan_spec ds4424_channels[] =3D { @@ -56,52 +55,88 @@ static const struct iio_chan_spec ds4424_channels[] =3D= { DS4424_CHANNEL(3), }; =20 -static int ds4424_get_value(struct iio_dev *indio_dev, - int *val, int channel) -{ - struct ds4424_data *data =3D iio_priv(indio_dev); - int ret; +static const struct regmap_range ds44x2_ranges[] =3D { + regmap_reg_range(DS4424_DAC_ADDR(0), DS4424_DAC_ADDR(1)), +}; =20 - mutex_lock(&data->lock); - ret =3D i2c_smbus_read_byte_data(data->client, DS4424_DAC_ADDR(channel)); - if (ret < 0) - goto fail; +static const struct regmap_range ds44x4_ranges[] =3D { + regmap_reg_range(DS4424_DAC_ADDR(0), DS4424_DAC_ADDR(3)), +}; =20 - *val =3D ret; +static const struct regmap_access_table ds44x2_table =3D { + .yes_ranges =3D ds44x2_ranges, + .n_yes_ranges =3D ARRAY_SIZE(ds44x2_ranges), +}; =20 -fail: - mutex_unlock(&data->lock); - return ret; -} +static const struct regmap_access_table ds44x4_table =3D { + .yes_ranges =3D ds44x4_ranges, + .n_yes_ranges =3D ARRAY_SIZE(ds44x4_ranges), +}; =20 -static int ds4424_set_value(struct iio_dev *indio_dev, - int val, struct iio_chan_spec const *chan) +static const struct regmap_config ds44x2_regmap_config =3D { + .reg_bits =3D 8, + .val_bits =3D 8, + .cache_type =3D REGCACHE_MAPLE, + .max_register =3D DS4424_DAC_ADDR(1), + .rd_table =3D &ds44x2_table, + .wr_table =3D &ds44x2_table, + /* Seed cache from HW during regmap_init */ +}; + +static const struct regmap_config ds44x4_regmap_config =3D { + .reg_bits =3D 8, + .val_bits =3D 8, + .cache_type =3D REGCACHE_MAPLE, + .max_register =3D DS4424_DAC_ADDR(3), + .rd_table =3D &ds44x4_table, + .wr_table =3D &ds44x4_table, + /* Seed cache from HW during regmap_init */ +}; + +static int ds4424_init_regmap(struct i2c_client *client, + struct iio_dev *indio_dev) { struct ds4424_data *data =3D iio_priv(indio_dev); + const struct regmap_config *regmap_config; + u8 vals[DS4424_MAX_DAC_CHANNELS]; int ret; =20 - mutex_lock(&data->lock); - ret =3D i2c_smbus_write_byte_data(data->client, - DS4424_DAC_ADDR(chan->channel), val); - if (ret < 0) - goto fail; - - data->raw[chan->channel] =3D val; - -fail: - mutex_unlock(&data->lock); - return ret; + if (indio_dev->num_channels =3D=3D DS4424_MAX_DAC_CHANNELS) + regmap_config =3D &ds44x4_regmap_config; + else + regmap_config =3D &ds44x2_regmap_config; + + data->regmap =3D devm_regmap_init_i2c(client, regmap_config); + if (IS_ERR(data->regmap)) + return dev_err_probe(&client->dev, PTR_ERR(data->regmap), + "Failed to init regmap.\n"); + + /* + * Prime the cache with the bootloader's configuration. + * regmap_bulk_read will automatically populate the cache with + * the values read from the hardware. + */ + ret =3D regmap_bulk_read(data->regmap, DS4424_DAC_ADDR(0), vals, + indio_dev->num_channels); + if (ret) + return dev_err_probe(&client->dev, ret, + "Failed to read hardware defaults\n"); + + return 0; } =20 static int ds4424_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val, int *val2, long mask) { - int ret, regval; + struct ds4424_data *data =3D iio_priv(indio_dev); + unsigned int regval; + int ret; =20 switch (mask) { case IIO_CHAN_INFO_RAW: - ret =3D ds4424_get_value(indio_dev, ®val, chan->channel); + ret =3D regmap_read(data->regmap, DS4424_DAC_ADDR(chan->channel), + ®val); if (ret < 0) { dev_err_ratelimited(indio_dev->dev.parent, "Failed to read channel %d: %pe\n", @@ -124,6 +159,7 @@ static int ds4424_write_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int val, int val2, long mask) { + struct ds4424_data *data =3D iio_priv(indio_dev); unsigned int abs_val; =20 if (val2 !=3D 0) @@ -143,58 +179,44 @@ static int ds4424_write_raw(struct iio_dev *indio_dev, if (val > 0) abs_val |=3D DS4424_DAC_SOURCE; =20 - return ds4424_set_value(indio_dev, abs_val, chan); + return regmap_write(data->regmap, DS4424_DAC_ADDR(chan->channel), + abs_val); =20 default: return -EINVAL; } } =20 -static int ds4424_verify_chip(struct iio_dev *indio_dev) -{ - int ret, val; - - ret =3D ds4424_get_value(indio_dev, &val, 0); - if (ret < 0) - dev_err(&indio_dev->dev, - "%s failed. ret: %d\n", __func__, ret); - - return ret; -} - static int ds4424_suspend(struct device *dev) { - struct i2c_client *client =3D to_i2c_client(dev); - struct iio_dev *indio_dev =3D i2c_get_clientdata(client); + struct iio_dev *indio_dev =3D dev_get_drvdata(dev); struct ds4424_data *data =3D iio_priv(indio_dev); - int ret =3D 0; - int i; - - for (i =3D 0; i < indio_dev->num_channels; i++) { - data->save[i] =3D data->raw[i]; - ret =3D ds4424_set_value(indio_dev, 0, - &indio_dev->channels[i]); - if (ret < 0) - return ret; + u8 zero_buf[DS4424_MAX_DAC_CHANNELS] =3D { 0 }; + int ret; + + /* Disable all outputs, bypass cache so the '0' isn't saved */ + regcache_cache_bypass(data->regmap, true); + ret =3D regmap_bulk_write(data->regmap, DS4424_DAC_ADDR(0), + zero_buf, indio_dev->num_channels); + regcache_cache_bypass(data->regmap, false); + if (ret) { + dev_err(dev, "Failed to zero outputs: %pe\n", ERR_PTR(ret)); + return ret; } - return ret; + + regcache_cache_only(data->regmap, true); + regcache_mark_dirty(data->regmap); + + return 0; } =20 static int ds4424_resume(struct device *dev) { - struct i2c_client *client =3D to_i2c_client(dev); - struct iio_dev *indio_dev =3D i2c_get_clientdata(client); + struct iio_dev *indio_dev =3D dev_get_drvdata(dev); struct ds4424_data *data =3D iio_priv(indio_dev); - int ret =3D 0; - int i; =20 - for (i =3D 0; i < indio_dev->num_channels; i++) { - ret =3D ds4424_set_value(indio_dev, data->save[i], - &indio_dev->channels[i]); - if (ret < 0) - return ret; - } - return ret; + regcache_cache_only(data->regmap, false); + return regcache_sync(data->regmap); } =20 static DEFINE_SIMPLE_DEV_PM_OPS(ds4424_pm_ops, ds4424_suspend, ds4424_resu= me); @@ -217,7 +239,6 @@ static int ds4424_probe(struct i2c_client *client) =20 data =3D iio_priv(indio_dev); i2c_set_clientdata(client, indio_dev); - data->client =3D client; indio_dev->name =3D id->name; =20 data->vcc_reg =3D devm_regulator_get(&client->dev, "vcc"); @@ -225,7 +246,6 @@ static int ds4424_probe(struct i2c_client *client) return dev_err_probe(&client->dev, PTR_ERR(data->vcc_reg), "Failed to get vcc-supply regulator.\n"); =20 - mutex_init(&data->lock); ret =3D regulator_enable(data->vcc_reg); if (ret < 0) { dev_err(&client->dev, @@ -233,10 +253,7 @@ static int ds4424_probe(struct i2c_client *client) return ret; } =20 - usleep_range(1000, 1200); - ret =3D ds4424_verify_chip(indio_dev); - if (ret < 0) - goto fail; + fsleep(1000); =20 switch (id->driver_data) { case ID_DS4402: @@ -258,6 +275,10 @@ static int ds4424_probe(struct i2c_client *client) goto fail; } =20 + ret =3D ds4424_init_regmap(client, indio_dev); + if (ret) + goto fail; + indio_dev->channels =3D ds4424_channels; indio_dev->modes =3D INDIO_DIRECT_MODE; indio_dev->info =3D &ds4424_info; --=20 2.47.3 From nobody Mon Feb 9 03:47:23 2026 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (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 4E0572DE6FC for ; Wed, 28 Jan 2026 15:38:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769614715; cv=none; b=S7+of1p1CsGvkOxJ3n0Qhz5XGl6CTPA750iX2c+QfBx2tJ5LRq34+oFSV7+VzCUmUwbxLU83MHL3kDQYmwZ9fRy8f+94wcqVk/134YaeOT8Qb2pi6UsS1AaeSVGGv/pN4yi9hUsgmQplD7h0ppHBt/n8Clnq1/KaTOAl/mcJonY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769614715; c=relaxed/simple; bh=g2b3UszPCHECOmiGzz20e72H5NdvyxMqvnX7o6q8Vr4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=t0VclkmU2i/LqUc8rLpj9TDwt2YrWQfntkdeqlQG4Wxz7eHemtOYg8kjyO8UWAx4SP2Sf0Ni0AEVdp2yEXP6kPionaIqnlqh9MRvLj8rEZus4cpMhMkTn3M5b5kkz7PnkqA2vn02mh/AiPOhhinugept/hQ/rwJiNxoUohJi22o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1vl7cg-0003ow-Nh; Wed, 28 Jan 2026 16:38:26 +0100 Received: from dude04.red.stw.pengutronix.de ([2a0a:edc0:0:1101:1d::ac] helo=dude04) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vl7cg-002wSZ-3A; Wed, 28 Jan 2026 16:38:26 +0100 Received: from ore by dude04 with local (Exim 4.98.2) (envelope-from ) id 1vl7cg-0000000FRAv-0oe3; Wed, 28 Jan 2026 16:38:26 +0100 From: Oleksij Rempel To: Jonathan Cameron , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: Oleksij Rempel , kernel@pengutronix.de, linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, Andy Shevchenko , David Lechner , =?UTF-8?q?Nuno=20S=C3=A1?= , David Jander Subject: [PATCH v3 8/8] iio: dac: ds4424: add Rfs-based scale and per-variant limits Date: Wed, 28 Jan 2026 16:38:24 +0100 Message-ID: <20260128153824.3679187-9-o.rempel@pengutronix.de> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260128153824.3679187-1-o.rempel@pengutronix.de> References: <20260128153824.3679187-1-o.rempel@pengutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ore@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Parse optional maxim,rfs-ohms values to derive the per-channel output current scale (mA per step) for the IIO current ABI. Select per-variant parameters to match the shared register map while handling different data widths and full-scale current calculations. Behavior changes: - If maxim,rfs-ohms is present, IIO_CHAN_INFO_SCALE becomes available and reports mA/step derived from Rfs. - If maxim,rfs-ohms is missing, SCALE is not exposed to keep older DTs working without requiring updates. - RAW writes are now limited to the representable sign-magnitude range of the detected variant to avoid silent truncation (e.g. +/-31 on DS440x). Signed-off-by: Oleksij Rempel Reviewed-by: Andy Shevchenko --- changes v3: - Added explicit check for negative return from device_property_count_u32(). - Rename vref_mv to vref_mV - Use devm_kmemdup_array() instead of devm_kmemdup() - Use %u for unsigned index in Rfs error logs. - Consolidated Rfs parse logs to a single line. changes v2: - Reorder struct ds4424_chip_info members to optimize padding. - Use GENMASK() for chip variant masks instead of hex constants. - Simplify ds4424_setup_channels: use direct devm_kmemdup to avoid stack usage and memcpy. - Use local 'dev' pointer and dev_err_probe() in ds4424_parse_rfs for cleaner error handling. - Rename the static iio_info struct to ds4424_iio_info to prevent name collision with the new hardware chip_info structs. - Use unsigned int for loop counters. - Rebase on top of regmap and symmetrical raw_access refactoring. --- drivers/iio/dac/ds4424.c | 121 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 116 insertions(+), 5 deletions(-) diff --git a/drivers/iio/dac/ds4424.c b/drivers/iio/dac/ds4424.c index 9bef1c60b2eb..2b01e20daee4 100644 --- a/drivers/iio/dac/ds4424.c +++ b/drivers/iio/dac/ds4424.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include =20 @@ -24,6 +25,7 @@ #define DS4424_MAX_DAC_CHANNELS 4 =20 #define DS4424_DAC_MASK GENMASK(6, 0) +#define DS4404_DAC_MASK GENMASK(4, 0) #define DS4424_DAC_SOURCE BIT(7) =20 #define DS4424_DAC_ADDR(chan) ((chan) + 0xf8) @@ -43,9 +45,38 @@ enum ds4424_device_ids { ID_DS4424, }; =20 +/* + * Two variant groups share the same register map but differ in: + * - resolution/data mask (DS4402/DS4404: 5-bit, DS4422/DS4424: 7-bit) + * - full-scale current calculation (different Vref and divider) + * Addressing also differs (DS440x tri-level, DS442x bi-level), but is + * handled via board configuration, not driver logic. + */ +struct ds4424_chip_info { + int vref_mV; + int scale_denom; + u8 result_mask; +}; + +static const struct ds4424_chip_info ds4424_info =3D { + .vref_mV =3D 976, + .scale_denom =3D 16, + .result_mask =3D DS4424_DAC_MASK, +}; + +/* DS4402 is handled like DS4404 (same resolution and scale formula). */ +static const struct ds4424_chip_info ds4404_info =3D { + .vref_mV =3D 1230, + .scale_denom =3D 4, + .result_mask =3D DS4404_DAC_MASK, +}; + struct ds4424_data { struct regmap *regmap; struct regulator *vcc_reg; + const struct ds4424_chip_info *chip_info; + u32 rfs_ohms[DS4424_MAX_DAC_CHANNELS]; + bool has_rfs; }; =20 static const struct iio_chan_spec ds4424_channels[] =3D { @@ -144,11 +175,20 @@ static int ds4424_read_raw(struct iio_dev *indio_dev, return ret; } =20 - *val =3D regval & DS4424_DAC_MASK; + *val =3D regval & data->chip_info->result_mask; if (!(regval & DS4424_DAC_SOURCE)) *val =3D -*val; =20 return IIO_VAL_INT; + case IIO_CHAN_INFO_SCALE: + if (!data->has_rfs) + return -EINVAL; + + /* SCALE is mA/step: mV / Ohm =3D mA. */ + *val =3D data->chip_info->vref_mV; + *val2 =3D data->rfs_ohms[chan->channel] * + data->chip_info->scale_denom; + return IIO_VAL_FRACTIONAL; =20 default: return -EINVAL; @@ -168,7 +208,7 @@ static int ds4424_write_raw(struct iio_dev *indio_dev, switch (mask) { case IIO_CHAN_INFO_RAW: abs_val =3D abs(val); - if (abs_val > DS4424_DAC_MASK) + if (abs_val > data->chip_info->result_mask) return -EINVAL; =20 /* @@ -187,6 +227,65 @@ static int ds4424_write_raw(struct iio_dev *indio_dev, } } =20 +static int ds4424_setup_channels(struct i2c_client *client, + struct ds4424_data *data, + struct iio_dev *indio_dev) +{ + struct iio_chan_spec *channels; + + /* Use a local non-const pointer for modification */ + channels =3D devm_kmemdup_array(&client->dev, ds4424_channels, + indio_dev->num_channels, + sizeof(ds4424_channels[0]), GFP_KERNEL); + if (!channels) + return -ENOMEM; + + if (data->has_rfs) { + for (unsigned int i =3D 0; i < indio_dev->num_channels; i++) + channels[i].info_mask_separate |=3D + BIT(IIO_CHAN_INFO_SCALE); + } + + indio_dev->channels =3D channels; + + return 0; +} + +static int ds4424_parse_rfs(struct i2c_client *client, + struct ds4424_data *data, + struct iio_dev *indio_dev) +{ + struct device *dev =3D &client->dev; + int count, ret; + + if (!device_property_present(dev, "maxim,rfs-ohms")) { + dev_info_once(dev, "maxim,rfs-ohms missing, scale not supported\n"); + return 0; + } + + count =3D device_property_count_u32(dev, "maxim,rfs-ohms"); + if (count < 0) + return dev_err_probe(dev, count, "Failed to count maxim,rfs-ohms entries= \n"); + if (count !=3D indio_dev->num_channels) + return dev_err_probe(dev, -EINVAL, "maxim,rfs-ohms must have %u entries\= n", + indio_dev->num_channels); + + ret =3D device_property_read_u32_array(dev, "maxim,rfs-ohms", + data->rfs_ohms, + indio_dev->num_channels); + if (ret) + return dev_err_probe(dev, ret, "Failed to read maxim,rfs-ohms property\n= "); + + for (unsigned int i =3D 0; i < indio_dev->num_channels; i++) { + if (!data->rfs_ohms[i]) + return dev_err_probe(dev, -EINVAL, "maxim,rfs-ohms entry %u is zero\n",= i); + } + + data->has_rfs =3D true; + + return 0; +} + static int ds4424_suspend(struct device *dev) { struct iio_dev *indio_dev =3D dev_get_drvdata(dev); @@ -221,7 +320,7 @@ static int ds4424_resume(struct device *dev) =20 static DEFINE_SIMPLE_DEV_PM_OPS(ds4424_pm_ops, ds4424_suspend, ds4424_resu= me); =20 -static const struct iio_info ds4424_info =3D { +static const struct iio_info ds4424_iio_info =3D { .read_raw =3D ds4424_read_raw, .write_raw =3D ds4424_write_raw, }; @@ -258,15 +357,20 @@ static int ds4424_probe(struct i2c_client *client) switch (id->driver_data) { case ID_DS4402: indio_dev->num_channels =3D DS4422_MAX_DAC_CHANNELS; + /* See ds4404_info comment above. */ + data->chip_info =3D &ds4404_info; break; case ID_DS4404: indio_dev->num_channels =3D DS4424_MAX_DAC_CHANNELS; + data->chip_info =3D &ds4404_info; break; case ID_DS4422: indio_dev->num_channels =3D DS4422_MAX_DAC_CHANNELS; + data->chip_info =3D &ds4424_info; break; case ID_DS4424: indio_dev->num_channels =3D DS4424_MAX_DAC_CHANNELS; + data->chip_info =3D &ds4424_info; break; default: dev_err(&client->dev, @@ -279,9 +383,16 @@ static int ds4424_probe(struct i2c_client *client) if (ret) goto fail; =20 - indio_dev->channels =3D ds4424_channels; + ret =3D ds4424_parse_rfs(client, data, indio_dev); + if (ret) + goto fail; + + ret =3D ds4424_setup_channels(client, data, indio_dev); + if (ret) + goto fail; + indio_dev->modes =3D INDIO_DIRECT_MODE; - indio_dev->info =3D &ds4424_info; + indio_dev->info =3D &ds4424_iio_info; =20 ret =3D iio_device_register(indio_dev); if (ret < 0) { --=20 2.47.3