Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *  Intel HID event & 5 button array driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *  Copyright (C) 2015 Alex Hung <alex.hung@canonical.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *  Copyright (C) 2015 Andrew Lutomirski <luto@kernel.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/acpi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/dmi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/input.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/input/sparse-keymap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/suspend.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) MODULE_AUTHOR("Alex Hung");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) static const struct acpi_device_id intel_hid_ids[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 	{"INT33D5", 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	{"INTC1051", 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	{"", 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) MODULE_DEVICE_TABLE(acpi, intel_hid_ids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) /* In theory, these are HID usages. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) static const struct key_entry intel_hid_keymap[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	/* 1: LSuper (Page 0x07, usage 0xE3) -- unclear what to do */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	/* 2: Toggle SW_ROTATE_LOCK -- easy to implement if seen in wild */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	{ KE_KEY, 3, { KEY_NUMLOCK } },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	{ KE_KEY, 4, { KEY_HOME } },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	{ KE_KEY, 5, { KEY_END } },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	{ KE_KEY, 6, { KEY_PAGEUP } },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	{ KE_KEY, 7, { KEY_PAGEDOWN } },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	{ KE_KEY, 8, { KEY_RFKILL } },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	{ KE_KEY, 9, { KEY_POWER } },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	{ KE_KEY, 11, { KEY_SLEEP } },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	/* 13 has two different meanings in the spec -- ignore it. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	{ KE_KEY, 14, { KEY_STOPCD } },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	{ KE_KEY, 15, { KEY_PLAYPAUSE } },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	{ KE_KEY, 16, { KEY_MUTE } },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	{ KE_KEY, 17, { KEY_VOLUMEUP } },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	{ KE_KEY, 18, { KEY_VOLUMEDOWN } },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	{ KE_KEY, 19, { KEY_BRIGHTNESSUP } },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	{ KE_KEY, 20, { KEY_BRIGHTNESSDOWN } },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	/* 27: wake -- needs special handling */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	{ KE_END },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) /* 5 button array notification value. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) static const struct key_entry intel_array_keymap[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	{ KE_KEY,    0xC2, { KEY_LEFTMETA } },                /* Press */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	{ KE_IGNORE, 0xC3, { KEY_LEFTMETA } },                /* Release */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	{ KE_KEY,    0xC4, { KEY_VOLUMEUP } },                /* Press */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	{ KE_IGNORE, 0xC5, { KEY_VOLUMEUP } },                /* Release */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	{ KE_KEY,    0xC6, { KEY_VOLUMEDOWN } },              /* Press */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	{ KE_IGNORE, 0xC7, { KEY_VOLUMEDOWN } },              /* Release */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	{ KE_KEY,    0xC8, { KEY_ROTATE_LOCK_TOGGLE } },      /* Press */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	{ KE_IGNORE, 0xC9, { KEY_ROTATE_LOCK_TOGGLE } },      /* Release */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	{ KE_KEY,    0xCE, { KEY_POWER } },                   /* Press */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	{ KE_IGNORE, 0xCF, { KEY_POWER } },                   /* Release */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	{ KE_END },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) static const struct dmi_system_id button_array_table[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 		.ident = "Wacom MobileStudio Pro 13",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 		.matches = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 			DMI_MATCH(DMI_SYS_VENDOR, "Wacom Co.,Ltd"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 			DMI_MATCH(DMI_PRODUCT_NAME, "Wacom MobileStudio Pro 13"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 		},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 		.ident = "Wacom MobileStudio Pro 16",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 		.matches = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 			DMI_MATCH(DMI_SYS_VENDOR, "Wacom Co.,Ltd"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 			DMI_MATCH(DMI_PRODUCT_NAME, "Wacom MobileStudio Pro 16"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 		},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 		.ident = "HP Spectre x2 (2015)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 		.matches = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 			DMI_MATCH(DMI_SYS_VENDOR, "HP"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 			DMI_MATCH(DMI_PRODUCT_NAME, "HP Spectre x2 Detachable"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 		},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		.ident = "Lenovo ThinkPad X1 Tablet Gen 2",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		.matches = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 			DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 			DMI_MATCH(DMI_PRODUCT_FAMILY, "ThinkPad X1 Tablet Gen 2"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	{ }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) struct intel_hid_priv {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	struct input_dev *input_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	struct input_dev *array;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	bool wakeup_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) #define HID_EVENT_FILTER_UUID	"eeec56b3-4442-408f-a792-4edd4d758054"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) enum intel_hid_dsm_fn_codes {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	INTEL_HID_DSM_FN_INVALID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	INTEL_HID_DSM_BTNL_FN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	INTEL_HID_DSM_HDMM_FN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	INTEL_HID_DSM_HDSM_FN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	INTEL_HID_DSM_HDEM_FN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	INTEL_HID_DSM_BTNS_FN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	INTEL_HID_DSM_BTNE_FN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	INTEL_HID_DSM_HEBC_V1_FN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	INTEL_HID_DSM_VGBS_FN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	INTEL_HID_DSM_HEBC_V2_FN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	INTEL_HID_DSM_FN_MAX
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) static const char *intel_hid_dsm_fn_to_method[INTEL_HID_DSM_FN_MAX] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	"BTNL",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	"HDMM",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	"HDSM",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	"HDEM",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	"BTNS",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	"BTNE",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	"HEBC",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	"VGBS",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	"HEBC"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) static unsigned long long intel_hid_dsm_fn_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) static guid_t intel_dsm_guid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) static bool intel_hid_execute_method(acpi_handle handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 				     enum intel_hid_dsm_fn_codes fn_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 				     unsigned long long arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	union acpi_object *obj, argv4, req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	char *method_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	if (fn_index <= INTEL_HID_DSM_FN_INVALID ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	    fn_index >= INTEL_HID_DSM_FN_MAX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	method_name = (char *)intel_hid_dsm_fn_to_method[fn_index];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	if (!(intel_hid_dsm_fn_mask & fn_index))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 		goto skip_dsm_exec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	/* All methods expects a package with one integer element */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	req.type = ACPI_TYPE_INTEGER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	req.integer.value = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	argv4.type = ACPI_TYPE_PACKAGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	argv4.package.count = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	argv4.package.elements = &req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	obj = acpi_evaluate_dsm(handle, &intel_dsm_guid, 1, fn_index, &argv4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	if (obj) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 		acpi_handle_debug(handle, "Exec DSM Fn code: %d[%s] success\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 				  fn_index, method_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 		ACPI_FREE(obj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 		return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) skip_dsm_exec:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	status = acpi_execute_simple_method(handle, method_name, arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	if (ACPI_SUCCESS(status))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 		return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) static bool intel_hid_evaluate_method(acpi_handle handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 				      enum intel_hid_dsm_fn_codes fn_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 				      unsigned long long *result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	union acpi_object *obj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	char *method_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	if (fn_index <= INTEL_HID_DSM_FN_INVALID ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	    fn_index >= INTEL_HID_DSM_FN_MAX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	method_name = (char *)intel_hid_dsm_fn_to_method[fn_index];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	if (!(intel_hid_dsm_fn_mask & fn_index))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 		goto skip_dsm_eval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	obj = acpi_evaluate_dsm_typed(handle, &intel_dsm_guid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 				      1, fn_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 				      NULL,  ACPI_TYPE_INTEGER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	if (obj) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 		*result = obj->integer.value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 		acpi_handle_debug(handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 				  "Eval DSM Fn code: %d[%s] results: 0x%llx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 				  fn_index, method_name, *result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 		ACPI_FREE(obj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) skip_dsm_eval:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	status = acpi_evaluate_integer(handle, method_name, NULL, result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	if (ACPI_SUCCESS(status))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 		return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) static void intel_hid_init_dsm(acpi_handle handle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	union acpi_object *obj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	guid_parse(HID_EVENT_FILTER_UUID, &intel_dsm_guid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	obj = acpi_evaluate_dsm_typed(handle, &intel_dsm_guid, 1, 0, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 				      ACPI_TYPE_BUFFER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	if (obj) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 		intel_hid_dsm_fn_mask = *obj->buffer.pointer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 		ACPI_FREE(obj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	acpi_handle_debug(handle, "intel_hid_dsm_fn_mask = %llx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 			  intel_hid_dsm_fn_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) static int intel_hid_set_enable(struct device *device, bool enable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	acpi_handle handle = ACPI_HANDLE(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	/* Enable|disable features - power button is always enabled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	if (!intel_hid_execute_method(handle, INTEL_HID_DSM_HDSM_FN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 				      enable)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 		dev_warn(device, "failed to %sable hotkeys\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 			 enable ? "en" : "dis");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) static void intel_button_array_enable(struct device *device, bool enable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	struct intel_hid_priv *priv = dev_get_drvdata(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	acpi_handle handle = ACPI_HANDLE(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	unsigned long long button_cap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	if (!priv->array)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	/* Query supported platform features */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	status = acpi_evaluate_integer(handle, "BTNC", NULL, &button_cap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 		dev_warn(device, "failed to get button capability\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	/* Enable|disable features - power button is always enabled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	if (!intel_hid_execute_method(handle, INTEL_HID_DSM_BTNE_FN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 				      enable ? button_cap : 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 		dev_warn(device, "failed to set button capability\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) static int intel_hid_pm_prepare(struct device *device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	if (device_may_wakeup(device)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 		struct intel_hid_priv *priv = dev_get_drvdata(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 		priv->wakeup_mode = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) static void intel_hid_pm_complete(struct device *device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	struct intel_hid_priv *priv = dev_get_drvdata(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	priv->wakeup_mode = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) static int intel_hid_pl_suspend_handler(struct device *device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	intel_button_array_enable(device, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	if (!pm_suspend_no_platform())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 		intel_hid_set_enable(device, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) static int intel_hid_pl_resume_handler(struct device *device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	intel_hid_pm_complete(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	if (!pm_suspend_no_platform())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 		intel_hid_set_enable(device, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	intel_button_array_enable(device, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) static const struct dev_pm_ops intel_hid_pl_pm_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	.prepare = intel_hid_pm_prepare,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	.complete = intel_hid_pm_complete,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	.freeze  = intel_hid_pl_suspend_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	.thaw  = intel_hid_pl_resume_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	.restore  = intel_hid_pl_resume_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	.suspend  = intel_hid_pl_suspend_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	.resume  = intel_hid_pl_resume_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) static int intel_hid_input_setup(struct platform_device *device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	struct intel_hid_priv *priv = dev_get_drvdata(&device->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 	priv->input_dev = devm_input_allocate_device(&device->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 	if (!priv->input_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	ret = sparse_keymap_setup(priv->input_dev, intel_hid_keymap, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	priv->input_dev->name = "Intel HID events";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	priv->input_dev->id.bustype = BUS_HOST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	return input_register_device(priv->input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) static int intel_button_array_input_setup(struct platform_device *device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 	struct intel_hid_priv *priv = dev_get_drvdata(&device->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	/* Setup input device for 5 button array */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	priv->array = devm_input_allocate_device(&device->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	if (!priv->array)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	ret = sparse_keymap_setup(priv->array, intel_array_keymap, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	priv->array->name = "Intel HID 5 button array";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 	priv->array->id.bustype = BUS_HOST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 	return input_register_device(priv->array);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) static void notify_handler(acpi_handle handle, u32 event, void *context)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 	struct platform_device *device = context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	struct intel_hid_priv *priv = dev_get_drvdata(&device->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	unsigned long long ev_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	if (priv->wakeup_mode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 		 * Needed for wakeup from suspend-to-idle to work on some
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 		 * platforms that don't expose the 5-button array, but still
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 		 * send notifies with the power button event code to this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 		 * device object on power button actions while suspended.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 		if (event == 0xce)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 			goto wakeup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 		/* Wake up on 5-button array events only. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 		if (event == 0xc0 || !priv->array)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 		if (!sparse_keymap_entry_from_scancode(priv->array, event)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 			dev_info(&device->dev, "unknown event 0x%x\n", event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) wakeup:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 		pm_wakeup_hard_event(&device->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 	 * Needed for suspend to work on some platforms that don't expose
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 	 * the 5-button array, but still send notifies with power button
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 	 * event code to this device object on power button actions.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 	 * Report the power button press and release.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 	if (!priv->array) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 		if (event == 0xce) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 			input_report_key(priv->input_dev, KEY_POWER, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 			input_sync(priv->input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 		if (event == 0xcf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 			input_report_key(priv->input_dev, KEY_POWER, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 			input_sync(priv->input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 	/* 0xC0 is for HID events, other values are for 5 button array */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 	if (event != 0xc0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 		if (!priv->array ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 		    !sparse_keymap_report_event(priv->array, event, 1, true))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 			dev_dbg(&device->dev, "unknown event 0x%x\n", event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 	if (!intel_hid_evaluate_method(handle, INTEL_HID_DSM_HDEM_FN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 				       &ev_index)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 		dev_warn(&device->dev, "failed to get event index\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 	if (!sparse_keymap_report_event(priv->input_dev, ev_index, 1, true))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 		dev_dbg(&device->dev, "unknown event index 0x%llx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 			 ev_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) static bool button_array_present(struct platform_device *device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 	acpi_handle handle = ACPI_HANDLE(&device->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 	unsigned long long event_cap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 	if (intel_hid_evaluate_method(handle, INTEL_HID_DSM_HEBC_V2_FN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 				      &event_cap)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 		/* Check presence of 5 button array or v2 power button */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 		if (event_cap & 0x60000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 			return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 	if (intel_hid_evaluate_method(handle, INTEL_HID_DSM_HEBC_V1_FN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 				      &event_cap)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 		if (event_cap & 0x20000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 			return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 	if (dmi_check_system(button_array_table))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 		return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 	return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) static int intel_hid_probe(struct platform_device *device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 	acpi_handle handle = ACPI_HANDLE(&device->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 	unsigned long long mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 	struct intel_hid_priv *priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 	acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 	intel_hid_init_dsm(handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 	if (!intel_hid_evaluate_method(handle, INTEL_HID_DSM_HDMM_FN, &mode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 		dev_warn(&device->dev, "failed to read mode\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 	if (mode != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 		 * This driver only implements "simple" mode.  There appear
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 		 * to be no other modes, but we should be paranoid and check
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 		 * for compatibility.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 		dev_info(&device->dev, "platform is not in simple mode\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 	priv = devm_kzalloc(&device->dev, sizeof(*priv), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 	if (!priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 	dev_set_drvdata(&device->dev, priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 	err = intel_hid_input_setup(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 		pr_err("Failed to setup Intel HID hotkeys\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 	/* Setup 5 button array */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 	if (button_array_present(device)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 		dev_info(&device->dev, "platform supports 5 button array\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 		err = intel_button_array_input_setup(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 			pr_err("Failed to setup Intel 5 button array hotkeys\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 	status = acpi_install_notify_handler(handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 					     ACPI_DEVICE_NOTIFY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 					     notify_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 					     device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 	if (ACPI_FAILURE(status))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 		return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 	err = intel_hid_set_enable(&device->dev, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 		goto err_remove_notify;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 	if (priv->array) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 		unsigned long long dummy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 		intel_button_array_enable(&device->dev, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 		/* Call button load method to enable HID power button */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 		if (!intel_hid_evaluate_method(handle, INTEL_HID_DSM_BTNL_FN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 					       &dummy)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 			dev_warn(&device->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 				 "failed to enable HID power button\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 	device_init_wakeup(&device->dev, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 	 * In order for system wakeup to work, the EC GPE has to be marked as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 	 * a wakeup one, so do that here (this setting will persist, but it has
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 	 * no effect until the wakeup mask is set for the EC GPE).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 	acpi_ec_mark_gpe_for_wake();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) err_remove_notify:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 	acpi_remove_notify_handler(handle, ACPI_DEVICE_NOTIFY, notify_handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) static int intel_hid_remove(struct platform_device *device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 	acpi_handle handle = ACPI_HANDLE(&device->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 	device_init_wakeup(&device->dev, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 	acpi_remove_notify_handler(handle, ACPI_DEVICE_NOTIFY, notify_handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 	intel_hid_set_enable(&device->dev, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) 	intel_button_array_enable(&device->dev, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 	 * Even if we failed to shut off the event stream, we can still
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) 	 * safely detach from the device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) static struct platform_driver intel_hid_pl_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) 		.name = "intel-hid",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) 		.acpi_match_table = intel_hid_ids,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) 		.pm = &intel_hid_pl_pm_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) 	.probe = intel_hid_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) 	.remove = intel_hid_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561)  * Unfortunately, some laptops provide a _HID="INT33D5" device with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562)  * _CID="PNP0C02".  This causes the pnpacpi scan driver to claim the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563)  * ACPI node, so no platform device will be created.  The pnpacpi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564)  * driver rejects this device in subsequent processing, so no physical
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565)  * node is created at all.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567)  * As a workaround until the ACPI core figures out how to handle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568)  * this corner case, manually ask the ACPI platform device code to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569)  * claim the ACPI node.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) static acpi_status __init
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) check_acpi_dev(acpi_handle handle, u32 lvl, void *context, void **rv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) 	const struct acpi_device_id *ids = context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) 	struct acpi_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) 	if (acpi_bus_get_device(handle, &dev) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) 		return AE_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) 	if (acpi_match_device_ids(dev, ids) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) 		if (!IS_ERR_OR_NULL(acpi_create_platform_device(dev, NULL)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) 			dev_info(&dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) 				 "intel-hid: created platform device\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) 	return AE_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) static int __init intel_hid_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) 	acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) 			    ACPI_UINT32_MAX, check_acpi_dev, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) 			    (void *)intel_hid_ids, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) 	return platform_driver_register(&intel_hid_pl_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) module_init(intel_hid_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) static void __exit intel_hid_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) 	platform_driver_unregister(&intel_hid_pl_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) module_exit(intel_hid_exit);