Skip to content

Commit 4401117

Browse files
lukaszluba-armdlezcano
authored andcommitted
thermal/drivers/devfreq_cooling: Fix the build when !ENERGY_MODEL
Prevent build failure if the option CONFIG_ENERGY_MODEL is not set. The devfreq cooling is able to operate without the Energy Model. Don't use dev->em_pd directly and use local pointer. Fixes: 615510f ("thermal: devfreq_cooling: remove old power model and use EM") Reported-by: Stephen Rothwell <[email protected]> Signed-off-by: Lukasz Luba <[email protected]> Signed-off-by: Daniel Lezcano <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 1fa34e4 commit 4401117

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

drivers/thermal/devfreq_cooling.c

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ static DEFINE_IDA(devfreq_ida);
4848
* @capped_state: index to cooling state with in dynamic power budget
4949
* @req_max_freq: PM QoS request for limiting the maximum frequency
5050
* of the devfreq device.
51+
* @em_pd: Energy Model for the associated Devfreq device
5152
*/
5253
struct devfreq_cooling_device {
5354
int id;
@@ -60,6 +61,7 @@ struct devfreq_cooling_device {
6061
u32 res_util;
6162
int capped_state;
6263
struct dev_pm_qos_request req_max_freq;
64+
struct em_perf_domain *em_pd;
6365
};
6466

6567
static int devfreq_cooling_get_max_state(struct thermal_cooling_device *cdev,
@@ -99,9 +101,9 @@ static int devfreq_cooling_set_cur_state(struct thermal_cooling_device *cdev,
99101
if (state > dfc->max_state)
100102
return -EINVAL;
101103

102-
if (dev->em_pd) {
104+
if (dfc->em_pd) {
103105
perf_idx = dfc->max_state - state;
104-
freq = dev->em_pd->table[perf_idx].frequency * 1000;
106+
freq = dfc->em_pd->table[perf_idx].frequency * 1000;
105107
} else {
106108
freq = dfc->freq_table[state];
107109
}
@@ -181,7 +183,6 @@ static int devfreq_cooling_get_requested_power(struct thermal_cooling_device *cd
181183
{
182184
struct devfreq_cooling_device *dfc = cdev->devdata;
183185
struct devfreq *df = dfc->devfreq;
184-
struct device *dev = df->dev.parent;
185186
struct devfreq_dev_status status;
186187
unsigned long state;
187188
unsigned long freq;
@@ -204,7 +205,7 @@ static int devfreq_cooling_get_requested_power(struct thermal_cooling_device *cd
204205
res = dfc->power_ops->get_real_power(df, power, freq, voltage);
205206
if (!res) {
206207
state = dfc->capped_state;
207-
dfc->res_util = dev->em_pd->table[state].power;
208+
dfc->res_util = dfc->em_pd->table[state].power;
208209
dfc->res_util *= SCALE_ERROR_MITIGATION;
209210

210211
if (*power > 1)
@@ -214,7 +215,7 @@ static int devfreq_cooling_get_requested_power(struct thermal_cooling_device *cd
214215
}
215216
} else {
216217
/* Energy Model frequencies are in kHz */
217-
perf_idx = get_perf_idx(dev->em_pd, freq / 1000);
218+
perf_idx = get_perf_idx(dfc->em_pd, freq / 1000);
218219
if (perf_idx < 0) {
219220
res = -EAGAIN;
220221
goto fail;
@@ -223,7 +224,7 @@ static int devfreq_cooling_get_requested_power(struct thermal_cooling_device *cd
223224
_normalize_load(&status);
224225

225226
/* Scale power for utilization */
226-
*power = dev->em_pd->table[perf_idx].power;
227+
*power = dfc->em_pd->table[perf_idx].power;
227228
*power *= status.busy_time;
228229
*power >>= 10;
229230
}
@@ -241,15 +242,13 @@ static int devfreq_cooling_state2power(struct thermal_cooling_device *cdev,
241242
unsigned long state, u32 *power)
242243
{
243244
struct devfreq_cooling_device *dfc = cdev->devdata;
244-
struct devfreq *df = dfc->devfreq;
245-
struct device *dev = df->dev.parent;
246245
int perf_idx;
247246

248247
if (state > dfc->max_state)
249248
return -EINVAL;
250249

251250
perf_idx = dfc->max_state - state;
252-
*power = dev->em_pd->table[perf_idx].power;
251+
*power = dfc->em_pd->table[perf_idx].power;
253252

254253
return 0;
255254
}
@@ -259,7 +258,6 @@ static int devfreq_cooling_power2state(struct thermal_cooling_device *cdev,
259258
{
260259
struct devfreq_cooling_device *dfc = cdev->devdata;
261260
struct devfreq *df = dfc->devfreq;
262-
struct device *dev = df->dev.parent;
263261
struct devfreq_dev_status status;
264262
unsigned long freq;
265263
s32 est_power;
@@ -287,7 +285,7 @@ static int devfreq_cooling_power2state(struct thermal_cooling_device *cdev,
287285
* budget. The EM power table is sorted ascending.
288286
*/
289287
for (i = dfc->max_state; i > 0; i--)
290-
if (est_power >= dev->em_pd->table[i].power)
288+
if (est_power >= dfc->em_pd->table[i].power)
291289
break;
292290

293291
*state = dfc->max_state - i;
@@ -374,15 +372,16 @@ of_devfreq_cooling_register_power(struct device_node *np, struct devfreq *df,
374372

375373
dfc->devfreq = df;
376374

377-
if (dev->em_pd) {
375+
dfc->em_pd = em_pd_get(dev);
376+
if (dfc->em_pd) {
378377
devfreq_cooling_ops.get_requested_power =
379378
devfreq_cooling_get_requested_power;
380379
devfreq_cooling_ops.state2power = devfreq_cooling_state2power;
381380
devfreq_cooling_ops.power2state = devfreq_cooling_power2state;
382381

383382
dfc->power_ops = dfc_power;
384383

385-
num_opps = em_pd_nr_perf_states(dev->em_pd);
384+
num_opps = em_pd_nr_perf_states(dfc->em_pd);
386385
} else {
387386
/* Backward compatibility for drivers which do not use IPA */
388387
dev_dbg(dev, "missing EM for cooling device\n");

0 commit comments

Comments
 (0)