From patchwork Sun Jun 25 11:18:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Crawford X-Patchwork-Id: 13291886 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 837BDEB64DD for ; Sun, 25 Jun 2023 11:19:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231683AbjFYLT5 (ORCPT ); Sun, 25 Jun 2023 07:19:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36342 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231782AbjFYLT4 (ORCPT ); Sun, 25 Jun 2023 07:19:56 -0400 Received: from ipmail03.adl6.internode.on.net (ipmail03.adl6.internode.on.net [150.101.137.143]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 478CE189 for ; Sun, 25 Jun 2023 04:19:50 -0700 (PDT) IronPort-SDR: 649822d2_QFDbQY2vKEhzBFv3fIitL60L7d14CNsSSZv/Js4A/Nhk1Up Xf2b5DDdFertrqOTcrb05DhPxFJd9+75rTqGhVg== X-SMTP-MATCH: 0 X-IPAS-Result: A2CkAwAAIphkjPQc8jxagRKGSrYVDwEPAQFEBAEBhQaGCCY4EwECBAEBAQEDAgMBAQEBAQEDAQEGAQEBAQEBBgQUAQEBAUBFhWgNhgcrCwENAQE3ASiBFQESgn6CXa9tM4EBgggBAQaCZa4wgV8JgUKMHYEZgzuBPD+BToEVgTyBPm+LBo4thWIFAjKBS4oggShvgR45Z3oCCQIRZ4EICGCBcUACDVQLC2OBHIJSAgIROg8FU18ZGwMHA4EFEC8HBDIoBgkYLyUGUQcXFiQJExVBBINYCoEMPxUOEYJYIgIHNj8bUYJsCRdHAwkDBwVJQ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JfhyTjstlQ0QtlBkdcPF a2JTmisSlevvHpzn3PBiOJmOWDiONkNW1Da7dCPqe4ME8oOjfFofUQMyYCLhnSyMjU22zKPv QjGWb3a8Pw696RogLnXM/tiAyeaFIrNcdqmoSGJjsR2TNLQMM3xmRsfhXv5Mi93Y7YAedRFu o6ckdzw3XLAuO49Qj3bkJyvTJtMtNSAd7dTOPLKMXBlpDazaPLtxzAh+GmID4NDv/0Ax8ugR iq+MNCRc/xMUfhj5XRlUQpsODdDNLbScYHbujKbrd6ALjM/wD73Boqr2lGxZF4KaxJSHYP1D zHFnsqH5/dandxqPwAFDfQ3OK1ICgbvdoV+fuKgqATCKHejh26Dnb7QlRAAzzXvIVvcGebY5 aP1fDTPRC6Qiorpku4A65dTuycJBklTmeMzJ0IR2+BnggCAUVIpE74vDoUkOLp1zArCjZ32X WSYJi9qQyDwRi9NfhjA8czuFFXXTPAHPtDiYCcl5QWIYiOxH5mNG6Zl6jwm2XptZz//16uyH LnyIJEr0sSZmfmFndou28E= IronPort-HdrOrdr: A9a23:eDEiAaiQ3oqGHt/UL6yotLUJinBQXuQji2hC6mlwRA09TyVXra GTdZMgpHjJYFR4YhsdcLW7VZVoLkmslqKdjbN/AV7AZniDhILLFvAB0WKK+VSJcEHDH4VmtZ uIHZIRNDV+YGIK6/oSmDPIdurIH+P3iZxBVI/lvg9QcT0= X-Talos-CUID: 9a23:AKwcRW3ge+eaNpB0EVofBrxfEP4kMWL/zVfqeka2JVR0GJ6OE3Sc0fYx X-Talos-MUID: 9a23:qJ0UAwqTYVTJtVjXv0Mezw19ZcZZ2f2HNGc2kZopksuVNnJIFQ7I2Q== X-IronPort-Anti-Spam-Filtered: true Received: from 60-242-28-244.static.tpgi.com.au (HELO bits.crawford.emu.id.au) ([60.242.28.244]) by ipmail03.adl6.internode.on.net with ESMTP; 25 Jun 2023 20:49:46 +0930 Received: from bits.crawford.emu.id.au ([127.0.0.1]) by bits.crawford.emu.id.au (8.17.1/8.17.1) with ESMTPS id 35PBJf5o3779768 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Sun, 25 Jun 2023 21:19:41 +1000 DKIM-Filter: OpenDKIM Filter v2.11.0 bits.crawford.emu.id.au 35PBJf5o3779768 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=crawford.emu.id.au; s=s1; t=1687691981; bh=DzW8PTI4FcUJt+rd137n2CQvBROGcxKN9ZyHwecseHY=; h=From:To:Cc:Subject:Date:From; b=FDUeJqMPsyGsOUP8ji5HFUTzAdPoJNqwP/o7GIanyctC+JtNLSNe9oO/3a9KjUFE5 zp+iJclR4l3u+fkW+EVp3aLwT15nK+92bOnteg7DiRoCR0P4nQpUXMdGQuy9dooskl W8IkWNJSlouVwaNXxsF3aKqvUPMe2vuab9JKrxH1XMOohSf0LoSXXEBgzYRAUOxHpM WnV+cz7ZJ44SwOiYOeJwlmO04xRoOT91ymcNB6PRD4gESceOox0djn5PL9WZi3V9R2 JumnZ8jtb03RP57/0EP8YSGinF/Vl7GQ3IVYFpvW73+KCVLQWxEgJFPMKumzHmCRZf 0ePY4YgTWts/w== Received: (from frank@localhost) by bits.crawford.emu.id.au (8.17.1/8.17.1/Submit) id 35PBJbTX3779767; Sun, 25 Jun 2023 21:19:37 +1000 From: Frank Crawford To: Jean Delvare , Guenter Roeck Cc: linux-hwmon@vger.kernel.org, Frank Crawford Subject: [PATCH v1] hwmon: (it87) Separate temperature type to separate funtion and detect AMDTSI Date: Sun, 25 Jun 2023 21:18:38 +1000 Message-ID: <20230625111838.3779678-1-frank@crawford.emu.id.au> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (bits.crawford.emu.id.au [0.0.0.0]); Sun, 25 Jun 2023 21:19:41 +1000 (AEST) X-Virus-Scanned: clamav-milter 1.0.1 at bits.crawford.emu.id.au X-Virus-Status: Clean Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org The temperature sensor type needs to be used in multiple places, so split it out into its own function. It is used both in show_temp_type attribute and testing if the attribute should be visible (i.e. is defined). The sensor type also reports the type AMDTSI on certain chipsets. Signed-off-by: Frank Crawford --- drivers/hwmon/it87.c | 78 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 65 insertions(+), 13 deletions(-) diff --git a/drivers/hwmon/it87.c b/drivers/hwmon/it87.c index 5deff5e5f693..ba75f33301ce 100644 --- a/drivers/hwmon/it87.c +++ b/drivers/hwmon/it87.c @@ -221,6 +221,10 @@ static bool fix_pwm_polarity; * Super-I/O configuration space. */ #define IT87_REG_VID 0x0a + +/* Interface Selection register on other chips */ +#define IT87_REG_IFSEL 0x0a + /* * The IT8705F and IT8712F earlier than revision 0x08 use register 0x0b * for fan divisors. Later IT8712F revisions must use 16-bit tachometer @@ -1159,28 +1163,68 @@ static SENSOR_DEVICE_ATTR_2(temp4_input, S_IRUGO, show_temp, NULL, 3, 0); static SENSOR_DEVICE_ATTR_2(temp5_input, S_IRUGO, show_temp, NULL, 4, 0); static SENSOR_DEVICE_ATTR_2(temp6_input, S_IRUGO, show_temp, NULL, 5, 0); +static int get_temp_type(struct it87_data *data, int index) +{ + /* + * 2 is deprecated; + * 3 = thermal diode; + * 4 = thermistor; + * 5 = AMDTSI; + * 6 = Intel PECI; + * 0 = disabled + */ + u8 reg, extra; + int ttype, type = 0; + + /* Detect PECI vs. AMDTSI */ + ttype = 6; + if ((has_temp_peci(data, index)) || data->type == it8721 || + data->type == it8720) { + extra = it87_read_value(data, IT87_REG_IFSEL); + if ((extra & 0x70) == 0x40) + ttype = 5; + } + + reg = it87_read_value(data, IT87_REG_TEMP_ENABLE); + + /* Per chip special detection */ + switch (data->type) { + case it8622: + if (!(reg & 0xc0) && index == 3) + type = ttype; + break; + default: + break; + } + + if (type || index >= 3) + return type; + + extra = it87_read_value(data, IT87_REG_TEMP_EXTRA); + + if ((has_temp_peci(data, index) && (reg >> 6 == index + 1)) || + (has_temp_old_peci(data, index) && (extra & 0x80))) + type = ttype; /* Intel PECI or AMDTSI */ + else if (reg & BIT(index)) + type = 3; /* thermal diode */ + else if (reg & BIT(index + 3)) + type = 4; /* thermistor */ + + return type; +} + static ssize_t show_temp_type(struct device *dev, struct device_attribute *attr, char *buf) { struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); - int nr = sensor_attr->index; struct it87_data *data = it87_update_device(dev); - u8 reg, extra; + int type; if (IS_ERR(data)) return PTR_ERR(data); - reg = data->sensor; /* In case value is updated while used */ - extra = data->extra; - - if ((has_temp_peci(data, nr) && (reg >> 6 == nr + 1)) || - (has_temp_old_peci(data, nr) && (extra & 0x80))) - return sprintf(buf, "6\n"); /* Intel PECI */ - if (reg & (1 << nr)) - return sprintf(buf, "3\n"); /* thermal diode */ - if (reg & (8 << nr)) - return sprintf(buf, "4\n"); /* thermistor */ - return sprintf(buf, "0\n"); /* disabled */ + type = get_temp_type(data, sensor_attr->index); + return sprintf(buf, "%d\n", type); } static ssize_t set_temp_type(struct device *dev, struct device_attribute *attr, @@ -2313,6 +2357,14 @@ static umode_t it87_temp_is_visible(struct kobject *kobj, if (!(data->has_temp & BIT(i))) return 0; + if (a == 3) { + int type = get_temp_type(data, i); + + if (type == 0) + return 0; + return attr->mode; + } + if (a == 5 && !has_temp_offset(data)) return 0;