[PATCH linux dev-4.10 v6 1/3] hwmon: (ucd9000) Add interface to clear logged faults.

Matt Spinler mspinler at linux.vnet.ibm.com
Fri Sep 1 02:11:22 AEST 2017


Tested-by: Matt Spinler mspinler at linux.vnet.ibm.com


On 8/30/2017 4:49 PM, Christopher Bostic wrote:
> Provide a means for user space to clear out any logged faults
> on these types of devices.  Ability to do so allows user to
> start with a clean slate at system poweron which can be done
> multiple times after this driver loads.
>
> Signed-off-by: Christopher Bostic <cbostic at linux.vnet.ibm.com>
> ---
>   drivers/hwmon/pmbus/ucd9000.c | 49 ++++++++++++++++++++++++++++++++++++++++++-
>   1 file changed, 48 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/hwmon/pmbus/ucd9000.c b/drivers/hwmon/pmbus/ucd9000.c
> index 3e3aa95..c401e5b 100644
> --- a/drivers/hwmon/pmbus/ucd9000.c
> +++ b/drivers/hwmon/pmbus/ucd9000.c
> @@ -26,6 +26,8 @@
>   #include <linux/slab.h>
>   #include <linux/i2c.h>
>   #include <linux/i2c/pmbus.h>
> +#include <linux/sysfs.h>
> +#include <linux/hwmon-sysfs.h>
>   #include "pmbus.h"
>
>   enum chips { ucd9000, ucd90120, ucd90124, ucd90160, ucd9090, ucd90910 };
> @@ -34,6 +36,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)
> @@ -119,6 +122,37 @@ static int ucd9000_read_byte_data(struct i2c_client *client, int page, int reg)
>   };
>   MODULE_DEVICE_TABLE(i2c, ucd9000_id);
>
> +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 int ucd9000_probe(struct i2c_client *client,
>   			 const struct i2c_device_id *id)
>   {
> @@ -227,16 +261,29 @@ 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) {
> +		dev_warn(&client->dev, "Failed to add sysfs files: %d\n", ret);
> +
> +		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 = {
>   		.name = "ucd9000",
>   	},
>   	.probe = ucd9000_probe,
> -	.remove = pmbus_do_remove,
> +	.remove = ucd9000_remove,
>   	.id_table = ucd9000_id,
>   };
>



More information about the openbmc mailing list