Skip to content

Commit b459449

Browse files
AdityaGarg8Jiri Kosina
authored andcommitted
HID: apple: use switch case to set fn translation table
There has been a continuous increase in the number of devices requiring hid-apple driver during the last few years. Moreover, unlike previous releases, the PIDs of the newer devices released cannot be combined in a specific range, thus filling up the if else if statements with individual device IDs. For such large table, its now more suitable to use switch case instead of if else if for improved readability. Signed-off-by: Aditya Garg <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent 4e960bb commit b459449

File tree

1 file changed

+41
-32
lines changed

1 file changed

+41
-32
lines changed

drivers/hid/hid-apple.c

Lines changed: 41 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -465,42 +465,51 @@ static int hidinput_apple_event(struct hid_device *hid, struct input_dev *input,
465465
asc->fn_on = !!value;
466466

467467
if (real_fnmode) {
468-
if (hid->product == USB_DEVICE_ID_APPLE_ALU_WIRELESS_ANSI ||
469-
hid->product == USB_DEVICE_ID_APPLE_ALU_WIRELESS_ISO ||
470-
hid->product == USB_DEVICE_ID_APPLE_ALU_WIRELESS_JIS ||
471-
hid->product == USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ANSI ||
472-
hid->product == USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ISO ||
473-
hid->product == USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_JIS ||
474-
hid->product == USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ANSI ||
475-
hid->product == USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ISO ||
476-
hid->product == USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_JIS)
468+
switch (hid->product) {
469+
case USB_DEVICE_ID_APPLE_ALU_WIRELESS_ANSI:
470+
case USB_DEVICE_ID_APPLE_ALU_WIRELESS_ISO:
471+
case USB_DEVICE_ID_APPLE_ALU_WIRELESS_JIS:
472+
case USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ANSI:
473+
case USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ISO:
474+
case USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_JIS:
475+
case USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ANSI:
476+
case USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ISO:
477+
case USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_JIS:
477478
table = magic_keyboard_alu_fn_keys;
478-
else if (hid->product == USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_2015 ||
479-
hid->product == USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_NUMPAD_2015)
479+
break;
480+
case USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_2015:
481+
case USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_NUMPAD_2015:
480482
table = magic_keyboard_2015_fn_keys;
481-
else if (hid->product == USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_2021 ||
482-
hid->product == USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_2024 ||
483-
hid->product == USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_FINGERPRINT_2021 ||
484-
hid->product == USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_NUMPAD_2021)
483+
break;
484+
case USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_2021:
485+
case USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_2024:
486+
case USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_FINGERPRINT_2021:
487+
case USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_NUMPAD_2021:
485488
table = apple2021_fn_keys;
486-
else if (hid->product == USB_DEVICE_ID_APPLE_WELLSPRINGT2_J132 ||
487-
hid->product == USB_DEVICE_ID_APPLE_WELLSPRINGT2_J680 ||
488-
hid->product == USB_DEVICE_ID_APPLE_WELLSPRINGT2_J213)
489-
table = macbookpro_no_esc_fn_keys;
490-
else if (hid->product == USB_DEVICE_ID_APPLE_WELLSPRINGT2_J214K ||
491-
hid->product == USB_DEVICE_ID_APPLE_WELLSPRINGT2_J223 ||
492-
hid->product == USB_DEVICE_ID_APPLE_WELLSPRINGT2_J152F)
493-
table = macbookpro_dedicated_esc_fn_keys;
494-
else if (hid->product == USB_DEVICE_ID_APPLE_WELLSPRINGT2_J140K ||
495-
hid->product == USB_DEVICE_ID_APPLE_WELLSPRINGT2_J230K)
496-
table = apple_fn_keys;
497-
else if (hid->product >= USB_DEVICE_ID_APPLE_WELLSPRING4_ANSI &&
498-
hid->product <= USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS)
499-
table = macbookair_fn_keys;
500-
else if (hid->product < 0x21d || hid->product >= 0x300)
501-
table = powerbook_fn_keys;
502-
else
489+
break;
490+
case USB_DEVICE_ID_APPLE_WELLSPRINGT2_J132:
491+
case USB_DEVICE_ID_APPLE_WELLSPRINGT2_J213:
492+
case USB_DEVICE_ID_APPLE_WELLSPRINGT2_J680:
493+
table = macbookpro_no_esc_fn_keys;
494+
break;
495+
case USB_DEVICE_ID_APPLE_WELLSPRINGT2_J152F:
496+
case USB_DEVICE_ID_APPLE_WELLSPRINGT2_J214K:
497+
case USB_DEVICE_ID_APPLE_WELLSPRINGT2_J223:
498+
table = macbookpro_dedicated_esc_fn_keys;
499+
break;
500+
case USB_DEVICE_ID_APPLE_WELLSPRINGT2_J140K:
501+
case USB_DEVICE_ID_APPLE_WELLSPRINGT2_J230K:
503502
table = apple_fn_keys;
503+
break;
504+
default:
505+
if (hid->product >= USB_DEVICE_ID_APPLE_WELLSPRING4_ANSI &&
506+
hid->product <= USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS)
507+
table = macbookair_fn_keys;
508+
else if (hid->product < 0x21d || hid->product >= 0x300)
509+
table = powerbook_fn_keys;
510+
else
511+
table = apple_fn_keys;
512+
}
504513

505514
trans = apple_find_translation(table, code);
506515

0 commit comments

Comments
 (0)