@@ -449,6 +449,32 @@ struct pwrseq_provider *__devm_of_pwrseq_provider_register(struct device *dev,
}
EXPORT_SYMBOL_GPL(__devm_of_pwrseq_provider_register);
+/**
+ * of_pwrseq_xlate_single() - returns the pwrseq instance from pwrseq provider using single index
+ * @data: the pwrseq provider data, struct pwrseq_onecell_data
+ * @args: of_phandle_args containing single integer index
+ *
+ * Intended to be used by pwrseq provider for the common case where
+ * #pwrseq-cells is 1. It will return corresponding pwrseq instance.
+ */
+struct pwrseq *of_pwrseq_xlate_onecell(void *data, struct of_phandle_args *args)
+{
+ struct pwrseq_onecell_data *pwrseq_data = data;
+ unsigned int idx;
+
+ if (args->args_count != 1)
+ return ERR_PTR(-EINVAL);
+
+ idx = args->args[0];
+ if (idx >= pwrseq_data->num) {
+ pr_err("%s: invalid index %u\n", __func__, idx);
+ return ERR_PTR(-EINVAL);
+ }
+
+ return pwrseq_data->pwrseqs[idx];
+}
+EXPORT_SYMBOL_GPL(of_pwrseq_xlate_onecell);
+
static int __init pwrseq_core_init(void)
{
return class_register(&pwrseq_class);
@@ -157,4 +157,16 @@ static inline struct pwrseq *of_pwrseq_xlate_single(void *data,
return data;
}
+/**
+ * struct pwrseq_onecell_data - pwrseq data for of_pwrseq_xlate_onecell
+ * @num: amount of instances in @owrseqs
+ * @pwrseqs: array of pwrseq instances
+ */
+struct pwrseq_onecell_data {
+ unsigned int num;
+ struct pwrseq *pwrseqs[];
+};
+
+struct pwrseq *of_pwrseq_xlate_onecell(void *data, struct of_phandle_args *args);
+
#endif /* __LINUX_PWRSEQ_DRIVER_H__ */
Provide of_pwrseq_xlate_onecell() - a helper easing implementation of power sequencers using one cell to determine pwrseq instance to return. Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org> --- drivers/power/pwrseq/core.c | 26 ++++++++++++++++++++++++++ include/linux/pwrseq/driver.h | 12 ++++++++++++ 2 files changed, 38 insertions(+)