From patchwork Sat Dec 24 04:18:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Armin Wolf X-Patchwork-Id: 36386 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp7878wrt; Fri, 23 Dec 2022 20:21:34 -0800 (PST) X-Google-Smtp-Source: AMrXdXttWXZF/y8y98CE4GjIDAsYFfpAco2Djkz4VCo247GwN6cR4YRafXS+qUOPsSTVPPbB2q0N X-Received: by 2002:a17:906:b150:b0:7c1:9b07:32cd with SMTP id bt16-20020a170906b15000b007c19b0732cdmr8887842ejb.39.1671855694190; Fri, 23 Dec 2022 20:21:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671855694; cv=none; d=google.com; s=arc-20160816; b=HEU2T1FRsU++LHT93E23ww1zZHHF8b4+tlMEXeRELP64hc2HtCxwbjrJg9soN09uVb PIG/IBiDSLTaA+lZyqCEjS+NqHAgV09jnakS+VA4zMA9aUhSXkKFQP1O0TMrv02Vnhmd D8gmht7rHWkM8vIAIbOVFg9YRC7Mxhxbd24NX1/Klq+f/j2mp6j+TTaaKjHiUaFo51tG 2ODxfPFPRJKxCSlsIrnxItCXfq1t0dwIs0TvcDeNRGrxY+TUo0Z0FCvuAGULPkjkvUQA R5AcRGXJRk3q5OEtejx/F3QakwB03W1EubD1RQEMo0bmjlk8fGaaAED/eTKAPEsEuBvy fs/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:ui-outboundreport:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=VV+yAMDqdLNlkrUHw14mI13wMfuZSIiUj7i+YSAmPQY=; b=O3xJjVTHnsr8moBnZSy/bHgXZHzDeGqJ0DSz7jyPqmnGsCedIzlACmNFyncFhPyU4c akJEVeP+YAcb2kRkXb5RL26RejRE8MBX1lXM7WUlLuUIPA369QnImSkog1p5UJSaBHKT V7medeKnY4io+QT/nwc029EWkT9miUcew5+W9+W+DasFgEkQ6JybNjWZkVj+ch5CuBPG /LwlywUkNUxWdZPf15+24Srdk7vKY8I9TemqPeu01AFFwdSuJwx1OzLHhnl1ZLUSIoUs Qv/hAqr9ICCK9eufmbPoTnhGVNjBF3dutU+3VceW7tjZy/wAYACPep4hEBg+V4m5YzeC 2P4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b=WnFVltG1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmx.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hb39-20020a170907162700b007c841b8fa31si4344659ejc.629.2022.12.23.20.21.11; Fri, 23 Dec 2022 20:21:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b=WnFVltG1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmx.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232728AbiLXETc (ORCPT + 99 others); Fri, 23 Dec 2022 23:19:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50496 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230242AbiLXETT (ORCPT ); Fri, 23 Dec 2022 23:19:19 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.15.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9AF941CB14; Fri, 23 Dec 2022 20:19:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1671855540; bh=5PoiGuKTjTB2f9D4z+MnZKdOvcx2VJpMI8xwt9UGaxg=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=WnFVltG1bY+7NVl6gfuDWom0b0Dx0Mgy2UI4yUSie5PlVXvx+jB0G3pNanK3QlyTs DOYrBpfsM4b13rWxYC4mCQcp2LzxA7Lbxh90GGVIUj5MOtuQuVzON7evI7lA7izLbM eV6wOr+kOglPbgIJz2M2fTUNYJZw4KGeTqPCIaDJpUOX2He9oBaU2vzaFXOPLxW0+L SBcJAENjN6uNEnWvZSMaBtFHGPfL0vV0132jCZZ5SKePeaRLsZf0hmGRPYosJN8+Ou KX69b+CeOGgH4qq+2ggfccxhmKV1CnohV0xk58LJ6viuve3XSeBWWNs9H9f3J6NTHU QGOJCGQjEJdfw== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from esprimo-mx.users.agdsn.de ([141.30.226.129]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MirjS-1od9Tk2KYO-00euL0; Sat, 24 Dec 2022 05:19:00 +0100 From: Armin Wolf To: jdelvare@suse.com, linux@roeck-us.net Cc: linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/3] hwmon: (ftsteutates) Fix scaling of measurements Date: Sat, 24 Dec 2022 05:18:53 +0100 Message-Id: <20221224041855.83981-2-W_Armin@gmx.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221224041855.83981-1-W_Armin@gmx.de> References: <20221224041855.83981-1-W_Armin@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:zwsmSLNj/mM9MGI2msAmznXpdXUl/1DAJ8f8clp9J97TVKEyIhw AoGW6GY3BGa5Wll0tpAH7rabhsDh4rDa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3AVbQkU7/rF9f7GE8TRUcWiy38Ek2iKD8oEugXMrcVm7OGij/vu7aKslPOgswO1QZrtHTUr 1qjjlcnpXeeOAUIRH9yulzUQAN8= X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1753067756194457456?= X-GMAIL-MSGID: =?utf-8?q?1753067756194457456?= A user complained that the ftsteutates driver was displaying bogus values since its introduction. This happens because the sensor measurements need to be scaled in order to produce meaningful results: - the fan speed needs to be multiplied by 60 since its in RPS - the temperature is in degrees celsius and needs an offset of 64 - the voltage is in 1/256 of 3.3V The offical datasheet says the voltage needs to be divided by 256, but this is likely an off-by-one-error, since even the BIOS devides by 255 (otherwise 3.3V could not be measured). The voltage channels additionally need a board-specific multiplier, however this can be done by the driver since its board-specific. The reason the missing scaling of measurements is the way Fujitsu used this driver when it was still out-of-tree. Back then, all scaling was done in userspace by libsensors, even the generic one. Tested on a Fujitsu DS3401-B1. Fixes: 08426eda58e0 ("hwmon: Add driver for FTS BMC chip "Teutates"") Signed-off-by: Armin Wolf --- Documentation/hwmon/ftsteutates.rst | 4 ++++ drivers/hwmon/ftsteutates.c | 19 +++++++++++++------ 2 files changed, 17 insertions(+), 6 deletions(-) -- 2.30.2 diff --git a/Documentation/hwmon/ftsteutates.rst b/Documentation/hwmon/ftsteutates.rst index 58a2483d8d0d..198fa8e2819d 100644 --- a/Documentation/hwmon/ftsteutates.rst +++ b/Documentation/hwmon/ftsteutates.rst @@ -22,6 +22,10 @@ enhancements. It can monitor up to 4 voltages, 16 temperatures and 8 fans. It also contains an integrated watchdog which is currently implemented in this driver. +The 4 voltages require a board-specific multiplier, since the BMC can +only measure voltages up to 3.3V and thus relies on voltage dividers. +Consult your motherboard manual for details. + To clear a temperature or fan alarm, execute the following command with the correct path to the alarm file:: diff --git a/drivers/hwmon/ftsteutates.c b/drivers/hwmon/ftsteutates.c index f5b8e724a8ca..ffa0bb364877 100644 --- a/drivers/hwmon/ftsteutates.c +++ b/drivers/hwmon/ftsteutates.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -347,13 +348,15 @@ static ssize_t in_value_show(struct device *dev, { struct fts_data *data = dev_get_drvdata(dev); int index = to_sensor_dev_attr(devattr)->index; - int err; + int value, err; err = fts_update_device(data); if (err < 0) return err; - return sprintf(buf, "%u\n", data->volt[index]); + value = DIV_ROUND_CLOSEST(data->volt[index] * 3300, 255); + + return sprintf(buf, "%d\n", value); } static ssize_t temp_value_show(struct device *dev, @@ -361,13 +364,15 @@ static ssize_t temp_value_show(struct device *dev, { struct fts_data *data = dev_get_drvdata(dev); int index = to_sensor_dev_attr(devattr)->index; - int err; + int value, err; err = fts_update_device(data); if (err < 0) return err; - return sprintf(buf, "%u\n", data->temp_input[index]); + value = (data->temp_input[index] - 64) * 1000; + + return sprintf(buf, "%d\n", value); } static ssize_t temp_fault_show(struct device *dev, @@ -436,13 +441,15 @@ static ssize_t fan_value_show(struct device *dev, { struct fts_data *data = dev_get_drvdata(dev); int index = to_sensor_dev_attr(devattr)->index; - int err; + int value, err; err = fts_update_device(data); if (err < 0) return err; - return sprintf(buf, "%u\n", data->fan_input[index]); + value = data->fan_input[index] * 60; + + return sprintf(buf, "%d\n", value); } static ssize_t fan_source_show(struct device *dev,