aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/hwmon')
-rw-r--r--drivers/hwmon/Kconfig16
-rw-r--r--drivers/hwmon/Makefile2
-rw-r--r--drivers/hwmon/abituguru3.c3
-rw-r--r--drivers/hwmon/ad7414.c2
-rw-r--r--drivers/hwmon/ams/ams.h2
-rw-r--r--drivers/hwmon/atxp1.c18
-rw-r--r--drivers/hwmon/dme1737.c320
-rw-r--r--drivers/hwmon/hwmon.c4
-rw-r--r--drivers/hwmon/it87.c74
-rw-r--r--drivers/hwmon/max1111.c244
-rw-r--r--drivers/hwmon/ultra45_env.c320
11 files changed, 803 insertions, 202 deletions
diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index d402e8d813ce..ebacc0af40fe 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -540,6 +540,15 @@ config SENSORS_LM93
540 This driver can also be built as a module. If so, the module 540 This driver can also be built as a module. If so, the module
541 will be called lm93. 541 will be called lm93.
542 542
543config SENSORS_MAX1111
544 tristate "Maxim MAX1111 Multichannel, Serial 8-bit ADC chip"
545 depends on SPI_MASTER
546 help
547 Say y here to support Maxim's MAX1111 ADC chips.
548
549 This driver can also be built as a module. If so, the module
550 will be called max1111.
551
543config SENSORS_MAX1619 552config SENSORS_MAX1619
544 tristate "Maxim MAX1619 sensor chip" 553 tristate "Maxim MAX1619 sensor chip"
545 depends on I2C 554 depends on I2C
@@ -791,6 +800,13 @@ config SENSORS_W83627EHF
791 This driver can also be built as a module. If so, the module 800 This driver can also be built as a module. If so, the module
792 will be called w83627ehf. 801 will be called w83627ehf.
793 802
803config SENSORS_ULTRA45
804 tristate "Sun Ultra45 PIC16F747"
805 depends on SPARC64
806 help
807 This driver provides support for the Ultra45 workstation environmental
808 sensors.
809
794config SENSORS_HDAPS 810config SENSORS_HDAPS
795 tristate "IBM Hard Drive Active Protection System (hdaps)" 811 tristate "IBM Hard Drive Active Protection System (hdaps)"
796 depends on INPUT && X86 812 depends on INPUT && X86
diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
index 950134ab8426..042d5a78622e 100644
--- a/drivers/hwmon/Makefile
+++ b/drivers/hwmon/Makefile
@@ -41,6 +41,7 @@ obj-$(CONFIG_SENSORS_FSCHMD) += fschmd.o
41obj-$(CONFIG_SENSORS_FSCPOS) += fscpos.o 41obj-$(CONFIG_SENSORS_FSCPOS) += fscpos.o
42obj-$(CONFIG_SENSORS_GL518SM) += gl518sm.o 42obj-$(CONFIG_SENSORS_GL518SM) += gl518sm.o
43obj-$(CONFIG_SENSORS_GL520SM) += gl520sm.o 43obj-$(CONFIG_SENSORS_GL520SM) += gl520sm.o
44obj-$(CONFIG_SENSORS_ULTRA45) += ultra45_env.o
44obj-$(CONFIG_SENSORS_HDAPS) += hdaps.o 45obj-$(CONFIG_SENSORS_HDAPS) += hdaps.o
45obj-$(CONFIG_SENSORS_I5K_AMB) += i5k_amb.o 46obj-$(CONFIG_SENSORS_I5K_AMB) += i5k_amb.o
46obj-$(CONFIG_SENSORS_IBMAEM) += ibmaem.o 47obj-$(CONFIG_SENSORS_IBMAEM) += ibmaem.o
@@ -59,6 +60,7 @@ obj-$(CONFIG_SENSORS_LM87) += lm87.o
59obj-$(CONFIG_SENSORS_LM90) += lm90.o 60obj-$(CONFIG_SENSORS_LM90) += lm90.o
60obj-$(CONFIG_SENSORS_LM92) += lm92.o 61obj-$(CONFIG_SENSORS_LM92) += lm92.o
61obj-$(CONFIG_SENSORS_LM93) += lm93.o 62obj-$(CONFIG_SENSORS_LM93) += lm93.o
63obj-$(CONFIG_SENSORS_MAX1111) += max1111.o
62obj-$(CONFIG_SENSORS_MAX1619) += max1619.o 64obj-$(CONFIG_SENSORS_MAX1619) += max1619.o
63obj-$(CONFIG_SENSORS_MAX6650) += max6650.o 65obj-$(CONFIG_SENSORS_MAX6650) += max6650.o
64obj-$(CONFIG_SENSORS_PC87360) += pc87360.o 66obj-$(CONFIG_SENSORS_PC87360) += pc87360.o
diff --git a/drivers/hwmon/abituguru3.c b/drivers/hwmon/abituguru3.c
index d568c65c1370..d9e7a49d6cbf 100644
--- a/drivers/hwmon/abituguru3.c
+++ b/drivers/hwmon/abituguru3.c
@@ -279,7 +279,7 @@ static const struct abituguru3_motherboard_info abituguru3_motherboards[] = {
279 { "OTES1 Fan", 36, 2, 60, 1, 0 }, 279 { "OTES1 Fan", 36, 2, 60, 1, 0 },
280 { NULL, 0, 0, 0, 0, 0 } } 280 { NULL, 0, 0, 0, 0, 0 } }
281 }, 281 },
282 { 0x0011, NULL /* Abit AT8 32X, need DMI string */, { 282 { 0x0011, "AT8 32X(ATI RD580-ULI M1575)", {
283 { "CPU Core", 0, 0, 10, 1, 0 }, 283 { "CPU Core", 0, 0, 10, 1, 0 },
284 { "DDR", 1, 0, 20, 1, 0 }, 284 { "DDR", 1, 0, 20, 1, 0 },
285 { "DDR VTT", 2, 0, 10, 1, 0 }, 285 { "DDR VTT", 2, 0, 10, 1, 0 },
@@ -303,6 +303,7 @@ static const struct abituguru3_motherboard_info abituguru3_motherboards[] = {
303 { "SYS Fan", 34, 2, 60, 1, 0 }, 303 { "SYS Fan", 34, 2, 60, 1, 0 },
304 { "AUX1 Fan", 35, 2, 60, 1, 0 }, 304 { "AUX1 Fan", 35, 2, 60, 1, 0 },
305 { "AUX2 Fan", 36, 2, 60, 1, 0 }, 305 { "AUX2 Fan", 36, 2, 60, 1, 0 },
306 { "AUX3 Fan", 37, 2, 60, 1, 0 },
306 { NULL, 0, 0, 0, 0, 0 } } 307 { NULL, 0, 0, 0, 0, 0 } }
307 }, 308 },
308 { 0x0012, NULL /* Abit AN8 32X, need DMI string */, { 309 { 0x0012, NULL /* Abit AN8 32X, need DMI string */, {
diff --git a/drivers/hwmon/ad7414.c b/drivers/hwmon/ad7414.c
index ce8d94fbfd7e..bfda8c80ef24 100644
--- a/drivers/hwmon/ad7414.c
+++ b/drivers/hwmon/ad7414.c
@@ -69,7 +69,7 @@ static inline int ad7414_write(struct i2c_client *client, u8 reg, u8 value)
69 return i2c_smbus_write_byte_data(client, reg, value); 69 return i2c_smbus_write_byte_data(client, reg, value);
70} 70}
71 71
72struct ad7414_data *ad7414_update_device(struct device *dev) 72static struct ad7414_data *ad7414_update_device(struct device *dev)
73{ 73{
74 struct i2c_client *client = to_i2c_client(dev); 74 struct i2c_client *client = to_i2c_client(dev);
75 struct ad7414_data *data = i2c_get_clientdata(client); 75 struct ad7414_data *data = i2c_get_clientdata(client);
diff --git a/drivers/hwmon/ams/ams.h b/drivers/hwmon/ams/ams.h
index a6221e5dd984..221ef6915a5f 100644
--- a/drivers/hwmon/ams/ams.h
+++ b/drivers/hwmon/ams/ams.h
@@ -4,7 +4,7 @@
4#include <linux/mutex.h> 4#include <linux/mutex.h>
5#include <linux/spinlock.h> 5#include <linux/spinlock.h>
6#include <linux/types.h> 6#include <linux/types.h>
7#include <asm/of_device.h> 7#include <linux/of_device.h>
8 8
9enum ams_irq { 9enum ams_irq {
10 AMS_IRQ_FREEFALL = 0x01, 10 AMS_IRQ_FREEFALL = 0x01,
diff --git a/drivers/hwmon/atxp1.c b/drivers/hwmon/atxp1.c
index d191118ba0cb..d6b490d3e36f 100644
--- a/drivers/hwmon/atxp1.c
+++ b/drivers/hwmon/atxp1.c
@@ -31,7 +31,7 @@
31 31
32MODULE_LICENSE("GPL"); 32MODULE_LICENSE("GPL");
33MODULE_DESCRIPTION("System voltages control via Attansic ATXP1"); 33MODULE_DESCRIPTION("System voltages control via Attansic ATXP1");
34MODULE_VERSION("0.6.2"); 34MODULE_VERSION("0.6.3");
35MODULE_AUTHOR("Sebastian Witt <se.witt@gmx.net>"); 35MODULE_AUTHOR("Sebastian Witt <se.witt@gmx.net>");
36 36
37#define ATXP1_VID 0x00 37#define ATXP1_VID 0x00
@@ -289,16 +289,16 @@ static int atxp1_detect(struct i2c_client *new_client, int kind,
289 if (!((i2c_smbus_read_byte_data(new_client, 0x3e) == 0) && 289 if (!((i2c_smbus_read_byte_data(new_client, 0x3e) == 0) &&
290 (i2c_smbus_read_byte_data(new_client, 0x3f) == 0) && 290 (i2c_smbus_read_byte_data(new_client, 0x3f) == 0) &&
291 (i2c_smbus_read_byte_data(new_client, 0xfe) == 0) && 291 (i2c_smbus_read_byte_data(new_client, 0xfe) == 0) &&
292 (i2c_smbus_read_byte_data(new_client, 0xff) == 0) )) { 292 (i2c_smbus_read_byte_data(new_client, 0xff) == 0)))
293 return -ENODEV;
293 294
294 /* No vendor ID, now checking if registers 0x10,0x11 (non-existent) 295 /* No vendor ID, now checking if registers 0x10,0x11 (non-existent)
295 * showing the same as register 0x00 */ 296 * showing the same as register 0x00 */
296 temp = i2c_smbus_read_byte_data(new_client, 0x00); 297 temp = i2c_smbus_read_byte_data(new_client, 0x00);
297 298
298 if (!((i2c_smbus_read_byte_data(new_client, 0x10) == temp) && 299 if (!((i2c_smbus_read_byte_data(new_client, 0x10) == temp) &&
299 (i2c_smbus_read_byte_data(new_client, 0x11) == temp) )) 300 (i2c_smbus_read_byte_data(new_client, 0x11) == temp)))
300 return -ENODEV; 301 return -ENODEV;
301 }
302 302
303 /* Get VRM */ 303 /* Get VRM */
304 temp = vid_which_vrm(); 304 temp = vid_which_vrm();
diff --git a/drivers/hwmon/dme1737.c b/drivers/hwmon/dme1737.c
index cdb8311e4ef7..27a5d397f9a1 100644
--- a/drivers/hwmon/dme1737.c
+++ b/drivers/hwmon/dme1737.c
@@ -175,11 +175,11 @@ static const u8 DME1737_BIT_ALARM_FAN[] = {10, 11, 12, 13, 22, 23};
175 * Data structures and manipulation thereof 175 * Data structures and manipulation thereof
176 * --------------------------------------------------------------------- */ 176 * --------------------------------------------------------------------- */
177 177
178/* For ISA chips, we abuse the i2c_client addr and name fields. We also use
179 the driver field to differentiate between I2C and ISA chips. */
180struct dme1737_data { 178struct dme1737_data {
181 struct i2c_client client; 179 struct i2c_client *client; /* for I2C devices only */
182 struct device *hwmon_dev; 180 struct device *hwmon_dev;
181 const char *name;
182 unsigned int addr; /* for ISA devices only */
183 183
184 struct mutex update_lock; 184 struct mutex update_lock;
185 int valid; /* !=0 if following fields are valid */ 185 int valid; /* !=0 if following fields are valid */
@@ -512,11 +512,12 @@ static inline int PWM_OFF_TO_REG(int val, int ix, int reg)
512 * before calling dme1737_read or dme1737_write. 512 * before calling dme1737_read or dme1737_write.
513 * --------------------------------------------------------------------- */ 513 * --------------------------------------------------------------------- */
514 514
515static u8 dme1737_read(struct i2c_client *client, u8 reg) 515static u8 dme1737_read(const struct dme1737_data *data, u8 reg)
516{ 516{
517 struct i2c_client *client = data->client;
517 s32 val; 518 s32 val;
518 519
519 if (client->driver) { /* I2C device */ 520 if (client) { /* I2C device */
520 val = i2c_smbus_read_byte_data(client, reg); 521 val = i2c_smbus_read_byte_data(client, reg);
521 522
522 if (val < 0) { 523 if (val < 0) {
@@ -525,18 +526,19 @@ static u8 dme1737_read(struct i2c_client *client, u8 reg)
525 "maintainer.\n", reg); 526 "maintainer.\n", reg);
526 } 527 }
527 } else { /* ISA device */ 528 } else { /* ISA device */
528 outb(reg, client->addr); 529 outb(reg, data->addr);
529 val = inb(client->addr + 1); 530 val = inb(data->addr + 1);
530 } 531 }
531 532
532 return val; 533 return val;
533} 534}
534 535
535static s32 dme1737_write(struct i2c_client *client, u8 reg, u8 val) 536static s32 dme1737_write(const struct dme1737_data *data, u8 reg, u8 val)
536{ 537{
538 struct i2c_client *client = data->client;
537 s32 res = 0; 539 s32 res = 0;
538 540
539 if (client->driver) { /* I2C device */ 541 if (client) { /* I2C device */
540 res = i2c_smbus_write_byte_data(client, reg, val); 542 res = i2c_smbus_write_byte_data(client, reg, val);
541 543
542 if (res < 0) { 544 if (res < 0) {
@@ -545,8 +547,8 @@ static s32 dme1737_write(struct i2c_client *client, u8 reg, u8 val)
545 "maintainer.\n", reg); 547 "maintainer.\n", reg);
546 } 548 }
547 } else { /* ISA device */ 549 } else { /* ISA device */
548 outb(reg, client->addr); 550 outb(reg, data->addr);
549 outb(val, client->addr + 1); 551 outb(val, data->addr + 1);
550 } 552 }
551 553
552 return res; 554 return res;
@@ -555,7 +557,6 @@ static s32 dme1737_write(struct i2c_client *client, u8 reg, u8 val)
555static struct dme1737_data *dme1737_update_device(struct device *dev) 557static struct dme1737_data *dme1737_update_device(struct device *dev)
556{ 558{
557 struct dme1737_data *data = dev_get_drvdata(dev); 559 struct dme1737_data *data = dev_get_drvdata(dev);
558 struct i2c_client *client = &data->client;
559 int ix; 560 int ix;
560 u8 lsb[5]; 561 u8 lsb[5];
561 562
@@ -563,7 +564,7 @@ static struct dme1737_data *dme1737_update_device(struct device *dev)
563 564
564 /* Enable a Vbat monitoring cycle every 10 mins */ 565 /* Enable a Vbat monitoring cycle every 10 mins */
565 if (time_after(jiffies, data->last_vbat + 600 * HZ) || !data->valid) { 566 if (time_after(jiffies, data->last_vbat + 600 * HZ) || !data->valid) {
566 dme1737_write(client, DME1737_REG_CONFIG, dme1737_read(client, 567 dme1737_write(data, DME1737_REG_CONFIG, dme1737_read(data,
567 DME1737_REG_CONFIG) | 0x10); 568 DME1737_REG_CONFIG) | 0x10);
568 data->last_vbat = jiffies; 569 data->last_vbat = jiffies;
569 } 570 }
@@ -571,7 +572,7 @@ static struct dme1737_data *dme1737_update_device(struct device *dev)
571 /* Sample register contents every 1 sec */ 572 /* Sample register contents every 1 sec */
572 if (time_after(jiffies, data->last_update + HZ) || !data->valid) { 573 if (time_after(jiffies, data->last_update + HZ) || !data->valid) {
573 if (data->type != sch5027) { 574 if (data->type != sch5027) {
574 data->vid = dme1737_read(client, DME1737_REG_VID) & 575 data->vid = dme1737_read(data, DME1737_REG_VID) &
575 0x3f; 576 0x3f;
576 } 577 }
577 578
@@ -580,11 +581,11 @@ static struct dme1737_data *dme1737_update_device(struct device *dev)
580 /* Voltage inputs are stored as 16 bit values even 581 /* Voltage inputs are stored as 16 bit values even
581 * though they have only 12 bits resolution. This is 582 * though they have only 12 bits resolution. This is
582 * to make it consistent with the temp inputs. */ 583 * to make it consistent with the temp inputs. */
583 data->in[ix] = dme1737_read(client, 584 data->in[ix] = dme1737_read(data,
584 DME1737_REG_IN(ix)) << 8; 585 DME1737_REG_IN(ix)) << 8;
585 data->in_min[ix] = dme1737_read(client, 586 data->in_min[ix] = dme1737_read(data,
586 DME1737_REG_IN_MIN(ix)); 587 DME1737_REG_IN_MIN(ix));
587 data->in_max[ix] = dme1737_read(client, 588 data->in_max[ix] = dme1737_read(data,
588 DME1737_REG_IN_MAX(ix)); 589 DME1737_REG_IN_MAX(ix));
589 } 590 }
590 591
@@ -595,14 +596,14 @@ static struct dme1737_data *dme1737_update_device(struct device *dev)
595 * to take advantage of implicit conversions between 596 * to take advantage of implicit conversions between
596 * register values (2's complement) and temp values 597 * register values (2's complement) and temp values
597 * (signed decimal). */ 598 * (signed decimal). */
598 data->temp[ix] = dme1737_read(client, 599 data->temp[ix] = dme1737_read(data,
599 DME1737_REG_TEMP(ix)) << 8; 600 DME1737_REG_TEMP(ix)) << 8;
600 data->temp_min[ix] = dme1737_read(client, 601 data->temp_min[ix] = dme1737_read(data,
601 DME1737_REG_TEMP_MIN(ix)); 602 DME1737_REG_TEMP_MIN(ix));
602 data->temp_max[ix] = dme1737_read(client, 603 data->temp_max[ix] = dme1737_read(data,
603 DME1737_REG_TEMP_MAX(ix)); 604 DME1737_REG_TEMP_MAX(ix));
604 if (data->type != sch5027) { 605 if (data->type != sch5027) {
605 data->temp_offset[ix] = dme1737_read(client, 606 data->temp_offset[ix] = dme1737_read(data,
606 DME1737_REG_TEMP_OFFSET(ix)); 607 DME1737_REG_TEMP_OFFSET(ix));
607 } 608 }
608 } 609 }
@@ -612,7 +613,7 @@ static struct dme1737_data *dme1737_update_device(struct device *dev)
612 * which the registers are read (MSB first, then LSB) is 613 * which the registers are read (MSB first, then LSB) is
613 * important! */ 614 * important! */
614 for (ix = 0; ix < ARRAY_SIZE(lsb); ix++) { 615 for (ix = 0; ix < ARRAY_SIZE(lsb); ix++) {
615 lsb[ix] = dme1737_read(client, 616 lsb[ix] = dme1737_read(data,
616 DME1737_REG_IN_TEMP_LSB(ix)); 617 DME1737_REG_IN_TEMP_LSB(ix));
617 } 618 }
618 for (ix = 0; ix < ARRAY_SIZE(data->in); ix++) { 619 for (ix = 0; ix < ARRAY_SIZE(data->in); ix++) {
@@ -631,19 +632,19 @@ static struct dme1737_data *dme1737_update_device(struct device *dev)
631 if (!(data->has_fan & (1 << ix))) { 632 if (!(data->has_fan & (1 << ix))) {
632 continue; 633 continue;
633 } 634 }
634 data->fan[ix] = dme1737_read(client, 635 data->fan[ix] = dme1737_read(data,
635 DME1737_REG_FAN(ix)); 636 DME1737_REG_FAN(ix));
636 data->fan[ix] |= dme1737_read(client, 637 data->fan[ix] |= dme1737_read(data,
637 DME1737_REG_FAN(ix) + 1) << 8; 638 DME1737_REG_FAN(ix) + 1) << 8;
638 data->fan_min[ix] = dme1737_read(client, 639 data->fan_min[ix] = dme1737_read(data,
639 DME1737_REG_FAN_MIN(ix)); 640 DME1737_REG_FAN_MIN(ix));
640 data->fan_min[ix] |= dme1737_read(client, 641 data->fan_min[ix] |= dme1737_read(data,
641 DME1737_REG_FAN_MIN(ix) + 1) << 8; 642 DME1737_REG_FAN_MIN(ix) + 1) << 8;
642 data->fan_opt[ix] = dme1737_read(client, 643 data->fan_opt[ix] = dme1737_read(data,
643 DME1737_REG_FAN_OPT(ix)); 644 DME1737_REG_FAN_OPT(ix));
644 /* fan_max exists only for fan[5-6] */ 645 /* fan_max exists only for fan[5-6] */
645 if (ix > 3) { 646 if (ix > 3) {
646 data->fan_max[ix - 4] = dme1737_read(client, 647 data->fan_max[ix - 4] = dme1737_read(data,
647 DME1737_REG_FAN_MAX(ix)); 648 DME1737_REG_FAN_MAX(ix));
648 } 649 }
649 } 650 }
@@ -655,63 +656,63 @@ static struct dme1737_data *dme1737_update_device(struct device *dev)
655 if (!(data->has_pwm & (1 << ix))) { 656 if (!(data->has_pwm & (1 << ix))) {
656 continue; 657 continue;
657 } 658 }
658 data->pwm[ix] = dme1737_read(client, 659 data->pwm[ix] = dme1737_read(data,
659 DME1737_REG_PWM(ix)); 660 DME1737_REG_PWM(ix));
660 data->pwm_freq[ix] = dme1737_read(client, 661 data->pwm_freq[ix] = dme1737_read(data,
661 DME1737_REG_PWM_FREQ(ix)); 662 DME1737_REG_PWM_FREQ(ix));
662 /* pwm_config and pwm_min exist only for pwm[1-3] */ 663 /* pwm_config and pwm_min exist only for pwm[1-3] */
663 if (ix < 3) { 664 if (ix < 3) {
664 data->pwm_config[ix] = dme1737_read(client, 665 data->pwm_config[ix] = dme1737_read(data,
665 DME1737_REG_PWM_CONFIG(ix)); 666 DME1737_REG_PWM_CONFIG(ix));
666 data->pwm_min[ix] = dme1737_read(client, 667 data->pwm_min[ix] = dme1737_read(data,
667 DME1737_REG_PWM_MIN(ix)); 668 DME1737_REG_PWM_MIN(ix));
668 } 669 }
669 } 670 }
670 for (ix = 0; ix < ARRAY_SIZE(data->pwm_rr); ix++) { 671 for (ix = 0; ix < ARRAY_SIZE(data->pwm_rr); ix++) {
671 data->pwm_rr[ix] = dme1737_read(client, 672 data->pwm_rr[ix] = dme1737_read(data,
672 DME1737_REG_PWM_RR(ix)); 673 DME1737_REG_PWM_RR(ix));
673 } 674 }
674 675
675 /* Thermal zone registers */ 676 /* Thermal zone registers */
676 for (ix = 0; ix < ARRAY_SIZE(data->zone_low); ix++) { 677 for (ix = 0; ix < ARRAY_SIZE(data->zone_low); ix++) {
677 data->zone_low[ix] = dme1737_read(client, 678 data->zone_low[ix] = dme1737_read(data,
678 DME1737_REG_ZONE_LOW(ix)); 679 DME1737_REG_ZONE_LOW(ix));
679 data->zone_abs[ix] = dme1737_read(client, 680 data->zone_abs[ix] = dme1737_read(data,
680 DME1737_REG_ZONE_ABS(ix)); 681 DME1737_REG_ZONE_ABS(ix));
681 } 682 }
682 if (data->type != sch5027) { 683 if (data->type != sch5027) {
683 for (ix = 0; ix < ARRAY_SIZE(data->zone_hyst); ix++) { 684 for (ix = 0; ix < ARRAY_SIZE(data->zone_hyst); ix++) {
684 data->zone_hyst[ix] = dme1737_read(client, 685 data->zone_hyst[ix] = dme1737_read(data,
685 DME1737_REG_ZONE_HYST(ix)); 686 DME1737_REG_ZONE_HYST(ix));
686 } 687 }
687 } 688 }
688 689
689 /* Alarm registers */ 690 /* Alarm registers */
690 data->alarms = dme1737_read(client, 691 data->alarms = dme1737_read(data,
691 DME1737_REG_ALARM1); 692 DME1737_REG_ALARM1);
692 /* Bit 7 tells us if the other alarm registers are non-zero and 693 /* Bit 7 tells us if the other alarm registers are non-zero and
693 * therefore also need to be read */ 694 * therefore also need to be read */
694 if (data->alarms & 0x80) { 695 if (data->alarms & 0x80) {
695 data->alarms |= dme1737_read(client, 696 data->alarms |= dme1737_read(data,
696 DME1737_REG_ALARM2) << 8; 697 DME1737_REG_ALARM2) << 8;
697 data->alarms |= dme1737_read(client, 698 data->alarms |= dme1737_read(data,
698 DME1737_REG_ALARM3) << 16; 699 DME1737_REG_ALARM3) << 16;
699 } 700 }
700 701
701 /* The ISA chips require explicit clearing of alarm bits. 702 /* The ISA chips require explicit clearing of alarm bits.
702 * Don't worry, an alarm will come back if the condition 703 * Don't worry, an alarm will come back if the condition
703 * that causes it still exists */ 704 * that causes it still exists */
704 if (!client->driver) { 705 if (!data->client) {
705 if (data->alarms & 0xff0000) { 706 if (data->alarms & 0xff0000) {
706 dme1737_write(client, DME1737_REG_ALARM3, 707 dme1737_write(data, DME1737_REG_ALARM3,
707 0xff); 708 0xff);
708 } 709 }
709 if (data->alarms & 0xff00) { 710 if (data->alarms & 0xff00) {
710 dme1737_write(client, DME1737_REG_ALARM2, 711 dme1737_write(data, DME1737_REG_ALARM2,
711 0xff); 712 0xff);
712 } 713 }
713 if (data->alarms & 0xff) { 714 if (data->alarms & 0xff) {
714 dme1737_write(client, DME1737_REG_ALARM1, 715 dme1737_write(data, DME1737_REG_ALARM1,
715 0xff); 716 0xff);
716 } 717 }
717 } 718 }
@@ -770,7 +771,6 @@ static ssize_t set_in(struct device *dev, struct device_attribute *attr,
770 const char *buf, size_t count) 771 const char *buf, size_t count)
771{ 772{
772 struct dme1737_data *data = dev_get_drvdata(dev); 773 struct dme1737_data *data = dev_get_drvdata(dev);
773 struct i2c_client *client = &data->client;
774 struct sensor_device_attribute_2 774 struct sensor_device_attribute_2
775 *sensor_attr_2 = to_sensor_dev_attr_2(attr); 775 *sensor_attr_2 = to_sensor_dev_attr_2(attr);
776 int ix = sensor_attr_2->index; 776 int ix = sensor_attr_2->index;
@@ -781,12 +781,12 @@ static ssize_t set_in(struct device *dev, struct device_attribute *attr,
781 switch (fn) { 781 switch (fn) {
782 case SYS_IN_MIN: 782 case SYS_IN_MIN:
783 data->in_min[ix] = IN_TO_REG(val, data->in_nominal[ix]); 783 data->in_min[ix] = IN_TO_REG(val, data->in_nominal[ix]);
784 dme1737_write(client, DME1737_REG_IN_MIN(ix), 784 dme1737_write(data, DME1737_REG_IN_MIN(ix),
785 data->in_min[ix]); 785 data->in_min[ix]);
786 break; 786 break;
787 case SYS_IN_MAX: 787 case SYS_IN_MAX:
788 data->in_max[ix] = IN_TO_REG(val, data->in_nominal[ix]); 788 data->in_max[ix] = IN_TO_REG(val, data->in_nominal[ix]);
789 dme1737_write(client, DME1737_REG_IN_MAX(ix), 789 dme1737_write(data, DME1737_REG_IN_MAX(ix),
790 data->in_max[ix]); 790 data->in_max[ix]);
791 break; 791 break;
792 default: 792 default:
@@ -850,7 +850,6 @@ static ssize_t set_temp(struct device *dev, struct device_attribute *attr,
850 const char *buf, size_t count) 850 const char *buf, size_t count)
851{ 851{
852 struct dme1737_data *data = dev_get_drvdata(dev); 852 struct dme1737_data *data = dev_get_drvdata(dev);
853 struct i2c_client *client = &data->client;
854 struct sensor_device_attribute_2 853 struct sensor_device_attribute_2
855 *sensor_attr_2 = to_sensor_dev_attr_2(attr); 854 *sensor_attr_2 = to_sensor_dev_attr_2(attr);
856 int ix = sensor_attr_2->index; 855 int ix = sensor_attr_2->index;
@@ -861,17 +860,17 @@ static ssize_t set_temp(struct device *dev, struct device_attribute *attr,
861 switch (fn) { 860 switch (fn) {
862 case SYS_TEMP_MIN: 861 case SYS_TEMP_MIN:
863 data->temp_min[ix] = TEMP_TO_REG(val); 862 data->temp_min[ix] = TEMP_TO_REG(val);
864 dme1737_write(client, DME1737_REG_TEMP_MIN(ix), 863 dme1737_write(data, DME1737_REG_TEMP_MIN(ix),
865 data->temp_min[ix]); 864 data->temp_min[ix]);
866 break; 865 break;
867 case SYS_TEMP_MAX: 866 case SYS_TEMP_MAX:
868 data->temp_max[ix] = TEMP_TO_REG(val); 867 data->temp_max[ix] = TEMP_TO_REG(val);
869 dme1737_write(client, DME1737_REG_TEMP_MAX(ix), 868 dme1737_write(data, DME1737_REG_TEMP_MAX(ix),
870 data->temp_max[ix]); 869 data->temp_max[ix]);
871 break; 870 break;
872 case SYS_TEMP_OFFSET: 871 case SYS_TEMP_OFFSET:
873 data->temp_offset[ix] = TEMP_TO_REG(val); 872 data->temp_offset[ix] = TEMP_TO_REG(val);
874 dme1737_write(client, DME1737_REG_TEMP_OFFSET(ix), 873 dme1737_write(data, DME1737_REG_TEMP_OFFSET(ix),
875 data->temp_offset[ix]); 874 data->temp_offset[ix]);
876 break; 875 break;
877 default: 876 default:
@@ -939,7 +938,6 @@ static ssize_t set_zone(struct device *dev, struct device_attribute *attr,
939 const char *buf, size_t count) 938 const char *buf, size_t count)
940{ 939{
941 struct dme1737_data *data = dev_get_drvdata(dev); 940 struct dme1737_data *data = dev_get_drvdata(dev);
942 struct i2c_client *client = &data->client;
943 struct sensor_device_attribute_2 941 struct sensor_device_attribute_2
944 *sensor_attr_2 = to_sensor_dev_attr_2(attr); 942 *sensor_attr_2 = to_sensor_dev_attr_2(attr);
945 int ix = sensor_attr_2->index; 943 int ix = sensor_attr_2->index;
@@ -950,37 +948,37 @@ static ssize_t set_zone(struct device *dev, struct device_attribute *attr,
950 switch (fn) { 948 switch (fn) {
951 case SYS_ZONE_AUTO_POINT1_TEMP_HYST: 949 case SYS_ZONE_AUTO_POINT1_TEMP_HYST:
952 /* Refresh the cache */ 950 /* Refresh the cache */
953 data->zone_low[ix] = dme1737_read(client, 951 data->zone_low[ix] = dme1737_read(data,
954 DME1737_REG_ZONE_LOW(ix)); 952 DME1737_REG_ZONE_LOW(ix));
955 /* Modify the temp hyst value */ 953 /* Modify the temp hyst value */
956 data->zone_hyst[ix == 2] = TEMP_HYST_TO_REG( 954 data->zone_hyst[ix == 2] = TEMP_HYST_TO_REG(
957 TEMP_FROM_REG(data->zone_low[ix], 8) - 955 TEMP_FROM_REG(data->zone_low[ix], 8) -
958 val, ix, dme1737_read(client, 956 val, ix, dme1737_read(data,
959 DME1737_REG_ZONE_HYST(ix == 2))); 957 DME1737_REG_ZONE_HYST(ix == 2)));
960 dme1737_write(client, DME1737_REG_ZONE_HYST(ix == 2), 958 dme1737_write(data, DME1737_REG_ZONE_HYST(ix == 2),
961 data->zone_hyst[ix == 2]); 959 data->zone_hyst[ix == 2]);
962 break; 960 break;
963 case SYS_ZONE_AUTO_POINT1_TEMP: 961 case SYS_ZONE_AUTO_POINT1_TEMP:
964 data->zone_low[ix] = TEMP_TO_REG(val); 962 data->zone_low[ix] = TEMP_TO_REG(val);
965 dme1737_write(client, DME1737_REG_ZONE_LOW(ix), 963 dme1737_write(data, DME1737_REG_ZONE_LOW(ix),
966 data->zone_low[ix]); 964 data->zone_low[ix]);
967 break; 965 break;
968 case SYS_ZONE_AUTO_POINT2_TEMP: 966 case SYS_ZONE_AUTO_POINT2_TEMP:
969 /* Refresh the cache */ 967 /* Refresh the cache */
970 data->zone_low[ix] = dme1737_read(client, 968 data->zone_low[ix] = dme1737_read(data,
971 DME1737_REG_ZONE_LOW(ix)); 969 DME1737_REG_ZONE_LOW(ix));
972 /* Modify the temp range value (which is stored in the upper 970 /* Modify the temp range value (which is stored in the upper
973 * nibble of the pwm_freq register) */ 971 * nibble of the pwm_freq register) */
974 data->pwm_freq[ix] = TEMP_RANGE_TO_REG(val - 972 data->pwm_freq[ix] = TEMP_RANGE_TO_REG(val -
975 TEMP_FROM_REG(data->zone_low[ix], 8), 973 TEMP_FROM_REG(data->zone_low[ix], 8),
976 dme1737_read(client, 974 dme1737_read(data,
977 DME1737_REG_PWM_FREQ(ix))); 975 DME1737_REG_PWM_FREQ(ix)));
978 dme1737_write(client, DME1737_REG_PWM_FREQ(ix), 976 dme1737_write(data, DME1737_REG_PWM_FREQ(ix),
979 data->pwm_freq[ix]); 977 data->pwm_freq[ix]);
980 break; 978 break;
981 case SYS_ZONE_AUTO_POINT3_TEMP: 979 case SYS_ZONE_AUTO_POINT3_TEMP:
982 data->zone_abs[ix] = TEMP_TO_REG(val); 980 data->zone_abs[ix] = TEMP_TO_REG(val);
983 dme1737_write(client, DME1737_REG_ZONE_ABS(ix), 981 dme1737_write(data, DME1737_REG_ZONE_ABS(ix),
984 data->zone_abs[ix]); 982 data->zone_abs[ix]);
985 break; 983 break;
986 default: 984 default:
@@ -1046,7 +1044,6 @@ static ssize_t set_fan(struct device *dev, struct device_attribute *attr,
1046 const char *buf, size_t count) 1044 const char *buf, size_t count)
1047{ 1045{
1048 struct dme1737_data *data = dev_get_drvdata(dev); 1046 struct dme1737_data *data = dev_get_drvdata(dev);
1049 struct i2c_client *client = &data->client;
1050 struct sensor_device_attribute_2 1047 struct sensor_device_attribute_2
1051 *sensor_attr_2 = to_sensor_dev_attr_2(attr); 1048 *sensor_attr_2 = to_sensor_dev_attr_2(attr);
1052 int ix = sensor_attr_2->index; 1049 int ix = sensor_attr_2->index;
@@ -1060,21 +1057,21 @@ static ssize_t set_fan(struct device *dev, struct device_attribute *attr,
1060 data->fan_min[ix] = FAN_TO_REG(val, 0); 1057 data->fan_min[ix] = FAN_TO_REG(val, 0);
1061 } else { 1058 } else {
1062 /* Refresh the cache */ 1059 /* Refresh the cache */
1063 data->fan_opt[ix] = dme1737_read(client, 1060 data->fan_opt[ix] = dme1737_read(data,
1064 DME1737_REG_FAN_OPT(ix)); 1061 DME1737_REG_FAN_OPT(ix));
1065 /* Modify the fan min value */ 1062 /* Modify the fan min value */
1066 data->fan_min[ix] = FAN_TO_REG(val, 1063 data->fan_min[ix] = FAN_TO_REG(val,
1067 FAN_TPC_FROM_REG(data->fan_opt[ix])); 1064 FAN_TPC_FROM_REG(data->fan_opt[ix]));
1068 } 1065 }
1069 dme1737_write(client, DME1737_REG_FAN_MIN(ix), 1066 dme1737_write(data, DME1737_REG_FAN_MIN(ix),
1070 data->fan_min[ix] & 0xff); 1067 data->fan_min[ix] & 0xff);
1071 dme1737_write(client, DME1737_REG_FAN_MIN(ix) + 1, 1068 dme1737_write(data, DME1737_REG_FAN_MIN(ix) + 1,
1072 data->fan_min[ix] >> 8); 1069 data->fan_min[ix] >> 8);
1073 break; 1070 break;
1074 case SYS_FAN_MAX: 1071 case SYS_FAN_MAX:
1075 /* Only valid for fan[5-6] */ 1072 /* Only valid for fan[5-6] */
1076 data->fan_max[ix - 4] = FAN_MAX_TO_REG(val); 1073 data->fan_max[ix - 4] = FAN_MAX_TO_REG(val);
1077 dme1737_write(client, DME1737_REG_FAN_MAX(ix), 1074 dme1737_write(data, DME1737_REG_FAN_MAX(ix),
1078 data->fan_max[ix - 4]); 1075 data->fan_max[ix - 4]);
1079 break; 1076 break;
1080 case SYS_FAN_TYPE: 1077 case SYS_FAN_TYPE:
@@ -1086,9 +1083,9 @@ static ssize_t set_fan(struct device *dev, struct device_attribute *attr,
1086 val); 1083 val);
1087 goto exit; 1084 goto exit;
1088 } 1085 }
1089 data->fan_opt[ix] = FAN_TYPE_TO_REG(val, dme1737_read(client, 1086 data->fan_opt[ix] = FAN_TYPE_TO_REG(val, dme1737_read(data,
1090 DME1737_REG_FAN_OPT(ix))); 1087 DME1737_REG_FAN_OPT(ix)));
1091 dme1737_write(client, DME1737_REG_FAN_OPT(ix), 1088 dme1737_write(data, DME1737_REG_FAN_OPT(ix),
1092 data->fan_opt[ix]); 1089 data->fan_opt[ix]);
1093 break; 1090 break;
1094 default: 1091 default:
@@ -1185,7 +1182,6 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
1185 const char *buf, size_t count) 1182 const char *buf, size_t count)
1186{ 1183{
1187 struct dme1737_data *data = dev_get_drvdata(dev); 1184 struct dme1737_data *data = dev_get_drvdata(dev);
1188 struct i2c_client *client = &data->client;
1189 struct sensor_device_attribute_2 1185 struct sensor_device_attribute_2
1190 *sensor_attr_2 = to_sensor_dev_attr_2(attr); 1186 *sensor_attr_2 = to_sensor_dev_attr_2(attr);
1191 int ix = sensor_attr_2->index; 1187 int ix = sensor_attr_2->index;
@@ -1196,12 +1192,12 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
1196 switch (fn) { 1192 switch (fn) {
1197 case SYS_PWM: 1193 case SYS_PWM:
1198 data->pwm[ix] = SENSORS_LIMIT(val, 0, 255); 1194 data->pwm[ix] = SENSORS_LIMIT(val, 0, 255);
1199 dme1737_write(client, DME1737_REG_PWM(ix), data->pwm[ix]); 1195 dme1737_write(data, DME1737_REG_PWM(ix), data->pwm[ix]);
1200 break; 1196 break;
1201 case SYS_PWM_FREQ: 1197 case SYS_PWM_FREQ:
1202 data->pwm_freq[ix] = PWM_FREQ_TO_REG(val, dme1737_read(client, 1198 data->pwm_freq[ix] = PWM_FREQ_TO_REG(val, dme1737_read(data,
1203 DME1737_REG_PWM_FREQ(ix))); 1199 DME1737_REG_PWM_FREQ(ix)));
1204 dme1737_write(client, DME1737_REG_PWM_FREQ(ix), 1200 dme1737_write(data, DME1737_REG_PWM_FREQ(ix),
1205 data->pwm_freq[ix]); 1201 data->pwm_freq[ix]);
1206 break; 1202 break;
1207 case SYS_PWM_ENABLE: 1203 case SYS_PWM_ENABLE:
@@ -1214,7 +1210,7 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
1214 goto exit; 1210 goto exit;
1215 } 1211 }
1216 /* Refresh the cache */ 1212 /* Refresh the cache */
1217 data->pwm_config[ix] = dme1737_read(client, 1213 data->pwm_config[ix] = dme1737_read(data,
1218 DME1737_REG_PWM_CONFIG(ix)); 1214 DME1737_REG_PWM_CONFIG(ix));
1219 if (val == PWM_EN_FROM_REG(data->pwm_config[ix])) { 1215 if (val == PWM_EN_FROM_REG(data->pwm_config[ix])) {
1220 /* Bail out if no change */ 1216 /* Bail out if no change */
@@ -1226,14 +1222,14 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
1226 data->pwm_acz[ix] = PWM_ACZ_FROM_REG( 1222 data->pwm_acz[ix] = PWM_ACZ_FROM_REG(
1227 data->pwm_config[ix]); 1223 data->pwm_config[ix]);
1228 /* Save the current ramp rate state and disable it */ 1224 /* Save the current ramp rate state and disable it */
1229 data->pwm_rr[ix > 0] = dme1737_read(client, 1225 data->pwm_rr[ix > 0] = dme1737_read(data,
1230 DME1737_REG_PWM_RR(ix > 0)); 1226 DME1737_REG_PWM_RR(ix > 0));
1231 data->pwm_rr_en &= ~(1 << ix); 1227 data->pwm_rr_en &= ~(1 << ix);
1232 if (PWM_RR_EN_FROM_REG(data->pwm_rr[ix > 0], ix)) { 1228 if (PWM_RR_EN_FROM_REG(data->pwm_rr[ix > 0], ix)) {
1233 data->pwm_rr_en |= (1 << ix); 1229 data->pwm_rr_en |= (1 << ix);
1234 data->pwm_rr[ix > 0] = PWM_RR_EN_TO_REG(0, ix, 1230 data->pwm_rr[ix > 0] = PWM_RR_EN_TO_REG(0, ix,
1235 data->pwm_rr[ix > 0]); 1231 data->pwm_rr[ix > 0]);
1236 dme1737_write(client, 1232 dme1737_write(data,
1237 DME1737_REG_PWM_RR(ix > 0), 1233 DME1737_REG_PWM_RR(ix > 0),
1238 data->pwm_rr[ix > 0]); 1234 data->pwm_rr[ix > 0]);
1239 } 1235 }
@@ -1247,14 +1243,14 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
1247 /* Turn fan fully on */ 1243 /* Turn fan fully on */
1248 data->pwm_config[ix] = PWM_EN_TO_REG(0, 1244 data->pwm_config[ix] = PWM_EN_TO_REG(0,
1249 data->pwm_config[ix]); 1245 data->pwm_config[ix]);
1250 dme1737_write(client, DME1737_REG_PWM_CONFIG(ix), 1246 dme1737_write(data, DME1737_REG_PWM_CONFIG(ix),
1251 data->pwm_config[ix]); 1247 data->pwm_config[ix]);
1252 break; 1248 break;
1253 case 1: 1249 case 1:
1254 /* Turn on manual mode */ 1250 /* Turn on manual mode */
1255 data->pwm_config[ix] = PWM_EN_TO_REG(1, 1251 data->pwm_config[ix] = PWM_EN_TO_REG(1,
1256 data->pwm_config[ix]); 1252 data->pwm_config[ix]);
1257 dme1737_write(client, DME1737_REG_PWM_CONFIG(ix), 1253 dme1737_write(data, DME1737_REG_PWM_CONFIG(ix),
1258 data->pwm_config[ix]); 1254 data->pwm_config[ix]);
1259 /* Change permissions of pwm[ix] to read-writeable */ 1255 /* Change permissions of pwm[ix] to read-writeable */
1260 dme1737_chmod_file(dev, dme1737_pwm_chmod_attr[ix], 1256 dme1737_chmod_file(dev, dme1737_pwm_chmod_attr[ix],
@@ -1269,14 +1265,14 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
1269 data->pwm_config[ix] = PWM_ACZ_TO_REG( 1265 data->pwm_config[ix] = PWM_ACZ_TO_REG(
1270 data->pwm_acz[ix], 1266 data->pwm_acz[ix],
1271 data->pwm_config[ix]); 1267 data->pwm_config[ix]);
1272 dme1737_write(client, DME1737_REG_PWM_CONFIG(ix), 1268 dme1737_write(data, DME1737_REG_PWM_CONFIG(ix),
1273 data->pwm_config[ix]); 1269 data->pwm_config[ix]);
1274 /* Enable PWM ramp rate if previously enabled */ 1270 /* Enable PWM ramp rate if previously enabled */
1275 if (data->pwm_rr_en & (1 << ix)) { 1271 if (data->pwm_rr_en & (1 << ix)) {
1276 data->pwm_rr[ix > 0] = PWM_RR_EN_TO_REG(1, ix, 1272 data->pwm_rr[ix > 0] = PWM_RR_EN_TO_REG(1, ix,
1277 dme1737_read(client, 1273 dme1737_read(data,
1278 DME1737_REG_PWM_RR(ix > 0))); 1274 DME1737_REG_PWM_RR(ix > 0)));
1279 dme1737_write(client, 1275 dme1737_write(data,
1280 DME1737_REG_PWM_RR(ix > 0), 1276 DME1737_REG_PWM_RR(ix > 0),
1281 data->pwm_rr[ix > 0]); 1277 data->pwm_rr[ix > 0]);
1282 } 1278 }
@@ -1286,9 +1282,9 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
1286 case SYS_PWM_RAMP_RATE: 1282 case SYS_PWM_RAMP_RATE:
1287 /* Only valid for pwm[1-3] */ 1283 /* Only valid for pwm[1-3] */
1288 /* Refresh the cache */ 1284 /* Refresh the cache */
1289 data->pwm_config[ix] = dme1737_read(client, 1285 data->pwm_config[ix] = dme1737_read(data,
1290 DME1737_REG_PWM_CONFIG(ix)); 1286 DME1737_REG_PWM_CONFIG(ix));
1291 data->pwm_rr[ix > 0] = dme1737_read(client, 1287 data->pwm_rr[ix > 0] = dme1737_read(data,
1292 DME1737_REG_PWM_RR(ix > 0)); 1288 DME1737_REG_PWM_RR(ix > 0));
1293 /* Set the ramp rate value */ 1289 /* Set the ramp rate value */
1294 if (val > 0) { 1290 if (val > 0) {
@@ -1301,7 +1297,7 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
1301 data->pwm_rr[ix > 0] = PWM_RR_EN_TO_REG(val > 0, ix, 1297 data->pwm_rr[ix > 0] = PWM_RR_EN_TO_REG(val > 0, ix,
1302 data->pwm_rr[ix > 0]); 1298 data->pwm_rr[ix > 0]);
1303 } 1299 }
1304 dme1737_write(client, DME1737_REG_PWM_RR(ix > 0), 1300 dme1737_write(data, DME1737_REG_PWM_RR(ix > 0),
1305 data->pwm_rr[ix > 0]); 1301 data->pwm_rr[ix > 0]);
1306 break; 1302 break;
1307 case SYS_PWM_AUTO_CHANNELS_ZONE: 1303 case SYS_PWM_AUTO_CHANNELS_ZONE:
@@ -1315,14 +1311,14 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
1315 goto exit; 1311 goto exit;
1316 } 1312 }
1317 /* Refresh the cache */ 1313 /* Refresh the cache */
1318 data->pwm_config[ix] = dme1737_read(client, 1314 data->pwm_config[ix] = dme1737_read(data,
1319 DME1737_REG_PWM_CONFIG(ix)); 1315 DME1737_REG_PWM_CONFIG(ix));
1320 if (PWM_EN_FROM_REG(data->pwm_config[ix]) == 2) { 1316 if (PWM_EN_FROM_REG(data->pwm_config[ix]) == 2) {
1321 /* PWM is already in auto mode so update the temp 1317 /* PWM is already in auto mode so update the temp
1322 * channel assignment */ 1318 * channel assignment */
1323 data->pwm_config[ix] = PWM_ACZ_TO_REG(val, 1319 data->pwm_config[ix] = PWM_ACZ_TO_REG(val,
1324 data->pwm_config[ix]); 1320 data->pwm_config[ix]);
1325 dme1737_write(client, DME1737_REG_PWM_CONFIG(ix), 1321 dme1737_write(data, DME1737_REG_PWM_CONFIG(ix),
1326 data->pwm_config[ix]); 1322 data->pwm_config[ix]);
1327 } else { 1323 } else {
1328 /* PWM is not in auto mode so we save the temp 1324 /* PWM is not in auto mode so we save the temp
@@ -1333,7 +1329,7 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
1333 case SYS_PWM_AUTO_PWM_MIN: 1329 case SYS_PWM_AUTO_PWM_MIN:
1334 /* Only valid for pwm[1-3] */ 1330 /* Only valid for pwm[1-3] */
1335 /* Refresh the cache */ 1331 /* Refresh the cache */
1336 data->pwm_min[ix] = dme1737_read(client, 1332 data->pwm_min[ix] = dme1737_read(data,
1337 DME1737_REG_PWM_MIN(ix)); 1333 DME1737_REG_PWM_MIN(ix));
1338 /* There are only 2 values supported for the auto_pwm_min 1334 /* There are only 2 values supported for the auto_pwm_min
1339 * value: 0 or auto_point1_pwm. So if the temperature drops 1335 * value: 0 or auto_point1_pwm. So if the temperature drops
@@ -1341,20 +1337,20 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
1341 * off or runs at auto_point1_pwm duty-cycle. */ 1337 * off or runs at auto_point1_pwm duty-cycle. */
1342 if (val > ((data->pwm_min[ix] + 1) / 2)) { 1338 if (val > ((data->pwm_min[ix] + 1) / 2)) {
1343 data->pwm_rr[0] = PWM_OFF_TO_REG(1, ix, 1339 data->pwm_rr[0] = PWM_OFF_TO_REG(1, ix,
1344 dme1737_read(client, 1340 dme1737_read(data,
1345 DME1737_REG_PWM_RR(0))); 1341 DME1737_REG_PWM_RR(0)));
1346 } else { 1342 } else {
1347 data->pwm_rr[0] = PWM_OFF_TO_REG(0, ix, 1343 data->pwm_rr[0] = PWM_OFF_TO_REG(0, ix,
1348 dme1737_read(client, 1344 dme1737_read(data,
1349 DME1737_REG_PWM_RR(0))); 1345 DME1737_REG_PWM_RR(0)));
1350 } 1346 }
1351 dme1737_write(client, DME1737_REG_PWM_RR(0), 1347 dme1737_write(data, DME1737_REG_PWM_RR(0),
1352 data->pwm_rr[0]); 1348 data->pwm_rr[0]);
1353 break; 1349 break;
1354 case SYS_PWM_AUTO_POINT1_PWM: 1350 case SYS_PWM_AUTO_POINT1_PWM:
1355 /* Only valid for pwm[1-3] */ 1351 /* Only valid for pwm[1-3] */
1356 data->pwm_min[ix] = SENSORS_LIMIT(val, 0, 255); 1352 data->pwm_min[ix] = SENSORS_LIMIT(val, 0, 255);
1357 dme1737_write(client, DME1737_REG_PWM_MIN(ix), 1353 dme1737_write(data, DME1737_REG_PWM_MIN(ix),
1358 data->pwm_min[ix]); 1354 data->pwm_min[ix]);
1359 break; 1355 break;
1360 default: 1356 default:
@@ -1402,7 +1398,7 @@ static ssize_t show_name(struct device *dev, struct device_attribute *attr,
1402{ 1398{
1403 struct dme1737_data *data = dev_get_drvdata(dev); 1399 struct dme1737_data *data = dev_get_drvdata(dev);
1404 1400
1405 return sprintf(buf, "%s\n", data->client.name); 1401 return sprintf(buf, "%s\n", data->name);
1406} 1402}
1407 1403
1408/* --------------------------------------------------------------------- 1404/* ---------------------------------------------------------------------
@@ -1908,7 +1904,7 @@ static void dme1737_remove_files(struct device *dev)
1908 1904
1909 sysfs_remove_group(&dev->kobj, &dme1737_group); 1905 sysfs_remove_group(&dev->kobj, &dme1737_group);
1910 1906
1911 if (!data->client.driver) { 1907 if (!data->client) {
1912 sysfs_remove_file(&dev->kobj, &dev_attr_name.attr); 1908 sysfs_remove_file(&dev->kobj, &dev_attr_name.attr);
1913 } 1909 }
1914} 1910}
@@ -1919,7 +1915,7 @@ static int dme1737_create_files(struct device *dev)
1919 int err, ix; 1915 int err, ix;
1920 1916
1921 /* Create a name attribute for ISA devices */ 1917 /* Create a name attribute for ISA devices */
1922 if (!data->client.driver && 1918 if (!data->client &&
1923 (err = sysfs_create_file(&dev->kobj, &dev_attr_name.attr))) { 1919 (err = sysfs_create_file(&dev->kobj, &dev_attr_name.attr))) {
1924 goto exit; 1920 goto exit;
1925 } 1921 }
@@ -2013,14 +2009,14 @@ exit:
2013static int dme1737_init_device(struct device *dev) 2009static int dme1737_init_device(struct device *dev)
2014{ 2010{
2015 struct dme1737_data *data = dev_get_drvdata(dev); 2011 struct dme1737_data *data = dev_get_drvdata(dev);
2016 struct i2c_client *client = &data->client; 2012 struct i2c_client *client = data->client;
2017 int ix; 2013 int ix;
2018 u8 reg; 2014 u8 reg;
2019 2015
2020 /* Point to the right nominal voltages array */ 2016 /* Point to the right nominal voltages array */
2021 data->in_nominal = IN_NOMINAL(data->type); 2017 data->in_nominal = IN_NOMINAL(data->type);
2022 2018
2023 data->config = dme1737_read(client, DME1737_REG_CONFIG); 2019 data->config = dme1737_read(data, DME1737_REG_CONFIG);
2024 /* Inform if part is not monitoring/started */ 2020 /* Inform if part is not monitoring/started */
2025 if (!(data->config & 0x01)) { 2021 if (!(data->config & 0x01)) {
2026 if (!force_start) { 2022 if (!force_start) {
@@ -2032,7 +2028,7 @@ static int dme1737_init_device(struct device *dev)
2032 2028
2033 /* Force monitoring */ 2029 /* Force monitoring */
2034 data->config |= 0x01; 2030 data->config |= 0x01;
2035 dme1737_write(client, DME1737_REG_CONFIG, data->config); 2031 dme1737_write(data, DME1737_REG_CONFIG, data->config);
2036 } 2032 }
2037 /* Inform if part is not ready */ 2033 /* Inform if part is not ready */
2038 if (!(data->config & 0x04)) { 2034 if (!(data->config & 0x04)) {
@@ -2041,8 +2037,8 @@ static int dme1737_init_device(struct device *dev)
2041 } 2037 }
2042 2038
2043 /* Determine which optional fan and pwm features are enabled/present */ 2039 /* Determine which optional fan and pwm features are enabled/present */
2044 if (client->driver) { /* I2C chip */ 2040 if (client) { /* I2C chip */
2045 data->config2 = dme1737_read(client, DME1737_REG_CONFIG2); 2041 data->config2 = dme1737_read(data, DME1737_REG_CONFIG2);
2046 /* Check if optional fan3 input is enabled */ 2042 /* Check if optional fan3 input is enabled */
2047 if (data->config2 & 0x04) { 2043 if (data->config2 & 0x04) {
2048 data->has_fan |= (1 << 2); 2044 data->has_fan |= (1 << 2);
@@ -2051,7 +2047,7 @@ static int dme1737_init_device(struct device *dev)
2051 /* Fan4 and pwm3 are only available if the client's I2C address 2047 /* Fan4 and pwm3 are only available if the client's I2C address
2052 * is the default 0x2e. Otherwise the I/Os associated with 2048 * is the default 0x2e. Otherwise the I/Os associated with
2053 * these functions are used for addr enable/select. */ 2049 * these functions are used for addr enable/select. */
2054 if (data->client.addr == 0x2e) { 2050 if (client->addr == 0x2e) {
2055 data->has_fan |= (1 << 3); 2051 data->has_fan |= (1 << 3);
2056 data->has_pwm |= (1 << 2); 2052 data->has_pwm |= (1 << 2);
2057 } 2053 }
@@ -2086,16 +2082,16 @@ static int dme1737_init_device(struct device *dev)
2086 (data->has_fan & (1 << 4)) ? "yes" : "no", 2082 (data->has_fan & (1 << 4)) ? "yes" : "no",
2087 (data->has_fan & (1 << 5)) ? "yes" : "no"); 2083 (data->has_fan & (1 << 5)) ? "yes" : "no");
2088 2084
2089 reg = dme1737_read(client, DME1737_REG_TACH_PWM); 2085 reg = dme1737_read(data, DME1737_REG_TACH_PWM);
2090 /* Inform if fan-to-pwm mapping differs from the default */ 2086 /* Inform if fan-to-pwm mapping differs from the default */
2091 if (client->driver && reg != 0xa4) { /* I2C chip */ 2087 if (client && reg != 0xa4) { /* I2C chip */
2092 dev_warn(dev, "Non-standard fan to pwm mapping: " 2088 dev_warn(dev, "Non-standard fan to pwm mapping: "
2093 "fan1->pwm%d, fan2->pwm%d, fan3->pwm%d, " 2089 "fan1->pwm%d, fan2->pwm%d, fan3->pwm%d, "
2094 "fan4->pwm%d. Please report to the driver " 2090 "fan4->pwm%d. Please report to the driver "
2095 "maintainer.\n", 2091 "maintainer.\n",
2096 (reg & 0x03) + 1, ((reg >> 2) & 0x03) + 1, 2092 (reg & 0x03) + 1, ((reg >> 2) & 0x03) + 1,
2097 ((reg >> 4) & 0x03) + 1, ((reg >> 6) & 0x03) + 1); 2093 ((reg >> 4) & 0x03) + 1, ((reg >> 6) & 0x03) + 1);
2098 } else if (!client->driver && reg != 0x24) { /* ISA chip */ 2094 } else if (!client && reg != 0x24) { /* ISA chip */
2099 dev_warn(dev, "Non-standard fan to pwm mapping: " 2095 dev_warn(dev, "Non-standard fan to pwm mapping: "
2100 "fan1->pwm%d, fan2->pwm%d, fan3->pwm%d. " 2096 "fan1->pwm%d, fan2->pwm%d, fan3->pwm%d. "
2101 "Please report to the driver maintainer.\n", 2097 "Please report to the driver maintainer.\n",
@@ -2108,7 +2104,7 @@ static int dme1737_init_device(struct device *dev)
2108 * disabled). */ 2104 * disabled). */
2109 if (!(data->config & 0x02)) { 2105 if (!(data->config & 0x02)) {
2110 for (ix = 0; ix < 3; ix++) { 2106 for (ix = 0; ix < 3; ix++) {
2111 data->pwm_config[ix] = dme1737_read(client, 2107 data->pwm_config[ix] = dme1737_read(data,
2112 DME1737_REG_PWM_CONFIG(ix)); 2108 DME1737_REG_PWM_CONFIG(ix));
2113 if ((data->has_pwm & (1 << ix)) && 2109 if ((data->has_pwm & (1 << ix)) &&
2114 (PWM_EN_FROM_REG(data->pwm_config[ix]) == -1)) { 2110 (PWM_EN_FROM_REG(data->pwm_config[ix]) == -1)) {
@@ -2116,8 +2112,8 @@ static int dme1737_init_device(struct device *dev)
2116 "manual mode.\n", ix + 1); 2112 "manual mode.\n", ix + 1);
2117 data->pwm_config[ix] = PWM_EN_TO_REG(1, 2113 data->pwm_config[ix] = PWM_EN_TO_REG(1,
2118 data->pwm_config[ix]); 2114 data->pwm_config[ix]);
2119 dme1737_write(client, DME1737_REG_PWM(ix), 0); 2115 dme1737_write(data, DME1737_REG_PWM(ix), 0);
2120 dme1737_write(client, 2116 dme1737_write(data,
2121 DME1737_REG_PWM_CONFIG(ix), 2117 DME1737_REG_PWM_CONFIG(ix),
2122 data->pwm_config[ix]); 2118 data->pwm_config[ix]);
2123 } 2119 }
@@ -2191,37 +2187,24 @@ exit:
2191 return err; 2187 return err;
2192} 2188}
2193 2189
2194static int dme1737_i2c_detect(struct i2c_adapter *adapter, int address, 2190/* Return 0 if detection is successful, -ENODEV otherwise */
2195 int kind) 2191static int dme1737_i2c_detect(struct i2c_client *client, int kind,
2192 struct i2c_board_info *info)
2196{ 2193{
2194 struct i2c_adapter *adapter = client->adapter;
2195 struct device *dev = &adapter->dev;
2197 u8 company, verstep = 0; 2196 u8 company, verstep = 0;
2198 struct i2c_client *client;
2199 struct dme1737_data *data;
2200 struct device *dev;
2201 int err = 0;
2202 const char *name; 2197 const char *name;
2203 2198
2204 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { 2199 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
2205 goto exit; 2200 return -ENODEV;
2206 }
2207
2208 if (!(data = kzalloc(sizeof(struct dme1737_data), GFP_KERNEL))) {
2209 err = -ENOMEM;
2210 goto exit;
2211 } 2201 }
2212 2202
2213 client = &data->client;
2214 i2c_set_clientdata(client, data);
2215 client->addr = address;
2216 client->adapter = adapter;
2217 client->driver = &dme1737_i2c_driver;
2218 dev = &client->dev;
2219
2220 /* A negative kind means that the driver was loaded with no force 2203 /* A negative kind means that the driver was loaded with no force
2221 * parameter (default), so we must identify the chip. */ 2204 * parameter (default), so we must identify the chip. */
2222 if (kind < 0) { 2205 if (kind < 0) {
2223 company = dme1737_read(client, DME1737_REG_COMPANY); 2206 company = i2c_smbus_read_byte_data(client, DME1737_REG_COMPANY);
2224 verstep = dme1737_read(client, DME1737_REG_VERSTEP); 2207 verstep = i2c_smbus_read_byte_data(client, DME1737_REG_VERSTEP);
2225 2208
2226 if (company == DME1737_COMPANY_SMSC && 2209 if (company == DME1737_COMPANY_SMSC &&
2227 (verstep & DME1737_VERSTEP_MASK) == DME1737_VERSTEP) { 2210 (verstep & DME1737_VERSTEP_MASK) == DME1737_VERSTEP) {
@@ -2230,8 +2213,7 @@ static int dme1737_i2c_detect(struct i2c_adapter *adapter, int address,
2230 verstep == SCH5027_VERSTEP) { 2213 verstep == SCH5027_VERSTEP) {
2231 kind = sch5027; 2214 kind = sch5027;
2232 } else { 2215 } else {
2233 err = -ENODEV; 2216 return -ENODEV;
2234 goto exit_kfree;
2235 } 2217 }
2236 } 2218 }
2237 2219
@@ -2241,32 +2223,44 @@ static int dme1737_i2c_detect(struct i2c_adapter *adapter, int address,
2241 kind = dme1737; 2223 kind = dme1737;
2242 name = "dme1737"; 2224 name = "dme1737";
2243 } 2225 }
2244 data->type = kind;
2245
2246 /* Fill in the remaining client fields and put it into the global
2247 * list */
2248 strlcpy(client->name, name, I2C_NAME_SIZE);
2249 mutex_init(&data->update_lock);
2250
2251 /* Tell the I2C layer a new client has arrived */
2252 if ((err = i2c_attach_client(client))) {
2253 goto exit_kfree;
2254 }
2255 2226
2256 dev_info(dev, "Found a %s chip at 0x%02x (rev 0x%02x).\n", 2227 dev_info(dev, "Found a %s chip at 0x%02x (rev 0x%02x).\n",
2257 kind == sch5027 ? "SCH5027" : "DME1737", client->addr, 2228 kind == sch5027 ? "SCH5027" : "DME1737", client->addr,
2258 verstep); 2229 verstep);
2230 strlcpy(info->type, name, I2C_NAME_SIZE);
2231
2232 return 0;
2233}
2234
2235static int dme1737_i2c_probe(struct i2c_client *client,
2236 const struct i2c_device_id *id)
2237{
2238 struct dme1737_data *data;
2239 struct device *dev = &client->dev;
2240 int err;
2241
2242 data = kzalloc(sizeof(struct dme1737_data), GFP_KERNEL);
2243 if (!data) {
2244 err = -ENOMEM;
2245 goto exit;
2246 }
2247
2248 i2c_set_clientdata(client, data);
2249 data->type = id->driver_data;
2250 data->client = client;
2251 data->name = client->name;
2252 mutex_init(&data->update_lock);
2259 2253
2260 /* Initialize the DME1737 chip */ 2254 /* Initialize the DME1737 chip */
2261 if ((err = dme1737_init_device(dev))) { 2255 if ((err = dme1737_init_device(dev))) {
2262 dev_err(dev, "Failed to initialize device.\n"); 2256 dev_err(dev, "Failed to initialize device.\n");
2263 goto exit_detach; 2257 goto exit_kfree;
2264 } 2258 }
2265 2259
2266 /* Create sysfs files */ 2260 /* Create sysfs files */
2267 if ((err = dme1737_create_files(dev))) { 2261 if ((err = dme1737_create_files(dev))) {
2268 dev_err(dev, "Failed to create sysfs files.\n"); 2262 dev_err(dev, "Failed to create sysfs files.\n");
2269 goto exit_detach; 2263 goto exit_kfree;
2270 } 2264 }
2271 2265
2272 /* Register device */ 2266 /* Register device */
@@ -2281,45 +2275,40 @@ static int dme1737_i2c_detect(struct i2c_adapter *adapter, int address,
2281 2275
2282exit_remove: 2276exit_remove:
2283 dme1737_remove_files(dev); 2277 dme1737_remove_files(dev);
2284exit_detach:
2285 i2c_detach_client(client);
2286exit_kfree: 2278exit_kfree:
2287 kfree(data); 2279 kfree(data);
2288exit: 2280exit:
2289 return err; 2281 return err;
2290} 2282}
2291 2283
2292static int dme1737_i2c_attach_adapter(struct i2c_adapter *adapter) 2284static int dme1737_i2c_remove(struct i2c_client *client)
2293{
2294 if (!(adapter->class & I2C_CLASS_HWMON)) {
2295 return 0;
2296 }
2297
2298 return i2c_probe(adapter, &addr_data, dme1737_i2c_detect);
2299}
2300
2301static int dme1737_i2c_detach_client(struct i2c_client *client)
2302{ 2285{
2303 struct dme1737_data *data = i2c_get_clientdata(client); 2286 struct dme1737_data *data = i2c_get_clientdata(client);
2304 int err;
2305 2287
2306 hwmon_device_unregister(data->hwmon_dev); 2288 hwmon_device_unregister(data->hwmon_dev);
2307 dme1737_remove_files(&client->dev); 2289 dme1737_remove_files(&client->dev);
2308 2290
2309 if ((err = i2c_detach_client(client))) {
2310 return err;
2311 }
2312
2313 kfree(data); 2291 kfree(data);
2314 return 0; 2292 return 0;
2315} 2293}
2316 2294
2295static const struct i2c_device_id dme1737_id[] = {
2296 { "dme1737", dme1737 },
2297 { "sch5027", sch5027 },
2298 { }
2299};
2300MODULE_DEVICE_TABLE(i2c, dme1737_id);
2301
2317static struct i2c_driver dme1737_i2c_driver = { 2302static struct i2c_driver dme1737_i2c_driver = {
2303 .class = I2C_CLASS_HWMON,
2318 .driver = { 2304 .driver = {
2319 .name = "dme1737", 2305 .name = "dme1737",
2320 }, 2306 },
2321 .attach_adapter = dme1737_i2c_attach_adapter, 2307 .probe = dme1737_i2c_probe,
2322 .detach_client = dme1737_i2c_detach_client, 2308 .remove = dme1737_i2c_remove,
2309 .id_table = dme1737_id,
2310 .detect = dme1737_i2c_detect,
2311 .address_data = &addr_data,
2323}; 2312};
2324 2313
2325/* --------------------------------------------------------------------- 2314/* ---------------------------------------------------------------------
@@ -2403,7 +2392,6 @@ static int __devinit dme1737_isa_probe(struct platform_device *pdev)
2403{ 2392{
2404 u8 company, device; 2393 u8 company, device;
2405 struct resource *res; 2394 struct resource *res;
2406 struct i2c_client *client;
2407 struct dme1737_data *data; 2395 struct dme1737_data *data;
2408 struct device *dev = &pdev->dev; 2396 struct device *dev = &pdev->dev;
2409 int err; 2397 int err;
@@ -2422,15 +2410,13 @@ static int __devinit dme1737_isa_probe(struct platform_device *pdev)
2422 goto exit_release_region; 2410 goto exit_release_region;
2423 } 2411 }
2424 2412
2425 client = &data->client; 2413 data->addr = res->start;
2426 i2c_set_clientdata(client, data);
2427 client->addr = res->start;
2428 platform_set_drvdata(pdev, data); 2414 platform_set_drvdata(pdev, data);
2429 2415
2430 /* Skip chip detection if module is loaded with force_id parameter */ 2416 /* Skip chip detection if module is loaded with force_id parameter */
2431 if (!force_id) { 2417 if (!force_id) {
2432 company = dme1737_read(client, DME1737_REG_COMPANY); 2418 company = dme1737_read(data, DME1737_REG_COMPANY);
2433 device = dme1737_read(client, DME1737_REG_DEVICE); 2419 device = dme1737_read(data, DME1737_REG_DEVICE);
2434 2420
2435 if (!((company == DME1737_COMPANY_SMSC) && 2421 if (!((company == DME1737_COMPANY_SMSC) &&
2436 (device == SCH311X_DEVICE))) { 2422 (device == SCH311X_DEVICE))) {
@@ -2441,10 +2427,10 @@ static int __devinit dme1737_isa_probe(struct platform_device *pdev)
2441 data->type = sch311x; 2427 data->type = sch311x;
2442 2428
2443 /* Fill in the remaining client fields and initialize the mutex */ 2429 /* Fill in the remaining client fields and initialize the mutex */
2444 strlcpy(client->name, "sch311x", I2C_NAME_SIZE); 2430 data->name = "sch311x";
2445 mutex_init(&data->update_lock); 2431 mutex_init(&data->update_lock);
2446 2432
2447 dev_info(dev, "Found a SCH311x chip at 0x%04x\n", client->addr); 2433 dev_info(dev, "Found a SCH311x chip at 0x%04x\n", data->addr);
2448 2434
2449 /* Initialize the chip */ 2435 /* Initialize the chip */
2450 if ((err = dme1737_init_device(dev))) { 2436 if ((err = dme1737_init_device(dev))) {
@@ -2485,7 +2471,7 @@ static int __devexit dme1737_isa_remove(struct platform_device *pdev)
2485 2471
2486 hwmon_device_unregister(data->hwmon_dev); 2472 hwmon_device_unregister(data->hwmon_dev);
2487 dme1737_remove_files(&pdev->dev); 2473 dme1737_remove_files(&pdev->dev);
2488 release_region(data->client.addr, DME1737_EXTENT); 2474 release_region(data->addr, DME1737_EXTENT);
2489 platform_set_drvdata(pdev, NULL); 2475 platform_set_drvdata(pdev, NULL);
2490 kfree(data); 2476 kfree(data);
2491 2477
diff --git a/drivers/hwmon/hwmon.c b/drivers/hwmon/hwmon.c
index 7321a88a5112..076a59cdabe9 100644
--- a/drivers/hwmon/hwmon.c
+++ b/drivers/hwmon/hwmon.c
@@ -55,8 +55,8 @@ again:
55 return ERR_PTR(err); 55 return ERR_PTR(err);
56 56
57 id = id & MAX_ID_MASK; 57 id = id & MAX_ID_MASK;
58 hwdev = device_create_drvdata(hwmon_class, dev, MKDEV(0, 0), NULL, 58 hwdev = device_create(hwmon_class, dev, MKDEV(0, 0), NULL,
59 HWMON_ID_FORMAT, id); 59 HWMON_ID_FORMAT, id);
60 60
61 if (IS_ERR(hwdev)) { 61 if (IS_ERR(hwdev)) {
62 spin_lock(&idr_lock); 62 spin_lock(&idr_lock);
diff --git a/drivers/hwmon/it87.c b/drivers/hwmon/it87.c
index 30cdb0956779..d793cc011990 100644
--- a/drivers/hwmon/it87.c
+++ b/drivers/hwmon/it87.c
@@ -46,6 +46,8 @@
46#include <linux/err.h> 46#include <linux/err.h>
47#include <linux/mutex.h> 47#include <linux/mutex.h>
48#include <linux/sysfs.h> 48#include <linux/sysfs.h>
49#include <linux/string.h>
50#include <linux/dmi.h>
49#include <asm/io.h> 51#include <asm/io.h>
50 52
51#define DRVNAME "it87" 53#define DRVNAME "it87"
@@ -236,6 +238,8 @@ struct it87_sio_data {
236 /* Values read from Super-I/O config space */ 238 /* Values read from Super-I/O config space */
237 u8 revision; 239 u8 revision;
238 u8 vid_value; 240 u8 vid_value;
241 /* Values set based on DMI strings */
242 u8 skip_pwm;
239}; 243};
240 244
241/* For each registered chip, we need to keep some data in memory. 245/* For each registered chip, we need to keep some data in memory.
@@ -273,10 +277,10 @@ struct it87_data {
273static inline int has_16bit_fans(const struct it87_data *data) 277static inline int has_16bit_fans(const struct it87_data *data)
274{ 278{
275 /* IT8705F Datasheet 0.4.1, 3h == Version G. 279 /* IT8705F Datasheet 0.4.1, 3h == Version G.
276 IT8712F Datasheet 0.9.1, section 8.3.5 indicates 7h == Version I. 280 IT8712F Datasheet 0.9.1, section 8.3.5 indicates 8h == Version J.
277 These are the first revisions with 16bit tachometer support. */ 281 These are the first revisions with 16bit tachometer support. */
278 return (data->type == it87 && data->revision >= 0x03) 282 return (data->type == it87 && data->revision >= 0x03)
279 || (data->type == it8712 && data->revision >= 0x07) 283 || (data->type == it8712 && data->revision >= 0x08)
280 || data->type == it8716 284 || data->type == it8716
281 || data->type == it8718; 285 || data->type == it8718;
282} 286}
@@ -964,6 +968,7 @@ static int __init it87_find(unsigned short *address,
964{ 968{
965 int err = -ENODEV; 969 int err = -ENODEV;
966 u16 chip_type; 970 u16 chip_type;
971 const char *board_vendor, *board_name;
967 972
968 superio_enter(); 973 superio_enter();
969 chip_type = force_id ? force_id : superio_inw(DEVID); 974 chip_type = force_id ? force_id : superio_inw(DEVID);
@@ -1022,6 +1027,24 @@ static int __init it87_find(unsigned short *address,
1022 pr_info("it87: in7 is VCCH (+5V Stand-By)\n"); 1027 pr_info("it87: in7 is VCCH (+5V Stand-By)\n");
1023 } 1028 }
1024 1029
1030 /* Disable specific features based on DMI strings */
1031 board_vendor = dmi_get_system_info(DMI_BOARD_VENDOR);
1032 board_name = dmi_get_system_info(DMI_BOARD_NAME);
1033 if (board_vendor && board_name) {
1034 if (strcmp(board_vendor, "nVIDIA") == 0
1035 && strcmp(board_name, "FN68PT") == 0) {
1036 /* On the Shuttle SN68PT, FAN_CTL2 is apparently not
1037 connected to a fan, but to something else. One user
1038 has reported instant system power-off when changing
1039 the PWM2 duty cycle, so we disable it.
1040 I use the board name string as the trigger in case
1041 the same board is ever used in other systems. */
1042 pr_info("it87: Disabling pwm2 due to "
1043 "hardware constraints\n");
1044 sio_data->skip_pwm = (1 << 1);
1045 }
1046 }
1047
1025exit: 1048exit:
1026 superio_exit(); 1049 superio_exit();
1027 return err; 1050 return err;
@@ -1168,25 +1191,33 @@ static int __devinit it87_probe(struct platform_device *pdev)
1168 } 1191 }
1169 1192
1170 if (enable_pwm_interface) { 1193 if (enable_pwm_interface) {
1171 if ((err = device_create_file(dev, 1194 if (!(sio_data->skip_pwm & (1 << 0))) {
1172 &sensor_dev_attr_pwm1_enable.dev_attr)) 1195 if ((err = device_create_file(dev,
1173 || (err = device_create_file(dev, 1196 &sensor_dev_attr_pwm1_enable.dev_attr))
1174 &sensor_dev_attr_pwm2_enable.dev_attr)) 1197 || (err = device_create_file(dev,
1175 || (err = device_create_file(dev, 1198 &sensor_dev_attr_pwm1.dev_attr))
1176 &sensor_dev_attr_pwm3_enable.dev_attr)) 1199 || (err = device_create_file(dev,
1177 || (err = device_create_file(dev, 1200 &dev_attr_pwm1_freq)))
1178 &sensor_dev_attr_pwm1.dev_attr)) 1201 goto ERROR4;
1179 || (err = device_create_file(dev, 1202 }
1180 &sensor_dev_attr_pwm2.dev_attr)) 1203 if (!(sio_data->skip_pwm & (1 << 1))) {
1181 || (err = device_create_file(dev, 1204 if ((err = device_create_file(dev,
1182 &sensor_dev_attr_pwm3.dev_attr)) 1205 &sensor_dev_attr_pwm2_enable.dev_attr))
1183 || (err = device_create_file(dev, 1206 || (err = device_create_file(dev,
1184 &dev_attr_pwm1_freq)) 1207 &sensor_dev_attr_pwm2.dev_attr))
1185 || (err = device_create_file(dev, 1208 || (err = device_create_file(dev,
1186 &dev_attr_pwm2_freq)) 1209 &dev_attr_pwm2_freq)))
1187 || (err = device_create_file(dev, 1210 goto ERROR4;
1188 &dev_attr_pwm3_freq))) 1211 }
1189 goto ERROR4; 1212 if (!(sio_data->skip_pwm & (1 << 2))) {
1213 if ((err = device_create_file(dev,
1214 &sensor_dev_attr_pwm3_enable.dev_attr))
1215 || (err = device_create_file(dev,
1216 &sensor_dev_attr_pwm3.dev_attr))
1217 || (err = device_create_file(dev,
1218 &dev_attr_pwm3_freq)))
1219 goto ERROR4;
1220 }
1190 } 1221 }
1191 1222
1192 if (data->type == it8712 || data->type == it8716 1223 if (data->type == it8712 || data->type == it8716
@@ -1546,6 +1577,7 @@ static int __init sm_it87_init(void)
1546 unsigned short isa_address=0; 1577 unsigned short isa_address=0;
1547 struct it87_sio_data sio_data; 1578 struct it87_sio_data sio_data;
1548 1579
1580 memset(&sio_data, 0, sizeof(struct it87_sio_data));
1549 err = it87_find(&isa_address, &sio_data); 1581 err = it87_find(&isa_address, &sio_data);
1550 if (err) 1582 if (err)
1551 return err; 1583 return err;
diff --git a/drivers/hwmon/max1111.c b/drivers/hwmon/max1111.c
new file mode 100644
index 000000000000..bfaa665ccf32
--- /dev/null
+++ b/drivers/hwmon/max1111.c
@@ -0,0 +1,244 @@
1/*
2 * max1111.c - +2.7V, Low-Power, Multichannel, Serial 8-bit ADCs
3 *
4 * Based on arch/arm/mach-pxa/corgi_ssp.c
5 *
6 * Copyright (C) 2004-2005 Richard Purdie
7 *
8 * Copyright (C) 2008 Marvell International Ltd.
9 * Eric Miao <eric.miao@marvell.com>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * publishhed by the Free Software Foundation.
14 */
15
16#include <linux/module.h>
17#include <linux/kernel.h>
18#include <linux/init.h>
19#include <linux/err.h>
20#include <linux/hwmon.h>
21#include <linux/hwmon-sysfs.h>
22#include <linux/spi/spi.h>
23
24#define MAX1111_TX_BUF_SIZE 1
25#define MAX1111_RX_BUF_SIZE 2
26
27/* MAX1111 Commands */
28#define MAX1111_CTRL_PD0 (1u << 0)
29#define MAX1111_CTRL_PD1 (1u << 1)
30#define MAX1111_CTRL_SGL (1u << 2)
31#define MAX1111_CTRL_UNI (1u << 3)
32#define MAX1111_CTRL_SEL_SH (5) /* NOTE: bit 4 is ignored */
33#define MAX1111_CTRL_STR (1u << 7)
34
35struct max1111_data {
36 struct spi_device *spi;
37 struct device *hwmon_dev;
38 struct spi_message msg;
39 struct spi_transfer xfer[2];
40 uint8_t *tx_buf;
41 uint8_t *rx_buf;
42};
43
44static int max1111_read(struct device *dev, int channel)
45{
46 struct max1111_data *data = dev_get_drvdata(dev);
47 uint8_t v1, v2;
48 int err;
49
50 data->tx_buf[0] = (channel << MAX1111_CTRL_SEL_SH) |
51 MAX1111_CTRL_PD0 | MAX1111_CTRL_PD1 |
52 MAX1111_CTRL_SGL | MAX1111_CTRL_UNI | MAX1111_CTRL_STR;
53
54 err = spi_sync(data->spi, &data->msg);
55 if (err < 0) {
56 dev_err(dev, "spi_sync failed with %d\n", err);
57 return err;
58 }
59
60 v1 = data->rx_buf[0];
61 v2 = data->rx_buf[1];
62
63 if ((v1 & 0xc0) || (v2 & 0x3f))
64 return -EINVAL;
65
66 return (v1 << 2) | (v2 >> 6);
67}
68
69#ifdef CONFIG_SHARPSL_PM
70static struct max1111_data *the_max1111;
71
72int max1111_read_channel(int channel)
73{
74 return max1111_read(&the_max1111->spi->dev, channel);
75}
76EXPORT_SYMBOL(max1111_read_channel);
77#endif
78
79/*
80 * NOTE: SPI devices do not have a default 'name' attribute, which is
81 * likely to be used by hwmon applications to distinguish between
82 * different devices, explicitly add a name attribute here.
83 */
84static ssize_t show_name(struct device *dev,
85 struct device_attribute *attr, char *buf)
86{
87 return sprintf(buf, "max1111\n");
88}
89
90static ssize_t show_adc(struct device *dev,
91 struct device_attribute *attr, char *buf)
92{
93 int channel = to_sensor_dev_attr(attr)->index;
94 int ret;
95
96 ret = max1111_read(dev, channel);
97 if (ret < 0)
98 return ret;
99
100 return sprintf(buf, "%d\n", ret);
101}
102
103#define MAX1111_ADC_ATTR(_id) \
104 SENSOR_DEVICE_ATTR(adc##_id##_in, S_IRUGO, show_adc, NULL, _id)
105
106static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
107static MAX1111_ADC_ATTR(0);
108static MAX1111_ADC_ATTR(1);
109static MAX1111_ADC_ATTR(2);
110static MAX1111_ADC_ATTR(3);
111
112static struct attribute *max1111_attributes[] = {
113 &dev_attr_name.attr,
114 &sensor_dev_attr_adc0_in.dev_attr.attr,
115 &sensor_dev_attr_adc1_in.dev_attr.attr,
116 &sensor_dev_attr_adc2_in.dev_attr.attr,
117 &sensor_dev_attr_adc3_in.dev_attr.attr,
118 NULL,
119};
120
121static const struct attribute_group max1111_attr_group = {
122 .attrs = max1111_attributes,
123};
124
125static int setup_transfer(struct max1111_data *data)
126{
127 struct spi_message *m;
128 struct spi_transfer *x;
129
130 data->tx_buf = kmalloc(MAX1111_TX_BUF_SIZE, GFP_KERNEL);
131 if (!data->tx_buf)
132 return -ENOMEM;
133
134 data->rx_buf = kmalloc(MAX1111_RX_BUF_SIZE, GFP_KERNEL);
135 if (!data->rx_buf) {
136 kfree(data->tx_buf);
137 return -ENOMEM;
138 }
139
140 m = &data->msg;
141 x = &data->xfer[0];
142
143 spi_message_init(m);
144
145 x->tx_buf = &data->tx_buf[0];
146 x->len = 1;
147 spi_message_add_tail(x, m);
148
149 x++;
150 x->rx_buf = &data->rx_buf[0];
151 x->len = 2;
152 spi_message_add_tail(x, m);
153
154 return 0;
155}
156
157static int __devinit max1111_probe(struct spi_device *spi)
158{
159 struct max1111_data *data;
160 int err;
161
162 spi->bits_per_word = 8;
163 spi->mode = SPI_MODE_0;
164 err = spi_setup(spi);
165 if (err < 0)
166 return err;
167
168 data = kzalloc(sizeof(struct max1111_data), GFP_KERNEL);
169 if (data == NULL) {
170 dev_err(&spi->dev, "failed to allocate memory\n");
171 return -ENOMEM;
172 }
173
174 err = setup_transfer(data);
175 if (err)
176 goto err_free_data;
177
178 data->spi = spi;
179 spi_set_drvdata(spi, data);
180
181 err = sysfs_create_group(&spi->dev.kobj, &max1111_attr_group);
182 if (err) {
183 dev_err(&spi->dev, "failed to create attribute group\n");
184 goto err_free_all;
185 }
186
187 data->hwmon_dev = hwmon_device_register(&spi->dev);
188 if (IS_ERR(data->hwmon_dev)) {
189 dev_err(&spi->dev, "failed to create hwmon device\n");
190 err = PTR_ERR(data->hwmon_dev);
191 goto err_remove;
192 }
193
194#ifdef CONFIG_SHARPSL_PM
195 the_max1111 = data;
196#endif
197 return 0;
198
199err_remove:
200 sysfs_remove_group(&spi->dev.kobj, &max1111_attr_group);
201err_free_all:
202 kfree(data->rx_buf);
203 kfree(data->tx_buf);
204err_free_data:
205 kfree(data);
206 return err;
207}
208
209static int __devexit max1111_remove(struct spi_device *spi)
210{
211 struct max1111_data *data = spi_get_drvdata(spi);
212
213 hwmon_device_unregister(data->hwmon_dev);
214 sysfs_remove_group(&spi->dev.kobj, &max1111_attr_group);
215 kfree(data->rx_buf);
216 kfree(data->tx_buf);
217 kfree(data);
218 return 0;
219}
220
221static struct spi_driver max1111_driver = {
222 .driver = {
223 .name = "max1111",
224 .owner = THIS_MODULE,
225 },
226 .probe = max1111_probe,
227 .remove = __devexit_p(max1111_remove),
228};
229
230static int __init max1111_init(void)
231{
232 return spi_register_driver(&max1111_driver);
233}
234module_init(max1111_init);
235
236static void __exit max1111_exit(void)
237{
238 spi_unregister_driver(&max1111_driver);
239}
240module_exit(max1111_exit);
241
242MODULE_AUTHOR("Eric Miao <eric.miao@marvell.com>");
243MODULE_DESCRIPTION("MAX1111 ADC Driver");
244MODULE_LICENSE("GPL");
diff --git a/drivers/hwmon/ultra45_env.c b/drivers/hwmon/ultra45_env.c
new file mode 100644
index 000000000000..68e90abeba96
--- /dev/null
+++ b/drivers/hwmon/ultra45_env.c
@@ -0,0 +1,320 @@
1/* ultra45_env.c: Driver for Ultra45 PIC16F747 environmental monitor.
2 *
3 * Copyright (C) 2008 David S. Miller <davem@davemloft.net>
4 */
5
6#include <linux/kernel.h>
7#include <linux/types.h>
8#include <linux/slab.h>
9#include <linux/of_device.h>
10#include <linux/io.h>
11#include <linux/hwmon.h>
12#include <linux/hwmon-sysfs.h>
13
14#define DRV_MODULE_VERSION "0.1"
15
16MODULE_AUTHOR("David S. Miller (davem@davemloft.net)");
17MODULE_DESCRIPTION("Ultra45 environmental monitor driver");
18MODULE_LICENSE("GPL");
19MODULE_VERSION(DRV_MODULE_VERSION);
20
21/* PIC device registers */
22#define REG_CMD 0x00UL
23#define REG_CMD_RESET 0x80
24#define REG_CMD_ESTAR 0x01
25#define REG_STAT 0x01UL
26#define REG_STAT_FWVER 0xf0
27#define REG_STAT_TGOOD 0x08
28#define REG_STAT_STALE 0x04
29#define REG_STAT_BUSY 0x02
30#define REG_STAT_FAULT 0x01
31#define REG_DATA 0x40UL
32#define REG_ADDR 0x41UL
33#define REG_SIZE 0x42UL
34
35/* Registers accessed indirectly via REG_DATA/REG_ADDR */
36#define IREG_FAN0 0x00
37#define IREG_FAN1 0x01
38#define IREG_FAN2 0x02
39#define IREG_FAN3 0x03
40#define IREG_FAN4 0x04
41#define IREG_FAN5 0x05
42#define IREG_LCL_TEMP 0x06
43#define IREG_RMT1_TEMP 0x07
44#define IREG_RMT2_TEMP 0x08
45#define IREG_RMT3_TEMP 0x09
46#define IREG_LM95221_TEMP 0x0a
47#define IREG_FIRE_TEMP 0x0b
48#define IREG_LSI1064_TEMP 0x0c
49#define IREG_FRONT_TEMP 0x0d
50#define IREG_FAN_STAT 0x0e
51#define IREG_VCORE0 0x0f
52#define IREG_VCORE1 0x10
53#define IREG_VMEM0 0x11
54#define IREG_VMEM1 0x12
55#define IREG_PSU_TEMP 0x13
56
57struct env {
58 void __iomem *regs;
59 spinlock_t lock;
60
61 struct device *hwmon_dev;
62};
63
64static u8 env_read(struct env *p, u8 ireg)
65{
66 u8 ret;
67
68 spin_lock(&p->lock);
69 writeb(ireg, p->regs + REG_ADDR);
70 ret = readb(p->regs + REG_DATA);
71 spin_unlock(&p->lock);
72
73 return ret;
74}
75
76static void env_write(struct env *p, u8 ireg, u8 val)
77{
78 spin_lock(&p->lock);
79 writeb(ireg, p->regs + REG_ADDR);
80 writeb(val, p->regs + REG_DATA);
81 spin_unlock(&p->lock);
82}
83
84/* There seems to be a adr7462 providing these values, thus a lot
85 * of these calculations are borrowed from the adt7470 driver.
86 */
87#define FAN_PERIOD_TO_RPM(x) ((90000 * 60) / (x))
88#define FAN_RPM_TO_PERIOD FAN_PERIOD_TO_RPM
89#define FAN_PERIOD_INVALID (0xff << 8)
90#define FAN_DATA_VALID(x) ((x) && (x) != FAN_PERIOD_INVALID)
91
92static ssize_t show_fan_speed(struct device *dev, struct device_attribute *attr, char *buf)
93{
94 int fan_nr = to_sensor_dev_attr(attr)->index;
95 struct env *p = dev_get_drvdata(dev);
96 int rpm, period;
97 u8 val;
98
99 val = env_read(p, IREG_FAN0 + fan_nr);
100 period = (int) val << 8;
101 if (FAN_DATA_VALID(period))
102 rpm = FAN_PERIOD_TO_RPM(period);
103 else
104 rpm = 0;
105
106 return sprintf(buf, "%d\n", rpm);
107}
108
109static ssize_t set_fan_speed(struct device *dev, struct device_attribute *attr,
110 const char *buf, size_t count)
111{
112 int fan_nr = to_sensor_dev_attr(attr)->index;
113 int rpm = simple_strtol(buf, NULL, 10);
114 struct env *p = dev_get_drvdata(dev);
115 int period;
116 u8 val;
117
118 if (!rpm)
119 return -EINVAL;
120
121 period = FAN_RPM_TO_PERIOD(rpm);
122 val = period >> 8;
123 env_write(p, IREG_FAN0 + fan_nr, val);
124
125 return count;
126}
127
128static ssize_t show_fan_fault(struct device *dev, struct device_attribute *attr, char *buf)
129{
130 int fan_nr = to_sensor_dev_attr(attr)->index;
131 struct env *p = dev_get_drvdata(dev);
132 u8 val = env_read(p, IREG_FAN_STAT);
133 return sprintf(buf, "%d\n", (val & (1 << fan_nr)) ? 1 : 0);
134}
135
136#define fan(index) \
137static SENSOR_DEVICE_ATTR(fan##index##_speed, S_IRUGO | S_IWUSR, \
138 show_fan_speed, set_fan_speed, index); \
139static SENSOR_DEVICE_ATTR(fan##index##_fault, S_IRUGO, \
140 show_fan_fault, NULL, index)
141
142fan(0);
143fan(1);
144fan(2);
145fan(3);
146fan(4);
147
148static SENSOR_DEVICE_ATTR(psu_fan_fault, S_IRUGO, show_fan_fault, NULL, 6);
149
150static ssize_t show_temp(struct device *dev, struct device_attribute *attr, char *buf)
151{
152 int temp_nr = to_sensor_dev_attr(attr)->index;
153 struct env *p = dev_get_drvdata(dev);
154 s8 val;
155
156 val = env_read(p, IREG_LCL_TEMP + temp_nr);
157 return sprintf(buf, "%d\n", ((int) val) - 64);
158}
159
160static SENSOR_DEVICE_ATTR(adt7462_local_temp, S_IRUGO, show_temp, NULL, 0);
161static SENSOR_DEVICE_ATTR(cpu0_temp, S_IRUGO, show_temp, NULL, 1);
162static SENSOR_DEVICE_ATTR(cpu1_temp, S_IRUGO, show_temp, NULL, 2);
163static SENSOR_DEVICE_ATTR(motherboard_temp, S_IRUGO, show_temp, NULL, 3);
164static SENSOR_DEVICE_ATTR(lm95221_local_temp, S_IRUGO, show_temp, NULL, 4);
165static SENSOR_DEVICE_ATTR(fire_temp, S_IRUGO, show_temp, NULL, 5);
166static SENSOR_DEVICE_ATTR(lsi1064_local_temp, S_IRUGO, show_temp, NULL, 6);
167static SENSOR_DEVICE_ATTR(front_panel_temp, S_IRUGO, show_temp, NULL, 7);
168static SENSOR_DEVICE_ATTR(psu_temp, S_IRUGO, show_temp, NULL, 13);
169
170static ssize_t show_stat_bit(struct device *dev, struct device_attribute *attr, char *buf)
171{
172 int index = to_sensor_dev_attr(attr)->index;
173 struct env *p = dev_get_drvdata(dev);
174 u8 val;
175
176 val = readb(p->regs + REG_STAT);
177 return sprintf(buf, "%d\n", (val & (1 << index)) ? 1 : 0);
178}
179
180static SENSOR_DEVICE_ATTR(fan_failure, S_IRUGO, show_stat_bit, NULL, 0);
181static SENSOR_DEVICE_ATTR(env_bus_busy, S_IRUGO, show_stat_bit, NULL, 1);
182static SENSOR_DEVICE_ATTR(env_data_stale, S_IRUGO, show_stat_bit, NULL, 2);
183static SENSOR_DEVICE_ATTR(tpm_self_test_passed, S_IRUGO, show_stat_bit, NULL, 3);
184
185static ssize_t show_fwver(struct device *dev, struct device_attribute *attr, char *buf)
186{
187 struct env *p = dev_get_drvdata(dev);
188 u8 val;
189
190 val = readb(p->regs + REG_STAT);
191 return sprintf(buf, "%d\n", val >> 4);
192}
193
194static SENSOR_DEVICE_ATTR(firmware_version, S_IRUGO, show_fwver, NULL, 0);
195
196static ssize_t show_name(struct device *dev, struct device_attribute *attr, char *buf)
197{
198 return sprintf(buf, "ultra45\n");
199}
200
201static SENSOR_DEVICE_ATTR(name, S_IRUGO, show_name, NULL, 0);
202
203static struct attribute *env_attributes[] = {
204 &sensor_dev_attr_fan0_speed.dev_attr.attr,
205 &sensor_dev_attr_fan0_fault.dev_attr.attr,
206 &sensor_dev_attr_fan1_speed.dev_attr.attr,
207 &sensor_dev_attr_fan1_fault.dev_attr.attr,
208 &sensor_dev_attr_fan2_speed.dev_attr.attr,
209 &sensor_dev_attr_fan2_fault.dev_attr.attr,
210 &sensor_dev_attr_fan3_speed.dev_attr.attr,
211 &sensor_dev_attr_fan3_fault.dev_attr.attr,
212 &sensor_dev_attr_fan4_speed.dev_attr.attr,
213 &sensor_dev_attr_fan4_fault.dev_attr.attr,
214 &sensor_dev_attr_psu_fan_fault.dev_attr.attr,
215 &sensor_dev_attr_adt7462_local_temp.dev_attr.attr,
216 &sensor_dev_attr_cpu0_temp.dev_attr.attr,
217 &sensor_dev_attr_cpu1_temp.dev_attr.attr,
218 &sensor_dev_attr_motherboard_temp.dev_attr.attr,
219 &sensor_dev_attr_lm95221_local_temp.dev_attr.attr,
220 &sensor_dev_attr_fire_temp.dev_attr.attr,
221 &sensor_dev_attr_lsi1064_local_temp.dev_attr.attr,
222 &sensor_dev_attr_front_panel_temp.dev_attr.attr,
223 &sensor_dev_attr_psu_temp.dev_attr.attr,
224 &sensor_dev_attr_fan_failure.dev_attr.attr,
225 &sensor_dev_attr_env_bus_busy.dev_attr.attr,
226 &sensor_dev_attr_env_data_stale.dev_attr.attr,
227 &sensor_dev_attr_tpm_self_test_passed.dev_attr.attr,
228 &sensor_dev_attr_firmware_version.dev_attr.attr,
229 &sensor_dev_attr_name.dev_attr.attr,
230 NULL,
231};
232
233static const struct attribute_group env_group = {
234 .attrs = env_attributes,
235};
236
237static int __devinit env_probe(struct of_device *op,
238 const struct of_device_id *match)
239{
240 struct env *p = kzalloc(sizeof(*p), GFP_KERNEL);
241 int err = -ENOMEM;
242
243 if (!p)
244 goto out;
245
246 spin_lock_init(&p->lock);
247
248 p->regs = of_ioremap(&op->resource[0], 0, REG_SIZE, "pic16f747");
249 if (!p->regs)
250 goto out_free;
251
252 err = sysfs_create_group(&op->dev.kobj, &env_group);
253 if (err)
254 goto out_iounmap;
255
256 p->hwmon_dev = hwmon_device_register(&op->dev);
257 if (IS_ERR(p->hwmon_dev)) {
258 err = PTR_ERR(p->hwmon_dev);
259 goto out_sysfs_remove_group;
260 }
261
262 dev_set_drvdata(&op->dev, p);
263 err = 0;
264
265out:
266 return err;
267
268out_sysfs_remove_group:
269 sysfs_remove_group(&op->dev.kobj, &env_group);
270
271out_iounmap:
272 of_iounmap(&op->resource[0], p->regs, REG_SIZE);
273
274out_free:
275 kfree(p);
276 goto out;
277}
278
279static int __devexit env_remove(struct of_device *op)
280{
281 struct env *p = dev_get_drvdata(&op->dev);
282
283 if (p) {
284 sysfs_remove_group(&op->dev.kobj, &env_group);
285 hwmon_device_unregister(p->hwmon_dev);
286 of_iounmap(&op->resource[0], p->regs, REG_SIZE);
287 kfree(p);
288 }
289
290 return 0;
291}
292
293static const struct of_device_id env_match[] = {
294 {
295 .name = "env-monitor",
296 .compatible = "SUNW,ebus-pic16f747-env",
297 },
298 {},
299};
300MODULE_DEVICE_TABLE(of, env_match);
301
302static struct of_platform_driver env_driver = {
303 .name = "ultra45_env",
304 .match_table = env_match,
305 .probe = env_probe,
306 .remove = __devexit_p(env_remove),
307};
308
309static int __init env_init(void)
310{
311 return of_register_driver(&env_driver, &of_bus_type);
312}
313
314static void __exit env_exit(void)
315{
316 of_unregister_driver(&env_driver);
317}
318
319module_init(env_init);
320module_exit(env_exit);