Merge tag 'scsi-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi
[linux/fpc-iii.git] / drivers / acpi / cm_sbs.c
blob0ca9f82de8ba77cac55e460ff1dea61fd4c9ee90
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 #include <linux/kernel.h>
4 #include <linux/module.h>
5 #include <linux/init.h>
6 #include <linux/acpi.h>
7 #include <linux/types.h>
8 #include <linux/proc_fs.h>
9 #include <linux/seq_file.h>
10 #include <acpi/acpi_bus.h>
11 #include <acpi/acpi_drivers.h>
13 #define PREFIX "ACPI: "
15 ACPI_MODULE_NAME("cm_sbs");
16 #define ACPI_AC_CLASS "ac_adapter"
17 #define ACPI_BATTERY_CLASS "battery"
18 #define _COMPONENT ACPI_SBS_COMPONENT
19 static struct proc_dir_entry *acpi_ac_dir;
20 static struct proc_dir_entry *acpi_battery_dir;
22 static DEFINE_MUTEX(cm_sbs_mutex);
24 static int lock_ac_dir_cnt;
25 static int lock_battery_dir_cnt;
27 struct proc_dir_entry *acpi_lock_ac_dir(void)
29 mutex_lock(&cm_sbs_mutex);
30 if (!acpi_ac_dir)
31 acpi_ac_dir = proc_mkdir(ACPI_AC_CLASS, acpi_root_dir);
32 if (acpi_ac_dir) {
33 lock_ac_dir_cnt++;
34 } else {
35 printk(KERN_ERR PREFIX
36 "Cannot create %s\n", ACPI_AC_CLASS);
38 mutex_unlock(&cm_sbs_mutex);
39 return acpi_ac_dir;
41 EXPORT_SYMBOL(acpi_lock_ac_dir);
43 void acpi_unlock_ac_dir(struct proc_dir_entry *acpi_ac_dir_param)
45 mutex_lock(&cm_sbs_mutex);
46 if (acpi_ac_dir_param)
47 lock_ac_dir_cnt--;
48 if (lock_ac_dir_cnt == 0 && acpi_ac_dir_param && acpi_ac_dir) {
49 remove_proc_entry(ACPI_AC_CLASS, acpi_root_dir);
50 acpi_ac_dir = NULL;
52 mutex_unlock(&cm_sbs_mutex);
54 EXPORT_SYMBOL(acpi_unlock_ac_dir);
56 struct proc_dir_entry *acpi_lock_battery_dir(void)
58 mutex_lock(&cm_sbs_mutex);
59 if (!acpi_battery_dir) {
60 acpi_battery_dir =
61 proc_mkdir(ACPI_BATTERY_CLASS, acpi_root_dir);
63 if (acpi_battery_dir) {
64 lock_battery_dir_cnt++;
65 } else {
66 printk(KERN_ERR PREFIX
67 "Cannot create %s\n", ACPI_BATTERY_CLASS);
69 mutex_unlock(&cm_sbs_mutex);
70 return acpi_battery_dir;
72 EXPORT_SYMBOL(acpi_lock_battery_dir);
74 void acpi_unlock_battery_dir(struct proc_dir_entry *acpi_battery_dir_param)
76 mutex_lock(&cm_sbs_mutex);
77 if (acpi_battery_dir_param)
78 lock_battery_dir_cnt--;
79 if (lock_battery_dir_cnt == 0 && acpi_battery_dir_param
80 && acpi_battery_dir) {
81 remove_proc_entry(ACPI_BATTERY_CLASS, acpi_root_dir);
82 acpi_battery_dir = NULL;
84 mutex_unlock(&cm_sbs_mutex);
85 return;
87 EXPORT_SYMBOL(acpi_unlock_battery_dir);