Re: [PATCH 1/7] [RFC] External power framework
Hi! > External power framework - power supplies and power supplicants. > > Supplicants (batteries so far) may ask to notify they when power supply > arrive/gone. This framework used by battery class (next patches). > > It's permitted for supply to be bound to several supplicants (think main > and backup batteries). > > It's also permitted for supplicants to consume power from several > external supplies (say AC and USB). > > Here is how it look like from userspace: > > # pwd > /sys/class/power_supply > # ls > ac usb > # cat ac/online usb/online > 1 > 0 Looks nice to me. Pavel -- (english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH 1/7] [RFC] External power framework
On Thu, Apr 12, 2007 at 03:24:46AM +0400, Anton Vorontsov wrote: > External power framework - power supplies and power supplicants. > > Supplicants (batteries so far) may ask to notify they when power supply > arrive/gone. This framework used by battery class (next patches). > > It's permitted for supply to be bound to several supplicants (think main > and backup batteries). > > It's also permitted for supplicants to consume power from several > external supplies (say AC and USB). > > Here is how it look like from userspace: > > # pwd > /sys/class/power_supply > # ls > ac usb > # cat ac/online usb/online > 1 > 0 Cleaned up version based on comments from Randy Dunlap. Subject: [PATCH] [take2] External power framework Signed-off-by: Anton Vorontsov <[EMAIL PROTECTED]> --- drivers/Kconfig|2 + drivers/Makefile |1 + drivers/power/Kconfig | 13 ++ drivers/power/Makefile |1 + drivers/power/external_power.c | 326 include/linux/external_power.h | 54 +++ 6 files changed, 397 insertions(+), 0 deletions(-) create mode 100644 drivers/power/Kconfig create mode 100644 drivers/power/Makefile create mode 100644 drivers/power/external_power.c create mode 100644 include/linux/external_power.h diff --git a/drivers/Kconfig b/drivers/Kconfig index 050323f..c546de3 100644 --- a/drivers/Kconfig +++ b/drivers/Kconfig @@ -54,6 +54,8 @@ source "drivers/spi/Kconfig" source "drivers/w1/Kconfig" +source "drivers/power/Kconfig" + source "drivers/hwmon/Kconfig" source "drivers/mfd/Kconfig" diff --git a/drivers/Makefile b/drivers/Makefile index 3a718f5..2bdaae7 100644 --- a/drivers/Makefile +++ b/drivers/Makefile @@ -60,6 +60,7 @@ obj-$(CONFIG_I2O) += message/ obj-$(CONFIG_RTC_LIB) += rtc/ obj-$(CONFIG_I2C) += i2c/ obj-$(CONFIG_W1) += w1/ +obj-$(CONFIG_EXTERNAL_POWER) += power/ obj-$(CONFIG_HWMON)+= hwmon/ obj-$(CONFIG_PHONE)+= telephony/ obj-$(CONFIG_MD) += md/ diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig new file mode 100644 index 000..17349c1 --- /dev/null +++ b/drivers/power/Kconfig @@ -0,0 +1,13 @@ + +menu "External power support" + +config EXTERNAL_POWER + tristate "External power kernel interface" + help + Say Y here to enable kernel external power detection interface, + like AC or USB. Information also will exported to userspace via + /sys/class/external_power/ directory. + + This interface is mandatory for battery class support. + +endmenu diff --git a/drivers/power/Makefile b/drivers/power/Makefile new file mode 100644 index 000..c303b45 --- /dev/null +++ b/drivers/power/Makefile @@ -0,0 +1 @@ +obj-$(CONFIG_EXTERNAL_POWER) += external_power.o diff --git a/drivers/power/external_power.c b/drivers/power/external_power.c new file mode 100644 index 000..310ea4b --- /dev/null +++ b/drivers/power/external_power.c @@ -0,0 +1,326 @@ +/* + * Linux kernel interface for external power suppliers/supplicants + * + * Copyright (c) 2007 Anton Vorontsov <[EMAIL PROTECTED]> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#include +#include +#include +#include +#include + +static struct class *power_supply_class; + +static LIST_HEAD(supplicants); +static struct rw_semaphore supplicants_sem; + +struct bound_supply { + struct power_supply *psy; + struct list_head node; +}; + +struct bound_supplicant { + struct power_supplicant *pst; + struct list_head node; +}; + +int power_supplicant_am_i_supplied(struct power_supplicant *pst) +{ + int ret = 0; + struct bound_supply *bpsy; + + pr_debug("%s\n", __FUNCTION__); + down(&power_supply_class->sem); + list_for_each_entry(bpsy, &pst->bound_supplies, node) { + if (bpsy->psy->is_online(bpsy->psy)) { + ret = 1; + goto out; + } + } +out: + up(&power_supply_class->sem); + + return ret; +} + +static void unbind_pst_from_psys(struct power_supplicant *pst) +{ + struct bound_supply *bpsy, *bpsy_tmp; + struct bound_supplicant *bpst, *bpst_tmp; + + list_for_each_entry_safe(bpsy, bpsy_tmp, &pst->bound_supplies, node) { + list_for_each_entry_safe(bpst, bpst_tmp, + &bpsy->psy->bound_supplicants, node) { + if (bpst->pst == pst) { + list_del(&bpst->node); + kfree(bpst); + break; + } + } + list_del(&bpsy->node); + kfree(bpsy); + } + + retur
Re: [PATCH 1/7] [RFC] External power framework
> diff --git a/drivers/Kconfig b/drivers/Kconfig > index 050323f..c546de3 100644 I've forgot to pass -s flag to git-format-patch. :-/ Please count it for whole x/7 patch set: Signed-off-by: Anton Vorontsov <[EMAIL PROTECTED]> - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[PATCH 1/7] [RFC] External power framework
External power framework - power supplies and power supplicants. Supplicants (batteries so far) may ask to notify they when power supply arrive/gone. This framework used by battery class (next patches). It's permitted for supply to be bound to several supplicants (think main and backup batteries). It's also permitted for supplicants to consume power from several external supplies (say AC and USB). Here is how it look like from userspace: # pwd /sys/class/power_supply # ls ac usb # cat ac/online usb/online 1 0 --- drivers/Kconfig|2 + drivers/Makefile |1 + drivers/power/Kconfig | 13 ++ drivers/power/Makefile |1 + drivers/power/external_power.c | 318 include/linux/external_power.h | 54 +++ 6 files changed, 389 insertions(+), 0 deletions(-) create mode 100644 drivers/power/Kconfig create mode 100644 drivers/power/Makefile create mode 100644 drivers/power/external_power.c create mode 100644 include/linux/external_power.h diff --git a/drivers/Kconfig b/drivers/Kconfig index 050323f..c546de3 100644 --- a/drivers/Kconfig +++ b/drivers/Kconfig @@ -54,6 +54,8 @@ source "drivers/spi/Kconfig" source "drivers/w1/Kconfig" +source "drivers/power/Kconfig" + source "drivers/hwmon/Kconfig" source "drivers/mfd/Kconfig" diff --git a/drivers/Makefile b/drivers/Makefile index 3a718f5..2bdaae7 100644 --- a/drivers/Makefile +++ b/drivers/Makefile @@ -60,6 +60,7 @@ obj-$(CONFIG_I2O) += message/ obj-$(CONFIG_RTC_LIB) += rtc/ obj-$(CONFIG_I2C) += i2c/ obj-$(CONFIG_W1) += w1/ +obj-$(CONFIG_EXTERNAL_POWER) += power/ obj-$(CONFIG_HWMON)+= hwmon/ obj-$(CONFIG_PHONE)+= telephony/ obj-$(CONFIG_MD) += md/ diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig new file mode 100644 index 000..17349c1 --- /dev/null +++ b/drivers/power/Kconfig @@ -0,0 +1,13 @@ + +menu "External power support" + +config EXTERNAL_POWER + tristate "External power kernel interface" + help + Say Y here to enable kernel external power detection interface, + like AC or USB. Information also will exported to userspace via + /sys/class/external_power/ directory. + + This interface is mandatory for battery class support. + +endmenu diff --git a/drivers/power/Makefile b/drivers/power/Makefile new file mode 100644 index 000..c303b45 --- /dev/null +++ b/drivers/power/Makefile @@ -0,0 +1 @@ +obj-$(CONFIG_EXTERNAL_POWER) += external_power.o diff --git a/drivers/power/external_power.c b/drivers/power/external_power.c new file mode 100644 index 000..21c25a4 --- /dev/null +++ b/drivers/power/external_power.c @@ -0,0 +1,318 @@ +/* + * Linux kernel interface for external power suppliers/supplicants + * + * Copyright (c) 2007 Anton Vorontsov <[EMAIL PROTECTED]> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#include +#include +#include +#include +#include + +static struct class *power_supply_class; + +static LIST_HEAD(supplicants); +static struct rw_semaphore supplicants_sem; + +struct bound_supply { + struct power_supply *psy; + struct list_head node; +}; + +struct bound_supplicant { + struct power_supplicant *pst; + struct list_head node; +}; + +int power_supplicant_am_i_supplied(struct power_supplicant *pst) +{ + int ret = 0; + struct bound_supply *bpsy; + + pr_debug("%s\n", __FUNCTION__); + down(&power_supply_class->sem); + list_for_each_entry(bpsy, &pst->bound_supplies, node) { + if (bpsy->psy->is_online(bpsy->psy)) { + ret = 1; + goto out; + } + } +out: + up(&power_supply_class->sem); + + return ret; +} + +static void unbind_pst_from_psys(struct power_supplicant *pst) +{ + struct bound_supply *bpsy, *bpsy_tmp; + struct bound_supplicant *bpst, *bpst_tmp; + + list_for_each_entry_safe(bpsy, bpsy_tmp, &pst->bound_supplies, node) { + list_for_each_entry_safe(bpst, bpst_tmp, + &bpsy->psy->bound_supplicants, node) { + if (bpst->pst == pst) { + list_del(&bpst->node); + kfree(bpst); + break; + } + } + list_del(&bpsy->node); + kfree(bpsy); + } + + return; +} + +static void unbind_psy_from_psts(struct power_supply *psy) +{ + struct bound_supply *bpsy, *bpsy_tmp; + struct bound_supplicant *bpst, *bpst_tmp; + + list_for_each_entry_safe(bpst, bpst_tmp, &psy->bound_supplicants, +