0

I need battery properties for a custom kernel module. this data is mounted in sys/class/power_supply .I know all the discussions about why one should not read/write files from kernel and a solution seems to be using VFS level functions. but I wonder how can I get this data directly from power driver? there is power_supply class with this structure:

struct power_supply {
const char *name;
enum power_supply_type type;
enum power_supply_property *properties;
size_t num_properties;

char **supplied_to;
size_t num_supplicants;

char **supplied_from;
size_t num_supplies;
#ifdef CONFIG_OF
struct device_node *of_node;
#endif

int (*get_property)(struct power_supply *psy,
            enum power_supply_property psp,
            union power_supply_propval *val);
int (*set_property)(struct power_supply *psy,
            enum power_supply_property psp,
            const union power_supply_propval *val);
int (*property_is_writeable)(struct power_supply *psy,
                 enum power_supply_property psp);
void (*external_power_changed)(struct power_supply *psy);
void (*set_charged)(struct power_supply *psy);

/* For APM emulation, think legacy userspace. */
int use_for_apm;

/* private */
struct device *dev;
struct work_struct changed_work;
spinlock_t changed_lock;
bool changed;
[...]
};

every struct chip has a instance of this struct , my question is that can I get access to chip object and get this values directly from get_property()? I also read power_supply_sysfs.c and find this line:

struct power_supply *psy = dev_get_drvdata(dev);

this line get power_supply struct and dev is argument of this function:

power_supply_show_property(struct device *dev,struct device_attribute *attr,char *buf) arguement.

well it seems that I will need a object of devise that points to battery. but how can get access to this object inside my code which is in kernel/tracing?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.