aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/thermal/thermal_sys.c
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 /drivers/thermal/thermal_sys.c
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>
Diffstat (limited to 'drivers/thermal/thermal_sys.c')
-rw-r--r--drivers/thermal/thermal_sys.c91
1 files changed, 78 insertions, 13 deletions
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