9
0
Fork 0

regmap: Add regmap_write_bits() function

Add code implementing a simple version of regmap_write_bits().

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This commit is contained in:
Andrey Smirnov 2016-11-14 22:21:13 -08:00 committed by Sascha Hauer
parent bb9125c93e
commit 8f154474fa
2 changed files with 32 additions and 1 deletions

View File

@ -136,6 +136,33 @@ int regmap_read(struct regmap *map, unsigned int reg, unsigned int *val)
return map->bus->reg_read(map->bus_context, reg, val);
}
/**
* regmap_write_bits - write bits of a register in a map
*
* @map: The map
* @reg: The register offset of the register
* @mask: Mask indicating bits to be modified
* (1 - modified, 0 - untouched)
* @val: Bit value to be set
*
* Returns 0 for success or negative error code on failure
*/
int regmap_write_bits(struct regmap *map, unsigned int reg,
unsigned int mask, unsigned int val)
{
int ret;
unsigned int tmp, orig;
ret = regmap_read(map, reg, &orig);
if (ret != 0)
return ret;
tmp = orig & ~mask;
tmp |= val & mask;
return regmap_write(map, reg, tmp);
}
/**
* regmap_bulk_read(): Read data from the device
*

View File

@ -60,4 +60,8 @@ int regmap_get_val_bytes(struct regmap *map);
int regmap_get_max_register(struct regmap *map);
int regmap_get_reg_stride(struct regmap *map);
#endif /* __REGMAP_H */
int regmap_write_bits(struct regmap *map, unsigned int reg,
unsigned int mask, unsigned int val);
#endif /* __REGMAP_H */