|
47 | 47 | */
|
48 | 48 | struct freq_table {
|
49 | 49 | u32 frequency;
|
| 50 | +#ifdef CONFIG_THERMAL_GOV_POWER_ALLOCATOR |
50 | 51 | u32 power;
|
| 52 | +#endif |
51 | 53 | };
|
52 | 54 |
|
53 | 55 | /**
|
@@ -95,8 +97,7 @@ static DEFINE_IDA(cpufreq_ida);
|
95 | 97 | static DEFINE_MUTEX(cooling_list_lock);
|
96 | 98 | static LIST_HEAD(cpufreq_cdev_list);
|
97 | 99 |
|
98 |
| -/* Below code defines functions to be used for cpufreq as cooling device */ |
99 |
| - |
| 100 | +#ifdef CONFIG_THERMAL_GOV_POWER_ALLOCATOR |
100 | 101 | /**
|
101 | 102 | * get_level: Find the level for a particular frequency
|
102 | 103 | * @cpufreq_cdev: cpufreq_cdev for which the property is required
|
@@ -265,76 +266,6 @@ static u32 get_dynamic_power(struct cpufreq_cooling_device *cpufreq_cdev,
|
265 | 266 | return (raw_cpu_power * cpufreq_cdev->last_load) / 100;
|
266 | 267 | }
|
267 | 268 |
|
268 |
| -/* cpufreq cooling device callback functions are defined below */ |
269 |
| - |
270 |
| -/** |
271 |
| - * cpufreq_get_max_state - callback function to get the max cooling state. |
272 |
| - * @cdev: thermal cooling device pointer. |
273 |
| - * @state: fill this variable with the max cooling state. |
274 |
| - * |
275 |
| - * Callback for the thermal cooling device to return the cpufreq |
276 |
| - * max cooling state. |
277 |
| - * |
278 |
| - * Return: 0 on success, an error code otherwise. |
279 |
| - */ |
280 |
| -static int cpufreq_get_max_state(struct thermal_cooling_device *cdev, |
281 |
| - unsigned long *state) |
282 |
| -{ |
283 |
| - struct cpufreq_cooling_device *cpufreq_cdev = cdev->devdata; |
284 |
| - |
285 |
| - *state = cpufreq_cdev->max_level; |
286 |
| - return 0; |
287 |
| -} |
288 |
| - |
289 |
| -/** |
290 |
| - * cpufreq_get_cur_state - callback function to get the current cooling state. |
291 |
| - * @cdev: thermal cooling device pointer. |
292 |
| - * @state: fill this variable with the current cooling state. |
293 |
| - * |
294 |
| - * Callback for the thermal cooling device to return the cpufreq |
295 |
| - * current cooling state. |
296 |
| - * |
297 |
| - * Return: 0 on success, an error code otherwise. |
298 |
| - */ |
299 |
| -static int cpufreq_get_cur_state(struct thermal_cooling_device *cdev, |
300 |
| - unsigned long *state) |
301 |
| -{ |
302 |
| - struct cpufreq_cooling_device *cpufreq_cdev = cdev->devdata; |
303 |
| - |
304 |
| - *state = cpufreq_cdev->cpufreq_state; |
305 |
| - |
306 |
| - return 0; |
307 |
| -} |
308 |
| - |
309 |
| -/** |
310 |
| - * cpufreq_set_cur_state - callback function to set the current cooling state. |
311 |
| - * @cdev: thermal cooling device pointer. |
312 |
| - * @state: set this variable to the current cooling state. |
313 |
| - * |
314 |
| - * Callback for the thermal cooling device to change the cpufreq |
315 |
| - * current cooling state. |
316 |
| - * |
317 |
| - * Return: 0 on success, an error code otherwise. |
318 |
| - */ |
319 |
| -static int cpufreq_set_cur_state(struct thermal_cooling_device *cdev, |
320 |
| - unsigned long state) |
321 |
| -{ |
322 |
| - struct cpufreq_cooling_device *cpufreq_cdev = cdev->devdata; |
323 |
| - |
324 |
| - /* Request state should be less than max_level */ |
325 |
| - if (WARN_ON(state > cpufreq_cdev->max_level)) |
326 |
| - return -EINVAL; |
327 |
| - |
328 |
| - /* Check if the old cooling action is same as new cooling action */ |
329 |
| - if (cpufreq_cdev->cpufreq_state == state) |
330 |
| - return 0; |
331 |
| - |
332 |
| - cpufreq_cdev->cpufreq_state = state; |
333 |
| - |
334 |
| - return freq_qos_update_request(&cpufreq_cdev->qos_req, |
335 |
| - cpufreq_cdev->freq_table[state].frequency); |
336 |
| -} |
337 |
| - |
338 | 269 | /**
|
339 | 270 | * cpufreq_get_requested_power() - get the current power
|
340 | 271 | * @cdev: &thermal_cooling_device pointer
|
@@ -478,22 +409,84 @@ static int cpufreq_power2state(struct thermal_cooling_device *cdev,
|
478 | 409 | power);
|
479 | 410 | return 0;
|
480 | 411 | }
|
| 412 | +#endif /* CONFIG_THERMAL_GOV_POWER_ALLOCATOR */ |
| 413 | + |
| 414 | +/* cpufreq cooling device callback functions are defined below */ |
| 415 | + |
| 416 | +/** |
| 417 | + * cpufreq_get_max_state - callback function to get the max cooling state. |
| 418 | + * @cdev: thermal cooling device pointer. |
| 419 | + * @state: fill this variable with the max cooling state. |
| 420 | + * |
| 421 | + * Callback for the thermal cooling device to return the cpufreq |
| 422 | + * max cooling state. |
| 423 | + * |
| 424 | + * Return: 0 on success, an error code otherwise. |
| 425 | + */ |
| 426 | +static int cpufreq_get_max_state(struct thermal_cooling_device *cdev, |
| 427 | + unsigned long *state) |
| 428 | +{ |
| 429 | + struct cpufreq_cooling_device *cpufreq_cdev = cdev->devdata; |
| 430 | + |
| 431 | + *state = cpufreq_cdev->max_level; |
| 432 | + return 0; |
| 433 | +} |
| 434 | + |
| 435 | +/** |
| 436 | + * cpufreq_get_cur_state - callback function to get the current cooling state. |
| 437 | + * @cdev: thermal cooling device pointer. |
| 438 | + * @state: fill this variable with the current cooling state. |
| 439 | + * |
| 440 | + * Callback for the thermal cooling device to return the cpufreq |
| 441 | + * current cooling state. |
| 442 | + * |
| 443 | + * Return: 0 on success, an error code otherwise. |
| 444 | + */ |
| 445 | +static int cpufreq_get_cur_state(struct thermal_cooling_device *cdev, |
| 446 | + unsigned long *state) |
| 447 | +{ |
| 448 | + struct cpufreq_cooling_device *cpufreq_cdev = cdev->devdata; |
| 449 | + |
| 450 | + *state = cpufreq_cdev->cpufreq_state; |
| 451 | + |
| 452 | + return 0; |
| 453 | +} |
| 454 | + |
| 455 | +/** |
| 456 | + * cpufreq_set_cur_state - callback function to set the current cooling state. |
| 457 | + * @cdev: thermal cooling device pointer. |
| 458 | + * @state: set this variable to the current cooling state. |
| 459 | + * |
| 460 | + * Callback for the thermal cooling device to change the cpufreq |
| 461 | + * current cooling state. |
| 462 | + * |
| 463 | + * Return: 0 on success, an error code otherwise. |
| 464 | + */ |
| 465 | +static int cpufreq_set_cur_state(struct thermal_cooling_device *cdev, |
| 466 | + unsigned long state) |
| 467 | +{ |
| 468 | + struct cpufreq_cooling_device *cpufreq_cdev = cdev->devdata; |
| 469 | + |
| 470 | + /* Request state should be less than max_level */ |
| 471 | + if (WARN_ON(state > cpufreq_cdev->max_level)) |
| 472 | + return -EINVAL; |
| 473 | + |
| 474 | + /* Check if the old cooling action is same as new cooling action */ |
| 475 | + if (cpufreq_cdev->cpufreq_state == state) |
| 476 | + return 0; |
| 477 | + |
| 478 | + cpufreq_cdev->cpufreq_state = state; |
| 479 | + |
| 480 | + return freq_qos_update_request(&cpufreq_cdev->qos_req, |
| 481 | + cpufreq_cdev->freq_table[state].frequency); |
| 482 | +} |
481 | 483 |
|
482 | 484 | /* Bind cpufreq callbacks to thermal cooling device ops */
|
483 | 485 |
|
484 | 486 | static struct thermal_cooling_device_ops cpufreq_cooling_ops = {
|
485 |
| - .get_max_state = cpufreq_get_max_state, |
486 |
| - .get_cur_state = cpufreq_get_cur_state, |
487 |
| - .set_cur_state = cpufreq_set_cur_state, |
488 |
| -}; |
489 |
| - |
490 |
| -static struct thermal_cooling_device_ops cpufreq_power_cooling_ops = { |
491 | 487 | .get_max_state = cpufreq_get_max_state,
|
492 | 488 | .get_cur_state = cpufreq_get_cur_state,
|
493 | 489 | .set_cur_state = cpufreq_set_cur_state,
|
494 |
| - .get_requested_power = cpufreq_get_requested_power, |
495 |
| - .state2power = cpufreq_state2power, |
496 |
| - .power2state = cpufreq_power2state, |
497 | 490 | };
|
498 | 491 |
|
499 | 492 | static unsigned int find_next_max(struct cpufreq_frequency_table *table,
|
@@ -603,17 +596,20 @@ __cpufreq_cooling_register(struct device_node *np,
|
603 | 596 | pr_debug("%s: freq:%u KHz\n", __func__, freq);
|
604 | 597 | }
|
605 | 598 |
|
| 599 | + cooling_ops = &cpufreq_cooling_ops; |
| 600 | + |
| 601 | +#ifdef CONFIG_THERMAL_GOV_POWER_ALLOCATOR |
606 | 602 | if (capacitance) {
|
607 | 603 | ret = update_freq_table(cpufreq_cdev, capacitance);
|
608 | 604 | if (ret) {
|
609 | 605 | cdev = ERR_PTR(ret);
|
610 | 606 | goto remove_ida;
|
611 | 607 | }
|
612 |
| - |
613 |
| - cooling_ops = &cpufreq_power_cooling_ops; |
614 |
| - } else { |
615 |
| - cooling_ops = &cpufreq_cooling_ops; |
| 608 | + cooling_ops->get_requested_power = cpufreq_get_requested_power; |
| 609 | + cooling_ops->state2power = cpufreq_state2power; |
| 610 | + cooling_ops->power2state = cpufreq_power2state; |
616 | 611 | }
|
| 612 | +#endif |
617 | 613 |
|
618 | 614 | ret = freq_qos_add_request(&policy->constraints,
|
619 | 615 | &cpufreq_cdev->qos_req, FREQ_QOS_MAX,
|
|
0 commit comments