aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/acpi/cm_sbs.c
diff options
context:
space:
mode:
authorRich Townsend <rhdt@bartol.udel.edu>2006-07-01 11:36:54 -0400
committerLen Brown <len.brown@intel.com>2006-07-01 16:36:14 -0400
commit3f86b83243d59bb50caf5938d284d22e10d082a4 (patch)
treeebc93aff4abae0b3f4aa96c19973782eede3411d /drivers/acpi/cm_sbs.c
parent37672d4c5263d54ee4302f55242f6fd5317b0f9f (diff)
ACPI: add support for Smart Battery
Most batteries today are ACPI "Control Method" batteries, but some models ship with the older "Smart Battery" that requires this code. Rich Townsend and Bruno Ducrot were the original authors. Vladimir Lebedev updated to run on latest kernel. http://bugzilla.kernel.org/show_bug.cgi?id=3734 Signed-off-by: Len Brown <len.brown@intel.com>
Diffstat (limited to 'drivers/acpi/cm_sbs.c')
-rw-r--r--drivers/acpi/cm_sbs.c135
1 files changed, 135 insertions, 0 deletions
diff --git a/drivers/acpi/cm_sbs.c b/drivers/acpi/cm_sbs.c
new file mode 100644
index 000000000000..d11507c7b8a4
--- /dev/null
+++ b/drivers/acpi/cm_sbs.c
@@ -0,0 +1,135 @@
1/*
2 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or (at
7 * your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17 *
18 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
19 */
20
21#include <linux/kernel.h>
22#include <linux/module.h>
23#include <linux/init.h>
24#include <linux/acpi.h>
25#include <linux/types.h>
26#include <linux/proc_fs.h>
27#include <linux/seq_file.h>
28#include <acpi/acpi_bus.h>
29#include <acpi/acpi_drivers.h>
30#include <acpi/acmacros.h>
31#include <acpi/actypes.h>
32#include <acpi/acutils.h>
33
34ACPI_MODULE_NAME("cm_sbs")
35#define ACPI_AC_CLASS "ac_adapter"
36#define ACPI_BATTERY_CLASS "battery"
37#define ACPI_SBS_COMPONENT 0x00080000
38#define _COMPONENT ACPI_SBS_COMPONENT
39static struct proc_dir_entry *acpi_ac_dir;
40static struct proc_dir_entry *acpi_battery_dir;
41
42static struct semaphore cm_sbs_sem;
43
44static int lock_ac_dir_cnt = 0;
45static int lock_battery_dir_cnt = 0;
46
47struct proc_dir_entry *acpi_lock_ac_dir(void)
48{
49 ACPI_FUNCTION_TRACE("acpi_lock_ac_dir");
50
51 down(&cm_sbs_sem);
52 if (!acpi_ac_dir) {
53 acpi_ac_dir = proc_mkdir(ACPI_AC_CLASS, acpi_root_dir);
54 }
55 if (acpi_ac_dir) {
56 lock_ac_dir_cnt++;
57 } else {
58 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
59 "Cannot create %s\n", ACPI_AC_CLASS));
60 }
61 up(&cm_sbs_sem);
62 return (acpi_ac_dir);
63}
64
65EXPORT_SYMBOL(acpi_lock_ac_dir);
66
67void acpi_unlock_ac_dir(struct proc_dir_entry *acpi_ac_dir_param)
68{
69 ACPI_FUNCTION_TRACE("acpi_unlock_ac_dir");
70
71 down(&cm_sbs_sem);
72 if (acpi_ac_dir_param) {
73 lock_ac_dir_cnt--;
74 }
75 if (lock_ac_dir_cnt == 0 && acpi_ac_dir_param && acpi_ac_dir) {
76 remove_proc_entry(ACPI_AC_CLASS, acpi_root_dir);
77 acpi_ac_dir = 0;
78 }
79 up(&cm_sbs_sem);
80}
81
82EXPORT_SYMBOL(acpi_unlock_ac_dir);
83
84struct proc_dir_entry *acpi_lock_battery_dir(void)
85{
86 ACPI_FUNCTION_TRACE("acpi_lock_battery_dir");
87
88 down(&cm_sbs_sem);
89 if (!acpi_battery_dir) {
90 acpi_battery_dir =
91 proc_mkdir(ACPI_BATTERY_CLASS, acpi_root_dir);
92 }
93 if (acpi_battery_dir) {
94 lock_battery_dir_cnt++;
95 } else {
96 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
97 "Cannot create %s\n", ACPI_BATTERY_CLASS));
98 }
99 up(&cm_sbs_sem);
100 return (acpi_battery_dir);
101}
102
103EXPORT_SYMBOL(acpi_lock_battery_dir);
104
105void acpi_unlock_battery_dir(struct proc_dir_entry *acpi_battery_dir_param)
106{
107 ACPI_FUNCTION_TRACE("acpi_unlock_battery_dir");
108
109 down(&cm_sbs_sem);
110 if (acpi_battery_dir_param) {
111 lock_battery_dir_cnt--;
112 }
113 if (lock_battery_dir_cnt == 0 && acpi_battery_dir_param
114 && acpi_battery_dir) {
115 remove_proc_entry(ACPI_BATTERY_CLASS, acpi_root_dir);
116 acpi_battery_dir = 0;
117 }
118 up(&cm_sbs_sem);
119}
120
121EXPORT_SYMBOL(acpi_unlock_battery_dir);
122
123static int __init acpi_cm_sbs_init(void)
124{
125 ACPI_FUNCTION_TRACE("acpi_cm_sbs_init");
126
127 if (acpi_disabled)
128 return_VALUE(0);
129
130 init_MUTEX(&cm_sbs_sem);
131
132 return_VALUE(0);
133}
134
135subsys_initcall(acpi_cm_sbs_init);