~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Linux/drivers/acpi/power.c

Version: ~ [ 2.4.0 ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  *  power.c - Overall power driver. Also handles AC adapter device.
  3  *
  4  *  Copyright (C) 2000 Andrew Grover
  5  *
  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.
 10  *
 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.
 15  *
 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
 19  */
 20 
 21 #include <linux/kernel.h>
 22 #include <linux/types.h>
 23 #include <linux/proc_fs.h>
 24 #include "acpi.h"
 25 #include "driver.h"
 26 
 27 #define _COMPONENT      OS_DEPENDENT
 28         MODULE_NAME     ("power")
 29 
 30 int acpi_cmbatt_init(void);
 31 int acpi_cmbatt_terminate(void);
 32 
 33 /* ACPI-specific defines */
 34 #define ACPI_AC_ADAPTER_HID     "ACPI0003"
 35 
 36 static int ac_count = 0;
 37 static ACPI_HANDLE ac_handle = 0;
 38 
 39 /*
 40  * We found a device with the correct HID
 41  */
 42 static ACPI_STATUS
 43 acpi_found_ac_adapter(ACPI_HANDLE handle, u32 level, void *ctx, void **value)
 44 {
 45         ACPI_DEVICE_INFO        info;
 46 
 47         if (ac_count > 0) {
 48                 printk(KERN_ERR "AC Adapter: more than one!\n");
 49                 return (AE_OK);
 50         }
 51 
 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);
 55         }
 56 
 57         if (!(info.valid & ACPI_VALID_STA)) {
 58                 printk(KERN_ERR "AC Adapter: Battery _STA invalid\n");
 59                 return AE_OK;
 60         }
 61 
 62         printk(KERN_INFO "AC Adapter: found\n");
 63 
 64         ac_handle = handle;
 65 
 66         ac_count++;
 67 
 68         return AE_OK;
 69 }
 70 
 71 static int
 72 proc_read_ac_adapter_status(char *page, char **start, off_t off,
 73                                 int count, int *eof, void *data)
 74 {
 75         ACPI_OBJECT obj;
 76         ACPI_BUFFER buf;
 77 
 78         char *p = page;
 79         int len;
 80 
 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;
 87         }
 88 
 89         if (obj.number.value)
 90                 p += sprintf(p, "on-line\n");
 91         else
 92                 p += sprintf(p, "off-line\n");
 93 
 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;
102 }
103 
104 int
105 acpi_power_init(void)
106 {
107         acpi_get_devices(ACPI_AC_ADAPTER_HID, 
108                         acpi_found_ac_adapter,
109                         NULL,
110                         NULL);
111 
112         if (!proc_mkdir("power", NULL))
113                 return 0;
114 
115         if (ac_handle) {
116                 create_proc_read_entry("power/ac", 0, NULL,
117                         proc_read_ac_adapter_status, NULL);
118         }
119 
120         acpi_cmbatt_init();
121 
122         return 0;
123 }
124 
125 int
126 acpi_power_terminate(void)
127 {
128         acpi_cmbatt_terminate();
129 
130         if (ac_handle) {
131                 remove_proc_entry("power/ac", NULL);
132         }
133 
134         remove_proc_entry("power", NULL);
135 
136         return 0;
137 }
138 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.