162306a36Sopenharmony_ci===================================
262306a36Sopenharmony_ciGeneric Thermal Sysfs driver How To
362306a36Sopenharmony_ci===================================
462306a36Sopenharmony_ci
562306a36Sopenharmony_ciWritten by Sujith Thomas <sujith.thomas@intel.com>, Zhang Rui <rui.zhang@intel.com>
662306a36Sopenharmony_ci
762306a36Sopenharmony_ciUpdated: 2 January 2008
862306a36Sopenharmony_ci
962306a36Sopenharmony_ciCopyright (c)  2008 Intel Corporation
1062306a36Sopenharmony_ci
1162306a36Sopenharmony_ci
1262306a36Sopenharmony_ci0. Introduction
1362306a36Sopenharmony_ci===============
1462306a36Sopenharmony_ci
1562306a36Sopenharmony_ciThe generic thermal sysfs provides a set of interfaces for thermal zone
1662306a36Sopenharmony_cidevices (sensors) and thermal cooling devices (fan, processor...) to register
1762306a36Sopenharmony_ciwith the thermal management solution and to be a part of it.
1862306a36Sopenharmony_ci
1962306a36Sopenharmony_ciThis how-to focuses on enabling new thermal zone and cooling devices to
2062306a36Sopenharmony_ciparticipate in thermal management.
2162306a36Sopenharmony_ciThis solution is platform independent and any type of thermal zone devices
2262306a36Sopenharmony_ciand cooling devices should be able to make use of the infrastructure.
2362306a36Sopenharmony_ci
2462306a36Sopenharmony_ciThe main task of the thermal sysfs driver is to expose thermal zone attributes
2562306a36Sopenharmony_cias well as cooling device attributes to the user space.
2662306a36Sopenharmony_ciAn intelligent thermal management application can make decisions based on
2762306a36Sopenharmony_ciinputs from thermal zone attributes (the current temperature and trip point
2862306a36Sopenharmony_citemperature) and throttle appropriate devices.
2962306a36Sopenharmony_ci
3062306a36Sopenharmony_ci- `[0-*]`	denotes any positive number starting from 0
3162306a36Sopenharmony_ci- `[1-*]`	denotes any positive number starting from 1
3262306a36Sopenharmony_ci
3362306a36Sopenharmony_ci1. thermal sysfs driver interface functions
3462306a36Sopenharmony_ci===========================================
3562306a36Sopenharmony_ci
3662306a36Sopenharmony_ci1.1 thermal zone device interface
3762306a36Sopenharmony_ci---------------------------------
3862306a36Sopenharmony_ci
3962306a36Sopenharmony_ci    ::
4062306a36Sopenharmony_ci
4162306a36Sopenharmony_ci	struct thermal_zone_device
4262306a36Sopenharmony_ci	*thermal_zone_device_register(char *type,
4362306a36Sopenharmony_ci				      int trips, int mask, void *devdata,
4462306a36Sopenharmony_ci				      struct thermal_zone_device_ops *ops,
4562306a36Sopenharmony_ci				      const struct thermal_zone_params *tzp,
4662306a36Sopenharmony_ci				      int passive_delay, int polling_delay))
4762306a36Sopenharmony_ci
4862306a36Sopenharmony_ci    This interface function adds a new thermal zone device (sensor) to
4962306a36Sopenharmony_ci    /sys/class/thermal folder as `thermal_zone[0-*]`. It tries to bind all the
5062306a36Sopenharmony_ci    thermal cooling devices registered at the same time.
5162306a36Sopenharmony_ci
5262306a36Sopenharmony_ci    type:
5362306a36Sopenharmony_ci	the thermal zone type.
5462306a36Sopenharmony_ci    trips:
5562306a36Sopenharmony_ci	the total number of trip points this thermal zone supports.
5662306a36Sopenharmony_ci    mask:
5762306a36Sopenharmony_ci	Bit string: If 'n'th bit is set, then trip point 'n' is writable.
5862306a36Sopenharmony_ci    devdata:
5962306a36Sopenharmony_ci	device private data
6062306a36Sopenharmony_ci    ops:
6162306a36Sopenharmony_ci	thermal zone device call-backs.
6262306a36Sopenharmony_ci
6362306a36Sopenharmony_ci	.bind:
6462306a36Sopenharmony_ci		bind the thermal zone device with a thermal cooling device.
6562306a36Sopenharmony_ci	.unbind:
6662306a36Sopenharmony_ci		unbind the thermal zone device with a thermal cooling device.
6762306a36Sopenharmony_ci	.get_temp:
6862306a36Sopenharmony_ci		get the current temperature of the thermal zone.
6962306a36Sopenharmony_ci	.set_trips:
7062306a36Sopenharmony_ci		    set the trip points window. Whenever the current temperature
7162306a36Sopenharmony_ci		    is updated, the trip points immediately below and above the
7262306a36Sopenharmony_ci		    current temperature are found.
7362306a36Sopenharmony_ci	.get_mode:
7462306a36Sopenharmony_ci		   get the current mode (enabled/disabled) of the thermal zone.
7562306a36Sopenharmony_ci
7662306a36Sopenharmony_ci			- "enabled" means the kernel thermal management is
7762306a36Sopenharmony_ci			  enabled.
7862306a36Sopenharmony_ci			- "disabled" will prevent kernel thermal driver action
7962306a36Sopenharmony_ci			  upon trip points so that user applications can take
8062306a36Sopenharmony_ci			  charge of thermal management.
8162306a36Sopenharmony_ci	.set_mode:
8262306a36Sopenharmony_ci		set the mode (enabled/disabled) of the thermal zone.
8362306a36Sopenharmony_ci	.get_trip_type:
8462306a36Sopenharmony_ci		get the type of certain trip point.
8562306a36Sopenharmony_ci	.get_trip_temp:
8662306a36Sopenharmony_ci			get the temperature above which the certain trip point
8762306a36Sopenharmony_ci			will be fired.
8862306a36Sopenharmony_ci	.set_emul_temp:
8962306a36Sopenharmony_ci			set the emulation temperature which helps in debugging
9062306a36Sopenharmony_ci			different threshold temperature points.
9162306a36Sopenharmony_ci    tzp:
9262306a36Sopenharmony_ci	thermal zone platform parameters.
9362306a36Sopenharmony_ci    passive_delay:
9462306a36Sopenharmony_ci	number of milliseconds to wait between polls when
9562306a36Sopenharmony_ci	performing passive cooling.
9662306a36Sopenharmony_ci    polling_delay:
9762306a36Sopenharmony_ci	number of milliseconds to wait between polls when checking
9862306a36Sopenharmony_ci	whether trip points have been crossed (0 for interrupt driven systems).
9962306a36Sopenharmony_ci
10062306a36Sopenharmony_ci    ::
10162306a36Sopenharmony_ci
10262306a36Sopenharmony_ci	void thermal_zone_device_unregister(struct thermal_zone_device *tz)
10362306a36Sopenharmony_ci
10462306a36Sopenharmony_ci    This interface function removes the thermal zone device.
10562306a36Sopenharmony_ci    It deletes the corresponding entry from /sys/class/thermal folder and
10662306a36Sopenharmony_ci    unbinds all the thermal cooling devices it uses.
10762306a36Sopenharmony_ci
10862306a36Sopenharmony_ci	::
10962306a36Sopenharmony_ci
11062306a36Sopenharmony_ci	   struct thermal_zone_device
11162306a36Sopenharmony_ci	   *thermal_zone_of_sensor_register(struct device *dev, int sensor_id,
11262306a36Sopenharmony_ci				void *data,
11362306a36Sopenharmony_ci				const struct thermal_zone_of_device_ops *ops)
11462306a36Sopenharmony_ci
11562306a36Sopenharmony_ci	This interface adds a new sensor to a DT thermal zone.
11662306a36Sopenharmony_ci	This function will search the list of thermal zones described in
11762306a36Sopenharmony_ci	device tree and look for the zone that refer to the sensor device
11862306a36Sopenharmony_ci	pointed by dev->of_node as temperature providers. For the zone
11962306a36Sopenharmony_ci	pointing to the sensor node, the sensor will be added to the DT
12062306a36Sopenharmony_ci	thermal zone device.
12162306a36Sopenharmony_ci
12262306a36Sopenharmony_ci	The parameters for this interface are:
12362306a36Sopenharmony_ci
12462306a36Sopenharmony_ci	dev:
12562306a36Sopenharmony_ci			Device node of sensor containing valid node pointer in
12662306a36Sopenharmony_ci			dev->of_node.
12762306a36Sopenharmony_ci	sensor_id:
12862306a36Sopenharmony_ci			a sensor identifier, in case the sensor IP has more
12962306a36Sopenharmony_ci			than one sensors
13062306a36Sopenharmony_ci	data:
13162306a36Sopenharmony_ci			a private pointer (owned by the caller) that will be
13262306a36Sopenharmony_ci			passed back, when a temperature reading is needed.
13362306a36Sopenharmony_ci	ops:
13462306a36Sopenharmony_ci			`struct thermal_zone_of_device_ops *`.
13562306a36Sopenharmony_ci
13662306a36Sopenharmony_ci			==============  =======================================
13762306a36Sopenharmony_ci			get_temp	a pointer to a function that reads the
13862306a36Sopenharmony_ci					sensor temperature. This is mandatory
13962306a36Sopenharmony_ci					callback provided by sensor driver.
14062306a36Sopenharmony_ci			set_trips	a pointer to a function that sets a
14162306a36Sopenharmony_ci					temperature window. When this window is
14262306a36Sopenharmony_ci					left the driver must inform the thermal
14362306a36Sopenharmony_ci					core via thermal_zone_device_update.
14462306a36Sopenharmony_ci			get_trend 	a pointer to a function that reads the
14562306a36Sopenharmony_ci					sensor temperature trend.
14662306a36Sopenharmony_ci			set_emul_temp	a pointer to a function that sets
14762306a36Sopenharmony_ci					sensor emulated temperature.
14862306a36Sopenharmony_ci			==============  =======================================
14962306a36Sopenharmony_ci
15062306a36Sopenharmony_ci	The thermal zone temperature is provided by the get_temp() function
15162306a36Sopenharmony_ci	pointer of thermal_zone_of_device_ops. When called, it will
15262306a36Sopenharmony_ci	have the private pointer @data back.
15362306a36Sopenharmony_ci
15462306a36Sopenharmony_ci	It returns error pointer if fails otherwise valid thermal zone device
15562306a36Sopenharmony_ci	handle. Caller should check the return handle with IS_ERR() for finding
15662306a36Sopenharmony_ci	whether success or not.
15762306a36Sopenharmony_ci
15862306a36Sopenharmony_ci	::
15962306a36Sopenharmony_ci
16062306a36Sopenharmony_ci	    void thermal_zone_of_sensor_unregister(struct device *dev,
16162306a36Sopenharmony_ci						   struct thermal_zone_device *tzd)
16262306a36Sopenharmony_ci
16362306a36Sopenharmony_ci	This interface unregisters a sensor from a DT thermal zone which was
16462306a36Sopenharmony_ci	successfully added by interface thermal_zone_of_sensor_register().
16562306a36Sopenharmony_ci	This function removes the sensor callbacks and private data from the
16662306a36Sopenharmony_ci	thermal zone device registered with thermal_zone_of_sensor_register()
16762306a36Sopenharmony_ci	interface. It will also silent the zone by remove the .get_temp() and
16862306a36Sopenharmony_ci	get_trend() thermal zone device callbacks.
16962306a36Sopenharmony_ci
17062306a36Sopenharmony_ci	::
17162306a36Sopenharmony_ci
17262306a36Sopenharmony_ci	  struct thermal_zone_device
17362306a36Sopenharmony_ci	  *devm_thermal_zone_of_sensor_register(struct device *dev,
17462306a36Sopenharmony_ci				int sensor_id,
17562306a36Sopenharmony_ci				void *data,
17662306a36Sopenharmony_ci				const struct thermal_zone_of_device_ops *ops)
17762306a36Sopenharmony_ci
17862306a36Sopenharmony_ci	This interface is resource managed version of
17962306a36Sopenharmony_ci	thermal_zone_of_sensor_register().
18062306a36Sopenharmony_ci
18162306a36Sopenharmony_ci	All details of thermal_zone_of_sensor_register() described in
18262306a36Sopenharmony_ci	section 1.1.3 is applicable here.
18362306a36Sopenharmony_ci
18462306a36Sopenharmony_ci	The benefit of using this interface to register sensor is that it
18562306a36Sopenharmony_ci	is not require to explicitly call thermal_zone_of_sensor_unregister()
18662306a36Sopenharmony_ci	in error path or during driver unbinding as this is done by driver
18762306a36Sopenharmony_ci	resource manager.
18862306a36Sopenharmony_ci
18962306a36Sopenharmony_ci	::
19062306a36Sopenharmony_ci
19162306a36Sopenharmony_ci		void devm_thermal_zone_of_sensor_unregister(struct device *dev,
19262306a36Sopenharmony_ci						struct thermal_zone_device *tzd)
19362306a36Sopenharmony_ci
19462306a36Sopenharmony_ci	This interface is resource managed version of
19562306a36Sopenharmony_ci	thermal_zone_of_sensor_unregister().
19662306a36Sopenharmony_ci	All details of thermal_zone_of_sensor_unregister() described in
19762306a36Sopenharmony_ci	section 1.1.4 is applicable here.
19862306a36Sopenharmony_ci	Normally this function will not need to be called and the resource
19962306a36Sopenharmony_ci	management code will ensure that the resource is freed.
20062306a36Sopenharmony_ci
20162306a36Sopenharmony_ci	::
20262306a36Sopenharmony_ci
20362306a36Sopenharmony_ci		int thermal_zone_get_slope(struct thermal_zone_device *tz)
20462306a36Sopenharmony_ci
20562306a36Sopenharmony_ci	This interface is used to read the slope attribute value
20662306a36Sopenharmony_ci	for the thermal zone device, which might be useful for platform
20762306a36Sopenharmony_ci	drivers for temperature calculations.
20862306a36Sopenharmony_ci
20962306a36Sopenharmony_ci	::
21062306a36Sopenharmony_ci
21162306a36Sopenharmony_ci		int thermal_zone_get_offset(struct thermal_zone_device *tz)
21262306a36Sopenharmony_ci
21362306a36Sopenharmony_ci	This interface is used to read the offset attribute value
21462306a36Sopenharmony_ci	for the thermal zone device, which might be useful for platform
21562306a36Sopenharmony_ci	drivers for temperature calculations.
21662306a36Sopenharmony_ci
21762306a36Sopenharmony_ci1.2 thermal cooling device interface
21862306a36Sopenharmony_ci------------------------------------
21962306a36Sopenharmony_ci
22062306a36Sopenharmony_ci
22162306a36Sopenharmony_ci    ::
22262306a36Sopenharmony_ci
22362306a36Sopenharmony_ci	struct thermal_cooling_device
22462306a36Sopenharmony_ci	*thermal_cooling_device_register(char *name,
22562306a36Sopenharmony_ci			void *devdata, struct thermal_cooling_device_ops *)
22662306a36Sopenharmony_ci
22762306a36Sopenharmony_ci    This interface function adds a new thermal cooling device (fan/processor/...)
22862306a36Sopenharmony_ci    to /sys/class/thermal/ folder as `cooling_device[0-*]`. It tries to bind itself
22962306a36Sopenharmony_ci    to all the thermal zone devices registered at the same time.
23062306a36Sopenharmony_ci
23162306a36Sopenharmony_ci    name:
23262306a36Sopenharmony_ci	the cooling device name.
23362306a36Sopenharmony_ci    devdata:
23462306a36Sopenharmony_ci	device private data.
23562306a36Sopenharmony_ci    ops:
23662306a36Sopenharmony_ci	thermal cooling devices call-backs.
23762306a36Sopenharmony_ci
23862306a36Sopenharmony_ci	.get_max_state:
23962306a36Sopenharmony_ci		get the Maximum throttle state of the cooling device.
24062306a36Sopenharmony_ci	.get_cur_state:
24162306a36Sopenharmony_ci		get the Currently requested throttle state of the
24262306a36Sopenharmony_ci		cooling device.
24362306a36Sopenharmony_ci	.set_cur_state:
24462306a36Sopenharmony_ci		set the Current throttle state of the cooling device.
24562306a36Sopenharmony_ci
24662306a36Sopenharmony_ci    ::
24762306a36Sopenharmony_ci
24862306a36Sopenharmony_ci	void thermal_cooling_device_unregister(struct thermal_cooling_device *cdev)
24962306a36Sopenharmony_ci
25062306a36Sopenharmony_ci    This interface function removes the thermal cooling device.
25162306a36Sopenharmony_ci    It deletes the corresponding entry from /sys/class/thermal folder and
25262306a36Sopenharmony_ci    unbinds itself from all the thermal zone devices using it.
25362306a36Sopenharmony_ci
25462306a36Sopenharmony_ci1.3 interface for binding a thermal zone device with a thermal cooling device
25562306a36Sopenharmony_ci-----------------------------------------------------------------------------
25662306a36Sopenharmony_ci
25762306a36Sopenharmony_ci    ::
25862306a36Sopenharmony_ci
25962306a36Sopenharmony_ci	int thermal_zone_bind_cooling_device(struct thermal_zone_device *tz,
26062306a36Sopenharmony_ci		int trip, struct thermal_cooling_device *cdev,
26162306a36Sopenharmony_ci		unsigned long upper, unsigned long lower, unsigned int weight);
26262306a36Sopenharmony_ci
26362306a36Sopenharmony_ci    This interface function binds a thermal cooling device to a particular trip
26462306a36Sopenharmony_ci    point of a thermal zone device.
26562306a36Sopenharmony_ci
26662306a36Sopenharmony_ci    This function is usually called in the thermal zone device .bind callback.
26762306a36Sopenharmony_ci
26862306a36Sopenharmony_ci    tz:
26962306a36Sopenharmony_ci	  the thermal zone device
27062306a36Sopenharmony_ci    cdev:
27162306a36Sopenharmony_ci	  thermal cooling device
27262306a36Sopenharmony_ci    trip:
27362306a36Sopenharmony_ci	  indicates which trip point in this thermal zone the cooling device
27462306a36Sopenharmony_ci	  is associated with.
27562306a36Sopenharmony_ci    upper:
27662306a36Sopenharmony_ci	  the Maximum cooling state for this trip point.
27762306a36Sopenharmony_ci	  THERMAL_NO_LIMIT means no upper limit,
27862306a36Sopenharmony_ci	  and the cooling device can be in max_state.
27962306a36Sopenharmony_ci    lower:
28062306a36Sopenharmony_ci	  the Minimum cooling state can be used for this trip point.
28162306a36Sopenharmony_ci	  THERMAL_NO_LIMIT means no lower limit,
28262306a36Sopenharmony_ci	  and the cooling device can be in cooling state 0.
28362306a36Sopenharmony_ci    weight:
28462306a36Sopenharmony_ci	  the influence of this cooling device in this thermal
28562306a36Sopenharmony_ci	  zone.  See 1.4.1 below for more information.
28662306a36Sopenharmony_ci
28762306a36Sopenharmony_ci    ::
28862306a36Sopenharmony_ci
28962306a36Sopenharmony_ci	int thermal_zone_unbind_cooling_device(struct thermal_zone_device *tz,
29062306a36Sopenharmony_ci				int trip, struct thermal_cooling_device *cdev);
29162306a36Sopenharmony_ci
29262306a36Sopenharmony_ci    This interface function unbinds a thermal cooling device from a particular
29362306a36Sopenharmony_ci    trip point of a thermal zone device. This function is usually called in
29462306a36Sopenharmony_ci    the thermal zone device .unbind callback.
29562306a36Sopenharmony_ci
29662306a36Sopenharmony_ci    tz:
29762306a36Sopenharmony_ci	the thermal zone device
29862306a36Sopenharmony_ci    cdev:
29962306a36Sopenharmony_ci	thermal cooling device
30062306a36Sopenharmony_ci    trip:
30162306a36Sopenharmony_ci	indicates which trip point in this thermal zone the cooling device
30262306a36Sopenharmony_ci	is associated with.
30362306a36Sopenharmony_ci
30462306a36Sopenharmony_ci1.4 Thermal Zone Parameters
30562306a36Sopenharmony_ci---------------------------
30662306a36Sopenharmony_ci
30762306a36Sopenharmony_ci    ::
30862306a36Sopenharmony_ci
30962306a36Sopenharmony_ci	struct thermal_zone_params
31062306a36Sopenharmony_ci
31162306a36Sopenharmony_ci    This structure defines the platform level parameters for a thermal zone.
31262306a36Sopenharmony_ci    This data, for each thermal zone should come from the platform layer.
31362306a36Sopenharmony_ci    This is an optional feature where some platforms can choose not to
31462306a36Sopenharmony_ci    provide this data.
31562306a36Sopenharmony_ci
31662306a36Sopenharmony_ci    .governor_name:
31762306a36Sopenharmony_ci	       Name of the thermal governor used for this zone
31862306a36Sopenharmony_ci    .no_hwmon:
31962306a36Sopenharmony_ci	       a boolean to indicate if the thermal to hwmon sysfs interface
32062306a36Sopenharmony_ci	       is required. when no_hwmon == false, a hwmon sysfs interface
32162306a36Sopenharmony_ci	       will be created. when no_hwmon == true, nothing will be done.
32262306a36Sopenharmony_ci	       In case the thermal_zone_params is NULL, the hwmon interface
32362306a36Sopenharmony_ci	       will be created (for backward compatibility).
32462306a36Sopenharmony_ci
32562306a36Sopenharmony_ci2. sysfs attributes structure
32662306a36Sopenharmony_ci=============================
32762306a36Sopenharmony_ci
32862306a36Sopenharmony_ci==	================
32962306a36Sopenharmony_ciRO	read only value
33062306a36Sopenharmony_ciWO	write only value
33162306a36Sopenharmony_ciRW	read/write value
33262306a36Sopenharmony_ci==	================
33362306a36Sopenharmony_ci
33462306a36Sopenharmony_ciThermal sysfs attributes will be represented under /sys/class/thermal.
33562306a36Sopenharmony_ciHwmon sysfs I/F extension is also available under /sys/class/hwmon
33662306a36Sopenharmony_ciif hwmon is compiled in or built as a module.
33762306a36Sopenharmony_ci
33862306a36Sopenharmony_ciThermal zone device sys I/F, created once it's registered::
33962306a36Sopenharmony_ci
34062306a36Sopenharmony_ci  /sys/class/thermal/thermal_zone[0-*]:
34162306a36Sopenharmony_ci    |---type:			Type of the thermal zone
34262306a36Sopenharmony_ci    |---temp:			Current temperature
34362306a36Sopenharmony_ci    |---mode:			Working mode of the thermal zone
34462306a36Sopenharmony_ci    |---policy:			Thermal governor used for this zone
34562306a36Sopenharmony_ci    |---available_policies:	Available thermal governors for this zone
34662306a36Sopenharmony_ci    |---trip_point_[0-*]_temp:	Trip point temperature
34762306a36Sopenharmony_ci    |---trip_point_[0-*]_type:	Trip point type
34862306a36Sopenharmony_ci    |---trip_point_[0-*]_hyst:	Hysteresis value for this trip point
34962306a36Sopenharmony_ci    |---emul_temp:		Emulated temperature set node
35062306a36Sopenharmony_ci    |---sustainable_power:      Sustainable dissipatable power
35162306a36Sopenharmony_ci    |---k_po:                   Proportional term during temperature overshoot
35262306a36Sopenharmony_ci    |---k_pu:                   Proportional term during temperature undershoot
35362306a36Sopenharmony_ci    |---k_i:                    PID's integral term in the power allocator gov
35462306a36Sopenharmony_ci    |---k_d:                    PID's derivative term in the power allocator
35562306a36Sopenharmony_ci    |---integral_cutoff:        Offset above which errors are accumulated
35662306a36Sopenharmony_ci    |---slope:                  Slope constant applied as linear extrapolation
35762306a36Sopenharmony_ci    |---offset:                 Offset constant applied as linear extrapolation
35862306a36Sopenharmony_ci
35962306a36Sopenharmony_ciThermal cooling device sys I/F, created once it's registered::
36062306a36Sopenharmony_ci
36162306a36Sopenharmony_ci  /sys/class/thermal/cooling_device[0-*]:
36262306a36Sopenharmony_ci    |---type:			Type of the cooling device(processor/fan/...)
36362306a36Sopenharmony_ci    |---max_state:		Maximum cooling state of the cooling device
36462306a36Sopenharmony_ci    |---cur_state:		Current cooling state of the cooling device
36562306a36Sopenharmony_ci    |---stats:			Directory containing cooling device's statistics
36662306a36Sopenharmony_ci    |---stats/reset:		Writing any value resets the statistics
36762306a36Sopenharmony_ci    |---stats/time_in_state_ms:	Time (msec) spent in various cooling states
36862306a36Sopenharmony_ci    |---stats/total_trans:	Total number of times cooling state is changed
36962306a36Sopenharmony_ci    |---stats/trans_table:	Cooling state transition table
37062306a36Sopenharmony_ci
37162306a36Sopenharmony_ci
37262306a36Sopenharmony_ciThen next two dynamic attributes are created/removed in pairs. They represent
37362306a36Sopenharmony_cithe relationship between a thermal zone and its associated cooling device.
37462306a36Sopenharmony_ciThey are created/removed for each successful execution of
37562306a36Sopenharmony_cithermal_zone_bind_cooling_device/thermal_zone_unbind_cooling_device.
37662306a36Sopenharmony_ci
37762306a36Sopenharmony_ci::
37862306a36Sopenharmony_ci
37962306a36Sopenharmony_ci  /sys/class/thermal/thermal_zone[0-*]:
38062306a36Sopenharmony_ci    |---cdev[0-*]:		[0-*]th cooling device in current thermal zone
38162306a36Sopenharmony_ci    |---cdev[0-*]_trip_point:	Trip point that cdev[0-*] is associated with
38262306a36Sopenharmony_ci    |---cdev[0-*]_weight:       Influence of the cooling device in
38362306a36Sopenharmony_ci				this thermal zone
38462306a36Sopenharmony_ci
38562306a36Sopenharmony_ciBesides the thermal zone device sysfs I/F and cooling device sysfs I/F,
38662306a36Sopenharmony_cithe generic thermal driver also creates a hwmon sysfs I/F for each _type_
38762306a36Sopenharmony_ciof thermal zone device. E.g. the generic thermal driver registers one hwmon
38862306a36Sopenharmony_ciclass device and build the associated hwmon sysfs I/F for all the registered
38962306a36Sopenharmony_ciACPI thermal zones.
39062306a36Sopenharmony_ci
39162306a36Sopenharmony_ciPlease read Documentation/ABI/testing/sysfs-class-thermal for thermal
39262306a36Sopenharmony_cizone and cooling device attribute details.
39362306a36Sopenharmony_ci
39462306a36Sopenharmony_ci::
39562306a36Sopenharmony_ci
39662306a36Sopenharmony_ci  /sys/class/hwmon/hwmon[0-*]:
39762306a36Sopenharmony_ci    |---name:			The type of the thermal zone devices
39862306a36Sopenharmony_ci    |---temp[1-*]_input:	The current temperature of thermal zone [1-*]
39962306a36Sopenharmony_ci    |---temp[1-*]_critical:	The critical trip point of thermal zone [1-*]
40062306a36Sopenharmony_ci
40162306a36Sopenharmony_ciPlease read Documentation/hwmon/sysfs-interface.rst for additional information.
40262306a36Sopenharmony_ci
40362306a36Sopenharmony_ci3. A simple implementation
40462306a36Sopenharmony_ci==========================
40562306a36Sopenharmony_ci
40662306a36Sopenharmony_ciACPI thermal zone may support multiple trip points like critical, hot,
40762306a36Sopenharmony_cipassive, active. If an ACPI thermal zone supports critical, passive,
40862306a36Sopenharmony_ciactive[0] and active[1] at the same time, it may register itself as a
40962306a36Sopenharmony_cithermal_zone_device (thermal_zone1) with 4 trip points in all.
41062306a36Sopenharmony_ciIt has one processor and one fan, which are both registered as
41162306a36Sopenharmony_cithermal_cooling_device. Both are considered to have the same
41262306a36Sopenharmony_cieffectiveness in cooling the thermal zone.
41362306a36Sopenharmony_ci
41462306a36Sopenharmony_ciIf the processor is listed in _PSL method, and the fan is listed in _AL0
41562306a36Sopenharmony_cimethod, the sys I/F structure will be built like this::
41662306a36Sopenharmony_ci
41762306a36Sopenharmony_ci /sys/class/thermal:
41862306a36Sopenharmony_ci  |thermal_zone1:
41962306a36Sopenharmony_ci    |---type:			acpitz
42062306a36Sopenharmony_ci    |---temp:			37000
42162306a36Sopenharmony_ci    |---mode:			enabled
42262306a36Sopenharmony_ci    |---policy:			step_wise
42362306a36Sopenharmony_ci    |---available_policies:	step_wise fair_share
42462306a36Sopenharmony_ci    |---trip_point_0_temp:	100000
42562306a36Sopenharmony_ci    |---trip_point_0_type:	critical
42662306a36Sopenharmony_ci    |---trip_point_1_temp:	80000
42762306a36Sopenharmony_ci    |---trip_point_1_type:	passive
42862306a36Sopenharmony_ci    |---trip_point_2_temp:	70000
42962306a36Sopenharmony_ci    |---trip_point_2_type:	active0
43062306a36Sopenharmony_ci    |---trip_point_3_temp:	60000
43162306a36Sopenharmony_ci    |---trip_point_3_type:	active1
43262306a36Sopenharmony_ci    |---cdev0:			--->/sys/class/thermal/cooling_device0
43362306a36Sopenharmony_ci    |---cdev0_trip_point:	1	/* cdev0 can be used for passive */
43462306a36Sopenharmony_ci    |---cdev0_weight:           1024
43562306a36Sopenharmony_ci    |---cdev1:			--->/sys/class/thermal/cooling_device3
43662306a36Sopenharmony_ci    |---cdev1_trip_point:	2	/* cdev1 can be used for active[0]*/
43762306a36Sopenharmony_ci    |---cdev1_weight:           1024
43862306a36Sopenharmony_ci
43962306a36Sopenharmony_ci  |cooling_device0:
44062306a36Sopenharmony_ci    |---type:			Processor
44162306a36Sopenharmony_ci    |---max_state:		8
44262306a36Sopenharmony_ci    |---cur_state:		0
44362306a36Sopenharmony_ci
44462306a36Sopenharmony_ci  |cooling_device3:
44562306a36Sopenharmony_ci    |---type:			Fan
44662306a36Sopenharmony_ci    |---max_state:		2
44762306a36Sopenharmony_ci    |---cur_state:		0
44862306a36Sopenharmony_ci
44962306a36Sopenharmony_ci /sys/class/hwmon:
45062306a36Sopenharmony_ci  |hwmon0:
45162306a36Sopenharmony_ci    |---name:			acpitz
45262306a36Sopenharmony_ci    |---temp1_input:		37000
45362306a36Sopenharmony_ci    |---temp1_crit:		100000
45462306a36Sopenharmony_ci
45562306a36Sopenharmony_ci4. Export Symbol APIs
45662306a36Sopenharmony_ci=====================
45762306a36Sopenharmony_ci
45862306a36Sopenharmony_ci4.1. get_tz_trend
45962306a36Sopenharmony_ci-----------------
46062306a36Sopenharmony_ci
46162306a36Sopenharmony_ciThis function returns the trend of a thermal zone, i.e the rate of change
46262306a36Sopenharmony_ciof temperature of the thermal zone. Ideally, the thermal sensor drivers
46362306a36Sopenharmony_ciare supposed to implement the callback. If they don't, the thermal
46462306a36Sopenharmony_ciframework calculated the trend by comparing the previous and the current
46562306a36Sopenharmony_citemperature values.
46662306a36Sopenharmony_ci
46762306a36Sopenharmony_ci4.2. get_thermal_instance
46862306a36Sopenharmony_ci-------------------------
46962306a36Sopenharmony_ci
47062306a36Sopenharmony_ciThis function returns the thermal_instance corresponding to a given
47162306a36Sopenharmony_ci{thermal_zone, cooling_device, trip_point} combination. Returns NULL
47262306a36Sopenharmony_ciif such an instance does not exist.
47362306a36Sopenharmony_ci
47462306a36Sopenharmony_ci4.3. thermal_cdev_update
47562306a36Sopenharmony_ci------------------------
47662306a36Sopenharmony_ci
47762306a36Sopenharmony_ciThis function serves as an arbitrator to set the state of a cooling
47862306a36Sopenharmony_cidevice. It sets the cooling device to the deepest cooling state if
47962306a36Sopenharmony_cipossible.
48062306a36Sopenharmony_ci
48162306a36Sopenharmony_ci5. thermal_emergency_poweroff
48262306a36Sopenharmony_ci=============================
48362306a36Sopenharmony_ci
48462306a36Sopenharmony_ciOn an event of critical trip temperature crossing the thermal framework
48562306a36Sopenharmony_cishuts down the system by calling hw_protection_shutdown(). The
48662306a36Sopenharmony_cihw_protection_shutdown() first attempts to perform an orderly shutdown
48762306a36Sopenharmony_cibut accepts a delay after which it proceeds doing a forced power-off
48862306a36Sopenharmony_cior as last resort an emergency_restart.
48962306a36Sopenharmony_ci
49062306a36Sopenharmony_ciThe delay should be carefully profiled so as to give adequate time for
49162306a36Sopenharmony_ciorderly poweroff.
49262306a36Sopenharmony_ci
49362306a36Sopenharmony_ciIf the delay is set to 0 emergency poweroff will not be supported. So a
49462306a36Sopenharmony_cicarefully profiled non-zero positive value is a must for emergency
49562306a36Sopenharmony_cipoweroff to be triggered.
496