aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/smsc47m192.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/hwmon/smsc47m192.c')
-rw-r--r--drivers/hwmon/smsc47m192.c37
1 files changed, 19 insertions, 18 deletions
diff --git a/drivers/hwmon/smsc47m192.c b/drivers/hwmon/smsc47m192.c
index a012f396f354..d3a3ba04cb0f 100644
--- a/drivers/hwmon/smsc47m192.c
+++ b/drivers/hwmon/smsc47m192.c
@@ -31,6 +31,7 @@
31#include <linux/hwmon-vid.h> 31#include <linux/hwmon-vid.h>
32#include <linux/err.h> 32#include <linux/err.h>
33#include <linux/sysfs.h> 33#include <linux/sysfs.h>
34#include <linux/mutex.h>
34 35
35/* Addresses to scan */ 36/* Addresses to scan */
36static unsigned short normal_i2c[] = { 0x2c, 0x2d, I2C_CLIENT_END }; 37static unsigned short normal_i2c[] = { 0x2c, 0x2d, I2C_CLIENT_END };
@@ -97,7 +98,7 @@ static inline int TEMP_FROM_REG(s8 val)
97struct smsc47m192_data { 98struct smsc47m192_data {
98 struct i2c_client client; 99 struct i2c_client client;
99 struct class_device *class_dev; 100 struct class_device *class_dev;
100 struct semaphore update_lock; 101 struct mutex update_lock;
101 char valid; /* !=0 if following fields are valid */ 102 char valid; /* !=0 if following fields are valid */
102 unsigned long last_updated; /* In jiffies */ 103 unsigned long last_updated; /* In jiffies */
103 104
@@ -164,11 +165,11 @@ static ssize_t set_in_min(struct device *dev, struct device_attribute *attr,
164 struct smsc47m192_data *data = i2c_get_clientdata(client); 165 struct smsc47m192_data *data = i2c_get_clientdata(client);
165 unsigned long val = simple_strtoul(buf, NULL, 10); 166 unsigned long val = simple_strtoul(buf, NULL, 10);
166 167
167 down(&data->update_lock); 168 mutex_lock(&data->update_lock);
168 data->in_min[nr] = IN_TO_REG(val, nr); 169 data->in_min[nr] = IN_TO_REG(val, nr);
169 i2c_smbus_write_byte_data(client, SMSC47M192_REG_IN_MIN(nr), 170 i2c_smbus_write_byte_data(client, SMSC47M192_REG_IN_MIN(nr),
170 data->in_min[nr]); 171 data->in_min[nr]);
171 up(&data->update_lock); 172 mutex_unlock(&data->update_lock);
172 return count; 173 return count;
173} 174}
174 175
@@ -181,11 +182,11 @@ static ssize_t set_in_max(struct device *dev, struct device_attribute *attr,
181 struct smsc47m192_data *data = i2c_get_clientdata(client); 182 struct smsc47m192_data *data = i2c_get_clientdata(client);
182 unsigned long val = simple_strtoul(buf, NULL, 10); 183 unsigned long val = simple_strtoul(buf, NULL, 10);
183 184
184 down(&data->update_lock); 185 mutex_lock(&data->update_lock);
185 data->in_max[nr] = IN_TO_REG(val, nr); 186 data->in_max[nr] = IN_TO_REG(val, nr);
186 i2c_smbus_write_byte_data(client, SMSC47M192_REG_IN_MAX(nr), 187 i2c_smbus_write_byte_data(client, SMSC47M192_REG_IN_MAX(nr),
187 data->in_max[nr]); 188 data->in_max[nr]);
188 up(&data->update_lock); 189 mutex_unlock(&data->update_lock);
189 return count; 190 return count;
190} 191}
191 192
@@ -243,11 +244,11 @@ static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr,
243 struct smsc47m192_data *data = i2c_get_clientdata(client); 244 struct smsc47m192_data *data = i2c_get_clientdata(client);
244 long val = simple_strtol(buf, NULL, 10); 245 long val = simple_strtol(buf, NULL, 10);
245 246
246 down(&data->update_lock); 247 mutex_lock(&data->update_lock);
247 data->temp_min[nr] = TEMP_TO_REG(val); 248 data->temp_min[nr] = TEMP_TO_REG(val);
248 i2c_smbus_write_byte_data(client, SMSC47M192_REG_TEMP_MIN[nr], 249 i2c_smbus_write_byte_data(client, SMSC47M192_REG_TEMP_MIN[nr],
249 data->temp_min[nr]); 250 data->temp_min[nr]);
250 up(&data->update_lock); 251 mutex_unlock(&data->update_lock);
251 return count; 252 return count;
252} 253}
253 254
@@ -260,11 +261,11 @@ static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr,
260 struct smsc47m192_data *data = i2c_get_clientdata(client); 261 struct smsc47m192_data *data = i2c_get_clientdata(client);
261 long val = simple_strtol(buf, NULL, 10); 262 long val = simple_strtol(buf, NULL, 10);
262 263
263 down(&data->update_lock); 264 mutex_lock(&data->update_lock);
264 data->temp_max[nr] = TEMP_TO_REG(val); 265 data->temp_max[nr] = TEMP_TO_REG(val);
265 i2c_smbus_write_byte_data(client, SMSC47M192_REG_TEMP_MAX[nr], 266 i2c_smbus_write_byte_data(client, SMSC47M192_REG_TEMP_MAX[nr],
266 data->temp_max[nr]); 267 data->temp_max[nr]);
267 up(&data->update_lock); 268 mutex_unlock(&data->update_lock);
268 return count; 269 return count;
269} 270}
270 271
@@ -287,7 +288,7 @@ static ssize_t set_temp_offset(struct device *dev, struct device_attribute
287 u8 sfr = i2c_smbus_read_byte_data(client, SMSC47M192_REG_SFR); 288 u8 sfr = i2c_smbus_read_byte_data(client, SMSC47M192_REG_SFR);
288 long val = simple_strtol(buf, NULL, 10); 289 long val = simple_strtol(buf, NULL, 10);
289 290
290 down(&data->update_lock); 291 mutex_lock(&data->update_lock);
291 data->temp_offset[nr] = TEMP_TO_REG(val); 292 data->temp_offset[nr] = TEMP_TO_REG(val);
292 if (nr>1) 293 if (nr>1)
293 i2c_smbus_write_byte_data(client, 294 i2c_smbus_write_byte_data(client,
@@ -303,7 +304,7 @@ static ssize_t set_temp_offset(struct device *dev, struct device_attribute
303 } else if ((sfr & 0x10) == (nr==0 ? 0x10 : 0)) 304 } else if ((sfr & 0x10) == (nr==0 ? 0x10 : 0))
304 i2c_smbus_write_byte_data(client, 305 i2c_smbus_write_byte_data(client,
305 SMSC47M192_REG_TEMP_OFFSET(nr), 0); 306 SMSC47M192_REG_TEMP_OFFSET(nr), 0);
306 up(&data->update_lock); 307 mutex_unlock(&data->update_lock);
307 return count; 308 return count;
308} 309}
309 310
@@ -360,8 +361,8 @@ static ssize_t show_alarm(struct device *dev, struct device_attribute *attr,
360static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 0x0010); 361static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 0x0010);
361static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 0x0020); 362static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 0x0020);
362static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 0x0040); 363static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 0x0040);
363static SENSOR_DEVICE_ATTR(temp2_input_fault, S_IRUGO, show_alarm, NULL, 0x4000); 364static SENSOR_DEVICE_ATTR(temp2_fault, S_IRUGO, show_alarm, NULL, 0x4000);
364static SENSOR_DEVICE_ATTR(temp3_input_fault, S_IRUGO, show_alarm, NULL, 0x8000); 365static SENSOR_DEVICE_ATTR(temp3_fault, S_IRUGO, show_alarm, NULL, 0x8000);
365static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 0x0001); 366static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 0x0001);
366static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 0x0002); 367static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 0x0002);
367static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 0x0004); 368static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 0x0004);
@@ -411,13 +412,13 @@ static struct attribute *smsc47m192_attributes[] = {
411 &sensor_dev_attr_temp2_min.dev_attr.attr, 412 &sensor_dev_attr_temp2_min.dev_attr.attr,
412 &sensor_dev_attr_temp2_offset.dev_attr.attr, 413 &sensor_dev_attr_temp2_offset.dev_attr.attr,
413 &sensor_dev_attr_temp2_alarm.dev_attr.attr, 414 &sensor_dev_attr_temp2_alarm.dev_attr.attr,
414 &sensor_dev_attr_temp2_input_fault.dev_attr.attr, 415 &sensor_dev_attr_temp2_fault.dev_attr.attr,
415 &sensor_dev_attr_temp3_input.dev_attr.attr, 416 &sensor_dev_attr_temp3_input.dev_attr.attr,
416 &sensor_dev_attr_temp3_max.dev_attr.attr, 417 &sensor_dev_attr_temp3_max.dev_attr.attr,
417 &sensor_dev_attr_temp3_min.dev_attr.attr, 418 &sensor_dev_attr_temp3_min.dev_attr.attr,
418 &sensor_dev_attr_temp3_offset.dev_attr.attr, 419 &sensor_dev_attr_temp3_offset.dev_attr.attr,
419 &sensor_dev_attr_temp3_alarm.dev_attr.attr, 420 &sensor_dev_attr_temp3_alarm.dev_attr.attr,
420 &sensor_dev_attr_temp3_input_fault.dev_attr.attr, 421 &sensor_dev_attr_temp3_fault.dev_attr.attr,
421 422
422 &dev_attr_cpu0_vid.attr, 423 &dev_attr_cpu0_vid.attr,
423 &dev_attr_vrm.attr, 424 &dev_attr_vrm.attr,
@@ -531,7 +532,7 @@ static int smsc47m192_detect(struct i2c_adapter *adapter, int address,
531 /* Fill in the remaining client fields and put into the global list */ 532 /* Fill in the remaining client fields and put into the global list */
532 strlcpy(client->name, "smsc47m192", I2C_NAME_SIZE); 533 strlcpy(client->name, "smsc47m192", I2C_NAME_SIZE);
533 data->vrm = vid_which_vrm(); 534 data->vrm = vid_which_vrm();
534 init_MUTEX(&data->update_lock); 535 mutex_init(&data->update_lock);
535 536
536 /* Tell the I2C layer a new client has arrived */ 537 /* Tell the I2C layer a new client has arrived */
537 if ((err = i2c_attach_client(client))) 538 if ((err = i2c_attach_client(client)))
@@ -594,7 +595,7 @@ static struct smsc47m192_data *smsc47m192_update_device(struct device *dev)
594 struct smsc47m192_data *data = i2c_get_clientdata(client); 595 struct smsc47m192_data *data = i2c_get_clientdata(client);
595 int i, config; 596 int i, config;
596 597
597 down(&data->update_lock); 598 mutex_lock(&data->update_lock);
598 599
599 if (time_after(jiffies, data->last_updated + HZ + HZ / 2) 600 if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
600 || !data->valid) { 601 || !data->valid) {
@@ -645,7 +646,7 @@ static struct smsc47m192_data *smsc47m192_update_device(struct device *dev)
645 data->valid = 1; 646 data->valid = 1;
646 } 647 }
647 648
648 up(&data->update_lock); 649 mutex_unlock(&data->update_lock);
649 650
650 return data; 651 return data;
651} 652}