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

regulator: Add regulator_err2notif() helper

Help drivers avoid storing both supported notification and supported error
flags by supporting conversion from regulator error to notification.
This may help saving some bytes.

Add helper for finding the regulator notification corresponding to a
regulator error.

Signed-off-by: Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>
Link: https://lore.kernel.org/r/eb1755ac0569ff07ffa466cf8912c6fd50e7c7c6.1637736436.git.matti.vaittinen@fi.rohmeurope.com
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Matti Vaittinen and committed by
Mark Brown
6fadec4c 1b6ed6bf

+34
+34
include/linux/regulator/driver.h
··· 645 645 spinlock_t err_lock; 646 646 }; 647 647 648 + /* 649 + * Convert error flags to corresponding notifications. 650 + * 651 + * Can be used by drivers which use the notification helpers to 652 + * find out correct notification flags based on the error flags. Drivers 653 + * can avoid storing both supported notification and error flags which 654 + * may save few bytes. 655 + */ 656 + static inline int regulator_err2notif(int err) 657 + { 658 + switch (err) { 659 + case REGULATOR_ERROR_UNDER_VOLTAGE: 660 + return REGULATOR_EVENT_UNDER_VOLTAGE; 661 + case REGULATOR_ERROR_OVER_CURRENT: 662 + return REGULATOR_EVENT_OVER_CURRENT; 663 + case REGULATOR_ERROR_REGULATION_OUT: 664 + return REGULATOR_EVENT_REGULATION_OUT; 665 + case REGULATOR_ERROR_FAIL: 666 + return REGULATOR_EVENT_FAIL; 667 + case REGULATOR_ERROR_OVER_TEMP: 668 + return REGULATOR_EVENT_OVER_TEMP; 669 + case REGULATOR_ERROR_UNDER_VOLTAGE_WARN: 670 + return REGULATOR_EVENT_UNDER_VOLTAGE_WARN; 671 + case REGULATOR_ERROR_OVER_CURRENT_WARN: 672 + return REGULATOR_EVENT_OVER_CURRENT_WARN; 673 + case REGULATOR_ERROR_OVER_VOLTAGE_WARN: 674 + return REGULATOR_EVENT_OVER_VOLTAGE_WARN; 675 + case REGULATOR_ERROR_OVER_TEMP_WARN: 676 + return REGULATOR_EVENT_OVER_TEMP_WARN; 677 + } 678 + return 0; 679 + } 680 + 681 + 648 682 struct regulator_dev * 649 683 regulator_register(const struct regulator_desc *regulator_desc, 650 684 const struct regulator_config *config);