virtio-input: add multi-touch support

Without multi-touch slots allocated, ABS_MT_SLOT events will be lost by
input_handle_abs_event.

Implementation is based on uinput_create_device.

Signed-off-by: Mathias Crombez <mathias.crombez@faurecia.com>
Co-developed-by: Vasyl Vavrychuk <vasyl.vavrychuk@opensynergy.com>
Signed-off-by: Vasyl Vavrychuk <vasyl.vavrychuk@opensynergy.com>
Link: https://lore.kernel.org/r/20210115002623.8576-1-vasyl.vavrychuk@opensynergy.com
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Gerd Hoffmann <kraxel@redhat.com>
This commit is contained in:
Mathias Crombez 2021-01-15 02:26:23 +02:00 committed by Michael S. Tsirkin
parent 0c4aeb4b50
commit 16c10bede8

View File

@ -7,6 +7,7 @@
#include <uapi/linux/virtio_ids.h> #include <uapi/linux/virtio_ids.h>
#include <uapi/linux/virtio_input.h> #include <uapi/linux/virtio_input.h>
#include <linux/input/mt.h>
struct virtio_input { struct virtio_input {
struct virtio_device *vdev; struct virtio_device *vdev;
@ -219,7 +220,7 @@ static int virtinput_probe(struct virtio_device *vdev)
struct virtio_input *vi; struct virtio_input *vi;
unsigned long flags; unsigned long flags;
size_t size; size_t size;
int abs, err; int abs, err, nslots;
if (!virtio_has_feature(vdev, VIRTIO_F_VERSION_1)) if (!virtio_has_feature(vdev, VIRTIO_F_VERSION_1))
return -ENODEV; return -ENODEV;
@ -304,6 +305,13 @@ static int virtinput_probe(struct virtio_device *vdev)
continue; continue;
virtinput_cfg_abs(vi, abs); virtinput_cfg_abs(vi, abs);
} }
if (test_bit(ABS_MT_SLOT, vi->idev->absbit)) {
nslots = input_abs_get_max(vi->idev, ABS_MT_SLOT) + 1;
err = input_mt_init_slots(vi->idev, nslots, 0);
if (err)
goto err_mt_init_slots;
}
} }
virtio_device_ready(vdev); virtio_device_ready(vdev);
@ -319,6 +327,7 @@ err_input_register:
spin_lock_irqsave(&vi->lock, flags); spin_lock_irqsave(&vi->lock, flags);
vi->ready = false; vi->ready = false;
spin_unlock_irqrestore(&vi->lock, flags); spin_unlock_irqrestore(&vi->lock, flags);
err_mt_init_slots:
input_free_device(vi->idev); input_free_device(vi->idev);
err_input_alloc: err_input_alloc:
vdev->config->del_vqs(vdev); vdev->config->del_vqs(vdev);