blob: 4fa262337e9eadfa5534c270404f39d8514bce97 [file] [log] [blame]
Amit Daniel Kachhap02361412012-08-16 17:11:40 +05301/*
2 * linux/include/linux/cpu_cooling.h
3 *
4 * Copyright (C) 2012 Samsung Electronics Co., Ltd(http://www.samsung.com)
5 * Copyright (C) 2012 Amit Daniel <amit.kachhap@linaro.org>
6 *
7 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 2 of the License.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
20 *
21 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
22 */
23
24#ifndef __CPU_COOLING_H__
25#define __CPU_COOLING_H__
26
Eduardo Valentin39d99cf2013-09-12 19:26:45 -040027#include <linux/of.h>
Amit Daniel Kachhap02361412012-08-16 17:11:40 +053028#include <linux/thermal.h>
Eduardo Valentin198f38f2013-04-24 23:10:28 +080029#include <linux/cpumask.h>
Amit Daniel Kachhap02361412012-08-16 17:11:40 +053030
Javi Merinoc36cf072015-02-26 19:00:29 +000031typedef int (*get_static_t)(cpumask_t *cpumask, int interval,
32 unsigned long voltage, u32 *power);
Lina Iyer986fde12016-02-23 13:08:31 -070033typedef int (*plat_mitig_t)(int cpu, u32 clip_freq);
34
35struct cpu_cooling_ops {
36 plat_mitig_t ceil_limit, floor_limit;
37};
Javi Merinoc36cf072015-02-26 19:00:29 +000038
Zhang Ruibbf7fc82013-03-26 23:57:01 +080039#ifdef CONFIG_CPU_THERMAL
Amit Daniel Kachhap02361412012-08-16 17:11:40 +053040/**
41 * cpufreq_cooling_register - function to create cpufreq cooling device.
42 * @clip_cpus: cpumask of cpus where the frequency constraints will happen
43 */
Eduardo Valentind44ada52013-04-17 17:12:23 +000044struct thermal_cooling_device *
45cpufreq_cooling_register(const struct cpumask *clip_cpus);
Amit Daniel Kachhap02361412012-08-16 17:11:40 +053046
Javi Merinoc36cf072015-02-26 19:00:29 +000047struct thermal_cooling_device *
48cpufreq_power_cooling_register(const struct cpumask *clip_cpus,
49 u32 capacitance, get_static_t plat_static_func);
50
Lina Iyer986fde12016-02-23 13:08:31 -070051struct thermal_cooling_device *
52cpufreq_platform_cooling_register(const struct cpumask *clip_cpus,
53 struct cpu_cooling_ops *ops);
54
Amit Daniel Kachhap02361412012-08-16 17:11:40 +053055/**
Eduardo Valentin39d99cf2013-09-12 19:26:45 -040056 * of_cpufreq_cooling_register - create cpufreq cooling device based on DT.
57 * @np: a valid struct device_node to the cooling device device tree node.
58 * @clip_cpus: cpumask of cpus where the frequency constraints will happen
59 */
60#ifdef CONFIG_THERMAL_OF
61struct thermal_cooling_device *
62of_cpufreq_cooling_register(struct device_node *np,
63 const struct cpumask *clip_cpus);
Javi Merinoc36cf072015-02-26 19:00:29 +000064
65struct thermal_cooling_device *
66of_cpufreq_power_cooling_register(struct device_node *np,
67 const struct cpumask *clip_cpus,
68 u32 capacitance,
69 get_static_t plat_static_func);
Eduardo Valentin39d99cf2013-09-12 19:26:45 -040070#else
71static inline struct thermal_cooling_device *
72of_cpufreq_cooling_register(struct device_node *np,
73 const struct cpumask *clip_cpus)
74{
Javi Merino503ccc32014-12-17 11:11:24 +000075 return ERR_PTR(-ENOSYS);
Eduardo Valentin39d99cf2013-09-12 19:26:45 -040076}
Javi Merinoc36cf072015-02-26 19:00:29 +000077
78static inline struct thermal_cooling_device *
79of_cpufreq_power_cooling_register(struct device_node *np,
80 const struct cpumask *clip_cpus,
81 u32 capacitance,
82 get_static_t plat_static_func)
83{
84 return NULL;
85}
Eduardo Valentin39d99cf2013-09-12 19:26:45 -040086#endif
87
88/**
Amit Daniel Kachhap02361412012-08-16 17:11:40 +053089 * cpufreq_cooling_unregister - function to remove cpufreq cooling device.
90 * @cdev: thermal cooling device pointer.
91 */
92void cpufreq_cooling_unregister(struct thermal_cooling_device *cdev);
Zhang Rui57df8102013-02-08 14:52:06 +080093
Arnd Bergmanne8d39242013-07-05 17:40:13 +020094unsigned long cpufreq_cooling_get_level(unsigned int cpu, unsigned int freq);
Amit Daniel Kachhap02361412012-08-16 17:11:40 +053095#else /* !CONFIG_CPU_THERMAL */
Eduardo Valentind44ada52013-04-17 17:12:23 +000096static inline struct thermal_cooling_device *
97cpufreq_cooling_register(const struct cpumask *clip_cpus)
Amit Daniel Kachhap02361412012-08-16 17:11:40 +053098{
Javi Merino503ccc32014-12-17 11:11:24 +000099 return ERR_PTR(-ENOSYS);
Amit Daniel Kachhap02361412012-08-16 17:11:40 +0530100}
Eduardo Valentin39d99cf2013-09-12 19:26:45 -0400101static inline struct thermal_cooling_device *
Javi Merinoc36cf072015-02-26 19:00:29 +0000102cpufreq_power_cooling_register(const struct cpumask *clip_cpus,
103 u32 capacitance, get_static_t plat_static_func)
104{
105 return NULL;
106}
107
108static inline struct thermal_cooling_device *
Eduardo Valentin39d99cf2013-09-12 19:26:45 -0400109of_cpufreq_cooling_register(struct device_node *np,
110 const struct cpumask *clip_cpus)
111{
Javi Merino503ccc32014-12-17 11:11:24 +0000112 return ERR_PTR(-ENOSYS);
Eduardo Valentin39d99cf2013-09-12 19:26:45 -0400113}
Javi Merinoc36cf072015-02-26 19:00:29 +0000114
115static inline struct thermal_cooling_device *
116of_cpufreq_power_cooling_register(struct device_node *np,
117 const struct cpumask *clip_cpus,
118 u32 capacitance,
119 get_static_t plat_static_func)
120{
121 return NULL;
122}
123
Lina Iyer986fde12016-02-23 13:08:31 -0700124static inline struct thermal_cooling_device *
125cpufreq_platform_cooling_register(const struct cpumask *clip_cpus,
126 struct cpu_cooling_ops *ops)
127{
128 return NULL;
129}
130
Eduardo Valentind44ada52013-04-17 17:12:23 +0000131static inline
132void cpufreq_cooling_unregister(struct thermal_cooling_device *cdev)
Amit Daniel Kachhap02361412012-08-16 17:11:40 +0530133{
134 return;
135}
Eduardo Valentind44ada52013-04-17 17:12:23 +0000136static inline
Arnd Bergmanne8d39242013-07-05 17:40:13 +0200137unsigned long cpufreq_cooling_get_level(unsigned int cpu, unsigned int freq)
Zhang Rui57df8102013-02-08 14:52:06 +0800138{
139 return THERMAL_CSTATE_INVALID;
140}
Amit Daniel Kachhap02361412012-08-16 17:11:40 +0530141#endif /* CONFIG_CPU_THERMAL */
142
143#endif /* __CPU_COOLING_H__ */