diff --git a/drivers/powerop/Kconfig b/drivers/powerop/Kconfig index 94d2459..fe5c946 100644 --- a/drivers/powerop/Kconfig +++ b/drivers/powerop/Kconfig @@ -8,5 +8,10 @@ config POWEROP bool "PowerOP Core" help +config POWEROP_SYSFS + bool " Enable PowerOP sysfs interface" + depends on POWEROP && SYSFS + help + endmenu diff --git a/drivers/powerop/Makefile b/drivers/powerop/Makefile index 131b983..1d430ce 100644 --- a/drivers/powerop/Makefile +++ b/drivers/powerop/Makefile @@ -1,2 +1,3 @@ obj-$(CONFIG_POWEROP) += powerop.o +obj-$(CONFIG_POWEROP_SYSFS) += powerop_sysfs.o diff --git a/drivers/powerop/powerop_sysfs.c b/drivers/powerop/powerop_sysfs.c new file mode 100644 index 0000000..6cfd45f --- /dev/null +++ b/drivers/powerop/powerop_sysfs.c @@ -0,0 +1,99 @@ +/* + * PowerOP sysfs UI + * + * Author: Todd Poynor + * + * 2005 (c) MontaVista Software, Inc. This file is licensed under + * the terms of the GNU General Public License version 2. This program + * is licensed "as is" without any warranty of any kind, whether express + * or implied. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +#define powerop_attr(_name) \ +static struct subsys_attribute _name##_attr = { \ + .attr = { \ + .name = __stringify(_name), \ + .mode = 0644, \ + .owner = THIS_MODULE, \ + }, \ + .show = _name##_show, \ + .store = _name##_store, \ +} + +decl_subsys(powerop, NULL, NULL); +static char active_name[32]; + +static ssize_t active_show(struct subsystem * subsys, char * buf) +{ + return sprintf(buf, "%s\n", active_name); +} + +static ssize_t active_store(struct subsystem * subsys, const char * buf, + size_t n) +{ + int error; + + error = powerop_set_point(buf); + if (error != 0) + return error; + + strcpy(active_name, buf); + return n; +} + +powerop_attr(active); + +static struct attribute * g[] = { + &active_attr.attr, + NULL, +}; + +static struct attribute_group attr_group = { + .attrs = g, +}; + +static int __init powerop_sysfs_init(void) +{ + int error; + + if ((error = subsystem_register(&powerop_subsys))) { + printk(KERN_ERR + "PowerOP SysFS subsystem_register failed.\n"); + return error; + } + + if ((error = + sysfs_create_group(&powerop_subsys.kset.kobj,&attr_group))) { + printk(KERN_ERR + "PowerOP subsys sysfs_create_group failed.\n"); + subsystem_unregister(&powerop_subsys); + return error; + } + + return 0; +} + +static void __exit powerop_sysfs_exit(void) +{ + sysfs_remove_group(&powerop_subsys.kset.kobj,&attr_group); + subsystem_unregister(&powerop_subsys); +} + +module_init(powerop_sysfs_init); +module_exit(powerop_sysfs_exit); + +MODULE_DESCRIPTION("PowerOP Power Management SysFS UI"); +MODULE_LICENSE("GPL"); +