* [PATCH 2/2] platform/x86: hp-wmi: add platform profile support
@ 2021-02-21 21:04 Elia Devito
2021-02-21 21:30 ` [PATCH v2 " Elia Devito
0 siblings, 1 reply; 6+ messages in thread
From: Elia Devito @ 2021-02-21 21:04 UTC (permalink / raw)
Cc: Elia Devito, Hans de Goede, Mark Gross, platform-driver-x86,
linux-kernel
Implement support for cool, balanced and performance thermal profile
Signed-off-by: Elia Devito <eliadevito@gmail.com>
---
the "quiet" profile will be implemented with a further patch
drivers/platform/x86/hp-wmi.c | 96 +++++++++++++++++++++++++++++++++--
1 file changed, 91 insertions(+), 5 deletions(-)
diff --git a/drivers/platform/x86/hp-wmi.c b/drivers/platform/x86/hp-wmi.c
index 6d7b91b8109b..d983267b252b 100644
--- a/drivers/platform/x86/hp-wmi.c
+++ b/drivers/platform/x86/hp-wmi.c
@@ -21,6 +21,7 @@
#include <linux/input.h>
#include <linux/input/sparse-keymap.h>
#include <linux/platform_device.h>
+#include <linux/platform_profile.h>
#include <linux/acpi.h>
#include <linux/rfkill.h>
#include <linux/string.h>
@@ -119,6 +120,12 @@ enum hp_wireless2_bits {
HPWMI_POWER_FW_OR_HW = HPWMI_POWER_BIOS | HPWMI_POWER_HARD,
};
+enum hp_thermal_profile {
+ HP_THERMAL_PROFILE_PERFORMANCE = 0x00,
+ HP_THERMAL_PROFILE_DEFAULT = 0x01,
+ HP_THERMAL_PROFILE_COOL = 0x02
+};
+
#define IS_HWBLOCKED(x) ((x & HPWMI_POWER_FW_OR_HW) != HPWMI_POWER_FW_OR_HW)
#define IS_SWBLOCKED(x) !(x & HPWMI_POWER_SOFT)
@@ -159,6 +166,7 @@ static const struct key_entry hp_wmi_keymap[] = {
static struct input_dev *hp_wmi_input_dev;
static struct platform_device *hp_wmi_platform_dev;
+static struct platform_profile_handler platform_profile_handler;
static struct rfkill *wifi_rfkill;
static struct rfkill *bluetooth_rfkill;
@@ -869,23 +877,101 @@ static int __init hp_wmi_rfkill2_setup(struct platform_device *device)
return err;
}
-static int thermal_profile_setup(struct platform_device *device)
+static int thermal_profile_get(void)
{
- int err, tp;
+ int tp;
tp = hp_wmi_read_int(HPWMI_THERMAL_PROFILE_QUERY);
if (tp < 0)
return tp;
+ return tp;
+}
+
+static int thermal_profile_set(int thermal_profile)
+{
+ int err;
+
+ err = hp_wmi_perform_query(HPWMI_THERMAL_PROFILE_QUERY, HPWMI_WRITE, &thermal_profile,
+ sizeof(thermal_profile), 0);
+ if (err)
+ return err;
+
+ return 0;
+}
+
+static int platform_profile_get(struct platform_profile_handler *pprof,
+ enum platform_profile_option *profile)
+{
+ int tp = thermal_profile_get();
+
+ switch (tp) {
+ case HP_THERMAL_PROFILE_PERFORMANCE:
+ *profile = PLATFORM_PROFILE_PERFORMANCE;
+ break;
+ case HP_THERMAL_PROFILE_DEFAULT:
+ *profile = PLATFORM_PROFILE_BALANCED;
+ break;
+ case HP_THERMAL_PROFILE_COOL:
+ *profile = PLATFORM_PROFILE_COOL;
+ break;
+ default:
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
+static int platform_profile_set(struct platform_profile_handler *pprof,
+ enum platform_profile_option profile)
+{
+ int err, tp;
+
+ switch (profile) {
+ case PLATFORM_PROFILE_PERFORMANCE:
+ tp = HP_THERMAL_PROFILE_PERFORMANCE;
+ break;
+ case PLATFORM_PROFILE_BALANCED:
+ tp = HP_THERMAL_PROFILE_DEFAULT;
+ break;
+ case PLATFORM_PROFILE_COOL:
+ tp = HP_THERMAL_PROFILE_COOL;
+ break;
+ default:
+ return -EOPNOTSUPP;
+ }
+
+ err = thermal_profile_set(tp);
+ if (err)
+ return err;
+
+ return 0;
+}
+
+static int thermal_profile_setup(void)
+{
+ int err, tp;
+
+ tp = thermal_profile_get();
+ if (tp < 0)
+ return tp;
+
/*
* call thermal profile write command to ensure that the firmware correctly
* sets the OEM variables for the DPTF
*/
- err = hp_wmi_perform_query(HPWMI_THERMAL_PROFILE_QUERY, HPWMI_WRITE, &tp,
- sizeof(tp), 0);
+ err = thermal_profile_set(tp);
if (err)
return err;
+ platform_profile_handler.profile_get = platform_profile_get,
+ platform_profile_handler.profile_set = platform_profile_set,
+
+ set_bit(PLATFORM_PROFILE_COOL, platform_profile_handler.choices);
+ set_bit(PLATFORM_PROFILE_BALANCED, platform_profile_handler.choices);
+ set_bit(PLATFORM_PROFILE_PERFORMANCE, platform_profile_handler.choices);
+
+ platform_profile_register(&platform_profile_handler);
return 0;
}
@@ -900,7 +986,7 @@ static int __init hp_wmi_bios_setup(struct platform_device *device)
if (hp_wmi_rfkill_setup(device))
hp_wmi_rfkill2_setup(device);
- thermal_profile_setup(device);
+ thermal_profile_setup();
return 0;
}
--
2.29.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v2 2/2] platform/x86: hp-wmi: add platform profile support
2021-02-21 21:04 [PATCH 2/2] platform/x86: hp-wmi: add platform profile support Elia Devito
@ 2021-02-21 21:30 ` Elia Devito
2021-02-21 21:51 ` Barnabás Pőcze
0 siblings, 1 reply; 6+ messages in thread
From: Elia Devito @ 2021-02-21 21:30 UTC (permalink / raw)
Cc: Elia Devito, Hans de Goede, Mark Gross, platform-driver-x86,
linux-kernel
Implement support for cool, balanced and performance thermal profile
Signed-off-by: Elia Devito <eliadevito@gmail.com>
---
the "quiet" profile will be implemented with a further patch
v2: added platform_profile_remove() missing call
drivers/platform/x86/hp-wmi.c | 103 ++++++++++++++++++++++++++++++++--
1 file changed, 98 insertions(+), 5 deletions(-)
diff --git a/drivers/platform/x86/hp-wmi.c b/drivers/platform/x86/hp-wmi.c
index 6d7b91b8109b..a33203d61cf0 100644
--- a/drivers/platform/x86/hp-wmi.c
+++ b/drivers/platform/x86/hp-wmi.c
@@ -21,6 +21,7 @@
#include <linux/input.h>
#include <linux/input/sparse-keymap.h>
#include <linux/platform_device.h>
+#include <linux/platform_profile.h>
#include <linux/acpi.h>
#include <linux/rfkill.h>
#include <linux/string.h>
@@ -119,6 +120,12 @@ enum hp_wireless2_bits {
HPWMI_POWER_FW_OR_HW = HPWMI_POWER_BIOS | HPWMI_POWER_HARD,
};
+enum hp_thermal_profile {
+ HP_THERMAL_PROFILE_PERFORMANCE = 0x00,
+ HP_THERMAL_PROFILE_DEFAULT = 0x01,
+ HP_THERMAL_PROFILE_COOL = 0x02
+};
+
#define IS_HWBLOCKED(x) ((x & HPWMI_POWER_FW_OR_HW) != HPWMI_POWER_FW_OR_HW)
#define IS_SWBLOCKED(x) !(x & HPWMI_POWER_SOFT)
@@ -159,6 +166,8 @@ static const struct key_entry hp_wmi_keymap[] = {
static struct input_dev *hp_wmi_input_dev;
static struct platform_device *hp_wmi_platform_dev;
+static struct platform_profile_handler platform_profile_handler;
+static int platform_profile_support = 0;
static struct rfkill *wifi_rfkill;
static struct rfkill *bluetooth_rfkill;
@@ -869,11 +878,80 @@ static int __init hp_wmi_rfkill2_setup(struct platform_device *device)
return err;
}
-static int thermal_profile_setup(struct platform_device *device)
+static int thermal_profile_get(void)
{
- int err, tp;
+ int tp;
tp = hp_wmi_read_int(HPWMI_THERMAL_PROFILE_QUERY);
+
+ return tp;
+}
+
+static int thermal_profile_set(int thermal_profile)
+{
+ int err;
+
+ err = hp_wmi_perform_query(HPWMI_THERMAL_PROFILE_QUERY, HPWMI_WRITE, &thermal_profile,
+ sizeof(thermal_profile), 0);
+ if (err)
+ return err;
+
+ return 0;
+}
+
+static int platform_profile_get(struct platform_profile_handler *pprof,
+ enum platform_profile_option *profile)
+{
+ int tp = thermal_profile_get();
+
+ switch (tp) {
+ case HP_THERMAL_PROFILE_PERFORMANCE:
+ *profile = PLATFORM_PROFILE_PERFORMANCE;
+ break;
+ case HP_THERMAL_PROFILE_DEFAULT:
+ *profile = PLATFORM_PROFILE_BALANCED;
+ break;
+ case HP_THERMAL_PROFILE_COOL:
+ *profile = PLATFORM_PROFILE_COOL;
+ break;
+ default:
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
+static int platform_profile_set(struct platform_profile_handler *pprof,
+ enum platform_profile_option profile)
+{
+ int err, tp;
+
+ switch (profile) {
+ case PLATFORM_PROFILE_PERFORMANCE:
+ tp = HP_THERMAL_PROFILE_PERFORMANCE;
+ break;
+ case PLATFORM_PROFILE_BALANCED:
+ tp = HP_THERMAL_PROFILE_DEFAULT;
+ break;
+ case PLATFORM_PROFILE_COOL:
+ tp = HP_THERMAL_PROFILE_COOL;
+ break;
+ default:
+ return -EOPNOTSUPP;
+ }
+
+ err = thermal_profile_set(tp);
+ if (err)
+ return err;
+
+ return 0;
+}
+
+static int thermal_profile_setup(void)
+{
+ int err, tp;
+
+ tp = thermal_profile_get();
if (tp < 0)
return tp;
@@ -881,11 +959,23 @@ static int thermal_profile_setup(struct platform_device *device)
* call thermal profile write command to ensure that the firmware correctly
* sets the OEM variables for the DPTF
*/
- err = hp_wmi_perform_query(HPWMI_THERMAL_PROFILE_QUERY, HPWMI_WRITE, &tp,
- sizeof(tp), 0);
+ err = thermal_profile_set(tp);
if (err)
return err;
+ platform_profile_handler.profile_get = platform_profile_get,
+ platform_profile_handler.profile_set = platform_profile_set,
+
+ set_bit(PLATFORM_PROFILE_COOL, platform_profile_handler.choices);
+ set_bit(PLATFORM_PROFILE_BALANCED, platform_profile_handler.choices);
+ set_bit(PLATFORM_PROFILE_PERFORMANCE, platform_profile_handler.choices);
+
+ err = platform_profile_register(&platform_profile_handler);
+ if (err)
+ return err;
+
+ platform_profile_support = 1;
+
return 0;
}
@@ -900,7 +990,7 @@ static int __init hp_wmi_bios_setup(struct platform_device *device)
if (hp_wmi_rfkill_setup(device))
hp_wmi_rfkill2_setup(device);
- thermal_profile_setup(device);
+ thermal_profile_setup();
return 0;
}
@@ -1030,5 +1120,8 @@ static void __exit hp_wmi_exit(void)
platform_device_unregister(hp_wmi_platform_dev);
platform_driver_unregister(&hp_wmi_driver);
}
+
+ if (platform_profile_support)
+ platform_profile_remove();
}
module_exit(hp_wmi_exit);
--
2.29.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v2 2/2] platform/x86: hp-wmi: add platform profile support
2021-02-21 21:30 ` [PATCH v2 " Elia Devito
@ 2021-02-21 21:51 ` Barnabás Pőcze
2021-02-21 22:13 ` [PATCH v3 " Elia Devito
0 siblings, 1 reply; 6+ messages in thread
From: Barnabás Pőcze @ 2021-02-21 21:51 UTC (permalink / raw)
To: Elia Devito; +Cc: Hans de Goede, Mark Gross, platform-driver-x86, linux-kernel
Hi
2021. február 21., vasárnap 22:30 keltezéssel, Elia Devito írta:
> Implement support for cool, balanced and performance thermal profile
>
> Signed-off-by: Elia Devito <eliadevito@gmail.com>
> ---
> the "quiet" profile will be implemented with a further patch
>
> v2: added platform_profile_remove() missing call
>
> drivers/platform/x86/hp-wmi.c | 103 ++++++++++++++++++++++++++++++++--
> 1 file changed, 98 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/platform/x86/hp-wmi.c b/drivers/platform/x86/hp-wmi.c
> index 6d7b91b8109b..a33203d61cf0 100644
> --- a/drivers/platform/x86/hp-wmi.c
> +++ b/drivers/platform/x86/hp-wmi.c
> @@ -21,6 +21,7 @@
> #include <linux/input.h>
> #include <linux/input/sparse-keymap.h>
> #include <linux/platform_device.h>
> +#include <linux/platform_profile.h>
> #include <linux/acpi.h>
> #include <linux/rfkill.h>
> #include <linux/string.h>
> @@ -119,6 +120,12 @@ enum hp_wireless2_bits {
> HPWMI_POWER_FW_OR_HW = HPWMI_POWER_BIOS | HPWMI_POWER_HARD,
> };
>
> +enum hp_thermal_profile {
> + HP_THERMAL_PROFILE_PERFORMANCE = 0x00,
> + HP_THERMAL_PROFILE_DEFAULT = 0x01,
> + HP_THERMAL_PROFILE_COOL = 0x02
> +};
> +
> #define IS_HWBLOCKED(x) ((x & HPWMI_POWER_FW_OR_HW) != HPWMI_POWER_FW_OR_HW)
> #define IS_SWBLOCKED(x) !(x & HPWMI_POWER_SOFT)
>
> @@ -159,6 +166,8 @@ static const struct key_entry hp_wmi_keymap[] = {
>
> static struct input_dev *hp_wmi_input_dev;
> static struct platform_device *hp_wmi_platform_dev;
> +static struct platform_profile_handler platform_profile_handler;
> +static int platform_profile_support = 0;
I suggest you use `bool` and omit the initialization (checkpatch will warn you
about that).
>
> static struct rfkill *wifi_rfkill;
> static struct rfkill *bluetooth_rfkill;
> @@ -869,11 +878,80 @@ static int __init hp_wmi_rfkill2_setup(struct platform_device *device)
> return err;
> }
>
> -static int thermal_profile_setup(struct platform_device *device)
> +static int thermal_profile_get(void)
> {
> - int err, tp;
> + int tp;
>
> tp = hp_wmi_read_int(HPWMI_THERMAL_PROFILE_QUERY);
> +
> + return tp;
> +}
Is there any reason why you didn't write
return hp_wmi_read_int(...);
?
> +
> +static int thermal_profile_set(int thermal_profile)
> +{
> + int err;
> +
> + err = hp_wmi_perform_query(HPWMI_THERMAL_PROFILE_QUERY, HPWMI_WRITE, &thermal_profile,
> + sizeof(thermal_profile), 0);
> + if (err)
> + return err;
> +
> + return 0;
> +}
Here as well?
> +
> +static int platform_profile_get(struct platform_profile_handler *pprof,
> + enum platform_profile_option *profile)
> +{
> + int tp = thermal_profile_get();
> +
> + switch (tp) {
> + case HP_THERMAL_PROFILE_PERFORMANCE:
> + *profile = PLATFORM_PROFILE_PERFORMANCE;
> + break;
> + case HP_THERMAL_PROFILE_DEFAULT:
> + *profile = PLATFORM_PROFILE_BALANCED;
> + break;
> + case HP_THERMAL_PROFILE_COOL:
> + *profile = PLATFORM_PROFILE_COOL;
> + break;
> + default:
> + return -EINVAL;
I think error values (tp < 0) could possibly be propagated.
> + }
> +
> + return 0;
> +}
> +
> +static int platform_profile_set(struct platform_profile_handler *pprof,
> + enum platform_profile_option profile)
> +{
> + int err, tp;
> +
> + switch (profile) {
> + case PLATFORM_PROFILE_PERFORMANCE:
> + tp = HP_THERMAL_PROFILE_PERFORMANCE;
> + break;
> + case PLATFORM_PROFILE_BALANCED:
> + tp = HP_THERMAL_PROFILE_DEFAULT;
> + break;
> + case PLATFORM_PROFILE_COOL:
> + tp = HP_THERMAL_PROFILE_COOL;
> + break;
> + default:
> + return -EOPNOTSUPP;
> + }
> +
> + err = thermal_profile_set(tp);
> + if (err)
> + return err;
> +
> + return 0;
> +}
> +
> +static int thermal_profile_setup(void)
> +{
> + int err, tp;
> +
> + tp = thermal_profile_get();
> if (tp < 0)
> return tp;
>
> @@ -881,11 +959,23 @@ static int thermal_profile_setup(struct platform_device *device)
> * call thermal profile write command to ensure that the firmware correctly
> * sets the OEM variables for the DPTF
> */
> - err = hp_wmi_perform_query(HPWMI_THERMAL_PROFILE_QUERY, HPWMI_WRITE, &tp,
> - sizeof(tp), 0);
> + err = thermal_profile_set(tp);
> if (err)
> return err;
>
> + platform_profile_handler.profile_get = platform_profile_get,
> + platform_profile_handler.profile_set = platform_profile_set,
> +
> + set_bit(PLATFORM_PROFILE_COOL, platform_profile_handler.choices);
> + set_bit(PLATFORM_PROFILE_BALANCED, platform_profile_handler.choices);
> + set_bit(PLATFORM_PROFILE_PERFORMANCE, platform_profile_handler.choices);
> +
> + err = platform_profile_register(&platform_profile_handler);
> + if (err)
> + return err;
> +
> + platform_profile_support = 1;
> +
> return 0;
> }
>
> @@ -900,7 +990,7 @@ static int __init hp_wmi_bios_setup(struct platform_device *device)
> if (hp_wmi_rfkill_setup(device))
> hp_wmi_rfkill2_setup(device);
>
> - thermal_profile_setup(device);
> + thermal_profile_setup();
>
> return 0;
> }
> @@ -1030,5 +1120,8 @@ static void __exit hp_wmi_exit(void)
> platform_device_unregister(hp_wmi_platform_dev);
> platform_driver_unregister(&hp_wmi_driver);
> }
> +
> + if (platform_profile_support)
> + platform_profile_remove();
I personally don't like the asymmetry that hp_wmi_bios_setup() registers (even
if only indirectly), but hp_wmi_exit() removes. I'd put this in hp_wmi_bios_remove().
> }
> module_exit(hp_wmi_exit);
> --
> 2.29.2
Regards,
Barnabás Pőcze
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v3 2/2] platform/x86: hp-wmi: add platform profile support
2021-02-21 21:51 ` Barnabás Pőcze
@ 2021-02-21 22:13 ` Elia Devito
2021-02-22 9:55 ` Hans de Goede
2021-03-04 13:26 ` Hans de Goede
0 siblings, 2 replies; 6+ messages in thread
From: Elia Devito @ 2021-02-21 22:13 UTC (permalink / raw)
Cc: Elia Devito, Hans de Goede, Mark Gross, platform-driver-x86,
linux-kernel
Implement support for cool, balanced and performance thermal profile
Signed-off-by: Elia Devito <eliadevito@gmail.com>
---
the "quiet" profile will be implemented with a further patch
v2: added platform_profile_remove() missing call
v3: apply Barnabás suggestions
drivers/platform/x86/hp-wmi.c | 97 +++++++++++++++++++++++++++++++++--
1 file changed, 92 insertions(+), 5 deletions(-)
diff --git a/drivers/platform/x86/hp-wmi.c b/drivers/platform/x86/hp-wmi.c
index 6d7b91b8109b..027a1467d009 100644
--- a/drivers/platform/x86/hp-wmi.c
+++ b/drivers/platform/x86/hp-wmi.c
@@ -21,6 +21,7 @@
#include <linux/input.h>
#include <linux/input/sparse-keymap.h>
#include <linux/platform_device.h>
+#include <linux/platform_profile.h>
#include <linux/acpi.h>
#include <linux/rfkill.h>
#include <linux/string.h>
@@ -119,6 +120,12 @@ enum hp_wireless2_bits {
HPWMI_POWER_FW_OR_HW = HPWMI_POWER_BIOS | HPWMI_POWER_HARD,
};
+enum hp_thermal_profile {
+ HP_THERMAL_PROFILE_PERFORMANCE = 0x00,
+ HP_THERMAL_PROFILE_DEFAULT = 0x01,
+ HP_THERMAL_PROFILE_COOL = 0x02
+};
+
#define IS_HWBLOCKED(x) ((x & HPWMI_POWER_FW_OR_HW) != HPWMI_POWER_FW_OR_HW)
#define IS_SWBLOCKED(x) !(x & HPWMI_POWER_SOFT)
@@ -159,6 +166,8 @@ static const struct key_entry hp_wmi_keymap[] = {
static struct input_dev *hp_wmi_input_dev;
static struct platform_device *hp_wmi_platform_dev;
+static struct platform_profile_handler platform_profile_handler;
+static bool platform_profile_support;
static struct rfkill *wifi_rfkill;
static struct rfkill *bluetooth_rfkill;
@@ -869,11 +878,74 @@ static int __init hp_wmi_rfkill2_setup(struct platform_device *device)
return err;
}
-static int thermal_profile_setup(struct platform_device *device)
+static int thermal_profile_get(void)
+{
+ return hp_wmi_read_int(HPWMI_THERMAL_PROFILE_QUERY);
+}
+
+static int thermal_profile_set(int thermal_profile)
+{
+ return hp_wmi_perform_query(HPWMI_THERMAL_PROFILE_QUERY, HPWMI_WRITE, &thermal_profile,
+ sizeof(thermal_profile), 0);
+}
+
+static int platform_profile_get(struct platform_profile_handler *pprof,
+ enum platform_profile_option *profile)
+{
+ int tp;
+
+ tp = thermal_profile_get();
+ if (tp < 0)
+ return tp;
+
+ switch (tp) {
+ case HP_THERMAL_PROFILE_PERFORMANCE:
+ *profile = PLATFORM_PROFILE_PERFORMANCE;
+ break;
+ case HP_THERMAL_PROFILE_DEFAULT:
+ *profile = PLATFORM_PROFILE_BALANCED;
+ break;
+ case HP_THERMAL_PROFILE_COOL:
+ *profile = PLATFORM_PROFILE_COOL;
+ break;
+ default:
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
+static int platform_profile_set(struct platform_profile_handler *pprof,
+ enum platform_profile_option profile)
{
int err, tp;
- tp = hp_wmi_read_int(HPWMI_THERMAL_PROFILE_QUERY);
+ switch (profile) {
+ case PLATFORM_PROFILE_PERFORMANCE:
+ tp = HP_THERMAL_PROFILE_PERFORMANCE;
+ break;
+ case PLATFORM_PROFILE_BALANCED:
+ tp = HP_THERMAL_PROFILE_DEFAULT;
+ break;
+ case PLATFORM_PROFILE_COOL:
+ tp = HP_THERMAL_PROFILE_COOL;
+ break;
+ default:
+ return -EOPNOTSUPP;
+ }
+
+ err = thermal_profile_set(tp);
+ if (err)
+ return err;
+
+ return 0;
+}
+
+static int thermal_profile_setup(void)
+{
+ int err, tp;
+
+ tp = thermal_profile_get();
if (tp < 0)
return tp;
@@ -881,11 +953,23 @@ static int thermal_profile_setup(struct platform_device *device)
* call thermal profile write command to ensure that the firmware correctly
* sets the OEM variables for the DPTF
*/
- err = hp_wmi_perform_query(HPWMI_THERMAL_PROFILE_QUERY, HPWMI_WRITE, &tp,
- sizeof(tp), 0);
+ err = thermal_profile_set(tp);
if (err)
return err;
+ platform_profile_handler.profile_get = platform_profile_get,
+ platform_profile_handler.profile_set = platform_profile_set,
+
+ set_bit(PLATFORM_PROFILE_COOL, platform_profile_handler.choices);
+ set_bit(PLATFORM_PROFILE_BALANCED, platform_profile_handler.choices);
+ set_bit(PLATFORM_PROFILE_PERFORMANCE, platform_profile_handler.choices);
+
+ err = platform_profile_register(&platform_profile_handler);
+ if (err)
+ return err;
+
+ platform_profile_support = true;
+
return 0;
}
@@ -900,7 +984,7 @@ static int __init hp_wmi_bios_setup(struct platform_device *device)
if (hp_wmi_rfkill_setup(device))
hp_wmi_rfkill2_setup(device);
- thermal_profile_setup(device);
+ thermal_profile_setup();
return 0;
}
@@ -927,6 +1011,9 @@ static int __exit hp_wmi_bios_remove(struct platform_device *device)
rfkill_destroy(wwan_rfkill);
}
+ if (platform_profile_support)
+ platform_profile_remove();
+
return 0;
}
--
2.29.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v3 2/2] platform/x86: hp-wmi: add platform profile support
2021-02-21 22:13 ` [PATCH v3 " Elia Devito
@ 2021-02-22 9:55 ` Hans de Goede
2021-03-04 13:26 ` Hans de Goede
1 sibling, 0 replies; 6+ messages in thread
From: Hans de Goede @ 2021-02-22 9:55 UTC (permalink / raw)
To: Elia Devito; +Cc: Mark Gross, platform-driver-x86, linux-kernel
Hi,
On 2/21/21 11:13 PM, Elia Devito wrote:
> Implement support for cool, balanced and performance thermal profile
>
> Signed-off-by: Elia Devito <eliadevito@gmail.com>
Thanks, patch looks good to me:
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
I will merge this once we are out of the merge-window / once 5.12-rc1 is out.
Regards,
Hans
> ---
> the "quiet" profile will be implemented with a further patch
>
> v2: added platform_profile_remove() missing call
> v3: apply Barnabás suggestions
>
> drivers/platform/x86/hp-wmi.c | 97 +++++++++++++++++++++++++++++++++--
> 1 file changed, 92 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/platform/x86/hp-wmi.c b/drivers/platform/x86/hp-wmi.c
> index 6d7b91b8109b..027a1467d009 100644
> --- a/drivers/platform/x86/hp-wmi.c
> +++ b/drivers/platform/x86/hp-wmi.c
> @@ -21,6 +21,7 @@
> #include <linux/input.h>
> #include <linux/input/sparse-keymap.h>
> #include <linux/platform_device.h>
> +#include <linux/platform_profile.h>
> #include <linux/acpi.h>
> #include <linux/rfkill.h>
> #include <linux/string.h>
> @@ -119,6 +120,12 @@ enum hp_wireless2_bits {
> HPWMI_POWER_FW_OR_HW = HPWMI_POWER_BIOS | HPWMI_POWER_HARD,
> };
>
> +enum hp_thermal_profile {
> + HP_THERMAL_PROFILE_PERFORMANCE = 0x00,
> + HP_THERMAL_PROFILE_DEFAULT = 0x01,
> + HP_THERMAL_PROFILE_COOL = 0x02
> +};
> +
> #define IS_HWBLOCKED(x) ((x & HPWMI_POWER_FW_OR_HW) != HPWMI_POWER_FW_OR_HW)
> #define IS_SWBLOCKED(x) !(x & HPWMI_POWER_SOFT)
>
> @@ -159,6 +166,8 @@ static const struct key_entry hp_wmi_keymap[] = {
>
> static struct input_dev *hp_wmi_input_dev;
> static struct platform_device *hp_wmi_platform_dev;
> +static struct platform_profile_handler platform_profile_handler;
> +static bool platform_profile_support;
>
> static struct rfkill *wifi_rfkill;
> static struct rfkill *bluetooth_rfkill;
> @@ -869,11 +878,74 @@ static int __init hp_wmi_rfkill2_setup(struct platform_device *device)
> return err;
> }
>
> -static int thermal_profile_setup(struct platform_device *device)
> +static int thermal_profile_get(void)
> +{
> + return hp_wmi_read_int(HPWMI_THERMAL_PROFILE_QUERY);
> +}
> +
> +static int thermal_profile_set(int thermal_profile)
> +{
> + return hp_wmi_perform_query(HPWMI_THERMAL_PROFILE_QUERY, HPWMI_WRITE, &thermal_profile,
> + sizeof(thermal_profile), 0);
> +}
> +
> +static int platform_profile_get(struct platform_profile_handler *pprof,
> + enum platform_profile_option *profile)
> +{
> + int tp;
> +
> + tp = thermal_profile_get();
> + if (tp < 0)
> + return tp;
> +
> + switch (tp) {
> + case HP_THERMAL_PROFILE_PERFORMANCE:
> + *profile = PLATFORM_PROFILE_PERFORMANCE;
> + break;
> + case HP_THERMAL_PROFILE_DEFAULT:
> + *profile = PLATFORM_PROFILE_BALANCED;
> + break;
> + case HP_THERMAL_PROFILE_COOL:
> + *profile = PLATFORM_PROFILE_COOL;
> + break;
> + default:
> + return -EINVAL;
> + }
> +
> + return 0;
> +}
> +
> +static int platform_profile_set(struct platform_profile_handler *pprof,
> + enum platform_profile_option profile)
> {
> int err, tp;
>
> - tp = hp_wmi_read_int(HPWMI_THERMAL_PROFILE_QUERY);
> + switch (profile) {
> + case PLATFORM_PROFILE_PERFORMANCE:
> + tp = HP_THERMAL_PROFILE_PERFORMANCE;
> + break;
> + case PLATFORM_PROFILE_BALANCED:
> + tp = HP_THERMAL_PROFILE_DEFAULT;
> + break;
> + case PLATFORM_PROFILE_COOL:
> + tp = HP_THERMAL_PROFILE_COOL;
> + break;
> + default:
> + return -EOPNOTSUPP;
> + }
> +
> + err = thermal_profile_set(tp);
> + if (err)
> + return err;
> +
> + return 0;
> +}
> +
> +static int thermal_profile_setup(void)
> +{
> + int err, tp;
> +
> + tp = thermal_profile_get();
> if (tp < 0)
> return tp;
>
> @@ -881,11 +953,23 @@ static int thermal_profile_setup(struct platform_device *device)
> * call thermal profile write command to ensure that the firmware correctly
> * sets the OEM variables for the DPTF
> */
> - err = hp_wmi_perform_query(HPWMI_THERMAL_PROFILE_QUERY, HPWMI_WRITE, &tp,
> - sizeof(tp), 0);
> + err = thermal_profile_set(tp);
> if (err)
> return err;
>
> + platform_profile_handler.profile_get = platform_profile_get,
> + platform_profile_handler.profile_set = platform_profile_set,
> +
> + set_bit(PLATFORM_PROFILE_COOL, platform_profile_handler.choices);
> + set_bit(PLATFORM_PROFILE_BALANCED, platform_profile_handler.choices);
> + set_bit(PLATFORM_PROFILE_PERFORMANCE, platform_profile_handler.choices);
> +
> + err = platform_profile_register(&platform_profile_handler);
> + if (err)
> + return err;
> +
> + platform_profile_support = true;
> +
> return 0;
> }
>
> @@ -900,7 +984,7 @@ static int __init hp_wmi_bios_setup(struct platform_device *device)
> if (hp_wmi_rfkill_setup(device))
> hp_wmi_rfkill2_setup(device);
>
> - thermal_profile_setup(device);
> + thermal_profile_setup();
>
> return 0;
> }
> @@ -927,6 +1011,9 @@ static int __exit hp_wmi_bios_remove(struct platform_device *device)
> rfkill_destroy(wwan_rfkill);
> }
>
> + if (platform_profile_support)
> + platform_profile_remove();
> +
> return 0;
> }
>
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v3 2/2] platform/x86: hp-wmi: add platform profile support
2021-02-21 22:13 ` [PATCH v3 " Elia Devito
2021-02-22 9:55 ` Hans de Goede
@ 2021-03-04 13:26 ` Hans de Goede
1 sibling, 0 replies; 6+ messages in thread
From: Hans de Goede @ 2021-03-04 13:26 UTC (permalink / raw)
To: Elia Devito; +Cc: Mark Gross, platform-driver-x86, linux-kernel
Hi,
On 2/21/21 11:13 PM, Elia Devito wrote:
> Implement support for cool, balanced and performance thermal profile
>
> Signed-off-by: Elia Devito <eliadevito@gmail.com>
> ---
> the "quiet" profile will be implemented with a further patch
>
> v2: added platform_profile_remove() missing call
> v3: apply Barnabás suggestions
Thank you for your patch, I've applied this patch to my review-hans
branch:
https://git.kernel.org/pub/scm/linux/kernel/git/pdx86/platform-drivers-x86.git/log/?h=review-hans
Note it will show up in my review-hans branch once I've pushed my
local branch there, which might take a while.
Once I've run some tests on this branch the patches there will be
added to the platform-drivers-x86/for-next branch and eventually
will be included in the pdx86 pull-request to Linus for the next
merge-window.
Regards,
Hans
>
> drivers/platform/x86/hp-wmi.c | 97 +++++++++++++++++++++++++++++++++--
> 1 file changed, 92 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/platform/x86/hp-wmi.c b/drivers/platform/x86/hp-wmi.c
> index 6d7b91b8109b..027a1467d009 100644
> --- a/drivers/platform/x86/hp-wmi.c
> +++ b/drivers/platform/x86/hp-wmi.c
> @@ -21,6 +21,7 @@
> #include <linux/input.h>
> #include <linux/input/sparse-keymap.h>
> #include <linux/platform_device.h>
> +#include <linux/platform_profile.h>
> #include <linux/acpi.h>
> #include <linux/rfkill.h>
> #include <linux/string.h>
> @@ -119,6 +120,12 @@ enum hp_wireless2_bits {
> HPWMI_POWER_FW_OR_HW = HPWMI_POWER_BIOS | HPWMI_POWER_HARD,
> };
>
> +enum hp_thermal_profile {
> + HP_THERMAL_PROFILE_PERFORMANCE = 0x00,
> + HP_THERMAL_PROFILE_DEFAULT = 0x01,
> + HP_THERMAL_PROFILE_COOL = 0x02
> +};
> +
> #define IS_HWBLOCKED(x) ((x & HPWMI_POWER_FW_OR_HW) != HPWMI_POWER_FW_OR_HW)
> #define IS_SWBLOCKED(x) !(x & HPWMI_POWER_SOFT)
>
> @@ -159,6 +166,8 @@ static const struct key_entry hp_wmi_keymap[] = {
>
> static struct input_dev *hp_wmi_input_dev;
> static struct platform_device *hp_wmi_platform_dev;
> +static struct platform_profile_handler platform_profile_handler;
> +static bool platform_profile_support;
>
> static struct rfkill *wifi_rfkill;
> static struct rfkill *bluetooth_rfkill;
> @@ -869,11 +878,74 @@ static int __init hp_wmi_rfkill2_setup(struct platform_device *device)
> return err;
> }
>
> -static int thermal_profile_setup(struct platform_device *device)
> +static int thermal_profile_get(void)
> +{
> + return hp_wmi_read_int(HPWMI_THERMAL_PROFILE_QUERY);
> +}
> +
> +static int thermal_profile_set(int thermal_profile)
> +{
> + return hp_wmi_perform_query(HPWMI_THERMAL_PROFILE_QUERY, HPWMI_WRITE, &thermal_profile,
> + sizeof(thermal_profile), 0);
> +}
> +
> +static int platform_profile_get(struct platform_profile_handler *pprof,
> + enum platform_profile_option *profile)
> +{
> + int tp;
> +
> + tp = thermal_profile_get();
> + if (tp < 0)
> + return tp;
> +
> + switch (tp) {
> + case HP_THERMAL_PROFILE_PERFORMANCE:
> + *profile = PLATFORM_PROFILE_PERFORMANCE;
> + break;
> + case HP_THERMAL_PROFILE_DEFAULT:
> + *profile = PLATFORM_PROFILE_BALANCED;
> + break;
> + case HP_THERMAL_PROFILE_COOL:
> + *profile = PLATFORM_PROFILE_COOL;
> + break;
> + default:
> + return -EINVAL;
> + }
> +
> + return 0;
> +}
> +
> +static int platform_profile_set(struct platform_profile_handler *pprof,
> + enum platform_profile_option profile)
> {
> int err, tp;
>
> - tp = hp_wmi_read_int(HPWMI_THERMAL_PROFILE_QUERY);
> + switch (profile) {
> + case PLATFORM_PROFILE_PERFORMANCE:
> + tp = HP_THERMAL_PROFILE_PERFORMANCE;
> + break;
> + case PLATFORM_PROFILE_BALANCED:
> + tp = HP_THERMAL_PROFILE_DEFAULT;
> + break;
> + case PLATFORM_PROFILE_COOL:
> + tp = HP_THERMAL_PROFILE_COOL;
> + break;
> + default:
> + return -EOPNOTSUPP;
> + }
> +
> + err = thermal_profile_set(tp);
> + if (err)
> + return err;
> +
> + return 0;
> +}
> +
> +static int thermal_profile_setup(void)
> +{
> + int err, tp;
> +
> + tp = thermal_profile_get();
> if (tp < 0)
> return tp;
>
> @@ -881,11 +953,23 @@ static int thermal_profile_setup(struct platform_device *device)
> * call thermal profile write command to ensure that the firmware correctly
> * sets the OEM variables for the DPTF
> */
> - err = hp_wmi_perform_query(HPWMI_THERMAL_PROFILE_QUERY, HPWMI_WRITE, &tp,
> - sizeof(tp), 0);
> + err = thermal_profile_set(tp);
> if (err)
> return err;
>
> + platform_profile_handler.profile_get = platform_profile_get,
> + platform_profile_handler.profile_set = platform_profile_set,
> +
> + set_bit(PLATFORM_PROFILE_COOL, platform_profile_handler.choices);
> + set_bit(PLATFORM_PROFILE_BALANCED, platform_profile_handler.choices);
> + set_bit(PLATFORM_PROFILE_PERFORMANCE, platform_profile_handler.choices);
> +
> + err = platform_profile_register(&platform_profile_handler);
> + if (err)
> + return err;
> +
> + platform_profile_support = true;
> +
> return 0;
> }
>
> @@ -900,7 +984,7 @@ static int __init hp_wmi_bios_setup(struct platform_device *device)
> if (hp_wmi_rfkill_setup(device))
> hp_wmi_rfkill2_setup(device);
>
> - thermal_profile_setup(device);
> + thermal_profile_setup();
>
> return 0;
> }
> @@ -927,6 +1011,9 @@ static int __exit hp_wmi_bios_remove(struct platform_device *device)
> rfkill_destroy(wwan_rfkill);
> }
>
> + if (platform_profile_support)
> + platform_profile_remove();
> +
> return 0;
> }
>
>
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2021-03-04 13:29 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-21 21:04 [PATCH 2/2] platform/x86: hp-wmi: add platform profile support Elia Devito
2021-02-21 21:30 ` [PATCH v2 " Elia Devito
2021-02-21 21:51 ` Barnabás Pőcze
2021-02-21 22:13 ` [PATCH v3 " Elia Devito
2021-02-22 9:55 ` Hans de Goede
2021-03-04 13:26 ` Hans de Goede
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.