aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon
diff options
context:
space:
mode:
authorJean Delvare <khali@linux-fr.org>2007-05-08 11:22:01 -0400
committerJean Delvare <khali@hyperion.delvare>2007-05-08 11:22:01 -0400
commit247dde4cdded4e4c332622b7c2860254e61cf5ce (patch)
tree8bb25911861d6446aa0b29ef38347637499c52ff /drivers/hwmon
parentc59cc301ee4589b096d2364af7cf91a2e46b5b1d (diff)
hwmon/lm78: Use dynamic sysfs callbacks
This lets us get rid of macro-generated functions and shrinks the driver size significantly (about 10%). Signed-off-by: Jean Delvare <khali@linux-fr.org>
Diffstat (limited to 'drivers/hwmon')
-rw-r--r--drivers/hwmon/lm78.c225
1 files changed, 101 insertions, 124 deletions
diff --git a/drivers/hwmon/lm78.c b/drivers/hwmon/lm78.c
index cc68c85e1561..9fb572f03ba5 100644
--- a/drivers/hwmon/lm78.c
+++ b/drivers/hwmon/lm78.c
@@ -28,6 +28,7 @@
28#include <linux/ioport.h> 28#include <linux/ioport.h>
29#include <linux/hwmon.h> 29#include <linux/hwmon.h>
30#include <linux/hwmon-vid.h> 30#include <linux/hwmon-vid.h>
31#include <linux/hwmon-sysfs.h>
31#include <linux/err.h> 32#include <linux/err.h>
32#include <linux/mutex.h> 33#include <linux/mutex.h>
33#include <asm/io.h> 34#include <asm/io.h>
@@ -185,29 +186,37 @@ static struct platform_driver lm78_isa_driver = {
185 186
186 187
187/* 7 Voltages */ 188/* 7 Voltages */
188static ssize_t show_in(struct device *dev, char *buf, int nr) 189static ssize_t show_in(struct device *dev, struct device_attribute *da,
190 char *buf)
189{ 191{
192 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
190 struct lm78_data *data = lm78_update_device(dev); 193 struct lm78_data *data = lm78_update_device(dev);
191 return sprintf(buf, "%d\n", IN_FROM_REG(data->in[nr])); 194 return sprintf(buf, "%d\n", IN_FROM_REG(data->in[attr->index]));
192} 195}
193 196
194static ssize_t show_in_min(struct device *dev, char *buf, int nr) 197static ssize_t show_in_min(struct device *dev, struct device_attribute *da,
198 char *buf)
195{ 199{
200 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
196 struct lm78_data *data = lm78_update_device(dev); 201 struct lm78_data *data = lm78_update_device(dev);
197 return sprintf(buf, "%d\n", IN_FROM_REG(data->in_min[nr])); 202 return sprintf(buf, "%d\n", IN_FROM_REG(data->in_min[attr->index]));
198} 203}
199 204
200static ssize_t show_in_max(struct device *dev, char *buf, int nr) 205static ssize_t show_in_max(struct device *dev, struct device_attribute *da,
206 char *buf)
201{ 207{
208 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
202 struct lm78_data *data = lm78_update_device(dev); 209 struct lm78_data *data = lm78_update_device(dev);
203 return sprintf(buf, "%d\n", IN_FROM_REG(data->in_max[nr])); 210 return sprintf(buf, "%d\n", IN_FROM_REG(data->in_max[attr->index]));
204} 211}
205 212
206static ssize_t set_in_min(struct device *dev, const char *buf, 213static ssize_t set_in_min(struct device *dev, struct device_attribute *da,
207 size_t count, int nr) 214 const char *buf, size_t count)
208{ 215{
216 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
209 struct lm78_data *data = dev_get_drvdata(dev); 217 struct lm78_data *data = dev_get_drvdata(dev);
210 unsigned long val = simple_strtoul(buf, NULL, 10); 218 unsigned long val = simple_strtoul(buf, NULL, 10);
219 int nr = attr->index;
211 220
212 mutex_lock(&data->update_lock); 221 mutex_lock(&data->update_lock);
213 data->in_min[nr] = IN_TO_REG(val); 222 data->in_min[nr] = IN_TO_REG(val);
@@ -216,11 +225,13 @@ static ssize_t set_in_min(struct device *dev, const char *buf,
216 return count; 225 return count;
217} 226}
218 227
219static ssize_t set_in_max(struct device *dev, const char *buf, 228static ssize_t set_in_max(struct device *dev, struct device_attribute *da,
220 size_t count, int nr) 229 const char *buf, size_t count)
221{ 230{
231 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
222 struct lm78_data *data = dev_get_drvdata(dev); 232 struct lm78_data *data = dev_get_drvdata(dev);
223 unsigned long val = simple_strtoul(buf, NULL, 10); 233 unsigned long val = simple_strtoul(buf, NULL, 10);
234 int nr = attr->index;
224 235
225 mutex_lock(&data->update_lock); 236 mutex_lock(&data->update_lock);
226 data->in_max[nr] = IN_TO_REG(val); 237 data->in_max[nr] = IN_TO_REG(val);
@@ -230,37 +241,12 @@ static ssize_t set_in_max(struct device *dev, const char *buf,
230} 241}
231 242
232#define show_in_offset(offset) \ 243#define show_in_offset(offset) \
233static ssize_t \ 244static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, \
234 show_in##offset (struct device *dev, struct device_attribute *attr, char *buf) \ 245 show_in, NULL, offset); \
235{ \ 246static SENSOR_DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \
236 return show_in(dev, buf, offset); \ 247 show_in_min, set_in_min, offset); \
237} \ 248static SENSOR_DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \
238static DEVICE_ATTR(in##offset##_input, S_IRUGO, \ 249 show_in_max, set_in_max, offset);
239 show_in##offset, NULL); \
240static ssize_t \
241 show_in##offset##_min (struct device *dev, struct device_attribute *attr, char *buf) \
242{ \
243 return show_in_min(dev, buf, offset); \
244} \
245static ssize_t \
246 show_in##offset##_max (struct device *dev, struct device_attribute *attr, char *buf) \
247{ \
248 return show_in_max(dev, buf, offset); \
249} \
250static ssize_t set_in##offset##_min (struct device *dev, struct device_attribute *attr, \
251 const char *buf, size_t count) \
252{ \
253 return set_in_min(dev, buf, count, offset); \
254} \
255static ssize_t set_in##offset##_max (struct device *dev, struct device_attribute *attr, \
256 const char *buf, size_t count) \
257{ \
258 return set_in_max(dev, buf, count, offset); \
259} \
260static DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \
261 show_in##offset##_min, set_in##offset##_min); \
262static DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \
263 show_in##offset##_max, set_in##offset##_max);
264 250
265show_in_offset(0); 251show_in_offset(0);
266show_in_offset(1); 252show_in_offset(1);
@@ -271,19 +257,22 @@ show_in_offset(5);
271show_in_offset(6); 257show_in_offset(6);
272 258
273/* Temperature */ 259/* Temperature */
274static ssize_t show_temp(struct device *dev, struct device_attribute *attr, char *buf) 260static ssize_t show_temp(struct device *dev, struct device_attribute *da,
261 char *buf)
275{ 262{
276 struct lm78_data *data = lm78_update_device(dev); 263 struct lm78_data *data = lm78_update_device(dev);
277 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp)); 264 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp));
278} 265}
279 266
280static ssize_t show_temp_over(struct device *dev, struct device_attribute *attr, char *buf) 267static ssize_t show_temp_over(struct device *dev, struct device_attribute *da,
268 char *buf)
281{ 269{
282 struct lm78_data *data = lm78_update_device(dev); 270 struct lm78_data *data = lm78_update_device(dev);
283 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_over)); 271 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_over));
284} 272}
285 273
286static ssize_t set_temp_over(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 274static ssize_t set_temp_over(struct device *dev, struct device_attribute *da,
275 const char *buf, size_t count)
287{ 276{
288 struct lm78_data *data = dev_get_drvdata(dev); 277 struct lm78_data *data = dev_get_drvdata(dev);
289 long val = simple_strtol(buf, NULL, 10); 278 long val = simple_strtol(buf, NULL, 10);
@@ -295,13 +284,15 @@ static ssize_t set_temp_over(struct device *dev, struct device_attribute *attr,
295 return count; 284 return count;
296} 285}
297 286
298static ssize_t show_temp_hyst(struct device *dev, struct device_attribute *attr, char *buf) 287static ssize_t show_temp_hyst(struct device *dev, struct device_attribute *da,
288 char *buf)
299{ 289{
300 struct lm78_data *data = lm78_update_device(dev); 290 struct lm78_data *data = lm78_update_device(dev);
301 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_hyst)); 291 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_hyst));
302} 292}
303 293
304static ssize_t set_temp_hyst(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 294static ssize_t set_temp_hyst(struct device *dev, struct device_attribute *da,
295 const char *buf, size_t count)
305{ 296{
306 struct lm78_data *data = dev_get_drvdata(dev); 297 struct lm78_data *data = dev_get_drvdata(dev);
307 long val = simple_strtol(buf, NULL, 10); 298 long val = simple_strtol(buf, NULL, 10);
@@ -320,24 +311,32 @@ static DEVICE_ATTR(temp1_max_hyst, S_IRUGO | S_IWUSR,
320 show_temp_hyst, set_temp_hyst); 311 show_temp_hyst, set_temp_hyst);
321 312
322/* 3 Fans */ 313/* 3 Fans */
323static ssize_t show_fan(struct device *dev, char *buf, int nr) 314static ssize_t show_fan(struct device *dev, struct device_attribute *da,
315 char *buf)
324{ 316{
317 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
325 struct lm78_data *data = lm78_update_device(dev); 318 struct lm78_data *data = lm78_update_device(dev);
319 int nr = attr->index;
326 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[nr], 320 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[nr],
327 DIV_FROM_REG(data->fan_div[nr])) ); 321 DIV_FROM_REG(data->fan_div[nr])) );
328} 322}
329 323
330static ssize_t show_fan_min(struct device *dev, char *buf, int nr) 324static ssize_t show_fan_min(struct device *dev, struct device_attribute *da,
325 char *buf)
331{ 326{
327 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
332 struct lm78_data *data = lm78_update_device(dev); 328 struct lm78_data *data = lm78_update_device(dev);
329 int nr = attr->index;
333 return sprintf(buf,"%d\n", FAN_FROM_REG(data->fan_min[nr], 330 return sprintf(buf,"%d\n", FAN_FROM_REG(data->fan_min[nr],
334 DIV_FROM_REG(data->fan_div[nr])) ); 331 DIV_FROM_REG(data->fan_div[nr])) );
335} 332}
336 333
337static ssize_t set_fan_min(struct device *dev, const char *buf, 334static ssize_t set_fan_min(struct device *dev, struct device_attribute *da,
338 size_t count, int nr) 335 const char *buf, size_t count)
339{ 336{
337 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
340 struct lm78_data *data = dev_get_drvdata(dev); 338 struct lm78_data *data = dev_get_drvdata(dev);
339 int nr = attr->index;
341 unsigned long val = simple_strtoul(buf, NULL, 10); 340 unsigned long val = simple_strtoul(buf, NULL, 10);
342 341
343 mutex_lock(&data->update_lock); 342 mutex_lock(&data->update_lock);
@@ -347,20 +346,24 @@ static ssize_t set_fan_min(struct device *dev, const char *buf,
347 return count; 346 return count;
348} 347}
349 348
350static ssize_t show_fan_div(struct device *dev, char *buf, int nr) 349static ssize_t show_fan_div(struct device *dev, struct device_attribute *da,
350 char *buf)
351{ 351{
352 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
352 struct lm78_data *data = lm78_update_device(dev); 353 struct lm78_data *data = lm78_update_device(dev);
353 return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr]) ); 354 return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[attr->index]));
354} 355}
355 356
356/* Note: we save and restore the fan minimum here, because its value is 357/* Note: we save and restore the fan minimum here, because its value is
357 determined in part by the fan divisor. This follows the principle of 358 determined in part by the fan divisor. This follows the principle of
358 least surprise; the user doesn't expect the fan minimum to change just 359 least surprise; the user doesn't expect the fan minimum to change just
359 because the divisor changed. */ 360 because the divisor changed. */
360static ssize_t set_fan_div(struct device *dev, const char *buf, 361static ssize_t set_fan_div(struct device *dev, struct device_attribute *da,
361 size_t count, int nr) 362 const char *buf, size_t count)
362{ 363{
364 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
363 struct lm78_data *data = dev_get_drvdata(dev); 365 struct lm78_data *data = dev_get_drvdata(dev);
366 int nr = attr->index;
364 unsigned long val = simple_strtoul(buf, NULL, 10); 367 unsigned long val = simple_strtoul(buf, NULL, 10);
365 unsigned long min; 368 unsigned long min;
366 u8 reg; 369 u8 reg;
@@ -400,53 +403,26 @@ static ssize_t set_fan_div(struct device *dev, const char *buf,
400 return count; 403 return count;
401} 404}
402 405
403#define show_fan_offset(offset) \ 406#define show_fan_offset(offset) \
404static ssize_t show_fan_##offset (struct device *dev, struct device_attribute *attr, char *buf) \ 407static SENSOR_DEVICE_ATTR(fan##offset##_input, S_IRUGO, \
405{ \ 408 show_fan, NULL, offset - 1); \
406 return show_fan(dev, buf, offset - 1); \ 409static SENSOR_DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
407} \ 410 show_fan_min, set_fan_min, offset - 1);
408static ssize_t show_fan_##offset##_min (struct device *dev, struct device_attribute *attr, char *buf) \
409{ \
410 return show_fan_min(dev, buf, offset - 1); \
411} \
412static ssize_t show_fan_##offset##_div (struct device *dev, struct device_attribute *attr, char *buf) \
413{ \
414 return show_fan_div(dev, buf, offset - 1); \
415} \
416static ssize_t set_fan_##offset##_min (struct device *dev, struct device_attribute *attr, \
417 const char *buf, size_t count) \
418{ \
419 return set_fan_min(dev, buf, count, offset - 1); \
420} \
421static DEVICE_ATTR(fan##offset##_input, S_IRUGO, show_fan_##offset, NULL);\
422static DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
423 show_fan_##offset##_min, set_fan_##offset##_min);
424
425static ssize_t set_fan_1_div(struct device *dev, struct device_attribute *attr, const char *buf,
426 size_t count)
427{
428 return set_fan_div(dev, buf, count, 0) ;
429}
430
431static ssize_t set_fan_2_div(struct device *dev, struct device_attribute *attr, const char *buf,
432 size_t count)
433{
434 return set_fan_div(dev, buf, count, 1) ;
435}
436 411
437show_fan_offset(1); 412show_fan_offset(1);
438show_fan_offset(2); 413show_fan_offset(2);
439show_fan_offset(3); 414show_fan_offset(3);
440 415
441/* Fan 3 divisor is locked in H/W */ 416/* Fan 3 divisor is locked in H/W */
442static DEVICE_ATTR(fan1_div, S_IRUGO | S_IWUSR, 417static SENSOR_DEVICE_ATTR(fan1_div, S_IRUGO | S_IWUSR,
443 show_fan_1_div, set_fan_1_div); 418 show_fan_div, set_fan_div, 0);
444static DEVICE_ATTR(fan2_div, S_IRUGO | S_IWUSR, 419static SENSOR_DEVICE_ATTR(fan2_div, S_IRUGO | S_IWUSR,
445 show_fan_2_div, set_fan_2_div); 420 show_fan_div, set_fan_div, 1);
446static DEVICE_ATTR(fan3_div, S_IRUGO, show_fan_3_div, NULL); 421static SENSOR_DEVICE_ATTR(fan3_div, S_IRUGO, show_fan_div, NULL, 2);
447 422
448/* VID */ 423/* VID */
449static ssize_t show_vid(struct device *dev, struct device_attribute *attr, char *buf) 424static ssize_t show_vid(struct device *dev, struct device_attribute *da,
425 char *buf)
450{ 426{
451 struct lm78_data *data = lm78_update_device(dev); 427 struct lm78_data *data = lm78_update_device(dev);
452 return sprintf(buf, "%d\n", vid_from_reg(data->vid, 82)); 428 return sprintf(buf, "%d\n", vid_from_reg(data->vid, 82));
@@ -454,7 +430,8 @@ static ssize_t show_vid(struct device *dev, struct device_attribute *attr, char
454static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid, NULL); 430static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid, NULL);
455 431
456/* Alarms */ 432/* Alarms */
457static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, char *buf) 433static ssize_t show_alarms(struct device *dev, struct device_attribute *da,
434 char *buf)
458{ 435{
459 struct lm78_data *data = lm78_update_device(dev); 436 struct lm78_data *data = lm78_update_device(dev);
460 return sprintf(buf, "%u\n", data->alarms); 437 return sprintf(buf, "%u\n", data->alarms);
@@ -473,39 +450,39 @@ static int lm78_attach_adapter(struct i2c_adapter *adapter)
473} 450}
474 451
475static struct attribute *lm78_attributes[] = { 452static struct attribute *lm78_attributes[] = {
476 &dev_attr_in0_input.attr, 453 &sensor_dev_attr_in0_input.dev_attr.attr,
477 &dev_attr_in0_min.attr, 454 &sensor_dev_attr_in0_min.dev_attr.attr,
478 &dev_attr_in0_max.attr, 455 &sensor_dev_attr_in0_max.dev_attr.attr,
479 &dev_attr_in1_input.attr, 456 &sensor_dev_attr_in1_input.dev_attr.attr,
480 &dev_attr_in1_min.attr, 457 &sensor_dev_attr_in1_min.dev_attr.attr,
481 &dev_attr_in1_max.attr, 458 &sensor_dev_attr_in1_max.dev_attr.attr,
482 &dev_attr_in2_input.attr, 459 &sensor_dev_attr_in2_input.dev_attr.attr,
483 &dev_attr_in2_min.attr, 460 &sensor_dev_attr_in2_min.dev_attr.attr,
484 &dev_attr_in2_max.attr, 461 &sensor_dev_attr_in2_max.dev_attr.attr,
485 &dev_attr_in3_input.attr, 462 &sensor_dev_attr_in3_input.dev_attr.attr,
486 &dev_attr_in3_min.attr, 463 &sensor_dev_attr_in3_min.dev_attr.attr,
487 &dev_attr_in3_max.attr, 464 &sensor_dev_attr_in3_max.dev_attr.attr,
488 &dev_attr_in4_input.attr, 465 &sensor_dev_attr_in4_input.dev_attr.attr,
489 &dev_attr_in4_min.attr, 466 &sensor_dev_attr_in4_min.dev_attr.attr,
490 &dev_attr_in4_max.attr, 467 &sensor_dev_attr_in4_max.dev_attr.attr,
491 &dev_attr_in5_input.attr, 468 &sensor_dev_attr_in5_input.dev_attr.attr,
492 &dev_attr_in5_min.attr, 469 &sensor_dev_attr_in5_min.dev_attr.attr,
493 &dev_attr_in5_max.attr, 470 &sensor_dev_attr_in5_max.dev_attr.attr,
494 &dev_attr_in6_input.attr, 471 &sensor_dev_attr_in6_input.dev_attr.attr,
495 &dev_attr_in6_min.attr, 472 &sensor_dev_attr_in6_min.dev_attr.attr,
496 &dev_attr_in6_max.attr, 473 &sensor_dev_attr_in6_max.dev_attr.attr,
497 &dev_attr_temp1_input.attr, 474 &dev_attr_temp1_input.attr,
498 &dev_attr_temp1_max.attr, 475 &dev_attr_temp1_max.attr,
499 &dev_attr_temp1_max_hyst.attr, 476 &dev_attr_temp1_max_hyst.attr,
500 &dev_attr_fan1_input.attr, 477 &sensor_dev_attr_fan1_input.dev_attr.attr,
501 &dev_attr_fan1_min.attr, 478 &sensor_dev_attr_fan1_min.dev_attr.attr,
502 &dev_attr_fan1_div.attr, 479 &sensor_dev_attr_fan1_div.dev_attr.attr,
503 &dev_attr_fan2_input.attr, 480 &sensor_dev_attr_fan2_input.dev_attr.attr,
504 &dev_attr_fan2_min.attr, 481 &sensor_dev_attr_fan2_min.dev_attr.attr,
505 &dev_attr_fan2_div.attr, 482 &sensor_dev_attr_fan2_div.dev_attr.attr,
506 &dev_attr_fan3_input.attr, 483 &sensor_dev_attr_fan3_input.dev_attr.attr,
507 &dev_attr_fan3_min.attr, 484 &sensor_dev_attr_fan3_min.dev_attr.attr,
508 &dev_attr_fan3_div.attr, 485 &sensor_dev_attr_fan3_div.dev_attr.attr,
509 &dev_attr_alarms.attr, 486 &dev_attr_alarms.attr,
510 &dev_attr_cpu0_vid.attr, 487 &dev_attr_cpu0_vid.attr,
511 488