All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 1/2] pmbus: support for custom sysfs attributes
@ 2019-04-15 18:14 Patrick Venture
  2019-04-15 18:15 ` Patrick Venture
  0 siblings, 1 reply; 2+ messages in thread
From: Patrick Venture @ 2019-04-15 18:14 UTC (permalink / raw)
  To: venture, linux, jdelvare
  Cc: krzysztof.adamski, linux-hwmon, alexander.sverdlin

From: krzysztof.adamski@nokia.com

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>
---
v3:
 - staged before v3 hwmon/pmbus/isl68137 driver
---
 drivers/hwmon/pmbus/pmbus.h      |  3 +++
 drivers/hwmon/pmbus/pmbus_core.c | 13 ++++++++++++-
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/drivers/hwmon/pmbus/pmbus.h b/drivers/hwmon/pmbus/pmbus.h
index 1d24397d36ecd..fb267ec116235 100644
--- a/drivers/hwmon/pmbus/pmbus.h
+++ b/drivers/hwmon/pmbus/pmbus.h
@@ -417,6 +417,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 */
diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
index e2366428a9a91..d6170a802c0f7 100644
--- a/drivers/hwmon/pmbus/pmbus_core.c
+++ b/drivers/hwmon/pmbus/pmbus_core.c
@@ -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;
@@ -2305,6 +2305,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)
@@ -2319,6 +2320,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;
@@ -2346,6 +2356,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)) {
-- 
2.21.0.392.gf8f6787159e-goog


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

* Re: [PATCH v3 1/2] pmbus: support for custom sysfs attributes
  2019-04-15 18:14 [PATCH v3 1/2] pmbus: support for custom sysfs attributes Patrick Venture
@ 2019-04-15 18:15 ` Patrick Venture
  0 siblings, 0 replies; 2+ messages in thread
From: Patrick Venture @ 2019-04-15 18:15 UTC (permalink / raw)
  To: Patrick Venture, Guenter Roeck, jdelvare
  Cc: krzysztof.adamski, linux-hwmon, alexander.sverdlin

On Mon, Apr 15, 2019 at 11:14 AM Patrick Venture <venture@google.com> wrote:
>
> From: krzysztof.adamski@nokia.com

My instance of git send-email didn't parse the From line correctly, my
apologies.

>
> 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>
> ---
> v3:
>  - staged before v3 hwmon/pmbus/isl68137 driver
> ---
>  drivers/hwmon/pmbus/pmbus.h      |  3 +++
>  drivers/hwmon/pmbus/pmbus_core.c | 13 ++++++++++++-
>  2 files changed, 15 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/hwmon/pmbus/pmbus.h b/drivers/hwmon/pmbus/pmbus.h
> index 1d24397d36ecd..fb267ec116235 100644
> --- a/drivers/hwmon/pmbus/pmbus.h
> +++ b/drivers/hwmon/pmbus/pmbus.h
> @@ -417,6 +417,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 */
> diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
> index e2366428a9a91..d6170a802c0f7 100644
> --- a/drivers/hwmon/pmbus/pmbus_core.c
> +++ b/drivers/hwmon/pmbus/pmbus_core.c
> @@ -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;
> @@ -2305,6 +2305,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)
> @@ -2319,6 +2320,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;
> @@ -2346,6 +2356,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)) {
> --
> 2.21.0.392.gf8f6787159e-goog
>

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

end of thread, other threads:[~2019-04-15 18:15 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-15 18:14 [PATCH v3 1/2] pmbus: support for custom sysfs attributes Patrick Venture
2019-04-15 18:15 ` Patrick Venture

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.