From patchwork Mon Jan 9 23:35:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cormier X-Patchwork-Id: 41220 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp2441006wrt; Mon, 9 Jan 2023 15:38:28 -0800 (PST) X-Google-Smtp-Source: AMrXdXveGwvLExWBAEjOCrtfpNwFvsJXNrq54fA2dnZLAIcQg5yZMc1VRRL2Ls3SUPZ71i2rmNyF X-Received: by 2002:a17:90a:ab09:b0:219:dc24:7595 with SMTP id m9-20020a17090aab0900b00219dc247595mr67893431pjq.19.1673307507913; Mon, 09 Jan 2023 15:38:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673307507; cv=none; d=google.com; s=arc-20160816; b=Nl6Uo5o55CLMtr9Ro4DXuSw0Pbjo6IlM2jt9/Iwx2d8e2OWC/L8srfeCOazwNKqQJO nPkpmBYOkskLNbLmZLZ2E6uI6ItEqfhlFNZzrA41YGYuCds/FhVtvei27B8LLVoPyRV0 JgbQlj7M4c1DvjtxCIxaFZS6UVcTghtsMBcQg9xgAPLiT4KrkoMKPfH5kwqyOKp7z4PC WAdbv6raemGPPubux/c+Xeot/gtQc8HW0wBaOlW3hUItx0FLhf990/jJvxalxUGqmVYA Y+levz3NzOz5PDVb11OzrnTVXVaIxOhT6QR4CCxs3GLQI81Vj1gnYrYKC2nkif1hMiUu Xv8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=gWfOKCoKa6fVAUu6wQ1ieIdGSmrl8W8A2HgAxf0hwpE=; b=YWBPzqywzxToqaaeTtTK+HeFn+7g7R88euBao+MsAF34+UqGIYnZ/VBR0IbcH/ugVm z8kh6+xEWPB1zQJZ/V//t/6OGRx9DyCRTz+xuv8LVARUdWNcuDrJD2dohcTKhJvBkETD hJm6kWzmQgIc4u6GDs/N6dxoC9UPwMX7NK1dIyVUSmkYC8JXZskdThRzT6g/rPnnoCD+ uR8fZILahAgmqNFhlW7zmIjlhSV3oHzP0jQyc+uNpDRggP62GI7NX84hCMt3SnaorWhT b4bJkqHzTZWJItOzUiJJ3AQQDa8BsUB3mG3APJXUMWeIsq1DMyYCjwGaufVvRnathmXB S4FA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@criticallink.com header.s=google header.b=bvtIZBsz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=criticallink.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k14-20020a17090a590e00b002262f38c314si9433765pji.120.2023.01.09.15.38.15; Mon, 09 Jan 2023 15:38:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@criticallink.com header.s=google header.b=bvtIZBsz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=criticallink.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237848AbjAIXgD (ORCPT + 99 others); Mon, 9 Jan 2023 18:36:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58374 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235432AbjAIXf6 (ORCPT ); Mon, 9 Jan 2023 18:35:58 -0500 Received: from mail-qv1-xf2d.google.com (mail-qv1-xf2d.google.com [IPv6:2607:f8b0:4864:20::f2d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 35FCA6442 for ; Mon, 9 Jan 2023 15:35:57 -0800 (PST) Received: by mail-qv1-xf2d.google.com with SMTP id p17so7471181qvn.1 for ; Mon, 09 Jan 2023 15:35:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=criticallink.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=gWfOKCoKa6fVAUu6wQ1ieIdGSmrl8W8A2HgAxf0hwpE=; b=bvtIZBszxda3SApy+Vt245BDingr6VZTIE0uCE8ugMrSsv+pvqEUruYgswQfXSdXNC VAmuqsJCdrrXukhir+jfqy8l19M5PrfFk69mRqg9raoPIPug6x1o6cRVtZeAcf/lOLoW 7Cgg+TicuwJrkCt5Sqy5P5530IM+waDzfGZ1yMxP1Bhq+TjdXyNkEBDiPUXqqJtq5za/ 5ax6j0+xghsb2p/NVTdAbJPQrBnzzSRRzhpfdWhVDR20+0j0LFf7xuI7fjcJsyYZBgAd stdkfOLeBElQnrxjBCk5Qbkot5Uojaw2N8f1rxRdMveNL9PTyrPQK8hy1aaRoLP9lGgp EuWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gWfOKCoKa6fVAUu6wQ1ieIdGSmrl8W8A2HgAxf0hwpE=; b=XisB/2FSjLlRiIjA30/Bo2FX8FwVVTU+tVlVfRqw2O4EEmBmDB8Zb5MBZ0H8y+95Hq rT2SJRFrsO2Cha4FK4qkD1BYZjREPsdhX5/agRj0mN7A8MY3ntPHxni4XKiB5MCh03Jj PtEHCIgeYdZv/b3RFvCCNHtxluBwUbPUQNxrRjbRFXScSwI+8kgjN2/XAN2oHxq5PwX8 U8+JHL9vK7e0DePFfHPMAw6eL0PhDIf1w9MKiVK2QQTBe2zPzmcP68cYUXFsSUGqA91j z1X2A4sa7BI0NOpsK0v5IWLKuQl+mAOX3rjNeyMsrkSiAG9S/x2bFQA2go7myL7sldGo fxqg== X-Gm-Message-State: AFqh2kpqCr5q0ZcTstF1dgWCUBOk5IcW7PSdcOZEL7LqFvnVm01LrRrN PAhmxnVC9eb5PeIQNa8OE6JaBA== X-Received: by 2002:a05:6214:c6c:b0:50e:48cc:a95a with SMTP id t12-20020a0562140c6c00b0050e48cca95amr123111751qvj.43.1673307356280; Mon, 09 Jan 2023 15:35:56 -0800 (PST) Received: from jcormier-MS-7A93.syr.criticallink.com (static-72-90-70-109.syrcny.fios.verizon.net. [72.90.70.109]) by smtp.gmail.com with ESMTPSA id t5-20020a05620a450500b006fa8299b4d5sm6294846qkp.100.2023.01.09.15.35.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Jan 2023 15:35:55 -0800 (PST) From: Jonathan Cormier To: linux-hwmon@vger.kernel.org Cc: Jonathan Cormier , Jean Delvare , Guenter Roeck , linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Rob Herring , Krzysztof Kozlowski , Bob Duke , John Pruitt Subject: [PATCH v3 1/5] dt-bindings: hwmon: adi,ltc2945: Add binding Date: Mon, 9 Jan 2023 18:35:30 -0500 Message-Id: <20230109233534.1932370-2-jcormier@criticallink.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230109233534.1932370-1-jcormier@criticallink.com> References: <20221214220727.1350784-3-jcormier@criticallink.com> <20230109233534.1932370-1-jcormier@criticallink.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754590093480810557?= X-GMAIL-MSGID: =?utf-8?q?1754590093480810557?= Create initial binding for the LTC2945 I2C power monitor. Add shunt-resistor-micro-ohms parameter Signed-off-by: Jonathan Cormier Reviewed-by: Krzysztof Kozlowski --- .../bindings/hwmon/adi,ltc2945.yaml | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 Documentation/devicetree/bindings/hwmon/adi,ltc2945.yaml diff --git a/Documentation/devicetree/bindings/hwmon/adi,ltc2945.yaml b/Documentation/devicetree/bindings/hwmon/adi,ltc2945.yaml new file mode 100644 index 000000000000..5cb66e97e816 --- /dev/null +++ b/Documentation/devicetree/bindings/hwmon/adi,ltc2945.yaml @@ -0,0 +1,49 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/hwmon/adi,ltc2945.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Analog Devices LTC2945 wide range i2c power monitor + +maintainers: + - Guenter Roeck + +description: | + Analog Devices LTC2945 wide range i2c power monitor over I2C. + + https://www.analog.com/media/en/technical-documentation/data-sheets/LTC2945.pdf + +properties: + compatible: + enum: + - adi,ltc2945 + + reg: + maxItems: 1 + + shunt-resistor-micro-ohms: + description: + Shunt resistor value in micro-Ohms + default: 1000 + +required: + - compatible + - reg + +additionalProperties: false + +examples: + - | + i2c { + #address-cells = <1>; + #size-cells = <0>; + + power-monitor@6e { + compatible = "adi,ltc2945"; + reg = <0x6e>; + /* 10 milli-Ohm shunt resistor */ + shunt-resistor-micro-ohms = <10000>; + }; + }; +... From patchwork Mon Jan 9 23:35:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cormier X-Patchwork-Id: 41222 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp2441169wrt; Mon, 9 Jan 2023 15:38:56 -0800 (PST) X-Google-Smtp-Source: AMrXdXsYIKG0z2kl4Jm+uD5tCEmJPPIVtW1+gMNwmU9tulYZA0mZ5qS5maylBYWa1zqoVNtwOHWM X-Received: by 2002:a17:907:a08d:b0:7c1:6986:2b7c with SMTP id hu13-20020a170907a08d00b007c169862b7cmr51141915ejc.8.1673307536650; Mon, 09 Jan 2023 15:38:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673307536; cv=none; d=google.com; s=arc-20160816; b=vXqqzJIWxS0Xu/Yf34KajZwp/cjIqQPB7pAdnjW7Onp7H+J9apKKcWcLMtyXQVdd+F dyIg02Ss/jUg0JWLGjl4Wo47sYqJsjoOV5lNDNB0xonI8xqvdwYrJmp/hhgrqms9sjT5 OkhE+I5rz0VlVaDVnLBR0VDgvaNFUB2JiuoiWsDeCv97qVNezX2e4t7gdh7fAQjvAGTX OQWBcWOUfM1T6s6L5bgZUahk/fQD8KGpi3eXIypGdr9BXEVc1qwMGaWWJ2FpcTOF9vdN WAJfC/+N00Zp8i1tNakEPhz0IRcV7mpkqZBeVq9fLrsGv2xttUFidfIKnmjIBxCTpB3j s6+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=foqffIKuz799F5wyGtIM3OCFdqRESGZUJXSmZJH7pvM=; b=BvCsDeR6zFuKicNdqSZLSEMDwd6bASLQWXwHMGMpuuUxz6NnK9PC3+xBEnRVWP/vhH 5NbvCSMBk9iRRgyd6VjqU1pv+4u3bNI0KqiuLCO7C3aHX6o10oNv32w7OnCD9S6YKHNg 0cavAZ1Q6aXg/F0B6ilHInqaPgabnEQMGcxgYxIT5srBxprXWy9j/OmFu0lXnTtrvmwQ 1CyjKaeayeBRMA97xoJSwvQCwDk5L1Hp5G/BBaEdzH0mowdi2jKc9qKdE2C966zOc+oH BL5SHMHsYKLwB3re2FhwbUV3jMgzS/pDezXQqXanwWixPoguNSfqRrPr+Q0l5j3lG8No zfMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@criticallink.com header.s=google header.b=LW23jYdp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=criticallink.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sb40-20020a1709076da800b007baa6e2275asi11841409ejc.236.2023.01.09.15.38.32; Mon, 09 Jan 2023 15:38:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@criticallink.com header.s=google header.b=LW23jYdp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=criticallink.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237667AbjAIXgN (ORCPT + 99 others); Mon, 9 Jan 2023 18:36:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58376 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237780AbjAIXgB (ORCPT ); Mon, 9 Jan 2023 18:36:01 -0500 Received: from mail-qt1-x836.google.com (mail-qt1-x836.google.com [IPv6:2607:f8b0:4864:20::836]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5CB37CE38 for ; Mon, 9 Jan 2023 15:35:58 -0800 (PST) Received: by mail-qt1-x836.google.com with SMTP id h26so9585102qtu.2 for ; Mon, 09 Jan 2023 15:35:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=criticallink.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=foqffIKuz799F5wyGtIM3OCFdqRESGZUJXSmZJH7pvM=; b=LW23jYdpmTZPKAu1WNAQKdJrg5k7NJiFihuZiyYCDKpFVyPTxoX3R+4j2E/8C20sGz DdPxbKkkaAXqsaLfqLHBFijQTc6CYz4U5GpoJYjEsTG2PZKxaVtq3Tso9AiBDCHhXqV5 dq4q63L+CIGkpvTwRe98VF3jzL3qibGsXp6E2Bp4lvs5DB1lIG6ZTjSP4pDpVhX8L2nC L4XNW6VIMQsR9lcNlSxeJmkqwFkxnsgA5AbemvE2r/Ld4N8ubsHn0FDVZDZH2dK/oHJo FkzrdomLx36tBU+wDHxCLM7SJc/fIRMyhdh9dXD9cnbf7gFtv7nAktBx0YFhFZvEsrXs A5GA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=foqffIKuz799F5wyGtIM3OCFdqRESGZUJXSmZJH7pvM=; b=EbKnZ7jj9nD++5/3/ZbMnpp9fknE7IuZhoWDm0RBLx3ah0Thl9xtApOH514QpPZ6vL eIpfErqRemgJ49p3RC9QdnRK6S/8mYnIIfq8FqAykkITkKHABIxufNguXl4+kgcm+tY1 IjbBUKiEWYj/8lqZPo/ii01iHtCuPHE1S3DQuytgbLIQQVIuCFLJo5AlHdde/1+cklOL MlW9zJ3byWEi/wW7lIcIGYq9hYcr5hOWasrIvB3z+l/HgU9AY7Nht3O6QCKo8UrGeG3u ZQWA0nLQbr2HhD8KDS13SDtvovvOZIe+uLsDyNmAByunbyKCoaVURkLQ9b1YaTkmyG0r PH3A== X-Gm-Message-State: AFqh2kptqguVxRZTcTtpE0R5Kwl/LBpF5VT3noUGeSYY+Y1z8egx6qJf YAMxVk0ujiqz3X/cA/nNa1RECg== X-Received: by 2002:ac8:5557:0:b0:3ab:5b6d:1add with SMTP id o23-20020ac85557000000b003ab5b6d1addmr99038370qtr.66.1673307357915; Mon, 09 Jan 2023 15:35:57 -0800 (PST) Received: from jcormier-MS-7A93.syr.criticallink.com (static-72-90-70-109.syrcny.fios.verizon.net. [72.90.70.109]) by smtp.gmail.com with ESMTPSA id t5-20020a05620a450500b006fa8299b4d5sm6294846qkp.100.2023.01.09.15.35.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Jan 2023 15:35:57 -0800 (PST) From: Jonathan Cormier To: linux-hwmon@vger.kernel.org Cc: Jonathan Cormier , Jean Delvare , Guenter Roeck , linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Rob Herring , Krzysztof Kozlowski , Bob Duke , John Pruitt Subject: [PATCH v3 2/5] hwmon: ltc2945: Add devicetree match table Date: Mon, 9 Jan 2023 18:35:31 -0500 Message-Id: <20230109233534.1932370-3-jcormier@criticallink.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230109233534.1932370-1-jcormier@criticallink.com> References: <20221214220727.1350784-3-jcormier@criticallink.com> <20230109233534.1932370-1-jcormier@criticallink.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754590123695544465?= X-GMAIL-MSGID: =?utf-8?q?1754590123695544465?= Add adi,ltc2945 compatible Signed-off-by: Jonathan Cormier --- drivers/hwmon/ltc2945.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/hwmon/ltc2945.c b/drivers/hwmon/ltc2945.c index 9adebb59f604..9af3e3821152 100644 --- a/drivers/hwmon/ltc2945.c +++ b/drivers/hwmon/ltc2945.c @@ -58,6 +58,12 @@ #define CONTROL_MULT_SELECT (1 << 0) #define CONTROL_TEST_MODE (1 << 4) +static const struct of_device_id __maybe_unused ltc2945_of_match[] = { + { .compatible = "adi,ltc2945" }, + { } +}; +MODULE_DEVICE_TABLE(of, ltc2945_of_match); + static inline bool is_power_reg(u8 reg) { return reg < LTC2945_SENSE_H; @@ -475,8 +481,9 @@ MODULE_DEVICE_TABLE(i2c, ltc2945_id); static struct i2c_driver ltc2945_driver = { .driver = { - .name = "ltc2945", - }, + .name = "ltc2945", + .of_match_table = of_match_ptr(ltc2945_of_match), + }, .probe_new = ltc2945_probe, .id_table = ltc2945_id, }; From patchwork Mon Jan 9 23:35:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cormier X-Patchwork-Id: 41221 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp2441162wrt; Mon, 9 Jan 2023 15:38:55 -0800 (PST) X-Google-Smtp-Source: AMrXdXsrqUa6Z0+kEYHVmaP/5+8daNZNoZlF7EMu6EqYc+6fA1jio+c8UGuvdfFqLglOqOi131JZ X-Received: by 2002:a05:6402:3998:b0:46b:203:f388 with SMTP id fk24-20020a056402399800b0046b0203f388mr70256288edb.39.1673307535262; Mon, 09 Jan 2023 15:38:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673307535; cv=none; d=google.com; s=arc-20160816; b=eIXLEPS164KgTcTqh1oKVSAdBdpUSQcfXiPt+Nb9i5M8F+Dgx9mjki4Ainlojj6eGM QuKmJk/h5LeiyCFjYeO87OhHGsBZttgfF+xuoDCDShpUJbMw9GgsdLQuR5enhzWx6dF+ NwkuAiiIYybNCJE6uxzFbzzODWzpVOezOxvZ9jsouYzZ16Ma7vMcWY1vRnAa6Y0kLc8t FLiP9odpb8Gb/BZrLksKRY04xJ3LjvHKQlNLKT0vI/B72Ydr1o7Xod6i9wfPvpDSVLt2 BMTqe3FmWwL7XOD9oAbKpAwfOeJ/UW0lbaSulfklBpiEZXqlbtIEIHIAokdlxbZbVEGF Bm6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Omc6RJb75WehF9fTbabhEnE5DcQvC42CI90e1s9PLrk=; b=v0YCPSENB/UBgza0yoNASD5YAJzTsPsLJlejob4XeSdkthF8v7A8l4TJ/UONH5YDsF LfIM6JB6TuBwOw+aF2dJuj0yZDS8WVeduv7nmJb5vsuzslvUGmnw30HkDX3l2P6DbBuz VXVTHRexUPkRyaF8uwDThSi0hV9yYJ+Fi2RoRrBpILH3468BhKGEy3S56qtnVTipnEu0 M7EzbCOYTw3bMaWtOeKzAJHKXKdXu7yg3V/q6urEWaOmyOzLbm6USuC2I3BjjWq3QfQp 31dinx9lCnQ48MjTSdoTjFQyRb3CZ+RHzQG+P/LrYIyn68G4KNYK9lLf0SEggG4B02Y5 b1/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@criticallink.com header.s=google header.b=siN7GujK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=criticallink.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ef8-20020a05640228c800b00486ac69b9f3si9722658edb.327.2023.01.09.15.38.31; Mon, 09 Jan 2023 15:38:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@criticallink.com header.s=google header.b=siN7GujK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=criticallink.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237682AbjAIXgI (ORCPT + 99 others); Mon, 9 Jan 2023 18:36:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58512 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237851AbjAIXgD (ORCPT ); Mon, 9 Jan 2023 18:36:03 -0500 Received: from mail-qt1-x82b.google.com (mail-qt1-x82b.google.com [IPv6:2607:f8b0:4864:20::82b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6C51F10A9 for ; Mon, 9 Jan 2023 15:36:00 -0800 (PST) Received: by mail-qt1-x82b.google.com with SMTP id h26so9585159qtu.2 for ; Mon, 09 Jan 2023 15:36:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=criticallink.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Omc6RJb75WehF9fTbabhEnE5DcQvC42CI90e1s9PLrk=; b=siN7GujK+FUeCr1O9CoGS68J8NCUuh891jd428rzwVirnNPB7oC2DlSjmTSm8qIabm 4Kr2rS3D0QyFDcK+DybptVP8qF4AHpoXkE9+xX6TGlOz2M3kfVOJIYjkiWOycG1WhD7d 3++yAlvgrHbibGcQWIOQex/6Avqplc+Gi3n9Z88jNWozj45nCH9Wk0hIxyknVDmJu8WW Qg1oCYk/7P/Z6uo5vbhiiZ0XV0L4pIguflN4qPbqMjo+/kmDFOemsJVQSbnlnXgyk/Rb eIY26LrBkunXiEPKVeky1t+vm87yTROF5QClgnYHZOtGnzXkgkxfXblMnAu/7KCEJQWO JNNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Omc6RJb75WehF9fTbabhEnE5DcQvC42CI90e1s9PLrk=; b=0FvGFJshcv/j0JN7HXCxDm5qLLt6+a0AT05l6OdgiD7S2r7I8S9zWbFItCITBrsbyT IU5uqoSf/FWGVCfzcjcoF2CK5GLBzie18LAQGbyNx8cLiObPw5oFgFbiQqWuM7krYouh gGBOVisG7pXl4AKqsqtLQGWqUFbe5HMR8uFNJckQiQGe0oK/K0DPiC4aiaLODWS2Uiul iXr9c4WbZSzzQQ1L8u4qYIEZljk83GznGRSqaeJVgWhJoKftjZBq+SqHkZ8RqGy1Y4Bm M6c92XzhuA59JLM30Z+AUbrTogXoChwW35g/oiz/Xi2Oj4PU76Av25ogCaK56QSwZ0Za JeYA== X-Gm-Message-State: AFqh2kqaE+FMa/6Ki9RaBQ2lsZ7dxmhEjXCXIi0ZUNVlUD/8Gel6Zzii d11R7SJPKjo8QtErYQllro+EKQ== X-Received: by 2002:ac8:7551:0:b0:3a7:f46b:7a82 with SMTP id b17-20020ac87551000000b003a7f46b7a82mr85112283qtr.21.1673307359514; Mon, 09 Jan 2023 15:35:59 -0800 (PST) Received: from jcormier-MS-7A93.syr.criticallink.com (static-72-90-70-109.syrcny.fios.verizon.net. [72.90.70.109]) by smtp.gmail.com with ESMTPSA id t5-20020a05620a450500b006fa8299b4d5sm6294846qkp.100.2023.01.09.15.35.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Jan 2023 15:35:59 -0800 (PST) From: Jonathan Cormier To: linux-hwmon@vger.kernel.org Cc: Jonathan Cormier , Jean Delvare , Guenter Roeck , linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Rob Herring , Krzysztof Kozlowski , Bob Duke , John Pruitt Subject: [PATCH v3 3/5] hwmon: ltc2945: Handle error case in ltc2945_value_store Date: Mon, 9 Jan 2023 18:35:32 -0500 Message-Id: <20230109233534.1932370-4-jcormier@criticallink.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230109233534.1932370-1-jcormier@criticallink.com> References: <20221214220727.1350784-3-jcormier@criticallink.com> <20230109233534.1932370-1-jcormier@criticallink.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754590122129436543?= X-GMAIL-MSGID: =?utf-8?q?1754590122129436543?= ltc2945_val_to_reg errors were not being handled which would have resulted in register being set to 0 (clamped) instead of being left alone. Change reg_to_val and val_to_reg to return values via parameters to make it more obvious when an error case isn't handled. Also to allow the regval type to be the correct sign in prep for next commits. Fixes: 6700ce035f83 ("hwmon: Driver for Linear Technologies LTC2945") Signed-off-by: Jonathan Cormier --- drivers/hwmon/ltc2945.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/drivers/hwmon/ltc2945.c b/drivers/hwmon/ltc2945.c index 9af3e3821152..c66acf8d2124 100644 --- a/drivers/hwmon/ltc2945.c +++ b/drivers/hwmon/ltc2945.c @@ -70,12 +70,12 @@ static inline bool is_power_reg(u8 reg) } /* Return the value from the given register in uW, mV, or mA */ -static long long ltc2945_reg_to_val(struct device *dev, u8 reg) +static int ltc2945_reg_to_val(struct device *dev, u8 reg, u64 *regval) { struct regmap *regmap = dev_get_drvdata(dev); unsigned int control; u8 buf[3]; - long long val; + u64 val; int ret; ret = regmap_bulk_read(regmap, reg, buf, @@ -148,11 +148,12 @@ static long long ltc2945_reg_to_val(struct device *dev, u8 reg) default: return -EINVAL; } - return val; + *regval = val; + return 0; } static int ltc2945_val_to_reg(struct device *dev, u8 reg, - unsigned long val) + unsigned long val, unsigned long *regval) { struct regmap *regmap = dev_get_drvdata(dev); unsigned int control; @@ -220,19 +221,21 @@ static int ltc2945_val_to_reg(struct device *dev, u8 reg, default: return -EINVAL; } - return val; + *regval = val; + return 0; } static ssize_t ltc2945_value_show(struct device *dev, struct device_attribute *da, char *buf) { struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - long long value; + int ret; + u64 value; - value = ltc2945_reg_to_val(dev, attr->index); - if (value < 0) - return value; - return sysfs_emit(buf, "%lld\n", value); + ret = ltc2945_reg_to_val(dev, attr->index, &value); + if (ret < 0) + return ret; + return sysfs_emit(buf, "%llu\n", value); } static ssize_t ltc2945_value_store(struct device *dev, @@ -245,7 +248,7 @@ static ssize_t ltc2945_value_store(struct device *dev, unsigned long val; u8 regbuf[3]; int num_regs; - int regval; + unsigned long regval; int ret; ret = kstrtoul(buf, 10, &val); @@ -253,7 +256,10 @@ static ssize_t ltc2945_value_store(struct device *dev, return ret; /* convert to register value, then clamp and write result */ - regval = ltc2945_val_to_reg(dev, reg, val); + ret = ltc2945_val_to_reg(dev, reg, val, ®val); + if (ret < 0) + return ret; + if (is_power_reg(reg)) { regval = clamp_val(regval, 0, 0xffffff); regbuf[0] = regval >> 16; From patchwork Mon Jan 9 23:35:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cormier X-Patchwork-Id: 41223 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp2441253wrt; Mon, 9 Jan 2023 15:39:12 -0800 (PST) X-Google-Smtp-Source: AMrXdXsnEk8lv+5OAqJgjMP4BE3xJZ2OHI8HKVqcVFCSVa+d48NYIOti22ZN5pP9HDOzxP4hseWz X-Received: by 2002:a05:6402:1d98:b0:498:b9ea:1894 with SMTP id dk24-20020a0564021d9800b00498b9ea1894mr7168805edb.15.1673307552055; Mon, 09 Jan 2023 15:39:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673307552; cv=none; d=google.com; s=arc-20160816; b=0HxYE1bj6j2sRr0DH6hak8MT38iV6MlKlGmQ6c+xaIqVoP3jtqKWmSBrLU+LMb4dTb 3LdqHCp99sXbsT6XhdsYFSeqYoElbw9hJ5SkmiTJ1ArIVOHGdP+iGnoZYcs6CgNddrbQ K6QPmpdNRJGjwmsdWClbHc4GiHgz8jvmfNZMVF9Ju5+idO+t1ZETlqCMlxsmuzJXWnQv hNFBqBwsyBu4K5u3IUfLm7DOfR/L800BrN7ZlkNZ67QCKE/8+p+H6RcKCEWxMC7+PDx0 EiDm32VaAAgCLD43t8xRVabTbTlXCDZIPWs+jOOChs8XVZvyvcNsokfFzTYhC6aKlpJ+ HeMw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=4tt9ZKVvbkRyy+/76a2Ps7Ey7sKYXuH2yhPjmc2T/FY=; b=hagSi3gvjRKA+Hemi/g25T0HA16TIMYfkahm8+uebQXRJqZ2Z2iEpe5pPiAiP9MBeJ dq7w1IkKCq+STUWETbFHb3HiO7hOdTBxS1kPheKiv3lyaUktFJQ8e94Ex1Q8YIyz8Iq9 l46A4UEksQLiYkfhrQFEiW8W5MyD0SN56XwZeDTxy3skmREEBfh/6kmtk7lrRYO1mKMf ykAFV2ic/tpeoNkZfnVW03vATKDe+xmasatxL5j/kTXnzRXYp1MUh9KC4YyZYogUVhTT OZGwRQ5NFkA/3ZTe73LQwAq7a+x0wf7+QSlqM+6owJmsdKqawQDdeFaUGwSbnmtTegZk 3hyg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@criticallink.com header.s=google header.b=TgyNb8tl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=criticallink.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t5-20020aa7d4c5000000b00497326c9e1csi8977960edr.594.2023.01.09.15.38.47; Mon, 09 Jan 2023 15:39:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@criticallink.com header.s=google header.b=TgyNb8tl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=criticallink.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237928AbjAIXgQ (ORCPT + 99 others); Mon, 9 Jan 2023 18:36:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237692AbjAIXgG (ORCPT ); Mon, 9 Jan 2023 18:36:06 -0500 Received: from mail-qv1-xf33.google.com (mail-qv1-xf33.google.com [IPv6:2607:f8b0:4864:20::f33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D823AE74 for ; Mon, 9 Jan 2023 15:36:01 -0800 (PST) Received: by mail-qv1-xf33.google.com with SMTP id l14so3622447qvw.12 for ; Mon, 09 Jan 2023 15:36:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=criticallink.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=4tt9ZKVvbkRyy+/76a2Ps7Ey7sKYXuH2yhPjmc2T/FY=; b=TgyNb8tlCwb8NVJ6ze4x0xBiUvKgpq9zpFpAfS3Ox+7imoYvYLplE4gz6haj1OJMX7 k7Vg8JWDq3iR6dRmmx5EH1uGSrENw5CBAXxK66Of4yN8zR/pA+yZrQ2vT1716fTcZxb/ ps0IHaTqlvVBZTc/xlED4EPxQXJ0Y9qr5FuQ0/7Qzo9eufKHOr4UFxwJ8MKDPpgGyCM4 JyzLYI3UKc4oGIKq5xgEvZPXU4vu1ypcmawZ8FlqIABrxnJMjwLgCc+jFTNs6wbIDcVQ Xci/6rZhopDhwAguOa4ZrFWSXURMdEcft5zkAd+o2v/uH1Dm52BUQJEHu7SDfsMqNj7p HLMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4tt9ZKVvbkRyy+/76a2Ps7Ey7sKYXuH2yhPjmc2T/FY=; b=YyhgAkBLTUTh99bF6WvMdUiU9N2hmB4OSppXEHIQgAJP33cETpo2i1cvv1eDZHkk+t Iv5gPVuvfOZlDHKS5TiPJWimwzRhlJOC647lNFBTXhQBeoj17J6hYULNap+fifjNtkB+ U44XDN7pWCIAzqBLxsM1ThLaK5elSIINkoU86H+fe/SyAr/yxdKN/UD+HA+xOeoI5WUd PSBPpldJvY9iyGrrZIwtGebPEN2itNuNO9ZrNeAsrg6ei4esMVnzNJQOJJfTh/K/WHoh eWMLN8Nk8gi+SHbkRTAzpS5Ec6MdxGWZT/XzXeWoHJAyB6WFt0DFGayvZSxud/RCGmpt L2/A== X-Gm-Message-State: AFqh2koJnur2rhg/9celVJS4K0DlkfmQY88ivqnSl/xxMQgoHVc8A0LA 4CgnbksMLxsf8QjC9NE0QXSUMg== X-Received: by 2002:a0c:fba2:0:b0:531:e436:8e92 with SMTP id m2-20020a0cfba2000000b00531e4368e92mr29324882qvp.22.1673307360861; Mon, 09 Jan 2023 15:36:00 -0800 (PST) Received: from jcormier-MS-7A93.syr.criticallink.com (static-72-90-70-109.syrcny.fios.verizon.net. [72.90.70.109]) by smtp.gmail.com with ESMTPSA id t5-20020a05620a450500b006fa8299b4d5sm6294846qkp.100.2023.01.09.15.36.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Jan 2023 15:36:00 -0800 (PST) From: Jonathan Cormier To: linux-hwmon@vger.kernel.org Cc: John Pruitt , Jean Delvare , Guenter Roeck , linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Rob Herring , Krzysztof Kozlowski , Bob Duke , Jonathan Cormier Subject: [PATCH v3 4/5] hwmon: ltc2945: Allow setting shunt resistor Date: Mon, 9 Jan 2023 18:35:33 -0500 Message-Id: <20230109233534.1932370-5-jcormier@criticallink.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230109233534.1932370-1-jcormier@criticallink.com> References: <20221214220727.1350784-3-jcormier@criticallink.com> <20230109233534.1932370-1-jcormier@criticallink.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752229002631218550?= X-GMAIL-MSGID: =?utf-8?q?1754590139550515780?= From: John Pruitt Add the ability to specify the value of the shunt resistor in the device tree instead of assuming it is 1 milliOhm. The value in the device tree has the name shunt-resistor-micro-ohms and the default value is 1000 micro-ohms in order to preserve the current behavior. Signed-off-by: Jonathan Cormier Signed-off-by: John Pruitt --- drivers/hwmon/ltc2945.c | 85 +++++++++++++++++++++++++---------------- 1 file changed, 53 insertions(+), 32 deletions(-) diff --git a/drivers/hwmon/ltc2945.c b/drivers/hwmon/ltc2945.c index c66acf8d2124..0d743d75459c 100644 --- a/drivers/hwmon/ltc2945.c +++ b/drivers/hwmon/ltc2945.c @@ -64,6 +64,16 @@ static const struct of_device_id __maybe_unused ltc2945_of_match[] = { }; MODULE_DEVICE_TABLE(of, ltc2945_of_match); +/** + * struct ltc2945_data - LTC2945 device data + * @regmap: regmap device + * @shunt_resistor: shunt resistor value in micro ohms (1000 by default) + */ +struct ltc2945_data { + struct regmap *regmap; + u32 shunt_resistor; +}; + static inline bool is_power_reg(u8 reg) { return reg < LTC2945_SENSE_H; @@ -72,7 +82,9 @@ static inline bool is_power_reg(u8 reg) /* Return the value from the given register in uW, mV, or mA */ static int ltc2945_reg_to_val(struct device *dev, u8 reg, u64 *regval) { - struct regmap *regmap = dev_get_drvdata(dev); + struct ltc2945_data *data = dev_get_drvdata(dev); + struct regmap *regmap = data->regmap; + u32 shunt_resistor = data->shunt_resistor; unsigned int control; u8 buf[3]; u64 val; @@ -98,9 +110,7 @@ static int ltc2945_reg_to_val(struct device *dev, u8 reg, u64 *regval) case LTC2945_MAX_POWER_THRES_H: case LTC2945_MIN_POWER_THRES_H: /* - * Convert to uW by assuming current is measured with - * an 1mOhm sense resistor, similar to current - * measurements. + * Convert to uW * Control register bit 0 selects if voltage at SENSE+/VDD * or voltage at ADIN is used to measure power. */ @@ -114,6 +124,9 @@ static int ltc2945_reg_to_val(struct device *dev, u8 reg, u64 *regval) /* 0.5 mV * 25 uV = 0.0125 uV resolution. */ val = (val * 25LL) >> 1; } + val *= 1000; + val = DIV_ROUND_CLOSEST_ULL(val, shunt_resistor); + break; case LTC2945_VIN_H: case LTC2945_MAX_VIN_H: @@ -136,14 +149,9 @@ static int ltc2945_reg_to_val(struct device *dev, u8 reg, u64 *regval) case LTC2945_MIN_SENSE_H: case LTC2945_MAX_SENSE_THRES_H: case LTC2945_MIN_SENSE_THRES_H: - /* - * 25 uV resolution. Convert to current as measured with - * an 1 mOhm sense resistor, in mA. If a different sense - * resistor is installed, calculate the actual current by - * dividing the reported current by the sense resistor value - * in mOhm. - */ - val *= 25; + /* 25 uV resolution. Convert to mA. */ + val *= 25 * 1000; + val = DIV_ROUND_CLOSEST_ULL(val, shunt_resistor); break; default: return -EINVAL; @@ -153,9 +161,11 @@ static int ltc2945_reg_to_val(struct device *dev, u8 reg, u64 *regval) } static int ltc2945_val_to_reg(struct device *dev, u8 reg, - unsigned long val, unsigned long *regval) + u64 val, u64 *regval) { - struct regmap *regmap = dev_get_drvdata(dev); + struct ltc2945_data *data = dev_get_drvdata(dev); + struct regmap *regmap = data->regmap; + u32 shunt_resistor = data->shunt_resistor; unsigned int control; int ret; @@ -166,9 +176,6 @@ static int ltc2945_val_to_reg(struct device *dev, u8 reg, case LTC2945_MAX_POWER_THRES_H: case LTC2945_MIN_POWER_THRES_H: /* - * Convert to register value by assuming current is measured - * with an 1mOhm sense resistor, similar to current - * measurements. * Control register bit 0 selects if voltage at SENSE+/VDD * or voltage at ADIN is used to measure power, which in turn * determines register calculations. @@ -178,14 +185,16 @@ static int ltc2945_val_to_reg(struct device *dev, u8 reg, return ret; if (control & CONTROL_MULT_SELECT) { /* 25 mV * 25 uV = 0.625 uV resolution. */ - val = DIV_ROUND_CLOSEST(val, 625); + val *= shunt_resistor; + val = DIV_ROUND_CLOSEST_ULL(val, 625 * 1000); } else { /* * 0.5 mV * 25 uV = 0.0125 uV resolution. * Divide first to avoid overflow; * accept loss of accuracy. */ - val = DIV_ROUND_CLOSEST(val, 25) * 2; + val *= shunt_resistor; + val = DIV_ROUND_CLOSEST_ULL(val, 25 * 1000) * 2; } break; case LTC2945_VIN_H: @@ -209,14 +218,9 @@ static int ltc2945_val_to_reg(struct device *dev, u8 reg, case LTC2945_MIN_SENSE_H: case LTC2945_MAX_SENSE_THRES_H: case LTC2945_MIN_SENSE_THRES_H: - /* - * 25 uV resolution. Convert to current as measured with - * an 1 mOhm sense resistor, in mA. If a different sense - * resistor is installed, calculate the actual current by - * dividing the reported current by the sense resistor value - * in mOhm. - */ - val = DIV_ROUND_CLOSEST(val, 25); + /* 25 uV resolution. Convert to mA. */ + val *= shunt_resistor; + val = DIV_ROUND_CLOSEST_ULL(val, 25 * 1000); break; default: return -EINVAL; @@ -243,12 +247,13 @@ static ssize_t ltc2945_value_store(struct device *dev, const char *buf, size_t count) { struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - struct regmap *regmap = dev_get_drvdata(dev); + struct ltc2945_data *data = dev_get_drvdata(dev); + struct regmap *regmap = data->regmap; u8 reg = attr->index; unsigned long val; u8 regbuf[3]; int num_regs; - unsigned long regval; + u64 regval; int ret; ret = kstrtoul(buf, 10, &val); @@ -281,7 +286,8 @@ static ssize_t ltc2945_history_store(struct device *dev, const char *buf, size_t count) { struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - struct regmap *regmap = dev_get_drvdata(dev); + struct ltc2945_data *data = dev_get_drvdata(dev); + struct regmap *regmap = data->regmap; u8 reg = attr->index; int num_regs = is_power_reg(reg) ? 3 : 2; u8 buf_min[3] = { 0xff, 0xff, 0xff }; @@ -333,7 +339,8 @@ static ssize_t ltc2945_bool_show(struct device *dev, struct device_attribute *da, char *buf) { struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - struct regmap *regmap = dev_get_drvdata(dev); + struct ltc2945_data *data = dev_get_drvdata(dev); + struct regmap *regmap = data->regmap; unsigned int fault; int ret; @@ -462,6 +469,12 @@ static int ltc2945_probe(struct i2c_client *client) struct device *dev = &client->dev; struct device *hwmon_dev; struct regmap *regmap; + struct ltc2945_data *data; + + data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + if (!data) + return -ENOMEM; + dev_set_drvdata(dev, data); regmap = devm_regmap_init_i2c(client, <c2945_regmap_config); if (IS_ERR(regmap)) { @@ -469,11 +482,19 @@ static int ltc2945_probe(struct i2c_client *client) return PTR_ERR(regmap); } + data->regmap = regmap; + if (device_property_read_u32(dev, "shunt-resistor-micro-ohms", + &data->shunt_resistor)) + data->shunt_resistor = 1000; + + if (data->shunt_resistor == 0) + return -EINVAL; + /* Clear faults */ regmap_write(regmap, LTC2945_FAULT, 0x00); hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, - regmap, + data, ltc2945_groups); return PTR_ERR_OR_ZERO(hwmon_dev); } From patchwork Mon Jan 9 23:35:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cormier X-Patchwork-Id: 41224 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp2441342wrt; Mon, 9 Jan 2023 15:39:31 -0800 (PST) X-Google-Smtp-Source: AMrXdXvrBgaxk5ejW2hvvxw91sYjpBcK4NHFKYYnxlrWxBjeM4iocEo4Fz3vuNxE36xn51vo/zr8 X-Received: by 2002:a17:907:d684:b0:7c1:11fd:9b98 with SMTP id wf4-20020a170907d68400b007c111fd9b98mr58149801ejc.27.1673307571271; Mon, 09 Jan 2023 15:39:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673307571; cv=none; d=google.com; s=arc-20160816; b=U295/ztGQGGxIirOQs4pzxvWdqNsznLve7pISwlrEhn62lMnx6uaNwvtb1jsXA0SoU 9yIQY5x/f1g5hQ6lwHp4++VzqYTptdZFINePgPl2E4S5myXUCS3G2KirwUrSzALtBoyj 881pcPZgCL0Q2Z6CfoWUYRn8qA2IwdyD5/f/Y5qkkDQILA1Af8smMmhk6KZ33u8KKwq7 bDz/BEQoU+WPXThNNme/1FOFsfVPM9Jf94d4zGPS4xscI4T6kF4g98BKi0W+GkyvhIYQ uzfmObUxw3igUEcW/bg1+ziGQkL9ROlg0/kNlQZ0g7MpoUvcE62cW83zEwWk+hpPHbtf DBoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=tHdylmQcW9wYYsCa9wwYr0VU2Cu3mjkXydVxqDNSd7s=; b=BDW9DecwokKzdAO7/RXENwezbN6oKdl4aVuoJJ71XEgMpXW93Aw8aWXm4BshEerxub KAT8UHMlCWNLZUCy3HmUcgBuJHgr1HT6K2mho3UgVQ9cBfp5q1AryDug9eOHSsEuNTDK PnNbxJ9sSko0G5UYTNJUrApdjOqpjsXnXlCqbrIZag+wbjmcMZiRvyWXzzulZ1BTxaU7 MQOcu/pAabB11a3cEue1YCJD3xCDX1cXjcIq4zL8kAjEKgd8WezHdN43gbPPmUuFNg2V hj1psGVpNVqSdlVM3UN8LDETqk4xcsUmKJTs7z+XVaMpIAsmepvv1/84Fv0xCmoeV/AH +iLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@criticallink.com header.s=google header.b=IgpF0zOJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=criticallink.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hs22-20020a1709073e9600b0084c83fd7847si11408413ejc.102.2023.01.09.15.39.07; Mon, 09 Jan 2023 15:39:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@criticallink.com header.s=google header.b=IgpF0zOJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=criticallink.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237924AbjAIXgj (ORCPT + 99 others); Mon, 9 Jan 2023 18:36:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58668 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237627AbjAIXgJ (ORCPT ); Mon, 9 Jan 2023 18:36:09 -0500 Received: from mail-qt1-x82f.google.com (mail-qt1-x82f.google.com [IPv6:2607:f8b0:4864:20::82f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6DD1AF46 for ; Mon, 9 Jan 2023 15:36:03 -0800 (PST) Received: by mail-qt1-x82f.google.com with SMTP id g7so9609477qts.1 for ; Mon, 09 Jan 2023 15:36:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=criticallink.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=tHdylmQcW9wYYsCa9wwYr0VU2Cu3mjkXydVxqDNSd7s=; b=IgpF0zOJNGRyYHPgr14oe84dRF4bZ4IkqF/xVJTwejgGZZo5CdElnmDII9psWkdYdV VQgAkixF2ZeGL6DjydEyuZtNHfBmLn5rpdRFaqqVL6z6PTXvZGBtF2fg3LEBWOnKmrnD GRdkAhof4yATzA6aIyB0m9QnqDPh8pJZnSPX5VoFJfhoAK6iXoQFA/3N8coGLwXEfWIt H1fpOo3VaGy9D6L276k0b/V0maEo+T8b3eyXLn7gmkjhPLokinE0gtFt89rvOcRu/IiB JOulRj1Gu0ycfFA24YeJLNK2FoAMGqHZlXEZ5ywgdniFUq3JKfUlvxPa/A1U2rYYCjDJ SIMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tHdylmQcW9wYYsCa9wwYr0VU2Cu3mjkXydVxqDNSd7s=; b=NvKRZ7NOUElNvdlgrrCBwK5qhBvXBF/gksiYhSY0rdgmvbM/KbIB4Pxa5nMqgSezn5 5QiWosorppX5mUgYpg0svscLEHK596V66UCkvfe8EdL/fj0T8qwvyo95Al61BNOAj24V 5BrYGvW1dmAUhiD79MudXtWqayj885AlYhXze+RnR1s6TrQ0zkCVQXJxX8jJIXmcA761 L9LEtzHasTa2f3EWYWXPghpPdiarKsKAUDnuhl7aNQKkKKUDu+oJqPwqWo9rVGfcqiv2 Psin4UOcvtHIAYFqDDdvJfDCKG3LDte+w7TEMZNygefgCTH/ZQbxG1p96Vmh+CNk8k/R N5yw== X-Gm-Message-State: AFqh2kq05I2Vg76ZBBgL6shXo2a7iZoooMuOaRtkB/vDqyYXAi3Cd5/1 9Z1YhgrY407zC3Czg7I23fGPrA== X-Received: by 2002:a05:622a:1646:b0:3a7:f6cf:a597 with SMTP id y6-20020a05622a164600b003a7f6cfa597mr120230588qtj.33.1673307362569; Mon, 09 Jan 2023 15:36:02 -0800 (PST) Received: from jcormier-MS-7A93.syr.criticallink.com (static-72-90-70-109.syrcny.fios.verizon.net. [72.90.70.109]) by smtp.gmail.com with ESMTPSA id t5-20020a05620a450500b006fa8299b4d5sm6294846qkp.100.2023.01.09.15.36.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Jan 2023 15:36:02 -0800 (PST) From: Jonathan Cormier To: linux-hwmon@vger.kernel.org Cc: Jonathan Cormier , Jean Delvare , Guenter Roeck , linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Rob Herring , Krzysztof Kozlowski , Bob Duke , John Pruitt Subject: [PATCH v3 5/5] hwmon: ltc2945: Convert division to DIV_ROUND_CLOSEST_ULL Date: Mon, 9 Jan 2023 18:35:34 -0500 Message-Id: <20230109233534.1932370-6-jcormier@criticallink.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230109233534.1932370-1-jcormier@criticallink.com> References: <20221214220727.1350784-3-jcormier@criticallink.com> <20230109233534.1932370-1-jcormier@criticallink.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754590160203669093?= X-GMAIL-MSGID: =?utf-8?q?1754590160203669093?= Convert division to DIV_ROUND_CLOSEST_ULL to match code in same function Signed-off-by: Jonathan Cormier --- drivers/hwmon/ltc2945.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/hwmon/ltc2945.c b/drivers/hwmon/ltc2945.c index 0d743d75459c..5456c1b60b8b 100644 --- a/drivers/hwmon/ltc2945.c +++ b/drivers/hwmon/ltc2945.c @@ -203,7 +203,7 @@ static int ltc2945_val_to_reg(struct device *dev, u8 reg, case LTC2945_MAX_VIN_THRES_H: case LTC2945_MIN_VIN_THRES_H: /* 25 mV resolution. */ - val /= 25; + val = DIV_ROUND_CLOSEST_ULL(val, 25); break; case LTC2945_ADIN_H: case LTC2945_MAX_ADIN_H: