Skip to contentSkip to conversation

platform/x86: acer-wmi: Add helper functions for misc gaming settings

RFC PATCH New Armin Wolf 2 participants 2 messages Dec 29, 2024

Subsystems (2)
lore
Share & tools
lore

Armin Wolf

author
#0 lore raw

RFC PATCH 1/1 platform/x86: acer-wmi: Add helper functions for misc gaming settings

When getting and setting misc gaming settings, a special protocol needs to be observed according to the ACPI AML code.

Add helper functions for this.

---
This patch is intended to be used by Hridesh to improve the platform profile handling of the acer-wmi driver. Since he requested to work on the final patch himself i decided to mark this patch as an RFC since it is incomplete.

---
 drivers/platform/x86/acer-wmi.c | 93 +++++++++++++++++++++++++++++++++
 1 file changed, 93 insertions(+)
drivers/platform/x86/acer-wmi.c +93 -0
index b3043d78a7b3..a71fab88e8c6 100644
@@ -30,6 +30,7 @@
 #include <linux/input/sparse-keymap.h>
 #include <acpi/video.h>
 #include <linux/hwmon.h>
+#include <linux/unaligned.h>
 #include <linux/units.h>
 #include <linux/bitfield.h>
 
@@ -68,6 +69,7 @@ MODULE_LICENSE("GPL");
 #define ACER_WMID_GET_GAMING_SYS_INFO_METHODID 5
 #define ACER_WMID_SET_GAMING_FAN_BEHAVIOR 14
 #define ACER_WMID_SET_GAMING_MISC_SETTING_METHODID 22
+#define ACER_WMID_GET_GAMING_MISC_SETTING_METHODID 23
 
 #define ACER_PREDATOR_V4_THERMAL_PROFILE_EC_OFFSET 0x54
 
@@ -76,6 +78,10 @@ MODULE_LICENSE("GPL");
 #define ACER_PREDATOR_V4_SENSOR_READING_BIT_MASK GENMASK_ULL(23, 8)
 #define ACER_PREDATOR_V4_SUPPORTED_SENSORS_BIT_MASK GENMASK_ULL(39, 24)
 
+#define ACER_GAMING_MISC_SETTING_STATUS_MASK GENMASK_ULL(7, 0)
+#define ACER_GAMING_MISC_SETTING_INDEX_MASK GENMASK_ULL(7, 0)
+#define ACER_GAMING_MISC_SETTING_VALUE_MASK GENMASK_ULL(15, 8)
+
 /*
  * Acer ACPI method GUIDs
  */
@@ -115,6 +121,12 @@ enum acer_wmi_predator_v4_sensor_id {
 	ACER_WMID_SENSOR_GPU_TEMPERATURE	= 0x0A,
 };
 
+enum acer_wmi_gaming_misc_setting {
+	ACER_WMID_MISC_SETTING_OC_1			= 0x0005,
+	ACER_WMID_MISC_SETTING_OC_2			= 0x0007,
+	ACER_WMID_MISC_SETTING_PLATFORM_PROFILE		= 0x000B,
+};
+
 static const struct key_entry acer_wmi_keymap[] __initconst = {
 	{KE_KEY, 0x01, {KEY_WLAN} },     /* WiFi */
 	{KE_KEY, 0x03, {KEY_WLAN} },     /* WiFi */
@@ -1477,6 +1489,45 @@ WMI_gaming_execute_u64(u32 method_id, u64 in, u64 *out)
 	return status;
 }
 
+static int WMI_gaming_execute_u32_u64(u32 method_id, u32 in, u64 *out)
+{
+	struct acpi_buffer result = { ACPI_ALLOCATE_BUFFER, NULL };
+	struct acpi_buffer input = {
+		.length = sizeof(in),
+		.pointer = &in,
+	};
+	union acpi_object *obj;
+	acpi_status status;
+	int ret = 0;
+
+	status = wmi_evaluate_method(WMID_GUID4, 0, method_id, &input, &result);
+	if (ACPI_FAILURE(status))
+		return -EIO;
+
+	obj = result.pointer;
+	if (obj && out) {
+		switch (obj->type) {
+		case ACPI_TYPE_INTEGER:
+			*out = obj->integer.value;
+			break;
+		case ACPI_TYPE_BUFFER:
+			if (obj->buffer.length < sizeof(*out))
+				ret = -ENOMSG;
+			else
+				*out = get_unaligned_le64(obj->buffer.pointer);
+
+			break;
+		default:
+			ret = -ENOMSG;
+			break;
+		}
+	}
+
+	kfree(obj);
+
+	return ret;
+}
+
 static acpi_status WMID_gaming_set_u64(u64 value, u32 cap)
 {
 	u32 method_id = 0;
@@ -1544,6 +1595,48 @@ static int WMID_gaming_get_sys_info(u32 command, u64 *out)
 	return 0;
 }
 
+static int WMID_gaming_set_misc_setting(enum acer_wmi_gaming_misc_setting setting, u8 value)
+{
+	acpi_status status;
+	u64 input = 0;
+	u64 result;
+
+	input |= FIELD_PREP(ACER_GAMING_MISC_SETTING_INDEX_MASK, setting);
+	input |= FIELD_PREP(ACER_GAMING_MISC_SETTING_VALUE_MASK, value);
+
+	status = WMI_gaming_execute_u64(ACER_WMID_SET_GAMING_MISC_SETTING_METHODID, input, &result);
+	if (ACPI_FAILURE(status))
+		return -EIO;
+
+	/* The return status must be zero for the operation to have succeeded */
+	if (FIELD_GET(ACER_GAMING_MISC_SETTING_STATUS_MASK, result))
+		return -EIO;
+
+	return 0;
+}
+
+static int WMID_gaming_get_misc_setting(enum acer_wmi_gaming_misc_setting setting, u8 *value)
+{
+	u64 input = 0;
+	u64 result;
+	int ret;
+
+	input |= FIELD_PREP(ACER_GAMING_MISC_SETTING_INDEX_MASK, setting);
+
+	ret = WMI_gaming_execute_u32_u64(ACER_WMID_GET_GAMING_MISC_SETTING_METHODID, input,
+					 &result);
+	if (ret < 0)
+		return ret;
+
+	/* The return status must be zero for the operation to have succeeded */
+	if (FIELD_GET(ACER_GAMING_MISC_SETTING_STATUS_MASK, result))
+		return -EIO;
+
+	*value = FIELD_GET(ACER_GAMING_MISC_SETTING_VALUE_MASK, result);
+
+	return 0;
+}
+
 static void WMID_gaming_set_fan_mode(u8 fan_mode)
 {
 	/* fan_mode = 1 is used for auto, fan_mode = 2 used for turbo*/

--
2.39.5

#1 lore raw
kernel test robot noticed the following build warnings:

Hi Armin,

[This is a private test report for your RFC patch.] kernel test robot noticed the following build warnings:

[auto build test WARNING on next-20241220]
[cannot apply to linus/master v6.13-rc4 v6.13-rc3 v6.13-rc2 v6.13-rc4] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Armin-Wolf/platform-x86-acer-wmi-Add-helper-functions-for-misc-gaming-settings/20241229-081405
base:   next-20241220
patch link:    https://lore.kernel.org/r/20241229001308.10064-1-W_Armin%40gmx.de
patch subject: [RFC PATCH] platform/x86: acer-wmi: Add helper functions for misc gaming settings
config: x86_64-buildonly-randconfig-002-20241229 (https://download.01.org/0day-ci/archive/20241229/[email protected]/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241229/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

>> drivers/platform/x86/acer-wmi.c:1618:12: warning: 'WMID_gaming_get_misc_setting' defined but not used [-Wunused-function]
    1618 | static int WMID_gaming_get_misc_setting(enum acer_wmi_gaming_misc_setting setting, u8 *value)
         |            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> drivers/platform/x86/acer-wmi.c:1598:12: warning: 'WMID_gaming_set_misc_setting' defined but not used [-Wunused-function]

1598 | static int WMID_gaming_set_misc_setting(enum acer_wmi_gaming_misc_setting setting, u8 value)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~

vim +/WMID_gaming_get_misc_setting +1618 drivers/platform/x86/acer-wmi.c

1597

> 1598	static int WMID_gaming_set_misc_setting(enum acer_wmi_gaming_misc_setting setting, u8 value)
  1599	{
  1600		acpi_status status;
  1601		u64 input = 0;
  1602		u64 result;
  1603	
  1604		input |= FIELD_PREP(ACER_GAMING_MISC_SETTING_INDEX_MASK, setting);
  1605		input |= FIELD_PREP(ACER_GAMING_MISC_SETTING_VALUE_MASK, value);
  1606	
  1607		status = WMI_gaming_execute_u64(ACER_WMID_SET_GAMING_MISC_SETTING_METHODID, input, &result);
  1608		if (ACPI_FAILURE(status))
  1609			return -EIO;
  1610	
  1611		/* The return status must be zero for the operation to have succeeded */
  1612		if (FIELD_GET(ACER_GAMING_MISC_SETTING_STATUS_MASK, result))
  1613			return -EIO;
  1614	
  1615		return 0;
  1616	}
  1617	
> 1618	static int WMID_gaming_get_misc_setting(enum acer_wmi_gaming_misc_setting setting, u8 *value)

1619 {
1620 u64 input = 0;
1621 u64 result;
1622 int ret;
1623
1624 input |= FIELD_PREP(ACER_GAMING_MISC_SETTING_INDEX_MASK, setting);
1625
1626 ret = WMI_gaming_execute_u32_u64(ACER_WMID_GET_GAMING_MISC_SETTING_METHODID, input,
1627 &result);
1628 if (ret < 0)
1629 return ret;
1630
1631 /* The return status must be zero for the operation to have succeeded */
1632 if (FIELD_GET(ACER_GAMING_MISC_SETTING_STATUS_MASK, result))
1633 return -EIO;
1634
1635 *value = FIELD_GET(ACER_GAMING_MISC_SETTING_VALUE_MASK, result);
1636
1637 return 0;
1638 }
1639

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki