diff --git a/drivers/hwmon/pwm-fan.c b/drivers/hwmon/pwm-fan.c index 70cc0d134f3cd7..2886feff5cf0f7 100644 --- a/drivers/hwmon/pwm-fan.c +++ b/drivers/hwmon/pwm-fan.c @@ -98,11 +98,55 @@ static ssize_t show_pwm(struct device *dev, return sprintf(buf, "%u\n", ctx->pwm_value); } +static ssize_t set_cool(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + struct pwm_fan_ctx *ctx = dev_get_drvdata(dev); + unsigned int speed_0, speed_1, speed_2, speed_3; + + if(sscanf(buf, "%u %u %u %u\n", &speed_0, &speed_1, &speed_2, &speed_3) != 4) { + dev_err(dev, "invalid speed input"); + return -EINVAL; + } + + if(!(speed_0 < speed_1 && speed_1 < speed_2 && speed_2 < speed_3)){ + dev_err(dev, "fan speeds must be increasing in value"); + return count; + } + + dev_info(dev, "fan_speeds : %s [%d %d %d %d] \n", + __func__, speed_0, speed_1, speed_2, speed_3); + + mutex_lock(&ctx->lock); + ctx->pwm_fan_cooling_levels[0] = speed_0; + ctx->pwm_fan_cooling_levels[1] = speed_1; + ctx->pwm_fan_cooling_levels[2] = speed_2; + ctx->pwm_fan_cooling_levels[3] = speed_3; + mutex_unlock(&ctx->lock); + + return count; +} + +static ssize_t show_cool(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct pwm_fan_ctx *ctx = dev_get_drvdata(dev); + int lenght = 0, i; + + mutex_lock(&ctx->lock); + for (i = 0; i <= ctx->pwm_fan_max_state; i++) + lenght += sprintf(buf+lenght, "%u ", ctx->pwm_fan_cooling_levels[i]); + mutex_unlock(&ctx->lock); + + return lenght; +} static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, show_pwm, set_pwm, 0); +static SENSOR_DEVICE_ATTR(fan_speed, S_IRUGO | S_IWUSR, show_cool, set_cool, 0); static struct attribute *pwm_fan_attrs[] = { &sensor_dev_attr_pwm1.dev_attr.attr, + &sensor_dev_attr_fan_speed.dev_attr.attr, NULL, };