* [PATCH] driver core: platform: allow attaching software nodes when creating devices
@ 2026-02-13 22:36 Dmitry Torokhov
2026-02-13 23:25 ` Danilo Krummrich
0 siblings, 1 reply; 5+ messages in thread
From: Dmitry Torokhov @ 2026-02-13 22:36 UTC (permalink / raw)
To: Greg Kroah-Hartman
Cc: Rafael J. Wysocki, Danilo Krummrich, Arnd Bergmann,
Bartosz Golaszewski, Hans de Goede, linux-kernel
Extend platform_device_info structure with an optional pointer to a
software node to be used as a secondary firmware node for the device
being created. If software node has not been registered yet it will be
automatically registered.
This reduces boilerplate needed when switching legacy board code to
static device properties/GPIO references.
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
drivers/base/platform.c | 15 ++++++++++-----
include/linux/platform_device.h | 23 ++++++++++++-----------
2 files changed, 22 insertions(+), 16 deletions(-)
diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index b45d41b018ca..bef69ad68e02 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -850,6 +850,9 @@ struct platform_device *platform_device_register_full(
int ret;
struct platform_device *pdev;
+ if (pdevinfo->swnode && pdevinfo->properties)
+ return ERR_PTR(-EINVAL);
+
pdev = platform_device_alloc(pdevinfo->name, pdevinfo->id);
if (!pdev)
return ERR_PTR(-ENOMEM);
@@ -865,17 +868,19 @@ struct platform_device *platform_device_register_full(
pdev->dev.coherent_dma_mask = pdevinfo->dma_mask;
}
- ret = platform_device_add_resources(pdev,
- pdevinfo->res, pdevinfo->num_res);
+ ret = platform_device_add_resources(pdev, pdevinfo->res, pdevinfo->num_res);
if (ret)
goto err;
- ret = platform_device_add_data(pdev,
- pdevinfo->data, pdevinfo->size_data);
+ ret = platform_device_add_data(pdev, pdevinfo->data, pdevinfo->size_data);
if (ret)
goto err;
- if (pdevinfo->properties) {
+ if (pdevinfo->swnode) {
+ ret = device_add_software_node(&pdev->dev, pdevinfo->swnode);
+ if (ret)
+ goto err;
+ } else if (pdevinfo->properties) {
ret = device_create_managed_software_node(&pdev->dev,
pdevinfo->properties, NULL);
if (ret)
diff --git a/include/linux/platform_device.h b/include/linux/platform_device.h
index 813da101b5bf..3d96edfe0ee6 100644
--- a/include/linux/platform_device.h
+++ b/include/linux/platform_device.h
@@ -119,21 +119,22 @@ extern int platform_get_irq_byname_optional(struct platform_device *dev,
extern int platform_add_devices(struct platform_device **, int);
struct platform_device_info {
- struct device *parent;
- struct fwnode_handle *fwnode;
- bool of_node_reused;
+ struct device *parent;
+ struct fwnode_handle *fwnode;
+ bool of_node_reused;
- const char *name;
- int id;
+ const char *name;
+ int id;
- const struct resource *res;
- unsigned int num_res;
+ const struct resource *res;
+ unsigned int num_res;
- const void *data;
- size_t size_data;
- u64 dma_mask;
+ const void *data;
+ size_t size_data;
+ u64 dma_mask;
- const struct property_entry *properties;
+ const struct software_node *swnode;
+ const struct property_entry *properties;
};
extern struct platform_device *platform_device_register_full(
const struct platform_device_info *pdevinfo);
--
2.53.0.310.g728cabbaf7-goog
--
Dmitry
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] driver core: platform: allow attaching software nodes when creating devices
2026-02-13 22:36 [PATCH] driver core: platform: allow attaching software nodes when creating devices Dmitry Torokhov
@ 2026-02-13 23:25 ` Danilo Krummrich
2026-02-14 0:32 ` Dmitry Torokhov
0 siblings, 1 reply; 5+ messages in thread
From: Danilo Krummrich @ 2026-02-13 23:25 UTC (permalink / raw)
To: Dmitry Torokhov
Cc: Greg Kroah-Hartman, Rafael J. Wysocki, Arnd Bergmann,
Bartosz Golaszewski, Hans de Goede, linux-kernel
On Fri Feb 13, 2026 at 11:36 PM CET, Dmitry Torokhov wrote:
> Extend platform_device_info structure with an optional pointer to a
> software node to be used as a secondary firmware node for the device
> being created. If software node has not been registered yet it will be
> automatically registered.
>
> This reduces boilerplate needed when switching legacy board code to
> static device properties/GPIO references.
Are there any patches for this already? If so, how do you plan to land them?
> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> ---
> drivers/base/platform.c | 15 ++++++++++-----
> include/linux/platform_device.h | 23 ++++++++++++-----------
> 2 files changed, 22 insertions(+), 16 deletions(-)
>
> diff --git a/drivers/base/platform.c b/drivers/base/platform.c
> index b45d41b018ca..bef69ad68e02 100644
> --- a/drivers/base/platform.c
> +++ b/drivers/base/platform.c
> @@ -850,6 +850,9 @@ struct platform_device *platform_device_register_full(
> int ret;
> struct platform_device *pdev;
>
> + if (pdevinfo->swnode && pdevinfo->properties)
> + return ERR_PTR(-EINVAL);
Unfortunate that we can't catch this at build time.
> +
> pdev = platform_device_alloc(pdevinfo->name, pdevinfo->id);
> if (!pdev)
> return ERR_PTR(-ENOMEM);
> @@ -865,17 +868,19 @@ struct platform_device *platform_device_register_full(
> pdev->dev.coherent_dma_mask = pdevinfo->dma_mask;
> }
>
> - ret = platform_device_add_resources(pdev,
> - pdevinfo->res, pdevinfo->num_res);
While the formatting is indeed not great, I prefer not to change this in this
patch. The same goes for the other unrelated formatting changes in this patch.
> + ret = platform_device_add_resources(pdev, pdevinfo->res, pdevinfo->num_res);
> if (ret)
> goto err;
>
> - ret = platform_device_add_data(pdev,
> - pdevinfo->data, pdevinfo->size_data);
> + ret = platform_device_add_data(pdev, pdevinfo->data, pdevinfo->size_data);
> if (ret)
> goto err;
>
> - if (pdevinfo->properties) {
> + if (pdevinfo->swnode) {
> + ret = device_add_software_node(&pdev->dev, pdevinfo->swnode);
> + if (ret)
> + goto err;
> + } else if (pdevinfo->properties) {
> ret = device_create_managed_software_node(&pdev->dev,
> pdevinfo->properties, NULL);
> if (ret)
> diff --git a/include/linux/platform_device.h b/include/linux/platform_device.h
> index 813da101b5bf..3d96edfe0ee6 100644
> --- a/include/linux/platform_device.h
> +++ b/include/linux/platform_device.h
> @@ -119,21 +119,22 @@ extern int platform_get_irq_byname_optional(struct platform_device *dev,
> extern int platform_add_devices(struct platform_device **, int);
>
> struct platform_device_info {
> - struct device *parent;
> - struct fwnode_handle *fwnode;
> - bool of_node_reused;
> + struct device *parent;
> + struct fwnode_handle *fwnode;
> + bool of_node_reused;
>
> - const char *name;
> - int id;
> + const char *name;
> + int id;
>
> - const struct resource *res;
> - unsigned int num_res;
> + const struct resource *res;
> + unsigned int num_res;
>
> - const void *data;
> - size_t size_data;
> - u64 dma_mask;
> + const void *data;
> + size_t size_data;
> + u64 dma_mask;
>
> - const struct property_entry *properties;
> + const struct software_node *swnode;
> + const struct property_entry *properties;
It would be nice to document that the two are mutually exclusive.
> };
> extern struct platform_device *platform_device_register_full(
> const struct platform_device_info *pdevinfo);
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] driver core: platform: allow attaching software nodes when creating devices
2026-02-13 23:25 ` Danilo Krummrich
@ 2026-02-14 0:32 ` Dmitry Torokhov
2026-02-14 0:46 ` Danilo Krummrich
0 siblings, 1 reply; 5+ messages in thread
From: Dmitry Torokhov @ 2026-02-14 0:32 UTC (permalink / raw)
To: Danilo Krummrich
Cc: Greg Kroah-Hartman, Rafael J. Wysocki, Arnd Bergmann,
Bartosz Golaszewski, Hans de Goede, linux-kernel
On Sat, Feb 14, 2026 at 12:25:02AM +0100, Danilo Krummrich wrote:
> On Fri Feb 13, 2026 at 11:36 PM CET, Dmitry Torokhov wrote:
> > Extend platform_device_info structure with an optional pointer to a
> > software node to be used as a secondary firmware node for the device
> > being created. If software node has not been registered yet it will be
> > automatically registered.
> >
> > This reduces boilerplate needed when switching legacy board code to
> > static device properties/GPIO references.
>
> Are there any patches for this already? If so, how do you plan to land them?
I have a couple, the affect different boards/subsystems. Ideally if we
could have an immutable branch for everyone to pull in that would be
better. Otherwise we'll have to hold the patches for a bit...
>
> > Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> > ---
> > drivers/base/platform.c | 15 ++++++++++-----
> > include/linux/platform_device.h | 23 ++++++++++++-----------
> > 2 files changed, 22 insertions(+), 16 deletions(-)
> >
> > diff --git a/drivers/base/platform.c b/drivers/base/platform.c
> > index b45d41b018ca..bef69ad68e02 100644
> > --- a/drivers/base/platform.c
> > +++ b/drivers/base/platform.c
> > @@ -850,6 +850,9 @@ struct platform_device *platform_device_register_full(
> > int ret;
> > struct platform_device *pdev;
> >
> > + if (pdevinfo->swnode && pdevinfo->properties)
> > + return ERR_PTR(-EINVAL);
>
> Unfortunate that we can't catch this at build time.
>
> > +
> > pdev = platform_device_alloc(pdevinfo->name, pdevinfo->id);
> > if (!pdev)
> > return ERR_PTR(-ENOMEM);
> > @@ -865,17 +868,19 @@ struct platform_device *platform_device_register_full(
> > pdev->dev.coherent_dma_mask = pdevinfo->dma_mask;
> > }
> >
> > - ret = platform_device_add_resources(pdev,
> > - pdevinfo->res, pdevinfo->num_res);
>
> While the formatting is indeed not great, I prefer not to change this in this
> patch. The same goes for the other unrelated formatting changes in this patch.
I'll split into several patches.
>
> > + ret = platform_device_add_resources(pdev, pdevinfo->res, pdevinfo->num_res);
> > if (ret)
> > goto err;
> >
> > - ret = platform_device_add_data(pdev,
> > - pdevinfo->data, pdevinfo->size_data);
> > + ret = platform_device_add_data(pdev, pdevinfo->data, pdevinfo->size_data);
> > if (ret)
> > goto err;
> >
> > - if (pdevinfo->properties) {
> > + if (pdevinfo->swnode) {
> > + ret = device_add_software_node(&pdev->dev, pdevinfo->swnode);
> > + if (ret)
> > + goto err;
> > + } else if (pdevinfo->properties) {
> > ret = device_create_managed_software_node(&pdev->dev,
> > pdevinfo->properties, NULL);
> > if (ret)
> > diff --git a/include/linux/platform_device.h b/include/linux/platform_device.h
> > index 813da101b5bf..3d96edfe0ee6 100644
> > --- a/include/linux/platform_device.h
> > +++ b/include/linux/platform_device.h
> > @@ -119,21 +119,22 @@ extern int platform_get_irq_byname_optional(struct platform_device *dev,
> > extern int platform_add_devices(struct platform_device **, int);
> >
> > struct platform_device_info {
> > - struct device *parent;
> > - struct fwnode_handle *fwnode;
> > - bool of_node_reused;
> > + struct device *parent;
> > + struct fwnode_handle *fwnode;
> > + bool of_node_reused;
> >
> > - const char *name;
> > - int id;
> > + const char *name;
> > + int id;
> >
> > - const struct resource *res;
> > - unsigned int num_res;
> > + const struct resource *res;
> > + unsigned int num_res;
> >
> > - const void *data;
> > - size_t size_data;
> > - u64 dma_mask;
> > + const void *data;
> > + size_t size_data;
> > + u64 dma_mask;
> >
> > - const struct property_entry *properties;
> > + const struct software_node *swnode;
> > + const struct property_entry *properties;
>
> It would be nice to document that the two are mutually exclusive.
I'll document platform_device_info.
Thanks.
--
Dmitry
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] driver core: platform: allow attaching software nodes when creating devices
2026-02-14 0:32 ` Dmitry Torokhov
@ 2026-02-14 0:46 ` Danilo Krummrich
2026-02-14 1:10 ` Dmitry Torokhov
0 siblings, 1 reply; 5+ messages in thread
From: Danilo Krummrich @ 2026-02-14 0:46 UTC (permalink / raw)
To: Dmitry Torokhov
Cc: Greg Kroah-Hartman, Rafael J. Wysocki, Arnd Bergmann,
Bartosz Golaszewski, Hans de Goede, linux-kernel
On Sat Feb 14, 2026 at 1:32 AM CET, Dmitry Torokhov wrote:
> I have a couple, the affect different boards/subsystems. Ideally if we
> could have an immutable branch for everyone to pull in that would be
> better. Otherwise we'll have to hold the patches for a bit...
If it helps you, I can provide a signed tag for this purpose once we land this
patch.
> I'll split into several patches.
Honestly, I'm not sure if we want to fix the formatting at all. It is not too
bad, and fixing it messes with git-blame.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] driver core: platform: allow attaching software nodes when creating devices
2026-02-14 0:46 ` Danilo Krummrich
@ 2026-02-14 1:10 ` Dmitry Torokhov
0 siblings, 0 replies; 5+ messages in thread
From: Dmitry Torokhov @ 2026-02-14 1:10 UTC (permalink / raw)
To: Danilo Krummrich
Cc: Greg Kroah-Hartman, Rafael J. Wysocki, Arnd Bergmann,
Bartosz Golaszewski, Hans de Goede, linux-kernel
On Sat, Feb 14, 2026 at 01:46:03AM +0100, Danilo Krummrich wrote:
> On Sat Feb 14, 2026 at 1:32 AM CET, Dmitry Torokhov wrote:
> > I have a couple, the affect different boards/subsystems. Ideally if we
> > could have an immutable branch for everyone to pull in that would be
> > better. Otherwise we'll have to hold the patches for a bit...
>
> If it helps you, I can provide a signed tag for this purpose once we land this
> patch.
>
> > I'll split into several patches.
>
> Honestly, I'm not sure if we want to fix the formatting at all. It is not too
> bad, and fixing it messes with git-blame.
It's pretty easy to re-blame... I really prefer to keep the codebase
clean.
--
Dmitry
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-02-14 1:11 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-13 22:36 [PATCH] driver core: platform: allow attaching software nodes when creating devices Dmitry Torokhov
2026-02-13 23:25 ` Danilo Krummrich
2026-02-14 0:32 ` Dmitry Torokhov
2026-02-14 0:46 ` Danilo Krummrich
2026-02-14 1:10 ` Dmitry Torokhov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox