1 #include <linux/proc_fs.h>
2 #include <linux/seq_file.h>
3 #include <linux/suspend.h>
5 #include <asm/uaccess.h>
7 #include <acpi/acpi_bus.h>
8 #include <acpi/acpi_drivers.h>
11 #include <linux/mc146818rtc.h>
16 #define _COMPONENT ACPI_SYSTEM_COMPONENT
17 ACPI_MODULE_NAME ("sleep")
19 #ifdef CONFIG_ACPI_SLEEP_PROC_SLEEP
21 static int acpi_system_sleep_seq_show(struct seq_file *seq, void *offset)
25 ACPI_FUNCTION_TRACE("acpi_system_sleep_seq_show");
27 for (i = 0; i <= ACPI_STATE_S5; i++) {
28 if (sleep_states[i]) {
29 seq_printf(seq,"S%d ", i);
30 if (i == ACPI_STATE_S4 && acpi_gbl_FACS->S4bios_f)
31 seq_printf(seq, "S4bios ");
40 static int acpi_system_sleep_open_fs(struct inode *inode, struct file *file)
42 return single_open(file, acpi_system_sleep_seq_show, PDE(inode)->data);
46 acpi_system_write_sleep (
48 const char __user *buffer,
56 if (count > sizeof(str) - 1)
58 memset(str,0,sizeof(str));
59 if (copy_from_user(str, buffer, count))
62 /* Check for S4 bios request */
63 if (!strcmp(str,"4b")) {
64 error = acpi_suspend(4);
67 state = simple_strtoul(str, NULL, 0);
68 #ifdef CONFIG_SOFTWARE_SUSPEND
70 error = software_suspend();
74 error = acpi_suspend(state);
76 return error ? error : count;
78 #endif /* CONFIG_ACPI_SLEEP_PROC_SLEEP */
80 static int acpi_system_alarm_seq_show(struct seq_file *seq, void *offset)
84 unsigned char rtc_control = 0;
87 ACPI_FUNCTION_TRACE("acpi_system_alarm_seq_show");
89 spin_lock_irqsave(&rtc_lock, flags);
91 sec = CMOS_READ(RTC_SECONDS_ALARM);
92 min = CMOS_READ(RTC_MINUTES_ALARM);
93 hr = CMOS_READ(RTC_HOURS_ALARM);
94 rtc_control = CMOS_READ(RTC_CONTROL);
96 /* If we ever get an FACP with proper values... */
97 if (acpi_gbl_FADT->day_alrm)
98 /* ACPI spec: only low 6 its should be cared */
99 day = CMOS_READ(acpi_gbl_FADT->day_alrm) & 0x3F;
101 day = CMOS_READ(RTC_DAY_OF_MONTH);
102 if (acpi_gbl_FADT->mon_alrm)
103 mo = CMOS_READ(acpi_gbl_FADT->mon_alrm);
105 mo = CMOS_READ(RTC_MONTH);
106 if (acpi_gbl_FADT->century)
107 yr = CMOS_READ(acpi_gbl_FADT->century) * 100 + CMOS_READ(RTC_YEAR);
109 yr = CMOS_READ(RTC_YEAR);
111 spin_unlock_irqrestore(&rtc_lock, flags);
113 if (!(rtc_control & RTC_DM_BINARY) || RTC_ALWAYS_BCD) {
122 /* we're trusting the FADT (see above)*/
123 if (!acpi_gbl_FADT->century)
124 /* If we're not trusting the FADT, we should at least make it
125 * right for _this_ century... ehm, what is _this_ century?
128 * ASAP: find piece of code in the kernel, e.g. star tracker driver,
129 * which we can trust to determine the century correctly. Atom
130 * watch driver would be nice, too...
132 * if that has not happened, change for first release in 2050:
136 * yr += 2000; // current line of code
138 * if that has not happened either, please do on 2099/12/31:23:59:59
144 seq_printf(seq,"%4.4u-", yr);
145 (mo > 12) ? seq_puts(seq, "**-") : seq_printf(seq, "%2.2u-", mo);
146 (day > 31) ? seq_puts(seq, "** ") : seq_printf(seq, "%2.2u ", day);
147 (hr > 23) ? seq_puts(seq, "**:") : seq_printf(seq, "%2.2u:", hr);
148 (min > 59) ? seq_puts(seq, "**:") : seq_printf(seq, "%2.2u:", min);
149 (sec > 59) ? seq_puts(seq, "**\n") : seq_printf(seq, "%2.2u\n", sec);
154 static int acpi_system_alarm_open_fs(struct inode *inode, struct file *file)
156 return single_open(file, acpi_system_alarm_seq_show, PDE(inode)->data);
166 char *string_end = NULL;
167 int result = -EINVAL;
170 * Try to find delimeter, only to insert null. The end of the
171 * string won't have one, but is still valid.
173 next = strpbrk(*p, "- :");
177 *value = simple_strtoul(*p, &string_end, 10);
179 /* Signal success if we got a good digit */
180 if (string_end != *p)
191 acpi_system_write_alarm (
193 const char __user *buffer,
198 char alarm_string[30] = {'\0'};
199 char *p = alarm_string;
200 u32 sec, min, hr, day, mo, yr;
202 unsigned char rtc_control = 0;
204 ACPI_FUNCTION_TRACE("acpi_system_write_alarm");
206 if (count > sizeof(alarm_string) - 1)
207 return_VALUE(-EINVAL);
209 if (copy_from_user(alarm_string, buffer, count))
210 return_VALUE(-EFAULT);
212 alarm_string[count] = '\0';
214 /* check for time adjustment */
215 if (alarm_string[0] == '+') {
220 if ((result = get_date_field(&p, &yr)))
222 if ((result = get_date_field(&p, &mo)))
224 if ((result = get_date_field(&p, &day)))
226 if ((result = get_date_field(&p, &hr)))
228 if ((result = get_date_field(&p, &min)))
230 if ((result = get_date_field(&p, &sec)))
254 spin_lock_irq(&rtc_lock);
256 rtc_control = CMOS_READ(RTC_CONTROL);
257 if (!(rtc_control & RTC_DM_BINARY) || RTC_ALWAYS_BCD) {
267 yr += CMOS_READ(RTC_YEAR);
268 mo += CMOS_READ(RTC_MONTH);
269 day += CMOS_READ(RTC_DAY_OF_MONTH);
270 hr += CMOS_READ(RTC_HOURS);
271 min += CMOS_READ(RTC_MINUTES);
272 sec += CMOS_READ(RTC_SECONDS);
275 spin_unlock_irq(&rtc_lock);
277 if (!(rtc_control & RTC_DM_BINARY) || RTC_ALWAYS_BCD) {
306 if (!(rtc_control & RTC_DM_BINARY) || RTC_ALWAYS_BCD) {
315 spin_lock_irq(&rtc_lock);
317 * Disable alarm interrupt before setting alarm timer or else
318 * when ACPI_EVENT_RTC is enabled, a spurious ACPI interrupt occurs
320 rtc_control &= ~RTC_AIE;
321 CMOS_WRITE(rtc_control, RTC_CONTROL);
322 CMOS_READ(RTC_INTR_FLAGS);
324 /* write the fields the rtc knows about */
325 CMOS_WRITE(hr, RTC_HOURS_ALARM);
326 CMOS_WRITE(min, RTC_MINUTES_ALARM);
327 CMOS_WRITE(sec, RTC_SECONDS_ALARM);
330 * If the system supports an enhanced alarm it will have non-zero
331 * offsets into the CMOS RAM here -- which for some reason are pointing
332 * to the RTC area of memory.
334 if (acpi_gbl_FADT->day_alrm)
335 CMOS_WRITE(day, acpi_gbl_FADT->day_alrm);
336 if (acpi_gbl_FADT->mon_alrm)
337 CMOS_WRITE(mo, acpi_gbl_FADT->mon_alrm);
338 if (acpi_gbl_FADT->century)
339 CMOS_WRITE(yr/100, acpi_gbl_FADT->century);
340 /* enable the rtc alarm interrupt */
341 rtc_control |= RTC_AIE;
342 CMOS_WRITE(rtc_control, RTC_CONTROL);
343 CMOS_READ(RTC_INTR_FLAGS);
345 spin_unlock_irq(&rtc_lock);
347 acpi_clear_event(ACPI_EVENT_RTC);
348 acpi_enable_event(ACPI_EVENT_RTC, 0);
354 return_VALUE(result ? result : count);
357 extern struct list_head acpi_wakeup_device_list;
358 extern spinlock_t acpi_device_lock;
361 acpi_system_wakeup_device_seq_show(struct seq_file *seq, void *offset)
363 struct list_head * node, * next;
365 seq_printf(seq, "Device Sleep state Status\n");
367 spin_lock(&acpi_device_lock);
368 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
369 struct acpi_device * dev = container_of(node, struct acpi_device, wakeup_list);
371 if (!dev->wakeup.flags.valid)
373 spin_unlock(&acpi_device_lock);
374 seq_printf(seq, "%4s %4d %s%8s\n",
375 dev->pnp.bus_id, (u32) dev->wakeup.sleep_state,
376 dev->wakeup.flags.run_wake ? "*" : "",
377 dev->wakeup.state.enabled ? "enabled" : "disabled");
378 spin_lock(&acpi_device_lock);
380 spin_unlock(&acpi_device_lock);
385 acpi_system_write_wakeup_device (
387 const char __user *buffer,
391 struct list_head * node, * next;
395 struct acpi_device *found_dev = NULL;
397 if (len > 4) len = 4;
399 if (copy_from_user(strbuf, buffer, len))
402 sscanf(strbuf, "%s", str);
404 spin_lock(&acpi_device_lock);
405 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
406 struct acpi_device * dev = container_of(node, struct acpi_device, wakeup_list);
407 if (!dev->wakeup.flags.valid)
410 if (!strncmp(dev->pnp.bus_id, str, 4)) {
411 dev->wakeup.state.enabled = dev->wakeup.state.enabled ? 0:1;
417 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
418 struct acpi_device * dev = container_of(node,
419 struct acpi_device, wakeup_list);
421 if ((dev != found_dev) &&
422 (dev->wakeup.gpe_number == found_dev->wakeup.gpe_number) &&
423 (dev->wakeup.gpe_device == found_dev->wakeup.gpe_device)) {
424 printk(KERN_WARNING "ACPI: '%s' and '%s' have the same GPE, "
425 "can't disable/enable one seperately\n",
426 dev->pnp.bus_id, found_dev->pnp.bus_id);
427 dev->wakeup.state.enabled = found_dev->wakeup.state.enabled;
431 spin_unlock(&acpi_device_lock);
436 acpi_system_wakeup_device_open_fs(struct inode *inode, struct file *file)
438 return single_open(file, acpi_system_wakeup_device_seq_show, PDE(inode)->data);
441 static struct file_operations acpi_system_wakeup_device_fops = {
442 .open = acpi_system_wakeup_device_open_fs,
444 .write = acpi_system_write_wakeup_device,
446 .release = single_release,
449 #ifdef CONFIG_ACPI_SLEEP_PROC_SLEEP
450 static struct file_operations acpi_system_sleep_fops = {
451 .open = acpi_system_sleep_open_fs,
453 .write = acpi_system_write_sleep,
455 .release = single_release,
457 #endif /* CONFIG_ACPI_SLEEP_PROC_SLEEP */
459 static struct file_operations acpi_system_alarm_fops = {
460 .open = acpi_system_alarm_open_fs,
462 .write = acpi_system_write_alarm,
464 .release = single_release,
468 static u32 rtc_handler(void * context)
470 acpi_clear_event(ACPI_EVENT_RTC);
471 acpi_disable_event(ACPI_EVENT_RTC, 0);
473 return ACPI_INTERRUPT_HANDLED;
476 static int acpi_sleep_proc_init(void)
478 struct proc_dir_entry *entry = NULL;
483 #ifdef CONFIG_ACPI_SLEEP_PROC_SLEEP
485 entry = create_proc_entry("sleep", S_IFREG|S_IRUGO|S_IWUSR, acpi_root_dir);
487 entry->proc_fops = &acpi_system_sleep_fops;
491 entry = create_proc_entry("alarm", S_IFREG|S_IRUGO|S_IWUSR, acpi_root_dir);
493 entry->proc_fops = &acpi_system_alarm_fops;
495 /* 'wakeup device' [R/W] */
496 entry = create_proc_entry("wakeup", S_IFREG|S_IRUGO|S_IWUSR, acpi_root_dir);
498 entry->proc_fops = &acpi_system_wakeup_device_fops;
500 acpi_install_fixed_event_handler(ACPI_EVENT_RTC, rtc_handler, NULL);
504 late_initcall(acpi_sleep_proc_init);