* [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; 4+ 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] 4+ messages in thread
* Re: [PATCH] iio: dac: mcp47a1: Allow full-scale output
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ıç
[not found] ` <1788525776688344002.1788525776@tunakilic.com>
0 siblings, 2 replies; 4+ messages in thread
From: Joshua Crofts @ 2026-09-04 12:38 UTC (permalink / raw)
To: Tuna Kılıç
Cc: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
linux-iio, linux-kernel
Hi Tuna,
Thanks for the patch!
On Fri, 4 Sep 2026 12:25:17 +0000 (UTC)
Tuna Kılıç <tuna@tunakilic.com> wrote:
> 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>
> ---
This makes sense, I must've misread the datasheet...
Can I ask how this was found? Manual code analysis or AI?
--
Kind regards,
Joshua Crofts
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] iio: dac: mcp47a1: Allow full-scale output
2026-09-04 12:38 ` Joshua Crofts
@ 2026-09-04 12:51 ` Tuna Kılıç
[not found] ` <1788525776688344002.1788525776@tunakilic.com>
1 sibling, 0 replies; 4+ messages in thread
From: Tuna Kılıç @ 2026-09-04 12:51 UTC (permalink / raw)
To: Joshua Crofts
Cc: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
linux-iio, linux-kernel
On Fri, Sep 4, 2026 at 2:38 PM Joshua Crofts <joshua.crofts1@gmail.com> wrote:
> Can I ask how this was found? Manual code analysis or AI?
I noticed it while reviewing the driver's range handling and then
compared it with the MCP47A1 datasheet. AI was used as an aid during
the analysis, but I manually verified the datasheet values, in_range()
semantics, and the final patch before sending it.
I don't have MCP47A1 hardware available, so the testing was limited to
build and static checks.
Thanks,
Tuna
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] iio: dac: mcp47a1: Allow full-scale output
[not found] ` <1788525776688344002.1788525776@tunakilic.com>
@ 2026-09-04 13:03 ` Joshua Crofts
0 siblings, 0 replies; 4+ messages in thread
From: Joshua Crofts @ 2026-09-04 13:03 UTC (permalink / raw)
To: Tuna; +Cc: jic23, dlechner, nuno.sa, andy, linux-iio, linux-kernel
On Fri, 4 Sep 2026 12:43:04 +0000 (UTC)
"Tuna" <tuna@tunakilic.com> wrote:
> I noticed it while reviewing the driver's range handling and then compared it with the MCP47A1 datasheet. AI was used as an aid during the analysis, but I manually verified the datasheet values, in_range() semantics, and the final patch before sending it.
>
> I don't have MCP47A1 hardware available, so the testing was limited to build and static checks.
>
Okay, that's fine, I have the hardware so I will test it.
Also, please don't top-post (inline comments are preferred) and please
wrap your lines to ~75 characters.
Thanks.
--
Kind regards,
Joshua Crofts
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-09-04 13:03 UTC | newest]
Thread overview: 4+ 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ıç
[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