Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  *  Interface for power-management for ppc64 compliant platform
0004  *
0005  *  Manish Ahuja <mahuja@us.ibm.com>
0006  *
0007  *  Feb 2007
0008  *
0009  *  Copyright (C) 2007 IBM Corporation.
0010  */
0011 
0012 #include <linux/kobject.h>
0013 #include <linux/string.h>
0014 #include <linux/errno.h>
0015 #include <linux/init.h>
0016 #include <asm/machdep.h>
0017 
0018 #include "pseries.h"
0019 
0020 unsigned long rtas_poweron_auto; /* default and normal state is 0 */
0021 
0022 static ssize_t auto_poweron_show(struct kobject *kobj,
0023                  struct kobj_attribute *attr, char *buf)
0024 {
0025         return sprintf(buf, "%lu\n", rtas_poweron_auto);
0026 }
0027 
0028 static ssize_t auto_poweron_store(struct kobject *kobj,
0029                   struct kobj_attribute *attr,
0030                   const char *buf, size_t n)
0031 {
0032     int ret;
0033     unsigned long ups_restart;
0034     ret = sscanf(buf, "%lu", &ups_restart);
0035 
0036     if ((ret == 1) && ((ups_restart == 1) || (ups_restart == 0))){
0037         rtas_poweron_auto = ups_restart;
0038         return n;
0039     }
0040     return -EINVAL;
0041 }
0042 
0043 static struct kobj_attribute auto_poweron_attr =
0044     __ATTR(auto_poweron, 0644, auto_poweron_show, auto_poweron_store);
0045 
0046 #ifndef CONFIG_PM
0047 struct kobject *power_kobj;
0048 
0049 static struct attribute *g[] = {
0050         &auto_poweron_attr.attr,
0051         NULL,
0052 };
0053 
0054 static const struct attribute_group attr_group = {
0055         .attrs = g,
0056 };
0057 
0058 static int __init pm_init(void)
0059 {
0060     power_kobj = kobject_create_and_add("power", NULL);
0061     if (!power_kobj)
0062         return -ENOMEM;
0063     return sysfs_create_group(power_kobj, &attr_group);
0064 }
0065 machine_core_initcall(pseries, pm_init);
0066 #else
0067 static int __init apo_pm_init(void)
0068 {
0069     return (sysfs_create_file(power_kobj, &auto_poweron_attr.attr));
0070 }
0071 machine_device_initcall(pseries, apo_pm_init);
0072 #endif