[PATCH v2 2/3] regulator: core: add helper to check if regulator is disabled in suspend

From: Claudiu.Beznea
Date: Tue Jan 08 2019 - 05:56:37 EST


From: Claudiu Beznea <claudiu.beznea@xxxxxxxxxxxxx>

Add helper to check if regulator will be disabled in suspend.

Signed-off-by: Claudiu Beznea <claudiu.beznea@xxxxxxxxxxxxx>
---
drivers/regulator/core.c | 17 +++++++++++++++++
include/linux/regulator/consumer.h | 7 +++++++
2 files changed, 24 insertions(+)

diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index b9d7b45c7295..3b761969732a 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -3786,6 +3786,23 @@ int regulator_suspend_disable(struct regulator_dev *rdev,
}
EXPORT_SYMBOL_GPL(regulator_suspend_disable);

+bool regulator_is_disabled_in_suspend(struct regulator *regulator,
+ suspend_state_t state)
+{
+ struct regulator_state *rstate;
+
+ if (!regulator->rdev->constraints)
+ return false;
+
+ rstate = regulator_get_suspend_state(regulator->rdev, state);
+ if (!rstate)
+ return false;
+
+ return regulator->rdev->desc->ops->set_suspend_disable &&
+ rstate->enabled == DISABLE_IN_SUSPEND;
+}
+EXPORT_SYMBOL_GPL(regulator_is_disabled_in_suspend);
+
static int _regulator_set_suspend_voltage(struct regulator *regulator,
int min_uV, int max_uV,
suspend_state_t state)
diff --git a/include/linux/regulator/consumer.h b/include/linux/regulator/consumer.h
index f3f76051e8b0..cf5e71dc63ce 100644
--- a/include/linux/regulator/consumer.h
+++ b/include/linux/regulator/consumer.h
@@ -36,6 +36,7 @@
#define __LINUX_REGULATOR_CONSUMER_H_

#include <linux/err.h>
+#include <linux/suspend.h>

struct device;
struct notifier_block;
@@ -285,6 +286,9 @@ void devm_regulator_unregister_notifier(struct regulator *regulator,
void *regulator_get_drvdata(struct regulator *regulator);
void regulator_set_drvdata(struct regulator *regulator, void *data);

+/* regulator suspend/resume state */
+bool regulator_is_disabled_in_suspend(struct regulator *regulator,
+ suspend_state_t state);
#else

/*
@@ -579,6 +583,9 @@ static inline int regulator_list_voltage(struct regulator *regulator, unsigned s
return -EINVAL;
}

+bool regulator_is_disabled_in_suspend(struct regulator *regulator,
+ suspend_state_t state);
+
#endif

static inline int regulator_set_voltage_triplet(struct regulator *regulator,
--
2.7.4