From patchwork Sun Jan 26 22:10:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Logan Shaw X-Patchwork-Id: 11351977 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 88B2913A4 for ; Sun, 26 Jan 2020 22:10:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 673BF2071A for ; Sun, 26 Jan 2020 22:10:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=alliedtelesis.co.nz header.i=@alliedtelesis.co.nz header.b="hWmywt9R" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728266AbgAZWKe (ORCPT ); Sun, 26 Jan 2020 17:10:34 -0500 Received: from gate2.alliedtelesis.co.nz ([202.36.163.20]:40315 "EHLO gate2.alliedtelesis.co.nz" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727409AbgAZWKd (ORCPT ); Sun, 26 Jan 2020 17:10:33 -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 6C1FA886BF; Mon, 27 Jan 2020 11:10:31 +1300 (NZDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alliedtelesis.co.nz; s=mail181024; t=1580076631; bh=vfOUd83vLniAyLu6CP72Bs9UFXDfxICC0fERRfGsS9I=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=hWmywt9ReGC2OcMBw7s0lcrsCgV031LGp3Zs7/5p8e4YL2rcfkpCdMdqSfijx5Zj+ TFk+pSxuXoF6sFffG+33eUNR2EoNFEOk97nCK6zKM5HH5jPlTSZES8hme8j4v1Oksu IEKrfP4iw13F1KLRvHmycj6wetPMndlfirQ8ot4MyxpFI7iQJ2/AM3w4I0fycR1SKO 1pSJyM14FC0Ktn5WEk7LpR5RTaXSP89fa6KYOgFHeGbMs6HIwoOyhm5AaVk7JZ7IIO 6mueltACEb1ChkDE3IsglI6lN+FxnCvasRogbXg70oVnIKyqaBckvmxGqMo8HUixuj /nRar8Det1Few== Received: from smtp (Not Verified[10.32.16.33]) by mmarshal3.atlnz.lc with Trustwave SEG (v7,5,8,10121) id ; Mon, 27 Jan 2020 11:10:31 +1300 Received: from logans-dl.ws.atlnz.lc (logans-dl.ws.atlnz.lc [10.33.25.61]) by smtp (Postfix) with ESMTP id 22B3413EEB9; Mon, 27 Jan 2020 11:10:30 +1300 (NZDT) Received: by logans-dl.ws.atlnz.lc (Postfix, from userid 1820) id 38F71C0DF6; Mon, 27 Jan 2020 11:10:31 +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 v6 1/2] hwmon: (adt7475) Added attenuator bypass support Date: Mon, 27 Jan 2020 11:10:13 +1300 Message-Id: <20200126221014.2978-2-logan.shaw@alliedtelesis.co.nz> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200126221014.2978-1-logan.shaw@alliedtelesis.co.nz> References: <20200126221014.2978-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 | 55 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/drivers/hwmon/adt7475.c b/drivers/hwmon/adt7475.c index 6c64d50c9aae..3f4bdc1eaaec 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,57 @@ static int adt7475_update_limits(struct i2c_client *client) return 0; } +static void modify_config(const struct i2c_client *client, char *property, + u8 *config, u8 bit_index) +{ + u32 prop_value = 0; + int ret = of_property_read_u32(client->dev.of_node, property, + &prop_value); + + if (!ret) { + if (prop_value) + *config |= (1 << bit_index); + else + *config &= ~(1 << bit_index); + } +} + +static int load_attenuators(const struct i2c_client *client, int chip, + u8 *config2, u8 *config4) +{ + u8 conf_copy; + int ret; + + if (chip == adt7476 || chip == adt7490) { + conf_copy = *config4; + + modify_config(client, "bypass-attenuator-in0", &conf_copy, 4); + modify_config(client, "bypass-attenuator-in1", &conf_copy, 5); + modify_config(client, "bypass-attenuator-in3", &conf_copy, 6); + modify_config(client, "bypass-attenuator-in4", &conf_copy, 7); + + ret = i2c_smbus_write_byte_data(client, REG_CONFIG4, + conf_copy); + if (ret < 0) + return ret; + + *config4 = conf_copy; + } else if (chip == adt7473 || chip == adt7475) { + conf_copy = *config2; + + modify_config(client, "bypass-attenuator-in1", &conf_copy, 5); + + ret = i2c_smbus_write_byte_data(client, REG_CONFIG2, + conf_copy); + if (ret < 0) + return ret; + + *config2 = conf_copy; + } + + return 0; +} + static int adt7475_probe(struct i2c_client *client, const struct i2c_device_id *id) { @@ -1546,6 +1598,9 @@ static int adt7475_probe(struct i2c_client *client, /* Voltage attenuators can be bypassed, globally or individually */ config2 = adt7475_read(REG_CONFIG2); + if (load_attenuators(client, chip, &config2, &data->config4) < 0) + dev_warn(&client->dev, "Error setting bypass attenuators\n"); + if (config2 & CONFIG2_ATTN) { data->bypass_attn = (0x3 << 3) | 0x3; } else { From patchwork Sun Jan 26 22:10:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Logan Shaw X-Patchwork-Id: 11351979 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 E85EC13A4 for ; Sun, 26 Jan 2020 22:10:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C610B206F0 for ; Sun, 26 Jan 2020 22:10:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=alliedtelesis.co.nz header.i=@alliedtelesis.co.nz header.b="BGznTRfO" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728449AbgAZWKf (ORCPT ); Sun, 26 Jan 2020 17:10:35 -0500 Received: from gate2.alliedtelesis.co.nz ([202.36.163.20]:40322 "EHLO gate2.alliedtelesis.co.nz" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726252AbgAZWKf (ORCPT ); Sun, 26 Jan 2020 17:10:35 -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 2F37A891A9; Mon, 27 Jan 2020 11:10:33 +1300 (NZDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alliedtelesis.co.nz; s=mail181024; t=1580076633; bh=zeFePKo6fhbCcfDQ2OhTCgA3upjarST3rYiHMVEi89M=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=BGznTRfO5sN7M+oQ88oLAP30KKUOxLXp5Cc7yKuPsgpvnzJckq2ILigXesgN0jbWB 9hlE+YiZ/nzw3IAXbSYKetDEpWrDfZVOak4OLoNh7vZDgt+YlQACBYwMru76vO7jM7 WK2Fvr8PE2foQtchitXxllYlOQIhaO4LrkK89qvbZCg9g8qQ9tb6/ei2ps6Nyj/xwg LParGQ7Vco5LxGxqUtLkrcHHSAmETp0N+1MaAqCQo7j85XVVUZXtk6Lvqa5tLGmYC+ NW4eOtxBybY38cIV4fhGnHzQudbmM+EVk1nfNWtM260H4MH9KMUe0TbwpKTs3c+FpB XdgvrmNEJlfUg== Received: from smtp (Not Verified[10.32.16.33]) by mmarshal3.atlnz.lc with Trustwave SEG (v7,5,8,10121) id ; Mon, 27 Jan 2020 11:10:32 +1300 Received: from logans-dl.ws.atlnz.lc (logans-dl.ws.atlnz.lc [10.33.25.61]) by smtp (Postfix) with ESMTP id B6CDA13EEB9; Mon, 27 Jan 2020 11:10:31 +1300 (NZDT) Received: by logans-dl.ws.atlnz.lc (Postfix, from userid 1820) id CD3DEC0DF6; Mon, 27 Jan 2020 11:10:32 +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 v6 2/2] dt-bindings: hwmon: (adt7475) Added missing adt7475 documentation Date: Mon, 27 Jan 2020 11:10:14 +1300 Message-Id: <20200126221014.2978-3-logan.shaw@alliedtelesis.co.nz> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200126221014.2978-1-logan.shaw@alliedtelesis.co.nz> References: <20200126221014.2978-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 | 95 +++++++++++++++++++ 1 file changed, 95 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..450da5e66e07 --- /dev/null +++ b/Documentation/devicetree/bindings/hwmon/adt7475.yaml @@ -0,0 +1,95 @@ +# 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: + - | + i2c { + #address-cells = <1>; + #size-cells = <0>; + + hwmon@2e { + compatible = "adi,adt7476"; + reg = <0x2e>; + bypass-attenuator-in0 = <1>; + bypass-attenuator-in1 = <0>; + }; + }; +...