aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/w83627ehf.c
diff options
context:
space:
mode:
authorGuenter Roeck <guenter.roeck@ericsson.com>2011-02-04 15:54:14 -0500
committerGuenter Roeck <guenter.roeck@ericsson.com>2011-03-15 01:39:13 -0400
commitbce26c58df86599c9570cee83eac58bdaae760e4 (patch)
tree0c9623f1cf7c273b7e201080ff85adff94b83bc5 /drivers/hwmon/w83627ehf.c
parent2d2e148a237f790a19e2faa6d8387cf254010358 (diff)
hwmon: (w83627ehf) Unify temperature register access, and use strict string conversions
This patch unifies temperature register access, and replaces simple_strtoXXX with strict_strtoXXX throughout the driver. Signed-off-by: Guenter Roeck <guenter.roeck@ericsson.com> Acked-by: Ian Dobson <i.dobson@planet-ian.com>
Diffstat (limited to 'drivers/hwmon/w83627ehf.c')
-rw-r--r--drivers/hwmon/w83627ehf.c219
1 files changed, 113 insertions, 106 deletions
diff --git a/drivers/hwmon/w83627ehf.c b/drivers/hwmon/w83627ehf.c
index 073eabedc432..66e6855f9397 100644
--- a/drivers/hwmon/w83627ehf.c
+++ b/drivers/hwmon/w83627ehf.c
@@ -164,13 +164,10 @@ static const u16 W83627EHF_REG_FAN_MIN[] = { 0x3b, 0x3c, 0x3d, 0x3e, 0x55c };
164#define W83627EHF_REG_IN(nr) ((nr < 7) ? (0x20 + (nr)) : \ 164#define W83627EHF_REG_IN(nr) ((nr < 7) ? (0x20 + (nr)) : \
165 (0x550 + (nr) - 7)) 165 (0x550 + (nr) - 7))
166 166
167#define W83627EHF_REG_TEMP1 0x27 167static const u16 W83627EHF_REG_TEMP[] = { 0x27, 0x150, 0x250 };
168#define W83627EHF_REG_TEMP1_HYST 0x3a 168static const u16 W83627EHF_REG_TEMP_HYST[] = { 0x3a, 0x153, 0x253 };
169#define W83627EHF_REG_TEMP1_OVER 0x39 169static const u16 W83627EHF_REG_TEMP_OVER[] = { 0x39, 0x155, 0x255 };
170static const u16 W83627EHF_REG_TEMP[] = { 0x150, 0x250 }; 170static const u16 W83627EHF_REG_TEMP_CONFIG[] = { 0, 0x152, 0x252 };
171static const u16 W83627EHF_REG_TEMP_HYST[] = { 0x153, 0x253 };
172static const u16 W83627EHF_REG_TEMP_OVER[] = { 0x155, 0x255 };
173static const u16 W83627EHF_REG_TEMP_CONFIG[] = { 0x152, 0x252 };
174 171
175/* Fan clock dividers are spread over the following five registers */ 172/* Fan clock dividers are spread over the following five registers */
176#define W83627EHF_REG_FANDIV1 0x47 173#define W83627EHF_REG_FANDIV1 0x47
@@ -216,6 +213,15 @@ static const u8 W83627EHF_REG_FAN_STEP_OUTPUT_COMMON[]
216static const u8 W83627EHF_REG_FAN_MAX_OUTPUT_W83667_B[] = { 0x67, 0x69, 0x6b }; 213static const u8 W83627EHF_REG_FAN_MAX_OUTPUT_W83667_B[] = { 0x67, 0x69, 0x6b };
217static const u8 W83627EHF_REG_FAN_STEP_OUTPUT_W83667_B[] = { 0x68, 0x6a, 0x6c }; 214static const u8 W83627EHF_REG_FAN_STEP_OUTPUT_W83667_B[] = { 0x68, 0x6a, 0x6c };
218 215
216static inline int is_word_sized(u16 reg)
217{
218 return (((reg & 0xff00) == 0x100
219 || (reg & 0xff00) == 0x200)
220 && ((reg & 0x00ff) == 0x50
221 || (reg & 0x00ff) == 0x53
222 || (reg & 0x00ff) == 0x55));
223}
224
219/* 225/*
220 * Conversions 226 * Conversions
221 */ 227 */
@@ -247,21 +253,19 @@ div_from_reg(u8 reg)
247} 253}
248 254
249static inline int 255static inline int
250temp1_from_reg(s8 reg) 256temp_from_reg(u16 reg, s16 regval)
251{ 257{
252 return reg * 1000; 258 if (is_word_sized(reg))
259 return LM75_TEMP_FROM_REG(regval);
260 return regval * 1000;
253} 261}
254 262
255static inline s8 263static inline s16
256temp1_to_reg(long temp, int min, int max) 264temp_to_reg(u16 reg, long temp)
257{ 265{
258 if (temp <= min) 266 if (is_word_sized(reg))
259 return min / 1000; 267 return LM75_TEMP_TO_REG(temp);
260 if (temp >= max) 268 return DIV_ROUND_CLOSEST(SENSORS_LIMIT(temp, -127000, 128000), 1000);
261 return max / 1000;
262 if (temp < 0)
263 return (temp - 500) / 1000;
264 return (temp + 500) / 1000;
265} 269}
266 270
267/* Some of analog inputs have internal scaling (2x), 8mV is ADC LSB */ 271/* Some of analog inputs have internal scaling (2x), 8mV is ADC LSB */
@@ -308,12 +312,9 @@ struct w83627ehf_data {
308 u8 fan_div[5]; 312 u8 fan_div[5];
309 u8 has_fan; /* some fan inputs can be disabled */ 313 u8 has_fan; /* some fan inputs can be disabled */
310 u8 temp_type[3]; 314 u8 temp_type[3];
311 s8 temp1; 315 s16 temp[3];
312 s8 temp1_max; 316 s16 temp_max[3];
313 s8 temp1_max_hyst; 317 s16 temp_max_hyst[3];
314 s16 temp[2];
315 s16 temp_max[2];
316 s16 temp_max_hyst[2];
317 u32 alarms; 318 u32 alarms;
318 319
319 u8 pwm_mode[4]; /* 0->DC variable voltage, 1->PWM variable duty cycle */ 320 u8 pwm_mode[4]; /* 0->DC variable voltage, 1->PWM variable duty cycle */
@@ -344,15 +345,6 @@ struct w83627ehf_sio_data {
344 enum kinds kind; 345 enum kinds kind;
345}; 346};
346 347
347static inline int is_word_sized(u16 reg)
348{
349 return (((reg & 0xff00) == 0x100
350 || (reg & 0xff00) == 0x200)
351 && ((reg & 0x00ff) == 0x50
352 || (reg & 0x00ff) == 0x53
353 || (reg & 0x00ff) == 0x55));
354}
355
356/* Registers 0x50-0x5f are banked */ 348/* Registers 0x50-0x5f are banked */
357static inline void w83627ehf_set_bank(struct w83627ehf_data *data, u16 reg) 349static inline void w83627ehf_set_bank(struct w83627ehf_data *data, u16 reg)
358{ 350{
@@ -586,13 +578,7 @@ static struct w83627ehf_data *w83627ehf_update_device(struct device *dev)
586 } 578 }
587 579
588 /* Measured temperatures and limits */ 580 /* Measured temperatures and limits */
589 data->temp1 = w83627ehf_read_value(data, 581 for (i = 0; i < 3; i++) {
590 W83627EHF_REG_TEMP1);
591 data->temp1_max = w83627ehf_read_value(data,
592 W83627EHF_REG_TEMP1_OVER);
593 data->temp1_max_hyst = w83627ehf_read_value(data,
594 W83627EHF_REG_TEMP1_HYST);
595 for (i = 0; i < 2; i++) {
596 data->temp[i] = w83627ehf_read_value(data, 582 data->temp[i] = w83627ehf_read_value(data,
597 W83627EHF_REG_TEMP[i]); 583 W83627EHF_REG_TEMP[i]);
598 data->temp_max[i] = w83627ehf_read_value(data, 584 data->temp_max[i] = w83627ehf_read_value(data,
@@ -641,8 +627,11 @@ store_in_##reg (struct device *dev, struct device_attribute *attr, \
641 struct w83627ehf_data *data = dev_get_drvdata(dev); \ 627 struct w83627ehf_data *data = dev_get_drvdata(dev); \
642 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \ 628 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \
643 int nr = sensor_attr->index; \ 629 int nr = sensor_attr->index; \
644 u32 val = simple_strtoul(buf, NULL, 10); \ 630 unsigned long val; \
645 \ 631 int err; \
632 err = strict_strtoul(buf, 10, &val); \
633 if (err < 0) \
634 return err; \
646 mutex_lock(&data->update_lock); \ 635 mutex_lock(&data->update_lock); \
647 data->in_##reg[nr] = in_to_reg(val, nr); \ 636 data->in_##reg[nr] = in_to_reg(val, nr); \
648 w83627ehf_write_value(data, W83627EHF_REG_IN_##REG(nr), \ 637 w83627ehf_write_value(data, W83627EHF_REG_IN_##REG(nr), \
@@ -746,10 +735,15 @@ store_fan_min(struct device *dev, struct device_attribute *attr,
746 struct w83627ehf_data *data = dev_get_drvdata(dev); 735 struct w83627ehf_data *data = dev_get_drvdata(dev);
747 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 736 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
748 int nr = sensor_attr->index; 737 int nr = sensor_attr->index;
749 unsigned int val = simple_strtoul(buf, NULL, 10); 738 unsigned long val;
739 int err;
750 unsigned int reg; 740 unsigned int reg;
751 u8 new_div; 741 u8 new_div;
752 742
743 err = strict_strtoul(buf, 10, &val);
744 if (err < 0)
745 return err;
746
753 mutex_lock(&data->update_lock); 747 mutex_lock(&data->update_lock);
754 if (!val) { 748 if (!val) {
755 /* No min limit, alarm disabled */ 749 /* No min limit, alarm disabled */
@@ -761,14 +755,14 @@ store_fan_min(struct device *dev, struct device_attribute *attr,
761 even with the highest divider (128) */ 755 even with the highest divider (128) */
762 data->fan_min[nr] = 254; 756 data->fan_min[nr] = 254;
763 new_div = 7; /* 128 == (1 << 7) */ 757 new_div = 7; /* 128 == (1 << 7) */
764 dev_warn(dev, "fan%u low limit %u below minimum %u, set to " 758 dev_warn(dev, "fan%u low limit %lu below minimum %u, set to "
765 "minimum\n", nr + 1, val, fan_from_reg(254, 128)); 759 "minimum\n", nr + 1, val, fan_from_reg(254, 128));
766 } else if (!reg) { 760 } else if (!reg) {
767 /* Speed above this value cannot possibly be represented, 761 /* Speed above this value cannot possibly be represented,
768 even with the lowest divider (1) */ 762 even with the lowest divider (1) */
769 data->fan_min[nr] = 1; 763 data->fan_min[nr] = 1;
770 new_div = 0; /* 1 == (1 << 0) */ 764 new_div = 0; /* 1 == (1 << 0) */
771 dev_warn(dev, "fan%u low limit %u above maximum %u, set to " 765 dev_warn(dev, "fan%u low limit %lu above maximum %u, set to "
772 "maximum\n", nr + 1, val, fan_from_reg(1, 1)); 766 "maximum\n", nr + 1, val, fan_from_reg(1, 1));
773 } else { 767 } else {
774 /* Automatically pick the best divider, i.e. the one such 768 /* Automatically pick the best divider, i.e. the one such
@@ -847,37 +841,7 @@ static struct sensor_device_attribute sda_fan_div[] = {
847 SENSOR_ATTR(fan5_div, S_IRUGO, show_fan_div, NULL, 4), 841 SENSOR_ATTR(fan5_div, S_IRUGO, show_fan_div, NULL, 4),
848}; 842};
849 843
850#define show_temp1_reg(reg) \ 844#define show_temp_reg(REG, reg) \
851static ssize_t \
852show_##reg(struct device *dev, struct device_attribute *attr, \
853 char *buf) \
854{ \
855 struct w83627ehf_data *data = w83627ehf_update_device(dev); \
856 return sprintf(buf, "%d\n", temp1_from_reg(data->reg)); \
857}
858show_temp1_reg(temp1);
859show_temp1_reg(temp1_max);
860show_temp1_reg(temp1_max_hyst);
861
862#define store_temp1_reg(REG, reg) \
863static ssize_t \
864store_temp1_##reg(struct device *dev, struct device_attribute *attr, \
865 const char *buf, size_t count) \
866{ \
867 struct w83627ehf_data *data = dev_get_drvdata(dev); \
868 long val = simple_strtol(buf, NULL, 10); \
869 \
870 mutex_lock(&data->update_lock); \
871 data->temp1_##reg = temp1_to_reg(val, -128000, 127000); \
872 w83627ehf_write_value(data, W83627EHF_REG_TEMP1_##REG, \
873 data->temp1_##reg); \
874 mutex_unlock(&data->update_lock); \
875 return count; \
876}
877store_temp1_reg(OVER, max);
878store_temp1_reg(HYST, max_hyst);
879
880#define show_temp_reg(reg) \
881static ssize_t \ 845static ssize_t \
882show_##reg(struct device *dev, struct device_attribute *attr, \ 846show_##reg(struct device *dev, struct device_attribute *attr, \
883 char *buf) \ 847 char *buf) \
@@ -886,11 +850,11 @@ show_##reg(struct device *dev, struct device_attribute *attr, \
886 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \ 850 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \
887 int nr = sensor_attr->index; \ 851 int nr = sensor_attr->index; \
888 return sprintf(buf, "%d\n", \ 852 return sprintf(buf, "%d\n", \
889 LM75_TEMP_FROM_REG(data->reg[nr])); \ 853 temp_from_reg(W83627EHF_REG_##REG[nr], data->reg[nr])); \
890} 854}
891show_temp_reg(temp); 855show_temp_reg(TEMP, temp);
892show_temp_reg(temp_max); 856show_temp_reg(TEMP_OVER, temp_max);
893show_temp_reg(temp_max_hyst); 857show_temp_reg(TEMP_HYST, temp_max_hyst);
894 858
895#define store_temp_reg(REG, reg) \ 859#define store_temp_reg(REG, reg) \
896static ssize_t \ 860static ssize_t \
@@ -900,10 +864,13 @@ store_##reg(struct device *dev, struct device_attribute *attr, \
900 struct w83627ehf_data *data = dev_get_drvdata(dev); \ 864 struct w83627ehf_data *data = dev_get_drvdata(dev); \
901 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \ 865 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \
902 int nr = sensor_attr->index; \ 866 int nr = sensor_attr->index; \
903 long val = simple_strtol(buf, NULL, 10); \ 867 int err; \
904 \ 868 long val; \
869 err = strict_strtol(buf, 10, &val); \
870 if (err < 0) \
871 return err; \
905 mutex_lock(&data->update_lock); \ 872 mutex_lock(&data->update_lock); \
906 data->reg[nr] = LM75_TEMP_TO_REG(val); \ 873 data->reg[nr] = temp_to_reg(W83627EHF_REG_TEMP_##REG[nr], val); \
907 w83627ehf_write_value(data, W83627EHF_REG_TEMP_##REG[nr], \ 874 w83627ehf_write_value(data, W83627EHF_REG_TEMP_##REG[nr], \
908 data->reg[nr]); \ 875 data->reg[nr]); \
909 mutex_unlock(&data->update_lock); \ 876 mutex_unlock(&data->update_lock); \
@@ -922,27 +889,27 @@ show_temp_type(struct device *dev, struct device_attribute *attr, char *buf)
922} 889}
923 890
924static struct sensor_device_attribute sda_temp_input[] = { 891static struct sensor_device_attribute sda_temp_input[] = {
925 SENSOR_ATTR(temp1_input, S_IRUGO, show_temp1, NULL, 0), 892 SENSOR_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0),
926 SENSOR_ATTR(temp2_input, S_IRUGO, show_temp, NULL, 0), 893 SENSOR_ATTR(temp2_input, S_IRUGO, show_temp, NULL, 1),
927 SENSOR_ATTR(temp3_input, S_IRUGO, show_temp, NULL, 1), 894 SENSOR_ATTR(temp3_input, S_IRUGO, show_temp, NULL, 2),
928}; 895};
929 896
930static struct sensor_device_attribute sda_temp_max[] = { 897static struct sensor_device_attribute sda_temp_max[] = {
931 SENSOR_ATTR(temp1_max, S_IRUGO | S_IWUSR, show_temp1_max, 898 SENSOR_ATTR(temp1_max, S_IRUGO | S_IWUSR, show_temp_max,
932 store_temp1_max, 0),
933 SENSOR_ATTR(temp2_max, S_IRUGO | S_IWUSR, show_temp_max,
934 store_temp_max, 0), 899 store_temp_max, 0),
935 SENSOR_ATTR(temp3_max, S_IRUGO | S_IWUSR, show_temp_max, 900 SENSOR_ATTR(temp2_max, S_IRUGO | S_IWUSR, show_temp_max,
936 store_temp_max, 1), 901 store_temp_max, 1),
902 SENSOR_ATTR(temp3_max, S_IRUGO | S_IWUSR, show_temp_max,
903 store_temp_max, 2),
937}; 904};
938 905
939static struct sensor_device_attribute sda_temp_max_hyst[] = { 906static struct sensor_device_attribute sda_temp_max_hyst[] = {
940 SENSOR_ATTR(temp1_max_hyst, S_IRUGO | S_IWUSR, show_temp1_max_hyst, 907 SENSOR_ATTR(temp1_max_hyst, S_IRUGO | S_IWUSR, show_temp_max_hyst,
941 store_temp1_max_hyst, 0),
942 SENSOR_ATTR(temp2_max_hyst, S_IRUGO | S_IWUSR, show_temp_max_hyst,
943 store_temp_max_hyst, 0), 908 store_temp_max_hyst, 0),
944 SENSOR_ATTR(temp3_max_hyst, S_IRUGO | S_IWUSR, show_temp_max_hyst, 909 SENSOR_ATTR(temp2_max_hyst, S_IRUGO | S_IWUSR, show_temp_max_hyst,
945 store_temp_max_hyst, 1), 910 store_temp_max_hyst, 1),
911 SENSOR_ATTR(temp3_max_hyst, S_IRUGO | S_IWUSR, show_temp_max_hyst,
912 store_temp_max_hyst, 2),
946}; 913};
947 914
948static struct sensor_device_attribute sda_temp_alarm[] = { 915static struct sensor_device_attribute sda_temp_alarm[] = {
@@ -978,9 +945,14 @@ store_pwm_mode(struct device *dev, struct device_attribute *attr,
978 struct w83627ehf_data *data = dev_get_drvdata(dev); 945 struct w83627ehf_data *data = dev_get_drvdata(dev);
979 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 946 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
980 int nr = sensor_attr->index; 947 int nr = sensor_attr->index;
981 u32 val = simple_strtoul(buf, NULL, 10); 948 unsigned long val;
949 int err;
982 u16 reg; 950 u16 reg;
983 951
952 err = strict_strtoul(buf, 10, &val);
953 if (err < 0)
954 return err;
955
984 if (val > 1) 956 if (val > 1)
985 return -EINVAL; 957 return -EINVAL;
986 mutex_lock(&data->update_lock); 958 mutex_lock(&data->update_lock);
@@ -1001,7 +973,14 @@ store_pwm(struct device *dev, struct device_attribute *attr,
1001 struct w83627ehf_data *data = dev_get_drvdata(dev); 973 struct w83627ehf_data *data = dev_get_drvdata(dev);
1002 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 974 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1003 int nr = sensor_attr->index; 975 int nr = sensor_attr->index;
1004 u32 val = SENSORS_LIMIT(simple_strtoul(buf, NULL, 10), 0, 255); 976 unsigned long val;
977 int err;
978
979 err = strict_strtoul(buf, 10, &val);
980 if (err < 0)
981 return err;
982
983 val = SENSORS_LIMIT(val, 0, 255);
1005 984
1006 mutex_lock(&data->update_lock); 985 mutex_lock(&data->update_lock);
1007 data->pwm[nr] = val; 986 data->pwm[nr] = val;
@@ -1017,9 +996,14 @@ store_pwm_enable(struct device *dev, struct device_attribute *attr,
1017 struct w83627ehf_data *data = dev_get_drvdata(dev); 996 struct w83627ehf_data *data = dev_get_drvdata(dev);
1018 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 997 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1019 int nr = sensor_attr->index; 998 int nr = sensor_attr->index;
1020 u32 val = simple_strtoul(buf, NULL, 10); 999 unsigned long val;
1000 int err;
1021 u16 reg; 1001 u16 reg;
1022 1002
1003 err = strict_strtoul(buf, 10, &val);
1004 if (err < 0)
1005 return err;
1006
1023 if (!val || (val > 4)) 1007 if (!val || (val > 4))
1024 return -EINVAL; 1008 return -EINVAL;
1025 mutex_lock(&data->update_lock); 1009 mutex_lock(&data->update_lock);
@@ -1040,7 +1024,7 @@ static ssize_t show_##reg(struct device *dev, struct device_attribute *attr, \
1040 struct w83627ehf_data *data = w83627ehf_update_device(dev); \ 1024 struct w83627ehf_data *data = w83627ehf_update_device(dev); \
1041 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \ 1025 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \
1042 int nr = sensor_attr->index; \ 1026 int nr = sensor_attr->index; \
1043 return sprintf(buf, "%d\n", temp1_from_reg(data->reg[nr])); \ 1027 return sprintf(buf, "%d\n", data->reg[nr] * 1000); \
1044} 1028}
1045 1029
1046show_tol_temp(tolerance) 1030show_tol_temp(tolerance)
@@ -1053,7 +1037,14 @@ store_target_temp(struct device *dev, struct device_attribute *attr,
1053 struct w83627ehf_data *data = dev_get_drvdata(dev); 1037 struct w83627ehf_data *data = dev_get_drvdata(dev);
1054 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 1038 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1055 int nr = sensor_attr->index; 1039 int nr = sensor_attr->index;
1056 u8 val = temp1_to_reg(simple_strtoul(buf, NULL, 10), 0, 127000); 1040 long val;
1041 int err;
1042
1043 err = strict_strtol(buf, 10, &val);
1044 if (err < 0)
1045 return err;
1046
1047 val = SENSORS_LIMIT(DIV_ROUND_CLOSEST(val, 1000), 0, 127);
1057 1048
1058 mutex_lock(&data->update_lock); 1049 mutex_lock(&data->update_lock);
1059 data->target_temp[nr] = val; 1050 data->target_temp[nr] = val;
@@ -1070,8 +1061,15 @@ store_tolerance(struct device *dev, struct device_attribute *attr,
1070 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 1061 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1071 int nr = sensor_attr->index; 1062 int nr = sensor_attr->index;
1072 u16 reg; 1063 u16 reg;
1064 long val;
1065 int err;
1066
1067 err = strict_strtol(buf, 10, &val);
1068 if (err < 0)
1069 return err;
1070
1073 /* Limit the temp to 0C - 15C */ 1071 /* Limit the temp to 0C - 15C */
1074 u8 val = temp1_to_reg(simple_strtoul(buf, NULL, 10), 0, 15000); 1072 val = SENSORS_LIMIT(DIV_ROUND_CLOSEST(val, 1000), 0, 15);
1075 1073
1076 mutex_lock(&data->update_lock); 1074 mutex_lock(&data->update_lock);
1077 reg = w83627ehf_read_value(data, W83627EHF_REG_TOLERANCE[nr]); 1075 reg = w83627ehf_read_value(data, W83627EHF_REG_TOLERANCE[nr]);
@@ -1154,7 +1152,12 @@ store_##reg(struct device *dev, struct device_attribute *attr, \
1154 struct w83627ehf_data *data = dev_get_drvdata(dev); \ 1152 struct w83627ehf_data *data = dev_get_drvdata(dev); \
1155 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \ 1153 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \
1156 int nr = sensor_attr->index; \ 1154 int nr = sensor_attr->index; \
1157 u32 val = SENSORS_LIMIT(simple_strtoul(buf, NULL, 10), 1, 255); \ 1155 unsigned long val; \
1156 int err; \
1157 err = strict_strtoul(buf, 10, &val); \
1158 if (err < 0) \
1159 return err; \
1160 val = SENSORS_LIMIT(val, 1, 255); \
1158 mutex_lock(&data->update_lock); \ 1161 mutex_lock(&data->update_lock); \
1159 data->reg[nr] = val; \ 1162 data->reg[nr] = val; \
1160 w83627ehf_write_value(data, data->REG_##REG[nr], val); \ 1163 w83627ehf_write_value(data, data->REG_##REG[nr], val); \
@@ -1185,8 +1188,12 @@ store_##reg(struct device *dev, struct device_attribute *attr, \
1185 struct w83627ehf_data *data = dev_get_drvdata(dev); \ 1188 struct w83627ehf_data *data = dev_get_drvdata(dev); \
1186 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \ 1189 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \
1187 int nr = sensor_attr->index; \ 1190 int nr = sensor_attr->index; \
1188 u8 val = step_time_to_reg(simple_strtoul(buf, NULL, 10), \ 1191 unsigned long val; \
1189 data->pwm_mode[nr]); \ 1192 int err; \
1193 err = strict_strtoul(buf, 10, &val); \
1194 if (err < 0) \
1195 return err; \
1196 val = step_time_to_reg(val, data->pwm_mode[nr]); \
1190 mutex_lock(&data->update_lock); \ 1197 mutex_lock(&data->update_lock); \
1191 data->reg[nr] = val; \ 1198 data->reg[nr] = val; \
1192 w83627ehf_write_value(data, W83627EHF_REG_##REG[nr], val); \ 1199 w83627ehf_write_value(data, W83627EHF_REG_##REG[nr], val); \
@@ -1336,10 +1343,10 @@ static inline void __devinit w83627ehf_init_device(struct w83627ehf_data *data)
1336 tmp | 0x01); 1343 tmp | 0x01);
1337 1344
1338 /* Enable temp2 and temp3 if needed */ 1345 /* Enable temp2 and temp3 if needed */
1339 for (i = 0; i < 2; i++) { 1346 for (i = 1; i < 3; i++) {
1340 tmp = w83627ehf_read_value(data, 1347 tmp = w83627ehf_read_value(data,
1341 W83627EHF_REG_TEMP_CONFIG[i]); 1348 W83627EHF_REG_TEMP_CONFIG[i]);
1342 if ((i == 1) && data->temp3_disable) 1349 if ((i == 2) && data->temp3_disable)
1343 continue; 1350 continue;
1344 if (tmp & 0x01) 1351 if (tmp & 0x01)
1345 w83627ehf_write_value(data, 1352 w83627ehf_write_value(data,
@@ -1400,7 +1407,7 @@ static int __devinit w83627ehf_probe(struct platform_device *pdev)
1400 /* Check temp3 configuration bit for 667HG */ 1407 /* Check temp3 configuration bit for 667HG */
1401 if (sio_data->kind == w83667hg || sio_data->kind == w83667hg_b) { 1408 if (sio_data->kind == w83667hg || sio_data->kind == w83667hg_b) {
1402 data->temp3_disable = w83627ehf_read_value(data, 1409 data->temp3_disable = w83627ehf_read_value(data,
1403 W83627EHF_REG_TEMP_CONFIG[1]) & 0x01; 1410 W83627EHF_REG_TEMP_CONFIG[2]) & 0x01;
1404 data->in6_skip = !data->temp3_disable; 1411 data->in6_skip = !data->temp3_disable;
1405 } 1412 }
1406 1413