Bug 222609 - x11-servers/xorg-server: Add UDEV option to support evdev devices autodetection
Summary: x11-servers/xorg-server: Add UDEV option to support evdev devices autodetection
Status: Open
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Many People
Assignee: freebsd-x11 mailing list
URL:
Keywords: patch
Depends on:
Blocks:
 
Reported: 2017-09-25 22:13 UTC by Greg V
Modified: 2019-11-09 12:56 UTC (History)
12 users (show)

See Also:
bugzilla: maintainer-feedback? (x11)


Attachments
xorg-server-udev.patch (1.43 KB, patch)
2017-09-25 22:13 UTC, Greg V
no flags Details | Diff
xorg log (13.45 KB, text/x-log)
2017-10-12 10:30 UTC, Ivan
no flags Details
device list (2.23 KB, text/x-log)
2017-10-12 10:32 UTC, Ivan
no flags Details
boot log (6.15 KB, text/x-log)
2017-10-16 07:24 UTC, Ivan
no flags Details
evdev desc (3.41 KB, text/x-log)
2017-10-16 07:24 UTC, Ivan
no flags Details
fix-synaptics-resolution.patch (569 bytes, patch)
2017-10-16 22:35 UTC, Vladimir Kondratyev
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Greg V 2017-09-25 22:13:48 UTC
Created attachment 186724 [details]
xorg-server-udev.patch

This patch allows Xorg to be built with libudev-devd support, which allows automatic detection of /dev/input/* (evdev) devices, supported by xf86-input-libinput or xf86-input-evdev.
Comment 1 Jean-Sébastien Pédron freebsd_committer 2017-10-04 22:40:18 UTC
Hi!

I tried your patch + drm-next and it's working quite nicely!

I used xf86-input-libinput to drive a Synaptics touchpad (Thinkpad T440p) and an external USB mouse, and xf86-input-evdev to drive the internal keyboard of the laptop and an external USB keyboard.

I couldn't get the keyboard to work with xf86-input-libinput, even though correct events are reported by libinput-debug-events(1). With xf86-input-evdev, it looks ok, though with the internal keyboard, the "less than/greater than" key doesn't emit any event. I didn't check if the same issue exists with the external keyboard. They are a few other bugs with the touchpad as well, but it's still better than without libinput.

I don't know if it was necessary, but I added InputClass blocks to ignore other devices, like duplicates (/dev/{psm,sysmouse,atkbd,kbdmux}* vs /dev/event/*).
Comment 2 Greg V 2017-10-04 23:19:35 UTC
(In reply to Jean-Sébastien Pédron from comment #1)
It's not necessary, libudev-devd only discovers /dev/input/event* devices.
Comment 3 Vladimir Kondratyev freebsd_committer 2017-10-04 23:46:51 UTC
(In reply to Greg V from comment #0)
Slightly enhanced version of this patch was to included into XOrg update to version 1.19.3 but it has not hit ports tree yet for unknown reasons:
https://lists.freebsd.org/pipermail/freebsd-x11/2017-March/019100.html
Comment 4 Greg V 2017-10-04 23:56:13 UTC
(In reply to Vladimir Kondratyev from comment #3)
Hmm! "The devd config backend has been updated to handle /dev/hidX and 
/dev/input/eventX devices as provided by webcamd" — I wonder how *that* interacts with evdev devices from the kernel and handling duplicates in that case…
Comment 5 Vladimir Kondratyev freebsd_committer 2017-10-04 23:57:35 UTC
(In reply to Jean-Sébastien Pédron from comment #1)
> I couldn't get the keyboard to work with xf86-input-libinput

IIRC, libinput requires "xkb_rules" set to "evdev" explicitly

Try to add lines below to your xorg.conf after this patch has been applied:
Section "InputClass"
       Identifier              "Evdev keyboard XkbRules"
       MatchDevicePath         "/dev/input/event*"
       MatchIsKeyboard         "on"
       Option                  "XkbRules" "evdev"
EndSection
Comment 6 Vladimir Kondratyev freebsd_committer 2017-10-05 00:13:16 UTC
(In reply to Greg V from comment #4)
> I wonder how *that* interacts with evdev devices from the kernel and handling duplicates in that case
webcamd inter-operates with inkernel evdev-capable drivers almost perfectly. It just disables kernel driver at attach (but not restores it at detach). It has support for free /dev/input/* character device units detection and has the same API.
Comment 7 Vladimir Kondratyev freebsd_committer 2017-10-05 00:31:13 UTC
(In reply to Vladimir Kondratyev from comment #3)
> Slightly enhanced version of this patch was to included into XOrg update to version 1.19.3
I should mention that 1.19.3 update patches are made for kernel compiled w/o option EVDEV_SUPPORT. They require some additional work to properly handle kernels compiled with this option enabled.
Comment 8 Ivan 2017-10-05 19:59:23 UTC
Do we need CURRENT for testing ? I'm not sure I have /dev/input on my laptop with 11.1-RELEASE generic kernel.
Comment 9 Greg V 2017-10-05 20:02:56 UTC
(In reply to Ivan from comment #8)
I think some evdev stuff might have landed in 11, but you need to recompile your kernel with 'device evdev' and 'options EVDEV_SUPPORT'. (Or kldload evdev instead of compiling in the device I guess??)
Comment 10 Ivan 2017-10-12 09:09:46 UTC
kldload evdev doesn't bring /dev/input node up for me, but custom kernel is.
Proceeding to test now. :)
How can I discover what device every eventX represents?
Comment 11 Greg V 2017-10-12 10:05:26 UTC
(In reply to Ivan from comment #10)
Yeah, you need EVDEV_SUPPORT to enable the evdev support in the actual drivers (ums, ukbd, psm, etc.)

Use libinput-list-devices to list devices
Comment 12 Ivan 2017-10-12 10:29:46 UTC
I see echo from keys I pressing. It starts from the left top and proceeds to right bottom, as if I write text with editor. When I hit enter here, echo makes CR as well.
I use libinput driver.

Also, I've noticed that arrow keys are not working (but emitting something as echo)

Synaptics touchpad in not working as well.
Comment 13 Ivan 2017-10-12 10:30:39 UTC
Created attachment 187100 [details]
xorg log
Comment 14 Greg V 2017-10-12 10:32:30 UTC
(In reply to Ivan from comment #12)
Make sure you have kern.evdev.rcpt_mask=12 to get events from psm/ums/ukbd instead of sysmouse/kbdmux.

For arrow keys, make sure you have the evdev XKB ruleset (setxkbmap -rules evdev).
Comment 15 Ivan 2017-10-12 10:32:41 UTC
Created attachment 187101 [details]
device list
Comment 16 Ivan 2017-10-12 10:49:35 UTC
I set sysctl option and evdev rules. Arrow keys are fixed now.
Touchpad is not working. I have /dev/psm0 and hw.psm.synaptics_support=1 in loader.conf
And, echoing input is a show breaker.
Comment 17 Greg V 2017-10-12 10:57:48 UTC
(In reply to Ivan from comment #16)
Synaptics works for me… You don't even have the /dev/input device for it, that's weird. If you built your kernel with EVDEV_SUPPORT, psm should create an evdev device.

I don't understand what you mean by "echo"…
Comment 18 Ivan 2017-10-12 11:23:26 UTC
http://i.imgur.com/YzxZ225.png
When I type something, I see phantom output. It reflects all my actions, like console under by X11 session. I never see this effect before with legacy xf86-input drivers.
Comment 19 Ivan 2017-10-12 11:29:44 UTC
Phantom output is pure graphical glitch, so it doesn't interfere with actual keystrokes, like if libinput send keystrokes into 2 destinations.
Comment 20 Vladimir Kondratyev freebsd_committer 2017-10-12 23:15:37 UTC
(In reply to Ivan from comment #19)
> I see phantom output.
It is known issue. Try https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=220562
Comment 21 Ivan 2017-10-13 12:18:27 UTC
Thanks! I've used wrong words googling the matter. Now libinput works perfectly. As for synaptics touchpad, evdev support for psm devices is not merged into 11.1-RELENG.
Comment 22 Ivan 2017-10-15 12:48:14 UTC
Probably, I'm doing it wrong to use this bug for support, feel free to point me to right direction, but I can't get node for synaptics touchpad on STABLE and according commits, this code is already in. https://reviews.freebsd.org/D10265

1. FreeBSD 11.1-STABLE #1 r324623: Sun Oct 15 15:10:17 MSK 2017
2. Custom kernel with 
device evdev
options EVDEV_SUPPORT
3. hw.psm.synaptics_support=1 in /boot/loader.conf
4. kern.evdev.rcpt_mask=12 in /etc/sysctl.conf

I don't see touchpad under /dev/input , and /dev/input/event3 is missing in libinput-list-devices.

 ls /dev/input/
event0 event1 event2 event3 event4 event5 

When I run libinput-list-devices, event3 is skipped, the following warning is printed

# libinput-list-devices
libinput error: kernel bug: Kernel has only x or y resolution, not both.

Here is bits from /var/log/messages
Oct 15 15:28:27 sphinx kernel: psm0: <PS/2 Mouse> irq 12 on atkbdc0
Oct 15 15:28:27 sphinx kernel: psm0: [GIANT-LOCKED]
Oct 15 15:28:27 sphinx kernel: psm0: model Synaptics Touchpad, device ID 3
Comment 23 Ivan 2017-10-15 12:57:38 UTC
abishai@sphinx:~ % sysctl -a | grep synaptics
hw.psm.synaptics.softbutton3_x: 3900
hw.psm.synaptics.softbutton2_x: 3100
hw.psm.synaptics.softbuttons_y: 1700
hw.psm.synaptics.touchpad_off: 0
hw.psm.synaptics.vscroll_div_max: 150
hw.psm.synaptics.vscroll_div_min: 100
hw.psm.synaptics.vscroll_min_delta: 50
hw.psm.synaptics.vscroll_ver_area: -600
hw.psm.synaptics.vscroll_hor_area: 0
hw.psm.synaptics.taphold_timeout: 125000
hw.psm.synaptics.tap_min_queue: 2
hw.psm.synaptics.tap_max_delta: 80
hw.psm.synaptics.div_len: 100
hw.psm.synaptics.div_max_na: 30
hw.psm.synaptics.div_max: 17
hw.psm.synaptics.div_min: 9
hw.psm.synaptics.weight_len_squared: 2000
hw.psm.synaptics.weight_previous_na: 20
hw.psm.synaptics.weight_previous: 6
hw.psm.synaptics.weight_current: 3
hw.psm.synaptics.multiplicator: 10000
hw.psm.synaptics.window_max: 10
hw.psm.synaptics.window_min: 4
hw.psm.synaptics.na_left: 1600
hw.psm.synaptics.na_bottom: 1408
hw.psm.synaptics.na_right: 563
hw.psm.synaptics.na_top: 1783
hw.psm.synaptics.margin_left: 200
hw.psm.synaptics.margin_bottom: 200
hw.psm.synaptics.margin_right: 200
hw.psm.synaptics.margin_top: 200
hw.psm.synaptics.max_width: 10
hw.psm.synaptics.max_pressure: 220
hw.psm.synaptics.min_pressure: 32
hw.psm.synaptics.two_finger_scroll: 1
hw.psm.synaptics.max_y: 6143
hw.psm.synaptics.max_x: 6143
hw.psm.synaptics.directional_scrolls: 0
hw.psm.synaptics_support: 1

sysctls for synaptics. Looks like libinput rejecting this touchpad
Comment 24 Ivan 2017-10-15 13:03:48 UTC
And Xorg logs
[    19.170] (II) config/udev: Adding input device SynPS/2 Synaptics TouchPad (/dev/input/event3)
[    19.170] (**) SynPS/2 Synaptics TouchPad: Applying InputClass "libinput pointer catchall"
[    19.170] (**) SynPS/2 Synaptics TouchPad: Applying InputClass "libinput touchpad catchall"
[    19.170] (II) Using input driver 'libinput' for 'SynPS/2 Synaptics TouchPad'
[    19.170] (**) SynPS/2 Synaptics TouchPad: always reports core events
[    19.170] (**) Option "Device" "/dev/input/event3"
[    19.170] (**) Option "_source" "server/udev"
[    19.382] (II) input device 'SynPS/2 Synaptics TouchPad', /dev/input/event3 is tagged by udev as: Mouse Touchpad
[    19.382] (EE) kernel bug: Kernel has only x or y resolution, not both.
[    19.382] (II) input device 'SynPS/2 Synaptics TouchPad', /dev/input/event3 was rejected.
[    19.417] (II) not using input device '/dev/input/event3'.
[    19.417] (EE) libinput: SynPS/2 Synaptics TouchPad: Failed to create a device for /dev/input/event3
[    19.417] (EE) PreInit returned 2 for "SynPS/2 Synaptics TouchPad"
[    19.417] (II) UnloadModule: "libinput"


So, event3 is created for touchpad, but it's rejected.
https://github.com/wayland-project/libinput/blob/master/src/evdev.c#L1437
Comment 25 Vladimir Kondratyev freebsd_committer 2017-10-15 21:26:31 UTC
(In reply to Ivan from comment #23)
All these sysctls has no meaning for evdev except
> hw.psm.synaptics.min_pressure: 32
Comment 26 Vladimir Kondratyev freebsd_committer 2017-10-15 21:36:20 UTC
(In reply to Ivan from comment #24)
> [    19.382] (EE) kernel bug: Kernel has only x or y resolution, not both.
Very strange...

Could you:
1. Place debug.psm.loglevel=5 in to /boot/loader.conf and post here a part of boot log from "synaptics: BEGIN init" to "synaptics: END init"
2. Install devel/evemu and run evemu-describe or evemu-record on your touchpad /dev/input/eventN device node
Comment 27 Ivan 2017-10-16 07:24:03 UTC
Created attachment 187207 [details]
boot log
Comment 28 Ivan 2017-10-16 07:24:38 UTC
Created attachment 187208 [details]
evdev desc
Comment 29 Ivan 2017-10-16 07:33:42 UTC
I have the following device hint  hint.psm.0.flags="0x24" It left since I tried if psm flags can help me somehow. 
If it's interfering with logs attached I can repeat without it.
Comment 30 Vladimir Kondratyev freebsd_committer 2017-10-16 09:29:43 UTC
(In reply to Ivan from comment #29)
> If it's interfering with logs attached I can repeat without it.
No need. I`ll post fix here after getting access to my laptop with synaptics touchpad.
Comment 31 Vladimir Kondratyev freebsd_committer 2017-10-16 22:35:50 UTC
Created attachment 187227 [details]
fix-synaptics-resolution.patch

The patch does some extra sanity checks to avoid "only one axis has resolution" libinput issue
Comment 32 Ivan 2017-10-17 07:31:10 UTC
Thank you!
I hope resolution values are not needed elsewhere.

Touchpad works, I added some hints for better usability

Section "InputClass"
    Identifier "touchpad"
    MatchIsTouchpad "on"
    Option "TransformationMatrix" "1 0 0 0 1 0 0 0 0.7"
    Option "Tapping" "on"
    Option "ScrollMethod" "edge"
EndSection

TransformationMatrix boosts speed slightly. I was unable to adjust it in xfce configuration.

[  3691.584] (II) config/udev: Adding input device SynPS/2 Synaptics TouchPad (/dev/input/event3)
[  3691.584] (**) SynPS/2 Synaptics TouchPad: Applying InputClass "libinput pointer catchall"
[  3691.584] (**) SynPS/2 Synaptics TouchPad: Applying InputClass "libinput touchpad catchall"
[  3691.584] (**) SynPS/2 Synaptics TouchPad: Applying InputClass "touchpad"
[  3691.584] (II) Using input driver 'libinput' for 'SynPS/2 Synaptics TouchPad'
[  3691.584] (**) SynPS/2 Synaptics TouchPad: always reports core events
[  3691.584] (**) Option "Device" "/dev/input/event3"
[  3691.584] (**) Option "_source" "server/udev"
[  3691.799] (II) input device 'SynPS/2 Synaptics TouchPad', /dev/input/event3 is tagged by udev as: Mouse Touchpad
[  3691.799] (II) SynPS/2 Synaptics TouchPad: no resolution or size hints, assuming a size of 69x50mm
[  3691.799] (II) input device 'SynPS/2 Synaptics TouchPad', /dev/input/event3 is a touchpad
[  3691.834] (**) Option "Tapping" "on"
[  3691.834] (**) Option "ScrollMethod" "edge"
[  3691.834] (**) Option "config_info" "udev:/dev/input/event3"
[  3691.834] (II) XINPUT: Adding extended input device "SynPS/2 Synaptics TouchPad" (type: TOUCHPAD, id 9)
[  3691.834] (**) Option "AccelerationScheme" "none"
[  3691.834] (**) SynPS/2 Synaptics TouchPad: (accel) selected scheme none/0
[  3691.834] (**) SynPS/2 Synaptics TouchPad: (accel) acceleration factor: 2.000
[  3691.834] (**) SynPS/2 Synaptics TouchPad: (accel) acceleration threshold: 4
[  3691.834] (**) Option "TransformationMatrix" "1 0 0 0 1 0 0 0 0.7"
[  3692.054] (II) input device 'SynPS/2 Synaptics TouchPad', /dev/input/event3 is tagged by udev as: Mouse Touchpad
[  3692.054] (II) SynPS/2 Synaptics TouchPad: no resolution or size hints, assuming a size of 69x50mm
[  3692.054] (II) input device 'SynPS/2 Synaptics TouchPad', /dev/input/event3 is a touchpad
Comment 33 commit-hook freebsd_committer 2017-11-01 09:19:35 UTC
A commit references this bug:

Author: dumbbell
Date: Wed Nov  1 09:18:41 UTC 2017
New revision: 325269
URL: https://svnweb.freebsd.org/changeset/base/325269

Log:
  evdev: Translate KEY_102ND in evdev_scancode2key()

  This is the extra key on 102/105-keys keyboards, located on the right
  of the Left Shift key. For instance on a French layout, this is the '<'
  key.

  This fixes an issue where the key fires no evdev event and thus remains
  inactive in an evdev/libinput-enabled X.Org server. The issue only
  occurred on an AT keyboard; the same key on a USB keyboard worked fine.

  PR:		222609 (only for reference)
  Approved by:	wulf@
  Differential Revision:	https://reviews.freebsd.org/D12883

Changes:
  head/sys/dev/evdev/evdev_utils.c
Comment 34 Kirill Ponomarev freebsd_committer 2018-04-29 19:51:53 UTC
Is it possible to commit UDEV support soon?
Comment 35 Guido Kollerie 2019-05-28 06:08:53 UTC
(In reply to Kirill Ponomarev from comment #34)

I tested the xorg-server-udev.patch (without any of the other patches attached to this bug) on FreeBSD 12-stable as I struggled to get the touchpad on my Thinkpad T480 configured properly by any other means. Seems to work beautifully. Is there anything I can help with (testing wise) to get UDEV committed soon?
Comment 36 Guido Kollerie 2019-06-17 06:37:18 UTC
(In reply to Guido Kollerie from comment #35)

With the xorg-server-udev.patch applied, the keyboard shorts for switching virtual consoles becomes Alt-F[1-8] instead of the expected Ctlt-Alt-F[1-8].

Hence I've reverted to the regular, unpatched xorg-server for now. Which is a pitty, as the out-of-the-box experience for touchpads is so much better with evdev/libinput. Not only is the touchpad usable by default with evdev/libinput, desktop environments such as Mate, recognize the touchpad as being a touchpad and provide a separate Touchpad tab in Mouse Settings.

Anyway, still willing to help with testing.