From nobody Wed Feb 11 02:33:35 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 88A5C341AB1 for ; Tue, 10 Feb 2026 13:51:15 +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=1770731478; cv=none; b=txTBeAI0R50PaPKBiLN9lWd5D8di3QYRP3wrjYC2RMsu67u/p+K/mxvXOf1+Ha9yYPpy4ClDM6McqUXyZW3XMBbW4X7n4Nbwjwo7kVNb8BP9Fz2gLA17vIPNdBrwZtkZNm/lIqxJr5VlEh7hfPpEeupqw3sF/nI8pwndcCrMFiE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770731478; c=relaxed/simple; bh=thQFYrehlflnzoIUmGK6mMLizKsqQA7Qp/k5KFQIaMg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=swVDmn5onTtyRzIk8LrA040SYHs1HQUsPBIYJ3D3qgMV/HNChltPZwlMKHZqTJHWtAApOJTpmqVenRpDj6n5MrKHeQndpERUpJfzXm/s1tsrSH3FTsXRiZGlgeHR/f+zv7pip77jX7QDQ1k6Su6UaMjccpf33/Z521W05m9yRbc= 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 1vpo93-0005dN-HY; Tue, 10 Feb 2026 14:51:13 +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 1vpo92-0005dD-0m; Tue, 10 Feb 2026 14:51:12 +0100 Received: from ore by dude04 with local (Exim 4.98.2) (envelope-from ) id 1vpo92-00000008VOX-3kjo; Tue, 10 Feb 2026 14:51:12 +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 v6 09/12] iio: dac: ds4424: support per-variant output range limits Date: Tue, 10 Feb 2026 14:51:07 +0100 Message-ID: <20260210135110.2027073-10-o.rempel@pengutronix.de> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260210135110.2027073-1-o.rempel@pengutronix.de> References: <20260210135110.2027073-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 v6: - no changes changes v5: - add Reviewed-by: Andy .. 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 20031639e753..3560b151192b 100644 --- a/drivers/iio/dac/ds4424.c +++ b/drivers/iio/dac/ds4424.c @@ -23,6 +23,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) @@ -37,26 +38,31 @@ =20 struct ds4424_chip_info { const char *name; + u8 result_mask; u8 num_channels; }; =20 static const struct ds4424_chip_info ds4402_info =3D { .name =3D "ds4402", + .result_mask =3D DS4404_DAC_MASK, .num_channels =3D DS4422_MAX_DAC_CHANNELS, }; =20 static const struct ds4424_chip_info ds4404_info =3D { .name =3D "ds4404", + .result_mask =3D DS4404_DAC_MASK, .num_channels =3D DS4424_MAX_DAC_CHANNELS, }; =20 static const struct ds4424_chip_info ds4422_info =3D { .name =3D "ds4422", + .result_mask =3D DS4424_DAC_MASK, .num_channels =3D DS4422_MAX_DAC_CHANNELS, }; =20 static const struct ds4424_chip_info ds4424_info =3D { .name =3D "ds4424", + .result_mask =3D DS4424_DAC_MASK, .num_channels =3D DS4424_MAX_DAC_CHANNELS, }; =20 @@ -66,6 +72,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 { @@ -116,6 +123,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) { @@ -128,7 +136,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 @@ -143,6 +151,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) @@ -151,7 +160,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 /* @@ -242,6 +251,7 @@ static int ds4424_probe(struct i2c_client *client) i2c_set_clientdata(client, indio_dev); data->client =3D client; indio_dev->name =3D chip_info->name; + 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