For quite a while on several systems where ACPI is used to deliver key press events to the operating system (mostly laptops, that's why we got the asus_acpi, thinkpad, toshiba, sony,... drivers in the kernel). In userspace acpid was used then to fetch these commands, a callout script was used which used some application to inject the corresponding keycode (based on the ACPI event ID, which is just "randomly chosen" by the hardware manufacturers) on some input device, so applications (eg your X server) were able to see the key press events. Especially the acpid -> callout -> map scancode to keycode -> inject in input device isn't such a "nice" solution, but it worked, most of the time.
Recently people (one of them Richard Hughes of GPM fame, you know, that power-eating applet ;-)) started to rework these in-kernel drivers to use the kernel input subsystem directly, so no more round-trip to userspace would be necessary.
There are 2 possibilities here: you can store a scancode to keycode mapping table in the driver itself, or you can remap scancodes to a keycode from userspace on some device using ioctl's.
This last method is made easy by HAL (0.5.10 or git), which includes a callout which allows you to store the mappings in an FDI file, and then performs the remapping when a matched device is found on the system. More information about this can be found here.
IMHO this method is the cleanest, as it doesn't force us to store big device-specific mapping tables in the kernel driver. It's userspace so much easier to make changes, add new device information,...
ASUS laptop owners couldn't make use of this yet as nor the in-kernel driver, asus_laptop, or it's -cvs version provide relaying to a kernel input device. Yesterday I decided to implement this, and today it got somewhat finished, after some minor issues. You can find the resulting patch here, it's against current acpi4asus CVS, but I think it should apply cleanly against a vanilla kernel too. I'll submit it to the acpi4asus list tomorrow. Git repository is here, you want the "acpi_keys_to_input_layer_no_internal_mapping" branch.
After compiling the driver and insmoding it (or modprobe if you install it too, make sure you don't load the old version by accident) you should see some information in dmesg: a message the driver is loaded, the name of your laptop model, and the fact a new input device called "Asus Extra Buttons" was created. Now when you press some multimedia buttons and check dmesg again, it should tell you some keys were pressed it can't map to a known keycode, also providing the scancode. You can use this information to generate an FDI file as described in the pages I linked to before.
If you're using an "old" HAL version, you can download a small utility here to emulate HAL's behaviour using hard-coded information. You need to make a list of scancodes and their meaning using KEY_* values. You can find these constants in /usr/include/linux/input.h, or in include/linux/input.h of your local kernel source tree.
Once you know which scancodes map to which KEY_* value, you can add them to the "mappings" variable defined at the top of the C file. The format is simple: scancode1, keycode1, scancode2, keycode2,...,-1. Make sure you always add pairs of scancode/keycode values, and end the array with a -1.
Once you entered the values, compile the program (gcc -o set-asus-keymap set-asus-keymap.c), figure out the event device node for the Asus Extra Buttons device (check /proc/bus/input/devices, where Name is Asus Extra Buttons, see which eventX is after Handlers), and run the program (as root) using ./set-asus-keymap /dev/event/eventX (now I don't want *any* comments on this entry regarding "I have no eventX node").
When you're done with this, create a nice FDI file too, and send it to the HAL mailing list so others can enjoy your research too :-)
That's about it, your special keys should "just work" and acpid is no longer necessary to handle them.
Advertisement:
Comments:
I just bought an Asus laptop and I couldn't find a way to make the "turn off Wifi" button work.
Do you have any advice on how to do that? I was thinking about linking it to a shell script that would rmmod the iwl4965 module and the bluetooth modules. If there is a cleaner way, I'm here to listen :)
Thanks again!
HAL got support for the ipw killswitch, so that shouldn't be an issue. There are several ways to "power off" a bluetooth or wlan device, next to rmmod'ing the module, think of hcitool hci0 down, or iwconfig wlan0 down.
The "performance buttons" could eg also change GPU speed settings, set your wlan chipset to a lower power mode, etc. Would be an interesting project.
I'll look into compiling properly hal 0.5.10 (not even Gutsy has packages, meh) and try to prepare .fdi files.
Thanks again for your help!
keyboard.c: can't emulate rawmode for keycode 240
keyboard.c: can't emulate rawmode for keycode 240
asus-laptop: scancode 0x51 is unknown
Last line is your log. I think that previous two means that event was not generated because of a bug. Can you help me with that?
My model is:
system.hardware.product = 'V1J' (string)
system.hardware.serial = 'SSN12345678901234567' (string)
system.hardware.uuid = '533381DB-584F-4B81-7E80-0018F33C278E' (string)
system.hardware.vendor = 'ASUSTeK Computer Inc.' (string)
system.hardware.version = '1.0' (string)
I used asus-laptop -0.42-cvs
Keymap is also registered
info.capabilities = {'input', 'button', 'input.keymap'} (string list)
input.keymap.data = {'0x50:email', '0x51:www'} (string list)
Szymon O
info.capabilities = {'input', 'button', 'input.keymap'} (string list)
input.keymap.data = {'0x50:email', '0x51:www'} (string list)
Maybe I registered it wrong. I did new file like that:
<?xml version="1.0" encoding="ISO-8859-1"?> <!-- -*- SGML -*- -->
<deviceinfo version="0.2">
<device>
<!-- These are raw scancodes produced by the asus-latop driver with patch form http://blog.eikke.com/index.php/ikke/2007/08/15/asus_laptops_multimedia_keys_and_input -->
<match key="input.product" string="Asus Extra Buttons">
<match key="/org/freedesktop/Hal/devices/computer:system.hardware.vendor" prefix="ASUSTeK">
<match key="/org/freedesktop/Hal/devices/computer:system.hardware.product" contains="V1J">
<append key="input.keymap.data" type="strlist">0x50:email</append> <!-- Email -->
<append key="input.keymap.data" type="strlist">0x51:www</append> <!-- I key -->
<append key="info.capabilities" type="strlist">input.keymap</append>
</match>
</match>
</match>
</device>
</deviceinfo>
I bind keys to "Asus Extra Buttons" input.product is that ok?
This post has 7 feedbacks awaiting moderation...