|
@@ -33,20 +33,14 @@ struct pwm_fan_ctx {
|
|
unsigned char pwm_value;
|
|
unsigned char pwm_value;
|
|
};
|
|
};
|
|
|
|
|
|
-static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
|
|
|
|
- const char *buf, size_t count)
|
|
|
|
|
|
+static int __set_pwm(struct pwm_fan_ctx *ctx, unsigned long pwm)
|
|
{
|
|
{
|
|
- struct pwm_fan_ctx *ctx = dev_get_drvdata(dev);
|
|
|
|
- unsigned long pwm, duty;
|
|
|
|
- ssize_t ret;
|
|
|
|
-
|
|
|
|
- if (kstrtoul(buf, 10, &pwm) || pwm > MAX_PWM)
|
|
|
|
- return -EINVAL;
|
|
|
|
|
|
+ unsigned long duty;
|
|
|
|
+ int ret = 0;
|
|
|
|
|
|
mutex_lock(&ctx->lock);
|
|
mutex_lock(&ctx->lock);
|
|
-
|
|
|
|
if (ctx->pwm_value == pwm)
|
|
if (ctx->pwm_value == pwm)
|
|
- goto exit_set_pwm_no_change;
|
|
|
|
|
|
+ goto exit_set_pwm_err;
|
|
|
|
|
|
if (pwm == 0) {
|
|
if (pwm == 0) {
|
|
pwm_disable(ctx->pwm);
|
|
pwm_disable(ctx->pwm);
|
|
@@ -66,13 +60,28 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
|
|
|
|
|
|
exit_set_pwm:
|
|
exit_set_pwm:
|
|
ctx->pwm_value = pwm;
|
|
ctx->pwm_value = pwm;
|
|
-exit_set_pwm_no_change:
|
|
|
|
- ret = count;
|
|
|
|
exit_set_pwm_err:
|
|
exit_set_pwm_err:
|
|
mutex_unlock(&ctx->lock);
|
|
mutex_unlock(&ctx->lock);
|
|
return ret;
|
|
return ret;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
|
|
|
|
+ const char *buf, size_t count)
|
|
|
|
+{
|
|
|
|
+ struct pwm_fan_ctx *ctx = dev_get_drvdata(dev);
|
|
|
|
+ unsigned long pwm;
|
|
|
|
+ int ret;
|
|
|
|
+
|
|
|
|
+ if (kstrtoul(buf, 10, &pwm) || pwm > MAX_PWM)
|
|
|
|
+ return -EINVAL;
|
|
|
|
+
|
|
|
|
+ ret = __set_pwm(ctx, pwm);
|
|
|
|
+ if (ret)
|
|
|
|
+ return ret;
|
|
|
|
+
|
|
|
|
+ return count;
|
|
|
|
+}
|
|
|
|
+
|
|
static ssize_t show_pwm(struct device *dev,
|
|
static ssize_t show_pwm(struct device *dev,
|
|
struct device_attribute *attr, char *buf)
|
|
struct device_attribute *attr, char *buf)
|
|
{
|
|
{
|