From patchwork Mon May 29 22:20:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rahul Rameshbabu X-Patchwork-Id: 687074 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0EFF8C7EE23 for ; Mon, 29 May 2023 22:21:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229898AbjE2WVK (ORCPT ); Mon, 29 May 2023 18:21:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47642 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229712AbjE2WVI (ORCPT ); Mon, 29 May 2023 18:21:08 -0400 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2075.outbound.protection.outlook.com [40.107.223.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 42897D9; Mon, 29 May 2023 15:21:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eMzfX0XvPoFwNsXJngJaSecoGvjI0J84HZylrDzxrad+sl89wcD5aJiYCqsn1ENhZlTfcZYw05em/a0ECdus+NzIAm6xBlqn+xKh9+4SMccdDzn31U/6ZVEFb2e9kSKC8fvamqBC4YRQB/yZZPt3du63IN4GHFFj7Zmbh58dQtku+rAgSbQTG18i8jSAFgn8UhGIt5aHMdyveFBAEaPxLeZnmULOPfpnwmtkSWXIhHe9YFvA3oJko9k4WcdvpJZD99SA5cOoVPai8qUHJmIm+YaJNWiQglNynYYh2DKc+4tV6FjhzLbk2WEsvXNDXF0+y20ijup1WKZu+vobPGxV8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=vUe8hSLSkY6kC/+7P2GtOEmkhIVmW9KSZfXa6hRn4Ck=; b=Lf7jDt5WKG0acHlxdJG/GBhLqMsWsJByDQPx5J2dfgVzbBbeLiGUL/09Za2rFWvjx4/0z1Znc0bjmm8zT4erWW+h90WkxAEQlKWKWIpYMt/AYS50Uo6saq25N8K+/kN4iLDWmc5PiXUEBLd7qqTtFUVjQ4Z6FvhG/HXaE+ycg0/r4XolU6RCSWq/c8OqQHZyIBZPSr+E4VnIFDhAaJ2vkKULcmgLaYea4E2KV5NWexqqqy4clGzq5TxDrDu9QRL6p4xGBd1pNlUClrerO2h+SppTD6pssAvtsSDaSoqFNBSFhmjyOy0Z22O9y4+53ma3ILrgEbz+Vh3yN8vWmYZuzQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=vUe8hSLSkY6kC/+7P2GtOEmkhIVmW9KSZfXa6hRn4Ck=; b=qKgDYRASL9hWUjcH+xuwchrI35zTUUAuw3hVCRc+p8sZ65V7H6RLNKxtHzXgxduCMuUcShkAY+JdV+P9u8S2RFkShLBvzQqbNFwG1eyfacpOvPDUgfk9vDpoSic477IrmxZcNyADG25Yj2D/eg3q//FZWZcWsAEWaOQrA0gbOPkQIrZ3NzVWi7NzrkGepRy/qTtWuA7q+eNAGrJDOOS7RP3t27fr3Tgb4FbpOsPq91IkkvEZEEhdUG/mRcaQHtvhnfgytPbNVY7ytHZ55rsU1ZS2n1st3XaOMBdpQI4cYVdXppDMiuFBRVl34qwdAZR8lxMf5BPLNJfaFM8vFAiAgA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from BYAPR12MB2743.namprd12.prod.outlook.com (2603:10b6:a03:61::28) by BN9PR12MB5355.namprd12.prod.outlook.com (2603:10b6:408:104::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6433.23; Mon, 29 May 2023 22:21:04 +0000 Received: from BYAPR12MB2743.namprd12.prod.outlook.com ([fe80::f3d4:f48a:1bfc:dbf1]) by BYAPR12MB2743.namprd12.prod.outlook.com ([fe80::f3d4:f48a:1bfc:dbf1%5]) with mapi id 15.20.6433.018; Mon, 29 May 2023 22:21:04 +0000 From: Rahul Rameshbabu To: Benjamin Tissoires , Jiri Kosina Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, Rahul Rameshbabu Subject: [PATCH RFC v1 1/3] HID: nvidia-shield: Add mappings for consumer HID USAGE buttons Date: Mon, 29 May 2023 15:20:50 -0700 Message-Id: <20230529222052.68913-2-rrameshbabu@nvidia.com> X-Mailer: git-send-email 2.38.4 In-Reply-To: <20230529222052.68913-1-rrameshbabu@nvidia.com> References: <20230529222052.68913-1-rrameshbabu@nvidia.com> X-ClientProxiedBy: SJ0PR03CA0373.namprd03.prod.outlook.com (2603:10b6:a03:3a1::18) To BYAPR12MB2743.namprd12.prod.outlook.com (2603:10b6:a03:61::28) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BYAPR12MB2743:EE_|BN9PR12MB5355:EE_ X-MS-Office365-Filtering-Correlation-Id: 423125f8-d8a8-4efd-882c-08db6092fda9 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: rTBbCaONemfe9ZJH8f/4mfoc29VDjpI7qhUBCLIywA723t0H6Ik/QXvxBcL+fKDSxLD3rpas0J11Hh905v9eYOrSZ1G3CPzp6thB3SsRO3urd5IHmP0D8oXS0pY3s4XGxWJ9C5Lm2P+NRuXoVmjdTPaVpKgmwA0kBRKV5EMH1JYLBSuuqnl3qw8spzpPVMF32wU8+o2Dt5j01a+JOL++hRkFUoiIx9qRCF1UrtwTS5wPGgMKqYdm8ik5rWag4qTBcdvlh6qvOx2DQoC10svZvfwLye5Lpl7sVVSPu5JdxL2RN3dM25DUnfgkAZCDNHH/1SXFSI3f5a0U15OrGdtttj0YXYjkrlAWTx5qg0b6DcjbO9BFuzz6ltjEDMYAbzb7Uk3jKa3qy8gh5leN08XLlAH/dq3DllyQ2QtWw6Vxqa0cX3mLwTxFFq3u9yDd2l8/Re+NczAXPz+ISPffgORl+L62V7VljledTZOpibgxJ/vkHJ3XLavsX1GqyfwARwp8cKDi+V7UNxj/55D2Pn92FbWgJY3EZwG5Hvcf3EOPHfisJ5p0EUf1sVbt2ijtvLMt X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BYAPR12MB2743.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230028)(4636009)(366004)(39860400002)(396003)(346002)(376002)(136003)(451199021)(6506007)(6512007)(186003)(2906002)(2616005)(110136005)(478600001)(26005)(1076003)(83380400001)(8676002)(41300700001)(38100700002)(8936002)(6486002)(86362001)(6666004)(316002)(66946007)(5660300002)(66476007)(66556008)(36756003)(107886003)(4326008); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 34JsuWz3l1zXILzMP7H5ynEiU7ELQzTaJwmIFpdx+R0rQ09DgaVLpDh2HHkwXwsQcxN461IEbOHNOuy0bGOjMurFxN3/1wXXpoRVsXo8PQ/8WrjRhKt6x0pV5zO/n00Zqo2Z0ppHgvzAyS7P0i9VFbDAgGLstOSnH6OLYhdL3Xlz5b2a4OR7d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rZKS/ssbqlKiTYSBaP1zxoapBGBB99R8kTMWowcTFHEB+4Da6Dp0ifcHqPZwu1JRnkHfIxsWODsfNm/74H9yInp5qeSJP4AhNGI14K3W5SP3jQIENTrfmKDj9ggO7cVx3rk+APnOawL3lzFonVQ+CjVuw8fZHJMuW+CDfn1YorpCEH8qx6YVWkojF2th+D8jOSgz48GAHd7EVXGb3uYlpz7VSd+gYU//uDYgQeTpx/ScQTENZrxGEFA1UPVNmzT8iH4jPM4SAzEik8Aq8VYvX5+LINi81w+gSUweNzvFwTJIoIDgxe6XspMb5xbKprddwlmn9hRLO45tKhQFAjqVpqgrYqy3liQ9QVEHFA== X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 423125f8-d8a8-4efd-882c-08db6092fda9 X-MS-Exchange-CrossTenant-AuthSource: BYAPR12MB2743.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 May 2023 22:21:04.1392 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: mdfj+Xmbq9sbfbWGoUB/ACpI3JZ3EZM15tiuQgzGIlxx9aAQg/m1q/YnPkZJ9bqM/qnkkH6pMsHYBJxpT4kNRA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN9PR12MB5355 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org Map Android Home, Back, Search, VolumeUp, VolumeDown, and PlayPause buttons to the appropriate input event codes. Signed-off-by: Rahul Rameshbabu --- drivers/hid/hid-nvidia-shield.c | 55 ++++++++++++++++++++++++++++++--- 1 file changed, 50 insertions(+), 5 deletions(-) diff --git a/drivers/hid/hid-nvidia-shield.c b/drivers/hid/hid-nvidia-shield.c index bcf345e365c0..1a9d32b2c80c 100644 --- a/drivers/hid/hid-nvidia-shield.c +++ b/drivers/hid/hid-nvidia-shield.c @@ -15,6 +15,16 @@ #include "hid-ids.h" #define NOT_INIT_STR "NOT INITIALIZED" +#define android_map_key(c) hid_map_usage(hi, usage, bit, max, EV_KEY, (c)) + +enum { + HID_USAGE_ANDROID_PLAYPAUSE_BTN = 0xcd, /* Double-tap volume slider */ + HID_USAGE_ANDROID_VOLUMEUP_BTN = 0xe9, + HID_USAGE_ANDROID_VOLUMEDOWN_BTN = 0xea, + HID_USAGE_ANDROID_SEARCH_BTN = 0x221, /* NVIDIA btn on Thunderstrike */ + HID_USAGE_ANDROID_HOME_BTN = 0x223, + HID_USAGE_ANDROID_BACK_BTN = 0x224, +}; enum { SHIELD_FW_VERSION_INITIALIZED = 0, @@ -416,6 +426,40 @@ static struct shield_device *thunderstrike_create(struct hid_device *hdev) return shield_dev; } +static int android_input_mapping(struct hid_device *hdev, struct hid_input *hi, + struct hid_field *field, + struct hid_usage *usage, unsigned long **bit, + int *max) +{ + if ((usage->hid & HID_USAGE_PAGE) != HID_UP_CONSUMER) + return 0; + + switch (usage->hid & HID_USAGE) { + case HID_USAGE_ANDROID_PLAYPAUSE_BTN: + android_map_key(KEY_PLAYPAUSE); + break; + case HID_USAGE_ANDROID_VOLUMEUP_BTN: + android_map_key(KEY_VOLUMEUP); + break; + case HID_USAGE_ANDROID_VOLUMEDOWN_BTN: + android_map_key(KEY_VOLUMEDOWN); + break; + case HID_USAGE_ANDROID_SEARCH_BTN: + android_map_key(BTN_Z); + break; + case HID_USAGE_ANDROID_HOME_BTN: + android_map_key(BTN_MODE); + break; + case HID_USAGE_ANDROID_BACK_BTN: + android_map_key(BTN_SELECT); + break; + default: + return 0; + } + + return 1; +} + static ssize_t firmware_version_show(struct device *dev, struct device_attribute *attr, char *buf) { @@ -571,11 +615,12 @@ static const struct hid_device_id shield_devices[] = { MODULE_DEVICE_TABLE(hid, shield_devices); static struct hid_driver shield_driver = { - .name = "shield", - .id_table = shield_devices, - .probe = shield_probe, - .remove = shield_remove, - .raw_event = shield_raw_event, + .name = "shield", + .id_table = shield_devices, + .input_mapping = android_input_mapping, + .probe = shield_probe, + .remove = shield_remove, + .raw_event = shield_raw_event, .driver = { .dev_groups = shield_device_groups, },