Skip to content

Commit 05723e7

Browse files
committed
PM / devfreq: passive: Reduce duplicate code when passive_devfreq case
In order to keep the consistent coding style between passive_devfreq and passive_cpufreq, use common code for handling required opp property. Also remove the unneed conditional statement and unify the comment of both passive_devfreq and passive_cpufreq when getting the target frequency. Tested-by: Chen-Yu Tsai <wenst@chromium.org> Tested-by: Johnson Wang <johnson.wang@mediatek.com> Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
1 parent a03dacb commit 05723e7

1 file changed

Lines changed: 8 additions & 58 deletions

File tree

drivers/devfreq/governor_passive.c

Lines changed: 8 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -93,81 +93,31 @@ static int get_target_freq_with_devfreq(struct devfreq *devfreq,
9393
= (struct devfreq_passive_data *)devfreq->data;
9494
struct devfreq *parent_devfreq = (struct devfreq *)p_data->parent;
9595
unsigned long child_freq = ULONG_MAX;
96-
struct dev_pm_opp *opp, *p_opp;
9796
int i, count;
9897

99-
/*
100-
* If the devfreq device with passive governor has the specific method
101-
* to determine the next frequency, should use the get_target_freq()
102-
* of struct devfreq_passive_data.
103-
*/
104-
if (p_data->get_target_freq)
105-
return p_data->get_target_freq(devfreq, freq);
98+
/* Get target freq via required opps */
99+
child_freq = get_target_freq_by_required_opp(parent_devfreq->dev.parent,
100+
parent_devfreq->opp_table,
101+
devfreq->opp_table, freq);
102+
if (child_freq)
103+
goto out;
106104

107-
/*
108-
* If the parent and passive devfreq device uses the OPP table,
109-
* get the next frequency by using the OPP table.
110-
*/
111-
112-
/*
113-
* - parent devfreq device uses the governors except for passive.
114-
* - passive devfreq device uses the passive governor.
115-
*
116-
* Each devfreq has the OPP table. After deciding the new frequency
117-
* from the governor of parent devfreq device, the passive governor
118-
* need to get the index of new frequency on OPP table of parent
119-
* device. And then the index is used for getting the suitable
120-
* new frequency for passive devfreq device.
121-
*/
122-
if (!devfreq->profile || !devfreq->profile->freq_table
123-
|| devfreq->profile->max_state <= 0)
124-
return -EINVAL;
125-
126-
/*
127-
* The passive governor have to get the correct frequency from OPP
128-
* list of parent device. Because in this case, *freq is temporary
129-
* value which is decided by ondemand governor.
130-
*/
131-
if (devfreq->opp_table && parent_devfreq->opp_table) {
132-
p_opp = devfreq_recommended_opp(parent_devfreq->dev.parent,
133-
freq, 0);
134-
if (IS_ERR(p_opp))
135-
return PTR_ERR(p_opp);
136-
137-
opp = dev_pm_opp_xlate_required_opp(parent_devfreq->opp_table,
138-
devfreq->opp_table, p_opp);
139-
dev_pm_opp_put(p_opp);
140-
141-
if (IS_ERR(opp))
142-
goto no_required_opp;
143-
144-
*freq = dev_pm_opp_get_freq(opp);
145-
dev_pm_opp_put(opp);
146-
147-
return 0;
148-
}
149-
150-
no_required_opp:
151-
/*
152-
* Get the OPP table's index of decided frequency by governor
153-
* of parent device.
154-
*/
105+
/* Use interpolation if required opps is not available */
155106
for (i = 0; i < parent_devfreq->profile->max_state; i++)
156107
if (parent_devfreq->profile->freq_table[i] == *freq)
157108
break;
158109

159110
if (i == parent_devfreq->profile->max_state)
160111
return -EINVAL;
161112

162-
/* Get the suitable frequency by using index of parent device. */
163113
if (i < devfreq->profile->max_state) {
164114
child_freq = devfreq->profile->freq_table[i];
165115
} else {
166116
count = devfreq->profile->max_state;
167117
child_freq = devfreq->profile->freq_table[count - 1];
168118
}
169119

170-
/* Return the suitable frequency for passive device. */
120+
out:
171121
*freq = child_freq;
172122

173123
return 0;

0 commit comments

Comments
 (0)