[PATCH 2/3] platform/x86: dasharo-acpi: Add fan mode and PWM write support

From: Filip Gołaś

Date: Fri Nov 13 2026 - 07:04:48 EST


Allow switching fans between automatic control by the EC and manual
control via pwmN_enable (1=manual, 2=automatic), and setting the duty
cycle via pwmN. The EC refuses duty cycle writes in automatic mode.

Fan mode control is only exposed for fans on which the firmware reports
support for it.

Signed-off-by: Filip Gołaś <filip.golas@xxxxxxxxx>
---
drivers/platform/x86/dasharo-acpi.c | 117 +++++++++++++++++++++-------
1 file changed, 90 insertions(+), 27 deletions(-)

diff --git a/drivers/platform/x86/dasharo-acpi.c b/drivers/platform/x86/dasharo-acpi.c
index 13d97eb43511..29afcf78564c 100644
--- a/drivers/platform/x86/dasharo-acpi.c
+++ b/drivers/platform/x86/dasharo-acpi.c
@@ -15,6 +15,8 @@ enum dasharo_feature {
DASHARO_FEATURE_TEMPERATURE = 0,
DASHARO_FEATURE_FAN_PWM,
DASHARO_FEATURE_FAN_TACH,
+ DASHARO_FEATURE_FAN_POINTS,
+ DASHARO_FEATURE_FAN_MODE,
DASHARO_FEATURE_MAX
};

@@ -54,6 +56,16 @@ static const char * const dasharo_group_names[DASHARO_FEATURE_MAX][MAX_GROUPS_PE
[DASHARO_FAN_GPU] = "GPU",
[DASHARO_FAN_CHASSIS] = "Chassis",
},
+ [DASHARO_FEATURE_FAN_MODE] = {
+ [DASHARO_FAN_CPU] = "CPU",
+ [DASHARO_FAN_GPU] = "GPU",
+ [DASHARO_FAN_CHASSIS] = "Chassis",
+ },
+ [DASHARO_FEATURE_FAN_POINTS] = {
+ [DASHARO_FAN_CPU] = "CPU",
+ [DASHARO_FAN_GPU] = "GPU",
+ [DASHARO_FAN_CHASSIS] = "Chassis",
+ },
};

struct dasharo_capability {
@@ -143,6 +155,21 @@ static int dasharo_read_channel(struct dasharo_data *data, const char *method,
return ret;
}

+static int dasharo_write_channel(struct dasharo_data *data, const char *method,
+ enum dasharo_feature feat, int channel, long value)
+{
+ u64 arg = value;
+ u64 ret;
+ int err;
+
+ err = dasharo_call(data, method, feat, channel, &arg, 1, &ret);
+ if (err)
+ return err;
+
+ /* Non-zero status from the method means the EC refused the write */
+ return ret ? -EPERM : 0;
+}
+
static int dasharo_hwmon_read(struct device *dev, enum hwmon_sensor_types type,
u32 attr, int channel, long *val)
{
@@ -162,6 +189,14 @@ static int dasharo_hwmon_read(struct device *dev, enum hwmon_sensor_types type,
*val = value;
break;
case hwmon_pwm:
+ if (attr == hwmon_pwm_enable) {
+ /* hwmon: 1 = manual, 2 = automatic */
+ ret = dasharo_read_channel(data, "GFMD", DASHARO_FEATURE_FAN_MODE,
+ channel, &value);
+ if (!ret)
+ *val = value ? 1 : 2;
+ break;
+ }
ret = dasharo_read_channel(data, "GFDC", DASHARO_FEATURE_FAN_PWM, channel, &value);
if (!ret)
*val = value;
@@ -174,6 +209,31 @@ static int dasharo_hwmon_read(struct device *dev, enum hwmon_sensor_types type,
return ret;
}

+static int dasharo_hwmon_write(struct device *dev, enum hwmon_sensor_types type,
+ u32 attr, int channel, long val)
+{
+ struct dasharo_data *data = dev_get_drvdata(dev);
+
+ if (type != hwmon_pwm)
+ return -EINVAL;
+
+ switch (attr) {
+ case hwmon_pwm_enable:
+ if (val != 1 && val != 2)
+ return -EINVAL;
+ return dasharo_write_channel(data, "SFMD", DASHARO_FEATURE_FAN_MODE,
+ channel, val == 1);
+ case hwmon_pwm_input:
+ if (val < 0 || val > 255)
+ return -EINVAL;
+ /* Refused by the EC unless in manual mode */
+ return dasharo_write_channel(data, "SFDC", DASHARO_FEATURE_FAN_PWM,
+ channel, val);
+ default:
+ return -EOPNOTSUPP;
+ }
+}
+
static int dasharo_hwmon_read_string(struct device *dev, enum hwmon_sensor_types type,
u32 attr, int channel, const char **str)
{
@@ -210,9 +270,11 @@ static umode_t dasharo_hwmon_is_visible(const void *drvdata, enum hwmon_sensor_t
return 0444;
break;
case hwmon_pwm:
- if (channel < data->caps_found[DASHARO_FEATURE_FAN_PWM])
- return 0444;
- break;
+ if (channel >= data->caps_found[DASHARO_FEATURE_FAN_PWM])
+ break;
+ if (attr == hwmon_pwm_enable)
+ return channel < data->caps_found[DASHARO_FEATURE_FAN_MODE] ? 0644 : 0;
+ return data->caps_found[DASHARO_FEATURE_FAN_MODE] ? 0644 : 0444;
case hwmon_fan:
if (channel < data->caps_found[DASHARO_FEATURE_FAN_TACH])
return 0444;
@@ -228,6 +290,7 @@ static const struct hwmon_ops dasharo_hwmon_ops = {
.is_visible = dasharo_hwmon_is_visible,
.read_string = dasharo_hwmon_read_string,
.read = dasharo_hwmon_read,
+ .write = dasharo_hwmon_write,
};

// Max 24 capabilities per feature
@@ -283,30 +346,30 @@ static const struct hwmon_channel_info * const dasharo_hwmon_info[] = {
HWMON_T_INPUT | HWMON_T_LABEL,
HWMON_T_INPUT | HWMON_T_LABEL),
HWMON_CHANNEL_INFO(pwm,
- HWMON_PWM_INPUT,
- HWMON_PWM_INPUT,
- HWMON_PWM_INPUT,
- HWMON_PWM_INPUT,
- HWMON_PWM_INPUT,
- HWMON_PWM_INPUT,
- HWMON_PWM_INPUT,
- HWMON_PWM_INPUT,
- HWMON_PWM_INPUT,
- HWMON_PWM_INPUT,
- HWMON_PWM_INPUT,
- HWMON_PWM_INPUT,
- HWMON_PWM_INPUT,
- HWMON_PWM_INPUT,
- HWMON_PWM_INPUT,
- HWMON_PWM_INPUT,
- HWMON_PWM_INPUT,
- HWMON_PWM_INPUT,
- HWMON_PWM_INPUT,
- HWMON_PWM_INPUT,
- HWMON_PWM_INPUT,
- HWMON_PWM_INPUT,
- HWMON_PWM_INPUT,
- HWMON_PWM_INPUT),
+ HWMON_PWM_INPUT | HWMON_PWM_ENABLE,
+ HWMON_PWM_INPUT | HWMON_PWM_ENABLE,
+ HWMON_PWM_INPUT | HWMON_PWM_ENABLE,
+ HWMON_PWM_INPUT | HWMON_PWM_ENABLE,
+ HWMON_PWM_INPUT | HWMON_PWM_ENABLE,
+ HWMON_PWM_INPUT | HWMON_PWM_ENABLE,
+ HWMON_PWM_INPUT | HWMON_PWM_ENABLE,
+ HWMON_PWM_INPUT | HWMON_PWM_ENABLE,
+ HWMON_PWM_INPUT | HWMON_PWM_ENABLE,
+ HWMON_PWM_INPUT | HWMON_PWM_ENABLE,
+ HWMON_PWM_INPUT | HWMON_PWM_ENABLE,
+ HWMON_PWM_INPUT | HWMON_PWM_ENABLE,
+ HWMON_PWM_INPUT | HWMON_PWM_ENABLE,
+ HWMON_PWM_INPUT | HWMON_PWM_ENABLE,
+ HWMON_PWM_INPUT | HWMON_PWM_ENABLE,
+ HWMON_PWM_INPUT | HWMON_PWM_ENABLE,
+ HWMON_PWM_INPUT | HWMON_PWM_ENABLE,
+ HWMON_PWM_INPUT | HWMON_PWM_ENABLE,
+ HWMON_PWM_INPUT | HWMON_PWM_ENABLE,
+ HWMON_PWM_INPUT | HWMON_PWM_ENABLE,
+ HWMON_PWM_INPUT | HWMON_PWM_ENABLE,
+ HWMON_PWM_INPUT | HWMON_PWM_ENABLE,
+ HWMON_PWM_INPUT | HWMON_PWM_ENABLE,
+ HWMON_PWM_INPUT | HWMON_PWM_ENABLE),
NULL
};

--
2.56.0