Skip to content

Commit 02d6fde

Browse files
Ansuelbroonie
authored andcommitted
regmap: allow to define reg_update_bits for no bus configuration
Some device requires a special handling for reg_update_bits and can't use the normal regmap read write logic. An example is when locking is handled by the device and rmw operations requires to do atomic operations. Allow to declare a dedicated function in regmap_config for reg_update_bits in no bus configuration. Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com> Link: https://lore.kernel.org/r/20211104150040.1260-1-ansuelsmth@gmail.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent fa55b7d commit 02d6fde

2 files changed

Lines changed: 8 additions & 0 deletions

File tree

drivers/base/regmap/regmap.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,7 @@ struct regmap *__regmap_init(struct device *dev,
876876
if (!bus) {
877877
map->reg_read = config->reg_read;
878878
map->reg_write = config->reg_write;
879+
map->reg_update_bits = config->reg_update_bits;
879880

880881
map->defer_caching = false;
881882
goto skip_format_initialization;

include/linux/regmap.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,11 @@ typedef void (*regmap_unlock)(void *);
290290
* read operation on a bus such as SPI, I2C, etc. Most of the
291291
* devices do not need this.
292292
* @reg_write: Same as above for writing.
293+
* @reg_update_bits: Optional callback that if filled will be used to perform
294+
* all the update_bits(rmw) operation. Should only be provided
295+
* if the function require special handling with lock and reg
296+
* handling and the operation cannot be represented as a simple
297+
* update_bits operation on a bus such as SPI, I2C, etc.
293298
* @fast_io: Register IO is fast. Use a spinlock instead of a mutex
294299
* to perform locking. This field is ignored if custom lock/unlock
295300
* functions are used (see fields lock/unlock of struct regmap_config).
@@ -372,6 +377,8 @@ struct regmap_config {
372377

373378
int (*reg_read)(void *context, unsigned int reg, unsigned int *val);
374379
int (*reg_write)(void *context, unsigned int reg, unsigned int val);
380+
int (*reg_update_bits)(void *context, unsigned int reg,
381+
unsigned int mask, unsigned int val);
375382

376383
bool fast_io;
377384

0 commit comments

Comments
 (0)