|
From: Andy P. <at...@us...> - 2002-04-09 15:08:36
|
Update of /cvsroot/linux-vax/kernel-2.4/drivers/acpi/ospm/button
In directory usw-pr-cvs1:/tmp/cvs-serv13840/acpi/ospm/button
Added Files:
Makefile bn.c bn_osl.c
Log Message:
synch 2.4.15 commit 17
--- NEW FILE ---
O_TARGET := ospm_$(notdir $(CURDIR)).o
obj-m := $(O_TARGET)
EXTRA_CFLAGS += $(ACPI_CFLAGS)
obj-y := $(patsubst %.c,%.o,$(wildcard *.c))
include $(TOPDIR)/Rules.make
--- NEW FILE ---
/*****************************************************************************
*
* Module Name: bn.c
* $Revision: 1.1 $
*
*****************************************************************************/
/*
* Copyright (C) 2000, 2001 Andrew Grover
*
* 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 Plxxe, Suite 330, Boston, MA 02111-1307 USA
*/
#include <acpi.h>
#include "bn.h"
#define _COMPONENT ACPI_BUTTON
MODULE_NAME ("bn")
/*****************************************************************************
* Internal Functions
*****************************************************************************/
/*****************************************************************************
*
* FUNCTION: bn_print
*
* PARAMETERS:
*
* RETURN:
*
* DESCRIPTION: Prints out information on a specific button.
*
****************************************************************************/
void
bn_print (
BN_CONTEXT *button)
{
#ifdef ACPI_DEBUG
acpi_buffer buffer;
PROC_NAME("bn_print");
if (!button) {
return;
}
buffer.length = 256;
buffer.pointer = acpi_os_callocate(buffer.length);
if (!buffer.pointer) {
return;
}
/*
* Get the full pathname for this ACPI object.
*/
acpi_get_name(button->acpi_handle, ACPI_FULL_PATHNAME, &buffer);
/*
* Print out basic button information.
*/
ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INFO, "+------------------------------------------------------------\n"));
switch (button->type) {
case BN_TYPE_POWER_BUTTON:
case BN_TYPE_POWER_BUTTON_FIXED:
ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INFO, "| Power_button[%02x]:[%p] %s\n", button->device_handle, button->acpi_handle, (char*)buffer.pointer));
break;
case BN_TYPE_SLEEP_BUTTON:
case BN_TYPE_SLEEP_BUTTON_FIXED:
ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INFO, "| Sleep_button[%02x]:[%p] %s\n", button->device_handle, button->acpi_handle, (char*)buffer.pointer));
break;
case BN_TYPE_LID_SWITCH:
ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INFO, "| Lid_switch[%02x]:[%p] %s\n", button->device_handle, button->acpi_handle, (char*)buffer.pointer));
break;
}
ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INFO, "+------------------------------------------------------------\n"));
acpi_os_free(buffer.pointer);
#endif /*ACPI_DEBUG*/
return;
}
/****************************************************************************
*
* FUNCTION: bn_add_device
*
* PARAMETERS:
*
* RETURN:
*
* DESCRIPTION:
*
****************************************************************************/
acpi_status
bn_add_device(
BM_HANDLE device_handle,
void **context)
{
acpi_status status = AE_OK;
BM_DEVICE *device = NULL;
BN_CONTEXT *button = NULL;
FUNCTION_TRACE("bn_add_device");
ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Adding button device [%02x].\n", device_handle));
if (!context || *context) {
ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Invalid context.\n"));
return_ACPI_STATUS(AE_BAD_PARAMETER);
}
/*
* Get information on this device.
*/
status = bm_get_device_info( device_handle, &device );
if (ACPI_FAILURE(status)) {
return_ACPI_STATUS(status);
}
/*
* Allocate a new BN_CONTEXT structure.
*/
button = acpi_os_callocate(sizeof(BN_CONTEXT));
if (!button) {
return_ACPI_STATUS(AE_NO_MEMORY);
}
button->device_handle = device->handle;
button->acpi_handle = device->acpi_handle;
/*
* Power Button?
* -------------
* Either fixed-feature or generic (namespace) types.
*/
if (strncmp(device->id.hid, BN_HID_POWER_BUTTON,
sizeof(BM_DEVICE_HID)) == 0) {
if (device->id.type == BM_TYPE_FIXED_BUTTON) {
button->type = BN_TYPE_POWER_BUTTON_FIXED;
/* Register for fixed-feature events. */
status = acpi_install_fixed_event_handler(
ACPI_EVENT_POWER_BUTTON, bn_notify_fixed,
(void*)button);
}
else {
button->type = BN_TYPE_POWER_BUTTON;
}
}
/*
* Sleep Button?
* -------------
* Either fixed-feature or generic (namespace) types.
*/
else if (strncmp( device->id.hid, BN_HID_SLEEP_BUTTON,
sizeof(BM_DEVICE_HID)) == 0) {
if (device->id.type == BM_TYPE_FIXED_BUTTON) {
button->type = BN_TYPE_SLEEP_BUTTON_FIXED;
/* Register for fixed-feature events. */
status = acpi_install_fixed_event_handler(
ACPI_EVENT_SLEEP_BUTTON, bn_notify_fixed,
(void*)button);
}
else {
button->type = BN_TYPE_SLEEP_BUTTON;
}
}
/*
* LID Switch?
* -----------
*/
else if (strncmp( device->id.hid, BN_HID_LID_SWITCH,
sizeof(BM_DEVICE_HID)) == 0) {
button->type = BN_TYPE_LID_SWITCH;
}
status = bn_osl_add_device(button);
if (ACPI_FAILURE(status)) {
goto end;
}
*context = button;
bn_print(button);
end:
if (ACPI_FAILURE(status)) {
acpi_os_free(button);
}
return_ACPI_STATUS(status);
}
/****************************************************************************
*
* FUNCTION: bn_remove_device
*
* PARAMETERS:
*
* RETURN:
*
* DESCRIPTION:
*
****************************************************************************/
acpi_status
bn_remove_device(
void **context)
{
acpi_status status = AE_OK;
BN_CONTEXT *button = NULL;
FUNCTION_TRACE("bn_remove_device");
if (!context || !*context) {
return_ACPI_STATUS(AE_BAD_PARAMETER);
}
button = (BN_CONTEXT*)*context;
ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Removing button device [%02x].\n", button->device_handle));
/*
* Unregister for fixed-feature events.
*/
switch (button->type) {
case BN_TYPE_POWER_BUTTON_FIXED:
status = acpi_remove_fixed_event_handler(
ACPI_EVENT_POWER_BUTTON, bn_notify_fixed);
break;
case BN_TYPE_SLEEP_BUTTON_FIXED:
status = acpi_remove_fixed_event_handler(
ACPI_EVENT_SLEEP_BUTTON, bn_notify_fixed);
break;
}
bn_osl_remove_device(button);
acpi_os_free(button);
*context = NULL;
return_ACPI_STATUS(status);
}
/*****************************************************************************
* External Functions
*****************************************************************************/
/*****************************************************************************
*
* FUNCTION: bn_initialize
*
* PARAMETERS: <none>
*
* RETURN:
*
* DESCRIPTION:
*
****************************************************************************/
acpi_status
bn_initialize (void)
{
BM_DEVICE_ID criteria;
BM_DRIVER driver;
FUNCTION_TRACE("bn_initialize");
MEMSET(&criteria, 0, sizeof(BM_DEVICE_ID));
MEMSET(&driver, 0, sizeof(BM_DRIVER));
driver.notify = &bn_notify;
driver.request = &bn_request;
/*
* Register for power buttons.
*/
MEMCPY(criteria.hid, BN_HID_POWER_BUTTON, sizeof(BN_HID_POWER_BUTTON));
bm_register_driver(&criteria, &driver);
/*
* Register for sleep buttons.
*/
MEMCPY(criteria.hid, BN_HID_SLEEP_BUTTON, sizeof(BN_HID_SLEEP_BUTTON));
bm_register_driver(&criteria, &driver);
/*
* Register for LID switches.
*/
MEMCPY(criteria.hid, BN_HID_LID_SWITCH, sizeof(BN_HID_LID_SWITCH));
bm_register_driver(&criteria, &driver);
return_ACPI_STATUS(AE_OK);
}
/****************************************************************************
*
* FUNCTION: bn_terminate
*
* PARAMETERS: <none>
*
* RETURN:
*
* DESCRIPTION:
*
****************************************************************************/
acpi_status
bn_terminate (void)
{
acpi_status status = AE_OK;
BM_DEVICE_ID criteria;
BM_DRIVER driver;
FUNCTION_TRACE("bn_terminate");
MEMSET(&criteria, 0, sizeof(BM_DEVICE_ID));
MEMSET(&driver, 0, sizeof(BM_DRIVER));
driver.notify = &bn_notify;
driver.request = &bn_request;
/*
* Unregister for power buttons.
*/
MEMCPY(criteria.hid, BN_HID_POWER_BUTTON, sizeof(BN_HID_POWER_BUTTON));
status = bm_unregister_driver(&criteria, &driver);
/*
* Unregister for sleep buttons.
*/
MEMCPY(criteria.hid, BN_HID_SLEEP_BUTTON, sizeof(BN_HID_SLEEP_BUTTON));
status = bm_unregister_driver(&criteria, &driver);
/*
* Unregister for LID switches.
*/
MEMCPY(criteria.hid, BN_HID_LID_SWITCH, sizeof(BN_HID_LID_SWITCH));
status = bm_unregister_driver(&criteria, &driver);
return_ACPI_STATUS(status);
}
/****************************************************************************
*
* FUNCTION: bn_notify_fixed
*
* PARAMETERS: <none>
*
* RETURN:
*
* DESCRIPTION:
*
****************************************************************************/
acpi_status
bn_notify_fixed (
void *context)
{
acpi_status status = AE_OK;
FUNCTION_TRACE("bn_notify_fixed");
if (!context) {
return_ACPI_STATUS(AE_BAD_PARAMETER);
}
ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Status change event detected.\n"));
status = bn_osl_generate_event(BN_NOTIFY_STATUS_CHANGE,
((BN_CONTEXT*)context));
return_ACPI_STATUS(status);
}
/****************************************************************************
*
* FUNCTION: bn_notify
*
* PARAMETERS: <none>
*
* RETURN:
*
* DESCRIPTION:
*
****************************************************************************/
acpi_status
bn_notify (
BM_NOTIFY notify_type,
BM_HANDLE device_handle,
void **context)
{
acpi_status status = AE_OK;
FUNCTION_TRACE("bn_notify");
if (!context) {
return_ACPI_STATUS(AE_BAD_PARAMETER);
}
switch (notify_type) {
case BM_NOTIFY_DEVICE_ADDED:
status = bn_add_device(device_handle, context);
break;
case BM_NOTIFY_DEVICE_REMOVED:
status = bn_remove_device(context);
break;
case BN_NOTIFY_STATUS_CHANGE:
ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Status change event detected.\n"));
status = bn_osl_generate_event(BN_NOTIFY_STATUS_CHANGE,
((BN_CONTEXT*)*context));
break;
default:
status = AE_SUPPORT;
break;
}
return_ACPI_STATUS(status);
}
/****************************************************************************
*
* FUNCTION: bn_request
*
* PARAMETERS:
*
* RETURN:
*
* DESCRIPTION:
*
****************************************************************************/
acpi_status
bn_request (
BM_REQUEST *request,
void *context)
{
acpi_status status = AE_OK;
FUNCTION_TRACE("bn_request");
/*
* Must have a valid request structure and context.
*/
if (!request || !context) {
return_ACPI_STATUS(AE_BAD_PARAMETER);
}
/*
* Handle Request:
* ---------------
*/
switch (request->command) {
default:
status = AE_SUPPORT;
break;
}
request->status = status;
return_ACPI_STATUS(status);
}
--- NEW FILE ---
/******************************************************************************
*
* Module Name: bn_osl.c
* $Revision: 1.1 $
*
*****************************************************************************/
/*
* Copyright (C) 2000, 2001 Andrew Grover
*
* 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 <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/types.h>
#include <linux/proc_fs.h>
#include <acpi.h>
#include "bn.h"
MODULE_AUTHOR("Andrew Grover");
MODULE_DESCRIPTION("ACPI Component Architecture (CA) - Button Driver");
#define BN_PROC_ROOT "button"
#define BN_PROC_POWER_BUTTON "power"
#define BN_PROC_SLEEP_BUTTON "sleep"
#define BN_PROC_LID_SWITCH "lid"
extern struct proc_dir_entry *bm_proc_root;
static struct proc_dir_entry *bn_proc_root = NULL;
#define BN_TYPE_UNKNOWN 0
#define BN_TYPE_FIXED 1
#define BN_TYPE_GENERIC 2
static int bn_power_button = BN_TYPE_UNKNOWN;
static int bn_sleep_button = BN_TYPE_UNKNOWN;
static int bn_lid_switch = BN_TYPE_UNKNOWN;
/****************************************************************************
*
* FUNCTION: bn_osl_add_device
*
****************************************************************************/
acpi_status
bn_osl_add_device(
BN_CONTEXT *button)
{
acpi_status status = AE_OK;
if (!button) {
return(AE_BAD_PARAMETER);
}
switch (button->type) {
case BN_TYPE_POWER_BUTTON_FIXED:
bn_power_button = BN_TYPE_FIXED;
printk(KERN_INFO "ACPI: Power Button (FF) found\n");
if (!proc_mkdir(BN_PROC_POWER_BUTTON, bn_proc_root)) {
status = AE_ERROR;
}
break;
case BN_TYPE_POWER_BUTTON:
/*
* Avoid creating multiple /proc entries when (buggy) ACPI
* BIOS tables erroneously list both fixed- and generic-
* feature buttons. Note that fixed-feature buttons are
* always enumerated first (and there can only be one) so
* we only need to check here.
*/
switch (bn_power_button) {
case BN_TYPE_GENERIC:
printk(KERN_WARNING "ACPI: Multiple generic-space power buttons detected, using first\n");
break;
case BN_TYPE_FIXED:
printk(KERN_WARNING "ACPI: Multiple power buttons detected, ignoring fixed-feature\n");
default:
printk(KERN_INFO "ACPI: Power Button (CM) found\n");
bn_power_button = BN_TYPE_GENERIC;
if (!proc_mkdir(BN_PROC_POWER_BUTTON, bn_proc_root)) {
status = AE_ERROR;
}
break;
}
break;
case BN_TYPE_SLEEP_BUTTON_FIXED:
bn_sleep_button = BN_TYPE_FIXED;
printk(KERN_INFO "ACPI: Sleep Button (FF) found\n");
if (!proc_mkdir(BN_PROC_SLEEP_BUTTON, bn_proc_root)) {
status = AE_ERROR;
}
break;
case BN_TYPE_SLEEP_BUTTON:
/*
* Avoid creating multiple /proc entries when (buggy) ACPI
* BIOS tables erroneously list both fixed- and generic-
* feature buttons. Note that fixed-feature buttons are
* always enumerated first (and there can only be one) so
* we only need to check here.
*/
switch (bn_sleep_button) {
case BN_TYPE_GENERIC:
printk(KERN_WARNING "ACPI: Multiple generic-space sleep buttons detected, using first\n");
break;
case BN_TYPE_FIXED:
printk(KERN_WARNING "ACPI: Multiple sleep buttons detected, ignoring fixed-feature\n");
default:
bn_sleep_button = BN_TYPE_GENERIC;
printk(KERN_INFO "ACPI: Sleep Button (CM) found\n");
if (!proc_mkdir(BN_PROC_SLEEP_BUTTON, bn_proc_root)) {
status = AE_ERROR;
}
break;
}
break;
case BN_TYPE_LID_SWITCH:
if (bn_lid_switch) {
printk(KERN_WARNING "ACPI: Multiple generic-space lid switches detected, using first\n");
break;
}
bn_lid_switch = BN_TYPE_GENERIC;
printk(KERN_INFO "ACPI: Lid Switch (CM) found\n");
if (!proc_mkdir(BN_PROC_LID_SWITCH, bn_proc_root)) {
status = AE_ERROR;
}
break;
}
return(status);
}
/****************************************************************************
*
* FUNCTION: bn_osl_remove_device
*
****************************************************************************/
acpi_status
bn_osl_remove_device (
BN_CONTEXT *button)
{
if (!button) {
return(AE_BAD_PARAMETER);
}
switch (button->type) {
case BN_TYPE_POWER_BUTTON:
case BN_TYPE_POWER_BUTTON_FIXED:
remove_proc_entry(BN_PROC_POWER_BUTTON, bn_proc_root);
break;
case BN_TYPE_SLEEP_BUTTON:
case BN_TYPE_SLEEP_BUTTON_FIXED:
remove_proc_entry(BN_PROC_SLEEP_BUTTON, bn_proc_root);
break;
case BN_TYPE_LID_SWITCH:
remove_proc_entry(BN_PROC_LID_SWITCH, bn_proc_root);
break;
}
return(AE_OK);
}
/****************************************************************************
*
* FUNCTION: bn_osl_generate_event
*
****************************************************************************/
acpi_status
bn_osl_generate_event (
u32 event,
BN_CONTEXT *button)
{
acpi_status status = AE_OK;
if (!button) {
return(AE_BAD_PARAMETER);
}
switch (event) {
case BN_NOTIFY_STATUS_CHANGE:
switch(button->type) {
case BN_TYPE_POWER_BUTTON:
case BN_TYPE_POWER_BUTTON_FIXED:
status = bm_osl_generate_event(button->device_handle,
BN_PROC_ROOT, BN_PROC_POWER_BUTTON, event, 0);
break;
case BN_TYPE_SLEEP_BUTTON:
case BN_TYPE_SLEEP_BUTTON_FIXED:
status = bm_osl_generate_event(button->device_handle,
BN_PROC_ROOT, BN_PROC_SLEEP_BUTTON, event, 0);
break;
case BN_TYPE_LID_SWITCH:
status = bm_osl_generate_event(button->device_handle,
BN_PROC_ROOT, BN_PROC_LID_SWITCH, event, 0);
break;
default:
status = AE_SUPPORT;
break;
}
break;
default:
return(AE_BAD_PARAMETER);
break;
}
return(status);
}
/****************************************************************************
*
* FUNCTION: bn_osl_init
*
* PARAMETERS: <none>
*
* RETURN: 0: Success
*
* DESCRIPTION: Module initialization.
*
****************************************************************************/
static int __init
bn_osl_init (void)
{
acpi_status status = AE_OK;
/* abort if no busmgr */
if (!bm_proc_root)
return -ENODEV;
bn_proc_root = proc_mkdir(BN_PROC_ROOT, bm_proc_root);
if (!bn_proc_root) {
status = AE_ERROR;
}
else {
status = bn_initialize();
if (ACPI_FAILURE(status)) {
remove_proc_entry(BN_PROC_ROOT, bm_proc_root);
}
}
return (ACPI_SUCCESS(status)) ? 0 : -ENODEV;
}
/****************************************************************************
*
* FUNCTION: bn_osl_cleanup
*
* PARAMETERS: <none>
*
* RETURN: <none>
*
* DESCRIPTION: Module cleanup.
*
****************************************************************************/
static void __exit
bn_osl_cleanup (void)
{
bn_terminate();
if (bn_proc_root) {
remove_proc_entry(BN_PROC_ROOT, bm_proc_root);
}
return;
}
module_init(bn_osl_init);
module_exit(bn_osl_cleanup);
|