hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/hwmon/amc6821.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * amc6821.c - Part of lm_sensors, Linux kernel modules for hardware
34 * monitoring
....@@ -5,20 +6,6 @@
56 *
67 * Based on max6650.c:
78 * Copyright (C) 2007 Hans J. Koch <hjk@hansjkoch.de>
8
- *
9
- * This program is free software; you can redistribute it and/or modify
10
- * it under the terms of the GNU General Public License as published by
11
- * the Free Software Foundation; either version 2 of the License, or
12
- * (at your option) any later version.
13
- *
14
- * This program is distributed in the hope that it will be useful,
15
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
- * GNU General Public License for more details.
18
- *
19
- * You should have received a copy of the GNU General Public License
20
- * along with this program; if not, write to the Free Software
21
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
229 */
2310
2411 #include <linux/kernel.h> /* Needed for KERN_INFO */
....@@ -44,10 +31,10 @@
4431 */
4532
4633 static int pwminv; /*Inverted PWM output. */
47
-module_param(pwminv, int, S_IRUGO);
34
+module_param(pwminv, int, 0444);
4835
4936 static int init = 1; /*Power-on initialization.*/
50
-module_param(init, int, S_IRUGO);
37
+module_param(init, int, 0444);
5138
5239 enum chips { amc6821 };
5340
....@@ -277,10 +264,8 @@
277264 return data;
278265 }
279266
280
-static ssize_t get_temp(
281
- struct device *dev,
282
- struct device_attribute *devattr,
283
- char *buf)
267
+static ssize_t temp_show(struct device *dev, struct device_attribute *devattr,
268
+ char *buf)
284269 {
285270 struct amc6821_data *data = amc6821_update_device(dev);
286271 int ix = to_sensor_dev_attr(devattr)->index;
....@@ -288,11 +273,8 @@
288273 return sprintf(buf, "%d\n", data->temp[ix] * 1000);
289274 }
290275
291
-static ssize_t set_temp(
292
- struct device *dev,
293
- struct device_attribute *attr,
294
- const char *buf,
295
- size_t count)
276
+static ssize_t temp_store(struct device *dev, struct device_attribute *attr,
277
+ const char *buf, size_t count)
296278 {
297279 struct amc6821_data *data = dev_get_drvdata(dev);
298280 struct i2c_client *client = data->client;
....@@ -314,10 +296,8 @@
314296 return count;
315297 }
316298
317
-static ssize_t get_temp_alarm(
318
- struct device *dev,
319
- struct device_attribute *devattr,
320
- char *buf)
299
+static ssize_t temp_alarm_show(struct device *dev,
300
+ struct device_attribute *devattr, char *buf)
321301 {
322302 struct amc6821_data *data = amc6821_update_device(dev);
323303 int ix = to_sensor_dev_attr(devattr)->index;
....@@ -352,10 +332,8 @@
352332 return sprintf(buf, "0");
353333 }
354334
355
-static ssize_t get_temp2_fault(
356
- struct device *dev,
357
- struct device_attribute *devattr,
358
- char *buf)
335
+static ssize_t temp2_fault_show(struct device *dev,
336
+ struct device_attribute *devattr, char *buf)
359337 {
360338 struct amc6821_data *data = amc6821_update_device(dev);
361339 if (data->stat1 & AMC6821_STAT1_RTF)
....@@ -364,20 +342,16 @@
364342 return sprintf(buf, "0");
365343 }
366344
367
-static ssize_t get_pwm1(
368
- struct device *dev,
369
- struct device_attribute *devattr,
370
- char *buf)
345
+static ssize_t pwm1_show(struct device *dev, struct device_attribute *devattr,
346
+ char *buf)
371347 {
372348 struct amc6821_data *data = amc6821_update_device(dev);
373349 return sprintf(buf, "%d\n", data->pwm1);
374350 }
375351
376
-static ssize_t set_pwm1(
377
- struct device *dev,
378
- struct device_attribute *devattr,
379
- const char *buf,
380
- size_t count)
352
+static ssize_t pwm1_store(struct device *dev,
353
+ struct device_attribute *devattr, const char *buf,
354
+ size_t count)
381355 {
382356 struct amc6821_data *data = dev_get_drvdata(dev);
383357 struct i2c_client *client = data->client;
....@@ -393,20 +367,16 @@
393367 return count;
394368 }
395369
396
-static ssize_t get_pwm1_enable(
397
- struct device *dev,
398
- struct device_attribute *devattr,
399
- char *buf)
370
+static ssize_t pwm1_enable_show(struct device *dev,
371
+ struct device_attribute *devattr, char *buf)
400372 {
401373 struct amc6821_data *data = amc6821_update_device(dev);
402374 return sprintf(buf, "%d\n", data->pwm1_enable);
403375 }
404376
405
-static ssize_t set_pwm1_enable(
406
- struct device *dev,
407
- struct device_attribute *attr,
408
- const char *buf,
409
- size_t count)
377
+static ssize_t pwm1_enable_store(struct device *dev,
378
+ struct device_attribute *attr,
379
+ const char *buf, size_t count)
410380 {
411381 struct amc6821_data *data = dev_get_drvdata(dev);
412382 struct i2c_client *client = data->client;
....@@ -451,19 +421,17 @@
451421 return count;
452422 }
453423
454
-static ssize_t get_pwm1_auto_channels_temp(
455
- struct device *dev,
456
- struct device_attribute *devattr,
457
- char *buf)
424
+static ssize_t pwm1_auto_channels_temp_show(struct device *dev,
425
+ struct device_attribute *devattr,
426
+ char *buf)
458427 {
459428 struct amc6821_data *data = amc6821_update_device(dev);
460429 return sprintf(buf, "%d\n", data->pwm1_auto_channels_temp);
461430 }
462431
463
-static ssize_t get_temp_auto_point_temp(
464
- struct device *dev,
465
- struct device_attribute *devattr,
466
- char *buf)
432
+static ssize_t temp_auto_point_temp_show(struct device *dev,
433
+ struct device_attribute *devattr,
434
+ char *buf)
467435 {
468436 int ix = to_sensor_dev_attr_2(devattr)->index;
469437 int nr = to_sensor_dev_attr_2(devattr)->nr;
....@@ -481,10 +449,9 @@
481449 }
482450 }
483451
484
-static ssize_t get_pwm1_auto_point_pwm(
485
- struct device *dev,
486
- struct device_attribute *devattr,
487
- char *buf)
452
+static ssize_t pwm1_auto_point_pwm_show(struct device *dev,
453
+ struct device_attribute *devattr,
454
+ char *buf)
488455 {
489456 int ix = to_sensor_dev_attr(devattr)->index;
490457 struct amc6821_data *data = amc6821_update_device(dev);
....@@ -513,11 +480,9 @@
513480 return 0;
514481 }
515482
516
-static ssize_t set_temp_auto_point_temp(
517
- struct device *dev,
518
- struct device_attribute *attr,
519
- const char *buf,
520
- size_t count)
483
+static ssize_t temp_auto_point_temp_store(struct device *dev,
484
+ struct device_attribute *attr,
485
+ const char *buf, size_t count)
521486 {
522487 struct amc6821_data *data = amc6821_update_device(dev);
523488 struct i2c_client *client = data->client;
....@@ -586,11 +551,9 @@
586551 return count;
587552 }
588553
589
-static ssize_t set_pwm1_auto_point_pwm(
590
- struct device *dev,
591
- struct device_attribute *attr,
592
- const char *buf,
593
- size_t count)
554
+static ssize_t pwm1_auto_point_pwm_store(struct device *dev,
555
+ struct device_attribute *attr,
556
+ const char *buf, size_t count)
594557 {
595558 struct amc6821_data *data = dev_get_drvdata(dev);
596559 struct i2c_client *client = data->client;
....@@ -626,10 +589,8 @@
626589 return count;
627590 }
628591
629
-static ssize_t get_fan(
630
- struct device *dev,
631
- struct device_attribute *devattr,
632
- char *buf)
592
+static ssize_t fan_show(struct device *dev, struct device_attribute *devattr,
593
+ char *buf)
633594 {
634595 struct amc6821_data *data = amc6821_update_device(dev);
635596 int ix = to_sensor_dev_attr(devattr)->index;
....@@ -638,10 +599,8 @@
638599 return sprintf(buf, "%d\n", (int)(6000000 / data->fan[ix]));
639600 }
640601
641
-static ssize_t get_fan1_fault(
642
- struct device *dev,
643
- struct device_attribute *devattr,
644
- char *buf)
602
+static ssize_t fan1_fault_show(struct device *dev,
603
+ struct device_attribute *devattr, char *buf)
645604 {
646605 struct amc6821_data *data = amc6821_update_device(dev);
647606 if (data->stat1 & AMC6821_STAT1_FANS)
....@@ -650,10 +609,8 @@
650609 return sprintf(buf, "0");
651610 }
652611
653
-static ssize_t set_fan(
654
- struct device *dev,
655
- struct device_attribute *attr,
656
- const char *buf, size_t count)
612
+static ssize_t fan_store(struct device *dev, struct device_attribute *attr,
613
+ const char *buf, size_t count)
657614 {
658615 struct amc6821_data *data = dev_get_drvdata(dev);
659616 struct i2c_client *client = data->client;
....@@ -682,19 +639,16 @@
682639 return count;
683640 }
684641
685
-static ssize_t get_fan1_div(
686
- struct device *dev,
687
- struct device_attribute *devattr,
688
- char *buf)
642
+static ssize_t fan1_div_show(struct device *dev,
643
+ struct device_attribute *devattr, char *buf)
689644 {
690645 struct amc6821_data *data = amc6821_update_device(dev);
691646 return sprintf(buf, "%d\n", data->fan1_div);
692647 }
693648
694
-static ssize_t set_fan1_div(
695
- struct device *dev,
696
- struct device_attribute *attr,
697
- const char *buf, size_t count)
649
+static ssize_t fan1_div_store(struct device *dev,
650
+ struct device_attribute *attr, const char *buf,
651
+ size_t count)
698652 {
699653 struct amc6821_data *data = dev_get_drvdata(dev);
700654 struct i2c_client *client = data->client;
....@@ -734,69 +688,47 @@
734688 return count;
735689 }
736690
737
-static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO,
738
- get_temp, NULL, IDX_TEMP1_INPUT);
739
-static SENSOR_DEVICE_ATTR(temp1_min, S_IRUGO | S_IWUSR, get_temp,
740
- set_temp, IDX_TEMP1_MIN);
741
-static SENSOR_DEVICE_ATTR(temp1_max, S_IRUGO | S_IWUSR, get_temp,
742
- set_temp, IDX_TEMP1_MAX);
743
-static SENSOR_DEVICE_ATTR(temp1_crit, S_IRUGO | S_IWUSR, get_temp,
744
- set_temp, IDX_TEMP1_CRIT);
745
-static SENSOR_DEVICE_ATTR(temp1_min_alarm, S_IRUGO,
746
- get_temp_alarm, NULL, IDX_TEMP1_MIN);
747
-static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO,
748
- get_temp_alarm, NULL, IDX_TEMP1_MAX);
749
-static SENSOR_DEVICE_ATTR(temp1_crit_alarm, S_IRUGO,
750
- get_temp_alarm, NULL, IDX_TEMP1_CRIT);
751
-static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO,
752
- get_temp, NULL, IDX_TEMP2_INPUT);
753
-static SENSOR_DEVICE_ATTR(temp2_min, S_IRUGO | S_IWUSR, get_temp,
754
- set_temp, IDX_TEMP2_MIN);
755
-static SENSOR_DEVICE_ATTR(temp2_max, S_IRUGO | S_IWUSR, get_temp,
756
- set_temp, IDX_TEMP2_MAX);
757
-static SENSOR_DEVICE_ATTR(temp2_crit, S_IRUGO | S_IWUSR, get_temp,
758
- set_temp, IDX_TEMP2_CRIT);
759
-static SENSOR_DEVICE_ATTR(temp2_fault, S_IRUGO,
760
- get_temp2_fault, NULL, 0);
761
-static SENSOR_DEVICE_ATTR(temp2_min_alarm, S_IRUGO,
762
- get_temp_alarm, NULL, IDX_TEMP2_MIN);
763
-static SENSOR_DEVICE_ATTR(temp2_max_alarm, S_IRUGO,
764
- get_temp_alarm, NULL, IDX_TEMP2_MAX);
765
-static SENSOR_DEVICE_ATTR(temp2_crit_alarm, S_IRUGO,
766
- get_temp_alarm, NULL, IDX_TEMP2_CRIT);
767
-static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, get_fan, NULL, IDX_FAN1_INPUT);
768
-static SENSOR_DEVICE_ATTR(fan1_min, S_IRUGO | S_IWUSR,
769
- get_fan, set_fan, IDX_FAN1_MIN);
770
-static SENSOR_DEVICE_ATTR(fan1_max, S_IRUGO | S_IWUSR,
771
- get_fan, set_fan, IDX_FAN1_MAX);
772
-static SENSOR_DEVICE_ATTR(fan1_fault, S_IRUGO, get_fan1_fault, NULL, 0);
773
-static SENSOR_DEVICE_ATTR(fan1_div, S_IRUGO | S_IWUSR,
774
- get_fan1_div, set_fan1_div, 0);
691
+static SENSOR_DEVICE_ATTR_RO(temp1_input, temp, IDX_TEMP1_INPUT);
692
+static SENSOR_DEVICE_ATTR_RW(temp1_min, temp, IDX_TEMP1_MIN);
693
+static SENSOR_DEVICE_ATTR_RW(temp1_max, temp, IDX_TEMP1_MAX);
694
+static SENSOR_DEVICE_ATTR_RW(temp1_crit, temp, IDX_TEMP1_CRIT);
695
+static SENSOR_DEVICE_ATTR_RO(temp1_min_alarm, temp_alarm, IDX_TEMP1_MIN);
696
+static SENSOR_DEVICE_ATTR_RO(temp1_max_alarm, temp_alarm, IDX_TEMP1_MAX);
697
+static SENSOR_DEVICE_ATTR_RO(temp1_crit_alarm, temp_alarm, IDX_TEMP1_CRIT);
698
+static SENSOR_DEVICE_ATTR_RO(temp2_input, temp, IDX_TEMP2_INPUT);
699
+static SENSOR_DEVICE_ATTR_RW(temp2_min, temp, IDX_TEMP2_MIN);
700
+static SENSOR_DEVICE_ATTR_RW(temp2_max, temp, IDX_TEMP2_MAX);
701
+static SENSOR_DEVICE_ATTR_RW(temp2_crit, temp, IDX_TEMP2_CRIT);
702
+static SENSOR_DEVICE_ATTR_RO(temp2_fault, temp2_fault, 0);
703
+static SENSOR_DEVICE_ATTR_RO(temp2_min_alarm, temp_alarm, IDX_TEMP2_MIN);
704
+static SENSOR_DEVICE_ATTR_RO(temp2_max_alarm, temp_alarm, IDX_TEMP2_MAX);
705
+static SENSOR_DEVICE_ATTR_RO(temp2_crit_alarm, temp_alarm, IDX_TEMP2_CRIT);
706
+static SENSOR_DEVICE_ATTR_RO(fan1_input, fan, IDX_FAN1_INPUT);
707
+static SENSOR_DEVICE_ATTR_RW(fan1_min, fan, IDX_FAN1_MIN);
708
+static SENSOR_DEVICE_ATTR_RW(fan1_max, fan, IDX_FAN1_MAX);
709
+static SENSOR_DEVICE_ATTR_RO(fan1_fault, fan1_fault, 0);
710
+static SENSOR_DEVICE_ATTR_RW(fan1_div, fan1_div, 0);
775711
776
-static SENSOR_DEVICE_ATTR(pwm1, S_IWUSR | S_IRUGO, get_pwm1, set_pwm1, 0);
777
-static SENSOR_DEVICE_ATTR(pwm1_enable, S_IWUSR | S_IRUGO,
778
- get_pwm1_enable, set_pwm1_enable, 0);
779
-static SENSOR_DEVICE_ATTR(pwm1_auto_point1_pwm, S_IRUGO,
780
- get_pwm1_auto_point_pwm, NULL, 0);
781
-static SENSOR_DEVICE_ATTR(pwm1_auto_point2_pwm, S_IWUSR | S_IRUGO,
782
- get_pwm1_auto_point_pwm, set_pwm1_auto_point_pwm, 1);
783
-static SENSOR_DEVICE_ATTR(pwm1_auto_point3_pwm, S_IRUGO,
784
- get_pwm1_auto_point_pwm, NULL, 2);
785
-static SENSOR_DEVICE_ATTR(pwm1_auto_channels_temp, S_IRUGO,
786
- get_pwm1_auto_channels_temp, NULL, 0);
787
-static SENSOR_DEVICE_ATTR_2(temp1_auto_point1_temp, S_IRUGO,
788
- get_temp_auto_point_temp, NULL, 1, 0);
789
-static SENSOR_DEVICE_ATTR_2(temp1_auto_point2_temp, S_IWUSR | S_IRUGO,
790
- get_temp_auto_point_temp, set_temp_auto_point_temp, 1, 1);
791
-static SENSOR_DEVICE_ATTR_2(temp1_auto_point3_temp, S_IWUSR | S_IRUGO,
792
- get_temp_auto_point_temp, set_temp_auto_point_temp, 1, 2);
712
+static SENSOR_DEVICE_ATTR_RW(pwm1, pwm1, 0);
713
+static SENSOR_DEVICE_ATTR_RW(pwm1_enable, pwm1_enable, 0);
714
+static SENSOR_DEVICE_ATTR_RO(pwm1_auto_point1_pwm, pwm1_auto_point_pwm, 0);
715
+static SENSOR_DEVICE_ATTR_RW(pwm1_auto_point2_pwm, pwm1_auto_point_pwm, 1);
716
+static SENSOR_DEVICE_ATTR_RO(pwm1_auto_point3_pwm, pwm1_auto_point_pwm, 2);
717
+static SENSOR_DEVICE_ATTR_RO(pwm1_auto_channels_temp, pwm1_auto_channels_temp,
718
+ 0);
719
+static SENSOR_DEVICE_ATTR_2_RO(temp1_auto_point1_temp, temp_auto_point_temp,
720
+ 1, 0);
721
+static SENSOR_DEVICE_ATTR_2_RW(temp1_auto_point2_temp, temp_auto_point_temp,
722
+ 1, 1);
723
+static SENSOR_DEVICE_ATTR_2_RW(temp1_auto_point3_temp, temp_auto_point_temp,
724
+ 1, 2);
793725
794
-static SENSOR_DEVICE_ATTR_2(temp2_auto_point1_temp, S_IWUSR | S_IRUGO,
795
- get_temp_auto_point_temp, set_temp_auto_point_temp, 2, 0);
796
-static SENSOR_DEVICE_ATTR_2(temp2_auto_point2_temp, S_IWUSR | S_IRUGO,
797
- get_temp_auto_point_temp, set_temp_auto_point_temp, 2, 1);
798
-static SENSOR_DEVICE_ATTR_2(temp2_auto_point3_temp, S_IWUSR | S_IRUGO,
799
- get_temp_auto_point_temp, set_temp_auto_point_temp, 2, 2);
726
+static SENSOR_DEVICE_ATTR_2_RW(temp2_auto_point1_temp, temp_auto_point_temp,
727
+ 2, 0);
728
+static SENSOR_DEVICE_ATTR_2_RW(temp2_auto_point2_temp, temp_auto_point_temp,
729
+ 2, 1);
730
+static SENSOR_DEVICE_ATTR_2_RW(temp2_auto_point3_temp, temp_auto_point_temp,
731
+ 2, 2);
800732
801733 static struct attribute *amc6821_attrs[] = {
802734 &sensor_dev_attr_temp1_input.dev_attr.attr,
....@@ -968,8 +900,7 @@
968900 return 0;
969901 }
970902
971
-static int amc6821_probe(struct i2c_client *client,
972
- const struct i2c_device_id *id)
903
+static int amc6821_probe(struct i2c_client *client)
973904 {
974905 struct device *dev = &client->dev;
975906 struct amc6821_data *data;
....@@ -1008,7 +939,7 @@
1008939 .driver = {
1009940 .name = "amc6821",
1010941 },
1011
- .probe = amc6821_probe,
942
+ .probe_new = amc6821_probe,
1012943 .id_table = amc6821_id,
1013944 .detect = amc6821_detect,
1014945 .address_list = normal_i2c,