armbian_build/patch/kernel/archive/sunxi-5.15/megous/PM-devfreq-Add-a-recommended-frequency-helper.patch
The-going 33c413c679
Patches megous 5.15.5 (#3295)
* Rework patches for sunxi 5.15.4

* Rework patches sunxi for 5.15.5

* Kernel switch tag=v5.15.5 for sunxi EDGE

* Temporarily disabled, requires rework.

drivers/clk/sunxi-ng/sun8i-de33.c: In function ‘sunxi_de33_clk_probe’:
drivers/clk/sunxi-ng/sun8i-de33.c:155:8:
 error: implicit declaration of function ‘sunxi_ccu_probe’;
 did you mean ‘of_sunxi_ccu_probe’? [-Werror=implicit-function-declarati>
  ret = sunxi_ccu_probe(pdev->dev.of_node, reg, ccu_desc);
        ^~~~~~~~~~~~~~~
        of_sunxi_ccu_probe
cc1: some warnings being treated as errors
make[3]: *** [scripts/Makefile.build:277:
         drivers/clk/sunxi-ng/sun8i-de33.o] Error 1
make[2]: *** [scripts/Makefile.build:540: drivers/clk/sunxi-ng] Error 2

* Correct the comment.
2021-11-28 16:48:47 +01:00

72 lines
2.5 KiB
Diff

From 2ca5ff6734e0aa59b8f6979da2252dc919837fe6 Mon Sep 17 00:00:00 2001
From: Samuel Holland <samuel@sholland.org>
Date: Sat, 3 Apr 2021 17:07:13 -0500
Subject: [PATCH 410/467] PM / devfreq: Add a recommended frequency helper
This helper peforms the same function as devfreq_recommended_opp().
However, it works on devices without OPPs by iterating over freq_table.
Since freq_table is assumed to be sorted in ascending order, the
algorithm is relatively simple.
Devices with OPPs should continue using devfreq_recommended_opp(), as
that function respects disabled OPPs.
Signed-off-by: Samuel Holland <samuel@sholland.org>
---
drivers/devfreq/devfreq.c | 25 +++++++++++++++++++++++++
include/linux/devfreq.h | 2 ++
2 files changed, 27 insertions(+)
diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
index 9606eab1a..ea1126c31 100644
--- a/drivers/devfreq/devfreq.c
+++ b/drivers/devfreq/devfreq.c
@@ -1984,6 +1984,31 @@ subsys_initcall(devfreq_init);
* OPP framework.
*/
+/**
+ * devfreq_recommended_freq() - Helper function to get the proper frequency from
+ * freq_table for the value given to target callback.
+ * @devfreq: The devfreq device.
+ * @freq: The frequency given to target function.
+ * @flags: Flags handed from devfreq framework.
+ */
+void devfreq_recommended_freq(struct devfreq *devfreq,
+ unsigned long *freq, u32 flags)
+{
+ const unsigned long *min = devfreq->profile->freq_table;
+ const unsigned long *max = min + devfreq->profile->max_state - 1;
+ const unsigned long *f;
+
+ if (flags & DEVFREQ_FLAG_LEAST_UPPER_BOUND) {
+ /* Find the first item lower than freq, or else min. */
+ for (f = max; f > min && *f > *freq; --f);
+ } else {
+ /* Find the first item higher than freq, or else max. */
+ for (f = min; f < max && *f < *freq; ++f);
+ }
+ *freq = *f;
+}
+EXPORT_SYMBOL(devfreq_recommended_freq);
+
/**
* devfreq_recommended_opp() - Helper function to get proper OPP for the
* freq value given to target callback.
diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
index 142474b4a..4d324fea8 100644
--- a/include/linux/devfreq.h
+++ b/include/linux/devfreq.h
@@ -239,6 +239,8 @@ void devfreq_resume(void);
int update_devfreq(struct devfreq *devfreq);
/* Helper functions for devfreq user device driver with OPP. */
+void devfreq_recommended_freq(struct devfreq *devfreq,
+ unsigned long *freq, u32 flags);
struct dev_pm_opp *devfreq_recommended_opp(struct device *dev,
unsigned long *freq, u32 flags);
int devfreq_register_opp_notifier(struct device *dev,
--
2.34.0