linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Luke D. Jones" <luke@ljones.dev>
To: linux-kernel@vger.kernel.org
Cc: linux-input@vger.kernel.org, bentiss@kernel.org,
	jikos@kernel.org, platform-driver-x86@vger.kernel.org,
	ilpo.jarvinen@linux.intel.com, hdegoede@redhat.com,
	corentin.chary@gmail.com, superm1@kernel.org,
	"Luke D. Jones" <luke@ljones.dev>
Subject: [PATCH v4 1/9] platform/x86: asus-wmi: export symbols used for read/write WMI
Date: Thu, 26 Sep 2024 21:29:44 +1200	[thread overview]
Message-ID: <20240926092952.1284435-2-luke@ljones.dev> (raw)
In-Reply-To: <20240926092952.1284435-1-luke@ljones.dev>

Export some rather helpful read/write WMI symbols using a namespace.
These are DEVS and DSTS only, or require the arg0 input.

Also does a slight refactor of internals of these functions.

Signed-off-by: Luke D. Jones <luke@ljones.dev>
---
 drivers/platform/x86/asus-wmi.c            | 51 ++++++++++++++++++++--
 include/linux/platform_data/x86/asus-wmi.h | 10 +++++
 2 files changed, 58 insertions(+), 3 deletions(-)

diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c
index 6725a27df62f..0a5221d65130 100644
--- a/drivers/platform/x86/asus-wmi.c
+++ b/drivers/platform/x86/asus-wmi.c
@@ -385,7 +385,7 @@ int asus_wmi_evaluate_method(u32 method_id, u32 arg0, u32 arg1, u32 *retval)
 {
 	return asus_wmi_evaluate_method3(method_id, arg0, arg1, 0, retval);
 }
-EXPORT_SYMBOL_GPL(asus_wmi_evaluate_method);
+EXPORT_SYMBOL_NS_GPL(asus_wmi_evaluate_method, ASUS_WMI);
 
 static int asus_wmi_evaluate_method5(u32 method_id,
 		u32 arg0, u32 arg1, u32 arg2, u32 arg3, u32 arg4, u32 *retval)
@@ -549,12 +549,57 @@ static int asus_wmi_get_devstate(struct asus_wmi *asus, u32 dev_id, u32 *retval)
 	return 0;
 }
 
-static int asus_wmi_set_devstate(u32 dev_id, u32 ctrl_param,
-				 u32 *retval)
+/**
+ * asus_wmi_get_devstate_dsts() - Get the WMI function state.
+ * @dev_id: The WMI function to call.
+ * @retval: A pointer to where to store the value returned from WMI.
+ *
+ * The returned WMI function state can also be used to determine if the WMI
+ * function is supported by checking if the asus_wmi_get_devstate_dsts()
+ * returns an error.
+ *
+ * On success the return value is 0, and the retval is a valid value returned
+ * by the successful WMI function call. An error value is returned only if the
+ * WMI function failed, or if it returns "unsupported" which is typically a 0
+ * (no return, and no 'supported' bit set), or a 0xFFFFFFFE (~1) which if not
+ * caught here can result in unexpected behaviour later.
+ */
+int asus_wmi_get_devstate_dsts(u32 dev_id, u32 *retval)
+{
+	int err;
+
+	err = asus_wmi_evaluate_method(ASUS_WMI_METHODID_DSTS, dev_id, 0, retval);
+	if (err)
+		return err;
+
+	*retval &= ~ASUS_WMI_DSTS_PRESENCE_BIT;
+	if (*retval == ASUS_WMI_UNSUPPORTED_METHOD)
+		return -ENODEV;
+
+	return 0;
+}
+EXPORT_SYMBOL_NS_GPL(asus_wmi_get_devstate_dsts, ASUS_WMI);
+
+/**
+ * asus_wmi_set_devstate() - Set the WMI function state.
+ * @dev_id: The WMI function to call.
+ * @ctrl_param: The argument to be used for this WMI function.
+ * @retval: A pointer to where to store the value returned from WMI.
+ *
+ * The returned WMI function state if not checked here for error as
+ * asus_wmi_set_devstate() is not called unless first paired with a call to
+ * asus_wmi_get_devstate_dsts() to check that the WMI function is supported.
+ *
+ * On success the return value is 0, and the retval is a valid value returned
+ * by the successful WMI function call. An error value is returned only if the
+ * WMI function failed.
+ */
+int asus_wmi_set_devstate(u32 dev_id, u32 ctrl_param, u32 *retval)
 {
 	return asus_wmi_evaluate_method(ASUS_WMI_METHODID_DEVS, dev_id,
 					ctrl_param, retval);
 }
+EXPORT_SYMBOL_NS_GPL(asus_wmi_set_devstate, ASUS_WMI);
 
 /* Helper for special devices with magic return codes */
 static int asus_wmi_get_devstate_bits(struct asus_wmi *asus,
diff --git a/include/linux/platform_data/x86/asus-wmi.h b/include/linux/platform_data/x86/asus-wmi.h
index 365e119bebaa..6ea4dedfb85e 100644
--- a/include/linux/platform_data/x86/asus-wmi.h
+++ b/include/linux/platform_data/x86/asus-wmi.h
@@ -158,8 +158,18 @@
 #define ASUS_WMI_DSTS_LIGHTBAR_MASK	0x0000000F
 
 #if IS_REACHABLE(CONFIG_ASUS_WMI)
+int asus_wmi_get_devstate_dsts(u32 dev_id, u32 *retval);
+int asus_wmi_set_devstate(u32 dev_id, u32 ctrl_param, u32 *retval);
 int asus_wmi_evaluate_method(u32 method_id, u32 arg0, u32 arg1, u32 *retval);
 #else
+static inline int asus_wmi_get_devstate_dsts(u32 dev_id, u32 *retval)
+{
+	return -ENODEV;
+}
+static inline int asus_wmi_set_devstate(u32 dev_id, u32 ctrl_param, u32 *retval)
+{
+	return -ENODEV;
+}
 static inline int asus_wmi_evaluate_method(u32 method_id, u32 arg0, u32 arg1,
 					   u32 *retval)
 {
-- 
2.46.1


  reply	other threads:[~2024-09-26  9:30 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-26  9:29 [PATCH v4 0/9] platform/x86: introduce asus-armoury driver Luke D. Jones
2024-09-26  9:29 ` Luke D. Jones [this message]
2024-09-26 15:26   ` [PATCH v4 1/9] platform/x86: asus-wmi: export symbols used for read/write WMI Mario Limonciello
2024-09-26  9:29 ` [PATCH v4 2/9] hid-asus: Add MODULE_IMPORT_NS(ASUS_WMI) Luke D. Jones
2024-09-26 11:54   ` Jiri Kosina
2024-09-26  9:29 ` [PATCH v4 3/9] platform/x86: asus-armoury: move existing tunings to asus-armoury module Luke D. Jones
2024-09-26 15:48   ` Mario Limonciello
2024-09-26 23:20     ` Luke Jones
2024-09-27 14:45       ` Mario Limonciello
2024-09-28  9:52         ` Luke Jones
2024-09-26 19:10   ` Markus Elfring
2024-09-26 21:50     ` Luke Jones
2024-09-27  6:09       ` [v4 " Markus Elfring
2024-09-27  7:05         ` Luke Jones
2024-09-27  7:24           ` Markus Elfring
2024-09-27  7:43             ` Luke Jones
2024-09-27  7:48               ` Julia Lawall
2024-09-26  9:29 ` [PATCH v4 4/9] platform/x86: asus-armoury: add panel_hd_mode attribute Luke D. Jones
2024-09-26 15:17   ` Mario Limonciello
2024-09-26 22:12     ` Luke Jones
2024-09-26  9:29 ` [PATCH v4 5/9] platform/x86: asus-armoury: add the ppt_* and nv_* tuning knobs Luke D. Jones
2024-09-26 15:22   ` Mario Limonciello
2024-09-26 22:39     ` Luke Jones
2024-09-26  9:29 ` [PATCH v4 6/9] platform/x86: asus-armoury: add dgpu tgp control Luke D. Jones
2024-09-26  9:29 ` [PATCH v4 7/9] platform/x86: asus-armoury: add apu-mem control support Luke D. Jones
2024-09-26 15:25   ` Mario Limonciello
2024-09-26 22:14     ` Luke Jones
2024-09-26  9:29 ` [PATCH v4 8/9] platform/x86: asus-armoury: add core count control Luke D. Jones
2024-09-26 15:30   ` Mario Limonciello
2024-09-26 21:47     ` Luke Jones
2024-09-26 22:02       ` Mario Limonciello
2024-09-29  7:00         ` Luke Jones
2024-09-26  9:29 ` [PATCH v4 9/9] platform/x86: asus-wmi: deprecate bios features Luke D. Jones
2024-09-26 14:56   ` Mario Limonciello
2024-09-26 22:04     ` Luke Jones
2024-09-28  0:13   ` kernel test robot
2024-09-28 21:02     ` Luke Jones
2024-09-26 14:50 ` [PATCH v4 0/9] platform/x86: introduce asus-armoury driver Mario Limonciello
2024-09-26 21:44   ` Luke Jones

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240926092952.1284435-2-luke@ljones.dev \
    --to=luke@ljones.dev \
    --cc=bentiss@kernel.org \
    --cc=corentin.chary@gmail.com \
    --cc=hdegoede@redhat.com \
    --cc=ilpo.jarvinen@linux.intel.com \
    --cc=jikos@kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=platform-driver-x86@vger.kernel.org \
    --cc=superm1@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).