Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

regmap: allow to disable all locking mechanisms

We have a use case in the at24 EEPROM driver (recently converted to
using regmap instead of raw i2c/smbus calls) where we read from/write
to the regmap in a loop, while protecting the entire loop with
a mutex.

Currently this implicitly makes us use two mutexes - one in the driver
and one in regmap. While browsing the code for similar use cases I
noticed a significant number of places where locking *seems* redundant.

Allow users to completely disable any locking mechanisms in regmap
config.

Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Bartosz Golaszewski and committed by
Mark Brown
c9b41fcf 4fbd8d19

+13 -1
+8 -1
drivers/base/regmap/regmap.c
··· 459 459 } 460 460 #endif 461 461 462 + static void regmap_lock_unlock_empty(void *__map) 463 + { 464 + 465 + } 466 + 462 467 static void regmap_lock_mutex(void *__map) 463 468 { 464 469 struct regmap *map = __map; ··· 674 669 goto err; 675 670 } 676 671 677 - if (config->lock && config->unlock) { 672 + if (config->disable_locking) { 673 + map->lock = map->unlock = regmap_lock_unlock_empty; 674 + } else if (config->lock && config->unlock) { 678 675 map->lock = config->lock; 679 676 map->unlock = config->unlock; 680 677 map->lock_arg = config->lock_arg;
+5
include/linux/regmap.h
··· 264 264 * field is NULL but precious_table (see below) is not, the 265 265 * check is performed on such table (a register is precious if 266 266 * it belongs to one of the ranges specified by precious_table). 267 + * @disable_locking: This regmap is either protected by external means or 268 + * is guaranteed not be be accessed from multiple threads. 269 + * Don't use any locking mechanisms. 267 270 * @lock: Optional lock callback (overrides regmap's default lock 268 271 * function, based on spinlock or mutex). 269 272 * @unlock: As above for unlocking. ··· 336 333 bool (*readable_reg)(struct device *dev, unsigned int reg); 337 334 bool (*volatile_reg)(struct device *dev, unsigned int reg); 338 335 bool (*precious_reg)(struct device *dev, unsigned int reg); 336 + 337 + bool disable_locking; 339 338 regmap_lock lock; 340 339 regmap_unlock unlock; 341 340 void *lock_arg;