18 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
20 #include <linux/device.h>
21 #include <linux/hid.h>
22 #include <linux/module.h>
23 #include <linux/slab.h>
28 #define APPLE_RDESC_JIS 0x0001
29 #define APPLE_IGNORE_MOUSE 0x0002
30 #define APPLE_HAS_FN 0x0004
31 #define APPLE_HIDDEV 0x0008
32 #define APPLE_ISO_KEYBOARD 0x0010
33 #define APPLE_MIGHTYMOUSE 0x0020
34 #define APPLE_INVERT_HWHEEL 0x0040
35 #define APPLE_IGNORE_HIDINPUT 0x0080
36 #define APPLE_NUMLOCK_EMULATION 0x0100
38 #define APPLE_FLAG_FKEY 0x01
40 static unsigned int fnmode = 1;
43 "[1] = fkeyslast, 2 = fkeysfirst)");
45 static unsigned int iso_layout = 1;
47 MODULE_PARM_DESC(iso_layout,
"Enable/Disable hardcoded ISO-layout of the keyboard. "
48 "(0 = disabled, [1] = enabled)");
160 for (trans = table; trans->
from; trans++)
161 if (trans->
from == from)
167 static int hidinput_apple_event(
struct hid_device *hid,
struct input_dev *
input,
184 table = macbookair_fn_keys;
186 table = powerbook_fn_keys;
188 table = apple_fn_keys;
190 trans = apple_find_translation (table, usage->
code);
196 do_translate = (fnmode == 2 && asc->
fn_on) ||
197 (fnmode == 1 && !asc->
fn_on);
199 do_translate = asc->
fn_on;
217 trans = apple_find_translation(powerbook_numlock_keys,
223 asc->pressed_numlock);
226 asc->pressed_numlock);
238 trans = apple_find_translation(apple_iso_keyboard, usage->
code);
252 struct apple_sc *asc = hid_get_drvdata(hdev);
266 hidinput_apple_event(hdev, field->
hidinput->input,
280 struct apple_sc *asc = hid_get_drvdata(hdev);
283 rdesc[53] == 0x65 && rdesc[59] == 0x65) {
285 "fixing up MacBook JIS keyboard report descriptor\n");
286 rdesc[53] = rdesc[59] = 0xe7;
291 static void apple_setup_input(
struct input_dev *input)
298 for (trans = apple_fn_keys; trans->
from; trans++)
301 for (trans = powerbook_fn_keys; trans->
from; trans++)
304 for (trans = powerbook_numlock_keys; trans->
from; trans++)
307 for (trans = apple_iso_keyboard; trans->
from; trans++)
313 unsigned long **
bit,
int *
max)
318 hid_map_usage_clear(hi, usage, bit, max,
EV_KEY,
KEY_FN);
319 apple_setup_input(hi->
input);
329 unsigned long **bit,
int *max)
331 struct apple_sc *asc = hid_get_drvdata(hdev);
345 static int apple_probe(
struct hid_device *hdev,
348 unsigned long quirks =
id->driver_data;
355 hid_err(hdev,
"can't alloc apple descriptor\n");
361 hid_set_drvdata(hdev, asc);
363 ret = hid_parse(hdev);
365 hid_err(hdev,
"parse failed\n");
374 ret = hid_hw_start(hdev, connect_mask);
376 hid_err(hdev,
"hw start failed\n");
386 static void apple_remove(
struct hid_device *hdev)
389 kfree(hid_get_drvdata(hdev));
394 .driver_data = APPLE_HIDDEV | APPLE_IGNORE_HIDINPUT },
396 .driver_data = APPLE_HIDDEV | APPLE_IGNORE_HIDINPUT },
549 .id_table = apple_devices,
550 .report_fixup = apple_report_fixup,
551 .probe = apple_probe,
552 .remove = apple_remove,
553 .event = apple_event,
554 .input_mapping = apple_input_mapping,
555 .input_mapped = apple_input_mapped,
558 static int __init apple_init(
void)
564 pr_err(
"can't register apple driver\n");
569 static void __exit apple_exit(
void)