From patchwork Fri Jan 17 03:50:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Logan Shaw X-Patchwork-Id: 11338271 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3A21613A0 for ; Fri, 17 Jan 2020 03:51:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 173FA2082F for ; Fri, 17 Jan 2020 03:51:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=alliedtelesis.co.nz header.i=@alliedtelesis.co.nz header.b="ayEEvxq9" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729559AbgAQDvD (ORCPT ); Thu, 16 Jan 2020 22:51:03 -0500 Received: from gate2.alliedtelesis.co.nz ([202.36.163.20]:56321 "EHLO gate2.alliedtelesis.co.nz" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729372AbgAQDvD (ORCPT ); Thu, 16 Jan 2020 22:51:03 -0500 Received: from mmarshal3.atlnz.lc (mmarshal3.atlnz.lc [10.32.18.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by gate2.alliedtelesis.co.nz (Postfix) with ESMTPS id 0C336891AE; Fri, 17 Jan 2020 16:51:02 +1300 (NZDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alliedtelesis.co.nz; s=mail181024; t=1579233062; bh=IZF+L2Q5FLkUfOp7nAfJ6fRYNZITWKpUJNg/rlmCm7Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=ayEEvxq9AChPPU/CLMd6gpiEgUqjt0ios2mOV+TKeB+DC+i0nN3VM1YzZHN4W/Hv+ yyaSz5iRltAiAQTtitAHP2i6B2JBvQW2PTPs4K/jgoGheLIFd9CplCT0219o4IX2aa jYVdiNIEq4QMPqJRQw9kgkbMPOlqkXMR2IdHyir5B+HW+qOPl0uf/QesgqxYOx4p+n 1YNEs4qKJW1PmOB5/iYbesxBbQNCXuhVZCsRFRHXoqaHAMf1x1Q3F6GA948BL5pkZL aUHvwXROGH1rI4mLNKkjKd8dMy4x8JrPbnWS3frNBeTzCRrMn96bTfjON6xlYkZqX0 PJdrtK0sWUYhQ== Received: from smtp (Not Verified[10.32.16.33]) by mmarshal3.atlnz.lc with Trustwave SEG (v7,5,8,10121) id ; Fri, 17 Jan 2020 16:51:02 +1300 Received: from logans-dl.ws.atlnz.lc (logans-dl.ws.atlnz.lc [10.33.25.61]) by smtp (Postfix) with ESMTP id 552A213EEFE; Fri, 17 Jan 2020 16:51:01 +1300 (NZDT) Received: by logans-dl.ws.atlnz.lc (Postfix, from userid 1820) id C93E5C1A8B; Fri, 17 Jan 2020 16:51:01 +1300 (NZDT) From: Logan Shaw To: linux@roeck-us.net, jdelvare@suse.com, robh+dt@kernel.org Cc: linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Joshua.Scott@alliedtelesis.co.nz, Chris.Packham@alliedtelesis.co.nz, logan.shaw@alliedtelesis.co.nz Subject: [PATCH v3 1/2] hwmon: (adt7475) Added attenuator bypass support Date: Fri, 17 Jan 2020 16:50:17 +1300 Message-Id: <20200117035018.11985-2-logan.shaw@alliedtelesis.co.nz> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200117035018.11985-1-logan.shaw@alliedtelesis.co.nz> References: <20200117035018.11985-1-logan.shaw@alliedtelesis.co.nz> MIME-Version: 1.0 x-atlnz-ls: pat Sender: linux-hwmon-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org Added support for reading DTS properties to set attenuators on device probe for the ADT7473, ADT7475, ADT7476, and ADT7490. Signed-off-by: Logan Shaw --- --- drivers/hwmon/adt7475.c | 76 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/drivers/hwmon/adt7475.c b/drivers/hwmon/adt7475.c index 6c64d50c9aae..2bb787acb363 100644 --- a/drivers/hwmon/adt7475.c +++ b/drivers/hwmon/adt7475.c @@ -19,6 +19,7 @@ #include #include #include +#include #include /* Indexes for the sysfs hooks */ @@ -1457,6 +1458,76 @@ static int adt7475_update_limits(struct i2c_client *client) return 0; } +/** + * Attempts to read a u32 property from the DTS, if there is no error and + * the properties value is zero then the bit given by parameter bit_index + * is cleared in the parameter config. If the value is non-zero then the bit + * is set. + * + * If reading the dts property returned an error code then it is returned and + * the config parameter is not modified. + */ +static int modify_config_from_dts_prop(const struct i2c_client *client, + char *dts_property, u8 *config, u8 bit_index) { + u32 is_attenuator_bypassed = 0; + int ret = of_property_read_u32(client->dev.of_node, dts_property, + &is_attenuator_bypassed); + + if (! ret) { + if (is_attenuator_bypassed) + *config |= (1 << bit_index); + else + *config &= ~(1 << bit_index); + } + + return ret; +} + +/** + * Reads all individual voltage input bypass attenuator properties from the + * DTS, and if the property is present the corresponding bit is set in the + * register. + + * Properties are in the form of "bypass-attenuator-inx", where x is an + * integer from the set {0, 1, 3, 4} (can not bypass in2 attenuator). +.* + * The adt7473 and adt7475 only support bypassing in1. + * + * Returns a negative error code if there was an error writing to the register. + */ +static int load_all_bypass_attenuators(const struct i2c_client *client, + int chip, u8 *config2, u8 *config4) +{ + u8 config2_copy = *config2; + u8 config4_copy = *config4; + + if (chip == adt7476 || chip == adt7490) { + modify_config_from_dts_prop(client, "bypass-attenuator-in0", + &config4_copy, 4); + modify_config_from_dts_prop(client, "bypass-attenuator-in1", + &config4_copy, 5); + modify_config_from_dts_prop(client, "bypass-attenuator-in3", + &config4_copy, 6); + modify_config_from_dts_prop(client, "bypass-attenuator-in4", + &config4_copy, 7); + + if (i2c_smbus_write_byte_data(client, REG_CONFIG4, config4_copy) < 0) + return -EREMOTEIO; + + *config4 = config4_copy; + } else if (chip == adt7473 || chip == adt7475) { + modify_config_from_dts_prop(client, "bypass-attenuator-in1", + &config2_copy, 5); + + if (i2c_smbus_write_byte_data(client, REG_CONFIG2, config2_copy) < 0) + return -EREMOTEIO; + + *config2 = config2_copy; + } + + return 0; +} + static int adt7475_probe(struct i2c_client *client, const struct i2c_device_id *id) { @@ -1546,6 +1617,11 @@ static int adt7475_probe(struct i2c_client *client, /* Voltage attenuators can be bypassed, globally or individually */ config2 = adt7475_read(REG_CONFIG2); + if (load_all_bypass_attenuators(client, chip, + &config2, &(data->config4)) < 0) + dev_warn(&client->dev, + "Error setting bypass attenuator bits\n"); + if (config2 & CONFIG2_ATTN) { data->bypass_attn = (0x3 << 3) | 0x3; } else { From patchwork Fri Jan 17 03:50:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Logan Shaw X-Patchwork-Id: 11338273 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DE738138D for ; Fri, 17 Jan 2020 03:51:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BCBA82083E for ; Fri, 17 Jan 2020 03:51:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=alliedtelesis.co.nz header.i=@alliedtelesis.co.nz header.b="0I1ifQad" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729715AbgAQDvJ (ORCPT ); Thu, 16 Jan 2020 22:51:09 -0500 Received: from gate2.alliedtelesis.co.nz ([202.36.163.20]:56329 "EHLO gate2.alliedtelesis.co.nz" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729297AbgAQDvH (ORCPT ); Thu, 16 Jan 2020 22:51:07 -0500 Received: from mmarshal3.atlnz.lc (mmarshal3.atlnz.lc [10.32.18.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by gate2.alliedtelesis.co.nz (Postfix) with ESMTPS id B4CDD891AF; Fri, 17 Jan 2020 16:51:05 +1300 (NZDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alliedtelesis.co.nz; s=mail181024; t=1579233065; bh=fRH1fOtTq3nwhWeBJY9OSVBx1/bx+wOXC/1lsHlEf+Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=0I1ifQadS3Jx1N6SMXLWI8wK6VaBbmMKKLM45B+DcWd0FXtm91Feeqo3YIKGr+D3j 27OuYHT3y5n2Zd9EYwp8vVb6WB3d8Q3dV5D6BSWzzRWehz0LDgRPoLJpNUQ7jwA/0M ZXTWp6abAq6YJsYYR7n7eo4vDzwwISDvnRnjGSuHdKjCPavcNY/oIlCzQtco4tfs/d 74sRlE8VesA/oyIhIpSAMWHzJk2fTWQTcjPTr9RARw4Zc35NpUZUQrq3zBzIdK9QQ+ nXpT3115tOX3YihKHxSt7w+ggSVUiChYnNGGbAjI2/XpShUu8soo1WMsroTMGw12ja 6Zm3FP6AE1Opg== Received: from smtp (Not Verified[10.32.16.33]) by mmarshal3.atlnz.lc with Trustwave SEG (v7,5,8,10121) id ; Fri, 17 Jan 2020 16:51:05 +1300 Received: from logans-dl.ws.atlnz.lc (logans-dl.ws.atlnz.lc [10.33.25.61]) by smtp (Postfix) with ESMTP id DD91E13EEFE; Fri, 17 Jan 2020 16:51:04 +1300 (NZDT) Received: by logans-dl.ws.atlnz.lc (Postfix, from userid 1820) id 5DBE1C1A8B; Fri, 17 Jan 2020 16:51:05 +1300 (NZDT) From: Logan Shaw To: linux@roeck-us.net, jdelvare@suse.com, robh+dt@kernel.org Cc: linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Joshua.Scott@alliedtelesis.co.nz, Chris.Packham@alliedtelesis.co.nz, logan.shaw@alliedtelesis.co.nz Subject: [PATCH v3 2/2] hwmon: (adt7475) Added attenuator bypass support Date: Fri, 17 Jan 2020 16:50:18 +1300 Message-Id: <20200117035018.11985-3-logan.shaw@alliedtelesis.co.nz> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200117035018.11985-1-logan.shaw@alliedtelesis.co.nz> References: <20200117035018.11985-1-logan.shaw@alliedtelesis.co.nz> MIME-Version: 1.0 x-atlnz-ls: pat Sender: linux-hwmon-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org Added a new file documenting the adt7475 devicetree and added the four new properties to it. Signed-off-by: Logan Shaw --- --- .../devicetree/bindings/hwmon/adt7475.yaml | 90 +++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 Documentation/devicetree/bindings/hwmon/adt7475.yaml diff --git a/Documentation/devicetree/bindings/hwmon/adt7475.yaml b/Documentation/devicetree/bindings/hwmon/adt7475.yaml new file mode 100644 index 000000000000..e201948beb35 --- /dev/null +++ b/Documentation/devicetree/bindings/hwmon/adt7475.yaml @@ -0,0 +1,90 @@ +# SPDX-License-Identifier: GPL-2.0 +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/adt7475.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: ADT7475 hwmon sensor + +maintainers: + - Jean Delvare + +description: | + The ADT7473, ADT7475, ADT7476, and ADT7490 are thermal monitors and multiple + PWN fan controllers. + + They support monitoring and controlling up to four fans (the ADT7490 can only + control up to three). They support reading a single on chip temperature + sensor and two off chip temperature sensors (the ADT7490 additionally + supports measuring up to three current external temperature sensors with + series resistance cancellation (SRC)). + + Datasheets: + https://www.onsemi.com/pub/Collateral/ADT7473-D.PDF + https://www.onsemi.com/pub/Collateral/ADT7475-D.PDF + https://www.onsemi.com/pub/Collateral/ADT7476-D.PDF + https://www.onsemi.com/pub/Collateral/ADT7490-D.PDF + + Description taken from omsemiconductors specification sheets, with minor + rephrasing. + +properties: + compatible: + enum: + - adi,adt7473 + - adi,adt7475 + - adi,adt7476 + - adi,adt7490 + + reg: + maxItems: 1 + + bypass-attenuator-in0: + description: | + Configures bypassing the individual voltage input + attenuator, on in0. This is supported on the ADT7476 and ADT7490. + If set to a non-zero integer the attenuator is bypassed, if set to + zero the attenuator is not bypassed. If the property is absent then + the config register is not modified. + maxItems: 1 + + bypass-attenuator-in1: + description: | + Configures bypassing the individual voltage input + attenuator, on in1. This is supported on the ADT7473, ADT7475, + ADT7476 and ADT7490. If set to a non-zero integer the attenuator + is bypassed, if set to zero the attenuator is not bypassed. If the + property is absent then the config register is not modified. + maxItems: 1 + + bypass-attenuator-in3: + description: | + Configures bypassing the individual voltage input + attenuator, on in3. This is supported on the ADT7476 and ADT7490. + If set to a non-zero integer the attenuator is bypassed, if set to + zero the attenuator is not bypassed. If the property is absent then + the config register is not modified. + maxItems: 1 + + bypass-attenuator-in4: + description: | + Configures bypassing the individual voltage input + attenuator, on in4. This is supported on the ADT7476 and ADT7490. + If set to a non-zero integer the attenuator is bypassed, if set to + zero the attenuator is not bypassed. If the property is absent then + the config register is not modified. + maxItems: 1 + +required: + - compatible + - reg + +examples: + - | + hwmon@2e { + compatible = "adi,adt7476"; + reg = <0x2e>; + bypass-attenuator-in1 = <1>; + bypass-attenuator-in1 = <0>; + }; +...