/*
* hotkey.c - ACPI Hotkey Driver ($Revision: 0.2 $)
*
* Copyright (C) 2004 Luming Yu <luming.yu@intel.com>
*
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*
* 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 <linux/sched.h>
#include <linux/kmod.h>
#include <linux/seq_file.h>
#include <acpi/acpi_drivers.h>
#include <acpi/acpi_bus.h>
#include <asm/uaccess.h>
#define HOTKEY_ACPI_VERSION "0.1"
#define HOTKEY_PROC "hotkey"
#define HOTKEY_EV_CONFIG "event_config"
#define HOTKEY_PL_CONFIG "poll_config"
#define HOTKEY_ACTION "action"
#define HOTKEY_INFO "info"
#define ACPI_HOTK_NAME "Generic Hotkey Driver"
#define ACPI_HOTK_CLASS "Hotkey"
#define ACPI_HOTK_DEVICE_NAME "Hotkey"
#define ACPI_HOTK_HID "Unknown?"
#define ACPI_HOTKEY_COMPONENT 0x20000000
#define ACPI_HOTKEY_EVENT 0x1
#define ACPI_HOTKEY_POLLING 0x2
#define ACPI_UNDEFINED_EVENT 0xf
#define RESULT_STR_LEN 80
#define ACTION_METHOD 0
#define POLL_METHOD 1
#define IS_EVENT(e) ((e) <= 10000 && (e) >0)
#define IS_POLL(e) ((e) > 10000)
#define IS_OTHERS(e) ((e)<=0 || (e)>=20000)
#define _COMPONENT ACPI_HOTKEY_COMPONENT
ACPI_MODULE_NAME("acpi_hotkey")
MODULE_AUTHOR("luming.yu@intel.com");
MODULE_DESCRIPTION(ACPI_HOTK_NAME);
MODULE_LICENSE("GPL");
/* standardized internal hotkey number/event */
enum {
/* Video Extension event */
HK_EVENT_CYCLE_OUTPUT_DEVICE = 0x80,
HK_EVENT_OUTPUT_DEVICE_STATUS_CHANGE,
HK_EVENT_CYCLE_DISPLAY_OUTPUT,
HK_EVENT_NEXT_DISPLAY_OUTPUT,
HK_EVENT_PREVIOUS_DISPLAY_OUTPUT,
HK_EVENT_CYCLE_BRIGHTNESS,
HK_EVENT_INCREASE_BRIGHTNESS,
HK_EVENT_DECREASE_BRIGHTNESS,
HK_EVENT_ZERO_BRIGHTNESS,
HK_EVENT_DISPLAY_DEVICE_OFF,
/* Snd Card event */
HK_EVENT_VOLUME_MUTE,
HK_EVENT_VOLUME_INCLREASE,
HK_EVENT_VOLUME_DECREASE,
/* running state control */
HK_EVENT_ENTERRING_S3,
HK_EVENT_ENTERRING_S4,
HK_EVENT_ENTERRING_S5,
};
/* procdir we use */
static struct proc_dir_entry *hotkey_proc_dir;
static struct proc_dir_entry *hotkey_config;
static struct proc_dir_entry *hotkey_poll_config;
static struct proc_dir_entry *hotkey_action;
static struct proc_dir_entry *hotkey_info;
/* linkage for all type of hotkey */
struct acpi_hotkey_link {
struct list_head entries;
int hotkey_type; /* event or polling based hotkey */
int hotkey_standard_num; /* standardized hotkey(event) number */
};
/* event based hotkey */
struct acpi_event_hotkey {
struct acpi_hotkey_link hotkey_link;
int flag;
acpi_handle bus_handle; /* bus to install notify handler */
int external_hotkey_num; /* external hotkey/event number */
acpi_handle action_handle; /* acpi handle attached aml action method */
char *action_method; /* action method */
};
/*
* There are two ways to poll status
* 1. directy call read_xxx method, without any arguments passed in
* 2. call write_xxx method, with arguments passed in, you need
* the result is saved in acpi_polling_hotkey.poll_result.
* anthoer read command through polling interface.
*
*/
/* polling based hotkey */
struct acpi_polling_hotkey {
struct acpi_hotkey_link hotkey_link;
int flag;
acpi_handle poll_handle; /* acpi handle attached polling method */
char *poll_method; /* poll method */
acpi_handle action_handle; /* acpi handle attached action method */
char *action_method; /* action method */
union acpi_object *poll_result; /* polling_result */
struct proc_dir_entry *proc;
};
/* hotkey object union */
union acpi_hotkey {
struct list_head entries;
struct acpi_hotkey_link link;
struct acpi_event_hotkey event_hotkey;
struct acpi_polling_hotkey poll_hotkey;
};
/* hotkey object list */
struct acpi_hotkey_list {
struct list_head *entries;
int count;
};
static int auto_hotkey_add(struct acpi_device *device);
static int auto_hotkey_remove(struct acpi_device *device, int type);
static struct acpi_driver hotkey_driver = {
.name = ACPI_HOTK_NAME,
.class = ACPI_HOTK_CLASS,
.ids = ACPI_HOTK_HID,
.ops = {
.add = auto_hotkey_add,
.remove = auto_hotkey_remove,
},
};
static void free_hotkey_device(union acpi_hotkey *key);
static void free_hotkey_buffer(union acpi_hotkey *key);
static void free_poll_hotkey_buffer(union acpi_hotkey *key);
static int hotkey_open_config(struct inode *inode, struct file *file);
static int hotkey_poll_open_config(struct inode *inode, struct file *file