Received: by 2002:a17:90b:8d0:0:0:0:0 with SMTP id ds16csp4877563pjb; Mon, 27 Jul 2020 07:24:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzetR85t4P2lfoYlt+jzNBbYYd4jWqO4LjLsGKm2WhvLUcB/AflSLELNNYbIwGf/WfJTtnl X-Received: by 2002:a17:906:269a:: with SMTP id t26mr21072180ejc.286.1595859896937; Mon, 27 Jul 2020 07:24:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595859896; cv=none; d=google.com; s=arc-20160816; b=MUEwKm0Kzy4GeRBfqgEYYa+5KfvGsAQkt6kJlugrNOAam32xw2C0oqx5+KYj3gLM/O JFECEABVtKqzAOJuy1k4tMRsux6RGK7/DJje/c4FjDNSnX49solitVmlYg9sOVjvHWi4 2gWFYoqz9Lkmbtw/45Di5Lgo72cqrURmK3AioOISTc91u7Nc1Rw6rqxk+/99qNtJuxNv LWFgP+Mru0gJ2sfOpt06eE3UXJ+3EIsqDsrLwNmIclO5rPK0IP0s+xXlraXdrOCG1a7T j8MndUaPs7q/58EiArKJz1p/gDHk7QCyaSnDaA+KYHDcjIMoztnE48K529x87ZV8NfzU cgEg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=pZrvmPjBHmUrnLA49C28EG1Hu5sOcMzlYNZJ+1C+r80=; b=Yy2B9fXrCWlTkz7+7Wzbm5dZvuIH6GA494L6gOjxDmLsnv8mxhlxWFjy8ZFBGAjPhi /Dt2ZEHYasmFRwWXgTTEl/tuqmx6oPJThJn36Fc+Qkt5+Avx8D6CJgFupTDxsrcBCOgW bjgWZSeiadkuBKZHafHX1Pm4In40CWZMdbe25JEUFJig4OcVOoVMwyjG3TKl21EHTOiP rbf1RtgYS9+6KQZbIWPv1WYAt0cOZS5wCXZtSwthhn6tOUb5FMTeZXrQmr1A7a7t/Vws ArP3Q9plXhytn4egdN1VibIoBEq3QTMolUDkQitiuL/JgbaJP42m9hLVFkl4K81r388N RhJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=pPsJpn+g; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e17si4373271eje.672.2020.07.27.07.24.34; Mon, 27 Jul 2020 07:24:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=pPsJpn+g; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731468AbgG0OXP (ORCPT + 99 others); Mon, 27 Jul 2020 10:23:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:52398 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732027AbgG0OXO (ORCPT ); Mon, 27 Jul 2020 10:23:14 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D043C2070A; Mon, 27 Jul 2020 14:23:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1595859793; bh=9FOnQYGHVN4dOx8fmzyzmZVhYjbLjfdb9/yh2ELR+Ow=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pPsJpn+g3b1H1y1MRd/pH+Qtnz7NCFtEEPQVuUnBbj4ueqQ/WxvsU2z3GaVv7Nwx9 AQPVJ3UarEONynDuBL+ojp4LwrHwM95Vpa5JR5uhrb7DqVEUSd/VLoqT2thpF7hgaX P0kYll2PrBuDsGypLIMj4My5L5iz4t5FcRBDBhCs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Joao Moreno , Hans de Goede , Jiri Kosina , Sasha Levin Subject: [PATCH 5.7 107/179] HID: apple: Disable Fn-key key-re-mapping on clone keyboards Date: Mon, 27 Jul 2020 16:04:42 +0200 Message-Id: <20200727134937.863144249@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200727134932.659499757@linuxfoundation.org> References: <20200727134932.659499757@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 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 From: Hans de Goede [ Upstream commit a5d81646fa294eed57786a9310b06ca48902adf8 ] The Maxxter KB-BT-001 Bluetooth keyboard, which looks somewhat like the Apple Wireless Keyboard, is using the vendor and product IDs (05AC:0239) of the Apple Wireless Keyboard (2009 ANSI version) . But its F1 - F10 keys are marked as sending F1 - F10, not the special functions hid-apple.c maps them too; and since its descriptors do not contain the HID_UP_CUSTOM | 0x0003 usage apple-hid looks for for the Fn-key, apple_setup_input() never gets called, so F1 - F6 are mapped to key-codes which have not been set in the keybit array causing them to not send any events at all. The lack of a usage code matching the Fn key in the clone is actually useful as this allows solving this problem in a generic way. This commits adds a fn_found flag and it adds a input_configured callback which checks if this flag is set once all usages have been mapped. If it is not set, then assume this is a clone and clear the quirks bitmap so that the hid-apple code does not add any special handling to this keyboard. This fixes F1 - F6 not sending anything at all and F7 - F12 sending the wrong codes on the Maxxter KB-BT-001 Bluetooth keyboard and on similar clones. Cc: Joao Moreno Signed-off-by: Hans de Goede Signed-off-by: Jiri Kosina Signed-off-by: Sasha Levin --- drivers/hid/hid-apple.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/drivers/hid/hid-apple.c b/drivers/hid/hid-apple.c index d732d1d10cafb..6909c045fece1 100644 --- a/drivers/hid/hid-apple.c +++ b/drivers/hid/hid-apple.c @@ -54,6 +54,7 @@ MODULE_PARM_DESC(swap_opt_cmd, "Swap the Option (\"Alt\") and Command (\"Flag\") struct apple_sc { unsigned long quirks; unsigned int fn_on; + unsigned int fn_found; DECLARE_BITMAP(pressed_numlock, KEY_CNT); }; @@ -339,12 +340,15 @@ static int apple_input_mapping(struct hid_device *hdev, struct hid_input *hi, struct hid_field *field, struct hid_usage *usage, unsigned long **bit, int *max) { + struct apple_sc *asc = hid_get_drvdata(hdev); + if (usage->hid == (HID_UP_CUSTOM | 0x0003) || usage->hid == (HID_UP_MSVENDOR | 0x0003) || usage->hid == (HID_UP_HPVENDOR2 | 0x0003)) { /* The fn key on Apple USB keyboards */ set_bit(EV_REP, hi->input->evbit); hid_map_usage_clear(hi, usage, bit, max, EV_KEY, KEY_FN); + asc->fn_found = true; apple_setup_input(hi->input); return 1; } @@ -371,6 +375,19 @@ static int apple_input_mapped(struct hid_device *hdev, struct hid_input *hi, return 0; } +static int apple_input_configured(struct hid_device *hdev, + struct hid_input *hidinput) +{ + struct apple_sc *asc = hid_get_drvdata(hdev); + + if ((asc->quirks & APPLE_HAS_FN) && !asc->fn_found) { + hid_info(hdev, "Fn key not found (Apple Wireless Keyboard clone?), disabling Fn key handling\n"); + asc->quirks = 0; + } + + return 0; +} + static int apple_probe(struct hid_device *hdev, const struct hid_device_id *id) { @@ -585,6 +602,7 @@ static struct hid_driver apple_driver = { .event = apple_event, .input_mapping = apple_input_mapping, .input_mapped = apple_input_mapped, + .input_configured = apple_input_configured, }; module_hid_driver(apple_driver); -- 2.25.1