Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Input: add input_copy_abs() function

Add a new helper function to copy absinfo from one input_dev to
another input_dev.

This is useful to e.g. setup a pen/stylus input-device for combined
touchscreen/pen hardware where the pen uses the same coordinates as
the touchscreen.

Suggested-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Link: https://lore.kernel.org/r/20220131143539.109142-2-hdegoede@redhat.com
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

authored by

Hans de Goede and committed by
Dmitry Torokhov
cb66b9ba 3f9ed5c2

+38
+36
drivers/input/input.c
··· 526 526 } 527 527 EXPORT_SYMBOL(input_set_abs_params); 528 528 529 + /** 530 + * input_copy_abs - Copy absinfo from one input_dev to another 531 + * @dst: Destination input device to copy the abs settings to 532 + * @dst_axis: ABS_* value selecting the destination axis 533 + * @src: Source input device to copy the abs settings from 534 + * @src_axis: ABS_* value selecting the source axis 535 + * 536 + * Set absinfo for the selected destination axis by copying it from 537 + * the specified source input device's source axis. 538 + * This is useful to e.g. setup a pen/stylus input-device for combined 539 + * touchscreen/pen hardware where the pen uses the same coordinates as 540 + * the touchscreen. 541 + */ 542 + void input_copy_abs(struct input_dev *dst, unsigned int dst_axis, 543 + const struct input_dev *src, unsigned int src_axis) 544 + { 545 + /* src must have EV_ABS and src_axis set */ 546 + if (WARN_ON(!(test_bit(EV_ABS, src->evbit) && 547 + test_bit(src_axis, src->absbit)))) 548 + return; 549 + 550 + /* 551 + * input_alloc_absinfo() may have failed for the source. Our caller is 552 + * expected to catch this when registering the input devices, which may 553 + * happen after the input_copy_abs() call. 554 + */ 555 + if (!src->absinfo) 556 + return; 557 + 558 + input_set_capability(dst, EV_ABS, dst_axis); 559 + if (!dst->absinfo) 560 + return; 561 + 562 + dst->absinfo[dst_axis] = src->absinfo[src_axis]; 563 + } 564 + EXPORT_SYMBOL(input_copy_abs); 529 565 530 566 /** 531 567 * input_grab_device - grabs device for exclusive use
+2
include/linux/input.h
··· 475 475 void input_alloc_absinfo(struct input_dev *dev); 476 476 void input_set_abs_params(struct input_dev *dev, unsigned int axis, 477 477 int min, int max, int fuzz, int flat); 478 + void input_copy_abs(struct input_dev *dst, unsigned int dst_axis, 479 + const struct input_dev *src, unsigned int src_axis); 478 480 479 481 #define INPUT_GENERATE_ABS_ACCESSORS(_suffix, _item) \ 480 482 static inline int input_abs_get_##_suffix(struct input_dev *dev, \