From patchwork Wed Jul 11 10:38:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 10519295 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 0151E600CA for ; Wed, 11 Jul 2018 10:38:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D005628C68 for ; Wed, 11 Jul 2018 10:38:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C499428C79; Wed, 11 Jul 2018 10:38:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5E8D028D3B for ; Wed, 11 Jul 2018 10:38:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732361AbeGKKm3 (ORCPT ); Wed, 11 Jul 2018 06:42:29 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:33832 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726730AbeGKKm2 (ORCPT ); Wed, 11 Jul 2018 06:42:28 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 736B772621; Wed, 11 Jul 2018 10:38:47 +0000 (UTC) Received: from shalem.localdomain.com (ovpn-117-225.ams2.redhat.com [10.36.117.225]) by smtp.corp.redhat.com (Postfix) with ESMTP id 98F4B2026D6B; Wed, 11 Jul 2018 10:38:46 +0000 (UTC) From: Hans de Goede To: Jiri Kosina , Benjamin Tissoires Cc: Hans de Goede , Alexandrov Stanislav , linux-input@vger.kernel.org Subject: [PATCH v3 6/9] HID: elan: Query resolution from the touchpad Date: Wed, 11 Jul 2018 12:38:34 +0200 Message-Id: <20180711103837.5794-7-hdegoede@redhat.com> In-Reply-To: <20180711103837.5794-1-hdegoede@redhat.com> References: <20180711103837.5794-1-hdegoede@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Wed, 11 Jul 2018 10:38:47 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Wed, 11 Jul 2018 10:38:47 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'hdegoede@redhat.com' RCPT:'' Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Query the resolution from the touchpad and report it to userspace Signed-off-by: Hans de Goede --- Changes in v2: -Simplify elan_convert_res() and add a comment explaining what it does --- drivers/hid/hid-elan.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/drivers/hid/hid-elan.c b/drivers/hid/hid-elan.c index d696b57f1ccd..6969fb5344a5 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,15 @@ static int elan_get_device_param(struct hid_device *hdev, return 0; } +static unsigned int elan_convert_res(char val) +{ + /* + * (value from firmware) * 10 + 790 = dpi + * dpi * 10 / 254 = dots/mm + */ + return (val * 10 + 790) * 10 / 254; +} + static int elan_get_device_params(struct hid_device *hdev) { struct elan_drvdata *drvdata = hid_get_drvdata(hdev); @@ -119,6 +130,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 +184,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",