diff options
author | Jean Delvare <khali@linux-fr.org> | 2008-01-03 17:21:07 -0500 |
---|---|---|
committer | Mark M. Hoffman <mhoffman@lightlink.com> | 2008-02-07 20:39:44 -0500 |
commit | fad33c5fdae73a75af2f8ecf69147011bd57e28c (patch) | |
tree | 29adf7adb4d1a3cb5ec0d3f91b9d556c7e58d803 /drivers/hwmon | |
parent | af221931519571028c98cf7c7030dd973a524011 (diff) |
hwmon: (asb100) De-macro the sysfs callbacks
Use standard dynamic sysfs callbacks instead of macro-generated
wrappers. This makes the code more readable, and the binary smaller
(by about 12%).
Signed-off-by: Jean Delvare <khali@linux-fr.org>
Acked-by: Hans de Goede <j.w.r.degoede@hhs.nl>
Signed-off-by: Mark M. Hoffman <mhoffman@lightlink.com>
Diffstat (limited to 'drivers/hwmon')
-rw-r--r-- | drivers/hwmon/asb100.c | 233 |
1 files changed, 90 insertions, 143 deletions
diff --git a/drivers/hwmon/asb100.c b/drivers/hwmon/asb100.c index db86bc113905..407c86c20ecb 100644 --- a/drivers/hwmon/asb100.c +++ b/drivers/hwmon/asb100.c | |||
@@ -40,6 +40,7 @@ | |||
40 | #include <linux/slab.h> | 40 | #include <linux/slab.h> |
41 | #include <linux/i2c.h> | 41 | #include <linux/i2c.h> |
42 | #include <linux/hwmon.h> | 42 | #include <linux/hwmon.h> |
43 | #include <linux/hwmon-sysfs.h> | ||
43 | #include <linux/hwmon-vid.h> | 44 | #include <linux/hwmon-vid.h> |
44 | #include <linux/err.h> | 45 | #include <linux/err.h> |
45 | #include <linux/init.h> | 46 | #include <linux/init.h> |
@@ -221,8 +222,10 @@ static struct i2c_driver asb100_driver = { | |||
221 | 222 | ||
222 | /* 7 Voltages */ | 223 | /* 7 Voltages */ |
223 | #define show_in_reg(reg) \ | 224 | #define show_in_reg(reg) \ |
224 | static ssize_t show_##reg (struct device *dev, char *buf, int nr) \ | 225 | static ssize_t show_##reg(struct device *dev, struct device_attribute *attr, \ |
226 | char *buf) \ | ||
225 | { \ | 227 | { \ |
228 | int nr = to_sensor_dev_attr(attr)->index; \ | ||
226 | struct asb100_data *data = asb100_update_device(dev); \ | 229 | struct asb100_data *data = asb100_update_device(dev); \ |
227 | return sprintf(buf, "%d\n", IN_FROM_REG(data->reg[nr])); \ | 230 | return sprintf(buf, "%d\n", IN_FROM_REG(data->reg[nr])); \ |
228 | } | 231 | } |
@@ -232,9 +235,10 @@ show_in_reg(in_min) | |||
232 | show_in_reg(in_max) | 235 | show_in_reg(in_max) |
233 | 236 | ||
234 | #define set_in_reg(REG, reg) \ | 237 | #define set_in_reg(REG, reg) \ |
235 | static ssize_t set_in_##reg(struct device *dev, const char *buf, \ | 238 | static ssize_t set_in_##reg(struct device *dev, struct device_attribute *attr, \ |
236 | size_t count, int nr) \ | 239 | const char *buf, size_t count) \ |
237 | { \ | 240 | { \ |
241 | int nr = to_sensor_dev_attr(attr)->index; \ | ||
238 | struct i2c_client *client = to_i2c_client(dev); \ | 242 | struct i2c_client *client = to_i2c_client(dev); \ |
239 | struct asb100_data *data = i2c_get_clientdata(client); \ | 243 | struct asb100_data *data = i2c_get_clientdata(client); \ |
240 | unsigned long val = simple_strtoul(buf, NULL, 10); \ | 244 | unsigned long val = simple_strtoul(buf, NULL, 10); \ |
@@ -251,37 +255,12 @@ set_in_reg(MIN, min) | |||
251 | set_in_reg(MAX, max) | 255 | set_in_reg(MAX, max) |
252 | 256 | ||
253 | #define sysfs_in(offset) \ | 257 | #define sysfs_in(offset) \ |
254 | static ssize_t \ | 258 | static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, \ |
255 | show_in##offset (struct device *dev, struct device_attribute *attr, char *buf) \ | 259 | show_in, NULL, offset); \ |
256 | { \ | 260 | static SENSOR_DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \ |
257 | return show_in(dev, buf, offset); \ | 261 | show_in_min, set_in_min, offset); \ |
258 | } \ | 262 | static SENSOR_DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \ |
259 | static DEVICE_ATTR(in##offset##_input, S_IRUGO, \ | 263 | show_in_max, set_in_max, offset) |
260 | show_in##offset, NULL); \ | ||
261 | static ssize_t \ | ||
262 | show_in##offset##_min (struct device *dev, struct device_attribute *attr, char *buf) \ | ||
263 | { \ | ||
264 | return show_in_min(dev, buf, offset); \ | ||
265 | } \ | ||
266 | static ssize_t \ | ||
267 | show_in##offset##_max (struct device *dev, struct device_attribute *attr, char *buf) \ | ||
268 | { \ | ||
269 | return show_in_max(dev, buf, offset); \ | ||
270 | } \ | ||
271 | static ssize_t set_in##offset##_min (struct device *dev, struct device_attribute *attr, \ | ||
272 | const char *buf, size_t count) \ | ||
273 | { \ | ||
274 | return set_in_min(dev, buf, count, offset); \ | ||
275 | } \ | ||
276 | static ssize_t set_in##offset##_max (struct device *dev, struct device_attribute *attr, \ | ||
277 | const char *buf, size_t count) \ | ||
278 | { \ | ||
279 | return set_in_max(dev, buf, count, offset); \ | ||
280 | } \ | ||
281 | static DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \ | ||
282 | show_in##offset##_min, set_in##offset##_min); \ | ||
283 | static DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \ | ||
284 | show_in##offset##_max, set_in##offset##_max); | ||
285 | 264 | ||
286 | sysfs_in(0); | 265 | sysfs_in(0); |
287 | sysfs_in(1); | 266 | sysfs_in(1); |
@@ -292,29 +271,36 @@ sysfs_in(5); | |||
292 | sysfs_in(6); | 271 | sysfs_in(6); |
293 | 272 | ||
294 | /* 3 Fans */ | 273 | /* 3 Fans */ |
295 | static ssize_t show_fan(struct device *dev, char *buf, int nr) | 274 | static ssize_t show_fan(struct device *dev, struct device_attribute *attr, |
275 | char *buf) | ||
296 | { | 276 | { |
277 | int nr = to_sensor_dev_attr(attr)->index; | ||
297 | struct asb100_data *data = asb100_update_device(dev); | 278 | struct asb100_data *data = asb100_update_device(dev); |
298 | return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[nr], | 279 | return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[nr], |
299 | DIV_FROM_REG(data->fan_div[nr]))); | 280 | DIV_FROM_REG(data->fan_div[nr]))); |
300 | } | 281 | } |
301 | 282 | ||
302 | static ssize_t show_fan_min(struct device *dev, char *buf, int nr) | 283 | static ssize_t show_fan_min(struct device *dev, struct device_attribute *attr, |
284 | char *buf) | ||
303 | { | 285 | { |
286 | int nr = to_sensor_dev_attr(attr)->index; | ||
304 | struct asb100_data *data = asb100_update_device(dev); | 287 | struct asb100_data *data = asb100_update_device(dev); |
305 | return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan_min[nr], | 288 | return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan_min[nr], |
306 | DIV_FROM_REG(data->fan_div[nr]))); | 289 | DIV_FROM_REG(data->fan_div[nr]))); |
307 | } | 290 | } |
308 | 291 | ||
309 | static ssize_t show_fan_div(struct device *dev, char *buf, int nr) | 292 | static ssize_t show_fan_div(struct device *dev, struct device_attribute *attr, |
293 | char *buf) | ||
310 | { | 294 | { |
295 | int nr = to_sensor_dev_attr(attr)->index; | ||
311 | struct asb100_data *data = asb100_update_device(dev); | 296 | struct asb100_data *data = asb100_update_device(dev); |
312 | return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr])); | 297 | return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr])); |
313 | } | 298 | } |
314 | 299 | ||
315 | static ssize_t set_fan_min(struct device *dev, const char *buf, | 300 | static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr, |
316 | size_t count, int nr) | 301 | const char *buf, size_t count) |
317 | { | 302 | { |
303 | int nr = to_sensor_dev_attr(attr)->index; | ||
318 | struct i2c_client *client = to_i2c_client(dev); | 304 | struct i2c_client *client = to_i2c_client(dev); |
319 | struct asb100_data *data = i2c_get_clientdata(client); | 305 | struct asb100_data *data = i2c_get_clientdata(client); |
320 | u32 val = simple_strtoul(buf, NULL, 10); | 306 | u32 val = simple_strtoul(buf, NULL, 10); |
@@ -330,9 +316,10 @@ static ssize_t set_fan_min(struct device *dev, const char *buf, | |||
330 | determined in part by the fan divisor. This follows the principle of | 316 | determined in part by the fan divisor. This follows the principle of |
331 | least surprise; the user doesn't expect the fan minimum to change just | 317 | least surprise; the user doesn't expect the fan minimum to change just |
332 | because the divisor changed. */ | 318 | because the divisor changed. */ |
333 | static ssize_t set_fan_div(struct device *dev, const char *buf, | 319 | static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr, |
334 | size_t count, int nr) | 320 | const char *buf, size_t count) |
335 | { | 321 | { |
322 | int nr = to_sensor_dev_attr(attr)->index; | ||
336 | struct i2c_client *client = to_i2c_client(dev); | 323 | struct i2c_client *client = to_i2c_client(dev); |
337 | struct asb100_data *data = i2c_get_clientdata(client); | 324 | struct asb100_data *data = i2c_get_clientdata(client); |
338 | unsigned long min; | 325 | unsigned long min; |
@@ -375,34 +362,12 @@ static ssize_t set_fan_div(struct device *dev, const char *buf, | |||
375 | } | 362 | } |
376 | 363 | ||
377 | #define sysfs_fan(offset) \ | 364 | #define sysfs_fan(offset) \ |
378 | static ssize_t show_fan##offset(struct device *dev, struct device_attribute *attr, char *buf) \ | 365 | static SENSOR_DEVICE_ATTR(fan##offset##_input, S_IRUGO, \ |
379 | { \ | 366 | show_fan, NULL, offset - 1); \ |
380 | return show_fan(dev, buf, offset - 1); \ | 367 | static SENSOR_DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \ |
381 | } \ | 368 | show_fan_min, set_fan_min, offset - 1); \ |
382 | static ssize_t show_fan##offset##_min(struct device *dev, struct device_attribute *attr, char *buf) \ | 369 | static SENSOR_DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \ |
383 | { \ | 370 | show_fan_div, set_fan_div, offset - 1) |
384 | return show_fan_min(dev, buf, offset - 1); \ | ||
385 | } \ | ||
386 | static ssize_t show_fan##offset##_div(struct device *dev, struct device_attribute *attr, char *buf) \ | ||
387 | { \ | ||
388 | return show_fan_div(dev, buf, offset - 1); \ | ||
389 | } \ | ||
390 | static ssize_t set_fan##offset##_min(struct device *dev, struct device_attribute *attr, const char *buf, \ | ||
391 | size_t count) \ | ||
392 | { \ | ||
393 | return set_fan_min(dev, buf, count, offset - 1); \ | ||
394 | } \ | ||
395 | static ssize_t set_fan##offset##_div(struct device *dev, struct device_attribute *attr, const char *buf, \ | ||
396 | size_t count) \ | ||
397 | { \ | ||
398 | return set_fan_div(dev, buf, count, offset - 1); \ | ||
399 | } \ | ||
400 | static DEVICE_ATTR(fan##offset##_input, S_IRUGO, \ | ||
401 | show_fan##offset, NULL); \ | ||
402 | static DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \ | ||
403 | show_fan##offset##_min, set_fan##offset##_min); \ | ||
404 | static DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \ | ||
405 | show_fan##offset##_div, set_fan##offset##_div); | ||
406 | 371 | ||
407 | sysfs_fan(1); | 372 | sysfs_fan(1); |
408 | sysfs_fan(2); | 373 | sysfs_fan(2); |
@@ -425,8 +390,10 @@ static int sprintf_temp_from_reg(u16 reg, char *buf, int nr) | |||
425 | } | 390 | } |
426 | 391 | ||
427 | #define show_temp_reg(reg) \ | 392 | #define show_temp_reg(reg) \ |
428 | static ssize_t show_##reg(struct device *dev, char *buf, int nr) \ | 393 | static ssize_t show_##reg(struct device *dev, struct device_attribute *attr, \ |
394 | char *buf) \ | ||
429 | { \ | 395 | { \ |
396 | int nr = to_sensor_dev_attr(attr)->index; \ | ||
430 | struct asb100_data *data = asb100_update_device(dev); \ | 397 | struct asb100_data *data = asb100_update_device(dev); \ |
431 | return sprintf_temp_from_reg(data->reg[nr], buf, nr); \ | 398 | return sprintf_temp_from_reg(data->reg[nr], buf, nr); \ |
432 | } | 399 | } |
@@ -436,9 +403,10 @@ show_temp_reg(temp_max); | |||
436 | show_temp_reg(temp_hyst); | 403 | show_temp_reg(temp_hyst); |
437 | 404 | ||
438 | #define set_temp_reg(REG, reg) \ | 405 | #define set_temp_reg(REG, reg) \ |
439 | static ssize_t set_##reg(struct device *dev, const char *buf, \ | 406 | static ssize_t set_##reg(struct device *dev, struct device_attribute *attr, \ |
440 | size_t count, int nr) \ | 407 | const char *buf, size_t count) \ |
441 | { \ | 408 | { \ |
409 | int nr = to_sensor_dev_attr(attr)->index; \ | ||
442 | struct i2c_client *client = to_i2c_client(dev); \ | 410 | struct i2c_client *client = to_i2c_client(dev); \ |
443 | struct asb100_data *data = i2c_get_clientdata(client); \ | 411 | struct asb100_data *data = i2c_get_clientdata(client); \ |
444 | long val = simple_strtol(buf, NULL, 10); \ | 412 | long val = simple_strtol(buf, NULL, 10); \ |
@@ -462,33 +430,12 @@ set_temp_reg(MAX, temp_max); | |||
462 | set_temp_reg(HYST, temp_hyst); | 430 | set_temp_reg(HYST, temp_hyst); |
463 | 431 | ||
464 | #define sysfs_temp(num) \ | 432 | #define sysfs_temp(num) \ |
465 | static ssize_t show_temp##num(struct device *dev, struct device_attribute *attr, char *buf) \ | 433 | static SENSOR_DEVICE_ATTR(temp##num##_input, S_IRUGO, \ |
466 | { \ | 434 | show_temp, NULL, num - 1); \ |
467 | return show_temp(dev, buf, num-1); \ | 435 | static SENSOR_DEVICE_ATTR(temp##num##_max, S_IRUGO | S_IWUSR, \ |
468 | } \ | 436 | show_temp_max, set_temp_max, num - 1); \ |
469 | static DEVICE_ATTR(temp##num##_input, S_IRUGO, show_temp##num, NULL); \ | 437 | static SENSOR_DEVICE_ATTR(temp##num##_max_hyst, S_IRUGO | S_IWUSR, \ |
470 | static ssize_t show_temp_max##num(struct device *dev, struct device_attribute *attr, char *buf) \ | 438 | show_temp_hyst, set_temp_hyst, num - 1) |
471 | { \ | ||
472 | return show_temp_max(dev, buf, num-1); \ | ||
473 | } \ | ||
474 | static ssize_t set_temp_max##num(struct device *dev, struct device_attribute *attr, const char *buf, \ | ||
475 | size_t count) \ | ||
476 | { \ | ||
477 | return set_temp_max(dev, buf, count, num-1); \ | ||
478 | } \ | ||
479 | static DEVICE_ATTR(temp##num##_max, S_IRUGO | S_IWUSR, \ | ||
480 | show_temp_max##num, set_temp_max##num); \ | ||
481 | static ssize_t show_temp_hyst##num(struct device *dev, struct device_attribute *attr, char *buf) \ | ||
482 | { \ | ||
483 | return show_temp_hyst(dev, buf, num-1); \ | ||
484 | } \ | ||
485 | static ssize_t set_temp_hyst##num(struct device *dev, struct device_attribute *attr, const char *buf, \ | ||
486 | size_t count) \ | ||
487 | { \ | ||
488 | return set_temp_hyst(dev, buf, count, num-1); \ | ||
489 | } \ | ||
490 | static DEVICE_ATTR(temp##num##_max_hyst, S_IRUGO | S_IWUSR, \ | ||
491 | show_temp_hyst##num, set_temp_hyst##num); | ||
492 | 439 | ||
493 | sysfs_temp(1); | 440 | sysfs_temp(1); |
494 | sysfs_temp(2); | 441 | sysfs_temp(2); |
@@ -583,50 +530,50 @@ static DEVICE_ATTR(pwm1_enable, S_IRUGO | S_IWUSR, | |||
583 | show_pwm_enable1, set_pwm_enable1); | 530 | show_pwm_enable1, set_pwm_enable1); |
584 | 531 | ||
585 | static struct attribute *asb100_attributes[] = { | 532 | static struct attribute *asb100_attributes[] = { |
586 | &dev_attr_in0_input.attr, | 533 | &sensor_dev_attr_in0_input.dev_attr.attr, |
587 | &dev_attr_in0_min.attr, | 534 | &sensor_dev_attr_in0_min.dev_attr.attr, |
588 | &dev_attr_in0_max.attr, | 535 | &sensor_dev_attr_in0_max.dev_attr.attr, |
589 | &dev_attr_in1_input.attr, | 536 | &sensor_dev_attr_in1_input.dev_attr.attr, |
590 | &dev_attr_in1_min.attr, | 537 | &sensor_dev_attr_in1_min.dev_attr.attr, |
591 | &dev_attr_in1_max.attr, | 538 | &sensor_dev_attr_in1_max.dev_attr.attr, |
592 | &dev_attr_in2_input.attr, | 539 | &sensor_dev_attr_in2_input.dev_attr.attr, |
593 | &dev_attr_in2_min.attr, | 540 | &sensor_dev_attr_in2_min.dev_attr.attr, |
594 | &dev_attr_in2_max.attr, | 541 | &sensor_dev_attr_in2_max.dev_attr.attr, |
595 | &dev_attr_in3_input.attr, | 542 | &sensor_dev_attr_in3_input.dev_attr.attr, |
596 | &dev_attr_in3_min.attr, | 543 | &sensor_dev_attr_in3_min.dev_attr.attr, |
597 | &dev_attr_in3_max.attr, | 544 | &sensor_dev_attr_in3_max.dev_attr.attr, |
598 | &dev_attr_in4_input.attr, | 545 | &sensor_dev_attr_in4_input.dev_attr.attr, |
599 | &dev_attr_in4_min.attr, | 546 | &sensor_dev_attr_in4_min.dev_attr.attr, |
600 | &dev_attr_in4_max.attr, | 547 | &sensor_dev_attr_in4_max.dev_attr.attr, |
601 | &dev_attr_in5_input.attr, | 548 | &sensor_dev_attr_in5_input.dev_attr.attr, |
602 | &dev_attr_in5_min.attr, | 549 | &sensor_dev_attr_in5_min.dev_attr.attr, |
603 | &dev_attr_in5_max.attr, | 550 | &sensor_dev_attr_in5_max.dev_attr.attr, |
604 | &dev_attr_in6_input.attr, | 551 | &sensor_dev_attr_in6_input.dev_attr.attr, |
605 | &dev_attr_in6_min.attr, | 552 | &sensor_dev_attr_in6_min.dev_attr.attr, |
606 | &dev_attr_in6_max.attr, | 553 | &sensor_dev_attr_in6_max.dev_attr.attr, |
607 | 554 | ||
608 | &dev_attr_fan1_input.attr, | 555 | &sensor_dev_attr_fan1_input.dev_attr.attr, |
609 | &dev_attr_fan1_min.attr, | 556 | &sensor_dev_attr_fan1_min.dev_attr.attr, |
610 | &dev_attr_fan1_div.attr, | 557 | &sensor_dev_attr_fan1_div.dev_attr.attr, |
611 | &dev_attr_fan2_input.attr, | 558 | &sensor_dev_attr_fan2_input.dev_attr.attr, |
612 | &dev_attr_fan2_min.attr, | 559 | &sensor_dev_attr_fan2_min.dev_attr.attr, |
613 | &dev_attr_fan2_div.attr, | 560 | &sensor_dev_attr_fan2_div.dev_attr.attr, |
614 | &dev_attr_fan3_input.attr, | 561 | &sensor_dev_attr_fan3_input.dev_attr.attr, |
615 | &dev_attr_fan3_min.attr, | 562 | &sensor_dev_attr_fan3_min.dev_attr.attr, |
616 | &dev_attr_fan3_div.attr, | 563 | &sensor_dev_attr_fan3_div.dev_attr.attr, |
617 | 564 | ||
618 | &dev_attr_temp1_input.attr, | 565 | &sensor_dev_attr_temp1_input.dev_attr.attr, |
619 | &dev_attr_temp1_max.attr, | 566 | &sensor_dev_attr_temp1_max.dev_attr.attr, |
620 | &dev_attr_temp1_max_hyst.attr, | 567 | &sensor_dev_attr_temp1_max_hyst.dev_attr.attr, |
621 | &dev_attr_temp2_input.attr, | 568 | &sensor_dev_attr_temp2_input.dev_attr.attr, |
622 | &dev_attr_temp2_max.attr, | 569 | &sensor_dev_attr_temp2_max.dev_attr.attr, |
623 | &dev_attr_temp2_max_hyst.attr, | 570 | &sensor_dev_attr_temp2_max_hyst.dev_attr.attr, |
624 | &dev_attr_temp3_input.attr, | 571 | &sensor_dev_attr_temp3_input.dev_attr.attr, |
625 | &dev_attr_temp3_max.attr, | 572 | &sensor_dev_attr_temp3_max.dev_attr.attr, |
626 | &dev_attr_temp3_max_hyst.attr, | 573 | &sensor_dev_attr_temp3_max_hyst.dev_attr.attr, |
627 | &dev_attr_temp4_input.attr, | 574 | &sensor_dev_attr_temp4_input.dev_attr.attr, |
628 | &dev_attr_temp4_max.attr, | 575 | &sensor_dev_attr_temp4_max.dev_attr.attr, |
629 | &dev_attr_temp4_max_hyst.attr, | 576 | &sensor_dev_attr_temp4_max_hyst.dev_attr.attr, |
630 | 577 | ||
631 | &dev_attr_cpu0_vid.attr, | 578 | &dev_attr_cpu0_vid.attr, |
632 | &dev_attr_vrm.attr, | 579 | &dev_attr_vrm.attr, |