From nobody Sun Sep 14 22:44:00 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 9AC3DC54EE9 for ; Tue, 13 Sep 2022 14:45:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231538AbiIMOpd (ORCPT ); Tue, 13 Sep 2022 10:45:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59458 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231614AbiIMOnJ (ORCPT ); Tue, 13 Sep 2022 10:43:09 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 79DD56E2C7; Tue, 13 Sep 2022 07:22:47 -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 ams.source.kernel.org (Postfix) with ESMTPS id 43ADBB80F62; Tue, 13 Sep 2022 14:21:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9EFDDC433C1; Tue, 13 Sep 2022 14:21:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1663078868; bh=Aigls/T2iIg9bgXoNDvZ6FXoUTDTCKp4pPfuwujQVR4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=J6AKmyNY8BN+4wzHGcs8BVcCdO0YPU8H8BHWJAtYSWsAjEMC2MT1JsjNOvzjewF/4 XXNN4u+RNiz76v5ANT3drwqIgb9ndPv0inkXDvkuEyYjV2SdmaXQ7zGDbMncTY5LBr Q0OgjIcsKewRQ2pddb4Eq+v4jt81mjfwBzdC1fiI= 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.15 113/121] hwmon: (mr75203) fix multi-channel voltage reading Date: Tue, 13 Sep 2022 16:05:04 +0200 Message-Id: <20220913140402.210610082@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220913140357.323297659@linuxfoundation.org> References: <20220913140357.323297659@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 630d596d4317f..e62fae1491c85 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