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

From: Filip Gołaś

Date: Mon Nov 23 2026 - 05:58:58 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>
---
Changes in v2:
- The capabilities of each feature are packed independently, so channel N
of DASHARO_FEATURE_FAN_MODE will not necessarily be the fan of PWM channel N
if the two fans have different capabilities.
Use dasharo_fan_channel for looking up the fan mode capabilities by
comparing the group and index.
---
drivers/platform/x86/dasharo-acpi.c | 146 +++++++++++++++++++++++-----
1 file changed, 119 insertions(+), 27 deletions(-)

diff --git a/drivers/platform/x86/dasharo-acpi.c b/drivers/platform/x86/dasharo-acpi.c
index 13d97eb43511..85f88b11fcf9 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,10 +155,45 @@ 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_fan_channel(const struct dasharo_data *data, enum dasharo_feature feat,
+ int pwm_channel)
+{
+ const struct dasharo_capability *fan;
+ int i;
+
+ if (pwm_channel >= data->caps_found[DASHARO_FEATURE_FAN_PWM])
+ return -EINVAL;
+
+ fan = &data->capabilities[DASHARO_FEATURE_FAN_PWM][pwm_channel];
+ for (i = 0; i < data->caps_found[feat]; i++) {
+ if (data->capabilities[feat][i].group == fan->group &&
+ data->capabilities[feat][i].index == fan->index)
+ return i;
+ }
+
+ return -ENODEV;
+}
+
static int dasharo_hwmon_read(struct device *dev, enum hwmon_sensor_types type,
u32 attr, int channel, long *val)
{
struct dasharo_data *data = dev_get_drvdata(dev);
+ int mode_ch;
long value;
int ret;

@@ -162,6 +209,17 @@ 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 */
+ mode_ch = dasharo_fan_channel(data, DASHARO_FEATURE_FAN_MODE, channel);
+ if (mode_ch < 0)
+ return mode_ch;
+ ret = dasharo_read_channel(data, "GFMD", DASHARO_FEATURE_FAN_MODE,
+ mode_ch, &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 +232,35 @@ 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);
+ int mode_ch;
+
+ if (type != hwmon_pwm)
+ return -EINVAL;
+
+ switch (attr) {
+ case hwmon_pwm_enable:
+ if (val != 1 && val != 2)
+ return -EINVAL;
+ mode_ch = dasharo_fan_channel(data, DASHARO_FEATURE_FAN_MODE, channel);
+ if (mode_ch < 0)
+ return mode_ch;
+ return dasharo_write_channel(data, "SFMD", DASHARO_FEATURE_FAN_MODE,
+ mode_ch, 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)
{
@@ -203,6 +290,7 @@ static umode_t dasharo_hwmon_is_visible(const void *drvdata, enum hwmon_sensor_t
u32 attr, int channel)
{
const struct dasharo_data *data = drvdata;
+ bool has_mode;

switch (type) {
case hwmon_temp:
@@ -210,9 +298,12 @@ 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;
+ has_mode = dasharo_fan_channel(data, DASHARO_FEATURE_FAN_MODE, channel) >= 0;
+ if (attr == hwmon_pwm_enable)
+ return has_mode ? 0644 : 0;
+ return has_mode ? 0644 : 0444;
case hwmon_fan:
if (channel < data->caps_found[DASHARO_FEATURE_FAN_TACH])
return 0444;
@@ -228,6 +319,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 +375,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