From nobody Mon Apr 6 00:08:12 2026 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 94282C6FA89 for ; Tue, 13 Sep 2022 14:50:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234221AbiIMOuV (ORCPT ); Tue, 13 Sep 2022 10:50:21 -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-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 MR7= 5203 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 @@ =20 /* 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)) =20 /* 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 =3D dev_get_drvdata(dev); struct regmap *v_map =3D pvt->v_map; + u8 vm_idx, ch_idx; u32 n, stat; - u8 vm_idx; int ret; =20 - if (channel >=3D pvt->v_num) + if (channel >=3D pvt->v_num * pvt->c_num) return -EINVAL; =20 - vm_idx =3D pvt->vm_idx[channel]; + vm_idx =3D pvt->vm_idx[channel / pvt->c_num]; + ch_idx =3D channel % pvt->c_num; =20 switch (attr) { case hwmon_in_input: @@ -196,7 +199,7 @@ static int pvt_read_in(struct device *dev, u32 attr, in= t channel, long *val) if (ret) return ret; =20 - ret =3D regmap_read(v_map, VM_SDIF_DATA(vm_idx), &n); + ret =3D regmap_read(v_map, VM_SDIF_DATA(vm_idx, ch_idx), &n); if(ret < 0) return ret; =20 @@ -509,8 +512,8 @@ static int pvt_reset_control_deassert(struct device *de= v, struct pvt_device *pvt =20 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 =3D &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 =3D (val & TS_NUM_MSK) >> TS_NUM_SFT; pd_num =3D (val & PD_NUM_MSK) >> PD_NUM_SFT; vm_num =3D (val & VM_NUM_MSK) >> VM_NUM_SFT; + ch_num =3D (val & CH_NUM_MSK) >> CH_NUM_SFT; pvt->t_num =3D ts_num; pvt->p_num =3D pd_num; pvt->v_num =3D vm_num; + pvt->c_num =3D ch_num; val =3D 0; if (ts_num) val++; @@ -590,7 +595,7 @@ static int mr75203_probe(struct platform_device *pdev) } =20 if (vm_num) { - u32 num =3D vm_num; + u32 total_ch; =20 ret =3D pvt_get_regmap(pdev, "vm", pvt); if (ret) @@ -614,20 +619,20 @@ static int mr75203_probe(struct platform_device *pdev) for (i =3D 0; i < vm_num; i++) if (pvt->vm_idx[i] >=3D vm_num || pvt->vm_idx[i] =3D=3D 0xff) { - num =3D i; pvt->v_num =3D i; vm_num =3D i; break; } } =20 - in_config =3D devm_kcalloc(dev, num + 1, + total_ch =3D ch_num * vm_num; + in_config =3D devm_kcalloc(dev, total_ch + 1, sizeof(*in_config), GFP_KERNEL); if (!in_config) return -ENOMEM; =20 - memset32(in_config, HWMON_I_INPUT, num); - in_config[num] =3D 0; + memset32(in_config, HWMON_I_INPUT, total_ch); + in_config[total_ch] =3D 0; pvt_in.config =3D in_config; =20 pvt_info[index++] =3D &pvt_in; --=20 2.35.1