Re: [PATCH v3 3/4] hwmon: (ltc2945): add support for sense resistor

2021-01-08 Thread Alexandru Ardelean
On Thu, Jan 7, 2021 at 7:35 PM Guenter Roeck  wrote:
>
> On Thu, Jan 07, 2021 at 05:44:33PM +0200, Alexandru Ardelean wrote:
> > >
> > > Note that this patch doesn't compile on 32-bit targets.
> >
> > Yeah, my bad.
> > I only tested with  make allmodconfig, and that doesn't do a good job
> > at providing linker issues.
> >
> The problem is the 64-bit divide operation introduced with your patch.
> You'd see that if you build allmodconfig with ARCH=i386.

Oh, right.
That thought actually escaped me.

Thanks for the tip
Alex

>
> Guenter


Re: [PATCH v3 3/4] hwmon: (ltc2945): add support for sense resistor

2021-01-07 Thread Guenter Roeck
On Thu, Jan 07, 2021 at 05:44:33PM +0200, Alexandru Ardelean wrote:
> >
> > Note that this patch doesn't compile on 32-bit targets.
> 
> Yeah, my bad.
> I only tested with  make allmodconfig, and that doesn't do a good job
> at providing linker issues.
> 
The problem is the 64-bit divide operation introduced with your patch.
You'd see that if you build allmodconfig with ARCH=i386.

Guenter


Re: [PATCH v3 3/4] hwmon: (ltc2945): add support for sense resistor

2021-01-07 Thread Alexandru Ardelean
On Thu, Jan 7, 2021 at 5:25 PM Guenter Roeck  wrote:
>
> On Thu, Jan 07, 2021 at 12:34:16PM +0200, Alexandru Ardelean wrote:
> > The sense resistor is a parameter of the board. It should be configured in
> > the driver via a device-tree / ACPI property, so that the proper current
> > measurements can be done in the driver.
> >
> > It shouldn't be necessary that userspace need to know about the value of
> > the resistor. It makes things a bit harder to make the application code
> > portable from one board to another.
> >
> > This change implements support for the sense resistor to be configured from
> > DT/ACPI and used in current calculations.
> > Also, the maximum power and current that can be represented by the driver
> > are scaled with the value of the sense resistor.
> >
>
> In a way you are correct, but that applies to all hwmon
> drivers, not just to this one. A solution which only applies
> to a single driver doesn't solve the underlying problem,
> which would be the desire or need to provide kernel-based
> scaling for hwmon drivers. As such, I am not inclined to accept
> this patch. We should think about a generic solution instead.

I agree that scaling is an issue with hwmon [seeing as how IIO does it already].
Maybe I can adapt some things from IIO.
But I can't promise/commit to it quite yet.

>
> Note that this patch doesn't compile on 32-bit targets.

Yeah, my bad.
I only tested with  make allmodconfig, and that doesn't do a good job
at providing linker issues.

>
> Thanks,
> Guenter
>
> > Signed-off-by: Alexandru Ardelean 
> > ---
> >  drivers/hwmon/ltc2945.c | 60 ++---
> >  1 file changed, 39 insertions(+), 21 deletions(-)
> >
> > diff --git a/drivers/hwmon/ltc2945.c b/drivers/hwmon/ltc2945.c
> > index 41df2c8b7673..e60b15832b0e 100644
> > --- a/drivers/hwmon/ltc2945.c
> > +++ b/drivers/hwmon/ltc2945.c
> > @@ -70,9 +70,15 @@
> >  /**
> >   * struct ltc2945_state - driver instance specific data
> >   * @regmap:  regmap object to access device registers
> > + * @max_power_uw:maximum power that can be represented based on sense 
> > resistor
> > + * @max_current_ma:  maximum current that can be represented based on 
> > sense resistor
> > + * @r_sense_mohm:current sense resistor value
> >   */
> >  struct ltc2945_state {
> >   struct regmap   *regmap;
> > + u32 max_power_uw;
> > + u32 max_current_ma;
> > + u32 r_sense_mohm;
> >  };
> >
> >  static inline bool is_power_reg(u8 reg)
> > @@ -110,9 +116,8 @@ static long long ltc2945_reg_to_val(struct device *dev, 
> > u8 reg)
> >   case LTC2945_MAX_POWER_THRES_H:
> >   case LTC2945_MIN_POWER_THRES_H:
> >   /*
> > -  * Convert to uW by assuming current is measured with
> > -  * an 1mOhm sense resistor, similar to current
> > -  * measurements.
> > +  * Convert to uW by and scale it with the configured
> > +  * sense resistor, similar to current measurements.
> >* Control register bit 0 selects if voltage at SENSE+/VDD
> >* or voltage at ADIN is used to measure power.
> >*/
> > @@ -126,6 +131,7 @@ static long long ltc2945_reg_to_val(struct device *dev, 
> > u8 reg)
> >   /* 0.5 mV * 25 uV = 0.0125 uV resolution. */
> >   val = (val * 25LL) >> 1;
> >   }
> > + val /= st->r_sense_mohm;
> >   break;
> >   case LTC2945_VIN_H:
> >   case LTC2945_MAX_VIN_H:
> > @@ -149,13 +155,11 @@ static long long ltc2945_reg_to_val(struct device 
> > *dev, u8 reg)
> >   case LTC2945_MAX_SENSE_THRES_H:
> >   case LTC2945_MIN_SENSE_THRES_H:
> >   /*
> > -  * 25 uV resolution. Convert to current as measured with
> > -  * an 1 mOhm sense resistor, in mA. If a different sense
> > -  * resistor is installed, calculate the actual current by
> > -  * dividing the reported current by the sense resistor value
> > -  * in mOhm.
> > +  * 25 uV resolution. Convert to current and scale it
> > +  * with the value of the sense resistor.
> >*/
> >   val *= 25;
> > + val /= st->r_sense_mohm;
> >   break;
> >   default:
> >   return -EINVAL;
> > @@ -163,7 +167,8 @@ static long long ltc2945_reg_to_val(struct device *dev, 
> > u8 reg)
> >   return val;
> >  }
> >
> > -static unsigned long ltc2945_val_clamp(u8 reg, unsigned long val)
> > +static unsigned long ltc2945_val_clamp(struct ltc2945_state *st, u8 reg,
> > +unsigned long val)
> >  {
> >   switch (reg) {
> >   case LTC2945_POWER_H:
> > @@ -171,8 +176,7 @@ static unsigned long ltc2945_val_clamp(u8 reg, unsigned 
> > long val)
> >   case LTC2945_MIN_POWER_H:
> >   case LTC

Re: [PATCH v3 3/4] hwmon: (ltc2945): add support for sense resistor

2021-01-07 Thread Guenter Roeck
On Thu, Jan 07, 2021 at 12:34:16PM +0200, Alexandru Ardelean wrote:
> The sense resistor is a parameter of the board. It should be configured in
> the driver via a device-tree / ACPI property, so that the proper current
> measurements can be done in the driver.
> 
> It shouldn't be necessary that userspace need to know about the value of
> the resistor. It makes things a bit harder to make the application code
> portable from one board to another.
> 
> This change implements support for the sense resistor to be configured from
> DT/ACPI and used in current calculations.
> Also, the maximum power and current that can be represented by the driver
> are scaled with the value of the sense resistor.
> 

In a way you are correct, but that applies to all hwmon
drivers, not just to this one. A solution which only applies
to a single driver doesn't solve the underlying problem,
which would be the desire or need to provide kernel-based
scaling for hwmon drivers. As such, I am not inclined to accept
this patch. We should think about a generic solution instead.

Note that this patch doesn't compile on 32-bit targets.

Thanks,
Guenter

> Signed-off-by: Alexandru Ardelean 
> ---
>  drivers/hwmon/ltc2945.c | 60 ++---
>  1 file changed, 39 insertions(+), 21 deletions(-)
> 
> diff --git a/drivers/hwmon/ltc2945.c b/drivers/hwmon/ltc2945.c
> index 41df2c8b7673..e60b15832b0e 100644
> --- a/drivers/hwmon/ltc2945.c
> +++ b/drivers/hwmon/ltc2945.c
> @@ -70,9 +70,15 @@
>  /**
>   * struct ltc2945_state - driver instance specific data
>   * @regmap:  regmap object to access device registers
> + * @max_power_uw:maximum power that can be represented based on sense 
> resistor
> + * @max_current_ma:  maximum current that can be represented based on sense 
> resistor
> + * @r_sense_mohm:current sense resistor value
>   */
>  struct ltc2945_state {
>   struct regmap   *regmap;
> + u32 max_power_uw;
> + u32 max_current_ma;
> + u32 r_sense_mohm;
>  };
>  
>  static inline bool is_power_reg(u8 reg)
> @@ -110,9 +116,8 @@ static long long ltc2945_reg_to_val(struct device *dev, 
> u8 reg)
>   case LTC2945_MAX_POWER_THRES_H:
>   case LTC2945_MIN_POWER_THRES_H:
>   /*
> -  * Convert to uW by assuming current is measured with
> -  * an 1mOhm sense resistor, similar to current
> -  * measurements.
> +  * Convert to uW by and scale it with the configured
> +  * sense resistor, similar to current measurements.
>* Control register bit 0 selects if voltage at SENSE+/VDD
>* or voltage at ADIN is used to measure power.
>*/
> @@ -126,6 +131,7 @@ static long long ltc2945_reg_to_val(struct device *dev, 
> u8 reg)
>   /* 0.5 mV * 25 uV = 0.0125 uV resolution. */
>   val = (val * 25LL) >> 1;
>   }
> + val /= st->r_sense_mohm;
>   break;
>   case LTC2945_VIN_H:
>   case LTC2945_MAX_VIN_H:
> @@ -149,13 +155,11 @@ static long long ltc2945_reg_to_val(struct device *dev, 
> u8 reg)
>   case LTC2945_MAX_SENSE_THRES_H:
>   case LTC2945_MIN_SENSE_THRES_H:
>   /*
> -  * 25 uV resolution. Convert to current as measured with
> -  * an 1 mOhm sense resistor, in mA. If a different sense
> -  * resistor is installed, calculate the actual current by
> -  * dividing the reported current by the sense resistor value
> -  * in mOhm.
> +  * 25 uV resolution. Convert to current and scale it
> +  * with the value of the sense resistor.
>*/
>   val *= 25;
> + val /= st->r_sense_mohm;
>   break;
>   default:
>   return -EINVAL;
> @@ -163,7 +167,8 @@ static long long ltc2945_reg_to_val(struct device *dev, 
> u8 reg)
>   return val;
>  }
>  
> -static unsigned long ltc2945_val_clamp(u8 reg, unsigned long val)
> +static unsigned long ltc2945_val_clamp(struct ltc2945_state *st, u8 reg,
> +unsigned long val)
>  {
>   switch (reg) {
>   case LTC2945_POWER_H:
> @@ -171,8 +176,7 @@ static unsigned long ltc2945_val_clamp(u8 reg, unsigned 
> long val)
>   case LTC2945_MIN_POWER_H:
>   case LTC2945_MAX_POWER_THRES_H:
>   case LTC2945_MIN_POWER_THRES_H:
> - /* No sense in clamping now, LTC2945_POWER_FULL_SCALE_UW is 
> larger than UINT32_MAX */
> - return val;
> + return clamp_val(val, 0, st->max_power_uw);
>   case LTC2945_VIN_H:
>   case LTC2945_MAX_VIN_H:
>   case LTC2945_MIN_VIN_H:
> @@ -190,7 +194,7 @@ static unsigned long ltc2945_val_clamp(u8 reg, unsigned 
> long val)
>   case LTC2945_MIN_SENSE_H:
>   case LTC2945_MAX_SENSE_THRES_H:
>   case LTC2945_MIN_SEN

Re: [PATCH v3 3/4] hwmon: (ltc2945): add support for sense resistor

2021-01-07 Thread kernel test robot
Hi Alexandru,

I love your patch! Yet something to improve:

[auto build test ERROR on hwmon/hwmon-next]
[also build test ERROR on v5.11-rc2 next-20210104]
[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]

url:
https://github.com/0day-ci/linux/commits/Alexandru-Ardelean/hwmon-ltc2945-add-support-for-sense-resistor/20210107-183412
base:   
https://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging.git 
hwmon-next
config: i386-randconfig-a002-20210107 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-15) 9.3.0
reproduce (this is a W=1 build):
# 
https://github.com/0day-ci/linux/commit/1c0d97e2ccf58d83a895972d54b652adb1aba1c4
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review 
Alexandru-Ardelean/hwmon-ltc2945-add-support-for-sense-resistor/20210107-183412
git checkout 1c0d97e2ccf58d83a895972d54b652adb1aba1c4
# save the attached .config to linux build tree
make W=1 ARCH=i386 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot 

All errors (new ones prefixed by >>):

   ld: drivers/hwmon/ltc2945.o: in function `ltc2945_value_show':
   ltc2945.c:(.text+0x50e): undefined reference to `__divdi3'
>> ld: ltc2945.c:(.text+0x553): undefined reference to `__divdi3'
   ld: drivers/hwmon/ltc2945.o: in function `ltc2945_probe':
   ltc2945.c:(.text+0x63d): undefined reference to `__udivdi3'

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-...@lists.01.org


.config.gz
Description: application/gzip


Re: [PATCH v3 3/4] hwmon: (ltc2945): add support for sense resistor

2021-01-07 Thread Alexandru Ardelean
On Thu, Jan 7, 2021 at 3:29 PM kernel test robot  wrote:
>
> Hi Alexandru,
>
> I love your patch! Yet something to improve:

Huh?

I'm stumped.
This looks like it may not be related to my patch?

I'll take a look deeper in a couple of days.

>
> [auto build test ERROR on hwmon/hwmon-next]
> [also build test ERROR on v5.11-rc2 next-20210104]
> [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]
>
> url:
> https://github.com/0day-ci/linux/commits/Alexandru-Ardelean/hwmon-ltc2945-add-support-for-sense-resistor/20210107-183412
> base:   
> https://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging.git 
> hwmon-next
> config: openrisc-randconfig-r011-20210107 (attached as .config)
> compiler: or1k-linux-gcc (GCC) 9.3.0
> reproduce (this is a W=1 build):
> wget 
> https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O 
> ~/bin/make.cross
> chmod +x ~/bin/make.cross
> # 
> https://github.com/0day-ci/linux/commit/1c0d97e2ccf58d83a895972d54b652adb1aba1c4
> git remote add linux-review https://github.com/0day-ci/linux
> git fetch --no-tags linux-review 
> Alexandru-Ardelean/hwmon-ltc2945-add-support-for-sense-resistor/20210107-183412
> git checkout 1c0d97e2ccf58d83a895972d54b652adb1aba1c4
> # save the attached .config to linux build tree
> COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross 
> ARCH=openrisc
>
> If you fix the issue, kindly add following tag as appropriate
> Reported-by: kernel test robot 
>
> All errors (new ones prefixed by >>, old ones prefixed by <<):
>
> ERROR: modpost: "__mulsi3" [net/vmw_vsock/vsock.ko] undefined!
> ERROR: modpost: "__mulsi3" [net/9p/9pnet.ko] undefined!
> ERROR: modpost: "__mulsi3" [net/can/can-bcm.ko] undefined!
> ERROR: modpost: "__mulsi3" [net/can/can.ko] undefined!
> ERROR: modpost: "__mulsi3" [net/ax25/ax25.ko] undefined!
> ERROR: modpost: "__mulsi3" [net/netrom/netrom.ko] undefined!
> ERROR: modpost: "__mulsi3" [net/lapb/lapb.ko] undefined!
> ERROR: modpost: "__mulsi3" [net/packet/af_packet.ko] undefined!
> ERROR: modpost: "__mulsi3" [sound/soc/xtensa/snd-soc-xtfpga-i2s.ko] undefined!
> ERROR: modpost: "__mulsi3" [sound/soc/uniphier/snd-soc-uniphier-aio-cpu.ko] 
> undefined!
> ERROR: modpost: "__mulsi3" [sound/soc/sunxi/sun4i-i2s.ko] undefined!
> ERROR: modpost: "__mulsi3" [sound/soc/sti/snd-soc-sti.ko] undefined!
> ERROR: modpost: "__mulsi3" [sound/soc/img/img-spdif-in.ko] undefined!
> ERROR: modpost: "__mulsi3" [sound/soc/fsl/snd-soc-fsl-easrc.ko] undefined!
> ERROR: modpost: "__mulsi3" [sound/soc/fsl/snd-soc-fsl-esai.ko] undefined!
> ERROR: modpost: "__mulsi3" [sound/soc/fsl/snd-soc-fsl-ssi.ko] undefined!
> ERROR: modpost: "__mulsi3" [sound/soc/fsl/snd-soc-fsl-asrc.ko] undefined!
> ERROR: modpost: "__mulsi3" [sound/soc/bcm/snd-soc-cygnus.ko] undefined!
> ERROR: modpost: "__mulsi3" [sound/soc/atmel/snd-soc-mchp-i2s-mcc.ko] 
> undefined!
> ERROR: modpost: "__mulsi3" [sound/soc/codecs/snd-soc-sgtl5000.ko] undefined!
> ERROR: modpost: "__mulsi3" [sound/soc/codecs/snd-soc-rt5645.ko] undefined!
> ERROR: modpost: "__mulsi3" [sound/soc/codecs/snd-soc-rt5616.ko] undefined!
> ERROR: modpost: "__mulsi3" [sound/soc/codecs/snd-soc-rl6231.ko] undefined!
> ERROR: modpost: "__mulsi3" [sound/soc/codecs/snd-soc-nau8822.ko] undefined!
> ERROR: modpost: "__mulsi3" [sound/soc/codecs/snd-soc-cs42l42.ko] undefined!
> ERROR: modpost: "__mulsi3" [sound/firewire/motu/snd-firewire-motu.ko] 
> undefined!
> ERROR: modpost: "__mulsi3" [sound/firewire/tascam/snd-firewire-tascam.ko] 
> undefined!
> ERROR: modpost: "__mulsi3" [sound/firewire/digi00x/snd-firewire-digi00x.ko] 
> undefined!
> ERROR: modpost: "__mulsi3" [sound/firewire/snd-isight.ko] undefined!
> ERROR: modpost: "__mulsi3" [sound/firewire/dice/snd-dice.ko] undefined!
> ERROR: modpost: "__mulsi3" [sound/firewire/snd-firewire-lib.ko] undefined!
> ERROR: modpost: "__mulsi3" [sound/usb/hiface/snd-usb-hiface.ko] undefined!
> ERROR: modpost: "__mulsi3" [drivers/most/most_usb.ko] undefined!
> ERROR: modpost: "__mulsi3" [drivers/counter/counter.ko] undefined!
> ERROR: modpost: "__mulsi3" [drivers/hwtracing/stm/stm_core.ko] undefined!
> ERROR: modpost: "__mulsi3" [drivers/rpmsg/virtio_rpmsg_bus.ko] undefined!
> ERROR: modpost: "__mulsi3" [drivers/vhost/vhost.ko] undefined!
> ERROR: modpost: "__mulsi3" [drivers/vhost/vhost_vsock.ko] undefined!
> ERROR: modpost: "__mulsi3" [drivers/vhost/vhost_scsi.ko] undefined!
> ERROR: modpost: "__mulsi3" [drivers/vhost/vhost_net.ko] undefined!
> ERROR: modpost: "__mulsi3" [drivers/hwmon/occ/occ-hwmon-common.ko] undefined!
> ERROR: modpost: "__mulsi3" [drivers/hwmon/wm8350-hwmon.ko] undefined!
> ERROR: modpost: "__mulsi3" [drivers/hwmon/w83l786ng.ko] undefined!
> ERROR: modpost: "__mulsi3" [drivers/hwmon/w83l785ts.ko] undefined!
> ERROR: modpost: "__mulsi3" [drivers/hw

Re: [PATCH v3 3/4] hwmon: (ltc2945): add support for sense resistor

2021-01-07 Thread kernel test robot
Hi Alexandru,

I love your patch! Yet something to improve:

[auto build test ERROR on hwmon/hwmon-next]
[also build test ERROR on v5.11-rc2 next-20210104]
[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]

url:
https://github.com/0day-ci/linux/commits/Alexandru-Ardelean/hwmon-ltc2945-add-support-for-sense-resistor/20210107-183412
base:   
https://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging.git 
hwmon-next
config: openrisc-randconfig-r011-20210107 (attached as .config)
compiler: or1k-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
wget 
https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O 
~/bin/make.cross
chmod +x ~/bin/make.cross
# 
https://github.com/0day-ci/linux/commit/1c0d97e2ccf58d83a895972d54b652adb1aba1c4
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review 
Alexandru-Ardelean/hwmon-ltc2945-add-support-for-sense-resistor/20210107-183412
git checkout 1c0d97e2ccf58d83a895972d54b652adb1aba1c4
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross 
ARCH=openrisc 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot 

All errors (new ones prefixed by >>, old ones prefixed by <<):

ERROR: modpost: "__mulsi3" [net/vmw_vsock/vsock.ko] undefined!
ERROR: modpost: "__mulsi3" [net/9p/9pnet.ko] undefined!
ERROR: modpost: "__mulsi3" [net/can/can-bcm.ko] undefined!
ERROR: modpost: "__mulsi3" [net/can/can.ko] undefined!
ERROR: modpost: "__mulsi3" [net/ax25/ax25.ko] undefined!
ERROR: modpost: "__mulsi3" [net/netrom/netrom.ko] undefined!
ERROR: modpost: "__mulsi3" [net/lapb/lapb.ko] undefined!
ERROR: modpost: "__mulsi3" [net/packet/af_packet.ko] undefined!
ERROR: modpost: "__mulsi3" [sound/soc/xtensa/snd-soc-xtfpga-i2s.ko] undefined!
ERROR: modpost: "__mulsi3" [sound/soc/uniphier/snd-soc-uniphier-aio-cpu.ko] 
undefined!
ERROR: modpost: "__mulsi3" [sound/soc/sunxi/sun4i-i2s.ko] undefined!
ERROR: modpost: "__mulsi3" [sound/soc/sti/snd-soc-sti.ko] undefined!
ERROR: modpost: "__mulsi3" [sound/soc/img/img-spdif-in.ko] undefined!
ERROR: modpost: "__mulsi3" [sound/soc/fsl/snd-soc-fsl-easrc.ko] undefined!
ERROR: modpost: "__mulsi3" [sound/soc/fsl/snd-soc-fsl-esai.ko] undefined!
ERROR: modpost: "__mulsi3" [sound/soc/fsl/snd-soc-fsl-ssi.ko] undefined!
ERROR: modpost: "__mulsi3" [sound/soc/fsl/snd-soc-fsl-asrc.ko] undefined!
ERROR: modpost: "__mulsi3" [sound/soc/bcm/snd-soc-cygnus.ko] undefined!
ERROR: modpost: "__mulsi3" [sound/soc/atmel/snd-soc-mchp-i2s-mcc.ko] undefined!
ERROR: modpost: "__mulsi3" [sound/soc/codecs/snd-soc-sgtl5000.ko] undefined!
ERROR: modpost: "__mulsi3" [sound/soc/codecs/snd-soc-rt5645.ko] undefined!
ERROR: modpost: "__mulsi3" [sound/soc/codecs/snd-soc-rt5616.ko] undefined!
ERROR: modpost: "__mulsi3" [sound/soc/codecs/snd-soc-rl6231.ko] undefined!
ERROR: modpost: "__mulsi3" [sound/soc/codecs/snd-soc-nau8822.ko] undefined!
ERROR: modpost: "__mulsi3" [sound/soc/codecs/snd-soc-cs42l42.ko] undefined!
ERROR: modpost: "__mulsi3" [sound/firewire/motu/snd-firewire-motu.ko] undefined!
ERROR: modpost: "__mulsi3" [sound/firewire/tascam/snd-firewire-tascam.ko] 
undefined!
ERROR: modpost: "__mulsi3" [sound/firewire/digi00x/snd-firewire-digi00x.ko] 
undefined!
ERROR: modpost: "__mulsi3" [sound/firewire/snd-isight.ko] undefined!
ERROR: modpost: "__mulsi3" [sound/firewire/dice/snd-dice.ko] undefined!
ERROR: modpost: "__mulsi3" [sound/firewire/snd-firewire-lib.ko] undefined!
ERROR: modpost: "__mulsi3" [sound/usb/hiface/snd-usb-hiface.ko] undefined!
ERROR: modpost: "__mulsi3" [drivers/most/most_usb.ko] undefined!
ERROR: modpost: "__mulsi3" [drivers/counter/counter.ko] undefined!
ERROR: modpost: "__mulsi3" [drivers/hwtracing/stm/stm_core.ko] undefined!
ERROR: modpost: "__mulsi3" [drivers/rpmsg/virtio_rpmsg_bus.ko] undefined!
ERROR: modpost: "__mulsi3" [drivers/vhost/vhost.ko] undefined!
ERROR: modpost: "__mulsi3" [drivers/vhost/vhost_vsock.ko] undefined!
ERROR: modpost: "__mulsi3" [drivers/vhost/vhost_scsi.ko] undefined!
ERROR: modpost: "__mulsi3" [drivers/vhost/vhost_net.ko] undefined!
ERROR: modpost: "__mulsi3" [drivers/hwmon/occ/occ-hwmon-common.ko] undefined!
ERROR: modpost: "__mulsi3" [drivers/hwmon/wm8350-hwmon.ko] undefined!
ERROR: modpost: "__mulsi3" [drivers/hwmon/w83l786ng.ko] undefined!
ERROR: modpost: "__mulsi3" [drivers/hwmon/w83l785ts.ko] undefined!
ERROR: modpost: "__mulsi3" [drivers/hwmon/w83627ehf.ko] undefined!
ERROR: modpost: "__mulsi3" [drivers/hwmon/tmp421.ko] undefined!
ERROR: modpost: "__mulsi3" [drivers/hwmon/tmp401.ko] undefined!
ERROR: modpost: "__mulsi3" [drivers/hwmon/tmp108.ko] undefined!
ERROR: modpost: "__mulsi3" [drivers/hwmon/tmp102.ko] undefined!
ERROR: modpost: "__mulsi3" [drivers/hwmon/thmc50.ko] undefine

[PATCH v3 3/4] hwmon: (ltc2945): add support for sense resistor

2021-01-07 Thread Alexandru Ardelean
The sense resistor is a parameter of the board. It should be configured in
the driver via a device-tree / ACPI property, so that the proper current
measurements can be done in the driver.

It shouldn't be necessary that userspace need to know about the value of
the resistor. It makes things a bit harder to make the application code
portable from one board to another.

This change implements support for the sense resistor to be configured from
DT/ACPI and used in current calculations.
Also, the maximum power and current that can be represented by the driver
are scaled with the value of the sense resistor.

Signed-off-by: Alexandru Ardelean 
---
 drivers/hwmon/ltc2945.c | 60 ++---
 1 file changed, 39 insertions(+), 21 deletions(-)

diff --git a/drivers/hwmon/ltc2945.c b/drivers/hwmon/ltc2945.c
index 41df2c8b7673..e60b15832b0e 100644
--- a/drivers/hwmon/ltc2945.c
+++ b/drivers/hwmon/ltc2945.c
@@ -70,9 +70,15 @@
 /**
  * struct ltc2945_state - driver instance specific data
  * @regmap:regmap object to access device registers
+ * @max_power_uw:  maximum power that can be represented based on sense 
resistor
+ * @max_current_ma:maximum current that can be represented based on sense 
resistor
+ * @r_sense_mohm:  current sense resistor value
  */
 struct ltc2945_state {
struct regmap   *regmap;
+   u32 max_power_uw;
+   u32 max_current_ma;
+   u32 r_sense_mohm;
 };
 
 static inline bool is_power_reg(u8 reg)
@@ -110,9 +116,8 @@ static long long ltc2945_reg_to_val(struct device *dev, u8 
reg)
case LTC2945_MAX_POWER_THRES_H:
case LTC2945_MIN_POWER_THRES_H:
/*
-* Convert to uW by assuming current is measured with
-* an 1mOhm sense resistor, similar to current
-* measurements.
+* Convert to uW by and scale it with the configured
+* sense resistor, similar to current measurements.
 * Control register bit 0 selects if voltage at SENSE+/VDD
 * or voltage at ADIN is used to measure power.
 */
@@ -126,6 +131,7 @@ static long long ltc2945_reg_to_val(struct device *dev, u8 
reg)
/* 0.5 mV * 25 uV = 0.0125 uV resolution. */
val = (val * 25LL) >> 1;
}
+   val /= st->r_sense_mohm;
break;
case LTC2945_VIN_H:
case LTC2945_MAX_VIN_H:
@@ -149,13 +155,11 @@ static long long ltc2945_reg_to_val(struct device *dev, 
u8 reg)
case LTC2945_MAX_SENSE_THRES_H:
case LTC2945_MIN_SENSE_THRES_H:
/*
-* 25 uV resolution. Convert to current as measured with
-* an 1 mOhm sense resistor, in mA. If a different sense
-* resistor is installed, calculate the actual current by
-* dividing the reported current by the sense resistor value
-* in mOhm.
+* 25 uV resolution. Convert to current and scale it
+* with the value of the sense resistor.
 */
val *= 25;
+   val /= st->r_sense_mohm;
break;
default:
return -EINVAL;
@@ -163,7 +167,8 @@ static long long ltc2945_reg_to_val(struct device *dev, u8 
reg)
return val;
 }
 
-static unsigned long ltc2945_val_clamp(u8 reg, unsigned long val)
+static unsigned long ltc2945_val_clamp(struct ltc2945_state *st, u8 reg,
+  unsigned long val)
 {
switch (reg) {
case LTC2945_POWER_H:
@@ -171,8 +176,7 @@ static unsigned long ltc2945_val_clamp(u8 reg, unsigned 
long val)
case LTC2945_MIN_POWER_H:
case LTC2945_MAX_POWER_THRES_H:
case LTC2945_MIN_POWER_THRES_H:
-   /* No sense in clamping now, LTC2945_POWER_FULL_SCALE_UW is 
larger than UINT32_MAX */
-   return val;
+   return clamp_val(val, 0, st->max_power_uw);
case LTC2945_VIN_H:
case LTC2945_MAX_VIN_H:
case LTC2945_MIN_VIN_H:
@@ -190,7 +194,7 @@ static unsigned long ltc2945_val_clamp(u8 reg, unsigned 
long val)
case LTC2945_MIN_SENSE_H:
case LTC2945_MAX_SENSE_THRES_H:
case LTC2945_MIN_SENSE_THRES_H:
-   return clamp_val(val, 0, LTC2945_SENSE_FULL_SCALE_MA);
+   return clamp_val(val, 0, st->max_current_ma);
default:
/*
 * This is unlikely to happen, and if it does, it should
@@ -215,9 +219,8 @@ static int ltc2945_val_to_reg(struct device *dev, u8 reg,
case LTC2945_MAX_POWER_THRES_H:
case LTC2945_MIN_POWER_THRES_H:
/*
-* Convert to register value by assuming current is measured
-* with an 1mOhm sense resistor, similar to current
-* measure