Linux Audio

Check our new training course

Loading...
v5.9
  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#include "thermal_netlink.h"
 16
 17/* Default Thermal Governor */
 18#if defined(CONFIG_THERMAL_DEFAULT_GOV_STEP_WISE)
 19#define DEFAULT_THERMAL_GOVERNOR       "step_wise"
 20#elif defined(CONFIG_THERMAL_DEFAULT_GOV_FAIR_SHARE)
 21#define DEFAULT_THERMAL_GOVERNOR       "fair_share"
 22#elif defined(CONFIG_THERMAL_DEFAULT_GOV_USER_SPACE)
 23#define DEFAULT_THERMAL_GOVERNOR       "user_space"
 24#elif defined(CONFIG_THERMAL_DEFAULT_GOV_POWER_ALLOCATOR)
 25#define DEFAULT_THERMAL_GOVERNOR       "power_allocator"
 26#endif
 27
 28/* Initial state of a cooling device during binding */
 29#define THERMAL_NO_TARGET -1UL
 30
 31/* Init section thermal table */
 32extern struct thermal_governor *__governor_thermal_table[];
 33extern struct thermal_governor *__governor_thermal_table_end[];
 34
 35#define THERMAL_TABLE_ENTRY(table, name)			\
 36	static typeof(name) *__thermal_table_entry_##name	\
 37	__used __section(__##table##_thermal_table) = &name
 38
 39#define THERMAL_GOVERNOR_DECLARE(name)	THERMAL_TABLE_ENTRY(governor, name)
 40
 41#define for_each_governor_table(__governor)		\
 42	for (__governor = __governor_thermal_table;	\
 43	     __governor < __governor_thermal_table_end;	\
 44	     __governor++)
 45
 46int for_each_thermal_zone(int (*cb)(struct thermal_zone_device *, void *),
 47			  void *);
 48
 49int for_each_thermal_cooling_device(int (*cb)(struct thermal_cooling_device *,
 50					      void *), void *);
 51
 52int for_each_thermal_governor(int (*cb)(struct thermal_governor *, void *),
 53			      void *thermal_governor);
 54
 55struct thermal_zone_device *thermal_zone_get_by_id(int id);
 56
 57struct thermal_attr {
 58	struct device_attribute attr;
 59	char name[THERMAL_NAME_LENGTH];
 60};
 61
 62static inline bool cdev_is_power_actor(struct thermal_cooling_device *cdev)
 63{
 64	return cdev->ops->get_requested_power && cdev->ops->state2power &&
 65		cdev->ops->power2state;
 66}
 67
 68int power_actor_get_max_power(struct thermal_cooling_device *cdev,
 69			      struct thermal_zone_device *tz, u32 *max_power);
 70int power_actor_get_min_power(struct thermal_cooling_device *cdev,
 71			      struct thermal_zone_device *tz, u32 *min_power);
 72int power_actor_set_power(struct thermal_cooling_device *cdev,
 73			  struct thermal_instance *ti, u32 power);
 74/**
 75 * struct thermal_trip - representation of a point in temperature domain
 76 * @np: pointer to struct device_node that this trip point was created from
 77 * @temperature: temperature value in miliCelsius
 78 * @hysteresis: relative hysteresis in miliCelsius
 79 * @type: trip point type
 80 */
 81struct thermal_trip {
 82	struct device_node *np;
 83	int temperature;
 84	int hysteresis;
 85	enum thermal_trip_type type;
 86};
 87
 88int get_tz_trend(struct thermal_zone_device *tz, int trip);
 89
 90struct thermal_instance *
 91get_thermal_instance(struct thermal_zone_device *tz,
 92		     struct thermal_cooling_device *cdev,
 93		     int trip);
 94
 95/*
 96 * This structure is used to describe the behavior of
 97 * a certain cooling device on a certain trip point
 98 * in a certain thermal zone
 99 */
100struct thermal_instance {
101	int id;
102	char name[THERMAL_NAME_LENGTH];
103	struct thermal_zone_device *tz;
104	struct thermal_cooling_device *cdev;
105	int trip;
106	bool initialized;
107	unsigned long upper;	/* Highest cooling state for this trip point */
108	unsigned long lower;	/* Lowest cooling state for this trip point */
109	unsigned long target;	/* expected cooling state */
110	char attr_name[THERMAL_NAME_LENGTH];
111	struct device_attribute attr;
112	char weight_attr_name[THERMAL_NAME_LENGTH];
113	struct device_attribute weight_attr;
114	struct list_head tz_node; /* node in tz->thermal_instances */
115	struct list_head cdev_node; /* node in cdev->thermal_instances */
116	unsigned int weight; /* The weight of the cooling device */
117};
118
119#define to_thermal_zone(_dev) \
120	container_of(_dev, struct thermal_zone_device, device)
121
122#define to_cooling_device(_dev)	\
123	container_of(_dev, struct thermal_cooling_device, device)
124
125int thermal_register_governor(struct thermal_governor *);
126void thermal_unregister_governor(struct thermal_governor *);
127void thermal_zone_device_rebind_exception(struct thermal_zone_device *,
128					  const char *, size_t);
129void thermal_zone_device_unbind_exception(struct thermal_zone_device *,
130					  const char *, size_t);
131int thermal_zone_device_set_policy(struct thermal_zone_device *, char *);
132int thermal_build_list_of_policies(char *buf);
133
134/* Helpers */
135void thermal_zone_set_trips(struct thermal_zone_device *tz);
136
137/* sysfs I/F */
138int thermal_zone_create_device_groups(struct thermal_zone_device *, int);
139void thermal_zone_destroy_device_groups(struct thermal_zone_device *);
140void thermal_cooling_device_setup_sysfs(struct thermal_cooling_device *);
141void thermal_cooling_device_destroy_sysfs(struct thermal_cooling_device *cdev);
142/* used only at binding time */
143ssize_t trip_point_show(struct device *, struct device_attribute *, char *);
144ssize_t weight_show(struct device *, struct device_attribute *, char *);
145ssize_t weight_store(struct device *, struct device_attribute *, const char *,
146		     size_t);
147
148#ifdef CONFIG_THERMAL_STATISTICS
149void thermal_cooling_device_stats_update(struct thermal_cooling_device *cdev,
150					 unsigned long new_state);
151#else
152static inline void
153thermal_cooling_device_stats_update(struct thermal_cooling_device *cdev,
154				    unsigned long new_state) {}
155#endif /* CONFIG_THERMAL_STATISTICS */
 
 
 
 
 
 
 
 
 
 
 
156
157/* device tree support */
158#ifdef CONFIG_THERMAL_OF
159int of_parse_thermal_zones(void);
 
160int of_thermal_get_ntrips(struct thermal_zone_device *);
161bool of_thermal_is_trip_valid(struct thermal_zone_device *, int);
162const struct thermal_trip *
163of_thermal_get_trip_points(struct thermal_zone_device *);
164#else
165static inline int of_parse_thermal_zones(void) { return 0; }
 
166static inline int of_thermal_get_ntrips(struct thermal_zone_device *tz)
167{
168	return 0;
169}
170static inline bool of_thermal_is_trip_valid(struct thermal_zone_device *tz,
171					    int trip)
172{
173	return false;
174}
175static inline const struct thermal_trip *
176of_thermal_get_trip_points(struct thermal_zone_device *tz)
177{
178	return NULL;
179}
180#endif
181
182int thermal_zone_device_is_enabled(struct thermal_zone_device *tz);
183
184#endif /* __THERMAL_CORE_H__ */
v4.6
 
  1/*
  2 *  thermal_core.h
  3 *
  4 *  Copyright (C) 2012  Intel Corp
  5 *  Author: Durgadoss R <durgadoss.r@intel.com>
  6 *
  7 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  8 *  This program is free software; you can redistribute it and/or modify
  9 *  it under the terms of the GNU General Public License as published by
 10 *  the Free Software Foundation; version 2 of the License.
 11 *
 12 *  This program is distributed in the hope that it will be useful, but
 13 *  WITHOUT ANY WARRANTY; without even the implied warranty of
 14 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 15 *  General Public License for more details.
 16 *
 17 *  You should have received a copy of the GNU General Public License along
 18 *  with this program; if not, write to the Free Software Foundation, Inc.,
 19 *  59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
 20 *
 21 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 22 */
 23
 24#ifndef __THERMAL_CORE_H__
 25#define __THERMAL_CORE_H__
 26
 27#include <linux/device.h>
 28#include <linux/thermal.h>
 29
 
 
 
 
 
 
 
 
 
 
 
 
 
 30/* Initial state of a cooling device during binding */
 31#define THERMAL_NO_TARGET -1UL
 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 */
 38struct 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
 
 
 
 
 
 
 57int thermal_register_governor(struct thermal_governor *);
 58void thermal_unregister_governor(struct thermal_governor *);
 59
 60#ifdef CONFIG_THERMAL_GOV_STEP_WISE
 61int thermal_gov_step_wise_register(void);
 62void thermal_gov_step_wise_unregister(void);
 63#else
 64static inline int thermal_gov_step_wise_register(void) { return 0; }
 65static inline void thermal_gov_step_wise_unregister(void) {}
 66#endif /* CONFIG_THERMAL_GOV_STEP_WISE */
 67
 68#ifdef CONFIG_THERMAL_GOV_FAIR_SHARE
 69int thermal_gov_fair_share_register(void);
 70void thermal_gov_fair_share_unregister(void);
 71#else
 72static inline int thermal_gov_fair_share_register(void) { return 0; }
 73static inline void thermal_gov_fair_share_unregister(void) {}
 74#endif /* CONFIG_THERMAL_GOV_FAIR_SHARE */
 75
 76#ifdef CONFIG_THERMAL_GOV_BANG_BANG
 77int thermal_gov_bang_bang_register(void);
 78void thermal_gov_bang_bang_unregister(void);
 79#else
 80static inline int thermal_gov_bang_bang_register(void) { return 0; }
 81static inline void thermal_gov_bang_bang_unregister(void) {}
 82#endif /* CONFIG_THERMAL_GOV_BANG_BANG */
 83
 84#ifdef CONFIG_THERMAL_GOV_USER_SPACE
 85int thermal_gov_user_space_register(void);
 86void thermal_gov_user_space_unregister(void);
 87#else
 88static inline int thermal_gov_user_space_register(void) { return 0; }
 89static inline void thermal_gov_user_space_unregister(void) {}
 90#endif /* CONFIG_THERMAL_GOV_USER_SPACE */
 91
 92#ifdef CONFIG_THERMAL_GOV_POWER_ALLOCATOR
 93int thermal_gov_power_allocator_register(void);
 94void thermal_gov_power_allocator_unregister(void);
 95#else
 96static inline int thermal_gov_power_allocator_register(void) { return 0; }
 97static inline void thermal_gov_power_allocator_unregister(void) {}
 98#endif /* CONFIG_THERMAL_GOV_POWER_ALLOCATOR */
 99
100/* device tree support */
101#ifdef CONFIG_THERMAL_OF
102int of_parse_thermal_zones(void);
103void of_thermal_destroy_zones(void);
104int of_thermal_get_ntrips(struct thermal_zone_device *);
105bool of_thermal_is_trip_valid(struct thermal_zone_device *, int);
106const struct thermal_trip *
107of_thermal_get_trip_points(struct thermal_zone_device *);
108#else
109static inline int of_parse_thermal_zones(void) { return 0; }
110static inline void of_thermal_destroy_zones(void) { }
111static inline int of_thermal_get_ntrips(struct thermal_zone_device *tz)
112{
113	return 0;
114}
115static inline bool of_thermal_is_trip_valid(struct thermal_zone_device *tz,
116					    int trip)
117{
118	return false;
119}
120static inline const struct thermal_trip *
121of_thermal_get_trip_points(struct thermal_zone_device *tz)
122{
123	return NULL;
124}
125#endif
 
 
126
127#endif /* __THERMAL_CORE_H__ */