From nobody Fri Dec 19 01:38:57 2025 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 A3803C54EE9 for ; Tue, 13 Sep 2022 14:42:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231444AbiIMOms (ORCPT ); Tue, 13 Sep 2022 10:42:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60974 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231739AbiIMOlr (ORCPT ); Tue, 13 Sep 2022 10:41:47 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ED5EE6CD1A; Tue, 13 Sep 2022 07:22:03 -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 2C17E614C6; Tue, 13 Sep 2022 14:15:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 432D9C433B5; Tue, 13 Sep 2022 14:15:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1663078529; bh=mvcvsS+1zUqKJfTckT+CrHwvuKVgXAfDZbdDBQhLJmo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2ApvKk5aDj4v9NM6lVKC+RHI0/Y99wu60ienHXcJH4srXgEkobLnZJ54Mkj/bAbV/ sV5OOQrigteyuG6aWk9HyQ3GBUFPa06MFVhKoFqA5wxFNGoG1XiiuUs+89UMh66jaq /JCmF7+1lRTmv7cw+pz+ndzFMIbkGjD2w6VSDzKo= 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.19 176/192] hwmon: (mr75203) fix multi-channel voltage reading Date: Tue, 13 Sep 2022 16:04:42 +0200 Message-Id: <20220913140418.812679885@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220913140410.043243217@linuxfoundation.org> References: <20220913140410.043243217@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 6d3b3c499ed83..812ae40e7d74d 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 @@ -499,8 +502,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; @@ -541,9 +544,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++; @@ -580,7 +585,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) @@ -604,20 +609,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