| Rich Townsend | 3f86b83 | 2006-07-01 11:36:54 -0400 | [diff] [blame] | 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> | 
| Rich Townsend | 3f86b83 | 2006-07-01 11:36:54 -0400 | [diff] [blame] | 30 |  | 
| Len Brown | f52fd66 | 2007-02-12 22:42:12 -0500 | [diff] [blame] | 31 | ACPI_MODULE_NAME("cm_sbs"); | 
| Rich Townsend | 3f86b83 | 2006-07-01 11:36:54 -0400 | [diff] [blame] | 32 | #define ACPI_AC_CLASS		"ac_adapter" | 
 | 33 | #define ACPI_BATTERY_CLASS	"battery" | 
| Rich Townsend | 3f86b83 | 2006-07-01 11:36:54 -0400 | [diff] [blame] | 34 | #define _COMPONENT		ACPI_SBS_COMPONENT | 
 | 35 | static struct proc_dir_entry *acpi_ac_dir; | 
 | 36 | static struct proc_dir_entry *acpi_battery_dir; | 
 | 37 |  | 
| Andrew Morton | 8970bfe | 2006-07-10 02:34:45 -0400 | [diff] [blame] | 38 | static DEFINE_MUTEX(cm_sbs_mutex); | 
| Rich Townsend | 3f86b83 | 2006-07-01 11:36:54 -0400 | [diff] [blame] | 39 |  | 
| Andrew Morton | 8970bfe | 2006-07-10 02:34:45 -0400 | [diff] [blame] | 40 | static int lock_ac_dir_cnt; | 
 | 41 | static int lock_battery_dir_cnt; | 
| Rich Townsend | 3f86b83 | 2006-07-01 11:36:54 -0400 | [diff] [blame] | 42 |  | 
 | 43 | struct proc_dir_entry *acpi_lock_ac_dir(void) | 
 | 44 | { | 
| Andrew Morton | 8970bfe | 2006-07-10 02:34:45 -0400 | [diff] [blame] | 45 | 	mutex_lock(&cm_sbs_mutex); | 
 | 46 | 	if (!acpi_ac_dir) | 
| Rich Townsend | 3f86b83 | 2006-07-01 11:36:54 -0400 | [diff] [blame] | 47 | 		acpi_ac_dir = proc_mkdir(ACPI_AC_CLASS, acpi_root_dir); | 
| Rich Townsend | 3f86b83 | 2006-07-01 11:36:54 -0400 | [diff] [blame] | 48 | 	if (acpi_ac_dir) { | 
 | 49 | 		lock_ac_dir_cnt++; | 
 | 50 | 	} else { | 
| Lin Ming | 55ac9a0 | 2008-09-28 14:51:56 +0800 | [diff] [blame] | 51 | 		printk(KERN_ERR PREFIX | 
 | 52 | 				  "Cannot create %s\n", ACPI_AC_CLASS); | 
| Rich Townsend | 3f86b83 | 2006-07-01 11:36:54 -0400 | [diff] [blame] | 53 | 	} | 
| Andrew Morton | 8970bfe | 2006-07-10 02:34:45 -0400 | [diff] [blame] | 54 | 	mutex_unlock(&cm_sbs_mutex); | 
| Len Brown | 635227e | 2006-07-01 16:48:23 -0400 | [diff] [blame] | 55 | 	return acpi_ac_dir; | 
| Rich Townsend | 3f86b83 | 2006-07-01 11:36:54 -0400 | [diff] [blame] | 56 | } | 
| Rich Townsend | 3f86b83 | 2006-07-01 11:36:54 -0400 | [diff] [blame] | 57 | EXPORT_SYMBOL(acpi_lock_ac_dir); | 
 | 58 |  | 
 | 59 | void acpi_unlock_ac_dir(struct proc_dir_entry *acpi_ac_dir_param) | 
 | 60 | { | 
| Andrew Morton | 8970bfe | 2006-07-10 02:34:45 -0400 | [diff] [blame] | 61 | 	mutex_lock(&cm_sbs_mutex); | 
 | 62 | 	if (acpi_ac_dir_param) | 
| Rich Townsend | 3f86b83 | 2006-07-01 11:36:54 -0400 | [diff] [blame] | 63 | 		lock_ac_dir_cnt--; | 
| Rich Townsend | 3f86b83 | 2006-07-01 11:36:54 -0400 | [diff] [blame] | 64 | 	if (lock_ac_dir_cnt == 0 && acpi_ac_dir_param && acpi_ac_dir) { | 
 | 65 | 		remove_proc_entry(ACPI_AC_CLASS, acpi_root_dir); | 
| Al Viro | 4370df9 | 2006-10-10 22:47:17 +0100 | [diff] [blame] | 66 | 		acpi_ac_dir = NULL; | 
| Rich Townsend | 3f86b83 | 2006-07-01 11:36:54 -0400 | [diff] [blame] | 67 | 	} | 
| Andrew Morton | 8970bfe | 2006-07-10 02:34:45 -0400 | [diff] [blame] | 68 | 	mutex_unlock(&cm_sbs_mutex); | 
| Rich Townsend | 3f86b83 | 2006-07-01 11:36:54 -0400 | [diff] [blame] | 69 | } | 
| Rich Townsend | 3f86b83 | 2006-07-01 11:36:54 -0400 | [diff] [blame] | 70 | EXPORT_SYMBOL(acpi_unlock_ac_dir); | 
 | 71 |  | 
 | 72 | struct proc_dir_entry *acpi_lock_battery_dir(void) | 
 | 73 | { | 
| Andrew Morton | 8970bfe | 2006-07-10 02:34:45 -0400 | [diff] [blame] | 74 | 	mutex_lock(&cm_sbs_mutex); | 
| Rich Townsend | 3f86b83 | 2006-07-01 11:36:54 -0400 | [diff] [blame] | 75 | 	if (!acpi_battery_dir) { | 
 | 76 | 		acpi_battery_dir = | 
 | 77 | 		    proc_mkdir(ACPI_BATTERY_CLASS, acpi_root_dir); | 
 | 78 | 	} | 
 | 79 | 	if (acpi_battery_dir) { | 
 | 80 | 		lock_battery_dir_cnt++; | 
 | 81 | 	} else { | 
| Lin Ming | 55ac9a0 | 2008-09-28 14:51:56 +0800 | [diff] [blame] | 82 | 		printk(KERN_ERR PREFIX | 
 | 83 | 				  "Cannot create %s\n", ACPI_BATTERY_CLASS); | 
| Rich Townsend | 3f86b83 | 2006-07-01 11:36:54 -0400 | [diff] [blame] | 84 | 	} | 
| Andrew Morton | 8970bfe | 2006-07-10 02:34:45 -0400 | [diff] [blame] | 85 | 	mutex_unlock(&cm_sbs_mutex); | 
| Len Brown | 635227e | 2006-07-01 16:48:23 -0400 | [diff] [blame] | 86 | 	return acpi_battery_dir; | 
| Rich Townsend | 3f86b83 | 2006-07-01 11:36:54 -0400 | [diff] [blame] | 87 | } | 
| Rich Townsend | 3f86b83 | 2006-07-01 11:36:54 -0400 | [diff] [blame] | 88 | EXPORT_SYMBOL(acpi_lock_battery_dir); | 
 | 89 |  | 
 | 90 | void acpi_unlock_battery_dir(struct proc_dir_entry *acpi_battery_dir_param) | 
 | 91 | { | 
| Andrew Morton | 8970bfe | 2006-07-10 02:34:45 -0400 | [diff] [blame] | 92 | 	mutex_lock(&cm_sbs_mutex); | 
 | 93 | 	if (acpi_battery_dir_param) | 
| Rich Townsend | 3f86b83 | 2006-07-01 11:36:54 -0400 | [diff] [blame] | 94 | 		lock_battery_dir_cnt--; | 
| Rich Townsend | 3f86b83 | 2006-07-01 11:36:54 -0400 | [diff] [blame] | 95 | 	if (lock_battery_dir_cnt == 0 && acpi_battery_dir_param | 
 | 96 | 	    && acpi_battery_dir) { | 
 | 97 | 		remove_proc_entry(ACPI_BATTERY_CLASS, acpi_root_dir); | 
| Al Viro | 4370df9 | 2006-10-10 22:47:17 +0100 | [diff] [blame] | 98 | 		acpi_battery_dir = NULL; | 
| Rich Townsend | 3f86b83 | 2006-07-01 11:36:54 -0400 | [diff] [blame] | 99 | 	} | 
| Andrew Morton | 8970bfe | 2006-07-10 02:34:45 -0400 | [diff] [blame] | 100 | 	mutex_unlock(&cm_sbs_mutex); | 
| Len Brown | 635227e | 2006-07-01 16:48:23 -0400 | [diff] [blame] | 101 | 	return; | 
| Rich Townsend | 3f86b83 | 2006-07-01 11:36:54 -0400 | [diff] [blame] | 102 | } | 
| Rich Townsend | 3f86b83 | 2006-07-01 11:36:54 -0400 | [diff] [blame] | 103 | EXPORT_SYMBOL(acpi_unlock_battery_dir); |