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>
|
|
|
|
|
2020-07-07 17:01:57 +08:00
|
|
|
#include "thermal_netlink.h"
|
|
|
|
|
2020-04-02 22:27:39 +08:00
|
|
|
/* Default Thermal Governor */
|
|
|
|
#if defined(CONFIG_THERMAL_DEFAULT_GOV_STEP_WISE)
|
|
|
|
#define DEFAULT_THERMAL_GOVERNOR "step_wise"
|
|
|
|
#elif defined(CONFIG_THERMAL_DEFAULT_GOV_FAIR_SHARE)
|
|
|
|
#define DEFAULT_THERMAL_GOVERNOR "fair_share"
|
|
|
|
#elif defined(CONFIG_THERMAL_DEFAULT_GOV_USER_SPACE)
|
|
|
|
#define DEFAULT_THERMAL_GOVERNOR "user_space"
|
|
|
|
#elif defined(CONFIG_THERMAL_DEFAULT_GOV_POWER_ALLOCATOR)
|
|
|
|
#define DEFAULT_THERMAL_GOVERNOR "power_allocator"
|
2023-06-09 20:44:08 +08:00
|
|
|
#elif defined(CONFIG_THERMAL_DEFAULT_GOV_BANG_BANG)
|
|
|
|
#define DEFAULT_THERMAL_GOVERNOR "bang_bang"
|
2020-04-02 22:27:39 +08:00
|
|
|
#endif
|
|
|
|
|
2012-09-18 13:34:53 +08:00
|
|
|
/* 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 \
|
2020-10-22 10:36:07 +08:00
|
|
|
__used __section("__" #table "_thermal_table") = &name
|
2019-06-13 04:13:24 +08:00
|
|
|
|
|
|
|
#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++)
|
|
|
|
|
2020-07-06 18:55:35 +08:00
|
|
|
int for_each_thermal_zone(int (*cb)(struct thermal_zone_device *, void *),
|
|
|
|
void *);
|
|
|
|
|
|
|
|
int for_each_thermal_cooling_device(int (*cb)(struct thermal_cooling_device *,
|
|
|
|
void *), void *);
|
|
|
|
|
|
|
|
int for_each_thermal_governor(int (*cb)(struct thermal_governor *, void *),
|
|
|
|
void *thermal_governor);
|
|
|
|
|
2020-07-06 18:55:36 +08:00
|
|
|
struct thermal_zone_device *thermal_zone_get_by_id(int id);
|
|
|
|
|
2020-04-02 22:27:40 +08:00
|
|
|
struct thermal_attr {
|
|
|
|
struct device_attribute attr;
|
|
|
|
char name[THERMAL_NAME_LENGTH];
|
|
|
|
};
|
|
|
|
|
2020-04-02 22:27:41 +08:00
|
|
|
static inline bool cdev_is_power_actor(struct thermal_cooling_device *cdev)
|
|
|
|
{
|
|
|
|
return cdev->ops->get_requested_power && cdev->ops->state2power &&
|
|
|
|
cdev->ops->power2state;
|
|
|
|
}
|
|
|
|
|
2021-01-19 01:38:24 +08:00
|
|
|
void thermal_cdev_update(struct thermal_cooling_device *);
|
2021-04-22 19:43:06 +08:00
|
|
|
void __thermal_cdev_update(struct thermal_cooling_device *cdev);
|
2021-01-19 01:38:24 +08:00
|
|
|
|
2023-08-22 19:40:06 +08:00
|
|
|
int get_tz_trend(struct thermal_zone_device *tz, int trip_index);
|
2020-04-02 22:27:43 +08:00
|
|
|
|
2020-04-02 22:27:44 +08:00
|
|
|
struct thermal_instance *
|
|
|
|
get_thermal_instance(struct thermal_zone_device *tz,
|
|
|
|
struct thermal_cooling_device *cdev,
|
|
|
|
int trip);
|
|
|
|
|
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;
|
2023-09-22 01:52:44 +08:00
|
|
|
const struct thermal_trip *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 */
|
2023-03-18 01:01:26 +08:00
|
|
|
bool upper_no_limit;
|
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: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);
|
2022-11-10 23:24:58 +08:00
|
|
|
void __thermal_zone_device_update(struct thermal_zone_device *tz,
|
|
|
|
enum thermal_notify_event event);
|
2013-03-26 16:38:29 +08:00
|
|
|
|
2020-04-01 00:54:48 +08:00
|
|
|
/* Helpers */
|
2022-08-05 23:38:34 +08:00
|
|
|
void __thermal_zone_set_trips(struct thermal_zone_device *tz);
|
thermal/core: Add a generic thermal_zone_get_trip() function
The thermal_zone_device_ops structure defines a set of ops family,
get_trip_temp(), get_trip_hyst(), get_trip_type(). Each of them is
returning a property of a trip point.
The result is the code is calling the ops everywhere to get a trip
point which is supposed to be defined in the backend driver. It is a
non-sense as a thermal trip can be generic and used by the backend
driver to declare its trip points.
Part of the thermal framework has been changed and all the OF thermal
drivers are using the same definition for the trip point and use a
thermal zone registration variant to pass those trip points which are
part of the thermal zone device structure.
Consequently, we can use a generic function to get the trip points
when they are stored in the thermal zone device structure.
This approach can be generalized to all the drivers and we can get rid
of the ops->get_trip_*. That will result to a much more simpler code
and make possible to rework how the thermal trip are handled in the
thermal core framework as discussed previously.
This change adds a function thermal_zone_get_trip() where we get the
thermal trip point structure which contains all the properties (type,
temp, hyst) instead of doing multiple calls to ops->get_trip_*.
That opens the door for trip point extension with more attributes. For
instance, replacing the trip points disabled bitmask with a 'disabled'
field in the structure.
Here we replace all the calls to ops->get_trip_* in the thermal core
code with a call to the thermal_zone_get_trip() function.
The thermal zone ops defines a callback to retrieve the critical
temperature. As the trip handling is being reworked, all the trip
points will be the same whatever the driver and consequently finding
the critical trip temperature will be just a loop to search for a
critical trip point type.
Provide such a generic function, so we encapsulate the ops
get_crit_temp() which can be removed when all the backend drivers are
using the generic trip points handling.
While at it, add the thermal_zone_get_num_trips() to encapsulate the
code more and reduce the grip with the thermal framework internals.
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Zhang Rui <rui.zhang@intel.com>
Link: https://lore.kernel.org/r/20221003092602.1323944-2-daniel.lezcano@linaro.org
2022-10-03 17:25:34 +08:00
|
|
|
int __thermal_zone_get_trip(struct thermal_zone_device *tz, int trip_id,
|
|
|
|
struct thermal_trip *trip);
|
2023-09-22 01:52:44 +08:00
|
|
|
int thermal_zone_trip_id(struct thermal_zone_device *tz,
|
|
|
|
const struct thermal_trip *trip);
|
2022-08-05 23:38:34 +08:00
|
|
|
int __thermal_zone_get_temp(struct thermal_zone_device *tz, int *temp);
|
2020-04-01 00:54:48 +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);
|
2023-03-18 01:01:26 +08:00
|
|
|
void thermal_cooling_device_stats_reinit(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 */
|
2020-07-03 18:43:54 +08:00
|
|
|
int thermal_zone_device_is_enabled(struct thermal_zone_device *tz);
|
|
|
|
|
2012-09-18 13:34:53 +08:00
|
|
|
#endif /* __THERMAL_CORE_H__ */
|