From patchwork Wed May 25 07:36:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Slawomir Stepien X-Patchwork-Id: 12860742 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 420DBC4332F for ; Wed, 25 May 2022 07:37:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231339AbiEYHhT (ORCPT ); Wed, 25 May 2022 03:37:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46874 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232374AbiEYHhR (ORCPT ); Wed, 25 May 2022 03:37:17 -0400 Received: from smtpo68.interia.pl (smtpo68.interia.pl [217.74.67.68]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CABAE5DBF1 for ; Wed, 25 May 2022 00:37:16 -0700 (PDT) Received: from localhost (unknown [80.68.225.159]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by www.poczta.fm (INTERIA.PL) with ESMTPSA; Wed, 25 May 2022 09:37:13 +0200 (CEST) From: Slawomir Stepien To: linux-hwmon@vger.kernel.org, devicetree@vger.kernel.org Cc: jdelvare@suse.com, linux@roeck-us.net, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, przemyslaw.cencner@nokia.com, krzysztof.adamski@nokia.com, alexander.sverdlin@nokia.com, sst@poczta.fm, slawomir.stepien@nokia.com Subject: [PATCH 1/7] dt-bindings: hwmon: Add compatible string for ADT7481 in lm90 Date: Wed, 25 May 2022 09:36:51 +0200 Message-Id: <20220525073657.573327-2-sst@poczta.fm> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220525073657.573327-1-sst@poczta.fm> References: <20220525073657.573327-1-sst@poczta.fm> MIME-Version: 1.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=interia.pl; s=biztos; t=1653464235; bh=4odEewbwZcaxnfC1CYoMmE2sqvk0v0Ksnmm/yXE9drM=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=K4kEoXbTzL/PsDerrtcCkkfqNmkTvNrYVRlxf5TeueW9usAkj4MgC4JlORFg7cD1u H1LN8O272i/OoFgz3xyLvGH7TC0DaAwYddKmizCBjyYB/LKJ9yftcw3NI3SojDPUri 4gXIBbp58ky8E80JFSnHPGL6HDXiNNl9JKUUjyK0= Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org From: Slawomir Stepien This will allow binding the driver with the device from the device tree. This device can work in extended temperature measurement mode, so add it also to the list of devices that support 'ti,extended-range-enable'. Signed-off-by: Slawomir Stepien Acked-by: Rob Herring --- Documentation/devicetree/bindings/hwmon/national,lm90.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Documentation/devicetree/bindings/hwmon/national,lm90.yaml b/Documentation/devicetree/bindings/hwmon/national,lm90.yaml index b04657849852..82fce96498c7 100644 --- a/Documentation/devicetree/bindings/hwmon/national,lm90.yaml +++ b/Documentation/devicetree/bindings/hwmon/national,lm90.yaml @@ -16,6 +16,7 @@ properties: - adi,adm1032 - adi,adt7461 - adi,adt7461a + - adi,adt7481 - dallas,max6646 - dallas,max6647 - dallas,max6649 @@ -70,6 +71,7 @@ allOf: enum: - adi,adt7461 - adi,adt7461a + - adi,adt7481 - ti,tmp451 - ti,tmp461 then: From patchwork Wed May 25 07:36:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Slawomir Stepien X-Patchwork-Id: 12860743 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5591BC43217 for ; Wed, 25 May 2022 07:37:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235932AbiEYHhU (ORCPT ); Wed, 25 May 2022 03:37:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47014 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231589AbiEYHhT (ORCPT ); Wed, 25 May 2022 03:37:19 -0400 Received: from smtpo49.interia.pl (smtpo49.interia.pl [217.74.67.49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 466505E143 for ; Wed, 25 May 2022 00:37:17 -0700 (PDT) X-Interia-R: Interia X-Interia-R-IP: 80.68.225.159 X-Interia-R-Helo: Received: from localhost (unknown [80.68.225.159]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by www.poczta.fm (INTERIA.PL) with ESMTPSA; Wed, 25 May 2022 09:37:15 +0200 (CEST) From: Slawomir Stepien To: linux-hwmon@vger.kernel.org, devicetree@vger.kernel.org Cc: jdelvare@suse.com, linux@roeck-us.net, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, przemyslaw.cencner@nokia.com, krzysztof.adamski@nokia.com, alexander.sverdlin@nokia.com, sst@poczta.fm, slawomir.stepien@nokia.com Subject: [PATCH 2/7] dt-bindings: hwmon: Allow specifying channels for lm90 Date: Wed, 25 May 2022 09:36:52 +0200 Message-Id: <20220525073657.573327-3-sst@poczta.fm> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220525073657.573327-1-sst@poczta.fm> References: <20220525073657.573327-1-sst@poczta.fm> MIME-Version: 1.0 X-Interia-Antivirus: OK DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=interia.pl; s=biztos; t=1653464236; bh=rEM5QmxdVxr970vyVi7zmu0TXbpADeblybnFq/v1NqI=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=BMqjlDK3hSIJpsi1AWbk6CKeyT6VyRz3T32UJbJrHVFPxgYoJDkWkw+aEk/OX5I1N CbTGSTaUo/mQ/G9x0sVO3O+ttZ8Ulo89lF5RrtBZl0ikd4sPg6qsX3NYoMD0yO3gOP Rmu1AsdB2kHGk46/APowCf0UgUzprSzgDOCY3RUk= Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org From: Slawomir Stepien Add binding description for temperature channels. Currently, support for label and temperature-offset-millicelsius is implemented. Signed-off-by: Slawomir Stepien Reviewed-by: Rob Herring --- .../bindings/hwmon/national,lm90.yaml | 129 ++++++++++++++++++ 1 file changed, 129 insertions(+) diff --git a/Documentation/devicetree/bindings/hwmon/national,lm90.yaml b/Documentation/devicetree/bindings/hwmon/national,lm90.yaml index 82fce96498c7..e1719839faf0 100644 --- a/Documentation/devicetree/bindings/hwmon/national,lm90.yaml +++ b/Documentation/devicetree/bindings/hwmon/national,lm90.yaml @@ -51,6 +51,12 @@ properties: "#thermal-sensor-cells": const: 1 + '#address-cells': + const: 1 + + '#size-cells': + const: 0 + vcc-supply: description: phandle to the regulator that provides the +VCC supply @@ -62,6 +68,29 @@ required: - compatible - reg +patternProperties: + "^channel@([0-2])$": + type: object + description: Represents channels of the device and their specific configuration. + + properties: + reg: + description: The channel number. 0 is local channel, 1-2 are remote channels. + items: + minimum: 0 + maximum: 2 + + label: + description: A descriptive name for this channel, like "ambient" or "psu". + + temperature-offset-millicelsius: + description: Temperature offset to be added to or subtracted from remote temperature measurements. + + required: + - reg + + additionalProperties: false + allOf: - if: not: @@ -78,6 +107,77 @@ allOf: properties: ti,extended-range-enable: false + - if: + properties: + compatible: + contains: + enum: + - dallas,max6646 + - dallas,max6647 + - dallas,max6649 + - dallas,max6657 + - dallas,max6658 + - dallas,max6659 + - dallas,max6695 + - dallas,max6696 + then: + patternProperties: + "^channel@([0-2])$": + properties: + temperature-offset-millicelsius: false + + - if: + properties: + compatible: + contains: + enum: + - adi,adt7461 + - adi,adt7461a + - adi,adt7481 + - onnn,nct1008 + then: + patternProperties: + "^channel@([0-2])$": + properties: + temperature-offset-millicelsius: + maximum: 127750 + + - if: + properties: + compatible: + contains: + enum: + - adi,adm1032 + - dallas,max6680 + - dallas,max6681 + - gmt,g781 + - national,lm86 + - national,lm89 + - national,lm90 + - national,lm99 + - nxp,sa56004 + - winbond,w83l771 + then: + patternProperties: + "^channel@([0-2])$": + properties: + temperature-offset-millicelsius: + maximum: 127875 + + - if: + properties: + compatible: + contains: + enum: + - ti,tmp451 + - ti,tmp461 + then: + patternProperties: + "^channel@([0-2])$": + properties: + temperature-offset-millicelsius: + maximum: 127937 + additionalProperties: false examples: @@ -96,3 +196,32 @@ examples: #thermal-sensor-cells = <1>; }; }; + - | + i2c { + #address-cells = <1>; + #size-cells = <0>; + + sensor@4c { + compatible = "adi,adt7481"; + reg = <0x4c>; + #address-cells = <1>; + #size-cells = <0>; + + channel@0 { + reg = <0x0>; + label = "local"; + }; + + channel@1 { + reg = <0x1>; + label = "front"; + temperature-offset-millicelsius = <4000>; + }; + + channel@2 { + reg = <0x2>; + label = "back"; + temperature-offset-millicelsius = <750>; + }; + }; + }; From patchwork Wed May 25 07:36:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Slawomir Stepien X-Patchwork-Id: 12860744 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DF785C433EF for ; Wed, 25 May 2022 07:37:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232374AbiEYHhW (ORCPT ); Wed, 25 May 2022 03:37:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47158 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242165AbiEYHhV (ORCPT ); Wed, 25 May 2022 03:37:21 -0400 Received: from smtpo52.interia.pl (smtpo52.interia.pl [217.74.67.52]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1B26A5EBDF for ; Wed, 25 May 2022 00:37:19 -0700 (PDT) X-Interia-R: Interia X-Interia-R-IP: 80.68.225.159 X-Interia-R-Helo: Received: from localhost (unknown [80.68.225.159]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by www.poczta.fm (INTERIA.PL) with ESMTPSA; Wed, 25 May 2022 09:37:16 +0200 (CEST) From: Slawomir Stepien To: linux-hwmon@vger.kernel.org, devicetree@vger.kernel.org Cc: jdelvare@suse.com, linux@roeck-us.net, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, przemyslaw.cencner@nokia.com, krzysztof.adamski@nokia.com, alexander.sverdlin@nokia.com, sst@poczta.fm, slawomir.stepien@nokia.com Subject: [PATCH 3/7] hwmon: (lm90) Add compatible entry for adt7481 Date: Wed, 25 May 2022 09:36:53 +0200 Message-Id: <20220525073657.573327-4-sst@poczta.fm> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220525073657.573327-1-sst@poczta.fm> References: <20220525073657.573327-1-sst@poczta.fm> MIME-Version: 1.0 X-Interia-Antivirus: OK DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=interia.pl; s=biztos; t=1653464238; bh=Cu9DSzf+D/f0WnNOpnyIQms3Cua41iKyM7IrQRi/yB0=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=XTA5AZZm4nFANIazvXou8SqaitE5sZFkPlVt2416qop4HRfXS8WnWF9PWJRQ0dzyg wbV++AShQBIMtMoVm3rgGLT3V4h+W6GtP2z1+IjzCLKNC2+8htSh0VOGmDIZoo2uft 5UCKtk7epsf0Pgh88Px7eLlkNhcwyvfMsuOT+VHg= Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org From: Slawomir Stepien This will allow binding the driver with the device from the device tree. Signed-off-by: Slawomir Stepien --- drivers/hwmon/lm90.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/hwmon/lm90.c b/drivers/hwmon/lm90.c index 4c25c9ffdfe9..02b211a4e571 100644 --- a/drivers/hwmon/lm90.c +++ b/drivers/hwmon/lm90.c @@ -294,6 +294,10 @@ static const struct of_device_id __maybe_unused lm90_of_match[] = { .compatible = "adi,adt7461a", .data = (void *)adt7461a }, + { + .compatible = "adi,adt7481", + .data = (void *)adt7481 + }, { .compatible = "gmt,g781", .data = (void *)g781 From patchwork Wed May 25 07:36:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Slawomir Stepien X-Patchwork-Id: 12860745 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1BD60C433FE for ; Wed, 25 May 2022 07:37:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231802AbiEYHhX (ORCPT ); Wed, 25 May 2022 03:37:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47214 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243538AbiEYHhW (ORCPT ); Wed, 25 May 2022 03:37:22 -0400 Received: from smtpo49.interia.pl (smtpo49.interia.pl [217.74.67.49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E8DE75EDF0 for ; Wed, 25 May 2022 00:37:20 -0700 (PDT) X-Interia-R: Interia X-Interia-R-IP: 80.68.225.159 X-Interia-R-Helo: Received: from localhost (unknown [80.68.225.159]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by www.poczta.fm (INTERIA.PL) with ESMTPSA; Wed, 25 May 2022 09:37:18 +0200 (CEST) From: Slawomir Stepien To: linux-hwmon@vger.kernel.org, devicetree@vger.kernel.org Cc: jdelvare@suse.com, linux@roeck-us.net, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, przemyslaw.cencner@nokia.com, krzysztof.adamski@nokia.com, alexander.sverdlin@nokia.com, sst@poczta.fm, slawomir.stepien@nokia.com Subject: [PATCH 4/7] hwmon: (lm90) Add support for 2nd remote channel's offset register Date: Wed, 25 May 2022 09:36:54 +0200 Message-Id: <20220525073657.573327-5-sst@poczta.fm> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220525073657.573327-1-sst@poczta.fm> References: <20220525073657.573327-1-sst@poczta.fm> MIME-Version: 1.0 X-Interia-Antivirus: OK DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=interia.pl; s=biztos; t=1653464239; bh=lIUoqrfFVuyZ61m0GdcFyykewfYCp1VxxxRrxNV3G24=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=thW2OJutq3+oROWBXzf0uMUbezYSCdUnRaQmAsH3+MnW6L0p9YBB/oBQ8k/mrg5YE ERHKFBwP6uO+1sOST9rS26KCTCF/O/rHFdxJBVGP+tc5vlcCoIJAo0dsaKmiwOXRFV M6rcR714mMZ99wX2NV5IR2RRVUsz3SVfNfozTg3w= Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org From: Slawomir Stepien The ADT7461 supports offset register for both remote channels it has. Both registers have the same bit width (resolution). In the code, this device has LM90_HAVE_TEMP3 and LM90_HAVE_OFFSET flags, but the support of second remote channel's offset is missing. Add that implementation. Signed-off-by: Slawomir Stepien --- drivers/hwmon/lm90.c | 37 ++++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/drivers/hwmon/lm90.c b/drivers/hwmon/lm90.c index 02b211a4e571..d226f1dea2ba 100644 --- a/drivers/hwmon/lm90.c +++ b/drivers/hwmon/lm90.c @@ -153,6 +153,8 @@ enum chips { adm1023, adm1032, adt7461, adt7461a, adt7481, #define LM90_REG_REMOTE_TEMPL 0x10 #define LM90_REG_REMOTE_OFFSH 0x11 #define LM90_REG_REMOTE_OFFSL 0x12 +#define LM90_REG_REMOTE2_OFFSH 0x34 +#define LM90_REG_REMOTE2_OFFSL 0x35 #define LM90_REG_REMOTE_HIGHH 0x07 #define LM90_REG_REMOTE_HIGHL 0x13 #define LM90_REG_REMOTE_LOWH 0x08 @@ -669,6 +671,7 @@ enum lm90_temp_reg_index { REMOTE2_TEMP, /* max6695/96 only */ REMOTE2_LOW, /* max6695/96 only */ REMOTE2_HIGH, /* max6695/96 only */ + REMOTE2_OFFSET, TEMP_REG_NUM }; @@ -1024,6 +1027,14 @@ static int lm90_update_limits(struct device *dev) return val; data->temp[REMOTE2_HIGH] = val << 8; + if (data->flags & LM90_HAVE_OFFSET) { + val = lm90_read16(client, LM90_REG_REMOTE2_OFFSH, + LM90_REG_REMOTE2_OFFSL, false); + if (val < 0) + return val; + data->temp[REMOTE2_OFFSET] = val; + } + lm90_select_remote_channel(data, false); } @@ -1294,6 +1305,7 @@ static int lm90_temp_get_resolution(struct lm90_data *data, int index) return data->resolution; return 8; case REMOTE_OFFSET: + case REMOTE2_OFFSET: case REMOTE2_TEMP: return data->resolution; case LOCAL_TEMP: @@ -1515,8 +1527,13 @@ static int lm90_temp_read(struct device *dev, u32 attr, int channel, long *val) *val = lm90_get_temphyst(data, lm90_temp_emerg_index[channel], channel); break; case hwmon_temp_offset: - *val = lm90_temp_from_reg(0, data->temp[REMOTE_OFFSET], - lm90_temp_get_resolution(data, REMOTE_OFFSET)); + /* Both offset registers have the same resolution */ + int res = lm90_temp_get_resolution(data, REMOTE_OFFSET); + + if (channel == 1) + *val = lm90_temp_from_reg(0, data->temp[REMOTE_OFFSET], res); + else + *val = lm90_temp_from_reg(0, data->temp[REMOTE2_OFFSET], res); break; default: return -EOPNOTSUPP; @@ -1556,11 +1573,19 @@ static int lm90_temp_write(struct device *dev, u32 attr, int channel, long val) channel, val); break; case hwmon_temp_offset: + /* Both offset registers have the same resolution */ val = lm90_temp_to_reg(0, val, lm90_temp_get_resolution(data, REMOTE_OFFSET)); - data->temp[REMOTE_OFFSET] = val; - err = lm90_write16(data->client, LM90_REG_REMOTE_OFFSH, - LM90_REG_REMOTE_OFFSL, val); + + if (channel == 1) { + data->temp[REMOTE_OFFSET] = val; + err = lm90_write16(data->client, LM90_REG_REMOTE_OFFSH, + LM90_REG_REMOTE_OFFSL, val); + } else { + data->temp[REMOTE2_OFFSET] = val; + err = lm90_write16(data->client, LM90_REG_REMOTE2_OFFSH, + LM90_REG_REMOTE2_OFFSL, val); + } break; default: err = -EOPNOTSUPP; @@ -2733,6 +2758,8 @@ static int lm90_probe(struct i2c_client *client) } if (data->flags & LM90_HAVE_EMERGENCY_ALARM) data->channel_config[2] |= HWMON_T_EMERGENCY_ALARM; + if (data->flags & LM90_HAVE_OFFSET) + data->channel_config[2] |= HWMON_T_OFFSET; } data->faultqueue_mask = lm90_params[data->kind].faultqueue_mask; From patchwork Wed May 25 07:36:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Slawomir Stepien X-Patchwork-Id: 12860746 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D88C8C433EF for ; Wed, 25 May 2022 07:37:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244356AbiEYHha (ORCPT ); Wed, 25 May 2022 03:37:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47434 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244337AbiEYHhY (ORCPT ); Wed, 25 May 2022 03:37:24 -0400 Received: from smtpo68.interia.pl (smtpo68.interia.pl [217.74.67.68]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 661885F8E8 for ; Wed, 25 May 2022 00:37:21 -0700 (PDT) Received: from localhost (unknown [80.68.225.159]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by www.poczta.fm (INTERIA.PL) with ESMTPSA; Wed, 25 May 2022 09:37:19 +0200 (CEST) From: Slawomir Stepien To: linux-hwmon@vger.kernel.org, devicetree@vger.kernel.org Cc: jdelvare@suse.com, linux@roeck-us.net, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, przemyslaw.cencner@nokia.com, krzysztof.adamski@nokia.com, alexander.sverdlin@nokia.com, sst@poczta.fm, slawomir.stepien@nokia.com Subject: [PATCH 5/7] hwmon: (lm90) Define maximum number of channels that are supported Date: Wed, 25 May 2022 09:36:55 +0200 Message-Id: <20220525073657.573327-6-sst@poczta.fm> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220525073657.573327-1-sst@poczta.fm> References: <20220525073657.573327-1-sst@poczta.fm> MIME-Version: 1.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=interia.pl; s=biztos; t=1653464240; bh=WpSCCaXVgV8guUzHhXFxPXtohySKH0oEJGvpMDhhHbE=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=kRRzJ+6+exXQ9Znvc95NwRMff6Ss0GZYCLU2IGLTn1I/3oqI2/THbL8DlJuUvaYw2 AhMB8GucSWVFjofBWk67FV1zLLjFVeVzattp4KYJVKKXi+K3I75xdccoDTnirEr2Hu SWVcflYCv0KqsCO9U/WtsBNSmLLFxScKcOVrXnew= Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org From: Slawomir Stepien Use this define in all the places where literal '3' was used in this context. Signed-off-by: Slawomir Stepien --- drivers/hwmon/lm90.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/drivers/hwmon/lm90.c b/drivers/hwmon/lm90.c index d226f1dea2ba..82b020ffd490 100644 --- a/drivers/hwmon/lm90.c +++ b/drivers/hwmon/lm90.c @@ -110,6 +110,9 @@ #include #include +/* The maximum number of channels currently supported */ +#define MAX_CHANNELS 3 + /* * Addresses to scan * Address is fully defined internally and cannot be changed except for @@ -684,7 +687,7 @@ struct lm90_data { struct i2c_client *client; struct device *hwmon_dev; u32 chip_config[2]; - u32 channel_config[4]; + u32 channel_config[MAX_CHANNELS + 1]; struct hwmon_channel_info chip_info; struct hwmon_channel_info temp_info; const struct hwmon_channel_info *info[3]; @@ -1436,32 +1439,32 @@ static int lm90_set_temphyst(struct lm90_data *data, long val) return lm90_write_reg(data->client, LM90_REG_TCRIT_HYST, data->temp_hyst); } -static const u8 lm90_temp_index[3] = { +static const u8 lm90_temp_index[MAX_CHANNELS] = { LOCAL_TEMP, REMOTE_TEMP, REMOTE2_TEMP }; -static const u8 lm90_temp_min_index[3] = { +static const u8 lm90_temp_min_index[MAX_CHANNELS] = { LOCAL_LOW, REMOTE_LOW, REMOTE2_LOW }; -static const u8 lm90_temp_max_index[3] = { +static const u8 lm90_temp_max_index[MAX_CHANNELS] = { LOCAL_HIGH, REMOTE_HIGH, REMOTE2_HIGH }; -static const u8 lm90_temp_crit_index[3] = { +static const u8 lm90_temp_crit_index[MAX_CHANNELS] = { LOCAL_CRIT, REMOTE_CRIT, REMOTE2_CRIT }; -static const u8 lm90_temp_emerg_index[3] = { +static const u8 lm90_temp_emerg_index[MAX_CHANNELS] = { LOCAL_EMERG, REMOTE_EMERG, REMOTE2_EMERG }; -static const u16 lm90_min_alarm_bits[3] = { BIT(5), BIT(3), BIT(11) }; -static const u16 lm90_max_alarm_bits[3] = { BIT(6), BIT(4), BIT(12) }; -static const u16 lm90_crit_alarm_bits[3] = { BIT(0), BIT(1), BIT(9) }; -static const u16 lm90_crit_alarm_bits_swapped[3] = { BIT(1), BIT(0), BIT(9) }; -static const u16 lm90_emergency_alarm_bits[3] = { BIT(15), BIT(13), BIT(14) }; -static const u16 lm90_fault_bits[3] = { BIT(0), BIT(2), BIT(10) }; +static const u16 lm90_min_alarm_bits[MAX_CHANNELS] = { BIT(5), BIT(3), BIT(11) }; +static const u16 lm90_max_alarm_bits[MAX_CHANNELS] = { BIT(6), BIT(4), BIT(12) }; +static const u16 lm90_crit_alarm_bits[MAX_CHANNELS] = { BIT(0), BIT(1), BIT(9) }; +static const u16 lm90_crit_alarm_bits_swapped[MAX_CHANNELS] = { BIT(1), BIT(0), BIT(9) }; +static const u16 lm90_emergency_alarm_bits[MAX_CHANNELS] = { BIT(15), BIT(13), BIT(14) }; +static const u16 lm90_fault_bits[MAX_CHANNELS] = { BIT(0), BIT(2), BIT(10) }; static int lm90_temp_read(struct device *dev, u32 attr, int channel, long *val) { From patchwork Wed May 25 07:36:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Slawomir Stepien X-Patchwork-Id: 12860747 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5B4F7C4332F for ; Wed, 25 May 2022 07:37:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243462AbiEYHhd (ORCPT ); Wed, 25 May 2022 03:37:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47480 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244349AbiEYHhZ (ORCPT ); Wed, 25 May 2022 03:37:25 -0400 Received: from smtpo52.interia.pl (smtpo52.interia.pl [217.74.67.52]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3F3D360042 for ; Wed, 25 May 2022 00:37:22 -0700 (PDT) X-Interia-R: Interia X-Interia-R-IP: 80.68.225.159 X-Interia-R-Helo: Received: from localhost (unknown [80.68.225.159]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by www.poczta.fm (INTERIA.PL) with ESMTPSA; Wed, 25 May 2022 09:37:20 +0200 (CEST) From: Slawomir Stepien To: linux-hwmon@vger.kernel.org, devicetree@vger.kernel.org Cc: jdelvare@suse.com, linux@roeck-us.net, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, przemyslaw.cencner@nokia.com, krzysztof.adamski@nokia.com, alexander.sverdlin@nokia.com, sst@poczta.fm, slawomir.stepien@nokia.com Subject: [PATCH 6/7] hwmon: (lm90) Read the channel's label from device-tree Date: Wed, 25 May 2022 09:36:56 +0200 Message-Id: <20220525073657.573327-7-sst@poczta.fm> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220525073657.573327-1-sst@poczta.fm> References: <20220525073657.573327-1-sst@poczta.fm> MIME-Version: 1.0 X-Interia-Antivirus: OK DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=interia.pl; s=biztos; t=1653464241; bh=bUaqc8FAsvXQMoHQH74ICXcKexdammv+Fav5Lo8E4iM=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=ts0OVhEKlIe55LCmU61pClpSc2aGif2H2ntajaHKtEoPOFrVTqNRVVq/pUQ6qEiyc hEjUUNQ4aIHsvrTbblBJaq5j8XXpFEb/UFD3gTEiEPjhvdcCjUGS+h5I8/jI4e0+DI 7eSvk8kleQDzNlyHIMblN1ngke4ndagyYrAHNKpU= Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org From: Slawomir Stepien Try to read the channel's label from device-tree. Having label in device-tree node is not mandatory. Signed-off-by: Slawomir Stepien --- drivers/hwmon/lm90.c | 72 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/drivers/hwmon/lm90.c b/drivers/hwmon/lm90.c index 82b020ffd490..3837c4ab5833 100644 --- a/drivers/hwmon/lm90.c +++ b/drivers/hwmon/lm90.c @@ -688,6 +688,7 @@ struct lm90_data { struct device *hwmon_dev; u32 chip_config[2]; u32 channel_config[MAX_CHANNELS + 1]; + const char *channel_label[MAX_CHANNELS]; struct hwmon_channel_info chip_info; struct hwmon_channel_info temp_info; const struct hwmon_channel_info *info[3]; @@ -1610,6 +1611,7 @@ static umode_t lm90_temp_is_visible(const void *data, u32 attr, int channel) case hwmon_temp_emergency_alarm: case hwmon_temp_emergency_hyst: case hwmon_temp_fault: + case hwmon_temp_label: return 0444; case hwmon_temp_min: case hwmon_temp_max: @@ -1729,6 +1731,16 @@ static int lm90_read(struct device *dev, enum hwmon_sensor_types type, } } +static int lm90_read_string(struct device *dev, enum hwmon_sensor_types type, + u32 attr, int channel, const char **str) +{ + struct lm90_data *data = dev_get_drvdata(dev); + + *str = data->channel_label[channel]; + + return 0; +} + static int lm90_write(struct device *dev, enum hwmon_sensor_types type, u32 attr, int channel, long val) { @@ -2634,10 +2646,63 @@ static void lm90_regulator_disable(void *regulator) regulator_disable(regulator); } +static int lm90_probe_channel_from_dt(struct i2c_client *client, + struct device_node *child, + struct lm90_data *data) +{ + u32 id; + int err; + struct device *dev = &client->dev; + + err = of_property_read_u32(child, "reg", &id); + if (err) { + dev_err(dev, "missing reg property of %pOFn\n", child); + return err; + } + + if (id >= MAX_CHANNELS) { + dev_err(dev, "invalid reg property value %d in %pOFn\n", id, child); + return -EINVAL; + } + + err = of_property_read_string(child, "label", &data->channel_label[id]); + if (err == -ENODATA || err == -EILSEQ) { + dev_err(dev, "invalid label property in %pOFn\n", child); + return err; + } + + if (data->channel_label[id]) + data->channel_config[id] |= HWMON_T_LABEL; + + return 0; +} + +static int lm90_parse_dt_channel_info(struct i2c_client *client, + struct lm90_data *data) +{ + int err; + struct device_node *child; + struct device *dev = &client->dev; + const struct device_node *np = dev->of_node; + + for_each_child_of_node(np, child) { + if (strcmp(child->name, "channel")) + continue; + + err = lm90_probe_channel_from_dt(client, child, data); + if (err) { + of_node_put(child); + return err; + } + } + + return 0; +} static const struct hwmon_ops lm90_ops = { .is_visible = lm90_is_visible, .read = lm90_read, + .read_string = lm90_read_string, .write = lm90_write, }; @@ -2775,6 +2840,13 @@ static int lm90_probe(struct i2c_client *client) /* Set maximum conversion rate */ data->max_convrate = lm90_params[data->kind].max_convrate; + /* Parse device-tree channel information */ + if (client->dev.of_node) { + err = lm90_parse_dt_channel_info(client, data); + if (err) + return err; + } + /* Initialize the LM90 chip */ err = lm90_init_client(client, data); if (err < 0) { From patchwork Wed May 25 07:36:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Slawomir Stepien X-Patchwork-Id: 12860748 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A4774C433F5 for ; Wed, 25 May 2022 07:37:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243415AbiEYHhi (ORCPT ); Wed, 25 May 2022 03:37:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47664 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243612AbiEYHh1 (ORCPT ); Wed, 25 May 2022 03:37:27 -0400 Received: from smtpo52.interia.pl (smtpo52.interia.pl [217.74.67.52]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A7D6606CD for ; Wed, 25 May 2022 00:37:24 -0700 (PDT) X-Interia-R: Interia X-Interia-R-IP: 80.68.225.159 X-Interia-R-Helo: Received: from localhost (unknown [80.68.225.159]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by www.poczta.fm (INTERIA.PL) with ESMTPSA; Wed, 25 May 2022 09:37:21 +0200 (CEST) From: Slawomir Stepien To: linux-hwmon@vger.kernel.org, devicetree@vger.kernel.org Cc: jdelvare@suse.com, linux@roeck-us.net, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, przemyslaw.cencner@nokia.com, krzysztof.adamski@nokia.com, alexander.sverdlin@nokia.com, sst@poczta.fm, slawomir.stepien@nokia.com Subject: [PATCH 7/7] hwmon: (lm90) Read the channel's temperature offset from device-tree Date: Wed, 25 May 2022 09:36:57 +0200 Message-Id: <20220525073657.573327-8-sst@poczta.fm> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220525073657.573327-1-sst@poczta.fm> References: <20220525073657.573327-1-sst@poczta.fm> MIME-Version: 1.0 X-Interia-Antivirus: OK DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=interia.pl; s=biztos; t=1653464242; bh=WPeFse8j/Tn4aLsNvbD6wQT1rqQuT88dj0zMJFSIR/w=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=lpk9BnTKhcfeu6Srcb8OPYGsTKMo+3rKz/ykPBYTzY0ioyKMbRTkSX3WaJFEh4jz9 EzavTxhtiw5hJeEeDEfNrHHKUTjziRqYzggFMoy05qr9o+U0/aAz02WhOs/Pkb1ol0 txQLs7Ic4Czr6Yng6f/JOgFX+/spr0c94Tw12tiQ= Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org From: Slawomir Stepien Try to read the channel's temperature offset from device-tree. Having offset in device-tree node is not mandatory. The offset can only be set for remote channels. Signed-off-by: Slawomir Stepien --- drivers/hwmon/lm90.c | 48 ++++++++++++++++++++++++++++++++------------ 1 file changed, 35 insertions(+), 13 deletions(-) diff --git a/drivers/hwmon/lm90.c b/drivers/hwmon/lm90.c index 3837c4ab5833..12e8e874f1b9 100644 --- a/drivers/hwmon/lm90.c +++ b/drivers/hwmon/lm90.c @@ -1440,6 +1440,24 @@ static int lm90_set_temphyst(struct lm90_data *data, long val) return lm90_write_reg(data->client, LM90_REG_TCRIT_HYST, data->temp_hyst); } +static int lm90_set_temp_offset(struct lm90_data *data, int channel, long val) +{ + /* Both offset registers have the same resolution */ + int res = lm90_temp_get_resolution(data, REMOTE_OFFSET); + + val = lm90_temp_to_reg(0, val, res); + + if (channel == 1) { + data->temp[REMOTE_OFFSET] = val; + return lm90_write16(data->client, LM90_REG_REMOTE_OFFSH, + LM90_REG_REMOTE_OFFSL, val); + } + + data->temp[REMOTE2_OFFSET] = val; + return lm90_write16(data->client, LM90_REG_REMOTE2_OFFSH, + LM90_REG_REMOTE2_OFFSL, val); +} + static const u8 lm90_temp_index[MAX_CHANNELS] = { LOCAL_TEMP, REMOTE_TEMP, REMOTE2_TEMP }; @@ -1577,19 +1595,7 @@ static int lm90_temp_write(struct device *dev, u32 attr, int channel, long val) channel, val); break; case hwmon_temp_offset: - /* Both offset registers have the same resolution */ - val = lm90_temp_to_reg(0, val, - lm90_temp_get_resolution(data, REMOTE_OFFSET)); - - if (channel == 1) { - data->temp[REMOTE_OFFSET] = val; - err = lm90_write16(data->client, LM90_REG_REMOTE_OFFSH, - LM90_REG_REMOTE_OFFSL, val); - } else { - data->temp[REMOTE2_OFFSET] = val; - err = lm90_write16(data->client, LM90_REG_REMOTE2_OFFSH, - LM90_REG_REMOTE2_OFFSL, val); - } + err = lm90_set_temp_offset(data, channel, val); break; default: err = -EOPNOTSUPP; @@ -2651,6 +2657,7 @@ static int lm90_probe_channel_from_dt(struct i2c_client *client, struct lm90_data *data) { u32 id; + s32 val; int err; struct device *dev = &client->dev; @@ -2674,6 +2681,21 @@ static int lm90_probe_channel_from_dt(struct i2c_client *client, if (data->channel_label[id]) data->channel_config[id] |= HWMON_T_LABEL; + err = of_property_read_s32(child, "temperature-offset-millicelsius", &val); + if (!err) { + if (id == 0) { + dev_err(dev, "offset can't be set for internal channel\n"); + return -EINVAL; + } + + err = lm90_set_temp_offset(data, id, val); + if (err) { + dev_err(dev, "can't set offset %d for channel %d (%d)\n", + val, id, err); + return err; + } + } + return 0; }