]> git.sur5r.net Git - groeck-it87/commitdiff
Simplify and fix temperature sensor type detection v1.0
authorGuenter Roeck <linux@roeck-us.net>
Thu, 21 Sep 2017 23:17:53 +0000 (16:17 -0700)
committerGuenter Roeck <linux@roeck-us.net>
Thu, 21 Sep 2017 23:21:28 +0000 (16:21 -0700)
Temperature sensor types won't change, so we only need to read it once.
Also fix temperature register calculation.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
it87.c

diff --git a/it87.c b/it87.c
index e1d3b2ac603ff598e014db9fa86bd27bb734e656..76baaebb9cea438fc7265b9a75547fd9073e8f97 100644 (file)
--- a/it87.c
+++ b/it87.c
@@ -753,6 +753,7 @@ struct it87_data {
        s8 temp[NUM_TEMP][4];   /* [nr][0]=temp, [1]=min, [2]=max, [3]=offset */
        u8 num_temp_limit;      /* Number of temperature limit registers */
        u8 num_temp_offset;     /* Number of temperature offset registers */
+       u8 temp_src[4];         /* Up to 4 temperature source registers */
        u8 sensor;              /* Register value (IT87_REG_TEMP_ENABLE) */
        u8 extra;               /* Register value (IT87_REG_TEMP_EXTRA) */
        u8 fan_div[NUM_FAN_DIV];/* Register encoding, shifted right */
@@ -1336,10 +1337,9 @@ static int get_temp_type(struct it87_data *data, int index)
        int type = 0;
 
        if (has_bank_sel(data)) {
-               int s1reg = IT87_REG_TEMP_SRC1[index/2] >> ((index % 2) * 4);
                u8 src1, src2;
 
-               src1 = (it87_read_value(data, s1reg) >> ((index % 2) * 4)) & 0x0f;
+               src1 = (data->temp_src[index / 2] >> ((index % 2) * 4)) & 0x0f;
 
                switch (data->type) {
                case it8686:
@@ -1355,7 +1355,7 @@ static int get_temp_type(struct it87_data *data, int index)
                                index = src1;
                                break;
                        }
-                       src2 = it87_read_value(data, IT87_REG_TEMP_SRC2);
+                       src2 = data->temp_src[3];
                        switch(src1) {
                        case 3:
                                type = (src2 & BIT(index)) ? 6 : 5;
@@ -3580,6 +3580,13 @@ static void it87_init_device(struct platform_device *pdev)
                }
        }
 
+       if (has_bank_sel(data)) {
+               for (i = 0; i < 3; i++)
+                       data->temp_src[i] =
+                               it87_read_value(data, IT87_REG_TEMP_SRC1[i]);
+               data->temp_src[3] = it87_read_value(data, IT87_REG_TEMP_SRC2);
+       }
+
        /* Start monitoring */
        it87_write_value(data, IT87_REG_CONFIG,
                         (it87_read_value(data, IT87_REG_CONFIG) & 0x3e)