Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp1666973ybn; Wed, 2 Oct 2019 21:12:11 -0700 (PDT) X-Google-Smtp-Source: APXvYqzJz7XHH2tFpIA5fKdDLfdILZnRmrPKcm2EVGFinx0ylg/6SRKDkauls94EbH5eD4KPECo9 X-Received: by 2002:a50:c3c7:: with SMTP id i7mr7473971edf.138.1570075930910; Wed, 02 Oct 2019 21:12:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570075930; cv=none; d=google.com; s=arc-20160816; b=OIm93SXqgERnj/0STSzEu5KL5+Wl+Fv81qVCrpc7mbbKVcFaK0V6pMGog4gsQ+xPpy nb6vO5fYKxom6OpHha7/uF4kZi0Ypi82mlYr4tIgnwURZnB1rmIrPoCGCzIksoHow7Bc 1jFj2coHNhGNA05jam2n84S/4LGYzSAHanWIPcshwikdp3MnYWuqR8xzvISaEXQW5xu6 5VNN2UmdtHdg1XUlcoHvkD/K0V1s7UfLcSGwJfTjvYwWa/P19pX7jbl/r2/UiIYQ6FLu Q+Pv7CL5E5Y4CIX+PaI7/2w9wz37V+huQhudPVQDzf+eiJqclQOeRuwcKOtXJEcUhJ3j nfOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=lIn7NiyI8xbDV3NNqnM2aeG/Q5yob7NbX8qZedDLm0E=; b=X0hFFa73k0vRmKydR68yv6tggRqs9H/SNzFms78cihWY9U0y/tbTyUOdvKHU2keY+x IhDzUJ1mCbKqEM0aMSQ4EyI8bC0dTkTbdkf+A8joZ8wrOQ+ohcggJ/FAJa0LubnBwyfZ 85uUADBV0Cs+0oybQ7AW9et8PQ37NgHfBZ4ttCzbY8iJkdUek4ncg60ot68L9Dvnm5EF 7z2QUIgFVpnoUV38B3BZvNAej+0HEEZPbpEnc25vGe3XjghYFPiFpz/V/gEJZkLA7Ly/ AgadJd6abkI3gTKzrWyNvp+nHX+82Co2JhFyfu3Y7e3+DJRX12ImWHF1SgI+GhW3aNsg kBTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=XdrIQOHl; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p14si799049eda.411.2019.10.02.21.11.46; Wed, 02 Oct 2019 21:12:10 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=XdrIQOHl; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728443AbfJCDSR (ORCPT + 99 others); Wed, 2 Oct 2019 23:18:17 -0400 Received: from mail-pl1-f193.google.com ([209.85.214.193]:43547 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727488AbfJCDSR (ORCPT ); Wed, 2 Oct 2019 23:18:17 -0400 Received: by mail-pl1-f193.google.com with SMTP id f21so786229plj.10 for ; Wed, 02 Oct 2019 20:18:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=lIn7NiyI8xbDV3NNqnM2aeG/Q5yob7NbX8qZedDLm0E=; b=XdrIQOHl/QihUD3r9eNtQ8O2AIEJVaCkgqPrzZBvB6kw6kg5m93pzaOTwB3y21PhCu 07ik2VCJsMIqMlu9UP1U4GI9Dv0XNNvlXTgUpuvmgtEDWsaNSQue/KZRQNw3mMEtJfZf XyUhF1P9sWVFcmRIjvLzlltVji+oVK/DhJImg= 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:mime-version:content-transfer-encoding; bh=lIn7NiyI8xbDV3NNqnM2aeG/Q5yob7NbX8qZedDLm0E=; b=QKKKtlVeFilR6QYcNZHp9zhFfKX5AKIC3ySldiHy+iN/Nw2rNnfj9CdIJtohSCmCn5 RgXOWoWRx6ANw5cjqo48THYou1/tDlSGXo2LmYEvZP8T3TKgYYPvSqosJzRkv6jMaiyS 2g5aC0dzIff3+Ruze6seHtpKd7uyrmsOayfulqDsYVesAGedoquhNY3jhXdCjlBJUFYq CshUUqH6ZPzqJT+143qU5B2Lh87hW6lvO15xMX7OU7t4K7BsoOAIgnNyZlUr6+eCszNq yxCKf8y1dAbUJI9+sybdVlGe4m7Up0YBSmceRZs3+6b1P++yUvq1oygM4BMQVqDmop1s deYw== X-Gm-Message-State: APjAAAWE9wAfyL1bMPfoDMcjYn985vIOZhlCCmqF/8a8Fy1gm0QvqiHb dZu2pkYKHRdRtIuo9iwuscdt4w== X-Received: by 2002:a17:902:7895:: with SMTP id q21mr7094740pll.94.1570072696247; Wed, 02 Oct 2019 20:18:16 -0700 (PDT) Received: from drinkcat2.tpe.corp.google.com ([2401:fa00:1:b:d8b7:33af:adcb:b648]) by smtp.gmail.com with ESMTPSA id z12sm880999pfj.41.2019.10.02.20.18.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Oct 2019 20:18:15 -0700 (PDT) From: Nicolas Boichat To: Jiri Kosina Cc: Benjamin Tissoires , linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, dtor@chromium.org, ikjn@chromium.org Subject: [PATCH 2/2] HID: google: Detect base folded usage instead of hard-coding whiskers Date: Thu, 3 Oct 2019 11:18:00 +0800 Message-Id: <20191003031800.120237-2-drinkcat@chromium.org> X-Mailer: git-send-email 2.23.0.581.g78d2f28ef7-goog In-Reply-To: <20191003031800.120237-1-drinkcat@chromium.org> References: <20191003031800.120237-1-drinkcat@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Some other hammer-like device will emit a similar code, let's look for the folded event in HID usage table, instead of hard-coding whiskers in many places. Signed-off-by: Nicolas Boichat --- drivers/hid/hid-google-hammer.c | 53 ++++++++++++++++----------------- 1 file changed, 25 insertions(+), 28 deletions(-) diff --git a/drivers/hid/hid-google-hammer.c b/drivers/hid/hid-google-hammer.c index a52535ebc6fe92c..2aa4ed157aec875 100644 --- a/drivers/hid/hid-google-hammer.c +++ b/drivers/hid/hid-google-hammer.c @@ -370,7 +370,7 @@ static void hammer_unregister_leds(struct hid_device *hdev) #define HID_UP_GOOGLEVENDOR 0xffd10000 #define HID_VD_KBD_FOLDED 0x00000019 -#define WHISKERS_KBD_FOLDED (HID_UP_GOOGLEVENDOR | HID_VD_KBD_FOLDED) +#define HID_USAGE_KBD_FOLDED (HID_UP_GOOGLEVENDOR | HID_VD_KBD_FOLDED) /* HID usage for keyboard backlight (Alphanumeric display brightness) */ #define HID_AD_BRIGHTNESS 0x00140046 @@ -380,8 +380,7 @@ static int hammer_input_mapping(struct hid_device *hdev, struct hid_input *hi, struct hid_usage *usage, unsigned long **bit, int *max) { - if (hdev->product == USB_DEVICE_ID_GOOGLE_WHISKERS && - usage->hid == WHISKERS_KBD_FOLDED) { + if (usage->hid == HID_USAGE_KBD_FOLDED) { /* * We do not want to have this usage mapped as it will get * mixed in with "base attached" signal and delivered over @@ -398,8 +397,7 @@ static int hammer_event(struct hid_device *hid, struct hid_field *field, { unsigned long flags; - if (hid->product == USB_DEVICE_ID_GOOGLE_WHISKERS && - usage->hid == WHISKERS_KBD_FOLDED) { + if (usage->hid == HID_USAGE_KBD_FOLDED) { spin_lock_irqsave(&cbas_ec_lock, flags); /* @@ -424,33 +422,22 @@ static int hammer_event(struct hid_device *hid, struct hid_field *field, return 0; } -static bool hammer_is_keyboard_interface(struct hid_device *hdev) +static bool hammer_has_usage(struct hid_device *hdev, unsigned int report_type, + unsigned application, unsigned usage) { - struct hid_report_enum *re = &hdev->report_enum[HID_INPUT_REPORT]; - struct hid_report *report; - - list_for_each_entry(report, &re->report_list, list) - if (report->application == HID_GD_KEYBOARD) - return true; - - return false; -} - -static bool hammer_has_backlight_control(struct hid_device *hdev) -{ - struct hid_report_enum *re = &hdev->report_enum[HID_OUTPUT_REPORT]; + struct hid_report_enum *re = &hdev->report_enum[report_type]; struct hid_report *report; int i, j; list_for_each_entry(report, &re->report_list, list) { - if (report->application != HID_GD_KEYBOARD) + if (report->application != application) continue; for (i = 0; i < report->maxfield; i++) { struct hid_field *field = report->field[i]; for (j = 0; j < field->maxusage; j++) - if (field->usage[j].hid == HID_AD_BRIGHTNESS) + if (field->usage[j].hid == usage) return true; } } @@ -458,6 +445,18 @@ static bool hammer_has_backlight_control(struct hid_device *hdev) return false; } +static bool hammer_has_folded_event(struct hid_device *hdev) +{ + return hammer_has_usage(hdev, HID_INPUT_REPORT, + HID_GD_KEYBOARD, HID_USAGE_KBD_FOLDED); +} + +static bool hammer_has_backlight_control(struct hid_device *hdev) +{ + return hammer_has_usage(hdev, HID_OUTPUT_REPORT, + HID_GD_KEYBOARD, HID_AD_BRIGHTNESS); +} + static int hammer_probe(struct hid_device *hdev, const struct hid_device_id *id) { @@ -473,12 +472,11 @@ static int hammer_probe(struct hid_device *hdev, /* * We always want to poll for, and handle tablet mode events from - * Whiskers, even when nobody has opened the input device. This also - * prevents the hid core from dropping early tablet mode events from - * the device. + * devices that have folded usage, even when nobody has opened the input + * device. This also prevents the hid core from dropping early tablet + * mode events from the device. */ - if (hdev->product == USB_DEVICE_ID_GOOGLE_WHISKERS && - hammer_is_keyboard_interface(hdev)) { + if (hammer_has_folded_event(hdev)) { hdev->quirks |= HID_QUIRK_ALWAYS_POLL; error = hid_hw_open(hdev); if (error) @@ -500,8 +498,7 @@ static void hammer_remove(struct hid_device *hdev) { unsigned long flags; - if (hdev->product == USB_DEVICE_ID_GOOGLE_WHISKERS && - hammer_is_keyboard_interface(hdev)) { + if (hammer_has_folded_event(hdev)) { hid_hw_close(hdev); /* -- 2.23.0.444.g18eeb5a265-goog