aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/adm1025.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/hwmon/adm1025.c')
-rw-r--r--drivers/hwmon/adm1025.c25
1 files changed, 13 insertions, 12 deletions
diff --git a/drivers/hwmon/adm1025.c b/drivers/hwmon/adm1025.c
index 9331c56d2ba6..a4c859c9fbf8 100644
--- a/drivers/hwmon/adm1025.c
+++ b/drivers/hwmon/adm1025.c
@@ -53,6 +53,7 @@
53#include <linux/hwmon.h> 53#include <linux/hwmon.h>
54#include <linux/hwmon-vid.h> 54#include <linux/hwmon-vid.h>
55#include <linux/err.h> 55#include <linux/err.h>
56#include <linux/mutex.h>
56 57
57/* 58/*
58 * Addresses to scan 59 * Addresses to scan
@@ -133,7 +134,7 @@ static struct i2c_driver adm1025_driver = {
133struct adm1025_data { 134struct adm1025_data {
134 struct i2c_client client; 135 struct i2c_client client;
135 struct class_device *class_dev; 136 struct class_device *class_dev;
136 struct semaphore update_lock; 137 struct mutex update_lock;
137 char valid; /* zero until following fields are valid */ 138 char valid; /* zero until following fields are valid */
138 unsigned long last_updated; /* in jiffies */ 139 unsigned long last_updated; /* in jiffies */
139 140
@@ -207,11 +208,11 @@ static ssize_t set_in##offset##_min(struct device *dev, struct device_attribute
207 struct adm1025_data *data = i2c_get_clientdata(client); \ 208 struct adm1025_data *data = i2c_get_clientdata(client); \
208 long val = simple_strtol(buf, NULL, 10); \ 209 long val = simple_strtol(buf, NULL, 10); \
209 \ 210 \
210 down(&data->update_lock); \ 211 mutex_lock(&data->update_lock); \
211 data->in_min[offset] = IN_TO_REG(val, in_scale[offset]); \ 212 data->in_min[offset] = IN_TO_REG(val, in_scale[offset]); \
212 i2c_smbus_write_byte_data(client, ADM1025_REG_IN_MIN(offset), \ 213 i2c_smbus_write_byte_data(client, ADM1025_REG_IN_MIN(offset), \
213 data->in_min[offset]); \ 214 data->in_min[offset]); \
214 up(&data->update_lock); \ 215 mutex_unlock(&data->update_lock); \
215 return count; \ 216 return count; \
216} \ 217} \
217static ssize_t set_in##offset##_max(struct device *dev, struct device_attribute *attr, const char *buf, \ 218static ssize_t set_in##offset##_max(struct device *dev, struct device_attribute *attr, const char *buf, \
@@ -221,11 +222,11 @@ static ssize_t set_in##offset##_max(struct device *dev, struct device_attribute
221 struct adm1025_data *data = i2c_get_clientdata(client); \ 222 struct adm1025_data *data = i2c_get_clientdata(client); \
222 long val = simple_strtol(buf, NULL, 10); \ 223 long val = simple_strtol(buf, NULL, 10); \
223 \ 224 \
224 down(&data->update_lock); \ 225 mutex_lock(&data->update_lock); \
225 data->in_max[offset] = IN_TO_REG(val, in_scale[offset]); \ 226 data->in_max[offset] = IN_TO_REG(val, in_scale[offset]); \
226 i2c_smbus_write_byte_data(client, ADM1025_REG_IN_MAX(offset), \ 227 i2c_smbus_write_byte_data(client, ADM1025_REG_IN_MAX(offset), \
227 data->in_max[offset]); \ 228 data->in_max[offset]); \
228 up(&data->update_lock); \ 229 mutex_unlock(&data->update_lock); \
229 return count; \ 230 return count; \
230} \ 231} \
231static DEVICE_ATTR(in##offset##_min, S_IWUSR | S_IRUGO, \ 232static DEVICE_ATTR(in##offset##_min, S_IWUSR | S_IRUGO, \
@@ -247,11 +248,11 @@ static ssize_t set_temp##offset##_min(struct device *dev, struct device_attribut
247 struct adm1025_data *data = i2c_get_clientdata(client); \ 248 struct adm1025_data *data = i2c_get_clientdata(client); \
248 long val = simple_strtol(buf, NULL, 10); \ 249 long val = simple_strtol(buf, NULL, 10); \
249 \ 250 \
250 down(&data->update_lock); \ 251 mutex_lock(&data->update_lock); \
251 data->temp_min[offset-1] = TEMP_TO_REG(val); \ 252 data->temp_min[offset-1] = TEMP_TO_REG(val); \
252 i2c_smbus_write_byte_data(client, ADM1025_REG_TEMP_LOW(offset-1), \ 253 i2c_smbus_write_byte_data(client, ADM1025_REG_TEMP_LOW(offset-1), \
253 data->temp_min[offset-1]); \ 254 data->temp_min[offset-1]); \
254 up(&data->update_lock); \ 255 mutex_unlock(&data->update_lock); \
255 return count; \ 256 return count; \
256} \ 257} \
257static ssize_t set_temp##offset##_max(struct device *dev, struct device_attribute *attr, const char *buf, \ 258static ssize_t set_temp##offset##_max(struct device *dev, struct device_attribute *attr, const char *buf, \
@@ -261,11 +262,11 @@ static ssize_t set_temp##offset##_max(struct device *dev, struct device_attribut
261 struct adm1025_data *data = i2c_get_clientdata(client); \ 262 struct adm1025_data *data = i2c_get_clientdata(client); \
262 long val = simple_strtol(buf, NULL, 10); \ 263 long val = simple_strtol(buf, NULL, 10); \
263 \ 264 \
264 down(&data->update_lock); \ 265 mutex_lock(&data->update_lock); \
265 data->temp_max[offset-1] = TEMP_TO_REG(val); \ 266 data->temp_max[offset-1] = TEMP_TO_REG(val); \
266 i2c_smbus_write_byte_data(client, ADM1025_REG_TEMP_HIGH(offset-1), \ 267 i2c_smbus_write_byte_data(client, ADM1025_REG_TEMP_HIGH(offset-1), \
267 data->temp_max[offset-1]); \ 268 data->temp_max[offset-1]); \
268 up(&data->update_lock); \ 269 mutex_unlock(&data->update_lock); \
269 return count; \ 270 return count; \
270} \ 271} \
271static DEVICE_ATTR(temp##offset##_min, S_IWUSR | S_IRUGO, \ 272static DEVICE_ATTR(temp##offset##_min, S_IWUSR | S_IRUGO, \
@@ -404,7 +405,7 @@ static int adm1025_detect(struct i2c_adapter *adapter, int address, int kind)
404 /* We can fill in the remaining client fields */ 405 /* We can fill in the remaining client fields */
405 strlcpy(new_client->name, name, I2C_NAME_SIZE); 406 strlcpy(new_client->name, name, I2C_NAME_SIZE);
406 data->valid = 0; 407 data->valid = 0;
407 init_MUTEX(&data->update_lock); 408 mutex_init(&data->update_lock);
408 409
409 /* Tell the I2C layer a new client has arrived */ 410 /* Tell the I2C layer a new client has arrived */
410 if ((err = i2c_attach_client(new_client))) 411 if ((err = i2c_attach_client(new_client)))
@@ -523,7 +524,7 @@ static struct adm1025_data *adm1025_update_device(struct device *dev)
523 struct i2c_client *client = to_i2c_client(dev); 524 struct i2c_client *client = to_i2c_client(dev);
524 struct adm1025_data *data = i2c_get_clientdata(client); 525 struct adm1025_data *data = i2c_get_clientdata(client);
525 526
526 down(&data->update_lock); 527 mutex_lock(&data->update_lock);
527 528
528 if (time_after(jiffies, data->last_updated + HZ * 2) || !data->valid) { 529 if (time_after(jiffies, data->last_updated + HZ * 2) || !data->valid) {
529 int i; 530 int i;
@@ -558,7 +559,7 @@ static struct adm1025_data *adm1025_update_device(struct device *dev)
558 data->valid = 1; 559 data->valid = 1;
559 } 560 }
560 561
561 up(&data->update_lock); 562 mutex_unlock(&data->update_lock);
562 563
563 return data; 564 return data;
564} 565}