generic: copy backport, hack, pending patch and config from 6.1 to 6.6
[openwrt/openwrt.git] / target / linux / generic / pending-6.6 / 802-OPP-Provide-old-opp-to-config_clks-on-_set_opp.patch
1 From fd59b838dd90452f61a17dc9e5ff175205003068 Mon Sep 17 00:00:00 2001
2 From: Christian Marangi <ansuelsmth@gmail.com>
3 Date: Thu, 15 Sep 2022 18:49:43 +0200
4 Subject: [PATCH] OPP: Provide old opp to config_clks on _set_opp
5
6 With the target opp, also pass the old opp to config_clks function.
7 This can be useful when a driver needs to take decision on what fequency
8 to set based on what is the current frequency without using a
9 clk_get_freq call.
10 Update the only user of custom config_clks (tegra30 devfreq driver) to
11 this new implementation.
12
13 Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
14 ---
15 drivers/devfreq/tegra30-devfreq.c | 5 +++--
16 drivers/opp/core.c | 11 ++++++-----
17 include/linux/pm_opp.h | 11 ++++++-----
18 3 files changed, 15 insertions(+), 12 deletions(-)
19
20 --- a/drivers/devfreq/tegra30-devfreq.c
21 +++ b/drivers/devfreq/tegra30-devfreq.c
22 @@ -823,8 +823,9 @@ static int devm_tegra_devfreq_init_hw(st
23
24 static int tegra_devfreq_config_clks_nop(struct device *dev,
25 struct opp_table *opp_table,
26 - struct dev_pm_opp *opp, void *data,
27 - bool scaling_down)
28 + struct dev_pm_opp *old_opp,
29 + struct dev_pm_opp *opp,
30 + void *data, bool scaling_down)
31 {
32 /* We want to skip clk configuration via dev_pm_opp_set_opp() */
33 return 0;
34 --- a/drivers/opp/core.c
35 +++ b/drivers/opp/core.c
36 @@ -816,7 +816,8 @@ static int _set_opp_voltage(struct devic
37
38 static int
39 _opp_config_clk_single(struct device *dev, struct opp_table *opp_table,
40 - struct dev_pm_opp *opp, void *data, bool scaling_down)
41 + struct dev_pm_opp *old_opp, struct dev_pm_opp *opp,
42 + void *data, bool scaling_down)
43 {
44 unsigned long *target = data;
45 unsigned long freq;
46 @@ -848,8 +849,8 @@ _opp_config_clk_single(struct device *de
47 * the order in which they are present in the array while scaling up.
48 */
49 int dev_pm_opp_config_clks_simple(struct device *dev,
50 - struct opp_table *opp_table, struct dev_pm_opp *opp, void *data,
51 - bool scaling_down)
52 + struct opp_table *opp_table, struct dev_pm_opp *old_opp,
53 + struct dev_pm_opp *opp, void *data, bool scaling_down)
54 {
55 int ret, i;
56
57 @@ -1121,7 +1122,7 @@ static int _set_opp(struct device *dev,
58 }
59
60 if (opp_table->config_clks) {
61 - ret = opp_table->config_clks(dev, opp_table, opp, clk_data, scaling_down);
62 + ret = opp_table->config_clks(dev, opp_table, old_opp, opp, clk_data, scaling_down);
63 if (ret)
64 return ret;
65 }
66 @@ -1196,7 +1197,7 @@ int dev_pm_opp_set_rate(struct device *d
67 * equivalent to a clk_set_rate()
68 */
69 if (!_get_opp_count(opp_table)) {
70 - ret = opp_table->config_clks(dev, opp_table, NULL,
71 + ret = opp_table->config_clks(dev, opp_table, NULL, NULL,
72 &target_freq, false);
73 goto put_opp_table;
74 }
75 --- a/include/linux/pm_opp.h
76 +++ b/include/linux/pm_opp.h
77 @@ -61,7 +61,8 @@ typedef int (*config_regulators_t)(struc
78 struct dev_pm_opp *old_opp, struct dev_pm_opp *new_opp,
79 struct regulator **regulators, unsigned int count);
80
81 -typedef int (*config_clks_t)(struct device *dev, struct opp_table *opp_table,
82 +typedef int (*config_clks_t)(struct device *dev,
83 + struct opp_table *opp_table, struct dev_pm_opp *old_opp,
84 struct dev_pm_opp *opp, void *data, bool scaling_down);
85
86 /**
87 @@ -160,8 +161,8 @@ int dev_pm_opp_set_config(struct device
88 int devm_pm_opp_set_config(struct device *dev, struct dev_pm_opp_config *config);
89 void dev_pm_opp_clear_config(int token);
90 int dev_pm_opp_config_clks_simple(struct device *dev,
91 - struct opp_table *opp_table, struct dev_pm_opp *opp, void *data,
92 - bool scaling_down);
93 + struct opp_table *opp_table, struct dev_pm_opp *old_opp,
94 + struct dev_pm_opp *opp, void *data, bool scaling_down);
95
96 struct dev_pm_opp *dev_pm_opp_xlate_required_opp(struct opp_table *src_table, struct opp_table *dst_table, struct dev_pm_opp *src_opp);
97 int dev_pm_opp_xlate_performance_state(struct opp_table *src_table, struct opp_table *dst_table, unsigned int pstate);
98 @@ -346,8 +347,8 @@ static inline int devm_pm_opp_set_config
99 static inline void dev_pm_opp_clear_config(int token) {}
100
101 static inline int dev_pm_opp_config_clks_simple(struct device *dev,
102 - struct opp_table *opp_table, struct dev_pm_opp *opp, void *data,
103 - bool scaling_down)
104 + struct opp_table *opp_table, struct dev_pm_opp *old_opp,
105 + struct dev_pm_opp *opp, void *data, bool scaling_down)
106 {
107 return -EOPNOTSUPP;
108 }