162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci *  USB HID quirks support for Linux
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci *  Copyright (c) 1999 Andreas Gal
662306a36Sopenharmony_ci *  Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz>
762306a36Sopenharmony_ci *  Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc
862306a36Sopenharmony_ci *  Copyright (c) 2006-2007 Jiri Kosina
962306a36Sopenharmony_ci *  Copyright (c) 2008 Jiri Slaby <jirislaby@gmail.com>
1062306a36Sopenharmony_ci *  Copyright (c) 2019 Paul Pawlowski <paul@mrarm.io>
1162306a36Sopenharmony_ci */
1262306a36Sopenharmony_ci
1362306a36Sopenharmony_ci/*
1462306a36Sopenharmony_ci */
1562306a36Sopenharmony_ci
1662306a36Sopenharmony_ci#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
1762306a36Sopenharmony_ci
1862306a36Sopenharmony_ci#include <linux/device.h>
1962306a36Sopenharmony_ci#include <linux/hid.h>
2062306a36Sopenharmony_ci#include <linux/jiffies.h>
2162306a36Sopenharmony_ci#include <linux/module.h>
2262306a36Sopenharmony_ci#include <linux/slab.h>
2362306a36Sopenharmony_ci#include <linux/timer.h>
2462306a36Sopenharmony_ci#include <linux/string.h>
2562306a36Sopenharmony_ci#include <linux/leds.h>
2662306a36Sopenharmony_ci
2762306a36Sopenharmony_ci#include "hid-ids.h"
2862306a36Sopenharmony_ci
2962306a36Sopenharmony_ci#define APPLE_RDESC_JIS		BIT(0)
3062306a36Sopenharmony_ci#define APPLE_IGNORE_MOUSE	BIT(1)
3162306a36Sopenharmony_ci#define APPLE_HAS_FN		BIT(2)
3262306a36Sopenharmony_ci/* BIT(3) reserved, was: APPLE_HIDDEV */
3362306a36Sopenharmony_ci#define APPLE_ISO_TILDE_QUIRK	BIT(4)
3462306a36Sopenharmony_ci#define APPLE_MIGHTYMOUSE	BIT(5)
3562306a36Sopenharmony_ci#define APPLE_INVERT_HWHEEL	BIT(6)
3662306a36Sopenharmony_ci/* BIT(7) reserved, was: APPLE_IGNORE_HIDINPUT */
3762306a36Sopenharmony_ci#define APPLE_NUMLOCK_EMULATION	BIT(8)
3862306a36Sopenharmony_ci#define APPLE_RDESC_BATTERY	BIT(9)
3962306a36Sopenharmony_ci#define APPLE_BACKLIGHT_CTL	BIT(10)
4062306a36Sopenharmony_ci#define APPLE_IS_NON_APPLE	BIT(11)
4162306a36Sopenharmony_ci
4262306a36Sopenharmony_ci#define APPLE_FLAG_FKEY		0x01
4362306a36Sopenharmony_ci
4462306a36Sopenharmony_ci#define HID_COUNTRY_INTERNATIONAL_ISO	13
4562306a36Sopenharmony_ci#define APPLE_BATTERY_TIMEOUT_MS	60000
4662306a36Sopenharmony_ci
4762306a36Sopenharmony_cistatic unsigned int fnmode = 3;
4862306a36Sopenharmony_cimodule_param(fnmode, uint, 0644);
4962306a36Sopenharmony_ciMODULE_PARM_DESC(fnmode, "Mode of fn key on Apple keyboards (0 = disabled, "
5062306a36Sopenharmony_ci		"1 = fkeyslast, 2 = fkeysfirst, [3] = auto)");
5162306a36Sopenharmony_ci
5262306a36Sopenharmony_cistatic int iso_layout = -1;
5362306a36Sopenharmony_cimodule_param(iso_layout, int, 0644);
5462306a36Sopenharmony_ciMODULE_PARM_DESC(iso_layout, "Swap the backtick/tilde and greater-than/less-than keys. "
5562306a36Sopenharmony_ci		"([-1] = auto, 0 = disabled, 1 = enabled)");
5662306a36Sopenharmony_ci
5762306a36Sopenharmony_cistatic unsigned int swap_opt_cmd;
5862306a36Sopenharmony_cimodule_param(swap_opt_cmd, uint, 0644);
5962306a36Sopenharmony_ciMODULE_PARM_DESC(swap_opt_cmd, "Swap the Option (\"Alt\") and Command (\"Flag\") keys. "
6062306a36Sopenharmony_ci		"(For people who want to keep Windows PC keyboard muscle memory. "
6162306a36Sopenharmony_ci		"[0] = as-is, Mac layout. 1 = swapped, Windows layout., 2 = swapped, Swap only left side)");
6262306a36Sopenharmony_ci
6362306a36Sopenharmony_cistatic unsigned int swap_ctrl_cmd;
6462306a36Sopenharmony_cimodule_param(swap_ctrl_cmd, uint, 0644);
6562306a36Sopenharmony_ciMODULE_PARM_DESC(swap_ctrl_cmd, "Swap the Control (\"Ctrl\") and Command (\"Flag\") keys. "
6662306a36Sopenharmony_ci		"(For people who are used to Mac shortcuts involving Command instead of Control. "
6762306a36Sopenharmony_ci		"[0] = No change. 1 = Swapped.)");
6862306a36Sopenharmony_ci
6962306a36Sopenharmony_cistatic unsigned int swap_fn_leftctrl;
7062306a36Sopenharmony_cimodule_param(swap_fn_leftctrl, uint, 0644);
7162306a36Sopenharmony_ciMODULE_PARM_DESC(swap_fn_leftctrl, "Swap the Fn and left Control keys. "
7262306a36Sopenharmony_ci		"(For people who want to keep PC keyboard muscle memory. "
7362306a36Sopenharmony_ci		"[0] = as-is, Mac layout, 1 = swapped, PC layout)");
7462306a36Sopenharmony_ci
7562306a36Sopenharmony_cistruct apple_non_apple_keyboard {
7662306a36Sopenharmony_ci	char *name;
7762306a36Sopenharmony_ci};
7862306a36Sopenharmony_ci
7962306a36Sopenharmony_cistruct apple_sc_backlight {
8062306a36Sopenharmony_ci	struct led_classdev cdev;
8162306a36Sopenharmony_ci	struct hid_device *hdev;
8262306a36Sopenharmony_ci	unsigned short backlight_off, backlight_on_min, backlight_on_max;
8362306a36Sopenharmony_ci};
8462306a36Sopenharmony_ci
8562306a36Sopenharmony_cistruct apple_sc {
8662306a36Sopenharmony_ci	struct hid_device *hdev;
8762306a36Sopenharmony_ci	unsigned long quirks;
8862306a36Sopenharmony_ci	unsigned int fn_on;
8962306a36Sopenharmony_ci	unsigned int fn_found;
9062306a36Sopenharmony_ci	DECLARE_BITMAP(pressed_numlock, KEY_CNT);
9162306a36Sopenharmony_ci	struct timer_list battery_timer;
9262306a36Sopenharmony_ci	struct apple_sc_backlight *backlight;
9362306a36Sopenharmony_ci};
9462306a36Sopenharmony_ci
9562306a36Sopenharmony_cistruct apple_key_translation {
9662306a36Sopenharmony_ci	u16 from;
9762306a36Sopenharmony_ci	u16 to;
9862306a36Sopenharmony_ci	u8 flags;
9962306a36Sopenharmony_ci};
10062306a36Sopenharmony_ci
10162306a36Sopenharmony_cistatic const struct apple_key_translation magic_keyboard_alu_fn_keys[] = {
10262306a36Sopenharmony_ci	{ KEY_BACKSPACE, KEY_DELETE },
10362306a36Sopenharmony_ci	{ KEY_ENTER,	KEY_INSERT },
10462306a36Sopenharmony_ci	{ KEY_F1,	KEY_BRIGHTNESSDOWN, APPLE_FLAG_FKEY },
10562306a36Sopenharmony_ci	{ KEY_F2,	KEY_BRIGHTNESSUP,   APPLE_FLAG_FKEY },
10662306a36Sopenharmony_ci	{ KEY_F3,	KEY_SCALE,          APPLE_FLAG_FKEY },
10762306a36Sopenharmony_ci	{ KEY_F4,	KEY_DASHBOARD,      APPLE_FLAG_FKEY },
10862306a36Sopenharmony_ci	{ KEY_F6,	KEY_NUMLOCK,        APPLE_FLAG_FKEY },
10962306a36Sopenharmony_ci	{ KEY_F7,	KEY_PREVIOUSSONG,   APPLE_FLAG_FKEY },
11062306a36Sopenharmony_ci	{ KEY_F8,	KEY_PLAYPAUSE,      APPLE_FLAG_FKEY },
11162306a36Sopenharmony_ci	{ KEY_F9,	KEY_NEXTSONG,       APPLE_FLAG_FKEY },
11262306a36Sopenharmony_ci	{ KEY_F10,	KEY_MUTE,           APPLE_FLAG_FKEY },
11362306a36Sopenharmony_ci	{ KEY_F11,	KEY_VOLUMEDOWN,     APPLE_FLAG_FKEY },
11462306a36Sopenharmony_ci	{ KEY_F12,	KEY_VOLUMEUP,       APPLE_FLAG_FKEY },
11562306a36Sopenharmony_ci	{ KEY_UP,	KEY_PAGEUP },
11662306a36Sopenharmony_ci	{ KEY_DOWN,	KEY_PAGEDOWN },
11762306a36Sopenharmony_ci	{ KEY_LEFT,	KEY_HOME },
11862306a36Sopenharmony_ci	{ KEY_RIGHT,	KEY_END },
11962306a36Sopenharmony_ci	{ }
12062306a36Sopenharmony_ci};
12162306a36Sopenharmony_ci
12262306a36Sopenharmony_cistatic const struct apple_key_translation magic_keyboard_2015_fn_keys[] = {
12362306a36Sopenharmony_ci	{ KEY_BACKSPACE, KEY_DELETE },
12462306a36Sopenharmony_ci	{ KEY_ENTER,	KEY_INSERT },
12562306a36Sopenharmony_ci	{ KEY_F1,	KEY_BRIGHTNESSDOWN, APPLE_FLAG_FKEY },
12662306a36Sopenharmony_ci	{ KEY_F2,	KEY_BRIGHTNESSUP,   APPLE_FLAG_FKEY },
12762306a36Sopenharmony_ci	{ KEY_F3,	KEY_SCALE,          APPLE_FLAG_FKEY },
12862306a36Sopenharmony_ci	{ KEY_F4,	KEY_DASHBOARD,      APPLE_FLAG_FKEY },
12962306a36Sopenharmony_ci	{ KEY_F7,	KEY_PREVIOUSSONG,   APPLE_FLAG_FKEY },
13062306a36Sopenharmony_ci	{ KEY_F8,	KEY_PLAYPAUSE,      APPLE_FLAG_FKEY },
13162306a36Sopenharmony_ci	{ KEY_F9,	KEY_NEXTSONG,       APPLE_FLAG_FKEY },
13262306a36Sopenharmony_ci	{ KEY_F10,	KEY_MUTE,           APPLE_FLAG_FKEY },
13362306a36Sopenharmony_ci	{ KEY_F11,	KEY_VOLUMEDOWN,     APPLE_FLAG_FKEY },
13462306a36Sopenharmony_ci	{ KEY_F12,	KEY_VOLUMEUP,       APPLE_FLAG_FKEY },
13562306a36Sopenharmony_ci	{ KEY_UP,	KEY_PAGEUP },
13662306a36Sopenharmony_ci	{ KEY_DOWN,	KEY_PAGEDOWN },
13762306a36Sopenharmony_ci	{ KEY_LEFT,	KEY_HOME },
13862306a36Sopenharmony_ci	{ KEY_RIGHT,	KEY_END },
13962306a36Sopenharmony_ci	{ }
14062306a36Sopenharmony_ci};
14162306a36Sopenharmony_ci
14262306a36Sopenharmony_cistruct apple_backlight_config_report {
14362306a36Sopenharmony_ci	u8 report_id;
14462306a36Sopenharmony_ci	u8 version;
14562306a36Sopenharmony_ci	u16 backlight_off, backlight_on_min, backlight_on_max;
14662306a36Sopenharmony_ci};
14762306a36Sopenharmony_ci
14862306a36Sopenharmony_cistruct apple_backlight_set_report {
14962306a36Sopenharmony_ci	u8 report_id;
15062306a36Sopenharmony_ci	u8 version;
15162306a36Sopenharmony_ci	u16 backlight;
15262306a36Sopenharmony_ci	u16 rate;
15362306a36Sopenharmony_ci};
15462306a36Sopenharmony_ci
15562306a36Sopenharmony_ci
15662306a36Sopenharmony_cistatic const struct apple_key_translation apple2021_fn_keys[] = {
15762306a36Sopenharmony_ci	{ KEY_BACKSPACE, KEY_DELETE },
15862306a36Sopenharmony_ci	{ KEY_ENTER,	KEY_INSERT },
15962306a36Sopenharmony_ci	{ KEY_F1,	KEY_BRIGHTNESSDOWN, APPLE_FLAG_FKEY },
16062306a36Sopenharmony_ci	{ KEY_F2,	KEY_BRIGHTNESSUP,   APPLE_FLAG_FKEY },
16162306a36Sopenharmony_ci	{ KEY_F3,	KEY_SCALE,          APPLE_FLAG_FKEY },
16262306a36Sopenharmony_ci	{ KEY_F4,	KEY_SEARCH,         APPLE_FLAG_FKEY },
16362306a36Sopenharmony_ci	{ KEY_F5,	KEY_MICMUTE,        APPLE_FLAG_FKEY },
16462306a36Sopenharmony_ci	{ KEY_F6,	KEY_SLEEP,          APPLE_FLAG_FKEY },
16562306a36Sopenharmony_ci	{ KEY_F7,	KEY_PREVIOUSSONG,   APPLE_FLAG_FKEY },
16662306a36Sopenharmony_ci	{ KEY_F8,	KEY_PLAYPAUSE,      APPLE_FLAG_FKEY },
16762306a36Sopenharmony_ci	{ KEY_F9,	KEY_NEXTSONG,       APPLE_FLAG_FKEY },
16862306a36Sopenharmony_ci	{ KEY_F10,	KEY_MUTE,           APPLE_FLAG_FKEY },
16962306a36Sopenharmony_ci	{ KEY_F11,	KEY_VOLUMEDOWN,     APPLE_FLAG_FKEY },
17062306a36Sopenharmony_ci	{ KEY_F12,	KEY_VOLUMEUP,       APPLE_FLAG_FKEY },
17162306a36Sopenharmony_ci	{ KEY_UP,	KEY_PAGEUP },
17262306a36Sopenharmony_ci	{ KEY_DOWN,	KEY_PAGEDOWN },
17362306a36Sopenharmony_ci	{ KEY_LEFT,	KEY_HOME },
17462306a36Sopenharmony_ci	{ KEY_RIGHT,	KEY_END },
17562306a36Sopenharmony_ci	{ }
17662306a36Sopenharmony_ci};
17762306a36Sopenharmony_ci
17862306a36Sopenharmony_cistatic const struct apple_key_translation macbookair_fn_keys[] = {
17962306a36Sopenharmony_ci	{ KEY_BACKSPACE, KEY_DELETE },
18062306a36Sopenharmony_ci	{ KEY_ENTER,	KEY_INSERT },
18162306a36Sopenharmony_ci	{ KEY_F1,	KEY_BRIGHTNESSDOWN, APPLE_FLAG_FKEY },
18262306a36Sopenharmony_ci	{ KEY_F2,	KEY_BRIGHTNESSUP,   APPLE_FLAG_FKEY },
18362306a36Sopenharmony_ci	{ KEY_F3,	KEY_SCALE,          APPLE_FLAG_FKEY },
18462306a36Sopenharmony_ci	{ KEY_F4,	KEY_DASHBOARD,      APPLE_FLAG_FKEY },
18562306a36Sopenharmony_ci	{ KEY_F6,	KEY_PREVIOUSSONG,   APPLE_FLAG_FKEY },
18662306a36Sopenharmony_ci	{ KEY_F7,	KEY_PLAYPAUSE,      APPLE_FLAG_FKEY },
18762306a36Sopenharmony_ci	{ KEY_F8,	KEY_NEXTSONG,       APPLE_FLAG_FKEY },
18862306a36Sopenharmony_ci	{ KEY_F9,	KEY_MUTE,           APPLE_FLAG_FKEY },
18962306a36Sopenharmony_ci	{ KEY_F10,	KEY_VOLUMEDOWN,     APPLE_FLAG_FKEY },
19062306a36Sopenharmony_ci	{ KEY_F11,	KEY_VOLUMEUP,       APPLE_FLAG_FKEY },
19162306a36Sopenharmony_ci	{ KEY_F12,	KEY_EJECTCD,        APPLE_FLAG_FKEY },
19262306a36Sopenharmony_ci	{ KEY_UP,	KEY_PAGEUP },
19362306a36Sopenharmony_ci	{ KEY_DOWN,	KEY_PAGEDOWN },
19462306a36Sopenharmony_ci	{ KEY_LEFT,	KEY_HOME },
19562306a36Sopenharmony_ci	{ KEY_RIGHT,	KEY_END },
19662306a36Sopenharmony_ci	{ }
19762306a36Sopenharmony_ci};
19862306a36Sopenharmony_ci
19962306a36Sopenharmony_cistatic const struct apple_key_translation macbookpro_no_esc_fn_keys[] = {
20062306a36Sopenharmony_ci	{ KEY_BACKSPACE, KEY_DELETE },
20162306a36Sopenharmony_ci	{ KEY_ENTER,	KEY_INSERT },
20262306a36Sopenharmony_ci	{ KEY_GRAVE,	KEY_ESC },
20362306a36Sopenharmony_ci	{ KEY_1,	KEY_F1 },
20462306a36Sopenharmony_ci	{ KEY_2,	KEY_F2 },
20562306a36Sopenharmony_ci	{ KEY_3,	KEY_F3 },
20662306a36Sopenharmony_ci	{ KEY_4,	KEY_F4 },
20762306a36Sopenharmony_ci	{ KEY_5,	KEY_F5 },
20862306a36Sopenharmony_ci	{ KEY_6,	KEY_F6 },
20962306a36Sopenharmony_ci	{ KEY_7,	KEY_F7 },
21062306a36Sopenharmony_ci	{ KEY_8,	KEY_F8 },
21162306a36Sopenharmony_ci	{ KEY_9,	KEY_F9 },
21262306a36Sopenharmony_ci	{ KEY_0,	KEY_F10 },
21362306a36Sopenharmony_ci	{ KEY_MINUS,	KEY_F11 },
21462306a36Sopenharmony_ci	{ KEY_EQUAL,	KEY_F12 },
21562306a36Sopenharmony_ci	{ KEY_UP,	KEY_PAGEUP },
21662306a36Sopenharmony_ci	{ KEY_DOWN,	KEY_PAGEDOWN },
21762306a36Sopenharmony_ci	{ KEY_LEFT,	KEY_HOME },
21862306a36Sopenharmony_ci	{ KEY_RIGHT,	KEY_END },
21962306a36Sopenharmony_ci	{ }
22062306a36Sopenharmony_ci};
22162306a36Sopenharmony_ci
22262306a36Sopenharmony_cistatic const struct apple_key_translation macbookpro_dedicated_esc_fn_keys[] = {
22362306a36Sopenharmony_ci	{ KEY_BACKSPACE, KEY_DELETE },
22462306a36Sopenharmony_ci	{ KEY_ENTER,	KEY_INSERT },
22562306a36Sopenharmony_ci	{ KEY_1,	KEY_F1 },
22662306a36Sopenharmony_ci	{ KEY_2,	KEY_F2 },
22762306a36Sopenharmony_ci	{ KEY_3,	KEY_F3 },
22862306a36Sopenharmony_ci	{ KEY_4,	KEY_F4 },
22962306a36Sopenharmony_ci	{ KEY_5,	KEY_F5 },
23062306a36Sopenharmony_ci	{ KEY_6,	KEY_F6 },
23162306a36Sopenharmony_ci	{ KEY_7,	KEY_F7 },
23262306a36Sopenharmony_ci	{ KEY_8,	KEY_F8 },
23362306a36Sopenharmony_ci	{ KEY_9,	KEY_F9 },
23462306a36Sopenharmony_ci	{ KEY_0,	KEY_F10 },
23562306a36Sopenharmony_ci	{ KEY_MINUS,	KEY_F11 },
23662306a36Sopenharmony_ci	{ KEY_EQUAL,	KEY_F12 },
23762306a36Sopenharmony_ci	{ KEY_UP,	KEY_PAGEUP },
23862306a36Sopenharmony_ci	{ KEY_DOWN,	KEY_PAGEDOWN },
23962306a36Sopenharmony_ci	{ KEY_LEFT,	KEY_HOME },
24062306a36Sopenharmony_ci	{ KEY_RIGHT,	KEY_END },
24162306a36Sopenharmony_ci	{ }
24262306a36Sopenharmony_ci};
24362306a36Sopenharmony_ci
24462306a36Sopenharmony_cistatic const struct apple_key_translation apple_fn_keys[] = {
24562306a36Sopenharmony_ci	{ KEY_BACKSPACE, KEY_DELETE },
24662306a36Sopenharmony_ci	{ KEY_ENTER,	KEY_INSERT },
24762306a36Sopenharmony_ci	{ KEY_F1,	KEY_BRIGHTNESSDOWN, APPLE_FLAG_FKEY },
24862306a36Sopenharmony_ci	{ KEY_F2,	KEY_BRIGHTNESSUP,   APPLE_FLAG_FKEY },
24962306a36Sopenharmony_ci	{ KEY_F3,	KEY_SCALE,          APPLE_FLAG_FKEY },
25062306a36Sopenharmony_ci	{ KEY_F4,	KEY_DASHBOARD,      APPLE_FLAG_FKEY },
25162306a36Sopenharmony_ci	{ KEY_F5,	KEY_KBDILLUMDOWN,   APPLE_FLAG_FKEY },
25262306a36Sopenharmony_ci	{ KEY_F6,	KEY_KBDILLUMUP,     APPLE_FLAG_FKEY },
25362306a36Sopenharmony_ci	{ KEY_F7,	KEY_PREVIOUSSONG,   APPLE_FLAG_FKEY },
25462306a36Sopenharmony_ci	{ KEY_F8,	KEY_PLAYPAUSE,      APPLE_FLAG_FKEY },
25562306a36Sopenharmony_ci	{ KEY_F9,	KEY_NEXTSONG,       APPLE_FLAG_FKEY },
25662306a36Sopenharmony_ci	{ KEY_F10,	KEY_MUTE,           APPLE_FLAG_FKEY },
25762306a36Sopenharmony_ci	{ KEY_F11,	KEY_VOLUMEDOWN,     APPLE_FLAG_FKEY },
25862306a36Sopenharmony_ci	{ KEY_F12,	KEY_VOLUMEUP,       APPLE_FLAG_FKEY },
25962306a36Sopenharmony_ci	{ KEY_UP,	KEY_PAGEUP },
26062306a36Sopenharmony_ci	{ KEY_DOWN,	KEY_PAGEDOWN },
26162306a36Sopenharmony_ci	{ KEY_LEFT,	KEY_HOME },
26262306a36Sopenharmony_ci	{ KEY_RIGHT,	KEY_END },
26362306a36Sopenharmony_ci	{ }
26462306a36Sopenharmony_ci};
26562306a36Sopenharmony_ci
26662306a36Sopenharmony_cistatic const struct apple_key_translation powerbook_fn_keys[] = {
26762306a36Sopenharmony_ci	{ KEY_BACKSPACE, KEY_DELETE },
26862306a36Sopenharmony_ci	{ KEY_F1,	KEY_BRIGHTNESSDOWN,     APPLE_FLAG_FKEY },
26962306a36Sopenharmony_ci	{ KEY_F2,	KEY_BRIGHTNESSUP,       APPLE_FLAG_FKEY },
27062306a36Sopenharmony_ci	{ KEY_F3,	KEY_MUTE,               APPLE_FLAG_FKEY },
27162306a36Sopenharmony_ci	{ KEY_F4,	KEY_VOLUMEDOWN,         APPLE_FLAG_FKEY },
27262306a36Sopenharmony_ci	{ KEY_F5,	KEY_VOLUMEUP,           APPLE_FLAG_FKEY },
27362306a36Sopenharmony_ci	{ KEY_F6,	KEY_NUMLOCK,            APPLE_FLAG_FKEY },
27462306a36Sopenharmony_ci	{ KEY_F7,	KEY_SWITCHVIDEOMODE,    APPLE_FLAG_FKEY },
27562306a36Sopenharmony_ci	{ KEY_F8,	KEY_KBDILLUMTOGGLE,     APPLE_FLAG_FKEY },
27662306a36Sopenharmony_ci	{ KEY_F9,	KEY_KBDILLUMDOWN,       APPLE_FLAG_FKEY },
27762306a36Sopenharmony_ci	{ KEY_F10,	KEY_KBDILLUMUP,         APPLE_FLAG_FKEY },
27862306a36Sopenharmony_ci	{ KEY_UP,	KEY_PAGEUP },
27962306a36Sopenharmony_ci	{ KEY_DOWN,	KEY_PAGEDOWN },
28062306a36Sopenharmony_ci	{ KEY_LEFT,	KEY_HOME },
28162306a36Sopenharmony_ci	{ KEY_RIGHT,	KEY_END },
28262306a36Sopenharmony_ci	{ }
28362306a36Sopenharmony_ci};
28462306a36Sopenharmony_ci
28562306a36Sopenharmony_cistatic const struct apple_key_translation powerbook_numlock_keys[] = {
28662306a36Sopenharmony_ci	{ KEY_J,	KEY_KP1 },
28762306a36Sopenharmony_ci	{ KEY_K,	KEY_KP2 },
28862306a36Sopenharmony_ci	{ KEY_L,	KEY_KP3 },
28962306a36Sopenharmony_ci	{ KEY_U,	KEY_KP4 },
29062306a36Sopenharmony_ci	{ KEY_I,	KEY_KP5 },
29162306a36Sopenharmony_ci	{ KEY_O,	KEY_KP6 },
29262306a36Sopenharmony_ci	{ KEY_7,	KEY_KP7 },
29362306a36Sopenharmony_ci	{ KEY_8,	KEY_KP8 },
29462306a36Sopenharmony_ci	{ KEY_9,	KEY_KP9 },
29562306a36Sopenharmony_ci	{ KEY_M,	KEY_KP0 },
29662306a36Sopenharmony_ci	{ KEY_DOT,	KEY_KPDOT },
29762306a36Sopenharmony_ci	{ KEY_SLASH,	KEY_KPPLUS },
29862306a36Sopenharmony_ci	{ KEY_SEMICOLON, KEY_KPMINUS },
29962306a36Sopenharmony_ci	{ KEY_P,	KEY_KPASTERISK },
30062306a36Sopenharmony_ci	{ KEY_MINUS,	KEY_KPEQUAL },
30162306a36Sopenharmony_ci	{ KEY_0,	KEY_KPSLASH },
30262306a36Sopenharmony_ci	{ KEY_F6,	KEY_NUMLOCK },
30362306a36Sopenharmony_ci	{ KEY_KPENTER,	KEY_KPENTER },
30462306a36Sopenharmony_ci	{ KEY_BACKSPACE, KEY_BACKSPACE },
30562306a36Sopenharmony_ci	{ }
30662306a36Sopenharmony_ci};
30762306a36Sopenharmony_ci
30862306a36Sopenharmony_cistatic const struct apple_key_translation apple_iso_keyboard[] = {
30962306a36Sopenharmony_ci	{ KEY_GRAVE,	KEY_102ND },
31062306a36Sopenharmony_ci	{ KEY_102ND,	KEY_GRAVE },
31162306a36Sopenharmony_ci	{ }
31262306a36Sopenharmony_ci};
31362306a36Sopenharmony_ci
31462306a36Sopenharmony_cistatic const struct apple_key_translation swapped_option_cmd_keys[] = {
31562306a36Sopenharmony_ci	{ KEY_LEFTALT,	KEY_LEFTMETA },
31662306a36Sopenharmony_ci	{ KEY_LEFTMETA,	KEY_LEFTALT },
31762306a36Sopenharmony_ci	{ KEY_RIGHTALT,	KEY_RIGHTMETA },
31862306a36Sopenharmony_ci	{ KEY_RIGHTMETA, KEY_RIGHTALT },
31962306a36Sopenharmony_ci	{ }
32062306a36Sopenharmony_ci};
32162306a36Sopenharmony_ci
32262306a36Sopenharmony_cistatic const struct apple_key_translation swapped_option_cmd_left_keys[] = {
32362306a36Sopenharmony_ci	{ KEY_LEFTALT,	KEY_LEFTMETA },
32462306a36Sopenharmony_ci	{ KEY_LEFTMETA,	KEY_LEFTALT },
32562306a36Sopenharmony_ci	{ }
32662306a36Sopenharmony_ci};
32762306a36Sopenharmony_ci
32862306a36Sopenharmony_cistatic const struct apple_key_translation swapped_ctrl_cmd_keys[] = {
32962306a36Sopenharmony_ci	{ KEY_LEFTCTRL,	KEY_LEFTMETA },
33062306a36Sopenharmony_ci	{ KEY_LEFTMETA,	KEY_LEFTCTRL },
33162306a36Sopenharmony_ci	{ KEY_RIGHTCTRL, KEY_RIGHTMETA },
33262306a36Sopenharmony_ci	{ KEY_RIGHTMETA, KEY_RIGHTCTRL },
33362306a36Sopenharmony_ci	{ }
33462306a36Sopenharmony_ci};
33562306a36Sopenharmony_ci
33662306a36Sopenharmony_cistatic const struct apple_key_translation swapped_fn_leftctrl_keys[] = {
33762306a36Sopenharmony_ci	{ KEY_FN, KEY_LEFTCTRL },
33862306a36Sopenharmony_ci	{ KEY_LEFTCTRL, KEY_FN },
33962306a36Sopenharmony_ci	{ }
34062306a36Sopenharmony_ci};
34162306a36Sopenharmony_ci
34262306a36Sopenharmony_cistatic const struct apple_non_apple_keyboard non_apple_keyboards[] = {
34362306a36Sopenharmony_ci	{ "SONiX USB DEVICE" },
34462306a36Sopenharmony_ci	{ "Keychron" },
34562306a36Sopenharmony_ci	{ "AONE" },
34662306a36Sopenharmony_ci	{ "GANSS" },
34762306a36Sopenharmony_ci	{ "Hailuck" },
34862306a36Sopenharmony_ci	{ "Jamesdonkey" },
34962306a36Sopenharmony_ci	{ "A3R" },
35062306a36Sopenharmony_ci};
35162306a36Sopenharmony_ci
35262306a36Sopenharmony_cistatic bool apple_is_non_apple_keyboard(struct hid_device *hdev)
35362306a36Sopenharmony_ci{
35462306a36Sopenharmony_ci	int i;
35562306a36Sopenharmony_ci
35662306a36Sopenharmony_ci	for (i = 0; i < ARRAY_SIZE(non_apple_keyboards); i++) {
35762306a36Sopenharmony_ci		char *non_apple = non_apple_keyboards[i].name;
35862306a36Sopenharmony_ci
35962306a36Sopenharmony_ci		if (strncmp(hdev->name, non_apple, strlen(non_apple)) == 0)
36062306a36Sopenharmony_ci			return true;
36162306a36Sopenharmony_ci	}
36262306a36Sopenharmony_ci
36362306a36Sopenharmony_ci	return false;
36462306a36Sopenharmony_ci}
36562306a36Sopenharmony_ci
36662306a36Sopenharmony_cistatic inline void apple_setup_key_translation(struct input_dev *input,
36762306a36Sopenharmony_ci		const struct apple_key_translation *table)
36862306a36Sopenharmony_ci{
36962306a36Sopenharmony_ci	const struct apple_key_translation *trans;
37062306a36Sopenharmony_ci
37162306a36Sopenharmony_ci	for (trans = table; trans->from; trans++)
37262306a36Sopenharmony_ci		set_bit(trans->to, input->keybit);
37362306a36Sopenharmony_ci}
37462306a36Sopenharmony_ci
37562306a36Sopenharmony_cistatic const struct apple_key_translation *apple_find_translation(
37662306a36Sopenharmony_ci		const struct apple_key_translation *table, u16 from)
37762306a36Sopenharmony_ci{
37862306a36Sopenharmony_ci	const struct apple_key_translation *trans;
37962306a36Sopenharmony_ci
38062306a36Sopenharmony_ci	/* Look for the translation */
38162306a36Sopenharmony_ci	for (trans = table; trans->from; trans++)
38262306a36Sopenharmony_ci		if (trans->from == from)
38362306a36Sopenharmony_ci			return trans;
38462306a36Sopenharmony_ci
38562306a36Sopenharmony_ci	return NULL;
38662306a36Sopenharmony_ci}
38762306a36Sopenharmony_ci
38862306a36Sopenharmony_cistatic void input_event_with_scancode(struct input_dev *input,
38962306a36Sopenharmony_ci		__u8 type, __u16 code, unsigned int hid, __s32 value)
39062306a36Sopenharmony_ci{
39162306a36Sopenharmony_ci	if (type == EV_KEY &&
39262306a36Sopenharmony_ci	    (!test_bit(code, input->key)) == value)
39362306a36Sopenharmony_ci		input_event(input, EV_MSC, MSC_SCAN, hid);
39462306a36Sopenharmony_ci	input_event(input, type, code, value);
39562306a36Sopenharmony_ci}
39662306a36Sopenharmony_ci
39762306a36Sopenharmony_cistatic int hidinput_apple_event(struct hid_device *hid, struct input_dev *input,
39862306a36Sopenharmony_ci		struct hid_usage *usage, __s32 value)
39962306a36Sopenharmony_ci{
40062306a36Sopenharmony_ci	struct apple_sc *asc = hid_get_drvdata(hid);
40162306a36Sopenharmony_ci	const struct apple_key_translation *trans, *table;
40262306a36Sopenharmony_ci	bool do_translate;
40362306a36Sopenharmony_ci	u16 code = usage->code;
40462306a36Sopenharmony_ci	unsigned int real_fnmode;
40562306a36Sopenharmony_ci
40662306a36Sopenharmony_ci	if (fnmode == 3) {
40762306a36Sopenharmony_ci		real_fnmode = (asc->quirks & APPLE_IS_NON_APPLE) ? 2 : 1;
40862306a36Sopenharmony_ci	} else {
40962306a36Sopenharmony_ci		real_fnmode = fnmode;
41062306a36Sopenharmony_ci	}
41162306a36Sopenharmony_ci
41262306a36Sopenharmony_ci	if (swap_fn_leftctrl) {
41362306a36Sopenharmony_ci		trans = apple_find_translation(swapped_fn_leftctrl_keys, code);
41462306a36Sopenharmony_ci
41562306a36Sopenharmony_ci		if (trans)
41662306a36Sopenharmony_ci			code = trans->to;
41762306a36Sopenharmony_ci	}
41862306a36Sopenharmony_ci
41962306a36Sopenharmony_ci	if (iso_layout > 0 || (iso_layout < 0 && (asc->quirks & APPLE_ISO_TILDE_QUIRK) &&
42062306a36Sopenharmony_ci			hid->country == HID_COUNTRY_INTERNATIONAL_ISO)) {
42162306a36Sopenharmony_ci		trans = apple_find_translation(apple_iso_keyboard, code);
42262306a36Sopenharmony_ci
42362306a36Sopenharmony_ci		if (trans)
42462306a36Sopenharmony_ci			code = trans->to;
42562306a36Sopenharmony_ci	}
42662306a36Sopenharmony_ci
42762306a36Sopenharmony_ci	if (swap_opt_cmd) {
42862306a36Sopenharmony_ci		if (swap_opt_cmd == 2)
42962306a36Sopenharmony_ci			trans = apple_find_translation(swapped_option_cmd_left_keys, code);
43062306a36Sopenharmony_ci		else
43162306a36Sopenharmony_ci			trans = apple_find_translation(swapped_option_cmd_keys, code);
43262306a36Sopenharmony_ci
43362306a36Sopenharmony_ci		if (trans)
43462306a36Sopenharmony_ci			code = trans->to;
43562306a36Sopenharmony_ci	}
43662306a36Sopenharmony_ci
43762306a36Sopenharmony_ci	if (swap_ctrl_cmd) {
43862306a36Sopenharmony_ci		trans = apple_find_translation(swapped_ctrl_cmd_keys, code);
43962306a36Sopenharmony_ci
44062306a36Sopenharmony_ci		if (trans)
44162306a36Sopenharmony_ci			code = trans->to;
44262306a36Sopenharmony_ci	}
44362306a36Sopenharmony_ci
44462306a36Sopenharmony_ci	if (code == KEY_FN)
44562306a36Sopenharmony_ci		asc->fn_on = !!value;
44662306a36Sopenharmony_ci
44762306a36Sopenharmony_ci	if (real_fnmode) {
44862306a36Sopenharmony_ci		if (hid->product == USB_DEVICE_ID_APPLE_ALU_WIRELESS_ANSI ||
44962306a36Sopenharmony_ci		    hid->product == USB_DEVICE_ID_APPLE_ALU_WIRELESS_ISO ||
45062306a36Sopenharmony_ci		    hid->product == USB_DEVICE_ID_APPLE_ALU_WIRELESS_JIS ||
45162306a36Sopenharmony_ci		    hid->product == USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ANSI ||
45262306a36Sopenharmony_ci		    hid->product == USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ISO ||
45362306a36Sopenharmony_ci		    hid->product == USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_JIS ||
45462306a36Sopenharmony_ci		    hid->product == USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ANSI ||
45562306a36Sopenharmony_ci		    hid->product == USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ISO ||
45662306a36Sopenharmony_ci		    hid->product == USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_JIS)
45762306a36Sopenharmony_ci			table = magic_keyboard_alu_fn_keys;
45862306a36Sopenharmony_ci		else if (hid->product == USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_2015 ||
45962306a36Sopenharmony_ci			 hid->product == USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_NUMPAD_2015)
46062306a36Sopenharmony_ci			table = magic_keyboard_2015_fn_keys;
46162306a36Sopenharmony_ci		else if (hid->product == USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_2021 ||
46262306a36Sopenharmony_ci			 hid->product == USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_FINGERPRINT_2021 ||
46362306a36Sopenharmony_ci			 hid->product == USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_NUMPAD_2021)
46462306a36Sopenharmony_ci			table = apple2021_fn_keys;
46562306a36Sopenharmony_ci		else if (hid->product == USB_DEVICE_ID_APPLE_WELLSPRINGT2_J132 ||
46662306a36Sopenharmony_ci			 hid->product == USB_DEVICE_ID_APPLE_WELLSPRINGT2_J680 ||
46762306a36Sopenharmony_ci			 hid->product == USB_DEVICE_ID_APPLE_WELLSPRINGT2_J213)
46862306a36Sopenharmony_ci				table = macbookpro_no_esc_fn_keys;
46962306a36Sopenharmony_ci		else if (hid->product == USB_DEVICE_ID_APPLE_WELLSPRINGT2_J214K ||
47062306a36Sopenharmony_ci			 hid->product == USB_DEVICE_ID_APPLE_WELLSPRINGT2_J223 ||
47162306a36Sopenharmony_ci			 hid->product == USB_DEVICE_ID_APPLE_WELLSPRINGT2_J152F)
47262306a36Sopenharmony_ci				table = macbookpro_dedicated_esc_fn_keys;
47362306a36Sopenharmony_ci		else if (hid->product == USB_DEVICE_ID_APPLE_WELLSPRINGT2_J140K ||
47462306a36Sopenharmony_ci			 hid->product == USB_DEVICE_ID_APPLE_WELLSPRINGT2_J230K)
47562306a36Sopenharmony_ci				table = apple_fn_keys;
47662306a36Sopenharmony_ci		else if (hid->product >= USB_DEVICE_ID_APPLE_WELLSPRING4_ANSI &&
47762306a36Sopenharmony_ci				hid->product <= USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS)
47862306a36Sopenharmony_ci			table = macbookair_fn_keys;
47962306a36Sopenharmony_ci		else if (hid->product < 0x21d || hid->product >= 0x300)
48062306a36Sopenharmony_ci			table = powerbook_fn_keys;
48162306a36Sopenharmony_ci		else
48262306a36Sopenharmony_ci			table = apple_fn_keys;
48362306a36Sopenharmony_ci
48462306a36Sopenharmony_ci		trans = apple_find_translation(table, code);
48562306a36Sopenharmony_ci
48662306a36Sopenharmony_ci		if (trans) {
48762306a36Sopenharmony_ci			bool from_is_set = test_bit(trans->from, input->key);
48862306a36Sopenharmony_ci			bool to_is_set = test_bit(trans->to, input->key);
48962306a36Sopenharmony_ci
49062306a36Sopenharmony_ci			if (from_is_set)
49162306a36Sopenharmony_ci				code = trans->from;
49262306a36Sopenharmony_ci			else if (to_is_set)
49362306a36Sopenharmony_ci				code = trans->to;
49462306a36Sopenharmony_ci
49562306a36Sopenharmony_ci			if (!(from_is_set || to_is_set)) {
49662306a36Sopenharmony_ci				if (trans->flags & APPLE_FLAG_FKEY) {
49762306a36Sopenharmony_ci					switch (real_fnmode) {
49862306a36Sopenharmony_ci					case 1:
49962306a36Sopenharmony_ci						do_translate = !asc->fn_on;
50062306a36Sopenharmony_ci						break;
50162306a36Sopenharmony_ci					case 2:
50262306a36Sopenharmony_ci						do_translate = asc->fn_on;
50362306a36Sopenharmony_ci						break;
50462306a36Sopenharmony_ci					default:
50562306a36Sopenharmony_ci						/* should never happen */
50662306a36Sopenharmony_ci						do_translate = false;
50762306a36Sopenharmony_ci					}
50862306a36Sopenharmony_ci				} else {
50962306a36Sopenharmony_ci					do_translate = asc->fn_on;
51062306a36Sopenharmony_ci				}
51162306a36Sopenharmony_ci
51262306a36Sopenharmony_ci				if (do_translate)
51362306a36Sopenharmony_ci					code = trans->to;
51462306a36Sopenharmony_ci			}
51562306a36Sopenharmony_ci		}
51662306a36Sopenharmony_ci
51762306a36Sopenharmony_ci		if (asc->quirks & APPLE_NUMLOCK_EMULATION &&
51862306a36Sopenharmony_ci				(test_bit(code, asc->pressed_numlock) ||
51962306a36Sopenharmony_ci				test_bit(LED_NUML, input->led))) {
52062306a36Sopenharmony_ci			trans = apple_find_translation(powerbook_numlock_keys, code);
52162306a36Sopenharmony_ci
52262306a36Sopenharmony_ci			if (trans) {
52362306a36Sopenharmony_ci				if (value)
52462306a36Sopenharmony_ci					set_bit(code, asc->pressed_numlock);
52562306a36Sopenharmony_ci				else
52662306a36Sopenharmony_ci					clear_bit(code, asc->pressed_numlock);
52762306a36Sopenharmony_ci
52862306a36Sopenharmony_ci				code = trans->to;
52962306a36Sopenharmony_ci			}
53062306a36Sopenharmony_ci		}
53162306a36Sopenharmony_ci	}
53262306a36Sopenharmony_ci
53362306a36Sopenharmony_ci	if (usage->code != code) {
53462306a36Sopenharmony_ci		input_event_with_scancode(input, usage->type, code, usage->hid, value);
53562306a36Sopenharmony_ci
53662306a36Sopenharmony_ci		return 1;
53762306a36Sopenharmony_ci	}
53862306a36Sopenharmony_ci
53962306a36Sopenharmony_ci	return 0;
54062306a36Sopenharmony_ci}
54162306a36Sopenharmony_ci
54262306a36Sopenharmony_cistatic int apple_event(struct hid_device *hdev, struct hid_field *field,
54362306a36Sopenharmony_ci		struct hid_usage *usage, __s32 value)
54462306a36Sopenharmony_ci{
54562306a36Sopenharmony_ci	struct apple_sc *asc = hid_get_drvdata(hdev);
54662306a36Sopenharmony_ci
54762306a36Sopenharmony_ci	if (!(hdev->claimed & HID_CLAIMED_INPUT) || !field->hidinput ||
54862306a36Sopenharmony_ci			!usage->type)
54962306a36Sopenharmony_ci		return 0;
55062306a36Sopenharmony_ci
55162306a36Sopenharmony_ci	if ((asc->quirks & APPLE_INVERT_HWHEEL) &&
55262306a36Sopenharmony_ci			usage->code == REL_HWHEEL) {
55362306a36Sopenharmony_ci		input_event_with_scancode(field->hidinput->input, usage->type,
55462306a36Sopenharmony_ci				usage->code, usage->hid, -value);
55562306a36Sopenharmony_ci		return 1;
55662306a36Sopenharmony_ci	}
55762306a36Sopenharmony_ci
55862306a36Sopenharmony_ci	if ((asc->quirks & APPLE_HAS_FN) &&
55962306a36Sopenharmony_ci			hidinput_apple_event(hdev, field->hidinput->input,
56062306a36Sopenharmony_ci				usage, value))
56162306a36Sopenharmony_ci		return 1;
56262306a36Sopenharmony_ci
56362306a36Sopenharmony_ci
56462306a36Sopenharmony_ci	return 0;
56562306a36Sopenharmony_ci}
56662306a36Sopenharmony_ci
56762306a36Sopenharmony_cistatic int apple_fetch_battery(struct hid_device *hdev)
56862306a36Sopenharmony_ci{
56962306a36Sopenharmony_ci#ifdef CONFIG_HID_BATTERY_STRENGTH
57062306a36Sopenharmony_ci	struct apple_sc *asc = hid_get_drvdata(hdev);
57162306a36Sopenharmony_ci	struct hid_report_enum *report_enum;
57262306a36Sopenharmony_ci	struct hid_report *report;
57362306a36Sopenharmony_ci
57462306a36Sopenharmony_ci	if (!(asc->quirks & APPLE_RDESC_BATTERY) || !hdev->battery)
57562306a36Sopenharmony_ci		return -1;
57662306a36Sopenharmony_ci
57762306a36Sopenharmony_ci	report_enum = &hdev->report_enum[hdev->battery_report_type];
57862306a36Sopenharmony_ci	report = report_enum->report_id_hash[hdev->battery_report_id];
57962306a36Sopenharmony_ci
58062306a36Sopenharmony_ci	if (!report || report->maxfield < 1)
58162306a36Sopenharmony_ci		return -1;
58262306a36Sopenharmony_ci
58362306a36Sopenharmony_ci	if (hdev->battery_capacity == hdev->battery_max)
58462306a36Sopenharmony_ci		return -1;
58562306a36Sopenharmony_ci
58662306a36Sopenharmony_ci	hid_hw_request(hdev, report, HID_REQ_GET_REPORT);
58762306a36Sopenharmony_ci	return 0;
58862306a36Sopenharmony_ci#else
58962306a36Sopenharmony_ci	return -1;
59062306a36Sopenharmony_ci#endif
59162306a36Sopenharmony_ci}
59262306a36Sopenharmony_ci
59362306a36Sopenharmony_cistatic void apple_battery_timer_tick(struct timer_list *t)
59462306a36Sopenharmony_ci{
59562306a36Sopenharmony_ci	struct apple_sc *asc = from_timer(asc, t, battery_timer);
59662306a36Sopenharmony_ci	struct hid_device *hdev = asc->hdev;
59762306a36Sopenharmony_ci
59862306a36Sopenharmony_ci	if (apple_fetch_battery(hdev) == 0) {
59962306a36Sopenharmony_ci		mod_timer(&asc->battery_timer,
60062306a36Sopenharmony_ci			  jiffies + msecs_to_jiffies(APPLE_BATTERY_TIMEOUT_MS));
60162306a36Sopenharmony_ci	}
60262306a36Sopenharmony_ci}
60362306a36Sopenharmony_ci
60462306a36Sopenharmony_ci/*
60562306a36Sopenharmony_ci * MacBook JIS keyboard has wrong logical maximum
60662306a36Sopenharmony_ci * Magic Keyboard JIS has wrong logical maximum
60762306a36Sopenharmony_ci */
60862306a36Sopenharmony_cistatic __u8 *apple_report_fixup(struct hid_device *hdev, __u8 *rdesc,
60962306a36Sopenharmony_ci		unsigned int *rsize)
61062306a36Sopenharmony_ci{
61162306a36Sopenharmony_ci	struct apple_sc *asc = hid_get_drvdata(hdev);
61262306a36Sopenharmony_ci
61362306a36Sopenharmony_ci	if(*rsize >=71 && rdesc[70] == 0x65 && rdesc[64] == 0x65) {
61462306a36Sopenharmony_ci		hid_info(hdev,
61562306a36Sopenharmony_ci			 "fixing up Magic Keyboard JIS report descriptor\n");
61662306a36Sopenharmony_ci		rdesc[64] = rdesc[70] = 0xe7;
61762306a36Sopenharmony_ci	}
61862306a36Sopenharmony_ci
61962306a36Sopenharmony_ci	if ((asc->quirks & APPLE_RDESC_JIS) && *rsize >= 60 &&
62062306a36Sopenharmony_ci			rdesc[53] == 0x65 && rdesc[59] == 0x65) {
62162306a36Sopenharmony_ci		hid_info(hdev,
62262306a36Sopenharmony_ci			 "fixing up MacBook JIS keyboard report descriptor\n");
62362306a36Sopenharmony_ci		rdesc[53] = rdesc[59] = 0xe7;
62462306a36Sopenharmony_ci	}
62562306a36Sopenharmony_ci
62662306a36Sopenharmony_ci	/*
62762306a36Sopenharmony_ci	 * Change the usage from:
62862306a36Sopenharmony_ci	 *   0x06, 0x00, 0xff, // Usage Page (Vendor Defined Page 1)  0
62962306a36Sopenharmony_ci	 *   0x09, 0x0b,       // Usage (Vendor Usage 0x0b)           3
63062306a36Sopenharmony_ci	 * To:
63162306a36Sopenharmony_ci	 *   0x05, 0x01,       // Usage Page (Generic Desktop)        0
63262306a36Sopenharmony_ci	 *   0x09, 0x06,       // Usage (Keyboard)                    2
63362306a36Sopenharmony_ci	 */
63462306a36Sopenharmony_ci	if ((asc->quirks & APPLE_RDESC_BATTERY) && *rsize == 83 &&
63562306a36Sopenharmony_ci	    rdesc[46] == 0x84 && rdesc[58] == 0x85) {
63662306a36Sopenharmony_ci		hid_info(hdev,
63762306a36Sopenharmony_ci			 "fixing up Magic Keyboard battery report descriptor\n");
63862306a36Sopenharmony_ci		*rsize = *rsize - 1;
63962306a36Sopenharmony_ci		rdesc = kmemdup(rdesc + 1, *rsize, GFP_KERNEL);
64062306a36Sopenharmony_ci		if (!rdesc)
64162306a36Sopenharmony_ci			return NULL;
64262306a36Sopenharmony_ci
64362306a36Sopenharmony_ci		rdesc[0] = 0x05;
64462306a36Sopenharmony_ci		rdesc[1] = 0x01;
64562306a36Sopenharmony_ci		rdesc[2] = 0x09;
64662306a36Sopenharmony_ci		rdesc[3] = 0x06;
64762306a36Sopenharmony_ci	}
64862306a36Sopenharmony_ci
64962306a36Sopenharmony_ci	return rdesc;
65062306a36Sopenharmony_ci}
65162306a36Sopenharmony_ci
65262306a36Sopenharmony_cistatic void apple_setup_input(struct input_dev *input)
65362306a36Sopenharmony_ci{
65462306a36Sopenharmony_ci	set_bit(KEY_NUMLOCK, input->keybit);
65562306a36Sopenharmony_ci
65662306a36Sopenharmony_ci	/* Enable all needed keys */
65762306a36Sopenharmony_ci	apple_setup_key_translation(input, apple_fn_keys);
65862306a36Sopenharmony_ci	apple_setup_key_translation(input, powerbook_fn_keys);
65962306a36Sopenharmony_ci	apple_setup_key_translation(input, powerbook_numlock_keys);
66062306a36Sopenharmony_ci	apple_setup_key_translation(input, apple_iso_keyboard);
66162306a36Sopenharmony_ci	apple_setup_key_translation(input, magic_keyboard_alu_fn_keys);
66262306a36Sopenharmony_ci	apple_setup_key_translation(input, magic_keyboard_2015_fn_keys);
66362306a36Sopenharmony_ci	apple_setup_key_translation(input, apple2021_fn_keys);
66462306a36Sopenharmony_ci	apple_setup_key_translation(input, macbookpro_no_esc_fn_keys);
66562306a36Sopenharmony_ci	apple_setup_key_translation(input, macbookpro_dedicated_esc_fn_keys);
66662306a36Sopenharmony_ci}
66762306a36Sopenharmony_ci
66862306a36Sopenharmony_cistatic int apple_input_mapping(struct hid_device *hdev, struct hid_input *hi,
66962306a36Sopenharmony_ci		struct hid_field *field, struct hid_usage *usage,
67062306a36Sopenharmony_ci		unsigned long **bit, int *max)
67162306a36Sopenharmony_ci{
67262306a36Sopenharmony_ci	struct apple_sc *asc = hid_get_drvdata(hdev);
67362306a36Sopenharmony_ci
67462306a36Sopenharmony_ci	if (usage->hid == (HID_UP_CUSTOM | 0x0003) ||
67562306a36Sopenharmony_ci			usage->hid == (HID_UP_MSVENDOR | 0x0003) ||
67662306a36Sopenharmony_ci			usage->hid == (HID_UP_HPVENDOR2 | 0x0003)) {
67762306a36Sopenharmony_ci		/* The fn key on Apple USB keyboards */
67862306a36Sopenharmony_ci		set_bit(EV_REP, hi->input->evbit);
67962306a36Sopenharmony_ci		hid_map_usage_clear(hi, usage, bit, max, EV_KEY, KEY_FN);
68062306a36Sopenharmony_ci		asc->fn_found = true;
68162306a36Sopenharmony_ci		apple_setup_input(hi->input);
68262306a36Sopenharmony_ci		return 1;
68362306a36Sopenharmony_ci	}
68462306a36Sopenharmony_ci
68562306a36Sopenharmony_ci	/* we want the hid layer to go through standard path (set and ignore) */
68662306a36Sopenharmony_ci	return 0;
68762306a36Sopenharmony_ci}
68862306a36Sopenharmony_ci
68962306a36Sopenharmony_cistatic int apple_input_mapped(struct hid_device *hdev, struct hid_input *hi,
69062306a36Sopenharmony_ci		struct hid_field *field, struct hid_usage *usage,
69162306a36Sopenharmony_ci		unsigned long **bit, int *max)
69262306a36Sopenharmony_ci{
69362306a36Sopenharmony_ci	struct apple_sc *asc = hid_get_drvdata(hdev);
69462306a36Sopenharmony_ci
69562306a36Sopenharmony_ci	if (asc->quirks & APPLE_MIGHTYMOUSE) {
69662306a36Sopenharmony_ci		if (usage->hid == HID_GD_Z)
69762306a36Sopenharmony_ci			hid_map_usage(hi, usage, bit, max, EV_REL, REL_HWHEEL);
69862306a36Sopenharmony_ci		else if (usage->code == BTN_1)
69962306a36Sopenharmony_ci			hid_map_usage(hi, usage, bit, max, EV_KEY, BTN_2);
70062306a36Sopenharmony_ci		else if (usage->code == BTN_2)
70162306a36Sopenharmony_ci			hid_map_usage(hi, usage, bit, max, EV_KEY, BTN_1);
70262306a36Sopenharmony_ci	}
70362306a36Sopenharmony_ci
70462306a36Sopenharmony_ci	return 0;
70562306a36Sopenharmony_ci}
70662306a36Sopenharmony_ci
70762306a36Sopenharmony_cistatic int apple_input_configured(struct hid_device *hdev,
70862306a36Sopenharmony_ci		struct hid_input *hidinput)
70962306a36Sopenharmony_ci{
71062306a36Sopenharmony_ci	struct apple_sc *asc = hid_get_drvdata(hdev);
71162306a36Sopenharmony_ci
71262306a36Sopenharmony_ci	if ((asc->quirks & APPLE_HAS_FN) && !asc->fn_found) {
71362306a36Sopenharmony_ci		hid_info(hdev, "Fn key not found (Apple Wireless Keyboard clone?), disabling Fn key handling\n");
71462306a36Sopenharmony_ci		asc->quirks &= ~APPLE_HAS_FN;
71562306a36Sopenharmony_ci	}
71662306a36Sopenharmony_ci
71762306a36Sopenharmony_ci	if (apple_is_non_apple_keyboard(hdev)) {
71862306a36Sopenharmony_ci		hid_info(hdev, "Non-apple keyboard detected; function keys will default to fnmode=2 behavior\n");
71962306a36Sopenharmony_ci		asc->quirks |= APPLE_IS_NON_APPLE;
72062306a36Sopenharmony_ci	}
72162306a36Sopenharmony_ci
72262306a36Sopenharmony_ci	return 0;
72362306a36Sopenharmony_ci}
72462306a36Sopenharmony_ci
72562306a36Sopenharmony_cistatic bool apple_backlight_check_support(struct hid_device *hdev)
72662306a36Sopenharmony_ci{
72762306a36Sopenharmony_ci	int i;
72862306a36Sopenharmony_ci	unsigned int hid;
72962306a36Sopenharmony_ci	struct hid_report *report;
73062306a36Sopenharmony_ci
73162306a36Sopenharmony_ci	list_for_each_entry(report, &hdev->report_enum[HID_INPUT_REPORT].report_list, list) {
73262306a36Sopenharmony_ci		for (i = 0; i < report->maxfield; i++) {
73362306a36Sopenharmony_ci			hid = report->field[i]->usage->hid;
73462306a36Sopenharmony_ci			if ((hid & HID_USAGE_PAGE) == HID_UP_MSVENDOR && (hid & HID_USAGE) == 0xf)
73562306a36Sopenharmony_ci				return true;
73662306a36Sopenharmony_ci		}
73762306a36Sopenharmony_ci	}
73862306a36Sopenharmony_ci
73962306a36Sopenharmony_ci	return false;
74062306a36Sopenharmony_ci}
74162306a36Sopenharmony_ci
74262306a36Sopenharmony_cistatic int apple_backlight_set(struct hid_device *hdev, u16 value, u16 rate)
74362306a36Sopenharmony_ci{
74462306a36Sopenharmony_ci	int ret = 0;
74562306a36Sopenharmony_ci	struct apple_backlight_set_report *rep;
74662306a36Sopenharmony_ci
74762306a36Sopenharmony_ci	rep = kmalloc(sizeof(*rep), GFP_KERNEL);
74862306a36Sopenharmony_ci	if (rep == NULL)
74962306a36Sopenharmony_ci		return -ENOMEM;
75062306a36Sopenharmony_ci
75162306a36Sopenharmony_ci	rep->report_id = 0xB0;
75262306a36Sopenharmony_ci	rep->version = 1;
75362306a36Sopenharmony_ci	rep->backlight = value;
75462306a36Sopenharmony_ci	rep->rate = rate;
75562306a36Sopenharmony_ci
75662306a36Sopenharmony_ci	ret = hid_hw_raw_request(hdev, 0xB0u, (u8 *) rep, sizeof(*rep),
75762306a36Sopenharmony_ci				 HID_OUTPUT_REPORT, HID_REQ_SET_REPORT);
75862306a36Sopenharmony_ci
75962306a36Sopenharmony_ci	kfree(rep);
76062306a36Sopenharmony_ci	return ret;
76162306a36Sopenharmony_ci}
76262306a36Sopenharmony_ci
76362306a36Sopenharmony_cistatic int apple_backlight_led_set(struct led_classdev *led_cdev,
76462306a36Sopenharmony_ci	enum led_brightness brightness)
76562306a36Sopenharmony_ci{
76662306a36Sopenharmony_ci	struct apple_sc_backlight *backlight = container_of(led_cdev,
76762306a36Sopenharmony_ci							    struct apple_sc_backlight, cdev);
76862306a36Sopenharmony_ci
76962306a36Sopenharmony_ci	return apple_backlight_set(backlight->hdev, brightness, 0);
77062306a36Sopenharmony_ci}
77162306a36Sopenharmony_ci
77262306a36Sopenharmony_cistatic int apple_backlight_init(struct hid_device *hdev)
77362306a36Sopenharmony_ci{
77462306a36Sopenharmony_ci	int ret;
77562306a36Sopenharmony_ci	struct apple_sc *asc = hid_get_drvdata(hdev);
77662306a36Sopenharmony_ci	struct apple_backlight_config_report *rep;
77762306a36Sopenharmony_ci
77862306a36Sopenharmony_ci	if (!apple_backlight_check_support(hdev))
77962306a36Sopenharmony_ci		return -EINVAL;
78062306a36Sopenharmony_ci
78162306a36Sopenharmony_ci	rep = kmalloc(0x200, GFP_KERNEL);
78262306a36Sopenharmony_ci	if (rep == NULL)
78362306a36Sopenharmony_ci		return -ENOMEM;
78462306a36Sopenharmony_ci
78562306a36Sopenharmony_ci	ret = hid_hw_raw_request(hdev, 0xBFu, (u8 *) rep, sizeof(*rep),
78662306a36Sopenharmony_ci				 HID_FEATURE_REPORT, HID_REQ_GET_REPORT);
78762306a36Sopenharmony_ci	if (ret < 0) {
78862306a36Sopenharmony_ci		hid_err(hdev, "backlight request failed: %d\n", ret);
78962306a36Sopenharmony_ci		goto cleanup_and_exit;
79062306a36Sopenharmony_ci	}
79162306a36Sopenharmony_ci	if (ret < 8 || rep->version != 1) {
79262306a36Sopenharmony_ci		hid_err(hdev, "backlight config struct: bad version %i\n", rep->version);
79362306a36Sopenharmony_ci		ret = -EINVAL;
79462306a36Sopenharmony_ci		goto cleanup_and_exit;
79562306a36Sopenharmony_ci	}
79662306a36Sopenharmony_ci
79762306a36Sopenharmony_ci	hid_dbg(hdev, "backlight config: off=%u, on_min=%u, on_max=%u\n",
79862306a36Sopenharmony_ci		rep->backlight_off, rep->backlight_on_min, rep->backlight_on_max);
79962306a36Sopenharmony_ci
80062306a36Sopenharmony_ci	asc->backlight = devm_kzalloc(&hdev->dev, sizeof(*asc->backlight), GFP_KERNEL);
80162306a36Sopenharmony_ci	if (!asc->backlight) {
80262306a36Sopenharmony_ci		ret = -ENOMEM;
80362306a36Sopenharmony_ci		goto cleanup_and_exit;
80462306a36Sopenharmony_ci	}
80562306a36Sopenharmony_ci
80662306a36Sopenharmony_ci	asc->backlight->hdev = hdev;
80762306a36Sopenharmony_ci	asc->backlight->cdev.name = "apple::kbd_backlight";
80862306a36Sopenharmony_ci	asc->backlight->cdev.max_brightness = rep->backlight_on_max;
80962306a36Sopenharmony_ci	asc->backlight->cdev.brightness_set_blocking = apple_backlight_led_set;
81062306a36Sopenharmony_ci
81162306a36Sopenharmony_ci	ret = apple_backlight_set(hdev, 0, 0);
81262306a36Sopenharmony_ci	if (ret < 0) {
81362306a36Sopenharmony_ci		hid_err(hdev, "backlight set request failed: %d\n", ret);
81462306a36Sopenharmony_ci		goto cleanup_and_exit;
81562306a36Sopenharmony_ci	}
81662306a36Sopenharmony_ci
81762306a36Sopenharmony_ci	ret = devm_led_classdev_register(&hdev->dev, &asc->backlight->cdev);
81862306a36Sopenharmony_ci
81962306a36Sopenharmony_cicleanup_and_exit:
82062306a36Sopenharmony_ci	kfree(rep);
82162306a36Sopenharmony_ci	return ret;
82262306a36Sopenharmony_ci}
82362306a36Sopenharmony_ci
82462306a36Sopenharmony_cistatic int apple_probe(struct hid_device *hdev,
82562306a36Sopenharmony_ci		const struct hid_device_id *id)
82662306a36Sopenharmony_ci{
82762306a36Sopenharmony_ci	unsigned long quirks = id->driver_data;
82862306a36Sopenharmony_ci	struct apple_sc *asc;
82962306a36Sopenharmony_ci	int ret;
83062306a36Sopenharmony_ci
83162306a36Sopenharmony_ci	asc = devm_kzalloc(&hdev->dev, sizeof(*asc), GFP_KERNEL);
83262306a36Sopenharmony_ci	if (asc == NULL) {
83362306a36Sopenharmony_ci		hid_err(hdev, "can't alloc apple descriptor\n");
83462306a36Sopenharmony_ci		return -ENOMEM;
83562306a36Sopenharmony_ci	}
83662306a36Sopenharmony_ci
83762306a36Sopenharmony_ci	asc->hdev = hdev;
83862306a36Sopenharmony_ci	asc->quirks = quirks;
83962306a36Sopenharmony_ci
84062306a36Sopenharmony_ci	hid_set_drvdata(hdev, asc);
84162306a36Sopenharmony_ci
84262306a36Sopenharmony_ci	ret = hid_parse(hdev);
84362306a36Sopenharmony_ci	if (ret) {
84462306a36Sopenharmony_ci		hid_err(hdev, "parse failed\n");
84562306a36Sopenharmony_ci		return ret;
84662306a36Sopenharmony_ci	}
84762306a36Sopenharmony_ci
84862306a36Sopenharmony_ci	ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
84962306a36Sopenharmony_ci	if (ret) {
85062306a36Sopenharmony_ci		hid_err(hdev, "hw start failed\n");
85162306a36Sopenharmony_ci		return ret;
85262306a36Sopenharmony_ci	}
85362306a36Sopenharmony_ci
85462306a36Sopenharmony_ci	timer_setup(&asc->battery_timer, apple_battery_timer_tick, 0);
85562306a36Sopenharmony_ci	mod_timer(&asc->battery_timer,
85662306a36Sopenharmony_ci		  jiffies + msecs_to_jiffies(APPLE_BATTERY_TIMEOUT_MS));
85762306a36Sopenharmony_ci	apple_fetch_battery(hdev);
85862306a36Sopenharmony_ci
85962306a36Sopenharmony_ci	if (quirks & APPLE_BACKLIGHT_CTL)
86062306a36Sopenharmony_ci		apple_backlight_init(hdev);
86162306a36Sopenharmony_ci
86262306a36Sopenharmony_ci	return 0;
86362306a36Sopenharmony_ci}
86462306a36Sopenharmony_ci
86562306a36Sopenharmony_cistatic void apple_remove(struct hid_device *hdev)
86662306a36Sopenharmony_ci{
86762306a36Sopenharmony_ci	struct apple_sc *asc = hid_get_drvdata(hdev);
86862306a36Sopenharmony_ci
86962306a36Sopenharmony_ci	del_timer_sync(&asc->battery_timer);
87062306a36Sopenharmony_ci
87162306a36Sopenharmony_ci	hid_hw_stop(hdev);
87262306a36Sopenharmony_ci}
87362306a36Sopenharmony_ci
87462306a36Sopenharmony_cistatic const struct hid_device_id apple_devices[] = {
87562306a36Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MIGHTYMOUSE),
87662306a36Sopenharmony_ci		.driver_data = APPLE_MIGHTYMOUSE | APPLE_INVERT_HWHEEL },
87762306a36Sopenharmony_ci
87862306a36Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI),
87962306a36Sopenharmony_ci		.driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
88062306a36Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ISO),
88162306a36Sopenharmony_ci		.driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
88262306a36Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ANSI),
88362306a36Sopenharmony_ci		.driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
88462306a36Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ISO),
88562306a36Sopenharmony_ci		.driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
88662306a36Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_JIS),
88762306a36Sopenharmony_ci		.driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
88862306a36Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ANSI),
88962306a36Sopenharmony_ci		.driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
89062306a36Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ISO),
89162306a36Sopenharmony_ci		.driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN |
89262306a36Sopenharmony_ci			APPLE_ISO_TILDE_QUIRK },
89362306a36Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_JIS),
89462306a36Sopenharmony_ci		.driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN |
89562306a36Sopenharmony_ci			APPLE_RDESC_JIS },
89662306a36Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ANSI),
89762306a36Sopenharmony_ci		.driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
89862306a36Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ISO),
89962306a36Sopenharmony_ci		.driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN |
90062306a36Sopenharmony_ci			APPLE_ISO_TILDE_QUIRK },
90162306a36Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_JIS),
90262306a36Sopenharmony_ci		.driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN |
90362306a36Sopenharmony_ci			APPLE_RDESC_JIS },
90462306a36Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_ANSI),
90562306a36Sopenharmony_ci		.driver_data = APPLE_HAS_FN },
90662306a36Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_ISO),
90762306a36Sopenharmony_ci		.driver_data = APPLE_HAS_FN },
90862306a36Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_JIS),
90962306a36Sopenharmony_ci		.driver_data = APPLE_HAS_FN },
91062306a36Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_ANSI),
91162306a36Sopenharmony_ci		.driver_data = APPLE_HAS_FN },
91262306a36Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_ISO),
91362306a36Sopenharmony_ci		.driver_data = APPLE_HAS_FN },
91462306a36Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_JIS),
91562306a36Sopenharmony_ci		.driver_data = APPLE_HAS_FN },
91662306a36Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ANSI),
91762306a36Sopenharmony_ci		.driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
91862306a36Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ISO),
91962306a36Sopenharmony_ci		.driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN |
92062306a36Sopenharmony_ci			APPLE_ISO_TILDE_QUIRK },
92162306a36Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_JIS),
92262306a36Sopenharmony_ci		.driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN |
92362306a36Sopenharmony_ci			APPLE_RDESC_JIS },
92462306a36Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_REVB_ANSI),
92562306a36Sopenharmony_ci		.driver_data = APPLE_HAS_FN },
92662306a36Sopenharmony_ci	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_REVB_ANSI),
92762306a36Sopenharmony_ci		.driver_data = APPLE_HAS_FN },
92862306a36Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_REVB_ISO),
92962306a36Sopenharmony_ci		.driver_data = APPLE_HAS_FN },
93062306a36Sopenharmony_ci	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_REVB_ISO),
93162306a36Sopenharmony_ci		.driver_data = APPLE_HAS_FN },
93262306a36Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_REVB_JIS),
93362306a36Sopenharmony_ci		.driver_data = APPLE_HAS_FN },
93462306a36Sopenharmony_ci	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_ANSI),
93562306a36Sopenharmony_ci		.driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
93662306a36Sopenharmony_ci	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_ISO),
93762306a36Sopenharmony_ci		.driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN |
93862306a36Sopenharmony_ci			APPLE_ISO_TILDE_QUIRK },
93962306a36Sopenharmony_ci	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ISO),
94062306a36Sopenharmony_ci		.driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN |
94162306a36Sopenharmony_ci			APPLE_ISO_TILDE_QUIRK },
94262306a36Sopenharmony_ci	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE,
94362306a36Sopenharmony_ci				USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ANSI),
94462306a36Sopenharmony_ci		.driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
94562306a36Sopenharmony_ci	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE,
94662306a36Sopenharmony_ci				USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_JIS),
94762306a36Sopenharmony_ci		.driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
94862306a36Sopenharmony_ci	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_JIS),
94962306a36Sopenharmony_ci		.driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
95062306a36Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_2015),
95162306a36Sopenharmony_ci		.driver_data = APPLE_HAS_FN | APPLE_ISO_TILDE_QUIRK | APPLE_RDESC_BATTERY },
95262306a36Sopenharmony_ci	{ HID_BLUETOOTH_DEVICE(BT_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_2015),
95362306a36Sopenharmony_ci		.driver_data = APPLE_HAS_FN | APPLE_ISO_TILDE_QUIRK },
95462306a36Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_NUMPAD_2015),
95562306a36Sopenharmony_ci		.driver_data = APPLE_HAS_FN | APPLE_ISO_TILDE_QUIRK | APPLE_RDESC_BATTERY },
95662306a36Sopenharmony_ci	{ HID_BLUETOOTH_DEVICE(BT_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_NUMPAD_2015),
95762306a36Sopenharmony_ci		.driver_data = APPLE_HAS_FN | APPLE_ISO_TILDE_QUIRK },
95862306a36Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ANSI),
95962306a36Sopenharmony_ci		.driver_data = APPLE_HAS_FN },
96062306a36Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ISO),
96162306a36Sopenharmony_ci		.driver_data = APPLE_HAS_FN | APPLE_ISO_TILDE_QUIRK },
96262306a36Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_JIS),
96362306a36Sopenharmony_ci		.driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
96462306a36Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ANSI),
96562306a36Sopenharmony_ci		.driver_data = APPLE_HAS_FN },
96662306a36Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ISO),
96762306a36Sopenharmony_ci		.driver_data = APPLE_HAS_FN | APPLE_ISO_TILDE_QUIRK },
96862306a36Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_JIS),
96962306a36Sopenharmony_ci		.driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
97062306a36Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ANSI),
97162306a36Sopenharmony_ci		.driver_data = APPLE_HAS_FN },
97262306a36Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ISO),
97362306a36Sopenharmony_ci		.driver_data = APPLE_HAS_FN | APPLE_ISO_TILDE_QUIRK },
97462306a36Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_JIS),
97562306a36Sopenharmony_ci		.driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
97662306a36Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ANSI),
97762306a36Sopenharmony_ci		.driver_data = APPLE_HAS_FN },
97862306a36Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ISO),
97962306a36Sopenharmony_ci		.driver_data = APPLE_HAS_FN | APPLE_ISO_TILDE_QUIRK },
98062306a36Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_JIS),
98162306a36Sopenharmony_ci		.driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
98262306a36Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ANSI),
98362306a36Sopenharmony_ci		.driver_data = APPLE_HAS_FN },
98462306a36Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ISO),
98562306a36Sopenharmony_ci		.driver_data = APPLE_HAS_FN | APPLE_ISO_TILDE_QUIRK },
98662306a36Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS),
98762306a36Sopenharmony_ci		.driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
98862306a36Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_ANSI),
98962306a36Sopenharmony_ci		.driver_data = APPLE_HAS_FN },
99062306a36Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_ISO),
99162306a36Sopenharmony_ci		.driver_data = APPLE_HAS_FN | APPLE_ISO_TILDE_QUIRK },
99262306a36Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_JIS),
99362306a36Sopenharmony_ci		.driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
99462306a36Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_ANSI),
99562306a36Sopenharmony_ci		.driver_data = APPLE_HAS_FN },
99662306a36Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_ISO),
99762306a36Sopenharmony_ci		.driver_data = APPLE_HAS_FN | APPLE_ISO_TILDE_QUIRK },
99862306a36Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_JIS),
99962306a36Sopenharmony_ci		.driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
100062306a36Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_ANSI),
100162306a36Sopenharmony_ci		.driver_data = APPLE_HAS_FN },
100262306a36Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_ISO),
100362306a36Sopenharmony_ci		.driver_data = APPLE_HAS_FN | APPLE_ISO_TILDE_QUIRK },
100462306a36Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_JIS),
100562306a36Sopenharmony_ci		.driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
100662306a36Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_ANSI),
100762306a36Sopenharmony_ci		.driver_data = APPLE_HAS_FN },
100862306a36Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_ISO),
100962306a36Sopenharmony_ci		.driver_data = APPLE_HAS_FN | APPLE_ISO_TILDE_QUIRK },
101062306a36Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_JIS),
101162306a36Sopenharmony_ci		.driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
101262306a36Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7_ANSI),
101362306a36Sopenharmony_ci		.driver_data = APPLE_HAS_FN },
101462306a36Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7_ISO),
101562306a36Sopenharmony_ci		.driver_data = APPLE_HAS_FN | APPLE_ISO_TILDE_QUIRK },
101662306a36Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7_JIS),
101762306a36Sopenharmony_ci		.driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
101862306a36Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7A_ANSI),
101962306a36Sopenharmony_ci		.driver_data = APPLE_HAS_FN },
102062306a36Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7A_ISO),
102162306a36Sopenharmony_ci		.driver_data = APPLE_HAS_FN | APPLE_ISO_TILDE_QUIRK },
102262306a36Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7A_JIS),
102362306a36Sopenharmony_ci		.driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
102462306a36Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING8_ANSI),
102562306a36Sopenharmony_ci		.driver_data = APPLE_HAS_FN },
102662306a36Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING8_ISO),
102762306a36Sopenharmony_ci		.driver_data = APPLE_HAS_FN | APPLE_ISO_TILDE_QUIRK },
102862306a36Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING8_JIS),
102962306a36Sopenharmony_ci		.driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
103062306a36Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING9_ANSI),
103162306a36Sopenharmony_ci		.driver_data = APPLE_HAS_FN },
103262306a36Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING9_ISO),
103362306a36Sopenharmony_ci		.driver_data = APPLE_HAS_FN | APPLE_ISO_TILDE_QUIRK },
103462306a36Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING9_JIS),
103562306a36Sopenharmony_ci		.driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
103662306a36Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRINGT2_J140K),
103762306a36Sopenharmony_ci		.driver_data = APPLE_HAS_FN | APPLE_BACKLIGHT_CTL | APPLE_ISO_TILDE_QUIRK },
103862306a36Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRINGT2_J132),
103962306a36Sopenharmony_ci		.driver_data = APPLE_HAS_FN | APPLE_BACKLIGHT_CTL | APPLE_ISO_TILDE_QUIRK },
104062306a36Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRINGT2_J680),
104162306a36Sopenharmony_ci		.driver_data = APPLE_HAS_FN | APPLE_BACKLIGHT_CTL | APPLE_ISO_TILDE_QUIRK },
104262306a36Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRINGT2_J213),
104362306a36Sopenharmony_ci		.driver_data = APPLE_HAS_FN | APPLE_BACKLIGHT_CTL | APPLE_ISO_TILDE_QUIRK },
104462306a36Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRINGT2_J214K),
104562306a36Sopenharmony_ci		.driver_data = APPLE_HAS_FN | APPLE_ISO_TILDE_QUIRK },
104662306a36Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRINGT2_J223),
104762306a36Sopenharmony_ci		.driver_data = APPLE_HAS_FN | APPLE_ISO_TILDE_QUIRK },
104862306a36Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRINGT2_J230K),
104962306a36Sopenharmony_ci		.driver_data = APPLE_HAS_FN | APPLE_ISO_TILDE_QUIRK },
105062306a36Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRINGT2_J152F),
105162306a36Sopenharmony_ci		.driver_data = APPLE_HAS_FN | APPLE_ISO_TILDE_QUIRK },
105262306a36Sopenharmony_ci	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ANSI),
105362306a36Sopenharmony_ci		.driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
105462306a36Sopenharmony_ci	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ISO),
105562306a36Sopenharmony_ci		.driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN |
105662306a36Sopenharmony_ci			APPLE_ISO_TILDE_QUIRK },
105762306a36Sopenharmony_ci	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_JIS),
105862306a36Sopenharmony_ci		.driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
105962306a36Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY),
106062306a36Sopenharmony_ci		.driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
106162306a36Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY),
106262306a36Sopenharmony_ci		.driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
106362306a36Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_2021),
106462306a36Sopenharmony_ci		.driver_data = APPLE_HAS_FN | APPLE_ISO_TILDE_QUIRK | APPLE_RDESC_BATTERY },
106562306a36Sopenharmony_ci	{ HID_BLUETOOTH_DEVICE(BT_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_2021),
106662306a36Sopenharmony_ci		.driver_data = APPLE_HAS_FN | APPLE_ISO_TILDE_QUIRK },
106762306a36Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_FINGERPRINT_2021),
106862306a36Sopenharmony_ci		.driver_data = APPLE_HAS_FN | APPLE_ISO_TILDE_QUIRK | APPLE_RDESC_BATTERY },
106962306a36Sopenharmony_ci	{ HID_BLUETOOTH_DEVICE(BT_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_FINGERPRINT_2021),
107062306a36Sopenharmony_ci		.driver_data = APPLE_HAS_FN | APPLE_ISO_TILDE_QUIRK },
107162306a36Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_NUMPAD_2021),
107262306a36Sopenharmony_ci		.driver_data = APPLE_HAS_FN | APPLE_ISO_TILDE_QUIRK | APPLE_RDESC_BATTERY },
107362306a36Sopenharmony_ci	{ HID_BLUETOOTH_DEVICE(BT_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_NUMPAD_2021),
107462306a36Sopenharmony_ci		.driver_data = APPLE_HAS_FN | APPLE_ISO_TILDE_QUIRK },
107562306a36Sopenharmony_ci
107662306a36Sopenharmony_ci	{ }
107762306a36Sopenharmony_ci};
107862306a36Sopenharmony_ciMODULE_DEVICE_TABLE(hid, apple_devices);
107962306a36Sopenharmony_ci
108062306a36Sopenharmony_cistatic struct hid_driver apple_driver = {
108162306a36Sopenharmony_ci	.name = "apple",
108262306a36Sopenharmony_ci	.id_table = apple_devices,
108362306a36Sopenharmony_ci	.report_fixup = apple_report_fixup,
108462306a36Sopenharmony_ci	.probe = apple_probe,
108562306a36Sopenharmony_ci	.remove = apple_remove,
108662306a36Sopenharmony_ci	.event = apple_event,
108762306a36Sopenharmony_ci	.input_mapping = apple_input_mapping,
108862306a36Sopenharmony_ci	.input_mapped = apple_input_mapped,
108962306a36Sopenharmony_ci	.input_configured = apple_input_configured,
109062306a36Sopenharmony_ci};
109162306a36Sopenharmony_cimodule_hid_driver(apple_driver);
109262306a36Sopenharmony_ci
109362306a36Sopenharmony_ciMODULE_LICENSE("GPL");
1094