View | Details | Raw Unified | Return to bug 124223
Collapse All | Expand All

(-)acpi_battery.c (+88 lines)
Lines 31-40 Link Here
31
#include "opt_acpi.h"
31
#include "opt_acpi.h"
32
#include <sys/param.h>
32
#include <sys/param.h>
33
#include <sys/kernel.h>
33
#include <sys/kernel.h>
34
#include <sys/kthread.h>
34
#include <sys/malloc.h>
35
#include <sys/malloc.h>
35
#include <sys/bus.h>
36
#include <sys/bus.h>
36
#include <sys/ioccom.h>
37
#include <sys/ioccom.h>
37
#include <sys/sysctl.h>
38
#include <sys/sysctl.h>
39
#include <sys/unistd.h>
38
40
39
#include <contrib/dev/acpica/acpi.h>
41
#include <contrib/dev/acpica/acpi.h>
40
#include <dev/acpica/acpivar.h>
42
#include <dev/acpica/acpivar.h>
Lines 43-48 Link Here
43
/* Default seconds before re-sampling the battery state. */
45
/* Default seconds before re-sampling the battery state. */
44
#define	ACPI_BATTERY_INFO_EXPIRE	5
46
#define	ACPI_BATTERY_INFO_EXPIRE	5
45
47
48
/* Check for battery low level each 60 seconds */
49
#define BATT_POLLRATE 60
50
51
/* Default level to notify devd */
52
#define BATT_LOWLEVEL 5
53
54
#define BATT_NOTIFY_LOWLEVEL    0x80
55
46
static int	acpi_batteries_initted;
56
static int	acpi_batteries_initted;
47
static int	acpi_battery_info_expire = ACPI_BATTERY_INFO_EXPIRE;
57
static int	acpi_battery_info_expire = ACPI_BATTERY_INFO_EXPIRE;
48
static struct	acpi_battinfo	acpi_battery_battinfo;
58
static struct	acpi_battinfo	acpi_battery_battinfo;
Lines 56-63 Link Here
56
static device_t acpi_battery_find_dev(u_int logical_unit);
66
static device_t acpi_battery_find_dev(u_int logical_unit);
57
static int acpi_battery_ioctl(u_long cmd, caddr_t addr, void *arg);
67
static int acpi_battery_ioctl(u_long cmd, caddr_t addr, void *arg);
58
static int acpi_battery_sysctl(SYSCTL_HANDLER_ARGS);
68
static int acpi_battery_sysctl(SYSCTL_HANDLER_ARGS);
69
static int acpi_battery_rate_sysctl(SYSCTL_HANDLER_ARGS);
70
static int acpi_battery_crit_sysctl(SYSCTL_HANDLER_ARGS);
59
static int acpi_battery_units_sysctl(SYSCTL_HANDLER_ARGS);
71
static int acpi_battery_units_sysctl(SYSCTL_HANDLER_ARGS);
60
static int acpi_battery_init(void);
72
static int acpi_battery_init(void);
73
static void acpi_battery_thread(void *);
74
75
static struct proc  *acpi_battery_proc;
76
static int acpi_battery_pollrate = BATT_POLLRATE;
77
static int acpi_battery_lowlevel = BATT_LOWLEVEL;
78
static int acpi_battery_previous = -1;
61
79
62
int
80
int
63
acpi_battery_register(device_t dev)
81
acpi_battery_register(device_t dev)
Lines 69-74 Link Here
69
    if (!acpi_batteries_initted)
87
    if (!acpi_batteries_initted)
70
	error = acpi_battery_init();
88
	error = acpi_battery_init();
71
    ACPI_SERIAL_END(battery);
89
    ACPI_SERIAL_END(battery);
90
    if(error) return (error);
91
    error = kproc_create(acpi_battery_thread, NULL, &acpi_battery_proc, RFHIGHPID, 0, "acpi_battery");
72
    return (error);
92
    return (error);
73
}
93
}
74
94
Lines 422-427 Link Here
422
}
442
}
423
443
424
static int
444
static int
445
acpi_battery_rate_sysctl(SYSCTL_HANDLER_ARGS)
446
{
447
    int error;
448
449
    error = sysctl_handle_int(oidp, &acpi_battery_pollrate, 0, req);
450
451
    if(error || !req->newptr)
452
        return (error);
453
    
454
    acpi_battery_pollrate = *(int *)req->newptr;
455
456
    wakeup(&acpi_battery_proc);
457
    return (error);
458
}
459
460
static int
461
acpi_battery_crit_sysctl(SYSCTL_HANDLER_ARGS)
462
{
463
    int error;
464
465
    error = sysctl_handle_int(oidp, &acpi_battery_lowlevel, 0, req);
466
    
467
    if(error || !req->newptr)
468
        return (error);
469
470
    acpi_battery_lowlevel = *(int *)req->newptr;
471
    return (error);
472
}
473
474
static int
425
acpi_battery_units_sysctl(SYSCTL_HANDLER_ARGS)
475
acpi_battery_units_sysctl(SYSCTL_HANDLER_ARGS)
426
{
476
{
427
    int count, error;
477
    int count, error;
Lines 489-494 Link Here
489
	OID_AUTO, "info_expire", CTLFLAG_RW,
539
	OID_AUTO, "info_expire", CTLFLAG_RW,
490
	&acpi_battery_info_expire, 0,
540
	&acpi_battery_info_expire, 0,
491
	"time in seconds until info is refreshed");
541
	"time in seconds until info is refreshed");
542
    SYSCTL_ADD_PROC(&acpi_battery_sysctl_ctx,
543
	SYSCTL_CHILDREN(acpi_battery_sysctl_tree),
544
	OID_AUTO, "polling_rate", CTLTYPE_INT | CTLFLAG_RW,
545
	NULL, 0, acpi_battery_rate_sysctl, "I",
546
	"polling rate in seconds");
547
    SYSCTL_ADD_PROC(&acpi_battery_sysctl_ctx,
548
	SYSCTL_CHILDREN(acpi_battery_sysctl_tree),
549
	OID_AUTO, "critical_level", CTLTYPE_INT | CTLFLAG_RW,
550
	NULL, 0, acpi_battery_crit_sysctl, "I",
551
	"critical level in percent");
492
552
493
    acpi_batteries_initted = TRUE;
553
    acpi_batteries_initted = TRUE;
494
554
Lines 501-503 Link Here
501
    }
561
    }
502
    return (error);
562
    return (error);
503
}
563
}
564
565
/*
566
 * ACPI Battery monitor thread
567
 */
568
static void
569
acpi_battery_thread(void *arg)
570
{
571
    (void) arg; /* not used */
572
    struct acpi_battinfo    battinfo;
573
    device_t                dev;
574
    ACPI_HANDLE             h;
575
576
    if(!(dev = devclass_get_device(devclass_find("acpi"), 0)))
577
        return;
578
579
    h = acpi_get_handle(dev);
580
581
    while(1)
582
    {
583
        if(!acpi_battery_get_battinfo(NULL, &battinfo))
584
        {
585
            if(battinfo.cap <= acpi_battery_lowlevel && battinfo.cap < acpi_battery_previous)
586
                acpi_UserNotify("Battery", h, BATT_NOTIFY_LOWLEVEL);
587
            acpi_battery_previous = battinfo.cap;
588
        }
589
        tsleep(&acpi_battery_proc, 0, "batpol", hz * acpi_battery_pollrate);
590
    }
591
}

Return to bug 124223