]>
Commit | Line | Data |
---|---|---|
3f86b832 RT |
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> | |
3f86b832 | 30 | |
a192a958 LB |
31 | #define PREFIX "ACPI: " |
32 | ||
f52fd66d | 33 | ACPI_MODULE_NAME("cm_sbs"); |
3f86b832 RT |
34 | #define ACPI_AC_CLASS "ac_adapter" |
35 | #define ACPI_BATTERY_CLASS "battery" | |
3f86b832 RT |
36 | #define _COMPONENT ACPI_SBS_COMPONENT |
37 | static struct proc_dir_entry *acpi_ac_dir; | |
38 | static struct proc_dir_entry *acpi_battery_dir; | |
39 | ||
8970bfe7 | 40 | static DEFINE_MUTEX(cm_sbs_mutex); |
3f86b832 | 41 | |
8970bfe7 AM |
42 | static int lock_ac_dir_cnt; |
43 | static int lock_battery_dir_cnt; | |
3f86b832 RT |
44 | |
45 | struct proc_dir_entry *acpi_lock_ac_dir(void) | |
46 | { | |
8970bfe7 AM |
47 | mutex_lock(&cm_sbs_mutex); |
48 | if (!acpi_ac_dir) | |
3f86b832 | 49 | acpi_ac_dir = proc_mkdir(ACPI_AC_CLASS, acpi_root_dir); |
3f86b832 RT |
50 | if (acpi_ac_dir) { |
51 | lock_ac_dir_cnt++; | |
52 | } else { | |
55ac9a01 LM |
53 | printk(KERN_ERR PREFIX |
54 | "Cannot create %s\n", ACPI_AC_CLASS); | |
3f86b832 | 55 | } |
8970bfe7 | 56 | mutex_unlock(&cm_sbs_mutex); |
635227ee | 57 | return acpi_ac_dir; |
3f86b832 | 58 | } |
3f86b832 RT |
59 | EXPORT_SYMBOL(acpi_lock_ac_dir); |
60 | ||
61 | void acpi_unlock_ac_dir(struct proc_dir_entry *acpi_ac_dir_param) | |
62 | { | |
8970bfe7 AM |
63 | mutex_lock(&cm_sbs_mutex); |
64 | if (acpi_ac_dir_param) | |
3f86b832 | 65 | lock_ac_dir_cnt--; |
3f86b832 RT |
66 | if (lock_ac_dir_cnt == 0 && acpi_ac_dir_param && acpi_ac_dir) { |
67 | remove_proc_entry(ACPI_AC_CLASS, acpi_root_dir); | |
4370df97 | 68 | acpi_ac_dir = NULL; |
3f86b832 | 69 | } |
8970bfe7 | 70 | mutex_unlock(&cm_sbs_mutex); |
3f86b832 | 71 | } |
3f86b832 RT |
72 | EXPORT_SYMBOL(acpi_unlock_ac_dir); |
73 | ||
74 | struct proc_dir_entry *acpi_lock_battery_dir(void) | |
75 | { | |
8970bfe7 | 76 | mutex_lock(&cm_sbs_mutex); |
3f86b832 RT |
77 | if (!acpi_battery_dir) { |
78 | acpi_battery_dir = | |
79 | proc_mkdir(ACPI_BATTERY_CLASS, acpi_root_dir); | |
80 | } | |
81 | if (acpi_battery_dir) { | |
82 | lock_battery_dir_cnt++; | |
83 | } else { | |
55ac9a01 LM |
84 | printk(KERN_ERR PREFIX |
85 | "Cannot create %s\n", ACPI_BATTERY_CLASS); | |
3f86b832 | 86 | } |
8970bfe7 | 87 | mutex_unlock(&cm_sbs_mutex); |
635227ee | 88 | return acpi_battery_dir; |
3f86b832 | 89 | } |
3f86b832 RT |
90 | EXPORT_SYMBOL(acpi_lock_battery_dir); |
91 | ||
92 | void acpi_unlock_battery_dir(struct proc_dir_entry *acpi_battery_dir_param) | |
93 | { | |
8970bfe7 AM |
94 | mutex_lock(&cm_sbs_mutex); |
95 | if (acpi_battery_dir_param) | |
3f86b832 | 96 | lock_battery_dir_cnt--; |
3f86b832 RT |
97 | if (lock_battery_dir_cnt == 0 && acpi_battery_dir_param |
98 | && acpi_battery_dir) { | |
99 | remove_proc_entry(ACPI_BATTERY_CLASS, acpi_root_dir); | |
4370df97 | 100 | acpi_battery_dir = NULL; |
3f86b832 | 101 | } |
8970bfe7 | 102 | mutex_unlock(&cm_sbs_mutex); |
635227ee | 103 | return; |
3f86b832 | 104 | } |
3f86b832 | 105 | EXPORT_SYMBOL(acpi_unlock_battery_dir); |