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 59DA4606A332 for ; Thu, 3 Dec 2026 09:05:52 +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=YDINilDN Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1AB5E1120F4; Thu, 3 Dec 2026 09:05:47 +0000 (UTC) Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.18]) by gabe.freedesktop.org (Postfix) with ESMTPS id AFDDC1120FA for ; Thu, 3 Dec 2026 09:05:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796288741; x=1827824741; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=VX3ZTwlDMY+ndEht2SoXmQK8lzO6WtZg6eFVXNjrIGc=; b=YDINilDNQF1wIhrQbhlmg4K7/nm8WMYSA4wguYvEJ5LUJ2FHTasN9iAz oVwE5Rn/gpRJE+q+c0ghlGrIQa1hb2cJcZ7s6kJiniphNytUu8693y/iK JkHmeLKHzNYMrn7ZuZulY5F13TAq7N4iZu47QEvVbXw9lMSs63lBoT3tn nxcU0wWgVi/tL5pktQkhYMvR2D/A6ixA11+O0iKtwpS9Ad+lB7oly+7h8 HDXZnSy/caGJH77mT3U4t7tCfTiX3qfyGQ8f9dswrPUPGCoK8ixfJ31yA 4rmFDSogMu6x3/H/DB9otIMx8yKBSWLRGthHsW+rOWwasXYpU21zWNImf Q==; X-CSE-ConnectionGUID: 5BNpXGlXTSi12EVrGg1wcQ== X-CSE-MsgGUID: RePwg4/sTgiCo+iwskE3Aw== X-IronPort-AV: E=McAfee;i="6800,10657,11984"; a="5254264" X-IronPort-AV: E=Sophos;i="6.27,248,1787036400"; d="scan'208";a="5254264" Received: from fmviesa013.fm.intel.com ([10.60.135.153]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Dec 2026 01:05:41 -0800 X-CSE-ConnectionGUID: KAAxMZrpSC+jsNiTKisWdg== X-CSE-MsgGUID: GqGoisl6Suy3bdZgtBHF5Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,248,1787036400"; d="scan'208";a="15730389" Received: from sinjan-super-server.iind.intel.com ([10.190.239.39]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Dec 2026 01:05:38 -0800 From: Karthik Poosa To: intel-xe@lists.freedesktop.org Cc: rodrigo.vivi@intel.com, anshuman.gupta@intel.com, badal.nilawar@intel.com, raag.jadav@intel.com, soham.purkait@intel.com, riana.tauro@intel.com, Karthik Poosa Subject: [PATCH v11 07/11] drm/xe/hwmon: Enable fan curve control support Date: Thu, 3 Dec 2026 14:37:01 +0530 Message-Id: <20261203090705.2500610-8-karthik.poosa@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261203090705.2500610-1-karthik.poosa@intel.com> References: <20261203090705.2500610-1-karthik.poosa@intel.com> X-Archived-By: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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=-18.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,USER_AGENT_GIT 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 Expose curve-point temperature and pwm controls via pwmF_auto_point[P]_temp and pwmF_auto_point[P]_pwm, where F is the fan number and P is the fan curve point number. Each fan curve point has a temperature and a pwm attribute. Stage writes until the curve ends with a (0, 0) marker or all points are supplied. Validate the curve before programming it; on firmware rejection, attempt to restore stock mode and return an error. Update Xe hwmon ABI documentation for pwm auto point temperature attributes. Reviewed-by: Rodrigo Vivi Signed-off-by: Karthik Poosa --- v2: - Use xe helpers for dmesg logs. - Update kernel version in Xe hwmon documentation. - Correct debug level of some dmesg logs. v3: - Allow variable fan curve points from >=2 to MAX_FAN_CONTROL_POINTS. - Expose all MAX_FAN_CONTROL_POINTS fan-curve slots so users can extend a short fan table. - Stage temp/PWM pairs without changing the active curve. Commit at a (0, 0) end marker or after all MAX_FAN_CONTROL_POINTS pairs. - Write the points together, verify the firmware count, then update the active cache. v4: - Use the two-argument IS_FAN_ENABLED() after rebase. - Fix kernel-doc for nested staged fan_table members. - Use "speed" for percent values and "pwm" only for the 0..255 sysfs value. (Soham) - Use u32 for the point index in xe_hwmon_commit_user_fan_table(). (Soham) - Fix comment to say curve points must not decrease. (Soham) - Add debug logs before -EINVAL returns. (Soham) - Drop inline from xe_hwmon_get_active_fan_table(). (Soham) - Use reverse xmas tree ordering for local variables. (Soham) - Rename xe_hwmon_get_u8_from_sysfs() to xe_hwmon_sysfs_to_hw_val(). (Soham) - Use if/else if/else for value selection in pwm auto point show. (Soham) - Create the fan curve sensor attributes at probe time instead of 60 static definitions. (Soham) - Clamp min PWM to 100% and reject pwm values above 100% speed. - Use xe helpers for logs in the auto point store functions. v5: - Address review comments from Sashiko. - Remove min_pwm as it is not available. - Read back the user point count after curve programming and fall back to stock control when firmware does not accept it. v6: - Require strictly increasing temperatures across curve points, as firmware rejects equal temperatures. - Reject tables with fewer than MIN_FAN_CONTROL_POINTS before writing to firmware. - Expose pwmN_auto_point* only when the fan has a stock table, like pwmN_enable. - Return -ENODATA from pwmN_auto_point* reads while the fan control mode is not established, like pwmN and pwmN_enable. - Add the missing ABI documentation for pwm[1-3]_auto_point[1-10]_temp and pwm[1-3]_auto_point[1-10]_pwm. - Use reverse xmas tree ordering in xe_hwmon_activate_user_fan_table(). (Soham) - Drop the else after return in xe_hwmon_get_active_fan_table(). (Soham) - Keep staged curve points when the user table is re-applied on resume or after late binding; clear them only on pwm_enable writes. (sashiko) - Document that a failed completing curve write drops all staged points. (Soham) v7: - xe_hwmon_commit_user_fan_table() and xe_hwmon_activate_user_fan_table() are moved to previous patches. Refactor this patch accordingly. .../ABI/testing/sysfs-driver-intel-xe-hwmon | 46 +++ drivers/gpu/drm/xe/xe_hwmon.c | 361 +++++++++++++++++- 2 files changed, 394 insertions(+), 13 deletions(-) diff --git a/Documentation/ABI/testing/sysfs-driver-intel-xe-hwmon b/Documentation/ABI/testing/sysfs-driver-intel-xe-hwmon index dbf2c6d01376..81c0c8217d4a 100644 --- a/Documentation/ABI/testing/sysfs-driver-intel-xe-hwmon +++ b/Documentation/ABI/testing/sysfs-driver-intel-xe-hwmon @@ -374,3 +374,49 @@ Description: RW. Fan control mode selector. from the firmware stock curve. Only supported for particular Intel Xe graphics platforms. + +What: /sys/bus/pci/drivers/xe/.../hwmon/hwmon/pwm[1-3]_auto_point[1-10]_temp +Date: December 2026 +KernelVersion: 7.5 +Contact: intel-xe@lists.freedesktop.org +Description: RW. Temperature of fan curve point in millidegree Celsius. + + Reads return the point of the stock fan curve when + pwm[1-3]_enable is 2 and of the user fan curve otherwise. Unused + points read 0. Reads fail with -ENODATA while the fan control + mode is not established. + + Writes stage the user curve point and require pwm[1-3]_enable + to be 1; otherwise they are rejected with -EINVAL. See + pwm[1-3]_auto_point[1-10]_pwm for how the curve is committed. + + Only supported for particular Intel Xe graphics platforms. + +What: /sys/bus/pci/drivers/xe/.../hwmon/hwmon/pwm[1-3]_auto_point[1-10]_pwm +Date: December 2026 +KernelVersion: 7.5 +Contact: intel-xe@lists.freedesktop.org +Description: RW. Fan PWM duty of fan curve point in the range 0..255, where + 255 is 100% fan speed. Firmware stores the duty in percent, so + reads return the value rounded to the nearest percent step. + + Reads return the point of the stock fan curve when + pwm[1-3]_enable is 2 and of the user fan curve otherwise. Unused + points read 0. Reads fail with -ENODATA while the fan control + mode is not established. + + Writes stage the user curve point and require pwm[1-3]_enable + to be 1; otherwise they are rejected with -EINVAL. Nonzero + values are kept at least 1%. + + The staged curve is programmed once points 1..K all have both a + temperature and a PWM value and either point K+1 is set to + temperature 0 and PWM 0, or K is 10. The end marker is not part + of the curve. The curve needs at least two points, temperature + must increase and PWM must not decrease from one point to the + next; otherwise the completing write fails with -EINVAL. A + completing write that fails drops all staged points. If + firmware does not accept the curve, the fan falls back to + pwm[1-3]_enable 2 and the write fails. + + 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 614fb392f899..1891b0006000 100644 --- a/drivers/gpu/drm/xe/xe_hwmon.c +++ b/drivers/gpu/drm/xe/xe_hwmon.c @@ -181,6 +181,11 @@ enum fan_table_type { /* Minimum number of points required for a user fan table. */ #define MIN_FAN_CONTROL_POINTS 2 +/* pwmN_auto_pointM_temp and pwmN_auto_pointM_pwm for every curve point of a fan. */ +#define XE_CURVE_ATTRS_PER_FAN (2 * MAX_FAN_CONTROL_POINTS) +#define XE_CURVE_ATTRS (FAN_MAX * XE_CURVE_ATTRS_PER_FAN) +#define XE_CURVE_ATTR_NAME_LEN sizeof("pwmN_auto_pointNN_temp") + /* Fan control point index: bit31 selects fan table type; bits30:0 control point index. */ #define FCP_INDEX(table_type, point_num) (((u32)(table_type) << 31) | \ ((u32)(point_num) & GENMASK(30, 0))) @@ -208,6 +213,12 @@ struct xe_hwmon_fan_info { /** @fan_table.fcp.speed: fan speed in percentage */ u8 speed; } fcp[MAX_FAN_CONTROL_POINTS]; + /** @fan_table.staged_fcp: curve supplied via sysfs but not yet committed */ + struct fan_control_point staged_fcp[MAX_FAN_CONTROL_POINTS]; + /** @fan_table.temp_staged: bitmask of temperature fields supplied via sysfs */ + u16 temp_staged; + /** @fan_table.speed_staged: bitmask of speed fields supplied via sysfs */ + u16 speed_staged; } fan_table[FAN_TABLE_MAX]; /** @max_rps: maximum fan RPS */ u32 max_rps; @@ -273,6 +284,16 @@ struct xe_hwmon { u32 pl2_on_boot[CHANNEL_MAX]; /** @temp: Temperature info */ struct xe_hwmon_thermal_info temp; + /** @curve_sda: fan curve sensor attributes */ + struct sensor_device_attribute curve_sda[XE_CURVE_ATTRS]; + /** @curve_names: names of the fan curve sensor attributes */ + char curve_names[XE_CURVE_ATTRS][XE_CURVE_ATTR_NAME_LEN]; + /** @curve_attrs: NULL-terminated list of fan curve attributes */ + struct attribute *curve_attrs[XE_CURVE_ATTRS + 1]; + /** @curve_group: fan curve attribute group */ + struct attribute_group curve_group; + /** @groups: NULL-terminated list of extra attribute groups */ + const struct attribute_group *groups[3]; }; static inline int prepare_power_limit_param2(const struct xe_hwmon *hwmon, int channel) @@ -917,11 +938,6 @@ static const struct attribute_group hwmon_attrgroup = { .is_visible = xe_hwmon_attributes_visible, }; -static const struct attribute_group *hwmon_groups[] = { - &hwmon_attrgroup, - NULL -}; - static const u32 hwmon_temp_config[CHANNEL_MAX + 1] = { [CHANNEL_CARD] = HWMON_T_LABEL, [CHANNEL_PKG] = HWMON_T_CRIT | HWMON_T_EMERGENCY | HWMON_T_INPUT | @@ -1404,11 +1420,324 @@ static int xe_hwmon_set_user_fan_pwm(struct xe_hwmon *hwmon, u8 fan, u8 pwm) /* Update the user fan table cache. */ memcpy(user_table->fcp, points, sizeof(points)); user_table->point_count = MIN_FAN_CONTROL_POINTS; + user_table->temp_staged = 0; + user_table->speed_staged = 0; xe_dbg(hwmon->xe, "applied pwm %u (%u%%) for fan %d\n", pwm, speed, fan); return 0; } +#define XE_CURVE_IDX(fan, point) (((fan) << 8) | (point)) +#define XE_CURVE_FAN(idx) ((u8)(((idx) >> 8) & 0xff)) +#define XE_CURVE_POINT(idx) ((u8)((idx) & 0xff)) + +static int +xe_hwmon_decode_curve_index(struct xe_hwmon *hwmon, u32 index, u8 *fan, u8 *point) +{ + u8 local_fan = XE_CURVE_FAN(index); + u8 local_point = XE_CURVE_POINT(index); + + if (local_fan >= FAN_MAX || local_point >= MAX_FAN_CONTROL_POINTS) { + xe_dbg(hwmon->xe, "invalid fan curve index 0x%x: fan %u point %u\n", + index, local_fan, local_point); + return -EINVAL; + } + + *fan = local_fan; + *point = local_point; + + return 0; +} + +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; +} + +static ssize_t +xe_hwmon_pwm_auto_point_temp_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr); + struct xe_hwmon *hwmon = dev_get_drvdata(dev); + enum fan_table_type active_table; + struct xe_hwmon_fan_info *fi; + u32 point_count; + u8 point; + u8 temp; + int ret; + u8 fan; + + ret = xe_hwmon_decode_curve_index(hwmon, sattr->index, &fan, &point); + if (ret) + return ret; + + guard(mutex)(&hwmon->hwmon_lock); + + fi = &hwmon->fi[fan]; + if (fi->pwm_enable_mode == XE_FAN_PWM_UNINITIALIZED) + return -ENODATA; + + active_table = xe_hwmon_get_active_fan_table(hwmon, fan); + + point_count = fi->fan_table[active_table].point_count; + + if (point >= point_count) + temp = 0; + else + temp = fi->fan_table[active_table].fcp[point].temp; + return sysfs_emit(buf, "%u\n", temp * MILLIDEGREE_PER_DEGREE); +} + +static int xe_hwmon_update_user_fan_point(struct xe_hwmon *hwmon, u8 fan, u32 point, + bool is_temp, u8 value) +{ + struct xe_hwmon_fan_info *fi = &hwmon->fi[fan]; + struct fan_table *table; + u32 point_count; + int ret; + + table = &fi->fan_table[USER_FAN_TABLE]; + + if (is_temp) { + table->staged_fcp[point].temp = value; + table->temp_staged |= BIT(point); + } else { + table->staged_fcp[point].speed = value; + table->speed_staged |= BIT(point); + } + + /* Wait for a complete prefix; (0, 0) ends the curve without becoming a point. */ + for (point_count = 0; point_count < MAX_FAN_CONTROL_POINTS; point_count++) { + if (!(table->temp_staged & BIT(point_count)) || + !(table->speed_staged & BIT(point_count))) + return 0; + if (!table->staged_fcp[point_count].temp && + !table->staged_fcp[point_count].speed) + break; + } + + if (point_count < MIN_FAN_CONTROL_POINTS) { + xe_dbg(hwmon->xe, "fan %d curve needs at least %d points, got %u\n", + fan, MIN_FAN_CONTROL_POINTS, point_count); + ret = -EINVAL; + goto clear_staged; + } + + ret = xe_hwmon_commit_user_fan_table(hwmon, fan, table->staged_fcp, point_count); + if (ret) + goto clear_staged; + + /* Publish the new curve only after firmware accepts its point count. */ + memcpy(table->fcp, table->staged_fcp, point_count * sizeof(table->fcp[0])); + table->point_count = point_count; + fi->pwm_enable_mode = XE_FAN_PWM_MANUAL_USER_TABLE; + +clear_staged: + table->temp_staged = 0; + table->speed_staged = 0; + return ret; +} + +static int xe_hwmon_sysfs_to_hw_val(struct xe_hwmon *hwmon, long val, bool is_temp, u8 *out) +{ + long max = is_temp ? U8_MAX * MILLIDEGREE_PER_DEGREE : U8_MAX; + long hw_val; + + if (val < 0 || val > max) { + xe_dbg(hwmon->xe, "%s value %ld out of range\n", is_temp ? "temp" : "pwm", val); + return -EINVAL; + } + + /* Temperature is in degrees Celsius, speed in percent. */ + if (is_temp) + hw_val = DIV_ROUND_CLOSEST(val, MILLIDEGREE_PER_DEGREE); + else + hw_val = DIV_ROUND_CLOSEST(val * 100, U8_MAX); + + if (!is_temp && val && !hw_val) + hw_val = 1; + + *out = hw_val; + + return 0; +} + +static ssize_t +xe_hwmon_pwm_auto_point_temp_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr); + struct xe_hwmon *hwmon = dev_get_drvdata(dev); + struct xe_hwmon_fan_info *fi; + long val; + u8 point; + u8 temp; + int ret; + u8 fan; + + ret = xe_hwmon_decode_curve_index(hwmon, sattr->index, &fan, &point); + if (ret) + return ret; + + ret = kstrtol(buf, 10, &val); + if (ret) + return ret; + + ret = xe_hwmon_sysfs_to_hw_val(hwmon, val, true, &temp); + if (ret) + return ret; + + guard(xe_pm_runtime)(hwmon->xe); + + guard(mutex)(&hwmon->hwmon_lock); + fi = &hwmon->fi[fan]; + + if (fi->pwm_enable_mode != XE_FAN_PWM_MANUAL_USER_TABLE) { + xe_dbg(hwmon->xe, "pwm%d_enable not in manual mode; cannot update temp point %d\n", + fan + 1, point + 1); + return -EINVAL; + } + + xe_dbg(hwmon->xe, "staging fan %d point %d temp to %u\n", fan, point, temp); + ret = xe_hwmon_update_user_fan_point(hwmon, fan, point, true, temp); + + return ret ? ret : count; +} + +static ssize_t +xe_hwmon_pwm_auto_point_pwm_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr); + struct xe_hwmon *hwmon = dev_get_drvdata(dev); + enum fan_table_type active_table; + struct xe_hwmon_fan_info *fi; + u32 point_count; + u8 point; + u8 speed; + int ret; + u8 fan; + + ret = xe_hwmon_decode_curve_index(hwmon, sattr->index, &fan, &point); + if (ret) + return ret; + + guard(mutex)(&hwmon->hwmon_lock); + + fi = &hwmon->fi[fan]; + if (fi->pwm_enable_mode == XE_FAN_PWM_UNINITIALIZED) + return -ENODATA; + + active_table = xe_hwmon_get_active_fan_table(hwmon, fan); + + point_count = fi->fan_table[active_table].point_count; + + if (point >= point_count) + speed = 0; + else + speed = fi->fan_table[active_table].fcp[point].speed; + return sysfs_emit(buf, "%u\n", DIV_ROUND_CLOSEST(speed * U8_MAX, 100)); +} + +static ssize_t +xe_hwmon_pwm_auto_point_pwm_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr); + struct xe_hwmon *hwmon = dev_get_drvdata(dev); + struct xe_hwmon_fan_info *fi; + long val; + u8 point; + u8 speed; + int ret; + u8 fan; + + ret = xe_hwmon_decode_curve_index(hwmon, sattr->index, &fan, &point); + if (ret) + return ret; + + ret = kstrtol(buf, 10, &val); + if (ret) + return ret; + + ret = xe_hwmon_sysfs_to_hw_val(hwmon, val, false, &speed); + if (ret) + return ret; + + guard(xe_pm_runtime)(hwmon->xe); + + guard(mutex)(&hwmon->hwmon_lock); + fi = &hwmon->fi[fan]; + + if (fi->pwm_enable_mode != XE_FAN_PWM_MANUAL_USER_TABLE) { + xe_dbg(hwmon->xe, + "pwm%d_enable is not in manual user mode, cannot update pwm point %d\n", + fan + 1, point + 1); + return -EINVAL; + } + + xe_dbg(hwmon->xe, "staging fan %d point %d speed to %u%%\n", fan, point, speed); + ret = xe_hwmon_update_user_fan_point(hwmon, fan, point, false, speed); + + return ret ? ret : count; +} + +static umode_t xe_hwmon_curve_attributes_visible(struct kobject *kobj, + struct attribute *attr, int index) +{ + struct device *dev = kobj_to_dev(kobj); + struct xe_hwmon *hwmon = dev_get_drvdata(dev); + u32 fan = index / XE_CURVE_ATTRS_PER_FAN; + + /* Manual mode, and thus curve writes, need a stock table, as for pwmN_enable. */ + if (!hwmon->xe->info.has_fan_control || !IS_FAN_ENABLED(hwmon, fan) || + hwmon->fi[fan].fan_table[STOCK_FAN_TABLE].point_count < MIN_FAN_CONTROL_POINTS) + return 0; + + /* All slots must exist at registration, before the user curve has been staged. */ + return attr->mode; +} + +static void xe_hwmon_init_curve_attrs(struct xe_hwmon *hwmon) +{ + int fan, kind, point, i = 0; + + /* Per fan: all temp points then all pwm points; is_visible relies on this layout. */ + for (fan = 0; fan < FAN_MAX; fan++) { + for (kind = 0; kind < 2; kind++) { + bool is_temp = !kind; + + for (point = 0; point < MAX_FAN_CONTROL_POINTS; point++, i++) { + struct sensor_device_attribute *sda = &hwmon->curve_sda[i]; + + snprintf(hwmon->curve_names[i], XE_CURVE_ATTR_NAME_LEN, + "pwm%d_auto_point%d_%s", fan + 1, point + 1, + is_temp ? "temp" : "pwm"); + sysfs_attr_init(&sda->dev_attr.attr); + sda->dev_attr.attr.name = hwmon->curve_names[i]; + sda->dev_attr.attr.mode = 0644; + if (is_temp) { + sda->dev_attr.show = xe_hwmon_pwm_auto_point_temp_show; + sda->dev_attr.store = xe_hwmon_pwm_auto_point_temp_store; + } else { + sda->dev_attr.show = xe_hwmon_pwm_auto_point_pwm_show; + sda->dev_attr.store = xe_hwmon_pwm_auto_point_pwm_store; + } + sda->index = XE_CURVE_IDX(fan, point); + hwmon->curve_attrs[i] = &sda->dev_attr.attr; + } + } + } + + hwmon->curve_group.attrs = hwmon->curve_attrs; + hwmon->curve_group.is_visible = xe_hwmon_curve_attributes_visible; +} + static int xe_hwmon_read_fan_control_info(struct xe_hwmon *hwmon) { bool found = false; @@ -2110,12 +2439,6 @@ 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_active_table_pwm - Calculate PWM from the active fan curve * @hwmon: hwmon instance, with hwmon_lock held and runtime PM active @@ -2317,9 +2640,13 @@ xe_hwmon_pwm_write(struct xe_hwmon *hwmon, u32 attr, int channel, long val) USER_FAN_TABLE : STOCK_FAN_TABLE; ret = xe_hwmon_activate_user_fan_table(hwmon, channel, full_speed, source); - if (ret) + if (ret) { xe_warn(hwmon->xe, "failed to set fan %d pwm_enable %ld, ret=%d\n", channel, val, ret); + break; + } + fi->fan_table[USER_FAN_TABLE].temp_staged = 0; + fi->fan_table[USER_FAN_TABLE].speed_staged = 0; } else if (val == XE_FAN_PWM_AUTO_STOCK_TABLE) { ret = xe_hwmon_fan_set_auto(hwmon, channel); if (ret) { @@ -2331,6 +2658,8 @@ xe_hwmon_pwm_write(struct xe_hwmon *hwmon, u32 attr, int channel, long val) xe_dbg(hwmon->xe, "automatic control enabled for fan %d using stock table\n", channel); + fi->fan_table[USER_FAN_TABLE].temp_staged = 0; + fi->fan_table[USER_FAN_TABLE].speed_staged = 0; } else { xe_dbg(hwmon->xe, "invalid pwm%d_enable value %ld\n", channel + 1, val); ret = -EINVAL; @@ -2582,10 +2911,16 @@ int xe_hwmon_register(struct xe_device *xe) drm_dbg(&xe->drm, "Register xe hwmon interface\n"); + hwmon->groups[0] = &hwmon_attrgroup; + if (xe->info.has_fan_control) { + xe_hwmon_init_curve_attrs(hwmon); + hwmon->groups[1] = &hwmon->curve_group; + } + /* hwmon_dev points to device hwmon */ hwmon->hwmon_dev = hwmon_device_register_with_info(dev, "xe", hwmon, &hwmon_chip_info, - hwmon_groups); + hwmon->groups); if (IS_ERR(hwmon->hwmon_dev)) { ret = PTR_ERR(hwmon->hwmon_dev); xe_log_err(xe, HWMON, ret, "Failed to register xe hwmon\n"); -- 2.34.1