hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/drivers/hwmon/ina209.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Driver for the Texas Instruments / Burr Brown INA209
34 * Bidirectional Current/Power Monitor
....@@ -12,12 +13,8 @@
1213 * Copyright (C) 2012 Lothar Felten <l-felten@ti.com>
1314 * Thanks to Jan Volkering
1415 *
15
- * This program is free software; you can redistribute it and/or modify
16
- * it under the terms of the GNU General Public License as published by
17
- * the Free Software Foundation; version 2 of the License.
18
- *
1916 * Datasheet:
20
- * http://www.ti.com/lit/gpn/ina209
17
+ * https://www.ti.com/lit/gpn/ina209
2118 */
2219
2320 #include <linux/kernel.h>
....@@ -230,9 +227,9 @@
230227 return (config & 0xf807) | (adc << 3) | (adc << 7);
231228 }
232229
233
-static ssize_t ina209_set_interval(struct device *dev,
234
- struct device_attribute *da,
235
- const char *buf, size_t count)
230
+static ssize_t ina209_interval_store(struct device *dev,
231
+ struct device_attribute *da,
232
+ const char *buf, size_t count)
236233 {
237234 struct ina209_data *data = ina209_update_device(dev);
238235 long val;
....@@ -257,7 +254,7 @@
257254 return count;
258255 }
259256
260
-static ssize_t ina209_show_interval(struct device *dev,
257
+static ssize_t ina209_interval_show(struct device *dev,
261258 struct device_attribute *da, char *buf)
262259 {
263260 struct ina209_data *data = dev_get_drvdata(dev);
....@@ -279,10 +276,9 @@
279276 INA209_POWER_PEAK
280277 };
281278
282
-static ssize_t ina209_reset_history(struct device *dev,
279
+static ssize_t ina209_history_store(struct device *dev,
283280 struct device_attribute *da,
284
- const char *buf,
285
- size_t count)
281
+ const char *buf, size_t count)
286282 {
287283 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
288284 struct ina209_data *data = dev_get_drvdata(dev);
....@@ -306,10 +302,9 @@
306302 return count;
307303 }
308304
309
-static ssize_t ina209_set_value(struct device *dev,
310
- struct device_attribute *da,
311
- const char *buf,
312
- size_t count)
305
+static ssize_t ina209_value_store(struct device *dev,
306
+ struct device_attribute *da,
307
+ const char *buf, size_t count)
313308 {
314309 struct ina209_data *data = ina209_update_device(dev);
315310 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
....@@ -337,9 +332,8 @@
337332 return count;
338333 }
339334
340
-static ssize_t ina209_show_value(struct device *dev,
341
- struct device_attribute *da,
342
- char *buf)
335
+static ssize_t ina209_value_show(struct device *dev,
336
+ struct device_attribute *da, char *buf)
343337 {
344338 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
345339 struct ina209_data *data = ina209_update_device(dev);
....@@ -352,9 +346,8 @@
352346 return snprintf(buf, PAGE_SIZE, "%ld\n", val);
353347 }
354348
355
-static ssize_t ina209_show_alarm(struct device *dev,
356
- struct device_attribute *da,
357
- char *buf)
349
+static ssize_t ina209_alarm_show(struct device *dev,
350
+ struct device_attribute *da, char *buf)
358351 {
359352 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
360353 struct ina209_data *data = ina209_update_device(dev);
....@@ -374,82 +367,65 @@
374367 }
375368
376369 /* Shunt voltage, history, limits, alarms */
377
-static SENSOR_DEVICE_ATTR(in0_input, S_IRUGO, ina209_show_value, NULL,
378
- INA209_SHUNT_VOLTAGE);
379
-static SENSOR_DEVICE_ATTR(in0_input_highest, S_IRUGO, ina209_show_value, NULL,
380
- INA209_SHUNT_VOLTAGE_POS_PEAK);
381
-static SENSOR_DEVICE_ATTR(in0_input_lowest, S_IRUGO, ina209_show_value, NULL,
382
- INA209_SHUNT_VOLTAGE_NEG_PEAK);
383
-static SENSOR_DEVICE_ATTR(in0_reset_history, S_IWUSR, NULL,
384
- ina209_reset_history, (1 << 0) | (1 << 1));
385
-static SENSOR_DEVICE_ATTR(in0_max, S_IRUGO | S_IWUSR, ina209_show_value,
386
- ina209_set_value, INA209_SHUNT_VOLTAGE_POS_WARN);
387
-static SENSOR_DEVICE_ATTR(in0_min, S_IRUGO | S_IWUSR, ina209_show_value,
388
- ina209_set_value, INA209_SHUNT_VOLTAGE_NEG_WARN);
389
-static SENSOR_DEVICE_ATTR(in0_crit_max, S_IRUGO | S_IWUSR, ina209_show_value,
390
- ina209_set_value, INA209_CRITICAL_DAC_POS);
391
-static SENSOR_DEVICE_ATTR(in0_crit_min, S_IRUGO | S_IWUSR, ina209_show_value,
392
- ina209_set_value, INA209_CRITICAL_DAC_NEG);
370
+static SENSOR_DEVICE_ATTR_RO(in0_input, ina209_value, INA209_SHUNT_VOLTAGE);
371
+static SENSOR_DEVICE_ATTR_RO(in0_input_highest, ina209_value,
372
+ INA209_SHUNT_VOLTAGE_POS_PEAK);
373
+static SENSOR_DEVICE_ATTR_RO(in0_input_lowest, ina209_value,
374
+ INA209_SHUNT_VOLTAGE_NEG_PEAK);
375
+static SENSOR_DEVICE_ATTR_WO(in0_reset_history, ina209_history,
376
+ (1 << 0) | (1 << 1));
377
+static SENSOR_DEVICE_ATTR_RW(in0_max, ina209_value,
378
+ INA209_SHUNT_VOLTAGE_POS_WARN);
379
+static SENSOR_DEVICE_ATTR_RW(in0_min, ina209_value,
380
+ INA209_SHUNT_VOLTAGE_NEG_WARN);
381
+static SENSOR_DEVICE_ATTR_RW(in0_crit_max, ina209_value,
382
+ INA209_CRITICAL_DAC_POS);
383
+static SENSOR_DEVICE_ATTR_RW(in0_crit_min, ina209_value,
384
+ INA209_CRITICAL_DAC_NEG);
393385
394
-static SENSOR_DEVICE_ATTR(in0_min_alarm, S_IRUGO, ina209_show_alarm, NULL,
395
- 1 << 11);
396
-static SENSOR_DEVICE_ATTR(in0_max_alarm, S_IRUGO, ina209_show_alarm, NULL,
397
- 1 << 12);
398
-static SENSOR_DEVICE_ATTR(in0_crit_min_alarm, S_IRUGO, ina209_show_alarm, NULL,
399
- 1 << 6);
400
-static SENSOR_DEVICE_ATTR(in0_crit_max_alarm, S_IRUGO, ina209_show_alarm, NULL,
401
- 1 << 7);
386
+static SENSOR_DEVICE_ATTR_RO(in0_min_alarm, ina209_alarm, 1 << 11);
387
+static SENSOR_DEVICE_ATTR_RO(in0_max_alarm, ina209_alarm, 1 << 12);
388
+static SENSOR_DEVICE_ATTR_RO(in0_crit_min_alarm, ina209_alarm, 1 << 6);
389
+static SENSOR_DEVICE_ATTR_RO(in0_crit_max_alarm, ina209_alarm, 1 << 7);
402390
403391 /* Bus voltage, history, limits, alarms */
404
-static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, ina209_show_value, NULL,
405
- INA209_BUS_VOLTAGE);
406
-static SENSOR_DEVICE_ATTR(in1_input_highest, S_IRUGO, ina209_show_value, NULL,
407
- INA209_BUS_VOLTAGE_MAX_PEAK);
408
-static SENSOR_DEVICE_ATTR(in1_input_lowest, S_IRUGO, ina209_show_value, NULL,
409
- INA209_BUS_VOLTAGE_MIN_PEAK);
410
-static SENSOR_DEVICE_ATTR(in1_reset_history, S_IWUSR, NULL,
411
- ina209_reset_history, (1 << 2) | (1 << 3));
412
-static SENSOR_DEVICE_ATTR(in1_max, S_IRUGO | S_IWUSR, ina209_show_value,
413
- ina209_set_value, INA209_BUS_VOLTAGE_OVER_WARN);
414
-static SENSOR_DEVICE_ATTR(in1_min, S_IRUGO | S_IWUSR, ina209_show_value,
415
- ina209_set_value, INA209_BUS_VOLTAGE_UNDER_WARN);
416
-static SENSOR_DEVICE_ATTR(in1_crit_max, S_IRUGO | S_IWUSR, ina209_show_value,
417
- ina209_set_value, INA209_BUS_VOLTAGE_OVER_LIMIT);
418
-static SENSOR_DEVICE_ATTR(in1_crit_min, S_IRUGO | S_IWUSR, ina209_show_value,
419
- ina209_set_value, INA209_BUS_VOLTAGE_UNDER_LIMIT);
392
+static SENSOR_DEVICE_ATTR_RO(in1_input, ina209_value, INA209_BUS_VOLTAGE);
393
+static SENSOR_DEVICE_ATTR_RO(in1_input_highest, ina209_value,
394
+ INA209_BUS_VOLTAGE_MAX_PEAK);
395
+static SENSOR_DEVICE_ATTR_RO(in1_input_lowest, ina209_value,
396
+ INA209_BUS_VOLTAGE_MIN_PEAK);
397
+static SENSOR_DEVICE_ATTR_WO(in1_reset_history, ina209_history,
398
+ (1 << 2) | (1 << 3));
399
+static SENSOR_DEVICE_ATTR_RW(in1_max, ina209_value,
400
+ INA209_BUS_VOLTAGE_OVER_WARN);
401
+static SENSOR_DEVICE_ATTR_RW(in1_min, ina209_value,
402
+ INA209_BUS_VOLTAGE_UNDER_WARN);
403
+static SENSOR_DEVICE_ATTR_RW(in1_crit_max, ina209_value,
404
+ INA209_BUS_VOLTAGE_OVER_LIMIT);
405
+static SENSOR_DEVICE_ATTR_RW(in1_crit_min, ina209_value,
406
+ INA209_BUS_VOLTAGE_UNDER_LIMIT);
420407
421
-static SENSOR_DEVICE_ATTR(in1_min_alarm, S_IRUGO, ina209_show_alarm, NULL,
422
- 1 << 14);
423
-static SENSOR_DEVICE_ATTR(in1_max_alarm, S_IRUGO, ina209_show_alarm, NULL,
424
- 1 << 15);
425
-static SENSOR_DEVICE_ATTR(in1_crit_min_alarm, S_IRUGO, ina209_show_alarm, NULL,
426
- 1 << 9);
427
-static SENSOR_DEVICE_ATTR(in1_crit_max_alarm, S_IRUGO, ina209_show_alarm, NULL,
428
- 1 << 10);
408
+static SENSOR_DEVICE_ATTR_RO(in1_min_alarm, ina209_alarm, 1 << 14);
409
+static SENSOR_DEVICE_ATTR_RO(in1_max_alarm, ina209_alarm, 1 << 15);
410
+static SENSOR_DEVICE_ATTR_RO(in1_crit_min_alarm, ina209_alarm, 1 << 9);
411
+static SENSOR_DEVICE_ATTR_RO(in1_crit_max_alarm, ina209_alarm, 1 << 10);
429412
430413 /* Power */
431
-static SENSOR_DEVICE_ATTR(power1_input, S_IRUGO, ina209_show_value, NULL,
432
- INA209_POWER);
433
-static SENSOR_DEVICE_ATTR(power1_input_highest, S_IRUGO, ina209_show_value,
434
- NULL, INA209_POWER_PEAK);
435
-static SENSOR_DEVICE_ATTR(power1_reset_history, S_IWUSR, NULL,
436
- ina209_reset_history, 1 << 4);
437
-static SENSOR_DEVICE_ATTR(power1_max, S_IRUGO | S_IWUSR, ina209_show_value,
438
- ina209_set_value, INA209_POWER_WARN);
439
-static SENSOR_DEVICE_ATTR(power1_crit, S_IRUGO | S_IWUSR, ina209_show_value,
440
- ina209_set_value, INA209_POWER_OVER_LIMIT);
414
+static SENSOR_DEVICE_ATTR_RO(power1_input, ina209_value, INA209_POWER);
415
+static SENSOR_DEVICE_ATTR_RO(power1_input_highest, ina209_value,
416
+ INA209_POWER_PEAK);
417
+static SENSOR_DEVICE_ATTR_WO(power1_reset_history, ina209_history, 1 << 4);
418
+static SENSOR_DEVICE_ATTR_RW(power1_max, ina209_value, INA209_POWER_WARN);
419
+static SENSOR_DEVICE_ATTR_RW(power1_crit, ina209_value,
420
+ INA209_POWER_OVER_LIMIT);
441421
442
-static SENSOR_DEVICE_ATTR(power1_max_alarm, S_IRUGO, ina209_show_alarm, NULL,
443
- 1 << 13);
444
-static SENSOR_DEVICE_ATTR(power1_crit_alarm, S_IRUGO, ina209_show_alarm, NULL,
445
- 1 << 8);
422
+static SENSOR_DEVICE_ATTR_RO(power1_max_alarm, ina209_alarm, 1 << 13);
423
+static SENSOR_DEVICE_ATTR_RO(power1_crit_alarm, ina209_alarm, 1 << 8);
446424
447425 /* Current */
448
-static SENSOR_DEVICE_ATTR(curr1_input, S_IRUGO, ina209_show_value, NULL,
449
- INA209_CURRENT);
426
+static SENSOR_DEVICE_ATTR_RO(curr1_input, ina209_value, INA209_CURRENT);
450427
451
-static SENSOR_DEVICE_ATTR(update_interval, S_IRUGO | S_IWUSR,
452
- ina209_show_interval, ina209_set_interval, 0);
428
+static SENSOR_DEVICE_ATTR_RW(update_interval, ina209_interval, 0);
453429
454430 /*
455431 * Finally, construct an array of pointers to members of the above objects,
....@@ -555,8 +531,7 @@
555531 return 0;
556532 }
557533
558
-static int ina209_probe(struct i2c_client *client,
559
- const struct i2c_device_id *id)
534
+static int ina209_probe(struct i2c_client *client)
560535 {
561536 struct i2c_adapter *adapter = client->adapter;
562537 struct ina209_data *data;
....@@ -608,7 +583,7 @@
608583 };
609584 MODULE_DEVICE_TABLE(i2c, ina209_id);
610585
611
-static const struct of_device_id ina209_of_match[] = {
586
+static const struct of_device_id __maybe_unused ina209_of_match[] = {
612587 { .compatible = "ti,ina209" },
613588 { },
614589 };
....@@ -621,7 +596,7 @@
621596 .name = "ina209",
622597 .of_match_table = of_match_ptr(ina209_of_match),
623598 },
624
- .probe = ina209_probe,
599
+ .probe_new = ina209_probe,
625600 .remove = ina209_remove,
626601 .id_table = ina209_id,
627602 };