blob: 0362c1d57e281460c73d83498c060f9f6b0d19ac [file] [log] [blame]
From 77c141ad01723075b661e20ee6bd7fff32963813 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 e87567dbe99f27d09c9de29fc40e9e1108f4a5da..f922ccca838d23bda1a2059d5effec1c87471645 100644
--- a/drivers/opp/core.c
+++ b/drivers/opp/core.c
@@ -129,6 +129,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_supplies() - Gets the supply information corresponding to an opp
* @opp: opp for which voltage has to be returned for
diff --git a/include/linux/pm_opp.h b/include/linux/pm_opp.h
index dc1fb5890792950a79bdb7b036da2ed3c5e45a94..19990b235b74e71c6c8d0ba1c44280406629134c 100644
--- a/include/linux/pm_opp.h
+++ b/include/linux/pm_opp.h
@@ -99,6 +99,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);
+
int dev_pm_opp_get_supplies(struct dev_pm_opp *opp, struct dev_pm_opp_supply *supplies);
unsigned long dev_pm_opp_get_power(struct dev_pm_opp *opp);
--
2.38.1.584.g0f3c55d4c2-goog