From: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
To: "Luke D. Jones" <luke@ljones.dev>
Cc: Hans de Goede <hdegoede@redhat.com>,
corentin.chary@gmail.com, mohamed.ghanmi@supcom.tn,
platform-driver-x86@vger.kernel.org,
LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] platform/x86: asus-wmi: add support for vivobook fan profiles
Date: Tue, 16 Apr 2024 15:51:03 +0300 (EEST) [thread overview]
Message-ID: <dccc5701-f533-e80e-09f8-199f232f447f@linux.intel.com> (raw)
In-Reply-To: <20240413202112.37729-1-luke@ljones.dev>
On Sun, 14 Apr 2024, Luke D. Jones wrote:
> From: Mohamed Ghanmi <mohamed.ghanmi@supcom.tn>
>
> Add support for vivobook fan profiles wmi call on the ASUS VIVOBOOK
> to adjust power limits.
>
> These fan profiles have a different device id than the ROG series.
> and different order.
Fix grammar.
> This reorders the existing modes and adds a new
> full speed mode available on these laptops.
>
> As part of keeping the patch clean the throttle_thermal_policy_available
> boolean stored in the driver struct is removed and
> throttle_thermal_policy_dev is used in place (as on init it is zeroed).
>
> Signed-off-by: Mohamed Ghanmi <mohamed.ghanmi@supcom.tn>
> Co-developed-by: Luke D. Jones <luke@ljones.dev>
> Signed-off-by: Luke D. Jones <luke@ljones.dev>
> ---
> drivers/platform/x86/asus-wmi.c | 100 +++++++++++----------
> include/linux/platform_data/x86/asus-wmi.h | 1 +
> 2 files changed, 55 insertions(+), 46 deletions(-)
>
> diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c
> index 2d2b4eca7fd8..439d330fb80b 100644
> --- a/drivers/platform/x86/asus-wmi.c
> +++ b/drivers/platform/x86/asus-wmi.c
> @@ -97,6 +97,11 @@ module_param(fnlock_default, bool, 0444);
> #define ASUS_THROTTLE_THERMAL_POLICY_OVERBOOST 1
> #define ASUS_THROTTLE_THERMAL_POLICY_SILENT 2
>
> +#define ASUS_THROTTLE_THERMAL_POLICY_DEFAULT_VIVO 0
> +#define ASUS_THROTTLE_THERMAL_POLICY_OVERBOOST_VIVO 2
> +#define ASUS_THROTTLE_THERMAL_POLICY_SILENT_VIVO 1
Any good reason why these are not in numerical order?
> +#define ASUS_THROTTLE_THERMAL_POLICY_FULLSPEED 3
> +
> #define USB_INTEL_XUSB2PR 0xD0
> #define PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_XHCI 0x9c31
>
> @@ -285,8 +290,8 @@ struct asus_wmi {
> u32 kbd_rgb_dev;
> bool kbd_rgb_state_available;
>
> - bool throttle_thermal_policy_available;
> u8 throttle_thermal_policy_mode;
> + u32 throttle_thermal_policy_dev;
>
> bool cpu_fan_curve_available;
> bool gpu_fan_curve_available;
> @@ -3153,7 +3158,7 @@ static int fan_curve_get_factory_default(struct asus_wmi *asus, u32 fan_dev)
> int err, fan_idx;
> u8 mode = 0;
>
> - if (asus->throttle_thermal_policy_available)
> + if (asus->throttle_thermal_policy_dev)
> mode = asus->throttle_thermal_policy_mode;
> /* DEVID_<C/G>PU_FAN_CURVE is switched for OVERBOOST vs SILENT */
> if (mode == 2)
> @@ -3360,7 +3365,7 @@ static ssize_t fan_curve_enable_store(struct device *dev,
> * For machines with throttle this is the only way to reset fans
> * to default mode of operation (does not erase curve data).
> */
> - if (asus->throttle_thermal_policy_available) {
> + if (asus->throttle_thermal_policy_dev) {
> err = throttle_thermal_policy_write(asus);
> if (err)
> return err;
> @@ -3577,8 +3582,8 @@ static const struct attribute_group asus_fan_curve_attr_group = {
> __ATTRIBUTE_GROUPS(asus_fan_curve_attr);
>
> /*
> - * Must be initialised after throttle_thermal_policy_check_present() as
> - * we check the status of throttle_thermal_policy_available during init.
> + * Must be initialised after throttle_thermal_policy_dev is set as
> + * we check the status of throttle_thermal_policy_dev during init.
> */
> static int asus_wmi_custom_fan_curve_init(struct asus_wmi *asus)
> {
> @@ -3619,38 +3624,31 @@ static int asus_wmi_custom_fan_curve_init(struct asus_wmi *asus)
> }
>
> /* Throttle thermal policy ****************************************************/
> -
> -static int throttle_thermal_policy_check_present(struct asus_wmi *asus)
> -{
> - u32 result;
> - int err;
> -
> - asus->throttle_thermal_policy_available = false;
> -
> - err = asus_wmi_get_devstate(asus,
> - ASUS_WMI_DEVID_THROTTLE_THERMAL_POLICY,
> - &result);
> - if (err) {
> - if (err == -ENODEV)
> - return 0;
> - return err;
> - }
> -
> - if (result & ASUS_WMI_DSTS_PRESENCE_BIT)
> - asus->throttle_thermal_policy_available = true;
> -
> - return 0;
> -}
> -
> static int throttle_thermal_policy_write(struct asus_wmi *asus)
> {
> - int err;
> - u8 value;
> + u8 value = asus->throttle_thermal_policy_mode;
> u32 retval;
> + bool vivo;
> + int err;
>
> - value = asus->throttle_thermal_policy_mode;
> + vivo = asus->throttle_thermal_policy_dev == ASUS_WMI_DEVID_THROTTLE_THERMAL_POLICY_VIVO;
> + if (vivo) {
> + switch (value) {
> + case ASUS_THROTTLE_THERMAL_POLICY_DEFAULT:
> + value = ASUS_THROTTLE_THERMAL_POLICY_DEFAULT_VIVO;
> + break;
> + case ASUS_THROTTLE_THERMAL_POLICY_OVERBOOST:
> + value = ASUS_THROTTLE_THERMAL_POLICY_OVERBOOST_VIVO;
> + break;
> + case ASUS_THROTTLE_THERMAL_POLICY_SILENT:
> + value = ASUS_THROTTLE_THERMAL_POLICY_SILENT_VIVO;
> + break;
> + default:
> + break;
> + }
> + }
>
> - err = asus_wmi_set_devstate(ASUS_WMI_DEVID_THROTTLE_THERMAL_POLICY,
> + err = asus_wmi_set_devstate(asus->throttle_thermal_policy_dev,
> value, &retval);
>
> sysfs_notify(&asus->platform_device->dev.kobj, NULL,
> @@ -3680,7 +3678,7 @@ static int throttle_thermal_policy_write(struct asus_wmi *asus)
>
> static int throttle_thermal_policy_set_default(struct asus_wmi *asus)
> {
> - if (!asus->throttle_thermal_policy_available)
> + if (!asus->throttle_thermal_policy_dev)
> return 0;
>
> asus->throttle_thermal_policy_mode = ASUS_THROTTLE_THERMAL_POLICY_DEFAULT;
> @@ -3690,9 +3688,14 @@ static int throttle_thermal_policy_set_default(struct asus_wmi *asus)
> static int throttle_thermal_policy_switch_next(struct asus_wmi *asus)
> {
> u8 new_mode = asus->throttle_thermal_policy_mode + 1;
> + bool vivo;
> int err;
>
> - if (new_mode > ASUS_THROTTLE_THERMAL_POLICY_SILENT)
> + vivo = asus->throttle_thermal_policy_dev == ASUS_WMI_DEVID_THROTTLE_THERMAL_POLICY_VIVO;
> + if (!vivo && new_mode > ASUS_THROTTLE_THERMAL_POLICY_SILENT)
> + new_mode = ASUS_THROTTLE_THERMAL_POLICY_DEFAULT;
> +
> + if (vivo && new_mode > ASUS_THROTTLE_THERMAL_POLICY_FULLSPEED)
> new_mode = ASUS_THROTTLE_THERMAL_POLICY_DEFAULT;
Hmm, add a throttle_thermal_policy_max_mode() helper instead so you can do
just this:
if (new_mode > throttle_thermal_policy_max_mode(...))
new_mode = ASUS_THROTTLE_THERMAL_POLICY_DEFAULT;
> asus->throttle_thermal_policy_mode = new_mode;
> @@ -3725,13 +3728,17 @@ static ssize_t throttle_thermal_policy_store(struct device *dev,
> struct asus_wmi *asus = dev_get_drvdata(dev);
> u8 new_mode;
> int result;
> + bool vivo;
> int err;
>
> result = kstrtou8(buf, 10, &new_mode);
> if (result < 0)
> return result;
>
> - if (new_mode > ASUS_THROTTLE_THERMAL_POLICY_SILENT)
> + vivo = asus->throttle_thermal_policy_dev == ASUS_WMI_DEVID_THROTTLE_THERMAL_POLICY_VIVO;
> + if (vivo && new_mode > ASUS_THROTTLE_THERMAL_POLICY_FULLSPEED)
> + return -EINVAL;
> + else if (!vivo && new_mode > ASUS_THROTTLE_THERMAL_POLICY_SILENT)
Use the throttle_thermal_policy_max_mode() helper here too.
> return -EINVAL;
>
> asus->throttle_thermal_policy_mode = new_mode;
--
i.
next prev parent reply other threads:[~2024-04-16 12:51 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-13 20:21 [PATCH] platform/x86: asus-wmi: add support for vivobook fan profiles Luke D. Jones
2024-04-16 12:51 ` Ilpo Järvinen [this message]
2024-04-16 16:34 ` Mohamed Ghanmi
2024-04-17 6:28 ` Ilpo Järvinen
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=dccc5701-f533-e80e-09f8-199f232f447f@linux.intel.com \
--to=ilpo.jarvinen@linux.intel.com \
--cc=corentin.chary@gmail.com \
--cc=hdegoede@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=luke@ljones.dev \
--cc=mohamed.ghanmi@supcom.tn \
--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 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.