Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f23a5bcb authored by Bastien Nocera's avatar Bastien Nocera Committed by Darren Hart
Browse files

thinkpad_acpi: Remember adaptive kbd presence



Rather than checking on each suspend and resume whether the laptop
has an adaptive keyboard, check when the driver is initialised.

Signed-off-by: default avatarBastien Nocera <hadess@hadess.net>
Acked-by: default avatarHenrique de Moraes Holschuh <hmh@hmh.eng.br>
Signed-off-by: default avatarDarren Hart <dvhart@linux.intel.com>
parent c517d838
Loading
Loading
Loading
Loading
+18 −19
Original line number Original line Diff line number Diff line
@@ -319,6 +319,7 @@ static struct {
	u32 sensors_pdrv_attrs_registered:1;
	u32 sensors_pdrv_attrs_registered:1;
	u32 sensors_pdev_attrs_registered:1;
	u32 sensors_pdev_attrs_registered:1;
	u32 hotkey_poll_active:1;
	u32 hotkey_poll_active:1;
	u32 has_adaptive_kbd:1;
} tp_features;
} tp_features;


static struct {
static struct {
@@ -3227,6 +3228,15 @@ static int __init hotkey_init(struct ibm_init_struct *iibm)
	if (!tp_features.hotkey)
	if (!tp_features.hotkey)
		return 1;
		return 1;


	/*
	 * Check if we have an adaptive keyboard, like on the
	 * Lenovo Carbon X1 2014 (2nd Gen).
	 */
	if (acpi_evalf(hkey_handle, &hkeyv, "MHKV", "qd")) {
		if ((hkeyv >> 8) == 2)
			tp_features.has_adaptive_kbd = true;
	}

	quirks = tpacpi_check_quirks(tpacpi_hotkey_qtable,
	quirks = tpacpi_check_quirks(tpacpi_hotkey_qtable,
				     ARRAY_SIZE(tpacpi_hotkey_qtable));
				     ARRAY_SIZE(tpacpi_hotkey_qtable));


@@ -3836,28 +3846,21 @@ static void hotkey_notify(struct ibm_struct *ibm, u32 event)


static void hotkey_suspend(void)
static void hotkey_suspend(void)
{
{
	int hkeyv;

	/* Do these on suspend, we get the events on early resume! */
	/* Do these on suspend, we get the events on early resume! */
	hotkey_wakeup_reason = TP_ACPI_WAKEUP_NONE;
	hotkey_wakeup_reason = TP_ACPI_WAKEUP_NONE;
	hotkey_autosleep_ack = 0;
	hotkey_autosleep_ack = 0;


	/* save previous mode of adaptive keyboard of X1 Carbon */
	/* save previous mode of adaptive keyboard of X1 Carbon */
	if (acpi_evalf(hkey_handle, &hkeyv, "MHKV", "qd")) {
	if (tp_features.has_adaptive_kbd) {
		if ((hkeyv >> 8) == 2) {
		if (!acpi_evalf(hkey_handle, &adaptive_keyboard_prev_mode,
			if (!acpi_evalf(hkey_handle,
						&adaptive_keyboard_prev_mode,
					"GTRW", "dd", 0)) {
					"GTRW", "dd", 0)) {
			pr_err("Cannot read adaptive keyboard mode.\n");
			pr_err("Cannot read adaptive keyboard mode.\n");
		}
		}
	}
	}
}
}
}


static void hotkey_resume(void)
static void hotkey_resume(void)
{
{
	int hkeyv;

	tpacpi_disable_brightness_delay();
	tpacpi_disable_brightness_delay();


	if (hotkey_status_set(true) < 0 ||
	if (hotkey_status_set(true) < 0 ||
@@ -3872,17 +3875,13 @@ static void hotkey_resume(void)
	hotkey_poll_setup_safe(false);
	hotkey_poll_setup_safe(false);


	/* restore previous mode of adapive keyboard of X1 Carbon */
	/* restore previous mode of adapive keyboard of X1 Carbon */
	if (acpi_evalf(hkey_handle, &hkeyv, "MHKV", "qd")) {
	if (tp_features.has_adaptive_kbd) {
		if ((hkeyv >> 8) == 2) {
		if (!acpi_evalf(hkey_handle, NULL, "STRW", "vd",
			if (!acpi_evalf(hkey_handle,
						NULL,
						"STRW", "vd",
					adaptive_keyboard_prev_mode)) {
					adaptive_keyboard_prev_mode)) {
			pr_err("Cannot set adaptive keyboard mode.\n");
			pr_err("Cannot set adaptive keyboard mode.\n");
		}
		}
	}
	}
}
}
}


/* procfs -------------------------------------------------------------- */
/* procfs -------------------------------------------------------------- */
static int hotkey_read(struct seq_file *m)
static int hotkey_read(struct seq_file *m)