From patchwork Mon Jun 17 08:08:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amy.Shih@advantech.com.tw X-Patchwork-Id: 10998287 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4FCD5924 for ; Mon, 17 Jun 2019 08:09:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 39B6C287FE for ; Mon, 17 Jun 2019 08:09:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2C29828807; Mon, 17 Jun 2019 08:09:16 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DD7F4287FE for ; Mon, 17 Jun 2019 08:09:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725862AbfFQIJO (ORCPT ); Mon, 17 Jun 2019 04:09:14 -0400 Received: from aclms1.advantech.com.tw ([61.58.41.199]:52260 "EHLO ACLMS1.advantech.com.tw" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725995AbfFQIJO (ORCPT ); Mon, 17 Jun 2019 04:09:14 -0400 Received: from taipei08.ADVANTECH.CORP (unverified [172.20.0.235]) by ACLMS1.advantech.com.tw (Clearswift SMTPRS 5.6.0) with ESMTP id ; Mon, 17 Jun 2019 16:09:09 +0800 From: To: CC: , , , Jean Delvare , Guenter Roeck , , Subject: [v2 1/9] hwmon: (nct7904) Add error handling in probe function. Date: Mon, 17 Jun 2019 08:08:50 +0000 Message-ID: <928e46508bbe1ebc0763c3d2403a5aebe95af552.1560756733.git.amy.shih@advantech.com.tw> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 X-Originating-IP: [172.17.10.58] X-ClientProxiedBy: ACLDAG.ADVANTECH.CORP (172.20.2.88) To taipei08.ADVANTECH.CORP (172.20.0.235) X-StopIT: No Sender: linux-hwmon-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: "amy.shih" When register read and write operations return errors, needs to add error handling. Signed-off-by: amy.shih --- Changes in v2: - Check for errors on register read and write operations. drivers/hwmon/nct7904.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/drivers/hwmon/nct7904.c b/drivers/hwmon/nct7904.c index 5708171197e7..401ed4a4a576 100644 --- a/drivers/hwmon/nct7904.c +++ b/drivers/hwmon/nct7904.c @@ -506,6 +506,8 @@ static int nct7904_probe(struct i2c_client *client, /* CPU_TEMP attributes */ ret = nct7904_read_reg(data, BANK_0, VT_ADC_CTRL0_REG); + if (ret < 0) + return ret; if ((ret & 0x6) == 0x6) data->tcpu_mask |= 1; /* TR1 */ @@ -518,11 +520,15 @@ static int nct7904_probe(struct i2c_client *client, /* LTD */ ret = nct7904_read_reg(data, BANK_0, VT_ADC_CTRL2_REG); + if (ret < 0) + return ret; if ((ret & 0x02) == 0x02) data->tcpu_mask |= 0x10; /* Multi-Function detecting for Volt and TR/TD */ ret = nct7904_read_reg(data, BANK_0, VT_ADC_MD_REG); + if (ret < 0) + return ret; for (i = 0; i < 4; i++) { val = (ret & (0x03 << i)) >> (i * 2); @@ -533,22 +539,29 @@ static int nct7904_probe(struct i2c_client *client, /* PECI */ ret = nct7904_read_reg(data, BANK_2, PFE_REG); + if (ret < 0) + return ret; if (ret & 0x80) { data->enable_dts = 1; //Enable DTS & PECI } else { ret = nct7904_read_reg(data, BANK_2, TSI_CTRL_REG); + if (ret < 0) + return ret; if (ret & 0x80) data->enable_dts = 0x3; //Enable DTS & TSI } /* Check DTS enable status */ if (data->enable_dts) { - data->has_dts = - nct7904_read_reg(data, BANK_0, DTS_T_CTRL0_REG) & 0xF; + ret = nct7904_read_reg(data, BANK_0, DTS_T_CTRL0_REG); + if (ret < 0) + return ret; + data->has_dts = ret & 0xF; if (data->enable_dts & 0x2) { - data->has_dts |= - (nct7904_read_reg(data, BANK_0, DTS_T_CTRL1_REG) & 0xF) - << 4; + ret = nct7904_read_reg(data, BANK_0, DTS_T_CTRL1_REG); + if (ret < 0) + return ret; + data->has_dts |= (ret & 0xF) << 4; } } From patchwork Mon Jun 17 08:10:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amy.Shih@advantech.com.tw X-Patchwork-Id: 10998289 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 709FB112C for ; Mon, 17 Jun 2019 08:10:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 51FB128610 for ; Mon, 17 Jun 2019 08:10:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4054728685; Mon, 17 Jun 2019 08:10:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 973FB28610 for ; Mon, 17 Jun 2019 08:10:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726712AbfFQIKY (ORCPT ); Mon, 17 Jun 2019 04:10:24 -0400 Received: from aclms3.advantech.com.tw ([125.252.70.86]:38563 "EHLO ACLMS3.advantech.com.tw" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725995AbfFQIKY (ORCPT ); Mon, 17 Jun 2019 04:10:24 -0400 Received: from taipei08.ADVANTECH.CORP (unverified [172.20.0.235]) by ACLMS3.advantech.com.tw (Clearswift SMTPRS 5.6.0) with ESMTP id ; Mon, 17 Jun 2019 16:10:22 +0800 From: To: CC: , , , Jean Delvare , Guenter Roeck , , Subject: [v2 2/9] hwmon: (nct7904) Changes comments in probe function. Date: Mon, 17 Jun 2019 08:10:00 +0000 Message-ID: X-Mailer: git-send-email 2.17.1 In-Reply-To: <928e46508bbe1ebc0763c3d2403a5aebe95af552.1560756733.git.amy.shih@advantech.com.tw> References: <928e46508bbe1ebc0763c3d2403a5aebe95af552.1560756733.git.amy.shih@advantech.com.tw> MIME-Version: 1.0 X-Originating-IP: [172.17.10.58] X-ClientProxiedBy: ACLDAG.ADVANTECH.CORP (172.20.2.88) To taipei08.ADVANTECH.CORP (172.20.0.235) X-StopIT: No Sender: linux-hwmon-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: "amy.shih" Linux style for comments is the C89 "/* ... */" style, changes the comments to Linux style. Signed-off-by: amy.shih --- Changes in v2: - Fix wrong style of comments. drivers/hwmon/nct7904.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/hwmon/nct7904.c b/drivers/hwmon/nct7904.c index 401ed4a4a576..710c30562fc1 100644 --- a/drivers/hwmon/nct7904.c +++ b/drivers/hwmon/nct7904.c @@ -542,13 +542,13 @@ static int nct7904_probe(struct i2c_client *client, if (ret < 0) return ret; if (ret & 0x80) { - data->enable_dts = 1; //Enable DTS & PECI + data->enable_dts = 1; /* Enable DTS & PECI */ } else { ret = nct7904_read_reg(data, BANK_2, TSI_CTRL_REG); if (ret < 0) return ret; if (ret & 0x80) - data->enable_dts = 0x3; //Enable DTS & TSI + data->enable_dts = 0x3; /* Enable DTS & TSI */ } /* Check DTS enable status */ From patchwork Mon Jun 17 08:11:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amy.Shih@advantech.com.tw X-Patchwork-Id: 10998293 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 09E66924 for ; Mon, 17 Jun 2019 08:11:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F081128717 for ; Mon, 17 Jun 2019 08:11:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E413E28807; Mon, 17 Jun 2019 08:11:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B90CD28717 for ; Mon, 17 Jun 2019 08:11:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726215AbfFQIL2 (ORCPT ); Mon, 17 Jun 2019 04:11:28 -0400 Received: from aclms1.advantech.com.tw ([61.58.41.199]:52386 "EHLO ACLMS1.advantech.com.tw" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725837AbfFQIL2 (ORCPT ); Mon, 17 Jun 2019 04:11:28 -0400 Received: from taipei08.ADVANTECH.CORP (unverified [172.20.0.235]) by ACLMS1.advantech.com.tw (Clearswift SMTPRS 5.6.0) with ESMTP id ; Mon, 17 Jun 2019 16:11:26 +0800 From: To: CC: , , , Jean Delvare , Guenter Roeck , , Subject: [v2 3/9] hwmon: (nct7904) Add extra sysfs support for fan, voltage and temperature. Date: Mon, 17 Jun 2019 08:11:07 +0000 Message-ID: X-Mailer: git-send-email 2.17.1 In-Reply-To: <928e46508bbe1ebc0763c3d2403a5aebe95af552.1560756733.git.amy.shih@advantech.com.tw> References: <928e46508bbe1ebc0763c3d2403a5aebe95af552.1560756733.git.amy.shih@advantech.com.tw> MIME-Version: 1.0 X-Originating-IP: [172.17.10.58] X-ClientProxiedBy: ACLDAG.ADVANTECH.CORP (172.20.2.88) To taipei08.ADVANTECH.CORP (172.20.0.235) X-StopIT: No Sender: linux-hwmon-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: "amy.shih" NCT-7904D also supports reading of channel limitation registers and SMI status registers for fan, voltage and temperature monitoring, and also supports reading of temperature sensor type which is thermal diode, thermistor, AMD SB-TSI or Intel PECI, thus add below sysfs nodes: -fan[1-*]_min -fan[1-*]_alarm -in[1-*]_min -in[1-*]_max -in[1-*]_alarm -temp[1-*]_max -temp[1-*]_max_hyst -temp[1-*]_emergency -temp[1-*]_emergency_hyst -temp[1-*]_alarm -temp[1-*]_type Signed-off-by: amy.shih --- Changes in v2: - Fix bad fallthrough in various switch statements. - Fix the wrong declared of tmp as u8 in nct7904_write_in, declared tmp to int. drivers/hwmon/nct7904.c | 469 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 424 insertions(+), 45 deletions(-) diff --git a/drivers/hwmon/nct7904.c b/drivers/hwmon/nct7904.c index 710c30562fc1..cdd67932938d 100644 --- a/drivers/hwmon/nct7904.c +++ b/drivers/hwmon/nct7904.c @@ -46,10 +46,33 @@ #define DTS_T_CTRL1_REG 0x27 #define VT_ADC_MD_REG 0x2E +#define VSEN1_HV_LL_REG 0x02 /* Bank 1; 2 regs (HV/LV) per sensor */ +#define VSEN1_LV_LL_REG 0x03 /* Bank 1; 2 regs (HV/LV) per sensor */ +#define VSEN1_HV_HL_REG 0x00 /* Bank 1; 2 regs (HV/LV) per sensor */ +#define VSEN1_LV_HL_REG 0x01 /* Bank 1; 2 regs (HV/LV) per sensor */ +#define SMI_STS1_REG 0xC1 /* Bank 0; SMI Status Register */ +#define SMI_STS5_REG 0xC5 /* Bank 0; SMI Status Register */ +#define SMI_STS7_REG 0xC7 /* Bank 0; SMI Status Register */ +#define SMI_STS8_REG 0xC8 /* Bank 0; SMI Status Register */ + #define VSEN1_HV_REG 0x40 /* Bank 0; 2 regs (HV/LV) per sensor */ #define TEMP_CH1_HV_REG 0x42 /* Bank 0; same as VSEN2_HV */ #define LTD_HV_REG 0x62 /* Bank 0; 2 regs in VSEN range */ +#define LTD_HV_HL_REG 0x44 /* Bank 1; 1 reg for LTD */ +#define LTD_LV_HL_REG 0x45 /* Bank 1; 1 reg for LTD */ +#define LTD_HV_LL_REG 0x46 /* Bank 1; 1 reg for LTD */ +#define LTD_LV_LL_REG 0x47 /* Bank 1; 1 reg for LTD */ +#define TEMP_CH1_CH_REG 0x05 /* Bank 1; 1 reg for LTD */ +#define TEMP_CH1_W_REG 0x06 /* Bank 1; 1 reg for LTD */ +#define TEMP_CH1_WH_REG 0x07 /* Bank 1; 1 reg for LTD */ +#define TEMP_CH1_C_REG 0x04 /* Bank 1; 1 reg per sensor */ +#define DTS_T_CPU1_C_REG 0x90 /* Bank 1; 1 reg per sensor */ +#define DTS_T_CPU1_CH_REG 0x91 /* Bank 1; 1 reg per sensor */ +#define DTS_T_CPU1_W_REG 0x92 /* Bank 1; 1 reg per sensor */ +#define DTS_T_CPU1_WH_REG 0x93 /* Bank 1; 1 reg per sensor */ #define FANIN1_HV_REG 0x80 /* Bank 0; 2 regs (HV/LV) per sensor */ +#define FANIN1_HV_HL_REG 0x60 /* Bank 1; 2 regs (HV/LV) per sensor */ +#define FANIN1_LV_HL_REG 0x61 /* Bank 1; 2 regs (HV/LV) per sensor */ #define T_CPU1_HV_REG 0xA0 /* Bank 0; 2 regs (HV/LV) per sensor */ #define PRTS_REG 0x03 /* Bank 2 */ @@ -58,6 +81,8 @@ #define FANCTL1_FMR_REG 0x00 /* Bank 3; 1 reg per channel */ #define FANCTL1_OUT_REG 0x10 /* Bank 3; 1 reg per channel */ +#define ENABLE_TSI BIT(1) + static const unsigned short normal_i2c[] = { 0x2d, 0x2e, I2C_CLIENT_END }; @@ -72,6 +97,7 @@ struct nct7904_data { u8 fan_mode[FANCTL_MAX]; u8 enable_dts; u8 has_dts; + u8 temp_mode; /* 0: TR mode, 1: TD mode */ }; /* Access functions */ @@ -170,6 +196,25 @@ static int nct7904_read_fan(struct device *dev, u32 attr, int channel, rpm = 1350000 / cnt; *val = rpm; return 0; + case hwmon_fan_min: + ret = nct7904_read_reg16(data, BANK_1, + FANIN1_HV_HL_REG + channel * 2); + if (ret < 0) + return ret; + cnt = ((ret & 0xff00) >> 3) | (ret & 0x1f); + if (cnt == 0x1fff) + rpm = 0; + else + rpm = 1350000 / cnt; + *val = rpm; + return 0; + case hwmon_fan_alarm: + ret = nct7904_read_reg(data, BANK_0, + SMI_STS7_REG + (channel >> 3)); + if (ret < 0) + return ret; + *val = (ret >> (channel & 0x07)) & 1; + return 0; default: return -EOPNOTSUPP; } @@ -179,8 +224,20 @@ static umode_t nct7904_fan_is_visible(const void *_data, u32 attr, int channel) { const struct nct7904_data *data = _data; - if (attr == hwmon_fan_input && data->fanin_mask & (1 << channel)) - return 0444; + switch (attr) { + case hwmon_fan_input: + case hwmon_fan_alarm: + if (data->fanin_mask & (1 << channel)) + return 0444; + break; + case hwmon_fan_min: + if (data->fanin_mask & (1 << channel)) + return 0644; + break; + default: + break; + } + return 0; } @@ -211,6 +268,37 @@ static int nct7904_read_in(struct device *dev, u32 attr, int channel, volt *= 6; /* 0.006V scale */ *val = volt; return 0; + case hwmon_in_min: + ret = nct7904_read_reg16(data, BANK_1, + VSEN1_HV_LL_REG + index * 4); + if (ret < 0) + return ret; + volt = ((ret & 0xff00) >> 5) | (ret & 0x7); + if (index < 14) + volt *= 2; /* 0.002V scale */ + else + volt *= 6; /* 0.006V scale */ + *val = volt; + return 0; + case hwmon_in_max: + ret = nct7904_read_reg16(data, BANK_1, + VSEN1_HV_HL_REG + index * 4); + if (ret < 0) + return ret; + volt = ((ret & 0xff00) >> 5) | (ret & 0x7); + if (index < 14) + volt *= 2; /* 0.002V scale */ + else + volt *= 6; /* 0.006V scale */ + *val = volt; + return 0; + case hwmon_in_alarm: + ret = nct7904_read_reg(data, BANK_0, + SMI_STS1_REG + (index >> 3)); + if (ret < 0) + return ret; + *val = (ret >> (index & 0x07)) & 1; + return 0; default: return -EOPNOTSUPP; } @@ -221,9 +309,20 @@ static umode_t nct7904_in_is_visible(const void *_data, u32 attr, int channel) const struct nct7904_data *data = _data; int index = nct7904_chan_to_index[channel]; - if (channel > 0 && attr == hwmon_in_input && - (data->vsen_mask & BIT(index))) - return 0444; + switch (attr) { + case hwmon_in_input: + case hwmon_in_alarm: + if (channel > 0 && (data->vsen_mask & BIT(index))) + return 0444; + break; + case hwmon_in_min: + case hwmon_in_max: + if (channel > 0 && (data->vsen_mask & BIT(index))) + return 0644; + break; + default: + break; + } return 0; } @@ -233,6 +332,7 @@ static int nct7904_read_temp(struct device *dev, u32 attr, int channel, { struct nct7904_data *data = dev_get_drvdata(dev); int ret, temp; + unsigned int reg1, reg2, reg3; switch (attr) { case hwmon_temp_input: @@ -250,16 +350,100 @@ static int nct7904_read_temp(struct device *dev, u32 attr, int channel, temp = ((ret & 0xff00) >> 5) | (ret & 0x7); *val = sign_extend32(temp, 10) * 125; return 0; + case hwmon_temp_alarm: + if (channel < 5) { + ret = nct7904_read_reg(data, BANK_0, + SMI_STS1_REG); + if (ret < 0) + return ret; + *val = (ret >> (channel & 0x07)) & 1; + } else { + if ((channel - 5) < 4) { + ret = nct7904_read_reg(data, BANK_0, + SMI_STS7_REG + + ((channel - 5) >> 3)); + if (ret < 0) + return ret; + *val = (ret >> ((channel - 5) & 0x07)) & 1; + } else { + ret = nct7904_read_reg(data, BANK_0, + SMI_STS8_REG + + ((channel - 5) >> 3)); + if (ret < 0) + return ret; + *val = (ret >> (((channel - 5) & 0x07) - 4)) + & 1; + } + } + return 0; + case hwmon_temp_type: + if (channel < 5) { + if ((data->tcpu_mask >> channel) & 0x01) { + if ((data->temp_mode >> channel) & 0x01) + *val = 3; /* TD */ + else + *val = 4; /* TR */ + } else { + *val = 0; + } + } else { + if ((data->has_dts >> (channel - 5)) & 0x01) { + if (data->enable_dts & ENABLE_TSI) + *val = 5; /* TSI */ + else + *val = 6; /* PECI */ + } else { + *val = 0; + } + } + return 0; + case hwmon_temp_max: + reg1 = LTD_HV_HL_REG; + reg2 = TEMP_CH1_C_REG; + reg3 = DTS_T_CPU1_C_REG; + break; + case hwmon_temp_max_hyst: + reg1 = LTD_LV_HL_REG; + reg2 = TEMP_CH1_CH_REG; + reg3 = DTS_T_CPU1_CH_REG; + break; + case hwmon_temp_emergency: + reg1 = LTD_HV_LL_REG; + reg2 = TEMP_CH1_W_REG; + reg3 = DTS_T_CPU1_W_REG; + break; + case hwmon_temp_emergency_hyst: + reg1 = LTD_LV_LL_REG; + reg2 = TEMP_CH1_WH_REG; + reg3 = DTS_T_CPU1_WH_REG; + break; default: return -EOPNOTSUPP; } + + if (channel == 4) + ret = nct7904_read_reg(data, BANK_1, reg1); + else if (channel < 5) + ret = nct7904_read_reg(data, BANK_1, + reg2 + channel * 8); + else + ret = nct7904_read_reg(data, BANK_1, + reg3 + (channel - 5) * 4); + + if (ret < 0) + return ret; + *val = ret * 1000; + return 0; } static umode_t nct7904_temp_is_visible(const void *_data, u32 attr, int channel) { const struct nct7904_data *data = _data; - if (attr == hwmon_temp_input) { + switch (attr) { + case hwmon_temp_input: + case hwmon_temp_alarm: + case hwmon_temp_type: if (channel < 5) { if (data->tcpu_mask & BIT(channel)) return 0444; @@ -267,6 +451,21 @@ static umode_t nct7904_temp_is_visible(const void *_data, u32 attr, int channel) if (data->has_dts & BIT(channel - 5)) return 0444; } + break; + case hwmon_temp_max: + case hwmon_temp_max_hyst: + case hwmon_temp_emergency: + case hwmon_temp_emergency_hyst: + if (channel < 5) { + if (data->tcpu_mask & BIT(channel)) + return 0644; + } else { + if (data->has_dts & BIT(channel - 5)) + return 0644; + } + break; + default: + break; } return 0; @@ -297,6 +496,137 @@ static int nct7904_read_pwm(struct device *dev, u32 attr, int channel, } } +static int nct7904_write_temp(struct device *dev, u32 attr, int channel, + long val) +{ + struct nct7904_data *data = dev_get_drvdata(dev); + int ret; + unsigned int reg1, reg2, reg3; + + val = clamp_val(val / 1000, -128, 127); + + switch (attr) { + case hwmon_temp_max: + reg1 = LTD_HV_HL_REG; + reg2 = TEMP_CH1_C_REG; + reg3 = DTS_T_CPU1_C_REG; + break; + case hwmon_temp_max_hyst: + reg1 = LTD_LV_HL_REG; + reg2 = TEMP_CH1_CH_REG; + reg3 = DTS_T_CPU1_CH_REG; + break; + case hwmon_temp_emergency: + reg1 = LTD_HV_LL_REG; + reg2 = TEMP_CH1_W_REG; + reg3 = DTS_T_CPU1_W_REG; + break; + case hwmon_temp_emergency_hyst: + reg1 = LTD_LV_LL_REG; + reg2 = TEMP_CH1_WH_REG; + reg3 = DTS_T_CPU1_WH_REG; + break; + default: + return -EOPNOTSUPP; + } + if (channel == 4) + ret = nct7904_write_reg(data, BANK_1, reg1, val); + else if (channel < 5) + ret = nct7904_write_reg(data, BANK_1, + reg2 + channel * 8, val); + else + ret = nct7904_write_reg(data, BANK_1, + reg3 + (channel - 5) * 4, val); + + return ret; +} + +static int nct7904_write_fan(struct device *dev, u32 attr, int channel, + long val) +{ + struct nct7904_data *data = dev_get_drvdata(dev); + int ret; + u8 tmp; + + switch (attr) { + case hwmon_fan_min: + if (val <= 0) + return 0x1fff; + + val = clamp_val((1350000 + (val >> 1)) / val, 1, 0x1fff); + tmp = (val >> 5) & 0xff; + ret = nct7904_write_reg(data, BANK_1, + FANIN1_HV_HL_REG + channel * 2, tmp); + if (ret < 0) + return ret; + tmp = val & 0x1f; + ret = nct7904_write_reg(data, BANK_1, + FANIN1_LV_HL_REG + channel * 2, tmp); + return ret; + default: + return -EOPNOTSUPP; + } +} + +static int nct7904_write_in(struct device *dev, u32 attr, int channel, + long val) +{ + struct nct7904_data *data = dev_get_drvdata(dev); + int ret, index, tmp; + + index = nct7904_chan_to_index[channel]; + + if (index < 14) + val = val / 2; /* 0.002V scale */ + else + val = val / 6; /* 0.006V scale */ + + val = clamp_val(val, 0, 0x7ff); /* Bit 15 is sign bit */ + + switch (attr) { + case hwmon_in_min: + tmp = nct7904_read_reg(data, BANK_1, + VSEN1_LV_LL_REG + index * 4); + if (tmp < 0) + return tmp; + tmp &= ~0x7; + tmp |= val & 0x7; + ret = nct7904_write_reg(data, BANK_1, + VSEN1_LV_LL_REG + index * 4, tmp); + if (ret < 0) + return ret; + tmp = nct7904_read_reg(data, BANK_1, + VSEN1_HV_LL_REG + index * 4); + if (tmp < 0) + return tmp; + tmp = (val >> 3) & 0xff; + ret = nct7904_write_reg(data, BANK_1, + VSEN1_HV_LL_REG + index * 4, tmp); + return ret; + case hwmon_in_max: + tmp = nct7904_read_reg(data, BANK_1, + VSEN1_LV_HL_REG + index * 4); + if (tmp < 0) + return tmp; + tmp &= ~0x7; + tmp |= val & 0x7; + ret = nct7904_write_reg(data, BANK_1, + VSEN1_LV_HL_REG + index * 4, tmp); + if (ret < 0) + return ret; + tmp = nct7904_read_reg(data, BANK_1, + VSEN1_HV_LL_REG + index * 4); + if (tmp < 0) + return tmp; + tmp = (val >> 3) & 0xff; + ret = nct7904_write_reg(data, BANK_1, + VSEN1_HV_LL_REG + index * 4, tmp); + return ret; + default: + return -EOPNOTSUPP; + } +} + static int nct7904_write_pwm(struct device *dev, u32 attr, int channel, long val) { @@ -354,8 +684,14 @@ static int nct7904_write(struct device *dev, enum hwmon_sensor_types type, u32 attr, int channel, long val) { switch (type) { + case hwmon_in: + return nct7904_write_in(dev, attr, channel, val); + case hwmon_fan: + return nct7904_write_fan(dev, attr, channel, val); case hwmon_pwm: return nct7904_write_pwm(dev, attr, channel, val); + case hwmon_temp: + return nct7904_write_temp(dev, attr, channel, val); default: return -EOPNOTSUPP; } @@ -404,51 +740,91 @@ static int nct7904_detect(struct i2c_client *client, static const struct hwmon_channel_info *nct7904_info[] = { HWMON_CHANNEL_INFO(in, - HWMON_I_INPUT, /* dummy, skipped in is_visible */ - HWMON_I_INPUT, - HWMON_I_INPUT, - HWMON_I_INPUT, - HWMON_I_INPUT, - HWMON_I_INPUT, - HWMON_I_INPUT, - HWMON_I_INPUT, - HWMON_I_INPUT, - HWMON_I_INPUT, - HWMON_I_INPUT, - HWMON_I_INPUT, - HWMON_I_INPUT, - HWMON_I_INPUT, - HWMON_I_INPUT, - HWMON_I_INPUT, - HWMON_I_INPUT, - HWMON_I_INPUT, - HWMON_I_INPUT, - HWMON_I_INPUT, - HWMON_I_INPUT), + /* dummy, skipped in is_visible */ + HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | + HWMON_I_ALARM, + HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | + HWMON_I_ALARM, + HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | + HWMON_I_ALARM, + HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | + HWMON_I_ALARM, + HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | + HWMON_I_ALARM, + HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | + HWMON_I_ALARM, + HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | + HWMON_I_ALARM, + HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | + HWMON_I_ALARM, + HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | + HWMON_I_ALARM, + HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | + HWMON_I_ALARM, + HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | + HWMON_I_ALARM, + HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | + HWMON_I_ALARM, + HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | + HWMON_I_ALARM, + HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | + HWMON_I_ALARM, + HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | + HWMON_I_ALARM, + HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | + HWMON_I_ALARM, + HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | + HWMON_I_ALARM, + HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | + HWMON_I_ALARM, + HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | + HWMON_I_ALARM, + HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | + HWMON_I_ALARM, + HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | + HWMON_I_ALARM), HWMON_CHANNEL_INFO(fan, - HWMON_F_INPUT, - HWMON_F_INPUT, - HWMON_F_INPUT, - HWMON_F_INPUT, - HWMON_F_INPUT, - HWMON_F_INPUT, - HWMON_F_INPUT, - HWMON_F_INPUT), + HWMON_F_INPUT | HWMON_F_MIN | HWMON_F_ALARM, + HWMON_F_INPUT | HWMON_F_MIN | HWMON_F_ALARM, + HWMON_F_INPUT | HWMON_F_MIN | HWMON_F_ALARM, + HWMON_F_INPUT | HWMON_F_MIN | HWMON_F_ALARM, + HWMON_F_INPUT | HWMON_F_MIN | HWMON_F_ALARM, + HWMON_F_INPUT | HWMON_F_MIN | HWMON_F_ALARM, + HWMON_F_INPUT | HWMON_F_MIN | HWMON_F_ALARM, + HWMON_F_INPUT | HWMON_F_MIN | HWMON_F_ALARM), HWMON_CHANNEL_INFO(pwm, HWMON_PWM_INPUT | HWMON_PWM_ENABLE, HWMON_PWM_INPUT | HWMON_PWM_ENABLE, HWMON_PWM_INPUT | HWMON_PWM_ENABLE, HWMON_PWM_INPUT | HWMON_PWM_ENABLE), HWMON_CHANNEL_INFO(temp, - HWMON_T_INPUT, - HWMON_T_INPUT, - HWMON_T_INPUT, - HWMON_T_INPUT, - HWMON_T_INPUT, - HWMON_T_INPUT, - HWMON_T_INPUT, - HWMON_T_INPUT, - HWMON_T_INPUT), + HWMON_T_INPUT | HWMON_T_ALARM | HWMON_T_MAX | + HWMON_T_MAX_HYST | HWMON_T_TYPE | HWMON_T_EMERGENCY | + HWMON_T_EMERGENCY_HYST, + HWMON_T_INPUT | HWMON_T_ALARM | HWMON_T_MAX | + HWMON_T_MAX_HYST | HWMON_T_TYPE | HWMON_T_EMERGENCY | + HWMON_T_EMERGENCY_HYST, + HWMON_T_INPUT | HWMON_T_ALARM | HWMON_T_MAX | + HWMON_T_MAX_HYST | HWMON_T_TYPE | HWMON_T_EMERGENCY | + HWMON_T_EMERGENCY_HYST, + HWMON_T_INPUT | HWMON_T_ALARM | HWMON_T_MAX | + HWMON_T_MAX_HYST | HWMON_T_TYPE | HWMON_T_EMERGENCY | + HWMON_T_EMERGENCY_HYST, + HWMON_T_INPUT | HWMON_T_ALARM | HWMON_T_MAX | + HWMON_T_MAX_HYST | HWMON_T_TYPE | HWMON_T_EMERGENCY | + HWMON_T_EMERGENCY_HYST, + HWMON_T_INPUT | HWMON_T_ALARM | HWMON_T_MAX | + HWMON_T_MAX_HYST | HWMON_T_TYPE | HWMON_T_EMERGENCY | + HWMON_T_EMERGENCY_HYST, + HWMON_T_INPUT | HWMON_T_ALARM | HWMON_T_MAX | + HWMON_T_MAX_HYST | HWMON_T_TYPE | HWMON_T_EMERGENCY | + HWMON_T_EMERGENCY_HYST, + HWMON_T_INPUT | HWMON_T_ALARM | HWMON_T_MAX | + HWMON_T_MAX_HYST | HWMON_T_TYPE | HWMON_T_EMERGENCY | + HWMON_T_EMERGENCY_HYST, + HWMON_T_INPUT | HWMON_T_ALARM | HWMON_T_MAX | + HWMON_T_MAX_HYST | HWMON_T_TYPE | HWMON_T_EMERGENCY | + HWMON_T_EMERGENCY_HYST), NULL }; @@ -530,11 +906,14 @@ static int nct7904_probe(struct i2c_client *client, if (ret < 0) return ret; + data->temp_mode = 0; for (i = 0; i < 4; i++) { val = (ret & (0x03 << i)) >> (i * 2); bit = (1 << i); if (val == 0) data->tcpu_mask &= ~bit; + else if (val == 0x1 || val == 0x2) + data->temp_mode |= bit; } /* PECI */ @@ -557,7 +936,7 @@ static int nct7904_probe(struct i2c_client *client, if (ret < 0) return ret; data->has_dts = ret & 0xF; - if (data->enable_dts & 0x2) { + if (data->enable_dts & ENABLE_TSI) { ret = nct7904_read_reg(data, BANK_0, DTS_T_CTRL1_REG); if (ret < 0) return ret; From patchwork Mon Jun 17 08:11:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amy.Shih@advantech.com.tw X-Patchwork-Id: 10998295 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C8328112C for ; Mon, 17 Jun 2019 08:12:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BB04928717 for ; Mon, 17 Jun 2019 08:12:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AB8E428807; Mon, 17 Jun 2019 08:12:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4F06128717 for ; Mon, 17 Jun 2019 08:12:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725919AbfFQIMO (ORCPT ); Mon, 17 Jun 2019 04:12:14 -0400 Received: from aclms1.advantech.com.tw ([61.58.41.199]:52438 "EHLO ACLMS1.advantech.com.tw" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725810AbfFQIMO (ORCPT ); Mon, 17 Jun 2019 04:12:14 -0400 Received: from taipei08.ADVANTECH.CORP (unverified [172.20.0.235]) by ACLMS1.advantech.com.tw (Clearswift SMTPRS 5.6.0) with ESMTP id ; Mon, 17 Jun 2019 16:12:12 +0800 From: To: CC: , , , Jean Delvare , Guenter Roeck , , Subject: [v2 4/9] hwmon: (nct7904) Fix incorrect register setting for the high value high limit of voltage. Date: Mon, 17 Jun 2019 08:11:50 +0000 Message-ID: X-Mailer: git-send-email 2.17.1 In-Reply-To: <928e46508bbe1ebc0763c3d2403a5aebe95af552.1560756733.git.amy.shih@advantech.com.tw> References: <928e46508bbe1ebc0763c3d2403a5aebe95af552.1560756733.git.amy.shih@advantech.com.tw> MIME-Version: 1.0 X-Originating-IP: [172.17.10.58] X-ClientProxiedBy: ACLDAG.ADVANTECH.CORP (172.20.2.88) To taipei08.ADVANTECH.CORP (172.20.0.235) X-StopIT: No Sender: linux-hwmon-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: "amy.shih" In function nct7904_write_in, the high value high limit of voltage registers should be VSEN1_HV_HL_REG. Signed-off-by: amy.shih --- Changes in v2: - Fix incorrect register setting of voltage. drivers/hwmon/nct7904.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/hwmon/nct7904.c b/drivers/hwmon/nct7904.c index cdd67932938d..402c1bb2a99f 100644 --- a/drivers/hwmon/nct7904.c +++ b/drivers/hwmon/nct7904.c @@ -615,12 +615,12 @@ static int nct7904_write_in(struct device *dev, u32 attr, int channel, if (ret < 0) return ret; tmp = nct7904_read_reg(data, BANK_1, - VSEN1_HV_LL_REG + index * 4); + VSEN1_HV_HL_REG + index * 4); if (tmp < 0) return tmp; tmp = (val >> 3) & 0xff; ret = nct7904_write_reg(data, BANK_1, - VSEN1_HV_LL_REG + index * 4, tmp); + VSEN1_HV_HL_REG + index * 4, tmp); return ret; default: return -EOPNOTSUPP; From patchwork Mon Jun 17 08:12:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amy.Shih@advantech.com.tw X-Patchwork-Id: 10998299 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2297C924 for ; Mon, 17 Jun 2019 08:13:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 16BB5287FF for ; Mon, 17 Jun 2019 08:13:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0AA9328837; Mon, 17 Jun 2019 08:13:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9FE50287FF for ; Mon, 17 Jun 2019 08:13:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725862AbfFQIN6 (ORCPT ); Mon, 17 Jun 2019 04:13:58 -0400 Received: from aclms3.advantech.com.tw ([125.252.70.86]:39229 "EHLO ACLMS3.advantech.com.tw" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725810AbfFQIN6 (ORCPT ); Mon, 17 Jun 2019 04:13:58 -0400 Received: from taipei08.ADVANTECH.CORP (unverified [172.20.0.235]) by ACLMS3.advantech.com.tw (Clearswift SMTPRS 5.6.0) with ESMTP id ; Mon, 17 Jun 2019 16:13:56 +0800 From: To: CC: , , , Jean Delvare , Guenter Roeck , , Subject: [v2 5/9] hwmon: (nct7904) Fix incorrect register bit mapping of temperature alarm. Date: Mon, 17 Jun 2019 08:12:30 +0000 Message-ID: <87e748a5f2e7d8e6ef69fa5acb177cb0a1474cb2.1560756733.git.amy.shih@advantech.com.tw> X-Mailer: git-send-email 2.17.1 In-Reply-To: <928e46508bbe1ebc0763c3d2403a5aebe95af552.1560756733.git.amy.shih@advantech.com.tw> References: <928e46508bbe1ebc0763c3d2403a5aebe95af552.1560756733.git.amy.shih@advantech.com.tw> MIME-Version: 1.0 X-Originating-IP: [172.17.10.58] X-ClientProxiedBy: ACLDAG.ADVANTECH.CORP (172.20.2.88) To taipei08.ADVANTECH.CORP (172.20.0.235) X-StopIT: No Sender: linux-hwmon-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: "amy.shih" In function nct7904_read_temp, the bit to shift for register SMI_STS1_REG should be bit 1 & 3 & 5 &7 for TEMP_CH1~4. Signed-off-by: amy.shih --- Changes in v2: - Fix incorrect register bit mapping of temperature alarm. drivers/hwmon/nct7904.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/hwmon/nct7904.c b/drivers/hwmon/nct7904.c index 402c1bb2a99f..95348eebe8e4 100644 --- a/drivers/hwmon/nct7904.c +++ b/drivers/hwmon/nct7904.c @@ -356,7 +356,7 @@ static int nct7904_read_temp(struct device *dev, u32 attr, int channel, SMI_STS1_REG); if (ret < 0) return ret; - *val = (ret >> (channel & 0x07)) & 1; + *val = (ret >> (((channel * 2) + 1) & 0x07)) & 1; } else { if ((channel - 5) < 4) { ret = nct7904_read_reg(data, BANK_0, From patchwork Mon Jun 17 08:14:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amy.Shih@advantech.com.tw X-Patchwork-Id: 10998303 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AD3FC112C for ; Mon, 17 Jun 2019 08:14:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A095A28717 for ; Mon, 17 Jun 2019 08:14:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 94F8328807; Mon, 17 Jun 2019 08:14:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4E00C28717 for ; Mon, 17 Jun 2019 08:14:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726469AbfFQIO6 (ORCPT ); Mon, 17 Jun 2019 04:14:58 -0400 Received: from aclms3.advantech.com.tw ([125.252.70.86]:39405 "EHLO ACLMS3.advantech.com.tw" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726248AbfFQIO6 (ORCPT ); Mon, 17 Jun 2019 04:14:58 -0400 Received: from taipei08.ADVANTECH.CORP (unverified [172.20.0.235]) by ACLMS3.advantech.com.tw (Clearswift SMTPRS 5.6.0) with ESMTP id ; Mon, 17 Jun 2019 16:14:56 +0800 From: To: CC: , , , Jean Delvare , Guenter Roeck , , Subject: [v2 6/9] hwmon: (nct7904) Fix wrong return code in function nct7904_write_fan. Date: Mon, 17 Jun 2019 08:14:35 +0000 Message-ID: <70e520dfcf80c58045d2238a0af972d9cdbb6ac4.1560756733.git.amy.shih@advantech.com.tw> X-Mailer: git-send-email 2.17.1 In-Reply-To: <928e46508bbe1ebc0763c3d2403a5aebe95af552.1560756733.git.amy.shih@advantech.com.tw> References: <928e46508bbe1ebc0763c3d2403a5aebe95af552.1560756733.git.amy.shih@advantech.com.tw> MIME-Version: 1.0 X-Originating-IP: [172.17.10.58] X-ClientProxiedBy: ACLDAG.ADVANTECH.CORP (172.20.2.88) To taipei08.ADVANTECH.CORP (172.20.0.235) X-StopIT: No Sender: linux-hwmon-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: "amy.shih" In function nct7904_write_fan, the return code is either 0 or an error code. 0x1fff is not a valid return code. Thus, set return code to 0 when setting value is smaller or equal to 0. Signed-off-by: amy.shih --- Changes in v2: - Fix wrong return code 0x1fff in function nct7904_write_fan. drivers/hwmon/nct7904.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/hwmon/nct7904.c b/drivers/hwmon/nct7904.c index 95348eebe8e4..3fa3eb31d176 100644 --- a/drivers/hwmon/nct7904.c +++ b/drivers/hwmon/nct7904.c @@ -551,7 +551,7 @@ static int nct7904_write_fan(struct device *dev, u32 attr, int channel, switch (attr) { case hwmon_fan_min: if (val <= 0) - return 0x1fff; + return 0; val = clamp_val((1350000 + (val >> 1)) / val, 1, 0x1fff); tmp = (val >> 5) & 0xff; From patchwork Mon Jun 17 08:15:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amy.Shih@advantech.com.tw X-Patchwork-Id: 10998307 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9B1A1924 for ; Mon, 17 Jun 2019 08:15:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8E9732858E for ; Mon, 17 Jun 2019 08:15:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 82E56286A4; Mon, 17 Jun 2019 08:15:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3B6F92858E for ; Mon, 17 Jun 2019 08:15:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725919AbfFQIPo (ORCPT ); Mon, 17 Jun 2019 04:15:44 -0400 Received: from aclms1.advantech.com.tw ([61.58.41.199]:52652 "EHLO ACLMS1.advantech.com.tw" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725837AbfFQIPo (ORCPT ); Mon, 17 Jun 2019 04:15:44 -0400 Received: from taipei08.ADVANTECH.CORP (unverified [172.20.0.235]) by ACLMS1.advantech.com.tw (Clearswift SMTPRS 5.6.0) with ESMTP id ; Mon, 17 Jun 2019 16:15:42 +0800 From: To: CC: , , , Jean Delvare , Guenter Roeck , , Subject: [v2 7/9] hwmon: (nct7904) Delete wrong comment in function nct7904_write_in. Date: Mon, 17 Jun 2019 08:15:26 +0000 Message-ID: <5be014e8e289c615bd9c74321e39484e8f448d8a.1560756733.git.amy.shih@advantech.com.tw> X-Mailer: git-send-email 2.17.1 In-Reply-To: <928e46508bbe1ebc0763c3d2403a5aebe95af552.1560756733.git.amy.shih@advantech.com.tw> References: <928e46508bbe1ebc0763c3d2403a5aebe95af552.1560756733.git.amy.shih@advantech.com.tw> MIME-Version: 1.0 X-Originating-IP: [172.17.10.58] X-ClientProxiedBy: ACLDAG.ADVANTECH.CORP (172.20.2.88) To taipei08.ADVANTECH.CORP (172.20.0.235) X-StopIT: No Sender: linux-hwmon-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: "amy.shih" In function nct7904_write_in, delete wrong comment "Bit 15 is sign bit". Signed-off-by: amy.shih --- Changes in v2: - Delete wrong comment in function nct7904_write_in. drivers/hwmon/nct7904.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/hwmon/nct7904.c b/drivers/hwmon/nct7904.c index 3fa3eb31d176..c74f919c0181 100644 --- a/drivers/hwmon/nct7904.c +++ b/drivers/hwmon/nct7904.c @@ -581,7 +581,7 @@ static int nct7904_write_in(struct device *dev, u32 attr, int channel, else val = val / 6; /* 0.006V scale */ - val = clamp_val(val, 0, 0x7ff); /* Bit 15 is sign bit */ + val = clamp_val(val, 0, 0x7ff); switch (attr) { case hwmon_in_min: From patchwork Mon Jun 17 08:16:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amy.Shih@advantech.com.tw X-Patchwork-Id: 10998333 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6F1B714BB for ; Mon, 17 Jun 2019 08:22:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 62C41288A9 for ; Mon, 17 Jun 2019 08:22:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 60994288AE; Mon, 17 Jun 2019 08:22:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI,UPPERCASE_50_75 autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E4CAA288A2 for ; Mon, 17 Jun 2019 08:22:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726121AbfFQIWR (ORCPT ); Mon, 17 Jun 2019 04:22:17 -0400 Received: from aclms3.advantech.com.tw ([125.252.70.86]:40383 "EHLO ACLMS3.advantech.com.tw" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725791AbfFQIWR (ORCPT ); Mon, 17 Jun 2019 04:22:17 -0400 Received: from taipei08.ADVANTECH.CORP (unverified [172.20.0.235]) by ACLMS3.advantech.com.tw (Clearswift SMTPRS 5.6.0) with ESMTP id ; Mon, 17 Jun 2019 16:16:23 +0800 From: To: CC: , , , Jean Delvare , Guenter Roeck , , Subject: [v2 8/9] hwmon: (nct7904) Fix wrong attribute names for temperature. Date: Mon, 17 Jun 2019 08:16:09 +0000 Message-ID: X-Mailer: git-send-email 2.17.1 In-Reply-To: <928e46508bbe1ebc0763c3d2403a5aebe95af552.1560756733.git.amy.shih@advantech.com.tw> References: <928e46508bbe1ebc0763c3d2403a5aebe95af552.1560756733.git.amy.shih@advantech.com.tw> MIME-Version: 1.0 X-Originating-IP: [172.17.10.58] X-ClientProxiedBy: ACLDAG.ADVANTECH.CORP (172.20.2.88) To taipei08.ADVANTECH.CORP (172.20.0.235) X-StopIT: No Sender: linux-hwmon-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: "amy.shih" Emergency attributes without crit attributes are not acceptable. In datasheet there are registers labeled "critical", and there is no mention of "emergency". Thus, set the attribute names from "temp[1-*]_emergency" and "temp[1-*]_emergency_hyst" to "temp[1-*]_crit" and "temp[1-*]_crit_hyst". Signed-off-by: amy.shih --- Changes in v2: - Fix wrong attribute names for temperature. drivers/hwmon/nct7904.c | 48 ++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/drivers/hwmon/nct7904.c b/drivers/hwmon/nct7904.c index c74f919c0181..fc145c73a4e7 100644 --- a/drivers/hwmon/nct7904.c +++ b/drivers/hwmon/nct7904.c @@ -407,12 +407,12 @@ static int nct7904_read_temp(struct device *dev, u32 attr, int channel, reg2 = TEMP_CH1_CH_REG; reg3 = DTS_T_CPU1_CH_REG; break; - case hwmon_temp_emergency: + case hwmon_temp_crit: reg1 = LTD_HV_LL_REG; reg2 = TEMP_CH1_W_REG; reg3 = DTS_T_CPU1_W_REG; break; - case hwmon_temp_emergency_hyst: + case hwmon_temp_crit_hyst: reg1 = LTD_LV_LL_REG; reg2 = TEMP_CH1_WH_REG; reg3 = DTS_T_CPU1_WH_REG; @@ -454,8 +454,8 @@ static umode_t nct7904_temp_is_visible(const void *_data, u32 attr, int channel) break; case hwmon_temp_max: case hwmon_temp_max_hyst: - case hwmon_temp_emergency: - case hwmon_temp_emergency_hyst: + case hwmon_temp_crit: + case hwmon_temp_crit_hyst: if (channel < 5) { if (data->tcpu_mask & BIT(channel)) return 0644; @@ -516,12 +516,12 @@ static int nct7904_write_temp(struct device *dev, u32 attr, int channel, reg2 = TEMP_CH1_CH_REG; reg3 = DTS_T_CPU1_CH_REG; break; - case hwmon_temp_emergency: + case hwmon_temp_crit: reg1 = LTD_HV_LL_REG; reg2 = TEMP_CH1_W_REG; reg3 = DTS_T_CPU1_W_REG; break; - case hwmon_temp_emergency_hyst: + case hwmon_temp_crit_hyst: reg1 = LTD_LV_LL_REG; reg2 = TEMP_CH1_WH_REG; reg3 = DTS_T_CPU1_WH_REG; @@ -799,32 +799,32 @@ static const struct hwmon_channel_info *nct7904_info[] = { HWMON_PWM_INPUT | HWMON_PWM_ENABLE), HWMON_CHANNEL_INFO(temp, HWMON_T_INPUT | HWMON_T_ALARM | HWMON_T_MAX | - HWMON_T_MAX_HYST | HWMON_T_TYPE | HWMON_T_EMERGENCY | - HWMON_T_EMERGENCY_HYST, + HWMON_T_MAX_HYST | HWMON_T_TYPE | HWMON_T_CRIT | + HWMON_T_CRIT_HYST, HWMON_T_INPUT | HWMON_T_ALARM | HWMON_T_MAX | - HWMON_T_MAX_HYST | HWMON_T_TYPE | HWMON_T_EMERGENCY | - HWMON_T_EMERGENCY_HYST, + HWMON_T_MAX_HYST | HWMON_T_TYPE | HWMON_T_CRIT | + HWMON_T_CRIT_HYST, HWMON_T_INPUT | HWMON_T_ALARM | HWMON_T_MAX | - HWMON_T_MAX_HYST | HWMON_T_TYPE | HWMON_T_EMERGENCY | - HWMON_T_EMERGENCY_HYST, + HWMON_T_MAX_HYST | HWMON_T_TYPE | HWMON_T_CRIT | + HWMON_T_CRIT_HYST, HWMON_T_INPUT | HWMON_T_ALARM | HWMON_T_MAX | - HWMON_T_MAX_HYST | HWMON_T_TYPE | HWMON_T_EMERGENCY | - HWMON_T_EMERGENCY_HYST, + HWMON_T_MAX_HYST | HWMON_T_TYPE | HWMON_T_CRIT | + HWMON_T_CRIT_HYST, HWMON_T_INPUT | HWMON_T_ALARM | HWMON_T_MAX | - HWMON_T_MAX_HYST | HWMON_T_TYPE | HWMON_T_EMERGENCY | - HWMON_T_EMERGENCY_HYST, + HWMON_T_MAX_HYST | HWMON_T_TYPE | HWMON_T_CRIT | + HWMON_T_CRIT_HYST, HWMON_T_INPUT | HWMON_T_ALARM | HWMON_T_MAX | - HWMON_T_MAX_HYST | HWMON_T_TYPE | HWMON_T_EMERGENCY | - HWMON_T_EMERGENCY_HYST, + HWMON_T_MAX_HYST | HWMON_T_TYPE | HWMON_T_CRIT | + HWMON_T_CRIT_HYST, HWMON_T_INPUT | HWMON_T_ALARM | HWMON_T_MAX | - HWMON_T_MAX_HYST | HWMON_T_TYPE | HWMON_T_EMERGENCY | - HWMON_T_EMERGENCY_HYST, + HWMON_T_MAX_HYST | HWMON_T_TYPE | HWMON_T_CRIT | + HWMON_T_CRIT_HYST, HWMON_T_INPUT | HWMON_T_ALARM | HWMON_T_MAX | - HWMON_T_MAX_HYST | HWMON_T_TYPE | HWMON_T_EMERGENCY | - HWMON_T_EMERGENCY_HYST, + HWMON_T_MAX_HYST | HWMON_T_TYPE | HWMON_T_CRIT | + HWMON_T_CRIT_HYST, HWMON_T_INPUT | HWMON_T_ALARM | HWMON_T_MAX | - HWMON_T_MAX_HYST | HWMON_T_TYPE | HWMON_T_EMERGENCY | - HWMON_T_EMERGENCY_HYST), + HWMON_T_MAX_HYST | HWMON_T_TYPE | HWMON_T_CRIT | + HWMON_T_CRIT_HYST), NULL }; From patchwork Mon Jun 17 08:22:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amy.Shih@advantech.com.tw X-Patchwork-Id: 10998339 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 24B191395 for ; Mon, 17 Jun 2019 08:23:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 16F7C28862 for ; Mon, 17 Jun 2019 08:23:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 154E328885; Mon, 17 Jun 2019 08:23:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AACAB28862 for ; Mon, 17 Jun 2019 08:23:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725983AbfFQIXW (ORCPT ); Mon, 17 Jun 2019 04:23:22 -0400 Received: from aclms1.advantech.com.tw ([61.58.41.199]:53019 "EHLO ACLMS1.advantech.com.tw" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725862AbfFQIXW (ORCPT ); Mon, 17 Jun 2019 04:23:22 -0400 Received: from taipei08.ADVANTECH.CORP (unverified [172.20.0.235]) by ACLMS1.advantech.com.tw (Clearswift SMTPRS 5.6.0) with ESMTP id ; Mon, 17 Jun 2019 16:23:20 +0800 From: To: CC: , , , Jean Delvare , Guenter Roeck , , Subject: [v2 9/9] hwmon: (nct7904) Fix wrong registers setting for temperature. Date: Mon, 17 Jun 2019 08:22:55 +0000 Message-ID: <9b03a23bbb5385658c21bf5129a5b1c9b5065237.1560756733.git.amy.shih@advantech.com.tw> X-Mailer: git-send-email 2.17.1 In-Reply-To: <928e46508bbe1ebc0763c3d2403a5aebe95af552.1560756733.git.amy.shih@advantech.com.tw> References: <928e46508bbe1ebc0763c3d2403a5aebe95af552.1560756733.git.amy.shih@advantech.com.tw> MIME-Version: 1.0 X-Originating-IP: [172.17.10.58] X-ClientProxiedBy: ACLDAG.ADVANTECH.CORP (172.20.2.88) To taipei08.ADVANTECH.CORP (172.20.0.235) X-StopIT: No Sender: linux-hwmon-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: "amy.shih" For "attributes temp[1-*]_max" and "temp[1-*]_max_hyst", should show the reading of "WARNING TEMPERATURE" and "WARNING TEMPERATURE HYSTERESIS" registers. For attribute "temp[1-*]_crit" and "temp[1-*]_crit_hyst", shuld show the reading of "CRITICAL TEMPERATURE" and "CRITICAL TEMPERATURE HYSTERESIS" registers in datasheet. Signed-off-by: amy.shih --- Changes in v2: - Fix wrong registers setting for temperature. drivers/hwmon/nct7904.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/drivers/hwmon/nct7904.c b/drivers/hwmon/nct7904.c index fc145c73a4e7..d842c10ba11f 100644 --- a/drivers/hwmon/nct7904.c +++ b/drivers/hwmon/nct7904.c @@ -399,23 +399,23 @@ static int nct7904_read_temp(struct device *dev, u32 attr, int channel, return 0; case hwmon_temp_max: reg1 = LTD_HV_HL_REG; - reg2 = TEMP_CH1_C_REG; - reg3 = DTS_T_CPU1_C_REG; + reg2 = TEMP_CH1_W_REG; + reg3 = DTS_T_CPU1_W_REG; break; case hwmon_temp_max_hyst: reg1 = LTD_LV_HL_REG; - reg2 = TEMP_CH1_CH_REG; - reg3 = DTS_T_CPU1_CH_REG; + reg2 = TEMP_CH1_WH_REG; + reg3 = DTS_T_CPU1_WH_REG; break; case hwmon_temp_crit: reg1 = LTD_HV_LL_REG; - reg2 = TEMP_CH1_W_REG; - reg3 = DTS_T_CPU1_W_REG; + reg2 = TEMP_CH1_C_REG; + reg3 = DTS_T_CPU1_C_REG; break; case hwmon_temp_crit_hyst: reg1 = LTD_LV_LL_REG; - reg2 = TEMP_CH1_WH_REG; - reg3 = DTS_T_CPU1_WH_REG; + reg2 = TEMP_CH1_CH_REG; + reg3 = DTS_T_CPU1_CH_REG; break; default: return -EOPNOTSUPP; @@ -508,23 +508,23 @@ static int nct7904_write_temp(struct device *dev, u32 attr, int channel, switch (attr) { case hwmon_temp_max: reg1 = LTD_HV_HL_REG; - reg2 = TEMP_CH1_C_REG; - reg3 = DTS_T_CPU1_C_REG; + reg2 = TEMP_CH1_W_REG; + reg3 = DTS_T_CPU1_W_REG; break; case hwmon_temp_max_hyst: reg1 = LTD_LV_HL_REG; - reg2 = TEMP_CH1_CH_REG; - reg3 = DTS_T_CPU1_CH_REG; + reg2 = TEMP_CH1_WH_REG; + reg3 = DTS_T_CPU1_WH_REG; break; case hwmon_temp_crit: reg1 = LTD_HV_LL_REG; - reg2 = TEMP_CH1_W_REG; - reg3 = DTS_T_CPU1_W_REG; + reg2 = TEMP_CH1_C_REG; + reg3 = DTS_T_CPU1_C_REG; break; case hwmon_temp_crit_hyst: reg1 = LTD_LV_LL_REG; - reg2 = TEMP_CH1_WH_REG; - reg3 = DTS_T_CPU1_WH_REG; + reg2 = TEMP_CH1_CH_REG; + reg3 = DTS_T_CPU1_CH_REG; break; default: return -EOPNOTSUPP;