aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Garrett <mjg59@srcf.ucam.org>2008-11-27 12:48:13 -0500
committerLen Brown <len.brown@intel.com>2009-02-20 10:52:37 -0500
commit6503e5df08008b9a47022b5e9ebba658c8fa69af (patch)
tree8ef36d1b85d2a03ac9e61f5074d717b67f9259ba
parentd2f8d7ee1a9b4650b4e43325b321801264f7c37a (diff)
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: Matthew Garrett <mjg@redhat.com> Acked-by: Zhang Rui <rui.zhang@intel.com> Acked-by: Thomas Renninger <trenn@suse.de> Signed-off-by: Len Brown <len.brown@intel.com>
-rw-r--r--drivers/acpi/fan.c20
-rw-r--r--drivers/acpi/processor_thermal.c20
-rw-r--r--drivers/acpi/thermal.c80
-rw-r--r--drivers/acpi/video.c22
-rw-r--r--drivers/platform/x86/intel_menlow.c29
-rw-r--r--drivers/thermal/thermal_sys.c91
-rw-r--r--include/linux/thermal.h32
7 files changed, 198 insertions, 96 deletions
diff --git a/drivers/acpi/fan.c b/drivers/acpi/fan.c
index eaaee1660bdf..ae41cf3cf4e5 100644
--- a/drivers/acpi/fan.c
+++ b/drivers/acpi/fan.c
@@ -68,31 +68,35 @@ static struct acpi_driver acpi_fan_driver = {
68}; 68};
69 69
70/* thermal cooling device callbacks */ 70/* thermal cooling device callbacks */
71static int fan_get_max_state(struct thermal_cooling_device *cdev, char *buf) 71static int fan_get_max_state(struct thermal_cooling_device *cdev, unsigned long
72 *state)
72{ 73{
73 /* ACPI fan device only support two states: ON/OFF */ 74 /* ACPI fan device only support two states: ON/OFF */
74 return sprintf(buf, "1\n"); 75 *state = 1;
76 return 0;
75} 77}
76 78
77static int fan_get_cur_state(struct thermal_cooling_device *cdev, char *buf) 79static int fan_get_cur_state(struct thermal_cooling_device *cdev, unsigned long
80 *state)
78{ 81{
79 struct acpi_device *device = cdev->devdata; 82 struct acpi_device *device = cdev->devdata;
80 int state;
81 int result; 83 int result;
84 int acpi_state;
82 85
83 if (!device) 86 if (!device)
84 return -EINVAL; 87 return -EINVAL;
85 88
86 result = acpi_bus_get_power(device->handle, &state); 89 result = acpi_bus_get_power(device->handle, &acpi_state);
87 if (result) 90 if (result)
88 return result; 91 return result;
89 92
90 return sprintf(buf, "%s\n", state == ACPI_STATE_D3 ? "0" : 93 *state = (acpi_state == ACPI_STATE_D3 ? 0 :
91 (state == ACPI_STATE_D0 ? "1" : "unknown")); 94 (acpi_state == ACPI_STATE_D0 ? 1 : -1));
95 return 0;
92} 96}
93 97
94static int 98static int
95fan_set_cur_state(struct thermal_cooling_device *cdev, unsigned int state) 99fan_set_cur_state(struct thermal_cooling_device *cdev, unsigned long state)
96{ 100{
97 struct acpi_device *device = cdev->devdata; 101 struct acpi_device *device = cdev->devdata;
98 int result; 102 int result;
diff --git a/drivers/acpi/processor_thermal.c b/drivers/acpi/processor_thermal.c
index b1eb376fae45..0e47e299a9ac 100644
--- a/drivers/acpi/processor_thermal.c
+++ b/drivers/acpi/processor_thermal.c
@@ -373,7 +373,8 @@ static int acpi_processor_max_state(struct acpi_processor *pr)
373 return max_state; 373 return max_state;
374} 374}
375static int 375static int
376processor_get_max_state(struct thermal_cooling_device *cdev, char *buf) 376processor_get_max_state(struct thermal_cooling_device *cdev,
377 unsigned long *state)
377{ 378{
378 struct acpi_device *device = cdev->devdata; 379 struct acpi_device *device = cdev->devdata;
379 struct acpi_processor *pr = acpi_driver_data(device); 380 struct acpi_processor *pr = acpi_driver_data(device);
@@ -381,28 +382,29 @@ processor_get_max_state(struct thermal_cooling_device *cdev, char *buf)
381 if (!device || !pr) 382 if (!device || !pr)
382 return -EINVAL; 383 return -EINVAL;
383 384
384 return sprintf(buf, "%d\n", acpi_processor_max_state(pr)); 385 *state = acpi_processor_max_state(pr);
386 return 0;
385} 387}
386 388
387static int 389static int
388processor_get_cur_state(struct thermal_cooling_device *cdev, char *buf) 390processor_get_cur_state(struct thermal_cooling_device *cdev,
391 unsigned long *cur_state)
389{ 392{
390 struct acpi_device *device = cdev->devdata; 393 struct acpi_device *device = cdev->devdata;
391 struct acpi_processor *pr = acpi_driver_data(device); 394 struct acpi_processor *pr = acpi_driver_data(device);
392 int cur_state;
393 395
394 if (!device || !pr) 396 if (!device || !pr)
395 return -EINVAL; 397 return -EINVAL;
396 398
397 cur_state = cpufreq_get_cur_state(pr->id); 399 *cur_state = cpufreq_get_cur_state(pr->id);
398 if (pr->flags.throttling) 400 if (pr->flags.throttling)
399 cur_state += pr->throttling.state; 401 *cur_state += pr->throttling.state;
400 402 return 0;
401 return sprintf(buf, "%d\n", cur_state);
402} 403}
403 404
404static int 405static int
405processor_set_cur_state(struct thermal_cooling_device *cdev, unsigned int state) 406processor_set_cur_state(struct thermal_cooling_device *cdev,
407 unsigned long state)
406{ 408{
407 struct acpi_device *device = cdev->devdata; 409 struct acpi_device *device = cdev->devdata;
408 struct acpi_processor *pr = acpi_driver_data(device); 410 struct acpi_processor *pr = acpi_driver_data(device);
diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c
index 99e6f1f8ea45..1c410ef859c6 100644
--- a/drivers/acpi/thermal.c
+++ b/drivers/acpi/thermal.c
@@ -954,7 +954,8 @@ static void acpi_thermal_check(void *data)
954/* sys I/F for generic thermal sysfs support */ 954/* sys I/F for generic thermal sysfs support */
955#define KELVIN_TO_MILLICELSIUS(t) (t * 100 - 273200) 955#define KELVIN_TO_MILLICELSIUS(t) (t * 100 - 273200)
956 956
957static int thermal_get_temp(struct thermal_zone_device *thermal, char *buf) 957static int thermal_get_temp(struct thermal_zone_device *thermal,
958 unsigned long *temp)
958{ 959{
959 struct acpi_thermal *tz = thermal->devdata; 960 struct acpi_thermal *tz = thermal->devdata;
960 int result; 961 int result;
@@ -966,25 +967,28 @@ static int thermal_get_temp(struct thermal_zone_device *thermal, char *buf)
966 if (result) 967 if (result)
967 return result; 968 return result;
968 969
969 return sprintf(buf, "%ld\n", KELVIN_TO_MILLICELSIUS(tz->temperature)); 970 *temp = KELVIN_TO_MILLICELSIUS(tz->temperature);
971 return 0;
970} 972}
971 973
972static const char enabled[] = "kernel"; 974static const char enabled[] = "kernel";
973static const char disabled[] = "user"; 975static const char disabled[] = "user";
974static int thermal_get_mode(struct thermal_zone_device *thermal, 976static int thermal_get_mode(struct thermal_zone_device *thermal,
975 char *buf) 977 enum thermal_device_mode *mode)
976{ 978{
977 struct acpi_thermal *tz = thermal->devdata; 979 struct acpi_thermal *tz = thermal->devdata;
978 980
979 if (!tz) 981 if (!tz)
980 return -EINVAL; 982 return -EINVAL;
981 983
982 return sprintf(buf, "%s\n", tz->tz_enabled ? 984 *mode = tz->tz_enabled ? THERMAL_DEVICE_ENABLED :
983 enabled : disabled); 985 THERMAL_DEVICE_DISABLED;
986
987 return 0;
984} 988}
985 989
986static int thermal_set_mode(struct thermal_zone_device *thermal, 990static int thermal_set_mode(struct thermal_zone_device *thermal,
987 const char *buf) 991 enum thermal_device_mode mode)
988{ 992{
989 struct acpi_thermal *tz = thermal->devdata; 993 struct acpi_thermal *tz = thermal->devdata;
990 int enable; 994 int enable;
@@ -995,9 +999,9 @@ static int thermal_set_mode(struct thermal_zone_device *thermal,
995 /* 999 /*
996 * enable/disable thermal management from ACPI thermal driver 1000 * enable/disable thermal management from ACPI thermal driver
997 */ 1001 */
998 if (!strncmp(buf, enabled, sizeof enabled - 1)) 1002 if (mode == THERMAL_DEVICE_ENABLED)
999 enable = 1; 1003 enable = 1;
1000 else if (!strncmp(buf, disabled, sizeof disabled - 1)) 1004 else if (mode == THERMAL_DEVICE_DISABLED)
1001 enable = 0; 1005 enable = 0;
1002 else 1006 else
1003 return -EINVAL; 1007 return -EINVAL;
@@ -1013,7 +1017,7 @@ static int thermal_set_mode(struct thermal_zone_device *thermal,
1013} 1017}
1014 1018
1015static int thermal_get_trip_type(struct thermal_zone_device *thermal, 1019static int thermal_get_trip_type(struct thermal_zone_device *thermal,
1016 int trip, char *buf) 1020 int trip, enum thermal_trip_type *type)
1017{ 1021{
1018 struct acpi_thermal *tz = thermal->devdata; 1022 struct acpi_thermal *tz = thermal->devdata;
1019 int i; 1023 int i;
@@ -1022,27 +1026,35 @@ static int thermal_get_trip_type(struct thermal_zone_device *thermal,
1022 return -EINVAL; 1026 return -EINVAL;
1023 1027
1024 if (tz->trips.critical.flags.valid) { 1028 if (tz->trips.critical.flags.valid) {
1025 if (!trip) 1029 if (!trip) {
1026 return sprintf(buf, "critical\n"); 1030 *type = THERMAL_TRIP_CRITICAL;
1031 return 0;
1032 }
1027 trip--; 1033 trip--;
1028 } 1034 }
1029 1035
1030 if (tz->trips.hot.flags.valid) { 1036 if (tz->trips.hot.flags.valid) {
1031 if (!trip) 1037 if (!trip) {
1032 return sprintf(buf, "hot\n"); 1038 *type = THERMAL_TRIP_HOT;
1039 return 0;
1040 }
1033 trip--; 1041 trip--;
1034 } 1042 }
1035 1043
1036 if (tz->trips.passive.flags.valid) { 1044 if (tz->trips.passive.flags.valid) {
1037 if (!trip) 1045 if (!trip) {
1038 return sprintf(buf, "passive\n"); 1046 *type = THERMAL_TRIP_PASSIVE;
1047 return 0;
1048 }
1039 trip--; 1049 trip--;
1040 } 1050 }
1041 1051
1042 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE && 1052 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE &&
1043 tz->trips.active[i].flags.valid; i++) { 1053 tz->trips.active[i].flags.valid; i++) {
1044 if (!trip) 1054 if (!trip) {
1045 return sprintf(buf, "active%d\n", i); 1055 *type = THERMAL_TRIP_ACTIVE;
1056 return 0;
1057 }
1046 trip--; 1058 trip--;
1047 } 1059 }
1048 1060
@@ -1050,7 +1062,7 @@ static int thermal_get_trip_type(struct thermal_zone_device *thermal,
1050} 1062}
1051 1063
1052static int thermal_get_trip_temp(struct thermal_zone_device *thermal, 1064static int thermal_get_trip_temp(struct thermal_zone_device *thermal,
1053 int trip, char *buf) 1065 int trip, unsigned long *temp)
1054{ 1066{
1055 struct acpi_thermal *tz = thermal->devdata; 1067 struct acpi_thermal *tz = thermal->devdata;
1056 int i; 1068 int i;
@@ -1059,31 +1071,39 @@ static int thermal_get_trip_temp(struct thermal_zone_device *thermal,
1059 return -EINVAL; 1071 return -EINVAL;
1060 1072
1061 if (tz->trips.critical.flags.valid) { 1073 if (tz->trips.critical.flags.valid) {
1062 if (!trip) 1074 if (!trip) {
1063 return sprintf(buf, "%ld\n", KELVIN_TO_MILLICELSIUS( 1075 *temp = KELVIN_TO_MILLICELSIUS(
1064 tz->trips.critical.temperature)); 1076 tz->trips.critical.temperature);
1077 return 0;
1078 }
1065 trip--; 1079 trip--;
1066 } 1080 }
1067 1081
1068 if (tz->trips.hot.flags.valid) { 1082 if (tz->trips.hot.flags.valid) {
1069 if (!trip) 1083 if (!trip) {
1070 return sprintf(buf, "%ld\n", KELVIN_TO_MILLICELSIUS( 1084 *temp = KELVIN_TO_MILLICELSIUS(
1071 tz->trips.hot.temperature)); 1085 tz->trips.hot.temperature);
1086 return 0;
1087 }
1072 trip--; 1088 trip--;
1073 } 1089 }
1074 1090
1075 if (tz->trips.passive.flags.valid) { 1091 if (tz->trips.passive.flags.valid) {
1076 if (!trip) 1092 if (!trip) {
1077 return sprintf(buf, "%ld\n", KELVIN_TO_MILLICELSIUS( 1093 *temp = KELVIN_TO_MILLICELSIUS(
1078 tz->trips.passive.temperature)); 1094 tz->trips.passive.temperature);
1095 return 0;
1096 }
1079 trip--; 1097 trip--;
1080 } 1098 }
1081 1099
1082 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE && 1100 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE &&
1083 tz->trips.active[i].flags.valid; i++) { 1101 tz->trips.active[i].flags.valid; i++) {
1084 if (!trip) 1102 if (!trip) {
1085 return sprintf(buf, "%ld\n", KELVIN_TO_MILLICELSIUS( 1103 *temp = KELVIN_TO_MILLICELSIUS(
1086 tz->trips.active[i].temperature)); 1104 tz->trips.active[i].temperature);
1105 return 0;
1106 }
1087 trip--; 1107 trip--;
1088 } 1108 }
1089 1109
diff --git a/drivers/acpi/video.c b/drivers/acpi/video.c
index bb5ed059114a..5259d502add6 100644
--- a/drivers/acpi/video.c
+++ b/drivers/acpi/video.c
@@ -358,32 +358,36 @@ static struct output_properties acpi_output_properties = {
358 358
359 359
360/* thermal cooling device callbacks */ 360/* thermal cooling device callbacks */
361static int video_get_max_state(struct thermal_cooling_device *cdev, char *buf) 361static int video_get_max_state(struct thermal_cooling_device *cdev, unsigned
362 long *state)
362{ 363{
363 struct acpi_device *device = cdev->devdata; 364 struct acpi_device *device = cdev->devdata;
364 struct acpi_video_device *video = acpi_driver_data(device); 365 struct acpi_video_device *video = acpi_driver_data(device);
365 366
366 return sprintf(buf, "%d\n", video->brightness->count - 3); 367 *state = video->brightness->count - 3;
368 return 0;
367} 369}
368 370
369static int video_get_cur_state(struct thermal_cooling_device *cdev, char *buf) 371static int video_get_cur_state(struct thermal_cooling_device *cdev, unsigned
372 long *state)
370{ 373{
371 struct acpi_device *device = cdev->devdata; 374 struct acpi_device *device = cdev->devdata;
372 struct acpi_video_device *video = acpi_driver_data(device); 375 struct acpi_video_device *video = acpi_driver_data(device);
373 unsigned long long level; 376 unsigned long long level;
374 int state; 377 int offset;
375 378
376 acpi_video_device_lcd_get_level_current(video, &level); 379 acpi_video_device_lcd_get_level_current(video, &level);
377 for (state = 2; state < video->brightness->count; state++) 380 for (offset = 2; offset < video->brightness->count; offset++)
378 if (level == video->brightness->levels[state]) 381 if (level == video->brightness->levels[offset]) {
379 return sprintf(buf, "%d\n", 382 *state = video->brightness->count - offset - 1;
380 video->brightness->count - state - 1); 383 return 0;
384 }
381 385
382 return -EINVAL; 386 return -EINVAL;
383} 387}
384 388
385static int 389static int
386video_set_cur_state(struct thermal_cooling_device *cdev, unsigned int state) 390video_set_cur_state(struct thermal_cooling_device *cdev, unsigned long state)
387{ 391{
388 struct acpi_device *device = cdev->devdata; 392 struct acpi_device *device = cdev->devdata;
389 struct acpi_video_device *video = acpi_driver_data(device); 393 struct acpi_video_device *video = acpi_driver_data(device);
diff --git a/drivers/platform/x86/intel_menlow.c b/drivers/platform/x86/intel_menlow.c
index 27b7662955bb..29432a50be45 100644
--- a/drivers/platform/x86/intel_menlow.c
+++ b/drivers/platform/x86/intel_menlow.c
@@ -57,8 +57,8 @@ MODULE_LICENSE("GPL");
57 * In that case max_cstate would be n-1 57 * In that case max_cstate would be n-1
58 * GTHS returning '0' would mean that no bandwidth control states are supported 58 * GTHS returning '0' would mean that no bandwidth control states are supported
59 */ 59 */
60static int memory_get_int_max_bandwidth(struct thermal_cooling_device *cdev, 60static int memory_get_max_bandwidth(struct thermal_cooling_device *cdev,
61 unsigned long *max_state) 61 unsigned long *max_state)
62{ 62{
63 struct acpi_device *device = cdev->devdata; 63 struct acpi_device *device = cdev->devdata;
64 acpi_handle handle = device->handle; 64 acpi_handle handle = device->handle;
@@ -83,22 +83,12 @@ static int memory_get_int_max_bandwidth(struct thermal_cooling_device *cdev,
83 return 0; 83 return 0;
84} 84}
85 85
86static int memory_get_max_bandwidth(struct thermal_cooling_device *cdev,
87 char *buf)
88{
89 unsigned long value;
90 if (memory_get_int_max_bandwidth(cdev, &value))
91 return -EINVAL;
92
93 return sprintf(buf, "%ld\n", value);
94}
95
96static int memory_get_cur_bandwidth(struct thermal_cooling_device *cdev, 86static int memory_get_cur_bandwidth(struct thermal_cooling_device *cdev,
97 char *buf) 87 unsigned long *value)
98{ 88{
99 struct acpi_device *device = cdev->devdata; 89 struct acpi_device *device = cdev->devdata;
100 acpi_handle handle = device->handle; 90 acpi_handle handle = device->handle;
101 unsigned long long value; 91 unsigned long long result;
102 struct acpi_object_list arg_list; 92 struct acpi_object_list arg_list;
103 union acpi_object arg; 93 union acpi_object arg;
104 acpi_status status = AE_OK; 94 acpi_status status = AE_OK;
@@ -108,15 +98,16 @@ static int memory_get_cur_bandwidth(struct thermal_cooling_device *cdev,
108 arg.type = ACPI_TYPE_INTEGER; 98 arg.type = ACPI_TYPE_INTEGER;
109 arg.integer.value = MEMORY_ARG_CUR_BANDWIDTH; 99 arg.integer.value = MEMORY_ARG_CUR_BANDWIDTH;
110 status = acpi_evaluate_integer(handle, MEMORY_GET_BANDWIDTH, 100 status = acpi_evaluate_integer(handle, MEMORY_GET_BANDWIDTH,
111 &arg_list, &value); 101 &arg_list, &result);
112 if (ACPI_FAILURE(status)) 102 if (ACPI_FAILURE(status))
113 return -EFAULT; 103 return -EFAULT;
114 104
115 return sprintf(buf, "%llu\n", value); 105 *value = result;
106 return 0;
116} 107}
117 108
118static int memory_set_cur_bandwidth(struct thermal_cooling_device *cdev, 109static int memory_set_cur_bandwidth(struct thermal_cooling_device *cdev,
119 unsigned int state) 110 unsigned long state)
120{ 111{
121 struct acpi_device *device = cdev->devdata; 112 struct acpi_device *device = cdev->devdata;
122 acpi_handle handle = device->handle; 113 acpi_handle handle = device->handle;
@@ -126,7 +117,7 @@ static int memory_set_cur_bandwidth(struct thermal_cooling_device *cdev,
126 unsigned long long temp; 117 unsigned long long temp;
127 unsigned long max_state; 118 unsigned long max_state;
128 119
129 if (memory_get_int_max_bandwidth(cdev, &max_state)) 120 if (memory_get_max_bandwidth(cdev, &max_state))
130 return -EFAULT; 121 return -EFAULT;
131 122
132 if (state > max_state) 123 if (state > max_state)
@@ -142,7 +133,7 @@ static int memory_set_cur_bandwidth(struct thermal_cooling_device *cdev,
142 &temp); 133 &temp);
143 134
144 printk(KERN_INFO 135 printk(KERN_INFO
145 "Bandwidth value was %d: status is %d\n", state, status); 136 "Bandwidth value was %ld: status is %d\n", state, status);
146 if (ACPI_FAILURE(status)) 137 if (ACPI_FAILURE(status))
147 return -EFAULT; 138 return -EFAULT;
148 139
diff --git a/drivers/thermal/thermal_sys.c b/drivers/thermal/thermal_sys.c
index 8171ca17b936..bd139adc6d32 100644
--- a/drivers/thermal/thermal_sys.c
+++ b/drivers/thermal/thermal_sys.c
@@ -104,22 +104,36 @@ static ssize_t
104temp_show(struct device *dev, struct device_attribute *attr, char *buf) 104temp_show(struct device *dev, struct device_attribute *attr, char *buf)
105{ 105{
106 struct thermal_zone_device *tz = to_thermal_zone(dev); 106 struct thermal_zone_device *tz = to_thermal_zone(dev);
107 long temperature;
108 int ret;
107 109
108 if (!tz->ops->get_temp) 110 if (!tz->ops->get_temp)
109 return -EPERM; 111 return -EPERM;
110 112
111 return tz->ops->get_temp(tz, buf); 113 ret = tz->ops->get_temp(tz, &temperature);
114
115 if (ret)
116 return ret;
117
118 return sprintf(buf, "%ld\n", temperature);
112} 119}
113 120
114static ssize_t 121static ssize_t
115mode_show(struct device *dev, struct device_attribute *attr, char *buf) 122mode_show(struct device *dev, struct device_attribute *attr, char *buf)
116{ 123{
117 struct thermal_zone_device *tz = to_thermal_zone(dev); 124 struct thermal_zone_device *tz = to_thermal_zone(dev);
125 enum thermal_device_mode mode;
126 int result;
118 127
119 if (!tz->ops->get_mode) 128 if (!tz->ops->get_mode)
120 return -EPERM; 129 return -EPERM;
121 130
122 return tz->ops->get_mode(tz, buf); 131 result = tz->ops->get_mode(tz, &mode);
132 if (result)
133 return result;
134
135 return sprintf(buf, "%s\n", mode == THERMAL_DEVICE_ENABLED ? "enabled"
136 : "disabled");
123} 137}
124 138
125static ssize_t 139static ssize_t
@@ -132,7 +146,13 @@ mode_store(struct device *dev, struct device_attribute *attr,
132 if (!tz->ops->set_mode) 146 if (!tz->ops->set_mode)
133 return -EPERM; 147 return -EPERM;
134 148
135 result = tz->ops->set_mode(tz, buf); 149 if (!strncmp(buf, "enabled", sizeof("enabled")))
150 result = tz->ops->set_mode(tz, THERMAL_DEVICE_ENABLED);
151 else if (!strncmp(buf, "disabled", sizeof("disabled")))
152 result = tz->ops->set_mode(tz, THERMAL_DEVICE_DISABLED);
153 else
154 result = -EINVAL;
155
136 if (result) 156 if (result)
137 return result; 157 return result;
138 158
@@ -144,7 +164,8 @@ trip_point_type_show(struct device *dev, struct device_attribute *attr,
144 char *buf) 164 char *buf)
145{ 165{
146 struct thermal_zone_device *tz = to_thermal_zone(dev); 166 struct thermal_zone_device *tz = to_thermal_zone(dev);
147 int trip; 167 enum thermal_trip_type type;
168 int trip, result;
148 169
149 if (!tz->ops->get_trip_type) 170 if (!tz->ops->get_trip_type)
150 return -EPERM; 171 return -EPERM;
@@ -152,7 +173,22 @@ trip_point_type_show(struct device *dev, struct device_attribute *attr,
152 if (!sscanf(attr->attr.name, "trip_point_%d_type", &trip)) 173 if (!sscanf(attr->attr.name, "trip_point_%d_type", &trip))
153 return -EINVAL; 174 return -EINVAL;
154 175
155 return tz->ops->get_trip_type(tz, trip, buf); 176 result = tz->ops->get_trip_type(tz, trip, &type);
177 if (result)
178 return result;
179
180 switch (type) {
181 case THERMAL_TRIP_CRITICAL:
182 return sprintf(buf, "critical");
183 case THERMAL_TRIP_HOT:
184 return sprintf(buf, "hot");
185 case THERMAL_TRIP_PASSIVE:
186 return sprintf(buf, "passive");
187 case THERMAL_TRIP_ACTIVE:
188 return sprintf(buf, "active");
189 default:
190 return sprintf(buf, "unknown");
191 }
156} 192}
157 193
158static ssize_t 194static ssize_t
@@ -160,7 +196,8 @@ trip_point_temp_show(struct device *dev, struct device_attribute *attr,
160 char *buf) 196 char *buf)
161{ 197{
162 struct thermal_zone_device *tz = to_thermal_zone(dev); 198 struct thermal_zone_device *tz = to_thermal_zone(dev);
163 int trip; 199 int trip, ret;
200 long temperature;
164 201
165 if (!tz->ops->get_trip_temp) 202 if (!tz->ops->get_trip_temp)
166 return -EPERM; 203 return -EPERM;
@@ -168,7 +205,12 @@ trip_point_temp_show(struct device *dev, struct device_attribute *attr,
168 if (!sscanf(attr->attr.name, "trip_point_%d_temp", &trip)) 205 if (!sscanf(attr->attr.name, "trip_point_%d_temp", &trip))
169 return -EINVAL; 206 return -EINVAL;
170 207
171 return tz->ops->get_trip_temp(tz, trip, buf); 208 ret = tz->ops->get_trip_temp(tz, trip, &temperature);
209
210 if (ret)
211 return ret;
212
213 return sprintf(buf, "%ld\n", temperature);
172} 214}
173 215
174static DEVICE_ATTR(type, 0444, type_show, NULL); 216static DEVICE_ATTR(type, 0444, type_show, NULL);
@@ -236,8 +278,13 @@ thermal_cooling_device_max_state_show(struct device *dev,
236 struct device_attribute *attr, char *buf) 278 struct device_attribute *attr, char *buf)
237{ 279{
238 struct thermal_cooling_device *cdev = to_cooling_device(dev); 280 struct thermal_cooling_device *cdev = to_cooling_device(dev);
281 unsigned long state;
282 int ret;
239 283
240 return cdev->ops->get_max_state(cdev, buf); 284 ret = cdev->ops->get_max_state(cdev, &state);
285 if (ret)
286 return ret;
287 return sprintf(buf, "%ld\n", state);
241} 288}
242 289
243static ssize_t 290static ssize_t
@@ -245,8 +292,13 @@ thermal_cooling_device_cur_state_show(struct device *dev,
245 struct device_attribute *attr, char *buf) 292 struct device_attribute *attr, char *buf)
246{ 293{
247 struct thermal_cooling_device *cdev = to_cooling_device(dev); 294 struct thermal_cooling_device *cdev = to_cooling_device(dev);
295 unsigned long state;
296 int ret;
248 297
249 return cdev->ops->get_cur_state(cdev, buf); 298 ret = cdev->ops->get_cur_state(cdev, &state);
299 if (ret)
300 return ret;
301 return sprintf(buf, "%ld\n", state);
250} 302}
251 303
252static ssize_t 304static ssize_t
@@ -255,10 +307,10 @@ thermal_cooling_device_cur_state_store(struct device *dev,
255 const char *buf, size_t count) 307 const char *buf, size_t count)
256{ 308{
257 struct thermal_cooling_device *cdev = to_cooling_device(dev); 309 struct thermal_cooling_device *cdev = to_cooling_device(dev);
258 int state; 310 unsigned long state;
259 int result; 311 int result;
260 312
261 if (!sscanf(buf, "%d\n", &state)) 313 if (!sscanf(buf, "%ld\n", &state))
262 return -EINVAL; 314 return -EINVAL;
263 315
264 if (state < 0) 316 if (state < 0)
@@ -312,13 +364,20 @@ static DEVICE_ATTR(name, 0444, name_show, NULL);
312static ssize_t 364static ssize_t
313temp_input_show(struct device *dev, struct device_attribute *attr, char *buf) 365temp_input_show(struct device *dev, struct device_attribute *attr, char *buf)
314{ 366{
367 long temperature;
368 int ret;
315 struct thermal_hwmon_attr *hwmon_attr 369 struct thermal_hwmon_attr *hwmon_attr
316 = container_of(attr, struct thermal_hwmon_attr, attr); 370 = container_of(attr, struct thermal_hwmon_attr, attr);
317 struct thermal_zone_device *tz 371 struct thermal_zone_device *tz
318 = container_of(hwmon_attr, struct thermal_zone_device, 372 = container_of(hwmon_attr, struct thermal_zone_device,
319 temp_input); 373 temp_input);
320 374
321 return tz->ops->get_temp(tz, buf); 375 ret = tz->ops->get_temp(tz, &temperature);
376
377 if (ret)
378 return ret;
379
380 return sprintf(buf, "%ld\n", temperature);
322} 381}
323 382
324static ssize_t 383static ssize_t
@@ -330,8 +389,14 @@ temp_crit_show(struct device *dev, struct device_attribute *attr,
330 struct thermal_zone_device *tz 389 struct thermal_zone_device *tz
331 = container_of(hwmon_attr, struct thermal_zone_device, 390 = container_of(hwmon_attr, struct thermal_zone_device,
332 temp_crit); 391 temp_crit);
392 long temperature;
393 int ret;
394
395 ret = tz->ops->get_trip_temp(tz, 0, &temperature);
396 if (ret)
397 return ret;
333 398
334 return tz->ops->get_trip_temp(tz, 0, buf); 399 return sprintf(buf, "%ld\n", temperature);
335} 400}
336 401
337 402
diff --git a/include/linux/thermal.h b/include/linux/thermal.h
index 917707e6151d..4cb3292fb6e4 100644
--- a/include/linux/thermal.h
+++ b/include/linux/thermal.h
@@ -31,23 +31,39 @@
31struct thermal_zone_device; 31struct thermal_zone_device;
32struct thermal_cooling_device; 32struct thermal_cooling_device;
33 33
34enum thermal_device_mode {
35 THERMAL_DEVICE_DISABLED = 0,
36 THERMAL_DEVICE_ENABLED,
37};
38
39enum thermal_trip_type {
40 THERMAL_TRIP_ACTIVE = 0,
41 THERMAL_TRIP_PASSIVE,
42 THERMAL_TRIP_HOT,
43 THERMAL_TRIP_CRITICAL,
44};
45
34struct thermal_zone_device_ops { 46struct thermal_zone_device_ops {
35 int (*bind) (struct thermal_zone_device *, 47 int (*bind) (struct thermal_zone_device *,
36 struct thermal_cooling_device *); 48 struct thermal_cooling_device *);
37 int (*unbind) (struct thermal_zone_device *, 49 int (*unbind) (struct thermal_zone_device *,
38 struct thermal_cooling_device *); 50 struct thermal_cooling_device *);
39 int (*get_temp) (struct thermal_zone_device *, char *); 51 int (*get_temp) (struct thermal_zone_device *, unsigned long *);
40 int (*get_mode) (struct thermal_zone_device *, char *); 52 int (*get_mode) (struct thermal_zone_device *,
41 int (*set_mode) (struct thermal_zone_device *, const char *); 53 enum thermal_device_mode *);
42 int (*get_trip_type) (struct thermal_zone_device *, int, char *); 54 int (*set_mode) (struct thermal_zone_device *,
43 int (*get_trip_temp) (struct thermal_zone_device *, int, char *); 55 enum thermal_device_mode);
56 int (*get_trip_type) (struct thermal_zone_device *, int,
57 enum thermal_trip_type *);
58 int (*get_trip_temp) (struct thermal_zone_device *, int,
59 unsigned long *);
44 int (*get_crit_temp) (struct thermal_zone_device *, unsigned long *); 60 int (*get_crit_temp) (struct thermal_zone_device *, unsigned long *);
45}; 61};
46 62
47struct thermal_cooling_device_ops { 63struct thermal_cooling_device_ops {
48 int (*get_max_state) (struct thermal_cooling_device *, char *); 64 int (*get_max_state) (struct thermal_cooling_device *, unsigned long *);
49 int (*get_cur_state) (struct thermal_cooling_device *, char *); 65 int (*get_cur_state) (struct thermal_cooling_device *, unsigned long *);
50 int (*set_cur_state) (struct thermal_cooling_device *, unsigned int); 66 int (*set_cur_state) (struct thermal_cooling_device *, unsigned long);
51}; 67};
52 68
53#define THERMAL_TRIPS_NONE -1 69#define THERMAL_TRIPS_NONE -1