power: supply: core: introduce power_supply_has_property()

Introduce a helper to check if a power supply implements a certain
property. It will be used by the sysfs and hwmon code to remove similar
open-coded checks.
It also paves the way for the extension API to hook into.

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>
Reviewed-by: Armin Wolf <W_Armin@gmx.de>
Link: https://lore.kernel.org/r/20241111-power-supply-extensions-v4-3-7240144daa8e@weissschuh.net
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
This commit is contained in:
Thomas Weißschuh 2024-11-11 22:40:05 +01:00 committed by Sebastian Reichel
parent 172f2151c2
commit aa40f37d63
2 changed files with 14 additions and 0 deletions

View File

@ -15,6 +15,8 @@ struct power_supply;
extern int power_supply_property_is_writeable(struct power_supply *psy,
enum power_supply_property psp);
extern bool power_supply_has_property(struct power_supply *psy,
enum power_supply_property psp);
#ifdef CONFIG_SYSFS

View File

@ -1196,6 +1196,18 @@ static bool psy_desc_has_property(const struct power_supply_desc *psy_desc,
return found;
}
bool power_supply_has_property(struct power_supply *psy,
enum power_supply_property psp)
{
if (psy_desc_has_property(psy->desc, psp))
return true;
if (power_supply_battery_info_has_prop(psy->battery_info, psp))
return true;
return false;
}
int power_supply_get_property(struct power_supply *psy,
enum power_supply_property psp,
union power_supply_propval *val)