From nobody Sun Nov 24 07:00:33 2024 Received: from mout.gmx.net (mout.gmx.net [212.227.15.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 23083802; Thu, 7 Nov 2024 00:39:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=212.227.15.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730939960; cv=none; b=SIYJPAPrmAmxgs5Pp55Kf9SJTH/q+lNgf/n8j/XQGVEPYtWt1cgNs34MiWj1vHfzarMQ+9zEClsryhuqsyJDot9hprkRs9w5+hurYPloZJDWYHRG7cRtfcDJ2JEE+s+LsT9g4n+SdCBsZj9G75NtP3cvC8tbo4Oi+GLTVkoDm3Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730939960; c=relaxed/simple; bh=TT7HlVRFxw1GAd62T5Q4/Ve33tNll6qGnDMOCZPzNMg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=hjoK6OxjIgik8nY3R2A5YpWhH9zc18LA/Q3lrmaKY27TyjtC5JDb7JC6XEp8H7VqI0Jkxs6b5vR2XBYrgDOAz9Zy76PEb+/ceXg6j19YAKWeeFAG9e83p5Lmb+MioYZAHaLERwrqfYncGj0BMjKQW0TrT1kmEBPmLhpGI8lTe2g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=gmx.de; spf=pass smtp.mailfrom=gmx.de; dkim=pass (2048-bit key) header.d=gmx.de header.i=w_armin@gmx.de header.b=YXTohGg0; arc=none smtp.client-ip=212.227.15.19 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=gmx.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmx.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmx.de header.i=w_armin@gmx.de header.b="YXTohGg0" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.de; s=s31663417; t=1730939901; x=1731544701; i=w_armin@gmx.de; bh=LNOp/yeIPjPfCtSw3lO1DGc24JRvcgll0Xua2h+ZKOk=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:Message-Id:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding:cc: content-transfer-encoding:content-type:date:from:message-id: mime-version:reply-to:subject:to; b=YXTohGg0eh9FSNXOY/6HXhon/7OsEcnZyZT66uPWYRdKqAB22y5EQF2n2IFaHnQM z3ROhYLdG2bYnWo1w8J435xGJGDGwjHp63sBX7eZ8cemrWZPWD0/HavhyT87X+t0/ PCv+2z9tJ0EQUo4/gr2Jwwx/6mYWYwDeSiMuq7fIlL4FX9rV2BT3+l7We1Xj0mygP mBkjwhY0qqsJ4LYm/cj7NO88Fe9IeVPccNw7IlUmifBsJNKc6NKGbKWnWVhG/9aeM 6BIREdzzhemJUV/HnzBrXTPow/mPIibGbAZgbtf+k+0aAf1f1wkX31tTbntL4+WBs q8pPlmUyZPVHiHW3Kg== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from mx-amd-b650.users.agdsn.de ([141.30.226.129]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1Mz9Yv-1u55SQ2xvf-013Qy8; Thu, 07 Nov 2024 01:38:21 +0100 From: Armin Wolf To: corentin.chary@gmail.com, luke@ljones.dev, mohamed.ghanmi@supcom.tn Cc: srinivas.pandruvada@linux.intel.com, hdegoede@redhat.com, ilpo.jarvinen@linux.intel.com, Michael@phoronix.com, casey.g.bowman@intel.com, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 1/2] platform/x86: asus-wmi: Fix inconsistent use of thermal policies Date: Thu, 7 Nov 2024 01:38:10 +0100 Message-Id: <20241107003811.615574-2-W_Armin@gmx.de> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241107003811.615574-1-W_Armin@gmx.de> References: <20241107003811.615574-1-W_Armin@gmx.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:a0IKNqKRmere3yeM5Ftg85jMXrSaYMXOwodfQ3b/dgYv1oUUYsw BFccwAaDBpo7f8HAGNr+GuM0jpO9Z4Vme5SfC+lhdGwTjHhoanmAJfamJ9WgdTD+BDva8dq M1bUXUtdh8xrhx1oz4PyNssz9WqNsMofBLk/RRfhV+uOLINxlpcg61TCoTPrHdlseqQ3+0C gCeL952VdMcZTZFi5LuVg== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:p3F9FySU/sA=;pCyc2Iq94lyk5YRuKydO2+hePGq wehf4LcACLjx9g4B+AxK5kui1f63aeDOv5NNRlWTHxT0yDYkjDsHVX4YpngjTVfsaqwNY+6Vz 7D9UN+SRzQP89Y2PREOcEC/bj2ZRXTIFmhGhc51AfeZwt6ImSaoiVdvd4IVeYW4ke6EVGuooH OYwfo+Oo/QWIz0PY+YEKbrmnXJ/Pu9PlDFQvXJEiPleV1s41rOlz/UwioVGgBVhY0ltokdorj fDGFcla+OpJmjVt40Y6FYqao46VvItWHlpSgBHLnexmrp3kx6se1jlkX+RMP4s/SO8wTIkdra I4fAnprrvMZ41wIhlFUzJgZDN7aS3R/uGqvXJnVBiARPuUWGWtRObhVaUraiDDCENCa43Yp8K 5ag2eWqqoasYroBQzozMvLkqcYrHYxouxfW6asAScgI8FXz8DgBj3/iJ8StDptVrgCsa7JUkO cnd4hZSx6wWCRFABDqxcV9mU5ry9iJt9tgU7KSSTHS3Vv8Y+9qNEGx9OrgTSc5A9G89mqmOKW qihbRkbT02k5DfwRpA7g43d7AFMqGSLWue08CDDuf4nyQuUx+HzcjVpM1MS/5KRn1m8q9lO2S vExVnyT3EEtLknt5FpY0UsjEfWSCXHB/EZ6exA4St+n3ZaRVU069tIKi452zi1dZktgPatByW hdLZICiaNo2DAxxQ//KZZCWZ/Fj9S/vQvtqTsMf6fEGTCmXNpcSHor8tUhXb3XaSdGUOhDKPk R2kPEXub7Vd2tfrOLoA1lwgIBPNTusayfb/gKN9dG5ZjTlb1MPQ48CIS1djJf9xoUdVSQAkH+ UBQ9kXdfqhmoNxADbXs9gSaD8AT0EMefOjQy/HI//786yXuRu/dH2Tqcht4fkxIVmF287UVay uGDqUdC3/bHUGwfizzKQNcS1IQIF0XT/quZP4ndQZ+lAEjGwybsR5wWok Content-Type: text/plain; charset="utf-8" When changing the thermal policy using the platform profile API, a Vivobook thermal policy is stored in throttle_thermal_policy_mode. However everywhere else a normal thermal policy is stored inside this variable, potentially confusing the platform profile. Fix this by always storing normal thermal policy values inside throttle_thermal_policy_mode and only do the conversion when writing the thermal policy to hardware. This also fixes the order in which throttle_thermal_policy_switch_next() steps through the thermal modes on Vivobook machines. Tested-by: Casey G Bowman Fixes: bcbfcebda2cb ("platform/x86: asus-wmi: add support for vivobook fan = profiles") Signed-off-by: Armin Wolf Reviewed-by: Hans de Goede --- drivers/platform/x86/asus-wmi.c | 64 +++++++++++---------------------- 1 file changed, 21 insertions(+), 43 deletions(-) diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wm= i.c index ab9342a01a48..ce60835d0303 100644 --- a/drivers/platform/x86/asus-wmi.c +++ b/drivers/platform/x86/asus-wmi.c @@ -3696,10 +3696,28 @@ static int asus_wmi_custom_fan_curve_init(struct as= us_wmi *asus) /* Throttle thermal policy ***********************************************= *****/ static int throttle_thermal_policy_write(struct asus_wmi *asus) { - u8 value =3D asus->throttle_thermal_policy_mode; u32 retval; + u8 value; int err; + if (asus->throttle_thermal_policy_dev =3D=3D ASUS_WMI_DEVID_THROTTLE_THER= MAL_POLICY_VIVO) { + switch (asus->throttle_thermal_policy_mode) { + case ASUS_THROTTLE_THERMAL_POLICY_DEFAULT: + value =3D ASUS_THROTTLE_THERMAL_POLICY_DEFAULT_VIVO; + break; + case ASUS_THROTTLE_THERMAL_POLICY_OVERBOOST: + value =3D ASUS_THROTTLE_THERMAL_POLICY_OVERBOOST_VIVO; + break; + case ASUS_THROTTLE_THERMAL_POLICY_SILENT: + value =3D ASUS_THROTTLE_THERMAL_POLICY_SILENT_VIVO; + break; + default: + return -EINVAL; + } + } else { + value =3D asus->throttle_thermal_policy_mode; + } + err =3D asus_wmi_set_devstate(asus->throttle_thermal_policy_dev, value, &retval); @@ -3804,46 +3822,6 @@ static ssize_t throttle_thermal_policy_store(struct = device *dev, static DEVICE_ATTR_RW(throttle_thermal_policy); /* Platform profile ******************************************************= *****/ -static int asus_wmi_platform_profile_to_vivo(struct asus_wmi *asus, int mo= de) -{ - bool vivo; - - vivo =3D asus->throttle_thermal_policy_dev =3D=3D ASUS_WMI_DEVID_THROTTLE= _THERMAL_POLICY_VIVO; - - if (vivo) { - switch (mode) { - case ASUS_THROTTLE_THERMAL_POLICY_DEFAULT: - return ASUS_THROTTLE_THERMAL_POLICY_DEFAULT_VIVO; - case ASUS_THROTTLE_THERMAL_POLICY_OVERBOOST: - return ASUS_THROTTLE_THERMAL_POLICY_OVERBOOST_VIVO; - case ASUS_THROTTLE_THERMAL_POLICY_SILENT: - return ASUS_THROTTLE_THERMAL_POLICY_SILENT_VIVO; - } - } - - return mode; -} - -static int asus_wmi_platform_profile_mode_from_vivo(struct asus_wmi *asus,= int mode) -{ - bool vivo; - - vivo =3D asus->throttle_thermal_policy_dev =3D=3D ASUS_WMI_DEVID_THROTTLE= _THERMAL_POLICY_VIVO; - - if (vivo) { - switch (mode) { - case ASUS_THROTTLE_THERMAL_POLICY_DEFAULT_VIVO: - return ASUS_THROTTLE_THERMAL_POLICY_DEFAULT; - case ASUS_THROTTLE_THERMAL_POLICY_OVERBOOST_VIVO: - return ASUS_THROTTLE_THERMAL_POLICY_OVERBOOST; - case ASUS_THROTTLE_THERMAL_POLICY_SILENT_VIVO: - return ASUS_THROTTLE_THERMAL_POLICY_SILENT; - } - } - - return mode; -} - static int asus_wmi_platform_profile_get(struct platform_profile_handler *= pprof, enum platform_profile_option *profile) { @@ -3853,7 +3831,7 @@ static int asus_wmi_platform_profile_get(struct platf= orm_profile_handler *pprof, asus =3D container_of(pprof, struct asus_wmi, platform_profile_handler); tp =3D asus->throttle_thermal_policy_mode; - switch (asus_wmi_platform_profile_mode_from_vivo(asus, tp)) { + switch (tp) { case ASUS_THROTTLE_THERMAL_POLICY_DEFAULT: *profile =3D PLATFORM_PROFILE_BALANCED; break; @@ -3892,7 +3870,7 @@ static int asus_wmi_platform_profile_set(struct platf= orm_profile_handler *pprof, return -EOPNOTSUPP; } - asus->throttle_thermal_policy_mode =3D asus_wmi_platform_profile_to_vivo(= asus, tp); + asus->throttle_thermal_policy_mode =3D tp; return throttle_thermal_policy_write(asus); } -- 2.39.5 From nobody Sun Nov 24 07:00:33 2024 Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0FD044A21; Thu, 7 Nov 2024 00:39:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=212.227.15.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730939962; cv=none; b=mTZfGYcpnmmUum/AqaBJA5cUu64lLZxIvjq0rVny8Q5NFy3vTNybUFcD9SSB/iw+f201R8H356ZeNqxYmzTLndkUiJOcxP4aE0jqWBja+/JjEzI2743cSg10XgKQuhAW89/WiqDraeklBj5SBVMqSC2ANvG1dx2+9qGESbc1aMY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730939962; c=relaxed/simple; bh=CiNGNmCtmcQqR4cHpsTtyoNSfQjxTODBNQfMf2zqCnY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=vEmLcSRvq9XwnenplRXi8Ltu+04NywOra5iFOkIaqgI4p6vRN37U14W6YPHdZrbrFpBniyboZlWMU2INcAjiueOEUI2xztt/mhDSHZNAyjq3Rkj31EGzj7ODcs1TyeXmq5d6ad+FxdlUg/4GhCoZ8pBwmu4oCNxGBSFUehV2cg8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=gmx.de; spf=pass smtp.mailfrom=gmx.de; dkim=pass (2048-bit key) header.d=gmx.de header.i=w_armin@gmx.de header.b=EWYbKHQh; arc=none smtp.client-ip=212.227.15.18 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=gmx.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmx.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmx.de header.i=w_armin@gmx.de header.b="EWYbKHQh" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.de; s=s31663417; t=1730939903; x=1731544703; i=w_armin@gmx.de; bh=4/K7RD8dkLVueUtuW32hIC1eLVwXkD29dLtXLraKleY=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:Message-Id:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding:cc: content-transfer-encoding:content-type:date:from:message-id: mime-version:reply-to:subject:to; b=EWYbKHQhE9GW6l6LrkfZncQLFBV9lLxQs6H9bxVGV4Yx7CQOLElJpc1ezZ+qWijW 4leK3CydLwJF2RwSwvmpXE/iRLj5JqSTQQOXQxaExP/UlMRr6pNojr7ILgbgNcYCR 8F9cAoFGE9bgILvMM92jqTDHuDAT1FplRDa/LXRp0HiYZxzWPMqbBwHS5fPKoDR2E iFE/tOVjjRa3tE63OAtrCn4L8RyNmYkcSgFI82wG67H9xYci6tFEMDLnJBPmuM9c0 pDwVE/fF2AMS+vuV90gc/vm8IPHA1ltn+1dTCCE5gh2Zbu4//3Ld4PDZKg+xsu3cs J1JzhN6fs7wio5OR6w== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from mx-amd-b650.users.agdsn.de ([141.30.226.129]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1Mkpf3-1tWvwH3bwd-00e19i; Thu, 07 Nov 2024 01:38:22 +0100 From: Armin Wolf To: corentin.chary@gmail.com, luke@ljones.dev, mohamed.ghanmi@supcom.tn Cc: srinivas.pandruvada@linux.intel.com, hdegoede@redhat.com, ilpo.jarvinen@linux.intel.com, Michael@phoronix.com, casey.g.bowman@intel.com, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 2/2] platform/x86: asus-wmi: Use platform_profile_cycle() Date: Thu, 7 Nov 2024 01:38:11 +0100 Message-Id: <20241107003811.615574-3-W_Armin@gmx.de> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241107003811.615574-1-W_Armin@gmx.de> References: <20241107003811.615574-1-W_Armin@gmx.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:p4rJly3IMJzDUYMLOcDzSU9ohGwXQolasZTR9MX1vJfDConvt+F cgfCN9pUFqmsEWrS7UREjNCg15NA464aFB/MCWBhjNXHus74lz0nekZztV2D4Vma+8Es/HT xLgNhotv5RKdp82ZgHzjV4kMtzKtt9Kx95s2MBWtRRGI84M5MaYg+9VSu0ULpxsTCG0pHpp yoYnbEkjT0rLZVsxjgx9Q== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:JEFWBE15POE=;12ktHUjGRDDfq+M0VeTMYs4fE15 PjrxW2m0a3Ido0Dvvd5gbdfnz183cZ6KxDOJrIdD+4Sjv8QST61cR7/pQLkYdNCBvmwRhW7+o P0iTX67vMHkS/LZu+Svr8FvSTjkPJICw9xeCo6hpECB+2RvgU3V2aD2cxsx5tR8nwkuDRZut+ agjOUwlOL7KXjqh7NVt3qjxYgbQhZE2l8bQ+ToJ5xd3gC7TVJ6Gw7fU0/QaefdXrsYfuqK0u3 A58+MjdSuIvg8+w+0iAMzCGINjL7Nb9ttVP2+BfFu3ewp1HMgcn/8L1subZESlY3YyhRkeemt WMh7GOWavTob4htTTuuq5jFKG7aEMXdrtfm/62Pv3jdc8Zq92+KFuzTEKGsqOwFpx5ajMsukS 3JYpJsZ4kSTyNz2UszX1tRtckCIJ5uDRfiXDW3SnQ9msbB0Jw1bMrahQX3s2hkwlbuQitz3Cw apA6+CGwxrYjfk4nSOtpyDbbBSNzJJS5J88Xnrb7oizb0kg32JmAYvCu2frN74GqmQ3sas04V vHzmX/qDMDOdESsZBKfx82h/fjGGT7cH/tNlfN34DClBWIuhhBrZAPcESZvJbXGs8GzUcbF+r B0snt2gqJlIhvcBtzfDEkR2LhRD6cBR95V+yupoiV2f2JLyVNuu8CbEAvFxOnfxkLt3zerPi+ G1dQ1Z2wUj3ugTT6W3vdxguo4RUg+PgOhJj2zsQ0gv2iOvazEBiFVTYRJY0fuuQcTLTjl53Rq wb+zIN/L5bwQKwswOizy6vBwZ9Ni2iJvl6GcW8p0CFuRCCLtmxWh/VSehILjTOljiiY8UVHAT 8WEgVbHxvib7k03dDFpdI00Jc2omIOE0qyWNyvD7SjVpdwfpTcYZm7zrnJMHFx0F4IF/c4RA2 TwWB5x28kBNjWL7vGKNtkeH5aZbLwbRYcly0uCQGVZw5C9MYak1fgJLoT Content-Type: text/plain; charset="utf-8" Replace throttle_thermal_policy_switch_next() with platform_profile_cycle() to reduce code duplication and avoid a potential race condition with the platform profile handler. Suggested-by: Hans de Goede Signed-off-by: Armin Wolf Reviewed-by: Hans de Goede --- drivers/platform/x86/asus-wmi.c | 24 +----------------------- 1 file changed, 1 insertion(+), 23 deletions(-) diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wm= i.c index ce60835d0303..ba8b6d028f9f 100644 --- a/drivers/platform/x86/asus-wmi.c +++ b/drivers/platform/x86/asus-wmi.c @@ -3755,28 +3755,6 @@ static int throttle_thermal_policy_set_default(struc= t asus_wmi *asus) return throttle_thermal_policy_write(asus); } -static int throttle_thermal_policy_switch_next(struct asus_wmi *asus) -{ - u8 new_mode =3D asus->throttle_thermal_policy_mode + 1; - int err; - - if (new_mode > PLATFORM_PROFILE_MAX) - new_mode =3D ASUS_THROTTLE_THERMAL_POLICY_DEFAULT; - - asus->throttle_thermal_policy_mode =3D new_mode; - err =3D throttle_thermal_policy_write(asus); - if (err) - return err; - - /* - * Ensure that platform_profile updates userspace with the change to ensu= re - * that platform_profile and throttle_thermal_policy_mode are in sync. - */ - platform_profile_notify(); - - return 0; -} - static ssize_t throttle_thermal_policy_show(struct device *dev, struct device_attribute *attr, char *buf) { @@ -4301,7 +4279,7 @@ static void asus_wmi_handle_event_code(int code, stru= ct asus_wmi *asus) if (asus->fan_boost_mode_available) fan_boost_mode_switch_next(asus); if (asus->throttle_thermal_policy_dev) - throttle_thermal_policy_switch_next(asus); + platform_profile_cycle(); return; } -- 2.39.5