Blame view

drivers/acpi/proc.c 10.7 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
2
  #include <linux/proc_fs.h>
  #include <linux/seq_file.h>
214f2c90b   Paul Gortmaker   acpi: add export....
3
  #include <linux/export.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
4
5
6
7
8
9
10
11
12
13
14
15
  #include <linux/suspend.h>
  #include <linux/bcd.h>
  #include <asm/uaccess.h>
  
  #include <acpi/acpi_bus.h>
  #include <acpi/acpi_drivers.h>
  
  #ifdef CONFIG_X86
  #include <linux/mc146818rtc.h>
  #endif
  
  #include "sleep.h"
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
16
  #define _COMPONENT		ACPI_SYSTEM_COMPONENT
43532c8a4   Len Brown   ACPI: Kconfig: fo...
17
18
19
  
  /*
   * this file provides support for:
43532c8a4   Len Brown   ACPI: Kconfig: fo...
20
21
22
   * /proc/acpi/alarm
   * /proc/acpi/wakeup
   */
4be44fcd3   Len Brown   [ACPI] Lindent al...
23
  ACPI_MODULE_NAME("sleep")
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
24

673d5b43d   Len Brown   ACPI: restore CON...
25
  #if defined(CONFIG_RTC_DRV_CMOS) || defined(CONFIG_RTC_DRV_CMOS_MODULE) || !defined(CONFIG_X86)
f5f72b46c   David Brownell   ACPI wakeup hooks...
26
27
28
29
30
31
  /* use /sys/class/rtc/rtcX/wakealarm instead; it's not ACPI-specific */
  #else
  #define	HAVE_ACPI_LEGACY_ALARM
  #endif
  
  #ifdef	HAVE_ACPI_LEGACY_ALARM
2602a671a   Len Brown   ACPI: fix build w...
32
  static u32 cmos_bcd_read(int offset, int rtc_control);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
33
34
  static int acpi_system_alarm_seq_show(struct seq_file *seq, void *offset)
  {
4be44fcd3   Len Brown   [ACPI] Lindent al...
35
  	u32 sec, min, hr;
ad71860a1   Alexey Starikovskiy   ACPICA: minimal p...
36
  	u32 day, mo, yr, cent = 0;
48452e5f9   Mark Lord   /proc/acpi/alarm:...
37
  	u32 today = 0;
4be44fcd3   Len Brown   [ACPI] Lindent al...
38
39
  	unsigned char rtc_control = 0;
  	unsigned long flags;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
40

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
41
  	spin_lock_irqsave(&rtc_lock, flags);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
42
  	rtc_control = CMOS_READ(RTC_CONTROL);
48452e5f9   Mark Lord   /proc/acpi/alarm:...
43
44
45
  	sec = cmos_bcd_read(RTC_SECONDS_ALARM, rtc_control);
  	min = cmos_bcd_read(RTC_MINUTES_ALARM, rtc_control);
  	hr = cmos_bcd_read(RTC_HOURS_ALARM, rtc_control);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
46
47
  
  	/* If we ever get an FACP with proper values... */
48452e5f9   Mark Lord   /proc/acpi/alarm:...
48
  	if (acpi_gbl_FADT.day_alarm) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
49
  		/* ACPI spec: only low 6 its should be cared */
ad71860a1   Alexey Starikovskiy   ACPICA: minimal p...
50
  		day = CMOS_READ(acpi_gbl_FADT.day_alarm) & 0x3F;
48452e5f9   Mark Lord   /proc/acpi/alarm:...
51
52
53
54
  		if (!(rtc_control & RTC_DM_BINARY) || RTC_ALWAYS_BCD)
  			day = bcd2bin(day);
  	} else
  		day = cmos_bcd_read(RTC_DAY_OF_MONTH, rtc_control);
ad71860a1   Alexey Starikovskiy   ACPICA: minimal p...
55
  	if (acpi_gbl_FADT.month_alarm)
48452e5f9   Mark Lord   /proc/acpi/alarm:...
56
57
58
59
60
  		mo = cmos_bcd_read(acpi_gbl_FADT.month_alarm, rtc_control);
  	else {
  		mo = cmos_bcd_read(RTC_MONTH, rtc_control);
  		today = cmos_bcd_read(RTC_DAY_OF_MONTH, rtc_control);
  	}
ad71860a1   Alexey Starikovskiy   ACPICA: minimal p...
61
  	if (acpi_gbl_FADT.century)
48452e5f9   Mark Lord   /proc/acpi/alarm:...
62
  		cent = cmos_bcd_read(acpi_gbl_FADT.century, rtc_control);
ad71860a1   Alexey Starikovskiy   ACPICA: minimal p...
63

48452e5f9   Mark Lord   /proc/acpi/alarm:...
64
  	yr = cmos_bcd_read(RTC_YEAR, rtc_control);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
65
66
  
  	spin_unlock_irqrestore(&rtc_lock, flags);
4be44fcd3   Len Brown   [ACPI] Lindent al...
67
  	/* we're trusting the FADT (see above) */
ad71860a1   Alexey Starikovskiy   ACPICA: minimal p...
68
  	if (!acpi_gbl_FADT.century)
4be44fcd3   Len Brown   [ACPI] Lindent al...
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
  		/* If we're not trusting the FADT, we should at least make it
  		 * right for _this_ century... ehm, what is _this_ century?
  		 *
  		 * TBD:
  		 *  ASAP: find piece of code in the kernel, e.g. star tracker driver,
  		 *        which we can trust to determine the century correctly. Atom
  		 *        watch driver would be nice, too...
  		 *
  		 *  if that has not happened, change for first release in 2050:
  		 *        if (yr<50)
  		 *                yr += 2100;
  		 *        else
  		 *                yr += 2000;   // current line of code
  		 *
  		 *  if that has not happened either, please do on 2099/12/31:23:59:59
  		 *        s/2000/2100
  		 *
  		 */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
87
  		yr += 2000;
ad71860a1   Alexey Starikovskiy   ACPICA: minimal p...
88
89
  	else
  		yr += cent * 100;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
90

48452e5f9   Mark Lord   /proc/acpi/alarm:...
91
92
93
94
95
96
97
98
99
100
101
102
103
  	/*
  	 * Show correct dates for alarms up to a month into the future.
  	 * This solves issues for nearly all situations with the common
  	 * 30-day alarm clocks in PC hardware.
  	 */
  	if (day < today) {
  		if (mo < 12) {
  			mo += 1;
  		} else {
  			mo = 1;
  			yr += 1;
  		}
  	}
4be44fcd3   Len Brown   [ACPI] Lindent al...
104
105
106
107
108
  	seq_printf(seq, "%4.4u-", yr);
  	(mo > 12) ? seq_puts(seq, "**-") : seq_printf(seq, "%2.2u-", mo);
  	(day > 31) ? seq_puts(seq, "** ") : seq_printf(seq, "%2.2u ", day);
  	(hr > 23) ? seq_puts(seq, "**:") : seq_printf(seq, "%2.2u:", hr);
  	(min > 59) ? seq_puts(seq, "**:") : seq_printf(seq, "%2.2u:", min);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
109
110
111
112
113
114
115
116
117
118
119
  	(sec > 59) ? seq_puts(seq, "**
  ") : seq_printf(seq, "%2.2u
  ", sec);
  
  	return 0;
  }
  
  static int acpi_system_alarm_open_fs(struct inode *inode, struct file *file)
  {
  	return single_open(file, acpi_system_alarm_seq_show, PDE(inode)->data);
  }
4be44fcd3   Len Brown   [ACPI] Lindent al...
120
  static int get_date_field(char **p, u32 * value)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
121
  {
4be44fcd3   Len Brown   [ACPI] Lindent al...
122
123
124
  	char *next = NULL;
  	char *string_end = NULL;
  	int result = -EINVAL;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
125
126
127
128
129
  
  	/*
  	 * Try to find delimeter, only to insert null.  The end of the
  	 * string won't have one, but is still valid.
  	 */
975c30257   Signed-off by Yi Yang   ACPI: detect inva...
130
131
  	if (*p == NULL)
  		return result;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
132
133
134
135
136
137
138
139
140
141
142
143
  	next = strpbrk(*p, "- :");
  	if (next)
  		*next++ = '\0';
  
  	*value = simple_strtoul(*p, &string_end, 10);
  
  	/* Signal success if we got a good digit */
  	if (string_end != *p)
  		result = 0;
  
  	if (next)
  		*p = next;
975c30257   Signed-off by Yi Yang   ACPI: detect inva...
144
145
  	else
  		*p = NULL;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
146
147
148
  
  	return result;
  }
c67c36e4b   Linus Torvalds   Fix /proc/acpi/al...
149
150
151
152
153
  /* Read a possibly BCD register, always return binary */
  static u32 cmos_bcd_read(int offset, int rtc_control)
  {
  	u32 val = CMOS_READ(offset);
  	if (!(rtc_control & RTC_DM_BINARY) || RTC_ALWAYS_BCD)
ab527d757   Adrian Bunk   acpi: use bcd2bin...
154
  		val = bcd2bin(val);
c67c36e4b   Linus Torvalds   Fix /proc/acpi/al...
155
156
157
158
159
160
161
  	return val;
  }
  
  /* Write binary value into possibly BCD register */
  static void cmos_bcd_write(u32 val, int offset, int rtc_control)
  {
  	if (!(rtc_control & RTC_DM_BINARY) || RTC_ALWAYS_BCD)
ab527d757   Adrian Bunk   acpi: use bcd2bin...
162
  		val = bin2bcd(val);
c67c36e4b   Linus Torvalds   Fix /proc/acpi/al...
163
164
  	CMOS_WRITE(val, offset);
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
165
  static ssize_t
4be44fcd3   Len Brown   [ACPI] Lindent al...
166
167
  acpi_system_write_alarm(struct file *file,
  			const char __user * buffer, size_t count, loff_t * ppos)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
168
  {
4be44fcd3   Len Brown   [ACPI] Lindent al...
169
170
171
172
173
174
  	int result = 0;
  	char alarm_string[30] = { '\0' };
  	char *p = alarm_string;
  	u32 sec, min, hr, day, mo, yr;
  	int adjust = 0;
  	unsigned char rtc_control = 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
175

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
176
  	if (count > sizeof(alarm_string) - 1)
95d9a7a82   Lin Ming   ACPI: proc.c: rem...
177
  		return -EINVAL;
4be44fcd3   Len Brown   [ACPI] Lindent al...
178

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
179
  	if (copy_from_user(alarm_string, buffer, count))
95d9a7a82   Lin Ming   ACPI: proc.c: rem...
180
  		return -EFAULT;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
  
  	alarm_string[count] = '\0';
  
  	/* check for time adjustment */
  	if (alarm_string[0] == '+') {
  		p++;
  		adjust = 1;
  	}
  
  	if ((result = get_date_field(&p, &yr)))
  		goto end;
  	if ((result = get_date_field(&p, &mo)))
  		goto end;
  	if ((result = get_date_field(&p, &day)))
  		goto end;
  	if ((result = get_date_field(&p, &hr)))
  		goto end;
  	if ((result = get_date_field(&p, &min)))
  		goto end;
  	if ((result = get_date_field(&p, &sec)))
  		goto end;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
202
203
204
  	spin_lock_irq(&rtc_lock);
  
  	rtc_control = CMOS_READ(RTC_CONTROL);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
205
206
  
  	if (adjust) {
c67c36e4b   Linus Torvalds   Fix /proc/acpi/al...
207
208
209
210
211
212
  		yr += cmos_bcd_read(RTC_YEAR, rtc_control);
  		mo += cmos_bcd_read(RTC_MONTH, rtc_control);
  		day += cmos_bcd_read(RTC_DAY_OF_MONTH, rtc_control);
  		hr += cmos_bcd_read(RTC_HOURS, rtc_control);
  		min += cmos_bcd_read(RTC_MINUTES, rtc_control);
  		sec += cmos_bcd_read(RTC_SECONDS, rtc_control);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
213
214
215
  	}
  
  	spin_unlock_irq(&rtc_lock);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
216
  	if (sec > 59) {
087980295   Yi Yang   ACPI: /proc/acpi/...
217
218
  		min += sec/60;
  		sec = sec%60;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
219
220
  	}
  	if (min > 59) {
087980295   Yi Yang   ACPI: /proc/acpi/...
221
222
  		hr += min/60;
  		min = min%60;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
223
224
  	}
  	if (hr > 23) {
087980295   Yi Yang   ACPI: /proc/acpi/...
225
226
  		day += hr/24;
  		hr = hr%24;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
227
228
  	}
  	if (day > 31) {
087980295   Yi Yang   ACPI: /proc/acpi/...
229
230
  		mo += day/32;
  		day = day%32;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
231
232
  	}
  	if (mo > 12) {
087980295   Yi Yang   ACPI: /proc/acpi/...
233
234
  		yr += mo/13;
  		mo = mo%13;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
235
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
236
237
238
239
240
241
242
243
244
245
246
  
  	spin_lock_irq(&rtc_lock);
  	/*
  	 * Disable alarm interrupt before setting alarm timer or else
  	 * when ACPI_EVENT_RTC is enabled, a spurious ACPI interrupt occurs
  	 */
  	rtc_control &= ~RTC_AIE;
  	CMOS_WRITE(rtc_control, RTC_CONTROL);
  	CMOS_READ(RTC_INTR_FLAGS);
  
  	/* write the fields the rtc knows about */
c67c36e4b   Linus Torvalds   Fix /proc/acpi/al...
247
248
249
  	cmos_bcd_write(hr, RTC_HOURS_ALARM, rtc_control);
  	cmos_bcd_write(min, RTC_MINUTES_ALARM, rtc_control);
  	cmos_bcd_write(sec, RTC_SECONDS_ALARM, rtc_control);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
250
251
252
253
254
255
  
  	/*
  	 * If the system supports an enhanced alarm it will have non-zero
  	 * offsets into the CMOS RAM here -- which for some reason are pointing
  	 * to the RTC area of memory.
  	 */
ad71860a1   Alexey Starikovskiy   ACPICA: minimal p...
256
  	if (acpi_gbl_FADT.day_alarm)
c67c36e4b   Linus Torvalds   Fix /proc/acpi/al...
257
  		cmos_bcd_write(day, acpi_gbl_FADT.day_alarm, rtc_control);
ad71860a1   Alexey Starikovskiy   ACPICA: minimal p...
258
  	if (acpi_gbl_FADT.month_alarm)
c67c36e4b   Linus Torvalds   Fix /proc/acpi/al...
259
  		cmos_bcd_write(mo, acpi_gbl_FADT.month_alarm, rtc_control);
cce3ce89c   Huacai Chen   rtc: fix CMOS tim...
260
261
262
  	if (acpi_gbl_FADT.century) {
  		if (adjust)
  			yr += cmos_bcd_read(acpi_gbl_FADT.century, rtc_control) * 100;
c67c36e4b   Linus Torvalds   Fix /proc/acpi/al...
263
  		cmos_bcd_write(yr / 100, acpi_gbl_FADT.century, rtc_control);
cce3ce89c   Huacai Chen   rtc: fix CMOS tim...
264
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
265
266
267
268
269
270
271
272
273
274
275
276
277
  	/* enable the rtc alarm interrupt */
  	rtc_control |= RTC_AIE;
  	CMOS_WRITE(rtc_control, RTC_CONTROL);
  	CMOS_READ(RTC_INTR_FLAGS);
  
  	spin_unlock_irq(&rtc_lock);
  
  	acpi_clear_event(ACPI_EVENT_RTC);
  	acpi_enable_event(ACPI_EVENT_RTC, 0);
  
  	*ppos += count;
  
  	result = 0;
4be44fcd3   Len Brown   [ACPI] Lindent al...
278
        end:
95d9a7a82   Lin Ming   ACPI: proc.c: rem...
279
  	return result ? result : count;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
280
  }
fd3509436   Len Brown   ACPICA: Lindent
281
  #endif				/* HAVE_ACPI_LEGACY_ALARM */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
282

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
283
284
285
  static int
  acpi_system_wakeup_device_seq_show(struct seq_file *seq, void *offset)
  {
4be44fcd3   Len Brown   [ACPI] Lindent al...
286
  	struct list_head *node, *next;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
287

8aa55591b   David Brownell   ACPI: make /proc/...
288
289
  	seq_printf(seq, "Device\tS-state\t  Status   Sysfs node
  ");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
290

9090589d8   Shaohua Li   ACPI: convert acp...
291
  	mutex_lock(&acpi_device_lock);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
292
  	list_for_each_safe(node, next, &acpi_wakeup_device_list) {
4be44fcd3   Len Brown   [ACPI] Lindent al...
293
294
  		struct acpi_device *dev =
  		    container_of(node, struct acpi_device, wakeup_list);
8aa55591b   David Brownell   ACPI: make /proc/...
295
  		struct device *ldev;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
296
297
298
  
  		if (!dev->wakeup.flags.valid)
  			continue;
8aa55591b   David Brownell   ACPI: make /proc/...
299
300
301
  
  		ldev = acpi_get_physical_device(dev->handle);
  		seq_printf(seq, "%s\t  S%d\t%c%-8s  ",
4be44fcd3   Len Brown   [ACPI] Lindent al...
302
303
  			   dev->pnp.bus_id,
  			   (u32) dev->wakeup.sleep_state,
8aa55591b   David Brownell   ACPI: make /proc/...
304
  			   dev->wakeup.flags.run_wake ? '*' : ' ',
f2b56bc80   Rafael J. Wysocki   ACPI / PM: Use de...
305
306
307
  			   (device_may_wakeup(&dev->dev)
  			     || (ldev && device_may_wakeup(ldev))) ?
  			       "enabled" : "disabled");
8aa55591b   David Brownell   ACPI: make /proc/...
308
309
  		if (ldev)
  			seq_printf(seq, "%s:%s",
77fb61a04   Linus Torvalds   acpi: fix oops in...
310
  				   ldev->bus ? ldev->bus->name : "no-bus",
0794469da   Kay Sievers   ACPI: struct devi...
311
  				   dev_name(ldev));
8aa55591b   David Brownell   ACPI: make /proc/...
312
313
314
  		seq_printf(seq, "
  ");
  		put_device(ldev);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
315
  	}
9090589d8   Shaohua Li   ACPI: convert acp...
316
  	mutex_unlock(&acpi_device_lock);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
317
318
  	return 0;
  }
76acae04c   Rafael J. Wysocki   ACPI: Make /proc/...
319
320
321
  static void physical_device_enable_wakeup(struct acpi_device *adev)
  {
  	struct device *dev = acpi_get_physical_device(adev->handle);
f2b56bc80   Rafael J. Wysocki   ACPI / PM: Use de...
322
323
324
325
  	if (dev && device_can_wakeup(dev)) {
  		bool enable = !device_may_wakeup(dev);
  		device_set_wakeup_enable(dev, enable);
  	}
76acae04c   Rafael J. Wysocki   ACPI: Make /proc/...
326
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
327
  static ssize_t
4be44fcd3   Len Brown   [ACPI] Lindent al...
328
329
330
  acpi_system_write_wakeup_device(struct file *file,
  				const char __user * buffer,
  				size_t count, loff_t * ppos)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
331
  {
4be44fcd3   Len Brown   [ACPI] Lindent al...
332
333
334
  	struct list_head *node, *next;
  	char strbuf[5];
  	char str[5] = "";
52a2b11ca   Arjan van de Ven   ACPI: clean up vi...
335
  	unsigned int len = count;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
336

4be44fcd3   Len Brown   [ACPI] Lindent al...
337
338
  	if (len > 4)
  		len = 4;
d9f650180   Arjan van de Ven   ACPI: Fix bound c...
339
340
  	if (len < 0)
  		return -EFAULT;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
341
342
343
344
345
  
  	if (copy_from_user(strbuf, buffer, len))
  		return -EFAULT;
  	strbuf[len] = '\0';
  	sscanf(strbuf, "%s", str);
9090589d8   Shaohua Li   ACPI: convert acp...
346
  	mutex_lock(&acpi_device_lock);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
347
  	list_for_each_safe(node, next, &acpi_wakeup_device_list) {
4be44fcd3   Len Brown   [ACPI] Lindent al...
348
349
  		struct acpi_device *dev =
  		    container_of(node, struct acpi_device, wakeup_list);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
350
351
352
353
  		if (!dev->wakeup.flags.valid)
  			continue;
  
  		if (!strncmp(dev->pnp.bus_id, str, 4)) {
f2b56bc80   Rafael J. Wysocki   ACPI / PM: Use de...
354
355
356
357
358
359
  			if (device_can_wakeup(&dev->dev)) {
  				bool enable = !device_may_wakeup(&dev->dev);
  				device_set_wakeup_enable(&dev->dev, enable);
  			} else {
  				physical_device_enable_wakeup(dev);
  			}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
360
361
362
  			break;
  		}
  	}
9090589d8   Shaohua Li   ACPI: convert acp...
363
  	mutex_unlock(&acpi_device_lock);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
364
365
366
367
368
369
  	return count;
  }
  
  static int
  acpi_system_wakeup_device_open_fs(struct inode *inode, struct file *file)
  {
4be44fcd3   Len Brown   [ACPI] Lindent al...
370
371
  	return single_open(file, acpi_system_wakeup_device_seq_show,
  			   PDE(inode)->data);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
372
  }
d75080328   Arjan van de Ven   ACPI: add 'const'...
373
  static const struct file_operations acpi_system_wakeup_device_fops = {
cf7acfab0   Denis V. Lunev   acpi: use non-rac...
374
  	.owner = THIS_MODULE,
4be44fcd3   Len Brown   [ACPI] Lindent al...
375
376
377
378
379
  	.open = acpi_system_wakeup_device_open_fs,
  	.read = seq_read,
  	.write = acpi_system_write_wakeup_device,
  	.llseek = seq_lseek,
  	.release = single_release,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
380
  };
f5f72b46c   David Brownell   ACPI wakeup hooks...
381
  #ifdef	HAVE_ACPI_LEGACY_ALARM
d75080328   Arjan van de Ven   ACPI: add 'const'...
382
  static const struct file_operations acpi_system_alarm_fops = {
cf7acfab0   Denis V. Lunev   acpi: use non-rac...
383
  	.owner = THIS_MODULE,
4be44fcd3   Len Brown   [ACPI] Lindent al...
384
385
386
387
388
  	.open = acpi_system_alarm_open_fs,
  	.read = seq_read,
  	.write = acpi_system_write_alarm,
  	.llseek = seq_lseek,
  	.release = single_release,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
389
  };
4be44fcd3   Len Brown   [ACPI] Lindent al...
390
  static u32 rtc_handler(void *context)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
391
392
393
394
395
396
  {
  	acpi_clear_event(ACPI_EVENT_RTC);
  	acpi_disable_event(ACPI_EVENT_RTC, 0);
  
  	return ACPI_INTERRUPT_HANDLED;
  }
fd3509436   Len Brown   ACPICA: Lindent
397
  #endif				/* HAVE_ACPI_LEGACY_ALARM */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
398

9cee43e07   Bjorn Helgaas   ACPI: call acpi_s...
399
  int __init acpi_sleep_proc_init(void)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
400
  {
f5f72b46c   David Brownell   ACPI wakeup hooks...
401
  #ifdef	HAVE_ACPI_LEGACY_ALARM
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
402
  	/* 'alarm' [R/W] */
cf7acfab0   Denis V. Lunev   acpi: use non-rac...
403
404
  	proc_create("alarm", S_IFREG | S_IRUGO | S_IWUSR,
  		    acpi_root_dir, &acpi_system_alarm_fops);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
405

f5f72b46c   David Brownell   ACPI wakeup hooks...
406
  	acpi_install_fixed_event_handler(ACPI_EVENT_RTC, rtc_handler, NULL);
e1094bfa2   Zhao Yakui   ACPI: Disable Fix...
407
408
409
410
411
412
  	/*
  	 * Disable the RTC event after installing RTC handler.
  	 * Only when RTC alarm is set will it be enabled.
  	 */
  	acpi_clear_event(ACPI_EVENT_RTC);
  	acpi_disable_event(ACPI_EVENT_RTC, 0);
fd3509436   Len Brown   ACPICA: Lindent
413
  #endif				/* HAVE_ACPI_LEGACY_ALARM */
f5f72b46c   David Brownell   ACPI wakeup hooks...
414

c65ade4dc   Pavel Machek   [ACPI] whitespace
415
  	/* 'wakeup device' [R/W] */
cf7acfab0   Denis V. Lunev   acpi: use non-rac...
416
417
  	proc_create("wakeup", S_IFREG | S_IRUGO | S_IWUSR,
  		    acpi_root_dir, &acpi_system_wakeup_device_fops);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
418

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
419
420
  	return 0;
  }