|
@@ -1,14 +1,12 @@
|
|
|
/*
|
|
|
* lm90.c - Part of lm_sensors, Linux kernel modules for hardware
|
|
|
* monitoring
|
|
|
- * Copyright (C) 2003-2006 Jean Delvare <khali@linux-fr.org>
|
|
|
+ * Copyright (C) 2003-2008 Jean Delvare <khali@linux-fr.org>
|
|
|
*
|
|
|
* Based on the lm83 driver. The LM90 is a sensor chip made by National
|
|
|
* Semiconductor. It reports up to two temperatures (its own plus up to
|
|
|
* one external one) with a 0.125 deg resolution (1 deg for local
|
|
|
- * temperature) and a 3-4 deg accuracy. Complete datasheet can be
|
|
|
- * obtained from National's website at:
|
|
|
- * http://www.national.com/pf/LM/LM90.html
|
|
|
+ * temperature) and a 3-4 deg accuracy.
|
|
|
*
|
|
|
* This driver also supports the LM89 and LM99, two other sensor chips
|
|
|
* made by National Semiconductor. Both have an increased remote
|
|
@@ -16,48 +14,38 @@
|
|
|
* additionally shifts remote temperatures (measured and limits) by 16
|
|
|
* degrees, which allows for higher temperatures measurement. The
|
|
|
* driver doesn't handle it since it can be done easily in user-space.
|
|
|
- * Complete datasheets can be obtained from National's website at:
|
|
|
- * http://www.national.com/pf/LM/LM89.html
|
|
|
- * http://www.national.com/pf/LM/LM99.html
|
|
|
* Note that there is no way to differentiate between both chips.
|
|
|
*
|
|
|
* This driver also supports the LM86, another sensor chip made by
|
|
|
* National Semiconductor. It is exactly similar to the LM90 except it
|
|
|
* has a higher accuracy.
|
|
|
- * Complete datasheet can be obtained from National's website at:
|
|
|
- * http://www.national.com/pf/LM/LM86.html
|
|
|
*
|
|
|
* This driver also supports the ADM1032, a sensor chip made by Analog
|
|
|
* Devices. That chip is similar to the LM90, with a few differences
|
|
|
- * that are not handled by this driver. Complete datasheet can be
|
|
|
- * obtained from Analog's website at:
|
|
|
- * http://www.analog.com/en/prod/0,2877,ADM1032,00.html
|
|
|
- * Among others, it has a higher accuracy than the LM90, much like the
|
|
|
- * LM86 does.
|
|
|
+ * that are not handled by this driver. Among others, it has a higher
|
|
|
+ * accuracy than the LM90, much like the LM86 does.
|
|
|
*
|
|
|
* This driver also supports the MAX6657, MAX6658 and MAX6659 sensor
|
|
|
- * chips made by Maxim. These chips are similar to the LM86. Complete
|
|
|
- * datasheet can be obtained at Maxim's website at:
|
|
|
- * http://www.maxim-ic.com/quick_view2.cfm/qv_pk/2578
|
|
|
+ * chips made by Maxim. These chips are similar to the LM86.
|
|
|
* Note that there is no easy way to differentiate between the three
|
|
|
* variants. The extra address and features of the MAX6659 are not
|
|
|
* supported by this driver. These chips lack the remote temperature
|
|
|
* offset feature.
|
|
|
*
|
|
|
+ * This driver also supports the MAX6646, MAX6647 and MAX6649 chips
|
|
|
+ * made by Maxim. These are again similar to the LM86, but they use
|
|
|
+ * unsigned temperature values and can report temperatures from 0 to
|
|
|
+ * 145 degrees.
|
|
|
+ *
|
|
|
* This driver also supports the MAX6680 and MAX6681, two other sensor
|
|
|
* chips made by Maxim. These are quite similar to the other Maxim
|
|
|
- * chips. Complete datasheet can be obtained at:
|
|
|
- * http://www.maxim-ic.com/quick_view2.cfm/qv_pk/3370
|
|
|
- * The MAX6680 and MAX6681 only differ in the pinout so they can be
|
|
|
- * treated identically.
|
|
|
+ * chips. The MAX6680 and MAX6681 only differ in the pinout so they can
|
|
|
+ * be treated identically.
|
|
|
*
|
|
|
- * This driver also supports the ADT7461 chip from Analog Devices but
|
|
|
- * only in its "compatability mode". If an ADT7461 chip is found but
|
|
|
- * is configured in non-compatible mode (where its temperature
|
|
|
- * register values are decoded differently) it is ignored by this
|
|
|
- * driver. Complete datasheet can be obtained from Analog's website
|
|
|
- * at:
|
|
|
- * http://www.analog.com/en/prod/0,2877,ADT7461,00.html
|
|
|
+ * This driver also supports the ADT7461 chip from Analog Devices.
|
|
|
+ * It's supported in both compatibility and extended mode. It is mostly
|
|
|
+ * compatible with LM90 except for a data format difference for the
|
|
|
+ * temperature value registers.
|
|
|
*
|
|
|
* Since the LM90 was the first chipset supported by this driver, most
|
|
|
* comments will refer to this chipset, but are actually general and
|
|
@@ -93,9 +81,10 @@
|
|
|
* Addresses to scan
|
|
|
* Address is fully defined internally and cannot be changed except for
|
|
|
* MAX6659, MAX6680 and MAX6681.
|
|
|
- * LM86, LM89, LM90, LM99, ADM1032, ADM1032-1, ADT7461, MAX6657 and MAX6658
|
|
|
- * have address 0x4c.
|
|
|
- * ADM1032-2, ADT7461-2, LM89-1, and LM99-1 have address 0x4d.
|
|
|
+ * LM86, LM89, LM90, LM99, ADM1032, ADM1032-1, ADT7461, MAX6649, MAX6657
|
|
|
+ * and MAX6658 have address 0x4c.
|
|
|
+ * ADM1032-2, ADT7461-2, LM89-1, LM99-1 and MAX6646 have address 0x4d.
|
|
|
+ * MAX6647 has address 0x4e.
|
|
|
* MAX6659 can have address 0x4c, 0x4d or 0x4e (unsupported).
|
|
|
* MAX6680 and MAX6681 can have address 0x18, 0x19, 0x1a, 0x29, 0x2a, 0x2b,
|
|
|
* 0x4c, 0x4d or 0x4e.
|
|
@@ -108,7 +97,8 @@ static const unsigned short normal_i2c[] = {
|
|
|
* Insmod parameters
|
|
|
*/
|
|
|
|
|
|
-I2C_CLIENT_INSMOD_7(lm90, adm1032, lm99, lm86, max6657, adt7461, max6680);
|
|
|
+I2C_CLIENT_INSMOD_8(lm90, adm1032, lm99, lm86, max6657, adt7461, max6680,
|
|
|
+ max6646);
|
|
|
|
|
|
/*
|
|
|
* The LM90 registers
|
|
@@ -149,39 +139,14 @@ I2C_CLIENT_INSMOD_7(lm90, adm1032, lm99, lm86, max6657, adt7461, max6680);
|
|
|
#define LM90_REG_R_TCRIT_HYST 0x21
|
|
|
#define LM90_REG_W_TCRIT_HYST 0x21
|
|
|
|
|
|
-/*
|
|
|
- * Conversions and various macros
|
|
|
- * For local temperatures and limits, critical limits and the hysteresis
|
|
|
- * value, the LM90 uses signed 8-bit values with LSB = 1 degree Celsius.
|
|
|
- * For remote temperatures and limits, it uses signed 11-bit values with
|
|
|
- * LSB = 0.125 degree Celsius, left-justified in 16-bit registers.
|
|
|
- */
|
|
|
+/* MAX6646/6647/6649/6657/6658/6659 registers */
|
|
|
|
|
|
-#define TEMP1_FROM_REG(val) ((val) * 1000)
|
|
|
-#define TEMP1_TO_REG(val) ((val) <= -128000 ? -128 : \
|
|
|
- (val) >= 127000 ? 127 : \
|
|
|
- (val) < 0 ? ((val) - 500) / 1000 : \
|
|
|
- ((val) + 500) / 1000)
|
|
|
-#define TEMP2_FROM_REG(val) ((val) / 32 * 125)
|
|
|
-#define TEMP2_TO_REG(val) ((val) <= -128000 ? 0x8000 : \
|
|
|
- (val) >= 127875 ? 0x7FE0 : \
|
|
|
- (val) < 0 ? ((val) - 62) / 125 * 32 : \
|
|
|
- ((val) + 62) / 125 * 32)
|
|
|
-#define HYST_TO_REG(val) ((val) <= 0 ? 0 : (val) >= 30500 ? 31 : \
|
|
|
- ((val) + 500) / 1000)
|
|
|
-
|
|
|
-/*
|
|
|
- * ADT7461 is almost identical to LM90 except that attempts to write
|
|
|
- * values that are outside the range 0 < temp < 127 are treated as
|
|
|
- * the boundary value.
|
|
|
- */
|
|
|
+#define MAX6657_REG_R_LOCAL_TEMPL 0x11
|
|
|
|
|
|
-#define TEMP1_TO_REG_ADT7461(val) ((val) <= 0 ? 0 : \
|
|
|
- (val) >= 127000 ? 127 : \
|
|
|
- ((val) + 500) / 1000)
|
|
|
-#define TEMP2_TO_REG_ADT7461(val) ((val) <= 0 ? 0 : \
|
|
|
- (val) >= 127750 ? 0x7FC0 : \
|
|
|
- ((val) + 125) / 250 * 64)
|
|
|
+/*
|
|
|
+ * Device flags
|
|
|
+ */
|
|
|
+#define LM90_FLAG_ADT7461_EXT 0x01 /* ADT7461 extended mode */
|
|
|
|
|
|
/*
|
|
|
* Functions declaration
|
|
@@ -206,6 +171,9 @@ static const struct i2c_device_id lm90_id[] = {
|
|
|
{ "lm86", lm86 },
|
|
|
{ "lm89", lm99 },
|
|
|
{ "lm99", lm99 }, /* Missing temperature offset */
|
|
|
+ { "max6646", max6646 },
|
|
|
+ { "max6647", max6646 },
|
|
|
+ { "max6649", max6646 },
|
|
|
{ "max6657", max6657 },
|
|
|
{ "max6658", max6657 },
|
|
|
{ "max6659", max6657 },
|
|
@@ -237,21 +205,149 @@ struct lm90_data {
|
|
|
char valid; /* zero until following fields are valid */
|
|
|
unsigned long last_updated; /* in jiffies */
|
|
|
int kind;
|
|
|
+ int flags;
|
|
|
|
|
|
/* registers values */
|
|
|
- s8 temp8[5]; /* 0: local input
|
|
|
- 1: local low limit
|
|
|
- 2: local high limit
|
|
|
- 3: local critical limit
|
|
|
- 4: remote critical limit */
|
|
|
- s16 temp11[4]; /* 0: remote input
|
|
|
+ s8 temp8[4]; /* 0: local low limit
|
|
|
+ 1: local high limit
|
|
|
+ 2: local critical limit
|
|
|
+ 3: remote critical limit */
|
|
|
+ s16 temp11[5]; /* 0: remote input
|
|
|
1: remote low limit
|
|
|
2: remote high limit
|
|
|
- 3: remote offset (except max6657) */
|
|
|
+ 3: remote offset (except max6646 and max6657)
|
|
|
+ 4: local input */
|
|
|
u8 temp_hyst;
|
|
|
u8 alarms; /* bitvector */
|
|
|
};
|
|
|
|
|
|
+/*
|
|
|
+ * Conversions
|
|
|
+ * For local temperatures and limits, critical limits and the hysteresis
|
|
|
+ * value, the LM90 uses signed 8-bit values with LSB = 1 degree Celsius.
|
|
|
+ * For remote temperatures and limits, it uses signed 11-bit values with
|
|
|
+ * LSB = 0.125 degree Celsius, left-justified in 16-bit registers. Some
|
|
|
+ * Maxim chips use unsigned values.
|
|
|
+ */
|
|
|
+
|
|
|
+static inline int temp_from_s8(s8 val)
|
|
|
+{
|
|
|
+ return val * 1000;
|
|
|
+}
|
|
|
+
|
|
|
+static inline int temp_from_u8(u8 val)
|
|
|
+{
|
|
|
+ return val * 1000;
|
|
|
+}
|
|
|
+
|
|
|
+static inline int temp_from_s16(s16 val)
|
|
|
+{
|
|
|
+ return val / 32 * 125;
|
|
|
+}
|
|
|
+
|
|
|
+static inline int temp_from_u16(u16 val)
|
|
|
+{
|
|
|
+ return val / 32 * 125;
|
|
|
+}
|
|
|
+
|
|
|
+static s8 temp_to_s8(long val)
|
|
|
+{
|
|
|
+ if (val <= -128000)
|
|
|
+ return -128;
|
|
|
+ if (val >= 127000)
|
|
|
+ return 127;
|
|
|
+ if (val < 0)
|
|
|
+ return (val - 500) / 1000;
|
|
|
+ return (val + 500) / 1000;
|
|
|
+}
|
|
|
+
|
|
|
+static u8 temp_to_u8(long val)
|
|
|
+{
|
|
|
+ if (val <= 0)
|
|
|
+ return 0;
|
|
|
+ if (val >= 255000)
|
|
|
+ return 255;
|
|
|
+ return (val + 500) / 1000;
|
|
|
+}
|
|
|
+
|
|
|
+static s16 temp_to_s16(long val)
|
|
|
+{
|
|
|
+ if (val <= -128000)
|
|
|
+ return 0x8000;
|
|
|
+ if (val >= 127875)
|
|
|
+ return 0x7FE0;
|
|
|
+ if (val < 0)
|
|
|
+ return (val - 62) / 125 * 32;
|
|
|
+ return (val + 62) / 125 * 32;
|
|
|
+}
|
|
|
+
|
|
|
+static u8 hyst_to_reg(long val)
|
|
|
+{
|
|
|
+ if (val <= 0)
|
|
|
+ return 0;
|
|
|
+ if (val >= 30500)
|
|
|
+ return 31;
|
|
|
+ return (val + 500) / 1000;
|
|
|
+}
|
|
|
+
|
|
|
+/*
|
|
|
+ * ADT7461 in compatibility mode is almost identical to LM90 except that
|
|
|
+ * attempts to write values that are outside the range 0 < temp < 127 are
|
|
|
+ * treated as the boundary value.
|
|
|
+ *
|
|
|
+ * ADT7461 in "extended mode" operation uses unsigned integers offset by
|
|
|
+ * 64 (e.g., 0 -> -64 degC). The range is restricted to -64..191 degC.
|
|
|
+ */
|
|
|
+static inline int temp_from_u8_adt7461(struct lm90_data *data, u8 val)
|
|
|
+{
|
|
|
+ if (data->flags & LM90_FLAG_ADT7461_EXT)
|
|
|
+ return (val - 64) * 1000;
|
|
|
+ else
|
|
|
+ return temp_from_s8(val);
|
|
|
+}
|
|
|
+
|
|
|
+static inline int temp_from_u16_adt7461(struct lm90_data *data, u16 val)
|
|
|
+{
|
|
|
+ if (data->flags & LM90_FLAG_ADT7461_EXT)
|
|
|
+ return (val - 0x4000) / 64 * 250;
|
|
|
+ else
|
|
|
+ return temp_from_s16(val);
|
|
|
+}
|
|
|
+
|
|
|
+static u8 temp_to_u8_adt7461(struct lm90_data *data, long val)
|
|
|
+{
|
|
|
+ if (data->flags & LM90_FLAG_ADT7461_EXT) {
|
|
|
+ if (val <= -64000)
|
|
|
+ return 0;
|
|
|
+ if (val >= 191000)
|
|
|
+ return 0xFF;
|
|
|
+ return (val + 500 + 64000) / 1000;
|
|
|
+ } else {
|
|
|
+ if (val <= 0)
|
|
|
+ return 0;
|
|
|
+ if (val >= 127000)
|
|
|
+ return 127;
|
|
|
+ return (val + 500) / 1000;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+static u16 temp_to_u16_adt7461(struct lm90_data *data, long val)
|
|
|
+{
|
|
|
+ if (data->flags & LM90_FLAG_ADT7461_EXT) {
|
|
|
+ if (val <= -64000)
|
|
|
+ return 0;
|
|
|
+ if (val >= 191750)
|
|
|
+ return 0xFFC0;
|
|
|
+ return (val + 64000 + 125) / 250 * 64;
|
|
|
+ } else {
|
|
|
+ if (val <= 0)
|
|
|
+ return 0;
|
|
|
+ if (val >= 127750)
|
|
|
+ return 0x7FC0;
|
|
|
+ return (val + 125) / 250 * 64;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
/*
|
|
|
* Sysfs stuff
|
|
|
*/
|
|
@@ -261,7 +357,16 @@ static ssize_t show_temp8(struct device *dev, struct device_attribute *devattr,
|
|
|
{
|
|
|
struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
|
|
|
struct lm90_data *data = lm90_update_device(dev);
|
|
|
- return sprintf(buf, "%d\n", TEMP1_FROM_REG(data->temp8[attr->index]));
|
|
|
+ int temp;
|
|
|
+
|
|
|
+ if (data->kind == adt7461)
|
|
|
+ temp = temp_from_u8_adt7461(data, data->temp8[attr->index]);
|
|
|
+ else if (data->kind == max6646)
|
|
|
+ temp = temp_from_u8(data->temp8[attr->index]);
|
|
|
+ else
|
|
|
+ temp = temp_from_s8(data->temp8[attr->index]);
|
|
|
+
|
|
|
+ return sprintf(buf, "%d\n", temp);
|
|
|
}
|
|
|
|
|
|
static ssize_t set_temp8(struct device *dev, struct device_attribute *devattr,
|
|
@@ -282,10 +387,12 @@ static ssize_t set_temp8(struct device *dev, struct device_attribute *devattr,
|
|
|
|
|
|
mutex_lock(&data->update_lock);
|
|
|
if (data->kind == adt7461)
|
|
|
- data->temp8[nr] = TEMP1_TO_REG_ADT7461(val);
|
|
|
+ data->temp8[nr] = temp_to_u8_adt7461(data, val);
|
|
|
+ else if (data->kind == max6646)
|
|
|
+ data->temp8[nr] = temp_to_u8(val);
|
|
|
else
|
|
|
- data->temp8[nr] = TEMP1_TO_REG(val);
|
|
|
- i2c_smbus_write_byte_data(client, reg[nr - 1], data->temp8[nr]);
|
|
|
+ data->temp8[nr] = temp_to_s8(val);
|
|
|
+ i2c_smbus_write_byte_data(client, reg[nr], data->temp8[nr]);
|
|
|
mutex_unlock(&data->update_lock);
|
|
|
return count;
|
|
|
}
|
|
@@ -295,7 +402,16 @@ static ssize_t show_temp11(struct device *dev, struct device_attribute *devattr,
|
|
|
{
|
|
|
struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
|
|
|
struct lm90_data *data = lm90_update_device(dev);
|
|
|
- return sprintf(buf, "%d\n", TEMP2_FROM_REG(data->temp11[attr->index]));
|
|
|
+ int temp;
|
|
|
+
|
|
|
+ if (data->kind == adt7461)
|
|
|
+ temp = temp_from_u16_adt7461(data, data->temp11[attr->index]);
|
|
|
+ else if (data->kind == max6646)
|
|
|
+ temp = temp_from_u16(data->temp11[attr->index]);
|
|
|
+ else
|
|
|
+ temp = temp_from_s16(data->temp11[attr->index]);
|
|
|
+
|
|
|
+ return sprintf(buf, "%d\n", temp);
|
|
|
}
|
|
|
|
|
|
static ssize_t set_temp11(struct device *dev, struct device_attribute *devattr,
|
|
@@ -318,13 +434,20 @@ static ssize_t set_temp11(struct device *dev, struct device_attribute *devattr,
|
|
|
|
|
|
mutex_lock(&data->update_lock);
|
|
|
if (data->kind == adt7461)
|
|
|
- data->temp11[nr] = TEMP2_TO_REG_ADT7461(val);
|
|
|
+ data->temp11[nr] = temp_to_u16_adt7461(data, val);
|
|
|
+ else if (data->kind == max6657 || data->kind == max6680)
|
|
|
+ data->temp11[nr] = temp_to_s8(val) << 8;
|
|
|
+ else if (data->kind == max6646)
|
|
|
+ data->temp11[nr] = temp_to_u8(val) << 8;
|
|
|
else
|
|
|
- data->temp11[nr] = TEMP2_TO_REG(val);
|
|
|
+ data->temp11[nr] = temp_to_s16(val);
|
|
|
+
|
|
|
i2c_smbus_write_byte_data(client, reg[(nr - 1) * 2],
|
|
|
data->temp11[nr] >> 8);
|
|
|
- i2c_smbus_write_byte_data(client, reg[(nr - 1) * 2 + 1],
|
|
|
- data->temp11[nr] & 0xff);
|
|
|
+ if (data->kind != max6657 && data->kind != max6680
|
|
|
+ && data->kind != max6646)
|
|
|
+ i2c_smbus_write_byte_data(client, reg[(nr - 1) * 2 + 1],
|
|
|
+ data->temp11[nr] & 0xff);
|
|
|
mutex_unlock(&data->update_lock);
|
|
|
return count;
|
|
|
}
|
|
@@ -334,8 +457,14 @@ static ssize_t show_temphyst(struct device *dev, struct device_attribute *devatt
|
|
|
{
|
|
|
struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
|
|
|
struct lm90_data *data = lm90_update_device(dev);
|
|
|
- return sprintf(buf, "%d\n", TEMP1_FROM_REG(data->temp8[attr->index])
|
|
|
- - TEMP1_FROM_REG(data->temp_hyst));
|
|
|
+ int temp;
|
|
|
+
|
|
|
+ if (data->kind == adt7461)
|
|
|
+ temp = temp_from_u8_adt7461(data, data->temp8[attr->index]);
|
|
|
+ else
|
|
|
+ temp = temp_from_s8(data->temp8[attr->index]);
|
|
|
+
|
|
|
+ return sprintf(buf, "%d\n", temp - temp_from_s8(data->temp_hyst));
|
|
|
}
|
|
|
|
|
|
static ssize_t set_temphyst(struct device *dev, struct device_attribute *dummy,
|
|
@@ -347,9 +476,9 @@ static ssize_t set_temphyst(struct device *dev, struct device_attribute *dummy,
|
|
|
long hyst;
|
|
|
|
|
|
mutex_lock(&data->update_lock);
|
|
|
- hyst = TEMP1_FROM_REG(data->temp8[3]) - val;
|
|
|
+ hyst = temp_from_s8(data->temp8[2]) - val;
|
|
|
i2c_smbus_write_byte_data(client, LM90_REG_W_TCRIT_HYST,
|
|
|
- HYST_TO_REG(hyst));
|
|
|
+ hyst_to_reg(hyst));
|
|
|
mutex_unlock(&data->update_lock);
|
|
|
return count;
|
|
|
}
|
|
@@ -371,23 +500,23 @@ static ssize_t show_alarm(struct device *dev, struct device_attribute
|
|
|
return sprintf(buf, "%d\n", (data->alarms >> bitnr) & 1);
|
|
|
}
|
|
|
|
|
|
-static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp8, NULL, 0);
|
|
|
+static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp11, NULL, 4);
|
|
|
static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_temp11, NULL, 0);
|
|
|
static SENSOR_DEVICE_ATTR(temp1_min, S_IWUSR | S_IRUGO, show_temp8,
|
|
|
- set_temp8, 1);
|
|
|
+ set_temp8, 0);
|
|
|
static SENSOR_DEVICE_ATTR(temp2_min, S_IWUSR | S_IRUGO, show_temp11,
|
|
|
set_temp11, 1);
|
|
|
static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp8,
|
|
|
- set_temp8, 2);
|
|
|
+ set_temp8, 1);
|
|
|
static SENSOR_DEVICE_ATTR(temp2_max, S_IWUSR | S_IRUGO, show_temp11,
|
|
|
set_temp11, 2);
|
|
|
static SENSOR_DEVICE_ATTR(temp1_crit, S_IWUSR | S_IRUGO, show_temp8,
|
|
|
- set_temp8, 3);
|
|
|
+ set_temp8, 2);
|
|
|
static SENSOR_DEVICE_ATTR(temp2_crit, S_IWUSR | S_IRUGO, show_temp8,
|
|
|
- set_temp8, 4);
|
|
|
+ set_temp8, 3);
|
|
|
static SENSOR_DEVICE_ATTR(temp1_crit_hyst, S_IWUSR | S_IRUGO, show_temphyst,
|
|
|
- set_temphyst, 3);
|
|
|
-static SENSOR_DEVICE_ATTR(temp2_crit_hyst, S_IRUGO, show_temphyst, NULL, 4);
|
|
|
+ set_temphyst, 2);
|
|
|
+static SENSOR_DEVICE_ATTR(temp2_crit_hyst, S_IRUGO, show_temphyst, NULL, 3);
|
|
|
static SENSOR_DEVICE_ATTR(temp2_offset, S_IWUSR | S_IRUGO, show_temp11,
|
|
|
set_temp11, 3);
|
|
|
|
|
@@ -568,7 +697,7 @@ static int lm90_detect(struct i2c_client *new_client, int kind,
|
|
|
kind = adm1032;
|
|
|
} else
|
|
|
if (chip_id == 0x51 /* ADT7461 */
|
|
|
- && (reg_config1 & 0x1F) == 0x00 /* check compat mode */
|
|
|
+ && (reg_config1 & 0x1B) == 0x00
|
|
|
&& reg_convrate <= 0x0A) {
|
|
|
kind = adt7461;
|
|
|
}
|
|
@@ -599,13 +728,23 @@ static int lm90_detect(struct i2c_client *new_client, int kind,
|
|
|
&& (reg_config1 & 0x03) == 0x00
|
|
|
&& reg_convrate <= 0x07) {
|
|
|
kind = max6680;
|
|
|
+ } else
|
|
|
+ /* The chip_id register of the MAX6646/6647/6649
|
|
|
+ * holds the revision of the chip.
|
|
|
+ * The lowest 6 bits of the config1 register are
|
|
|
+ * unused and should return zero when read.
|
|
|
+ */
|
|
|
+ if (chip_id == 0x59
|
|
|
+ && (reg_config1 & 0x3f) == 0x00
|
|
|
+ && reg_convrate <= 0x07) {
|
|
|
+ kind = max6646;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (kind <= 0) { /* identification failed */
|
|
|
- dev_info(&adapter->dev,
|
|
|
- "Unsupported chip (man_id=0x%02X, "
|
|
|
- "chip_id=0x%02X).\n", man_id, chip_id);
|
|
|
+ dev_dbg(&adapter->dev,
|
|
|
+ "Unsupported chip at 0x%02x (man_id=0x%02X, "
|
|
|
+ "chip_id=0x%02X)\n", address, man_id, chip_id);
|
|
|
return -ENODEV;
|
|
|
}
|
|
|
}
|
|
@@ -629,6 +768,8 @@ static int lm90_detect(struct i2c_client *new_client, int kind,
|
|
|
name = "max6680";
|
|
|
} else if (kind == adt7461) {
|
|
|
name = "adt7461";
|
|
|
+ } else if (kind == max6646) {
|
|
|
+ name = "max6646";
|
|
|
}
|
|
|
strlcpy(info->type, name, I2C_NAME_SIZE);
|
|
|
|
|
@@ -668,7 +809,7 @@ static int lm90_probe(struct i2c_client *new_client,
|
|
|
&dev_attr_pec)))
|
|
|
goto exit_remove_files;
|
|
|
}
|
|
|
- if (data->kind != max6657) {
|
|
|
+ if (data->kind != max6657 && data->kind != max6646) {
|
|
|
if ((err = device_create_file(&new_client->dev,
|
|
|
&sensor_dev_attr_temp2_offset.dev_attr)))
|
|
|
goto exit_remove_files;
|
|
@@ -707,6 +848,12 @@ static void lm90_init_client(struct i2c_client *client)
|
|
|
}
|
|
|
config_orig = config;
|
|
|
|
|
|
+ /* Check Temperature Range Select */
|
|
|
+ if (data->kind == adt7461) {
|
|
|
+ if (config & 0x04)
|
|
|
+ data->flags |= LM90_FLAG_ADT7461_EXT;
|
|
|
+ }
|
|
|
+
|
|
|
/*
|
|
|
* Put MAX6680/MAX8881 into extended resolution (bit 0x10,
|
|
|
* 0.125 degree resolution) and range (0x08, extend range
|
|
@@ -728,7 +875,7 @@ static int lm90_remove(struct i2c_client *client)
|
|
|
hwmon_device_unregister(data->hwmon_dev);
|
|
|
sysfs_remove_group(&client->dev.kobj, &lm90_group);
|
|
|
device_remove_file(&client->dev, &dev_attr_pec);
|
|
|
- if (data->kind != max6657)
|
|
|
+ if (data->kind != max6657 && data->kind != max6646)
|
|
|
device_remove_file(&client->dev,
|
|
|
&sensor_dev_attr_temp2_offset.dev_attr);
|
|
|
|
|
@@ -736,6 +883,38 @@ static int lm90_remove(struct i2c_client *client)
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
+static int lm90_read16(struct i2c_client *client, u8 regh, u8 regl, u16 *value)
|
|
|
+{
|
|
|
+ int err;
|
|
|
+ u8 oldh, newh, l;
|
|
|
+
|
|
|
+ /*
|
|
|
+ * There is a trick here. We have to read two registers to have the
|
|
|
+ * sensor temperature, but we have to beware a conversion could occur
|
|
|
+ * inbetween the readings. The datasheet says we should either use
|
|
|
+ * the one-shot conversion register, which we don't want to do
|
|
|
+ * (disables hardware monitoring) or monitor the busy bit, which is
|
|
|
+ * impossible (we can't read the values and monitor that bit at the
|
|
|
+ * exact same time). So the solution used here is to read the high
|
|
|
+ * byte once, then the low byte, then the high byte again. If the new
|
|
|
+ * high byte matches the old one, then we have a valid reading. Else
|
|
|
+ * we have to read the low byte again, and now we believe we have a
|
|
|
+ * correct reading.
|
|
|
+ */
|
|
|
+ if ((err = lm90_read_reg(client, regh, &oldh))
|
|
|
+ || (err = lm90_read_reg(client, regl, &l))
|
|
|
+ || (err = lm90_read_reg(client, regh, &newh)))
|
|
|
+ return err;
|
|
|
+ if (oldh != newh) {
|
|
|
+ err = lm90_read_reg(client, regl, &l);
|
|
|
+ if (err)
|
|
|
+ return err;
|
|
|
+ }
|
|
|
+ *value = (newh << 8) | l;
|
|
|
+
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
static struct lm90_data *lm90_update_device(struct device *dev)
|
|
|
{
|
|
|
struct i2c_client *client = to_i2c_client(dev);
|
|
@@ -744,49 +923,50 @@ static struct lm90_data *lm90_update_device(struct device *dev)
|
|
|
mutex_lock(&data->update_lock);
|
|
|
|
|
|
if (time_after(jiffies, data->last_updated + HZ * 2) || !data->valid) {
|
|
|
- u8 oldh, newh, l;
|
|
|
+ u8 h, l;
|
|
|
|
|
|
dev_dbg(&client->dev, "Updating lm90 data.\n");
|
|
|
- lm90_read_reg(client, LM90_REG_R_LOCAL_TEMP, &data->temp8[0]);
|
|
|
- lm90_read_reg(client, LM90_REG_R_LOCAL_LOW, &data->temp8[1]);
|
|
|
- lm90_read_reg(client, LM90_REG_R_LOCAL_HIGH, &data->temp8[2]);
|
|
|
- lm90_read_reg(client, LM90_REG_R_LOCAL_CRIT, &data->temp8[3]);
|
|
|
- lm90_read_reg(client, LM90_REG_R_REMOTE_CRIT, &data->temp8[4]);
|
|
|
+ lm90_read_reg(client, LM90_REG_R_LOCAL_LOW, &data->temp8[0]);
|
|
|
+ lm90_read_reg(client, LM90_REG_R_LOCAL_HIGH, &data->temp8[1]);
|
|
|
+ lm90_read_reg(client, LM90_REG_R_LOCAL_CRIT, &data->temp8[2]);
|
|
|
+ lm90_read_reg(client, LM90_REG_R_REMOTE_CRIT, &data->temp8[3]);
|
|
|
lm90_read_reg(client, LM90_REG_R_TCRIT_HYST, &data->temp_hyst);
|
|
|
|
|
|
- /*
|
|
|
- * There is a trick here. We have to read two registers to
|
|
|
- * have the remote sensor temperature, but we have to beware
|
|
|
- * a conversion could occur inbetween the readings. The
|
|
|
- * datasheet says we should either use the one-shot
|
|
|
- * conversion register, which we don't want to do (disables
|
|
|
- * hardware monitoring) or monitor the busy bit, which is
|
|
|
- * impossible (we can't read the values and monitor that bit
|
|
|
- * at the exact same time). So the solution used here is to
|
|
|
- * read the high byte once, then the low byte, then the high
|
|
|
- * byte again. If the new high byte matches the old one,
|
|
|
- * then we have a valid reading. Else we have to read the low
|
|
|
- * byte again, and now we believe we have a correct reading.
|
|
|
- */
|
|
|
- if (lm90_read_reg(client, LM90_REG_R_REMOTE_TEMPH, &oldh) == 0
|
|
|
- && lm90_read_reg(client, LM90_REG_R_REMOTE_TEMPL, &l) == 0
|
|
|
- && lm90_read_reg(client, LM90_REG_R_REMOTE_TEMPH, &newh) == 0
|
|
|
- && (newh == oldh
|
|
|
- || lm90_read_reg(client, LM90_REG_R_REMOTE_TEMPL, &l) == 0))
|
|
|
- data->temp11[0] = (newh << 8) | l;
|
|
|
-
|
|
|
- if (lm90_read_reg(client, LM90_REG_R_REMOTE_LOWH, &newh) == 0
|
|
|
- && lm90_read_reg(client, LM90_REG_R_REMOTE_LOWL, &l) == 0)
|
|
|
- data->temp11[1] = (newh << 8) | l;
|
|
|
- if (lm90_read_reg(client, LM90_REG_R_REMOTE_HIGHH, &newh) == 0
|
|
|
- && lm90_read_reg(client, LM90_REG_R_REMOTE_HIGHL, &l) == 0)
|
|
|
- data->temp11[2] = (newh << 8) | l;
|
|
|
- if (data->kind != max6657) {
|
|
|
+ if (data->kind == max6657 || data->kind == max6646) {
|
|
|
+ lm90_read16(client, LM90_REG_R_LOCAL_TEMP,
|
|
|
+ MAX6657_REG_R_LOCAL_TEMPL,
|
|
|
+ &data->temp11[4]);
|
|
|
+ } else {
|
|
|
+ if (lm90_read_reg(client, LM90_REG_R_LOCAL_TEMP,
|
|
|
+ &h) == 0)
|
|
|
+ data->temp11[4] = h << 8;
|
|
|
+ }
|
|
|
+ lm90_read16(client, LM90_REG_R_REMOTE_TEMPH,
|
|
|
+ LM90_REG_R_REMOTE_TEMPL, &data->temp11[0]);
|
|
|
+
|
|
|
+ if (lm90_read_reg(client, LM90_REG_R_REMOTE_LOWH, &h) == 0) {
|
|
|
+ data->temp11[1] = h << 8;
|
|
|
+ if (data->kind != max6657 && data->kind != max6680
|
|
|
+ && data->kind != max6646
|
|
|
+ && lm90_read_reg(client, LM90_REG_R_REMOTE_LOWL,
|
|
|
+ &l) == 0)
|
|
|
+ data->temp11[1] |= l;
|
|
|
+ }
|
|
|
+ if (lm90_read_reg(client, LM90_REG_R_REMOTE_HIGHH, &h) == 0) {
|
|
|
+ data->temp11[2] = h << 8;
|
|
|
+ if (data->kind != max6657 && data->kind != max6680
|
|
|
+ && data->kind != max6646
|
|
|
+ && lm90_read_reg(client, LM90_REG_R_REMOTE_HIGHL,
|
|
|
+ &l) == 0)
|
|
|
+ data->temp11[2] |= l;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (data->kind != max6657 && data->kind != max6646) {
|
|
|
if (lm90_read_reg(client, LM90_REG_R_REMOTE_OFFSH,
|
|
|
- &newh) == 0
|
|
|
+ &h) == 0
|
|
|
&& lm90_read_reg(client, LM90_REG_R_REMOTE_OFFSL,
|
|
|
&l) == 0)
|
|
|
- data->temp11[3] = (newh << 8) | l;
|
|
|
+ data->temp11[3] = (h << 8) | l;
|
|
|
}
|
|
|
lm90_read_reg(client, LM90_REG_R_STATUS, &data->alarms);
|
|
|
|