blob: c36febe7ce7d1e1b4e1b65d53264772e183a7aeb [file] [log] [blame]
Manish Ahuja5d30bf32007-02-08 16:01:17 -06001/*
2 * Interface for power-management for ppc64 compliant platform
3 *
4 * Manish Ahuja <mahuja@us.ibm.com>
5 *
6 * Feb 2007
7 *
8 * Copyright (C) 2007 IBM Corporation.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; version 2 of the License.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */
23
24#include <linux/kobject.h>
25#include <linux/string.h>
26#include <linux/errno.h>
27#include <linux/init.h>
28
29unsigned long rtas_poweron_auto; /* default and normal state is 0 */
30
Greg Kroah-Hartman823bccf2007-04-13 13:15:19 -070031static ssize_t auto_poweron_show(struct kset *kset, char *buf)
Manish Ahuja5d30bf32007-02-08 16:01:17 -060032{
33 return sprintf(buf, "%lu\n", rtas_poweron_auto);
34}
35
36static ssize_t
Greg Kroah-Hartman823bccf2007-04-13 13:15:19 -070037auto_poweron_store(struct kset *kset, const char *buf, size_t n)
Manish Ahuja5d30bf32007-02-08 16:01:17 -060038{
39 int ret;
40 unsigned long ups_restart;
41 ret = sscanf(buf, "%lu", &ups_restart);
42
43 if ((ret == 1) && ((ups_restart == 1) || (ups_restart == 0))){
44 rtas_poweron_auto = ups_restart;
45 return n;
46 }
47 return -EINVAL;
48}
49
50static struct subsys_attribute auto_poweron_attr = {
51 .attr = {
52 .name = __stringify(auto_poweron),
53 .mode = 0644,
54 },
55 .show = auto_poweron_show,
56 .store = auto_poweron_store,
57};
58
59#ifndef CONFIG_PM
Greg Kroah-Hartman039a5dc2007-11-01 10:39:50 -070060struct kset *power_kset;
Manish Ahuja5d30bf32007-02-08 16:01:17 -060061
62static struct attribute *g[] = {
63 &auto_poweron_attr.attr,
64 NULL,
65};
66
67static struct attribute_group attr_group = {
68 .attrs = g,
69};
70
71static int __init pm_init(void)
72{
Greg Kroah-Hartman039a5dc2007-11-01 10:39:50 -070073 power_kset = kset_create_and_add("power", NULL, NULL);
74 if (!power_kset)
75 return -ENOMEM;
76 return sysfs_create_group(&power_kset->kobj, &attr_group);
Manish Ahuja5d30bf32007-02-08 16:01:17 -060077}
78core_initcall(pm_init);
79#else
Manish Ahuja5d30bf32007-02-08 16:01:17 -060080static int __init apo_pm_init(void)
81{
Greg Kroah-Hartman039a5dc2007-11-01 10:39:50 -070082 return (subsys_create_file(power_kset, &auto_poweron_attr));
Manish Ahuja5d30bf32007-02-08 16:01:17 -060083}
84__initcall(apo_pm_init);
85#endif