diff options
author | Lars-Peter Clausen <lars@metafoo.de> | 2013-05-24 04:29:22 -0400 |
---|---|---|
committer | Nitin Garg <nitin.garg@freescale.com> | 2014-04-16 09:05:42 -0400 |
commit | 248b3a445b5764b6e677093a650839dc36d886d8 (patch) | |
tree | 49e6c8fa0716f75aebf7b469ddd22c5a8f5dc521 | |
parent | 7a36cd6bdcf89fded4fba44c8ebe259465b742e8 (diff) |
regmap: Make regmap-mmio usable from atomic contexts
regmap-mmio uses a spinlock with spin_lock() and spin_unlock() for locking.
To be able to use the regmap API from different contexts (atomic vs non-atomic),
without the risk of race conditions, we need to use spin_lock_irqsave() and
spin_lock_irqrestore() instead. A new field, the spinlock_flags field, is added
to regmap struct to store the flags between regmap_{,un}lock_spinlock(). The
spinlock_flags field itself is also protected by the spinlock.
Thanks to Stephen Warren for the suggestion of this particular solution.
Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Reviewed-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Signed-off-by: Nicolin Chen <b42378@freescale.com>
-rw-r--r-- | drivers/base/regmap/internal.h | 1 | ||||
-rw-r--r-- | drivers/base/regmap/regmap.c | 7 |
2 files changed, 6 insertions, 2 deletions
diff --git a/drivers/base/regmap/internal.h b/drivers/base/regmap/internal.h index c130536e0ab0..1b74b71aed12 100644 --- a/drivers/base/regmap/internal.h +++ b/drivers/base/regmap/internal.h | |||
@@ -52,6 +52,7 @@ struct regmap_async { | |||
52 | struct regmap { | 52 | struct regmap { |
53 | struct mutex mutex; | 53 | struct mutex mutex; |
54 | spinlock_t spinlock; | 54 | spinlock_t spinlock; |
55 | unsigned long spinlock_flags; | ||
55 | regmap_lock lock; | 56 | regmap_lock lock; |
56 | regmap_unlock unlock; | 57 | regmap_unlock unlock; |
57 | void *lock_arg; /* This is passed to lock/unlock functions */ | 58 | void *lock_arg; /* This is passed to lock/unlock functions */ |
diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c index d0c81d1f409c..3c447cf2aa6a 100644 --- a/drivers/base/regmap/regmap.c +++ b/drivers/base/regmap/regmap.c | |||
@@ -302,13 +302,16 @@ static void regmap_unlock_mutex(void *__map) | |||
302 | static void regmap_lock_spinlock(void *__map) | 302 | static void regmap_lock_spinlock(void *__map) |
303 | { | 303 | { |
304 | struct regmap *map = __map; | 304 | struct regmap *map = __map; |
305 | spin_lock(&map->spinlock); | 305 | unsigned long flags; |
306 | |||
307 | spin_lock_irqsave(&map->spinlock, flags); | ||
308 | map->spinlock_flags = flags; | ||
306 | } | 309 | } |
307 | 310 | ||
308 | static void regmap_unlock_spinlock(void *__map) | 311 | static void regmap_unlock_spinlock(void *__map) |
309 | { | 312 | { |
310 | struct regmap *map = __map; | 313 | struct regmap *map = __map; |
311 | spin_unlock(&map->spinlock); | 314 | spin_unlock_irqrestore(&map->spinlock, map->spinlock_flags); |
312 | } | 315 | } |
313 | 316 | ||
314 | static void dev_get_regmap_release(struct device *dev, void *res) | 317 | static void dev_get_regmap_release(struct device *dev, void *res) |