2 * Copyright 2013 Matthew Garrett <mjg59@srcf.ucam.org>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include <linux/init.h>
21 #include <linux/module.h>
22 #include <linux/slab.h>
23 #include <acpi/acpi_drivers.h>
25 MODULE_LICENSE("GPL");
27 static ssize_t
irst_show_wakeup_events(struct device
*dev
,
28 struct device_attribute
*attr
,
31 struct acpi_device
*acpi
;
32 struct acpi_buffer output
= { ACPI_ALLOCATE_BUFFER
, NULL
};
33 union acpi_object
*result
;
36 acpi
= to_acpi_device(dev
);
38 status
= acpi_evaluate_object(acpi
->handle
, "GFFS", NULL
, &output
);
39 if (!ACPI_SUCCESS(status
))
42 result
= output
.pointer
;
44 if (result
->type
!= ACPI_TYPE_INTEGER
) {
49 return sprintf(buf
, "%lld\n", result
->integer
.value
);
52 static ssize_t
irst_store_wakeup_events(struct device
*dev
,
53 struct device_attribute
*attr
,
54 const char *buf
, size_t count
)
56 struct acpi_device
*acpi
;
57 struct acpi_object_list input
;
58 union acpi_object param
;
63 acpi
= to_acpi_device(dev
);
65 error
= kstrtoul(buf
, 0, &value
);
70 param
.type
= ACPI_TYPE_INTEGER
;
71 param
.integer
.value
= value
;
74 input
.pointer
= ¶m
;
76 status
= acpi_evaluate_object(acpi
->handle
, "SFFS", &input
, NULL
);
78 if (!ACPI_SUCCESS(status
))
84 static struct device_attribute irst_wakeup_attr
= {
85 .attr
= { .name
= "wakeup_events", .mode
= 0600 },
86 .show
= irst_show_wakeup_events
,
87 .store
= irst_store_wakeup_events
90 static ssize_t
irst_show_wakeup_time(struct device
*dev
,
91 struct device_attribute
*attr
, char *buf
)
93 struct acpi_device
*acpi
;
94 struct acpi_buffer output
= { ACPI_ALLOCATE_BUFFER
, NULL
};
95 union acpi_object
*result
;
98 acpi
= to_acpi_device(dev
);
100 status
= acpi_evaluate_object(acpi
->handle
, "GFTV", NULL
, &output
);
101 if (!ACPI_SUCCESS(status
))
104 result
= output
.pointer
;
106 if (result
->type
!= ACPI_TYPE_INTEGER
) {
111 return sprintf(buf
, "%lld\n", result
->integer
.value
);
114 static ssize_t
irst_store_wakeup_time(struct device
*dev
,
115 struct device_attribute
*attr
,
116 const char *buf
, size_t count
)
118 struct acpi_device
*acpi
;
119 struct acpi_object_list input
;
120 union acpi_object param
;
125 acpi
= to_acpi_device(dev
);
127 error
= kstrtoul(buf
, 0, &value
);
132 param
.type
= ACPI_TYPE_INTEGER
;
133 param
.integer
.value
= value
;
136 input
.pointer
= ¶m
;
138 status
= acpi_evaluate_object(acpi
->handle
, "SFTV", &input
, NULL
);
140 if (!ACPI_SUCCESS(status
))
146 static struct device_attribute irst_timeout_attr
= {
147 .attr
= { .name
= "wakeup_time", .mode
= 0600 },
148 .show
= irst_show_wakeup_time
,
149 .store
= irst_store_wakeup_time
152 static int irst_add(struct acpi_device
*acpi
)
156 error
= device_create_file(&acpi
->dev
, &irst_timeout_attr
);
160 error
= device_create_file(&acpi
->dev
, &irst_wakeup_attr
);
167 device_remove_file(&acpi
->dev
, &irst_timeout_attr
);
172 static int irst_remove(struct acpi_device
*acpi
)
174 device_remove_file(&acpi
->dev
, &irst_wakeup_attr
);
175 device_remove_file(&acpi
->dev
, &irst_timeout_attr
);
180 static const struct acpi_device_id irst_ids
[] = {
185 static struct acpi_driver irst_driver
= {
186 .owner
= THIS_MODULE
,
187 .name
= "intel_rapid_start",
188 .class = "intel_rapid_start",
192 .remove
= irst_remove
,
196 module_acpi_driver(irst_driver
);
198 MODULE_DEVICE_TABLE(acpi
, irst_ids
);