hc
2024-05-11 04dd17822334871b23ea2862f7798fb0e0007777
kernel/drivers/hwmon/lm95234.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * Driver for Texas Instruments / National Semiconductor LM95234
34 *
....@@ -5,16 +6,6 @@
56 *
67 * Derived from lm95241.c
78 * Copyright (C) 2008, 2010 Davide Rizzo <elpa.rizzo@gmail.com>
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.
189 */
1910
2011 #include <linux/module.h>
....@@ -211,7 +202,7 @@
211202 return ret;
212203 }
213204
214
-static ssize_t show_temp(struct device *dev, struct device_attribute *attr,
205
+static ssize_t temp_show(struct device *dev, struct device_attribute *attr,
215206 char *buf)
216207 {
217208 struct lm95234_data *data = dev_get_drvdata(dev);
....@@ -225,8 +216,8 @@
225216 DIV_ROUND_CLOSEST(data->temp[index] * 125, 32));
226217 }
227218
228
-static ssize_t show_alarm(struct device *dev,
229
- struct device_attribute *attr, char *buf)
219
+static ssize_t alarm_show(struct device *dev, struct device_attribute *attr,
220
+ char *buf)
230221 {
231222 struct lm95234_data *data = dev_get_drvdata(dev);
232223 u32 mask = to_sensor_dev_attr(attr)->index;
....@@ -238,7 +229,7 @@
238229 return sprintf(buf, "%u", !!(data->status & mask));
239230 }
240231
241
-static ssize_t show_type(struct device *dev, struct device_attribute *attr,
232
+static ssize_t type_show(struct device *dev, struct device_attribute *attr,
242233 char *buf)
243234 {
244235 struct lm95234_data *data = dev_get_drvdata(dev);
....@@ -251,8 +242,8 @@
251242 return sprintf(buf, data->sensor_type & mask ? "1\n" : "2\n");
252243 }
253244
254
-static ssize_t set_type(struct device *dev, struct device_attribute *attr,
255
- const char *buf, size_t count)
245
+static ssize_t type_store(struct device *dev, struct device_attribute *attr,
246
+ const char *buf, size_t count)
256247 {
257248 struct lm95234_data *data = dev_get_drvdata(dev);
258249 unsigned long val;
....@@ -282,7 +273,7 @@
282273 return count;
283274 }
284275
285
-static ssize_t show_tcrit2(struct device *dev, struct device_attribute *attr,
276
+static ssize_t tcrit2_show(struct device *dev, struct device_attribute *attr,
286277 char *buf)
287278 {
288279 struct lm95234_data *data = dev_get_drvdata(dev);
....@@ -295,8 +286,8 @@
295286 return sprintf(buf, "%u", data->tcrit2[index] * 1000);
296287 }
297288
298
-static ssize_t set_tcrit2(struct device *dev, struct device_attribute *attr,
299
- const char *buf, size_t count)
289
+static ssize_t tcrit2_store(struct device *dev, struct device_attribute *attr,
290
+ const char *buf, size_t count)
300291 {
301292 struct lm95234_data *data = dev_get_drvdata(dev);
302293 int index = to_sensor_dev_attr(attr)->index;
....@@ -320,7 +311,7 @@
320311 return count;
321312 }
322313
323
-static ssize_t show_tcrit2_hyst(struct device *dev,
314
+static ssize_t tcrit2_hyst_show(struct device *dev,
324315 struct device_attribute *attr, char *buf)
325316 {
326317 struct lm95234_data *data = dev_get_drvdata(dev);
....@@ -335,7 +326,7 @@
335326 ((int)data->tcrit2[index] - (int)data->thyst) * 1000);
336327 }
337328
338
-static ssize_t show_tcrit1(struct device *dev, struct device_attribute *attr,
329
+static ssize_t tcrit1_show(struct device *dev, struct device_attribute *attr,
339330 char *buf)
340331 {
341332 struct lm95234_data *data = dev_get_drvdata(dev);
....@@ -344,8 +335,8 @@
344335 return sprintf(buf, "%u", data->tcrit1[index] * 1000);
345336 }
346337
347
-static ssize_t set_tcrit1(struct device *dev, struct device_attribute *attr,
348
- const char *buf, size_t count)
338
+static ssize_t tcrit1_store(struct device *dev, struct device_attribute *attr,
339
+ const char *buf, size_t count)
349340 {
350341 struct lm95234_data *data = dev_get_drvdata(dev);
351342 int index = to_sensor_dev_attr(attr)->index;
....@@ -369,7 +360,7 @@
369360 return count;
370361 }
371362
372
-static ssize_t show_tcrit1_hyst(struct device *dev,
363
+static ssize_t tcrit1_hyst_show(struct device *dev,
373364 struct device_attribute *attr, char *buf)
374365 {
375366 struct lm95234_data *data = dev_get_drvdata(dev);
....@@ -384,9 +375,9 @@
384375 ((int)data->tcrit1[index] - (int)data->thyst) * 1000);
385376 }
386377
387
-static ssize_t set_tcrit1_hyst(struct device *dev,
388
- struct device_attribute *attr,
389
- const char *buf, size_t count)
378
+static ssize_t tcrit1_hyst_store(struct device *dev,
379
+ struct device_attribute *attr,
380
+ const char *buf, size_t count)
390381 {
391382 struct lm95234_data *data = dev_get_drvdata(dev);
392383 int index = to_sensor_dev_attr(attr)->index;
....@@ -411,7 +402,7 @@
411402 return count;
412403 }
413404
414
-static ssize_t show_offset(struct device *dev, struct device_attribute *attr,
405
+static ssize_t offset_show(struct device *dev, struct device_attribute *attr,
415406 char *buf)
416407 {
417408 struct lm95234_data *data = dev_get_drvdata(dev);
....@@ -424,8 +415,8 @@
424415 return sprintf(buf, "%d", data->toffset[index] * 500);
425416 }
426417
427
-static ssize_t set_offset(struct device *dev, struct device_attribute *attr,
428
- const char *buf, size_t count)
418
+static ssize_t offset_store(struct device *dev, struct device_attribute *attr,
419
+ const char *buf, size_t count)
429420 {
430421 struct lm95234_data *data = dev_get_drvdata(dev);
431422 int index = to_sensor_dev_attr(attr)->index;
....@@ -492,80 +483,53 @@
492483 return count;
493484 }
494485
495
-static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0);
496
-static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_temp, NULL, 1);
497
-static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO, show_temp, NULL, 2);
498
-static SENSOR_DEVICE_ATTR(temp4_input, S_IRUGO, show_temp, NULL, 3);
499
-static SENSOR_DEVICE_ATTR(temp5_input, S_IRUGO, show_temp, NULL, 4);
486
+static SENSOR_DEVICE_ATTR_RO(temp1_input, temp, 0);
487
+static SENSOR_DEVICE_ATTR_RO(temp2_input, temp, 1);
488
+static SENSOR_DEVICE_ATTR_RO(temp3_input, temp, 2);
489
+static SENSOR_DEVICE_ATTR_RO(temp4_input, temp, 3);
490
+static SENSOR_DEVICE_ATTR_RO(temp5_input, temp, 4);
500491
501
-static SENSOR_DEVICE_ATTR(temp2_fault, S_IRUGO, show_alarm, NULL,
502
- BIT(0) | BIT(1));
503
-static SENSOR_DEVICE_ATTR(temp3_fault, S_IRUGO, show_alarm, NULL,
504
- BIT(2) | BIT(3));
505
-static SENSOR_DEVICE_ATTR(temp4_fault, S_IRUGO, show_alarm, NULL,
506
- BIT(4) | BIT(5));
507
-static SENSOR_DEVICE_ATTR(temp5_fault, S_IRUGO, show_alarm, NULL,
508
- BIT(6) | BIT(7));
492
+static SENSOR_DEVICE_ATTR_RO(temp2_fault, alarm, BIT(0) | BIT(1));
493
+static SENSOR_DEVICE_ATTR_RO(temp3_fault, alarm, BIT(2) | BIT(3));
494
+static SENSOR_DEVICE_ATTR_RO(temp4_fault, alarm, BIT(4) | BIT(5));
495
+static SENSOR_DEVICE_ATTR_RO(temp5_fault, alarm, BIT(6) | BIT(7));
509496
510
-static SENSOR_DEVICE_ATTR(temp2_type, S_IWUSR | S_IRUGO, show_type, set_type,
511
- BIT(1));
512
-static SENSOR_DEVICE_ATTR(temp3_type, S_IWUSR | S_IRUGO, show_type, set_type,
513
- BIT(2));
514
-static SENSOR_DEVICE_ATTR(temp4_type, S_IWUSR | S_IRUGO, show_type, set_type,
515
- BIT(3));
516
-static SENSOR_DEVICE_ATTR(temp5_type, S_IWUSR | S_IRUGO, show_type, set_type,
517
- BIT(4));
497
+static SENSOR_DEVICE_ATTR_RW(temp2_type, type, BIT(1));
498
+static SENSOR_DEVICE_ATTR_RW(temp3_type, type, BIT(2));
499
+static SENSOR_DEVICE_ATTR_RW(temp4_type, type, BIT(3));
500
+static SENSOR_DEVICE_ATTR_RW(temp5_type, type, BIT(4));
518501
519
-static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_tcrit1,
520
- set_tcrit1, 0);
521
-static SENSOR_DEVICE_ATTR(temp2_max, S_IWUSR | S_IRUGO, show_tcrit2,
522
- set_tcrit2, 0);
523
-static SENSOR_DEVICE_ATTR(temp3_max, S_IWUSR | S_IRUGO, show_tcrit2,
524
- set_tcrit2, 1);
525
-static SENSOR_DEVICE_ATTR(temp4_max, S_IWUSR | S_IRUGO, show_tcrit1,
526
- set_tcrit1, 3);
527
-static SENSOR_DEVICE_ATTR(temp5_max, S_IWUSR | S_IRUGO, show_tcrit1,
528
- set_tcrit1, 4);
502
+static SENSOR_DEVICE_ATTR_RW(temp1_max, tcrit1, 0);
503
+static SENSOR_DEVICE_ATTR_RW(temp2_max, tcrit2, 0);
504
+static SENSOR_DEVICE_ATTR_RW(temp3_max, tcrit2, 1);
505
+static SENSOR_DEVICE_ATTR_RW(temp4_max, tcrit1, 3);
506
+static SENSOR_DEVICE_ATTR_RW(temp5_max, tcrit1, 4);
529507
530
-static SENSOR_DEVICE_ATTR(temp1_max_hyst, S_IWUSR | S_IRUGO, show_tcrit1_hyst,
531
- set_tcrit1_hyst, 0);
532
-static SENSOR_DEVICE_ATTR(temp2_max_hyst, S_IRUGO, show_tcrit2_hyst, NULL, 0);
533
-static SENSOR_DEVICE_ATTR(temp3_max_hyst, S_IRUGO, show_tcrit2_hyst, NULL, 1);
534
-static SENSOR_DEVICE_ATTR(temp4_max_hyst, S_IRUGO, show_tcrit1_hyst, NULL, 3);
535
-static SENSOR_DEVICE_ATTR(temp5_max_hyst, S_IRUGO, show_tcrit1_hyst, NULL, 4);
508
+static SENSOR_DEVICE_ATTR_RW(temp1_max_hyst, tcrit1_hyst, 0);
509
+static SENSOR_DEVICE_ATTR_RO(temp2_max_hyst, tcrit2_hyst, 0);
510
+static SENSOR_DEVICE_ATTR_RO(temp3_max_hyst, tcrit2_hyst, 1);
511
+static SENSOR_DEVICE_ATTR_RO(temp4_max_hyst, tcrit1_hyst, 3);
512
+static SENSOR_DEVICE_ATTR_RO(temp5_max_hyst, tcrit1_hyst, 4);
536513
537
-static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL,
538
- BIT(0 + 8));
539
-static SENSOR_DEVICE_ATTR(temp2_max_alarm, S_IRUGO, show_alarm, NULL,
540
- BIT(1 + 16));
541
-static SENSOR_DEVICE_ATTR(temp3_max_alarm, S_IRUGO, show_alarm, NULL,
542
- BIT(2 + 16));
543
-static SENSOR_DEVICE_ATTR(temp4_max_alarm, S_IRUGO, show_alarm, NULL,
544
- BIT(3 + 8));
545
-static SENSOR_DEVICE_ATTR(temp5_max_alarm, S_IRUGO, show_alarm, NULL,
546
- BIT(4 + 8));
514
+static SENSOR_DEVICE_ATTR_RO(temp1_max_alarm, alarm, BIT(0 + 8));
515
+static SENSOR_DEVICE_ATTR_RO(temp2_max_alarm, alarm, BIT(1 + 16));
516
+static SENSOR_DEVICE_ATTR_RO(temp3_max_alarm, alarm, BIT(2 + 16));
517
+static SENSOR_DEVICE_ATTR_RO(temp4_max_alarm, alarm, BIT(3 + 8));
518
+static SENSOR_DEVICE_ATTR_RO(temp5_max_alarm, alarm, BIT(4 + 8));
547519
548
-static SENSOR_DEVICE_ATTR(temp2_crit, S_IWUSR | S_IRUGO, show_tcrit1,
549
- set_tcrit1, 1);
550
-static SENSOR_DEVICE_ATTR(temp3_crit, S_IWUSR | S_IRUGO, show_tcrit1,
551
- set_tcrit1, 2);
520
+static SENSOR_DEVICE_ATTR_RW(temp2_crit, tcrit1, 1);
521
+static SENSOR_DEVICE_ATTR_RW(temp3_crit, tcrit1, 2);
552522
553
-static SENSOR_DEVICE_ATTR(temp2_crit_hyst, S_IRUGO, show_tcrit1_hyst, NULL, 1);
554
-static SENSOR_DEVICE_ATTR(temp3_crit_hyst, S_IRUGO, show_tcrit1_hyst, NULL, 2);
523
+static SENSOR_DEVICE_ATTR_RO(temp2_crit_hyst, tcrit1_hyst, 1);
524
+static SENSOR_DEVICE_ATTR_RO(temp3_crit_hyst, tcrit1_hyst, 2);
555525
556
-static SENSOR_DEVICE_ATTR(temp2_crit_alarm, S_IRUGO, show_alarm, NULL,
557
- BIT(1 + 8));
558
-static SENSOR_DEVICE_ATTR(temp3_crit_alarm, S_IRUGO, show_alarm, NULL,
559
- BIT(2 + 8));
526
+static SENSOR_DEVICE_ATTR_RO(temp2_crit_alarm, alarm, BIT(1 + 8));
527
+static SENSOR_DEVICE_ATTR_RO(temp3_crit_alarm, alarm, BIT(2 + 8));
560528
561
-static SENSOR_DEVICE_ATTR(temp2_offset, S_IWUSR | S_IRUGO, show_offset,
562
- set_offset, 0);
563
-static SENSOR_DEVICE_ATTR(temp3_offset, S_IWUSR | S_IRUGO, show_offset,
564
- set_offset, 1);
565
-static SENSOR_DEVICE_ATTR(temp4_offset, S_IWUSR | S_IRUGO, show_offset,
566
- set_offset, 2);
567
-static SENSOR_DEVICE_ATTR(temp5_offset, S_IWUSR | S_IRUGO, show_offset,
568
- set_offset, 3);
529
+static SENSOR_DEVICE_ATTR_RW(temp2_offset, offset, 0);
530
+static SENSOR_DEVICE_ATTR_RW(temp3_offset, offset, 1);
531
+static SENSOR_DEVICE_ATTR_RW(temp4_offset, offset, 2);
532
+static SENSOR_DEVICE_ATTR_RW(temp5_offset, offset, 3);
569533
570534 static DEVICE_ATTR_RW(update_interval);
571535
....@@ -713,8 +677,9 @@
713677 return 0;
714678 }
715679
716
-static int lm95234_probe(struct i2c_client *client,
717
- const struct i2c_device_id *id)
680
+static const struct i2c_device_id lm95234_id[];
681
+
682
+static int lm95234_probe(struct i2c_client *client)
718683 {
719684 struct device *dev = &client->dev;
720685 struct lm95234_data *data;
....@@ -734,7 +699,7 @@
734699 return err;
735700
736701 data->groups[0] = &lm95234_common_group;
737
- if (id->driver_data == lm95234)
702
+ if (i2c_match_id(lm95234_id, client)->driver_data == lm95234)
738703 data->groups[1] = &lm95234_group;
739704
740705 hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name,
....@@ -755,7 +720,7 @@
755720 .driver = {
756721 .name = DRVNAME,
757722 },
758
- .probe = lm95234_probe,
723
+ .probe_new = lm95234_probe,
759724 .id_table = lm95234_id,
760725 .detect = lm95234_detect,
761726 .address_list = normal_i2c,