Skip to contentSkip to conversation

pcc_acpi: v0.8 panasonic hotkey driver update

PATCH New Hiroshi Miura 1 participant 1 message Sep 28, 2004 ACPI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pcc_acpi: v0.8 panasonic hotkey driver update

Hi,

I update panasonic hotkey driver.
Now other discussion about key input event related hotkey, then this version of driver is one answer.

*new features
- generate normal key input event added to acpi event this is useful for volume up/down and mute. this hotkeys utility, you can show fancy gui.

This enhancdment is based on Ryuta Nakanishi's work.

You can get driver source from http://www.da-cha.org/letsnote/

*future plan
- support Fn sticky mode.

Thanx.

Signature · 4 lines
Hiroshi Miura  --- http://www.da-cha.org/  --- [email protected]
NTTDATA Corp. OpenSource Software Center. --- [email protected] 
NTTDATA Intellilink Corp. OpenSource Engineering Dev. -- miurahr-w0OK63jvRlAuJ+9fw/[email protected]
Key fingerprint = 9117 9407 5684 FBF1 4063  15B4 401D D077 04AB 8617

#### AUTHOR [email protected] #### COMMENT START
### Comments for ChangeSet
[ACPI] pcc_acpi: v0.8 - Generate key input event on input subsystem.
This is based on yet another driver written by Ryuta Nakanishi.

### Comments for drivers/acpi/pcc_acpi.c
Generate key input event on input subsystem.
This is based on yet another driver written by Ryuta Nakanishi. #### COMMENT END

# This is a BitKeeper generated diff -Nru style patch. #
# ChangeSet
# 2004/09/19 12:44:31+09:00 [email protected]
# [ACPI] pcc_acpi: v0.8 - Generate key input event on input subsystem.
# This is based on yet another driver written by Ryuta Nakanishi.
#
# Signed-off-by: Hiroshi Miura <[email protected]>
#

# drivers/acpi/pcc_acpi.c
#   2004/09/19 12:44:19+09:00 [email protected] +197 -6
#   Generate key input event on input subsystem.
#   This is based on yet another driver written by Ryuta Nakanishi.
# 
diff -Nru a/drivers/acpi/pcc_acpi.c b/drivers/acpi/pcc_acpi.c
--- a/drivers/acpi/pcc_acpi.c	2004-09-22 09:12:13 +09:00
+++ b/drivers/acpi/pcc_acpi.c	2004-09-22 09:12:13 +09:00
@@ -21,6 +21,10 @@
  *---------------------------------------------------------------------------
  *
  * ChangeLog:
+ *	Sep.15, 2004	Hiroshi Miura <[email protected]>
+ *		-v0.8	Generate key input event on input subsystem.
+ *			This is based on yet another driver written by Ryuta Nakanishi.
+ *
  *	Sep.10, 2004	Hiroshi Miura <[email protected]>
  *		-v0.7	Change proc interface functions using seq_file
  *			fasility as same as other ACPI drivers.
@@ -66,7 +70,7 @@
  *
  */

-#define ACPI_PCC_VERSION "0.7"
+#define ACPI_PCC_VERSION "0.8"

#include <linux/kernel.h>
#include <linux/module.h>
@@ -78,6 +82,7 @@
#include <asm/uaccess.h>
#include <acpi/acpi_bus.h>
#include <acpi/acpi_drivers.h>
+#include <linux/input.h>

#define ACPI_HOTKEY_COMPONENT 0x10000000
#define _COMPONENT ACPI_HOTKEY_COMPONENT
@@ -98,7 +103,7 @@
#define METHOD_HKEY_SQTY "SQTY"
#define METHOD_HKEY_SINF "SINF"
#define METHOD_HKEY_SSET "SSET"
-#define HKEY_HID "MAT0019"
+#define HKEY_HID "MAT0012,MAT0013,MAT0018,MAT0019"
#define HKEY_NOTIFY 0x80

/*******************************************************************
@@ -112,6 +117,13 @@
#define ACPI_PCC_DEVICE_NAME "PCCExtra"
#define ACPI_PCC_CLASS "pcc"

+#define ACPI_PCC_INPUT_PHYS "panasonic/hkey0"
+
+/* This is transitional definition */
+#ifndef KEY_BATT
+#define KEY_BATT 227
+#endif
+
/* LCD_TYPEs: 0 = Normal, 1 = Semi-transparent

    ENV_STATEs: Normal temp=0x01, High temp=0x81, N/A=0x00 

*/
@@ -140,6 +152,12 @@
struct proc_dir_entry *proc_dir_entry;
unsigned long num_sifr;
unsigned long status;
+ struct input_dev *input_dev;
+};
+
+struct pcc_keyinput {
+ struct acpi_hotkey *hotkey;
+ int key_mode;
};

/* --------------------------------------------------------------------------
@@ -155,9 +173,11 @@
static int acpi_pcc_dc_brightness_min_open_fs(struct inode*,struct file*); static int acpi_pcc_ac_brightness_open_fs(struct inode*,struct file*);
static int acpi_pcc_dc_brightness_open_fs(struct inode*,struct file*);
+static int acpi_pcc_keyinput_open_fs(struct inode*,struct file*);
static ssize_t acpi_pcc_write_mute (struct file*,const char __user *,size_t,loff_t *); static ssize_t acpi_pcc_write_ac_brightness (struct file*,const char __user *,size_t,loff_t *); static ssize_t acpi_pcc_write_dc_brightness (struct file*,const char __user *,size_t,loff_t *);
+static ssize_t acpi_pcc_write_keyinput (struct file*,const char __user *,size_t,loff_t *);

static struct file_operations acpi_pcc_version_fops = {
.open = acpi_pcc_version_open_fs,
@@ -165,7 +185,6 @@
.llseek = seq_lseek,
.release = single_release,
};
-
static struct file_operations acpi_pcc_numbatteries_fops = {
.open = acpi_pcc_numbatteries_open_fs,
.read = seq_read,
@@ -223,6 +242,13 @@
.llseek = seq_lseek,
.release = single_release,
};
+static struct file_operations acpi_pcc_keyinput_fops = {
+ .open = acpi_pcc_keyinput_open_fs,
+ .read = seq_read,
+ .write = acpi_pcc_write_keyinput,
+ .llseek = seq_lseek,
+ .release = single_release,
+};

/* --------------------------------------------------------------------------
method access functions
@@ -463,11 +489,51 @@
SINF_DC_CUR_BRIGHT);
}

+static int acpi_pcc_keyinput_show(struct seq_file *seq, void *offset) +{
+ struct acpi_hotkey *hotkey = (struct acpi_hotkey *) seq->private;
+ struct input_dev *hotk_input_dev = hotkey->input_dev;
+ struct pcc_keyinput *keyinput = hotk_input_dev->private;
+
+ ACPI_FUNCTION_TRACE("acpi_pcc_keyinput_show");
+
+ seq_printf(seq, "%d\n", keyinput->key_mode);
+
+ return_VALUE(0);
+}
+
+static ssize_t acpi_pcc_write_keyinput(struct file *file, const char __user *buffer,
+ size_t count, loff_t *ppos)
+{
+ struct seq_file *seq = (struct seq_file *)file->private_data;
+ struct acpi_hotkey *hotkey = (struct acpi_hotkey *)seq->private;
+ struct pcc_keyinput *keyinput;
+ char write_string[8] = {'\0'};
+ int key_mode;
+
+ ACPI_FUNCTION_TRACE("acpi_pcc_write_keyinput");
+
+ if (!hotkey || (count > sizeof(write_string) - 1))
+ return_VALUE(-EINVAL);
+
+ if (copy_from_user(write_string, buffer, count))
+ return_VALUE(-EFAULT);
+
+ write_string[count] = '\0';
+
+ if (sscanf(write_string, "%i", &key_mode) == 1 && (key_mode == 0 || key_mode == 1)) {
+ keyinput = (struct pcc_keyinput *) hotkey->input_dev->private;
+ keyinput->key_mode = key_mode;
+ }
+
+ return_VALUE(count);
+}
+
static int acpi_pcc_version_show(struct seq_file *seq, void *offset)
{
struct acpi_hotkey *hotkey = (struct acpi_hotkey *) seq->private;

- ACPI_FUNCTION_TRACE("acpi_pcc_version_seq_show");
+ ACPI_FUNCTION_TRACE("acpi_pcc_version_show");

if (!hotkey || !hotkey->device)
return 0;
@@ -529,10 +595,58 @@
return single_open(file, acpi_pcc_version_show, PDE(inode)->data);
}

+static int acpi_pcc_keyinput_open_fs(struct inode *inode, struct file *file) +{
+ return single_open(file, acpi_pcc_keyinput_show, PDE(inode)->data);
+}
+
/* --------------------------------------------------------------------------

                             hotkey driver 
    -------------------------------------------------------------------------- */

+static void pcc_acpi_generete_keyinput(struct acpi_hotkey *hotkey)
+{
+ struct input_dev *hotk_input_dev = hotkey->input_dev;
+ struct pcc_keyinput *keyinput = hotk_input_dev->private;
+ int hinf = hotkey->status;
+
+ if (keyinput->key_mode) {
+ switch (hinf & 0xf){
+ case 0x01:
+ input_report_key(hotk_input_dev, KEY_BRIGHTNESSDOWN, hinf & 0x80);
+ break;
+ case 0x02:
+ input_report_key(hotk_input_dev, KEY_BRIGHTNESSUP, hinf & 0x80);
+ break;
+ case 0x03:
+ /* vga/lcd switch event is not occur on hotkey driver. */
+ break;
+ case 0x04:
+ input_report_key(hotk_input_dev, KEY_MUTE, hinf & 0x80);
+ break;
+ case 0x05:
+ input_report_key(hotk_input_dev, KEY_VOLUMEDOWN, hinf & 0x80);
+ break;
+ case 0x06:
+ input_report_key(hotk_input_dev, KEY_VOLUMEUP, hinf & 0x80);
+ break;
+ case 0x07:
+ input_report_key(hotk_input_dev, KEY_SLEEP, hinf & 0x80);
+ break;
+ case 0x08:
+ /* do nothing */
+ break;
+ case 0x09:
+ input_report_key(hotk_input_dev, KEY_BATT, hinf & 0x80);
+ break;
+ case 0x0a:
+ input_report_key(hotk_input_dev, KEY_SUSPEND, hinf & 0x80);
+ break;
+ }
+ input_sync(hotk_input_dev);
+ }
+}
+
static int acpi_pcc_hotkey_get_key(struct acpi_hotkey *hotkey)
{
unsigned long result;
@@ -559,9 +673,10 @@
switch(event) {
case HKEY_NOTIFY:
if (acpi_pcc_hotkey_get_key(hotkey)) {
- /* generate event like 'pcc HKEY 0004 0001' when Fn+F4 pressed */
+ /* generate event like '"pcc HKEY 00000080 00000084"' when Fn+F4 pressed */
acpi_bus_generate_event(hotkey->device, event, hotkey->status);
}
+ pcc_acpi_generete_keyinput(hotkey);
break;
default:
/* nothing to do */
@@ -593,6 +708,7 @@
{ "dc_brightness_min" , &acpi_pcc_dc_brightness_min_fops,S_IRUGO },

 	{ "dc_brightness" ,     &acpi_pcc_dc_brightness_fops,    S_IFREG | S_IRUGO | S_IWUSR }, 
 	{ "mute",               &acpi_pcc_mute_fops,             S_IFREG | S_IRUGO | S_IWUSR },
+	{ "keyinput",           &acpi_pcc_keyinput_fops,         S_IFREG | S_IRUGO | S_IWUSR },
 	{ "version",            &acpi_pcc_version_fops,          S_IRUGO },

{ NULL, NULL, 0 },
};
@@ -666,6 +782,74 @@
}

/* --------------------------------------------------------------------------
+ input init
+ -------------------------------------------------------------------------- */
+static int hotk_input_open(struct input_dev *dev)
+{
+ return 0;
+}
+
+static void hotk_input_close(struct input_dev *dev)
+{
+}
+
+static int acpi_pcc_init_input(struct acpi_hotkey *hotkey)
+{
+ struct input_dev *hotk_input_dev;
+ struct pcc_keyinput *pcc_keyinput;
+
+ ACPI_FUNCTION_TRACE("acpi_pcc_init_input");
+
+ hotk_input_dev = kmalloc(sizeof(struct input_dev),GFP_KERNEL);
+
+ if (!hotk_input_dev) {
+ ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Couldn't allocate mem for hotkey"));
+ return_VALUE(-ENOMEM);
+ }
+
+ pcc_keyinput = kmalloc(sizeof(struct pcc_keyinput),GFP_KERNEL);
+
+ if (!pcc_keyinput) {
+ ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Couldn't allocate mem for hotkey"));
+ return_VALUE(-ENOMEM);
+ }
+
+ memset(hotk_input_dev, 0, sizeof(struct input_dev));
+ hotk_input_dev->open = hotk_input_open;
+ hotk_input_dev->close = hotk_input_close;
+
+ hotk_input_dev->evbit[0] = BIT(EV_KEY);
+
+ set_bit(KEY_BRIGHTNESSDOWN, hotk_input_dev->keybit);
+ set_bit(KEY_BRIGHTNESSUP, hotk_input_dev->keybit);
+ set_bit(KEY_MUTE, hotk_input_dev->keybit);
+ set_bit(KEY_VOLUMEDOWN, hotk_input_dev->keybit);
+ set_bit(KEY_VOLUMEUP, hotk_input_dev->keybit);
+ set_bit(KEY_SLEEP, hotk_input_dev->keybit);
+ set_bit(KEY_BATT, hotk_input_dev->keybit);
+ set_bit(KEY_SUSPEND, hotk_input_dev->keybit);
+
+ hotk_input_dev->name = ACPI_PCC_DRIVER_NAME;
+ hotk_input_dev->phys = ACPI_PCC_INPUT_PHYS;
+ hotk_input_dev->id.bustype = 0x1a; /* XXX FIXME: BUS_I8042? */
+ hotk_input_dev->id.vendor = 0x0001;
+ hotk_input_dev->id.product = 0x0001;
+ hotk_input_dev->id.version = 0x0100;
+
+ pcc_keyinput->key_mode = 1; /* default on */
+ pcc_keyinput->hotkey = hotkey;
+
+ hotk_input_dev->private = pcc_keyinput;
+
+ hotkey->input_dev = hotk_input_dev;
+
+
+ input_register_device(hotk_input_dev);
+
+ return_VALUE(0);
+}
+
+/* --------------------------------------------------------------------------

                          module init
    -------------------------------------------------------------------------- */

@@ -673,7 +857,7 @@
{
acpi_status status = AE_OK;
struct acpi_hotkey *hotkey = NULL;
- int num_sifr;
+ int num_sifr, result;

ACPI_FUNCTION_TRACE("acpi_pcc_hotkey_add");

@@ -713,6 +897,13 @@
ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error installing notify handler\n")); kfree(hotkey);
return_VALUE(-ENODEV);
+ }
+
+ result = acpi_pcc_init_input(hotkey);
+ if (result) {
+ ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error installing keyinput handler\n"));
+ kfree(hotkey);
+ return_VALUE(result);
}

return_VALUE(acpi_pcc_proc_init(device));