From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-20.4 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 55185C2D0A3 for ; Thu, 29 Oct 2020 19:47:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E7388207EA for ; Thu, 29 Oct 2020 19:47:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="mRBiru9b" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726209AbgJ2Trg (ORCPT ); Thu, 29 Oct 2020 15:47:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58616 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725857AbgJ2Trg (ORCPT ); Thu, 29 Oct 2020 15:47:36 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 15A59C0613CF for ; Thu, 29 Oct 2020 12:47:36 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id h64so3848882ybc.1 for ; Thu, 29 Oct 2020 12:47:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:message-id:mime-version:subject:from:to:cc; bh=OuJr16cGdSeTRRY2e3lrFCZY64j7gnlLJ3xITCQ65aI=; b=mRBiru9bKQ8H7OIKP2wk7/7jYdaUvQCKVnAZG3PEe9QwZte2v00DMCh90xfZYmOCGS 6cxCgcKBu5N7/FfyT87zTGt3ar3qItyRGaNn1N8wOthCUiAuppfC6gIs0KZmaIpA5yFq Ik0LSzUi6uEPEfREI6pbK4SsHeqmlspqX9aO+efxDsmThbRpQMLOMnz0Jin+xiEOUtUv QS5sVIeqxc9luhCUN5+ppW4gUIXs/DHa6Kmm2clhmnGjjhk8GGmkGQ/l9Ina8gB7uKKF edX7J0JeVgN27rDNeLm77M09wFRCParf9w2p0alrAL3XoQ2GIaHqkVC1sDYLBUNhA/6z fLxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:message-id:mime-version:subject:from :to:cc; bh=OuJr16cGdSeTRRY2e3lrFCZY64j7gnlLJ3xITCQ65aI=; b=gzqn2Cl0ChQJyxJW0XPMXNvw1ipQKdoOQmB2h8LkmYHoMyhYTTpnJrYMAuk7Vc9x3T p+wgjh/qHdXQg4YYSYkvRGY8bpmOkbduFkozLv9OLPaZHdu4VqZaIsfvLbS7YmkiA+GN 4jqtlIKLd6KwjaLOMgMET+Bistxx4JdW4ifUDee7TZ+t5Rr6KK9CtNuHnAndmoAjnpX0 Yy45eENy4AxTLw6mFYVA8A/sNT2r4Z0j5nuoX3hdb65x64XgJ8lr6O9VgdcArQW4oBfy TgPya5CfBpbVSiUpc7i/46Z5KR9epN5Yjl+PtMbN52V7QGvri8IOYaPBCFaFQkhz4Tko FZWw== X-Gm-Message-State: AOAM533LTuEzXJSflEFMXq4LgcazZ1yGCDoEVNV8lm44Pk880+r5A614 umrrbHAIrEgSS7a9OiXp/P5TTrOK X-Google-Smtp-Source: ABdhPJyibp/8MRZ03uFNH2K7UJYyrLBfJXZ6SPg+5oSGvhikGPO6Q3wrWr7cwnzCiBqm+Rk0wPGtAqFu Sender: "lzye via sendgmr" X-Received: from chrisye.mtv.corp.google.com ([2620:15c:211:2:f693:9fff:fef4:4323]) (user=lzye job=sendgmr) by 2002:a25:3bd0:: with SMTP id i199mr8949465yba.70.1604000855284; Thu, 29 Oct 2020 12:47:35 -0700 (PDT) Date: Thu, 29 Oct 2020 12:47:30 -0700 Message-Id: <20201029194730.1615465-1-lzye@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog Subject: [PATCH] ANDROID: Fix the HID usage of DPAD input event generation. From: Chris Ye To: Dmitry Torokhov , Alexandru Ardelean , Mark Brown Cc: linux-kernel@vger.kernel.org, trivial@kernel.org, linux-input@vger.kernel.org, linzhao.ye@gmail.com, Chris Ye Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Generic Desktop DPAD usage is mapped by hid-input, that only the first DPAD usage maps to usage type EV_ABS and code of an axis. If HID descriptor has DPAD UP/DOWN/LEFT/RIGHT HID usages and each of usage size is 1 bit, then only the first one will generate input event, the rest of the HID usages will be assigned to hat direction only. The hid input event should check the HID report value and generate HID event for its hat direction. Test: Connect HID device with Generic Desktop DPAD usage and press the DPAD to generate input events. Signed-off-by: Chris Ye --- drivers/hid/hid-input.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/drivers/hid/hid-input.c b/drivers/hid/hid-input.c index 9770db624bfa..6c1007de3409 100644 --- a/drivers/hid/hid-input.c +++ b/drivers/hid/hid-input.c @@ -1269,7 +1269,7 @@ void hidinput_hid_event(struct hid_device *hid, struct hid_field *field, struct struct input_dev *input; unsigned *quirks = &hid->quirks; - if (!usage->type) + if (!usage->type && !field->dpad) return; if (usage->type == EV_PWR) { @@ -1286,9 +1286,17 @@ void hidinput_hid_event(struct hid_device *hid, struct hid_field *field, struct int hat_dir = usage->hat_dir; if (!hat_dir) hat_dir = (value - usage->hat_min) * 8 / (usage->hat_max - usage->hat_min + 1) + 1; - if (hat_dir < 0 || hat_dir > 8) hat_dir = 0; - input_event(input, usage->type, usage->code , hid_hat_to_axis[hat_dir].x); - input_event(input, usage->type, usage->code + 1, hid_hat_to_axis[hat_dir].y); + if (hat_dir < 0 || hat_dir > 8 || value == 0) + hat_dir = 0; + if (field->dpad) { + input_event(input, EV_ABS, field->dpad, hid_hat_to_axis[hat_dir].x); + input_event(input, EV_ABS, field->dpad + 1, hid_hat_to_axis[hat_dir].y); + } else { + input_event(input, usage->type, usage->code, + hid_hat_to_axis[hat_dir].x); + input_event(input, usage->type, usage->code + 1, + hid_hat_to_axis[hat_dir].y); + } return; } -- 2.29.1.341.ge80a0c044ae-goog