]> bbs.cooldavid.org Git - net-next-2.6.git/blobdiff - drivers/hwmon/w83795.c
hwmon: (w83795) Avoid reading the same register twice
[net-next-2.6.git] / drivers / hwmon / w83795.c
index f4b7cb45ebcbdb6f43941b573aa86eb9f734d93f..aea3275f5daed2b1fa445eb56834c0c83808c33f 100644 (file)
@@ -236,6 +236,7 @@ static const u8 IN_LSB_SHIFT_IDX[][2] = {
 #define W83795_REG_DTSC                        0x301
 #define W83795_REG_DTSE                        0x302
 #define W83795_REG_DTS(index)          (0x26 + (index))
+#define W83795_REG_PECI_TBASE(index)   (0x320 + (index))
 
 #define DTS_CRIT                       0
 #define DTS_CRIT_HYST                  1
@@ -397,7 +398,6 @@ struct w83795_data {
 
        u8 alarms[6];           /* Register value */
        u8 beeps[6];            /* Register value */
-       u8 beep_enable;
 
        char valid;
 };
@@ -615,39 +615,6 @@ store_beep(struct device *dev, struct device_attribute *attr,
        return count;
 }
 
-static ssize_t
-show_beep_enable(struct device *dev, struct device_attribute *attr, char *buf)
-{
-       struct i2c_client *client = to_i2c_client(dev);
-       struct w83795_data *data = i2c_get_clientdata(client);
-       return sprintf(buf, "%u\n", data->beep_enable);
-}
-
-static ssize_t
-store_beep_enable(struct device *dev, struct device_attribute *attr,
-                 const char *buf, size_t count)
-{
-       struct i2c_client *client = to_i2c_client(dev);
-       struct w83795_data *data = i2c_get_clientdata(client);
-       unsigned long val;
-       u8 tmp;
-
-       if (strict_strtoul(buf, 10, &val) < 0)
-               return -EINVAL;
-       if (val != 0 && val != 1)
-               return -EINVAL;
-
-       mutex_lock(&data->update_lock);
-       data->beep_enable = val;
-       tmp = w83795_read(client, W83795_REG_BEEP(5));
-       tmp &= 0x7f;
-       tmp |= val << 7;
-       w83795_write(client, W83795_REG_BEEP(5), tmp);
-       mutex_unlock(&data->update_lock);
-
-       return count;
-}
-
 /* Write any value to clear chassis alarm */
 static ssize_t
 store_chassis_clear(struct device *dev,
@@ -1688,8 +1655,8 @@ static const struct sensor_device_attribute_2 w83795_pwm[][7] = {
 static const struct sensor_device_attribute_2 sda_single_files[] = {
        SENSOR_ATTR_2(chassis, S_IWUSR | S_IRUGO, show_alarm_beep,
                      store_chassis_clear, ALARM_STATUS, 46),
-       SENSOR_ATTR_2(beep_enable, S_IWUSR | S_IRUGO, show_beep_enable,
-                     store_beep_enable, NOT_USED, NOT_USED),
+       SENSOR_ATTR_2(beep_enable, S_IWUSR | S_IRUGO, show_alarm_beep,
+                     store_beep, BEEP_ENABLE, 47),
        SENSOR_ATTR_2(speed_cruise_tolerance, S_IWUSR | S_IRUGO, show_fanin,
                store_fanin, FANIN_TOL, NOT_USED),
        SENSOR_ATTR_2(pwm_default, S_IWUSR | S_IRUGO, show_sf_setup,
@@ -1993,6 +1960,18 @@ static int w83795_probe(struct i2c_client *client,
                data->has_dts = w83795_read(client, W83795_REG_DTSE);
        }
 
+       /* Report PECI Tbase values */
+       if (data->enable_dts == 1) {
+               for (i = 0; i < 8; i++) {
+                       if (!(data->has_dts & (1 << i)))
+                               continue;
+                       tmp = w83795_read(client, W83795_REG_PECI_TBASE(i));
+                       dev_info(&client->dev,
+                                "PECI agent %d Tbase temperature: %u\n",
+                                i + 1, (unsigned int)tmp & 0x7f);
+               }
+       }
+
        /* First update the voltages measured value and limits */
        for (i = 0; i < ARRAY_SIZE(data->in); i++) {
                if (!(data->has_in & (1 << i)))
@@ -2007,6 +1986,9 @@ static int w83795_probe(struct i2c_client *client,
                data->in[i][IN_READ] = tmp;
        }
        for (i = 0; i < IN_LSB_REG_NUM; i++) {
+               if ((i == 2 && data->chip_type == w83795adg) ||
+                   (i >= 4 && !(data->has_in & (1 << (i + 11)))))
+                       continue;
                data->in_lsb[i][IN_MAX] =
                        w83795_read(client, IN_LSB_REG(i, IN_MAX));
                data->in_lsb[i][IN_LOW] =
@@ -2016,13 +1998,17 @@ static int w83795_probe(struct i2c_client *client,
 
        /* First update fan and limits */
        for (i = 0; i < ARRAY_SIZE(data->fan); i++) {
+               /* Each register contains LSB for 2 fans, but we want to
+                * read it only once to save time */
+               if ((i & 1) == 0 && (data->has_fan & (3 << i)))
+                       tmp = w83795_read(client, W83795_REG_FAN_MIN_LSB(i));
+
                if (!(data->has_fan & (1 << i)))
                        continue;
                data->fan_min[i] =
                        w83795_read(client, W83795_REG_FAN_MIN_HL(i)) << 4;
                data->fan_min[i] |=
-                 (w83795_read(client, W83795_REG_FAN_MIN_LSB(i)) >>
-                       W83795_REG_FAN_MIN_LSB_SHIFT(i)) & 0x0F;
+                       (tmp >> W83795_REG_FAN_MIN_LSB_SHIFT(i)) & 0x0F;
                data->fan[i] = w83795_read(client, W83795_REG_FAN(i)) << 4;
                data->fan[i] |=
                  (w83795_read(client, W83795_REG_VRLSB) >> 4) & 0x0F;
@@ -2123,8 +2109,6 @@ static int w83795_probe(struct i2c_client *client,
                data->alarms[i] = w83795_read(client, W83795_REG_ALARM(i));
                data->beeps[i] = w83795_read(client, W83795_REG_BEEP(i));
        }
-       data->beep_enable =
-               (w83795_read(client, W83795_REG_BEEP(5)) >> 7) & 0x01;
 
        err = w83795_handle_files(dev, device_create_file);
        if (err)