mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-08-31 23:27:20 +00:00

Add and use wrapper functions for the sysfs interaction.
Restore the compatibility of CONFIG_POWER_SUPPLY=y and CONFIG_SYSFS=n.
Reported-by: Nathan Chancellor <nathan@kernel.org>
Closes: https://lore.kernel.org/lkml/20241218195229.GA2796534@ax162/
Fixes: 288a2cabcf
("power: supply: core: add UAPI to discover currently used extensions")
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
Link: https://lore.kernel.org/r/20241219-psy-extensions-sysfs-v1-1-868fc6cb46d6@weissschuh.net
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
94 lines
2.9 KiB
C
94 lines
2.9 KiB
C
/* SPDX-License-Identifier: GPL-2.0-only */
|
|
/*
|
|
* Functions private to power supply class
|
|
*
|
|
* Copyright © 2007 Anton Vorontsov <cbou@mail.ru>
|
|
* Copyright © 2004 Szabolcs Gyurko
|
|
* Copyright © 2003 Ian Molton <spyro@f2s.com>
|
|
*
|
|
* Modified: 2004, Oct Szabolcs Gyurko
|
|
*/
|
|
|
|
#include <linux/lockdep.h>
|
|
|
|
struct device;
|
|
struct device_type;
|
|
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);
|
|
extern bool power_supply_ext_has_property(const struct power_supply_ext *ext,
|
|
enum power_supply_property psp);
|
|
|
|
struct power_supply_ext_registration {
|
|
struct list_head list_head;
|
|
const struct power_supply_ext *ext;
|
|
struct device *dev;
|
|
void *data;
|
|
};
|
|
|
|
/* Make sure that the macro is a single expression */
|
|
#define power_supply_for_each_extension(pos, psy) \
|
|
if ( ({ lockdep_assert_held(&(psy)->extensions_sem); 0; }) ) \
|
|
; \
|
|
else \
|
|
list_for_each_entry(pos, &(psy)->extensions, list_head) \
|
|
|
|
#ifdef CONFIG_SYSFS
|
|
|
|
extern void __init power_supply_init_attrs(void);
|
|
extern int power_supply_uevent(const struct device *dev, struct kobj_uevent_env *env);
|
|
extern const struct attribute_group *power_supply_attr_groups[];
|
|
extern int power_supply_sysfs_add_extension(struct power_supply *psy,
|
|
const struct power_supply_ext *ext,
|
|
struct device *dev);
|
|
extern void power_supply_sysfs_remove_extension(struct power_supply *psy,
|
|
const struct power_supply_ext *ext);
|
|
|
|
#else
|
|
|
|
static inline void power_supply_init_attrs(void) {}
|
|
#define power_supply_attr_groups NULL
|
|
#define power_supply_uevent NULL
|
|
static inline int power_supply_sysfs_add_extension(struct power_supply *psy,
|
|
const struct power_supply_ext *ext,
|
|
struct device *dev)
|
|
{ return 0; }
|
|
static inline void power_supply_sysfs_remove_extension(struct power_supply *psy,
|
|
const struct power_supply_ext *ext) {}
|
|
|
|
#endif /* CONFIG_SYSFS */
|
|
|
|
#ifdef CONFIG_LEDS_TRIGGERS
|
|
|
|
extern void power_supply_update_leds(struct power_supply *psy);
|
|
extern int power_supply_create_triggers(struct power_supply *psy);
|
|
extern void power_supply_remove_triggers(struct power_supply *psy);
|
|
|
|
#else
|
|
|
|
static inline void power_supply_update_leds(struct power_supply *psy) {}
|
|
static inline int power_supply_create_triggers(struct power_supply *psy)
|
|
{ return 0; }
|
|
static inline void power_supply_remove_triggers(struct power_supply *psy) {}
|
|
|
|
#endif /* CONFIG_LEDS_TRIGGERS */
|
|
|
|
#ifdef CONFIG_POWER_SUPPLY_HWMON
|
|
|
|
int power_supply_add_hwmon_sysfs(struct power_supply *psy);
|
|
void power_supply_remove_hwmon_sysfs(struct power_supply *psy);
|
|
|
|
#else
|
|
|
|
static inline int power_supply_add_hwmon_sysfs(struct power_supply *psy)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
static inline
|
|
void power_supply_remove_hwmon_sysfs(struct power_supply *psy) {}
|
|
|
|
#endif /* CONFIG_POWER_SUPPLY_HWMON */
|