Message ID | 20241111-power-supply-extensions-v4-4-7240144daa8e@weissschuh.net |
---|---|
State | New |
Headers | show |
Series | power: supply: extension API | expand |
Am 11.11.24 um 22:40 schrieb Thomas Weißschuh: > The upcoming extension API will add properties which are not part of the > the power_supply_desc. > Use power_supply_has_property() so the properties from extensions are > also chec Reviewed-by: Armin Wolf <W_Armin@gmx.de> > ked. > > Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> > Reviewed-by: Hans de Goede <hdegoede@redhat.com> > Reviewed-by: Sebastian Reichel <sebastian.reichel@collabora.com> > --- > drivers/power/supply/power_supply_hwmon.c | 50 +++++++++++++++---------------- > 1 file changed, 24 insertions(+), 26 deletions(-) > > diff --git a/drivers/power/supply/power_supply_hwmon.c b/drivers/power/supply/power_supply_hwmon.c > index 01be04903d7d2465ae2acb9eeb0b55a87868bb87..95245e6a6baa3e85ae8551e71f4f7905639a3325 100644 > --- a/drivers/power/supply/power_supply_hwmon.c > +++ b/drivers/power/supply/power_supply_hwmon.c > @@ -349,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; > @@ -377,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; >
diff --git a/drivers/power/supply/power_supply_hwmon.c b/drivers/power/supply/power_supply_hwmon.c index 01be04903d7d2465ae2acb9eeb0b55a87868bb87..95245e6a6baa3e85ae8551e71f4f7905639a3325 100644 --- a/drivers/power/supply/power_supply_hwmon.c +++ b/drivers/power/supply/power_supply_hwmon.c @@ -349,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; @@ -377,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;