From nobody Sat Feb 7 06:54:18 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 E2E83329E5C for ; Tue, 27 Jan 2026 06:09:43 +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=1769494187; cv=none; b=T1NOPG66v9AWLMUB7NALxnuf3EcmGXUYfk9EhSJ9qic/NER9++irTuSt0NbnPzaB8OAJcvVILOpl4znTP3UQSxea41NOf3s0k4/IzqEbLLI5R4WnA0pnjjzuHGLrYBL4ytNEIIho3Qd/t+e2vauykwH1SrmbNWpy6hBtrY+sme0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769494187; c=relaxed/simple; bh=Vclby+W+AAqlLGtdB2m/yN+Rh2ygSLizK+DQhzh864Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JiLtrJyY6apmxn7ILXbPmDRK1Mpyo/doRE7dhY/zEbwAEMUaSmKcIoGsptgw86W6U7Ny5Zezew4bkHCaTGVsWZIUqmYyi5czBmGI3RzS+KZdeKZCvppZVXtAyZdF4IansyVK2x9zrUNkFNF3uZ6HkOjwYovIxkpXEuqHJkTwR3o= 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 1vkcGk-0003pX-0D; Tue, 27 Jan 2026 07:09:42 +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 1vkcGj-002hiI-2l; Tue, 27 Jan 2026 07:09:41 +0100 Received: from ore by dude04 with local (Exim 4.98.2) (envelope-from ) id 1vkcGj-0000000GQEj-0SV2; Tue, 27 Jan 2026 07:09:41 +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 v2 1/8] dt-bindings: iio: dac: maxim,ds4424: add ds4402/ds4404 Date: Tue, 27 Jan 2026 07:09:32 +0100 Message-ID: <20260127060939.3914006-2-o.rempel@pengutronix.de> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260127060939.3914006-1-o.rempel@pengutronix.de> References: <20260127060939.3914006-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 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 Sat Feb 7 06:54:18 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 E6C2C329E71 for ; Tue, 27 Jan 2026 06:09:43 +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=1769494188; cv=none; b=RO0pGtm2Vh10EOPIONEI02RcNdPTwi16dTCKy1zoAD19vj4sjhT8h9XUy5vFKWm7kY20UTjudHoX0PCvUVxzMP7YfoOFmLSIjOCC28D2xg5m0ZA+3/q57abaMYSjmu0vxFNVgfeMvzauith1+POjqgMBb4lVlLoVHVSyazdEK/Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769494188; c=relaxed/simple; bh=tlOEm1BPNblfpRZaqxme09QCM+gvLrWtWYFzJqX7T/o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Vaa+HRU/3/wNdoJ+0Vx2i0ACGMv7LkgI0kgJCsjhxdvPNFgBKX4jsTov9H4Bc30B2x2TKXd/+qybYwvBpO/JzIKEgf85gGtBb2SU8rNERyedPQ5bgQe8GZKKOf8C/kgWNgcsCpuwhbVtvzcw4B4CY7rLU63cEDhCtmf7RhfBiOg= 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 1vkcGk-0003pZ-0D; Tue, 27 Jan 2026 07:09:42 +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 1vkcGj-002hiJ-2s; Tue, 27 Jan 2026 07:09:41 +0100 Received: from ore by dude04 with local (Exim 4.98.2) (envelope-from ) id 1vkcGj-0000000GQEt-0aHo; Tue, 27 Jan 2026 07:09:41 +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 v2 2/8] dt-bindings: iio: dac: maxim,ds4424: add maxim,rfs-ohms property Date: Tue, 27 Jan 2026 07:09:33 +0100 Message-ID: <20260127060939.3914006-3-o.rempel@pengutronix.de> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260127060939.3914006-1-o.rempel@pengutronix.de> References: <20260127060939.3914006-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 --- 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 | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/Documentation/devicetree/bindings/iio/dac/maxim,ds4424.yaml b/= Documentation/devicetree/bindings/iio/dac/maxim,ds4424.yaml index efe63e6cb55d..400afd8771aa 100644 --- a/Documentation/devicetree/bindings/iio/dac/maxim,ds4424.yaml +++ b/Documentation/devicetree/bindings/iio/dac/maxim,ds4424.yaml @@ -27,9 +27,44 @@ 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. + - For DS44x2 (2 channels): 2 values required. + - For DS44x4 (4 channels): 4 values required. + Typical values range from 40000 (40 kOhm) to 160000 (160 kOhm). + required: - compatible - reg + - maxim,rfs-ohms + +allOf: + - if: + properties: + compatible: + contains: + enum: + - maxim,ds4402 + - maxim,ds4422 + then: + properties: + maxim,rfs-ohms: + minItems: 2 + maxItems: 2 + - if: + properties: + compatible: + contains: + enum: + - maxim,ds4404 + - maxim,ds4424 + then: + properties: + maxim,rfs-ohms: + minItems: 4 + maxItems: 4 =20 additionalProperties: false =20 @@ -43,6 +78,7 @@ examples: compatible =3D "maxim,ds4424"; reg =3D <0x10>; /* When A0, A1 pins are ground */ vcc-supply =3D <&vcc_3v3>; + maxim,rfs-ohms =3D <5100>, <5100>, <5100>, <5100>; }; }; ... --=20 2.47.3 From nobody Sat Feb 7 06:54:18 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 E8154329E77 for ; Tue, 27 Jan 2026 06:09:43 +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=1769494188; cv=none; b=Ybv5bjgi7shNJE4BJICT236lirUQeLqgcqkndDXBAKc1tVInbG4c2DdXv94XTz/sjq8Kg+RpHgBEOvlbyG3ozFmeZ7gNlVrLdEkDqDMq+ARu8Tkx2QoYaPbGFwUm/GssAimz6JYvfAhnZc1uI7oUqbBoyJI1/lUPW2xnmCFkhl0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769494188; c=relaxed/simple; bh=FgmAT561uv4OuDcGoVQH9E8QL+FuR3mXrkzMwJcAHlY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=S1m9Nn5SxWRqPhdKmwyMgFbq0iPYk11oiMfNYmEJv58K6w995ZOszsxiMNZytGvwolEHY6996gSqBeibLJME+0pmbGjEdTt4tt89juGQXlu6kOn7JqVnAEr2VnBUAI8sObQWdycIe07qTABxNtAvo+d7l+DnjRoRJElDc4kFGmY= 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 1vkcGk-0003pa-0A; Tue, 27 Jan 2026 07:09:42 +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 1vkcGj-002hiK-2w; Tue, 27 Jan 2026 07:09:41 +0100 Received: from ore by dude04 with local (Exim 4.98.2) (envelope-from ) id 1vkcGj-0000000GQF2-0gUX; Tue, 27 Jan 2026 07:09:41 +0100 From: Oleksij Rempel To: Jonathan Cameron , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: Oleksij Rempel , David Jander , 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 v2 3/8] iio: dac: ds4424: add DS4402/DS4404 device IDs Date: Tue, 27 Jan 2026 07:09:34 +0100 Message-ID: <20260127060939.3914006-4-o.rempel@pengutronix.de> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260127060939.3914006-1-o.rempel@pengutronix.de> References: <20260127060939.3914006-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 I2C/OF IDs for DS4402 and DS4404 and set the correct channel count. Follow-up changes add per-variant scaling based on external Rfs. Signed-off-by: David Jander Signed-off-by: Oleksij Rempel --- 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 a8198ba4f98a..072b7e6672cf 100644 --- a/drivers/iio/dac/ds4424.c +++ b/drivers/iio/dac/ds4424.c @@ -48,6 +48,8 @@ union ds4424_raw_data { }; =20 enum ds4424_device_ids { + ID_DS4402, + ID_DS4404, ID_DS4422, ID_DS4424, }; @@ -248,6 +250,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; @@ -289,6 +297,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 }, { } @@ -297,6 +307,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 Sat Feb 7 06:54:18 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 E2E012FD69E for ; Tue, 27 Jan 2026 06:09:43 +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=1769494187; cv=none; b=RDFUqS46VlrjdrnP5C6ybBLWwShqD1Nlv5cTB10PE/zZHIK5r/hwlALVWA3GMsvXxmGEUdyxDgHtl2z666F1fbRyAu8zHBqSNKxORKftf6w8sCFc3BtvMhnaIBHmZQaJMMRUtt/qvnSRtMPUImOg40+xGW/hBXzoYMyOAqc1g7Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769494187; c=relaxed/simple; bh=9Cz8ny6H8Kxen28oclTzgb9tYmjwRZ2qNY5FU7uS0G4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QBlydil4A7MKRyjlBDg4hpBbnuYmhfG/84B1XOl6iraKwSJIUodyaxcPFeGxo3ADMvl8EUmYngzx6WjyGnDwiuTiZptivcFFag4r4eMz8FgMYKBVAHQtEXGfyBx5sp2Zr7+uF31xu74e8PU+Ee8yFsXOl/BM7fQgA/UVPc90McI= 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 1vkcGk-0003pY-0E; Tue, 27 Jan 2026 07:09:42 +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 1vkcGj-002hiM-36; Tue, 27 Jan 2026 07:09:41 +0100 Received: from ore by dude04 with local (Exim 4.98.2) (envelope-from ) id 1vkcGj-0000000GQFD-0maB; Tue, 27 Jan 2026 07:09:41 +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 v2 4/8] iio: dac: ds4424: sort headers alphabetically Date: Tue, 27 Jan 2026 07:09:35 +0100 Message-ID: <20260127060939.3914006-5-o.rempel@pengutronix.de> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260127060939.3914006-1-o.rempel@pengutronix.de> References: <20260127060939.3914006-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. Signed-off-by: Oleksij Rempel --- changes v2: - new patch --- drivers/iio/dac/ds4424.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/iio/dac/ds4424.c b/drivers/iio/dac/ds4424.c index 072b7e6672cf..a4f00045f17b 100644 --- a/drivers/iio/dac/ds4424.c +++ b/drivers/iio/dac/ds4424.c @@ -5,16 +5,16 @@ * Copyright (C) 2017 Maxim Integrated */ =20 -#include -#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 Sat Feb 7 06:54:18 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 EC00F329E7A for ; Tue, 27 Jan 2026 06:09:43 +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=1769494186; cv=none; b=f7RaW8LGd6MjC0Jfz2YdGDYot+8S5mpbPTqRXrudIpcz81pJJwGzkAzIap7NqHw2vHBYFIQvDxi0y74UWMUuDHp92URRwE1koinmym0iSB85QKCxHq9ecSB9IHc9hD76DzQPba4pDp4+Rshp0WCeyWK/7LhRELeEo3/1Cx/AAJA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769494186; c=relaxed/simple; bh=3VAe1S+YoVFTzjAEeIIj6KaWPmcgZqLeu66mEbSENWI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=r9LIiiM1SgISZAMvfQjJuKZM4ey9LDfi+FUfsEi5sCV88M8JPgPoSf6o+H7lrDo0VRgspxS7RNxEUiLsywBlJJCRmXAM45JCpcQzAGS3oPHeFWXWGBeH1Tc/IWrEO16Z3Jym9APe2v/GLFMQlcik8d/VYjc9dfTBVygoKDP+4e8= 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 1vkcGk-0003pb-0D; Tue, 27 Jan 2026 07:09:42 +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 1vkcGj-002hiP-35; Tue, 27 Jan 2026 07:09:41 +0100 Received: from ore by dude04 with local (Exim 4.98.2) (envelope-from ) id 1vkcGj-0000000GQFN-0sCO; Tue, 27 Jan 2026 07:09:41 +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 v2 5/8] iio: dac: ds4424: convert to regmap Date: Tue, 27 Jan 2026 07:09:36 +0100 Message-ID: <20260127060939.3914006-6-o.rempel@pengutronix.de> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260127060939.3914006-1-o.rempel@pengutronix.de> References: <20260127060939.3914006-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 --- changes v2: - new patch --- drivers/iio/dac/Kconfig | 1 + drivers/iio/dac/ds4424.c | 163 +++++++++++++++++++++++---------------- 2 files changed, 96 insertions(+), 68 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 a4f00045f17b..f9ab7f4b97ff 100644 --- a/drivers/iio/dac/ds4424.c +++ b/drivers/iio/dac/ds4424.c @@ -14,6 +14,7 @@ #include #include #include +#include #include =20 #define DS4422_MAX_DAC_CHANNELS 2 @@ -55,11 +56,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 { @@ -69,59 +67,80 @@ 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_FLAT, + .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_FLAT, + .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); - int ret; + const struct regmap_config *regmap_config; =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; + 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) { + struct ds4424_data *data =3D iio_priv(indio_dev); union ds4424_raw_data raw; + 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) { - pr_err("%s : ds4424_get_value returned %d\n", - __func__, ret); + pr_err("%s : regmap_read returned %d\n", + __func__, ret); return ret; } - raw.bits =3D *val; + raw.bits =3D regval; *val =3D raw.dx; if (raw.source_bit =3D=3D DS4424_SINK_I) *val =3D -*val; @@ -136,6 +155,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); union ds4424_raw_data raw; =20 if (val2 !=3D 0) @@ -154,7 +174,8 @@ static int ds4424_write_raw(struct iio_dev *indio_dev, raw.dx =3D -val; } =20 - return ds4424_set_value(indio_dev, raw.bits, chan); + return regmap_write(data->regmap, DS4424_DAC_ADDR(chan->channel), + raw.bits); =20 default: return -EINVAL; @@ -163,49 +184,52 @@ static int ds4424_write_raw(struct iio_dev *indio_dev, =20 static int ds4424_verify_chip(struct iio_dev *indio_dev) { - int ret, val; + struct ds4424_data *data =3D iio_priv(indio_dev); + u8 raw_values[DS4424_MAX_DAC_CHANNELS]; + int ret; =20 - ret =3D ds4424_get_value(indio_dev, &val, 0); - if (ret < 0) - dev_err(&indio_dev->dev, - "%s failed. ret: %d\n", __func__, ret); + /* Bulk read all channels starting at 0xf8. + * This populates the regmap cache with current HW values. + */ + ret =3D regmap_bulk_read(data->regmap, DS4424_DAC_ADDR(0), + raw_values, indio_dev->num_channels); + if (ret) + return dev_err_probe(&indio_dev->dev, ret, "Failed to seed cache\n"); =20 - return ret; + return 0; } =20 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) + int ret; + + /* Disable all outputs, bypass cache so the '0' isn't saved */ + regcache_cache_bypass(data->regmap, true); + for (unsigned int i =3D 0; i < indio_dev->num_channels; i++) { + ret =3D regmap_write(data->regmap, DS4424_DAC_ADDR(i), 0); + if (ret) { + dev_err(dev, "Failed to zero channel %d: %d\n", i, ret); + regcache_cache_bypass(data->regmap, false); return ret; + } } - return ret; + regcache_cache_bypass(data->regmap, false); + + 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); @@ -228,7 +252,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"); @@ -236,7 +259,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, @@ -245,9 +267,6 @@ static int ds4424_probe(struct i2c_client *client) } =20 usleep_range(1000, 1200); - ret =3D ds4424_verify_chip(indio_dev); - if (ret < 0) - goto fail; =20 switch (id->driver_data) { case ID_DS4402: @@ -269,6 +288,14 @@ static int ds4424_probe(struct i2c_client *client) goto fail; } =20 + ret =3D ds4424_init_regmap(client, indio_dev); + if (ret < 0) + goto fail; + + ret =3D ds4424_verify_chip(indio_dev); + if (ret < 0) + 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 Sat Feb 7 06:54:18 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 F3D2D32A3C9 for ; Tue, 27 Jan 2026 06:09:43 +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=1769494188; cv=none; b=esE8uc3NQAw+IPceln3Qe2M31HZ77NqG/ass/Lm3e8tMwdP6KLMkwEKi6EE5daj1j3TGsUrk978vinRSgg5faMeAT2D6SQEM8h5Vsrq+upw4Jubx0MG0w5q2x0in5lNCMEl54CopEGlKjGd7Vic27b3cT2DSp/P4a53NjpV0lKo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769494188; c=relaxed/simple; bh=xsfl6CjRRGIj+atIrtIembJNz4raXcozsc4Yq786hY4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uINoH/mXtktoMYStn9a/DnUCJB+PDJbKnr+hKHUdeV6BP5HgeuwxlkpGpGH/+gEeg5kb6yrmHfOeZq6A5JLF9eDSHeGKduZzbUT0jBe7FpLHpPa3KIKoWgCI98GAXHTofnkI8UVgS6A0vBKTyeBycvayJbhvs6RsTmUbOlVxC5s= 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 1vkcGk-0003pc-0E; Tue, 27 Jan 2026 07:09:42 +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 1vkcGj-002hiR-38; Tue, 27 Jan 2026 07:09:41 +0100 Received: from ore by dude04 with local (Exim 4.98.2) (envelope-from ) id 1vkcGj-0000000GQFY-0y0s; Tue, 27 Jan 2026 07:09:41 +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 v2 6/8] iio: dac: ds4424: fix -128 rejection and refactor raw access Date: Tue, 27 Jan 2026 07:09:37 +0100 Message-ID: <20260127060939.3914006-7-o.rempel@pengutronix.de> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260127060939.3914006-1-o.rempel@pengutronix.de> References: <20260127060939.3914006-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 --- 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 | 50 +++++++++++++++------------------------- 1 file changed, 18 insertions(+), 32 deletions(-) diff --git a/drivers/iio/dac/ds4424.c b/drivers/iio/dac/ds4424.c index f9ab7f4b97ff..8110ca7f062f 100644 --- a/drivers/iio/dac/ds4424.c +++ b/drivers/iio/dac/ds4424.c @@ -20,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, \ @@ -32,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_DS4402, ID_DS4404, @@ -127,7 +112,6 @@ 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); - union ds4424_raw_data raw; unsigned int regval; int ret; =20 @@ -140,10 +124,11 @@ static int ds4424_read_raw(struct iio_dev *indio_dev, __func__, ret); return ret; } - raw.bits =3D regval; - *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: @@ -156,26 +141,27 @@ static int ds4424_write_raw(struct iio_dev *indio_dev, int val, int val2, long mask) { struct ds4424_data *data =3D iio_priv(indio_dev); - 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. + * Canonicalize 0 to sink; datasheet treats sign as don't-care. + */ + if (val > 0) + abs_val |=3D DS4424_DAC_SOURCE; =20 return regmap_write(data->regmap, DS4424_DAC_ADDR(chan->channel), - raw.bits); + abs_val); =20 default: return -EINVAL; --=20 2.47.3 From nobody Sat Feb 7 06:54:18 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 EFEA3329E7D for ; Tue, 27 Jan 2026 06:09:43 +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=1769494188; cv=none; b=do4zJgMXEc/1kYk7M7cihHY6EORZ4Fp0itV2aLSRcdbHWyxMXBuoy/3vk1SYEoTXoonBjyxpmxi1qf4Yc6lAJL/Z9IZ3m24UBkX3sAHaauNJfoU8ITsj9+ZUW9xaATU13eyL4vTqHMN/hSx5xgNkkF1B4gZUAGOv7R8ixDkYYBg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769494188; c=relaxed/simple; bh=ROeV3eFQ6wFSDgrK1HKXQAwS3oeqGxNJwHliijxFUnY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NfXAlEI7I2izN42idNIS9GkXuxzOCSU2LBy8wEq/cK4AfPXcnyncIEGRFxCnpSA3DdBNWPJo9Xl9gvy9yqtq7NZSqsoYsy/lRQdn30TLlXFg0L9cUcmLfXMcUDPEJxlWkX774XQB5SZ92r8A2ZH12HAAwbIXyiwY/mdrVdnARHA= 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 1vkcGk-0003pd-0E; Tue, 27 Jan 2026 07:09:42 +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 1vkcGk-002hiS-07; Tue, 27 Jan 2026 07:09:41 +0100 Received: from ore by dude04 with local (Exim 4.98.2) (envelope-from ) id 1vkcGj-0000000GQFj-13aU; Tue, 27 Jan 2026 07:09:41 +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 v2 7/8] iio: dac: ds4424: add Rfs-based scale and per-variant limits Date: Tue, 27 Jan 2026 07:09:38 +0100 Message-ID: <20260127060939.3914006-8-o.rempel@pengutronix.de> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260127060939.3914006-1-o.rempel@pengutronix.de> References: <20260127060939.3914006-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 --- 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 8110ca7f062f..891069d8c80a 100644 --- a/drivers/iio/dac/ds4424.c +++ b/drivers/iio/dac/ds4424.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include =20 @@ -21,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) @@ -40,9 +42,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 { @@ -125,11 +156,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; @@ -150,7 +190,7 @@ static int ds4424_write_raw(struct iio_dev *indio_dev, case IIO_CHAN_INFO_RAW: abs_val =3D abs(val); =20 - if (abs_val > DS4424_DAC_MASK) + if (abs_val > data->chip_info->result_mask) return -EINVAL; =20 /* @@ -185,6 +225,65 @@ static int ds4424_verify_chip(struct iio_dev *indio_de= v) return 0; } =20 +static int ds4424_setup_channels(struct i2c_client *client, + struct ds4424_data *data, + struct iio_dev *indio_dev) +{ + struct iio_chan_spec *channels; + size_t channels_size; + + channels_size =3D indio_dev->num_channels * sizeof(ds4424_channels[0]); + /* Use a local non-const pointer for modification */ + channels =3D devm_kmemdup(&client->dev, ds4424_channels, channels_size, + 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 !=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 %d 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); @@ -220,7 +319,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, }; @@ -257,15 +356,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, @@ -282,9 +386,16 @@ static int ds4424_probe(struct i2c_client *client) if (ret < 0) 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 From nobody Sat Feb 7 06:54:18 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 EE9E6329E7C for ; Tue, 27 Jan 2026 06:09:43 +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=1769494187; cv=none; b=eDBpYN/WRN9TFRLxm51iogX4JmFSiy3mxcV5MX93ld3u0dBo6V2itGnozSMkl+E8UPhGnyjKMRufwvrVAbiGvGUrCXt2yqnQBwc4j6tMLC+yUAqEh4kmZ24GhDaku4XNj/3ugAp3hlzWIEZNo2b55eTH6tvmtpsssLD3pb4wULI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769494187; c=relaxed/simple; bh=XnQBQO+ZVEObbuEfr2qwIdxGHlQ8ISURzS7cKxJRpko=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ktnNlDXMdQzbYhrQjL6wu3XMx7THPtd75fZjWe0gIwgpZRhXzIjRW1mrDEIif/tIotzrbDXQvb6N8ohaJ85ri2ea729vCXfT9jl5b1WiS2QzMgsAOw4YObHkBtWn0cXEm+QrEwtVho5X08lnrF9nLkNNRj3ySG8F8SrkIz6rTZU= 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 1vkcGk-0003pe-0E; Tue, 27 Jan 2026 07:09:42 +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 1vkcGk-002hiT-07; Tue, 27 Jan 2026 07:09:41 +0100 Received: from ore by dude04 with local (Exim 4.98.2) (envelope-from ) id 1vkcGj-0000000GQFt-18yd; Tue, 27 Jan 2026 07:09:41 +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 v2 8/8] iio: dac: ds4424: ratelimit read errors and use device context Date: Tue, 27 Jan 2026 07:09:39 +0100 Message-ID: <20260127060939.3914006-9-o.rempel@pengutronix.de> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260127060939.3914006-1-o.rempel@pengutronix.de> References: <20260127060939.3914006-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. Signed-off-by: Oleksij Rempel --- 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 891069d8c80a..3e762d4e84ef 100644 --- a/drivers/iio/dac/ds4424.c +++ b/drivers/iio/dac/ds4424.c @@ -151,8 +151,9 @@ static int ds4424_read_raw(struct iio_dev *indio_dev, ret =3D regmap_read(data->regmap, DS4424_DAC_ADDR(chan->channel), ®val); if (ret < 0) { - pr_err("%s : regmap_read returned %d\n", - __func__, ret); + dev_err_ratelimited(&indio_dev->dev, + "Failed to read channel %d: %pe\n", + chan->channel, ERR_PTR(ret)); return ret; } =20 --=20 2.47.3