Re: [PATCH v5 2/4] Fix SW_TABLET_MODE detection method

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Ilpo,

thank you for your comments.
I added some defines for the values of the module param and re-ordered the
logic a bit. I think it is easier to follow now.

I now also use another return variable "ret2" for the result of
hp_wmi_read_int() to not overwrite the result of original
hp_wmi_perform_query() when hp_wmi_read_int() fails. This was actually a
bug in my first implementation.

I still think that re-using the enable_tablet_mode_sw param for that is
a reasonable compromise, because the comment of original
commit 520ee4ea1cc60251a6e3c911cf0336278aa52634 suggests that there was
some problem with hp_wmi_read_int(HPWMI_HARDWARE_QUERY) on newer Tablets.
So, because I cannot test this, I'd prefer to not change current behavior
when the enable_tablet_mode_sw parameter is not set.

Best Regards
Stefan

Actual patch starts here:

From: Stefan Sichler <stsichler@xxxxxx>
Date: Mon, 19 Aug 2024 14:45:57 +0200
Subject: [PATCH] platform/x86: hp-wmi: repair Tablet Mode detection on old
 Convertibles

This fixes a regression introduced by commit
520ee4ea1cc60251a6e3c911cf0336278aa52634
("Fix SW_TABLET_MODE detection method").

Investigation showed that some older Convertibles like HP EliteBook 2760p
do neither report Chassis Type correctly nor report tablet state by
HPWMI_SYSTEM_DEVICE_MODE, so for those, it is still required to fallback
to previous HPWMI_HARDWARE_QUERY method.

Since on pre-5.18 kernels, it was required to set enable_tablet_mode_sw
module param to enable this anyway, we re-add this removed parameter here
and re-use it in the following way:
  - when left at default -1 (auto): no change to current implementation
  - when set to 0 (off): unconditionally disable tablet mode reporting
  - when set to 1 (force on): ignore Chassis type and use old
    hp_wmi_hw_state(HPWMI_TABLET_MASK) query method in addition to new
    hp_wmi_perform_query(HPWMI_SYSTEM_DEVICE_MODE...) method

Signed-off-by: Stefan Sichler <stsichler@xxxxxx>

---
 drivers/platform/x86/hp/hp-wmi.c | 32 ++++++++++++++++++++++++++++----
 1 file changed, 28 insertions(+), 4 deletions(-)

diff --git a/drivers/platform/x86/hp/hp-wmi.c b/drivers/platform/x86/hp/hp-wmi.c
index 876e0a97c..cab01308d 100644
--- a/drivers/platform/x86/hp/hp-wmi.c
+++ b/drivers/platform/x86/hp/hp-wmi.c
@@ -38,6 +38,13 @@ MODULE_LICENSE("GPL");
 MODULE_ALIAS("wmi:95F24279-4D7B-4334-9387-ACCDC67EF61C");
 MODULE_ALIAS("wmi:5FB7F034-2C63-45E9-BE91-3D44E2C707E4");

+static int enable_tablet_mode_sw = -1;
+module_param(enable_tablet_mode_sw, int, 0444);
+MODULE_PARM_DESC(enable_tablet_mode_sw, "Enable SW_TABLET_MODE reporting (-1=auto, 0=no, 1=yes)");
+#define HPWMI_TABLET_MODE_SW_AUTO -1
+#define HPWMI_TABLET_MODE_SW_OFF 0
+#define HPWMI_TABLET_MODE_SW_FORCE_ON 1
+
 #define HPWMI_EVENT_GUID "95F24279-4D7B-4334-9387-ACCDC67EF61C"
 #define HPWMI_BIOS_GUID "5FB7F034-2C63-45E9-BE91-3D44E2C707E4"

@@ -459,23 +466,40 @@ static int hp_wmi_get_tablet_mode(void)
 	bool tablet_found;
 	int ret;

+	if (enable_tablet_mode_sw == HPWMI_TABLET_MODE_SW_OFF)
+		return -ENODEV;
+
 	chassis_type = dmi_get_system_info(DMI_CHASSIS_TYPE);
 	if (!chassis_type)
 		return -ENODEV;

-	tablet_found = match_string(tablet_chassis_types,
+	tablet_found =
+		(enable_tablet_mode_sw == HPWMI_TABLET_MODE_SW_FORCE_ON)
+		|| (match_string(tablet_chassis_types,
 				    ARRAY_SIZE(tablet_chassis_types),
-				    chassis_type) >= 0;
+				    chassis_type) >= 0);
 	if (!tablet_found)
 		return -ENODEV;

 	ret = hp_wmi_perform_query(HPWMI_SYSTEM_DEVICE_MODE, HPWMI_READ,
 				   system_device_mode, zero_if_sup(system_device_mode),
 				   sizeof(system_device_mode));
-	if (ret < 0)
+	if (ret < 0 && enable_tablet_mode_sw != HPWMI_TABLET_MODE_SW_FORCE_ON)
 		return ret;

-	return system_device_mode[0] == DEVICE_MODE_TABLET;
+	if (ret >= 0)
+		ret = (system_device_mode[0] == DEVICE_MODE_TABLET);
+
+	/* workaround for older convertibles. needs to be actively switched on
+	 * and is only executed when HPWMI_SYSTEM_DEVICE_MODE query failed or
+	 * did not report tablet state, i.e. (ret < 0) or (ret == 0) */
+	if (ret <= 0 && enable_tablet_mode_sw == HPWMI_TABLET_MODE_SW_FORCE_ON) {
+		int ret2 = hp_wmi_read_int(HPWMI_HARDWARE_QUERY);
+		if (ret2 >= 0)
+			ret = !!(ret2 & HPWMI_TABLET_MASK);
+	}
+
+	return ret;
 }

 static int omen_thermal_profile_set(int mode)
--
2.43.0





[Index of Archives]     [Linux Kernel Development]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux