public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Matthew Garrett <mjg59@srcf.ucam.org>
To: linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [RFC] [PATCH] Make ACPI button driver an input device
Date: Wed, 19 Apr 2006 20:53:58 +0100	[thread overview]
Message-ID: <20060419195356.GA24122@srcf.ucam.org> (raw)

Sleep and power buttons are logically part of the keyboard, and it makes 
for them to be exposed via an input device rather than an odd file in 
/proc. This patch adds a keycode for lid switches (are we running out of 
keycodes?) and allows the button driver to register an input device.

Signed-off-by: Matthew Garrett <mjg59@srcf.ucam.org>

diff -ur drivers/acpi.bak/button.c drivers/acpi/button.c
--- drivers/acpi.bak/button.c	2006-04-03 04:22:10 +0100
+++ a/drivers/acpi/button.c	2006-04-19 20:36:05 +0100
@@ -26,6 +26,7 @@
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/init.h>
+#include <linux/input.h>
 #include <linux/types.h>
 #include <linux/proc_fs.h>
 #include <linux/seq_file.h>
@@ -102,6 +103,8 @@
 	.release = single_release,
 };
 
+static struct input_dev *input_dev;
+
 /* --------------------------------------------------------------------------
                               FS Interface (/proc)
    -------------------------------------------------------------------------- */
@@ -260,6 +263,37 @@
                                 Driver Interface
    -------------------------------------------------------------------------- */
 
+static void acpi_button_report (struct acpi_button *button)
+{
+	int keycode = 0;
+
+	ACPI_FUNCTION_TRACE("acpi_button_report");
+
+	switch(button->type) {
+	case ACPI_BUTTON_TYPE_POWER:
+	case ACPI_BUTTON_TYPE_POWERF:
+		keycode = KEY_POWER;
+		break;
+	case ACPI_BUTTON_TYPE_SLEEP:
+	case ACPI_BUTTON_TYPE_SLEEPF:
+		keycode = KEY_SLEEP;
+		break;
+	case ACPI_BUTTON_TYPE_LID:
+		keycode = KEY_LID;
+		break;
+
+	}
+
+	if (keycode) {
+		input_report_key(input_dev, keycode, 1);
+		input_sync(input_dev);
+		input_report_key(input_dev, keycode, 0);
+		input_sync(input_dev);
+	}
+
+	return_VOID;
+}
+
 static void acpi_button_notify(acpi_handle handle, u32 event, void *data)
 {
 	struct acpi_button *button = (struct acpi_button *)data;
@@ -273,6 +307,7 @@
 	case ACPI_BUTTON_NOTIFY_STATUS:
 		acpi_bus_generate_event(button->device, event,
 					++button->pushed);
+		acpi_button_report(button);		
 		break;
 	default:
 		ACPI_DEBUG_PRINT((ACPI_DB_INFO,
@@ -467,6 +502,26 @@
 		return_VALUE(-ENODEV);
 	}
 
+	input_dev = input_allocate_device();
+
+	if (input_dev) {
+		int error;
+
+		input_dev->name = "ACPI button driver";
+		input_dev->phys = "acpi/input0";
+		input_dev->id.bustype = BUS_HOST;
+		input_dev->evbit[LONG(EV_KEY)] = BIT(EV_KEY);
+		set_bit(KEY_SLEEP, input_dev->keybit);
+		set_bit(KEY_POWER, input_dev->keybit);
+		set_bit(KEY_LID, input_dev->keybit);
+
+		error = input_register_device(input_dev);
+		if (error) {
+			printk(KERN_ERR "Unable to register ACPI input device\n");
+			input_free_device(input_dev);
+		}
+	}
+
 	return_VALUE(0);
 }
 
@@ -484,6 +539,9 @@
 		remove_proc_entry(ACPI_BUTTON_SUBCLASS_LID, acpi_button_dir);
 	remove_proc_entry(ACPI_BUTTON_CLASS, acpi_root_dir);
 
+	if (input_dev)
+		input_unregister_device(input_dev);
+
 	return_VOID;
 }
 
--- include/linux/input.h.bak	2006-04-19 20:47:58 +0100
+++ a/include/linux/input.h	2006-04-19 20:49:18 +0100
@@ -344,6 +344,7 @@
 #define KEY_FORWARDMAIL		233
 #define KEY_SAVE		234
 #define KEY_DOCUMENTS		235
+#define KEY_LID			237
 
 #define KEY_UNKNOWN		240

-- 
Matthew Garrett | mjg59@srcf.ucam.org

             reply	other threads:[~2006-04-19 19:54 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-04-19 19:53 Matthew Garrett [this message]
2006-04-19 20:04 ` [RFC] [PATCH] Make ACPI button driver an input device Dominik Brodowski
2006-04-19 20:24   ` Matthew Garrett
2006-04-24 14:45     ` Dmitry Torokhov
2006-04-24 15:10       ` Matthew Garrett
2006-04-24 16:05       ` Richard Purdie
2006-04-24 16:26         ` Dmitry Torokhov
2006-04-24 17:05           ` Richard Purdie
2006-04-24 20:34             ` Pavel Machek
2006-04-24 20:59               ` Richard Purdie
2006-04-24 21:29                 ` Pavel Machek
2006-04-24 20:20         ` Pavel Machek
2006-04-20 21:56 ` Pavel Machek
  -- strict thread matches above, loose matches on Subject: below --
2006-04-20  5:45 Yu, Luming
2006-04-20  7:37 ` Matthew Garrett
2006-04-20 15:35   ` Alexey Starikovskiy
2006-04-20 15:38     ` Matthew Garrett
2006-04-20 15:57       ` Alexey Starikovskiy
2006-04-20 16:11         ` Xavier Bestel
2006-04-20 16:33           ` Alexey Starikovskiy
2006-04-20 16:44             ` Matthew Garrett
2006-04-20 16:47               ` Alexey Starikovskiy
2006-04-20 16:55                 ` Matthew Garrett
2006-04-20 17:06                   ` Alexey Starikovskiy
2006-04-20 22:03                     ` Pavel Machek
2006-04-20 19:30             ` Dmitry Torokhov
2006-04-20 20:07               ` Xavier Bestel
2006-04-21  8:52                 ` Alexey Starikovskiy
2006-04-20 22:04                   ` Pavel Machek
2006-04-21 12:56                   ` Dmitry Torokhov
2006-04-20 22:01             ` Pavel Machek
2006-04-22 20:59             ` David Weinehall
2006-04-20 16:15         ` Matthew Garrett
2006-04-20 16:28           ` Alexey Starikovskiy
2006-04-20 16:32             ` Matthew Garrett
2006-04-20 16:35               ` Alexey Starikovskiy
2006-04-20 16:45                 ` Matthew Garrett
2006-04-20 22:10                 ` Pavel Machek
2006-04-20 16:58         ` Martin Mares
2006-04-20 17:08           ` Alexey Starikovskiy
2006-04-20 22:07             ` Pavel Machek
2006-04-24  6:54               ` Alexey Starikovskiy
2006-04-24  8:31                 ` Pavel Machek
2006-04-24 14:39                   ` Alexey Starikovskiy
2006-04-24 15:09                     ` Matthew Garrett
2006-04-28 17:43                     ` Stefan Seyfried
2006-04-21  7:27 Yu, Luming
2006-04-20 21:55 ` Pavel Machek
2006-04-24 14:51   ` Dmitry Torokhov
2006-04-21 11:37 ` Martin Mares
2006-04-21 12:21 ` Dmitry Torokhov
2006-04-25 14:17 Yu, Luming

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20060419195356.GA24122@srcf.ucam.org \
    --to=mjg59@srcf.ucam.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox