diff mbox series

hwmon: (pmbus) Expose PEC debugfs attribute

Message ID 20200909132411.2906159-1-andrew@aj.id.au (mailing list archive)
State Changes Requested
Headers show
Series hwmon: (pmbus) Expose PEC debugfs attribute | expand

Commit Message

Andrew Jeffery Sept. 9, 2020, 1:24 p.m. UTC
Enable runtime debug control of whether the PEC byte is exchanged with
the PMBus device.

Some manufacturers have asked for the PEC to be disabled as part of
debugging driver communication issues with devices.

Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
---
 drivers/hwmon/pmbus/pmbus_core.c | 39 ++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)

Comments

Guenter Roeck Sept. 9, 2020, 3:31 p.m. UTC | #1
On 9/9/20 6:24 AM, Andrew Jeffery wrote:
> Enable runtime debug control of whether the PEC byte is exchanged with
> the PMBus device.
> 
> Some manufacturers have asked for the PEC to be disabled as part of
> debugging driver communication issues with devices.
> 
> Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
> ---
>  drivers/hwmon/pmbus/pmbus_core.c | 39 ++++++++++++++++++++++++++++++++
>  1 file changed, 39 insertions(+)
> 
> diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
> index 44535add3a4a..51c8502b35e9 100644
> --- a/drivers/hwmon/pmbus/pmbus_core.c
> +++ b/drivers/hwmon/pmbus/pmbus_core.c
> @@ -2346,6 +2346,42 @@ static int pmbus_debugfs_get_status(void *data, u64 *val)
>  DEFINE_DEBUGFS_ATTRIBUTE(pmbus_debugfs_ops_status, pmbus_debugfs_get_status,
>  			 NULL, "0x%04llx\n");
>  
> +static int pmbus_debugfs_get_pec(void *data, u64 *val)
> +{
> +	struct i2c_client *client = data;
> +
> +	*val = !!(client->flags & I2C_CLIENT_PEC);
> +
> +	return 0;
> +}
> +
> +static int pmbus_debugfs_set_pec(void *data, u64 val)
> +{
> +	int rc;
> +	struct i2c_client *client = data;
> +
> +	if (!val) {
> +		client->flags &= ~I2C_CLIENT_PEC;
> +		return 0;
> +	}
> +
> +	if (val != 1)
> +		return -EINVAL;
> +
> +	rc = i2c_smbus_read_byte_data(client, PMBUS_CAPABILITY);
> +	if (rc < 0)
> +		return rc;
> +
> +	if (!(rc & PB_CAPABILITY_ERROR_CHECK))
> +		return -ENOTSUPP;

WARNING: ENOTSUPP is not a SUSV4 error code, prefer EOPNOTSUPP

> +
> +	client->flags |= I2C_CLIENT_PEC;
> +
> +	return 0;
> +}
> +DEFINE_DEBUGFS_ATTRIBUTE(pmbus_debugfs_ops_pec, pmbus_debugfs_get_pec,
> +			 pmbus_debugfs_set_pec, "0x%1llu\n");

ERROR: Prefixing 0x with decimal output is defective

(since the displayed value is a boolean, it is also quite useless).

> +
>  static int pmbus_init_debugfs(struct i2c_client *client,
>  			      struct pmbus_data *data)
>  {
> @@ -2374,6 +2410,9 @@ static int pmbus_init_debugfs(struct i2c_client *client,
>  	if (!entries)
>  		return -ENOMEM;
>  
> +	debugfs_create_file("pec", 0664, data->debugfs, client,
> +			    &pmbus_debugfs_ops_pec);
> +
>  	for (i = 0; i < data->info->pages; ++i) {
>  		/* Check accessibility of status register if it's not page 0 */
>  		if (!i || pmbus_check_status_register(client, i)) {
>
Andrew Jeffery Sept. 10, 2020, 2:12 a.m. UTC | #2
On Thu, 10 Sep 2020, at 01:01, Guenter Roeck wrote:
> On 9/9/20 6:24 AM, Andrew Jeffery wrote:
> > Enable runtime debug control of whether the PEC byte is exchanged with
> > the PMBus device.
> > 
> > Some manufacturers have asked for the PEC to be disabled as part of
> > debugging driver communication issues with devices.
> > 
> > Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
> > ---
> >  drivers/hwmon/pmbus/pmbus_core.c | 39 ++++++++++++++++++++++++++++++++
> >  1 file changed, 39 insertions(+)
> > 
> > diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
> > index 44535add3a4a..51c8502b35e9 100644
> > --- a/drivers/hwmon/pmbus/pmbus_core.c
> > +++ b/drivers/hwmon/pmbus/pmbus_core.c
> > @@ -2346,6 +2346,42 @@ static int pmbus_debugfs_get_status(void *data, u64 *val)
> >  DEFINE_DEBUGFS_ATTRIBUTE(pmbus_debugfs_ops_status, pmbus_debugfs_get_status,
> >  			 NULL, "0x%04llx\n");
> >  
> > +static int pmbus_debugfs_get_pec(void *data, u64 *val)
> > +{
> > +	struct i2c_client *client = data;
> > +
> > +	*val = !!(client->flags & I2C_CLIENT_PEC);
> > +
> > +	return 0;
> > +}
> > +
> > +static int pmbus_debugfs_set_pec(void *data, u64 val)
> > +{
> > +	int rc;
> > +	struct i2c_client *client = data;
> > +
> > +	if (!val) {
> > +		client->flags &= ~I2C_CLIENT_PEC;
> > +		return 0;
> > +	}
> > +
> > +	if (val != 1)
> > +		return -EINVAL;
> > +
> > +	rc = i2c_smbus_read_byte_data(client, PMBUS_CAPABILITY);
> > +	if (rc < 0)
> > +		return rc;
> > +
> > +	if (!(rc & PB_CAPABILITY_ERROR_CHECK))
> > +		return -ENOTSUPP;
> 
> WARNING: ENOTSUPP is not a SUSV4 error code, prefer EOPNOTSUPP
> 
> > +
> > +	client->flags |= I2C_CLIENT_PEC;
> > +
> > +	return 0;
> > +}
> > +DEFINE_DEBUGFS_ATTRIBUTE(pmbus_debugfs_ops_pec, pmbus_debugfs_get_pec,
> > +			 pmbus_debugfs_set_pec, "0x%1llu\n");
> 
> ERROR: Prefixing 0x with decimal output is defective
> 
> (since the displayed value is a boolean, it is also quite useless).

Indeed. I overlooked running checkpatch, sorry for the noise.

I've sent v2 which checkpatch claims to be clean.

Andrew
Dan Carpenter Sept. 10, 2020, 10:05 a.m. UTC | #3
Hi Andrew,

url:    https://github.com/0day-ci/linux/commits/Andrew-Jeffery/hwmon-pmbus-Expose-PEC-debugfs-attribute/20200910-010642
base:   https://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging.git hwmon-next
config: x86_64-randconfig-m001-20200909 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-15) 9.3.0

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>

smatch warnings:
drivers/hwmon/pmbus/pmbus_core.c:2415 pmbus_debugfs_ops_pec_open() warn: '0x' prefix is confusing together with '%1llu' specifier

# https://github.com/0day-ci/linux/commit/705b8b5588d4102256d0954086ed16c9bdf9804f
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Andrew-Jeffery/hwmon-pmbus-Expose-PEC-debugfs-attribute/20200910-010642
git checkout 705b8b5588d4102256d0954086ed16c9bdf9804f
vim +2415 drivers/hwmon/pmbus/pmbus_core.c

705b8b5588d410 Andrew Jeffery 2020-09-09  2391  static int pmbus_debugfs_set_pec(void *data, u64 val)
705b8b5588d410 Andrew Jeffery 2020-09-09  2392  {
705b8b5588d410 Andrew Jeffery 2020-09-09  2393  	int rc;
705b8b5588d410 Andrew Jeffery 2020-09-09  2394  	struct i2c_client *client = data;
705b8b5588d410 Andrew Jeffery 2020-09-09  2395  
705b8b5588d410 Andrew Jeffery 2020-09-09  2396  	if (!val) {
705b8b5588d410 Andrew Jeffery 2020-09-09  2397  		client->flags &= ~I2C_CLIENT_PEC;
705b8b5588d410 Andrew Jeffery 2020-09-09  2398  		return 0;
705b8b5588d410 Andrew Jeffery 2020-09-09  2399  	}
705b8b5588d410 Andrew Jeffery 2020-09-09  2400  
705b8b5588d410 Andrew Jeffery 2020-09-09  2401  	if (val != 1)
705b8b5588d410 Andrew Jeffery 2020-09-09  2402  		return -EINVAL;
705b8b5588d410 Andrew Jeffery 2020-09-09  2403  
705b8b5588d410 Andrew Jeffery 2020-09-09  2404  	rc = i2c_smbus_read_byte_data(client, PMBUS_CAPABILITY);
705b8b5588d410 Andrew Jeffery 2020-09-09  2405  	if (rc < 0)
705b8b5588d410 Andrew Jeffery 2020-09-09  2406  		return rc;
705b8b5588d410 Andrew Jeffery 2020-09-09  2407  
705b8b5588d410 Andrew Jeffery 2020-09-09  2408  	if (!(rc & PB_CAPABILITY_ERROR_CHECK))
705b8b5588d410 Andrew Jeffery 2020-09-09  2409  		return -ENOTSUPP;
705b8b5588d410 Andrew Jeffery 2020-09-09  2410  
705b8b5588d410 Andrew Jeffery 2020-09-09  2411  	client->flags |= I2C_CLIENT_PEC;
705b8b5588d410 Andrew Jeffery 2020-09-09  2412  
705b8b5588d410 Andrew Jeffery 2020-09-09  2413  	return 0;
705b8b5588d410 Andrew Jeffery 2020-09-09  2414  }
705b8b5588d410 Andrew Jeffery 2020-09-09 @2415  DEFINE_DEBUGFS_ATTRIBUTE(pmbus_debugfs_ops_pec, pmbus_debugfs_get_pec,
705b8b5588d410 Andrew Jeffery 2020-09-09  2416  			 pmbus_debugfs_set_pec, "0x%1llu\n");
                                                                                                 ^^^^^^^
Was the 1 intentional?  Anyway, you probably want to remove the 0x so
it doesn't look like hex.

705b8b5588d410 Andrew Jeffery 2020-09-09  2417  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
Guenter Roeck Sept. 10, 2020, 10:34 a.m. UTC | #4
On 9/10/20 3:05 AM, Dan Carpenter wrote:
> Hi Andrew,
> 
> url:    https://github.com/0day-ci/linux/commits/Andrew-Jeffery/hwmon-pmbus-Expose-PEC-debugfs-attribute/20200910-010642
> base:   https://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging.git hwmon-next
> config: x86_64-randconfig-m001-20200909 (attached as .config)
> compiler: gcc-9 (Debian 9.3.0-15) 9.3.0
> 
> If you fix the issue, kindly add following tag as appropriate
> Reported-by: kernel test robot <lkp@intel.com>
> Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
> 
> smatch warnings:
> drivers/hwmon/pmbus/pmbus_core.c:2415 pmbus_debugfs_ops_pec_open() warn: '0x' prefix is confusing together with '%1llu' specifier
> 
> # https://github.com/0day-ci/linux/commit/705b8b5588d4102256d0954086ed16c9bdf9804f
> git remote add linux-review https://github.com/0day-ci/linux
> git fetch --no-tags linux-review Andrew-Jeffery/hwmon-pmbus-Expose-PEC-debugfs-attribute/20200910-010642
> git checkout 705b8b5588d4102256d0954086ed16c9bdf9804f
> vim +2415 drivers/hwmon/pmbus/pmbus_core.c
> 
> 705b8b5588d410 Andrew Jeffery 2020-09-09  2391  static int pmbus_debugfs_set_pec(void *data, u64 val)
> 705b8b5588d410 Andrew Jeffery 2020-09-09  2392  {
> 705b8b5588d410 Andrew Jeffery 2020-09-09  2393  	int rc;
> 705b8b5588d410 Andrew Jeffery 2020-09-09  2394  	struct i2c_client *client = data;
> 705b8b5588d410 Andrew Jeffery 2020-09-09  2395  
> 705b8b5588d410 Andrew Jeffery 2020-09-09  2396  	if (!val) {
> 705b8b5588d410 Andrew Jeffery 2020-09-09  2397  		client->flags &= ~I2C_CLIENT_PEC;
> 705b8b5588d410 Andrew Jeffery 2020-09-09  2398  		return 0;
> 705b8b5588d410 Andrew Jeffery 2020-09-09  2399  	}
> 705b8b5588d410 Andrew Jeffery 2020-09-09  2400  
> 705b8b5588d410 Andrew Jeffery 2020-09-09  2401  	if (val != 1)
> 705b8b5588d410 Andrew Jeffery 2020-09-09  2402  		return -EINVAL;
> 705b8b5588d410 Andrew Jeffery 2020-09-09  2403  
> 705b8b5588d410 Andrew Jeffery 2020-09-09  2404  	rc = i2c_smbus_read_byte_data(client, PMBUS_CAPABILITY);
> 705b8b5588d410 Andrew Jeffery 2020-09-09  2405  	if (rc < 0)
> 705b8b5588d410 Andrew Jeffery 2020-09-09  2406  		return rc;
> 705b8b5588d410 Andrew Jeffery 2020-09-09  2407  
> 705b8b5588d410 Andrew Jeffery 2020-09-09  2408  	if (!(rc & PB_CAPABILITY_ERROR_CHECK))
> 705b8b5588d410 Andrew Jeffery 2020-09-09  2409  		return -ENOTSUPP;
> 705b8b5588d410 Andrew Jeffery 2020-09-09  2410  
> 705b8b5588d410 Andrew Jeffery 2020-09-09  2411  	client->flags |= I2C_CLIENT_PEC;
> 705b8b5588d410 Andrew Jeffery 2020-09-09  2412  
> 705b8b5588d410 Andrew Jeffery 2020-09-09  2413  	return 0;
> 705b8b5588d410 Andrew Jeffery 2020-09-09  2414  }
> 705b8b5588d410 Andrew Jeffery 2020-09-09 @2415  DEFINE_DEBUGFS_ATTRIBUTE(pmbus_debugfs_ops_pec, pmbus_debugfs_get_pec,
> 705b8b5588d410 Andrew Jeffery 2020-09-09  2416  			 pmbus_debugfs_set_pec, "0x%1llu\n");
>                                                                                                  ^^^^^^^
> Was the 1 intentional?  Anyway, you probably want to remove the 0x so
> it doesn't look like hex.
> 

Nice catch; I didn't notice the 1. It is still there in v2, but it does seem quite useless.

Guenter

> 705b8b5588d410 Andrew Jeffery 2020-09-09  2417  
> 
> ---
> 0-DAY CI Kernel Test Service, Intel Corporation
> https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
>
Andrew Jeffery Sept. 10, 2020, 10:51 a.m. UTC | #5
On Thu, 10 Sep 2020, at 20:04, Guenter Roeck wrote:
> On 9/10/20 3:05 AM, Dan Carpenter wrote:
> > Hi Andrew,
> > 
> > url:    https://github.com/0day-ci/linux/commits/Andrew-Jeffery/hwmon-pmbus-Expose-PEC-debugfs-attribute/20200910-010642
> > base:   https://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging.git hwmon-next
> > config: x86_64-randconfig-m001-20200909 (attached as .config)
> > compiler: gcc-9 (Debian 9.3.0-15) 9.3.0
> > 
> > If you fix the issue, kindly add following tag as appropriate
> > Reported-by: kernel test robot <lkp@intel.com>
> > Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
> > 
> > smatch warnings:
> > drivers/hwmon/pmbus/pmbus_core.c:2415 pmbus_debugfs_ops_pec_open() warn: '0x' prefix is confusing together with '%1llu' specifier
> > 
> > # https://github.com/0day-ci/linux/commit/705b8b5588d4102256d0954086ed16c9bdf9804f
> > git remote add linux-review https://github.com/0day-ci/linux
> > git fetch --no-tags linux-review Andrew-Jeffery/hwmon-pmbus-Expose-PEC-debugfs-attribute/20200910-010642
> > git checkout 705b8b5588d4102256d0954086ed16c9bdf9804f
> > vim +2415 drivers/hwmon/pmbus/pmbus_core.c
> > 
> > 705b8b5588d410 Andrew Jeffery 2020-09-09  2391  static int pmbus_debugfs_set_pec(void *data, u64 val)
> > 705b8b5588d410 Andrew Jeffery 2020-09-09  2392  {
> > 705b8b5588d410 Andrew Jeffery 2020-09-09  2393  	int rc;
> > 705b8b5588d410 Andrew Jeffery 2020-09-09  2394  	struct i2c_client *client = data;
> > 705b8b5588d410 Andrew Jeffery 2020-09-09  2395  
> > 705b8b5588d410 Andrew Jeffery 2020-09-09  2396  	if (!val) {
> > 705b8b5588d410 Andrew Jeffery 2020-09-09  2397  		client->flags &= ~I2C_CLIENT_PEC;
> > 705b8b5588d410 Andrew Jeffery 2020-09-09  2398  		return 0;
> > 705b8b5588d410 Andrew Jeffery 2020-09-09  2399  	}
> > 705b8b5588d410 Andrew Jeffery 2020-09-09  2400  
> > 705b8b5588d410 Andrew Jeffery 2020-09-09  2401  	if (val != 1)
> > 705b8b5588d410 Andrew Jeffery 2020-09-09  2402  		return -EINVAL;
> > 705b8b5588d410 Andrew Jeffery 2020-09-09  2403  
> > 705b8b5588d410 Andrew Jeffery 2020-09-09  2404  	rc = i2c_smbus_read_byte_data(client, PMBUS_CAPABILITY);
> > 705b8b5588d410 Andrew Jeffery 2020-09-09  2405  	if (rc < 0)
> > 705b8b5588d410 Andrew Jeffery 2020-09-09  2406  		return rc;
> > 705b8b5588d410 Andrew Jeffery 2020-09-09  2407  
> > 705b8b5588d410 Andrew Jeffery 2020-09-09  2408  	if (!(rc & PB_CAPABILITY_ERROR_CHECK))
> > 705b8b5588d410 Andrew Jeffery 2020-09-09  2409  		return -ENOTSUPP;
> > 705b8b5588d410 Andrew Jeffery 2020-09-09  2410  
> > 705b8b5588d410 Andrew Jeffery 2020-09-09  2411  	client->flags |= I2C_CLIENT_PEC;
> > 705b8b5588d410 Andrew Jeffery 2020-09-09  2412  
> > 705b8b5588d410 Andrew Jeffery 2020-09-09  2413  	return 0;
> > 705b8b5588d410 Andrew Jeffery 2020-09-09  2414  }
> > 705b8b5588d410 Andrew Jeffery 2020-09-09 @2415  DEFINE_DEBUGFS_ATTRIBUTE(pmbus_debugfs_ops_pec, pmbus_debugfs_get_pec,
> > 705b8b5588d410 Andrew Jeffery 2020-09-09  2416  			 pmbus_debugfs_set_pec, "0x%1llu\n");
> >                                                                                                  ^^^^^^^
> > Was the 1 intentional?  Anyway, you probably want to remove the 0x so
> > it doesn't look like hex.
> > 
> 
> Nice catch; I didn't notice the 1. It is still there in v2, but it does 
> seem quite useless.

Do you want to just rebase it out, or would you like me to send
a patch removing the stray 1 from v2?

Andrew
Guenter Roeck Sept. 10, 2020, 1:32 p.m. UTC | #6
On 9/10/20 3:51 AM, Andrew Jeffery wrote:
> 
> 
> On Thu, 10 Sep 2020, at 20:04, Guenter Roeck wrote:
>> On 9/10/20 3:05 AM, Dan Carpenter wrote:
>>> Hi Andrew,
>>>
>>> url:    https://github.com/0day-ci/linux/commits/Andrew-Jeffery/hwmon-pmbus-Expose-PEC-debugfs-attribute/20200910-010642
>>> base:   https://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging.git hwmon-next
>>> config: x86_64-randconfig-m001-20200909 (attached as .config)
>>> compiler: gcc-9 (Debian 9.3.0-15) 9.3.0
>>>
>>> If you fix the issue, kindly add following tag as appropriate
>>> Reported-by: kernel test robot <lkp@intel.com>
>>> Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
>>>
>>> smatch warnings:
>>> drivers/hwmon/pmbus/pmbus_core.c:2415 pmbus_debugfs_ops_pec_open() warn: '0x' prefix is confusing together with '%1llu' specifier
>>>
>>> # https://github.com/0day-ci/linux/commit/705b8b5588d4102256d0954086ed16c9bdf9804f
>>> git remote add linux-review https://github.com/0day-ci/linux
>>> git fetch --no-tags linux-review Andrew-Jeffery/hwmon-pmbus-Expose-PEC-debugfs-attribute/20200910-010642
>>> git checkout 705b8b5588d4102256d0954086ed16c9bdf9804f
>>> vim +2415 drivers/hwmon/pmbus/pmbus_core.c
>>>
>>> 705b8b5588d410 Andrew Jeffery 2020-09-09  2391  static int pmbus_debugfs_set_pec(void *data, u64 val)
>>> 705b8b5588d410 Andrew Jeffery 2020-09-09  2392  {
>>> 705b8b5588d410 Andrew Jeffery 2020-09-09  2393  	int rc;
>>> 705b8b5588d410 Andrew Jeffery 2020-09-09  2394  	struct i2c_client *client = data;
>>> 705b8b5588d410 Andrew Jeffery 2020-09-09  2395  
>>> 705b8b5588d410 Andrew Jeffery 2020-09-09  2396  	if (!val) {
>>> 705b8b5588d410 Andrew Jeffery 2020-09-09  2397  		client->flags &= ~I2C_CLIENT_PEC;
>>> 705b8b5588d410 Andrew Jeffery 2020-09-09  2398  		return 0;
>>> 705b8b5588d410 Andrew Jeffery 2020-09-09  2399  	}
>>> 705b8b5588d410 Andrew Jeffery 2020-09-09  2400  
>>> 705b8b5588d410 Andrew Jeffery 2020-09-09  2401  	if (val != 1)
>>> 705b8b5588d410 Andrew Jeffery 2020-09-09  2402  		return -EINVAL;
>>> 705b8b5588d410 Andrew Jeffery 2020-09-09  2403  
>>> 705b8b5588d410 Andrew Jeffery 2020-09-09  2404  	rc = i2c_smbus_read_byte_data(client, PMBUS_CAPABILITY);
>>> 705b8b5588d410 Andrew Jeffery 2020-09-09  2405  	if (rc < 0)
>>> 705b8b5588d410 Andrew Jeffery 2020-09-09  2406  		return rc;
>>> 705b8b5588d410 Andrew Jeffery 2020-09-09  2407  
>>> 705b8b5588d410 Andrew Jeffery 2020-09-09  2408  	if (!(rc & PB_CAPABILITY_ERROR_CHECK))
>>> 705b8b5588d410 Andrew Jeffery 2020-09-09  2409  		return -ENOTSUPP;
>>> 705b8b5588d410 Andrew Jeffery 2020-09-09  2410  
>>> 705b8b5588d410 Andrew Jeffery 2020-09-09  2411  	client->flags |= I2C_CLIENT_PEC;
>>> 705b8b5588d410 Andrew Jeffery 2020-09-09  2412  
>>> 705b8b5588d410 Andrew Jeffery 2020-09-09  2413  	return 0;
>>> 705b8b5588d410 Andrew Jeffery 2020-09-09  2414  }
>>> 705b8b5588d410 Andrew Jeffery 2020-09-09 @2415  DEFINE_DEBUGFS_ATTRIBUTE(pmbus_debugfs_ops_pec, pmbus_debugfs_get_pec,
>>> 705b8b5588d410 Andrew Jeffery 2020-09-09  2416  			 pmbus_debugfs_set_pec, "0x%1llu\n");
>>>                                                                                                  ^^^^^^^
>>> Was the 1 intentional?  Anyway, you probably want to remove the 0x so
>>> it doesn't look like hex.
>>>
>>
>> Nice catch; I didn't notice the 1. It is still there in v2, but it does 
>> seem quite useless.
> 
> Do you want to just rebase it out, or would you like me to send
> a patch removing the stray 1 from v2?
> 

I'll rebase it.

Thanks,
Guenter
diff mbox series

Patch

diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
index 44535add3a4a..51c8502b35e9 100644
--- a/drivers/hwmon/pmbus/pmbus_core.c
+++ b/drivers/hwmon/pmbus/pmbus_core.c
@@ -2346,6 +2346,42 @@  static int pmbus_debugfs_get_status(void *data, u64 *val)
 DEFINE_DEBUGFS_ATTRIBUTE(pmbus_debugfs_ops_status, pmbus_debugfs_get_status,
 			 NULL, "0x%04llx\n");
 
+static int pmbus_debugfs_get_pec(void *data, u64 *val)
+{
+	struct i2c_client *client = data;
+
+	*val = !!(client->flags & I2C_CLIENT_PEC);
+
+	return 0;
+}
+
+static int pmbus_debugfs_set_pec(void *data, u64 val)
+{
+	int rc;
+	struct i2c_client *client = data;
+
+	if (!val) {
+		client->flags &= ~I2C_CLIENT_PEC;
+		return 0;
+	}
+
+	if (val != 1)
+		return -EINVAL;
+
+	rc = i2c_smbus_read_byte_data(client, PMBUS_CAPABILITY);
+	if (rc < 0)
+		return rc;
+
+	if (!(rc & PB_CAPABILITY_ERROR_CHECK))
+		return -ENOTSUPP;
+
+	client->flags |= I2C_CLIENT_PEC;
+
+	return 0;
+}
+DEFINE_DEBUGFS_ATTRIBUTE(pmbus_debugfs_ops_pec, pmbus_debugfs_get_pec,
+			 pmbus_debugfs_set_pec, "0x%1llu\n");
+
 static int pmbus_init_debugfs(struct i2c_client *client,
 			      struct pmbus_data *data)
 {
@@ -2374,6 +2410,9 @@  static int pmbus_init_debugfs(struct i2c_client *client,
 	if (!entries)
 		return -ENOMEM;
 
+	debugfs_create_file("pec", 0664, data->debugfs, client,
+			    &pmbus_debugfs_ops_pec);
+
 	for (i = 0; i < data->info->pages; ++i) {
 		/* Check accessibility of status register if it's not page 0 */
 		if (!i || pmbus_check_status_register(client, i)) {