Skip to content

Commit

Permalink
power_supply: Add driver private data
Browse files Browse the repository at this point in the history
Allow drivers to store private data inside power_supply structure for
later usage in power supply operations.

Usage of driver private data is necessary to access driver's state
container object from power supply calls (like get_property()) if struct
'power_supply' is a stored there as a pointer, for example:

struct some_driver_info {
	struct i2c_client       *client;
	struct power_supply     *power_supply;
	...
}

In such case one cannot use container_of() and must store pointer to
state container as private data.

Signed-off-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
Reviewed-by: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>
Reviewed-by: Sebastian Reichel <sre@kernel.org>
Acked-by: Pavel Machek <pavel@ucw.cz>
Signed-off-by: Sebastian Reichel <sre@kernel.org>
  • Loading branch information
Krzysztof Kozlowski authored and Sebastian Reichel committed Mar 13, 2015
1 parent 1915a71 commit e44ea36
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
6 changes: 6 additions & 0 deletions drivers/power/power_supply_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,12 @@ void power_supply_unregister(struct power_supply *psy)
}
EXPORT_SYMBOL_GPL(power_supply_unregister);

void *power_supply_get_drvdata(struct power_supply *psy)
{
return psy->drv_data;
}
EXPORT_SYMBOL_GPL(power_supply_get_drvdata);

static int __init power_supply_class_init(void)
{
power_supply_class = class_create(THIS_MODULE, "power_supply");
Expand Down
4 changes: 4 additions & 0 deletions include/linux/power_supply.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,9 @@ struct power_supply {
/* For APM emulation, think legacy userspace. */
int use_for_apm;

/* Driver private data */
void *drv_data;

/* private */
struct device *dev;
struct work_struct changed_work;
Expand Down Expand Up @@ -285,6 +288,7 @@ extern int devm_power_supply_register_no_ws(struct device *parent,
extern void power_supply_unregister(struct power_supply *psy);
extern int power_supply_powers(struct power_supply *psy, struct device *dev);

extern void *power_supply_get_drvdata(struct power_supply *psy);
/* For APM emulation, think legacy userspace. */
extern struct class *power_supply_class;

Expand Down

0 comments on commit e44ea36

Please sign in to comment.