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

thermal: trip: Pass trip pointer to .set_trip_temp() thermal zone callback



Out of several drivers implementing the .set_trip_temp() thermal zone
operation, three don't actually use the trip ID argument passed to it,
two call __thermal_zone_get_trip() to get a struct thermal_trip
corresponding to the given trip ID, and the other use the trip ID as an
index into their own data structures with the assumption that it will
always match the ordering of entries in the trips table passed to the
core during thermal zone registration, which is fragile and not really
guaranteed.

Even though the trip IDs used by the core are in fact their indices in the
trips table passed to it by the thermal zone creator, that is purely a
matter of convenience and should not be relied on for correctness.

For this reason, modify trip_point_temp_store() to pass a (const) trip
pointer to .set_trip_temp() and adjust the drivers implementing it
accordingly.

This helps to simplify the drivers invoking __thermal_zone_get_trip()
from their .set_trip_temp() callback functions because they will not
need to do it now and the other drivers can store their internal
trip indices in the priv field in struct thermal_trip and their
.set_trip_temp() callback functions can get those indices from there.

The intel_quark_dts thermal driver can instead use the trip type to
determine the requisite trip index.

Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
Link: https://patch.msgid.link/8392906.T7Z3S40VBb@rjwysocki.net


[ rjw: Add missing colon and 2 empty code lines ]
[ rjw: Add missing change in imx_thermal.c and adjust the changelog ]
[ rjw: Drop an unused local variable ]
Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
parent 81caa5d5
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -638,7 +638,7 @@ static int iwl_mvm_tzone_get_temp(struct thermal_zone_device *device,
}

static int iwl_mvm_tzone_set_trip_temp(struct thermal_zone_device *device,
				       int trip, int temp)
				       const struct thermal_trip *trip, int temp)
{
	struct iwl_mvm *mvm = thermal_zone_device_priv(device);
	int ret;
+2 −2
Original line number Diff line number Diff line
@@ -331,8 +331,8 @@ static int imx_change_mode(struct thermal_zone_device *tz,
	return 0;
}

static int imx_set_trip_temp(struct thermal_zone_device *tz, int trip_id,
			     int temp)
static int imx_set_trip_temp(struct thermal_zone_device *tz,
			     const struct thermal_trip *trip, int temp)
{
	struct imx_thermal_data *data = thermal_zone_device_priv(tz);
	int ret;
+5 −3
Original line number Diff line number Diff line
@@ -39,13 +39,14 @@ static int int340x_thermal_get_zone_temp(struct thermal_zone_device *zone,
}

static int int340x_thermal_set_trip_temp(struct thermal_zone_device *zone,
					 int trip, int temp)
					 const struct thermal_trip *trip, int temp)
{
	struct int34x_thermal_zone *d = thermal_zone_device_priv(zone);
	char name[] = {'P', 'A', 'T', '0' + trip, '\0'};
	unsigned int trip_index = THERMAL_TRIP_PRIV_TO_INT(trip->priv);
	char name[] = {'P', 'A', 'T', '0' + trip_index, '\0'};
	acpi_status status;

	if (trip > 9)
	if (trip_index > 9)
		return -EINVAL;

	status = acpi_execute_simple_method(d->adev->handle, name,
@@ -144,6 +145,7 @@ struct int34x_thermal_zone *int340x_thermal_zone_add(struct acpi_device *adev,
		zone_trips[i].type = THERMAL_TRIP_PASSIVE;
		zone_trips[i].temperature = THERMAL_TEMP_INVALID;
		zone_trips[i].flags |= THERMAL_TRIP_FLAG_RW_TEMP;
		zone_trips[i].priv = THERMAL_INT_TO_TRIP_PRIV(i);
	}

	trip_cnt = int340x_thermal_read_trips(adev, zone_trips, trip_cnt);
+2 −1
Original line number Diff line number Diff line
@@ -194,7 +194,8 @@ static int sys_get_curr_temp(struct thermal_zone_device *tzd, int *temp)
	return 0;
}

static int sys_set_trip_temp(struct thermal_zone_device *tzd, int trip, int temp)
static int sys_set_trip_temp(struct thermal_zone_device *tzd,
			     const struct thermal_trip *trip, int temp)
{
	struct proc_thermal_pci *pci_info = thermal_zone_device_priv(tzd);
	int tjmax, _temp;
+22 −6
Original line number Diff line number Diff line
@@ -195,7 +195,7 @@ static int get_trip_temp(int trip)
}

static int update_trip_temp(struct soc_sensor_entry *aux_entry,
				int trip, int temp)
				int trip_index, int temp)
{
	u32 out;
	u32 temp_out;
@@ -230,9 +230,9 @@ static int update_trip_temp(struct soc_sensor_entry *aux_entry,
	 */
	temp_out = temp + QRK_DTS_TEMP_BASE;
	out = (store_ptps & ~(QRK_DTS_MASK_TP_THRES <<
		(trip * QRK_DTS_SHIFT_TP)));
		(trip_index * QRK_DTS_SHIFT_TP)));
	out |= (temp_out & QRK_DTS_MASK_TP_THRES) <<
		(trip * QRK_DTS_SHIFT_TP);
		(trip_index * QRK_DTS_SHIFT_TP);

	ret = iosf_mbi_write(QRK_MBI_UNIT_RMU, MBI_REG_WRITE,
			     QRK_DTS_REG_OFFSET_PTPS, out);
@@ -242,10 +242,26 @@ static int update_trip_temp(struct soc_sensor_entry *aux_entry,
	return ret;
}

static inline int sys_set_trip_temp(struct thermal_zone_device *tzd, int trip,
static inline int sys_set_trip_temp(struct thermal_zone_device *tzd,
				    const struct thermal_trip *trip,
				    int temp)
{
	return update_trip_temp(thermal_zone_device_priv(tzd), trip, temp);
	unsigned int trip_index;

	switch (trip->type) {
	case THERMAL_TRIP_HOT:
		trip_index = QRK_DTS_ID_TP_HOT;
		break;

	case THERMAL_TRIP_CRITICAL:
		trip_index = QRK_DTS_ID_TP_CRITICAL;
		break;

	default:
		return -EINVAL;
	}

	return update_trip_temp(thermal_zone_device_priv(tzd), trip_index, temp);
}

static int sys_get_curr_temp(struct thermal_zone_device *tzd,
Loading