summaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/nct7904.c
diff options
context:
space:
mode:
authoramy.shih <amy.shih@advantech.com.tw>2019-05-31 06:20:47 -0400
committerGuenter Roeck <linux@roeck-us.net>2019-06-23 21:33:01 -0400
commitb67b7356135a4f969a33cde46359ab1068a75117 (patch)
tree5c90942114d57a2b01cdbe46225eb3daedf19eee /drivers/hwmon/nct7904.c
parent37ab356417950bcefce49aa18a2c9d68dfcaab4b (diff)
hwmon: (nct7904) Fix the incorrect value of tcpu_mask in nct7904_data struct.
Detect the multi-function of voltage, thermal diode and thermistor from register VT_ADC_MD_REG to set value of tcpu_mask in nct7904_data struct, set temp[1-5]_input the input values TEMP_CH1~4 and LTD of temperature. Set temp[6~13]_input the input values of DTS temperature that correspond to sensors TCPU1~8. Signed-off-by: amy.shih <amy.shih@advantech.com.tw> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Diffstat (limited to 'drivers/hwmon/nct7904.c')
-rw-r--r--drivers/hwmon/nct7904.c72
1 files changed, 63 insertions, 9 deletions
diff --git a/drivers/hwmon/nct7904.c b/drivers/hwmon/nct7904.c
index 58a957445484..5708171197e7 100644
--- a/drivers/hwmon/nct7904.c
+++ b/drivers/hwmon/nct7904.c
@@ -4,6 +4,9 @@
4 * 4 *
5 * Copyright (c) 2015 Kontron 5 * Copyright (c) 2015 Kontron
6 * Author: Vadim V. Vlasov <vvlasov@dev.rtsoft.ru> 6 * Author: Vadim V. Vlasov <vvlasov@dev.rtsoft.ru>
7 *
8 * Copyright (c) 2019 Advantech
9 * Author: Amy.Shih <amy.shih@advantech.com.tw>
7 */ 10 */
8 11
9#include <linux/module.h> 12#include <linux/module.h>
@@ -50,6 +53,8 @@
50#define T_CPU1_HV_REG 0xA0 /* Bank 0; 2 regs (HV/LV) per sensor */ 53#define T_CPU1_HV_REG 0xA0 /* Bank 0; 2 regs (HV/LV) per sensor */
51 54
52#define PRTS_REG 0x03 /* Bank 2 */ 55#define PRTS_REG 0x03 /* Bank 2 */
56#define PFE_REG 0x00 /* Bank 2; PECI Function Enable */
57#define TSI_CTRL_REG 0x50 /* Bank 2; TSI Control Register */
53#define FANCTL1_FMR_REG 0x00 /* Bank 3; 1 reg per channel */ 58#define FANCTL1_FMR_REG 0x00 /* Bank 3; 1 reg per channel */
54#define FANCTL1_OUT_REG 0x10 /* Bank 3; 1 reg per channel */ 59#define FANCTL1_OUT_REG 0x10 /* Bank 3; 1 reg per channel */
55 60
@@ -65,6 +70,8 @@ struct nct7904_data {
65 u32 vsen_mask; 70 u32 vsen_mask;
66 u32 tcpu_mask; 71 u32 tcpu_mask;
67 u8 fan_mode[FANCTL_MAX]; 72 u8 fan_mode[FANCTL_MAX];
73 u8 enable_dts;
74 u8 has_dts;
68}; 75};
69 76
70/* Access functions */ 77/* Access functions */
@@ -229,11 +236,15 @@ static int nct7904_read_temp(struct device *dev, u32 attr, int channel,
229 236
230 switch (attr) { 237 switch (attr) {
231 case hwmon_temp_input: 238 case hwmon_temp_input:
232 if (channel == 0) 239 if (channel == 4)
233 ret = nct7904_read_reg16(data, BANK_0, LTD_HV_REG); 240 ret = nct7904_read_reg16(data, BANK_0, LTD_HV_REG);
241 else if (channel < 5)
242 ret = nct7904_read_reg16(data, BANK_0,
243 TEMP_CH1_HV_REG + channel * 4);
234 else 244 else
235 ret = nct7904_read_reg16(data, BANK_0, 245 ret = nct7904_read_reg16(data, BANK_0,
236 T_CPU1_HV_REG + (channel - 1) * 2); 246 T_CPU1_HV_REG + (channel - 5)
247 * 2);
237 if (ret < 0) 248 if (ret < 0)
238 return ret; 249 return ret;
239 temp = ((ret & 0xff00) >> 5) | (ret & 0x7); 250 temp = ((ret & 0xff00) >> 5) | (ret & 0x7);
@@ -249,11 +260,11 @@ static umode_t nct7904_temp_is_visible(const void *_data, u32 attr, int channel)
249 const struct nct7904_data *data = _data; 260 const struct nct7904_data *data = _data;
250 261
251 if (attr == hwmon_temp_input) { 262 if (attr == hwmon_temp_input) {
252 if (channel == 0) { 263 if (channel < 5) {
253 if (data->vsen_mask & BIT(17)) 264 if (data->tcpu_mask & BIT(channel))
254 return 0444; 265 return 0444;
255 } else { 266 } else {
256 if (data->tcpu_mask & BIT(channel - 1)) 267 if (data->has_dts & BIT(channel - 5))
257 return 0444; 268 return 0444;
258 } 269 }
259 } 270 }
@@ -460,6 +471,7 @@ static int nct7904_probe(struct i2c_client *client,
460 struct device *dev = &client->dev; 471 struct device *dev = &client->dev;
461 int ret, i; 472 int ret, i;
462 u32 mask; 473 u32 mask;
474 u8 val, bit;
463 475
464 data = devm_kzalloc(dev, sizeof(struct nct7904_data), GFP_KERNEL); 476 data = devm_kzalloc(dev, sizeof(struct nct7904_data), GFP_KERNEL);
465 if (!data) 477 if (!data)
@@ -493,10 +505,52 @@ static int nct7904_probe(struct i2c_client *client,
493 data->vsen_mask = mask; 505 data->vsen_mask = mask;
494 506
495 /* CPU_TEMP attributes */ 507 /* CPU_TEMP attributes */
496 ret = nct7904_read_reg16(data, BANK_0, DTS_T_CTRL0_REG); 508 ret = nct7904_read_reg(data, BANK_0, VT_ADC_CTRL0_REG);
497 if (ret < 0) 509
498 return ret; 510 if ((ret & 0x6) == 0x6)
499 data->tcpu_mask = ((ret >> 8) & 0xf) | ((ret & 0xf) << 4); 511 data->tcpu_mask |= 1; /* TR1 */
512 if ((ret & 0x18) == 0x18)
513 data->tcpu_mask |= 2; /* TR2 */
514 if ((ret & 0x20) == 0x20)
515 data->tcpu_mask |= 4; /* TR3 */
516 if ((ret & 0x80) == 0x80)
517 data->tcpu_mask |= 8; /* TR4 */
518
519 /* LTD */
520 ret = nct7904_read_reg(data, BANK_0, VT_ADC_CTRL2_REG);
521 if ((ret & 0x02) == 0x02)
522 data->tcpu_mask |= 0x10;
523
524 /* Multi-Function detecting for Volt and TR/TD */
525 ret = nct7904_read_reg(data, BANK_0, VT_ADC_MD_REG);
526
527 for (i = 0; i < 4; i++) {
528 val = (ret & (0x03 << i)) >> (i * 2);
529 bit = (1 << i);
530 if (val == 0)
531 data->tcpu_mask &= ~bit;
532 }
533
534 /* PECI */
535 ret = nct7904_read_reg(data, BANK_2, PFE_REG);
536 if (ret & 0x80) {
537 data->enable_dts = 1; //Enable DTS & PECI
538 } else {
539 ret = nct7904_read_reg(data, BANK_2, TSI_CTRL_REG);
540 if (ret & 0x80)
541 data->enable_dts = 0x3; //Enable DTS & TSI
542 }
543
544 /* Check DTS enable status */
545 if (data->enable_dts) {
546 data->has_dts =
547 nct7904_read_reg(data, BANK_0, DTS_T_CTRL0_REG) & 0xF;
548 if (data->enable_dts & 0x2) {
549 data->has_dts |=
550 (nct7904_read_reg(data, BANK_0, DTS_T_CTRL1_REG) & 0xF)
551 << 4;
552 }
553 }
500 554
501 for (i = 0; i < FANCTL_MAX; i++) { 555 for (i = 0; i < FANCTL_MAX; i++) {
502 ret = nct7904_read_reg(data, BANK_3, FANCTL1_FMR_REG + i); 556 ret = nct7904_read_reg(data, BANK_3, FANCTL1_FMR_REG + i);