Implements platform profile support for Dell laptops with new WMAX
thermal interface, present on some Alienware X-Series, Alienware
M-Series and Dell's G-Series laptops. This implementation supports two
sets of thermal profile codes, namely *thermal* and *thermal_ustt*, plus
additional quirk *gmode* for Dell's G-Series laptops.
Signed-off-by: Kurt Borja <kuurtb@gmail.com>
---
drivers/platform/x86/dell/Kconfig | 1 +
drivers/platform/x86/dell/alienware-wmi.c | 236 ++++++++++++++++++++++
2 files changed, 237 insertions(+)
diff --git a/drivers/platform/x86/dell/Kconfig b/drivers/platform/x86/dell/Kconfig
index 68a49788a..b06d634cd 100644
--- a/drivers/platform/x86/dell/Kconfig
+++ b/drivers/platform/x86/dell/Kconfig
@@ -21,6 +21,7 @@ config ALIENWARE_WMI
depends on LEDS_CLASS
depends on NEW_LEDS
depends on ACPI_WMI
+ select ACPI_PLATFORM_PROFILE
help
This is a driver for controlling Alienware BIOS driven
features. It exposes an interface for controlling the AlienFX
diff --git a/drivers/platform/x86/dell/alienware-wmi.c b/drivers/platform/x86/dell/alienware-wmi.c
index b27f3b64c..6e30e9376 100644
--- a/drivers/platform/x86/dell/alienware-wmi.c
+++ b/drivers/platform/x86/dell/alienware-wmi.c
@@ -8,8 +8,11 @@
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include <linux/acpi.h>
+#include <linux/bitfield.h>
+#include <linux/bits.h>
#include <linux/module.h>
#include <linux/platform_device.h>
+#include <linux/platform_profile.h>
#include <linux/dmi.h>
#include <linux/leds.h>
@@ -25,6 +28,12 @@
#define WMAX_METHOD_AMPLIFIER_CABLE 0x6
#define WMAX_METHOD_DEEP_SLEEP_CONTROL 0x0B
#define WMAX_METHOD_DEEP_SLEEP_STATUS 0x0C
+#define WMAX_METHOD_THERMAL_INFORMATION 0x14
+#define WMAX_METHOD_THERMAL_CONTROL 0x15
+
+#define WMAX_ARG_GET_CURRENT_PROF 0x0B
+
+#define WMAX_FAILURE_CODE 0xFFFFFFFF
MODULE_AUTHOR("Mario Limonciello <mario.limonciello@outlook.com>");
MODULE_DESCRIPTION("Alienware special feature control");
@@ -49,11 +58,27 @@ enum WMAX_CONTROL_STATES {
WMAX_SUSPEND = 3,
};
+enum WMAX_THERMAL_PROFILE {
+ WMAX_THERMAL_QUIET = 0x96,
+ WMAX_THERMAL_BALANCED = 0x97,
+ WMAX_THERMAL_BALANCED_PERFORMANCE = 0x98,
+ WMAX_THERMAL_PERFORMANCE = 0x99,
+ WMAX_THERMAL_USTT_LOW_POWER = 0xA5,
+ WMAX_THERMAL_USTT_QUIET = 0xA3,
+ WMAX_THERMAL_USTT_BALANCED = 0xA0,
+ WMAX_THERMAL_USTT_BALANCED_PERFORMANCE = 0xA1,
+ WMAX_THERMAL_USTT_PERFORMANCE = 0xA4,
+ WMAX_THERMAL_GMODE = 0xAB,
+};
+
struct quirk_entry {
u8 num_zones;
u8 hdmi_mux;
u8 amplifier;
u8 deepslp;
+ u8 thermal;
+ u8 thermal_ustt;
+ u8 gmode;
};
static struct quirk_entry *quirks;
@@ -64,6 +89,9 @@ static struct quirk_entry quirk_inspiron5675 = {
.hdmi_mux = 0,
.amplifier = 0,
.deepslp = 0,
+ .thermal = 0,
+ .thermal_ustt = 0,
+ .gmode = 0,
};
static struct quirk_entry quirk_unknown = {
@@ -71,6 +99,9 @@ static struct quirk_entry quirk_unknown = {
.hdmi_mux = 0,
.amplifier = 0,
.deepslp = 0,
+ .thermal = 0,
+ .thermal_ustt = 0,
+ .gmode = 0,
};
static struct quirk_entry quirk_x51_r1_r2 = {
@@ -78,6 +109,9 @@ static struct quirk_entry quirk_x51_r1_r2 = {
.hdmi_mux = 0,
.amplifier = 0,
.deepslp = 0,
+ .thermal = 0,
+ .thermal_ustt = 0,
+ .gmode = 0,
};
static struct quirk_entry quirk_x51_r3 = {
@@ -85,6 +119,9 @@ static struct quirk_entry quirk_x51_r3 = {
.hdmi_mux = 0,
.amplifier = 1,
.deepslp = 0,
+ .thermal = 0,
+ .thermal_ustt = 0,
+ .gmode = 0,
};
static struct quirk_entry quirk_asm100 = {
@@ -92,6 +129,9 @@ static struct quirk_entry quirk_asm100 = {
.hdmi_mux = 1,
.amplifier = 0,
.deepslp = 0,
+ .thermal = 0,
+ .thermal_ustt = 0,
+ .gmode = 0,
};
static struct quirk_entry quirk_asm200 = {
@@ -99,6 +139,9 @@ static struct quirk_entry quirk_asm200 = {
.hdmi_mux = 1,
.amplifier = 0,
.deepslp = 1,
+ .thermal = 0,
+ .thermal_ustt = 0,
+ .gmode = 0,
};
static struct quirk_entry quirk_asm201 = {
@@ -106,6 +149,19 @@ static struct quirk_entry quirk_asm201 = {
.hdmi_mux = 1,
.amplifier = 1,
.deepslp = 1,
+ .thermal = 0,
+ .thermal_ustt = 0,
+ .gmode = 0,
+};
+
+static struct quirk_entry quirk_x15_r1 = {
+ .num_zones = 2,
+ .hdmi_mux = 0,
+ .amplifier = 0,
+ .deepslp = 0,
+ .thermal = 0,
+ .thermal_ustt = 1,
+ .gmode = 0,
};
static int __init dmi_matched(const struct dmi_system_id *dmi)
@@ -169,6 +225,15 @@ static const struct dmi_system_id alienware_quirks[] __initconst = {
},
.driver_data = &quirk_asm201,
},
+ {
+ .callback = dmi_matched,
+ .ident = "Alienware x15 R1",
+ .matches = {
+ DMI_MATCH(DMI_SYS_VENDOR, "Alienware"),
+ DMI_MATCH(DMI_PRODUCT_NAME, "Alienware x15 R1")
+ },
+ .driver_data = &quirk_x15_r1,
+ },
{
.callback = dmi_matched,
.ident = "Dell Inc. Inspiron 5675",
@@ -218,6 +283,7 @@ static struct platform_device *platform_device;
static struct device_attribute *zone_dev_attrs;
static struct attribute **zone_attrs;
static struct platform_zone *zone_data;
+static struct platform_profile_handler pp_handler;
static struct platform_driver platform_driver = {
.driver = {
@@ -761,6 +827,168 @@ static int create_deepsleep(struct platform_device *dev)
return ret;
}
+/*
+ * Thermal Profile control
+ * - Provides thermal profile control through the Platform Profile API
+ */
+#define WMAX_PROFILE_MASK GENMASK(15, 8)
+#define WMAX_PROFILE_ACTIVATE BIT(0)
+
+static u32 profile_to_wmax_arg(enum WMAX_THERMAL_PROFILE prof)
+{
+ return FIELD_PREP(WMAX_PROFILE_MASK, prof) | WMAX_PROFILE_ACTIVATE;
+}
+
+static int thermal_profile_get(struct platform_profile_handler *pprof,
+ enum platform_profile_option *profile)
+{
+ acpi_status status;
+ u32 in_args = WMAX_ARG_GET_CURRENT_PROF;
+ u32 out_data;
+
+ status = alienware_wmax_command(&in_args, sizeof(in_args),
+ WMAX_METHOD_THERMAL_INFORMATION, &out_data);
+
+ if (ACPI_FAILURE(status))
+ return -EIO;
+
+ if (out_data == WMAX_FAILURE_CODE)
+ return -EBADRQC;
+
+ switch (out_data) {
+ case WMAX_THERMAL_USTT_LOW_POWER:
+ *profile = PLATFORM_PROFILE_LOW_POWER;
+ break;
+ case WMAX_THERMAL_QUIET:
+ case WMAX_THERMAL_USTT_QUIET:
+ *profile = PLATFORM_PROFILE_QUIET;
+ break;
+ case WMAX_THERMAL_BALANCED:
+ case WMAX_THERMAL_USTT_BALANCED:
+ *profile = PLATFORM_PROFILE_BALANCED;
+ break;
+ case WMAX_THERMAL_BALANCED_PERFORMANCE:
+ case WMAX_THERMAL_USTT_BALANCED_PERFORMANCE:
+ *profile = PLATFORM_PROFILE_BALANCED_PERFORMANCE;
+ break;
+ case WMAX_THERMAL_GMODE:
+ case WMAX_THERMAL_PERFORMANCE:
+ case WMAX_THERMAL_USTT_PERFORMANCE:
+ *profile = PLATFORM_PROFILE_PERFORMANCE;
+ break;
+ default:
+ return -ENODATA;
+ }
+
+ return 0;
+}
+
+static int thermal_profile_set(struct platform_profile_handler *pprof,
+ enum platform_profile_option profile)
+{
+ acpi_status status;
+ u32 in_args;
+ u32 out_data;
+
+ switch (profile) {
+ case PLATFORM_PROFILE_QUIET:
+ in_args = profile_to_wmax_arg(WMAX_THERMAL_QUIET);
+ break;
+ case PLATFORM_PROFILE_BALANCED:
+ in_args = profile_to_wmax_arg(WMAX_THERMAL_BALANCED);
+ break;
+ case PLATFORM_PROFILE_BALANCED_PERFORMANCE:
+ in_args = profile_to_wmax_arg(WMAX_THERMAL_BALANCED_PERFORMANCE);
+ break;
+ case PLATFORM_PROFILE_PERFORMANCE:
+ if (quirks->gmode > 0)
+ in_args = profile_to_wmax_arg(WMAX_THERMAL_GMODE);
+ else
+ in_args = profile_to_wmax_arg(WMAX_THERMAL_PERFORMANCE);
+ break;
+ default:
+ return -EOPNOTSUPP;
+ }
+
+ status = alienware_wmax_command(&in_args, sizeof(in_args),
+ WMAX_METHOD_THERMAL_CONTROL, &out_data);
+
+ if (ACPI_FAILURE(status))
+ return -EIO;
+
+ if (out_data == WMAX_FAILURE_CODE)
+ return -EBADRQC;
+
+ return 0;
+}
+
+static int thermal_profile_set_ustt(struct platform_profile_handler *pprof,
+ enum platform_profile_option profile)
+{
+ acpi_status status;
+ u32 in_args;
+ u32 out_data;
+
+ switch (profile) {
+ case PLATFORM_PROFILE_LOW_POWER:
+ in_args = profile_to_wmax_arg(WMAX_THERMAL_USTT_LOW_POWER);
+ break;
+ case PLATFORM_PROFILE_QUIET:
+ in_args = profile_to_wmax_arg(WMAX_THERMAL_USTT_QUIET);
+ break;
+ case PLATFORM_PROFILE_BALANCED:
+ in_args = profile_to_wmax_arg(WMAX_THERMAL_USTT_BALANCED);
+ break;
+ case PLATFORM_PROFILE_BALANCED_PERFORMANCE:
+ in_args = profile_to_wmax_arg(WMAX_THERMAL_USTT_BALANCED_PERFORMANCE);
+ break;
+ case PLATFORM_PROFILE_PERFORMANCE:
+ if (quirks->gmode > 0)
+ in_args = profile_to_wmax_arg(WMAX_THERMAL_GMODE);
+ else
+ in_args = profile_to_wmax_arg(WMAX_THERMAL_USTT_PERFORMANCE);
+ break;
+ default:
+ return -EOPNOTSUPP;
+ }
+
+ status = alienware_wmax_command(&in_args, sizeof(in_args),
+ WMAX_METHOD_THERMAL_CONTROL, &out_data);
+
+ if (ACPI_FAILURE(status))
+ return -EIO;
+
+ if (out_data == WMAX_FAILURE_CODE)
+ return -EBADRQC;
+
+ return 0;
+}
+
+static int create_thermal_profile(void)
+{
+ pp_handler.profile_get = thermal_profile_get;
+
+ if (quirks->thermal > 0)
+ pp_handler.profile_set = thermal_profile_set;
+ else {
+ pp_handler.profile_set = thermal_profile_set_ustt;
+ set_bit(PLATFORM_PROFILE_LOW_POWER, pp_handler.choices);
+ }
+
+ set_bit(PLATFORM_PROFILE_QUIET, pp_handler.choices);
+ set_bit(PLATFORM_PROFILE_BALANCED, pp_handler.choices);
+ set_bit(PLATFORM_PROFILE_BALANCED_PERFORMANCE, pp_handler.choices);
+ set_bit(PLATFORM_PROFILE_PERFORMANCE, pp_handler.choices);
+
+ return platform_profile_register(&pp_handler);
+}
+
+static void remove_thermal_profile(void)
+{
+ if (quirks->thermal > 0)
+ platform_profile_remove();
+}
+
static int __init alienware_wmi_init(void)
{
int ret;
@@ -808,6 +1036,12 @@ static int __init alienware_wmi_init(void)
goto fail_prep_deepsleep;
}
+ if (quirks->thermal > 0 || quirks->thermal_ustt > 0) {
+ ret = create_thermal_profile();
+ if (ret)
+ goto fail_prep_thermal_profile;
+ }
+
ret = alienware_zone_init(platform_device);
if (ret)
goto fail_prep_zones;
@@ -818,6 +1052,7 @@ static int __init alienware_wmi_init(void)
alienware_zone_exit(platform_device);
fail_prep_deepsleep:
fail_prep_amplifier:
+fail_prep_thermal_profile:
fail_prep_hdmi:
platform_device_del(platform_device);
fail_platform_device2:
@@ -835,6 +1070,7 @@ static void __exit alienware_wmi_exit(void)
if (platform_device) {
alienware_zone_exit(platform_device);
remove_hdmi(platform_device);
+ remove_thermal_profile();
platform_device_unregister(platform_device);
platform_driver_unregister(&platform_driver);
}
--
2.47.0
On Fri, 11 Oct 2024, Kurt Borja wrote: > Implements platform profile support for Dell laptops with new WMAX > thermal interface, present on some Alienware X-Series, Alienware > M-Series and Dell's G-Series laptops. This implementation supports two > sets of thermal profile codes, namely *thermal* and *thermal_ustt*, plus > additional quirk *gmode* for Dell's G-Series laptops. > > Signed-off-by: Kurt Borja <kuurtb@gmail.com> > --- > drivers/platform/x86/dell/Kconfig | 1 + > drivers/platform/x86/dell/alienware-wmi.c | 236 ++++++++++++++++++++++ > 2 files changed, 237 insertions(+) > > diff --git a/drivers/platform/x86/dell/Kconfig b/drivers/platform/x86/dell/Kconfig > index 68a49788a..b06d634cd 100644 > --- a/drivers/platform/x86/dell/Kconfig > +++ b/drivers/platform/x86/dell/Kconfig > @@ -21,6 +21,7 @@ config ALIENWARE_WMI > depends on LEDS_CLASS > depends on NEW_LEDS > depends on ACPI_WMI > + select ACPI_PLATFORM_PROFILE > help > This is a driver for controlling Alienware BIOS driven > features. It exposes an interface for controlling the AlienFX > diff --git a/drivers/platform/x86/dell/alienware-wmi.c b/drivers/platform/x86/dell/alienware-wmi.c > index b27f3b64c..6e30e9376 100644 > --- a/drivers/platform/x86/dell/alienware-wmi.c > +++ b/drivers/platform/x86/dell/alienware-wmi.c > @@ -8,8 +8,11 @@ > #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt > > #include <linux/acpi.h> > +#include <linux/bitfield.h> > +#include <linux/bits.h> > #include <linux/module.h> > #include <linux/platform_device.h> > +#include <linux/platform_profile.h> > #include <linux/dmi.h> > #include <linux/leds.h> > > @@ -25,6 +28,12 @@ > #define WMAX_METHOD_AMPLIFIER_CABLE 0x6 > #define WMAX_METHOD_DEEP_SLEEP_CONTROL 0x0B > #define WMAX_METHOD_DEEP_SLEEP_STATUS 0x0C > +#define WMAX_METHOD_THERMAL_INFORMATION 0x14 > +#define WMAX_METHOD_THERMAL_CONTROL 0x15 > + > +#define WMAX_ARG_GET_CURRENT_PROF 0x0B > + > +#define WMAX_FAILURE_CODE 0xFFFFFFFF > > MODULE_AUTHOR("Mario Limonciello <mario.limonciello@outlook.com>"); > MODULE_DESCRIPTION("Alienware special feature control"); > @@ -49,11 +58,27 @@ enum WMAX_CONTROL_STATES { > WMAX_SUSPEND = 3, > }; > > +enum WMAX_THERMAL_PROFILE { > + WMAX_THERMAL_QUIET = 0x96, > + WMAX_THERMAL_BALANCED = 0x97, > + WMAX_THERMAL_BALANCED_PERFORMANCE = 0x98, > + WMAX_THERMAL_PERFORMANCE = 0x99, > + WMAX_THERMAL_USTT_LOW_POWER = 0xA5, > + WMAX_THERMAL_USTT_QUIET = 0xA3, > + WMAX_THERMAL_USTT_BALANCED = 0xA0, > + WMAX_THERMAL_USTT_BALANCED_PERFORMANCE = 0xA1, > + WMAX_THERMAL_USTT_PERFORMANCE = 0xA4, > + WMAX_THERMAL_GMODE = 0xAB, While doing the next version, could also align these values please. -- i.
Am 12.10.24 um 04:02 schrieb Kurt Borja: > Implements platform profile support for Dell laptops with new WMAX > thermal interface, present on some Alienware X-Series, Alienware > M-Series and Dell's G-Series laptops. This implementation supports two > sets of thermal profile codes, namely *thermal* and *thermal_ustt*, plus > additional quirk *gmode* for Dell's G-Series laptops. > > Signed-off-by: Kurt Borja <kuurtb@gmail.com> > --- > drivers/platform/x86/dell/Kconfig | 1 + > drivers/platform/x86/dell/alienware-wmi.c | 236 ++++++++++++++++++++++ > 2 files changed, 237 insertions(+) > > diff --git a/drivers/platform/x86/dell/Kconfig b/drivers/platform/x86/dell/Kconfig > index 68a49788a..b06d634cd 100644 > --- a/drivers/platform/x86/dell/Kconfig > +++ b/drivers/platform/x86/dell/Kconfig > @@ -21,6 +21,7 @@ config ALIENWARE_WMI > depends on LEDS_CLASS > depends on NEW_LEDS > depends on ACPI_WMI > + select ACPI_PLATFORM_PROFILE > help > This is a driver for controlling Alienware BIOS driven > features. It exposes an interface for controlling the AlienFX > diff --git a/drivers/platform/x86/dell/alienware-wmi.c b/drivers/platform/x86/dell/alienware-wmi.c > index b27f3b64c..6e30e9376 100644 > --- a/drivers/platform/x86/dell/alienware-wmi.c > +++ b/drivers/platform/x86/dell/alienware-wmi.c > @@ -8,8 +8,11 @@ > #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt > > #include <linux/acpi.h> > +#include <linux/bitfield.h> > +#include <linux/bits.h> > #include <linux/module.h> > #include <linux/platform_device.h> > +#include <linux/platform_profile.h> > #include <linux/dmi.h> > #include <linux/leds.h> > > @@ -25,6 +28,12 @@ > #define WMAX_METHOD_AMPLIFIER_CABLE 0x6 > #define WMAX_METHOD_DEEP_SLEEP_CONTROL 0x0B > #define WMAX_METHOD_DEEP_SLEEP_STATUS 0x0C > +#define WMAX_METHOD_THERMAL_INFORMATION 0x14 > +#define WMAX_METHOD_THERMAL_CONTROL 0x15 > + > +#define WMAX_ARG_GET_CURRENT_PROF 0x0B > + > +#define WMAX_FAILURE_CODE 0xFFFFFFFF > > MODULE_AUTHOR("Mario Limonciello <mario.limonciello@outlook.com>"); > MODULE_DESCRIPTION("Alienware special feature control"); > @@ -49,11 +58,27 @@ enum WMAX_CONTROL_STATES { > WMAX_SUSPEND = 3, > }; > > +enum WMAX_THERMAL_PROFILE { > + WMAX_THERMAL_QUIET = 0x96, > + WMAX_THERMAL_BALANCED = 0x97, > + WMAX_THERMAL_BALANCED_PERFORMANCE = 0x98, > + WMAX_THERMAL_PERFORMANCE = 0x99, > + WMAX_THERMAL_USTT_LOW_POWER = 0xA5, > + WMAX_THERMAL_USTT_QUIET = 0xA3, > + WMAX_THERMAL_USTT_BALANCED = 0xA0, > + WMAX_THERMAL_USTT_BALANCED_PERFORMANCE = 0xA1, > + WMAX_THERMAL_USTT_PERFORMANCE = 0xA4, > + WMAX_THERMAL_GMODE = 0xAB, > +}; > + > struct quirk_entry { > u8 num_zones; > u8 hdmi_mux; > u8 amplifier; > u8 deepslp; > + u8 thermal; > + u8 thermal_ustt; > + u8 gmode; > }; > > static struct quirk_entry *quirks; > @@ -64,6 +89,9 @@ static struct quirk_entry quirk_inspiron5675 = { > .hdmi_mux = 0, > .amplifier = 0, > .deepslp = 0, > + .thermal = 0, > + .thermal_ustt = 0, > + .gmode = 0, > }; > > static struct quirk_entry quirk_unknown = { > @@ -71,6 +99,9 @@ static struct quirk_entry quirk_unknown = { > .hdmi_mux = 0, > .amplifier = 0, > .deepslp = 0, > + .thermal = 0, > + .thermal_ustt = 0, > + .gmode = 0, > }; > > static struct quirk_entry quirk_x51_r1_r2 = { > @@ -78,6 +109,9 @@ static struct quirk_entry quirk_x51_r1_r2 = { > .hdmi_mux = 0, > .amplifier = 0, > .deepslp = 0, > + .thermal = 0, > + .thermal_ustt = 0, > + .gmode = 0, > }; > > static struct quirk_entry quirk_x51_r3 = { > @@ -85,6 +119,9 @@ static struct quirk_entry quirk_x51_r3 = { > .hdmi_mux = 0, > .amplifier = 1, > .deepslp = 0, > + .thermal = 0, > + .thermal_ustt = 0, > + .gmode = 0, > }; > > static struct quirk_entry quirk_asm100 = { > @@ -92,6 +129,9 @@ static struct quirk_entry quirk_asm100 = { > .hdmi_mux = 1, > .amplifier = 0, > .deepslp = 0, > + .thermal = 0, > + .thermal_ustt = 0, > + .gmode = 0, > }; > > static struct quirk_entry quirk_asm200 = { > @@ -99,6 +139,9 @@ static struct quirk_entry quirk_asm200 = { > .hdmi_mux = 1, > .amplifier = 0, > .deepslp = 1, > + .thermal = 0, > + .thermal_ustt = 0, > + .gmode = 0, > }; > > static struct quirk_entry quirk_asm201 = { > @@ -106,6 +149,19 @@ static struct quirk_entry quirk_asm201 = { > .hdmi_mux = 1, > .amplifier = 1, > .deepslp = 1, > + .thermal = 0, > + .thermal_ustt = 0, > + .gmode = 0, > +}; > + > +static struct quirk_entry quirk_x15_r1 = { > + .num_zones = 2, > + .hdmi_mux = 0, > + .amplifier = 0, > + .deepslp = 0, > + .thermal = 0, > + .thermal_ustt = 1, > + .gmode = 0, > }; > > static int __init dmi_matched(const struct dmi_system_id *dmi) > @@ -169,6 +225,15 @@ static const struct dmi_system_id alienware_quirks[] __initconst = { > }, > .driver_data = &quirk_asm201, > }, > + { > + .callback = dmi_matched, > + .ident = "Alienware x15 R1", > + .matches = { > + DMI_MATCH(DMI_SYS_VENDOR, "Alienware"), > + DMI_MATCH(DMI_PRODUCT_NAME, "Alienware x15 R1") > + }, > + .driver_data = &quirk_x15_r1, > + }, > { > .callback = dmi_matched, > .ident = "Dell Inc. Inspiron 5675", > @@ -218,6 +283,7 @@ static struct platform_device *platform_device; > static struct device_attribute *zone_dev_attrs; > static struct attribute **zone_attrs; > static struct platform_zone *zone_data; > +static struct platform_profile_handler pp_handler; > > static struct platform_driver platform_driver = { > .driver = { > @@ -761,6 +827,168 @@ static int create_deepsleep(struct platform_device *dev) > return ret; > } > > +/* > + * Thermal Profile control > + * - Provides thermal profile control through the Platform Profile API > + */ > +#define WMAX_PROFILE_MASK GENMASK(15, 8) > +#define WMAX_PROFILE_ACTIVATE BIT(0) > + > +static u32 profile_to_wmax_arg(enum WMAX_THERMAL_PROFILE prof) > +{ > + return FIELD_PREP(WMAX_PROFILE_MASK, prof) | WMAX_PROFILE_ACTIVATE; > +} > + > +static int thermal_profile_get(struct platform_profile_handler *pprof, > + enum platform_profile_option *profile) Alignment should match open parenthesis. > +{ > + acpi_status status; > + u32 in_args = WMAX_ARG_GET_CURRENT_PROF; > + u32 out_data; > + > + status = alienware_wmax_command(&in_args, sizeof(in_args), > + WMAX_METHOD_THERMAL_INFORMATION, &out_data); > + > + if (ACPI_FAILURE(status)) > + return -EIO; > + > + if (out_data == WMAX_FAILURE_CODE) > + return -EBADRQC; > + > + switch (out_data) { > + case WMAX_THERMAL_USTT_LOW_POWER: > + *profile = PLATFORM_PROFILE_LOW_POWER; > + break; > + case WMAX_THERMAL_QUIET: > + case WMAX_THERMAL_USTT_QUIET: > + *profile = PLATFORM_PROFILE_QUIET; > + break; > + case WMAX_THERMAL_BALANCED: > + case WMAX_THERMAL_USTT_BALANCED: > + *profile = PLATFORM_PROFILE_BALANCED; > + break; > + case WMAX_THERMAL_BALANCED_PERFORMANCE: > + case WMAX_THERMAL_USTT_BALANCED_PERFORMANCE: > + *profile = PLATFORM_PROFILE_BALANCED_PERFORMANCE; > + break; > + case WMAX_THERMAL_GMODE: > + case WMAX_THERMAL_PERFORMANCE: > + case WMAX_THERMAL_USTT_PERFORMANCE: > + *profile = PLATFORM_PROFILE_PERFORMANCE; > + break; > + default: > + return -ENODATA; > + } > + > + return 0; > +} > + > +static int thermal_profile_set(struct platform_profile_handler *pprof, > + enum platform_profile_option profile) > +{ Alignment should match open parenthesis. > + acpi_status status; > + u32 in_args; > + u32 out_data; > + > + switch (profile) { > + case PLATFORM_PROFILE_QUIET: > + in_args = profile_to_wmax_arg(WMAX_THERMAL_QUIET); > + break; > + case PLATFORM_PROFILE_BALANCED: > + in_args = profile_to_wmax_arg(WMAX_THERMAL_BALANCED); > + break; > + case PLATFORM_PROFILE_BALANCED_PERFORMANCE: > + in_args = profile_to_wmax_arg(WMAX_THERMAL_BALANCED_PERFORMANCE); > + break; > + case PLATFORM_PROFILE_PERFORMANCE: > + if (quirks->gmode > 0) > + in_args = profile_to_wmax_arg(WMAX_THERMAL_GMODE); > + else > + in_args = profile_to_wmax_arg(WMAX_THERMAL_PERFORMANCE); > + break; > + default: > + return -EOPNOTSUPP; > + } > + > + status = alienware_wmax_command(&in_args, sizeof(in_args), > + WMAX_METHOD_THERMAL_CONTROL, &out_data); > + > + if (ACPI_FAILURE(status)) > + return -EIO; > + > + if (out_data == WMAX_FAILURE_CODE) > + return -EBADRQC; > + > + return 0; > +} > + > +static int thermal_profile_set_ustt(struct platform_profile_handler *pprof, > + enum platform_profile_option profile) > +{ > + acpi_status status; > + u32 in_args; > + u32 out_data; > + > + switch (profile) { > + case PLATFORM_PROFILE_LOW_POWER: > + in_args = profile_to_wmax_arg(WMAX_THERMAL_USTT_LOW_POWER); > + break; > + case PLATFORM_PROFILE_QUIET: > + in_args = profile_to_wmax_arg(WMAX_THERMAL_USTT_QUIET); > + break; > + case PLATFORM_PROFILE_BALANCED: > + in_args = profile_to_wmax_arg(WMAX_THERMAL_USTT_BALANCED); > + break; > + case PLATFORM_PROFILE_BALANCED_PERFORMANCE: > + in_args = profile_to_wmax_arg(WMAX_THERMAL_USTT_BALANCED_PERFORMANCE); > + break; > + case PLATFORM_PROFILE_PERFORMANCE: > + if (quirks->gmode > 0) > + in_args = profile_to_wmax_arg(WMAX_THERMAL_GMODE); > + else > + in_args = profile_to_wmax_arg(WMAX_THERMAL_USTT_PERFORMANCE); > + break; > + default: > + return -EOPNOTSUPP; > + } > + > + status = alienware_wmax_command(&in_args, sizeof(in_args), > + WMAX_METHOD_THERMAL_CONTROL, &out_data); > + > + if (ACPI_FAILURE(status)) > + return -EIO; > + > + if (out_data == WMAX_FAILURE_CODE) > + return -EBADRQC; > + > + return 0; > +} > + > +static int create_thermal_profile(void) > +{ > + pp_handler.profile_get = thermal_profile_get; > + > + if (quirks->thermal > 0) > + pp_handler.profile_set = thermal_profile_set; Braces {} should be used on all arms of this statement. > + else { > + pp_handler.profile_set = thermal_profile_set_ustt; > + set_bit(PLATFORM_PROFILE_LOW_POWER, pp_handler.choices); > + } > + > + set_bit(PLATFORM_PROFILE_QUIET, pp_handler.choices); > + set_bit(PLATFORM_PROFILE_BALANCED, pp_handler.choices); > + set_bit(PLATFORM_PROFILE_BALANCED_PERFORMANCE, pp_handler.choices); > + set_bit(PLATFORM_PROFILE_PERFORMANCE, pp_handler.choices); > + > + return platform_profile_register(&pp_handler); > +} > + > +static void remove_thermal_profile(void) > +{ > + if (quirks->thermal > 0) > + platform_profile_remove(); platform_profile_remove() should also be called when quirks->thermal_ustt is set. > +} > + > static int __init alienware_wmi_init(void) > { > int ret; > @@ -808,6 +1036,12 @@ static int __init alienware_wmi_init(void) > goto fail_prep_deepsleep; > } > > + if (quirks->thermal > 0 || quirks->thermal_ustt > 0) { > + ret = create_thermal_profile(); > + if (ret) > + goto fail_prep_thermal_profile; > + } > + > ret = alienware_zone_init(platform_device); > if (ret) > goto fail_prep_zones; > @@ -818,6 +1052,7 @@ static int __init alienware_wmi_init(void) > alienware_zone_exit(platform_device); > fail_prep_deepsleep: > fail_prep_amplifier: > +fail_prep_thermal_profile: fail_prep_thermal_profile should come before fail_prep_deepsleep for proper rollback in case of an error. Also fail_prep_zones should call remove_thermal_profile(). > fail_prep_hdmi: > platform_device_del(platform_device); > fail_platform_device2: > @@ -835,6 +1070,7 @@ static void __exit alienware_wmi_exit(void) > if (platform_device) { > alienware_zone_exit(platform_device); > remove_hdmi(platform_device); > + remove_thermal_profile(); Please move remove_thermal_profile() above remove_hdmi(). Otherwise, the patch look good. Thanks, Armin Wolf > platform_device_unregister(platform_device); > platform_driver_unregister(&platform_driver); > }
On Mon, Oct 14, 2024 at 06:40:49PM +0200, Armin Wolf wrote: > Am 12.10.24 um 04:02 schrieb Kurt Borja: > > > Implements platform profile support for Dell laptops with new WMAX > > thermal interface, present on some Alienware X-Series, Alienware > > M-Series and Dell's G-Series laptops. This implementation supports two > > sets of thermal profile codes, namely *thermal* and *thermal_ustt*, plus > > additional quirk *gmode* for Dell's G-Series laptops. > > > > Signed-off-by: Kurt Borja <kuurtb@gmail.com> > > --- > > drivers/platform/x86/dell/Kconfig | 1 + > > drivers/platform/x86/dell/alienware-wmi.c | 236 ++++++++++++++++++++++ > > 2 files changed, 237 insertions(+) > > > > diff --git a/drivers/platform/x86/dell/Kconfig b/drivers/platform/x86/dell/Kconfig > > index 68a49788a..b06d634cd 100644 > > --- a/drivers/platform/x86/dell/Kconfig > > +++ b/drivers/platform/x86/dell/Kconfig > > @@ -21,6 +21,7 @@ config ALIENWARE_WMI > > depends on LEDS_CLASS > > depends on NEW_LEDS > > depends on ACPI_WMI > > + select ACPI_PLATFORM_PROFILE > > help > > This is a driver for controlling Alienware BIOS driven > > features. It exposes an interface for controlling the AlienFX > > diff --git a/drivers/platform/x86/dell/alienware-wmi.c b/drivers/platform/x86/dell/alienware-wmi.c > > index b27f3b64c..6e30e9376 100644 > > --- a/drivers/platform/x86/dell/alienware-wmi.c > > +++ b/drivers/platform/x86/dell/alienware-wmi.c > > @@ -8,8 +8,11 @@ > > #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt > > > > #include <linux/acpi.h> > > +#include <linux/bitfield.h> > > +#include <linux/bits.h> > > #include <linux/module.h> > > #include <linux/platform_device.h> > > +#include <linux/platform_profile.h> > > #include <linux/dmi.h> > > #include <linux/leds.h> > > > > @@ -25,6 +28,12 @@ > > #define WMAX_METHOD_AMPLIFIER_CABLE 0x6 > > #define WMAX_METHOD_DEEP_SLEEP_CONTROL 0x0B > > #define WMAX_METHOD_DEEP_SLEEP_STATUS 0x0C > > +#define WMAX_METHOD_THERMAL_INFORMATION 0x14 > > +#define WMAX_METHOD_THERMAL_CONTROL 0x15 > > + > > +#define WMAX_ARG_GET_CURRENT_PROF 0x0B > > + > > +#define WMAX_FAILURE_CODE 0xFFFFFFFF > > > > MODULE_AUTHOR("Mario Limonciello <mario.limonciello@outlook.com>"); > > MODULE_DESCRIPTION("Alienware special feature control"); > > @@ -49,11 +58,27 @@ enum WMAX_CONTROL_STATES { > > WMAX_SUSPEND = 3, > > }; > > > > +enum WMAX_THERMAL_PROFILE { > > + WMAX_THERMAL_QUIET = 0x96, > > + WMAX_THERMAL_BALANCED = 0x97, > > + WMAX_THERMAL_BALANCED_PERFORMANCE = 0x98, > > + WMAX_THERMAL_PERFORMANCE = 0x99, > > + WMAX_THERMAL_USTT_LOW_POWER = 0xA5, > > + WMAX_THERMAL_USTT_QUIET = 0xA3, > > + WMAX_THERMAL_USTT_BALANCED = 0xA0, > > + WMAX_THERMAL_USTT_BALANCED_PERFORMANCE = 0xA1, > > + WMAX_THERMAL_USTT_PERFORMANCE = 0xA4, > > + WMAX_THERMAL_GMODE = 0xAB, > > +}; > > + > > struct quirk_entry { > > u8 num_zones; > > u8 hdmi_mux; > > u8 amplifier; > > u8 deepslp; > > + u8 thermal; > > + u8 thermal_ustt; > > + u8 gmode; > > }; > > > > static struct quirk_entry *quirks; > > @@ -64,6 +89,9 @@ static struct quirk_entry quirk_inspiron5675 = { > > .hdmi_mux = 0, > > .amplifier = 0, > > .deepslp = 0, > > + .thermal = 0, > > + .thermal_ustt = 0, > > + .gmode = 0, > > }; > > > > static struct quirk_entry quirk_unknown = { > > @@ -71,6 +99,9 @@ static struct quirk_entry quirk_unknown = { > > .hdmi_mux = 0, > > .amplifier = 0, > > .deepslp = 0, > > + .thermal = 0, > > + .thermal_ustt = 0, > > + .gmode = 0, > > }; > > > > static struct quirk_entry quirk_x51_r1_r2 = { > > @@ -78,6 +109,9 @@ static struct quirk_entry quirk_x51_r1_r2 = { > > .hdmi_mux = 0, > > .amplifier = 0, > > .deepslp = 0, > > + .thermal = 0, > > + .thermal_ustt = 0, > > + .gmode = 0, > > }; > > > > static struct quirk_entry quirk_x51_r3 = { > > @@ -85,6 +119,9 @@ static struct quirk_entry quirk_x51_r3 = { > > .hdmi_mux = 0, > > .amplifier = 1, > > .deepslp = 0, > > + .thermal = 0, > > + .thermal_ustt = 0, > > + .gmode = 0, > > }; > > > > static struct quirk_entry quirk_asm100 = { > > @@ -92,6 +129,9 @@ static struct quirk_entry quirk_asm100 = { > > .hdmi_mux = 1, > > .amplifier = 0, > > .deepslp = 0, > > + .thermal = 0, > > + .thermal_ustt = 0, > > + .gmode = 0, > > }; > > > > static struct quirk_entry quirk_asm200 = { > > @@ -99,6 +139,9 @@ static struct quirk_entry quirk_asm200 = { > > .hdmi_mux = 1, > > .amplifier = 0, > > .deepslp = 1, > > + .thermal = 0, > > + .thermal_ustt = 0, > > + .gmode = 0, > > }; > > > > static struct quirk_entry quirk_asm201 = { > > @@ -106,6 +149,19 @@ static struct quirk_entry quirk_asm201 = { > > .hdmi_mux = 1, > > .amplifier = 1, > > .deepslp = 1, > > + .thermal = 0, > > + .thermal_ustt = 0, > > + .gmode = 0, > > +}; > > + > > +static struct quirk_entry quirk_x15_r1 = { > > + .num_zones = 2, > > + .hdmi_mux = 0, > > + .amplifier = 0, > > + .deepslp = 0, > > + .thermal = 0, > > + .thermal_ustt = 1, > > + .gmode = 0, > > }; > > > > static int __init dmi_matched(const struct dmi_system_id *dmi) > > @@ -169,6 +225,15 @@ static const struct dmi_system_id alienware_quirks[] __initconst = { > > }, > > .driver_data = &quirk_asm201, > > }, > > + { > > + .callback = dmi_matched, > > + .ident = "Alienware x15 R1", > > + .matches = { > > + DMI_MATCH(DMI_SYS_VENDOR, "Alienware"), > > + DMI_MATCH(DMI_PRODUCT_NAME, "Alienware x15 R1") > > + }, > > + .driver_data = &quirk_x15_r1, > > + }, > > { > > .callback = dmi_matched, > > .ident = "Dell Inc. Inspiron 5675", > > @@ -218,6 +283,7 @@ static struct platform_device *platform_device; > > static struct device_attribute *zone_dev_attrs; > > static struct attribute **zone_attrs; > > static struct platform_zone *zone_data; > > +static struct platform_profile_handler pp_handler; > > > > static struct platform_driver platform_driver = { > > .driver = { > > @@ -761,6 +827,168 @@ static int create_deepsleep(struct platform_device *dev) > > return ret; > > } > > > > +/* > > + * Thermal Profile control > > + * - Provides thermal profile control through the Platform Profile API > > + */ > > +#define WMAX_PROFILE_MASK GENMASK(15, 8) > > +#define WMAX_PROFILE_ACTIVATE BIT(0) > > + > > +static u32 profile_to_wmax_arg(enum WMAX_THERMAL_PROFILE prof) > > +{ > > + return FIELD_PREP(WMAX_PROFILE_MASK, prof) | WMAX_PROFILE_ACTIVATE; > > +} > > + > > +static int thermal_profile_get(struct platform_profile_handler *pprof, > > + enum platform_profile_option *profile) > > Alignment should match open parenthesis. I will fix it. > > > +{ > > + acpi_status status; > > + u32 in_args = WMAX_ARG_GET_CURRENT_PROF; > > + u32 out_data; > > + > > + status = alienware_wmax_command(&in_args, sizeof(in_args), > > + WMAX_METHOD_THERMAL_INFORMATION, &out_data); > > + > > + if (ACPI_FAILURE(status)) > > + return -EIO; > > + > > + if (out_data == WMAX_FAILURE_CODE) > > + return -EBADRQC; > > + > > + switch (out_data) { > > + case WMAX_THERMAL_USTT_LOW_POWER: > > + *profile = PLATFORM_PROFILE_LOW_POWER; > > + break; > > + case WMAX_THERMAL_QUIET: > > + case WMAX_THERMAL_USTT_QUIET: > > + *profile = PLATFORM_PROFILE_QUIET; > > + break; > > + case WMAX_THERMAL_BALANCED: > > + case WMAX_THERMAL_USTT_BALANCED: > > + *profile = PLATFORM_PROFILE_BALANCED; > > + break; > > + case WMAX_THERMAL_BALANCED_PERFORMANCE: > > + case WMAX_THERMAL_USTT_BALANCED_PERFORMANCE: > > + *profile = PLATFORM_PROFILE_BALANCED_PERFORMANCE; > > + break; > > + case WMAX_THERMAL_GMODE: > > + case WMAX_THERMAL_PERFORMANCE: > > + case WMAX_THERMAL_USTT_PERFORMANCE: > > + *profile = PLATFORM_PROFILE_PERFORMANCE; > > + break; > > + default: > > + return -ENODATA; > > + } > > + > > + return 0; > > +} > > + > > +static int thermal_profile_set(struct platform_profile_handler *pprof, > > + enum platform_profile_option profile) > > +{ > > Alignment should match open parenthesis. > > > + acpi_status status; > > + u32 in_args; > > + u32 out_data; > > + > > + switch (profile) { > > + case PLATFORM_PROFILE_QUIET: > > + in_args = profile_to_wmax_arg(WMAX_THERMAL_QUIET); > > + break; > > + case PLATFORM_PROFILE_BALANCED: > > + in_args = profile_to_wmax_arg(WMAX_THERMAL_BALANCED); > > + break; > > + case PLATFORM_PROFILE_BALANCED_PERFORMANCE: > > + in_args = profile_to_wmax_arg(WMAX_THERMAL_BALANCED_PERFORMANCE); > > + break; > > + case PLATFORM_PROFILE_PERFORMANCE: > > + if (quirks->gmode > 0) > > + in_args = profile_to_wmax_arg(WMAX_THERMAL_GMODE); > > + else > > + in_args = profile_to_wmax_arg(WMAX_THERMAL_PERFORMANCE); > > + break; > > + default: > > + return -EOPNOTSUPP; > > + } > > + > > + status = alienware_wmax_command(&in_args, sizeof(in_args), > > + WMAX_METHOD_THERMAL_CONTROL, &out_data); > > + > > + if (ACPI_FAILURE(status)) > > + return -EIO; > > + > > + if (out_data == WMAX_FAILURE_CODE) > > + return -EBADRQC; > > + > > + return 0; > > +} > > + > > +static int thermal_profile_set_ustt(struct platform_profile_handler *pprof, > > + enum platform_profile_option profile) > > +{ > > + acpi_status status; > > + u32 in_args; > > + u32 out_data; > > + > > + switch (profile) { > > + case PLATFORM_PROFILE_LOW_POWER: > > + in_args = profile_to_wmax_arg(WMAX_THERMAL_USTT_LOW_POWER); > > + break; > > + case PLATFORM_PROFILE_QUIET: > > + in_args = profile_to_wmax_arg(WMAX_THERMAL_USTT_QUIET); > > + break; > > + case PLATFORM_PROFILE_BALANCED: > > + in_args = profile_to_wmax_arg(WMAX_THERMAL_USTT_BALANCED); > > + break; > > + case PLATFORM_PROFILE_BALANCED_PERFORMANCE: > > + in_args = profile_to_wmax_arg(WMAX_THERMAL_USTT_BALANCED_PERFORMANCE); > > + break; > > + case PLATFORM_PROFILE_PERFORMANCE: > > + if (quirks->gmode > 0) > > + in_args = profile_to_wmax_arg(WMAX_THERMAL_GMODE); > > + else > > + in_args = profile_to_wmax_arg(WMAX_THERMAL_USTT_PERFORMANCE); > > + break; > > + default: > > + return -EOPNOTSUPP; > > + } > > + > > + status = alienware_wmax_command(&in_args, sizeof(in_args), > > + WMAX_METHOD_THERMAL_CONTROL, &out_data); > > + > > + if (ACPI_FAILURE(status)) > > + return -EIO; > > + > > + if (out_data == WMAX_FAILURE_CODE) > > + return -EBADRQC; > > + > > + return 0; > > +} > > + > > +static int create_thermal_profile(void) > > +{ > > + pp_handler.profile_get = thermal_profile_get; > > + > > + if (quirks->thermal > 0) > > + pp_handler.profile_set = thermal_profile_set; > > Braces {} should be used on all arms of this statement. Ok. > > > + else { > > + pp_handler.profile_set = thermal_profile_set_ustt; > > + set_bit(PLATFORM_PROFILE_LOW_POWER, pp_handler.choices); > > + } > > + > > + set_bit(PLATFORM_PROFILE_QUIET, pp_handler.choices); > > + set_bit(PLATFORM_PROFILE_BALANCED, pp_handler.choices); > > + set_bit(PLATFORM_PROFILE_BALANCED_PERFORMANCE, pp_handler.choices); > > + set_bit(PLATFORM_PROFILE_PERFORMANCE, pp_handler.choices); > > + > > + return platform_profile_register(&pp_handler); > > +} > > + > > +static void remove_thermal_profile(void) > > +{ > > + if (quirks->thermal > 0) > > + platform_profile_remove(); > > platform_profile_remove() should also be called when quirks->thermal_ustt is set. Thank you for catching it. > > > +} > > + > > static int __init alienware_wmi_init(void) > > { > > int ret; > > @@ -808,6 +1036,12 @@ static int __init alienware_wmi_init(void) > > goto fail_prep_deepsleep; > > } > > > > + if (quirks->thermal > 0 || quirks->thermal_ustt > 0) { > > + ret = create_thermal_profile(); > > + if (ret) > > + goto fail_prep_thermal_profile; > > + } > > + > > ret = alienware_zone_init(platform_device); > > if (ret) > > goto fail_prep_zones; > > @@ -818,6 +1052,7 @@ static int __init alienware_wmi_init(void) > > alienware_zone_exit(platform_device); > > fail_prep_deepsleep: > > fail_prep_amplifier: > > +fail_prep_thermal_profile: > > fail_prep_thermal_profile should come before fail_prep_deepsleep for proper rollback in case of an error. > Also fail_prep_zones should call remove_thermal_profile(). Ok. > > > fail_prep_hdmi: > > platform_device_del(platform_device); > > fail_platform_device2: > > @@ -835,6 +1070,7 @@ static void __exit alienware_wmi_exit(void) > > if (platform_device) { > > alienware_zone_exit(platform_device); > > remove_hdmi(platform_device); > > + remove_thermal_profile(); > > Please move remove_thermal_profile() above remove_hdmi(). Ok. > > Otherwise, the patch look good. > > Thanks, > Armin Wolf > Thank you. Kurt > > platform_device_unregister(platform_device); > > platform_driver_unregister(&platform_driver); > > }
© 2016 - 2024 Red Hat, Inc.