mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v1 0/1] hwmon: (isl28022) Fix current reading calculation
@ 2025-05-19  6:16 Yikai Tsai
  2025-05-19  6:16 ` [PATCH v1 1/1] " Yikai Tsai
  0 siblings, 1 reply; 4+ messages in thread
From: Yikai Tsai @ 2025-05-19  6:16 UTC (permalink / raw)
  To: patrick
  Cc: Yikai Tsai, Carsten Spieß,
	Jean Delvare, Guenter Roeck, linux-hwmon, linux-kernel

Fix the driver for Renesas ISL28022 power monitor chip.
According to the ISL28022 datasheet, bit15 of the current register is
representing -32768. Fix the calculation to properly handle this bit,
ensuring correct measurements for negative values.

v1: fix current reading calculation

Yikai Tsai (1):
  hwmon: (isl28022) Fix current reading calculation

 drivers/hwmon/isl28022.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

-- 
2.25.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v1 1/1] hwmon: (isl28022) Fix current reading calculation
  2025-05-19  6:16 [PATCH v1 0/1] hwmon: (isl28022) Fix current reading calculation Yikai Tsai
@ 2025-05-19  6:16 ` Yikai Tsai
  2025-05-19  8:25   ` kernel test robot
  2025-05-19 13:22   ` Guenter Roeck
  0 siblings, 2 replies; 4+ messages in thread
From: Yikai Tsai @ 2025-05-19  6:16 UTC (permalink / raw)
  To: patrick, Carsten Spieß, Jean Delvare, Guenter Roeck
  Cc: Yikai Tsai, linux-hwmon, linux-kernel

According to the ISL28022 datasheet, bit15 of the current register is
representing -32768. Fix the calculation to properly handle this bit,
ensuring correct measurements for negative values.

Signed-off-by: Yikai Tsai <yikai.tsai.wiwynn@gmail.com>
---
 drivers/hwmon/isl28022.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/hwmon/isl28022.c b/drivers/hwmon/isl28022.c
index 1fb9864635db..6d8cdf80c9ea 100644
--- a/drivers/hwmon/isl28022.c
+++ b/drivers/hwmon/isl28022.c
@@ -161,8 +161,9 @@ static int isl28022_read_current(struct device *dev, u32 attr, long *val)
 				  ISL28022_REG_CURRENT, &regval);
 		if (err < 0)
 			return err;
-		*val = ((long)regval * 1250L * (long)data->gain) /
-			(long)data->shunt;
+		sign_bit = (regval >> 15) & 0x01;
+		*val = (((long)(((u16)regval) & 0x7FFF) - (sign_bit * 32768)) *
+			1250L * (long)data->gain) / (long)data->shunt;
 		break;
 	default:
 		return -EOPNOTSUPP;
-- 
2.25.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v1 1/1] hwmon: (isl28022) Fix current reading calculation
  2025-05-19  6:16 ` [PATCH v1 1/1] " Yikai Tsai
@ 2025-05-19  8:25   ` kernel test robot
  2025-05-19 13:22   ` Guenter Roeck
  1 sibling, 0 replies; 4+ messages in thread
From: kernel test robot @ 2025-05-19  8:25 UTC (permalink / raw)
  To: Yikai Tsai, patrick, Carsten Spieß, Jean Delvare, Guenter Roeck
  Cc: oe-kbuild-all, Yikai Tsai, linux-hwmon, linux-kernel

Hi Yikai,

kernel test robot noticed the following build errors:

[auto build test ERROR on groeck-staging/hwmon-next]
[also build test ERROR on linus/master v6.15-rc7 next-20250516]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Yikai-Tsai/hwmon-isl28022-Fix-current-reading-calculation/20250519-142038
base:   https://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging.git hwmon-next
patch link:    https://lore.kernel.org/r/20250519061637.8796-2-yikai.tsai.wiwynn%40gmail.com
patch subject: [PATCH v1 1/1] hwmon: (isl28022) Fix current reading calculation
config: s390-randconfig-001-20250519 (https://download.01.org/0day-ci/archive/20250519/202505191635.mix4vgrC-lkp@intel.com/config)
compiler: s390-linux-gcc (GCC) 7.5.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250519/202505191635.mix4vgrC-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202505191635.mix4vgrC-lkp@intel.com/

All errors (new ones prefixed by >>):

   drivers/hwmon/isl28022.c: In function 'isl28022_read_current':
>> drivers/hwmon/isl28022.c:164:3: error: 'sign_bit' undeclared (first use in this function); did you mean 'assign_bit'?
      sign_bit = (regval >> 15) & 0x01;
      ^~~~~~~~
      assign_bit
   drivers/hwmon/isl28022.c:164:3: note: each undeclared identifier is reported only once for each function it appears in


vim +164 drivers/hwmon/isl28022.c

   151	
   152	static int isl28022_read_current(struct device *dev, u32 attr, long *val)
   153	{
   154		struct isl28022_data *data = dev_get_drvdata(dev);
   155		unsigned int regval;
   156		int err;
   157	
   158		switch (attr) {
   159		case hwmon_curr_input:
   160			err = regmap_read(data->regmap,
   161					  ISL28022_REG_CURRENT, &regval);
   162			if (err < 0)
   163				return err;
 > 164			sign_bit = (regval >> 15) & 0x01;
   165			*val = (((long)(((u16)regval) & 0x7FFF) - (sign_bit * 32768)) *
   166				1250L * (long)data->gain) / (long)data->shunt;
   167			break;
   168		default:
   169			return -EOPNOTSUPP;
   170		}
   171	
   172		return 0;
   173	}
   174	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v1 1/1] hwmon: (isl28022) Fix current reading calculation
  2025-05-19  6:16 ` [PATCH v1 1/1] " Yikai Tsai
  2025-05-19  8:25   ` kernel test robot
@ 2025-05-19 13:22   ` Guenter Roeck
  1 sibling, 0 replies; 4+ messages in thread
From: Guenter Roeck @ 2025-05-19 13:22 UTC (permalink / raw)
  To: Yikai Tsai, patrick, Carsten Spieß, Jean Delvare
  Cc: linux-hwmon, linux-kernel

On 5/18/25 23:16, Yikai Tsai wrote:
> According to the ISL28022 datasheet, bit15 of the current register is
> representing -32768. Fix the calculation to properly handle this bit,
> ensuring correct measurements for negative values.
> 
> Signed-off-by: Yikai Tsai <yikai.tsai.wiwynn@gmail.com>
> ---
>   drivers/hwmon/isl28022.c | 5 +++--
>   1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/hwmon/isl28022.c b/drivers/hwmon/isl28022.c
> index 1fb9864635db..6d8cdf80c9ea 100644
> --- a/drivers/hwmon/isl28022.c
> +++ b/drivers/hwmon/isl28022.c
> @@ -161,8 +161,9 @@ static int isl28022_read_current(struct device *dev, u32 attr, long *val)
>   				  ISL28022_REG_CURRENT, &regval);
>   		if (err < 0)
>   			return err;
> -		*val = ((long)regval * 1250L * (long)data->gain) /
> -			(long)data->shunt;
> +		sign_bit = (regval >> 15) & 0x01;

Just use (s16)(regval) or sign_extend() [granted, the rest of the code should
have done the same]. At the very least make sure that the code compiles.

Guenter

> +		*val = (((long)(((u16)regval) & 0x7FFF) - (sign_bit * 32768)) *
> +			1250L * (long)data->gain) / (long)data->shunt;
>   		break;
>   	default:
>   		return -EOPNOTSUPP;


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-05-19 13:22 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-05-19  6:16 [PATCH v1 0/1] hwmon: (isl28022) Fix current reading calculation Yikai Tsai
2025-05-19  6:16 ` [PATCH v1 1/1] " Yikai Tsai
2025-05-19  8:25   ` kernel test robot
2025-05-19 13:22   ` Guenter Roeck

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®