diff options
author | Jean Delvare <khali@linux-fr.org> | 2008-01-03 17:04:55 -0500 |
---|---|---|
committer | Mark M. Hoffman <mhoffman@lightlink.com> | 2008-02-07 20:39:45 -0500 |
commit | 1c1381076f8c6cf0a2c9918194e3fa6369cdf06a (patch) | |
tree | 1b542417e95fe9ccc5911d997681d45fd4d6f1cb /drivers | |
parent | e3604c626cdcddf37bf5c9663ae75b79dad40000 (diff) |
hwmon: (w83627hf) 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>
Signed-off-by: Mark M. Hoffman <mhoffman@lightlink.com>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/hwmon/w83627hf.c | 76 |
1 files changed, 25 insertions, 51 deletions
diff --git a/drivers/hwmon/w83627hf.c b/drivers/hwmon/w83627hf.c index c02c3bbde19f..9564fb069957 100644 --- a/drivers/hwmon/w83627hf.c +++ b/drivers/hwmon/w83627hf.c | |||
@@ -323,10 +323,8 @@ static inline u8 pwm_freq_to_reg(unsigned long val) | |||
323 | return (0x80 | (180000UL / (val << 8))); | 323 | return (0x80 | (180000UL / (val << 8))); |
324 | } | 324 | } |
325 | 325 | ||
326 | #define BEEP_MASK_FROM_REG(val) (val) | 326 | #define BEEP_MASK_FROM_REG(val) ((val) & 0xff7fff) |
327 | #define BEEP_MASK_TO_REG(val) ((val) & 0xffffff) | 327 | #define BEEP_MASK_TO_REG(val) ((val) & 0xff7fff) |
328 | #define BEEP_ENABLE_TO_REG(val) ((val)?1:0) | ||
329 | #define BEEP_ENABLE_FROM_REG(val) ((val)?1:0) | ||
330 | 328 | ||
331 | #define DIV_FROM_REG(val) (1 << (val)) | 329 | #define DIV_FROM_REG(val) (1 << (val)) |
332 | 330 | ||
@@ -367,7 +365,6 @@ struct w83627hf_data { | |||
367 | u8 vid; /* Register encoding, combined */ | 365 | u8 vid; /* Register encoding, combined */ |
368 | u32 alarms; /* Register encoding, combined */ | 366 | u32 alarms; /* Register encoding, combined */ |
369 | u32 beep_mask; /* Register encoding, combined */ | 367 | u32 beep_mask; /* Register encoding, combined */ |
370 | u8 beep_enable; /* Boolean */ | ||
371 | u8 pwm[3]; /* Register value */ | 368 | u8 pwm[3]; /* Register value */ |
372 | u8 pwm_freq[3]; /* Register value */ | 369 | u8 pwm_freq[3]; /* Register value */ |
373 | u16 sens[3]; /* 1 = pentium diode; 2 = 3904 diode; | 370 | u16 sens[3]; /* 1 = pentium diode; 2 = 3904 diode; |
@@ -740,65 +737,41 @@ static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 4); | |||
740 | static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 5); | 737 | static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 5); |
741 | static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 13); | 738 | static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 13); |
742 | 739 | ||
743 | #define show_beep_reg(REG, reg) \ | 740 | static ssize_t |
744 | static ssize_t show_beep_##reg (struct device *dev, struct device_attribute *attr, char *buf) \ | 741 | show_beep_mask(struct device *dev, struct device_attribute *attr, char *buf) |
745 | { \ | 742 | { |
746 | struct w83627hf_data *data = w83627hf_update_device(dev); \ | 743 | struct w83627hf_data *data = w83627hf_update_device(dev); |
747 | return sprintf(buf,"%ld\n", \ | 744 | return sprintf(buf, "%ld\n", |
748 | (long)BEEP_##REG##_FROM_REG(data->beep_##reg)); \ | 745 | (long)BEEP_MASK_FROM_REG(data->beep_mask)); |
749 | } | 746 | } |
750 | show_beep_reg(ENABLE, enable) | ||
751 | show_beep_reg(MASK, mask) | ||
752 | |||
753 | #define BEEP_ENABLE 0 /* Store beep_enable */ | ||
754 | #define BEEP_MASK 1 /* Store beep_mask */ | ||
755 | 747 | ||
756 | static ssize_t | 748 | static ssize_t |
757 | store_beep_reg(struct device *dev, const char *buf, size_t count, | 749 | store_beep_mask(struct device *dev, struct device_attribute *attr, |
758 | int update_mask) | 750 | const char *buf, size_t count) |
759 | { | 751 | { |
760 | struct w83627hf_data *data = dev_get_drvdata(dev); | 752 | struct w83627hf_data *data = dev_get_drvdata(dev); |
761 | u32 val, val2; | 753 | unsigned long val; |
762 | 754 | ||
763 | val = simple_strtoul(buf, NULL, 10); | 755 | val = simple_strtoul(buf, NULL, 10); |
764 | 756 | ||
765 | mutex_lock(&data->update_lock); | 757 | mutex_lock(&data->update_lock); |
766 | 758 | ||
767 | if (update_mask == BEEP_MASK) { /* We are storing beep_mask */ | 759 | /* preserve beep enable */ |
768 | data->beep_mask = BEEP_MASK_TO_REG(val); | 760 | data->beep_mask = (data->beep_mask & 0x8000) |
769 | w83627hf_write_value(data, W83781D_REG_BEEP_INTS1, | 761 | | BEEP_MASK_TO_REG(val); |
770 | data->beep_mask & 0xff); | 762 | w83627hf_write_value(data, W83781D_REG_BEEP_INTS1, |
771 | w83627hf_write_value(data, W83781D_REG_BEEP_INTS3, | 763 | data->beep_mask & 0xff); |
772 | ((data->beep_mask) >> 16) & 0xff); | 764 | w83627hf_write_value(data, W83781D_REG_BEEP_INTS3, |
773 | val2 = (data->beep_mask >> 8) & 0x7f; | 765 | ((data->beep_mask) >> 16) & 0xff); |
774 | } else { /* We are storing beep_enable */ | ||
775 | val2 = | ||
776 | w83627hf_read_value(data, W83781D_REG_BEEP_INTS2) & 0x7f; | ||
777 | data->beep_enable = BEEP_ENABLE_TO_REG(val); | ||
778 | } | ||
779 | |||
780 | w83627hf_write_value(data, W83781D_REG_BEEP_INTS2, | 766 | w83627hf_write_value(data, W83781D_REG_BEEP_INTS2, |
781 | val2 | data->beep_enable << 7); | 767 | (data->beep_mask >> 8) & 0xff); |
782 | 768 | ||
783 | mutex_unlock(&data->update_lock); | 769 | mutex_unlock(&data->update_lock); |
784 | return count; | 770 | return count; |
785 | } | 771 | } |
786 | 772 | ||
787 | #define sysfs_beep(REG, reg) \ | 773 | static DEVICE_ATTR(beep_mask, S_IRUGO | S_IWUSR, |
788 | static ssize_t show_regs_beep_##reg (struct device *dev, struct device_attribute *attr, char *buf) \ | 774 | show_beep_mask, store_beep_mask); |
789 | { \ | ||
790 | return show_beep_##reg(dev, attr, buf); \ | ||
791 | } \ | ||
792 | static ssize_t \ | ||
793 | store_regs_beep_##reg (struct device *dev, struct device_attribute *attr, const char *buf, size_t count) \ | ||
794 | { \ | ||
795 | return store_beep_reg(dev, buf, count, BEEP_##REG); \ | ||
796 | } \ | ||
797 | static DEVICE_ATTR(beep_##reg, S_IRUGO | S_IWUSR, \ | ||
798 | show_regs_beep_##reg, store_regs_beep_##reg); | ||
799 | |||
800 | sysfs_beep(ENABLE, enable); | ||
801 | sysfs_beep(MASK, mask); | ||
802 | 775 | ||
803 | static ssize_t | 776 | static ssize_t |
804 | show_beep(struct device *dev, struct device_attribute *attr, char *buf) | 777 | show_beep(struct device *dev, struct device_attribute *attr, char *buf) |
@@ -884,6 +857,8 @@ static SENSOR_DEVICE_ATTR(temp2_beep, S_IRUGO | S_IWUSR, | |||
884 | show_beep, store_beep, 5); | 857 | show_beep, store_beep, 5); |
885 | static SENSOR_DEVICE_ATTR(temp3_beep, S_IRUGO | S_IWUSR, | 858 | static SENSOR_DEVICE_ATTR(temp3_beep, S_IRUGO | S_IWUSR, |
886 | show_beep, store_beep, 13); | 859 | show_beep, store_beep, 13); |
860 | static SENSOR_DEVICE_ATTR(beep_enable, S_IRUGO | S_IWUSR, | ||
861 | show_beep, store_beep, 15); | ||
887 | 862 | ||
888 | static ssize_t | 863 | static ssize_t |
889 | show_fan_div(struct device *dev, struct device_attribute *devattr, char *buf) | 864 | show_fan_div(struct device *dev, struct device_attribute *devattr, char *buf) |
@@ -1223,7 +1198,7 @@ static struct attribute *w83627hf_attributes[] = { | |||
1223 | TEMP_UNIT_ATTRS(2), | 1198 | TEMP_UNIT_ATTRS(2), |
1224 | 1199 | ||
1225 | &dev_attr_alarms.attr, | 1200 | &dev_attr_alarms.attr, |
1226 | &dev_attr_beep_enable.attr, | 1201 | &sensor_dev_attr_beep_enable.dev_attr.attr, |
1227 | &dev_attr_beep_mask.attr, | 1202 | &dev_attr_beep_mask.attr, |
1228 | 1203 | ||
1229 | &sensor_dev_attr_pwm1.dev_attr.attr, | 1204 | &sensor_dev_attr_pwm1.dev_attr.attr, |
@@ -1748,8 +1723,7 @@ static struct w83627hf_data *w83627hf_update_device(struct device *dev) | |||
1748 | (w83627hf_read_value(data, W83781D_REG_ALARM2) << 8) | | 1723 | (w83627hf_read_value(data, W83781D_REG_ALARM2) << 8) | |
1749 | (w83627hf_read_value(data, W83781D_REG_ALARM3) << 16); | 1724 | (w83627hf_read_value(data, W83781D_REG_ALARM3) << 16); |
1750 | i = w83627hf_read_value(data, W83781D_REG_BEEP_INTS2); | 1725 | i = w83627hf_read_value(data, W83781D_REG_BEEP_INTS2); |
1751 | data->beep_enable = i >> 7; | 1726 | data->beep_mask = (i << 8) | |
1752 | data->beep_mask = ((i & 0x7f) << 8) | | ||
1753 | w83627hf_read_value(data, W83781D_REG_BEEP_INTS1) | | 1727 | w83627hf_read_value(data, W83781D_REG_BEEP_INTS1) | |
1754 | w83627hf_read_value(data, W83781D_REG_BEEP_INTS3) << 16; | 1728 | w83627hf_read_value(data, W83781D_REG_BEEP_INTS3) << 16; |
1755 | data->last_updated = jiffies; | 1729 | data->last_updated = jiffies; |