blob: 2d0e6b577502c482552bc81cf082df42cbfa0e1b [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
Len Brown2602a672009-01-09 02:10:16 -050089static u32 cmos_bcd_read(int offset, int rtc_control);
90
Linus Torvalds1da177e2005-04-16 15:20:36 -070091static int acpi_system_alarm_seq_show(struct seq_file *seq, void *offset)
92{
Len Brown4be44fc2005-08-05 00:44:28 -040093 u32 sec, min, hr;
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +030094 u32 day, mo, yr, cent = 0;
Mark Lord48452e52008-12-09 10:46:30 -050095 u32 today = 0;
Len Brown4be44fc2005-08-05 00:44:28 -040096 unsigned char rtc_control = 0;
97 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -070098
99 ACPI_FUNCTION_TRACE("acpi_system_alarm_seq_show");
100
101 spin_lock_irqsave(&rtc_lock, flags);
102
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 rtc_control = CMOS_READ(RTC_CONTROL);
Mark Lord48452e52008-12-09 10:46:30 -0500104 sec = cmos_bcd_read(RTC_SECONDS_ALARM, rtc_control);
105 min = cmos_bcd_read(RTC_MINUTES_ALARM, rtc_control);
106 hr = cmos_bcd_read(RTC_HOURS_ALARM, rtc_control);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107
108 /* If we ever get an FACP with proper values... */
Mark Lord48452e52008-12-09 10:46:30 -0500109 if (acpi_gbl_FADT.day_alarm) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 /* ACPI spec: only low 6 its should be cared */
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +0300111 day = CMOS_READ(acpi_gbl_FADT.day_alarm) & 0x3F;
Mark Lord48452e52008-12-09 10:46:30 -0500112 if (!(rtc_control & RTC_DM_BINARY) || RTC_ALWAYS_BCD)
113 day = bcd2bin(day);
114 } else
115 day = cmos_bcd_read(RTC_DAY_OF_MONTH, rtc_control);
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +0300116 if (acpi_gbl_FADT.month_alarm)
Mark Lord48452e52008-12-09 10:46:30 -0500117 mo = cmos_bcd_read(acpi_gbl_FADT.month_alarm, rtc_control);
118 else {
119 mo = cmos_bcd_read(RTC_MONTH, rtc_control);
120 today = cmos_bcd_read(RTC_DAY_OF_MONTH, rtc_control);
121 }
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +0300122 if (acpi_gbl_FADT.century)
Mark Lord48452e52008-12-09 10:46:30 -0500123 cent = cmos_bcd_read(acpi_gbl_FADT.century, rtc_control);
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +0300124
Mark Lord48452e52008-12-09 10:46:30 -0500125 yr = cmos_bcd_read(RTC_YEAR, rtc_control);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126
127 spin_unlock_irqrestore(&rtc_lock, flags);
128
Len Brown4be44fc2005-08-05 00:44:28 -0400129 /* we're trusting the FADT (see above) */
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +0300130 if (!acpi_gbl_FADT.century)
Len Brown4be44fc2005-08-05 00:44:28 -0400131 /* If we're not trusting the FADT, we should at least make it
132 * right for _this_ century... ehm, what is _this_ century?
133 *
134 * TBD:
135 * ASAP: find piece of code in the kernel, e.g. star tracker driver,
136 * which we can trust to determine the century correctly. Atom
137 * watch driver would be nice, too...
138 *
139 * if that has not happened, change for first release in 2050:
140 * if (yr<50)
141 * yr += 2100;
142 * else
143 * yr += 2000; // current line of code
144 *
145 * if that has not happened either, please do on 2099/12/31:23:59:59
146 * s/2000/2100
147 *
148 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 yr += 2000;
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +0300150 else
151 yr += cent * 100;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152
Mark Lord48452e52008-12-09 10:46:30 -0500153 /*
154 * Show correct dates for alarms up to a month into the future.
155 * This solves issues for nearly all situations with the common
156 * 30-day alarm clocks in PC hardware.
157 */
158 if (day < today) {
159 if (mo < 12) {
160 mo += 1;
161 } else {
162 mo = 1;
163 yr += 1;
164 }
165 }
166
Len Brown4be44fc2005-08-05 00:44:28 -0400167 seq_printf(seq, "%4.4u-", yr);
168 (mo > 12) ? seq_puts(seq, "**-") : seq_printf(seq, "%2.2u-", mo);
169 (day > 31) ? seq_puts(seq, "** ") : seq_printf(seq, "%2.2u ", day);
170 (hr > 23) ? seq_puts(seq, "**:") : seq_printf(seq, "%2.2u:", hr);
171 (min > 59) ? seq_puts(seq, "**:") : seq_printf(seq, "%2.2u:", min);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 (sec > 59) ? seq_puts(seq, "**\n") : seq_printf(seq, "%2.2u\n", sec);
173
174 return 0;
175}
176
177static int acpi_system_alarm_open_fs(struct inode *inode, struct file *file)
178{
179 return single_open(file, acpi_system_alarm_seq_show, PDE(inode)->data);
180}
181
Len Brown4be44fc2005-08-05 00:44:28 -0400182static int get_date_field(char **p, u32 * value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183{
Len Brown4be44fc2005-08-05 00:44:28 -0400184 char *next = NULL;
185 char *string_end = NULL;
186 int result = -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187
188 /*
189 * Try to find delimeter, only to insert null. The end of the
190 * string won't have one, but is still valid.
191 */
Signed-off by Yi Yang975c3022007-12-27 21:50:42 -0500192 if (*p == NULL)
193 return result;
194
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195 next = strpbrk(*p, "- :");
196 if (next)
197 *next++ = '\0';
198
199 *value = simple_strtoul(*p, &string_end, 10);
200
201 /* Signal success if we got a good digit */
202 if (string_end != *p)
203 result = 0;
204
205 if (next)
206 *p = next;
Signed-off by Yi Yang975c3022007-12-27 21:50:42 -0500207 else
208 *p = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209
210 return result;
211}
212
Linus Torvaldsc67c36e2007-10-17 23:18:32 -0400213/* Read a possibly BCD register, always return binary */
214static u32 cmos_bcd_read(int offset, int rtc_control)
215{
216 u32 val = CMOS_READ(offset);
217 if (!(rtc_control & RTC_DM_BINARY) || RTC_ALWAYS_BCD)
Adrian Bunkab527d72008-10-18 20:28:39 -0700218 val = bcd2bin(val);
Linus Torvaldsc67c36e2007-10-17 23:18:32 -0400219 return val;
220}
221
222/* Write binary value into possibly BCD register */
223static void cmos_bcd_write(u32 val, int offset, int rtc_control)
224{
225 if (!(rtc_control & RTC_DM_BINARY) || RTC_ALWAYS_BCD)
Adrian Bunkab527d72008-10-18 20:28:39 -0700226 val = bin2bcd(val);
Linus Torvaldsc67c36e2007-10-17 23:18:32 -0400227 CMOS_WRITE(val, offset);
228}
229
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -0400231acpi_system_write_alarm(struct file *file,
232 const char __user * buffer, size_t count, loff_t * ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233{
Len Brown4be44fc2005-08-05 00:44:28 -0400234 int result = 0;
235 char alarm_string[30] = { '\0' };
236 char *p = alarm_string;
237 u32 sec, min, hr, day, mo, yr;
238 int adjust = 0;
239 unsigned char rtc_control = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240
241 ACPI_FUNCTION_TRACE("acpi_system_write_alarm");
242
243 if (count > sizeof(alarm_string) - 1)
244 return_VALUE(-EINVAL);
Len Brown4be44fc2005-08-05 00:44:28 -0400245
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 if (copy_from_user(alarm_string, buffer, count))
247 return_VALUE(-EFAULT);
248
249 alarm_string[count] = '\0';
250
251 /* check for time adjustment */
252 if (alarm_string[0] == '+') {
253 p++;
254 adjust = 1;
255 }
256
257 if ((result = get_date_field(&p, &yr)))
258 goto end;
259 if ((result = get_date_field(&p, &mo)))
260 goto end;
261 if ((result = get_date_field(&p, &day)))
262 goto end;
263 if ((result = get_date_field(&p, &hr)))
264 goto end;
265 if ((result = get_date_field(&p, &min)))
266 goto end;
267 if ((result = get_date_field(&p, &sec)))
268 goto end;
269
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 spin_lock_irq(&rtc_lock);
271
272 rtc_control = CMOS_READ(RTC_CONTROL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273
274 if (adjust) {
Linus Torvaldsc67c36e2007-10-17 23:18:32 -0400275 yr += cmos_bcd_read(RTC_YEAR, rtc_control);
276 mo += cmos_bcd_read(RTC_MONTH, rtc_control);
277 day += cmos_bcd_read(RTC_DAY_OF_MONTH, rtc_control);
278 hr += cmos_bcd_read(RTC_HOURS, rtc_control);
279 min += cmos_bcd_read(RTC_MINUTES, rtc_control);
280 sec += cmos_bcd_read(RTC_SECONDS, rtc_control);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 }
282
283 spin_unlock_irq(&rtc_lock);
284
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 if (sec > 59) {
Yi Yang08798022007-12-27 22:04:26 -0500286 min += sec/60;
287 sec = sec%60;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 }
289 if (min > 59) {
Yi Yang08798022007-12-27 22:04:26 -0500290 hr += min/60;
291 min = min%60;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292 }
293 if (hr > 23) {
Yi Yang08798022007-12-27 22:04:26 -0500294 day += hr/24;
295 hr = hr%24;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 }
297 if (day > 31) {
Yi Yang08798022007-12-27 22:04:26 -0500298 mo += day/32;
299 day = day%32;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 }
301 if (mo > 12) {
Yi Yang08798022007-12-27 22:04:26 -0500302 yr += mo/13;
303 mo = mo%13;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305
306 spin_lock_irq(&rtc_lock);
307 /*
308 * Disable alarm interrupt before setting alarm timer or else
309 * when ACPI_EVENT_RTC is enabled, a spurious ACPI interrupt occurs
310 */
311 rtc_control &= ~RTC_AIE;
312 CMOS_WRITE(rtc_control, RTC_CONTROL);
313 CMOS_READ(RTC_INTR_FLAGS);
314
315 /* write the fields the rtc knows about */
Linus Torvaldsc67c36e2007-10-17 23:18:32 -0400316 cmos_bcd_write(hr, RTC_HOURS_ALARM, rtc_control);
317 cmos_bcd_write(min, RTC_MINUTES_ALARM, rtc_control);
318 cmos_bcd_write(sec, RTC_SECONDS_ALARM, rtc_control);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319
320 /*
321 * If the system supports an enhanced alarm it will have non-zero
322 * offsets into the CMOS RAM here -- which for some reason are pointing
323 * to the RTC area of memory.
324 */
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +0300325 if (acpi_gbl_FADT.day_alarm)
Linus Torvaldsc67c36e2007-10-17 23:18:32 -0400326 cmos_bcd_write(day, acpi_gbl_FADT.day_alarm, rtc_control);
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +0300327 if (acpi_gbl_FADT.month_alarm)
Linus Torvaldsc67c36e2007-10-17 23:18:32 -0400328 cmos_bcd_write(mo, acpi_gbl_FADT.month_alarm, rtc_control);
Huacai Chencce3ce82008-07-04 09:59:31 -0700329 if (acpi_gbl_FADT.century) {
330 if (adjust)
331 yr += cmos_bcd_read(acpi_gbl_FADT.century, rtc_control) * 100;
Linus Torvaldsc67c36e2007-10-17 23:18:32 -0400332 cmos_bcd_write(yr / 100, acpi_gbl_FADT.century, rtc_control);
Huacai Chencce3ce82008-07-04 09:59:31 -0700333 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334 /* enable the rtc alarm interrupt */
335 rtc_control |= RTC_AIE;
336 CMOS_WRITE(rtc_control, RTC_CONTROL);
337 CMOS_READ(RTC_INTR_FLAGS);
338
339 spin_unlock_irq(&rtc_lock);
340
341 acpi_clear_event(ACPI_EVENT_RTC);
342 acpi_enable_event(ACPI_EVENT_RTC, 0);
343
344 *ppos += count;
345
346 result = 0;
Len Brown4be44fc2005-08-05 00:44:28 -0400347 end:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 return_VALUE(result ? result : count);
349}
Len Brownfd350942007-05-09 23:34:35 -0400350#endif /* HAVE_ACPI_LEGACY_ALARM */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351
Len Brown4be44fc2005-08-05 00:44:28 -0400352extern struct list_head acpi_wakeup_device_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353extern spinlock_t acpi_device_lock;
354
355static int
356acpi_system_wakeup_device_seq_show(struct seq_file *seq, void *offset)
357{
Len Brown4be44fc2005-08-05 00:44:28 -0400358 struct list_head *node, *next;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359
David Brownell8aa55592007-04-25 15:20:10 -0400360 seq_printf(seq, "Device\tS-state\t Status Sysfs node\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361
362 spin_lock(&acpi_device_lock);
363 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
Len Brown4be44fc2005-08-05 00:44:28 -0400364 struct acpi_device *dev =
365 container_of(node, struct acpi_device, wakeup_list);
David Brownell8aa55592007-04-25 15:20:10 -0400366 struct device *ldev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367
368 if (!dev->wakeup.flags.valid)
369 continue;
370 spin_unlock(&acpi_device_lock);
David Brownell8aa55592007-04-25 15:20:10 -0400371
372 ldev = acpi_get_physical_device(dev->handle);
373 seq_printf(seq, "%s\t S%d\t%c%-8s ",
Len Brown4be44fc2005-08-05 00:44:28 -0400374 dev->pnp.bus_id,
375 (u32) dev->wakeup.sleep_state,
David Brownell8aa55592007-04-25 15:20:10 -0400376 dev->wakeup.flags.run_wake ? '*' : ' ',
Pavel Machekc65ade42005-08-05 00:37:45 -0400377 dev->wakeup.state.enabled ? "enabled" : "disabled");
David Brownell8aa55592007-04-25 15:20:10 -0400378 if (ldev)
379 seq_printf(seq, "%s:%s",
Linus Torvalds77fb61a2008-11-16 10:09:34 -0800380 ldev->bus ? ldev->bus->name : "no-bus",
Kay Sievers07944692008-10-30 01:18:59 +0100381 dev_name(ldev));
David Brownell8aa55592007-04-25 15:20:10 -0400382 seq_printf(seq, "\n");
383 put_device(ldev);
384
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385 spin_lock(&acpi_device_lock);
386 }
387 spin_unlock(&acpi_device_lock);
388 return 0;
389}
390
Rafael J. Wysocki76acae02008-10-03 15:23:49 -0700391static void physical_device_enable_wakeup(struct acpi_device *adev)
392{
393 struct device *dev = acpi_get_physical_device(adev->handle);
394
395 if (dev && device_can_wakeup(dev))
396 device_set_wakeup_enable(dev, adev->wakeup.state.enabled);
397}
398
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -0400400acpi_system_write_wakeup_device(struct file *file,
401 const char __user * buffer,
402 size_t count, loff_t * ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403{
Len Brown4be44fc2005-08-05 00:44:28 -0400404 struct list_head *node, *next;
405 char strbuf[5];
406 char str[5] = "";
407 int len = count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 struct acpi_device *found_dev = NULL;
409
Len Brown4be44fc2005-08-05 00:44:28 -0400410 if (len > 4)
411 len = 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412
413 if (copy_from_user(strbuf, buffer, len))
414 return -EFAULT;
415 strbuf[len] = '\0';
416 sscanf(strbuf, "%s", str);
417
418 spin_lock(&acpi_device_lock);
419 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
Len Brown4be44fc2005-08-05 00:44:28 -0400420 struct acpi_device *dev =
421 container_of(node, struct acpi_device, wakeup_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 if (!dev->wakeup.flags.valid)
423 continue;
424
425 if (!strncmp(dev->pnp.bus_id, str, 4)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400426 dev->wakeup.state.enabled =
427 dev->wakeup.state.enabled ? 0 : 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 found_dev = dev;
429 break;
430 }
431 }
432 if (found_dev) {
Rafael J. Wysocki76acae02008-10-03 15:23:49 -0700433 physical_device_enable_wakeup(found_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
Len Brown4be44fc2005-08-05 00:44:28 -0400435 struct acpi_device *dev = container_of(node,
436 struct
437 acpi_device,
438 wakeup_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439
440 if ((dev != found_dev) &&
Len Brown4be44fc2005-08-05 00:44:28 -0400441 (dev->wakeup.gpe_number ==
442 found_dev->wakeup.gpe_number)
443 && (dev->wakeup.gpe_device ==
444 found_dev->wakeup.gpe_device)) {
445 printk(KERN_WARNING
446 "ACPI: '%s' and '%s' have the same GPE, "
447 "can't disable/enable one seperately\n",
448 dev->pnp.bus_id, found_dev->pnp.bus_id);
449 dev->wakeup.state.enabled =
450 found_dev->wakeup.state.enabled;
Rafael J. Wysocki76acae02008-10-03 15:23:49 -0700451 physical_device_enable_wakeup(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 }
453 }
454 }
455 spin_unlock(&acpi_device_lock);
456 return count;
457}
458
459static int
460acpi_system_wakeup_device_open_fs(struct inode *inode, struct file *file)
461{
Len Brown4be44fc2005-08-05 00:44:28 -0400462 return single_open(file, acpi_system_wakeup_device_seq_show,
463 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464}
465
Arjan van de Vend7508032006-07-04 13:06:00 -0400466static const struct file_operations acpi_system_wakeup_device_fops = {
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -0700467 .owner = THIS_MODULE,
Len Brown4be44fc2005-08-05 00:44:28 -0400468 .open = acpi_system_wakeup_device_open_fs,
469 .read = seq_read,
470 .write = acpi_system_write_wakeup_device,
471 .llseek = seq_lseek,
472 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473};
474
Christian Borntraeger134c2172007-08-28 14:58:56 -0400475#ifdef CONFIG_ACPI_PROCFS
Arjan van de Vend7508032006-07-04 13:06:00 -0400476static const struct file_operations acpi_system_sleep_fops = {
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -0700477 .owner = THIS_MODULE,
Len Brown4be44fc2005-08-05 00:44:28 -0400478 .open = acpi_system_sleep_open_fs,
479 .read = seq_read,
480 .write = acpi_system_write_sleep,
481 .llseek = seq_lseek,
482 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483};
Christian Borntraeger134c2172007-08-28 14:58:56 -0400484#endif /* CONFIG_ACPI_PROCFS */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485
David Brownellf5f72b42007-05-08 00:34:02 -0700486#ifdef HAVE_ACPI_LEGACY_ALARM
Arjan van de Vend7508032006-07-04 13:06:00 -0400487static const struct file_operations acpi_system_alarm_fops = {
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -0700488 .owner = THIS_MODULE,
Len Brown4be44fc2005-08-05 00:44:28 -0400489 .open = acpi_system_alarm_open_fs,
490 .read = seq_read,
491 .write = acpi_system_write_alarm,
492 .llseek = seq_lseek,
493 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494};
495
Len Brown4be44fc2005-08-05 00:44:28 -0400496static u32 rtc_handler(void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497{
498 acpi_clear_event(ACPI_EVENT_RTC);
499 acpi_disable_event(ACPI_EVENT_RTC, 0);
500
501 return ACPI_INTERRUPT_HANDLED;
502}
Len Brownfd350942007-05-09 23:34:35 -0400503#endif /* HAVE_ACPI_LEGACY_ALARM */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504
David Brownellf5f72b42007-05-08 00:34:02 -0700505static int __init acpi_sleep_proc_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 if (acpi_disabled)
508 return 0;
Len Brown4be44fc2005-08-05 00:44:28 -0400509
Christian Borntraeger134c2172007-08-28 14:58:56 -0400510#ifdef CONFIG_ACPI_PROCFS
Pavel Machekc65ade42005-08-05 00:37:45 -0400511 /* 'sleep' [R/W] */
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -0700512 proc_create("sleep", S_IFREG | S_IRUGO | S_IWUSR,
513 acpi_root_dir, &acpi_system_sleep_fops);
Len Brown43532c82007-07-24 02:16:50 -0400514#endif /* CONFIG_ACPI_PROCFS */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515
David Brownellf5f72b42007-05-08 00:34:02 -0700516#ifdef HAVE_ACPI_LEGACY_ALARM
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 /* 'alarm' [R/W] */
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -0700518 proc_create("alarm", S_IFREG | S_IRUGO | S_IWUSR,
519 acpi_root_dir, &acpi_system_alarm_fops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520
David Brownellf5f72b42007-05-08 00:34:02 -0700521 acpi_install_fixed_event_handler(ACPI_EVENT_RTC, rtc_handler, NULL);
Zhao Yakuie1094bf2008-05-14 11:32:59 +0800522 /*
523 * Disable the RTC event after installing RTC handler.
524 * Only when RTC alarm is set will it be enabled.
525 */
526 acpi_clear_event(ACPI_EVENT_RTC);
527 acpi_disable_event(ACPI_EVENT_RTC, 0);
Len Brownfd350942007-05-09 23:34:35 -0400528#endif /* HAVE_ACPI_LEGACY_ALARM */
David Brownellf5f72b42007-05-08 00:34:02 -0700529
Pavel Machekc65ade42005-08-05 00:37:45 -0400530 /* 'wakeup device' [R/W] */
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -0700531 proc_create("wakeup", S_IFREG | S_IRUGO | S_IWUSR,
532 acpi_root_dir, &acpi_system_wakeup_device_fops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 return 0;
535}
536
537late_initcall(acpi_sleep_proc_init);