Re: [PATCH V2 1/4] regmap: cache: Add "was_reset" argument to regcache_sync_region()

From: Mark Brown
Date: Sat Apr 25 2015 - 07:33:01 EST


On Fri, Apr 24, 2015 at 03:36:45PM -0700, Kevin Cernekee wrote:

> index 116655d92269..ece122a6fdeb 100644
> --- a/include/linux/regmap.h
> +++ b/include/linux/regmap.h
> @@ -438,7 +438,7 @@ bool regmap_can_raw_write(struct regmap *map);
>
> int regcache_sync(struct regmap *map);
> int regcache_sync_region(struct regmap *map, unsigned int min,
> - unsigned int max);
> + unsigned int max, bool was_reset);

This seems pretty ugly - both the fact that we're changing the signature
of the function and the naming of the argument feel inelegant. The
point isn't if the device has been reset, the point is if the device
currently has the default register values or not, and this means that
the user is responsible for tracking that state until the next time it
does the sync. That may be immediately like in your case but there's no
reason that has to be the case. The fact that we're passing in
something called "is_reset" which sounds like a state value for the
register map is a bit of a warning sign here.

What we should be doing here is providing a way for users to tell regmap
if they've reset the register map and actually we already have that
interface, it's just not got the best name - regcache_mark_dirty() is
effectively it since there's really not a lot of other reasons why a
driver would need to mark the cache as dirty. We're just not handling
it properly. What we should do instead is to keep the interface as it
is for now and make it behave in a more expected fashion so that if the
cache is explicitly marked dirty we assume that the hardware is in the
default state and otherwise we don't.

Ideally what we'd do is both improve the naming of mark_dirty() (though
that's API churn which is nasty) and arrange for rbtree to cache the
default values lazily, that way the only things in the cache will be
things that have been explicitly changed (we will still want default
checking but it makes life easier and means we don't end up having to do
a full writeout for cases where things have been put into cache mode
without a reset).

Attachment: signature.asc
Description: Digital signature