Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs
[cascardo/linux.git] / drivers / hwmon / adt7470.c
index 94550d7..6e60ca5 100644 (file)
@@ -177,7 +177,6 @@ struct adt7470_data {
        u8                      pwm_auto_temp[ADT7470_PWM_COUNT];
 
        struct task_struct      *auto_update;
-       struct completion       auto_update_stop;
        unsigned int            auto_update_interval;
 };
 
@@ -273,12 +272,14 @@ static int adt7470_update_thread(void *p)
                mutex_lock(&data->lock);
                adt7470_read_temperatures(client, data);
                mutex_unlock(&data->lock);
+
+               set_current_state(TASK_INTERRUPTIBLE);
                if (kthread_should_stop())
                        break;
-               msleep_interruptible(data->auto_update_interval);
+
+               schedule_timeout(msecs_to_jiffies(data->auto_update_interval));
        }
 
-       complete_all(&data->auto_update_stop);
        return 0;
 }
 
@@ -545,6 +546,28 @@ static ssize_t show_alarm_mask(struct device *dev,
        return sprintf(buf, "%x\n", data->alarms_mask);
 }
 
+static ssize_t set_alarm_mask(struct device *dev,
+                             struct device_attribute *devattr,
+                             const char *buf,
+                             size_t count)
+{
+       struct adt7470_data *data = dev_get_drvdata(dev);
+       long mask;
+
+       if (kstrtoul(buf, 0, &mask))
+               return -EINVAL;
+
+       if (mask & ~0xffff)
+               return -EINVAL;
+
+       mutex_lock(&data->lock);
+       data->alarms_mask = mask;
+       adt7470_write_word_data(data->client, ADT7470_REG_ALARM1_MASK, mask);
+       mutex_unlock(&data->lock);
+
+       return count;
+}
+
 static ssize_t show_fan_max(struct device *dev,
                            struct device_attribute *devattr,
                            char *buf)
@@ -989,7 +1012,8 @@ static ssize_t show_alarm(struct device *dev,
                return sprintf(buf, "0\n");
 }
 
-static DEVICE_ATTR(alarm_mask, S_IRUGO, show_alarm_mask, NULL);
+static DEVICE_ATTR(alarm_mask, S_IWUSR | S_IRUGO, show_alarm_mask,
+                  set_alarm_mask);
 static DEVICE_ATTR(num_temp_sensors, S_IWUSR | S_IRUGO, show_num_temp_sensors,
                   set_num_temp_sensors);
 static DEVICE_ATTR(auto_update_interval, S_IWUSR | S_IRUGO,
@@ -1330,7 +1354,6 @@ static int adt7470_probe(struct i2c_client *client,
        if (IS_ERR(hwmon_dev))
                return PTR_ERR(hwmon_dev);
 
-       init_completion(&data->auto_update_stop);
        data->auto_update = kthread_run(adt7470_update_thread, client, "%s",
                                        dev_name(hwmon_dev));
        if (IS_ERR(data->auto_update)) {
@@ -1345,7 +1368,6 @@ static int adt7470_remove(struct i2c_client *client)
        struct adt7470_data *data = i2c_get_clientdata(client);
 
        kthread_stop(data->auto_update);
-       wait_for_completion(&data->auto_update_stop);
        return 0;
 }