More Makefile cleanups, otherwise mainly noticeable are the netfilter fix
[davej-history.git] / drivers / acpi / power.c
blob0422bf94dfd9bd0d50fdf75cd1327607133b1c84
1 /*
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>
24 #include "acpi.h"
25 #include "driver.h"
27 #define _COMPONENT OS_DEPENDENT
28 MODULE_NAME ("power")
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
42 static ACPI_STATUS
43 acpi_found_ac_adapter(ACPI_HANDLE handle, u32 level, void *ctx, void **value)
45 ACPI_DEVICE_INFO info;
47 if (ac_count > 0) {
48 printk(KERN_ERR "AC Adapter: more than one!\n");
49 return (AE_OK);
52 if (!ACPI_SUCCESS(acpi_get_object_info(handle, &info))) {
53 printk(KERN_ERR "AC Adapter: Could not get AC Adapter object info\n");
54 return (AE_OK);
57 if (!(info.valid & ACPI_VALID_STA)) {
58 printk(KERN_ERR "AC Adapter: Battery _STA invalid\n");
59 return AE_OK;
62 printk(KERN_INFO "AC Adapter: found\n");
64 ac_handle = handle;
66 ac_count++;
68 return AE_OK;
71 static int
72 proc_read_ac_adapter_status(char *page, char **start, off_t off,
73 int count, int *eof, void *data)
75 ACPI_OBJECT obj;
76 ACPI_BUFFER buf;
78 char *p = page;
79 int len;
81 buf.length = sizeof(obj);
82 buf.pointer = &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");
86 goto end;
89 if (obj.number.value)
90 p += sprintf(p, "on-line\n");
91 else
92 p += sprintf(p, "off-line\n");
94 end:
95 len = (p - page);
96 if (len <= off+count) *eof = 1;
97 *start = page + off;
98 len -= off;
99 if (len>count) len = count;
100 if (len<0) len = 0;
101 return len;
105 acpi_power_init(void)
107 acpi_get_devices(ACPI_AC_ADAPTER_HID,
108 acpi_found_ac_adapter,
109 NULL,
110 NULL);
112 if (!proc_mkdir("power", NULL))
113 return 0;
115 if (ac_handle) {
116 create_proc_read_entry("power/ac", 0, NULL,
117 proc_read_ac_adapter_status, NULL);
120 acpi_cmbatt_init();
122 return 0;
126 acpi_power_terminate(void)
128 acpi_cmbatt_terminate();
130 if (ac_handle) {
131 remove_proc_entry("power/ac", NULL);
134 remove_proc_entry("power", NULL);
136 return 0;