Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make laptop fan duty pwm writable #18

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions system76_acpi.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ struct system76_data {
struct input_dev *input;
bool has_open_ec;
enum kbled_type kbled_type;
int fan_duty;
};

static const struct acpi_device_id device_ids[] = {
Expand Down Expand Up @@ -516,12 +517,12 @@ static umode_t thermal_is_visible(const void *drvdata, enum hwmon_sensor_types t
const struct system76_data *data = drvdata;

switch (type) {
case hwmon_fan:
case hwmon_pwm:
if (system76_name(data->nfan, channel))
return 0444;
return 0644;
break;

case hwmon_fan:
case hwmon_temp:
if (system76_name(data->ntmp, channel))
return 0444;
Expand Down Expand Up @@ -578,6 +579,31 @@ static int thermal_read(struct device *dev, enum hwmon_sensor_types type, u32 at
return -EOPNOTSUPP;
}

static int thermal_write(struct device *dev, enum hwmon_sensor_types type, u32 attr,
int channel, long val)
{
struct system76_data *data = dev_get_drvdata(dev);
int raw;

switch (type) {
case hwmon_pwm:
if (attr == hwmon_pwm_input) {
char method[5];
snprintf(method, sizeof method, "SFD%d", channel);

data->fan_duty = val;

return system76_set(data, method, (int)data->fan_duty);
}
break;

default:
return -EOPNOTSUPP;
}

return -EOPNOTSUPP;
}

static int thermal_read_string(struct device *dev, enum hwmon_sensor_types type, u32 attr,
int channel, const char **str)
{
Expand Down Expand Up @@ -611,6 +637,7 @@ static const struct hwmon_ops thermal_ops = {
.is_visible = thermal_is_visible,
.read = thermal_read,
.read_string = thermal_read_string,
.write = thermal_write,
};

// Allocate up to 8 fans and temperatures
Expand Down