diff --git a/ina260.c b/ina260.c index 953ef3b..8c7d0e7 100755 --- a/ina260.c +++ b/ina260.c @@ -69,7 +69,7 @@ struct client_data { static int ina260_hwmon_read(struct device *dev, enum hwmon_sensor_types type, u32 attr, int channel, long *val) { - int rvalue, reg, err; + int rvalue, reg, err, rem; struct client_data *cdata = dev_get_drvdata(dev); switch (type) { @@ -91,7 +91,7 @@ static int ina260_hwmon_read(struct device *dev, enum hwmon_sensor_types type, else if (type == hwmon_power) *val = rvalue * 10000; else - *val = div_u64(rvalue * 25, 100) + rvalue; + *val = div_u64_rem(rvalue * 25, 100, &rem) + rvalue + div_u64(rem, 10); return 0; } @@ -120,7 +120,31 @@ INA260_REG_STORE(alert_limit, INA260_REG_ALERTLIMIT) static umode_t ina260_hwmon_is_visible(const void *drvdata, enum hwmon_sensor_types type, u32 attr, int channel) { - return 0444; + switch (type) { + case hwmon_in: + switch (attr) { + case hwmon_in_input: + return 0444; + default: + return 0; + } + case hwmon_curr: + switch (attr) { + case hwmon_curr_input: + return 0444; + default: + return 0; + } + case hwmon_power: + switch (attr) { + case hwmon_power_input: + return 0444; + default: + return 0; + } + default: + return 0; + } } static const struct hwmon_channel_info *ina260_hwmon_info[] = {