Skip to content

Commit 6fadec4

Browse files
M-Vaittinenbroonie
authored andcommitted
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 <[email protected]> Link: https://lore.kernel.org/r/eb1755ac0569ff07ffa466cf8912c6fd50e7c7c6.1637736436.git.matti.vaittinen@fi.rohmeurope.com Signed-off-by: Mark Brown <[email protected]>
1 parent 1b6ed6b commit 6fadec4

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

include/linux/regulator/driver.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,40 @@ struct regulator_dev {
645645
spinlock_t err_lock;
646646
};
647647

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+
648682
struct regulator_dev *
649683
regulator_register(const struct regulator_desc *regulator_desc,
650684
const struct regulator_config *config);

0 commit comments

Comments
 (0)