Commit 33dc2efd authored by Hans de Goede's avatar Hans de Goede
Browse files

platform/x86: thinkpad_acpi: Make tpacpi_driver_event() return if it handled the event



tpacpi_driver_event() already only responds to hkey events which it knows
about. Make it return a bool and return true when it has handled the event.

This avoids the need to list TP_HKEY_EV_foo values to which it responds
both in its caller and in the function itself.

Instead callers can now call it unconditionally and check the return value.

Tested-by: default avatarMark Pearson <mpearson-lenovo@squebb.ca>
Signed-off-by: default avatarHans de Goede <hdegoede@redhat.com>
Reviewed-by: default avatarMark Pearson <mpearson-lenovo@squebb.ca>
Reviewed-by: default avatarIlpo Järvinen <ilpo.jarvinen@linux.intel.com>
Link: https://lore.kernel.org/r/20240424122834.19801-8-hdegoede@redhat.com
parent 9e5d6b98
Loading
Loading
Loading
Loading
+61 −54
Original line number Diff line number Diff line
@@ -1918,7 +1918,7 @@ static u32 hotkey_acpi_mask; /* events enabled in firmware */

static u16 *hotkey_keycode_map;

static void tpacpi_driver_event(const unsigned int hkey_event);
static bool tpacpi_driver_event(const unsigned int hkey_event);
static void hotkey_driver_event(const unsigned int scancode);
static void hotkey_poll_setup(const bool may_warn);

@@ -3726,13 +3726,8 @@ static bool adaptive_keyboard_hotkey_notify_hotkey(const u32 hkey)

static bool hotkey_notify_extended_hotkey(const u32 hkey)
{
	switch (hkey) {
	case TP_HKEY_EV_PRIVACYGUARD_TOGGLE:
	case TP_HKEY_EV_AMT_TOGGLE:
	case TP_HKEY_EV_PROFILE_TOGGLE:
		tpacpi_driver_event(hkey);
	if (tpacpi_driver_event(hkey))
		return true;
	}

	if (hkey >= TP_HKEY_EV_EXTENDED_KEY_START &&
	    hkey <= TP_HKEY_EV_EXTENDED_KEY_END) {
@@ -11081,24 +11076,28 @@ static struct platform_driver tpacpi_hwmon_pdriver = {
 * HKEY event callout for other subdrivers go here
 * (yes, it is ugly, but it is quick, safe, and gets the job done
 */
static void tpacpi_driver_event(const unsigned int hkey_event)
static bool tpacpi_driver_event(const unsigned int hkey_event)
{
	if (ibm_backlight_device) {
	switch (hkey_event) {
	case TP_HKEY_EV_BRGHT_UP:
	case TP_HKEY_EV_BRGHT_DOWN:
		if (ibm_backlight_device)
			tpacpi_brightness_notify_change();
		}
	}
	if (alsa_card) {
		switch (hkey_event) {
		/*
		 * Key press events are suppressed by default hotkey_user_mask
		 * and should still be reported if explicitly requested.
		 */
		return false;
	case TP_HKEY_EV_VOL_UP:
	case TP_HKEY_EV_VOL_DOWN:
	case TP_HKEY_EV_VOL_MUTE:
		if (alsa_card)
			volume_alsa_notify_change();
		}
	}
	if (tp_features.kbdlight && hkey_event == TP_HKEY_EV_KBD_LIGHT) {

		/* Key events are suppressed by default hotkey_user_mask */
		return false;
	case TP_HKEY_EV_KBD_LIGHT:
		if (tp_features.kbdlight) {
			enum led_brightness brightness;

			mutex_lock(&kbdlight_mutex);
@@ -11116,15 +11115,17 @@ static void tpacpi_driver_event(const unsigned int hkey_event)

			mutex_unlock(&kbdlight_mutex);
		}

	if (hkey_event == TP_HKEY_EV_THM_CSM_COMPLETED) {
		/* Key events are suppressed by default hotkey_user_mask */
		return false;
	case TP_HKEY_EV_THM_CSM_COMPLETED:
		lapsensor_refresh();
		/* If we are already accessing DYTC then skip dytc update */
		if (!atomic_add_unless(&dytc_ignore_event, -1, 0))
			dytc_profile_refresh();
	}

	if (lcdshadow_dev && hkey_event == TP_HKEY_EV_PRIVACYGUARD_TOGGLE) {
		return true;
	case TP_HKEY_EV_PRIVACYGUARD_TOGGLE:
		if (lcdshadow_dev) {
			enum drm_privacy_screen_status old_hw_state;
			bool changed;

@@ -11137,16 +11138,22 @@ static void tpacpi_driver_event(const unsigned int hkey_event)
			if (changed)
				drm_privacy_screen_call_notifier_chain(lcdshadow_dev);
		}
	if (hkey_event == TP_HKEY_EV_AMT_TOGGLE) {
		return true;
	case TP_HKEY_EV_AMT_TOGGLE:
		/* If we're enabling AMT we need to force balanced mode */
		if (!dytc_amt_active)
			/* This will also set AMT mode enabled */
			dytc_profile_set(NULL, PLATFORM_PROFILE_BALANCED);
		else
			dytc_control_amt(!dytc_amt_active);
	}
	if (hkey_event == TP_HKEY_EV_PROFILE_TOGGLE)

		return true;
	case TP_HKEY_EV_PROFILE_TOGGLE:
		platform_profile_cycle();
		return true;
	}

	return false;
}

static void hotkey_driver_event(const unsigned int scancode)