Commit 8abd752b authored by Yurii Pavlovskyi's avatar Yurii Pavlovskyi Committed by Andy Shevchenko
Browse files

platform/x86: asus-wmi: Refactor WMI event handling



Refactor WMI event handling into separate functions for getting the event
code and handling the retrieved event code as a preparation for
introduction of WMI event queue support.

Signed-off-by: default avatarYurii Pavlovskyi <yurii.pavlovskyi@gmail.com>
Signed-off-by: default avatarAndy Shevchenko <andriy.shevchenko@linux.intel.com>
parent e0668f28
Loading
Loading
Loading
Loading
+42 −24
Original line number Original line Diff line number Diff line
@@ -85,6 +85,8 @@ MODULE_LICENSE("GPL");


#define ASUS_ACPI_UID_ASUSWMI		"ASUSWMI"
#define ASUS_ACPI_UID_ASUSWMI		"ASUSWMI"


#define WMI_EVENT_MASK			0xFFFF

static const char * const ashs_ids[] = { "ATK4001", "ATK4002", NULL };
static const char * const ashs_ids[] = { "ATK4001", "ATK4002", NULL };


static bool ashs_present(void)
static bool ashs_present(void)
@@ -1651,83 +1653,99 @@ static void asus_wmi_fnlock_update(struct asus_wmi *asus)
	asus_wmi_set_devstate(ASUS_WMI_DEVID_FNLOCK, mode, NULL);
	asus_wmi_set_devstate(ASUS_WMI_DEVID_FNLOCK, mode, NULL);
}
}


static void asus_wmi_notify(u32 value, void *context)
static int asus_wmi_get_event_code(u32 value)
{
{
	struct asus_wmi *asus = context;
	struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
	struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
	union acpi_object *obj;
	union acpi_object *obj;
	acpi_status status;
	acpi_status status;
	int code;
	int code;
	int orig_code;
	unsigned int key_value = 1;
	bool autorelease = 1;


	status = wmi_get_event_data(value, &response);
	status = wmi_get_event_data(value, &response);
	if (status != AE_OK) {
	if (ACPI_FAILURE(status)) {
		pr_err("bad event status 0x%x\n", status);
		pr_warn("Failed to get WMI notify code: %s\n",
		return;
				acpi_format_exception(status));
		return -EIO;
	}
	}


	obj = (union acpi_object *)response.pointer;
	obj = (union acpi_object *)response.pointer;


	if (!obj || obj->type != ACPI_TYPE_INTEGER)
	if (obj && obj->type == ACPI_TYPE_INTEGER)
		goto exit;
		code = (int)(obj->integer.value & WMI_EVENT_MASK);
	else
		code = -EIO;

	kfree(obj);
	return code;
}

static void asus_wmi_handle_event_code(int code, struct asus_wmi *asus)
{
	int orig_code;
	unsigned int key_value = 1;
	bool autorelease = 1;


	code = obj->integer.value;
	orig_code = code;
	orig_code = code;


	if (asus->driver->key_filter) {
	if (asus->driver->key_filter) {
		asus->driver->key_filter(asus->driver, &code, &key_value,
		asus->driver->key_filter(asus->driver, &code, &key_value,
					 &autorelease);
					 &autorelease);
		if (code == ASUS_WMI_KEY_IGNORE)
		if (code == ASUS_WMI_KEY_IGNORE)
			goto exit;
			return;
	}
	}


	if (code >= NOTIFY_BRNUP_MIN && code <= NOTIFY_BRNUP_MAX)
	if (code >= NOTIFY_BRNUP_MIN && code <= NOTIFY_BRNUP_MAX)
		code = ASUS_WMI_BRN_UP;
		code = ASUS_WMI_BRN_UP;
	else if (code >= NOTIFY_BRNDOWN_MIN &&
	else if (code >= NOTIFY_BRNDOWN_MIN && code <= NOTIFY_BRNDOWN_MAX)
		 code <= NOTIFY_BRNDOWN_MAX)
		code = ASUS_WMI_BRN_DOWN;
		code = ASUS_WMI_BRN_DOWN;


	if (code == ASUS_WMI_BRN_DOWN || code == ASUS_WMI_BRN_UP) {
	if (code == ASUS_WMI_BRN_DOWN || code == ASUS_WMI_BRN_UP) {
		if (acpi_video_get_backlight_type() == acpi_backlight_vendor) {
		if (acpi_video_get_backlight_type() == acpi_backlight_vendor) {
			asus_wmi_backlight_notify(asus, orig_code);
			asus_wmi_backlight_notify(asus, orig_code);
			goto exit;
			return;
		}
		}
	}
	}


	if (code == NOTIFY_KBD_BRTUP) {
	if (code == NOTIFY_KBD_BRTUP) {
		kbd_led_set_by_kbd(asus, asus->kbd_led_wk + 1);
		kbd_led_set_by_kbd(asus, asus->kbd_led_wk + 1);
		goto exit;
		return;
	}
	}
	if (code == NOTIFY_KBD_BRTDWN) {
	if (code == NOTIFY_KBD_BRTDWN) {
		kbd_led_set_by_kbd(asus, asus->kbd_led_wk - 1);
		kbd_led_set_by_kbd(asus, asus->kbd_led_wk - 1);
		goto exit;
		return;
	}
	}
	if (code == NOTIFY_KBD_BRTTOGGLE) {
	if (code == NOTIFY_KBD_BRTTOGGLE) {
		if (asus->kbd_led_wk == asus->kbd_led.max_brightness)
		if (asus->kbd_led_wk == asus->kbd_led.max_brightness)
			kbd_led_set_by_kbd(asus, 0);
			kbd_led_set_by_kbd(asus, 0);
		else
		else
			kbd_led_set_by_kbd(asus, asus->kbd_led_wk + 1);
			kbd_led_set_by_kbd(asus, asus->kbd_led_wk + 1);
		goto exit;
		return;
	}
	}


	if (code == NOTIFY_FNLOCK_TOGGLE) {
	if (code == NOTIFY_FNLOCK_TOGGLE) {
		asus->fnlock_locked = !asus->fnlock_locked;
		asus->fnlock_locked = !asus->fnlock_locked;
		asus_wmi_fnlock_update(asus);
		asus_wmi_fnlock_update(asus);
		goto exit;
		return;
	}
	}


	if (is_display_toggle(code) &&
	if (is_display_toggle(code) && asus->driver->quirks->no_display_toggle)
	    asus->driver->quirks->no_display_toggle)
		return;
		goto exit;


	if (!sparse_keymap_report_event(asus->inputdev, code,
	if (!sparse_keymap_report_event(asus->inputdev, code,
					key_value, autorelease))
					key_value, autorelease))
		pr_info("Unknown key %x pressed\n", code);
		pr_info("Unknown key %x pressed\n", code);
}


exit:
static void asus_wmi_notify(u32 value, void *context)
	kfree(obj);
{
	struct asus_wmi *asus = context;
	int code = asus_wmi_get_event_code(value);

	if (code < 0) {
		pr_warn("Failed to get notify code: %d\n", code);
		return;
	}

	asus_wmi_handle_event_code(code, asus);
}
}


/*
/*