Blame view

drivers/thermal/thermal_core.h 5.97 KB
7e3c03817   Lina Iyer   drivers: thermal:...
1
  /* SPDX-License-Identifier: GPL-2.0 */
71350db43   Durgadoss R   Thermal: Move the...
2
3
4
5
6
  /*
   *  thermal_core.h
   *
   *  Copyright (C) 2012  Intel Corp
   *  Author: Durgadoss R <durgadoss.r@intel.com>
71350db43   Durgadoss R   Thermal: Move the...
7
8
9
10
11
12
13
   */
  
  #ifndef __THERMAL_CORE_H__
  #define __THERMAL_CORE_H__
  
  #include <linux/device.h>
  #include <linux/thermal.h>
5b8583d3b   Daniel Lezcano   thermal: netlink:...
14
  #include "thermal_netlink.h"
8097db407   Daniel Lezcano   thermal: Move def...
15
16
17
18
19
20
21
22
23
24
  /* 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"
  #endif
71350db43   Durgadoss R   Thermal: Move the...
25
26
  /* Initial state of a cooling device during binding */
  #define THERMAL_NO_TARGET -1UL
980af75ed   Daniel Lezcano   thermal/drivers/c...
27
28
29
30
31
32
  /* 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	\
33def8498   Joe Perches   treewide: Convert...
33
  	__used __section("__" #table "_thermal_table") = &name
980af75ed   Daniel Lezcano   thermal/drivers/c...
34
35
36
37
38
39
40
  
  #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++)
3d44a509c   Daniel Lezcano   thermal: core: Ad...
41
42
43
44
45
46
47
48
  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);
329b064fb   Daniel Lezcano   thermal: core: Ge...
49
  struct thermal_zone_device *thermal_zone_get_by_id(int id);
c68df440b   Daniel Lezcano   thermal: Move str...
50
51
52
53
  struct thermal_attr {
  	struct device_attribute attr;
  	char name[THERMAL_NAME_LENGTH];
  };
33a88af10   Daniel Lezcano   thermal: Move int...
54
55
56
57
58
59
60
  static inline bool cdev_is_power_actor(struct thermal_cooling_device *cdev)
  {
  	return cdev->ops->get_requested_power && cdev->ops->state2power &&
  		cdev->ops->power2state;
  }
  
  int power_actor_get_max_power(struct thermal_cooling_device *cdev,
ecd1d2a3e   zhuguangqing   thermal: cooling:...
61
  			      u32 *max_power);
33a88af10   Daniel Lezcano   thermal: Move int...
62
  int power_actor_get_min_power(struct thermal_cooling_device *cdev,
ecd1d2a3e   zhuguangqing   thermal: cooling:...
63
  			      u32 *min_power);
33a88af10   Daniel Lezcano   thermal: Move int...
64
65
  int power_actor_set_power(struct thermal_cooling_device *cdev,
  			  struct thermal_instance *ti, u32 power);
2e7700dc3   Daniel Lezcano   thermal: Move tri...
66
67
68
69
70
71
72
73
74
75
76
77
78
  /**
   * struct thermal_trip - representation of a point in temperature domain
   * @np: pointer to struct device_node that this trip point was created from
   * @temperature: temperature value in miliCelsius
   * @hysteresis: relative hysteresis in miliCelsius
   * @type: trip point type
   */
  struct thermal_trip {
  	struct device_node *np;
  	int temperature;
  	int hysteresis;
  	enum thermal_trip_type type;
  };
33a88af10   Daniel Lezcano   thermal: Move int...
79

f0129c231   Daniel Lezcano   thermal: Move get...
80
  int get_tz_trend(struct thermal_zone_device *tz, int trip);
06f1041f5   Daniel Lezcano   thermal: Move get...
81
82
83
84
  struct thermal_instance *
  get_thermal_instance(struct thermal_zone_device *tz,
  		     struct thermal_cooling_device *cdev,
  		     int trip);
71350db43   Durgadoss R   Thermal: Move the...
85
86
87
88
89
90
91
92
93
94
95
  /*
   * 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;
bb431ba26   Zhang Rui   Thermal: initiali...
96
  	bool initialized;
71350db43   Durgadoss R   Thermal: Move the...
97
98
99
100
101
  	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;
db9165131   Javi Merino   thermal: export w...
102
103
  	char weight_attr_name[THERMAL_NAME_LENGTH];
  	struct device_attribute weight_attr;
71350db43   Durgadoss R   Thermal: Move the...
104
105
  	struct list_head tz_node; /* node in tz->thermal_instances */
  	struct list_head cdev_node; /* node in cdev->thermal_instances */
6cd9e9f62   Kapileshwar Singh   thermal: of: fix ...
106
  	unsigned int weight; /* The weight of the cooling device */
71350db43   Durgadoss R   Thermal: Move the...
107
  };
ba78da443   Eduardo Valentin   thermal: core: mo...
108
109
  #define to_thermal_zone(_dev) \
  	container_of(_dev, struct thermal_zone_device, device)
99ea2eff9   Eduardo Valentin   thermal: core: mo...
110
111
  #define to_cooling_device(_dev)	\
  	container_of(_dev, struct thermal_cooling_device, device)
80a26a5c2   Zhang Rui   Thermal: build th...
112
113
  int thermal_register_governor(struct thermal_governor *);
  void thermal_unregister_governor(struct thermal_governor *);
3d0055d2b   Eduardo Valentin   thermal: core: sp...
114
115
116
117
  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);
6b885202d   Eduardo Valentin   thermal: core: sp...
118
  int thermal_zone_device_set_policy(struct thermal_zone_device *, char *);
97d2423bd   Eduardo Valentin   thermal: core: sp...
119
  int thermal_build_list_of_policies(char *buf);
80a26a5c2   Zhang Rui   Thermal: build th...
120

bceb5646a   Daniel Lezcano   thermal: core: Ma...
121
122
  /* Helpers */
  void thermal_zone_set_trips(struct thermal_zone_device *tz);
a369ee88f   Eduardo Valentin   thermal: core: mo...
123
124
  /* sysfs I/F */
  int thermal_zone_create_device_groups(struct thermal_zone_device *, int);
32fa5ba31   Christophe Jaillet   thermal: core: Ad...
125
  void thermal_zone_destroy_device_groups(struct thermal_zone_device *);
45cf2ec99   Eduardo Valentin   thermal: core: mo...
126
  void thermal_cooling_device_setup_sysfs(struct thermal_cooling_device *);
8ea229511   Viresh Kumar   thermal: Add cool...
127
  void thermal_cooling_device_destroy_sysfs(struct thermal_cooling_device *cdev);
45cf2ec99   Eduardo Valentin   thermal: core: mo...
128
  /* used only at binding time */
33e678d47   Viresh Kumar   thermal: Shorten ...
129
130
131
132
  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);
a369ee88f   Eduardo Valentin   thermal: core: mo...
133

8ea229511   Viresh Kumar   thermal: Add cool...
134
135
136
137
138
139
140
141
  #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 */
4e5e4705b   Eduardo Valentin   thermal: introduc...
142
143
144
  /* device tree support */
  #ifdef CONFIG_THERMAL_OF
  int of_parse_thermal_zones(void);
08dab66ec   Lukasz Majewski   thermal: of: Exte...
145
  int of_thermal_get_ntrips(struct thermal_zone_device *);
a9bf2cc49   Lukasz Majewski   thermal: of: Exte...
146
  bool of_thermal_is_trip_valid(struct thermal_zone_device *, int);
ebc3193ae   Geert Uytterhoeven   thermal: of: Remo...
147
  const struct thermal_trip *
ce8be7785   Lukasz Majewski   thermal: of: Exte...
148
  of_thermal_get_trip_points(struct thermal_zone_device *);
4e5e4705b   Eduardo Valentin   thermal: introduc...
149
150
  #else
  static inline int of_parse_thermal_zones(void) { return 0; }
08dab66ec   Lukasz Majewski   thermal: of: Exte...
151
152
153
154
  static inline int of_thermal_get_ntrips(struct thermal_zone_device *tz)
  {
  	return 0;
  }
a9bf2cc49   Lukasz Majewski   thermal: of: Exte...
155
156
157
  static inline bool of_thermal_is_trip_valid(struct thermal_zone_device *tz,
  					    int trip)
  {
ce1d94919   Joe Perches   thermal: Use bool...
158
  	return false;
a9bf2cc49   Lukasz Majewski   thermal: of: Exte...
159
  }
ebc3193ae   Geert Uytterhoeven   thermal: of: Remo...
160
  static inline const struct thermal_trip *
ce8be7785   Lukasz Majewski   thermal: of: Exte...
161
162
163
164
  of_thermal_get_trip_points(struct thermal_zone_device *tz)
  {
  	return NULL;
  }
4e5e4705b   Eduardo Valentin   thermal: introduc...
165
  #endif
71350db43   Durgadoss R   Thermal: Move the...
166
  #endif /* __THERMAL_CORE_H__ */