1 // SPDX-License-Identifier: GPL-2.0-only 2 /* 3 * Interface for power-management for ppc64 compliant platform 4 * 5 * Manish Ahuja <mahuja@us.ibm.com> 6 * 7 * Feb 2007 8 * 9 * Copyright (C) 2007 IBM Corporation. 10 */ 11 12 #include <linux/kobject.h> 13 #include <linux/string.h> 14 #include <linux/sysfs.h> 15 #include <linux/errno.h> 16 #include <linux/init.h> 17 #include <asm/machdep.h> 18 19 #include "pseries.h" 20 21 unsigned long rtas_poweron_auto; /* default and normal state is 0 */ 22 23 static ssize_t auto_poweron_show(struct kobject *kobj, 24 struct kobj_attribute *attr, char *buf) 25 { 26 return sysfs_emit(buf, "%lu\n", rtas_poweron_auto); 27 } 28 29 static ssize_t auto_poweron_store(struct kobject *kobj, 30 struct kobj_attribute *attr, 31 const char *buf, size_t n) 32 { 33 int ret; 34 unsigned long ups_restart; 35 ret = sscanf(buf, "%lu", &ups_restart); 36 37 if ((ret == 1) && ((ups_restart == 1) || (ups_restart == 0))){ 38 rtas_poweron_auto = ups_restart; 39 return n; 40 } 41 return -EINVAL; 42 } 43 44 static struct kobj_attribute auto_poweron_attr = 45 __ATTR(auto_poweron, 0644, auto_poweron_show, auto_poweron_store); 46 47 #ifndef CONFIG_PM 48 struct kobject *power_kobj; 49 50 static struct attribute *g[] = { 51 &auto_poweron_attr.attr, 52 NULL, 53 }; 54 55 static const struct attribute_group attr_group = { 56 .attrs = g, 57 }; 58 59 static int __init pm_init(void) 60 { 61 power_kobj = kobject_create_and_add("power", NULL); 62 if (!power_kobj) 63 return -ENOMEM; 64 return sysfs_create_group(power_kobj, &attr_group); 65 } 66 machine_core_initcall(pseries, pm_init); 67 #else 68 static int __init apo_pm_init(void) 69 { 70 return (sysfs_create_file(power_kobj, &auto_poweron_attr.attr)); 71 } 72 machine_device_initcall(pseries, apo_pm_init); 73 #endif 74