]>
Commit | Line | Data |
---|---|---|
e2a7c3d7 LT |
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 | * | |
e2a7c3d7 LT |
14 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
15 | */ | |
16 | ||
17 | #include <linux/kernel.h> | |
18 | #include <linux/module.h> | |
19 | #include <linux/init.h> | |
20 | #include <linux/acpi.h> | |
21 | #include <linux/types.h> | |
22 | #include <linux/proc_fs.h> | |
23 | #include <linux/seq_file.h> | |
24 | #include <acpi/acpi_bus.h> | |
25 | #include <acpi/acpi_drivers.h> | |
26 | ||
27 | #define PREFIX "ACPI: " | |
28 | ||
29 | ACPI_MODULE_NAME("cm_sbs"); | |
30 | #define ACPI_AC_CLASS "ac_adapter" | |
31 | #define ACPI_BATTERY_CLASS "battery" | |
32 | #define _COMPONENT ACPI_SBS_COMPONENT | |
33 | static struct proc_dir_entry *acpi_ac_dir; | |
34 | static struct proc_dir_entry *acpi_battery_dir; | |
35 | ||
36 | static DEFINE_MUTEX(cm_sbs_mutex); | |
37 | ||
38 | static int lock_ac_dir_cnt; | |
39 | static int lock_battery_dir_cnt; | |
40 | ||
41 | struct proc_dir_entry *acpi_lock_ac_dir(void) | |
42 | { | |
43 | mutex_lock(&cm_sbs_mutex); | |
44 | if (!acpi_ac_dir) | |
45 | acpi_ac_dir = proc_mkdir(ACPI_AC_CLASS, acpi_root_dir); | |
46 | if (acpi_ac_dir) { | |
47 | lock_ac_dir_cnt++; | |
48 | } else { | |
49 | printk(KERN_ERR PREFIX | |
50 | "Cannot create %s\n", ACPI_AC_CLASS); | |
51 | } | |
52 | mutex_unlock(&cm_sbs_mutex); | |
53 | return acpi_ac_dir; | |
54 | } | |
55 | EXPORT_SYMBOL(acpi_lock_ac_dir); | |
56 | ||
57 | void acpi_unlock_ac_dir(struct proc_dir_entry *acpi_ac_dir_param) | |
58 | { | |
59 | mutex_lock(&cm_sbs_mutex); | |
60 | if (acpi_ac_dir_param) | |
61 | lock_ac_dir_cnt--; | |
62 | if (lock_ac_dir_cnt == 0 && acpi_ac_dir_param && acpi_ac_dir) { | |
63 | remove_proc_entry(ACPI_AC_CLASS, acpi_root_dir); | |
64 | acpi_ac_dir = NULL; | |
65 | } | |
66 | mutex_unlock(&cm_sbs_mutex); | |
67 | } | |
68 | EXPORT_SYMBOL(acpi_unlock_ac_dir); | |
69 | ||
70 | struct proc_dir_entry *acpi_lock_battery_dir(void) | |
71 | { | |
72 | mutex_lock(&cm_sbs_mutex); | |
73 | if (!acpi_battery_dir) { | |
74 | acpi_battery_dir = | |
75 | proc_mkdir(ACPI_BATTERY_CLASS, acpi_root_dir); | |
76 | } | |
77 | if (acpi_battery_dir) { | |
78 | lock_battery_dir_cnt++; | |
79 | } else { | |
80 | printk(KERN_ERR PREFIX | |
81 | "Cannot create %s\n", ACPI_BATTERY_CLASS); | |
82 | } | |
83 | mutex_unlock(&cm_sbs_mutex); | |
84 | return acpi_battery_dir; | |
85 | } | |
86 | EXPORT_SYMBOL(acpi_lock_battery_dir); | |
87 | ||
88 | void acpi_unlock_battery_dir(struct proc_dir_entry *acpi_battery_dir_param) | |
89 | { | |
90 | mutex_lock(&cm_sbs_mutex); | |
91 | if (acpi_battery_dir_param) | |
92 | lock_battery_dir_cnt--; | |
93 | if (lock_battery_dir_cnt == 0 && acpi_battery_dir_param | |
94 | && acpi_battery_dir) { | |
95 | remove_proc_entry(ACPI_BATTERY_CLASS, acpi_root_dir); | |
96 | acpi_battery_dir = NULL; | |
97 | } | |
98 | mutex_unlock(&cm_sbs_mutex); | |
99 | return; | |
100 | } | |
101 | EXPORT_SYMBOL(acpi_unlock_battery_dir); |