From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8848B606A329 for ; Wed, 2 Dec 2026 14:23:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=keSscN4x Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 4C47C10EA44; Wed, 2 Dec 2026 14:23:01 +0000 (UTC) Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.21]) by gabe.freedesktop.org (Postfix) with ESMTPS id B744F10E9E4 for ; Wed, 2 Dec 2026 14:22:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796221375; x=1827757375; h=date:from:to:cc:subject:message-id:references: in-reply-to:mime-version; bh=27RZJ9dOY+LW2/gQf6Y4a/V59oSI4lW0ggU1AC0+iu8=; b=keSscN4xWa2RVCO2LA4TMCGwH7db3kGzQaRhd+2OzZ6DDw2XAOrthkJ0 MuLo7XE30IWvUE01j41rAcOz+e9nUO+fkjBB8iOagZSg+WcbUZZT/eXLC x4QFXeq1JEGIm2hWGYFyIHtBTr9TgvEK88Xkot2I68f6+saLMEALClA4L e2Xs0GM5BKq+72Sw/Y3yMwW4fuVVDYu+gNdQnL4T/dF67Z1H4XQp3RcNx HB2VD6Bj39FQcbLbE7IeGHYJReGDXPMbr8H43mMI4JBOr3ufOkdC8QI7T Lj7FeBXzh8cOfNBx1EsH/DvlEnuHn8tcPwmywWyIOK/+ZMgA9JY/ilhEQ w==; X-CSE-ConnectionGUID: V9de6nMIRtymXVWhpzedig== X-CSE-MsgGUID: rzaPitydSpSokM7XVdPp+A== X-IronPort-AV: E=McAfee;i="6800,10657,11984"; a="5252669" X-IronPort-AV: E=Sophos;i="6.27,246,1787036400"; d="scan'208";a="5252669" Received: from orviesa006.jf.intel.com ([10.64.159.146]) by orvoesa113.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Dec 2026 06:22:55 -0800 X-CSE-ConnectionGUID: J9rkE4iNSlCbrmZeAO7ucA== X-CSE-MsgGUID: qqFjxUkvSYiUo7al6E8GcA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,246,1787036400"; d="scan'208";a="13494047" Received: from orsmsx901.amr.corp.intel.com ([10.22.229.23]) by orviesa006.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Dec 2026 06:22:54 -0800 Received: from ORSMSX903.amr.corp.intel.com (10.22.229.25) by ORSMSX901.amr.corp.intel.com (10.22.229.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.57; Wed, 2 Dec 2026 06:22:54 -0800 Received: from ORSEDG903.ED.cps.intel.com (10.7.248.13) by ORSMSX903.amr.corp.intel.com (10.22.229.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.57 via Frontend Transport; Wed, 2 Dec 2026 06:22:54 -0800 Received: from PH7PR06CU001.outbound.protection.outlook.com (52.101.201.60) by edgegateway.intel.com (134.134.137.113) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.57; Wed, 2 Dec 2026 06:22:53 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=S/fcgmarydI6cCWcBsKy+fJFqOk0c3cwjtKNzcjlBCe3CJSGlj52jcyvV+Gvwq6DSHlpHO1u7Tu7gTjrV6ZYABYIlrq7a+syWg4OvvjevnCdKnk1+e0T42n4YtE0eSJhQPzUbPN8M6e/ebEPG/ShWZlzZInUqDlKSrgMSMNCZLr2KSksWZeVO5JUeLUAaHCW4AfzG9vwCsORE9cPPE592+rJV/VI9tS+m2jPMr9ShoYBcGtx9N/6DUSqyZTQ7lzTU7PMizuPETU6EBQcoiwUdgmQeGyvPv+2EiAiryHCifGFGxw123nJM3jT6GGIKD7tBr6doTKPKBbKiTDndR0dPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=27RZJ9dOY+LW2/gQf6Y4a/V59oSI4lW0ggU1AC0+iu8=; b=iu+LRvTKeyuu4CPt4ljIXqLVH6mmiKFzETZtBxUDNyAJ2to8ZK2i5mkJ6xCr1GfMFiB3vhbmk1SY+yac6KdWmgKpk52bTVPpTReNLiGlw4pNRew11Hj6PGduQbJg2j9i13U2pevm1Ul+P6EvkqnUZ68Cu69B8/4EJGvJh7k97rWG7Gp9bMcTWz3za9Ogrxh7g1T8SV3DhAKIV+Qv9NArCUnPpJJjaI20oF5lWzCt4CPxsl388ueKx6oHr6N9vOHMsVRDcI3Yp7gBPuL+Mwd/wDtMYHG3UPSdb3WeNnePp6Vi14+Nf68eE6OPvI2YekM9JxlZUmzxNxl20zu9Bg1wxQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Authentication-Results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; Received: from DS7PR11MB5990.namprd11.prod.outlook.com (2603:10b6:8:71::5) by PH7PR11MB6979.namprd11.prod.outlook.com (2603:10b6:510:207::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.662.7; Wed, 2 Dec 2026 14:22:51 +0000 Received: from DS7PR11MB5990.namprd11.prod.outlook.com ([fe80::133c:5eed:3aec:b899]) by DS7PR11MB5990.namprd11.prod.outlook.com ([fe80::133c:5eed:3aec:b899%3]) with mapi id 15.21.0688.009; Wed, 2 Dec 2026 14:22:51 +0000 Date: Wed, 2 Dec 2026 09:22:47 -0500 From: Rodrigo Vivi To: Karthik Poosa CC: , , , , , , , , Subject: Re: [PATCH v7 05/10] drm/xe/hwmon: Expose pwm[1-3]_enable Message-ID: References: <20261202125637.1581881-1-karthik.poosa@intel.com> <20261202125637.1581881-6-karthik.poosa@intel.com> Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20261202125637.1581881-6-karthik.poosa@intel.com> X-ClientProxiedBy: BY3PR03CA0025.namprd03.prod.outlook.com (2603:10b6:a03:39a::30) To DS7PR11MB5990.namprd11.prod.outlook.com (2603:10b6:8:71::5) X-Archived-By: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS7PR11MB5990:EE_|PH7PR11MB6979:EE_ X-MS-Office365-Filtering-Correlation-Id: 251fabd1-c23b-4a40-c064-08df507fbf14 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|23010399003|376014|366016|1800799024|4143699003|18002099003|261009223027099003|6133799003|22082099003|3023799007|261022105027099003|11063799006|10067099003|56012099006|261022113327099003|261022115727099003|261102123227099003|261021121427099003|261026140227099003|261021123027099003|261026121527099003|261022075727099003|261028144727099003; X-Microsoft-Antispam-Message-Info: AlbyS5QAMWnNHbVWfgJfboF5XuE10bhbdYpgSxZJ7t4nST9qGYDQE6wjO2VWj3Ws3r/mWxArxw+NlXU4KYA3YqlhOhddk7/iCpYtnTDGc9AlbLMos3L8k62sIqYjCuqt2nBDb0OWZ49UfEZ1rqyQxv5wAba5MKDp8O7MrFj1UMKEep0uecqyV7vp9cF3mYlaYl0WS17c4b3rbOhp8YefW5wtbSyrLaLehqJ/lJHJJ88a87r+nkZE3/9zZbXJLx8XxrkiY4yquI/9Q8wMbrePjgRvHDMrSTeb3Z/S9B4VE2eVj5Qk5q4O1Hugj5w1epTvJv9IiFTW5/3smJeGhU+M0tK6mzsO2peA9RlyrristOc3NhiWNntNCVuWDmsYPvMp4qwiqgiNCqRlGD3y0WxzMmm0jdvNKpCdazNX7x2bsZDZ+cMItZQ/itsHBAlgsWmBccg0xyYZ6LuMXjPr+l47CbZ+OOiIyn/osTJ9+AF82ujC00kUJMrvQlOuE8wQBp5LPRyixbkBQa70Q9RI1nWH8B0aVzqmS9wzks4rrXvn8pvc9/VAC3+Fi6lveAZB3JAANk8p5aycISj6wTQjB4c2MqGe86ico6hVlwS1gFG9yhpZJ5EyvrEiziRqYo7CAXVP2ZgNE5UMKyI0IUAuUKaP2MOHdWiU92bc33zGeae19cY= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DS7PR11MB5990.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(23010399003)(376014)(366016)(1800799024)(4143699003)(18002099003)(261009223027099003)(6133799003)(22082099003)(3023799007)(261022105027099003)(11063799006)(10067099003)(56012099006)(261022113327099003)(261022115727099003)(261102123227099003)(261021121427099003)(261026140227099003)(261021123027099003)(261026121527099003)(261022075727099003)(261028144727099003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?zOqfdu/qS3EA7ijt3gzuc0uiU1qdo3hDwPGmF8iJ1nGeWaJj0vY0LzVqR5VF?= =?us-ascii?Q?tCuILCSBN8Vh09FpspPIWysRBivFqtL1vyc/qMVoAIm6cLdNs+HZ6UZ4eI8z?= =?us-ascii?Q?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ghUawY5mPPSGnqRdDXkVAZosk2VyR8O4MbbSpBCOLFABPOoG6fyKe6FqXhZWvPNXucLm77EAH7PqjRD2M2vq2sKdqryhzQR8ed9wdnVsLmGrm1Sz8ZYS7XsBWjL5k7hhraDc/8tjGLWi8JzVMqyegLjCfNdTubDS8VU0Um/SRSw0oHEiGggzrOWw6rnNYZWj4YQ176a0yCpvdN9IByuwEJK8evHQpUvH8Y7D/fw== X-MS-Exchange-CrossTenant-Network-Message-Id: 251fabd1-c23b-4a40-c064-08df507fbf14 X-MS-Exchange-CrossTenant-AuthSource: DS7PR11MB5990.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Dec 2026 14:22:50.9301 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Iul5sY/+m8aH17OO4hADs3EWOw5Aji9Pb0N3Ax88W3kLDtWM1YIPP7Kr18iydh+6n8H/Lr5dZ4maIBSI2mGTBw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR11MB6979 X-OriginatorOrg: intel.com X-BeenThere: intel-xe@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel Xe graphics driver List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Intel-xe" X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 On Wed, Dec 02, 2026 at 06:26:32PM +0530, Karthik Poosa wrote: > Expose pwm[1-3]_enable to control the fan operating mode through > the hwmon interface. > > Mode 0 forces the fan to run at full speed. > Mode 1 enables user fan-table control. > Mode 2 restores firmware-controlled fan management. > > pwm[1-3] writes now require pwm[1-3]_enable to be 1 first. Since fans > start in mode 2 after probe, a pwm[1-3] write without selecting manual > mode is rejected with -EINVAL. > > Document pwm[1-3]_enable in the Xe hwmon ABI. > > Signed-off-by: Karthik Poosa Reviewed-by: Rodrigo Vivi > --- > > v2: > - Use xe helpers for dmesg logs. > - Update kernel version in Xe hwmon documentation. > - Correct level of some dmesg logs. > > v3: > - Each pwm_enable mode now sets its own state; drop the redundant > post-switch pwm_enable_mode/is_full_speed update. (Badal) > - Fix misindented dead assignment in the stock-table branch. > - Make error handling consistent across pwm_enable modes. (Badal) > - Document the pwm[1-3] manual-mode write precondition in the ABI. (Badal) > - Use xe_pcode_write() instead of the timeout variant api as it is not > needed. > > v4: > - Rebase on reworked pwm[1-3] patch. > - Clamp min PWM to 100% when activating the user table, since fan > table speed is in percent. > - Drop redundant channel range check in pwm write. > - Use tab indentation and update Date and KernelVersion to November > 2026 and 7.5 in the pwm[1-3]_enable ABI entry. > > v5: > - Address review comments from sashiko. > - Avoid returning pwm[1-3]_enable as XE_FAN_PWM_MANUAL_USER_TABLE, when > setting to full speed mode. (sashiko) > - Set default pwm[1-3]_enable to XE_FAN_PWM_AUTO_STOCK_TABLE after > probe. (sashiko) > - Make pwm[1-3]_enable visible only if stock fan table has valid point > count. > - Add flag XE_FAN_PWM_UNINITIALIZED. > - Fall back to the stock table if firmware does not accept a table. > > v6: > - Remove is_full_speed as it is redundant with pwm_enable_mode now. > - Rename xe_hwmon_get_stock_table_pwm() to xe_hwmon_get_active_table_pwm(). > - Avoid overwriting user table cache for full speed. > - Align pwm_enable mode kernel-doc with the ABI wording. (Soham) > - Add debug logs before -EINVAL returns. (Soham) > - Note the pwm[1-3] write precondition in the commit message. (Soham) > > v7: > - Use xe_hwmon_commit_user_fan_table() helper in > xe_hwmon_activate_user_fan_table() for table update. (Badal) > - Return -ENODATA from pwm[1-3] reads on BMG too while the fan control > mode is not established. (sashiko) > - Add debug log if fan control mode is uninitialized. (Rodrigo) > - Made source_table const in xe_hwmon_commit_user_fan_table(). > - Added a user_table pointer for stock-table cache updates. > - Avoided redundant cache updates when the source is already > USER_FAN_TABLE. > > .../ABI/testing/sysfs-driver-intel-xe-hwmon | 19 ++ > drivers/gpu/drm/xe/xe_hwmon.c | 196 +++++++++++++++--- > 2 files changed, 187 insertions(+), 28 deletions(-) > > diff --git a/Documentation/ABI/testing/sysfs-driver-intel-xe-hwmon b/Documentation/ABI/testing/sysfs-driver-intel-xe-hwmon > index 34c50f13f0b4..dbf2c6d01376 100644 > --- a/Documentation/ABI/testing/sysfs-driver-intel-xe-hwmon > +++ b/Documentation/ABI/testing/sysfs-driver-intel-xe-hwmon > @@ -354,4 +354,23 @@ Contact: intel-xe@lists.freedesktop.org > Description: RW. Target fan PWM duty value in the range 0..255, where 255 > is 100% fan speed. > > + Writing requires the corresponding pwm[1-3]_enable to be set to > + 1 (manual user-table mode) first; otherwise the write is > + rejected with -EINVAL. > + > + Only supported for particular Intel Xe graphics platforms. > + > +What: /sys/bus/pci/drivers/xe/.../hwmon/hwmon/pwm[1-3]_enable > +Date: December 2026 > +KernelVersion: 7.5 > +Contact: intel-xe@lists.freedesktop.org > +Description: RW. Fan control mode selector. > + > + Use value 0 to run fans at full speed. Use value 1 to enable > + user table control and value 2 to use firmware default behavior. > + > + The user fan curve is kept across modes 0 and 2, and re-applied > + when switching back to 1. Without a user curve, mode 1 starts > + from the firmware stock curve. > + > Only supported for particular Intel Xe graphics platforms. > diff --git a/drivers/gpu/drm/xe/xe_hwmon.c b/drivers/gpu/drm/xe/xe_hwmon.c > index dd6f1f97fbf7..4eca1aa43564 100644 > --- a/drivers/gpu/drm/xe/xe_hwmon.c > +++ b/drivers/gpu/drm/xe/xe_hwmon.c > @@ -139,6 +139,20 @@ struct xe_hwmon_energy_info { > long accum_energy; > }; > > +/** > + * enum xe_fan_pwm_enable_mode - fan PWM enable modes > + */ > +enum xe_fan_pwm_enable_mode { > + /** @XE_FAN_PWM_FULL_SPEED: run the fan at full speed */ > + XE_FAN_PWM_FULL_SPEED = 0, > + /** @XE_FAN_PWM_MANUAL_USER_TABLE: user table control */ > + XE_FAN_PWM_MANUAL_USER_TABLE = 1, > + /** @XE_FAN_PWM_AUTO_STOCK_TABLE: firmware default behavior using the stock table */ > + XE_FAN_PWM_AUTO_STOCK_TABLE = 2, > + /** @XE_FAN_PWM_UNINITIALIZED: fan control mode is not established */ > + XE_FAN_PWM_UNINITIALIZED = 0xff, > +}; > + > /** > * enum fan_table_type - fan table types tracked per fan > */ > @@ -190,6 +204,8 @@ struct xe_hwmon_fan_info { > } fan_table[FAN_TABLE_MAX]; > /** @max_rps: maximum fan RPS */ > u32 max_rps; > + /** @pwm_enable_mode: current xe_fan_pwm_enable_mode */ > + u8 pwm_enable_mode; > }; > > /** > @@ -926,7 +942,9 @@ static const struct hwmon_channel_info * const hwmon_info[] = { > HWMON_CHANNEL_INFO(energy, HWMON_E_INPUT | HWMON_E_LABEL, HWMON_E_INPUT | HWMON_E_LABEL), > HWMON_CHANNEL_INFO(fan, HWMON_F_INPUT | HWMON_F_MAX, HWMON_F_INPUT | HWMON_F_MAX, > HWMON_F_INPUT | HWMON_F_MAX), > - HWMON_CHANNEL_INFO(pwm, HWMON_PWM_INPUT, HWMON_PWM_INPUT, HWMON_PWM_INPUT), > + HWMON_CHANNEL_INFO(pwm, HWMON_PWM_INPUT | HWMON_PWM_ENABLE, > + HWMON_PWM_INPUT | HWMON_PWM_ENABLE, > + HWMON_PWM_INPUT | HWMON_PWM_ENABLE), > NULL > }; > > @@ -1211,11 +1229,14 @@ static int xe_hwmon_fan_set_auto(struct xe_hwmon *hwmon, u8 fan) > PCODE_MBOX(FAN_SPEED_CONTROL, FSC_WRITE_NUM_FAN_CONTROL_POINTS, fan), > 0); > if (ret) > - return ret; > - > - fi->fan_table[USER_FAN_TABLE].point_count = 0; > + goto fail; > > + fi->pwm_enable_mode = XE_FAN_PWM_AUTO_STOCK_TABLE; > return 0; > + > +fail: > + fi->pwm_enable_mode = XE_FAN_PWM_UNINITIALIZED; > + return ret; > } > > static int xe_hwmon_commit_user_fan_table(struct xe_hwmon *hwmon, u8 fan, > @@ -1291,6 +1312,56 @@ static int xe_hwmon_commit_user_fan_table(struct xe_hwmon *hwmon, u8 fan, > return 0; > } > > +static int xe_hwmon_activate_user_fan_table(struct xe_hwmon *hwmon, u8 fan, > + bool is_full_speed, enum fan_table_type table_source) > +{ > + struct xe_hwmon_fan_info *fi = &hwmon->fi[fan]; > + struct fan_control_point points[MAX_FAN_CONTROL_POINTS]; > + const struct fan_table *source_table; > + u32 point_count, point; > + int ret; > + > + source_table = &fi->fan_table[table_source]; > + > + xe_dbg(hwmon->xe, "activating fan %d user table from %s table\n", fan, > + (table_source == USER_FAN_TABLE) ? "user" : "stock"); > + > + point_count = source_table->point_count; > + if (!point_count || point_count > MAX_FAN_CONTROL_POINTS) { > + xe_err(hwmon->xe, > + "fan %d %s table point count %u is invalid, cannot activate user table\n", > + fan, (table_source == USER_FAN_TABLE) ? "user" : "stock", point_count); > + return -EINVAL; > + } > + > + for (point = 0; point < point_count; point++) { > + points[point].temp = source_table->fcp[point].temp; > + points[point].speed = is_full_speed ? 100 : > + min_t(u8, source_table->fcp[point].speed, 100); > + } > + > + ret = xe_hwmon_commit_user_fan_table(hwmon, fan, points, point_count); > + if (ret) > + return ret; > + > + /* Full speed only overrides firmware; the cache keeps the manual curve. */ > + if (table_source == STOCK_FAN_TABLE) { > + struct fan_table *user_table = &fi->fan_table[USER_FAN_TABLE]; > + > + for (point = 0; point < point_count; point++) { > + user_table->fcp[point].temp = source_table->fcp[point].temp; > + user_table->fcp[point].speed = > + min_t(u8, source_table->fcp[point].speed, 100); > + } > + user_table->point_count = point_count; > + } > + > + fi->pwm_enable_mode = is_full_speed ? XE_FAN_PWM_FULL_SPEED : > + XE_FAN_PWM_MANUAL_USER_TABLE; > + > + return 0; > +} > + > /* Temperature to set when setting the fan PWM with pwm[1-3]. */ > #define FIXED_PWM_TEMP 1 > > @@ -1302,6 +1373,11 @@ static int xe_hwmon_set_user_fan_pwm(struct xe_hwmon *hwmon, u8 fan, u8 pwm) > int ret, i; > u8 speed; > > + if (fi->pwm_enable_mode != XE_FAN_PWM_MANUAL_USER_TABLE) { > + xe_dbg(hwmon->xe, "fan %d manual mode is not active, cannot set pwm\n", fan); > + return -EINVAL; > + } > + > /* Fan table speed are in percent. */ > speed = min_t(u32, DIV_ROUND_CLOSEST(pwm * 100, U8_MAX), 100); > > @@ -1401,6 +1477,8 @@ static int xe_hwmon_read_fan_control_info(struct xe_hwmon *hwmon) > stock_fcp_count * sizeof(stock_fcp[0])); > fi->fan_table[STOCK_FAN_TABLE].point_count = stock_fcp_count; > found = true; > + if (fi->pwm_enable_mode == XE_FAN_PWM_UNINITIALIZED) > + fi->pwm_enable_mode = XE_FAN_PWM_AUTO_STOCK_TABLE; > } > > /* Succeed if any enabled fan's stock table was read. */ > @@ -1965,6 +2043,7 @@ xe_hwmon_pwm_is_visible(struct xe_hwmon *hwmon, u32 attr, int channel) > > switch (attr) { > case hwmon_pwm_input: > + case hwmon_pwm_enable: > return 0644; > default: > return 0; > @@ -2024,25 +2103,43 @@ xe_hwmon_fan_read(struct xe_hwmon *hwmon, u32 attr, int channel, long *val) > } > } > > +static enum fan_table_type xe_hwmon_get_active_fan_table(struct xe_hwmon *hwmon, u8 fan) > +{ > + return (hwmon->fi[fan].pwm_enable_mode == XE_FAN_PWM_AUTO_STOCK_TABLE) ? STOCK_FAN_TABLE : > + USER_FAN_TABLE; > +} > + > /** > - * xe_hwmon_get_stock_table_pwm - Calculate PWM from the stock fan curve > + * xe_hwmon_get_active_table_pwm - Calculate PWM from the active fan curve > * @hwmon: hwmon instance, with hwmon_lock held and runtime PM active > * @channel: fan channel > * @val: calculated PWM percentage > * > - * Read package temperature and linearly interpolate the stock table. Temperatures > - * outside the table range use the speed at the nearest endpoint. > + * Read package temperature and linearly interpolate the fan table selected by > + * pwm_enable. Temperatures outside the table range use the nearest endpoint. > * > * Return: 0 on success, or a negative error code. > */ > -static int xe_hwmon_get_stock_table_pwm(struct xe_hwmon *hwmon, int channel, long *val) > +static int xe_hwmon_get_active_table_pwm(struct xe_hwmon *hwmon, int channel, long *val) > { > - const struct fan_table *table = &hwmon->fi[channel].fan_table[STOCK_FAN_TABLE]; > + const struct fan_table *table; > long temperature, pwm; > int point, ret; > > lockdep_assert_held(&hwmon->hwmon_lock); > > + switch (hwmon->fi[channel].pwm_enable_mode) { > + case XE_FAN_PWM_UNINITIALIZED: > + return -ENODATA; > + case XE_FAN_PWM_FULL_SPEED: > + *val = 100; > + return 0; > + default: > + break; > + } > + > + table = &hwmon->fi[channel].fan_table[xe_hwmon_get_active_fan_table(hwmon, channel)]; > + > if (!table->point_count) > return -ENODATA; > > @@ -2070,7 +2167,7 @@ static int xe_hwmon_get_stock_table_pwm(struct xe_hwmon *hwmon, int channel, lon > } > > *val = pwm; > - xe_dbg(hwmon->xe, "fan %d stock table active PWM value: %ld\n", channel, pwm); > + xe_dbg(hwmon->xe, "fan %d: pwm value from active table cache: %ld\n", channel, pwm); > return 0; > } > > @@ -2139,25 +2236,25 @@ xe_hwmon_pwm_read(struct xe_hwmon *hwmon, u32 attr, int channel, long *val) > > switch (attr) { > case hwmon_pwm_input: > - /* If the user fan table is not populated, get active stock pwm */ > - if (!fi->fan_table[USER_FAN_TABLE].point_count) { > - xe_dbg(hwmon->xe, "user fan table not active for fan %d\n", channel); > - switch (hwmon->xe->info.platform) { > - case XE_BATTLEMAGE: > + switch (hwmon->xe->info.platform) { > + case XE_BATTLEMAGE: > + if (fi->pwm_enable_mode == XE_FAN_PWM_UNINITIALIZED) > + ret = -ENODATA; > + else > ret = xe_hwmon_get_pwm_from_pmt(hwmon, channel, &pwm); > - break; > - default: > - ret = xe_hwmon_get_stock_table_pwm(hwmon, channel, &pwm); > - break; > - } > - if (ret) > - goto unlock; > - } else { > - /* > - * pwmN writes set every user-table point to the same speed, > - * so the first point gives the cached manual PWM percentage. > - */ > - pwm = fi->fan_table[USER_FAN_TABLE].fcp[0].speed; > + break; > + default: > + ret = xe_hwmon_get_active_table_pwm(hwmon, channel, &pwm); > + break; > + } > + if (ret == -ENODATA) { > + xe_dbg(hwmon->xe, "fan %d control mode not established\n", channel); > + goto unlock; > + } > + if (ret) { > + xe_err(hwmon->xe, "failed to get active pwm for fan %d, ret=%d\n", > + channel, ret); > + goto unlock; > } > if (pwm < 0 || pwm > 100) { > xe_dbg(hwmon->xe, "invalid PWM value %ld read for fan %d\n", pwm, channel); > @@ -2168,6 +2265,14 @@ xe_hwmon_pwm_read(struct xe_hwmon *hwmon, u32 attr, int channel, long *val) > *val = DIV_ROUND_CLOSEST(pwm * U8_MAX, 100); > xe_dbg(hwmon->xe, "pwm read for fan %d: %ld\n", channel, *val); > break; > + case hwmon_pwm_enable: > + if (fi->pwm_enable_mode == XE_FAN_PWM_UNINITIALIZED) { > + xe_dbg(hwmon->xe, "fan %d control mode is not initialized\n", channel); > + ret = -ENODATA; > + goto unlock; > + } > + *val = fi->pwm_enable_mode; > + break; > default: > ret = -EOPNOTSUPP; > break; > @@ -2181,8 +2286,11 @@ xe_hwmon_pwm_read(struct xe_hwmon *hwmon, u32 attr, int channel, long *val) > static int > xe_hwmon_pwm_write(struct xe_hwmon *hwmon, u32 attr, int channel, long val) > { > + struct xe_hwmon_fan_info *fi; > int ret = 0; > > + fi = &hwmon->fi[channel]; > + > mutex_lock(&hwmon->hwmon_lock); > > switch (attr) { > @@ -2194,6 +2302,33 @@ xe_hwmon_pwm_write(struct xe_hwmon *hwmon, u32 attr, int channel, long val) > } > ret = xe_hwmon_set_user_fan_pwm(hwmon, channel, (u8)val); > break; > + case hwmon_pwm_enable: > + if (val == XE_FAN_PWM_FULL_SPEED || val == XE_FAN_PWM_MANUAL_USER_TABLE) { > + bool full_speed = val == XE_FAN_PWM_FULL_SPEED; > + /* Without a user curve, start from the clamped stock table. */ > + enum fan_table_type source = fi->fan_table[USER_FAN_TABLE].point_count ? > + USER_FAN_TABLE : STOCK_FAN_TABLE; > + > + ret = xe_hwmon_activate_user_fan_table(hwmon, channel, full_speed, source); > + if (ret) > + xe_warn(hwmon->xe, "failed to set fan %d pwm_enable %ld, ret=%d\n", > + channel, val, ret); > + } else if (val == XE_FAN_PWM_AUTO_STOCK_TABLE) { > + ret = xe_hwmon_fan_set_auto(hwmon, channel); > + if (ret) { > + xe_warn(hwmon->xe, > + "failed to switch fan %d to automatic stock control, ret=%d\n", > + channel, ret); > + break; > + } > + xe_dbg(hwmon->xe, > + "automatic control enabled for fan %d using stock table\n", > + channel); > + } else { > + xe_dbg(hwmon->xe, "invalid pwm%d_enable value %ld\n", channel + 1, val); > + ret = -EINVAL; > + } > + break; > default: > ret = -EOPNOTSUPP; > break; > @@ -2407,6 +2542,7 @@ int xe_hwmon_register(struct xe_device *xe) > { > struct device *dev = xe->drm.dev; > struct xe_hwmon *hwmon; > + int fan; > int ret; > > /* hwmon is available only for dGfx */ > @@ -2421,6 +2557,10 @@ int xe_hwmon_register(struct xe_device *xe) > if (!hwmon) > return -ENOMEM; > > + /* Zero is XE_FAN_PWM_FULL_SPEED; stay unset until the stock table is read. */ > + for (fan = 0; fan < FAN_MAX; fan++) > + hwmon->fi[fan].pwm_enable_mode = XE_FAN_PWM_UNINITIALIZED; > + > ret = devm_mutex_init(dev, &hwmon->hwmon_lock); > if (ret) > return ret; > -- > 2.34.1 >