2018-05-08 01:52:29 +08:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 */
|
2012-09-18 13:34:53 +08:00
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
|
2019-06-13 04:13:24 +08:00
|
|
|
/* Init section thermal table */
|
|
|
|
extern struct thermal_governor *__governor_thermal_table[];
|
|
|
|
extern struct thermal_governor *__governor_thermal_table_end[];
|
|
|
|
|
|
|
|
#define THERMAL_TABLE_ENTRY(table, name) \
|
|
|
|
static typeof(name) *__thermal_table_entry_##name \
|
|
|
|
__used __section(__##table##_thermal_table) = &name
|
|
|
|
|
|
|
|
#define THERMAL_GOVERNOR_DECLARE(name) THERMAL_TABLE_ENTRY(governor, name)
|
|
|
|
|
|
|
|
#define for_each_governor_table(__governor) \
|
|
|
|
for (__governor = __governor_thermal_table; \
|
|
|
|
__governor < __governor_thermal_table_end; \
|
|
|
|
__governor++)
|
|
|
|
|
2012-09-18 13:34:53 +08:00
|
|
|
/*
|
|
|
|
* 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;
|
2015-10-30 16:31:47 +08:00
|
|
|
bool initialized;
|
2012-09-18 13:34:53 +08:00
|
|
|
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;
|
2015-02-19 00:04:24 +08:00
|
|
|
char weight_attr_name[THERMAL_NAME_LENGTH];
|
|
|
|
struct device_attribute weight_attr;
|
2012-09-18 13:34:53 +08:00
|
|
|
struct list_head tz_node; /* node in tz->thermal_instances */
|
|
|
|
struct list_head cdev_node; /* node in cdev->thermal_instances */
|
2015-02-19 00:04:21 +08:00
|
|
|
unsigned int weight; /* The weight of the cooling device */
|
2012-09-18 13:34:53 +08:00
|
|
|
};
|
|
|
|
|
2016-11-08 13:08:57 +08:00
|
|
|
#define to_thermal_zone(_dev) \
|
|
|
|
container_of(_dev, struct thermal_zone_device, device)
|
|
|
|
|
2016-11-08 13:09:01 +08:00
|
|
|
#define to_cooling_device(_dev) \
|
|
|
|
container_of(_dev, struct thermal_cooling_device, device)
|
|
|
|
|
2013-03-26 16:38:29 +08:00
|
|
|
int thermal_register_governor(struct thermal_governor *);
|
|
|
|
void thermal_unregister_governor(struct thermal_governor *);
|
2016-11-08 13:08:54 +08:00
|
|
|
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);
|
2016-11-08 13:08:55 +08:00
|
|
|
int thermal_zone_device_set_policy(struct thermal_zone_device *, char *);
|
2016-11-08 13:08:56 +08:00
|
|
|
int thermal_build_list_of_policies(char *buf);
|
2013-03-26 16:38:29 +08:00
|
|
|
|
2016-11-08 13:09:00 +08:00
|
|
|
/* sysfs I/F */
|
|
|
|
int thermal_zone_create_device_groups(struct thermal_zone_device *, int);
|
2017-08-08 22:39:52 +08:00
|
|
|
void thermal_zone_destroy_device_groups(struct thermal_zone_device *);
|
2016-11-08 13:09:02 +08:00
|
|
|
void thermal_cooling_device_setup_sysfs(struct thermal_cooling_device *);
|
2018-04-02 18:56:25 +08:00
|
|
|
void thermal_cooling_device_destroy_sysfs(struct thermal_cooling_device *cdev);
|
2016-11-08 13:09:02 +08:00
|
|
|
/* used only at binding time */
|
2018-04-03 17:49:03 +08:00
|
|
|
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);
|
2016-11-08 13:09:00 +08:00
|
|
|
|
2018-04-02 18:56:25 +08:00
|
|
|
#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 */
|
|
|
|
|
2013-07-04 03:35:39 +08:00
|
|
|
/* device tree support */
|
|
|
|
#ifdef CONFIG_THERMAL_OF
|
|
|
|
int of_parse_thermal_zones(void);
|
|
|
|
void of_thermal_destroy_zones(void);
|
2014-12-09 01:04:17 +08:00
|
|
|
int of_thermal_get_ntrips(struct thermal_zone_device *);
|
2014-12-09 01:04:18 +08:00
|
|
|
bool of_thermal_is_trip_valid(struct thermal_zone_device *, int);
|
2015-01-04 05:56:56 +08:00
|
|
|
const struct thermal_trip *
|
2014-12-09 01:04:20 +08:00
|
|
|
of_thermal_get_trip_points(struct thermal_zone_device *);
|
2013-07-04 03:35:39 +08:00
|
|
|
#else
|
|
|
|
static inline int of_parse_thermal_zones(void) { return 0; }
|
|
|
|
static inline void of_thermal_destroy_zones(void) { }
|
2014-12-09 01:04:17 +08:00
|
|
|
static inline int of_thermal_get_ntrips(struct thermal_zone_device *tz)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2014-12-09 01:04:18 +08:00
|
|
|
static inline bool of_thermal_is_trip_valid(struct thermal_zone_device *tz,
|
|
|
|
int trip)
|
|
|
|
{
|
2015-03-31 01:43:22 +08:00
|
|
|
return false;
|
2014-12-09 01:04:18 +08:00
|
|
|
}
|
2015-01-04 05:56:56 +08:00
|
|
|
static inline const struct thermal_trip *
|
2014-12-09 01:04:20 +08:00
|
|
|
of_thermal_get_trip_points(struct thermal_zone_device *tz)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
2013-07-04 03:35:39 +08:00
|
|
|
#endif
|
|
|
|
|
2012-09-18 13:34:53 +08:00
|
|
|
#endif /* __THERMAL_CORE_H__ */
|