blob: bbe98e3b860b67c61aaec01778c19a76e2a56582 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * bios-less APM driver for ARM Linux
3 * Jamey Hicks <jamey@crl.dec.com>
4 * adapted from the APM BIOS driver for Linux by Stephen Rothwell (sfr@linuxcare.com)
5 *
6 * APM 1.2 Reference:
7 * Intel Corporation, Microsoft Corporation. Advanced Power Management
8 * (APM) BIOS Interface Specification, Revision 1.2, February 1996.
9 *
10 * [This document is available from Microsoft at:
11 * http://www.microsoft.com/hwdev/busbios/amp_12.htm]
12 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <linux/module.h>
14#include <linux/poll.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <linux/slab.h>
16#include <linux/proc_fs.h>
17#include <linux/miscdevice.h>
18#include <linux/apm_bios.h>
Randy Dunlapa9415642006-01-11 12:17:48 -080019#include <linux/capability.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include <linux/sched.h>
21#include <linux/pm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include <linux/device.h>
23#include <linux/kernel.h>
24#include <linux/list.h>
25#include <linux/init.h>
26#include <linux/completion.h>
Serge E. Hallynea33a592006-08-07 11:57:36 -050027#include <linux/kthread.h>
Russell Kingb729c092006-11-07 21:00:22 +000028#include <linux/delay.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
30#include <asm/apm.h> /* apm_power_info */
31#include <asm/system.h>
32
33/*
34 * The apm_bios device is one of the misc char devices.
35 * This is its minor number.
36 */
37#define APM_MINOR_DEV 134
38
39/*
40 * See Documentation/Config.help for the configuration options.
41 *
42 * Various options can be changed at boot time as follows:
43 * (We allow underscores for compatibility with the modules code)
44 * apm=on/off enable/disable APM
45 */
46
47/*
48 * Maximum number of events stored
49 */
50#define APM_MAX_EVENTS 16
51
52struct apm_queue {
53 unsigned int event_head;
54 unsigned int event_tail;
55 apm_event_t events[APM_MAX_EVENTS];
56};
57
58/*
59 * The per-file APM data
60 */
61struct apm_user {
62 struct list_head list;
63
64 unsigned int suser: 1;
65 unsigned int writer: 1;
66 unsigned int reader: 1;
67
68 int suspend_result;
69 unsigned int suspend_state;
70#define SUSPEND_NONE 0 /* no suspend pending */
71#define SUSPEND_PENDING 1 /* suspend pending read */
72#define SUSPEND_READ 2 /* suspend read, pending ack */
73#define SUSPEND_ACKED 3 /* suspend acked */
Russell Kingb729c092006-11-07 21:00:22 +000074#define SUSPEND_WAIT 4 /* waiting for suspend */
75#define SUSPEND_DONE 5 /* suspend completed */
Linus Torvalds1da177e2005-04-16 15:20:36 -070076
77 struct apm_queue queue;
78};
79
80/*
81 * Local variables
82 */
83static int suspends_pending;
84static int apm_disabled;
Serge E. Hallynea33a592006-08-07 11:57:36 -050085static struct task_struct *kapmd_tsk;
Linus Torvalds1da177e2005-04-16 15:20:36 -070086
87static DECLARE_WAIT_QUEUE_HEAD(apm_waitqueue);
88static DECLARE_WAIT_QUEUE_HEAD(apm_suspend_waitqueue);
89
90/*
91 * This is a list of everyone who has opened /dev/apm_bios
92 */
93static DECLARE_RWSEM(user_list_lock);
94static LIST_HEAD(apm_user_list);
95
96/*
97 * kapmd info. kapmd provides us a process context to handle
98 * "APM" events within - specifically necessary if we're going
99 * to be suspending the system.
100 */
101static DECLARE_WAIT_QUEUE_HEAD(kapmd_wait);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102static DEFINE_SPINLOCK(kapmd_queue_lock);
103static struct apm_queue kapmd_queue;
104
Russell Kingb729c092006-11-07 21:00:22 +0000105static DECLARE_MUTEX(state_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106
107static const char driver_version[] = "1.13"; /* no spaces */
108
109
110
111/*
112 * Compatibility cruft until the IPAQ people move over to the new
113 * interface.
114 */
115static void __apm_get_power_status(struct apm_power_info *info)
116{
117}
118
119/*
120 * This allows machines to provide their own "apm get power status" function.
121 */
122void (*apm_get_power_status)(struct apm_power_info *) = __apm_get_power_status;
123EXPORT_SYMBOL(apm_get_power_status);
124
125
126/*
127 * APM event queue management.
128 */
129static inline int queue_empty(struct apm_queue *q)
130{
131 return q->event_head == q->event_tail;
132}
133
134static inline apm_event_t queue_get_event(struct apm_queue *q)
135{
136 q->event_tail = (q->event_tail + 1) % APM_MAX_EVENTS;
137 return q->events[q->event_tail];
138}
139
140static void queue_add_event(struct apm_queue *q, apm_event_t event)
141{
142 q->event_head = (q->event_head + 1) % APM_MAX_EVENTS;
143 if (q->event_head == q->event_tail) {
144 static int notified;
145
146 if (notified++ == 0)
147 printk(KERN_ERR "apm: an event queue overflowed\n");
148 q->event_tail = (q->event_tail + 1) % APM_MAX_EVENTS;
149 }
150 q->events[q->event_head] = event;
151}
152
Russell Kingb729c092006-11-07 21:00:22 +0000153static void queue_event(apm_event_t event)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154{
155 struct apm_user *as;
156
157 down_read(&user_list_lock);
158 list_for_each_entry(as, &apm_user_list, list) {
Russell Kingb729c092006-11-07 21:00:22 +0000159 if (as->reader)
160 queue_add_event(&as->queue, event);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 }
162 up_read(&user_list_lock);
163 wake_up_interruptible(&apm_waitqueue);
164}
165
Russell Kingb729c092006-11-07 21:00:22 +0000166/*
167 * queue_suspend_event - queue an APM suspend event.
168 *
169 * Check that we're in a state where we can suspend. If not,
170 * return -EBUSY. Otherwise, queue an event to all "writer"
171 * users. If there are no "writer" users, return '1' to
172 * indicate that we can immediately suspend.
173 */
174static int queue_suspend_event(apm_event_t event, struct apm_user *sender)
175{
176 struct apm_user *as;
177 int ret = 1;
178
179 down(&state_lock);
180 down_read(&user_list_lock);
181
182 /*
183 * If a thread is still processing, we can't suspend, so reject
184 * the request.
185 */
186 list_for_each_entry(as, &apm_user_list, list) {
187 if (as != sender && as->reader && as->writer && as->suser &&
188 as->suspend_state != SUSPEND_NONE) {
189 ret = -EBUSY;
190 goto out;
191 }
192 }
193
194 list_for_each_entry(as, &apm_user_list, list) {
195 if (as != sender && as->reader && as->writer && as->suser) {
196 as->suspend_state = SUSPEND_PENDING;
197 suspends_pending++;
198 queue_add_event(&as->queue, event);
199 ret = 0;
200 }
201 }
202 out:
203 up_read(&user_list_lock);
204 up(&state_lock);
205 wake_up_interruptible(&apm_waitqueue);
206 return ret;
207}
208
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209static void apm_suspend(void)
210{
211 struct apm_user *as;
212 int err = pm_suspend(PM_SUSPEND_MEM);
213
214 /*
215 * Anyone on the APM queues will think we're still suspended.
216 * Send a message so everyone knows we're now awake again.
217 */
Russell Kingb729c092006-11-07 21:00:22 +0000218 queue_event(APM_NORMAL_RESUME);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219
220 /*
221 * Finally, wake up anyone who is sleeping on the suspend.
222 */
Russell Kingb729c092006-11-07 21:00:22 +0000223 down(&state_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 down_read(&user_list_lock);
225 list_for_each_entry(as, &apm_user_list, list) {
Russell Kingb729c092006-11-07 21:00:22 +0000226 if (as->suspend_state == SUSPEND_WAIT ||
227 as->suspend_state == SUSPEND_ACKED) {
228 as->suspend_result = err;
229 as->suspend_state = SUSPEND_DONE;
230 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 }
232 up_read(&user_list_lock);
Russell Kingb729c092006-11-07 21:00:22 +0000233 up(&state_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234
235 wake_up(&apm_suspend_waitqueue);
236}
237
238static ssize_t apm_read(struct file *fp, char __user *buf, size_t count, loff_t *ppos)
239{
240 struct apm_user *as = fp->private_data;
241 apm_event_t event;
242 int i = count, ret = 0;
243
244 if (count < sizeof(apm_event_t))
245 return -EINVAL;
246
247 if (queue_empty(&as->queue) && fp->f_flags & O_NONBLOCK)
248 return -EAGAIN;
249
250 wait_event_interruptible(apm_waitqueue, !queue_empty(&as->queue));
251
252 while ((i >= sizeof(event)) && !queue_empty(&as->queue)) {
253 event = queue_get_event(&as->queue);
254
255 ret = -EFAULT;
256 if (copy_to_user(buf, &event, sizeof(event)))
257 break;
258
Russell Kingb729c092006-11-07 21:00:22 +0000259 down(&state_lock);
260 if (as->suspend_state == SUSPEND_PENDING &&
261 (event == APM_SYS_SUSPEND || event == APM_USER_SUSPEND))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262 as->suspend_state = SUSPEND_READ;
Russell Kingb729c092006-11-07 21:00:22 +0000263 up(&state_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264
265 buf += sizeof(event);
266 i -= sizeof(event);
267 }
268
269 if (i < count)
270 ret = count - i;
271
272 return ret;
273}
274
275static unsigned int apm_poll(struct file *fp, poll_table * wait)
276{
277 struct apm_user *as = fp->private_data;
278
279 poll_wait(fp, &apm_waitqueue, wait);
280 return queue_empty(&as->queue) ? 0 : POLLIN | POLLRDNORM;
281}
282
283/*
284 * apm_ioctl - handle APM ioctl
285 *
286 * APM_IOC_SUSPEND
287 * This IOCTL is overloaded, and performs two functions. It is used to:
288 * - initiate a suspend
289 * - acknowledge a suspend read from /dev/apm_bios.
290 * Only when everyone who has opened /dev/apm_bios with write permission
291 * has acknowledge does the actual suspend happen.
292 */
293static int
294apm_ioctl(struct inode * inode, struct file *filp, u_int cmd, u_long arg)
295{
296 struct apm_user *as = filp->private_data;
297 unsigned long flags;
298 int err = -EINVAL;
299
300 if (!as->suser || !as->writer)
301 return -EPERM;
302
303 switch (cmd) {
304 case APM_IOC_SUSPEND:
Russell Kingb729c092006-11-07 21:00:22 +0000305 down(&state_lock);
306
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 as->suspend_result = -EINTR;
308
309 if (as->suspend_state == SUSPEND_READ) {
Russell Kingb729c092006-11-07 21:00:22 +0000310 int pending;
311
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 /*
313 * If we read a suspend command from /dev/apm_bios,
314 * then the corresponding APM_IOC_SUSPEND ioctl is
315 * interpreted as an acknowledge.
316 */
317 as->suspend_state = SUSPEND_ACKED;
318 suspends_pending--;
Russell Kingb729c092006-11-07 21:00:22 +0000319 pending = suspends_pending == 0;
320 up(&state_lock);
321
322 /*
323 * If there are no further acknowledges required,
324 * suspend the system.
325 */
326 if (pending)
327 apm_suspend();
328
329 /*
330 * Wait for the suspend/resume to complete. If there
331 * are pending acknowledges, we wait here for them.
332 *
333 * Note: we need to ensure that the PM subsystem does
334 * not kick us out of the wait when it suspends the
335 * threads.
336 */
337 flags = current->flags;
338 current->flags |= PF_NOFREEZE;
339
340 wait_event(apm_suspend_waitqueue,
341 as->suspend_state == SUSPEND_DONE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 } else {
Russell Kingb729c092006-11-07 21:00:22 +0000343 up(&state_lock);
344
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 /*
346 * Otherwise it is a request to suspend the system.
347 * Queue an event for all readers, and expect an
348 * acknowledge from all writers who haven't already
349 * acknowledged.
350 */
Russell Kingb729c092006-11-07 21:00:22 +0000351 err = queue_suspend_event(APM_USER_SUSPEND, as);
352 if (err < 0)
353 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354
Russell Kingb729c092006-11-07 21:00:22 +0000355 if (err > 0)
356 apm_suspend();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357
Russell Kingb729c092006-11-07 21:00:22 +0000358 /*
359 * Wait for the suspend/resume to complete. If there
360 * are pending acknowledges, we wait here for them.
361 *
362 * Note: we need to ensure that the PM subsystem does
363 * not kick us out of the wait when it suspends the
364 * threads.
365 */
366 flags = current->flags;
367 current->flags |= PF_NOFREEZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 wait_event_interruptible(apm_suspend_waitqueue,
370 as->suspend_state == SUSPEND_DONE);
Russell Kingb729c092006-11-07 21:00:22 +0000371 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372
373 current->flags = flags;
Russell Kingb729c092006-11-07 21:00:22 +0000374
375 down(&state_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 err = as->suspend_result;
377 as->suspend_state = SUSPEND_NONE;
Russell Kingb729c092006-11-07 21:00:22 +0000378 up(&state_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 break;
380 }
381
382 return err;
383}
384
385static int apm_release(struct inode * inode, struct file * filp)
386{
387 struct apm_user *as = filp->private_data;
Russell Kingb729c092006-11-07 21:00:22 +0000388 int pending = 0;
389
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 filp->private_data = NULL;
391
392 down_write(&user_list_lock);
393 list_del(&as->list);
394 up_write(&user_list_lock);
395
396 /*
397 * We are now unhooked from the chain. As far as new
398 * events are concerned, we no longer exist. However, we
399 * need to balance suspends_pending, which means the
400 * possibility of sleeping.
401 */
Russell Kingb729c092006-11-07 21:00:22 +0000402 down(&state_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 if (as->suspend_state != SUSPEND_NONE) {
404 suspends_pending -= 1;
Russell Kingb729c092006-11-07 21:00:22 +0000405 pending = suspends_pending == 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 }
Russell Kingb729c092006-11-07 21:00:22 +0000407 up(&state_lock);
408 if (pending)
409 apm_suspend();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410
411 kfree(as);
412 return 0;
413}
414
415static int apm_open(struct inode * inode, struct file * filp)
416{
417 struct apm_user *as;
418
Russell Kingd2a02b92006-03-20 19:46:41 +0000419 as = (struct apm_user *)kzalloc(sizeof(*as), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 if (as) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 /*
422 * XXX - this is a tiny bit broken, when we consider BSD
423 * process accounting. If the device is opened by root, we
424 * instantly flag that we used superuser privs. Who knows,
425 * we might close the device immediately without doing a
426 * privileged operation -- cevans
427 */
428 as->suser = capable(CAP_SYS_ADMIN);
429 as->writer = (filp->f_mode & FMODE_WRITE) == FMODE_WRITE;
430 as->reader = (filp->f_mode & FMODE_READ) == FMODE_READ;
431
432 down_write(&user_list_lock);
433 list_add(&as->list, &apm_user_list);
434 up_write(&user_list_lock);
435
436 filp->private_data = as;
437 }
438
439 return as ? 0 : -ENOMEM;
440}
441
442static struct file_operations apm_bios_fops = {
443 .owner = THIS_MODULE,
444 .read = apm_read,
445 .poll = apm_poll,
446 .ioctl = apm_ioctl,
447 .open = apm_open,
448 .release = apm_release,
449};
450
451static struct miscdevice apm_device = {
452 .minor = APM_MINOR_DEV,
453 .name = "apm_bios",
454 .fops = &apm_bios_fops
455};
456
457
458#ifdef CONFIG_PROC_FS
459/*
460 * Arguments, with symbols from linux/apm_bios.h.
461 *
462 * 0) Linux driver version (this will change if format changes)
463 * 1) APM BIOS Version. Usually 1.0, 1.1 or 1.2.
464 * 2) APM flags from APM Installation Check (0x00):
465 * bit 0: APM_16_BIT_SUPPORT
466 * bit 1: APM_32_BIT_SUPPORT
467 * bit 2: APM_IDLE_SLOWS_CLOCK
468 * bit 3: APM_BIOS_DISABLED
469 * bit 4: APM_BIOS_DISENGAGED
470 * 3) AC line status
471 * 0x00: Off-line
472 * 0x01: On-line
473 * 0x02: On backup power (BIOS >= 1.1 only)
474 * 0xff: Unknown
475 * 4) Battery status
476 * 0x00: High
477 * 0x01: Low
478 * 0x02: Critical
479 * 0x03: Charging
480 * 0x04: Selected battery not present (BIOS >= 1.2 only)
481 * 0xff: Unknown
482 * 5) Battery flag
483 * bit 0: High
484 * bit 1: Low
485 * bit 2: Critical
486 * bit 3: Charging
487 * bit 7: No system battery
488 * 0xff: Unknown
489 * 6) Remaining battery life (percentage of charge):
490 * 0-100: valid
491 * -1: Unknown
492 * 7) Remaining battery life (time units):
493 * Number of remaining minutes or seconds
494 * -1: Unknown
495 * 8) min = minutes; sec = seconds
496 */
497static int apm_get_info(char *buf, char **start, off_t fpos, int length)
498{
499 struct apm_power_info info;
500 char *units;
501 int ret;
502
503 info.ac_line_status = 0xff;
504 info.battery_status = 0xff;
505 info.battery_flag = 0xff;
506 info.battery_life = -1;
507 info.time = -1;
508 info.units = -1;
509
510 if (apm_get_power_status)
511 apm_get_power_status(&info);
512
513 switch (info.units) {
514 default: units = "?"; break;
515 case 0: units = "min"; break;
516 case 1: units = "sec"; break;
517 }
518
519 ret = sprintf(buf, "%s 1.2 0x%02x 0x%02x 0x%02x 0x%02x %d%% %d %s\n",
520 driver_version, APM_32_BIT_SUPPORT,
521 info.ac_line_status, info.battery_status,
522 info.battery_flag, info.battery_life,
523 info.time, units);
524
525 return ret;
526}
527#endif
528
529static int kapmd(void *arg)
530{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 do {
532 apm_event_t event;
Russell Kingb729c092006-11-07 21:00:22 +0000533 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534
535 wait_event_interruptible(kapmd_wait,
Serge E. Hallynea33a592006-08-07 11:57:36 -0500536 !queue_empty(&kapmd_queue) || kthread_should_stop());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537
Serge E. Hallynea33a592006-08-07 11:57:36 -0500538 if (kthread_should_stop())
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 break;
540
541 spin_lock_irq(&kapmd_queue_lock);
542 event = 0;
543 if (!queue_empty(&kapmd_queue))
544 event = queue_get_event(&kapmd_queue);
545 spin_unlock_irq(&kapmd_queue_lock);
546
547 switch (event) {
548 case 0:
549 break;
550
551 case APM_LOW_BATTERY:
552 case APM_POWER_STATUS_CHANGE:
Russell Kingb729c092006-11-07 21:00:22 +0000553 queue_event(event);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 break;
555
556 case APM_USER_SUSPEND:
557 case APM_SYS_SUSPEND:
Russell Kingb729c092006-11-07 21:00:22 +0000558 ret = queue_suspend_event(event, NULL);
559 if (ret < 0) {
560 /*
561 * We were busy. Try again in 50ms.
562 */
563 queue_add_event(&kapmd_queue, event);
564 msleep(50);
565 }
566 if (ret > 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 apm_suspend();
568 break;
569
570 case APM_CRITICAL_SUSPEND:
571 apm_suspend();
572 break;
573 }
574 } while (1);
575
Serge E. Hallynea33a592006-08-07 11:57:36 -0500576 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577}
578
579static int __init apm_init(void)
580{
581 int ret;
582
583 if (apm_disabled) {
584 printk(KERN_NOTICE "apm: disabled on user request.\n");
585 return -ENODEV;
586 }
587
Serge E. Hallynea33a592006-08-07 11:57:36 -0500588 kapmd_tsk = kthread_create(kapmd, NULL, "kapmd");
589 if (IS_ERR(kapmd_tsk)) {
590 ret = PTR_ERR(kapmd_tsk);
591 kapmd_tsk = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 return ret;
593 }
Serge E. Hallynea33a592006-08-07 11:57:36 -0500594 kapmd_tsk->flags |= PF_NOFREEZE;
595 wake_up_process(kapmd_tsk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596
597#ifdef CONFIG_PROC_FS
598 create_proc_info_entry("apm", 0, NULL, apm_get_info);
599#endif
600
601 ret = misc_register(&apm_device);
602 if (ret != 0) {
603 remove_proc_entry("apm", NULL);
Serge E. Hallynea33a592006-08-07 11:57:36 -0500604 kthread_stop(kapmd_tsk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 }
606
607 return ret;
608}
609
610static void __exit apm_exit(void)
611{
612 misc_deregister(&apm_device);
613 remove_proc_entry("apm", NULL);
614
Serge E. Hallynea33a592006-08-07 11:57:36 -0500615 kthread_stop(kapmd_tsk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616}
617
618module_init(apm_init);
619module_exit(apm_exit);
620
621MODULE_AUTHOR("Stephen Rothwell");
622MODULE_DESCRIPTION("Advanced Power Management");
623MODULE_LICENSE("GPL");
624
625#ifndef MODULE
626static int __init apm_setup(char *str)
627{
628 while ((str != NULL) && (*str != '\0')) {
629 if (strncmp(str, "off", 3) == 0)
630 apm_disabled = 1;
631 if (strncmp(str, "on", 2) == 0)
632 apm_disabled = 0;
633 str = strchr(str, ',');
634 if (str != NULL)
635 str += strspn(str, ", \t");
636 }
637 return 1;
638}
639
640__setup("apm=", apm_setup);
641#endif
642
643/**
644 * apm_queue_event - queue an APM event for kapmd
645 * @event: APM event
646 *
647 * Queue an APM event for kapmd to process and ultimately take the
648 * appropriate action. Only a subset of events are handled:
649 * %APM_LOW_BATTERY
650 * %APM_POWER_STATUS_CHANGE
651 * %APM_USER_SUSPEND
652 * %APM_SYS_SUSPEND
653 * %APM_CRITICAL_SUSPEND
654 */
655void apm_queue_event(apm_event_t event)
656{
657 unsigned long flags;
658
659 spin_lock_irqsave(&kapmd_queue_lock, flags);
660 queue_add_event(&kapmd_queue, event);
661 spin_unlock_irqrestore(&kapmd_queue_lock, flags);
662
663 wake_up_interruptible(&kapmd_wait);
664}
665EXPORT_SYMBOL(apm_queue_event);