From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=198.175.65.17 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796126796; b=dVaL/S2si/bmfajHHKFRx0EHHECctvqfT2LdbREB2hgtB57JSQz/BcSxTwT8PkGtL2ZN XjNx2wy8UOclBAcSo54+ETN5B4ye4z4n/QSgBV8kE8Nj+46KYU+/vfJNQMgIW+aRW1Jqb EQ+x3sbYwopiEjFWL9JLEANCfhOnvCdgcN9DWR83IKHPNnADmxt3teciDE+W+0L/I1SsC 402s5DL0rG0wk/gexJeynnBmXPW1Rpe60ul/X/VprP7N0jxhq7ro8wsLE8WNjoV3s2gBy C1J040SVq92KShgmkUgtCQz/8TO32x+qLqi8XKyPyGEA8Jb3izNQhqa4PIJpYGVhK3Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796126796; h=DMARC-Filter:DKIM-Signature:X-CSE-ConnectionGUID:X-CSE-MsgGUID: X-IronPort-AV:X-IronPort-AV:Received:X-CSE-ConnectionGUID: X-CSE-MsgGUID:X-ExtLoop1:X-IronPort-AV:Received:From:Date:To:cc: Subject:In-Reply-To:Message-ID:References:MIME-Version:Content-Type; bh=DXLbaNOZC2ZfnemsLjlJdH+trOqSQmhzCvT6gGUHO5o=; b=FgnylZJ80+JD/kdhqCzJC+ELDzBdtAs1C3LTtJSNcL+wudyLcT2GU7Q4+/7lo4/SHin/ ICOfvj/bUqufsJnUdb8FcEORF7c0j5UiiXhokFuINh0yPDWDQh5j0sutCeKPVBcvLW4V+ Mv5G6q6fPPaoPSnNNRwnPuwE5Oj/JmDn51KKit1ETKWVvy3S2IWNH2mD7g8FDOdru+50j Jjuhcbzgh+Gr86ANl+bPoJHw0ia/rqpZPLpWgTwD5lINBRvv5dDNzG3T8dxLDm5MO6yza UOYNFSQZxwQpm3LQBsJBDGp9N9WcbO5FieWTsOtU60TNSzWwI8Ztj556SnLrmhDVQtQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.intel.com; spf=pass smtp.mailfrom=linux.intel.com; dkim=pass header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=LlwtNuUe; arc=none smtp.remote-ip=198.175.65.17 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 205EA606A335; Tue, 1 Dec 2026 12:06:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 205EA606A335 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=LlwtNuUe DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796126795; x=1827662795; h=from:date:to:cc:subject:in-reply-to:message-id: references:mime-version; bh=DXLbaNOZC2ZfnemsLjlJdH+trOqSQmhzCvT6gGUHO5o=; b=LlwtNuUedYtDSMZgWYBuySePeqeZwc/rYimpIb3TVqk7EJ4rh6UG1sJ4 I5XNPORf81tfP9XSkDlUxgYyTgMYYqwFyb52ZFtBxuP3oqs1FAUD1OPdh aNJHEGbkjqsG67R0OF0P3ktePTlnb5HgOSES6BFDfCxGwqUuTX8Hwovec oXXsDCCIgVUi7d2l82couVx1th3za8lqXk2CKZpUl8IldLzogccKctyAP fNHcnWrq4aQWoBCXXm4tDrB8JW7TC1VspXiTb3UboY88n1+oIPY8o7dhN NHlPSUt0fQ9ZJVOtOwxrdc0uip4F+2DczfQ1tGXm7iDduLea6nhlGhnTh g==; X-CSE-ConnectionGUID: 1/4AEOodRZimiboHDc68ag== X-CSE-MsgGUID: VYPH54nvTQS5XRiF6I0JwQ== X-IronPort-AV: E=McAfee;i="6800,10657,11983"; a="4999517" X-IronPort-AV: E=Sophos;i="6.27,244,1787036400"; d="scan'208";a="4999517" Received: from fmviesa002.fm.intel.com ([10.60.135.142]) by orvoesa109.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Dec 2026 04:06:35 -0800 X-CSE-ConnectionGUID: vGsjy55HSfCXO/qJYAqgJQ== X-CSE-MsgGUID: X1IqG7zdQAaEAv3VVwnMCg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,244,1787036400"; d="scan'208";a="13453648" Received: from pgcooper-mobl3.ger.corp.intel.com (HELO localhost) ([10.245.245.21]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Dec 2026 04:06:31 -0800 From: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= Date: Tue, 1 Dec 2026 14:06:28 +0200 (EET) To: =?ISO-8859-2?Q?Filip_Go=B3a=B6?= cc: =?ISO-8859-2?Q?Micha=B3_Kope=E6?= , Hans de Goede , platform-driver-x86@vger.kernel.org, linux-hwmon@vger.kernel.org, LKML , Guenter Roeck Subject: Re: [PATCH v4 3/3] platform/x86: dasharo-acpi: Add EC fan curve support In-Reply-To: <20261127084910.3355833-4-filip.golas@3mdeb.com> Message-ID: References: <20261127084910.3355833-1-filip.golas@3mdeb.com> <20261127084910.3355833-4-filip.golas@3mdeb.com> X-Mailing-List: linux-hwmon@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="8323328-835773488-1796126788=:1168" This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --8323328-835773488-1796126788=:1168 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: QUOTED-PRINTABLE On Fri, 27 Nov 2026, Filip Go=C5=82a=C5=9B wrote: > Expose the four-point fan curve run by the EC as pwmN_auto_pointM_temp > and pwmN_auto_pointM_pwm, so that userspace can read and change it. > The EC validates the curve on every write and keeps running the > previous one if the new curve is invalid. >=20 > On shutdown, ask the firmware to store the current curve, so that it is > restored on the next boot. >=20 > Fan curve control is only exposed for fans on which the firmware reports > support for it. >=20 > Signed-off-by: Filip Go=C5=82a=C5=9B Is it legal to have a non-monotonous curve? Should driver ensure it? > --- > Changes in v2: > - Make the curve point attributes static, so DASHARO_POINT_ATTRS() > does not define 16 global symbols. > - Reject negative fan curve temperatures before converting them to > degrees, which can round to positive. > - Use DIV_ROUND_CLOSEST_ULL() for showing curve PWM instead of > DIV_ROUND_CLOSEST(), so it links on 32-bit x86. > - Setting a curve point stages it, applying it is a separate ACPI call. > Add a mutex to prevent staging more changes before the first set is > applied. > - Use dasharo_fan_channel to find correct channel for DASHARO_FEATURE_FAN= _POINTS. > - SFCS now takes no arguments and saves all fans. The Dasharo dev > build previously was accepting and ignoring the argument. >=20 > Changes in v3: > - Fix inconsistent use of parentheses in DASHARO_POINT_ATTRS macro > - Create curve point attributes for all 24 PWM channels > - Use DIV_ROUND_CLOSEST for temperature unit conversion > - Use hwmon_lock instead of a private mutex >=20 > Changes in v4: > - Remove variable that became unused in v3 in dasharo_probe > - Fix incomplete creation of point attributes for PWM channels 3-24 > - Fix possible overflows in curve_point_temp_store after using DIV_ROUND_= CLOSEST > --- > drivers/platform/x86/dasharo-acpi.c | 227 +++++++++++++++++++++++++++- > 1 file changed, 226 insertions(+), 1 deletion(-) >=20 > diff --git a/drivers/platform/x86/dasharo-acpi.c b/drivers/platform/x86/d= asharo-acpi.c > index 85f88b11fcf9..ebbd9b7c8979 100644 > --- a/drivers/platform/x86/dasharo-acpi.c > +++ b/drivers/platform/x86/dasharo-acpi.c > @@ -6,6 +6,8 @@ > #include > #include > #include > +#include > +#include > #include > #include > #include > @@ -407,6 +409,217 @@ static const struct hwmon_chip_info dasharo_hwmon_c= hip_info =3D { > =09.info =3D dasharo_hwmon_info, > }; > =20 > +static int dasharo_curve_point_call(struct dasharo_data *data, int pwm_c= hannel, const char *method, > +=09=09=09=09 const u64 *args, unsigned int n_args, u64 *ret) > +{ > +=09int channel =3D dasharo_fan_channel(data, DASHARO_FEATURE_FAN_POINTS,= pwm_channel); > + > +=09if (channel < 0) Please keep call and its error handling together without blank lines in=20 between. You have to declare the variable separately because of that. > +=09=09return channel; > + > +=09return dasharo_call(data, method, DASHARO_FEATURE_FAN_POINTS, channel= , args, n_args, ret); > +} > + > +static int dasharo_curve_point_store(struct dasharo_data *data, int chan= nel, const char *method, > +=09=09=09=09 unsigned int point, u64 value) > +{ > +=09u64 args[2] =3D { point, value }; > +=09u64 ret; > +=09int err; > + > +=09// set of temp/duty > +=09err =3D dasharo_curve_point_call(data, channel, method, args, 2, &ret= ); > +=09if (err) > +=09=09return err; > +=09if (ret) > +=09=09return -EPERM; > + > +=09// commit > +=09err =3D dasharo_curve_point_call(data, channel, "CFCV", NULL, 0, &ret= ); > +=09if (err) > +=09=09return err; > + > +=09// The EC rejected the curve > +=09return ret ? -EINVAL : 0; > +} > + > +static ssize_t curve_point_temp_show(struct device *dev, struct device_a= ttribute *attr, char *buf) > +{ > +=09struct sensor_device_attribute_2 *sattr =3D to_sensor_dev_attr_2(attr= ); > +=09struct dasharo_data *data =3D dev_get_drvdata(dev); > +=09u64 point =3D sattr->index; > +=09u64 val; > +=09int err; > + > +=09guard(hwmon_lock)(dev); > + > +=09err =3D dasharo_curve_point_call(data, sattr->nr, "GFPT", &point, 1, = &val); > +=09if (err) > +=09=09return err; > + > +=09return sysfs_emit(buf, "%llu\n", val * MILLIDEGREE_PER_DEGREE); Add include. > +} > + > +static ssize_t curve_point_temp_store(struct device *dev, struct device_= attribute *attr, > +=09=09=09=09 const char *buf, size_t count) > +{ > +=09struct sensor_device_attribute_2 *sattr =3D to_sensor_dev_attr_2(attr= ); > +=09struct dasharo_data *data =3D dev_get_drvdata(dev); > +=09long val; > +=09int err; > + > +=09err =3D kstrtol(buf, 10, &val); > +=09if (err) > +=09=09return err; > + > +=09if (val < 0 || val > U8_MAX * MILLIDEGREE_PER_DEGREE) > +=09=09return -EINVAL; > + > +=09val =3D DIV_ROUND_CLOSEST(val, MILLIDEGREE_PER_DEGREE); Include? > + > +=09guard(hwmon_lock)(dev); > + > +=09err =3D dasharo_curve_point_store(data, sattr->nr, "SFPT", sattr->ind= ex, val); > +=09return err ?: count; > +} > + > +static ssize_t curve_point_pwm_show(struct device *dev, struct device_at= tribute *attr, char *buf) > +{ > +=09struct sensor_device_attribute_2 *sattr =3D to_sensor_dev_attr_2(attr= ); > +=09struct dasharo_data *data =3D dev_get_drvdata(dev); > +=09u64 point =3D sattr->index; > +=09u64 val; > +=09int err; > + > +=09guard(hwmon_lock)(dev); > + > +=09err =3D dasharo_curve_point_call(data, sattr->nr, "GFPD", &point, 1, = &val); > +=09if (err) > +=09=09return err; > + > +=09return sysfs_emit(buf, "%llu\n", DIV_ROUND_CLOSEST_ULL(val * 255, 100= )); > +} > + > +static ssize_t curve_point_pwm_store(struct device *dev, struct device_a= ttribute *attr, > +=09=09=09=09 const char *buf, size_t count) > +{ > +=09struct sensor_device_attribute_2 *sattr =3D to_sensor_dev_attr_2(attr= ); > +=09struct dasharo_data *data =3D dev_get_drvdata(dev); > +=09long val; > +=09int err; > + > +=09err =3D kstrtol(buf, 10, &val); > +=09if (err) > +=09=09return err; > + > +=09if (val < 0 || val > 255) > +=09=09return -EINVAL; > + > +=09guard(hwmon_lock)(dev); > + > +=09err =3D dasharo_curve_point_store(data, sattr->nr, "SFPD", sattr->ind= ex, > +=09=09=09=09=09DIV_ROUND_CLOSEST(val * 100, 255)); > +=09return err ?: count; > +} > + > +#define DASHARO_POINT_ATTR(ch, pt) \ > +=09static SENSOR_DEVICE_ATTR_2_RW(pwm##ch##_auto_point##pt##_temp, curve= _point_temp, \ > +=09=09=09=09 (ch) - 1, (pt) - 1); \ > +=09static SENSOR_DEVICE_ATTR_2_RW(pwm##ch##_auto_point##pt##_pwm, curve_= point_pwm, \ > +=09=09=09=09 (ch) - 1, (pt) - 1) > + > +#define DASHARO_POINT_ATTR_PTRS(ch, pt) \ > +=09&sensor_dev_attr_pwm##ch##_auto_point##pt##_temp.dev_attr.attr, \ > +=09&sensor_dev_attr_pwm##ch##_auto_point##pt##_pwm.dev_attr.attr > + > +#define DASHARO_POINT_ATTRS(ch) \ > +=09DASHARO_POINT_ATTR(ch, 1); \ > +=09DASHARO_POINT_ATTR(ch, 2); \ > +=09DASHARO_POINT_ATTR(ch, 3); \ > +=09DASHARO_POINT_ATTR(ch, 4) > + > +#define DASHARO_CHANNEL_PTRS(ch) \ > +=09DASHARO_POINT_ATTR_PTRS(ch, 1), \ > +=09DASHARO_POINT_ATTR_PTRS(ch, 2), \ > +=09DASHARO_POINT_ATTR_PTRS(ch, 3), \ > +=09DASHARO_POINT_ATTR_PTRS(ch, 4) > + > +DASHARO_POINT_ATTRS(1); > +DASHARO_POINT_ATTRS(2); > +DASHARO_POINT_ATTRS(3); > +DASHARO_POINT_ATTRS(4); > +DASHARO_POINT_ATTRS(5); > +DASHARO_POINT_ATTRS(6); > +DASHARO_POINT_ATTRS(7); > +DASHARO_POINT_ATTRS(8); > +DASHARO_POINT_ATTRS(9); > +DASHARO_POINT_ATTRS(10); > +DASHARO_POINT_ATTRS(11); > +DASHARO_POINT_ATTRS(12); > +DASHARO_POINT_ATTRS(13); > +DASHARO_POINT_ATTRS(14); > +DASHARO_POINT_ATTRS(15); > +DASHARO_POINT_ATTRS(16); > +DASHARO_POINT_ATTRS(17); > +DASHARO_POINT_ATTRS(18); > +DASHARO_POINT_ATTRS(19); > +DASHARO_POINT_ATTRS(20); > +DASHARO_POINT_ATTRS(21); > +DASHARO_POINT_ATTRS(22); > +DASHARO_POINT_ATTRS(23); > +DASHARO_POINT_ATTRS(24); > + > +static struct attribute *dasharo_point_attrs[] =3D { > +=09DASHARO_CHANNEL_PTRS(1), > +=09DASHARO_CHANNEL_PTRS(2), > +=09DASHARO_CHANNEL_PTRS(3), > +=09DASHARO_CHANNEL_PTRS(4), > +=09DASHARO_CHANNEL_PTRS(5), > +=09DASHARO_CHANNEL_PTRS(6), > +=09DASHARO_CHANNEL_PTRS(7), > +=09DASHARO_CHANNEL_PTRS(8), > +=09DASHARO_CHANNEL_PTRS(9), > +=09DASHARO_CHANNEL_PTRS(10), > +=09DASHARO_CHANNEL_PTRS(11), > +=09DASHARO_CHANNEL_PTRS(12), > +=09DASHARO_CHANNEL_PTRS(13), > +=09DASHARO_CHANNEL_PTRS(14), > +=09DASHARO_CHANNEL_PTRS(15), > +=09DASHARO_CHANNEL_PTRS(16), > +=09DASHARO_CHANNEL_PTRS(17), > +=09DASHARO_CHANNEL_PTRS(18), > +=09DASHARO_CHANNEL_PTRS(19), > +=09DASHARO_CHANNEL_PTRS(20), > +=09DASHARO_CHANNEL_PTRS(21), > +=09DASHARO_CHANNEL_PTRS(22), > +=09DASHARO_CHANNEL_PTRS(23), > +=09DASHARO_CHANNEL_PTRS(24), > +=09NULL > +}; > + > +static umode_t dasharo_curve_point_is_visible(struct kobject *kobj, stru= ct attribute *attr, int n) > +{ > +=09struct device *dev =3D kobj_to_dev(kobj); > +=09struct dasharo_data *data =3D dev_get_drvdata(dev); > +=09struct device_attribute *dattr =3D container_of(attr, struct device_a= ttribute, attr); > +=09int channel =3D to_sensor_dev_attr_2(dattr)->nr; > + > +=09if (dasharo_fan_channel(data, DASHARO_FEATURE_FAN_POINTS, channel) < = 0) > +=09=09return 0; > + > +=09return attr->mode; > +} > + > +static const struct attribute_group dasharo_point_group =3D { > +=09.attrs =3D dasharo_point_attrs, > +=09.is_visible =3D dasharo_curve_point_is_visible, > +}; > + > +static const struct attribute_group *dasharo_groups[] =3D { > +=09&dasharo_point_group, > +=09NULL > +}; > + > static void dasharo_fill_feature_caps(struct dasharo_data *data, enum da= sharo_feature feat) > { > =09struct dasharo_capability *cap; > @@ -442,16 +655,27 @@ static int dasharo_probe(struct platform_device *pd= ev) > =09if (!data) > =09=09return -ENOMEM; > =09data->pdev =3D pdev; > +=09platform_set_drvdata(pdev, data); > =20 > =09for (unsigned int i =3D 0; i < DASHARO_FEATURE_MAX; ++i) > =09=09dasharo_fill_feature_caps(data, i); > =20 > =09hwmon =3D devm_hwmon_device_register_with_info(&pdev->dev, "dasharo_a= cpi", data, > -=09=09=09=09=09=09 &dasharo_hwmon_chip_info, NULL); > +=09=09=09=09=09=09 &dasharo_hwmon_chip_info, dasharo_groups); > =20 > =09return PTR_ERR_OR_ZERO(hwmon); > } > =20 > +static void dasharo_shutdown(struct platform_device *pdev) > +{ > +=09struct dasharo_data *data =3D platform_get_drvdata(pdev); > +=09u64 ret; > + > +=09/* Let the firmware persist the fan curve the EC runs */ > +=09if (data->caps_found[DASHARO_FEATURE_FAN_POINTS]) > +=09=09acpi_evaluate_integer(ACPI_HANDLE(&pdev->dev), "SFCS", NULL, &ret)= ; > +} > + > static const struct acpi_device_id dasharo_device_ids[] =3D { > =09{"DSHR0001", 0}, > =09{} > @@ -464,6 +688,7 @@ static struct platform_driver dasharo_driver =3D { > =09=09.acpi_match_table =3D dasharo_device_ids, > =09}, > =09.probe =3D dasharo_probe, > +=09.shutdown =3D dasharo_shutdown, > }; > module_platform_driver(dasharo_driver); > =20 >=20 --=20 i. --8323328-835773488-1796126788=:1168--