From patchwork Mon May 6 22:41:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Fainelli X-Patchwork-Id: 10931957 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 2C17C1515 for ; Mon, 6 May 2019 22:41:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1C572288CE for ; Mon, 6 May 2019 22:41:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 108DA288D3; Mon, 6 May 2019 22:41:30 +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 AC095288CE for ; Mon, 6 May 2019 22:41:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726548AbfEFWlU (ORCPT ); Mon, 6 May 2019 18:41:20 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:40967 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725994AbfEFWlS (ORCPT ); Mon, 6 May 2019 18:41:18 -0400 Received: by mail-pf1-f194.google.com with SMTP id l132so2563065pfc.8; Mon, 06 May 2019 15:41: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=E5Dd3KTWD6CXDeQyGrryfHzlZnUN0IagEOvDF7fStsU=; b=rYc6GAsGNJY4zX3g6QYdRYAV9Fy8LhGm0OovP34jxb0OEZatnM4m710MQ288nFlXVW aODV9dCPzwT0a6u3eGQ679IS1JgFmz5hZQG7fn1u/o+EvFaZH07DyvjjCBwRQTKD76rb vJU/QbyWLP5bLL3/wZdt9OW4KteT3PGiEEoET/ZdMldivpnw+JqjfMLwfiezBJZxEavr q/ue5nnvia4Fa3r31P+NTnjI6BZAzLMmyQyr340miA06bynazZVEiQ0Q2g4cCiB5hk8M RE76YS1/6QxHnbckQtuhHth/NBcAmt2/tmKDXduPxYCIq+brr3MmECyhDTj7P2eC1VM4 Is3g== 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=E5Dd3KTWD6CXDeQyGrryfHzlZnUN0IagEOvDF7fStsU=; b=VbaL3QzrBk4trNGOIgmlmGbcjwuzONjl9rJpnojNxGFKVzsiedIF/uYDAwjW4paHwR SHCW/u4GcXwFMaLVuLWfxmGvIfqLn+kDLo70s9RWtNI9Ql0/1EEUevPaBl2JJAUn9LAM bFGDZonE2PdLfoTaXWAQpDRxnrvJBdocnm5BL/hBn6YoPoMCrxYmnzw8QAgyUDB7f8u6 NpqYj4RLwvjairVHFwya8P0FAcXpST/KqWteTxI0EIGlT8XiHyY00ZIxaPATAox9/lvw i8sKkGlHHZtsNHwkyFwskZugDfAU6bfMyoRed2XAPU9IkjEhFwrV+5hUZvW+1An2ssBM jagg== X-Gm-Message-State: APjAAAV3aJU4bzajjgYxxa2qZXX9SvwSl0xfkkvWfHrbDhkBRqpry6BR PvnSZh2Z7jJ7NJ5lE7KUinU0LrL6 X-Google-Smtp-Source: APXvYqzlpp4RXTrN/URhBa3Ul4oDUGmN3bljpPYVgvpBc9mbG/MQkXpb0BqL9en9ld7lE1hc2AnSSA== X-Received: by 2002:aa7:91c8:: with SMTP id z8mr37663612pfa.110.1557182477143; Mon, 06 May 2019 15:41:17 -0700 (PDT) Received: from fainelli-desktop.igp.broadcom.net ([192.19.223.250]) by smtp.gmail.com with ESMTPSA id s11sm19784153pga.36.2019.05.06.15.41.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 May 2019 15:41:16 -0700 (PDT) From: Florian Fainelli To: linux-kernel@vger.kernel.org Cc: bcm-kernel-feedback-list@broadcom.com, Florian Fainelli , Sudeep Holla , Jean Delvare , Guenter Roeck , linux-arm-kernel@lists.infradead.org, linux-hwmon@vger.kernel.org (open list:HARDWARE MONITORING) Subject: [PATCH 1/2] firmware: arm_scmi: Fetch and store sensor scale Date: Mon, 6 May 2019 15:41:08 -0700 Message-Id: <20190506224109.9357-2-f.fainelli@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190506224109.9357-1-f.fainelli@gmail.com> References: <20190506224109.9357-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. Signed-off-by: Florian Fainelli --- drivers/firmware/arm_scmi/sensors.c | 7 ++++++- include/linux/scmi_protocol.h | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/firmware/arm_scmi/sensors.c b/drivers/firmware/arm_scmi/sensors.c index b53d5cc9c9f6..f324f0a13ebe 100644 --- a/drivers/firmware/arm_scmi/sensors.c +++ b/drivers/firmware/arm_scmi/sensors.c @@ -33,7 +33,8 @@ struct scmi_msg_resp_sensor_description { #define NUM_TRIP_POINTS(x) (((x) >> 4) & 0xff) __le32 attributes_high; #define SENSOR_TYPE(x) ((x) & 0xff) -#define SENSOR_SCALE(x) (((x) >> 11) & 0x3f) +#define SENSOR_SCALE_MASK 0x3f +#define SENSOR_SCALE(x) (((x) >> 11) & SENSOR_SCALE_MASK) #define SENSOR_UPDATE_SCALE(x) (((x) >> 22) & 0x1f) #define SENSOR_UPDATE_BASE(x) (((x) >> 27) & 0x1f) u8 name[SCMI_MAX_STR_SIZE]; @@ -140,6 +141,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 u8 */ + if (s->scale & ((SENSOR_SCALE_MASK + 1) >> 1)) + s->scale |= GENMASK(7, 6); 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..7746f171f108 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; + u8 scale; char name[SCMI_MAX_STR_SIZE]; }; From patchwork Mon May 6 22:41:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Fainelli X-Patchwork-Id: 10931959 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 6B467924 for ; Mon, 6 May 2019 22:41:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5BF50288CE for ; Mon, 6 May 2019 22:41:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4DA4A288D2; Mon, 6 May 2019 22:41:30 +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 D6A30288D1 for ; Mon, 6 May 2019 22:41:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726519AbfEFWlU (ORCPT ); Mon, 6 May 2019 18:41:20 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:45948 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726517AbfEFWlT (ORCPT ); Mon, 6 May 2019 18:41:19 -0400 Received: by mail-pg1-f194.google.com with SMTP id i21so7168010pgi.12; Mon, 06 May 2019 15:41: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=FL8AbszKRwppcPe458VUea1JFGXeL+AyuUIjEd2fdow=; b=WD8Bl/oz4MmtFrgl/OR94+xGKMcER30iXdBiIr4cfyk1QUcR5T6uNyJUFUGTkXpwvS cyBf92CemP6O/jgpDmadEEXXJQXaB50ksCHXaLl8OL3UOesvt/RIvo5mIaCinVXp37V2 NzSwXCFOw4VZMoJLhEAaOeByPwVXfN97zDFmZZUSM4RADzzcWPxo6c0wALyVFp1kSY4r vXS+JgG/+w7dw1E/u7NoB7l0TfMaBYZxEUE+CwGB11X0hsfTGO+jcFkGkvwVRM2qrcR8 NcqYW5lEkUE9C8j/gvHc9jSodFPbNJ9VkoJ7lUr2DFVWsMJ1lyMy2IIpgQqZ9jet7hky gXLg== 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=FL8AbszKRwppcPe458VUea1JFGXeL+AyuUIjEd2fdow=; b=omNsQzAlVL7iDy/cu+nwI3x2nK5yOd8L1Np6rqqXnebmdGJXrma/Vzwsj10v5vso86 8S5VnUcS+CX4MFIX26DU1y0to41T9h32DNtJ6ej3YmHDRMSsiWBjVTfCatwu5EQ1/kQC HoDlHad0Zx92oauc62cDwu8PKs6SlvRkAS6RkLYnhg7s8TA70rVgEoOkYvvfCxCx6ma7 hZpDOi2D/o8V1sctoYdMcxrANdteSpO5lgPyRTRztHt5FJ5bHvfNOr6zid1hSqgUkRVU xdV32Dul3nCBb+/RDtzWLaCWfNUHlHwXV54iG3eEg43Wa7LIWgJFN6FlR4sNo6uE+NX3 KKNA== X-Gm-Message-State: APjAAAU8SVJj/uCvQpB135cm21VugHLhnrPCPT5zCMZ0mJAhdBXIsm1U dfb5m/B1wc6idEZ7r3Wf+OoHPxG7 X-Google-Smtp-Source: APXvYqzazBLsdP/PngE2ih+OrbyZh7ATgIiJ4YmGbGaickNYpdl6b/VcxzBShKtEhMdIOZbF6BYLhg== X-Received: by 2002:a63:fe0a:: with SMTP id p10mr34894833pgh.86.1557182478738; Mon, 06 May 2019 15:41:18 -0700 (PDT) Received: from fainelli-desktop.igp.broadcom.net ([192.19.223.250]) by smtp.gmail.com with ESMTPSA id s11sm19784153pga.36.2019.05.06.15.41.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 May 2019 15:41:17 -0700 (PDT) From: Florian Fainelli To: linux-kernel@vger.kernel.org Cc: bcm-kernel-feedback-list@broadcom.com, Florian Fainelli , Sudeep Holla , Jean Delvare , Guenter Roeck , linux-arm-kernel@lists.infradead.org, linux-hwmon@vger.kernel.org (open list:HARDWARE MONITORING) Subject: [PATCH 2/2] hwmon: scmi: Scale values to target desired HWMON units Date: Mon, 6 May 2019 15:41:09 -0700 Message-Id: <20190506224109.9357-3-f.fainelli@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190506224109.9357-1-f.fainelli@gmail.com> References: <20190506224109.9357-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 | 55 +++++++++++++++++++++++++++++++------- 1 file changed, 46 insertions(+), 9 deletions(-) diff --git a/drivers/hwmon/scmi-hwmon.c b/drivers/hwmon/scmi-hwmon.c index a80183a488c5..e9913509cb88 100644 --- a/drivers/hwmon/scmi-hwmon.c +++ b/drivers/hwmon/scmi-hwmon.c @@ -18,6 +18,51 @@ struct scmi_sensors { const struct scmi_sensor_info **info[hwmon_max]; }; +static enum hwmon_sensor_types scmi_types[] = { + [TEMPERATURE_C] = hwmon_temp, + [VOLTAGE] = hwmon_in, + [CURRENT] = hwmon_curr, + [POWER] = hwmon_power, + [ENERGY] = hwmon_energy, +}; + +static u64 scmi_hwmon_scale(const struct scmi_sensor_info *sensor, u64 value) +{ + u64 scaled_value = value; + s8 desired_scale; + int n, p; + + switch (sensor->type) { + case TEMPERATURE_C: + case VOLTAGE: + case CURRENT: + /* fall through */ + desired_scale = -3; + break; + case POWER: + case ENERGY: + /* fall through */ + desired_scale = -6; + break; + default: + return scaled_value; + } + + n = (s8)sensor->scale - desired_scale; + if (n == 0) + return scaled_value; + + for (p = 0; p < abs(n); p++) { + /* Need to scale up from sensor to HWMON */ + if (n > 0) + scaled_value *= 10; + else + do_div(scaled_value, 10); + } + + return scaled_value; +} + static int scmi_hwmon_read(struct device *dev, enum hwmon_sensor_types type, u32 attr, int channel, long *val) { @@ -30,7 +75,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; } @@ -91,14 +136,6 @@ static int scmi_hwmon_add_chan_info(struct hwmon_channel_info *scmi_hwmon_chan, return 0; } -static enum hwmon_sensor_types scmi_types[] = { - [TEMPERATURE_C] = hwmon_temp, - [VOLTAGE] = hwmon_in, - [CURRENT] = hwmon_curr, - [POWER] = hwmon_power, - [ENERGY] = hwmon_energy, -}; - static u32 hwmon_attributes[] = { [hwmon_chip] = HWMON_C_REGISTER_TZ, [hwmon_temp] = HWMON_T_INPUT | HWMON_T_LABEL,