From patchwork Tue Aug 30 19:21:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Farber, Eliav" X-Patchwork-Id: 12959747 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 B4ABDC0502C for ; Tue, 30 Aug 2022 19:22:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230473AbiH3TWf (ORCPT ); Tue, 30 Aug 2022 15:22:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58856 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231415AbiH3TWa (ORCPT ); Tue, 30 Aug 2022 15:22:30 -0400 Received: from smtp-fw-6002.amazon.com (smtp-fw-6002.amazon.com [52.95.49.90]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A285479A4D; Tue, 30 Aug 2022 12:22:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1661887351; x=1693423351; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=/xEafGbvvLM6mTe9gueCvxwCuhsgXrHzO8tCpRpTbCA=; b=X/5MvdNAMz1mQHFYTRIOYBaJPhxFBhjQ1+bpsJspP4CAuqD210XLlG/4 qMjtvFTH40MAL1yKWAwKobD7f9bEvNJDMC2LBKUCC84EYAfOZs3zlxRfP EbIGF18XBIMH1gezIzHmMFe3sw4RRb5yBrA7R748uIc0po/n45hlSmjSM M=; X-IronPort-AV: E=Sophos;i="5.93,275,1654560000"; d="scan'208";a="239190591" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-iad-1e-54c9d11f.us-east-1.amazon.com) ([10.43.8.6]) by smtp-border-fw-6002.iad6.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Aug 2022 19:22:18 +0000 Received: from EX13D41EUC003.ant.amazon.com (iad12-ws-svc-p26-lb9-vlan2.iad.amazon.com [10.40.163.34]) by email-inbound-relay-iad-1e-54c9d11f.us-east-1.amazon.com (Postfix) with ESMTPS id 74192C0431; Tue, 30 Aug 2022 19:22:15 +0000 (UTC) Received: from EX13MTAUEE002.ant.amazon.com (10.43.62.24) by EX13D41EUC003.ant.amazon.com (10.43.164.188) with Microsoft SMTP Server (TLS) id 15.0.1497.38; Tue, 30 Aug 2022 19:22:14 +0000 Received: from dev-dsk-farbere-1a-46ecabed.eu-west-1.amazon.com (172.19.116.181) by mail-relay.amazon.com (10.43.62.224) with Microsoft SMTP Server id 15.0.1497.38 via Frontend Transport; Tue, 30 Aug 2022 19:22:13 +0000 Received: by dev-dsk-farbere-1a-46ecabed.eu-west-1.amazon.com (Postfix, from userid 14301484) id 5F3C14D47; Tue, 30 Aug 2022 19:22:12 +0000 (UTC) From: Eliav Farber To: , , , , , , , CC: , , , , , , , , , , , , , Subject: [PATCH v3 01/19] dt-bindings: hwmon: (mr75203) update "intel,vm-map" property to be optional Date: Tue, 30 Aug 2022 19:21:54 +0000 Message-ID: <20220830192212.28570-2-farbere@amazon.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220830192212.28570-1-farbere@amazon.com> References: <20220830192212.28570-1-farbere@amazon.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org Change "intel,vm-map" property to be optional instead of required. The driver implementation indicates it is not mandatory to have "intel,vm-map" in the device tree: - probe doesn't fail in case it is absent. - explicit comment in code - "Incase intel,vm-map property is not defined, we assume incremental channel numbers". Signed-off-by: Eliav Farber Acked-by: Rob Herring --- V3 -> V2: - Change this patch to be first in the series. - Add explanation why "intel,vm-map" is not required. Documentation/devicetree/bindings/hwmon/moortec,mr75203.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/Documentation/devicetree/bindings/hwmon/moortec,mr75203.yaml b/Documentation/devicetree/bindings/hwmon/moortec,mr75203.yaml index 6f3e3c01f717..6abde48b746e 100644 --- a/Documentation/devicetree/bindings/hwmon/moortec,mr75203.yaml +++ b/Documentation/devicetree/bindings/hwmon/moortec,mr75203.yaml @@ -48,7 +48,6 @@ required: - compatible - reg - reg-names - - intel,vm-map - clocks - resets - "#thermal-sensor-cells" From patchwork Tue Aug 30 19:21:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Farber, Eliav" X-Patchwork-Id: 12959748 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 A8D3FC3DA6B for ; Tue, 30 Aug 2022 19:22:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231445AbiH3TWf (ORCPT ); Tue, 30 Aug 2022 15:22:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58914 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231416AbiH3TWe (ORCPT ); Tue, 30 Aug 2022 15:22:34 -0400 Received: from smtp-fw-6001.amazon.com (smtp-fw-6001.amazon.com [52.95.48.154]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 93CFA79A77; Tue, 30 Aug 2022 12:22:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1661887353; x=1693423353; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=7ifH3cIa9Vk5bt+LS9w+ApFk4pQIlZ4NAZMRDJUWzoU=; b=fKHkZp2T/Mj9NhXDxIzLqIS05Xl1CwTe+wWKLMYEkT1iJx6ITLNVPue7 ZZCh6KGnMUrFE/o7EKSaCez2fwBvYYNjWxTwy5M3Sctw4f/N2qG46vs3V ftmVxmHf4n8bWZNyk0sZ4UnnyaMU4jHfGuKrmsypVJ2XlKDaoU7aRTsmA I=; Received: from iad12-co-svc-p1-lb1-vlan2.amazon.com (HELO email-inbound-relay-pdx-2a-e6c05252.us-west-2.amazon.com) ([10.43.8.2]) by smtp-border-fw-6001.iad6.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Aug 2022 19:22:18 +0000 Received: from EX13D37EUA001.ant.amazon.com (pdx1-ws-svc-p6-lb9-vlan2.pdx.amazon.com [10.236.137.194]) by email-inbound-relay-pdx-2a-e6c05252.us-west-2.amazon.com (Postfix) with ESMTPS id 13A8344E0E; Tue, 30 Aug 2022 19:22:17 +0000 (UTC) Received: from EX13MTAUEE002.ant.amazon.com (10.43.62.24) by EX13D37EUA001.ant.amazon.com (10.43.165.212) with Microsoft SMTP Server (TLS) id 15.0.1497.38; Tue, 30 Aug 2022 19:22:15 +0000 Received: from dev-dsk-farbere-1a-46ecabed.eu-west-1.amazon.com (172.19.116.181) by mail-relay.amazon.com (10.43.62.224) with Microsoft SMTP Server id 15.0.1497.38 via Frontend Transport; Tue, 30 Aug 2022 19:22:14 +0000 Received: by dev-dsk-farbere-1a-46ecabed.eu-west-1.amazon.com (Postfix, from userid 14301484) id 659724D45; Tue, 30 Aug 2022 19:22:12 +0000 (UTC) From: Eliav Farber To: , , , , , , , CC: , , , , , , , , , , , , , Subject: [PATCH v3 02/19] hwmon: (mr75203) fix VM sensor allocation when "intel,vm-map" not defined Date: Tue, 30 Aug 2022 19:21:55 +0000 Message-ID: <20220830192212.28570-3-farbere@amazon.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220830192212.28570-1-farbere@amazon.com> References: <20220830192212.28570-1-farbere@amazon.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org Bug fix - in case "intel,vm-map" is missing in device-tree ,'num' is set to 0, and no voltage channel infos are allocated. Signed-off-by: Eliav Farber --- drivers/hwmon/mr75203.c | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/drivers/hwmon/mr75203.c b/drivers/hwmon/mr75203.c index 046523d47c29..0e29877a1a9c 100644 --- a/drivers/hwmon/mr75203.c +++ b/drivers/hwmon/mr75203.c @@ -580,8 +580,6 @@ static int mr75203_probe(struct platform_device *pdev) } if (vm_num) { - u32 num = vm_num; - ret = pvt_get_regmap(pdev, "vm", pvt); if (ret) return ret; @@ -594,30 +592,28 @@ static int mr75203_probe(struct platform_device *pdev) ret = device_property_read_u8_array(dev, "intel,vm-map", pvt->vm_idx, vm_num); if (ret) { - num = 0; + /* + * Incase intel,vm-map property is not defined, we + * assume incremental channel numbers. + */ + for (i = 0; i < vm_num; i++) + pvt->vm_idx[i] = i; } else { for (i = 0; i < vm_num; i++) if (pvt->vm_idx[i] >= vm_num || - pvt->vm_idx[i] == 0xff) { - num = i; + pvt->vm_idx[i] == 0xff) break; - } - } - /* - * Incase intel,vm-map property is not defined, we assume - * incremental channel numbers. - */ - for (i = num; i < vm_num; i++) - pvt->vm_idx[i] = i; + vm_num = i; + } - in_config = devm_kcalloc(dev, num + 1, + in_config = devm_kcalloc(dev, vm_num + 1, sizeof(*in_config), GFP_KERNEL); if (!in_config) return -ENOMEM; - memset32(in_config, HWMON_I_INPUT, num); - in_config[num] = 0; + memset32(in_config, HWMON_I_INPUT, vm_num); + in_config[vm_num] = 0; pvt_in.config = in_config; pvt_info[index++] = &pvt_in; From patchwork Tue Aug 30 19:21:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Farber, Eliav" X-Patchwork-Id: 12959744 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 0CFF7ECAAA1 for ; Tue, 30 Aug 2022 19:22:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231211AbiH3TW3 (ORCPT ); Tue, 30 Aug 2022 15:22:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58836 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230330AbiH3TW3 (ORCPT ); Tue, 30 Aug 2022 15:22:29 -0400 Received: from smtp-fw-80006.amazon.com (smtp-fw-80006.amazon.com [99.78.197.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4BA4279A41; Tue, 30 Aug 2022 12:22:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1661887349; x=1693423349; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=dUAtUowfndtQUTld7zE3vvVQEMIwQJ09YELan4asaoM=; b=OytGhpZiE1ELjuy+aqrYQlFM8S7u5AaLmmtaXCmbcZe/ypaJYyvN0atz Ymn5IxZzMQ4qQR8Jm7MdoFZdSXAFZbS4lf7aGLPtvac27T4dydtgsFSj5 xZkjWhYMvIGvkKfdAc+rVUiXrzfYsMMdxWwMEt+Qi/q6zcHFGqD51gu2W 4=; X-IronPort-AV: E=Sophos;i="5.93,275,1654560000"; d="scan'208";a="124960444" Received: from pdx4-co-svc-p1-lb2-vlan2.amazon.com (HELO email-inbound-relay-pdx-2a-6a4112b2.us-west-2.amazon.com) ([10.25.36.210]) by smtp-border-fw-80006.pdx80.corp.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Aug 2022 19:22:17 +0000 Received: from EX13D37EUA002.ant.amazon.com (pdx1-ws-svc-p6-lb9-vlan2.pdx.amazon.com [10.236.137.194]) by email-inbound-relay-pdx-2a-6a4112b2.us-west-2.amazon.com (Postfix) with ESMTPS id 76EE84C014E; Tue, 30 Aug 2022 19:22:16 +0000 (UTC) Received: from EX13MTAUEB002.ant.amazon.com (10.43.60.12) by EX13D37EUA002.ant.amazon.com (10.43.165.200) with Microsoft SMTP Server (TLS) id 15.0.1497.38; Tue, 30 Aug 2022 19:22:15 +0000 Received: from dev-dsk-farbere-1a-46ecabed.eu-west-1.amazon.com (172.19.116.181) by mail-relay.amazon.com (10.43.60.234) with Microsoft SMTP Server id 15.0.1497.38 via Frontend Transport; Tue, 30 Aug 2022 19:22:13 +0000 Received: by dev-dsk-farbere-1a-46ecabed.eu-west-1.amazon.com (Postfix, from userid 14301484) id 60EB84D48; Tue, 30 Aug 2022 19:22:12 +0000 (UTC) From: Eliav Farber To: , , , , , , , CC: , , , , , , , , , , , , , Subject: [PATCH v3 03/19] hwmon: (mr75203) update pvt->v_num to the actual number of used sensors Date: Tue, 30 Aug 2022 19:21:56 +0000 Message-ID: <20220830192212.28570-4-farbere@amazon.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220830192212.28570-1-farbere@amazon.com> References: <20220830192212.28570-1-farbere@amazon.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org This issue is relevant when "intel,vm-map" is set in device-tree, and defines a lower number of VMs than actually supported. This change is needed for all places that use pvt->v_num later on in the code. Signed-off-by: Eliav Farber --- drivers/hwmon/mr75203.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/hwmon/mr75203.c b/drivers/hwmon/mr75203.c index 0e29877a1a9c..f89f7bb5d698 100644 --- a/drivers/hwmon/mr75203.c +++ b/drivers/hwmon/mr75203.c @@ -605,6 +605,7 @@ static int mr75203_probe(struct platform_device *pdev) break; vm_num = i; + pvt->v_num = i; } in_config = devm_kcalloc(dev, vm_num + 1, From patchwork Tue Aug 30 19:21:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Farber, Eliav" X-Patchwork-Id: 12959756 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 8DA24ECAAD8 for ; Tue, 30 Aug 2022 19:23:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229876AbiH3TXN (ORCPT ); Tue, 30 Aug 2022 15:23:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59116 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231517AbiH3TW5 (ORCPT ); Tue, 30 Aug 2022 15:22:57 -0400 Received: from smtp-fw-2101.amazon.com (smtp-fw-2101.amazon.com [72.21.196.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0B5947A767; Tue, 30 Aug 2022 12:22:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1661887364; x=1693423364; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=f5P3J3S9Ti1VFAfx1jGvICC/fceEslJWV21LViEEo3o=; b=CL7L4rxxWvkbgQQVEDkN79+mviKRlXR1BLovdI095XH/QqCftFRVW80v TohkVNlocsAtahIXOF8Zkkd66rrUBddtE8tvP2PXLfKKiRplLmgFrcIPe n7zCUA53Sr50beLO5BcWHyhvpZQDMEL/dZrYpuaT2yf2fJTUPrDJNFscj o=; X-IronPort-AV: E=Sophos;i="5.93,275,1654560000"; d="scan'208";a="235792568" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-iad-1e-b69ea591.us-east-1.amazon.com) ([10.43.8.6]) by smtp-border-fw-2101.iad2.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Aug 2022 19:22:42 +0000 Received: from EX13MTAUWA001.ant.amazon.com (iad12-ws-svc-p26-lb9-vlan2.iad.amazon.com [10.40.163.34]) by email-inbound-relay-iad-1e-b69ea591.us-east-1.amazon.com (Postfix) with ESMTPS id 1BEC6C02C3; Tue, 30 Aug 2022 19:22:38 +0000 (UTC) Received: from EX19D013UWA002.ant.amazon.com (10.13.138.210) by EX13MTAUWA001.ant.amazon.com (10.43.160.118) with Microsoft SMTP Server (TLS) id 15.0.1497.38; Tue, 30 Aug 2022 19:22:15 +0000 Received: from EX13MTAUWB001.ant.amazon.com (10.43.161.207) by EX19D013UWA002.ant.amazon.com (10.13.138.210) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1118.12; Tue, 30 Aug 2022 19:22:15 +0000 Received: from dev-dsk-farbere-1a-46ecabed.eu-west-1.amazon.com (172.19.116.181) by mail-relay.amazon.com (10.43.161.249) with Microsoft SMTP Server id 15.0.1497.38 via Frontend Transport; Tue, 30 Aug 2022 19:22:15 +0000 Received: by dev-dsk-farbere-1a-46ecabed.eu-west-1.amazon.com (Postfix, from userid 14301484) id 68F574D4A; Tue, 30 Aug 2022 19:22:12 +0000 (UTC) From: Eliav Farber To: , , , , , , , CC: , , , , , , , , , , , , , Subject: [PATCH v3 04/19] dt-bindings: hwmon: (mr75203) change "reset" property to be optional Date: Tue, 30 Aug 2022 19:21:57 +0000 Message-ID: <20220830192212.28570-5-farbere@amazon.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220830192212.28570-1-farbere@amazon.com> References: <20220830192212.28570-1-farbere@amazon.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org Change "reset" property to be optional instead of required, for SOCs that don't support a reset controller. Signed-off-by: Eliav Farber Reviewed-by: Philipp Zabel --- V3 -> v2: - Change "reset" property to be optional instead of adding new "reset-control-skip" property. Documentation/devicetree/bindings/hwmon/moortec,mr75203.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/Documentation/devicetree/bindings/hwmon/moortec,mr75203.yaml b/Documentation/devicetree/bindings/hwmon/moortec,mr75203.yaml index 6abde48b746e..2ec4b9da4b92 100644 --- a/Documentation/devicetree/bindings/hwmon/moortec,mr75203.yaml +++ b/Documentation/devicetree/bindings/hwmon/moortec,mr75203.yaml @@ -49,7 +49,6 @@ required: - reg - reg-names - clocks - - resets - "#thermal-sensor-cells" additionalProperties: false From patchwork Tue Aug 30 19:21:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Farber, Eliav" X-Patchwork-Id: 12959759 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 CD032ECAAD5 for ; Tue, 30 Aug 2022 19:23:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231680AbiH3TXc (ORCPT ); Tue, 30 Aug 2022 15:23:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230147AbiH3TXC (ORCPT ); Tue, 30 Aug 2022 15:23:02 -0400 Received: from smtp-fw-9102.amazon.com (smtp-fw-9102.amazon.com [207.171.184.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8FB437AC1A; Tue, 30 Aug 2022 12:22:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1661887365; x=1693423365; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ojfEjjcjmyVBMCaqrtlxjcSlC7XkksBMngN5dfWRcB4=; b=sL8kDR1CvmTTsWTf+5vLnCOYnKeBmNJuuPj0VH0kTMkNfFMU9K0X3Umk hvWZSDY0UWEVBq7RHRpMVQYlU35oJ5/LWsBnya/K/bDxBAVh1upt8C/L9 Ivv/3ocEuVSq1jv+MkhIetInU0PWdBZ3Qec7LycUu3w0hiRnUsz9jIjxH c=; X-IronPort-AV: E=Sophos;i="5.93,275,1654560000"; d="scan'208";a="254493537" Received: from pdx4-co-svc-p1-lb2-vlan2.amazon.com (HELO email-inbound-relay-iad-1d-f20e0c8b.us-east-1.amazon.com) ([10.25.36.210]) by smtp-border-fw-9102.sea19.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Aug 2022 19:22:43 +0000 Received: from EX13MTAUWA001.ant.amazon.com (iad12-ws-svc-p26-lb9-vlan3.iad.amazon.com [10.40.163.38]) by email-inbound-relay-iad-1d-f20e0c8b.us-east-1.amazon.com (Postfix) with ESMTPS id 353DDE15CC; Tue, 30 Aug 2022 19:22:38 +0000 (UTC) Received: from EX19D013UWA001.ant.amazon.com (10.13.138.253) by EX13MTAUWA001.ant.amazon.com (10.43.160.118) with Microsoft SMTP Server (TLS) id 15.0.1497.38; Tue, 30 Aug 2022 19:22:16 +0000 Received: from EX13MTAUWA001.ant.amazon.com (10.43.160.58) by EX19D013UWA001.ant.amazon.com (10.13.138.253) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1118.12; Tue, 30 Aug 2022 19:22:15 +0000 Received: from dev-dsk-farbere-1a-46ecabed.eu-west-1.amazon.com (172.19.116.181) by mail-relay.amazon.com (10.43.160.118) with Microsoft SMTP Server id 15.0.1497.38 via Frontend Transport; Tue, 30 Aug 2022 19:22:15 +0000 Received: by dev-dsk-farbere-1a-46ecabed.eu-west-1.amazon.com (Postfix, from userid 14301484) id 6A8F34D46; Tue, 30 Aug 2022 19:22:12 +0000 (UTC) From: Eliav Farber To: , , , , , , , CC: , , , , , , , , , , , , , Subject: [PATCH v3 05/19] hwmon: (mr75203) skip reset-control deassert for SOCs that don't support it Date: Tue, 30 Aug 2022 19:21:58 +0000 Message-ID: <20220830192212.28570-6-farbere@amazon.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220830192212.28570-1-farbere@amazon.com> References: <20220830192212.28570-1-farbere@amazon.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org Don't fail the probe function and don't deassert the reset controller if a "reset" property doesn't exist in the device tree. Change is done for SOCs that don't support a reset controller. Signed-off-by: Eliav Farber Reviewed-by: Philipp Zabel --- V3 -> v2: - Change "reset" property to be optional instead of skipping it. drivers/hwmon/mr75203.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/drivers/hwmon/mr75203.c b/drivers/hwmon/mr75203.c index f89f7bb5d698..901030125127 100644 --- a/drivers/hwmon/mr75203.c +++ b/drivers/hwmon/mr75203.c @@ -525,14 +525,17 @@ static int mr75203_probe(struct platform_device *pdev) return ret; } - pvt->rst = devm_reset_control_get_exclusive(dev, NULL); + pvt->rst = devm_reset_control_get_optional_exclusive(dev, NULL); if (IS_ERR(pvt->rst)) return dev_err_probe(dev, PTR_ERR(pvt->rst), "failed to get reset control\n"); - ret = pvt_reset_control_deassert(dev, pvt); - if (ret) - return dev_err_probe(dev, ret, "cannot deassert reset control\n"); + if (pvt->rst) { + ret = pvt_reset_control_deassert(dev, pvt); + if (ret) + return dev_err_probe(dev, ret, + "cannot deassert reset control\n"); + } ret = regmap_read(pvt->c_map, PVT_IP_CONFIG, &val); if(ret < 0) From patchwork Tue Aug 30 19:21:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Farber, Eliav" X-Patchwork-Id: 12959746 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 B3085ECAAD8 for ; Tue, 30 Aug 2022 19:22:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231263AbiH3TWd (ORCPT ); Tue, 30 Aug 2022 15:22:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58854 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231269AbiH3TWa (ORCPT ); Tue, 30 Aug 2022 15:22:30 -0400 Received: from smtp-fw-80006.amazon.com (smtp-fw-80006.amazon.com [99.78.197.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9E86F79A41; Tue, 30 Aug 2022 12:22:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1661887350; x=1693423350; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=CgCc/kIyAEbfD4l7q/Fx6aovclZtydu0RItcAhZsPf0=; b=l6MY9ZqqAPIUinSrBBQSVnFTkRLQwkJf+xDvDYD48PcA8YIkznMzAIS+ oTOy0+mZL1k9L/O8aYcb01eUG3xwy0SSlcvzUSUB0uy/3wd5J+ANtCI8K TFqEx5T0DakeTjBbnkS7losKCCGpBdYXG8Rsg+1SxR3n8MfjDlUnurSv1 c=; X-IronPort-AV: E=Sophos;i="5.93,275,1654560000"; d="scan'208";a="124960453" Received: from pdx4-co-svc-p1-lb2-vlan2.amazon.com (HELO email-inbound-relay-pdx-2a-6a4112b2.us-west-2.amazon.com) ([10.25.36.210]) by smtp-border-fw-80006.pdx80.corp.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Aug 2022 19:22:18 +0000 Received: from EX13D44EUB004.ant.amazon.com (pdx1-ws-svc-p6-lb9-vlan2.pdx.amazon.com [10.236.137.194]) by email-inbound-relay-pdx-2a-6a4112b2.us-west-2.amazon.com (Postfix) with ESMTPS id 048C64C014E; Tue, 30 Aug 2022 19:22:17 +0000 (UTC) Received: from EX13MTAUEB002.ant.amazon.com (10.43.60.12) by EX13D44EUB004.ant.amazon.com (10.43.166.198) with Microsoft SMTP Server (TLS) id 15.0.1497.38; Tue, 30 Aug 2022 19:22:15 +0000 Received: from dev-dsk-farbere-1a-46ecabed.eu-west-1.amazon.com (172.19.116.181) by mail-relay.amazon.com (10.43.60.234) with Microsoft SMTP Server id 15.0.1497.38 via Frontend Transport; Tue, 30 Aug 2022 19:22:14 +0000 Received: by dev-dsk-farbere-1a-46ecabed.eu-west-1.amazon.com (Postfix, from userid 14301484) id 6752B4D44; Tue, 30 Aug 2022 19:22:12 +0000 (UTC) From: Eliav Farber To: , , , , , , , CC: , , , , , , , , , , , , , Subject: [PATCH v3 06/19] hwmon: (mr75203) fix multi-channel voltage reading Date: Tue, 30 Aug 2022 19:21:59 +0000 Message-ID: <20220830192212.28570-7-farbere@amazon.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220830192212.28570-1-farbere@amazon.com> References: <20220830192212.28570-1-farbere@amazon.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org Fix voltage allocation and reading to support all channels in all VMs. Prior to this change allocation and reading were done only for the first channel in each VM. This change counts the total number of channels for allocation, and takes into account the channel offset when reading the sample data register. Signed-off-by: Eliav Farber --- V3 -> V2: - Remove configuration of ip-polling register to a separate commit. - Explain the fix. drivers/hwmon/mr75203.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/drivers/hwmon/mr75203.c b/drivers/hwmon/mr75203.c index 901030125127..639f5a300170 100644 --- a/drivers/hwmon/mr75203.c +++ b/drivers/hwmon/mr75203.c @@ -68,8 +68,9 @@ /* VM Individual Macro Register */ #define VM_COM_REG_SIZE 0x200 -#define VM_SDIF_DONE(n) (VM_COM_REG_SIZE + 0x34 + 0x200 * (n)) -#define VM_SDIF_DATA(n) (VM_COM_REG_SIZE + 0x40 + 0x200 * (n)) +#define VM_SDIF_DONE(vm) (VM_COM_REG_SIZE + 0x34 + 0x200 * (vm)) +#define VM_SDIF_DATA(vm, ch) \ + (VM_COM_REG_SIZE + 0x40 + 0x200 * (vm) + 0x4 * (ch)) /* SDA Slave Register */ #define IP_CTRL 0x00 @@ -115,6 +116,7 @@ struct pvt_device { u32 t_num; u32 p_num; u32 v_num; + u32 c_num; u32 ip_freq; u8 *vm_idx; }; @@ -179,13 +181,14 @@ static int pvt_read_in(struct device *dev, u32 attr, int channel, long *val) struct pvt_device *pvt = dev_get_drvdata(dev); struct regmap *v_map = pvt->v_map; u32 n, stat; - u8 vm_idx; + u8 vm_idx, ch_idx; int ret; - if (channel >= pvt->v_num) + if (channel >= pvt->v_num * pvt->c_num) return -EINVAL; - vm_idx = pvt->vm_idx[channel]; + vm_idx = pvt->vm_idx[channel / pvt->c_num]; + ch_idx = channel % pvt->c_num; switch (attr) { case hwmon_in_input: @@ -196,7 +199,7 @@ static int pvt_read_in(struct device *dev, u32 attr, int channel, long *val) if (ret) return ret; - ret = regmap_read(v_map, VM_SDIF_DATA(vm_idx), &n); + ret = regmap_read(v_map, VM_SDIF_DATA(vm_idx, ch_idx), &n); if(ret < 0) return ret; @@ -500,7 +503,7 @@ static int pvt_reset_control_deassert(struct device *dev, struct pvt_device *pvt static int mr75203_probe(struct platform_device *pdev) { const struct hwmon_channel_info **pvt_info; - u32 ts_num, vm_num, pd_num, val, index, i; + u32 ts_num, vm_num, pd_num, ch_num, val, index, i; struct device *dev = &pdev->dev; u32 *temp_config, *in_config; struct device *hwmon_dev; @@ -544,9 +547,11 @@ static int mr75203_probe(struct platform_device *pdev) ts_num = (val & TS_NUM_MSK) >> TS_NUM_SFT; pd_num = (val & PD_NUM_MSK) >> PD_NUM_SFT; vm_num = (val & VM_NUM_MSK) >> VM_NUM_SFT; + ch_num = (val & CH_NUM_MSK) >> CH_NUM_SFT; pvt->t_num = ts_num; pvt->p_num = pd_num; pvt->v_num = vm_num; + pvt->c_num = ch_num; val = 0; if (ts_num) val++; @@ -583,6 +588,8 @@ static int mr75203_probe(struct platform_device *pdev) } if (vm_num) { + u32 total_ch = ch_num * vm_num; + ret = pvt_get_regmap(pdev, "vm", pvt); if (ret) return ret; @@ -611,13 +618,13 @@ static int mr75203_probe(struct platform_device *pdev) pvt->v_num = i; } - in_config = devm_kcalloc(dev, vm_num + 1, + in_config = devm_kcalloc(dev, total_ch + 1, sizeof(*in_config), GFP_KERNEL); if (!in_config) return -ENOMEM; - memset32(in_config, HWMON_I_INPUT, vm_num); - in_config[vm_num] = 0; + memset32(in_config, HWMON_I_INPUT, total_ch); + in_config[total_ch] = 0; pvt_in.config = in_config; pvt_info[index++] = &pvt_in; From patchwork Tue Aug 30 19:22:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Farber, Eliav" X-Patchwork-Id: 12959750 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 C4622ECAAA1 for ; Tue, 30 Aug 2022 19:22:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231371AbiH3TWk (ORCPT ); Tue, 30 Aug 2022 15:22:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58916 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231438AbiH3TWf (ORCPT ); Tue, 30 Aug 2022 15:22:35 -0400 Received: from smtp-fw-9102.amazon.com (smtp-fw-9102.amazon.com [207.171.184.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D78F379ECC; Tue, 30 Aug 2022 12:22:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1661887354; x=1693423354; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=7/V2KgNUUkyeEZdK4TEB8Ma46trE3WXZnGJEBdvfnUo=; b=fB2hSouuf6k9p117l5GbbQWD2pSfOLVXWX9Vsa37ooGk0FmJyZfslhNM Lgu/MBVNPM+9HPIewX6bdz7dR6XPh2xUdt60kEKJFa6ulf6avjnO3LPUL EsI/JuaN/Ie7BJUIejix8huHsjAj7eslXNJkzS2j40II8kBeIte66X6Xm E=; X-IronPort-AV: E=Sophos;i="5.93,275,1654560000"; d="scan'208";a="254493396" Received: from pdx4-co-svc-p1-lb2-vlan2.amazon.com (HELO email-inbound-relay-iad-1e-90d70b14.us-east-1.amazon.com) ([10.25.36.210]) by smtp-border-fw-9102.sea19.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Aug 2022 19:22:17 +0000 Received: from EX13D44EUC001.ant.amazon.com (iad12-ws-svc-p26-lb9-vlan3.iad.amazon.com [10.40.163.38]) by email-inbound-relay-iad-1e-90d70b14.us-east-1.amazon.com (Postfix) with ESMTPS id 0E541C02CA; Tue, 30 Aug 2022 19:22:16 +0000 (UTC) Received: from EX13MTAUEE002.ant.amazon.com (10.43.62.24) by EX13D44EUC001.ant.amazon.com (10.43.164.236) with Microsoft SMTP Server (TLS) id 15.0.1497.38; Tue, 30 Aug 2022 19:22:15 +0000 Received: from dev-dsk-farbere-1a-46ecabed.eu-west-1.amazon.com (172.19.116.181) by mail-relay.amazon.com (10.43.62.224) with Microsoft SMTP Server id 15.0.1497.38 via Frontend Transport; Tue, 30 Aug 2022 19:22:14 +0000 Received: by dev-dsk-farbere-1a-46ecabed.eu-west-1.amazon.com (Postfix, from userid 14301484) id 61BA24D3F; Tue, 30 Aug 2022 19:22:12 +0000 (UTC) From: Eliav Farber To: , , , , , , , CC: , , , , , , , , , , , , , Subject: [PATCH v3 07/19] hwmon: (mr75203) enable polling for all VM channels Date: Tue, 30 Aug 2022 19:22:00 +0000 Message-ID: <20220830192212.28570-8-farbere@amazon.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220830192212.28570-1-farbere@amazon.com> References: <20220830192212.28570-1-farbere@amazon.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org Configure ip-polling register to enable polling for all voltage monitor channels. This enables reading the voltage values for all inputs other than just input 0. Signed-off-by: Eliav Farber --- V3 -> V2: - Move configuration of ip-polling register from previous patch to a separate commit. drivers/hwmon/mr75203.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/drivers/hwmon/mr75203.c b/drivers/hwmon/mr75203.c index 639f5a300170..f561806c400d 100644 --- a/drivers/hwmon/mr75203.c +++ b/drivers/hwmon/mr75203.c @@ -388,6 +388,20 @@ static int pvt_init(struct pvt_device *pvt) if (ret) return ret; + val = GENMASK(pvt->c_num - 1, 0) | VM_CH_INIT | + IP_POLL << SDIF_ADDR_SFT | + SDIF_WRN_W | SDIF_PROG; + ret = regmap_write(v_map, SDIF_W, val); + if (ret < 0) + return ret; + + ret = regmap_read_poll_timeout(v_map, SDIF_STAT, + val, !(val & SDIF_BUSY), + PVT_POLL_DELAY_US, + PVT_POLL_TIMEOUT_US); + if (ret) + return ret; + val = CFG1_VOL_MEAS_MODE | CFG1_PARALLEL_OUT | CFG1_14_BIT | IP_CFG << SDIF_ADDR_SFT | SDIF_WRN_W | SDIF_PROG; From patchwork Tue Aug 30 19:22:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Farber, Eliav" X-Patchwork-Id: 12959757 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 EEB6AECAAA1 for ; Tue, 30 Aug 2022 19:23:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231634AbiH3TXW (ORCPT ); Tue, 30 Aug 2022 15:23:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59048 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229504AbiH3TXB (ORCPT ); Tue, 30 Aug 2022 15:23:01 -0400 Received: from smtp-fw-80007.amazon.com (smtp-fw-80007.amazon.com [99.78.197.218]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 958FA7A77F; Tue, 30 Aug 2022 12:22:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1661887364; x=1693423364; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=H+Q3pIefoo5VmiPth3Y5fvRbYEtr+wi/MT5kM6bWw7A=; b=X3tSpAP9FxpZQZgw4vzh5D+bINAzfC3DY5lejeJVFsiZqzvfIKlWI/fZ a4Teuu+ChvoDOHQ/X5nzyNCPCUQbe6fDrPA0tg3S81zGKID+pLqqp7G27 g+6hjcbZt8iw+duMe5QIhvY8ZcDt4+yL+2TTGw3F/bfLW7dSkBnNp5Q3K o=; X-IronPort-AV: E=Sophos;i="5.93,275,1654560000"; d="scan'208";a="125055935" Received: from pdx4-co-svc-p1-lb2-vlan3.amazon.com (HELO email-inbound-relay-iad-1e-8be8ed69.us-east-1.amazon.com) ([10.25.36.214]) by smtp-border-fw-80007.pdx80.corp.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Aug 2022 19:22:42 +0000 Received: from EX13MTAUWA001.ant.amazon.com (iad12-ws-svc-p26-lb9-vlan3.iad.amazon.com [10.40.163.38]) by email-inbound-relay-iad-1e-8be8ed69.us-east-1.amazon.com (Postfix) with ESMTPS id C81DCC084B; Tue, 30 Aug 2022 19:22:38 +0000 (UTC) Received: from EX19D013UWA003.ant.amazon.com (10.13.138.202) by EX13MTAUWA001.ant.amazon.com (10.43.160.118) with Microsoft SMTP Server (TLS) id 15.0.1497.38; Tue, 30 Aug 2022 19:22:15 +0000 Received: from EX13MTAUWA001.ant.amazon.com (10.43.160.58) by EX19D013UWA003.ant.amazon.com (10.13.138.202) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1118.12; Tue, 30 Aug 2022 19:22:15 +0000 Received: from dev-dsk-farbere-1a-46ecabed.eu-west-1.amazon.com (172.19.116.181) by mail-relay.amazon.com (10.43.160.118) with Microsoft SMTP Server id 15.0.1497.38 via Frontend Transport; Tue, 30 Aug 2022 19:22:15 +0000 Received: by dev-dsk-farbere-1a-46ecabed.eu-west-1.amazon.com (Postfix, from userid 14301484) id 666674D3E; Tue, 30 Aug 2022 19:22:12 +0000 (UTC) From: Eliav Farber To: , , , , , , , CC: , , , , , , , , , , , , , Subject: [PATCH v3 08/19] dt-bindings: hwmon: (mr75203) add "moortec,vm-active-channels" property Date: Tue, 30 Aug 2022 19:22:01 +0000 Message-ID: <20220830192212.28570-9-farbere@amazon.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220830192212.28570-1-farbere@amazon.com> References: <20220830192212.28570-1-farbere@amazon.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org Add optional "moortec,vm-active-channels" property to define the number of active channels per VM. This shall be useful to avoid exposing sysfs for reading inputs that are not connected to any voltage source. Signed-off-by: Eliav Farber --- V3 -> V2: - Add "moortec" prefix to property name. - Add explanation why this change is needed. .../devicetree/bindings/hwmon/moortec,mr75203.yaml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Documentation/devicetree/bindings/hwmon/moortec,mr75203.yaml b/Documentation/devicetree/bindings/hwmon/moortec,mr75203.yaml index 2ec4b9da4b92..69cc6caceb2c 100644 --- a/Documentation/devicetree/bindings/hwmon/moortec,mr75203.yaml +++ b/Documentation/devicetree/bindings/hwmon/moortec,mr75203.yaml @@ -44,6 +44,16 @@ properties: "#thermal-sensor-cells": const: 1 + moortec,vm-active-channels: + description: + moortec,vm-active-channels defines the number of channels per VM that are + actually used and are connected to some source. + Number of values in the array should be the number of VMs. + A value of 0 means that the entire VM sensor is nou used. + maximum: 16 + default: 16 + $ref: /schemas/types.yaml#definitions/uint8-array + required: - compatible - reg @@ -65,5 +75,6 @@ examples: intel,vm-map = [03 01 04 ff ff]; clocks = <&osc0>; resets = <&rcu0 0x40 7>; + moortec,vm-active-channels = <0x10 0x05>; #thermal-sensor-cells = <1>; }; From patchwork Tue Aug 30 19:22:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Farber, Eliav" X-Patchwork-Id: 12959755 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 F3B14ECAAD8 for ; Tue, 30 Aug 2022 19:23:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231567AbiH3TXL (ORCPT ); Tue, 30 Aug 2022 15:23:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58988 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230480AbiH3TWy (ORCPT ); Tue, 30 Aug 2022 15:22:54 -0400 Received: from smtp-fw-9102.amazon.com (smtp-fw-9102.amazon.com [207.171.184.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D0D137A53A; Tue, 30 Aug 2022 12:22:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1661887362; x=1693423362; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=bZviscXsfHKd1zp3p5HYJW1ERgEaJLRtXjTPhnyPpBc=; b=jwQV2L2cfGpB4sHUNnKtwD3TLkFXVBJztX4RUa+y6UXww5suvGtMv1Rk k1e+vw4rXRyzwlRs6f4fcK7wVI2Rly3MagyuLVbY0yNyBqOFSvFKFQW6r DvdBYADE4SrZSrWhDxZdc3mmqJ/Epzd+fLk0+ljLIkLkvc+Vi8bD7fpUU E=; X-IronPort-AV: E=Sophos;i="5.93,275,1654560000"; d="scan'208";a="254493530" Received: from pdx4-co-svc-p1-lb2-vlan2.amazon.com (HELO email-inbound-relay-iad-1d-9a235a16.us-east-1.amazon.com) ([10.25.36.210]) by smtp-border-fw-9102.sea19.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Aug 2022 19:22:40 +0000 Received: from EX13MTAUWA001.ant.amazon.com (iad12-ws-svc-p26-lb9-vlan3.iad.amazon.com [10.40.163.38]) by email-inbound-relay-iad-1d-9a235a16.us-east-1.amazon.com (Postfix) with ESMTPS id 89EB080242; Tue, 30 Aug 2022 19:22:38 +0000 (UTC) Received: from EX19D013UWA004.ant.amazon.com (10.13.138.207) by EX13MTAUWA001.ant.amazon.com (10.43.160.118) with Microsoft SMTP Server (TLS) id 15.0.1497.38; Tue, 30 Aug 2022 19:22:15 +0000 Received: from EX13MTAUWA001.ant.amazon.com (10.43.160.58) by EX19D013UWA004.ant.amazon.com (10.13.138.207) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1118.12; Tue, 30 Aug 2022 19:22:15 +0000 Received: from dev-dsk-farbere-1a-46ecabed.eu-west-1.amazon.com (172.19.116.181) by mail-relay.amazon.com (10.43.160.118) with Microsoft SMTP Server id 15.0.1497.38 via Frontend Transport; Tue, 30 Aug 2022 19:22:15 +0000 Received: by dev-dsk-farbere-1a-46ecabed.eu-west-1.amazon.com (Postfix, from userid 14301484) id 64D084D4F; Tue, 30 Aug 2022 19:22:12 +0000 (UTC) From: Eliav Farber To: , , , , , , , CC: , , , , , , , , , , , , , Subject: [PATCH v3 09/19] hwmon: (mr75203) add VM active channel support Date: Tue, 30 Aug 2022 19:22:02 +0000 Message-ID: <20220830192212.28570-10-farbere@amazon.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220830192212.28570-1-farbere@amazon.com> References: <20220830192212.28570-1-farbere@amazon.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org Add active channel support per voltage monitor. The number of active channels is read from the device-tree. When absent in device-tree, all channels are assumed to be used. This shall be useful to expose sysfs only for inputs that are connected to a voltage source. Setting number of active channels to 0, means that entire VM sensor is not used. Signed-off-by: Eliav Farber --- V3 -> V2: - Refactor the code changes (move code to a new function and group parameters in dedicated structure). V2 -> V1: - Fix compilation error for patch 08/16: "warning: ISO C90 forbids variable length array" drivers/hwmon/mr75203.c | 107 ++++++++++++++++++++++++++++++++-------- 1 file changed, 86 insertions(+), 21 deletions(-) diff --git a/drivers/hwmon/mr75203.c b/drivers/hwmon/mr75203.c index f561806c400d..6925e8490587 100644 --- a/drivers/hwmon/mr75203.c +++ b/drivers/hwmon/mr75203.c @@ -29,6 +29,8 @@ #define CH_NUM_MSK GENMASK(31, 24) #define CH_NUM_SFT 24 +#define VM_NUM_MAX (VM_NUM_MSK >> VM_NUM_SFT) + /* Macro Common Register */ #define CLK_SYNTH 0x00 #define CLK_SYNTH_LO_SFT 0 @@ -106,6 +108,16 @@ #define PVT_N_CONST 90 #define PVT_R_CONST 245805 +struct voltage_device { + u32 vm_map; /* Map channel number to VM index */ + u32 ch_map; /* Map channel number to channel index */ +}; + +struct voltage_channels { + u32 total; /* Total number of channels in all VMs */ + u8 max; /* Maximum number of channels among all VMs */ +}; + struct pvt_device { struct regmap *c_map; struct regmap *t_map; @@ -113,12 +125,12 @@ struct pvt_device { struct regmap *v_map; struct clk *clk; struct reset_control *rst; + struct voltage_device *vd; + struct voltage_channels vm_channels; u32 t_num; u32 p_num; u32 v_num; - u32 c_num; u32 ip_freq; - u8 *vm_idx; }; static umode_t pvt_is_visible(const void *data, enum hwmon_sensor_types type, @@ -184,11 +196,11 @@ static int pvt_read_in(struct device *dev, u32 attr, int channel, long *val) u8 vm_idx, ch_idx; int ret; - if (channel >= pvt->v_num * pvt->c_num) + if (channel >= pvt->vm_channels.total) return -EINVAL; - vm_idx = pvt->vm_idx[channel / pvt->c_num]; - ch_idx = channel % pvt->c_num; + vm_idx = pvt->vd[channel].vm_map; + ch_idx = pvt->vd[channel].ch_map; switch (attr) { case hwmon_in_input: @@ -388,7 +400,7 @@ static int pvt_init(struct pvt_device *pvt) if (ret) return ret; - val = GENMASK(pvt->c_num - 1, 0) | VM_CH_INIT | + val = GENMASK(pvt->vm_channels.max - 1, 0) | VM_CH_INIT | IP_POLL << SDIF_ADDR_SFT | SDIF_WRN_W | SDIF_PROG; ret = regmap_write(v_map, SDIF_W, val); @@ -514,6 +526,62 @@ static int pvt_reset_control_deassert(struct device *dev, struct pvt_device *pvt return devm_add_action_or_reset(dev, pvt_reset_control_assert, pvt); } +static int pvt_get_active_channel(struct device *dev, struct pvt_device *pvt, + u32 vm_num, u32 ch_num, u8 *vm_idx) +{ + u8 vm_active_ch[VM_NUM_MAX]; + int ret, i, j, k; + + ret = device_property_read_u8_array(dev, "moortec,vm-active-channels", + vm_active_ch, vm_num); + if (ret) { + /* + * Incase vm-active-channels property is not defined, + * we assume each VM sensor has all of its channels + * active. + */ + for (i = 0; i < vm_num; i++) + vm_active_ch[i] = ch_num; + + pvt->vm_channels.max = ch_num; + pvt->vm_channels.total = ch_num * vm_num; + } else { + for (i = 0; i < vm_num; i++) { + if (vm_active_ch[i] > ch_num) { + dev_err(dev, "invalid active channels: %u\n", + vm_active_ch[i]); + return -EINVAL; + } + + pvt->vm_channels.total += vm_active_ch[i]; + + if (vm_active_ch[i] > pvt->vm_channels.max) + pvt->vm_channels.max = vm_active_ch[i]; + } + } + + /* + * Map between the channel-number to VM-index and channel-index. + * Example - 3 VMs, vm_active_ch = [05 02 04]: + * vm_map = [0 0 0 0 0 1 1 2 2 2 2] + * ch_map = [0 1 2 3 4 0 1 0 1 2 3] + */ + pvt->vd = devm_kcalloc(dev, pvt->vm_channels.total, sizeof(*pvt->vd), + GFP_KERNEL); + if (!pvt->vd) + return -ENOMEM; + + k = 0; + for (i = 0; i < vm_num; i++) + for (j = 0; j < vm_active_ch[i]; j++) { + pvt->vd[k].vm_map = vm_idx[i]; + pvt->vd[k].ch_map = j; + k++; + } + + return 0; +} + static int mr75203_probe(struct platform_device *pdev) { const struct hwmon_channel_info **pvt_info; @@ -565,7 +633,6 @@ static int mr75203_probe(struct platform_device *pdev) pvt->t_num = ts_num; pvt->p_num = pd_num; pvt->v_num = vm_num; - pvt->c_num = ch_num; val = 0; if (ts_num) val++; @@ -602,43 +669,41 @@ static int mr75203_probe(struct platform_device *pdev) } if (vm_num) { - u32 total_ch = ch_num * vm_num; + u8 vm_idx[VM_NUM_MAX]; ret = pvt_get_regmap(pdev, "vm", pvt); if (ret) return ret; - pvt->vm_idx = devm_kcalloc(dev, vm_num, sizeof(*pvt->vm_idx), - GFP_KERNEL); - if (!pvt->vm_idx) - return -ENOMEM; - - ret = device_property_read_u8_array(dev, "intel,vm-map", - pvt->vm_idx, vm_num); + ret = device_property_read_u8_array(dev, "intel,vm-map", vm_idx, + vm_num); if (ret) { /* * Incase intel,vm-map property is not defined, we * assume incremental channel numbers. */ for (i = 0; i < vm_num; i++) - pvt->vm_idx[i] = i; + vm_idx[i] = i; } else { for (i = 0; i < vm_num; i++) - if (pvt->vm_idx[i] >= vm_num || - pvt->vm_idx[i] == 0xff) + if (vm_idx[i] >= vm_num || vm_idx[i] == 0xff) break; vm_num = i; pvt->v_num = i; } - in_config = devm_kcalloc(dev, total_ch + 1, + ret = pvt_get_active_channel(dev, pvt, vm_num, ch_num, vm_idx); + if (ret) + return ret; + + in_config = devm_kcalloc(dev, pvt->vm_channels.total + 1, sizeof(*in_config), GFP_KERNEL); if (!in_config) return -ENOMEM; - memset32(in_config, HWMON_I_INPUT, total_ch); - in_config[total_ch] = 0; + memset32(in_config, HWMON_I_INPUT, pvt->vm_channels.total); + in_config[pvt->vm_channels.total] = 0; pvt_in.config = in_config; pvt_info[index++] = &pvt_in; From patchwork Tue Aug 30 19:22:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Farber, Eliav" X-Patchwork-Id: 12959752 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 F27E5ECAAD5 for ; Tue, 30 Aug 2022 19:22:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231269AbiH3TWm (ORCPT ); Tue, 30 Aug 2022 15:22:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59024 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231453AbiH3TWh (ORCPT ); Tue, 30 Aug 2022 15:22:37 -0400 Received: from smtp-fw-9103.amazon.com (smtp-fw-9103.amazon.com [207.171.188.200]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B9AA479A77; Tue, 30 Aug 2022 12:22:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1661887355; x=1693423355; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=uZ5Kav3Eb8Y3l4mIN9Xlarp03YVDMTfsrhtTfsYkWOw=; b=lA4a/YtY5ndOijPL/rrcqb0ysn8KbF4lNbaIue1Jt1zVAqUymM8dzHRy y2l1DBqjq/GlO909cQIio8JDeTcUzK7Oapf0cqnL7Jb76xatB9ew7QVRc TKfpZKBgXKpWBjsoRBzEX9Rzj8mlK8YCO40PwwpTjvzuKQGYb+0c037Wu c=; X-IronPort-AV: E=Sophos;i="5.93,275,1654560000"; d="scan'208";a="1049654954" Received: from pdx4-co-svc-p1-lb2-vlan3.amazon.com (HELO email-inbound-relay-pdx-2a-92ba9394.us-west-2.amazon.com) ([10.25.36.214]) by smtp-border-fw-9103.sea19.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Aug 2022 19:22:19 +0000 Received: from EX13MTAUWB001.ant.amazon.com (pdx1-ws-svc-p6-lb9-vlan3.pdx.amazon.com [10.236.137.198]) by email-inbound-relay-pdx-2a-92ba9394.us-west-2.amazon.com (Postfix) with ESMTPS id F09DE4531D; Tue, 30 Aug 2022 19:22:18 +0000 (UTC) Received: from EX19D013UWB004.ant.amazon.com (10.13.138.62) by EX13MTAUWB001.ant.amazon.com (10.43.161.207) with Microsoft SMTP Server (TLS) id 15.0.1497.38; Tue, 30 Aug 2022 19:22:15 +0000 Received: from EX13MTAUWB001.ant.amazon.com (10.43.161.207) by EX19D013UWB004.ant.amazon.com (10.13.138.62) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.2.1118.12; Tue, 30 Aug 2022 19:22:15 +0000 Received: from dev-dsk-farbere-1a-46ecabed.eu-west-1.amazon.com (172.19.116.181) by mail-relay.amazon.com (10.43.161.249) with Microsoft SMTP Server id 15.0.1497.38 via Frontend Transport; Tue, 30 Aug 2022 19:22:15 +0000 Received: by dev-dsk-farbere-1a-46ecabed.eu-west-1.amazon.com (Postfix, from userid 14301484) id 69C594D40; Tue, 30 Aug 2022 19:22:12 +0000 (UTC) From: Eliav Farber To: , , , , , , , CC: , , , , , , , , , , , , , Subject: [PATCH v3 10/19] dt-bindings: hwmon: (mr75203) add "moortec,vm-pre-scaler" property Date: Tue, 30 Aug 2022 19:22:03 +0000 Message-ID: <20220830192212.28570-11-farbere@amazon.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220830192212.28570-1-farbere@amazon.com> References: <20220830192212.28570-1-farbere@amazon.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org Add support for mr76006 pre-scaler which provides divide-by-2 scaling of input voltage, which can then be presented for VM for measurement within its range (the VM input range is limited to -0.1V to 1V). The new "moortec,vm-pre-scaler" property lists the channels that use a pre-scaler. The driver will use this list to multiply the voltage result by 2, to present to the user the actual voltage input source. Signed-off-by: Eliav Farber --- V3 -> V2: - Add "moortec" prefix to property name. - Change property format to be a single u8 array. - Fix typo: scalar --> scaler. .../devicetree/bindings/hwmon/moortec,mr75203.yaml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Documentation/devicetree/bindings/hwmon/moortec,mr75203.yaml b/Documentation/devicetree/bindings/hwmon/moortec,mr75203.yaml index 69cc6caceb2c..4c983d8f8fe7 100644 --- a/Documentation/devicetree/bindings/hwmon/moortec,mr75203.yaml +++ b/Documentation/devicetree/bindings/hwmon/moortec,mr75203.yaml @@ -54,6 +54,16 @@ properties: default: 16 $ref: /schemas/types.yaml#definitions/uint8-array + moortec,vm-pre-scaler: + description: + moortec,vm-pre-scaler property is an array of channels that use a mr76006 + pre-scaler to divides the input source by 2. + The pre-scaler is used for input sources that exceed the VM input range. + The driver uses this information to present to the user the actual value + of the voltage source. + default: 1 + $ref: /schemas/types.yaml#definitions/uint8-array + required: - compatible - reg @@ -76,5 +86,6 @@ examples: clocks = <&osc0>; resets = <&rcu0 0x40 7>; moortec,vm-active-channels = <0x10 0x05>; + moortec,vm-pre-scaler = <5 6>; #thermal-sensor-cells = <1>; }; From patchwork Tue Aug 30 19:22:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Farber, Eliav" X-Patchwork-Id: 12959753 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 10305ECAAA1 for ; Tue, 30 Aug 2022 19:22:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231480AbiH3TWn (ORCPT ); Tue, 30 Aug 2022 15:22:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59038 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231461AbiH3TWh (ORCPT ); Tue, 30 Aug 2022 15:22:37 -0400 Received: from smtp-fw-80007.amazon.com (smtp-fw-80007.amazon.com [99.78.197.218]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CAFF679A7B; Tue, 30 Aug 2022 12:22:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1661887356; x=1693423356; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=OY7VLVa2TpEEvpaKzDB+Hlk4tGYxU6BP/Z21DvqRTqE=; b=SUbY8Bmlws3GnMW6KwHH2TPQpYyHVYU6ST6/pd/HRtv3gK9GGVaBGdx0 runp8brxknCNGGQ++8X39aQ4zd/ocHoIovUoAOaq5B8aePzQ0vJ9qZbEu Uhp4YvxTCzji992ZPUjdOyMOK86IvNkXXRpLjhjHaGNvt509oTDB9BDlJ k=; X-IronPort-AV: E=Sophos;i="5.93,275,1654560000"; d="scan'208";a="125055812" Received: from pdx4-co-svc-p1-lb2-vlan3.amazon.com (HELO email-inbound-relay-iad-1d-54a073b7.us-east-1.amazon.com) ([10.25.36.214]) by smtp-border-fw-80007.pdx80.corp.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Aug 2022 19:22:19 +0000 Received: from EX13D44EUB003.ant.amazon.com (iad12-ws-svc-p26-lb9-vlan3.iad.amazon.com [10.40.163.38]) by email-inbound-relay-iad-1d-54a073b7.us-east-1.amazon.com (Postfix) with ESMTPS id 80F5B803A7; Tue, 30 Aug 2022 19:22:16 +0000 (UTC) Received: from EX19D019EUB004.ant.amazon.com (10.252.51.91) by EX13D44EUB003.ant.amazon.com (10.43.166.64) with Microsoft SMTP Server (TLS) id 15.0.1497.38; Tue, 30 Aug 2022 19:22:14 +0000 Received: from EX13MTAUEB002.ant.amazon.com (10.43.60.12) by EX19D019EUB004.ant.amazon.com (10.252.51.91) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.2.1118.12; Tue, 30 Aug 2022 19:22:14 +0000 Received: from dev-dsk-farbere-1a-46ecabed.eu-west-1.amazon.com (172.19.116.181) by mail-relay.amazon.com (10.43.60.234) with Microsoft SMTP Server id 15.0.1497.38 via Frontend Transport; Tue, 30 Aug 2022 19:22:13 +0000 Received: by dev-dsk-farbere-1a-46ecabed.eu-west-1.amazon.com (Postfix, from userid 14301484) id 5E6D44D49; Tue, 30 Aug 2022 19:22:12 +0000 (UTC) From: Eliav Farber To: , , , , , , , CC: , , , , , , , , , , , , , Subject: [PATCH v3 11/19] hwmon: (mr75203) add VM pre-scaler support Date: Tue, 30 Aug 2022 19:22:04 +0000 Message-ID: <20220830192212.28570-12-farbere@amazon.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220830192212.28570-1-farbere@amazon.com> References: <20220830192212.28570-1-farbere@amazon.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org Add mr76006 pre-scaler support to normalize the voltage output result for channels that use pre-scaler units to get the measurement to be within the range that the sensor supports. For channels that are listed in the device-tree to have a pre-scaler, the voltage result is multiplied by a factor of 2, to represent to the user the actual voltage source which is measured. Signed-off-by: Eliav Farber --- V3 -> V2: - Modify code according to new property format. drivers/hwmon/mr75203.c | 64 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 62 insertions(+), 2 deletions(-) diff --git a/drivers/hwmon/mr75203.c b/drivers/hwmon/mr75203.c index 6925e8490587..1cd5ff6eacce 100644 --- a/drivers/hwmon/mr75203.c +++ b/drivers/hwmon/mr75203.c @@ -13,10 +13,12 @@ #include #include #include +#include #include #include #include #include +#include /* PVT Common register */ #define PVT_IP_CONFIG 0x04 @@ -108,9 +110,13 @@ #define PVT_N_CONST 90 #define PVT_R_CONST 245805 +#define PRE_SCALER_X1 1 +#define PRE_SCALER_X2 2 + struct voltage_device { u32 vm_map; /* Map channel number to VM index */ u32 ch_map; /* Map channel number to channel index */ + u32 pre_scaler; }; struct voltage_channels { @@ -192,7 +198,7 @@ static int pvt_read_in(struct device *dev, u32 attr, int channel, long *val) { struct pvt_device *pvt = dev_get_drvdata(dev); struct regmap *v_map = pvt->v_map; - u32 n, stat; + u32 n, stat, pre_scaler; u8 vm_idx, ch_idx; int ret; @@ -217,7 +223,9 @@ static int pvt_read_in(struct device *dev, u32 attr, int channel, long *val) n &= SAMPLE_DATA_MSK; /* Convert the N bitstream count into voltage */ - *val = (PVT_N_CONST * n - PVT_R_CONST) >> PVT_CONV_BITS; + pre_scaler = pvt->vd[channel].pre_scaler; + *val = pre_scaler * (PVT_N_CONST * n - PVT_R_CONST) >> + PVT_CONV_BITS; return 0; default: @@ -582,6 +590,54 @@ static int pvt_get_active_channel(struct device *dev, struct pvt_device *pvt, return 0; } +static int pvt_get_pre_scaler(struct device *dev, struct pvt_device *pvt) +{ + const struct device_node *np = dev->of_node; + u32 total_channels = pvt->vm_channels.total; + u32 channel; + u8 *pre_scaler_ch_list; + int i, ret, num_ch; + + /* Set default pre-scaler value to be 1. */ + for (i = 0; i < total_channels; i++) + pvt->vd[i].pre_scaler = PRE_SCALER_X1; + + /* Get number of channels configured in "moortec,vm-pre-scaler". */ + num_ch = of_property_count_u8_elems(np, "moortec,vm-pre-scaler"); + if (num_ch <= 0) + return 0; + + pre_scaler_ch_list = kcalloc(total_channels, + sizeof(*pre_scaler_ch_list), GFP_KERNEL); + if (!pre_scaler_ch_list) + return -ENOMEM; + + /* Get list of all channels that have pre-scaler of 2. */ + ret = device_property_read_u8_array(dev, "moortec,vm-pre-scaler", + pre_scaler_ch_list, num_ch); + if (ret) + goto out; + + for (i = 0; i < num_ch; i++) { + channel = pre_scaler_ch_list[i]; + + if (channel >= total_channels) { + dev_err(dev, + "invalid channel (%u) in pre-scaler list\n", + channel); + ret = -EINVAL; + goto out; + } + + pvt->vd[channel].pre_scaler = PRE_SCALER_X2; + } + +out: + kfree(pre_scaler_ch_list); + + return ret; +} + static int mr75203_probe(struct platform_device *pdev) { const struct hwmon_channel_info **pvt_info; @@ -697,6 +753,10 @@ static int mr75203_probe(struct platform_device *pdev) if (ret) return ret; + ret = pvt_get_pre_scaler(dev, pvt); + if (ret) + return ret; + in_config = devm_kcalloc(dev, pvt->vm_channels.total + 1, sizeof(*in_config), GFP_KERNEL); if (!in_config) From patchwork Tue Aug 30 19:22:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Farber, Eliav" X-Patchwork-Id: 12959745 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 30571ECAAD5 for ; Tue, 30 Aug 2022 19:22:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231299AbiH3TWa (ORCPT ); Tue, 30 Aug 2022 15:22:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58842 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230462AbiH3TW3 (ORCPT ); Tue, 30 Aug 2022 15:22:29 -0400 Received: from smtp-fw-80006.amazon.com (smtp-fw-80006.amazon.com [99.78.197.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 10B4879A46; Tue, 30 Aug 2022 12:22:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1661887349; x=1693423349; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=7jM9bxUFTiRFdN9eRnLAR3tNYJTs9bs57sY6eoa56LY=; b=KrrF4f0AGaOWgbevgpIQ/SPBB5lDbTbNFdast7FE3XaziHc4A3tEeJ2v 4k0l0uJ62DIWYV6leEFfuVdHpTy4Qve8lnDjfztTN81wDzGErapWSLrgJ vCNHNrWjwSzqm6Y0srA3yHPG3uhinq8fiDNQjz9TwmJyzTBGL23P6r6MO 8=; X-IronPort-AV: E=Sophos;i="5.93,275,1654560000"; d="scan'208";a="124960433" Received: from pdx4-co-svc-p1-lb2-vlan2.amazon.com (HELO email-inbound-relay-pdx-2c-4213ea4c.us-west-2.amazon.com) ([10.25.36.210]) by smtp-border-fw-80006.pdx80.corp.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Aug 2022 19:22:15 +0000 Received: from EX13MTAUWB001.ant.amazon.com (pdx1-ws-svc-p6-lb9-vlan3.pdx.amazon.com [10.236.137.198]) by email-inbound-relay-pdx-2c-4213ea4c.us-west-2.amazon.com (Postfix) with ESMTPS id 7544B81573; Tue, 30 Aug 2022 19:22:14 +0000 (UTC) Received: from EX19D013UWB001.ant.amazon.com (10.13.138.52) by EX13MTAUWB001.ant.amazon.com (10.43.161.249) with Microsoft SMTP Server (TLS) id 15.0.1497.38; Tue, 30 Aug 2022 19:22:14 +0000 Received: from EX13MTAUWB001.ant.amazon.com (10.43.161.207) by EX19D013UWB001.ant.amazon.com (10.13.138.52) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1118.12; Tue, 30 Aug 2022 19:22:13 +0000 Received: from dev-dsk-farbere-1a-46ecabed.eu-west-1.amazon.com (172.19.116.181) by mail-relay.amazon.com (10.43.161.249) with Microsoft SMTP Server id 15.0.1497.38 via Frontend Transport; Tue, 30 Aug 2022 19:22:13 +0000 Received: by dev-dsk-farbere-1a-46ecabed.eu-west-1.amazon.com (Postfix, from userid 14301484) id 6024C4D39; Tue, 30 Aug 2022 19:22:12 +0000 (UTC) From: Eliav Farber To: , , , , , , , CC: , , , , , , , , , , , , , Subject: [PATCH v3 12/19] hwmon: (mr75203) fix voltage equation for negative source input Date: Tue, 30 Aug 2022 19:22:05 +0000 Message-ID: <20220830192212.28570-13-farbere@amazon.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220830192212.28570-1-farbere@amazon.com> References: <20220830192212.28570-1-farbere@amazon.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org According to Moortec Embedded Voltage Monitor (MEVM) series 3 data sheet, the minimum input signal is -100mv and maximum input signal is +1000mv. When n was small enough, such that PVT_N_CONST * n < PVT_R_CONST it resulted in n overflowing to a very large number (since n is u32 type). This change fixes the problem by casting n to long and replacing shift right with div operation. Signed-off-by: Eliav Farber --- V3 -> V2: - Fix equation to support negative values instead of limiting value to zero. drivers/hwmon/mr75203.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/hwmon/mr75203.c b/drivers/hwmon/mr75203.c index 1cd5ff6eacce..d1f090a9baac 100644 --- a/drivers/hwmon/mr75203.c +++ b/drivers/hwmon/mr75203.c @@ -222,10 +222,11 @@ static int pvt_read_in(struct device *dev, u32 attr, int channel, long *val) return ret; n &= SAMPLE_DATA_MSK; + /* Convert the N bitstream count into voltage */ pre_scaler = pvt->vd[channel].pre_scaler; - *val = pre_scaler * (PVT_N_CONST * n - PVT_R_CONST) >> - PVT_CONV_BITS; + *val = pre_scaler * (PVT_N_CONST * (long)n - PVT_R_CONST) / + (1 << PVT_CONV_BITS); return 0; default: From patchwork Tue Aug 30 19:22:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Farber, Eliav" X-Patchwork-Id: 12959762 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 7FFB1ECAAD5 for ; Tue, 30 Aug 2022 19:24:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231689AbiH3TYO (ORCPT ); Tue, 30 Aug 2022 15:24:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59552 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231778AbiH3TXs (ORCPT ); Tue, 30 Aug 2022 15:23:48 -0400 Received: from smtp-fw-33001.amazon.com (smtp-fw-33001.amazon.com [207.171.190.10]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E61BD7C1C7; Tue, 30 Aug 2022 12:23:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1661887389; x=1693423389; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=D6zTFiLCs38Qd3fgLhl+xoNoittGTp7vL7ilYx1GgRc=; b=PRkeegemkUS6UX0Xa9fb9S36ebzzIfJkBu6sA+p5t55cyumoD4uBr2os Yk44NoxsAKODrBlCLs/HHDafOYEwZ5jdKLaNZnzSRsSiTxSNkqb4N/r2W ugtiMaG9gc7YAGxMO6BrVV957YxxmliVRpOyV3RJHdvEGkt1NC7DDt6bs 4=; X-IronPort-AV: E=Sophos;i="5.93,275,1654560000"; d="scan'208";a="222136156" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-iad-1a-c92fe759.us-east-1.amazon.com) ([10.43.8.6]) by smtp-border-fw-33001.sea14.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Aug 2022 19:22:41 +0000 Received: from EX13MTAUWA001.ant.amazon.com (iad12-ws-svc-p26-lb9-vlan2.iad.amazon.com [10.40.163.34]) by email-inbound-relay-iad-1a-c92fe759.us-east-1.amazon.com (Postfix) with ESMTPS id 79FDEC0925; Tue, 30 Aug 2022 19:22:38 +0000 (UTC) Received: from EX19D013UWA004.ant.amazon.com (10.13.138.207) by EX13MTAUWA001.ant.amazon.com (10.43.160.118) with Microsoft SMTP Server (TLS) id 15.0.1497.38; Tue, 30 Aug 2022 19:22:15 +0000 Received: from EX13MTAUEE002.ant.amazon.com (10.43.62.24) by EX19D013UWA004.ant.amazon.com (10.13.138.207) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1118.12; Tue, 30 Aug 2022 19:22:14 +0000 Received: from dev-dsk-farbere-1a-46ecabed.eu-west-1.amazon.com (172.19.116.181) by mail-relay.amazon.com (10.43.62.224) with Microsoft SMTP Server id 15.0.1497.38 via Frontend Transport; Tue, 30 Aug 2022 19:22:13 +0000 Received: by dev-dsk-farbere-1a-46ecabed.eu-west-1.amazon.com (Postfix, from userid 14301484) id 5DA524D09; Tue, 30 Aug 2022 19:22:12 +0000 (UTC) From: Eliav Farber To: , , , , , , , CC: , , , , , , , , , , , , , Subject: [PATCH v3 13/19] hwmon: (mr75203) modify the temperature equation according to series 5 datasheet Date: Tue, 30 Aug 2022 19:22:06 +0000 Message-ID: <20220830192212.28570-14-farbere@amazon.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220830192212.28570-1-farbere@amazon.com> References: <20220830192212.28570-1-farbere@amazon.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org Modify the equation and coefficients used to convert the digital output to temperature according to series 5 of the Moortec Embedded Temperature Sensor (METS) datasheet: T = G + H * (n / cal5 - 0.5) + J * F Where: *) G = 60, H = 200, cal5 = 4094, J = -0.1. *) F = frequency clock in MHz. *) n is the digital output. In code, the G, H and J coefficients are multiplied by a factor of 1000 to get the temperature in milli-Celsius. Final result is clamped in case it exceeds min/max thresholds. Change is done since it is not clear where the current equation and coefficients came from. Signed-off-by: Eliav Farber --- V3 -> V2: - Protect from overflow. - Add temperature clamping. - Add better documentation. drivers/hwmon/mr75203.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/drivers/hwmon/mr75203.c b/drivers/hwmon/mr75203.c index d1f090a9baac..5b8ca1ee4a54 100644 --- a/drivers/hwmon/mr75203.c +++ b/drivers/hwmon/mr75203.c @@ -103,13 +103,17 @@ #define PVT_POLL_DELAY_US 20 #define PVT_POLL_TIMEOUT_US 20000 -#define PVT_H_CONST 100000 -#define PVT_CAL5_CONST 2047 -#define PVT_G_CONST 40000 +#define PVT_H_CONST 200000 +#define PVT_G_CONST 60000 +#define PVT_J_CONST -100 +#define PVT_CAL5_CONST 4094 #define PVT_CONV_BITS 10 #define PVT_N_CONST 90 #define PVT_R_CONST 245805 +#define PVT_TEMP_MIN -40000 +#define PVT_TEMP_MAX 125000 + #define PRE_SCALER_X1 1 #define PRE_SCALER_X2 2 @@ -157,13 +161,24 @@ static umode_t pvt_is_visible(const void *data, enum hwmon_sensor_types type, return 0; } +static long pvt_calc_temp(struct pvt_device *pvt, u32 nbs) +{ + /* + * Convert the register value to degrees centigrade temperature: + * T = G + H * (n / cal5 - 0.5) + J * F + */ + s64 tmp = PVT_G_CONST + PVT_H_CONST * (s64)nbs / PVT_CAL5_CONST - + PVT_H_CONST / 2 + PVT_J_CONST * (s64)pvt->ip_freq / HZ_PER_MHZ; + + return clamp_val(tmp, PVT_TEMP_MIN, PVT_TEMP_MAX); +} + static int pvt_read_temp(struct device *dev, u32 attr, int channel, long *val) { struct pvt_device *pvt = dev_get_drvdata(dev); struct regmap *t_map = pvt->t_map; u32 stat, nbs; int ret; - u64 tmp; switch (attr) { case hwmon_temp_input: @@ -184,9 +199,7 @@ static int pvt_read_temp(struct device *dev, u32 attr, int channel, long *val) * Convert the register value to * degrees centigrade temperature */ - tmp = nbs * PVT_H_CONST; - do_div(tmp, PVT_CAL5_CONST); - *val = tmp - PVT_G_CONST - pvt->ip_freq; + *val = pvt_calc_temp(pvt, nbs); return 0; default: @@ -311,7 +324,7 @@ static int pvt_init(struct pvt_device *pvt) (key >> 1) << CLK_SYNTH_HI_SFT | (key >> 1) << CLK_SYNTH_HOLD_SFT | CLK_SYNTH_EN; - pvt->ip_freq = sys_freq * 100 / (key + 2); + pvt->ip_freq = clk_get_rate(pvt->clk) / (key + 2); if (t_num) { ret = regmap_write(t_map, SDIF_SMPL_CTRL, 0x0); From patchwork Tue Aug 30 19:22:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Farber, Eliav" X-Patchwork-Id: 12959749 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 EDCCEECAAD5 for ; Tue, 30 Aug 2022 19:22:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231451AbiH3TWg (ORCPT ); Tue, 30 Aug 2022 15:22:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58898 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230330AbiH3TWe (ORCPT ); Tue, 30 Aug 2022 15:22:34 -0400 Received: from smtp-fw-2101.amazon.com (smtp-fw-2101.amazon.com [72.21.196.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F3CBB79A41; Tue, 30 Aug 2022 12:22:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1661887354; x=1693423354; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=jpiHuxtmtOdbY+L9vFmRYPscv7SA5/m29+1SrabSDX0=; b=hu03mqAsv9+9AZQHGMyZQ7TfdaFs34Fpo66hjJQRMLE85CVTstUtaaBv AdHRv2QA6edzuEAQj9l38dRkiQshbPnTkY0AzvwE8zO2YzVn7sXzrffSG hUtJqs3PJETwwLtcI88drexKxPMTBSXOFad0WQ4iB1l6393yY1xAGZV1+ M=; X-IronPort-AV: E=Sophos;i="5.93,275,1654560000"; d="scan'208";a="235792417" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-pdx-2b-1f9d5b26.us-west-2.amazon.com) ([10.43.8.6]) by smtp-border-fw-2101.iad2.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Aug 2022 19:22:18 +0000 Received: from EX13D40EUB003.ant.amazon.com (pdx1-ws-svc-p6-lb9-vlan3.pdx.amazon.com [10.236.137.198]) by email-inbound-relay-pdx-2b-1f9d5b26.us-west-2.amazon.com (Postfix) with ESMTPS id 01C7844DD0; Tue, 30 Aug 2022 19:22:17 +0000 (UTC) Received: from EX13MTAUEA001.ant.amazon.com (10.43.61.82) by EX13D40EUB003.ant.amazon.com (10.43.166.128) with Microsoft SMTP Server (TLS) id 15.0.1497.38; Tue, 30 Aug 2022 19:22:15 +0000 Received: from dev-dsk-farbere-1a-46ecabed.eu-west-1.amazon.com (172.19.116.181) by mail-relay.amazon.com (10.43.61.243) with Microsoft SMTP Server id 15.0.1497.38 via Frontend Transport; Tue, 30 Aug 2022 19:22:14 +0000 Received: by dev-dsk-farbere-1a-46ecabed.eu-west-1.amazon.com (Postfix, from userid 14301484) id 682B14D42; Tue, 30 Aug 2022 19:22:12 +0000 (UTC) From: Eliav Farber To: , , , , , , , CC: , , , , , , , , , , , , , Subject: [PATCH v3 14/19] dt-bindings: hwmon: (mr75203) add "moortec,ts-series" property Date: Tue, 30 Aug 2022 19:22:07 +0000 Message-ID: <20220830192212.28570-15-farbere@amazon.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220830192212.28570-1-farbere@amazon.com> References: <20220830192212.28570-1-farbere@amazon.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org Add optional "moortec,ts-series" property to define the temperature equation and coefficients that shall be used to convert the digital output to value in milli-Celsius. Supported series: 5 (default) and 6. Series 5: T = G + H * (n / cal5 - 0.5) + J * F Where: G = 60, H = 200, cal5 = 4094, J = -0.1, F = frequency clock in MHz Series 6: T = G + H * (n / cal5 - 0.5) Where: G = 57.4, H = 249.4, cal5 = 4096 Signed-off-by: Eliav Farber --- V3 -> V2: - New patch to introduce "moortec,ts-series" property. .../devicetree/bindings/hwmon/moortec,mr75203.yaml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Documentation/devicetree/bindings/hwmon/moortec,mr75203.yaml b/Documentation/devicetree/bindings/hwmon/moortec,mr75203.yaml index 4c983d8f8fe7..ec2dbe7da9c2 100644 --- a/Documentation/devicetree/bindings/hwmon/moortec,mr75203.yaml +++ b/Documentation/devicetree/bindings/hwmon/moortec,mr75203.yaml @@ -64,6 +64,16 @@ properties: default: 1 $ref: /schemas/types.yaml#definitions/uint8-array + moortec,ts-series: + description: + moortec,ts-series defines the temperature equation and coefficients that + shall be used to convert the digital output to value in milli-Celsius. + Supported series are 5 and 6. + minimum: 5 + maximum: 6 + default: 5 + $ref: /schemas/types.yaml#definitions/uint32 + required: - compatible - reg From patchwork Tue Aug 30 19:22:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Farber, Eliav" X-Patchwork-Id: 12959761 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 93056ECAAA1 for ; Tue, 30 Aug 2022 19:24:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231477AbiH3TYH (ORCPT ); Tue, 30 Aug 2022 15:24:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58916 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231685AbiH3TXh (ORCPT ); Tue, 30 Aug 2022 15:23:37 -0400 Received: from smtp-fw-33001.amazon.com (smtp-fw-33001.amazon.com [207.171.190.10]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ED6D77B7A6; Tue, 30 Aug 2022 12:22:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1661887379; x=1693423379; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=o77vQ07d89glwBVV3yt+VAkiTa6XFTavUwgfAhgxg8E=; b=NerQXSoR3gsGvgRzhp5psBrMikXSmqYfnF/8umK2IhvKpwA6ZZEcn3Fc l2RfZtgjg9PYhOaTElmP0YQQy1ky03sHXKZb+5SbGReSKeq0nQ0Ilin9V znPna3N9597ZT2DVj2ymJ/WLRawN7ji/Mmn1PMcQZlX57sr1O0i7wjOUP g=; X-IronPort-AV: E=Sophos;i="5.93,275,1654560000"; d="scan'208";a="222136159" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-iad-1a-b27d4a00.us-east-1.amazon.com) ([10.43.8.6]) by smtp-border-fw-33001.sea14.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Aug 2022 19:22:42 +0000 Received: from EX13MTAUWA001.ant.amazon.com (iad12-ws-svc-p26-lb9-vlan3.iad.amazon.com [10.40.163.38]) by email-inbound-relay-iad-1a-b27d4a00.us-east-1.amazon.com (Postfix) with ESMTPS id 44220811F5; Tue, 30 Aug 2022 19:22:39 +0000 (UTC) Received: from EX19D013UWA002.ant.amazon.com (10.13.138.210) by EX13MTAUWA001.ant.amazon.com (10.43.160.118) with Microsoft SMTP Server (TLS) id 15.0.1497.38; Tue, 30 Aug 2022 19:22:16 +0000 Received: from EX13MTAUWA001.ant.amazon.com (10.43.160.58) by EX19D013UWA002.ant.amazon.com (10.13.138.210) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1118.12; Tue, 30 Aug 2022 19:22:15 +0000 Received: from dev-dsk-farbere-1a-46ecabed.eu-west-1.amazon.com (172.19.116.181) by mail-relay.amazon.com (10.43.160.118) with Microsoft SMTP Server id 15.0.1497.38 via Frontend Transport; Tue, 30 Aug 2022 19:22:15 +0000 Received: by dev-dsk-farbere-1a-46ecabed.eu-west-1.amazon.com (Postfix, from userid 14301484) id 6C2ED4D4D; Tue, 30 Aug 2022 19:22:12 +0000 (UTC) From: Eliav Farber To: , , , , , , , CC: , , , , , , , , , , , , , Subject: [PATCH v3 15/19] hwmon: (mr75203) add support for series 6 temperature equation Date: Tue, 30 Aug 2022 19:22:08 +0000 Message-ID: <20220830192212.28570-16-farbere@amazon.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220830192212.28570-1-farbere@amazon.com> References: <20220830192212.28570-1-farbere@amazon.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org The current equation used in code is aligned to series 5: T = G + H * (n / cal5 - 0.5) + J * F Where: G = 60, H = 200, cal5 = 4094, J = -0.1, F = frequency clock in MHz Series 6 has a slightly different equation: T = G + H * (n / cal5 - 0.5) and a different set of coefficients: G = 57.4, H = 249.4, cal5 = 4096 This change supports equation and coefficients for both series. (for series 6, J is set to 0). The series is determined according to “ts-series” property in device tree. If absent, series 5 is assumed to be the default. Signed-off-by: Eliav Farber --- V3 -> V2: - New patch to support temperature sensor series 6 instead of having to set all 4 coefficients. drivers/hwmon/mr75203.c | 69 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 63 insertions(+), 6 deletions(-) diff --git a/drivers/hwmon/mr75203.c b/drivers/hwmon/mr75203.c index 5b8ca1ee4a54..6a035fd115ca 100644 --- a/drivers/hwmon/mr75203.c +++ b/drivers/hwmon/mr75203.c @@ -103,10 +103,6 @@ #define PVT_POLL_DELAY_US 20 #define PVT_POLL_TIMEOUT_US 20000 -#define PVT_H_CONST 200000 -#define PVT_G_CONST 60000 -#define PVT_J_CONST -100 -#define PVT_CAL5_CONST 4094 #define PVT_CONV_BITS 10 #define PVT_N_CONST 90 #define PVT_R_CONST 245805 @@ -114,9 +110,31 @@ #define PVT_TEMP_MIN -40000 #define PVT_TEMP_MAX 125000 +/* Temperature coefficients for series 5 */ +#define PVT_SERIES5_H_CONST 200000 +#define PVT_SERIES5_G_CONST 60000 +#define PVT_SERIES5_J_CONST -100 +#define PVT_SERIES5_CAL5_CONST 4094 + +/* Temperature coefficients for series 6 */ +#define PVT_SERIES6_H_CONST 249400 +#define PVT_SERIES6_G_CONST 57400 +#define PVT_SERIES6_J_CONST 0 +#define PVT_SERIES6_CAL5_CONST 4096 + +#define TEMPERATURE_SENSOR_SERIES_5 5 +#define TEMPERATURE_SENSOR_SERIES_6 6 + #define PRE_SCALER_X1 1 #define PRE_SCALER_X2 2 +struct temp_coeff { + u32 h; + u32 g; + u32 cal5; + s32 j; +}; + struct voltage_device { u32 vm_map; /* Map channel number to VM index */ u32 ch_map; /* Map channel number to channel index */ @@ -137,6 +155,7 @@ struct pvt_device { struct reset_control *rst; struct voltage_device *vd; struct voltage_channels vm_channels; + struct temp_coeff ts_coeff; u32 t_num; u32 p_num; u32 v_num; @@ -167,8 +186,9 @@ static long pvt_calc_temp(struct pvt_device *pvt, u32 nbs) * Convert the register value to degrees centigrade temperature: * T = G + H * (n / cal5 - 0.5) + J * F */ - s64 tmp = PVT_G_CONST + PVT_H_CONST * (s64)nbs / PVT_CAL5_CONST - - PVT_H_CONST / 2 + PVT_J_CONST * (s64)pvt->ip_freq / HZ_PER_MHZ; + struct temp_coeff *ts_coeff = &pvt->ts_coeff; + s64 tmp = ts_coeff->g + ts_coeff->h * (s64)nbs / ts_coeff->cal5 - + ts_coeff->h / 2 + ts_coeff->j * (s64)pvt->ip_freq / HZ_PER_MHZ; return clamp_val(tmp, PVT_TEMP_MIN, PVT_TEMP_MAX); } @@ -652,6 +672,39 @@ static int pvt_get_pre_scaler(struct device *dev, struct pvt_device *pvt) return ret; } +static int pvt_set_temp_coeff(struct device *dev, struct pvt_device *pvt) +{ + struct temp_coeff *ts_coeff = &pvt->ts_coeff; + const struct device_node *np = dev->of_node; + u32 series; + int ret; + + /* Incase ts-series property is not defined, use default 5. */ + ret = of_property_read_u32(np, "moortec,ts-series", &series); + if (ret) + series = TEMPERATURE_SENSOR_SERIES_5; + + if (series == TEMPERATURE_SENSOR_SERIES_5) { + ts_coeff->h = PVT_SERIES5_H_CONST; + ts_coeff->g = PVT_SERIES5_G_CONST; + ts_coeff->j = PVT_SERIES5_J_CONST; + ts_coeff->cal5 = PVT_SERIES5_CAL5_CONST; + } else if (series == TEMPERATURE_SENSOR_SERIES_6) { + ts_coeff->h = PVT_SERIES6_H_CONST; + ts_coeff->g = PVT_SERIES6_G_CONST; + ts_coeff->j = PVT_SERIES6_J_CONST; + ts_coeff->cal5 = PVT_SERIES6_CAL5_CONST; + } else { + dev_err(dev, "invalid temperature sensor series (%u)\n", + series); + return -EINVAL; + } + + dev_dbg(dev, "temperature sensor series = %u\n", series); + + return 0; +} + static int mr75203_probe(struct platform_device *pdev) { const struct hwmon_channel_info **pvt_info; @@ -722,6 +775,10 @@ static int mr75203_probe(struct platform_device *pdev) if (ret) return ret; + ret = pvt_set_temp_coeff(dev, pvt); + if (ret) + return ret; + temp_config = devm_kcalloc(dev, ts_num + 1, sizeof(*temp_config), GFP_KERNEL); if (!temp_config) From patchwork Tue Aug 30 19:22:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Farber, Eliav" X-Patchwork-Id: 12959763 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 32051ECAAD5 for ; Tue, 30 Aug 2022 19:24:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231536AbiH3TYf (ORCPT ); Tue, 30 Aug 2022 15:24:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59240 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231547AbiH3TYH (ORCPT ); Tue, 30 Aug 2022 15:24:07 -0400 Received: from smtp-fw-33001.amazon.com (smtp-fw-33001.amazon.com [207.171.190.10]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB2297C311; Tue, 30 Aug 2022 12:23:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1661887395; x=1693423395; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=843kBT2eo8fZBeKaiWYGVSNFPK3qHfLWFvr35ISO3DM=; b=PzXUUC855NsrLuKCVsCDt7/2niPV73pc3cYtCcjO6ol2LCPxRmtBGosN h1vnM9hV1pBcRcMWlRfNYmrTAmBdHQ/7iexPCNYxqy07DEp1OcxyiAVlM M/fPymgcbjdIK4nk6MWSeFTpiiY9BwUnDP5zVsSIVv6vN+A4/Q48Jog+s E=; X-IronPort-AV: E=Sophos;i="5.93,275,1654560000"; d="scan'208";a="222136157" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-iad-1e-7dac3c4d.us-east-1.amazon.com) ([10.43.8.6]) by smtp-border-fw-33001.sea14.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Aug 2022 19:22:41 +0000 Received: from EX13MTAUWA001.ant.amazon.com (iad12-ws-svc-p26-lb9-vlan3.iad.amazon.com [10.40.163.38]) by email-inbound-relay-iad-1e-7dac3c4d.us-east-1.amazon.com (Postfix) with ESMTPS id 84690819D8; Tue, 30 Aug 2022 19:22:38 +0000 (UTC) Received: from EX19D013UWA001.ant.amazon.com (10.13.138.253) by EX13MTAUWA001.ant.amazon.com (10.43.160.118) with Microsoft SMTP Server (TLS) id 15.0.1497.38; Tue, 30 Aug 2022 19:22:15 +0000 Received: from EX13MTAUWB001.ant.amazon.com (10.43.161.207) by EX19D013UWA001.ant.amazon.com (10.13.138.253) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1118.12; Tue, 30 Aug 2022 19:22:14 +0000 Received: from dev-dsk-farbere-1a-46ecabed.eu-west-1.amazon.com (172.19.116.181) by mail-relay.amazon.com (10.43.161.249) with Microsoft SMTP Server id 15.0.1497.38 via Frontend Transport; Tue, 30 Aug 2022 19:22:14 +0000 Received: by dev-dsk-farbere-1a-46ecabed.eu-west-1.amazon.com (Postfix, from userid 14301484) id 634754D4E; Tue, 30 Aug 2022 19:22:12 +0000 (UTC) From: Eliav Farber To: , , , , , , , CC: , , , , , , , , , , , , , Subject: [PATCH v3 16/19] dt-bindings: hwmon: (mr75203) add coefficient properties for the thermal equation Date: Tue, 30 Aug 2022 19:22:09 +0000 Message-ID: <20220830192212.28570-17-farbere@amazon.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220830192212.28570-1-farbere@amazon.com> References: <20220830192212.28570-1-farbere@amazon.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org Add optional temperature coefficient properties: *) moortec,ts-coeff-g *) moortec,ts-coeff-h *) moortec,ts-coeff-cal5 *) moortec,ts-coeff-j If defined they shall be used instead of defaults. The coefficients were added to device tree on top of the series property (which can be used to select between series 5 and series 6), because coefficients can vary between product and product, and code defaults might not be accurate enough. Signed-off-by: Eliav Farber --- V3 -> V2: - Add "moortec" prefix to property name. .../bindings/hwmon/moortec,mr75203.yaml | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/Documentation/devicetree/bindings/hwmon/moortec,mr75203.yaml b/Documentation/devicetree/bindings/hwmon/moortec,mr75203.yaml index ec2dbe7da9c2..a92da6064285 100644 --- a/Documentation/devicetree/bindings/hwmon/moortec,mr75203.yaml +++ b/Documentation/devicetree/bindings/hwmon/moortec,mr75203.yaml @@ -74,6 +74,37 @@ properties: default: 5 $ref: /schemas/types.yaml#definitions/uint32 + moortec,ts-coeff-g: + description: + G coefficient for temperature equation. + Value should be multiplied by factor 1000. + Default for series 5 = 60000 + Default for series 6 = 57400 + $ref: /schemas/types.yaml#/definitions/uint32 + + moortec,ts-coeff-h: + description: + H coefficient for temperature equation. + Value should be multiplied by factor 1000. + Default for series 5 = 200000 + Default for series 6 = 249400 + $ref: /schemas/types.yaml#/definitions/uint32 + + moortec,ts-coeff-cal5: + description: + cal5 coefficient for temperature equation (can't be 0). + Default for series 5 = 4094 + Default for series 6 = 4096 + $ref: /schemas/types.yaml#/definitions/uint32 + + moortec,ts-coeff-j: + description: + J coefficient for temperature equation. + Value should be multiplied by factor 1000. + Default for series 5 = -100 + Default for series 6 = 0 + $ref: /schemas/types.yaml#/definitions/int32 + required: - compatible - reg @@ -97,5 +128,7 @@ examples: resets = <&rcu0 0x40 7>; moortec,vm-active-channels = <0x10 0x05>; moortec,vm-pre-scaler = <5 6>; + moortec,ts-coeff-g = <61400>; + moortec,ts-coeff-h = <253700>; #thermal-sensor-cells = <1>; }; From patchwork Tue Aug 30 19:22:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Farber, Eliav" X-Patchwork-Id: 12959754 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 87604ECAAD8 for ; Tue, 30 Aug 2022 19:23:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230175AbiH3TXF (ORCPT ); Tue, 30 Aug 2022 15:23:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58960 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229907AbiH3TWx (ORCPT ); Tue, 30 Aug 2022 15:22:53 -0400 Received: from smtp-fw-80007.amazon.com (smtp-fw-80007.amazon.com [99.78.197.218]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 53C0379A7E; Tue, 30 Aug 2022 12:22:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1661887362; x=1693423362; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=U0VJcbOTM8ab3MiQEMGAYi1n6qUqXBDMxjPiRHK115k=; b=Lh0vawBdls/5T6rFmXcgDZCxiuJveGKDZrnaq3QOjJw5/aWwSHVdSx0/ /SeMtWrg8GpvclrrtvEjwZVBiksnNt6uGvaM0CZfA9NCnbqKj5Z+jW/KW /P8BgWy/XrrYqeeUjjavp0J0rZsrLCqJd5Zu+vJ60R4aO8r6ELDc30fMc A=; X-IronPort-AV: E=Sophos;i="5.93,275,1654560000"; d="scan'208";a="125055929" Received: from pdx4-co-svc-p1-lb2-vlan3.amazon.com (HELO email-inbound-relay-iad-1e-f771ae83.us-east-1.amazon.com) ([10.25.36.214]) by smtp-border-fw-80007.pdx80.corp.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Aug 2022 19:22:40 +0000 Received: from EX13MTAUWA001.ant.amazon.com (iad12-ws-svc-p26-lb9-vlan2.iad.amazon.com [10.40.163.34]) by email-inbound-relay-iad-1e-f771ae83.us-east-1.amazon.com (Postfix) with ESMTPS id 2DD74120072; Tue, 30 Aug 2022 19:22:39 +0000 (UTC) Received: from EX19D013UWA004.ant.amazon.com (10.13.138.207) by EX13MTAUWA001.ant.amazon.com (10.43.160.118) with Microsoft SMTP Server (TLS) id 15.0.1497.38; Tue, 30 Aug 2022 19:22:16 +0000 Received: from EX13MTAUWA001.ant.amazon.com (10.43.160.58) by EX19D013UWA004.ant.amazon.com (10.13.138.207) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1118.12; Tue, 30 Aug 2022 19:22:16 +0000 Received: from dev-dsk-farbere-1a-46ecabed.eu-west-1.amazon.com (172.19.116.181) by mail-relay.amazon.com (10.43.160.118) with Microsoft SMTP Server id 15.0.1497.38 via Frontend Transport; Tue, 30 Aug 2022 19:22:15 +0000 Received: by dev-dsk-farbere-1a-46ecabed.eu-west-1.amazon.com (Postfix, from userid 14301484) id 6B5974D41; Tue, 30 Aug 2022 19:22:12 +0000 (UTC) From: Eliav Farber To: , , , , , , , CC: , , , , , , , , , , , , , Subject: [PATCH v3 17/19] hwmon: (mr75203) parse temperature coefficients from device-tree Date: Tue, 30 Aug 2022 19:22:10 +0000 Message-ID: <20220830192212.28570-18-farbere@amazon.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220830192212.28570-1-farbere@amazon.com> References: <20220830192212.28570-1-farbere@amazon.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org Use thermal coefficients from the device tree if they exist. Otherwise, use default values according to the series (5 or 6). All coefficients can be used or only part of them. The coefficients shall be used for fine tuning the default values since coefficients can vary between product and product. Signed-off-by: Eliav Farber --- drivers/hwmon/mr75203.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/drivers/hwmon/mr75203.c b/drivers/hwmon/mr75203.c index 6a035fd115ca..d9fc5d225868 100644 --- a/drivers/hwmon/mr75203.c +++ b/drivers/hwmon/mr75203.c @@ -676,7 +676,8 @@ static int pvt_set_temp_coeff(struct device *dev, struct pvt_device *pvt) { struct temp_coeff *ts_coeff = &pvt->ts_coeff; const struct device_node *np = dev->of_node; - u32 series; + u32 series, coeff_h, coeff_g, coeff_cal5; + s32 coeff_j; int ret; /* Incase ts-series property is not defined, use default 5. */ @@ -702,6 +703,32 @@ static int pvt_set_temp_coeff(struct device *dev, struct pvt_device *pvt) dev_dbg(dev, "temperature sensor series = %u\n", series); + /* Override ts-coeff-h/g/j/cal5 if they are defined. */ + ret = of_property_read_u32(np, "moortec,ts-coeff-h", &coeff_h); + if (!ret) + ts_coeff->h = coeff_h; + + ret = of_property_read_u32(np, "moortec,ts-coeff-g", &coeff_g); + if (!ret) + ts_coeff->g = coeff_g; + + ret = of_property_read_s32(np, "moortec,ts-coeff-j", &coeff_j); + if (!ret) + ts_coeff->j = coeff_j; + + ret = of_property_read_u32(np, "moortec,ts-coeff-cal5", &coeff_cal5); + if (!ret) { + if (coeff_cal5 == 0) { + dev_err(dev, "moortec,ts-coeff-cal5 can't be 0\n"); + return -EINVAL; + } + + ts_coeff->cal5 = coeff_cal5; + } + + dev_dbg(dev, "ts-coeff: h = %u, g = %u, j = %d, cal5 = %u\n", + ts_coeff->h, ts_coeff->g, ts_coeff->j, ts_coeff->cal5); + return 0; } From patchwork Tue Aug 30 19:22:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Farber, Eliav" X-Patchwork-Id: 12959760 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 5D9FBECAAD5 for ; Tue, 30 Aug 2022 19:23:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230038AbiH3TXw (ORCPT ); Tue, 30 Aug 2022 15:23:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59040 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231588AbiH3TXM (ORCPT ); Tue, 30 Aug 2022 15:23:12 -0400 Received: from smtp-fw-2101.amazon.com (smtp-fw-2101.amazon.com [72.21.196.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B8D887B296; Tue, 30 Aug 2022 12:22:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1661887370; x=1693423370; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=oKBXIGtN7Cud54nf08PbP0K1g2Fts4xlETNbDNNSKNU=; b=rE+inkUa7MqImNoNuyXkUV1sPIlRC32dRRw6S8/gOXjh5lIwus9BMwll v3u1ktopEHjNvwVyHP1E0NMCfC1otV5b5plEJOqvla/keTgnRNstC8U8n fPQjz39FiwzsexiIi4ImRJQ6GWlRPWoMMB/VtdbjWXFLvRn+i6fdxDD9y g=; X-IronPort-AV: E=Sophos;i="5.93,275,1654560000"; d="scan'208";a="235792567" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-iad-1a-c92fe759.us-east-1.amazon.com) ([10.43.8.6]) by smtp-border-fw-2101.iad2.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Aug 2022 19:22:42 +0000 Received: from EX13MTAUWA001.ant.amazon.com (iad12-ws-svc-p26-lb9-vlan2.iad.amazon.com [10.40.163.34]) by email-inbound-relay-iad-1a-c92fe759.us-east-1.amazon.com (Postfix) with ESMTPS id E152CC0920; Tue, 30 Aug 2022 19:22:38 +0000 (UTC) Received: from EX19D013UWA004.ant.amazon.com (10.13.138.207) by EX13MTAUWA001.ant.amazon.com (10.43.160.118) with Microsoft SMTP Server (TLS) id 15.0.1497.38; Tue, 30 Aug 2022 19:22:15 +0000 Received: from EX13MTAUEA001.ant.amazon.com (10.43.61.82) by EX19D013UWA004.ant.amazon.com (10.13.138.207) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1118.12; Tue, 30 Aug 2022 19:22:15 +0000 Received: from dev-dsk-farbere-1a-46ecabed.eu-west-1.amazon.com (172.19.116.181) by mail-relay.amazon.com (10.43.61.243) with Microsoft SMTP Server id 15.0.1497.38 via Frontend Transport; Tue, 30 Aug 2022 19:22:14 +0000 Received: by dev-dsk-farbere-1a-46ecabed.eu-west-1.amazon.com (Postfix, from userid 14301484) id 628494D43; Tue, 30 Aug 2022 19:22:12 +0000 (UTC) From: Eliav Farber To: , , , , , , , CC: , , , , , , , , , , , , , Subject: [PATCH v3 18/19] hwmon: (mr75203) add debugfs to read and write temperature coefficients Date: Tue, 30 Aug 2022 19:22:11 +0000 Message-ID: <20220830192212.28570-19-farbere@amazon.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220830192212.28570-1-farbere@amazon.com> References: <20220830192212.28570-1-farbere@amazon.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org This change adds debugfs to read and write temperature sensor coefficients - g, h, j and cal5. The coefficients can vary between product and product, so it can be very useful to be able to modify them on the fly during the calibration process. e.g.: cat /sys/kernel/debug/940f23d0000.pvt/ts_coeff_cal5 4096 echo 83000 > sys/kernel/debug/940f23d0000.pvt/ts_coeff_g Signed-off-by: Eliav Farber --- drivers/hwmon/mr75203.c | 196 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 196 insertions(+) diff --git a/drivers/hwmon/mr75203.c b/drivers/hwmon/mr75203.c index d9fc5d225868..8c30f0521452 100644 --- a/drivers/hwmon/mr75203.c +++ b/drivers/hwmon/mr75203.c @@ -9,6 +9,7 @@ */ #include #include +#include #include #include #include @@ -153,6 +154,7 @@ struct pvt_device { struct regmap *v_map; struct clk *clk; struct reset_control *rst; + struct dentry *dbgfs_dir; struct voltage_device *vd; struct voltage_channels vm_channels; struct temp_coeff ts_coeff; @@ -162,6 +164,198 @@ struct pvt_device { u32 ip_freq; }; +static ssize_t pvt_ts_coeff_h_read(struct file *file, + char __user *user_buf, + size_t count, loff_t *ppos) +{ + struct pvt_device *pvt = file->private_data; + char buf[16]; + unsigned int len; + + len = sprintf(buf, "%u\n", pvt->ts_coeff.h); + + return simple_read_from_buffer(user_buf, count, ppos, buf, len); +} + +static ssize_t pvt_ts_coeff_h_write(struct file *file, + const char __user *user_buf, + size_t count, loff_t *ppos) +{ + struct pvt_device *pvt = file->private_data; + int ret; + u32 coeff; + + ret = kstrtou32_from_user(user_buf, count, 0, &coeff); + if (ret) + return ret; + + pvt->ts_coeff.h = coeff; + + return count; +} + +static const struct file_operations pvt_ts_coeff_h_fops = { + .read = pvt_ts_coeff_h_read, + .write = pvt_ts_coeff_h_write, + .open = simple_open, + .owner = THIS_MODULE, + .llseek = default_llseek, +}; + +static ssize_t pvt_ts_coeff_g_read(struct file *file, + char __user *user_buf, + size_t count, loff_t *ppos) +{ + struct pvt_device *pvt = file->private_data; + char buf[16]; + unsigned int len; + + len = sprintf(buf, "%u\n", pvt->ts_coeff.g); + + return simple_read_from_buffer(user_buf, count, ppos, buf, len); +} + +static ssize_t pvt_ts_coeff_g_write(struct file *file, + const char __user *user_buf, + size_t count, loff_t *ppos) +{ + struct pvt_device *pvt = file->private_data; + int ret; + u32 coeff; + + ret = kstrtou32_from_user(user_buf, count, 0, &coeff); + if (ret) + return ret; + + pvt->ts_coeff.g = coeff; + + return count; +} + +static const struct file_operations pvt_ts_coeff_g_fops = { + .read = pvt_ts_coeff_g_read, + .write = pvt_ts_coeff_g_write, + .open = simple_open, + .owner = THIS_MODULE, + .llseek = default_llseek, +}; + +static ssize_t pvt_ts_coeff_j_read(struct file *file, + char __user *user_buf, + size_t count, loff_t *ppos) +{ + struct pvt_device *pvt = file->private_data; + char buf[16]; + unsigned int len; + + len = sprintf(buf, "%d\n", pvt->ts_coeff.j); + + return simple_read_from_buffer(user_buf, count, ppos, buf, len); +} + +static ssize_t pvt_ts_coeff_j_write(struct file *file, + const char __user *user_buf, + size_t count, loff_t *ppos) +{ + struct pvt_device *pvt = file->private_data; + int ret; + s32 coeff; + + ret = kstrtos32_from_user(user_buf, count, 0, &coeff); + if (ret) + return ret; + + pvt->ts_coeff.j = coeff; + + return count; +} + +static const struct file_operations pvt_ts_coeff_j_fops = { + .read = pvt_ts_coeff_j_read, + .write = pvt_ts_coeff_j_write, + .open = simple_open, + .owner = THIS_MODULE, + .llseek = default_llseek, +}; + +static ssize_t pvt_ts_coeff_cal5_read(struct file *file, + char __user *user_buf, + size_t count, loff_t *ppos) +{ + struct pvt_device *pvt = file->private_data; + char buf[16]; + unsigned int len; + + len = sprintf(buf, "%u\n", pvt->ts_coeff.cal5); + + return simple_read_from_buffer(user_buf, count, ppos, buf, len); +} + +static ssize_t pvt_ts_coeff_cal5_write(struct file *file, + const char __user *user_buf, + size_t count, loff_t *ppos) +{ + struct pvt_device *pvt = file->private_data; + int ret; + u32 coeff; + + ret = kstrtou32_from_user(user_buf, count, 0, &coeff); + if (ret) + return ret; + + if (coeff == 0) + return -EINVAL; + + pvt->ts_coeff.cal5 = coeff; + + return count; +} + +static const struct file_operations pvt_ts_coeff_cal5_fops = { + .read = pvt_ts_coeff_cal5_read, + .write = pvt_ts_coeff_cal5_write, + .open = simple_open, + .owner = THIS_MODULE, + .llseek = default_llseek, +}; + +static void devm_pvt_ts_dbgfs_remove(void *data) +{ + struct pvt_device *pvt = (struct pvt_device *)data; + + debugfs_remove_recursive(pvt->dbgfs_dir); + pvt->dbgfs_dir = NULL; +} + +static int pvt_ts_dbgfs_create(struct pvt_device *pvt, struct device *dev) +{ + int ret; + + pvt->dbgfs_dir = debugfs_create_dir(dev_name(dev), NULL); + if (!pvt->dbgfs_dir) { + dev_err(dev, "Failed to create dbgfs_dir\n"); + return -EINVAL; + } + + debugfs_create_file("ts_coeff_h", 0644, pvt->dbgfs_dir, pvt, + &pvt_ts_coeff_h_fops); + debugfs_create_file("ts_coeff_g", 0644, pvt->dbgfs_dir, pvt, + &pvt_ts_coeff_g_fops); + debugfs_create_file("ts_coeff_j", 0644, pvt->dbgfs_dir, pvt, + &pvt_ts_coeff_j_fops); + debugfs_create_file("ts_coeff_cal5", 0644, pvt->dbgfs_dir, pvt, + &pvt_ts_coeff_cal5_fops); + + ret = devm_add_action_or_reset(dev, devm_pvt_ts_dbgfs_remove, pvt); + if (ret) { + dev_err(dev, "failed to add action to remove pvt dbgfs (%d)\n", + ret); + return ret; + } + + return 0; +} + static umode_t pvt_is_visible(const void *data, enum hwmon_sensor_types type, u32 attr, int channel) { @@ -814,6 +1008,8 @@ static int mr75203_probe(struct platform_device *pdev) memset32(temp_config, HWMON_T_INPUT, ts_num); pvt_temp.config = temp_config; pvt_info[index++] = &pvt_temp; + + pvt_ts_dbgfs_create(pvt, dev); } if (pd_num) { From patchwork Tue Aug 30 19:22:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Farber, Eliav" X-Patchwork-Id: 12959758 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 CFF26ECAAA1 for ; Tue, 30 Aug 2022 19:23:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231670AbiH3TXb (ORCPT ); Tue, 30 Aug 2022 15:23:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59070 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231448AbiH3TXB (ORCPT ); Tue, 30 Aug 2022 15:23:01 -0400 Received: from smtp-fw-9103.amazon.com (smtp-fw-9103.amazon.com [207.171.188.200]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 32BB77A52D; Tue, 30 Aug 2022 12:22:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1661887364; x=1693423364; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Z7jW+V8MpqUAQfk+WoYCzoX7Aq0MV4Sqe7/ddtn8+sU=; b=Rq9EAdLx2/723Z873MozxMAl5DJywKtkaG2Cuq5ZvrsntCBTMlN/iNlF T4TyvInFfr2BKhOdxc+sAvFpQzzTDKXRlEXvLIqrTtwTchx18TUboM28W INXUmW97lzjfPAGczRgnwUTY2cohv+V2BkT+YIkQaG8rJJBvPHwnB7jGO Q=; X-IronPort-AV: E=Sophos;i="5.93,275,1654560000"; d="scan'208";a="1049655077" Received: from pdx4-co-svc-p1-lb2-vlan3.amazon.com (HELO email-inbound-relay-iad-1a-c92fe759.us-east-1.amazon.com) ([10.25.36.214]) by smtp-border-fw-9103.sea19.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Aug 2022 19:22:42 +0000 Received: from EX13MTAUWA001.ant.amazon.com (iad12-ws-svc-p26-lb9-vlan2.iad.amazon.com [10.40.163.34]) by email-inbound-relay-iad-1a-c92fe759.us-east-1.amazon.com (Postfix) with ESMTPS id CED54C091A; Tue, 30 Aug 2022 19:22:38 +0000 (UTC) Received: from EX19D013UWA002.ant.amazon.com (10.13.138.210) by EX13MTAUWA001.ant.amazon.com (10.43.160.118) with Microsoft SMTP Server (TLS) id 15.0.1497.38; Tue, 30 Aug 2022 19:22:15 +0000 Received: from EX13MTAUWA001.ant.amazon.com (10.43.160.58) by EX19D013UWA002.ant.amazon.com (10.13.138.210) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1118.12; Tue, 30 Aug 2022 19:22:15 +0000 Received: from dev-dsk-farbere-1a-46ecabed.eu-west-1.amazon.com (172.19.116.181) by mail-relay.amazon.com (10.43.160.118) with Microsoft SMTP Server id 15.0.1497.38 via Frontend Transport; Tue, 30 Aug 2022 19:22:15 +0000 Received: by dev-dsk-farbere-1a-46ecabed.eu-west-1.amazon.com (Postfix, from userid 14301484) id 640D04D4C; Tue, 30 Aug 2022 19:22:12 +0000 (UTC) From: Eliav Farber To: , , , , , , , CC: , , , , , , , , , , , , , Subject: [PATCH v3 19/19] hwmon: (mr75203) fix coding style space errors Date: Tue, 30 Aug 2022 19:22:12 +0000 Message-ID: <20220830192212.28570-20-farbere@amazon.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220830192212.28570-1-farbere@amazon.com> References: <20220830192212.28570-1-farbere@amazon.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org Fix: "ERROR: space required before the open parenthesis '('" Signed-off-by: Eliav Farber --- drivers/hwmon/mr75203.c | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/drivers/hwmon/mr75203.c b/drivers/hwmon/mr75203.c index 8c30f0521452..6a19f3d2a708 100644 --- a/drivers/hwmon/mr75203.c +++ b/drivers/hwmon/mr75203.c @@ -404,7 +404,7 @@ static int pvt_read_temp(struct device *dev, u32 attr, int channel, long *val) return ret; ret = regmap_read(t_map, SDIF_DATA(channel), &nbs); - if(ret < 0) + if (ret < 0) return ret; nbs &= SAMPLE_DATA_MSK; @@ -445,7 +445,7 @@ static int pvt_read_in(struct device *dev, u32 attr, int channel, long *val) return ret; ret = regmap_read(v_map, VM_SDIF_DATA(vm_idx, ch_idx), &n); - if(ret < 0) + if (ret < 0) return ret; n &= SAMPLE_DATA_MSK; @@ -542,19 +542,19 @@ static int pvt_init(struct pvt_device *pvt) if (t_num) { ret = regmap_write(t_map, SDIF_SMPL_CTRL, 0x0); - if(ret < 0) + if (ret < 0) return ret; ret = regmap_write(t_map, SDIF_HALT, 0x0); - if(ret < 0) + if (ret < 0) return ret; ret = regmap_write(t_map, CLK_SYNTH, clk_synth); - if(ret < 0) + if (ret < 0) return ret; ret = regmap_write(t_map, SDIF_DISABLE, 0x0); - if(ret < 0) + if (ret < 0) return ret; ret = regmap_read_poll_timeout(t_map, SDIF_STAT, @@ -567,7 +567,7 @@ static int pvt_init(struct pvt_device *pvt) val = CFG0_MODE_2 | CFG0_PARALLEL_OUT | CFG0_12_BIT | IP_CFG << SDIF_ADDR_SFT | SDIF_WRN_W | SDIF_PROG; ret = regmap_write(t_map, SDIF_W, val); - if(ret < 0) + if (ret < 0) return ret; ret = regmap_read_poll_timeout(t_map, SDIF_STAT, @@ -580,7 +580,7 @@ static int pvt_init(struct pvt_device *pvt) val = POWER_DELAY_CYCLE_256 | IP_TMR << SDIF_ADDR_SFT | SDIF_WRN_W | SDIF_PROG; ret = regmap_write(t_map, SDIF_W, val); - if(ret < 0) + if (ret < 0) return ret; ret = regmap_read_poll_timeout(t_map, SDIF_STAT, @@ -594,39 +594,39 @@ static int pvt_init(struct pvt_device *pvt) IP_CTRL << SDIF_ADDR_SFT | SDIF_WRN_W | SDIF_PROG; ret = regmap_write(t_map, SDIF_W, val); - if(ret < 0) + if (ret < 0) return ret; } if (p_num) { ret = regmap_write(p_map, SDIF_HALT, 0x0); - if(ret < 0) + if (ret < 0) return ret; ret = regmap_write(p_map, SDIF_DISABLE, BIT(p_num) - 1); - if(ret < 0) + if (ret < 0) return ret; ret = regmap_write(p_map, CLK_SYNTH, clk_synth); - if(ret < 0) + if (ret < 0) return ret; } if (v_num) { ret = regmap_write(v_map, SDIF_SMPL_CTRL, 0x0); - if(ret < 0) + if (ret < 0) return ret; ret = regmap_write(v_map, SDIF_HALT, 0x0); - if(ret < 0) + if (ret < 0) return ret; ret = regmap_write(v_map, CLK_SYNTH, clk_synth); - if(ret < 0) + if (ret < 0) return ret; ret = regmap_write(v_map, SDIF_DISABLE, 0x0); - if(ret < 0) + if (ret < 0) return ret; ret = regmap_read_poll_timeout(v_map, SDIF_STAT, @@ -654,7 +654,7 @@ static int pvt_init(struct pvt_device *pvt) CFG1_14_BIT | IP_CFG << SDIF_ADDR_SFT | SDIF_WRN_W | SDIF_PROG; ret = regmap_write(v_map, SDIF_W, val); - if(ret < 0) + if (ret < 0) return ret; ret = regmap_read_poll_timeout(v_map, SDIF_STAT, @@ -667,7 +667,7 @@ static int pvt_init(struct pvt_device *pvt) val = POWER_DELAY_CYCLE_64 | IP_TMR << SDIF_ADDR_SFT | SDIF_WRN_W | SDIF_PROG; ret = regmap_write(v_map, SDIF_W, val); - if(ret < 0) + if (ret < 0) return ret; ret = regmap_read_poll_timeout(v_map, SDIF_STAT, @@ -681,7 +681,7 @@ static int pvt_init(struct pvt_device *pvt) IP_CTRL << SDIF_ADDR_SFT | SDIF_WRN_W | SDIF_PROG; ret = regmap_write(v_map, SDIF_W, val); - if(ret < 0) + if (ret < 0) return ret; } @@ -967,7 +967,7 @@ static int mr75203_probe(struct platform_device *pdev) } ret = regmap_read(pvt->c_map, PVT_IP_CONFIG, &val); - if(ret < 0) + if (ret < 0) return ret; ts_num = (val & TS_NUM_MSK) >> TS_NUM_SFT;