1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun * devfreq_cooling: Thermal cooling device implementation for devices using
4*4882a593Smuzhiyun * devfreq
5*4882a593Smuzhiyun *
6*4882a593Smuzhiyun * Copyright (C) 2014-2015 ARM Limited
7*4882a593Smuzhiyun *
8*4882a593Smuzhiyun */
9*4882a593Smuzhiyun
10*4882a593Smuzhiyun #ifndef __DEVFREQ_COOLING_H__
11*4882a593Smuzhiyun #define __DEVFREQ_COOLING_H__
12*4882a593Smuzhiyun
13*4882a593Smuzhiyun #include <linux/devfreq.h>
14*4882a593Smuzhiyun #include <linux/thermal.h>
15*4882a593Smuzhiyun
16*4882a593Smuzhiyun
17*4882a593Smuzhiyun /**
18*4882a593Smuzhiyun * struct devfreq_cooling_power - Devfreq cooling power ops
19*4882a593Smuzhiyun * @get_static_power: Take voltage, in mV, and return the static power
20*4882a593Smuzhiyun * in mW. If NULL, the static power is assumed
21*4882a593Smuzhiyun * to be 0.
22*4882a593Smuzhiyun * @get_dynamic_power: Take voltage, in mV, and frequency, in HZ, and
23*4882a593Smuzhiyun * return the dynamic power draw in mW. If NULL,
24*4882a593Smuzhiyun * a simple power model is used.
25*4882a593Smuzhiyun * @dyn_power_coeff: Coefficient for the simple dynamic power model in
26*4882a593Smuzhiyun * mW/(MHz mV mV).
27*4882a593Smuzhiyun * If get_dynamic_power() is NULL, then the
28*4882a593Smuzhiyun * dynamic power is calculated as
29*4882a593Smuzhiyun * @dyn_power_coeff * frequency * voltage^2
30*4882a593Smuzhiyun * @get_real_power: When this is set, the framework uses it to ask the
31*4882a593Smuzhiyun * device driver for the actual power.
32*4882a593Smuzhiyun * Some devices have more sophisticated methods
33*4882a593Smuzhiyun * (like power counters) to approximate the actual power
34*4882a593Smuzhiyun * that they use.
35*4882a593Smuzhiyun * This function provides more accurate data to the
36*4882a593Smuzhiyun * thermal governor. When the driver does not provide
37*4882a593Smuzhiyun * such function, framework just uses pre-calculated
38*4882a593Smuzhiyun * table and scale the power by 'utilization'
39*4882a593Smuzhiyun * (based on 'busy_time' and 'total_time' taken from
40*4882a593Smuzhiyun * devfreq 'last_status').
41*4882a593Smuzhiyun * The value returned by this function must be lower
42*4882a593Smuzhiyun * or equal than the maximum power value
43*4882a593Smuzhiyun * for the current state
44*4882a593Smuzhiyun * (which can be found in power_table[state]).
45*4882a593Smuzhiyun * When this interface is used, the power_table holds
46*4882a593Smuzhiyun * max total (static + dynamic) power value for each OPP.
47*4882a593Smuzhiyun */
48*4882a593Smuzhiyun struct devfreq_cooling_power {
49*4882a593Smuzhiyun unsigned long (*get_static_power)(struct devfreq *devfreq,
50*4882a593Smuzhiyun unsigned long voltage);
51*4882a593Smuzhiyun unsigned long (*get_dynamic_power)(struct devfreq *devfreq,
52*4882a593Smuzhiyun unsigned long freq,
53*4882a593Smuzhiyun unsigned long voltage);
54*4882a593Smuzhiyun int (*get_real_power)(struct devfreq *df, u32 *power,
55*4882a593Smuzhiyun unsigned long freq, unsigned long voltage);
56*4882a593Smuzhiyun unsigned long dyn_power_coeff;
57*4882a593Smuzhiyun };
58*4882a593Smuzhiyun
59*4882a593Smuzhiyun #ifdef CONFIG_DEVFREQ_THERMAL
60*4882a593Smuzhiyun
61*4882a593Smuzhiyun struct thermal_cooling_device *
62*4882a593Smuzhiyun of_devfreq_cooling_register_power(struct device_node *np, struct devfreq *df,
63*4882a593Smuzhiyun struct devfreq_cooling_power *dfc_power);
64*4882a593Smuzhiyun struct thermal_cooling_device *
65*4882a593Smuzhiyun of_devfreq_cooling_register(struct device_node *np, struct devfreq *df);
66*4882a593Smuzhiyun struct thermal_cooling_device *devfreq_cooling_register(struct devfreq *df);
67*4882a593Smuzhiyun void devfreq_cooling_unregister(struct thermal_cooling_device *dfc);
68*4882a593Smuzhiyun
69*4882a593Smuzhiyun #else /* !CONFIG_DEVFREQ_THERMAL */
70*4882a593Smuzhiyun
71*4882a593Smuzhiyun static inline struct thermal_cooling_device *
of_devfreq_cooling_register_power(struct device_node * np,struct devfreq * df,struct devfreq_cooling_power * dfc_power)72*4882a593Smuzhiyun of_devfreq_cooling_register_power(struct device_node *np, struct devfreq *df,
73*4882a593Smuzhiyun struct devfreq_cooling_power *dfc_power)
74*4882a593Smuzhiyun {
75*4882a593Smuzhiyun return ERR_PTR(-EINVAL);
76*4882a593Smuzhiyun }
77*4882a593Smuzhiyun
78*4882a593Smuzhiyun static inline struct thermal_cooling_device *
of_devfreq_cooling_register(struct device_node * np,struct devfreq * df)79*4882a593Smuzhiyun of_devfreq_cooling_register(struct device_node *np, struct devfreq *df)
80*4882a593Smuzhiyun {
81*4882a593Smuzhiyun return ERR_PTR(-EINVAL);
82*4882a593Smuzhiyun }
83*4882a593Smuzhiyun
84*4882a593Smuzhiyun static inline struct thermal_cooling_device *
devfreq_cooling_register(struct devfreq * df)85*4882a593Smuzhiyun devfreq_cooling_register(struct devfreq *df)
86*4882a593Smuzhiyun {
87*4882a593Smuzhiyun return ERR_PTR(-EINVAL);
88*4882a593Smuzhiyun }
89*4882a593Smuzhiyun
90*4882a593Smuzhiyun static inline void
devfreq_cooling_unregister(struct thermal_cooling_device * dfc)91*4882a593Smuzhiyun devfreq_cooling_unregister(struct thermal_cooling_device *dfc)
92*4882a593Smuzhiyun {
93*4882a593Smuzhiyun }
94*4882a593Smuzhiyun
95*4882a593Smuzhiyun #endif /* CONFIG_DEVFREQ_THERMAL */
96*4882a593Smuzhiyun #endif /* __DEVFREQ_COOLING_H__ */
97