hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/hwmon/gl520sm.c
....@@ -1,24 +1,10 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * gl520sm.c - Part of lm_sensors, Linux kernel modules for hardware
34 * monitoring
45 * Copyright (c) 1998, 1999 Frodo Looijaard <frodol@dds.nl>,
56 * Kyösti Mälkki <kmalkki@cc.hut.fi>
67 * Copyright (c) 2005 Maarten Deprez <maartendeprez@users.sourceforge.net>
7
- *
8
- * This program is free software; you can redistribute it and/or modify
9
- * it under the terms of the GNU General Public License as published by
10
- * the Free Software Foundation; either version 2 of the License, or
11
- * (at your option) any later version.
12
- *
13
- * This program is distributed in the hope that it will be useful,
14
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
- * GNU General Public License for more details.
17
- *
18
- * You should have received a copy of the GNU General Public License
19
- * along with this program; if not, write to the Free Software
20
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21
- *
228 */
239
2410 #include <linux/module.h>
....@@ -216,8 +202,8 @@
216202 #define IN_CLAMP(val) clamp_val(val, 0, 255 * 19)
217203 #define IN_TO_REG(val) DIV_ROUND_CLOSEST(IN_CLAMP(val), 19)
218204
219
-static ssize_t get_in_input(struct device *dev, struct device_attribute *attr,
220
- char *buf)
205
+static ssize_t in_input_show(struct device *dev,
206
+ struct device_attribute *attr, char *buf)
221207 {
222208 int n = to_sensor_dev_attr(attr)->index;
223209 struct gl520_data *data = gl520_update_device(dev);
....@@ -229,8 +215,8 @@
229215 return sprintf(buf, "%d\n", IN_FROM_REG(r));
230216 }
231217
232
-static ssize_t get_in_min(struct device *dev, struct device_attribute *attr,
233
- char *buf)
218
+static ssize_t in_min_show(struct device *dev, struct device_attribute *attr,
219
+ char *buf)
234220 {
235221 int n = to_sensor_dev_attr(attr)->index;
236222 struct gl520_data *data = gl520_update_device(dev);
....@@ -242,8 +228,8 @@
242228 return sprintf(buf, "%d\n", IN_FROM_REG(r));
243229 }
244230
245
-static ssize_t get_in_max(struct device *dev, struct device_attribute *attr,
246
- char *buf)
231
+static ssize_t in_max_show(struct device *dev, struct device_attribute *attr,
232
+ char *buf)
247233 {
248234 int n = to_sensor_dev_attr(attr)->index;
249235 struct gl520_data *data = gl520_update_device(dev);
....@@ -255,8 +241,8 @@
255241 return sprintf(buf, "%d\n", IN_FROM_REG(r));
256242 }
257243
258
-static ssize_t set_in_min(struct device *dev, struct device_attribute *attr,
259
- const char *buf, size_t count)
244
+static ssize_t in_min_store(struct device *dev, struct device_attribute *attr,
245
+ const char *buf, size_t count)
260246 {
261247 struct gl520_data *data = dev_get_drvdata(dev);
262248 struct i2c_client *client = data->client;
....@@ -289,8 +275,8 @@
289275 return count;
290276 }
291277
292
-static ssize_t set_in_max(struct device *dev, struct device_attribute *attr,
293
- const char *buf, size_t count)
278
+static ssize_t in_max_store(struct device *dev, struct device_attribute *attr,
279
+ const char *buf, size_t count)
294280 {
295281 struct gl520_data *data = dev_get_drvdata(dev);
296282 struct i2c_client *client = data->client;
....@@ -323,31 +309,21 @@
323309 return count;
324310 }
325311
326
-static SENSOR_DEVICE_ATTR(in0_input, S_IRUGO, get_in_input, NULL, 0);
327
-static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, get_in_input, NULL, 1);
328
-static SENSOR_DEVICE_ATTR(in2_input, S_IRUGO, get_in_input, NULL, 2);
329
-static SENSOR_DEVICE_ATTR(in3_input, S_IRUGO, get_in_input, NULL, 3);
330
-static SENSOR_DEVICE_ATTR(in4_input, S_IRUGO, get_in_input, NULL, 4);
331
-static SENSOR_DEVICE_ATTR(in0_min, S_IRUGO | S_IWUSR,
332
- get_in_min, set_in_min, 0);
333
-static SENSOR_DEVICE_ATTR(in1_min, S_IRUGO | S_IWUSR,
334
- get_in_min, set_in_min, 1);
335
-static SENSOR_DEVICE_ATTR(in2_min, S_IRUGO | S_IWUSR,
336
- get_in_min, set_in_min, 2);
337
-static SENSOR_DEVICE_ATTR(in3_min, S_IRUGO | S_IWUSR,
338
- get_in_min, set_in_min, 3);
339
-static SENSOR_DEVICE_ATTR(in4_min, S_IRUGO | S_IWUSR,
340
- get_in_min, set_in_min, 4);
341
-static SENSOR_DEVICE_ATTR(in0_max, S_IRUGO | S_IWUSR,
342
- get_in_max, set_in_max, 0);
343
-static SENSOR_DEVICE_ATTR(in1_max, S_IRUGO | S_IWUSR,
344
- get_in_max, set_in_max, 1);
345
-static SENSOR_DEVICE_ATTR(in2_max, S_IRUGO | S_IWUSR,
346
- get_in_max, set_in_max, 2);
347
-static SENSOR_DEVICE_ATTR(in3_max, S_IRUGO | S_IWUSR,
348
- get_in_max, set_in_max, 3);
349
-static SENSOR_DEVICE_ATTR(in4_max, S_IRUGO | S_IWUSR,
350
- get_in_max, set_in_max, 4);
312
+static SENSOR_DEVICE_ATTR_RO(in0_input, in_input, 0);
313
+static SENSOR_DEVICE_ATTR_RO(in1_input, in_input, 1);
314
+static SENSOR_DEVICE_ATTR_RO(in2_input, in_input, 2);
315
+static SENSOR_DEVICE_ATTR_RO(in3_input, in_input, 3);
316
+static SENSOR_DEVICE_ATTR_RO(in4_input, in_input, 4);
317
+static SENSOR_DEVICE_ATTR_RW(in0_min, in_min, 0);
318
+static SENSOR_DEVICE_ATTR_RW(in1_min, in_min, 1);
319
+static SENSOR_DEVICE_ATTR_RW(in2_min, in_min, 2);
320
+static SENSOR_DEVICE_ATTR_RW(in3_min, in_min, 3);
321
+static SENSOR_DEVICE_ATTR_RW(in4_min, in_min, 4);
322
+static SENSOR_DEVICE_ATTR_RW(in0_max, in_max, 0);
323
+static SENSOR_DEVICE_ATTR_RW(in1_max, in_max, 1);
324
+static SENSOR_DEVICE_ATTR_RW(in2_max, in_max, 2);
325
+static SENSOR_DEVICE_ATTR_RW(in3_max, in_max, 3);
326
+static SENSOR_DEVICE_ATTR_RW(in4_max, in_max, 4);
351327
352328 #define DIV_FROM_REG(val) (1 << (val))
353329 #define FAN_FROM_REG(val, div) ((val) == 0 ? 0 : (480000 / ((val) << (div))))
....@@ -359,8 +335,8 @@
359335 DIV_ROUND_CLOSEST(480000, \
360336 FAN_CLAMP(val, div) << (div)))
361337
362
-static ssize_t get_fan_input(struct device *dev, struct device_attribute *attr,
363
- char *buf)
338
+static ssize_t fan_input_show(struct device *dev,
339
+ struct device_attribute *attr, char *buf)
364340 {
365341 int n = to_sensor_dev_attr(attr)->index;
366342 struct gl520_data *data = gl520_update_device(dev);
....@@ -369,8 +345,8 @@
369345 data->fan_div[n]));
370346 }
371347
372
-static ssize_t get_fan_min(struct device *dev, struct device_attribute *attr,
373
- char *buf)
348
+static ssize_t fan_min_show(struct device *dev, struct device_attribute *attr,
349
+ char *buf)
374350 {
375351 int n = to_sensor_dev_attr(attr)->index;
376352 struct gl520_data *data = gl520_update_device(dev);
....@@ -379,8 +355,8 @@
379355 data->fan_div[n]));
380356 }
381357
382
-static ssize_t get_fan_div(struct device *dev, struct device_attribute *attr,
383
- char *buf)
358
+static ssize_t fan_div_show(struct device *dev, struct device_attribute *attr,
359
+ char *buf)
384360 {
385361 int n = to_sensor_dev_attr(attr)->index;
386362 struct gl520_data *data = gl520_update_device(dev);
....@@ -395,8 +371,9 @@
395371 return sprintf(buf, "%d\n", data->fan_off);
396372 }
397373
398
-static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr,
399
- const char *buf, size_t count)
374
+static ssize_t fan_min_store(struct device *dev,
375
+ struct device_attribute *attr, const char *buf,
376
+ size_t count)
400377 {
401378 struct gl520_data *data = dev_get_drvdata(dev);
402379 struct i2c_client *client = data->client;
....@@ -434,8 +411,9 @@
434411 return count;
435412 }
436413
437
-static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
438
- const char *buf, size_t count)
414
+static ssize_t fan_div_store(struct device *dev,
415
+ struct device_attribute *attr, const char *buf,
416
+ size_t count)
439417 {
440418 struct gl520_data *data = dev_get_drvdata(dev);
441419 struct i2c_client *client = data->client;
....@@ -508,24 +486,20 @@
508486 return count;
509487 }
510488
511
-static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, get_fan_input, NULL, 0);
512
-static SENSOR_DEVICE_ATTR(fan2_input, S_IRUGO, get_fan_input, NULL, 1);
513
-static SENSOR_DEVICE_ATTR(fan1_min, S_IRUGO | S_IWUSR,
514
- get_fan_min, set_fan_min, 0);
515
-static SENSOR_DEVICE_ATTR(fan2_min, S_IRUGO | S_IWUSR,
516
- get_fan_min, set_fan_min, 1);
517
-static SENSOR_DEVICE_ATTR(fan1_div, S_IRUGO | S_IWUSR,
518
- get_fan_div, set_fan_div, 0);
519
-static SENSOR_DEVICE_ATTR(fan2_div, S_IRUGO | S_IWUSR,
520
- get_fan_div, set_fan_div, 1);
489
+static SENSOR_DEVICE_ATTR_RO(fan1_input, fan_input, 0);
490
+static SENSOR_DEVICE_ATTR_RO(fan2_input, fan_input, 1);
491
+static SENSOR_DEVICE_ATTR_RW(fan1_min, fan_min, 0);
492
+static SENSOR_DEVICE_ATTR_RW(fan2_min, fan_min, 1);
493
+static SENSOR_DEVICE_ATTR_RW(fan1_div, fan_div, 0);
494
+static SENSOR_DEVICE_ATTR_RW(fan2_div, fan_div, 1);
521495 static DEVICE_ATTR_RW(fan1_off);
522496
523497 #define TEMP_FROM_REG(val) (((val) - 130) * 1000)
524498 #define TEMP_CLAMP(val) clamp_val(val, -130000, 125000)
525499 #define TEMP_TO_REG(val) (DIV_ROUND_CLOSEST(TEMP_CLAMP(val), 1000) + 130)
526500
527
-static ssize_t get_temp_input(struct device *dev, struct device_attribute *attr,
528
- char *buf)
501
+static ssize_t temp_input_show(struct device *dev,
502
+ struct device_attribute *attr, char *buf)
529503 {
530504 int n = to_sensor_dev_attr(attr)->index;
531505 struct gl520_data *data = gl520_update_device(dev);
....@@ -533,8 +507,8 @@
533507 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_input[n]));
534508 }
535509
536
-static ssize_t get_temp_max(struct device *dev, struct device_attribute *attr,
537
- char *buf)
510
+static ssize_t temp_max_show(struct device *dev,
511
+ struct device_attribute *attr, char *buf)
538512 {
539513 int n = to_sensor_dev_attr(attr)->index;
540514 struct gl520_data *data = gl520_update_device(dev);
....@@ -542,8 +516,8 @@
542516 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max[n]));
543517 }
544518
545
-static ssize_t get_temp_max_hyst(struct device *dev,
546
- struct device_attribute *attr, char *buf)
519
+static ssize_t temp_max_hyst_show(struct device *dev,
520
+ struct device_attribute *attr, char *buf)
547521 {
548522 int n = to_sensor_dev_attr(attr)->index;
549523 struct gl520_data *data = gl520_update_device(dev);
....@@ -551,8 +525,9 @@
551525 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max_hyst[n]));
552526 }
553527
554
-static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr,
555
- const char *buf, size_t count)
528
+static ssize_t temp_max_store(struct device *dev,
529
+ struct device_attribute *attr, const char *buf,
530
+ size_t count)
556531 {
557532 struct gl520_data *data = dev_get_drvdata(dev);
558533 struct i2c_client *client = data->client;
....@@ -571,8 +546,9 @@
571546 return count;
572547 }
573548
574
-static ssize_t set_temp_max_hyst(struct device *dev, struct device_attribute
575
- *attr, const char *buf, size_t count)
549
+static ssize_t temp_max_hyst_store(struct device *dev,
550
+ struct device_attribute *attr,
551
+ const char *buf, size_t count)
576552 {
577553 struct gl520_data *data = dev_get_drvdata(dev);
578554 struct i2c_client *client = data->client;
....@@ -592,16 +568,12 @@
592568 return count;
593569 }
594570
595
-static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, get_temp_input, NULL, 0);
596
-static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, get_temp_input, NULL, 1);
597
-static SENSOR_DEVICE_ATTR(temp1_max, S_IRUGO | S_IWUSR,
598
- get_temp_max, set_temp_max, 0);
599
-static SENSOR_DEVICE_ATTR(temp2_max, S_IRUGO | S_IWUSR,
600
- get_temp_max, set_temp_max, 1);
601
-static SENSOR_DEVICE_ATTR(temp1_max_hyst, S_IRUGO | S_IWUSR,
602
- get_temp_max_hyst, set_temp_max_hyst, 0);
603
-static SENSOR_DEVICE_ATTR(temp2_max_hyst, S_IRUGO | S_IWUSR,
604
- get_temp_max_hyst, set_temp_max_hyst, 1);
571
+static SENSOR_DEVICE_ATTR_RO(temp1_input, temp_input, 0);
572
+static SENSOR_DEVICE_ATTR_RO(temp2_input, temp_input, 1);
573
+static SENSOR_DEVICE_ATTR_RW(temp1_max, temp_max, 0);
574
+static SENSOR_DEVICE_ATTR_RW(temp2_max, temp_max, 1);
575
+static SENSOR_DEVICE_ATTR_RW(temp1_max_hyst, temp_max_hyst, 0);
576
+static SENSOR_DEVICE_ATTR_RW(temp2_max_hyst, temp_max_hyst, 1);
605577
606578 static ssize_t alarms_show(struct device *dev, struct device_attribute *attr,
607579 char *buf)
....@@ -674,8 +646,8 @@
674646 static DEVICE_ATTR_RW(beep_enable);
675647 static DEVICE_ATTR_RW(beep_mask);
676648
677
-static ssize_t get_alarm(struct device *dev, struct device_attribute *attr,
678
- char *buf)
649
+static ssize_t alarm_show(struct device *dev, struct device_attribute *attr,
650
+ char *buf)
679651 {
680652 int bit_nr = to_sensor_dev_attr(attr)->index;
681653 struct gl520_data *data = gl520_update_device(dev);
....@@ -683,18 +655,18 @@
683655 return sprintf(buf, "%d\n", (data->alarms >> bit_nr) & 1);
684656 }
685657
686
-static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, get_alarm, NULL, 0);
687
-static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, get_alarm, NULL, 1);
688
-static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, get_alarm, NULL, 2);
689
-static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, get_alarm, NULL, 3);
690
-static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, get_alarm, NULL, 4);
691
-static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, get_alarm, NULL, 5);
692
-static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, get_alarm, NULL, 6);
693
-static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, get_alarm, NULL, 7);
694
-static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, get_alarm, NULL, 7);
658
+static SENSOR_DEVICE_ATTR_RO(in0_alarm, alarm, 0);
659
+static SENSOR_DEVICE_ATTR_RO(in1_alarm, alarm, 1);
660
+static SENSOR_DEVICE_ATTR_RO(in2_alarm, alarm, 2);
661
+static SENSOR_DEVICE_ATTR_RO(in3_alarm, alarm, 3);
662
+static SENSOR_DEVICE_ATTR_RO(temp1_alarm, alarm, 4);
663
+static SENSOR_DEVICE_ATTR_RO(fan1_alarm, alarm, 5);
664
+static SENSOR_DEVICE_ATTR_RO(fan2_alarm, alarm, 6);
665
+static SENSOR_DEVICE_ATTR_RO(temp2_alarm, alarm, 7);
666
+static SENSOR_DEVICE_ATTR_RO(in4_alarm, alarm, 7);
695667
696
-static ssize_t get_beep(struct device *dev, struct device_attribute *attr,
697
- char *buf)
668
+static ssize_t beep_show(struct device *dev, struct device_attribute *attr,
669
+ char *buf)
698670 {
699671 int bitnr = to_sensor_dev_attr(attr)->index;
700672 struct gl520_data *data = gl520_update_device(dev);
....@@ -702,8 +674,8 @@
702674 return sprintf(buf, "%d\n", (data->beep_mask >> bitnr) & 1);
703675 }
704676
705
-static ssize_t set_beep(struct device *dev, struct device_attribute *attr,
706
- const char *buf, size_t count)
677
+static ssize_t beep_store(struct device *dev, struct device_attribute *attr,
678
+ const char *buf, size_t count)
707679 {
708680 struct gl520_data *data = dev_get_drvdata(dev);
709681 struct i2c_client *client = data->client;
....@@ -729,15 +701,15 @@
729701 return count;
730702 }
731703
732
-static SENSOR_DEVICE_ATTR(in0_beep, S_IRUGO | S_IWUSR, get_beep, set_beep, 0);
733
-static SENSOR_DEVICE_ATTR(in1_beep, S_IRUGO | S_IWUSR, get_beep, set_beep, 1);
734
-static SENSOR_DEVICE_ATTR(in2_beep, S_IRUGO | S_IWUSR, get_beep, set_beep, 2);
735
-static SENSOR_DEVICE_ATTR(in3_beep, S_IRUGO | S_IWUSR, get_beep, set_beep, 3);
736
-static SENSOR_DEVICE_ATTR(temp1_beep, S_IRUGO | S_IWUSR, get_beep, set_beep, 4);
737
-static SENSOR_DEVICE_ATTR(fan1_beep, S_IRUGO | S_IWUSR, get_beep, set_beep, 5);
738
-static SENSOR_DEVICE_ATTR(fan2_beep, S_IRUGO | S_IWUSR, get_beep, set_beep, 6);
739
-static SENSOR_DEVICE_ATTR(temp2_beep, S_IRUGO | S_IWUSR, get_beep, set_beep, 7);
740
-static SENSOR_DEVICE_ATTR(in4_beep, S_IRUGO | S_IWUSR, get_beep, set_beep, 7);
704
+static SENSOR_DEVICE_ATTR_RW(in0_beep, beep, 0);
705
+static SENSOR_DEVICE_ATTR_RW(in1_beep, beep, 1);
706
+static SENSOR_DEVICE_ATTR_RW(in2_beep, beep, 2);
707
+static SENSOR_DEVICE_ATTR_RW(in3_beep, beep, 3);
708
+static SENSOR_DEVICE_ATTR_RW(temp1_beep, beep, 4);
709
+static SENSOR_DEVICE_ATTR_RW(fan1_beep, beep, 5);
710
+static SENSOR_DEVICE_ATTR_RW(fan2_beep, beep, 6);
711
+static SENSOR_DEVICE_ATTR_RW(temp2_beep, beep, 7);
712
+static SENSOR_DEVICE_ATTR_RW(in4_beep, beep, 7);
741713
742714 static struct attribute *gl520_attributes[] = {
743715 &dev_attr_cpu0_vid.attr,
....@@ -882,8 +854,7 @@
882854 gl520_write_value(client, GL520_REG_BEEP_MASK, data->beep_mask);
883855 }
884856
885
-static int gl520_probe(struct i2c_client *client,
886
- const struct i2c_device_id *id)
857
+static int gl520_probe(struct i2c_client *client)
887858 {
888859 struct device *dev = &client->dev;
889860 struct device *hwmon_dev;
....@@ -924,7 +895,7 @@
924895 .driver = {
925896 .name = "gl520sm",
926897 },
927
- .probe = gl520_probe,
898
+ .probe_new = gl520_probe,
928899 .id_table = gl520_id,
929900 .detect = gl520_detect,
930901 .address_list = normal_i2c,