Re: [RFC] regmap: allow volatile register writes with cached only read maps

From: Jorge Ramirez-Ortiz
Date: Wed May 09 2018 - 07:49:31 EST


On 05/09/2018 10:39 AM, Mark Brown wrote:
On Wed, May 09, 2018 at 12:06:09AM +0200, Jorge Ramirez-Ortiz wrote:
Regmap only allows volatile access to registers when the client
supports both reads and writes.

This commit bypasses that limitation and enables volatile writes to
selected registers while maintaining cached accesses on all reads. For
this, the client does not need to configure the reg_read callback.
I don't understand what voltile access means for write only devices.
Volatile means that we don't read the cache but go direct to the
hardware so if we can't read the hardware that's pretty redundant, a
volatile read that goes to the cache is just a default read.

oops, sorry will try to be a bit more clear with an example.

This patch tries to support a map that provides:

1. only cached reads: (as a consequence every regmap write must succeed).
2. cached writes: do not access the hardware unless the value differs from what is in the cache already or (3) applies.
3. support for selectable volatile writes: those that will always access the device no matter what the cache holds.

Something like this:

static const struct regmap_config foo_regmap = {
    .reg_write        = foo_write_reg,

    .reg_bits        = 32,
    .val_bits        = 32,
    .reg_stride        = 1,

    .volatile_reg        = foo_volatile_reg,

    .max_register        = CODEC_ENABLE_DEBUG_CTRL_REG,
    .reg_defaults        = foo_reg_defaults,
    .num_reg_defaults    = ARRAY_SIZE(foo_reg_defaults),
    .cache_type        = REGCACHE_RBTREE,
};


I dont think - I could be wrong- that this is something that we can support today since the current code seems to require that the regmap is readable (ie, that it implements reg_read).
But it could also be that I am missing something in my config? This is why I sent an RFC instead of a PATCH, because I am not 100% sure that I am not missing something.