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: 576094 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 35821C433F5 for ; Wed, 25 May 2022 07:37:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239050AbiEYHhU (ORCPT ); Wed, 25 May 2022 03:37:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47016 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232374AbiEYHhT (ORCPT ); Wed, 25 May 2022 03:37:19 -0400 Received: from smtpo68.interia.pl (smtpo68.interia.pl [217.74.67.68]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4683B5E146 for ; Wed, 25 May 2022 00:37:17 -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: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 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: devicetree@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 --- .../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: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: 576093 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 4443AC433EF for ; Wed, 25 May 2022 07:37:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242165AbiEYHhX (ORCPT ); Wed, 25 May 2022 03:37:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47212 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243415AbiEYHhW (ORCPT ); Wed, 25 May 2022 03:37:22 -0400 Received: from smtpo52.interia.pl (smtpo52.interia.pl [217.74.67.52]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E91665EDF4 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: devicetree@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: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: 576092 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 D731BC433F5 for ; Wed, 25 May 2022 07:37:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242149AbiEYHhc (ORCPT ); Wed, 25 May 2022 03:37:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47478 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243415AbiEYHhZ (ORCPT ); Wed, 25 May 2022 03:37:25 -0400 Received: from smtpo68.interia.pl (smtpo68.interia.pl [217.74.67.68]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5CAAF60044 for ; Wed, 25 May 2022 00:37:23 -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: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 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: devicetree@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) {