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>

authored by Jean Delvare and committed by Mark M. Hoffman fad33c5f af221931

+88 -141
+88 -141
drivers/hwmon/asb100.c
··· 40 #include <linux/slab.h> 41 #include <linux/i2c.h> 42 #include <linux/hwmon.h> 43 #include <linux/hwmon-vid.h> 44 #include <linux/err.h> 45 #include <linux/init.h> ··· 222 223 /* 7 Voltages */ 224 #define show_in_reg(reg) \ 225 - static ssize_t show_##reg (struct device *dev, char *buf, int nr) \ 226 { \ 227 struct asb100_data *data = asb100_update_device(dev); \ 228 return sprintf(buf, "%d\n", IN_FROM_REG(data->reg[nr])); \ 229 } ··· 235 show_in_reg(in_max) 236 237 #define set_in_reg(REG, reg) \ 238 - static ssize_t set_in_##reg(struct device *dev, const char *buf, \ 239 - size_t count, int nr) \ 240 { \ 241 struct i2c_client *client = to_i2c_client(dev); \ 242 struct asb100_data *data = i2c_get_clientdata(client); \ 243 unsigned long val = simple_strtoul(buf, NULL, 10); \ ··· 255 set_in_reg(MAX, max) 256 257 #define sysfs_in(offset) \ 258 - static ssize_t \ 259 - show_in##offset (struct device *dev, struct device_attribute *attr, char *buf) \ 260 - { \ 261 - return show_in(dev, buf, offset); \ 262 - } \ 263 - static DEVICE_ATTR(in##offset##_input, S_IRUGO, \ 264 - show_in##offset, NULL); \ 265 - static ssize_t \ 266 - show_in##offset##_min (struct device *dev, struct device_attribute *attr, char *buf) \ 267 - { \ 268 - return show_in_min(dev, buf, offset); \ 269 - } \ 270 - static ssize_t \ 271 - show_in##offset##_max (struct device *dev, struct device_attribute *attr, char *buf) \ 272 - { \ 273 - return show_in_max(dev, buf, offset); \ 274 - } \ 275 - static ssize_t set_in##offset##_min (struct device *dev, struct device_attribute *attr, \ 276 - const char *buf, size_t count) \ 277 - { \ 278 - return set_in_min(dev, buf, count, offset); \ 279 - } \ 280 - static ssize_t set_in##offset##_max (struct device *dev, struct device_attribute *attr, \ 281 - const char *buf, size_t count) \ 282 - { \ 283 - return set_in_max(dev, buf, count, offset); \ 284 - } \ 285 - static DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \ 286 - show_in##offset##_min, set_in##offset##_min); \ 287 - static DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \ 288 - show_in##offset##_max, set_in##offset##_max); 289 290 sysfs_in(0); 291 sysfs_in(1); ··· 271 sysfs_in(6); 272 273 /* 3 Fans */ 274 - static ssize_t show_fan(struct device *dev, char *buf, int nr) 275 { 276 struct asb100_data *data = asb100_update_device(dev); 277 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[nr], 278 DIV_FROM_REG(data->fan_div[nr]))); 279 } 280 281 - static ssize_t show_fan_min(struct device *dev, char *buf, int nr) 282 { 283 struct asb100_data *data = asb100_update_device(dev); 284 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan_min[nr], 285 DIV_FROM_REG(data->fan_div[nr]))); 286 } 287 288 - static ssize_t show_fan_div(struct device *dev, char *buf, int nr) 289 { 290 struct asb100_data *data = asb100_update_device(dev); 291 return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr])); 292 } 293 294 - static ssize_t set_fan_min(struct device *dev, const char *buf, 295 - size_t count, int nr) 296 { 297 struct i2c_client *client = to_i2c_client(dev); 298 struct asb100_data *data = i2c_get_clientdata(client); 299 u32 val = simple_strtoul(buf, NULL, 10); ··· 316 determined in part by the fan divisor. This follows the principle of 317 least surprise; the user doesn't expect the fan minimum to change just 318 because the divisor changed. */ 319 - static ssize_t set_fan_div(struct device *dev, const char *buf, 320 - size_t count, int nr) 321 { 322 struct i2c_client *client = to_i2c_client(dev); 323 struct asb100_data *data = i2c_get_clientdata(client); 324 unsigned long min; ··· 362 } 363 364 #define sysfs_fan(offset) \ 365 - static ssize_t show_fan##offset(struct device *dev, struct device_attribute *attr, char *buf) \ 366 - { \ 367 - return show_fan(dev, buf, offset - 1); \ 368 - } \ 369 - static ssize_t show_fan##offset##_min(struct device *dev, struct device_attribute *attr, char *buf) \ 370 - { \ 371 - return show_fan_min(dev, buf, offset - 1); \ 372 - } \ 373 - static ssize_t show_fan##offset##_div(struct device *dev, struct device_attribute *attr, char *buf) \ 374 - { \ 375 - return show_fan_div(dev, buf, offset - 1); \ 376 - } \ 377 - static ssize_t set_fan##offset##_min(struct device *dev, struct device_attribute *attr, const char *buf, \ 378 - size_t count) \ 379 - { \ 380 - return set_fan_min(dev, buf, count, offset - 1); \ 381 - } \ 382 - static ssize_t set_fan##offset##_div(struct device *dev, struct device_attribute *attr, const char *buf, \ 383 - size_t count) \ 384 - { \ 385 - return set_fan_div(dev, buf, count, offset - 1); \ 386 - } \ 387 - static DEVICE_ATTR(fan##offset##_input, S_IRUGO, \ 388 - show_fan##offset, NULL); \ 389 - static DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \ 390 - show_fan##offset##_min, set_fan##offset##_min); \ 391 - static DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \ 392 - show_fan##offset##_div, set_fan##offset##_div); 393 394 sysfs_fan(1); 395 sysfs_fan(2); ··· 390 } 391 392 #define show_temp_reg(reg) \ 393 - static ssize_t show_##reg(struct device *dev, char *buf, int nr) \ 394 { \ 395 struct asb100_data *data = asb100_update_device(dev); \ 396 return sprintf_temp_from_reg(data->reg[nr], buf, nr); \ 397 } ··· 403 show_temp_reg(temp_hyst); 404 405 #define set_temp_reg(REG, reg) \ 406 - static ssize_t set_##reg(struct device *dev, const char *buf, \ 407 - size_t count, int nr) \ 408 { \ 409 struct i2c_client *client = to_i2c_client(dev); \ 410 struct asb100_data *data = i2c_get_clientdata(client); \ 411 long val = simple_strtol(buf, NULL, 10); \ ··· 430 set_temp_reg(HYST, temp_hyst); 431 432 #define sysfs_temp(num) \ 433 - static ssize_t show_temp##num(struct device *dev, struct device_attribute *attr, char *buf) \ 434 - { \ 435 - return show_temp(dev, buf, num-1); \ 436 - } \ 437 - static DEVICE_ATTR(temp##num##_input, S_IRUGO, show_temp##num, NULL); \ 438 - static ssize_t show_temp_max##num(struct device *dev, struct device_attribute *attr, char *buf) \ 439 - { \ 440 - return show_temp_max(dev, buf, num-1); \ 441 - } \ 442 - static ssize_t set_temp_max##num(struct device *dev, struct device_attribute *attr, const char *buf, \ 443 - size_t count) \ 444 - { \ 445 - return set_temp_max(dev, buf, count, num-1); \ 446 - } \ 447 - static DEVICE_ATTR(temp##num##_max, S_IRUGO | S_IWUSR, \ 448 - show_temp_max##num, set_temp_max##num); \ 449 - static ssize_t show_temp_hyst##num(struct device *dev, struct device_attribute *attr, char *buf) \ 450 - { \ 451 - return show_temp_hyst(dev, buf, num-1); \ 452 - } \ 453 - static ssize_t set_temp_hyst##num(struct device *dev, struct device_attribute *attr, const char *buf, \ 454 - size_t count) \ 455 - { \ 456 - return set_temp_hyst(dev, buf, count, num-1); \ 457 - } \ 458 - static DEVICE_ATTR(temp##num##_max_hyst, S_IRUGO | S_IWUSR, \ 459 - show_temp_hyst##num, set_temp_hyst##num); 460 461 sysfs_temp(1); 462 sysfs_temp(2); ··· 530 show_pwm_enable1, set_pwm_enable1); 531 532 static struct attribute *asb100_attributes[] = { 533 - &dev_attr_in0_input.attr, 534 - &dev_attr_in0_min.attr, 535 - &dev_attr_in0_max.attr, 536 - &dev_attr_in1_input.attr, 537 - &dev_attr_in1_min.attr, 538 - &dev_attr_in1_max.attr, 539 - &dev_attr_in2_input.attr, 540 - &dev_attr_in2_min.attr, 541 - &dev_attr_in2_max.attr, 542 - &dev_attr_in3_input.attr, 543 - &dev_attr_in3_min.attr, 544 - &dev_attr_in3_max.attr, 545 - &dev_attr_in4_input.attr, 546 - &dev_attr_in4_min.attr, 547 - &dev_attr_in4_max.attr, 548 - &dev_attr_in5_input.attr, 549 - &dev_attr_in5_min.attr, 550 - &dev_attr_in5_max.attr, 551 - &dev_attr_in6_input.attr, 552 - &dev_attr_in6_min.attr, 553 - &dev_attr_in6_max.attr, 554 555 - &dev_attr_fan1_input.attr, 556 - &dev_attr_fan1_min.attr, 557 - &dev_attr_fan1_div.attr, 558 - &dev_attr_fan2_input.attr, 559 - &dev_attr_fan2_min.attr, 560 - &dev_attr_fan2_div.attr, 561 - &dev_attr_fan3_input.attr, 562 - &dev_attr_fan3_min.attr, 563 - &dev_attr_fan3_div.attr, 564 565 - &dev_attr_temp1_input.attr, 566 - &dev_attr_temp1_max.attr, 567 - &dev_attr_temp1_max_hyst.attr, 568 - &dev_attr_temp2_input.attr, 569 - &dev_attr_temp2_max.attr, 570 - &dev_attr_temp2_max_hyst.attr, 571 - &dev_attr_temp3_input.attr, 572 - &dev_attr_temp3_max.attr, 573 - &dev_attr_temp3_max_hyst.attr, 574 - &dev_attr_temp4_input.attr, 575 - &dev_attr_temp4_max.attr, 576 - &dev_attr_temp4_max_hyst.attr, 577 578 &dev_attr_cpu0_vid.attr, 579 &dev_attr_vrm.attr,
··· 40 #include <linux/slab.h> 41 #include <linux/i2c.h> 42 #include <linux/hwmon.h> 43 + #include <linux/hwmon-sysfs.h> 44 #include <linux/hwmon-vid.h> 45 #include <linux/err.h> 46 #include <linux/init.h> ··· 221 222 /* 7 Voltages */ 223 #define show_in_reg(reg) \ 224 + static ssize_t show_##reg(struct device *dev, struct device_attribute *attr, \ 225 + char *buf) \ 226 { \ 227 + int nr = to_sensor_dev_attr(attr)->index; \ 228 struct asb100_data *data = asb100_update_device(dev); \ 229 return sprintf(buf, "%d\n", IN_FROM_REG(data->reg[nr])); \ 230 } ··· 232 show_in_reg(in_max) 233 234 #define set_in_reg(REG, reg) \ 235 + static ssize_t set_in_##reg(struct device *dev, struct device_attribute *attr, \ 236 + const char *buf, size_t count) \ 237 { \ 238 + int nr = to_sensor_dev_attr(attr)->index; \ 239 struct i2c_client *client = to_i2c_client(dev); \ 240 struct asb100_data *data = i2c_get_clientdata(client); \ 241 unsigned long val = simple_strtoul(buf, NULL, 10); \ ··· 251 set_in_reg(MAX, max) 252 253 #define sysfs_in(offset) \ 254 + static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, \ 255 + show_in, NULL, offset); \ 256 + static SENSOR_DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \ 257 + show_in_min, set_in_min, offset); \ 258 + static SENSOR_DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \ 259 + show_in_max, set_in_max, offset) 260 261 sysfs_in(0); 262 sysfs_in(1); ··· 292 sysfs_in(6); 293 294 /* 3 Fans */ 295 + static ssize_t show_fan(struct device *dev, struct device_attribute *attr, 296 + char *buf) 297 { 298 + int nr = to_sensor_dev_attr(attr)->index; 299 struct asb100_data *data = asb100_update_device(dev); 300 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[nr], 301 DIV_FROM_REG(data->fan_div[nr]))); 302 } 303 304 + static ssize_t show_fan_min(struct device *dev, struct device_attribute *attr, 305 + char *buf) 306 { 307 + int nr = to_sensor_dev_attr(attr)->index; 308 struct asb100_data *data = asb100_update_device(dev); 309 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan_min[nr], 310 DIV_FROM_REG(data->fan_div[nr]))); 311 } 312 313 + static ssize_t show_fan_div(struct device *dev, struct device_attribute *attr, 314 + char *buf) 315 { 316 + int nr = to_sensor_dev_attr(attr)->index; 317 struct asb100_data *data = asb100_update_device(dev); 318 return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr])); 319 } 320 321 + static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr, 322 + const char *buf, size_t count) 323 { 324 + int nr = to_sensor_dev_attr(attr)->index; 325 struct i2c_client *client = to_i2c_client(dev); 326 struct asb100_data *data = i2c_get_clientdata(client); 327 u32 val = simple_strtoul(buf, NULL, 10); ··· 330 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 332 because the divisor changed. */ 333 + static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr, 334 + const char *buf, size_t count) 335 { 336 + int nr = to_sensor_dev_attr(attr)->index; 337 struct i2c_client *client = to_i2c_client(dev); 338 struct asb100_data *data = i2c_get_clientdata(client); 339 unsigned long min; ··· 375 } 376 377 #define sysfs_fan(offset) \ 378 + static SENSOR_DEVICE_ATTR(fan##offset##_input, S_IRUGO, \ 379 + show_fan, NULL, offset - 1); \ 380 + static SENSOR_DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \ 381 + show_fan_min, set_fan_min, offset - 1); \ 382 + static SENSOR_DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \ 383 + show_fan_div, set_fan_div, offset - 1) 384 385 sysfs_fan(1); 386 sysfs_fan(2); ··· 425 } 426 427 #define show_temp_reg(reg) \ 428 + static ssize_t show_##reg(struct device *dev, struct device_attribute *attr, \ 429 + char *buf) \ 430 { \ 431 + int nr = to_sensor_dev_attr(attr)->index; \ 432 struct asb100_data *data = asb100_update_device(dev); \ 433 return sprintf_temp_from_reg(data->reg[nr], buf, nr); \ 434 } ··· 436 show_temp_reg(temp_hyst); 437 438 #define set_temp_reg(REG, reg) \ 439 + static ssize_t set_##reg(struct device *dev, struct device_attribute *attr, \ 440 + const char *buf, size_t count) \ 441 { \ 442 + int nr = to_sensor_dev_attr(attr)->index; \ 443 struct i2c_client *client = to_i2c_client(dev); \ 444 struct asb100_data *data = i2c_get_clientdata(client); \ 445 long val = simple_strtol(buf, NULL, 10); \ ··· 462 set_temp_reg(HYST, temp_hyst); 463 464 #define sysfs_temp(num) \ 465 + static SENSOR_DEVICE_ATTR(temp##num##_input, S_IRUGO, \ 466 + show_temp, NULL, num - 1); \ 467 + static SENSOR_DEVICE_ATTR(temp##num##_max, S_IRUGO | S_IWUSR, \ 468 + show_temp_max, set_temp_max, num - 1); \ 469 + static SENSOR_DEVICE_ATTR(temp##num##_max_hyst, S_IRUGO | S_IWUSR, \ 470 + show_temp_hyst, set_temp_hyst, num - 1) 471 472 sysfs_temp(1); 473 sysfs_temp(2); ··· 583 show_pwm_enable1, set_pwm_enable1); 584 585 static struct attribute *asb100_attributes[] = { 586 + &sensor_dev_attr_in0_input.dev_attr.attr, 587 + &sensor_dev_attr_in0_min.dev_attr.attr, 588 + &sensor_dev_attr_in0_max.dev_attr.attr, 589 + &sensor_dev_attr_in1_input.dev_attr.attr, 590 + &sensor_dev_attr_in1_min.dev_attr.attr, 591 + &sensor_dev_attr_in1_max.dev_attr.attr, 592 + &sensor_dev_attr_in2_input.dev_attr.attr, 593 + &sensor_dev_attr_in2_min.dev_attr.attr, 594 + &sensor_dev_attr_in2_max.dev_attr.attr, 595 + &sensor_dev_attr_in3_input.dev_attr.attr, 596 + &sensor_dev_attr_in3_min.dev_attr.attr, 597 + &sensor_dev_attr_in3_max.dev_attr.attr, 598 + &sensor_dev_attr_in4_input.dev_attr.attr, 599 + &sensor_dev_attr_in4_min.dev_attr.attr, 600 + &sensor_dev_attr_in4_max.dev_attr.attr, 601 + &sensor_dev_attr_in5_input.dev_attr.attr, 602 + &sensor_dev_attr_in5_min.dev_attr.attr, 603 + &sensor_dev_attr_in5_max.dev_attr.attr, 604 + &sensor_dev_attr_in6_input.dev_attr.attr, 605 + &sensor_dev_attr_in6_min.dev_attr.attr, 606 + &sensor_dev_attr_in6_max.dev_attr.attr, 607 608 + &sensor_dev_attr_fan1_input.dev_attr.attr, 609 + &sensor_dev_attr_fan1_min.dev_attr.attr, 610 + &sensor_dev_attr_fan1_div.dev_attr.attr, 611 + &sensor_dev_attr_fan2_input.dev_attr.attr, 612 + &sensor_dev_attr_fan2_min.dev_attr.attr, 613 + &sensor_dev_attr_fan2_div.dev_attr.attr, 614 + &sensor_dev_attr_fan3_input.dev_attr.attr, 615 + &sensor_dev_attr_fan3_min.dev_attr.attr, 616 + &sensor_dev_attr_fan3_div.dev_attr.attr, 617 618 + &sensor_dev_attr_temp1_input.dev_attr.attr, 619 + &sensor_dev_attr_temp1_max.dev_attr.attr, 620 + &sensor_dev_attr_temp1_max_hyst.dev_attr.attr, 621 + &sensor_dev_attr_temp2_input.dev_attr.attr, 622 + &sensor_dev_attr_temp2_max.dev_attr.attr, 623 + &sensor_dev_attr_temp2_max_hyst.dev_attr.attr, 624 + &sensor_dev_attr_temp3_input.dev_attr.attr, 625 + &sensor_dev_attr_temp3_max.dev_attr.attr, 626 + &sensor_dev_attr_temp3_max_hyst.dev_attr.attr, 627 + &sensor_dev_attr_temp4_input.dev_attr.attr, 628 + &sensor_dev_attr_temp4_max.dev_attr.attr, 629 + &sensor_dev_attr_temp4_max_hyst.dev_attr.attr, 630 631 &dev_attr_cpu0_vid.attr, 632 &dev_attr_vrm.attr,