Manish Ahuja | 5d30bf3 | 2007-02-08 16:01:17 -0600 | [diff] [blame] | 1 | /* |
| 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> |
Michael Ellerman | 8e83e90 | 2014-07-16 12:02:43 +1000 | [diff] [blame] | 28 | #include <asm/machdep.h> |
Manish Ahuja | 5d30bf3 | 2007-02-08 16:01:17 -0600 | [diff] [blame] | 29 | |
Daniel Axtens | 665e87f | 2016-05-18 11:16:51 +1000 | [diff] [blame] | 30 | #include "pseries.h" |
| 31 | |
Manish Ahuja | 5d30bf3 | 2007-02-08 16:01:17 -0600 | [diff] [blame] | 32 | unsigned long rtas_poweron_auto; /* default and normal state is 0 */ |
| 33 | |
Greg Kroah-Hartman | 79393fc | 2007-11-02 13:20:40 -0700 | [diff] [blame] | 34 | static ssize_t auto_poweron_show(struct kobject *kobj, |
| 35 | struct kobj_attribute *attr, char *buf) |
Manish Ahuja | 5d30bf3 | 2007-02-08 16:01:17 -0600 | [diff] [blame] | 36 | { |
| 37 | return sprintf(buf, "%lu\n", rtas_poweron_auto); |
| 38 | } |
| 39 | |
Greg Kroah-Hartman | 79393fc | 2007-11-02 13:20:40 -0700 | [diff] [blame] | 40 | static ssize_t auto_poweron_store(struct kobject *kobj, |
| 41 | struct kobj_attribute *attr, |
| 42 | const char *buf, size_t n) |
Manish Ahuja | 5d30bf3 | 2007-02-08 16:01:17 -0600 | [diff] [blame] | 43 | { |
| 44 | int ret; |
| 45 | unsigned long ups_restart; |
| 46 | ret = sscanf(buf, "%lu", &ups_restart); |
| 47 | |
| 48 | if ((ret == 1) && ((ups_restart == 1) || (ups_restart == 0))){ |
| 49 | rtas_poweron_auto = ups_restart; |
| 50 | return n; |
| 51 | } |
| 52 | return -EINVAL; |
| 53 | } |
| 54 | |
Greg Kroah-Hartman | 79393fc | 2007-11-02 13:20:40 -0700 | [diff] [blame] | 55 | static struct kobj_attribute auto_poweron_attr = |
| 56 | __ATTR(auto_poweron, 0644, auto_poweron_show, auto_poweron_store); |
Manish Ahuja | 5d30bf3 | 2007-02-08 16:01:17 -0600 | [diff] [blame] | 57 | |
| 58 | #ifndef CONFIG_PM |
Greg Kroah-Hartman | d76e15f | 2007-11-27 11:28:26 -0800 | [diff] [blame] | 59 | struct kobject *power_kobj; |
Manish Ahuja | 5d30bf3 | 2007-02-08 16:01:17 -0600 | [diff] [blame] | 60 | |
| 61 | static struct attribute *g[] = { |
| 62 | &auto_poweron_attr.attr, |
| 63 | NULL, |
| 64 | }; |
| 65 | |
| 66 | static struct attribute_group attr_group = { |
| 67 | .attrs = g, |
| 68 | }; |
| 69 | |
| 70 | static int __init pm_init(void) |
| 71 | { |
Greg Kroah-Hartman | d76e15f | 2007-11-27 11:28:26 -0800 | [diff] [blame] | 72 | power_kobj = kobject_create_and_add("power", NULL); |
| 73 | if (!power_kobj) |
Greg Kroah-Hartman | 039a5dc | 2007-11-01 10:39:50 -0700 | [diff] [blame] | 74 | return -ENOMEM; |
Greg Kroah-Hartman | d76e15f | 2007-11-27 11:28:26 -0800 | [diff] [blame] | 75 | return sysfs_create_group(power_kobj, &attr_group); |
Manish Ahuja | 5d30bf3 | 2007-02-08 16:01:17 -0600 | [diff] [blame] | 76 | } |
Michael Ellerman | 8e83e90 | 2014-07-16 12:02:43 +1000 | [diff] [blame] | 77 | machine_core_initcall(pseries, pm_init); |
Manish Ahuja | 5d30bf3 | 2007-02-08 16:01:17 -0600 | [diff] [blame] | 78 | #else |
Manish Ahuja | 5d30bf3 | 2007-02-08 16:01:17 -0600 | [diff] [blame] | 79 | static int __init apo_pm_init(void) |
| 80 | { |
Stephen Rothwell | 3d5d27c | 2008-02-20 11:27:04 +1100 | [diff] [blame] | 81 | return (sysfs_create_file(power_kobj, &auto_poweron_attr.attr)); |
Manish Ahuja | 5d30bf3 | 2007-02-08 16:01:17 -0600 | [diff] [blame] | 82 | } |
Michael Ellerman | 8e83e90 | 2014-07-16 12:02:43 +1000 | [diff] [blame] | 83 | machine_device_initcall(pseries, apo_pm_init); |
Manish Ahuja | 5d30bf3 | 2007-02-08 16:01:17 -0600 | [diff] [blame] | 84 | #endif |