forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-10 748e4f3d702def1a4bff191e0cf93b6a05340f01
kernel/drivers/hwmon/nct7802.c
....@@ -1,17 +1,8 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * nct7802 - Driver for Nuvoton NCT7802Y
34 *
45 * Copyright (C) 2014 Guenter Roeck <linux@roeck-us.net>
5
- *
6
- * This program is free software; you can redistribute it and/or modify
7
- * it under the terms of the GNU General Public License as published by
8
- * the Free Software Foundation; either version 2 of the License, or
9
- * (at your option) any later version.
10
- *
11
- * This program is distributed in the hope that it will be useful,
12
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
- * GNU General Public License for more details.
156 */
167
178 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
....@@ -67,10 +58,12 @@
6758 struct nct7802_data {
6859 struct regmap *regmap;
6960 struct mutex access_lock; /* for multi-byte read and write operations */
61
+ u8 in_status;
62
+ struct mutex in_alarm_lock;
7063 };
7164
72
-static ssize_t show_temp_type(struct device *dev, struct device_attribute *attr,
73
- char *buf)
65
+static ssize_t temp_type_show(struct device *dev,
66
+ struct device_attribute *attr, char *buf)
7467 {
7568 struct nct7802_data *data = dev_get_drvdata(dev);
7669 struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr);
....@@ -84,9 +77,9 @@
8477 return sprintf(buf, "%u\n", (mode >> (2 * sattr->index) & 3) + 2);
8578 }
8679
87
-static ssize_t store_temp_type(struct device *dev,
88
- struct device_attribute *attr,
89
- const char *buf, size_t count)
80
+static ssize_t temp_type_store(struct device *dev,
81
+ struct device_attribute *attr, const char *buf,
82
+ size_t count)
9083 {
9184 struct nct7802_data *data = dev_get_drvdata(dev);
9285 struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr);
....@@ -105,8 +98,8 @@
10598 return err ? : count;
10699 }
107100
108
-static ssize_t show_pwm_mode(struct device *dev, struct device_attribute *attr,
109
- char *buf)
101
+static ssize_t pwm_mode_show(struct device *dev,
102
+ struct device_attribute *attr, char *buf)
110103 {
111104 struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr);
112105 struct nct7802_data *data = dev_get_drvdata(dev);
....@@ -123,7 +116,7 @@
123116 return sprintf(buf, "%u\n", !(regval & (1 << sattr->index)));
124117 }
125118
126
-static ssize_t show_pwm(struct device *dev, struct device_attribute *devattr,
119
+static ssize_t pwm_show(struct device *dev, struct device_attribute *devattr,
127120 char *buf)
128121 {
129122 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
....@@ -141,7 +134,7 @@
141134 return sprintf(buf, "%d\n", val);
142135 }
143136
144
-static ssize_t store_pwm(struct device *dev, struct device_attribute *devattr,
137
+static ssize_t pwm_store(struct device *dev, struct device_attribute *devattr,
145138 const char *buf, size_t count)
146139 {
147140 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
....@@ -157,7 +150,7 @@
157150 return err ? : count;
158151 }
159152
160
-static ssize_t show_pwm_enable(struct device *dev,
153
+static ssize_t pwm_enable_show(struct device *dev,
161154 struct device_attribute *attr, char *buf)
162155 {
163156 struct nct7802_data *data = dev_get_drvdata(dev);
....@@ -172,7 +165,7 @@
172165 return sprintf(buf, "%u\n", enabled + 1);
173166 }
174167
175
-static ssize_t store_pwm_enable(struct device *dev,
168
+static ssize_t pwm_enable_store(struct device *dev,
176169 struct device_attribute *attr,
177170 const char *buf, size_t count)
178171 {
....@@ -345,7 +338,7 @@
345338 return err;
346339 }
347340
348
-static ssize_t show_in(struct device *dev, struct device_attribute *attr,
341
+static ssize_t in_show(struct device *dev, struct device_attribute *attr,
349342 char *buf)
350343 {
351344 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
....@@ -359,7 +352,7 @@
359352 return sprintf(buf, "%d\n", voltage);
360353 }
361354
362
-static ssize_t store_in(struct device *dev, struct device_attribute *attr,
355
+static ssize_t in_store(struct device *dev, struct device_attribute *attr,
363356 const char *buf, size_t count)
364357 {
365358 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
....@@ -377,7 +370,67 @@
377370 return err ? : count;
378371 }
379372
380
-static ssize_t show_temp(struct device *dev, struct device_attribute *attr,
373
+static ssize_t in_alarm_show(struct device *dev, struct device_attribute *attr,
374
+ char *buf)
375
+{
376
+ struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
377
+ struct nct7802_data *data = dev_get_drvdata(dev);
378
+ int volt, min, max, ret;
379
+ unsigned int val;
380
+
381
+ mutex_lock(&data->in_alarm_lock);
382
+
383
+ /*
384
+ * The SMI Voltage status register is the only register giving a status
385
+ * for voltages. A bit is set for each input crossing a threshold, in
386
+ * both direction, but the "inside" or "outside" limits info is not
387
+ * available. Also this register is cleared on read.
388
+ * Note: this is not explicitly spelled out in the datasheet, but
389
+ * from experiment.
390
+ * To deal with this we use a status cache with one validity bit and
391
+ * one status bit for each input. Validity is cleared at startup and
392
+ * each time the register reports a change, and the status is processed
393
+ * by software based on current input value and limits.
394
+ */
395
+ ret = regmap_read(data->regmap, 0x1e, &val); /* SMI Voltage status */
396
+ if (ret < 0)
397
+ goto abort;
398
+
399
+ /* invalidate cached status for all inputs crossing a threshold */
400
+ data->in_status &= ~((val & 0x0f) << 4);
401
+
402
+ /* if cached status for requested input is invalid, update it */
403
+ if (!(data->in_status & (0x10 << sattr->index))) {
404
+ ret = nct7802_read_voltage(data, sattr->nr, 0);
405
+ if (ret < 0)
406
+ goto abort;
407
+ volt = ret;
408
+
409
+ ret = nct7802_read_voltage(data, sattr->nr, 1);
410
+ if (ret < 0)
411
+ goto abort;
412
+ min = ret;
413
+
414
+ ret = nct7802_read_voltage(data, sattr->nr, 2);
415
+ if (ret < 0)
416
+ goto abort;
417
+ max = ret;
418
+
419
+ if (volt < min || volt > max)
420
+ data->in_status |= (1 << sattr->index);
421
+ else
422
+ data->in_status &= ~(1 << sattr->index);
423
+
424
+ data->in_status |= 0x10 << sattr->index;
425
+ }
426
+
427
+ ret = sprintf(buf, "%u\n", !!(data->in_status & (1 << sattr->index)));
428
+abort:
429
+ mutex_unlock(&data->in_alarm_lock);
430
+ return ret;
431
+}
432
+
433
+static ssize_t temp_show(struct device *dev, struct device_attribute *attr,
381434 char *buf)
382435 {
383436 struct nct7802_data *data = dev_get_drvdata(dev);
....@@ -391,7 +444,7 @@
391444 return sprintf(buf, "%d\n", temp);
392445 }
393446
394
-static ssize_t store_temp(struct device *dev, struct device_attribute *attr,
447
+static ssize_t temp_store(struct device *dev, struct device_attribute *attr,
395448 const char *buf, size_t count)
396449 {
397450 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
....@@ -410,7 +463,7 @@
410463 return err ? : count;
411464 }
412465
413
-static ssize_t show_fan(struct device *dev, struct device_attribute *attr,
466
+static ssize_t fan_show(struct device *dev, struct device_attribute *attr,
414467 char *buf)
415468 {
416469 struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr);
....@@ -424,7 +477,7 @@
424477 return sprintf(buf, "%d\n", speed);
425478 }
426479
427
-static ssize_t show_fan_min(struct device *dev, struct device_attribute *attr,
480
+static ssize_t fan_min_show(struct device *dev, struct device_attribute *attr,
428481 char *buf)
429482 {
430483 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
....@@ -438,8 +491,9 @@
438491 return sprintf(buf, "%d\n", speed);
439492 }
440493
441
-static ssize_t store_fan_min(struct device *dev, struct device_attribute *attr,
442
- const char *buf, size_t count)
494
+static ssize_t fan_min_store(struct device *dev,
495
+ struct device_attribute *attr, const char *buf,
496
+ size_t count)
443497 {
444498 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
445499 struct nct7802_data *data = dev_get_drvdata(dev);
....@@ -454,7 +508,7 @@
454508 return err ? : count;
455509 }
456510
457
-static ssize_t show_alarm(struct device *dev, struct device_attribute *attr,
511
+static ssize_t alarm_show(struct device *dev, struct device_attribute *attr,
458512 char *buf)
459513 {
460514 struct nct7802_data *data = dev_get_drvdata(dev);
....@@ -471,7 +525,7 @@
471525 }
472526
473527 static ssize_t
474
-show_beep(struct device *dev, struct device_attribute *attr, char *buf)
528
+beep_show(struct device *dev, struct device_attribute *attr, char *buf)
475529 {
476530 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
477531 struct nct7802_data *data = dev_get_drvdata(dev);
....@@ -486,7 +540,7 @@
486540 }
487541
488542 static ssize_t
489
-store_beep(struct device *dev, struct device_attribute *attr, const char *buf,
543
+beep_store(struct device *dev, struct device_attribute *attr, const char *buf,
490544 size_t count)
491545 {
492546 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
....@@ -505,108 +559,64 @@
505559 return err ? : count;
506560 }
507561
508
-static SENSOR_DEVICE_ATTR(temp1_type, S_IRUGO | S_IWUSR,
509
- show_temp_type, store_temp_type, 0);
510
-static SENSOR_DEVICE_ATTR_2(temp1_input, S_IRUGO, show_temp, NULL, 0x01,
511
- REG_TEMP_LSB);
512
-static SENSOR_DEVICE_ATTR_2(temp1_min, S_IRUGO | S_IWUSR, show_temp,
513
- store_temp, 0x31, 0);
514
-static SENSOR_DEVICE_ATTR_2(temp1_max, S_IRUGO | S_IWUSR, show_temp,
515
- store_temp, 0x30, 0);
516
-static SENSOR_DEVICE_ATTR_2(temp1_crit, S_IRUGO | S_IWUSR, show_temp,
517
- store_temp, 0x3a, 0);
562
+static SENSOR_DEVICE_ATTR_RW(temp1_type, temp_type, 0);
563
+static SENSOR_DEVICE_ATTR_2_RO(temp1_input, temp, 0x01, REG_TEMP_LSB);
564
+static SENSOR_DEVICE_ATTR_2_RW(temp1_min, temp, 0x31, 0);
565
+static SENSOR_DEVICE_ATTR_2_RW(temp1_max, temp, 0x30, 0);
566
+static SENSOR_DEVICE_ATTR_2_RW(temp1_crit, temp, 0x3a, 0);
518567
519
-static SENSOR_DEVICE_ATTR(temp2_type, S_IRUGO | S_IWUSR,
520
- show_temp_type, store_temp_type, 1);
521
-static SENSOR_DEVICE_ATTR_2(temp2_input, S_IRUGO, show_temp, NULL, 0x02,
522
- REG_TEMP_LSB);
523
-static SENSOR_DEVICE_ATTR_2(temp2_min, S_IRUGO | S_IWUSR, show_temp,
524
- store_temp, 0x33, 0);
525
-static SENSOR_DEVICE_ATTR_2(temp2_max, S_IRUGO | S_IWUSR, show_temp,
526
- store_temp, 0x32, 0);
527
-static SENSOR_DEVICE_ATTR_2(temp2_crit, S_IRUGO | S_IWUSR, show_temp,
528
- store_temp, 0x3b, 0);
568
+static SENSOR_DEVICE_ATTR_RW(temp2_type, temp_type, 1);
569
+static SENSOR_DEVICE_ATTR_2_RO(temp2_input, temp, 0x02, REG_TEMP_LSB);
570
+static SENSOR_DEVICE_ATTR_2_RW(temp2_min, temp, 0x33, 0);
571
+static SENSOR_DEVICE_ATTR_2_RW(temp2_max, temp, 0x32, 0);
572
+static SENSOR_DEVICE_ATTR_2_RW(temp2_crit, temp, 0x3b, 0);
529573
530
-static SENSOR_DEVICE_ATTR(temp3_type, S_IRUGO | S_IWUSR,
531
- show_temp_type, store_temp_type, 2);
532
-static SENSOR_DEVICE_ATTR_2(temp3_input, S_IRUGO, show_temp, NULL, 0x03,
533
- REG_TEMP_LSB);
534
-static SENSOR_DEVICE_ATTR_2(temp3_min, S_IRUGO | S_IWUSR, show_temp,
535
- store_temp, 0x35, 0);
536
-static SENSOR_DEVICE_ATTR_2(temp3_max, S_IRUGO | S_IWUSR, show_temp,
537
- store_temp, 0x34, 0);
538
-static SENSOR_DEVICE_ATTR_2(temp3_crit, S_IRUGO | S_IWUSR, show_temp,
539
- store_temp, 0x3c, 0);
574
+static SENSOR_DEVICE_ATTR_RW(temp3_type, temp_type, 2);
575
+static SENSOR_DEVICE_ATTR_2_RO(temp3_input, temp, 0x03, REG_TEMP_LSB);
576
+static SENSOR_DEVICE_ATTR_2_RW(temp3_min, temp, 0x35, 0);
577
+static SENSOR_DEVICE_ATTR_2_RW(temp3_max, temp, 0x34, 0);
578
+static SENSOR_DEVICE_ATTR_2_RW(temp3_crit, temp, 0x3c, 0);
540579
541
-static SENSOR_DEVICE_ATTR_2(temp4_input, S_IRUGO, show_temp, NULL, 0x04, 0);
542
-static SENSOR_DEVICE_ATTR_2(temp4_min, S_IRUGO | S_IWUSR, show_temp,
543
- store_temp, 0x37, 0);
544
-static SENSOR_DEVICE_ATTR_2(temp4_max, S_IRUGO | S_IWUSR, show_temp,
545
- store_temp, 0x36, 0);
546
-static SENSOR_DEVICE_ATTR_2(temp4_crit, S_IRUGO | S_IWUSR, show_temp,
547
- store_temp, 0x3d, 0);
580
+static SENSOR_DEVICE_ATTR_2_RO(temp4_input, temp, 0x04, 0);
581
+static SENSOR_DEVICE_ATTR_2_RW(temp4_min, temp, 0x37, 0);
582
+static SENSOR_DEVICE_ATTR_2_RW(temp4_max, temp, 0x36, 0);
583
+static SENSOR_DEVICE_ATTR_2_RW(temp4_crit, temp, 0x3d, 0);
548584
549
-static SENSOR_DEVICE_ATTR_2(temp5_input, S_IRUGO, show_temp, NULL, 0x06,
550
- REG_TEMP_PECI_LSB);
551
-static SENSOR_DEVICE_ATTR_2(temp5_min, S_IRUGO | S_IWUSR, show_temp,
552
- store_temp, 0x39, 0);
553
-static SENSOR_DEVICE_ATTR_2(temp5_max, S_IRUGO | S_IWUSR, show_temp,
554
- store_temp, 0x38, 0);
555
-static SENSOR_DEVICE_ATTR_2(temp5_crit, S_IRUGO | S_IWUSR, show_temp,
556
- store_temp, 0x3e, 0);
585
+static SENSOR_DEVICE_ATTR_2_RO(temp5_input, temp, 0x06, REG_TEMP_PECI_LSB);
586
+static SENSOR_DEVICE_ATTR_2_RW(temp5_min, temp, 0x39, 0);
587
+static SENSOR_DEVICE_ATTR_2_RW(temp5_max, temp, 0x38, 0);
588
+static SENSOR_DEVICE_ATTR_2_RW(temp5_crit, temp, 0x3e, 0);
557589
558
-static SENSOR_DEVICE_ATTR_2(temp6_input, S_IRUGO, show_temp, NULL, 0x07,
559
- REG_TEMP_PECI_LSB);
590
+static SENSOR_DEVICE_ATTR_2_RO(temp6_input, temp, 0x07, REG_TEMP_PECI_LSB);
560591
561
-static SENSOR_DEVICE_ATTR_2(temp1_min_alarm, S_IRUGO, show_alarm, NULL,
562
- 0x18, 0);
563
-static SENSOR_DEVICE_ATTR_2(temp2_min_alarm, S_IRUGO, show_alarm, NULL,
564
- 0x18, 1);
565
-static SENSOR_DEVICE_ATTR_2(temp3_min_alarm, S_IRUGO, show_alarm, NULL,
566
- 0x18, 2);
567
-static SENSOR_DEVICE_ATTR_2(temp4_min_alarm, S_IRUGO, show_alarm, NULL,
568
- 0x18, 3);
569
-static SENSOR_DEVICE_ATTR_2(temp5_min_alarm, S_IRUGO, show_alarm, NULL,
570
- 0x18, 4);
592
+static SENSOR_DEVICE_ATTR_2_RO(temp1_min_alarm, alarm, 0x18, 0);
593
+static SENSOR_DEVICE_ATTR_2_RO(temp2_min_alarm, alarm, 0x18, 1);
594
+static SENSOR_DEVICE_ATTR_2_RO(temp3_min_alarm, alarm, 0x18, 2);
595
+static SENSOR_DEVICE_ATTR_2_RO(temp4_min_alarm, alarm, 0x18, 3);
596
+static SENSOR_DEVICE_ATTR_2_RO(temp5_min_alarm, alarm, 0x18, 4);
571597
572
-static SENSOR_DEVICE_ATTR_2(temp1_max_alarm, S_IRUGO, show_alarm, NULL,
573
- 0x19, 0);
574
-static SENSOR_DEVICE_ATTR_2(temp2_max_alarm, S_IRUGO, show_alarm, NULL,
575
- 0x19, 1);
576
-static SENSOR_DEVICE_ATTR_2(temp3_max_alarm, S_IRUGO, show_alarm, NULL,
577
- 0x19, 2);
578
-static SENSOR_DEVICE_ATTR_2(temp4_max_alarm, S_IRUGO, show_alarm, NULL,
579
- 0x19, 3);
580
-static SENSOR_DEVICE_ATTR_2(temp5_max_alarm, S_IRUGO, show_alarm, NULL,
581
- 0x19, 4);
598
+static SENSOR_DEVICE_ATTR_2_RO(temp1_max_alarm, alarm, 0x19, 0);
599
+static SENSOR_DEVICE_ATTR_2_RO(temp2_max_alarm, alarm, 0x19, 1);
600
+static SENSOR_DEVICE_ATTR_2_RO(temp3_max_alarm, alarm, 0x19, 2);
601
+static SENSOR_DEVICE_ATTR_2_RO(temp4_max_alarm, alarm, 0x19, 3);
602
+static SENSOR_DEVICE_ATTR_2_RO(temp5_max_alarm, alarm, 0x19, 4);
582603
583
-static SENSOR_DEVICE_ATTR_2(temp1_crit_alarm, S_IRUGO, show_alarm, NULL,
584
- 0x1b, 0);
585
-static SENSOR_DEVICE_ATTR_2(temp2_crit_alarm, S_IRUGO, show_alarm, NULL,
586
- 0x1b, 1);
587
-static SENSOR_DEVICE_ATTR_2(temp3_crit_alarm, S_IRUGO, show_alarm, NULL,
588
- 0x1b, 2);
589
-static SENSOR_DEVICE_ATTR_2(temp4_crit_alarm, S_IRUGO, show_alarm, NULL,
590
- 0x1b, 3);
591
-static SENSOR_DEVICE_ATTR_2(temp5_crit_alarm, S_IRUGO, show_alarm, NULL,
592
- 0x1b, 4);
604
+static SENSOR_DEVICE_ATTR_2_RO(temp1_crit_alarm, alarm, 0x1b, 0);
605
+static SENSOR_DEVICE_ATTR_2_RO(temp2_crit_alarm, alarm, 0x1b, 1);
606
+static SENSOR_DEVICE_ATTR_2_RO(temp3_crit_alarm, alarm, 0x1b, 2);
607
+static SENSOR_DEVICE_ATTR_2_RO(temp4_crit_alarm, alarm, 0x1b, 3);
608
+static SENSOR_DEVICE_ATTR_2_RO(temp5_crit_alarm, alarm, 0x1b, 4);
593609
594
-static SENSOR_DEVICE_ATTR_2(temp1_fault, S_IRUGO, show_alarm, NULL, 0x17, 0);
595
-static SENSOR_DEVICE_ATTR_2(temp2_fault, S_IRUGO, show_alarm, NULL, 0x17, 1);
596
-static SENSOR_DEVICE_ATTR_2(temp3_fault, S_IRUGO, show_alarm, NULL, 0x17, 2);
610
+static SENSOR_DEVICE_ATTR_2_RO(temp1_fault, alarm, 0x17, 0);
611
+static SENSOR_DEVICE_ATTR_2_RO(temp2_fault, alarm, 0x17, 1);
612
+static SENSOR_DEVICE_ATTR_2_RO(temp3_fault, alarm, 0x17, 2);
597613
598
-static SENSOR_DEVICE_ATTR_2(temp1_beep, S_IRUGO | S_IWUSR, show_beep,
599
- store_beep, 0x5c, 0);
600
-static SENSOR_DEVICE_ATTR_2(temp2_beep, S_IRUGO | S_IWUSR, show_beep,
601
- store_beep, 0x5c, 1);
602
-static SENSOR_DEVICE_ATTR_2(temp3_beep, S_IRUGO | S_IWUSR, show_beep,
603
- store_beep, 0x5c, 2);
604
-static SENSOR_DEVICE_ATTR_2(temp4_beep, S_IRUGO | S_IWUSR, show_beep,
605
- store_beep, 0x5c, 3);
606
-static SENSOR_DEVICE_ATTR_2(temp5_beep, S_IRUGO | S_IWUSR, show_beep,
607
- store_beep, 0x5c, 4);
608
-static SENSOR_DEVICE_ATTR_2(temp6_beep, S_IRUGO | S_IWUSR, show_beep,
609
- store_beep, 0x5c, 5);
614
+static SENSOR_DEVICE_ATTR_2_RW(temp1_beep, beep, 0x5c, 0);
615
+static SENSOR_DEVICE_ATTR_2_RW(temp2_beep, beep, 0x5c, 1);
616
+static SENSOR_DEVICE_ATTR_2_RW(temp3_beep, beep, 0x5c, 2);
617
+static SENSOR_DEVICE_ATTR_2_RW(temp4_beep, beep, 0x5c, 3);
618
+static SENSOR_DEVICE_ATTR_2_RW(temp5_beep, beep, 0x5c, 4);
619
+static SENSOR_DEVICE_ATTR_2_RW(temp6_beep, beep, 0x5c, 5);
610620
611621 static struct attribute *nct7802_temp_attrs[] = {
612622 &sensor_dev_attr_temp1_type.dev_attr.attr,
....@@ -669,7 +679,7 @@
669679 static umode_t nct7802_temp_is_visible(struct kobject *kobj,
670680 struct attribute *attr, int index)
671681 {
672
- struct device *dev = container_of(kobj, struct device, kobj);
682
+ struct device *dev = kobj_to_dev(kobj);
673683 struct nct7802_data *data = dev_get_drvdata(dev);
674684 unsigned int reg;
675685 int err;
....@@ -698,7 +708,7 @@
698708 if (index >= 38 && index < 46 && !(reg & 0x01)) /* PECI 0 */
699709 return 0;
700710
701
- if (index >= 0x46 && (!(reg & 0x02))) /* PECI 1 */
711
+ if (index >= 46 && !(reg & 0x02)) /* PECI 1 */
702712 return 0;
703713
704714 return attr->mode;
....@@ -709,43 +719,31 @@
709719 .is_visible = nct7802_temp_is_visible,
710720 };
711721
712
-static SENSOR_DEVICE_ATTR_2(in0_input, S_IRUGO, show_in, NULL, 0, 0);
713
-static SENSOR_DEVICE_ATTR_2(in0_min, S_IRUGO | S_IWUSR, show_in, store_in,
714
- 0, 1);
715
-static SENSOR_DEVICE_ATTR_2(in0_max, S_IRUGO | S_IWUSR, show_in, store_in,
716
- 0, 2);
717
-static SENSOR_DEVICE_ATTR_2(in0_alarm, S_IRUGO, show_alarm, NULL, 0x1e, 3);
718
-static SENSOR_DEVICE_ATTR_2(in0_beep, S_IRUGO | S_IWUSR, show_beep, store_beep,
719
- 0x5a, 3);
722
+static SENSOR_DEVICE_ATTR_2_RO(in0_input, in, 0, 0);
723
+static SENSOR_DEVICE_ATTR_2_RW(in0_min, in, 0, 1);
724
+static SENSOR_DEVICE_ATTR_2_RW(in0_max, in, 0, 2);
725
+static SENSOR_DEVICE_ATTR_2_RO(in0_alarm, in_alarm, 0, 3);
726
+static SENSOR_DEVICE_ATTR_2_RW(in0_beep, beep, 0x5a, 3);
720727
721
-static SENSOR_DEVICE_ATTR_2(in1_input, S_IRUGO, show_in, NULL, 1, 0);
728
+static SENSOR_DEVICE_ATTR_2_RO(in1_input, in, 1, 0);
722729
723
-static SENSOR_DEVICE_ATTR_2(in2_input, S_IRUGO, show_in, NULL, 2, 0);
724
-static SENSOR_DEVICE_ATTR_2(in2_min, S_IRUGO | S_IWUSR, show_in, store_in,
725
- 2, 1);
726
-static SENSOR_DEVICE_ATTR_2(in2_max, S_IRUGO | S_IWUSR, show_in, store_in,
727
- 2, 2);
728
-static SENSOR_DEVICE_ATTR_2(in2_alarm, S_IRUGO, show_alarm, NULL, 0x1e, 0);
729
-static SENSOR_DEVICE_ATTR_2(in2_beep, S_IRUGO | S_IWUSR, show_beep, store_beep,
730
- 0x5a, 0);
730
+static SENSOR_DEVICE_ATTR_2_RO(in2_input, in, 2, 0);
731
+static SENSOR_DEVICE_ATTR_2_RW(in2_min, in, 2, 1);
732
+static SENSOR_DEVICE_ATTR_2_RW(in2_max, in, 2, 2);
733
+static SENSOR_DEVICE_ATTR_2_RO(in2_alarm, in_alarm, 2, 0);
734
+static SENSOR_DEVICE_ATTR_2_RW(in2_beep, beep, 0x5a, 0);
731735
732
-static SENSOR_DEVICE_ATTR_2(in3_input, S_IRUGO, show_in, NULL, 3, 0);
733
-static SENSOR_DEVICE_ATTR_2(in3_min, S_IRUGO | S_IWUSR, show_in, store_in,
734
- 3, 1);
735
-static SENSOR_DEVICE_ATTR_2(in3_max, S_IRUGO | S_IWUSR, show_in, store_in,
736
- 3, 2);
737
-static SENSOR_DEVICE_ATTR_2(in3_alarm, S_IRUGO, show_alarm, NULL, 0x1e, 1);
738
-static SENSOR_DEVICE_ATTR_2(in3_beep, S_IRUGO | S_IWUSR, show_beep, store_beep,
739
- 0x5a, 1);
736
+static SENSOR_DEVICE_ATTR_2_RO(in3_input, in, 3, 0);
737
+static SENSOR_DEVICE_ATTR_2_RW(in3_min, in, 3, 1);
738
+static SENSOR_DEVICE_ATTR_2_RW(in3_max, in, 3, 2);
739
+static SENSOR_DEVICE_ATTR_2_RO(in3_alarm, in_alarm, 3, 1);
740
+static SENSOR_DEVICE_ATTR_2_RW(in3_beep, beep, 0x5a, 1);
740741
741
-static SENSOR_DEVICE_ATTR_2(in4_input, S_IRUGO, show_in, NULL, 4, 0);
742
-static SENSOR_DEVICE_ATTR_2(in4_min, S_IRUGO | S_IWUSR, show_in, store_in,
743
- 4, 1);
744
-static SENSOR_DEVICE_ATTR_2(in4_max, S_IRUGO | S_IWUSR, show_in, store_in,
745
- 4, 2);
746
-static SENSOR_DEVICE_ATTR_2(in4_alarm, S_IRUGO, show_alarm, NULL, 0x1e, 2);
747
-static SENSOR_DEVICE_ATTR_2(in4_beep, S_IRUGO | S_IWUSR, show_beep, store_beep,
748
- 0x5a, 2);
742
+static SENSOR_DEVICE_ATTR_2_RO(in4_input, in, 4, 0);
743
+static SENSOR_DEVICE_ATTR_2_RW(in4_min, in, 4, 1);
744
+static SENSOR_DEVICE_ATTR_2_RW(in4_max, in, 4, 2);
745
+static SENSOR_DEVICE_ATTR_2_RO(in4_alarm, in_alarm, 4, 2);
746
+static SENSOR_DEVICE_ATTR_2_RW(in4_beep, beep, 0x5a, 2);
749747
750748 static struct attribute *nct7802_in_attrs[] = {
751749 &sensor_dev_attr_in0_input.dev_attr.attr,
....@@ -780,7 +778,7 @@
780778 static umode_t nct7802_in_is_visible(struct kobject *kobj,
781779 struct attribute *attr, int index)
782780 {
783
- struct device *dev = container_of(kobj, struct device, kobj);
781
+ struct device *dev = kobj_to_dev(kobj);
784782 struct nct7802_data *data = dev_get_drvdata(dev);
785783 unsigned int reg;
786784 int err;
....@@ -807,45 +805,33 @@
807805 .is_visible = nct7802_in_is_visible,
808806 };
809807
810
-static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, show_fan, NULL, 0x10);
811
-static SENSOR_DEVICE_ATTR_2(fan1_min, S_IRUGO | S_IWUSR, show_fan_min,
812
- store_fan_min, 0x49, 0x4c);
813
-static SENSOR_DEVICE_ATTR_2(fan1_alarm, S_IRUGO, show_alarm, NULL, 0x1a, 0);
814
-static SENSOR_DEVICE_ATTR_2(fan1_beep, S_IRUGO | S_IWUSR, show_beep, store_beep,
815
- 0x5b, 0);
816
-static SENSOR_DEVICE_ATTR(fan2_input, S_IRUGO, show_fan, NULL, 0x11);
817
-static SENSOR_DEVICE_ATTR_2(fan2_min, S_IRUGO | S_IWUSR, show_fan_min,
818
- store_fan_min, 0x4a, 0x4d);
819
-static SENSOR_DEVICE_ATTR_2(fan2_alarm, S_IRUGO, show_alarm, NULL, 0x1a, 1);
820
-static SENSOR_DEVICE_ATTR_2(fan2_beep, S_IRUGO | S_IWUSR, show_beep, store_beep,
821
- 0x5b, 1);
822
-static SENSOR_DEVICE_ATTR(fan3_input, S_IRUGO, show_fan, NULL, 0x12);
823
-static SENSOR_DEVICE_ATTR_2(fan3_min, S_IRUGO | S_IWUSR, show_fan_min,
824
- store_fan_min, 0x4b, 0x4e);
825
-static SENSOR_DEVICE_ATTR_2(fan3_alarm, S_IRUGO, show_alarm, NULL, 0x1a, 2);
826
-static SENSOR_DEVICE_ATTR_2(fan3_beep, S_IRUGO | S_IWUSR, show_beep, store_beep,
827
- 0x5b, 2);
808
+static SENSOR_DEVICE_ATTR_RO(fan1_input, fan, 0x10);
809
+static SENSOR_DEVICE_ATTR_2_RW(fan1_min, fan_min, 0x49, 0x4c);
810
+static SENSOR_DEVICE_ATTR_2_RO(fan1_alarm, alarm, 0x1a, 0);
811
+static SENSOR_DEVICE_ATTR_2_RW(fan1_beep, beep, 0x5b, 0);
812
+static SENSOR_DEVICE_ATTR_RO(fan2_input, fan, 0x11);
813
+static SENSOR_DEVICE_ATTR_2_RW(fan2_min, fan_min, 0x4a, 0x4d);
814
+static SENSOR_DEVICE_ATTR_2_RO(fan2_alarm, alarm, 0x1a, 1);
815
+static SENSOR_DEVICE_ATTR_2_RW(fan2_beep, beep, 0x5b, 1);
816
+static SENSOR_DEVICE_ATTR_RO(fan3_input, fan, 0x12);
817
+static SENSOR_DEVICE_ATTR_2_RW(fan3_min, fan_min, 0x4b, 0x4e);
818
+static SENSOR_DEVICE_ATTR_2_RO(fan3_alarm, alarm, 0x1a, 2);
819
+static SENSOR_DEVICE_ATTR_2_RW(fan3_beep, beep, 0x5b, 2);
828820
829821 /* 7.2.89 Fan Control Output Type */
830
-static SENSOR_DEVICE_ATTR(pwm1_mode, S_IRUGO, show_pwm_mode, NULL, 0);
831
-static SENSOR_DEVICE_ATTR(pwm2_mode, S_IRUGO, show_pwm_mode, NULL, 1);
832
-static SENSOR_DEVICE_ATTR(pwm3_mode, S_IRUGO, show_pwm_mode, NULL, 2);
822
+static SENSOR_DEVICE_ATTR_RO(pwm1_mode, pwm_mode, 0);
823
+static SENSOR_DEVICE_ATTR_RO(pwm2_mode, pwm_mode, 1);
824
+static SENSOR_DEVICE_ATTR_RO(pwm3_mode, pwm_mode, 2);
833825
834826 /* 7.2.91... Fan Control Output Value */
835
-static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, show_pwm, store_pwm,
836
- REG_PWM(0));
837
-static SENSOR_DEVICE_ATTR(pwm2, S_IRUGO | S_IWUSR, show_pwm, store_pwm,
838
- REG_PWM(1));
839
-static SENSOR_DEVICE_ATTR(pwm3, S_IRUGO | S_IWUSR, show_pwm, store_pwm,
840
- REG_PWM(2));
827
+static SENSOR_DEVICE_ATTR_RW(pwm1, pwm, REG_PWM(0));
828
+static SENSOR_DEVICE_ATTR_RW(pwm2, pwm, REG_PWM(1));
829
+static SENSOR_DEVICE_ATTR_RW(pwm3, pwm, REG_PWM(2));
841830
842831 /* 7.2.95... Temperature to Fan mapping Relationships Register */
843
-static SENSOR_DEVICE_ATTR(pwm1_enable, S_IRUGO | S_IWUSR, show_pwm_enable,
844
- store_pwm_enable, 0);
845
-static SENSOR_DEVICE_ATTR(pwm2_enable, S_IRUGO | S_IWUSR, show_pwm_enable,
846
- store_pwm_enable, 1);
847
-static SENSOR_DEVICE_ATTR(pwm3_enable, S_IRUGO | S_IWUSR, show_pwm_enable,
848
- store_pwm_enable, 2);
832
+static SENSOR_DEVICE_ATTR_RW(pwm1_enable, pwm_enable, 0);
833
+static SENSOR_DEVICE_ATTR_RW(pwm2_enable, pwm_enable, 1);
834
+static SENSOR_DEVICE_ATTR_RW(pwm3_enable, pwm_enable, 2);
849835
850836 static struct attribute *nct7802_fan_attrs[] = {
851837 &sensor_dev_attr_fan1_input.dev_attr.attr,
....@@ -867,7 +853,7 @@
867853 static umode_t nct7802_fan_is_visible(struct kobject *kobj,
868854 struct attribute *attr, int index)
869855 {
870
- struct device *dev = container_of(kobj, struct device, kobj);
856
+ struct device *dev = kobj_to_dev(kobj);
871857 struct nct7802_data *data = dev_get_drvdata(dev);
872858 int fan = index / 4; /* 4 attributes per fan */
873859 unsigned int reg;
....@@ -903,73 +889,46 @@
903889 };
904890
905891 /* 7.2.115... 0x80-0x83, 0x84 Temperature (X-axis) transition */
906
-static SENSOR_DEVICE_ATTR_2(pwm1_auto_point1_temp, S_IRUGO | S_IWUSR,
907
- show_temp, store_temp, 0x80, 0);
908
-static SENSOR_DEVICE_ATTR_2(pwm1_auto_point2_temp, S_IRUGO | S_IWUSR,
909
- show_temp, store_temp, 0x81, 0);
910
-static SENSOR_DEVICE_ATTR_2(pwm1_auto_point3_temp, S_IRUGO | S_IWUSR,
911
- show_temp, store_temp, 0x82, 0);
912
-static SENSOR_DEVICE_ATTR_2(pwm1_auto_point4_temp, S_IRUGO | S_IWUSR,
913
- show_temp, store_temp, 0x83, 0);
914
-static SENSOR_DEVICE_ATTR_2(pwm1_auto_point5_temp, S_IRUGO | S_IWUSR,
915
- show_temp, store_temp, 0x84, 0);
892
+static SENSOR_DEVICE_ATTR_2_RW(pwm1_auto_point1_temp, temp, 0x80, 0);
893
+static SENSOR_DEVICE_ATTR_2_RW(pwm1_auto_point2_temp, temp, 0x81, 0);
894
+static SENSOR_DEVICE_ATTR_2_RW(pwm1_auto_point3_temp, temp, 0x82, 0);
895
+static SENSOR_DEVICE_ATTR_2_RW(pwm1_auto_point4_temp, temp, 0x83, 0);
896
+static SENSOR_DEVICE_ATTR_2_RW(pwm1_auto_point5_temp, temp, 0x84, 0);
916897
917898 /* 7.2.120... 0x85-0x88 PWM (Y-axis) transition */
918
-static SENSOR_DEVICE_ATTR(pwm1_auto_point1_pwm, S_IRUGO | S_IWUSR,
919
- show_pwm, store_pwm, 0x85);
920
-static SENSOR_DEVICE_ATTR(pwm1_auto_point2_pwm, S_IRUGO | S_IWUSR,
921
- show_pwm, store_pwm, 0x86);
922
-static SENSOR_DEVICE_ATTR(pwm1_auto_point3_pwm, S_IRUGO | S_IWUSR,
923
- show_pwm, store_pwm, 0x87);
924
-static SENSOR_DEVICE_ATTR(pwm1_auto_point4_pwm, S_IRUGO | S_IWUSR,
925
- show_pwm, store_pwm, 0x88);
926
-static SENSOR_DEVICE_ATTR(pwm1_auto_point5_pwm, S_IRUGO, show_pwm, NULL, 0);
899
+static SENSOR_DEVICE_ATTR_RW(pwm1_auto_point1_pwm, pwm, 0x85);
900
+static SENSOR_DEVICE_ATTR_RW(pwm1_auto_point2_pwm, pwm, 0x86);
901
+static SENSOR_DEVICE_ATTR_RW(pwm1_auto_point3_pwm, pwm, 0x87);
902
+static SENSOR_DEVICE_ATTR_RW(pwm1_auto_point4_pwm, pwm, 0x88);
903
+static SENSOR_DEVICE_ATTR_RO(pwm1_auto_point5_pwm, pwm, 0);
927904
928905 /* 7.2.124 Table 2 X-axis Transition Point 1 Register */
929
-static SENSOR_DEVICE_ATTR_2(pwm2_auto_point1_temp, S_IRUGO | S_IWUSR,
930
- show_temp, store_temp, 0x90, 0);
931
-static SENSOR_DEVICE_ATTR_2(pwm2_auto_point2_temp, S_IRUGO | S_IWUSR,
932
- show_temp, store_temp, 0x91, 0);
933
-static SENSOR_DEVICE_ATTR_2(pwm2_auto_point3_temp, S_IRUGO | S_IWUSR,
934
- show_temp, store_temp, 0x92, 0);
935
-static SENSOR_DEVICE_ATTR_2(pwm2_auto_point4_temp, S_IRUGO | S_IWUSR,
936
- show_temp, store_temp, 0x93, 0);
937
-static SENSOR_DEVICE_ATTR_2(pwm2_auto_point5_temp, S_IRUGO | S_IWUSR,
938
- show_temp, store_temp, 0x94, 0);
906
+static SENSOR_DEVICE_ATTR_2_RW(pwm2_auto_point1_temp, temp, 0x90, 0);
907
+static SENSOR_DEVICE_ATTR_2_RW(pwm2_auto_point2_temp, temp, 0x91, 0);
908
+static SENSOR_DEVICE_ATTR_2_RW(pwm2_auto_point3_temp, temp, 0x92, 0);
909
+static SENSOR_DEVICE_ATTR_2_RW(pwm2_auto_point4_temp, temp, 0x93, 0);
910
+static SENSOR_DEVICE_ATTR_2_RW(pwm2_auto_point5_temp, temp, 0x94, 0);
939911
940912 /* 7.2.129 Table 2 Y-axis Transition Point 1 Register */
941
-static SENSOR_DEVICE_ATTR(pwm2_auto_point1_pwm, S_IRUGO | S_IWUSR,
942
- show_pwm, store_pwm, 0x95);
943
-static SENSOR_DEVICE_ATTR(pwm2_auto_point2_pwm, S_IRUGO | S_IWUSR,
944
- show_pwm, store_pwm, 0x96);
945
-static SENSOR_DEVICE_ATTR(pwm2_auto_point3_pwm, S_IRUGO | S_IWUSR,
946
- show_pwm, store_pwm, 0x97);
947
-static SENSOR_DEVICE_ATTR(pwm2_auto_point4_pwm, S_IRUGO | S_IWUSR,
948
- show_pwm, store_pwm, 0x98);
949
-static SENSOR_DEVICE_ATTR(pwm2_auto_point5_pwm, S_IRUGO, show_pwm, NULL, 0);
913
+static SENSOR_DEVICE_ATTR_RW(pwm2_auto_point1_pwm, pwm, 0x95);
914
+static SENSOR_DEVICE_ATTR_RW(pwm2_auto_point2_pwm, pwm, 0x96);
915
+static SENSOR_DEVICE_ATTR_RW(pwm2_auto_point3_pwm, pwm, 0x97);
916
+static SENSOR_DEVICE_ATTR_RW(pwm2_auto_point4_pwm, pwm, 0x98);
917
+static SENSOR_DEVICE_ATTR_RO(pwm2_auto_point5_pwm, pwm, 0);
950918
951919 /* 7.2.133 Table 3 X-axis Transition Point 1 Register */
952
-static SENSOR_DEVICE_ATTR_2(pwm3_auto_point1_temp, S_IRUGO | S_IWUSR,
953
- show_temp, store_temp, 0xA0, 0);
954
-static SENSOR_DEVICE_ATTR_2(pwm3_auto_point2_temp, S_IRUGO | S_IWUSR,
955
- show_temp, store_temp, 0xA1, 0);
956
-static SENSOR_DEVICE_ATTR_2(pwm3_auto_point3_temp, S_IRUGO | S_IWUSR,
957
- show_temp, store_temp, 0xA2, 0);
958
-static SENSOR_DEVICE_ATTR_2(pwm3_auto_point4_temp, S_IRUGO | S_IWUSR,
959
- show_temp, store_temp, 0xA3, 0);
960
-static SENSOR_DEVICE_ATTR_2(pwm3_auto_point5_temp, S_IRUGO | S_IWUSR,
961
- show_temp, store_temp, 0xA4, 0);
920
+static SENSOR_DEVICE_ATTR_2_RW(pwm3_auto_point1_temp, temp, 0xA0, 0);
921
+static SENSOR_DEVICE_ATTR_2_RW(pwm3_auto_point2_temp, temp, 0xA1, 0);
922
+static SENSOR_DEVICE_ATTR_2_RW(pwm3_auto_point3_temp, temp, 0xA2, 0);
923
+static SENSOR_DEVICE_ATTR_2_RW(pwm3_auto_point4_temp, temp, 0xA3, 0);
924
+static SENSOR_DEVICE_ATTR_2_RW(pwm3_auto_point5_temp, temp, 0xA4, 0);
962925
963926 /* 7.2.138 Table 3 Y-axis Transition Point 1 Register */
964
-static SENSOR_DEVICE_ATTR(pwm3_auto_point1_pwm, S_IRUGO | S_IWUSR,
965
- show_pwm, store_pwm, 0xA5);
966
-static SENSOR_DEVICE_ATTR(pwm3_auto_point2_pwm, S_IRUGO | S_IWUSR,
967
- show_pwm, store_pwm, 0xA6);
968
-static SENSOR_DEVICE_ATTR(pwm3_auto_point3_pwm, S_IRUGO | S_IWUSR,
969
- show_pwm, store_pwm, 0xA7);
970
-static SENSOR_DEVICE_ATTR(pwm3_auto_point4_pwm, S_IRUGO | S_IWUSR,
971
- show_pwm, store_pwm, 0xA8);
972
-static SENSOR_DEVICE_ATTR(pwm3_auto_point5_pwm, S_IRUGO, show_pwm, NULL, 0);
927
+static SENSOR_DEVICE_ATTR_RW(pwm3_auto_point1_pwm, pwm, 0xA5);
928
+static SENSOR_DEVICE_ATTR_RW(pwm3_auto_point2_pwm, pwm, 0xA6);
929
+static SENSOR_DEVICE_ATTR_RW(pwm3_auto_point3_pwm, pwm, 0xA7);
930
+static SENSOR_DEVICE_ATTR_RW(pwm3_auto_point4_pwm, pwm, 0xA8);
931
+static SENSOR_DEVICE_ATTR_RO(pwm3_auto_point5_pwm, pwm, 0);
973932
974933 static struct attribute *nct7802_auto_point_attrs[] = {
975934 &sensor_dev_attr_pwm1_auto_point1_temp.dev_attr.attr,
....@@ -1097,8 +1056,7 @@
10971056 return regmap_update_bits(data->regmap, REG_VMON_ENABLE, 0x03, 0x03);
10981057 }
10991058
1100
-static int nct7802_probe(struct i2c_client *client,
1101
- const struct i2c_device_id *id)
1059
+static int nct7802_probe(struct i2c_client *client)
11021060 {
11031061 struct device *dev = &client->dev;
11041062 struct nct7802_data *data;
....@@ -1114,6 +1072,7 @@
11141072 return PTR_ERR(data->regmap);
11151073
11161074 mutex_init(&data->access_lock);
1075
+ mutex_init(&data->in_alarm_lock);
11171076
11181077 ret = nct7802_init_chip(data);
11191078 if (ret < 0)
....@@ -1141,7 +1100,7 @@
11411100 .name = DRVNAME,
11421101 },
11431102 .detect = nct7802_detect,
1144
- .probe = nct7802_probe,
1103
+ .probe_new = nct7802_probe,
11451104 .id_table = nct7802_idtable,
11461105 .address_list = nct7802_address_list,
11471106 };