Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp6831446rwn; Tue, 13 Sep 2022 09:32:56 -0700 (PDT) X-Google-Smtp-Source: AA6agR5HUFHmOQ9rj7bhDtW2f906CLitPAg4D11e1OaKpbQi/5JBc19aalB883qq5jPMqcNuFV3P X-Received: by 2002:a17:907:d07:b0:72e:ec79:ad0f with SMTP id gn7-20020a1709070d0700b0072eec79ad0fmr23084722ejc.296.1663086776259; Tue, 13 Sep 2022 09:32:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663086776; cv=none; d=google.com; s=arc-20160816; b=uJYpcqew28t+o8jWD/rigI5gjvUDF3fA2PmVPeJlsNHKcROiJrJBQ+ETVp2W+z7n3G f42/MWkBUydd1maqatALkVnQVlSs/pmz2xprTxZgWXA2pwTWH5yNks63xVIpedYKV0T+ 8O5khzYIP7l389N0EuHn6bLngSKC5et2AjC63cDmQVk3VcbQl273xfr+0e1j97Ybbi3n AkmhD8PIvoQOZrwZgBUuFzVI7KgOqMZ8+cZHxfVnhbrTW9U3JE5OGIs4yiggZrq/q73k DR4GtvZNgFn8WiEkjtXKCFapX/paZLbkedINNUawJ8Kmp67tDh3SPLdGZFsO36b8ghrw QcJA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=E5dODK4XfcST3Hp261Pere06tYNgAR8Y+h1blgOKhyU=; b=bND9SqgpdfGl9egFGdT5L7tHqo0MWBDr58s5kjzFiDkDsLG4XJvyHyNtn7a8gToxJP QuawiaTtGK2Se2iajgObjph7O+c1Z6eSkQfLG5yrZSTzdcqnJFXc49QZiNfbAEb/g/pm p2CMorlnJb2bx1o6z2KA8PhAJ9yGByz5ulLLlSaHwIDChBTm7C3xTfTdTM2D0cs2lG2P 5Kqzw6d2LBF0PQ8GUtRw1mfYrCp+aCfMufg3SoWdB4igKSH+I7Sd1wfKBWZxmScrMkrR qhU0/2w5J+caGg7M8YusLX3x6J+pZCZfP3ppKP1dM9FhI95YR4XXyfhRWw9nZLV4bgI2 oHIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=lt3HiNrP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s27-20020a170906061b00b0073d7f493935si7908693ejb.755.2022.09.13.09.32.02; Tue, 13 Sep 2022 09:32:56 -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=@linuxfoundation.org header.s=korg header.b=lt3HiNrP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233213AbiIMOuR (ORCPT + 99 others); Tue, 13 Sep 2022 10:50:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47090 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231722AbiIMOsG (ORCPT ); Tue, 13 Sep 2022 10:48:06 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D400140559; Tue, 13 Sep 2022 07:24:55 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 5C620614E7; Tue, 13 Sep 2022 14:24:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 75612C433C1; Tue, 13 Sep 2022 14:24:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1663079086; bh=q/kijbVduNiIdugxy6na5WAdoKPnDMCDgKhaCKwIfgo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lt3HiNrP2uYPrDMXuisfVaaE+ujBGOqf+M8MP+LQJph0Qg4e08PYIMEzIl6UHSkXT Yeefs2qzHlqqTDLr1dz6LPUsLcgefPoQLx38+njvH5g2GVbPpqmthEOan9YY7Rg5tK Hgnp+AHH3flptri4WCuqs3fgL98tkPhWa3ZvIH0E= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eliav Farber , Andy Shevchenko , Guenter Roeck , Sasha Levin Subject: [PATCH 5.10 77/79] hwmon: (mr75203) fix multi-channel voltage reading Date: Tue, 13 Sep 2022 16:05:22 +0200 Message-Id: <20220913140353.853425620@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220913140350.291927556@linuxfoundation.org> References: <20220913140350.291927556@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 From: Eliav Farber [ Upstream commit 91a9e063cdcfca8fe642b078d6fae4ce49187975 ] 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. Fixes: 9d823351a337 ("hwmon: Add hardware monitoring driver for Moortec MR75203 PVT controller") Signed-off-by: Eliav Farber Reviewed-by: Andy Shevchenko Link: https://lore.kernel.org/r/20220908152449.35457-6-farbere@amazon.com Signed-off-by: Guenter Roeck Signed-off-by: Sasha Levin --- drivers/hwmon/mr75203.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/drivers/hwmon/mr75203.c b/drivers/hwmon/mr75203.c index 8211d463495d0..87a14713e1249 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; }; @@ -178,14 +180,15 @@ 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; + u8 vm_idx, ch_idx; u32 n, stat; - u8 vm_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; @@ -509,8 +512,8 @@ static int pvt_reset_control_deassert(struct device *dev, struct pvt_device *pvt static int mr75203_probe(struct platform_device *pdev) { + u32 ts_num, vm_num, pd_num, ch_num, val, index, i; const struct hwmon_channel_info **pvt_info; - u32 ts_num, vm_num, pd_num, val, index, i; struct device *dev = &pdev->dev; u32 *temp_config, *in_config; struct device *hwmon_dev; @@ -551,9 +554,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++; @@ -590,7 +595,7 @@ static int mr75203_probe(struct platform_device *pdev) } if (vm_num) { - u32 num = vm_num; + u32 total_ch; ret = pvt_get_regmap(pdev, "vm", pvt); if (ret) @@ -614,20 +619,20 @@ static int mr75203_probe(struct platform_device *pdev) for (i = 0; i < vm_num; i++) if (pvt->vm_idx[i] >= vm_num || pvt->vm_idx[i] == 0xff) { - num = i; pvt->v_num = i; vm_num = i; break; } } - in_config = devm_kcalloc(dev, num + 1, + total_ch = ch_num * vm_num; + in_config = devm_kcalloc(dev, total_ch + 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, total_ch); + in_config[total_ch] = 0; pvt_in.config = in_config; pvt_info[index++] = &pvt_in; -- 2.35.1