public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [RFC] [PATCH] Make ACPI button driver an input device
@ 2006-04-19 19:53 Matthew Garrett
  2006-04-19 20:04 ` Dominik Brodowski
  2006-04-20 21:56 ` Pavel Machek
  0 siblings, 2 replies; 52+ messages in thread
From: Matthew Garrett @ 2006-04-19 19:53 UTC (permalink / raw)
  To: linux-acpi, linux-kernel

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

^ permalink raw reply	[flat|nested] 52+ messages in thread
* RE: [RFC] [PATCH] Make ACPI button driver an input device
@ 2006-04-20  5:45 Yu, Luming
  2006-04-20  7:37 ` Matthew Garrett
  0 siblings, 1 reply; 52+ messages in thread
From: Yu, Luming @ 2006-04-20  5:45 UTC (permalink / raw)
  To: Matthew Garrett, linux-acpi, linux-kernel

>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.

Do you plan to port the whole acpi event interface into input layer?
If so,  keycode is NOT a right way.

--Luming

^ permalink raw reply	[flat|nested] 52+ messages in thread
* RE: [RFC] [PATCH] Make ACPI button driver an input device
@ 2006-04-21  7:27 Yu, Luming
  2006-04-20 21:55 ` Pavel Machek
                   ` (2 more replies)
  0 siblings, 3 replies; 52+ messages in thread
From: Yu, Luming @ 2006-04-21  7:27 UTC (permalink / raw)
  To: dtor_core, Alexey Starikovskiy
  Cc: Xavier Bestel, Matthew Garrett, linux-acpi, linux-kernel

>> > There are keyboards with power/sleep buttons. It makes 
>sense they have
>> > the same behavior than ACPI buttons.
>> Agree, make them behave like ACPI buttons -- remove them 
>from input stream, as they do not belong there...
>
>What if there is no ACPI? What if I want to remap the button to do
>something else? Input layer is the proper place for them.

If you define input layer as a universe place to all manual input 
activity, then I agree to port some type of ACPI event into
input layer.  But it shouldn't be a fake keyboard scancode,
My suggestion is to have a separate input event type,e.g. EV_ACPI
for acpi event layer.

>
>--
>Dmitry

Thanks,
Luming

^ permalink raw reply	[flat|nested] 52+ messages in thread
* RE: [RFC] [PATCH] Make ACPI button driver an input device
@ 2006-04-25 14:17 Yu, Luming
  0 siblings, 0 replies; 52+ messages in thread
From: Yu, Luming @ 2006-04-25 14:17 UTC (permalink / raw)
  To: dtor_core
  Cc: Alexey Starikovskiy, Xavier Bestel, Matthew Garrett, linux-acpi,
	linux-kernel

>> >> > There are keyboards with power/sleep buttons. It makes
>> >sense they have
>> >> > the same behavior than ACPI buttons.
>> >> Agree, make them behave like ACPI buttons -- remove them
>> >from input stream, as they do not belong there...
>> >
>> >What if there is no ACPI? What if I want to remap the button to do
>> >something else? Input layer is the proper place for them.
>>
>> If you define input layer as a universe place to all manual input
>> activity,
>
>Yes. If something is related to input it should be integrated 
>into input layer.

Yes, it sounds reasonable. Then, at least, the user space Apps can
rely on a single interface, and don't need to know the implementation  
details for the common input event. That will save a lot of support
effort. 

>
>> then I agree to port some type of ACPI event into
>> input layer.  But it shouldn't be a fake keyboard scancode,
>> My suggestion is to have a separate input event type,e.g. EV_ACPI
>> for acpi event layer.
>>
>
>The point is that it is not a fake scancode. There are keyboards that
>have these keys that don't have anything to do with ACPI. That's why
>they belong to input layer. The same goes for lid switch - we have
>EV_SW that is used by some PDAs.

ok.

>
>Note that I am not saying that other ACPI events, like battery status
>or device insertion/removal, should be propagated through input layer.
>But things that exist even without ACPI should not be ACPI-specific.
>

I'm NOT sure if it is reasonable to propagate other ACPI events 
through input layer.  But from my understanding, Laptop with ACPI
features 
should be the super class of PDA. It would be nice to have input layer
handle all ACPI events. Then, we can enjoy the advantage of a single 
input interface for user Apps.

--Luming 

^ permalink raw reply	[flat|nested] 52+ messages in thread

end of thread, other threads:[~2006-04-28 17:46 UTC | newest]

Thread overview: 52+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-04-19 19:53 [RFC] [PATCH] Make ACPI button driver an input device Matthew Garrett
2006-04-19 20:04 ` 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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox