aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/hwmon')
-rw-r--r--drivers/hwmon/Kconfig24
-rw-r--r--drivers/hwmon/Makefile2
-rw-r--r--drivers/hwmon/abituguru.c36
-rw-r--r--drivers/hwmon/abituguru3.c45
-rw-r--r--drivers/hwmon/adm9240.c32
-rw-r--r--drivers/hwmon/ads7828.c4
-rw-r--r--drivers/hwmon/adt7470.c4
-rw-r--r--drivers/hwmon/applesmc.c1632
-rw-r--r--drivers/hwmon/asb100.c9
-rw-r--r--drivers/hwmon/asus_atk0110.c7
-rw-r--r--drivers/hwmon/coretemp.c11
-rw-r--r--drivers/hwmon/dme1737.c201
-rw-r--r--drivers/hwmon/ds620.c337
-rw-r--r--drivers/hwmon/emc1403.c16
-rw-r--r--drivers/hwmon/f71805f.c29
-rw-r--r--drivers/hwmon/f71882fg.c23
-rw-r--r--drivers/hwmon/fschmd.c5
-rw-r--r--drivers/hwmon/hp_accel.c13
-rw-r--r--drivers/hwmon/hwmon-vid.c11
-rw-r--r--drivers/hwmon/hwmon.c4
-rw-r--r--drivers/hwmon/ibmaem.c4
-rw-r--r--drivers/hwmon/it87.c30
-rw-r--r--drivers/hwmon/lis3lv02d.c23
-rw-r--r--drivers/hwmon/lm70.c5
-rw-r--r--drivers/hwmon/lm78.c14
-rw-r--r--drivers/hwmon/lm95241.c495
-rw-r--r--drivers/hwmon/pc87360.c53
-rw-r--r--drivers/hwmon/pc87427.c26
-rw-r--r--drivers/hwmon/pcf8591.c5
-rw-r--r--drivers/hwmon/pkgtemp.c7
-rw-r--r--drivers/hwmon/sht21.c307
-rw-r--r--drivers/hwmon/sis5595.c10
-rw-r--r--drivers/hwmon/smsc47b397.c13
-rw-r--r--drivers/hwmon/smsc47m1.c31
-rw-r--r--drivers/hwmon/via-cputemp.c35
-rw-r--r--drivers/hwmon/via686a.c24
-rw-r--r--drivers/hwmon/vt1211.c30
-rw-r--r--drivers/hwmon/vt8231.c10
-rw-r--r--drivers/hwmon/w83627ehf.c23
-rw-r--r--drivers/hwmon/w83627hf.c17
-rw-r--r--drivers/hwmon/w83781d.c29
-rw-r--r--drivers/hwmon/w83792d.c44
-rw-r--r--drivers/hwmon/w83793.c38
-rw-r--r--drivers/hwmon/w83795.c4
44 files changed, 2009 insertions, 1713 deletions
diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index a56f6adf3b76..35f00dae3676 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -274,6 +274,16 @@ config SENSORS_ATXP1
274 This driver can also be built as a module. If so, the module 274 This driver can also be built as a module. If so, the module
275 will be called atxp1. 275 will be called atxp1.
276 276
277config SENSORS_DS620
278 tristate "Dallas Semiconductor DS620"
279 depends on I2C
280 help
281 If you say yes here you get support for Dallas Semiconductor
282 DS620 sensor chip.
283
284 This driver can also be built as a module. If so, the module
285 will be called ds620.
286
277config SENSORS_DS1621 287config SENSORS_DS1621
278 tristate "Dallas Semiconductor DS1621 and DS1625" 288 tristate "Dallas Semiconductor DS1621 and DS1625"
279 depends on I2C 289 depends on I2C
@@ -734,6 +744,16 @@ config SENSORS_SHT15
734 This driver can also be built as a module. If so, the module 744 This driver can also be built as a module. If so, the module
735 will be called sht15. 745 will be called sht15.
736 746
747config SENSORS_SHT21
748 tristate "Sensiron humidity and temperature sensors. SHT21 and compat."
749 depends on I2C
750 help
751 If you say yes here you get support for the Sensiron SHT21, SHT25
752 humidity and temperature sensors.
753
754 This driver can also be built as a module. If so, the module
755 will be called sht21.
756
737config SENSORS_S3C 757config SENSORS_S3C
738 tristate "Samsung built-in ADC" 758 tristate "Samsung built-in ADC"
739 depends on S3C_ADC 759 depends on S3C_ADC
@@ -789,10 +809,10 @@ config SENSORS_DME1737
789 will be called dme1737. 809 will be called dme1737.
790 810
791config SENSORS_EMC1403 811config SENSORS_EMC1403
792 tristate "SMSC EMC1403 thermal sensor" 812 tristate "SMSC EMC1403/23 thermal sensor"
793 depends on I2C 813 depends on I2C
794 help 814 help
795 If you say yes here you get support for the SMSC EMC1403 815 If you say yes here you get support for the SMSC EMC1403/23
796 temperature monitoring chip. 816 temperature monitoring chip.
797 817
798 Threshold values can be configured using sysfs. 818 Threshold values can be configured using sysfs.
diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
index 2479b3da272c..dde02d99c238 100644
--- a/drivers/hwmon/Makefile
+++ b/drivers/hwmon/Makefile
@@ -41,6 +41,7 @@ obj-$(CONFIG_SENSORS_ATXP1) += atxp1.o
41obj-$(CONFIG_SENSORS_CORETEMP) += coretemp.o 41obj-$(CONFIG_SENSORS_CORETEMP) += coretemp.o
42obj-$(CONFIG_SENSORS_PKGTEMP) += pkgtemp.o 42obj-$(CONFIG_SENSORS_PKGTEMP) += pkgtemp.o
43obj-$(CONFIG_SENSORS_DME1737) += dme1737.o 43obj-$(CONFIG_SENSORS_DME1737) += dme1737.o
44obj-$(CONFIG_SENSORS_DS620) += ds620.o
44obj-$(CONFIG_SENSORS_DS1621) += ds1621.o 45obj-$(CONFIG_SENSORS_DS1621) += ds1621.o
45obj-$(CONFIG_SENSORS_EMC1403) += emc1403.o 46obj-$(CONFIG_SENSORS_EMC1403) += emc1403.o
46obj-$(CONFIG_SENSORS_EMC2103) += emc2103.o 47obj-$(CONFIG_SENSORS_EMC2103) += emc2103.o
@@ -90,6 +91,7 @@ obj-$(CONFIG_SENSORS_PC87427) += pc87427.o
90obj-$(CONFIG_SENSORS_PCF8591) += pcf8591.o 91obj-$(CONFIG_SENSORS_PCF8591) += pcf8591.o
91obj-$(CONFIG_SENSORS_S3C) += s3c-hwmon.o 92obj-$(CONFIG_SENSORS_S3C) += s3c-hwmon.o
92obj-$(CONFIG_SENSORS_SHT15) += sht15.o 93obj-$(CONFIG_SENSORS_SHT15) += sht15.o
94obj-$(CONFIG_SENSORS_SHT21) += sht21.o
93obj-$(CONFIG_SENSORS_SIS5595) += sis5595.o 95obj-$(CONFIG_SENSORS_SIS5595) += sis5595.o
94obj-$(CONFIG_SENSORS_SMM665) += smm665.o 96obj-$(CONFIG_SENSORS_SMM665) += smm665.o
95obj-$(CONFIG_SENSORS_SMSC47B397)+= smsc47b397.o 97obj-$(CONFIG_SENSORS_SMSC47B397)+= smsc47b397.o
diff --git a/drivers/hwmon/abituguru.c b/drivers/hwmon/abituguru.c
index 03694cc17a32..8f07a9dda152 100644
--- a/drivers/hwmon/abituguru.c
+++ b/drivers/hwmon/abituguru.c
@@ -20,6 +20,9 @@
20 the custom Abit uGuru chip found on Abit uGuru motherboards. Note: because 20 the custom Abit uGuru chip found on Abit uGuru motherboards. Note: because
21 of lack of specs the CPU/RAM voltage & frequency control is not supported! 21 of lack of specs the CPU/RAM voltage & frequency control is not supported!
22*/ 22*/
23
24#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
25
23#include <linux/module.h> 26#include <linux/module.h>
24#include <linux/sched.h> 27#include <linux/sched.h>
25#include <linux/init.h> 28#include <linux/init.h>
@@ -220,6 +223,10 @@ struct abituguru_data {
220 u8 pwm_settings[ABIT_UGURU_MAX_PWMS][5]; 223 u8 pwm_settings[ABIT_UGURU_MAX_PWMS][5];
221}; 224};
222 225
226static const char *never_happen = "This should never happen.";
227static const char *report_this =
228 "Please report this to the abituguru maintainer (see MAINTAINERS)";
229
223/* wait till the uguru is in the specified state */ 230/* wait till the uguru is in the specified state */
224static int abituguru_wait(struct abituguru_data *data, u8 state) 231static int abituguru_wait(struct abituguru_data *data, u8 state)
225{ 232{
@@ -438,8 +445,7 @@ abituguru_detect_bank1_sensor_type(struct abituguru_data *data,
438 445
439 /* Test val is sane / usable for sensor type detection. */ 446 /* Test val is sane / usable for sensor type detection. */
440 if ((val < 10u) || (val > 250u)) { 447 if ((val < 10u) || (val > 250u)) {
441 printk(KERN_WARNING ABIT_UGURU_NAME 448 pr_warn("bank1-sensor: %d reading (%d) too close to limits, "
442 ": bank1-sensor: %d reading (%d) too close to limits, "
443 "unable to determine sensor type, skipping sensor\n", 449 "unable to determine sensor type, skipping sensor\n",
444 (int)sensor_addr, (int)val); 450 (int)sensor_addr, (int)val);
445 /* assume no sensor is there for sensors for which we can't 451 /* assume no sensor is there for sensors for which we can't
@@ -535,10 +541,8 @@ abituguru_detect_bank1_sensor_type_exit:
535 3) == 3) 541 3) == 3)
536 break; 542 break;
537 if (i == 3) { 543 if (i == 3) {
538 printk(KERN_ERR ABIT_UGURU_NAME 544 pr_err("Fatal error could not restore original settings. %s %s\n",
539 ": Fatal error could not restore original settings. " 545 never_happen, report_this);
540 "This should never happen please report this to the "
541 "abituguru maintainer (see MAINTAINERS)\n");
542 return -ENODEV; 546 return -ENODEV;
543 } 547 }
544 return ret; 548 return ret;
@@ -1268,14 +1272,12 @@ static int __devinit abituguru_probe(struct platform_device *pdev)
1268 } 1272 }
1269 /* Fail safe check, this should never happen! */ 1273 /* Fail safe check, this should never happen! */
1270 if (sysfs_names_free < 0) { 1274 if (sysfs_names_free < 0) {
1271 printk(KERN_ERR ABIT_UGURU_NAME ": Fatal error ran out of " 1275 pr_err("Fatal error ran out of space for sysfs attr names. %s %s",
1272 "space for sysfs attr names. This should never " 1276 never_happen, report_this);
1273 "happen please report to the abituguru maintainer "
1274 "(see MAINTAINERS)\n");
1275 res = -ENAMETOOLONG; 1277 res = -ENAMETOOLONG;
1276 goto abituguru_probe_error; 1278 goto abituguru_probe_error;
1277 } 1279 }
1278 printk(KERN_INFO ABIT_UGURU_NAME ": found Abit uGuru\n"); 1280 pr_info("found Abit uGuru\n");
1279 1281
1280 /* Register sysfs hooks */ 1282 /* Register sysfs hooks */
1281 for (i = 0; i < sysfs_attr_i; i++) 1283 for (i = 0; i < sysfs_attr_i; i++)
@@ -1432,8 +1434,7 @@ static int __init abituguru_detect(void)
1432 "0x%02X\n", (unsigned int)data_val, (unsigned int)cmd_val); 1434 "0x%02X\n", (unsigned int)data_val, (unsigned int)cmd_val);
1433 1435
1434 if (force) { 1436 if (force) {
1435 printk(KERN_INFO ABIT_UGURU_NAME ": Assuming Abit uGuru is " 1437 pr_info("Assuming Abit uGuru is present because of \"force\" parameter\n");
1436 "present because of \"force\" parameter\n");
1437 return ABIT_UGURU_BASE; 1438 return ABIT_UGURU_BASE;
1438 } 1439 }
1439 1440
@@ -1467,8 +1468,7 @@ static int __init abituguru_init(void)
1467 1468
1468 abituguru_pdev = platform_device_alloc(ABIT_UGURU_NAME, address); 1469 abituguru_pdev = platform_device_alloc(ABIT_UGURU_NAME, address);
1469 if (!abituguru_pdev) { 1470 if (!abituguru_pdev) {
1470 printk(KERN_ERR ABIT_UGURU_NAME 1471 pr_err("Device allocation failed\n");
1471 ": Device allocation failed\n");
1472 err = -ENOMEM; 1472 err = -ENOMEM;
1473 goto exit_driver_unregister; 1473 goto exit_driver_unregister;
1474 } 1474 }
@@ -1479,15 +1479,13 @@ static int __init abituguru_init(void)
1479 1479
1480 err = platform_device_add_resources(abituguru_pdev, &res, 1); 1480 err = platform_device_add_resources(abituguru_pdev, &res, 1);
1481 if (err) { 1481 if (err) {
1482 printk(KERN_ERR ABIT_UGURU_NAME 1482 pr_err("Device resource addition failed (%d)\n", err);
1483 ": Device resource addition failed (%d)\n", err);
1484 goto exit_device_put; 1483 goto exit_device_put;
1485 } 1484 }
1486 1485
1487 err = platform_device_add(abituguru_pdev); 1486 err = platform_device_add(abituguru_pdev);
1488 if (err) { 1487 if (err) {
1489 printk(KERN_ERR ABIT_UGURU_NAME 1488 pr_err("Device addition failed (%d)\n", err);
1490 ": Device addition failed (%d)\n", err);
1491 goto exit_device_put; 1489 goto exit_device_put;
1492 } 1490 }
1493 1491
diff --git a/drivers/hwmon/abituguru3.c b/drivers/hwmon/abituguru3.c
index 3cf28af614b5..48d21e22e930 100644
--- a/drivers/hwmon/abituguru3.c
+++ b/drivers/hwmon/abituguru3.c
@@ -23,6 +23,9 @@
23 chip found on newer Abit uGuru motherboards. Note: because of lack of specs 23 chip found on newer Abit uGuru motherboards. Note: because of lack of specs
24 only reading the sensors and their settings is supported. 24 only reading the sensors and their settings is supported.
25*/ 25*/
26
27#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
28
26#include <linux/module.h> 29#include <linux/module.h>
27#include <linux/init.h> 30#include <linux/init.h>
28#include <linux/slab.h> 31#include <linux/slab.h>
@@ -608,6 +611,9 @@ static int verbose = 1;
608module_param(verbose, bool, 0644); 611module_param(verbose, bool, 0644);
609MODULE_PARM_DESC(verbose, "Enable/disable verbose error reporting"); 612MODULE_PARM_DESC(verbose, "Enable/disable verbose error reporting");
610 613
614static const char *never_happen = "This should never happen.";
615static const char *report_this =
616 "Please report this to the abituguru3 maintainer (see MAINTAINERS)";
611 617
612/* wait while the uguru is busy (usually after a write) */ 618/* wait while the uguru is busy (usually after a write) */
613static int abituguru3_wait_while_busy(struct abituguru3_data *data) 619static int abituguru3_wait_while_busy(struct abituguru3_data *data)
@@ -940,15 +946,13 @@ static int __devinit abituguru3_probe(struct platform_device *pdev)
940 if (abituguru3_motherboards[i].id == id) 946 if (abituguru3_motherboards[i].id == id)
941 break; 947 break;
942 if (!abituguru3_motherboards[i].id) { 948 if (!abituguru3_motherboards[i].id) {
943 printk(KERN_ERR ABIT_UGURU3_NAME ": error unknown motherboard " 949 pr_err("error unknown motherboard ID: %04X. %s\n",
944 "ID: %04X. Please report this to the abituguru3 " 950 (unsigned int)id, report_this);
945 "maintainer (see MAINTAINERS)\n", (unsigned int)id);
946 goto abituguru3_probe_error; 951 goto abituguru3_probe_error;
947 } 952 }
948 data->sensors = abituguru3_motherboards[i].sensors; 953 data->sensors = abituguru3_motherboards[i].sensors;
949 954
950 printk(KERN_INFO ABIT_UGURU3_NAME ": found Abit uGuru3, motherboard " 955 pr_info("found Abit uGuru3, motherboard ID: %04X\n", (unsigned int)id);
951 "ID: %04X\n", (unsigned int)id);
952 956
953 /* Fill the sysfs attr array */ 957 /* Fill the sysfs attr array */
954 sysfs_attr_i = 0; 958 sysfs_attr_i = 0;
@@ -957,11 +961,8 @@ static int __devinit abituguru3_probe(struct platform_device *pdev)
957 for (i = 0; data->sensors[i].name; i++) { 961 for (i = 0; data->sensors[i].name; i++) {
958 /* Fail safe check, this should never happen! */ 962 /* Fail safe check, this should never happen! */
959 if (i >= ABIT_UGURU3_MAX_NO_SENSORS) { 963 if (i >= ABIT_UGURU3_MAX_NO_SENSORS) {
960 printk(KERN_ERR ABIT_UGURU3_NAME 964 pr_err("Fatal error motherboard has more sensors then ABIT_UGURU3_MAX_NO_SENSORS. %s %s\n",
961 ": Fatal error motherboard has more sensors " 965 never_happen, report_this);
962 "then ABIT_UGURU3_MAX_NO_SENSORS. This should "
963 "never happen please report to the abituguru3 "
964 "maintainer (see MAINTAINERS)\n");
965 res = -ENAMETOOLONG; 966 res = -ENAMETOOLONG;
966 goto abituguru3_probe_error; 967 goto abituguru3_probe_error;
967 } 968 }
@@ -983,10 +984,8 @@ static int __devinit abituguru3_probe(struct platform_device *pdev)
983 } 984 }
984 /* Fail safe check, this should never happen! */ 985 /* Fail safe check, this should never happen! */
985 if (sysfs_names_free < 0) { 986 if (sysfs_names_free < 0) {
986 printk(KERN_ERR ABIT_UGURU3_NAME 987 pr_err("Fatal error ran out of space for sysfs attr names. %s %s\n",
987 ": Fatal error ran out of space for sysfs attr names. " 988 never_happen, report_this);
988 "This should never happen please report to the "
989 "abituguru3 maintainer (see MAINTAINERS)\n");
990 res = -ENAMETOOLONG; 989 res = -ENAMETOOLONG;
991 goto abituguru3_probe_error; 990 goto abituguru3_probe_error;
992 } 991 }
@@ -1189,8 +1188,7 @@ static int __init abituguru3_detect(void)
1189 "0x%02X\n", (unsigned int)data_val, (unsigned int)cmd_val); 1188 "0x%02X\n", (unsigned int)data_val, (unsigned int)cmd_val);
1190 1189
1191 if (force) { 1190 if (force) {
1192 printk(KERN_INFO ABIT_UGURU3_NAME ": Assuming Abit uGuru3 is " 1191 pr_info("Assuming Abit uGuru3 is present because of \"force\" parameter\n");
1193 "present because of \"force\" parameter\n");
1194 return 0; 1192 return 0;
1195 } 1193 }
1196 1194
@@ -1219,10 +1217,8 @@ static int __init abituguru3_init(void)
1219 return err; 1217 return err;
1220 1218
1221#ifdef CONFIG_DMI 1219#ifdef CONFIG_DMI
1222 printk(KERN_WARNING ABIT_UGURU3_NAME ": this motherboard was " 1220 pr_warn("this motherboard was not detected using DMI. "
1223 "not detected using DMI. Please send the output of " 1221 "Please send the output of \"dmidecode\" to the abituguru3 maintainer (see MAINTAINERS)\n");
1224 "\"dmidecode\" to the abituguru3 maintainer "
1225 "(see MAINTAINERS)\n");
1226#endif 1222#endif
1227 } 1223 }
1228 1224
@@ -1233,8 +1229,7 @@ static int __init abituguru3_init(void)
1233 abituguru3_pdev = platform_device_alloc(ABIT_UGURU3_NAME, 1229 abituguru3_pdev = platform_device_alloc(ABIT_UGURU3_NAME,
1234 ABIT_UGURU3_BASE); 1230 ABIT_UGURU3_BASE);
1235 if (!abituguru3_pdev) { 1231 if (!abituguru3_pdev) {
1236 printk(KERN_ERR ABIT_UGURU3_NAME 1232 pr_err("Device allocation failed\n");
1237 ": Device allocation failed\n");
1238 err = -ENOMEM; 1233 err = -ENOMEM;
1239 goto exit_driver_unregister; 1234 goto exit_driver_unregister;
1240 } 1235 }
@@ -1245,15 +1240,13 @@ static int __init abituguru3_init(void)
1245 1240
1246 err = platform_device_add_resources(abituguru3_pdev, &res, 1); 1241 err = platform_device_add_resources(abituguru3_pdev, &res, 1);
1247 if (err) { 1242 if (err) {
1248 printk(KERN_ERR ABIT_UGURU3_NAME 1243 pr_err("Device resource addition failed (%d)\n", err);
1249 ": Device resource addition failed (%d)\n", err);
1250 goto exit_device_put; 1244 goto exit_device_put;
1251 } 1245 }
1252 1246
1253 err = platform_device_add(abituguru3_pdev); 1247 err = platform_device_add(abituguru3_pdev);
1254 if (err) { 1248 if (err) {
1255 printk(KERN_ERR ABIT_UGURU3_NAME 1249 pr_err("Device addition failed (%d)\n", err);
1256 ": Device addition failed (%d)\n", err);
1257 goto exit_device_put; 1250 goto exit_device_put;
1258 } 1251 }
1259 1252
diff --git a/drivers/hwmon/adm9240.c b/drivers/hwmon/adm9240.c
index 0727ad250793..9e234b981b83 100644
--- a/drivers/hwmon/adm9240.c
+++ b/drivers/hwmon/adm9240.c
@@ -20,7 +20,7 @@
20 * Alarms 16-bit map of active alarms 20 * Alarms 16-bit map of active alarms
21 * Analog Out 0..1250 mV output 21 * Analog Out 0..1250 mV output
22 * 22 *
23 * Chassis Intrusion: clear CI latch with 'echo 1 > chassis_clear' 23 * Chassis Intrusion: clear CI latch with 'echo 0 > intrusion0_alarm'
24 * 24 *
25 * Test hardware: Intel SE440BX-2 desktop motherboard --Grant 25 * Test hardware: Intel SE440BX-2 desktop motherboard --Grant
26 * 26 *
@@ -476,13 +476,16 @@ static ssize_t set_aout(struct device *dev,
476static DEVICE_ATTR(aout_output, S_IRUGO | S_IWUSR, show_aout, set_aout); 476static DEVICE_ATTR(aout_output, S_IRUGO | S_IWUSR, show_aout, set_aout);
477 477
478/* chassis_clear */ 478/* chassis_clear */
479static ssize_t chassis_clear(struct device *dev, 479static ssize_t chassis_clear_legacy(struct device *dev,
480 struct device_attribute *attr, 480 struct device_attribute *attr,
481 const char *buf, size_t count) 481 const char *buf, size_t count)
482{ 482{
483 struct i2c_client *client = to_i2c_client(dev); 483 struct i2c_client *client = to_i2c_client(dev);
484 unsigned long val = simple_strtol(buf, NULL, 10); 484 unsigned long val = simple_strtol(buf, NULL, 10);
485 485
486 dev_warn(dev, "Attribute chassis_clear is deprecated, "
487 "use intrusion0_alarm instead\n");
488
486 if (val == 1) { 489 if (val == 1) {
487 i2c_smbus_write_byte_data(client, 490 i2c_smbus_write_byte_data(client,
488 ADM9240_REG_CHASSIS_CLEAR, 0x80); 491 ADM9240_REG_CHASSIS_CLEAR, 0x80);
@@ -490,7 +493,29 @@ static ssize_t chassis_clear(struct device *dev,
490 } 493 }
491 return count; 494 return count;
492} 495}
493static DEVICE_ATTR(chassis_clear, S_IWUSR, NULL, chassis_clear); 496static DEVICE_ATTR(chassis_clear, S_IWUSR, NULL, chassis_clear_legacy);
497
498static ssize_t chassis_clear(struct device *dev,
499 struct device_attribute *attr,
500 const char *buf, size_t count)
501{
502 struct i2c_client *client = to_i2c_client(dev);
503 struct adm9240_data *data = i2c_get_clientdata(client);
504 unsigned long val;
505
506 if (strict_strtoul(buf, 10, &val) || val != 0)
507 return -EINVAL;
508
509 mutex_lock(&data->update_lock);
510 i2c_smbus_write_byte_data(client, ADM9240_REG_CHASSIS_CLEAR, 0x80);
511 data->valid = 0; /* Force cache refresh */
512 mutex_unlock(&data->update_lock);
513 dev_dbg(&client->dev, "chassis intrusion latch cleared\n");
514
515 return count;
516}
517static SENSOR_DEVICE_ATTR(intrusion0_alarm, S_IRUGO | S_IWUSR, show_alarm,
518 chassis_clear, 12);
494 519
495static struct attribute *adm9240_attributes[] = { 520static struct attribute *adm9240_attributes[] = {
496 &sensor_dev_attr_in0_input.dev_attr.attr, 521 &sensor_dev_attr_in0_input.dev_attr.attr,
@@ -532,6 +557,7 @@ static struct attribute *adm9240_attributes[] = {
532 &dev_attr_alarms.attr, 557 &dev_attr_alarms.attr,
533 &dev_attr_aout_output.attr, 558 &dev_attr_aout_output.attr,
534 &dev_attr_chassis_clear.attr, 559 &dev_attr_chassis_clear.attr,
560 &sensor_dev_attr_intrusion0_alarm.dev_attr.attr,
535 &dev_attr_cpu0_vid.attr, 561 &dev_attr_cpu0_vid.attr,
536 NULL 562 NULL
537}; 563};
diff --git a/drivers/hwmon/ads7828.c b/drivers/hwmon/ads7828.c
index aac85f3aed50..c42c5a69a664 100644
--- a/drivers/hwmon/ads7828.c
+++ b/drivers/hwmon/ads7828.c
@@ -4,7 +4,7 @@
4 4
5 This driver is based on the lm75 and other lm_sensors/hwmon drivers 5 This driver is based on the lm75 and other lm_sensors/hwmon drivers
6 6
7 Written by Steve Hardy <steve@linuxrealtime.co.uk> 7 Written by Steve Hardy <shardy@redhat.com>
8 8
9 Datasheet available at: http://focus.ti.com/lit/ds/symlink/ads7828.pdf 9 Datasheet available at: http://focus.ti.com/lit/ds/symlink/ads7828.pdf
10 10
@@ -271,7 +271,7 @@ static void __exit sensors_ads7828_exit(void)
271 i2c_del_driver(&ads7828_driver); 271 i2c_del_driver(&ads7828_driver);
272} 272}
273 273
274MODULE_AUTHOR("Steve Hardy <steve@linuxrealtime.co.uk>"); 274MODULE_AUTHOR("Steve Hardy <shardy@redhat.com>");
275MODULE_DESCRIPTION("ADS7828 driver"); 275MODULE_DESCRIPTION("ADS7828 driver");
276MODULE_LICENSE("GPL"); 276MODULE_LICENSE("GPL");
277 277
diff --git a/drivers/hwmon/adt7470.c b/drivers/hwmon/adt7470.c
index 87d92a56a939..c6d1ce059aea 100644
--- a/drivers/hwmon/adt7470.c
+++ b/drivers/hwmon/adt7470.c
@@ -19,6 +19,8 @@
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */ 20 */
21 21
22#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
23
22#include <linux/module.h> 24#include <linux/module.h>
23#include <linux/jiffies.h> 25#include <linux/jiffies.h>
24#include <linux/i2c.h> 26#include <linux/i2c.h>
@@ -274,7 +276,7 @@ static int adt7470_read_temperatures(struct i2c_client *client,
274 i2c_smbus_write_byte_data(client, ADT7470_REG_PWM_CFG(2), pwm_cfg[1]); 276 i2c_smbus_write_byte_data(client, ADT7470_REG_PWM_CFG(2), pwm_cfg[1]);
275 277
276 if (res) { 278 if (res) {
277 printk(KERN_ERR "ha ha, interrupted"); 279 pr_err("ha ha, interrupted\n");
278 return -EAGAIN; 280 return -EAGAIN;
279 } 281 }
280 282
diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
index b6598aa557a0..ce0372f0615e 100644
--- a/drivers/hwmon/applesmc.c
+++ b/drivers/hwmon/applesmc.c
@@ -4,6 +4,7 @@
4 * computers. 4 * computers.
5 * 5 *
6 * Copyright (C) 2007 Nicolas Boichat <nicolas@boichat.ch> 6 * Copyright (C) 2007 Nicolas Boichat <nicolas@boichat.ch>
7 * Copyright (C) 2010 Henrik Rydberg <rydberg@euromail.se>
7 * 8 *
8 * Based on hdaps.c driver: 9 * Based on hdaps.c driver:
9 * Copyright (C) 2005 Robert Love <rml@novell.com> 10 * Copyright (C) 2005 Robert Love <rml@novell.com>
@@ -26,10 +27,13 @@
26 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 27 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
27 */ 28 */
28 29
30#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
31
29#include <linux/delay.h> 32#include <linux/delay.h>
30#include <linux/platform_device.h> 33#include <linux/platform_device.h>
31#include <linux/input-polldev.h> 34#include <linux/input-polldev.h>
32#include <linux/kernel.h> 35#include <linux/kernel.h>
36#include <linux/slab.h>
33#include <linux/module.h> 37#include <linux/module.h>
34#include <linux/timer.h> 38#include <linux/timer.h>
35#include <linux/dmi.h> 39#include <linux/dmi.h>
@@ -49,6 +53,7 @@
49 53
50#define APPLESMC_MAX_DATA_LENGTH 32 54#define APPLESMC_MAX_DATA_LENGTH 32
51 55
56/* wait up to 32 ms for a status change. */
52#define APPLESMC_MIN_WAIT 0x0040 57#define APPLESMC_MIN_WAIT 0x0040
53#define APPLESMC_MAX_WAIT 0x8000 58#define APPLESMC_MAX_WAIT 0x8000
54 59
@@ -73,104 +78,15 @@
73 78
74#define FANS_COUNT "FNum" /* r-o ui8 */ 79#define FANS_COUNT "FNum" /* r-o ui8 */
75#define FANS_MANUAL "FS! " /* r-w ui16 */ 80#define FANS_MANUAL "FS! " /* r-w ui16 */
76#define FAN_ACTUAL_SPEED "F0Ac" /* r-o fpe2 (2 bytes) */ 81#define FAN_ID_FMT "F%dID" /* r-o char[16] */
77#define FAN_MIN_SPEED "F0Mn" /* r-o fpe2 (2 bytes) */
78#define FAN_MAX_SPEED "F0Mx" /* r-o fpe2 (2 bytes) */
79#define FAN_SAFE_SPEED "F0Sf" /* r-o fpe2 (2 bytes) */
80#define FAN_TARGET_SPEED "F0Tg" /* r-w fpe2 (2 bytes) */
81#define FAN_POSITION "F0ID" /* r-o char[16] */
82
83/*
84 * Temperature sensors keys (sp78 - 2 bytes).
85 */
86static const char *temperature_sensors_sets[][41] = {
87/* Set 0: Macbook Pro */
88 { "TA0P", "TB0T", "TC0D", "TC0P", "TG0H", "TG0P", "TG0T", "Th0H",
89 "Th1H", "Tm0P", "Ts0P", "Ts1P", NULL },
90/* Set 1: Macbook2 set */
91 { "TB0T", "TC0D", "TC0P", "TM0P", "TN0P", "TN1P", "TTF0", "Th0H",
92 "Th0S", "Th1H", NULL },
93/* Set 2: Macbook set */
94 { "TB0T", "TC0D", "TC0P", "TM0P", "TN0P", "TN1P", "Th0H", "Th0S",
95 "Th1H", "Ts0P", NULL },
96/* Set 3: Macmini set */
97 { "TC0D", "TC0P", NULL },
98/* Set 4: Mac Pro (2 x Quad-Core) */
99 { "TA0P", "TCAG", "TCAH", "TCBG", "TCBH", "TC0C", "TC0D", "TC0P",
100 "TC1C", "TC1D", "TC2C", "TC2D", "TC3C", "TC3D", "THTG", "TH0P",
101 "TH1P", "TH2P", "TH3P", "TMAP", "TMAS", "TMBS", "TM0P", "TM0S",
102 "TM1P", "TM1S", "TM2P", "TM2S", "TM3S", "TM8P", "TM8S", "TM9P",
103 "TM9S", "TN0H", "TS0C", NULL },
104/* Set 5: iMac */
105 { "TC0D", "TA0P", "TG0P", "TG0D", "TG0H", "TH0P", "Tm0P", "TO0P",
106 "Tp0C", NULL },
107/* Set 6: Macbook3 set */
108 { "TB0T", "TC0D", "TC0P", "TM0P", "TN0P", "TTF0", "TW0P", "Th0H",
109 "Th0S", "Th1H", NULL },
110/* Set 7: Macbook Air */
111 { "TB0T", "TB1S", "TB1T", "TB2S", "TB2T", "TC0D", "TC0P", "TCFP",
112 "TTF0", "TW0P", "Th0H", "Tp0P", "TpFP", "Ts0P", "Ts0S", NULL },
113/* Set 8: Macbook Pro 4,1 (Penryn) */
114 { "TB0T", "TC0D", "TC0P", "TG0D", "TG0H", "TTF0", "TW0P", "Th0H",
115 "Th1H", "Th2H", "Tm0P", "Ts0P", NULL },
116/* Set 9: Macbook Pro 3,1 (Santa Rosa) */
117 { "TALP", "TB0T", "TC0D", "TC0P", "TG0D", "TG0H", "TTF0", "TW0P",
118 "Th0H", "Th1H", "Th2H", "Tm0P", "Ts0P", NULL },
119/* Set 10: iMac 5,1 */
120 { "TA0P", "TC0D", "TC0P", "TG0D", "TH0P", "TO0P", "Tm0P", NULL },
121/* Set 11: Macbook 5,1 */
122 { "TB0T", "TB1T", "TB2T", "TB3T", "TC0D", "TC0P", "TN0D", "TN0P",
123 "TTF0", "Th0H", "Th1H", "ThFH", "Ts0P", "Ts0S", NULL },
124/* Set 12: Macbook Pro 5,1 */
125 { "TB0T", "TB1T", "TB2T", "TB3T", "TC0D", "TC0F", "TC0P", "TG0D",
126 "TG0F", "TG0H", "TG0P", "TG0T", "TG1H", "TN0D", "TN0P", "TTF0",
127 "Th2H", "Tm0P", "Ts0P", "Ts0S", NULL },
128/* Set 13: iMac 8,1 */
129 { "TA0P", "TC0D", "TC0H", "TC0P", "TG0D", "TG0H", "TG0P", "TH0P",
130 "TL0P", "TO0P", "TW0P", "Tm0P", "Tp0P", NULL },
131/* Set 14: iMac 6,1 */
132 { "TA0P", "TC0D", "TC0H", "TC0P", "TG0D", "TG0H", "TG0P", "TH0P",
133 "TO0P", "Tp0P", NULL },
134/* Set 15: MacBook Air 2,1 */
135 { "TB0T", "TB1S", "TB1T", "TB2S", "TB2T", "TC0D", "TN0D", "TTF0",
136 "TV0P", "TVFP", "TW0P", "Th0P", "Tp0P", "Tp1P", "TpFP", "Ts0P",
137 "Ts0S", NULL },
138/* Set 16: Mac Pro 3,1 (2 x Quad-Core) */
139 { "TA0P", "TCAG", "TCAH", "TCBG", "TCBH", "TC0C", "TC0D", "TC0P",
140 "TC1C", "TC1D", "TC2C", "TC2D", "TC3C", "TC3D", "TH0P", "TH1P",
141 "TH2P", "TH3P", "TMAP", "TMAS", "TMBS", "TM0P", "TM0S", "TM1P",
142 "TM1S", "TM2P", "TM2S", "TM3S", "TM8P", "TM8S", "TM9P", "TM9S",
143 "TN0C", "TN0D", "TN0H", "TS0C", "Tp0C", "Tp1C", "Tv0S", "Tv1S",
144 NULL },
145/* Set 17: iMac 9,1 */
146 { "TA0P", "TC0D", "TC0H", "TC0P", "TG0D", "TG0H", "TH0P", "TL0P",
147 "TN0D", "TN0H", "TN0P", "TO0P", "Tm0P", "Tp0P", NULL },
148/* Set 18: MacBook Pro 2,2 */
149 { "TB0T", "TC0D", "TC0P", "TG0H", "TG0P", "TG0T", "TM0P", "TTF0",
150 "Th0H", "Th1H", "Tm0P", "Ts0P", NULL },
151/* Set 19: Macbook Pro 5,3 */
152 { "TB0T", "TB1T", "TB2T", "TB3T", "TC0D", "TC0F", "TC0P", "TG0D",
153 "TG0F", "TG0H", "TG0P", "TG0T", "TN0D", "TN0P", "TTF0", "Th2H",
154 "Tm0P", "Ts0P", "Ts0S", NULL },
155/* Set 20: MacBook Pro 5,4 */
156 { "TB0T", "TB1T", "TB2T", "TB3T", "TC0D", "TC0F", "TC0P", "TN0D",
157 "TN0P", "TTF0", "Th2H", "Ts0P", "Ts0S", NULL },
158/* Set 21: MacBook Pro 6,2 */
159 { "TB0T", "TB1T", "TB2T", "TC0C", "TC0D", "TC0P", "TC1C", "TG0D",
160 "TG0P", "TG0T", "TMCD", "TP0P", "TPCD", "Th1H", "Th2H", "Tm0P",
161 "Ts0P", "Ts0S", NULL },
162/* Set 22: MacBook Pro 7,1 */
163 { "TB0T", "TB1T", "TB2T", "TC0D", "TC0P", "TN0D", "TN0P", "TN0S",
164 "TN1D", "TN1F", "TN1G", "TN1S", "Th1H", "Ts0P", "Ts0S", NULL },
165};
166 82
167/* List of keys used to read/write fan speeds */ 83/* List of keys used to read/write fan speeds */
168static const char* fan_speed_keys[] = { 84static const char *const fan_speed_fmt[] = {
169 FAN_ACTUAL_SPEED, 85 "F%dAc", /* actual speed */
170 FAN_MIN_SPEED, 86 "F%dMn", /* minimum speed (rw) */
171 FAN_MAX_SPEED, 87 "F%dMx", /* maximum speed */
172 FAN_SAFE_SPEED, 88 "F%dSf", /* safe speed - not all models */
173 FAN_TARGET_SPEED 89 "F%dTg", /* target speed (manual: rw) */
174}; 90};
175 91
176#define INIT_TIMEOUT_MSECS 5000 /* wait up to 5s for device init ... */ 92#define INIT_TIMEOUT_MSECS 5000 /* wait up to 5s for device init ... */
@@ -184,14 +100,48 @@ static const char* fan_speed_keys[] = {
184#define SENSOR_Y 1 100#define SENSOR_Y 1
185#define SENSOR_Z 2 101#define SENSOR_Z 2
186 102
187/* Structure to be passed to DMI_MATCH function */ 103#define to_index(attr) (to_sensor_dev_attr(attr)->index & 0xffff)
188struct dmi_match_data { 104#define to_option(attr) (to_sensor_dev_attr(attr)->index >> 16)
189/* Indicates whether this computer has an accelerometer. */ 105
190 int accelerometer; 106/* Dynamic device node attributes */
191/* Indicates whether this computer has light sensors and keyboard backlight. */ 107struct applesmc_dev_attr {
192 int light; 108 struct sensor_device_attribute sda; /* hwmon attributes */
193/* Indicates which temperature sensors set to use. */ 109 char name[32]; /* room for node file name */
194 int temperature_set; 110};
111
112/* Dynamic device node group */
113struct applesmc_node_group {
114 char *format; /* format string */
115 void *show; /* show function */
116 void *store; /* store function */
117 int option; /* function argument */
118 struct applesmc_dev_attr *nodes; /* dynamic node array */
119};
120
121/* AppleSMC entry - cached register information */
122struct applesmc_entry {
123 char key[5]; /* four-letter key code */
124 u8 valid; /* set when entry is successfully read once */
125 u8 len; /* bounded by APPLESMC_MAX_DATA_LENGTH */
126 char type[5]; /* four-letter type code */
127 u8 flags; /* 0x10: func; 0x40: write; 0x80: read */
128};
129
130/* Register lookup and registers common to all SMCs */
131static struct applesmc_registers {
132 struct mutex mutex; /* register read/write mutex */
133 unsigned int key_count; /* number of SMC registers */
134 unsigned int fan_count; /* number of fans */
135 unsigned int temp_count; /* number of temperature registers */
136 unsigned int temp_begin; /* temperature lower index bound */
137 unsigned int temp_end; /* temperature upper index bound */
138 int num_light_sensors; /* number of light sensors */
139 bool has_accelerometer; /* has motion sensor */
140 bool has_key_backlight; /* has keyboard backlight */
141 bool init_complete; /* true when fully initialized */
142 struct applesmc_entry *cache; /* cached key entries */
143} smcreg = {
144 .mutex = __MUTEX_INITIALIZER(smcreg.mutex),
195}; 145};
196 146
197static const int debug; 147static const int debug;
@@ -203,20 +153,6 @@ static u8 backlight_state[2];
203static struct device *hwmon_dev; 153static struct device *hwmon_dev;
204static struct input_polled_dev *applesmc_idev; 154static struct input_polled_dev *applesmc_idev;
205 155
206/* Indicates whether this computer has an accelerometer. */
207static unsigned int applesmc_accelerometer;
208
209/* Indicates whether this computer has light sensors and keyboard backlight. */
210static unsigned int applesmc_light;
211
212/* The number of fans handled by the driver */
213static unsigned int fans_handled;
214
215/* Indicates which temperature sensors set to use. */
216static unsigned int applesmc_temperature_set;
217
218static DEFINE_MUTEX(applesmc_lock);
219
220/* 156/*
221 * Last index written to key_at_index sysfs file, and value to use for all other 157 * Last index written to key_at_index sysfs file, and value to use for all other
222 * key_at_index_* sysfs files. 158 * key_at_index_* sysfs files.
@@ -238,18 +174,10 @@ static int __wait_status(u8 val)
238 174
239 for (us = APPLESMC_MIN_WAIT; us < APPLESMC_MAX_WAIT; us <<= 1) { 175 for (us = APPLESMC_MIN_WAIT; us < APPLESMC_MAX_WAIT; us <<= 1) {
240 udelay(us); 176 udelay(us);
241 if ((inb(APPLESMC_CMD_PORT) & APPLESMC_STATUS_MASK) == val) { 177 if ((inb(APPLESMC_CMD_PORT) & APPLESMC_STATUS_MASK) == val)
242 if (debug)
243 printk(KERN_DEBUG
244 "Waited %d us for status %x\n",
245 2 * us - APPLESMC_MIN_WAIT, val);
246 return 0; 178 return 0;
247 }
248 } 179 }
249 180
250 printk(KERN_WARNING "applesmc: wait status failed: %x != %x\n",
251 val, inb(APPLESMC_CMD_PORT));
252
253 return -EIO; 181 return -EIO;
254} 182}
255 183
@@ -267,159 +195,242 @@ static int send_command(u8 cmd)
267 if ((inb(APPLESMC_CMD_PORT) & APPLESMC_STATUS_MASK) == 0x0c) 195 if ((inb(APPLESMC_CMD_PORT) & APPLESMC_STATUS_MASK) == 0x0c)
268 return 0; 196 return 0;
269 } 197 }
270 printk(KERN_WARNING "applesmc: command failed: %x -> %x\n",
271 cmd, inb(APPLESMC_CMD_PORT));
272 return -EIO; 198 return -EIO;
273} 199}
274 200
275/* 201static int send_argument(const char *key)
276 * applesmc_read_key - reads len bytes from a given key, and put them in buffer.
277 * Returns zero on success or a negative error on failure. Callers must
278 * hold applesmc_lock.
279 */
280static int applesmc_read_key(const char* key, u8* buffer, u8 len)
281{ 202{
282 int i; 203 int i;
283 204
284 if (len > APPLESMC_MAX_DATA_LENGTH) {
285 printk(KERN_ERR "applesmc_read_key: cannot read more than "
286 "%d bytes\n", APPLESMC_MAX_DATA_LENGTH);
287 return -EINVAL;
288 }
289
290 if (send_command(APPLESMC_READ_CMD))
291 return -EIO;
292
293 for (i = 0; i < 4; i++) { 205 for (i = 0; i < 4; i++) {
294 outb(key[i], APPLESMC_DATA_PORT); 206 outb(key[i], APPLESMC_DATA_PORT);
295 if (__wait_status(0x04)) 207 if (__wait_status(0x04))
296 return -EIO; 208 return -EIO;
297 } 209 }
298 if (debug) 210 return 0;
299 printk(KERN_DEBUG "<%s", key); 211}
212
213static int read_smc(u8 cmd, const char *key, u8 *buffer, u8 len)
214{
215 int i;
216
217 if (send_command(cmd) || send_argument(key)) {
218 pr_warn("%s: read arg fail\n", key);
219 return -EIO;
220 }
300 221
301 outb(len, APPLESMC_DATA_PORT); 222 outb(len, APPLESMC_DATA_PORT);
302 if (debug)
303 printk(KERN_DEBUG ">%x", len);
304 223
305 for (i = 0; i < len; i++) { 224 for (i = 0; i < len; i++) {
306 if (__wait_status(0x05)) 225 if (__wait_status(0x05)) {
226 pr_warn("%s: read data fail\n", key);
307 return -EIO; 227 return -EIO;
228 }
308 buffer[i] = inb(APPLESMC_DATA_PORT); 229 buffer[i] = inb(APPLESMC_DATA_PORT);
309 if (debug)
310 printk(KERN_DEBUG "<%x", buffer[i]);
311 } 230 }
312 if (debug)
313 printk(KERN_DEBUG "\n");
314 231
315 return 0; 232 return 0;
316} 233}
317 234
318/* 235static int write_smc(u8 cmd, const char *key, const u8 *buffer, u8 len)
319 * applesmc_write_key - writes len bytes from buffer to a given key.
320 * Returns zero on success or a negative error on failure. Callers must
321 * hold applesmc_lock.
322 */
323static int applesmc_write_key(const char* key, u8* buffer, u8 len)
324{ 236{
325 int i; 237 int i;
326 238
327 if (len > APPLESMC_MAX_DATA_LENGTH) { 239 if (send_command(cmd) || send_argument(key)) {
328 printk(KERN_ERR "applesmc_write_key: cannot write more than " 240 pr_warn("%s: write arg fail\n", key);
329 "%d bytes\n", APPLESMC_MAX_DATA_LENGTH);
330 return -EINVAL;
331 }
332
333 if (send_command(APPLESMC_WRITE_CMD))
334 return -EIO; 241 return -EIO;
335
336 for (i = 0; i < 4; i++) {
337 outb(key[i], APPLESMC_DATA_PORT);
338 if (__wait_status(0x04))
339 return -EIO;
340 } 242 }
341 243
342 outb(len, APPLESMC_DATA_PORT); 244 outb(len, APPLESMC_DATA_PORT);
343 245
344 for (i = 0; i < len; i++) { 246 for (i = 0; i < len; i++) {
345 if (__wait_status(0x04)) 247 if (__wait_status(0x04)) {
248 pr_warn("%s: write data fail\n", key);
346 return -EIO; 249 return -EIO;
250 }
347 outb(buffer[i], APPLESMC_DATA_PORT); 251 outb(buffer[i], APPLESMC_DATA_PORT);
348 } 252 }
349 253
350 return 0; 254 return 0;
351} 255}
352 256
257static int read_register_count(unsigned int *count)
258{
259 __be32 be;
260 int ret;
261
262 ret = read_smc(APPLESMC_READ_CMD, KEY_COUNT_KEY, (u8 *)&be, 4);
263 if (ret)
264 return ret;
265
266 *count = be32_to_cpu(be);
267 return 0;
268}
269
353/* 270/*
354 * applesmc_get_key_at_index - get key at index, and put the result in key 271 * Serialized I/O
355 * (char[6]). Returns zero on success or a negative error on failure. Callers 272 *
356 * must hold applesmc_lock. 273 * Returns zero on success or a negative error on failure.
274 * All functions below are concurrency safe - callers should NOT hold lock.
357 */ 275 */
358static int applesmc_get_key_at_index(int index, char* key) 276
277static int applesmc_read_entry(const struct applesmc_entry *entry,
278 u8 *buf, u8 len)
359{ 279{
360 int i; 280 int ret;
361 u8 readkey[4];
362 readkey[0] = index >> 24;
363 readkey[1] = index >> 16;
364 readkey[2] = index >> 8;
365 readkey[3] = index;
366 281
367 if (send_command(APPLESMC_GET_KEY_BY_INDEX_CMD)) 282 if (entry->len != len)
368 return -EIO; 283 return -EINVAL;
284 mutex_lock(&smcreg.mutex);
285 ret = read_smc(APPLESMC_READ_CMD, entry->key, buf, len);
286 mutex_unlock(&smcreg.mutex);
369 287
370 for (i = 0; i < 4; i++) { 288 return ret;
371 outb(readkey[i], APPLESMC_DATA_PORT); 289}
372 if (__wait_status(0x04)) 290
373 return -EIO; 291static int applesmc_write_entry(const struct applesmc_entry *entry,
292 const u8 *buf, u8 len)
293{
294 int ret;
295
296 if (entry->len != len)
297 return -EINVAL;
298 mutex_lock(&smcreg.mutex);
299 ret = write_smc(APPLESMC_WRITE_CMD, entry->key, buf, len);
300 mutex_unlock(&smcreg.mutex);
301 return ret;
302}
303
304static const struct applesmc_entry *applesmc_get_entry_by_index(int index)
305{
306 struct applesmc_entry *cache = &smcreg.cache[index];
307 u8 key[4], info[6];
308 __be32 be;
309 int ret = 0;
310
311 if (cache->valid)
312 return cache;
313
314 mutex_lock(&smcreg.mutex);
315
316 if (cache->valid)
317 goto out;
318 be = cpu_to_be32(index);
319 ret = read_smc(APPLESMC_GET_KEY_BY_INDEX_CMD, (u8 *)&be, key, 4);
320 if (ret)
321 goto out;
322 ret = read_smc(APPLESMC_GET_KEY_TYPE_CMD, key, info, 6);
323 if (ret)
324 goto out;
325
326 memcpy(cache->key, key, 4);
327 cache->len = info[0];
328 memcpy(cache->type, &info[1], 4);
329 cache->flags = info[5];
330 cache->valid = 1;
331
332out:
333 mutex_unlock(&smcreg.mutex);
334 if (ret)
335 return ERR_PTR(ret);
336 return cache;
337}
338
339static int applesmc_get_lower_bound(unsigned int *lo, const char *key)
340{
341 int begin = 0, end = smcreg.key_count;
342 const struct applesmc_entry *entry;
343
344 while (begin != end) {
345 int middle = begin + (end - begin) / 2;
346 entry = applesmc_get_entry_by_index(middle);
347 if (IS_ERR(entry))
348 return PTR_ERR(entry);
349 if (strcmp(entry->key, key) < 0)
350 begin = middle + 1;
351 else
352 end = middle;
374 } 353 }
375 354
376 outb(4, APPLESMC_DATA_PORT); 355 *lo = begin;
356 return 0;
357}
377 358
378 for (i = 0; i < 4; i++) { 359static int applesmc_get_upper_bound(unsigned int *hi, const char *key)
379 if (__wait_status(0x05)) 360{
380 return -EIO; 361 int begin = 0, end = smcreg.key_count;
381 key[i] = inb(APPLESMC_DATA_PORT); 362 const struct applesmc_entry *entry;
363
364 while (begin != end) {
365 int middle = begin + (end - begin) / 2;
366 entry = applesmc_get_entry_by_index(middle);
367 if (IS_ERR(entry))
368 return PTR_ERR(entry);
369 if (strcmp(key, entry->key) < 0)
370 end = middle;
371 else
372 begin = middle + 1;
382 } 373 }
383 key[4] = 0;
384 374
375 *hi = begin;
385 return 0; 376 return 0;
386} 377}
387 378
388/* 379static const struct applesmc_entry *applesmc_get_entry_by_key(const char *key)
389 * applesmc_get_key_type - get key type, and put the result in type (char[6]).
390 * Returns zero on success or a negative error on failure. Callers must
391 * hold applesmc_lock.
392 */
393static int applesmc_get_key_type(char* key, char* type)
394{ 380{
395 int i; 381 int begin, end;
382 int ret;
396 383
397 if (send_command(APPLESMC_GET_KEY_TYPE_CMD)) 384 ret = applesmc_get_lower_bound(&begin, key);
398 return -EIO; 385 if (ret)
386 return ERR_PTR(ret);
387 ret = applesmc_get_upper_bound(&end, key);
388 if (ret)
389 return ERR_PTR(ret);
390 if (end - begin != 1)
391 return ERR_PTR(-EINVAL);
399 392
400 for (i = 0; i < 4; i++) { 393 return applesmc_get_entry_by_index(begin);
401 outb(key[i], APPLESMC_DATA_PORT); 394}
402 if (__wait_status(0x04))
403 return -EIO;
404 }
405 395
406 outb(6, APPLESMC_DATA_PORT); 396static int applesmc_read_key(const char *key, u8 *buffer, u8 len)
397{
398 const struct applesmc_entry *entry;
407 399
408 for (i = 0; i < 6; i++) { 400 entry = applesmc_get_entry_by_key(key);
409 if (__wait_status(0x05)) 401 if (IS_ERR(entry))
410 return -EIO; 402 return PTR_ERR(entry);
411 type[i] = inb(APPLESMC_DATA_PORT); 403
412 } 404 return applesmc_read_entry(entry, buffer, len);
413 type[5] = 0; 405}
406
407static int applesmc_write_key(const char *key, const u8 *buffer, u8 len)
408{
409 const struct applesmc_entry *entry;
414 410
411 entry = applesmc_get_entry_by_key(key);
412 if (IS_ERR(entry))
413 return PTR_ERR(entry);
414
415 return applesmc_write_entry(entry, buffer, len);
416}
417
418static int applesmc_has_key(const char *key, bool *value)
419{
420 const struct applesmc_entry *entry;
421
422 entry = applesmc_get_entry_by_key(key);
423 if (IS_ERR(entry) && PTR_ERR(entry) != -EINVAL)
424 return PTR_ERR(entry);
425
426 *value = !IS_ERR(entry);
415 return 0; 427 return 0;
416} 428}
417 429
418/* 430/*
419 * applesmc_read_motion_sensor - Read motion sensor (X, Y or Z). Callers must 431 * applesmc_read_motion_sensor - Read motion sensor (X, Y or Z).
420 * hold applesmc_lock.
421 */ 432 */
422static int applesmc_read_motion_sensor(int index, s16* value) 433static int applesmc_read_motion_sensor(int index, s16 *value)
423{ 434{
424 u8 buffer[2]; 435 u8 buffer[2];
425 int ret; 436 int ret;
@@ -444,69 +455,120 @@ static int applesmc_read_motion_sensor(int index, s16* value)
444} 455}
445 456
446/* 457/*
447 * applesmc_device_init - initialize the accelerometer. Returns zero on success 458 * applesmc_device_init - initialize the accelerometer. Can sleep.
448 * and negative error code on failure. Can sleep.
449 */ 459 */
450static int applesmc_device_init(void) 460static void applesmc_device_init(void)
451{ 461{
452 int total, ret = -ENXIO; 462 int total;
453 u8 buffer[2]; 463 u8 buffer[2];
454 464
455 if (!applesmc_accelerometer) 465 if (!smcreg.has_accelerometer)
456 return 0; 466 return;
457
458 mutex_lock(&applesmc_lock);
459 467
460 for (total = INIT_TIMEOUT_MSECS; total > 0; total -= INIT_WAIT_MSECS) { 468 for (total = INIT_TIMEOUT_MSECS; total > 0; total -= INIT_WAIT_MSECS) {
461 if (debug)
462 printk(KERN_DEBUG "applesmc try %d\n", total);
463 if (!applesmc_read_key(MOTION_SENSOR_KEY, buffer, 2) && 469 if (!applesmc_read_key(MOTION_SENSOR_KEY, buffer, 2) &&
464 (buffer[0] != 0x00 || buffer[1] != 0x00)) { 470 (buffer[0] != 0x00 || buffer[1] != 0x00))
465 if (total == INIT_TIMEOUT_MSECS) { 471 return;
466 printk(KERN_DEBUG "applesmc: device has"
467 " already been initialized"
468 " (0x%02x, 0x%02x).\n",
469 buffer[0], buffer[1]);
470 } else {
471 printk(KERN_DEBUG "applesmc: device"
472 " successfully initialized"
473 " (0x%02x, 0x%02x).\n",
474 buffer[0], buffer[1]);
475 }
476 ret = 0;
477 goto out;
478 }
479 buffer[0] = 0xe0; 472 buffer[0] = 0xe0;
480 buffer[1] = 0x00; 473 buffer[1] = 0x00;
481 applesmc_write_key(MOTION_SENSOR_KEY, buffer, 2); 474 applesmc_write_key(MOTION_SENSOR_KEY, buffer, 2);
482 msleep(INIT_WAIT_MSECS); 475 msleep(INIT_WAIT_MSECS);
483 } 476 }
484 477
485 printk(KERN_WARNING "applesmc: failed to init the device\n"); 478 pr_warn("failed to init the device\n");
486
487out:
488 mutex_unlock(&applesmc_lock);
489 return ret;
490} 479}
491 480
492/* 481/*
493 * applesmc_get_fan_count - get the number of fans. Callers must NOT hold 482 * applesmc_init_smcreg_try - Try to initialize register cache. Idempotent.
494 * applesmc_lock.
495 */ 483 */
496static int applesmc_get_fan_count(void) 484static int applesmc_init_smcreg_try(void)
497{ 485{
486 struct applesmc_registers *s = &smcreg;
487 bool left_light_sensor, right_light_sensor;
488 u8 tmp[1];
498 int ret; 489 int ret;
499 u8 buffer[1];
500 490
501 mutex_lock(&applesmc_lock); 491 if (s->init_complete)
492 return 0;
502 493
503 ret = applesmc_read_key(FANS_COUNT, buffer, 1); 494 ret = read_register_count(&s->key_count);
495 if (ret)
496 return ret;
497
498 if (!s->cache)
499 s->cache = kcalloc(s->key_count, sizeof(*s->cache), GFP_KERNEL);
500 if (!s->cache)
501 return -ENOMEM;
504 502
505 mutex_unlock(&applesmc_lock); 503 ret = applesmc_read_key(FANS_COUNT, tmp, 1);
506 if (ret) 504 if (ret)
507 return ret; 505 return ret;
508 else 506 s->fan_count = tmp[0];
509 return buffer[0]; 507
508 ret = applesmc_get_lower_bound(&s->temp_begin, "T");
509 if (ret)
510 return ret;
511 ret = applesmc_get_lower_bound(&s->temp_end, "U");
512 if (ret)
513 return ret;
514 s->temp_count = s->temp_end - s->temp_begin;
515
516 ret = applesmc_has_key(LIGHT_SENSOR_LEFT_KEY, &left_light_sensor);
517 if (ret)
518 return ret;
519 ret = applesmc_has_key(LIGHT_SENSOR_RIGHT_KEY, &right_light_sensor);
520 if (ret)
521 return ret;
522 ret = applesmc_has_key(MOTION_SENSOR_KEY, &s->has_accelerometer);
523 if (ret)
524 return ret;
525 ret = applesmc_has_key(BACKLIGHT_KEY, &s->has_key_backlight);
526 if (ret)
527 return ret;
528
529 s->num_light_sensors = left_light_sensor + right_light_sensor;
530 s->init_complete = true;
531
532 pr_info("key=%d fan=%d temp=%d acc=%d lux=%d kbd=%d\n",
533 s->key_count, s->fan_count, s->temp_count,
534 s->has_accelerometer,
535 s->num_light_sensors,
536 s->has_key_backlight);
537
538 return 0;
539}
540
541/*
542 * applesmc_init_smcreg - Initialize register cache.
543 *
544 * Retries until initialization is successful, or the operation times out.
545 *
546 */
547static int applesmc_init_smcreg(void)
548{
549 int ms, ret;
550
551 for (ms = 0; ms < INIT_TIMEOUT_MSECS; ms += INIT_WAIT_MSECS) {
552 ret = applesmc_init_smcreg_try();
553 if (!ret) {
554 if (ms)
555 pr_info("init_smcreg() took %d ms\n", ms);
556 return 0;
557 }
558 msleep(INIT_WAIT_MSECS);
559 }
560
561 kfree(smcreg.cache);
562 smcreg.cache = NULL;
563
564 return ret;
565}
566
567static void applesmc_destroy_smcreg(void)
568{
569 kfree(smcreg.cache);
570 smcreg.cache = NULL;
571 smcreg.init_complete = false;
510} 572}
511 573
512/* Device model stuff */ 574/* Device model stuff */
@@ -514,30 +576,27 @@ static int applesmc_probe(struct platform_device *dev)
514{ 576{
515 int ret; 577 int ret;
516 578
517 ret = applesmc_device_init(); 579 ret = applesmc_init_smcreg();
518 if (ret) 580 if (ret)
519 return ret; 581 return ret;
520 582
521 printk(KERN_INFO "applesmc: device successfully initialized.\n"); 583 applesmc_device_init();
584
522 return 0; 585 return 0;
523} 586}
524 587
525/* Synchronize device with memorized backlight state */ 588/* Synchronize device with memorized backlight state */
526static int applesmc_pm_resume(struct device *dev) 589static int applesmc_pm_resume(struct device *dev)
527{ 590{
528 mutex_lock(&applesmc_lock); 591 if (smcreg.has_key_backlight)
529 if (applesmc_light)
530 applesmc_write_key(BACKLIGHT_KEY, backlight_state, 2); 592 applesmc_write_key(BACKLIGHT_KEY, backlight_state, 2);
531 mutex_unlock(&applesmc_lock);
532 return 0; 593 return 0;
533} 594}
534 595
535/* Reinitialize device on resume from hibernation */ 596/* Reinitialize device on resume from hibernation */
536static int applesmc_pm_restore(struct device *dev) 597static int applesmc_pm_restore(struct device *dev)
537{ 598{
538 int ret = applesmc_device_init(); 599 applesmc_device_init();
539 if (ret)
540 return ret;
541 return applesmc_pm_resume(dev); 600 return applesmc_pm_resume(dev);
542} 601}
543 602
@@ -571,20 +630,15 @@ static void applesmc_idev_poll(struct input_polled_dev *dev)
571 struct input_dev *idev = dev->input; 630 struct input_dev *idev = dev->input;
572 s16 x, y; 631 s16 x, y;
573 632
574 mutex_lock(&applesmc_lock);
575
576 if (applesmc_read_motion_sensor(SENSOR_X, &x)) 633 if (applesmc_read_motion_sensor(SENSOR_X, &x))
577 goto out; 634 return;
578 if (applesmc_read_motion_sensor(SENSOR_Y, &y)) 635 if (applesmc_read_motion_sensor(SENSOR_Y, &y))
579 goto out; 636 return;
580 637
581 x = -x; 638 x = -x;
582 input_report_abs(idev, ABS_X, x - rest_x); 639 input_report_abs(idev, ABS_X, x - rest_x);
583 input_report_abs(idev, ABS_Y, y - rest_y); 640 input_report_abs(idev, ABS_Y, y - rest_y);
584 input_sync(idev); 641 input_sync(idev);
585
586out:
587 mutex_unlock(&applesmc_lock);
588} 642}
589 643
590/* Sysfs Files */ 644/* Sysfs Files */
@@ -601,8 +655,6 @@ static ssize_t applesmc_position_show(struct device *dev,
601 int ret; 655 int ret;
602 s16 x, y, z; 656 s16 x, y, z;
603 657
604 mutex_lock(&applesmc_lock);
605
606 ret = applesmc_read_motion_sensor(SENSOR_X, &x); 658 ret = applesmc_read_motion_sensor(SENSOR_X, &x);
607 if (ret) 659 if (ret)
608 goto out; 660 goto out;
@@ -614,7 +666,6 @@ static ssize_t applesmc_position_show(struct device *dev,
614 goto out; 666 goto out;
615 667
616out: 668out:
617 mutex_unlock(&applesmc_lock);
618 if (ret) 669 if (ret)
619 return ret; 670 return ret;
620 else 671 else
@@ -624,20 +675,20 @@ out:
624static ssize_t applesmc_light_show(struct device *dev, 675static ssize_t applesmc_light_show(struct device *dev,
625 struct device_attribute *attr, char *sysfsbuf) 676 struct device_attribute *attr, char *sysfsbuf)
626{ 677{
678 const struct applesmc_entry *entry;
627 static int data_length; 679 static int data_length;
628 int ret; 680 int ret;
629 u8 left = 0, right = 0; 681 u8 left = 0, right = 0;
630 u8 buffer[10], query[6]; 682 u8 buffer[10];
631
632 mutex_lock(&applesmc_lock);
633 683
634 if (!data_length) { 684 if (!data_length) {
635 ret = applesmc_get_key_type(LIGHT_SENSOR_LEFT_KEY, query); 685 entry = applesmc_get_entry_by_key(LIGHT_SENSOR_LEFT_KEY);
636 if (ret) 686 if (IS_ERR(entry))
637 goto out; 687 return PTR_ERR(entry);
638 data_length = clamp_val(query[0], 0, 10); 688 if (entry->len > 10)
639 printk(KERN_INFO "applesmc: light sensor data length set to " 689 return -ENXIO;
640 "%d\n", data_length); 690 data_length = entry->len;
691 pr_info("light sensor data length set to %d\n", data_length);
641 } 692 }
642 693
643 ret = applesmc_read_key(LIGHT_SENSOR_LEFT_KEY, buffer, data_length); 694 ret = applesmc_read_key(LIGHT_SENSOR_LEFT_KEY, buffer, data_length);
@@ -653,7 +704,6 @@ static ssize_t applesmc_light_show(struct device *dev,
653 right = buffer[2]; 704 right = buffer[2];
654 705
655out: 706out:
656 mutex_unlock(&applesmc_lock);
657 if (ret) 707 if (ret)
658 return ret; 708 return ret;
659 else 709 else
@@ -664,36 +714,44 @@ out:
664static ssize_t applesmc_show_sensor_label(struct device *dev, 714static ssize_t applesmc_show_sensor_label(struct device *dev,
665 struct device_attribute *devattr, char *sysfsbuf) 715 struct device_attribute *devattr, char *sysfsbuf)
666{ 716{
667 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 717 int index = smcreg.temp_begin + to_index(devattr);
668 const char *key = 718 const struct applesmc_entry *entry;
669 temperature_sensors_sets[applesmc_temperature_set][attr->index]; 719
720 entry = applesmc_get_entry_by_index(index);
721 if (IS_ERR(entry))
722 return PTR_ERR(entry);
670 723
671 return snprintf(sysfsbuf, PAGE_SIZE, "%s\n", key); 724 return snprintf(sysfsbuf, PAGE_SIZE, "%s\n", entry->key);
672} 725}
673 726
674/* Displays degree Celsius * 1000 */ 727/* Displays degree Celsius * 1000 */
675static ssize_t applesmc_show_temperature(struct device *dev, 728static ssize_t applesmc_show_temperature(struct device *dev,
676 struct device_attribute *devattr, char *sysfsbuf) 729 struct device_attribute *devattr, char *sysfsbuf)
677{ 730{
731 int index = smcreg.temp_begin + to_index(devattr);
732 const struct applesmc_entry *entry;
678 int ret; 733 int ret;
679 u8 buffer[2]; 734 u8 buffer[2];
680 unsigned int temp; 735 unsigned int temp;
681 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
682 const char* key =
683 temperature_sensors_sets[applesmc_temperature_set][attr->index];
684
685 mutex_lock(&applesmc_lock);
686 736
687 ret = applesmc_read_key(key, buffer, 2); 737 entry = applesmc_get_entry_by_index(index);
688 temp = buffer[0]*1000; 738 if (IS_ERR(entry))
689 temp += (buffer[1] >> 6) * 250; 739 return PTR_ERR(entry);
690 740 if (entry->len > 2)
691 mutex_unlock(&applesmc_lock); 741 return -EINVAL;
692 742
743 ret = applesmc_read_entry(entry, buffer, entry->len);
693 if (ret) 744 if (ret)
694 return ret; 745 return ret;
695 else 746
696 return snprintf(sysfsbuf, PAGE_SIZE, "%u\n", temp); 747 if (entry->len == 2) {
748 temp = buffer[0] * 1000;
749 temp += (buffer[1] >> 6) * 250;
750 } else {
751 temp = buffer[0] * 4000;
752 }
753
754 return snprintf(sysfsbuf, PAGE_SIZE, "%u\n", temp);
697} 755}
698 756
699static ssize_t applesmc_show_fan_speed(struct device *dev, 757static ssize_t applesmc_show_fan_speed(struct device *dev,
@@ -703,21 +761,12 @@ static ssize_t applesmc_show_fan_speed(struct device *dev,
703 unsigned int speed = 0; 761 unsigned int speed = 0;
704 char newkey[5]; 762 char newkey[5];
705 u8 buffer[2]; 763 u8 buffer[2];
706 struct sensor_device_attribute_2 *sensor_attr =
707 to_sensor_dev_attr_2(attr);
708
709 newkey[0] = fan_speed_keys[sensor_attr->nr][0];
710 newkey[1] = '0' + sensor_attr->index;
711 newkey[2] = fan_speed_keys[sensor_attr->nr][2];
712 newkey[3] = fan_speed_keys[sensor_attr->nr][3];
713 newkey[4] = 0;
714 764
715 mutex_lock(&applesmc_lock); 765 sprintf(newkey, fan_speed_fmt[to_option(attr)], to_index(attr));
716 766
717 ret = applesmc_read_key(newkey, buffer, 2); 767 ret = applesmc_read_key(newkey, buffer, 2);
718 speed = ((buffer[0] << 8 | buffer[1]) >> 2); 768 speed = ((buffer[0] << 8 | buffer[1]) >> 2);
719 769
720 mutex_unlock(&applesmc_lock);
721 if (ret) 770 if (ret)
722 return ret; 771 return ret;
723 else 772 else
@@ -729,30 +778,19 @@ static ssize_t applesmc_store_fan_speed(struct device *dev,
729 const char *sysfsbuf, size_t count) 778 const char *sysfsbuf, size_t count)
730{ 779{
731 int ret; 780 int ret;
732 u32 speed; 781 unsigned long speed;
733 char newkey[5]; 782 char newkey[5];
734 u8 buffer[2]; 783 u8 buffer[2];
735 struct sensor_device_attribute_2 *sensor_attr =
736 to_sensor_dev_attr_2(attr);
737
738 speed = simple_strtoul(sysfsbuf, NULL, 10);
739
740 if (speed > 0x4000) /* Bigger than a 14-bit value */
741 return -EINVAL;
742 784
743 newkey[0] = fan_speed_keys[sensor_attr->nr][0]; 785 if (strict_strtoul(sysfsbuf, 10, &speed) < 0 || speed >= 0x4000)
744 newkey[1] = '0' + sensor_attr->index; 786 return -EINVAL; /* Bigger than a 14-bit value */
745 newkey[2] = fan_speed_keys[sensor_attr->nr][2];
746 newkey[3] = fan_speed_keys[sensor_attr->nr][3];
747 newkey[4] = 0;
748 787
749 mutex_lock(&applesmc_lock); 788 sprintf(newkey, fan_speed_fmt[to_option(attr)], to_index(attr));
750 789
751 buffer[0] = (speed >> 6) & 0xff; 790 buffer[0] = (speed >> 6) & 0xff;
752 buffer[1] = (speed << 2) & 0xff; 791 buffer[1] = (speed << 2) & 0xff;
753 ret = applesmc_write_key(newkey, buffer, 2); 792 ret = applesmc_write_key(newkey, buffer, 2);
754 793
755 mutex_unlock(&applesmc_lock);
756 if (ret) 794 if (ret)
757 return ret; 795 return ret;
758 else 796 else
@@ -760,19 +798,15 @@ static ssize_t applesmc_store_fan_speed(struct device *dev,
760} 798}
761 799
762static ssize_t applesmc_show_fan_manual(struct device *dev, 800static ssize_t applesmc_show_fan_manual(struct device *dev,
763 struct device_attribute *devattr, char *sysfsbuf) 801 struct device_attribute *attr, char *sysfsbuf)
764{ 802{
765 int ret; 803 int ret;
766 u16 manual = 0; 804 u16 manual = 0;
767 u8 buffer[2]; 805 u8 buffer[2];
768 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
769
770 mutex_lock(&applesmc_lock);
771 806
772 ret = applesmc_read_key(FANS_MANUAL, buffer, 2); 807 ret = applesmc_read_key(FANS_MANUAL, buffer, 2);
773 manual = ((buffer[0] << 8 | buffer[1]) >> attr->index) & 0x01; 808 manual = ((buffer[0] << 8 | buffer[1]) >> to_index(attr)) & 0x01;
774 809
775 mutex_unlock(&applesmc_lock);
776 if (ret) 810 if (ret)
777 return ret; 811 return ret;
778 else 812 else
@@ -780,18 +814,16 @@ static ssize_t applesmc_show_fan_manual(struct device *dev,
780} 814}
781 815
782static ssize_t applesmc_store_fan_manual(struct device *dev, 816static ssize_t applesmc_store_fan_manual(struct device *dev,
783 struct device_attribute *devattr, 817 struct device_attribute *attr,
784 const char *sysfsbuf, size_t count) 818 const char *sysfsbuf, size_t count)
785{ 819{
786 int ret; 820 int ret;
787 u8 buffer[2]; 821 u8 buffer[2];
788 u32 input; 822 unsigned long input;
789 u16 val; 823 u16 val;
790 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
791
792 input = simple_strtoul(sysfsbuf, NULL, 10);
793 824
794 mutex_lock(&applesmc_lock); 825 if (strict_strtoul(sysfsbuf, 10, &input) < 0)
826 return -EINVAL;
795 827
796 ret = applesmc_read_key(FANS_MANUAL, buffer, 2); 828 ret = applesmc_read_key(FANS_MANUAL, buffer, 2);
797 val = (buffer[0] << 8 | buffer[1]); 829 val = (buffer[0] << 8 | buffer[1]);
@@ -799,9 +831,9 @@ static ssize_t applesmc_store_fan_manual(struct device *dev,
799 goto out; 831 goto out;
800 832
801 if (input) 833 if (input)
802 val = val | (0x01 << attr->index); 834 val = val | (0x01 << to_index(attr));
803 else 835 else
804 val = val & ~(0x01 << attr->index); 836 val = val & ~(0x01 << to_index(attr));
805 837
806 buffer[0] = (val >> 8) & 0xFF; 838 buffer[0] = (val >> 8) & 0xFF;
807 buffer[1] = val & 0xFF; 839 buffer[1] = val & 0xFF;
@@ -809,7 +841,6 @@ static ssize_t applesmc_store_fan_manual(struct device *dev,
809 ret = applesmc_write_key(FANS_MANUAL, buffer, 2); 841 ret = applesmc_write_key(FANS_MANUAL, buffer, 2);
810 842
811out: 843out:
812 mutex_unlock(&applesmc_lock);
813 if (ret) 844 if (ret)
814 return ret; 845 return ret;
815 else 846 else
@@ -822,21 +853,12 @@ static ssize_t applesmc_show_fan_position(struct device *dev,
822 int ret; 853 int ret;
823 char newkey[5]; 854 char newkey[5];
824 u8 buffer[17]; 855 u8 buffer[17];
825 struct sensor_device_attribute_2 *sensor_attr =
826 to_sensor_dev_attr_2(attr);
827
828 newkey[0] = FAN_POSITION[0];
829 newkey[1] = '0' + sensor_attr->index;
830 newkey[2] = FAN_POSITION[2];
831 newkey[3] = FAN_POSITION[3];
832 newkey[4] = 0;
833 856
834 mutex_lock(&applesmc_lock); 857 sprintf(newkey, FAN_ID_FMT, to_index(attr));
835 858
836 ret = applesmc_read_key(newkey, buffer, 16); 859 ret = applesmc_read_key(newkey, buffer, 16);
837 buffer[16] = 0; 860 buffer[16] = 0;
838 861
839 mutex_unlock(&applesmc_lock);
840 if (ret) 862 if (ret)
841 return ret; 863 return ret;
842 else 864 else
@@ -852,18 +874,14 @@ static ssize_t applesmc_calibrate_show(struct device *dev,
852static ssize_t applesmc_calibrate_store(struct device *dev, 874static ssize_t applesmc_calibrate_store(struct device *dev,
853 struct device_attribute *attr, const char *sysfsbuf, size_t count) 875 struct device_attribute *attr, const char *sysfsbuf, size_t count)
854{ 876{
855 mutex_lock(&applesmc_lock);
856 applesmc_calibrate(); 877 applesmc_calibrate();
857 mutex_unlock(&applesmc_lock);
858 878
859 return count; 879 return count;
860} 880}
861 881
862static void applesmc_backlight_set(struct work_struct *work) 882static void applesmc_backlight_set(struct work_struct *work)
863{ 883{
864 mutex_lock(&applesmc_lock);
865 applesmc_write_key(BACKLIGHT_KEY, backlight_state, 2); 884 applesmc_write_key(BACKLIGHT_KEY, backlight_state, 2);
866 mutex_unlock(&applesmc_lock);
867} 885}
868static DECLARE_WORK(backlight_work, &applesmc_backlight_set); 886static DECLARE_WORK(backlight_work, &applesmc_backlight_set);
869 887
@@ -886,13 +904,10 @@ static ssize_t applesmc_key_count_show(struct device *dev,
886 u8 buffer[4]; 904 u8 buffer[4];
887 u32 count; 905 u32 count;
888 906
889 mutex_lock(&applesmc_lock);
890
891 ret = applesmc_read_key(KEY_COUNT_KEY, buffer, 4); 907 ret = applesmc_read_key(KEY_COUNT_KEY, buffer, 4);
892 count = ((u32)buffer[0]<<24) + ((u32)buffer[1]<<16) + 908 count = ((u32)buffer[0]<<24) + ((u32)buffer[1]<<16) +
893 ((u32)buffer[2]<<8) + buffer[3]; 909 ((u32)buffer[2]<<8) + buffer[3];
894 910
895 mutex_unlock(&applesmc_lock);
896 if (ret) 911 if (ret)
897 return ret; 912 return ret;
898 else 913 else
@@ -902,113 +917,53 @@ static ssize_t applesmc_key_count_show(struct device *dev,
902static ssize_t applesmc_key_at_index_read_show(struct device *dev, 917static ssize_t applesmc_key_at_index_read_show(struct device *dev,
903 struct device_attribute *attr, char *sysfsbuf) 918 struct device_attribute *attr, char *sysfsbuf)
904{ 919{
905 char key[5]; 920 const struct applesmc_entry *entry;
906 char info[6];
907 int ret; 921 int ret;
908 922
909 mutex_lock(&applesmc_lock); 923 entry = applesmc_get_entry_by_index(key_at_index);
910 924 if (IS_ERR(entry))
911 ret = applesmc_get_key_at_index(key_at_index, key); 925 return PTR_ERR(entry);
912 926 ret = applesmc_read_entry(entry, sysfsbuf, entry->len);
913 if (ret || !key[0]) { 927 if (ret)
914 mutex_unlock(&applesmc_lock);
915
916 return -EINVAL;
917 }
918
919 ret = applesmc_get_key_type(key, info);
920
921 if (ret) {
922 mutex_unlock(&applesmc_lock);
923
924 return ret; 928 return ret;
925 }
926
927 /*
928 * info[0] maximum value (APPLESMC_MAX_DATA_LENGTH) is much lower than
929 * PAGE_SIZE, so we don't need any checks before writing to sysfsbuf.
930 */
931 ret = applesmc_read_key(key, sysfsbuf, info[0]);
932
933 mutex_unlock(&applesmc_lock);
934 929
935 if (!ret) { 930 return entry->len;
936 return info[0];
937 } else {
938 return ret;
939 }
940} 931}
941 932
942static ssize_t applesmc_key_at_index_data_length_show(struct device *dev, 933static ssize_t applesmc_key_at_index_data_length_show(struct device *dev,
943 struct device_attribute *attr, char *sysfsbuf) 934 struct device_attribute *attr, char *sysfsbuf)
944{ 935{
945 char key[5]; 936 const struct applesmc_entry *entry;
946 char info[6];
947 int ret;
948
949 mutex_lock(&applesmc_lock);
950
951 ret = applesmc_get_key_at_index(key_at_index, key);
952 937
953 if (ret || !key[0]) { 938 entry = applesmc_get_entry_by_index(key_at_index);
954 mutex_unlock(&applesmc_lock); 939 if (IS_ERR(entry))
940 return PTR_ERR(entry);
955 941
956 return -EINVAL; 942 return snprintf(sysfsbuf, PAGE_SIZE, "%d\n", entry->len);
957 }
958
959 ret = applesmc_get_key_type(key, info);
960
961 mutex_unlock(&applesmc_lock);
962
963 if (!ret)
964 return snprintf(sysfsbuf, PAGE_SIZE, "%d\n", info[0]);
965 else
966 return ret;
967} 943}
968 944
969static ssize_t applesmc_key_at_index_type_show(struct device *dev, 945static ssize_t applesmc_key_at_index_type_show(struct device *dev,
970 struct device_attribute *attr, char *sysfsbuf) 946 struct device_attribute *attr, char *sysfsbuf)
971{ 947{
972 char key[5]; 948 const struct applesmc_entry *entry;
973 char info[6];
974 int ret;
975
976 mutex_lock(&applesmc_lock);
977
978 ret = applesmc_get_key_at_index(key_at_index, key);
979
980 if (ret || !key[0]) {
981 mutex_unlock(&applesmc_lock);
982
983 return -EINVAL;
984 }
985
986 ret = applesmc_get_key_type(key, info);
987 949
988 mutex_unlock(&applesmc_lock); 950 entry = applesmc_get_entry_by_index(key_at_index);
951 if (IS_ERR(entry))
952 return PTR_ERR(entry);
989 953
990 if (!ret) 954 return snprintf(sysfsbuf, PAGE_SIZE, "%s\n", entry->type);
991 return snprintf(sysfsbuf, PAGE_SIZE, "%s\n", info+1);
992 else
993 return ret;
994} 955}
995 956
996static ssize_t applesmc_key_at_index_name_show(struct device *dev, 957static ssize_t applesmc_key_at_index_name_show(struct device *dev,
997 struct device_attribute *attr, char *sysfsbuf) 958 struct device_attribute *attr, char *sysfsbuf)
998{ 959{
999 char key[5]; 960 const struct applesmc_entry *entry;
1000 int ret;
1001 961
1002 mutex_lock(&applesmc_lock); 962 entry = applesmc_get_entry_by_index(key_at_index);
963 if (IS_ERR(entry))
964 return PTR_ERR(entry);
1003 965
1004 ret = applesmc_get_key_at_index(key_at_index, key); 966 return snprintf(sysfsbuf, PAGE_SIZE, "%s\n", entry->key);
1005
1006 mutex_unlock(&applesmc_lock);
1007
1008 if (!ret && key[0])
1009 return snprintf(sysfsbuf, PAGE_SIZE, "%s\n", key);
1010 else
1011 return -EINVAL;
1012} 967}
1013 968
1014static ssize_t applesmc_key_at_index_show(struct device *dev, 969static ssize_t applesmc_key_at_index_show(struct device *dev,
@@ -1020,12 +975,13 @@ static ssize_t applesmc_key_at_index_show(struct device *dev,
1020static ssize_t applesmc_key_at_index_store(struct device *dev, 975static ssize_t applesmc_key_at_index_store(struct device *dev,
1021 struct device_attribute *attr, const char *sysfsbuf, size_t count) 976 struct device_attribute *attr, const char *sysfsbuf, size_t count)
1022{ 977{
1023 mutex_lock(&applesmc_lock); 978 unsigned long newkey;
1024
1025 key_at_index = simple_strtoul(sysfsbuf, NULL, 10);
1026 979
1027 mutex_unlock(&applesmc_lock); 980 if (strict_strtoul(sysfsbuf, 10, &newkey) < 0
981 || newkey >= smcreg.key_count)
982 return -EINVAL;
1028 983
984 key_at_index = newkey;
1029 return count; 985 return count;
1030} 986}
1031 987
@@ -1035,387 +991,101 @@ static struct led_classdev applesmc_backlight = {
1035 .brightness_set = applesmc_brightness_set, 991 .brightness_set = applesmc_brightness_set,
1036}; 992};
1037 993
1038static DEVICE_ATTR(name, 0444, applesmc_name_show, NULL); 994static struct applesmc_node_group info_group[] = {
1039 995 { "name", applesmc_name_show },
1040static DEVICE_ATTR(position, 0444, applesmc_position_show, NULL); 996 { "key_count", applesmc_key_count_show },
1041static DEVICE_ATTR(calibrate, 0644, 997 { "key_at_index", applesmc_key_at_index_show, applesmc_key_at_index_store },
1042 applesmc_calibrate_show, applesmc_calibrate_store); 998 { "key_at_index_name", applesmc_key_at_index_name_show },
1043 999 { "key_at_index_type", applesmc_key_at_index_type_show },
1044static struct attribute *accelerometer_attributes[] = { 1000 { "key_at_index_data_length", applesmc_key_at_index_data_length_show },
1045 &dev_attr_position.attr, 1001 { "key_at_index_data", applesmc_key_at_index_read_show },
1046 &dev_attr_calibrate.attr, 1002 { }
1047 NULL
1048};
1049
1050static const struct attribute_group accelerometer_attributes_group =
1051 { .attrs = accelerometer_attributes };
1052
1053static DEVICE_ATTR(light, 0444, applesmc_light_show, NULL);
1054
1055static DEVICE_ATTR(key_count, 0444, applesmc_key_count_show, NULL);
1056static DEVICE_ATTR(key_at_index, 0644,
1057 applesmc_key_at_index_show, applesmc_key_at_index_store);
1058static DEVICE_ATTR(key_at_index_name, 0444,
1059 applesmc_key_at_index_name_show, NULL);
1060static DEVICE_ATTR(key_at_index_type, 0444,
1061 applesmc_key_at_index_type_show, NULL);
1062static DEVICE_ATTR(key_at_index_data_length, 0444,
1063 applesmc_key_at_index_data_length_show, NULL);
1064static DEVICE_ATTR(key_at_index_data, 0444,
1065 applesmc_key_at_index_read_show, NULL);
1066
1067static struct attribute *key_enumeration_attributes[] = {
1068 &dev_attr_key_count.attr,
1069 &dev_attr_key_at_index.attr,
1070 &dev_attr_key_at_index_name.attr,
1071 &dev_attr_key_at_index_type.attr,
1072 &dev_attr_key_at_index_data_length.attr,
1073 &dev_attr_key_at_index_data.attr,
1074 NULL
1075};
1076
1077static const struct attribute_group key_enumeration_group =
1078 { .attrs = key_enumeration_attributes };
1079
1080/*
1081 * Macro defining SENSOR_DEVICE_ATTR for a fan sysfs entries.
1082 * - show actual speed
1083 * - show/store minimum speed
1084 * - show maximum speed
1085 * - show safe speed
1086 * - show/store target speed
1087 * - show/store manual mode
1088 */
1089#define sysfs_fan_speeds_offset(offset) \
1090static SENSOR_DEVICE_ATTR_2(fan##offset##_input, S_IRUGO, \
1091 applesmc_show_fan_speed, NULL, 0, offset-1); \
1092\
1093static SENSOR_DEVICE_ATTR_2(fan##offset##_min, S_IRUGO | S_IWUSR, \
1094 applesmc_show_fan_speed, applesmc_store_fan_speed, 1, offset-1); \
1095\
1096static SENSOR_DEVICE_ATTR_2(fan##offset##_max, S_IRUGO, \
1097 applesmc_show_fan_speed, NULL, 2, offset-1); \
1098\
1099static SENSOR_DEVICE_ATTR_2(fan##offset##_safe, S_IRUGO, \
1100 applesmc_show_fan_speed, NULL, 3, offset-1); \
1101\
1102static SENSOR_DEVICE_ATTR_2(fan##offset##_output, S_IRUGO | S_IWUSR, \
1103 applesmc_show_fan_speed, applesmc_store_fan_speed, 4, offset-1); \
1104\
1105static SENSOR_DEVICE_ATTR(fan##offset##_manual, S_IRUGO | S_IWUSR, \
1106 applesmc_show_fan_manual, applesmc_store_fan_manual, offset-1); \
1107\
1108static SENSOR_DEVICE_ATTR(fan##offset##_label, S_IRUGO, \
1109 applesmc_show_fan_position, NULL, offset-1); \
1110\
1111static struct attribute *fan##offset##_attributes[] = { \
1112 &sensor_dev_attr_fan##offset##_input.dev_attr.attr, \
1113 &sensor_dev_attr_fan##offset##_min.dev_attr.attr, \
1114 &sensor_dev_attr_fan##offset##_max.dev_attr.attr, \
1115 &sensor_dev_attr_fan##offset##_safe.dev_attr.attr, \
1116 &sensor_dev_attr_fan##offset##_output.dev_attr.attr, \
1117 &sensor_dev_attr_fan##offset##_manual.dev_attr.attr, \
1118 &sensor_dev_attr_fan##offset##_label.dev_attr.attr, \
1119 NULL \
1120}; 1003};
1121 1004
1122/* 1005static struct applesmc_node_group accelerometer_group[] = {
1123 * Create the needed functions for each fan using the macro defined above 1006 { "position", applesmc_position_show },
1124 * (4 fans are supported) 1007 { "calibrate", applesmc_calibrate_show, applesmc_calibrate_store },
1125 */ 1008 { }
1126sysfs_fan_speeds_offset(1);
1127sysfs_fan_speeds_offset(2);
1128sysfs_fan_speeds_offset(3);
1129sysfs_fan_speeds_offset(4);
1130
1131static const struct attribute_group fan_attribute_groups[] = {
1132 { .attrs = fan1_attributes },
1133 { .attrs = fan2_attributes },
1134 { .attrs = fan3_attributes },
1135 { .attrs = fan4_attributes },
1136}; 1009};
1137 1010
1138/* 1011static struct applesmc_node_group light_sensor_group[] = {
1139 * Temperature sensors sysfs entries. 1012 { "light", applesmc_light_show },
1140 */ 1013 { }
1141static SENSOR_DEVICE_ATTR(temp1_label, S_IRUGO,
1142 applesmc_show_sensor_label, NULL, 0);
1143static SENSOR_DEVICE_ATTR(temp2_label, S_IRUGO,
1144 applesmc_show_sensor_label, NULL, 1);
1145static SENSOR_DEVICE_ATTR(temp3_label, S_IRUGO,
1146 applesmc_show_sensor_label, NULL, 2);
1147static SENSOR_DEVICE_ATTR(temp4_label, S_IRUGO,
1148 applesmc_show_sensor_label, NULL, 3);
1149static SENSOR_DEVICE_ATTR(temp5_label, S_IRUGO,
1150 applesmc_show_sensor_label, NULL, 4);
1151static SENSOR_DEVICE_ATTR(temp6_label, S_IRUGO,
1152 applesmc_show_sensor_label, NULL, 5);
1153static SENSOR_DEVICE_ATTR(temp7_label, S_IRUGO,
1154 applesmc_show_sensor_label, NULL, 6);
1155static SENSOR_DEVICE_ATTR(temp8_label, S_IRUGO,
1156 applesmc_show_sensor_label, NULL, 7);
1157static SENSOR_DEVICE_ATTR(temp9_label, S_IRUGO,
1158 applesmc_show_sensor_label, NULL, 8);
1159static SENSOR_DEVICE_ATTR(temp10_label, S_IRUGO,
1160 applesmc_show_sensor_label, NULL, 9);
1161static SENSOR_DEVICE_ATTR(temp11_label, S_IRUGO,
1162 applesmc_show_sensor_label, NULL, 10);
1163static SENSOR_DEVICE_ATTR(temp12_label, S_IRUGO,
1164 applesmc_show_sensor_label, NULL, 11);
1165static SENSOR_DEVICE_ATTR(temp13_label, S_IRUGO,
1166 applesmc_show_sensor_label, NULL, 12);
1167static SENSOR_DEVICE_ATTR(temp14_label, S_IRUGO,
1168 applesmc_show_sensor_label, NULL, 13);
1169static SENSOR_DEVICE_ATTR(temp15_label, S_IRUGO,
1170 applesmc_show_sensor_label, NULL, 14);
1171static SENSOR_DEVICE_ATTR(temp16_label, S_IRUGO,
1172 applesmc_show_sensor_label, NULL, 15);
1173static SENSOR_DEVICE_ATTR(temp17_label, S_IRUGO,
1174 applesmc_show_sensor_label, NULL, 16);
1175static SENSOR_DEVICE_ATTR(temp18_label, S_IRUGO,
1176 applesmc_show_sensor_label, NULL, 17);
1177static SENSOR_DEVICE_ATTR(temp19_label, S_IRUGO,
1178 applesmc_show_sensor_label, NULL, 18);
1179static SENSOR_DEVICE_ATTR(temp20_label, S_IRUGO,
1180 applesmc_show_sensor_label, NULL, 19);
1181static SENSOR_DEVICE_ATTR(temp21_label, S_IRUGO,
1182 applesmc_show_sensor_label, NULL, 20);
1183static SENSOR_DEVICE_ATTR(temp22_label, S_IRUGO,
1184 applesmc_show_sensor_label, NULL, 21);
1185static SENSOR_DEVICE_ATTR(temp23_label, S_IRUGO,
1186 applesmc_show_sensor_label, NULL, 22);
1187static SENSOR_DEVICE_ATTR(temp24_label, S_IRUGO,
1188 applesmc_show_sensor_label, NULL, 23);
1189static SENSOR_DEVICE_ATTR(temp25_label, S_IRUGO,
1190 applesmc_show_sensor_label, NULL, 24);
1191static SENSOR_DEVICE_ATTR(temp26_label, S_IRUGO,
1192 applesmc_show_sensor_label, NULL, 25);
1193static SENSOR_DEVICE_ATTR(temp27_label, S_IRUGO,
1194 applesmc_show_sensor_label, NULL, 26);
1195static SENSOR_DEVICE_ATTR(temp28_label, S_IRUGO,
1196 applesmc_show_sensor_label, NULL, 27);
1197static SENSOR_DEVICE_ATTR(temp29_label, S_IRUGO,
1198 applesmc_show_sensor_label, NULL, 28);
1199static SENSOR_DEVICE_ATTR(temp30_label, S_IRUGO,
1200 applesmc_show_sensor_label, NULL, 29);
1201static SENSOR_DEVICE_ATTR(temp31_label, S_IRUGO,
1202 applesmc_show_sensor_label, NULL, 30);
1203static SENSOR_DEVICE_ATTR(temp32_label, S_IRUGO,
1204 applesmc_show_sensor_label, NULL, 31);
1205static SENSOR_DEVICE_ATTR(temp33_label, S_IRUGO,
1206 applesmc_show_sensor_label, NULL, 32);
1207static SENSOR_DEVICE_ATTR(temp34_label, S_IRUGO,
1208 applesmc_show_sensor_label, NULL, 33);
1209static SENSOR_DEVICE_ATTR(temp35_label, S_IRUGO,
1210 applesmc_show_sensor_label, NULL, 34);
1211static SENSOR_DEVICE_ATTR(temp36_label, S_IRUGO,
1212 applesmc_show_sensor_label, NULL, 35);
1213static SENSOR_DEVICE_ATTR(temp37_label, S_IRUGO,
1214 applesmc_show_sensor_label, NULL, 36);
1215static SENSOR_DEVICE_ATTR(temp38_label, S_IRUGO,
1216 applesmc_show_sensor_label, NULL, 37);
1217static SENSOR_DEVICE_ATTR(temp39_label, S_IRUGO,
1218 applesmc_show_sensor_label, NULL, 38);
1219static SENSOR_DEVICE_ATTR(temp40_label, S_IRUGO,
1220 applesmc_show_sensor_label, NULL, 39);
1221static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO,
1222 applesmc_show_temperature, NULL, 0);
1223static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO,
1224 applesmc_show_temperature, NULL, 1);
1225static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO,
1226 applesmc_show_temperature, NULL, 2);
1227static SENSOR_DEVICE_ATTR(temp4_input, S_IRUGO,
1228 applesmc_show_temperature, NULL, 3);
1229static SENSOR_DEVICE_ATTR(temp5_input, S_IRUGO,
1230 applesmc_show_temperature, NULL, 4);
1231static SENSOR_DEVICE_ATTR(temp6_input, S_IRUGO,
1232 applesmc_show_temperature, NULL, 5);
1233static SENSOR_DEVICE_ATTR(temp7_input, S_IRUGO,
1234 applesmc_show_temperature, NULL, 6);
1235static SENSOR_DEVICE_ATTR(temp8_input, S_IRUGO,
1236 applesmc_show_temperature, NULL, 7);
1237static SENSOR_DEVICE_ATTR(temp9_input, S_IRUGO,
1238 applesmc_show_temperature, NULL, 8);
1239static SENSOR_DEVICE_ATTR(temp10_input, S_IRUGO,
1240 applesmc_show_temperature, NULL, 9);
1241static SENSOR_DEVICE_ATTR(temp11_input, S_IRUGO,
1242 applesmc_show_temperature, NULL, 10);
1243static SENSOR_DEVICE_ATTR(temp12_input, S_IRUGO,
1244 applesmc_show_temperature, NULL, 11);
1245static SENSOR_DEVICE_ATTR(temp13_input, S_IRUGO,
1246 applesmc_show_temperature, NULL, 12);
1247static SENSOR_DEVICE_ATTR(temp14_input, S_IRUGO,
1248 applesmc_show_temperature, NULL, 13);
1249static SENSOR_DEVICE_ATTR(temp15_input, S_IRUGO,
1250 applesmc_show_temperature, NULL, 14);
1251static SENSOR_DEVICE_ATTR(temp16_input, S_IRUGO,
1252 applesmc_show_temperature, NULL, 15);
1253static SENSOR_DEVICE_ATTR(temp17_input, S_IRUGO,
1254 applesmc_show_temperature, NULL, 16);
1255static SENSOR_DEVICE_ATTR(temp18_input, S_IRUGO,
1256 applesmc_show_temperature, NULL, 17);
1257static SENSOR_DEVICE_ATTR(temp19_input, S_IRUGO,
1258 applesmc_show_temperature, NULL, 18);
1259static SENSOR_DEVICE_ATTR(temp20_input, S_IRUGO,
1260 applesmc_show_temperature, NULL, 19);
1261static SENSOR_DEVICE_ATTR(temp21_input, S_IRUGO,
1262 applesmc_show_temperature, NULL, 20);
1263static SENSOR_DEVICE_ATTR(temp22_input, S_IRUGO,
1264 applesmc_show_temperature, NULL, 21);
1265static SENSOR_DEVICE_ATTR(temp23_input, S_IRUGO,
1266 applesmc_show_temperature, NULL, 22);
1267static SENSOR_DEVICE_ATTR(temp24_input, S_IRUGO,
1268 applesmc_show_temperature, NULL, 23);
1269static SENSOR_DEVICE_ATTR(temp25_input, S_IRUGO,
1270 applesmc_show_temperature, NULL, 24);
1271static SENSOR_DEVICE_ATTR(temp26_input, S_IRUGO,
1272 applesmc_show_temperature, NULL, 25);
1273static SENSOR_DEVICE_ATTR(temp27_input, S_IRUGO,
1274 applesmc_show_temperature, NULL, 26);
1275static SENSOR_DEVICE_ATTR(temp28_input, S_IRUGO,
1276 applesmc_show_temperature, NULL, 27);
1277static SENSOR_DEVICE_ATTR(temp29_input, S_IRUGO,
1278 applesmc_show_temperature, NULL, 28);
1279static SENSOR_DEVICE_ATTR(temp30_input, S_IRUGO,
1280 applesmc_show_temperature, NULL, 29);
1281static SENSOR_DEVICE_ATTR(temp31_input, S_IRUGO,
1282 applesmc_show_temperature, NULL, 30);
1283static SENSOR_DEVICE_ATTR(temp32_input, S_IRUGO,
1284 applesmc_show_temperature, NULL, 31);
1285static SENSOR_DEVICE_ATTR(temp33_input, S_IRUGO,
1286 applesmc_show_temperature, NULL, 32);
1287static SENSOR_DEVICE_ATTR(temp34_input, S_IRUGO,
1288 applesmc_show_temperature, NULL, 33);
1289static SENSOR_DEVICE_ATTR(temp35_input, S_IRUGO,
1290 applesmc_show_temperature, NULL, 34);
1291static SENSOR_DEVICE_ATTR(temp36_input, S_IRUGO,
1292 applesmc_show_temperature, NULL, 35);
1293static SENSOR_DEVICE_ATTR(temp37_input, S_IRUGO,
1294 applesmc_show_temperature, NULL, 36);
1295static SENSOR_DEVICE_ATTR(temp38_input, S_IRUGO,
1296 applesmc_show_temperature, NULL, 37);
1297static SENSOR_DEVICE_ATTR(temp39_input, S_IRUGO,
1298 applesmc_show_temperature, NULL, 38);
1299static SENSOR_DEVICE_ATTR(temp40_input, S_IRUGO,
1300 applesmc_show_temperature, NULL, 39);
1301
1302static struct attribute *label_attributes[] = {
1303 &sensor_dev_attr_temp1_label.dev_attr.attr,
1304 &sensor_dev_attr_temp2_label.dev_attr.attr,
1305 &sensor_dev_attr_temp3_label.dev_attr.attr,
1306 &sensor_dev_attr_temp4_label.dev_attr.attr,
1307 &sensor_dev_attr_temp5_label.dev_attr.attr,
1308 &sensor_dev_attr_temp6_label.dev_attr.attr,
1309 &sensor_dev_attr_temp7_label.dev_attr.attr,
1310 &sensor_dev_attr_temp8_label.dev_attr.attr,
1311 &sensor_dev_attr_temp9_label.dev_attr.attr,
1312 &sensor_dev_attr_temp10_label.dev_attr.attr,
1313 &sensor_dev_attr_temp11_label.dev_attr.attr,
1314 &sensor_dev_attr_temp12_label.dev_attr.attr,
1315 &sensor_dev_attr_temp13_label.dev_attr.attr,
1316 &sensor_dev_attr_temp14_label.dev_attr.attr,
1317 &sensor_dev_attr_temp15_label.dev_attr.attr,
1318 &sensor_dev_attr_temp16_label.dev_attr.attr,
1319 &sensor_dev_attr_temp17_label.dev_attr.attr,
1320 &sensor_dev_attr_temp18_label.dev_attr.attr,
1321 &sensor_dev_attr_temp19_label.dev_attr.attr,
1322 &sensor_dev_attr_temp20_label.dev_attr.attr,
1323 &sensor_dev_attr_temp21_label.dev_attr.attr,
1324 &sensor_dev_attr_temp22_label.dev_attr.attr,
1325 &sensor_dev_attr_temp23_label.dev_attr.attr,
1326 &sensor_dev_attr_temp24_label.dev_attr.attr,
1327 &sensor_dev_attr_temp25_label.dev_attr.attr,
1328 &sensor_dev_attr_temp26_label.dev_attr.attr,
1329 &sensor_dev_attr_temp27_label.dev_attr.attr,
1330 &sensor_dev_attr_temp28_label.dev_attr.attr,
1331 &sensor_dev_attr_temp29_label.dev_attr.attr,
1332 &sensor_dev_attr_temp30_label.dev_attr.attr,
1333 &sensor_dev_attr_temp31_label.dev_attr.attr,
1334 &sensor_dev_attr_temp32_label.dev_attr.attr,
1335 &sensor_dev_attr_temp33_label.dev_attr.attr,
1336 &sensor_dev_attr_temp34_label.dev_attr.attr,
1337 &sensor_dev_attr_temp35_label.dev_attr.attr,
1338 &sensor_dev_attr_temp36_label.dev_attr.attr,
1339 &sensor_dev_attr_temp37_label.dev_attr.attr,
1340 &sensor_dev_attr_temp38_label.dev_attr.attr,
1341 &sensor_dev_attr_temp39_label.dev_attr.attr,
1342 &sensor_dev_attr_temp40_label.dev_attr.attr,
1343 NULL
1344}; 1014};
1345 1015
1346static struct attribute *temperature_attributes[] = { 1016static struct applesmc_node_group fan_group[] = {
1347 &sensor_dev_attr_temp1_input.dev_attr.attr, 1017 { "fan%d_label", applesmc_show_fan_position },
1348 &sensor_dev_attr_temp2_input.dev_attr.attr, 1018 { "fan%d_input", applesmc_show_fan_speed, NULL, 0 },
1349 &sensor_dev_attr_temp3_input.dev_attr.attr, 1019 { "fan%d_min", applesmc_show_fan_speed, applesmc_store_fan_speed, 1 },
1350 &sensor_dev_attr_temp4_input.dev_attr.attr, 1020 { "fan%d_max", applesmc_show_fan_speed, NULL, 2 },
1351 &sensor_dev_attr_temp5_input.dev_attr.attr, 1021 { "fan%d_safe", applesmc_show_fan_speed, NULL, 3 },
1352 &sensor_dev_attr_temp6_input.dev_attr.attr, 1022 { "fan%d_output", applesmc_show_fan_speed, applesmc_store_fan_speed, 4 },
1353 &sensor_dev_attr_temp7_input.dev_attr.attr, 1023 { "fan%d_manual", applesmc_show_fan_manual, applesmc_store_fan_manual },
1354 &sensor_dev_attr_temp8_input.dev_attr.attr, 1024 { }
1355 &sensor_dev_attr_temp9_input.dev_attr.attr,
1356 &sensor_dev_attr_temp10_input.dev_attr.attr,
1357 &sensor_dev_attr_temp11_input.dev_attr.attr,
1358 &sensor_dev_attr_temp12_input.dev_attr.attr,
1359 &sensor_dev_attr_temp13_input.dev_attr.attr,
1360 &sensor_dev_attr_temp14_input.dev_attr.attr,
1361 &sensor_dev_attr_temp15_input.dev_attr.attr,
1362 &sensor_dev_attr_temp16_input.dev_attr.attr,
1363 &sensor_dev_attr_temp17_input.dev_attr.attr,
1364 &sensor_dev_attr_temp18_input.dev_attr.attr,
1365 &sensor_dev_attr_temp19_input.dev_attr.attr,
1366 &sensor_dev_attr_temp20_input.dev_attr.attr,
1367 &sensor_dev_attr_temp21_input.dev_attr.attr,
1368 &sensor_dev_attr_temp22_input.dev_attr.attr,
1369 &sensor_dev_attr_temp23_input.dev_attr.attr,
1370 &sensor_dev_attr_temp24_input.dev_attr.attr,
1371 &sensor_dev_attr_temp25_input.dev_attr.attr,
1372 &sensor_dev_attr_temp26_input.dev_attr.attr,
1373 &sensor_dev_attr_temp27_input.dev_attr.attr,
1374 &sensor_dev_attr_temp28_input.dev_attr.attr,
1375 &sensor_dev_attr_temp29_input.dev_attr.attr,
1376 &sensor_dev_attr_temp30_input.dev_attr.attr,
1377 &sensor_dev_attr_temp31_input.dev_attr.attr,
1378 &sensor_dev_attr_temp32_input.dev_attr.attr,
1379 &sensor_dev_attr_temp33_input.dev_attr.attr,
1380 &sensor_dev_attr_temp34_input.dev_attr.attr,
1381 &sensor_dev_attr_temp35_input.dev_attr.attr,
1382 &sensor_dev_attr_temp36_input.dev_attr.attr,
1383 &sensor_dev_attr_temp37_input.dev_attr.attr,
1384 &sensor_dev_attr_temp38_input.dev_attr.attr,
1385 &sensor_dev_attr_temp39_input.dev_attr.attr,
1386 &sensor_dev_attr_temp40_input.dev_attr.attr,
1387 NULL
1388}; 1025};
1389 1026
1390static const struct attribute_group temperature_attributes_group = 1027static struct applesmc_node_group temp_group[] = {
1391 { .attrs = temperature_attributes }; 1028 { "temp%d_label", applesmc_show_sensor_label },
1392 1029 { "temp%d_input", applesmc_show_temperature },
1393static const struct attribute_group label_attributes_group = { 1030 { }
1394 .attrs = label_attributes
1395}; 1031};
1396 1032
1397/* Module stuff */ 1033/* Module stuff */
1398 1034
1399/* 1035/*
1400 * applesmc_dmi_match - found a match. return one, short-circuiting the hunt. 1036 * applesmc_destroy_nodes - remove files and free associated memory
1401 */ 1037 */
1402static int applesmc_dmi_match(const struct dmi_system_id *id) 1038static void applesmc_destroy_nodes(struct applesmc_node_group *groups)
1403{ 1039{
1404 int i = 0; 1040 struct applesmc_node_group *grp;
1405 struct dmi_match_data* dmi_data = id->driver_data; 1041 struct applesmc_dev_attr *node;
1406 printk(KERN_INFO "applesmc: %s detected:\n", id->ident); 1042
1407 applesmc_accelerometer = dmi_data->accelerometer; 1043 for (grp = groups; grp->nodes; grp++) {
1408 printk(KERN_INFO "applesmc: - Model %s accelerometer\n", 1044 for (node = grp->nodes; node->sda.dev_attr.attr.name; node++)
1409 applesmc_accelerometer ? "with" : "without"); 1045 sysfs_remove_file(&pdev->dev.kobj,
1410 applesmc_light = dmi_data->light; 1046 &node->sda.dev_attr.attr);
1411 printk(KERN_INFO "applesmc: - Model %s light sensors and backlight\n", 1047 kfree(grp->nodes);
1412 applesmc_light ? "with" : "without"); 1048 grp->nodes = NULL;
1413 1049 }
1414 applesmc_temperature_set = dmi_data->temperature_set; 1050}
1415 while (temperature_sensors_sets[applesmc_temperature_set][i] != NULL) 1051
1416 i++; 1052/*
1417 printk(KERN_INFO "applesmc: - Model with %d temperature sensors\n", i); 1053 * applesmc_create_nodes - create a two-dimensional group of sysfs files
1418 return 1; 1054 */
1055static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
1056{
1057 struct applesmc_node_group *grp;
1058 struct applesmc_dev_attr *node;
1059 struct attribute *attr;
1060 int ret, i;
1061
1062 for (grp = groups; grp->format; grp++) {
1063 grp->nodes = kcalloc(num + 1, sizeof(*node), GFP_KERNEL);
1064 if (!grp->nodes) {
1065 ret = -ENOMEM;
1066 goto out;
1067 }
1068 for (i = 0; i < num; i++) {
1069 node = &grp->nodes[i];
1070 sprintf(node->name, grp->format, i + 1);
1071 node->sda.index = (grp->option << 16) | (i & 0xffff);
1072 node->sda.dev_attr.show = grp->show;
1073 node->sda.dev_attr.store = grp->store;
1074 attr = &node->sda.dev_attr.attr;
1075 attr->name = node->name;
1076 attr->mode = S_IRUGO | (grp->store ? S_IWUSR : 0);
1077 ret = sysfs_create_file(&pdev->dev.kobj, attr);
1078 if (ret) {
1079 attr->name = NULL;
1080 goto out;
1081 }
1082 }
1083 }
1084
1085 return 0;
1086out:
1087 applesmc_destroy_nodes(groups);
1088 return ret;
1419} 1089}
1420 1090
1421/* Create accelerometer ressources */ 1091/* Create accelerometer ressources */
@@ -1424,8 +1094,10 @@ static int applesmc_create_accelerometer(void)
1424 struct input_dev *idev; 1094 struct input_dev *idev;
1425 int ret; 1095 int ret;
1426 1096
1427 ret = sysfs_create_group(&pdev->dev.kobj, 1097 if (!smcreg.has_accelerometer)
1428 &accelerometer_attributes_group); 1098 return 0;
1099
1100 ret = applesmc_create_nodes(accelerometer_group, 1);
1429 if (ret) 1101 if (ret)
1430 goto out; 1102 goto out;
1431 1103
@@ -1462,184 +1134,96 @@ out_idev:
1462 input_free_polled_device(applesmc_idev); 1134 input_free_polled_device(applesmc_idev);
1463 1135
1464out_sysfs: 1136out_sysfs:
1465 sysfs_remove_group(&pdev->dev.kobj, &accelerometer_attributes_group); 1137 applesmc_destroy_nodes(accelerometer_group);
1466 1138
1467out: 1139out:
1468 printk(KERN_WARNING "applesmc: driver init failed (ret=%d)!\n", ret); 1140 pr_warn("driver init failed (ret=%d)!\n", ret);
1469 return ret; 1141 return ret;
1470} 1142}
1471 1143
1472/* Release all ressources used by the accelerometer */ 1144/* Release all ressources used by the accelerometer */
1473static void applesmc_release_accelerometer(void) 1145static void applesmc_release_accelerometer(void)
1474{ 1146{
1147 if (!smcreg.has_accelerometer)
1148 return;
1475 input_unregister_polled_device(applesmc_idev); 1149 input_unregister_polled_device(applesmc_idev);
1476 input_free_polled_device(applesmc_idev); 1150 input_free_polled_device(applesmc_idev);
1477 sysfs_remove_group(&pdev->dev.kobj, &accelerometer_attributes_group); 1151 applesmc_destroy_nodes(accelerometer_group);
1478} 1152}
1479 1153
1480static __initdata struct dmi_match_data applesmc_dmi_data[] = { 1154static int applesmc_create_light_sensor(void)
1481/* MacBook Pro: accelerometer, backlight and temperature set 0 */ 1155{
1482 { .accelerometer = 1, .light = 1, .temperature_set = 0 }, 1156 if (!smcreg.num_light_sensors)
1483/* MacBook2: accelerometer and temperature set 1 */ 1157 return 0;
1484 { .accelerometer = 1, .light = 0, .temperature_set = 1 }, 1158 return applesmc_create_nodes(light_sensor_group, 1);
1485/* MacBook: accelerometer and temperature set 2 */ 1159}
1486 { .accelerometer = 1, .light = 0, .temperature_set = 2 }, 1160
1487/* MacMini: temperature set 3 */ 1161static void applesmc_release_light_sensor(void)
1488 { .accelerometer = 0, .light = 0, .temperature_set = 3 }, 1162{
1489/* MacPro: temperature set 4 */ 1163 if (!smcreg.num_light_sensors)
1490 { .accelerometer = 0, .light = 0, .temperature_set = 4 }, 1164 return;
1491/* iMac: temperature set 5 */ 1165 applesmc_destroy_nodes(light_sensor_group);
1492 { .accelerometer = 0, .light = 0, .temperature_set = 5 }, 1166}
1493/* MacBook3, MacBook4: accelerometer and temperature set 6 */ 1167
1494 { .accelerometer = 1, .light = 0, .temperature_set = 6 }, 1168static int applesmc_create_key_backlight(void)
1495/* MacBook Air: accelerometer, backlight and temperature set 7 */ 1169{
1496 { .accelerometer = 1, .light = 1, .temperature_set = 7 }, 1170 if (!smcreg.has_key_backlight)
1497/* MacBook Pro 4: accelerometer, backlight and temperature set 8 */ 1171 return 0;
1498 { .accelerometer = 1, .light = 1, .temperature_set = 8 }, 1172 applesmc_led_wq = create_singlethread_workqueue("applesmc-led");
1499/* MacBook Pro 3: accelerometer, backlight and temperature set 9 */ 1173 if (!applesmc_led_wq)
1500 { .accelerometer = 1, .light = 1, .temperature_set = 9 }, 1174 return -ENOMEM;
1501/* iMac 5: light sensor only, temperature set 10 */ 1175 return led_classdev_register(&pdev->dev, &applesmc_backlight);
1502 { .accelerometer = 0, .light = 0, .temperature_set = 10 }, 1176}
1503/* MacBook 5: accelerometer, backlight and temperature set 11 */ 1177
1504 { .accelerometer = 1, .light = 1, .temperature_set = 11 }, 1178static void applesmc_release_key_backlight(void)
1505/* MacBook Pro 5: accelerometer, backlight and temperature set 12 */ 1179{
1506 { .accelerometer = 1, .light = 1, .temperature_set = 12 }, 1180 if (!smcreg.has_key_backlight)
1507/* iMac 8: light sensor only, temperature set 13 */ 1181 return;
1508 { .accelerometer = 0, .light = 0, .temperature_set = 13 }, 1182 led_classdev_unregister(&applesmc_backlight);
1509/* iMac 6: light sensor only, temperature set 14 */ 1183 destroy_workqueue(applesmc_led_wq);
1510 { .accelerometer = 0, .light = 0, .temperature_set = 14 }, 1184}
1511/* MacBook Air 2,1: accelerometer, backlight and temperature set 15 */ 1185
1512 { .accelerometer = 1, .light = 1, .temperature_set = 15 }, 1186static int applesmc_dmi_match(const struct dmi_system_id *id)
1513/* MacPro3,1: temperature set 16 */ 1187{
1514 { .accelerometer = 0, .light = 0, .temperature_set = 16 }, 1188 return 1;
1515/* iMac 9,1: light sensor only, temperature set 17 */ 1189}
1516 { .accelerometer = 0, .light = 0, .temperature_set = 17 },
1517/* MacBook Pro 2,2: accelerometer, backlight and temperature set 18 */
1518 { .accelerometer = 1, .light = 1, .temperature_set = 18 },
1519/* MacBook Pro 5,3: accelerometer, backlight and temperature set 19 */
1520 { .accelerometer = 1, .light = 1, .temperature_set = 19 },
1521/* MacBook Pro 5,4: accelerometer, backlight and temperature set 20 */
1522 { .accelerometer = 1, .light = 1, .temperature_set = 20 },
1523/* MacBook Pro 6,2: accelerometer, backlight and temperature set 21 */
1524 { .accelerometer = 1, .light = 1, .temperature_set = 21 },
1525/* MacBook Pro 7,1: accelerometer, backlight and temperature set 22 */
1526 { .accelerometer = 1, .light = 1, .temperature_set = 22 },
1527};
1528 1190
1529/* Note that DMI_MATCH(...,"MacBook") will match "MacBookPro1,1". 1191/* Note that DMI_MATCH(...,"MacBook") will match "MacBookPro1,1".
1530 * So we need to put "Apple MacBook Pro" before "Apple MacBook". */ 1192 * So we need to put "Apple MacBook Pro" before "Apple MacBook". */
1531static __initdata struct dmi_system_id applesmc_whitelist[] = { 1193static __initdata struct dmi_system_id applesmc_whitelist[] = {
1532 { applesmc_dmi_match, "Apple MacBook Air 2", {
1533 DMI_MATCH(DMI_BOARD_VENDOR, "Apple"),
1534 DMI_MATCH(DMI_PRODUCT_NAME, "MacBookAir2") },
1535 &applesmc_dmi_data[15]},
1536 { applesmc_dmi_match, "Apple MacBook Air", { 1194 { applesmc_dmi_match, "Apple MacBook Air", {
1537 DMI_MATCH(DMI_BOARD_VENDOR, "Apple"), 1195 DMI_MATCH(DMI_BOARD_VENDOR, "Apple"),
1538 DMI_MATCH(DMI_PRODUCT_NAME, "MacBookAir") }, 1196 DMI_MATCH(DMI_PRODUCT_NAME, "MacBookAir") },
1539 &applesmc_dmi_data[7]}, 1197 },
1540 { applesmc_dmi_match, "Apple MacBook Pro 7", {
1541 DMI_MATCH(DMI_BOARD_VENDOR, "Apple"),
1542 DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro7") },
1543 &applesmc_dmi_data[22]},
1544 { applesmc_dmi_match, "Apple MacBook Pro 5,4", {
1545 DMI_MATCH(DMI_BOARD_VENDOR, "Apple"),
1546 DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro5,4") },
1547 &applesmc_dmi_data[20]},
1548 { applesmc_dmi_match, "Apple MacBook Pro 5,3", {
1549 DMI_MATCH(DMI_BOARD_VENDOR, "Apple"),
1550 DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro5,3") },
1551 &applesmc_dmi_data[19]},
1552 { applesmc_dmi_match, "Apple MacBook Pro 6", {
1553 DMI_MATCH(DMI_BOARD_VENDOR, "Apple"),
1554 DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro6") },
1555 &applesmc_dmi_data[21]},
1556 { applesmc_dmi_match, "Apple MacBook Pro 5", {
1557 DMI_MATCH(DMI_BOARD_VENDOR, "Apple"),
1558 DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro5") },
1559 &applesmc_dmi_data[12]},
1560 { applesmc_dmi_match, "Apple MacBook Pro 4", {
1561 DMI_MATCH(DMI_BOARD_VENDOR, "Apple"),
1562 DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro4") },
1563 &applesmc_dmi_data[8]},
1564 { applesmc_dmi_match, "Apple MacBook Pro 3", {
1565 DMI_MATCH(DMI_BOARD_VENDOR, "Apple"),
1566 DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro3") },
1567 &applesmc_dmi_data[9]},
1568 { applesmc_dmi_match, "Apple MacBook Pro 2,2", {
1569 DMI_MATCH(DMI_BOARD_VENDOR, "Apple Computer, Inc."),
1570 DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro2,2") },
1571 &applesmc_dmi_data[18]},
1572 { applesmc_dmi_match, "Apple MacBook Pro", { 1198 { applesmc_dmi_match, "Apple MacBook Pro", {
1573 DMI_MATCH(DMI_BOARD_VENDOR,"Apple"),
1574 DMI_MATCH(DMI_PRODUCT_NAME,"MacBookPro") },
1575 &applesmc_dmi_data[0]},
1576 { applesmc_dmi_match, "Apple MacBook (v2)", {
1577 DMI_MATCH(DMI_BOARD_VENDOR,"Apple"),
1578 DMI_MATCH(DMI_PRODUCT_NAME,"MacBook2") },
1579 &applesmc_dmi_data[1]},
1580 { applesmc_dmi_match, "Apple MacBook (v3)", {
1581 DMI_MATCH(DMI_BOARD_VENDOR,"Apple"),
1582 DMI_MATCH(DMI_PRODUCT_NAME,"MacBook3") },
1583 &applesmc_dmi_data[6]},
1584 { applesmc_dmi_match, "Apple MacBook 4", {
1585 DMI_MATCH(DMI_BOARD_VENDOR, "Apple"),
1586 DMI_MATCH(DMI_PRODUCT_NAME, "MacBook4") },
1587 &applesmc_dmi_data[6]},
1588 { applesmc_dmi_match, "Apple MacBook 5", {
1589 DMI_MATCH(DMI_BOARD_VENDOR, "Apple"), 1199 DMI_MATCH(DMI_BOARD_VENDOR, "Apple"),
1590 DMI_MATCH(DMI_PRODUCT_NAME, "MacBook5") }, 1200 DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro") },
1591 &applesmc_dmi_data[11]}, 1201 },
1592 { applesmc_dmi_match, "Apple MacBook", { 1202 { applesmc_dmi_match, "Apple MacBook", {
1593 DMI_MATCH(DMI_BOARD_VENDOR,"Apple"), 1203 DMI_MATCH(DMI_BOARD_VENDOR, "Apple"),
1594 DMI_MATCH(DMI_PRODUCT_NAME,"MacBook") }, 1204 DMI_MATCH(DMI_PRODUCT_NAME, "MacBook") },
1595 &applesmc_dmi_data[2]}, 1205 },
1596 { applesmc_dmi_match, "Apple Macmini", { 1206 { applesmc_dmi_match, "Apple Macmini", {
1597 DMI_MATCH(DMI_BOARD_VENDOR,"Apple"),
1598 DMI_MATCH(DMI_PRODUCT_NAME,"Macmini") },
1599 &applesmc_dmi_data[3]},
1600 { applesmc_dmi_match, "Apple MacPro2", {
1601 DMI_MATCH(DMI_BOARD_VENDOR,"Apple"),
1602 DMI_MATCH(DMI_PRODUCT_NAME,"MacPro2") },
1603 &applesmc_dmi_data[4]},
1604 { applesmc_dmi_match, "Apple MacPro3", {
1605 DMI_MATCH(DMI_BOARD_VENDOR, "Apple"), 1207 DMI_MATCH(DMI_BOARD_VENDOR, "Apple"),
1606 DMI_MATCH(DMI_PRODUCT_NAME, "MacPro3") }, 1208 DMI_MATCH(DMI_PRODUCT_NAME, "Macmini") },
1607 &applesmc_dmi_data[16]}, 1209 },
1608 { applesmc_dmi_match, "Apple MacPro", { 1210 { applesmc_dmi_match, "Apple MacPro", {
1609 DMI_MATCH(DMI_BOARD_VENDOR, "Apple"), 1211 DMI_MATCH(DMI_BOARD_VENDOR, "Apple"),
1610 DMI_MATCH(DMI_PRODUCT_NAME, "MacPro") }, 1212 DMI_MATCH(DMI_PRODUCT_NAME, "MacPro") },
1611 &applesmc_dmi_data[4]}, 1213 },
1612 { applesmc_dmi_match, "Apple iMac 9,1", {
1613 DMI_MATCH(DMI_BOARD_VENDOR, "Apple Inc."),
1614 DMI_MATCH(DMI_PRODUCT_NAME, "iMac9,1") },
1615 &applesmc_dmi_data[17]},
1616 { applesmc_dmi_match, "Apple iMac 8", {
1617 DMI_MATCH(DMI_BOARD_VENDOR, "Apple"),
1618 DMI_MATCH(DMI_PRODUCT_NAME, "iMac8") },
1619 &applesmc_dmi_data[13]},
1620 { applesmc_dmi_match, "Apple iMac 6", {
1621 DMI_MATCH(DMI_BOARD_VENDOR, "Apple"),
1622 DMI_MATCH(DMI_PRODUCT_NAME, "iMac6") },
1623 &applesmc_dmi_data[14]},
1624 { applesmc_dmi_match, "Apple iMac 5", {
1625 DMI_MATCH(DMI_BOARD_VENDOR, "Apple"),
1626 DMI_MATCH(DMI_PRODUCT_NAME, "iMac5") },
1627 &applesmc_dmi_data[10]},
1628 { applesmc_dmi_match, "Apple iMac", { 1214 { applesmc_dmi_match, "Apple iMac", {
1629 DMI_MATCH(DMI_BOARD_VENDOR,"Apple"), 1215 DMI_MATCH(DMI_BOARD_VENDOR, "Apple"),
1630 DMI_MATCH(DMI_PRODUCT_NAME,"iMac") }, 1216 DMI_MATCH(DMI_PRODUCT_NAME, "iMac") },
1631 &applesmc_dmi_data[5]}, 1217 },
1632 { .ident = NULL } 1218 { .ident = NULL }
1633}; 1219};
1634 1220
1635static int __init applesmc_init(void) 1221static int __init applesmc_init(void)
1636{ 1222{
1637 int ret; 1223 int ret;
1638 int count;
1639 int i;
1640 1224
1641 if (!dmi_check_system(applesmc_whitelist)) { 1225 if (!dmi_check_system(applesmc_whitelist)) {
1642 printk(KERN_WARNING "applesmc: supported laptop not found!\n"); 1226 pr_warn("supported laptop not found!\n");
1643 ret = -ENODEV; 1227 ret = -ENODEV;
1644 goto out; 1228 goto out;
1645 } 1229 }
@@ -1661,83 +1245,34 @@ static int __init applesmc_init(void)
1661 goto out_driver; 1245 goto out_driver;
1662 } 1246 }
1663 1247
1664 ret = sysfs_create_file(&pdev->dev.kobj, &dev_attr_name.attr); 1248 /* create register cache */
1249 ret = applesmc_init_smcreg();
1665 if (ret) 1250 if (ret)
1666 goto out_device; 1251 goto out_device;
1667 1252
1668 /* Create key enumeration sysfs files */ 1253 ret = applesmc_create_nodes(info_group, 1);
1669 ret = sysfs_create_group(&pdev->dev.kobj, &key_enumeration_group);
1670 if (ret) 1254 if (ret)
1671 goto out_name; 1255 goto out_smcreg;
1672
1673 /* create fan files */
1674 count = applesmc_get_fan_count();
1675 if (count < 0)
1676 printk(KERN_ERR "applesmc: Cannot get the number of fans.\n");
1677 else
1678 printk(KERN_INFO "applesmc: %d fans found.\n", count);
1679 1256
1680 if (count > 4) { 1257 ret = applesmc_create_nodes(fan_group, smcreg.fan_count);
1681 count = 4; 1258 if (ret)
1682 printk(KERN_WARNING "applesmc: More than 4 fans found," 1259 goto out_info;
1683 " but at most 4 fans are supported"
1684 " by the driver.\n");
1685 }
1686
1687 while (fans_handled < count) {
1688 ret = sysfs_create_group(&pdev->dev.kobj,
1689 &fan_attribute_groups[fans_handled]);
1690 if (ret)
1691 goto out_fans;
1692 fans_handled++;
1693 }
1694
1695 for (i = 0;
1696 temperature_sensors_sets[applesmc_temperature_set][i] != NULL;
1697 i++) {
1698 if (temperature_attributes[i] == NULL ||
1699 label_attributes[i] == NULL) {
1700 printk(KERN_ERR "applesmc: More temperature sensors "
1701 "in temperature_sensors_sets (at least %i)"
1702 "than available sysfs files in "
1703 "temperature_attributes (%i), please report "
1704 "this bug.\n", i, i-1);
1705 goto out_temperature;
1706 }
1707 ret = sysfs_create_file(&pdev->dev.kobj,
1708 temperature_attributes[i]);
1709 if (ret)
1710 goto out_temperature;
1711 ret = sysfs_create_file(&pdev->dev.kobj,
1712 label_attributes[i]);
1713 if (ret)
1714 goto out_temperature;
1715 }
1716 1260
1717 if (applesmc_accelerometer) { 1261 ret = applesmc_create_nodes(temp_group, smcreg.temp_count);
1718 ret = applesmc_create_accelerometer(); 1262 if (ret)
1719 if (ret) 1263 goto out_fans;
1720 goto out_temperature;
1721 }
1722 1264
1723 if (applesmc_light) { 1265 ret = applesmc_create_accelerometer();
1724 /* Add light sensor file */ 1266 if (ret)
1725 ret = sysfs_create_file(&pdev->dev.kobj, &dev_attr_light.attr); 1267 goto out_temperature;
1726 if (ret)
1727 goto out_accelerometer;
1728 1268
1729 /* Create the workqueue */ 1269 ret = applesmc_create_light_sensor();
1730 applesmc_led_wq = create_singlethread_workqueue("applesmc-led"); 1270 if (ret)
1731 if (!applesmc_led_wq) { 1271 goto out_accelerometer;
1732 ret = -ENOMEM;
1733 goto out_light_sysfs;
1734 }
1735 1272
1736 /* register as a led device */ 1273 ret = applesmc_create_key_backlight();
1737 ret = led_classdev_register(&pdev->dev, &applesmc_backlight); 1274 if (ret)
1738 if (ret < 0) 1275 goto out_light_sysfs;
1739 goto out_light_wq;
1740 }
1741 1276
1742 hwmon_dev = hwmon_device_register(&pdev->dev); 1277 hwmon_dev = hwmon_device_register(&pdev->dev);
1743 if (IS_ERR(hwmon_dev)) { 1278 if (IS_ERR(hwmon_dev)) {
@@ -1745,32 +1280,22 @@ static int __init applesmc_init(void)
1745 goto out_light_ledclass; 1280 goto out_light_ledclass;
1746 } 1281 }
1747 1282
1748 printk(KERN_INFO "applesmc: driver successfully loaded.\n");
1749
1750 return 0; 1283 return 0;
1751 1284
1752out_light_ledclass: 1285out_light_ledclass:
1753 if (applesmc_light) 1286 applesmc_release_key_backlight();
1754 led_classdev_unregister(&applesmc_backlight);
1755out_light_wq:
1756 if (applesmc_light)
1757 destroy_workqueue(applesmc_led_wq);
1758out_light_sysfs: 1287out_light_sysfs:
1759 if (applesmc_light) 1288 applesmc_release_light_sensor();
1760 sysfs_remove_file(&pdev->dev.kobj, &dev_attr_light.attr);
1761out_accelerometer: 1289out_accelerometer:
1762 if (applesmc_accelerometer) 1290 applesmc_release_accelerometer();
1763 applesmc_release_accelerometer();
1764out_temperature: 1291out_temperature:
1765 sysfs_remove_group(&pdev->dev.kobj, &label_attributes_group); 1292 applesmc_destroy_nodes(temp_group);
1766 sysfs_remove_group(&pdev->dev.kobj, &temperature_attributes_group);
1767out_fans: 1293out_fans:
1768 while (fans_handled) 1294 applesmc_destroy_nodes(fan_group);
1769 sysfs_remove_group(&pdev->dev.kobj, 1295out_info:
1770 &fan_attribute_groups[--fans_handled]); 1296 applesmc_destroy_nodes(info_group);
1771 sysfs_remove_group(&pdev->dev.kobj, &key_enumeration_group); 1297out_smcreg:
1772out_name: 1298 applesmc_destroy_smcreg();
1773 sysfs_remove_file(&pdev->dev.kobj, &dev_attr_name.attr);
1774out_device: 1299out_device:
1775 platform_device_unregister(pdev); 1300 platform_device_unregister(pdev);
1776out_driver: 1301out_driver:
@@ -1778,32 +1303,23 @@ out_driver:
1778out_region: 1303out_region:
1779 release_region(APPLESMC_DATA_PORT, APPLESMC_NR_PORTS); 1304 release_region(APPLESMC_DATA_PORT, APPLESMC_NR_PORTS);
1780out: 1305out:
1781 printk(KERN_WARNING "applesmc: driver init failed (ret=%d)!\n", ret); 1306 pr_warn("driver init failed (ret=%d)!\n", ret);
1782 return ret; 1307 return ret;
1783} 1308}
1784 1309
1785static void __exit applesmc_exit(void) 1310static void __exit applesmc_exit(void)
1786{ 1311{
1787 hwmon_device_unregister(hwmon_dev); 1312 hwmon_device_unregister(hwmon_dev);
1788 if (applesmc_light) { 1313 applesmc_release_key_backlight();
1789 led_classdev_unregister(&applesmc_backlight); 1314 applesmc_release_light_sensor();
1790 destroy_workqueue(applesmc_led_wq); 1315 applesmc_release_accelerometer();
1791 sysfs_remove_file(&pdev->dev.kobj, &dev_attr_light.attr); 1316 applesmc_destroy_nodes(temp_group);
1792 } 1317 applesmc_destroy_nodes(fan_group);
1793 if (applesmc_accelerometer) 1318 applesmc_destroy_nodes(info_group);
1794 applesmc_release_accelerometer(); 1319 applesmc_destroy_smcreg();
1795 sysfs_remove_group(&pdev->dev.kobj, &label_attributes_group);
1796 sysfs_remove_group(&pdev->dev.kobj, &temperature_attributes_group);
1797 while (fans_handled)
1798 sysfs_remove_group(&pdev->dev.kobj,
1799 &fan_attribute_groups[--fans_handled]);
1800 sysfs_remove_group(&pdev->dev.kobj, &key_enumeration_group);
1801 sysfs_remove_file(&pdev->dev.kobj, &dev_attr_name.attr);
1802 platform_device_unregister(pdev); 1320 platform_device_unregister(pdev);
1803 platform_driver_unregister(&applesmc_driver); 1321 platform_driver_unregister(&applesmc_driver);
1804 release_region(APPLESMC_DATA_PORT, APPLESMC_NR_PORTS); 1322 release_region(APPLESMC_DATA_PORT, APPLESMC_NR_PORTS);
1805
1806 printk(KERN_INFO "applesmc: driver unloaded.\n");
1807} 1323}
1808 1324
1809module_init(applesmc_init); 1325module_init(applesmc_init);
diff --git a/drivers/hwmon/asb100.c b/drivers/hwmon/asb100.c
index 7dada559b3a1..c02a052d3085 100644
--- a/drivers/hwmon/asb100.c
+++ b/drivers/hwmon/asb100.c
@@ -36,6 +36,8 @@
36 asb100 7 3 1 4 0x31 0x0694 yes no 36 asb100 7 3 1 4 0x31 0x0694 yes no
37*/ 37*/
38 38
39#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
40
39#include <linux/module.h> 41#include <linux/module.h>
40#include <linux/slab.h> 42#include <linux/slab.h>
41#include <linux/i2c.h> 43#include <linux/i2c.h>
@@ -701,8 +703,7 @@ static int asb100_detect(struct i2c_client *client,
701 int val1, val2; 703 int val1, val2;
702 704
703 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { 705 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
704 pr_debug("asb100.o: detect failed, " 706 pr_debug("detect failed, smbus byte data not supported!\n");
705 "smbus byte data not supported!\n");
706 return -ENODEV; 707 return -ENODEV;
707 } 708 }
708 709
@@ -715,7 +716,7 @@ static int asb100_detect(struct i2c_client *client,
715 (((!(val1 & 0x80)) && (val2 != 0x94)) || 716 (((!(val1 & 0x80)) && (val2 != 0x94)) ||
716 /* Check for ASB100 ID (high byte ) */ 717 /* Check for ASB100 ID (high byte ) */
717 ((val1 & 0x80) && (val2 != 0x06)))) { 718 ((val1 & 0x80) && (val2 != 0x06)))) {
718 pr_debug("asb100: detect failed, bad chip id 0x%02x!\n", val2); 719 pr_debug("detect failed, bad chip id 0x%02x!\n", val2);
719 return -ENODEV; 720 return -ENODEV;
720 } 721 }
721 722
@@ -744,7 +745,7 @@ static int asb100_probe(struct i2c_client *client,
744 745
745 data = kzalloc(sizeof(struct asb100_data), GFP_KERNEL); 746 data = kzalloc(sizeof(struct asb100_data), GFP_KERNEL);
746 if (!data) { 747 if (!data) {
747 pr_debug("asb100.o: probe failed, kzalloc failed!\n"); 748 pr_debug("probe failed, kzalloc failed!\n");
748 err = -ENOMEM; 749 err = -ENOMEM;
749 goto ERROR0; 750 goto ERROR0;
750 } 751 }
diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
index 23b8555215d2..2d68cf3c223b 100644
--- a/drivers/hwmon/asus_atk0110.c
+++ b/drivers/hwmon/asus_atk0110.c
@@ -5,6 +5,8 @@
5 * See COPYING in the top level directory of the kernel tree. 5 * See COPYING in the top level directory of the kernel tree.
6 */ 6 */
7 7
8#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
9
8#include <linux/debugfs.h> 10#include <linux/debugfs.h>
9#include <linux/kernel.h> 11#include <linux/kernel.h>
10#include <linux/hwmon.h> 12#include <linux/hwmon.h>
@@ -1414,14 +1416,13 @@ static int __init atk0110_init(void)
1414 1416
1415 /* Make sure it's safe to access the device through ACPI */ 1417 /* Make sure it's safe to access the device through ACPI */
1416 if (!acpi_resources_are_enforced()) { 1418 if (!acpi_resources_are_enforced()) {
1417 pr_err("atk: Resources not safely usable due to " 1419 pr_err("Resources not safely usable due to acpi_enforce_resources kernel parameter\n");
1418 "acpi_enforce_resources kernel parameter\n");
1419 return -EBUSY; 1420 return -EBUSY;
1420 } 1421 }
1421 1422
1422 ret = acpi_bus_register_driver(&atk_driver); 1423 ret = acpi_bus_register_driver(&atk_driver);
1423 if (ret) 1424 if (ret)
1424 pr_info("atk: acpi_bus_register_driver failed: %d\n", ret); 1425 pr_info("acpi_bus_register_driver failed: %d\n", ret);
1425 1426
1426 return ret; 1427 return ret;
1427} 1428}
diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
index 42de98d73ff5..194ca0aa8b0c 100644
--- a/drivers/hwmon/coretemp.c
+++ b/drivers/hwmon/coretemp.c
@@ -20,6 +20,8 @@
20 * 02110-1301 USA. 20 * 02110-1301 USA.
21 */ 21 */
22 22
23#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
24
23#include <linux/module.h> 25#include <linux/module.h>
24#include <linux/init.h> 26#include <linux/init.h>
25#include <linux/slab.h> 27#include <linux/slab.h>
@@ -445,8 +447,8 @@ static int __cpuinit coretemp_device_add(unsigned int cpu)
445 * without thermal sensors will be filtered out. 447 * without thermal sensors will be filtered out.
446 */ 448 */
447 if (!cpu_has(c, X86_FEATURE_DTS)) { 449 if (!cpu_has(c, X86_FEATURE_DTS)) {
448 printk(KERN_INFO DRVNAME ": CPU (model=0x%x)" 450 pr_info("CPU (model=0x%x) has no thermal sensor\n",
449 " has no thermal sensor.\n", c->x86_model); 451 c->x86_model);
450 return 0; 452 return 0;
451 } 453 }
452 454
@@ -466,7 +468,7 @@ static int __cpuinit coretemp_device_add(unsigned int cpu)
466 pdev = platform_device_alloc(DRVNAME, cpu); 468 pdev = platform_device_alloc(DRVNAME, cpu);
467 if (!pdev) { 469 if (!pdev) {
468 err = -ENOMEM; 470 err = -ENOMEM;
469 printk(KERN_ERR DRVNAME ": Device allocation failed\n"); 471 pr_err("Device allocation failed\n");
470 goto exit; 472 goto exit;
471 } 473 }
472 474
@@ -478,8 +480,7 @@ static int __cpuinit coretemp_device_add(unsigned int cpu)
478 480
479 err = platform_device_add(pdev); 481 err = platform_device_add(pdev);
480 if (err) { 482 if (err) {
481 printk(KERN_ERR DRVNAME ": Device addition failed (%d)\n", 483 pr_err("Device addition failed (%d)\n", err);
482 err);
483 goto exit_device_free; 484 goto exit_device_free;
484 } 485 }
485 486
diff --git a/drivers/hwmon/dme1737.c b/drivers/hwmon/dme1737.c
index 980c17d5eeae..d9c592713919 100644
--- a/drivers/hwmon/dme1737.c
+++ b/drivers/hwmon/dme1737.c
@@ -25,6 +25,8 @@
25 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 25 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 */ 26 */
27 27
28#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
29
28#include <linux/module.h> 30#include <linux/module.h>
29#include <linux/init.h> 31#include <linux/init.h>
30#include <linux/slab.h> 32#include <linux/slab.h>
@@ -75,12 +77,14 @@ enum chips { dme1737, sch5027, sch311x, sch5127 };
75 * in4 +12V 77 * in4 +12V
76 * in5 VTR (+3.3V stby) 78 * in5 VTR (+3.3V stby)
77 * in6 Vbat 79 * in6 Vbat
80 * in7 Vtrip (sch5127 only)
78 * 81 *
79 * --------------------------------------------------------------------- */ 82 * --------------------------------------------------------------------- */
80 83
81/* Voltages (in) numbered 0-6 (ix) */ 84/* Voltages (in) numbered 0-7 (ix) */
82#define DME1737_REG_IN(ix) ((ix) < 5 ? 0x20 + (ix) \ 85#define DME1737_REG_IN(ix) ((ix) < 5 ? 0x20 + (ix) : \
83 : 0x94 + (ix)) 86 (ix) < 7 ? 0x94 + (ix) : \
87 0x1f)
84#define DME1737_REG_IN_MIN(ix) ((ix) < 5 ? 0x44 + (ix) * 2 \ 88#define DME1737_REG_IN_MIN(ix) ((ix) < 5 ? 0x44 + (ix) * 2 \
85 : 0x91 + (ix) * 2) 89 : 0x91 + (ix) * 2)
86#define DME1737_REG_IN_MAX(ix) ((ix) < 5 ? 0x45 + (ix) * 2 \ 90#define DME1737_REG_IN_MAX(ix) ((ix) < 5 ? 0x45 + (ix) * 2 \
@@ -99,10 +103,11 @@ enum chips { dme1737, sch5027, sch311x, sch5127 };
99 * IN_TEMP_LSB(1) = [temp3, temp1] 103 * IN_TEMP_LSB(1) = [temp3, temp1]
100 * IN_TEMP_LSB(2) = [in4, temp2] 104 * IN_TEMP_LSB(2) = [in4, temp2]
101 * IN_TEMP_LSB(3) = [in3, in0] 105 * IN_TEMP_LSB(3) = [in3, in0]
102 * IN_TEMP_LSB(4) = [in2, in1] */ 106 * IN_TEMP_LSB(4) = [in2, in1]
107 * IN_TEMP_LSB(5) = [res, in7] */
103#define DME1737_REG_IN_TEMP_LSB(ix) (0x84 + (ix)) 108#define DME1737_REG_IN_TEMP_LSB(ix) (0x84 + (ix))
104static const u8 DME1737_REG_IN_LSB[] = {3, 4, 4, 3, 2, 0, 0}; 109static const u8 DME1737_REG_IN_LSB[] = {3, 4, 4, 3, 2, 0, 0, 5};
105static const u8 DME1737_REG_IN_LSB_SHL[] = {4, 4, 0, 0, 0, 0, 4}; 110static const u8 DME1737_REG_IN_LSB_SHL[] = {4, 4, 0, 0, 0, 0, 4, 4};
106static const u8 DME1737_REG_TEMP_LSB[] = {1, 2, 1}; 111static const u8 DME1737_REG_TEMP_LSB[] = {1, 2, 1};
107static const u8 DME1737_REG_TEMP_LSB_SHL[] = {4, 4, 0}; 112static const u8 DME1737_REG_TEMP_LSB_SHL[] = {4, 4, 0};
108 113
@@ -143,7 +148,7 @@ static const u8 DME1737_REG_TEMP_LSB_SHL[] = {4, 4, 0};
143#define DME1737_REG_ALARM1 0x41 148#define DME1737_REG_ALARM1 0x41
144#define DME1737_REG_ALARM2 0x42 149#define DME1737_REG_ALARM2 0x42
145#define DME1737_REG_ALARM3 0x83 150#define DME1737_REG_ALARM3 0x83
146static const u8 DME1737_BIT_ALARM_IN[] = {0, 1, 2, 3, 8, 16, 17}; 151static const u8 DME1737_BIT_ALARM_IN[] = {0, 1, 2, 3, 8, 16, 17, 18};
147static const u8 DME1737_BIT_ALARM_TEMP[] = {4, 5, 6}; 152static const u8 DME1737_BIT_ALARM_TEMP[] = {4, 5, 6};
148static const u8 DME1737_BIT_ALARM_FAN[] = {10, 11, 12, 13, 22, 23}; 153static const u8 DME1737_BIT_ALARM_FAN[] = {10, 11, 12, 13, 22, 23};
149 154
@@ -188,6 +193,7 @@ static const u8 DME1737_BIT_ALARM_FAN[] = {10, 11, 12, 13, 22, 23};
188#define HAS_PWM_MIN (1 << 4) /* bit 4 */ 193#define HAS_PWM_MIN (1 << 4) /* bit 4 */
189#define HAS_FAN(ix) (1 << ((ix) + 5)) /* bits 5-10 */ 194#define HAS_FAN(ix) (1 << ((ix) + 5)) /* bits 5-10 */
190#define HAS_PWM(ix) (1 << ((ix) + 11)) /* bits 11-16 */ 195#define HAS_PWM(ix) (1 << ((ix) + 11)) /* bits 11-16 */
196#define HAS_IN7 (1 << 17) /* bit 17 */
191 197
192/* --------------------------------------------------------------------- 198/* ---------------------------------------------------------------------
193 * Data structures and manipulation thereof 199 * Data structures and manipulation thereof
@@ -211,9 +217,9 @@ struct dme1737_data {
211 u32 has_features; 217 u32 has_features;
212 218
213 /* Register values */ 219 /* Register values */
214 u16 in[7]; 220 u16 in[8];
215 u8 in_min[7]; 221 u8 in_min[8];
216 u8 in_max[7]; 222 u8 in_max[8];
217 s16 temp[3]; 223 s16 temp[3];
218 s8 temp_min[3]; 224 s8 temp_min[3];
219 s8 temp_max[3]; 225 s8 temp_max[3];
@@ -245,7 +251,7 @@ static const int IN_NOMINAL_SCH311x[] = {2500, 1500, 3300, 5000, 12000, 3300,
245static const int IN_NOMINAL_SCH5027[] = {5000, 2250, 3300, 1125, 1125, 3300, 251static const int IN_NOMINAL_SCH5027[] = {5000, 2250, 3300, 1125, 1125, 3300,
246 3300}; 252 3300};
247static const int IN_NOMINAL_SCH5127[] = {2500, 2250, 3300, 1125, 1125, 3300, 253static const int IN_NOMINAL_SCH5127[] = {2500, 2250, 3300, 1125, 1125, 3300,
248 3300}; 254 3300, 1500};
249#define IN_NOMINAL(type) ((type) == sch311x ? IN_NOMINAL_SCH311x : \ 255#define IN_NOMINAL(type) ((type) == sch311x ? IN_NOMINAL_SCH311x : \
250 (type) == sch5027 ? IN_NOMINAL_SCH5027 : \ 256 (type) == sch5027 ? IN_NOMINAL_SCH5027 : \
251 (type) == sch5127 ? IN_NOMINAL_SCH5127 : \ 257 (type) == sch5127 ? IN_NOMINAL_SCH5127 : \
@@ -578,7 +584,7 @@ static struct dme1737_data *dme1737_update_device(struct device *dev)
578{ 584{
579 struct dme1737_data *data = dev_get_drvdata(dev); 585 struct dme1737_data *data = dev_get_drvdata(dev);
580 int ix; 586 int ix;
581 u8 lsb[5]; 587 u8 lsb[6];
582 588
583 mutex_lock(&data->update_lock); 589 mutex_lock(&data->update_lock);
584 590
@@ -601,6 +607,9 @@ static struct dme1737_data *dme1737_update_device(struct device *dev)
601 /* Voltage inputs are stored as 16 bit values even 607 /* Voltage inputs are stored as 16 bit values even
602 * though they have only 12 bits resolution. This is 608 * though they have only 12 bits resolution. This is
603 * to make it consistent with the temp inputs. */ 609 * to make it consistent with the temp inputs. */
610 if (ix == 7 && !(data->has_features & HAS_IN7)) {
611 continue;
612 }
604 data->in[ix] = dme1737_read(data, 613 data->in[ix] = dme1737_read(data,
605 DME1737_REG_IN(ix)) << 8; 614 DME1737_REG_IN(ix)) << 8;
606 data->in_min[ix] = dme1737_read(data, 615 data->in_min[ix] = dme1737_read(data,
@@ -633,10 +642,16 @@ static struct dme1737_data *dme1737_update_device(struct device *dev)
633 * which the registers are read (MSB first, then LSB) is 642 * which the registers are read (MSB first, then LSB) is
634 * important! */ 643 * important! */
635 for (ix = 0; ix < ARRAY_SIZE(lsb); ix++) { 644 for (ix = 0; ix < ARRAY_SIZE(lsb); ix++) {
645 if (ix == 5 && !(data->has_features & HAS_IN7)) {
646 continue;
647 }
636 lsb[ix] = dme1737_read(data, 648 lsb[ix] = dme1737_read(data,
637 DME1737_REG_IN_TEMP_LSB(ix)); 649 DME1737_REG_IN_TEMP_LSB(ix));
638 } 650 }
639 for (ix = 0; ix < ARRAY_SIZE(data->in); ix++) { 651 for (ix = 0; ix < ARRAY_SIZE(data->in); ix++) {
652 if (ix == 7 && !(data->has_features & HAS_IN7)) {
653 continue;
654 }
640 data->in[ix] |= (lsb[DME1737_REG_IN_LSB[ix]] << 655 data->in[ix] |= (lsb[DME1737_REG_IN_LSB[ix]] <<
641 DME1737_REG_IN_LSB_SHL[ix]) & 0xf0; 656 DME1737_REG_IN_LSB_SHL[ix]) & 0xf0;
642 } 657 }
@@ -760,7 +775,7 @@ static struct dme1737_data *dme1737_update_device(struct device *dev)
760 775
761/* --------------------------------------------------------------------- 776/* ---------------------------------------------------------------------
762 * Voltage sysfs attributes 777 * Voltage sysfs attributes
763 * ix = [0-5] 778 * ix = [0-7]
764 * --------------------------------------------------------------------- */ 779 * --------------------------------------------------------------------- */
765 780
766#define SYS_IN_INPUT 0 781#define SYS_IN_INPUT 0
@@ -1437,7 +1452,7 @@ static ssize_t show_name(struct device *dev, struct device_attribute *attr,
1437 * Sysfs device attribute defines and structs 1452 * Sysfs device attribute defines and structs
1438 * --------------------------------------------------------------------- */ 1453 * --------------------------------------------------------------------- */
1439 1454
1440/* Voltages 0-6 */ 1455/* Voltages 0-7 */
1441 1456
1442#define SENSOR_DEVICE_ATTR_IN(ix) \ 1457#define SENSOR_DEVICE_ATTR_IN(ix) \
1443static SENSOR_DEVICE_ATTR_2(in##ix##_input, S_IRUGO, \ 1458static SENSOR_DEVICE_ATTR_2(in##ix##_input, S_IRUGO, \
@@ -1456,6 +1471,7 @@ SENSOR_DEVICE_ATTR_IN(3);
1456SENSOR_DEVICE_ATTR_IN(4); 1471SENSOR_DEVICE_ATTR_IN(4);
1457SENSOR_DEVICE_ATTR_IN(5); 1472SENSOR_DEVICE_ATTR_IN(5);
1458SENSOR_DEVICE_ATTR_IN(6); 1473SENSOR_DEVICE_ATTR_IN(6);
1474SENSOR_DEVICE_ATTR_IN(7);
1459 1475
1460/* Temperatures 1-3 */ 1476/* Temperatures 1-3 */
1461 1477
@@ -1574,7 +1590,7 @@ static DEVICE_ATTR(name, S_IRUGO, show_name, NULL); /* for ISA devices */
1574 * created unconditionally. The attributes that need modification of their 1590 * created unconditionally. The attributes that need modification of their
1575 * permissions are created read-only and write permissions are added or removed 1591 * permissions are created read-only and write permissions are added or removed
1576 * on the fly when required */ 1592 * on the fly when required */
1577static struct attribute *dme1737_attr[] ={ 1593static struct attribute *dme1737_attr[] = {
1578 /* Voltages */ 1594 /* Voltages */
1579 &sensor_dev_attr_in0_input.dev_attr.attr, 1595 &sensor_dev_attr_in0_input.dev_attr.attr,
1580 &sensor_dev_attr_in0_min.dev_attr.attr, 1596 &sensor_dev_attr_in0_min.dev_attr.attr,
@@ -1679,7 +1695,7 @@ static const struct attribute_group dme1737_zone3_group = {
1679}; 1695};
1680 1696
1681 1697
1682/* The following struct holds temp zone hysteresis related attributes, which 1698/* The following struct holds temp zone hysteresis related attributes, which
1683 * are not available in all chips. The following chips support them: 1699 * are not available in all chips. The following chips support them:
1684 * DME1737, SCH311x */ 1700 * DME1737, SCH311x */
1685static struct attribute *dme1737_zone_hyst_attr[] = { 1701static struct attribute *dme1737_zone_hyst_attr[] = {
@@ -1693,6 +1709,21 @@ static const struct attribute_group dme1737_zone_hyst_group = {
1693 .attrs = dme1737_zone_hyst_attr, 1709 .attrs = dme1737_zone_hyst_attr,
1694}; 1710};
1695 1711
1712/* The following struct holds voltage in7 related attributes, which
1713 * are not available in all chips. The following chips support them:
1714 * SCH5127 */
1715static struct attribute *dme1737_in7_attr[] = {
1716 &sensor_dev_attr_in7_input.dev_attr.attr,
1717 &sensor_dev_attr_in7_min.dev_attr.attr,
1718 &sensor_dev_attr_in7_max.dev_attr.attr,
1719 &sensor_dev_attr_in7_alarm.dev_attr.attr,
1720 NULL
1721};
1722
1723static const struct attribute_group dme1737_in7_group = {
1724 .attrs = dme1737_in7_attr,
1725};
1726
1696/* The following structs hold the PWM attributes, some of which are optional. 1727/* The following structs hold the PWM attributes, some of which are optional.
1697 * Their creation depends on the chip configuration which is determined during 1728 * Their creation depends on the chip configuration which is determined during
1698 * module load. */ 1729 * module load. */
@@ -1984,6 +2015,9 @@ static void dme1737_remove_files(struct device *dev)
1984 if (data->has_features & HAS_ZONE_HYST) { 2015 if (data->has_features & HAS_ZONE_HYST) {
1985 sysfs_remove_group(&dev->kobj, &dme1737_zone_hyst_group); 2016 sysfs_remove_group(&dev->kobj, &dme1737_zone_hyst_group);
1986 } 2017 }
2018 if (data->has_features & HAS_IN7) {
2019 sysfs_remove_group(&dev->kobj, &dme1737_in7_group);
2020 }
1987 sysfs_remove_group(&dev->kobj, &dme1737_group); 2021 sysfs_remove_group(&dev->kobj, &dme1737_group);
1988 2022
1989 if (!data->client) { 2023 if (!data->client) {
@@ -1997,43 +2031,58 @@ static int dme1737_create_files(struct device *dev)
1997 int err, ix; 2031 int err, ix;
1998 2032
1999 /* Create a name attribute for ISA devices */ 2033 /* Create a name attribute for ISA devices */
2000 if (!data->client && 2034 if (!data->client) {
2001 (err = sysfs_create_file(&dev->kobj, &dev_attr_name.attr))) { 2035 err = sysfs_create_file(&dev->kobj, &dev_attr_name.attr);
2002 goto exit; 2036 if (err) {
2037 goto exit;
2038 }
2003 } 2039 }
2004 2040
2005 /* Create standard sysfs attributes */ 2041 /* Create standard sysfs attributes */
2006 if ((err = sysfs_create_group(&dev->kobj, &dme1737_group))) { 2042 err = sysfs_create_group(&dev->kobj, &dme1737_group);
2043 if (err) {
2007 goto exit_remove; 2044 goto exit_remove;
2008 } 2045 }
2009 2046
2010 /* Create chip-dependent sysfs attributes */ 2047 /* Create chip-dependent sysfs attributes */
2011 if ((data->has_features & HAS_TEMP_OFFSET) && 2048 if (data->has_features & HAS_TEMP_OFFSET) {
2012 (err = sysfs_create_group(&dev->kobj, 2049 err = sysfs_create_group(&dev->kobj,
2013 &dme1737_temp_offset_group))) { 2050 &dme1737_temp_offset_group);
2014 goto exit_remove; 2051 if (err) {
2052 goto exit_remove;
2053 }
2015 } 2054 }
2016 if ((data->has_features & HAS_VID) && 2055 if (data->has_features & HAS_VID) {
2017 (err = sysfs_create_group(&dev->kobj, 2056 err = sysfs_create_group(&dev->kobj, &dme1737_vid_group);
2018 &dme1737_vid_group))) { 2057 if (err) {
2019 goto exit_remove; 2058 goto exit_remove;
2059 }
2020 } 2060 }
2021 if ((data->has_features & HAS_ZONE3) && 2061 if (data->has_features & HAS_ZONE3) {
2022 (err = sysfs_create_group(&dev->kobj, 2062 err = sysfs_create_group(&dev->kobj, &dme1737_zone3_group);
2023 &dme1737_zone3_group))) { 2063 if (err) {
2024 goto exit_remove; 2064 goto exit_remove;
2065 }
2025 } 2066 }
2026 if ((data->has_features & HAS_ZONE_HYST) && 2067 if (data->has_features & HAS_ZONE_HYST) {
2027 (err = sysfs_create_group(&dev->kobj, 2068 err = sysfs_create_group(&dev->kobj, &dme1737_zone_hyst_group);
2028 &dme1737_zone_hyst_group))) { 2069 if (err) {
2029 goto exit_remove; 2070 goto exit_remove;
2071 }
2072 }
2073 if (data->has_features & HAS_IN7) {
2074 err = sysfs_create_group(&dev->kobj, &dme1737_in7_group);
2075 if (err) {
2076 goto exit_remove;
2077 }
2030 } 2078 }
2031 2079
2032 /* Create fan sysfs attributes */ 2080 /* Create fan sysfs attributes */
2033 for (ix = 0; ix < ARRAY_SIZE(dme1737_fan_group); ix++) { 2081 for (ix = 0; ix < ARRAY_SIZE(dme1737_fan_group); ix++) {
2034 if (data->has_features & HAS_FAN(ix)) { 2082 if (data->has_features & HAS_FAN(ix)) {
2035 if ((err = sysfs_create_group(&dev->kobj, 2083 err = sysfs_create_group(&dev->kobj,
2036 &dme1737_fan_group[ix]))) { 2084 &dme1737_fan_group[ix]);
2085 if (err) {
2037 goto exit_remove; 2086 goto exit_remove;
2038 } 2087 }
2039 } 2088 }
@@ -2042,14 +2091,17 @@ static int dme1737_create_files(struct device *dev)
2042 /* Create PWM sysfs attributes */ 2091 /* Create PWM sysfs attributes */
2043 for (ix = 0; ix < ARRAY_SIZE(dme1737_pwm_group); ix++) { 2092 for (ix = 0; ix < ARRAY_SIZE(dme1737_pwm_group); ix++) {
2044 if (data->has_features & HAS_PWM(ix)) { 2093 if (data->has_features & HAS_PWM(ix)) {
2045 if ((err = sysfs_create_group(&dev->kobj, 2094 err = sysfs_create_group(&dev->kobj,
2046 &dme1737_pwm_group[ix]))) { 2095 &dme1737_pwm_group[ix]);
2096 if (err) {
2047 goto exit_remove; 2097 goto exit_remove;
2048 } 2098 }
2049 if ((data->has_features & HAS_PWM_MIN) && ix < 3 && 2099 if ((data->has_features & HAS_PWM_MIN) && (ix < 3)) {
2050 (err = sysfs_create_file(&dev->kobj, 2100 err = sysfs_create_file(&dev->kobj,
2051 dme1737_auto_pwm_min_attr[ix]))) { 2101 dme1737_auto_pwm_min_attr[ix]);
2052 goto exit_remove; 2102 if (err) {
2103 goto exit_remove;
2104 }
2053 } 2105 }
2054 } 2106 }
2055 } 2107 }
@@ -2186,7 +2238,7 @@ static int dme1737_init_device(struct device *dev)
2186 data->has_features |= HAS_ZONE3; 2238 data->has_features |= HAS_ZONE3;
2187 break; 2239 break;
2188 case sch5127: 2240 case sch5127:
2189 data->has_features |= HAS_FAN(2) | HAS_PWM(2); 2241 data->has_features |= HAS_FAN(2) | HAS_PWM(2) | HAS_IN7;
2190 break; 2242 break;
2191 default: 2243 default:
2192 break; 2244 break;
@@ -2279,8 +2331,9 @@ static int dme1737_i2c_get_features(int sio_cip, struct dme1737_data *data)
2279 dme1737_sio_outb(sio_cip, 0x07, 0x0a); 2331 dme1737_sio_outb(sio_cip, 0x07, 0x0a);
2280 2332
2281 /* Get the base address of the runtime registers */ 2333 /* Get the base address of the runtime registers */
2282 if (!(addr = (dme1737_sio_inb(sio_cip, 0x60) << 8) | 2334 addr = (dme1737_sio_inb(sio_cip, 0x60) << 8) |
2283 dme1737_sio_inb(sio_cip, 0x61))) { 2335 dme1737_sio_inb(sio_cip, 0x61);
2336 if (!addr) {
2284 err = -ENODEV; 2337 err = -ENODEV;
2285 goto exit; 2338 goto exit;
2286 } 2339 }
@@ -2361,13 +2414,15 @@ static int dme1737_i2c_probe(struct i2c_client *client,
2361 mutex_init(&data->update_lock); 2414 mutex_init(&data->update_lock);
2362 2415
2363 /* Initialize the DME1737 chip */ 2416 /* Initialize the DME1737 chip */
2364 if ((err = dme1737_init_device(dev))) { 2417 err = dme1737_init_device(dev);
2418 if (err) {
2365 dev_err(dev, "Failed to initialize device.\n"); 2419 dev_err(dev, "Failed to initialize device.\n");
2366 goto exit_kfree; 2420 goto exit_kfree;
2367 } 2421 }
2368 2422
2369 /* Create sysfs files */ 2423 /* Create sysfs files */
2370 if ((err = dme1737_create_files(dev))) { 2424 err = dme1737_create_files(dev);
2425 if (err) {
2371 dev_err(dev, "Failed to create sysfs files.\n"); 2426 dev_err(dev, "Failed to create sysfs files.\n");
2372 goto exit_kfree; 2427 goto exit_kfree;
2373 } 2428 }
@@ -2444,9 +2499,10 @@ static int __init dme1737_isa_detect(int sio_cip, unsigned short *addr)
2444 dme1737_sio_outb(sio_cip, 0x07, 0x0a); 2499 dme1737_sio_outb(sio_cip, 0x07, 0x0a);
2445 2500
2446 /* Get the base address of the runtime registers */ 2501 /* Get the base address of the runtime registers */
2447 if (!(base_addr = (dme1737_sio_inb(sio_cip, 0x60) << 8) | 2502 base_addr = (dme1737_sio_inb(sio_cip, 0x60) << 8) |
2448 dme1737_sio_inb(sio_cip, 0x61))) { 2503 dme1737_sio_inb(sio_cip, 0x61);
2449 printk(KERN_ERR "dme1737: Base address not set.\n"); 2504 if (!base_addr) {
2505 pr_err("Base address not set\n");
2450 err = -ENODEV; 2506 err = -ENODEV;
2451 goto exit; 2507 goto exit;
2452 } 2508 }
@@ -2474,21 +2530,22 @@ static int __init dme1737_isa_device_add(unsigned short addr)
2474 if (err) 2530 if (err)
2475 goto exit; 2531 goto exit;
2476 2532
2477 if (!(pdev = platform_device_alloc("dme1737", addr))) { 2533 pdev = platform_device_alloc("dme1737", addr);
2478 printk(KERN_ERR "dme1737: Failed to allocate device.\n"); 2534 if (!pdev) {
2535 pr_err("Failed to allocate device\n");
2479 err = -ENOMEM; 2536 err = -ENOMEM;
2480 goto exit; 2537 goto exit;
2481 } 2538 }
2482 2539
2483 if ((err = platform_device_add_resources(pdev, &res, 1))) { 2540 err = platform_device_add_resources(pdev, &res, 1);
2484 printk(KERN_ERR "dme1737: Failed to add device resource " 2541 if (err) {
2485 "(err = %d).\n", err); 2542 pr_err("Failed to add device resource (err = %d)\n", err);
2486 goto exit_device_put; 2543 goto exit_device_put;
2487 } 2544 }
2488 2545
2489 if ((err = platform_device_add(pdev))) { 2546 err = platform_device_add(pdev);
2490 printk(KERN_ERR "dme1737: Failed to add device (err = %d).\n", 2547 if (err) {
2491 err); 2548 pr_err("Failed to add device (err = %d)\n", err);
2492 goto exit_device_put; 2549 goto exit_device_put;
2493 } 2550 }
2494 2551
@@ -2514,11 +2571,12 @@ static int __devinit dme1737_isa_probe(struct platform_device *pdev)
2514 dev_err(dev, "Failed to request region 0x%04x-0x%04x.\n", 2571 dev_err(dev, "Failed to request region 0x%04x-0x%04x.\n",
2515 (unsigned short)res->start, 2572 (unsigned short)res->start,
2516 (unsigned short)res->start + DME1737_EXTENT - 1); 2573 (unsigned short)res->start + DME1737_EXTENT - 1);
2517 err = -EBUSY; 2574 err = -EBUSY;
2518 goto exit; 2575 goto exit;
2519 } 2576 }
2520 2577
2521 if (!(data = kzalloc(sizeof(struct dme1737_data), GFP_KERNEL))) { 2578 data = kzalloc(sizeof(struct dme1737_data), GFP_KERNEL);
2579 if (!data) {
2522 err = -ENOMEM; 2580 err = -ENOMEM;
2523 goto exit_release_region; 2581 goto exit_release_region;
2524 } 2582 }
@@ -2565,13 +2623,15 @@ static int __devinit dme1737_isa_probe(struct platform_device *pdev)
2565 data->type == sch5127 ? "SCH5127" : "SCH311x", data->addr); 2623 data->type == sch5127 ? "SCH5127" : "SCH311x", data->addr);
2566 2624
2567 /* Initialize the chip */ 2625 /* Initialize the chip */
2568 if ((err = dme1737_init_device(dev))) { 2626 err = dme1737_init_device(dev);
2627 if (err) {
2569 dev_err(dev, "Failed to initialize device.\n"); 2628 dev_err(dev, "Failed to initialize device.\n");
2570 goto exit_kfree; 2629 goto exit_kfree;
2571 } 2630 }
2572 2631
2573 /* Create sysfs files */ 2632 /* Create sysfs files */
2574 if ((err = dme1737_create_files(dev))) { 2633 err = dme1737_create_files(dev);
2634 if (err) {
2575 dev_err(dev, "Failed to create sysfs files.\n"); 2635 dev_err(dev, "Failed to create sysfs files.\n");
2576 goto exit_kfree; 2636 goto exit_kfree;
2577 } 2637 }
@@ -2628,7 +2688,8 @@ static int __init dme1737_init(void)
2628 int err; 2688 int err;
2629 unsigned short addr; 2689 unsigned short addr;
2630 2690
2631 if ((err = i2c_add_driver(&dme1737_i2c_driver))) { 2691 err = i2c_add_driver(&dme1737_i2c_driver);
2692 if (err) {
2632 goto exit; 2693 goto exit;
2633 } 2694 }
2634 2695
@@ -2641,12 +2702,14 @@ static int __init dme1737_init(void)
2641 return 0; 2702 return 0;
2642 } 2703 }
2643 2704
2644 if ((err = platform_driver_register(&dme1737_isa_driver))) { 2705 err = platform_driver_register(&dme1737_isa_driver);
2706 if (err) {
2645 goto exit_del_i2c_driver; 2707 goto exit_del_i2c_driver;
2646 } 2708 }
2647 2709
2648 /* Sets global pdev as a side effect */ 2710 /* Sets global pdev as a side effect */
2649 if ((err = dme1737_isa_device_add(addr))) { 2711 err = dme1737_isa_device_add(addr);
2712 if (err) {
2650 goto exit_del_isa_driver; 2713 goto exit_del_isa_driver;
2651 } 2714 }
2652 2715
diff --git a/drivers/hwmon/ds620.c b/drivers/hwmon/ds620.c
new file mode 100644
index 000000000000..257957c69d92
--- /dev/null
+++ b/drivers/hwmon/ds620.c
@@ -0,0 +1,337 @@
1/*
2 * ds620.c - Support for temperature sensor and thermostat DS620
3 *
4 * Copyright (C) 2010, 2011 Roland Stigge <stigge@antcom.de>
5 *
6 * based on ds1621.c by Christian W. Zuckschwerdt <zany@triq.net>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23#include <linux/module.h>
24#include <linux/init.h>
25#include <linux/slab.h>
26#include <linux/jiffies.h>
27#include <linux/i2c.h>
28#include <linux/hwmon.h>
29#include <linux/hwmon-sysfs.h>
30#include <linux/err.h>
31#include <linux/mutex.h>
32#include <linux/sysfs.h>
33#include <linux/i2c/ds620.h>
34
35/*
36 * Many DS620 constants specified below
37 * 15 14 13 12 11 10 09 08
38 * |Done|NVB |THF |TLF |R1 |R0 |AUTOC|1SHOT|
39 *
40 * 07 06 05 04 03 02 01 00
41 * |PO2 |PO1 |A2 |A1 |A0 | | | |
42 */
43#define DS620_REG_CONFIG_DONE 0x8000
44#define DS620_REG_CONFIG_NVB 0x4000
45#define DS620_REG_CONFIG_THF 0x2000
46#define DS620_REG_CONFIG_TLF 0x1000
47#define DS620_REG_CONFIG_R1 0x0800
48#define DS620_REG_CONFIG_R0 0x0400
49#define DS620_REG_CONFIG_AUTOC 0x0200
50#define DS620_REG_CONFIG_1SHOT 0x0100
51#define DS620_REG_CONFIG_PO2 0x0080
52#define DS620_REG_CONFIG_PO1 0x0040
53#define DS620_REG_CONFIG_A2 0x0020
54#define DS620_REG_CONFIG_A1 0x0010
55#define DS620_REG_CONFIG_A0 0x0008
56
57/* The DS620 registers */
58static const u8 DS620_REG_TEMP[3] = {
59 0xAA, /* input, word, RO */
60 0xA2, /* min, word, RW */
61 0xA0, /* max, word, RW */
62};
63
64#define DS620_REG_CONF 0xAC /* word, RW */
65#define DS620_COM_START 0x51 /* no data */
66#define DS620_COM_STOP 0x22 /* no data */
67
68/* Each client has this additional data */
69struct ds620_data {
70 struct device *hwmon_dev;
71 struct mutex update_lock;
72 char valid; /* !=0 if following fields are valid */
73 unsigned long last_updated; /* In jiffies */
74
75 u16 temp[3]; /* Register values, word */
76};
77
78/*
79 * Temperature registers are word-sized.
80 * DS620 uses a high-byte first convention, which is exactly opposite to
81 * the SMBus standard.
82 */
83static int ds620_read_temp(struct i2c_client *client, u8 reg)
84{
85 int ret;
86
87 ret = i2c_smbus_read_word_data(client, reg);
88 if (ret < 0)
89 return ret;
90 return swab16(ret);
91}
92
93static int ds620_write_temp(struct i2c_client *client, u8 reg, u16 value)
94{
95 return i2c_smbus_write_word_data(client, reg, swab16(value));
96}
97
98static void ds620_init_client(struct i2c_client *client)
99{
100 struct ds620_platform_data *ds620_info = client->dev.platform_data;
101 u16 conf, new_conf;
102
103 new_conf = conf =
104 swab16(i2c_smbus_read_word_data(client, DS620_REG_CONF));
105
106 /* switch to continuous conversion mode */
107 new_conf &= ~DS620_REG_CONFIG_1SHOT;
108 /* already high at power-on, but don't trust the BIOS! */
109 new_conf |= DS620_REG_CONFIG_PO2;
110 /* thermostat mode according to platform data */
111 if (ds620_info && ds620_info->pomode == 1)
112 new_conf &= ~DS620_REG_CONFIG_PO1; /* PO_LOW */
113 else if (ds620_info && ds620_info->pomode == 2)
114 new_conf |= DS620_REG_CONFIG_PO1; /* PO_HIGH */
115 else
116 new_conf &= ~DS620_REG_CONFIG_PO2; /* always low */
117 /* with highest precision */
118 new_conf |= DS620_REG_CONFIG_R1 | DS620_REG_CONFIG_R0;
119
120 if (conf != new_conf)
121 i2c_smbus_write_word_data(client, DS620_REG_CONF,
122 swab16(new_conf));
123
124 /* start conversion */
125 i2c_smbus_write_byte(client, DS620_COM_START);
126}
127
128static struct ds620_data *ds620_update_client(struct device *dev)
129{
130 struct i2c_client *client = to_i2c_client(dev);
131 struct ds620_data *data = i2c_get_clientdata(client);
132 struct ds620_data *ret = data;
133
134 mutex_lock(&data->update_lock);
135
136 if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
137 || !data->valid) {
138 int i;
139 int res;
140
141 dev_dbg(&client->dev, "Starting ds620 update\n");
142
143 for (i = 0; i < ARRAY_SIZE(data->temp); i++) {
144 res = ds620_read_temp(client,
145 DS620_REG_TEMP[i]);
146 if (res < 0) {
147 ret = ERR_PTR(res);
148 goto abort;
149 }
150
151 data->temp[i] = res;
152 }
153
154 data->last_updated = jiffies;
155 data->valid = 1;
156 }
157abort:
158 mutex_unlock(&data->update_lock);
159
160 return ret;
161}
162
163static ssize_t show_temp(struct device *dev, struct device_attribute *da,
164 char *buf)
165{
166 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
167 struct ds620_data *data = ds620_update_client(dev);
168
169 if (IS_ERR(data))
170 return PTR_ERR(data);
171
172 return sprintf(buf, "%d\n", ((data->temp[attr->index] / 8) * 625) / 10);
173}
174
175static ssize_t set_temp(struct device *dev, struct device_attribute *da,
176 const char *buf, size_t count)
177{
178 int res;
179 long val;
180
181 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
182 struct i2c_client *client = to_i2c_client(dev);
183 struct ds620_data *data = i2c_get_clientdata(client);
184
185 res = strict_strtol(buf, 10, &val);
186
187 if (res)
188 return res;
189
190 val = (val * 10 / 625) * 8;
191
192 mutex_lock(&data->update_lock);
193 data->temp[attr->index] = val;
194 ds620_write_temp(client, DS620_REG_TEMP[attr->index],
195 data->temp[attr->index]);
196 mutex_unlock(&data->update_lock);
197 return count;
198}
199
200static ssize_t show_alarm(struct device *dev, struct device_attribute *da,
201 char *buf)
202{
203 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
204 struct ds620_data *data = ds620_update_client(dev);
205 struct i2c_client *client = to_i2c_client(dev);
206 u16 conf, new_conf;
207 int res;
208
209 if (IS_ERR(data))
210 return PTR_ERR(data);
211
212 /* reset alarms if necessary */
213 res = i2c_smbus_read_word_data(client, DS620_REG_CONF);
214 if (res < 0)
215 return res;
216
217 conf = swab16(res);
218 new_conf = conf;
219 new_conf &= ~attr->index;
220 if (conf != new_conf) {
221 res = i2c_smbus_write_word_data(client, DS620_REG_CONF,
222 swab16(new_conf));
223 if (res < 0)
224 return res;
225 }
226
227 return sprintf(buf, "%d\n", !!(conf & attr->index));
228}
229
230static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0);
231static SENSOR_DEVICE_ATTR(temp1_min, S_IWUSR | S_IRUGO, show_temp, set_temp, 1);
232static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp, set_temp, 2);
233static SENSOR_DEVICE_ATTR(temp1_min_alarm, S_IRUGO, show_alarm, NULL,
234 DS620_REG_CONFIG_TLF);
235static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL,
236 DS620_REG_CONFIG_THF);
237
238static struct attribute *ds620_attributes[] = {
239 &sensor_dev_attr_temp1_input.dev_attr.attr,
240 &sensor_dev_attr_temp1_min.dev_attr.attr,
241 &sensor_dev_attr_temp1_max.dev_attr.attr,
242 &sensor_dev_attr_temp1_min_alarm.dev_attr.attr,
243 &sensor_dev_attr_temp1_max_alarm.dev_attr.attr,
244 NULL
245};
246
247static const struct attribute_group ds620_group = {
248 .attrs = ds620_attributes,
249};
250
251static int ds620_probe(struct i2c_client *client,
252 const struct i2c_device_id *id)
253{
254 struct ds620_data *data;
255 int err;
256
257 data = kzalloc(sizeof(struct ds620_data), GFP_KERNEL);
258 if (!data) {
259 err = -ENOMEM;
260 goto exit;
261 }
262
263 i2c_set_clientdata(client, data);
264 mutex_init(&data->update_lock);
265
266 /* Initialize the DS620 chip */
267 ds620_init_client(client);
268
269 /* Register sysfs hooks */
270 err = sysfs_create_group(&client->dev.kobj, &ds620_group);
271 if (err)
272 goto exit_free;
273
274 data->hwmon_dev = hwmon_device_register(&client->dev);
275 if (IS_ERR(data->hwmon_dev)) {
276 err = PTR_ERR(data->hwmon_dev);
277 goto exit_remove_files;
278 }
279
280 dev_info(&client->dev, "temperature sensor found\n");
281
282 return 0;
283
284exit_remove_files:
285 sysfs_remove_group(&client->dev.kobj, &ds620_group);
286exit_free:
287 kfree(data);
288exit:
289 return err;
290}
291
292static int ds620_remove(struct i2c_client *client)
293{
294 struct ds620_data *data = i2c_get_clientdata(client);
295
296 hwmon_device_unregister(data->hwmon_dev);
297 sysfs_remove_group(&client->dev.kobj, &ds620_group);
298
299 kfree(data);
300
301 return 0;
302}
303
304static const struct i2c_device_id ds620_id[] = {
305 {"ds620", 0},
306 {}
307};
308
309MODULE_DEVICE_TABLE(i2c, ds620_id);
310
311/* This is the driver that will be inserted */
312static struct i2c_driver ds620_driver = {
313 .class = I2C_CLASS_HWMON,
314 .driver = {
315 .name = "ds620",
316 },
317 .probe = ds620_probe,
318 .remove = ds620_remove,
319 .id_table = ds620_id,
320};
321
322static int __init ds620_init(void)
323{
324 return i2c_add_driver(&ds620_driver);
325}
326
327static void __exit ds620_exit(void)
328{
329 i2c_del_driver(&ds620_driver);
330}
331
332MODULE_AUTHOR("Roland Stigge <stigge@antcom.de>");
333MODULE_DESCRIPTION("DS620 driver");
334MODULE_LICENSE("GPL");
335
336module_init(ds620_init);
337module_exit(ds620_exit);
diff --git a/drivers/hwmon/emc1403.c b/drivers/hwmon/emc1403.c
index 8dee3f38fdfb..5dea9faa1656 100644
--- a/drivers/hwmon/emc1403.c
+++ b/drivers/hwmon/emc1403.c
@@ -269,23 +269,30 @@ static int emc1403_detect(struct i2c_client *client,
269 struct i2c_board_info *info) 269 struct i2c_board_info *info)
270{ 270{
271 int id; 271 int id;
272 /* Check if thermal chip is SMSC and EMC1403 */ 272 /* Check if thermal chip is SMSC and EMC1403 or EMC1423 */
273 273
274 id = i2c_smbus_read_byte_data(client, THERMAL_SMSC_ID_REG); 274 id = i2c_smbus_read_byte_data(client, THERMAL_SMSC_ID_REG);
275 if (id != 0x5d) 275 if (id != 0x5d)
276 return -ENODEV; 276 return -ENODEV;
277 277
278 id = i2c_smbus_read_byte_data(client, THERMAL_PID_REG);
279 switch (id) {
280 case 0x21:
281 strlcpy(info->type, "emc1403", I2C_NAME_SIZE);
282 break;
283 case 0x23:
284 strlcpy(info->type, "emc1423", I2C_NAME_SIZE);
285 break;
278 /* Note: 0x25 is the 1404 which is very similar and this 286 /* Note: 0x25 is the 1404 which is very similar and this
279 driver could be extended */ 287 driver could be extended */
280 id = i2c_smbus_read_byte_data(client, THERMAL_PID_REG); 288 default:
281 if (id != 0x21)
282 return -ENODEV; 289 return -ENODEV;
290 }
283 291
284 id = i2c_smbus_read_byte_data(client, THERMAL_REVISION_REG); 292 id = i2c_smbus_read_byte_data(client, THERMAL_REVISION_REG);
285 if (id != 0x01) 293 if (id != 0x01)
286 return -ENODEV; 294 return -ENODEV;
287 295
288 strlcpy(info->type, "emc1403", I2C_NAME_SIZE);
289 return 0; 296 return 0;
290} 297}
291 298
@@ -342,6 +349,7 @@ static const unsigned short emc1403_address_list[] = {
342 349
343static const struct i2c_device_id emc1403_idtable[] = { 350static const struct i2c_device_id emc1403_idtable[] = {
344 { "emc1403", 0 }, 351 { "emc1403", 0 },
352 { "emc1423", 0 },
345 { } 353 { }
346}; 354};
347MODULE_DEVICE_TABLE(i2c, emc1403_idtable); 355MODULE_DEVICE_TABLE(i2c, emc1403_idtable);
diff --git a/drivers/hwmon/f71805f.c b/drivers/hwmon/f71805f.c
index 525a00bd70b1..92f949767ece 100644
--- a/drivers/hwmon/f71805f.c
+++ b/drivers/hwmon/f71805f.c
@@ -28,6 +28,8 @@
28 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 28 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 */ 29 */
30 30
31#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
32
31#include <linux/module.h> 33#include <linux/module.h>
32#include <linux/init.h> 34#include <linux/init.h>
33#include <linux/slab.h> 35#include <linux/slab.h>
@@ -1309,7 +1311,7 @@ static int __devinit f71805f_probe(struct platform_device *pdev)
1309 1311
1310 if (!(data = kzalloc(sizeof(struct f71805f_data), GFP_KERNEL))) { 1312 if (!(data = kzalloc(sizeof(struct f71805f_data), GFP_KERNEL))) {
1311 err = -ENOMEM; 1313 err = -ENOMEM;
1312 printk(KERN_ERR DRVNAME ": Out of memory\n"); 1314 pr_err("Out of memory\n");
1313 goto exit; 1315 goto exit;
1314 } 1316 }
1315 1317
@@ -1451,7 +1453,7 @@ static int __init f71805f_device_add(unsigned short address,
1451 pdev = platform_device_alloc(DRVNAME, address); 1453 pdev = platform_device_alloc(DRVNAME, address);
1452 if (!pdev) { 1454 if (!pdev) {
1453 err = -ENOMEM; 1455 err = -ENOMEM;
1454 printk(KERN_ERR DRVNAME ": Device allocation failed\n"); 1456 pr_err("Device allocation failed\n");
1455 goto exit; 1457 goto exit;
1456 } 1458 }
1457 1459
@@ -1462,22 +1464,20 @@ static int __init f71805f_device_add(unsigned short address,
1462 1464
1463 err = platform_device_add_resources(pdev, &res, 1); 1465 err = platform_device_add_resources(pdev, &res, 1);
1464 if (err) { 1466 if (err) {
1465 printk(KERN_ERR DRVNAME ": Device resource addition failed " 1467 pr_err("Device resource addition failed (%d)\n", err);
1466 "(%d)\n", err);
1467 goto exit_device_put; 1468 goto exit_device_put;
1468 } 1469 }
1469 1470
1470 err = platform_device_add_data(pdev, sio_data, 1471 err = platform_device_add_data(pdev, sio_data,
1471 sizeof(struct f71805f_sio_data)); 1472 sizeof(struct f71805f_sio_data));
1472 if (err) { 1473 if (err) {
1473 printk(KERN_ERR DRVNAME ": Platform data allocation failed\n"); 1474 pr_err("Platform data allocation failed\n");
1474 goto exit_device_put; 1475 goto exit_device_put;
1475 } 1476 }
1476 1477
1477 err = platform_device_add(pdev); 1478 err = platform_device_add(pdev);
1478 if (err) { 1479 if (err) {
1479 printk(KERN_ERR DRVNAME ": Device addition failed (%d)\n", 1480 pr_err("Device addition failed (%d)\n", err);
1480 err);
1481 goto exit_device_put; 1481 goto exit_device_put;
1482 } 1482 }
1483 1483
@@ -1516,30 +1516,27 @@ static int __init f71805f_find(int sioaddr, unsigned short *address,
1516 sio_data->fnsel1 = superio_inb(sioaddr, SIO_REG_FNSEL1); 1516 sio_data->fnsel1 = superio_inb(sioaddr, SIO_REG_FNSEL1);
1517 break; 1517 break;
1518 default: 1518 default:
1519 printk(KERN_INFO DRVNAME ": Unsupported Fintek device, " 1519 pr_info("Unsupported Fintek device, skipping\n");
1520 "skipping\n");
1521 goto exit; 1520 goto exit;
1522 } 1521 }
1523 1522
1524 superio_select(sioaddr, F71805F_LD_HWM); 1523 superio_select(sioaddr, F71805F_LD_HWM);
1525 if (!(superio_inb(sioaddr, SIO_REG_ENABLE) & 0x01)) { 1524 if (!(superio_inb(sioaddr, SIO_REG_ENABLE) & 0x01)) {
1526 printk(KERN_WARNING DRVNAME ": Device not activated, " 1525 pr_warn("Device not activated, skipping\n");
1527 "skipping\n");
1528 goto exit; 1526 goto exit;
1529 } 1527 }
1530 1528
1531 *address = superio_inw(sioaddr, SIO_REG_ADDR); 1529 *address = superio_inw(sioaddr, SIO_REG_ADDR);
1532 if (*address == 0) { 1530 if (*address == 0) {
1533 printk(KERN_WARNING DRVNAME ": Base address not set, " 1531 pr_warn("Base address not set, skipping\n");
1534 "skipping\n");
1535 goto exit; 1532 goto exit;
1536 } 1533 }
1537 *address &= ~(REGION_LENGTH - 1); /* Ignore 3 LSB */ 1534 *address &= ~(REGION_LENGTH - 1); /* Ignore 3 LSB */
1538 1535
1539 err = 0; 1536 err = 0;
1540 printk(KERN_INFO DRVNAME ": Found %s chip at %#x, revision %u\n", 1537 pr_info("Found %s chip at %#x, revision %u\n",
1541 names[sio_data->kind], *address, 1538 names[sio_data->kind], *address,
1542 superio_inb(sioaddr, SIO_REG_DEVREV)); 1539 superio_inb(sioaddr, SIO_REG_DEVREV));
1543 1540
1544exit: 1541exit:
1545 superio_exit(sioaddr); 1542 superio_exit(sioaddr);
diff --git a/drivers/hwmon/f71882fg.c b/drivers/hwmon/f71882fg.c
index 75afb3b0e076..3f49dd376f02 100644
--- a/drivers/hwmon/f71882fg.c
+++ b/drivers/hwmon/f71882fg.c
@@ -18,6 +18,8 @@
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/ 19 ***************************************************************************/
20 20
21#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
22
21#include <linux/module.h> 23#include <linux/module.h>
22#include <linux/init.h> 24#include <linux/init.h>
23#include <linux/slab.h> 25#include <linux/slab.h>
@@ -865,8 +867,7 @@ static inline int superio_enter(int base)
865{ 867{
866 /* Don't step on other drivers' I/O space by accident */ 868 /* Don't step on other drivers' I/O space by accident */
867 if (!request_muxed_region(base, 2, DRVNAME)) { 869 if (!request_muxed_region(base, 2, DRVNAME)) {
868 printk(KERN_ERR DRVNAME ": I/O address 0x%04x already in use\n", 870 pr_err("I/O address 0x%04x already in use\n", base);
869 base);
870 return -EBUSY; 871 return -EBUSY;
871 } 872 }
872 873
@@ -2192,7 +2193,7 @@ static int __init f71882fg_find(int sioaddr, unsigned short *address,
2192 2193
2193 devid = superio_inw(sioaddr, SIO_REG_MANID); 2194 devid = superio_inw(sioaddr, SIO_REG_MANID);
2194 if (devid != SIO_FINTEK_ID) { 2195 if (devid != SIO_FINTEK_ID) {
2195 pr_debug(DRVNAME ": Not a Fintek device\n"); 2196 pr_debug("Not a Fintek device\n");
2196 err = -ENODEV; 2197 err = -ENODEV;
2197 goto exit; 2198 goto exit;
2198 } 2199 }
@@ -2215,8 +2216,8 @@ static int __init f71882fg_find(int sioaddr, unsigned short *address,
2215 sio_data->type = f8000; 2216 sio_data->type = f8000;
2216 break; 2217 break;
2217 default: 2218 default:
2218 printk(KERN_INFO DRVNAME ": Unsupported Fintek device: %04x\n", 2219 pr_info("Unsupported Fintek device: %04x\n",
2219 (unsigned int)devid); 2220 (unsigned int)devid);
2220 err = -ENODEV; 2221 err = -ENODEV;
2221 goto exit; 2222 goto exit;
2222 } 2223 }
@@ -2227,21 +2228,21 @@ static int __init f71882fg_find(int sioaddr, unsigned short *address,
2227 superio_select(sioaddr, SIO_F71882FG_LD_HWM); 2228 superio_select(sioaddr, SIO_F71882FG_LD_HWM);
2228 2229
2229 if (!(superio_inb(sioaddr, SIO_REG_ENABLE) & 0x01)) { 2230 if (!(superio_inb(sioaddr, SIO_REG_ENABLE) & 0x01)) {
2230 printk(KERN_WARNING DRVNAME ": Device not activated\n"); 2231 pr_warn("Device not activated\n");
2231 err = -ENODEV; 2232 err = -ENODEV;
2232 goto exit; 2233 goto exit;
2233 } 2234 }
2234 2235
2235 *address = superio_inw(sioaddr, SIO_REG_ADDR); 2236 *address = superio_inw(sioaddr, SIO_REG_ADDR);
2236 if (*address == 0) { 2237 if (*address == 0) {
2237 printk(KERN_WARNING DRVNAME ": Base address not set\n"); 2238 pr_warn("Base address not set\n");
2238 err = -ENODEV; 2239 err = -ENODEV;
2239 goto exit; 2240 goto exit;
2240 } 2241 }
2241 *address &= ~(REGION_LENGTH - 1); /* Ignore 3 LSB */ 2242 *address &= ~(REGION_LENGTH - 1); /* Ignore 3 LSB */
2242 2243
2243 err = 0; 2244 err = 0;
2244 printk(KERN_INFO DRVNAME ": Found %s chip at %#x, revision %d\n", 2245 pr_info("Found %s chip at %#x, revision %d\n",
2245 f71882fg_names[sio_data->type], (unsigned int)*address, 2246 f71882fg_names[sio_data->type], (unsigned int)*address,
2246 (int)superio_inb(sioaddr, SIO_REG_DEVREV)); 2247 (int)superio_inb(sioaddr, SIO_REG_DEVREV));
2247exit: 2248exit:
@@ -2270,20 +2271,20 @@ static int __init f71882fg_device_add(unsigned short address,
2270 2271
2271 err = platform_device_add_resources(f71882fg_pdev, &res, 1); 2272 err = platform_device_add_resources(f71882fg_pdev, &res, 1);
2272 if (err) { 2273 if (err) {
2273 printk(KERN_ERR DRVNAME ": Device resource addition failed\n"); 2274 pr_err("Device resource addition failed\n");
2274 goto exit_device_put; 2275 goto exit_device_put;
2275 } 2276 }
2276 2277
2277 err = platform_device_add_data(f71882fg_pdev, sio_data, 2278 err = platform_device_add_data(f71882fg_pdev, sio_data,
2278 sizeof(struct f71882fg_sio_data)); 2279 sizeof(struct f71882fg_sio_data));
2279 if (err) { 2280 if (err) {
2280 printk(KERN_ERR DRVNAME ": Platform data allocation failed\n"); 2281 pr_err("Platform data allocation failed\n");
2281 goto exit_device_put; 2282 goto exit_device_put;
2282 } 2283 }
2283 2284
2284 err = platform_device_add(f71882fg_pdev); 2285 err = platform_device_add(f71882fg_pdev);
2285 if (err) { 2286 if (err) {
2286 printk(KERN_ERR DRVNAME ": Device addition failed\n"); 2287 pr_err("Device addition failed\n");
2287 goto exit_device_put; 2288 goto exit_device_put;
2288 } 2289 }
2289 2290
diff --git a/drivers/hwmon/fschmd.c b/drivers/hwmon/fschmd.c
index d4d4ca65d371..aa6d8b686f82 100644
--- a/drivers/hwmon/fschmd.c
+++ b/drivers/hwmon/fschmd.c
@@ -49,7 +49,6 @@
49#include <linux/kref.h> 49#include <linux/kref.h>
50 50
51/* Addresses to scan */ 51/* Addresses to scan */
52static DEFINE_MUTEX(watchdog_mutex);
53static const unsigned short normal_i2c[] = { 0x73, I2C_CLIENT_END }; 52static const unsigned short normal_i2c[] = { 0x73, I2C_CLIENT_END };
54 53
55/* Insmod parameters */ 54/* Insmod parameters */
@@ -850,7 +849,7 @@ static ssize_t watchdog_write(struct file *filp, const char __user *buf,
850 849
851static long watchdog_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) 850static long watchdog_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
852{ 851{
853 static struct watchdog_info ident = { 852 struct watchdog_info ident = {
854 .options = WDIOF_KEEPALIVEPING | WDIOF_SETTIMEOUT | 853 .options = WDIOF_KEEPALIVEPING | WDIOF_SETTIMEOUT |
855 WDIOF_CARDRESET, 854 WDIOF_CARDRESET,
856 .identity = "FSC watchdog" 855 .identity = "FSC watchdog"
@@ -858,7 +857,6 @@ static long watchdog_ioctl(struct file *filp, unsigned int cmd, unsigned long ar
858 int i, ret = 0; 857 int i, ret = 0;
859 struct fschmd_data *data = filp->private_data; 858 struct fschmd_data *data = filp->private_data;
860 859
861 mutex_lock(&watchdog_mutex);
862 switch (cmd) { 860 switch (cmd) {
863 case WDIOC_GETSUPPORT: 861 case WDIOC_GETSUPPORT:
864 ident.firmware_version = data->revision; 862 ident.firmware_version = data->revision;
@@ -915,7 +913,6 @@ static long watchdog_ioctl(struct file *filp, unsigned int cmd, unsigned long ar
915 default: 913 default:
916 ret = -ENOTTY; 914 ret = -ENOTTY;
917 } 915 }
918 mutex_unlock(&watchdog_mutex);
919 return ret; 916 return ret;
920} 917}
921 918
diff --git a/drivers/hwmon/hp_accel.c b/drivers/hwmon/hp_accel.c
index a56a78412fcb..3d21fa2b97cd 100644
--- a/drivers/hwmon/hp_accel.c
+++ b/drivers/hwmon/hp_accel.c
@@ -20,6 +20,8 @@
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */ 21 */
22 22
23#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
24
23#include <linux/kernel.h> 25#include <linux/kernel.h>
24#include <linux/init.h> 26#include <linux/init.h>
25#include <linux/dmi.h> 27#include <linux/dmi.h>
@@ -147,7 +149,7 @@ int lis3lv02d_acpi_write(struct lis3lv02d *lis3, int reg, u8 val)
147static int lis3lv02d_dmi_matched(const struct dmi_system_id *dmi) 149static int lis3lv02d_dmi_matched(const struct dmi_system_id *dmi)
148{ 150{
149 lis3_dev.ac = *((union axis_conversion *)dmi->driver_data); 151 lis3_dev.ac = *((union axis_conversion *)dmi->driver_data);
150 printk(KERN_INFO DRIVER_NAME ": hardware type %s found.\n", dmi->ident); 152 pr_info("hardware type %s found\n", dmi->ident);
151 153
152 return 1; 154 return 1;
153} 155}
@@ -303,11 +305,10 @@ static int lis3lv02d_add(struct acpi_device *device)
303 305
304 /* If possible use a "standard" axes order */ 306 /* If possible use a "standard" axes order */
305 if (lis3_dev.ac.x && lis3_dev.ac.y && lis3_dev.ac.z) { 307 if (lis3_dev.ac.x && lis3_dev.ac.y && lis3_dev.ac.z) {
306 printk(KERN_INFO DRIVER_NAME ": Using custom axes %d,%d,%d\n", 308 pr_info("Using custom axes %d,%d,%d\n",
307 lis3_dev.ac.x, lis3_dev.ac.y, lis3_dev.ac.z); 309 lis3_dev.ac.x, lis3_dev.ac.y, lis3_dev.ac.z);
308 } else if (dmi_check_system(lis3lv02d_dmi_ids) == 0) { 310 } else if (dmi_check_system(lis3lv02d_dmi_ids) == 0) {
309 printk(KERN_INFO DRIVER_NAME ": laptop model unknown, " 311 pr_info("laptop model unknown, using default axes configuration\n");
310 "using default axes configuration\n");
311 lis3_dev.ac = lis3lv02d_axis_normal; 312 lis3_dev.ac = lis3lv02d_axis_normal;
312 } 313 }
313 314
@@ -385,7 +386,7 @@ static int __init lis3lv02d_init_module(void)
385 if (ret < 0) 386 if (ret < 0)
386 return ret; 387 return ret;
387 388
388 printk(KERN_INFO DRIVER_NAME " driver loaded.\n"); 389 pr_info("driver loaded\n");
389 390
390 return 0; 391 return 0;
391} 392}
diff --git a/drivers/hwmon/hwmon-vid.c b/drivers/hwmon/hwmon-vid.c
index 2b2ca1694f95..2582bfef6ccb 100644
--- a/drivers/hwmon/hwmon-vid.c
+++ b/drivers/hwmon/hwmon-vid.c
@@ -22,6 +22,8 @@
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 */ 23 */
24 24
25#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
26
25#include <linux/module.h> 27#include <linux/module.h>
26#include <linux/kernel.h> 28#include <linux/kernel.h>
27#include <linux/hwmon-vid.h> 29#include <linux/hwmon-vid.h>
@@ -146,8 +148,8 @@ int vid_from_reg(int val, u8 vrm)
146 return(val > 0x77 ? 0 : (1500000 - (val * 12500) + 500) / 1000); 148 return(val > 0x77 ? 0 : (1500000 - (val * 12500) + 500) / 1000);
147 default: /* report 0 for unknown */ 149 default: /* report 0 for unknown */
148 if (vrm) 150 if (vrm)
149 printk(KERN_WARNING "hwmon-vid: Requested unsupported " 151 pr_warn("Requested unsupported VRM version (%u)\n",
150 "VRM version (%u)\n", (unsigned int)vrm); 152 (unsigned int)vrm);
151 return 0; 153 return 0;
152 } 154 }
153} 155}
@@ -246,8 +248,7 @@ u8 vid_which_vrm(void)
246 } 248 }
247 vrm_ret = find_vrm(eff_family, eff_model, eff_stepping, c->x86_vendor); 249 vrm_ret = find_vrm(eff_family, eff_model, eff_stepping, c->x86_vendor);
248 if (vrm_ret == 0) 250 if (vrm_ret == 0)
249 printk(KERN_INFO "hwmon-vid: Unknown VRM version of your " 251 pr_info("Unknown VRM version of your x86 CPU\n");
250 "x86 CPU\n");
251 return vrm_ret; 252 return vrm_ret;
252} 253}
253 254
@@ -255,7 +256,7 @@ u8 vid_which_vrm(void)
255#else 256#else
256u8 vid_which_vrm(void) 257u8 vid_which_vrm(void)
257{ 258{
258 printk(KERN_INFO "hwmon-vid: Unknown VRM version of your CPU\n"); 259 pr_info("Unknown VRM version of your CPU\n");
259 return 0; 260 return 0;
260} 261}
261#endif 262#endif
diff --git a/drivers/hwmon/hwmon.c b/drivers/hwmon/hwmon.c
index 29ea6753f3bb..a61e7815a2a9 100644
--- a/drivers/hwmon/hwmon.c
+++ b/drivers/hwmon/hwmon.c
@@ -10,6 +10,8 @@
10 the Free Software Foundation; version 2 of the License. 10 the Free Software Foundation; version 2 of the License.
11*/ 11*/
12 12
13#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
14
13#include <linux/module.h> 15#include <linux/module.h>
14#include <linux/device.h> 16#include <linux/device.h>
15#include <linux/err.h> 17#include <linux/err.h>
@@ -119,7 +121,7 @@ static int __init hwmon_init(void)
119 121
120 hwmon_class = class_create(THIS_MODULE, "hwmon"); 122 hwmon_class = class_create(THIS_MODULE, "hwmon");
121 if (IS_ERR(hwmon_class)) { 123 if (IS_ERR(hwmon_class)) {
122 printk(KERN_ERR "hwmon.c: couldn't create sysfs class\n"); 124 pr_err("couldn't create sysfs class\n");
123 return PTR_ERR(hwmon_class); 125 return PTR_ERR(hwmon_class);
124 } 126 }
125 return 0; 127 return 0;
diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
index eaee546af19a..bc6e2ab3a361 100644
--- a/drivers/hwmon/ibmaem.c
+++ b/drivers/hwmon/ibmaem.c
@@ -20,6 +20,8 @@
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */ 21 */
22 22
23#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
24
23#include <linux/ipmi.h> 25#include <linux/ipmi.h>
24#include <linux/module.h> 26#include <linux/module.h>
25#include <linux/hwmon.h> 27#include <linux/hwmon.h>
@@ -1090,7 +1092,7 @@ static int __init aem_init(void)
1090 1092
1091 res = driver_register(&aem_driver.driver); 1093 res = driver_register(&aem_driver.driver);
1092 if (res) { 1094 if (res) {
1093 printk(KERN_ERR "Can't register aem driver\n"); 1095 pr_err("Can't register aem driver\n");
1094 return res; 1096 return res;
1095 } 1097 }
1096 1098
diff --git a/drivers/hwmon/it87.c b/drivers/hwmon/it87.c
index a428a9264195..316b64823f7b 100644
--- a/drivers/hwmon/it87.c
+++ b/drivers/hwmon/it87.c
@@ -38,6 +38,8 @@
38 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 38 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
39 */ 39 */
40 40
41#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
42
41#include <linux/module.h> 43#include <linux/module.h>
42#include <linux/init.h> 44#include <linux/init.h>
43#include <linux/slab.h> 45#include <linux/slab.h>
@@ -1570,26 +1572,25 @@ static int __init it87_find(unsigned short *address,
1570 case 0xffff: /* No device at all */ 1572 case 0xffff: /* No device at all */
1571 goto exit; 1573 goto exit;
1572 default: 1574 default:
1573 pr_debug(DRVNAME ": Unsupported chip (DEVID=0x%x)\n", 1575 pr_debug("Unsupported chip (DEVID=0x%x)\n", chip_type);
1574 chip_type);
1575 goto exit; 1576 goto exit;
1576 } 1577 }
1577 1578
1578 superio_select(PME); 1579 superio_select(PME);
1579 if (!(superio_inb(IT87_ACT_REG) & 0x01)) { 1580 if (!(superio_inb(IT87_ACT_REG) & 0x01)) {
1580 pr_info("it87: Device not activated, skipping\n"); 1581 pr_info("Device not activated, skipping\n");
1581 goto exit; 1582 goto exit;
1582 } 1583 }
1583 1584
1584 *address = superio_inw(IT87_BASE_REG) & ~(IT87_EXTENT - 1); 1585 *address = superio_inw(IT87_BASE_REG) & ~(IT87_EXTENT - 1);
1585 if (*address == 0) { 1586 if (*address == 0) {
1586 pr_info("it87: Base address not set, skipping\n"); 1587 pr_info("Base address not set, skipping\n");
1587 goto exit; 1588 goto exit;
1588 } 1589 }
1589 1590
1590 err = 0; 1591 err = 0;
1591 sio_data->revision = superio_inb(DEVREV) & 0x0f; 1592 sio_data->revision = superio_inb(DEVREV) & 0x0f;
1592 pr_info("it87: Found IT%04xF chip at 0x%x, revision %d\n", 1593 pr_info("Found IT%04xF chip at 0x%x, revision %d\n",
1593 chip_type, *address, sio_data->revision); 1594 chip_type, *address, sio_data->revision);
1594 1595
1595 /* in8 (Vbat) is always internal */ 1596 /* in8 (Vbat) is always internal */
@@ -1615,7 +1616,7 @@ static int __init it87_find(unsigned short *address,
1615 } else { 1616 } else {
1616 /* We need at least 4 VID pins */ 1617 /* We need at least 4 VID pins */
1617 if (reg & 0x0f) { 1618 if (reg & 0x0f) {
1618 pr_info("it87: VID is disabled (pins used for GPIO)\n"); 1619 pr_info("VID is disabled (pins used for GPIO)\n");
1619 sio_data->skip_vid = 1; 1620 sio_data->skip_vid = 1;
1620 } 1621 }
1621 } 1622 }
@@ -1651,7 +1652,7 @@ static int __init it87_find(unsigned short *address,
1651 if (sio_data->type == it8720 && !(reg & (1 << 1))) { 1652 if (sio_data->type == it8720 && !(reg & (1 << 1))) {
1652 reg |= (1 << 1); 1653 reg |= (1 << 1);
1653 superio_outb(IT87_SIO_PINX2_REG, reg); 1654 superio_outb(IT87_SIO_PINX2_REG, reg);
1654 pr_notice("it87: Routing internal VCCH to in7\n"); 1655 pr_notice("Routing internal VCCH to in7\n");
1655 } 1656 }
1656 if (reg & (1 << 0)) 1657 if (reg & (1 << 0))
1657 sio_data->internal |= (1 << 0); 1658 sio_data->internal |= (1 << 0);
@@ -1661,7 +1662,7 @@ static int __init it87_find(unsigned short *address,
1661 sio_data->beep_pin = superio_inb(IT87_SIO_BEEP_PIN_REG) & 0x3f; 1662 sio_data->beep_pin = superio_inb(IT87_SIO_BEEP_PIN_REG) & 0x3f;
1662 } 1663 }
1663 if (sio_data->beep_pin) 1664 if (sio_data->beep_pin)
1664 pr_info("it87: Beeping is supported\n"); 1665 pr_info("Beeping is supported\n");
1665 1666
1666 /* Disable specific features based on DMI strings */ 1667 /* Disable specific features based on DMI strings */
1667 board_vendor = dmi_get_system_info(DMI_BOARD_VENDOR); 1668 board_vendor = dmi_get_system_info(DMI_BOARD_VENDOR);
@@ -1675,8 +1676,7 @@ static int __init it87_find(unsigned short *address,
1675 the PWM2 duty cycle, so we disable it. 1676 the PWM2 duty cycle, so we disable it.
1676 I use the board name string as the trigger in case 1677 I use the board name string as the trigger in case
1677 the same board is ever used in other systems. */ 1678 the same board is ever used in other systems. */
1678 pr_info("it87: Disabling pwm2 due to " 1679 pr_info("Disabling pwm2 due to hardware constraints\n");
1679 "hardware constraints\n");
1680 sio_data->skip_pwm = (1 << 1); 1680 sio_data->skip_pwm = (1 << 1);
1681 } 1681 }
1682 } 1682 }
@@ -2189,28 +2189,26 @@ static int __init it87_device_add(unsigned short address,
2189 pdev = platform_device_alloc(DRVNAME, address); 2189 pdev = platform_device_alloc(DRVNAME, address);
2190 if (!pdev) { 2190 if (!pdev) {
2191 err = -ENOMEM; 2191 err = -ENOMEM;
2192 printk(KERN_ERR DRVNAME ": Device allocation failed\n"); 2192 pr_err("Device allocation failed\n");
2193 goto exit; 2193 goto exit;
2194 } 2194 }
2195 2195
2196 err = platform_device_add_resources(pdev, &res, 1); 2196 err = platform_device_add_resources(pdev, &res, 1);
2197 if (err) { 2197 if (err) {
2198 printk(KERN_ERR DRVNAME ": Device resource addition failed " 2198 pr_err("Device resource addition failed (%d)\n", err);
2199 "(%d)\n", err);
2200 goto exit_device_put; 2199 goto exit_device_put;
2201 } 2200 }
2202 2201
2203 err = platform_device_add_data(pdev, sio_data, 2202 err = platform_device_add_data(pdev, sio_data,
2204 sizeof(struct it87_sio_data)); 2203 sizeof(struct it87_sio_data));
2205 if (err) { 2204 if (err) {
2206 printk(KERN_ERR DRVNAME ": Platform data allocation failed\n"); 2205 pr_err("Platform data allocation failed\n");
2207 goto exit_device_put; 2206 goto exit_device_put;
2208 } 2207 }
2209 2208
2210 err = platform_device_add(pdev); 2209 err = platform_device_add(pdev);
2211 if (err) { 2210 if (err) {
2212 printk(KERN_ERR DRVNAME ": Device addition failed (%d)\n", 2211 pr_err("Device addition failed (%d)\n", err);
2213 err);
2214 goto exit_device_put; 2212 goto exit_device_put;
2215 } 2213 }
2216 2214
diff --git a/drivers/hwmon/lis3lv02d.c b/drivers/hwmon/lis3lv02d.c
index 0cee73a6124e..1b674b7d4584 100644
--- a/drivers/hwmon/lis3lv02d.c
+++ b/drivers/hwmon/lis3lv02d.c
@@ -20,6 +20,8 @@
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */ 21 */
22 22
23#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
24
23#include <linux/kernel.h> 25#include <linux/kernel.h>
24#include <linux/init.h> 26#include <linux/init.h>
25#include <linux/dmi.h> 27#include <linux/dmi.h>
@@ -860,8 +862,7 @@ static void lis3lv02d_8b_configure(struct lis3lv02d *dev,
860 (p->irq_flags2 & IRQF_TRIGGER_MASK), 862 (p->irq_flags2 & IRQF_TRIGGER_MASK),
861 DRIVER_NAME, &lis3_dev); 863 DRIVER_NAME, &lis3_dev);
862 if (err < 0) 864 if (err < 0)
863 printk(KERN_ERR DRIVER_NAME 865 pr_err("No second IRQ. Limited functionality\n");
864 "No second IRQ. Limited functionality\n");
865 } 866 }
866} 867}
867 868
@@ -879,7 +880,7 @@ int lis3lv02d_init_device(struct lis3lv02d *dev)
879 880
880 switch (dev->whoami) { 881 switch (dev->whoami) {
881 case WAI_12B: 882 case WAI_12B:
882 printk(KERN_INFO DRIVER_NAME ": 12 bits sensor found\n"); 883 pr_info("12 bits sensor found\n");
883 dev->read_data = lis3lv02d_read_12; 884 dev->read_data = lis3lv02d_read_12;
884 dev->mdps_max_val = 2048; 885 dev->mdps_max_val = 2048;
885 dev->pwron_delay = LIS3_PWRON_DELAY_WAI_12B; 886 dev->pwron_delay = LIS3_PWRON_DELAY_WAI_12B;
@@ -890,7 +891,7 @@ int lis3lv02d_init_device(struct lis3lv02d *dev)
890 dev->regs_size = ARRAY_SIZE(lis3_wai12_regs); 891 dev->regs_size = ARRAY_SIZE(lis3_wai12_regs);
891 break; 892 break;
892 case WAI_8B: 893 case WAI_8B:
893 printk(KERN_INFO DRIVER_NAME ": 8 bits sensor found\n"); 894 pr_info("8 bits sensor found\n");
894 dev->read_data = lis3lv02d_read_8; 895 dev->read_data = lis3lv02d_read_8;
895 dev->mdps_max_val = 128; 896 dev->mdps_max_val = 128;
896 dev->pwron_delay = LIS3_PWRON_DELAY_WAI_8B; 897 dev->pwron_delay = LIS3_PWRON_DELAY_WAI_8B;
@@ -901,7 +902,7 @@ int lis3lv02d_init_device(struct lis3lv02d *dev)
901 dev->regs_size = ARRAY_SIZE(lis3_wai8_regs); 902 dev->regs_size = ARRAY_SIZE(lis3_wai8_regs);
902 break; 903 break;
903 case WAI_3DC: 904 case WAI_3DC:
904 printk(KERN_INFO DRIVER_NAME ": 8 bits 3DC sensor found\n"); 905 pr_info("8 bits 3DC sensor found\n");
905 dev->read_data = lis3lv02d_read_8; 906 dev->read_data = lis3lv02d_read_8;
906 dev->mdps_max_val = 128; 907 dev->mdps_max_val = 128;
907 dev->pwron_delay = LIS3_PWRON_DELAY_WAI_8B; 908 dev->pwron_delay = LIS3_PWRON_DELAY_WAI_8B;
@@ -910,8 +911,7 @@ int lis3lv02d_init_device(struct lis3lv02d *dev)
910 dev->scale = LIS3_SENSITIVITY_8B; 911 dev->scale = LIS3_SENSITIVITY_8B;
911 break; 912 break;
912 default: 913 default:
913 printk(KERN_ERR DRIVER_NAME 914 pr_err("unknown sensor type 0x%X\n", dev->whoami);
914 ": unknown sensor type 0x%X\n", dev->whoami);
915 return -EINVAL; 915 return -EINVAL;
916 } 916 }
917 917
@@ -935,7 +935,7 @@ int lis3lv02d_init_device(struct lis3lv02d *dev)
935 } 935 }
936 936
937 if (lis3lv02d_joystick_enable()) 937 if (lis3lv02d_joystick_enable())
938 printk(KERN_ERR DRIVER_NAME ": joystick initialization failed\n"); 938 pr_err("joystick initialization failed\n");
939 939
940 /* passing in platform specific data is purely optional and only 940 /* passing in platform specific data is purely optional and only
941 * used by the SPI transport layer at the moment */ 941 * used by the SPI transport layer at the moment */
@@ -957,8 +957,7 @@ int lis3lv02d_init_device(struct lis3lv02d *dev)
957 957
958 /* bail if we did not get an IRQ from the bus layer */ 958 /* bail if we did not get an IRQ from the bus layer */
959 if (!dev->irq) { 959 if (!dev->irq) {
960 printk(KERN_ERR DRIVER_NAME 960 pr_err("No IRQ. Disabling /dev/freefall\n");
961 ": No IRQ. Disabling /dev/freefall\n");
962 goto out; 961 goto out;
963 } 962 }
964 963
@@ -985,12 +984,12 @@ int lis3lv02d_init_device(struct lis3lv02d *dev)
985 DRIVER_NAME, &lis3_dev); 984 DRIVER_NAME, &lis3_dev);
986 985
987 if (err < 0) { 986 if (err < 0) {
988 printk(KERN_ERR DRIVER_NAME "Cannot get IRQ\n"); 987 pr_err("Cannot get IRQ\n");
989 goto out; 988 goto out;
990 } 989 }
991 990
992 if (misc_register(&lis3lv02d_misc_device)) 991 if (misc_register(&lis3lv02d_misc_device))
993 printk(KERN_ERR DRIVER_NAME ": misc_register failed\n"); 992 pr_err("misc_register failed\n");
994out: 993out:
995 return 0; 994 return 0;
996} 995}
diff --git a/drivers/hwmon/lm70.c b/drivers/hwmon/lm70.c
index fd108cfc05c7..3b84fb503053 100644
--- a/drivers/hwmon/lm70.c
+++ b/drivers/hwmon/lm70.c
@@ -24,6 +24,8 @@
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 */ 25 */
26 26
27#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
28
27#include <linux/init.h> 29#include <linux/init.h>
28#include <linux/module.h> 30#include <linux/module.h>
29#include <linux/kernel.h> 31#include <linux/kernel.h>
@@ -67,8 +69,7 @@ static ssize_t lm70_sense_temp(struct device *dev,
67 */ 69 */
68 status = spi_write_then_read(spi, NULL, 0, &rxbuf[0], 2); 70 status = spi_write_then_read(spi, NULL, 0, &rxbuf[0], 2);
69 if (status < 0) { 71 if (status < 0) {
70 printk(KERN_WARNING 72 pr_warn("spi_write_then_read failed with status %d\n", status);
71 "spi_write_then_read failed with status %d\n", status);
72 goto out; 73 goto out;
73 } 74 }
74 raw = (rxbuf[0] << 8) + rxbuf[1]; 75 raw = (rxbuf[0] << 8) + rxbuf[1];
diff --git a/drivers/hwmon/lm78.c b/drivers/hwmon/lm78.c
index 72ff2c4e757d..4cb24eafe318 100644
--- a/drivers/hwmon/lm78.c
+++ b/drivers/hwmon/lm78.c
@@ -19,6 +19,8 @@
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20*/ 20*/
21 21
22#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
23
22#include <linux/module.h> 24#include <linux/module.h>
23#include <linux/init.h> 25#include <linux/init.h>
24#include <linux/slab.h> 26#include <linux/slab.h>
@@ -858,7 +860,7 @@ static int __init lm78_isa_found(unsigned short address)
858 * individually for the probing phase. */ 860 * individually for the probing phase. */
859 for (port = address; port < address + LM78_EXTENT; port++) { 861 for (port = address; port < address + LM78_EXTENT; port++) {
860 if (!request_region(port, 1, "lm78")) { 862 if (!request_region(port, 1, "lm78")) {
861 pr_debug("lm78: Failed to request port 0x%x\n", port); 863 pr_debug("Failed to request port 0x%x\n", port);
862 goto release; 864 goto release;
863 } 865 }
864 } 866 }
@@ -920,7 +922,7 @@ static int __init lm78_isa_found(unsigned short address)
920 found = 1; 922 found = 1;
921 923
922 if (found) 924 if (found)
923 pr_info("lm78: Found an %s chip at %#x\n", 925 pr_info("Found an %s chip at %#x\n",
924 val & 0x80 ? "LM79" : "LM78", (int)address); 926 val & 0x80 ? "LM79" : "LM78", (int)address);
925 927
926 release: 928 release:
@@ -942,21 +944,19 @@ static int __init lm78_isa_device_add(unsigned short address)
942 pdev = platform_device_alloc("lm78", address); 944 pdev = platform_device_alloc("lm78", address);
943 if (!pdev) { 945 if (!pdev) {
944 err = -ENOMEM; 946 err = -ENOMEM;
945 printk(KERN_ERR "lm78: Device allocation failed\n"); 947 pr_err("Device allocation failed\n");
946 goto exit; 948 goto exit;
947 } 949 }
948 950
949 err = platform_device_add_resources(pdev, &res, 1); 951 err = platform_device_add_resources(pdev, &res, 1);
950 if (err) { 952 if (err) {
951 printk(KERN_ERR "lm78: Device resource addition failed " 953 pr_err("Device resource addition failed (%d)\n", err);
952 "(%d)\n", err);
953 goto exit_device_put; 954 goto exit_device_put;
954 } 955 }
955 956
956 err = platform_device_add(pdev); 957 err = platform_device_add(pdev);
957 if (err) { 958 if (err) {
958 printk(KERN_ERR "lm78: Device addition failed (%d)\n", 959 pr_err("Device addition failed (%d)\n", err);
959 err);
960 goto exit_device_put; 960 goto exit_device_put;
961 } 961 }
962 962
diff --git a/drivers/hwmon/lm95241.c b/drivers/hwmon/lm95241.c
index 4546d82f024a..1a6dfb6df1e7 100644
--- a/drivers/hwmon/lm95241.c
+++ b/drivers/hwmon/lm95241.c
@@ -1,13 +1,9 @@
1/* 1/*
2 * lm95241.c - Part of lm_sensors, Linux kernel modules for hardware 2 * Copyright (C) 2008, 2010 Davide Rizzo <elpa.rizzo@gmail.com>
3 * monitoring
4 * Copyright (C) 2008 Davide Rizzo <elpa-rizzo@gmail.com>
5 * 3 *
6 * Based on the max1619 driver. The LM95241 is a sensor chip made by National 4 * The LM95241 is a sensor chip made by National Semiconductors.
7 * Semiconductors. 5 * It reports up to three temperatures (its own plus up to two external ones).
8 * It reports up to three temperatures (its own plus up to 6 * Complete datasheet can be obtained from National's website at:
9 * two external ones). Complete datasheet can be
10 * obtained from National's website at:
11 * http://www.national.com/ds.cgi/LM/LM95241.pdf 7 * http://www.national.com/ds.cgi/LM/LM95241.pdf
12 * 8 *
13 * This program is free software; you can redistribute it and/or modify 9 * This program is free software; you can redistribute it and/or modify
@@ -36,8 +32,10 @@
36#include <linux/mutex.h> 32#include <linux/mutex.h>
37#include <linux/sysfs.h> 33#include <linux/sysfs.h>
38 34
35#define DEVNAME "lm95241"
36
39static const unsigned short normal_i2c[] = { 37static const unsigned short normal_i2c[] = {
40 0x19, 0x2a, 0x2b, I2C_CLIENT_END}; 38 0x19, 0x2a, 0x2b, I2C_CLIENT_END };
41 39
42/* LM95241 registers */ 40/* LM95241 registers */
43#define LM95241_REG_R_MAN_ID 0xFE 41#define LM95241_REG_R_MAN_ID 0xFE
@@ -46,7 +44,7 @@ static const unsigned short normal_i2c[] = {
46#define LM95241_REG_RW_CONFIG 0x03 44#define LM95241_REG_RW_CONFIG 0x03
47#define LM95241_REG_RW_REM_FILTER 0x06 45#define LM95241_REG_RW_REM_FILTER 0x06
48#define LM95241_REG_RW_TRUTHERM 0x07 46#define LM95241_REG_RW_TRUTHERM 0x07
49#define LM95241_REG_W_ONE_SHOT 0x0F 47#define LM95241_REG_W_ONE_SHOT 0x0F
50#define LM95241_REG_R_LOCAL_TEMPH 0x10 48#define LM95241_REG_R_LOCAL_TEMPH 0x10
51#define LM95241_REG_R_REMOTE1_TEMPH 0x11 49#define LM95241_REG_R_REMOTE1_TEMPH 0x11
52#define LM95241_REG_R_REMOTE2_TEMPH 0x12 50#define LM95241_REG_R_REMOTE2_TEMPH 0x12
@@ -79,235 +77,246 @@ static const unsigned short normal_i2c[] = {
79#define MANUFACTURER_ID 0x01 77#define MANUFACTURER_ID 0x01
80#define DEFAULT_REVISION 0xA4 78#define DEFAULT_REVISION 0xA4
81 79
82/* Conversions and various macros */ 80static const u8 lm95241_reg_address[] = {
83#define TEMP_FROM_REG(val_h, val_l) (((val_h) & 0x80 ? (val_h) - 0x100 : \ 81 LM95241_REG_R_LOCAL_TEMPH,
84 (val_h)) * 1000 + (val_l) * 1000 / 256) 82 LM95241_REG_R_LOCAL_TEMPL,
85 83 LM95241_REG_R_REMOTE1_TEMPH,
86/* Functions declaration */ 84 LM95241_REG_R_REMOTE1_TEMPL,
87static void lm95241_init_client(struct i2c_client *client); 85 LM95241_REG_R_REMOTE2_TEMPH,
88static struct lm95241_data *lm95241_update_device(struct device *dev); 86 LM95241_REG_R_REMOTE2_TEMPL
87};
89 88
90/* Client data (each client gets its own) */ 89/* Client data (each client gets its own) */
91struct lm95241_data { 90struct lm95241_data {
92 struct device *hwmon_dev; 91 struct device *hwmon_dev;
93 struct mutex update_lock; 92 struct mutex update_lock;
94 unsigned long last_updated, interval; /* in jiffies */ 93 unsigned long last_updated, interval; /* in jiffies */
95 char valid; /* zero until following fields are valid */ 94 char valid; /* zero until following fields are valid */
96 /* registers values */ 95 /* registers values */
97 u8 local_h, local_l; /* local */ 96 u8 temp[ARRAY_SIZE(lm95241_reg_address)];
98 u8 remote1_h, remote1_l; /* remote1 */
99 u8 remote2_h, remote2_l; /* remote2 */
100 u8 config, model, trutherm; 97 u8 config, model, trutherm;
101}; 98};
102 99
100/* Conversions */
101static int TempFromReg(u8 val_h, u8 val_l)
102{
103 if (val_h & 0x80)
104 return val_h - 0x100;
105 return val_h * 1000 + val_l * 1000 / 256;
106}
107
108static struct lm95241_data *lm95241_update_device(struct device *dev)
109{
110 struct i2c_client *client = to_i2c_client(dev);
111 struct lm95241_data *data = i2c_get_clientdata(client);
112
113 mutex_lock(&data->update_lock);
114
115 if (time_after(jiffies, data->last_updated + data->interval) ||
116 !data->valid) {
117 int i;
118
119 dev_dbg(&client->dev, "Updating lm95241 data.\n");
120 for (i = 0; i < ARRAY_SIZE(lm95241_reg_address); i++)
121 data->temp[i]
122 = i2c_smbus_read_byte_data(client,
123 lm95241_reg_address[i]);
124 data->last_updated = jiffies;
125 data->valid = 1;
126 }
127
128 mutex_unlock(&data->update_lock);
129
130 return data;
131}
132
103/* Sysfs stuff */ 133/* Sysfs stuff */
104#define show_temp(value) \ 134static ssize_t show_input(struct device *dev, struct device_attribute *attr,
105static ssize_t show_##value(struct device *dev, \ 135 char *buf)
106 struct device_attribute *attr, char *buf) \ 136{
107{ \ 137 struct lm95241_data *data = lm95241_update_device(dev);
108 struct lm95241_data *data = lm95241_update_device(dev); \ 138
109 snprintf(buf, PAGE_SIZE - 1, "%d\n", \ 139 return snprintf(buf, PAGE_SIZE - 1, "%d\n",
110 TEMP_FROM_REG(data->value##_h, data->value##_l)); \ 140 TempFromReg(data->temp[to_sensor_dev_attr(attr)->index],
111 return strlen(buf); \ 141 data->temp[to_sensor_dev_attr(attr)->index + 1]));
112} 142}
113show_temp(local);
114show_temp(remote1);
115show_temp(remote2);
116 143
117static ssize_t show_interval(struct device *dev, struct device_attribute *attr, 144static ssize_t show_type(struct device *dev, struct device_attribute *attr,
118 char *buf) 145 char *buf)
119{ 146{
120 struct lm95241_data *data = lm95241_update_device(dev); 147 struct i2c_client *client = to_i2c_client(dev);
148 struct lm95241_data *data = i2c_get_clientdata(client);
121 149
122 snprintf(buf, PAGE_SIZE - 1, "%lu\n", 1000 * data->interval / HZ); 150 return snprintf(buf, PAGE_SIZE - 1,
123 return strlen(buf); 151 data->model & to_sensor_dev_attr(attr)->index ? "1\n" : "2\n");
124} 152}
125 153
126static ssize_t set_interval(struct device *dev, struct device_attribute *attr, 154static ssize_t set_type(struct device *dev, struct device_attribute *attr,
127 const char *buf, size_t count) 155 const char *buf, size_t count)
128{ 156{
129 struct i2c_client *client = to_i2c_client(dev); 157 struct i2c_client *client = to_i2c_client(dev);
130 struct lm95241_data *data = i2c_get_clientdata(client); 158 struct lm95241_data *data = i2c_get_clientdata(client);
131 unsigned long val; 159 unsigned long val;
160 int shift;
161 u8 mask = to_sensor_dev_attr(attr)->index;
132 162
133 if (strict_strtoul(buf, 10, &val) < 0) 163 if (strict_strtoul(buf, 10, &val) < 0)
134 return -EINVAL; 164 return -EINVAL;
165 if (val != 1 && val != 2)
166 return -EINVAL;
135 167
136 data->interval = val * HZ / 1000; 168 shift = mask == R1MS_MASK ? TT1_SHIFT : TT2_SHIFT;
169
170 mutex_lock(&data->update_lock);
171
172 data->trutherm &= ~(TT_MASK << shift);
173 if (val == 1) {
174 data->model |= mask;
175 data->trutherm |= (TT_ON << shift);
176 } else {
177 data->model &= ~mask;
178 data->trutherm |= (TT_OFF << shift);
179 }
180 data->valid = 0;
181
182 i2c_smbus_write_byte_data(client, LM95241_REG_RW_REMOTE_MODEL,
183 data->model);
184 i2c_smbus_write_byte_data(client, LM95241_REG_RW_TRUTHERM,
185 data->trutherm);
186
187 mutex_unlock(&data->update_lock);
137 188
138 return count; 189 return count;
139} 190}
140 191
141#define show_type(flag) \ 192static ssize_t show_min(struct device *dev, struct device_attribute *attr,
142static ssize_t show_type##flag(struct device *dev, \ 193 char *buf)
143 struct device_attribute *attr, char *buf) \ 194{
144{ \ 195 struct i2c_client *client = to_i2c_client(dev);
145 struct i2c_client *client = to_i2c_client(dev); \ 196 struct lm95241_data *data = i2c_get_clientdata(client);
146 struct lm95241_data *data = i2c_get_clientdata(client); \ 197
147\ 198 return snprintf(buf, PAGE_SIZE - 1,
148 snprintf(buf, PAGE_SIZE - 1, \ 199 data->config & to_sensor_dev_attr(attr)->index ?
149 data->model & R##flag##MS_MASK ? "1\n" : "2\n"); \ 200 "-127000\n" : "0\n");
150 return strlen(buf); \
151} 201}
152show_type(1); 202
153show_type(2); 203static ssize_t set_min(struct device *dev, struct device_attribute *attr,
154 204 const char *buf, size_t count)
155#define show_min(flag) \ 205{
156static ssize_t show_min##flag(struct device *dev, \ 206 struct i2c_client *client = to_i2c_client(dev);
157 struct device_attribute *attr, char *buf) \ 207 struct lm95241_data *data = i2c_get_clientdata(client);
158{ \ 208 long val;
159 struct i2c_client *client = to_i2c_client(dev); \ 209
160 struct lm95241_data *data = i2c_get_clientdata(client); \ 210 if (strict_strtol(buf, 10, &val) < 0)
161\ 211 return -EINVAL;
162 snprintf(buf, PAGE_SIZE - 1, \ 212 if (val < -128000)
163 data->config & R##flag##DF_MASK ? \ 213 return -EINVAL;
164 "-127000\n" : "0\n"); \ 214
165 return strlen(buf); \ 215 mutex_lock(&data->update_lock);
216
217 if (val < 0)
218 data->config |= to_sensor_dev_attr(attr)->index;
219 else
220 data->config &= ~to_sensor_dev_attr(attr)->index;
221 data->valid = 0;
222
223 i2c_smbus_write_byte_data(client, LM95241_REG_RW_CONFIG, data->config);
224
225 mutex_unlock(&data->update_lock);
226
227 return count;
166} 228}
167show_min(1); 229
168show_min(2); 230static ssize_t show_max(struct device *dev, struct device_attribute *attr,
169 231 char *buf)
170#define show_max(flag) \ 232{
171static ssize_t show_max##flag(struct device *dev, \ 233 struct i2c_client *client = to_i2c_client(dev);
172 struct device_attribute *attr, char *buf) \ 234 struct lm95241_data *data = i2c_get_clientdata(client);
173{ \ 235
174 struct i2c_client *client = to_i2c_client(dev); \ 236 return snprintf(buf, PAGE_SIZE - 1,
175 struct lm95241_data *data = i2c_get_clientdata(client); \ 237 data->config & to_sensor_dev_attr(attr)->index ?
176\ 238 "127000\n" : "255000\n");
177 snprintf(buf, PAGE_SIZE - 1, \
178 data->config & R##flag##DF_MASK ? \
179 "127000\n" : "255000\n"); \
180 return strlen(buf); \
181} 239}
182show_max(1); 240
183show_max(2); 241static ssize_t set_max(struct device *dev, struct device_attribute *attr,
184 242 const char *buf, size_t count)
185#define set_type(flag) \ 243{
186static ssize_t set_type##flag(struct device *dev, \ 244 struct i2c_client *client = to_i2c_client(dev);
187 struct device_attribute *attr, \ 245 struct lm95241_data *data = i2c_get_clientdata(client);
188 const char *buf, size_t count) \ 246 long val;
189{ \ 247
190 struct i2c_client *client = to_i2c_client(dev); \ 248 if (strict_strtol(buf, 10, &val) < 0)
191 struct lm95241_data *data = i2c_get_clientdata(client); \ 249 return -EINVAL;
192\ 250 if (val >= 256000)
193 long val; \ 251 return -EINVAL;
194\ 252
195 if (strict_strtol(buf, 10, &val) < 0) \ 253 mutex_lock(&data->update_lock);
196 return -EINVAL; \ 254
197\ 255 if (val <= 127000)
198 if ((val == 1) || (val == 2)) { \ 256 data->config |= to_sensor_dev_attr(attr)->index;
199\ 257 else
200 mutex_lock(&data->update_lock); \ 258 data->config &= ~to_sensor_dev_attr(attr)->index;
201\ 259 data->valid = 0;
202 data->trutherm &= ~(TT_MASK << TT##flag##_SHIFT); \ 260
203 if (val == 1) { \ 261 i2c_smbus_write_byte_data(client, LM95241_REG_RW_CONFIG, data->config);
204 data->model |= R##flag##MS_MASK; \ 262
205 data->trutherm |= (TT_ON << TT##flag##_SHIFT); \ 263 mutex_unlock(&data->update_lock);
206 } \ 264
207 else { \ 265 return count;
208 data->model &= ~R##flag##MS_MASK; \
209 data->trutherm |= (TT_OFF << TT##flag##_SHIFT); \
210 } \
211\
212 data->valid = 0; \
213\
214 i2c_smbus_write_byte_data(client, LM95241_REG_RW_REMOTE_MODEL, \
215 data->model); \
216 i2c_smbus_write_byte_data(client, LM95241_REG_RW_TRUTHERM, \
217 data->trutherm); \
218\
219 mutex_unlock(&data->update_lock); \
220\
221 } \
222 return count; \
223} 266}
224set_type(1); 267
225set_type(2); 268static ssize_t show_interval(struct device *dev, struct device_attribute *attr,
226 269 char *buf)
227#define set_min(flag) \ 270{
228static ssize_t set_min##flag(struct device *dev, \ 271 struct lm95241_data *data = lm95241_update_device(dev);
229 struct device_attribute *devattr, const char *buf, size_t count) \ 272
230{ \ 273 return snprintf(buf, PAGE_SIZE - 1, "%lu\n", 1000 * data->interval
231 struct i2c_client *client = to_i2c_client(dev); \ 274 / HZ);
232 struct lm95241_data *data = i2c_get_clientdata(client); \
233\
234 long val; \
235\
236 if (strict_strtol(buf, 10, &val) < 0) \
237 return -EINVAL;\
238\
239 mutex_lock(&data->update_lock); \
240\
241 if (val < 0) \
242 data->config |= R##flag##DF_MASK; \
243 else \
244 data->config &= ~R##flag##DF_MASK; \
245\
246 data->valid = 0; \
247\
248 i2c_smbus_write_byte_data(client, LM95241_REG_RW_CONFIG, \
249 data->config); \
250\
251 mutex_unlock(&data->update_lock); \
252\
253 return count; \
254} 275}
255set_min(1); 276
256set_min(2); 277static ssize_t set_interval(struct device *dev, struct device_attribute *attr,
257 278 const char *buf, size_t count)
258#define set_max(flag) \ 279{
259static ssize_t set_max##flag(struct device *dev, \ 280 struct i2c_client *client = to_i2c_client(dev);
260 struct device_attribute *devattr, const char *buf, size_t count) \ 281 struct lm95241_data *data = i2c_get_clientdata(client);
261{ \ 282 unsigned long val;
262 struct i2c_client *client = to_i2c_client(dev); \ 283
263 struct lm95241_data *data = i2c_get_clientdata(client); \ 284 if (strict_strtoul(buf, 10, &val) < 0)
264\ 285 return -EINVAL;
265 long val; \ 286
266\ 287 data->interval = val * HZ / 1000;
267 if (strict_strtol(buf, 10, &val) < 0) \ 288
268 return -EINVAL; \ 289 return count;
269\
270 mutex_lock(&data->update_lock); \
271\
272 if (val <= 127000) \
273 data->config |= R##flag##DF_MASK; \
274 else \
275 data->config &= ~R##flag##DF_MASK; \
276\
277 data->valid = 0; \
278\
279 i2c_smbus_write_byte_data(client, LM95241_REG_RW_CONFIG, \
280 data->config); \
281\
282 mutex_unlock(&data->update_lock); \
283\
284 return count; \
285} 290}
286set_max(1); 291
287set_max(2); 292static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_input, NULL, 0);
288 293static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_input, NULL, 2);
289static DEVICE_ATTR(temp1_input, S_IRUGO, show_local, NULL); 294static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO, show_input, NULL, 4);
290static DEVICE_ATTR(temp2_input, S_IRUGO, show_remote1, NULL); 295static SENSOR_DEVICE_ATTR(temp2_type, S_IWUSR | S_IRUGO, show_type, set_type,
291static DEVICE_ATTR(temp3_input, S_IRUGO, show_remote2, NULL); 296 R1MS_MASK);
292static DEVICE_ATTR(temp2_type, S_IWUSR | S_IRUGO, show_type1, set_type1); 297static SENSOR_DEVICE_ATTR(temp3_type, S_IWUSR | S_IRUGO, show_type, set_type,
293static DEVICE_ATTR(temp3_type, S_IWUSR | S_IRUGO, show_type2, set_type2); 298 R2MS_MASK);
294static DEVICE_ATTR(temp2_min, S_IWUSR | S_IRUGO, show_min1, set_min1); 299static SENSOR_DEVICE_ATTR(temp2_min, S_IWUSR | S_IRUGO, show_min, set_min,
295static DEVICE_ATTR(temp3_min, S_IWUSR | S_IRUGO, show_min2, set_min2); 300 R1DF_MASK);
296static DEVICE_ATTR(temp2_max, S_IWUSR | S_IRUGO, show_max1, set_max1); 301static SENSOR_DEVICE_ATTR(temp3_min, S_IWUSR | S_IRUGO, show_min, set_min,
297static DEVICE_ATTR(temp3_max, S_IWUSR | S_IRUGO, show_max2, set_max2); 302 R2DF_MASK);
303static SENSOR_DEVICE_ATTR(temp2_max, S_IWUSR | S_IRUGO, show_max, set_max,
304 R1DF_MASK);
305static SENSOR_DEVICE_ATTR(temp3_max, S_IWUSR | S_IRUGO, show_max, set_max,
306 R2DF_MASK);
298static DEVICE_ATTR(update_interval, S_IWUSR | S_IRUGO, show_interval, 307static DEVICE_ATTR(update_interval, S_IWUSR | S_IRUGO, show_interval,
299 set_interval); 308 set_interval);
300 309
301static struct attribute *lm95241_attributes[] = { 310static struct attribute *lm95241_attributes[] = {
302 &dev_attr_temp1_input.attr, 311 &sensor_dev_attr_temp1_input.dev_attr.attr,
303 &dev_attr_temp2_input.attr, 312 &sensor_dev_attr_temp2_input.dev_attr.attr,
304 &dev_attr_temp3_input.attr, 313 &sensor_dev_attr_temp3_input.dev_attr.attr,
305 &dev_attr_temp2_type.attr, 314 &sensor_dev_attr_temp2_type.dev_attr.attr,
306 &dev_attr_temp3_type.attr, 315 &sensor_dev_attr_temp3_type.dev_attr.attr,
307 &dev_attr_temp2_min.attr, 316 &sensor_dev_attr_temp2_min.dev_attr.attr,
308 &dev_attr_temp3_min.attr, 317 &sensor_dev_attr_temp3_min.dev_attr.attr,
309 &dev_attr_temp2_max.attr, 318 &sensor_dev_attr_temp2_max.dev_attr.attr,
310 &dev_attr_temp3_max.attr, 319 &sensor_dev_attr_temp3_max.dev_attr.attr,
311 &dev_attr_update_interval.attr, 320 &dev_attr_update_interval.attr,
312 NULL 321 NULL
313}; 322};
@@ -329,9 +338,9 @@ static int lm95241_detect(struct i2c_client *new_client,
329 338
330 if ((i2c_smbus_read_byte_data(new_client, LM95241_REG_R_MAN_ID) 339 if ((i2c_smbus_read_byte_data(new_client, LM95241_REG_R_MAN_ID)
331 == MANUFACTURER_ID) 340 == MANUFACTURER_ID)
332 && (i2c_smbus_read_byte_data(new_client, LM95241_REG_R_CHIP_ID) 341 && (i2c_smbus_read_byte_data(new_client, LM95241_REG_R_CHIP_ID)
333 >= DEFAULT_REVISION)) { 342 >= DEFAULT_REVISION)) {
334 name = "lm95241"; 343 name = DEVNAME;
335 } else { 344 } else {
336 dev_dbg(&adapter->dev, "LM95241 detection failed at 0x%02x\n", 345 dev_dbg(&adapter->dev, "LM95241 detection failed at 0x%02x\n",
337 address); 346 address);
@@ -343,6 +352,25 @@ static int lm95241_detect(struct i2c_client *new_client,
343 return 0; 352 return 0;
344} 353}
345 354
355static void lm95241_init_client(struct i2c_client *client)
356{
357 struct lm95241_data *data = i2c_get_clientdata(client);
358
359 data->interval = HZ; /* 1 sec default */
360 data->valid = 0;
361 data->config = CFG_CR0076;
362 data->model = 0;
363 data->trutherm = (TT_OFF << TT1_SHIFT) | (TT_OFF << TT2_SHIFT);
364
365 i2c_smbus_write_byte_data(client, LM95241_REG_RW_CONFIG, data->config);
366 i2c_smbus_write_byte_data(client, LM95241_REG_RW_REM_FILTER,
367 R1FE_MASK | R2FE_MASK);
368 i2c_smbus_write_byte_data(client, LM95241_REG_RW_TRUTHERM,
369 data->trutherm);
370 i2c_smbus_write_byte_data(client, LM95241_REG_RW_REMOTE_MODEL,
371 data->model);
372}
373
346static int lm95241_probe(struct i2c_client *new_client, 374static int lm95241_probe(struct i2c_client *new_client,
347 const struct i2c_device_id *id) 375 const struct i2c_device_id *id)
348{ 376{
@@ -382,26 +410,6 @@ exit:
382 return err; 410 return err;
383} 411}
384 412
385static void lm95241_init_client(struct i2c_client *client)
386{
387 struct lm95241_data *data = i2c_get_clientdata(client);
388
389 data->interval = HZ; /* 1 sec default */
390 data->valid = 0;
391 data->config = CFG_CR0076;
392 data->model = 0;
393 data->trutherm = (TT_OFF << TT1_SHIFT) | (TT_OFF << TT2_SHIFT);
394
395 i2c_smbus_write_byte_data(client, LM95241_REG_RW_CONFIG,
396 data->config);
397 i2c_smbus_write_byte_data(client, LM95241_REG_RW_REM_FILTER,
398 R1FE_MASK | R2FE_MASK);
399 i2c_smbus_write_byte_data(client, LM95241_REG_RW_TRUTHERM,
400 data->trutherm);
401 i2c_smbus_write_byte_data(client, LM95241_REG_RW_REMOTE_MODEL,
402 data->model);
403}
404
405static int lm95241_remove(struct i2c_client *client) 413static int lm95241_remove(struct i2c_client *client)
406{ 414{
407 struct lm95241_data *data = i2c_get_clientdata(client); 415 struct lm95241_data *data = i2c_get_clientdata(client);
@@ -413,46 +421,9 @@ static int lm95241_remove(struct i2c_client *client)
413 return 0; 421 return 0;
414} 422}
415 423
416static struct lm95241_data *lm95241_update_device(struct device *dev)
417{
418 struct i2c_client *client = to_i2c_client(dev);
419 struct lm95241_data *data = i2c_get_clientdata(client);
420
421 mutex_lock(&data->update_lock);
422
423 if (time_after(jiffies, data->last_updated + data->interval) ||
424 !data->valid) {
425 dev_dbg(&client->dev, "Updating lm95241 data.\n");
426 data->local_h =
427 i2c_smbus_read_byte_data(client,
428 LM95241_REG_R_LOCAL_TEMPH);
429 data->local_l =
430 i2c_smbus_read_byte_data(client,
431 LM95241_REG_R_LOCAL_TEMPL);
432 data->remote1_h =
433 i2c_smbus_read_byte_data(client,
434 LM95241_REG_R_REMOTE1_TEMPH);
435 data->remote1_l =
436 i2c_smbus_read_byte_data(client,
437 LM95241_REG_R_REMOTE1_TEMPL);
438 data->remote2_h =
439 i2c_smbus_read_byte_data(client,
440 LM95241_REG_R_REMOTE2_TEMPH);
441 data->remote2_l =
442 i2c_smbus_read_byte_data(client,
443 LM95241_REG_R_REMOTE2_TEMPL);
444 data->last_updated = jiffies;
445 data->valid = 1;
446 }
447
448 mutex_unlock(&data->update_lock);
449
450 return data;
451}
452
453/* Driver data (common to all clients) */ 424/* Driver data (common to all clients) */
454static const struct i2c_device_id lm95241_id[] = { 425static const struct i2c_device_id lm95241_id[] = {
455 { "lm95241", 0 }, 426 { DEVNAME, 0 },
456 { } 427 { }
457}; 428};
458MODULE_DEVICE_TABLE(i2c, lm95241_id); 429MODULE_DEVICE_TABLE(i2c, lm95241_id);
@@ -460,7 +431,7 @@ MODULE_DEVICE_TABLE(i2c, lm95241_id);
460static struct i2c_driver lm95241_driver = { 431static struct i2c_driver lm95241_driver = {
461 .class = I2C_CLASS_HWMON, 432 .class = I2C_CLASS_HWMON,
462 .driver = { 433 .driver = {
463 .name = "lm95241", 434 .name = DEVNAME,
464 }, 435 },
465 .probe = lm95241_probe, 436 .probe = lm95241_probe,
466 .remove = lm95241_remove, 437 .remove = lm95241_remove,
@@ -479,7 +450,7 @@ static void __exit sensors_lm95241_exit(void)
479 i2c_del_driver(&lm95241_driver); 450 i2c_del_driver(&lm95241_driver);
480} 451}
481 452
482MODULE_AUTHOR("Davide Rizzo <elpa-rizzo@gmail.com>"); 453MODULE_AUTHOR("Davide Rizzo <elpa.rizzo@gmail.com>");
483MODULE_DESCRIPTION("LM95241 sensor driver"); 454MODULE_DESCRIPTION("LM95241 sensor driver");
484MODULE_LICENSE("GPL"); 455MODULE_LICENSE("GPL");
485 456
diff --git a/drivers/hwmon/pc87360.c b/drivers/hwmon/pc87360.c
index 68e69a49633c..3d99b8854d7c 100644
--- a/drivers/hwmon/pc87360.c
+++ b/drivers/hwmon/pc87360.c
@@ -33,6 +33,8 @@
33 * the standard Super-I/O addresses is used (0x2E/0x2F or 0x4E/0x4F). 33 * the standard Super-I/O addresses is used (0x2E/0x2F or 0x4E/0x4F).
34 */ 34 */
35 35
36#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
37
36#include <linux/module.h> 38#include <linux/module.h>
37#include <linux/init.h> 39#include <linux/init.h>
38#include <linux/slab.h> 40#include <linux/slab.h>
@@ -1031,16 +1033,15 @@ static int __init pc87360_find(int sioaddr, u8 *devid, unsigned short *addresses
1031 1033
1032 val = superio_inb(sioaddr, ACT); 1034 val = superio_inb(sioaddr, ACT);
1033 if (!(val & 0x01)) { 1035 if (!(val & 0x01)) {
1034 printk(KERN_INFO "pc87360: Device 0x%02x not " 1036 pr_info("Device 0x%02x not activated\n", logdev[i]);
1035 "activated\n", logdev[i]);
1036 continue; 1037 continue;
1037 } 1038 }
1038 1039
1039 val = (superio_inb(sioaddr, BASE) << 8) 1040 val = (superio_inb(sioaddr, BASE) << 8)
1040 | superio_inb(sioaddr, BASE + 1); 1041 | superio_inb(sioaddr, BASE + 1);
1041 if (!val) { 1042 if (!val) {
1042 printk(KERN_INFO "pc87360: Base address not set for " 1043 pr_info("Base address not set for device 0x%02x\n",
1043 "device 0x%02x\n", logdev[i]); 1044 logdev[i]);
1044 continue; 1045 continue;
1045 } 1046 }
1046 1047
@@ -1050,17 +1051,15 @@ static int __init pc87360_find(int sioaddr, u8 *devid, unsigned short *addresses
1050 confreg[0] = superio_inb(sioaddr, 0xF0); 1051 confreg[0] = superio_inb(sioaddr, 0xF0);
1051 confreg[1] = superio_inb(sioaddr, 0xF1); 1052 confreg[1] = superio_inb(sioaddr, 0xF1);
1052 1053
1053#ifdef DEBUG 1054 pr_debug("Fan %d: mon=%d ctrl=%d inv=%d\n", 1,
1054 printk(KERN_DEBUG "pc87360: Fan 1: mon=%d " 1055 (confreg[0] >> 2) & 1, (confreg[0] >> 3) & 1,
1055 "ctrl=%d inv=%d\n", (confreg[0]>>2)&1, 1056 (confreg[0] >> 4) & 1);
1056 (confreg[0]>>3)&1, (confreg[0]>>4)&1); 1057 pr_debug("Fan %d: mon=%d ctrl=%d inv=%d\n", 2,
1057 printk(KERN_DEBUG "pc87360: Fan 2: mon=%d " 1058 (confreg[0] >> 5) & 1, (confreg[0] >> 6) & 1,
1058 "ctrl=%d inv=%d\n", (confreg[0]>>5)&1, 1059 (confreg[0] >> 7) & 1);
1059 (confreg[0]>>6)&1, (confreg[0]>>7)&1); 1060 pr_debug("Fan %d: mon=%d ctrl=%d inv=%d\n", 3,
1060 printk(KERN_DEBUG "pc87360: Fan 3: mon=%d " 1061 confreg[1] & 1, (confreg[1] >> 1) & 1,
1061 "ctrl=%d inv=%d\n", confreg[1]&1, 1062 (confreg[1] >> 2) & 1);
1062 (confreg[1]>>1)&1, (confreg[1]>>2)&1);
1063#endif
1064 } else if (i==1) { /* Voltages */ 1063 } else if (i==1) { /* Voltages */
1065 /* Are we using thermistors? */ 1064 /* Are we using thermistors? */
1066 if (*devid == 0xE9) { /* PC87366 */ 1065 if (*devid == 0xE9) { /* PC87366 */
@@ -1071,14 +1070,12 @@ static int __init pc87360_find(int sioaddr, u8 *devid, unsigned short *addresses
1071 confreg[3] = superio_inb(sioaddr, 0x25); 1070 confreg[3] = superio_inb(sioaddr, 0x25);
1072 1071
1073 if (confreg[2] & 0x40) { 1072 if (confreg[2] & 0x40) {
1074 printk(KERN_INFO "pc87360: Using " 1073 pr_info("Using thermistors for "
1075 "thermistors for temperature " 1074 "temperature monitoring\n");
1076 "monitoring\n");
1077 } 1075 }
1078 if (confreg[3] & 0xE0) { 1076 if (confreg[3] & 0xE0) {
1079 printk(KERN_INFO "pc87360: VID " 1077 pr_info("VID inputs routed (mode %u)\n",
1080 "inputs routed (mode %u)\n", 1078 confreg[3] >> 5);
1081 confreg[3] >> 5);
1082 } 1079 }
1083 } 1080 }
1084 } 1081 }
@@ -1616,7 +1613,7 @@ static int __init pc87360_device_add(unsigned short address)
1616 pdev = platform_device_alloc("pc87360", address); 1613 pdev = platform_device_alloc("pc87360", address);
1617 if (!pdev) { 1614 if (!pdev) {
1618 err = -ENOMEM; 1615 err = -ENOMEM;
1619 printk(KERN_ERR "pc87360: Device allocation failed\n"); 1616 pr_err("Device allocation failed\n");
1620 goto exit; 1617 goto exit;
1621 } 1618 }
1622 1619
@@ -1639,15 +1636,13 @@ static int __init pc87360_device_add(unsigned short address)
1639 1636
1640 err = platform_device_add_resources(pdev, res, res_count); 1637 err = platform_device_add_resources(pdev, res, res_count);
1641 if (err) { 1638 if (err) {
1642 printk(KERN_ERR "pc87360: Device resources addition failed " 1639 pr_err("Device resources addition failed (%d)\n", err);
1643 "(%d)\n", err);
1644 goto exit_device_put; 1640 goto exit_device_put;
1645 } 1641 }
1646 1642
1647 err = platform_device_add(pdev); 1643 err = platform_device_add(pdev);
1648 if (err) { 1644 if (err) {
1649 printk(KERN_ERR "pc87360: Device addition failed (%d)\n", 1645 pr_err("Device addition failed (%d)\n", err);
1650 err);
1651 goto exit_device_put; 1646 goto exit_device_put;
1652 } 1647 }
1653 1648
@@ -1666,8 +1661,7 @@ static int __init pc87360_init(void)
1666 1661
1667 if (pc87360_find(0x2e, &devid, extra_isa) 1662 if (pc87360_find(0x2e, &devid, extra_isa)
1668 && pc87360_find(0x4e, &devid, extra_isa)) { 1663 && pc87360_find(0x4e, &devid, extra_isa)) {
1669 printk(KERN_WARNING "pc87360: PC8736x not detected, " 1664 pr_warn("PC8736x not detected, module not inserted\n");
1670 "module not inserted.\n");
1671 return -ENODEV; 1665 return -ENODEV;
1672 } 1666 }
1673 1667
@@ -1680,8 +1674,7 @@ static int __init pc87360_init(void)
1680 } 1674 }
1681 1675
1682 if (address == 0x0000) { 1676 if (address == 0x0000) {
1683 printk(KERN_WARNING "pc87360: No active logical device, " 1677 pr_warn("No active logical device, module not inserted\n");
1684 "module not inserted.\n");
1685 return -ENODEV; 1678 return -ENODEV;
1686 } 1679 }
1687 1680
diff --git a/drivers/hwmon/pc87427.c b/drivers/hwmon/pc87427.c
index 9ec4daaf6ca6..8da2181630b1 100644
--- a/drivers/hwmon/pc87427.c
+++ b/drivers/hwmon/pc87427.c
@@ -22,6 +22,8 @@
22 * mode, and voltages aren't supported at all. 22 * mode, and voltages aren't supported at all.
23 */ 23 */
24 24
25#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
26
25#include <linux/module.h> 27#include <linux/module.h>
26#include <linux/init.h> 28#include <linux/init.h>
27#include <linux/slab.h> 29#include <linux/slab.h>
@@ -1077,7 +1079,7 @@ static int __devinit pc87427_probe(struct platform_device *pdev)
1077 data = kzalloc(sizeof(struct pc87427_data), GFP_KERNEL); 1079 data = kzalloc(sizeof(struct pc87427_data), GFP_KERNEL);
1078 if (!data) { 1080 if (!data) {
1079 err = -ENOMEM; 1081 err = -ENOMEM;
1080 printk(KERN_ERR DRVNAME ": Out of memory\n"); 1082 pr_err("Out of memory\n");
1081 goto exit; 1083 goto exit;
1082 } 1084 }
1083 1085
@@ -1196,28 +1198,26 @@ static int __init pc87427_device_add(const struct pc87427_sio_data *sio_data)
1196 pdev = platform_device_alloc(DRVNAME, res[0].start); 1198 pdev = platform_device_alloc(DRVNAME, res[0].start);
1197 if (!pdev) { 1199 if (!pdev) {
1198 err = -ENOMEM; 1200 err = -ENOMEM;
1199 printk(KERN_ERR DRVNAME ": Device allocation failed\n"); 1201 pr_err("Device allocation failed\n");
1200 goto exit; 1202 goto exit;
1201 } 1203 }
1202 1204
1203 err = platform_device_add_resources(pdev, res, res_count); 1205 err = platform_device_add_resources(pdev, res, res_count);
1204 if (err) { 1206 if (err) {
1205 printk(KERN_ERR DRVNAME ": Device resource addition failed " 1207 pr_err("Device resource addition failed (%d)\n", err);
1206 "(%d)\n", err);
1207 goto exit_device_put; 1208 goto exit_device_put;
1208 } 1209 }
1209 1210
1210 err = platform_device_add_data(pdev, sio_data, 1211 err = platform_device_add_data(pdev, sio_data,
1211 sizeof(struct pc87427_sio_data)); 1212 sizeof(struct pc87427_sio_data));
1212 if (err) { 1213 if (err) {
1213 printk(KERN_ERR DRVNAME ": Platform data allocation failed\n"); 1214 pr_err("Platform data allocation failed\n");
1214 goto exit_device_put; 1215 goto exit_device_put;
1215 } 1216 }
1216 1217
1217 err = platform_device_add(pdev); 1218 err = platform_device_add(pdev);
1218 if (err) { 1219 if (err) {
1219 printk(KERN_ERR DRVNAME ": Device addition failed (%d)\n", 1220 pr_err("Device addition failed (%d)\n", err);
1220 err);
1221 goto exit_device_put; 1221 goto exit_device_put;
1222 } 1222 }
1223 1223
@@ -1249,23 +1249,23 @@ static int __init pc87427_find(int sioaddr, struct pc87427_sio_data *sio_data)
1249 1249
1250 val = superio_inb(sioaddr, SIOREG_ACT); 1250 val = superio_inb(sioaddr, SIOREG_ACT);
1251 if (!(val & 0x01)) { 1251 if (!(val & 0x01)) {
1252 printk(KERN_INFO DRVNAME ": Logical device 0x%02x " 1252 pr_info("Logical device 0x%02x not activated\n",
1253 "not activated\n", logdev[i]); 1253 logdev[i]);
1254 continue; 1254 continue;
1255 } 1255 }
1256 1256
1257 val = superio_inb(sioaddr, SIOREG_MAP); 1257 val = superio_inb(sioaddr, SIOREG_MAP);
1258 if (val & 0x01) { 1258 if (val & 0x01) {
1259 printk(KERN_WARNING DRVNAME ": Logical device 0x%02x " 1259 pr_warn("Logical device 0x%02x is memory-mapped, "
1260 "is memory-mapped, can't use\n", logdev[i]); 1260 "can't use\n", logdev[i]);
1261 continue; 1261 continue;
1262 } 1262 }
1263 1263
1264 val = (superio_inb(sioaddr, SIOREG_IOBASE) << 8) 1264 val = (superio_inb(sioaddr, SIOREG_IOBASE) << 8)
1265 | superio_inb(sioaddr, SIOREG_IOBASE + 1); 1265 | superio_inb(sioaddr, SIOREG_IOBASE + 1);
1266 if (!val) { 1266 if (!val) {
1267 printk(KERN_INFO DRVNAME ": I/O base address not set " 1267 pr_info("I/O base address not set for logical device "
1268 "for logical device 0x%02x\n", logdev[i]); 1268 "0x%02x\n", logdev[i]);
1269 continue; 1269 continue;
1270 } 1270 }
1271 sio_data->address[i] = val; 1271 sio_data->address[i] = val;
diff --git a/drivers/hwmon/pcf8591.c b/drivers/hwmon/pcf8591.c
index dc7259d69812..731b09af76b9 100644
--- a/drivers/hwmon/pcf8591.c
+++ b/drivers/hwmon/pcf8591.c
@@ -18,6 +18,8 @@
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19*/ 19*/
20 20
21#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
22
21#include <linux/module.h> 23#include <linux/module.h>
22#include <linux/init.h> 24#include <linux/init.h>
23#include <linux/slab.h> 25#include <linux/slab.h>
@@ -290,8 +292,7 @@ static struct i2c_driver pcf8591_driver = {
290static int __init pcf8591_init(void) 292static int __init pcf8591_init(void)
291{ 293{
292 if (input_mode < 0 || input_mode > 3) { 294 if (input_mode < 0 || input_mode > 3) {
293 printk(KERN_WARNING "pcf8591: invalid input_mode (%d)\n", 295 pr_warn("invalid input_mode (%d)\n", input_mode);
294 input_mode);
295 input_mode = 0; 296 input_mode = 0;
296 } 297 }
297 return i2c_add_driver(&pcf8591_driver); 298 return i2c_add_driver(&pcf8591_driver);
diff --git a/drivers/hwmon/pkgtemp.c b/drivers/hwmon/pkgtemp.c
index 0798210590bc..21c817d98123 100644
--- a/drivers/hwmon/pkgtemp.c
+++ b/drivers/hwmon/pkgtemp.c
@@ -20,6 +20,8 @@
20 * 02110-1301 USA. 20 * 02110-1301 USA.
21 */ 21 */
22 22
23#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
24
23#include <linux/module.h> 25#include <linux/module.h>
24#include <linux/init.h> 26#include <linux/init.h>
25#include <linux/slab.h> 27#include <linux/slab.h>
@@ -303,7 +305,7 @@ static int __cpuinit pkgtemp_device_add(unsigned int cpu)
303 pdev = platform_device_alloc(DRVNAME, cpu); 305 pdev = platform_device_alloc(DRVNAME, cpu);
304 if (!pdev) { 306 if (!pdev) {
305 err = -ENOMEM; 307 err = -ENOMEM;
306 printk(KERN_ERR DRVNAME ": Device allocation failed\n"); 308 pr_err("Device allocation failed\n");
307 goto exit; 309 goto exit;
308 } 310 }
309 311
@@ -315,8 +317,7 @@ static int __cpuinit pkgtemp_device_add(unsigned int cpu)
315 317
316 err = platform_device_add(pdev); 318 err = platform_device_add(pdev);
317 if (err) { 319 if (err) {
318 printk(KERN_ERR DRVNAME ": Device addition failed (%d)\n", 320 pr_err("Device addition failed (%d)\n", err);
319 err);
320 goto exit_device_free; 321 goto exit_device_free;
321 } 322 }
322 323
diff --git a/drivers/hwmon/sht21.c b/drivers/hwmon/sht21.c
new file mode 100644
index 000000000000..1c8c9812f244
--- /dev/null
+++ b/drivers/hwmon/sht21.c
@@ -0,0 +1,307 @@
1/* Sensirion SHT21 humidity and temperature sensor driver
2 *
3 * Copyright (C) 2010 Urs Fleisch <urs.fleisch@sensirion.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA
18 *
19 * Data sheet available (5/2010) at
20 * http://www.sensirion.com/en/pdf/product_information/Datasheet-humidity-sensor-SHT21.pdf
21 */
22
23#include <linux/module.h>
24#include <linux/init.h>
25#include <linux/slab.h>
26#include <linux/i2c.h>
27#include <linux/hwmon.h>
28#include <linux/hwmon-sysfs.h>
29#include <linux/err.h>
30#include <linux/mutex.h>
31#include <linux/device.h>
32
33/* I2C command bytes */
34#define SHT21_TRIG_T_MEASUREMENT_HM 0xe3
35#define SHT21_TRIG_RH_MEASUREMENT_HM 0xe5
36
37/**
38 * struct sht21 - SHT21 device specific data
39 * @hwmon_dev: device registered with hwmon
40 * @lock: mutex to protect measurement values
41 * @valid: only 0 before first measurement is taken
42 * @last_update: time of last update (jiffies)
43 * @temperature: cached temperature measurement value
44 * @humidity: cached humidity measurement value
45 */
46struct sht21 {
47 struct device *hwmon_dev;
48 struct mutex lock;
49 char valid;
50 unsigned long last_update;
51 int temperature;
52 int humidity;
53};
54
55/**
56 * sht21_temp_ticks_to_millicelsius() - convert raw temperature ticks to
57 * milli celsius
58 * @ticks: temperature ticks value received from sensor
59 */
60static inline int sht21_temp_ticks_to_millicelsius(int ticks)
61{
62 ticks &= ~0x0003; /* clear status bits */
63 /*
64 * Formula T = -46.85 + 175.72 * ST / 2^16 from data sheet 6.2,
65 * optimized for integer fixed point (3 digits) arithmetic
66 */
67 return ((21965 * ticks) >> 13) - 46850;
68}
69
70/**
71 * sht21_rh_ticks_to_per_cent_mille() - convert raw humidity ticks to
72 * one-thousandths of a percent relative humidity
73 * @ticks: humidity ticks value received from sensor
74 */
75static inline int sht21_rh_ticks_to_per_cent_mille(int ticks)
76{
77 ticks &= ~0x0003; /* clear status bits */
78 /*
79 * Formula RH = -6 + 125 * SRH / 2^16 from data sheet 6.1,
80 * optimized for integer fixed point (3 digits) arithmetic
81 */
82 return ((15625 * ticks) >> 13) - 6000;
83}
84
85/**
86 * sht21_read_word_data() - read word from register
87 * @client: I2C client device
88 * @reg: I2C command byte
89 *
90 * Returns value, negative errno on error.
91 */
92static inline int sht21_read_word_data(struct i2c_client *client, u8 reg)
93{
94 int ret = i2c_smbus_read_word_data(client, reg);
95 if (ret < 0)
96 return ret;
97 /*
98 * SMBus specifies low byte first, but the SHT21 returns MSB
99 * first, so we have to swab16 the values
100 */
101 return swab16(ret);
102}
103
104/**
105 * sht21_update_measurements() - get updated measurements from device
106 * @client: I2C client device
107 *
108 * Returns 0 on success, else negative errno.
109 */
110static int sht21_update_measurements(struct i2c_client *client)
111{
112 int ret = 0;
113 struct sht21 *sht21 = i2c_get_clientdata(client);
114
115 mutex_lock(&sht21->lock);
116 /*
117 * Data sheet 2.4:
118 * SHT2x should not be active for more than 10% of the time - e.g.
119 * maximum two measurements per second at 12bit accuracy shall be made.
120 */
121 if (time_after(jiffies, sht21->last_update + HZ / 2) || !sht21->valid) {
122 ret = sht21_read_word_data(client, SHT21_TRIG_T_MEASUREMENT_HM);
123 if (ret < 0)
124 goto out;
125 sht21->temperature = sht21_temp_ticks_to_millicelsius(ret);
126 ret = sht21_read_word_data(client,
127 SHT21_TRIG_RH_MEASUREMENT_HM);
128 if (ret < 0)
129 goto out;
130 sht21->humidity = sht21_rh_ticks_to_per_cent_mille(ret);
131 sht21->last_update = jiffies;
132 sht21->valid = 1;
133 }
134out:
135 mutex_unlock(&sht21->lock);
136
137 return ret >= 0 ? 0 : ret;
138}
139
140/**
141 * sht21_show_temperature() - show temperature measurement value in sysfs
142 * @dev: device
143 * @attr: device attribute
144 * @buf: sysfs buffer (PAGE_SIZE) where measurement values are written to
145 *
146 * Will be called on read access to temp1_input sysfs attribute.
147 * Returns number of bytes written into buffer, negative errno on error.
148 */
149static ssize_t sht21_show_temperature(struct device *dev,
150 struct device_attribute *attr,
151 char *buf)
152{
153 struct i2c_client *client = to_i2c_client(dev);
154 struct sht21 *sht21 = i2c_get_clientdata(client);
155 int ret = sht21_update_measurements(client);
156 if (ret < 0)
157 return ret;
158 return sprintf(buf, "%d\n", sht21->temperature);
159}
160
161/**
162 * sht21_show_humidity() - show humidity measurement value in sysfs
163 * @dev: device
164 * @attr: device attribute
165 * @buf: sysfs buffer (PAGE_SIZE) where measurement values are written to
166 *
167 * Will be called on read access to humidity1_input sysfs attribute.
168 * Returns number of bytes written into buffer, negative errno on error.
169 */
170static ssize_t sht21_show_humidity(struct device *dev,
171 struct device_attribute *attr,
172 char *buf)
173{
174 struct i2c_client *client = to_i2c_client(dev);
175 struct sht21 *sht21 = i2c_get_clientdata(client);
176 int ret = sht21_update_measurements(client);
177 if (ret < 0)
178 return ret;
179 return sprintf(buf, "%d\n", sht21->humidity);
180}
181
182/* sysfs attributes */
183static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, sht21_show_temperature,
184 NULL, 0);
185static SENSOR_DEVICE_ATTR(humidity1_input, S_IRUGO, sht21_show_humidity,
186 NULL, 0);
187
188static struct attribute *sht21_attributes[] = {
189 &sensor_dev_attr_temp1_input.dev_attr.attr,
190 &sensor_dev_attr_humidity1_input.dev_attr.attr,
191 NULL
192};
193
194static const struct attribute_group sht21_attr_group = {
195 .attrs = sht21_attributes,
196};
197
198/**
199 * sht21_probe() - probe device
200 * @client: I2C client device
201 * @id: device ID
202 *
203 * Called by the I2C core when an entry in the ID table matches a
204 * device's name.
205 * Returns 0 on success.
206 */
207static int __devinit sht21_probe(struct i2c_client *client,
208 const struct i2c_device_id *id)
209{
210 struct sht21 *sht21;
211 int err;
212
213 if (!i2c_check_functionality(client->adapter,
214 I2C_FUNC_SMBUS_WORD_DATA)) {
215 dev_err(&client->dev,
216 "adapter does not support SMBus word transactions\n");
217 return -ENODEV;
218 }
219
220 sht21 = kzalloc(sizeof(*sht21), GFP_KERNEL);
221 if (!sht21) {
222 dev_dbg(&client->dev, "kzalloc failed\n");
223 return -ENOMEM;
224 }
225 i2c_set_clientdata(client, sht21);
226
227 mutex_init(&sht21->lock);
228
229 err = sysfs_create_group(&client->dev.kobj, &sht21_attr_group);
230 if (err) {
231 dev_dbg(&client->dev, "could not create sysfs files\n");
232 goto fail_free;
233 }
234 sht21->hwmon_dev = hwmon_device_register(&client->dev);
235 if (IS_ERR(sht21->hwmon_dev)) {
236 dev_dbg(&client->dev, "unable to register hwmon device\n");
237 err = PTR_ERR(sht21->hwmon_dev);
238 goto fail_remove_sysfs;
239 }
240
241 dev_info(&client->dev, "initialized\n");
242
243 return 0;
244
245fail_remove_sysfs:
246 sysfs_remove_group(&client->dev.kobj, &sht21_attr_group);
247fail_free:
248 kfree(sht21);
249
250 return err;
251}
252
253/**
254 * sht21_remove() - remove device
255 * @client: I2C client device
256 */
257static int __devexit sht21_remove(struct i2c_client *client)
258{
259 struct sht21 *sht21 = i2c_get_clientdata(client);
260
261 hwmon_device_unregister(sht21->hwmon_dev);
262 sysfs_remove_group(&client->dev.kobj, &sht21_attr_group);
263 kfree(sht21);
264
265 return 0;
266}
267
268/* Device ID table */
269static const struct i2c_device_id sht21_id[] = {
270 { "sht21", 0 },
271 { }
272};
273MODULE_DEVICE_TABLE(i2c, sht21_id);
274
275static struct i2c_driver sht21_driver = {
276 .driver.name = "sht21",
277 .probe = sht21_probe,
278 .remove = __devexit_p(sht21_remove),
279 .id_table = sht21_id,
280};
281
282/**
283 * sht21_init() - initialize driver
284 *
285 * Called when kernel is booted or module is inserted.
286 * Returns 0 on success.
287 */
288static int __init sht21_init(void)
289{
290 return i2c_add_driver(&sht21_driver);
291}
292module_init(sht21_init);
293
294/**
295 * sht21_init() - clean up driver
296 *
297 * Called when module is removed.
298 */
299static void __exit sht21_exit(void)
300{
301 i2c_del_driver(&sht21_driver);
302}
303module_exit(sht21_exit);
304
305MODULE_AUTHOR("Urs Fleisch <urs.fleisch@sensirion.com>");
306MODULE_DESCRIPTION("Sensirion SHT21 humidity and temperature sensor driver");
307MODULE_LICENSE("GPL");
diff --git a/drivers/hwmon/sis5595.c b/drivers/hwmon/sis5595.c
index 79c2931e3008..47d7ce9af8fb 100644
--- a/drivers/hwmon/sis5595.c
+++ b/drivers/hwmon/sis5595.c
@@ -50,6 +50,8 @@
50 735 0008 0735 50 735 0008 0735
51*/ 51*/
52 52
53#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
54
53#include <linux/module.h> 55#include <linux/module.h>
54#include <linux/slab.h> 56#include <linux/slab.h>
55#include <linux/ioport.h> 57#include <linux/ioport.h>
@@ -735,21 +737,19 @@ static int __devinit sis5595_device_add(unsigned short address)
735 pdev = platform_device_alloc("sis5595", address); 737 pdev = platform_device_alloc("sis5595", address);
736 if (!pdev) { 738 if (!pdev) {
737 err = -ENOMEM; 739 err = -ENOMEM;
738 printk(KERN_ERR "sis5595: Device allocation failed\n"); 740 pr_err("Device allocation failed\n");
739 goto exit; 741 goto exit;
740 } 742 }
741 743
742 err = platform_device_add_resources(pdev, &res, 1); 744 err = platform_device_add_resources(pdev, &res, 1);
743 if (err) { 745 if (err) {
744 printk(KERN_ERR "sis5595: Device resource addition failed " 746 pr_err("Device resource addition failed (%d)\n", err);
745 "(%d)\n", err);
746 goto exit_device_put; 747 goto exit_device_put;
747 } 748 }
748 749
749 err = platform_device_add(pdev); 750 err = platform_device_add(pdev);
750 if (err) { 751 if (err) {
751 printk(KERN_ERR "sis5595: Device addition failed (%d)\n", 752 pr_err("Device addition failed (%d)\n", err);
752 err);
753 goto exit_device_put; 753 goto exit_device_put;
754 } 754 }
755 755
diff --git a/drivers/hwmon/smsc47b397.c b/drivers/hwmon/smsc47b397.c
index f46d936c12da..9fb7516e6f45 100644
--- a/drivers/hwmon/smsc47b397.c
+++ b/drivers/hwmon/smsc47b397.c
@@ -26,6 +26,8 @@
26 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 26 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27*/ 27*/
28 28
29#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
30
29#include <linux/module.h> 31#include <linux/module.h>
30#include <linux/slab.h> 32#include <linux/slab.h>
31#include <linux/ioport.h> 33#include <linux/ioport.h>
@@ -311,21 +313,19 @@ static int __init smsc47b397_device_add(unsigned short address)
311 pdev = platform_device_alloc(DRVNAME, address); 313 pdev = platform_device_alloc(DRVNAME, address);
312 if (!pdev) { 314 if (!pdev) {
313 err = -ENOMEM; 315 err = -ENOMEM;
314 printk(KERN_ERR DRVNAME ": Device allocation failed\n"); 316 pr_err("Device allocation failed\n");
315 goto exit; 317 goto exit;
316 } 318 }
317 319
318 err = platform_device_add_resources(pdev, &res, 1); 320 err = platform_device_add_resources(pdev, &res, 1);
319 if (err) { 321 if (err) {
320 printk(KERN_ERR DRVNAME ": Device resource addition failed " 322 pr_err("Device resource addition failed (%d)\n", err);
321 "(%d)\n", err);
322 goto exit_device_put; 323 goto exit_device_put;
323 } 324 }
324 325
325 err = platform_device_add(pdev); 326 err = platform_device_add(pdev);
326 if (err) { 327 if (err) {
327 printk(KERN_ERR DRVNAME ": Device addition failed (%d)\n", 328 pr_err("Device addition failed (%d)\n", err);
328 err);
329 goto exit_device_put; 329 goto exit_device_put;
330 } 330 }
331 331
@@ -367,8 +367,7 @@ static int __init smsc47b397_find(unsigned short *addr)
367 *addr = (superio_inb(SUPERIO_REG_BASE_MSB) << 8) 367 *addr = (superio_inb(SUPERIO_REG_BASE_MSB) << 8)
368 | superio_inb(SUPERIO_REG_BASE_LSB); 368 | superio_inb(SUPERIO_REG_BASE_LSB);
369 369
370 printk(KERN_INFO DRVNAME ": found SMSC %s " 370 pr_info("found SMSC %s (base address 0x%04x, revision %u)\n",
371 "(base address 0x%04x, revision %u)\n",
372 name, *addr, rev); 371 name, *addr, rev);
373 372
374 superio_exit(); 373 superio_exit();
diff --git a/drivers/hwmon/smsc47m1.c b/drivers/hwmon/smsc47m1.c
index 8fa462f2b570..f44a89aac381 100644
--- a/drivers/hwmon/smsc47m1.c
+++ b/drivers/hwmon/smsc47m1.c
@@ -26,6 +26,8 @@
26 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 26 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27*/ 27*/
28 28
29#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
30
29#include <linux/module.h> 31#include <linux/module.h>
30#include <linux/slab.h> 32#include <linux/slab.h>
31#include <linux/ioport.h> 33#include <linux/ioport.h>
@@ -435,30 +437,29 @@ static int __init smsc47m1_find(unsigned short *addr,
435 */ 437 */
436 switch (val) { 438 switch (val) {
437 case 0x51: 439 case 0x51:
438 pr_info(DRVNAME ": Found SMSC LPC47B27x\n"); 440 pr_info("Found SMSC LPC47B27x\n");
439 sio_data->type = smsc47m1; 441 sio_data->type = smsc47m1;
440 break; 442 break;
441 case 0x59: 443 case 0x59:
442 pr_info(DRVNAME ": Found SMSC LPC47M10x/LPC47M112/LPC47M13x\n"); 444 pr_info("Found SMSC LPC47M10x/LPC47M112/LPC47M13x\n");
443 sio_data->type = smsc47m1; 445 sio_data->type = smsc47m1;
444 break; 446 break;
445 case 0x5F: 447 case 0x5F:
446 pr_info(DRVNAME ": Found SMSC LPC47M14x\n"); 448 pr_info("Found SMSC LPC47M14x\n");
447 sio_data->type = smsc47m1; 449 sio_data->type = smsc47m1;
448 break; 450 break;
449 case 0x60: 451 case 0x60:
450 pr_info(DRVNAME ": Found SMSC LPC47M15x/LPC47M192/LPC47M997\n"); 452 pr_info("Found SMSC LPC47M15x/LPC47M192/LPC47M997\n");
451 sio_data->type = smsc47m1; 453 sio_data->type = smsc47m1;
452 break; 454 break;
453 case 0x6B: 455 case 0x6B:
454 if (superio_inb(SUPERIO_REG_DEVREV) & 0x80) { 456 if (superio_inb(SUPERIO_REG_DEVREV) & 0x80) {
455 pr_debug(DRVNAME ": " 457 pr_debug("Found SMSC LPC47M233, unsupported\n");
456 "Found SMSC LPC47M233, unsupported\n");
457 superio_exit(); 458 superio_exit();
458 return -ENODEV; 459 return -ENODEV;
459 } 460 }
460 461
461 pr_info(DRVNAME ": Found SMSC LPC47M292\n"); 462 pr_info("Found SMSC LPC47M292\n");
462 sio_data->type = smsc47m2; 463 sio_data->type = smsc47m2;
463 break; 464 break;
464 default: 465 default:
@@ -470,7 +471,7 @@ static int __init smsc47m1_find(unsigned short *addr,
470 *addr = (superio_inb(SUPERIO_REG_BASE) << 8) 471 *addr = (superio_inb(SUPERIO_REG_BASE) << 8)
471 | superio_inb(SUPERIO_REG_BASE + 1); 472 | superio_inb(SUPERIO_REG_BASE + 1);
472 if (*addr == 0) { 473 if (*addr == 0) {
473 pr_info(DRVNAME ": Device address not set, will not use\n"); 474 pr_info("Device address not set, will not use\n");
474 superio_exit(); 475 superio_exit();
475 return -ENODEV; 476 return -ENODEV;
476 } 477 }
@@ -479,7 +480,7 @@ static int __init smsc47m1_find(unsigned short *addr,
479 * Compaq Presario S4000NX) */ 480 * Compaq Presario S4000NX) */
480 sio_data->activate = superio_inb(SUPERIO_REG_ACT); 481 sio_data->activate = superio_inb(SUPERIO_REG_ACT);
481 if ((sio_data->activate & 0x01) == 0) { 482 if ((sio_data->activate & 0x01) == 0) {
482 pr_info(DRVNAME ": Enabling device\n"); 483 pr_info("Enabling device\n");
483 superio_outb(SUPERIO_REG_ACT, sio_data->activate | 0x01); 484 superio_outb(SUPERIO_REG_ACT, sio_data->activate | 0x01);
484 } 485 }
485 486
@@ -494,7 +495,7 @@ static void smsc47m1_restore(const struct smsc47m1_sio_data *sio_data)
494 superio_enter(); 495 superio_enter();
495 superio_select(); 496 superio_select();
496 497
497 pr_info(DRVNAME ": Disabling device\n"); 498 pr_info("Disabling device\n");
498 superio_outb(SUPERIO_REG_ACT, sio_data->activate); 499 superio_outb(SUPERIO_REG_ACT, sio_data->activate);
499 500
500 superio_exit(); 501 superio_exit();
@@ -823,28 +824,26 @@ static int __init smsc47m1_device_add(unsigned short address,
823 pdev = platform_device_alloc(DRVNAME, address); 824 pdev = platform_device_alloc(DRVNAME, address);
824 if (!pdev) { 825 if (!pdev) {
825 err = -ENOMEM; 826 err = -ENOMEM;
826 printk(KERN_ERR DRVNAME ": Device allocation failed\n"); 827 pr_err("Device allocation failed\n");
827 goto exit; 828 goto exit;
828 } 829 }
829 830
830 err = platform_device_add_resources(pdev, &res, 1); 831 err = platform_device_add_resources(pdev, &res, 1);
831 if (err) { 832 if (err) {
832 printk(KERN_ERR DRVNAME ": Device resource addition failed " 833 pr_err("Device resource addition failed (%d)\n", err);
833 "(%d)\n", err);
834 goto exit_device_put; 834 goto exit_device_put;
835 } 835 }
836 836
837 err = platform_device_add_data(pdev, sio_data, 837 err = platform_device_add_data(pdev, sio_data,
838 sizeof(struct smsc47m1_sio_data)); 838 sizeof(struct smsc47m1_sio_data));
839 if (err) { 839 if (err) {
840 printk(KERN_ERR DRVNAME ": Platform data allocation failed\n"); 840 pr_err("Platform data allocation failed\n");
841 goto exit_device_put; 841 goto exit_device_put;
842 } 842 }
843 843
844 err = platform_device_add(pdev); 844 err = platform_device_add(pdev);
845 if (err) { 845 if (err) {
846 printk(KERN_ERR DRVNAME ": Device addition failed (%d)\n", 846 pr_err("Device addition failed (%d)\n", err);
847 err);
848 goto exit_device_put; 847 goto exit_device_put;
849 } 848 }
850 849
diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
index ec7fad747adc..0d18de424c66 100644
--- a/drivers/hwmon/via-cputemp.c
+++ b/drivers/hwmon/via-cputemp.c
@@ -21,6 +21,8 @@
21 * 02110-1301 USA. 21 * 02110-1301 USA.
22 */ 22 */
23 23
24#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
25
24#include <linux/module.h> 26#include <linux/module.h>
25#include <linux/init.h> 27#include <linux/init.h>
26#include <linux/slab.h> 28#include <linux/slab.h>
@@ -202,7 +204,7 @@ static int __cpuinit via_cputemp_device_add(unsigned int cpu)
202 pdev = platform_device_alloc(DRVNAME, cpu); 204 pdev = platform_device_alloc(DRVNAME, cpu);
203 if (!pdev) { 205 if (!pdev) {
204 err = -ENOMEM; 206 err = -ENOMEM;
205 printk(KERN_ERR DRVNAME ": Device allocation failed\n"); 207 pr_err("Device allocation failed\n");
206 goto exit; 208 goto exit;
207 } 209 }
208 210
@@ -214,8 +216,7 @@ static int __cpuinit via_cputemp_device_add(unsigned int cpu)
214 216
215 err = platform_device_add(pdev); 217 err = platform_device_add(pdev);
216 if (err) { 218 if (err) {
217 printk(KERN_ERR DRVNAME ": Device addition failed (%d)\n", 219 pr_err("Device addition failed (%d)\n", err);
218 err);
219 goto exit_device_free; 220 goto exit_device_free;
220 } 221 }
221 222
@@ -237,13 +238,16 @@ exit:
237 238
238static void __cpuinit via_cputemp_device_remove(unsigned int cpu) 239static void __cpuinit via_cputemp_device_remove(unsigned int cpu)
239{ 240{
240 struct pdev_entry *p, *n; 241 struct pdev_entry *p;
242
241 mutex_lock(&pdev_list_mutex); 243 mutex_lock(&pdev_list_mutex);
242 list_for_each_entry_safe(p, n, &pdev_list, list) { 244 list_for_each_entry(p, &pdev_list, list) {
243 if (p->cpu == cpu) { 245 if (p->cpu == cpu) {
244 platform_device_unregister(p->pdev); 246 platform_device_unregister(p->pdev);
245 list_del(&p->list); 247 list_del(&p->list);
248 mutex_unlock(&pdev_list_mutex);
246 kfree(p); 249 kfree(p);
250 return;
247 } 251 }
248 } 252 }
249 mutex_unlock(&pdev_list_mutex); 253 mutex_unlock(&pdev_list_mutex);
@@ -273,7 +277,6 @@ static struct notifier_block via_cputemp_cpu_notifier __refdata = {
273static int __init via_cputemp_init(void) 277static int __init via_cputemp_init(void)
274{ 278{
275 int i, err; 279 int i, err;
276 struct pdev_entry *p, *n;
277 280
278 if (cpu_data(0).x86_vendor != X86_VENDOR_CENTAUR) { 281 if (cpu_data(0).x86_vendor != X86_VENDOR_CENTAUR) {
279 printk(KERN_DEBUG DRVNAME ": Not a VIA CPU\n"); 282 printk(KERN_DEBUG DRVNAME ": Not a VIA CPU\n");
@@ -295,33 +298,27 @@ static int __init via_cputemp_init(void)
295 continue; 298 continue;
296 299
297 if (c->x86_model > 0x0f) { 300 if (c->x86_model > 0x0f) {
298 printk(KERN_WARNING DRVNAME ": Unknown CPU " 301 pr_warn("Unknown CPU model 0x%x\n", c->x86_model);
299 "model 0x%x\n", c->x86_model);
300 continue; 302 continue;
301 } 303 }
302 304
303 err = via_cputemp_device_add(i); 305 via_cputemp_device_add(i);
304 if (err)
305 goto exit_devices_unreg;
306 } 306 }
307
308#ifndef CONFIG_HOTPLUG_CPU
307 if (list_empty(&pdev_list)) { 309 if (list_empty(&pdev_list)) {
308 err = -ENODEV; 310 err = -ENODEV;
309 goto exit_driver_unreg; 311 goto exit_driver_unreg;
310 } 312 }
313#endif
311 314
312 register_hotcpu_notifier(&via_cputemp_cpu_notifier); 315 register_hotcpu_notifier(&via_cputemp_cpu_notifier);
313 return 0; 316 return 0;
314 317
315exit_devices_unreg: 318#ifndef CONFIG_HOTPLUG_CPU
316 mutex_lock(&pdev_list_mutex);
317 list_for_each_entry_safe(p, n, &pdev_list, list) {
318 platform_device_unregister(p->pdev);
319 list_del(&p->list);
320 kfree(p);
321 }
322 mutex_unlock(&pdev_list_mutex);
323exit_driver_unreg: 319exit_driver_unreg:
324 platform_driver_unregister(&via_cputemp_driver); 320 platform_driver_unregister(&via_cputemp_driver);
321#endif
325exit: 322exit:
326 return err; 323 return err;
327} 324}
diff --git a/drivers/hwmon/via686a.c b/drivers/hwmon/via686a.c
index f397ce7ad598..25e91665a0a2 100644
--- a/drivers/hwmon/via686a.c
+++ b/drivers/hwmon/via686a.c
@@ -30,6 +30,8 @@
30 Warning - only supports a single device. 30 Warning - only supports a single device.
31*/ 31*/
32 32
33#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
34
33#include <linux/module.h> 35#include <linux/module.h>
34#include <linux/slab.h> 36#include <linux/slab.h>
35#include <linux/pci.h> 37#include <linux/pci.h>
@@ -687,6 +689,13 @@ static int __devexit via686a_remove(struct platform_device *pdev)
687 return 0; 689 return 0;
688} 690}
689 691
692static void via686a_update_fan_div(struct via686a_data *data)
693{
694 int reg = via686a_read_value(data, VIA686A_REG_FANDIV);
695 data->fan_div[0] = (reg >> 4) & 0x03;
696 data->fan_div[1] = reg >> 6;
697}
698
690static void __devinit via686a_init_device(struct via686a_data *data) 699static void __devinit via686a_init_device(struct via686a_data *data)
691{ 700{
692 u8 reg; 701 u8 reg;
@@ -700,6 +709,9 @@ static void __devinit via686a_init_device(struct via686a_data *data)
700 via686a_write_value(data, VIA686A_REG_TEMP_MODE, 709 via686a_write_value(data, VIA686A_REG_TEMP_MODE,
701 (reg & ~VIA686A_TEMP_MODE_MASK) 710 (reg & ~VIA686A_TEMP_MODE_MASK)
702 | VIA686A_TEMP_MODE_CONTINUOUS); 711 | VIA686A_TEMP_MODE_CONTINUOUS);
712
713 /* Pre-read fan clock divisor values */
714 via686a_update_fan_div(data);
703} 715}
704 716
705static struct via686a_data *via686a_update_device(struct device *dev) 717static struct via686a_data *via686a_update_device(struct device *dev)
@@ -751,9 +763,7 @@ static struct via686a_data *via686a_update_device(struct device *dev)
751 (via686a_read_value(data, VIA686A_REG_TEMP_LOW23) & 763 (via686a_read_value(data, VIA686A_REG_TEMP_LOW23) &
752 0xc0) >> 6; 764 0xc0) >> 6;
753 765
754 i = via686a_read_value(data, VIA686A_REG_FANDIV); 766 via686a_update_fan_div(data);
755 data->fan_div[0] = (i >> 4) & 0x03;
756 data->fan_div[1] = i >> 6;
757 data->alarms = 767 data->alarms =
758 via686a_read_value(data, 768 via686a_read_value(data,
759 VIA686A_REG_ALARM1) | 769 VIA686A_REG_ALARM1) |
@@ -791,21 +801,19 @@ static int __devinit via686a_device_add(unsigned short address)
791 pdev = platform_device_alloc("via686a", address); 801 pdev = platform_device_alloc("via686a", address);
792 if (!pdev) { 802 if (!pdev) {
793 err = -ENOMEM; 803 err = -ENOMEM;
794 printk(KERN_ERR "via686a: Device allocation failed\n"); 804 pr_err("Device allocation failed\n");
795 goto exit; 805 goto exit;
796 } 806 }
797 807
798 err = platform_device_add_resources(pdev, &res, 1); 808 err = platform_device_add_resources(pdev, &res, 1);
799 if (err) { 809 if (err) {
800 printk(KERN_ERR "via686a: Device resource addition failed " 810 pr_err("Device resource addition failed (%d)\n", err);
801 "(%d)\n", err);
802 goto exit_device_put; 811 goto exit_device_put;
803 } 812 }
804 813
805 err = platform_device_add(pdev); 814 err = platform_device_add(pdev);
806 if (err) { 815 if (err) {
807 printk(KERN_ERR "via686a: Device addition failed (%d)\n", 816 pr_err("Device addition failed (%d)\n", err);
808 err);
809 goto exit_device_put; 817 goto exit_device_put;
810 } 818 }
811 819
diff --git a/drivers/hwmon/vt1211.c b/drivers/hwmon/vt1211.c
index ae33bbb577c7..49163d48e966 100644
--- a/drivers/hwmon/vt1211.c
+++ b/drivers/hwmon/vt1211.c
@@ -21,6 +21,8 @@
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 */ 22 */
23 23
24#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
25
24#include <linux/module.h> 26#include <linux/module.h>
25#include <linux/init.h> 27#include <linux/init.h>
26#include <linux/slab.h> 28#include <linux/slab.h>
@@ -1254,8 +1256,7 @@ static int __init vt1211_device_add(unsigned short address)
1254 pdev = platform_device_alloc(DRVNAME, address); 1256 pdev = platform_device_alloc(DRVNAME, address);
1255 if (!pdev) { 1257 if (!pdev) {
1256 err = -ENOMEM; 1258 err = -ENOMEM;
1257 printk(KERN_ERR DRVNAME ": Device allocation failed (%d)\n", 1259 pr_err("Device allocation failed (%d)\n", err);
1258 err);
1259 goto EXIT; 1260 goto EXIT;
1260 } 1261 }
1261 1262
@@ -1266,15 +1267,13 @@ static int __init vt1211_device_add(unsigned short address)
1266 1267
1267 err = platform_device_add_resources(pdev, &res, 1); 1268 err = platform_device_add_resources(pdev, &res, 1);
1268 if (err) { 1269 if (err) {
1269 printk(KERN_ERR DRVNAME ": Device resource addition failed " 1270 pr_err("Device resource addition failed (%d)\n", err);
1270 "(%d)\n", err);
1271 goto EXIT_DEV_PUT; 1271 goto EXIT_DEV_PUT;
1272 } 1272 }
1273 1273
1274 err = platform_device_add(pdev); 1274 err = platform_device_add(pdev);
1275 if (err) { 1275 if (err) {
1276 printk(KERN_ERR DRVNAME ": Device addition failed (%d)\n", 1276 pr_err("Device addition failed (%d)\n", err);
1277 err);
1278 goto EXIT_DEV_PUT; 1277 goto EXIT_DEV_PUT;
1279 } 1278 }
1280 1279
@@ -1301,23 +1300,20 @@ static int __init vt1211_find(int sio_cip, unsigned short *address)
1301 superio_select(sio_cip, SIO_VT1211_LDN_HWMON); 1300 superio_select(sio_cip, SIO_VT1211_LDN_HWMON);
1302 1301
1303 if ((superio_inb(sio_cip, SIO_VT1211_ACTIVE) & 1) == 0) { 1302 if ((superio_inb(sio_cip, SIO_VT1211_ACTIVE) & 1) == 0) {
1304 printk(KERN_WARNING DRVNAME ": HW monitor is disabled, " 1303 pr_warn("HW monitor is disabled, skipping\n");
1305 "skipping\n");
1306 goto EXIT; 1304 goto EXIT;
1307 } 1305 }
1308 1306
1309 *address = ((superio_inb(sio_cip, SIO_VT1211_BADDR) << 8) | 1307 *address = ((superio_inb(sio_cip, SIO_VT1211_BADDR) << 8) |
1310 (superio_inb(sio_cip, SIO_VT1211_BADDR + 1))) & 0xff00; 1308 (superio_inb(sio_cip, SIO_VT1211_BADDR + 1))) & 0xff00;
1311 if (*address == 0) { 1309 if (*address == 0) {
1312 printk(KERN_WARNING DRVNAME ": Base address is not set, " 1310 pr_warn("Base address is not set, skipping\n");
1313 "skipping\n");
1314 goto EXIT; 1311 goto EXIT;
1315 } 1312 }
1316 1313
1317 err = 0; 1314 err = 0;
1318 printk(KERN_INFO DRVNAME ": Found VT1211 chip at 0x%04x, " 1315 pr_info("Found VT1211 chip at 0x%04x, revision %u\n",
1319 "revision %u\n", *address, 1316 *address, superio_inb(sio_cip, SIO_VT1211_DEVREV));
1320 superio_inb(sio_cip, SIO_VT1211_DEVREV));
1321 1317
1322EXIT: 1318EXIT:
1323 superio_exit(sio_cip); 1319 superio_exit(sio_cip);
@@ -1336,15 +1332,15 @@ static int __init vt1211_init(void)
1336 1332
1337 if ((uch_config < -1) || (uch_config > 31)) { 1333 if ((uch_config < -1) || (uch_config > 31)) {
1338 err = -EINVAL; 1334 err = -EINVAL;
1339 printk(KERN_WARNING DRVNAME ": Invalid UCH configuration %d. " 1335 pr_warn("Invalid UCH configuration %d. "
1340 "Choose a value between 0 and 31.\n", uch_config); 1336 "Choose a value between 0 and 31.\n", uch_config);
1341 goto EXIT; 1337 goto EXIT;
1342 } 1338 }
1343 1339
1344 if ((int_mode < -1) || (int_mode > 0)) { 1340 if ((int_mode < -1) || (int_mode > 0)) {
1345 err = -EINVAL; 1341 err = -EINVAL;
1346 printk(KERN_WARNING DRVNAME ": Invalid interrupt mode %d. " 1342 pr_warn("Invalid interrupt mode %d. "
1347 "Only mode 0 is supported.\n", int_mode); 1343 "Only mode 0 is supported.\n", int_mode);
1348 goto EXIT; 1344 goto EXIT;
1349 } 1345 }
1350 1346
diff --git a/drivers/hwmon/vt8231.c b/drivers/hwmon/vt8231.c
index e6078c9f0e27..db3b2e8d2a67 100644
--- a/drivers/hwmon/vt8231.c
+++ b/drivers/hwmon/vt8231.c
@@ -24,6 +24,8 @@
24/* Supports VIA VT8231 South Bridge embedded sensors 24/* Supports VIA VT8231 South Bridge embedded sensors
25*/ 25*/
26 26
27#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
28
27#include <linux/module.h> 29#include <linux/module.h>
28#include <linux/init.h> 30#include <linux/init.h>
29#include <linux/slab.h> 31#include <linux/slab.h>
@@ -902,21 +904,19 @@ static int __devinit vt8231_device_add(unsigned short address)
902 pdev = platform_device_alloc("vt8231", address); 904 pdev = platform_device_alloc("vt8231", address);
903 if (!pdev) { 905 if (!pdev) {
904 err = -ENOMEM; 906 err = -ENOMEM;
905 printk(KERN_ERR "vt8231: Device allocation failed\n"); 907 pr_err("Device allocation failed\n");
906 goto exit; 908 goto exit;
907 } 909 }
908 910
909 err = platform_device_add_resources(pdev, &res, 1); 911 err = platform_device_add_resources(pdev, &res, 1);
910 if (err) { 912 if (err) {
911 printk(KERN_ERR "vt8231: Device resource addition failed " 913 pr_err("Device resource addition failed (%d)\n", err);
912 "(%d)\n", err);
913 goto exit_device_put; 914 goto exit_device_put;
914 } 915 }
915 916
916 err = platform_device_add(pdev); 917 err = platform_device_add(pdev);
917 if (err) { 918 if (err) {
918 printk(KERN_ERR "vt8231: Device addition failed (%d)\n", 919 pr_err("Device addition failed (%d)\n", err);
919 err);
920 goto exit_device_put; 920 goto exit_device_put;
921 } 921 }
922 922
diff --git a/drivers/hwmon/w83627ehf.c b/drivers/hwmon/w83627ehf.c
index 072c58008a63..073eabedc432 100644
--- a/drivers/hwmon/w83627ehf.c
+++ b/drivers/hwmon/w83627ehf.c
@@ -42,6 +42,8 @@
42 w83667hg-b 9 5 3 3 0xb350 0xc1 0x5ca3 42 w83667hg-b 9 5 3 3 0xb350 0xc1 0x5ca3
43*/ 43*/
44 44
45#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
46
45#include <linux/module.h> 47#include <linux/module.h>
46#include <linux/init.h> 48#include <linux/init.h>
47#include <linux/slab.h> 49#include <linux/slab.h>
@@ -1668,8 +1670,7 @@ static int __init w83627ehf_find(int sioaddr, unsigned short *addr,
1668 break; 1670 break;
1669 default: 1671 default:
1670 if (val != 0xffff) 1672 if (val != 0xffff)
1671 pr_debug(DRVNAME ": unsupported chip ID: 0x%04x\n", 1673 pr_debug("unsupported chip ID: 0x%04x\n", val);
1672 val);
1673 superio_exit(sioaddr); 1674 superio_exit(sioaddr);
1674 return -ENODEV; 1675 return -ENODEV;
1675 } 1676 }
@@ -1680,8 +1681,7 @@ static int __init w83627ehf_find(int sioaddr, unsigned short *addr,
1680 | superio_inb(sioaddr, SIO_REG_ADDR + 1); 1681 | superio_inb(sioaddr, SIO_REG_ADDR + 1);
1681 *addr = val & IOREGION_ALIGNMENT; 1682 *addr = val & IOREGION_ALIGNMENT;
1682 if (*addr == 0) { 1683 if (*addr == 0) {
1683 printk(KERN_ERR DRVNAME ": Refusing to enable a Super-I/O " 1684 pr_err("Refusing to enable a Super-I/O device with a base I/O port 0\n");
1684 "device with a base I/O port 0.\n");
1685 superio_exit(sioaddr); 1685 superio_exit(sioaddr);
1686 return -ENODEV; 1686 return -ENODEV;
1687 } 1687 }
@@ -1689,13 +1689,12 @@ static int __init w83627ehf_find(int sioaddr, unsigned short *addr,
1689 /* Activate logical device if needed */ 1689 /* Activate logical device if needed */
1690 val = superio_inb(sioaddr, SIO_REG_ENABLE); 1690 val = superio_inb(sioaddr, SIO_REG_ENABLE);
1691 if (!(val & 0x01)) { 1691 if (!(val & 0x01)) {
1692 printk(KERN_WARNING DRVNAME ": Forcibly enabling Super-I/O. " 1692 pr_warn("Forcibly enabling Super-I/O. Sensor is probably unusable.\n");
1693 "Sensor is probably unusable.\n");
1694 superio_outb(sioaddr, SIO_REG_ENABLE, val | 0x01); 1693 superio_outb(sioaddr, SIO_REG_ENABLE, val | 0x01);
1695 } 1694 }
1696 1695
1697 superio_exit(sioaddr); 1696 superio_exit(sioaddr);
1698 pr_info(DRVNAME ": Found %s chip at %#x\n", sio_name, *addr); 1697 pr_info("Found %s chip at %#x\n", sio_name, *addr);
1699 sio_data->sioreg = sioaddr; 1698 sio_data->sioreg = sioaddr;
1700 1699
1701 return 0; 1700 return 0;
@@ -1729,14 +1728,14 @@ static int __init sensors_w83627ehf_init(void)
1729 1728
1730 if (!(pdev = platform_device_alloc(DRVNAME, address))) { 1729 if (!(pdev = platform_device_alloc(DRVNAME, address))) {
1731 err = -ENOMEM; 1730 err = -ENOMEM;
1732 printk(KERN_ERR DRVNAME ": Device allocation failed\n"); 1731 pr_err("Device allocation failed\n");
1733 goto exit_unregister; 1732 goto exit_unregister;
1734 } 1733 }
1735 1734
1736 err = platform_device_add_data(pdev, &sio_data, 1735 err = platform_device_add_data(pdev, &sio_data,
1737 sizeof(struct w83627ehf_sio_data)); 1736 sizeof(struct w83627ehf_sio_data));
1738 if (err) { 1737 if (err) {
1739 printk(KERN_ERR DRVNAME ": Platform data allocation failed\n"); 1738 pr_err("Platform data allocation failed\n");
1740 goto exit_device_put; 1739 goto exit_device_put;
1741 } 1740 }
1742 1741
@@ -1752,16 +1751,14 @@ static int __init sensors_w83627ehf_init(void)
1752 1751
1753 err = platform_device_add_resources(pdev, &res, 1); 1752 err = platform_device_add_resources(pdev, &res, 1);
1754 if (err) { 1753 if (err) {
1755 printk(KERN_ERR DRVNAME ": Device resource addition failed " 1754 pr_err("Device resource addition failed (%d)\n", err);
1756 "(%d)\n", err);
1757 goto exit_device_put; 1755 goto exit_device_put;
1758 } 1756 }
1759 1757
1760 /* platform_device_add calls probe() */ 1758 /* platform_device_add calls probe() */
1761 err = platform_device_add(pdev); 1759 err = platform_device_add(pdev);
1762 if (err) { 1760 if (err) {
1763 printk(KERN_ERR DRVNAME ": Device addition failed (%d)\n", 1761 pr_err("Device addition failed (%d)\n", err);
1764 err);
1765 goto exit_device_put; 1762 goto exit_device_put;
1766 } 1763 }
1767 1764
diff --git a/drivers/hwmon/w83627hf.c b/drivers/hwmon/w83627hf.c
index 38e280523071..bde50e34d013 100644
--- a/drivers/hwmon/w83627hf.c
+++ b/drivers/hwmon/w83627hf.c
@@ -39,6 +39,8 @@
39 supported yet. 39 supported yet.
40*/ 40*/
41 41
42#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
43
42#include <linux/module.h> 44#include <linux/module.h>
43#include <linux/init.h> 45#include <linux/init.h>
44#include <linux/slab.h> 46#include <linux/slab.h>
@@ -1166,14 +1168,13 @@ static int __init w83627hf_find(int sioaddr, unsigned short *addr,
1166 superio_inb(sio_data, WINB_BASE_REG + 1); 1168 superio_inb(sio_data, WINB_BASE_REG + 1);
1167 *addr = val & WINB_ALIGNMENT; 1169 *addr = val & WINB_ALIGNMENT;
1168 if (*addr == 0) { 1170 if (*addr == 0) {
1169 printk(KERN_WARNING DRVNAME ": Base address not set, " 1171 pr_warn("Base address not set, skipping\n");
1170 "skipping\n");
1171 goto exit; 1172 goto exit;
1172 } 1173 }
1173 1174
1174 val = superio_inb(sio_data, WINB_ACT_REG); 1175 val = superio_inb(sio_data, WINB_ACT_REG);
1175 if (!(val & 0x01)) { 1176 if (!(val & 0x01)) {
1176 printk(KERN_WARNING DRVNAME ": Enabling HWM logical device\n"); 1177 pr_warn("Enabling HWM logical device\n");
1177 superio_outb(sio_data, WINB_ACT_REG, val | 0x01); 1178 superio_outb(sio_data, WINB_ACT_REG, val | 0x01);
1178 } 1179 }
1179 1180
@@ -1789,28 +1790,26 @@ static int __init w83627hf_device_add(unsigned short address,
1789 pdev = platform_device_alloc(DRVNAME, address); 1790 pdev = platform_device_alloc(DRVNAME, address);
1790 if (!pdev) { 1791 if (!pdev) {
1791 err = -ENOMEM; 1792 err = -ENOMEM;
1792 printk(KERN_ERR DRVNAME ": Device allocation failed\n"); 1793 pr_err("Device allocation failed\n");
1793 goto exit; 1794 goto exit;
1794 } 1795 }
1795 1796
1796 err = platform_device_add_resources(pdev, &res, 1); 1797 err = platform_device_add_resources(pdev, &res, 1);
1797 if (err) { 1798 if (err) {
1798 printk(KERN_ERR DRVNAME ": Device resource addition failed " 1799 pr_err("Device resource addition failed (%d)\n", err);
1799 "(%d)\n", err);
1800 goto exit_device_put; 1800 goto exit_device_put;
1801 } 1801 }
1802 1802
1803 err = platform_device_add_data(pdev, sio_data, 1803 err = platform_device_add_data(pdev, sio_data,
1804 sizeof(struct w83627hf_sio_data)); 1804 sizeof(struct w83627hf_sio_data));
1805 if (err) { 1805 if (err) {
1806 printk(KERN_ERR DRVNAME ": Platform data allocation failed\n"); 1806 pr_err("Platform data allocation failed\n");
1807 goto exit_device_put; 1807 goto exit_device_put;
1808 } 1808 }
1809 1809
1810 err = platform_device_add(pdev); 1810 err = platform_device_add(pdev);
1811 if (err) { 1811 if (err) {
1812 printk(KERN_ERR DRVNAME ": Device addition failed (%d)\n", 1812 pr_err("Device addition failed (%d)\n", err);
1813 err);
1814 goto exit_device_put; 1813 goto exit_device_put;
1815 } 1814 }
1816 1815
diff --git a/drivers/hwmon/w83781d.c b/drivers/hwmon/w83781d.c
index c84b9b4e6960..eed43a008be1 100644
--- a/drivers/hwmon/w83781d.c
+++ b/drivers/hwmon/w83781d.c
@@ -33,6 +33,8 @@
33 33
34*/ 34*/
35 35
36#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
37
36#include <linux/module.h> 38#include <linux/module.h>
37#include <linux/init.h> 39#include <linux/init.h>
38#include <linux/slab.h> 40#include <linux/slab.h>
@@ -1798,8 +1800,7 @@ w83781d_isa_found(unsigned short address)
1798 * individually for the probing phase. */ 1800 * individually for the probing phase. */
1799 for (port = address; port < address + W83781D_EXTENT; port++) { 1801 for (port = address; port < address + W83781D_EXTENT; port++) {
1800 if (!request_region(port, 1, "w83781d")) { 1802 if (!request_region(port, 1, "w83781d")) {
1801 pr_debug("w83781d: Failed to request port 0x%x\n", 1803 pr_debug("Failed to request port 0x%x\n", port);
1802 port);
1803 goto release; 1804 goto release;
1804 } 1805 }
1805 } 1806 }
@@ -1811,7 +1812,7 @@ w83781d_isa_found(unsigned short address)
1811 if (inb_p(address + 2) != val 1812 if (inb_p(address + 2) != val
1812 || inb_p(address + 3) != val 1813 || inb_p(address + 3) != val
1813 || inb_p(address + 7) != val) { 1814 || inb_p(address + 7) != val) {
1814 pr_debug("w83781d: Detection failed at step 1\n"); 1815 pr_debug("Detection failed at step %d\n", 1);
1815 goto release; 1816 goto release;
1816 } 1817 }
1817#undef REALLY_SLOW_IO 1818#undef REALLY_SLOW_IO
@@ -1820,14 +1821,14 @@ w83781d_isa_found(unsigned short address)
1820 MSB (busy flag) should be clear initially, set after the write. */ 1821 MSB (busy flag) should be clear initially, set after the write. */
1821 save = inb_p(address + W83781D_ADDR_REG_OFFSET); 1822 save = inb_p(address + W83781D_ADDR_REG_OFFSET);
1822 if (save & 0x80) { 1823 if (save & 0x80) {
1823 pr_debug("w83781d: Detection failed at step 2\n"); 1824 pr_debug("Detection failed at step %d\n", 2);
1824 goto release; 1825 goto release;
1825 } 1826 }
1826 val = ~save & 0x7f; 1827 val = ~save & 0x7f;
1827 outb_p(val, address + W83781D_ADDR_REG_OFFSET); 1828 outb_p(val, address + W83781D_ADDR_REG_OFFSET);
1828 if (inb_p(address + W83781D_ADDR_REG_OFFSET) != (val | 0x80)) { 1829 if (inb_p(address + W83781D_ADDR_REG_OFFSET) != (val | 0x80)) {
1829 outb_p(save, address + W83781D_ADDR_REG_OFFSET); 1830 outb_p(save, address + W83781D_ADDR_REG_OFFSET);
1830 pr_debug("w83781d: Detection failed at step 3\n"); 1831 pr_debug("Detection failed at step %d\n", 3);
1831 goto release; 1832 goto release;
1832 } 1833 }
1833 1834
@@ -1835,7 +1836,7 @@ w83781d_isa_found(unsigned short address)
1835 outb_p(W83781D_REG_CONFIG, address + W83781D_ADDR_REG_OFFSET); 1836 outb_p(W83781D_REG_CONFIG, address + W83781D_ADDR_REG_OFFSET);
1836 val = inb_p(address + W83781D_DATA_REG_OFFSET); 1837 val = inb_p(address + W83781D_DATA_REG_OFFSET);
1837 if (val & 0x80) { 1838 if (val & 0x80) {
1838 pr_debug("w83781d: Detection failed at step 4\n"); 1839 pr_debug("Detection failed at step %d\n", 4);
1839 goto release; 1840 goto release;
1840 } 1841 }
1841 outb_p(W83781D_REG_BANK, address + W83781D_ADDR_REG_OFFSET); 1842 outb_p(W83781D_REG_BANK, address + W83781D_ADDR_REG_OFFSET);
@@ -1844,19 +1845,19 @@ w83781d_isa_found(unsigned short address)
1844 val = inb_p(address + W83781D_DATA_REG_OFFSET); 1845 val = inb_p(address + W83781D_DATA_REG_OFFSET);
1845 if ((!(save & 0x80) && (val != 0xa3)) 1846 if ((!(save & 0x80) && (val != 0xa3))
1846 || ((save & 0x80) && (val != 0x5c))) { 1847 || ((save & 0x80) && (val != 0x5c))) {
1847 pr_debug("w83781d: Detection failed at step 5\n"); 1848 pr_debug("Detection failed at step %d\n", 5);
1848 goto release; 1849 goto release;
1849 } 1850 }
1850 outb_p(W83781D_REG_I2C_ADDR, address + W83781D_ADDR_REG_OFFSET); 1851 outb_p(W83781D_REG_I2C_ADDR, address + W83781D_ADDR_REG_OFFSET);
1851 val = inb_p(address + W83781D_DATA_REG_OFFSET); 1852 val = inb_p(address + W83781D_DATA_REG_OFFSET);
1852 if (val < 0x03 || val > 0x77) { /* Not a valid I2C address */ 1853 if (val < 0x03 || val > 0x77) { /* Not a valid I2C address */
1853 pr_debug("w83781d: Detection failed at step 6\n"); 1854 pr_debug("Detection failed at step %d\n", 6);
1854 goto release; 1855 goto release;
1855 } 1856 }
1856 1857
1857 /* The busy flag should be clear again */ 1858 /* The busy flag should be clear again */
1858 if (inb_p(address + W83781D_ADDR_REG_OFFSET) & 0x80) { 1859 if (inb_p(address + W83781D_ADDR_REG_OFFSET) & 0x80) {
1859 pr_debug("w83781d: Detection failed at step 7\n"); 1860 pr_debug("Detection failed at step %d\n", 7);
1860 goto release; 1861 goto release;
1861 } 1862 }
1862 1863
@@ -1871,7 +1872,7 @@ w83781d_isa_found(unsigned short address)
1871 found = 1; 1872 found = 1;
1872 1873
1873 if (found) 1874 if (found)
1874 pr_info("w83781d: Found a %s chip at %#x\n", 1875 pr_info("Found a %s chip at %#x\n",
1875 val == 0x30 ? "W83782D" : "W83781D", (int)address); 1876 val == 0x30 ? "W83782D" : "W83781D", (int)address);
1876 1877
1877 release: 1878 release:
@@ -1894,21 +1895,19 @@ w83781d_isa_device_add(unsigned short address)
1894 pdev = platform_device_alloc("w83781d", address); 1895 pdev = platform_device_alloc("w83781d", address);
1895 if (!pdev) { 1896 if (!pdev) {
1896 err = -ENOMEM; 1897 err = -ENOMEM;
1897 printk(KERN_ERR "w83781d: Device allocation failed\n"); 1898 pr_err("Device allocation failed\n");
1898 goto exit; 1899 goto exit;
1899 } 1900 }
1900 1901
1901 err = platform_device_add_resources(pdev, &res, 1); 1902 err = platform_device_add_resources(pdev, &res, 1);
1902 if (err) { 1903 if (err) {
1903 printk(KERN_ERR "w83781d: Device resource addition failed " 1904 pr_err("Device resource addition failed (%d)\n", err);
1904 "(%d)\n", err);
1905 goto exit_device_put; 1905 goto exit_device_put;
1906 } 1906 }
1907 1907
1908 err = platform_device_add(pdev); 1908 err = platform_device_add(pdev);
1909 if (err) { 1909 if (err) {
1910 printk(KERN_ERR "w83781d: Device addition failed (%d)\n", 1910 pr_err("Device addition failed (%d)\n", err);
1911 err);
1912 goto exit_device_put; 1911 goto exit_device_put;
1913 } 1912 }
1914 1913
diff --git a/drivers/hwmon/w83792d.c b/drivers/hwmon/w83792d.c
index 679718e6b017..63841f8cec07 100644
--- a/drivers/hwmon/w83792d.c
+++ b/drivers/hwmon/w83792d.c
@@ -691,7 +691,7 @@ store_pwm_mode(struct device *dev, struct device_attribute *attr,
691} 691}
692 692
693static ssize_t 693static ssize_t
694show_regs_chassis(struct device *dev, struct device_attribute *attr, 694show_chassis(struct device *dev, struct device_attribute *attr,
695 char *buf) 695 char *buf)
696{ 696{
697 struct w83792d_data *data = w83792d_update_device(dev); 697 struct w83792d_data *data = w83792d_update_device(dev);
@@ -699,6 +699,16 @@ show_regs_chassis(struct device *dev, struct device_attribute *attr,
699} 699}
700 700
701static ssize_t 701static ssize_t
702show_regs_chassis(struct device *dev, struct device_attribute *attr,
703 char *buf)
704{
705 dev_warn(dev,
706 "Attribute %s is deprecated, use intrusion0_alarm instead\n",
707 "chassis");
708 return show_chassis(dev, attr, buf);
709}
710
711static ssize_t
702show_chassis_clear(struct device *dev, struct device_attribute *attr, char *buf) 712show_chassis_clear(struct device *dev, struct device_attribute *attr, char *buf)
703{ 713{
704 struct w83792d_data *data = w83792d_update_device(dev); 714 struct w83792d_data *data = w83792d_update_device(dev);
@@ -706,7 +716,7 @@ show_chassis_clear(struct device *dev, struct device_attribute *attr, char *buf)
706} 716}
707 717
708static ssize_t 718static ssize_t
709store_chassis_clear(struct device *dev, struct device_attribute *attr, 719store_chassis_clear_legacy(struct device *dev, struct device_attribute *attr,
710 const char *buf, size_t count) 720 const char *buf, size_t count)
711{ 721{
712 struct i2c_client *client = to_i2c_client(dev); 722 struct i2c_client *client = to_i2c_client(dev);
@@ -714,6 +724,10 @@ store_chassis_clear(struct device *dev, struct device_attribute *attr,
714 u32 val; 724 u32 val;
715 u8 temp1 = 0, temp2 = 0; 725 u8 temp1 = 0, temp2 = 0;
716 726
727 dev_warn(dev,
728 "Attribute %s is deprecated, use intrusion0_alarm instead\n",
729 "chassis_clear");
730
717 val = simple_strtoul(buf, NULL, 10); 731 val = simple_strtoul(buf, NULL, 10);
718 mutex_lock(&data->update_lock); 732 mutex_lock(&data->update_lock);
719 data->chassis_clear = SENSORS_LIMIT(val, 0 ,1); 733 data->chassis_clear = SENSORS_LIMIT(val, 0 ,1);
@@ -726,6 +740,27 @@ store_chassis_clear(struct device *dev, struct device_attribute *attr,
726 return count; 740 return count;
727} 741}
728 742
743static ssize_t
744store_chassis_clear(struct device *dev, struct device_attribute *attr,
745 const char *buf, size_t count)
746{
747 struct i2c_client *client = to_i2c_client(dev);
748 struct w83792d_data *data = i2c_get_clientdata(client);
749 unsigned long val;
750 u8 reg;
751
752 if (strict_strtoul(buf, 10, &val) || val != 0)
753 return -EINVAL;
754
755 mutex_lock(&data->update_lock);
756 reg = w83792d_read_value(client, W83792D_REG_CHASSIS_CLR);
757 w83792d_write_value(client, W83792D_REG_CHASSIS_CLR, reg | 0x80);
758 data->valid = 0; /* Force cache refresh */
759 mutex_unlock(&data->update_lock);
760
761 return count;
762}
763
729/* For Smart Fan I / Thermal Cruise */ 764/* For Smart Fan I / Thermal Cruise */
730static ssize_t 765static ssize_t
731show_thermal_cruise(struct device *dev, struct device_attribute *attr, 766show_thermal_cruise(struct device *dev, struct device_attribute *attr,
@@ -1012,7 +1047,9 @@ static SENSOR_DEVICE_ATTR(fan5_alarm, S_IRUGO, show_alarm, NULL, 22);
1012static SENSOR_DEVICE_ATTR(fan6_alarm, S_IRUGO, show_alarm, NULL, 23); 1047static SENSOR_DEVICE_ATTR(fan6_alarm, S_IRUGO, show_alarm, NULL, 23);
1013static DEVICE_ATTR(chassis, S_IRUGO, show_regs_chassis, NULL); 1048static DEVICE_ATTR(chassis, S_IRUGO, show_regs_chassis, NULL);
1014static DEVICE_ATTR(chassis_clear, S_IRUGO | S_IWUSR, 1049static DEVICE_ATTR(chassis_clear, S_IRUGO | S_IWUSR,
1015 show_chassis_clear, store_chassis_clear); 1050 show_chassis_clear, store_chassis_clear_legacy);
1051static DEVICE_ATTR(intrusion0_alarm, S_IRUGO | S_IWUSR,
1052 show_chassis, store_chassis_clear);
1016static SENSOR_DEVICE_ATTR(pwm1, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 0); 1053static SENSOR_DEVICE_ATTR(pwm1, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 0);
1017static SENSOR_DEVICE_ATTR(pwm2, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 1); 1054static SENSOR_DEVICE_ATTR(pwm2, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 1);
1018static SENSOR_DEVICE_ATTR(pwm3, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 2); 1055static SENSOR_DEVICE_ATTR(pwm3, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 2);
@@ -1214,6 +1251,7 @@ static struct attribute *w83792d_attributes[] = {
1214 &dev_attr_alarms.attr, 1251 &dev_attr_alarms.attr,
1215 &dev_attr_chassis.attr, 1252 &dev_attr_chassis.attr,
1216 &dev_attr_chassis_clear.attr, 1253 &dev_attr_chassis_clear.attr,
1254 &dev_attr_intrusion0_alarm.attr,
1217 &sensor_dev_attr_tolerance1.dev_attr.attr, 1255 &sensor_dev_attr_tolerance1.dev_attr.attr,
1218 &sensor_dev_attr_thermal_cruise1.dev_attr.attr, 1256 &sensor_dev_attr_thermal_cruise1.dev_attr.attr,
1219 &sensor_dev_attr_tolerance2.dev_attr.attr, 1257 &sensor_dev_attr_tolerance2.dev_attr.attr,
diff --git a/drivers/hwmon/w83793.c b/drivers/hwmon/w83793.c
index 8e540ada47d2..e3bdedfb5347 100644
--- a/drivers/hwmon/w83793.c
+++ b/drivers/hwmon/w83793.c
@@ -51,7 +51,6 @@
51#define WATCHDOG_TIMEOUT 2 /* 2 minute default timeout */ 51#define WATCHDOG_TIMEOUT 2 /* 2 minute default timeout */
52 52
53/* Addresses to scan */ 53/* Addresses to scan */
54static DEFINE_MUTEX(watchdog_mutex);
55static const unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, 0x2f, 54static const unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, 0x2f,
56 I2C_CLIENT_END }; 55 I2C_CLIENT_END };
57 56
@@ -421,14 +420,17 @@ store_beep_enable(struct device *dev, struct device_attribute *attr,
421 420
422/* Write any value to clear chassis alarm */ 421/* Write any value to clear chassis alarm */
423static ssize_t 422static ssize_t
424store_chassis_clear(struct device *dev, 423store_chassis_clear_legacy(struct device *dev,
425 struct device_attribute *attr, const char *buf, 424 struct device_attribute *attr, const char *buf,
426 size_t count) 425 size_t count)
427{ 426{
428 struct i2c_client *client = to_i2c_client(dev); 427 struct i2c_client *client = to_i2c_client(dev);
429 struct w83793_data *data = i2c_get_clientdata(client); 428 struct w83793_data *data = i2c_get_clientdata(client);
430 u8 val; 429 u8 val;
431 430
431 dev_warn(dev, "Attribute chassis is deprecated, "
432 "use intrusion0_alarm instead\n");
433
432 mutex_lock(&data->update_lock); 434 mutex_lock(&data->update_lock);
433 val = w83793_read_value(client, W83793_REG_CLR_CHASSIS); 435 val = w83793_read_value(client, W83793_REG_CLR_CHASSIS);
434 val |= 0x80; 436 val |= 0x80;
@@ -437,6 +439,28 @@ store_chassis_clear(struct device *dev,
437 return count; 439 return count;
438} 440}
439 441
442/* Write 0 to clear chassis alarm */
443static ssize_t
444store_chassis_clear(struct device *dev,
445 struct device_attribute *attr, const char *buf,
446 size_t count)
447{
448 struct i2c_client *client = to_i2c_client(dev);
449 struct w83793_data *data = i2c_get_clientdata(client);
450 unsigned long val;
451 u8 reg;
452
453 if (strict_strtoul(buf, 10, &val) || val != 0)
454 return -EINVAL;
455
456 mutex_lock(&data->update_lock);
457 reg = w83793_read_value(client, W83793_REG_CLR_CHASSIS);
458 w83793_write_value(client, W83793_REG_CLR_CHASSIS, reg | 0x80);
459 data->valid = 0; /* Force cache refresh */
460 mutex_unlock(&data->update_lock);
461 return count;
462}
463
440#define FAN_INPUT 0 464#define FAN_INPUT 0
441#define FAN_MIN 1 465#define FAN_MIN 1
442static ssize_t 466static ssize_t
@@ -1102,6 +1126,8 @@ static DEVICE_ATTR(vrm, S_IWUSR | S_IRUGO, show_vrm, store_vrm);
1102 1126
1103static struct sensor_device_attribute_2 sda_single_files[] = { 1127static struct sensor_device_attribute_2 sda_single_files[] = {
1104 SENSOR_ATTR_2(chassis, S_IWUSR | S_IRUGO, show_alarm_beep, 1128 SENSOR_ATTR_2(chassis, S_IWUSR | S_IRUGO, show_alarm_beep,
1129 store_chassis_clear_legacy, ALARM_STATUS, 30),
1130 SENSOR_ATTR_2(intrusion0_alarm, S_IWUSR | S_IRUGO, show_alarm_beep,
1105 store_chassis_clear, ALARM_STATUS, 30), 1131 store_chassis_clear, ALARM_STATUS, 30),
1106 SENSOR_ATTR_2(beep_enable, S_IWUSR | S_IRUGO, show_beep_enable, 1132 SENSOR_ATTR_2(beep_enable, S_IWUSR | S_IRUGO, show_beep_enable,
1107 store_beep_enable, NOT_USED, NOT_USED), 1133 store_beep_enable, NOT_USED, NOT_USED),
@@ -1323,7 +1349,7 @@ static ssize_t watchdog_write(struct file *filp, const char __user *buf,
1323static long watchdog_ioctl(struct file *filp, unsigned int cmd, 1349static long watchdog_ioctl(struct file *filp, unsigned int cmd,
1324 unsigned long arg) 1350 unsigned long arg)
1325{ 1351{
1326 static struct watchdog_info ident = { 1352 struct watchdog_info ident = {
1327 .options = WDIOF_KEEPALIVEPING | 1353 .options = WDIOF_KEEPALIVEPING |
1328 WDIOF_SETTIMEOUT | 1354 WDIOF_SETTIMEOUT |
1329 WDIOF_CARDRESET, 1355 WDIOF_CARDRESET,
@@ -1333,7 +1359,6 @@ static long watchdog_ioctl(struct file *filp, unsigned int cmd,
1333 int val, ret = 0; 1359 int val, ret = 0;
1334 struct w83793_data *data = filp->private_data; 1360 struct w83793_data *data = filp->private_data;
1335 1361
1336 mutex_lock(&watchdog_mutex);
1337 switch (cmd) { 1362 switch (cmd) {
1338 case WDIOC_GETSUPPORT: 1363 case WDIOC_GETSUPPORT:
1339 if (!nowayout) 1364 if (!nowayout)
@@ -1387,7 +1412,6 @@ static long watchdog_ioctl(struct file *filp, unsigned int cmd,
1387 default: 1412 default:
1388 ret = -ENOTTY; 1413 ret = -ENOTTY;
1389 } 1414 }
1390 mutex_unlock(&watchdog_mutex);
1391 return ret; 1415 return ret;
1392} 1416}
1393 1417
diff --git a/drivers/hwmon/w83795.c b/drivers/hwmon/w83795.c
index cdbc7448491e..845232d7f611 100644
--- a/drivers/hwmon/w83795.c
+++ b/drivers/hwmon/w83795.c
@@ -458,6 +458,7 @@ static void w83795_update_limits(struct i2c_client *client)
458{ 458{
459 struct w83795_data *data = i2c_get_clientdata(client); 459 struct w83795_data *data = i2c_get_clientdata(client);
460 int i, limit; 460 int i, limit;
461 u8 lsb;
461 462
462 /* Read the voltage limits */ 463 /* Read the voltage limits */
463 for (i = 0; i < ARRAY_SIZE(data->in); i++) { 464 for (i = 0; i < ARRAY_SIZE(data->in); i++) {
@@ -479,9 +480,8 @@ static void w83795_update_limits(struct i2c_client *client)
479 } 480 }
480 481
481 /* Read the fan limits */ 482 /* Read the fan limits */
483 lsb = 0; /* Silent false gcc warning */
482 for (i = 0; i < ARRAY_SIZE(data->fan); i++) { 484 for (i = 0; i < ARRAY_SIZE(data->fan); i++) {
483 u8 lsb;
484
485 /* Each register contains LSB for 2 fans, but we want to 485 /* Each register contains LSB for 2 fans, but we want to
486 * read it only once to save time */ 486 * read it only once to save time */
487 if ((i & 1) == 0 && (data->has_fan & (3 << i))) 487 if ((i & 1) == 0 && (data->has_fan & (3 << i)))