Skip to content

Commit

Permalink
Support regmap_update_bits*() stuff
Browse files Browse the repository at this point in the history
Signed-off-by: Takashi Iwai <tiwai@suse.de>
  • Loading branch information
tiwai committed May 7, 2020
1 parent 945461c commit 8241946
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
6 changes: 6 additions & 0 deletions include/linux/regmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,10 @@ void regcache_cache_only(struct regmap *map, bool enable);
void regcache_cache_bypass(struct regmap *map, bool enable);
void regcache_mark_dirty(struct regmap *map);

int regmap_update_bits(struct regmap *map, unsigned int reg,
unsigned int mask, unsigned int val);
int regmap_update_bits_check(struct regmap *map, unsigned int reg,
unsigned int mask, unsigned int val,
bool *change);

#endif /* __LINUX_REGMAP_H */
1 change: 1 addition & 0 deletions include/wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ typedef unsigned int uuid_le;
#define __user
#define __bitwise
#define __iomem
#define __must_check

#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))

Expand Down
31 changes: 31 additions & 0 deletions lib/hdac_regmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,3 +183,34 @@ void regcache_mark_dirty(struct regmap *map)
map->cache_dirty = true;
}

int regmap_update_bits(struct regmap *map, unsigned int reg,
unsigned int mask, unsigned int val)
{
return regmap_update_bits_check(map, reg, mask, val, NULL);
}

int regmap_update_bits_check(struct regmap *map, unsigned int reg,
unsigned int mask, unsigned int val,
bool *change)
{
unsigned int tmp, orig;
int ret;

if (change)
*change = false;

ret = map->config->reg_read(map->bus_context, reg, &orig);
if (ret != 0)
return ret;

tmp = orig & ~mask;
tmp |= val & mask;

if (tmp != orig) {
ret = map->config->reg_write(map->bus_context, reg, tmp);
if (ret == 0 && change)
*change = true;
}

return ret;
}

0 comments on commit 8241946

Please sign in to comment.