blob: d0918d421f90a34d4b2ad292880a3e8ebc987b10 [file] [log] [blame]
Lan Tianyue2a7c3d2014-05-04 11:07:24 +08001/*
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 *
Lan Tianyue2a7c3d2014-05-04 11:07:24 +080014 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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
29ACPI_MODULE_NAME("cm_sbs");
30#define ACPI_AC_CLASS "ac_adapter"
31#define ACPI_BATTERY_CLASS "battery"
32#define _COMPONENT ACPI_SBS_COMPONENT
33static struct proc_dir_entry *acpi_ac_dir;
34static struct proc_dir_entry *acpi_battery_dir;
35
36static DEFINE_MUTEX(cm_sbs_mutex);
37
38static int lock_ac_dir_cnt;
39static int lock_battery_dir_cnt;
40
41struct 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}
55EXPORT_SYMBOL(acpi_lock_ac_dir);
56
57void 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}
68EXPORT_SYMBOL(acpi_unlock_ac_dir);
69
70struct 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}
86EXPORT_SYMBOL(acpi_lock_battery_dir);
87
88void 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}
101EXPORT_SYMBOL(acpi_unlock_battery_dir);