blob: e99bae0e6898e80ba0cb3296e5705bc39ce6fcaf [file] [log] [blame]
From b3248a41119d69d0d845a00c16bcdd85e9230b29 Mon Sep 17 00:00:00 2001
From: Nick Fan <Nick.Fan@mediatek.com>
Date: Fri, 2 Nov 2018 16:40:30 +0800
Subject: [PATCH] CHROMIUM: opp: Add API for getting voltage from supplies
Add API to get voltage for multiple supplies from opp table
(am from https://patchwork.kernel.org/patch/10730753/)
(also found at https://lkml.org/lkml/2018/12/4/114)
BUG=b:109911488
Test=build and boot to shell
Change-Id: I6e3f4320429b9267e58bc34cc147b9adc41c88ec
Signed-off-by: Nick Fan <Nick.Fan@mediatek.com>
Reviewed-on: https://chromium-review.googlesource.com/1377753
Commit-Ready: Nicolas Boichat <drinkcat@chromium.org>
Tested-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-by: Nicolas Boichat <drinkcat@chromium.org>
[rebase510(groeck): FROMLIST -> CHROMIUM (rejected upstream)]
Signed-off-by: Guenter Roeck <groeck@chromium.org>
---
drivers/opp/core.c | 28 ++++++++++++++++++++++++++++
include/linux/pm_opp.h | 3 +++
2 files changed, 31 insertions(+)
diff --git a/drivers/opp/core.c b/drivers/opp/core.c
index 740407252298..b2f94604aac8 100644
--- a/drivers/opp/core.c
+++ b/drivers/opp/core.c
@@ -113,6 +113,34 @@ unsigned long dev_pm_opp_get_voltage(struct dev_pm_opp *opp)
}
EXPORT_SYMBOL_GPL(dev_pm_opp_get_voltage);
+/**
+ * dev_pm_opp_get_voltage_supply() - Gets the voltage corresponding to an opp
+ * with index
+ * @opp: opp for which voltage has to be returned for
+ * @index: index to specify the returned supplies
+ *
+ * Return: voltage in micro volt corresponding to the opp with index, else
+ * return 0
+ *
+ * This is useful for devices with multiple power supplies.
+ */
+unsigned long dev_pm_opp_get_voltage_supply(struct dev_pm_opp *opp,
+ unsigned int index)
+{
+ if (IS_ERR_OR_NULL(opp)) {
+ pr_err("%s: Invalid parameters\n", __func__);
+ return 0;
+ }
+
+ if (index >= opp->opp_table->regulator_count) {
+ pr_err("%s: Invalid supply index: %u\n", __func__, index);
+ return 0;
+ }
+
+ return opp->supplies[index].u_volt;
+}
+EXPORT_SYMBOL_GPL(dev_pm_opp_get_voltage_supply);
+
/**
* dev_pm_opp_get_power() - Gets the power corresponding to an opp
* @opp: opp for which power has to be returned for
diff --git a/include/linux/pm_opp.h b/include/linux/pm_opp.h
index 0d85a63a1f78..e9255ea1f984 100644
--- a/include/linux/pm_opp.h
+++ b/include/linux/pm_opp.h
@@ -97,6 +97,9 @@ void dev_pm_opp_put_opp_table(struct opp_table *opp_table);
unsigned long dev_pm_opp_get_voltage(struct dev_pm_opp *opp);
+unsigned long dev_pm_opp_get_voltage_supply(struct dev_pm_opp *opp,
+ unsigned int index);
+
unsigned long dev_pm_opp_get_power(struct dev_pm_opp *opp);
unsigned long dev_pm_opp_get_freq(struct dev_pm_opp *opp);
--
2.35.0