aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/w83781d.c
diff options
context:
space:
mode:
authorJean Delvare <khali@linux-fr.org>2008-10-17 11:51:18 -0400
committerJean Delvare <khali@mahadeva.delvare>2008-10-17 11:51:18 -0400
commit2fbbbf148840332d614790ea00d9a7ecb38d648d (patch)
treeaa091caf282979543ece975e4f19423c8059e263 /drivers/hwmon/w83781d.c
parent6aa693b85257cd41fdb3554016b663519dbf9d14 (diff)
hwmon: (w83781d) Refactor beep enable handling
We can handle the beep enable bit as any other beep mask bit for slightly smaller code. Signed-off-by: Jean Delvare <khali@linux-fr.org> Cc: Wolfgang Grandegger <wg@grandegger.com>
Diffstat (limited to 'drivers/hwmon/w83781d.c')
-rw-r--r--drivers/hwmon/w83781d.c46
1 files changed, 9 insertions, 37 deletions
diff --git a/drivers/hwmon/w83781d.c b/drivers/hwmon/w83781d.c
index f942ecdd47c8..136bec3fd645 100644
--- a/drivers/hwmon/w83781d.c
+++ b/drivers/hwmon/w83781d.c
@@ -178,9 +178,9 @@ FAN_FROM_REG(u8 val, int div)
178#define TEMP_FROM_REG(val) ((val) * 1000) 178#define TEMP_FROM_REG(val) ((val) * 1000)
179 179
180#define BEEP_MASK_FROM_REG(val,type) ((type) == as99127f ? \ 180#define BEEP_MASK_FROM_REG(val,type) ((type) == as99127f ? \
181 (val) ^ 0x7fff : (val)) 181 (~(val)) & 0x7fff : (val) & 0xff7fff)
182#define BEEP_MASK_TO_REG(val,type) ((type) == as99127f ? \ 182#define BEEP_MASK_TO_REG(val,type) ((type) == as99127f ? \
183 (~(val)) & 0x7fff : (val) & 0xffffff) 183 (~(val)) & 0x7fff : (val) & 0xff7fff)
184 184
185#define DIV_FROM_REG(val) (1 << (val)) 185#define DIV_FROM_REG(val) (1 << (val))
186 186
@@ -240,7 +240,6 @@ struct w83781d_data {
240 u8 vid; /* Register encoding, combined */ 240 u8 vid; /* Register encoding, combined */
241 u32 alarms; /* Register encoding, combined */ 241 u32 alarms; /* Register encoding, combined */
242 u32 beep_mask; /* Register encoding, combined */ 242 u32 beep_mask; /* Register encoding, combined */
243 u8 beep_enable; /* Boolean */
244 u8 pwm[4]; /* Register value */ 243 u8 pwm[4]; /* Register value */
245 u8 pwm2_enable; /* Boolean */ 244 u8 pwm2_enable; /* Boolean */
246 u16 sens[3]; /* 782D/783S only. 245 u16 sens[3]; /* 782D/783S only.
@@ -513,11 +512,6 @@ static ssize_t show_beep_mask (struct device *dev, struct device_attribute *attr
513 return sprintf(buf, "%ld\n", 512 return sprintf(buf, "%ld\n",
514 (long)BEEP_MASK_FROM_REG(data->beep_mask, data->type)); 513 (long)BEEP_MASK_FROM_REG(data->beep_mask, data->type));
515} 514}
516static ssize_t show_beep_enable (struct device *dev, struct device_attribute *attr, char *buf)
517{
518 struct w83781d_data *data = w83781d_update_device(dev);
519 return sprintf(buf, "%ld\n", (long)data->beep_enable);
520}
521 515
522static ssize_t 516static ssize_t
523store_beep_mask(struct device *dev, struct device_attribute *attr, 517store_beep_mask(struct device *dev, struct device_attribute *attr,
@@ -529,12 +523,12 @@ store_beep_mask(struct device *dev, struct device_attribute *attr,
529 val = simple_strtoul(buf, NULL, 10); 523 val = simple_strtoul(buf, NULL, 10);
530 524
531 mutex_lock(&data->update_lock); 525 mutex_lock(&data->update_lock);
532 data->beep_mask = BEEP_MASK_TO_REG(val, data->type); 526 data->beep_mask &= 0x8000; /* preserve beep enable */
527 data->beep_mask |= BEEP_MASK_TO_REG(val, data->type);
533 w83781d_write_value(data, W83781D_REG_BEEP_INTS1, 528 w83781d_write_value(data, W83781D_REG_BEEP_INTS1,
534 data->beep_mask & 0xff); 529 data->beep_mask & 0xff);
535 w83781d_write_value(data, W83781D_REG_BEEP_INTS2, 530 w83781d_write_value(data, W83781D_REG_BEEP_INTS2,
536 ((data->beep_mask >> 8) & 0x7f) 531 (data->beep_mask >> 8) & 0xff);
537 | data->beep_enable << 7);
538 if (data->type != w83781d && data->type != as99127f) { 532 if (data->type != w83781d && data->type != as99127f) {
539 w83781d_write_value(data, W83781D_REG_BEEP_INTS3, 533 w83781d_write_value(data, W83781D_REG_BEEP_INTS3,
540 ((data->beep_mask) >> 16) & 0xff); 534 ((data->beep_mask) >> 16) & 0xff);
@@ -544,31 +538,8 @@ store_beep_mask(struct device *dev, struct device_attribute *attr,
544 return count; 538 return count;
545} 539}
546 540
547static ssize_t
548store_beep_enable(struct device *dev, struct device_attribute *attr,
549 const char *buf, size_t count)
550{
551 struct w83781d_data *data = dev_get_drvdata(dev);
552 u32 val;
553
554 val = simple_strtoul(buf, NULL, 10);
555 if (val != 0 && val != 1)
556 return -EINVAL;
557
558 mutex_lock(&data->update_lock);
559 data->beep_enable = val;
560 val = w83781d_read_value(data, W83781D_REG_BEEP_INTS2) & 0x7f;
561 val |= data->beep_enable << 7;
562 w83781d_write_value(data, W83781D_REG_BEEP_INTS2, val);
563 mutex_unlock(&data->update_lock);
564
565 return count;
566}
567
568static DEVICE_ATTR(beep_mask, S_IRUGO | S_IWUSR, 541static DEVICE_ATTR(beep_mask, S_IRUGO | S_IWUSR,
569 show_beep_mask, store_beep_mask); 542 show_beep_mask, store_beep_mask);
570static DEVICE_ATTR(beep_enable, S_IRUGO | S_IWUSR,
571 show_beep_enable, store_beep_enable);
572 543
573static ssize_t show_beep(struct device *dev, struct device_attribute *attr, 544static ssize_t show_beep(struct device *dev, struct device_attribute *attr,
574 char *buf) 545 char *buf)
@@ -663,6 +634,8 @@ static SENSOR_DEVICE_ATTR(temp2_beep, S_IRUGO | S_IWUSR,
663 show_beep, store_beep, 5); 634 show_beep, store_beep, 5);
664static SENSOR_DEVICE_ATTR(temp3_beep, S_IRUGO, 635static SENSOR_DEVICE_ATTR(temp3_beep, S_IRUGO,
665 show_temp3_beep, store_beep, 13); 636 show_temp3_beep, store_beep, 13);
637static SENSOR_DEVICE_ATTR(beep_enable, S_IRUGO | S_IWUSR,
638 show_beep, store_beep, 15);
666 639
667static ssize_t 640static ssize_t
668show_fan_div(struct device *dev, struct device_attribute *da, char *buf) 641show_fan_div(struct device *dev, struct device_attribute *da, char *buf)
@@ -1029,7 +1002,7 @@ static struct attribute* w83781d_attributes[] = {
1029 &dev_attr_vrm.attr, 1002 &dev_attr_vrm.attr,
1030 &dev_attr_alarms.attr, 1003 &dev_attr_alarms.attr,
1031 &dev_attr_beep_mask.attr, 1004 &dev_attr_beep_mask.attr,
1032 &dev_attr_beep_enable.attr, 1005 &sensor_dev_attr_beep_enable.dev_attr.attr,
1033 NULL 1006 NULL
1034}; 1007};
1035static const struct attribute_group w83781d_group = { 1008static const struct attribute_group w83781d_group = {
@@ -1775,8 +1748,7 @@ static struct w83781d_data *w83781d_update_device(struct device *dev)
1775 W83781D_REG_ALARM2) << 8); 1748 W83781D_REG_ALARM2) << 8);
1776 } 1749 }
1777 i = w83781d_read_value(data, W83781D_REG_BEEP_INTS2); 1750 i = w83781d_read_value(data, W83781D_REG_BEEP_INTS2);
1778 data->beep_enable = i >> 7; 1751 data->beep_mask = (i << 8) +
1779 data->beep_mask = ((i & 0x7f) << 8) +
1780 w83781d_read_value(data, W83781D_REG_BEEP_INTS1); 1752 w83781d_read_value(data, W83781D_REG_BEEP_INTS1);
1781 if ((data->type != w83781d) && (data->type != as99127f)) { 1753 if ((data->type != w83781d) && (data->type != as99127f)) {
1782 data->beep_mask |= 1754 data->beep_mask |=