linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/6] OPP: Indexed searching based on frequency
@ 2023-07-21  9:40 Viresh Kumar
  2023-07-21  9:40 ` [PATCH 1/6] OPP: Rearrange entries in pm_opp.h Viresh Kumar
                   ` (5 more replies)
  0 siblings, 6 replies; 11+ messages in thread
From: Viresh Kumar @ 2023-07-21  9:40 UTC (permalink / raw)
  To: Nishanth Menon, Rafael J. Wysocki, Stephen Boyd, Viresh Kumar
  Cc: Viresh Kumar, linux-pm, Vincent Guittot, Manivannan Sadhasivam,
	linux-kernel

Hi,

This series adds support for indexed versions OPP finding helpers.
Some of these are picked from the series posted by Manivannan.

--
Viresh

Manivannan Sadhasivam (2):
  OPP: Introduce dev_pm_opp_find_freq_{ceil/floor}_indexed() APIs
  OPP: Introduce dev_pm_opp_get_freq_indexed() API

Viresh Kumar (4):
  OPP: Rearrange entries in pm_opp.h
  OPP: Add dev_pm_opp_find_freq_exact_indexed()
  OPP: Update _read_freq() to return the correct frequency
  OPP: Reuse dev_pm_opp_get_freq_indexed()

 drivers/opp/core.c     | 109 ++++++++++++++++++++++++++++++++++++-----
 include/linux/pm_opp.h |  62 ++++++++++++++++++-----
 2 files changed, 146 insertions(+), 25 deletions(-)

-- 
2.31.1.272.g89b43f80a514


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 1/6] OPP: Rearrange entries in pm_opp.h
  2023-07-21  9:40 [PATCH 0/6] OPP: Indexed searching based on frequency Viresh Kumar
@ 2023-07-21  9:40 ` Viresh Kumar
  2023-07-21  9:40 ` [PATCH 2/6] OPP: Introduce dev_pm_opp_find_freq_{ceil/floor}_indexed() APIs Viresh Kumar
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 11+ messages in thread
From: Viresh Kumar @ 2023-07-21  9:40 UTC (permalink / raw)
  To: Viresh Kumar, Nishanth Menon, Stephen Boyd, Rafael J. Wysocki
  Cc: Viresh Kumar, linux-pm, Vincent Guittot, Manivannan Sadhasivam,
	linux-kernel

Rearrange the helper function declarations / definitions to keep them in
order of freq, level and then bw.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
 include/linux/pm_opp.h | 28 +++++++++++++++-------------
 1 file changed, 15 insertions(+), 13 deletions(-)

diff --git a/include/linux/pm_opp.h b/include/linux/pm_opp.h
index dc1fb5890792..3821f50b9b89 100644
--- a/include/linux/pm_opp.h
+++ b/include/linux/pm_opp.h
@@ -121,17 +121,19 @@ unsigned long dev_pm_opp_get_suspend_opp_freq(struct device *dev);
 struct dev_pm_opp *dev_pm_opp_find_freq_exact(struct device *dev,
 					      unsigned long freq,
 					      bool available);
+
 struct dev_pm_opp *dev_pm_opp_find_freq_floor(struct device *dev,
 					      unsigned long *freq);
 
+struct dev_pm_opp *dev_pm_opp_find_freq_ceil(struct device *dev,
+					     unsigned long *freq);
+
 struct dev_pm_opp *dev_pm_opp_find_level_exact(struct device *dev,
 					       unsigned int level);
+
 struct dev_pm_opp *dev_pm_opp_find_level_ceil(struct device *dev,
 					      unsigned int *level);
 
-struct dev_pm_opp *dev_pm_opp_find_freq_ceil(struct device *dev,
-					     unsigned long *freq);
-
 struct dev_pm_opp *dev_pm_opp_find_bw_ceil(struct device *dev,
 					   unsigned int *bw, int index);
 
@@ -247,32 +249,32 @@ static inline unsigned long dev_pm_opp_get_suspend_opp_freq(struct device *dev)
 	return 0;
 }
 
-static inline struct dev_pm_opp *dev_pm_opp_find_level_exact(struct device *dev,
-					unsigned int level)
+static inline struct dev_pm_opp *dev_pm_opp_find_freq_exact(struct device *dev,
+					unsigned long freq, bool available)
 {
 	return ERR_PTR(-EOPNOTSUPP);
 }
 
-static inline struct dev_pm_opp *dev_pm_opp_find_level_ceil(struct device *dev,
-					unsigned int *level)
+static inline struct dev_pm_opp *dev_pm_opp_find_freq_floor(struct device *dev,
+					unsigned long *freq)
 {
 	return ERR_PTR(-EOPNOTSUPP);
 }
 
-static inline struct dev_pm_opp *dev_pm_opp_find_freq_exact(struct device *dev,
-					unsigned long freq, bool available)
+static inline struct dev_pm_opp *dev_pm_opp_find_freq_ceil(struct device *dev,
+					unsigned long *freq)
 {
 	return ERR_PTR(-EOPNOTSUPP);
 }
 
-static inline struct dev_pm_opp *dev_pm_opp_find_freq_floor(struct device *dev,
-					unsigned long *freq)
+static inline struct dev_pm_opp *dev_pm_opp_find_level_exact(struct device *dev,
+					unsigned int level)
 {
 	return ERR_PTR(-EOPNOTSUPP);
 }
 
-static inline struct dev_pm_opp *dev_pm_opp_find_freq_ceil(struct device *dev,
-					unsigned long *freq)
+static inline struct dev_pm_opp *dev_pm_opp_find_level_ceil(struct device *dev,
+					unsigned int *level)
 {
 	return ERR_PTR(-EOPNOTSUPP);
 }
-- 
2.31.1.272.g89b43f80a514


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 2/6] OPP: Introduce dev_pm_opp_find_freq_{ceil/floor}_indexed() APIs
  2023-07-21  9:40 [PATCH 0/6] OPP: Indexed searching based on frequency Viresh Kumar
  2023-07-21  9:40 ` [PATCH 1/6] OPP: Rearrange entries in pm_opp.h Viresh Kumar
@ 2023-07-21  9:40 ` Viresh Kumar
  2023-07-21  9:40 ` [PATCH 3/6] OPP: Introduce dev_pm_opp_get_freq_indexed() API Viresh Kumar
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 11+ messages in thread
From: Viresh Kumar @ 2023-07-21  9:40 UTC (permalink / raw)
  To: Viresh Kumar, Nishanth Menon, Stephen Boyd, Rafael J. Wysocki
  Cc: Viresh Kumar, linux-pm, Vincent Guittot, Manivannan Sadhasivam,
	linux-kernel

From: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>

In the case of devices with multiple clocks, drivers need to specify the
clock index for the OPP framework to find the OPP corresponding to the
floor/ceil of the supplied frequency. So let's introduce the two new APIs
accepting the clock index as an argument.

These APIs use the exising _find_key_ceil() helper by supplying the clock
index to it.

Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
[ Viresh: Rearranged definitions in pm_opp.h ]
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
 drivers/opp/core.c     | 56 ++++++++++++++++++++++++++++++++++++++++++
 include/linux/pm_opp.h | 18 ++++++++++++++
 2 files changed, 74 insertions(+)

diff --git a/drivers/opp/core.c b/drivers/opp/core.c
index 3f46e499d615..cb4f47b341f9 100644
--- a/drivers/opp/core.c
+++ b/drivers/opp/core.c
@@ -658,6 +658,34 @@ struct dev_pm_opp *dev_pm_opp_find_freq_ceil(struct device *dev,
 }
 EXPORT_SYMBOL_GPL(dev_pm_opp_find_freq_ceil);
 
+/**
+ * dev_pm_opp_find_freq_ceil_indexed() - Search for a rounded ceil freq for the
+ *					 clock corresponding to the index
+ * @dev:	Device for which we do this operation
+ * @freq:	Start frequency
+ * @index:	Clock index
+ *
+ * Search for the matching ceil *available* OPP for the clock corresponding to
+ * the specified index from a starting freq for a device.
+ *
+ * Return: matching *opp and refreshes *freq accordingly, else returns
+ * ERR_PTR in case of error and should be handled using IS_ERR. Error return
+ * values can be:
+ * EINVAL:	for bad pointer
+ * ERANGE:	no match found for search
+ * ENODEV:	if device not found in list of registered devices
+ *
+ * The callers are required to call dev_pm_opp_put() for the returned OPP after
+ * use.
+ */
+struct dev_pm_opp *
+dev_pm_opp_find_freq_ceil_indexed(struct device *dev, unsigned long *freq,
+				  u32 index)
+{
+	return _find_key_ceil(dev, freq, index, true, _read_freq, NULL);
+}
+EXPORT_SYMBOL_GPL(dev_pm_opp_find_freq_ceil_indexed);
+
 /**
  * dev_pm_opp_find_freq_floor() - Search for a rounded floor freq
  * @dev:	device for which we do this operation
@@ -683,6 +711,34 @@ struct dev_pm_opp *dev_pm_opp_find_freq_floor(struct device *dev,
 }
 EXPORT_SYMBOL_GPL(dev_pm_opp_find_freq_floor);
 
+/**
+ * dev_pm_opp_find_freq_floor_indexed() - Search for a rounded floor freq for the
+ *					  clock corresponding to the index
+ * @dev:	Device for which we do this operation
+ * @freq:	Start frequency
+ * @index:	Clock index
+ *
+ * Search for the matching floor *available* OPP for the clock corresponding to
+ * the specified index from a starting freq for a device.
+ *
+ * Return: matching *opp and refreshes *freq accordingly, else returns
+ * ERR_PTR in case of error and should be handled using IS_ERR. Error return
+ * values can be:
+ * EINVAL:	for bad pointer
+ * ERANGE:	no match found for search
+ * ENODEV:	if device not found in list of registered devices
+ *
+ * The callers are required to call dev_pm_opp_put() for the returned OPP after
+ * use.
+ */
+struct dev_pm_opp *
+dev_pm_opp_find_freq_floor_indexed(struct device *dev, unsigned long *freq,
+				   u32 index)
+{
+	return _find_key_floor(dev, freq, index, true, _read_freq, NULL);
+}
+EXPORT_SYMBOL_GPL(dev_pm_opp_find_freq_floor_indexed);
+
 /**
  * dev_pm_opp_find_level_exact() - search for an exact level
  * @dev:		device for which we do this operation
diff --git a/include/linux/pm_opp.h b/include/linux/pm_opp.h
index 3821f50b9b89..2617f2c51f29 100644
--- a/include/linux/pm_opp.h
+++ b/include/linux/pm_opp.h
@@ -125,9 +125,15 @@ struct dev_pm_opp *dev_pm_opp_find_freq_exact(struct device *dev,
 struct dev_pm_opp *dev_pm_opp_find_freq_floor(struct device *dev,
 					      unsigned long *freq);
 
+struct dev_pm_opp *dev_pm_opp_find_freq_floor_indexed(struct device *dev,
+						      unsigned long *freq, u32 index);
+
 struct dev_pm_opp *dev_pm_opp_find_freq_ceil(struct device *dev,
 					     unsigned long *freq);
 
+struct dev_pm_opp *dev_pm_opp_find_freq_ceil_indexed(struct device *dev,
+						     unsigned long *freq, u32 index);
+
 struct dev_pm_opp *dev_pm_opp_find_level_exact(struct device *dev,
 					       unsigned int level);
 
@@ -261,12 +267,24 @@ static inline struct dev_pm_opp *dev_pm_opp_find_freq_floor(struct device *dev,
 	return ERR_PTR(-EOPNOTSUPP);
 }
 
+static inline struct dev_pm_opp *
+dev_pm_opp_find_freq_floor_indexed(struct device *dev, unsigned long *freq, u32 index)
+{
+	return ERR_PTR(-EOPNOTSUPP);
+}
+
 static inline struct dev_pm_opp *dev_pm_opp_find_freq_ceil(struct device *dev,
 					unsigned long *freq)
 {
 	return ERR_PTR(-EOPNOTSUPP);
 }
 
+static inline struct dev_pm_opp *
+dev_pm_opp_find_freq_ceil_indexed(struct device *dev, unsigned long *freq, u32 index)
+{
+	return ERR_PTR(-EOPNOTSUPP);
+}
+
 static inline struct dev_pm_opp *dev_pm_opp_find_level_exact(struct device *dev,
 					unsigned int level)
 {
-- 
2.31.1.272.g89b43f80a514


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 3/6] OPP: Introduce dev_pm_opp_get_freq_indexed() API
  2023-07-21  9:40 [PATCH 0/6] OPP: Indexed searching based on frequency Viresh Kumar
  2023-07-21  9:40 ` [PATCH 1/6] OPP: Rearrange entries in pm_opp.h Viresh Kumar
  2023-07-21  9:40 ` [PATCH 2/6] OPP: Introduce dev_pm_opp_find_freq_{ceil/floor}_indexed() APIs Viresh Kumar
@ 2023-07-21  9:40 ` Viresh Kumar
  2023-07-21  9:40 ` [PATCH 4/6] OPP: Add dev_pm_opp_find_freq_exact_indexed() Viresh Kumar
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 11+ messages in thread
From: Viresh Kumar @ 2023-07-21  9:40 UTC (permalink / raw)
  To: Viresh Kumar, Nishanth Menon, Stephen Boyd, Rafael J. Wysocki
  Cc: Viresh Kumar, linux-pm, Vincent Guittot, Manivannan Sadhasivam,
	linux-kernel

From: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>

In the case of devices with multiple clocks, drivers need to specify the
frequency index for the OPP framework to get the specific frequency within
the required OPP. So let's introduce the dev_pm_opp_get_freq_indexed() API
accepting the frequency index as an argument.

Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
 drivers/opp/core.c     | 22 ++++++++++++++++++++++
 include/linux/pm_opp.h |  7 +++++++
 2 files changed, 29 insertions(+)

diff --git a/drivers/opp/core.c b/drivers/opp/core.c
index cb4f47b341f9..00638d40353f 100644
--- a/drivers/opp/core.c
+++ b/drivers/opp/core.c
@@ -197,6 +197,28 @@ unsigned long dev_pm_opp_get_freq(struct dev_pm_opp *opp)
 }
 EXPORT_SYMBOL_GPL(dev_pm_opp_get_freq);
 
+/**
+ * dev_pm_opp_get_freq_indexed() - Gets the frequency corresponding to an
+ *				   available opp with specified index
+ * @opp: opp for which frequency has to be returned for
+ * @index: index of the frequency within the required opp
+ *
+ * Return: frequency in hertz corresponding to the opp with specified index,
+ * else return 0
+ */
+unsigned long dev_pm_opp_get_freq_indexed(struct dev_pm_opp *opp, u32 index)
+{
+	struct opp_table *opp_table = opp->opp_table;
+
+	if (IS_ERR_OR_NULL(opp) || index >= opp_table->clk_count) {
+		pr_err("%s: Invalid parameters\n", __func__);
+		return 0;
+	}
+
+	return opp->rates[index];
+}
+EXPORT_SYMBOL_GPL(dev_pm_opp_get_freq_indexed);
+
 /**
  * dev_pm_opp_get_level() - Gets the level corresponding to an available opp
  * @opp:	opp for which level value has to be returned for
diff --git a/include/linux/pm_opp.h b/include/linux/pm_opp.h
index 2617f2c51f29..a13a1705df57 100644
--- a/include/linux/pm_opp.h
+++ b/include/linux/pm_opp.h
@@ -105,6 +105,8 @@ unsigned long dev_pm_opp_get_power(struct dev_pm_opp *opp);
 
 unsigned long dev_pm_opp_get_freq(struct dev_pm_opp *opp);
 
+unsigned long dev_pm_opp_get_freq_indexed(struct dev_pm_opp *opp, u32 index);
+
 unsigned int dev_pm_opp_get_level(struct dev_pm_opp *opp);
 
 unsigned int dev_pm_opp_get_required_pstate(struct dev_pm_opp *opp,
@@ -213,6 +215,11 @@ static inline unsigned long dev_pm_opp_get_freq(struct dev_pm_opp *opp)
 	return 0;
 }
 
+static inline unsigned long dev_pm_opp_get_freq_indexed(struct dev_pm_opp *opp, u32 index)
+{
+	return 0;
+}
+
 static inline unsigned int dev_pm_opp_get_level(struct dev_pm_opp *opp)
 {
 	return 0;
-- 
2.31.1.272.g89b43f80a514


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 4/6] OPP: Add dev_pm_opp_find_freq_exact_indexed()
  2023-07-21  9:40 [PATCH 0/6] OPP: Indexed searching based on frequency Viresh Kumar
                   ` (2 preceding siblings ...)
  2023-07-21  9:40 ` [PATCH 3/6] OPP: Introduce dev_pm_opp_get_freq_indexed() API Viresh Kumar
@ 2023-07-21  9:40 ` Viresh Kumar
  2023-07-24  6:24   ` Manivannan Sadhasivam
  2023-07-21  9:40 ` [PATCH 5/6] OPP: Update _read_freq() to return the correct frequency Viresh Kumar
  2023-07-21  9:40 ` [PATCH 6/6] OPP: Reuse dev_pm_opp_get_freq_indexed() Viresh Kumar
  5 siblings, 1 reply; 11+ messages in thread
From: Viresh Kumar @ 2023-07-21  9:40 UTC (permalink / raw)
  To: Viresh Kumar, Nishanth Menon, Stephen Boyd, Rafael J. Wysocki
  Cc: Viresh Kumar, linux-pm, Vincent Guittot, Manivannan Sadhasivam,
	linux-kernel

The indexed version of the API is added for other floor and ceil, add
the same for exact as well for completeness.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
 drivers/opp/core.c     | 28 ++++++++++++++++++++++++++++
 include/linux/pm_opp.h | 11 +++++++++++
 2 files changed, 39 insertions(+)

diff --git a/drivers/opp/core.c b/drivers/opp/core.c
index 00638d40353f..7b1d5724b3d8 100644
--- a/drivers/opp/core.c
+++ b/drivers/opp/core.c
@@ -648,6 +648,34 @@ struct dev_pm_opp *dev_pm_opp_find_freq_exact(struct device *dev,
 }
 EXPORT_SYMBOL_GPL(dev_pm_opp_find_freq_exact);
 
+/**
+ * dev_pm_opp_find_freq_exact_indexed() - Search for an exact freq for the
+ *					 clock corresponding to the index
+ * @dev:	Device for which we do this operation
+ * @freq:	frequency to search for
+ * @index:	Clock index
+ * @available:	true/false - match for available opp
+ *
+ * Search for the matching exact OPP for the clock corresponding to the
+ * specified index from a starting freq for a device.
+ *
+ * Return: matching *opp , else returns ERR_PTR in case of error and should be
+ * handled using IS_ERR. Error return values can be:
+ * EINVAL:	for bad pointer
+ * ERANGE:	no match found for search
+ * ENODEV:	if device not found in list of registered devices
+ *
+ * The callers are required to call dev_pm_opp_put() for the returned OPP after
+ * use.
+ */
+struct dev_pm_opp *
+dev_pm_opp_find_freq_exact_indexed(struct device *dev, unsigned long freq,
+				   u32 index, bool available)
+{
+	return _find_key_exact(dev, freq, index, available, _read_freq, NULL);
+}
+EXPORT_SYMBOL_GPL(dev_pm_opp_find_freq_exact_indexed);
+
 static noinline struct dev_pm_opp *_find_freq_ceil(struct opp_table *opp_table,
 						   unsigned long *freq)
 {
diff --git a/include/linux/pm_opp.h b/include/linux/pm_opp.h
index a13a1705df57..23e4e4eaaa42 100644
--- a/include/linux/pm_opp.h
+++ b/include/linux/pm_opp.h
@@ -124,6 +124,10 @@ struct dev_pm_opp *dev_pm_opp_find_freq_exact(struct device *dev,
 					      unsigned long freq,
 					      bool available);
 
+struct dev_pm_opp *
+dev_pm_opp_find_freq_exact_indexed(struct device *dev, unsigned long freq,
+				   u32 index, bool available);
+
 struct dev_pm_opp *dev_pm_opp_find_freq_floor(struct device *dev,
 					      unsigned long *freq);
 
@@ -268,6 +272,13 @@ static inline struct dev_pm_opp *dev_pm_opp_find_freq_exact(struct device *dev,
 	return ERR_PTR(-EOPNOTSUPP);
 }
 
+static inline struct dev_pm_opp *
+dev_pm_opp_find_freq_exact_indexed(struct device *dev, unsigned long freq,
+				   u32 index, bool available)
+{
+	return ERR_PTR(-EOPNOTSUPP);
+}
+
 static inline struct dev_pm_opp *dev_pm_opp_find_freq_floor(struct device *dev,
 					unsigned long *freq)
 {
-- 
2.31.1.272.g89b43f80a514


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 5/6] OPP: Update _read_freq() to return the correct frequency
  2023-07-21  9:40 [PATCH 0/6] OPP: Indexed searching based on frequency Viresh Kumar
                   ` (3 preceding siblings ...)
  2023-07-21  9:40 ` [PATCH 4/6] OPP: Add dev_pm_opp_find_freq_exact_indexed() Viresh Kumar
@ 2023-07-21  9:40 ` Viresh Kumar
  2023-07-24  6:25   ` Manivannan Sadhasivam
  2023-07-21  9:40 ` [PATCH 6/6] OPP: Reuse dev_pm_opp_get_freq_indexed() Viresh Kumar
  5 siblings, 1 reply; 11+ messages in thread
From: Viresh Kumar @ 2023-07-21  9:40 UTC (permalink / raw)
  To: Viresh Kumar, Nishanth Menon, Stephen Boyd
  Cc: Viresh Kumar, linux-pm, Vincent Guittot, Rafael J. Wysocki,
	Manivannan Sadhasivam, linux-kernel

Now that we support finding indexed frequencies, lets update
_read_freq() to return the right one.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
 drivers/opp/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/opp/core.c b/drivers/opp/core.c
index 7b1d5724b3d8..95f49fbe431c 100644
--- a/drivers/opp/core.c
+++ b/drivers/opp/core.c
@@ -472,7 +472,7 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_get_opp_count);
 /* Helpers to read keys */
 static unsigned long _read_freq(struct dev_pm_opp *opp, int index)
 {
-	return opp->rates[0];
+	return opp->rates[index];
 }
 
 static unsigned long _read_level(struct dev_pm_opp *opp, int index)
-- 
2.31.1.272.g89b43f80a514


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 6/6] OPP: Reuse dev_pm_opp_get_freq_indexed()
  2023-07-21  9:40 [PATCH 0/6] OPP: Indexed searching based on frequency Viresh Kumar
                   ` (4 preceding siblings ...)
  2023-07-21  9:40 ` [PATCH 5/6] OPP: Update _read_freq() to return the correct frequency Viresh Kumar
@ 2023-07-21  9:40 ` Viresh Kumar
  2023-07-24  6:26   ` Manivannan Sadhasivam
  5 siblings, 1 reply; 11+ messages in thread
From: Viresh Kumar @ 2023-07-21  9:40 UTC (permalink / raw)
  To: Viresh Kumar, Nishanth Menon, Stephen Boyd, Rafael J. Wysocki
  Cc: Viresh Kumar, linux-pm, Vincent Guittot, Manivannan Sadhasivam,
	linux-kernel

Reuse dev_pm_opp_get_freq_indexed() from dev_pm_opp_get_freq().

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
 drivers/opp/core.c     | 21 ---------------------
 include/linux/pm_opp.h | 12 +++++-------
 2 files changed, 5 insertions(+), 28 deletions(-)

diff --git a/drivers/opp/core.c b/drivers/opp/core.c
index 95f49fbe431c..16a103e6695b 100644
--- a/drivers/opp/core.c
+++ b/drivers/opp/core.c
@@ -176,27 +176,6 @@ unsigned long dev_pm_opp_get_power(struct dev_pm_opp *opp)
 }
 EXPORT_SYMBOL_GPL(dev_pm_opp_get_power);
 
-/**
- * dev_pm_opp_get_freq() - Gets the frequency corresponding to an available opp
- * @opp:	opp for which frequency has to be returned for
- *
- * Return: frequency in hertz corresponding to the opp, else
- * return 0
- */
-unsigned long dev_pm_opp_get_freq(struct dev_pm_opp *opp)
-{
-	if (IS_ERR_OR_NULL(opp)) {
-		pr_err("%s: Invalid parameters\n", __func__);
-		return 0;
-	}
-
-	if (!assert_single_clk(opp->opp_table))
-		return 0;
-
-	return opp->rates[0];
-}
-EXPORT_SYMBOL_GPL(dev_pm_opp_get_freq);
-
 /**
  * dev_pm_opp_get_freq_indexed() - Gets the frequency corresponding to an
  *				   available opp with specified index
diff --git a/include/linux/pm_opp.h b/include/linux/pm_opp.h
index 23e4e4eaaa42..91f87d7e807c 100644
--- a/include/linux/pm_opp.h
+++ b/include/linux/pm_opp.h
@@ -103,8 +103,6 @@ int dev_pm_opp_get_supplies(struct dev_pm_opp *opp, struct dev_pm_opp_supply *su
 
 unsigned long dev_pm_opp_get_power(struct dev_pm_opp *opp);
 
-unsigned long dev_pm_opp_get_freq(struct dev_pm_opp *opp);
-
 unsigned long dev_pm_opp_get_freq_indexed(struct dev_pm_opp *opp, u32 index);
 
 unsigned int dev_pm_opp_get_level(struct dev_pm_opp *opp);
@@ -214,11 +212,6 @@ static inline unsigned long dev_pm_opp_get_power(struct dev_pm_opp *opp)
 	return 0;
 }
 
-static inline unsigned long dev_pm_opp_get_freq(struct dev_pm_opp *opp)
-{
-	return 0;
-}
-
 static inline unsigned long dev_pm_opp_get_freq_indexed(struct dev_pm_opp *opp, u32 index)
 {
 	return 0;
@@ -669,4 +662,9 @@ static inline void dev_pm_opp_put_prop_name(int token)
 	dev_pm_opp_clear_config(token);
 }
 
+static inline unsigned long dev_pm_opp_get_freq(struct dev_pm_opp *opp)
+{
+	return dev_pm_opp_get_freq_indexed(opp, 0);
+}
+
 #endif		/* __LINUX_OPP_H__ */
-- 
2.31.1.272.g89b43f80a514


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH 4/6] OPP: Add dev_pm_opp_find_freq_exact_indexed()
  2023-07-21  9:40 ` [PATCH 4/6] OPP: Add dev_pm_opp_find_freq_exact_indexed() Viresh Kumar
@ 2023-07-24  6:24   ` Manivannan Sadhasivam
  2023-07-24  7:31     ` Viresh Kumar
  0 siblings, 1 reply; 11+ messages in thread
From: Manivannan Sadhasivam @ 2023-07-24  6:24 UTC (permalink / raw)
  To: Viresh Kumar
  Cc: Viresh Kumar, Nishanth Menon, Stephen Boyd, Rafael J. Wysocki,
	linux-pm, Vincent Guittot, linux-kernel

On Fri, Jul 21, 2023 at 03:10:57PM +0530, Viresh Kumar wrote:
> The indexed version of the API is added for other floor and ceil, add
> the same for exact as well for completeness.
> 

Well, "completeness" makes sense to me but I always heard that you should add
an API when there is a user. That was the reason I didn't add it in my patch.

- Mani

> Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
> ---
>  drivers/opp/core.c     | 28 ++++++++++++++++++++++++++++
>  include/linux/pm_opp.h | 11 +++++++++++
>  2 files changed, 39 insertions(+)
> 
> diff --git a/drivers/opp/core.c b/drivers/opp/core.c
> index 00638d40353f..7b1d5724b3d8 100644
> --- a/drivers/opp/core.c
> +++ b/drivers/opp/core.c
> @@ -648,6 +648,34 @@ struct dev_pm_opp *dev_pm_opp_find_freq_exact(struct device *dev,
>  }
>  EXPORT_SYMBOL_GPL(dev_pm_opp_find_freq_exact);
>  
> +/**
> + * dev_pm_opp_find_freq_exact_indexed() - Search for an exact freq for the
> + *					 clock corresponding to the index
> + * @dev:	Device for which we do this operation
> + * @freq:	frequency to search for
> + * @index:	Clock index
> + * @available:	true/false - match for available opp
> + *
> + * Search for the matching exact OPP for the clock corresponding to the
> + * specified index from a starting freq for a device.
> + *
> + * Return: matching *opp , else returns ERR_PTR in case of error and should be
> + * handled using IS_ERR. Error return values can be:
> + * EINVAL:	for bad pointer
> + * ERANGE:	no match found for search
> + * ENODEV:	if device not found in list of registered devices
> + *
> + * The callers are required to call dev_pm_opp_put() for the returned OPP after
> + * use.
> + */
> +struct dev_pm_opp *
> +dev_pm_opp_find_freq_exact_indexed(struct device *dev, unsigned long freq,
> +				   u32 index, bool available)
> +{
> +	return _find_key_exact(dev, freq, index, available, _read_freq, NULL);
> +}
> +EXPORT_SYMBOL_GPL(dev_pm_opp_find_freq_exact_indexed);
> +
>  static noinline struct dev_pm_opp *_find_freq_ceil(struct opp_table *opp_table,
>  						   unsigned long *freq)
>  {
> diff --git a/include/linux/pm_opp.h b/include/linux/pm_opp.h
> index a13a1705df57..23e4e4eaaa42 100644
> --- a/include/linux/pm_opp.h
> +++ b/include/linux/pm_opp.h
> @@ -124,6 +124,10 @@ struct dev_pm_opp *dev_pm_opp_find_freq_exact(struct device *dev,
>  					      unsigned long freq,
>  					      bool available);
>  
> +struct dev_pm_opp *
> +dev_pm_opp_find_freq_exact_indexed(struct device *dev, unsigned long freq,
> +				   u32 index, bool available);
> +
>  struct dev_pm_opp *dev_pm_opp_find_freq_floor(struct device *dev,
>  					      unsigned long *freq);
>  
> @@ -268,6 +272,13 @@ static inline struct dev_pm_opp *dev_pm_opp_find_freq_exact(struct device *dev,
>  	return ERR_PTR(-EOPNOTSUPP);
>  }
>  
> +static inline struct dev_pm_opp *
> +dev_pm_opp_find_freq_exact_indexed(struct device *dev, unsigned long freq,
> +				   u32 index, bool available)
> +{
> +	return ERR_PTR(-EOPNOTSUPP);
> +}
> +
>  static inline struct dev_pm_opp *dev_pm_opp_find_freq_floor(struct device *dev,
>  					unsigned long *freq)
>  {
> -- 
> 2.31.1.272.g89b43f80a514
> 

-- 
மணிவண்ணன் சதாசிவம்

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 5/6] OPP: Update _read_freq() to return the correct frequency
  2023-07-21  9:40 ` [PATCH 5/6] OPP: Update _read_freq() to return the correct frequency Viresh Kumar
@ 2023-07-24  6:25   ` Manivannan Sadhasivam
  0 siblings, 0 replies; 11+ messages in thread
From: Manivannan Sadhasivam @ 2023-07-24  6:25 UTC (permalink / raw)
  To: Viresh Kumar
  Cc: Viresh Kumar, Nishanth Menon, Stephen Boyd, linux-pm,
	Vincent Guittot, Rafael J. Wysocki, linux-kernel

On Fri, Jul 21, 2023 at 03:10:58PM +0530, Viresh Kumar wrote:
> Now that we support finding indexed frequencies, lets update
> _read_freq() to return the right one.
> 
> Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>

Acked-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>

- Mani

> ---
>  drivers/opp/core.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/opp/core.c b/drivers/opp/core.c
> index 7b1d5724b3d8..95f49fbe431c 100644
> --- a/drivers/opp/core.c
> +++ b/drivers/opp/core.c
> @@ -472,7 +472,7 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_get_opp_count);
>  /* Helpers to read keys */
>  static unsigned long _read_freq(struct dev_pm_opp *opp, int index)
>  {
> -	return opp->rates[0];
> +	return opp->rates[index];
>  }
>  
>  static unsigned long _read_level(struct dev_pm_opp *opp, int index)
> -- 
> 2.31.1.272.g89b43f80a514
> 

-- 
மணிவண்ணன் சதாசிவம்

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 6/6] OPP: Reuse dev_pm_opp_get_freq_indexed()
  2023-07-21  9:40 ` [PATCH 6/6] OPP: Reuse dev_pm_opp_get_freq_indexed() Viresh Kumar
@ 2023-07-24  6:26   ` Manivannan Sadhasivam
  0 siblings, 0 replies; 11+ messages in thread
From: Manivannan Sadhasivam @ 2023-07-24  6:26 UTC (permalink / raw)
  To: Viresh Kumar
  Cc: Viresh Kumar, Nishanth Menon, Stephen Boyd, Rafael J. Wysocki,
	linux-pm, Vincent Guittot, linux-kernel

On Fri, Jul 21, 2023 at 03:10:59PM +0530, Viresh Kumar wrote:
> Reuse dev_pm_opp_get_freq_indexed() from dev_pm_opp_get_freq().
> 
> Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>

Acked-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>

- Mani

> ---
>  drivers/opp/core.c     | 21 ---------------------
>  include/linux/pm_opp.h | 12 +++++-------
>  2 files changed, 5 insertions(+), 28 deletions(-)
> 
> diff --git a/drivers/opp/core.c b/drivers/opp/core.c
> index 95f49fbe431c..16a103e6695b 100644
> --- a/drivers/opp/core.c
> +++ b/drivers/opp/core.c
> @@ -176,27 +176,6 @@ unsigned long dev_pm_opp_get_power(struct dev_pm_opp *opp)
>  }
>  EXPORT_SYMBOL_GPL(dev_pm_opp_get_power);
>  
> -/**
> - * dev_pm_opp_get_freq() - Gets the frequency corresponding to an available opp
> - * @opp:	opp for which frequency has to be returned for
> - *
> - * Return: frequency in hertz corresponding to the opp, else
> - * return 0
> - */
> -unsigned long dev_pm_opp_get_freq(struct dev_pm_opp *opp)
> -{
> -	if (IS_ERR_OR_NULL(opp)) {
> -		pr_err("%s: Invalid parameters\n", __func__);
> -		return 0;
> -	}
> -
> -	if (!assert_single_clk(opp->opp_table))
> -		return 0;
> -
> -	return opp->rates[0];
> -}
> -EXPORT_SYMBOL_GPL(dev_pm_opp_get_freq);
> -
>  /**
>   * dev_pm_opp_get_freq_indexed() - Gets the frequency corresponding to an
>   *				   available opp with specified index
> diff --git a/include/linux/pm_opp.h b/include/linux/pm_opp.h
> index 23e4e4eaaa42..91f87d7e807c 100644
> --- a/include/linux/pm_opp.h
> +++ b/include/linux/pm_opp.h
> @@ -103,8 +103,6 @@ int dev_pm_opp_get_supplies(struct dev_pm_opp *opp, struct dev_pm_opp_supply *su
>  
>  unsigned long dev_pm_opp_get_power(struct dev_pm_opp *opp);
>  
> -unsigned long dev_pm_opp_get_freq(struct dev_pm_opp *opp);
> -
>  unsigned long dev_pm_opp_get_freq_indexed(struct dev_pm_opp *opp, u32 index);
>  
>  unsigned int dev_pm_opp_get_level(struct dev_pm_opp *opp);
> @@ -214,11 +212,6 @@ static inline unsigned long dev_pm_opp_get_power(struct dev_pm_opp *opp)
>  	return 0;
>  }
>  
> -static inline unsigned long dev_pm_opp_get_freq(struct dev_pm_opp *opp)
> -{
> -	return 0;
> -}
> -
>  static inline unsigned long dev_pm_opp_get_freq_indexed(struct dev_pm_opp *opp, u32 index)
>  {
>  	return 0;
> @@ -669,4 +662,9 @@ static inline void dev_pm_opp_put_prop_name(int token)
>  	dev_pm_opp_clear_config(token);
>  }
>  
> +static inline unsigned long dev_pm_opp_get_freq(struct dev_pm_opp *opp)
> +{
> +	return dev_pm_opp_get_freq_indexed(opp, 0);
> +}
> +
>  #endif		/* __LINUX_OPP_H__ */
> -- 
> 2.31.1.272.g89b43f80a514
> 

-- 
மணிவண்ணன் சதாசிவம்

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 4/6] OPP: Add dev_pm_opp_find_freq_exact_indexed()
  2023-07-24  6:24   ` Manivannan Sadhasivam
@ 2023-07-24  7:31     ` Viresh Kumar
  0 siblings, 0 replies; 11+ messages in thread
From: Viresh Kumar @ 2023-07-24  7:31 UTC (permalink / raw)
  To: Manivannan Sadhasivam
  Cc: Viresh Kumar, Nishanth Menon, Stephen Boyd, Rafael J. Wysocki,
	linux-pm, Vincent Guittot, linux-kernel

On 24-07-23, 11:54, Manivannan Sadhasivam wrote:
> On Fri, Jul 21, 2023 at 03:10:57PM +0530, Viresh Kumar wrote:
> > The indexed version of the API is added for other floor and ceil, add
> > the same for exact as well for completeness.
> > 
> 
> Well, "completeness" makes sense to me but I always heard that you should add
> an API when there is a user. That was the reason I didn't add it in my patch.

Yes that is true for any new API I guess. But since we support multiple clocks,
it made sense to support all three variants here.

-- 
viresh

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2023-07-24  7:31 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-21  9:40 [PATCH 0/6] OPP: Indexed searching based on frequency Viresh Kumar
2023-07-21  9:40 ` [PATCH 1/6] OPP: Rearrange entries in pm_opp.h Viresh Kumar
2023-07-21  9:40 ` [PATCH 2/6] OPP: Introduce dev_pm_opp_find_freq_{ceil/floor}_indexed() APIs Viresh Kumar
2023-07-21  9:40 ` [PATCH 3/6] OPP: Introduce dev_pm_opp_get_freq_indexed() API Viresh Kumar
2023-07-21  9:40 ` [PATCH 4/6] OPP: Add dev_pm_opp_find_freq_exact_indexed() Viresh Kumar
2023-07-24  6:24   ` Manivannan Sadhasivam
2023-07-24  7:31     ` Viresh Kumar
2023-07-21  9:40 ` [PATCH 5/6] OPP: Update _read_freq() to return the correct frequency Viresh Kumar
2023-07-24  6:25   ` Manivannan Sadhasivam
2023-07-21  9:40 ` [PATCH 6/6] OPP: Reuse dev_pm_opp_get_freq_indexed() Viresh Kumar
2023-07-24  6:26   ` Manivannan Sadhasivam

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).