cb10bd1b62cd2a08eb6583c196a149dd624b7240
[openwrt/openwrt.git] / target / linux / ipq806x / patches-5.15 / 111-v5.19-03-PM-devfreq-passive-Reduce-duplicate-code-when-passiv.patch
1 From 05723e71234b60a1a47313ea1a889797ec648f1c Mon Sep 17 00:00:00 2001
2 From: Chanwoo Choi <cw00.choi@samsung.com>
3 Date: Tue, 2 Mar 2021 17:22:50 +0900
4 Subject: [PATCH 3/5] PM / devfreq: passive: Reduce duplicate code when
5 passive_devfreq case
6
7 In order to keep the consistent coding style between passive_devfreq
8 and passive_cpufreq, use common code for handling required opp property.
9 Also remove the unneed conditional statement and unify the comment
10 of both passive_devfreq and passive_cpufreq when getting the target frequency.
11
12 Tested-by: Chen-Yu Tsai <wenst@chromium.org>
13 Tested-by: Johnson Wang <johnson.wang@mediatek.com>
14 Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
15 ---
16 drivers/devfreq/governor_passive.c | 66 ++++--------------------------
17 1 file changed, 8 insertions(+), 58 deletions(-)
18
19 --- a/drivers/devfreq/governor_passive.c
20 +++ b/drivers/devfreq/governor_passive.c
21 @@ -93,65 +93,16 @@ static int get_target_freq_with_devfreq(
22 = (struct devfreq_passive_data *)devfreq->data;
23 struct devfreq *parent_devfreq = (struct devfreq *)p_data->parent;
24 unsigned long child_freq = ULONG_MAX;
25 - struct dev_pm_opp *opp, *p_opp;
26 int i, count;
27
28 - /*
29 - * If the devfreq device with passive governor has the specific method
30 - * to determine the next frequency, should use the get_target_freq()
31 - * of struct devfreq_passive_data.
32 - */
33 - if (p_data->get_target_freq)
34 - return p_data->get_target_freq(devfreq, freq);
35 -
36 - /*
37 - * If the parent and passive devfreq device uses the OPP table,
38 - * get the next frequency by using the OPP table.
39 - */
40 -
41 - /*
42 - * - parent devfreq device uses the governors except for passive.
43 - * - passive devfreq device uses the passive governor.
44 - *
45 - * Each devfreq has the OPP table. After deciding the new frequency
46 - * from the governor of parent devfreq device, the passive governor
47 - * need to get the index of new frequency on OPP table of parent
48 - * device. And then the index is used for getting the suitable
49 - * new frequency for passive devfreq device.
50 - */
51 - if (!devfreq->profile || !devfreq->profile->freq_table
52 - || devfreq->profile->max_state <= 0)
53 - return -EINVAL;
54 -
55 - /*
56 - * The passive governor have to get the correct frequency from OPP
57 - * list of parent device. Because in this case, *freq is temporary
58 - * value which is decided by ondemand governor.
59 - */
60 - if (devfreq->opp_table && parent_devfreq->opp_table) {
61 - p_opp = devfreq_recommended_opp(parent_devfreq->dev.parent,
62 - freq, 0);
63 - if (IS_ERR(p_opp))
64 - return PTR_ERR(p_opp);
65 -
66 - opp = dev_pm_opp_xlate_required_opp(parent_devfreq->opp_table,
67 - devfreq->opp_table, p_opp);
68 - dev_pm_opp_put(p_opp);
69 -
70 - if (IS_ERR(opp))
71 - goto no_required_opp;
72 -
73 - *freq = dev_pm_opp_get_freq(opp);
74 - dev_pm_opp_put(opp);
75 -
76 - return 0;
77 - }
78 + /* Get target freq via required opps */
79 + child_freq = get_target_freq_by_required_opp(parent_devfreq->dev.parent,
80 + parent_devfreq->opp_table,
81 + devfreq->opp_table, freq);
82 + if (child_freq)
83 + goto out;
84
85 -no_required_opp:
86 - /*
87 - * Get the OPP table's index of decided frequency by governor
88 - * of parent device.
89 - */
90 + /* Use interpolation if required opps is not available */
91 for (i = 0; i < parent_devfreq->profile->max_state; i++)
92 if (parent_devfreq->profile->freq_table[i] == *freq)
93 break;
94 @@ -159,7 +110,6 @@ no_required_opp:
95 if (i == parent_devfreq->profile->max_state)
96 return -EINVAL;
97
98 - /* Get the suitable frequency by using index of parent device. */
99 if (i < devfreq->profile->max_state) {
100 child_freq = devfreq->profile->freq_table[i];
101 } else {
102 @@ -167,7 +117,7 @@ no_required_opp:
103 child_freq = devfreq->profile->freq_table[count - 1];
104 }
105
106 - /* Return the suitable frequency for passive device. */
107 +out:
108 *freq = child_freq;
109
110 return 0;