blob: 1c4851ff2657bbb875813f81a02c098ed1ae13f1 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#include <linux/proc_fs.h>
2#include <linux/seq_file.h>
3#include <linux/suspend.h>
4#include <linux/bcd.h>
5#include <asm/uaccess.h>
6
7#include <acpi/acpi_bus.h>
8#include <acpi/acpi_drivers.h>
9
10#ifdef CONFIG_X86
11#include <linux/mc146818rtc.h>
12#endif
13
14#include "sleep.h"
15
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#define _COMPONENT ACPI_SYSTEM_COMPONENT
Len Brown43532c82007-07-24 02:16:50 -040017
18/*
19 * this file provides support for:
20 * /proc/acpi/sleep
21 * /proc/acpi/alarm
22 * /proc/acpi/wakeup
23 */
24
Len Brown4be44fc2005-08-05 00:44:28 -040025ACPI_MODULE_NAME("sleep")
Christian Borntraeger134c2172007-08-28 14:58:56 -040026#ifdef CONFIG_ACPI_PROCFS
Linus Torvalds1da177e2005-04-16 15:20:36 -070027static int acpi_system_sleep_seq_show(struct seq_file *seq, void *offset)
28{
Len Brown4be44fc2005-08-05 00:44:28 -040029 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
Linus Torvalds1da177e2005-04-16 15:20:36 -070031 for (i = 0; i <= ACPI_STATE_S5; i++) {
32 if (sleep_states[i]) {
Len Brown4be44fc2005-08-05 00:44:28 -040033 seq_printf(seq, "S%d ", i);
Linus Torvalds1da177e2005-04-16 15:20:36 -070034 }
35 }
36
37 seq_puts(seq, "\n");
38
39 return 0;
40}
41
42static int acpi_system_sleep_open_fs(struct inode *inode, struct file *file)
43{
44 return single_open(file, acpi_system_sleep_seq_show, PDE(inode)->data);
45}
46
47static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -040048acpi_system_write_sleep(struct file *file,
49 const char __user * buffer, size_t count, loff_t * ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -070050{
Len Brown4be44fc2005-08-05 00:44:28 -040051 char str[12];
52 u32 state = 0;
53 int error = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070054
55 if (count > sizeof(str) - 1)
56 goto Done;
Len Brown4be44fc2005-08-05 00:44:28 -040057 memset(str, 0, sizeof(str));
Linus Torvalds1da177e2005-04-16 15:20:36 -070058 if (copy_from_user(str, buffer, count))
59 return -EFAULT;
60
61 /* Check for S4 bios request */
Len Brown4be44fc2005-08-05 00:44:28 -040062 if (!strcmp(str, "4b")) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 error = acpi_suspend(4);
64 goto Done;
65 }
66 state = simple_strtoul(str, NULL, 0);
Rafael J. Wysockib0cb1a12007-07-29 23:24:36 +020067#ifdef CONFIG_HIBERNATION
Linus Torvalds1da177e2005-04-16 15:20:36 -070068 if (state == 4) {
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -070069 error = hibernate();
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 goto Done;
71 }
72#endif
73 error = acpi_suspend(state);
Len Brown4be44fc2005-08-05 00:44:28 -040074 Done:
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 return error ? error : count;
76}
Christian Borntraeger134c2172007-08-28 14:58:56 -040077#endif /* CONFIG_ACPI_PROCFS */
Linus Torvalds1da177e2005-04-16 15:20:36 -070078
Len Brown673d5b42007-07-28 03:33:16 -040079#if defined(CONFIG_RTC_DRV_CMOS) || defined(CONFIG_RTC_DRV_CMOS_MODULE) || !defined(CONFIG_X86)
David Brownellf5f72b42007-05-08 00:34:02 -070080/* use /sys/class/rtc/rtcX/wakealarm instead; it's not ACPI-specific */
81#else
82#define HAVE_ACPI_LEGACY_ALARM
83#endif
84
85#ifdef HAVE_ACPI_LEGACY_ALARM
86
Linus Torvalds1da177e2005-04-16 15:20:36 -070087static int acpi_system_alarm_seq_show(struct seq_file *seq, void *offset)
88{
Len Brown4be44fc2005-08-05 00:44:28 -040089 u32 sec, min, hr;
Alexey Starikovskiyad718602007-02-02 19:48:19 +030090 u32 day, mo, yr, cent = 0;
Len Brown4be44fc2005-08-05 00:44:28 -040091 unsigned char rtc_control = 0;
92 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -070093
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 spin_lock_irqsave(&rtc_lock, flags);
95
96 sec = CMOS_READ(RTC_SECONDS_ALARM);
97 min = CMOS_READ(RTC_MINUTES_ALARM);
98 hr = CMOS_READ(RTC_HOURS_ALARM);
99 rtc_control = CMOS_READ(RTC_CONTROL);
100
101 /* If we ever get an FACP with proper values... */
Alexey Starikovskiyad718602007-02-02 19:48:19 +0300102 if (acpi_gbl_FADT.day_alarm)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 /* ACPI spec: only low 6 its should be cared */
Alexey Starikovskiyad718602007-02-02 19:48:19 +0300104 day = CMOS_READ(acpi_gbl_FADT.day_alarm) & 0x3F;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 else
Len Brown4be44fc2005-08-05 00:44:28 -0400106 day = CMOS_READ(RTC_DAY_OF_MONTH);
Alexey Starikovskiyad718602007-02-02 19:48:19 +0300107 if (acpi_gbl_FADT.month_alarm)
108 mo = CMOS_READ(acpi_gbl_FADT.month_alarm);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 else
110 mo = CMOS_READ(RTC_MONTH);
Alexey Starikovskiyad718602007-02-02 19:48:19 +0300111 if (acpi_gbl_FADT.century)
112 cent = CMOS_READ(acpi_gbl_FADT.century);
113
114 yr = CMOS_READ(RTC_YEAR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115
116 spin_unlock_irqrestore(&rtc_lock, flags);
117
118 if (!(rtc_control & RTC_DM_BINARY) || RTC_ALWAYS_BCD) {
Adrian Bunkab527d72008-10-18 20:28:39 -0700119 sec = bcd2bin(sec);
120 min = bcd2bin(min);
121 hr = bcd2bin(hr);
122 day = bcd2bin(day);
123 mo = bcd2bin(mo);
124 yr = bcd2bin(yr);
125 cent = bcd2bin(cent);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 }
127
Len Brown4be44fc2005-08-05 00:44:28 -0400128 /* we're trusting the FADT (see above) */
Alexey Starikovskiyad718602007-02-02 19:48:19 +0300129 if (!acpi_gbl_FADT.century)
Len Brown4be44fc2005-08-05 00:44:28 -0400130 /* If we're not trusting the FADT, we should at least make it
131 * right for _this_ century... ehm, what is _this_ century?
132 *
133 * TBD:
134 * ASAP: find piece of code in the kernel, e.g. star tracker driver,
135 * which we can trust to determine the century correctly. Atom
136 * watch driver would be nice, too...
137 *
138 * if that has not happened, change for first release in 2050:
139 * if (yr<50)
140 * yr += 2100;
141 * else
142 * yr += 2000; // current line of code
143 *
144 * if that has not happened either, please do on 2099/12/31:23:59:59
145 * s/2000/2100
146 *
147 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 yr += 2000;
Alexey Starikovskiyad718602007-02-02 19:48:19 +0300149 else
150 yr += cent * 100;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151
Len Brown4be44fc2005-08-05 00:44:28 -0400152 seq_printf(seq, "%4.4u-", yr);
153 (mo > 12) ? seq_puts(seq, "**-") : seq_printf(seq, "%2.2u-", mo);
154 (day > 31) ? seq_puts(seq, "** ") : seq_printf(seq, "%2.2u ", day);
155 (hr > 23) ? seq_puts(seq, "**:") : seq_printf(seq, "%2.2u:", hr);
156 (min > 59) ? seq_puts(seq, "**:") : seq_printf(seq, "%2.2u:", min);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 (sec > 59) ? seq_puts(seq, "**\n") : seq_printf(seq, "%2.2u\n", sec);
158
159 return 0;
160}
161
162static int acpi_system_alarm_open_fs(struct inode *inode, struct file *file)
163{
164 return single_open(file, acpi_system_alarm_seq_show, PDE(inode)->data);
165}
166
Len Brown4be44fc2005-08-05 00:44:28 -0400167static int get_date_field(char **p, u32 * value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168{
Len Brown4be44fc2005-08-05 00:44:28 -0400169 char *next = NULL;
170 char *string_end = NULL;
171 int result = -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172
173 /*
174 * Try to find delimeter, only to insert null. The end of the
175 * string won't have one, but is still valid.
176 */
Signed-off by Yi Yang975c3022007-12-27 21:50:42 -0500177 if (*p == NULL)
178 return result;
179
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 next = strpbrk(*p, "- :");
181 if (next)
182 *next++ = '\0';
183
184 *value = simple_strtoul(*p, &string_end, 10);
185
186 /* Signal success if we got a good digit */
187 if (string_end != *p)
188 result = 0;
189
190 if (next)
191 *p = next;
Signed-off by Yi Yang975c3022007-12-27 21:50:42 -0500192 else
193 *p = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194
195 return result;
196}
197
Linus Torvaldsc67c36e2007-10-17 23:18:32 -0400198/* Read a possibly BCD register, always return binary */
199static u32 cmos_bcd_read(int offset, int rtc_control)
200{
201 u32 val = CMOS_READ(offset);
202 if (!(rtc_control & RTC_DM_BINARY) || RTC_ALWAYS_BCD)
Adrian Bunkab527d72008-10-18 20:28:39 -0700203 val = bcd2bin(val);
Linus Torvaldsc67c36e2007-10-17 23:18:32 -0400204 return val;
205}
206
207/* Write binary value into possibly BCD register */
208static void cmos_bcd_write(u32 val, int offset, int rtc_control)
209{
210 if (!(rtc_control & RTC_DM_BINARY) || RTC_ALWAYS_BCD)
Adrian Bunkab527d72008-10-18 20:28:39 -0700211 val = bin2bcd(val);
Linus Torvaldsc67c36e2007-10-17 23:18:32 -0400212 CMOS_WRITE(val, offset);
213}
214
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -0400216acpi_system_write_alarm(struct file *file,
217 const char __user * buffer, size_t count, loff_t * ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218{
Len Brown4be44fc2005-08-05 00:44:28 -0400219 int result = 0;
220 char alarm_string[30] = { '\0' };
221 char *p = alarm_string;
222 u32 sec, min, hr, day, mo, yr;
223 int adjust = 0;
224 unsigned char rtc_control = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 if (count > sizeof(alarm_string) - 1)
Lin Ming95d9a7a2008-12-16 16:49:26 +0800227 return -EINVAL;
Len Brown4be44fc2005-08-05 00:44:28 -0400228
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 if (copy_from_user(alarm_string, buffer, count))
Lin Ming95d9a7a2008-12-16 16:49:26 +0800230 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231
232 alarm_string[count] = '\0';
233
234 /* check for time adjustment */
235 if (alarm_string[0] == '+') {
236 p++;
237 adjust = 1;
238 }
239
240 if ((result = get_date_field(&p, &yr)))
241 goto end;
242 if ((result = get_date_field(&p, &mo)))
243 goto end;
244 if ((result = get_date_field(&p, &day)))
245 goto end;
246 if ((result = get_date_field(&p, &hr)))
247 goto end;
248 if ((result = get_date_field(&p, &min)))
249 goto end;
250 if ((result = get_date_field(&p, &sec)))
251 goto end;
252
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 spin_lock_irq(&rtc_lock);
254
255 rtc_control = CMOS_READ(RTC_CONTROL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256
257 if (adjust) {
Linus Torvaldsc67c36e2007-10-17 23:18:32 -0400258 yr += cmos_bcd_read(RTC_YEAR, rtc_control);
259 mo += cmos_bcd_read(RTC_MONTH, rtc_control);
260 day += cmos_bcd_read(RTC_DAY_OF_MONTH, rtc_control);
261 hr += cmos_bcd_read(RTC_HOURS, rtc_control);
262 min += cmos_bcd_read(RTC_MINUTES, rtc_control);
263 sec += cmos_bcd_read(RTC_SECONDS, rtc_control);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 }
265
266 spin_unlock_irq(&rtc_lock);
267
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 if (sec > 59) {
Yi Yang08798022007-12-27 22:04:26 -0500269 min += sec/60;
270 sec = sec%60;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 }
272 if (min > 59) {
Yi Yang08798022007-12-27 22:04:26 -0500273 hr += min/60;
274 min = min%60;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 }
276 if (hr > 23) {
Yi Yang08798022007-12-27 22:04:26 -0500277 day += hr/24;
278 hr = hr%24;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 }
280 if (day > 31) {
Yi Yang08798022007-12-27 22:04:26 -0500281 mo += day/32;
282 day = day%32;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 }
284 if (mo > 12) {
Yi Yang08798022007-12-27 22:04:26 -0500285 yr += mo/13;
286 mo = mo%13;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288
289 spin_lock_irq(&rtc_lock);
290 /*
291 * Disable alarm interrupt before setting alarm timer or else
292 * when ACPI_EVENT_RTC is enabled, a spurious ACPI interrupt occurs
293 */
294 rtc_control &= ~RTC_AIE;
295 CMOS_WRITE(rtc_control, RTC_CONTROL);
296 CMOS_READ(RTC_INTR_FLAGS);
297
298 /* write the fields the rtc knows about */
Linus Torvaldsc67c36e2007-10-17 23:18:32 -0400299 cmos_bcd_write(hr, RTC_HOURS_ALARM, rtc_control);
300 cmos_bcd_write(min, RTC_MINUTES_ALARM, rtc_control);
301 cmos_bcd_write(sec, RTC_SECONDS_ALARM, rtc_control);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302
303 /*
304 * If the system supports an enhanced alarm it will have non-zero
305 * offsets into the CMOS RAM here -- which for some reason are pointing
306 * to the RTC area of memory.
307 */
Alexey Starikovskiyad718602007-02-02 19:48:19 +0300308 if (acpi_gbl_FADT.day_alarm)
Linus Torvaldsc67c36e2007-10-17 23:18:32 -0400309 cmos_bcd_write(day, acpi_gbl_FADT.day_alarm, rtc_control);
Alexey Starikovskiyad718602007-02-02 19:48:19 +0300310 if (acpi_gbl_FADT.month_alarm)
Linus Torvaldsc67c36e2007-10-17 23:18:32 -0400311 cmos_bcd_write(mo, acpi_gbl_FADT.month_alarm, rtc_control);
Huacai Chencce3ce82008-07-04 09:59:31 -0700312 if (acpi_gbl_FADT.century) {
313 if (adjust)
314 yr += cmos_bcd_read(acpi_gbl_FADT.century, rtc_control) * 100;
Linus Torvaldsc67c36e2007-10-17 23:18:32 -0400315 cmos_bcd_write(yr / 100, acpi_gbl_FADT.century, rtc_control);
Huacai Chencce3ce82008-07-04 09:59:31 -0700316 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 /* enable the rtc alarm interrupt */
318 rtc_control |= RTC_AIE;
319 CMOS_WRITE(rtc_control, RTC_CONTROL);
320 CMOS_READ(RTC_INTR_FLAGS);
321
322 spin_unlock_irq(&rtc_lock);
323
324 acpi_clear_event(ACPI_EVENT_RTC);
325 acpi_enable_event(ACPI_EVENT_RTC, 0);
326
327 *ppos += count;
328
329 result = 0;
Len Brown4be44fc2005-08-05 00:44:28 -0400330 end:
Lin Ming95d9a7a2008-12-16 16:49:26 +0800331 return result ? result : count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332}
Len Brownfd350942007-05-09 23:34:35 -0400333#endif /* HAVE_ACPI_LEGACY_ALARM */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334
Len Brown4be44fc2005-08-05 00:44:28 -0400335extern struct list_head acpi_wakeup_device_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336extern spinlock_t acpi_device_lock;
337
338static int
339acpi_system_wakeup_device_seq_show(struct seq_file *seq, void *offset)
340{
Len Brown4be44fc2005-08-05 00:44:28 -0400341 struct list_head *node, *next;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342
David Brownell8aa55592007-04-25 15:20:10 -0400343 seq_printf(seq, "Device\tS-state\t Status Sysfs node\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344
345 spin_lock(&acpi_device_lock);
346 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
Len Brown4be44fc2005-08-05 00:44:28 -0400347 struct acpi_device *dev =
348 container_of(node, struct acpi_device, wakeup_list);
David Brownell8aa55592007-04-25 15:20:10 -0400349 struct device *ldev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350
351 if (!dev->wakeup.flags.valid)
352 continue;
353 spin_unlock(&acpi_device_lock);
David Brownell8aa55592007-04-25 15:20:10 -0400354
355 ldev = acpi_get_physical_device(dev->handle);
356 seq_printf(seq, "%s\t S%d\t%c%-8s ",
Len Brown4be44fc2005-08-05 00:44:28 -0400357 dev->pnp.bus_id,
358 (u32) dev->wakeup.sleep_state,
David Brownell8aa55592007-04-25 15:20:10 -0400359 dev->wakeup.flags.run_wake ? '*' : ' ',
Pavel Machekc65ade42005-08-05 00:37:45 -0400360 dev->wakeup.state.enabled ? "enabled" : "disabled");
David Brownell8aa55592007-04-25 15:20:10 -0400361 if (ldev)
362 seq_printf(seq, "%s:%s",
Linus Torvalds77fb61a2008-11-16 10:09:34 -0800363 ldev->bus ? ldev->bus->name : "no-bus",
Kay Sievers07944692008-10-30 01:18:59 +0100364 dev_name(ldev));
David Brownell8aa55592007-04-25 15:20:10 -0400365 seq_printf(seq, "\n");
366 put_device(ldev);
367
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 spin_lock(&acpi_device_lock);
369 }
370 spin_unlock(&acpi_device_lock);
371 return 0;
372}
373
Rafael J. Wysocki76acae02008-10-03 15:23:49 -0700374static void physical_device_enable_wakeup(struct acpi_device *adev)
375{
376 struct device *dev = acpi_get_physical_device(adev->handle);
377
378 if (dev && device_can_wakeup(dev))
379 device_set_wakeup_enable(dev, adev->wakeup.state.enabled);
380}
381
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -0400383acpi_system_write_wakeup_device(struct file *file,
384 const char __user * buffer,
385 size_t count, loff_t * ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386{
Len Brown4be44fc2005-08-05 00:44:28 -0400387 struct list_head *node, *next;
388 char strbuf[5];
389 char str[5] = "";
390 int len = count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 struct acpi_device *found_dev = NULL;
392
Len Brown4be44fc2005-08-05 00:44:28 -0400393 if (len > 4)
394 len = 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395
396 if (copy_from_user(strbuf, buffer, len))
397 return -EFAULT;
398 strbuf[len] = '\0';
399 sscanf(strbuf, "%s", str);
400
401 spin_lock(&acpi_device_lock);
402 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
Len Brown4be44fc2005-08-05 00:44:28 -0400403 struct acpi_device *dev =
404 container_of(node, struct acpi_device, wakeup_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 if (!dev->wakeup.flags.valid)
406 continue;
407
408 if (!strncmp(dev->pnp.bus_id, str, 4)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400409 dev->wakeup.state.enabled =
410 dev->wakeup.state.enabled ? 0 : 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 found_dev = dev;
412 break;
413 }
414 }
415 if (found_dev) {
Rafael J. Wysocki76acae02008-10-03 15:23:49 -0700416 physical_device_enable_wakeup(found_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
Len Brown4be44fc2005-08-05 00:44:28 -0400418 struct acpi_device *dev = container_of(node,
419 struct
420 acpi_device,
421 wakeup_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422
423 if ((dev != found_dev) &&
Len Brown4be44fc2005-08-05 00:44:28 -0400424 (dev->wakeup.gpe_number ==
425 found_dev->wakeup.gpe_number)
426 && (dev->wakeup.gpe_device ==
427 found_dev->wakeup.gpe_device)) {
428 printk(KERN_WARNING
429 "ACPI: '%s' and '%s' have the same GPE, "
430 "can't disable/enable one seperately\n",
431 dev->pnp.bus_id, found_dev->pnp.bus_id);
432 dev->wakeup.state.enabled =
433 found_dev->wakeup.state.enabled;
Rafael J. Wysocki76acae02008-10-03 15:23:49 -0700434 physical_device_enable_wakeup(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 }
436 }
437 }
438 spin_unlock(&acpi_device_lock);
439 return count;
440}
441
442static int
443acpi_system_wakeup_device_open_fs(struct inode *inode, struct file *file)
444{
Len Brown4be44fc2005-08-05 00:44:28 -0400445 return single_open(file, acpi_system_wakeup_device_seq_show,
446 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447}
448
Arjan van de Vend7508032006-07-04 13:06:00 -0400449static const struct file_operations acpi_system_wakeup_device_fops = {
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -0700450 .owner = THIS_MODULE,
Len Brown4be44fc2005-08-05 00:44:28 -0400451 .open = acpi_system_wakeup_device_open_fs,
452 .read = seq_read,
453 .write = acpi_system_write_wakeup_device,
454 .llseek = seq_lseek,
455 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456};
457
Christian Borntraeger134c2172007-08-28 14:58:56 -0400458#ifdef CONFIG_ACPI_PROCFS
Arjan van de Vend7508032006-07-04 13:06:00 -0400459static const struct file_operations acpi_system_sleep_fops = {
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -0700460 .owner = THIS_MODULE,
Len Brown4be44fc2005-08-05 00:44:28 -0400461 .open = acpi_system_sleep_open_fs,
462 .read = seq_read,
463 .write = acpi_system_write_sleep,
464 .llseek = seq_lseek,
465 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466};
Christian Borntraeger134c2172007-08-28 14:58:56 -0400467#endif /* CONFIG_ACPI_PROCFS */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468
David Brownellf5f72b42007-05-08 00:34:02 -0700469#ifdef HAVE_ACPI_LEGACY_ALARM
Arjan van de Vend7508032006-07-04 13:06:00 -0400470static const struct file_operations acpi_system_alarm_fops = {
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -0700471 .owner = THIS_MODULE,
Len Brown4be44fc2005-08-05 00:44:28 -0400472 .open = acpi_system_alarm_open_fs,
473 .read = seq_read,
474 .write = acpi_system_write_alarm,
475 .llseek = seq_lseek,
476 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477};
478
Len Brown4be44fc2005-08-05 00:44:28 -0400479static u32 rtc_handler(void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480{
481 acpi_clear_event(ACPI_EVENT_RTC);
482 acpi_disable_event(ACPI_EVENT_RTC, 0);
483
484 return ACPI_INTERRUPT_HANDLED;
485}
Len Brownfd350942007-05-09 23:34:35 -0400486#endif /* HAVE_ACPI_LEGACY_ALARM */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487
David Brownellf5f72b42007-05-08 00:34:02 -0700488static int __init acpi_sleep_proc_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 if (acpi_disabled)
491 return 0;
Len Brown4be44fc2005-08-05 00:44:28 -0400492
Christian Borntraeger134c2172007-08-28 14:58:56 -0400493#ifdef CONFIG_ACPI_PROCFS
Pavel Machekc65ade42005-08-05 00:37:45 -0400494 /* 'sleep' [R/W] */
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -0700495 proc_create("sleep", S_IFREG | S_IRUGO | S_IWUSR,
496 acpi_root_dir, &acpi_system_sleep_fops);
Len Brown43532c82007-07-24 02:16:50 -0400497#endif /* CONFIG_ACPI_PROCFS */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498
David Brownellf5f72b42007-05-08 00:34:02 -0700499#ifdef HAVE_ACPI_LEGACY_ALARM
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 /* 'alarm' [R/W] */
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -0700501 proc_create("alarm", S_IFREG | S_IRUGO | S_IWUSR,
502 acpi_root_dir, &acpi_system_alarm_fops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503
David Brownellf5f72b42007-05-08 00:34:02 -0700504 acpi_install_fixed_event_handler(ACPI_EVENT_RTC, rtc_handler, NULL);
Zhao Yakuie1094bf2008-05-14 11:32:59 +0800505 /*
506 * Disable the RTC event after installing RTC handler.
507 * Only when RTC alarm is set will it be enabled.
508 */
509 acpi_clear_event(ACPI_EVENT_RTC);
510 acpi_disable_event(ACPI_EVENT_RTC, 0);
Len Brownfd350942007-05-09 23:34:35 -0400511#endif /* HAVE_ACPI_LEGACY_ALARM */
David Brownellf5f72b42007-05-08 00:34:02 -0700512
Pavel Machekc65ade42005-08-05 00:37:45 -0400513 /* 'wakeup device' [R/W] */
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -0700514 proc_create("wakeup", S_IFREG | S_IRUGO | S_IWUSR,
515 acpi_root_dir, &acpi_system_wakeup_device_fops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 return 0;
518}
519
520late_initcall(acpi_sleep_proc_init);