• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 /* Init section thermal table */
19 extern struct thermal_governor *__governor_thermal_table[];
20 extern struct thermal_governor *__governor_thermal_table_end[];
21 
22 #define THERMAL_TABLE_ENTRY(table, name)			\
23 	static typeof(name) *__thermal_table_entry_##name	\
24 	__used __section(__##table##_thermal_table) = &name
25 
26 #define THERMAL_GOVERNOR_DECLARE(name)	THERMAL_TABLE_ENTRY(governor, name)
27 
28 #define for_each_governor_table(__governor)		\
29 	for (__governor = __governor_thermal_table;	\
30 	     __governor < __governor_thermal_table_end;	\
31 	     __governor++)
32 
33 /*
34  * This structure is used to describe the behavior of
35  * a certain cooling device on a certain trip point
36  * in a certain thermal zone
37  */
38 struct thermal_instance {
39 	int id;
40 	char name[THERMAL_NAME_LENGTH];
41 	struct thermal_zone_device *tz;
42 	struct thermal_cooling_device *cdev;
43 	int trip;
44 	bool initialized;
45 	unsigned long upper;	/* Highest cooling state for this trip point */
46 	unsigned long lower;	/* Lowest cooling state for this trip point */
47 	unsigned long target;	/* expected cooling state */
48 	char attr_name[THERMAL_NAME_LENGTH];
49 	struct device_attribute attr;
50 	char weight_attr_name[THERMAL_NAME_LENGTH];
51 	struct device_attribute weight_attr;
52 	struct list_head tz_node; /* node in tz->thermal_instances */
53 	struct list_head cdev_node; /* node in cdev->thermal_instances */
54 	unsigned int weight; /* The weight of the cooling device */
55 };
56 
57 #define to_thermal_zone(_dev) \
58 	container_of(_dev, struct thermal_zone_device, device)
59 
60 #define to_cooling_device(_dev)	\
61 	container_of(_dev, struct thermal_cooling_device, device)
62 
63 int thermal_register_governor(struct thermal_governor *);
64 void thermal_unregister_governor(struct thermal_governor *);
65 void thermal_zone_device_rebind_exception(struct thermal_zone_device *,
66 					  const char *, size_t);
67 void thermal_zone_device_unbind_exception(struct thermal_zone_device *,
68 					  const char *, size_t);
69 int thermal_zone_device_set_policy(struct thermal_zone_device *, char *);
70 int thermal_build_list_of_policies(char *buf);
71 
72 /* sysfs I/F */
73 int thermal_zone_create_device_groups(struct thermal_zone_device *, int);
74 void thermal_zone_destroy_device_groups(struct thermal_zone_device *);
75 void thermal_cooling_device_setup_sysfs(struct thermal_cooling_device *);
76 void thermal_cooling_device_destroy_sysfs(struct thermal_cooling_device *cdev);
77 /* used only at binding time */
78 ssize_t trip_point_show(struct device *, struct device_attribute *, char *);
79 ssize_t weight_show(struct device *, struct device_attribute *, char *);
80 ssize_t weight_store(struct device *, struct device_attribute *, const char *,
81 		     size_t);
82 
83 #ifdef CONFIG_THERMAL_STATISTICS
84 void thermal_cooling_device_stats_update(struct thermal_cooling_device *cdev,
85 					 unsigned long new_state);
86 #else
87 static inline void
thermal_cooling_device_stats_update(struct thermal_cooling_device * cdev,unsigned long new_state)88 thermal_cooling_device_stats_update(struct thermal_cooling_device *cdev,
89 				    unsigned long new_state) {}
90 #endif /* CONFIG_THERMAL_STATISTICS */
91 
92 /* device tree support */
93 #ifdef CONFIG_THERMAL_OF
94 int of_parse_thermal_zones(void);
95 void of_thermal_destroy_zones(void);
96 int of_thermal_get_ntrips(struct thermal_zone_device *);
97 bool of_thermal_is_trip_valid(struct thermal_zone_device *, int);
98 const struct thermal_trip *
99 of_thermal_get_trip_points(struct thermal_zone_device *);
100 #else
of_parse_thermal_zones(void)101 static inline int of_parse_thermal_zones(void) { return 0; }
of_thermal_destroy_zones(void)102 static inline void of_thermal_destroy_zones(void) { }
of_thermal_get_ntrips(struct thermal_zone_device * tz)103 static inline int of_thermal_get_ntrips(struct thermal_zone_device *tz)
104 {
105 	return 0;
106 }
of_thermal_is_trip_valid(struct thermal_zone_device * tz,int trip)107 static inline bool of_thermal_is_trip_valid(struct thermal_zone_device *tz,
108 					    int trip)
109 {
110 	return false;
111 }
112 static inline const struct thermal_trip *
of_thermal_get_trip_points(struct thermal_zone_device * tz)113 of_thermal_get_trip_points(struct thermal_zone_device *tz)
114 {
115 	return NULL;
116 }
117 #endif
118 
119 #endif /* __THERMAL_CORE_H__ */
120