Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

hwmon: (ltc4282) Use the energy64 attribute type to report the energy

Use the energy64 attribute type instead of a locally defined sysfs
attribute to report the accumulated energy.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Reviewed-by: Nuno Sá <nuno.sa@analog.com>
Link: https://lore.kernel.org/r/20251012211625.533791-2-linux@roeck-us.net
Signed-off-by: Guenter Roeck <linux@roeck-us.net>

+13 -31
+13 -31
drivers/hwmon/ltc4282.c
··· 12 12 #include <linux/delay.h> 13 13 #include <linux/device.h> 14 14 #include <linux/hwmon.h> 15 - #include <linux/hwmon-sysfs.h> 16 15 #include <linux/i2c.h> 17 16 #include <linux/math.h> 18 17 #include <linux/minmax.h> ··· 540 541 return 0; 541 542 } 542 543 543 - static int ltc4282_read_energy(const struct ltc4282_state *st, u64 *val) 544 + static int ltc4282_read_energy(const struct ltc4282_state *st, s64 *val) 544 545 { 545 546 u64 temp, energy; 546 547 __be64 raw; ··· 616 617 *val = st->energy_en; 617 618 } 618 619 return 0; 620 + case hwmon_energy64: 621 + scoped_guard(mutex, &st->lock) { 622 + if (st->energy_en) 623 + return ltc4282_read_energy(st, (s64 *)val); 624 + } 625 + return -ENODATA; 619 626 default: 620 627 return -EOPNOTSUPP; 621 628 } ··· 1083 1078 case hwmon_energy: 1084 1079 /* hwmon_energy_enable */ 1085 1080 return 0644; 1081 + case hwmon_energy64: 1082 + /* hwmon_energy_input */ 1083 + return 0444; 1086 1084 default: 1087 1085 return 0; 1088 1086 } ··· 1112 1104 default: 1113 1105 return -EOPNOTSUPP; 1114 1106 } 1115 - } 1116 - 1117 - static ssize_t ltc4282_energy_show(struct device *dev, 1118 - struct device_attribute *da, char *buf) 1119 - { 1120 - struct ltc4282_state *st = dev_get_drvdata(dev); 1121 - u64 energy; 1122 - int ret; 1123 - 1124 - guard(mutex)(&st->lock); 1125 - if (!st->energy_en) 1126 - return -ENODATA; 1127 - 1128 - ret = ltc4282_read_energy(st, &energy); 1129 - if (ret < 0) 1130 - return ret; 1131 - 1132 - return sysfs_emit(buf, "%llu\n", energy); 1133 1107 } 1134 1108 1135 1109 static const struct clk_ops ltc4282_ops = { ··· 1578 1588 HWMON_P_RESET_HISTORY | HWMON_P_LABEL), 1579 1589 HWMON_CHANNEL_INFO(energy, 1580 1590 HWMON_E_ENABLE), 1591 + HWMON_CHANNEL_INFO(energy64, 1592 + HWMON_E_INPUT), 1581 1593 NULL 1582 1594 }; 1583 1595 ··· 1594 1602 .ops = &ltc4282_hwmon_ops, 1595 1603 .info = ltc4282_info, 1596 1604 }; 1597 - 1598 - /* energy attributes are 6bytes wide so we need u64 */ 1599 - static SENSOR_DEVICE_ATTR_RO(energy1_input, ltc4282_energy, 0); 1600 - 1601 - static struct attribute *ltc4282_attrs[] = { 1602 - &sensor_dev_attr_energy1_input.dev_attr.attr, 1603 - NULL 1604 - }; 1605 - ATTRIBUTE_GROUPS(ltc4282); 1606 1605 1607 1606 static int ltc4282_show_fault_log(void *arg, u64 *val, u32 mask) 1608 1607 { ··· 1701 1718 1702 1719 mutex_init(&st->lock); 1703 1720 hwmon = devm_hwmon_device_register_with_info(dev, "ltc4282", st, 1704 - &ltc4282_chip_info, 1705 - ltc4282_groups); 1721 + &ltc4282_chip_info, NULL); 1706 1722 if (IS_ERR(hwmon)) 1707 1723 return PTR_ERR(hwmon); 1708 1724