Skip to content

Commit 85b7720

Browse files
committed
Input: introduce device properties
Today, userspace sets up an input device based on the data it emits. This is not always enough; a tablet and a touchscreen may emit exactly the same data, for instance, but the former should be set up with a pointer whereas the latter does not need to. Recently, a new type of touchpad has emerged where the buttons are under the pad, which changes logic without changing the emitted data. This patch introduces a new ioctl, EVIOCGPROP, which enables user access to a set of device properties useful during setup. The properties are given as a bitmap in the same fashion as the event types, and are also made available via sysfs, uevent and /proc/bus/input/devices. Acked-by: Ping Cheng <pingc@wacom.com> Acked-by: Chase Douglas <chase.douglas@canonical.com> Acked-by: Dmitry Torokhov <dtor@mail.ru> Signed-off-by: Henrik Rydberg <rydberg@euromail.se>
1 parent 4dd295a commit 85b7720

5 files changed

Lines changed: 44 additions & 0 deletions

File tree

‎drivers/input/evdev.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,10 @@ static long evdev_do_ioctl(struct file *file, unsigned int cmd,
677677
#define EVIOC_MASK_SIZE(nr) ((nr) & ~(_IOC_SIZEMASK << _IOC_SIZESHIFT))
678678
switch (EVIOC_MASK_SIZE(cmd)) {
679679

680+
case EVIOCGPROP(0):
681+
return bits_to_user(dev->propbit, INPUT_PROP_MAX,
682+
size, p, compat_mode);
683+
680684
case EVIOCGKEY(0):
681685
return bits_to_user(dev->key, KEY_MAX, size, p, compat_mode);
682686

‎drivers/input/input.c‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,6 +1095,8 @@ static int input_devices_seq_show(struct seq_file *seq, void *v)
10951095
seq_printf(seq, "%s ", handle->name);
10961096
seq_putc(seq, '\n');
10971097

1098+
input_seq_print_bitmap(seq, "PROP", dev->propbit, INPUT_PROP_MAX);
1099+
10981100
input_seq_print_bitmap(seq, "EV", dev->evbit, EV_MAX);
10991101
if (test_bit(EV_KEY, dev->evbit))
11001102
input_seq_print_bitmap(seq, "KEY", dev->keybit, KEY_MAX);
@@ -1318,11 +1320,26 @@ static ssize_t input_dev_show_modalias(struct device *dev,
13181320
}
13191321
static DEVICE_ATTR(modalias, S_IRUGO, input_dev_show_modalias, NULL);
13201322

1323+
static int input_print_bitmap(char *buf, int buf_size, unsigned long *bitmap,
1324+
int max, int add_cr);
1325+
1326+
static ssize_t input_dev_show_properties(struct device *dev,
1327+
struct device_attribute *attr,
1328+
char *buf)
1329+
{
1330+
struct input_dev *input_dev = to_input_dev(dev);
1331+
int len = input_print_bitmap(buf, PAGE_SIZE, input_dev->propbit,
1332+
INPUT_PROP_MAX, true);
1333+
return min_t(int, len, PAGE_SIZE);
1334+
}
1335+
static DEVICE_ATTR(properties, S_IRUGO, input_dev_show_properties, NULL);
1336+
13211337
static struct attribute *input_dev_attrs[] = {
13221338
&dev_attr_name.attr,
13231339
&dev_attr_phys.attr,
13241340
&dev_attr_uniq.attr,
13251341
&dev_attr_modalias.attr,
1342+
&dev_attr_properties.attr,
13261343
NULL
13271344
};
13281345

@@ -1522,6 +1539,8 @@ static int input_dev_uevent(struct device *device, struct kobj_uevent_env *env)
15221539
if (dev->uniq)
15231540
INPUT_ADD_HOTPLUG_VAR("UNIQ=\"%s\"", dev->uniq);
15241541

1542+
INPUT_ADD_HOTPLUG_BM_VAR("PROP=", dev->propbit, INPUT_PROP_MAX);
1543+
15251544
INPUT_ADD_HOTPLUG_BM_VAR("EV=", dev->evbit, EV_MAX);
15261545
if (test_bit(EV_KEY, dev->evbit))
15271546
INPUT_ADD_HOTPLUG_BM_VAR("KEY=", dev->keybit, KEY_MAX);

‎drivers/input/misc/uinput.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,10 @@ static long uinput_ioctl_handler(struct file *file, unsigned int cmd,
680680
retval = uinput_set_bit(arg, swbit, SW_MAX);
681681
break;
682682

683+
case UI_SET_PROPBIT:
684+
retval = uinput_set_bit(arg, propbit, INPUT_PROP_MAX);
685+
break;
686+
683687
case UI_SET_PHYS:
684688
if (udev->state == UIST_CREATED) {
685689
retval = -EINVAL;

‎include/linux/input.h‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ struct input_keymap_entry {
9191
#define EVIOCGNAME(len) _IOC(_IOC_READ, 'E', 0x06, len) /* get device name */
9292
#define EVIOCGPHYS(len) _IOC(_IOC_READ, 'E', 0x07, len) /* get physical location */
9393
#define EVIOCGUNIQ(len) _IOC(_IOC_READ, 'E', 0x08, len) /* get unique identifier */
94+
#define EVIOCGPROP(len) _IOC(_IOC_READ, 'E', 0x09, len) /* get device properties */
9495

9596
#define EVIOCGKEY(len) _IOC(_IOC_READ, 'E', 0x18, len) /* get global key state */
9697
#define EVIOCGLED(len) _IOC(_IOC_READ, 'E', 0x19, len) /* get all LEDs */
@@ -107,6 +108,18 @@ struct input_keymap_entry {
107108

108109
#define EVIOCGRAB _IOW('E', 0x90, int) /* Grab/Release device */
109110

111+
/*
112+
* Device properties and quirks
113+
*/
114+
115+
#define INPUT_PROP_POINTER 0x00 /* needs a pointer */
116+
#define INPUT_PROP_DIRECT 0x01 /* direct input devices */
117+
#define INPUT_PROP_BUTTONPAD 0x02 /* has button(s) under pad */
118+
#define INPUT_PROP_SEMI_MT 0x03 /* touch rectangle only */
119+
120+
#define INPUT_PROP_MAX 0x1f
121+
#define INPUT_PROP_CNT (INPUT_PROP_MAX + 1)
122+
110123
/*
111124
* Event types
112125
*/
@@ -1090,6 +1103,7 @@ struct ff_effect {
10901103
* @phys: physical path to the device in the system hierarchy
10911104
* @uniq: unique identification code for the device (if device has it)
10921105
* @id: id of the device (struct input_id)
1106+
* @propbit: bitmap of device properties and quirks
10931107
* @evbit: bitmap of types of events supported by the device (EV_KEY,
10941108
* EV_REL, etc.)
10951109
* @keybit: bitmap of keys/buttons this device has
@@ -1173,6 +1187,8 @@ struct input_dev {
11731187
const char *uniq;
11741188
struct input_id id;
11751189

1190+
unsigned long propbit[BITS_TO_LONGS(INPUT_PROP_CNT)];
1191+
11761192
unsigned long evbit[BITS_TO_LONGS(EV_CNT)];
11771193
unsigned long keybit[BITS_TO_LONGS(KEY_CNT)];
11781194
unsigned long relbit[BITS_TO_LONGS(REL_CNT)];

‎include/linux/uinput.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ struct uinput_ff_erase {
104104
#define UI_SET_FFBIT _IOW(UINPUT_IOCTL_BASE, 107, int)
105105
#define UI_SET_PHYS _IOW(UINPUT_IOCTL_BASE, 108, char*)
106106
#define UI_SET_SWBIT _IOW(UINPUT_IOCTL_BASE, 109, int)
107+
#define UI_SET_PROPBIT _IOW(UINPUT_IOCTL_BASE, 110, int)
107108

108109
#define UI_BEGIN_FF_UPLOAD _IOWR(UINPUT_IOCTL_BASE, 200, struct uinput_ff_upload)
109110
#define UI_END_FF_UPLOAD _IOW(UINPUT_IOCTL_BASE, 201, struct uinput_ff_upload)

0 commit comments

Comments
 (0)