13 #include <linux/module.h>
14 #include <linux/poll.h>
15 #include <linux/slab.h>
20 #include <linux/apm_bios.h>
21 #include <linux/capability.h>
22 #include <linux/sched.h>
26 #include <linux/device.h>
27 #include <linux/kernel.h>
28 #include <linux/list.h>
39 #define APM_MINOR_DEV 134
49 #define APM_MAX_EVENTS 16
112 unsigned int suser: 1;
127 static int apm_disabled;
150 static const char driver_version[] =
"1.13";
172 static inline int queue_empty(
struct apm_queue *
q)
203 queue_add_event(&as->
queue, event);
223 while ((i >=
sizeof(event)) && !queue_empty(&as->
queue)) {
224 event = queue_get_event(&as->
queue);
236 buf +=
sizeof(
event);
250 poll_wait(fp, &apm_waitqueue, wait);
294 wake_up(&apm_suspend_waitqueue);
353 wake_up(&apm_suspend_waitqueue);
359 static int apm_open(
struct inode * inode,
struct file * filp)
377 list_add(&as->
list, &apm_user_list);
390 .unlocked_ioctl = apm_ioctl,
392 .release = apm_release,
399 .fops = &apm_bios_fops
403 #ifdef CONFIG_PROC_FS
442 static int proc_apm_show(
struct seq_file *
m,
void *
v)
447 info.ac_line_status = 0xff;
448 info.battery_status = 0xff;
449 info.battery_flag = 0xff;
450 info.battery_life = -1;
457 switch (
info.units) {
458 default: units =
"?";
break;
459 case 0: units =
"min";
break;
460 case 1: units =
"sec";
break;
463 seq_printf(m,
"%s 1.2 0x%02x 0x%02x 0x%02x 0x%02x %d%% %d %s\n",
465 info.ac_line_status,
info.battery_status,
466 info.battery_flag,
info.battery_life,
472 static int proc_apm_open(
struct inode *inode,
struct file *
file)
479 .open = proc_apm_open,
486 static int kapmd(
void *arg)
497 spin_lock_irq(&kapmd_queue_lock);
499 if (!queue_empty(&kapmd_queue))
500 event = queue_get_event(&kapmd_queue);
501 spin_unlock_irq(&kapmd_queue_lock);
570 apm_suspend_waitqueue,
601 return notifier_from_errno(err);
630 wake_up(&apm_suspend_waitqueue);
639 .notifier_call = apm_suspend_notifier,
642 static int __init apm_init(
void)
652 if (IS_ERR(kapmd_tsk)) {
653 ret = PTR_ERR(kapmd_tsk);
659 #ifdef CONFIG_PROC_FS
660 proc_create(
"apm", 0,
NULL, &apm_proc_fops);
667 ret = register_pm_notifier(&apm_notif_block);
682 static void __exit apm_exit(
void)
684 unregister_pm_notifier(&apm_notif_block);
701 while ((str !=
NULL) && (*str !=
'\0')) {
702 if (
strncmp(str,
"off", 3) == 0)
704 if (
strncmp(str,
"on", 2) == 0)
708 str +=
strspn(str,
", \t");
733 queue_add_event(&kapmd_queue, event);
734 spin_unlock_irqrestore(&kapmd_queue_lock, flags);