]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
driver core: platform: allow attaching software nodes when creating devices
authorDmitry Torokhov <dmitry.torokhov@gmail.com>
Sat, 14 Feb 2026 02:52:44 +0000 (18:52 -0800)
committerDanilo Krummrich <dakr@kernel.org>
Mon, 2 Mar 2026 11:13:43 +0000 (12:13 +0100)
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>
Reviewed-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
Link: https://patch.msgid.link/20260214025246.2095239-3-dmitry.torokhov@gmail.com
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
drivers/base/platform.c
include/linux/platform_device.h

index b45d41b018ca6dc2677af7709b27a3735a4bc780..ec467ccd05b344135aad44d5bfaf150168f467a5 100644 (file)
@@ -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);
@@ -875,7 +878,11 @@ struct platform_device *platform_device_register_full(
        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)
index 5f54217930e12cecbc397159322166c590719606..754e4bf2771ac0943aaee11f0584f3184be5c783 100644 (file)
@@ -136,10 +136,14 @@ extern int platform_add_devices(struct platform_device **, int);
  * @data: device-specific data for this platform device.
  * @size_data: size of device-specific data.
  * @dma_mask: DMA mask for the device.
+ * @swnode: a secondary software node to be attached to the device. The node
+ *     will be automatically registered and its lifetime tied to the platform
+ *     device if it is not registered yet.
  * @properties: a set of software properties for the device. If provided,
  *     a managed software node will be automatically created and
  *     assigned to the device. The properties array must be terminated
- *     with a sentinel entry.
+ *     with a sentinel entry. Specifying both @properties and @swnode is not
+ *     allowed.
  *
  * This structure is used to hold information needed to create and register
  * a platform device using platform_device_register_full().
@@ -164,6 +168,7 @@ struct platform_device_info {
        size_t size_data;
        u64 dma_mask;
 
+       const struct software_node *swnode;
        const struct property_entry *properties;
 };
 extern struct platform_device *platform_device_register_full(