Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6503e5df authored by Matthew Garrett's avatar Matthew Garrett Committed by Len Brown
Browse files

thermal: use integers rather than strings for thermal values



The thermal API currently uses strings to pass values to userspace. This
makes it difficult to use from within the kernel. Change the interface
to use integers and fix up the consumers.

Signed-off-by: default avatarMatthew Garrett <mjg@redhat.com>
Acked-by: default avatarZhang Rui <rui.zhang@intel.com>
Acked-by: default avatarThomas Renninger <trenn@suse.de>
Signed-off-by: default avatarLen Brown <len.brown@intel.com>
parent d2f8d7ee
Loading
Loading
Loading
Loading
+12 −8
Original line number Original line Diff line number Diff line
@@ -68,31 +68,35 @@ static struct acpi_driver acpi_fan_driver = {
};
};


/* thermal cooling device callbacks */
/* thermal cooling device callbacks */
static int fan_get_max_state(struct thermal_cooling_device *cdev, char *buf)
static int fan_get_max_state(struct thermal_cooling_device *cdev, unsigned long
			     *state)
{
{
	/* ACPI fan device only support two states: ON/OFF */
	/* ACPI fan device only support two states: ON/OFF */
	return sprintf(buf, "1\n");
	*state = 1;
	return 0;
}
}


static int fan_get_cur_state(struct thermal_cooling_device *cdev, char *buf)
static int fan_get_cur_state(struct thermal_cooling_device *cdev, unsigned long
			     *state)
{
{
	struct acpi_device *device = cdev->devdata;
	struct acpi_device *device = cdev->devdata;
	int state;
	int result;
	int result;
	int acpi_state;


	if (!device)
	if (!device)
		return -EINVAL;
		return -EINVAL;


	result = acpi_bus_get_power(device->handle, &state);
	result = acpi_bus_get_power(device->handle, &acpi_state);
	if (result)
	if (result)
		return result;
		return result;


	return sprintf(buf, "%s\n", state == ACPI_STATE_D3 ? "0" :
	*state = (acpi_state == ACPI_STATE_D3 ? 0 :
			 (state == ACPI_STATE_D0 ? "1" : "unknown"));
		 (acpi_state == ACPI_STATE_D0 ? 1 : -1));
	return 0;
}
}


static int
static int
fan_set_cur_state(struct thermal_cooling_device *cdev, unsigned int state)
fan_set_cur_state(struct thermal_cooling_device *cdev, unsigned long state)
{
{
	struct acpi_device *device = cdev->devdata;
	struct acpi_device *device = cdev->devdata;
	int result;
	int result;
+11 −9
Original line number Original line Diff line number Diff line
@@ -373,7 +373,8 @@ static int acpi_processor_max_state(struct acpi_processor *pr)
	return max_state;
	return max_state;
}
}
static int
static int
processor_get_max_state(struct thermal_cooling_device *cdev, char *buf)
processor_get_max_state(struct thermal_cooling_device *cdev,
			unsigned long *state)
{
{
	struct acpi_device *device = cdev->devdata;
	struct acpi_device *device = cdev->devdata;
	struct acpi_processor *pr = acpi_driver_data(device);
	struct acpi_processor *pr = acpi_driver_data(device);
@@ -381,28 +382,29 @@ processor_get_max_state(struct thermal_cooling_device *cdev, char *buf)
	if (!device || !pr)
	if (!device || !pr)
		return -EINVAL;
		return -EINVAL;


	return sprintf(buf, "%d\n", acpi_processor_max_state(pr));
	*state = acpi_processor_max_state(pr);
	return 0;
}
}


static int
static int
processor_get_cur_state(struct thermal_cooling_device *cdev, char *buf)
processor_get_cur_state(struct thermal_cooling_device *cdev,
			unsigned long *cur_state)
{
{
	struct acpi_device *device = cdev->devdata;
	struct acpi_device *device = cdev->devdata;
	struct acpi_processor *pr = acpi_driver_data(device);
	struct acpi_processor *pr = acpi_driver_data(device);
	int cur_state;


	if (!device || !pr)
	if (!device || !pr)
		return -EINVAL;
		return -EINVAL;


	cur_state = cpufreq_get_cur_state(pr->id);
	*cur_state = cpufreq_get_cur_state(pr->id);
	if (pr->flags.throttling)
	if (pr->flags.throttling)
		cur_state += pr->throttling.state;
		*cur_state += pr->throttling.state;

	return 0;
	return sprintf(buf, "%d\n", cur_state);
}
}


static int
static int
processor_set_cur_state(struct thermal_cooling_device *cdev, unsigned int state)
processor_set_cur_state(struct thermal_cooling_device *cdev,
			unsigned long state)
{
{
	struct acpi_device *device = cdev->devdata;
	struct acpi_device *device = cdev->devdata;
	struct acpi_processor *pr = acpi_driver_data(device);
	struct acpi_processor *pr = acpi_driver_data(device);
+50 −30
Original line number Original line Diff line number Diff line
@@ -954,7 +954,8 @@ static void acpi_thermal_check(void *data)
/* sys I/F for generic thermal sysfs support */
/* sys I/F for generic thermal sysfs support */
#define KELVIN_TO_MILLICELSIUS(t) (t * 100 - 273200)
#define KELVIN_TO_MILLICELSIUS(t) (t * 100 - 273200)


static int thermal_get_temp(struct thermal_zone_device *thermal, char *buf)
static int thermal_get_temp(struct thermal_zone_device *thermal,
			    unsigned long *temp)
{
{
	struct acpi_thermal *tz = thermal->devdata;
	struct acpi_thermal *tz = thermal->devdata;
	int result;
	int result;
@@ -966,25 +967,28 @@ static int thermal_get_temp(struct thermal_zone_device *thermal, char *buf)
	if (result)
	if (result)
		return result;
		return result;


	return sprintf(buf, "%ld\n", KELVIN_TO_MILLICELSIUS(tz->temperature));
	*temp = KELVIN_TO_MILLICELSIUS(tz->temperature);
	return 0;
}
}


static const char enabled[] = "kernel";
static const char enabled[] = "kernel";
static const char disabled[] = "user";
static const char disabled[] = "user";
static int thermal_get_mode(struct thermal_zone_device *thermal,
static int thermal_get_mode(struct thermal_zone_device *thermal,
				char *buf)
				enum thermal_device_mode *mode)
{
{
	struct acpi_thermal *tz = thermal->devdata;
	struct acpi_thermal *tz = thermal->devdata;


	if (!tz)
	if (!tz)
		return -EINVAL;
		return -EINVAL;


	return sprintf(buf, "%s\n", tz->tz_enabled ?
	*mode = tz->tz_enabled ? THERMAL_DEVICE_ENABLED :
			enabled : disabled);
		THERMAL_DEVICE_DISABLED;

	return 0;
}
}


static int thermal_set_mode(struct thermal_zone_device *thermal,
static int thermal_set_mode(struct thermal_zone_device *thermal,
				const char *buf)
				enum thermal_device_mode mode)
{
{
	struct acpi_thermal *tz = thermal->devdata;
	struct acpi_thermal *tz = thermal->devdata;
	int enable;
	int enable;
@@ -995,9 +999,9 @@ static int thermal_set_mode(struct thermal_zone_device *thermal,
	/*
	/*
	 * enable/disable thermal management from ACPI thermal driver
	 * enable/disable thermal management from ACPI thermal driver
	 */
	 */
	if (!strncmp(buf, enabled, sizeof enabled - 1))
	if (mode == THERMAL_DEVICE_ENABLED)
		enable = 1;
		enable = 1;
	else if (!strncmp(buf, disabled, sizeof disabled - 1))
	else if (mode == THERMAL_DEVICE_DISABLED)
		enable = 0;
		enable = 0;
	else
	else
		return -EINVAL;
		return -EINVAL;
@@ -1013,7 +1017,7 @@ static int thermal_set_mode(struct thermal_zone_device *thermal,
}
}


static int thermal_get_trip_type(struct thermal_zone_device *thermal,
static int thermal_get_trip_type(struct thermal_zone_device *thermal,
				 int trip, char *buf)
				 int trip, enum thermal_trip_type *type)
{
{
	struct acpi_thermal *tz = thermal->devdata;
	struct acpi_thermal *tz = thermal->devdata;
	int i;
	int i;
@@ -1022,27 +1026,35 @@ static int thermal_get_trip_type(struct thermal_zone_device *thermal,
		return -EINVAL;
		return -EINVAL;


	if (tz->trips.critical.flags.valid) {
	if (tz->trips.critical.flags.valid) {
		if (!trip)
		if (!trip) {
			return sprintf(buf, "critical\n");
			*type = THERMAL_TRIP_CRITICAL;
			return 0;
		}
		trip--;
		trip--;
	}
	}


	if (tz->trips.hot.flags.valid) {
	if (tz->trips.hot.flags.valid) {
		if (!trip)
		if (!trip) {
			return sprintf(buf, "hot\n");
			*type = THERMAL_TRIP_HOT;
			return 0;
		}
		trip--;
		trip--;
	}
	}


	if (tz->trips.passive.flags.valid) {
	if (tz->trips.passive.flags.valid) {
		if (!trip)
		if (!trip) {
			return sprintf(buf, "passive\n");
			*type = THERMAL_TRIP_PASSIVE;
			return 0;
		}
		trip--;
		trip--;
	}
	}


	for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE &&
	for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE &&
		tz->trips.active[i].flags.valid; i++) {
		tz->trips.active[i].flags.valid; i++) {
		if (!trip)
		if (!trip) {
			return sprintf(buf, "active%d\n", i);
			*type = THERMAL_TRIP_ACTIVE;
			return 0;
		}
		trip--;
		trip--;
	}
	}


@@ -1050,7 +1062,7 @@ static int thermal_get_trip_type(struct thermal_zone_device *thermal,
}
}


static int thermal_get_trip_temp(struct thermal_zone_device *thermal,
static int thermal_get_trip_temp(struct thermal_zone_device *thermal,
				 int trip, char *buf)
				 int trip, unsigned long *temp)
{
{
	struct acpi_thermal *tz = thermal->devdata;
	struct acpi_thermal *tz = thermal->devdata;
	int i;
	int i;
@@ -1059,31 +1071,39 @@ static int thermal_get_trip_temp(struct thermal_zone_device *thermal,
		return -EINVAL;
		return -EINVAL;


	if (tz->trips.critical.flags.valid) {
	if (tz->trips.critical.flags.valid) {
		if (!trip)
		if (!trip) {
			return sprintf(buf, "%ld\n", KELVIN_TO_MILLICELSIUS(
			*temp = KELVIN_TO_MILLICELSIUS(
				tz->trips.critical.temperature));
				tz->trips.critical.temperature);
			return 0;
		}
		trip--;
		trip--;
	}
	}


	if (tz->trips.hot.flags.valid) {
	if (tz->trips.hot.flags.valid) {
		if (!trip)
		if (!trip) {
			return sprintf(buf, "%ld\n", KELVIN_TO_MILLICELSIUS(
			*temp = KELVIN_TO_MILLICELSIUS(
					tz->trips.hot.temperature));
				tz->trips.hot.temperature);
			return 0;
		}
		trip--;
		trip--;
	}
	}


	if (tz->trips.passive.flags.valid) {
	if (tz->trips.passive.flags.valid) {
		if (!trip)
		if (!trip) {
			return sprintf(buf, "%ld\n", KELVIN_TO_MILLICELSIUS(
			*temp = KELVIN_TO_MILLICELSIUS(
					tz->trips.passive.temperature));
				tz->trips.passive.temperature);
			return 0;
		}
		trip--;
		trip--;
	}
	}


	for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE &&
	for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE &&
		tz->trips.active[i].flags.valid; i++) {
		tz->trips.active[i].flags.valid; i++) {
		if (!trip)
		if (!trip) {
			return sprintf(buf, "%ld\n", KELVIN_TO_MILLICELSIUS(
			*temp = KELVIN_TO_MILLICELSIUS(
					tz->trips.active[i].temperature));
				tz->trips.active[i].temperature);
			return 0;
		}
		trip--;
		trip--;
	}
	}


+13 −9
Original line number Original line Diff line number Diff line
@@ -358,32 +358,36 @@ static struct output_properties acpi_output_properties = {




/* thermal cooling device callbacks */
/* thermal cooling device callbacks */
static int video_get_max_state(struct thermal_cooling_device *cdev, char *buf)
static int video_get_max_state(struct thermal_cooling_device *cdev, unsigned
			       long *state)
{
{
	struct acpi_device *device = cdev->devdata;
	struct acpi_device *device = cdev->devdata;
	struct acpi_video_device *video = acpi_driver_data(device);
	struct acpi_video_device *video = acpi_driver_data(device);


	return sprintf(buf, "%d\n", video->brightness->count - 3);
	*state = video->brightness->count - 3;
	return 0;
}
}


static int video_get_cur_state(struct thermal_cooling_device *cdev, char *buf)
static int video_get_cur_state(struct thermal_cooling_device *cdev, unsigned
			       long *state)
{
{
	struct acpi_device *device = cdev->devdata;
	struct acpi_device *device = cdev->devdata;
	struct acpi_video_device *video = acpi_driver_data(device);
	struct acpi_video_device *video = acpi_driver_data(device);
	unsigned long long level;
	unsigned long long level;
	int state;
	int offset;


	acpi_video_device_lcd_get_level_current(video, &level);
	acpi_video_device_lcd_get_level_current(video, &level);
	for (state = 2; state < video->brightness->count; state++)
	for (offset = 2; offset < video->brightness->count; offset++)
		if (level == video->brightness->levels[state])
		if (level == video->brightness->levels[offset]) {
			return sprintf(buf, "%d\n",
			*state = video->brightness->count - offset - 1;
				       video->brightness->count - state - 1);
			return 0;
		}


	return -EINVAL;
	return -EINVAL;
}
}


static int
static int
video_set_cur_state(struct thermal_cooling_device *cdev, unsigned int state)
video_set_cur_state(struct thermal_cooling_device *cdev, unsigned long state)
{
{
	struct acpi_device *device = cdev->devdata;
	struct acpi_device *device = cdev->devdata;
	struct acpi_video_device *video = acpi_driver_data(device);
	struct acpi_video_device *video = acpi_driver_data(device);
+10 −19
Original line number Original line Diff line number Diff line
@@ -57,7 +57,7 @@ MODULE_LICENSE("GPL");
 * In that case max_cstate would be n-1
 * In that case max_cstate would be n-1
 * GTHS returning '0' would mean that no bandwidth control states are supported
 * GTHS returning '0' would mean that no bandwidth control states are supported
 */
 */
static int memory_get_int_max_bandwidth(struct thermal_cooling_device *cdev,
static int memory_get_max_bandwidth(struct thermal_cooling_device *cdev,
				    unsigned long *max_state)
				    unsigned long *max_state)
{
{
	struct acpi_device *device = cdev->devdata;
	struct acpi_device *device = cdev->devdata;
@@ -83,22 +83,12 @@ static int memory_get_int_max_bandwidth(struct thermal_cooling_device *cdev,
	return 0;
	return 0;
}
}


static int memory_get_max_bandwidth(struct thermal_cooling_device *cdev,
				    char *buf)
{
	unsigned long value;
	if (memory_get_int_max_bandwidth(cdev, &value))
		return -EINVAL;

	return sprintf(buf, "%ld\n", value);
}

static int memory_get_cur_bandwidth(struct thermal_cooling_device *cdev,
static int memory_get_cur_bandwidth(struct thermal_cooling_device *cdev,
				    char *buf)
				    unsigned long *value)
{
{
	struct acpi_device *device = cdev->devdata;
	struct acpi_device *device = cdev->devdata;
	acpi_handle handle = device->handle;
	acpi_handle handle = device->handle;
	unsigned long long value;
	unsigned long long result;
	struct acpi_object_list arg_list;
	struct acpi_object_list arg_list;
	union acpi_object arg;
	union acpi_object arg;
	acpi_status status = AE_OK;
	acpi_status status = AE_OK;
@@ -108,15 +98,16 @@ static int memory_get_cur_bandwidth(struct thermal_cooling_device *cdev,
	arg.type = ACPI_TYPE_INTEGER;
	arg.type = ACPI_TYPE_INTEGER;
	arg.integer.value = MEMORY_ARG_CUR_BANDWIDTH;
	arg.integer.value = MEMORY_ARG_CUR_BANDWIDTH;
	status = acpi_evaluate_integer(handle, MEMORY_GET_BANDWIDTH,
	status = acpi_evaluate_integer(handle, MEMORY_GET_BANDWIDTH,
				       &arg_list, &value);
				       &arg_list, &result);
	if (ACPI_FAILURE(status))
	if (ACPI_FAILURE(status))
		return -EFAULT;
		return -EFAULT;


	return sprintf(buf, "%llu\n", value);
	*value = result;
	return 0;
}
}


static int memory_set_cur_bandwidth(struct thermal_cooling_device *cdev,
static int memory_set_cur_bandwidth(struct thermal_cooling_device *cdev,
				    unsigned int state)
				    unsigned long state)
{
{
	struct acpi_device *device = cdev->devdata;
	struct acpi_device *device = cdev->devdata;
	acpi_handle handle = device->handle;
	acpi_handle handle = device->handle;
@@ -126,7 +117,7 @@ static int memory_set_cur_bandwidth(struct thermal_cooling_device *cdev,
	unsigned long long temp;
	unsigned long long temp;
	unsigned long max_state;
	unsigned long max_state;


	if (memory_get_int_max_bandwidth(cdev, &max_state))
	if (memory_get_max_bandwidth(cdev, &max_state))
		return -EFAULT;
		return -EFAULT;


	if (state > max_state)
	if (state > max_state)
@@ -142,7 +133,7 @@ static int memory_set_cur_bandwidth(struct thermal_cooling_device *cdev,
				  &temp);
				  &temp);


	printk(KERN_INFO
	printk(KERN_INFO
	       "Bandwidth value was %d: status is %d\n", state, status);
	       "Bandwidth value was %ld: status is %d\n", state, status);
	if (ACPI_FAILURE(status))
	if (ACPI_FAILURE(status))
		return -EFAULT;
		return -EFAULT;


Loading