blob: d0d550d22a6d43a14ccecec6658e9fb2773d6b70 [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
Len Brown2602a672009-01-09 02:10:16 -050087static u32 cmos_bcd_read(int offset, int rtc_control);
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;
Mark Lord48452e52008-12-09 10:46:30 -050093 u32 today = 0;
Len Brown4be44fc2005-08-05 00:44:28 -040094 unsigned char rtc_control = 0;
95 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -070096
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 spin_lock_irqsave(&rtc_lock, flags);
98
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 rtc_control = CMOS_READ(RTC_CONTROL);
Mark Lord48452e52008-12-09 10:46:30 -0500100 sec = cmos_bcd_read(RTC_SECONDS_ALARM, rtc_control);
101 min = cmos_bcd_read(RTC_MINUTES_ALARM, rtc_control);
102 hr = cmos_bcd_read(RTC_HOURS_ALARM, rtc_control);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103
104 /* If we ever get an FACP with proper values... */
Mark Lord48452e52008-12-09 10:46:30 -0500105 if (acpi_gbl_FADT.day_alarm) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 /* ACPI spec: only low 6 its should be cared */
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +0300107 day = CMOS_READ(acpi_gbl_FADT.day_alarm) & 0x3F;
Mark Lord48452e52008-12-09 10:46:30 -0500108 if (!(rtc_control & RTC_DM_BINARY) || RTC_ALWAYS_BCD)
109 day = bcd2bin(day);
110 } else
111 day = cmos_bcd_read(RTC_DAY_OF_MONTH, rtc_control);
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +0300112 if (acpi_gbl_FADT.month_alarm)
Mark Lord48452e52008-12-09 10:46:30 -0500113 mo = cmos_bcd_read(acpi_gbl_FADT.month_alarm, rtc_control);
114 else {
115 mo = cmos_bcd_read(RTC_MONTH, rtc_control);
116 today = cmos_bcd_read(RTC_DAY_OF_MONTH, rtc_control);
117 }
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +0300118 if (acpi_gbl_FADT.century)
Mark Lord48452e52008-12-09 10:46:30 -0500119 cent = cmos_bcd_read(acpi_gbl_FADT.century, rtc_control);
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +0300120
Mark Lord48452e52008-12-09 10:46:30 -0500121 yr = cmos_bcd_read(RTC_YEAR, rtc_control);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122
123 spin_unlock_irqrestore(&rtc_lock, flags);
124
Len Brown4be44fc2005-08-05 00:44:28 -0400125 /* we're trusting the FADT (see above) */
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +0300126 if (!acpi_gbl_FADT.century)
Len Brown4be44fc2005-08-05 00:44:28 -0400127 /* If we're not trusting the FADT, we should at least make it
128 * right for _this_ century... ehm, what is _this_ century?
129 *
130 * TBD:
131 * ASAP: find piece of code in the kernel, e.g. star tracker driver,
132 * which we can trust to determine the century correctly. Atom
133 * watch driver would be nice, too...
134 *
135 * if that has not happened, change for first release in 2050:
136 * if (yr<50)
137 * yr += 2100;
138 * else
139 * yr += 2000; // current line of code
140 *
141 * if that has not happened either, please do on 2099/12/31:23:59:59
142 * s/2000/2100
143 *
144 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 yr += 2000;
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +0300146 else
147 yr += cent * 100;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148
Mark Lord48452e52008-12-09 10:46:30 -0500149 /*
150 * Show correct dates for alarms up to a month into the future.
151 * This solves issues for nearly all situations with the common
152 * 30-day alarm clocks in PC hardware.
153 */
154 if (day < today) {
155 if (mo < 12) {
156 mo += 1;
157 } else {
158 mo = 1;
159 yr += 1;
160 }
161 }
162
Len Brown4be44fc2005-08-05 00:44:28 -0400163 seq_printf(seq, "%4.4u-", yr);
164 (mo > 12) ? seq_puts(seq, "**-") : seq_printf(seq, "%2.2u-", mo);
165 (day > 31) ? seq_puts(seq, "** ") : seq_printf(seq, "%2.2u ", day);
166 (hr > 23) ? seq_puts(seq, "**:") : seq_printf(seq, "%2.2u:", hr);
167 (min > 59) ? seq_puts(seq, "**:") : seq_printf(seq, "%2.2u:", min);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 (sec > 59) ? seq_puts(seq, "**\n") : seq_printf(seq, "%2.2u\n", sec);
169
170 return 0;
171}
172
173static int acpi_system_alarm_open_fs(struct inode *inode, struct file *file)
174{
175 return single_open(file, acpi_system_alarm_seq_show, PDE(inode)->data);
176}
177
Len Brown4be44fc2005-08-05 00:44:28 -0400178static int get_date_field(char **p, u32 * value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179{
Len Brown4be44fc2005-08-05 00:44:28 -0400180 char *next = NULL;
181 char *string_end = NULL;
182 int result = -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183
184 /*
185 * Try to find delimeter, only to insert null. The end of the
186 * string won't have one, but is still valid.
187 */
Signed-off by Yi Yang975c3022007-12-27 21:50:42 -0500188 if (*p == NULL)
189 return result;
190
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191 next = strpbrk(*p, "- :");
192 if (next)
193 *next++ = '\0';
194
195 *value = simple_strtoul(*p, &string_end, 10);
196
197 /* Signal success if we got a good digit */
198 if (string_end != *p)
199 result = 0;
200
201 if (next)
202 *p = next;
Signed-off by Yi Yang975c3022007-12-27 21:50:42 -0500203 else
204 *p = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205
206 return result;
207}
208
Linus Torvaldsc67c36e2007-10-17 23:18:32 -0400209/* Read a possibly BCD register, always return binary */
210static u32 cmos_bcd_read(int offset, int rtc_control)
211{
212 u32 val = CMOS_READ(offset);
213 if (!(rtc_control & RTC_DM_BINARY) || RTC_ALWAYS_BCD)
Adrian Bunkab527d72008-10-18 20:28:39 -0700214 val = bcd2bin(val);
Linus Torvaldsc67c36e2007-10-17 23:18:32 -0400215 return val;
216}
217
218/* Write binary value into possibly BCD register */
219static void cmos_bcd_write(u32 val, int offset, int rtc_control)
220{
221 if (!(rtc_control & RTC_DM_BINARY) || RTC_ALWAYS_BCD)
Adrian Bunkab527d72008-10-18 20:28:39 -0700222 val = bin2bcd(val);
Linus Torvaldsc67c36e2007-10-17 23:18:32 -0400223 CMOS_WRITE(val, offset);
224}
225
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -0400227acpi_system_write_alarm(struct file *file,
228 const char __user * buffer, size_t count, loff_t * ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229{
Len Brown4be44fc2005-08-05 00:44:28 -0400230 int result = 0;
231 char alarm_string[30] = { '\0' };
232 char *p = alarm_string;
233 u32 sec, min, hr, day, mo, yr;
234 int adjust = 0;
235 unsigned char rtc_control = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 if (count > sizeof(alarm_string) - 1)
Lin Ming95d9a7a2008-12-16 16:49:26 +0800238 return -EINVAL;
Len Brown4be44fc2005-08-05 00:44:28 -0400239
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 if (copy_from_user(alarm_string, buffer, count))
Lin Ming95d9a7a2008-12-16 16:49:26 +0800241 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242
243 alarm_string[count] = '\0';
244
245 /* check for time adjustment */
246 if (alarm_string[0] == '+') {
247 p++;
248 adjust = 1;
249 }
250
251 if ((result = get_date_field(&p, &yr)))
252 goto end;
253 if ((result = get_date_field(&p, &mo)))
254 goto end;
255 if ((result = get_date_field(&p, &day)))
256 goto end;
257 if ((result = get_date_field(&p, &hr)))
258 goto end;
259 if ((result = get_date_field(&p, &min)))
260 goto end;
261 if ((result = get_date_field(&p, &sec)))
262 goto end;
263
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 spin_lock_irq(&rtc_lock);
265
266 rtc_control = CMOS_READ(RTC_CONTROL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267
268 if (adjust) {
Linus Torvaldsc67c36e2007-10-17 23:18:32 -0400269 yr += cmos_bcd_read(RTC_YEAR, rtc_control);
270 mo += cmos_bcd_read(RTC_MONTH, rtc_control);
271 day += cmos_bcd_read(RTC_DAY_OF_MONTH, rtc_control);
272 hr += cmos_bcd_read(RTC_HOURS, rtc_control);
273 min += cmos_bcd_read(RTC_MINUTES, rtc_control);
274 sec += cmos_bcd_read(RTC_SECONDS, rtc_control);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 }
276
277 spin_unlock_irq(&rtc_lock);
278
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 if (sec > 59) {
Yi Yang08798022007-12-27 22:04:26 -0500280 min += sec/60;
281 sec = sec%60;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 }
283 if (min > 59) {
Yi Yang08798022007-12-27 22:04:26 -0500284 hr += min/60;
285 min = min%60;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 }
287 if (hr > 23) {
Yi Yang08798022007-12-27 22:04:26 -0500288 day += hr/24;
289 hr = hr%24;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 }
291 if (day > 31) {
Yi Yang08798022007-12-27 22:04:26 -0500292 mo += day/32;
293 day = day%32;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 }
295 if (mo > 12) {
Yi Yang08798022007-12-27 22:04:26 -0500296 yr += mo/13;
297 mo = mo%13;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299
300 spin_lock_irq(&rtc_lock);
301 /*
302 * Disable alarm interrupt before setting alarm timer or else
303 * when ACPI_EVENT_RTC is enabled, a spurious ACPI interrupt occurs
304 */
305 rtc_control &= ~RTC_AIE;
306 CMOS_WRITE(rtc_control, RTC_CONTROL);
307 CMOS_READ(RTC_INTR_FLAGS);
308
309 /* write the fields the rtc knows about */
Linus Torvaldsc67c36e2007-10-17 23:18:32 -0400310 cmos_bcd_write(hr, RTC_HOURS_ALARM, rtc_control);
311 cmos_bcd_write(min, RTC_MINUTES_ALARM, rtc_control);
312 cmos_bcd_write(sec, RTC_SECONDS_ALARM, rtc_control);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313
314 /*
315 * If the system supports an enhanced alarm it will have non-zero
316 * offsets into the CMOS RAM here -- which for some reason are pointing
317 * to the RTC area of memory.
318 */
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +0300319 if (acpi_gbl_FADT.day_alarm)
Linus Torvaldsc67c36e2007-10-17 23:18:32 -0400320 cmos_bcd_write(day, acpi_gbl_FADT.day_alarm, rtc_control);
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +0300321 if (acpi_gbl_FADT.month_alarm)
Linus Torvaldsc67c36e2007-10-17 23:18:32 -0400322 cmos_bcd_write(mo, acpi_gbl_FADT.month_alarm, rtc_control);
Huacai Chencce3ce82008-07-04 09:59:31 -0700323 if (acpi_gbl_FADT.century) {
324 if (adjust)
325 yr += cmos_bcd_read(acpi_gbl_FADT.century, rtc_control) * 100;
Linus Torvaldsc67c36e2007-10-17 23:18:32 -0400326 cmos_bcd_write(yr / 100, acpi_gbl_FADT.century, rtc_control);
Huacai Chencce3ce82008-07-04 09:59:31 -0700327 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 /* enable the rtc alarm interrupt */
329 rtc_control |= RTC_AIE;
330 CMOS_WRITE(rtc_control, RTC_CONTROL);
331 CMOS_READ(RTC_INTR_FLAGS);
332
333 spin_unlock_irq(&rtc_lock);
334
335 acpi_clear_event(ACPI_EVENT_RTC);
336 acpi_enable_event(ACPI_EVENT_RTC, 0);
337
338 *ppos += count;
339
340 result = 0;
Len Brown4be44fc2005-08-05 00:44:28 -0400341 end:
Lin Ming95d9a7a2008-12-16 16:49:26 +0800342 return result ? result : count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343}
Len Brownfd350942007-05-09 23:34:35 -0400344#endif /* HAVE_ACPI_LEGACY_ALARM */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346static int
347acpi_system_wakeup_device_seq_show(struct seq_file *seq, void *offset)
348{
Len Brown4be44fc2005-08-05 00:44:28 -0400349 struct list_head *node, *next;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350
David Brownell8aa55592007-04-25 15:20:10 -0400351 seq_printf(seq, "Device\tS-state\t Status Sysfs node\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352
Shaohua Li90905892009-04-07 10:24:29 +0800353 mutex_lock(&acpi_device_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
Len Brown4be44fc2005-08-05 00:44:28 -0400355 struct acpi_device *dev =
356 container_of(node, struct acpi_device, wakeup_list);
David Brownell8aa55592007-04-25 15:20:10 -0400357 struct device *ldev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358
359 if (!dev->wakeup.flags.valid)
360 continue;
David Brownell8aa55592007-04-25 15:20:10 -0400361
362 ldev = acpi_get_physical_device(dev->handle);
363 seq_printf(seq, "%s\t S%d\t%c%-8s ",
Len Brown4be44fc2005-08-05 00:44:28 -0400364 dev->pnp.bus_id,
365 (u32) dev->wakeup.sleep_state,
David Brownell8aa55592007-04-25 15:20:10 -0400366 dev->wakeup.flags.run_wake ? '*' : ' ',
Pavel Machekc65ade42005-08-05 00:37:45 -0400367 dev->wakeup.state.enabled ? "enabled" : "disabled");
David Brownell8aa55592007-04-25 15:20:10 -0400368 if (ldev)
369 seq_printf(seq, "%s:%s",
Linus Torvalds77fb61a2008-11-16 10:09:34 -0800370 ldev->bus ? ldev->bus->name : "no-bus",
Kay Sievers07944692008-10-30 01:18:59 +0100371 dev_name(ldev));
David Brownell8aa55592007-04-25 15:20:10 -0400372 seq_printf(seq, "\n");
373 put_device(ldev);
374
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375 }
Shaohua Li90905892009-04-07 10:24:29 +0800376 mutex_unlock(&acpi_device_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 return 0;
378}
379
Rafael J. Wysocki76acae02008-10-03 15:23:49 -0700380static void physical_device_enable_wakeup(struct acpi_device *adev)
381{
382 struct device *dev = acpi_get_physical_device(adev->handle);
383
384 if (dev && device_can_wakeup(dev))
385 device_set_wakeup_enable(dev, adev->wakeup.state.enabled);
386}
387
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -0400389acpi_system_write_wakeup_device(struct file *file,
390 const char __user * buffer,
391 size_t count, loff_t * ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392{
Len Brown4be44fc2005-08-05 00:44:28 -0400393 struct list_head *node, *next;
394 char strbuf[5];
395 char str[5] = "";
396 int len = count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 struct acpi_device *found_dev = NULL;
398
Len Brown4be44fc2005-08-05 00:44:28 -0400399 if (len > 4)
400 len = 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401
402 if (copy_from_user(strbuf, buffer, len))
403 return -EFAULT;
404 strbuf[len] = '\0';
405 sscanf(strbuf, "%s", str);
406
Shaohua Li90905892009-04-07 10:24:29 +0800407 mutex_lock(&acpi_device_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
Len Brown4be44fc2005-08-05 00:44:28 -0400409 struct acpi_device *dev =
410 container_of(node, struct acpi_device, wakeup_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 if (!dev->wakeup.flags.valid)
412 continue;
413
414 if (!strncmp(dev->pnp.bus_id, str, 4)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400415 dev->wakeup.state.enabled =
416 dev->wakeup.state.enabled ? 0 : 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 found_dev = dev;
418 break;
419 }
420 }
421 if (found_dev) {
Rafael J. Wysocki76acae02008-10-03 15:23:49 -0700422 physical_device_enable_wakeup(found_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
Len Brown4be44fc2005-08-05 00:44:28 -0400424 struct acpi_device *dev = container_of(node,
425 struct
426 acpi_device,
427 wakeup_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428
429 if ((dev != found_dev) &&
Len Brown4be44fc2005-08-05 00:44:28 -0400430 (dev->wakeup.gpe_number ==
431 found_dev->wakeup.gpe_number)
432 && (dev->wakeup.gpe_device ==
433 found_dev->wakeup.gpe_device)) {
434 printk(KERN_WARNING
435 "ACPI: '%s' and '%s' have the same GPE, "
436 "can't disable/enable one seperately\n",
437 dev->pnp.bus_id, found_dev->pnp.bus_id);
438 dev->wakeup.state.enabled =
439 found_dev->wakeup.state.enabled;
Rafael J. Wysocki76acae02008-10-03 15:23:49 -0700440 physical_device_enable_wakeup(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441 }
442 }
443 }
Shaohua Li90905892009-04-07 10:24:29 +0800444 mutex_unlock(&acpi_device_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445 return count;
446}
447
448static int
449acpi_system_wakeup_device_open_fs(struct inode *inode, struct file *file)
450{
Len Brown4be44fc2005-08-05 00:44:28 -0400451 return single_open(file, acpi_system_wakeup_device_seq_show,
452 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453}
454
Arjan van de Vend7508032006-07-04 13:06:00 -0400455static const struct file_operations acpi_system_wakeup_device_fops = {
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -0700456 .owner = THIS_MODULE,
Len Brown4be44fc2005-08-05 00:44:28 -0400457 .open = acpi_system_wakeup_device_open_fs,
458 .read = seq_read,
459 .write = acpi_system_write_wakeup_device,
460 .llseek = seq_lseek,
461 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462};
463
Christian Borntraeger134c2172007-08-28 14:58:56 -0400464#ifdef CONFIG_ACPI_PROCFS
Arjan van de Vend7508032006-07-04 13:06:00 -0400465static const struct file_operations acpi_system_sleep_fops = {
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -0700466 .owner = THIS_MODULE,
Len Brown4be44fc2005-08-05 00:44:28 -0400467 .open = acpi_system_sleep_open_fs,
468 .read = seq_read,
469 .write = acpi_system_write_sleep,
470 .llseek = seq_lseek,
471 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472};
Christian Borntraeger134c2172007-08-28 14:58:56 -0400473#endif /* CONFIG_ACPI_PROCFS */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474
David Brownellf5f72b42007-05-08 00:34:02 -0700475#ifdef HAVE_ACPI_LEGACY_ALARM
Arjan van de Vend7508032006-07-04 13:06:00 -0400476static const struct file_operations acpi_system_alarm_fops = {
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -0700477 .owner = THIS_MODULE,
Len Brown4be44fc2005-08-05 00:44:28 -0400478 .open = acpi_system_alarm_open_fs,
479 .read = seq_read,
480 .write = acpi_system_write_alarm,
481 .llseek = seq_lseek,
482 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483};
484
Len Brown4be44fc2005-08-05 00:44:28 -0400485static u32 rtc_handler(void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486{
487 acpi_clear_event(ACPI_EVENT_RTC);
488 acpi_disable_event(ACPI_EVENT_RTC, 0);
489
490 return ACPI_INTERRUPT_HANDLED;
491}
Len Brownfd350942007-05-09 23:34:35 -0400492#endif /* HAVE_ACPI_LEGACY_ALARM */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493
Bjorn Helgaas9cee43e2009-03-24 16:50:14 -0600494int __init acpi_sleep_proc_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495{
Christian Borntraeger134c2172007-08-28 14:58:56 -0400496#ifdef CONFIG_ACPI_PROCFS
Pavel Machekc65ade42005-08-05 00:37:45 -0400497 /* 'sleep' [R/W] */
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -0700498 proc_create("sleep", S_IFREG | S_IRUGO | S_IWUSR,
499 acpi_root_dir, &acpi_system_sleep_fops);
Len Brown43532c82007-07-24 02:16:50 -0400500#endif /* CONFIG_ACPI_PROCFS */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501
David Brownellf5f72b42007-05-08 00:34:02 -0700502#ifdef HAVE_ACPI_LEGACY_ALARM
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 /* 'alarm' [R/W] */
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -0700504 proc_create("alarm", S_IFREG | S_IRUGO | S_IWUSR,
505 acpi_root_dir, &acpi_system_alarm_fops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506
David Brownellf5f72b42007-05-08 00:34:02 -0700507 acpi_install_fixed_event_handler(ACPI_EVENT_RTC, rtc_handler, NULL);
Zhao Yakuie1094bf2008-05-14 11:32:59 +0800508 /*
509 * Disable the RTC event after installing RTC handler.
510 * Only when RTC alarm is set will it be enabled.
511 */
512 acpi_clear_event(ACPI_EVENT_RTC);
513 acpi_disable_event(ACPI_EVENT_RTC, 0);
Len Brownfd350942007-05-09 23:34:35 -0400514#endif /* HAVE_ACPI_LEGACY_ALARM */
David Brownellf5f72b42007-05-08 00:34:02 -0700515
Pavel Machekc65ade42005-08-05 00:37:45 -0400516 /* 'wakeup device' [R/W] */
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -0700517 proc_create("wakeup", S_IFREG | S_IRUGO | S_IWUSR,
518 acpi_root_dir, &acpi_system_wakeup_device_fops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 return 0;
521}