Advertisement
Guest User

0001-platform-x86-hp-wmi-support-omen-thermal-profile-pol.patch

a guest
Mar 18th, 2023
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 5.44 KB | Source Code | 0 0
  1. From 286e937efbc7177c114e80aae9b402131e3886c1 Mon Sep 17 00:00:00 2001
  2. From: Enver Balalic <balalic.enver@gmail.com>
  3. Date: Mon, 14 Mar 2022 13:14:53 +0100
  4. Subject: [PATCH] platform/x86: hp-wmi: support omen thermal profile policy v1
  5.  
  6. As it turns out, these laptops have 2 thermal profile versions.
  7. A previous patch added support for v0, this patch adds support
  8. for v1 thermal policies that are in use on some devices.
  9. We obtain the thermal policy version by querying the get system
  10. design data WMI call and looking at the fourth byte it returns,
  11. except if the system board DMI Board ID is in a specific array
  12. that the windows command center app overrides to thermal policy
  13. v0 for some reason.
  14.  
  15. Signed-off-by: Enver Balalic <balalic.enver@gmail.com>
  16. Link: https://lore.kernel.org/r/20220314121453.kjszdciymtg6ctbq@omen
  17. Reviewed-by: Hans de Goede <hdegoede@redhat.com>
  18. Signed-off-by: Hans de Goede <hdegoede@redhat.com>
  19. ---
  20.  drivers/platform/x86/hp-wmi.c | 81 +++++++++++++++++++++++++++++------
  21.  1 file changed, 67 insertions(+), 14 deletions(-)
  22.  
  23. diff --git a/drivers/platform/x86/hp-wmi.c b/drivers/platform/x86/hp-wmi.c
  24. index 1f9d6e1de5af..0e9a25b56e0e 100644
  25. --- a/drivers/platform/x86/hp-wmi.c
  26. +++ b/drivers/platform/x86/hp-wmi.c
  27. @@ -57,6 +57,14 @@ static const char * const omen_thermal_profile_boards[] = {
  28.     "8917", "8918", "8949", "894A", "89EB"
  29.  };
  30.  
  31. +/* DMI Board names of Omen laptops that are specifically set to be thermal
  32. + * profile version 0 by the Omen Command Center app, regardless of what
  33. + * the get system design information WMI call returns
  34. + */
  35. +static const char *const omen_thermal_profile_force_v0_boards[] = {
  36. +   "8607", "8746", "8747", "8749", "874A", "8748"
  37. +};
  38. +
  39.  enum hp_wmi_radio {
  40.     HPWMI_WIFI  = 0x0,
  41.     HPWMI_BLUETOOTH = 0x1,
  42. @@ -117,6 +125,7 @@ enum hp_wmi_gm_commandtype {
  43.     HPWMI_SET_PERFORMANCE_MODE = 0x1A,
  44.     HPWMI_FAN_SPEED_MAX_GET_QUERY = 0x26,
  45.     HPWMI_FAN_SPEED_MAX_SET_QUERY = 0x27,
  46. +   HPWMI_GET_SYSTEM_DESIGN_DATA = 0x28,
  47.  };
  48.  
  49.  enum hp_wmi_command {
  50. @@ -151,10 +160,16 @@ enum hp_wireless2_bits {
  51.     HPWMI_POWER_FW_OR_HW    = HPWMI_POWER_BIOS | HPWMI_POWER_HARD,
  52.  };
  53.  
  54. -enum hp_thermal_profile_omen {
  55. -   HP_OMEN_THERMAL_PROFILE_DEFAULT     = 0x00,
  56. -   HP_OMEN_THERMAL_PROFILE_PERFORMANCE = 0x01,
  57. -   HP_OMEN_THERMAL_PROFILE_COOL        = 0x02,
  58. +enum hp_thermal_profile_omen_v0 {
  59. +   HP_OMEN_V0_THERMAL_PROFILE_DEFAULT     = 0x00,
  60. +   HP_OMEN_V0_THERMAL_PROFILE_PERFORMANCE = 0x01,
  61. +   HP_OMEN_V0_THERMAL_PROFILE_COOL        = 0x02,
  62. +};
  63. +
  64. +enum hp_thermal_profile_omen_v1 {
  65. +   HP_OMEN_V1_THERMAL_PROFILE_DEFAULT  = 0x30,
  66. +   HP_OMEN_V1_THERMAL_PROFILE_PERFORMANCE  = 0x31,
  67. +   HP_OMEN_V1_THERMAL_PROFILE_COOL     = 0x50,
  68.  };
  69.  
  70.  enum hp_thermal_profile {
  71. @@ -407,9 +422,6 @@ static int omen_thermal_profile_set(int mode)
  72.     char buffer[2] = {0, mode};
  73.     int ret;
  74.  
  75. -   if (mode < 0 || mode > 2)
  76. -       return -EINVAL;
  77. -
  78.     ret = hp_wmi_perform_query(HPWMI_SET_PERFORMANCE_MODE, HPWMI_GM,
  79.                    &buffer, sizeof(buffer), 0);
  80.  
  81. @@ -431,6 +443,30 @@ static bool is_omen_thermal_profile(void)
  82.                 board_name) >= 0;
  83.  }
  84.  
  85. +static int omen_get_thermal_policy_version(void)
  86. +{
  87. +   unsigned char buffer[8] = { 0 };
  88. +   int ret;
  89. +
  90. +   const char *board_name = dmi_get_system_info(DMI_BOARD_NAME);
  91. +
  92. +   if (board_name) {
  93. +       int matches = match_string(omen_thermal_profile_force_v0_boards,
  94. +           ARRAY_SIZE(omen_thermal_profile_force_v0_boards),
  95. +           board_name);
  96. +       if (matches >= 0)
  97. +           return 0;
  98. +   }
  99. +
  100. +   ret = hp_wmi_perform_query(HPWMI_GET_SYSTEM_DESIGN_DATA, HPWMI_GM,
  101. +                  &buffer, sizeof(buffer), sizeof(buffer));
  102. +
  103. +   if (ret)
  104. +       return ret < 0 ? ret : -EINVAL;
  105. +
  106. +   return buffer[3];
  107. +}
  108. +
  109.  static int omen_thermal_profile_get(void)
  110.  {
  111.     u8 data;
  112. @@ -1053,13 +1089,16 @@ static int platform_profile_omen_get(struct platform_profile_handler *pprof,
  113.         return tp;
  114.  
  115.     switch (tp) {
  116. -   case HP_OMEN_THERMAL_PROFILE_PERFORMANCE:
  117. +   case HP_OMEN_V0_THERMAL_PROFILE_PERFORMANCE:
  118. +   case HP_OMEN_V1_THERMAL_PROFILE_PERFORMANCE:
  119.         *profile = PLATFORM_PROFILE_PERFORMANCE;
  120.         break;
  121. -   case HP_OMEN_THERMAL_PROFILE_DEFAULT:
  122. +   case HP_OMEN_V0_THERMAL_PROFILE_DEFAULT:
  123. +   case HP_OMEN_V1_THERMAL_PROFILE_DEFAULT:
  124.         *profile = PLATFORM_PROFILE_BALANCED;
  125.         break;
  126. -   case HP_OMEN_THERMAL_PROFILE_COOL:
  127. +   case HP_OMEN_V0_THERMAL_PROFILE_COOL:
  128. +   case HP_OMEN_V1_THERMAL_PROFILE_COOL:
  129.         *profile = PLATFORM_PROFILE_COOL;
  130.         break;
  131.     default:
  132. @@ -1072,17 +1111,31 @@ static int platform_profile_omen_get(struct platform_profile_handler *pprof,
  133.  static int platform_profile_omen_set(struct platform_profile_handler *pprof,
  134.                      enum platform_profile_option profile)
  135.  {
  136. -   int err, tp;
  137. +   int err, tp, tp_version;
  138. +
  139. +   tp_version = omen_get_thermal_policy_version();
  140. +
  141. +   if (tp_version < 0 || tp_version > 1)
  142. +       return -EOPNOTSUPP;
  143.  
  144.     switch (profile) {
  145.     case PLATFORM_PROFILE_PERFORMANCE:
  146. -       tp = HP_OMEN_THERMAL_PROFILE_PERFORMANCE;
  147. +       if (tp_version == 0)
  148. +           tp = HP_OMEN_V0_THERMAL_PROFILE_PERFORMANCE;
  149. +       else
  150. +           tp = HP_OMEN_V1_THERMAL_PROFILE_PERFORMANCE;
  151.         break;
  152.     case PLATFORM_PROFILE_BALANCED:
  153. -       tp = HP_OMEN_THERMAL_PROFILE_DEFAULT;
  154. +       if (tp_version == 0)
  155. +           tp = HP_OMEN_V0_THERMAL_PROFILE_DEFAULT;
  156. +       else
  157. +           tp = HP_OMEN_V1_THERMAL_PROFILE_DEFAULT;
  158.         break;
  159.     case PLATFORM_PROFILE_COOL:
  160. -       tp = HP_OMEN_THERMAL_PROFILE_COOL;
  161. +       if (tp_version == 0)
  162. +           tp = HP_OMEN_V0_THERMAL_PROFILE_COOL;
  163. +       else
  164. +           tp = HP_OMEN_V1_THERMAL_PROFILE_COOL;
  165.         break;
  166.     default:
  167.         return -EOPNOTSUPP;
  168. --
  169. 2.25.1
Tags: kernel patch
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement