[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <6c161ffb-93bb-44f5-a47d-b93561da7cb4@redhat.com>
Date: Wed, 4 Sep 2024 21:57:08 +0200
From: Hans de Goede <hdegoede@...hat.com>
To: Thomas Weißschuh <linux@...ssschuh.net>,
Sebastian Reichel <sre@...nel.org>, Armin Wolf <W_Armin@....de>
Cc: linux-pm@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH RFC v3 3/9] power: supply: hwmon: register battery
properties
Hi,
On 9/4/24 9:25 PM, Thomas Weißschuh wrote:
> Instead of only registering properties from the psy_desc itself,
> also register the ones from the battery.
> Use power_supply_has_property() for this test which makes the logic also
> easier to read.
>
> Signed-off-by: Thomas Weißschuh <linux@...ssschuh.net>
Thanks, patch looks good to me:
Reviewed-by: Hans de Goede <hdegoede@...hat.com>
Regards,
Hans
> ---
> drivers/power/supply/power_supply_hwmon.c | 52 +++++++++++++++----------------
> 1 file changed, 26 insertions(+), 26 deletions(-)
>
> diff --git a/drivers/power/supply/power_supply_hwmon.c b/drivers/power/supply/power_supply_hwmon.c
> index baacefbdf768..1c1ad3e1d81f 100644
> --- a/drivers/power/supply/power_supply_hwmon.c
> +++ b/drivers/power/supply/power_supply_hwmon.c
> @@ -8,6 +8,8 @@
> #include <linux/power_supply.h>
> #include <linux/slab.h>
>
> +#include "power_supply.h"
> +
> struct power_supply_hwmon {
> struct power_supply *psy;
> unsigned long *props;
> @@ -347,9 +349,28 @@ static const struct hwmon_chip_info power_supply_hwmon_chip_info = {
> .info = power_supply_hwmon_info,
> };
>
> +static const enum power_supply_property power_supply_hwmon_props[] = {
> + POWER_SUPPLY_PROP_CURRENT_AVG,
> + POWER_SUPPLY_PROP_CURRENT_MAX,
> + POWER_SUPPLY_PROP_CURRENT_NOW,
> + POWER_SUPPLY_PROP_POWER_AVG,
> + POWER_SUPPLY_PROP_POWER_NOW,
> + POWER_SUPPLY_PROP_TEMP,
> + POWER_SUPPLY_PROP_TEMP_MAX,
> + POWER_SUPPLY_PROP_TEMP_MIN,
> + POWER_SUPPLY_PROP_TEMP_ALERT_MIN,
> + POWER_SUPPLY_PROP_TEMP_ALERT_MAX,
> + POWER_SUPPLY_PROP_TEMP_AMBIENT,
> + POWER_SUPPLY_PROP_TEMP_AMBIENT_ALERT_MIN,
> + POWER_SUPPLY_PROP_TEMP_AMBIENT_ALERT_MAX,
> + POWER_SUPPLY_PROP_VOLTAGE_AVG,
> + POWER_SUPPLY_PROP_VOLTAGE_MIN,
> + POWER_SUPPLY_PROP_VOLTAGE_MAX,
> + POWER_SUPPLY_PROP_VOLTAGE_NOW,
> +};
> +
> int power_supply_add_hwmon_sysfs(struct power_supply *psy)
> {
> - const struct power_supply_desc *desc = psy->desc;
> struct power_supply_hwmon *psyhw;
> struct device *dev = &psy->dev;
> struct device *hwmon;
> @@ -375,32 +396,11 @@ int power_supply_add_hwmon_sysfs(struct power_supply *psy)
> goto error;
> }
>
> - for (i = 0; i < desc->num_properties; i++) {
> - const enum power_supply_property prop = desc->properties[i];
> -
> - switch (prop) {
> - 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:
> - case POWER_SUPPLY_PROP_TEMP_ALERT_MIN:
> - case POWER_SUPPLY_PROP_TEMP_ALERT_MAX:
> - case POWER_SUPPLY_PROP_TEMP_AMBIENT:
> - case POWER_SUPPLY_PROP_TEMP_AMBIENT_ALERT_MIN:
> - case POWER_SUPPLY_PROP_TEMP_AMBIENT_ALERT_MAX:
> - case POWER_SUPPLY_PROP_VOLTAGE_AVG:
> - case POWER_SUPPLY_PROP_VOLTAGE_MIN:
> - case POWER_SUPPLY_PROP_VOLTAGE_MAX:
> - case POWER_SUPPLY_PROP_VOLTAGE_NOW:
> + for (i = 0; i < ARRAY_SIZE(power_supply_hwmon_props); i++) {
> + const enum power_supply_property prop = power_supply_hwmon_props[i];
> +
> + if (power_supply_has_property(psy, prop))
> set_bit(prop, psyhw->props);
> - break;
> - default:
> - break;
> - }
> }
>
> name = psy->desc->name;
>
Powered by blists - more mailing lists