Skip to content

Commit

Permalink
Input: add input_copy_abs() function
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Hans de Goede <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Dmitry Torokhov <[email protected]>
  • Loading branch information
jwrdegoede authored and dtor committed Mar 1, 2022
1 parent 3f9ed5c commit cb66b9b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
36 changes: 36 additions & 0 deletions drivers/input/input.c
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,42 @@ void input_set_abs_params(struct input_dev *dev, unsigned int axis,
}
EXPORT_SYMBOL(input_set_abs_params);

/**
* input_copy_abs - Copy absinfo from one input_dev to another
* @dst: Destination input device to copy the abs settings to
* @dst_axis: ABS_* value selecting the destination axis
* @src: Source input device to copy the abs settings from
* @src_axis: ABS_* value selecting the source axis
*
* Set absinfo for the selected destination axis by copying it from
* the specified source input device's source axis.
* 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.
*/
void input_copy_abs(struct input_dev *dst, unsigned int dst_axis,
const struct input_dev *src, unsigned int src_axis)
{
/* src must have EV_ABS and src_axis set */
if (WARN_ON(!(test_bit(EV_ABS, src->evbit) &&
test_bit(src_axis, src->absbit))))
return;

/*
* input_alloc_absinfo() may have failed for the source. Our caller is
* expected to catch this when registering the input devices, which may
* happen after the input_copy_abs() call.
*/
if (!src->absinfo)
return;

input_set_capability(dst, EV_ABS, dst_axis);
if (!dst->absinfo)
return;

dst->absinfo[dst_axis] = src->absinfo[src_axis];
}
EXPORT_SYMBOL(input_copy_abs);

/**
* input_grab_device - grabs device for exclusive use
Expand Down
2 changes: 2 additions & 0 deletions include/linux/input.h
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,8 @@ static inline void input_set_events_per_packet(struct input_dev *dev, int n_even
void input_alloc_absinfo(struct input_dev *dev);
void input_set_abs_params(struct input_dev *dev, unsigned int axis,
int min, int max, int fuzz, int flat);
void input_copy_abs(struct input_dev *dst, unsigned int dst_axis,
const struct input_dev *src, unsigned int src_axis);

#define INPUT_GENERATE_ABS_ACCESSORS(_suffix, _item) \
static inline int input_abs_get_##_suffix(struct input_dev *dev, \
Expand Down

0 comments on commit cb66b9b

Please sign in to comment.