blob: 6c9ee68e46fb0a1873d05d03b2ec4ce74b72921f [file] [log] [blame]
Rich Townsend3f86b832006-07-01 11:36:54 -04001/*
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>
Rich Townsend3f86b832006-07-01 11:36:54 -040030
Len Browna192a952009-07-28 16:45:54 -040031#define PREFIX "ACPI: "
32
Len Brownf52fd662007-02-12 22:42:12 -050033ACPI_MODULE_NAME("cm_sbs");
Rich Townsend3f86b832006-07-01 11:36:54 -040034#define ACPI_AC_CLASS "ac_adapter"
35#define ACPI_BATTERY_CLASS "battery"
Rich Townsend3f86b832006-07-01 11:36:54 -040036#define _COMPONENT ACPI_SBS_COMPONENT
37static struct proc_dir_entry *acpi_ac_dir;
38static struct proc_dir_entry *acpi_battery_dir;
39
Andrew Morton8970bfe2006-07-10 02:34:45 -040040static DEFINE_MUTEX(cm_sbs_mutex);
Rich Townsend3f86b832006-07-01 11:36:54 -040041
Andrew Morton8970bfe2006-07-10 02:34:45 -040042static int lock_ac_dir_cnt;
43static int lock_battery_dir_cnt;
Rich Townsend3f86b832006-07-01 11:36:54 -040044
45struct proc_dir_entry *acpi_lock_ac_dir(void)
46{
Andrew Morton8970bfe2006-07-10 02:34:45 -040047 mutex_lock(&cm_sbs_mutex);
48 if (!acpi_ac_dir)
Rich Townsend3f86b832006-07-01 11:36:54 -040049 acpi_ac_dir = proc_mkdir(ACPI_AC_CLASS, acpi_root_dir);
Rich Townsend3f86b832006-07-01 11:36:54 -040050 if (acpi_ac_dir) {
51 lock_ac_dir_cnt++;
52 } else {
Lin Ming55ac9a02008-09-28 14:51:56 +080053 printk(KERN_ERR PREFIX
54 "Cannot create %s\n", ACPI_AC_CLASS);
Rich Townsend3f86b832006-07-01 11:36:54 -040055 }
Andrew Morton8970bfe2006-07-10 02:34:45 -040056 mutex_unlock(&cm_sbs_mutex);
Len Brown635227e2006-07-01 16:48:23 -040057 return acpi_ac_dir;
Rich Townsend3f86b832006-07-01 11:36:54 -040058}
Rich Townsend3f86b832006-07-01 11:36:54 -040059EXPORT_SYMBOL(acpi_lock_ac_dir);
60
61void acpi_unlock_ac_dir(struct proc_dir_entry *acpi_ac_dir_param)
62{
Andrew Morton8970bfe2006-07-10 02:34:45 -040063 mutex_lock(&cm_sbs_mutex);
64 if (acpi_ac_dir_param)
Rich Townsend3f86b832006-07-01 11:36:54 -040065 lock_ac_dir_cnt--;
Rich Townsend3f86b832006-07-01 11:36:54 -040066 if (lock_ac_dir_cnt == 0 && acpi_ac_dir_param && acpi_ac_dir) {
67 remove_proc_entry(ACPI_AC_CLASS, acpi_root_dir);
Al Viro4370df92006-10-10 22:47:17 +010068 acpi_ac_dir = NULL;
Rich Townsend3f86b832006-07-01 11:36:54 -040069 }
Andrew Morton8970bfe2006-07-10 02:34:45 -040070 mutex_unlock(&cm_sbs_mutex);
Rich Townsend3f86b832006-07-01 11:36:54 -040071}
Rich Townsend3f86b832006-07-01 11:36:54 -040072EXPORT_SYMBOL(acpi_unlock_ac_dir);
73
74struct proc_dir_entry *acpi_lock_battery_dir(void)
75{
Andrew Morton8970bfe2006-07-10 02:34:45 -040076 mutex_lock(&cm_sbs_mutex);
Rich Townsend3f86b832006-07-01 11:36:54 -040077 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 {
Lin Ming55ac9a02008-09-28 14:51:56 +080084 printk(KERN_ERR PREFIX
85 "Cannot create %s\n", ACPI_BATTERY_CLASS);
Rich Townsend3f86b832006-07-01 11:36:54 -040086 }
Andrew Morton8970bfe2006-07-10 02:34:45 -040087 mutex_unlock(&cm_sbs_mutex);
Len Brown635227e2006-07-01 16:48:23 -040088 return acpi_battery_dir;
Rich Townsend3f86b832006-07-01 11:36:54 -040089}
Rich Townsend3f86b832006-07-01 11:36:54 -040090EXPORT_SYMBOL(acpi_lock_battery_dir);
91
92void acpi_unlock_battery_dir(struct proc_dir_entry *acpi_battery_dir_param)
93{
Andrew Morton8970bfe2006-07-10 02:34:45 -040094 mutex_lock(&cm_sbs_mutex);
95 if (acpi_battery_dir_param)
Rich Townsend3f86b832006-07-01 11:36:54 -040096 lock_battery_dir_cnt--;
Rich Townsend3f86b832006-07-01 11:36:54 -040097 if (lock_battery_dir_cnt == 0 && acpi_battery_dir_param
98 && acpi_battery_dir) {
99 remove_proc_entry(ACPI_BATTERY_CLASS, acpi_root_dir);
Al Viro4370df92006-10-10 22:47:17 +0100100 acpi_battery_dir = NULL;
Rich Townsend3f86b832006-07-01 11:36:54 -0400101 }
Andrew Morton8970bfe2006-07-10 02:34:45 -0400102 mutex_unlock(&cm_sbs_mutex);
Len Brown635227e2006-07-01 16:48:23 -0400103 return;
Rich Townsend3f86b832006-07-01 11:36:54 -0400104}
Rich Townsend3f86b832006-07-01 11:36:54 -0400105EXPORT_SYMBOL(acpi_unlock_battery_dir);