Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1/* SPDX-License-Identifier: GPL-2.0 */
2/*
3 * thermal_core.h
4 *
5 * Copyright (C) 2012 Intel Corp
6 * Author: Durgadoss R <durgadoss.r@intel.com>
7 */
8
9#ifndef __THERMAL_CORE_H__
10#define __THERMAL_CORE_H__
11
12#include <linux/device.h>
13#include <linux/thermal.h>
14
15/* Initial state of a cooling device during binding */
16#define THERMAL_NO_TARGET -1UL
17
18/*
19 * This structure is used to describe the behavior of
20 * a certain cooling device on a certain trip point
21 * in a certain thermal zone
22 */
23struct thermal_instance {
24 int id;
25 char name[THERMAL_NAME_LENGTH];
26 struct thermal_zone_device *tz;
27 struct thermal_cooling_device *cdev;
28 int trip;
29 bool initialized;
30 unsigned long upper; /* Highest cooling state for this trip point */
31 unsigned long lower; /* Lowest cooling state for this trip point */
32 unsigned long target; /* expected cooling state */
33 char attr_name[THERMAL_NAME_LENGTH];
34 struct device_attribute attr;
35 char weight_attr_name[THERMAL_NAME_LENGTH];
36 struct device_attribute weight_attr;
37 struct list_head tz_node; /* node in tz->thermal_instances */
38 struct list_head cdev_node; /* node in cdev->thermal_instances */
39 unsigned int weight; /* The weight of the cooling device */
40};
41
42#define to_thermal_zone(_dev) \
43 container_of(_dev, struct thermal_zone_device, device)
44
45#define to_cooling_device(_dev) \
46 container_of(_dev, struct thermal_cooling_device, device)
47
48int thermal_register_governor(struct thermal_governor *);
49void thermal_unregister_governor(struct thermal_governor *);
50void thermal_zone_device_rebind_exception(struct thermal_zone_device *,
51 const char *, size_t);
52void thermal_zone_device_unbind_exception(struct thermal_zone_device *,
53 const char *, size_t);
54int thermal_zone_device_set_policy(struct thermal_zone_device *, char *);
55int thermal_build_list_of_policies(char *buf);
56
57/* sysfs I/F */
58int thermal_zone_create_device_groups(struct thermal_zone_device *, int);
59void thermal_zone_destroy_device_groups(struct thermal_zone_device *);
60void thermal_cooling_device_setup_sysfs(struct thermal_cooling_device *);
61void thermal_cooling_device_destroy_sysfs(struct thermal_cooling_device *cdev);
62/* used only at binding time */
63ssize_t trip_point_show(struct device *, struct device_attribute *, char *);
64ssize_t weight_show(struct device *, struct device_attribute *, char *);
65ssize_t weight_store(struct device *, struct device_attribute *, const char *,
66 size_t);
67
68#ifdef CONFIG_THERMAL_STATISTICS
69void thermal_cooling_device_stats_update(struct thermal_cooling_device *cdev,
70 unsigned long new_state);
71#else
72static inline void
73thermal_cooling_device_stats_update(struct thermal_cooling_device *cdev,
74 unsigned long new_state) {}
75#endif /* CONFIG_THERMAL_STATISTICS */
76
77#ifdef CONFIG_THERMAL_GOV_STEP_WISE
78int thermal_gov_step_wise_register(void);
79void thermal_gov_step_wise_unregister(void);
80#else
81static inline int thermal_gov_step_wise_register(void) { return 0; }
82static inline void thermal_gov_step_wise_unregister(void) {}
83#endif /* CONFIG_THERMAL_GOV_STEP_WISE */
84
85#ifdef CONFIG_THERMAL_GOV_FAIR_SHARE
86int thermal_gov_fair_share_register(void);
87void thermal_gov_fair_share_unregister(void);
88#else
89static inline int thermal_gov_fair_share_register(void) { return 0; }
90static inline void thermal_gov_fair_share_unregister(void) {}
91#endif /* CONFIG_THERMAL_GOV_FAIR_SHARE */
92
93#ifdef CONFIG_THERMAL_GOV_BANG_BANG
94int thermal_gov_bang_bang_register(void);
95void thermal_gov_bang_bang_unregister(void);
96#else
97static inline int thermal_gov_bang_bang_register(void) { return 0; }
98static inline void thermal_gov_bang_bang_unregister(void) {}
99#endif /* CONFIG_THERMAL_GOV_BANG_BANG */
100
101#ifdef CONFIG_THERMAL_GOV_USER_SPACE
102int thermal_gov_user_space_register(void);
103void thermal_gov_user_space_unregister(void);
104#else
105static inline int thermal_gov_user_space_register(void) { return 0; }
106static inline void thermal_gov_user_space_unregister(void) {}
107#endif /* CONFIG_THERMAL_GOV_USER_SPACE */
108
109#ifdef CONFIG_THERMAL_GOV_POWER_ALLOCATOR
110int thermal_gov_power_allocator_register(void);
111void thermal_gov_power_allocator_unregister(void);
112#else
113static inline int thermal_gov_power_allocator_register(void) { return 0; }
114static inline void thermal_gov_power_allocator_unregister(void) {}
115#endif /* CONFIG_THERMAL_GOV_POWER_ALLOCATOR */
116
117/* device tree support */
118#ifdef CONFIG_THERMAL_OF
119int of_parse_thermal_zones(void);
120void of_thermal_destroy_zones(void);
121int of_thermal_get_ntrips(struct thermal_zone_device *);
122bool of_thermal_is_trip_valid(struct thermal_zone_device *, int);
123const struct thermal_trip *
124of_thermal_get_trip_points(struct thermal_zone_device *);
125#else
126static inline int of_parse_thermal_zones(void) { return 0; }
127static inline void of_thermal_destroy_zones(void) { }
128static inline int of_thermal_get_ntrips(struct thermal_zone_device *tz)
129{
130 return 0;
131}
132static inline bool of_thermal_is_trip_valid(struct thermal_zone_device *tz,
133 int trip)
134{
135 return false;
136}
137static inline const struct thermal_trip *
138of_thermal_get_trip_points(struct thermal_zone_device *tz)
139{
140 return NULL;
141}
142#endif
143
144#endif /* __THERMAL_CORE_H__ */