aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/adm1031.c
diff options
context:
space:
mode:
authorGuenter Roeck <guenter.roeck@ericsson.com>2012-01-16 16:51:48 -0500
committerJean Delvare <khali@endymion.delvare>2012-01-16 16:51:48 -0500
commit1c720093f635af490e103c79c056e7408aee6618 (patch)
treeb604e59b53e73ba693e855b89c746900f091ca69 /drivers/hwmon/adm1031.c
parent16b5dda22e3798e61bb008d2329d4f4d90ef764e (diff)
hwmon: (adm1031) Fix coding style issues
Fix almost all coding style issues except for the multi-line macro errors, which do not really apply since the macros are not multi-line statements but declarations. Based on merged patch series from Zac Storer; fixed remaining checkpatch errors and warnings. Cc: Zac Storer <zac.3.14159@gmail.com> Signed-off-by: Guenter Roeck <guenter.roeck@ericsson.com> Signed-off-by: Jean Delvare <khali@linux-fr.org>
Diffstat (limited to 'drivers/hwmon/adm1031.c')
-rw-r--r--drivers/hwmon/adm1031.c153
1 files changed, 103 insertions, 50 deletions
diff --git a/drivers/hwmon/adm1031.c b/drivers/hwmon/adm1031.c
index e6291dafa4ca..97e2cfb0bc93 100644
--- a/drivers/hwmon/adm1031.c
+++ b/drivers/hwmon/adm1031.c
@@ -155,7 +155,8 @@ adm1031_write_value(struct i2c_client *client, u8 reg, unsigned int value)
155#define TEMP_OFFSET_FROM_REG(val) TEMP_FROM_REG((val) < 0 ? \ 155#define TEMP_OFFSET_FROM_REG(val) TEMP_FROM_REG((val) < 0 ? \
156 (val) | 0x70 : (val)) 156 (val) | 0x70 : (val))
157 157
158#define FAN_FROM_REG(reg, div) ((reg) ? (11250 * 60) / ((reg) * (div)) : 0) 158#define FAN_FROM_REG(reg, div) ((reg) ? \
159 (11250 * 60) / ((reg) * (div)) : 0)
159 160
160static int FAN_TO_REG(int reg, int div) 161static int FAN_TO_REG(int reg, int div)
161{ 162{
@@ -174,8 +175,8 @@ static int FAN_TO_REG(int reg, int div)
174 (((reg) & 0x1F) | (((val) << 5) & 0xe0)) 175 (((reg) & 0x1F) | (((val) << 5) & 0xe0))
175 176
176#define AUTO_TEMP_MIN_TO_REG(val, reg) \ 177#define AUTO_TEMP_MIN_TO_REG(val, reg) \
177 ((((val)/500) & 0xf8)|((reg) & 0x7)) 178 ((((val) / 500) & 0xf8) | ((reg) & 0x7))
178#define AUTO_TEMP_RANGE_FROM_REG(reg) (5000 * (1<< ((reg)&0x7))) 179#define AUTO_TEMP_RANGE_FROM_REG(reg) (5000 * (1 << ((reg) & 0x7)))
179#define AUTO_TEMP_MIN_FROM_REG(reg) (1000 * ((((reg) >> 3) & 0x1f) << 2)) 180#define AUTO_TEMP_MIN_FROM_REG(reg) (1000 * ((((reg) >> 3) & 0x1f) << 2))
180 181
181#define AUTO_TEMP_MIN_FROM_REG_DEG(reg) ((((reg) >> 3) & 0x1f) << 2) 182#define AUTO_TEMP_MIN_FROM_REG_DEG(reg) ((((reg) >> 3) & 0x1f) << 2)
@@ -202,7 +203,7 @@ static int AUTO_TEMP_MAX_TO_REG(int val, int reg, int pwm)
202 203
203/* FAN auto control */ 204/* FAN auto control */
204#define GET_FAN_AUTO_BITFIELD(data, idx) \ 205#define GET_FAN_AUTO_BITFIELD(data, idx) \
205 (*(data)->chan_select_table)[FAN_CHAN_FROM_REG((data)->conf1)][idx%2] 206 (*(data)->chan_select_table)[FAN_CHAN_FROM_REG((data)->conf1)][idx % 2]
206 207
207/* The tables below contains the possible values for the auto fan 208/* The tables below contains the possible values for the auto fan
208 * control bitfields. the index in the table is the register value. 209 * control bitfields. the index in the table is the register value.
@@ -230,7 +231,7 @@ static const auto_chan_table_t auto_channel_select_table_adm1030 = {
230 */ 231 */
231static int 232static int
232get_fan_auto_nearest(struct adm1031_data *data, 233get_fan_auto_nearest(struct adm1031_data *data,
233 int chan, u8 val, u8 reg, u8 * new_reg) 234 int chan, u8 val, u8 reg, u8 *new_reg)
234{ 235{
235 int i; 236 int i;
236 int first_match = -1, exact_match = -1; 237 int first_match = -1, exact_match = -1;
@@ -258,13 +259,13 @@ get_fan_auto_nearest(struct adm1031_data *data,
258 } 259 }
259 } 260 }
260 261
261 if (exact_match >= 0) { 262 if (exact_match >= 0)
262 *new_reg = exact_match; 263 *new_reg = exact_match;
263 } else if (first_match >= 0) { 264 else if (first_match >= 0)
264 *new_reg = first_match; 265 *new_reg = first_match;
265 } else { 266 else
266 return -EINVAL; 267 return -EINVAL;
267 } 268
268 return 0; 269 return 0;
269} 270}
270 271
@@ -283,23 +284,28 @@ set_fan_auto_channel(struct device *dev, struct device_attribute *attr,
283 struct i2c_client *client = to_i2c_client(dev); 284 struct i2c_client *client = to_i2c_client(dev);
284 struct adm1031_data *data = i2c_get_clientdata(client); 285 struct adm1031_data *data = i2c_get_clientdata(client);
285 int nr = to_sensor_dev_attr(attr)->index; 286 int nr = to_sensor_dev_attr(attr)->index;
286 int val = simple_strtol(buf, NULL, 10); 287 long val;
287 u8 reg; 288 u8 reg;
288 int ret; 289 int ret;
289 u8 old_fan_mode; 290 u8 old_fan_mode;
290 291
292 ret = kstrtol(buf, 10, &val);
293 if (ret)
294 return ret;
295
291 old_fan_mode = data->conf1; 296 old_fan_mode = data->conf1;
292 297
293 mutex_lock(&data->update_lock); 298 mutex_lock(&data->update_lock);
294 299
295 if ((ret = get_fan_auto_nearest(data, nr, val, data->conf1, &reg))) { 300 ret = get_fan_auto_nearest(data, nr, val, data->conf1, &reg);
301 if (ret) {
296 mutex_unlock(&data->update_lock); 302 mutex_unlock(&data->update_lock);
297 return ret; 303 return ret;
298 } 304 }
299 data->conf1 = FAN_CHAN_TO_REG(reg, data->conf1); 305 data->conf1 = FAN_CHAN_TO_REG(reg, data->conf1);
300 if ((data->conf1 & ADM1031_CONF1_AUTO_MODE) ^ 306 if ((data->conf1 & ADM1031_CONF1_AUTO_MODE) ^
301 (old_fan_mode & ADM1031_CONF1_AUTO_MODE)) { 307 (old_fan_mode & ADM1031_CONF1_AUTO_MODE)) {
302 if (data->conf1 & ADM1031_CONF1_AUTO_MODE){ 308 if (data->conf1 & ADM1031_CONF1_AUTO_MODE) {
303 /* Switch to Auto Fan Mode 309 /* Switch to Auto Fan Mode
304 * Save PWM registers 310 * Save PWM registers
305 * Set PWM registers to 33% Both */ 311 * Set PWM registers to 33% Both */
@@ -350,7 +356,12 @@ set_auto_temp_min(struct device *dev, struct device_attribute *attr,
350 struct i2c_client *client = to_i2c_client(dev); 356 struct i2c_client *client = to_i2c_client(dev);
351 struct adm1031_data *data = i2c_get_clientdata(client); 357 struct adm1031_data *data = i2c_get_clientdata(client);
352 int nr = to_sensor_dev_attr(attr)->index; 358 int nr = to_sensor_dev_attr(attr)->index;
353 int val = simple_strtol(buf, NULL, 10); 359 long val;
360 int ret;
361
362 ret = kstrtol(buf, 10, &val);
363 if (ret)
364 return ret;
354 365
355 mutex_lock(&data->update_lock); 366 mutex_lock(&data->update_lock);
356 data->auto_temp[nr] = AUTO_TEMP_MIN_TO_REG(val, data->auto_temp[nr]); 367 data->auto_temp[nr] = AUTO_TEMP_MIN_TO_REG(val, data->auto_temp[nr]);
@@ -374,10 +385,16 @@ set_auto_temp_max(struct device *dev, struct device_attribute *attr,
374 struct i2c_client *client = to_i2c_client(dev); 385 struct i2c_client *client = to_i2c_client(dev);
375 struct adm1031_data *data = i2c_get_clientdata(client); 386 struct adm1031_data *data = i2c_get_clientdata(client);
376 int nr = to_sensor_dev_attr(attr)->index; 387 int nr = to_sensor_dev_attr(attr)->index;
377 int val = simple_strtol(buf, NULL, 10); 388 long val;
389 int ret;
390
391 ret = kstrtol(buf, 10, &val);
392 if (ret)
393 return ret;
378 394
379 mutex_lock(&data->update_lock); 395 mutex_lock(&data->update_lock);
380 data->temp_max[nr] = AUTO_TEMP_MAX_TO_REG(val, data->auto_temp[nr], data->pwm[nr]); 396 data->temp_max[nr] = AUTO_TEMP_MAX_TO_REG(val, data->auto_temp[nr],
397 data->pwm[nr]);
381 adm1031_write_value(client, ADM1031_REG_AUTO_TEMP(nr), 398 adm1031_write_value(client, ADM1031_REG_AUTO_TEMP(nr),
382 data->temp_max[nr]); 399 data->temp_max[nr]);
383 mutex_unlock(&data->update_lock); 400 mutex_unlock(&data->update_lock);
@@ -410,8 +427,12 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
410 struct i2c_client *client = to_i2c_client(dev); 427 struct i2c_client *client = to_i2c_client(dev);
411 struct adm1031_data *data = i2c_get_clientdata(client); 428 struct adm1031_data *data = i2c_get_clientdata(client);
412 int nr = to_sensor_dev_attr(attr)->index; 429 int nr = to_sensor_dev_attr(attr)->index;
413 int val = simple_strtol(buf, NULL, 10); 430 long val;
414 int reg; 431 int ret, reg;
432
433 ret = kstrtol(buf, 10, &val);
434 if (ret)
435 return ret;
415 436
416 mutex_lock(&data->update_lock); 437 mutex_lock(&data->update_lock);
417 if ((data->conf1 & ADM1031_CONF1_AUTO_MODE) && 438 if ((data->conf1 & ADM1031_CONF1_AUTO_MODE) &&
@@ -449,9 +470,13 @@ static int trust_fan_readings(struct adm1031_data *data, int chan)
449 470
450 if (data->conf1 & ADM1031_CONF1_AUTO_MODE) { 471 if (data->conf1 & ADM1031_CONF1_AUTO_MODE) {
451 switch (data->conf1 & 0x60) { 472 switch (data->conf1 & 0x60) {
452 case 0x00: /* remote temp1 controls fan1 remote temp2 controls fan2 */ 473 case 0x00:
474 /*
475 * remote temp1 controls fan1,
476 * remote temp2 controls fan2
477 */
453 res = data->temp[chan+1] >= 478 res = data->temp[chan+1] >=
454 AUTO_TEMP_MIN_FROM_REG_DEG(data->auto_temp[chan+1]); 479 AUTO_TEMP_MIN_FROM_REG_DEG(data->auto_temp[chan+1]);
455 break; 480 break;
456 case 0x20: /* remote temp1 controls both fans */ 481 case 0x20: /* remote temp1 controls both fans */
457 res = 482 res =
@@ -515,7 +540,12 @@ static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr,
515 struct i2c_client *client = to_i2c_client(dev); 540 struct i2c_client *client = to_i2c_client(dev);
516 struct adm1031_data *data = i2c_get_clientdata(client); 541 struct adm1031_data *data = i2c_get_clientdata(client);
517 int nr = to_sensor_dev_attr(attr)->index; 542 int nr = to_sensor_dev_attr(attr)->index;
518 int val = simple_strtol(buf, NULL, 10); 543 long val;
544 int ret;
545
546 ret = kstrtol(buf, 10, &val);
547 if (ret)
548 return ret;
519 549
520 mutex_lock(&data->update_lock); 550 mutex_lock(&data->update_lock);
521 if (val) { 551 if (val) {
@@ -534,10 +564,15 @@ static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
534 struct i2c_client *client = to_i2c_client(dev); 564 struct i2c_client *client = to_i2c_client(dev);
535 struct adm1031_data *data = i2c_get_clientdata(client); 565 struct adm1031_data *data = i2c_get_clientdata(client);
536 int nr = to_sensor_dev_attr(attr)->index; 566 int nr = to_sensor_dev_attr(attr)->index;
537 int val = simple_strtol(buf, NULL, 10); 567 long val;
538 u8 tmp; 568 u8 tmp;
539 int old_div; 569 int old_div;
540 int new_min; 570 int new_min;
571 int ret;
572
573 ret = kstrtol(buf, 10, &val);
574 if (ret)
575 return ret;
541 576
542 tmp = val == 8 ? 0xc0 : 577 tmp = val == 8 ? 0xc0 :
543 val == 4 ? 0x80 : 578 val == 4 ? 0x80 :
@@ -631,9 +666,13 @@ static ssize_t set_temp_offset(struct device *dev,
631 struct i2c_client *client = to_i2c_client(dev); 666 struct i2c_client *client = to_i2c_client(dev);
632 struct adm1031_data *data = i2c_get_clientdata(client); 667 struct adm1031_data *data = i2c_get_clientdata(client);
633 int nr = to_sensor_dev_attr(attr)->index; 668 int nr = to_sensor_dev_attr(attr)->index;
634 int val; 669 long val;
670 int ret;
671
672 ret = kstrtol(buf, 10, &val);
673 if (ret)
674 return ret;
635 675
636 val = simple_strtol(buf, NULL, 10);
637 val = SENSORS_LIMIT(val, -15000, 15000); 676 val = SENSORS_LIMIT(val, -15000, 15000);
638 mutex_lock(&data->update_lock); 677 mutex_lock(&data->update_lock);
639 data->temp_offset[nr] = TEMP_OFFSET_TO_REG(val); 678 data->temp_offset[nr] = TEMP_OFFSET_TO_REG(val);
@@ -648,9 +687,13 @@ static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr,
648 struct i2c_client *client = to_i2c_client(dev); 687 struct i2c_client *client = to_i2c_client(dev);
649 struct adm1031_data *data = i2c_get_clientdata(client); 688 struct adm1031_data *data = i2c_get_clientdata(client);
650 int nr = to_sensor_dev_attr(attr)->index; 689 int nr = to_sensor_dev_attr(attr)->index;
651 int val; 690 long val;
691 int ret;
692
693 ret = kstrtol(buf, 10, &val);
694 if (ret)
695 return ret;
652 696
653 val = simple_strtol(buf, NULL, 10);
654 val = SENSORS_LIMIT(val, -55000, nr == 0 ? 127750 : 127875); 697 val = SENSORS_LIMIT(val, -55000, nr == 0 ? 127750 : 127875);
655 mutex_lock(&data->update_lock); 698 mutex_lock(&data->update_lock);
656 data->temp_min[nr] = TEMP_TO_REG(val); 699 data->temp_min[nr] = TEMP_TO_REG(val);
@@ -665,9 +708,13 @@ static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr,
665 struct i2c_client *client = to_i2c_client(dev); 708 struct i2c_client *client = to_i2c_client(dev);
666 struct adm1031_data *data = i2c_get_clientdata(client); 709 struct adm1031_data *data = i2c_get_clientdata(client);
667 int nr = to_sensor_dev_attr(attr)->index; 710 int nr = to_sensor_dev_attr(attr)->index;
668 int val; 711 long val;
712 int ret;
713
714 ret = kstrtol(buf, 10, &val);
715 if (ret)
716 return ret;
669 717
670 val = simple_strtol(buf, NULL, 10);
671 val = SENSORS_LIMIT(val, -55000, nr == 0 ? 127750 : 127875); 718 val = SENSORS_LIMIT(val, -55000, nr == 0 ? 127750 : 127875);
672 mutex_lock(&data->update_lock); 719 mutex_lock(&data->update_lock);
673 data->temp_max[nr] = TEMP_TO_REG(val); 720 data->temp_max[nr] = TEMP_TO_REG(val);
@@ -682,9 +729,13 @@ static ssize_t set_temp_crit(struct device *dev, struct device_attribute *attr,
682 struct i2c_client *client = to_i2c_client(dev); 729 struct i2c_client *client = to_i2c_client(dev);
683 struct adm1031_data *data = i2c_get_clientdata(client); 730 struct adm1031_data *data = i2c_get_clientdata(client);
684 int nr = to_sensor_dev_attr(attr)->index; 731 int nr = to_sensor_dev_attr(attr)->index;
685 int val; 732 long val;
733 int ret;
734
735 ret = kstrtol(buf, 10, &val);
736 if (ret)
737 return ret;
686 738
687 val = simple_strtol(buf, NULL, 10);
688 val = SENSORS_LIMIT(val, -55000, nr == 0 ? 127750 : 127875); 739 val = SENSORS_LIMIT(val, -55000, nr == 0 ? 127750 : 127875);
689 mutex_lock(&data->update_lock); 740 mutex_lock(&data->update_lock);
690 data->temp_crit[nr] = TEMP_TO_REG(val); 741 data->temp_crit[nr] = TEMP_TO_REG(val);
@@ -711,7 +762,8 @@ temp_reg(2);
711temp_reg(3); 762temp_reg(3);
712 763
713/* Alarms */ 764/* Alarms */
714static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, char *buf) 765static ssize_t show_alarms(struct device *dev, struct device_attribute *attr,
766 char *buf)
715{ 767{
716 struct adm1031_data *data = adm1031_update_device(dev); 768 struct adm1031_data *data = adm1031_update_device(dev);
717 return sprintf(buf, "%d\n", data->alarm); 769 return sprintf(buf, "%d\n", data->alarm);
@@ -919,12 +971,13 @@ static int adm1031_probe(struct i2c_client *client,
919 adm1031_init_client(client); 971 adm1031_init_client(client);
920 972
921 /* Register sysfs hooks */ 973 /* Register sysfs hooks */
922 if ((err = sysfs_create_group(&client->dev.kobj, &adm1031_group))) 974 err = sysfs_create_group(&client->dev.kobj, &adm1031_group);
975 if (err)
923 goto exit_free; 976 goto exit_free;
924 977
925 if (data->chip_type == adm1031) { 978 if (data->chip_type == adm1031) {
926 if ((err = sysfs_create_group(&client->dev.kobj, 979 err = sysfs_create_group(&client->dev.kobj, &adm1031_group_opt);
927 &adm1031_group_opt))) 980 if (err)
928 goto exit_remove; 981 goto exit_remove;
929 } 982 }
930 983
@@ -970,14 +1023,13 @@ static void adm1031_init_client(struct i2c_client *client)
970 } 1023 }
971 /* Initialize the ADM1031 chip (enables fan speed reading ) */ 1024 /* Initialize the ADM1031 chip (enables fan speed reading ) */
972 read_val = adm1031_read_value(client, ADM1031_REG_CONF2); 1025 read_val = adm1031_read_value(client, ADM1031_REG_CONF2);
973 if ((read_val | mask) != read_val) { 1026 if ((read_val | mask) != read_val)
974 adm1031_write_value(client, ADM1031_REG_CONF2, read_val | mask); 1027 adm1031_write_value(client, ADM1031_REG_CONF2, read_val | mask);
975 }
976 1028
977 read_val = adm1031_read_value(client, ADM1031_REG_CONF1); 1029 read_val = adm1031_read_value(client, ADM1031_REG_CONF1);
978 if ((read_val | ADM1031_CONF1_MONITOR_ENABLE) != read_val) { 1030 if ((read_val | ADM1031_CONF1_MONITOR_ENABLE) != read_val) {
979 adm1031_write_value(client, ADM1031_REG_CONF1, read_val | 1031 adm1031_write_value(client, ADM1031_REG_CONF1,
980 ADM1031_CONF1_MONITOR_ENABLE); 1032 read_val | ADM1031_CONF1_MONITOR_ENABLE);
981 } 1033 }
982 1034
983 /* Read the chip's update rate */ 1035 /* Read the chip's update rate */
@@ -1024,8 +1076,7 @@ static struct adm1031_data *adm1031_update_device(struct device *dev)
1024 /* oldh is actually newer */ 1076 /* oldh is actually newer */
1025 if (newh != oldh) 1077 if (newh != oldh)
1026 dev_warn(&client->dev, 1078 dev_warn(&client->dev,
1027 "Remote temperature may be " 1079 "Remote temperature may be wrong.\n");
1028 "wrong.\n");
1029#endif 1080#endif
1030 } 1081 }
1031 data->temp[chan] = newh; 1082 data->temp[chan] = newh;
@@ -1052,22 +1103,24 @@ static struct adm1031_data *adm1031_update_device(struct device *dev)
1052 data->conf2 = adm1031_read_value(client, ADM1031_REG_CONF2); 1103 data->conf2 = adm1031_read_value(client, ADM1031_REG_CONF2);
1053 1104
1054 data->alarm = adm1031_read_value(client, ADM1031_REG_STATUS(0)) 1105 data->alarm = adm1031_read_value(client, ADM1031_REG_STATUS(0))
1055 | (adm1031_read_value(client, ADM1031_REG_STATUS(1)) 1106 | (adm1031_read_value(client, ADM1031_REG_STATUS(1)) << 8);
1056 << 8); 1107 if (data->chip_type == adm1030)
1057 if (data->chip_type == adm1030) {
1058 data->alarm &= 0xc0ff; 1108 data->alarm &= 0xc0ff;
1059 }
1060 1109
1061 for (chan=0; chan<(data->chip_type == adm1030 ? 1 : 2); chan++) { 1110 for (chan = 0; chan < (data->chip_type == adm1030 ? 1 : 2);
1111 chan++) {
1062 data->fan_div[chan] = 1112 data->fan_div[chan] =
1063 adm1031_read_value(client, ADM1031_REG_FAN_DIV(chan)); 1113 adm1031_read_value(client,
1114 ADM1031_REG_FAN_DIV(chan));
1064 data->fan_min[chan] = 1115 data->fan_min[chan] =
1065 adm1031_read_value(client, ADM1031_REG_FAN_MIN(chan)); 1116 adm1031_read_value(client,
1117 ADM1031_REG_FAN_MIN(chan));
1066 data->fan[chan] = 1118 data->fan[chan] =
1067 adm1031_read_value(client, ADM1031_REG_FAN_SPEED(chan)); 1119 adm1031_read_value(client,
1120 ADM1031_REG_FAN_SPEED(chan));
1068 data->pwm[chan] = 1121 data->pwm[chan] =
1069 0xf & (adm1031_read_value(client, ADM1031_REG_PWM) >> 1122 (adm1031_read_value(client,
1070 (4*chan)); 1123 ADM1031_REG_PWM) >> (4 * chan)) & 0x0f;
1071 } 1124 }
1072 data->last_updated = jiffies; 1125 data->last_updated = jiffies;
1073 data->valid = 1; 1126 data->valid = 1;