blob: fce78fbf5f6450d70fe49ae6ca6be92866791300 [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
31 ACPI_FUNCTION_TRACE("acpi_system_sleep_seq_show");
32
33 for (i = 0; i <= ACPI_STATE_S5; i++) {
34 if (sleep_states[i]) {
Len Brown4be44fc2005-08-05 00:44:28 -040035 seq_printf(seq, "S%d ", i);
Linus Torvalds1da177e2005-04-16 15:20:36 -070036 }
37 }
38
39 seq_puts(seq, "\n");
40
41 return 0;
42}
43
44static int acpi_system_sleep_open_fs(struct inode *inode, struct file *file)
45{
46 return single_open(file, acpi_system_sleep_seq_show, PDE(inode)->data);
47}
48
49static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -040050acpi_system_write_sleep(struct file *file,
51 const char __user * buffer, size_t count, loff_t * ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -070052{
Len Brown4be44fc2005-08-05 00:44:28 -040053 char str[12];
54 u32 state = 0;
55 int error = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
57 if (count > sizeof(str) - 1)
58 goto Done;
Len Brown4be44fc2005-08-05 00:44:28 -040059 memset(str, 0, sizeof(str));
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 if (copy_from_user(str, buffer, count))
61 return -EFAULT;
62
63 /* Check for S4 bios request */
Len Brown4be44fc2005-08-05 00:44:28 -040064 if (!strcmp(str, "4b")) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070065 error = acpi_suspend(4);
66 goto Done;
67 }
68 state = simple_strtoul(str, NULL, 0);
Rafael J. Wysockib0cb1a12007-07-29 23:24:36 +020069#ifdef CONFIG_HIBERNATION
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 if (state == 4) {
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -070071 error = hibernate();
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 goto Done;
73 }
74#endif
75 error = acpi_suspend(state);
Len Brown4be44fc2005-08-05 00:44:28 -040076 Done:
Linus Torvalds1da177e2005-04-16 15:20:36 -070077 return error ? error : count;
78}
Christian Borntraeger134c2172007-08-28 14:58:56 -040079#endif /* CONFIG_ACPI_PROCFS */
Linus Torvalds1da177e2005-04-16 15:20:36 -070080
Len Brown673d5b42007-07-28 03:33:16 -040081#if defined(CONFIG_RTC_DRV_CMOS) || defined(CONFIG_RTC_DRV_CMOS_MODULE) || !defined(CONFIG_X86)
David Brownellf5f72b42007-05-08 00:34:02 -070082/* use /sys/class/rtc/rtcX/wakealarm instead; it's not ACPI-specific */
83#else
84#define HAVE_ACPI_LEGACY_ALARM
85#endif
86
87#ifdef HAVE_ACPI_LEGACY_ALARM
88
Linus Torvalds1da177e2005-04-16 15:20:36 -070089static int acpi_system_alarm_seq_show(struct seq_file *seq, void *offset)
90{
Len Brown4be44fc2005-08-05 00:44:28 -040091 u32 sec, min, hr;
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +030092 u32 day, mo, yr, cent = 0;
Len Brown4be44fc2005-08-05 00:44:28 -040093 unsigned char rtc_control = 0;
94 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -070095
96 ACPI_FUNCTION_TRACE("acpi_system_alarm_seq_show");
97
98 spin_lock_irqsave(&rtc_lock, flags);
99
100 sec = CMOS_READ(RTC_SECONDS_ALARM);
101 min = CMOS_READ(RTC_MINUTES_ALARM);
102 hr = CMOS_READ(RTC_HOURS_ALARM);
103 rtc_control = CMOS_READ(RTC_CONTROL);
104
105 /* If we ever get an FACP with proper values... */
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +0300106 if (acpi_gbl_FADT.day_alarm)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 /* ACPI spec: only low 6 its should be cared */
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +0300108 day = CMOS_READ(acpi_gbl_FADT.day_alarm) & 0x3F;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 else
Len Brown4be44fc2005-08-05 00:44:28 -0400110 day = CMOS_READ(RTC_DAY_OF_MONTH);
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +0300111 if (acpi_gbl_FADT.month_alarm)
112 mo = CMOS_READ(acpi_gbl_FADT.month_alarm);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 else
114 mo = CMOS_READ(RTC_MONTH);
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +0300115 if (acpi_gbl_FADT.century)
116 cent = CMOS_READ(acpi_gbl_FADT.century);
117
118 yr = CMOS_READ(RTC_YEAR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119
120 spin_unlock_irqrestore(&rtc_lock, flags);
121
122 if (!(rtc_control & RTC_DM_BINARY) || RTC_ALWAYS_BCD) {
123 BCD_TO_BIN(sec);
124 BCD_TO_BIN(min);
125 BCD_TO_BIN(hr);
126 BCD_TO_BIN(day);
127 BCD_TO_BIN(mo);
128 BCD_TO_BIN(yr);
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +0300129 BCD_TO_BIN(cent);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 }
131
Len Brown4be44fc2005-08-05 00:44:28 -0400132 /* we're trusting the FADT (see above) */
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +0300133 if (!acpi_gbl_FADT.century)
Len Brown4be44fc2005-08-05 00:44:28 -0400134 /* If we're not trusting the FADT, we should at least make it
135 * right for _this_ century... ehm, what is _this_ century?
136 *
137 * TBD:
138 * ASAP: find piece of code in the kernel, e.g. star tracker driver,
139 * which we can trust to determine the century correctly. Atom
140 * watch driver would be nice, too...
141 *
142 * if that has not happened, change for first release in 2050:
143 * if (yr<50)
144 * yr += 2100;
145 * else
146 * yr += 2000; // current line of code
147 *
148 * if that has not happened either, please do on 2099/12/31:23:59:59
149 * s/2000/2100
150 *
151 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 yr += 2000;
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +0300153 else
154 yr += cent * 100;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155
Len Brown4be44fc2005-08-05 00:44:28 -0400156 seq_printf(seq, "%4.4u-", yr);
157 (mo > 12) ? seq_puts(seq, "**-") : seq_printf(seq, "%2.2u-", mo);
158 (day > 31) ? seq_puts(seq, "** ") : seq_printf(seq, "%2.2u ", day);
159 (hr > 23) ? seq_puts(seq, "**:") : seq_printf(seq, "%2.2u:", hr);
160 (min > 59) ? seq_puts(seq, "**:") : seq_printf(seq, "%2.2u:", min);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 (sec > 59) ? seq_puts(seq, "**\n") : seq_printf(seq, "%2.2u\n", sec);
162
163 return 0;
164}
165
166static int acpi_system_alarm_open_fs(struct inode *inode, struct file *file)
167{
168 return single_open(file, acpi_system_alarm_seq_show, PDE(inode)->data);
169}
170
Len Brown4be44fc2005-08-05 00:44:28 -0400171static int get_date_field(char **p, u32 * value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172{
Len Brown4be44fc2005-08-05 00:44:28 -0400173 char *next = NULL;
174 char *string_end = NULL;
175 int result = -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176
177 /*
178 * Try to find delimeter, only to insert null. The end of the
179 * string won't have one, but is still valid.
180 */
Signed-off by Yi Yang975c3022007-12-27 21:50:42 -0500181 if (*p == NULL)
182 return result;
183
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184 next = strpbrk(*p, "- :");
185 if (next)
186 *next++ = '\0';
187
188 *value = simple_strtoul(*p, &string_end, 10);
189
190 /* Signal success if we got a good digit */
191 if (string_end != *p)
192 result = 0;
193
194 if (next)
195 *p = next;
Signed-off by Yi Yang975c3022007-12-27 21:50:42 -0500196 else
197 *p = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198
199 return result;
200}
201
Linus Torvaldsc67c36e2007-10-17 23:18:32 -0400202/* Read a possibly BCD register, always return binary */
203static u32 cmos_bcd_read(int offset, int rtc_control)
204{
205 u32 val = CMOS_READ(offset);
206 if (!(rtc_control & RTC_DM_BINARY) || RTC_ALWAYS_BCD)
207 BCD_TO_BIN(val);
208 return val;
209}
210
211/* Write binary value into possibly BCD register */
212static void cmos_bcd_write(u32 val, int offset, int rtc_control)
213{
214 if (!(rtc_control & RTC_DM_BINARY) || RTC_ALWAYS_BCD)
215 BIN_TO_BCD(val);
216 CMOS_WRITE(val, offset);
217}
218
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -0400220acpi_system_write_alarm(struct file *file,
221 const char __user * buffer, size_t count, loff_t * ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222{
Len Brown4be44fc2005-08-05 00:44:28 -0400223 int result = 0;
224 char alarm_string[30] = { '\0' };
225 char *p = alarm_string;
226 u32 sec, min, hr, day, mo, yr;
227 int adjust = 0;
228 unsigned char rtc_control = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229
230 ACPI_FUNCTION_TRACE("acpi_system_write_alarm");
231
232 if (count > sizeof(alarm_string) - 1)
233 return_VALUE(-EINVAL);
Len Brown4be44fc2005-08-05 00:44:28 -0400234
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 if (copy_from_user(alarm_string, buffer, count))
236 return_VALUE(-EFAULT);
237
238 alarm_string[count] = '\0';
239
240 /* check for time adjustment */
241 if (alarm_string[0] == '+') {
242 p++;
243 adjust = 1;
244 }
245
246 if ((result = get_date_field(&p, &yr)))
247 goto end;
248 if ((result = get_date_field(&p, &mo)))
249 goto end;
250 if ((result = get_date_field(&p, &day)))
251 goto end;
252 if ((result = get_date_field(&p, &hr)))
253 goto end;
254 if ((result = get_date_field(&p, &min)))
255 goto end;
256 if ((result = get_date_field(&p, &sec)))
257 goto end;
258
259 if (sec > 59) {
260 min += 1;
261 sec -= 60;
262 }
263 if (min > 59) {
264 hr += 1;
265 min -= 60;
266 }
267 if (hr > 23) {
268 day += 1;
269 hr -= 24;
270 }
271 if (day > 31) {
272 mo += 1;
273 day -= 31;
274 }
275 if (mo > 12) {
276 yr += 1;
277 mo -= 12;
278 }
279
280 spin_lock_irq(&rtc_lock);
281
282 rtc_control = CMOS_READ(RTC_CONTROL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283
284 if (adjust) {
Linus Torvaldsc67c36e2007-10-17 23:18:32 -0400285 yr += cmos_bcd_read(RTC_YEAR, rtc_control);
286 mo += cmos_bcd_read(RTC_MONTH, rtc_control);
287 day += cmos_bcd_read(RTC_DAY_OF_MONTH, rtc_control);
288 hr += cmos_bcd_read(RTC_HOURS, rtc_control);
289 min += cmos_bcd_read(RTC_MINUTES, rtc_control);
290 sec += cmos_bcd_read(RTC_SECONDS, rtc_control);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 }
292
293 spin_unlock_irq(&rtc_lock);
294
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 if (sec > 59) {
296 min++;
297 sec -= 60;
298 }
299 if (min > 59) {
300 hr++;
301 min -= 60;
302 }
303 if (hr > 23) {
304 day++;
305 hr -= 24;
306 }
307 if (day > 31) {
308 mo++;
309 day -= 31;
310 }
311 if (mo > 12) {
312 yr++;
313 mo -= 12;
314 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315
316 spin_lock_irq(&rtc_lock);
317 /*
318 * Disable alarm interrupt before setting alarm timer or else
319 * when ACPI_EVENT_RTC is enabled, a spurious ACPI interrupt occurs
320 */
321 rtc_control &= ~RTC_AIE;
322 CMOS_WRITE(rtc_control, RTC_CONTROL);
323 CMOS_READ(RTC_INTR_FLAGS);
324
325 /* write the fields the rtc knows about */
Linus Torvaldsc67c36e2007-10-17 23:18:32 -0400326 cmos_bcd_write(hr, RTC_HOURS_ALARM, rtc_control);
327 cmos_bcd_write(min, RTC_MINUTES_ALARM, rtc_control);
328 cmos_bcd_write(sec, RTC_SECONDS_ALARM, rtc_control);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329
330 /*
331 * If the system supports an enhanced alarm it will have non-zero
332 * offsets into the CMOS RAM here -- which for some reason are pointing
333 * to the RTC area of memory.
334 */
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +0300335 if (acpi_gbl_FADT.day_alarm)
Linus Torvaldsc67c36e2007-10-17 23:18:32 -0400336 cmos_bcd_write(day, acpi_gbl_FADT.day_alarm, rtc_control);
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +0300337 if (acpi_gbl_FADT.month_alarm)
Linus Torvaldsc67c36e2007-10-17 23:18:32 -0400338 cmos_bcd_write(mo, acpi_gbl_FADT.month_alarm, rtc_control);
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +0300339 if (acpi_gbl_FADT.century)
Linus Torvaldsc67c36e2007-10-17 23:18:32 -0400340 cmos_bcd_write(yr / 100, acpi_gbl_FADT.century, rtc_control);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 /* enable the rtc alarm interrupt */
342 rtc_control |= RTC_AIE;
343 CMOS_WRITE(rtc_control, RTC_CONTROL);
344 CMOS_READ(RTC_INTR_FLAGS);
345
346 spin_unlock_irq(&rtc_lock);
347
348 acpi_clear_event(ACPI_EVENT_RTC);
349 acpi_enable_event(ACPI_EVENT_RTC, 0);
350
351 *ppos += count;
352
353 result = 0;
Len Brown4be44fc2005-08-05 00:44:28 -0400354 end:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 return_VALUE(result ? result : count);
356}
Len Brownfd350942007-05-09 23:34:35 -0400357#endif /* HAVE_ACPI_LEGACY_ALARM */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358
Len Brown4be44fc2005-08-05 00:44:28 -0400359extern struct list_head acpi_wakeup_device_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360extern spinlock_t acpi_device_lock;
361
362static int
363acpi_system_wakeup_device_seq_show(struct seq_file *seq, void *offset)
364{
Len Brown4be44fc2005-08-05 00:44:28 -0400365 struct list_head *node, *next;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366
David Brownell8aa55592007-04-25 15:20:10 -0400367 seq_printf(seq, "Device\tS-state\t Status Sysfs node\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368
369 spin_lock(&acpi_device_lock);
370 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
Len Brown4be44fc2005-08-05 00:44:28 -0400371 struct acpi_device *dev =
372 container_of(node, struct acpi_device, wakeup_list);
David Brownell8aa55592007-04-25 15:20:10 -0400373 struct device *ldev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374
375 if (!dev->wakeup.flags.valid)
376 continue;
377 spin_unlock(&acpi_device_lock);
David Brownell8aa55592007-04-25 15:20:10 -0400378
379 ldev = acpi_get_physical_device(dev->handle);
380 seq_printf(seq, "%s\t S%d\t%c%-8s ",
Len Brown4be44fc2005-08-05 00:44:28 -0400381 dev->pnp.bus_id,
382 (u32) dev->wakeup.sleep_state,
David Brownell8aa55592007-04-25 15:20:10 -0400383 dev->wakeup.flags.run_wake ? '*' : ' ',
Pavel Machekc65ade42005-08-05 00:37:45 -0400384 dev->wakeup.state.enabled ? "enabled" : "disabled");
David Brownell8aa55592007-04-25 15:20:10 -0400385 if (ldev)
386 seq_printf(seq, "%s:%s",
Len Brownfd350942007-05-09 23:34:35 -0400387 ldev->bus ? ldev->bus->name : "no-bus",
388 ldev->bus_id);
David Brownell8aa55592007-04-25 15:20:10 -0400389 seq_printf(seq, "\n");
390 put_device(ldev);
391
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 spin_lock(&acpi_device_lock);
393 }
394 spin_unlock(&acpi_device_lock);
395 return 0;
396}
397
398static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -0400399acpi_system_write_wakeup_device(struct file *file,
400 const char __user * buffer,
401 size_t count, loff_t * ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402{
Len Brown4be44fc2005-08-05 00:44:28 -0400403 struct list_head *node, *next;
404 char strbuf[5];
405 char str[5] = "";
406 int len = count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 struct acpi_device *found_dev = NULL;
408
Len Brown4be44fc2005-08-05 00:44:28 -0400409 if (len > 4)
410 len = 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411
412 if (copy_from_user(strbuf, buffer, len))
413 return -EFAULT;
414 strbuf[len] = '\0';
415 sscanf(strbuf, "%s", str);
416
417 spin_lock(&acpi_device_lock);
418 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
Len Brown4be44fc2005-08-05 00:44:28 -0400419 struct acpi_device *dev =
420 container_of(node, struct acpi_device, wakeup_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 if (!dev->wakeup.flags.valid)
422 continue;
423
424 if (!strncmp(dev->pnp.bus_id, str, 4)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400425 dev->wakeup.state.enabled =
426 dev->wakeup.state.enabled ? 0 : 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 found_dev = dev;
428 break;
429 }
430 }
431 if (found_dev) {
432 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
Len Brown4be44fc2005-08-05 00:44:28 -0400433 struct acpi_device *dev = container_of(node,
434 struct
435 acpi_device,
436 wakeup_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437
438 if ((dev != found_dev) &&
Len Brown4be44fc2005-08-05 00:44:28 -0400439 (dev->wakeup.gpe_number ==
440 found_dev->wakeup.gpe_number)
441 && (dev->wakeup.gpe_device ==
442 found_dev->wakeup.gpe_device)) {
443 printk(KERN_WARNING
444 "ACPI: '%s' and '%s' have the same GPE, "
445 "can't disable/enable one seperately\n",
446 dev->pnp.bus_id, found_dev->pnp.bus_id);
447 dev->wakeup.state.enabled =
448 found_dev->wakeup.state.enabled;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 }
450 }
451 }
452 spin_unlock(&acpi_device_lock);
453 return count;
454}
455
456static int
457acpi_system_wakeup_device_open_fs(struct inode *inode, struct file *file)
458{
Len Brown4be44fc2005-08-05 00:44:28 -0400459 return single_open(file, acpi_system_wakeup_device_seq_show,
460 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461}
462
Arjan van de Vend7508032006-07-04 13:06:00 -0400463static const struct file_operations acpi_system_wakeup_device_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400464 .open = acpi_system_wakeup_device_open_fs,
465 .read = seq_read,
466 .write = acpi_system_write_wakeup_device,
467 .llseek = seq_lseek,
468 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469};
470
Christian Borntraeger134c2172007-08-28 14:58:56 -0400471#ifdef CONFIG_ACPI_PROCFS
Arjan van de Vend7508032006-07-04 13:06:00 -0400472static const struct file_operations acpi_system_sleep_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400473 .open = acpi_system_sleep_open_fs,
474 .read = seq_read,
475 .write = acpi_system_write_sleep,
476 .llseek = seq_lseek,
477 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478};
Christian Borntraeger134c2172007-08-28 14:58:56 -0400479#endif /* CONFIG_ACPI_PROCFS */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480
David Brownellf5f72b42007-05-08 00:34:02 -0700481#ifdef HAVE_ACPI_LEGACY_ALARM
Arjan van de Vend7508032006-07-04 13:06:00 -0400482static const struct file_operations acpi_system_alarm_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400483 .open = acpi_system_alarm_open_fs,
484 .read = seq_read,
485 .write = acpi_system_write_alarm,
486 .llseek = seq_lseek,
487 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488};
489
Len Brown4be44fc2005-08-05 00:44:28 -0400490static u32 rtc_handler(void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491{
492 acpi_clear_event(ACPI_EVENT_RTC);
493 acpi_disable_event(ACPI_EVENT_RTC, 0);
494
495 return ACPI_INTERRUPT_HANDLED;
496}
Len Brownfd350942007-05-09 23:34:35 -0400497#endif /* HAVE_ACPI_LEGACY_ALARM */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498
David Brownellf5f72b42007-05-08 00:34:02 -0700499static int __init acpi_sleep_proc_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500{
Pavel Machekc65ade42005-08-05 00:37:45 -0400501 struct proc_dir_entry *entry = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502
503 if (acpi_disabled)
504 return 0;
Len Brown4be44fc2005-08-05 00:44:28 -0400505
Christian Borntraeger134c2172007-08-28 14:58:56 -0400506#ifdef CONFIG_ACPI_PROCFS
Pavel Machekc65ade42005-08-05 00:37:45 -0400507 /* 'sleep' [R/W] */
Len Brown4be44fc2005-08-05 00:44:28 -0400508 entry =
509 create_proc_entry("sleep", S_IFREG | S_IRUGO | S_IWUSR,
510 acpi_root_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 if (entry)
512 entry->proc_fops = &acpi_system_sleep_fops;
Len Brown43532c82007-07-24 02:16:50 -0400513#endif /* CONFIG_ACPI_PROCFS */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514
David Brownellf5f72b42007-05-08 00:34:02 -0700515#ifdef HAVE_ACPI_LEGACY_ALARM
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 /* 'alarm' [R/W] */
Len Brown4be44fc2005-08-05 00:44:28 -0400517 entry =
518 create_proc_entry("alarm", S_IFREG | S_IRUGO | S_IWUSR,
519 acpi_root_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 if (entry)
521 entry->proc_fops = &acpi_system_alarm_fops;
522
David Brownellf5f72b42007-05-08 00:34:02 -0700523 acpi_install_fixed_event_handler(ACPI_EVENT_RTC, rtc_handler, NULL);
Len Brownfd350942007-05-09 23:34:35 -0400524#endif /* HAVE_ACPI_LEGACY_ALARM */
David Brownellf5f72b42007-05-08 00:34:02 -0700525
Pavel Machekc65ade42005-08-05 00:37:45 -0400526 /* 'wakeup device' [R/W] */
Len Brown4be44fc2005-08-05 00:44:28 -0400527 entry =
528 create_proc_entry("wakeup", S_IFREG | S_IRUGO | S_IWUSR,
529 acpi_root_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 if (entry)
531 entry->proc_fops = &acpi_system_wakeup_device_fops;
532
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 return 0;
534}
535
536late_initcall(acpi_sleep_proc_init);