hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/hwmon/lm87.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * lm87.c
34 *
....@@ -39,21 +40,7 @@
3940 * This driver also supports the ADM1024, a sensor chip made by Analog
4041 * Devices. That chip is fully compatible with the LM87. Complete
4142 * datasheet can be obtained from Analog's website at:
42
- * http://www.analog.com/en/prod/0,2877,ADM1024,00.html
43
- *
44
- * This program is free software; you can redistribute it and/or modify
45
- * it under the terms of the GNU General Public License as published by
46
- * the Free Software Foundation; either version 2 of the License, or
47
- * (at your option) any later version.
48
- *
49
- * This program is distributed in the hope that it will be useful,
50
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
51
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
52
- * GNU General Public License for more details.
53
- *
54
- * You should have received a copy of the GNU General Public License
55
- * along with this program; if not, write to the Free Software
56
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
43
+ * https://www.analog.com/en/prod/0,2877,ADM1024,00.html
5744 */
5845
5946 #include <linux/module.h>
....@@ -276,8 +263,8 @@
276263 * Sysfs stuff
277264 */
278265
279
-static ssize_t show_in_input(struct device *dev, struct device_attribute *attr,
280
- char *buf)
266
+static ssize_t in_input_show(struct device *dev,
267
+ struct device_attribute *attr, char *buf)
281268 {
282269 struct lm87_data *data = lm87_update_device(dev);
283270 int nr = to_sensor_dev_attr(attr)->index;
....@@ -286,8 +273,8 @@
286273 data->in_scale[nr]));
287274 }
288275
289
-static ssize_t show_in_min(struct device *dev,
290
- struct device_attribute *attr, char *buf)
276
+static ssize_t in_min_show(struct device *dev, struct device_attribute *attr,
277
+ char *buf)
291278 {
292279 struct lm87_data *data = lm87_update_device(dev);
293280 int nr = to_sensor_dev_attr(attr)->index;
....@@ -296,8 +283,8 @@
296283 data->in_scale[nr]));
297284 }
298285
299
-static ssize_t show_in_max(struct device *dev,
300
- struct device_attribute *attr, char *buf)
286
+static ssize_t in_max_show(struct device *dev, struct device_attribute *attr,
287
+ char *buf)
301288 {
302289 struct lm87_data *data = lm87_update_device(dev);
303290 int nr = to_sensor_dev_attr(attr)->index;
....@@ -306,8 +293,8 @@
306293 data->in_scale[nr]));
307294 }
308295
309
-static ssize_t set_in_min(struct device *dev, struct device_attribute *attr,
310
- const char *buf, size_t count)
296
+static ssize_t in_min_store(struct device *dev, struct device_attribute *attr,
297
+ const char *buf, size_t count)
311298 {
312299 struct i2c_client *client = dev_get_drvdata(dev);
313300 struct lm87_data *data = i2c_get_clientdata(client);
....@@ -327,8 +314,8 @@
327314 return count;
328315 }
329316
330
-static ssize_t set_in_max(struct device *dev, struct device_attribute *attr,
331
- const char *buf, size_t count)
317
+static ssize_t in_max_store(struct device *dev, struct device_attribute *attr,
318
+ const char *buf, size_t count)
332319 {
333320 struct i2c_client *client = dev_get_drvdata(dev);
334321 struct lm87_data *data = i2c_get_clientdata(client);
....@@ -348,23 +335,32 @@
348335 return count;
349336 }
350337
351
-#define set_in(offset) \
352
-static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, \
353
- show_in_input, NULL, offset); \
354
-static SENSOR_DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \
355
- show_in_min, set_in_min, offset); \
356
-static SENSOR_DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \
357
- show_in_max, set_in_max, offset)
358
-set_in(0);
359
-set_in(1);
360
-set_in(2);
361
-set_in(3);
362
-set_in(4);
363
-set_in(5);
364
-set_in(6);
365
-set_in(7);
338
+static SENSOR_DEVICE_ATTR_RO(in0_input, in_input, 0);
339
+static SENSOR_DEVICE_ATTR_RW(in0_min, in_min, 0);
340
+static SENSOR_DEVICE_ATTR_RW(in0_max, in_max, 0);
341
+static SENSOR_DEVICE_ATTR_RO(in1_input, in_input, 1);
342
+static SENSOR_DEVICE_ATTR_RW(in1_min, in_min, 1);
343
+static SENSOR_DEVICE_ATTR_RW(in1_max, in_max, 1);
344
+static SENSOR_DEVICE_ATTR_RO(in2_input, in_input, 2);
345
+static SENSOR_DEVICE_ATTR_RW(in2_min, in_min, 2);
346
+static SENSOR_DEVICE_ATTR_RW(in2_max, in_max, 2);
347
+static SENSOR_DEVICE_ATTR_RO(in3_input, in_input, 3);
348
+static SENSOR_DEVICE_ATTR_RW(in3_min, in_min, 3);
349
+static SENSOR_DEVICE_ATTR_RW(in3_max, in_max, 3);
350
+static SENSOR_DEVICE_ATTR_RO(in4_input, in_input, 4);
351
+static SENSOR_DEVICE_ATTR_RW(in4_min, in_min, 4);
352
+static SENSOR_DEVICE_ATTR_RW(in4_max, in_max, 4);
353
+static SENSOR_DEVICE_ATTR_RO(in5_input, in_input, 5);
354
+static SENSOR_DEVICE_ATTR_RW(in5_min, in_min, 5);
355
+static SENSOR_DEVICE_ATTR_RW(in5_max, in_max, 5);
356
+static SENSOR_DEVICE_ATTR_RO(in6_input, in_input, 6);
357
+static SENSOR_DEVICE_ATTR_RW(in6_min, in_min, 6);
358
+static SENSOR_DEVICE_ATTR_RW(in6_max, in_max, 6);
359
+static SENSOR_DEVICE_ATTR_RO(in7_input, in_input, 7);
360
+static SENSOR_DEVICE_ATTR_RW(in7_min, in_min, 7);
361
+static SENSOR_DEVICE_ATTR_RW(in7_max, in_max, 7);
366362
367
-static ssize_t show_temp_input(struct device *dev,
363
+static ssize_t temp_input_show(struct device *dev,
368364 struct device_attribute *attr, char *buf)
369365 {
370366 struct lm87_data *data = lm87_update_device(dev);
....@@ -373,7 +369,7 @@
373369 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[nr]));
374370 }
375371
376
-static ssize_t show_temp_low(struct device *dev,
372
+static ssize_t temp_low_show(struct device *dev,
377373 struct device_attribute *attr, char *buf)
378374 {
379375 struct lm87_data *data = lm87_update_device(dev);
....@@ -383,7 +379,7 @@
383379 TEMP_FROM_REG(data->temp_low[nr]));
384380 }
385381
386
-static ssize_t show_temp_high(struct device *dev,
382
+static ssize_t temp_high_show(struct device *dev,
387383 struct device_attribute *attr, char *buf)
388384 {
389385 struct lm87_data *data = lm87_update_device(dev);
....@@ -393,8 +389,9 @@
393389 TEMP_FROM_REG(data->temp_high[nr]));
394390 }
395391
396
-static ssize_t set_temp_low(struct device *dev, struct device_attribute *attr,
397
- const char *buf, size_t count)
392
+static ssize_t temp_low_store(struct device *dev,
393
+ struct device_attribute *attr, const char *buf,
394
+ size_t count)
398395 {
399396 struct i2c_client *client = dev_get_drvdata(dev);
400397 struct lm87_data *data = i2c_get_clientdata(client);
....@@ -413,8 +410,9 @@
413410 return count;
414411 }
415412
416
-static ssize_t set_temp_high(struct device *dev, struct device_attribute *attr,
417
- const char *buf, size_t count)
413
+static ssize_t temp_high_store(struct device *dev,
414
+ struct device_attribute *attr, const char *buf,
415
+ size_t count)
418416 {
419417 struct i2c_client *client = dev_get_drvdata(dev);
420418 struct lm87_data *data = i2c_get_clientdata(client);
....@@ -433,16 +431,15 @@
433431 return count;
434432 }
435433
436
-#define set_temp(offset) \
437
-static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, \
438
- show_temp_input, NULL, offset - 1); \
439
-static SENSOR_DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \
440
- show_temp_high, set_temp_high, offset - 1); \
441
-static SENSOR_DEVICE_ATTR(temp##offset##_min, S_IRUGO | S_IWUSR, \
442
- show_temp_low, set_temp_low, offset - 1)
443
-set_temp(1);
444
-set_temp(2);
445
-set_temp(3);
434
+static SENSOR_DEVICE_ATTR_RO(temp1_input, temp_input, 0);
435
+static SENSOR_DEVICE_ATTR_RW(temp1_min, temp_low, 0);
436
+static SENSOR_DEVICE_ATTR_RW(temp1_max, temp_high, 0);
437
+static SENSOR_DEVICE_ATTR_RO(temp2_input, temp_input, 1);
438
+static SENSOR_DEVICE_ATTR_RW(temp2_min, temp_low, 1);
439
+static SENSOR_DEVICE_ATTR_RW(temp2_max, temp_high, 1);
440
+static SENSOR_DEVICE_ATTR_RO(temp3_input, temp_input, 2);
441
+static SENSOR_DEVICE_ATTR_RW(temp3_min, temp_low, 2);
442
+static SENSOR_DEVICE_ATTR_RW(temp3_max, temp_high, 2);
446443
447444 static ssize_t temp1_crit_show(struct device *dev,
448445 struct device_attribute *attr, char *buf)
....@@ -460,9 +457,9 @@
460457
461458 static DEVICE_ATTR_RO(temp1_crit);
462459 static DEVICE_ATTR_RO(temp2_crit);
463
-static DEVICE_ATTR(temp3_crit, S_IRUGO, temp2_crit_show, NULL);
460
+static DEVICE_ATTR(temp3_crit, 0444, temp2_crit_show, NULL);
464461
465
-static ssize_t show_fan_input(struct device *dev,
462
+static ssize_t fan_input_show(struct device *dev,
466463 struct device_attribute *attr, char *buf)
467464 {
468465 struct lm87_data *data = lm87_update_device(dev);
....@@ -472,8 +469,8 @@
472469 FAN_DIV_FROM_REG(data->fan_div[nr])));
473470 }
474471
475
-static ssize_t show_fan_min(struct device *dev,
476
- struct device_attribute *attr, char *buf)
472
+static ssize_t fan_min_show(struct device *dev, struct device_attribute *attr,
473
+ char *buf)
477474 {
478475 struct lm87_data *data = lm87_update_device(dev);
479476 int nr = to_sensor_dev_attr(attr)->index;
....@@ -482,8 +479,8 @@
482479 FAN_DIV_FROM_REG(data->fan_div[nr])));
483480 }
484481
485
-static ssize_t show_fan_div(struct device *dev,
486
- struct device_attribute *attr, char *buf)
482
+static ssize_t fan_div_show(struct device *dev, struct device_attribute *attr,
483
+ char *buf)
487484 {
488485 struct lm87_data *data = lm87_update_device(dev);
489486 int nr = to_sensor_dev_attr(attr)->index;
....@@ -492,8 +489,9 @@
492489 FAN_DIV_FROM_REG(data->fan_div[nr]));
493490 }
494491
495
-static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr,
496
- const char *buf, size_t count)
492
+static ssize_t fan_min_store(struct device *dev,
493
+ struct device_attribute *attr, const char *buf,
494
+ size_t count)
497495 {
498496 struct i2c_client *client = dev_get_drvdata(dev);
499497 struct lm87_data *data = i2c_get_clientdata(client);
....@@ -519,8 +517,9 @@
519517 * of least surprise; the user doesn't expect the fan minimum to change just
520518 * because the divider changed.
521519 */
522
-static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
523
- const char *buf, size_t count)
520
+static ssize_t fan_div_store(struct device *dev,
521
+ struct device_attribute *attr, const char *buf,
522
+ size_t count)
524523 {
525524 struct i2c_client *client = dev_get_drvdata(dev);
526525 struct lm87_data *data = i2c_get_clientdata(client);
....@@ -575,15 +574,12 @@
575574 return count;
576575 }
577576
578
-#define set_fan(offset) \
579
-static SENSOR_DEVICE_ATTR(fan##offset##_input, S_IRUGO, \
580
- show_fan_input, NULL, offset - 1); \
581
-static SENSOR_DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
582
- show_fan_min, set_fan_min, offset - 1); \
583
-static SENSOR_DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \
584
- show_fan_div, set_fan_div, offset - 1)
585
-set_fan(1);
586
-set_fan(2);
577
+static SENSOR_DEVICE_ATTR_RO(fan1_input, fan_input, 0);
578
+static SENSOR_DEVICE_ATTR_RW(fan1_min, fan_min, 0);
579
+static SENSOR_DEVICE_ATTR_RW(fan1_div, fan_div, 0);
580
+static SENSOR_DEVICE_ATTR_RO(fan2_input, fan_input, 1);
581
+static SENSOR_DEVICE_ATTR_RW(fan2_min, fan_min, 1);
582
+static SENSOR_DEVICE_ATTR_RW(fan2_div, fan_div, 1);
587583
588584 static ssize_t alarms_show(struct device *dev, struct device_attribute *attr,
589585 char *buf)
....@@ -653,28 +649,28 @@
653649 }
654650 static DEVICE_ATTR_RW(aout_output);
655651
656
-static ssize_t show_alarm(struct device *dev, struct device_attribute *attr,
652
+static ssize_t alarm_show(struct device *dev, struct device_attribute *attr,
657653 char *buf)
658654 {
659655 struct lm87_data *data = lm87_update_device(dev);
660656 int bitnr = to_sensor_dev_attr(attr)->index;
661657 return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1);
662658 }
663
-static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 0);
664
-static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 1);
665
-static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 2);
666
-static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 3);
667
-static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 8);
668
-static SENSOR_DEVICE_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL, 9);
669
-static SENSOR_DEVICE_ATTR(in6_alarm, S_IRUGO, show_alarm, NULL, 6);
670
-static SENSOR_DEVICE_ATTR(in7_alarm, S_IRUGO, show_alarm, NULL, 7);
671
-static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 4);
672
-static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 5);
673
-static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 5);
674
-static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 6);
675
-static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 7);
676
-static SENSOR_DEVICE_ATTR(temp2_fault, S_IRUGO, show_alarm, NULL, 14);
677
-static SENSOR_DEVICE_ATTR(temp3_fault, S_IRUGO, show_alarm, NULL, 15);
659
+static SENSOR_DEVICE_ATTR_RO(in0_alarm, alarm, 0);
660
+static SENSOR_DEVICE_ATTR_RO(in1_alarm, alarm, 1);
661
+static SENSOR_DEVICE_ATTR_RO(in2_alarm, alarm, 2);
662
+static SENSOR_DEVICE_ATTR_RO(in3_alarm, alarm, 3);
663
+static SENSOR_DEVICE_ATTR_RO(in4_alarm, alarm, 8);
664
+static SENSOR_DEVICE_ATTR_RO(in5_alarm, alarm, 9);
665
+static SENSOR_DEVICE_ATTR_RO(in6_alarm, alarm, 6);
666
+static SENSOR_DEVICE_ATTR_RO(in7_alarm, alarm, 7);
667
+static SENSOR_DEVICE_ATTR_RO(temp1_alarm, alarm, 4);
668
+static SENSOR_DEVICE_ATTR_RO(temp2_alarm, alarm, 5);
669
+static SENSOR_DEVICE_ATTR_RO(temp3_alarm, alarm, 5);
670
+static SENSOR_DEVICE_ATTR_RO(fan1_alarm, alarm, 6);
671
+static SENSOR_DEVICE_ATTR_RO(fan2_alarm, alarm, 7);
672
+static SENSOR_DEVICE_ATTR_RO(temp2_fault, alarm, 14);
673
+static SENSOR_DEVICE_ATTR_RO(temp3_fault, alarm, 15);
678674
679675 /*
680676 * Real code
....@@ -916,7 +912,7 @@
916912 return 0;
917913 }
918914
919
-static int lm87_probe(struct i2c_client *client, const struct i2c_device_id *id)
915
+static int lm87_probe(struct i2c_client *client)
920916 {
921917 struct lm87_data *data;
922918 struct device *hwmon_dev;
....@@ -998,7 +994,7 @@
998994 .name = "lm87",
999995 .of_match_table = lm87_of_match,
1000996 },
1001
- .probe = lm87_probe,
997
+ .probe_new = lm87_probe,
1002998 .id_table = lm87_id,
1003999 .detect = lm87_detect,
10041000 .address_list = normal_i2c,