public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Kurt Borja <kuurtb@gmail.com>
To: kuurtb@gmail.com
Cc: W_Armin@gmx.de, hdegoede@redhat.com,
	ilpo.jarvinen@linux.intel.com, linux-kernel@vger.kernel.org,
	platform-driver-x86@vger.kernel.org
Subject: [PATCH v6 4/5] alienware-wmi: added autodetect_thermal_profile for devices with quirk_unknown
Date: Thu, 17 Oct 2024 05:16:33 -0300	[thread overview]
Message-ID: <20241017081631.127333-3-kuurtb@gmail.com> (raw)
In-Reply-To: <20241017081211.126214-2-kuurtb@gmail.com>

Added autodetect_thermal_profile for devices with quirk_unknown.
Autodetection is done through basic conditions most devices with WMAX's
thermal interface meet. Function exits returning 0 in case of errors.

Signed-off-by: Kurt Borja <kuurtb@gmail.com>

---
I apologize for the late inclusion. This feature can extend support to
many devices without having to list them in alienware_quirks.

The conditions for selecting the automatic thermal profile are based on
observations on a lot of *issues* in AWCC open source alternatives. 

I observed only Dell's G-Series laptops have WMAX_THERMAL_BALANCED
avaliable and when it's present none of the other profiles are
avaliable, except for GMODE. When a model has USTT profiles avaliable
usually they have all USTT profiles avaliable, except for cool on mostly
Alienware devices.

I made another implementation of this function, brute-forcing operation
0x03 of Thermal_Information, which is the operation that varies the most
across models. I found the implementation too cumbersome to include in
this series, but it could potentially extend support of this driver to
all posible devices with this interface automatically.

Another possibility is just including every device I observed into
alienware_quirks, which I can do but I want to know your opinion first.
---
 drivers/platform/x86/dell/alienware-wmi.c | 42 +++++++++++++++++++++++
 1 file changed, 42 insertions(+)

diff --git a/drivers/platform/x86/dell/alienware-wmi.c b/drivers/platform/x86/dell/alienware-wmi.c
index 37a898273..a11ff4851 100644
--- a/drivers/platform/x86/dell/alienware-wmi.c
+++ b/drivers/platform/x86/dell/alienware-wmi.c
@@ -30,8 +30,11 @@
 #define WMAX_METHOD_DEEP_SLEEP_STATUS	0x0C
 #define WMAX_METHOD_THERMAL_INFORMATION	0x14
 #define WMAX_METHOD_THERMAL_CONTROL	0x15
+#define WMAX_METHOD_GMODE_STATUS	0x25
 
+#define WMAX_ARG_GET_DEFAULT_PROF	0x0A
 #define WMAX_ARG_GET_CURRENT_PROF	0x0B
+#define WMAX_ARG_GET_GMODE_STATUS	0x02
 
 #define WMAX_FAILURE_CODE		0xFFFFFFFF
 
@@ -968,6 +971,42 @@ static int thermal_profile_set_ustt(struct platform_profile_handler *pprof,
 	return 0;
 }
 
+static int autodetect_thermal_profile(void)
+{
+	acpi_status status;
+	u32 in_args;
+	u32 default_profile;
+	u32 gmode;
+
+	in_args = WMAX_ARG_GET_DEFAULT_PROF;
+	status = alienware_wmax_command(&in_args, sizeof(in_args),
+					WMAX_METHOD_THERMAL_INFORMATION, &default_profile);
+
+	if (ACPI_FAILURE(status))
+		return 0;
+
+	in_args = WMAX_ARG_GET_GMODE_STATUS;
+	status = alienware_wmax_command(&in_args, sizeof(in_args),
+					WMAX_METHOD_GMODE_STATUS, &gmode);
+
+	if (ACPI_FAILURE(status))
+		return 0;
+
+	if (default_profile == WMAX_THERMAL_BALANCED && gmode == 1) {
+		quirks->thermal = WMAX_THERMAL_TABLE_SIMPLE;
+		quirks->gmode = 1;
+		return 0;
+	}
+
+	if (default_profile == WMAX_THERMAL_USTT_BALANCED)
+		quirks->thermal = WMAX_THERMAL_TABLE_USTT;
+
+	if (gmode == 0 || gmode == 1)
+		quirks->gmode = 1;
+
+	return 0;
+}
+
 static int create_thermal_profile(void)
 {
 	pp_handler.profile_get = thermal_profile_get;
@@ -1050,6 +1089,9 @@ static int __init alienware_wmi_init(void)
 			goto fail_prep_deepsleep;
 	}
 
+	if (interface == WMAX && quirks == &quirk_unknown)
+		autodetect_thermal_profile();
+
 	if (quirks->thermal > 0) {
 		ret = create_thermal_profile();
 		if (ret)
-- 
2.47.0


  parent reply	other threads:[~2024-10-17  8:16 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-17  8:12 [PATCH v6 0/5] Dell AWCC platform_profile support Kurt Borja
2024-10-17  8:13 ` [PATCH v6 1/5] alienware-wmi: fixed indentation and clean up Kurt Borja
2024-10-20 20:04   ` Armin Wolf
2024-10-17  8:14 ` [PATCH v6 2/5] alienware-wmi: alienware_wmax_command() is now input size agnostic Kurt Borja
2024-10-20 20:05   ` Armin Wolf
2024-10-17  8:15 ` [PATCH v6 3/5] alienware-wmi: added platform profile support Kurt Borja
2024-10-20 20:12   ` Armin Wolf
2024-10-22  7:35     ` Kurt Borja
2024-10-17  8:16 ` Kurt Borja [this message]
2024-10-20 20:39   ` [PATCH v6 4/5] alienware-wmi: added autodetect_thermal_profile for devices with quirk_unknown Armin Wolf
2024-10-20 20:40     ` Armin Wolf
2024-10-20 22:09       ` Armin Wolf
2024-10-22  7:58     ` Kurt Borja
2024-10-17  8:17 ` [PATCH v6 5/5] alienware-wmi: WMAX interface documentation Kurt Borja
2024-10-20 22:09   ` Armin Wolf

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=20241017081631.127333-3-kuurtb@gmail.com \
    --to=kuurtb@gmail.com \
    --cc=W_Armin@gmx.de \
    --cc=hdegoede@redhat.com \
    --cc=ilpo.jarvinen@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=platform-driver-x86@vger.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