hc
2024-02-19 1c055e55a242a33e574e48be530e06770a210dcd
kernel/drivers/hwmon/tmp401.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /* tmp401.c
23 *
34 * Copyright (C) 2007,2008 Hans de Goede <hdegoede@redhat.com>
....@@ -7,20 +8,6 @@
78 *
89 * Cleanup and support for TMP431 and TMP432 by Guenter Roeck
910 * Copyright (c) 2013 Guenter Roeck <linux@roeck-us.net>
10
- *
11
- * This program is free software; you can redistribute it and/or modify
12
- * it under the terms of the GNU General Public License as published by
13
- * the Free Software Foundation; either version 2 of the License, or
14
- * (at your option) any later version.
15
- *
16
- * This program is distributed in the hope that it will be useful,
17
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
- * GNU General Public License for more details.
20
- *
21
- * You should have received a copy of the GNU General Public License
22
- * along with this program; if not, write to the Free Software
23
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
2411 */
2512
2613 /*
....@@ -288,8 +275,8 @@
288275 return ret;
289276 }
290277
291
-static ssize_t show_temp(struct device *dev,
292
- struct device_attribute *devattr, char *buf)
278
+static ssize_t temp_show(struct device *dev, struct device_attribute *devattr,
279
+ char *buf)
293280 {
294281 int nr = to_sensor_dev_attr_2(devattr)->nr;
295282 int index = to_sensor_dev_attr_2(devattr)->index;
....@@ -302,8 +289,9 @@
302289 tmp401_register_to_temp(data->temp[nr][index], data->config));
303290 }
304291
305
-static ssize_t show_temp_crit_hyst(struct device *dev,
306
- struct device_attribute *devattr, char *buf)
292
+static ssize_t temp_crit_hyst_show(struct device *dev,
293
+ struct device_attribute *devattr,
294
+ char *buf)
307295 {
308296 int temp, index = to_sensor_dev_attr(devattr)->index;
309297 struct tmp401_data *data = tmp401_update_device(dev);
....@@ -319,8 +307,8 @@
319307 return sprintf(buf, "%d\n", temp);
320308 }
321309
322
-static ssize_t show_status(struct device *dev,
323
- struct device_attribute *devattr, char *buf)
310
+static ssize_t status_show(struct device *dev,
311
+ struct device_attribute *devattr, char *buf)
324312 {
325313 int nr = to_sensor_dev_attr_2(devattr)->nr;
326314 int mask = to_sensor_dev_attr_2(devattr)->index;
....@@ -332,8 +320,9 @@
332320 return sprintf(buf, "%d\n", !!(data->status[nr] & mask));
333321 }
334322
335
-static ssize_t store_temp(struct device *dev, struct device_attribute *devattr,
336
- const char *buf, size_t count)
323
+static ssize_t temp_store(struct device *dev,
324
+ struct device_attribute *devattr, const char *buf,
325
+ size_t count)
337326 {
338327 int nr = to_sensor_dev_attr_2(devattr)->nr;
339328 int index = to_sensor_dev_attr_2(devattr)->index;
....@@ -365,8 +354,9 @@
365354 return count;
366355 }
367356
368
-static ssize_t store_temp_crit_hyst(struct device *dev, struct device_attribute
369
- *devattr, const char *buf, size_t count)
357
+static ssize_t temp_crit_hyst_store(struct device *dev,
358
+ struct device_attribute *devattr,
359
+ const char *buf, size_t count)
370360 {
371361 int temp, index = to_sensor_dev_attr(devattr)->index;
372362 struct tmp401_data *data = tmp401_update_device(dev);
....@@ -404,8 +394,9 @@
404394 * This is done by writing any value to any of the minimum/maximum registers
405395 * (0x30-0x37).
406396 */
407
-static ssize_t reset_temp_history(struct device *dev,
408
- struct device_attribute *devattr, const char *buf, size_t count)
397
+static ssize_t reset_temp_history_store(struct device *dev,
398
+ struct device_attribute *devattr,
399
+ const char *buf, size_t count)
409400 {
410401 struct tmp401_data *data = dev_get_drvdata(dev);
411402 struct i2c_client *client = data->client;
....@@ -467,38 +458,29 @@
467458 return count;
468459 }
469460
470
-static SENSOR_DEVICE_ATTR_2(temp1_input, S_IRUGO, show_temp, NULL, 0, 0);
471
-static SENSOR_DEVICE_ATTR_2(temp1_min, S_IWUSR | S_IRUGO, show_temp,
472
- store_temp, 1, 0);
473
-static SENSOR_DEVICE_ATTR_2(temp1_max, S_IWUSR | S_IRUGO, show_temp,
474
- store_temp, 2, 0);
475
-static SENSOR_DEVICE_ATTR_2(temp1_crit, S_IWUSR | S_IRUGO, show_temp,
476
- store_temp, 3, 0);
477
-static SENSOR_DEVICE_ATTR(temp1_crit_hyst, S_IWUSR | S_IRUGO,
478
- show_temp_crit_hyst, store_temp_crit_hyst, 0);
479
-static SENSOR_DEVICE_ATTR_2(temp1_min_alarm, S_IRUGO, show_status, NULL,
480
- 1, TMP432_STATUS_LOCAL);
481
-static SENSOR_DEVICE_ATTR_2(temp1_max_alarm, S_IRUGO, show_status, NULL,
482
- 2, TMP432_STATUS_LOCAL);
483
-static SENSOR_DEVICE_ATTR_2(temp1_crit_alarm, S_IRUGO, show_status, NULL,
484
- 3, TMP432_STATUS_LOCAL);
485
-static SENSOR_DEVICE_ATTR_2(temp2_input, S_IRUGO, show_temp, NULL, 0, 1);
486
-static SENSOR_DEVICE_ATTR_2(temp2_min, S_IWUSR | S_IRUGO, show_temp,
487
- store_temp, 1, 1);
488
-static SENSOR_DEVICE_ATTR_2(temp2_max, S_IWUSR | S_IRUGO, show_temp,
489
- store_temp, 2, 1);
490
-static SENSOR_DEVICE_ATTR_2(temp2_crit, S_IWUSR | S_IRUGO, show_temp,
491
- store_temp, 3, 1);
492
-static SENSOR_DEVICE_ATTR(temp2_crit_hyst, S_IRUGO, show_temp_crit_hyst,
493
- NULL, 1);
494
-static SENSOR_DEVICE_ATTR_2(temp2_fault, S_IRUGO, show_status, NULL,
495
- 0, TMP432_STATUS_REMOTE1);
496
-static SENSOR_DEVICE_ATTR_2(temp2_min_alarm, S_IRUGO, show_status, NULL,
497
- 1, TMP432_STATUS_REMOTE1);
498
-static SENSOR_DEVICE_ATTR_2(temp2_max_alarm, S_IRUGO, show_status, NULL,
499
- 2, TMP432_STATUS_REMOTE1);
500
-static SENSOR_DEVICE_ATTR_2(temp2_crit_alarm, S_IRUGO, show_status, NULL,
501
- 3, TMP432_STATUS_REMOTE1);
461
+static SENSOR_DEVICE_ATTR_2_RO(temp1_input, temp, 0, 0);
462
+static SENSOR_DEVICE_ATTR_2_RW(temp1_min, temp, 1, 0);
463
+static SENSOR_DEVICE_ATTR_2_RW(temp1_max, temp, 2, 0);
464
+static SENSOR_DEVICE_ATTR_2_RW(temp1_crit, temp, 3, 0);
465
+static SENSOR_DEVICE_ATTR_RW(temp1_crit_hyst, temp_crit_hyst, 0);
466
+static SENSOR_DEVICE_ATTR_2_RO(temp1_min_alarm, status, 1,
467
+ TMP432_STATUS_LOCAL);
468
+static SENSOR_DEVICE_ATTR_2_RO(temp1_max_alarm, status, 2,
469
+ TMP432_STATUS_LOCAL);
470
+static SENSOR_DEVICE_ATTR_2_RO(temp1_crit_alarm, status, 3,
471
+ TMP432_STATUS_LOCAL);
472
+static SENSOR_DEVICE_ATTR_2_RO(temp2_input, temp, 0, 1);
473
+static SENSOR_DEVICE_ATTR_2_RW(temp2_min, temp, 1, 1);
474
+static SENSOR_DEVICE_ATTR_2_RW(temp2_max, temp, 2, 1);
475
+static SENSOR_DEVICE_ATTR_2_RW(temp2_crit, temp, 3, 1);
476
+static SENSOR_DEVICE_ATTR_RO(temp2_crit_hyst, temp_crit_hyst, 1);
477
+static SENSOR_DEVICE_ATTR_2_RO(temp2_fault, status, 0, TMP432_STATUS_REMOTE1);
478
+static SENSOR_DEVICE_ATTR_2_RO(temp2_min_alarm, status, 1,
479
+ TMP432_STATUS_REMOTE1);
480
+static SENSOR_DEVICE_ATTR_2_RO(temp2_max_alarm, status, 2,
481
+ TMP432_STATUS_REMOTE1);
482
+static SENSOR_DEVICE_ATTR_2_RO(temp2_crit_alarm, status, 3,
483
+ TMP432_STATUS_REMOTE1);
502484
503485 static DEVICE_ATTR_RW(update_interval);
504486
....@@ -538,12 +520,11 @@
538520 * minimum and maximum register reset for both the local
539521 * and remote channels.
540522 */
541
-static SENSOR_DEVICE_ATTR_2(temp1_lowest, S_IRUGO, show_temp, NULL, 4, 0);
542
-static SENSOR_DEVICE_ATTR_2(temp1_highest, S_IRUGO, show_temp, NULL, 5, 0);
543
-static SENSOR_DEVICE_ATTR_2(temp2_lowest, S_IRUGO, show_temp, NULL, 4, 1);
544
-static SENSOR_DEVICE_ATTR_2(temp2_highest, S_IRUGO, show_temp, NULL, 5, 1);
545
-static SENSOR_DEVICE_ATTR(temp_reset_history, S_IWUSR, NULL, reset_temp_history,
546
- 0);
523
+static SENSOR_DEVICE_ATTR_2_RO(temp1_lowest, temp, 4, 0);
524
+static SENSOR_DEVICE_ATTR_2_RO(temp1_highest, temp, 5, 0);
525
+static SENSOR_DEVICE_ATTR_2_RO(temp2_lowest, temp, 4, 1);
526
+static SENSOR_DEVICE_ATTR_2_RO(temp2_highest, temp, 5, 1);
527
+static SENSOR_DEVICE_ATTR_WO(temp_reset_history, reset_temp_history, 0);
547528
548529 static struct attribute *tmp411_attributes[] = {
549530 &sensor_dev_attr_temp1_highest.dev_attr.attr,
....@@ -558,23 +539,18 @@
558539 .attrs = tmp411_attributes,
559540 };
560541
561
-static SENSOR_DEVICE_ATTR_2(temp3_input, S_IRUGO, show_temp, NULL, 0, 2);
562
-static SENSOR_DEVICE_ATTR_2(temp3_min, S_IWUSR | S_IRUGO, show_temp,
563
- store_temp, 1, 2);
564
-static SENSOR_DEVICE_ATTR_2(temp3_max, S_IWUSR | S_IRUGO, show_temp,
565
- store_temp, 2, 2);
566
-static SENSOR_DEVICE_ATTR_2(temp3_crit, S_IWUSR | S_IRUGO, show_temp,
567
- store_temp, 3, 2);
568
-static SENSOR_DEVICE_ATTR(temp3_crit_hyst, S_IRUGO, show_temp_crit_hyst,
569
- NULL, 2);
570
-static SENSOR_DEVICE_ATTR_2(temp3_fault, S_IRUGO, show_status, NULL,
571
- 0, TMP432_STATUS_REMOTE2);
572
-static SENSOR_DEVICE_ATTR_2(temp3_min_alarm, S_IRUGO, show_status, NULL,
573
- 1, TMP432_STATUS_REMOTE2);
574
-static SENSOR_DEVICE_ATTR_2(temp3_max_alarm, S_IRUGO, show_status, NULL,
575
- 2, TMP432_STATUS_REMOTE2);
576
-static SENSOR_DEVICE_ATTR_2(temp3_crit_alarm, S_IRUGO, show_status, NULL,
577
- 3, TMP432_STATUS_REMOTE2);
542
+static SENSOR_DEVICE_ATTR_2_RO(temp3_input, temp, 0, 2);
543
+static SENSOR_DEVICE_ATTR_2_RW(temp3_min, temp, 1, 2);
544
+static SENSOR_DEVICE_ATTR_2_RW(temp3_max, temp, 2, 2);
545
+static SENSOR_DEVICE_ATTR_2_RW(temp3_crit, temp, 3, 2);
546
+static SENSOR_DEVICE_ATTR_RO(temp3_crit_hyst, temp_crit_hyst, 2);
547
+static SENSOR_DEVICE_ATTR_2_RO(temp3_fault, status, 0, TMP432_STATUS_REMOTE2);
548
+static SENSOR_DEVICE_ATTR_2_RO(temp3_min_alarm, status, 1,
549
+ TMP432_STATUS_REMOTE2);
550
+static SENSOR_DEVICE_ATTR_2_RO(temp3_max_alarm, status, 2,
551
+ TMP432_STATUS_REMOTE2);
552
+static SENSOR_DEVICE_ATTR_2_RO(temp3_crit_alarm, status, 3,
553
+ TMP432_STATUS_REMOTE2);
578554
579555 static struct attribute *tmp432_attributes[] = {
580556 &sensor_dev_attr_temp3_input.dev_attr.attr,
....@@ -598,8 +574,7 @@
598574 * Additional features of the TMP461 chip.
599575 * The TMP461 temperature offset for the remote channel.
600576 */
601
-static SENSOR_DEVICE_ATTR_2(temp2_offset, S_IWUSR | S_IRUGO, show_temp,
602
- store_temp, 6, 1);
577
+static SENSOR_DEVICE_ATTR_2_RW(temp2_offset, temp, 6, 1);
603578
604579 static struct attribute *tmp461_attributes[] = {
605580 &sensor_dev_attr_temp2_offset.dev_attr.attr,
....@@ -708,8 +683,7 @@
708683 return 0;
709684 }
710685
711
-static int tmp401_probe(struct i2c_client *client,
712
- const struct i2c_device_id *id)
686
+static int tmp401_probe(struct i2c_client *client)
713687 {
714688 static const char * const names[] = {
715689 "TMP401", "TMP411", "TMP431", "TMP432", "TMP435", "TMP461"
....@@ -725,7 +699,7 @@
725699
726700 data->client = client;
727701 mutex_init(&data->update_lock);
728
- data->kind = id->driver_data;
702
+ data->kind = i2c_match_id(tmp401_id, client)->driver_data;
729703
730704 /* Initialize the TMP401 chip */
731705 status = tmp401_init_client(data, client);
....@@ -756,12 +730,23 @@
756730 return 0;
757731 }
758732
733
+static const struct of_device_id __maybe_unused tmp4xx_of_match[] = {
734
+ { .compatible = "ti,tmp401", },
735
+ { .compatible = "ti,tmp411", },
736
+ { .compatible = "ti,tmp431", },
737
+ { .compatible = "ti,tmp432", },
738
+ { .compatible = "ti,tmp435", },
739
+ { },
740
+};
741
+MODULE_DEVICE_TABLE(of, tmp4xx_of_match);
742
+
759743 static struct i2c_driver tmp401_driver = {
760744 .class = I2C_CLASS_HWMON,
761745 .driver = {
762746 .name = "tmp401",
747
+ .of_match_table = of_match_ptr(tmp4xx_of_match),
763748 },
764
- .probe = tmp401_probe,
749
+ .probe_new = tmp401_probe,
765750 .id_table = tmp401_id,
766751 .detect = tmp401_detect,
767752 .address_list = normal_i2c,