From: Guenter Roeck Date: Thu, 21 Sep 2017 23:17:53 +0000 (-0700) Subject: Simplify and fix temperature sensor type detection X-Git-Tag: v1.0^0 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=59ea85eb83d64e6a073619b3f96ea0ce4e3a7b12;p=groeck-it87 Simplify and fix temperature sensor type detection Temperature sensor types won't change, so we only need to read it once. Also fix temperature register calculation. Signed-off-by: Guenter Roeck --- diff --git a/it87.c b/it87.c index e1d3b2a..76baaeb 100644 --- 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)