Linux IIO development
 help / color / mirror / Atom feed
* [PATCH] iio: dac: mcp47a1: Allow full-scale output
@ 2026-09-04 12:25 Tuna Kılıç
  2026-09-04 12:38 ` Joshua Crofts
  0 siblings, 1 reply; 5+ messages in thread
From: Tuna Kılıç @ 2026-09-04 12:25 UTC (permalink / raw)
  To: Joshua Crofts, Jonathan Cameron
  Cc: David Lechner, Nuno Sá, Andy Shevchenko, linux-iio,
	linux-kernel

The MCP47A1 has 64 resistors but exposes 65 wiper positions. The valid
DAC codes are 0 through 64, and code 64 selects VREF.

The driver currently advertises 0 through 63 and uses 64 as the length
argument to in_range(), which also rejects 64. Therefore userspace
cannot select full-scale output.

Advertise code 64 and make validation cover all 65 codes. Keep 64 as
the scale denominator because the output voltage is VREF multiplied by
the code and divided by 64.

Fixes: 350d1fb9204b ("iio: dac: mcp47a1: add support for new device")
Signed-off-by: Tuna Kılıç <tuna@tunakilic.com>
---
 drivers/iio/dac/mcp47a1.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/iio/dac/mcp47a1.c b/drivers/iio/dac/mcp47a1.c
index 0bf994aa0e4..3ed306f3060 100644
--- a/drivers/iio/dac/mcp47a1.c
+++ b/drivers/iio/dac/mcp47a1.c
@@ -26,7 +26,7 @@ struct mcp47a1_data {
 	int vref_mV;
 };
 
-static const int mcp47a1_raw_avail[] = { 0, 1, MCP47A1_MAX_STEPS - 1 };
+static const int mcp47a1_raw_avail[] = { 0, 1, MCP47A1_MAX_STEPS };
 
 static const struct iio_chan_spec mcp47a1_channel = {
 	.type = IIO_VOLTAGE,
@@ -46,7 +46,7 @@ static int mcp47a1_write(struct iio_dev *indio_dev,
 
 	switch (mask) {
 	case IIO_CHAN_INFO_RAW:
-		if (!in_range(val, 0, MCP47A1_MAX_STEPS))
+		if (!in_range(val, 0, MCP47A1_MAX_STEPS + 1))
 			return -EINVAL;
 
 		return i2c_smbus_write_byte_data(data->client, MCP47A1_CMD_CODE,
-- 
2.55.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-09-06  3:54 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-04 12:25 [PATCH] iio: dac: mcp47a1: Allow full-scale output Tuna Kılıç
2026-09-04 12:38 ` Joshua Crofts
2026-09-04 12:51   ` Tuna Kılıç
2026-09-06  3:54     ` Jonathan Cameron
     [not found]   ` <1788525776688344002.1788525776@tunakilic.com>
2026-09-04 13:03     ` Joshua Crofts

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox