From patchwork Mon Mar 24 21:01:47 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antheas Kapenekakis X-Patchwork-Id: 14027819 Received: from linux1587.grserver.gr (linux1587.grserver.gr [185.138.42.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 04B1B1F0E40; Mon, 24 Mar 2025 21:02:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.138.42.100 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742850138; cv=none; b=iSyHmBUpZizVHO1lE8Fj6JSdMRtJ3GHALgenpTfGPTWDycXKbDYG75iwCdaWD9TCjzEq3M9ORsANHVy+iXnyhEMQ9RTVAc68UZdDZi1+aK/y9im8cX5ENsbb6Ly378UqP1T28imhs8M7DX1HOKWG+f1Ge+U4kyaDsLYA3JA8wjE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742850138; c=relaxed/simple; bh=m7WRcBMYwqQzDbW5k3TFYJLeNKK7cKjDPRlvGgH28vQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kzkBO272+M8v7ZN18xROXfFpPZLD2jV2wZMhxZn1slnTHfaE4Whkux8Z6WH8hl0X2sw4ygXaD2qQ9OkLofC9vp8y0XMqldCRsyXFBnxjW5GJ1RG2pEha/tPbr6xwvDXD3iGanS6jddFVxsY4EQMAnp0083mup5Uo3OIDbzJXXnM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=antheas.dev; spf=pass smtp.mailfrom=antheas.dev; dkim=pass (1024-bit key) header.d=antheas.dev header.i=@antheas.dev header.b=TscyDK6p; arc=none smtp.client-ip=185.138.42.100 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=antheas.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=antheas.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=antheas.dev header.i=@antheas.dev header.b="TscyDK6p" Received: from localhost.localdomain (unknown [IPv6:2a05:f6c2:511b:0:cbc0:999f:73ad:33bd]) by linux1587.grserver.gr (Postfix) with ESMTPSA id 4327B2E09D9D; Mon, 24 Mar 2025 23:02:13 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=antheas.dev; s=default; t=1742850134; bh=ZaQlexox+qAyhztZWBKe1B/QYiaU0VomN92g03HD1kI=; h=From:To:Subject; b=TscyDK6pVn7oXdcbE/7nIBczV3QjS/G4ItH6FoSooBzZtrBvJQbhGAAaUxeeI+JZK 2u4/SCmnCY1xeqJNJeWR4RRpUr27U/1oz83buLKhh0uKoWr/vvTdldb1zEoK/I5VRd zo90tgIgnhutz6JRdDPB2QTD9WQHVnvVOUFBq2gg= Authentication-Results: linux1587.grserver.gr; spf=pass (sender IP is 2a05:f6c2:511b:0:cbc0:999f:73ad:33bd) smtp.mailfrom=lkml@antheas.dev smtp.helo=localhost.localdomain Received-SPF: pass (linux1587.grserver.gr: connection is authenticated) From: Antheas Kapenekakis To: platform-driver-x86@vger.kernel.org, linux-input@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Jiri Kosina , Benjamin Tissoires , Corentin Chary , "Luke D . Jones" , Hans de Goede , =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Antheas Kapenekakis Subject: [PATCH v4 07/11] platform/x86: asus-wmi: add keyboard brightness event handler Date: Mon, 24 Mar 2025 22:01:47 +0100 Message-ID: <20250324210151.6042-8-lkml@antheas.dev> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250324210151.6042-1-lkml@antheas.dev> References: <20250324210151.6042-1-lkml@antheas.dev> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-PPP-Message-ID: <174285013444.23447.318626906308363703@linux1587.grserver.gr> X-PPP-Vhost: antheas.dev X-Virus-Scanned: clamav-milter 0.103.11 at linux1587.grserver.gr X-Virus-Status: Clean Currenlty, the keyboard brightness control of Asus WMI keyboards is handled in the kernel, which leads to the shortcut going from brightness 0, to 1, to 2, and 3. However, for HID keyboards it is exposed as a key and handled by the user's desktop environment. For the toggle button, this means that brightness control becomes on/off. In addition, in the absence of a DE, the keyboard brightness does not work. Therefore, expose an event handler for the keyboard brightness control which can then be used by hid-asus. Reviewed-by: Luke D. Jones Tested-by: Luke D. Jones Signed-off-by: Antheas Kapenekakis --- drivers/platform/x86/asus-wmi.c | 39 ++++++++++++++++++++++ include/linux/platform_data/x86/asus-wmi.h | 11 ++++++ 2 files changed, 50 insertions(+) diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c index ff1d7ccb3982f..27468d67dba09 100644 --- a/drivers/platform/x86/asus-wmi.c +++ b/drivers/platform/x86/asus-wmi.c @@ -1536,6 +1536,45 @@ void asus_hid_unregister_listener(struct asus_hid_listener *bdev) } EXPORT_SYMBOL_GPL(asus_hid_unregister_listener); +static void do_kbd_led_set(struct led_classdev *led_cdev, int value); + +int asus_hid_event(enum asus_hid_event event) +{ + unsigned long flags; + int brightness; + + spin_lock_irqsave(&asus_ref.lock, flags); + if (!asus_ref.asus || !asus_ref.asus->kbd_led_registered) { + spin_unlock_irqrestore(&asus_ref.lock, flags); + return -EBUSY; + } + brightness = asus_ref.asus->kbd_led_wk; + + switch (event) { + case ASUS_EV_BRTUP: + brightness += 1; + break; + case ASUS_EV_BRTDOWN: + brightness -= 1; + break; + case ASUS_EV_BRTTOGGLE: + if (brightness >= 3) + brightness = 0; + else + brightness += 1; + break; + } + + do_kbd_led_set(&asus_ref.asus->kbd_led, brightness); + led_classdev_notify_brightness_hw_changed(&asus_ref.asus->kbd_led, + asus_ref.asus->kbd_led_wk); + + spin_unlock_irqrestore(&asus_ref.lock, flags); + + return 0; +} +EXPORT_SYMBOL_GPL(asus_hid_event); + /* * These functions actually update the LED's, and are called from a * workqueue. By doing this as separate work rather than when the LED diff --git a/include/linux/platform_data/x86/asus-wmi.h b/include/linux/platform_data/x86/asus-wmi.h index c513b5a732323..9adbe8abef090 100644 --- a/include/linux/platform_data/x86/asus-wmi.h +++ b/include/linux/platform_data/x86/asus-wmi.h @@ -162,11 +162,18 @@ struct asus_hid_listener { void (*brightness_set)(struct asus_hid_listener *listener, int brightness); }; +enum asus_hid_event { + ASUS_EV_BRTUP, + ASUS_EV_BRTDOWN, + ASUS_EV_BRTTOGGLE, +}; + #if IS_REACHABLE(CONFIG_ASUS_WMI) int asus_wmi_evaluate_method(u32 method_id, u32 arg0, u32 arg1, u32 *retval); int asus_hid_register_listener(struct asus_hid_listener *cdev); void asus_hid_unregister_listener(struct asus_hid_listener *cdev); +int asus_hid_event(enum asus_hid_event event); #else static inline int asus_wmi_evaluate_method(u32 method_id, u32 arg0, u32 arg1, u32 *retval) @@ -181,6 +188,10 @@ static inline int asus_hid_register_listener(struct asus_hid_listener *bdev) static inline void asus_hid_unregister_listener(struct asus_hid_listener *bdev) { } +static inline int asus_hid_event(enum asus_hid_event event) +{ + return -ENODEV; +} #endif #endif /* __PLATFORM_DATA_X86_ASUS_WMI_H */