diff mbox series

[1/5] Input: Add input_copy_abs() function

Message ID 20211212124242.81019-2-hdegoede@redhat.com (mailing list archive)
State New, archived
Headers show
Series Input: goodix - Various fixes and improvements | expand

Commit Message

Hans de Goede Dec. 12, 2021, 12:42 p.m. UTC
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>
---
 drivers/input/input.c | 34 ++++++++++++++++++++++++++++++++++
 include/linux/input.h |  2 ++
 2 files changed, 36 insertions(+)

Comments

Dmitry Torokhov Dec. 13, 2021, 4:58 a.m. UTC | #1
Hi Hans,

On Sun, Dec 12, 2021 at 01:42:38PM +0100, Hans de Goede wrote:
> 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>
> ---
>  drivers/input/input.c | 34 ++++++++++++++++++++++++++++++++++
>  include/linux/input.h |  2 ++
>  2 files changed, 36 insertions(+)
> 
> diff --git a/drivers/input/input.c b/drivers/input/input.c
> index ccaeb2426385..60f3eb38906f 100644
> --- a/drivers/input/input.c
> +++ b/drivers/input/input.c
> @@ -526,6 +526,40 @@ 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)
> +{
> +	/*
> +	 * 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;

I'd probably check if source device actually declared EV_ABS/src_axis
and yelled loudly (WARN?) in such case.

> +
> +	input_alloc_absinfo(dst);
> +	if (!dst->absinfo)
> +		return;
> +
> +	dst->absinfo[dst_axis] = src->absinfo[src_axis];
> +
> +	__set_bit(EV_ABS, dst->evbit);
> +	__set_bit(dst_axis, dst->absbit);

input_set_capability() ?

> +}
> +EXPORT_SYMBOL(input_copy_abs);

Thanks.
Hans de Goede Jan. 31, 2022, 1:21 p.m. UTC | #2
Hi Dmitry,

Thank you for your review of this patch series; and sorry for
being so slow in getting back to you on this.

On 12/13/21 05:58, Dmitry Torokhov wrote:
> Hi Hans,
> 
> On Sun, Dec 12, 2021 at 01:42:38PM +0100, Hans de Goede wrote:
>> 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>
>> ---
>>  drivers/input/input.c | 34 ++++++++++++++++++++++++++++++++++
>>  include/linux/input.h |  2 ++
>>  2 files changed, 36 insertions(+)
>>
>> diff --git a/drivers/input/input.c b/drivers/input/input.c
>> index ccaeb2426385..60f3eb38906f 100644
>> --- a/drivers/input/input.c
>> +++ b/drivers/input/input.c
>> @@ -526,6 +526,40 @@ 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)
>> +{
>> +	/*
>> +	 * 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;
> 
> I'd probably check if source device actually declared EV_ABS/src_axis
> and yelled loudly (WARN?) in such case.

Ack, I will add this for v2.

> 
>> +
>> +	input_alloc_absinfo(dst);
>> +	if (!dst->absinfo)
>> +		return;
>> +
>> +	dst->absinfo[dst_axis] = src->absinfo[src_axis];
>> +
>> +	__set_bit(EV_ABS, dst->evbit);
>> +	__set_bit(dst_axis, dst->absbit);
> 
> input_set_capability() ?

Ack.

Regards,

Hans



> 
>> +}
>> +EXPORT_SYMBOL(input_copy_abs);
> 
> Thanks.
>
diff mbox series

Patch

diff --git a/drivers/input/input.c b/drivers/input/input.c
index ccaeb2426385..60f3eb38906f 100644
--- a/drivers/input/input.c
+++ b/drivers/input/input.c
@@ -526,6 +526,40 @@  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)
+{
+	/*
+	 * 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_alloc_absinfo(dst);
+	if (!dst->absinfo)
+		return;
+
+	dst->absinfo[dst_axis] = src->absinfo[src_axis];
+
+	__set_bit(EV_ABS, dst->evbit);
+	__set_bit(dst_axis, dst->absbit);
+}
+EXPORT_SYMBOL(input_copy_abs);
 
 /**
  * input_grab_device - grabs device for exclusive use
diff --git a/include/linux/input.h b/include/linux/input.h
index 0354b298d874..49790c1bd2c4 100644
--- a/include/linux/input.h
+++ b/include/linux/input.h
@@ -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,	\