Skip to contentSkip to conversation

hwmon: (pmbus/acbel-fsg032) Add firmware version debugfs attribute

PATCH In review Eddie James 3 participants 4 messages Jun 28, 2023 – Jun 29, 2023 Hardware monitoring

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 hwmon: (pmbus/acbel-fsg032) Add firmware version debugfs attribute

Like the IBM CFFPS driver, export the PSU's firmware version to a debugfs attribute as reported in the manufacturer register.

---
Changes since v1:
- Remove locking since there's only one page
- Switch to %*ph in snprintf instead of loop of %02x

 drivers/hwmon/pmbus/acbel-fsg032.c | 39 ++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)
drivers/hwmon/pmbus/acbel-fsg032.c +39 -0
index 0a0ef4ce3493..6413f5ae605f 100644
@@ -3,14 +3,52 @@
  * Copyright 2023 IBM Corp.
  */
 
+#include <linux/debugfs.h>
 #include <linux/device.h>
 #include <linux/fs.h>
 #include <linux/i2c.h>
+#include <linux/minmax.h>
 #include <linux/module.h>
 #include <linux/pmbus.h>
 #include <linux/hwmon-sysfs.h>
 #include "pmbus.h"
 
+#define ACBEL_MFR_FW_REVISION	0xd9
+
+static ssize_t acbel_fsg032_debugfs_read(struct file *file, char __user *buf, size_t count,
+					 loff_t *ppos)
+{
+	struct i2c_client *client = file->private_data;
+	char data[I2C_SMBUS_BLOCK_MAX + 2] = { 0 };
+	char out[8];
+	int rc;
+	int i;
+
+	rc = i2c_smbus_read_block_data(client, ACBEL_MFR_FW_REVISION, data);
+	if (rc < 0)
+		return rc;
+
+	rc = snprintf(out, sizeof(out), "%*phN\n", min(rc, 3), data);
+	return simple_read_from_buffer(buf, count, ppos, out, rc);
+}
+
+static const struct file_operations acbel_debugfs_ops = {
+	.llseek = noop_llseek,
+	.read = acbel_fsg032_debugfs_read,
+	.write = NULL,
+	.open = simple_open,
+};
+
+static void acbel_fsg032_init_debugfs(struct i2c_client *client)
+{
+	struct dentry *debugfs = pmbus_get_debugfs_dir(client);
+
+	if (!debugfs)
+		return;
+
+	debugfs_create_file("fw_version", 0444, debugfs, client, &acbel_debugfs_ops);
+}
+
 static const struct i2c_device_id acbel_fsg032_id[] = {
 	{ "acbel_fsg032" },
 	{}
@@ -59,6 +97,7 @@ static int acbel_fsg032_probe(struct i2c_client *client)
 	if (rc)
 		return rc;
 
+	acbel_fsg032_init_debugfs(client);
 	return 0;
 }
 
Signature · 1 line
2.39.3
maintainer Reviewed-by on v2 1/1
#1 lore raw
Quoted 4 lines · Eddie James

Like the IBM CFFPS driver, export the PSU's firmware version to a debugfs attribute as reported in the manufacturer register.

For my reference:

I'll apply after the commit window closes.

Thanks,
Guenter

Quoted 73 lines

---
Changes since v1:
- Remove locking since there's only one page
- Switch to %*ph in snprintf instead of loop of %02x

  drivers/hwmon/pmbus/acbel-fsg032.c | 39 ++++++++++++++++++++++++++++++
  1 file changed, 39 insertions(+)
drivers/hwmon/pmbus/acbel-fsg032.c +39 -0
index 0a0ef4ce3493..6413f5ae605f 100644
@@ -3,14 +3,52 @@
   * Copyright 2023 IBM Corp.
   */
 
+#include <linux/debugfs.h>
  #include <linux/device.h>
  #include <linux/fs.h>
  #include <linux/i2c.h>
+#include <linux/minmax.h>
  #include <linux/module.h>
  #include <linux/pmbus.h>
  #include <linux/hwmon-sysfs.h>
  #include "pmbus.h"
 
+#define ACBEL_MFR_FW_REVISION	0xd9
+
+static ssize_t acbel_fsg032_debugfs_read(struct file *file, char __user *buf, size_t count,
+					 loff_t *ppos)
+{
+	struct i2c_client *client = file->private_data;
+	char data[I2C_SMBUS_BLOCK_MAX + 2] = { 0 };
+	char out[8];
+	int rc;
+	int i;
+
+	rc = i2c_smbus_read_block_data(client, ACBEL_MFR_FW_REVISION, data);
+	if (rc < 0)
+		return rc;
+
+	rc = snprintf(out, sizeof(out), "%*phN\n", min(rc, 3), data);
+	return simple_read_from_buffer(buf, count, ppos, out, rc);
+}
+
+static const struct file_operations acbel_debugfs_ops = {
+	.llseek = noop_llseek,
+	.read = acbel_fsg032_debugfs_read,
+	.write = NULL,
+	.open = simple_open,
+};
+
+static void acbel_fsg032_init_debugfs(struct i2c_client *client)
+{
+	struct dentry *debugfs = pmbus_get_debugfs_dir(client);
+
+	if (!debugfs)
+		return;
+
+	debugfs_create_file("fw_version", 0444, debugfs, client, &acbel_debugfs_ops);
+}
+
  static const struct i2c_device_id acbel_fsg032_id[] = {
  	{ "acbel_fsg032" },
  	{}
@@ -59,6 +97,7 @@ static int acbel_fsg032_probe(struct i2c_client *client)
  	if (rc)
  		return rc;
 
+	acbel_fsg032_init_debugfs(client);
  	return 0;
  }
 
#2 lore raw
In reply to Eddie James
kernel test robot noticed the following build warnings:

Hi Eddie,

kernel test robot noticed the following build warnings:

[auto build test WARNING on groeck-staging/hwmon-next]
[also build test WARNING on linus/master v6.4 next-20230628] [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/Eddie-James/hwmon-pmbus-acbel-fsg032-Add-firmware-version-debugfs-attribute/20230628-233840
base:   https://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging.git hwmon-next
patch link:    https://lore.kernel.org/r/20230628153453.122213-1-eajames%40linux.ibm.com
patch subject: [PATCH v2] hwmon: (pmbus/acbel-fsg032) Add firmware version debugfs attribute
config: i386-randconfig-i012-20230628 (https://download.01.org/0day-ci/archive/20230629/[email protected]/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce: (https://download.01.org/0day-ci/archive/20230629/[email protected]/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 <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

drivers/hwmon/pmbus/acbel-fsg032.c: In function 'acbel_fsg032_debugfs_read':

>> drivers/hwmon/pmbus/acbel-fsg032.c:25:13: warning: unused variable 'i' [-Wunused-variable]
      25 |         int i;
         |             ^

vim +/i +25 drivers/hwmon/pmbus/acbel-fsg032.c

    17	
    18	static ssize_t acbel_fsg032_debugfs_read(struct file *file, char __user *buf, size_t count,
    19						 loff_t *ppos)
    20	{
    21		struct i2c_client *client = file->private_data;
    22		char data[I2C_SMBUS_BLOCK_MAX + 2] = { 0 };
    23		char out[8];
    24		int rc;
  > 25		int i;
    26	
    27		rc = i2c_smbus_read_block_data(client, ACBEL_MFR_FW_REVISION, data);
    28		if (rc < 0)
    29			return rc;
    30	
    31		rc = snprintf(out, sizeof(out), "%*phN\n", min(rc, 3), data);
    32		return simple_read_from_buffer(buf, count, ppos, out, rc);
    33	}
    34	
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#3 lore raw
In reply to Eddie James
kernel test robot noticed the following build warnings:

Hi Eddie,

kernel test robot noticed the following build warnings:

[auto build test WARNING on groeck-staging/hwmon-next]
[also build test WARNING on linus/master v6.4 next-20230628] [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/Eddie-James/hwmon-pmbus-acbel-fsg032-Add-firmware-version-debugfs-attribute/20230628-233840
base:   https://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging.git hwmon-next
patch link:    https://lore.kernel.org/r/20230628153453.122213-1-eajames%40linux.ibm.com
patch subject: [PATCH v2] hwmon: (pmbus/acbel-fsg032) Add firmware version debugfs attribute
config: x86_64-randconfig-x016-20230628 (https://download.01.org/0day-ci/archive/20230629/[email protected]/config)
compiler: clang version 15.0.7 (https://github.com/llvm/llvm-project.git 8dfdcc7b7bf66834a761bd8de445840ef68e4d1a)
reproduce: (https://download.01.org/0day-ci/archive/20230629/[email protected]/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 <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

>> drivers/hwmon/pmbus/acbel-fsg032.c:25:6: warning: unused variable 'i' [-Wunused-variable]
           int i;
               ^

1 warning generated.

vim +/i +25 drivers/hwmon/pmbus/acbel-fsg032.c

    17	
    18	static ssize_t acbel_fsg032_debugfs_read(struct file *file, char __user *buf, size_t count,
    19						 loff_t *ppos)
    20	{
    21		struct i2c_client *client = file->private_data;
    22		char data[I2C_SMBUS_BLOCK_MAX + 2] = { 0 };
    23		char out[8];
    24		int rc;
  > 25		int i;
    26	
    27		rc = i2c_smbus_read_block_data(client, ACBEL_MFR_FW_REVISION, data);
    28		if (rc < 0)
    29			return rc;
    30	
    31		rc = snprintf(out, sizeof(out), "%*phN\n", min(rc, 3), data);
    32		return simple_read_from_buffer(buf, count, ppos, out, rc);
    33	}
    34	
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki