| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * via686a.c - Part of lm_sensors, Linux kernel modules |
|---|
| 3 | 4 | * for hardware monitoring |
|---|
| .. | .. |
|---|
| 9 | 10 | * |
|---|
| 10 | 11 | * (Some conversion-factor data were contributed by Jonathan Teh Soon Yew |
|---|
| 11 | 12 | * <j.teh@iname.com> and Alex van Kaam <darkside@chello.nl>.) |
|---|
| 12 | | - * |
|---|
| 13 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 14 | | - * it under the terms of the GNU General Public License as published by |
|---|
| 15 | | - * the Free Software Foundation; either version 2 of the License, or |
|---|
| 16 | | - * (at your option) any later version. |
|---|
| 17 | | - * |
|---|
| 18 | | - * This program is distributed in the hope that it will be useful, |
|---|
| 19 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 20 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 21 | | - * GNU General Public License for more details. |
|---|
| 22 | | - * |
|---|
| 23 | | - * You should have received a copy of the GNU General Public License |
|---|
| 24 | | - * along with this program; if not, write to the Free Software |
|---|
| 25 | | - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
|---|
| 26 | 13 | */ |
|---|
| 27 | 14 | |
|---|
| 28 | 15 | /* |
|---|
| .. | .. |
|---|
| 46 | 33 | #include <linux/sysfs.h> |
|---|
| 47 | 34 | #include <linux/acpi.h> |
|---|
| 48 | 35 | #include <linux/io.h> |
|---|
| 49 | | - |
|---|
| 50 | 36 | |
|---|
| 51 | 37 | /* |
|---|
| 52 | 38 | * If force_addr is set to anything different from 0, we forcibly enable |
|---|
| .. | .. |
|---|
| 355 | 341 | /* following are the sysfs callback functions */ |
|---|
| 356 | 342 | |
|---|
| 357 | 343 | /* 7 voltage sensors */ |
|---|
| 358 | | -static ssize_t show_in(struct device *dev, struct device_attribute *da, |
|---|
| 359 | | - char *buf) { |
|---|
| 344 | +static ssize_t in_show(struct device *dev, struct device_attribute *da, |
|---|
| 345 | + char *buf) { |
|---|
| 360 | 346 | struct via686a_data *data = via686a_update_device(dev); |
|---|
| 361 | 347 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); |
|---|
| 362 | 348 | int nr = attr->index; |
|---|
| 363 | 349 | return sprintf(buf, "%ld\n", IN_FROM_REG(data->in[nr], nr)); |
|---|
| 364 | 350 | } |
|---|
| 365 | 351 | |
|---|
| 366 | | -static ssize_t show_in_min(struct device *dev, struct device_attribute *da, |
|---|
| 367 | | - char *buf) { |
|---|
| 352 | +static ssize_t in_min_show(struct device *dev, struct device_attribute *da, |
|---|
| 353 | + char *buf) { |
|---|
| 368 | 354 | struct via686a_data *data = via686a_update_device(dev); |
|---|
| 369 | 355 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); |
|---|
| 370 | 356 | int nr = attr->index; |
|---|
| 371 | 357 | return sprintf(buf, "%ld\n", IN_FROM_REG(data->in_min[nr], nr)); |
|---|
| 372 | 358 | } |
|---|
| 373 | 359 | |
|---|
| 374 | | -static ssize_t show_in_max(struct device *dev, struct device_attribute *da, |
|---|
| 375 | | - char *buf) { |
|---|
| 360 | +static ssize_t in_max_show(struct device *dev, struct device_attribute *da, |
|---|
| 361 | + char *buf) { |
|---|
| 376 | 362 | struct via686a_data *data = via686a_update_device(dev); |
|---|
| 377 | 363 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); |
|---|
| 378 | 364 | int nr = attr->index; |
|---|
| 379 | 365 | return sprintf(buf, "%ld\n", IN_FROM_REG(data->in_max[nr], nr)); |
|---|
| 380 | 366 | } |
|---|
| 381 | 367 | |
|---|
| 382 | | -static ssize_t set_in_min(struct device *dev, struct device_attribute *da, |
|---|
| 383 | | - const char *buf, size_t count) { |
|---|
| 368 | +static ssize_t in_min_store(struct device *dev, struct device_attribute *da, |
|---|
| 369 | + const char *buf, size_t count) { |
|---|
| 384 | 370 | struct via686a_data *data = dev_get_drvdata(dev); |
|---|
| 385 | 371 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); |
|---|
| 386 | 372 | int nr = attr->index; |
|---|
| .. | .. |
|---|
| 398 | 384 | mutex_unlock(&data->update_lock); |
|---|
| 399 | 385 | return count; |
|---|
| 400 | 386 | } |
|---|
| 401 | | -static ssize_t set_in_max(struct device *dev, struct device_attribute *da, |
|---|
| 402 | | - const char *buf, size_t count) { |
|---|
| 387 | +static ssize_t in_max_store(struct device *dev, struct device_attribute *da, |
|---|
| 388 | + const char *buf, size_t count) { |
|---|
| 403 | 389 | struct via686a_data *data = dev_get_drvdata(dev); |
|---|
| 404 | 390 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); |
|---|
| 405 | 391 | int nr = attr->index; |
|---|
| .. | .. |
|---|
| 417 | 403 | mutex_unlock(&data->update_lock); |
|---|
| 418 | 404 | return count; |
|---|
| 419 | 405 | } |
|---|
| 420 | | -#define show_in_offset(offset) \ |
|---|
| 421 | | -static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, \ |
|---|
| 422 | | - show_in, NULL, offset); \ |
|---|
| 423 | | -static SENSOR_DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \ |
|---|
| 424 | | - show_in_min, set_in_min, offset); \ |
|---|
| 425 | | -static SENSOR_DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \ |
|---|
| 426 | | - show_in_max, set_in_max, offset); |
|---|
| 427 | 406 | |
|---|
| 428 | | -show_in_offset(0); |
|---|
| 429 | | -show_in_offset(1); |
|---|
| 430 | | -show_in_offset(2); |
|---|
| 431 | | -show_in_offset(3); |
|---|
| 432 | | -show_in_offset(4); |
|---|
| 407 | +static SENSOR_DEVICE_ATTR_RO(in0_input, in, 0); |
|---|
| 408 | +static SENSOR_DEVICE_ATTR_RW(in0_min, in_min, 0); |
|---|
| 409 | +static SENSOR_DEVICE_ATTR_RW(in0_max, in_max, 0); |
|---|
| 410 | +static SENSOR_DEVICE_ATTR_RO(in1_input, in, 1); |
|---|
| 411 | +static SENSOR_DEVICE_ATTR_RW(in1_min, in_min, 1); |
|---|
| 412 | +static SENSOR_DEVICE_ATTR_RW(in1_max, in_max, 1); |
|---|
| 413 | +static SENSOR_DEVICE_ATTR_RO(in2_input, in, 2); |
|---|
| 414 | +static SENSOR_DEVICE_ATTR_RW(in2_min, in_min, 2); |
|---|
| 415 | +static SENSOR_DEVICE_ATTR_RW(in2_max, in_max, 2); |
|---|
| 416 | +static SENSOR_DEVICE_ATTR_RO(in3_input, in, 3); |
|---|
| 417 | +static SENSOR_DEVICE_ATTR_RW(in3_min, in_min, 3); |
|---|
| 418 | +static SENSOR_DEVICE_ATTR_RW(in3_max, in_max, 3); |
|---|
| 419 | +static SENSOR_DEVICE_ATTR_RO(in4_input, in, 4); |
|---|
| 420 | +static SENSOR_DEVICE_ATTR_RW(in4_min, in_min, 4); |
|---|
| 421 | +static SENSOR_DEVICE_ATTR_RW(in4_max, in_max, 4); |
|---|
| 433 | 422 | |
|---|
| 434 | 423 | /* 3 temperatures */ |
|---|
| 435 | | -static ssize_t show_temp(struct device *dev, struct device_attribute *da, |
|---|
| 436 | | - char *buf) { |
|---|
| 424 | +static ssize_t temp_show(struct device *dev, struct device_attribute *da, |
|---|
| 425 | + char *buf) { |
|---|
| 437 | 426 | struct via686a_data *data = via686a_update_device(dev); |
|---|
| 438 | 427 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); |
|---|
| 439 | 428 | int nr = attr->index; |
|---|
| 440 | 429 | return sprintf(buf, "%ld\n", TEMP_FROM_REG10(data->temp[nr])); |
|---|
| 441 | 430 | } |
|---|
| 442 | | -static ssize_t show_temp_over(struct device *dev, struct device_attribute *da, |
|---|
| 443 | | - char *buf) { |
|---|
| 431 | +static ssize_t temp_over_show(struct device *dev, struct device_attribute *da, |
|---|
| 432 | + char *buf) { |
|---|
| 444 | 433 | struct via686a_data *data = via686a_update_device(dev); |
|---|
| 445 | 434 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); |
|---|
| 446 | 435 | int nr = attr->index; |
|---|
| 447 | 436 | return sprintf(buf, "%ld\n", TEMP_FROM_REG(data->temp_over[nr])); |
|---|
| 448 | 437 | } |
|---|
| 449 | | -static ssize_t show_temp_hyst(struct device *dev, struct device_attribute *da, |
|---|
| 450 | | - char *buf) { |
|---|
| 438 | +static ssize_t temp_hyst_show(struct device *dev, struct device_attribute *da, |
|---|
| 439 | + char *buf) { |
|---|
| 451 | 440 | struct via686a_data *data = via686a_update_device(dev); |
|---|
| 452 | 441 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); |
|---|
| 453 | 442 | int nr = attr->index; |
|---|
| 454 | 443 | return sprintf(buf, "%ld\n", TEMP_FROM_REG(data->temp_hyst[nr])); |
|---|
| 455 | 444 | } |
|---|
| 456 | | -static ssize_t set_temp_over(struct device *dev, struct device_attribute *da, |
|---|
| 457 | | - const char *buf, size_t count) { |
|---|
| 445 | +static ssize_t temp_over_store(struct device *dev, |
|---|
| 446 | + struct device_attribute *da, const char *buf, |
|---|
| 447 | + size_t count) { |
|---|
| 458 | 448 | struct via686a_data *data = dev_get_drvdata(dev); |
|---|
| 459 | 449 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); |
|---|
| 460 | 450 | int nr = attr->index; |
|---|
| .. | .. |
|---|
| 472 | 462 | mutex_unlock(&data->update_lock); |
|---|
| 473 | 463 | return count; |
|---|
| 474 | 464 | } |
|---|
| 475 | | -static ssize_t set_temp_hyst(struct device *dev, struct device_attribute *da, |
|---|
| 476 | | - const char *buf, size_t count) { |
|---|
| 465 | +static ssize_t temp_hyst_store(struct device *dev, |
|---|
| 466 | + struct device_attribute *da, const char *buf, |
|---|
| 467 | + size_t count) { |
|---|
| 477 | 468 | struct via686a_data *data = dev_get_drvdata(dev); |
|---|
| 478 | 469 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); |
|---|
| 479 | 470 | int nr = attr->index; |
|---|
| .. | .. |
|---|
| 491 | 482 | mutex_unlock(&data->update_lock); |
|---|
| 492 | 483 | return count; |
|---|
| 493 | 484 | } |
|---|
| 494 | | -#define show_temp_offset(offset) \ |
|---|
| 495 | | -static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, \ |
|---|
| 496 | | - show_temp, NULL, offset - 1); \ |
|---|
| 497 | | -static SENSOR_DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \ |
|---|
| 498 | | - show_temp_over, set_temp_over, offset - 1); \ |
|---|
| 499 | | -static SENSOR_DEVICE_ATTR(temp##offset##_max_hyst, S_IRUGO | S_IWUSR, \ |
|---|
| 500 | | - show_temp_hyst, set_temp_hyst, offset - 1); |
|---|
| 501 | 485 | |
|---|
| 502 | | -show_temp_offset(1); |
|---|
| 503 | | -show_temp_offset(2); |
|---|
| 504 | | -show_temp_offset(3); |
|---|
| 486 | +static SENSOR_DEVICE_ATTR_RO(temp1_input, temp, 0); |
|---|
| 487 | +static SENSOR_DEVICE_ATTR_RW(temp1_max, temp_over, 0); |
|---|
| 488 | +static SENSOR_DEVICE_ATTR_RW(temp1_max_hyst, temp_hyst, 0); |
|---|
| 489 | +static SENSOR_DEVICE_ATTR_RO(temp2_input, temp, 1); |
|---|
| 490 | +static SENSOR_DEVICE_ATTR_RW(temp2_max, temp_over, 1); |
|---|
| 491 | +static SENSOR_DEVICE_ATTR_RW(temp2_max_hyst, temp_hyst, 1); |
|---|
| 492 | +static SENSOR_DEVICE_ATTR_RO(temp3_input, temp, 2); |
|---|
| 493 | +static SENSOR_DEVICE_ATTR_RW(temp3_max, temp_over, 2); |
|---|
| 494 | +static SENSOR_DEVICE_ATTR_RW(temp3_max_hyst, temp_hyst, 2); |
|---|
| 505 | 495 | |
|---|
| 506 | 496 | /* 2 Fans */ |
|---|
| 507 | | -static ssize_t show_fan(struct device *dev, struct device_attribute *da, |
|---|
| 508 | | - char *buf) { |
|---|
| 497 | +static ssize_t fan_show(struct device *dev, struct device_attribute *da, |
|---|
| 498 | + char *buf) { |
|---|
| 509 | 499 | struct via686a_data *data = via686a_update_device(dev); |
|---|
| 510 | 500 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); |
|---|
| 511 | 501 | int nr = attr->index; |
|---|
| 512 | 502 | return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[nr], |
|---|
| 513 | 503 | DIV_FROM_REG(data->fan_div[nr]))); |
|---|
| 514 | 504 | } |
|---|
| 515 | | -static ssize_t show_fan_min(struct device *dev, struct device_attribute *da, |
|---|
| 516 | | - char *buf) { |
|---|
| 505 | +static ssize_t fan_min_show(struct device *dev, struct device_attribute *da, |
|---|
| 506 | + char *buf) { |
|---|
| 517 | 507 | struct via686a_data *data = via686a_update_device(dev); |
|---|
| 518 | 508 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); |
|---|
| 519 | 509 | int nr = attr->index; |
|---|
| .. | .. |
|---|
| 521 | 511 | FAN_FROM_REG(data->fan_min[nr], |
|---|
| 522 | 512 | DIV_FROM_REG(data->fan_div[nr]))); |
|---|
| 523 | 513 | } |
|---|
| 524 | | -static ssize_t show_fan_div(struct device *dev, struct device_attribute *da, |
|---|
| 525 | | - char *buf) { |
|---|
| 514 | +static ssize_t fan_div_show(struct device *dev, struct device_attribute *da, |
|---|
| 515 | + char *buf) { |
|---|
| 526 | 516 | struct via686a_data *data = via686a_update_device(dev); |
|---|
| 527 | 517 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); |
|---|
| 528 | 518 | int nr = attr->index; |
|---|
| 529 | 519 | return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr])); |
|---|
| 530 | 520 | } |
|---|
| 531 | | -static ssize_t set_fan_min(struct device *dev, struct device_attribute *da, |
|---|
| 532 | | - const char *buf, size_t count) { |
|---|
| 521 | +static ssize_t fan_min_store(struct device *dev, struct device_attribute *da, |
|---|
| 522 | + const char *buf, size_t count) { |
|---|
| 533 | 523 | struct via686a_data *data = dev_get_drvdata(dev); |
|---|
| 534 | 524 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); |
|---|
| 535 | 525 | int nr = attr->index; |
|---|
| .. | .. |
|---|
| 546 | 536 | mutex_unlock(&data->update_lock); |
|---|
| 547 | 537 | return count; |
|---|
| 548 | 538 | } |
|---|
| 549 | | -static ssize_t set_fan_div(struct device *dev, struct device_attribute *da, |
|---|
| 550 | | - const char *buf, size_t count) { |
|---|
| 539 | +static ssize_t fan_div_store(struct device *dev, struct device_attribute *da, |
|---|
| 540 | + const char *buf, size_t count) { |
|---|
| 551 | 541 | struct via686a_data *data = dev_get_drvdata(dev); |
|---|
| 552 | 542 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); |
|---|
| 553 | 543 | int nr = attr->index; |
|---|
| .. | .. |
|---|
| 568 | 558 | return count; |
|---|
| 569 | 559 | } |
|---|
| 570 | 560 | |
|---|
| 571 | | -#define show_fan_offset(offset) \ |
|---|
| 572 | | -static SENSOR_DEVICE_ATTR(fan##offset##_input, S_IRUGO, \ |
|---|
| 573 | | - show_fan, NULL, offset - 1); \ |
|---|
| 574 | | -static SENSOR_DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \ |
|---|
| 575 | | - show_fan_min, set_fan_min, offset - 1); \ |
|---|
| 576 | | -static SENSOR_DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \ |
|---|
| 577 | | - show_fan_div, set_fan_div, offset - 1); |
|---|
| 578 | | - |
|---|
| 579 | | -show_fan_offset(1); |
|---|
| 580 | | -show_fan_offset(2); |
|---|
| 561 | +static SENSOR_DEVICE_ATTR_RO(fan1_input, fan, 0); |
|---|
| 562 | +static SENSOR_DEVICE_ATTR_RW(fan1_min, fan_min, 0); |
|---|
| 563 | +static SENSOR_DEVICE_ATTR_RW(fan1_div, fan_div, 0); |
|---|
| 564 | +static SENSOR_DEVICE_ATTR_RO(fan2_input, fan, 1); |
|---|
| 565 | +static SENSOR_DEVICE_ATTR_RW(fan2_min, fan_min, 1); |
|---|
| 566 | +static SENSOR_DEVICE_ATTR_RW(fan2_div, fan_div, 1); |
|---|
| 581 | 567 | |
|---|
| 582 | 568 | /* Alarms */ |
|---|
| 583 | 569 | static ssize_t alarms_show(struct device *dev, struct device_attribute *attr, |
|---|
| .. | .. |
|---|
| 589 | 575 | |
|---|
| 590 | 576 | static DEVICE_ATTR_RO(alarms); |
|---|
| 591 | 577 | |
|---|
| 592 | | -static ssize_t show_alarm(struct device *dev, struct device_attribute *attr, |
|---|
| 578 | +static ssize_t alarm_show(struct device *dev, struct device_attribute *attr, |
|---|
| 593 | 579 | char *buf) |
|---|
| 594 | 580 | { |
|---|
| 595 | 581 | int bitnr = to_sensor_dev_attr(attr)->index; |
|---|
| 596 | 582 | struct via686a_data *data = via686a_update_device(dev); |
|---|
| 597 | 583 | return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1); |
|---|
| 598 | 584 | } |
|---|
| 599 | | -static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 0); |
|---|
| 600 | | -static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 1); |
|---|
| 601 | | -static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 2); |
|---|
| 602 | | -static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 3); |
|---|
| 603 | | -static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 8); |
|---|
| 604 | | -static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 4); |
|---|
| 605 | | -static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 11); |
|---|
| 606 | | -static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 15); |
|---|
| 607 | | -static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 6); |
|---|
| 608 | | -static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 7); |
|---|
| 585 | +static SENSOR_DEVICE_ATTR_RO(in0_alarm, alarm, 0); |
|---|
| 586 | +static SENSOR_DEVICE_ATTR_RO(in1_alarm, alarm, 1); |
|---|
| 587 | +static SENSOR_DEVICE_ATTR_RO(in2_alarm, alarm, 2); |
|---|
| 588 | +static SENSOR_DEVICE_ATTR_RO(in3_alarm, alarm, 3); |
|---|
| 589 | +static SENSOR_DEVICE_ATTR_RO(in4_alarm, alarm, 8); |
|---|
| 590 | +static SENSOR_DEVICE_ATTR_RO(temp1_alarm, alarm, 4); |
|---|
| 591 | +static SENSOR_DEVICE_ATTR_RO(temp2_alarm, alarm, 11); |
|---|
| 592 | +static SENSOR_DEVICE_ATTR_RO(temp3_alarm, alarm, 15); |
|---|
| 593 | +static SENSOR_DEVICE_ATTR_RO(fan1_alarm, alarm, 6); |
|---|
| 594 | +static SENSOR_DEVICE_ATTR_RO(fan2_alarm, alarm, 7); |
|---|
| 609 | 595 | |
|---|
| 610 | 596 | static ssize_t name_show(struct device *dev, struct device_attribute |
|---|
| 611 | 597 | *devattr, char *buf) |
|---|
| .. | .. |
|---|
| 675 | 661 | .probe = via686a_probe, |
|---|
| 676 | 662 | .remove = via686a_remove, |
|---|
| 677 | 663 | }; |
|---|
| 678 | | - |
|---|
| 679 | 664 | |
|---|
| 680 | 665 | /* This is called when the module is loaded */ |
|---|
| 681 | 666 | static int via686a_probe(struct platform_device *pdev) |
|---|