From patchwork Sat May 29 16:29:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Perches X-Patchwork-Id: 450166 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=-13.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, UNPARSEABLE_RELAY, URIBL_BLOCKED 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 0E806C4708E for ; Sat, 29 May 2021 16:29:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CADBC61090 for ; Sat, 29 May 2021 16:29:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229716AbhE2Qb2 (ORCPT ); Sat, 29 May 2021 12:31:28 -0400 Received: from smtprelay0132.hostedemail.com ([216.40.44.132]:46406 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229704AbhE2Qb2 (ORCPT ); Sat, 29 May 2021 12:31:28 -0400 Received: from omf12.hostedemail.com (clb03-v110.bra.tucows.net [216.40.38.60]) by smtprelay05.hostedemail.com (Postfix) with ESMTP id 0F28A18028E85; Sat, 29 May 2021 16:29:51 +0000 (UTC) Received: from [HIDDEN] (Authenticated sender: joe@perches.com) by omf12.hostedemail.com (Postfix) with ESMTPA id 49BDD240236; Sat, 29 May 2021 16:29:50 +0000 (UTC) Message-ID: <56767df55117cc5834b0021ba2c056272e686804.camel@perches.com> Subject: [PATCH] HID: asus: Reduce object size by consolidating calls From: Joe Perches To: Jiri Kosina , Benjamin Tissoires Cc: linux-input , LKML Date: Sat, 29 May 2021 09:29:48 -0700 User-Agent: Evolution 3.38.1-1 MIME-Version: 1.0 X-Stat-Signature: 5ua3pak1316wh7njudnygas7mc65fnxd X-Rspamd-Server: rspamout04 X-Rspamd-Queue-Id: 49BDD240236 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Session-ID: U2FsdGVkX1+DcKysZUCHqlPe7g/GHmLDopwkRmJ3TDc= X-HE-Tag: 1622305790-299222 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org Add intermediating lookup functions to avoid repetitive calls. Reduces object size ~4kb (x86-64 defconfig w/ hid-asus) $ size drivers/hid/hid-asus.o* text data bss dec hex filename 10442 468 0 10910 2a9e drivers/hid/hid-asus.o.bew 14523 468 0 14991 3a8f drivers/hid/hid-asus.o.old Miscellanea: o Remove now unused asus_map_kay_clear macro Signed-off-by: Joe Perches --- untested, no hardware drivers/hid/hid-asus.c | 128 ++++++++++++++++++++++++------------------------- 1 file changed, 64 insertions(+), 64 deletions(-) diff --git a/drivers/hid/hid-asus.c b/drivers/hid/hid-asus.c index fca8fc78a78a3..5b78e6c3bb5d9 100644 --- a/drivers/hid/hid-asus.c +++ b/drivers/hid/hid-asus.c @@ -811,8 +811,58 @@ static int asus_input_configured(struct hid_device *hdev, struct hid_input *hi) return 0; } -#define asus_map_key_clear(c) hid_map_usage_clear(hi, usage, bit, \ - max, EV_KEY, (c)) +static int asus_map_use_to_btn(int use) +{ + switch (use) { + case 0x10: return KEY_BRIGHTNESSDOWN; + case 0x20: return KEY_BRIGHTNESSUP; + case 0x35: return KEY_DISPLAY_OFF; + case 0x6c: return KEY_SLEEP; + case 0x7c: return KEY_MICMUTE; + case 0x82: return KEY_CAMERA; + case 0x88: return KEY_RFKILL; + case 0xb5: return KEY_CALC; + case 0xc4: return KEY_KBDILLUMUP; + case 0xc5: return KEY_KBDILLUMDOWN; + case 0x6b: return KEY_F21; /* ASUS touchpad toggle */ + case 0x38: return KEY_PROG1; /* ROG key */ + case 0xba: return KEY_PROG2; /* Fn+C ASUS Splendid */ + case 0x5c: return KEY_PROG3; /* Fn+Space Power4Gear Hybrid */ + case 0x99: return KEY_PROG4; /* Fn+F5 "fan" symbol on FX503VD */ + /* for N-Key keyboard */ + case 0xae: return KEY_PROG4; /* Fn+F5 "fan" symbol */ + case 0x92: return KEY_CALC; /* Fn+Ret "Calc" symbol */ + case 0xb2: return KEY_PROG2; /* Fn+Left Aura mode previous */ + case 0xb3: return KEY_PROG3; /* Fn+Right Aura mode next */ + } + + return 0; +} + +static int ms_map_use_to_btn(int use) +{ + switch (use) { + case 0xff01: return BTN_1; + case 0xff02: return BTN_2; + case 0xff03: return BTN_3; + case 0xff04: return BTN_4; + case 0xff05: return BTN_5; + case 0xff06: return BTN_6; + case 0xff07: return BTN_7; + case 0xff08: return BTN_8; + case 0xff09: return BTN_9; + case 0xff0a: return BTN_A; + case 0xff0b: return BTN_B; + case 0x00f1: return KEY_WLAN; + case 0x00f2: return KEY_BRIGHTNESSDOWN; + case 0x00f3: return KEY_BRIGHTNESSUP; + case 0x00f4: return KEY_DISPLAY_OFF; + case 0x00f7: return KEY_CAMERA; + case 0x00f8: return KEY_PROG1; + } + + return 0; +} static int asus_input_mapping(struct hid_device *hdev, struct hid_input *hi, struct hid_field *field, struct hid_usage *usage, unsigned long **bit, @@ -842,50 +892,16 @@ static int asus_input_mapping(struct hid_device *hdev, /* ASUS-specific keyboard hotkeys and led backlight */ if ((usage->hid & HID_USAGE_PAGE) == HID_UP_ASUSVENDOR) { - switch (usage->hid & HID_USAGE) { - case 0x10: asus_map_key_clear(KEY_BRIGHTNESSDOWN); break; - case 0x20: asus_map_key_clear(KEY_BRIGHTNESSUP); break; - case 0x35: asus_map_key_clear(KEY_DISPLAY_OFF); break; - case 0x6c: asus_map_key_clear(KEY_SLEEP); break; - case 0x7c: asus_map_key_clear(KEY_MICMUTE); break; - case 0x82: asus_map_key_clear(KEY_CAMERA); break; - case 0x88: asus_map_key_clear(KEY_RFKILL); break; - case 0xb5: asus_map_key_clear(KEY_CALC); break; - case 0xc4: asus_map_key_clear(KEY_KBDILLUMUP); break; - case 0xc5: asus_map_key_clear(KEY_KBDILLUMDOWN); break; - - /* ASUS touchpad toggle */ - case 0x6b: asus_map_key_clear(KEY_F21); break; - - /* ROG key */ - case 0x38: asus_map_key_clear(KEY_PROG1); break; - - /* Fn+C ASUS Splendid */ - case 0xba: asus_map_key_clear(KEY_PROG2); break; + int btn = asus_map_use_to_btn(usage->hid & HID_USAGE); - /* Fn+Space Power4Gear Hybrid */ - case 0x5c: asus_map_key_clear(KEY_PROG3); break; - - /* Fn+F5 "fan" symbol on FX503VD */ - case 0x99: asus_map_key_clear(KEY_PROG4); break; - - /* Fn+F5 "fan" symbol on N-Key keyboard */ - case 0xae: asus_map_key_clear(KEY_PROG4); break; - - /* Fn+Ret "Calc" symbol on N-Key keyboard */ - case 0x92: asus_map_key_clear(KEY_CALC); break; - - /* Fn+Left Aura mode previous on N-Key keyboard */ - case 0xb2: asus_map_key_clear(KEY_PROG2); break; - - /* Fn+Right Aura mode next on N-Key keyboard */ - case 0xb3: asus_map_key_clear(KEY_PROG3); break; - - default: - /* ASUS lazily declares 256 usages, ignore the rest, - * as some make the keyboard appear as a pointer device. */ + /* + * ASUS lazily declares 256 usages, ignore the rest, + * as some make the keyboard appear as a pointer device. + */ + if (!btn) return -1; - } + + hid_map_usage_clear(hi, usage, bit, max, EV_KEY, btn); /* * Check and enable backlight only on devices with UsagePage == @@ -901,28 +917,12 @@ static int asus_input_mapping(struct hid_device *hdev, } if ((usage->hid & HID_USAGE_PAGE) == HID_UP_MSVENDOR) { - switch (usage->hid & HID_USAGE) { - case 0xff01: asus_map_key_clear(BTN_1); break; - case 0xff02: asus_map_key_clear(BTN_2); break; - case 0xff03: asus_map_key_clear(BTN_3); break; - case 0xff04: asus_map_key_clear(BTN_4); break; - case 0xff05: asus_map_key_clear(BTN_5); break; - case 0xff06: asus_map_key_clear(BTN_6); break; - case 0xff07: asus_map_key_clear(BTN_7); break; - case 0xff08: asus_map_key_clear(BTN_8); break; - case 0xff09: asus_map_key_clear(BTN_9); break; - case 0xff0a: asus_map_key_clear(BTN_A); break; - case 0xff0b: asus_map_key_clear(BTN_B); break; - case 0x00f1: asus_map_key_clear(KEY_WLAN); break; - case 0x00f2: asus_map_key_clear(KEY_BRIGHTNESSDOWN); break; - case 0x00f3: asus_map_key_clear(KEY_BRIGHTNESSUP); break; - case 0x00f4: asus_map_key_clear(KEY_DISPLAY_OFF); break; - case 0x00f7: asus_map_key_clear(KEY_CAMERA); break; - case 0x00f8: asus_map_key_clear(KEY_PROG1); break; - default: + int btn = ms_map_use_to_btn(usage->hid & HID_USAGE); + + if (!btn) return 0; - } + hid_map_usage_clear(hi, usage, bit, max, EV_KEY, btn); set_bit(EV_REP, hi->input->evbit); return 1; }