Skip to content

Commit

Permalink
pmbus: support for custom sysfs attributes
Browse files Browse the repository at this point in the history
This patch makes it possible to pass custom struct attribute_group array
via the pmbus_driver_info struct so that those can be added to the
attribute groups passed to hwmon_device_register_with_groups().

This makes it possible to register custom sysfs attributes by PMBUS
drivers similar to how you can do this with most other busses/classes.

Signed-off-by: Krzysztof Adamski <krzysztof.adamski@nokia.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
  • Loading branch information
krzysztof.adamski@nokia.com authored and Guenter Roeck committed Apr 16, 2019
1 parent 9f00995 commit 991d679
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
3 changes: 3 additions & 0 deletions drivers/hwmon/pmbus/pmbus.h
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,9 @@ struct pmbus_driver_info {
/* Regulator functionality, if supported by this chip driver. */
int num_regulators;
const struct regulator_desc *reg_desc;

/* custom attributes */
const struct attribute_group **groups;
};

/* Regulator ops */
Expand Down
13 changes: 12 additions & 1 deletion drivers/hwmon/pmbus/pmbus_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ struct pmbus_data {
int max_attributes;
int num_attributes;
struct attribute_group group;
const struct attribute_group *groups[2];
const struct attribute_group **groups;
struct dentry *debugfs; /* debugfs device directory */

struct pmbus_sensor *sensors;
Expand Down Expand Up @@ -2415,6 +2415,7 @@ int pmbus_do_probe(struct i2c_client *client, const struct i2c_device_id *id,
struct device *dev = &client->dev;
const struct pmbus_platform_data *pdata = dev_get_platdata(dev);
struct pmbus_data *data;
size_t groups_num = 0;
int ret;

if (!info)
Expand All @@ -2429,6 +2430,15 @@ int pmbus_do_probe(struct i2c_client *client, const struct i2c_device_id *id,
if (!data)
return -ENOMEM;

if (info->groups)
while (info->groups[groups_num])
groups_num++;

data->groups = devm_kcalloc(dev, groups_num + 2, sizeof(void *),
GFP_KERNEL);
if (!data->groups)
return -ENOMEM;

i2c_set_clientdata(client, data);
mutex_init(&data->update_lock);
data->dev = dev;
Expand Down Expand Up @@ -2456,6 +2466,7 @@ int pmbus_do_probe(struct i2c_client *client, const struct i2c_device_id *id,
}

data->groups[0] = &data->group;
memcpy(data->groups + 1, info->groups, sizeof(void *) * groups_num);
data->hwmon_dev = hwmon_device_register_with_groups(dev, client->name,
data, data->groups);
if (IS_ERR(data->hwmon_dev)) {
Expand Down

0 comments on commit 991d679

Please sign in to comment.