diff mbox series

power: supply: hwmon: Add support for power sensors

Message ID 20240528222115.791511-1-W_Armin@gmx.de
State Accepted
Commit ad175de1f8da6043553dec4402fc1ff28494ac7b
Headers show
Series power: supply: hwmon: Add support for power sensors | expand

Commit Message

Armin Wolf May 28, 2024, 10:21 p.m. UTC
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 <W_Armin@gmx.de>
---
 drivers/power/supply/power_supply_hwmon.c | 25 +++++++++++++++++++++++
 1 file changed, 25 insertions(+)

--
2.39.2

Comments

Armin Wolf June 4, 2024, 12:02 p.m. UTC | #1
Am 29.05.24 um 00:21 schrieb Armin Wolf:

> 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.

Hi, what is the status of this patch? Are there any obvious errors which
need to be fixed?

Thanks,
Armin Wolf

> Signed-off-by: Armin Wolf <W_Armin@gmx.de>
> ---
>   drivers/power/supply/power_supply_hwmon.c | 25 +++++++++++++++++++++++
>   1 file changed, 25 insertions(+)
>
> diff --git a/drivers/power/supply/power_supply_hwmon.c b/drivers/power/supply/power_supply_hwmon.c
> index c97893d4c25e..baacefbdf768 100644
> --- a/drivers/power/supply/power_supply_hwmon.c
> +++ b/drivers/power/supply/power_supply_hwmon.c
> @@ -48,6 +48,18 @@ static int power_supply_hwmon_curr_to_property(u32 attr)
>   	}
>   }
>
> +static int power_supply_hwmon_power_to_property(u32 attr)
> +{
> +	switch (attr) {
> +	case hwmon_power_input:
> +		return POWER_SUPPLY_PROP_POWER_NOW;
> +	case hwmon_power_average:
> +		return POWER_SUPPLY_PROP_POWER_AVG;
> +	default:
> +		return -EINVAL;
> +	}
> +}
> +
>   static int power_supply_hwmon_temp_to_property(u32 attr, int channel)
>   {
>   	if (channel) {
> @@ -90,6 +102,8 @@ power_supply_hwmon_to_property(enum hwmon_sensor_types type,
>   		return power_supply_hwmon_in_to_property(attr);
>   	case hwmon_curr:
>   		return power_supply_hwmon_curr_to_property(attr);
> +	case hwmon_power:
> +		return power_supply_hwmon_power_to_property(attr);
>   	case hwmon_temp:
>   		return power_supply_hwmon_temp_to_property(attr, channel);
>   	default:
> @@ -229,6 +243,11 @@ power_supply_hwmon_read(struct device *dev, enum hwmon_sensor_types type,
>   	case hwmon_in:
>   		pspval.intval = DIV_ROUND_CLOSEST(pspval.intval, 1000);
>   		break;
> +	case hwmon_power:
> +		/*
> +		 * Power properties are already in microwatts.
> +		 */
> +		break;
>   	/*
>   	 * Temp needs to be converted from 1/10 C to milli-C
>   	 */
> @@ -311,6 +330,10 @@ static const struct hwmon_channel_info * const power_supply_hwmon_info[] = {
>   			   HWMON_C_MAX     |
>   			   HWMON_C_INPUT),
>
> +	HWMON_CHANNEL_INFO(power,
> +			   HWMON_P_INPUT |
> +			   HWMON_P_AVERAGE),
> +
>   	HWMON_CHANNEL_INFO(in,
>   			   HWMON_I_AVERAGE |
>   			   HWMON_I_MIN     |
> @@ -359,6 +382,8 @@ int power_supply_add_hwmon_sysfs(struct power_supply *psy)
>   		case POWER_SUPPLY_PROP_CURRENT_AVG:
>   		case POWER_SUPPLY_PROP_CURRENT_MAX:
>   		case POWER_SUPPLY_PROP_CURRENT_NOW:
> +		case POWER_SUPPLY_PROP_POWER_AVG:
> +		case POWER_SUPPLY_PROP_POWER_NOW:
>   		case POWER_SUPPLY_PROP_TEMP:
>   		case POWER_SUPPLY_PROP_TEMP_MAX:
>   		case POWER_SUPPLY_PROP_TEMP_MIN:
> --
> 2.39.2
>
>
Sebastian Reichel June 5, 2024, 9:38 p.m. UTC | #2
On Wed, 29 May 2024 00:21:15 +0200, Armin Wolf wrote:
> 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.
> 
> [...]

Applied, thanks!

[1/1] power: supply: hwmon: Add support for power sensors
      commit: ad175de1f8da6043553dec4402fc1ff28494ac7b

Best regards,
diff mbox series

Patch

diff --git a/drivers/power/supply/power_supply_hwmon.c b/drivers/power/supply/power_supply_hwmon.c
index c97893d4c25e..baacefbdf768 100644
--- a/drivers/power/supply/power_supply_hwmon.c
+++ b/drivers/power/supply/power_supply_hwmon.c
@@ -48,6 +48,18 @@  static int power_supply_hwmon_curr_to_property(u32 attr)
 	}
 }

+static int power_supply_hwmon_power_to_property(u32 attr)
+{
+	switch (attr) {
+	case hwmon_power_input:
+		return POWER_SUPPLY_PROP_POWER_NOW;
+	case hwmon_power_average:
+		return POWER_SUPPLY_PROP_POWER_AVG;
+	default:
+		return -EINVAL;
+	}
+}
+
 static int power_supply_hwmon_temp_to_property(u32 attr, int channel)
 {
 	if (channel) {
@@ -90,6 +102,8 @@  power_supply_hwmon_to_property(enum hwmon_sensor_types type,
 		return power_supply_hwmon_in_to_property(attr);
 	case hwmon_curr:
 		return power_supply_hwmon_curr_to_property(attr);
+	case hwmon_power:
+		return power_supply_hwmon_power_to_property(attr);
 	case hwmon_temp:
 		return power_supply_hwmon_temp_to_property(attr, channel);
 	default:
@@ -229,6 +243,11 @@  power_supply_hwmon_read(struct device *dev, enum hwmon_sensor_types type,
 	case hwmon_in:
 		pspval.intval = DIV_ROUND_CLOSEST(pspval.intval, 1000);
 		break;
+	case hwmon_power:
+		/*
+		 * Power properties are already in microwatts.
+		 */
+		break;
 	/*
 	 * Temp needs to be converted from 1/10 C to milli-C
 	 */
@@ -311,6 +330,10 @@  static const struct hwmon_channel_info * const power_supply_hwmon_info[] = {
 			   HWMON_C_MAX     |
 			   HWMON_C_INPUT),

+	HWMON_CHANNEL_INFO(power,
+			   HWMON_P_INPUT |
+			   HWMON_P_AVERAGE),
+
 	HWMON_CHANNEL_INFO(in,
 			   HWMON_I_AVERAGE |
 			   HWMON_I_MIN     |
@@ -359,6 +382,8 @@  int power_supply_add_hwmon_sysfs(struct power_supply *psy)
 		case POWER_SUPPLY_PROP_CURRENT_AVG:
 		case POWER_SUPPLY_PROP_CURRENT_MAX:
 		case POWER_SUPPLY_PROP_CURRENT_NOW:
+		case POWER_SUPPLY_PROP_POWER_AVG:
+		case POWER_SUPPLY_PROP_POWER_NOW:
 		case POWER_SUPPLY_PROP_TEMP:
 		case POWER_SUPPLY_PROP_TEMP_MAX:
 		case POWER_SUPPLY_PROP_TEMP_MIN: