From patchwork Tue May 7 19:35:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Fainelli X-Patchwork-Id: 10933711 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 F3C0014DB for ; Tue, 7 May 2019 19:38:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DE7CD24B44 for ; Tue, 7 May 2019 19:38:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CF529281DB; Tue, 7 May 2019 19:38:52 +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=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 84A4024B44 for ; Tue, 7 May 2019 19:38:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=n8x34qC/C1x47L/5+kqAzPyn+BcTxFWaDvhOh9XV63E=; b=ExPV4PE3WR6rWfDd2EKVleRTv3 utfliQwCcBSCmAEkX9B9OTqXFXgYdwdTXgspJYhRBLDfjQp8vXjgoZNzi3QM6gW351OMCHl5aXB0Q I+GBs7p7OC2cYTR37R4AD1sno1be+cNHSxehEQPgbJB6Sy7hNAlUngAiXklbj4t/PhW8mV4SAyAhX L+Ex7hqD5+uMaCHW0CM967gSzmi0Jxn62R4ofeX1FKK2z4hC/dPco8OmUeGu8VqJ6RV2RGjJxFoRf /2yRieoSRVQCe3bScNkk0UUBdOgq8SWZNL/+hCLNf5LaPuE6WyodU6JXjO1y9Z0c7KR7HkbQEZbCP 9BqtkxaQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hO5vK-0005qc-EK; Tue, 07 May 2019 19:38:46 +0000 Received: from mail-pl1-x644.google.com ([2607:f8b0:4864:20::644]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hO5ut-0005GM-PF for linux-arm-kernel@lists.infradead.org; Tue, 07 May 2019 19:38:23 +0000 Received: by mail-pl1-x644.google.com with SMTP id y3so8690194plp.0 for ; Tue, 07 May 2019 12:38:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=0un4Zq1Ylcl4MILUCeu+0vxFmB6uI/BzyrLOsfSvsMM=; b=RFOUUtGXP8OJR5bQmeIdNY3FuggAcfnTfuyUoXqn9lbFOD3gfZnBbA63LWUpgklwQ0 7MI/Qs3Ae2RpZm4tI4XSW4RxXp7Y3xj7Z1uwkilzE6NDrPqc3uvJwx8/vr2giw9wKfB0 zkDlRQXeb/bF6fflJkc0DBDNJNtkVoQIdoeimGxZJUPGfJGRLaCpbx2IIkj3foDMYjOO PWaPmr/M3yhPf7N681uWwQDkxLfH2/8qL9wUalhnAnG5ihkkEaJK+G+QhLmANO7vRiTn cgcZ8jdoAM7U3czBbWeKKh7ObtbqV5/X4mA9beUOefb+nLMwGUReTc2+PVbgv41TMLfO gXdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=0un4Zq1Ylcl4MILUCeu+0vxFmB6uI/BzyrLOsfSvsMM=; b=AB9Wqx9aMc8M8UVrzWzXmQjsRjWDWN8aG1glC6dgR6qYbyDfcU17qEFCOWo7dwf4MF HgDdnrCWh73BVc2pEHA1d9ELUPHyqBp8hbsnAGX/NsdwgryJaY6iFPUOwCiHVASsSHGf FEGhDiy8PwsWuoJB2i3frG9czHRqVP74Wn4E3YGfpJ0duo6zoBHNA/CWpIYRipftk/Qy fFTzUqFGZJMpsqFg/lM5GIUxZNLZzlRqoenbPNB6XZML9f65bprX5/R4w0y1S3o+Crdn oXvJIVUcsTJWU7MdgxgBeQPfTTq3LH21p8EXJXgRgc1g7IGu2YSAVQ47I6e7h7IUG9Ax 8kHw== X-Gm-Message-State: APjAAAWd/EgAi4+xxgLUlEwEl6T1ojBS34/XVtM2qjhWYSfu6iC3RMAS 4lnXD8LNZUjBkbYLyzCWF48= X-Google-Smtp-Source: APXvYqy9JrXGy3NKwIYDouYAWcrRPVQJ8hxuwN5Y/em8coxBLkR2WaURI4/cr8v4DaOdBargyNfPXA== X-Received: by 2002:a17:902:e188:: with SMTP id cd8mr20263009plb.110.1557257899147; Tue, 07 May 2019 12:38:19 -0700 (PDT) Received: from fainelli-desktop.igp.broadcom.net ([192.19.223.250]) by smtp.gmail.com with ESMTPSA id l21sm5964658pff.40.2019.05.07.12.38.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 07 May 2019 12:38:18 -0700 (PDT) From: Florian Fainelli To: linux-kernel@vger.kernel.org Subject: [PATCH v2 3/3] hwmon: scmi: Scale values to target desired HWMON units Date: Tue, 7 May 2019 12:35:04 -0700 Message-Id: <20190507193504.28248-4-f.fainelli@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190507193504.28248-1-f.fainelli@gmail.com> References: <20190507193504.28248-1-f.fainelli@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190507_123820_015630_D2143F74 X-CRM114-Status: GOOD ( 15.12 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "open list:HARDWARE MONITORING" , Jean Delvare , Florian Fainelli , bcm-kernel-feedback-list@broadcom.com, Guenter Roeck , Sudeep Holla , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP If the SCMI firmware implementation is reporting values in a scale that is different from the HWMON units, we need to scale up or down the value according to how far appart they are. Signed-off-by: Florian Fainelli --- drivers/hwmon/scmi-hwmon.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/drivers/hwmon/scmi-hwmon.c b/drivers/hwmon/scmi-hwmon.c index a80183a488c5..5c244053efc8 100644 --- a/drivers/hwmon/scmi-hwmon.c +++ b/drivers/hwmon/scmi-hwmon.c @@ -18,6 +18,34 @@ struct scmi_sensors { const struct scmi_sensor_info **info[hwmon_max]; }; +static u64 scmi_hwmon_scale(const struct scmi_sensor_info *sensor, u64 value) +{ + s8 scale = sensor->scale; + unsigned long long f; + + switch (sensor->type) { + case TEMPERATURE_C: + case VOLTAGE: + case CURRENT: + scale += 3; + break; + case POWER: + case ENERGY: + scale += 6; + break; + default: + break; + } + + __pow10(abs(scale), f); + if (scale > 0) + value *= f; + else + do_div(value, f); + + return value; +} + static int scmi_hwmon_read(struct device *dev, enum hwmon_sensor_types type, u32 attr, int channel, long *val) { @@ -30,7 +58,7 @@ static int scmi_hwmon_read(struct device *dev, enum hwmon_sensor_types type, sensor = *(scmi_sensors->info[type] + channel); ret = h->sensor_ops->reading_get(h, sensor->id, false, &value); if (!ret) - *val = value; + *val = scmi_hwmon_scale(sensor, value); return ret; }