hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/hwmon/vt8231.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * vt8231.c - Part of lm_sensors, Linux kernel modules
34 * for hardware monitoring
....@@ -5,20 +6,6 @@
56 * Copyright (c) 2005 Roger Lucas <vt8231@hiddenengine.co.uk>
67 * Copyright (c) 2002 Mark D. Studebaker <mdsxyz123@yahoo.com>
78 * Aaron M. Marsh <amarsh@sdf.lonestar.org>
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 /*
....@@ -192,8 +179,8 @@
192179 }
193180
194181 /* following are the sysfs callback functions */
195
-static ssize_t show_in(struct device *dev, struct device_attribute *attr,
196
- char *buf)
182
+static ssize_t in_show(struct device *dev, struct device_attribute *attr,
183
+ char *buf)
197184 {
198185 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
199186 int nr = sensor_attr->index;
....@@ -202,8 +189,8 @@
202189 return sprintf(buf, "%d\n", ((data->in[nr] - 3) * 10000) / 958);
203190 }
204191
205
-static ssize_t show_in_min(struct device *dev, struct device_attribute *attr,
206
- char *buf)
192
+static ssize_t in_min_show(struct device *dev, struct device_attribute *attr,
193
+ char *buf)
207194 {
208195 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
209196 int nr = sensor_attr->index;
....@@ -212,8 +199,8 @@
212199 return sprintf(buf, "%d\n", ((data->in_min[nr] - 3) * 10000) / 958);
213200 }
214201
215
-static ssize_t show_in_max(struct device *dev, struct device_attribute *attr,
216
- char *buf)
202
+static ssize_t in_max_show(struct device *dev, struct device_attribute *attr,
203
+ char *buf)
217204 {
218205 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
219206 int nr = sensor_attr->index;
....@@ -222,8 +209,8 @@
222209 return sprintf(buf, "%d\n", (((data->in_max[nr] - 3) * 10000) / 958));
223210 }
224211
225
-static ssize_t set_in_min(struct device *dev, struct device_attribute *attr,
226
- const char *buf, size_t count)
212
+static ssize_t in_min_store(struct device *dev, struct device_attribute *attr,
213
+ const char *buf, size_t count)
227214 {
228215 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
229216 int nr = sensor_attr->index;
....@@ -242,8 +229,8 @@
242229 return count;
243230 }
244231
245
-static ssize_t set_in_max(struct device *dev, struct device_attribute *attr,
246
- const char *buf, size_t count)
232
+static ssize_t in_max_store(struct device *dev, struct device_attribute *attr,
233
+ const char *buf, size_t count)
247234 {
248235 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
249236 int nr = sensor_attr->index;
....@@ -330,19 +317,21 @@
330317 return count;
331318 }
332319
333
-#define define_voltage_sysfs(offset) \
334
-static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, \
335
- show_in, NULL, offset); \
336
-static SENSOR_DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \
337
- show_in_min, set_in_min, offset); \
338
-static SENSOR_DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \
339
- show_in_max, set_in_max, offset)
340
-
341
-define_voltage_sysfs(0);
342
-define_voltage_sysfs(1);
343
-define_voltage_sysfs(2);
344
-define_voltage_sysfs(3);
345
-define_voltage_sysfs(4);
320
+static SENSOR_DEVICE_ATTR_RO(in0_input, in, 0);
321
+static SENSOR_DEVICE_ATTR_RW(in0_min, in_min, 0);
322
+static SENSOR_DEVICE_ATTR_RW(in0_max, in_max, 0);
323
+static SENSOR_DEVICE_ATTR_RO(in1_input, in, 1);
324
+static SENSOR_DEVICE_ATTR_RW(in1_min, in_min, 1);
325
+static SENSOR_DEVICE_ATTR_RW(in1_max, in_max, 1);
326
+static SENSOR_DEVICE_ATTR_RO(in2_input, in, 2);
327
+static SENSOR_DEVICE_ATTR_RW(in2_min, in_min, 2);
328
+static SENSOR_DEVICE_ATTR_RW(in2_max, in_max, 2);
329
+static SENSOR_DEVICE_ATTR_RO(in3_input, in, 3);
330
+static SENSOR_DEVICE_ATTR_RW(in3_min, in_min, 3);
331
+static SENSOR_DEVICE_ATTR_RW(in3_max, in_max, 3);
332
+static SENSOR_DEVICE_ATTR_RO(in4_input, in, 4);
333
+static SENSOR_DEVICE_ATTR_RW(in4_min, in_min, 4);
334
+static SENSOR_DEVICE_ATTR_RW(in4_max, in_max, 4);
346335
347336 static DEVICE_ATTR_RO(in5_input);
348337 static DEVICE_ATTR_RW(in5_min);
....@@ -407,8 +396,8 @@
407396 return count;
408397 }
409398
410
-static ssize_t show_temp(struct device *dev, struct device_attribute *attr,
411
- char *buf)
399
+static ssize_t temp_show(struct device *dev, struct device_attribute *attr,
400
+ char *buf)
412401 {
413402 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
414403 int nr = sensor_attr->index;
....@@ -416,8 +405,8 @@
416405 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[nr]));
417406 }
418407
419
-static ssize_t show_temp_max(struct device *dev, struct device_attribute *attr,
420
- char *buf)
408
+static ssize_t temp_max_show(struct device *dev,
409
+ struct device_attribute *attr, char *buf)
421410 {
422411 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
423412 int nr = sensor_attr->index;
....@@ -425,8 +414,8 @@
425414 return sprintf(buf, "%d\n", TEMP_MAXMIN_FROM_REG(data->temp_max[nr]));
426415 }
427416
428
-static ssize_t show_temp_min(struct device *dev, struct device_attribute *attr,
429
- char *buf)
417
+static ssize_t temp_min_show(struct device *dev,
418
+ struct device_attribute *attr, char *buf)
430419 {
431420 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
432421 int nr = sensor_attr->index;
....@@ -434,8 +423,9 @@
434423 return sprintf(buf, "%d\n", TEMP_MAXMIN_FROM_REG(data->temp_min[nr]));
435424 }
436425
437
-static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr,
438
- const char *buf, size_t count)
426
+static ssize_t temp_max_store(struct device *dev,
427
+ struct device_attribute *attr, const char *buf,
428
+ size_t count)
439429 {
440430 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
441431 int nr = sensor_attr->index;
....@@ -453,8 +443,9 @@
453443 mutex_unlock(&data->update_lock);
454444 return count;
455445 }
456
-static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr,
457
- const char *buf, size_t count)
446
+static ssize_t temp_min_store(struct device *dev,
447
+ struct device_attribute *attr, const char *buf,
448
+ size_t count)
458449 {
459450 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
460451 int nr = sensor_attr->index;
....@@ -477,27 +468,30 @@
477468 * Note that these map the Linux temperature sensor numbering (1-6) to the VIA
478469 * temperature sensor numbering (0-5)
479470 */
480
-#define define_temperature_sysfs(offset) \
481
-static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, \
482
- show_temp, NULL, offset - 1); \
483
-static SENSOR_DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \
484
- show_temp_max, set_temp_max, offset - 1); \
485
-static SENSOR_DEVICE_ATTR(temp##offset##_max_hyst, S_IRUGO | S_IWUSR, \
486
- show_temp_min, set_temp_min, offset - 1)
487471
488472 static DEVICE_ATTR_RO(temp1_input);
489473 static DEVICE_ATTR_RW(temp1_max);
490474 static DEVICE_ATTR_RW(temp1_max_hyst);
491475
492
-define_temperature_sysfs(2);
493
-define_temperature_sysfs(3);
494
-define_temperature_sysfs(4);
495
-define_temperature_sysfs(5);
496
-define_temperature_sysfs(6);
476
+static SENSOR_DEVICE_ATTR_RO(temp2_input, temp, 1);
477
+static SENSOR_DEVICE_ATTR_RW(temp2_max, temp_max, 1);
478
+static SENSOR_DEVICE_ATTR_RW(temp2_max_hyst, temp_min, 1);
479
+static SENSOR_DEVICE_ATTR_RO(temp3_input, temp, 2);
480
+static SENSOR_DEVICE_ATTR_RW(temp3_max, temp_max, 2);
481
+static SENSOR_DEVICE_ATTR_RW(temp3_max_hyst, temp_min, 2);
482
+static SENSOR_DEVICE_ATTR_RO(temp4_input, temp, 3);
483
+static SENSOR_DEVICE_ATTR_RW(temp4_max, temp_max, 3);
484
+static SENSOR_DEVICE_ATTR_RW(temp4_max_hyst, temp_min, 3);
485
+static SENSOR_DEVICE_ATTR_RO(temp5_input, temp, 4);
486
+static SENSOR_DEVICE_ATTR_RW(temp5_max, temp_max, 4);
487
+static SENSOR_DEVICE_ATTR_RW(temp5_max_hyst, temp_min, 4);
488
+static SENSOR_DEVICE_ATTR_RO(temp6_input, temp, 5);
489
+static SENSOR_DEVICE_ATTR_RW(temp6_max, temp_max, 5);
490
+static SENSOR_DEVICE_ATTR_RW(temp6_max_hyst, temp_min, 5);
497491
498492 /* Fans */
499
-static ssize_t show_fan(struct device *dev, struct device_attribute *attr,
500
- char *buf)
493
+static ssize_t fan_show(struct device *dev, struct device_attribute *attr,
494
+ char *buf)
501495 {
502496 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
503497 int nr = sensor_attr->index;
....@@ -506,8 +500,8 @@
506500 DIV_FROM_REG(data->fan_div[nr])));
507501 }
508502
509
-static ssize_t show_fan_min(struct device *dev, struct device_attribute *attr,
510
- char *buf)
503
+static ssize_t fan_min_show(struct device *dev, struct device_attribute *attr,
504
+ char *buf)
511505 {
512506 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
513507 int nr = sensor_attr->index;
....@@ -516,8 +510,8 @@
516510 DIV_FROM_REG(data->fan_div[nr])));
517511 }
518512
519
-static ssize_t show_fan_div(struct device *dev, struct device_attribute *attr,
520
- char *buf)
513
+static ssize_t fan_div_show(struct device *dev, struct device_attribute *attr,
514
+ char *buf)
521515 {
522516 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
523517 int nr = sensor_attr->index;
....@@ -525,8 +519,9 @@
525519 return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr]));
526520 }
527521
528
-static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr,
529
- const char *buf, size_t count)
522
+static ssize_t fan_min_store(struct device *dev,
523
+ struct device_attribute *attr, const char *buf,
524
+ size_t count)
530525 {
531526 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
532527 int nr = sensor_attr->index;
....@@ -545,8 +540,9 @@
545540 return count;
546541 }
547542
548
-static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
549
- const char *buf, size_t count)
543
+static ssize_t fan_div_store(struct device *dev,
544
+ struct device_attribute *attr, const char *buf,
545
+ size_t count)
550546 {
551547 struct vt8231_data *data = dev_get_drvdata(dev);
552548 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
....@@ -593,17 +589,12 @@
593589 return count;
594590 }
595591
596
-
597
-#define define_fan_sysfs(offset) \
598
-static SENSOR_DEVICE_ATTR(fan##offset##_input, S_IRUGO, \
599
- show_fan, NULL, offset - 1); \
600
-static SENSOR_DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \
601
- show_fan_div, set_fan_div, offset - 1); \
602
-static SENSOR_DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
603
- show_fan_min, set_fan_min, offset - 1)
604
-
605
-define_fan_sysfs(1);
606
-define_fan_sysfs(2);
592
+static SENSOR_DEVICE_ATTR_RO(fan1_input, fan, 0);
593
+static SENSOR_DEVICE_ATTR_RW(fan1_min, fan_min, 0);
594
+static SENSOR_DEVICE_ATTR_RW(fan1_div, fan_div, 0);
595
+static SENSOR_DEVICE_ATTR_RO(fan2_input, fan, 1);
596
+static SENSOR_DEVICE_ATTR_RW(fan2_min, fan_min, 1);
597
+static SENSOR_DEVICE_ATTR_RW(fan2_div, fan_div, 1);
607598
608599 /* Alarms */
609600 static ssize_t alarms_show(struct device *dev, struct device_attribute *attr,
....@@ -614,27 +605,27 @@
614605 }
615606 static DEVICE_ATTR_RO(alarms);
616607
617
-static ssize_t show_alarm(struct device *dev, struct device_attribute *attr,
608
+static ssize_t alarm_show(struct device *dev, struct device_attribute *attr,
618609 char *buf)
619610 {
620611 int bitnr = to_sensor_dev_attr(attr)->index;
621612 struct vt8231_data *data = vt8231_update_device(dev);
622613 return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1);
623614 }
624
-static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 4);
625
-static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 11);
626
-static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 0);
627
-static SENSOR_DEVICE_ATTR(temp4_alarm, S_IRUGO, show_alarm, NULL, 1);
628
-static SENSOR_DEVICE_ATTR(temp5_alarm, S_IRUGO, show_alarm, NULL, 3);
629
-static SENSOR_DEVICE_ATTR(temp6_alarm, S_IRUGO, show_alarm, NULL, 8);
630
-static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 11);
631
-static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 0);
632
-static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 1);
633
-static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 3);
634
-static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 8);
635
-static SENSOR_DEVICE_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL, 2);
636
-static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 6);
637
-static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 7);
615
+static SENSOR_DEVICE_ATTR_RO(temp1_alarm, alarm, 4);
616
+static SENSOR_DEVICE_ATTR_RO(temp2_alarm, alarm, 11);
617
+static SENSOR_DEVICE_ATTR_RO(temp3_alarm, alarm, 0);
618
+static SENSOR_DEVICE_ATTR_RO(temp4_alarm, alarm, 1);
619
+static SENSOR_DEVICE_ATTR_RO(temp5_alarm, alarm, 3);
620
+static SENSOR_DEVICE_ATTR_RO(temp6_alarm, alarm, 8);
621
+static SENSOR_DEVICE_ATTR_RO(in0_alarm, alarm, 11);
622
+static SENSOR_DEVICE_ATTR_RO(in1_alarm, alarm, 0);
623
+static SENSOR_DEVICE_ATTR_RO(in2_alarm, alarm, 1);
624
+static SENSOR_DEVICE_ATTR_RO(in3_alarm, alarm, 3);
625
+static SENSOR_DEVICE_ATTR_RO(in4_alarm, alarm, 8);
626
+static SENSOR_DEVICE_ATTR_RO(in5_alarm, alarm, 2);
627
+static SENSOR_DEVICE_ATTR_RO(fan1_alarm, alarm, 6);
628
+static SENSOR_DEVICE_ATTR_RO(fan2_alarm, alarm, 7);
638629
639630 static ssize_t name_show(struct device *dev, struct device_attribute
640631 *devattr, char *buf)
....@@ -1001,8 +992,8 @@
1001992 return -ENODEV;
1002993 }
1003994
1004
- if (PCIBIOS_SUCCESSFUL != pci_read_config_word(dev, VT8231_BASE_REG,
1005
- &val))
995
+ pci_read_config_word(dev, VT8231_BASE_REG, &val);
996
+ if (val == (u16)~0)
1006997 return -ENODEV;
1007998
1008999 address = val & ~(VT8231_EXTENT - 1);
....@@ -1011,8 +1002,8 @@
10111002 return -ENODEV;
10121003 }
10131004
1014
- if (PCIBIOS_SUCCESSFUL != pci_read_config_word(dev, VT8231_ENABLE_REG,
1015
- &val))
1005
+ pci_read_config_word(dev, VT8231_ENABLE_REG, &val);
1006
+ if (val == (u16)~0)
10161007 return -ENODEV;
10171008
10181009 if (!(val & 0x0001)) {