From fcab304b5df5bf6188d9addc340d78f1a153ea2d Mon Sep 17 00:00:00 2001 From: Patrick Mochel Date: Thu, 14 Aug 2003 05:31:17 -0700 Subject: [PATCH] [power] Register PM subsystem, and create power/ directory in sysfs. - Add file 'state' which provides single point of entry for all PM transitions. File accepts a string specifying what state to enter, which is one of: "standby": Power-on Suspend (aka S1) "suspend": Suspend-to-RAM (aka S3) "hibernate": Suspend-to-disk (aka S4) The names do suck, because they are lifted from the ACPI spec. Better naming suggestions are welcome, though these names are relatively well- known. - Handler for file does little now, but will validate the passed string and call the appropriate functions. - Needs to be integrated with swsusp and ACPI S3 code. --- kernel/power/Makefile | 2 +- kernel/power/main.c | 129 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 130 insertions(+), 1 deletion(-) create mode 100644 kernel/power/main.c diff --git a/kernel/power/Makefile b/kernel/power/Makefile index 3a11202cc91eb..9640751c43385 100644 --- a/kernel/power/Makefile +++ b/kernel/power/Makefile @@ -1,4 +1,4 @@ -obj-y := process.o console.o pm.o +obj-y := main.o process.o console.o pm.o obj-$(CONFIG_SOFTWARE_SUSPEND) += swsusp.o obj-$(CONFIG_MAGIC_SYSRQ) += poweroff.o diff --git a/kernel/power/main.c b/kernel/power/main.c new file mode 100644 index 0000000000000..6039369648151 --- /dev/null +++ b/kernel/power/main.c @@ -0,0 +1,129 @@ +/* + * kernel/power/main.c - PM subsystem core functionality. + * + * Copyright (c) 2003 Patrick Mochel + * Copyright (c) 2003 Open Source Development Lab + * + * This file is release under the GPLv2 + * + */ + +#include +#include +#include +#include +#include + + + +static int standby(void) +{ + return 0; +} + +static int suspend(void) +{ + return 0; +} + +static int hibernate(void) +{ + return 0; +} + +#define decl_state(_name) \ + { .name = __stringify(_name), .fn = _name } + +struct pm_state { + char * name; + int (*fn)(void); +} pm_states[] = { + decl_state(standby), + decl_state(suspend), + decl_state(hibernate), + { NULL }, +}; + + +static int enter_state(struct pm_state * state) +{ + return state->fn(); +} + + + +decl_subsys(power,NULL,NULL); + + +#define power_attr(_name) \ +static struct subsys_attribute _name##_attr = { \ + .attr = { \ + .name = __stringify(_name), \ + .mode = 0644, \ + }, \ + .show = _name##_show, \ + .store = _name##_store, \ +} + +/** + * state - control system power state. + * + * show() returns what states are supported, which is hard-coded to + * 'standby' (Power-On Suspend), 'suspend' (Suspend-to-RAM), and + * 'hibernate' (Suspend-to-Disk). + * + * store() accepts one of those strings, translates it into the + * proper enumerated value, and initiates a suspend transition. + */ + +static ssize_t state_show(struct subsystem * subsys, char * buf) +{ + struct pm_state * state; + char * s = buf; + + for (state = &pm_states[0]; state->name; state++) + s += sprintf(s,"%s ",state->name); + s += sprintf(s,"\n"); + return (s - buf); +} + +static ssize_t state_store(struct subsystem * s, const char * buf, size_t n) +{ + struct pm_state * state; + int error; + char * end = strchr(buf,'\n'); + + if (end) + *end = '\0'; + + for (state = &pm_states[0]; state; state++) { + if (!strcmp(buf,state->name)) + break; + } + if (!state) + return -EINVAL; + error = enter_state(state); + return error ? error : n; +} + +power_attr(state); + +static struct attribute * g[] = { + &state_attr.attr, + NULL, +}; + +static struct attribute_group attr_group = { + .attrs = g, +}; + + +static int pm_init(void) +{ + int error = subsystem_register(&power_subsys); + if (!error) + error = sysfs_create_group(&power_subsys.kset.kobj,&attr_group); + return error; +} + +core_initcall(pm_init); -- 2.53.0