From patchwork Tue May 7 19:35:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Fainelli X-Patchwork-Id: 10933697 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 BC46114B6 for ; Tue, 7 May 2019 19:38:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ABBBE24B44 for ; Tue, 7 May 2019 19:38:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9D6232870E; Tue, 7 May 2019 19:38:20 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B62D126246 for ; Tue, 7 May 2019 19:38:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726567AbfEGTiR (ORCPT ); Tue, 7 May 2019 15:38:17 -0400 Received: from mail-pl1-f195.google.com ([209.85.214.195]:45450 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726336AbfEGTiQ (ORCPT ); Tue, 7 May 2019 15:38:16 -0400 Received: by mail-pl1-f195.google.com with SMTP id a5so3735587pls.12; Tue, 07 May 2019 12:38:16 -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=E3cy6coJyOOa2SbBo8UlxqrSWJcV9cpYsmbojY6zx78=; b=PdeQdBMH+PUZqj2w9dPXVinwmbVbRY3710/zgoNzmgAAwN1AnPnO68PuvRcTOgHdGC ztkUdxZHXvkX6BHIg+H4erw9aGn9DaxXx3diAqZuf3ThTXCSBbfcYT9mckVk1F/RYBI8 vFPjklCNJW2gmPY9EZSVJmdZO9xxOEsViODA/+Fdy7FjBpKFZi24JMxqOjXFmoBz7vSW AFnR5jMbkNZSEt6tRcevkk0cRRxTwksw0LKr9AldUi8bxRDcLXAQ9LB9PRwx/wLbZzk0 zVGxm/MEOKDNF91YJVNk+Ofsq89/gAt68fo76RXVPNxH40O5HAn2CUzUrYt86PSyg7rt FSog== 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=E3cy6coJyOOa2SbBo8UlxqrSWJcV9cpYsmbojY6zx78=; b=BX9+KgiOhr/qvEWNzxyrTsTp+Gwmx5H1wYg2lIv0KeYOVNFkojB8cvbK/6M1j3RkzL mPWpRFxuf1h6UMh9UDkq+L+zB/BAVvGP+dUBZEKb5ceE8iYS5PlQrjufzOPm2ZwPEOHv P5379z8Mj+O008DXTenFPWumAHP9XRwipIV5v5/XkDLwNxBuzQgbE2qmOp/oyMWMe9VG zrH5yu9onqjD1dnKTBPWqKfPtpLkTyH59kMnZ3w38Tp/SZ/eB//YDAHdkyG3OAkm4ufg AsoPoS9Qp9577RVghuXf+/x2QLcirafcXhQz4XItn6QMkZ7TDSXDrzNNlJhZpGyCvYVS fVXw== X-Gm-Message-State: APjAAAUshBVqv/LqBb7IZkvF4joy7CfWAStxNlhHL4BeQ0iFO89tSWcR +xxJjqYKWvr1rtmgfPN2XYLt54xn X-Google-Smtp-Source: APXvYqwSKFH3OcPH0UwFlrAn9EVBXhRUaujmIGC6dieqwuOP4POjIFzGh4hKO76fOOfeE/bNAObGkg== X-Received: by 2002:a17:902:8a81:: with SMTP id p1mr42323974plo.106.1557257895759; Tue, 07 May 2019 12:38:15 -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.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 07 May 2019 12:38:14 -0700 (PDT) From: Florian Fainelli To: linux-kernel@vger.kernel.org Cc: Florian Fainelli , Sudeep Holla , Jean Delvare , Guenter Roeck , linux-arm-kernel@lists.infradead.org, linux-hwmon@vger.kernel.org (open list:HARDWARE MONITORING), bcm-kernel-feedback-list@broadcom.com Subject: [PATCH v2 1/3] kernel: Provide a __pow10() function Date: Tue, 7 May 2019 12:35:02 -0700 Message-Id: <20190507193504.28248-2-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> Sender: linux-hwmon-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Provide a simple macro that can return the value of 10 raised to a positive integer. We are going to use this in order to scale units from firmware to HWMON. Signed-off-by: Florian Fainelli --- include/linux/kernel.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/include/linux/kernel.h b/include/linux/kernel.h index 2d14e21c16c0..62fc8bd84bc9 100644 --- a/include/linux/kernel.h +++ b/include/linux/kernel.h @@ -294,6 +294,17 @@ static inline u32 reciprocal_scale(u32 val, u32 ep_ro) return (u32)(((u64) val * ep_ro) >> 32); } +/* Return in f the value of 10 raise to the power x */ +#define __pow10(x, f)( \ +{ \ + typeof(x) __x = abs(x); \ + f = 1; \ + while (__x--) \ + f *= 10; \ + f; \ +} \ +) + #if defined(CONFIG_MMU) && \ (defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_DEBUG_ATOMIC_SLEEP)) #define might_fault() __might_fault(__FILE__, __LINE__) From patchwork Tue May 7 19:35:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Fainelli X-Patchwork-Id: 10933703 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 8D40614B6 for ; Tue, 7 May 2019 19:38:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7C4A924B44 for ; Tue, 7 May 2019 19:38:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7079F274D1; Tue, 7 May 2019 19:38:31 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1D0CA24B44 for ; Tue, 7 May 2019 19:38:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726336AbfEGTi0 (ORCPT ); Tue, 7 May 2019 15:38:26 -0400 Received: from mail-pl1-f195.google.com ([209.85.214.195]:36068 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726563AbfEGTiS (ORCPT ); Tue, 7 May 2019 15:38:18 -0400 Received: by mail-pl1-f195.google.com with SMTP id d21so1188634plr.3; Tue, 07 May 2019 12:38:18 -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=NxAUam5Dvt1HQoAAg/vTkC6mAACjVaJFnU6FSnpD4fQ=; b=supJbkS+TvzwiaGvP7CzePiq38v/y5xY0z87bhAKggMMhvSyxETbpEDetJuR15OUjT AxuJQu8rp3sOufc6NUvueIbSBKpk/BrlBqtKNu4HP96mfG1KZFrMj/W5CgUergGGawk1 V6M0EevyFGKuGjQOYJpzDJ81ZQBgjQQaeSrWoVb8SGCn9SSP4kdy66klqRlletmtU51N 6/TX7lm5mXToRsytvDNCJT6lUE/xfefcI2FxJKDAH9DbRjBRsoVBF3sziA5yDB9jqTgt GqYx6g31qQBnNBJ0TlcxHzZ942zS1/R1nwPTlMdV8YJbbTFv7Us/rZJ59fsJLHkfUXIC zOIw== 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=NxAUam5Dvt1HQoAAg/vTkC6mAACjVaJFnU6FSnpD4fQ=; b=ItO44BYrfPAHL05ydt7zc7eJ9HFRBtSrxTJosefHZTZiwB+3ne639wlhxpQeZwqcRA 20IEMXDKXPY9nqOUcoH+gwZdeBGAWOhNV+OXwFBgqlUsC3A4L8r6l89AcSRvQKplNCpr ThH53McHCsZChx/zOmPzD4BZI7X8ejocKOnhRUhDMlhVRmydl9w+yl6b/l7RakZQXjqa OjxYNAlUjRxGKKpYjMEUiwTkW6crEyPDIf6ixAAQ4areiVtEF3lFaDXrWz2YlykOhScb bCyzmlwArXnI0cZEHl8Th9SLuEmzyrZFKMBuXgoH9dBWgyXleL1vXC6J86NOCaOCiRwb 2Waw== X-Gm-Message-State: APjAAAViGUG4zdV14X6qF51uzfwc1FXgCHWHdVLdRHDmYn1alv6YXcZ3 ty2InsAbjxjxATKrkTsCwdPCF+k9 X-Google-Smtp-Source: APXvYqw5f3+BqYRPyHnvk/luvhl70lmxR6wsQrxcgUbarh8heRLEfenNRO+d7eY9YJWmBJT9OunRBg== X-Received: by 2002:a17:902:364:: with SMTP id 91mr41315233pld.72.1557257897280; Tue, 07 May 2019 12:38:17 -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.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 07 May 2019 12:38:16 -0700 (PDT) From: Florian Fainelli To: linux-kernel@vger.kernel.org Cc: Florian Fainelli , Sudeep Holla , Jean Delvare , Guenter Roeck , linux-arm-kernel@lists.infradead.org, linux-hwmon@vger.kernel.org (open list:HARDWARE MONITORING), bcm-kernel-feedback-list@broadcom.com Subject: [PATCH v2 2/3] firmware: arm_scmi: Fetch and store sensor scale Date: Tue, 7 May 2019 12:35:03 -0700 Message-Id: <20190507193504.28248-3-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> Sender: linux-hwmon-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP In preparation for dealing with scales within the SCMI HWMON driver, fetch and store the sensor unit scale into the scmi_sensor_info structure. In order to simplify computations for upper layer, take care of sign extending the scale to a full 8-bit signed value. Signed-off-by: Florian Fainelli --- drivers/firmware/arm_scmi/sensors.c | 6 ++++++ include/linux/scmi_protocol.h | 1 + 2 files changed, 7 insertions(+) diff --git a/drivers/firmware/arm_scmi/sensors.c b/drivers/firmware/arm_scmi/sensors.c index b53d5cc9c9f6..21353470a740 100644 --- a/drivers/firmware/arm_scmi/sensors.c +++ b/drivers/firmware/arm_scmi/sensors.c @@ -34,6 +34,8 @@ struct scmi_msg_resp_sensor_description { __le32 attributes_high; #define SENSOR_TYPE(x) ((x) & 0xff) #define SENSOR_SCALE(x) (((x) >> 11) & 0x3f) +#define SENSOR_SCALE_SIGN BIT(5) +#define SENSOR_SCALE_EXTEND GENMASK(7, 6) #define SENSOR_UPDATE_SCALE(x) (((x) >> 22) & 0x1f) #define SENSOR_UPDATE_BASE(x) (((x) >> 27) & 0x1f) u8 name[SCMI_MAX_STR_SIZE]; @@ -140,6 +142,10 @@ static int scmi_sensor_description_get(const struct scmi_handle *handle, s = &si->sensors[desc_index + cnt]; s->id = le32_to_cpu(buf->desc[cnt].id); s->type = SENSOR_TYPE(attrh); + s->scale = SENSOR_SCALE(attrh); + /* Sign extend to a full s8 */ + if (s->scale & SENSOR_SCALE_SIGN) + s->scale |= SENSOR_SCALE_EXTEND; strlcpy(s->name, buf->desc[cnt].name, SCMI_MAX_STR_SIZE); } diff --git a/include/linux/scmi_protocol.h b/include/linux/scmi_protocol.h index 3105055c00a7..9ff2e9357e9a 100644 --- a/include/linux/scmi_protocol.h +++ b/include/linux/scmi_protocol.h @@ -144,6 +144,7 @@ struct scmi_power_ops { struct scmi_sensor_info { u32 id; u8 type; + s8 scale; char name[SCMI_MAX_STR_SIZE]; }; 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: 10933701 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 4C03616C1 for ; Tue, 7 May 2019 19:38:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3C11024B44 for ; Tue, 7 May 2019 19:38:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 30684274D1; Tue, 7 May 2019 19:38:22 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D451724B44 for ; Tue, 7 May 2019 19:38:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726608AbfEGTiV (ORCPT ); Tue, 7 May 2019 15:38:21 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:46729 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726336AbfEGTiU (ORCPT ); Tue, 7 May 2019 15:38:20 -0400 Received: by mail-pl1-f194.google.com with SMTP id bi2so8668667plb.13; 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=DaY1NFiMQNmL4I1nseJxl2l74ew+xt6RG9GeJuw01Fk5I9jPQ4Oc0U7OHuZYNtpLyw PzZvzf+MOMsmg8/3cp3CIsTILLdXRZM7vf2SUCXWG+HoCIHT7RrqPwpUkXo8whfr9FVP 15amTxVu0XWxlupH0Z489fWjAKqs7GR2DFfy80lv5WkxGufmRZBjQBfTIZblAUQyBUAL oKIksqUtbh6ClaHhwaYUNqlAt3YJW7R724jUE/UY8aV1bWaSCRDryJUPUM+gKqrJchwj SNS/KxjPHajfxTbsTHD3yFK4maqQgoNHKnUIe+sakT0p+EFUqmIEXkdNQ5Appk3+8e3r SAXg== X-Gm-Message-State: APjAAAXQwMyI2qnz368APL+8Pgk7npums5ksQgoMqpFaqhOZc+Vw6GEA RodoiyjD/nCNFemcVFxR0dPEYhKA 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 Cc: Florian Fainelli , Sudeep Holla , Jean Delvare , Guenter Roeck , linux-arm-kernel@lists.infradead.org, linux-hwmon@vger.kernel.org (open list:HARDWARE MONITORING), bcm-kernel-feedback-list@broadcom.com 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> Sender: linux-hwmon-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.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; }