Commit 3ef8a2ee authored by Oleksandr Andrushchenko's avatar Oleksandr Andrushchenko Committed by Dmitry Torokhov

Input: xen-kbdfront - allow better run-time configuration

It is now only possible to control if multi-touch virtual device
is created or not (via the corresponding XenStore entries),
but keyboard and pointer devices are always created.
In some cases this is not desirable. For example, if virtual
keyboard device is exposed to Android then the latter won't
automatically show on-screen keyboard as it expects that a
physical keyboard device can be used for typing.

Utilize keyboard and pointer device XenStore feature fields to
configure which virtual devices are created:
 - set "feature-disable-keyboard" to 1 if no keyboard device
   needs to be created
 - set "feature-disable-pointer" to 1 if no pointer device
   needs to be created
Keep old behavior by default.
Signed-off-by: default avatarOleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>
Suggested-by: default avatarAndrii Chepurnyi <andrii_chepurnyi@epam.com>
Tested-by: default avatarAndrii Chepurnyi <andrii_chepurnyi@epam.com>
Reviewed-by: default avatarJuergen Gross <jgross@suse.com>
Signed-off-by: default avatarDmitry Torokhov <dmitry.torokhov@gmail.com>
parent ce6f7d08
...@@ -63,6 +63,9 @@ static void xenkbd_disconnect_backend(struct xenkbd_info *); ...@@ -63,6 +63,9 @@ static void xenkbd_disconnect_backend(struct xenkbd_info *);
static void xenkbd_handle_motion_event(struct xenkbd_info *info, static void xenkbd_handle_motion_event(struct xenkbd_info *info,
struct xenkbd_motion *motion) struct xenkbd_motion *motion)
{ {
if (unlikely(!info->ptr))
return;
input_report_rel(info->ptr, REL_X, motion->rel_x); input_report_rel(info->ptr, REL_X, motion->rel_x);
input_report_rel(info->ptr, REL_Y, motion->rel_y); input_report_rel(info->ptr, REL_Y, motion->rel_y);
if (motion->rel_z) if (motion->rel_z)
...@@ -73,6 +76,9 @@ static void xenkbd_handle_motion_event(struct xenkbd_info *info, ...@@ -73,6 +76,9 @@ static void xenkbd_handle_motion_event(struct xenkbd_info *info,
static void xenkbd_handle_position_event(struct xenkbd_info *info, static void xenkbd_handle_position_event(struct xenkbd_info *info,
struct xenkbd_position *pos) struct xenkbd_position *pos)
{ {
if (unlikely(!info->ptr))
return;
input_report_abs(info->ptr, ABS_X, pos->abs_x); input_report_abs(info->ptr, ABS_X, pos->abs_x);
input_report_abs(info->ptr, ABS_Y, pos->abs_y); input_report_abs(info->ptr, ABS_Y, pos->abs_y);
if (pos->rel_z) if (pos->rel_z)
...@@ -97,6 +103,9 @@ static void xenkbd_handle_key_event(struct xenkbd_info *info, ...@@ -97,6 +103,9 @@ static void xenkbd_handle_key_event(struct xenkbd_info *info,
return; return;
} }
if (unlikely(!dev))
return;
input_event(dev, EV_KEY, key->keycode, value); input_event(dev, EV_KEY, key->keycode, value);
input_sync(dev); input_sync(dev);
} }
...@@ -192,7 +201,7 @@ static int xenkbd_probe(struct xenbus_device *dev, ...@@ -192,7 +201,7 @@ static int xenkbd_probe(struct xenbus_device *dev,
const struct xenbus_device_id *id) const struct xenbus_device_id *id)
{ {
int ret, i; int ret, i;
unsigned int abs, touch; bool with_mtouch, with_kbd, with_ptr;
struct xenkbd_info *info; struct xenkbd_info *info;
struct input_dev *kbd, *ptr, *mtouch; struct input_dev *kbd, *ptr, *mtouch;
...@@ -211,93 +220,114 @@ static int xenkbd_probe(struct xenbus_device *dev, ...@@ -211,93 +220,114 @@ static int xenkbd_probe(struct xenbus_device *dev,
if (!info->page) if (!info->page)
goto error_nomem; goto error_nomem;
/* Set input abs params to match backend screen res */ /*
abs = xenbus_read_unsigned(dev->otherend, * The below are reverse logic, e.g. if the feature is set, then
XENKBD_FIELD_FEAT_ABS_POINTER, 0); * do not expose the corresponding virtual device.
ptr_size[KPARAM_X] = xenbus_read_unsigned(dev->otherend, */
XENKBD_FIELD_WIDTH, with_kbd = !xenbus_read_unsigned(dev->otherend,
ptr_size[KPARAM_X]); XENKBD_FIELD_FEAT_DSBL_KEYBRD, 0);
ptr_size[KPARAM_Y] = xenbus_read_unsigned(dev->otherend,
XENKBD_FIELD_HEIGHT, with_ptr = !xenbus_read_unsigned(dev->otherend,
ptr_size[KPARAM_Y]); XENKBD_FIELD_FEAT_DSBL_POINTER, 0);
if (abs) {
ret = xenbus_write(XBT_NIL, dev->nodename,
XENKBD_FIELD_REQ_ABS_POINTER, "1");
if (ret) {
pr_warn("xenkbd: can't request abs-pointer\n");
abs = 0;
}
}
touch = xenbus_read_unsigned(dev->otherend, /* Direct logic: if set, then create multi-touch device. */
XENKBD_FIELD_FEAT_MTOUCH, 0); with_mtouch = xenbus_read_unsigned(dev->otherend,
if (touch) { XENKBD_FIELD_FEAT_MTOUCH, 0);
if (with_mtouch) {
ret = xenbus_write(XBT_NIL, dev->nodename, ret = xenbus_write(XBT_NIL, dev->nodename,
XENKBD_FIELD_REQ_MTOUCH, "1"); XENKBD_FIELD_REQ_MTOUCH, "1");
if (ret) { if (ret) {
pr_warn("xenkbd: can't request multi-touch"); pr_warn("xenkbd: can't request multi-touch");
touch = 0; with_mtouch = 0;
} }
} }
/* keyboard */ /* keyboard */
kbd = input_allocate_device(); if (with_kbd) {
if (!kbd) kbd = input_allocate_device();
goto error_nomem; if (!kbd)
kbd->name = "Xen Virtual Keyboard"; goto error_nomem;
kbd->phys = info->phys; kbd->name = "Xen Virtual Keyboard";
kbd->id.bustype = BUS_PCI; kbd->phys = info->phys;
kbd->id.vendor = 0x5853; kbd->id.bustype = BUS_PCI;
kbd->id.product = 0xffff; kbd->id.vendor = 0x5853;
kbd->id.product = 0xffff;
__set_bit(EV_KEY, kbd->evbit);
for (i = KEY_ESC; i < KEY_UNKNOWN; i++) __set_bit(EV_KEY, kbd->evbit);
__set_bit(i, kbd->keybit); for (i = KEY_ESC; i < KEY_UNKNOWN; i++)
for (i = KEY_OK; i < KEY_MAX; i++) __set_bit(i, kbd->keybit);
__set_bit(i, kbd->keybit); for (i = KEY_OK; i < KEY_MAX; i++)
__set_bit(i, kbd->keybit);
ret = input_register_device(kbd);
if (ret) { ret = input_register_device(kbd);
input_free_device(kbd); if (ret) {
xenbus_dev_fatal(dev, ret, "input_register_device(kbd)"); input_free_device(kbd);
goto error; xenbus_dev_fatal(dev, ret,
"input_register_device(kbd)");
goto error;
}
info->kbd = kbd;
} }
info->kbd = kbd;
/* pointing device */ /* pointing device */
ptr = input_allocate_device(); if (with_ptr) {
if (!ptr) unsigned int abs;
goto error_nomem;
ptr->name = "Xen Virtual Pointer"; /* Set input abs params to match backend screen res */
ptr->phys = info->phys; abs = xenbus_read_unsigned(dev->otherend,
ptr->id.bustype = BUS_PCI; XENKBD_FIELD_FEAT_ABS_POINTER, 0);
ptr->id.vendor = 0x5853; ptr_size[KPARAM_X] = xenbus_read_unsigned(dev->otherend,
ptr->id.product = 0xfffe; XENKBD_FIELD_WIDTH,
ptr_size[KPARAM_X]);
if (abs) { ptr_size[KPARAM_Y] = xenbus_read_unsigned(dev->otherend,
__set_bit(EV_ABS, ptr->evbit); XENKBD_FIELD_HEIGHT,
input_set_abs_params(ptr, ABS_X, 0, ptr_size[KPARAM_X], 0, 0); ptr_size[KPARAM_Y]);
input_set_abs_params(ptr, ABS_Y, 0, ptr_size[KPARAM_Y], 0, 0); if (abs) {
} else { ret = xenbus_write(XBT_NIL, dev->nodename,
input_set_capability(ptr, EV_REL, REL_X); XENKBD_FIELD_REQ_ABS_POINTER, "1");
input_set_capability(ptr, EV_REL, REL_Y); if (ret) {
} pr_warn("xenkbd: can't request abs-pointer\n");
input_set_capability(ptr, EV_REL, REL_WHEEL); abs = 0;
}
}
__set_bit(EV_KEY, ptr->evbit); ptr = input_allocate_device();
for (i = BTN_LEFT; i <= BTN_TASK; i++) if (!ptr)
__set_bit(i, ptr->keybit); goto error_nomem;
ptr->name = "Xen Virtual Pointer";
ptr->phys = info->phys;
ptr->id.bustype = BUS_PCI;
ptr->id.vendor = 0x5853;
ptr->id.product = 0xfffe;
if (abs) {
__set_bit(EV_ABS, ptr->evbit);
input_set_abs_params(ptr, ABS_X, 0,
ptr_size[KPARAM_X], 0, 0);
input_set_abs_params(ptr, ABS_Y, 0,
ptr_size[KPARAM_Y], 0, 0);
} else {
input_set_capability(ptr, EV_REL, REL_X);
input_set_capability(ptr, EV_REL, REL_Y);
}
input_set_capability(ptr, EV_REL, REL_WHEEL);
ret = input_register_device(ptr); __set_bit(EV_KEY, ptr->evbit);
if (ret) { for (i = BTN_LEFT; i <= BTN_TASK; i++)
input_free_device(ptr); __set_bit(i, ptr->keybit);
xenbus_dev_fatal(dev, ret, "input_register_device(ptr)");
goto error; ret = input_register_device(ptr);
if (ret) {
input_free_device(ptr);
xenbus_dev_fatal(dev, ret,
"input_register_device(ptr)");
goto error;
}
info->ptr = ptr;
} }
info->ptr = ptr;
/* multi-touch device */ /* multi-touch device */
if (touch) { if (with_mtouch) {
int num_cont, width, height; int num_cont, width, height;
mtouch = input_allocate_device(); mtouch = input_allocate_device();
...@@ -346,6 +376,11 @@ static int xenkbd_probe(struct xenbus_device *dev, ...@@ -346,6 +376,11 @@ static int xenkbd_probe(struct xenbus_device *dev,
info->mtouch = mtouch; info->mtouch = mtouch;
} }
if (!(with_kbd || with_ptr || with_mtouch)) {
ret = -ENXIO;
goto error;
}
ret = xenkbd_connect_backend(dev, info); ret = xenkbd_connect_backend(dev, info);
if (ret < 0) if (ret < 0)
goto error; goto error;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment