thermal_core.h 4.99 KB
Newer Older
1
/* SPDX-License-Identifier: GPL-2.0 */
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
/*
 *  thermal_core.h
 *
 *  Copyright (C) 2012  Intel Corp
 *  Author: Durgadoss R <durgadoss.r@intel.com>
 */

#ifndef __THERMAL_CORE_H__
#define __THERMAL_CORE_H__

#include <linux/device.h>
#include <linux/thermal.h>

/* Initial state of a cooling device during binding */
#define THERMAL_NO_TARGET -1UL

/*
 * This structure is used to describe the behavior of
 * a certain cooling device on a certain trip point
 * in a certain thermal zone
 */
struct thermal_instance {
	int id;
	char name[THERMAL_NAME_LENGTH];
	struct thermal_zone_device *tz;
	struct thermal_cooling_device *cdev;
	int trip;
29
	bool initialized;
30 31 32 33 34
	unsigned long upper;	/* Highest cooling state for this trip point */
	unsigned long lower;	/* Lowest cooling state for this trip point */
	unsigned long target;	/* expected cooling state */
	char attr_name[THERMAL_NAME_LENGTH];
	struct device_attribute attr;
35 36
	char weight_attr_name[THERMAL_NAME_LENGTH];
	struct device_attribute weight_attr;
37 38
	struct list_head tz_node; /* node in tz->thermal_instances */
	struct list_head cdev_node; /* node in cdev->thermal_instances */
39
	unsigned int weight; /* The weight of the cooling device */
40 41
};

42 43 44
#define to_thermal_zone(_dev) \
	container_of(_dev, struct thermal_zone_device, device)

45 46 47
#define to_cooling_device(_dev)	\
	container_of(_dev, struct thermal_cooling_device, device)

48 49
int thermal_register_governor(struct thermal_governor *);
void thermal_unregister_governor(struct thermal_governor *);
50 51 52 53
void thermal_zone_device_rebind_exception(struct thermal_zone_device *,
					  const char *, size_t);
void thermal_zone_device_unbind_exception(struct thermal_zone_device *,
					  const char *, size_t);
54
int thermal_zone_device_set_policy(struct thermal_zone_device *, char *);
55
int thermal_build_list_of_policies(char *buf);
56

57 58
/* sysfs I/F */
int thermal_zone_create_device_groups(struct thermal_zone_device *, int);
59
void thermal_zone_destroy_device_groups(struct thermal_zone_device *);
60
void thermal_cooling_device_setup_sysfs(struct thermal_cooling_device *);
61
void thermal_cooling_device_destroy_sysfs(struct thermal_cooling_device *cdev);
62
/* used only at binding time */
63 64 65 66
ssize_t trip_point_show(struct device *, struct device_attribute *, char *);
ssize_t weight_show(struct device *, struct device_attribute *, char *);
ssize_t weight_store(struct device *, struct device_attribute *, const char *,
		     size_t);
67

68 69 70 71 72 73 74 75 76
#ifdef CONFIG_THERMAL_STATISTICS
void thermal_cooling_device_stats_update(struct thermal_cooling_device *cdev,
					 unsigned long new_state);
#else
static inline void
thermal_cooling_device_stats_update(struct thermal_cooling_device *cdev,
				    unsigned long new_state) {}
#endif /* CONFIG_THERMAL_STATISTICS */

77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
#ifdef CONFIG_THERMAL_GOV_STEP_WISE
int thermal_gov_step_wise_register(void);
void thermal_gov_step_wise_unregister(void);
#else
static inline int thermal_gov_step_wise_register(void) { return 0; }
static inline void thermal_gov_step_wise_unregister(void) {}
#endif /* CONFIG_THERMAL_GOV_STEP_WISE */

#ifdef CONFIG_THERMAL_GOV_FAIR_SHARE
int thermal_gov_fair_share_register(void);
void thermal_gov_fair_share_unregister(void);
#else
static inline int thermal_gov_fair_share_register(void) { return 0; }
static inline void thermal_gov_fair_share_unregister(void) {}
#endif /* CONFIG_THERMAL_GOV_FAIR_SHARE */

93 94 95 96 97 98 99 100
#ifdef CONFIG_THERMAL_GOV_BANG_BANG
int thermal_gov_bang_bang_register(void);
void thermal_gov_bang_bang_unregister(void);
#else
static inline int thermal_gov_bang_bang_register(void) { return 0; }
static inline void thermal_gov_bang_bang_unregister(void) {}
#endif /* CONFIG_THERMAL_GOV_BANG_BANG */

101 102 103 104 105 106 107 108
#ifdef CONFIG_THERMAL_GOV_USER_SPACE
int thermal_gov_user_space_register(void);
void thermal_gov_user_space_unregister(void);
#else
static inline int thermal_gov_user_space_register(void) { return 0; }
static inline void thermal_gov_user_space_unregister(void) {}
#endif /* CONFIG_THERMAL_GOV_USER_SPACE */

109 110 111 112 113 114 115 116
#ifdef CONFIG_THERMAL_GOV_POWER_ALLOCATOR
int thermal_gov_power_allocator_register(void);
void thermal_gov_power_allocator_unregister(void);
#else
static inline int thermal_gov_power_allocator_register(void) { return 0; }
static inline void thermal_gov_power_allocator_unregister(void) {}
#endif /* CONFIG_THERMAL_GOV_POWER_ALLOCATOR */

117 118 119 120
/* device tree support */
#ifdef CONFIG_THERMAL_OF
int of_parse_thermal_zones(void);
void of_thermal_destroy_zones(void);
121
int of_thermal_get_ntrips(struct thermal_zone_device *);
122
bool of_thermal_is_trip_valid(struct thermal_zone_device *, int);
123
const struct thermal_trip *
124
of_thermal_get_trip_points(struct thermal_zone_device *);
125 126 127
#else
static inline int of_parse_thermal_zones(void) { return 0; }
static inline void of_thermal_destroy_zones(void) { }
128 129 130 131
static inline int of_thermal_get_ntrips(struct thermal_zone_device *tz)
{
	return 0;
}
132 133 134
static inline bool of_thermal_is_trip_valid(struct thermal_zone_device *tz,
					    int trip)
{
135
	return false;
136
}
137
static inline const struct thermal_trip *
138 139 140 141
of_thermal_get_trip_points(struct thermal_zone_device *tz)
{
	return NULL;
}
142 143
#endif

144
#endif /* __THERMAL_CORE_H__ */