Skip to content

Commit ad175de

Browse files
Wer-Wolfsre
authored andcommitted
power: supply: hwmon: Add support for power sensors
Currently, more than seven power supply drivers are supporting POWER_SUPPLY_PROP_POWER_NOW, but their power readings are not being reported through the hwmon subsystem. Fix this by adding support for power sensors to the power supply hwmon integration. Signed-off-by: Armin Wolf <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sebastian Reichel <[email protected]>
1 parent a5dd84f commit ad175de

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

drivers/power/supply/power_supply_hwmon.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,18 @@ static int power_supply_hwmon_curr_to_property(u32 attr)
4848
}
4949
}
5050

51+
static int power_supply_hwmon_power_to_property(u32 attr)
52+
{
53+
switch (attr) {
54+
case hwmon_power_input:
55+
return POWER_SUPPLY_PROP_POWER_NOW;
56+
case hwmon_power_average:
57+
return POWER_SUPPLY_PROP_POWER_AVG;
58+
default:
59+
return -EINVAL;
60+
}
61+
}
62+
5163
static int power_supply_hwmon_temp_to_property(u32 attr, int channel)
5264
{
5365
if (channel) {
@@ -90,6 +102,8 @@ power_supply_hwmon_to_property(enum hwmon_sensor_types type,
90102
return power_supply_hwmon_in_to_property(attr);
91103
case hwmon_curr:
92104
return power_supply_hwmon_curr_to_property(attr);
105+
case hwmon_power:
106+
return power_supply_hwmon_power_to_property(attr);
93107
case hwmon_temp:
94108
return power_supply_hwmon_temp_to_property(attr, channel);
95109
default:
@@ -229,6 +243,11 @@ power_supply_hwmon_read(struct device *dev, enum hwmon_sensor_types type,
229243
case hwmon_in:
230244
pspval.intval = DIV_ROUND_CLOSEST(pspval.intval, 1000);
231245
break;
246+
case hwmon_power:
247+
/*
248+
* Power properties are already in microwatts.
249+
*/
250+
break;
232251
/*
233252
* Temp needs to be converted from 1/10 C to milli-C
234253
*/
@@ -311,6 +330,10 @@ static const struct hwmon_channel_info * const power_supply_hwmon_info[] = {
311330
HWMON_C_MAX |
312331
HWMON_C_INPUT),
313332

333+
HWMON_CHANNEL_INFO(power,
334+
HWMON_P_INPUT |
335+
HWMON_P_AVERAGE),
336+
314337
HWMON_CHANNEL_INFO(in,
315338
HWMON_I_AVERAGE |
316339
HWMON_I_MIN |
@@ -359,6 +382,8 @@ int power_supply_add_hwmon_sysfs(struct power_supply *psy)
359382
case POWER_SUPPLY_PROP_CURRENT_AVG:
360383
case POWER_SUPPLY_PROP_CURRENT_MAX:
361384
case POWER_SUPPLY_PROP_CURRENT_NOW:
385+
case POWER_SUPPLY_PROP_POWER_AVG:
386+
case POWER_SUPPLY_PROP_POWER_NOW:
362387
case POWER_SUPPLY_PROP_TEMP:
363388
case POWER_SUPPLY_PROP_TEMP_MAX:
364389
case POWER_SUPPLY_PROP_TEMP_MIN:

0 commit comments

Comments
 (0)