aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/base
diff options
context:
space:
mode:
authorMark Brown <broonie@opensource.wolfsonmicro.com>2011-11-29 15:10:36 -0500
committerMark Brown <broonie@opensource.wolfsonmicro.com>2011-11-29 15:15:50 -0500
commit018690d33ecf4aa1eb1415e38c40e2b0b6c7808e (patch)
tree3ae08fb9d199813840564fb392ebc9b4a5d8c230 /drivers/base
parentc86845dc7b56be050b9e53b31079e8bd0a3dc279 (diff)
regmap: Allow regmap_update_bits() users to detect changes
Some users of regmap_update_bits() would like to be able to tell their users if they actually did an update so provide a variant which also returns a flag indicating if an update took place. We could return a tristate in the return value of regmap_update_bits() but this makes the API more cumbersome to use and doesn't fit with the general zero for success idiom we have. Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'drivers/base')
-rw-r--r--drivers/base/regmap/regmap.c58
1 files changed, 45 insertions, 13 deletions
diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c
index a8620900abc4..add5da6d9c0a 100644
--- a/drivers/base/regmap/regmap.c
+++ b/drivers/base/regmap/regmap.c
@@ -569,18 +569,9 @@ int regmap_bulk_read(struct regmap *map, unsigned int reg, void *val,
569} 569}
570EXPORT_SYMBOL_GPL(regmap_bulk_read); 570EXPORT_SYMBOL_GPL(regmap_bulk_read);
571 571
572/** 572static int _regmap_update_bits(struct regmap *map, unsigned int reg,
573 * regmap_update_bits: Perform a read/modify/write cycle on the register map 573 unsigned int mask, unsigned int val,
574 * 574 bool *change)
575 * @map: Register map to update
576 * @reg: Register to update
577 * @mask: Bitmask to change
578 * @val: New value for bitmask
579 *
580 * Returns zero for success, a negative number on error.
581 */
582int regmap_update_bits(struct regmap *map, unsigned int reg,
583 unsigned int mask, unsigned int val)
584{ 575{
585 int ret; 576 int ret;
586 unsigned int tmp, orig; 577 unsigned int tmp, orig;
@@ -594,16 +585,57 @@ int regmap_update_bits(struct regmap *map, unsigned int reg,
594 tmp = orig & ~mask; 585 tmp = orig & ~mask;
595 tmp |= val & mask; 586 tmp |= val & mask;
596 587
597 if (tmp != orig) 588 if (tmp != orig) {
598 ret = _regmap_write(map, reg, tmp); 589 ret = _regmap_write(map, reg, tmp);
590 *change = true;
591 } else {
592 *change = false;
593 }
599 594
600out: 595out:
601 mutex_unlock(&map->lock); 596 mutex_unlock(&map->lock);
602 597
603 return ret; 598 return ret;
604} 599}
600
601/**
602 * regmap_update_bits: Perform a read/modify/write cycle on the register map
603 *
604 * @map: Register map to update
605 * @reg: Register to update
606 * @mask: Bitmask to change
607 * @val: New value for bitmask
608 *
609 * Returns zero for success, a negative number on error.
610 */
611int regmap_update_bits(struct regmap *map, unsigned int reg,
612 unsigned int mask, unsigned int val)
613{
614 bool change;
615 return _regmap_update_bits(map, reg, mask, val, &change);
616}
605EXPORT_SYMBOL_GPL(regmap_update_bits); 617EXPORT_SYMBOL_GPL(regmap_update_bits);
606 618
619/**
620 * regmap_update_bits_check: Perform a read/modify/write cycle on the
621 * register map and report if updated
622 *
623 * @map: Register map to update
624 * @reg: Register to update
625 * @mask: Bitmask to change
626 * @val: New value for bitmask
627 * @change: Boolean indicating if a write was done
628 *
629 * Returns zero for success, a negative number on error.
630 */
631int regmap_update_bits_check(struct regmap *map, unsigned int reg,
632 unsigned int mask, unsigned int val,
633 bool *change)
634{
635 return _regmap_update_bits(map, reg, mask, val, change);
636}
637EXPORT_SYMBOL_GPL(regmap_update_bits_check);
638
607static int __init regmap_initcall(void) 639static int __init regmap_initcall(void)
608{ 640{
609 regmap_debugfs_initcall(); 641 regmap_debugfs_initcall();