Ørjan Eide | a76caf5 | 2015-09-10 18:09:30 +0100 | [diff] [blame] | 1 | /* |
| 2 | * devfreq_cooling: Thermal cooling device implementation for devices using |
| 3 | * devfreq |
| 4 | * |
| 5 | * Copyright (C) 2014-2015 ARM Limited |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License version 2 as |
| 9 | * published by the Free Software Foundation. |
| 10 | * |
| 11 | * This program is distributed "as is" WITHOUT ANY WARRANTY of any |
| 12 | * kind, whether express or implied; without even the implied warranty |
| 13 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | */ |
| 16 | |
| 17 | #ifndef __DEVFREQ_COOLING_H__ |
| 18 | #define __DEVFREQ_COOLING_H__ |
| 19 | |
| 20 | #include <linux/devfreq.h> |
| 21 | #include <linux/thermal.h> |
| 22 | |
Ørjan Eide | a76caf5 | 2015-09-10 18:09:30 +0100 | [diff] [blame] | 23 | |
| 24 | /** |
| 25 | * struct devfreq_cooling_power - Devfreq cooling power ops |
| 26 | * @get_static_power: Take voltage, in mV, and return the static power |
| 27 | * in mW. If NULL, the static power is assumed |
| 28 | * to be 0. |
| 29 | * @get_dynamic_power: Take voltage, in mV, and frequency, in HZ, and |
| 30 | * return the dynamic power draw in mW. If NULL, |
| 31 | * a simple power model is used. |
| 32 | * @dyn_power_coeff: Coefficient for the simple dynamic power model in |
| 33 | * mW/(MHz mV mV). |
| 34 | * If get_dynamic_power() is NULL, then the |
| 35 | * dynamic power is calculated as |
| 36 | * @dyn_power_coeff * frequency * voltage^2 |
Lukasz Luba | 2be83da | 2017-05-04 12:34:32 +0100 | [diff] [blame] | 37 | * @get_real_power: When this is set, the framework uses it to ask the |
| 38 | * device driver for the actual power. |
| 39 | * Some devices have more sophisticated methods |
| 40 | * (like power counters) to approximate the actual power |
| 41 | * that they use. |
| 42 | * This function provides more accurate data to the |
| 43 | * thermal governor. When the driver does not provide |
| 44 | * such function, framework just uses pre-calculated |
| 45 | * table and scale the power by 'utilization' |
| 46 | * (based on 'busy_time' and 'total_time' taken from |
| 47 | * devfreq 'last_status'). |
| 48 | * The value returned by this function must be lower |
| 49 | * or equal than the maximum power value |
| 50 | * for the current state |
| 51 | * (which can be found in power_table[state]). |
| 52 | * When this interface is used, the power_table holds |
| 53 | * max total (static + dynamic) power value for each OPP. |
Ørjan Eide | a76caf5 | 2015-09-10 18:09:30 +0100 | [diff] [blame] | 54 | */ |
| 55 | struct devfreq_cooling_power { |
Javi Merino | 3aa5374 | 2016-09-15 15:44:23 +0100 | [diff] [blame] | 56 | unsigned long (*get_static_power)(struct devfreq *devfreq, |
| 57 | unsigned long voltage); |
| 58 | unsigned long (*get_dynamic_power)(struct devfreq *devfreq, |
| 59 | unsigned long freq, |
Ørjan Eide | a76caf5 | 2015-09-10 18:09:30 +0100 | [diff] [blame] | 60 | unsigned long voltage); |
Lukasz Luba | 2be83da | 2017-05-04 12:34:32 +0100 | [diff] [blame] | 61 | int (*get_real_power)(struct devfreq *df, u32 *power, |
| 62 | unsigned long freq, unsigned long voltage); |
Ørjan Eide | a76caf5 | 2015-09-10 18:09:30 +0100 | [diff] [blame] | 63 | unsigned long dyn_power_coeff; |
| 64 | }; |
| 65 | |
Lukasz Luba | 1cea4e7 | 2016-09-15 15:44:22 +0100 | [diff] [blame] | 66 | #ifdef CONFIG_DEVFREQ_THERMAL |
| 67 | |
Javi Merino | 3c99c2c | 2015-11-02 19:03:03 +0000 | [diff] [blame] | 68 | struct thermal_cooling_device * |
Ørjan Eide | a76caf5 | 2015-09-10 18:09:30 +0100 | [diff] [blame] | 69 | of_devfreq_cooling_register_power(struct device_node *np, struct devfreq *df, |
| 70 | struct devfreq_cooling_power *dfc_power); |
Javi Merino | 3c99c2c | 2015-11-02 19:03:03 +0000 | [diff] [blame] | 71 | struct thermal_cooling_device * |
Ørjan Eide | a76caf5 | 2015-09-10 18:09:30 +0100 | [diff] [blame] | 72 | of_devfreq_cooling_register(struct device_node *np, struct devfreq *df); |
Javi Merino | 3c99c2c | 2015-11-02 19:03:03 +0000 | [diff] [blame] | 73 | struct thermal_cooling_device *devfreq_cooling_register(struct devfreq *df); |
| 74 | void devfreq_cooling_unregister(struct thermal_cooling_device *dfc); |
Ørjan Eide | a76caf5 | 2015-09-10 18:09:30 +0100 | [diff] [blame] | 75 | |
| 76 | #else /* !CONFIG_DEVFREQ_THERMAL */ |
| 77 | |
Javi Merino | 3c99c2c | 2015-11-02 19:03:03 +0000 | [diff] [blame] | 78 | struct thermal_cooling_device * |
Ørjan Eide | a76caf5 | 2015-09-10 18:09:30 +0100 | [diff] [blame] | 79 | of_devfreq_cooling_register_power(struct device_node *np, struct devfreq *df, |
| 80 | struct devfreq_cooling_power *dfc_power) |
| 81 | { |
| 82 | return ERR_PTR(-EINVAL); |
| 83 | } |
| 84 | |
Javi Merino | 3c99c2c | 2015-11-02 19:03:03 +0000 | [diff] [blame] | 85 | static inline struct thermal_cooling_device * |
Ørjan Eide | a76caf5 | 2015-09-10 18:09:30 +0100 | [diff] [blame] | 86 | of_devfreq_cooling_register(struct device_node *np, struct devfreq *df) |
| 87 | { |
| 88 | return ERR_PTR(-EINVAL); |
| 89 | } |
| 90 | |
Javi Merino | 3c99c2c | 2015-11-02 19:03:03 +0000 | [diff] [blame] | 91 | static inline struct thermal_cooling_device * |
Ørjan Eide | a76caf5 | 2015-09-10 18:09:30 +0100 | [diff] [blame] | 92 | devfreq_cooling_register(struct devfreq *df) |
| 93 | { |
| 94 | return ERR_PTR(-EINVAL); |
| 95 | } |
| 96 | |
| 97 | static inline void |
Javi Merino | 3c99c2c | 2015-11-02 19:03:03 +0000 | [diff] [blame] | 98 | devfreq_cooling_unregister(struct thermal_cooling_device *dfc) |
Ørjan Eide | a76caf5 | 2015-09-10 18:09:30 +0100 | [diff] [blame] | 99 | { |
| 100 | } |
| 101 | |
| 102 | #endif /* CONFIG_DEVFREQ_THERMAL */ |
| 103 | #endif /* __DEVFREQ_COOLING_H__ */ |