Tuesday, September 29, 2009

Logitech S510 keyboard in Linux

There was a long journey to working keyboard setup. All started with a switch from 2.6.26-i686 kernel to new kernel 2.6.28-amd64 and the way it handled keyboard as device. There were no xev events on multimedia keys but usbmon has been showing some traffic going on from keyboard. I though that must be some problem with kernel and commited bug report, awaiting some answers. Few months has passed until Dmitry Torokhov metioned evtest utility and I have found another logical device, that udev has been creating for my keyboard. The next step was putting that other device to work as multimedia keys.
Adding InputDevice section in xorg.conf was enough until udev changed the input device number. So I had to come with stable solution. HAL was no way to go (terribly complicated), so only possible way was to set exact number for device at udev.
First I had to find device, that was created for multimedia keys

cat /proc/bus/input/devices
Standard keys:

I: Bus=0003 Vendor=046d Product=c517 Version=0110
N: Name="Logitech USB Receiver"
P: Phys=usb-0000:00:1d.0-2.1/input0
S: Sysfs=/devices/pci0000:00/0000:00:1d.0/usb5/5-2/5-2.1/5-2.1:1.0/input/input3
U: Uniq=
H: Handlers=kbd event3
B: EV=120013
B: KEY=1000000000007 ff800000000007ff febeffdfffefffff fffffffffffffffe
B: MSC=10
B: LED=1f

Multimedia keys:

I: Bus=0003 Vendor=046d Product=c517 Version=0110
N: Name="Logitech USB Receiver"
P: Phys=usb-0000:00:1d.0-2.1/input1
S: Sysfs=/devices/pci0000:00/0000:00:1d.0/usb5/5-2/5-2.1/5-2.1:1.1/input/input4
U: Uniq=
H: Handlers=kbd mouse1 event4
B: EV=1f
B: KEY=837fff042c332f bf08444400000000 ff0001 1f848a37cc00 667bfadd71dfed
9e000000000000 0
B: REL=1c3
B: ABS=100000000
B: MSC=10

So /dev/input/event4 was device for multimedia keys and I just had to look for exact ID, udev is using to identify device.
udevadm info --query=all --name=/dev/input/event4 --attribute-walk | grep modalias

The line I was interested in showed following:
ATTRS{modalias}=="usb:v046DpC517d3810dc00dsc00dp00ic03isc01ip02"

With exact device ID, I could create udev rule /etc/udev/rules.d/z70_logitech_multimedia.rules containing following line:
KERNEL=="event*", ATTRS{modalias}=="usb:v046DpC517d3810dc00dsc00dp00ic03isc01ip02", MODE="0644", NAME="input/event20"

This way udev create always /dev/input/event20 for device with ID "usb:v046DpC517d3810dc00dsc00dp00ic03isc01ip02". Event number should be reasonably high not to conflict with other logical devices that could be created by udev.

Final step was adding another InputDevice in /etc/X11/xorg.conf section:
Section "InputDevice"
Identifier "Multimedia keys"
Driver "evdev"
Option "Protocol" "evdev"
Option "Device" "/dev/input/event20"
Option "XkbModel" "evdev"
EndSection

Almost all multimedia keys started to work after I removed .xmodmap(ing) I was using with old kernel (2.6.26-i686) - some mappings got messed up with new setup.

"Almost all" I mean except shuffle, rotate and zoom keys - but I can live with that until xorg-xserver get REAL key mapping not just 256 keycodes.


Edit
If I first said that HAL was no way to go, that was truth until first system hibernation or keyboard unplug. When you hibernate/resume system or connect keyboard after xserver has been started, the HAL is the only way how to setup multimedia keys. After some woodoo with HAL, I came up with following fdi file:
cat /usr/share/hal/fdi/policy/20thirdparty/30-logitech-multimedia-keys.fdi 

<?xml version="1.0" encoding="ISO-8859-1"?> <!-- -*- SGML -*- -->

<deviceinfo version="0.2">
<device>

<match key="info.udi" prefix="/org/freedesktop/Hal/devices/usb_device_46d_c517_noserial_if1_logicaldev_input">
<append key="info.addons.singleton" type="strlist">hald-addon-input</append>
<merge key="info.capabilities" type="strlist">input</merge>
<append key="info.capabilities" type="strlist">input.keyboard</append>
<append key="info.capabilities" type="strlist">input.keys</append>
<merge key="input.x11_driver" type="string">evdev</merge>
<merge key="input.xkb.model" type="string">evdev</merge>
</match>

</device>
</deviceinfo>

3 comments:

WLT said...

Do you mind me asking what your initial problem was? I have the same wireless keyboard and mouse, and since switching to a 64bit kernel, I get intermittent mouse failure, and with it, multimedia key failure. I haven't been able to isolate the problem, or find anyone else with the same issue.

Q said...

The thing is, that 64bit kernel split one physical device (keyboard) to two logical devices (standard keys and multimedia keys). So you have to instruct xorg or HAL to handle those devices properly. Both cases are described in the blog post.

I don't use mouse that comes with keyboard, but I think you can figure out how to get it in working order by using similar procedure as with multimedia keys.

naveed ahmad khan said...

t was preeti good site then other when i visited last month
and got good information about work from home


work from home