diff mbox

[resend,6/8] HID: elan: Query resolution from the touchpad

Message ID 20180601130555.25625-7-hdegoede@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Hans de Goede June 1, 2018, 1:05 p.m. UTC
Query the resolution from the touchpad and report it to userspace

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 drivers/hid/hid-elan.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

Comments

Benjamin Tissoires July 2, 2018, 7 a.m. UTC | #1
Hi Hans,

On Fri, Jun 1, 2018 at 3:05 PM, Hans de Goede <hdegoede@redhat.com> wrote:
> Query the resolution from the touchpad and report it to userspace
>
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
> ---
>  drivers/hid/hid-elan.c | 26 ++++++++++++++++++++++++++
>  1 file changed, 26 insertions(+)
>
> diff --git a/drivers/hid/hid-elan.c b/drivers/hid/hid-elan.c
> index d696b57f1ccd..4791c22a3d37 100644
> --- a/drivers/hid/hid-elan.c
> +++ b/drivers/hid/hid-elan.c
> @@ -43,6 +43,8 @@ struct elan_drvdata {
>         u8 mute_led_state;
>         u16 max_x;
>         u16 max_y;
> +       u16 res_x;
> +       u16 res_y;
>  };
>
>  static int is_not_elan_touchpad(struct hid_device *hdev)
> @@ -97,6 +99,20 @@ static int elan_get_device_param(struct hid_device *hdev,
>         return 0;
>  }
>
> +static unsigned int elan_convert_res(char val)
> +{
> +       int res;
> +
> +       if (val & 0x80) {
> +               val = ~val + 1;
> +               res = (790 - val * 10) * 10 / 254;
> +       } else {
> +               res = (val * 10 + 790) * 10 / 254;

Could you explain a little bit those computations?
I have a feeling there is a inch to/from mm involved, but better not
have random values inserted in the code.

Cheers,
Benjamin

> +       }
> +
> +       return res;
> +}
> +
>  static int elan_get_device_params(struct hid_device *hdev)
>  {
>         struct elan_drvdata *drvdata = hid_get_drvdata(hdev);
> @@ -119,6 +135,13 @@ static int elan_get_device_params(struct hid_device *hdev)
>
>         drvdata->max_y = (dmabuf[4] << 8) | dmabuf[3];
>
> +       ret = elan_get_device_param(hdev, dmabuf, ELAN_PARAM_RES);
> +       if (ret)
> +               goto err;
> +
> +       drvdata->res_x = elan_convert_res(dmabuf[3]);
> +       drvdata->res_y = elan_convert_res(dmabuf[4]);
> +
>  err:
>         kfree(dmabuf);
>         return ret;
> @@ -166,6 +189,9 @@ static int elan_input_configured(struct hid_device *hdev, struct hid_input *hi)
>                 return ret;
>         }
>
> +       input_abs_set_res(input, ABS_X, drvdata->res_x);
> +       input_abs_set_res(input, ABS_Y, drvdata->res_y);
> +
>         ret = input_register_device(input);
>         if (ret) {
>                 hid_err(hdev, "Failed to register elan input device: %d\n",
> --
> 2.17.0
>
--
To unsubscribe from this list: send the line "unsubscribe linux-input" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/hid/hid-elan.c b/drivers/hid/hid-elan.c
index d696b57f1ccd..4791c22a3d37 100644
--- a/drivers/hid/hid-elan.c
+++ b/drivers/hid/hid-elan.c
@@ -43,6 +43,8 @@  struct elan_drvdata {
 	u8 mute_led_state;
 	u16 max_x;
 	u16 max_y;
+	u16 res_x;
+	u16 res_y;
 };
 
 static int is_not_elan_touchpad(struct hid_device *hdev)
@@ -97,6 +99,20 @@  static int elan_get_device_param(struct hid_device *hdev,
 	return 0;
 }
 
+static unsigned int elan_convert_res(char val)
+{
+	int res;
+
+	if (val & 0x80) {
+		val = ~val + 1;
+		res = (790 - val * 10) * 10 / 254;
+	} else {
+		res = (val * 10 + 790) * 10 / 254;
+	}
+
+	return res;
+}
+
 static int elan_get_device_params(struct hid_device *hdev)
 {
 	struct elan_drvdata *drvdata = hid_get_drvdata(hdev);
@@ -119,6 +135,13 @@  static int elan_get_device_params(struct hid_device *hdev)
 
 	drvdata->max_y = (dmabuf[4] << 8) | dmabuf[3];
 
+	ret = elan_get_device_param(hdev, dmabuf, ELAN_PARAM_RES);
+	if (ret)
+		goto err;
+
+	drvdata->res_x = elan_convert_res(dmabuf[3]);
+	drvdata->res_y = elan_convert_res(dmabuf[4]);
+
 err:
 	kfree(dmabuf);
 	return ret;
@@ -166,6 +189,9 @@  static int elan_input_configured(struct hid_device *hdev, struct hid_input *hi)
 		return ret;
 	}
 
+	input_abs_set_res(input, ABS_X, drvdata->res_x);
+	input_abs_set_res(input, ABS_Y, drvdata->res_y);
+
 	ret = input_register_device(input);
 	if (ret) {
 		hid_err(hdev, "Failed to register elan input device: %d\n",