Received: by 2002:a05:6358:f14:b0:e5:3b68:ec04 with SMTP id b20csp1492183rwj; Fri, 23 Dec 2022 21:10:35 -0800 (PST) X-Google-Smtp-Source: AMrXdXuOe2yXBXeMYf16UquAM97VijItzt/IVGTjSs0muTVR6/N3x8uOkq9C3QqIiwK2xma+UaM+ X-Received: by 2002:a05:6a20:4916:b0:a8:61bd:d9af with SMTP id ft22-20020a056a20491600b000a861bdd9afmr12962706pzb.40.1671858635495; Fri, 23 Dec 2022 21:10:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671858635; cv=none; d=google.com; s=arc-20160816; b=d+PK1E0FwEVGQE4m0LnI7nzVars4xI/dGqcNXyYrle4GsCt9tdlT5NHqGyCBx6x6ea oouBbcPc4E3T/PIURoGqSnkQtCyey6WEDKirR6E0cRCp0EFxV/tt5OuXwrriIucA8Yzw v6iDjU2C+hL+edA3nLEfPk5tFPA562PirpHicW+nIQR9ag/zsMO4w1f47kHFV7AZ3Yow mwhYwg3ehfvlwWNQEwRpuEtjdhKEYNC15qo+dHcb57iVxRvFK6iRtjQ7CVH4HFa481I+ XBAUL7PH04lHypjzSfCRoZW8lhYZATS9xB/R9LzNA7P59qj0lhpxeQsawLbwyIzhoWRn ke+w== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h37-20020a632125000000b00476837b4138si5022045pgh.800.2022.12.23.21.10.20; Fri, 23 Dec 2022 21:10:35 -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 + 65 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 Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:zwsmSLNj/mM9MGI2msAmznXpdXUl/1DAJ8f8clp9J97TVKEyIhw AoGW6GY3BGa5Wll0tpAH7rabhsDh4rDa/JHVkU/DCYoGmo72w9JLjiVMFkV7H7XKhl/QH/g ju45yhE8jQw5dlCefEvkMpOrR8PSpwuRgBrmvLEyh4C62QnlmZkutxT9VCNN9qQHpCMkT/Z b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=-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 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 =2D-- Documentation/hwmon/ftsteutates.rst | 4 ++++ drivers/hwmon/ftsteutates.c | 19 +++++++++++++------ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/Documentation/hwmon/ftsteutates.rst b/Documentation/hwmon/fts= teutates.rst index 58a2483d8d0d..198fa8e2819d 100644 =2D-- a/Documentation/hwmon/ftsteutates.rst +++ b/Documentation/hwmon/ftsteutates.rst @@ -22,6 +22,10 @@ enhancements. It can monitor up to 4 voltages, 16 tempe= ratures 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 t= he correct path to the alarm file:: diff --git a/drivers/hwmon/ftsteutates.c b/drivers/hwmon/ftsteutates.c index f5b8e724a8ca..ffa0bb364877 100644 =2D-- 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 =3D dev_get_drvdata(dev); int index =3D to_sensor_dev_attr(devattr)->index; - int err; + int value, err; err =3D fts_update_device(data); if (err < 0) return err; - return sprintf(buf, "%u\n", data->volt[index]); + value =3D 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 =3D dev_get_drvdata(dev); int index =3D to_sensor_dev_attr(devattr)->index; - int err; + int value, err; err =3D fts_update_device(data); if (err < 0) return err; - return sprintf(buf, "%u\n", data->temp_input[index]); + value =3D (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 =3D dev_get_drvdata(dev); int index =3D to_sensor_dev_attr(devattr)->index; - int err; + int value, err; err =3D fts_update_device(data); if (err < 0) return err; - return sprintf(buf, "%u\n", data->fan_input[index]); + value =3D data->fan_input[index] * 60; + + return sprintf(buf, "%d\n", value); } static ssize_t fan_source_show(struct device *dev, =2D- 2.30.2