aboutsummarylogtreecommitdiffstats
path: root/HID-asus-Reduce-object-size-by-consolidating-calls.patch
blob: 761b6bcae9effbfc4c3eee31a542784f60b58dc8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
From patchwork Sat May 29 16:29:48 2021
Message-ID: <56767df55117cc5834b0021ba2c056272e686804.camel@perches.com>
Subject: [PATCH] HID: asus: Reduce object size by consolidating calls
From: Joe Perches <joe@perches.com>
To: Jiri Kosina <jikos@kernel.org>,
        Benjamin Tissoires <benjamin.tissoires@redhat.com>
Cc: linux-input <linux-input@vger.kernel.org>,
        LKML <linux-kernel@vger.kernel.org>
Date: Sat, 29 May 2021 09:29:48 -0700
List-ID: <linux-input.vger.kernel.org>
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 <joe@perches.com>
---

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;
 	}