From patchwork Fri May 20 09:32:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Slawomir Stepien X-Patchwork-Id: 12856588 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 673A6C433EF for ; Fri, 20 May 2022 09:53:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241878AbiETJxf (ORCPT ); Fri, 20 May 2022 05:53:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54040 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347922AbiETJxe (ORCPT ); Fri, 20 May 2022 05:53:34 -0400 X-Greylist: delayed 120 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Fri, 20 May 2022 02:53:32 PDT Received: from smtpo62.interia.pl (smtpo62.interia.pl [217.74.67.62]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C8B8D14AC9B for ; Fri, 20 May 2022 02:53:32 -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; Fri, 20 May 2022 11:51:43 +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, Slawomir Stepien , Slawomir Stepien Subject: [PATCH 1/8] dt-bindings: hwmon: Add support for ADT7481 in lm90 Date: Fri, 20 May 2022 11:32:37 +0200 Message-Id: <20220520093243.2523749-2-sst@poczta.fm> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220520093243.2523749-1-sst@poczta.fm> References: <20220520093243.2523749-1-sst@poczta.fm> MIME-Version: 1.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=interia.pl; s=biztos; t=1653040304; bh=rZ3VasfHokP8cmTBuMPcZ2asdVA79OQ/FHbd5JxSj8M=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=T2AwcBbZeb+rHS0/V115GsrTxwtDKFcFUnljlYQN9QII9SbhRvRTDHA6ncAC8AIhk oiht2d2KM0/5RK72m8Qg/zEal2MK5RC7lstezGR7nBtgZBKnduLndaNevH5OSCs5T5 vfLmXVODj8ncw2506JjBDuHmyGGC1CjMSAG4lLDE= Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org From: Slawomir Stepien The ADT7481 sensor is quite similar to MAX6696 so we can reuse a lot of code from lm90.c driver. Signed-off-by: Slawomir Stepien Acked-by: Krzysztof Kozlowski --- Documentation/devicetree/bindings/hwmon/national,lm90.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/Documentation/devicetree/bindings/hwmon/national,lm90.yaml b/Documentation/devicetree/bindings/hwmon/national,lm90.yaml index 30db92977937..92d97ebefaae 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 From patchwork Fri May 20 09:32:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Slawomir Stepien X-Patchwork-Id: 12856592 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 17741C433F5 for ; Fri, 20 May 2022 09:54:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346778AbiETJyS (ORCPT ); Fri, 20 May 2022 05:54:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54374 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347972AbiETJyP (ORCPT ); Fri, 20 May 2022 05:54:15 -0400 Received: from smtpo49.interia.pl (smtpo49.interia.pl [217.74.67.49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E34A714ACA0 for ; Fri, 20 May 2022 02:54:12 -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; Fri, 20 May 2022 11:51:44 +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, Slawomir Stepien , Slawomir Stepien Subject: [PATCH 2/8] dt-bindings: hwmon: Add 'extended-range-enable' property support in lm90 Date: Fri, 20 May 2022 11:32:38 +0200 Message-Id: <20220520093243.2523749-3-sst@poczta.fm> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220520093243.2523749-1-sst@poczta.fm> References: <20220520093243.2523749-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=1653040306; bh=22cLxtKoijqNk6rKLajnHx+TImeEoOc7fC+XaF4oOGY=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=OaFPbgLWGjxNysMm6Eb1i3bs6Wok4figSFmMJk+RZozWqA+ZGE/6NqDOhR7eJQ417 m6Df8kqu5gI0XnChXJsY3BoAC5fIxGyIZR6WiHYtWUH88jpyF4dCrH4INqyvl+JHbg iXK4GtsrdJ2o66jE6BU+74eBIDmZsCF8TyW8/sq4= Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org From: Slawomir Stepien Using the 'extended-range-enable' prop will enable the extended measurement range for device (if supported by the device). Signed-off-by: Slawomir Stepien --- Documentation/devicetree/bindings/hwmon/national,lm90.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Documentation/devicetree/bindings/hwmon/national,lm90.yaml b/Documentation/devicetree/bindings/hwmon/national,lm90.yaml index 92d97ebefaae..066c02541fcf 100644 --- a/Documentation/devicetree/bindings/hwmon/national,lm90.yaml +++ b/Documentation/devicetree/bindings/hwmon/national,lm90.yaml @@ -53,6 +53,9 @@ properties: vcc-supply: description: phandle to the regulator that provides the +VCC supply + extended-range-enable: + description: enables the extended temperature range measurement (if supported by device). + required: - compatible - reg From patchwork Fri May 20 09:32:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Slawomir Stepien X-Patchwork-Id: 12856589 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 D6426C433F5 for ; Fri, 20 May 2022 09:54:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230091AbiETJyQ (ORCPT ); Fri, 20 May 2022 05:54:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54376 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347970AbiETJyP (ORCPT ); Fri, 20 May 2022 05:54:15 -0400 Received: from smtpo49.interia.pl (smtpo49.interia.pl [217.74.67.49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E435F14AF5B for ; Fri, 20 May 2022 02:54:12 -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; Fri, 20 May 2022 11:51:46 +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, Slawomir Stepien , Slawomir Stepien Subject: [PATCH 3/8] dt-bindings: hwmon: Allow specifying channels for lm90 Date: Fri, 20 May 2022 11:32:39 +0200 Message-Id: <20220520093243.2523749-4-sst@poczta.fm> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220520093243.2523749-1-sst@poczta.fm> References: <20220520093243.2523749-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=1653040307; bh=EGkm4dZ2OZYas/b+5k8K/CiGIywj9eMvu3WdswLRnrg=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=tFnKkwf9i3AB9eytyYRwt0W06vX7VQn2Z7IlTPN9997l5nxUc94p7JoDelgl0mVuh XBfNjmXoHJ5XkiyettrGRXK1zsi3GAhDnpTWDnGUcr+Nb3RZsgzVAjtF5oZLqIEqXv DoqANY9xwoJGYIYLiXvCHjrmW4E/MbfM3B4jEj1Y= 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 offset is implemented. Signed-off-by: Slawomir Stepien --- .../bindings/hwmon/national,lm90.yaml | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/Documentation/devicetree/bindings/hwmon/national,lm90.yaml b/Documentation/devicetree/bindings/hwmon/national,lm90.yaml index 066c02541fcf..9a5aa78d4db1 100644 --- a/Documentation/devicetree/bindings/hwmon/national,lm90.yaml +++ b/Documentation/devicetree/bindings/hwmon/national,lm90.yaml @@ -62,6 +62,37 @@ required: additionalProperties: false +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". + + offset: + description: | + The value (millidegree Celsius) to be programmed in the channel specific offset register + (if supported by device). + For remote channels only. + $ref: /schemas/types.yaml#/definitions/int32 + default: 0 + + required: + - reg + + additionalProperties: false + examples: - | #include @@ -76,5 +107,13 @@ examples: vcc-supply = <&palmas_ldo6_reg>; interrupts = <4 IRQ_TYPE_LEVEL_LOW>; #thermal-sensor-cells = <1>; + #address-cells = <1>; + #size-cells = <0>; + + channel@0 { + reg = <0x0>; + label = "internal"; + offset = <1000>; + }; }; }; From patchwork Fri May 20 09:32:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Slawomir Stepien X-Patchwork-Id: 12856595 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 8F141C433EF for ; Fri, 20 May 2022 09:54:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347989AbiETJy5 (ORCPT ); Fri, 20 May 2022 05:54:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54888 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348015AbiETJyy (ORCPT ); Fri, 20 May 2022 05:54:54 -0400 Received: from smtpo52.interia.pl (smtpo52.interia.pl [217.74.67.52]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6A00B14B65B for ; Fri, 20 May 2022 02:54:52 -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; Fri, 20 May 2022 11:51:47 +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, Slawomir Stepien , Slawomir Stepien Subject: [PATCH 4/8] hwmon: (lm90) add support for ADT7481 Date: Fri, 20 May 2022 11:32:40 +0200 Message-Id: <20220520093243.2523749-5-sst@poczta.fm> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220520093243.2523749-1-sst@poczta.fm> References: <20220520093243.2523749-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=1653040311; bh=6J1bs99vTx7LHEUGI178VDCZdAtohxbVRtrKWQBZXXk=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=fmZ95VS8X9Z79BmmlRs1UnVRP0wONR9iUYDqa+B5u+ljRaasaSWF5Xfq/nVyVy4Ja Hvw/KKReCbcx47UTE79rX4OWbjVU/OVNXSV/o6MyrVHZ23iDrTnXEH9Y0QjiCNi0R/ CpsFeY+9oXlp39wn5bRy328XDoMKBnPkxAuzn4VE= Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org From: Slawomir Stepien The ADT7481 is a 3-channel digital thermometer and under/over temperature alarm, intended for use in PCs and thermal management systems. From driver point-of-view, it is quite similar to MAX6696 so a lot of code for MAX6696 is reused. Signed-off-by: Slawomir Stepien --- Documentation/hwmon/lm90.rst | 12 +++- drivers/hwmon/Kconfig | 15 +++-- drivers/hwmon/lm90.c | 114 ++++++++++++++++++++++++++--------- 3 files changed, 105 insertions(+), 36 deletions(-) diff --git a/Documentation/hwmon/lm90.rst b/Documentation/hwmon/lm90.rst index 05391fb4042d..2e67d602e275 100644 --- a/Documentation/hwmon/lm90.rst +++ b/Documentation/hwmon/lm90.rst @@ -73,6 +73,16 @@ Supported chips: https://www.onsemi.com/PowerSolutions/product.do?id=ADT7461A + * Analog Devices ADT7481 + + Prefix: 'adt7481' + + Addresses scanned: I2C 0x4c and 0x4b + + Datasheet: Publicly available at the ON Semiconductor website + + http://www.onsemi.com/PowerSolutions/product.do?id=ADT7481 + * ON Semiconductor NCT1008 Prefix: 'nct1008' @@ -319,7 +329,7 @@ ADM1032: * ALERT is triggered by open remote sensor. * SMBus PEC support for Write Byte and Receive Byte transactions. -ADT7461, ADT7461A, NCT1008: +ADT7461, ADT7461A, ADT7481, NCT1008: * Extended temperature range (breaks compatibility) * Lower resolution for remote temperature diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig index f2b038fa3b84..9586b610b5d8 100644 --- a/drivers/hwmon/Kconfig +++ b/drivers/hwmon/Kconfig @@ -1339,13 +1339,16 @@ config SENSORS_LM90 tristate "National Semiconductor LM90 and compatibles" depends on I2C help - If you say yes here you get support for National Semiconductor LM90, - LM86, LM89 and LM99, Analog Devices ADM1032, ADT7461, and ADT7461A, + If you say yes here you will get support for sensor chips: + National Semiconductor LM90, LM86, LM89 and LM99, + Analog Devices ADM1032, ADT7461, ADT7461A and ADT7481, Maxim MAX6646, MAX6647, MAX6648, MAX6649, MAX6654, MAX6657, MAX6658, - MAX6659, MAX6680, MAX6681, MAX6692, MAX6695, MAX6696, - ON Semiconductor NCT1008, Winbond/Nuvoton W83L771W/G/AWG/ASG, - Philips SA56004, GMT G781, Texas Instruments TMP451 and TMP461 - sensor chips. + MAX6659, MAX6680, MAX6681, MAX6692, MAX6695 and MAX6696, + ON Semiconductor NCT1008, + Winbond/Nuvoton W83L771W/G/AWG/ASG, + Philips SA56004, + GMT G781, + Texas Instruments TMP451 and TMP461. This driver can also be built as a module. If so, the module will be called lm90. diff --git a/drivers/hwmon/lm90.c b/drivers/hwmon/lm90.c index 1c9493c70813..00fd5734f217 100644 --- a/drivers/hwmon/lm90.c +++ b/drivers/hwmon/lm90.c @@ -59,10 +59,10 @@ * chips, but support three temperature sensors instead of two. MAX6695 * and MAX6696 only differ in the pinout so they can be treated identically. * - * This driver also supports ADT7461 and ADT7461A from Analog Devices as well as - * NCT1008 from ON Semiconductor. The chips are supported in both compatibility - * and extended mode. They are mostly compatible with LM90 except for a data - * format difference for the temperature value registers. + * This driver also supports ADT7461, ADT7461A and ADT7481 from Analog Devices + * as well as NCT1008 from ON Semiconductor. The chips are supported in both + * compatibility and extended mode. They are mostly compatible with LM90 except + * for a data format difference for the temperature value registers. * * This driver also supports the SA56004 from Philips. This device is * pin-compatible with the LM86, the ED/EDP parts are also address-compatible. @@ -106,14 +106,16 @@ * MAX6654, MAX6680, and MAX6681 can have address 0x18, 0x19, 0x1a, 0x29, * 0x2a, 0x2b, 0x4c, 0x4d or 0x4e. * SA56004 can have address 0x48 through 0x4F. + * ADT7481 can have address 0x4c or 0x4b (ADT7481-1). */ static const unsigned short normal_i2c[] = { 0x18, 0x19, 0x1a, 0x29, 0x2a, 0x2b, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, I2C_CLIENT_END }; -enum chips { lm90, adm1032, lm99, lm86, max6657, max6659, adt7461, max6680, - max6646, w83l771, max6696, sa56004, g781, tmp451, tmp461, max6654 }; +enum chips { lm90, adm1032, lm99, lm86, max6657, max6659, adt7461, adt7481, + max6680, max6646, w83l771, max6696, sa56004, g781, tmp451, tmp461, + max6654 }; /* * The LM90 registers @@ -141,6 +143,10 @@ enum chips { lm90, adm1032, lm99, lm86, max6657, max6659, adt7461, max6680, #define LM90_REG_W_REMOTE_OFFSH 0x11 #define LM90_REG_R_REMOTE_OFFSL 0x12 #define LM90_REG_W_REMOTE_OFFSL 0x12 +#define LM90_REG_R_REMOTE2_OFFSH 0x34 +#define LM90_REG_W_REMOTE2_OFFSH 0x34 +#define LM90_REG_R_REMOTE2_OFFSL 0x35 +#define LM90_REG_W_REMOTE2_OFFSL 0x35 #define LM90_REG_R_REMOTE_HIGHH 0x07 #define LM90_REG_W_REMOTE_HIGHH 0x0D #define LM90_REG_R_REMOTE_HIGHL 0x13 @@ -154,6 +160,10 @@ enum chips { lm90, adm1032, lm99, lm86, max6657, max6659, adt7461, max6680, #define LM90_REG_R_TCRIT_HYST 0x21 #define LM90_REG_W_TCRIT_HYST 0x21 +/* ADT7481 registers */ + +#define ADT7481_REG_R_STATUS2 0x23 + /* MAX6646/6647/6649/6654/6657/6658/6659/6695/6696 registers */ #define MAX6657_REG_R_LOCAL_TEMPL 0x11 @@ -202,6 +212,7 @@ enum chips { lm90, adm1032, lm99, lm86, max6657, max6659, adt7461, max6680, #define LM90_STATUS_LHIGH (1 << 6) /* local high temp limit tripped */ #define LM90_STATUS_BUSY (1 << 7) /* conversion is ongoing */ +/* Note: bits 1, 2, 3 and 4 are used by ADT7481 too */ #define MAX6696_STATUS2_R2THRM (1 << 1) /* remote2 THERM limit tripped */ #define MAX6696_STATUS2_R2OPEN (1 << 2) /* remote2 is an open circuit */ #define MAX6696_STATUS2_R2LOW (1 << 3) /* remote2 low temp limit tripped */ @@ -218,6 +229,7 @@ static const struct i2c_device_id lm90_id[] = { { "adm1032", adm1032 }, { "adt7461", adt7461 }, { "adt7461a", adt7461 }, + { "adt7481", adt7481 }, { "g781", g781 }, { "lm90", lm90 }, { "lm86", lm86 }, @@ -256,6 +268,10 @@ static const struct of_device_id __maybe_unused lm90_of_match[] = { .compatible = "adi,adt7461a", .data = (void *)adt7461 }, + { + .compatible = "adi,adt7481", + .data = (void *)adt7481 + }, { .compatible = "gmt,g781", .data = (void *)g781 @@ -353,6 +369,7 @@ struct lm90_params { /* Upper 8 bits for max6695/96 */ u8 max_convrate; /* Maximum conversion rate register value */ u8 reg_local_ext; /* Extended local temp register (optional) */ + u8 reg_status2; /* Second status register (optional) */ }; static const struct lm90_params lm90_params[] = { @@ -369,6 +386,14 @@ static const struct lm90_params lm90_params[] = { .alert_alarms = 0x7c, .max_convrate = 10, }, + [adt7481] = { + .flags = LM90_HAVE_OFFSET | LM90_HAVE_REM_LIMIT_EXT + | LM90_HAVE_BROKEN_ALERT | LM90_HAVE_EXTENDED_TEMP + | LM90_HAVE_CRIT | LM90_HAVE_TEMP3, + .alert_alarms = 0x1c7c, + .max_convrate = 11, + .reg_status2 = ADT7481_REG_R_STATUS2, + }, [g781] = { .flags = LM90_HAVE_OFFSET | LM90_HAVE_REM_LIMIT_EXT | LM90_HAVE_BROKEN_ALERT | LM90_HAVE_CRIT, @@ -429,6 +454,7 @@ static const struct lm90_params lm90_params[] = { .alert_alarms = 0x1c7c, .max_convrate = 6, .reg_local_ext = MAX6657_REG_R_LOCAL_TEMPL, + .reg_status2 = MAX6696_REG_R_STATUS2, }, [w83l771] = { .flags = LM90_HAVE_OFFSET | LM90_HAVE_REM_LIMIT_EXT | LM90_HAVE_CRIT, @@ -480,10 +506,11 @@ enum lm90_temp11_reg_index { REMOTE_LOW, REMOTE_HIGH, REMOTE_OFFSET, /* except max6646, max6657/58/59, and max6695/96 */ + REMOTE2_OFFSET, /* for dev that can set offset for the 2nd channel */ LOCAL_TEMP, - REMOTE2_TEMP, /* max6695/96 only */ - REMOTE2_LOW, /* max6695/96 only */ - REMOTE2_HIGH, /* max6695/96 only */ + REMOTE2_TEMP, /* max6695/96 and adt7481 only */ + REMOTE2_LOW, /* max6695/96 and adt7481 only */ + REMOTE2_HIGH, /* max6695/96 and adt7481 only */ TEMP11_REG_NUM }; @@ -512,7 +539,8 @@ struct lm90_data { u16 alert_alarms; /* Which alarm bits trigger ALERT# */ /* Upper 8 bits for max6695/96 */ u8 max_convrate; /* Maximum conversion rate */ - u8 reg_local_ext; /* local extension register offset */ + u8 reg_local_ext; /* Local extension register offset */ + u8 reg_status2; /* Second status register */ /* registers values */ s8 temp8[TEMP8_REG_NUM]; @@ -617,7 +645,7 @@ static int lm90_select_remote_channel(struct lm90_data *data, int channel) { int err = 0; - if (data->kind == max6696) { + if (data->kind == max6696 || data->kind == adt7481) { u8 config = data->config & ~0x08; if (channel) @@ -726,6 +754,14 @@ static int lm90_update_limits(struct device *dev) if (val < 0) return val; data->temp11[REMOTE_OFFSET] = val; + + if (data->flags & LM90_HAVE_TEMP3) { + val = lm90_read16(client, LM90_REG_R_REMOTE2_OFFSH, + LM90_REG_R_REMOTE2_OFFSL); + if (val < 0) + return val; + data->temp11[REMOTE2_OFFSET] = val; + } } if (data->flags & LM90_HAVE_EMERGENCY) { @@ -740,7 +776,7 @@ static int lm90_update_limits(struct device *dev) data->temp8[REMOTE_EMERG] = val; } - if (data->kind == max6696) { + if (data->kind == max6696 || data->kind == adt7481) { val = lm90_select_remote_channel(data, 1); if (val < 0) return val; @@ -750,10 +786,12 @@ static int lm90_update_limits(struct device *dev) return val; data->temp8[REMOTE2_CRIT] = val; - val = lm90_read_reg(client, MAX6659_REG_R_REMOTE_EMERG); - if (val < 0) - return val; - data->temp8[REMOTE2_EMERG] = val; + if (data->kind == max6696) { + val = lm90_read_reg(client, MAX6659_REG_R_REMOTE_EMERG); + if (val < 0) + return val; + data->temp8[REMOTE2_EMERG] = val; + } val = lm90_read_reg(client, LM90_REG_R_REMOTE_LOWH); if (val < 0) @@ -824,7 +862,7 @@ static int lm90_update_device(struct device *dev) return val; data->alarms = val & ~LM90_STATUS_BUSY; - if (data->kind == max6696) { + if (data->kind == max6696 || data->kind == adt7481) { val = lm90_select_remote_channel(data, 1); if (val < 0) return val; @@ -838,8 +876,10 @@ static int lm90_update_device(struct device *dev) data->temp11[REMOTE2_TEMP] = val; lm90_select_remote_channel(data, 0); + } - val = lm90_read_reg(client, MAX6696_REG_R_STATUS2); + if (data->reg_status2) { + val = lm90_read_reg(client, data->reg_status2); if (val < 0) return val; data->alarms |= val << 8; @@ -1051,6 +1091,7 @@ static int lm90_set_temp11(struct lm90_data *data, int index, long val) [REMOTE_LOW] = { LM90_REG_W_REMOTE_LOWH, LM90_REG_W_REMOTE_LOWL }, [REMOTE_HIGH] = { LM90_REG_W_REMOTE_HIGHH, LM90_REG_W_REMOTE_HIGHL }, [REMOTE_OFFSET] = { LM90_REG_W_REMOTE_OFFSH, LM90_REG_W_REMOTE_OFFSL }, + [REMOTE2_OFFSET] = { LM90_REG_W_REMOTE_OFFSH, LM90_REG_W_REMOTE_OFFSL }, [REMOTE2_LOW] = { LM90_REG_W_REMOTE_LOWH, LM90_REG_W_REMOTE_LOWL }, [REMOTE2_HIGH] = { LM90_REG_W_REMOTE_HIGHH, LM90_REG_W_REMOTE_HIGHL } }; @@ -1074,7 +1115,7 @@ static int lm90_set_temp11(struct lm90_data *data, int index, long val) else data->temp11[index] = temp_to_s8(val) << 8; - lm90_select_remote_channel(data, index >= 3); + lm90_select_remote_channel(data, index >= REMOTE2_OFFSET); err = i2c_smbus_write_byte_data(client, regp->high, data->temp11[index] >> 8); if (err < 0) @@ -1271,7 +1312,10 @@ static int lm90_temp_read(struct device *dev, u32 attr, int channel, long *val) *val = lm90_get_temphyst(data, lm90_temp_emerg_index[channel]); break; case hwmon_temp_offset: - *val = lm90_get_temp11(data, REMOTE_OFFSET); + if (channel == 1) + *val = lm90_get_temp11(data, REMOTE_OFFSET); + else + *val = lm90_get_temp11(data, REMOTE2_OFFSET); break; default: return -EOPNOTSUPP; @@ -1321,7 +1365,10 @@ static int lm90_temp_write(struct device *dev, u32 attr, int channel, long val) err = lm90_set_temp8(data, lm90_temp_emerg_index[channel], val); break; case hwmon_temp_offset: - err = lm90_set_temp11(data, REMOTE_OFFSET, val); + if (channel == 1) + err = lm90_set_temp11(data, REMOTE_OFFSET, val); + else + err = lm90_set_temp11(data, REMOTE2_OFFSET, val); break; default: err = -EOPNOTSUPP; @@ -1513,7 +1560,7 @@ static int lm90_detect(struct i2c_client *client, } } } else - if ((address == 0x4C || address == 0x4D) + if ((address == 0x4C || address == 0x4D || address == 0x4B) && man_id == 0x41) { /* Analog Devices */ if ((chip_id & 0xF0) == 0x40 /* ADM1032 */ && (config1 & 0x3F) == 0x00 @@ -1536,6 +1583,11 @@ static int lm90_detect(struct i2c_client *client, && (config1 & 0x1B) == 0x00 && convrate <= 0x0A) { name = "adt7461a"; + } else + if (chip_id == 0x62 /* ADT7481 (undocumented in datasheet) */ + && (config1 & 0x1B) == 0x00 + && convrate <= 0x0B) { + name = "adt7481"; } } else if (man_id == 0x4D) { /* Maxim */ @@ -1749,9 +1801,9 @@ static int lm90_init_client(struct i2c_client *client, struct lm90_data *data) config |= 0x20; /* - * Select external channel 0 for max6695/96 + * Select external channel 0 for max6695/96 or adt7481 */ - if (data->kind == max6696) + if (data->kind == max6696 || data->kind == adt7481) config &= ~0x08; /* @@ -1776,11 +1828,11 @@ static bool lm90_is_tripped(struct i2c_client *client, u16 *status) if (st < 0) return false; - if (data->kind == max6696) { - st2 = lm90_read_reg(client, MAX6696_REG_R_STATUS2); - if (st2 < 0) - return false; - } + if (data->reg_status2) + st2 = lm90_read_reg(client, data->reg_status2); + + if (st2 < 0) + return false; *status = st | (st2 << 8); @@ -1951,9 +2003,13 @@ static int lm90_probe(struct i2c_client *client) HWMON_T_MIN_ALARM | HWMON_T_MAX_ALARM | HWMON_T_CRIT_ALARM | HWMON_T_EMERGENCY_ALARM | HWMON_T_FAULT; + + if (data->flags & LM90_HAVE_OFFSET) + data->channel_config[2] |= HWMON_T_OFFSET; } data->reg_local_ext = lm90_params[data->kind].reg_local_ext; + data->reg_status2 = lm90_params[data->kind].reg_status2; /* Set maximum conversion rate */ data->max_convrate = lm90_params[data->kind].max_convrate; From patchwork Fri May 20 09:32:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Slawomir Stepien X-Patchwork-Id: 12856591 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 4D440C4332F for ; Fri, 20 May 2022 09:54:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347936AbiETJyR (ORCPT ); Fri, 20 May 2022 05:54:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54380 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347969AbiETJyP (ORCPT ); Fri, 20 May 2022 05:54:15 -0400 Received: from smtpo49.interia.pl (smtpo49.interia.pl [217.74.67.49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E36E014ACB1 for ; Fri, 20 May 2022 02:54:12 -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; Fri, 20 May 2022 11:51:51 +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, Slawomir Stepien , Slawomir Stepien Subject: [PATCH 5/8] hwmon: (lm90) define maximum number of channels that are supported Date: Fri, 20 May 2022 11:32:41 +0200 Message-Id: <20220520093243.2523749-6-sst@poczta.fm> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220520093243.2523749-1-sst@poczta.fm> References: <20220520093243.2523749-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=1653040313; bh=CueFz9a7mfkox4k37DjBXT5XaBNq4PIE4cBWeHaaVDo=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=rcBwsHtntotWrE+OV4Qbax2w9lyytelLIiK6hasa66dEZo9cTyUXG5UdM0Dld81OK gvglrQl2T81hrPFZDeMMvKmOu1MKkp/zsqZu/SVP8dOOeYnD2vn7iXOwT+M6LgHYkV jo3WJs6NJ0F7Rjfu+0tBZFAT3a3JdwVaIioL+Ap8= 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 | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/drivers/hwmon/lm90.c b/drivers/hwmon/lm90.c index 00fd5734f217..f642c6fd1641 100644 --- a/drivers/hwmon/lm90.c +++ b/drivers/hwmon/lm90.c @@ -93,6 +93,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 @@ -521,9 +524,9 @@ enum lm90_temp11_reg_index { struct lm90_data { struct i2c_client *client; struct device *hwmon_dev; - u32 channel_config[4]; + u32 channel_config[MAX_CHANNELS + 1]; struct hwmon_channel_info temp_info; - const struct hwmon_channel_info *info[3]; + const struct hwmon_channel_info *info[MAX_CHANNELS]; struct hwmon_chip_info chip; struct mutex update_lock; bool valid; /* true if register values are valid */ @@ -1223,32 +1226,32 @@ static int lm90_set_temphyst(struct lm90_data *data, long val) return err; } -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 u8 lm90_min_alarm_bits[3] = { 5, 3, 11 }; -static const u8 lm90_max_alarm_bits[3] = { 6, 4, 12 }; -static const u8 lm90_crit_alarm_bits[3] = { 0, 1, 9 }; -static const u8 lm90_crit_alarm_bits_swapped[3] = { 1, 0, 9 }; -static const u8 lm90_emergency_alarm_bits[3] = { 15, 13, 14 }; -static const u8 lm90_fault_bits[3] = { 0, 2, 10 }; +static const u8 lm90_min_alarm_bits[MAX_CHANNELS] = { 5, 3, 11 }; +static const u8 lm90_max_alarm_bits[MAX_CHANNELS] = { 6, 4, 12 }; +static const u8 lm90_crit_alarm_bits[MAX_CHANNELS] = { 0, 1, 9 }; +static const u8 lm90_crit_alarm_bits_swapped[MAX_CHANNELS] = { 1, 0, 9 }; +static const u8 lm90_emergency_alarm_bits[MAX_CHANNELS] = { 15, 13, 14 }; +static const u8 lm90_fault_bits[MAX_CHANNELS] = { 0, 2, 10 }; static int lm90_temp_read(struct device *dev, u32 attr, int channel, long *val) { From patchwork Fri May 20 09:32:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Slawomir Stepien X-Patchwork-Id: 12856590 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 95676C433FE for ; Fri, 20 May 2022 09:54:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347970AbiETJyQ (ORCPT ); Fri, 20 May 2022 05:54:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54378 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347936AbiETJyP (ORCPT ); Fri, 20 May 2022 05:54:15 -0400 Received: from smtpo49.interia.pl (smtpo49.interia.pl [217.74.67.49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E3453FD343 for ; Fri, 20 May 2022 02:54:12 -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; Fri, 20 May 2022 11:51:53 +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, Slawomir Stepien , Slawomir Stepien Subject: [PATCH 6/8] hwmon: (lm90) enable the extended temperature range Date: Fri, 20 May 2022 11:32:42 +0200 Message-Id: <20220520093243.2523749-7-sst@poczta.fm> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220520093243.2523749-1-sst@poczta.fm> References: <20220520093243.2523749-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=1653040314; bh=sVsMdV+8BfY9/NwT5Uaq6GjYpmIrVBc5zRUmBPpGcGU=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=NC8FGXo3xpK25hBxY07JyekmdjZ2u+dTwS6Cdm8HA3Ot0Sfm0C+J2Gfr/GT1/ASF6 uRiJjM9hyPRrLiWIyJADriDC9tW2ZbRvLPMEFQxkS2tvgzHFQ+FNDHYpks/mc1zIjR lff+8ZGWdf58stQ5iwgKWRP/d7L2B2n0LyIt+BZg= Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org From: Slawomir Stepien Enable the extended temperature range if it was requested from device-tree node. Signed-off-by: Slawomir Stepien --- drivers/hwmon/lm90.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/hwmon/lm90.c b/drivers/hwmon/lm90.c index f642c6fd1641..67d48707a8d6 100644 --- a/drivers/hwmon/lm90.c +++ b/drivers/hwmon/lm90.c @@ -1914,6 +1914,7 @@ static const struct hwmon_ops lm90_ops = { static int lm90_probe(struct i2c_client *client) { struct device *dev = &client->dev; + const struct device_node *np = dev->of_node; struct i2c_adapter *adapter = client->adapter; struct hwmon_channel_info *info; struct regulator *regulator; @@ -2017,6 +2018,17 @@ static int lm90_probe(struct i2c_client *client) /* Set maximum conversion rate */ data->max_convrate = lm90_params[data->kind].max_convrate; + /* Parse device-tree information */ + if (np) { + if (data->flags & LM90_HAVE_EXTENDED_TEMP) { + if (of_property_read_bool(np, "extended-range-enable")) { + err = lm90_update_confreg(data, data->config | 0x04); + if (err) + return err; + } + } + } + /* Initialize the LM90 chip */ err = lm90_init_client(client, data); if (err < 0) { From patchwork Fri May 20 09:32:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Slawomir Stepien X-Patchwork-Id: 12856593 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 D49F1C433EF for ; Fri, 20 May 2022 09:54:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347969AbiETJyT (ORCPT ); Fri, 20 May 2022 05:54:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54390 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229765AbiETJyP (ORCPT ); Fri, 20 May 2022 05:54:15 -0400 Received: from smtpo49.interia.pl (smtpo49.interia.pl [217.74.67.49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E42B914AF52 for ; Fri, 20 May 2022 02:54:12 -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; Fri, 20 May 2022 11:51:54 +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, Slawomir Stepien , Slawomir Stepien Subject: [PATCH 7/8] hwmon: (lm90) read the channel's label from device-tree Date: Fri, 20 May 2022 11:32:43 +0200 Message-Id: <20220520093243.2523749-8-sst@poczta.fm> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220520093243.2523749-1-sst@poczta.fm> References: <20220520093243.2523749-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=1653040315; bh=xFk1LxjyDkD37itPRXtcBJqbTO1hWn+ulsWUgVpJpIw=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=fT5mqlScM5PWDV2dAVFQy+VX3g4mFSFZ2ZsNld8O3ynC4ryS352AszEOV7zCpr5y9 pk2OaigVcdwiZesojFTWj+IE5vuw5aYZ5DKobARCNp3y2RBiGnT1ebMcY5o0twm9vh pudbr4ROvlACOl2enRnOV80zy1xzG3LKV1qi5VN8= 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 | 70 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/drivers/hwmon/lm90.c b/drivers/hwmon/lm90.c index 67d48707a8d6..e81cc21e525f 100644 --- a/drivers/hwmon/lm90.c +++ b/drivers/hwmon/lm90.c @@ -525,6 +525,7 @@ struct lm90_data { struct i2c_client *client; struct device *hwmon_dev; u32 channel_config[MAX_CHANNELS + 1]; + const char *channel_label[MAX_CHANNELS]; struct hwmon_channel_info temp_info; const struct hwmon_channel_info *info[MAX_CHANNELS]; struct hwmon_chip_info chip; @@ -1393,6 +1394,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: @@ -1486,6 +1488,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) { @@ -1904,10 +1916,64 @@ 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 %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 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, }; @@ -2027,6 +2093,10 @@ static int lm90_probe(struct i2c_client *client) return err; } } + + err = lm90_parse_dt_channel_info(client, data); + if (err) + return err; } /* Initialize the LM90 chip */ From patchwork Fri May 20 09:32:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Slawomir Stepien X-Patchwork-Id: 12856594 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 D579CC433F5 for ; Fri, 20 May 2022 09:54:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347973AbiETJy4 (ORCPT ); Fri, 20 May 2022 05:54:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54894 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348025AbiETJyy (ORCPT ); Fri, 20 May 2022 05:54:54 -0400 Received: from smtpo52.interia.pl (smtpo52.interia.pl [217.74.67.52]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 69FB114B657 for ; Fri, 20 May 2022 02:54:52 -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; Fri, 20 May 2022 11:51:55 +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, Slawomir Stepien , Slawomir Stepien Subject: [PATCH 8/8] hwmon: (lm90) read the channel's offset from device-tree Date: Fri, 20 May 2022 11:32:44 +0200 Message-Id: <20220520093243.2523749-9-sst@poczta.fm> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220520093243.2523749-1-sst@poczta.fm> References: <20220520093243.2523749-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=1653040317; bh=EN4hRZxKuHTd81cuBG9n6Zwbmm3nhipzCK7dawab70c=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=q31nKgG0DWNsPxujtR+0SqcRaVpXwQW03DMwORa9XYAydFSju8EcMPkiaiSu0W7lQ DLO1pl9+XGM6nv5bqaUzmoH753lrqrgyMRHrjx3CAaUd1Qb9wxHtSfBqsYtB8Og0m5 ZQeXjyGOYHWsYaxykbHMlPAe2/m+8V7lWnqkNp4k= Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org From: Slawomir Stepien Try to read the channel's 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 | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/drivers/hwmon/lm90.c b/drivers/hwmon/lm90.c index e81cc21e525f..e4e7b4ddbfb6 100644 --- a/drivers/hwmon/lm90.c +++ b/drivers/hwmon/lm90.c @@ -1921,6 +1921,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; @@ -1944,6 +1945,25 @@ 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, "offset", &val); + if (!err) { + if (id == 0) { + dev_err(dev, "offset can't be set for internal channel\n"); + return -EINVAL; + } + + if (id == 1) + err = lm90_set_temp11(data, REMOTE_OFFSET, val); + else + err = lm90_set_temp11(data, REMOTE2_OFFSET, val); + + if (err) { + dev_err(dev, "can't set offset %d for channel %d (%d)\n", + val, id, err); + return err; + } + } + return 0; } @@ -2091,6 +2111,12 @@ static int lm90_probe(struct i2c_client *client) err = lm90_update_confreg(data, data->config | 0x04); if (err) return err; + + /* + * In lm90_parse_dt_channel_info() we might set offset, so we need + * to use correct format indication before that + */ + data->flags |= LM90_FLAG_ADT7461_EXT; } }