Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3478015rwb; Tue, 16 Aug 2022 03:56:19 -0700 (PDT) X-Google-Smtp-Source: AA6agR7lqxuVWilUQ2ymv5pIr06IdDvO5y2owz2/SwQo9l+iU9hJBMbifS4tInWNc/2FmBApPlTu X-Received: by 2002:a17:902:720b:b0:16d:2c4c:b52a with SMTP id ba11-20020a170902720b00b0016d2c4cb52amr20929562plb.155.1660647379747; Tue, 16 Aug 2022 03:56:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660647379; cv=none; d=google.com; s=arc-20160816; b=tz+uaYNulvchJfYzEkbup3FwgRgfG6jz4/MM5FtoVbkL9qyCOdC+9M/68rY3mUFgqD +sLWRA/cWYB6MLj0m866VHLb0qIghs3TdFB8v+EfXl/v+KZdl4o2KhnxHCtz3B4K9L5G h4tpUnqorLoMaIxOAs/0RnkwKmeGBUu4uyHjwwVGaIjw6TkbDWcOF7kMcPPu43H0J8qt Gv8gdflJOXsP6hjY5hp173dLQ2Ie9U94zSDGeHt6D0J4C8LQ8kK9yj4ITx+6omO3A3bx VS6/OaJvSt/g9hdfWl3pITO+eN7+6eQqzfXqKFGW388jgdzjKdioD2/AB/a9U21JPbz6 hV/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=c8/SDcTJ30dbsZp2QPCvuIMC9D3VXp4QdqzbVFqmdMU=; b=ndInP5Rp8/TtEas4c7RKyqdKBxLfpvAkAILj1fRYoRF+9l9M8UeH46g+ZFCiz6vgba r2n624lTe2bKN1TbQOw0BaLgN74+pmAonN4z0bAZT1Mun070D2ua2Gmj6EPMs7dVS6tt bVctuvTEGR+DWDzcBiaaczULRh6KBvr4LvNXuUcKYzKTi9E3uMsCZdTxMSU7+A2rItcD IiWME+uJu6xe096vXDcNl6VUZfVIe1IgRu5ZijDdH44Ek4Ut0GpmIs4vA9XEXU3YwaDx FSxSz1nvLWC27iW461q0QfAdBs732+CF1KrwBWUUsbKKmzuefp/cCv1Ev/LVqfiE4zH4 8PgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=gzng2BZW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r129-20020a632b87000000b00427d4537a61si8448767pgr.252.2022.08.16.03.56.09; Tue, 16 Aug 2022 03:56:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=gzng2BZW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234721AbiHPKcn (ORCPT + 99 others); Tue, 16 Aug 2022 06:32:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39302 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234685AbiHPKcV (ORCPT ); Tue, 16 Aug 2022 06:32:21 -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 6F650B9406; Tue, 16 Aug 2022 01:28:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1660638499; x=1692174499; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=c8/SDcTJ30dbsZp2QPCvuIMC9D3VXp4QdqzbVFqmdMU=; b=gzng2BZWA2tgDnctUO+lpBuDgCvhWSipfgHkhidylqiBrt/EcnQ2O1TH 1IdI6PU34Garc6Z6qgLHTltan+ttWhNYaayVtD4tmbXlMO7T2q+MseXOW l7wsFL4Qn2RfmZqF0zQdDO+F+8io0C1vug4DiaLfEStFjCSSAUM9esy3m I=; X-IronPort-AV: E=Sophos;i="5.93,240,1654560000"; d="scan'208";a="233486620" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-pdx-2b-718d0906.us-west-2.amazon.com) ([10.43.8.6]) by smtp-border-fw-6002.iad6.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Aug 2022 08:28:17 +0000 Received: from EX13MTAUEE002.ant.amazon.com (pdx1-ws-svc-p6-lb9-vlan2.pdx.amazon.com [10.236.137.194]) by email-inbound-relay-pdx-2b-718d0906.us-west-2.amazon.com (Postfix) with ESMTPS id EBFE43E0053; Tue, 16 Aug 2022 08:28:16 +0000 (UTC) Received: from EX13D08UEE003.ant.amazon.com (10.43.62.118) by EX13MTAUEE002.ant.amazon.com (10.43.62.24) with Microsoft SMTP Server (TLS) id 15.0.1497.38; Tue, 16 Aug 2022 08:27:59 +0000 Received: from EX13MTAUEE002.ant.amazon.com (10.43.62.24) by EX13D08UEE003.ant.amazon.com (10.43.62.118) with Microsoft SMTP Server (TLS) id 15.0.1497.38; Tue, 16 Aug 2022 08:27:59 +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, 16 Aug 2022 08:27:59 +0000 Received: by dev-dsk-farbere-1a-46ecabed.eu-west-1.amazon.com (Postfix, from userid 14301484) id 5CD724C0C; Tue, 16 Aug 2022 08:27:57 +0000 (UTC) From: Eliav Farber To: , , , , , , CC: , , , , , , , , , , , , Subject: [PATCH 10/16] hwmon: (mr75203) add VM pre-scalar support Date: Tue, 16 Aug 2022 08:27:51 +0000 Message-ID: <20220816082757.11990-11-farbere@amazon.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220816082757.11990-1-farbere@amazon.com> References: <20220816082757.11990-1-farbere@amazon.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add pre-scalar support to normalzie the voltage output results for channels the use pre-scalar units to get the measurement to be within the range that the sensor supports. The pre-scalar value is used if it exists in device-tree, otherwise default value of 1 is used. Signed-off-by: Eliav Farber --- drivers/hwmon/mr75203.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/drivers/hwmon/mr75203.c b/drivers/hwmon/mr75203.c index 9b45fd089fcf..417b135c1b3f 100644 --- a/drivers/hwmon/mr75203.c +++ b/drivers/hwmon/mr75203.c @@ -110,8 +110,12 @@ struct voltage_device { u8 vm_map; u8 ch_map; + u32 pre_scaler; }; +#define PRE_SCALR_PROPERTY_NAME 32 +#define PRE_SCALR_DEFAULT_VAL 1 + struct pvt_device { struct regmap *c_map; struct regmap *t_map; @@ -213,7 +217,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; + *val = pvt->vd[channel].pre_scaler; + *val *= (PVT_N_CONST * n - PVT_R_CONST); + *val >>= PVT_CONV_BITS; return 0; default: @@ -525,6 +531,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; + const struct device_node *np = pdev->dev.of_node; u32 ts_num, vm_num, pd_num, ch_num, val, index, i, j, k; struct device *dev = &pdev->dev; u32 *temp_config, *in_config; @@ -550,7 +557,7 @@ static int mr75203_probe(struct platform_device *pdev) return ret; } - if (of_property_read_bool(dev->of_node, "reset-control-skip")) { + if (of_property_read_bool(np, "reset-control-skip")) { dev_info(dev, "skipping reset-control\n"); } else { pvt->rst = devm_reset_control_get_exclusive(dev, NULL); @@ -613,6 +620,8 @@ static int mr75203_probe(struct platform_device *pdev) if (vm_num) { u8 vm_idx[vm_num]; u8 vm_active_ch[vm_num]; + char prop_name[PRE_SCALR_PROPERTY_NAME] = {0}; + u32 pre_scaler; ret = pvt_get_regmap(pdev, "vm", pvt); if (ret) @@ -684,6 +693,21 @@ static int mr75203_probe(struct platform_device *pdev) k++; } + /* + * Incase vm-pre-scalar-ch# property is not defined, we assume + * default pre-scaler of 1. + */ + for (i = 0; i < pvt->vm_ch_total; i++) { + snprintf(prop_name, sizeof(prop_name), + "vm-pre-scalar-ch%u", i); + + ret = of_property_read_u32(np, prop_name, &pre_scaler); + if (ret) + pvt->vd[i].pre_scaler = PRE_SCALR_DEFAULT_VAL; + else + pvt->vd[i].pre_scaler = pre_scaler; + } + in_config = devm_kcalloc(dev, pvt->vm_ch_total + 1, sizeof(*in_config), GFP_KERNEL); if (!in_config) -- 2.37.1