2 * power.c - Overall power driver. Also handles AC adapter device.
4 * Copyright (C) 2000 Andrew Grover
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include <linux/kernel.h>
22 #include <linux/types.h>
23 #include <linux/proc_fs.h>
27 #define _COMPONENT OS_DEPENDENT
30 int acpi_cmbatt_init(void);
31 int acpi_cmbatt_terminate(void);
33 /* ACPI-specific defines */
34 #define ACPI_AC_ADAPTER_HID "ACPI0003"
36 static int ac_count
= 0;
37 static ACPI_HANDLE ac_handle
= 0;
40 * We found a device with the correct HID
43 acpi_found_ac_adapter(ACPI_HANDLE handle
, u32 level
, void *ctx
, void **value
)
45 ACPI_DEVICE_INFO info
;
48 printk(KERN_ERR
"AC Adapter: more than one!\n");
52 if (!ACPI_SUCCESS(acpi_get_object_info(handle
, &info
))) {
53 printk(KERN_ERR
"AC Adapter: Could not get AC Adapter object info\n");
57 if (!(info
.valid
& ACPI_VALID_STA
)) {
58 printk(KERN_ERR
"AC Adapter: Battery _STA invalid\n");
62 printk(KERN_INFO
"AC Adapter: found\n");
72 proc_read_ac_adapter_status(char *page
, char **start
, off_t off
,
73 int count
, int *eof
, void *data
)
81 buf
.length
= sizeof(obj
);
83 if (!ACPI_SUCCESS(acpi_evaluate_object(ac_handle
, "_PSR", NULL
, &buf
))
84 || obj
.type
!= ACPI_TYPE_NUMBER
) {
85 p
+= sprintf(p
, "Could not read AC status\n");
90 p
+= sprintf(p
, "on-line\n");
92 p
+= sprintf(p
, "off-line\n");
96 if (len
<= off
+count
) *eof
= 1;
99 if (len
>count
) len
= count
;
105 acpi_power_init(void)
107 acpi_get_devices(ACPI_AC_ADAPTER_HID
,
108 acpi_found_ac_adapter
,
112 if (!proc_mkdir("power", NULL
))
116 create_proc_read_entry("power/ac", 0, NULL
,
117 proc_read_ac_adapter_status
, NULL
);
126 acpi_power_terminate(void)
128 acpi_cmbatt_terminate();
131 remove_proc_entry("power/ac", NULL
);
134 remove_proc_entry("power", NULL
);