Merge branch 'irq-fixes-for-linus-4' of git://git.kernel.org/pub/scm/linux/kernel...
[deliverable/linux.git] / drivers / acpi / cm_sbs.c
CommitLineData
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>
30#include <acpi/acmacros.h>
31#include <acpi/actypes.h>
32#include <acpi/acutils.h>
33
f52fd66d 34ACPI_MODULE_NAME("cm_sbs");
3f86b832
RT
35#define ACPI_AC_CLASS "ac_adapter"
36#define ACPI_BATTERY_CLASS "battery"
3f86b832
RT
37#define _COMPONENT ACPI_SBS_COMPONENT
38static struct proc_dir_entry *acpi_ac_dir;
39static struct proc_dir_entry *acpi_battery_dir;
40
8970bfe7 41static DEFINE_MUTEX(cm_sbs_mutex);
3f86b832 42
8970bfe7
AM
43static int lock_ac_dir_cnt;
44static int lock_battery_dir_cnt;
3f86b832
RT
45
46struct proc_dir_entry *acpi_lock_ac_dir(void)
47{
8970bfe7
AM
48 mutex_lock(&cm_sbs_mutex);
49 if (!acpi_ac_dir)
3f86b832 50 acpi_ac_dir = proc_mkdir(ACPI_AC_CLASS, acpi_root_dir);
3f86b832
RT
51 if (acpi_ac_dir) {
52 lock_ac_dir_cnt++;
53 } else {
55ac9a01
LM
54 printk(KERN_ERR PREFIX
55 "Cannot create %s\n", ACPI_AC_CLASS);
3f86b832 56 }
8970bfe7 57 mutex_unlock(&cm_sbs_mutex);
635227ee 58 return acpi_ac_dir;
3f86b832 59}
3f86b832
RT
60EXPORT_SYMBOL(acpi_lock_ac_dir);
61
62void acpi_unlock_ac_dir(struct proc_dir_entry *acpi_ac_dir_param)
63{
8970bfe7
AM
64 mutex_lock(&cm_sbs_mutex);
65 if (acpi_ac_dir_param)
3f86b832 66 lock_ac_dir_cnt--;
3f86b832
RT
67 if (lock_ac_dir_cnt == 0 && acpi_ac_dir_param && acpi_ac_dir) {
68 remove_proc_entry(ACPI_AC_CLASS, acpi_root_dir);
4370df97 69 acpi_ac_dir = NULL;
3f86b832 70 }
8970bfe7 71 mutex_unlock(&cm_sbs_mutex);
3f86b832 72}
3f86b832
RT
73EXPORT_SYMBOL(acpi_unlock_ac_dir);
74
75struct proc_dir_entry *acpi_lock_battery_dir(void)
76{
8970bfe7 77 mutex_lock(&cm_sbs_mutex);
3f86b832
RT
78 if (!acpi_battery_dir) {
79 acpi_battery_dir =
80 proc_mkdir(ACPI_BATTERY_CLASS, acpi_root_dir);
81 }
82 if (acpi_battery_dir) {
83 lock_battery_dir_cnt++;
84 } else {
55ac9a01
LM
85 printk(KERN_ERR PREFIX
86 "Cannot create %s\n", ACPI_BATTERY_CLASS);
3f86b832 87 }
8970bfe7 88 mutex_unlock(&cm_sbs_mutex);
635227ee 89 return acpi_battery_dir;
3f86b832 90}
3f86b832
RT
91EXPORT_SYMBOL(acpi_lock_battery_dir);
92
93void acpi_unlock_battery_dir(struct proc_dir_entry *acpi_battery_dir_param)
94{
8970bfe7
AM
95 mutex_lock(&cm_sbs_mutex);
96 if (acpi_battery_dir_param)
3f86b832 97 lock_battery_dir_cnt--;
3f86b832
RT
98 if (lock_battery_dir_cnt == 0 && acpi_battery_dir_param
99 && acpi_battery_dir) {
100 remove_proc_entry(ACPI_BATTERY_CLASS, acpi_root_dir);
4370df97 101 acpi_battery_dir = NULL;
3f86b832 102 }
8970bfe7 103 mutex_unlock(&cm_sbs_mutex);
635227ee 104 return;
3f86b832 105}
3f86b832 106EXPORT_SYMBOL(acpi_unlock_battery_dir);
This page took 0.248708 seconds and 5 git commands to generate.