Skip to content

Commit f1d1b3a

Browse files
JoseExpositoJiri Kosina
authored andcommitted
HID: apple: Refactor key translation setup
The code used to map the apple_key_translation structs is duplicated. Extract it to a common function. Refactor, no functional changes. Signed-off-by: José Expósito <jose.exposito89@gmail.com> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
1 parent a254a9d commit f1d1b3a

1 file changed

Lines changed: 17 additions & 21 deletions

File tree

drivers/hid/hid-apple.c

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,15 @@ static const struct apple_key_translation swapped_fn_leftctrl_keys[] = {
202202
{ }
203203
};
204204

205+
static inline void apple_setup_key_translation(struct input_dev *input,
206+
const struct apple_key_translation *table)
207+
{
208+
const struct apple_key_translation *trans;
209+
210+
for (trans = table; trans->from; trans++)
211+
set_bit(trans->to, input->keybit);
212+
}
213+
205214
static const struct apple_key_translation *apple_find_translation(
206215
const struct apple_key_translation *table, u16 from)
207216
{
@@ -452,30 +461,17 @@ static __u8 *apple_report_fixup(struct hid_device *hdev, __u8 *rdesc,
452461

453462
static void apple_setup_input(struct input_dev *input)
454463
{
455-
const struct apple_key_translation *trans;
456-
457464
set_bit(KEY_NUMLOCK, input->keybit);
458465

459466
/* Enable all needed keys */
460-
for (trans = apple_fn_keys; trans->from; trans++)
461-
set_bit(trans->to, input->keybit);
462-
463-
for (trans = powerbook_fn_keys; trans->from; trans++)
464-
set_bit(trans->to, input->keybit);
465-
466-
for (trans = powerbook_numlock_keys; trans->from; trans++)
467-
set_bit(trans->to, input->keybit);
468-
469-
for (trans = apple_iso_keyboard; trans->from; trans++)
470-
set_bit(trans->to, input->keybit);
471-
472-
for (trans = apple2021_fn_keys; trans->from; trans++)
473-
set_bit(trans->to, input->keybit);
474-
475-
if (swap_fn_leftctrl) {
476-
for (trans = swapped_fn_leftctrl_keys; trans->from; trans++)
477-
set_bit(trans->to, input->keybit);
478-
}
467+
apple_setup_key_translation(input, apple_fn_keys);
468+
apple_setup_key_translation(input, powerbook_fn_keys);
469+
apple_setup_key_translation(input, powerbook_numlock_keys);
470+
apple_setup_key_translation(input, apple_iso_keyboard);
471+
apple_setup_key_translation(input, apple2021_fn_keys);
472+
473+
if (swap_fn_leftctrl)
474+
apple_setup_key_translation(input, swapped_fn_leftctrl_keys);
479475
}
480476

481477
static int apple_input_mapping(struct hid_device *hdev, struct hid_input *hi,

0 commit comments

Comments
 (0)