1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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;
30
31static ssize_t auto_poweron_show(struct kobject *kobj,
32 struct kobj_attribute *attr, char *buf)
33{
34 return sprintf(buf, "%lu\n", rtas_poweron_auto);
35}
36
37static ssize_t auto_poweron_store(struct kobject *kobj,
38 struct kobj_attribute *attr,
39 const char *buf, size_t n)
40{
41 int ret;
42 unsigned long ups_restart;
43 ret = sscanf(buf, "%lu", &ups_restart);
44
45 if ((ret == 1) && ((ups_restart == 1) || (ups_restart == 0))){
46 rtas_poweron_auto = ups_restart;
47 return n;
48 }
49 return -EINVAL;
50}
51
52static struct kobj_attribute auto_poweron_attr =
53 __ATTR(auto_poweron, 0644, auto_poweron_show, auto_poweron_store);
54
55#ifndef CONFIG_PM
56struct kobject *power_kobj;
57
58static struct attribute *g[] = {
59 &auto_poweron_attr.attr,
60 NULL,
61};
62
63static struct attribute_group attr_group = {
64 .attrs = g,
65};
66
67static int __init pm_init(void)
68{
69 power_kobj = kobject_create_and_add("power", NULL);
70 if (!power_kobj)
71 return -ENOMEM;
72 return sysfs_create_group(power_kobj, &attr_group);
73}
74core_initcall(pm_init);
75#else
76static int __init apo_pm_init(void)
77{
78 return (sysfs_create_file(power_kobj, &auto_poweron_attr.attr));
79}
80__initcall(apo_pm_init);
81#endif
82