gru: improve GRU TLB dropin statistics
[safe/jmp/linux-2.6] / drivers / hwmon / lm90.c
index 3edeebc..7c9bdc1 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * lm90.c - Part of lm_sensors, Linux kernel modules for hardware
  *          monitoring
- * Copyright (C) 2003-2008  Jean Delvare <khali@linux-fr.org>
+ * Copyright (C) 2003-2009  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
@@ -12,9 +12,9 @@
  * made by National Semiconductor. Both have an increased remote
  * temperature measurement accuracy (1 degree), and the LM99
  * 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.
+ * degrees, which allows for higher temperatures measurement.
  * Note that there is no way to differentiate between both chips.
+ * When device is auto-detected, the driver will assume an LM99.
  *
  * This driver also supports the LM86, another sensor chip made by
  * National Semiconductor. It is exactly similar to the LM90 except it
  * 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 MAX6646, MAX6647, MAX6648, MAX6649 and
+ * MAX6692 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
 static const unsigned short normal_i2c[] = {
        0x18, 0x19, 0x1a, 0x29, 0x2a, 0x2b, 0x4c, 0x4d, 0x4e, I2C_CLIENT_END };
 
-/*
- * Insmod parameters
- */
-
-I2C_CLIENT_INSMOD_8(lm90, adm1032, lm99, lm86, max6657, adt7461, max6680,
-                   max6646);
+enum chips { lm90, adm1032, lm99, lm86, max6657, adt7461, max6680, max6646 };
 
 /*
  * The LM90 registers
@@ -152,8 +147,7 @@ I2C_CLIENT_INSMOD_8(lm90, adm1032, lm99, lm86, max6657, adt7461, max6680,
  * Functions declaration
  */
 
-static int lm90_detect(struct i2c_client *client, int kind,
-                      struct i2c_board_info *info);
+static int lm90_detect(struct i2c_client *client, struct i2c_board_info *info);
 static int lm90_probe(struct i2c_client *client,
                      const struct i2c_device_id *id);
 static void lm90_init_client(struct i2c_client *client);
@@ -169,8 +163,8 @@ static const struct i2c_device_id lm90_id[] = {
        { "adt7461", adt7461 },
        { "lm90", lm90 },
        { "lm86", lm86 },
-       { "lm89", lm99 },
-       { "lm99", lm99 },       /* Missing temperature offset */
+       { "lm89", lm86 },
+       { "lm99", lm99 },
        { "max6646", max6646 },
        { "max6647", max6646 },
        { "max6649", max6646 },
@@ -192,7 +186,7 @@ static struct i2c_driver lm90_driver = {
        .remove         = lm90_remove,
        .id_table       = lm90_id,
        .detect         = lm90_detect,
-       .address_data   = &addr_data,
+       .address_list   = normal_i2c,
 };
 
 /*
@@ -366,6 +360,10 @@ static ssize_t show_temp8(struct device *dev, struct device_attribute *devattr,
        else
                temp = temp_from_s8(data->temp8[attr->index]);
 
+       /* +16 degrees offset for temp2 for the LM99 */
+       if (data->kind == lm99 && attr->index == 3)
+               temp += 16000;
+
        return sprintf(buf, "%d\n", temp);
 }
 
@@ -385,6 +383,10 @@ static ssize_t set_temp8(struct device *dev, struct device_attribute *devattr,
        long val = simple_strtol(buf, NULL, 10);
        int nr = attr->index;
 
+       /* +16 degrees offset for temp2 for the LM99 */
+       if (data->kind == lm99 && attr->index == 3)
+               val -= 16000;
+
        mutex_lock(&data->update_lock);
        if (data->kind == adt7461)
                data->temp8[nr] = temp_to_u8_adt7461(data, val);
@@ -411,6 +413,10 @@ static ssize_t show_temp11(struct device *dev, struct device_attribute *devattr,
        else
                temp = temp_from_s16(data->temp11[attr->index]);
 
+       /* +16 degrees offset for temp2 for the LM99 */
+       if (data->kind == lm99 &&  attr->index <= 2)
+               temp += 16000;
+
        return sprintf(buf, "%d\n", temp);
 }
 
@@ -432,6 +438,10 @@ static ssize_t set_temp11(struct device *dev, struct device_attribute *devattr,
        long val = simple_strtol(buf, NULL, 10);
        int nr = attr->index;
 
+       /* +16 degrees offset for temp2 for the LM99 */
+       if (data->kind == lm99 && attr->index <= 2)
+               val -= 16000;
+
        mutex_lock(&data->update_lock);
        if (data->kind == adt7461)
                data->temp11[nr] = temp_to_u16_adt7461(data, val);
@@ -461,9 +471,15 @@ static ssize_t show_temphyst(struct device *dev, struct device_attribute *devatt
 
        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]);
 
+       /* +16 degrees offset for temp2 for the LM99 */
+       if (data->kind == lm99 && attr->index == 3)
+               temp += 16000;
+
        return sprintf(buf, "%d\n", temp - temp_from_s8(data->temp_hyst));
 }
 
@@ -473,12 +489,19 @@ static ssize_t set_temphyst(struct device *dev, struct device_attribute *dummy,
        struct i2c_client *client = to_i2c_client(dev);
        struct lm90_data *data = i2c_get_clientdata(client);
        long val = simple_strtol(buf, NULL, 10);
-       long hyst;
+       int temp;
 
        mutex_lock(&data->update_lock);
-       hyst = temp_from_s8(data->temp8[2]) - val;
+       if (data->kind == adt7461)
+               temp = temp_from_u8_adt7461(data, data->temp8[2]);
+       else if (data->kind == max6646)
+               temp = temp_from_u8(data->temp8[2]);
+       else
+               temp = temp_from_s8(data->temp8[2]);
+
+       data->temp_hyst = hyst_to_reg(temp - val);
        i2c_smbus_write_byte_data(client, LM90_REG_W_TCRIT_HYST,
-                                 hyst_to_reg(hyst));
+                                 data->temp_hyst);
        mutex_unlock(&data->update_lock);
        return count;
 }
@@ -627,150 +650,123 @@ static int lm90_read_reg(struct i2c_client* client, u8 reg, u8 *value)
 }
 
 /* Return 0 if detection is successful, -ENODEV otherwise */
-static int lm90_detect(struct i2c_client *new_client, int kind,
+static int lm90_detect(struct i2c_client *new_client,
                       struct i2c_board_info *info)
 {
        struct i2c_adapter *adapter = new_client->adapter;
        int address = new_client->addr;
-       const char *name = "";
+       const char *name = NULL;
+       int man_id, chip_id, reg_config1, reg_convrate;
 
        if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
                return -ENODEV;
 
-       /*
-        * Now we do the remaining detection. A negative kind means that
-        * the driver was loaded with no force parameter (default), so we
-        * must both detect and identify the chip. A zero kind means that
-        * the driver was loaded with the force parameter, the detection
-        * step shall be skipped. A positive kind means that the driver
-        * was loaded with the force parameter and a given kind of chip is
-        * requested, so both the detection and the identification steps
-        * are skipped.
-        */
-
-       /* Default to an LM90 if forced */
-       if (kind == 0)
-               kind = lm90;
-
-       if (kind < 0) { /* detection and identification */
-               int man_id, chip_id, reg_config1, reg_convrate;
-
-               if ((man_id = i2c_smbus_read_byte_data(new_client,
+       /* detection and identification */
+       if ((man_id = i2c_smbus_read_byte_data(new_client,
                                                LM90_REG_R_MAN_ID)) < 0
-                || (chip_id = i2c_smbus_read_byte_data(new_client,
+        || (chip_id = i2c_smbus_read_byte_data(new_client,
                                                LM90_REG_R_CHIP_ID)) < 0
-                || (reg_config1 = i2c_smbus_read_byte_data(new_client,
+        || (reg_config1 = i2c_smbus_read_byte_data(new_client,
                                                LM90_REG_R_CONFIG1)) < 0
-                || (reg_convrate = i2c_smbus_read_byte_data(new_client,
+        || (reg_convrate = i2c_smbus_read_byte_data(new_client,
                                                LM90_REG_R_CONVRATE)) < 0)
+               return -ENODEV;
+
+       if ((address == 0x4C || address == 0x4D)
+        && man_id == 0x01) { /* National Semiconductor */
+               int reg_config2;
+
+               reg_config2 = i2c_smbus_read_byte_data(new_client,
+                                               LM90_REG_R_CONFIG2);
+               if (reg_config2 < 0)
                        return -ENODEV;
-               
-               if ((address == 0x4C || address == 0x4D)
-                && man_id == 0x01) { /* National Semiconductor */
-                       int reg_config2;
-
-                       if ((reg_config2 = i2c_smbus_read_byte_data(new_client,
-                                               LM90_REG_R_CONFIG2)) < 0)
-                               return -ENODEV;
-
-                       if ((reg_config1 & 0x2A) == 0x00
-                        && (reg_config2 & 0xF8) == 0x00
-                        && reg_convrate <= 0x09) {
-                               if (address == 0x4C
-                                && (chip_id & 0xF0) == 0x20) { /* LM90 */
-                                       kind = lm90;
-                               } else
-                               if ((chip_id & 0xF0) == 0x30) { /* LM89/LM99 */
-                                       kind = lm99;
-                               } else
-                               if (address == 0x4C
-                                && (chip_id & 0xF0) == 0x10) { /* LM86 */
-                                       kind = lm86;
-                               }
-                       }
-               } else
-               if ((address == 0x4C || address == 0x4D)
-                && man_id == 0x41) { /* Analog Devices */
-                       if ((chip_id & 0xF0) == 0x40 /* ADM1032 */
-                        && (reg_config1 & 0x3F) == 0x00
-                        && reg_convrate <= 0x0A) {
-                               kind = adm1032;
-                       } else
-                       if (chip_id == 0x51 /* ADT7461 */
-                        && (reg_config1 & 0x1B) == 0x00
-                        && reg_convrate <= 0x0A) {
-                               kind = adt7461;
-                       }
-               } else
-               if (man_id == 0x4D) { /* Maxim */
-                       /*
-                        * The MAX6657, MAX6658 and MAX6659 do NOT have a
-                        * chip_id register. Reading from that address will
-                        * return the last read value, which in our case is
-                        * those of the man_id register. Likewise, the config1
-                        * register seems to lack a low nibble, so the value
-                        * will be those of the previous read, so in our case
-                        * those of the man_id register.
-                        */
-                       if (chip_id == man_id
-                        && (address == 0x4C || address == 0x4D)
-                        && (reg_config1 & 0x1F) == (man_id & 0x0F)
-                        && reg_convrate <= 0x09) {
-                               kind = max6657;
+
+               if ((reg_config1 & 0x2A) == 0x00
+                && (reg_config2 & 0xF8) == 0x00
+                && reg_convrate <= 0x09) {
+                       if (address == 0x4C
+                        && (chip_id & 0xF0) == 0x20) { /* LM90 */
+                               name = "lm90";
                        } else
-                       /* The chip_id register of the MAX6680 and MAX6681
-                        * holds the revision of the chip.
-                        * the lowest bit of the config1 register is unused
-                        * and should return zero when read, so should the
-                        * second to last bit of config1 (software reset)
-                        */
-                       if (chip_id == 0x01
-                        && (reg_config1 & 0x03) == 0x00
-                        && reg_convrate <= 0x07) {
-                               kind = max6680;
+                       if ((chip_id & 0xF0) == 0x30) { /* LM89/LM99 */
+                               name = "lm99";
+                               dev_info(&adapter->dev,
+                                        "Assuming LM99 chip at 0x%02x\n",
+                                        address);
+                               dev_info(&adapter->dev,
+                                        "If it is an LM89, instantiate it "
+                                        "with the new_device sysfs "
+                                        "interface\n");
                        } 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 (address == 0x4C
+                        && (chip_id & 0xF0) == 0x10) { /* LM86 */
+                               name = "lm86";
                        }
                }
-
-               if (kind <= 0) { /* identification failed */
-                       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;
+       } else
+       if ((address == 0x4C || address == 0x4D)
+        && man_id == 0x41) { /* Analog Devices */
+               if ((chip_id & 0xF0) == 0x40 /* ADM1032 */
+                && (reg_config1 & 0x3F) == 0x00
+                && reg_convrate <= 0x0A) {
+                       name = "adm1032";
+                       /* The ADM1032 supports PEC, but only if combined
+                          transactions are not used. */
+                       if (i2c_check_functionality(adapter,
+                                                   I2C_FUNC_SMBUS_BYTE))
+                               info->flags |= I2C_CLIENT_PEC;
+               } else
+               if (chip_id == 0x51 /* ADT7461 */
+                && (reg_config1 & 0x1B) == 0x00
+                && reg_convrate <= 0x0A) {
+                       name = "adt7461";
+               }
+       } else
+       if (man_id == 0x4D) { /* Maxim */
+               /*
+                * The MAX6657, MAX6658 and MAX6659 do NOT have a chip_id
+                * register. Reading from that address will return the last
+                * read value, which in our case is those of the man_id
+                * register. Likewise, the config1 register seems to lack a
+                * low nibble, so the value will be those of the previous
+                * read, so in our case those of the man_id register.
+                */
+               if (chip_id == man_id
+                && (address == 0x4C || address == 0x4D)
+                && (reg_config1 & 0x1F) == (man_id & 0x0F)
+                && reg_convrate <= 0x09) {
+                       name = "max6657";
+               } else
+               /*
+                * The chip_id register of the MAX6680 and MAX6681 holds the
+                * revision of the chip. The lowest bit of the config1 register
+                * is unused and should return zero when read, so should the
+                * second to last bit of config1 (software reset).
+                */
+               if (chip_id == 0x01
+                && (reg_config1 & 0x03) == 0x00
+                && reg_convrate <= 0x07) {
+                       name = "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) {
+                       name = "max6646";
                }
        }
 
-       /* Fill the i2c board info */
-       if (kind == lm90) {
-               name = "lm90";
-       } else if (kind == adm1032) {
-               name = "adm1032";
-               /* The ADM1032 supports PEC, but only if combined
-                  transactions are not used. */
-               if (i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE))
-                       info->flags |= I2C_CLIENT_PEC;
-       } else if (kind == lm99) {
-               name = "lm99";
-       } else if (kind == lm86) {
-               name = "lm86";
-       } else if (kind == max6657) {
-               name = "max6657";
-       } else if (kind == max6680) {
-               name = "max6680";
-       } else if (kind == adt7461) {
-               name = "adt7461";
-       } else if (kind == max6646) {
-               name = "max6646";
+       if (!name) { /* identification failed */
+               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;
        }
+
        strlcpy(info->type, name, I2C_NAME_SIZE);
 
        return 0;