aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'drivers')
-rw-r--r--drivers/hwmon/f71805f.c57
1 files changed, 29 insertions, 28 deletions
diff --git a/drivers/hwmon/f71805f.c b/drivers/hwmon/f71805f.c
index 8e810f05d0ae..885465df6e6a 100644
--- a/drivers/hwmon/f71805f.c
+++ b/drivers/hwmon/f71805f.c
@@ -30,6 +30,7 @@
30#include <linux/hwmon.h> 30#include <linux/hwmon.h>
31#include <linux/hwmon-sysfs.h> 31#include <linux/hwmon-sysfs.h>
32#include <linux/err.h> 32#include <linux/err.h>
33#include <linux/mutex.h>
33#include <asm/io.h> 34#include <asm/io.h>
34 35
35static struct platform_device *pdev; 36static struct platform_device *pdev;
@@ -131,10 +132,10 @@ static struct resource f71805f_resource __initdata = {
131struct f71805f_data { 132struct f71805f_data {
132 unsigned short addr; 133 unsigned short addr;
133 const char *name; 134 const char *name;
134 struct semaphore lock; 135 struct mutex lock;
135 struct class_device *class_dev; 136 struct class_device *class_dev;
136 137
137 struct semaphore update_lock; 138 struct mutex update_lock;
138 char valid; /* !=0 if following fields are valid */ 139 char valid; /* !=0 if following fields are valid */
139 unsigned long last_updated; /* In jiffies */ 140 unsigned long last_updated; /* In jiffies */
140 unsigned long last_limits; /* In jiffies */ 141 unsigned long last_limits; /* In jiffies */
@@ -224,20 +225,20 @@ static u8 f71805f_read8(struct f71805f_data *data, u8 reg)
224{ 225{
225 u8 val; 226 u8 val;
226 227
227 down(&data->lock); 228 mutex_lock(&data->lock);
228 outb(reg, data->addr + ADDR_REG_OFFSET); 229 outb(reg, data->addr + ADDR_REG_OFFSET);
229 val = inb(data->addr + DATA_REG_OFFSET); 230 val = inb(data->addr + DATA_REG_OFFSET);
230 up(&data->lock); 231 mutex_unlock(&data->lock);
231 232
232 return val; 233 return val;
233} 234}
234 235
235static void f71805f_write8(struct f71805f_data *data, u8 reg, u8 val) 236static void f71805f_write8(struct f71805f_data *data, u8 reg, u8 val)
236{ 237{
237 down(&data->lock); 238 mutex_lock(&data->lock);
238 outb(reg, data->addr + ADDR_REG_OFFSET); 239 outb(reg, data->addr + ADDR_REG_OFFSET);
239 outb(val, data->addr + DATA_REG_OFFSET); 240 outb(val, data->addr + DATA_REG_OFFSET);
240 up(&data->lock); 241 mutex_unlock(&data->lock);
241} 242}
242 243
243/* It is important to read the MSB first, because doing so latches the 244/* It is important to read the MSB first, because doing so latches the
@@ -246,24 +247,24 @@ static u16 f71805f_read16(struct f71805f_data *data, u8 reg)
246{ 247{
247 u16 val; 248 u16 val;
248 249
249 down(&data->lock); 250 mutex_lock(&data->lock);
250 outb(reg, data->addr + ADDR_REG_OFFSET); 251 outb(reg, data->addr + ADDR_REG_OFFSET);
251 val = inb(data->addr + DATA_REG_OFFSET) << 8; 252 val = inb(data->addr + DATA_REG_OFFSET) << 8;
252 outb(++reg, data->addr + ADDR_REG_OFFSET); 253 outb(++reg, data->addr + ADDR_REG_OFFSET);
253 val |= inb(data->addr + DATA_REG_OFFSET); 254 val |= inb(data->addr + DATA_REG_OFFSET);
254 up(&data->lock); 255 mutex_unlock(&data->lock);
255 256
256 return val; 257 return val;
257} 258}
258 259
259static void f71805f_write16(struct f71805f_data *data, u8 reg, u16 val) 260static void f71805f_write16(struct f71805f_data *data, u8 reg, u16 val)
260{ 261{
261 down(&data->lock); 262 mutex_lock(&data->lock);
262 outb(reg, data->addr + ADDR_REG_OFFSET); 263 outb(reg, data->addr + ADDR_REG_OFFSET);
263 outb(val >> 8, data->addr + DATA_REG_OFFSET); 264 outb(val >> 8, data->addr + DATA_REG_OFFSET);
264 outb(++reg, data->addr + ADDR_REG_OFFSET); 265 outb(++reg, data->addr + ADDR_REG_OFFSET);
265 outb(val & 0xff, data->addr + DATA_REG_OFFSET); 266 outb(val & 0xff, data->addr + DATA_REG_OFFSET);
266 up(&data->lock); 267 mutex_unlock(&data->lock);
267} 268}
268 269
269static struct f71805f_data *f71805f_update_device(struct device *dev) 270static struct f71805f_data *f71805f_update_device(struct device *dev)
@@ -271,7 +272,7 @@ static struct f71805f_data *f71805f_update_device(struct device *dev)
271 struct f71805f_data *data = dev_get_drvdata(dev); 272 struct f71805f_data *data = dev_get_drvdata(dev);
272 int nr; 273 int nr;
273 274
274 down(&data->update_lock); 275 mutex_lock(&data->update_lock);
275 276
276 /* Limit registers cache is refreshed after 60 seconds */ 277 /* Limit registers cache is refreshed after 60 seconds */
277 if (time_after(jiffies, data->last_updated + 60 * HZ) 278 if (time_after(jiffies, data->last_updated + 60 * HZ)
@@ -323,7 +324,7 @@ static struct f71805f_data *f71805f_update_device(struct device *dev)
323 data->valid = 1; 324 data->valid = 1;
324 } 325 }
325 326
326 up(&data->update_lock); 327 mutex_unlock(&data->update_lock);
327 328
328 return data; 329 return data;
329} 330}
@@ -362,10 +363,10 @@ static ssize_t set_in0_max(struct device *dev, struct device_attribute
362 struct f71805f_data *data = dev_get_drvdata(dev); 363 struct f71805f_data *data = dev_get_drvdata(dev);
363 long val = simple_strtol(buf, NULL, 10); 364 long val = simple_strtol(buf, NULL, 10);
364 365
365 down(&data->update_lock); 366 mutex_lock(&data->update_lock);
366 data->in_high[0] = in0_to_reg(val); 367 data->in_high[0] = in0_to_reg(val);
367 f71805f_write8(data, F71805F_REG_IN_HIGH(0), data->in_high[0]); 368 f71805f_write8(data, F71805F_REG_IN_HIGH(0), data->in_high[0]);
368 up(&data->update_lock); 369 mutex_unlock(&data->update_lock);
369 370
370 return count; 371 return count;
371} 372}
@@ -376,10 +377,10 @@ static ssize_t set_in0_min(struct device *dev, struct device_attribute
376 struct f71805f_data *data = dev_get_drvdata(dev); 377 struct f71805f_data *data = dev_get_drvdata(dev);
377 long val = simple_strtol(buf, NULL, 10); 378 long val = simple_strtol(buf, NULL, 10);
378 379
379 down(&data->update_lock); 380 mutex_lock(&data->update_lock);
380 data->in_low[0] = in0_to_reg(val); 381 data->in_low[0] = in0_to_reg(val);
381 f71805f_write8(data, F71805F_REG_IN_LOW(0), data->in_low[0]); 382 f71805f_write8(data, F71805F_REG_IN_LOW(0), data->in_low[0]);
382 up(&data->update_lock); 383 mutex_unlock(&data->update_lock);
383 384
384 return count; 385 return count;
385} 386}
@@ -422,10 +423,10 @@ static ssize_t set_in_max(struct device *dev, struct device_attribute
422 int nr = attr->index; 423 int nr = attr->index;
423 long val = simple_strtol(buf, NULL, 10); 424 long val = simple_strtol(buf, NULL, 10);
424 425
425 down(&data->update_lock); 426 mutex_lock(&data->update_lock);
426 data->in_high[nr] = in_to_reg(val); 427 data->in_high[nr] = in_to_reg(val);
427 f71805f_write8(data, F71805F_REG_IN_HIGH(nr), data->in_high[nr]); 428 f71805f_write8(data, F71805F_REG_IN_HIGH(nr), data->in_high[nr]);
428 up(&data->update_lock); 429 mutex_unlock(&data->update_lock);
429 430
430 return count; 431 return count;
431} 432}
@@ -438,10 +439,10 @@ static ssize_t set_in_min(struct device *dev, struct device_attribute
438 int nr = attr->index; 439 int nr = attr->index;
439 long val = simple_strtol(buf, NULL, 10); 440 long val = simple_strtol(buf, NULL, 10);
440 441
441 down(&data->update_lock); 442 mutex_lock(&data->update_lock);
442 data->in_low[nr] = in_to_reg(val); 443 data->in_low[nr] = in_to_reg(val);
443 f71805f_write8(data, F71805F_REG_IN_LOW(nr), data->in_low[nr]); 444 f71805f_write8(data, F71805F_REG_IN_LOW(nr), data->in_low[nr]);
444 up(&data->update_lock); 445 mutex_unlock(&data->update_lock);
445 446
446 return count; 447 return count;
447} 448}
@@ -474,10 +475,10 @@ static ssize_t set_fan_min(struct device *dev, struct device_attribute
474 int nr = attr->index; 475 int nr = attr->index;
475 long val = simple_strtol(buf, NULL, 10); 476 long val = simple_strtol(buf, NULL, 10);
476 477
477 down(&data->update_lock); 478 mutex_lock(&data->update_lock);
478 data->fan_low[nr] = fan_to_reg(val); 479 data->fan_low[nr] = fan_to_reg(val);
479 f71805f_write16(data, F71805F_REG_FAN_LOW(nr), data->fan_low[nr]); 480 f71805f_write16(data, F71805F_REG_FAN_LOW(nr), data->fan_low[nr]);
480 up(&data->update_lock); 481 mutex_unlock(&data->update_lock);
481 482
482 return count; 483 return count;
483} 484}
@@ -531,10 +532,10 @@ static ssize_t set_temp_max(struct device *dev, struct device_attribute
531 int nr = attr->index; 532 int nr = attr->index;
532 long val = simple_strtol(buf, NULL, 10); 533 long val = simple_strtol(buf, NULL, 10);
533 534
534 down(&data->update_lock); 535 mutex_lock(&data->update_lock);
535 data->temp_high[nr] = temp_to_reg(val); 536 data->temp_high[nr] = temp_to_reg(val);
536 f71805f_write8(data, F71805F_REG_TEMP_HIGH(nr), data->temp_high[nr]); 537 f71805f_write8(data, F71805F_REG_TEMP_HIGH(nr), data->temp_high[nr]);
537 up(&data->update_lock); 538 mutex_unlock(&data->update_lock);
538 539
539 return count; 540 return count;
540} 541}
@@ -547,10 +548,10 @@ static ssize_t set_temp_hyst(struct device *dev, struct device_attribute
547 int nr = attr->index; 548 int nr = attr->index;
548 long val = simple_strtol(buf, NULL, 10); 549 long val = simple_strtol(buf, NULL, 10);
549 550
550 down(&data->update_lock); 551 mutex_lock(&data->update_lock);
551 data->temp_hyst[nr] = temp_to_reg(val); 552 data->temp_hyst[nr] = temp_to_reg(val);
552 f71805f_write8(data, F71805F_REG_TEMP_HYST(nr), data->temp_hyst[nr]); 553 f71805f_write8(data, F71805F_REG_TEMP_HYST(nr), data->temp_hyst[nr]);
553 up(&data->update_lock); 554 mutex_unlock(&data->update_lock);
554 555
555 return count; 556 return count;
556} 557}
@@ -711,9 +712,9 @@ static int __devinit f71805f_probe(struct platform_device *pdev)
711 712
712 res = platform_get_resource(pdev, IORESOURCE_IO, 0); 713 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
713 data->addr = res->start; 714 data->addr = res->start;
714 init_MUTEX(&data->lock); 715 mutex_init(&data->lock);
715 data->name = "f71805f"; 716 data->name = "f71805f";
716 init_MUTEX(&data->update_lock); 717 mutex_init(&data->update_lock);
717 718
718 platform_set_drvdata(pdev, data); 719 platform_set_drvdata(pdev, data);
719 720