aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/vt1211.c
diff options
context:
space:
mode:
authorGuenter Roeck <linux@roeck-us.net>2012-01-15 09:52:33 -0500
committerGuenter Roeck <guenter.roeck@ericsson.com>2012-03-18 21:27:28 -0400
commitb162c033480a7ba0433d329f56c142a0ab59049d (patch)
treed8ace75be0caaf6acf2eb83328bcb8d8ad4a2178 /drivers/hwmon/vt1211.c
parent9004ac8134de260b2eb9a6d8fb2dd4a37321e49b (diff)
hwmon: (vt1211) Fix checkpatch issues
Fixed: ERROR: do not use assignment in if condition ERROR: switch and case should be at the same indent ERROR: trailing statements should be on next line WARNING: braces {} are not necessary for single statement blocks WARNING: simple_strtol is obsolete, use kstrtol instead Modify multi-line comments to follow Documentation/CodingStyle. Not fixed (false positive): ERROR: Macros with complex values should be enclosed in parenthesis Not all fixed (code complexity): ERROR: do not use assignment in if condition Cc: Juerg Haefliger <juergh@gmail.com> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Diffstat (limited to 'drivers/hwmon/vt1211.c')
-rw-r--r--drivers/hwmon/vt1211.c162
1 files changed, 102 insertions, 60 deletions
diff --git a/drivers/hwmon/vt1211.c b/drivers/hwmon/vt1211.c
index 49163d48e96..5de5f72a820 100644
--- a/drivers/hwmon/vt1211.c
+++ b/drivers/hwmon/vt1211.c
@@ -151,8 +151,10 @@ struct vt1211_data {
151#define ISTEMP(ix, uch_config) ((ix) < 2 ? 1 : \ 151#define ISTEMP(ix, uch_config) ((ix) < 2 ? 1 : \
152 ((uch_config) >> (ix)) & 1) 152 ((uch_config) >> (ix)) & 1)
153 153
154/* in5 (ix = 5) is special. It's the internal 3.3V so it's scaled in the 154/*
155 driver according to the VT1211 BIOS porting guide */ 155 * in5 (ix = 5) is special. It's the internal 3.3V so it's scaled in the
156 * driver according to the VT1211 BIOS porting guide
157 */
156#define IN_FROM_REG(ix, reg) ((reg) < 3 ? 0 : (ix) == 5 ? \ 158#define IN_FROM_REG(ix, reg) ((reg) < 3 ? 0 : (ix) == 5 ? \
157 (((reg) - 3) * 15882 + 479) / 958 : \ 159 (((reg) - 3) * 15882 + 479) / 958 : \
158 (((reg) - 3) * 10000 + 479) / 958) 160 (((reg) - 3) * 10000 + 479) / 958)
@@ -160,11 +162,13 @@ struct vt1211_data {
160 ((val) * 958 + 7941) / 15882 + 3 : \ 162 ((val) * 958 + 7941) / 15882 + 3 : \
161 ((val) * 958 + 5000) / 10000 + 3, 0, 255)) 163 ((val) * 958 + 5000) / 10000 + 3, 0, 255))
162 164
163/* temp1 (ix = 0) is an intel thermal diode which is scaled in user space. 165/*
164 temp2 (ix = 1) is the internal temp diode so it's scaled in the driver 166 * temp1 (ix = 0) is an intel thermal diode which is scaled in user space.
165 according to some measurements that I took on an EPIA M10000. 167 * temp2 (ix = 1) is the internal temp diode so it's scaled in the driver
166 temp3-7 are thermistor based so the driver returns the voltage measured at 168 * according to some measurements that I took on an EPIA M10000.
167 the pin (range 0V - 2.2V). */ 169 * temp3-7 are thermistor based so the driver returns the voltage measured at
170 * the pin (range 0V - 2.2V).
171 */
168#define TEMP_FROM_REG(ix, reg) ((ix) == 0 ? (reg) * 1000 : \ 172#define TEMP_FROM_REG(ix, reg) ((ix) == 0 ? (reg) * 1000 : \
169 (ix) == 1 ? (reg) < 51 ? 0 : \ 173 (ix) == 1 ? (reg) < 51 ? 0 : \
170 ((reg) - 51) * 1000 : \ 174 ((reg) - 51) * 1000 : \
@@ -186,8 +190,10 @@ struct vt1211_data {
186 * Super-I/O constants and functions 190 * Super-I/O constants and functions
187 * --------------------------------------------------------------------- */ 191 * --------------------------------------------------------------------- */
188 192
189/* Configuration index port registers 193/*
190 * The vt1211 can live at 2 different addresses so we need to probe both */ 194 * Configuration index port registers
195 * The vt1211 can live at 2 different addresses so we need to probe both
196 */
191#define SIO_REG_CIP1 0x2e 197#define SIO_REG_CIP1 0x2e
192#define SIO_REG_CIP2 0x4e 198#define SIO_REG_CIP2 0x4e
193 199
@@ -377,7 +383,12 @@ static ssize_t set_in(struct device *dev, struct device_attribute *attr,
377 to_sensor_dev_attr_2(attr); 383 to_sensor_dev_attr_2(attr);
378 int ix = sensor_attr_2->index; 384 int ix = sensor_attr_2->index;
379 int fn = sensor_attr_2->nr; 385 int fn = sensor_attr_2->nr;
380 long val = simple_strtol(buf, NULL, 10); 386 long val;
387 int err;
388
389 err = kstrtol(buf, 10, &val);
390 if (err)
391 return err;
381 392
382 mutex_lock(&data->update_lock); 393 mutex_lock(&data->update_lock);
383 switch (fn) { 394 switch (fn) {
@@ -446,7 +457,12 @@ static ssize_t set_temp(struct device *dev, struct device_attribute *attr,
446 to_sensor_dev_attr_2(attr); 457 to_sensor_dev_attr_2(attr);
447 int ix = sensor_attr_2->index; 458 int ix = sensor_attr_2->index;
448 int fn = sensor_attr_2->nr; 459 int fn = sensor_attr_2->nr;
449 long val = simple_strtol(buf, NULL, 10); 460 long val;
461 int err;
462
463 err = kstrtol(buf, 10, &val);
464 if (err)
465 return err;
450 466
451 mutex_lock(&data->update_lock); 467 mutex_lock(&data->update_lock);
452 switch (fn) { 468 switch (fn) {
@@ -517,8 +533,13 @@ static ssize_t set_fan(struct device *dev, struct device_attribute *attr,
517 to_sensor_dev_attr_2(attr); 533 to_sensor_dev_attr_2(attr);
518 int ix = sensor_attr_2->index; 534 int ix = sensor_attr_2->index;
519 int fn = sensor_attr_2->nr; 535 int fn = sensor_attr_2->nr;
520 long val = simple_strtol(buf, NULL, 10);
521 int reg; 536 int reg;
537 unsigned long val;
538 int err;
539
540 err = kstrtoul(buf, 10, &val);
541 if (err)
542 return err;
522 543
523 mutex_lock(&data->update_lock); 544 mutex_lock(&data->update_lock);
524 545
@@ -536,16 +557,23 @@ static ssize_t set_fan(struct device *dev, struct device_attribute *attr,
536 break; 557 break;
537 case SHOW_SET_FAN_DIV: 558 case SHOW_SET_FAN_DIV:
538 switch (val) { 559 switch (val) {
539 case 1: data->fan_div[ix] = 0; break; 560 case 1:
540 case 2: data->fan_div[ix] = 1; break; 561 data->fan_div[ix] = 0;
541 case 4: data->fan_div[ix] = 2; break; 562 break;
542 case 8: data->fan_div[ix] = 3; break; 563 case 2:
543 default: 564 data->fan_div[ix] = 1;
544 count = -EINVAL; 565 break;
545 dev_warn(dev, "fan div value %ld not " 566 case 4:
546 "supported. Choose one of 1, 2, " 567 data->fan_div[ix] = 2;
547 "4, or 8.\n", val); 568 break;
548 goto EXIT; 569 case 8:
570 data->fan_div[ix] = 3;
571 break;
572 default:
573 count = -EINVAL;
574 dev_warn(dev, "fan div value %ld not supported. "
575 "Choose one of 1, 2, 4, or 8.\n", val);
576 goto EXIT;
549 } 577 }
550 vt1211_write8(data, VT1211_REG_FAN_DIV, 578 vt1211_write8(data, VT1211_REG_FAN_DIV,
551 ((data->fan_div[1] << 6) | 579 ((data->fan_div[1] << 6) |
@@ -610,8 +638,13 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
610 to_sensor_dev_attr_2(attr); 638 to_sensor_dev_attr_2(attr);
611 int ix = sensor_attr_2->index; 639 int ix = sensor_attr_2->index;
612 int fn = sensor_attr_2->nr; 640 int fn = sensor_attr_2->nr;
613 long val = simple_strtol(buf, NULL, 10);
614 int tmp, reg; 641 int tmp, reg;
642 unsigned long val;
643 int err;
644
645 err = kstrtoul(buf, 10, &val);
646 if (err)
647 return err;
615 648
616 mutex_lock(&data->update_lock); 649 mutex_lock(&data->update_lock);
617 650
@@ -628,11 +661,12 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
628 switch (val) { 661 switch (val) {
629 case 0: 662 case 0:
630 data->pwm_ctl[ix] &= 7; 663 data->pwm_ctl[ix] &= 7;
631 /* disable SmartGuardian if both PWM outputs are 664 /*
632 * disabled */ 665 * disable SmartGuardian if both PWM outputs are
633 if ((data->pwm_ctl[ix ^ 1] & 1) == 0) { 666 * disabled
667 */
668 if ((data->pwm_ctl[ix ^ 1] & 1) == 0)
634 data->fan_ctl &= 0xe; 669 data->fan_ctl &= 0xe;
635 }
636 break; 670 break;
637 case 2: 671 case 2:
638 data->pwm_ctl[ix] |= 8; 672 data->pwm_ctl[ix] |= 8;
@@ -656,16 +690,15 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
656 val = 135000 / SENSORS_LIMIT(val, 135000 >> 7, 135000); 690 val = 135000 / SENSORS_LIMIT(val, 135000 >> 7, 135000);
657 /* calculate tmp = log2(val) */ 691 /* calculate tmp = log2(val) */
658 tmp = 0; 692 tmp = 0;
659 for (val >>= 1; val > 0; val >>= 1) { 693 for (val >>= 1; val > 0; val >>= 1)
660 tmp++; 694 tmp++;
661 }
662 /* sync the data cache */ 695 /* sync the data cache */
663 reg = vt1211_read8(data, VT1211_REG_PWM_CLK); 696 reg = vt1211_read8(data, VT1211_REG_PWM_CLK);
664 data->pwm_clk = (reg & 0xf8) | tmp; 697 data->pwm_clk = (reg & 0xf8) | tmp;
665 vt1211_write8(data, VT1211_REG_PWM_CLK, data->pwm_clk); 698 vt1211_write8(data, VT1211_REG_PWM_CLK, data->pwm_clk);
666 break; 699 break;
667 case SHOW_SET_PWM_AUTO_CHANNELS_TEMP: 700 case SHOW_SET_PWM_AUTO_CHANNELS_TEMP:
668 if ((val < 1) || (val > 7)) { 701 if (val < 1 || val > 7) {
669 count = -EINVAL; 702 count = -EINVAL;
670 dev_warn(dev, "temp channel %ld not supported. " 703 dev_warn(dev, "temp channel %ld not supported. "
671 "Choose a value between 1 and 7.\n", val); 704 "Choose a value between 1 and 7.\n", val);
@@ -741,8 +774,14 @@ static ssize_t set_pwm_auto_point_temp(struct device *dev,
741 to_sensor_dev_attr_2(attr); 774 to_sensor_dev_attr_2(attr);
742 int ix = sensor_attr_2->index; 775 int ix = sensor_attr_2->index;
743 int ap = sensor_attr_2->nr; 776 int ap = sensor_attr_2->nr;
744 long val = simple_strtol(buf, NULL, 10);
745 int reg; 777 int reg;
778 long val;
779 int err;
780
781 err = kstrtol(buf, 10, &val);
782 if (err)
783 return err;
784
746 785
747 mutex_lock(&data->update_lock); 786 mutex_lock(&data->update_lock);
748 787
@@ -774,7 +813,7 @@ static ssize_t set_pwm_auto_point_temp(struct device *dev,
774 * 1 1 : pwm2 low speed duty cycle (pwm_auto_pwm[1][1]) 813 * 1 1 : pwm2 low speed duty cycle (pwm_auto_pwm[1][1])
775 * 1 2 : pwm2 high speed duty cycle (pwm_auto_pwm[1][2]) 814 * 1 2 : pwm2 high speed duty cycle (pwm_auto_pwm[1][2])
776 * 1 3 : pwm2 full speed (pwm_auto_pwm[1][3], hard-wired to 255) 815 * 1 3 : pwm2 full speed (pwm_auto_pwm[1][3], hard-wired to 255)
777*/ 816 */
778 817
779static ssize_t show_pwm_auto_point_pwm(struct device *dev, 818static ssize_t show_pwm_auto_point_pwm(struct device *dev,
780 struct device_attribute *attr, 819 struct device_attribute *attr,
@@ -798,16 +837,15 @@ static ssize_t set_pwm_auto_point_pwm(struct device *dev,
798 to_sensor_dev_attr_2(attr); 837 to_sensor_dev_attr_2(attr);
799 int ix = sensor_attr_2->index; 838 int ix = sensor_attr_2->index;
800 int ap = sensor_attr_2->nr; 839 int ap = sensor_attr_2->nr;
801 long val = simple_strtol(buf, NULL, 10); 840 unsigned long val;
841 int err;
802 842
803 if ((val < 0) || (val > 255)) { 843 err = kstrtoul(buf, 10, &val);
804 dev_err(dev, "pwm value %ld is out of range. " 844 if (err)
805 "Choose a value between 0 and 255.\n" , val); 845 return err;
806 return -EINVAL;
807 }
808 846
809 mutex_lock(&data->update_lock); 847 mutex_lock(&data->update_lock);
810 data->pwm_auto_pwm[ix][ap] = val; 848 data->pwm_auto_pwm[ix][ap] = SENSORS_LIMIT(val, 0, 255);
811 vt1211_write8(data, VT1211_REG_PWM_AUTO_PWM(ix, ap), 849 vt1211_write8(data, VT1211_REG_PWM_AUTO_PWM(ix, ap),
812 data->pwm_auto_pwm[ix][ap]); 850 data->pwm_auto_pwm[ix][ap]);
813 mutex_unlock(&data->update_lock); 851 mutex_unlock(&data->update_lock);
@@ -831,7 +869,12 @@ static ssize_t set_vrm(struct device *dev, struct device_attribute *attr,
831 const char *buf, size_t count) 869 const char *buf, size_t count)
832{ 870{
833 struct vt1211_data *data = dev_get_drvdata(dev); 871 struct vt1211_data *data = dev_get_drvdata(dev);
834 long val = simple_strtol(buf, NULL, 10); 872 unsigned long val;
873 int err;
874
875 err = kstrtoul(buf, 10, &val);
876 if (err)
877 return err;
835 878
836 data->vrm = val; 879 data->vrm = val;
837 880
@@ -1069,7 +1112,8 @@ static void __devinit vt1211_init_device(struct vt1211_data *data)
1069 vt1211_write8(data, VT1211_REG_UCH_CONFIG, data->uch_config); 1112 vt1211_write8(data, VT1211_REG_UCH_CONFIG, data->uch_config);
1070 } 1113 }
1071 1114
1072 /* Initialize the interrupt mode (if request at module load time). 1115 /*
1116 * Initialize the interrupt mode (if request at module load time).
1073 * The VT1211 implements 3 different modes for clearing interrupts: 1117 * The VT1211 implements 3 different modes for clearing interrupts:
1074 * 0: Clear INT when status register is read. Regenerate INT as long 1118 * 0: Clear INT when status register is read. Regenerate INT as long
1075 * as temp stays above hysteresis limit. 1119 * as temp stays above hysteresis limit.
@@ -1079,7 +1123,8 @@ static void __devinit vt1211_init_device(struct vt1211_data *data)
1079 * 2: Clear INT when temp falls below max limit. 1123 * 2: Clear INT when temp falls below max limit.
1080 * 1124 *
1081 * The driver only allows to force mode 0 since that's the only one 1125 * The driver only allows to force mode 0 since that's the only one
1082 * that makes sense for 'sensors' */ 1126 * that makes sense for 'sensors'
1127 */
1083 if (int_mode == 0) { 1128 if (int_mode == 0) {
1084 vt1211_write8(data, VT1211_REG_TEMP1_CONFIG, 0); 1129 vt1211_write8(data, VT1211_REG_TEMP1_CONFIG, 0);
1085 vt1211_write8(data, VT1211_REG_TEMP2_CONFIG, 0); 1130 vt1211_write8(data, VT1211_REG_TEMP2_CONFIG, 0);
@@ -1119,9 +1164,8 @@ static void vt1211_remove_sysfs(struct platform_device *pdev)
1119 device_remove_file(dev, 1164 device_remove_file(dev,
1120 &vt1211_sysfs_fan_pwm[i].dev_attr); 1165 &vt1211_sysfs_fan_pwm[i].dev_attr);
1121 } 1166 }
1122 for (i = 0; i < ARRAY_SIZE(vt1211_sysfs_misc); i++) { 1167 for (i = 0; i < ARRAY_SIZE(vt1211_sysfs_misc); i++)
1123 device_remove_file(dev, &vt1211_sysfs_misc[i]); 1168 device_remove_file(dev, &vt1211_sysfs_misc[i]);
1124 }
1125} 1169}
1126 1170
1127static int __devinit vt1211_probe(struct platform_device *pdev) 1171static int __devinit vt1211_probe(struct platform_device *pdev)
@@ -1131,7 +1175,8 @@ static int __devinit vt1211_probe(struct platform_device *pdev)
1131 struct resource *res; 1175 struct resource *res;
1132 int i, err; 1176 int i, err;
1133 1177
1134 if (!(data = kzalloc(sizeof(struct vt1211_data), GFP_KERNEL))) { 1178 data = kzalloc(sizeof(struct vt1211_data), GFP_KERNEL);
1179 if (!data) {
1135 err = -ENOMEM; 1180 err = -ENOMEM;
1136 dev_err(dev, "Out of memory\n"); 1181 dev_err(dev, "Out of memory\n");
1137 goto EXIT; 1182 goto EXIT;
@@ -1185,16 +1230,14 @@ static int __devinit vt1211_probe(struct platform_device *pdev)
1185 for (i = 0; i < ARRAY_SIZE(vt1211_sysfs_fan_pwm); i++) { 1230 for (i = 0; i < ARRAY_SIZE(vt1211_sysfs_fan_pwm); i++) {
1186 err = device_create_file(dev, 1231 err = device_create_file(dev,
1187 &vt1211_sysfs_fan_pwm[i].dev_attr); 1232 &vt1211_sysfs_fan_pwm[i].dev_attr);
1188 if (err) { 1233 if (err)
1189 goto EXIT_DEV_REMOVE; 1234 goto EXIT_DEV_REMOVE;
1190 }
1191 } 1235 }
1192 for (i = 0; i < ARRAY_SIZE(vt1211_sysfs_misc); i++) { 1236 for (i = 0; i < ARRAY_SIZE(vt1211_sysfs_misc); i++) {
1193 err = device_create_file(dev, 1237 err = device_create_file(dev,
1194 &vt1211_sysfs_misc[i]); 1238 &vt1211_sysfs_misc[i]);
1195 if (err) { 1239 if (err)
1196 goto EXIT_DEV_REMOVE; 1240 goto EXIT_DEV_REMOVE;
1197 }
1198 } 1241 }
1199 1242
1200 /* Register device */ 1243 /* Register device */
@@ -1293,9 +1336,8 @@ static int __init vt1211_find(int sio_cip, unsigned short *address)
1293 superio_enter(sio_cip); 1336 superio_enter(sio_cip);
1294 1337
1295 devid = force_id ? force_id : superio_inb(sio_cip, SIO_VT1211_DEVID); 1338 devid = force_id ? force_id : superio_inb(sio_cip, SIO_VT1211_DEVID);
1296 if (devid != SIO_VT1211_ID) { 1339 if (devid != SIO_VT1211_ID)
1297 goto EXIT; 1340 goto EXIT;
1298 }
1299 1341
1300 superio_select(sio_cip, SIO_VT1211_LDN_HWMON); 1342 superio_select(sio_cip, SIO_VT1211_LDN_HWMON);
1301 1343
@@ -1325,35 +1367,35 @@ static int __init vt1211_init(void)
1325 int err; 1367 int err;
1326 unsigned short address = 0; 1368 unsigned short address = 0;
1327 1369
1328 if ((err = vt1211_find(SIO_REG_CIP1, &address)) && 1370 err = vt1211_find(SIO_REG_CIP1, &address);
1329 (err = vt1211_find(SIO_REG_CIP2, &address))) { 1371 if (err) {
1330 goto EXIT; 1372 err = vt1211_find(SIO_REG_CIP2, &address);
1373 if (err)
1374 goto EXIT;
1331 } 1375 }
1332 1376
1333 if ((uch_config < -1) || (uch_config > 31)) { 1377 if ((uch_config < -1) || (uch_config > 31)) {
1334 err = -EINVAL; 1378 err = -EINVAL;
1335 pr_warn("Invalid UCH configuration %d. " 1379 pr_warn("Invalid UCH configuration %d. "
1336 "Choose a value between 0 and 31.\n", uch_config); 1380 "Choose a value between 0 and 31.\n", uch_config);
1337 goto EXIT; 1381 goto EXIT;
1338 } 1382 }
1339 1383
1340 if ((int_mode < -1) || (int_mode > 0)) { 1384 if ((int_mode < -1) || (int_mode > 0)) {
1341 err = -EINVAL; 1385 err = -EINVAL;
1342 pr_warn("Invalid interrupt mode %d. " 1386 pr_warn("Invalid interrupt mode %d. "
1343 "Only mode 0 is supported.\n", int_mode); 1387 "Only mode 0 is supported.\n", int_mode);
1344 goto EXIT; 1388 goto EXIT;
1345 } 1389 }
1346 1390
1347 err = platform_driver_register(&vt1211_driver); 1391 err = platform_driver_register(&vt1211_driver);
1348 if (err) { 1392 if (err)
1349 goto EXIT; 1393 goto EXIT;
1350 }
1351 1394
1352 /* Sets global pdev as a side effect */ 1395 /* Sets global pdev as a side effect */
1353 err = vt1211_device_add(address); 1396 err = vt1211_device_add(address);
1354 if (err) { 1397 if (err)
1355 goto EXIT_DRV_UNREGISTER; 1398 goto EXIT_DRV_UNREGISTER;
1356 }
1357 1399
1358 return 0; 1400 return 0;
1359 1401