@@ -48,6 +48,7 @@ static DEFINE_IDA(devfreq_ida);
48
48
* @capped_state: index to cooling state with in dynamic power budget
49
49
* @req_max_freq: PM QoS request for limiting the maximum frequency
50
50
* of the devfreq device.
51
+ * @em_pd: Energy Model for the associated Devfreq device
51
52
*/
52
53
struct devfreq_cooling_device {
53
54
int id ;
@@ -60,6 +61,7 @@ struct devfreq_cooling_device {
60
61
u32 res_util ;
61
62
int capped_state ;
62
63
struct dev_pm_qos_request req_max_freq ;
64
+ struct em_perf_domain * em_pd ;
63
65
};
64
66
65
67
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,
99
101
if (state > dfc -> max_state )
100
102
return - EINVAL ;
101
103
102
- if (dev -> em_pd ) {
104
+ if (dfc -> em_pd ) {
103
105
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 ;
105
107
} else {
106
108
freq = dfc -> freq_table [state ];
107
109
}
@@ -181,7 +183,6 @@ static int devfreq_cooling_get_requested_power(struct thermal_cooling_device *cd
181
183
{
182
184
struct devfreq_cooling_device * dfc = cdev -> devdata ;
183
185
struct devfreq * df = dfc -> devfreq ;
184
- struct device * dev = df -> dev .parent ;
185
186
struct devfreq_dev_status status ;
186
187
unsigned long state ;
187
188
unsigned long freq ;
@@ -204,7 +205,7 @@ static int devfreq_cooling_get_requested_power(struct thermal_cooling_device *cd
204
205
res = dfc -> power_ops -> get_real_power (df , power , freq , voltage );
205
206
if (!res ) {
206
207
state = dfc -> capped_state ;
207
- dfc -> res_util = dev -> em_pd -> table [state ].power ;
208
+ dfc -> res_util = dfc -> em_pd -> table [state ].power ;
208
209
dfc -> res_util *= SCALE_ERROR_MITIGATION ;
209
210
210
211
if (* power > 1 )
@@ -214,7 +215,7 @@ static int devfreq_cooling_get_requested_power(struct thermal_cooling_device *cd
214
215
}
215
216
} else {
216
217
/* 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 );
218
219
if (perf_idx < 0 ) {
219
220
res = - EAGAIN ;
220
221
goto fail ;
@@ -223,7 +224,7 @@ static int devfreq_cooling_get_requested_power(struct thermal_cooling_device *cd
223
224
_normalize_load (& status );
224
225
225
226
/* Scale power for utilization */
226
- * power = dev -> em_pd -> table [perf_idx ].power ;
227
+ * power = dfc -> em_pd -> table [perf_idx ].power ;
227
228
* power *= status .busy_time ;
228
229
* power >>= 10 ;
229
230
}
@@ -241,15 +242,13 @@ static int devfreq_cooling_state2power(struct thermal_cooling_device *cdev,
241
242
unsigned long state , u32 * power )
242
243
{
243
244
struct devfreq_cooling_device * dfc = cdev -> devdata ;
244
- struct devfreq * df = dfc -> devfreq ;
245
- struct device * dev = df -> dev .parent ;
246
245
int perf_idx ;
247
246
248
247
if (state > dfc -> max_state )
249
248
return - EINVAL ;
250
249
251
250
perf_idx = dfc -> max_state - state ;
252
- * power = dev -> em_pd -> table [perf_idx ].power ;
251
+ * power = dfc -> em_pd -> table [perf_idx ].power ;
253
252
254
253
return 0 ;
255
254
}
@@ -259,7 +258,6 @@ static int devfreq_cooling_power2state(struct thermal_cooling_device *cdev,
259
258
{
260
259
struct devfreq_cooling_device * dfc = cdev -> devdata ;
261
260
struct devfreq * df = dfc -> devfreq ;
262
- struct device * dev = df -> dev .parent ;
263
261
struct devfreq_dev_status status ;
264
262
unsigned long freq ;
265
263
s32 est_power ;
@@ -287,7 +285,7 @@ static int devfreq_cooling_power2state(struct thermal_cooling_device *cdev,
287
285
* budget. The EM power table is sorted ascending.
288
286
*/
289
287
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 )
291
289
break ;
292
290
293
291
* state = dfc -> max_state - i ;
@@ -374,15 +372,16 @@ of_devfreq_cooling_register_power(struct device_node *np, struct devfreq *df,
374
372
375
373
dfc -> devfreq = df ;
376
374
377
- if (dev -> em_pd ) {
375
+ dfc -> em_pd = em_pd_get (dev );
376
+ if (dfc -> em_pd ) {
378
377
devfreq_cooling_ops .get_requested_power =
379
378
devfreq_cooling_get_requested_power ;
380
379
devfreq_cooling_ops .state2power = devfreq_cooling_state2power ;
381
380
devfreq_cooling_ops .power2state = devfreq_cooling_power2state ;
382
381
383
382
dfc -> power_ops = dfc_power ;
384
383
385
- num_opps = em_pd_nr_perf_states (dev -> em_pd );
384
+ num_opps = em_pd_nr_perf_states (dfc -> em_pd );
386
385
} else {
387
386
/* Backward compatibility for drivers which do not use IPA */
388
387
dev_dbg (dev , "missing EM for cooling device\n" );
0 commit comments