From 3f86b83243d59bb50caf5938d284d22e10d082a4 Mon Sep 17 00:00:00 2001 From: Rich Townsend Date: Sat, 1 Jul 2006 11:36:54 -0400 Subject: ACPI: add support for Smart Battery Most batteries today are ACPI "Control Method" batteries, but some models ship with the older "Smart Battery" that requires this code. Rich Townsend and Bruno Ducrot were the original authors. Vladimir Lebedev updated to run on latest kernel. http://bugzilla.kernel.org/show_bug.cgi?id=3734 Signed-off-by: Len Brown --- drivers/acpi/cm_sbs.c | 135 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 135 insertions(+) create mode 100644 drivers/acpi/cm_sbs.c (limited to 'drivers/acpi/cm_sbs.c') diff --git a/drivers/acpi/cm_sbs.c b/drivers/acpi/cm_sbs.c new file mode 100644 index 000000000000..d11507c7b8a4 --- /dev/null +++ b/drivers/acpi/cm_sbs.c @@ -0,0 +1,135 @@ +/* + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + * + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +ACPI_MODULE_NAME("cm_sbs") +#define ACPI_AC_CLASS "ac_adapter" +#define ACPI_BATTERY_CLASS "battery" +#define ACPI_SBS_COMPONENT 0x00080000 +#define _COMPONENT ACPI_SBS_COMPONENT +static struct proc_dir_entry *acpi_ac_dir; +static struct proc_dir_entry *acpi_battery_dir; + +static struct semaphore cm_sbs_sem; + +static int lock_ac_dir_cnt = 0; +static int lock_battery_dir_cnt = 0; + +struct proc_dir_entry *acpi_lock_ac_dir(void) +{ + ACPI_FUNCTION_TRACE("acpi_lock_ac_dir"); + + down(&cm_sbs_sem); + if (!acpi_ac_dir) { + acpi_ac_dir = proc_mkdir(ACPI_AC_CLASS, acpi_root_dir); + } + if (acpi_ac_dir) { + lock_ac_dir_cnt++; + } else { + ACPI_DEBUG_PRINT((ACPI_DB_ERROR, + "Cannot create %s\n", ACPI_AC_CLASS)); + } + up(&cm_sbs_sem); + return (acpi_ac_dir); +} + +EXPORT_SYMBOL(acpi_lock_ac_dir); + +void acpi_unlock_ac_dir(struct proc_dir_entry *acpi_ac_dir_param) +{ + ACPI_FUNCTION_TRACE("acpi_unlock_ac_dir"); + + down(&cm_sbs_sem); + if (acpi_ac_dir_param) { + lock_ac_dir_cnt--; + } + if (lock_ac_dir_cnt == 0 && acpi_ac_dir_param && acpi_ac_dir) { + remove_proc_entry(ACPI_AC_CLASS, acpi_root_dir); + acpi_ac_dir = 0; + } + up(&cm_sbs_sem); +} + +EXPORT_SYMBOL(acpi_unlock_ac_dir); + +struct proc_dir_entry *acpi_lock_battery_dir(void) +{ + ACPI_FUNCTION_TRACE("acpi_lock_battery_dir"); + + down(&cm_sbs_sem); + if (!acpi_battery_dir) { + acpi_battery_dir = + proc_mkdir(ACPI_BATTERY_CLASS, acpi_root_dir); + } + if (acpi_battery_dir) { + lock_battery_dir_cnt++; + } else { + ACPI_DEBUG_PRINT((ACPI_DB_ERROR, + "Cannot create %s\n", ACPI_BATTERY_CLASS)); + } + up(&cm_sbs_sem); + return (acpi_battery_dir); +} + +EXPORT_SYMBOL(acpi_lock_battery_dir); + +void acpi_unlock_battery_dir(struct proc_dir_entry *acpi_battery_dir_param) +{ + ACPI_FUNCTION_TRACE("acpi_unlock_battery_dir"); + + down(&cm_sbs_sem); + if (acpi_battery_dir_param) { + lock_battery_dir_cnt--; + } + if (lock_battery_dir_cnt == 0 && acpi_battery_dir_param + && acpi_battery_dir) { + remove_proc_entry(ACPI_BATTERY_CLASS, acpi_root_dir); + acpi_battery_dir = 0; + } + up(&cm_sbs_sem); +} + +EXPORT_SYMBOL(acpi_unlock_battery_dir); + +static int __init acpi_cm_sbs_init(void) +{ + ACPI_FUNCTION_TRACE("acpi_cm_sbs_init"); + + if (acpi_disabled) + return_VALUE(0); + + init_MUTEX(&cm_sbs_sem); + + return_VALUE(0); +} + +subsys_initcall(acpi_cm_sbs_init); -- cgit v1.2.2