Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp211557ybh; Mon, 20 Jul 2020 14:42:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw6oM6C6uIGvOKsv32u+BGFkgqJeul1gvFwUSDAzgpDBUD7DGoNuKM8GK4D6VT1RjAxVthv X-Received: by 2002:aa7:cf02:: with SMTP id a2mr23776151edy.263.1595281350351; Mon, 20 Jul 2020 14:42:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595281350; cv=none; d=google.com; s=arc-20160816; b=iDblQwAceY2GnLuQ8CFxR6AIWpLz+ABMAH+g1zhMlL8OwOD/KynxW+hvdtg8eL6O+Q 3l33yhfxgn3GPjkNGAp4B4gtBX7g62UVxv4mM2NCY2/lODiliVVXn9ZXU4nq1DuhxkDc yHbTlgjdbLf13ep2Qtz2mnfVDHxZcGa0H5MYxXfXsm3ykb9WQDzuaHCcSNGwevmP6e2S cduW/+4JOIpV4jRGZkl+6AgAG2L4bSOsZB1AIT7V5feXw55eWOduxgM9XJT/RYJW1PUZ ahrceex06GSHCuRM6WELJQaYa9gSEck1pkzrNrSwm68w4nleuA+/kAiwGi28cVNZJwro ys3A== 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=9AkQBO7OaY2E6cAJuy3GyLoG2YleUg/+tcXtiA96laA=; b=Mi/fCPtrjVWtVEZyI7mhdLr24EZltM7gm0xir52cthRFYumOM0UZXLECmDbrTmK8ZO Gfhi7ndZcxqB11DVaWqCahczDjXAHl3uTqLNpKxmgfpwX2tujGb10SFanTDvGfUbQR+a FcY6qOrGXjZm2sf6h1YJrZyVHC7DW+Mtn5gYdG3xjxEJFKsM3RE6gq6y9i1ROTB8fWcX N1n8tzlrozZBjH7+lpLQsvetzUfTBFCWYUudIOeyp1JSP3SPcjzMTzRCk3y+4NbbN4HG JHnfqKCHHHr2vMska2zixbp8eoy8QXEGsmi8LxZSYHj6iR7fm+BnUdvpJl6LoHSGEgld hnZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=aKOsZgk3; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l9si11576318edn.77.2020.07.20.14.42.07; Mon, 20 Jul 2020 14:42:30 -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=aKOsZgk3; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728443AbgGTVjX (ORCPT + 99 others); Mon, 20 Jul 2020 17:39:23 -0400 Received: from mail.kernel.org ([198.145.29.99]:57906 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728291AbgGTVi5 (ORCPT ); Mon, 20 Jul 2020 17:38:57 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 9478D22CF7; Mon, 20 Jul 2020 21:38:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1595281136; bh=gsPJusJ2WJfAmoKVDrtfaIh+MKZOfkh8nvK442dShYQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aKOsZgk3edSalwlWzRsyOARH9gLY0n/+hWbLW4AmUFZZXOY6dyEm/jWBZYQ7g9Y6e gbZExbhgYi8FIonDRHwFTlg7WCSjJxdNxi4FIMca+mDrufIgpmT54TySmxb229NXJJ v8bTFnxfgorHyAZR+eobF9Qyb5sou1Xna3znxqP8= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Hans de Goede , Joao Moreno , Jiri Kosina , Sasha Levin , linux-input@vger.kernel.org Subject: [PATCH AUTOSEL 4.19 04/19] HID: apple: Disable Fn-key key-re-mapping on clone keyboards Date: Mon, 20 Jul 2020 17:38:35 -0400 Message-Id: <20200720213851.407715-4-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200720213851.407715-1-sashal@kernel.org> References: <20200720213851.407715-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore 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 8ab8f2350bbcd..b58ab769aa7b3 100644 --- a/drivers/hid/hid-apple.c +++ b/drivers/hid/hid-apple.c @@ -57,6 +57,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); }; @@ -342,12 +343,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; } @@ -374,6 +378,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) { @@ -588,6 +605,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