Skip to content

Commit b629c69

Browse files
whamebroonie
authored andcommitted
regmap: Add debugfs file for forcing field writes
`_regmap_update_bits()` checks if the current register value differs from the new value, and only writes to the register if they differ. When testing hardware drivers, it might be desirable to always force a register write, for example when writing to a `regmap_field`. This enables and simplifies testing and verification of the hardware interaction. For example, when using a hardware mock/simulation model, one can then more easily verify that the driver makes the correct expected register writes during certain events. Add a bool variable `force_write_field` and a corresponding debugfs entry to enable this. Since this feature could interfere with driver operation, guard it with a macro. Signed-off-by: Waqar Hameed <waqar.hameed@axis.com> Link: https://lore.kernel.org/r/pnd1qifa7sj.fsf@axis.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent ecfb8ce commit b629c69

3 files changed

Lines changed: 15 additions & 1 deletion

File tree

drivers/base/regmap/internal.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@ struct regmap {
125125
int reg_stride;
126126
int reg_stride_order;
127127

128+
/* If set, will always write field to HW. */
129+
bool force_write_field;
130+
128131
/* regcache specific members */
129132
const struct regcache_ops *cache_ops;
130133
enum regcache_type cache_type;

drivers/base/regmap/regmap-debugfs.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,17 @@ void regmap_debugfs_init(struct regmap *map)
636636
&regmap_cache_bypass_fops);
637637
}
638638

639+
/*
640+
* This could interfere with driver operation. Therefore, don't provide
641+
* any real compile time configuration option for this feature. One will
642+
* have to modify the source code directly in order to use it.
643+
*/
644+
#undef REGMAP_ALLOW_FORCE_WRITE_FIELD_DEBUGFS
645+
#ifdef REGMAP_ALLOW_FORCE_WRITE_FIELD_DEBUGFS
646+
debugfs_create_bool("force_write_field", 0600, map->debugfs,
647+
&map->force_write_field);
648+
#endif
649+
639650
next = rb_first(&map->range_tree);
640651
while (next) {
641652
range_node = rb_entry(next, struct regmap_range_node, node);

drivers/base/regmap/regmap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3279,7 +3279,7 @@ static int _regmap_update_bits(struct regmap *map, unsigned int reg,
32793279
tmp = orig & ~mask;
32803280
tmp |= val & mask;
32813281

3282-
if (force_write || (tmp != orig)) {
3282+
if (force_write || (tmp != orig) || map->force_write_field) {
32833283
ret = _regmap_write(map, reg, tmp);
32843284
if (ret == 0 && change)
32853285
*change = true;

0 commit comments

Comments
 (0)