From patchwork Fri Jul 7 12:29:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Crawford X-Patchwork-Id: 13304865 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 6CD81C0015E for ; Fri, 7 Jul 2023 12:30:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231666AbjGGMav (ORCPT ); Fri, 7 Jul 2023 08:30:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59562 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232151AbjGGMat (ORCPT ); Fri, 7 Jul 2023 08:30:49 -0400 Received: from ipmail06.adl3.internode.on.net (ipmail06.adl3.internode.on.net [150.101.137.16]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 5FDEC1FE6 for ; Fri, 7 Jul 2023 05:30:46 -0700 (PDT) IronPort-SDR: 64a80565_92LQFesX7kbcdCy7AWv5J69SbIpLlyR9Qbpb4NThCiK5fO7 EBpUhTU7ygLLTCzm7bYR/xHeFCEiASrYQnBvEfA== X-SMTP-MATCH: 0 X-IPAS-Result: A2C5AAASBahkjPQc8jxaHQEBAQEJARIBBQUBSYE1BQELAYIyglG2Hw8BDwEBRAQBAYUGAoYVJjcGDgECBAEBAQEDAgMBAQEBAQEDAQEGAQEBAQEBBgQUAQEBAUBFhWgNhgUCAQMnCwENAQE3AQ8ZOFcGARKCfoJdqWMzgQGCCQEBBoJlrjGBXwmBQgGMH4EZgzt6Qj+BToEVgTyBPm+LBo4ghV0HMo0UgSdvgR43Z3oCCQIRZ4EICF+Bbj4CDVQLC2OBHIEqgSQCAhE6FFNfGR0DBwOBBRAvBwQyJgYJGC8lBlEHFxYk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vQFQac1K2YXwLUE/iM0lgvShcgUlbg== 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 ipmail06.adl3.internode.on.net with ESMTP; 07 Jul 2023 22:00:29 +0930 Received: from agc.crawford.emu.id.au (agc.crawford.emu.id.au [IPv6:fdd2:7aad:d478:1:0:0:cb10:cc07]) (authenticated bits=0) by bits.crawford.emu.id.au (8.17.1/8.17.1) with ESMTPSA id 367CU7bK2026771 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Fri, 7 Jul 2023 22:30:21 +1000 Authentication-Results: bits.crawford.emu.id.au; arc=none smtp.remote-ip=fdd2:7aad:d478:1::cb10:cc07 DKIM-Filter: OpenDKIM Filter v2.11.0 bits.crawford.emu.id.au 367CU7bK2026771 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=crawford.emu.id.au; s=s1; t=1688733022; bh=vO9iS60rDSU0yqJU6pRxERHjUfpLe5PC2SHm5W8r7tU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UA7aE1mskWUWHjZNGEl1KBmy+LMF5ihPyc6krNX9sIaFvqb1ODrA7i3CUAo56E3vG YhIv6fDrBBjquvWauc1tFT48kIlMS12HUsfQ5u84avY4LdKvQ8X/iLCLlScn5IunH8 G82OO5Ct1Cy5NOYFmNr1SpWEjbOihH8ll69HJXE2LM8UzlujQi9VpTrB/Pp1PPf5VM qU2PVZJfwVSBPIwEdLmeRitt3aCi72iHMQYH2l0zfS4kLV0XU2cxnB8PPSVIquadXe nf+j5E6F9wfwQBMI1fDLo/b0l0nuB9e6DuAXX14v4Jq5PhYFYJUBPpYwTTdTxFOpFI gnLlWobv//5Ng== From: Frank Crawford To: Jean Delvare , Guenter Roeck Cc: linux-hwmon@vger.kernel.org, Frank Crawford Subject: [PATCH v2 1/3] hwmon: (it87) Split temperature sensor detection to separate function Date: Fri, 7 Jul 2023 22:29:50 +1000 Message-ID: <20230707123005.956415-2-frank@crawford.emu.id.au> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230707123005.956415-1-frank@crawford.emu.id.au> References: <20230707123005.956415-1-frank@crawford.emu.id.au> MIME-Version: 1.0 X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.6.4 (bits.crawford.emu.id.au [IPv6:fdd2:7aad:d478:1:0:0:cb10:cc01]); Fri, 07 Jul 2023 22:30:22 +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 will need to be used in multiple places, so split it out into its own function. Signed-off-by: Frank Crawford --- v2: * Split single patch into multi-patch set following review. --- drivers/hwmon/it87.c | 43 ++++++++++++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/drivers/hwmon/it87.c b/drivers/hwmon/it87.c index 5deff5e5f693..7a1224ddc8b1 100644 --- a/drivers/hwmon/it87.c +++ b/drivers/hwmon/it87.c @@ -1159,28 +1159,45 @@ 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 type = 0; + + reg = data->sensor; /* In case value is updated while used */ + extra = data->extra; + + if ((has_temp_peci(data, index) && (reg >> 6 == index + 1)) || + (has_temp_old_peci(data, index) && (extra & 0x80))) + type = 6; /* Intel PECI */ + 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,