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