generic: 6.1: add pending OPP set opp improvement patch
[openwrt/staging/ldir.git] / target / linux / generic / pending-6.1 / 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 diff --git a/drivers/devfreq/tegra30-devfreq.c b/drivers/devfreq/tegra30-devfreq.c
21 index 503376b894b6..92cdb6bf9a89 100644
22 --- a/drivers/devfreq/tegra30-devfreq.c
23 +++ b/drivers/devfreq/tegra30-devfreq.c
24 @@ -823,8 +823,9 @@ static int devm_tegra_devfreq_init_hw(struct device *dev,
25
26 static int tegra_devfreq_config_clks_nop(struct device *dev,
27 struct opp_table *opp_table,
28 - struct dev_pm_opp *opp, void *data,
29 - bool scaling_down)
30 + struct dev_pm_opp *old_opp,
31 + struct dev_pm_opp *opp,
32 + void *data, bool scaling_down)
33 {
34 /* We want to skip clk configuration via dev_pm_opp_set_opp() */
35 return 0;
36 diff --git a/drivers/opp/core.c b/drivers/opp/core.c
37 index e87567dbe99f..2f44ceaf8d3c 100644
38 --- a/drivers/opp/core.c
39 +++ b/drivers/opp/core.c
40 @@ -816,7 +816,8 @@ static int _set_opp_voltage(struct device *dev, struct regulator *reg,
41
42 static int
43 _opp_config_clk_single(struct device *dev, struct opp_table *opp_table,
44 - struct dev_pm_opp *opp, void *data, bool scaling_down)
45 + struct dev_pm_opp *old_opp, struct dev_pm_opp *opp,
46 + void *data, bool scaling_down)
47 {
48 unsigned long *target = data;
49 unsigned long freq;
50 @@ -848,8 +849,8 @@ _opp_config_clk_single(struct device *dev, struct opp_table *opp_table,
51 * the order in which they are present in the array while scaling up.
52 */
53 int dev_pm_opp_config_clks_simple(struct device *dev,
54 - struct opp_table *opp_table, struct dev_pm_opp *opp, void *data,
55 - bool scaling_down)
56 + struct opp_table *opp_table, struct dev_pm_opp *old_opp,
57 + struct dev_pm_opp *opp, void *data, bool scaling_down)
58 {
59 int ret, i;
60
61 @@ -1121,7 +1122,7 @@ static int _set_opp(struct device *dev, struct opp_table *opp_table,
62 }
63
64 if (opp_table->config_clks) {
65 - ret = opp_table->config_clks(dev, opp_table, opp, clk_data, scaling_down);
66 + ret = opp_table->config_clks(dev, opp_table, old_opp, opp, clk_data, scaling_down);
67 if (ret)
68 return ret;
69 }
70 @@ -1196,7 +1197,7 @@ int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq)
71 * equivalent to a clk_set_rate()
72 */
73 if (!_get_opp_count(opp_table)) {
74 - ret = opp_table->config_clks(dev, opp_table, NULL,
75 + ret = opp_table->config_clks(dev, opp_table, NULL, NULL,
76 &target_freq, false);
77 goto put_opp_table;
78 }
79 diff --git a/include/linux/pm_opp.h b/include/linux/pm_opp.h
80 index dc1fb5890792..6c24a4f9fc49 100644
81 --- a/include/linux/pm_opp.h
82 +++ b/include/linux/pm_opp.h
83 @@ -61,7 +61,8 @@ typedef int (*config_regulators_t)(struct device *dev,
84 struct dev_pm_opp *old_opp, struct dev_pm_opp *new_opp,
85 struct regulator **regulators, unsigned int count);
86
87 -typedef int (*config_clks_t)(struct device *dev, struct opp_table *opp_table,
88 +typedef int (*config_clks_t)(struct device *dev,
89 + struct opp_table *opp_table, struct dev_pm_opp *old_opp,
90 struct dev_pm_opp *opp, void *data, bool scaling_down);
91
92 /**
93 @@ -160,8 +161,8 @@ int dev_pm_opp_set_config(struct device *dev, struct dev_pm_opp_config *config);
94 int devm_pm_opp_set_config(struct device *dev, struct dev_pm_opp_config *config);
95 void dev_pm_opp_clear_config(int token);
96 int dev_pm_opp_config_clks_simple(struct device *dev,
97 - struct opp_table *opp_table, struct dev_pm_opp *opp, void *data,
98 - bool scaling_down);
99 + struct opp_table *opp_table, struct dev_pm_opp *old_opp,
100 + struct dev_pm_opp *opp, void *data, bool scaling_down);
101
102 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);
103 int dev_pm_opp_xlate_performance_state(struct opp_table *src_table, struct opp_table *dst_table, unsigned int pstate);
104 @@ -346,8 +347,8 @@ static inline int devm_pm_opp_set_config(struct device *dev, struct dev_pm_opp_c
105 static inline void dev_pm_opp_clear_config(int token) {}
106
107 static inline int dev_pm_opp_config_clks_simple(struct device *dev,
108 - struct opp_table *opp_table, struct dev_pm_opp *opp, void *data,
109 - bool scaling_down)
110 + struct opp_table *opp_table, struct dev_pm_opp *old_opp,
111 + struct dev_pm_opp *opp, void *data, bool scaling_down)
112 {
113 return -EOPNOTSUPP;
114 }
115 --
116 2.37.2
117