hc
2024-05-10 23fa18eaa71266feff7ba8d83022d9e1cc83c65a
kernel/drivers/hwmon/via686a.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * via686a.c - Part of lm_sensors, Linux kernel modules
34 * for hardware monitoring
....@@ -9,20 +10,6 @@
910 *
1011 * (Some conversion-factor data were contributed by Jonathan Teh Soon Yew
1112 * <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.
2613 */
2714
2815 /*
....@@ -46,7 +33,6 @@
4633 #include <linux/sysfs.h>
4734 #include <linux/acpi.h>
4835 #include <linux/io.h>
49
-
5036
5137 /*
5238 * If force_addr is set to anything different from 0, we forcibly enable
....@@ -355,32 +341,32 @@
355341 /* following are the sysfs callback functions */
356342
357343 /* 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) {
360346 struct via686a_data *data = via686a_update_device(dev);
361347 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
362348 int nr = attr->index;
363349 return sprintf(buf, "%ld\n", IN_FROM_REG(data->in[nr], nr));
364350 }
365351
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) {
368354 struct via686a_data *data = via686a_update_device(dev);
369355 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
370356 int nr = attr->index;
371357 return sprintf(buf, "%ld\n", IN_FROM_REG(data->in_min[nr], nr));
372358 }
373359
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) {
376362 struct via686a_data *data = via686a_update_device(dev);
377363 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
378364 int nr = attr->index;
379365 return sprintf(buf, "%ld\n", IN_FROM_REG(data->in_max[nr], nr));
380366 }
381367
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) {
384370 struct via686a_data *data = dev_get_drvdata(dev);
385371 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
386372 int nr = attr->index;
....@@ -398,8 +384,8 @@
398384 mutex_unlock(&data->update_lock);
399385 return count;
400386 }
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) {
403389 struct via686a_data *data = dev_get_drvdata(dev);
404390 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
405391 int nr = attr->index;
....@@ -417,44 +403,48 @@
417403 mutex_unlock(&data->update_lock);
418404 return count;
419405 }
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);
427406
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);
433422
434423 /* 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) {
437426 struct via686a_data *data = via686a_update_device(dev);
438427 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
439428 int nr = attr->index;
440429 return sprintf(buf, "%ld\n", TEMP_FROM_REG10(data->temp[nr]));
441430 }
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) {
444433 struct via686a_data *data = via686a_update_device(dev);
445434 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
446435 int nr = attr->index;
447436 return sprintf(buf, "%ld\n", TEMP_FROM_REG(data->temp_over[nr]));
448437 }
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) {
451440 struct via686a_data *data = via686a_update_device(dev);
452441 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
453442 int nr = attr->index;
454443 return sprintf(buf, "%ld\n", TEMP_FROM_REG(data->temp_hyst[nr]));
455444 }
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) {
458448 struct via686a_data *data = dev_get_drvdata(dev);
459449 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
460450 int nr = attr->index;
....@@ -472,8 +462,9 @@
472462 mutex_unlock(&data->update_lock);
473463 return count;
474464 }
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) {
477468 struct via686a_data *data = dev_get_drvdata(dev);
478469 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
479470 int nr = attr->index;
....@@ -491,29 +482,28 @@
491482 mutex_unlock(&data->update_lock);
492483 return count;
493484 }
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);
501485
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);
505495
506496 /* 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) {
509499 struct via686a_data *data = via686a_update_device(dev);
510500 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
511501 int nr = attr->index;
512502 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[nr],
513503 DIV_FROM_REG(data->fan_div[nr])));
514504 }
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) {
517507 struct via686a_data *data = via686a_update_device(dev);
518508 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
519509 int nr = attr->index;
....@@ -521,15 +511,15 @@
521511 FAN_FROM_REG(data->fan_min[nr],
522512 DIV_FROM_REG(data->fan_div[nr])));
523513 }
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) {
526516 struct via686a_data *data = via686a_update_device(dev);
527517 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
528518 int nr = attr->index;
529519 return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr]));
530520 }
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) {
533523 struct via686a_data *data = dev_get_drvdata(dev);
534524 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
535525 int nr = attr->index;
....@@ -546,8 +536,8 @@
546536 mutex_unlock(&data->update_lock);
547537 return count;
548538 }
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) {
551541 struct via686a_data *data = dev_get_drvdata(dev);
552542 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
553543 int nr = attr->index;
....@@ -568,16 +558,12 @@
568558 return count;
569559 }
570560
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);
581567
582568 /* Alarms */
583569 static ssize_t alarms_show(struct device *dev, struct device_attribute *attr,
....@@ -589,23 +575,23 @@
589575
590576 static DEVICE_ATTR_RO(alarms);
591577
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,
593579 char *buf)
594580 {
595581 int bitnr = to_sensor_dev_attr(attr)->index;
596582 struct via686a_data *data = via686a_update_device(dev);
597583 return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1);
598584 }
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);
609595
610596 static ssize_t name_show(struct device *dev, struct device_attribute
611597 *devattr, char *buf)
....@@ -675,7 +661,6 @@
675661 .probe = via686a_probe,
676662 .remove = via686a_remove,
677663 };
678
-
679664
680665 /* This is called when the module is loaded */
681666 static int via686a_probe(struct platform_device *pdev)