]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
alienware-wmi: create_thermal_profile() no longer brute-forces IDs
authorKurt Borja <kuurtb@gmail.com>
Mon, 11 Nov 2024 18:36:23 +0000 (15:36 -0300)
committerIlpo Järvinen <ilpo.jarvinen@linux.intel.com>
Sat, 16 Nov 2024 14:50:15 +0000 (16:50 +0200)
WMAX_METHOD_THERMAL_INFORMATION has a *system description* operation
that outputs a buffer with the following structure:

out[0] -> Number of fans
out[1] -> Number of sensors
out[2] -> 0x00
out[3] -> Number of thermal modes

This is now used by create_thermal_profile() to retrieve available thermal
codes instead of brute-forcing every ID.

Tested on an Alienware x15 R1. Verified by checking ACPI tables of
supported models.

Signed-off-by: Kurt Borja <kuurtb@gmail.com>
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Link: https://lore.kernel.org/r/20241111183623.14691-1-kuurtb@gmail.com
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
drivers/platform/x86/dell/alienware-wmi.c

index 36d182f217e24c9686bd4bb7e55adaeb3c998135..77465ed9b449bfa96c427ba781a1818235641c91 100644 (file)
@@ -68,6 +68,7 @@ enum WMAX_CONTROL_STATES {
 };
 
 enum WMAX_THERMAL_INFORMATION_OPERATIONS {
+       WMAX_OPERATION_SYS_DESCRIPTION          = 0x02,
        WMAX_OPERATION_LIST_IDS                 = 0x03,
        WMAX_OPERATION_CURRENT_PROFILE          = 0x0B,
 };
@@ -1110,13 +1111,22 @@ static int thermal_profile_set(struct platform_profile_handler *pprof,
 static int create_thermal_profile(void)
 {
        u32 out_data;
+       u8 sys_desc[4];
+       u32 first_mode;
        enum wmax_thermal_mode mode;
        enum platform_profile_option profile;
        int ret;
 
-       for (u8 i = 0x2; i <= 0xD; i++) {
+       ret = wmax_thermal_information(WMAX_OPERATION_SYS_DESCRIPTION,
+                                      0, (u32 *) &sys_desc);
+       if (ret < 0)
+               return ret;
+
+       first_mode = sys_desc[0] + sys_desc[1];
+
+       for (u32 i = 0; i < sys_desc[3]; i++) {
                ret = wmax_thermal_information(WMAX_OPERATION_LIST_IDS,
-                                              i, &out_data);
+                                              i + first_mode, &out_data);
 
                if (ret == -EIO)
                        return ret;