Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp4562711rwe; Tue, 30 Aug 2022 12:24:32 -0700 (PDT) X-Google-Smtp-Source: AA6agR58b+GllApsXO6iu+RODDXioDY7UZ6ZAiZd3/6IsDW6sJ1gfZRkrLFNkPph2Lj1WncdltQk X-Received: by 2002:a63:6b04:0:b0:42a:910f:2cde with SMTP id g4-20020a636b04000000b0042a910f2cdemr19803558pgc.59.1661887471650; Tue, 30 Aug 2022 12:24:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661887471; cv=none; d=google.com; s=arc-20160816; b=n4NV2R2jlf2th1eicRJbkT+nNyjiD8SiEKji/w9Yw4Vdx5yuc73KbkSRRu23NgfxbW BDK/062iwLJlCUoQ+vBJAm+t1P+Xg44cM4YrAKyOetwuKvG9YfD7Sce2jq2OCR7/59Du ffNKItTQuwpr21tBABsyxt1YTBD+Q6+U90sQHaXB7ijdeGSbFPEOlWltbpUGlcAxFnSC AN4QzYNjU0be/qtDGh4o7nJobyXVhtW6komyA0+B5B9qFJbAKnARbn3w3kk83yrdlLNa OzhiBOydqB9lT56T3GiYJfe8dZjp0yerCyxFeohmNvmBKaAfwKAlZ8iqfVuXNtvx//ox QmaQ== 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=CgCc/kIyAEbfD4l7q/Fx6aovclZtydu0RItcAhZsPf0=; b=I+4sC9N4dlBH8GSjwj68rHyrYDQk2mUxKLzMvvof8ilBG+HgoR/MlvZWy1tfY3U6yZ dp+pqrxLLXZHcHHD3iL5LPVhIEyuS3UX1S/raH0gDCA7BwhJcZctFMHXlJQj1Aid4di5 54ryHNfysVMXVeZtpzMEG7yjcaO0pxnAATJmhNMYwP5TJvb/0BcCbGJ6CQmL1kF6W3W9 y9egww4x2cUUMdxY6sGdgHV/NR9GbOsLZ1/7SHwIodF4ykhzVBfr1jI+8kFsMDajppV6 7cB+Q783vi+Iqro+p/wrjvcnjDtXTZZLo5hJrqJr+LAwaXpWB+kblvK/wvTwpNptU9y/ sCPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=l6MY9Zqq; 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 dw22-20020a056a00369600b00537e5d992c2si10501390pfb.56.2022.08.30.12.24.20; Tue, 30 Aug 2022 12:24:31 -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=l6MY9Zqq; 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 S231428AbiH3TWj (ORCPT + 99 others); Tue, 30 Aug 2022 15:22:39 -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 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 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; -- 2.37.1