Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch 'hwmon-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/groeck/staging

* 'hwmon-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/groeck/staging: (44 commits)
hwmon: Support for Dallas Semiconductor DS620
hwmon: driver for Sensirion SHT21 humidity and temperature sensor
hwmon: Add humidity attribute to sysfs ABI
hwmon: sysfs ABI updates
hwmon: (via-cputemp) sync hotplug handling with coretemp/pkgtemp
hwmon: (lm95241) Rewrite to avoid using macros
hwmon: (applesmc) Fix checkpatch errors and fix value range checks
hwmon: (applesmc) Update copyright information
hwmon: (applesmc) Silence driver
hwmon: (applesmc) Simplify feature sysfs handling
hwmon: (applesmc) Dynamic creation of fan files
hwmon: (applesmc) Extract all features generically
hwmon: (applesmc) Handle new temperature format
hwmon: (applesmc) Dynamic creation of temperature files
hwmon: (applesmc) Introduce a register lookup table
hwmon: (applesmc) Use pr_fmt and pr_<level>
hwmon: (applesmc) Relax the severity of device init failure
hwmon: (applesmc) Add MacBookAir3,1(3,2) support
hwmon: (w83627hf) Use pr_fmt and pr_<level>
hwmon: (w83627ehf) Use pr_fmt and pr_<level>
...

+1837 -1556
+34
Documentation/hwmon/ds620
··· 1 + Kernel driver ds620 2 + =================== 3 + 4 + Supported chips: 5 + * Dallas Semiconductor DS620 6 + Prefix: 'ds620' 7 + Datasheet: Publicly available at the Dallas Semiconductor website 8 + http://www.dalsemi.com/ 9 + 10 + Authors: 11 + Roland Stigge <stigge@antcom.de> 12 + based on ds1621.c by 13 + Christian W. Zuckschwerdt <zany@triq.net> 14 + 15 + Description 16 + ----------- 17 + 18 + The DS620 is a (one instance) digital thermometer and thermostat. It has both 19 + high and low temperature limits which can be user defined (i.e. programmed 20 + into non-volatile on-chip registers). Temperature range is -55 degree Celsius 21 + to +125. Between 0 and 70 degree Celsius, accuracy is 0.5 Kelvin. The value 22 + returned via sysfs displays post decimal positions. 23 + 24 + The thermostat function works as follows: When configured via platform_data 25 + (struct ds620_platform_data) .pomode == 0 (default), the thermostat output pin 26 + PO is always low. If .pomode == 1, the thermostat is in PO_LOW mode. I.e., the 27 + output pin PO becomes active when the temperature falls below temp1_min and 28 + stays active until the temperature goes above temp1_max. 29 + 30 + Likewise, with .pomode == 2, the thermostat is in PO_HIGH mode. I.e., the PO 31 + output pin becomes active when the temperature goes above temp1_max and stays 32 + active until the temperature falls below temp1_min. 33 + 34 + The PO output pin of the DS620 operates active-low.
+49
Documentation/hwmon/sht21
··· 1 + Kernel driver sht21 2 + =================== 3 + 4 + Supported chips: 5 + * Sensirion SHT21 6 + Prefix: 'sht21' 7 + Addresses scanned: none 8 + Datasheet: Publicly available at the Sensirion website 9 + http://www.sensirion.com/en/pdf/product_information/Datasheet-humidity-sensor-SHT21.pdf 10 + 11 + * Sensirion SHT25 12 + Prefix: 'sht21' 13 + Addresses scanned: none 14 + Datasheet: Publicly available at the Sensirion website 15 + http://www.sensirion.com/en/pdf/product_information/Datasheet-humidity-sensor-SHT25.pdf 16 + 17 + Author: 18 + Urs Fleisch <urs.fleisch@sensirion.com> 19 + 20 + Description 21 + ----------- 22 + 23 + The SHT21 and SHT25 are humidity and temperature sensors in a DFN package of 24 + only 3 x 3 mm footprint and 1.1 mm height. The difference between the two 25 + devices is the higher level of precision of the SHT25 (1.8% relative humidity, 26 + 0.2 degree Celsius) compared with the SHT21 (2.0% relative humidity, 27 + 0.3 degree Celsius). 28 + 29 + The devices communicate with the I2C protocol. All sensors are set to the same 30 + I2C address 0x40, so an entry with I2C_BOARD_INFO("sht21", 0x40) can be used 31 + in the board setup code. 32 + 33 + sysfs-Interface 34 + --------------- 35 + 36 + temp1_input - temperature input 37 + humidity1_input - humidity input 38 + 39 + Notes 40 + ----- 41 + 42 + The driver uses the default resolution settings of 12 bit for humidity and 14 43 + bit for temperature, which results in typical measurement times of 22 ms for 44 + humidity and 66 ms for temperature. To keep self heating below 0.1 degree 45 + Celsius, the device should not be active for more than 10% of the time, 46 + e.g. maximum two measurements per second at the given resolution. 47 + 48 + Different resolutions, the on-chip heater, using the CRC checksum and reading 49 + the serial number are not supported yet.
+42 -7
Documentation/hwmon/sysfs-interface
··· 384 384 Unit: milliampere 385 385 RW 386 386 387 + curr[1-*]_lcrit Current critical low value 388 + Unit: milliampere 389 + RW 390 + 391 + curr[1-*]_crit Current critical high value. 392 + Unit: milliampere 393 + RW 394 + 387 395 curr[1-*]_input Current input value 388 396 Unit: milliampere 389 397 RO 398 + 399 + Also see the Alarms section for status flags associated with currents. 390 400 391 401 ********* 392 402 * Power * ··· 460 450 Unit: Percent 461 451 RO 462 452 463 - power[1-*]_alarm 1 if the system is drawing more power than the 464 - cap allows; 0 otherwise. A poll notification is 465 - sent to this file when the power use exceeds the 466 - cap. This file only appears if the cap is known 467 - to be enforced by hardware. 468 - RO 469 - 470 453 power[1-*]_cap If power use rises above this limit, the 471 454 system should take action to reduce power use. 472 455 A poll notification is sent to this file if the ··· 482 479 Unit: microWatt 483 480 RO 484 481 482 + power[1-*]_max Maximum power. 483 + Unit: microWatt 484 + RW 485 + 486 + power[1-*]_crit Critical maximum power. 487 + If power rises to or above this limit, the 488 + system is expected take drastic action to reduce 489 + power consumption, such as a system shutdown or 490 + a forced powerdown of some devices. 491 + Unit: microWatt 492 + RW 493 + 494 + Also see the Alarms section for status flags associated with power readings. 495 + 485 496 ********** 486 497 * Energy * 487 498 ********** 488 499 489 500 energy[1-*]_input Cumulative energy use 490 501 Unit: microJoule 502 + RO 503 + 504 + 505 + ************ 506 + * Humidity * 507 + ************ 508 + 509 + humidity[1-*]_input Humidity 510 + Unit: milli-percent (per cent mille, pcm) 491 511 RO 492 512 493 513 ··· 527 501 528 502 in[0-*]_alarm 529 503 curr[1-*]_alarm 504 + power[1-*]_alarm 530 505 fan[1-*]_alarm 531 506 temp[1-*]_alarm 532 507 Channel alarm ··· 539 512 540 513 in[0-*]_min_alarm 541 514 in[0-*]_max_alarm 515 + in[0-*]_lcrit_alarm 516 + in[0-*]_crit_alarm 542 517 curr[1-*]_min_alarm 543 518 curr[1-*]_max_alarm 519 + curr[1-*]_lcrit_alarm 520 + curr[1-*]_crit_alarm 521 + power[1-*]_cap_alarm 522 + power[1-*]_max_alarm 523 + power[1-*]_crit_alarm 544 524 fan[1-*]_min_alarm 545 525 fan[1-*]_max_alarm 546 526 temp[1-*]_min_alarm 547 527 temp[1-*]_max_alarm 528 + temp[1-*]_lcrit_alarm 548 529 temp[1-*]_crit_alarm 549 530 temp[1-*]_emergency_alarm 550 531 Limit alarm
+20
drivers/hwmon/Kconfig
··· 274 274 This driver can also be built as a module. If so, the module 275 275 will be called atxp1. 276 276 277 + config 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 + 277 287 config SENSORS_DS1621 278 288 tristate "Dallas Semiconductor DS1621 and DS1625" 279 289 depends on I2C ··· 743 733 744 734 This driver can also be built as a module. If so, the module 745 735 will be called sht15. 736 + 737 + config SENSORS_SHT21 738 + tristate "Sensiron humidity and temperature sensors. SHT21 and compat." 739 + depends on I2C 740 + help 741 + If you say yes here you get support for the Sensiron SHT21, SHT25 742 + humidity and temperature sensors. 743 + 744 + This driver can also be built as a module. If so, the module 745 + will be called sht21. 746 746 747 747 config SENSORS_S3C 748 748 tristate "Samsung built-in ADC"
+2
drivers/hwmon/Makefile
··· 41 41 obj-$(CONFIG_SENSORS_CORETEMP) += coretemp.o 42 42 obj-$(CONFIG_SENSORS_PKGTEMP) += pkgtemp.o 43 43 obj-$(CONFIG_SENSORS_DME1737) += dme1737.o 44 + obj-$(CONFIG_SENSORS_DS620) += ds620.o 44 45 obj-$(CONFIG_SENSORS_DS1621) += ds1621.o 45 46 obj-$(CONFIG_SENSORS_EMC1403) += emc1403.o 46 47 obj-$(CONFIG_SENSORS_EMC2103) += emc2103.o ··· 91 90 obj-$(CONFIG_SENSORS_PCF8591) += pcf8591.o 92 91 obj-$(CONFIG_SENSORS_S3C) += s3c-hwmon.o 93 92 obj-$(CONFIG_SENSORS_SHT15) += sht15.o 93 + obj-$(CONFIG_SENSORS_SHT21) += sht21.o 94 94 obj-$(CONFIG_SENSORS_SIS5595) += sis5595.o 95 95 obj-$(CONFIG_SENSORS_SMM665) += smm665.o 96 96 obj-$(CONFIG_SENSORS_SMSC47B397)+= smsc47b397.o
+17 -19
drivers/hwmon/abituguru.c
··· 20 20 the custom Abit uGuru chip found on Abit uGuru motherboards. Note: because 21 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 26 #include <linux/module.h> 24 27 #include <linux/sched.h> 25 28 #include <linux/init.h> ··· 222 219 u8 pwms; /* actual number of pwms found */ 223 220 u8 pwm_settings[ABIT_UGURU_MAX_PWMS][5]; 224 221 }; 222 + 223 + static const char *never_happen = "This should never happen."; 224 + static const char *report_this = 225 + "Please report this to the abituguru maintainer (see MAINTAINERS)"; 225 226 226 227 /* wait till the uguru is in the specified state */ 227 228 static int abituguru_wait(struct abituguru_data *data, u8 state) ··· 445 438 446 439 /* Test val is sane / usable for sensor type detection. */ 447 440 if ((val < 10u) || (val > 250u)) { 448 - printk(KERN_WARNING ABIT_UGURU_NAME 449 - ": bank1-sensor: %d reading (%d) too close to limits, " 441 + pr_warn("bank1-sensor: %d reading (%d) too close to limits, " 450 442 "unable to determine sensor type, skipping sensor\n", 451 443 (int)sensor_addr, (int)val); 452 444 /* assume no sensor is there for sensors for which we can't ··· 541 535 3) == 3) 542 536 break; 543 537 if (i == 3) { 544 - printk(KERN_ERR ABIT_UGURU_NAME 545 - ": Fatal error could not restore original settings. " 546 - "This should never happen please report this to the " 547 - "abituguru maintainer (see MAINTAINERS)\n"); 538 + pr_err("Fatal error could not restore original settings. %s %s\n", 539 + never_happen, report_this); 548 540 return -ENODEV; 549 541 } 550 542 return ret; ··· 1272 1268 } 1273 1269 /* Fail safe check, this should never happen! */ 1274 1270 if (sysfs_names_free < 0) { 1275 - printk(KERN_ERR ABIT_UGURU_NAME ": Fatal error ran out of " 1276 - "space for sysfs attr names. This should never " 1277 - "happen please report to the abituguru maintainer " 1278 - "(see MAINTAINERS)\n"); 1271 + pr_err("Fatal error ran out of space for sysfs attr names. %s %s", 1272 + never_happen, report_this); 1279 1273 res = -ENAMETOOLONG; 1280 1274 goto abituguru_probe_error; 1281 1275 } 1282 - printk(KERN_INFO ABIT_UGURU_NAME ": found Abit uGuru\n"); 1276 + pr_info("found Abit uGuru\n"); 1283 1277 1284 1278 /* Register sysfs hooks */ 1285 1279 for (i = 0; i < sysfs_attr_i; i++) ··· 1434 1432 "0x%02X\n", (unsigned int)data_val, (unsigned int)cmd_val); 1435 1433 1436 1434 if (force) { 1437 - printk(KERN_INFO ABIT_UGURU_NAME ": Assuming Abit uGuru is " 1438 - "present because of \"force\" parameter\n"); 1435 + pr_info("Assuming Abit uGuru is present because of \"force\" parameter\n"); 1439 1436 return ABIT_UGURU_BASE; 1440 1437 } 1441 1438 ··· 1468 1467 1469 1468 abituguru_pdev = platform_device_alloc(ABIT_UGURU_NAME, address); 1470 1469 if (!abituguru_pdev) { 1471 - printk(KERN_ERR ABIT_UGURU_NAME 1472 - ": Device allocation failed\n"); 1470 + pr_err("Device allocation failed\n"); 1473 1471 err = -ENOMEM; 1474 1472 goto exit_driver_unregister; 1475 1473 } ··· 1479 1479 1480 1480 err = platform_device_add_resources(abituguru_pdev, &res, 1); 1481 1481 if (err) { 1482 - printk(KERN_ERR ABIT_UGURU_NAME 1483 - ": Device resource addition failed (%d)\n", err); 1482 + pr_err("Device resource addition failed (%d)\n", err); 1484 1483 goto exit_device_put; 1485 1484 } 1486 1485 1487 1486 err = platform_device_add(abituguru_pdev); 1488 1487 if (err) { 1489 - printk(KERN_ERR ABIT_UGURU_NAME 1490 - ": Device addition failed (%d)\n", err); 1488 + pr_err("Device addition failed (%d)\n", err); 1491 1489 goto exit_device_put; 1492 1490 } 1493 1491
+19 -26
drivers/hwmon/abituguru3.c
··· 23 23 chip found on newer Abit uGuru motherboards. Note: because of lack of specs 24 24 only reading the sensors and their settings is supported. 25 25 */ 26 + 27 + #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 28 + 26 29 #include <linux/module.h> 27 30 #include <linux/init.h> 28 31 #include <linux/slab.h> ··· 611 608 module_param(verbose, bool, 0644); 612 609 MODULE_PARM_DESC(verbose, "Enable/disable verbose error reporting"); 613 610 611 + static const char *never_happen = "This should never happen."; 612 + static const char *report_this = 613 + "Please report this to the abituguru3 maintainer (see MAINTAINERS)"; 614 614 615 615 /* wait while the uguru is busy (usually after a write) */ 616 616 static int abituguru3_wait_while_busy(struct abituguru3_data *data) ··· 946 940 if (abituguru3_motherboards[i].id == id) 947 941 break; 948 942 if (!abituguru3_motherboards[i].id) { 949 - printk(KERN_ERR ABIT_UGURU3_NAME ": error unknown motherboard " 950 - "ID: %04X. Please report this to the abituguru3 " 951 - "maintainer (see MAINTAINERS)\n", (unsigned int)id); 943 + pr_err("error unknown motherboard ID: %04X. %s\n", 944 + (unsigned int)id, report_this); 952 945 goto abituguru3_probe_error; 953 946 } 954 947 data->sensors = abituguru3_motherboards[i].sensors; 955 948 956 - printk(KERN_INFO ABIT_UGURU3_NAME ": found Abit uGuru3, motherboard " 957 - "ID: %04X\n", (unsigned int)id); 949 + pr_info("found Abit uGuru3, motherboard ID: %04X\n", (unsigned int)id); 958 950 959 951 /* Fill the sysfs attr array */ 960 952 sysfs_attr_i = 0; ··· 961 957 for (i = 0; data->sensors[i].name; i++) { 962 958 /* Fail safe check, this should never happen! */ 963 959 if (i >= ABIT_UGURU3_MAX_NO_SENSORS) { 964 - printk(KERN_ERR ABIT_UGURU3_NAME 965 - ": Fatal error motherboard has more sensors " 966 - "then ABIT_UGURU3_MAX_NO_SENSORS. This should " 967 - "never happen please report to the abituguru3 " 968 - "maintainer (see MAINTAINERS)\n"); 960 + pr_err("Fatal error motherboard has more sensors then ABIT_UGURU3_MAX_NO_SENSORS. %s %s\n", 961 + never_happen, report_this); 969 962 res = -ENAMETOOLONG; 970 963 goto abituguru3_probe_error; 971 964 } ··· 984 983 } 985 984 /* Fail safe check, this should never happen! */ 986 985 if (sysfs_names_free < 0) { 987 - printk(KERN_ERR ABIT_UGURU3_NAME 988 - ": Fatal error ran out of space for sysfs attr names. " 989 - "This should never happen please report to the " 990 - "abituguru3 maintainer (see MAINTAINERS)\n"); 986 + pr_err("Fatal error ran out of space for sysfs attr names. %s %s\n", 987 + never_happen, report_this); 991 988 res = -ENAMETOOLONG; 992 989 goto abituguru3_probe_error; 993 990 } ··· 1188 1189 "0x%02X\n", (unsigned int)data_val, (unsigned int)cmd_val); 1189 1190 1190 1191 if (force) { 1191 - printk(KERN_INFO ABIT_UGURU3_NAME ": Assuming Abit uGuru3 is " 1192 - "present because of \"force\" parameter\n"); 1192 + pr_info("Assuming Abit uGuru3 is present because of \"force\" parameter\n"); 1193 1193 return 0; 1194 1194 } 1195 1195 ··· 1217 1219 return err; 1218 1220 1219 1221 #ifdef CONFIG_DMI 1220 - printk(KERN_WARNING ABIT_UGURU3_NAME ": this motherboard was " 1221 - "not detected using DMI. Please send the output of " 1222 - "\"dmidecode\" to the abituguru3 maintainer " 1223 - "(see MAINTAINERS)\n"); 1222 + pr_warn("this motherboard was not detected using DMI. " 1223 + "Please send the output of \"dmidecode\" to the abituguru3 maintainer (see MAINTAINERS)\n"); 1224 1224 #endif 1225 1225 } 1226 1226 ··· 1229 1233 abituguru3_pdev = platform_device_alloc(ABIT_UGURU3_NAME, 1230 1234 ABIT_UGURU3_BASE); 1231 1235 if (!abituguru3_pdev) { 1232 - printk(KERN_ERR ABIT_UGURU3_NAME 1233 - ": Device allocation failed\n"); 1236 + pr_err("Device allocation failed\n"); 1234 1237 err = -ENOMEM; 1235 1238 goto exit_driver_unregister; 1236 1239 } ··· 1240 1245 1241 1246 err = platform_device_add_resources(abituguru3_pdev, &res, 1); 1242 1247 if (err) { 1243 - printk(KERN_ERR ABIT_UGURU3_NAME 1244 - ": Device resource addition failed (%d)\n", err); 1248 + pr_err("Device resource addition failed (%d)\n", err); 1245 1249 goto exit_device_put; 1246 1250 } 1247 1251 1248 1252 err = platform_device_add(abituguru3_pdev); 1249 1253 if (err) { 1250 - printk(KERN_ERR ABIT_UGURU3_NAME 1251 - ": Device addition failed (%d)\n", err); 1254 + pr_err("Device addition failed (%d)\n", err); 1252 1255 goto exit_device_put; 1253 1256 } 1254 1257
+3 -1
drivers/hwmon/adt7470.c
··· 19 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 24 #include <linux/module.h> 23 25 #include <linux/jiffies.h> 24 26 #include <linux/i2c.h> ··· 276 274 i2c_smbus_write_byte_data(client, ADT7470_REG_PWM_CFG(2), pwm_cfg[1]); 277 275 278 276 if (res) { 279 - printk(KERN_ERR "ha ha, interrupted"); 277 + pr_err("ha ha, interrupted\n"); 280 278 return -EAGAIN; 281 279 } 282 280
+578 -1062
drivers/hwmon/applesmc.c
··· 4 4 * computers. 5 5 * 6 6 * Copyright (C) 2007 Nicolas Boichat <nicolas@boichat.ch> 7 + * Copyright (C) 2010 Henrik Rydberg <rydberg@euromail.se> 7 8 * 8 9 * Based on hdaps.c driver: 9 10 * Copyright (C) 2005 Robert Love <rml@novell.com> ··· 27 26 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 28 27 */ 29 28 29 + #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 30 + 30 31 #include <linux/delay.h> 31 32 #include <linux/platform_device.h> 32 33 #include <linux/input-polldev.h> 33 34 #include <linux/kernel.h> 35 + #include <linux/slab.h> 34 36 #include <linux/module.h> 35 37 #include <linux/timer.h> 36 38 #include <linux/dmi.h> ··· 53 49 54 50 #define APPLESMC_MAX_DATA_LENGTH 32 55 51 52 + /* wait up to 32 ms for a status change. */ 56 53 #define APPLESMC_MIN_WAIT 0x0040 57 54 #define APPLESMC_MAX_WAIT 0x8000 58 55 ··· 78 73 79 74 #define FANS_COUNT "FNum" /* r-o ui8 */ 80 75 #define FANS_MANUAL "FS! " /* r-w ui16 */ 81 - #define FAN_ACTUAL_SPEED "F0Ac" /* r-o fpe2 (2 bytes) */ 82 - #define FAN_MIN_SPEED "F0Mn" /* r-o fpe2 (2 bytes) */ 83 - #define FAN_MAX_SPEED "F0Mx" /* r-o fpe2 (2 bytes) */ 84 - #define FAN_SAFE_SPEED "F0Sf" /* r-o fpe2 (2 bytes) */ 85 - #define FAN_TARGET_SPEED "F0Tg" /* r-w fpe2 (2 bytes) */ 86 - #define FAN_POSITION "F0ID" /* r-o char[16] */ 87 - 88 - /* 89 - * Temperature sensors keys (sp78 - 2 bytes). 90 - */ 91 - static const char *temperature_sensors_sets[][41] = { 92 - /* Set 0: Macbook Pro */ 93 - { "TA0P", "TB0T", "TC0D", "TC0P", "TG0H", "TG0P", "TG0T", "Th0H", 94 - "Th1H", "Tm0P", "Ts0P", "Ts1P", NULL }, 95 - /* Set 1: Macbook2 set */ 96 - { "TB0T", "TC0D", "TC0P", "TM0P", "TN0P", "TN1P", "TTF0", "Th0H", 97 - "Th0S", "Th1H", NULL }, 98 - /* Set 2: Macbook set */ 99 - { "TB0T", "TC0D", "TC0P", "TM0P", "TN0P", "TN1P", "Th0H", "Th0S", 100 - "Th1H", "Ts0P", NULL }, 101 - /* Set 3: Macmini set */ 102 - { "TC0D", "TC0P", NULL }, 103 - /* Set 4: Mac Pro (2 x Quad-Core) */ 104 - { "TA0P", "TCAG", "TCAH", "TCBG", "TCBH", "TC0C", "TC0D", "TC0P", 105 - "TC1C", "TC1D", "TC2C", "TC2D", "TC3C", "TC3D", "THTG", "TH0P", 106 - "TH1P", "TH2P", "TH3P", "TMAP", "TMAS", "TMBS", "TM0P", "TM0S", 107 - "TM1P", "TM1S", "TM2P", "TM2S", "TM3S", "TM8P", "TM8S", "TM9P", 108 - "TM9S", "TN0H", "TS0C", NULL }, 109 - /* Set 5: iMac */ 110 - { "TC0D", "TA0P", "TG0P", "TG0D", "TG0H", "TH0P", "Tm0P", "TO0P", 111 - "Tp0C", NULL }, 112 - /* Set 6: Macbook3 set */ 113 - { "TB0T", "TC0D", "TC0P", "TM0P", "TN0P", "TTF0", "TW0P", "Th0H", 114 - "Th0S", "Th1H", NULL }, 115 - /* Set 7: Macbook Air */ 116 - { "TB0T", "TB1S", "TB1T", "TB2S", "TB2T", "TC0D", "TC0P", "TCFP", 117 - "TTF0", "TW0P", "Th0H", "Tp0P", "TpFP", "Ts0P", "Ts0S", NULL }, 118 - /* Set 8: Macbook Pro 4,1 (Penryn) */ 119 - { "TB0T", "TC0D", "TC0P", "TG0D", "TG0H", "TTF0", "TW0P", "Th0H", 120 - "Th1H", "Th2H", "Tm0P", "Ts0P", NULL }, 121 - /* Set 9: Macbook Pro 3,1 (Santa Rosa) */ 122 - { "TALP", "TB0T", "TC0D", "TC0P", "TG0D", "TG0H", "TTF0", "TW0P", 123 - "Th0H", "Th1H", "Th2H", "Tm0P", "Ts0P", NULL }, 124 - /* Set 10: iMac 5,1 */ 125 - { "TA0P", "TC0D", "TC0P", "TG0D", "TH0P", "TO0P", "Tm0P", NULL }, 126 - /* Set 11: Macbook 5,1 */ 127 - { "TB0T", "TB1T", "TB2T", "TB3T", "TC0D", "TC0P", "TN0D", "TN0P", 128 - "TTF0", "Th0H", "Th1H", "ThFH", "Ts0P", "Ts0S", NULL }, 129 - /* Set 12: Macbook Pro 5,1 */ 130 - { "TB0T", "TB1T", "TB2T", "TB3T", "TC0D", "TC0F", "TC0P", "TG0D", 131 - "TG0F", "TG0H", "TG0P", "TG0T", "TG1H", "TN0D", "TN0P", "TTF0", 132 - "Th2H", "Tm0P", "Ts0P", "Ts0S", NULL }, 133 - /* Set 13: iMac 8,1 */ 134 - { "TA0P", "TC0D", "TC0H", "TC0P", "TG0D", "TG0H", "TG0P", "TH0P", 135 - "TL0P", "TO0P", "TW0P", "Tm0P", "Tp0P", NULL }, 136 - /* Set 14: iMac 6,1 */ 137 - { "TA0P", "TC0D", "TC0H", "TC0P", "TG0D", "TG0H", "TG0P", "TH0P", 138 - "TO0P", "Tp0P", NULL }, 139 - /* Set 15: MacBook Air 2,1 */ 140 - { "TB0T", "TB1S", "TB1T", "TB2S", "TB2T", "TC0D", "TN0D", "TTF0", 141 - "TV0P", "TVFP", "TW0P", "Th0P", "Tp0P", "Tp1P", "TpFP", "Ts0P", 142 - "Ts0S", NULL }, 143 - /* Set 16: Mac Pro 3,1 (2 x Quad-Core) */ 144 - { "TA0P", "TCAG", "TCAH", "TCBG", "TCBH", "TC0C", "TC0D", "TC0P", 145 - "TC1C", "TC1D", "TC2C", "TC2D", "TC3C", "TC3D", "TH0P", "TH1P", 146 - "TH2P", "TH3P", "TMAP", "TMAS", "TMBS", "TM0P", "TM0S", "TM1P", 147 - "TM1S", "TM2P", "TM2S", "TM3S", "TM8P", "TM8S", "TM9P", "TM9S", 148 - "TN0C", "TN0D", "TN0H", "TS0C", "Tp0C", "Tp1C", "Tv0S", "Tv1S", 149 - NULL }, 150 - /* Set 17: iMac 9,1 */ 151 - { "TA0P", "TC0D", "TC0H", "TC0P", "TG0D", "TG0H", "TH0P", "TL0P", 152 - "TN0D", "TN0H", "TN0P", "TO0P", "Tm0P", "Tp0P", NULL }, 153 - /* Set 18: MacBook Pro 2,2 */ 154 - { "TB0T", "TC0D", "TC0P", "TG0H", "TG0P", "TG0T", "TM0P", "TTF0", 155 - "Th0H", "Th1H", "Tm0P", "Ts0P", NULL }, 156 - /* Set 19: Macbook Pro 5,3 */ 157 - { "TB0T", "TB1T", "TB2T", "TB3T", "TC0D", "TC0F", "TC0P", "TG0D", 158 - "TG0F", "TG0H", "TG0P", "TG0T", "TN0D", "TN0P", "TTF0", "Th2H", 159 - "Tm0P", "Ts0P", "Ts0S", NULL }, 160 - /* Set 20: MacBook Pro 5,4 */ 161 - { "TB0T", "TB1T", "TB2T", "TB3T", "TC0D", "TC0F", "TC0P", "TN0D", 162 - "TN0P", "TTF0", "Th2H", "Ts0P", "Ts0S", NULL }, 163 - /* Set 21: MacBook Pro 6,2 */ 164 - { "TB0T", "TB1T", "TB2T", "TC0C", "TC0D", "TC0P", "TC1C", "TG0D", 165 - "TG0P", "TG0T", "TMCD", "TP0P", "TPCD", "Th1H", "Th2H", "Tm0P", 166 - "Ts0P", "Ts0S", NULL }, 167 - /* Set 22: MacBook Pro 7,1 */ 168 - { "TB0T", "TB1T", "TB2T", "TC0D", "TC0P", "TN0D", "TN0P", "TN0S", 169 - "TN1D", "TN1F", "TN1G", "TN1S", "Th1H", "Ts0P", "Ts0S", NULL }, 170 - }; 76 + #define FAN_ID_FMT "F%dID" /* r-o char[16] */ 171 77 172 78 /* List of keys used to read/write fan speeds */ 173 - static const char* fan_speed_keys[] = { 174 - FAN_ACTUAL_SPEED, 175 - FAN_MIN_SPEED, 176 - FAN_MAX_SPEED, 177 - FAN_SAFE_SPEED, 178 - FAN_TARGET_SPEED 79 + static const char *const fan_speed_fmt[] = { 80 + "F%dAc", /* actual speed */ 81 + "F%dMn", /* minimum speed (rw) */ 82 + "F%dMx", /* maximum speed */ 83 + "F%dSf", /* safe speed - not all models */ 84 + "F%dTg", /* target speed (manual: rw) */ 179 85 }; 180 86 181 87 #define INIT_TIMEOUT_MSECS 5000 /* wait up to 5s for device init ... */ ··· 100 184 #define SENSOR_Y 1 101 185 #define SENSOR_Z 2 102 186 103 - /* Structure to be passed to DMI_MATCH function */ 104 - struct dmi_match_data { 105 - /* Indicates whether this computer has an accelerometer. */ 106 - int accelerometer; 107 - /* Indicates whether this computer has light sensors and keyboard backlight. */ 108 - int light; 109 - /* Indicates which temperature sensors set to use. */ 110 - int temperature_set; 187 + #define to_index(attr) (to_sensor_dev_attr(attr)->index & 0xffff) 188 + #define to_option(attr) (to_sensor_dev_attr(attr)->index >> 16) 189 + 190 + /* Dynamic device node attributes */ 191 + struct applesmc_dev_attr { 192 + struct sensor_device_attribute sda; /* hwmon attributes */ 193 + char name[32]; /* room for node file name */ 194 + }; 195 + 196 + /* Dynamic device node group */ 197 + struct applesmc_node_group { 198 + char *format; /* format string */ 199 + void *show; /* show function */ 200 + void *store; /* store function */ 201 + int option; /* function argument */ 202 + struct applesmc_dev_attr *nodes; /* dynamic node array */ 203 + }; 204 + 205 + /* AppleSMC entry - cached register information */ 206 + struct applesmc_entry { 207 + char key[5]; /* four-letter key code */ 208 + u8 valid; /* set when entry is successfully read once */ 209 + u8 len; /* bounded by APPLESMC_MAX_DATA_LENGTH */ 210 + char type[5]; /* four-letter type code */ 211 + u8 flags; /* 0x10: func; 0x40: write; 0x80: read */ 212 + }; 213 + 214 + /* Register lookup and registers common to all SMCs */ 215 + static struct applesmc_registers { 216 + struct mutex mutex; /* register read/write mutex */ 217 + unsigned int key_count; /* number of SMC registers */ 218 + unsigned int fan_count; /* number of fans */ 219 + unsigned int temp_count; /* number of temperature registers */ 220 + unsigned int temp_begin; /* temperature lower index bound */ 221 + unsigned int temp_end; /* temperature upper index bound */ 222 + int num_light_sensors; /* number of light sensors */ 223 + bool has_accelerometer; /* has motion sensor */ 224 + bool has_key_backlight; /* has keyboard backlight */ 225 + bool init_complete; /* true when fully initialized */ 226 + struct applesmc_entry *cache; /* cached key entries */ 227 + } smcreg = { 228 + .mutex = __MUTEX_INITIALIZER(smcreg.mutex), 111 229 }; 112 230 113 231 static const int debug; ··· 152 202 153 203 static struct device *hwmon_dev; 154 204 static struct input_polled_dev *applesmc_idev; 155 - 156 - /* Indicates whether this computer has an accelerometer. */ 157 - static unsigned int applesmc_accelerometer; 158 - 159 - /* Indicates whether this computer has light sensors and keyboard backlight. */ 160 - static unsigned int applesmc_light; 161 - 162 - /* The number of fans handled by the driver */ 163 - static unsigned int fans_handled; 164 - 165 - /* Indicates which temperature sensors set to use. */ 166 - static unsigned int applesmc_temperature_set; 167 - 168 - static DEFINE_MUTEX(applesmc_lock); 169 205 170 206 /* 171 207 * Last index written to key_at_index sysfs file, and value to use for all other ··· 174 238 175 239 for (us = APPLESMC_MIN_WAIT; us < APPLESMC_MAX_WAIT; us <<= 1) { 176 240 udelay(us); 177 - if ((inb(APPLESMC_CMD_PORT) & APPLESMC_STATUS_MASK) == val) { 178 - if (debug) 179 - printk(KERN_DEBUG 180 - "Waited %d us for status %x\n", 181 - 2 * us - APPLESMC_MIN_WAIT, val); 241 + if ((inb(APPLESMC_CMD_PORT) & APPLESMC_STATUS_MASK) == val) 182 242 return 0; 183 - } 184 243 } 185 - 186 - printk(KERN_WARNING "applesmc: wait status failed: %x != %x\n", 187 - val, inb(APPLESMC_CMD_PORT)); 188 244 189 245 return -EIO; 190 246 } ··· 195 267 if ((inb(APPLESMC_CMD_PORT) & APPLESMC_STATUS_MASK) == 0x0c) 196 268 return 0; 197 269 } 198 - printk(KERN_WARNING "applesmc: command failed: %x -> %x\n", 199 - cmd, inb(APPLESMC_CMD_PORT)); 200 270 return -EIO; 201 271 } 202 272 203 - /* 204 - * applesmc_read_key - reads len bytes from a given key, and put them in buffer. 205 - * Returns zero on success or a negative error on failure. Callers must 206 - * hold applesmc_lock. 207 - */ 208 - static int applesmc_read_key(const char* key, u8* buffer, u8 len) 273 + static int send_argument(const char *key) 209 274 { 210 275 int i; 211 - 212 - if (len > APPLESMC_MAX_DATA_LENGTH) { 213 - printk(KERN_ERR "applesmc_read_key: cannot read more than " 214 - "%d bytes\n", APPLESMC_MAX_DATA_LENGTH); 215 - return -EINVAL; 216 - } 217 - 218 - if (send_command(APPLESMC_READ_CMD)) 219 - return -EIO; 220 276 221 277 for (i = 0; i < 4; i++) { 222 278 outb(key[i], APPLESMC_DATA_PORT); 223 279 if (__wait_status(0x04)) 224 280 return -EIO; 225 281 } 226 - if (debug) 227 - printk(KERN_DEBUG "<%s", key); 282 + return 0; 283 + } 284 + 285 + static int read_smc(u8 cmd, const char *key, u8 *buffer, u8 len) 286 + { 287 + int i; 288 + 289 + if (send_command(cmd) || send_argument(key)) { 290 + pr_warn("%s: read arg fail\n", key); 291 + return -EIO; 292 + } 228 293 229 294 outb(len, APPLESMC_DATA_PORT); 230 - if (debug) 231 - printk(KERN_DEBUG ">%x", len); 232 295 233 296 for (i = 0; i < len; i++) { 234 - if (__wait_status(0x05)) 297 + if (__wait_status(0x05)) { 298 + pr_warn("%s: read data fail\n", key); 235 299 return -EIO; 300 + } 236 301 buffer[i] = inb(APPLESMC_DATA_PORT); 237 - if (debug) 238 - printk(KERN_DEBUG "<%x", buffer[i]); 239 302 } 240 - if (debug) 241 - printk(KERN_DEBUG "\n"); 242 303 243 304 return 0; 244 305 } 245 306 246 - /* 247 - * applesmc_write_key - writes len bytes from buffer to a given key. 248 - * Returns zero on success or a negative error on failure. Callers must 249 - * hold applesmc_lock. 250 - */ 251 - static int applesmc_write_key(const char* key, u8* buffer, u8 len) 307 + static int write_smc(u8 cmd, const char *key, const u8 *buffer, u8 len) 252 308 { 253 309 int i; 254 310 255 - if (len > APPLESMC_MAX_DATA_LENGTH) { 256 - printk(KERN_ERR "applesmc_write_key: cannot write more than " 257 - "%d bytes\n", APPLESMC_MAX_DATA_LENGTH); 258 - return -EINVAL; 259 - } 260 - 261 - if (send_command(APPLESMC_WRITE_CMD)) 311 + if (send_command(cmd) || send_argument(key)) { 312 + pr_warn("%s: write arg fail\n", key); 262 313 return -EIO; 263 - 264 - for (i = 0; i < 4; i++) { 265 - outb(key[i], APPLESMC_DATA_PORT); 266 - if (__wait_status(0x04)) 267 - return -EIO; 268 314 } 269 315 270 316 outb(len, APPLESMC_DATA_PORT); 271 317 272 318 for (i = 0; i < len; i++) { 273 - if (__wait_status(0x04)) 319 + if (__wait_status(0x04)) { 320 + pr_warn("%s: write data fail\n", key); 274 321 return -EIO; 322 + } 275 323 outb(buffer[i], APPLESMC_DATA_PORT); 276 324 } 277 325 278 326 return 0; 279 327 } 280 328 281 - /* 282 - * applesmc_get_key_at_index - get key at index, and put the result in key 283 - * (char[6]). Returns zero on success or a negative error on failure. Callers 284 - * must hold applesmc_lock. 285 - */ 286 - static int applesmc_get_key_at_index(int index, char* key) 329 + static int read_register_count(unsigned int *count) 287 330 { 288 - int i; 289 - u8 readkey[4]; 290 - readkey[0] = index >> 24; 291 - readkey[1] = index >> 16; 292 - readkey[2] = index >> 8; 293 - readkey[3] = index; 331 + __be32 be; 332 + int ret; 294 333 295 - if (send_command(APPLESMC_GET_KEY_BY_INDEX_CMD)) 296 - return -EIO; 334 + ret = read_smc(APPLESMC_READ_CMD, KEY_COUNT_KEY, (u8 *)&be, 4); 335 + if (ret) 336 + return ret; 297 337 298 - for (i = 0; i < 4; i++) { 299 - outb(readkey[i], APPLESMC_DATA_PORT); 300 - if (__wait_status(0x04)) 301 - return -EIO; 302 - } 303 - 304 - outb(4, APPLESMC_DATA_PORT); 305 - 306 - for (i = 0; i < 4; i++) { 307 - if (__wait_status(0x05)) 308 - return -EIO; 309 - key[i] = inb(APPLESMC_DATA_PORT); 310 - } 311 - key[4] = 0; 312 - 338 + *count = be32_to_cpu(be); 313 339 return 0; 314 340 } 315 341 316 342 /* 317 - * applesmc_get_key_type - get key type, and put the result in type (char[6]). 318 - * Returns zero on success or a negative error on failure. Callers must 319 - * hold applesmc_lock. 343 + * Serialized I/O 344 + * 345 + * Returns zero on success or a negative error on failure. 346 + * All functions below are concurrency safe - callers should NOT hold lock. 320 347 */ 321 - static int applesmc_get_key_type(char* key, char* type) 348 + 349 + static int applesmc_read_entry(const struct applesmc_entry *entry, 350 + u8 *buf, u8 len) 322 351 { 323 - int i; 352 + int ret; 324 353 325 - if (send_command(APPLESMC_GET_KEY_TYPE_CMD)) 326 - return -EIO; 354 + if (entry->len != len) 355 + return -EINVAL; 356 + mutex_lock(&smcreg.mutex); 357 + ret = read_smc(APPLESMC_READ_CMD, entry->key, buf, len); 358 + mutex_unlock(&smcreg.mutex); 327 359 328 - for (i = 0; i < 4; i++) { 329 - outb(key[i], APPLESMC_DATA_PORT); 330 - if (__wait_status(0x04)) 331 - return -EIO; 360 + return ret; 361 + } 362 + 363 + static int applesmc_write_entry(const struct applesmc_entry *entry, 364 + const u8 *buf, u8 len) 365 + { 366 + int ret; 367 + 368 + if (entry->len != len) 369 + return -EINVAL; 370 + mutex_lock(&smcreg.mutex); 371 + ret = write_smc(APPLESMC_WRITE_CMD, entry->key, buf, len); 372 + mutex_unlock(&smcreg.mutex); 373 + return ret; 374 + } 375 + 376 + static const struct applesmc_entry *applesmc_get_entry_by_index(int index) 377 + { 378 + struct applesmc_entry *cache = &smcreg.cache[index]; 379 + u8 key[4], info[6]; 380 + __be32 be; 381 + int ret = 0; 382 + 383 + if (cache->valid) 384 + return cache; 385 + 386 + mutex_lock(&smcreg.mutex); 387 + 388 + if (cache->valid) 389 + goto out; 390 + be = cpu_to_be32(index); 391 + ret = read_smc(APPLESMC_GET_KEY_BY_INDEX_CMD, (u8 *)&be, key, 4); 392 + if (ret) 393 + goto out; 394 + ret = read_smc(APPLESMC_GET_KEY_TYPE_CMD, key, info, 6); 395 + if (ret) 396 + goto out; 397 + 398 + memcpy(cache->key, key, 4); 399 + cache->len = info[0]; 400 + memcpy(cache->type, &info[1], 4); 401 + cache->flags = info[5]; 402 + cache->valid = 1; 403 + 404 + out: 405 + mutex_unlock(&smcreg.mutex); 406 + if (ret) 407 + return ERR_PTR(ret); 408 + return cache; 409 + } 410 + 411 + static int applesmc_get_lower_bound(unsigned int *lo, const char *key) 412 + { 413 + int begin = 0, end = smcreg.key_count; 414 + const struct applesmc_entry *entry; 415 + 416 + while (begin != end) { 417 + int middle = begin + (end - begin) / 2; 418 + entry = applesmc_get_entry_by_index(middle); 419 + if (IS_ERR(entry)) 420 + return PTR_ERR(entry); 421 + if (strcmp(entry->key, key) < 0) 422 + begin = middle + 1; 423 + else 424 + end = middle; 332 425 } 333 426 334 - outb(6, APPLESMC_DATA_PORT); 427 + *lo = begin; 428 + return 0; 429 + } 335 430 336 - for (i = 0; i < 6; i++) { 337 - if (__wait_status(0x05)) 338 - return -EIO; 339 - type[i] = inb(APPLESMC_DATA_PORT); 431 + static int applesmc_get_upper_bound(unsigned int *hi, const char *key) 432 + { 433 + int begin = 0, end = smcreg.key_count; 434 + const struct applesmc_entry *entry; 435 + 436 + while (begin != end) { 437 + int middle = begin + (end - begin) / 2; 438 + entry = applesmc_get_entry_by_index(middle); 439 + if (IS_ERR(entry)) 440 + return PTR_ERR(entry); 441 + if (strcmp(key, entry->key) < 0) 442 + end = middle; 443 + else 444 + begin = middle + 1; 340 445 } 341 - type[5] = 0; 342 446 447 + *hi = begin; 448 + return 0; 449 + } 450 + 451 + static const struct applesmc_entry *applesmc_get_entry_by_key(const char *key) 452 + { 453 + int begin, end; 454 + int ret; 455 + 456 + ret = applesmc_get_lower_bound(&begin, key); 457 + if (ret) 458 + return ERR_PTR(ret); 459 + ret = applesmc_get_upper_bound(&end, key); 460 + if (ret) 461 + return ERR_PTR(ret); 462 + if (end - begin != 1) 463 + return ERR_PTR(-EINVAL); 464 + 465 + return applesmc_get_entry_by_index(begin); 466 + } 467 + 468 + static int applesmc_read_key(const char *key, u8 *buffer, u8 len) 469 + { 470 + const struct applesmc_entry *entry; 471 + 472 + entry = applesmc_get_entry_by_key(key); 473 + if (IS_ERR(entry)) 474 + return PTR_ERR(entry); 475 + 476 + return applesmc_read_entry(entry, buffer, len); 477 + } 478 + 479 + static int applesmc_write_key(const char *key, const u8 *buffer, u8 len) 480 + { 481 + const struct applesmc_entry *entry; 482 + 483 + entry = applesmc_get_entry_by_key(key); 484 + if (IS_ERR(entry)) 485 + return PTR_ERR(entry); 486 + 487 + return applesmc_write_entry(entry, buffer, len); 488 + } 489 + 490 + static int applesmc_has_key(const char *key, bool *value) 491 + { 492 + const struct applesmc_entry *entry; 493 + 494 + entry = applesmc_get_entry_by_key(key); 495 + if (IS_ERR(entry) && PTR_ERR(entry) != -EINVAL) 496 + return PTR_ERR(entry); 497 + 498 + *value = !IS_ERR(entry); 343 499 return 0; 344 500 } 345 501 346 502 /* 347 - * applesmc_read_motion_sensor - Read motion sensor (X, Y or Z). Callers must 348 - * hold applesmc_lock. 503 + * applesmc_read_motion_sensor - Read motion sensor (X, Y or Z). 349 504 */ 350 - static int applesmc_read_motion_sensor(int index, s16* value) 505 + static int applesmc_read_motion_sensor(int index, s16 *value) 351 506 { 352 507 u8 buffer[2]; 353 508 int ret; ··· 455 444 } 456 445 457 446 /* 458 - * applesmc_device_init - initialize the accelerometer. Returns zero on success 459 - * and negative error code on failure. Can sleep. 447 + * applesmc_device_init - initialize the accelerometer. Can sleep. 460 448 */ 461 - static int applesmc_device_init(void) 449 + static void applesmc_device_init(void) 462 450 { 463 - int total, ret = -ENXIO; 451 + int total; 464 452 u8 buffer[2]; 465 453 466 - if (!applesmc_accelerometer) 467 - return 0; 468 - 469 - mutex_lock(&applesmc_lock); 454 + if (!smcreg.has_accelerometer) 455 + return; 470 456 471 457 for (total = INIT_TIMEOUT_MSECS; total > 0; total -= INIT_WAIT_MSECS) { 472 - if (debug) 473 - printk(KERN_DEBUG "applesmc try %d\n", total); 474 458 if (!applesmc_read_key(MOTION_SENSOR_KEY, buffer, 2) && 475 - (buffer[0] != 0x00 || buffer[1] != 0x00)) { 476 - if (total == INIT_TIMEOUT_MSECS) { 477 - printk(KERN_DEBUG "applesmc: device has" 478 - " already been initialized" 479 - " (0x%02x, 0x%02x).\n", 480 - buffer[0], buffer[1]); 481 - } else { 482 - printk(KERN_DEBUG "applesmc: device" 483 - " successfully initialized" 484 - " (0x%02x, 0x%02x).\n", 485 - buffer[0], buffer[1]); 486 - } 487 - ret = 0; 488 - goto out; 489 - } 459 + (buffer[0] != 0x00 || buffer[1] != 0x00)) 460 + return; 490 461 buffer[0] = 0xe0; 491 462 buffer[1] = 0x00; 492 463 applesmc_write_key(MOTION_SENSOR_KEY, buffer, 2); 493 464 msleep(INIT_WAIT_MSECS); 494 465 } 495 466 496 - printk(KERN_WARNING "applesmc: failed to init the device\n"); 497 - 498 - out: 499 - mutex_unlock(&applesmc_lock); 500 - return ret; 467 + pr_warn("failed to init the device\n"); 501 468 } 502 469 503 470 /* 504 - * applesmc_get_fan_count - get the number of fans. Callers must NOT hold 505 - * applesmc_lock. 471 + * applesmc_init_smcreg_try - Try to initialize register cache. Idempotent. 506 472 */ 507 - static int applesmc_get_fan_count(void) 473 + static int applesmc_init_smcreg_try(void) 508 474 { 475 + struct applesmc_registers *s = &smcreg; 476 + bool left_light_sensor, right_light_sensor; 477 + u8 tmp[1]; 509 478 int ret; 510 - u8 buffer[1]; 511 479 512 - mutex_lock(&applesmc_lock); 480 + if (s->init_complete) 481 + return 0; 513 482 514 - ret = applesmc_read_key(FANS_COUNT, buffer, 1); 515 - 516 - mutex_unlock(&applesmc_lock); 483 + ret = read_register_count(&s->key_count); 517 484 if (ret) 518 485 return ret; 519 - else 520 - return buffer[0]; 486 + 487 + if (!s->cache) 488 + s->cache = kcalloc(s->key_count, sizeof(*s->cache), GFP_KERNEL); 489 + if (!s->cache) 490 + return -ENOMEM; 491 + 492 + ret = applesmc_read_key(FANS_COUNT, tmp, 1); 493 + if (ret) 494 + return ret; 495 + s->fan_count = tmp[0]; 496 + 497 + ret = applesmc_get_lower_bound(&s->temp_begin, "T"); 498 + if (ret) 499 + return ret; 500 + ret = applesmc_get_lower_bound(&s->temp_end, "U"); 501 + if (ret) 502 + return ret; 503 + s->temp_count = s->temp_end - s->temp_begin; 504 + 505 + ret = applesmc_has_key(LIGHT_SENSOR_LEFT_KEY, &left_light_sensor); 506 + if (ret) 507 + return ret; 508 + ret = applesmc_has_key(LIGHT_SENSOR_RIGHT_KEY, &right_light_sensor); 509 + if (ret) 510 + return ret; 511 + ret = applesmc_has_key(MOTION_SENSOR_KEY, &s->has_accelerometer); 512 + if (ret) 513 + return ret; 514 + ret = applesmc_has_key(BACKLIGHT_KEY, &s->has_key_backlight); 515 + if (ret) 516 + return ret; 517 + 518 + s->num_light_sensors = left_light_sensor + right_light_sensor; 519 + s->init_complete = true; 520 + 521 + pr_info("key=%d fan=%d temp=%d acc=%d lux=%d kbd=%d\n", 522 + s->key_count, s->fan_count, s->temp_count, 523 + s->has_accelerometer, 524 + s->num_light_sensors, 525 + s->has_key_backlight); 526 + 527 + return 0; 528 + } 529 + 530 + /* 531 + * applesmc_init_smcreg - Initialize register cache. 532 + * 533 + * Retries until initialization is successful, or the operation times out. 534 + * 535 + */ 536 + static int applesmc_init_smcreg(void) 537 + { 538 + int ms, ret; 539 + 540 + for (ms = 0; ms < INIT_TIMEOUT_MSECS; ms += INIT_WAIT_MSECS) { 541 + ret = applesmc_init_smcreg_try(); 542 + if (!ret) { 543 + if (ms) 544 + pr_info("init_smcreg() took %d ms\n", ms); 545 + return 0; 546 + } 547 + msleep(INIT_WAIT_MSECS); 548 + } 549 + 550 + kfree(smcreg.cache); 551 + smcreg.cache = NULL; 552 + 553 + return ret; 554 + } 555 + 556 + static void applesmc_destroy_smcreg(void) 557 + { 558 + kfree(smcreg.cache); 559 + smcreg.cache = NULL; 560 + smcreg.init_complete = false; 521 561 } 522 562 523 563 /* Device model stuff */ ··· 576 514 { 577 515 int ret; 578 516 579 - ret = applesmc_device_init(); 517 + ret = applesmc_init_smcreg(); 580 518 if (ret) 581 519 return ret; 582 520 583 - printk(KERN_INFO "applesmc: device successfully initialized.\n"); 521 + applesmc_device_init(); 522 + 584 523 return 0; 585 524 } 586 525 587 526 /* Synchronize device with memorized backlight state */ 588 527 static int applesmc_pm_resume(struct device *dev) 589 528 { 590 - mutex_lock(&applesmc_lock); 591 - if (applesmc_light) 529 + if (smcreg.has_key_backlight) 592 530 applesmc_write_key(BACKLIGHT_KEY, backlight_state, 2); 593 - mutex_unlock(&applesmc_lock); 594 531 return 0; 595 532 } 596 533 597 534 /* Reinitialize device on resume from hibernation */ 598 535 static int applesmc_pm_restore(struct device *dev) 599 536 { 600 - int ret = applesmc_device_init(); 601 - if (ret) 602 - return ret; 537 + applesmc_device_init(); 603 538 return applesmc_pm_resume(dev); 604 539 } 605 540 ··· 630 571 struct input_dev *idev = dev->input; 631 572 s16 x, y; 632 573 633 - mutex_lock(&applesmc_lock); 634 - 635 574 if (applesmc_read_motion_sensor(SENSOR_X, &x)) 636 - goto out; 575 + return; 637 576 if (applesmc_read_motion_sensor(SENSOR_Y, &y)) 638 - goto out; 577 + return; 639 578 640 579 x = -x; 641 580 input_report_abs(idev, ABS_X, x - rest_x); 642 581 input_report_abs(idev, ABS_Y, y - rest_y); 643 582 input_sync(idev); 644 - 645 - out: 646 - mutex_unlock(&applesmc_lock); 647 583 } 648 584 649 585 /* Sysfs Files */ ··· 655 601 int ret; 656 602 s16 x, y, z; 657 603 658 - mutex_lock(&applesmc_lock); 659 - 660 604 ret = applesmc_read_motion_sensor(SENSOR_X, &x); 661 605 if (ret) 662 606 goto out; ··· 666 614 goto out; 667 615 668 616 out: 669 - mutex_unlock(&applesmc_lock); 670 617 if (ret) 671 618 return ret; 672 619 else ··· 675 624 static ssize_t applesmc_light_show(struct device *dev, 676 625 struct device_attribute *attr, char *sysfsbuf) 677 626 { 627 + const struct applesmc_entry *entry; 678 628 static int data_length; 679 629 int ret; 680 630 u8 left = 0, right = 0; 681 - u8 buffer[10], query[6]; 682 - 683 - mutex_lock(&applesmc_lock); 631 + u8 buffer[10]; 684 632 685 633 if (!data_length) { 686 - ret = applesmc_get_key_type(LIGHT_SENSOR_LEFT_KEY, query); 687 - if (ret) 688 - goto out; 689 - data_length = clamp_val(query[0], 0, 10); 690 - printk(KERN_INFO "applesmc: light sensor data length set to " 691 - "%d\n", data_length); 634 + entry = applesmc_get_entry_by_key(LIGHT_SENSOR_LEFT_KEY); 635 + if (IS_ERR(entry)) 636 + return PTR_ERR(entry); 637 + if (entry->len > 10) 638 + return -ENXIO; 639 + data_length = entry->len; 640 + pr_info("light sensor data length set to %d\n", data_length); 692 641 } 693 642 694 643 ret = applesmc_read_key(LIGHT_SENSOR_LEFT_KEY, buffer, data_length); ··· 704 653 right = buffer[2]; 705 654 706 655 out: 707 - mutex_unlock(&applesmc_lock); 708 656 if (ret) 709 657 return ret; 710 658 else ··· 714 664 static ssize_t applesmc_show_sensor_label(struct device *dev, 715 665 struct device_attribute *devattr, char *sysfsbuf) 716 666 { 717 - struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 718 - const char *key = 719 - temperature_sensors_sets[applesmc_temperature_set][attr->index]; 667 + int index = smcreg.temp_begin + to_index(devattr); 668 + const struct applesmc_entry *entry; 720 669 721 - return snprintf(sysfsbuf, PAGE_SIZE, "%s\n", key); 670 + entry = applesmc_get_entry_by_index(index); 671 + if (IS_ERR(entry)) 672 + return PTR_ERR(entry); 673 + 674 + return snprintf(sysfsbuf, PAGE_SIZE, "%s\n", entry->key); 722 675 } 723 676 724 677 /* Displays degree Celsius * 1000 */ 725 678 static ssize_t applesmc_show_temperature(struct device *dev, 726 679 struct device_attribute *devattr, char *sysfsbuf) 727 680 { 681 + int index = smcreg.temp_begin + to_index(devattr); 682 + const struct applesmc_entry *entry; 728 683 int ret; 729 684 u8 buffer[2]; 730 685 unsigned int temp; 731 - struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 732 - const char* key = 733 - temperature_sensors_sets[applesmc_temperature_set][attr->index]; 734 686 735 - mutex_lock(&applesmc_lock); 687 + entry = applesmc_get_entry_by_index(index); 688 + if (IS_ERR(entry)) 689 + return PTR_ERR(entry); 690 + if (entry->len > 2) 691 + return -EINVAL; 736 692 737 - ret = applesmc_read_key(key, buffer, 2); 738 - temp = buffer[0]*1000; 739 - temp += (buffer[1] >> 6) * 250; 740 - 741 - mutex_unlock(&applesmc_lock); 742 - 693 + ret = applesmc_read_entry(entry, buffer, entry->len); 743 694 if (ret) 744 695 return ret; 745 - else 746 - return snprintf(sysfsbuf, PAGE_SIZE, "%u\n", temp); 696 + 697 + if (entry->len == 2) { 698 + temp = buffer[0] * 1000; 699 + temp += (buffer[1] >> 6) * 250; 700 + } else { 701 + temp = buffer[0] * 4000; 702 + } 703 + 704 + return snprintf(sysfsbuf, PAGE_SIZE, "%u\n", temp); 747 705 } 748 706 749 707 static ssize_t applesmc_show_fan_speed(struct device *dev, ··· 761 703 unsigned int speed = 0; 762 704 char newkey[5]; 763 705 u8 buffer[2]; 764 - struct sensor_device_attribute_2 *sensor_attr = 765 - to_sensor_dev_attr_2(attr); 766 706 767 - newkey[0] = fan_speed_keys[sensor_attr->nr][0]; 768 - newkey[1] = '0' + sensor_attr->index; 769 - newkey[2] = fan_speed_keys[sensor_attr->nr][2]; 770 - newkey[3] = fan_speed_keys[sensor_attr->nr][3]; 771 - newkey[4] = 0; 772 - 773 - mutex_lock(&applesmc_lock); 707 + sprintf(newkey, fan_speed_fmt[to_option(attr)], to_index(attr)); 774 708 775 709 ret = applesmc_read_key(newkey, buffer, 2); 776 710 speed = ((buffer[0] << 8 | buffer[1]) >> 2); 777 711 778 - mutex_unlock(&applesmc_lock); 779 712 if (ret) 780 713 return ret; 781 714 else ··· 778 729 const char *sysfsbuf, size_t count) 779 730 { 780 731 int ret; 781 - u32 speed; 732 + unsigned long speed; 782 733 char newkey[5]; 783 734 u8 buffer[2]; 784 - struct sensor_device_attribute_2 *sensor_attr = 785 - to_sensor_dev_attr_2(attr); 786 735 787 - speed = simple_strtoul(sysfsbuf, NULL, 10); 736 + if (strict_strtoul(sysfsbuf, 10, &speed) < 0 || speed >= 0x4000) 737 + return -EINVAL; /* Bigger than a 14-bit value */ 788 738 789 - if (speed > 0x4000) /* Bigger than a 14-bit value */ 790 - return -EINVAL; 791 - 792 - newkey[0] = fan_speed_keys[sensor_attr->nr][0]; 793 - newkey[1] = '0' + sensor_attr->index; 794 - newkey[2] = fan_speed_keys[sensor_attr->nr][2]; 795 - newkey[3] = fan_speed_keys[sensor_attr->nr][3]; 796 - newkey[4] = 0; 797 - 798 - mutex_lock(&applesmc_lock); 739 + sprintf(newkey, fan_speed_fmt[to_option(attr)], to_index(attr)); 799 740 800 741 buffer[0] = (speed >> 6) & 0xff; 801 742 buffer[1] = (speed << 2) & 0xff; 802 743 ret = applesmc_write_key(newkey, buffer, 2); 803 744 804 - mutex_unlock(&applesmc_lock); 805 745 if (ret) 806 746 return ret; 807 747 else ··· 798 760 } 799 761 800 762 static ssize_t applesmc_show_fan_manual(struct device *dev, 801 - struct device_attribute *devattr, char *sysfsbuf) 763 + struct device_attribute *attr, char *sysfsbuf) 802 764 { 803 765 int ret; 804 766 u16 manual = 0; 805 767 u8 buffer[2]; 806 - struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 807 - 808 - mutex_lock(&applesmc_lock); 809 768 810 769 ret = applesmc_read_key(FANS_MANUAL, buffer, 2); 811 - manual = ((buffer[0] << 8 | buffer[1]) >> attr->index) & 0x01; 770 + manual = ((buffer[0] << 8 | buffer[1]) >> to_index(attr)) & 0x01; 812 771 813 - mutex_unlock(&applesmc_lock); 814 772 if (ret) 815 773 return ret; 816 774 else ··· 814 780 } 815 781 816 782 static ssize_t applesmc_store_fan_manual(struct device *dev, 817 - struct device_attribute *devattr, 783 + struct device_attribute *attr, 818 784 const char *sysfsbuf, size_t count) 819 785 { 820 786 int ret; 821 787 u8 buffer[2]; 822 - u32 input; 788 + unsigned long input; 823 789 u16 val; 824 - struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 825 790 826 - input = simple_strtoul(sysfsbuf, NULL, 10); 827 - 828 - mutex_lock(&applesmc_lock); 791 + if (strict_strtoul(sysfsbuf, 10, &input) < 0) 792 + return -EINVAL; 829 793 830 794 ret = applesmc_read_key(FANS_MANUAL, buffer, 2); 831 795 val = (buffer[0] << 8 | buffer[1]); ··· 831 799 goto out; 832 800 833 801 if (input) 834 - val = val | (0x01 << attr->index); 802 + val = val | (0x01 << to_index(attr)); 835 803 else 836 - val = val & ~(0x01 << attr->index); 804 + val = val & ~(0x01 << to_index(attr)); 837 805 838 806 buffer[0] = (val >> 8) & 0xFF; 839 807 buffer[1] = val & 0xFF; ··· 841 809 ret = applesmc_write_key(FANS_MANUAL, buffer, 2); 842 810 843 811 out: 844 - mutex_unlock(&applesmc_lock); 845 812 if (ret) 846 813 return ret; 847 814 else ··· 853 822 int ret; 854 823 char newkey[5]; 855 824 u8 buffer[17]; 856 - struct sensor_device_attribute_2 *sensor_attr = 857 - to_sensor_dev_attr_2(attr); 858 825 859 - newkey[0] = FAN_POSITION[0]; 860 - newkey[1] = '0' + sensor_attr->index; 861 - newkey[2] = FAN_POSITION[2]; 862 - newkey[3] = FAN_POSITION[3]; 863 - newkey[4] = 0; 864 - 865 - mutex_lock(&applesmc_lock); 826 + sprintf(newkey, FAN_ID_FMT, to_index(attr)); 866 827 867 828 ret = applesmc_read_key(newkey, buffer, 16); 868 829 buffer[16] = 0; 869 830 870 - mutex_unlock(&applesmc_lock); 871 831 if (ret) 872 832 return ret; 873 833 else ··· 874 852 static ssize_t applesmc_calibrate_store(struct device *dev, 875 853 struct device_attribute *attr, const char *sysfsbuf, size_t count) 876 854 { 877 - mutex_lock(&applesmc_lock); 878 855 applesmc_calibrate(); 879 - mutex_unlock(&applesmc_lock); 880 856 881 857 return count; 882 858 } 883 859 884 860 static void applesmc_backlight_set(struct work_struct *work) 885 861 { 886 - mutex_lock(&applesmc_lock); 887 862 applesmc_write_key(BACKLIGHT_KEY, backlight_state, 2); 888 - mutex_unlock(&applesmc_lock); 889 863 } 890 864 static DECLARE_WORK(backlight_work, &applesmc_backlight_set); 891 865 ··· 904 886 u8 buffer[4]; 905 887 u32 count; 906 888 907 - mutex_lock(&applesmc_lock); 908 - 909 889 ret = applesmc_read_key(KEY_COUNT_KEY, buffer, 4); 910 890 count = ((u32)buffer[0]<<24) + ((u32)buffer[1]<<16) + 911 891 ((u32)buffer[2]<<8) + buffer[3]; 912 892 913 - mutex_unlock(&applesmc_lock); 914 893 if (ret) 915 894 return ret; 916 895 else ··· 917 902 static ssize_t applesmc_key_at_index_read_show(struct device *dev, 918 903 struct device_attribute *attr, char *sysfsbuf) 919 904 { 920 - char key[5]; 921 - char info[6]; 905 + const struct applesmc_entry *entry; 922 906 int ret; 923 907 924 - mutex_lock(&applesmc_lock); 925 - 926 - ret = applesmc_get_key_at_index(key_at_index, key); 927 - 928 - if (ret || !key[0]) { 929 - mutex_unlock(&applesmc_lock); 930 - 931 - return -EINVAL; 932 - } 933 - 934 - ret = applesmc_get_key_type(key, info); 935 - 936 - if (ret) { 937 - mutex_unlock(&applesmc_lock); 938 - 908 + entry = applesmc_get_entry_by_index(key_at_index); 909 + if (IS_ERR(entry)) 910 + return PTR_ERR(entry); 911 + ret = applesmc_read_entry(entry, sysfsbuf, entry->len); 912 + if (ret) 939 913 return ret; 940 - } 941 914 942 - /* 943 - * info[0] maximum value (APPLESMC_MAX_DATA_LENGTH) is much lower than 944 - * PAGE_SIZE, so we don't need any checks before writing to sysfsbuf. 945 - */ 946 - ret = applesmc_read_key(key, sysfsbuf, info[0]); 947 - 948 - mutex_unlock(&applesmc_lock); 949 - 950 - if (!ret) { 951 - return info[0]; 952 - } else { 953 - return ret; 954 - } 915 + return entry->len; 955 916 } 956 917 957 918 static ssize_t applesmc_key_at_index_data_length_show(struct device *dev, 958 919 struct device_attribute *attr, char *sysfsbuf) 959 920 { 960 - char key[5]; 961 - char info[6]; 962 - int ret; 921 + const struct applesmc_entry *entry; 963 922 964 - mutex_lock(&applesmc_lock); 923 + entry = applesmc_get_entry_by_index(key_at_index); 924 + if (IS_ERR(entry)) 925 + return PTR_ERR(entry); 965 926 966 - ret = applesmc_get_key_at_index(key_at_index, key); 967 - 968 - if (ret || !key[0]) { 969 - mutex_unlock(&applesmc_lock); 970 - 971 - return -EINVAL; 972 - } 973 - 974 - ret = applesmc_get_key_type(key, info); 975 - 976 - mutex_unlock(&applesmc_lock); 977 - 978 - if (!ret) 979 - return snprintf(sysfsbuf, PAGE_SIZE, "%d\n", info[0]); 980 - else 981 - return ret; 927 + return snprintf(sysfsbuf, PAGE_SIZE, "%d\n", entry->len); 982 928 } 983 929 984 930 static ssize_t applesmc_key_at_index_type_show(struct device *dev, 985 931 struct device_attribute *attr, char *sysfsbuf) 986 932 { 987 - char key[5]; 988 - char info[6]; 989 - int ret; 933 + const struct applesmc_entry *entry; 990 934 991 - mutex_lock(&applesmc_lock); 935 + entry = applesmc_get_entry_by_index(key_at_index); 936 + if (IS_ERR(entry)) 937 + return PTR_ERR(entry); 992 938 993 - ret = applesmc_get_key_at_index(key_at_index, key); 994 - 995 - if (ret || !key[0]) { 996 - mutex_unlock(&applesmc_lock); 997 - 998 - return -EINVAL; 999 - } 1000 - 1001 - ret = applesmc_get_key_type(key, info); 1002 - 1003 - mutex_unlock(&applesmc_lock); 1004 - 1005 - if (!ret) 1006 - return snprintf(sysfsbuf, PAGE_SIZE, "%s\n", info+1); 1007 - else 1008 - return ret; 939 + return snprintf(sysfsbuf, PAGE_SIZE, "%s\n", entry->type); 1009 940 } 1010 941 1011 942 static ssize_t applesmc_key_at_index_name_show(struct device *dev, 1012 943 struct device_attribute *attr, char *sysfsbuf) 1013 944 { 1014 - char key[5]; 1015 - int ret; 945 + const struct applesmc_entry *entry; 1016 946 1017 - mutex_lock(&applesmc_lock); 947 + entry = applesmc_get_entry_by_index(key_at_index); 948 + if (IS_ERR(entry)) 949 + return PTR_ERR(entry); 1018 950 1019 - ret = applesmc_get_key_at_index(key_at_index, key); 1020 - 1021 - mutex_unlock(&applesmc_lock); 1022 - 1023 - if (!ret && key[0]) 1024 - return snprintf(sysfsbuf, PAGE_SIZE, "%s\n", key); 1025 - else 1026 - return -EINVAL; 951 + return snprintf(sysfsbuf, PAGE_SIZE, "%s\n", entry->key); 1027 952 } 1028 953 1029 954 static ssize_t applesmc_key_at_index_show(struct device *dev, ··· 975 1020 static ssize_t applesmc_key_at_index_store(struct device *dev, 976 1021 struct device_attribute *attr, const char *sysfsbuf, size_t count) 977 1022 { 978 - mutex_lock(&applesmc_lock); 1023 + unsigned long newkey; 979 1024 980 - key_at_index = simple_strtoul(sysfsbuf, NULL, 10); 1025 + if (strict_strtoul(sysfsbuf, 10, &newkey) < 0 1026 + || newkey >= smcreg.key_count) 1027 + return -EINVAL; 981 1028 982 - mutex_unlock(&applesmc_lock); 983 - 1029 + key_at_index = newkey; 984 1030 return count; 985 1031 } 986 1032 ··· 991 1035 .brightness_set = applesmc_brightness_set, 992 1036 }; 993 1037 994 - static DEVICE_ATTR(name, 0444, applesmc_name_show, NULL); 995 - 996 - static DEVICE_ATTR(position, 0444, applesmc_position_show, NULL); 997 - static DEVICE_ATTR(calibrate, 0644, 998 - applesmc_calibrate_show, applesmc_calibrate_store); 999 - 1000 - static struct attribute *accelerometer_attributes[] = { 1001 - &dev_attr_position.attr, 1002 - &dev_attr_calibrate.attr, 1003 - NULL 1038 + static struct applesmc_node_group info_group[] = { 1039 + { "name", applesmc_name_show }, 1040 + { "key_count", applesmc_key_count_show }, 1041 + { "key_at_index", applesmc_key_at_index_show, applesmc_key_at_index_store }, 1042 + { "key_at_index_name", applesmc_key_at_index_name_show }, 1043 + { "key_at_index_type", applesmc_key_at_index_type_show }, 1044 + { "key_at_index_data_length", applesmc_key_at_index_data_length_show }, 1045 + { "key_at_index_data", applesmc_key_at_index_read_show }, 1046 + { } 1004 1047 }; 1005 1048 1006 - static const struct attribute_group accelerometer_attributes_group = 1007 - { .attrs = accelerometer_attributes }; 1008 - 1009 - static DEVICE_ATTR(light, 0444, applesmc_light_show, NULL); 1010 - 1011 - static DEVICE_ATTR(key_count, 0444, applesmc_key_count_show, NULL); 1012 - static DEVICE_ATTR(key_at_index, 0644, 1013 - applesmc_key_at_index_show, applesmc_key_at_index_store); 1014 - static DEVICE_ATTR(key_at_index_name, 0444, 1015 - applesmc_key_at_index_name_show, NULL); 1016 - static DEVICE_ATTR(key_at_index_type, 0444, 1017 - applesmc_key_at_index_type_show, NULL); 1018 - static DEVICE_ATTR(key_at_index_data_length, 0444, 1019 - applesmc_key_at_index_data_length_show, NULL); 1020 - static DEVICE_ATTR(key_at_index_data, 0444, 1021 - applesmc_key_at_index_read_show, NULL); 1022 - 1023 - static struct attribute *key_enumeration_attributes[] = { 1024 - &dev_attr_key_count.attr, 1025 - &dev_attr_key_at_index.attr, 1026 - &dev_attr_key_at_index_name.attr, 1027 - &dev_attr_key_at_index_type.attr, 1028 - &dev_attr_key_at_index_data_length.attr, 1029 - &dev_attr_key_at_index_data.attr, 1030 - NULL 1049 + static struct applesmc_node_group accelerometer_group[] = { 1050 + { "position", applesmc_position_show }, 1051 + { "calibrate", applesmc_calibrate_show, applesmc_calibrate_store }, 1052 + { } 1031 1053 }; 1032 1054 1033 - static const struct attribute_group key_enumeration_group = 1034 - { .attrs = key_enumeration_attributes }; 1035 - 1036 - /* 1037 - * Macro defining SENSOR_DEVICE_ATTR for a fan sysfs entries. 1038 - * - show actual speed 1039 - * - show/store minimum speed 1040 - * - show maximum speed 1041 - * - show safe speed 1042 - * - show/store target speed 1043 - * - show/store manual mode 1044 - */ 1045 - #define sysfs_fan_speeds_offset(offset) \ 1046 - static SENSOR_DEVICE_ATTR_2(fan##offset##_input, S_IRUGO, \ 1047 - applesmc_show_fan_speed, NULL, 0, offset-1); \ 1048 - \ 1049 - static SENSOR_DEVICE_ATTR_2(fan##offset##_min, S_IRUGO | S_IWUSR, \ 1050 - applesmc_show_fan_speed, applesmc_store_fan_speed, 1, offset-1); \ 1051 - \ 1052 - static SENSOR_DEVICE_ATTR_2(fan##offset##_max, S_IRUGO, \ 1053 - applesmc_show_fan_speed, NULL, 2, offset-1); \ 1054 - \ 1055 - static SENSOR_DEVICE_ATTR_2(fan##offset##_safe, S_IRUGO, \ 1056 - applesmc_show_fan_speed, NULL, 3, offset-1); \ 1057 - \ 1058 - static SENSOR_DEVICE_ATTR_2(fan##offset##_output, S_IRUGO | S_IWUSR, \ 1059 - applesmc_show_fan_speed, applesmc_store_fan_speed, 4, offset-1); \ 1060 - \ 1061 - static SENSOR_DEVICE_ATTR(fan##offset##_manual, S_IRUGO | S_IWUSR, \ 1062 - applesmc_show_fan_manual, applesmc_store_fan_manual, offset-1); \ 1063 - \ 1064 - static SENSOR_DEVICE_ATTR(fan##offset##_label, S_IRUGO, \ 1065 - applesmc_show_fan_position, NULL, offset-1); \ 1066 - \ 1067 - static struct attribute *fan##offset##_attributes[] = { \ 1068 - &sensor_dev_attr_fan##offset##_input.dev_attr.attr, \ 1069 - &sensor_dev_attr_fan##offset##_min.dev_attr.attr, \ 1070 - &sensor_dev_attr_fan##offset##_max.dev_attr.attr, \ 1071 - &sensor_dev_attr_fan##offset##_safe.dev_attr.attr, \ 1072 - &sensor_dev_attr_fan##offset##_output.dev_attr.attr, \ 1073 - &sensor_dev_attr_fan##offset##_manual.dev_attr.attr, \ 1074 - &sensor_dev_attr_fan##offset##_label.dev_attr.attr, \ 1075 - NULL \ 1055 + static struct applesmc_node_group light_sensor_group[] = { 1056 + { "light", applesmc_light_show }, 1057 + { } 1076 1058 }; 1077 1059 1078 - /* 1079 - * Create the needed functions for each fan using the macro defined above 1080 - * (4 fans are supported) 1081 - */ 1082 - sysfs_fan_speeds_offset(1); 1083 - sysfs_fan_speeds_offset(2); 1084 - sysfs_fan_speeds_offset(3); 1085 - sysfs_fan_speeds_offset(4); 1086 - 1087 - static const struct attribute_group fan_attribute_groups[] = { 1088 - { .attrs = fan1_attributes }, 1089 - { .attrs = fan2_attributes }, 1090 - { .attrs = fan3_attributes }, 1091 - { .attrs = fan4_attributes }, 1060 + static struct applesmc_node_group fan_group[] = { 1061 + { "fan%d_label", applesmc_show_fan_position }, 1062 + { "fan%d_input", applesmc_show_fan_speed, NULL, 0 }, 1063 + { "fan%d_min", applesmc_show_fan_speed, applesmc_store_fan_speed, 1 }, 1064 + { "fan%d_max", applesmc_show_fan_speed, NULL, 2 }, 1065 + { "fan%d_safe", applesmc_show_fan_speed, NULL, 3 }, 1066 + { "fan%d_output", applesmc_show_fan_speed, applesmc_store_fan_speed, 4 }, 1067 + { "fan%d_manual", applesmc_show_fan_manual, applesmc_store_fan_manual }, 1068 + { } 1092 1069 }; 1093 1070 1094 - /* 1095 - * Temperature sensors sysfs entries. 1096 - */ 1097 - static SENSOR_DEVICE_ATTR(temp1_label, S_IRUGO, 1098 - applesmc_show_sensor_label, NULL, 0); 1099 - static SENSOR_DEVICE_ATTR(temp2_label, S_IRUGO, 1100 - applesmc_show_sensor_label, NULL, 1); 1101 - static SENSOR_DEVICE_ATTR(temp3_label, S_IRUGO, 1102 - applesmc_show_sensor_label, NULL, 2); 1103 - static SENSOR_DEVICE_ATTR(temp4_label, S_IRUGO, 1104 - applesmc_show_sensor_label, NULL, 3); 1105 - static SENSOR_DEVICE_ATTR(temp5_label, S_IRUGO, 1106 - applesmc_show_sensor_label, NULL, 4); 1107 - static SENSOR_DEVICE_ATTR(temp6_label, S_IRUGO, 1108 - applesmc_show_sensor_label, NULL, 5); 1109 - static SENSOR_DEVICE_ATTR(temp7_label, S_IRUGO, 1110 - applesmc_show_sensor_label, NULL, 6); 1111 - static SENSOR_DEVICE_ATTR(temp8_label, S_IRUGO, 1112 - applesmc_show_sensor_label, NULL, 7); 1113 - static SENSOR_DEVICE_ATTR(temp9_label, S_IRUGO, 1114 - applesmc_show_sensor_label, NULL, 8); 1115 - static SENSOR_DEVICE_ATTR(temp10_label, S_IRUGO, 1116 - applesmc_show_sensor_label, NULL, 9); 1117 - static SENSOR_DEVICE_ATTR(temp11_label, S_IRUGO, 1118 - applesmc_show_sensor_label, NULL, 10); 1119 - static SENSOR_DEVICE_ATTR(temp12_label, S_IRUGO, 1120 - applesmc_show_sensor_label, NULL, 11); 1121 - static SENSOR_DEVICE_ATTR(temp13_label, S_IRUGO, 1122 - applesmc_show_sensor_label, NULL, 12); 1123 - static SENSOR_DEVICE_ATTR(temp14_label, S_IRUGO, 1124 - applesmc_show_sensor_label, NULL, 13); 1125 - static SENSOR_DEVICE_ATTR(temp15_label, S_IRUGO, 1126 - applesmc_show_sensor_label, NULL, 14); 1127 - static SENSOR_DEVICE_ATTR(temp16_label, S_IRUGO, 1128 - applesmc_show_sensor_label, NULL, 15); 1129 - static SENSOR_DEVICE_ATTR(temp17_label, S_IRUGO, 1130 - applesmc_show_sensor_label, NULL, 16); 1131 - static SENSOR_DEVICE_ATTR(temp18_label, S_IRUGO, 1132 - applesmc_show_sensor_label, NULL, 17); 1133 - static SENSOR_DEVICE_ATTR(temp19_label, S_IRUGO, 1134 - applesmc_show_sensor_label, NULL, 18); 1135 - static SENSOR_DEVICE_ATTR(temp20_label, S_IRUGO, 1136 - applesmc_show_sensor_label, NULL, 19); 1137 - static SENSOR_DEVICE_ATTR(temp21_label, S_IRUGO, 1138 - applesmc_show_sensor_label, NULL, 20); 1139 - static SENSOR_DEVICE_ATTR(temp22_label, S_IRUGO, 1140 - applesmc_show_sensor_label, NULL, 21); 1141 - static SENSOR_DEVICE_ATTR(temp23_label, S_IRUGO, 1142 - applesmc_show_sensor_label, NULL, 22); 1143 - static SENSOR_DEVICE_ATTR(temp24_label, S_IRUGO, 1144 - applesmc_show_sensor_label, NULL, 23); 1145 - static SENSOR_DEVICE_ATTR(temp25_label, S_IRUGO, 1146 - applesmc_show_sensor_label, NULL, 24); 1147 - static SENSOR_DEVICE_ATTR(temp26_label, S_IRUGO, 1148 - applesmc_show_sensor_label, NULL, 25); 1149 - static SENSOR_DEVICE_ATTR(temp27_label, S_IRUGO, 1150 - applesmc_show_sensor_label, NULL, 26); 1151 - static SENSOR_DEVICE_ATTR(temp28_label, S_IRUGO, 1152 - applesmc_show_sensor_label, NULL, 27); 1153 - static SENSOR_DEVICE_ATTR(temp29_label, S_IRUGO, 1154 - applesmc_show_sensor_label, NULL, 28); 1155 - static SENSOR_DEVICE_ATTR(temp30_label, S_IRUGO, 1156 - applesmc_show_sensor_label, NULL, 29); 1157 - static SENSOR_DEVICE_ATTR(temp31_label, S_IRUGO, 1158 - applesmc_show_sensor_label, NULL, 30); 1159 - static SENSOR_DEVICE_ATTR(temp32_label, S_IRUGO, 1160 - applesmc_show_sensor_label, NULL, 31); 1161 - static SENSOR_DEVICE_ATTR(temp33_label, S_IRUGO, 1162 - applesmc_show_sensor_label, NULL, 32); 1163 - static SENSOR_DEVICE_ATTR(temp34_label, S_IRUGO, 1164 - applesmc_show_sensor_label, NULL, 33); 1165 - static SENSOR_DEVICE_ATTR(temp35_label, S_IRUGO, 1166 - applesmc_show_sensor_label, NULL, 34); 1167 - static SENSOR_DEVICE_ATTR(temp36_label, S_IRUGO, 1168 - applesmc_show_sensor_label, NULL, 35); 1169 - static SENSOR_DEVICE_ATTR(temp37_label, S_IRUGO, 1170 - applesmc_show_sensor_label, NULL, 36); 1171 - static SENSOR_DEVICE_ATTR(temp38_label, S_IRUGO, 1172 - applesmc_show_sensor_label, NULL, 37); 1173 - static SENSOR_DEVICE_ATTR(temp39_label, S_IRUGO, 1174 - applesmc_show_sensor_label, NULL, 38); 1175 - static SENSOR_DEVICE_ATTR(temp40_label, S_IRUGO, 1176 - applesmc_show_sensor_label, NULL, 39); 1177 - static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, 1178 - applesmc_show_temperature, NULL, 0); 1179 - static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, 1180 - applesmc_show_temperature, NULL, 1); 1181 - static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO, 1182 - applesmc_show_temperature, NULL, 2); 1183 - static SENSOR_DEVICE_ATTR(temp4_input, S_IRUGO, 1184 - applesmc_show_temperature, NULL, 3); 1185 - static SENSOR_DEVICE_ATTR(temp5_input, S_IRUGO, 1186 - applesmc_show_temperature, NULL, 4); 1187 - static SENSOR_DEVICE_ATTR(temp6_input, S_IRUGO, 1188 - applesmc_show_temperature, NULL, 5); 1189 - static SENSOR_DEVICE_ATTR(temp7_input, S_IRUGO, 1190 - applesmc_show_temperature, NULL, 6); 1191 - static SENSOR_DEVICE_ATTR(temp8_input, S_IRUGO, 1192 - applesmc_show_temperature, NULL, 7); 1193 - static SENSOR_DEVICE_ATTR(temp9_input, S_IRUGO, 1194 - applesmc_show_temperature, NULL, 8); 1195 - static SENSOR_DEVICE_ATTR(temp10_input, S_IRUGO, 1196 - applesmc_show_temperature, NULL, 9); 1197 - static SENSOR_DEVICE_ATTR(temp11_input, S_IRUGO, 1198 - applesmc_show_temperature, NULL, 10); 1199 - static SENSOR_DEVICE_ATTR(temp12_input, S_IRUGO, 1200 - applesmc_show_temperature, NULL, 11); 1201 - static SENSOR_DEVICE_ATTR(temp13_input, S_IRUGO, 1202 - applesmc_show_temperature, NULL, 12); 1203 - static SENSOR_DEVICE_ATTR(temp14_input, S_IRUGO, 1204 - applesmc_show_temperature, NULL, 13); 1205 - static SENSOR_DEVICE_ATTR(temp15_input, S_IRUGO, 1206 - applesmc_show_temperature, NULL, 14); 1207 - static SENSOR_DEVICE_ATTR(temp16_input, S_IRUGO, 1208 - applesmc_show_temperature, NULL, 15); 1209 - static SENSOR_DEVICE_ATTR(temp17_input, S_IRUGO, 1210 - applesmc_show_temperature, NULL, 16); 1211 - static SENSOR_DEVICE_ATTR(temp18_input, S_IRUGO, 1212 - applesmc_show_temperature, NULL, 17); 1213 - static SENSOR_DEVICE_ATTR(temp19_input, S_IRUGO, 1214 - applesmc_show_temperature, NULL, 18); 1215 - static SENSOR_DEVICE_ATTR(temp20_input, S_IRUGO, 1216 - applesmc_show_temperature, NULL, 19); 1217 - static SENSOR_DEVICE_ATTR(temp21_input, S_IRUGO, 1218 - applesmc_show_temperature, NULL, 20); 1219 - static SENSOR_DEVICE_ATTR(temp22_input, S_IRUGO, 1220 - applesmc_show_temperature, NULL, 21); 1221 - static SENSOR_DEVICE_ATTR(temp23_input, S_IRUGO, 1222 - applesmc_show_temperature, NULL, 22); 1223 - static SENSOR_DEVICE_ATTR(temp24_input, S_IRUGO, 1224 - applesmc_show_temperature, NULL, 23); 1225 - static SENSOR_DEVICE_ATTR(temp25_input, S_IRUGO, 1226 - applesmc_show_temperature, NULL, 24); 1227 - static SENSOR_DEVICE_ATTR(temp26_input, S_IRUGO, 1228 - applesmc_show_temperature, NULL, 25); 1229 - static SENSOR_DEVICE_ATTR(temp27_input, S_IRUGO, 1230 - applesmc_show_temperature, NULL, 26); 1231 - static SENSOR_DEVICE_ATTR(temp28_input, S_IRUGO, 1232 - applesmc_show_temperature, NULL, 27); 1233 - static SENSOR_DEVICE_ATTR(temp29_input, S_IRUGO, 1234 - applesmc_show_temperature, NULL, 28); 1235 - static SENSOR_DEVICE_ATTR(temp30_input, S_IRUGO, 1236 - applesmc_show_temperature, NULL, 29); 1237 - static SENSOR_DEVICE_ATTR(temp31_input, S_IRUGO, 1238 - applesmc_show_temperature, NULL, 30); 1239 - static SENSOR_DEVICE_ATTR(temp32_input, S_IRUGO, 1240 - applesmc_show_temperature, NULL, 31); 1241 - static SENSOR_DEVICE_ATTR(temp33_input, S_IRUGO, 1242 - applesmc_show_temperature, NULL, 32); 1243 - static SENSOR_DEVICE_ATTR(temp34_input, S_IRUGO, 1244 - applesmc_show_temperature, NULL, 33); 1245 - static SENSOR_DEVICE_ATTR(temp35_input, S_IRUGO, 1246 - applesmc_show_temperature, NULL, 34); 1247 - static SENSOR_DEVICE_ATTR(temp36_input, S_IRUGO, 1248 - applesmc_show_temperature, NULL, 35); 1249 - static SENSOR_DEVICE_ATTR(temp37_input, S_IRUGO, 1250 - applesmc_show_temperature, NULL, 36); 1251 - static SENSOR_DEVICE_ATTR(temp38_input, S_IRUGO, 1252 - applesmc_show_temperature, NULL, 37); 1253 - static SENSOR_DEVICE_ATTR(temp39_input, S_IRUGO, 1254 - applesmc_show_temperature, NULL, 38); 1255 - static SENSOR_DEVICE_ATTR(temp40_input, S_IRUGO, 1256 - applesmc_show_temperature, NULL, 39); 1257 - 1258 - static struct attribute *label_attributes[] = { 1259 - &sensor_dev_attr_temp1_label.dev_attr.attr, 1260 - &sensor_dev_attr_temp2_label.dev_attr.attr, 1261 - &sensor_dev_attr_temp3_label.dev_attr.attr, 1262 - &sensor_dev_attr_temp4_label.dev_attr.attr, 1263 - &sensor_dev_attr_temp5_label.dev_attr.attr, 1264 - &sensor_dev_attr_temp6_label.dev_attr.attr, 1265 - &sensor_dev_attr_temp7_label.dev_attr.attr, 1266 - &sensor_dev_attr_temp8_label.dev_attr.attr, 1267 - &sensor_dev_attr_temp9_label.dev_attr.attr, 1268 - &sensor_dev_attr_temp10_label.dev_attr.attr, 1269 - &sensor_dev_attr_temp11_label.dev_attr.attr, 1270 - &sensor_dev_attr_temp12_label.dev_attr.attr, 1271 - &sensor_dev_attr_temp13_label.dev_attr.attr, 1272 - &sensor_dev_attr_temp14_label.dev_attr.attr, 1273 - &sensor_dev_attr_temp15_label.dev_attr.attr, 1274 - &sensor_dev_attr_temp16_label.dev_attr.attr, 1275 - &sensor_dev_attr_temp17_label.dev_attr.attr, 1276 - &sensor_dev_attr_temp18_label.dev_attr.attr, 1277 - &sensor_dev_attr_temp19_label.dev_attr.attr, 1278 - &sensor_dev_attr_temp20_label.dev_attr.attr, 1279 - &sensor_dev_attr_temp21_label.dev_attr.attr, 1280 - &sensor_dev_attr_temp22_label.dev_attr.attr, 1281 - &sensor_dev_attr_temp23_label.dev_attr.attr, 1282 - &sensor_dev_attr_temp24_label.dev_attr.attr, 1283 - &sensor_dev_attr_temp25_label.dev_attr.attr, 1284 - &sensor_dev_attr_temp26_label.dev_attr.attr, 1285 - &sensor_dev_attr_temp27_label.dev_attr.attr, 1286 - &sensor_dev_attr_temp28_label.dev_attr.attr, 1287 - &sensor_dev_attr_temp29_label.dev_attr.attr, 1288 - &sensor_dev_attr_temp30_label.dev_attr.attr, 1289 - &sensor_dev_attr_temp31_label.dev_attr.attr, 1290 - &sensor_dev_attr_temp32_label.dev_attr.attr, 1291 - &sensor_dev_attr_temp33_label.dev_attr.attr, 1292 - &sensor_dev_attr_temp34_label.dev_attr.attr, 1293 - &sensor_dev_attr_temp35_label.dev_attr.attr, 1294 - &sensor_dev_attr_temp36_label.dev_attr.attr, 1295 - &sensor_dev_attr_temp37_label.dev_attr.attr, 1296 - &sensor_dev_attr_temp38_label.dev_attr.attr, 1297 - &sensor_dev_attr_temp39_label.dev_attr.attr, 1298 - &sensor_dev_attr_temp40_label.dev_attr.attr, 1299 - NULL 1300 - }; 1301 - 1302 - static struct attribute *temperature_attributes[] = { 1303 - &sensor_dev_attr_temp1_input.dev_attr.attr, 1304 - &sensor_dev_attr_temp2_input.dev_attr.attr, 1305 - &sensor_dev_attr_temp3_input.dev_attr.attr, 1306 - &sensor_dev_attr_temp4_input.dev_attr.attr, 1307 - &sensor_dev_attr_temp5_input.dev_attr.attr, 1308 - &sensor_dev_attr_temp6_input.dev_attr.attr, 1309 - &sensor_dev_attr_temp7_input.dev_attr.attr, 1310 - &sensor_dev_attr_temp8_input.dev_attr.attr, 1311 - &sensor_dev_attr_temp9_input.dev_attr.attr, 1312 - &sensor_dev_attr_temp10_input.dev_attr.attr, 1313 - &sensor_dev_attr_temp11_input.dev_attr.attr, 1314 - &sensor_dev_attr_temp12_input.dev_attr.attr, 1315 - &sensor_dev_attr_temp13_input.dev_attr.attr, 1316 - &sensor_dev_attr_temp14_input.dev_attr.attr, 1317 - &sensor_dev_attr_temp15_input.dev_attr.attr, 1318 - &sensor_dev_attr_temp16_input.dev_attr.attr, 1319 - &sensor_dev_attr_temp17_input.dev_attr.attr, 1320 - &sensor_dev_attr_temp18_input.dev_attr.attr, 1321 - &sensor_dev_attr_temp19_input.dev_attr.attr, 1322 - &sensor_dev_attr_temp20_input.dev_attr.attr, 1323 - &sensor_dev_attr_temp21_input.dev_attr.attr, 1324 - &sensor_dev_attr_temp22_input.dev_attr.attr, 1325 - &sensor_dev_attr_temp23_input.dev_attr.attr, 1326 - &sensor_dev_attr_temp24_input.dev_attr.attr, 1327 - &sensor_dev_attr_temp25_input.dev_attr.attr, 1328 - &sensor_dev_attr_temp26_input.dev_attr.attr, 1329 - &sensor_dev_attr_temp27_input.dev_attr.attr, 1330 - &sensor_dev_attr_temp28_input.dev_attr.attr, 1331 - &sensor_dev_attr_temp29_input.dev_attr.attr, 1332 - &sensor_dev_attr_temp30_input.dev_attr.attr, 1333 - &sensor_dev_attr_temp31_input.dev_attr.attr, 1334 - &sensor_dev_attr_temp32_input.dev_attr.attr, 1335 - &sensor_dev_attr_temp33_input.dev_attr.attr, 1336 - &sensor_dev_attr_temp34_input.dev_attr.attr, 1337 - &sensor_dev_attr_temp35_input.dev_attr.attr, 1338 - &sensor_dev_attr_temp36_input.dev_attr.attr, 1339 - &sensor_dev_attr_temp37_input.dev_attr.attr, 1340 - &sensor_dev_attr_temp38_input.dev_attr.attr, 1341 - &sensor_dev_attr_temp39_input.dev_attr.attr, 1342 - &sensor_dev_attr_temp40_input.dev_attr.attr, 1343 - NULL 1344 - }; 1345 - 1346 - static const struct attribute_group temperature_attributes_group = 1347 - { .attrs = temperature_attributes }; 1348 - 1349 - static const struct attribute_group label_attributes_group = { 1350 - .attrs = label_attributes 1071 + static struct applesmc_node_group temp_group[] = { 1072 + { "temp%d_label", applesmc_show_sensor_label }, 1073 + { "temp%d_input", applesmc_show_temperature }, 1074 + { } 1351 1075 }; 1352 1076 1353 1077 /* Module stuff */ 1354 1078 1355 1079 /* 1356 - * applesmc_dmi_match - found a match. return one, short-circuiting the hunt. 1080 + * applesmc_destroy_nodes - remove files and free associated memory 1357 1081 */ 1358 - static int applesmc_dmi_match(const struct dmi_system_id *id) 1082 + static void applesmc_destroy_nodes(struct applesmc_node_group *groups) 1359 1083 { 1360 - int i = 0; 1361 - struct dmi_match_data* dmi_data = id->driver_data; 1362 - printk(KERN_INFO "applesmc: %s detected:\n", id->ident); 1363 - applesmc_accelerometer = dmi_data->accelerometer; 1364 - printk(KERN_INFO "applesmc: - Model %s accelerometer\n", 1365 - applesmc_accelerometer ? "with" : "without"); 1366 - applesmc_light = dmi_data->light; 1367 - printk(KERN_INFO "applesmc: - Model %s light sensors and backlight\n", 1368 - applesmc_light ? "with" : "without"); 1084 + struct applesmc_node_group *grp; 1085 + struct applesmc_dev_attr *node; 1369 1086 1370 - applesmc_temperature_set = dmi_data->temperature_set; 1371 - while (temperature_sensors_sets[applesmc_temperature_set][i] != NULL) 1372 - i++; 1373 - printk(KERN_INFO "applesmc: - Model with %d temperature sensors\n", i); 1374 - return 1; 1087 + for (grp = groups; grp->nodes; grp++) { 1088 + for (node = grp->nodes; node->sda.dev_attr.attr.name; node++) 1089 + sysfs_remove_file(&pdev->dev.kobj, 1090 + &node->sda.dev_attr.attr); 1091 + kfree(grp->nodes); 1092 + grp->nodes = NULL; 1093 + } 1094 + } 1095 + 1096 + /* 1097 + * applesmc_create_nodes - create a two-dimensional group of sysfs files 1098 + */ 1099 + static int applesmc_create_nodes(struct applesmc_node_group *groups, int num) 1100 + { 1101 + struct applesmc_node_group *grp; 1102 + struct applesmc_dev_attr *node; 1103 + struct attribute *attr; 1104 + int ret, i; 1105 + 1106 + for (grp = groups; grp->format; grp++) { 1107 + grp->nodes = kcalloc(num + 1, sizeof(*node), GFP_KERNEL); 1108 + if (!grp->nodes) { 1109 + ret = -ENOMEM; 1110 + goto out; 1111 + } 1112 + for (i = 0; i < num; i++) { 1113 + node = &grp->nodes[i]; 1114 + sprintf(node->name, grp->format, i + 1); 1115 + node->sda.index = (grp->option << 16) | (i & 0xffff); 1116 + node->sda.dev_attr.show = grp->show; 1117 + node->sda.dev_attr.store = grp->store; 1118 + attr = &node->sda.dev_attr.attr; 1119 + attr->name = node->name; 1120 + attr->mode = S_IRUGO | (grp->store ? S_IWUSR : 0); 1121 + ret = sysfs_create_file(&pdev->dev.kobj, attr); 1122 + if (ret) { 1123 + attr->name = NULL; 1124 + goto out; 1125 + } 1126 + } 1127 + } 1128 + 1129 + return 0; 1130 + out: 1131 + applesmc_destroy_nodes(groups); 1132 + return ret; 1375 1133 } 1376 1134 1377 1135 /* Create accelerometer ressources */ ··· 1094 1424 struct input_dev *idev; 1095 1425 int ret; 1096 1426 1097 - ret = sysfs_create_group(&pdev->dev.kobj, 1098 - &accelerometer_attributes_group); 1427 + if (!smcreg.has_accelerometer) 1428 + return 0; 1429 + 1430 + ret = applesmc_create_nodes(accelerometer_group, 1); 1099 1431 if (ret) 1100 1432 goto out; 1101 1433 ··· 1134 1462 input_free_polled_device(applesmc_idev); 1135 1463 1136 1464 out_sysfs: 1137 - sysfs_remove_group(&pdev->dev.kobj, &accelerometer_attributes_group); 1465 + applesmc_destroy_nodes(accelerometer_group); 1138 1466 1139 1467 out: 1140 - printk(KERN_WARNING "applesmc: driver init failed (ret=%d)!\n", ret); 1468 + pr_warn("driver init failed (ret=%d)!\n", ret); 1141 1469 return ret; 1142 1470 } 1143 1471 1144 1472 /* Release all ressources used by the accelerometer */ 1145 1473 static void applesmc_release_accelerometer(void) 1146 1474 { 1475 + if (!smcreg.has_accelerometer) 1476 + return; 1147 1477 input_unregister_polled_device(applesmc_idev); 1148 1478 input_free_polled_device(applesmc_idev); 1149 - sysfs_remove_group(&pdev->dev.kobj, &accelerometer_attributes_group); 1479 + applesmc_destroy_nodes(accelerometer_group); 1150 1480 } 1151 1481 1152 - static __initdata struct dmi_match_data applesmc_dmi_data[] = { 1153 - /* MacBook Pro: accelerometer, backlight and temperature set 0 */ 1154 - { .accelerometer = 1, .light = 1, .temperature_set = 0 }, 1155 - /* MacBook2: accelerometer and temperature set 1 */ 1156 - { .accelerometer = 1, .light = 0, .temperature_set = 1 }, 1157 - /* MacBook: accelerometer and temperature set 2 */ 1158 - { .accelerometer = 1, .light = 0, .temperature_set = 2 }, 1159 - /* MacMini: temperature set 3 */ 1160 - { .accelerometer = 0, .light = 0, .temperature_set = 3 }, 1161 - /* MacPro: temperature set 4 */ 1162 - { .accelerometer = 0, .light = 0, .temperature_set = 4 }, 1163 - /* iMac: temperature set 5 */ 1164 - { .accelerometer = 0, .light = 0, .temperature_set = 5 }, 1165 - /* MacBook3, MacBook4: accelerometer and temperature set 6 */ 1166 - { .accelerometer = 1, .light = 0, .temperature_set = 6 }, 1167 - /* MacBook Air: accelerometer, backlight and temperature set 7 */ 1168 - { .accelerometer = 1, .light = 1, .temperature_set = 7 }, 1169 - /* MacBook Pro 4: accelerometer, backlight and temperature set 8 */ 1170 - { .accelerometer = 1, .light = 1, .temperature_set = 8 }, 1171 - /* MacBook Pro 3: accelerometer, backlight and temperature set 9 */ 1172 - { .accelerometer = 1, .light = 1, .temperature_set = 9 }, 1173 - /* iMac 5: light sensor only, temperature set 10 */ 1174 - { .accelerometer = 0, .light = 0, .temperature_set = 10 }, 1175 - /* MacBook 5: accelerometer, backlight and temperature set 11 */ 1176 - { .accelerometer = 1, .light = 1, .temperature_set = 11 }, 1177 - /* MacBook Pro 5: accelerometer, backlight and temperature set 12 */ 1178 - { .accelerometer = 1, .light = 1, .temperature_set = 12 }, 1179 - /* iMac 8: light sensor only, temperature set 13 */ 1180 - { .accelerometer = 0, .light = 0, .temperature_set = 13 }, 1181 - /* iMac 6: light sensor only, temperature set 14 */ 1182 - { .accelerometer = 0, .light = 0, .temperature_set = 14 }, 1183 - /* MacBook Air 2,1: accelerometer, backlight and temperature set 15 */ 1184 - { .accelerometer = 1, .light = 1, .temperature_set = 15 }, 1185 - /* MacPro3,1: temperature set 16 */ 1186 - { .accelerometer = 0, .light = 0, .temperature_set = 16 }, 1187 - /* iMac 9,1: light sensor only, temperature set 17 */ 1188 - { .accelerometer = 0, .light = 0, .temperature_set = 17 }, 1189 - /* MacBook Pro 2,2: accelerometer, backlight and temperature set 18 */ 1190 - { .accelerometer = 1, .light = 1, .temperature_set = 18 }, 1191 - /* MacBook Pro 5,3: accelerometer, backlight and temperature set 19 */ 1192 - { .accelerometer = 1, .light = 1, .temperature_set = 19 }, 1193 - /* MacBook Pro 5,4: accelerometer, backlight and temperature set 20 */ 1194 - { .accelerometer = 1, .light = 1, .temperature_set = 20 }, 1195 - /* MacBook Pro 6,2: accelerometer, backlight and temperature set 21 */ 1196 - { .accelerometer = 1, .light = 1, .temperature_set = 21 }, 1197 - /* MacBook Pro 7,1: accelerometer, backlight and temperature set 22 */ 1198 - { .accelerometer = 1, .light = 1, .temperature_set = 22 }, 1199 - }; 1482 + static int applesmc_create_light_sensor(void) 1483 + { 1484 + if (!smcreg.num_light_sensors) 1485 + return 0; 1486 + return applesmc_create_nodes(light_sensor_group, 1); 1487 + } 1488 + 1489 + static void applesmc_release_light_sensor(void) 1490 + { 1491 + if (!smcreg.num_light_sensors) 1492 + return; 1493 + applesmc_destroy_nodes(light_sensor_group); 1494 + } 1495 + 1496 + static int applesmc_create_key_backlight(void) 1497 + { 1498 + if (!smcreg.has_key_backlight) 1499 + return 0; 1500 + applesmc_led_wq = create_singlethread_workqueue("applesmc-led"); 1501 + if (!applesmc_led_wq) 1502 + return -ENOMEM; 1503 + return led_classdev_register(&pdev->dev, &applesmc_backlight); 1504 + } 1505 + 1506 + static void applesmc_release_key_backlight(void) 1507 + { 1508 + if (!smcreg.has_key_backlight) 1509 + return; 1510 + led_classdev_unregister(&applesmc_backlight); 1511 + destroy_workqueue(applesmc_led_wq); 1512 + } 1513 + 1514 + static int applesmc_dmi_match(const struct dmi_system_id *id) 1515 + { 1516 + return 1; 1517 + } 1200 1518 1201 1519 /* Note that DMI_MATCH(...,"MacBook") will match "MacBookPro1,1". 1202 1520 * So we need to put "Apple MacBook Pro" before "Apple MacBook". */ 1203 1521 static __initdata struct dmi_system_id applesmc_whitelist[] = { 1204 - { applesmc_dmi_match, "Apple MacBook Air 2", { 1205 - DMI_MATCH(DMI_BOARD_VENDOR, "Apple"), 1206 - DMI_MATCH(DMI_PRODUCT_NAME, "MacBookAir2") }, 1207 - &applesmc_dmi_data[15]}, 1208 1522 { applesmc_dmi_match, "Apple MacBook Air", { 1209 1523 DMI_MATCH(DMI_BOARD_VENDOR, "Apple"), 1210 1524 DMI_MATCH(DMI_PRODUCT_NAME, "MacBookAir") }, 1211 - &applesmc_dmi_data[7]}, 1212 - { applesmc_dmi_match, "Apple MacBook Pro 7", { 1213 - DMI_MATCH(DMI_BOARD_VENDOR, "Apple"), 1214 - DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro7") }, 1215 - &applesmc_dmi_data[22]}, 1216 - { applesmc_dmi_match, "Apple MacBook Pro 5,4", { 1217 - DMI_MATCH(DMI_BOARD_VENDOR, "Apple"), 1218 - DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro5,4") }, 1219 - &applesmc_dmi_data[20]}, 1220 - { applesmc_dmi_match, "Apple MacBook Pro 5,3", { 1221 - DMI_MATCH(DMI_BOARD_VENDOR, "Apple"), 1222 - DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro5,3") }, 1223 - &applesmc_dmi_data[19]}, 1224 - { applesmc_dmi_match, "Apple MacBook Pro 6", { 1225 - DMI_MATCH(DMI_BOARD_VENDOR, "Apple"), 1226 - DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro6") }, 1227 - &applesmc_dmi_data[21]}, 1228 - { applesmc_dmi_match, "Apple MacBook Pro 5", { 1229 - DMI_MATCH(DMI_BOARD_VENDOR, "Apple"), 1230 - DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro5") }, 1231 - &applesmc_dmi_data[12]}, 1232 - { applesmc_dmi_match, "Apple MacBook Pro 4", { 1233 - DMI_MATCH(DMI_BOARD_VENDOR, "Apple"), 1234 - DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro4") }, 1235 - &applesmc_dmi_data[8]}, 1236 - { applesmc_dmi_match, "Apple MacBook Pro 3", { 1237 - DMI_MATCH(DMI_BOARD_VENDOR, "Apple"), 1238 - DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro3") }, 1239 - &applesmc_dmi_data[9]}, 1240 - { applesmc_dmi_match, "Apple MacBook Pro 2,2", { 1241 - DMI_MATCH(DMI_BOARD_VENDOR, "Apple Computer, Inc."), 1242 - DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro2,2") }, 1243 - &applesmc_dmi_data[18]}, 1525 + }, 1244 1526 { applesmc_dmi_match, "Apple MacBook Pro", { 1245 - DMI_MATCH(DMI_BOARD_VENDOR,"Apple"), 1246 - DMI_MATCH(DMI_PRODUCT_NAME,"MacBookPro") }, 1247 - &applesmc_dmi_data[0]}, 1248 - { applesmc_dmi_match, "Apple MacBook (v2)", { 1249 - DMI_MATCH(DMI_BOARD_VENDOR,"Apple"), 1250 - DMI_MATCH(DMI_PRODUCT_NAME,"MacBook2") }, 1251 - &applesmc_dmi_data[1]}, 1252 - { applesmc_dmi_match, "Apple MacBook (v3)", { 1253 - DMI_MATCH(DMI_BOARD_VENDOR,"Apple"), 1254 - DMI_MATCH(DMI_PRODUCT_NAME,"MacBook3") }, 1255 - &applesmc_dmi_data[6]}, 1256 - { applesmc_dmi_match, "Apple MacBook 4", { 1257 1527 DMI_MATCH(DMI_BOARD_VENDOR, "Apple"), 1258 - DMI_MATCH(DMI_PRODUCT_NAME, "MacBook4") }, 1259 - &applesmc_dmi_data[6]}, 1260 - { applesmc_dmi_match, "Apple MacBook 5", { 1261 - DMI_MATCH(DMI_BOARD_VENDOR, "Apple"), 1262 - DMI_MATCH(DMI_PRODUCT_NAME, "MacBook5") }, 1263 - &applesmc_dmi_data[11]}, 1528 + DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro") }, 1529 + }, 1264 1530 { applesmc_dmi_match, "Apple MacBook", { 1265 - DMI_MATCH(DMI_BOARD_VENDOR,"Apple"), 1266 - DMI_MATCH(DMI_PRODUCT_NAME,"MacBook") }, 1267 - &applesmc_dmi_data[2]}, 1268 - { applesmc_dmi_match, "Apple Macmini", { 1269 - DMI_MATCH(DMI_BOARD_VENDOR,"Apple"), 1270 - DMI_MATCH(DMI_PRODUCT_NAME,"Macmini") }, 1271 - &applesmc_dmi_data[3]}, 1272 - { applesmc_dmi_match, "Apple MacPro2", { 1273 - DMI_MATCH(DMI_BOARD_VENDOR,"Apple"), 1274 - DMI_MATCH(DMI_PRODUCT_NAME,"MacPro2") }, 1275 - &applesmc_dmi_data[4]}, 1276 - { applesmc_dmi_match, "Apple MacPro3", { 1277 1531 DMI_MATCH(DMI_BOARD_VENDOR, "Apple"), 1278 - DMI_MATCH(DMI_PRODUCT_NAME, "MacPro3") }, 1279 - &applesmc_dmi_data[16]}, 1532 + DMI_MATCH(DMI_PRODUCT_NAME, "MacBook") }, 1533 + }, 1534 + { applesmc_dmi_match, "Apple Macmini", { 1535 + DMI_MATCH(DMI_BOARD_VENDOR, "Apple"), 1536 + DMI_MATCH(DMI_PRODUCT_NAME, "Macmini") }, 1537 + }, 1280 1538 { applesmc_dmi_match, "Apple MacPro", { 1281 1539 DMI_MATCH(DMI_BOARD_VENDOR, "Apple"), 1282 1540 DMI_MATCH(DMI_PRODUCT_NAME, "MacPro") }, 1283 - &applesmc_dmi_data[4]}, 1284 - { applesmc_dmi_match, "Apple iMac 9,1", { 1285 - DMI_MATCH(DMI_BOARD_VENDOR, "Apple Inc."), 1286 - DMI_MATCH(DMI_PRODUCT_NAME, "iMac9,1") }, 1287 - &applesmc_dmi_data[17]}, 1288 - { applesmc_dmi_match, "Apple iMac 8", { 1289 - DMI_MATCH(DMI_BOARD_VENDOR, "Apple"), 1290 - DMI_MATCH(DMI_PRODUCT_NAME, "iMac8") }, 1291 - &applesmc_dmi_data[13]}, 1292 - { applesmc_dmi_match, "Apple iMac 6", { 1293 - DMI_MATCH(DMI_BOARD_VENDOR, "Apple"), 1294 - DMI_MATCH(DMI_PRODUCT_NAME, "iMac6") }, 1295 - &applesmc_dmi_data[14]}, 1296 - { applesmc_dmi_match, "Apple iMac 5", { 1297 - DMI_MATCH(DMI_BOARD_VENDOR, "Apple"), 1298 - DMI_MATCH(DMI_PRODUCT_NAME, "iMac5") }, 1299 - &applesmc_dmi_data[10]}, 1541 + }, 1300 1542 { applesmc_dmi_match, "Apple iMac", { 1301 - DMI_MATCH(DMI_BOARD_VENDOR,"Apple"), 1302 - DMI_MATCH(DMI_PRODUCT_NAME,"iMac") }, 1303 - &applesmc_dmi_data[5]}, 1543 + DMI_MATCH(DMI_BOARD_VENDOR, "Apple"), 1544 + DMI_MATCH(DMI_PRODUCT_NAME, "iMac") }, 1545 + }, 1304 1546 { .ident = NULL } 1305 1547 }; 1306 1548 1307 1549 static int __init applesmc_init(void) 1308 1550 { 1309 1551 int ret; 1310 - int count; 1311 - int i; 1312 1552 1313 1553 if (!dmi_check_system(applesmc_whitelist)) { 1314 - printk(KERN_WARNING "applesmc: supported laptop not found!\n"); 1554 + pr_warn("supported laptop not found!\n"); 1315 1555 ret = -ENODEV; 1316 1556 goto out; 1317 1557 } ··· 1245 1661 goto out_driver; 1246 1662 } 1247 1663 1248 - ret = sysfs_create_file(&pdev->dev.kobj, &dev_attr_name.attr); 1664 + /* create register cache */ 1665 + ret = applesmc_init_smcreg(); 1249 1666 if (ret) 1250 1667 goto out_device; 1251 1668 1252 - /* Create key enumeration sysfs files */ 1253 - ret = sysfs_create_group(&pdev->dev.kobj, &key_enumeration_group); 1669 + ret = applesmc_create_nodes(info_group, 1); 1254 1670 if (ret) 1255 - goto out_name; 1671 + goto out_smcreg; 1256 1672 1257 - /* create fan files */ 1258 - count = applesmc_get_fan_count(); 1259 - if (count < 0) 1260 - printk(KERN_ERR "applesmc: Cannot get the number of fans.\n"); 1261 - else 1262 - printk(KERN_INFO "applesmc: %d fans found.\n", count); 1673 + ret = applesmc_create_nodes(fan_group, smcreg.fan_count); 1674 + if (ret) 1675 + goto out_info; 1263 1676 1264 - if (count > 4) { 1265 - count = 4; 1266 - printk(KERN_WARNING "applesmc: More than 4 fans found," 1267 - " but at most 4 fans are supported" 1268 - " by the driver.\n"); 1269 - } 1677 + ret = applesmc_create_nodes(temp_group, smcreg.temp_count); 1678 + if (ret) 1679 + goto out_fans; 1270 1680 1271 - while (fans_handled < count) { 1272 - ret = sysfs_create_group(&pdev->dev.kobj, 1273 - &fan_attribute_groups[fans_handled]); 1274 - if (ret) 1275 - goto out_fans; 1276 - fans_handled++; 1277 - } 1681 + ret = applesmc_create_accelerometer(); 1682 + if (ret) 1683 + goto out_temperature; 1278 1684 1279 - for (i = 0; 1280 - temperature_sensors_sets[applesmc_temperature_set][i] != NULL; 1281 - i++) { 1282 - if (temperature_attributes[i] == NULL || 1283 - label_attributes[i] == NULL) { 1284 - printk(KERN_ERR "applesmc: More temperature sensors " 1285 - "in temperature_sensors_sets (at least %i)" 1286 - "than available sysfs files in " 1287 - "temperature_attributes (%i), please report " 1288 - "this bug.\n", i, i-1); 1289 - goto out_temperature; 1290 - } 1291 - ret = sysfs_create_file(&pdev->dev.kobj, 1292 - temperature_attributes[i]); 1293 - if (ret) 1294 - goto out_temperature; 1295 - ret = sysfs_create_file(&pdev->dev.kobj, 1296 - label_attributes[i]); 1297 - if (ret) 1298 - goto out_temperature; 1299 - } 1685 + ret = applesmc_create_light_sensor(); 1686 + if (ret) 1687 + goto out_accelerometer; 1300 1688 1301 - if (applesmc_accelerometer) { 1302 - ret = applesmc_create_accelerometer(); 1303 - if (ret) 1304 - goto out_temperature; 1305 - } 1306 - 1307 - if (applesmc_light) { 1308 - /* Add light sensor file */ 1309 - ret = sysfs_create_file(&pdev->dev.kobj, &dev_attr_light.attr); 1310 - if (ret) 1311 - goto out_accelerometer; 1312 - 1313 - /* Create the workqueue */ 1314 - applesmc_led_wq = create_singlethread_workqueue("applesmc-led"); 1315 - if (!applesmc_led_wq) { 1316 - ret = -ENOMEM; 1317 - goto out_light_sysfs; 1318 - } 1319 - 1320 - /* register as a led device */ 1321 - ret = led_classdev_register(&pdev->dev, &applesmc_backlight); 1322 - if (ret < 0) 1323 - goto out_light_wq; 1324 - } 1689 + ret = applesmc_create_key_backlight(); 1690 + if (ret) 1691 + goto out_light_sysfs; 1325 1692 1326 1693 hwmon_dev = hwmon_device_register(&pdev->dev); 1327 1694 if (IS_ERR(hwmon_dev)) { ··· 1280 1745 goto out_light_ledclass; 1281 1746 } 1282 1747 1283 - printk(KERN_INFO "applesmc: driver successfully loaded.\n"); 1284 - 1285 1748 return 0; 1286 1749 1287 1750 out_light_ledclass: 1288 - if (applesmc_light) 1289 - led_classdev_unregister(&applesmc_backlight); 1290 - out_light_wq: 1291 - if (applesmc_light) 1292 - destroy_workqueue(applesmc_led_wq); 1751 + applesmc_release_key_backlight(); 1293 1752 out_light_sysfs: 1294 - if (applesmc_light) 1295 - sysfs_remove_file(&pdev->dev.kobj, &dev_attr_light.attr); 1753 + applesmc_release_light_sensor(); 1296 1754 out_accelerometer: 1297 - if (applesmc_accelerometer) 1298 - applesmc_release_accelerometer(); 1755 + applesmc_release_accelerometer(); 1299 1756 out_temperature: 1300 - sysfs_remove_group(&pdev->dev.kobj, &label_attributes_group); 1301 - sysfs_remove_group(&pdev->dev.kobj, &temperature_attributes_group); 1757 + applesmc_destroy_nodes(temp_group); 1302 1758 out_fans: 1303 - while (fans_handled) 1304 - sysfs_remove_group(&pdev->dev.kobj, 1305 - &fan_attribute_groups[--fans_handled]); 1306 - sysfs_remove_group(&pdev->dev.kobj, &key_enumeration_group); 1307 - out_name: 1308 - sysfs_remove_file(&pdev->dev.kobj, &dev_attr_name.attr); 1759 + applesmc_destroy_nodes(fan_group); 1760 + out_info: 1761 + applesmc_destroy_nodes(info_group); 1762 + out_smcreg: 1763 + applesmc_destroy_smcreg(); 1309 1764 out_device: 1310 1765 platform_device_unregister(pdev); 1311 1766 out_driver: ··· 1303 1778 out_region: 1304 1779 release_region(APPLESMC_DATA_PORT, APPLESMC_NR_PORTS); 1305 1780 out: 1306 - printk(KERN_WARNING "applesmc: driver init failed (ret=%d)!\n", ret); 1781 + pr_warn("driver init failed (ret=%d)!\n", ret); 1307 1782 return ret; 1308 1783 } 1309 1784 1310 1785 static void __exit applesmc_exit(void) 1311 1786 { 1312 1787 hwmon_device_unregister(hwmon_dev); 1313 - if (applesmc_light) { 1314 - led_classdev_unregister(&applesmc_backlight); 1315 - destroy_workqueue(applesmc_led_wq); 1316 - sysfs_remove_file(&pdev->dev.kobj, &dev_attr_light.attr); 1317 - } 1318 - if (applesmc_accelerometer) 1319 - applesmc_release_accelerometer(); 1320 - sysfs_remove_group(&pdev->dev.kobj, &label_attributes_group); 1321 - sysfs_remove_group(&pdev->dev.kobj, &temperature_attributes_group); 1322 - while (fans_handled) 1323 - sysfs_remove_group(&pdev->dev.kobj, 1324 - &fan_attribute_groups[--fans_handled]); 1325 - sysfs_remove_group(&pdev->dev.kobj, &key_enumeration_group); 1326 - sysfs_remove_file(&pdev->dev.kobj, &dev_attr_name.attr); 1788 + applesmc_release_key_backlight(); 1789 + applesmc_release_light_sensor(); 1790 + applesmc_release_accelerometer(); 1791 + applesmc_destroy_nodes(temp_group); 1792 + applesmc_destroy_nodes(fan_group); 1793 + applesmc_destroy_nodes(info_group); 1794 + applesmc_destroy_smcreg(); 1327 1795 platform_device_unregister(pdev); 1328 1796 platform_driver_unregister(&applesmc_driver); 1329 1797 release_region(APPLESMC_DATA_PORT, APPLESMC_NR_PORTS); 1330 - 1331 - printk(KERN_INFO "applesmc: driver unloaded.\n"); 1332 1798 } 1333 1799 1334 1800 module_init(applesmc_init);
+5 -4
drivers/hwmon/asb100.c
··· 36 36 asb100 7 3 1 4 0x31 0x0694 yes no 37 37 */ 38 38 39 + #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 40 + 39 41 #include <linux/module.h> 40 42 #include <linux/slab.h> 41 43 #include <linux/i2c.h> ··· 703 701 int val1, val2; 704 702 705 703 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { 706 - pr_debug("asb100.o: detect failed, " 707 - "smbus byte data not supported!\n"); 704 + pr_debug("detect failed, smbus byte data not supported!\n"); 708 705 return -ENODEV; 709 706 } 710 707 ··· 716 715 (((!(val1 & 0x80)) && (val2 != 0x94)) || 717 716 /* Check for ASB100 ID (high byte ) */ 718 717 ((val1 & 0x80) && (val2 != 0x06)))) { 719 - pr_debug("asb100: detect failed, bad chip id 0x%02x!\n", val2); 718 + pr_debug("detect failed, bad chip id 0x%02x!\n", val2); 720 719 return -ENODEV; 721 720 } 722 721 ··· 745 744 746 745 data = kzalloc(sizeof(struct asb100_data), GFP_KERNEL); 747 746 if (!data) { 748 - pr_debug("asb100.o: probe failed, kzalloc failed!\n"); 747 + pr_debug("probe failed, kzalloc failed!\n"); 749 748 err = -ENOMEM; 750 749 goto ERROR0; 751 750 }
+4 -3
drivers/hwmon/asus_atk0110.c
··· 5 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 10 #include <linux/debugfs.h> 9 11 #include <linux/kernel.h> 10 12 #include <linux/hwmon.h> ··· 1416 1414 1417 1415 /* Make sure it's safe to access the device through ACPI */ 1418 1416 if (!acpi_resources_are_enforced()) { 1419 - pr_err("atk: Resources not safely usable due to " 1420 - "acpi_enforce_resources kernel parameter\n"); 1417 + pr_err("Resources not safely usable due to acpi_enforce_resources kernel parameter\n"); 1421 1418 return -EBUSY; 1422 1419 } 1423 1420 1424 1421 ret = acpi_bus_register_driver(&atk_driver); 1425 1422 if (ret) 1426 - pr_info("atk: acpi_bus_register_driver failed: %d\n", ret); 1423 + pr_info("acpi_bus_register_driver failed: %d\n", ret); 1427 1424 1428 1425 return ret; 1429 1426 }
+6 -5
drivers/hwmon/coretemp.c
··· 20 20 * 02110-1301 USA. 21 21 */ 22 22 23 + #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 24 + 23 25 #include <linux/module.h> 24 26 #include <linux/init.h> 25 27 #include <linux/slab.h> ··· 447 445 * without thermal sensors will be filtered out. 448 446 */ 449 447 if (!cpu_has(c, X86_FEATURE_DTS)) { 450 - printk(KERN_INFO DRVNAME ": CPU (model=0x%x)" 451 - " has no thermal sensor.\n", c->x86_model); 448 + pr_info("CPU (model=0x%x) has no thermal sensor\n", 449 + c->x86_model); 452 450 return 0; 453 451 } 454 452 ··· 468 466 pdev = platform_device_alloc(DRVNAME, cpu); 469 467 if (!pdev) { 470 468 err = -ENOMEM; 471 - printk(KERN_ERR DRVNAME ": Device allocation failed\n"); 469 + pr_err("Device allocation failed\n"); 472 470 goto exit; 473 471 } 474 472 ··· 480 478 481 479 err = platform_device_add(pdev); 482 480 if (err) { 483 - printk(KERN_ERR DRVNAME ": Device addition failed (%d)\n", 484 - err); 481 + pr_err("Device addition failed (%d)\n", err); 485 482 goto exit_device_free; 486 483 } 487 484
+6 -6
drivers/hwmon/dme1737.c
··· 25 25 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 26 26 */ 27 27 28 + #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 29 + 28 30 #include <linux/module.h> 29 31 #include <linux/init.h> 30 32 #include <linux/slab.h> ··· 2448 2446 /* Get the base address of the runtime registers */ 2449 2447 if (!(base_addr = (dme1737_sio_inb(sio_cip, 0x60) << 8) | 2450 2448 dme1737_sio_inb(sio_cip, 0x61))) { 2451 - printk(KERN_ERR "dme1737: Base address not set.\n"); 2449 + pr_err("Base address not set\n"); 2452 2450 err = -ENODEV; 2453 2451 goto exit; 2454 2452 } ··· 2477 2475 goto exit; 2478 2476 2479 2477 if (!(pdev = platform_device_alloc("dme1737", addr))) { 2480 - printk(KERN_ERR "dme1737: Failed to allocate device.\n"); 2478 + pr_err("Failed to allocate device\n"); 2481 2479 err = -ENOMEM; 2482 2480 goto exit; 2483 2481 } 2484 2482 2485 2483 if ((err = platform_device_add_resources(pdev, &res, 1))) { 2486 - printk(KERN_ERR "dme1737: Failed to add device resource " 2487 - "(err = %d).\n", err); 2484 + pr_err("Failed to add device resource (err = %d)\n", err); 2488 2485 goto exit_device_put; 2489 2486 } 2490 2487 2491 2488 if ((err = platform_device_add(pdev))) { 2492 - printk(KERN_ERR "dme1737: Failed to add device (err = %d).\n", 2493 - err); 2489 + pr_err("Failed to add device (err = %d)\n", err); 2494 2490 goto exit_device_put; 2495 2491 } 2496 2492
+337
drivers/hwmon/ds620.c
··· 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 */ 58 + static 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 */ 69 + struct 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 + */ 83 + static 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 + 93 + static 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 + 98 + static 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 + 128 + static 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 + } 157 + abort: 158 + mutex_unlock(&data->update_lock); 159 + 160 + return ret; 161 + } 162 + 163 + static 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 + 175 + static 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 + 200 + static 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 + 230 + static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0); 231 + static SENSOR_DEVICE_ATTR(temp1_min, S_IWUSR | S_IRUGO, show_temp, set_temp, 1); 232 + static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp, set_temp, 2); 233 + static SENSOR_DEVICE_ATTR(temp1_min_alarm, S_IRUGO, show_alarm, NULL, 234 + DS620_REG_CONFIG_TLF); 235 + static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL, 236 + DS620_REG_CONFIG_THF); 237 + 238 + static 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 + 247 + static const struct attribute_group ds620_group = { 248 + .attrs = ds620_attributes, 249 + }; 250 + 251 + static 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 + 284 + exit_remove_files: 285 + sysfs_remove_group(&client->dev.kobj, &ds620_group); 286 + exit_free: 287 + kfree(data); 288 + exit: 289 + return err; 290 + } 291 + 292 + static 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 + 304 + static const struct i2c_device_id ds620_id[] = { 305 + {"ds620", 0}, 306 + {} 307 + }; 308 + 309 + MODULE_DEVICE_TABLE(i2c, ds620_id); 310 + 311 + /* This is the driver that will be inserted */ 312 + static 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 + 322 + static int __init ds620_init(void) 323 + { 324 + return i2c_add_driver(&ds620_driver); 325 + } 326 + 327 + static void __exit ds620_exit(void) 328 + { 329 + i2c_del_driver(&ds620_driver); 330 + } 331 + 332 + MODULE_AUTHOR("Roland Stigge <stigge@antcom.de>"); 333 + MODULE_DESCRIPTION("DS620 driver"); 334 + MODULE_LICENSE("GPL"); 335 + 336 + module_init(ds620_init); 337 + module_exit(ds620_exit);
+13 -16
drivers/hwmon/f71805f.c
··· 28 28 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 29 29 */ 30 30 31 + #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 32 + 31 33 #include <linux/module.h> 32 34 #include <linux/init.h> 33 35 #include <linux/slab.h> ··· 1311 1309 1312 1310 if (!(data = kzalloc(sizeof(struct f71805f_data), GFP_KERNEL))) { 1313 1311 err = -ENOMEM; 1314 - printk(KERN_ERR DRVNAME ": Out of memory\n"); 1312 + pr_err("Out of memory\n"); 1315 1313 goto exit; 1316 1314 } 1317 1315 ··· 1453 1451 pdev = platform_device_alloc(DRVNAME, address); 1454 1452 if (!pdev) { 1455 1453 err = -ENOMEM; 1456 - printk(KERN_ERR DRVNAME ": Device allocation failed\n"); 1454 + pr_err("Device allocation failed\n"); 1457 1455 goto exit; 1458 1456 } 1459 1457 ··· 1464 1462 1465 1463 err = platform_device_add_resources(pdev, &res, 1); 1466 1464 if (err) { 1467 - printk(KERN_ERR DRVNAME ": Device resource addition failed " 1468 - "(%d)\n", err); 1465 + pr_err("Device resource addition failed (%d)\n", err); 1469 1466 goto exit_device_put; 1470 1467 } 1471 1468 1472 1469 err = platform_device_add_data(pdev, sio_data, 1473 1470 sizeof(struct f71805f_sio_data)); 1474 1471 if (err) { 1475 - printk(KERN_ERR DRVNAME ": Platform data allocation failed\n"); 1472 + pr_err("Platform data allocation failed\n"); 1476 1473 goto exit_device_put; 1477 1474 } 1478 1475 1479 1476 err = platform_device_add(pdev); 1480 1477 if (err) { 1481 - printk(KERN_ERR DRVNAME ": Device addition failed (%d)\n", 1482 - err); 1478 + pr_err("Device addition failed (%d)\n", err); 1483 1479 goto exit_device_put; 1484 1480 } 1485 1481 ··· 1516 1516 sio_data->fnsel1 = superio_inb(sioaddr, SIO_REG_FNSEL1); 1517 1517 break; 1518 1518 default: 1519 - printk(KERN_INFO DRVNAME ": Unsupported Fintek device, " 1520 - "skipping\n"); 1519 + pr_info("Unsupported Fintek device, skipping\n"); 1521 1520 goto exit; 1522 1521 } 1523 1522 1524 1523 superio_select(sioaddr, F71805F_LD_HWM); 1525 1524 if (!(superio_inb(sioaddr, SIO_REG_ENABLE) & 0x01)) { 1526 - printk(KERN_WARNING DRVNAME ": Device not activated, " 1527 - "skipping\n"); 1525 + pr_warn("Device not activated, skipping\n"); 1528 1526 goto exit; 1529 1527 } 1530 1528 1531 1529 *address = superio_inw(sioaddr, SIO_REG_ADDR); 1532 1530 if (*address == 0) { 1533 - printk(KERN_WARNING DRVNAME ": Base address not set, " 1534 - "skipping\n"); 1531 + pr_warn("Base address not set, skipping\n"); 1535 1532 goto exit; 1536 1533 } 1537 1534 *address &= ~(REGION_LENGTH - 1); /* Ignore 3 LSB */ 1538 1535 1539 1536 err = 0; 1540 - printk(KERN_INFO DRVNAME ": Found %s chip at %#x, revision %u\n", 1541 - names[sio_data->kind], *address, 1542 - superio_inb(sioaddr, SIO_REG_DEVREV)); 1537 + pr_info("Found %s chip at %#x, revision %u\n", 1538 + names[sio_data->kind], *address, 1539 + superio_inb(sioaddr, SIO_REG_DEVREV)); 1543 1540 1544 1541 exit: 1545 1542 superio_exit(sioaddr);
+12 -11
drivers/hwmon/f71882fg.c
··· 18 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 23 #include <linux/module.h> 22 24 #include <linux/init.h> 23 25 #include <linux/slab.h> ··· 867 865 { 868 866 /* Don't step on other drivers' I/O space by accident */ 869 867 if (!request_muxed_region(base, 2, DRVNAME)) { 870 - printk(KERN_ERR DRVNAME ": I/O address 0x%04x already in use\n", 871 - base); 868 + pr_err("I/O address 0x%04x already in use\n", base); 872 869 return -EBUSY; 873 870 } 874 871 ··· 2193 2192 2194 2193 devid = superio_inw(sioaddr, SIO_REG_MANID); 2195 2194 if (devid != SIO_FINTEK_ID) { 2196 - pr_debug(DRVNAME ": Not a Fintek device\n"); 2195 + pr_debug("Not a Fintek device\n"); 2197 2196 err = -ENODEV; 2198 2197 goto exit; 2199 2198 } ··· 2216 2215 sio_data->type = f8000; 2217 2216 break; 2218 2217 default: 2219 - printk(KERN_INFO DRVNAME ": Unsupported Fintek device: %04x\n", 2220 - (unsigned int)devid); 2218 + pr_info("Unsupported Fintek device: %04x\n", 2219 + (unsigned int)devid); 2221 2220 err = -ENODEV; 2222 2221 goto exit; 2223 2222 } ··· 2228 2227 superio_select(sioaddr, SIO_F71882FG_LD_HWM); 2229 2228 2230 2229 if (!(superio_inb(sioaddr, SIO_REG_ENABLE) & 0x01)) { 2231 - printk(KERN_WARNING DRVNAME ": Device not activated\n"); 2230 + pr_warn("Device not activated\n"); 2232 2231 err = -ENODEV; 2233 2232 goto exit; 2234 2233 } 2235 2234 2236 2235 *address = superio_inw(sioaddr, SIO_REG_ADDR); 2237 2236 if (*address == 0) { 2238 - printk(KERN_WARNING DRVNAME ": Base address not set\n"); 2237 + pr_warn("Base address not set\n"); 2239 2238 err = -ENODEV; 2240 2239 goto exit; 2241 2240 } 2242 2241 *address &= ~(REGION_LENGTH - 1); /* Ignore 3 LSB */ 2243 2242 2244 2243 err = 0; 2245 - printk(KERN_INFO DRVNAME ": Found %s chip at %#x, revision %d\n", 2244 + pr_info("Found %s chip at %#x, revision %d\n", 2246 2245 f71882fg_names[sio_data->type], (unsigned int)*address, 2247 2246 (int)superio_inb(sioaddr, SIO_REG_DEVREV)); 2248 2247 exit: ··· 2271 2270 2272 2271 err = platform_device_add_resources(f71882fg_pdev, &res, 1); 2273 2272 if (err) { 2274 - printk(KERN_ERR DRVNAME ": Device resource addition failed\n"); 2273 + pr_err("Device resource addition failed\n"); 2275 2274 goto exit_device_put; 2276 2275 } 2277 2276 2278 2277 err = platform_device_add_data(f71882fg_pdev, sio_data, 2279 2278 sizeof(struct f71882fg_sio_data)); 2280 2279 if (err) { 2281 - printk(KERN_ERR DRVNAME ": Platform data allocation failed\n"); 2280 + pr_err("Platform data allocation failed\n"); 2282 2281 goto exit_device_put; 2283 2282 } 2284 2283 2285 2284 err = platform_device_add(f71882fg_pdev); 2286 2285 if (err) { 2287 - printk(KERN_ERR DRVNAME ": Device addition failed\n"); 2286 + pr_err("Device addition failed\n"); 2288 2287 goto exit_device_put; 2289 2288 } 2290 2289
+7 -6
drivers/hwmon/hp_accel.c
··· 20 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 25 #include <linux/kernel.h> 24 26 #include <linux/init.h> 25 27 #include <linux/dmi.h> ··· 149 147 static int lis3lv02d_dmi_matched(const struct dmi_system_id *dmi) 150 148 { 151 149 lis3_dev.ac = *((union axis_conversion *)dmi->driver_data); 152 - printk(KERN_INFO DRIVER_NAME ": hardware type %s found.\n", dmi->ident); 150 + pr_info("hardware type %s found\n", dmi->ident); 153 151 154 152 return 1; 155 153 } ··· 305 303 306 304 /* If possible use a "standard" axes order */ 307 305 if (lis3_dev.ac.x && lis3_dev.ac.y && lis3_dev.ac.z) { 308 - printk(KERN_INFO DRIVER_NAME ": Using custom axes %d,%d,%d\n", 309 - lis3_dev.ac.x, lis3_dev.ac.y, lis3_dev.ac.z); 306 + pr_info("Using custom axes %d,%d,%d\n", 307 + lis3_dev.ac.x, lis3_dev.ac.y, lis3_dev.ac.z); 310 308 } else if (dmi_check_system(lis3lv02d_dmi_ids) == 0) { 311 - printk(KERN_INFO DRIVER_NAME ": laptop model unknown, " 312 - "using default axes configuration\n"); 309 + pr_info("laptop model unknown, using default axes configuration\n"); 313 310 lis3_dev.ac = lis3lv02d_axis_normal; 314 311 } 315 312 ··· 386 385 if (ret < 0) 387 386 return ret; 388 387 389 - printk(KERN_INFO DRIVER_NAME " driver loaded.\n"); 388 + pr_info("driver loaded\n"); 390 389 391 390 return 0; 392 391 }
+6 -5
drivers/hwmon/hwmon-vid.c
··· 22 22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 23 23 */ 24 24 25 + #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 26 + 25 27 #include <linux/module.h> 26 28 #include <linux/kernel.h> 27 29 #include <linux/hwmon-vid.h> ··· 148 146 return(val > 0x77 ? 0 : (1500000 - (val * 12500) + 500) / 1000); 149 147 default: /* report 0 for unknown */ 150 148 if (vrm) 151 - printk(KERN_WARNING "hwmon-vid: Requested unsupported " 152 - "VRM version (%u)\n", (unsigned int)vrm); 149 + pr_warn("Requested unsupported VRM version (%u)\n", 150 + (unsigned int)vrm); 153 151 return 0; 154 152 } 155 153 } ··· 248 246 } 249 247 vrm_ret = find_vrm(eff_family, eff_model, eff_stepping, c->x86_vendor); 250 248 if (vrm_ret == 0) 251 - printk(KERN_INFO "hwmon-vid: Unknown VRM version of your " 252 - "x86 CPU\n"); 249 + pr_info("Unknown VRM version of your x86 CPU\n"); 253 250 return vrm_ret; 254 251 } 255 252 ··· 256 255 #else 257 256 u8 vid_which_vrm(void) 258 257 { 259 - printk(KERN_INFO "hwmon-vid: Unknown VRM version of your CPU\n"); 258 + pr_info("Unknown VRM version of your CPU\n"); 260 259 return 0; 261 260 } 262 261 #endif
+3 -1
drivers/hwmon/hwmon.c
··· 10 10 the Free Software Foundation; version 2 of the License. 11 11 */ 12 12 13 + #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 14 + 13 15 #include <linux/module.h> 14 16 #include <linux/device.h> 15 17 #include <linux/err.h> ··· 121 119 122 120 hwmon_class = class_create(THIS_MODULE, "hwmon"); 123 121 if (IS_ERR(hwmon_class)) { 124 - printk(KERN_ERR "hwmon.c: couldn't create sysfs class\n"); 122 + pr_err("couldn't create sysfs class\n"); 125 123 return PTR_ERR(hwmon_class); 126 124 } 127 125 return 0;
+3 -1
drivers/hwmon/ibmaem.c
··· 20 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 25 #include <linux/ipmi.h> 24 26 #include <linux/module.h> 25 27 #include <linux/hwmon.h> ··· 1092 1090 1093 1091 res = driver_register(&aem_driver.driver); 1094 1092 if (res) { 1095 - printk(KERN_ERR "Can't register aem driver\n"); 1093 + pr_err("Can't register aem driver\n"); 1096 1094 return res; 1097 1095 } 1098 1096
+11 -12
drivers/hwmon/lis3lv02d.c
··· 20 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 25 #include <linux/kernel.h> 24 26 #include <linux/init.h> 25 27 #include <linux/dmi.h> ··· 862 860 (p->irq_flags2 & IRQF_TRIGGER_MASK), 863 861 DRIVER_NAME, &lis3_dev); 864 862 if (err < 0) 865 - printk(KERN_ERR DRIVER_NAME 866 - "No second IRQ. Limited functionality\n"); 863 + pr_err("No second IRQ. Limited functionality\n"); 867 864 } 868 865 } 869 866 ··· 880 879 881 880 switch (dev->whoami) { 882 881 case WAI_12B: 883 - printk(KERN_INFO DRIVER_NAME ": 12 bits sensor found\n"); 882 + pr_info("12 bits sensor found\n"); 884 883 dev->read_data = lis3lv02d_read_12; 885 884 dev->mdps_max_val = 2048; 886 885 dev->pwron_delay = LIS3_PWRON_DELAY_WAI_12B; ··· 891 890 dev->regs_size = ARRAY_SIZE(lis3_wai12_regs); 892 891 break; 893 892 case WAI_8B: 894 - printk(KERN_INFO DRIVER_NAME ": 8 bits sensor found\n"); 893 + pr_info("8 bits sensor found\n"); 895 894 dev->read_data = lis3lv02d_read_8; 896 895 dev->mdps_max_val = 128; 897 896 dev->pwron_delay = LIS3_PWRON_DELAY_WAI_8B; ··· 902 901 dev->regs_size = ARRAY_SIZE(lis3_wai8_regs); 903 902 break; 904 903 case WAI_3DC: 905 - printk(KERN_INFO DRIVER_NAME ": 8 bits 3DC sensor found\n"); 904 + pr_info("8 bits 3DC sensor found\n"); 906 905 dev->read_data = lis3lv02d_read_8; 907 906 dev->mdps_max_val = 128; 908 907 dev->pwron_delay = LIS3_PWRON_DELAY_WAI_8B; ··· 911 910 dev->scale = LIS3_SENSITIVITY_8B; 912 911 break; 913 912 default: 914 - printk(KERN_ERR DRIVER_NAME 915 - ": unknown sensor type 0x%X\n", dev->whoami); 913 + pr_err("unknown sensor type 0x%X\n", dev->whoami); 916 914 return -EINVAL; 917 915 } 918 916 ··· 935 935 } 936 936 937 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 940 /* passing in platform specific data is purely optional and only 941 941 * used by the SPI transport layer at the moment */ ··· 957 957 958 958 /* bail if we did not get an IRQ from the bus layer */ 959 959 if (!dev->irq) { 960 - printk(KERN_ERR DRIVER_NAME 961 - ": No IRQ. Disabling /dev/freefall\n"); 960 + pr_err("No IRQ. Disabling /dev/freefall\n"); 962 961 goto out; 963 962 } 964 963 ··· 984 985 DRIVER_NAME, &lis3_dev); 985 986 986 987 if (err < 0) { 987 - printk(KERN_ERR DRIVER_NAME "Cannot get IRQ\n"); 988 + pr_err("Cannot get IRQ\n"); 988 989 goto out; 989 990 } 990 991 991 992 if (misc_register(&lis3lv02d_misc_device)) 992 - printk(KERN_ERR DRIVER_NAME ": misc_register failed\n"); 993 + pr_err("misc_register failed\n"); 993 994 out: 994 995 return 0; 995 996 }
+3 -2
drivers/hwmon/lm70.c
··· 24 24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 25 25 */ 26 26 27 + #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 28 + 27 29 #include <linux/init.h> 28 30 #include <linux/module.h> 29 31 #include <linux/kernel.h> ··· 69 67 */ 70 68 status = spi_write_then_read(spi, NULL, 0, &rxbuf[0], 2); 71 69 if (status < 0) { 72 - printk(KERN_WARNING 73 - "spi_write_then_read failed with status %d\n", status); 70 + pr_warn("spi_write_then_read failed with status %d\n", status); 74 71 goto out; 75 72 } 76 73 raw = (rxbuf[0] << 8) + rxbuf[1];
+239 -268
drivers/hwmon/lm95241.c
··· 1 1 /* 2 - * lm95241.c - Part of lm_sensors, Linux kernel modules for hardware 3 - * monitoring 4 - * Copyright (C) 2008 Davide Rizzo <elpa-rizzo@gmail.com> 2 + * Copyright (C) 2008, 2010 Davide Rizzo <elpa.rizzo@gmail.com> 5 3 * 6 - * Based on the max1619 driver. The LM95241 is a sensor chip made by National 7 - * Semiconductors. 8 - * It reports up to three temperatures (its own plus up to 9 - * two external ones). Complete datasheet can be 10 - * obtained from National's website at: 4 + * The LM95241 is a sensor chip made by National Semiconductors. 5 + * It reports up to three temperatures (its own plus up to two external ones). 6 + * Complete datasheet can be obtained from National's website at: 11 7 * http://www.national.com/ds.cgi/LM/LM95241.pdf 12 8 * 13 9 * This program is free software; you can redistribute it and/or modify ··· 32 36 #include <linux/mutex.h> 33 37 #include <linux/sysfs.h> 34 38 39 + #define DEVNAME "lm95241" 40 + 35 41 static const unsigned short normal_i2c[] = { 36 - 0x19, 0x2a, 0x2b, I2C_CLIENT_END}; 42 + 0x19, 0x2a, 0x2b, I2C_CLIENT_END }; 37 43 38 44 /* LM95241 registers */ 39 45 #define LM95241_REG_R_MAN_ID 0xFE ··· 44 46 #define LM95241_REG_RW_CONFIG 0x03 45 47 #define LM95241_REG_RW_REM_FILTER 0x06 46 48 #define LM95241_REG_RW_TRUTHERM 0x07 47 - #define LM95241_REG_W_ONE_SHOT 0x0F 49 + #define LM95241_REG_W_ONE_SHOT 0x0F 48 50 #define LM95241_REG_R_LOCAL_TEMPH 0x10 49 51 #define LM95241_REG_R_REMOTE1_TEMPH 0x11 50 52 #define LM95241_REG_R_REMOTE2_TEMPH 0x12 ··· 77 79 #define MANUFACTURER_ID 0x01 78 80 #define DEFAULT_REVISION 0xA4 79 81 80 - /* Conversions and various macros */ 81 - #define TEMP_FROM_REG(val_h, val_l) (((val_h) & 0x80 ? (val_h) - 0x100 : \ 82 - (val_h)) * 1000 + (val_l) * 1000 / 256) 83 - 84 - /* Functions declaration */ 85 - static void lm95241_init_client(struct i2c_client *client); 86 - static struct lm95241_data *lm95241_update_device(struct device *dev); 82 + static const u8 lm95241_reg_address[] = { 83 + LM95241_REG_R_LOCAL_TEMPH, 84 + LM95241_REG_R_LOCAL_TEMPL, 85 + LM95241_REG_R_REMOTE1_TEMPH, 86 + LM95241_REG_R_REMOTE1_TEMPL, 87 + LM95241_REG_R_REMOTE2_TEMPH, 88 + LM95241_REG_R_REMOTE2_TEMPL 89 + }; 87 90 88 91 /* Client data (each client gets its own) */ 89 92 struct lm95241_data { 90 93 struct device *hwmon_dev; 91 94 struct mutex update_lock; 92 - unsigned long last_updated, interval; /* in jiffies */ 93 - char valid; /* zero until following fields are valid */ 95 + unsigned long last_updated, interval; /* in jiffies */ 96 + char valid; /* zero until following fields are valid */ 94 97 /* registers values */ 95 - u8 local_h, local_l; /* local */ 96 - u8 remote1_h, remote1_l; /* remote1 */ 97 - u8 remote2_h, remote2_l; /* remote2 */ 98 + u8 temp[ARRAY_SIZE(lm95241_reg_address)]; 98 99 u8 config, model, trutherm; 99 100 }; 100 101 101 - /* Sysfs stuff */ 102 - #define show_temp(value) \ 103 - static ssize_t show_##value(struct device *dev, \ 104 - struct device_attribute *attr, char *buf) \ 105 - { \ 106 - struct lm95241_data *data = lm95241_update_device(dev); \ 107 - snprintf(buf, PAGE_SIZE - 1, "%d\n", \ 108 - TEMP_FROM_REG(data->value##_h, data->value##_l)); \ 109 - return strlen(buf); \ 102 + /* Conversions */ 103 + static int TempFromReg(u8 val_h, u8 val_l) 104 + { 105 + if (val_h & 0x80) 106 + return val_h - 0x100; 107 + return val_h * 1000 + val_l * 1000 / 256; 110 108 } 111 - show_temp(local); 112 - show_temp(remote1); 113 - show_temp(remote2); 114 109 115 - static ssize_t show_interval(struct device *dev, struct device_attribute *attr, 116 - char *buf) 110 + static struct lm95241_data *lm95241_update_device(struct device *dev) 111 + { 112 + struct i2c_client *client = to_i2c_client(dev); 113 + struct lm95241_data *data = i2c_get_clientdata(client); 114 + 115 + mutex_lock(&data->update_lock); 116 + 117 + if (time_after(jiffies, data->last_updated + data->interval) || 118 + !data->valid) { 119 + int i; 120 + 121 + dev_dbg(&client->dev, "Updating lm95241 data.\n"); 122 + for (i = 0; i < ARRAY_SIZE(lm95241_reg_address); i++) 123 + data->temp[i] 124 + = i2c_smbus_read_byte_data(client, 125 + lm95241_reg_address[i]); 126 + data->last_updated = jiffies; 127 + data->valid = 1; 128 + } 129 + 130 + mutex_unlock(&data->update_lock); 131 + 132 + return data; 133 + } 134 + 135 + /* Sysfs stuff */ 136 + static ssize_t show_input(struct device *dev, struct device_attribute *attr, 137 + char *buf) 117 138 { 118 139 struct lm95241_data *data = lm95241_update_device(dev); 119 140 120 - snprintf(buf, PAGE_SIZE - 1, "%lu\n", 1000 * data->interval / HZ); 121 - return strlen(buf); 141 + return snprintf(buf, PAGE_SIZE - 1, "%d\n", 142 + TempFromReg(data->temp[to_sensor_dev_attr(attr)->index], 143 + data->temp[to_sensor_dev_attr(attr)->index + 1])); 144 + } 145 + 146 + static ssize_t show_type(struct device *dev, struct device_attribute *attr, 147 + char *buf) 148 + { 149 + struct i2c_client *client = to_i2c_client(dev); 150 + struct lm95241_data *data = i2c_get_clientdata(client); 151 + 152 + return snprintf(buf, PAGE_SIZE - 1, 153 + data->model & to_sensor_dev_attr(attr)->index ? "1\n" : "2\n"); 154 + } 155 + 156 + static ssize_t set_type(struct device *dev, struct device_attribute *attr, 157 + const char *buf, size_t count) 158 + { 159 + struct i2c_client *client = to_i2c_client(dev); 160 + struct lm95241_data *data = i2c_get_clientdata(client); 161 + unsigned long val; 162 + int shift; 163 + u8 mask = to_sensor_dev_attr(attr)->index; 164 + 165 + if (strict_strtoul(buf, 10, &val) < 0) 166 + return -EINVAL; 167 + if (val != 1 && val != 2) 168 + return -EINVAL; 169 + 170 + shift = mask == R1MS_MASK ? TT1_SHIFT : TT2_SHIFT; 171 + 172 + mutex_lock(&data->update_lock); 173 + 174 + data->trutherm &= ~(TT_MASK << shift); 175 + if (val == 1) { 176 + data->model |= mask; 177 + data->trutherm |= (TT_ON << shift); 178 + } else { 179 + data->model &= ~mask; 180 + data->trutherm |= (TT_OFF << shift); 181 + } 182 + data->valid = 0; 183 + 184 + i2c_smbus_write_byte_data(client, LM95241_REG_RW_REMOTE_MODEL, 185 + data->model); 186 + i2c_smbus_write_byte_data(client, LM95241_REG_RW_TRUTHERM, 187 + data->trutherm); 188 + 189 + mutex_unlock(&data->update_lock); 190 + 191 + return count; 192 + } 193 + 194 + static ssize_t show_min(struct device *dev, struct device_attribute *attr, 195 + char *buf) 196 + { 197 + struct i2c_client *client = to_i2c_client(dev); 198 + struct lm95241_data *data = i2c_get_clientdata(client); 199 + 200 + return snprintf(buf, PAGE_SIZE - 1, 201 + data->config & to_sensor_dev_attr(attr)->index ? 202 + "-127000\n" : "0\n"); 203 + } 204 + 205 + static ssize_t set_min(struct device *dev, struct device_attribute *attr, 206 + const char *buf, size_t count) 207 + { 208 + struct i2c_client *client = to_i2c_client(dev); 209 + struct lm95241_data *data = i2c_get_clientdata(client); 210 + long val; 211 + 212 + if (strict_strtol(buf, 10, &val) < 0) 213 + return -EINVAL; 214 + if (val < -128000) 215 + return -EINVAL; 216 + 217 + mutex_lock(&data->update_lock); 218 + 219 + if (val < 0) 220 + data->config |= to_sensor_dev_attr(attr)->index; 221 + else 222 + data->config &= ~to_sensor_dev_attr(attr)->index; 223 + data->valid = 0; 224 + 225 + i2c_smbus_write_byte_data(client, LM95241_REG_RW_CONFIG, data->config); 226 + 227 + mutex_unlock(&data->update_lock); 228 + 229 + return count; 230 + } 231 + 232 + static ssize_t show_max(struct device *dev, struct device_attribute *attr, 233 + char *buf) 234 + { 235 + struct i2c_client *client = to_i2c_client(dev); 236 + struct lm95241_data *data = i2c_get_clientdata(client); 237 + 238 + return snprintf(buf, PAGE_SIZE - 1, 239 + data->config & to_sensor_dev_attr(attr)->index ? 240 + "127000\n" : "255000\n"); 241 + } 242 + 243 + static ssize_t set_max(struct device *dev, struct device_attribute *attr, 244 + const char *buf, size_t count) 245 + { 246 + struct i2c_client *client = to_i2c_client(dev); 247 + struct lm95241_data *data = i2c_get_clientdata(client); 248 + long val; 249 + 250 + if (strict_strtol(buf, 10, &val) < 0) 251 + return -EINVAL; 252 + if (val >= 256000) 253 + return -EINVAL; 254 + 255 + mutex_lock(&data->update_lock); 256 + 257 + if (val <= 127000) 258 + data->config |= to_sensor_dev_attr(attr)->index; 259 + else 260 + data->config &= ~to_sensor_dev_attr(attr)->index; 261 + data->valid = 0; 262 + 263 + i2c_smbus_write_byte_data(client, LM95241_REG_RW_CONFIG, data->config); 264 + 265 + mutex_unlock(&data->update_lock); 266 + 267 + return count; 268 + } 269 + 270 + static ssize_t show_interval(struct device *dev, struct device_attribute *attr, 271 + char *buf) 272 + { 273 + struct lm95241_data *data = lm95241_update_device(dev); 274 + 275 + return snprintf(buf, PAGE_SIZE - 1, "%lu\n", 1000 * data->interval 276 + / HZ); 122 277 } 123 278 124 279 static ssize_t set_interval(struct device *dev, struct device_attribute *attr, 125 - const char *buf, size_t count) 280 + const char *buf, size_t count) 126 281 { 127 282 struct i2c_client *client = to_i2c_client(dev); 128 283 struct lm95241_data *data = i2c_get_clientdata(client); ··· 289 138 return count; 290 139 } 291 140 292 - #define show_type(flag) \ 293 - static ssize_t show_type##flag(struct device *dev, \ 294 - struct device_attribute *attr, char *buf) \ 295 - { \ 296 - struct i2c_client *client = to_i2c_client(dev); \ 297 - struct lm95241_data *data = i2c_get_clientdata(client); \ 298 - \ 299 - snprintf(buf, PAGE_SIZE - 1, \ 300 - data->model & R##flag##MS_MASK ? "1\n" : "2\n"); \ 301 - return strlen(buf); \ 302 - } 303 - show_type(1); 304 - show_type(2); 305 - 306 - #define show_min(flag) \ 307 - static ssize_t show_min##flag(struct device *dev, \ 308 - struct device_attribute *attr, char *buf) \ 309 - { \ 310 - struct i2c_client *client = to_i2c_client(dev); \ 311 - struct lm95241_data *data = i2c_get_clientdata(client); \ 312 - \ 313 - snprintf(buf, PAGE_SIZE - 1, \ 314 - data->config & R##flag##DF_MASK ? \ 315 - "-127000\n" : "0\n"); \ 316 - return strlen(buf); \ 317 - } 318 - show_min(1); 319 - show_min(2); 320 - 321 - #define show_max(flag) \ 322 - static ssize_t show_max##flag(struct device *dev, \ 323 - struct device_attribute *attr, char *buf) \ 324 - { \ 325 - struct i2c_client *client = to_i2c_client(dev); \ 326 - struct lm95241_data *data = i2c_get_clientdata(client); \ 327 - \ 328 - snprintf(buf, PAGE_SIZE - 1, \ 329 - data->config & R##flag##DF_MASK ? \ 330 - "127000\n" : "255000\n"); \ 331 - return strlen(buf); \ 332 - } 333 - show_max(1); 334 - show_max(2); 335 - 336 - #define set_type(flag) \ 337 - static ssize_t set_type##flag(struct device *dev, \ 338 - struct device_attribute *attr, \ 339 - const char *buf, size_t count) \ 340 - { \ 341 - struct i2c_client *client = to_i2c_client(dev); \ 342 - struct lm95241_data *data = i2c_get_clientdata(client); \ 343 - \ 344 - long val; \ 345 - \ 346 - if (strict_strtol(buf, 10, &val) < 0) \ 347 - return -EINVAL; \ 348 - \ 349 - if ((val == 1) || (val == 2)) { \ 350 - \ 351 - mutex_lock(&data->update_lock); \ 352 - \ 353 - data->trutherm &= ~(TT_MASK << TT##flag##_SHIFT); \ 354 - if (val == 1) { \ 355 - data->model |= R##flag##MS_MASK; \ 356 - data->trutherm |= (TT_ON << TT##flag##_SHIFT); \ 357 - } \ 358 - else { \ 359 - data->model &= ~R##flag##MS_MASK; \ 360 - data->trutherm |= (TT_OFF << TT##flag##_SHIFT); \ 361 - } \ 362 - \ 363 - data->valid = 0; \ 364 - \ 365 - i2c_smbus_write_byte_data(client, LM95241_REG_RW_REMOTE_MODEL, \ 366 - data->model); \ 367 - i2c_smbus_write_byte_data(client, LM95241_REG_RW_TRUTHERM, \ 368 - data->trutherm); \ 369 - \ 370 - mutex_unlock(&data->update_lock); \ 371 - \ 372 - } \ 373 - return count; \ 374 - } 375 - set_type(1); 376 - set_type(2); 377 - 378 - #define set_min(flag) \ 379 - static ssize_t set_min##flag(struct device *dev, \ 380 - struct device_attribute *devattr, const char *buf, size_t count) \ 381 - { \ 382 - struct i2c_client *client = to_i2c_client(dev); \ 383 - struct lm95241_data *data = i2c_get_clientdata(client); \ 384 - \ 385 - long val; \ 386 - \ 387 - if (strict_strtol(buf, 10, &val) < 0) \ 388 - return -EINVAL;\ 389 - \ 390 - mutex_lock(&data->update_lock); \ 391 - \ 392 - if (val < 0) \ 393 - data->config |= R##flag##DF_MASK; \ 394 - else \ 395 - data->config &= ~R##flag##DF_MASK; \ 396 - \ 397 - data->valid = 0; \ 398 - \ 399 - i2c_smbus_write_byte_data(client, LM95241_REG_RW_CONFIG, \ 400 - data->config); \ 401 - \ 402 - mutex_unlock(&data->update_lock); \ 403 - \ 404 - return count; \ 405 - } 406 - set_min(1); 407 - set_min(2); 408 - 409 - #define set_max(flag) \ 410 - static ssize_t set_max##flag(struct device *dev, \ 411 - struct device_attribute *devattr, const char *buf, size_t count) \ 412 - { \ 413 - struct i2c_client *client = to_i2c_client(dev); \ 414 - struct lm95241_data *data = i2c_get_clientdata(client); \ 415 - \ 416 - long val; \ 417 - \ 418 - if (strict_strtol(buf, 10, &val) < 0) \ 419 - return -EINVAL; \ 420 - \ 421 - mutex_lock(&data->update_lock); \ 422 - \ 423 - if (val <= 127000) \ 424 - data->config |= R##flag##DF_MASK; \ 425 - else \ 426 - data->config &= ~R##flag##DF_MASK; \ 427 - \ 428 - data->valid = 0; \ 429 - \ 430 - i2c_smbus_write_byte_data(client, LM95241_REG_RW_CONFIG, \ 431 - data->config); \ 432 - \ 433 - mutex_unlock(&data->update_lock); \ 434 - \ 435 - return count; \ 436 - } 437 - set_max(1); 438 - set_max(2); 439 - 440 - static DEVICE_ATTR(temp1_input, S_IRUGO, show_local, NULL); 441 - static DEVICE_ATTR(temp2_input, S_IRUGO, show_remote1, NULL); 442 - static DEVICE_ATTR(temp3_input, S_IRUGO, show_remote2, NULL); 443 - static DEVICE_ATTR(temp2_type, S_IWUSR | S_IRUGO, show_type1, set_type1); 444 - static DEVICE_ATTR(temp3_type, S_IWUSR | S_IRUGO, show_type2, set_type2); 445 - static DEVICE_ATTR(temp2_min, S_IWUSR | S_IRUGO, show_min1, set_min1); 446 - static DEVICE_ATTR(temp3_min, S_IWUSR | S_IRUGO, show_min2, set_min2); 447 - static DEVICE_ATTR(temp2_max, S_IWUSR | S_IRUGO, show_max1, set_max1); 448 - static DEVICE_ATTR(temp3_max, S_IWUSR | S_IRUGO, show_max2, set_max2); 141 + static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_input, NULL, 0); 142 + static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_input, NULL, 2); 143 + static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO, show_input, NULL, 4); 144 + static SENSOR_DEVICE_ATTR(temp2_type, S_IWUSR | S_IRUGO, show_type, set_type, 145 + R1MS_MASK); 146 + static SENSOR_DEVICE_ATTR(temp3_type, S_IWUSR | S_IRUGO, show_type, set_type, 147 + R2MS_MASK); 148 + static SENSOR_DEVICE_ATTR(temp2_min, S_IWUSR | S_IRUGO, show_min, set_min, 149 + R1DF_MASK); 150 + static SENSOR_DEVICE_ATTR(temp3_min, S_IWUSR | S_IRUGO, show_min, set_min, 151 + R2DF_MASK); 152 + static SENSOR_DEVICE_ATTR(temp2_max, S_IWUSR | S_IRUGO, show_max, set_max, 153 + R1DF_MASK); 154 + static SENSOR_DEVICE_ATTR(temp3_max, S_IWUSR | S_IRUGO, show_max, set_max, 155 + R2DF_MASK); 449 156 static DEVICE_ATTR(update_interval, S_IWUSR | S_IRUGO, show_interval, 450 157 set_interval); 451 158 452 159 static struct attribute *lm95241_attributes[] = { 453 - &dev_attr_temp1_input.attr, 454 - &dev_attr_temp2_input.attr, 455 - &dev_attr_temp3_input.attr, 456 - &dev_attr_temp2_type.attr, 457 - &dev_attr_temp3_type.attr, 458 - &dev_attr_temp2_min.attr, 459 - &dev_attr_temp3_min.attr, 460 - &dev_attr_temp2_max.attr, 461 - &dev_attr_temp3_max.attr, 160 + &sensor_dev_attr_temp1_input.dev_attr.attr, 161 + &sensor_dev_attr_temp2_input.dev_attr.attr, 162 + &sensor_dev_attr_temp3_input.dev_attr.attr, 163 + &sensor_dev_attr_temp2_type.dev_attr.attr, 164 + &sensor_dev_attr_temp3_type.dev_attr.attr, 165 + &sensor_dev_attr_temp2_min.dev_attr.attr, 166 + &sensor_dev_attr_temp3_min.dev_attr.attr, 167 + &sensor_dev_attr_temp2_max.dev_attr.attr, 168 + &sensor_dev_attr_temp3_max.dev_attr.attr, 462 169 &dev_attr_update_interval.attr, 463 170 NULL 464 171 }; ··· 338 329 339 330 if ((i2c_smbus_read_byte_data(new_client, LM95241_REG_R_MAN_ID) 340 331 == MANUFACTURER_ID) 341 - && (i2c_smbus_read_byte_data(new_client, LM95241_REG_R_CHIP_ID) 342 - >= DEFAULT_REVISION)) { 343 - name = "lm95241"; 332 + && (i2c_smbus_read_byte_data(new_client, LM95241_REG_R_CHIP_ID) 333 + >= DEFAULT_REVISION)) { 334 + name = DEVNAME; 344 335 } else { 345 336 dev_dbg(&adapter->dev, "LM95241 detection failed at 0x%02x\n", 346 337 address); ··· 350 341 /* Fill the i2c board info */ 351 342 strlcpy(info->type, name, I2C_NAME_SIZE); 352 343 return 0; 344 + } 345 + 346 + static void lm95241_init_client(struct i2c_client *client) 347 + { 348 + struct lm95241_data *data = i2c_get_clientdata(client); 349 + 350 + data->interval = HZ; /* 1 sec default */ 351 + data->valid = 0; 352 + data->config = CFG_CR0076; 353 + data->model = 0; 354 + data->trutherm = (TT_OFF << TT1_SHIFT) | (TT_OFF << TT2_SHIFT); 355 + 356 + i2c_smbus_write_byte_data(client, LM95241_REG_RW_CONFIG, data->config); 357 + i2c_smbus_write_byte_data(client, LM95241_REG_RW_REM_FILTER, 358 + R1FE_MASK | R2FE_MASK); 359 + i2c_smbus_write_byte_data(client, LM95241_REG_RW_TRUTHERM, 360 + data->trutherm); 361 + i2c_smbus_write_byte_data(client, LM95241_REG_RW_REMOTE_MODEL, 362 + data->model); 353 363 } 354 364 355 365 static int lm95241_probe(struct i2c_client *new_client, ··· 410 382 return err; 411 383 } 412 384 413 - static void lm95241_init_client(struct i2c_client *client) 414 - { 415 - struct lm95241_data *data = i2c_get_clientdata(client); 416 - 417 - data->interval = HZ; /* 1 sec default */ 418 - data->valid = 0; 419 - data->config = CFG_CR0076; 420 - data->model = 0; 421 - data->trutherm = (TT_OFF << TT1_SHIFT) | (TT_OFF << TT2_SHIFT); 422 - 423 - i2c_smbus_write_byte_data(client, LM95241_REG_RW_CONFIG, 424 - data->config); 425 - i2c_smbus_write_byte_data(client, LM95241_REG_RW_REM_FILTER, 426 - R1FE_MASK | R2FE_MASK); 427 - i2c_smbus_write_byte_data(client, LM95241_REG_RW_TRUTHERM, 428 - data->trutherm); 429 - i2c_smbus_write_byte_data(client, LM95241_REG_RW_REMOTE_MODEL, 430 - data->model); 431 - } 432 - 433 385 static int lm95241_remove(struct i2c_client *client) 434 386 { 435 387 struct lm95241_data *data = i2c_get_clientdata(client); ··· 421 413 return 0; 422 414 } 423 415 424 - static struct lm95241_data *lm95241_update_device(struct device *dev) 425 - { 426 - struct i2c_client *client = to_i2c_client(dev); 427 - struct lm95241_data *data = i2c_get_clientdata(client); 428 - 429 - mutex_lock(&data->update_lock); 430 - 431 - if (time_after(jiffies, data->last_updated + data->interval) || 432 - !data->valid) { 433 - dev_dbg(&client->dev, "Updating lm95241 data.\n"); 434 - data->local_h = 435 - i2c_smbus_read_byte_data(client, 436 - LM95241_REG_R_LOCAL_TEMPH); 437 - data->local_l = 438 - i2c_smbus_read_byte_data(client, 439 - LM95241_REG_R_LOCAL_TEMPL); 440 - data->remote1_h = 441 - i2c_smbus_read_byte_data(client, 442 - LM95241_REG_R_REMOTE1_TEMPH); 443 - data->remote1_l = 444 - i2c_smbus_read_byte_data(client, 445 - LM95241_REG_R_REMOTE1_TEMPL); 446 - data->remote2_h = 447 - i2c_smbus_read_byte_data(client, 448 - LM95241_REG_R_REMOTE2_TEMPH); 449 - data->remote2_l = 450 - i2c_smbus_read_byte_data(client, 451 - LM95241_REG_R_REMOTE2_TEMPL); 452 - data->last_updated = jiffies; 453 - data->valid = 1; 454 - } 455 - 456 - mutex_unlock(&data->update_lock); 457 - 458 - return data; 459 - } 460 - 461 416 /* Driver data (common to all clients) */ 462 417 static const struct i2c_device_id lm95241_id[] = { 463 - { "lm95241", 0 }, 418 + { DEVNAME, 0 }, 464 419 { } 465 420 }; 466 421 MODULE_DEVICE_TABLE(i2c, lm95241_id); ··· 431 460 static struct i2c_driver lm95241_driver = { 432 461 .class = I2C_CLASS_HWMON, 433 462 .driver = { 434 - .name = "lm95241", 463 + .name = DEVNAME, 435 464 }, 436 465 .probe = lm95241_probe, 437 466 .remove = lm95241_remove, ··· 450 479 i2c_del_driver(&lm95241_driver); 451 480 } 452 481 453 - MODULE_AUTHOR("Davide Rizzo <elpa-rizzo@gmail.com>"); 482 + MODULE_AUTHOR("Davide Rizzo <elpa.rizzo@gmail.com>"); 454 483 MODULE_DESCRIPTION("LM95241 sensor driver"); 455 484 MODULE_LICENSE("GPL"); 456 485
+3 -2
drivers/hwmon/pcf8591.c
··· 18 18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 19 */ 20 20 21 + #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 22 + 21 23 #include <linux/module.h> 22 24 #include <linux/init.h> 23 25 #include <linux/slab.h> ··· 292 290 static int __init pcf8591_init(void) 293 291 { 294 292 if (input_mode < 0 || input_mode > 3) { 295 - printk(KERN_WARNING "pcf8591: invalid input_mode (%d)\n", 296 - input_mode); 293 + pr_warn("invalid input_mode (%d)\n", input_mode); 297 294 input_mode = 0; 298 295 } 299 296 return i2c_add_driver(&pcf8591_driver);
+4 -3
drivers/hwmon/pkgtemp.c
··· 20 20 * 02110-1301 USA. 21 21 */ 22 22 23 + #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 24 + 23 25 #include <linux/module.h> 24 26 #include <linux/init.h> 25 27 #include <linux/slab.h> ··· 305 303 pdev = platform_device_alloc(DRVNAME, cpu); 306 304 if (!pdev) { 307 305 err = -ENOMEM; 308 - printk(KERN_ERR DRVNAME ": Device allocation failed\n"); 306 + pr_err("Device allocation failed\n"); 309 307 goto exit; 310 308 } 311 309 ··· 317 315 318 316 err = platform_device_add(pdev); 319 317 if (err) { 320 - printk(KERN_ERR DRVNAME ": Device addition failed (%d)\n", 321 - err); 318 + pr_err("Device addition failed (%d)\n", err); 322 319 goto exit_device_free; 323 320 } 324 321
+307
drivers/hwmon/sht21.c
··· 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 + */ 46 + struct 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 + */ 60 + static 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 + */ 75 + static 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 + */ 92 + static 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 + */ 110 + static 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 + } 134 + out: 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 + */ 149 + static 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 + */ 170 + static 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 */ 183 + static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, sht21_show_temperature, 184 + NULL, 0); 185 + static SENSOR_DEVICE_ATTR(humidity1_input, S_IRUGO, sht21_show_humidity, 186 + NULL, 0); 187 + 188 + static 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 + 194 + static 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 + */ 207 + static 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 + 245 + fail_remove_sysfs: 246 + sysfs_remove_group(&client->dev.kobj, &sht21_attr_group); 247 + fail_free: 248 + kfree(sht21); 249 + 250 + return err; 251 + } 252 + 253 + /** 254 + * sht21_remove() - remove device 255 + * @client: I2C client device 256 + */ 257 + static 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 */ 269 + static const struct i2c_device_id sht21_id[] = { 270 + { "sht21", 0 }, 271 + { } 272 + }; 273 + MODULE_DEVICE_TABLE(i2c, sht21_id); 274 + 275 + static 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 + */ 288 + static int __init sht21_init(void) 289 + { 290 + return i2c_add_driver(&sht21_driver); 291 + } 292 + module_init(sht21_init); 293 + 294 + /** 295 + * sht21_init() - clean up driver 296 + * 297 + * Called when module is removed. 298 + */ 299 + static void __exit sht21_exit(void) 300 + { 301 + i2c_del_driver(&sht21_driver); 302 + } 303 + module_exit(sht21_exit); 304 + 305 + MODULE_AUTHOR("Urs Fleisch <urs.fleisch@sensirion.com>"); 306 + MODULE_DESCRIPTION("Sensirion SHT21 humidity and temperature sensor driver"); 307 + MODULE_LICENSE("GPL");
+5 -5
drivers/hwmon/sis5595.c
··· 50 50 735 0008 0735 51 51 */ 52 52 53 + #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 54 + 53 55 #include <linux/module.h> 54 56 #include <linux/slab.h> 55 57 #include <linux/ioport.h> ··· 737 735 pdev = platform_device_alloc("sis5595", address); 738 736 if (!pdev) { 739 737 err = -ENOMEM; 740 - printk(KERN_ERR "sis5595: Device allocation failed\n"); 738 + pr_err("Device allocation failed\n"); 741 739 goto exit; 742 740 } 743 741 744 742 err = platform_device_add_resources(pdev, &res, 1); 745 743 if (err) { 746 - printk(KERN_ERR "sis5595: Device resource addition failed " 747 - "(%d)\n", err); 744 + pr_err("Device resource addition failed (%d)\n", err); 748 745 goto exit_device_put; 749 746 } 750 747 751 748 err = platform_device_add(pdev); 752 749 if (err) { 753 - printk(KERN_ERR "sis5595: Device addition failed (%d)\n", 754 - err); 750 + pr_err("Device addition failed (%d)\n", err); 755 751 goto exit_device_put; 756 752 } 757 753
+6 -7
drivers/hwmon/smsc47b397.c
··· 26 26 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 27 27 */ 28 28 29 + #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 30 + 29 31 #include <linux/module.h> 30 32 #include <linux/slab.h> 31 33 #include <linux/ioport.h> ··· 313 311 pdev = platform_device_alloc(DRVNAME, address); 314 312 if (!pdev) { 315 313 err = -ENOMEM; 316 - printk(KERN_ERR DRVNAME ": Device allocation failed\n"); 314 + pr_err("Device allocation failed\n"); 317 315 goto exit; 318 316 } 319 317 320 318 err = platform_device_add_resources(pdev, &res, 1); 321 319 if (err) { 322 - printk(KERN_ERR DRVNAME ": Device resource addition failed " 323 - "(%d)\n", err); 320 + pr_err("Device resource addition failed (%d)\n", err); 324 321 goto exit_device_put; 325 322 } 326 323 327 324 err = platform_device_add(pdev); 328 325 if (err) { 329 - printk(KERN_ERR DRVNAME ": Device addition failed (%d)\n", 330 - err); 326 + pr_err("Device addition failed (%d)\n", err); 331 327 goto exit_device_put; 332 328 } 333 329 ··· 367 367 *addr = (superio_inb(SUPERIO_REG_BASE_MSB) << 8) 368 368 | superio_inb(SUPERIO_REG_BASE_LSB); 369 369 370 - printk(KERN_INFO DRVNAME ": found SMSC %s " 371 - "(base address 0x%04x, revision %u)\n", 370 + pr_info("found SMSC %s (base address 0x%04x, revision %u)\n", 372 371 name, *addr, rev); 373 372 374 373 superio_exit();
+15 -16
drivers/hwmon/smsc47m1.c
··· 26 26 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 27 27 */ 28 28 29 + #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 30 + 29 31 #include <linux/module.h> 30 32 #include <linux/slab.h> 31 33 #include <linux/ioport.h> ··· 437 435 */ 438 436 switch (val) { 439 437 case 0x51: 440 - pr_info(DRVNAME ": Found SMSC LPC47B27x\n"); 438 + pr_info("Found SMSC LPC47B27x\n"); 441 439 sio_data->type = smsc47m1; 442 440 break; 443 441 case 0x59: 444 - pr_info(DRVNAME ": Found SMSC LPC47M10x/LPC47M112/LPC47M13x\n"); 442 + pr_info("Found SMSC LPC47M10x/LPC47M112/LPC47M13x\n"); 445 443 sio_data->type = smsc47m1; 446 444 break; 447 445 case 0x5F: 448 - pr_info(DRVNAME ": Found SMSC LPC47M14x\n"); 446 + pr_info("Found SMSC LPC47M14x\n"); 449 447 sio_data->type = smsc47m1; 450 448 break; 451 449 case 0x60: 452 - pr_info(DRVNAME ": Found SMSC LPC47M15x/LPC47M192/LPC47M997\n"); 450 + pr_info("Found SMSC LPC47M15x/LPC47M192/LPC47M997\n"); 453 451 sio_data->type = smsc47m1; 454 452 break; 455 453 case 0x6B: 456 454 if (superio_inb(SUPERIO_REG_DEVREV) & 0x80) { 457 - pr_debug(DRVNAME ": " 458 - "Found SMSC LPC47M233, unsupported\n"); 455 + pr_debug("Found SMSC LPC47M233, unsupported\n"); 459 456 superio_exit(); 460 457 return -ENODEV; 461 458 } 462 459 463 - pr_info(DRVNAME ": Found SMSC LPC47M292\n"); 460 + pr_info("Found SMSC LPC47M292\n"); 464 461 sio_data->type = smsc47m2; 465 462 break; 466 463 default: ··· 471 470 *addr = (superio_inb(SUPERIO_REG_BASE) << 8) 472 471 | superio_inb(SUPERIO_REG_BASE + 1); 473 472 if (*addr == 0) { 474 - pr_info(DRVNAME ": Device address not set, will not use\n"); 473 + pr_info("Device address not set, will not use\n"); 475 474 superio_exit(); 476 475 return -ENODEV; 477 476 } ··· 480 479 * Compaq Presario S4000NX) */ 481 480 sio_data->activate = superio_inb(SUPERIO_REG_ACT); 482 481 if ((sio_data->activate & 0x01) == 0) { 483 - pr_info(DRVNAME ": Enabling device\n"); 482 + pr_info("Enabling device\n"); 484 483 superio_outb(SUPERIO_REG_ACT, sio_data->activate | 0x01); 485 484 } 486 485 ··· 495 494 superio_enter(); 496 495 superio_select(); 497 496 498 - pr_info(DRVNAME ": Disabling device\n"); 497 + pr_info("Disabling device\n"); 499 498 superio_outb(SUPERIO_REG_ACT, sio_data->activate); 500 499 501 500 superio_exit(); ··· 824 823 pdev = platform_device_alloc(DRVNAME, address); 825 824 if (!pdev) { 826 825 err = -ENOMEM; 827 - printk(KERN_ERR DRVNAME ": Device allocation failed\n"); 826 + pr_err("Device allocation failed\n"); 828 827 goto exit; 829 828 } 830 829 831 830 err = platform_device_add_resources(pdev, &res, 1); 832 831 if (err) { 833 - printk(KERN_ERR DRVNAME ": Device resource addition failed " 834 - "(%d)\n", err); 832 + pr_err("Device resource addition failed (%d)\n", err); 835 833 goto exit_device_put; 836 834 } 837 835 838 836 err = platform_device_add_data(pdev, sio_data, 839 837 sizeof(struct smsc47m1_sio_data)); 840 838 if (err) { 841 - printk(KERN_ERR DRVNAME ": Platform data allocation failed\n"); 839 + pr_err("Platform data allocation failed\n"); 842 840 goto exit_device_put; 843 841 } 844 842 845 843 err = platform_device_add(pdev); 846 844 if (err) { 847 - printk(KERN_ERR DRVNAME ": Device addition failed (%d)\n", 848 - err); 845 + pr_err("Device addition failed (%d)\n", err); 849 846 goto exit_device_put; 850 847 } 851 848
+16 -19
drivers/hwmon/via-cputemp.c
··· 21 21 * 02110-1301 USA. 22 22 */ 23 23 24 + #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 25 + 24 26 #include <linux/module.h> 25 27 #include <linux/init.h> 26 28 #include <linux/slab.h> ··· 204 202 pdev = platform_device_alloc(DRVNAME, cpu); 205 203 if (!pdev) { 206 204 err = -ENOMEM; 207 - printk(KERN_ERR DRVNAME ": Device allocation failed\n"); 205 + pr_err("Device allocation failed\n"); 208 206 goto exit; 209 207 } 210 208 ··· 216 214 217 215 err = platform_device_add(pdev); 218 216 if (err) { 219 - printk(KERN_ERR DRVNAME ": Device addition failed (%d)\n", 220 - err); 217 + pr_err("Device addition failed (%d)\n", err); 221 218 goto exit_device_free; 222 219 } 223 220 ··· 238 237 239 238 static void __cpuinit via_cputemp_device_remove(unsigned int cpu) 240 239 { 241 - struct pdev_entry *p, *n; 240 + struct pdev_entry *p; 241 + 242 242 mutex_lock(&pdev_list_mutex); 243 - list_for_each_entry_safe(p, n, &pdev_list, list) { 243 + list_for_each_entry(p, &pdev_list, list) { 244 244 if (p->cpu == cpu) { 245 245 platform_device_unregister(p->pdev); 246 246 list_del(&p->list); 247 + mutex_unlock(&pdev_list_mutex); 247 248 kfree(p); 249 + return; 248 250 } 249 251 } 250 252 mutex_unlock(&pdev_list_mutex); ··· 277 273 static int __init via_cputemp_init(void) 278 274 { 279 275 int i, err; 280 - struct pdev_entry *p, *n; 281 276 282 277 if (cpu_data(0).x86_vendor != X86_VENDOR_CENTAUR) { 283 278 printk(KERN_DEBUG DRVNAME ": Not a VIA CPU\n"); ··· 298 295 continue; 299 296 300 297 if (c->x86_model > 0x0f) { 301 - printk(KERN_WARNING DRVNAME ": Unknown CPU " 302 - "model 0x%x\n", c->x86_model); 298 + pr_warn("Unknown CPU model 0x%x\n", c->x86_model); 303 299 continue; 304 300 } 305 301 306 - err = via_cputemp_device_add(i); 307 - if (err) 308 - goto exit_devices_unreg; 302 + via_cputemp_device_add(i); 309 303 } 304 + 305 + #ifndef CONFIG_HOTPLUG_CPU 310 306 if (list_empty(&pdev_list)) { 311 307 err = -ENODEV; 312 308 goto exit_driver_unreg; 313 309 } 310 + #endif 314 311 315 312 register_hotcpu_notifier(&via_cputemp_cpu_notifier); 316 313 return 0; 317 314 318 - exit_devices_unreg: 319 - mutex_lock(&pdev_list_mutex); 320 - list_for_each_entry_safe(p, n, &pdev_list, list) { 321 - platform_device_unregister(p->pdev); 322 - list_del(&p->list); 323 - kfree(p); 324 - } 325 - mutex_unlock(&pdev_list_mutex); 315 + #ifndef CONFIG_HOTPLUG_CPU 326 316 exit_driver_unreg: 327 317 platform_driver_unregister(&via_cputemp_driver); 318 + #endif 328 319 exit: 329 320 return err; 330 321 }
+5 -5
drivers/hwmon/via686a.c
··· 30 30 Warning - only supports a single device. 31 31 */ 32 32 33 + #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 34 + 33 35 #include <linux/module.h> 34 36 #include <linux/slab.h> 35 37 #include <linux/pci.h> ··· 793 791 pdev = platform_device_alloc("via686a", address); 794 792 if (!pdev) { 795 793 err = -ENOMEM; 796 - printk(KERN_ERR "via686a: Device allocation failed\n"); 794 + pr_err("Device allocation failed\n"); 797 795 goto exit; 798 796 } 799 797 800 798 err = platform_device_add_resources(pdev, &res, 1); 801 799 if (err) { 802 - printk(KERN_ERR "via686a: Device resource addition failed " 803 - "(%d)\n", err); 800 + pr_err("Device resource addition failed (%d)\n", err); 804 801 goto exit_device_put; 805 802 } 806 803 807 804 err = platform_device_add(pdev); 808 805 if (err) { 809 - printk(KERN_ERR "via686a: Device addition failed (%d)\n", 810 - err); 806 + pr_err("Device addition failed (%d)\n", err); 811 807 goto exit_device_put; 812 808 } 813 809
+13 -17
drivers/hwmon/vt1211.c
··· 21 21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 22 22 */ 23 23 24 + #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 25 + 24 26 #include <linux/module.h> 25 27 #include <linux/init.h> 26 28 #include <linux/slab.h> ··· 1256 1254 pdev = platform_device_alloc(DRVNAME, address); 1257 1255 if (!pdev) { 1258 1256 err = -ENOMEM; 1259 - printk(KERN_ERR DRVNAME ": Device allocation failed (%d)\n", 1260 - err); 1257 + pr_err("Device allocation failed (%d)\n", err); 1261 1258 goto EXIT; 1262 1259 } 1263 1260 ··· 1267 1266 1268 1267 err = platform_device_add_resources(pdev, &res, 1); 1269 1268 if (err) { 1270 - printk(KERN_ERR DRVNAME ": Device resource addition failed " 1271 - "(%d)\n", err); 1269 + pr_err("Device resource addition failed (%d)\n", err); 1272 1270 goto EXIT_DEV_PUT; 1273 1271 } 1274 1272 1275 1273 err = platform_device_add(pdev); 1276 1274 if (err) { 1277 - printk(KERN_ERR DRVNAME ": Device addition failed (%d)\n", 1278 - err); 1275 + pr_err("Device addition failed (%d)\n", err); 1279 1276 goto EXIT_DEV_PUT; 1280 1277 } 1281 1278 ··· 1300 1301 superio_select(sio_cip, SIO_VT1211_LDN_HWMON); 1301 1302 1302 1303 if ((superio_inb(sio_cip, SIO_VT1211_ACTIVE) & 1) == 0) { 1303 - printk(KERN_WARNING DRVNAME ": HW monitor is disabled, " 1304 - "skipping\n"); 1304 + pr_warn("HW monitor is disabled, skipping\n"); 1305 1305 goto EXIT; 1306 1306 } 1307 1307 1308 1308 *address = ((superio_inb(sio_cip, SIO_VT1211_BADDR) << 8) | 1309 1309 (superio_inb(sio_cip, SIO_VT1211_BADDR + 1))) & 0xff00; 1310 1310 if (*address == 0) { 1311 - printk(KERN_WARNING DRVNAME ": Base address is not set, " 1312 - "skipping\n"); 1311 + pr_warn("Base address is not set, skipping\n"); 1313 1312 goto EXIT; 1314 1313 } 1315 1314 1316 1315 err = 0; 1317 - printk(KERN_INFO DRVNAME ": Found VT1211 chip at 0x%04x, " 1318 - "revision %u\n", *address, 1319 - superio_inb(sio_cip, SIO_VT1211_DEVREV)); 1316 + pr_info("Found VT1211 chip at 0x%04x, revision %u\n", 1317 + *address, superio_inb(sio_cip, SIO_VT1211_DEVREV)); 1320 1318 1321 1319 EXIT: 1322 1320 superio_exit(sio_cip); ··· 1332 1336 1333 1337 if ((uch_config < -1) || (uch_config > 31)) { 1334 1338 err = -EINVAL; 1335 - printk(KERN_WARNING DRVNAME ": Invalid UCH configuration %d. " 1336 - "Choose a value between 0 and 31.\n", uch_config); 1339 + pr_warn("Invalid UCH configuration %d. " 1340 + "Choose a value between 0 and 31.\n", uch_config); 1337 1341 goto EXIT; 1338 1342 } 1339 1343 1340 1344 if ((int_mode < -1) || (int_mode > 0)) { 1341 1345 err = -EINVAL; 1342 - printk(KERN_WARNING DRVNAME ": Invalid interrupt mode %d. " 1343 - "Only mode 0 is supported.\n", int_mode); 1346 + pr_warn("Invalid interrupt mode %d. " 1347 + "Only mode 0 is supported.\n", int_mode); 1344 1348 goto EXIT; 1345 1349 } 1346 1350
+5 -5
drivers/hwmon/vt8231.c
··· 24 24 /* Supports VIA VT8231 South Bridge embedded sensors 25 25 */ 26 26 27 + #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 28 + 27 29 #include <linux/module.h> 28 30 #include <linux/init.h> 29 31 #include <linux/slab.h> ··· 904 902 pdev = platform_device_alloc("vt8231", address); 905 903 if (!pdev) { 906 904 err = -ENOMEM; 907 - printk(KERN_ERR "vt8231: Device allocation failed\n"); 905 + pr_err("Device allocation failed\n"); 908 906 goto exit; 909 907 } 910 908 911 909 err = platform_device_add_resources(pdev, &res, 1); 912 910 if (err) { 913 - printk(KERN_ERR "vt8231: Device resource addition failed " 914 - "(%d)\n", err); 911 + pr_err("Device resource addition failed (%d)\n", err); 915 912 goto exit_device_put; 916 913 } 917 914 918 915 err = platform_device_add(pdev); 919 916 if (err) { 920 - printk(KERN_ERR "vt8231: Device addition failed (%d)\n", 921 - err); 917 + pr_err("Device addition failed (%d)\n", err); 922 918 goto exit_device_put; 923 919 } 924 920
+10 -13
drivers/hwmon/w83627ehf.c
··· 42 42 w83667hg-b 9 5 3 3 0xb350 0xc1 0x5ca3 43 43 */ 44 44 45 + #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 46 + 45 47 #include <linux/module.h> 46 48 #include <linux/init.h> 47 49 #include <linux/slab.h> ··· 1670 1668 break; 1671 1669 default: 1672 1670 if (val != 0xffff) 1673 - pr_debug(DRVNAME ": unsupported chip ID: 0x%04x\n", 1674 - val); 1671 + pr_debug("unsupported chip ID: 0x%04x\n", val); 1675 1672 superio_exit(sioaddr); 1676 1673 return -ENODEV; 1677 1674 } ··· 1681 1680 | superio_inb(sioaddr, SIO_REG_ADDR + 1); 1682 1681 *addr = val & IOREGION_ALIGNMENT; 1683 1682 if (*addr == 0) { 1684 - printk(KERN_ERR DRVNAME ": Refusing to enable a Super-I/O " 1685 - "device with a base I/O port 0.\n"); 1683 + pr_err("Refusing to enable a Super-I/O device with a base I/O port 0\n"); 1686 1684 superio_exit(sioaddr); 1687 1685 return -ENODEV; 1688 1686 } ··· 1689 1689 /* Activate logical device if needed */ 1690 1690 val = superio_inb(sioaddr, SIO_REG_ENABLE); 1691 1691 if (!(val & 0x01)) { 1692 - printk(KERN_WARNING DRVNAME ": Forcibly enabling Super-I/O. " 1693 - "Sensor is probably unusable.\n"); 1692 + pr_warn("Forcibly enabling Super-I/O. Sensor is probably unusable.\n"); 1694 1693 superio_outb(sioaddr, SIO_REG_ENABLE, val | 0x01); 1695 1694 } 1696 1695 1697 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 1698 sio_data->sioreg = sioaddr; 1700 1699 1701 1700 return 0; ··· 1728 1729 1729 1730 if (!(pdev = platform_device_alloc(DRVNAME, address))) { 1730 1731 err = -ENOMEM; 1731 - printk(KERN_ERR DRVNAME ": Device allocation failed\n"); 1732 + pr_err("Device allocation failed\n"); 1732 1733 goto exit_unregister; 1733 1734 } 1734 1735 1735 1736 err = platform_device_add_data(pdev, &sio_data, 1736 1737 sizeof(struct w83627ehf_sio_data)); 1737 1738 if (err) { 1738 - printk(KERN_ERR DRVNAME ": Platform data allocation failed\n"); 1739 + pr_err("Platform data allocation failed\n"); 1739 1740 goto exit_device_put; 1740 1741 } 1741 1742 ··· 1751 1752 1752 1753 err = platform_device_add_resources(pdev, &res, 1); 1753 1754 if (err) { 1754 - printk(KERN_ERR DRVNAME ": Device resource addition failed " 1755 - "(%d)\n", err); 1755 + pr_err("Device resource addition failed (%d)\n", err); 1756 1756 goto exit_device_put; 1757 1757 } 1758 1758 1759 1759 /* platform_device_add calls probe() */ 1760 1760 err = platform_device_add(pdev); 1761 1761 if (err) { 1762 - printk(KERN_ERR DRVNAME ": Device addition failed (%d)\n", 1763 - err); 1762 + pr_err("Device addition failed (%d)\n", err); 1764 1763 goto exit_device_put; 1765 1764 } 1766 1765
+8 -9
drivers/hwmon/w83627hf.c
··· 39 39 supported yet. 40 40 */ 41 41 42 + #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 43 + 42 44 #include <linux/module.h> 43 45 #include <linux/init.h> 44 46 #include <linux/slab.h> ··· 1168 1166 superio_inb(sio_data, WINB_BASE_REG + 1); 1169 1167 *addr = val & WINB_ALIGNMENT; 1170 1168 if (*addr == 0) { 1171 - printk(KERN_WARNING DRVNAME ": Base address not set, " 1172 - "skipping\n"); 1169 + pr_warn("Base address not set, skipping\n"); 1173 1170 goto exit; 1174 1171 } 1175 1172 1176 1173 val = superio_inb(sio_data, WINB_ACT_REG); 1177 1174 if (!(val & 0x01)) { 1178 - printk(KERN_WARNING DRVNAME ": Enabling HWM logical device\n"); 1175 + pr_warn("Enabling HWM logical device\n"); 1179 1176 superio_outb(sio_data, WINB_ACT_REG, val | 0x01); 1180 1177 } 1181 1178 ··· 1790 1789 pdev = platform_device_alloc(DRVNAME, address); 1791 1790 if (!pdev) { 1792 1791 err = -ENOMEM; 1793 - printk(KERN_ERR DRVNAME ": Device allocation failed\n"); 1792 + pr_err("Device allocation failed\n"); 1794 1793 goto exit; 1795 1794 } 1796 1795 1797 1796 err = platform_device_add_resources(pdev, &res, 1); 1798 1797 if (err) { 1799 - printk(KERN_ERR DRVNAME ": Device resource addition failed " 1800 - "(%d)\n", err); 1798 + pr_err("Device resource addition failed (%d)\n", err); 1801 1799 goto exit_device_put; 1802 1800 } 1803 1801 1804 1802 err = platform_device_add_data(pdev, sio_data, 1805 1803 sizeof(struct w83627hf_sio_data)); 1806 1804 if (err) { 1807 - printk(KERN_ERR DRVNAME ": Platform data allocation failed\n"); 1805 + pr_err("Platform data allocation failed\n"); 1808 1806 goto exit_device_put; 1809 1807 } 1810 1808 1811 1809 err = platform_device_add(pdev); 1812 1810 if (err) { 1813 - printk(KERN_ERR DRVNAME ": Device addition failed (%d)\n", 1814 - err); 1811 + pr_err("Device addition failed (%d)\n", err); 1815 1812 goto exit_device_put; 1816 1813 } 1817 1814
+21
include/linux/i2c/ds620.h
··· 1 + #ifndef _LINUX_DS620_H 2 + #define _LINUX_DS620_H 3 + 4 + #include <linux/types.h> 5 + #include <linux/i2c.h> 6 + 7 + /* platform data for the DS620 temperature sensor and thermostat */ 8 + 9 + struct ds620_platform_data { 10 + /* 11 + * Thermostat output pin PO mode: 12 + * 0 = always low (default) 13 + * 1 = PO_LOW 14 + * 2 = PO_HIGH 15 + * 16 + * (see Documentation/hwmon/ds620) 17 + */ 18 + int pomode; 19 + }; 20 + 21 + #endif /* _LINUX_DS620_H */