aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/hwmon/dme17374
-rw-r--r--Documentation/hwmon/lm8511
-rw-r--r--MAINTAINERS6
-rw-r--r--drivers/hwmon/Kconfig25
-rw-r--r--drivers/hwmon/adt7473.c16
-rw-r--r--drivers/hwmon/dme1737.c297
-rw-r--r--drivers/hwmon/lm75.c282
-rw-r--r--drivers/hwmon/lm85.c672
8 files changed, 692 insertions, 621 deletions
diff --git a/Documentation/hwmon/dme1737 b/Documentation/hwmon/dme1737
index 8f446070e64a..b1fe00999439 100644
--- a/Documentation/hwmon/dme1737
+++ b/Documentation/hwmon/dme1737
@@ -22,6 +22,10 @@ Module Parameters
22 and PWM output control functions. Using this parameter 22 and PWM output control functions. Using this parameter
23 shouldn't be required since the BIOS usually takes care 23 shouldn't be required since the BIOS usually takes care
24 of this. 24 of this.
25* probe_all_addr: bool Include non-standard LPC addresses 0x162e and 0x164e
26 when probing for ISA devices. This is required for the
27 following boards:
28 - VIA EPIA SN18000
25 29
26Note that there is no need to use this parameter if the driver loads without 30Note that there is no need to use this parameter if the driver loads without
27complaining. The driver will say so if it is necessary. 31complaining. The driver will say so if it is necessary.
diff --git a/Documentation/hwmon/lm85 b/Documentation/hwmon/lm85
index 9549237530cf..6d41db7f17f8 100644
--- a/Documentation/hwmon/lm85
+++ b/Documentation/hwmon/lm85
@@ -96,11 +96,6 @@ initial testing of the ADM1027 it was 1.00 degC steps. Analog Devices has
96confirmed this "bug". The ADT7463 is reported to work as described in the 96confirmed this "bug". The ADT7463 is reported to work as described in the
97documentation. The current lm85 driver does not show the offset register. 97documentation. The current lm85 driver does not show the offset register.
98 98
99The ADT7463 has a THERM asserted counter. This counter has a 22.76ms
100resolution and a range of 5.8 seconds. The driver implements a 32-bit
101accumulator of the counter value to extend the range to over a year. The
102counter will stay at it's max value until read.
103
104See the vendor datasheets for more information. There is application note 99See the vendor datasheets for more information. There is application note
105from National (AN-1260) with some additional information about the LM85. 100from National (AN-1260) with some additional information about the LM85.
106The Analog Devices datasheet is very detailed and describes a procedure for 101The Analog Devices datasheet is very detailed and describes a procedure for
@@ -206,13 +201,15 @@ Configuration choices:
206 201
207The National LM85's have two vendor specific configuration 202The National LM85's have two vendor specific configuration
208features. Tach. mode and Spinup Control. For more details on these, 203features. Tach. mode and Spinup Control. For more details on these,
209see the LM85 datasheet or Application Note AN-1260. 204see the LM85 datasheet or Application Note AN-1260. These features
205are not currently supported by the lm85 driver.
210 206
211The Analog Devices ADM1027 has several vendor specific enhancements. 207The Analog Devices ADM1027 has several vendor specific enhancements.
212The number of pulses-per-rev of the fans can be set, Tach monitoring 208The number of pulses-per-rev of the fans can be set, Tach monitoring
213can be optimized for PWM operation, and an offset can be applied to 209can be optimized for PWM operation, and an offset can be applied to
214the temperatures to compensate for systemic errors in the 210the temperatures to compensate for systemic errors in the
215measurements. 211measurements. These features are not currently supported by the lm85
212driver.
216 213
217In addition to the ADM1027 features, the ADT7463 also has Tmin control 214In addition to the ADM1027 features, the ADT7463 also has Tmin control
218and THERM asserted counts. Automatic Tmin control acts to adjust the 215and THERM asserted counts. Automatic Tmin control acts to adjust the
diff --git a/MAINTAINERS b/MAINTAINERS
index c65a5b9e3446..5e6d6ab82433 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1878,13 +1878,9 @@ W: http://gigaset307x.sourceforge.net/
1878S: Maintained 1878S: Maintained
1879 1879
1880HARDWARE MONITORING 1880HARDWARE MONITORING
1881P: Mark M. Hoffman
1882M: mhoffman@lightlink.com
1883L: lm-sensors@lm-sensors.org 1881L: lm-sensors@lm-sensors.org
1884W: http://www.lm-sensors.org/ 1882W: http://www.lm-sensors.org/
1885T: git lm-sensors.org:/kernel/mhoffman/hwmon-2.6.git testing 1883S: Orphaned
1886T: git lm-sensors.org:/kernel/mhoffman/hwmon-2.6.git release
1887S: Maintained
1888 1884
1889HARDWARE RANDOM NUMBER GENERATOR CORE 1885HARDWARE RANDOM NUMBER GENERATOR CORE
1890S: Orphaned 1886S: Orphaned
diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index 00ff53348491..c882fd05cf29 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -394,13 +394,24 @@ config SENSORS_LM75
394 tristate "National Semiconductor LM75 and compatibles" 394 tristate "National Semiconductor LM75 and compatibles"
395 depends on I2C 395 depends on I2C
396 help 396 help
397 If you say yes here you get support for National Semiconductor LM75 397 If you say yes here you get support for one common type of
398 sensor chips and clones: Dallas Semiconductor DS75 and DS1775 (in 398 temperature sensor chip, with models including:
399 9-bit precision mode), and TelCom (now Microchip) TCN75. 399
400 400 - Dallas Semiconductor DS75 and DS1775
401 The DS75 and DS1775 in 10- to 12-bit precision modes will require 401 - Maxim MAX6625 and MAX6626
402 a force module parameter. The driver will not handle the extra 402 - Microchip MCP980x
403 precision anyhow. 403 - National Semiconductor LM75
404 - NXP's LM75A
405 - ST Microelectronics STDS75
406 - TelCom (now Microchip) TCN75
407 - Texas Instruments TMP100, TMP101, TMP75, TMP175, TMP275
408
409 This driver supports driver model based binding through board
410 specific I2C device tables.
411
412 It also supports the "legacy" style of driver binding. To use
413 that with some chips which don't replicate LM75 quirks exactly,
414 you may need the "force" module parameter.
404 415
405 This driver can also be built as a module. If so, the module 416 This driver can also be built as a module. If so, the module
406 will be called lm75. 417 will be called lm75.
diff --git a/drivers/hwmon/adt7473.c b/drivers/hwmon/adt7473.c
index ce4a7cb5a116..3a0b63136479 100644
--- a/drivers/hwmon/adt7473.c
+++ b/drivers/hwmon/adt7473.c
@@ -39,32 +39,20 @@ I2C_CLIENT_INSMOD_1(adt7473);
39#define ADT7473_REG_BASE_ADDR 0x20 39#define ADT7473_REG_BASE_ADDR 0x20
40 40
41#define ADT7473_REG_VOLT_BASE_ADDR 0x21 41#define ADT7473_REG_VOLT_BASE_ADDR 0x21
42#define ADT7473_REG_VOLT_MAX_ADDR 0x22
43#define ADT7473_REG_VOLT_MIN_BASE_ADDR 0x46 42#define ADT7473_REG_VOLT_MIN_BASE_ADDR 0x46
44#define ADT7473_REG_VOLT_MIN_MAX_ADDR 0x49
45 43
46#define ADT7473_REG_TEMP_BASE_ADDR 0x25 44#define ADT7473_REG_TEMP_BASE_ADDR 0x25
47#define ADT7473_REG_TEMP_MAX_ADDR 0x27
48#define ADT7473_REG_TEMP_LIMITS_BASE_ADDR 0x4E 45#define ADT7473_REG_TEMP_LIMITS_BASE_ADDR 0x4E
49#define ADT7473_REG_TEMP_LIMITS_MAX_ADDR 0x53
50#define ADT7473_REG_TEMP_TMIN_BASE_ADDR 0x67 46#define ADT7473_REG_TEMP_TMIN_BASE_ADDR 0x67
51#define ADT7473_REG_TEMP_TMIN_MAX_ADDR 0x69
52#define ADT7473_REG_TEMP_TMAX_BASE_ADDR 0x6A 47#define ADT7473_REG_TEMP_TMAX_BASE_ADDR 0x6A
53#define ADT7473_REG_TEMP_TMAX_MAX_ADDR 0x6C
54 48
55#define ADT7473_REG_FAN_BASE_ADDR 0x28 49#define ADT7473_REG_FAN_BASE_ADDR 0x28
56#define ADT7473_REG_FAN_MAX_ADDR 0x2F
57#define ADT7473_REG_FAN_MIN_BASE_ADDR 0x54 50#define ADT7473_REG_FAN_MIN_BASE_ADDR 0x54
58#define ADT7473_REG_FAN_MIN_MAX_ADDR 0x5B
59 51
60#define ADT7473_REG_PWM_BASE_ADDR 0x30 52#define ADT7473_REG_PWM_BASE_ADDR 0x30
61#define ADT7473_REG_PWM_MAX_ADDR 0x32
62#define ADT7473_REG_PWM_MIN_BASE_ADDR 0x64 53#define ADT7473_REG_PWM_MIN_BASE_ADDR 0x64
63#define ADT7473_REG_PWM_MIN_MAX_ADDR 0x66
64#define ADT7473_REG_PWM_MAX_BASE_ADDR 0x38 54#define ADT7473_REG_PWM_MAX_BASE_ADDR 0x38
65#define ADT7473_REG_PWM_MAX_MAX_ADDR 0x3A
66#define ADT7473_REG_PWM_BHVR_BASE_ADDR 0x5C 55#define ADT7473_REG_PWM_BHVR_BASE_ADDR 0x5C
67#define ADT7473_REG_PWM_BHVR_MAX_ADDR 0x5E
68#define ADT7473_PWM_BHVR_MASK 0xE0 56#define ADT7473_PWM_BHVR_MASK 0xE0
69#define ADT7473_PWM_BHVR_SHIFT 5 57#define ADT7473_PWM_BHVR_SHIFT 5
70 58
@@ -102,7 +90,6 @@ I2C_CLIENT_INSMOD_1(adt7473);
102#define ADT7473_FAN4_ALARM 0x20 90#define ADT7473_FAN4_ALARM 0x20
103#define ADT7473_R1T_SHORT 0x40 91#define ADT7473_R1T_SHORT 0x40
104#define ADT7473_R2T_SHORT 0x80 92#define ADT7473_R2T_SHORT 0x80
105#define ADT7473_REG_MAX_ADDR 0x80
106 93
107#define ALARM2(x) ((x) << 8) 94#define ALARM2(x) ((x) << 8)
108 95
@@ -583,10 +570,9 @@ static ssize_t set_max_duty_at_crit(struct device *dev,
583 struct i2c_client *client = to_i2c_client(dev); 570 struct i2c_client *client = to_i2c_client(dev);
584 struct adt7473_data *data = i2c_get_clientdata(client); 571 struct adt7473_data *data = i2c_get_clientdata(client);
585 int temp = simple_strtol(buf, NULL, 10); 572 int temp = simple_strtol(buf, NULL, 10);
586 temp = temp && 0xFF;
587 573
588 mutex_lock(&data->lock); 574 mutex_lock(&data->lock);
589 data->max_duty_at_overheat = temp; 575 data->max_duty_at_overheat = !!temp;
590 reg = i2c_smbus_read_byte_data(client, ADT7473_REG_CFG4); 576 reg = i2c_smbus_read_byte_data(client, ADT7473_REG_CFG4);
591 if (temp) 577 if (temp)
592 reg |= ADT7473_CFG4_MAX_DUTY_AT_OVT; 578 reg |= ADT7473_CFG4_MAX_DUTY_AT_OVT;
diff --git a/drivers/hwmon/dme1737.c b/drivers/hwmon/dme1737.c
index 7673f65877e1..5e2cf0aef480 100644
--- a/drivers/hwmon/dme1737.c
+++ b/drivers/hwmon/dme1737.c
@@ -48,6 +48,11 @@ static unsigned short force_id;
48module_param(force_id, ushort, 0); 48module_param(force_id, ushort, 0);
49MODULE_PARM_DESC(force_id, "Override the detected device ID"); 49MODULE_PARM_DESC(force_id, "Override the detected device ID");
50 50
51static int probe_all_addr;
52module_param(probe_all_addr, bool, 0);
53MODULE_PARM_DESC(probe_all_addr, "Include probing of non-standard LPC "
54 "addresses");
55
51/* Addresses to scan */ 56/* Addresses to scan */
52static const unsigned short normal_i2c[] = {0x2c, 0x2d, 0x2e, I2C_CLIENT_END}; 57static const unsigned short normal_i2c[] = {0x2c, 0x2d, 0x2e, I2C_CLIENT_END};
53 58
@@ -176,6 +181,7 @@ struct dme1737_data {
176 int valid; /* !=0 if following fields are valid */ 181 int valid; /* !=0 if following fields are valid */
177 unsigned long last_update; /* in jiffies */ 182 unsigned long last_update; /* in jiffies */
178 unsigned long last_vbat; /* in jiffies */ 183 unsigned long last_vbat; /* in jiffies */
184 enum chips type;
179 185
180 u8 vid; 186 u8 vid;
181 u8 pwm_rr_en; 187 u8 pwm_rr_en;
@@ -210,20 +216,27 @@ struct dme1737_data {
210}; 216};
211 217
212/* Nominal voltage values */ 218/* Nominal voltage values */
213static const int IN_NOMINAL[] = {5000, 2250, 3300, 5000, 12000, 3300, 3300}; 219static const int IN_NOMINAL_DME1737[] = {5000, 2250, 3300, 5000, 12000, 3300,
220 3300};
221static const int IN_NOMINAL_SCH311x[] = {2500, 1500, 3300, 5000, 12000, 3300,
222 3300};
223#define IN_NOMINAL(ix, type) (((type) == dme1737) ? \
224 IN_NOMINAL_DME1737[(ix)] : \
225 IN_NOMINAL_SCH311x[(ix)])
214 226
215/* Voltage input 227/* Voltage input
216 * Voltage inputs have 16 bits resolution, limit values have 8 bits 228 * Voltage inputs have 16 bits resolution, limit values have 8 bits
217 * resolution. */ 229 * resolution. */
218static inline int IN_FROM_REG(int reg, int ix, int res) 230static inline int IN_FROM_REG(int reg, int ix, int res, int type)
219{ 231{
220 return (reg * IN_NOMINAL[ix] + (3 << (res - 3))) / (3 << (res - 2)); 232 return (reg * IN_NOMINAL(ix, type) + (3 << (res - 3))) /
233 (3 << (res - 2));
221} 234}
222 235
223static inline int IN_TO_REG(int val, int ix) 236static inline int IN_TO_REG(int val, int ix, int type)
224{ 237{
225 return SENSORS_LIMIT((val * 192 + IN_NOMINAL[ix] / 2) / 238 return SENSORS_LIMIT((val * 192 + IN_NOMINAL(ix, type) / 2) /
226 IN_NOMINAL[ix], 0, 255); 239 IN_NOMINAL(ix, type), 0, 255);
227} 240}
228 241
229/* Temperature input 242/* Temperature input
@@ -722,13 +735,13 @@ static ssize_t show_in(struct device *dev, struct device_attribute *attr,
722 735
723 switch (fn) { 736 switch (fn) {
724 case SYS_IN_INPUT: 737 case SYS_IN_INPUT:
725 res = IN_FROM_REG(data->in[ix], ix, 16); 738 res = IN_FROM_REG(data->in[ix], ix, 16, data->type);
726 break; 739 break;
727 case SYS_IN_MIN: 740 case SYS_IN_MIN:
728 res = IN_FROM_REG(data->in_min[ix], ix, 8); 741 res = IN_FROM_REG(data->in_min[ix], ix, 8, data->type);
729 break; 742 break;
730 case SYS_IN_MAX: 743 case SYS_IN_MAX:
731 res = IN_FROM_REG(data->in_max[ix], ix, 8); 744 res = IN_FROM_REG(data->in_max[ix], ix, 8, data->type);
732 break; 745 break;
733 case SYS_IN_ALARM: 746 case SYS_IN_ALARM:
734 res = (data->alarms >> DME1737_BIT_ALARM_IN[ix]) & 0x01; 747 res = (data->alarms >> DME1737_BIT_ALARM_IN[ix]) & 0x01;
@@ -755,12 +768,12 @@ static ssize_t set_in(struct device *dev, struct device_attribute *attr,
755 mutex_lock(&data->update_lock); 768 mutex_lock(&data->update_lock);
756 switch (fn) { 769 switch (fn) {
757 case SYS_IN_MIN: 770 case SYS_IN_MIN:
758 data->in_min[ix] = IN_TO_REG(val, ix); 771 data->in_min[ix] = IN_TO_REG(val, ix, data->type);
759 dme1737_write(client, DME1737_REG_IN_MIN(ix), 772 dme1737_write(client, DME1737_REG_IN_MIN(ix),
760 data->in_min[ix]); 773 data->in_min[ix]);
761 break; 774 break;
762 case SYS_IN_MAX: 775 case SYS_IN_MAX:
763 data->in_max[ix] = IN_TO_REG(val, ix); 776 data->in_max[ix] = IN_TO_REG(val, ix, data->type);
764 dme1737_write(client, DME1737_REG_IN_MAX(ix), 777 dme1737_write(client, DME1737_REG_IN_MAX(ix),
765 data->in_max[ix]); 778 data->in_max[ix]);
766 break; 779 break;
@@ -1501,9 +1514,9 @@ SENSOR_DEVICE_ATTR_PWM_1TO3(3);
1501/* PWMs 5-6 */ 1514/* PWMs 5-6 */
1502 1515
1503#define SENSOR_DEVICE_ATTR_PWM_5TO6(ix) \ 1516#define SENSOR_DEVICE_ATTR_PWM_5TO6(ix) \
1504static SENSOR_DEVICE_ATTR_2(pwm##ix, S_IRUGO | S_IWUSR, \ 1517static SENSOR_DEVICE_ATTR_2(pwm##ix, S_IRUGO, \
1505 show_pwm, set_pwm, SYS_PWM, ix-1); \ 1518 show_pwm, set_pwm, SYS_PWM, ix-1); \
1506static SENSOR_DEVICE_ATTR_2(pwm##ix##_freq, S_IRUGO | S_IWUSR, \ 1519static SENSOR_DEVICE_ATTR_2(pwm##ix##_freq, S_IRUGO, \
1507 show_pwm, set_pwm, SYS_PWM_FREQ, ix-1); \ 1520 show_pwm, set_pwm, SYS_PWM_FREQ, ix-1); \
1508static SENSOR_DEVICE_ATTR_2(pwm##ix##_enable, S_IRUGO, \ 1521static SENSOR_DEVICE_ATTR_2(pwm##ix##_enable, S_IRUGO, \
1509 show_pwm, NULL, SYS_PWM_ENABLE, ix-1) 1522 show_pwm, NULL, SYS_PWM_ENABLE, ix-1)
@@ -1517,91 +1530,75 @@ static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm, set_vrm);
1517static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid, NULL); 1530static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid, NULL);
1518static DEVICE_ATTR(name, S_IRUGO, show_name, NULL); /* for ISA devices */ 1531static DEVICE_ATTR(name, S_IRUGO, show_name, NULL); /* for ISA devices */
1519 1532
1520#define SENSOR_DEV_ATTR_IN(ix) \
1521&sensor_dev_attr_in##ix##_input.dev_attr.attr, \
1522&sensor_dev_attr_in##ix##_min.dev_attr.attr, \
1523&sensor_dev_attr_in##ix##_max.dev_attr.attr, \
1524&sensor_dev_attr_in##ix##_alarm.dev_attr.attr
1525
1526/* These attributes are read-writeable only if the chip is *not* locked */
1527#define SENSOR_DEV_ATTR_TEMP_LOCK(ix) \
1528&sensor_dev_attr_temp##ix##_offset.dev_attr.attr
1529
1530#define SENSOR_DEV_ATTR_TEMP(ix) \
1531SENSOR_DEV_ATTR_TEMP_LOCK(ix), \
1532&sensor_dev_attr_temp##ix##_input.dev_attr.attr, \
1533&sensor_dev_attr_temp##ix##_min.dev_attr.attr, \
1534&sensor_dev_attr_temp##ix##_max.dev_attr.attr, \
1535&sensor_dev_attr_temp##ix##_alarm.dev_attr.attr, \
1536&sensor_dev_attr_temp##ix##_fault.dev_attr.attr
1537
1538/* These attributes are read-writeable only if the chip is *not* locked */
1539#define SENSOR_DEV_ATTR_ZONE_LOCK(ix) \
1540&sensor_dev_attr_zone##ix##_auto_point1_temp_hyst.dev_attr.attr, \
1541&sensor_dev_attr_zone##ix##_auto_point1_temp.dev_attr.attr, \
1542&sensor_dev_attr_zone##ix##_auto_point2_temp.dev_attr.attr, \
1543&sensor_dev_attr_zone##ix##_auto_point3_temp.dev_attr.attr
1544
1545#define SENSOR_DEV_ATTR_ZONE(ix) \
1546SENSOR_DEV_ATTR_ZONE_LOCK(ix), \
1547&sensor_dev_attr_zone##ix##_auto_channels_temp.dev_attr.attr
1548
1549#define SENSOR_DEV_ATTR_FAN_1TO4(ix) \
1550&sensor_dev_attr_fan##ix##_input.dev_attr.attr, \
1551&sensor_dev_attr_fan##ix##_min.dev_attr.attr, \
1552&sensor_dev_attr_fan##ix##_alarm.dev_attr.attr, \
1553&sensor_dev_attr_fan##ix##_type.dev_attr.attr
1554
1555#define SENSOR_DEV_ATTR_FAN_5TO6(ix) \
1556&sensor_dev_attr_fan##ix##_input.dev_attr.attr, \
1557&sensor_dev_attr_fan##ix##_min.dev_attr.attr, \
1558&sensor_dev_attr_fan##ix##_alarm.dev_attr.attr, \
1559&sensor_dev_attr_fan##ix##_max.dev_attr.attr
1560
1561/* These attributes are read-writeable only if the chip is *not* locked */
1562#define SENSOR_DEV_ATTR_PWM_1TO3_LOCK(ix) \
1563&sensor_dev_attr_pwm##ix##_freq.dev_attr.attr, \
1564&sensor_dev_attr_pwm##ix##_enable.dev_attr.attr, \
1565&sensor_dev_attr_pwm##ix##_ramp_rate.dev_attr.attr, \
1566&sensor_dev_attr_pwm##ix##_auto_channels_zone.dev_attr.attr, \
1567&sensor_dev_attr_pwm##ix##_auto_pwm_min.dev_attr.attr, \
1568&sensor_dev_attr_pwm##ix##_auto_point1_pwm.dev_attr.attr
1569
1570#define SENSOR_DEV_ATTR_PWM_1TO3(ix) \
1571SENSOR_DEV_ATTR_PWM_1TO3_LOCK(ix), \
1572&sensor_dev_attr_pwm##ix.dev_attr.attr, \
1573&sensor_dev_attr_pwm##ix##_auto_point2_pwm.dev_attr.attr
1574
1575/* These attributes are read-writeable only if the chip is *not* locked */
1576#define SENSOR_DEV_ATTR_PWM_5TO6_LOCK(ix) \
1577&sensor_dev_attr_pwm##ix.dev_attr.attr, \
1578&sensor_dev_attr_pwm##ix##_freq.dev_attr.attr
1579
1580#define SENSOR_DEV_ATTR_PWM_5TO6(ix) \
1581SENSOR_DEV_ATTR_PWM_5TO6_LOCK(ix), \
1582&sensor_dev_attr_pwm##ix##_enable.dev_attr.attr
1583
1584/* This struct holds all the attributes that are always present and need to be 1533/* This struct holds all the attributes that are always present and need to be
1585 * created unconditionally. The attributes that need modification of their 1534 * created unconditionally. The attributes that need modification of their
1586 * permissions are created read-only and write permissions are added or removed 1535 * permissions are created read-only and write permissions are added or removed
1587 * on the fly when required */ 1536 * on the fly when required */
1588static struct attribute *dme1737_attr[] ={ 1537static struct attribute *dme1737_attr[] ={
1589 /* Voltages */ 1538 /* Voltages */
1590 SENSOR_DEV_ATTR_IN(0), 1539 &sensor_dev_attr_in0_input.dev_attr.attr,
1591 SENSOR_DEV_ATTR_IN(1), 1540 &sensor_dev_attr_in0_min.dev_attr.attr,
1592 SENSOR_DEV_ATTR_IN(2), 1541 &sensor_dev_attr_in0_max.dev_attr.attr,
1593 SENSOR_DEV_ATTR_IN(3), 1542 &sensor_dev_attr_in0_alarm.dev_attr.attr,
1594 SENSOR_DEV_ATTR_IN(4), 1543 &sensor_dev_attr_in1_input.dev_attr.attr,
1595 SENSOR_DEV_ATTR_IN(5), 1544 &sensor_dev_attr_in1_min.dev_attr.attr,
1596 SENSOR_DEV_ATTR_IN(6), 1545 &sensor_dev_attr_in1_max.dev_attr.attr,
1546 &sensor_dev_attr_in1_alarm.dev_attr.attr,
1547 &sensor_dev_attr_in2_input.dev_attr.attr,
1548 &sensor_dev_attr_in2_min.dev_attr.attr,
1549 &sensor_dev_attr_in2_max.dev_attr.attr,
1550 &sensor_dev_attr_in2_alarm.dev_attr.attr,
1551 &sensor_dev_attr_in3_input.dev_attr.attr,
1552 &sensor_dev_attr_in3_min.dev_attr.attr,
1553 &sensor_dev_attr_in3_max.dev_attr.attr,
1554 &sensor_dev_attr_in3_alarm.dev_attr.attr,
1555 &sensor_dev_attr_in4_input.dev_attr.attr,
1556 &sensor_dev_attr_in4_min.dev_attr.attr,
1557 &sensor_dev_attr_in4_max.dev_attr.attr,
1558 &sensor_dev_attr_in4_alarm.dev_attr.attr,
1559 &sensor_dev_attr_in5_input.dev_attr.attr,
1560 &sensor_dev_attr_in5_min.dev_attr.attr,
1561 &sensor_dev_attr_in5_max.dev_attr.attr,
1562 &sensor_dev_attr_in5_alarm.dev_attr.attr,
1563 &sensor_dev_attr_in6_input.dev_attr.attr,
1564 &sensor_dev_attr_in6_min.dev_attr.attr,
1565 &sensor_dev_attr_in6_max.dev_attr.attr,
1566 &sensor_dev_attr_in6_alarm.dev_attr.attr,
1597 /* Temperatures */ 1567 /* Temperatures */
1598 SENSOR_DEV_ATTR_TEMP(1), 1568 &sensor_dev_attr_temp1_input.dev_attr.attr,
1599 SENSOR_DEV_ATTR_TEMP(2), 1569 &sensor_dev_attr_temp1_min.dev_attr.attr,
1600 SENSOR_DEV_ATTR_TEMP(3), 1570 &sensor_dev_attr_temp1_max.dev_attr.attr,
1571 &sensor_dev_attr_temp1_alarm.dev_attr.attr,
1572 &sensor_dev_attr_temp1_fault.dev_attr.attr,
1573 &sensor_dev_attr_temp1_offset.dev_attr.attr,
1574 &sensor_dev_attr_temp2_input.dev_attr.attr,
1575 &sensor_dev_attr_temp2_min.dev_attr.attr,
1576 &sensor_dev_attr_temp2_max.dev_attr.attr,
1577 &sensor_dev_attr_temp2_alarm.dev_attr.attr,
1578 &sensor_dev_attr_temp2_fault.dev_attr.attr,
1579 &sensor_dev_attr_temp2_offset.dev_attr.attr,
1580 &sensor_dev_attr_temp3_input.dev_attr.attr,
1581 &sensor_dev_attr_temp3_min.dev_attr.attr,
1582 &sensor_dev_attr_temp3_max.dev_attr.attr,
1583 &sensor_dev_attr_temp3_alarm.dev_attr.attr,
1584 &sensor_dev_attr_temp3_fault.dev_attr.attr,
1585 &sensor_dev_attr_temp3_offset.dev_attr.attr,
1601 /* Zones */ 1586 /* Zones */
1602 SENSOR_DEV_ATTR_ZONE(1), 1587 &sensor_dev_attr_zone1_auto_point1_temp_hyst.dev_attr.attr,
1603 SENSOR_DEV_ATTR_ZONE(2), 1588 &sensor_dev_attr_zone1_auto_point1_temp.dev_attr.attr,
1604 SENSOR_DEV_ATTR_ZONE(3), 1589 &sensor_dev_attr_zone1_auto_point2_temp.dev_attr.attr,
1590 &sensor_dev_attr_zone1_auto_point3_temp.dev_attr.attr,
1591 &sensor_dev_attr_zone1_auto_channels_temp.dev_attr.attr,
1592 &sensor_dev_attr_zone2_auto_point1_temp_hyst.dev_attr.attr,
1593 &sensor_dev_attr_zone2_auto_point1_temp.dev_attr.attr,
1594 &sensor_dev_attr_zone2_auto_point2_temp.dev_attr.attr,
1595 &sensor_dev_attr_zone2_auto_point3_temp.dev_attr.attr,
1596 &sensor_dev_attr_zone2_auto_channels_temp.dev_attr.attr,
1597 &sensor_dev_attr_zone3_auto_point1_temp_hyst.dev_attr.attr,
1598 &sensor_dev_attr_zone3_auto_point1_temp.dev_attr.attr,
1599 &sensor_dev_attr_zone3_auto_point2_temp.dev_attr.attr,
1600 &sensor_dev_attr_zone3_auto_point3_temp.dev_attr.attr,
1601 &sensor_dev_attr_zone3_auto_channels_temp.dev_attr.attr,
1605 /* Misc */ 1602 /* Misc */
1606 &dev_attr_vrm.attr, 1603 &dev_attr_vrm.attr,
1607 &dev_attr_cpu0_vid.attr, 1604 &dev_attr_cpu0_vid.attr,
@@ -1616,23 +1613,48 @@ static const struct attribute_group dme1737_group = {
1616 * Their creation depends on the chip configuration which is determined during 1613 * Their creation depends on the chip configuration which is determined during
1617 * module load. */ 1614 * module load. */
1618static struct attribute *dme1737_attr_pwm1[] = { 1615static struct attribute *dme1737_attr_pwm1[] = {
1619 SENSOR_DEV_ATTR_PWM_1TO3(1), 1616 &sensor_dev_attr_pwm1.dev_attr.attr,
1617 &sensor_dev_attr_pwm1_freq.dev_attr.attr,
1618 &sensor_dev_attr_pwm1_enable.dev_attr.attr,
1619 &sensor_dev_attr_pwm1_ramp_rate.dev_attr.attr,
1620 &sensor_dev_attr_pwm1_auto_channels_zone.dev_attr.attr,
1621 &sensor_dev_attr_pwm1_auto_pwm_min.dev_attr.attr,
1622 &sensor_dev_attr_pwm1_auto_point1_pwm.dev_attr.attr,
1623 &sensor_dev_attr_pwm1_auto_point2_pwm.dev_attr.attr,
1620 NULL 1624 NULL
1621}; 1625};
1622static struct attribute *dme1737_attr_pwm2[] = { 1626static struct attribute *dme1737_attr_pwm2[] = {
1623 SENSOR_DEV_ATTR_PWM_1TO3(2), 1627 &sensor_dev_attr_pwm2.dev_attr.attr,
1628 &sensor_dev_attr_pwm2_freq.dev_attr.attr,
1629 &sensor_dev_attr_pwm2_enable.dev_attr.attr,
1630 &sensor_dev_attr_pwm2_ramp_rate.dev_attr.attr,
1631 &sensor_dev_attr_pwm2_auto_channels_zone.dev_attr.attr,
1632 &sensor_dev_attr_pwm2_auto_pwm_min.dev_attr.attr,
1633 &sensor_dev_attr_pwm2_auto_point1_pwm.dev_attr.attr,
1634 &sensor_dev_attr_pwm2_auto_point2_pwm.dev_attr.attr,
1624 NULL 1635 NULL
1625}; 1636};
1626static struct attribute *dme1737_attr_pwm3[] = { 1637static struct attribute *dme1737_attr_pwm3[] = {
1627 SENSOR_DEV_ATTR_PWM_1TO3(3), 1638 &sensor_dev_attr_pwm3.dev_attr.attr,
1639 &sensor_dev_attr_pwm3_freq.dev_attr.attr,
1640 &sensor_dev_attr_pwm3_enable.dev_attr.attr,
1641 &sensor_dev_attr_pwm3_ramp_rate.dev_attr.attr,
1642 &sensor_dev_attr_pwm3_auto_channels_zone.dev_attr.attr,
1643 &sensor_dev_attr_pwm3_auto_pwm_min.dev_attr.attr,
1644 &sensor_dev_attr_pwm3_auto_point1_pwm.dev_attr.attr,
1645 &sensor_dev_attr_pwm3_auto_point2_pwm.dev_attr.attr,
1628 NULL 1646 NULL
1629}; 1647};
1630static struct attribute *dme1737_attr_pwm5[] = { 1648static struct attribute *dme1737_attr_pwm5[] = {
1631 SENSOR_DEV_ATTR_PWM_5TO6(5), 1649 &sensor_dev_attr_pwm5.dev_attr.attr,
1650 &sensor_dev_attr_pwm5_freq.dev_attr.attr,
1651 &sensor_dev_attr_pwm5_enable.dev_attr.attr,
1632 NULL 1652 NULL
1633}; 1653};
1634static struct attribute *dme1737_attr_pwm6[] = { 1654static struct attribute *dme1737_attr_pwm6[] = {
1635 SENSOR_DEV_ATTR_PWM_5TO6(6), 1655 &sensor_dev_attr_pwm6.dev_attr.attr,
1656 &sensor_dev_attr_pwm6_freq.dev_attr.attr,
1657 &sensor_dev_attr_pwm6_enable.dev_attr.attr,
1636 NULL 1658 NULL
1637}; 1659};
1638 1660
@@ -1649,27 +1671,45 @@ static const struct attribute_group dme1737_pwm_group[] = {
1649 * Their creation depends on the chip configuration which is determined during 1671 * Their creation depends on the chip configuration which is determined during
1650 * module load. */ 1672 * module load. */
1651static struct attribute *dme1737_attr_fan1[] = { 1673static struct attribute *dme1737_attr_fan1[] = {
1652 SENSOR_DEV_ATTR_FAN_1TO4(1), 1674 &sensor_dev_attr_fan1_input.dev_attr.attr,
1675 &sensor_dev_attr_fan1_min.dev_attr.attr,
1676 &sensor_dev_attr_fan1_alarm.dev_attr.attr,
1677 &sensor_dev_attr_fan1_type.dev_attr.attr,
1653 NULL 1678 NULL
1654}; 1679};
1655static struct attribute *dme1737_attr_fan2[] = { 1680static struct attribute *dme1737_attr_fan2[] = {
1656 SENSOR_DEV_ATTR_FAN_1TO4(2), 1681 &sensor_dev_attr_fan2_input.dev_attr.attr,
1682 &sensor_dev_attr_fan2_min.dev_attr.attr,
1683 &sensor_dev_attr_fan2_alarm.dev_attr.attr,
1684 &sensor_dev_attr_fan2_type.dev_attr.attr,
1657 NULL 1685 NULL
1658}; 1686};
1659static struct attribute *dme1737_attr_fan3[] = { 1687static struct attribute *dme1737_attr_fan3[] = {
1660 SENSOR_DEV_ATTR_FAN_1TO4(3), 1688 &sensor_dev_attr_fan3_input.dev_attr.attr,
1689 &sensor_dev_attr_fan3_min.dev_attr.attr,
1690 &sensor_dev_attr_fan3_alarm.dev_attr.attr,
1691 &sensor_dev_attr_fan3_type.dev_attr.attr,
1661 NULL 1692 NULL
1662}; 1693};
1663static struct attribute *dme1737_attr_fan4[] = { 1694static struct attribute *dme1737_attr_fan4[] = {
1664 SENSOR_DEV_ATTR_FAN_1TO4(4), 1695 &sensor_dev_attr_fan4_input.dev_attr.attr,
1696 &sensor_dev_attr_fan4_min.dev_attr.attr,
1697 &sensor_dev_attr_fan4_alarm.dev_attr.attr,
1698 &sensor_dev_attr_fan4_type.dev_attr.attr,
1665 NULL 1699 NULL
1666}; 1700};
1667static struct attribute *dme1737_attr_fan5[] = { 1701static struct attribute *dme1737_attr_fan5[] = {
1668 SENSOR_DEV_ATTR_FAN_5TO6(5), 1702 &sensor_dev_attr_fan5_input.dev_attr.attr,
1703 &sensor_dev_attr_fan5_min.dev_attr.attr,
1704 &sensor_dev_attr_fan5_alarm.dev_attr.attr,
1705 &sensor_dev_attr_fan5_max.dev_attr.attr,
1669 NULL 1706 NULL
1670}; 1707};
1671static struct attribute *dme1737_attr_fan6[] = { 1708static struct attribute *dme1737_attr_fan6[] = {
1672 SENSOR_DEV_ATTR_FAN_5TO6(6), 1709 &sensor_dev_attr_fan6_input.dev_attr.attr,
1710 &sensor_dev_attr_fan6_min.dev_attr.attr,
1711 &sensor_dev_attr_fan6_alarm.dev_attr.attr,
1712 &sensor_dev_attr_fan6_max.dev_attr.attr,
1673 NULL 1713 NULL
1674}; 1714};
1675 1715
@@ -1686,13 +1726,22 @@ static const struct attribute_group dme1737_fan_group[] = {
1686 * writeable if the chip is *not* locked. Otherwise they stay read-only. */ 1726 * writeable if the chip is *not* locked. Otherwise they stay read-only. */
1687static struct attribute *dme1737_attr_lock[] = { 1727static struct attribute *dme1737_attr_lock[] = {
1688 /* Temperatures */ 1728 /* Temperatures */
1689 SENSOR_DEV_ATTR_TEMP_LOCK(1), 1729 &sensor_dev_attr_temp1_offset.dev_attr.attr,
1690 SENSOR_DEV_ATTR_TEMP_LOCK(2), 1730 &sensor_dev_attr_temp2_offset.dev_attr.attr,
1691 SENSOR_DEV_ATTR_TEMP_LOCK(3), 1731 &sensor_dev_attr_temp3_offset.dev_attr.attr,
1692 /* Zones */ 1732 /* Zones */
1693 SENSOR_DEV_ATTR_ZONE_LOCK(1), 1733 &sensor_dev_attr_zone1_auto_point1_temp_hyst.dev_attr.attr,
1694 SENSOR_DEV_ATTR_ZONE_LOCK(2), 1734 &sensor_dev_attr_zone1_auto_point1_temp.dev_attr.attr,
1695 SENSOR_DEV_ATTR_ZONE_LOCK(3), 1735 &sensor_dev_attr_zone1_auto_point2_temp.dev_attr.attr,
1736 &sensor_dev_attr_zone1_auto_point3_temp.dev_attr.attr,
1737 &sensor_dev_attr_zone2_auto_point1_temp_hyst.dev_attr.attr,
1738 &sensor_dev_attr_zone2_auto_point1_temp.dev_attr.attr,
1739 &sensor_dev_attr_zone2_auto_point2_temp.dev_attr.attr,
1740 &sensor_dev_attr_zone2_auto_point3_temp.dev_attr.attr,
1741 &sensor_dev_attr_zone3_auto_point1_temp_hyst.dev_attr.attr,
1742 &sensor_dev_attr_zone3_auto_point1_temp.dev_attr.attr,
1743 &sensor_dev_attr_zone3_auto_point2_temp.dev_attr.attr,
1744 &sensor_dev_attr_zone3_auto_point3_temp.dev_attr.attr,
1696 NULL 1745 NULL
1697}; 1746};
1698 1747
@@ -1704,23 +1753,40 @@ static const struct attribute_group dme1737_lock_group = {
1704 * writeable if the chip is *not* locked and the respective PWM is available. 1753 * writeable if the chip is *not* locked and the respective PWM is available.
1705 * Otherwise they stay read-only. */ 1754 * Otherwise they stay read-only. */
1706static struct attribute *dme1737_attr_pwm1_lock[] = { 1755static struct attribute *dme1737_attr_pwm1_lock[] = {
1707 SENSOR_DEV_ATTR_PWM_1TO3_LOCK(1), 1756 &sensor_dev_attr_pwm1_freq.dev_attr.attr,
1757 &sensor_dev_attr_pwm1_enable.dev_attr.attr,
1758 &sensor_dev_attr_pwm1_ramp_rate.dev_attr.attr,
1759 &sensor_dev_attr_pwm1_auto_channels_zone.dev_attr.attr,
1760 &sensor_dev_attr_pwm1_auto_pwm_min.dev_attr.attr,
1761 &sensor_dev_attr_pwm1_auto_point1_pwm.dev_attr.attr,
1708 NULL 1762 NULL
1709}; 1763};
1710static struct attribute *dme1737_attr_pwm2_lock[] = { 1764static struct attribute *dme1737_attr_pwm2_lock[] = {
1711 SENSOR_DEV_ATTR_PWM_1TO3_LOCK(2), 1765 &sensor_dev_attr_pwm2_freq.dev_attr.attr,
1766 &sensor_dev_attr_pwm2_enable.dev_attr.attr,
1767 &sensor_dev_attr_pwm2_ramp_rate.dev_attr.attr,
1768 &sensor_dev_attr_pwm2_auto_channels_zone.dev_attr.attr,
1769 &sensor_dev_attr_pwm2_auto_pwm_min.dev_attr.attr,
1770 &sensor_dev_attr_pwm2_auto_point1_pwm.dev_attr.attr,
1712 NULL 1771 NULL
1713}; 1772};
1714static struct attribute *dme1737_attr_pwm3_lock[] = { 1773static struct attribute *dme1737_attr_pwm3_lock[] = {
1715 SENSOR_DEV_ATTR_PWM_1TO3_LOCK(3), 1774 &sensor_dev_attr_pwm3_freq.dev_attr.attr,
1775 &sensor_dev_attr_pwm3_enable.dev_attr.attr,
1776 &sensor_dev_attr_pwm3_ramp_rate.dev_attr.attr,
1777 &sensor_dev_attr_pwm3_auto_channels_zone.dev_attr.attr,
1778 &sensor_dev_attr_pwm3_auto_pwm_min.dev_attr.attr,
1779 &sensor_dev_attr_pwm3_auto_point1_pwm.dev_attr.attr,
1716 NULL 1780 NULL
1717}; 1781};
1718static struct attribute *dme1737_attr_pwm5_lock[] = { 1782static struct attribute *dme1737_attr_pwm5_lock[] = {
1719 SENSOR_DEV_ATTR_PWM_5TO6_LOCK(5), 1783 &sensor_dev_attr_pwm5.dev_attr.attr,
1784 &sensor_dev_attr_pwm5_freq.dev_attr.attr,
1720 NULL 1785 NULL
1721}; 1786};
1722static struct attribute *dme1737_attr_pwm6_lock[] = { 1787static struct attribute *dme1737_attr_pwm6_lock[] = {
1723 SENSOR_DEV_ATTR_PWM_5TO6_LOCK(6), 1788 &sensor_dev_attr_pwm6.dev_attr.attr,
1789 &sensor_dev_attr_pwm6_freq.dev_attr.attr,
1724 NULL 1790 NULL
1725}; 1791};
1726 1792
@@ -2109,6 +2175,7 @@ static int dme1737_i2c_detect(struct i2c_adapter *adapter, int address,
2109 2175
2110 kind = dme1737; 2176 kind = dme1737;
2111 name = "dme1737"; 2177 name = "dme1737";
2178 data->type = kind;
2112 2179
2113 /* Fill in the remaining client fields and put it into the global 2180 /* Fill in the remaining client fields and put it into the global
2114 * list */ 2181 * list */
@@ -2301,6 +2368,7 @@ static int __devinit dme1737_isa_probe(struct platform_device *pdev)
2301 err = -ENODEV; 2368 err = -ENODEV;
2302 goto exit_kfree; 2369 goto exit_kfree;
2303 } 2370 }
2371 data->type = -1;
2304 2372
2305 /* Fill in the remaining client fields and initialize the mutex */ 2373 /* Fill in the remaining client fields and initialize the mutex */
2306 strlcpy(client->name, "sch311x", I2C_NAME_SIZE); 2374 strlcpy(client->name, "sch311x", I2C_NAME_SIZE);
@@ -2377,7 +2445,10 @@ static int __init dme1737_init(void)
2377 } 2445 }
2378 2446
2379 if (dme1737_isa_detect(0x2e, &addr) && 2447 if (dme1737_isa_detect(0x2e, &addr) &&
2380 dme1737_isa_detect(0x4e, &addr)) { 2448 dme1737_isa_detect(0x4e, &addr) &&
2449 (!probe_all_addr ||
2450 (dme1737_isa_detect(0x162e, &addr) &&
2451 dme1737_isa_detect(0x164e, &addr)))) {
2381 /* Return 0 if we didn't find an ISA device */ 2452 /* Return 0 if we didn't find an ISA device */
2382 return 0; 2453 return 0;
2383 } 2454 }
diff --git a/drivers/hwmon/lm75.c b/drivers/hwmon/lm75.c
index de698dc73020..7880c273c2c5 100644
--- a/drivers/hwmon/lm75.c
+++ b/drivers/hwmon/lm75.c
@@ -30,14 +30,37 @@
30#include "lm75.h" 30#include "lm75.h"
31 31
32 32
33/* Addresses to scan */ 33/*
34 * This driver handles the LM75 and compatible digital temperature sensors.
35 * Only types which are _not_ listed in I2C_CLIENT_INSMOD_*() need to be
36 * listed here. We start at 9 since I2C_CLIENT_INSMOD_*() currently allow
37 * definition of up to 8 chip types (plus zero).
38 */
39
40enum lm75_type { /* keep sorted in alphabetical order */
41 ds1775 = 9,
42 ds75,
43 /* lm75 -- in I2C_CLIENT_INSMOD_1() */
44 lm75a,
45 max6625,
46 max6626,
47 mcp980x,
48 stds75,
49 tcn75,
50 tmp100,
51 tmp101,
52 tmp175,
53 tmp275,
54 tmp75,
55};
56
57/* Addresses scanned by legacy style driver binding */
34static const unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b, 0x4c, 58static const unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b, 0x4c,
35 0x4d, 0x4e, 0x4f, I2C_CLIENT_END }; 59 0x4d, 0x4e, 0x4f, I2C_CLIENT_END };
36 60
37/* Insmod parameters */ 61/* Insmod parameters (only for legacy style driver binding) */
38I2C_CLIENT_INSMOD_1(lm75); 62I2C_CLIENT_INSMOD_1(lm75);
39 63
40/* Many LM75 constants specified below */
41 64
42/* The LM75 registers */ 65/* The LM75 registers */
43#define LM75_REG_CONF 0x01 66#define LM75_REG_CONF 0x01
@@ -49,10 +72,11 @@ static const u8 LM75_REG_TEMP[3] = {
49 72
50/* Each client has this additional data */ 73/* Each client has this additional data */
51struct lm75_data { 74struct lm75_data {
52 struct i2c_client client; 75 struct i2c_client *client;
53 struct device *hwmon_dev; 76 struct device *hwmon_dev;
54 struct mutex update_lock; 77 struct mutex update_lock;
55 char valid; /* !=0 if following fields are valid */ 78 u8 orig_conf;
79 char valid; /* !=0 if registers are valid */
56 unsigned long last_updated; /* In jiffies */ 80 unsigned long last_updated; /* In jiffies */
57 u16 temp[3]; /* Register values, 81 u16 temp[3]; /* Register values,
58 0 = input 82 0 = input
@@ -60,23 +84,14 @@ struct lm75_data {
60 2 = hyst */ 84 2 = hyst */
61}; 85};
62 86
63static int lm75_attach_adapter(struct i2c_adapter *adapter);
64static int lm75_detect(struct i2c_adapter *adapter, int address, int kind);
65static void lm75_init_client(struct i2c_client *client);
66static int lm75_detach_client(struct i2c_client *client);
67static int lm75_read_value(struct i2c_client *client, u8 reg); 87static int lm75_read_value(struct i2c_client *client, u8 reg);
68static int lm75_write_value(struct i2c_client *client, u8 reg, u16 value); 88static int lm75_write_value(struct i2c_client *client, u8 reg, u16 value);
69static struct lm75_data *lm75_update_device(struct device *dev); 89static struct lm75_data *lm75_update_device(struct device *dev);
70 90
71 91
72/* This is the driver that will be inserted */ 92/*-----------------------------------------------------------------------*/
73static struct i2c_driver lm75_driver = { 93
74 .driver = { 94/* sysfs attributes for hwmon */
75 .name = "lm75",
76 },
77 .attach_adapter = lm75_attach_adapter,
78 .detach_client = lm75_detach_client,
79};
80 95
81static ssize_t show_temp(struct device *dev, struct device_attribute *da, 96static ssize_t show_temp(struct device *dev, struct device_attribute *da,
82 char *buf) 97 char *buf)
@@ -109,13 +124,6 @@ static SENSOR_DEVICE_ATTR(temp1_max_hyst, S_IWUSR | S_IRUGO,
109 show_temp, set_temp, 2); 124 show_temp, set_temp, 2);
110static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0); 125static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0);
111 126
112static int lm75_attach_adapter(struct i2c_adapter *adapter)
113{
114 if (!(adapter->class & I2C_CLASS_HWMON))
115 return 0;
116 return i2c_probe(adapter, &addr_data, lm75_detect);
117}
118
119static struct attribute *lm75_attributes[] = { 127static struct attribute *lm75_attributes[] = {
120 &sensor_dev_attr_temp1_input.dev_attr.attr, 128 &sensor_dev_attr_temp1_input.dev_attr.attr,
121 &sensor_dev_attr_temp1_max.dev_attr.attr, 129 &sensor_dev_attr_temp1_max.dev_attr.attr,
@@ -128,32 +136,144 @@ static const struct attribute_group lm75_group = {
128 .attrs = lm75_attributes, 136 .attrs = lm75_attributes,
129}; 137};
130 138
139/*-----------------------------------------------------------------------*/
140
141/* "New style" I2C driver binding -- following the driver model */
142
143static int
144lm75_probe(struct i2c_client *client, const struct i2c_device_id *id)
145{
146 struct lm75_data *data;
147 int status;
148 u8 set_mask, clr_mask;
149 int new;
150
151 if (!i2c_check_functionality(client->adapter,
152 I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA))
153 return -EIO;
154
155 data = kzalloc(sizeof(struct lm75_data), GFP_KERNEL);
156 if (!data)
157 return -ENOMEM;
158
159 i2c_set_clientdata(client, data);
160
161 data->client = client;
162 mutex_init(&data->update_lock);
163
164 /* Set to LM75 resolution (9 bits, 1/2 degree C) and range.
165 * Then tweak to be more precise when appropriate.
166 */
167 set_mask = 0;
168 clr_mask = (1 << 0) /* continuous conversions */
169 | (1 << 6) | (1 << 5); /* 9-bit mode */
170
171 /* configure as specified */
172 status = lm75_read_value(client, LM75_REG_CONF);
173 if (status < 0) {
174 dev_dbg(&client->dev, "Can't read config? %d\n", status);
175 goto exit_free;
176 }
177 data->orig_conf = status;
178 new = status & ~clr_mask;
179 new |= set_mask;
180 if (status != new)
181 lm75_write_value(client, LM75_REG_CONF, new);
182 dev_dbg(&client->dev, "Config %02x\n", new);
183
184 /* Register sysfs hooks */
185 status = sysfs_create_group(&client->dev.kobj, &lm75_group);
186 if (status)
187 goto exit_free;
188
189 data->hwmon_dev = hwmon_device_register(&client->dev);
190 if (IS_ERR(data->hwmon_dev)) {
191 status = PTR_ERR(data->hwmon_dev);
192 goto exit_remove;
193 }
194
195 dev_info(&client->dev, "%s: sensor '%s'\n",
196 data->hwmon_dev->bus_id, client->name);
197
198 return 0;
199
200exit_remove:
201 sysfs_remove_group(&client->dev.kobj, &lm75_group);
202exit_free:
203 i2c_set_clientdata(client, NULL);
204 kfree(data);
205 return status;
206}
207
208static int lm75_remove(struct i2c_client *client)
209{
210 struct lm75_data *data = i2c_get_clientdata(client);
211
212 hwmon_device_unregister(data->hwmon_dev);
213 sysfs_remove_group(&client->dev.kobj, &lm75_group);
214 lm75_write_value(client, LM75_REG_CONF, data->orig_conf);
215 i2c_set_clientdata(client, NULL);
216 kfree(data);
217 return 0;
218}
219
220static const struct i2c_device_id lm75_ids[] = {
221 { "ds1775", ds1775, },
222 { "ds75", ds75, },
223 { "lm75", lm75, },
224 { "lm75a", lm75a, },
225 { "max6625", max6625, },
226 { "max6626", max6626, },
227 { "mcp980x", mcp980x, },
228 { "stds75", stds75, },
229 { "tcn75", tcn75, },
230 { "tmp100", tmp100, },
231 { "tmp101", tmp101, },
232 { "tmp175", tmp175, },
233 { "tmp275", tmp275, },
234 { "tmp75", tmp75, },
235 { /* LIST END */ }
236};
237MODULE_DEVICE_TABLE(i2c, lm75_ids);
238
239static struct i2c_driver lm75_driver = {
240 .driver = {
241 .name = "lm75",
242 },
243 .probe = lm75_probe,
244 .remove = lm75_remove,
245 .id_table = lm75_ids,
246};
247
248/*-----------------------------------------------------------------------*/
249
250/* "Legacy" I2C driver binding */
251
252static struct i2c_driver lm75_legacy_driver;
253
131/* This function is called by i2c_probe */ 254/* This function is called by i2c_probe */
132static int lm75_detect(struct i2c_adapter *adapter, int address, int kind) 255static int lm75_detect(struct i2c_adapter *adapter, int address, int kind)
133{ 256{
134 int i; 257 int i;
135 struct i2c_client *new_client; 258 struct i2c_client *new_client;
136 struct lm75_data *data;
137 int err = 0; 259 int err = 0;
138 const char *name = "";
139 260
140 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA | 261 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA |
141 I2C_FUNC_SMBUS_WORD_DATA)) 262 I2C_FUNC_SMBUS_WORD_DATA))
142 goto exit; 263 goto exit;
143 264
144 /* OK. For now, we presume we have a valid client. We now create the 265 /* OK. For now, we presume we have a valid address. We create the
145 client structure, even though we cannot fill it completely yet. 266 client structure, even though there may be no sensor present.
146 But it allows us to access lm75_{read,write}_value. */ 267 But it allows us to use i2c_smbus_read_*_data() calls. */
147 if (!(data = kzalloc(sizeof(struct lm75_data), GFP_KERNEL))) { 268 new_client = kzalloc(sizeof *new_client, GFP_KERNEL);
269 if (!new_client) {
148 err = -ENOMEM; 270 err = -ENOMEM;
149 goto exit; 271 goto exit;
150 } 272 }
151 273
152 new_client = &data->client;
153 i2c_set_clientdata(new_client, data);
154 new_client->addr = address; 274 new_client->addr = address;
155 new_client->adapter = adapter; 275 new_client->adapter = adapter;
156 new_client->driver = &lm75_driver; 276 new_client->driver = &lm75_legacy_driver;
157 new_client->flags = 0; 277 new_client->flags = 0;
158 278
159 /* Now, we do the remaining detection. There is no identification- 279 /* Now, we do the remaining detection. There is no identification-
@@ -174,17 +294,17 @@ static int lm75_detect(struct i2c_adapter *adapter, int address, int kind)
174 || i2c_smbus_read_word_data(new_client, 5) != hyst 294 || i2c_smbus_read_word_data(new_client, 5) != hyst
175 || i2c_smbus_read_word_data(new_client, 6) != hyst 295 || i2c_smbus_read_word_data(new_client, 6) != hyst
176 || i2c_smbus_read_word_data(new_client, 7) != hyst) 296 || i2c_smbus_read_word_data(new_client, 7) != hyst)
177 goto exit_free; 297 goto exit_free;
178 os = i2c_smbus_read_word_data(new_client, 3); 298 os = i2c_smbus_read_word_data(new_client, 3);
179 if (i2c_smbus_read_word_data(new_client, 4) != os 299 if (i2c_smbus_read_word_data(new_client, 4) != os
180 || i2c_smbus_read_word_data(new_client, 5) != os 300 || i2c_smbus_read_word_data(new_client, 5) != os
181 || i2c_smbus_read_word_data(new_client, 6) != os 301 || i2c_smbus_read_word_data(new_client, 6) != os
182 || i2c_smbus_read_word_data(new_client, 7) != os) 302 || i2c_smbus_read_word_data(new_client, 7) != os)
183 goto exit_free; 303 goto exit_free;
184 304
185 /* Unused bits */ 305 /* Unused bits */
186 if (conf & 0xe0) 306 if (conf & 0xe0)
187 goto exit_free; 307 goto exit_free;
188 308
189 /* Addresses cycling */ 309 /* Addresses cycling */
190 for (i = 8; i < 0xff; i += 8) 310 for (i = 8; i < 0xff; i += 8)
@@ -194,58 +314,57 @@ static int lm75_detect(struct i2c_adapter *adapter, int address, int kind)
194 goto exit_free; 314 goto exit_free;
195 } 315 }
196 316
197 /* Determine the chip type - only one kind supported! */ 317 /* NOTE: we treat "force=..." and "force_lm75=..." the same.
198 if (kind <= 0) 318 * Only new-style driver binding distinguishes chip types.
199 kind = lm75; 319 */
200 320 strlcpy(new_client->name, "lm75", I2C_NAME_SIZE);
201 if (kind == lm75) {
202 name = "lm75";
203 }
204
205 /* Fill in the remaining client fields and put it into the global list */
206 strlcpy(new_client->name, name, I2C_NAME_SIZE);
207 data->valid = 0;
208 mutex_init(&data->update_lock);
209 321
210 /* Tell the I2C layer a new client has arrived */ 322 /* Tell the I2C layer a new client has arrived */
211 if ((err = i2c_attach_client(new_client))) 323 err = i2c_attach_client(new_client);
324 if (err)
212 goto exit_free; 325 goto exit_free;
213 326
214 /* Initialize the LM75 chip */ 327 err = lm75_probe(new_client, NULL);
215 lm75_init_client(new_client); 328 if (err < 0)
216
217 /* Register sysfs hooks */
218 if ((err = sysfs_create_group(&new_client->dev.kobj, &lm75_group)))
219 goto exit_detach; 329 goto exit_detach;
220 330
221 data->hwmon_dev = hwmon_device_register(&new_client->dev);
222 if (IS_ERR(data->hwmon_dev)) {
223 err = PTR_ERR(data->hwmon_dev);
224 goto exit_remove;
225 }
226
227 return 0; 331 return 0;
228 332
229exit_remove:
230 sysfs_remove_group(&new_client->dev.kobj, &lm75_group);
231exit_detach: 333exit_detach:
232 i2c_detach_client(new_client); 334 i2c_detach_client(new_client);
233exit_free: 335exit_free:
234 kfree(data); 336 kfree(new_client);
235exit: 337exit:
236 return err; 338 return err;
237} 339}
238 340
341static int lm75_attach_adapter(struct i2c_adapter *adapter)
342{
343 if (!(adapter->class & I2C_CLASS_HWMON))
344 return 0;
345 return i2c_probe(adapter, &addr_data, lm75_detect);
346}
347
239static int lm75_detach_client(struct i2c_client *client) 348static int lm75_detach_client(struct i2c_client *client)
240{ 349{
241 struct lm75_data *data = i2c_get_clientdata(client); 350 lm75_remove(client);
242 hwmon_device_unregister(data->hwmon_dev);
243 sysfs_remove_group(&client->dev.kobj, &lm75_group);
244 i2c_detach_client(client); 351 i2c_detach_client(client);
245 kfree(data); 352 kfree(client);
246 return 0; 353 return 0;
247} 354}
248 355
356static struct i2c_driver lm75_legacy_driver = {
357 .driver = {
358 .name = "lm75_legacy",
359 },
360 .attach_adapter = lm75_attach_adapter,
361 .detach_client = lm75_detach_client,
362};
363
364/*-----------------------------------------------------------------------*/
365
366/* register access */
367
249/* All registers are word-sized, except for the configuration register. 368/* All registers are word-sized, except for the configuration register.
250 LM75 uses a high-byte first convention, which is exactly opposite to 369 LM75 uses a high-byte first convention, which is exactly opposite to
251 the SMBus standard. */ 370 the SMBus standard. */
@@ -268,16 +387,6 @@ static int lm75_write_value(struct i2c_client *client, u8 reg, u16 value)
268 return i2c_smbus_write_word_data(client, reg, swab16(value)); 387 return i2c_smbus_write_word_data(client, reg, swab16(value));
269} 388}
270 389
271static void lm75_init_client(struct i2c_client *client)
272{
273 int reg;
274
275 /* Enable if in shutdown mode */
276 reg = lm75_read_value(client, LM75_REG_CONF);
277 if (reg >= 0 && (reg & 0x01))
278 lm75_write_value(client, LM75_REG_CONF, reg & 0xfe);
279}
280
281static struct lm75_data *lm75_update_device(struct device *dev) 390static struct lm75_data *lm75_update_device(struct device *dev)
282{ 391{
283 struct i2c_client *client = to_i2c_client(dev); 392 struct i2c_client *client = to_i2c_client(dev);
@@ -309,13 +418,28 @@ static struct lm75_data *lm75_update_device(struct device *dev)
309 return data; 418 return data;
310} 419}
311 420
421/*-----------------------------------------------------------------------*/
422
423/* module glue */
424
312static int __init sensors_lm75_init(void) 425static int __init sensors_lm75_init(void)
313{ 426{
314 return i2c_add_driver(&lm75_driver); 427 int status;
428
429 status = i2c_add_driver(&lm75_driver);
430 if (status < 0)
431 return status;
432
433 status = i2c_add_driver(&lm75_legacy_driver);
434 if (status < 0)
435 i2c_del_driver(&lm75_driver);
436
437 return status;
315} 438}
316 439
317static void __exit sensors_lm75_exit(void) 440static void __exit sensors_lm75_exit(void)
318{ 441{
442 i2c_del_driver(&lm75_legacy_driver);
319 i2c_del_driver(&lm75_driver); 443 i2c_del_driver(&lm75_driver);
320} 444}
321 445
diff --git a/drivers/hwmon/lm85.c b/drivers/hwmon/lm85.c
index ee5eca1c1921..12d446f54f97 100644
--- a/drivers/hwmon/lm85.c
+++ b/drivers/hwmon/lm85.c
@@ -1,7 +1,7 @@
1/* 1/*
2 lm85.c - Part of lm_sensors, Linux kernel modules for hardware 2 lm85.c - Part of lm_sensors, Linux kernel modules for hardware
3 monitoring 3 monitoring
4 Copyright (c) 1998, 1999 Frodo Looijaard <frodol@dds.nl> 4 Copyright (c) 1998, 1999 Frodo Looijaard <frodol@dds.nl>
5 Copyright (c) 2002, 2003 Philip Pokorny <ppokorny@penguincomputing.com> 5 Copyright (c) 2002, 2003 Philip Pokorny <ppokorny@penguincomputing.com>
6 Copyright (c) 2003 Margit Schubert-While <margitsw@t-online.de> 6 Copyright (c) 2003 Margit Schubert-While <margitsw@t-online.de>
7 Copyright (c) 2004 Justin Thiessen <jthiessen@penguincomputing.com> 7 Copyright (c) 2004 Justin Thiessen <jthiessen@penguincomputing.com>
@@ -51,24 +51,17 @@ I2C_CLIENT_INSMOD_6(lm85b, lm85c, adm1027, adt7463, emc6d100, emc6d102);
51#define LM85_REG_TEMP_MAX(nr) (0x4f + (nr) * 2) 51#define LM85_REG_TEMP_MAX(nr) (0x4f + (nr) * 2)
52 52
53/* Fan speeds are LSB, MSB (2 bytes) */ 53/* Fan speeds are LSB, MSB (2 bytes) */
54#define LM85_REG_FAN(nr) (0x28 + (nr) *2) 54#define LM85_REG_FAN(nr) (0x28 + (nr) * 2)
55#define LM85_REG_FAN_MIN(nr) (0x54 + (nr) *2) 55#define LM85_REG_FAN_MIN(nr) (0x54 + (nr) * 2)
56 56
57#define LM85_REG_PWM(nr) (0x30 + (nr)) 57#define LM85_REG_PWM(nr) (0x30 + (nr))
58 58
59#define ADT7463_REG_OPPOINT(nr) (0x33 + (nr))
60
61#define ADT7463_REG_TMIN_CTL1 0x36
62#define ADT7463_REG_TMIN_CTL2 0x37
63
64#define LM85_REG_DEVICE 0x3d
65#define LM85_REG_COMPANY 0x3e 59#define LM85_REG_COMPANY 0x3e
66#define LM85_REG_VERSTEP 0x3f 60#define LM85_REG_VERSTEP 0x3f
67/* These are the recognized values for the above regs */ 61/* These are the recognized values for the above regs */
68#define LM85_DEVICE_ADX 0x27
69#define LM85_COMPANY_NATIONAL 0x01 62#define LM85_COMPANY_NATIONAL 0x01
70#define LM85_COMPANY_ANALOG_DEV 0x41 63#define LM85_COMPANY_ANALOG_DEV 0x41
71#define LM85_COMPANY_SMSC 0x5c 64#define LM85_COMPANY_SMSC 0x5c
72#define LM85_VERSTEP_VMASK 0xf0 65#define LM85_VERSTEP_VMASK 0xf0
73#define LM85_VERSTEP_GENERIC 0x60 66#define LM85_VERSTEP_GENERIC 0x60
74#define LM85_VERSTEP_LM85C 0x60 67#define LM85_VERSTEP_LM85C 0x60
@@ -91,58 +84,45 @@ I2C_CLIENT_INSMOD_6(lm85b, lm85c, adm1027, adt7463, emc6d100, emc6d102);
91#define LM85_REG_AFAN_CONFIG(nr) (0x5c + (nr)) 84#define LM85_REG_AFAN_CONFIG(nr) (0x5c + (nr))
92#define LM85_REG_AFAN_RANGE(nr) (0x5f + (nr)) 85#define LM85_REG_AFAN_RANGE(nr) (0x5f + (nr))
93#define LM85_REG_AFAN_SPIKE1 0x62 86#define LM85_REG_AFAN_SPIKE1 0x62
94#define LM85_REG_AFAN_SPIKE2 0x63
95#define LM85_REG_AFAN_MINPWM(nr) (0x64 + (nr)) 87#define LM85_REG_AFAN_MINPWM(nr) (0x64 + (nr))
96#define LM85_REG_AFAN_LIMIT(nr) (0x67 + (nr)) 88#define LM85_REG_AFAN_LIMIT(nr) (0x67 + (nr))
97#define LM85_REG_AFAN_CRITICAL(nr) (0x6a + (nr)) 89#define LM85_REG_AFAN_CRITICAL(nr) (0x6a + (nr))
98#define LM85_REG_AFAN_HYST1 0x6d 90#define LM85_REG_AFAN_HYST1 0x6d
99#define LM85_REG_AFAN_HYST2 0x6e 91#define LM85_REG_AFAN_HYST2 0x6e
100 92
101#define LM85_REG_TACH_MODE 0x74
102#define LM85_REG_SPINUP_CTL 0x75
103
104#define ADM1027_REG_TEMP_OFFSET(nr) (0x70 + (nr))
105#define ADM1027_REG_CONFIG2 0x73
106#define ADM1027_REG_INTMASK1 0x74
107#define ADM1027_REG_INTMASK2 0x75
108#define ADM1027_REG_EXTEND_ADC1 0x76 93#define ADM1027_REG_EXTEND_ADC1 0x76
109#define ADM1027_REG_EXTEND_ADC2 0x77 94#define ADM1027_REG_EXTEND_ADC2 0x77
110#define ADM1027_REG_CONFIG3 0x78
111#define ADM1027_REG_FAN_PPR 0x7b
112
113#define ADT7463_REG_THERM 0x79
114#define ADT7463_REG_THERM_LIMIT 0x7A
115 95
116#define EMC6D100_REG_ALARM3 0x7d 96#define EMC6D100_REG_ALARM3 0x7d
117/* IN5, IN6 and IN7 */ 97/* IN5, IN6 and IN7 */
118#define EMC6D100_REG_IN(nr) (0x70 + ((nr)-5)) 98#define EMC6D100_REG_IN(nr) (0x70 + ((nr) - 5))
119#define EMC6D100_REG_IN_MIN(nr) (0x73 + ((nr)-5) * 2) 99#define EMC6D100_REG_IN_MIN(nr) (0x73 + ((nr) - 5) * 2)
120#define EMC6D100_REG_IN_MAX(nr) (0x74 + ((nr)-5) * 2) 100#define EMC6D100_REG_IN_MAX(nr) (0x74 + ((nr) - 5) * 2)
121#define EMC6D102_REG_EXTEND_ADC1 0x85 101#define EMC6D102_REG_EXTEND_ADC1 0x85
122#define EMC6D102_REG_EXTEND_ADC2 0x86 102#define EMC6D102_REG_EXTEND_ADC2 0x86
123#define EMC6D102_REG_EXTEND_ADC3 0x87 103#define EMC6D102_REG_EXTEND_ADC3 0x87
124#define EMC6D102_REG_EXTEND_ADC4 0x88 104#define EMC6D102_REG_EXTEND_ADC4 0x88
125 105
126 106
127/* Conversions. Rounding and limit checking is only done on the TO_REG 107/* Conversions. Rounding and limit checking is only done on the TO_REG
128 variants. Note that you should be a bit careful with which arguments 108 variants. Note that you should be a bit careful with which arguments
129 these macros are called: arguments may be evaluated more than once. 109 these macros are called: arguments may be evaluated more than once.
130 */ 110 */
131 111
132/* IN are scaled acording to built-in resistors */ 112/* IN are scaled acording to built-in resistors */
133static int lm85_scaling[] = { /* .001 Volts */ 113static const int lm85_scaling[] = { /* .001 Volts */
134 2500, 2250, 3300, 5000, 12000, 114 2500, 2250, 3300, 5000, 12000,
135 3300, 1500, 1800 /*EMC6D100*/ 115 3300, 1500, 1800 /*EMC6D100*/
136 }; 116};
137#define SCALE(val,from,to) (((val)*(to) + ((from)/2))/(from)) 117#define SCALE(val, from, to) (((val) * (to) + ((from) / 2)) / (from))
138 118
139#define INS_TO_REG(n,val) \ 119#define INS_TO_REG(n, val) \
140 SENSORS_LIMIT(SCALE(val,lm85_scaling[n],192),0,255) 120 SENSORS_LIMIT(SCALE(val, lm85_scaling[n], 192), 0, 255)
141 121
142#define INSEXT_FROM_REG(n,val,ext) \ 122#define INSEXT_FROM_REG(n, val, ext) \
143 SCALE(((val) << 4) + (ext), 192 << 4, lm85_scaling[n]) 123 SCALE(((val) << 4) + (ext), 192 << 4, lm85_scaling[n])
144 124
145#define INS_FROM_REG(n,val) SCALE((val), 192, lm85_scaling[n]) 125#define INS_FROM_REG(n, val) SCALE((val), 192, lm85_scaling[n])
146 126
147/* FAN speed is measured using 90kHz clock */ 127/* FAN speed is measured using 90kHz clock */
148static inline u16 FAN_TO_REG(unsigned long val) 128static inline u16 FAN_TO_REG(unsigned long val)
@@ -151,16 +131,17 @@ static inline u16 FAN_TO_REG(unsigned long val)
151 return 0xffff; 131 return 0xffff;
152 return SENSORS_LIMIT(5400000 / val, 1, 0xfffe); 132 return SENSORS_LIMIT(5400000 / val, 1, 0xfffe);
153} 133}
154#define FAN_FROM_REG(val) ((val)==0?-1:(val)==0xffff?0:5400000/(val)) 134#define FAN_FROM_REG(val) ((val) == 0 ? -1 : (val) == 0xffff ? 0 : \
135 5400000 / (val))
155 136
156/* Temperature is reported in .001 degC increments */ 137/* Temperature is reported in .001 degC increments */
157#define TEMP_TO_REG(val) \ 138#define TEMP_TO_REG(val) \
158 SENSORS_LIMIT(SCALE(val,1000,1),-127,127) 139 SENSORS_LIMIT(SCALE(val, 1000, 1), -127, 127)
159#define TEMPEXT_FROM_REG(val,ext) \ 140#define TEMPEXT_FROM_REG(val, ext) \
160 SCALE(((val) << 4) + (ext), 16, 1000) 141 SCALE(((val) << 4) + (ext), 16, 1000)
161#define TEMP_FROM_REG(val) ((val) * 1000) 142#define TEMP_FROM_REG(val) ((val) * 1000)
162 143
163#define PWM_TO_REG(val) (SENSORS_LIMIT(val,0,255)) 144#define PWM_TO_REG(val) SENSORS_LIMIT(val, 0, 255)
164#define PWM_FROM_REG(val) (val) 145#define PWM_FROM_REG(val) (val)
165 146
166 147
@@ -183,17 +164,17 @@ static inline u16 FAN_TO_REG(unsigned long val)
183 */ 164 */
184 165
185/* These are the zone temperature range encodings in .001 degree C */ 166/* These are the zone temperature range encodings in .001 degree C */
186static int lm85_range_map[] = { 167static const int lm85_range_map[] = {
187 2000, 2500, 3300, 4000, 5000, 6600, 168 2000, 2500, 3300, 4000, 5000, 6600, 8000, 10000,
188 8000, 10000, 13300, 16000, 20000, 26600, 169 13300, 16000, 20000, 26600, 32000, 40000, 53300, 80000
189 32000, 40000, 53300, 80000 170};
190 }; 171
191static int RANGE_TO_REG( int range ) 172static int RANGE_TO_REG(int range)
192{ 173{
193 int i; 174 int i;
194 175
195 if (range >= lm85_range_map[15]) 176 if (range >= lm85_range_map[15])
196 return 15 ; 177 return 15;
197 178
198 /* Find the closest match */ 179 /* Find the closest match */
199 for (i = 14; i >= 0; --i) { 180 for (i = 14; i >= 0; --i) {
@@ -207,28 +188,25 @@ static int RANGE_TO_REG( int range )
207 188
208 return 0; 189 return 0;
209} 190}
210#define RANGE_FROM_REG(val) (lm85_range_map[(val)&0x0f]) 191#define RANGE_FROM_REG(val) lm85_range_map[(val) & 0x0f]
211 192
212/* These are the Acoustic Enhancement, or Temperature smoothing encodings
213 * NOTE: The enable/disable bit is INCLUDED in these encodings as the
214 * MSB (bit 3, value 8). If the enable bit is 0, the encoded value
215 * is ignored, or set to 0.
216 */
217/* These are the PWM frequency encodings */ 193/* These are the PWM frequency encodings */
218static int lm85_freq_map[] = { /* .1 Hz */ 194static const int lm85_freq_map[] = { /* .1 Hz */
219 100, 150, 230, 300, 380, 470, 620, 940 195 100, 150, 230, 300, 380, 470, 620, 940
220 }; 196};
221static int FREQ_TO_REG( int freq ) 197
198static int FREQ_TO_REG(int freq)
222{ 199{
223 int i; 200 int i;
224 201
225 if( freq >= lm85_freq_map[7] ) { return 7 ; } 202 if (freq >= lm85_freq_map[7])
226 for( i = 0 ; i < 7 ; ++i ) 203 return 7;
227 if( freq <= lm85_freq_map[i] ) 204 for (i = 0; i < 7; ++i)
228 break ; 205 if (freq <= lm85_freq_map[i])
229 return( i & 0x07 ); 206 break;
207 return i;
230} 208}
231#define FREQ_FROM_REG(val) (lm85_freq_map[(val)&0x07]) 209#define FREQ_FROM_REG(val) lm85_freq_map[(val) & 0x07]
232 210
233/* Since we can't use strings, I'm abusing these numbers 211/* Since we can't use strings, I'm abusing these numbers
234 * to stand in for the following meanings: 212 * to stand in for the following meanings:
@@ -242,30 +220,23 @@ static int FREQ_TO_REG( int freq )
242 * -2 -- PWM responds to manual control 220 * -2 -- PWM responds to manual control
243 */ 221 */
244 222
245static int lm85_zone_map[] = { 1, 2, 3, -1, 0, 23, 123, -2 }; 223static const int lm85_zone_map[] = { 1, 2, 3, -1, 0, 23, 123, -2 };
246#define ZONE_FROM_REG(val) (lm85_zone_map[((val)>>5)&0x07]) 224#define ZONE_FROM_REG(val) lm85_zone_map[(val) >> 5]
247 225
248static int ZONE_TO_REG( int zone ) 226static int ZONE_TO_REG(int zone)
249{ 227{
250 int i; 228 int i;
251 229
252 for( i = 0 ; i <= 7 ; ++i ) 230 for (i = 0; i <= 7; ++i)
253 if( zone == lm85_zone_map[i] ) 231 if (zone == lm85_zone_map[i])
254 break ; 232 break;
255 if( i > 7 ) /* Not found. */ 233 if (i > 7) /* Not found. */
256 i = 3; /* Always 100% */ 234 i = 3; /* Always 100% */
257 return( (i & 0x07)<<5 ); 235 return i << 5;
258} 236}
259 237
260#define HYST_TO_REG(val) (SENSORS_LIMIT(((val)+500)/1000,0,15)) 238#define HYST_TO_REG(val) SENSORS_LIMIT(((val) + 500) / 1000, 0, 15)
261#define HYST_FROM_REG(val) ((val)*1000) 239#define HYST_FROM_REG(val) ((val) * 1000)
262
263#define OFFSET_TO_REG(val) (SENSORS_LIMIT((val)/25,-127,127))
264#define OFFSET_FROM_REG(val) ((val)*25)
265
266#define PPR_MASK(fan) (0x03<<(fan *2))
267#define PPR_TO_REG(val,fan) (SENSORS_LIMIT((val)-1,0,3)<<(fan *2))
268#define PPR_FROM_REG(val,fan) ((((val)>>(fan * 2))&0x03)+1)
269 240
270/* Chip sampling rates 241/* Chip sampling rates
271 * 242 *
@@ -292,11 +263,11 @@ struct lm85_zone {
292 u8 hyst; /* Low limit hysteresis. (0-15) */ 263 u8 hyst; /* Low limit hysteresis. (0-15) */
293 u8 range; /* Temp range, encoded */ 264 u8 range; /* Temp range, encoded */
294 s8 critical; /* "All fans ON" temp limit */ 265 s8 critical; /* "All fans ON" temp limit */
295 u8 off_desired; /* Actual "off" temperature specified. Preserved 266 u8 off_desired; /* Actual "off" temperature specified. Preserved
296 * to prevent "drift" as other autofan control 267 * to prevent "drift" as other autofan control
297 * values change. 268 * values change.
298 */ 269 */
299 u8 max_desired; /* Actual "max" temperature specified. Preserved 270 u8 max_desired; /* Actual "max" temperature specified. Preserved
300 * to prevent "drift" as other autofan control 271 * to prevent "drift" as other autofan control
301 * values change. 272 * values change.
302 */ 273 */
@@ -327,23 +298,13 @@ struct lm85_data {
327 s8 temp[3]; /* Register value */ 298 s8 temp[3]; /* Register value */
328 s8 temp_min[3]; /* Register value */ 299 s8 temp_min[3]; /* Register value */
329 s8 temp_max[3]; /* Register value */ 300 s8 temp_max[3]; /* Register value */
330 s8 temp_offset[3]; /* Register value */
331 u16 fan[4]; /* Register value */ 301 u16 fan[4]; /* Register value */
332 u16 fan_min[4]; /* Register value */ 302 u16 fan_min[4]; /* Register value */
333 u8 pwm[3]; /* Register value */ 303 u8 pwm[3]; /* Register value */
334 u8 spinup_ctl; /* Register encoding, combined */
335 u8 tach_mode; /* Register encoding, combined */
336 u8 temp_ext[3]; /* Decoded values */ 304 u8 temp_ext[3]; /* Decoded values */
337 u8 in_ext[8]; /* Decoded values */ 305 u8 in_ext[8]; /* Decoded values */
338 u8 fan_ppr; /* Register value */
339 u8 smooth[3]; /* Register encoding */
340 u8 vid; /* Register value */ 306 u8 vid; /* Register value */
341 u8 vrm; /* VRM version */ 307 u8 vrm; /* VRM version */
342 u8 syncpwm3; /* Saved PWM3 for TACH 2,3,4 config */
343 u8 oppoint[3]; /* Register value */
344 u16 tmin_ctl; /* Register value */
345 unsigned long therm_total; /* Cummulative therm count */
346 u8 therm_limit; /* Register value */
347 u32 alarms; /* Register encoding, combined */ 308 u32 alarms; /* Register encoding, combined */
348 struct lm85_autofan autofan[3]; 309 struct lm85_autofan autofan[3];
349 struct lm85_zone zone[3]; 310 struct lm85_zone zone[3];
@@ -355,9 +316,8 @@ static int lm85_detect(struct i2c_adapter *adapter, int address,
355static int lm85_detach_client(struct i2c_client *client); 316static int lm85_detach_client(struct i2c_client *client);
356 317
357static int lm85_read_value(struct i2c_client *client, u8 reg); 318static int lm85_read_value(struct i2c_client *client, u8 reg);
358static int lm85_write_value(struct i2c_client *client, u8 reg, int value); 319static void lm85_write_value(struct i2c_client *client, u8 reg, int value);
359static struct lm85_data *lm85_update_device(struct device *dev); 320static struct lm85_data *lm85_update_device(struct device *dev);
360static void lm85_init_client(struct i2c_client *client);
361 321
362 322
363static struct i2c_driver lm85_driver = { 323static struct i2c_driver lm85_driver = {
@@ -375,7 +335,7 @@ static ssize_t show_fan(struct device *dev, struct device_attribute *attr,
375{ 335{
376 int nr = to_sensor_dev_attr(attr)->index; 336 int nr = to_sensor_dev_attr(attr)->index;
377 struct lm85_data *data = lm85_update_device(dev); 337 struct lm85_data *data = lm85_update_device(dev);
378 return sprintf(buf,"%d\n", FAN_FROM_REG(data->fan[nr]) ); 338 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[nr]));
379} 339}
380 340
381static ssize_t show_fan_min(struct device *dev, struct device_attribute *attr, 341static ssize_t show_fan_min(struct device *dev, struct device_attribute *attr,
@@ -383,7 +343,7 @@ static ssize_t show_fan_min(struct device *dev, struct device_attribute *attr,
383{ 343{
384 int nr = to_sensor_dev_attr(attr)->index; 344 int nr = to_sensor_dev_attr(attr)->index;
385 struct lm85_data *data = lm85_update_device(dev); 345 struct lm85_data *data = lm85_update_device(dev);
386 return sprintf(buf,"%d\n", FAN_FROM_REG(data->fan_min[nr]) ); 346 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan_min[nr]));
387} 347}
388 348
389static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr, 349static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr,
@@ -414,7 +374,8 @@ show_fan_offset(4);
414 374
415/* vid, vrm, alarms */ 375/* vid, vrm, alarms */
416 376
417static ssize_t show_vid_reg(struct device *dev, struct device_attribute *attr, char *buf) 377static ssize_t show_vid_reg(struct device *dev, struct device_attribute *attr,
378 char *buf)
418{ 379{
419 struct lm85_data *data = lm85_update_device(dev); 380 struct lm85_data *data = lm85_update_device(dev);
420 int vid; 381 int vid;
@@ -432,13 +393,15 @@ static ssize_t show_vid_reg(struct device *dev, struct device_attribute *attr, c
432 393
433static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL); 394static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL);
434 395
435static ssize_t show_vrm_reg(struct device *dev, struct device_attribute *attr, char *buf) 396static ssize_t show_vrm_reg(struct device *dev, struct device_attribute *attr,
397 char *buf)
436{ 398{
437 struct lm85_data *data = dev_get_drvdata(dev); 399 struct lm85_data *data = dev_get_drvdata(dev);
438 return sprintf(buf, "%ld\n", (long) data->vrm); 400 return sprintf(buf, "%ld\n", (long) data->vrm);
439} 401}
440 402
441static ssize_t store_vrm_reg(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 403static ssize_t store_vrm_reg(struct device *dev, struct device_attribute *attr,
404 const char *buf, size_t count)
442{ 405{
443 struct lm85_data *data = dev_get_drvdata(dev); 406 struct lm85_data *data = dev_get_drvdata(dev);
444 data->vrm = simple_strtoul(buf, NULL, 10); 407 data->vrm = simple_strtoul(buf, NULL, 10);
@@ -447,7 +410,8 @@ static ssize_t store_vrm_reg(struct device *dev, struct device_attribute *attr,
447 410
448static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg); 411static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg);
449 412
450static ssize_t show_alarms_reg(struct device *dev, struct device_attribute *attr, char *buf) 413static ssize_t show_alarms_reg(struct device *dev, struct device_attribute
414 *attr, char *buf)
451{ 415{
452 struct lm85_data *data = lm85_update_device(dev); 416 struct lm85_data *data = lm85_update_device(dev);
453 return sprintf(buf, "%u\n", data->alarms); 417 return sprintf(buf, "%u\n", data->alarms);
@@ -488,7 +452,7 @@ static ssize_t show_pwm(struct device *dev, struct device_attribute *attr,
488{ 452{
489 int nr = to_sensor_dev_attr(attr)->index; 453 int nr = to_sensor_dev_attr(attr)->index;
490 struct lm85_data *data = lm85_update_device(dev); 454 struct lm85_data *data = lm85_update_device(dev);
491 return sprintf(buf,"%d\n", PWM_FROM_REG(data->pwm[nr]) ); 455 return sprintf(buf, "%d\n", PWM_FROM_REG(data->pwm[nr]));
492} 456}
493 457
494static ssize_t set_pwm(struct device *dev, struct device_attribute *attr, 458static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
@@ -581,17 +545,16 @@ static ssize_t show_in(struct device *dev, struct device_attribute *attr,
581{ 545{
582 int nr = to_sensor_dev_attr(attr)->index; 546 int nr = to_sensor_dev_attr(attr)->index;
583 struct lm85_data *data = lm85_update_device(dev); 547 struct lm85_data *data = lm85_update_device(dev);
584 return sprintf( buf, "%d\n", INSEXT_FROM_REG(nr, 548 return sprintf(buf, "%d\n", INSEXT_FROM_REG(nr, data->in[nr],
585 data->in[nr], 549 data->in_ext[nr]));
586 data->in_ext[nr]));
587} 550}
588 551
589static ssize_t show_in_min(struct device *dev, struct device_attribute *attr, 552static ssize_t show_in_min(struct device *dev, struct device_attribute *attr,
590 char *buf) 553 char *buf)
591{ 554{
592 int nr = to_sensor_dev_attr(attr)->index; 555 int nr = to_sensor_dev_attr(attr)->index;
593 struct lm85_data *data = lm85_update_device(dev); 556 struct lm85_data *data = lm85_update_device(dev);
594 return sprintf(buf,"%d\n", INS_FROM_REG(nr, data->in_min[nr]) ); 557 return sprintf(buf, "%d\n", INS_FROM_REG(nr, data->in_min[nr]));
595} 558}
596 559
597static ssize_t set_in_min(struct device *dev, struct device_attribute *attr, 560static ssize_t set_in_min(struct device *dev, struct device_attribute *attr,
@@ -614,7 +577,7 @@ static ssize_t show_in_max(struct device *dev, struct device_attribute *attr,
614{ 577{
615 int nr = to_sensor_dev_attr(attr)->index; 578 int nr = to_sensor_dev_attr(attr)->index;
616 struct lm85_data *data = lm85_update_device(dev); 579 struct lm85_data *data = lm85_update_device(dev);
617 return sprintf(buf,"%d\n", INS_FROM_REG(nr, data->in_max[nr]) ); 580 return sprintf(buf, "%d\n", INS_FROM_REG(nr, data->in_max[nr]));
618} 581}
619 582
620static ssize_t set_in_max(struct device *dev, struct device_attribute *attr, 583static ssize_t set_in_max(struct device *dev, struct device_attribute *attr,
@@ -656,8 +619,8 @@ static ssize_t show_temp(struct device *dev, struct device_attribute *attr,
656{ 619{
657 int nr = to_sensor_dev_attr(attr)->index; 620 int nr = to_sensor_dev_attr(attr)->index;
658 struct lm85_data *data = lm85_update_device(dev); 621 struct lm85_data *data = lm85_update_device(dev);
659 return sprintf(buf,"%d\n", TEMPEXT_FROM_REG(data->temp[nr], 622 return sprintf(buf, "%d\n", TEMPEXT_FROM_REG(data->temp[nr],
660 data->temp_ext[nr])); 623 data->temp_ext[nr]));
661} 624}
662 625
663static ssize_t show_temp_min(struct device *dev, struct device_attribute *attr, 626static ssize_t show_temp_min(struct device *dev, struct device_attribute *attr,
@@ -665,7 +628,7 @@ static ssize_t show_temp_min(struct device *dev, struct device_attribute *attr,
665{ 628{
666 int nr = to_sensor_dev_attr(attr)->index; 629 int nr = to_sensor_dev_attr(attr)->index;
667 struct lm85_data *data = lm85_update_device(dev); 630 struct lm85_data *data = lm85_update_device(dev);
668 return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_min[nr]) ); 631 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_min[nr]));
669} 632}
670 633
671static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr, 634static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr,
@@ -688,7 +651,7 @@ static ssize_t show_temp_max(struct device *dev, struct device_attribute *attr,
688{ 651{
689 int nr = to_sensor_dev_attr(attr)->index; 652 int nr = to_sensor_dev_attr(attr)->index;
690 struct lm85_data *data = lm85_update_device(dev); 653 struct lm85_data *data = lm85_update_device(dev);
691 return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_max[nr]) ); 654 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max[nr]));
692} 655}
693 656
694static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr, 657static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr,
@@ -697,7 +660,7 @@ static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr,
697 int nr = to_sensor_dev_attr(attr)->index; 660 int nr = to_sensor_dev_attr(attr)->index;
698 struct i2c_client *client = to_i2c_client(dev); 661 struct i2c_client *client = to_i2c_client(dev);
699 struct lm85_data *data = i2c_get_clientdata(client); 662 struct lm85_data *data = i2c_get_clientdata(client);
700 long val = simple_strtol(buf, NULL, 10); 663 long val = simple_strtol(buf, NULL, 10);
701 664
702 mutex_lock(&data->update_lock); 665 mutex_lock(&data->update_lock);
703 data->temp_max[nr] = TEMP_TO_REG(val); 666 data->temp_max[nr] = TEMP_TO_REG(val);
@@ -726,7 +689,7 @@ static ssize_t show_pwm_auto_channels(struct device *dev,
726{ 689{
727 int nr = to_sensor_dev_attr(attr)->index; 690 int nr = to_sensor_dev_attr(attr)->index;
728 struct lm85_data *data = lm85_update_device(dev); 691 struct lm85_data *data = lm85_update_device(dev);
729 return sprintf(buf,"%d\n", ZONE_FROM_REG(data->autofan[nr].config)); 692 return sprintf(buf, "%d\n", ZONE_FROM_REG(data->autofan[nr].config));
730} 693}
731 694
732static ssize_t set_pwm_auto_channels(struct device *dev, 695static ssize_t set_pwm_auto_channels(struct device *dev,
@@ -735,11 +698,11 @@ static ssize_t set_pwm_auto_channels(struct device *dev,
735 int nr = to_sensor_dev_attr(attr)->index; 698 int nr = to_sensor_dev_attr(attr)->index;
736 struct i2c_client *client = to_i2c_client(dev); 699 struct i2c_client *client = to_i2c_client(dev);
737 struct lm85_data *data = i2c_get_clientdata(client); 700 struct lm85_data *data = i2c_get_clientdata(client);
738 long val = simple_strtol(buf, NULL, 10); 701 long val = simple_strtol(buf, NULL, 10);
739 702
740 mutex_lock(&data->update_lock); 703 mutex_lock(&data->update_lock);
741 data->autofan[nr].config = (data->autofan[nr].config & (~0xe0)) 704 data->autofan[nr].config = (data->autofan[nr].config & (~0xe0))
742 | ZONE_TO_REG(val) ; 705 | ZONE_TO_REG(val);
743 lm85_write_value(client, LM85_REG_AFAN_CONFIG(nr), 706 lm85_write_value(client, LM85_REG_AFAN_CONFIG(nr),
744 data->autofan[nr].config); 707 data->autofan[nr].config);
745 mutex_unlock(&data->update_lock); 708 mutex_unlock(&data->update_lock);
@@ -751,7 +714,7 @@ static ssize_t show_pwm_auto_pwm_min(struct device *dev,
751{ 714{
752 int nr = to_sensor_dev_attr(attr)->index; 715 int nr = to_sensor_dev_attr(attr)->index;
753 struct lm85_data *data = lm85_update_device(dev); 716 struct lm85_data *data = lm85_update_device(dev);
754 return sprintf(buf,"%d\n", PWM_FROM_REG(data->autofan[nr].min_pwm)); 717 return sprintf(buf, "%d\n", PWM_FROM_REG(data->autofan[nr].min_pwm));
755} 718}
756 719
757static ssize_t set_pwm_auto_pwm_min(struct device *dev, 720static ssize_t set_pwm_auto_pwm_min(struct device *dev,
@@ -775,7 +738,7 @@ static ssize_t show_pwm_auto_pwm_minctl(struct device *dev,
775{ 738{
776 int nr = to_sensor_dev_attr(attr)->index; 739 int nr = to_sensor_dev_attr(attr)->index;
777 struct lm85_data *data = lm85_update_device(dev); 740 struct lm85_data *data = lm85_update_device(dev);
778 return sprintf(buf,"%d\n", data->autofan[nr].min_off); 741 return sprintf(buf, "%d\n", data->autofan[nr].min_off);
779} 742}
780 743
781static ssize_t set_pwm_auto_pwm_minctl(struct device *dev, 744static ssize_t set_pwm_auto_pwm_minctl(struct device *dev,
@@ -785,15 +748,15 @@ static ssize_t set_pwm_auto_pwm_minctl(struct device *dev,
785 struct i2c_client *client = to_i2c_client(dev); 748 struct i2c_client *client = to_i2c_client(dev);
786 struct lm85_data *data = i2c_get_clientdata(client); 749 struct lm85_data *data = i2c_get_clientdata(client);
787 long val = simple_strtol(buf, NULL, 10); 750 long val = simple_strtol(buf, NULL, 10);
751 u8 tmp;
788 752
789 mutex_lock(&data->update_lock); 753 mutex_lock(&data->update_lock);
790 data->autofan[nr].min_off = val; 754 data->autofan[nr].min_off = val;
791 lm85_write_value(client, LM85_REG_AFAN_SPIKE1, data->smooth[0] 755 tmp = lm85_read_value(client, LM85_REG_AFAN_SPIKE1);
792 | data->syncpwm3 756 tmp &= ~(0x20 << nr);
793 | (data->autofan[0].min_off ? 0x20 : 0) 757 if (data->autofan[nr].min_off)
794 | (data->autofan[1].min_off ? 0x40 : 0) 758 tmp |= 0x20 << nr;
795 | (data->autofan[2].min_off ? 0x80 : 0) 759 lm85_write_value(client, LM85_REG_AFAN_SPIKE1, tmp);
796 );
797 mutex_unlock(&data->update_lock); 760 mutex_unlock(&data->update_lock);
798 return count; 761 return count;
799} 762}
@@ -803,7 +766,7 @@ static ssize_t show_pwm_auto_pwm_freq(struct device *dev,
803{ 766{
804 int nr = to_sensor_dev_attr(attr)->index; 767 int nr = to_sensor_dev_attr(attr)->index;
805 struct lm85_data *data = lm85_update_device(dev); 768 struct lm85_data *data = lm85_update_device(dev);
806 return sprintf(buf,"%d\n", FREQ_FROM_REG(data->autofan[nr].freq)); 769 return sprintf(buf, "%d\n", FREQ_FROM_REG(data->autofan[nr].freq));
807} 770}
808 771
809static ssize_t set_pwm_auto_pwm_freq(struct device *dev, 772static ssize_t set_pwm_auto_pwm_freq(struct device *dev,
@@ -818,8 +781,7 @@ static ssize_t set_pwm_auto_pwm_freq(struct device *dev,
818 data->autofan[nr].freq = FREQ_TO_REG(val); 781 data->autofan[nr].freq = FREQ_TO_REG(val);
819 lm85_write_value(client, LM85_REG_AFAN_RANGE(nr), 782 lm85_write_value(client, LM85_REG_AFAN_RANGE(nr),
820 (data->zone[nr].range << 4) 783 (data->zone[nr].range << 4)
821 | data->autofan[nr].freq 784 | data->autofan[nr].freq);
822 );
823 mutex_unlock(&data->update_lock); 785 mutex_unlock(&data->update_lock);
824 return count; 786 return count;
825} 787}
@@ -849,7 +811,7 @@ static ssize_t show_temp_auto_temp_off(struct device *dev,
849{ 811{
850 int nr = to_sensor_dev_attr(attr)->index; 812 int nr = to_sensor_dev_attr(attr)->index;
851 struct lm85_data *data = lm85_update_device(dev); 813 struct lm85_data *data = lm85_update_device(dev);
852 return sprintf(buf,"%d\n", TEMP_FROM_REG(data->zone[nr].limit) - 814 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->zone[nr].limit) -
853 HYST_FROM_REG(data->zone[nr].hyst)); 815 HYST_FROM_REG(data->zone[nr].hyst));
854} 816}
855 817
@@ -866,15 +828,13 @@ static ssize_t set_temp_auto_temp_off(struct device *dev,
866 min = TEMP_FROM_REG(data->zone[nr].limit); 828 min = TEMP_FROM_REG(data->zone[nr].limit);
867 data->zone[nr].off_desired = TEMP_TO_REG(val); 829 data->zone[nr].off_desired = TEMP_TO_REG(val);
868 data->zone[nr].hyst = HYST_TO_REG(min - val); 830 data->zone[nr].hyst = HYST_TO_REG(min - val);
869 if ( nr == 0 || nr == 1 ) { 831 if (nr == 0 || nr == 1) {
870 lm85_write_value(client, LM85_REG_AFAN_HYST1, 832 lm85_write_value(client, LM85_REG_AFAN_HYST1,
871 (data->zone[0].hyst << 4) 833 (data->zone[0].hyst << 4)
872 | data->zone[1].hyst 834 | data->zone[1].hyst);
873 );
874 } else { 835 } else {
875 lm85_write_value(client, LM85_REG_AFAN_HYST2, 836 lm85_write_value(client, LM85_REG_AFAN_HYST2,
876 (data->zone[2].hyst << 4) 837 (data->zone[2].hyst << 4));
877 );
878 } 838 }
879 mutex_unlock(&data->update_lock); 839 mutex_unlock(&data->update_lock);
880 return count; 840 return count;
@@ -885,7 +845,7 @@ static ssize_t show_temp_auto_temp_min(struct device *dev,
885{ 845{
886 int nr = to_sensor_dev_attr(attr)->index; 846 int nr = to_sensor_dev_attr(attr)->index;
887 struct lm85_data *data = lm85_update_device(dev); 847 struct lm85_data *data = lm85_update_device(dev);
888 return sprintf(buf,"%d\n", TEMP_FROM_REG(data->zone[nr].limit) ); 848 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->zone[nr].limit));
889} 849}
890 850
891static ssize_t set_temp_auto_temp_min(struct device *dev, 851static ssize_t set_temp_auto_temp_min(struct device *dev,
@@ -913,15 +873,13 @@ static ssize_t set_temp_auto_temp_min(struct device *dev,
913 data->zone[nr].hyst = HYST_TO_REG(TEMP_FROM_REG( 873 data->zone[nr].hyst = HYST_TO_REG(TEMP_FROM_REG(
914 data->zone[nr].limit) - TEMP_FROM_REG( 874 data->zone[nr].limit) - TEMP_FROM_REG(
915 data->zone[nr].off_desired)); 875 data->zone[nr].off_desired));
916 if ( nr == 0 || nr == 1 ) { 876 if (nr == 0 || nr == 1) {
917 lm85_write_value(client, LM85_REG_AFAN_HYST1, 877 lm85_write_value(client, LM85_REG_AFAN_HYST1,
918 (data->zone[0].hyst << 4) 878 (data->zone[0].hyst << 4)
919 | data->zone[1].hyst 879 | data->zone[1].hyst);
920 );
921 } else { 880 } else {
922 lm85_write_value(client, LM85_REG_AFAN_HYST2, 881 lm85_write_value(client, LM85_REG_AFAN_HYST2,
923 (data->zone[2].hyst << 4) 882 (data->zone[2].hyst << 4));
924 );
925 } 883 }
926 mutex_unlock(&data->update_lock); 884 mutex_unlock(&data->update_lock);
927 return count; 885 return count;
@@ -932,7 +890,7 @@ static ssize_t show_temp_auto_temp_max(struct device *dev,
932{ 890{
933 int nr = to_sensor_dev_attr(attr)->index; 891 int nr = to_sensor_dev_attr(attr)->index;
934 struct lm85_data *data = lm85_update_device(dev); 892 struct lm85_data *data = lm85_update_device(dev);
935 return sprintf(buf,"%d\n", TEMP_FROM_REG(data->zone[nr].limit) + 893 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->zone[nr].limit) +
936 RANGE_FROM_REG(data->zone[nr].range)); 894 RANGE_FROM_REG(data->zone[nr].range));
937} 895}
938 896
@@ -962,11 +920,11 @@ static ssize_t show_temp_auto_temp_crit(struct device *dev,
962{ 920{
963 int nr = to_sensor_dev_attr(attr)->index; 921 int nr = to_sensor_dev_attr(attr)->index;
964 struct lm85_data *data = lm85_update_device(dev); 922 struct lm85_data *data = lm85_update_device(dev);
965 return sprintf(buf,"%d\n", TEMP_FROM_REG(data->zone[nr].critical)); 923 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->zone[nr].critical));
966} 924}
967 925
968static ssize_t set_temp_auto_temp_crit(struct device *dev, 926static ssize_t set_temp_auto_temp_crit(struct device *dev,
969 struct device_attribute *attr,const char *buf, size_t count) 927 struct device_attribute *attr, const char *buf, size_t count)
970{ 928{
971 int nr = to_sensor_dev_attr(attr)->index; 929 int nr = to_sensor_dev_attr(attr)->index;
972 struct i2c_client *client = to_i2c_client(dev); 930 struct i2c_client *client = to_i2c_client(dev);
@@ -1127,20 +1085,37 @@ static const struct attribute_group lm85_group_in567 = {
1127 .attrs = lm85_attributes_in567, 1085 .attrs = lm85_attributes_in567,
1128}; 1086};
1129 1087
1088static void lm85_init_client(struct i2c_client *client)
1089{
1090 int value;
1091
1092 /* Start monitoring if needed */
1093 value = lm85_read_value(client, LM85_REG_CONFIG);
1094 if (!(value & 0x01)) {
1095 dev_info(&client->dev, "Starting monitoring\n");
1096 lm85_write_value(client, LM85_REG_CONFIG, value | 0x01);
1097 }
1098
1099 /* Warn about unusual configuration bits */
1100 if (value & 0x02)
1101 dev_warn(&client->dev, "Device configuration is locked\n");
1102 if (!(value & 0x04))
1103 dev_warn(&client->dev, "Device is not ready\n");
1104}
1105
1130static int lm85_detect(struct i2c_adapter *adapter, int address, 1106static int lm85_detect(struct i2c_adapter *adapter, int address,
1131 int kind) 1107 int kind)
1132{ 1108{
1133 int company, verstep ; 1109 int company, verstep;
1134 struct i2c_client *new_client = NULL; 1110 struct i2c_client *client;
1135 struct lm85_data *data; 1111 struct lm85_data *data;
1136 int err = 0; 1112 int err = 0;
1137 const char *type_name = ""; 1113 const char *type_name;
1138 1114
1139 if (!i2c_check_functionality(adapter, 1115 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
1140 I2C_FUNC_SMBUS_BYTE_DATA)) {
1141 /* We need to be able to do byte I/O */ 1116 /* We need to be able to do byte I/O */
1142 goto ERROR0 ; 1117 goto ERROR0;
1143 }; 1118 }
1144 1119
1145 /* OK. For now, we presume we have a valid client. We now create the 1120 /* OK. For now, we presume we have a valid client. We now create the
1146 client structure, even though we cannot fill it completely yet. 1121 client structure, even though we cannot fill it completely yet.
@@ -1151,138 +1126,145 @@ static int lm85_detect(struct i2c_adapter *adapter, int address,
1151 goto ERROR0; 1126 goto ERROR0;
1152 } 1127 }
1153 1128
1154 new_client = &data->client; 1129 client = &data->client;
1155 i2c_set_clientdata(new_client, data); 1130 i2c_set_clientdata(client, data);
1156 new_client->addr = address; 1131 client->addr = address;
1157 new_client->adapter = adapter; 1132 client->adapter = adapter;
1158 new_client->driver = &lm85_driver; 1133 client->driver = &lm85_driver;
1159 new_client->flags = 0;
1160 1134
1161 /* Now, we do the remaining detection. */ 1135 /* Now, we do the remaining detection. */
1162 1136
1163 company = lm85_read_value(new_client, LM85_REG_COMPANY); 1137 company = lm85_read_value(client, LM85_REG_COMPANY);
1164 verstep = lm85_read_value(new_client, LM85_REG_VERSTEP); 1138 verstep = lm85_read_value(client, LM85_REG_VERSTEP);
1165 1139
1166 dev_dbg(&adapter->dev, "Detecting device at %d,0x%02x with" 1140 dev_dbg(&adapter->dev, "Detecting device at %d,0x%02x with"
1167 " COMPANY: 0x%02x and VERSTEP: 0x%02x\n", 1141 " COMPANY: 0x%02x and VERSTEP: 0x%02x\n",
1168 i2c_adapter_id(new_client->adapter), new_client->addr, 1142 i2c_adapter_id(client->adapter), client->addr,
1169 company, verstep); 1143 company, verstep);
1170 1144
1171 /* If auto-detecting, Determine the chip type. */ 1145 /* If auto-detecting, Determine the chip type. */
1172 if (kind <= 0) { 1146 if (kind <= 0) {
1173 dev_dbg(&adapter->dev, "Autodetecting device at %d,0x%02x ...\n", 1147 dev_dbg(&adapter->dev, "Autodetecting device at %d,0x%02x ...\n",
1174 i2c_adapter_id(adapter), address ); 1148 i2c_adapter_id(adapter), address);
1175 if( company == LM85_COMPANY_NATIONAL 1149 if (company == LM85_COMPANY_NATIONAL
1176 && verstep == LM85_VERSTEP_LM85C ) { 1150 && verstep == LM85_VERSTEP_LM85C) {
1177 kind = lm85c ; 1151 kind = lm85c;
1178 } else if( company == LM85_COMPANY_NATIONAL 1152 } else if (company == LM85_COMPANY_NATIONAL
1179 && verstep == LM85_VERSTEP_LM85B ) { 1153 && verstep == LM85_VERSTEP_LM85B) {
1180 kind = lm85b ; 1154 kind = lm85b;
1181 } else if( company == LM85_COMPANY_NATIONAL 1155 } else if (company == LM85_COMPANY_NATIONAL
1182 && (verstep & LM85_VERSTEP_VMASK) == LM85_VERSTEP_GENERIC ) { 1156 && (verstep & LM85_VERSTEP_VMASK) == LM85_VERSTEP_GENERIC) {
1183 dev_err(&adapter->dev, "Unrecognized version/stepping 0x%02x" 1157 dev_err(&adapter->dev, "Unrecognized version/stepping 0x%02x"
1184 " Defaulting to LM85.\n", verstep); 1158 " Defaulting to LM85.\n", verstep);
1185 kind = any_chip ; 1159 kind = any_chip;
1186 } else if( company == LM85_COMPANY_ANALOG_DEV 1160 } else if (company == LM85_COMPANY_ANALOG_DEV
1187 && verstep == LM85_VERSTEP_ADM1027 ) { 1161 && verstep == LM85_VERSTEP_ADM1027) {
1188 kind = adm1027 ; 1162 kind = adm1027;
1189 } else if( company == LM85_COMPANY_ANALOG_DEV 1163 } else if (company == LM85_COMPANY_ANALOG_DEV
1190 && (verstep == LM85_VERSTEP_ADT7463 1164 && (verstep == LM85_VERSTEP_ADT7463
1191 || verstep == LM85_VERSTEP_ADT7463C) ) { 1165 || verstep == LM85_VERSTEP_ADT7463C)) {
1192 kind = adt7463 ; 1166 kind = adt7463;
1193 } else if( company == LM85_COMPANY_ANALOG_DEV 1167 } else if (company == LM85_COMPANY_ANALOG_DEV
1194 && (verstep & LM85_VERSTEP_VMASK) == LM85_VERSTEP_GENERIC ) { 1168 && (verstep & LM85_VERSTEP_VMASK) == LM85_VERSTEP_GENERIC) {
1195 dev_err(&adapter->dev, "Unrecognized version/stepping 0x%02x" 1169 dev_err(&adapter->dev, "Unrecognized version/stepping 0x%02x"
1196 " Defaulting to Generic LM85.\n", verstep ); 1170 " Defaulting to Generic LM85.\n", verstep);
1197 kind = any_chip ; 1171 kind = any_chip;
1198 } else if( company == LM85_COMPANY_SMSC 1172 } else if (company == LM85_COMPANY_SMSC
1199 && (verstep == LM85_VERSTEP_EMC6D100_A0 1173 && (verstep == LM85_VERSTEP_EMC6D100_A0
1200 || verstep == LM85_VERSTEP_EMC6D100_A1) ) { 1174 || verstep == LM85_VERSTEP_EMC6D100_A1)) {
1201 /* Unfortunately, we can't tell a '100 from a '101 1175 /* Unfortunately, we can't tell a '100 from a '101
1202 * from the registers. Since a '101 is a '100 1176 * from the registers. Since a '101 is a '100
1203 * in a package with fewer pins and therefore no 1177 * in a package with fewer pins and therefore no
1204 * 3.3V, 1.5V or 1.8V inputs, perhaps if those 1178 * 3.3V, 1.5V or 1.8V inputs, perhaps if those
1205 * inputs read 0, then it's a '101. 1179 * inputs read 0, then it's a '101.
1206 */ 1180 */
1207 kind = emc6d100 ; 1181 kind = emc6d100;
1208 } else if( company == LM85_COMPANY_SMSC 1182 } else if (company == LM85_COMPANY_SMSC
1209 && verstep == LM85_VERSTEP_EMC6D102) { 1183 && verstep == LM85_VERSTEP_EMC6D102) {
1210 kind = emc6d102 ; 1184 kind = emc6d102;
1211 } else if( company == LM85_COMPANY_SMSC 1185 } else if (company == LM85_COMPANY_SMSC
1212 && (verstep & LM85_VERSTEP_VMASK) == LM85_VERSTEP_GENERIC) { 1186 && (verstep & LM85_VERSTEP_VMASK) == LM85_VERSTEP_GENERIC) {
1213 dev_err(&adapter->dev, "lm85: Detected SMSC chip\n"); 1187 dev_err(&adapter->dev, "lm85: Detected SMSC chip\n");
1214 dev_err(&adapter->dev, "lm85: Unrecognized version/stepping 0x%02x" 1188 dev_err(&adapter->dev, "lm85: Unrecognized version/stepping 0x%02x"
1215 " Defaulting to Generic LM85.\n", verstep ); 1189 " Defaulting to Generic LM85.\n", verstep);
1216 kind = any_chip ; 1190 kind = any_chip;
1217 } else if( kind == any_chip 1191 } else if (kind == any_chip
1218 && (verstep & LM85_VERSTEP_VMASK) == LM85_VERSTEP_GENERIC) { 1192 && (verstep & LM85_VERSTEP_VMASK) == LM85_VERSTEP_GENERIC) {
1219 dev_err(&adapter->dev, "Generic LM85 Version 6 detected\n"); 1193 dev_err(&adapter->dev, "Generic LM85 Version 6 detected\n");
1220 /* Leave kind as "any_chip" */ 1194 /* Leave kind as "any_chip" */
1221 } else { 1195 } else {
1222 dev_dbg(&adapter->dev, "Autodetection failed\n"); 1196 dev_dbg(&adapter->dev, "Autodetection failed\n");
1223 /* Not an LM85 ... */ 1197 /* Not an LM85... */
1224 if( kind == any_chip ) { /* User used force=x,y */ 1198 if (kind == any_chip) { /* User used force=x,y */
1225 dev_err(&adapter->dev, "Generic LM85 Version 6 not" 1199 dev_err(&adapter->dev, "Generic LM85 Version 6 not"
1226 " found at %d,0x%02x. Try force_lm85c.\n", 1200 " found at %d,0x%02x. Try force_lm85c.\n",
1227 i2c_adapter_id(adapter), address ); 1201 i2c_adapter_id(adapter), address);
1228 } 1202 }
1229 err = 0 ; 1203 err = 0;
1230 goto ERROR1; 1204 goto ERROR1;
1231 } 1205 }
1232 } 1206 }
1233 1207
1234 /* Fill in the chip specific driver values */ 1208 /* Fill in the chip specific driver values */
1235 if ( kind == any_chip ) { 1209 switch (kind) {
1236 type_name = "lm85"; 1210 case lm85b:
1237 } else if ( kind == lm85b ) {
1238 type_name = "lm85b"; 1211 type_name = "lm85b";
1239 } else if ( kind == lm85c ) { 1212 break;
1213 case lm85c:
1240 type_name = "lm85c"; 1214 type_name = "lm85c";
1241 } else if ( kind == adm1027 ) { 1215 break;
1216 case adm1027:
1242 type_name = "adm1027"; 1217 type_name = "adm1027";
1243 } else if ( kind == adt7463 ) { 1218 break;
1219 case adt7463:
1244 type_name = "adt7463"; 1220 type_name = "adt7463";
1245 } else if ( kind == emc6d100){ 1221 break;
1222 case emc6d100:
1246 type_name = "emc6d100"; 1223 type_name = "emc6d100";
1247 } else if ( kind == emc6d102 ) { 1224 break;
1225 case emc6d102:
1248 type_name = "emc6d102"; 1226 type_name = "emc6d102";
1227 break;
1228 default:
1229 type_name = "lm85";
1249 } 1230 }
1250 strlcpy(new_client->name, type_name, I2C_NAME_SIZE); 1231 strlcpy(client->name, type_name, I2C_NAME_SIZE);
1251 1232
1252 /* Fill in the remaining client fields */ 1233 /* Fill in the remaining client fields */
1253 data->type = kind; 1234 data->type = kind;
1254 data->valid = 0;
1255 mutex_init(&data->update_lock); 1235 mutex_init(&data->update_lock);
1256 1236
1257 /* Tell the I2C layer a new client has arrived */ 1237 /* Tell the I2C layer a new client has arrived */
1258 if ((err = i2c_attach_client(new_client))) 1238 err = i2c_attach_client(client);
1239 if (err)
1259 goto ERROR1; 1240 goto ERROR1;
1260 1241
1261 /* Set the VRM version */ 1242 /* Set the VRM version */
1262 data->vrm = vid_which_vrm(); 1243 data->vrm = vid_which_vrm();
1263 1244
1264 /* Initialize the LM85 chip */ 1245 /* Initialize the LM85 chip */
1265 lm85_init_client(new_client); 1246 lm85_init_client(client);
1266 1247
1267 /* Register sysfs hooks */ 1248 /* Register sysfs hooks */
1268 if ((err = sysfs_create_group(&new_client->dev.kobj, &lm85_group))) 1249 err = sysfs_create_group(&client->dev.kobj, &lm85_group);
1250 if (err)
1269 goto ERROR2; 1251 goto ERROR2;
1270 1252
1271 /* The ADT7463 has an optional VRM 10 mode where pin 21 is used 1253 /* The ADT7463 has an optional VRM 10 mode where pin 21 is used
1272 as a sixth digital VID input rather than an analog input. */ 1254 as a sixth digital VID input rather than an analog input. */
1273 data->vid = lm85_read_value(new_client, LM85_REG_VID); 1255 data->vid = lm85_read_value(client, LM85_REG_VID);
1274 if (!(kind == adt7463 && (data->vid & 0x80))) 1256 if (!(kind == adt7463 && (data->vid & 0x80)))
1275 if ((err = sysfs_create_group(&new_client->dev.kobj, 1257 if ((err = sysfs_create_group(&client->dev.kobj,
1276 &lm85_group_in4))) 1258 &lm85_group_in4)))
1277 goto ERROR3; 1259 goto ERROR3;
1278 1260
1279 /* The EMC6D100 has 3 additional voltage inputs */ 1261 /* The EMC6D100 has 3 additional voltage inputs */
1280 if (kind == emc6d100) 1262 if (kind == emc6d100)
1281 if ((err = sysfs_create_group(&new_client->dev.kobj, 1263 if ((err = sysfs_create_group(&client->dev.kobj,
1282 &lm85_group_in567))) 1264 &lm85_group_in567)))
1283 goto ERROR3; 1265 goto ERROR3;
1284 1266
1285 data->hwmon_dev = hwmon_device_register(&new_client->dev); 1267 data->hwmon_dev = hwmon_device_register(&client->dev);
1286 if (IS_ERR(data->hwmon_dev)) { 1268 if (IS_ERR(data->hwmon_dev)) {
1287 err = PTR_ERR(data->hwmon_dev); 1269 err = PTR_ERR(data->hwmon_dev);
1288 goto ERROR3; 1270 goto ERROR3;
@@ -1291,16 +1273,16 @@ static int lm85_detect(struct i2c_adapter *adapter, int address,
1291 return 0; 1273 return 0;
1292 1274
1293 /* Error out and cleanup code */ 1275 /* Error out and cleanup code */
1294 ERROR3: 1276 ERROR3:
1295 sysfs_remove_group(&new_client->dev.kobj, &lm85_group); 1277 sysfs_remove_group(&client->dev.kobj, &lm85_group);
1296 sysfs_remove_group(&new_client->dev.kobj, &lm85_group_in4); 1278 sysfs_remove_group(&client->dev.kobj, &lm85_group_in4);
1297 if (kind == emc6d100) 1279 if (kind == emc6d100)
1298 sysfs_remove_group(&new_client->dev.kobj, &lm85_group_in567); 1280 sysfs_remove_group(&client->dev.kobj, &lm85_group_in567);
1299 ERROR2: 1281 ERROR2:
1300 i2c_detach_client(new_client); 1282 i2c_detach_client(client);
1301 ERROR1: 1283 ERROR1:
1302 kfree(data); 1284 kfree(data);
1303 ERROR0: 1285 ERROR0:
1304 return err; 1286 return err;
1305} 1287}
1306 1288
@@ -1323,100 +1305,46 @@ static int lm85_read_value(struct i2c_client *client, u8 reg)
1323 int res; 1305 int res;
1324 1306
1325 /* What size location is it? */ 1307 /* What size location is it? */
1326 switch( reg ) { 1308 switch (reg) {
1327 case LM85_REG_FAN(0) : /* Read WORD data */ 1309 case LM85_REG_FAN(0): /* Read WORD data */
1328 case LM85_REG_FAN(1) : 1310 case LM85_REG_FAN(1):
1329 case LM85_REG_FAN(2) : 1311 case LM85_REG_FAN(2):
1330 case LM85_REG_FAN(3) : 1312 case LM85_REG_FAN(3):
1331 case LM85_REG_FAN_MIN(0) : 1313 case LM85_REG_FAN_MIN(0):
1332 case LM85_REG_FAN_MIN(1) : 1314 case LM85_REG_FAN_MIN(1):
1333 case LM85_REG_FAN_MIN(2) : 1315 case LM85_REG_FAN_MIN(2):
1334 case LM85_REG_FAN_MIN(3) : 1316 case LM85_REG_FAN_MIN(3):
1335 case LM85_REG_ALARM1 : /* Read both bytes at once */ 1317 case LM85_REG_ALARM1: /* Read both bytes at once */
1336 res = i2c_smbus_read_byte_data(client, reg) & 0xff ; 1318 res = i2c_smbus_read_byte_data(client, reg) & 0xff;
1337 res |= i2c_smbus_read_byte_data(client, reg+1) << 8 ; 1319 res |= i2c_smbus_read_byte_data(client, reg + 1) << 8;
1338 break ; 1320 break;
1339 case ADT7463_REG_TMIN_CTL1 : /* Read WORD MSB, LSB */
1340 res = i2c_smbus_read_byte_data(client, reg) << 8 ;
1341 res |= i2c_smbus_read_byte_data(client, reg+1) & 0xff ;
1342 break ;
1343 default: /* Read BYTE data */ 1321 default: /* Read BYTE data */
1344 res = i2c_smbus_read_byte_data(client, reg); 1322 res = i2c_smbus_read_byte_data(client, reg);
1345 break ; 1323 break;
1346 } 1324 }
1347 1325
1348 return res ; 1326 return res;
1349} 1327}
1350 1328
1351static int lm85_write_value(struct i2c_client *client, u8 reg, int value) 1329static void lm85_write_value(struct i2c_client *client, u8 reg, int value)
1352{ 1330{
1353 int res ; 1331 switch (reg) {
1354 1332 case LM85_REG_FAN(0): /* Write WORD data */
1355 switch( reg ) { 1333 case LM85_REG_FAN(1):
1356 case LM85_REG_FAN(0) : /* Write WORD data */ 1334 case LM85_REG_FAN(2):
1357 case LM85_REG_FAN(1) : 1335 case LM85_REG_FAN(3):
1358 case LM85_REG_FAN(2) : 1336 case LM85_REG_FAN_MIN(0):
1359 case LM85_REG_FAN(3) : 1337 case LM85_REG_FAN_MIN(1):
1360 case LM85_REG_FAN_MIN(0) : 1338 case LM85_REG_FAN_MIN(2):
1361 case LM85_REG_FAN_MIN(1) : 1339 case LM85_REG_FAN_MIN(3):
1362 case LM85_REG_FAN_MIN(2) :
1363 case LM85_REG_FAN_MIN(3) :
1364 /* NOTE: ALARM is read only, so not included here */ 1340 /* NOTE: ALARM is read only, so not included here */
1365 res = i2c_smbus_write_byte_data(client, reg, value & 0xff) ; 1341 i2c_smbus_write_byte_data(client, reg, value & 0xff);
1366 res |= i2c_smbus_write_byte_data(client, reg+1, (value>>8) & 0xff) ; 1342 i2c_smbus_write_byte_data(client, reg + 1, value >> 8);
1367 break ; 1343 break;
1368 case ADT7463_REG_TMIN_CTL1 : /* Write WORD MSB, LSB */
1369 res = i2c_smbus_write_byte_data(client, reg, (value>>8) & 0xff);
1370 res |= i2c_smbus_write_byte_data(client, reg+1, value & 0xff) ;
1371 break ;
1372 default: /* Write BYTE data */ 1344 default: /* Write BYTE data */
1373 res = i2c_smbus_write_byte_data(client, reg, value); 1345 i2c_smbus_write_byte_data(client, reg, value);
1374 break ; 1346 break;
1375 } 1347 }
1376
1377 return res ;
1378}
1379
1380static void lm85_init_client(struct i2c_client *client)
1381{
1382 int value;
1383 struct lm85_data *data = i2c_get_clientdata(client);
1384
1385 dev_dbg(&client->dev, "Initializing device\n");
1386
1387 /* Warn if part was not "READY" */
1388 value = lm85_read_value(client, LM85_REG_CONFIG);
1389 dev_dbg(&client->dev, "LM85_REG_CONFIG is: 0x%02x\n", value);
1390 if( value & 0x02 ) {
1391 dev_err(&client->dev, "Client (%d,0x%02x) config is locked.\n",
1392 i2c_adapter_id(client->adapter), client->addr );
1393 };
1394 if( ! (value & 0x04) ) {
1395 dev_err(&client->dev, "Client (%d,0x%02x) is not ready.\n",
1396 i2c_adapter_id(client->adapter), client->addr );
1397 };
1398 if( value & 0x10
1399 && ( data->type == adm1027
1400 || data->type == adt7463 ) ) {
1401 dev_err(&client->dev, "Client (%d,0x%02x) VxI mode is set. "
1402 "Please report this to the lm85 maintainer.\n",
1403 i2c_adapter_id(client->adapter), client->addr );
1404 };
1405
1406 /* WE INTENTIONALLY make no changes to the limits,
1407 * offsets, pwms, fans and zones. If they were
1408 * configured, we don't want to mess with them.
1409 * If they weren't, the default is 100% PWM, no
1410 * control and will suffice until 'sensors -s'
1411 * can be run by the user.
1412 */
1413
1414 /* Start monitoring */
1415 value = lm85_read_value(client, LM85_REG_CONFIG);
1416 /* Try to clear LOCK, Set START, save everything else */
1417 value = (value & ~ 0x02) | 0x01 ;
1418 dev_dbg(&client->dev, "Setting CONFIG to: 0x%02x\n", value);
1419 lm85_write_value(client, LM85_REG_CONFIG, value);
1420} 1348}
1421 1349
1422static struct lm85_data *lm85_update_device(struct device *dev) 1350static struct lm85_data *lm85_update_device(struct device *dev)
@@ -1427,28 +1355,30 @@ static struct lm85_data *lm85_update_device(struct device *dev)
1427 1355
1428 mutex_lock(&data->update_lock); 1356 mutex_lock(&data->update_lock);
1429 1357
1430 if ( !data->valid || 1358 if (!data->valid ||
1431 time_after(jiffies, data->last_reading + LM85_DATA_INTERVAL) ) { 1359 time_after(jiffies, data->last_reading + LM85_DATA_INTERVAL)) {
1432 /* Things that change quickly */ 1360 /* Things that change quickly */
1433 dev_dbg(&client->dev, "Reading sensor values\n"); 1361 dev_dbg(&client->dev, "Reading sensor values\n");
1434 1362
1435 /* Have to read extended bits first to "freeze" the 1363 /* Have to read extended bits first to "freeze" the
1436 * more significant bits that are read later. 1364 * more significant bits that are read later.
1437 * There are 2 additional resolution bits per channel and we 1365 * There are 2 additional resolution bits per channel and we
1438 * have room for 4, so we shift them to the left. 1366 * have room for 4, so we shift them to the left.
1439 */ 1367 */
1440 if ( (data->type == adm1027) || (data->type == adt7463) ) { 1368 if (data->type == adm1027 || data->type == adt7463) {
1441 int ext1 = lm85_read_value(client, 1369 int ext1 = lm85_read_value(client,
1442 ADM1027_REG_EXTEND_ADC1); 1370 ADM1027_REG_EXTEND_ADC1);
1443 int ext2 = lm85_read_value(client, 1371 int ext2 = lm85_read_value(client,
1444 ADM1027_REG_EXTEND_ADC2); 1372 ADM1027_REG_EXTEND_ADC2);
1445 int val = (ext1 << 8) + ext2; 1373 int val = (ext1 << 8) + ext2;
1446 1374
1447 for(i = 0; i <= 4; i++) 1375 for (i = 0; i <= 4; i++)
1448 data->in_ext[i] = ((val>>(i * 2))&0x03) << 2; 1376 data->in_ext[i] =
1377 ((val >> (i * 2)) & 0x03) << 2;
1449 1378
1450 for(i = 0; i <= 2; i++) 1379 for (i = 0; i <= 2; i++)
1451 data->temp_ext[i] = (val>>((i + 4) * 2))&0x0c; 1380 data->temp_ext[i] =
1381 (val >> ((i + 4) * 2)) & 0x0c;
1452 } 1382 }
1453 1383
1454 data->vid = lm85_read_value(client, LM85_REG_VID); 1384 data->vid = lm85_read_value(client, LM85_REG_VID);
@@ -1456,6 +1386,8 @@ static struct lm85_data *lm85_update_device(struct device *dev)
1456 for (i = 0; i <= 3; ++i) { 1386 for (i = 0; i <= 3; ++i) {
1457 data->in[i] = 1387 data->in[i] =
1458 lm85_read_value(client, LM85_REG_IN(i)); 1388 lm85_read_value(client, LM85_REG_IN(i));
1389 data->fan[i] =
1390 lm85_read_value(client, LM85_REG_FAN(i));
1459 } 1391 }
1460 1392
1461 if (!(data->type == adt7463 && (data->vid & 0x80))) { 1393 if (!(data->type == adt7463 && (data->vid & 0x80))) {
@@ -1463,38 +1395,25 @@ static struct lm85_data *lm85_update_device(struct device *dev)
1463 LM85_REG_IN(4)); 1395 LM85_REG_IN(4));
1464 } 1396 }
1465 1397
1466 for (i = 0; i <= 3; ++i) {
1467 data->fan[i] =
1468 lm85_read_value(client, LM85_REG_FAN(i));
1469 }
1470
1471 for (i = 0; i <= 2; ++i) { 1398 for (i = 0; i <= 2; ++i) {
1472 data->temp[i] = 1399 data->temp[i] =
1473 lm85_read_value(client, LM85_REG_TEMP(i)); 1400 lm85_read_value(client, LM85_REG_TEMP(i));
1474 }
1475
1476 for (i = 0; i <= 2; ++i) {
1477 data->pwm[i] = 1401 data->pwm[i] =
1478 lm85_read_value(client, LM85_REG_PWM(i)); 1402 lm85_read_value(client, LM85_REG_PWM(i));
1479 } 1403 }
1480 1404
1481 data->alarms = lm85_read_value(client, LM85_REG_ALARM1); 1405 data->alarms = lm85_read_value(client, LM85_REG_ALARM1);
1482 1406
1483 if ( data->type == adt7463 ) { 1407 if (data->type == emc6d100) {
1484 if( data->therm_total < ULONG_MAX - 256 ) {
1485 data->therm_total +=
1486 lm85_read_value(client, ADT7463_REG_THERM );
1487 }
1488 } else if ( data->type == emc6d100 ) {
1489 /* Three more voltage sensors */ 1408 /* Three more voltage sensors */
1490 for (i = 5; i <= 7; ++i) { 1409 for (i = 5; i <= 7; ++i) {
1491 data->in[i] = 1410 data->in[i] = lm85_read_value(client,
1492 lm85_read_value(client, EMC6D100_REG_IN(i)); 1411 EMC6D100_REG_IN(i));
1493 } 1412 }
1494 /* More alarm bits */ 1413 /* More alarm bits */
1495 data->alarms |= 1414 data->alarms |= lm85_read_value(client,
1496 lm85_read_value(client, EMC6D100_REG_ALARM3) << 16; 1415 EMC6D100_REG_ALARM3) << 16;
1497 } else if (data->type == emc6d102 ) { 1416 } else if (data->type == emc6d102) {
1498 /* Have to read LSB bits after the MSB ones because 1417 /* Have to read LSB bits after the MSB ones because
1499 the reading of the MSB bits has frozen the 1418 the reading of the MSB bits has frozen the
1500 LSBs (backward from the ADM1027). 1419 LSBs (backward from the ADM1027).
@@ -1509,20 +1428,20 @@ static struct lm85_data *lm85_update_device(struct device *dev)
1509 EMC6D102_REG_EXTEND_ADC4); 1428 EMC6D102_REG_EXTEND_ADC4);
1510 data->in_ext[0] = ext3 & 0x0f; 1429 data->in_ext[0] = ext3 & 0x0f;
1511 data->in_ext[1] = ext4 & 0x0f; 1430 data->in_ext[1] = ext4 & 0x0f;
1512 data->in_ext[2] = (ext4 >> 4) & 0x0f; 1431 data->in_ext[2] = ext4 >> 4;
1513 data->in_ext[3] = (ext3 >> 4) & 0x0f; 1432 data->in_ext[3] = ext3 >> 4;
1514 data->in_ext[4] = (ext2 >> 4) & 0x0f; 1433 data->in_ext[4] = ext2 >> 4;
1515 1434
1516 data->temp_ext[0] = ext1 & 0x0f; 1435 data->temp_ext[0] = ext1 & 0x0f;
1517 data->temp_ext[1] = ext2 & 0x0f; 1436 data->temp_ext[1] = ext2 & 0x0f;
1518 data->temp_ext[2] = (ext1 >> 4) & 0x0f; 1437 data->temp_ext[2] = ext1 >> 4;
1519 } 1438 }
1520 1439
1521 data->last_reading = jiffies ; 1440 data->last_reading = jiffies;
1522 }; /* last_reading */ 1441 } /* last_reading */
1523 1442
1524 if ( !data->valid || 1443 if (!data->valid ||
1525 time_after(jiffies, data->last_config + LM85_CONFIG_INTERVAL) ) { 1444 time_after(jiffies, data->last_config + LM85_CONFIG_INTERVAL)) {
1526 /* Things that don't change often */ 1445 /* Things that don't change often */
1527 dev_dbg(&client->dev, "Reading config values\n"); 1446 dev_dbg(&client->dev, "Reading config values\n");
1528 1447
@@ -1531,6 +1450,8 @@ static struct lm85_data *lm85_update_device(struct device *dev)
1531 lm85_read_value(client, LM85_REG_IN_MIN(i)); 1450 lm85_read_value(client, LM85_REG_IN_MIN(i));
1532 data->in_max[i] = 1451 data->in_max[i] =
1533 lm85_read_value(client, LM85_REG_IN_MAX(i)); 1452 lm85_read_value(client, LM85_REG_IN_MAX(i));
1453 data->fan_min[i] =
1454 lm85_read_value(client, LM85_REG_FAN_MIN(i));
1534 } 1455 }
1535 1456
1536 if (!(data->type == adt7463 && (data->vid & 0x80))) { 1457 if (!(data->type == adt7463 && (data->vid & 0x80))) {
@@ -1540,34 +1461,28 @@ static struct lm85_data *lm85_update_device(struct device *dev)
1540 LM85_REG_IN_MAX(4)); 1461 LM85_REG_IN_MAX(4));
1541 } 1462 }
1542 1463
1543 if ( data->type == emc6d100 ) { 1464 if (data->type == emc6d100) {
1544 for (i = 5; i <= 7; ++i) { 1465 for (i = 5; i <= 7; ++i) {
1545 data->in_min[i] = 1466 data->in_min[i] = lm85_read_value(client,
1546 lm85_read_value(client, EMC6D100_REG_IN_MIN(i)); 1467 EMC6D100_REG_IN_MIN(i));
1547 data->in_max[i] = 1468 data->in_max[i] = lm85_read_value(client,
1548 lm85_read_value(client, EMC6D100_REG_IN_MAX(i)); 1469 EMC6D100_REG_IN_MAX(i));
1549 } 1470 }
1550 } 1471 }
1551 1472
1552 for (i = 0; i <= 3; ++i) {
1553 data->fan_min[i] =
1554 lm85_read_value(client, LM85_REG_FAN_MIN(i));
1555 }
1556
1557 for (i = 0; i <= 2; ++i) { 1473 for (i = 0; i <= 2; ++i) {
1474 int val;
1475
1558 data->temp_min[i] = 1476 data->temp_min[i] =
1559 lm85_read_value(client, LM85_REG_TEMP_MIN(i)); 1477 lm85_read_value(client, LM85_REG_TEMP_MIN(i));
1560 data->temp_max[i] = 1478 data->temp_max[i] =
1561 lm85_read_value(client, LM85_REG_TEMP_MAX(i)); 1479 lm85_read_value(client, LM85_REG_TEMP_MAX(i));
1562 }
1563 1480
1564 for (i = 0; i <= 2; ++i) {
1565 int val ;
1566 data->autofan[i].config = 1481 data->autofan[i].config =
1567 lm85_read_value(client, LM85_REG_AFAN_CONFIG(i)); 1482 lm85_read_value(client, LM85_REG_AFAN_CONFIG(i));
1568 val = lm85_read_value(client, LM85_REG_AFAN_RANGE(i)); 1483 val = lm85_read_value(client, LM85_REG_AFAN_RANGE(i));
1569 data->autofan[i].freq = val & 0x07 ; 1484 data->autofan[i].freq = val & 0x07;
1570 data->zone[i].range = (val >> 4) & 0x0f ; 1485 data->zone[i].range = val >> 4;
1571 data->autofan[i].min_pwm = 1486 data->autofan[i].min_pwm =
1572 lm85_read_value(client, LM85_REG_AFAN_MINPWM(i)); 1487 lm85_read_value(client, LM85_REG_AFAN_MINPWM(i));
1573 data->zone[i].limit = 1488 data->zone[i].limit =
@@ -1577,50 +1492,19 @@ static struct lm85_data *lm85_update_device(struct device *dev)
1577 } 1492 }
1578 1493
1579 i = lm85_read_value(client, LM85_REG_AFAN_SPIKE1); 1494 i = lm85_read_value(client, LM85_REG_AFAN_SPIKE1);
1580 data->smooth[0] = i & 0x0f ; 1495 data->autofan[0].min_off = (i & 0x20) != 0;
1581 data->syncpwm3 = i & 0x10 ; /* Save PWM3 config */ 1496 data->autofan[1].min_off = (i & 0x40) != 0;
1582 data->autofan[0].min_off = (i & 0x20) != 0 ; 1497 data->autofan[2].min_off = (i & 0x80) != 0;
1583 data->autofan[1].min_off = (i & 0x40) != 0 ;
1584 data->autofan[2].min_off = (i & 0x80) != 0 ;
1585 i = lm85_read_value(client, LM85_REG_AFAN_SPIKE2);
1586 data->smooth[1] = (i>>4) & 0x0f ;
1587 data->smooth[2] = i & 0x0f ;
1588 1498
1589 i = lm85_read_value(client, LM85_REG_AFAN_HYST1); 1499 i = lm85_read_value(client, LM85_REG_AFAN_HYST1);
1590 data->zone[0].hyst = (i>>4) & 0x0f ; 1500 data->zone[0].hyst = i >> 4;
1591 data->zone[1].hyst = i & 0x0f ; 1501 data->zone[1].hyst = i & 0x0f;
1592 1502
1593 i = lm85_read_value(client, LM85_REG_AFAN_HYST2); 1503 i = lm85_read_value(client, LM85_REG_AFAN_HYST2);
1594 data->zone[2].hyst = (i>>4) & 0x0f ; 1504 data->zone[2].hyst = i >> 4;
1595 1505
1596 if ( (data->type == lm85b) || (data->type == lm85c) ) {
1597 data->tach_mode = lm85_read_value(client,
1598 LM85_REG_TACH_MODE );
1599 data->spinup_ctl = lm85_read_value(client,
1600 LM85_REG_SPINUP_CTL );
1601 } else if ( (data->type == adt7463) || (data->type == adm1027) ) {
1602 if ( data->type == adt7463 ) {
1603 for (i = 0; i <= 2; ++i) {
1604 data->oppoint[i] = lm85_read_value(client,
1605 ADT7463_REG_OPPOINT(i) );
1606 }
1607 data->tmin_ctl = lm85_read_value(client,
1608 ADT7463_REG_TMIN_CTL1 );
1609 data->therm_limit = lm85_read_value(client,
1610 ADT7463_REG_THERM_LIMIT );
1611 }
1612 for (i = 0; i <= 2; ++i) {
1613 data->temp_offset[i] = lm85_read_value(client,
1614 ADM1027_REG_TEMP_OFFSET(i) );
1615 }
1616 data->tach_mode = lm85_read_value(client,
1617 ADM1027_REG_CONFIG3 );
1618 data->fan_ppr = lm85_read_value(client,
1619 ADM1027_REG_FAN_PPR );
1620 }
1621
1622 data->last_config = jiffies; 1506 data->last_config = jiffies;
1623 }; /* last_config */ 1507 } /* last_config */
1624 1508
1625 data->valid = 1; 1509 data->valid = 1;
1626 1510
@@ -1635,17 +1519,15 @@ static int __init sm_lm85_init(void)
1635 return i2c_add_driver(&lm85_driver); 1519 return i2c_add_driver(&lm85_driver);
1636} 1520}
1637 1521
1638static void __exit sm_lm85_exit(void) 1522static void __exit sm_lm85_exit(void)
1639{ 1523{
1640 i2c_del_driver(&lm85_driver); 1524 i2c_del_driver(&lm85_driver);
1641} 1525}
1642 1526
1643/* Thanks to Richard Barrington for adding the LM85 to sensors-detect.
1644 * Thanks to Margit Schubert-While <margitsw@t-online.de> for help with
1645 * post 2.7.0 CVS changes.
1646 */
1647MODULE_LICENSE("GPL"); 1527MODULE_LICENSE("GPL");
1648MODULE_AUTHOR("Philip Pokorny <ppokorny@penguincomputing.com>, Margit Schubert-While <margitsw@t-online.de>, Justin Thiessen <jthiessen@penguincomputing.com"); 1528MODULE_AUTHOR("Philip Pokorny <ppokorny@penguincomputing.com>, "
1529 "Margit Schubert-While <margitsw@t-online.de>, "
1530 "Justin Thiessen <jthiessen@penguincomputing.com>");
1649MODULE_DESCRIPTION("LM85-B, LM85-C driver"); 1531MODULE_DESCRIPTION("LM85-B, LM85-C driver");
1650 1532
1651module_init(sm_lm85_init); 1533module_init(sm_lm85_init);