From nobody Sun Feb 8 23:41:07 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 B332F395DA3 for ; Tue, 3 Feb 2026 09:34:37 +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=1770111281; cv=none; b=PflWZknmtjr1GcJd1/OdP1EGg0qCu6GcU2u5YWa9Ji+ByN+vYClAUYbkmQRCcQMuAWB9idOqHMgVBfXbbngc1olnZ9LUYHTCDS+utiTxkMX22lOaLL0WK9rrlHasPI+fdpnj1YOgXwmQC8DapbEvQq7nup+aVJJpAtIl2dE9tmA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770111281; c=relaxed/simple; bh=qCboVe1jx0nMNuIqVhOHA0NxWT5XKcf/52HDaAkhOlw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=baJxGIbRrSW0ywZn1anmk4YUF4wgXKZBgPyde6oMxTgd2pwZcjo3Hi/ZZ/x7sKUggYv/WFIrwGKl/ZHPc/L7obg13mAjKndh6oQTE5YfB/MJ/o6n/V6xFdsazG3Jf2T6EfewIfA85I7mN0FJkEd7FajB16fsOAy4uSnTMx2fb1c= 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 1vnCnr-0003lX-QA; Tue, 03 Feb 2026 10:34:35 +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 1vnCnr-003slN-2Z; Tue, 03 Feb 2026 10:34:35 +0100 Received: from ore by dude04 with local (Exim 4.98.2) (envelope-from ) id 1vnCnr-0000000Ah8n-0FPb; Tue, 03 Feb 2026 10:34:35 +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 v4 01/13] iio: dac: ds4424: reject -128 RAW value Date: Tue, 3 Feb 2026 10:34:21 +0100 Message-ID: <20260203093434.2548978-2-o.rempel@pengutronix.de> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260203093434.2548978-1-o.rempel@pengutronix.de> References: <20260203093434.2548978-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 in hardware (7-bit magnitude). Previously, passing -128 resulted in a truncated value that programmed 0mA (magnitude 0) instead of the expected maximum negative current, effectively failing silently. Reject -128 to avoid producing the wrong current. Fixes: d632a2bd8ffc ("iio: dac: ds4422/ds4424 dac driver") Cc: Signed-off-by: Oleksij Rempel --- changes v4: - Restore v1 implementation: Keep this patch as a minimal fix suitable for stable backports - Move the refactoring (bitwise operations and GENMASK usage) to a separate follow-up patch. changes v3: - (Merged into refactoring patch in v3, now split again) --- drivers/iio/dac/ds4424.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/iio/dac/ds4424.c b/drivers/iio/dac/ds4424.c index a8198ba4f98a..059acca45f64 100644 --- a/drivers/iio/dac/ds4424.c +++ b/drivers/iio/dac/ds4424.c @@ -141,7 +141,7 @@ static int ds4424_write_raw(struct iio_dev *indio_dev, =20 switch (mask) { case IIO_CHAN_INFO_RAW: - if (val < S8_MIN || val > S8_MAX) + if (val <=3D S8_MIN || val > S8_MAX) return -EINVAL; =20 if (val > 0) { --=20 2.47.3 From nobody Sun Feb 8 23:41:07 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 B28F73148C2 for ; Tue, 3 Feb 2026 09:34:37 +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=1770111281; cv=none; b=fA4WlsGNSdSZ4Y8Zd5dIONzQeIxq4Aqq9zWphUqY7Tuyo9YnQngOmEGKMO+i4xbJzZrj2ivl3MvRd3lHWc7x551EmN0L0SKY6jP7GhDPBRueWb4VL/03A5SGA7eePS3wyhhEs7OT2hCqBIGSrvI4GVW2UUk3KIjVpDSL47pe0Js= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770111281; c=relaxed/simple; bh=LNApek0UeIv8561bakOWYzQeuuZr30b4E0h9NsPKzFM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=n3xOKK38i5+1xYzFybQXP7N2Fwg2s7m/X531bZyboBRUhIZlNuM3vLYUsRytDkio0NBHLfNJmOR/EuToTYmt4QBN1cn/+xsDpQw5XNOYaRnbyarY0SV4q35Z23eWp/bipTVs5qGKGovdCcnBPeNBiPRLem0qTw3qjeChgsLP+/s= 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 1vnCnr-0003lY-QA; Tue, 03 Feb 2026 10:34:35 +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 1vnCnr-003slO-2f; Tue, 03 Feb 2026 10:34:35 +0100 Received: from ore by dude04 with local (Exim 4.98.2) (envelope-from ) id 1vnCnr-0000000Ah8x-0MCL; Tue, 03 Feb 2026 10:34:35 +0100 From: Oleksij Rempel To: Jonathan Cameron , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: Oleksij Rempel , Andy Shevchenko , 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 v4 02/13] iio: dac: ds4424: refactor raw access to use bitwise operations Date: Tue, 3 Feb 2026 10:34:22 +0100 Message-ID: <20260203093434.2548978-3-o.rempel@pengutronix.de> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260203093434.2548978-1-o.rempel@pengutronix.de> References: <20260203093434.2548978-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 raw access logic to use standard GENMASK() and BIT() macros. Use abs() for magnitude calculation to simplify the logic and make the data flow clearer. Signed-off-by: Oleksij Rempel Reviewed-by: Andy Shevchenko --- changes v4: - Split patch: The functional fix for -128 was moved to the previous patch (1/9) for stable backporting. - This patch now contains only the refactoring (GENMASK/BIT/abs) on top of the fix. 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 059acca45f64..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 <=3D 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 Sun Feb 8 23:41:07 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 B29A9392C2D for ; Tue, 3 Feb 2026 09:34:37 +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=1770111281; cv=none; b=k2tYzCS6iku0GKyCwzofhlCxPhCgSzByOuSNyqmVZeZpQA/ygWVYgIX0piWt5o3+up+ElMtmNhL9jPCwO8YceK18Egxho5Ks5jpareFI2rgO9uuXk8wx6J6qVyf/gPlo2nmlBRXLOtK0QwckpmDAQvRanBwpb9mxCM0SwmuyEc4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770111281; c=relaxed/simple; bh=O0EokgG+ZELOqsvWkD9XXW+m+o8FIHCBWzBKqvIvr1o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jeMvsZLBB34FNIotZ3CbDvQ7V3K/v4u+QQFAVw4jvP0UB5kUBVaV6XmmDcQBgl9QDctshBD0vDA/cY/LHuCeNXXVV49+kFG+bI9YJD3RB5qLdfW8BY7l3Srn3UePoWHtEm82fGZSz/eSYo7AKZnMr5BLAqXnvNMq96VsjLVuewY= 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 1vnCnr-0003lZ-Q9; Tue, 03 Feb 2026 10:34:35 +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 1vnCnr-003slP-2l; Tue, 03 Feb 2026 10:34:35 +0100 Received: from ore by dude04 with local (Exim 4.98.2) (envelope-from ) id 1vnCnr-0000000Ah97-0SP0; Tue, 03 Feb 2026 10:34:35 +0100 From: Oleksij Rempel To: Jonathan Cameron , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: Oleksij Rempel , Andy Shevchenko , 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 v4 03/13] iio: dac: ds4424: ratelimit read errors and use device context Date: Tue, 3 Feb 2026 10:34:23 +0100 Message-ID: <20260203093434.2548978-4-o.rempel@pengutronix.de> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260203093434.2548978-1-o.rempel@pengutronix.de> References: <20260203093434.2548978-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 v4: - no changes 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 Sun Feb 8 23:41:07 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 B24723128BE for ; Tue, 3 Feb 2026 09:34:37 +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=1770111281; cv=none; b=ppmKo33mLY0E7N3H/ze3RDrIUJFbjwQs9nGK5JgqEY8ITsD1vMWnu3CLPNlKQoJh6ig+zBhiEeEYcsXBiBmRgb5nXEBJ0fefksLAoH10aNk+DZW1dTxCFAnwViGYxODblGPEIq09O0mOJMPo49k+Sy6qvkGgnrMbSu/R4H439Kc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770111281; c=relaxed/simple; bh=+6YhG7phbK+WElAeA57nSgK9wBgYbaomoDmUpzkVf64=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=R/E4PVoRI2awfw08WFJgMbZgFyyRQWIOkd66OoMFep4lCMHibGvXxOzFWp7hymhXTMTVandMttjiLpDJ88aMJ8g+y0yDO9t6qv5P/jKoiHZfevRzCYA3yTT263ay8eO7sWZFJGslcawl2lyHrFK0uYpTD3EhumKAVv0AkRJx6xA= 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 1vnCnr-0003la-QA; Tue, 03 Feb 2026 10:34:35 +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 1vnCnr-003slR-2q; Tue, 03 Feb 2026 10:34:35 +0100 Received: from ore by dude04 with local (Exim 4.98.2) (envelope-from ) id 1vnCnr-0000000Ah9H-0Xpd; Tue, 03 Feb 2026 10:34:35 +0100 From: Oleksij Rempel To: Jonathan Cameron , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: Oleksij Rempel , Andy Shevchenko , 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 v4 04/13] iio: dac: ds4424: sort headers alphabetically Date: Tue, 3 Feb 2026 10:34:24 +0100 Message-ID: <20260203093434.2548978-5-o.rempel@pengutronix.de> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260203093434.2548978-1-o.rempel@pengutronix.de> References: <20260203093434.2548978-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 v4: - no changes 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 Sun Feb 8 23:41:07 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 B22CD312831 for ; Tue, 3 Feb 2026 09:34:37 +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=1770111281; cv=none; b=f+npV9diM7UUoAb+kZtMIG58PyaljBDlr3MzzLZAdWj7tH75rjG3NXygMXsV1TvFjmXpaM/nAsZRxhIRu/QCNavxFyCcFDJHXHVqbfa3aUEZCbcsaCwKEaZjMDXFjJ07QgOGLOXXEXnNixZjfhzcm1YXMHzg77ut8HXMAMTCVe8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770111281; c=relaxed/simple; bh=s7gzttavYRalNBWaV3Y5eMOcje/0ExAyLEKkNNtV2J0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IJ/Oyj+Vz3yAKTLNtJ9OVgD/V4KVyYFapoShXmP/mvhXnjYoJNxgkEcx/jwRsS5D3yuUk3mBUQ4aBf0IiyYf0x8MYARTbOz58V7l3AnlTck0NzbzYE/tnfXPlQkoOb5+kBHUGllmXFSxsxHdi9WrbxSDJzShNoeIPyR93ZvDWF0= 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 1vnCnr-0003lb-Q9; Tue, 03 Feb 2026 10:34:35 +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 1vnCnr-003slU-38; Tue, 03 Feb 2026 10:34:35 +0100 Received: from ore by dude04 with local (Exim 4.98.2) (envelope-from ) id 1vnCnr-0000000Ah9R-0d1C; Tue, 03 Feb 2026 10:34:35 +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 v4 05/13] iio: dac: ds4424: rename iio_info struct to avoid ambiguity Date: Tue, 3 Feb 2026 10:34:25 +0100 Message-ID: <20260203093434.2548978-6-o.rempel@pengutronix.de> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260203093434.2548978-1-o.rempel@pengutronix.de> References: <20260203093434.2548978-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" Rename the static `ds4424_info` structure to `ds4424_iio_info`. The previous name was generic and could be confused with chip-specific data structures (like the upcoming `ds4424_chip_info`). The new name explicitly indicates that this structure holds the IIO framework callbacks. Signed-off-by: Oleksij Rempel Reviewed-by: Andy Shevchenko --- changes v4: - New patch --- drivers/iio/dac/ds4424.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/iio/dac/ds4424.c b/drivers/iio/dac/ds4424.c index c03051dc763e..3385f39521d9 100644 --- a/drivers/iio/dac/ds4424.c +++ b/drivers/iio/dac/ds4424.c @@ -197,7 +197,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, }; @@ -252,7 +252,7 @@ static int ds4424_probe(struct i2c_client *client) =20 indio_dev->channels =3D ds4424_channels; 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 From nobody Sun Feb 8 23:41:07 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 B287C3148B4 for ; Tue, 3 Feb 2026 09:34:37 +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=1770111283; cv=none; b=Ix01QBvxEQUzODh/2hMUcaz6tTSq0bx1/V24iIS3StNiklKPEQn2Uj1os992YQgJT498A7ysZBSKaI+z0XG0fUTqZwP7Ag9BxCUjwX/QIsNhpIVpcfFMDrh7MAqY+k+i8kFviTjIHxh9QMc0aXEApE9RRvPx9jxb0XBplwoi6E8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770111283; c=relaxed/simple; bh=zwBYqkLNtbhXVbgrsrQaASQJCt7kvW7S2MFFwDgGVuw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bZJ35jG4hseZhCoXVsWLqMlDySTIdhnjcUJ1TeO85Ylc7VN9tpV9mX+lAmkDtGLgGqgoFis3hzRDNLee8olbj5VtnwFBRrGe0Y+xRdZqKfgBG2kUqfYbP6queAzyMLvHq6dmhihMUIq4d19DxEMTvupPCEGwxm0cDIgBzXkgbzA= 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 1vnCnr-0003lc-Q9; Tue, 03 Feb 2026 10:34:35 +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 1vnCnr-003slV-36; Tue, 03 Feb 2026 10:34:35 +0100 Received: from ore by dude04 with local (Exim 4.98.2) (envelope-from ) id 1vnCnr-0000000Ah9c-0icp; Tue, 03 Feb 2026 10:34:35 +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 v4 06/13] iio: dac: ds4424: use device match data for chip info Date: Tue, 3 Feb 2026 10:34:26 +0100 Message-ID: <20260203093434.2548978-7-o.rempel@pengutronix.de> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260203093434.2548978-1-o.rempel@pengutronix.de> References: <20260203093434.2548978-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 device match data instead of checking ID enums in a switch statement. Define a `ds4424_chip_info` structure to hold variant-specific attributes (currently just the channel count) and attach it directly to the I2C and OF device ID tables. Use `client->name` instead of `id->name` to decouple the probe function from the legacy `i2c_device_id` structure. This simplifies the probe function and makes it easier to add support for new variants like DS4402/DS4404. Signed-off-by: Oleksij Rempel --- changes v4: - New patch --- drivers/iio/dac/ds4424.c | 44 +++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/drivers/iio/dac/ds4424.c b/drivers/iio/dac/ds4424.c index 3385f39521d9..5709d8a39d7b 100644 --- a/drivers/iio/dac/ds4424.c +++ b/drivers/iio/dac/ds4424.c @@ -34,9 +34,16 @@ .info_mask_separate =3D BIT(IIO_CHAN_INFO_RAW), \ } =20 -enum ds4424_device_ids { - ID_DS4422, - ID_DS4424, +struct ds4424_chip_info { + u8 num_channels; +}; + +static const struct ds4424_chip_info ds4422_info =3D { + .num_channels =3D DS4422_MAX_DAC_CHANNELS, +}; + +static const struct ds4424_chip_info ds4424_info =3D { + .num_channels =3D DS4424_MAX_DAC_CHANNELS, }; =20 struct ds4424_data { @@ -204,11 +211,15 @@ static const struct iio_info ds4424_iio_info =3D { =20 static int ds4424_probe(struct i2c_client *client) { - const struct i2c_device_id *id =3D i2c_client_get_device_id(client); + const struct ds4424_chip_info *chip_info; struct ds4424_data *data; struct iio_dev *indio_dev; int ret; =20 + chip_info =3D i2c_get_match_data(client); + if (!chip_info) + return -ENODEV; + indio_dev =3D devm_iio_device_alloc(&client->dev, sizeof(*data)); if (!indio_dev) return -ENOMEM; @@ -216,7 +227,6 @@ static int ds4424_probe(struct i2c_client *client) 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"); if (IS_ERR(data->vcc_reg)) @@ -236,20 +246,8 @@ static int ds4424_probe(struct i2c_client *client) if (ret < 0) goto fail; =20 - switch (id->driver_data) { - case ID_DS4422: - indio_dev->num_channels =3D DS4422_MAX_DAC_CHANNELS; - break; - case ID_DS4424: - indio_dev->num_channels =3D DS4424_MAX_DAC_CHANNELS; - break; - default: - dev_err(&client->dev, - "ds4424: Invalid chip id.\n"); - ret =3D -ENXIO; - goto fail; - } - + indio_dev->name =3D client->name; + indio_dev->num_channels =3D chip_info->num_channels; indio_dev->channels =3D ds4424_channels; indio_dev->modes =3D INDIO_DIRECT_MODE; indio_dev->info =3D &ds4424_iio_info; @@ -278,16 +276,16 @@ static void ds4424_remove(struct i2c_client *client) } =20 static const struct i2c_device_id ds4424_id[] =3D { - { "ds4422", ID_DS4422 }, - { "ds4424", ID_DS4424 }, + { "ds4422", (kernel_ulong_t)&ds4422_info }, + { "ds4424", (kernel_ulong_t)&ds4424_info }, { } }; =20 MODULE_DEVICE_TABLE(i2c, ds4424_id); =20 static const struct of_device_id ds4424_of_match[] =3D { - { .compatible =3D "maxim,ds4422" }, - { .compatible =3D "maxim,ds4424" }, + { .compatible =3D "maxim,ds4422", .data =3D &ds4422_info }, + { .compatible =3D "maxim,ds4424", .data =3D &ds4424_info }, { } }; =20 --=20 2.47.3 From nobody Sun Feb 8 23:41:07 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 B21B7311C2D for ; Tue, 3 Feb 2026 09:34:37 +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=1770111281; cv=none; b=tlnXdrHcRA1UlxcO0/yvFr9zWmAg6rVF4EEhAVZSf78vj95KYEuRt22gZ483fEraw3t51ZobGLHN3l8369V4CUeaAHLO8pHuKnCQCBtMC31zm74eKv8RqbO/VunBHspLdTeztfyGlphzLzpldKybGoZNubtgZZpc5Nb5Gt8wU7s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770111281; c=relaxed/simple; bh=PIdksg1G07VqhZfWxWeVIPUH6eFQdZq3KZLVRtFrqR8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FkBtENAsJT8N+OyH2qKyHRjGxT2rWhR6zxMnnyRJClY1hNZVpzz1vy586RLKwBOV/cNl1iuD40Enklb0DiPiA1WZH9kEFxvh1rIukJvTKeWoGqR++zK2CWF+jKdxeT8XQZ6buSAslZs7gcS5alTTl4PAaL6SvJha4ofioG70gKA= 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 1vnCnr-0003ld-QA; Tue, 03 Feb 2026 10:34:35 +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 1vnCnr-003slY-31; Tue, 03 Feb 2026 10:34:35 +0100 Received: from ore by dude04 with local (Exim 4.98.2) (envelope-from ) id 1vnCnr-0000000Ah9n-0nsS; Tue, 03 Feb 2026 10:34:35 +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 v4 07/13] iio: dac: ds4424: use fsleep() instead of usleep_range() Date: Tue, 3 Feb 2026 10:34:27 +0100 Message-ID: <20260203093434.2548978-8-o.rempel@pengutronix.de> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260203093434.2548978-1-o.rempel@pengutronix.de> References: <20260203093434.2548978-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 DS4422/DS4424 and DS4402/DS4404 datasheets do not specify a minimum delay between power-up (POR) and the availability of the I2C interface. The driver previously used `usleep_range(1000, 1200)` to enforce a ~1ms delay. Replace this with `fsleep(1000)` to allow the kernel to select the most efficient sleep mechanism (usleep or msleep) while retaining the existing conservative delay to ensure device readiness. Signed-off-by: Oleksij Rempel Reviewed-by: Andy Shevchenko --- changes v4: - New patch --- drivers/iio/dac/ds4424.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/iio/dac/ds4424.c b/drivers/iio/dac/ds4424.c index 5709d8a39d7b..94803885d735 100644 --- a/drivers/iio/dac/ds4424.c +++ b/drivers/iio/dac/ds4424.c @@ -241,7 +241,13 @@ static int ds4424_probe(struct i2c_client *client) return ret; } =20 - usleep_range(1000, 1200); + /* + * The datasheet does not specify a power-up to I2C ready time. + * Maintain the existing conservative 1ms delay to ensure the + * device is ready for communication. + */ + fsleep(1000); + ret =3D ds4424_verify_chip(indio_dev); if (ret < 0) goto fail; --=20 2.47.3 From nobody Sun Feb 8 23:41:07 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 B1E04305E32 for ; Tue, 3 Feb 2026 09:34:37 +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=1770111280; cv=none; b=SqHRaJSZnpwtvq1zRLOFffk91Jkcg2Bs6lC5eKI0yP9AupP4xKH1U7AMhwyyp8dNvxIdKDBk+uzEx/mB48/TOJWa8KjBX3iC8GHCU7E6aQL4gxOyTBol7ZZOsHrXRHmaykdQe3VACZUopZHCEwpCYJ9aNtpUwkK0CBXHFgok+0I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770111280; c=relaxed/simple; bh=ilau8yL6huoGlzY1yLTbGIzny37UcmWhmrfY2LugRYA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Zcsv8kLNCSjZ6YTgPURtbIymEKdiiraLgqBcE8hhecmcJcKMj7jWCFGq9+a4BGEFb14HTt96vmDsWZjUoUBpZpC5gswJczxT0NIcBlwnpM9vFYl71fXLyhKIBjDVFS6Uf2inChwtY9QGRz0shDSZf5VTZfbTK5VopIs6+gh8s/c= 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 1vnCnr-0003lh-SG; Tue, 03 Feb 2026 10:34:35 +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 1vnCns-003sla-0I; Tue, 03 Feb 2026 10:34:35 +0100 Received: from ore by dude04 with local (Exim 4.98.2) (envelope-from ) id 1vnCnr-0000000Ah9x-0syV; Tue, 03 Feb 2026 10:34:35 +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 v4 08/13] dt-bindings: iio: dac: maxim,ds4424: add ds4402/ds4404 Date: Tue, 3 Feb 2026 10:34:28 +0100 Message-ID: <20260203093434.2548978-9-o.rempel@pengutronix.de> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260203093434.2548978-1-o.rempel@pengutronix.de> References: <20260203093434.2548978-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 --- 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 Sun Feb 8 23:41:07 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 B73FC31282C for ; Tue, 3 Feb 2026 09:34:39 +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=1770111282; cv=none; b=KvHjkbehUENr18VDUSDEmnYFtHLeyqWp4hjqThQN/qwmch9UNEAog/MMqsOH7ccD8sAkLH6FFt5oLFgakoyaGNj2SXGDdo7wi57OLJxvk2+XdDZJJ50K1YSBEEXz26eNiaxSb6lzmmSMJpWTLxelW53szltRRk3XQOkfQhcbBB0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770111282; c=relaxed/simple; bh=6Od/OPIyLMOb7BaP297IgCCSECC+i1WrnMbE7x5Br88=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LQBM7gXF/Q706jfshM9ROjofTJNPPKkswuFaw7leUIa4lHB6NX0ypyAXl9STyJvsE6X6gmOg7kXTFt7XkujrzPiQc9g+hmqwkEh3EL9vpuySaSLAIvv3cR+306InZMaXsDtOj8INUc8QGPvg/L5bQVtqhCR9vTh/A71o1Ok4TfY= 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 1vnCnr-0003le-Qe; Tue, 03 Feb 2026 10:34:35 +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 1vnCns-003slc-0B; Tue, 03 Feb 2026 10:34:35 +0100 Received: from ore by dude04 with local (Exim 4.98.2) (envelope-from ) id 1vnCnr-0000000AhA8-0y8k; Tue, 03 Feb 2026 10:34:35 +0100 From: Oleksij Rempel To: Jonathan Cameron , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: David Jander , Oleksij Rempel , Andy Shevchenko , 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 v4 09/13] iio: dac: ds4424: add DS4402/DS4404 device IDs Date: Tue, 3 Feb 2026 10:34:29 +0100 Message-ID: <20260203093434.2548978-10-o.rempel@pengutronix.de> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260203093434.2548978-1-o.rempel@pengutronix.de> References: <20260203093434.2548978-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 94803885d735..31dcf6632b58 100644 --- a/drivers/iio/dac/ds4424.c +++ b/drivers/iio/dac/ds4424.c @@ -38,6 +38,14 @@ struct ds4424_chip_info { u8 num_channels; }; =20 +static const struct ds4424_chip_info ds4402_info =3D { + .num_channels =3D DS4422_MAX_DAC_CHANNELS, +}; + +static const struct ds4424_chip_info ds4404_info =3D { + .num_channels =3D DS4424_MAX_DAC_CHANNELS, +}; + static const struct ds4424_chip_info ds4422_info =3D { .num_channels =3D DS4422_MAX_DAC_CHANNELS, }; @@ -282,6 +290,8 @@ static void ds4424_remove(struct i2c_client *client) } =20 static const struct i2c_device_id ds4424_id[] =3D { + { "ds4402", (kernel_ulong_t)&ds4402_info }, + { "ds4404", (kernel_ulong_t)&ds4404_info }, { "ds4422", (kernel_ulong_t)&ds4422_info }, { "ds4424", (kernel_ulong_t)&ds4424_info }, { } @@ -290,6 +300,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", .data =3D &ds4402_info }, + { .compatible =3D "maxim,ds4404", .data =3D &ds4404_info }, { .compatible =3D "maxim,ds4422", .data =3D &ds4422_info }, { .compatible =3D "maxim,ds4424", .data =3D &ds4424_info }, { } --=20 2.47.3 From nobody Sun Feb 8 23:41:07 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 B33F3396B76 for ; Tue, 3 Feb 2026 09:34:37 +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=1770111281; cv=none; b=Z1qlZT8OVCoR7QhT8TUKhoWMwil2uYB60rSTWyhfzm488828Bs/VUMzoVnxpXIolcufXX035uGzaRYIQVuDAZ70VzR/Xm6bB5MfiQfQXCysD7Ql7cUm2+kxLypoOUYpunL+MM9HXgXGpRWyzw+mwZ7Qyb3TgLA5WhhwKfTC2UHs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770111281; c=relaxed/simple; bh=Cv77hmMbLTpVDKjsQxYcJgHY1v9ruO+5hsF0i/QdGTI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BRLfwyqELCSKOoP2v9XipBJHDXHypkL7NFwgAXKZb8TIM76WIgDQXYLdtFSoWtQF8KXxT+7imvvja/+Pm1Q85k26M9cK9jWtzSmkprHSEKQfO4VtDGlhmF5dzIb2AqI2rAH6iRORqxAey8od8O2lE8nDaYuYfI/Yhl5rBrjVgHA= 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 1vnCnr-0003lf-Q9; Tue, 03 Feb 2026 10:34:35 +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 1vnCns-003sle-0L; Tue, 03 Feb 2026 10:34:35 +0100 Received: from ore by dude04 with local (Exim 4.98.2) (envelope-from ) id 1vnCnr-0000000AhAI-139M; Tue, 03 Feb 2026 10:34:35 +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 v4 10/13] iio: dac: ds4424: support per-variant output range limits Date: Tue, 3 Feb 2026 10:34:30 +0100 Message-ID: <20260203093434.2548978-11-o.rempel@pengutronix.de> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260203093434.2548978-1-o.rempel@pengutronix.de> References: <20260203093434.2548978-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 DS4402/DS4404 variants operate with a 5-bit resolution (31 steps), whereas the DS4422/DS4424 support 7-bit (127 steps). Previously, the driver enforced a hardcoded 7-bit mask (DS4424_DAC_MASK) for all variants. This allowed users to write values exceeding the 5-bit range to DS4402/DS4404 devices, resulting in silent truncation or undefined behavior. Add a `result_mask` field to the chip_info structure to define the valid data range for each variant. Use this mask to: 1. Correctly mask register values in read_raw(). 2. Return -EINVAL in write_raw() if the input value exceeds the variant's capabilities. Signed-off-by: Oleksij Rempel Reviewed-by: Andy Shevchenko --- changes v4: - New patch - Split from the original patch (v3) to isolate 5-bit vs 7-bit handling. --- drivers/iio/dac/ds4424.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/drivers/iio/dac/ds4424.c b/drivers/iio/dac/ds4424.c index 31dcf6632b58..43a622575cb5 100644 --- a/drivers/iio/dac/ds4424.c +++ b/drivers/iio/dac/ds4424.c @@ -22,6 +22,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) @@ -35,22 +36,27 @@ } =20 struct ds4424_chip_info { + u8 result_mask; u8 num_channels; }; =20 static const struct ds4424_chip_info ds4402_info =3D { + .result_mask =3D DS4404_DAC_MASK, .num_channels =3D DS4422_MAX_DAC_CHANNELS, }; =20 static const struct ds4424_chip_info ds4404_info =3D { + .result_mask =3D DS4404_DAC_MASK, .num_channels =3D DS4424_MAX_DAC_CHANNELS, }; =20 static const struct ds4424_chip_info ds4422_info =3D { + .result_mask =3D DS4424_DAC_MASK, .num_channels =3D DS4422_MAX_DAC_CHANNELS, }; =20 static const struct ds4424_chip_info ds4424_info =3D { + .result_mask =3D DS4424_DAC_MASK, .num_channels =3D DS4424_MAX_DAC_CHANNELS, }; =20 @@ -60,6 +66,7 @@ struct ds4424_data { uint8_t save[DS4424_MAX_DAC_CHANNELS]; struct regulator *vcc_reg; uint8_t raw[DS4424_MAX_DAC_CHANNELS]; + const struct ds4424_chip_info *chip_info; }; =20 static const struct iio_chan_spec ds4424_channels[] =3D { @@ -110,6 +117,7 @@ static int ds4424_read_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); int ret, regval; =20 switch (mask) { @@ -122,7 +130,7 @@ 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 @@ -137,6 +145,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) @@ -145,7 +154,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 /* @@ -235,6 +244,7 @@ static int ds4424_probe(struct i2c_client *client) data =3D iio_priv(indio_dev); i2c_set_clientdata(client, indio_dev); data->client =3D client; + data->chip_info =3D chip_info; =20 data->vcc_reg =3D devm_regulator_get(&client->dev, "vcc"); if (IS_ERR(data->vcc_reg)) --=20 2.47.3 From nobody Sun Feb 8 23:41:07 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 B31EF394465 for ; Tue, 3 Feb 2026 09:34:37 +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=1770111282; cv=none; b=ItMqH5fuLAeX3v7vLMVP1KKGraelZbPvI3oH6B2PMJ7SYyiUCk5lemASO8YTmI2wBnwTCbyNSMlaeMgeSzvO+zznDDO/aKtZ8RdZLDEqNyg8gFoKiHcssEQRcUN1CxNsLuojvG5BVxMb2f11gd1F7fdHc6E/Q1lQlBmwa6ivhig= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770111282; c=relaxed/simple; bh=h9OhDK3Tn0sl4nZmPazlqnOZL/eciAW3M/cQ9UK89I0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Cg9WbF6CMbF1QJcrkTANWbkCnigjb5WuOyQ+YJO0V/Z1Gq9Teqs4GgQUhUCw2d/4YYswBtrrjXfl/OiOhLxuRL+P6u4v9LOHJLwcJqbd/XFC5dxBhSxMertni+m+tRgCXbTGsCRdKK+Qk069vGzMpypnMkIc61CdzD3kMbChGZI= 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 1vnCnr-0003lj-WA; Tue, 03 Feb 2026 10:34:36 +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 1vnCns-003slf-0S; Tue, 03 Feb 2026 10:34:35 +0100 Received: from ore by dude04 with local (Exim 4.98.2) (envelope-from ) id 1vnCnr-0000000AhAT-18KC; Tue, 03 Feb 2026 10:34:35 +0100 From: Oleksij Rempel To: Jonathan Cameron , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: Oleksij Rempel , Sander Vanheule , 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 v4 11/13] iio: dac: ds4424: convert to regmap Date: Tue, 3 Feb 2026 10:34:31 +0100 Message-ID: <20260203093434.2548978-12-o.rempel@pengutronix.de> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260203093434.2548978-1-o.rempel@pengutronix.de> References: <20260203093434.2548978-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: Sander Vanheule Reviewed-by: Andy Shevchenko --- changes v4: - Split patch: Moved fsleep() conversion to a separate cleanup patch - Style fix: Add parentheses to function name in comments - Cleanup: Remove redundant comment in regmap_config - Fix typo: Change error message to "Failed to read hardware values" 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 | 162 +++++++++++++++++++++------------------ 2 files changed, 90 insertions(+), 73 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 43a622575cb5..d7ccf031b234 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 @@ -61,11 +63,8 @@ static const struct ds4424_chip_info ds4424_info =3D { }; =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]; const struct ds4424_chip_info *chip_info; }; =20 @@ -76,41 +75,72 @@ 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, +}; + +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, +}; + +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; + if (indio_dev->num_channels =3D=3D DS4424_MAX_DAC_CHANNELS) + regmap_config =3D &ds44x4_regmap_config; + else + regmap_config =3D &ds44x2_regmap_config; =20 - data->raw[chan->channel] =3D val; + 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"); =20 -fail: - mutex_unlock(&data->lock); - return ret; + /* + * 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 values\n"); + + return 0; } =20 static int ds4424_read_raw(struct iio_dev *indio_dev, @@ -118,11 +148,13 @@ static int ds4424_read_raw(struct iio_dev *indio_dev, int *val, int *val2, long mask) { struct ds4424_data *data =3D iio_priv(indio_dev); - int ret, regval; + 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", @@ -165,58 +197,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); @@ -243,7 +261,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; data->chip_info =3D chip_info; =20 data->vcc_reg =3D devm_regulator_get(&client->dev, "vcc"); @@ -251,7 +268,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, @@ -266,16 +282,16 @@ static int ds4424_probe(struct i2c_client *client) */ fsleep(1000); =20 - ret =3D ds4424_verify_chip(indio_dev); - if (ret < 0) - goto fail; - indio_dev->name =3D client->name; indio_dev->num_channels =3D chip_info->num_channels; indio_dev->channels =3D ds4424_channels; indio_dev->modes =3D INDIO_DIRECT_MODE; indio_dev->info =3D &ds4424_iio_info; =20 + ret =3D ds4424_init_regmap(client, indio_dev); + if (ret) + goto fail; + ret =3D iio_device_register(indio_dev); if (ret < 0) { dev_err(&client->dev, --=20 2.47.3 From nobody Sun Feb 8 23:41:07 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 B32A6395D96 for ; Tue, 3 Feb 2026 09:34:37 +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=1770111280; cv=none; b=mH2iJQ5HNrf2StsdVjTTbVIe0KUYL2PICVymPFTlPL36M8VA7Zfd3t4EtDAFL8uHG+ADO4l53BMG3fHyaZ50jcdXHVKN+SS93Wy9X2rPvOxhih7gqO6gnb3uRMTmoJUgwktvGATTWcOM/3/SbQqYspRG3UiD3YbPobCm092k7Sg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770111280; c=relaxed/simple; bh=I+KR3587GayMS9LYDAZmsoHVX1w+4QoBrKCV62DQFF8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fPzhtkcDVmsITpUBzQaUwWCdbWg7e9Mw9TbodVN8kFp50zA5t3v7znINgPkRisjmFZWPB3uY8redNp/XsKiGCXoe4tpuuUg9XgfUPb10IS9yyQxoO0SjfQoz1bEXqbv6qiPWm8wLl1CQSFE+r1vBQeT5B8p3wz9jFPc5shuYN38= 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 1vnCnr-0003lg-SL; Tue, 03 Feb 2026 10:34:35 +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 1vnCns-003slh-0J; Tue, 03 Feb 2026 10:34:35 +0100 Received: from ore by dude04 with local (Exim 4.98.2) (envelope-from ) id 1vnCnr-0000000AhAe-1DHG; Tue, 03 Feb 2026 10:34:35 +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 v4 12/13] dt-bindings: iio: dac: maxim,ds4424: add maxim,rfs-ohms property Date: Tue, 3 Feb 2026 10:34:32 +0100 Message-ID: <20260203093434.2548978-13-o.rempel@pengutronix.de> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260203093434.2548978-1-o.rempel@pengutronix.de> References: <20260203093434.2548978-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 --- 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 Sun Feb 8 23:41:07 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 B223A3126AB for ; Tue, 3 Feb 2026 09:34:37 +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=1770111281; cv=none; b=KfiFxdJF7UORoNyUySlSrqfO0JKmRIDLQTGj3ZHUpwO2PdcfruYJ5Lju5cOZDevlxrTO/jjtcAYAZRR5SZHz5PL8AaYpjc+G5pNJwC/j8r3vucIYTI7mawHb65iBoYOED75nP2BBEHIRo86YOZbDhJexouU6PSSjjx6DXtUwVXI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770111281; c=relaxed/simple; bh=rmjahTQPvSv9XFT3G+4DeZzcjyYHvnDAvMCOEXwXrn4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YxuzRYtBlY/N0Cb/CFRolRFZE8C0IEdCCVAajNMElcYfgoicFUGUPwSBP3bL8xlbzoWqkXEyf66tHkhteA0m9baVnVV4TsUgXoZXXJVR/m6/jeio5ggNN8lejOpgppTrn+DhAxWBm6Q+fIcjvEI+ATBjJG+2QEzejZWYKnXQJ0I= 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 1vnCnr-0003lo-S0; Tue, 03 Feb 2026 10:34:35 +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 1vnCns-003sli-0S; Tue, 03 Feb 2026 10:34:35 +0100 Received: from ore by dude04 with local (Exim 4.98.2) (envelope-from ) id 1vnCnr-0000000AhAo-1IEc; Tue, 03 Feb 2026 10:34:35 +0100 From: Oleksij Rempel To: Jonathan Cameron , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: Oleksij Rempel , Andy Shevchenko , 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 v4 13/13] iio: dac: ds4424: add Rfs-based scale and per-variant limits Date: Tue, 3 Feb 2026 10:34:33 +0100 Message-ID: <20260203093434.2548978-14-o.rempel@pengutronix.de> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260203093434.2548978-1-o.rempel@pengutronix.de> References: <20260203093434.2548978-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. 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. Signed-off-by: Oleksij Rempel Reviewed-by: Andy Shevchenko --- changes v4: - Split series: moved infrastructure and RAW limit fixes to a preceding pat= ch. - Replaced dynamic channel allocation (devm_kmemdup_array()) with static const arrays (ds4424_channels_with_scale) to handle the two states. - Removed log message when maxim,rfs-ohms is missing. 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 | 81 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 80 insertions(+), 1 deletion(-) diff --git a/drivers/iio/dac/ds4424.c b/drivers/iio/dac/ds4424.c index d7ccf031b234..e34a8c3fba87 100644 --- a/drivers/iio/dac/ds4424.c +++ b/drivers/iio/dac/ds4424.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include =20 @@ -37,27 +38,46 @@ .info_mask_separate =3D BIT(IIO_CHAN_INFO_RAW), \ } =20 +#define DS4424_CHANNEL_WITH_SCALE(chan) { \ + .type =3D IIO_CURRENT, \ + .indexed =3D 1, \ + .output =3D 1, \ + .channel =3D chan, \ + .info_mask_separate =3D BIT(IIO_CHAN_INFO_RAW) | \ + BIT(IIO_CHAN_INFO_SCALE), \ +} + struct ds4424_chip_info { + int vref_mV; + int scale_denom; u8 result_mask; u8 num_channels; }; =20 static const struct ds4424_chip_info ds4402_info =3D { + .vref_mV =3D 1230, + .scale_denom =3D 4, .result_mask =3D DS4404_DAC_MASK, .num_channels =3D DS4422_MAX_DAC_CHANNELS, }; =20 static const struct ds4424_chip_info ds4404_info =3D { + .vref_mV =3D 1230, + .scale_denom =3D 4, .result_mask =3D DS4404_DAC_MASK, .num_channels =3D DS4424_MAX_DAC_CHANNELS, }; =20 static const struct ds4424_chip_info ds4422_info =3D { + .vref_mV =3D 976, + .scale_denom =3D 16, .result_mask =3D DS4424_DAC_MASK, .num_channels =3D DS4422_MAX_DAC_CHANNELS, }; =20 static const struct ds4424_chip_info ds4424_info =3D { + .vref_mV =3D 976, + .scale_denom =3D 16, .result_mask =3D DS4424_DAC_MASK, .num_channels =3D DS4424_MAX_DAC_CHANNELS, }; @@ -66,6 +86,8 @@ 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 { @@ -75,6 +97,13 @@ static const struct iio_chan_spec ds4424_channels[] =3D { DS4424_CHANNEL(3), }; =20 +static const struct iio_chan_spec ds4424_channels_with_scale[] =3D { + DS4424_CHANNEL_WITH_SCALE(0), + DS4424_CHANNEL_WITH_SCALE(1), + DS4424_CHANNEL_WITH_SCALE(2), + DS4424_CHANNEL_WITH_SCALE(3), +}; + static const struct regmap_range ds44x2_ranges[] =3D { regmap_reg_range(DS4424_DAC_ADDR(0), DS4424_DAC_ADDR(1)), }; @@ -167,6 +196,15 @@ static int ds4424_read_raw(struct iio_dev *indio_dev, *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; @@ -205,6 +243,39 @@ static int ds4424_write_raw(struct iio_dev *indio_dev, } } =20 +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")) + 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); @@ -284,7 +355,6 @@ static int ds4424_probe(struct i2c_client *client) =20 indio_dev->name =3D client->name; indio_dev->num_channels =3D chip_info->num_channels; - indio_dev->channels =3D ds4424_channels; indio_dev->modes =3D INDIO_DIRECT_MODE; indio_dev->info =3D &ds4424_iio_info; =20 @@ -292,6 +362,15 @@ static int ds4424_probe(struct i2c_client *client) if (ret) goto fail; =20 + ret =3D ds4424_parse_rfs(client, data, indio_dev); + if (ret) + goto fail; + + if (data->has_rfs) + indio_dev->channels =3D ds4424_channels_with_scale; + else + indio_dev->channels =3D ds4424_channels; + ret =3D iio_device_register(indio_dev); if (ret < 0) { dev_err(&client->dev, --=20 2.47.3