From patchwork Mon Jun 25 20:24:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gerecke, Jason" X-Patchwork-Id: 10487241 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 1F7F7603B5 for ; Mon, 25 Jun 2018 20:24:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 067A62869F for ; Mon, 25 Jun 2018 20:24:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EC7B8286A4; Mon, 25 Jun 2018 20:24:55 +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.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID 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 59F792869F for ; Mon, 25 Jun 2018 20:24:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755674AbeFYUYy (ORCPT ); Mon, 25 Jun 2018 16:24:54 -0400 Received: from mail-pf0-f195.google.com ([209.85.192.195]:35748 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755668AbeFYUYx (ORCPT ); Mon, 25 Jun 2018 16:24:53 -0400 Received: by mail-pf0-f195.google.com with SMTP id c22-v6so6974185pfi.2 for ; Mon, 25 Jun 2018 13:24:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=5OB8IZOLA7eOPzVD9PIyg6xV9Sdp833L4I8SwpbIwYk=; b=AqRfkhVZTWUEgAa8SJ75v991596grY3PuXiTHh8/er9sWTxyPt18t9dvWWckBCPk61 /Q8VT1g/sdFPfvYCCtVOui9PwcaKhWimSilz8z5/kbzScvp/TV//KRQRUa+MYOP61y32 1gLHe63x/ErEJMH4tNiweSX07YpaUf5abBGURKOOWKHhhoDEh8xMefQ2iQ4BlqhATSZu FVKxEAZDCkmK0gLWV+OF6mgR0XnW0V4QmKYlcMSzRat2dztYqlqUb9FNNPIbIbBl0W/3 U1t949Np342dbrEZOyroDp8jsYTHS/glh/ZQg2rRlTnCBljv9yK0eB7Li+1SdK7Koe4r rSqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=5OB8IZOLA7eOPzVD9PIyg6xV9Sdp833L4I8SwpbIwYk=; b=LPK92slIN8S/iKwxcpgpAGWlYX74D+ngJsisZmjVNzt7teTpNElW/f5DoJ7qtBD/wa VXL/MKMfkijaaSlo2qJnNiZGoR1ItuW5tEaDP81ZaKE3zcn7VvEA2T7dKsRJBdd0s8Db xeyail8RuhFiz2xo4QifLWRu7y3tFOGQ9+SrXucc/zXqkGLMpv4P4L+ISTqfbfeH2jsA /Zz4DlLH0t3JVVWBWVTPEyN9dvIervgv03K93J0j1thjyHRxNLWW/fHNW85+OFm938/w TwteU1Z0rQlvGqaBdcxvjOyAjEG9mEMK32hsBxZ8iqlVSqZ/K/FPWzjWDA55sayPQx4i /nhQ== X-Gm-Message-State: APt69E2tq672rME2IygiGpkTvPIDn7TuUbVSIbGgM3Mf53nKn+9FIfxL 53VK0lYDG6UZA1fO2G32jEDzGTyR X-Google-Smtp-Source: ADUXVKKsOXiz83cCPyj4nwX/c9C1HmHMxbRfj1d7lSY5bywGDvX4YK5DIj1hDFRSX93d8250Y6D6dg== X-Received: by 2002:a65:5bce:: with SMTP id o14-v6mr11905868pgr.449.1529958292617; Mon, 25 Jun 2018 13:24:52 -0700 (PDT) Received: from wacom-arch2.corp.onewacom.com ([50.225.60.4]) by smtp.gmail.com with ESMTPSA id z26-v6sm31865677pfd.60.2018.06.25.13.24.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 25 Jun 2018 13:24:51 -0700 (PDT) From: Jason Gerecke To: linux-input@vger.kernel.org, Jiri Kosina Cc: Benjamin Tissoires , Ping Cheng , Aaron Skomra , Jason Gerecke , Jason Gerecke Subject: [PATCH 2/3] HID: wacom: Move handling of HID quirks into a dedicated function Date: Mon, 25 Jun 2018 13:24:35 -0700 Message-Id: <20180625202436.25114-2-killertofu@gmail.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180625202436.25114-1-killertofu@gmail.com> References: <20180625202436.25114-1-killertofu@gmail.com> 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 We want to keep device-specific quirks as contained as possible so that the the code remains maintainable. Our 'wacom_setup_device_quirks' function is the usual place for this, but some quirks need to be applied to the HID descriptor as it is parsed. This commit introduces a new function which is called for each usage so that any HID-specific quirks can be applied. The function now houses quirks that were being done in 'wacom_feature_mapping' and 'wacom_usage_mapping'. Signed-off-by: Jason Gerecke --- drivers/hid/wacom_sys.c | 92 ++++++++++++++++++++++++----------------- 1 file changed, 54 insertions(+), 38 deletions(-) diff --git a/drivers/hid/wacom_sys.c b/drivers/hid/wacom_sys.c index fd40037c2bcc..463eaf5f1290 100644 --- a/drivers/hid/wacom_sys.c +++ b/drivers/hid/wacom_sys.c @@ -210,6 +210,57 @@ static int wacom_calc_hid_res(int logical_extents, int physical_extents, return hidinput_calc_abs_res(&field, ABS_X); } +static void wacom_hid_usage_quirk(struct hid_device *hdev, + struct hid_field *field, struct hid_usage *usage) +{ + struct wacom *wacom = hid_get_drvdata(hdev); + struct wacom_features *features = &wacom->wacom_wac.features; + unsigned int equivalent_usage = wacom_equivalent_usage(usage->hid); + + /* + * The Dell Canvas 27 needs to be switched to its vendor-defined + * report to provide the best resolution. + */ + if (hdev->vendor == USB_VENDOR_ID_WACOM && + hdev->product == 0x4200 && + field->application == HID_UP_MSVENDOR) { + wacom->wacom_wac.mode_report = field->report->id; + wacom->wacom_wac.mode_value = 2; + } + + /* + * ISDv4 devices which predate HID's adoption of the + * HID_DG_BARELSWITCH2 usage use 0x000D0000 in its + * position instead. We can accurately detect if a + * usage with that value should be HID_DG_BARRELSWITCH2 + * based on the surrounding usages, which have remained + * constant across generations. + */ + if (features->type == HID_GENERIC && + usage->hid == 0x000D0000 && + field->application == HID_DG_PEN && + field->physical == HID_DG_STYLUS) { + int i = usage->usage_index; + + if (i-4 >= 0 && i+1 < field->maxusage && + field->usage[i-4].hid == HID_DG_TIPSWITCH && + field->usage[i-3].hid == HID_DG_BARRELSWITCH && + field->usage[i-2].hid == HID_DG_ERASER && + field->usage[i-1].hid == HID_DG_INVERT && + field->usage[i+1].hid == HID_DG_INRANGE) { + usage->hid = HID_DG_BARRELSWITCH2; + } + } + + /* 2nd-generation Intuos Pro Large has incorrect Y maximum */ + if (hdev->vendor == USB_VENDOR_ID_WACOM && + hdev->product == 0x0358 && + WACOM_PEN_FIELD(field) && + equivalent_usage == HID_GD_Y) { + field->logical_maximum = 43200; + } +} + static void wacom_feature_mapping(struct hid_device *hdev, struct hid_field *field, struct hid_usage *usage) { @@ -221,6 +272,8 @@ static void wacom_feature_mapping(struct hid_device *hdev, int ret; u32 n; + wacom_hid_usage_quirk(hdev, field, usage); + switch (equivalent_usage) { case HID_DG_CONTACTMAX: /* leave touch_max as is if predefined */ @@ -300,13 +353,6 @@ static void wacom_feature_mapping(struct hid_device *hdev, kfree(data); break; } - - if (hdev->vendor == USB_VENDOR_ID_WACOM && - hdev->product == 0x4200 /* Dell Canvas 27 */ && - field->application == HID_UP_MSVENDOR) { - wacom->wacom_wac.mode_report = field->report->id; - wacom->wacom_wac.mode_value = 2; - } } /* @@ -361,37 +407,7 @@ static void wacom_usage_mapping(struct hid_device *hdev, else return; - /* - * ISDv4 devices which predate HID's adoption of the - * HID_DG_BARELSWITCH2 usage use 0x000D0000 in its - * position instead. We can accurately detect if a - * usage with that value should be HID_DG_BARRELSWITCH2 - * based on the surrounding usages, which have remained - * constant across generations. - */ - if (features->type == HID_GENERIC && - usage->hid == 0x000D0000 && - field->application == HID_DG_PEN && - field->physical == HID_DG_STYLUS) { - int i = usage->usage_index; - - if (i-4 >= 0 && i+1 < field->maxusage && - field->usage[i-4].hid == HID_DG_TIPSWITCH && - field->usage[i-3].hid == HID_DG_BARRELSWITCH && - field->usage[i-2].hid == HID_DG_ERASER && - field->usage[i-1].hid == HID_DG_INVERT && - field->usage[i+1].hid == HID_DG_INRANGE) { - usage->hid = HID_DG_BARRELSWITCH2; - } - } - - /* 2nd-generation Intuos Pro Large has incorrect Y maximum */ - if (hdev->vendor == USB_VENDOR_ID_WACOM && - hdev->product == 0x0358 && - WACOM_PEN_FIELD(field) && - wacom_equivalent_usage(usage->hid) == HID_GD_Y) { - field->logical_maximum = 43200; - } + wacom_hid_usage_quirk(hdev, field, usage); switch (usage->hid) { case HID_GD_X: