From patchwork Thu Dec 19 03:32:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Logan Shaw X-Patchwork-Id: 11302619 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 46C2A921 for ; Thu, 19 Dec 2019 03:32:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2518721582 for ; Thu, 19 Dec 2019 03:32:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=alliedtelesis.co.nz header.i=@alliedtelesis.co.nz header.b="P+Wg+Sxj" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726813AbfLSDcU (ORCPT ); Wed, 18 Dec 2019 22:32:20 -0500 Received: from gate2.alliedtelesis.co.nz ([202.36.163.20]:57235 "EHLO gate2.alliedtelesis.co.nz" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726771AbfLSDcU (ORCPT ); Wed, 18 Dec 2019 22:32:20 -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 AEA4A891A9; Thu, 19 Dec 2019 16:32:17 +1300 (NZDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alliedtelesis.co.nz; s=mail181024; t=1576726337; bh=L/lznGEkZvrKK9QhU4VOrmOAm9GaSsI8P16EfgiyvQk=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=P+Wg+SxjomqdSgx9ts6amJMtVR5QkkM1L7/U/nUgqYWi1Mj+1tNoEMpMroeocXRRJ jO2WKWHROn/I/6uHBWq6XIsP8ECQDOAzm2mqjtN08UjvpzItnU2xnmYL4RzkMfi76n UuyNMrOecUfjypMdzsNpDCGyQTF55WTY84uyQ8yyxv5Uxa1upwazHdcf7OfugSb4kk Twe09iWSOCnx8cRiIARr/jJMZA7YQyMxXRgWPRMvUMnnnx+7GfUsx5d70N3M01ttZo k14Hco+FzPiw9htVUdjN/sucRvxNHgJefC8aIv6r57cAi3Hx0khja1uBntCWP6VAzo aL76TVr7ek6Fg== Received: from smtp (Not Verified[10.32.16.33]) by mmarshal3.atlnz.lc with Trustwave SEG (v7,5,8,10121) id ; Thu, 19 Dec 2019 16:32:17 +1300 Received: from logans-dl.ws.atlnz.lc (logans-dl.ws.atlnz.lc [10.33.25.49]) by smtp (Postfix) with ESMTP id 30FA513EEAF; Thu, 19 Dec 2019 16:32:16 +1300 (NZDT) Received: by logans-dl.ws.atlnz.lc (Postfix, from userid 1820) id 7D147C03C3; Thu, 19 Dec 2019 16:32:17 +1300 (NZDT) From: Logan Shaw To: jdelvare@suse.com, linux@roeck-us.net Cc: logan.shaw@alliedtelesis.co.nz, joshua.scott@alliedtelesis.co.nz, linux-hwmon@vger.kernel.org Subject: [PATCH v2 1/2] hwmon: (adt7475) Added attenuator bypass support Date: Thu, 19 Dec 2019 16:32:12 +1300 Message-Id: <20191219033213.30364-2-logan.shaw@alliedtelesis.co.nz> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191219033213.30364-1-logan.shaw@alliedtelesis.co.nz> References: <20191219033213.30364-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. Only bypasses attenuators on the ADT7476 and ADT7490 (other chips do not support this). Signed-off-by: Logan Shaw --- --- drivers/hwmon/adt7475.c | 73 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/drivers/hwmon/adt7475.c b/drivers/hwmon/adt7475.c index 6c64d50c9aae..1e6ca1bc28ce 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,68 @@ static int adt7475_update_limits(struct i2c_client *client) return 0; } +/** + * Reads individual voltage input bypass attenuator properties from the DTS, + * and if the property is present the corresponding bit is set in the + * register. Only the ADT7476 and ADT7490 support bypassing individual + * attenuators. + * + * Properties must be in the form of "bypass-attenuator-inx", where x is an + * integer from the set {0, 1, 3, 4} (can not bypass in2 attenuator). + * + * Returns a negative error code if there was an error writing to the register. + */ +static int load_individual_bypass_attenuators(const struct i2c_client *client, + u8 *config4) +{ + u8 config4_copy = *config4; + + if (of_get_property(client->dev.of_node, "bypass-attenuator-in0", NULL)) + config4_copy |= (1 << 4); + + if (of_get_property(client->dev.of_node, "bypass-attenuator-in1", NULL)) + config4_copy |= (1 << 5); + + if (of_get_property(client->dev.of_node, "bypass-attenuator-in3", NULL)) + config4_copy |= (1 << 6); + + if (of_get_property(client->dev.of_node, "bypass-attenuator-in4", NULL)) + config4_copy |= (1 << 7); + + if (i2c_smbus_write_byte_data(client, REG_CONFIG4, config4_copy) < 0) + return -EREMOTEIO; + + *config4 = config4_copy; + + return 0; +} + +/** + * Sets the bypass all attenuators bit, if the "bypass-attenuator-all" + * property exists in the DTS. + * + * Returns a negative error code if there was an error writing to the + * register. + */ +static int load_all_bypass_attenuator(const struct i2c_client *client, + u8 *config2) +{ + u8 config2_copy = *config2; + + if (!of_get_property(client->dev.of_node, + "bypass-attenuator-all", NULL)) + return 0; + + config2_copy |= (1 << 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) { @@ -1545,7 +1608,17 @@ static int adt7475_probe(struct i2c_client *client, } /* Voltage attenuators can be bypassed, globally or individually */ + if (chip == adt7476 || chip == adt7490) + if (load_individual_bypass_attenuators(client, + &(data->config4)) < 0) + dev_warn(&client->dev, + "Error setting bypass attenuator bits\n"); + config2 = adt7475_read(REG_CONFIG2); + if (chip == adt7476 || chip == adt7490) + if (load_all_bypass_attenuator(client, &config2) < 0) + dev_warn(&client->dev, "Error setting bypass all attenuator\n"); + if (config2 & CONFIG2_ATTN) { data->bypass_attn = (0x3 << 3) | 0x3; } else { From patchwork Thu Dec 19 03:32:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Logan Shaw X-Patchwork-Id: 11302617 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 1C2CF1593 for ; Thu, 19 Dec 2019 03:32:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id EE6572465E for ; Thu, 19 Dec 2019 03:32:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=alliedtelesis.co.nz header.i=@alliedtelesis.co.nz header.b="0IHvTuoV" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726795AbfLSDcT (ORCPT ); Wed, 18 Dec 2019 22:32:19 -0500 Received: from gate2.alliedtelesis.co.nz ([202.36.163.20]:57241 "EHLO gate2.alliedtelesis.co.nz" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726813AbfLSDcT (ORCPT ); Wed, 18 Dec 2019 22:32:19 -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 5CB39891AA; Thu, 19 Dec 2019 16:32:18 +1300 (NZDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alliedtelesis.co.nz; s=mail181024; t=1576726338; bh=QGGuWEOejvib1KsFRFTsduKYUrHgNswonePH3+UT11o=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=0IHvTuoVrB772z+i4BADQf2BQ85AQAyJ4wtE2MCsHos+5pWyhPKOQ2H6UWKcpieur +jWW28xstDrPCXqka44WRVRxDis6D90WqUl0DJ1pzxker3QI86xnu9KU8uWUNn2842 ahU0qrECGTot4rC7MysIm4L40ddPvsb0niyqrx3dxA9R8QGCfGUEY2TsLiHRUxC49T f58arASHqefut8ka/QElL97zFvRa/9LTB9+61Fw8M6of0d8Ke9UX4Doi4GENq8Xz7Z BhDg0IL1m6fr0XQJuVADOlOh18GIJ445etIol/29FPODpN1e+OEaIPxIDWnwddkWZA vC1SSiAT2F9TQ== Received: from smtp (Not Verified[10.32.16.33]) by mmarshal3.atlnz.lc with Trustwave SEG (v7,5,8,10121) id ; Thu, 19 Dec 2019 16:32:17 +1300 Received: from logans-dl.ws.atlnz.lc (logans-dl.ws.atlnz.lc [10.33.25.49]) by smtp (Postfix) with ESMTP id D8CA613EEAF; Thu, 19 Dec 2019 16:32:16 +1300 (NZDT) Received: by logans-dl.ws.atlnz.lc (Postfix, from userid 1820) id 30F2EC03C3; Thu, 19 Dec 2019 16:32:18 +1300 (NZDT) From: Logan Shaw To: jdelvare@suse.com, linux@roeck-us.net Cc: logan.shaw@alliedtelesis.co.nz, joshua.scott@alliedtelesis.co.nz, linux-hwmon@vger.kernel.org Subject: [PATCH v2 2/2] hwmon: (adt7475) Added attenuator bypass support Date: Thu, 19 Dec 2019 16:32:13 +1300 Message-Id: <20191219033213.30364-3-logan.shaw@alliedtelesis.co.nz> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191219033213.30364-1-logan.shaw@alliedtelesis.co.nz> References: <20191219033213.30364-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 five new properties to it. Signed-off-by: Logan Shaw --- --- .../devicetree/bindings/hwmon/adt7475.txt | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 Documentation/devicetree/bindings/hwmon/adt7475.txt diff --git a/Documentation/devicetree/bindings/hwmon/adt7475.txt b/Documentation/devicetree/bindings/hwmon/adt7475.txt new file mode 100644 index 000000000000..388dd718a246 --- /dev/null +++ b/Documentation/devicetree/bindings/hwmon/adt7475.txt @@ -0,0 +1,35 @@ +*ADT7475 hwmon sensor. + +Required properties: +- compatible: One of + "adi,adt7473" + "adi,adt7475" + "adi,adt7476" + "adi,adt7490" + +- reg: I2C address + +optional properties: + +- bypass-attenuator-all: Configures bypassing all voltage input attenuators. + This is only supported on the ADT7476 and ADT7490, this property does + nothing on other chips. + property present: Bit set to bypass all voltage input attenuators. + property absent: Registers left unchanged. + +- bypass-attenuator-inx: Configures bypassing individual voltage input + attenuators, where x is an integer from the set {0, 1, 3, 4}. This + is only supported on the ADT7476 and ADT7490, this property does nothing + on other chips. + property present: Bit set to bypass specific voltage input attenuator + for voltage input x. + property absent: Registers left unchanged. + +Example: + +hwmon@2e { + compatible = "adi,adt7475"; + reg = <0x2e>; + bypass-attenuator-all; + bypass-attenuator-in1; +}; \ No newline at end of file