diff options
Diffstat (limited to 'drivers/base/regmap/regmap.c')
-rw-r--r-- | drivers/base/regmap/regmap.c | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c index 677aeab24f75..1752f13ddebc 100644 --- a/drivers/base/regmap/regmap.c +++ b/drivers/base/regmap/regmap.c | |||
@@ -711,6 +711,64 @@ int regmap_update_bits_check(struct regmap *map, unsigned int reg, | |||
711 | } | 711 | } |
712 | EXPORT_SYMBOL_GPL(regmap_update_bits_check); | 712 | EXPORT_SYMBOL_GPL(regmap_update_bits_check); |
713 | 713 | ||
714 | /** | ||
715 | * regmap_register_patch: Register and apply register updates to be applied | ||
716 | * on device initialistion | ||
717 | * | ||
718 | * @map: Register map to apply updates to. | ||
719 | * @regs: Values to update. | ||
720 | * @num_regs: Number of entries in regs. | ||
721 | * | ||
722 | * Register a set of register updates to be applied to the device | ||
723 | * whenever the device registers are synchronised with the cache and | ||
724 | * apply them immediately. Typically this is used to apply | ||
725 | * corrections to be applied to the device defaults on startup, such | ||
726 | * as the updates some vendors provide to undocumented registers. | ||
727 | */ | ||
728 | int regmap_register_patch(struct regmap *map, const struct reg_default *regs, | ||
729 | int num_regs) | ||
730 | { | ||
731 | int i, ret; | ||
732 | bool bypass; | ||
733 | |||
734 | /* If needed the implementation can be extended to support this */ | ||
735 | if (map->patch) | ||
736 | return -EBUSY; | ||
737 | |||
738 | mutex_lock(&map->lock); | ||
739 | |||
740 | bypass = map->cache_bypass; | ||
741 | |||
742 | map->cache_bypass = true; | ||
743 | |||
744 | /* Write out first; it's useful to apply even if we fail later. */ | ||
745 | for (i = 0; i < num_regs; i++) { | ||
746 | ret = _regmap_write(map, regs[i].reg, regs[i].def); | ||
747 | if (ret != 0) { | ||
748 | dev_err(map->dev, "Failed to write %x = %x: %d\n", | ||
749 | regs[i].reg, regs[i].def, ret); | ||
750 | goto out; | ||
751 | } | ||
752 | } | ||
753 | |||
754 | map->patch = kcalloc(num_regs, sizeof(struct reg_default), GFP_KERNEL); | ||
755 | if (map->patch != NULL) { | ||
756 | memcpy(map->patch, regs, | ||
757 | num_regs * sizeof(struct reg_default)); | ||
758 | map->patch_regs = num_regs; | ||
759 | } else { | ||
760 | ret = -ENOMEM; | ||
761 | } | ||
762 | |||
763 | out: | ||
764 | map->cache_bypass = bypass; | ||
765 | |||
766 | mutex_unlock(&map->lock); | ||
767 | |||
768 | return ret; | ||
769 | } | ||
770 | EXPORT_SYMBOL_GPL(regmap_register_patch); | ||
771 | |||
714 | static int __init regmap_initcall(void) | 772 | static int __init regmap_initcall(void) |
715 | { | 773 | { |
716 | regmap_debugfs_initcall(); | 774 | regmap_debugfs_initcall(); |