Re: [PATCH v2 4/4] hwmon: (pmbus): Add debugfs for status registers
On 08/11/2017 08:52 AM, Guenter Roeck wrote: On 08/10/2017 02:57 PM, Eddie James wrote: From: "Edward A. James" Export all the available status registers through debugfs, if the client driver wants them. Signed-off-by: Edward A. James --- drivers/hwmon/pmbus/pmbus.h | 6 ++ drivers/hwmon/pmbus/pmbus_core.c | 201 +++ 2 files changed, 207 insertions(+) diff --git a/drivers/hwmon/pmbus/pmbus.h b/drivers/hwmon/pmbus/pmbus.h index bfcb13b..5f91a19 100644 --- a/drivers/hwmon/pmbus/pmbus.h +++ b/drivers/hwmon/pmbus/pmbus.h @@ -383,6 +383,12 @@ struct pmbus_driver_info { /* Regulator functionality, if supported by this chip driver. */ int num_regulators; const struct regulator_desc *reg_desc; + +/* + * Controls whether or not to create debugfs entries for this driver's + * devices. + */ +bool debugfs; }; /* Regulator ops */ diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c index ef135d8..b11ebec 100644 --- a/drivers/hwmon/pmbus/pmbus_core.c +++ b/drivers/hwmon/pmbus/pmbus_core.c @@ -19,6 +19,7 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +#include #include #include #include @@ -101,6 +102,7 @@ struct pmbus_data { int num_attributes; struct attribute_group group; const struct attribute_group *groups[2]; +struct dentry *debugfs;/* debugfs device directory */ struct pmbus_sensor *sensors; @@ -120,6 +122,12 @@ struct pmbus_data { u8 currpage; }; +struct pmbus_debugfs_entry { +struct i2c_client *client; +u8 page; +u8 reg; +}; + void pmbus_clear_cache(struct i2c_client *client) { struct pmbus_data *data = i2c_get_clientdata(client); @@ -1893,6 +1901,184 @@ static int pmbus_regulator_register(struct pmbus_data *data) } #endif +static struct dentry *pmbus_debugfs_dir;/* pmbus debugfs directory */ + +#if IS_ENABLED(CONFIG_DEBUG_FS) +static int pmbus_debugfs_get(void *data, u64 *val) +{ +struct pmbus_debugfs_entry *entry = data; + +*val = _pmbus_read_byte_data(entry->client, entry->page, entry->reg); + +return 0; +} +DEFINE_DEBUGFS_ATTRIBUTE(pmbus_debugfs_ops, pmbus_debugfs_get, NULL, + "0x%02llx\n"); + +static int pmbus_debugfs_get_status(void *data, u64 *val) +{ +struct pmbus_debugfs_entry *entry = data; +struct pmbus_data *pdata = i2c_get_clientdata(entry->client); + +*val = pdata->read_status(entry->client, entry->page); + +return 0; +} +DEFINE_DEBUGFS_ATTRIBUTE(pmbus_debugfs_ops_status, pmbus_debugfs_get_status, + NULL, "0x%04llx\n"); + +static int pmbus_init_debugfs(struct i2c_client *client, + struct pmbus_data *data) +{ +int i, idx = 0; +char name[PMBUS_NAME_SIZE]; +struct pmbus_debugfs_entry *entries; + +/* Check if client driver requested debugfs support. */ +if (!data->info->debugfs) +return 0; + Let's just make this unconditional and drop the flag. I don't see the value in enabling it per driver. The code is there anyway, might as well support it. +/* Create the root pmbus debugfs directory if it's not created yet. */ +if (!pmbus_debugfs_dir) { +pmbus_debugfs_dir = debugfs_create_dir("pmbus", NULL); +if (IS_ERR_OR_NULL(pmbus_debugfs_dir)) { +pmbus_debugfs_dir = NULL; +return -ENODEV; +} +} + +/* + * Create the debugfs directory for this device. Use the hwmon device + * name to avoid conflicts (hwmon numbers are globally unique). + */ +data->debugfs = debugfs_create_dir(dev_name(data->hwmon_dev), + pmbus_debugfs_dir); +if (IS_ERR_OR_NULL(data->debugfs)) { +data->debugfs = NULL; +return -ENODEV; +} + +/* Allocate the max possible entries we need. */ +entries = devm_kzalloc(data->dev, + sizeof(*entries) * (data->info->pages * 10), + GFP_KERNEL); +if (!entries) +return -ENOMEM; + +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)) { +/* No need to set reg as we have special read op. */ +entries[idx].client = client; +entries[idx].page = i; +snprintf(name, PMBUS_NAME_SIZE, "status%d", i); scnprintf might be better. +debugfs_create_file(name, 0444, data->debugfs, +&entries[idx++], +&pmbus_debugfs_ops_status); +} + +if (data->info->func[i] & PMBUS_HAVE_STATUS_VOUT) { +entries[idx].client = client; +entries[idx].page = i; +entries[idx].reg = PMBUS_STATUS_VOUT; +snprintf(name, PMBUS_NAME_SIZE, "status%d_vout", i); +debugfs_create_file(name, 0444, data->debugfs, +
Re: [PATCH v2 4/4] hwmon: (pmbus): Add debugfs for status registers
On 08/10/2017 02:57 PM, Eddie James wrote: From: "Edward A. James" Export all the available status registers through debugfs, if the client driver wants them. Signed-off-by: Edward A. James --- drivers/hwmon/pmbus/pmbus.h | 6 ++ drivers/hwmon/pmbus/pmbus_core.c | 201 +++ 2 files changed, 207 insertions(+) diff --git a/drivers/hwmon/pmbus/pmbus.h b/drivers/hwmon/pmbus/pmbus.h index bfcb13b..5f91a19 100644 --- a/drivers/hwmon/pmbus/pmbus.h +++ b/drivers/hwmon/pmbus/pmbus.h @@ -383,6 +383,12 @@ struct pmbus_driver_info { /* Regulator functionality, if supported by this chip driver. */ int num_regulators; const struct regulator_desc *reg_desc; + + /* +* Controls whether or not to create debugfs entries for this driver's +* devices. +*/ + bool debugfs; }; /* Regulator ops */ diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c index ef135d8..b11ebec 100644 --- a/drivers/hwmon/pmbus/pmbus_core.c +++ b/drivers/hwmon/pmbus/pmbus_core.c @@ -19,6 +19,7 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +#include #include #include #include @@ -101,6 +102,7 @@ struct pmbus_data { int num_attributes; struct attribute_group group; const struct attribute_group *groups[2]; + struct dentry *debugfs; /* debugfs device directory */ struct pmbus_sensor *sensors; @@ -120,6 +122,12 @@ struct pmbus_data { u8 currpage; }; +struct pmbus_debugfs_entry { + struct i2c_client *client; + u8 page; + u8 reg; +}; + void pmbus_clear_cache(struct i2c_client *client) { struct pmbus_data *data = i2c_get_clientdata(client); @@ -1893,6 +1901,184 @@ static int pmbus_regulator_register(struct pmbus_data *data) } #endif +static struct dentry *pmbus_debugfs_dir; /* pmbus debugfs directory */ + +#if IS_ENABLED(CONFIG_DEBUG_FS) +static int pmbus_debugfs_get(void *data, u64 *val) +{ + struct pmbus_debugfs_entry *entry = data; + + *val = _pmbus_read_byte_data(entry->client, entry->page, entry->reg); + + return 0; +} +DEFINE_DEBUGFS_ATTRIBUTE(pmbus_debugfs_ops, pmbus_debugfs_get, NULL, +"0x%02llx\n"); + +static int pmbus_debugfs_get_status(void *data, u64 *val) +{ + struct pmbus_debugfs_entry *entry = data; + struct pmbus_data *pdata = i2c_get_clientdata(entry->client); + + *val = pdata->read_status(entry->client, entry->page); + + return 0; +} +DEFINE_DEBUGFS_ATTRIBUTE(pmbus_debugfs_ops_status, pmbus_debugfs_get_status, +NULL, "0x%04llx\n"); + +static int pmbus_init_debugfs(struct i2c_client *client, + struct pmbus_data *data) +{ + int i, idx = 0; + char name[PMBUS_NAME_SIZE]; + struct pmbus_debugfs_entry *entries; + + /* Check if client driver requested debugfs support. */ + if (!data->info->debugfs) + return 0; + Let's just make this unconditional and drop the flag. I don't see the value in enabling it per driver. The code is there anyway, might as well support it. + /* Create the root pmbus debugfs directory if it's not created yet. */ + if (!pmbus_debugfs_dir) { + pmbus_debugfs_dir = debugfs_create_dir("pmbus", NULL); + if (IS_ERR_OR_NULL(pmbus_debugfs_dir)) { + pmbus_debugfs_dir = NULL; + return -ENODEV; + } + } + + /* +* Create the debugfs directory for this device. Use the hwmon device +* name to avoid conflicts (hwmon numbers are globally unique). +*/ + data->debugfs = debugfs_create_dir(dev_name(data->hwmon_dev), + pmbus_debugfs_dir); + if (IS_ERR_OR_NULL(data->debugfs)) { + data->debugfs = NULL; + return -ENODEV; + } + + /* Allocate the max possible entries we need. */ + entries = devm_kzalloc(data->dev, + sizeof(*entries) * (data->info->pages * 10), + GFP_KERNEL); + if (!entries) + return -ENOMEM; + + 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)) { + /* No need to set reg as we have special read op. */ + entries[idx].client = client; + entries[idx].page = i; + snprintf(name, PMBUS_NAME_SIZE, "status%d", i); scnprintf might be better. + debugfs_create_file(name, 0444, data->debugfs, + &entries[idx++], + &pmbus_debugfs_ops_status); + } + +
[PATCH v2 4/4] hwmon: (pmbus): Add debugfs for status registers
From: "Edward A. James" Export all the available status registers through debugfs, if the client driver wants them. Signed-off-by: Edward A. James --- drivers/hwmon/pmbus/pmbus.h | 6 ++ drivers/hwmon/pmbus/pmbus_core.c | 201 +++ 2 files changed, 207 insertions(+) diff --git a/drivers/hwmon/pmbus/pmbus.h b/drivers/hwmon/pmbus/pmbus.h index bfcb13b..5f91a19 100644 --- a/drivers/hwmon/pmbus/pmbus.h +++ b/drivers/hwmon/pmbus/pmbus.h @@ -383,6 +383,12 @@ struct pmbus_driver_info { /* Regulator functionality, if supported by this chip driver. */ int num_regulators; const struct regulator_desc *reg_desc; + + /* +* Controls whether or not to create debugfs entries for this driver's +* devices. +*/ + bool debugfs; }; /* Regulator ops */ diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c index ef135d8..b11ebec 100644 --- a/drivers/hwmon/pmbus/pmbus_core.c +++ b/drivers/hwmon/pmbus/pmbus_core.c @@ -19,6 +19,7 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +#include #include #include #include @@ -101,6 +102,7 @@ struct pmbus_data { int num_attributes; struct attribute_group group; const struct attribute_group *groups[2]; + struct dentry *debugfs; /* debugfs device directory */ struct pmbus_sensor *sensors; @@ -120,6 +122,12 @@ struct pmbus_data { u8 currpage; }; +struct pmbus_debugfs_entry { + struct i2c_client *client; + u8 page; + u8 reg; +}; + void pmbus_clear_cache(struct i2c_client *client) { struct pmbus_data *data = i2c_get_clientdata(client); @@ -1893,6 +1901,184 @@ static int pmbus_regulator_register(struct pmbus_data *data) } #endif +static struct dentry *pmbus_debugfs_dir; /* pmbus debugfs directory */ + +#if IS_ENABLED(CONFIG_DEBUG_FS) +static int pmbus_debugfs_get(void *data, u64 *val) +{ + struct pmbus_debugfs_entry *entry = data; + + *val = _pmbus_read_byte_data(entry->client, entry->page, entry->reg); + + return 0; +} +DEFINE_DEBUGFS_ATTRIBUTE(pmbus_debugfs_ops, pmbus_debugfs_get, NULL, +"0x%02llx\n"); + +static int pmbus_debugfs_get_status(void *data, u64 *val) +{ + struct pmbus_debugfs_entry *entry = data; + struct pmbus_data *pdata = i2c_get_clientdata(entry->client); + + *val = pdata->read_status(entry->client, entry->page); + + return 0; +} +DEFINE_DEBUGFS_ATTRIBUTE(pmbus_debugfs_ops_status, pmbus_debugfs_get_status, +NULL, "0x%04llx\n"); + +static int pmbus_init_debugfs(struct i2c_client *client, + struct pmbus_data *data) +{ + int i, idx = 0; + char name[PMBUS_NAME_SIZE]; + struct pmbus_debugfs_entry *entries; + + /* Check if client driver requested debugfs support. */ + if (!data->info->debugfs) + return 0; + + /* Create the root pmbus debugfs directory if it's not created yet. */ + if (!pmbus_debugfs_dir) { + pmbus_debugfs_dir = debugfs_create_dir("pmbus", NULL); + if (IS_ERR_OR_NULL(pmbus_debugfs_dir)) { + pmbus_debugfs_dir = NULL; + return -ENODEV; + } + } + + /* +* Create the debugfs directory for this device. Use the hwmon device +* name to avoid conflicts (hwmon numbers are globally unique). +*/ + data->debugfs = debugfs_create_dir(dev_name(data->hwmon_dev), + pmbus_debugfs_dir); + if (IS_ERR_OR_NULL(data->debugfs)) { + data->debugfs = NULL; + return -ENODEV; + } + + /* Allocate the max possible entries we need. */ + entries = devm_kzalloc(data->dev, + sizeof(*entries) * (data->info->pages * 10), + GFP_KERNEL); + if (!entries) + return -ENOMEM; + + 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)) { + /* No need to set reg as we have special read op. */ + entries[idx].client = client; + entries[idx].page = i; + snprintf(name, PMBUS_NAME_SIZE, "status%d", i); + debugfs_create_file(name, 0444, data->debugfs, + &entries[idx++], + &pmbus_debugfs_ops_status); + } + + if (data->info->func[i] & PMBUS_HAVE_STATUS_VOUT) { + entries[idx].client = client; + entries[idx].page = i; + entries[idx].reg = PMBUS_STATUS_VOUT; +