* [PATCH] iio: dac: mcp4725: Update the cached DAC value only on success
@ 2026-10-25 14:13 Baek Kyu, Kim
2026-10-25 21:08 ` Andy Shevchenko
0 siblings, 1 reply; 3+ messages in thread
From: Baek Kyu, Kim @ 2026-10-25 14:13 UTC (permalink / raw)
To: Jonathan Cameron
Cc: linux-iio, linux-kernel, David Lechner, Nuno Sá, Andy Shevchenko
mcp4725_write_raw() updates dac_value even if mcp4725_set_value() rejects
the requested value or reports an I2C transfer error. After writing 1000,
a rejected write of 4096 returns -EINVAL without an I2C transfer, but
out_voltage0_raw reports 4096. A later powerdown exit sends 00 00 instead
of the 03 e8 frame for the last successful value. The EEPROM store path
uses the same cache.
Return the setter error before updating dac_value. This keeps the last
successful software value for readback, powerdown exit and EEPROM writes.
Signed-off-by: Baek Kyu, Kim <pocj8ur4in@gmail.com>
---
Tested on ARM64 QEMU/KVM with emulated I2C peers through the MCP4725
and MCP4726 sysfs paths. After setting 1000, a rejected write of 4096
returned -EINVAL without a transfer. The baseline readback changed to
4096 and powerdown exit sent 00 00; the patch kept 1000 and sent 03 e8.
All 202 assertions passed with the patch; 40 failed on the baseline.
No physical DAC or persistent EEPROM was tested.
drivers/iio/dac/mcp4725.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/iio/dac/mcp4725.c b/drivers/iio/dac/mcp4725.c
index 3fa7acc69aeb..94d51af83042 100644
--- a/drivers/iio/dac/mcp4725.c
+++ b/drivers/iio/dac/mcp4725.c
@@ -356,6 +356,8 @@ static int mcp4725_write_raw(struct iio_dev *indio_dev,
switch (mask) {
case IIO_CHAN_INFO_RAW:
ret = mcp4725_set_value(indio_dev, val);
+ if (ret)
+ return ret;
data->dac_value = val;
break;
default:
--
2.55.0
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] iio: dac: mcp4725: Update the cached DAC value only on success
2026-10-25 14:13 [PATCH] iio: dac: mcp4725: Update the cached DAC value only on success Baek Kyu, Kim
@ 2026-10-25 21:08 ` Andy Shevchenko
2026-10-25 22:31 ` Jonathan Cameron
0 siblings, 1 reply; 3+ messages in thread
From: Andy Shevchenko @ 2026-10-25 21:08 UTC (permalink / raw)
To: Baek Kyu, Kim
Cc: Jonathan Cameron, linux-iio, linux-kernel, David Lechner,
Nuno Sá,
Andy Shevchenko
On Sun, Oct 25, 2026 at 11:13:51PM +0900, Baek Kyu, Kim wrote:
> mcp4725_write_raw() updates dac_value even if mcp4725_set_value() rejects
> the requested value or reports an I2C transfer error. After writing 1000,
> a rejected write of 4096 returns -EINVAL without an I2C transfer, but
> out_voltage0_raw reports 4096. A later powerdown exit sends 00 00 instead
> of the 03 e8 frame for the last successful value. The EEPROM store path
> uses the same cache.
>
> Return the setter error before updating dac_value. This keeps the last
> successful software value for readback, powerdown exit and EEPROM writes.
Does it need a Fixes tag?
> Signed-off-by: Baek Kyu, Kim <pocj8ur4in@gmail.com>
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] iio: dac: mcp4725: Update the cached DAC value only on success
2026-10-25 21:08 ` Andy Shevchenko
@ 2026-10-25 22:31 ` Jonathan Cameron
0 siblings, 0 replies; 3+ messages in thread
From: Jonathan Cameron @ 2026-10-25 22:31 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Baek Kyu, Kim, linux-iio, linux-kernel, David Lechner,
Nuno Sá,
Andy Shevchenko
On Sun, 25 Oct 2026 23:08:50 +0200
Andy Shevchenko <andriy.shevchenko@intel.com> wrote:
> On Sun, Oct 25, 2026 at 11:13:51PM +0900, Baek Kyu, Kim wrote:
> > mcp4725_write_raw() updates dac_value even if mcp4725_set_value() rejects
> > the requested value or reports an I2C transfer error. After writing 1000,
> > a rejected write of 4096 returns -EINVAL without an I2C transfer, but
> > out_voltage0_raw reports 4096. A later powerdown exit sends 00 00 instead
> > of the 03 e8 frame for the last successful value. The EEPROM store path
> > uses the same cache.
> >
> > Return the setter error before updating dac_value. This keeps the last
> > successful software value for readback, powerdown exit and EEPROM writes.
>
> Does it need a Fixes tag?
Yes. Given I wanted to reduce outstanding patches, I added it an applied
to the fixes-togreg branch of iio.git
This goes all the way back to 2012 introduction of the driver.
Fixes: cf35ad61aca2 ("iio: add mcp4725 I2C DAC driver")
>
> > Signed-off-by: Baek Kyu, Kim <pocj8ur4in@gmail.com>
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-10-25 22:31 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-25 14:13 [PATCH] iio: dac: mcp4725: Update the cached DAC value only on success Baek Kyu, Kim
2026-10-25 21:08 ` Andy Shevchenko
2026-10-25 22:31 ` Jonathan Cameron
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®