diff options
Diffstat (limited to 'drivers/hwmon/dme1737.c')
-rw-r--r-- | drivers/hwmon/dme1737.c | 320 |
1 files changed, 153 insertions, 167 deletions
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. */ | ||
180 | struct dme1737_data { | 178 | struct 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 | ||
515 | static u8 dme1737_read(struct i2c_client *client, u8 reg) | 515 | static 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 | ||
535 | static s32 dme1737_write(struct i2c_client *client, u8 reg, u8 val) | 536 | static 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) | |||
555 | static struct dme1737_data *dme1737_update_device(struct device *dev) | 557 | static 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: | |||
2013 | static int dme1737_init_device(struct device *dev) | 2009 | static 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 | ||
2194 | static int dme1737_i2c_detect(struct i2c_adapter *adapter, int address, | 2190 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
2195 | int kind) | 2191 | static 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 | |||
2235 | static 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 | ||
2282 | exit_remove: | 2276 | exit_remove: |
2283 | dme1737_remove_files(dev); | 2277 | dme1737_remove_files(dev); |
2284 | exit_detach: | ||
2285 | i2c_detach_client(client); | ||
2286 | exit_kfree: | 2278 | exit_kfree: |
2287 | kfree(data); | 2279 | kfree(data); |
2288 | exit: | 2280 | exit: |
2289 | return err; | 2281 | return err; |
2290 | } | 2282 | } |
2291 | 2283 | ||
2292 | static int dme1737_i2c_attach_adapter(struct i2c_adapter *adapter) | 2284 | static 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 | |||
2301 | static 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 | ||
2295 | static const struct i2c_device_id dme1737_id[] = { | ||
2296 | { "dme1737", dme1737 }, | ||
2297 | { "sch5027", sch5027 }, | ||
2298 | { } | ||
2299 | }; | ||
2300 | MODULE_DEVICE_TABLE(i2c, dme1737_id); | ||
2301 | |||
2317 | static struct i2c_driver dme1737_i2c_driver = { | 2302 | static 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 | ||