diff options
| author | Guenter Roeck <linux@roeck-us.net> | 2025-10-12 14:16:25 -0700 |
|---|---|---|
| committer | Guenter Roeck <linux@roeck-us.net> | 2025-10-15 11:02:42 -0700 |
| commit | 9d501496f094c71a1630e4d72dedbb5fa98bca0d (patch) | |
| tree | f3839cad30be1e839d4ca069c577227c573ce2f4 /drivers | |
| parent | 2272f61d7241f8dd8c44d5c25ef5e67e61062111 (diff) | |
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>
Diffstat (limited to 'drivers')
| -rw-r--r-- | drivers/hwmon/ltc4282.c | 44 |
1 files changed, 13 insertions, 31 deletions
diff --git a/drivers/hwmon/ltc4282.c b/drivers/hwmon/ltc4282.c index 1d664a2d7b3c..44102879694a 100644 --- a/drivers/hwmon/ltc4282.c +++ b/drivers/hwmon/ltc4282.c @@ -12,7 +12,6 @@ #include <linux/delay.h> #include <linux/device.h> #include <linux/hwmon.h> -#include <linux/hwmon-sysfs.h> #include <linux/i2c.h> #include <linux/math.h> #include <linux/minmax.h> @@ -541,7 +540,7 @@ static int ltc4282_read_power_byte(const struct ltc4282_state *st, u32 reg, return 0; } -static int ltc4282_read_energy(const struct ltc4282_state *st, u64 *val) +static int ltc4282_read_energy(const struct ltc4282_state *st, s64 *val) { u64 temp, energy; __be64 raw; @@ -617,6 +616,12 @@ static int ltc4282_read(struct device *dev, enum hwmon_sensor_types type, *val = st->energy_en; } return 0; + case hwmon_energy64: + scoped_guard(mutex, &st->lock) { + if (st->energy_en) + return ltc4282_read_energy(st, (s64 *)val); + } + return -ENODATA; default: return -EOPNOTSUPP; } @@ -1078,6 +1083,9 @@ static umode_t ltc4282_is_visible(const void *data, case hwmon_energy: /* hwmon_energy_enable */ return 0644; + case hwmon_energy64: + /* hwmon_energy_input */ + return 0444; default: return 0; } @@ -1106,24 +1114,6 @@ static int ltc4282_read_labels(struct device *dev, } } -static ssize_t ltc4282_energy_show(struct device *dev, - struct device_attribute *da, char *buf) -{ - struct ltc4282_state *st = dev_get_drvdata(dev); - u64 energy; - int ret; - - guard(mutex)(&st->lock); - if (!st->energy_en) - return -ENODATA; - - ret = ltc4282_read_energy(st, &energy); - if (ret < 0) - return ret; - - return sysfs_emit(buf, "%llu\n", energy); -} - static const struct clk_ops ltc4282_ops = { .recalc_rate = ltc4282_recalc_rate, .determine_rate = ltc4282_determine_rate, @@ -1588,6 +1578,8 @@ static const struct hwmon_channel_info * const ltc4282_info[] = { HWMON_P_RESET_HISTORY | HWMON_P_LABEL), HWMON_CHANNEL_INFO(energy, HWMON_E_ENABLE), + HWMON_CHANNEL_INFO(energy64, + HWMON_E_INPUT), NULL }; @@ -1603,15 +1595,6 @@ static const struct hwmon_chip_info ltc4282_chip_info = { .info = ltc4282_info, }; -/* energy attributes are 6bytes wide so we need u64 */ -static SENSOR_DEVICE_ATTR_RO(energy1_input, ltc4282_energy, 0); - -static struct attribute *ltc4282_attrs[] = { - &sensor_dev_attr_energy1_input.dev_attr.attr, - NULL -}; -ATTRIBUTE_GROUPS(ltc4282); - static int ltc4282_show_fault_log(void *arg, u64 *val, u32 mask) { struct ltc4282_state *st = arg; @@ -1718,8 +1701,7 @@ static int ltc4282_probe(struct i2c_client *i2c) mutex_init(&st->lock); hwmon = devm_hwmon_device_register_with_info(dev, "ltc4282", st, - <c4282_chip_info, - ltc4282_groups); + <c4282_chip_info, NULL); if (IS_ERR(hwmon)) return PTR_ERR(hwmon); |
