blob: 52ce76725c2024bfea9bc20602ea239c0bc011ff [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#include <linux/proc_fs.h>
2#include <linux/seq_file.h>
Paul Gortmaker214f2c92011-10-26 16:22:14 -04003#include <linux/export.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07004#include <linux/suspend.h>
5#include <linux/bcd.h>
6#include <asm/uaccess.h>
7
8#include <acpi/acpi_bus.h>
9#include <acpi/acpi_drivers.h>
10
11#ifdef CONFIG_X86
12#include <linux/mc146818rtc.h>
13#endif
14
15#include "sleep.h"
16
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#define _COMPONENT ACPI_SYSTEM_COMPONENT
Len Brown43532c82007-07-24 02:16:50 -040018
19/*
20 * this file provides support for:
Len Brown43532c82007-07-24 02:16:50 -040021 * /proc/acpi/alarm
22 * /proc/acpi/wakeup
23 */
24
Len Brown4be44fc2005-08-05 00:44:28 -040025ACPI_MODULE_NAME("sleep")
Linus Torvalds1da177e2005-04-16 15:20:36 -070026
Len Brown673d5b42007-07-28 03:33:16 -040027#if defined(CONFIG_RTC_DRV_CMOS) || defined(CONFIG_RTC_DRV_CMOS_MODULE) || !defined(CONFIG_X86)
David Brownellf5f72b42007-05-08 00:34:02 -070028/* use /sys/class/rtc/rtcX/wakealarm instead; it's not ACPI-specific */
29#else
30#define HAVE_ACPI_LEGACY_ALARM
31#endif
32
33#ifdef HAVE_ACPI_LEGACY_ALARM
34
Len Brown2602a672009-01-09 02:10:16 -050035static u32 cmos_bcd_read(int offset, int rtc_control);
36
Linus Torvalds1da177e2005-04-16 15:20:36 -070037static int acpi_system_alarm_seq_show(struct seq_file *seq, void *offset)
38{
Len Brown4be44fc2005-08-05 00:44:28 -040039 u32 sec, min, hr;
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +030040 u32 day, mo, yr, cent = 0;
Mark Lord48452e52008-12-09 10:46:30 -050041 u32 today = 0;
Len Brown4be44fc2005-08-05 00:44:28 -040042 unsigned char rtc_control = 0;
43 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -070044
Linus Torvalds1da177e2005-04-16 15:20:36 -070045 spin_lock_irqsave(&rtc_lock, flags);
46
Linus Torvalds1da177e2005-04-16 15:20:36 -070047 rtc_control = CMOS_READ(RTC_CONTROL);
Mark Lord48452e52008-12-09 10:46:30 -050048 sec = cmos_bcd_read(RTC_SECONDS_ALARM, rtc_control);
49 min = cmos_bcd_read(RTC_MINUTES_ALARM, rtc_control);
50 hr = cmos_bcd_read(RTC_HOURS_ALARM, rtc_control);
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
52 /* If we ever get an FACP with proper values... */
Mark Lord48452e52008-12-09 10:46:30 -050053 if (acpi_gbl_FADT.day_alarm) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 /* ACPI spec: only low 6 its should be cared */
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +030055 day = CMOS_READ(acpi_gbl_FADT.day_alarm) & 0x3F;
Mark Lord48452e52008-12-09 10:46:30 -050056 if (!(rtc_control & RTC_DM_BINARY) || RTC_ALWAYS_BCD)
57 day = bcd2bin(day);
58 } else
59 day = cmos_bcd_read(RTC_DAY_OF_MONTH, rtc_control);
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +030060 if (acpi_gbl_FADT.month_alarm)
Mark Lord48452e52008-12-09 10:46:30 -050061 mo = cmos_bcd_read(acpi_gbl_FADT.month_alarm, rtc_control);
62 else {
63 mo = cmos_bcd_read(RTC_MONTH, rtc_control);
64 today = cmos_bcd_read(RTC_DAY_OF_MONTH, rtc_control);
65 }
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +030066 if (acpi_gbl_FADT.century)
Mark Lord48452e52008-12-09 10:46:30 -050067 cent = cmos_bcd_read(acpi_gbl_FADT.century, rtc_control);
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +030068
Mark Lord48452e52008-12-09 10:46:30 -050069 yr = cmos_bcd_read(RTC_YEAR, rtc_control);
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
71 spin_unlock_irqrestore(&rtc_lock, flags);
72
Len Brown4be44fc2005-08-05 00:44:28 -040073 /* we're trusting the FADT (see above) */
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +030074 if (!acpi_gbl_FADT.century)
Len Brown4be44fc2005-08-05 00:44:28 -040075 /* If we're not trusting the FADT, we should at least make it
76 * right for _this_ century... ehm, what is _this_ century?
77 *
78 * TBD:
79 * ASAP: find piece of code in the kernel, e.g. star tracker driver,
80 * which we can trust to determine the century correctly. Atom
81 * watch driver would be nice, too...
82 *
83 * if that has not happened, change for first release in 2050:
84 * if (yr<50)
85 * yr += 2100;
86 * else
87 * yr += 2000; // current line of code
88 *
89 * if that has not happened either, please do on 2099/12/31:23:59:59
90 * s/2000/2100
91 *
92 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 yr += 2000;
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +030094 else
95 yr += cent * 100;
Linus Torvalds1da177e2005-04-16 15:20:36 -070096
Mark Lord48452e52008-12-09 10:46:30 -050097 /*
98 * Show correct dates for alarms up to a month into the future.
99 * This solves issues for nearly all situations with the common
100 * 30-day alarm clocks in PC hardware.
101 */
102 if (day < today) {
103 if (mo < 12) {
104 mo += 1;
105 } else {
106 mo = 1;
107 yr += 1;
108 }
109 }
110
Len Brown4be44fc2005-08-05 00:44:28 -0400111 seq_printf(seq, "%4.4u-", yr);
112 (mo > 12) ? seq_puts(seq, "**-") : seq_printf(seq, "%2.2u-", mo);
113 (day > 31) ? seq_puts(seq, "** ") : seq_printf(seq, "%2.2u ", day);
114 (hr > 23) ? seq_puts(seq, "**:") : seq_printf(seq, "%2.2u:", hr);
115 (min > 59) ? seq_puts(seq, "**:") : seq_printf(seq, "%2.2u:", min);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 (sec > 59) ? seq_puts(seq, "**\n") : seq_printf(seq, "%2.2u\n", sec);
117
118 return 0;
119}
120
121static int acpi_system_alarm_open_fs(struct inode *inode, struct file *file)
122{
123 return single_open(file, acpi_system_alarm_seq_show, PDE(inode)->data);
124}
125
Len Brown4be44fc2005-08-05 00:44:28 -0400126static int get_date_field(char **p, u32 * value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127{
Len Brown4be44fc2005-08-05 00:44:28 -0400128 char *next = NULL;
129 char *string_end = NULL;
130 int result = -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131
132 /*
133 * Try to find delimeter, only to insert null. The end of the
134 * string won't have one, but is still valid.
135 */
Signed-off by Yi Yang975c3022007-12-27 21:50:42 -0500136 if (*p == NULL)
137 return result;
138
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 next = strpbrk(*p, "- :");
140 if (next)
141 *next++ = '\0';
142
143 *value = simple_strtoul(*p, &string_end, 10);
144
145 /* Signal success if we got a good digit */
146 if (string_end != *p)
147 result = 0;
148
149 if (next)
150 *p = next;
Signed-off by Yi Yang975c3022007-12-27 21:50:42 -0500151 else
152 *p = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153
154 return result;
155}
156
Linus Torvaldsc67c36e2007-10-17 23:18:32 -0400157/* Read a possibly BCD register, always return binary */
158static u32 cmos_bcd_read(int offset, int rtc_control)
159{
160 u32 val = CMOS_READ(offset);
161 if (!(rtc_control & RTC_DM_BINARY) || RTC_ALWAYS_BCD)
Adrian Bunkab527d72008-10-18 20:28:39 -0700162 val = bcd2bin(val);
Linus Torvaldsc67c36e2007-10-17 23:18:32 -0400163 return val;
164}
165
166/* Write binary value into possibly BCD register */
167static void cmos_bcd_write(u32 val, int offset, int rtc_control)
168{
169 if (!(rtc_control & RTC_DM_BINARY) || RTC_ALWAYS_BCD)
Adrian Bunkab527d72008-10-18 20:28:39 -0700170 val = bin2bcd(val);
Linus Torvaldsc67c36e2007-10-17 23:18:32 -0400171 CMOS_WRITE(val, offset);
172}
173
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -0400175acpi_system_write_alarm(struct file *file,
176 const char __user * buffer, size_t count, loff_t * ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177{
Len Brown4be44fc2005-08-05 00:44:28 -0400178 int result = 0;
179 char alarm_string[30] = { '\0' };
180 char *p = alarm_string;
181 u32 sec, min, hr, day, mo, yr;
182 int adjust = 0;
183 unsigned char rtc_control = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 if (count > sizeof(alarm_string) - 1)
Lin Ming95d9a7a2008-12-16 16:49:26 +0800186 return -EINVAL;
Len Brown4be44fc2005-08-05 00:44:28 -0400187
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188 if (copy_from_user(alarm_string, buffer, count))
Lin Ming95d9a7a2008-12-16 16:49:26 +0800189 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190
191 alarm_string[count] = '\0';
192
193 /* check for time adjustment */
194 if (alarm_string[0] == '+') {
195 p++;
196 adjust = 1;
197 }
198
199 if ((result = get_date_field(&p, &yr)))
200 goto end;
201 if ((result = get_date_field(&p, &mo)))
202 goto end;
203 if ((result = get_date_field(&p, &day)))
204 goto end;
205 if ((result = get_date_field(&p, &hr)))
206 goto end;
207 if ((result = get_date_field(&p, &min)))
208 goto end;
209 if ((result = get_date_field(&p, &sec)))
210 goto end;
211
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 spin_lock_irq(&rtc_lock);
213
214 rtc_control = CMOS_READ(RTC_CONTROL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215
216 if (adjust) {
Linus Torvaldsc67c36e2007-10-17 23:18:32 -0400217 yr += cmos_bcd_read(RTC_YEAR, rtc_control);
218 mo += cmos_bcd_read(RTC_MONTH, rtc_control);
219 day += cmos_bcd_read(RTC_DAY_OF_MONTH, rtc_control);
220 hr += cmos_bcd_read(RTC_HOURS, rtc_control);
221 min += cmos_bcd_read(RTC_MINUTES, rtc_control);
222 sec += cmos_bcd_read(RTC_SECONDS, rtc_control);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 }
224
225 spin_unlock_irq(&rtc_lock);
226
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 if (sec > 59) {
Yi Yang08798022007-12-27 22:04:26 -0500228 min += sec/60;
229 sec = sec%60;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 }
231 if (min > 59) {
Yi Yang08798022007-12-27 22:04:26 -0500232 hr += min/60;
233 min = min%60;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 }
235 if (hr > 23) {
Yi Yang08798022007-12-27 22:04:26 -0500236 day += hr/24;
237 hr = hr%24;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 }
239 if (day > 31) {
Yi Yang08798022007-12-27 22:04:26 -0500240 mo += day/32;
241 day = day%32;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 }
243 if (mo > 12) {
Yi Yang08798022007-12-27 22:04:26 -0500244 yr += mo/13;
245 mo = mo%13;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247
248 spin_lock_irq(&rtc_lock);
249 /*
250 * Disable alarm interrupt before setting alarm timer or else
251 * when ACPI_EVENT_RTC is enabled, a spurious ACPI interrupt occurs
252 */
253 rtc_control &= ~RTC_AIE;
254 CMOS_WRITE(rtc_control, RTC_CONTROL);
255 CMOS_READ(RTC_INTR_FLAGS);
256
257 /* write the fields the rtc knows about */
Linus Torvaldsc67c36e2007-10-17 23:18:32 -0400258 cmos_bcd_write(hr, RTC_HOURS_ALARM, rtc_control);
259 cmos_bcd_write(min, RTC_MINUTES_ALARM, rtc_control);
260 cmos_bcd_write(sec, RTC_SECONDS_ALARM, rtc_control);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261
262 /*
263 * If the system supports an enhanced alarm it will have non-zero
264 * offsets into the CMOS RAM here -- which for some reason are pointing
265 * to the RTC area of memory.
266 */
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +0300267 if (acpi_gbl_FADT.day_alarm)
Linus Torvaldsc67c36e2007-10-17 23:18:32 -0400268 cmos_bcd_write(day, acpi_gbl_FADT.day_alarm, rtc_control);
Alexey Starikovskiyad71860a2007-02-02 19:48:19 +0300269 if (acpi_gbl_FADT.month_alarm)
Linus Torvaldsc67c36e2007-10-17 23:18:32 -0400270 cmos_bcd_write(mo, acpi_gbl_FADT.month_alarm, rtc_control);
Huacai Chencce3ce82008-07-04 09:59:31 -0700271 if (acpi_gbl_FADT.century) {
272 if (adjust)
273 yr += cmos_bcd_read(acpi_gbl_FADT.century, rtc_control) * 100;
Linus Torvaldsc67c36e2007-10-17 23:18:32 -0400274 cmos_bcd_write(yr / 100, acpi_gbl_FADT.century, rtc_control);
Huacai Chencce3ce82008-07-04 09:59:31 -0700275 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 /* enable the rtc alarm interrupt */
277 rtc_control |= RTC_AIE;
278 CMOS_WRITE(rtc_control, RTC_CONTROL);
279 CMOS_READ(RTC_INTR_FLAGS);
280
281 spin_unlock_irq(&rtc_lock);
282
283 acpi_clear_event(ACPI_EVENT_RTC);
284 acpi_enable_event(ACPI_EVENT_RTC, 0);
285
286 *ppos += count;
287
288 result = 0;
Len Brown4be44fc2005-08-05 00:44:28 -0400289 end:
Lin Ming95d9a7a2008-12-16 16:49:26 +0800290 return result ? result : count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291}
Len Brownfd350942007-05-09 23:34:35 -0400292#endif /* HAVE_ACPI_LEGACY_ALARM */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294static int
295acpi_system_wakeup_device_seq_show(struct seq_file *seq, void *offset)
296{
Len Brown4be44fc2005-08-05 00:44:28 -0400297 struct list_head *node, *next;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298
David Brownell8aa55592007-04-25 15:20:10 -0400299 seq_printf(seq, "Device\tS-state\t Status Sysfs node\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300
Shaohua Li90905892009-04-07 10:24:29 +0800301 mutex_lock(&acpi_device_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
Len Brown4be44fc2005-08-05 00:44:28 -0400303 struct acpi_device *dev =
304 container_of(node, struct acpi_device, wakeup_list);
Lan Tianyu1033f902012-08-17 14:44:09 +0800305 struct acpi_device_physical_node *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306
307 if (!dev->wakeup.flags.valid)
308 continue;
David Brownell8aa55592007-04-25 15:20:10 -0400309
Lan Tianyu1033f902012-08-17 14:44:09 +0800310 seq_printf(seq, "%s\t S%d\t",
Len Brown4be44fc2005-08-05 00:44:28 -0400311 dev->pnp.bus_id,
Lan Tianyu1033f902012-08-17 14:44:09 +0800312 (u32) dev->wakeup.sleep_state);
David Brownell8aa55592007-04-25 15:20:10 -0400313
Andreas Fleig65ab96f2013-01-27 14:17:55 +0000314 if (!dev->physical_node_count) {
Lan Tianyu1033f902012-08-17 14:44:09 +0800315 seq_printf(seq, "%c%-8s\n",
Andreas Fleig65ab96f2013-01-27 14:17:55 +0000316 dev->wakeup.flags.run_wake ? '*' : ' ',
317 device_may_wakeup(&dev->dev) ?
318 "enabled" : "disabled");
319 } else {
Lan Tianyu1033f902012-08-17 14:44:09 +0800320 struct device *ldev;
321 list_for_each_entry(entry, &dev->physical_node_list,
322 node) {
323 ldev = get_device(entry->dev);
324 if (!ldev)
325 continue;
326
327 if (&entry->node !=
328 dev->physical_node_list.next)
329 seq_printf(seq, "\t\t");
330
331 seq_printf(seq, "%c%-8s %s:%s\n",
332 dev->wakeup.flags.run_wake ? '*' : ' ',
333 (device_may_wakeup(&dev->dev) ||
334 (ldev && device_may_wakeup(ldev))) ?
335 "enabled" : "disabled",
336 ldev->bus ? ldev->bus->name :
337 "no-bus", dev_name(ldev));
338 put_device(ldev);
339 }
340 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 }
Shaohua Li90905892009-04-07 10:24:29 +0800342 mutex_unlock(&acpi_device_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 return 0;
344}
345
Rafael J. Wysocki76acae02008-10-03 15:23:49 -0700346static void physical_device_enable_wakeup(struct acpi_device *adev)
347{
Lan Tianyu1033f902012-08-17 14:44:09 +0800348 struct acpi_device_physical_node *entry;
Rafael J. Wysocki76acae02008-10-03 15:23:49 -0700349
Lan Tianyu1033f902012-08-17 14:44:09 +0800350 list_for_each_entry(entry,
351 &adev->physical_node_list, node)
352 if (entry->dev && device_can_wakeup(entry->dev)) {
353 bool enable = !device_may_wakeup(entry->dev);
354 device_set_wakeup_enable(entry->dev, enable);
355 }
Rafael J. Wysocki76acae02008-10-03 15:23:49 -0700356}
357
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -0400359acpi_system_write_wakeup_device(struct file *file,
360 const char __user * buffer,
361 size_t count, loff_t * ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362{
Len Brown4be44fc2005-08-05 00:44:28 -0400363 struct list_head *node, *next;
364 char strbuf[5];
365 char str[5] = "";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366
Cyril Roelandt05bce792012-11-22 23:20:31 +0100367 if (count > 4)
368 count = 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369
Cyril Roelandt05bce792012-11-22 23:20:31 +0100370 if (copy_from_user(strbuf, buffer, count))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 return -EFAULT;
Cyril Roelandt05bce792012-11-22 23:20:31 +0100372 strbuf[count] = '\0';
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 sscanf(strbuf, "%s", str);
374
Shaohua Li90905892009-04-07 10:24:29 +0800375 mutex_lock(&acpi_device_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
Len Brown4be44fc2005-08-05 00:44:28 -0400377 struct acpi_device *dev =
378 container_of(node, struct acpi_device, wakeup_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 if (!dev->wakeup.flags.valid)
380 continue;
381
382 if (!strncmp(dev->pnp.bus_id, str, 4)) {
Rafael J. Wysockif2b56bc2011-01-06 23:34:22 +0100383 if (device_can_wakeup(&dev->dev)) {
384 bool enable = !device_may_wakeup(&dev->dev);
385 device_set_wakeup_enable(&dev->dev, enable);
386 } else {
387 physical_device_enable_wakeup(dev);
388 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 break;
390 }
391 }
Shaohua Li90905892009-04-07 10:24:29 +0800392 mutex_unlock(&acpi_device_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 return count;
394}
395
396static int
397acpi_system_wakeup_device_open_fs(struct inode *inode, struct file *file)
398{
Len Brown4be44fc2005-08-05 00:44:28 -0400399 return single_open(file, acpi_system_wakeup_device_seq_show,
400 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401}
402
Arjan van de Vend7508032006-07-04 13:06:00 -0400403static const struct file_operations acpi_system_wakeup_device_fops = {
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -0700404 .owner = THIS_MODULE,
Len Brown4be44fc2005-08-05 00:44:28 -0400405 .open = acpi_system_wakeup_device_open_fs,
406 .read = seq_read,
407 .write = acpi_system_write_wakeup_device,
408 .llseek = seq_lseek,
409 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410};
411
David Brownellf5f72b42007-05-08 00:34:02 -0700412#ifdef HAVE_ACPI_LEGACY_ALARM
Arjan van de Vend7508032006-07-04 13:06:00 -0400413static const struct file_operations acpi_system_alarm_fops = {
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -0700414 .owner = THIS_MODULE,
Len Brown4be44fc2005-08-05 00:44:28 -0400415 .open = acpi_system_alarm_open_fs,
416 .read = seq_read,
417 .write = acpi_system_write_alarm,
418 .llseek = seq_lseek,
419 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420};
421
Len Brown4be44fc2005-08-05 00:44:28 -0400422static u32 rtc_handler(void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423{
424 acpi_clear_event(ACPI_EVENT_RTC);
425 acpi_disable_event(ACPI_EVENT_RTC, 0);
426
427 return ACPI_INTERRUPT_HANDLED;
428}
Len Brownfd350942007-05-09 23:34:35 -0400429#endif /* HAVE_ACPI_LEGACY_ALARM */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430
Bjorn Helgaas9cee43e2009-03-24 16:50:14 -0600431int __init acpi_sleep_proc_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432{
David Brownellf5f72b42007-05-08 00:34:02 -0700433#ifdef HAVE_ACPI_LEGACY_ALARM
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 /* 'alarm' [R/W] */
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -0700435 proc_create("alarm", S_IFREG | S_IRUGO | S_IWUSR,
436 acpi_root_dir, &acpi_system_alarm_fops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437
David Brownellf5f72b42007-05-08 00:34:02 -0700438 acpi_install_fixed_event_handler(ACPI_EVENT_RTC, rtc_handler, NULL);
Zhao Yakuie1094bf2008-05-14 11:32:59 +0800439 /*
440 * Disable the RTC event after installing RTC handler.
441 * Only when RTC alarm is set will it be enabled.
442 */
443 acpi_clear_event(ACPI_EVENT_RTC);
444 acpi_disable_event(ACPI_EVENT_RTC, 0);
Len Brownfd350942007-05-09 23:34:35 -0400445#endif /* HAVE_ACPI_LEGACY_ALARM */
David Brownellf5f72b42007-05-08 00:34:02 -0700446
Pavel Machekc65ade42005-08-05 00:37:45 -0400447 /* 'wakeup device' [R/W] */
Denis V. Lunevcf7acfa2008-04-29 01:02:27 -0700448 proc_create("wakeup", S_IFREG | S_IRUGO | S_IWUSR,
449 acpi_root_dir, &acpi_system_wakeup_device_fops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 return 0;
452}