All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] hwmon: (ucd9000) Add sysfs interface to clear logged faults
@ 2017-08-30 18:55 Christopher Bostic
  2017-08-30 18:55 ` [PATCH 1/2] hwmon: (ucd9000) Add support for clearing logged faults via sysfs Christopher Bostic
  2017-08-30 18:55 ` [PATCH 2/2] hwmon: (ucd9000) Add sysfs attribute to clear logged faults Christopher Bostic
  0 siblings, 2 replies; 4+ messages in thread
From: Christopher Bostic @ 2017-08-30 18:55 UTC (permalink / raw)
  To: jdelvare, linux, corbet, linux-hwmon, linux-doc, linux-kernel
  Cc: Christopher Bostic, openbmc

This set covers changes required to allow user space to clear logged faults
on ucd9000 type devices via sysfs.   A write to this new file with any value
will perform the clear operation.

Patch 1: Document new sysfs file.
Patch 2: Implementation of new file and clear process.

Christopher Bostic (2):
  hwmon: (ucd9000) Add support for clearing logged faults via sysfs
  hwmon: (ucd9000) Add sysfs attribute to clear logged faults

 Documentation/hwmon/ucd9000   |  2 ++
 drivers/hwmon/pmbus/ucd9000.c | 45 ++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 46 insertions(+), 1 deletion(-)

-- 
1.8.2.2


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

* [PATCH 1/2] hwmon: (ucd9000) Add support for clearing logged faults via sysfs
  2017-08-30 18:55 [PATCH 0/2] hwmon: (ucd9000) Add sysfs interface to clear logged faults Christopher Bostic
@ 2017-08-30 18:55 ` Christopher Bostic
  2017-08-30 18:55 ` [PATCH 2/2] hwmon: (ucd9000) Add sysfs attribute to clear logged faults Christopher Bostic
  1 sibling, 0 replies; 4+ messages in thread
From: Christopher Bostic @ 2017-08-30 18:55 UTC (permalink / raw)
  To: jdelvare, linux, corbet, linux-hwmon, linux-doc, linux-kernel
  Cc: Christopher Bostic, openbmc

Create an attribute to allow clearing of logged faults.

Signed-off-by: Christopher Bostic <cbostic@linux.vnet.ibm.com>
---
 Documentation/hwmon/ucd9000 | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/Documentation/hwmon/ucd9000 b/Documentation/hwmon/ucd9000
index 262e713..de7f7f23 100644
--- a/Documentation/hwmon/ucd9000
+++ b/Documentation/hwmon/ucd9000
@@ -116,3 +116,5 @@ fan[1-4]_fault		Fan fault.
 			created only for enabled fans.
 			Note that even though UCD90910 supports up to 10 fans,
 			only up to four fans are currently supported.
+
+clear_logged_faults	Write only.  Echo any value to clear logged faults.
-- 
1.8.2.2


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

* [PATCH 2/2] hwmon: (ucd9000) Add sysfs attribute to clear logged faults
  2017-08-30 18:55 [PATCH 0/2] hwmon: (ucd9000) Add sysfs interface to clear logged faults Christopher Bostic
  2017-08-30 18:55 ` [PATCH 1/2] hwmon: (ucd9000) Add support for clearing logged faults via sysfs Christopher Bostic
@ 2017-08-30 18:55 ` Christopher Bostic
  2017-08-31  4:11   ` Guenter Roeck
  1 sibling, 1 reply; 4+ messages in thread
From: Christopher Bostic @ 2017-08-30 18:55 UTC (permalink / raw)
  To: jdelvare, linux, corbet, linux-hwmon, linux-doc, linux-kernel
  Cc: Christopher Bostic, openbmc

Add ability to clear logged faults via sysfs.

Signed-off-by: Christopher Bostic <cbostic@linux.vnet.ibm.com>
---
 drivers/hwmon/pmbus/ucd9000.c | 45 ++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 44 insertions(+), 1 deletion(-)

diff --git a/drivers/hwmon/pmbus/ucd9000.c b/drivers/hwmon/pmbus/ucd9000.c
index b74dbec..8bd8cb1 100644
--- a/drivers/hwmon/pmbus/ucd9000.c
+++ b/drivers/hwmon/pmbus/ucd9000.c
@@ -27,6 +27,8 @@
 #include <linux/slab.h>
 #include <linux/i2c.h>
 #include <linux/pmbus.h>
+#include <linux/sysfs.h>
+#include <linux/hwmon-sysfs.h>
 #include "pmbus.h"
 
 enum chips { ucd9000, ucd90120, ucd90124, ucd90160, ucd9090, ucd90910 };
@@ -35,6 +37,7 @@
 #define UCD9000_NUM_PAGES		0xd6
 #define UCD9000_FAN_CONFIG_INDEX	0xe7
 #define UCD9000_FAN_CONFIG		0xe8
+#define UCD9000_LOGGED_FAULTS		0xea
 #define UCD9000_DEVICE_ID		0xfd
 
 #define UCD9000_MON_TYPE(x)	(((x) >> 5) & 0x07)
@@ -109,6 +112,36 @@ static int ucd9000_read_byte_data(struct i2c_client *client, int page, int reg)
 	return ret;
 }
 
+static ssize_t ucd9000_clear_logged_faults(struct device *dev,
+			struct device_attribute *attr, const char *buf,
+			size_t count)
+{
+	struct i2c_client *client = to_i2c_client(dev);
+	int ret;
+
+	/* No page set required */
+	ret = i2c_smbus_write_byte_data(client, UCD9000_LOGGED_FAULTS, 0);
+	if (ret) {
+		dev_err(&client->dev, "Failed to clear logged faults: %d\n",
+			ret);
+		return ret;
+	}
+
+	return count;
+}
+
+static DEVICE_ATTR(clear_logged_faults, 0200, NULL,
+			ucd9000_clear_logged_faults);
+
+static struct attribute *ucd9000_attributes[] = {
+	&dev_attr_clear_logged_faults.attr,
+	NULL
+};
+
+static const struct attribute_group ucd9000_attr_group = {
+	.attrs = ucd9000_attributes,
+};
+
 static const struct i2c_device_id ucd9000_id[] = {
 	{"ucd9000", ucd9000},
 	{"ucd90120", ucd90120},
@@ -263,9 +296,19 @@ static int ucd9000_probe(struct i2c_client *client,
 		  | PMBUS_HAVE_FAN34 | PMBUS_HAVE_STATUS_FAN34;
 	}
 
+	ret = sysfs_create_group(&client->dev.kobj, &ucd9000_attr_group);
+	if (ret < 0)
+		return ret;
+
 	return pmbus_do_probe(client, mid, info);
 }
 
+static int ucd9000_remove(struct i2c_client *client)
+{
+	sysfs_remove_group(&client->dev.kobj, &ucd9000_attr_group);
+	return pmbus_do_remove(client);
+}
+
 /* This is the driver that will be inserted */
 static struct i2c_driver ucd9000_driver = {
 	.driver = {
@@ -273,7 +316,7 @@ static int ucd9000_probe(struct i2c_client *client,
 		.of_match_table = of_match_ptr(ucd9000_of_match),
 	},
 	.probe = ucd9000_probe,
-	.remove = pmbus_do_remove,
+	.remove = ucd9000_remove,
 	.id_table = ucd9000_id,
 };
 
-- 
1.8.2.2


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

* Re: [PATCH 2/2] hwmon: (ucd9000) Add sysfs attribute to clear logged faults
  2017-08-30 18:55 ` [PATCH 2/2] hwmon: (ucd9000) Add sysfs attribute to clear logged faults Christopher Bostic
@ 2017-08-31  4:11   ` Guenter Roeck
  0 siblings, 0 replies; 4+ messages in thread
From: Guenter Roeck @ 2017-08-31  4:11 UTC (permalink / raw)
  To: Christopher Bostic
  Cc: jdelvare, corbet, linux-hwmon, linux-doc, linux-kernel, openbmc

On Wed, Aug 30, 2017 at 01:55:36PM -0500, Christopher Bostic wrote:
> Add ability to clear logged faults via sysfs.
> 
I am not in favor of such chip specific commands, in this case for several
reasons (besides it being a non-standard attribute).

The logged faults are not read or used by the driver in the first place.
Clearing them doesn't add any benefit for the driver.

The command as written only clears non-paged logged faults, but no paged
faults.

While PMBus "lingo" talks of faults, those are really often just status bits,
not "faults" from hwmon perspective.

The content of the various fault bits and bites is highly chip specific.
On top of that, each chip supported by the driver has different fault bits
and bytes.

To read the logged faults you have to access the chip directly, not through
the driver. I don't see the benefit of providing a sysfs attribute to clear
non-paged logged faults, but not doing anything else with it.

If you want to do something special with those faults (or status bits/nytes),
it might be more appropriate to create debugfs entries.

Thanks,
Guenter

> Signed-off-by: Christopher Bostic <cbostic@linux.vnet.ibm.com>
> ---
>  drivers/hwmon/pmbus/ucd9000.c | 45 ++++++++++++++++++++++++++++++++++++++++++-
>  1 file changed, 44 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/hwmon/pmbus/ucd9000.c b/drivers/hwmon/pmbus/ucd9000.c
> index b74dbec..8bd8cb1 100644
> --- a/drivers/hwmon/pmbus/ucd9000.c
> +++ b/drivers/hwmon/pmbus/ucd9000.c
> @@ -27,6 +27,8 @@
>  #include <linux/slab.h>
>  #include <linux/i2c.h>
>  #include <linux/pmbus.h>
> +#include <linux/sysfs.h>
> +#include <linux/hwmon-sysfs.h>
>  #include "pmbus.h"
>  
>  enum chips { ucd9000, ucd90120, ucd90124, ucd90160, ucd9090, ucd90910 };
> @@ -35,6 +37,7 @@
>  #define UCD9000_NUM_PAGES		0xd6
>  #define UCD9000_FAN_CONFIG_INDEX	0xe7
>  #define UCD9000_FAN_CONFIG		0xe8
> +#define UCD9000_LOGGED_FAULTS		0xea
>  #define UCD9000_DEVICE_ID		0xfd
>  
>  #define UCD9000_MON_TYPE(x)	(((x) >> 5) & 0x07)
> @@ -109,6 +112,36 @@ static int ucd9000_read_byte_data(struct i2c_client *client, int page, int reg)
>  	return ret;
>  }
>  
> +static ssize_t ucd9000_clear_logged_faults(struct device *dev,
> +			struct device_attribute *attr, const char *buf,
> +			size_t count)
> +{
> +	struct i2c_client *client = to_i2c_client(dev);
> +	int ret;
> +
> +	/* No page set required */
> +	ret = i2c_smbus_write_byte_data(client, UCD9000_LOGGED_FAULTS, 0);
> +	if (ret) {
> +		dev_err(&client->dev, "Failed to clear logged faults: %d\n",
> +			ret);
> +		return ret;
> +	}
> +
> +	return count;
> +}
> +
> +static DEVICE_ATTR(clear_logged_faults, 0200, NULL,
> +			ucd9000_clear_logged_faults);
> +
> +static struct attribute *ucd9000_attributes[] = {
> +	&dev_attr_clear_logged_faults.attr,
> +	NULL
> +};
> +
> +static const struct attribute_group ucd9000_attr_group = {
> +	.attrs = ucd9000_attributes,
> +};
> +
>  static const struct i2c_device_id ucd9000_id[] = {
>  	{"ucd9000", ucd9000},
>  	{"ucd90120", ucd90120},
> @@ -263,9 +296,19 @@ static int ucd9000_probe(struct i2c_client *client,
>  		  | PMBUS_HAVE_FAN34 | PMBUS_HAVE_STATUS_FAN34;
>  	}
>  
> +	ret = sysfs_create_group(&client->dev.kobj, &ucd9000_attr_group);
> +	if (ret < 0)
> +		return ret;
> +
>  	return pmbus_do_probe(client, mid, info);
>  }
>  
> +static int ucd9000_remove(struct i2c_client *client)
> +{
> +	sysfs_remove_group(&client->dev.kobj, &ucd9000_attr_group);
> +	return pmbus_do_remove(client);
> +}
> +
>  /* This is the driver that will be inserted */
>  static struct i2c_driver ucd9000_driver = {
>  	.driver = {
> @@ -273,7 +316,7 @@ static int ucd9000_probe(struct i2c_client *client,
>  		.of_match_table = of_match_ptr(ucd9000_of_match),
>  	},
>  	.probe = ucd9000_probe,
> -	.remove = pmbus_do_remove,
> +	.remove = ucd9000_remove,
>  	.id_table = ucd9000_id,
>  };
>  
> -- 
> 1.8.2.2
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-hwmon" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

end of thread, other threads:[~2017-08-31  4:11 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-08-30 18:55 [PATCH 0/2] hwmon: (ucd9000) Add sysfs interface to clear logged faults Christopher Bostic
2017-08-30 18:55 ` [PATCH 1/2] hwmon: (ucd9000) Add support for clearing logged faults via sysfs Christopher Bostic
2017-08-30 18:55 ` [PATCH 2/2] hwmon: (ucd9000) Add sysfs attribute to clear logged faults Christopher Bostic
2017-08-31  4:11   ` Guenter Roeck

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.