diff mbox series

[v5] drivers: hwmon: max31827: Add PEC support

Message ID 20240530112505.14831-1-radu.sabau@analog.com (mailing list archive)
State Superseded
Headers show
Series [v5] drivers: hwmon: max31827: Add PEC support | expand

Commit Message

Radu Sabau May 30, 2024, 11:25 a.m. UTC
Add support for PEC by configuring chip accordingly to the hwmon core
PEC attribute handling.
Add chip_write function to be used by max31827_write when setting
the attribute.

Signed-off-by: Radu Sabau <radu.sabau@analog.com>
---
Change log:
v2:
 *Rebase on top of v6.9
 *Attach pec attribute only to i2c device
 *Fix bug to attach pec attribute to i2c device if the device supports it.
v3:
 *Use only one variable to write PEC_EN bit in configuration register
 *Use regmap_set_bits to set PEC_EN bit when requested instead of
  regmap_update_bits.
 *Fix typo in commit message.
v4:
 *Use regmap_clear_bits to clear PEC_EN bit when requested instead of
  regmap_update_bits.
v5:
 *Adapt driver to the new hwmon PEC attribute handling from the hwmon core.
---
 Documentation/hwmon/max31827.rst | 13 ++++++++++---
 drivers/hwmon/max31827.c         | 17 ++++++++++++++++-
 2 files changed, 26 insertions(+), 4 deletions(-)

Comments

kernel test robot May 31, 2024, 3:16 a.m. UTC | #1
Hi Radu,

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.10-rc1 next-20240529]
[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/Radu-Sabau/drivers-hwmon-max31827-Add-PEC-support/20240530-192727
base:   https://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging.git hwmon-next
patch link:    https://lore.kernel.org/r/20240530112505.14831-1-radu.sabau%40analog.com
patch subject: [PATCH v5] drivers: hwmon: max31827: Add PEC support
config: hexagon-allmodconfig (https://download.01.org/0day-ci/archive/20240531/202405311134.f2ALUwLL-lkp@intel.com/config)
compiler: clang version 19.0.0git (https://github.com/llvm/llvm-project bafda89a0944d947fc4b3b5663185e07a397ac30)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240531/202405311134.f2ALUwLL-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/202405311134.f2ALUwLL-lkp@intel.com/

All errors (new ones prefixed by >>):

   In file included from drivers/hwmon/max31827.c:12:
   In file included from include/linux/i2c.h:19:
   In file included from include/linux/regulator/consumer.h:35:
   In file included from include/linux/suspend.h:5:
   In file included from include/linux/swap.h:9:
   In file included from include/linux/memcontrol.h:13:
   In file included from include/linux/cgroup.h:26:
   In file included from include/linux/kernel_stat.h:9:
   In file included from include/linux/interrupt.h:11:
   In file included from include/linux/hardirq.h:11:
   In file included from ./arch/hexagon/include/generated/asm/hardirq.h:1:
   In file included from include/asm-generic/hardirq.h:17:
   In file included from include/linux/irq.h:20:
   In file included from include/linux/io.h:13:
   In file included from arch/hexagon/include/asm/io.h:328:
   include/asm-generic/io.h:547:31: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     547 |         val = __raw_readb(PCI_IOBASE + addr);
         |                           ~~~~~~~~~~ ^
   include/asm-generic/io.h:560:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     560 |         val = __le16_to_cpu((__le16 __force)__raw_readw(PCI_IOBASE + addr));
         |                                                         ~~~~~~~~~~ ^
   include/uapi/linux/byteorder/little_endian.h:37:51: note: expanded from macro '__le16_to_cpu'
      37 | #define __le16_to_cpu(x) ((__force __u16)(__le16)(x))
         |                                                   ^
   In file included from drivers/hwmon/max31827.c:12:
   In file included from include/linux/i2c.h:19:
   In file included from include/linux/regulator/consumer.h:35:
   In file included from include/linux/suspend.h:5:
   In file included from include/linux/swap.h:9:
   In file included from include/linux/memcontrol.h:13:
   In file included from include/linux/cgroup.h:26:
   In file included from include/linux/kernel_stat.h:9:
   In file included from include/linux/interrupt.h:11:
   In file included from include/linux/hardirq.h:11:
   In file included from ./arch/hexagon/include/generated/asm/hardirq.h:1:
   In file included from include/asm-generic/hardirq.h:17:
   In file included from include/linux/irq.h:20:
   In file included from include/linux/io.h:13:
   In file included from arch/hexagon/include/asm/io.h:328:
   include/asm-generic/io.h:573:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     573 |         val = __le32_to_cpu((__le32 __force)__raw_readl(PCI_IOBASE + addr));
         |                                                         ~~~~~~~~~~ ^
   include/uapi/linux/byteorder/little_endian.h:35:51: note: expanded from macro '__le32_to_cpu'
      35 | #define __le32_to_cpu(x) ((__force __u32)(__le32)(x))
         |                                                   ^
   In file included from drivers/hwmon/max31827.c:12:
   In file included from include/linux/i2c.h:19:
   In file included from include/linux/regulator/consumer.h:35:
   In file included from include/linux/suspend.h:5:
   In file included from include/linux/swap.h:9:
   In file included from include/linux/memcontrol.h:13:
   In file included from include/linux/cgroup.h:26:
   In file included from include/linux/kernel_stat.h:9:
   In file included from include/linux/interrupt.h:11:
   In file included from include/linux/hardirq.h:11:
   In file included from ./arch/hexagon/include/generated/asm/hardirq.h:1:
   In file included from include/asm-generic/hardirq.h:17:
   In file included from include/linux/irq.h:20:
   In file included from include/linux/io.h:13:
   In file included from arch/hexagon/include/asm/io.h:328:
   include/asm-generic/io.h:584:33: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     584 |         __raw_writeb(value, PCI_IOBASE + addr);
         |                             ~~~~~~~~~~ ^
   include/asm-generic/io.h:594:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     594 |         __raw_writew((u16 __force)cpu_to_le16(value), PCI_IOBASE + addr);
         |                                                       ~~~~~~~~~~ ^
   include/asm-generic/io.h:604:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     604 |         __raw_writel((u32 __force)cpu_to_le32(value), PCI_IOBASE + addr);
         |                                                       ~~~~~~~~~~ ^
   In file included from drivers/hwmon/max31827.c:12:
   In file included from include/linux/i2c.h:19:
   In file included from include/linux/regulator/consumer.h:35:
   In file included from include/linux/suspend.h:5:
   In file included from include/linux/swap.h:9:
   In file included from include/linux/memcontrol.h:21:
   In file included from include/linux/mm.h:2208:
   include/linux/vmstat.h:522:36: warning: arithmetic between different enumeration types ('enum node_stat_item' and 'enum lru_list') [-Wenum-enum-conversion]
     522 |         return node_stat_name(NR_LRU_BASE + lru) + 3; // skip "nr_"
         |                               ~~~~~~~~~~~ ^ ~~~
>> drivers/hwmon/max31827.c:336:32: error: declaration of anonymous struct must be a definition
     336 | static int max31827_chip_write(struct *regmap, u32 attr, long val)
         |                                ^
>> drivers/hwmon/max31827.c:339:7: error: use of undeclared identifier 'hwmon_chip_pec'; did you mean 'hwmon_chip'?
     339 |         case hwmon_chip_pec:
         |              ^~~~~~~~~~~~~~
         |              hwmon_chip
   include/linux/hwmon.h:21:2: note: 'hwmon_chip' declared here
      21 |         hwmon_chip,
         |         ^
>> drivers/hwmon/max31827.c:340:29: error: use of undeclared identifier 'regmap'
     340 |                 return regmap_update_bits(regmap, MAX31827_CONFIGURATION_REG,
         |                                           ^
>> drivers/hwmon/max31827.c:341:8: error: use of undeclared identifier 'MAX38127_CONFIGURATION_PEC_EN_MASK'
     341 |                                           MAX38127_CONFIGURATION_PEC_EN_MASK,
         |                                           ^
   drivers/hwmon/max31827.c:342:14: error: use of undeclared identifier 'MAX38127_CONFIGURATION_PEC_EN_MASK'
     342 |                                           val ? MAX38127_CONFIGURATION_PEC_EN_MASK : 0);
         |                                                 ^
>> drivers/hwmon/max31827.c:357:48: error: too many arguments to function call, expected 2, have 3
     357 |                 return max31827_chip_write(st->regmap, attr, val);
         |                        ~~~~~~~~~~~~~~~~~~~                   ^~~
   drivers/hwmon/max31827.c:336:12: note: 'max31827_chip_write' declared here
     336 | static int max31827_chip_write(struct *regmap, u32 attr, long val)
         |            ^                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> drivers/hwmon/max31827.c:399:7: error: duplicate case value 'hwmon_chip'
     399 |         case hwmon_chip:
         |              ^
   drivers/hwmon/max31827.c:356:7: note: previous case defined here
     356 |         case hwmon_chip:
         |              ^
>> drivers/hwmon/max31827.c:601:53: error: use of undeclared identifier 'HWMON_C_PEC'
     601 |         HWMON_CHANNEL_INFO(chip, HWMON_C_UPDATE_INTERVAL | HWMON_C_PEC),
         |                                                            ^
   7 warnings and 8 errors generated.


vim +336 drivers/hwmon/max31827.c

   335	
 > 336	static int max31827_chip_write(struct *regmap, u32 attr, long val)
   337	{
   338		switch (attr) {
 > 339		case hwmon_chip_pec:
 > 340			return regmap_update_bits(regmap, MAX31827_CONFIGURATION_REG,
 > 341						  MAX38127_CONFIGURATION_PEC_EN_MASK,
 > 342						  val ? MAX38127_CONFIGURATION_PEC_EN_MASK : 0);
   343		default:
   344			return -EOPNOTSUPP;
   345		}
   346	}
   347	
   348	static int max31827_write(struct device *dev, enum hwmon_sensor_types type,
   349				  u32 attr, int channel, long val)
   350	{
   351		struct max31827_state *st = dev_get_drvdata(dev);
   352		int res = 1;
   353		int ret;
   354	
   355		switch (type) {
   356		case hwmon_chip:
 > 357			return max31827_chip_write(st->regmap, attr, val);
   358		case hwmon_temp:
   359			switch (attr) {
   360			case hwmon_temp_enable:
   361				if (val >> 1)
   362					return -EINVAL;
   363	
   364				mutex_lock(&st->lock);
   365				/**
   366				 * The chip should not be enabled while a conversion is
   367				 * performed. Neither should the chip be enabled when
   368				 * the alarm values are changed.
   369				 */
   370	
   371				st->enable = val;
   372	
   373				ret = regmap_update_bits(st->regmap,
   374							 MAX31827_CONFIGURATION_REG,
   375							 MAX31827_CONFIGURATION_1SHOT_MASK |
   376							 MAX31827_CONFIGURATION_CNV_RATE_MASK,
   377							 MAX31827_DEVICE_ENABLE(val));
   378	
   379				mutex_unlock(&st->lock);
   380	
   381				return ret;
   382	
   383			case hwmon_temp_max:
   384				return write_alarm_val(st, MAX31827_TH_REG, val);
   385	
   386			case hwmon_temp_max_hyst:
   387				return write_alarm_val(st, MAX31827_TH_HYST_REG, val);
   388	
   389			case hwmon_temp_min:
   390				return write_alarm_val(st, MAX31827_TL_REG, val);
   391	
   392			case hwmon_temp_min_hyst:
   393				return write_alarm_val(st, MAX31827_TL_HYST_REG, val);
   394	
   395			default:
   396				return -EOPNOTSUPP;
   397			}
   398	
 > 399		case hwmon_chip:
   400			if (attr == hwmon_chip_update_interval) {
   401				if (!st->enable)
   402					return -EINVAL;
   403	
   404				/*
   405				 * Convert the desired conversion rate into register
   406				 * bits. res is already initialized with 1.
   407				 *
   408				 * This was inspired by lm73 driver.
   409				 */
   410				while (res < ARRAY_SIZE(max31827_conversions) &&
   411				       val < max31827_conversions[res])
   412					res++;
   413	
   414				if (res == ARRAY_SIZE(max31827_conversions))
   415					res = ARRAY_SIZE(max31827_conversions) - 1;
   416	
   417				res = FIELD_PREP(MAX31827_CONFIGURATION_CNV_RATE_MASK,
   418						 res);
   419	
   420				ret = regmap_update_bits(st->regmap,
   421							 MAX31827_CONFIGURATION_REG,
   422							 MAX31827_CONFIGURATION_CNV_RATE_MASK,
   423							 res);
   424				if (ret)
   425					return ret;
   426	
   427				st->update_interval = val;
   428			}
   429			break;
   430	
   431		default:
   432			return -EOPNOTSUPP;
   433		}
   434	
   435		return 0;
   436	}
   437
Radu Sabau May 31, 2024, 8:26 a.m. UTC | #2
> -----Original Message-----
> From: Radu Sabau <radu.sabau@analog.com>
> Sent: Thursday, May 30, 2024 2:25 PM
> To: Jean Delvare <jdelvare@suse.com>; Guenter Roeck <linux@roeck-us.net>; Jonathan Corbet <corbet@lwn.net>; linux-
> hwmon@vger.kernel.org; linux-doc@vger.kernel.org; linux-kernel@vger.kernel.org
> Cc: Sabau, Radu bogdan <Radu.Sabau@analog.com>
> Subject: [PATCH v5] drivers: hwmon: max31827: Add PEC support
> 
> Add support for PEC by configuring chip accordingly to the hwmon core
> PEC attribute handling.
> Add chip_write function to be used by max31827_write when setting
> the attribute.
> 
> Signed-off-by: Radu Sabau <radu.sabau@analog.com>
> ---
> Change log:
> v2:
>  *Rebase on top of v6.9
>  *Attach pec attribute only to i2c device
>  *Fix bug to attach pec attribute to i2c device if the device supports it.
> v3:
>  *Use only one variable to write PEC_EN bit in configuration register
>  *Use regmap_set_bits to set PEC_EN bit when requested instead of
>   regmap_update_bits.
>  *Fix typo in commit message.
> v4:
>  *Use regmap_clear_bits to clear PEC_EN bit when requested instead of
>   regmap_update_bits.
> v5:
>  *Adapt driver to the new hwmon PEC attribute handling from the hwmon core.
> ---
>  Documentation/hwmon/max31827.rst | 13 ++++++++++---
>  drivers/hwmon/max31827.c         | 17 ++++++++++++++++-
>  2 files changed, 26 insertions(+), 4 deletions(-)
> 
> diff --git a/Documentation/hwmon/max31827.rst b/Documentation/hwmon/max31827.rst
> index 44ab9dc064cb..9c11a9518c67 100644
> --- a/Documentation/hwmon/max31827.rst
> +++ b/Documentation/hwmon/max31827.rst
> @@ -131,7 +131,14 @@ The Fault Queue bits select how many consecutive temperature faults must occur
>  before overtemperature or undertemperature faults are indicated in the
>  corresponding status bits.
> 
> -Notes
> ------
> +PEC Support
> +-----------
> +
> +When reading a register value, the PEC byte is computed and sent by the chip.
> +
> +PEC on word data transaction respresents a signifcant increase in bandwitdh
> +usage (+33% for both write and reads) in normal conditions.
> 
> -PEC is not implemented.
> +Since this operation implies there will be an extra delay to each
> +transaction, PEC can be disabled or enabled through sysfs.
> +Just write 1  to the "pec" file for enabling PEC and 0 for disabling it.
> diff --git a/drivers/hwmon/max31827.c b/drivers/hwmon/max31827.c
> index f8a13b30f100..4a5f86afd84e 100644
> --- a/drivers/hwmon/max31827.c
> +++ b/drivers/hwmon/max31827.c
> @@ -24,6 +24,7 @@
> 
>  #define MAX31827_CONFIGURATION_1SHOT_MASK	BIT(0)
>  #define MAX31827_CONFIGURATION_CNV_RATE_MASK	GENMASK(3, 1)
> +#define MAX31827_CONFIGURATION_PEC_EN_MASK	BIT(4)
>  #define MAX31827_CONFIGURATION_TIMEOUT_MASK	BIT(5)
>  #define MAX31827_CONFIGURATION_RESOLUTION_MASK	GENMASK(7, 6)
>  #define MAX31827_CONFIGURATION_ALRM_POL_MASK	BIT(8)
> @@ -332,6 +333,18 @@ static int max31827_read(struct device *dev, enum hwmon_sensor_types type,
>  	return ret;
>  }
> 
> +static int max31827_chip_write(struct *regmap, u32 attr, long val)

regmap parameter is declared wrong here, will send fix in next patch.

> +{
> +	switch (attr) {
> +	case hwmon_chip_pec:
> +		return regmap_update_bits(regmap, MAX31827_CONFIGURATION_REG,
> +					  MAX38127_CONFIGURATION_PEC_EN_MASK,

typo, MAX38127 -> MAX31827

> +					  val ? MAX38127_CONFIGURATION_PEC_EN_MASK : 0);

typo, MAX38127 -> MAX31827

> +	default:
> +		return -EOPNOTSUPP;
> +	}
> +}
> +
>  static int max31827_write(struct device *dev, enum hwmon_sensor_types type,
>  			  u32 attr, int channel, long val)
>  {
> @@ -340,6 +353,8 @@ static int max31827_write(struct device *dev, enum hwmon_sensor_types type,
>  	int ret;
> 
>  	switch (type) {
> +	case hwmon_chip:
> +		return max31827_chip_write(st->regmap, attr, val);
>  	case hwmon_temp:
>  		switch (attr) {
>  		case hwmon_temp_enable:
> @@ -583,7 +598,7 @@ static const struct hwmon_channel_info *max31827_info[] = {
>  					 HWMON_T_MIN_HYST | HWMON_T_MIN_ALARM |
>  					 HWMON_T_MAX | HWMON_T_MAX_HYST |
>  					 HWMON_T_MAX_ALARM),
> -	HWMON_CHANNEL_INFO(chip, HWMON_C_UPDATE_INTERVAL),
> +	HWMON_CHANNEL_INFO(chip, HWMON_C_UPDATE_INTERVAL | HWMON_C_PEC),
>  	NULL,
>  };

This patch is wrong due to the fact that hwmon_chip case is duplicated inside the switch, and therefore
I will send another patch fixing this and also modifying max31827_chip_write.

> 
> --
> 2.34.1
diff mbox series

Patch

diff --git a/Documentation/hwmon/max31827.rst b/Documentation/hwmon/max31827.rst
index 44ab9dc064cb..9c11a9518c67 100644
--- a/Documentation/hwmon/max31827.rst
+++ b/Documentation/hwmon/max31827.rst
@@ -131,7 +131,14 @@  The Fault Queue bits select how many consecutive temperature faults must occur
 before overtemperature or undertemperature faults are indicated in the
 corresponding status bits.
 
-Notes
------
+PEC Support
+-----------
+
+When reading a register value, the PEC byte is computed and sent by the chip.
+
+PEC on word data transaction respresents a signifcant increase in bandwitdh
+usage (+33% for both write and reads) in normal conditions.
 
-PEC is not implemented.
+Since this operation implies there will be an extra delay to each
+transaction, PEC can be disabled or enabled through sysfs.
+Just write 1  to the "pec" file for enabling PEC and 0 for disabling it.
diff --git a/drivers/hwmon/max31827.c b/drivers/hwmon/max31827.c
index f8a13b30f100..4a5f86afd84e 100644
--- a/drivers/hwmon/max31827.c
+++ b/drivers/hwmon/max31827.c
@@ -24,6 +24,7 @@ 
 
 #define MAX31827_CONFIGURATION_1SHOT_MASK	BIT(0)
 #define MAX31827_CONFIGURATION_CNV_RATE_MASK	GENMASK(3, 1)
+#define MAX31827_CONFIGURATION_PEC_EN_MASK	BIT(4)
 #define MAX31827_CONFIGURATION_TIMEOUT_MASK	BIT(5)
 #define MAX31827_CONFIGURATION_RESOLUTION_MASK	GENMASK(7, 6)
 #define MAX31827_CONFIGURATION_ALRM_POL_MASK	BIT(8)
@@ -332,6 +333,18 @@  static int max31827_read(struct device *dev, enum hwmon_sensor_types type,
 	return ret;
 }
 
+static int max31827_chip_write(struct *regmap, u32 attr, long val)
+{
+	switch (attr) {
+	case hwmon_chip_pec:
+		return regmap_update_bits(regmap, MAX31827_CONFIGURATION_REG,
+					  MAX38127_CONFIGURATION_PEC_EN_MASK,
+					  val ? MAX38127_CONFIGURATION_PEC_EN_MASK : 0);
+	default:
+		return -EOPNOTSUPP;
+	}
+}
+
 static int max31827_write(struct device *dev, enum hwmon_sensor_types type,
 			  u32 attr, int channel, long val)
 {
@@ -340,6 +353,8 @@  static int max31827_write(struct device *dev, enum hwmon_sensor_types type,
 	int ret;
 
 	switch (type) {
+	case hwmon_chip:
+		return max31827_chip_write(st->regmap, attr, val);
 	case hwmon_temp:
 		switch (attr) {
 		case hwmon_temp_enable:
@@ -583,7 +598,7 @@  static const struct hwmon_channel_info *max31827_info[] = {
 					 HWMON_T_MIN_HYST | HWMON_T_MIN_ALARM |
 					 HWMON_T_MAX | HWMON_T_MAX_HYST |
 					 HWMON_T_MAX_ALARM),
-	HWMON_CHANNEL_INFO(chip, HWMON_C_UPDATE_INTERVAL),
+	HWMON_CHANNEL_INFO(chip, HWMON_C_UPDATE_INTERVAL | HWMON_C_PEC),
 	NULL,
 };