Skip to content

Commit

Permalink
thermal: use integers rather than strings for thermal values
Browse files Browse the repository at this point in the history
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: Matthew Garrett <[email protected]>
Acked-by: Zhang Rui <[email protected]>
Acked-by: Thomas Renninger <[email protected]>
Signed-off-by: Len Brown <[email protected]>
  • Loading branch information
mjg59 authored and lenb committed Feb 20, 2009
1 parent d2f8d7e commit 6503e5d
Show file tree
Hide file tree
Showing 7 changed files with 198 additions and 96 deletions.
20 changes: 12 additions & 8 deletions drivers/acpi/fan.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,31 +68,35 @@ static struct acpi_driver acpi_fan_driver = {
};

/* 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 */
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;
int state;
int result;
int acpi_state;

if (!device)
return -EINVAL;

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

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

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;
int result;
Expand Down
20 changes: 11 additions & 9 deletions drivers/acpi/processor_thermal.c
Original file line number Diff line number Diff line change
Expand Up @@ -373,36 +373,38 @@ static int acpi_processor_max_state(struct acpi_processor *pr)
return max_state;
}
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_processor *pr = acpi_driver_data(device);

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

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

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_processor *pr = acpi_driver_data(device);
int cur_state;

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

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

return sprintf(buf, "%d\n", cur_state);
*cur_state += pr->throttling.state;
return 0;
}

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_processor *pr = acpi_driver_data(device);
Expand Down
80 changes: 50 additions & 30 deletions drivers/acpi/thermal.c
Original file line number Diff line number Diff line change
Expand Up @@ -954,7 +954,8 @@ static void acpi_thermal_check(void *data)
/* sys I/F for generic thermal sysfs support */
#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;
int result;
Expand All @@ -966,25 +967,28 @@ static int thermal_get_temp(struct thermal_zone_device *thermal, char *buf)
if (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 disabled[] = "user";
static int thermal_get_mode(struct thermal_zone_device *thermal,
char *buf)
enum thermal_device_mode *mode)
{
struct acpi_thermal *tz = thermal->devdata;

if (!tz)
return -EINVAL;

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

return 0;
}

static int thermal_set_mode(struct thermal_zone_device *thermal,
const char *buf)
enum thermal_device_mode mode)
{
struct acpi_thermal *tz = thermal->devdata;
int enable;
Expand All @@ -995,9 +999,9 @@ static int thermal_set_mode(struct thermal_zone_device *thermal,
/*
* enable/disable thermal management from ACPI thermal driver
*/
if (!strncmp(buf, enabled, sizeof enabled - 1))
if (mode == THERMAL_DEVICE_ENABLED)
enable = 1;
else if (!strncmp(buf, disabled, sizeof disabled - 1))
else if (mode == THERMAL_DEVICE_DISABLED)
enable = 0;
else
return -EINVAL;
Expand All @@ -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,
int trip, char *buf)
int trip, enum thermal_trip_type *type)
{
struct acpi_thermal *tz = thermal->devdata;
int i;
Expand All @@ -1022,35 +1026,43 @@ static int thermal_get_trip_type(struct thermal_zone_device *thermal,
return -EINVAL;

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

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

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

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

return -EINVAL;
}

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;
int i;
Expand All @@ -1059,31 +1071,39 @@ static int thermal_get_trip_temp(struct thermal_zone_device *thermal,
return -EINVAL;

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

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

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

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

Expand Down
22 changes: 13 additions & 9 deletions drivers/acpi/video.c
Original file line number Diff line number Diff line change
Expand Up @@ -358,32 +358,36 @@ static struct output_properties acpi_output_properties = {


/* 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_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_video_device *video = acpi_driver_data(device);
unsigned long long level;
int state;
int offset;

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

return -EINVAL;
}

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_video_device *video = acpi_driver_data(device);
Expand Down
29 changes: 10 additions & 19 deletions drivers/platform/x86/intel_menlow.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ MODULE_LICENSE("GPL");
* In that case max_cstate would be n-1
* GTHS returning '0' would mean that no bandwidth control states are supported
*/
static int memory_get_int_max_bandwidth(struct thermal_cooling_device *cdev,
unsigned long *max_state)
static int memory_get_max_bandwidth(struct thermal_cooling_device *cdev,
unsigned long *max_state)
{
struct acpi_device *device = cdev->devdata;
acpi_handle handle = device->handle;
Expand All @@ -83,22 +83,12 @@ static int memory_get_int_max_bandwidth(struct thermal_cooling_device *cdev,
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,
char *buf)
unsigned long *value)
{
struct acpi_device *device = cdev->devdata;
acpi_handle handle = device->handle;
unsigned long long value;
unsigned long long result;
struct acpi_object_list arg_list;
union acpi_object arg;
acpi_status status = AE_OK;
Expand All @@ -108,15 +98,16 @@ static int memory_get_cur_bandwidth(struct thermal_cooling_device *cdev,
arg.type = ACPI_TYPE_INTEGER;
arg.integer.value = MEMORY_ARG_CUR_BANDWIDTH;
status = acpi_evaluate_integer(handle, MEMORY_GET_BANDWIDTH,
&arg_list, &value);
&arg_list, &result);
if (ACPI_FAILURE(status))
return -EFAULT;

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

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

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

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

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))
return -EFAULT;

Expand Down
Loading

0 comments on commit 6503e5d

Please sign in to comment.