Commit 37702015 authored by Rafael J. Wysocki's avatar Rafael J. Wysocki
Browse files

Merge branch 'thermal-core'

Merge thermal core changes for v6.7 depended on by subsequent ACPI
thermal driver changes:

 - Drop trips_disabled bitmask that is not really useful any more from
   the thermal zone structure.

 - Drop a reduntant NULL pointer check from for_each_thermal_trip().

 - Redefine struct thermal_instance to hold a thernal trip pointer
   instead of a trip index.

 - Add helpers for binding and unbinding cooling devices to and from
   trip points, reslectively, that take trip pointers as arguments.

* thermal-core:
  thermal: core: Allow trip pointers to be used for cooling device binding
  thermal: core: Store trip pointer in struct thermal_instance
  thermal: trip: Drop redundant trips check from for_each_thermal_trip()
  thermal: core: Drop trips_disabled bitmask
parents 2713b83c d069ed6b
Loading
Loading
Loading
Loading
+8 −15
Original line number Diff line number Diff line
@@ -13,28 +13,21 @@

#include "thermal_core.h"

static int thermal_zone_trip_update(struct thermal_zone_device *tz, int trip_id)
static int thermal_zone_trip_update(struct thermal_zone_device *tz, int trip_index)
{
	struct thermal_trip trip;
	const struct thermal_trip *trip = &tz->trips[trip_index];
	struct thermal_instance *instance;
	int ret;

	ret = __thermal_zone_get_trip(tz, trip_id, &trip);
	if (ret) {
		pr_warn_once("Failed to retrieve trip point %d\n", trip_id);
		return ret;
	}

	if (!trip.hysteresis)
	if (!trip->hysteresis)
		dev_info_once(&tz->device,
			      "Zero hysteresis value for thermal zone %s\n", tz->type);

	dev_dbg(&tz->device, "Trip%d[temp=%d]:temp=%d:hyst=%d\n",
				trip_id, trip.temperature, tz->temperature,
				trip.hysteresis);
				trip_index, trip->temperature, tz->temperature,
				trip->hysteresis);

	list_for_each_entry(instance, &tz->thermal_instances, tz_node) {
		if (instance->trip != trip_id)
		if (instance->trip != trip)
			continue;

		/* in case fan is in initial state, switch the fan off */
@@ -52,10 +45,10 @@ static int thermal_zone_trip_update(struct thermal_zone_device *tz, int trip_id)
		 * enable fan when temperature exceeds trip_temp and disable
		 * the fan in case it falls below trip_temp minus hysteresis
		 */
		if (instance->target == 0 && tz->temperature >= trip.temperature)
		if (instance->target == 0 && tz->temperature >= trip->temperature)
			instance->target = 1;
		else if (instance->target == 1 &&
			 tz->temperature <= trip.temperature - trip.hysteresis)
			 tz->temperature <= trip->temperature - trip->hysteresis)
			instance->target = 0;

		dev_dbg(&instance->cdev->device, "target=%d\n",
+3 −2
Original line number Diff line number Diff line
@@ -49,7 +49,7 @@ static long get_target_state(struct thermal_zone_device *tz,
/**
 * fair_share_throttle - throttles devices associated with the given zone
 * @tz: thermal_zone_device
 * @trip: trip point index
 * @trip_index: trip point index
 *
 * Throttling Logic: This uses three parameters to calculate the new
 * throttle state of the cooling devices associated with the given zone.
@@ -65,8 +65,9 @@ static long get_target_state(struct thermal_zone_device *tz,
 *	(Heavily assumes the trip points are in ascending order)
 * new_state of cooling device = P3 * P2 * P1
 */
static int fair_share_throttle(struct thermal_zone_device *tz, int trip)
static int fair_share_throttle(struct thermal_zone_device *tz, int trip_index)
{
	const struct thermal_trip *trip = &tz->trips[trip_index];
	struct thermal_instance *instance;
	int total_weight = 0;
	int total_instance = 0;
+8 −3
Original line number Diff line number Diff line
@@ -90,12 +90,14 @@ static u32 estimate_sustainable_power(struct thermal_zone_device *tz)
	u32 sustainable_power = 0;
	struct thermal_instance *instance;
	struct power_allocator_params *params = tz->governor_data;
	const struct thermal_trip *trip_max_desired_temperature =
			&tz->trips[params->trip_max_desired_temperature];

	list_for_each_entry(instance, &tz->thermal_instances, tz_node) {
		struct thermal_cooling_device *cdev = instance->cdev;
		u32 min_power;

		if (instance->trip != params->trip_max_desired_temperature)
		if (instance->trip != trip_max_desired_temperature)
			continue;

		if (!cdev_is_power_actor(cdev))
@@ -383,12 +385,13 @@ static int allocate_power(struct thermal_zone_device *tz,
{
	struct thermal_instance *instance;
	struct power_allocator_params *params = tz->governor_data;
	const struct thermal_trip *trip_max_desired_temperature =
			&tz->trips[params->trip_max_desired_temperature];
	u32 *req_power, *max_power, *granted_power, *extra_actor_power;
	u32 *weighted_req_power;
	u32 total_req_power, max_allocatable_power, total_weighted_req_power;
	u32 total_granted_power, power_range;
	int i, num_actors, total_weight, ret = 0;
	int trip_max_desired_temperature = params->trip_max_desired_temperature;

	num_actors = 0;
	total_weight = 0;
@@ -564,12 +567,14 @@ static void allow_maximum_power(struct thermal_zone_device *tz, bool update)
{
	struct thermal_instance *instance;
	struct power_allocator_params *params = tz->governor_data;
	const struct thermal_trip *trip_max_desired_temperature =
			&tz->trips[params->trip_max_desired_temperature];
	u32 req_power;

	list_for_each_entry(instance, &tz->thermal_instances, tz_node) {
		struct thermal_cooling_device *cdev = instance->cdev;

		if ((instance->trip != params->trip_max_desired_temperature) ||
		if ((instance->trip != trip_max_desired_temperature) ||
		    (!cdev_is_power_actor(instance->cdev)))
			continue;

+7 −9
Original line number Diff line number Diff line
@@ -81,26 +81,24 @@ static void update_passive_instance(struct thermal_zone_device *tz,

static void thermal_zone_trip_update(struct thermal_zone_device *tz, int trip_id)
{
	const struct thermal_trip *trip = &tz->trips[trip_id];
	enum thermal_trend trend;
	struct thermal_instance *instance;
	struct thermal_trip trip;
	bool throttle = false;
	int old_target;

	__thermal_zone_get_trip(tz, trip_id, &trip);

	trend = get_tz_trend(tz, trip_id);

	if (tz->temperature >= trip.temperature) {
	if (tz->temperature >= trip->temperature) {
		throttle = true;
		trace_thermal_zone_trip(tz, trip_id, trip.type);
		trace_thermal_zone_trip(tz, trip_id, trip->type);
	}

	dev_dbg(&tz->device, "Trip%d[type=%d,temp=%d]:trend=%d,throttle=%d\n",
				trip_id, trip.type, trip.temperature, trend, throttle);
		trip_id, trip->type, trip->temperature, trend, throttle);

	list_for_each_entry(instance, &tz->thermal_instances, tz_node) {
		if (instance->trip != trip_id)
		if (instance->trip != trip)
			continue;

		old_target = instance->target;
@@ -114,11 +112,11 @@ static void thermal_zone_trip_update(struct thermal_zone_device *tz, int trip_id
		/* Activate a passive thermal instance */
		if (old_target == THERMAL_NO_TARGET &&
			instance->target != THERMAL_NO_TARGET)
			update_passive_instance(tz, trip.type, 1);
			update_passive_instance(tz, trip->type, 1);
		/* Deactivate a passive thermal instance */
		else if (old_target != THERMAL_NO_TARGET &&
			instance->target == THERMAL_NO_TARGET)
			update_passive_instance(tz, trip.type, -1);
			update_passive_instance(tz, trip->type, -1);

		instance->initialized = true;
		mutex_lock(&instance->cdev->lock);
+34 −28
Original line number Diff line number Diff line
@@ -347,10 +347,6 @@ static void handle_thermal_trip(struct thermal_zone_device *tz, int trip_id)
{
	struct thermal_trip trip;

	/* Ignore disabled trip points */
	if (test_bit(trip_id, &tz->trips_disabled))
		return;

	__thermal_zone_get_trip(tz, trip_id, &trip);

	if (trip.temperature == THERMAL_TEMP_INVALID)
@@ -604,10 +600,9 @@ struct thermal_zone_device *thermal_zone_get_by_id(int id)
 */

/**
 * thermal_zone_bind_cooling_device() - bind a cooling device to a thermal zone
 * thermal_bind_cdev_to_trip - bind a cooling device to a thermal zone
 * @tz:		pointer to struct thermal_zone_device
 * @trip:	indicates which trip point the cooling devices is
 *		associated with in this thermal zone.
 * @trip:	trip point the cooling devices is associated with in this zone.
 * @cdev:	pointer to struct thermal_cooling_device
 * @upper:	the Maximum cooling state for this trip point.
 *		THERMAL_NO_LIMIT means no upper limit,
@@ -625,8 +620,8 @@ struct thermal_zone_device *thermal_zone_get_by_id(int id)
 *
 * Return: 0 on success, the proper error value otherwise.
 */
int thermal_zone_bind_cooling_device(struct thermal_zone_device *tz,
				     int trip,
int thermal_bind_cdev_to_trip(struct thermal_zone_device *tz,
				     const struct thermal_trip *trip,
				     struct thermal_cooling_device *cdev,
				     unsigned long upper, unsigned long lower,
				     unsigned int weight)
@@ -638,9 +633,6 @@ int thermal_zone_bind_cooling_device(struct thermal_zone_device *tz,
	bool upper_no_limit;
	int result;

	if (trip >= tz->num_trips || trip < 0)
		return -EINVAL;

	list_for_each_entry(pos1, &thermal_tz_list, node) {
		if (pos1 == tz)
			break;
@@ -737,14 +729,26 @@ int thermal_zone_bind_cooling_device(struct thermal_zone_device *tz,
	kfree(dev);
	return result;
}
EXPORT_SYMBOL_GPL(thermal_bind_cdev_to_trip);

int thermal_zone_bind_cooling_device(struct thermal_zone_device *tz,
				     int trip_index,
				     struct thermal_cooling_device *cdev,
				     unsigned long upper, unsigned long lower,
				     unsigned int weight)
{
	if (trip_index < 0 || trip_index >= tz->num_trips)
		return -EINVAL;

	return thermal_bind_cdev_to_trip(tz, &tz->trips[trip_index], cdev,
					 upper, lower, weight);
}
EXPORT_SYMBOL_GPL(thermal_zone_bind_cooling_device);

/**
 * thermal_zone_unbind_cooling_device() - unbind a cooling device from a
 *					  thermal zone.
 * thermal_unbind_cdev_from_trip - unbind a cooling device from a thermal zone.
 * @tz:		pointer to a struct thermal_zone_device.
 * @trip:	indicates which trip point the cooling devices is
 *		associated with in this thermal zone.
 * @trip:	trip point the cooling devices is associated with in this zone.
 * @cdev:	pointer to a struct thermal_cooling_device.
 *
 * This interface function unbind a thermal cooling device from the certain
@@ -753,8 +757,8 @@ EXPORT_SYMBOL_GPL(thermal_zone_bind_cooling_device);
 *
 * Return: 0 on success, the proper error value otherwise.
 */
int thermal_zone_unbind_cooling_device(struct thermal_zone_device *tz,
				       int trip,
int thermal_unbind_cdev_from_trip(struct thermal_zone_device *tz,
				  const struct thermal_trip *trip,
				  struct thermal_cooling_device *cdev)
{
	struct thermal_instance *pos, *next;
@@ -783,6 +787,17 @@ int thermal_zone_unbind_cooling_device(struct thermal_zone_device *tz,
	kfree(pos);
	return 0;
}
EXPORT_SYMBOL_GPL(thermal_unbind_cdev_from_trip);

int thermal_zone_unbind_cooling_device(struct thermal_zone_device *tz,
				       int trip_index,
				       struct thermal_cooling_device *cdev)
{
	if (trip_index < 0 || trip_index >= tz->num_trips)
		return -EINVAL;

	return thermal_unbind_cdev_from_trip(tz, &tz->trips[trip_index], cdev);
}
EXPORT_SYMBOL_GPL(thermal_zone_unbind_cooling_device);

static void thermal_release(struct device *dev)
@@ -1231,7 +1246,6 @@ thermal_zone_device_register_with_trips(const char *type, struct thermal_trip *t
	struct thermal_zone_device *tz;
	int id;
	int result;
	int count;
	struct thermal_governor *governor;

	if (!type || strlen(type) == 0) {
@@ -1328,14 +1342,6 @@ thermal_zone_device_register_with_trips(const char *type, struct thermal_trip *t
	if (result)
		goto release_device;

	for (count = 0; count < num_trips; count++) {
		struct thermal_trip trip;

		result = thermal_zone_get_trip(tz, count, &trip);
		if (result || !trip.temperature)
			set_bit(count, &tz->trips_disabled);
	}

	/* Update 'this' zone's governor information */
	mutex_lock(&thermal_governor_lock);

Loading