public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Sander Vanheule <sander@svanheule.net>
To: Oleksij Rempel <o.rempel@pengutronix.de>,
	Andy Shevchenko <andy@kernel.org>
Cc: "Jonathan Cameron" <jic23@kernel.org>,
	"Rob Herring" <robh@kernel.org>,
	"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
	"Conor Dooley" <conor+dt@kernel.org>,
	kernel@pengutronix.de, linux-kernel@vger.kernel.org,
	linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
	"David Lechner" <dlechner@baylibre.com>,
	"Nuno Sá" <nuno.sa@analog.com>,
	"David Jander" <david@protonic.nl>
Subject: Re: [PATCH v2 5/8] iio: dac: ds4424: convert to regmap
Date: Sun, 01 Feb 2026 18:24:19 +0100	[thread overview]
Message-ID: <abeabd28e8ed4cfdfdf12e9c59cdbdc545c00e42.camel@svanheule.net> (raw)
In-Reply-To: <aX98dbnCcFnFY3ks@pengutronix.de>

Hi Oleksij,

Thanks for the quick reply!

On Sun, 2026-02-01 at 17:16 +0100, Oleksij Rempel wrote:
> Hi Sander,
> 
> On Sun, Feb 01, 2026 at 03:42:28PM +0100, Sander Vanheule wrote:
> > Hi Oleksij,
> > 
> > On Tue, 2026-01-27 at 07:09 +0100, Oleksij Rempel wrote:
> > > +static const struct regmap_access_table ds44x4_table = {
> > > + .yes_ranges = ds44x4_ranges,
> > > + .n_yes_ranges = ARRAY_SIZE(ds44x4_ranges),
> > > +};
> > >  
> > > -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 = {
> > > + .reg_bits = 8,
> > > + .val_bits = 8,
> > > + .cache_type = REGCACHE_FLAT,
> > > + .max_register = DS4424_DAC_ADDR(1),
> > > + .rd_table = &ds44x2_table,
> > > + .wr_table = &ds44x2_table,
> > > +};
> > 
> > Note that REGCACHE_FLAT will allocate 0xF8 unsigned longs you will never
> > use.
> > REGCACHE_MAPLE will probably be much closer to the size of the original
> > value
> > cache, for a small look-up performance penalty (but always fast compared to
> > the
> > I2C bus).
> 
> ACK, already migrated to REGCACHE_MAPLE in the v3:
> https://lore.kernel.org/all/20260128153824.3679187-8-o.rempel@pengutronix.de/

Thanks for the link. I'm not on the IIO list, so I hadn't seen this version yet.

> Which works mostly fine except of the cache initialisation. If I use
> num_reg_defaults_raw with REGCACHE_MAPLE as proposed by Andy
> Shevchenko, first access to regmap values over debugfs will explode with
> NULL pointer etc...
> If I remove num_reg_defaults_raw, I need to read register manually
> to init defaul values as implemented in v3.

num_reg_defaults_raw without a raw register value buffer is also problematic
IMHO. If it is used without a buffer, values will be read from hardware. This is
indeed widely used to prime a (flat) cache, but if you want to maintain the
documented behavior of regmap_sync() it should only be used if the hardware
really just came out of reset.

Not sure how likely it is that not all channels values are written after probe,
but for this driver specifically you might see:

   1. Driver probes with num_reg_defaults_raw, using current HW values as
      initial cache _and_ register defaults.
   2. No updates were written before device is suspended. DAC registers are set
      to 0, cache marked dirty.
   3. No updates were written before device comes out of suspend and
      regmap_sync() is called. regmap_sync() sees a cache state which is still
      identical to the register defaults and omits (all) writes.

After 3. your device is considered online again, but the HW registers are still
set to 0 and your cache is out-of-sync.

This also made me realize you do want to read all the channels at some point to
be able to resume to the same state after suspending.


> The REGCACHE_FLAT has one more problem, the cache will be inited with
> i2c NACKs (0xFF) if used with num_reg_defaults_raw.

That's rather nasty. I don't suppose you investigated why that's happening? (not
saying you should, just wondering)

Best,
Sander

  reply	other threads:[~2026-02-01 17:24 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-27  6:09 [PATCH v2 0/8] iio: dac: ds4424: add DS4402/DS4404 support and scale Oleksij Rempel
2026-01-27  6:09 ` [PATCH v2 1/8] dt-bindings: iio: dac: maxim,ds4424: add ds4402/ds4404 Oleksij Rempel
2026-01-27  6:09 ` [PATCH v2 2/8] dt-bindings: iio: dac: maxim,ds4424: add maxim,rfs-ohms property Oleksij Rempel
2026-01-27 19:49   ` Conor Dooley
2026-01-27 19:55     ` Conor Dooley
2026-01-28  8:01       ` David Jander
2026-01-28 17:00         ` Conor Dooley
2026-01-27  6:09 ` [PATCH v2 3/8] iio: dac: ds4424: add DS4402/DS4404 device IDs Oleksij Rempel
2026-01-27 10:27   ` Andy Shevchenko
2026-01-27  6:09 ` [PATCH v2 4/8] iio: dac: ds4424: sort headers alphabetically Oleksij Rempel
2026-01-27 10:30   ` Andy Shevchenko
2026-01-27  6:09 ` [PATCH v2 5/8] iio: dac: ds4424: convert to regmap Oleksij Rempel
2026-01-27 10:39   ` Andy Shevchenko
2026-02-01 14:42   ` Sander Vanheule
2026-02-01 16:16     ` Oleksij Rempel
2026-02-01 17:24       ` Sander Vanheule [this message]
2026-02-03 10:10       ` Andy Shevchenko
2026-02-03 10:13         ` Andy Shevchenko
2026-01-27  6:09 ` [PATCH v2 6/8] iio: dac: ds4424: fix -128 rejection and refactor raw access Oleksij Rempel
2026-01-27 10:42   ` Andy Shevchenko
2026-01-27 10:49     ` Oleksij Rempel
2026-01-27 10:51       ` Andy Shevchenko
2026-01-27  6:09 ` [PATCH v2 7/8] iio: dac: ds4424: add Rfs-based scale and per-variant limits Oleksij Rempel
2026-01-27 10:46   ` Andy Shevchenko
2026-01-27  6:09 ` [PATCH v2 8/8] iio: dac: ds4424: ratelimit read errors and use device context Oleksij Rempel
2026-01-27 10:47   ` Andy Shevchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=abeabd28e8ed4cfdfdf12e9c59cdbdc545c00e42.camel@svanheule.net \
    --to=sander@svanheule.net \
    --cc=andy@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=david@protonic.nl \
    --cc=devicetree@vger.kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=jic23@kernel.org \
    --cc=kernel@pengutronix.de \
    --cc=krzk+dt@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nuno.sa@analog.com \
    --cc=o.rempel@pengutronix.de \
    --cc=robh@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox