Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp359344ybe; Wed, 4 Sep 2019 00:27:03 -0700 (PDT) X-Google-Smtp-Source: APXvYqwGr8AyKxyakgalV0eLGdhxU3NP+GBwlBk49c+rf3o8dwDu2cX/FlNyHRlZWXidIQx0/3hB X-Received: by 2002:a65:5cca:: with SMTP id b10mr34786857pgt.365.1567582023761; Wed, 04 Sep 2019 00:27:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567582023; cv=none; d=google.com; s=arc-20160816; b=hcL8FK1guZfXmMkVQCDqfD6I7VjTw+fwc+PhnZ3K8p1y+FAz9fZ5xJiQbkLngFqL3D fIOugG4aTekCOnwNWWGhkzi/BTzDLmOii0M9pPD4LyxKwO0KW1Emx1mNUFRWYRV0gI+q Om/ySJ3qNvVy7aKk91yG2Gjt201KY0U7FYvEWc2DVfMkTjFZrpm0V265lW/YVuGkSms3 3theKcjQCAED8wQxE7MhHW9+mG3uBUVRocptpoRkhOAXxwA4chZ+8BFWbxlosvue/Kem H/891OMGBpV+VKTotw9YVFTjKdDtVC44kBZp0RZH4bMYNXD288Bin2YwonZz1WGK6Wbj EebQ== 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:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version; bh=TGd89B2kFxwy7BVV8OXsfhxRzVE3x0YglHJnIDE28f0=; b=ez0si7w1FbTth9CDef6JMcuVP0tswCyguzAydpDnuDNC/wjdS8xZ6hzV9K1EoQLSSv PBN8I2gkNEtJOAO9VcuKKmIB4AMW2Ri6/oFEQTOmMb4htv9MUOgy/L4ZYXY9cwgsheq5 ANn9ub8UwI65QmZzXequ/uTCKVcsv8x8EYyA319bjEVQnqG7cpMWyEDDzEDnzEZ4H6yP WP9p+XQloxmSvirDtVX9IoDqT7b01ZyUhXvIXjYZI04GnUuVzLgW0fcjIvfjEAUgGGPw 4xOZZ94vvRK4Q1rdFOtui/vbsjOSnms3+qnqk+XUxLCObi7MwI4Ep9uoU2rfpXXyyG41 aOOQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b6si1604582pjn.2.2019.09.04.00.26.48; Wed, 04 Sep 2019 00:27:03 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728951AbfIDHZw convert rfc822-to-8bit (ORCPT + 99 others); Wed, 4 Sep 2019 03:25:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41378 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725840AbfIDHZw (ORCPT ); Wed, 4 Sep 2019 03:25:52 -0400 Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 78D3BC04D293 for ; Wed, 4 Sep 2019 07:25:51 +0000 (UTC) Received: by mail-qt1-f198.google.com with SMTP id x11so21748451qtm.11 for ; Wed, 04 Sep 2019 00:25:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=qGt7/Asvjla5NLjhNtTVWV76tKsaxhQMsyUh6I8J27A=; b=ZLNOvsnVjlqzydQtbqOEVGPEuYk99mgR0IqKLZlIIyUaL5E0mOGWNADjvgVLLMpUpm eBXvvGQkIdtZD3epMQRy6YOf6UoEV8+fw/Puaaj8JQc8UdA2UHM7I9YVnQbAeUqopIf7 3nCABoMSts3GVwVpOq6G4Dzjkk88Ftq/rLv5Ss3aYzR2lQghAKw/Hh8ZSDs8lyRNux5g /GxZJl+3osm9AFmCZOfnoRPipxQ/mV/VCZch4Bt0hgeZK4L1hZZ3ST5H6UriLc2wMX6Q 6f9br/Qz+05YyCMqJtrxOZZ4YXUegKx35m2sddP1pqOTd7MflhBw3nkqXWvBfOkGsbdL SmgQ== X-Gm-Message-State: APjAAAXWNpKzedQ1wYPKMXwjBY8aI7AKLVY/vYM7/BzrP4Nf3+tcEAkh SBLpiU5CoaIQttxnMMLXwyDaL8mO0SuhrdktSvADFsxQu12cS3A48kquajrS4YtMXqION8lPO8N z20mdr5bODaJvUiqcRr6zBvbWHyqrPm7PoKfz4P6K X-Received: by 2002:a0c:afe6:: with SMTP id t35mr7541973qvc.29.1567581950732; Wed, 04 Sep 2019 00:25:50 -0700 (PDT) X-Received: by 2002:a0c:afe6:: with SMTP id t35mr7541962qvc.29.1567581950479; Wed, 04 Sep 2019 00:25:50 -0700 (PDT) MIME-Version: 1.0 References: <20190903144632.26299-1-benjamin.tissoires@redhat.com> In-Reply-To: From: Benjamin Tissoires Date: Wed, 4 Sep 2019 09:25:39 +0200 Message-ID: Subject: Re: [PATCH v2] HID: apple: Fix stuck function keys when using FN To: =?UTF-8?B?Sm/Do28gTW9yZW5v?= Cc: Jiri Kosina , "open list:HID CORE LAYER" , lkml Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Sep 3, 2019 at 8:33 PM João Moreno wrote: > > Hi Benjamin, > > On Tue, 3 Sep 2019 at 16:46, Benjamin Tissoires > wrote: > > > > From: Joao Moreno > > > > This fixes an issue in which key down events for function keys would be > > repeatedly emitted even after the user has raised the physical key. For > > example, the driver fails to emit the F5 key up event when going through > > the following steps: > > - fnmode=1: hold FN, hold F5, release FN, release F5 > > - fnmode=2: hold F5, hold FN, release F5, release FN > > > > The repeated F5 key down events can be easily verified using xev. > > > > Signed-off-by: Joao Moreno > > Co-developed-by: Benjamin Tissoires > > Signed-off-by: Benjamin Tissoires > > --- > > > > Hi Joao, > > > > last chance to pull back :) > > > > If you are still happy, I'll push this version > > > > Cheers, > > Benjamin > > > > Looks great. Thanks a bunch for your help! > Thanks. Applied to for-5.4/apple Cheers, Benjamin > Cheers, > João > > > drivers/hid/hid-apple.c | 49 +++++++++++++++++++++++------------------ > > 1 file changed, 28 insertions(+), 21 deletions(-) > > > > diff --git a/drivers/hid/hid-apple.c b/drivers/hid/hid-apple.c > > index 81df62f48c4c..6ac8becc2372 100644 > > --- a/drivers/hid/hid-apple.c > > +++ b/drivers/hid/hid-apple.c > > @@ -54,7 +54,6 @@ MODULE_PARM_DESC(swap_opt_cmd, "Swap the Option (\"Alt\") and Command (\"Flag\") > > struct apple_sc { > > unsigned long quirks; > > unsigned int fn_on; > > - DECLARE_BITMAP(pressed_fn, KEY_CNT); > > DECLARE_BITMAP(pressed_numlock, KEY_CNT); > > }; > > > > @@ -181,6 +180,8 @@ static int hidinput_apple_event(struct hid_device *hid, struct input_dev *input, > > { > > struct apple_sc *asc = hid_get_drvdata(hid); > > const struct apple_key_translation *trans, *table; > > + bool do_translate; > > + u16 code = 0; > > > > if (usage->code == KEY_FN) { > > asc->fn_on = !!value; > > @@ -189,8 +190,6 @@ static int hidinput_apple_event(struct hid_device *hid, struct input_dev *input, > > } > > > > if (fnmode) { > > - int do_translate; > > - > > if (hid->product >= USB_DEVICE_ID_APPLE_WELLSPRING4_ANSI && > > hid->product <= USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS) > > table = macbookair_fn_keys; > > @@ -202,25 +201,33 @@ static int hidinput_apple_event(struct hid_device *hid, struct input_dev *input, > > trans = apple_find_translation (table, usage->code); > > > > if (trans) { > > - if (test_bit(usage->code, asc->pressed_fn)) > > - do_translate = 1; > > - else if (trans->flags & APPLE_FLAG_FKEY) > > - do_translate = (fnmode == 2 && asc->fn_on) || > > - (fnmode == 1 && !asc->fn_on); > > - else > > - do_translate = asc->fn_on; > > - > > - if (do_translate) { > > - if (value) > > - set_bit(usage->code, asc->pressed_fn); > > - else > > - clear_bit(usage->code, asc->pressed_fn); > > - > > - input_event(input, usage->type, trans->to, > > - value); > > - > > - return 1; > > + if (test_bit(trans->from, input->key)) > > + code = trans->from; > > + else if (test_bit(trans->to, input->key)) > > + code = trans->to; > > + > > + if (!code) { > > + if (trans->flags & APPLE_FLAG_FKEY) { > > + switch (fnmode) { > > + case 1: > > + do_translate = !asc->fn_on; > > + break; > > + case 2: > > + do_translate = asc->fn_on; > > + break; > > + default: > > + /* should never happen */ > > + do_translate = false; > > + } > > + } else { > > + do_translate = asc->fn_on; > > + } > > + > > + code = do_translate ? trans->to : trans->from; > > } > > + > > + input_event(input, usage->type, code, value); > > + return 1; > > } > > > > if (asc->quirks & APPLE_NUMLOCK_EMULATION && > > -- > > 2.19.2 > >