* [PATCH v2 1/3] driver core: platform: add kerneldoc to struct platform_device_info
2026-02-14 2:52 [PATCH v2 0/3] Allow attaching software node when registering platform devices Dmitry Torokhov
@ 2026-02-14 2:52 ` Dmitry Torokhov
2026-02-16 13:31 ` Bartosz Golaszewski
2026-02-14 2:52 ` [PATCH v2 2/3] driver core: platform: allow attaching software nodes when creating devices Dmitry Torokhov
` (2 subsequent siblings)
3 siblings, 1 reply; 13+ messages in thread
From: Dmitry Torokhov @ 2026-02-14 2:52 UTC (permalink / raw)
To: Greg Kroah-Hartman, Danilo Krummrich
Cc: Rafael J. Wysocki, Arnd Bergmann, Bartosz Golaszewski,
Hans de Goede, linux-kernel
Add kernel documentation for struct platform_device_info and its
individual members. While at it remove an extra indent level from the
structure definition.
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
include/linux/platform_device.h | 53 ++++++++++++++++++++++++++-------
1 file changed, 42 insertions(+), 11 deletions(-)
diff --git a/include/linux/platform_device.h b/include/linux/platform_device.h
index 813da101b5bf..5f54217930e1 100644
--- a/include/linux/platform_device.h
+++ b/include/linux/platform_device.h
@@ -118,22 +118,53 @@ extern int platform_get_irq_byname_optional(struct platform_device *dev,
const char *name);
extern int platform_add_devices(struct platform_device **, int);
+/**
+ * struct platform_device_info - set of parameters for creating a platform device
+ * @parent: parent device for the new platform device.
+ * @fwnode: firmware node associated with the device.
+ * @of_node_reused: indicates that device tree node associated with the device
+ * is shared with another device, typically its ancestor. Setting this to
+ * %true prevents the device from being matched via the OF match table,
+ * and stops the device core from automatically binding pinctrl
+ * configuration to avoid disrupting the other device.
+ * @name: name of the device.
+ * @id: instance ID of the device. Use %PLATFORM_DEVID_NONE if there is only
+ * one instance of the device, or %PLATFORM_DEVID_AUTO to let the
+ * kernel automatically assign a unique instance ID.
+ * @res: set of resources to attach to the device.
+ * @num_res: number of entries in @res.
+ * @data: device-specific data for this platform device.
+ * @size_data: size of device-specific data.
+ * @dma_mask: DMA mask for the device.
+ * @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.
+ *
+ * This structure is used to hold information needed to create and register
+ * a platform device using platform_device_register_full().
+ *
+ * platform_device_register_full() makes deep copies of @name, @res, @data and
+ * @properties, so the caller does not need to keep them after registration.
+ * If the registration is performed during initialization, these can be marked
+ * as __initconst.
+ */
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 property_entry *properties;
};
extern struct platform_device *platform_device_register_full(
const struct platform_device_info *pdevinfo);
--
2.53.0.310.g728cabbaf7-goog
^ permalink raw reply related [flat|nested] 13+ messages in thread* [PATCH v2 2/3] driver core: platform: allow attaching software nodes when creating devices
2026-02-14 2:52 [PATCH v2 0/3] Allow attaching software node when registering platform devices Dmitry Torokhov
2026-02-14 2:52 ` [PATCH v2 1/3] driver core: platform: add kerneldoc to struct platform_device_info Dmitry Torokhov
@ 2026-02-14 2:52 ` Dmitry Torokhov
2026-02-16 13:31 ` Bartosz Golaszewski
2026-02-14 2:52 ` [PATCH v2 3/3] driver core: platform: fix various formatting issues Dmitry Torokhov
2026-02-14 10:55 ` [PATCH v2 0/3] Allow attaching software node when registering platform devices Danilo Krummrich
3 siblings, 1 reply; 13+ messages in thread
From: Dmitry Torokhov @ 2026-02-14 2:52 UTC (permalink / raw)
To: Greg Kroah-Hartman, Danilo Krummrich
Cc: Rafael J. Wysocki, 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 | 9 ++++++++-
include/linux/platform_device.h | 7 ++++++-
2 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index b45d41b018ca..ec467ccd05b3 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);
@@ -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)
diff --git a/include/linux/platform_device.h b/include/linux/platform_device.h
index 5f54217930e1..754e4bf2771a 100644
--- a/include/linux/platform_device.h
+++ b/include/linux/platform_device.h
@@ -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(
--
2.53.0.310.g728cabbaf7-goog
^ permalink raw reply related [flat|nested] 13+ messages in thread* [PATCH v2 3/3] driver core: platform: fix various formatting issues
2026-02-14 2:52 [PATCH v2 0/3] Allow attaching software node when registering platform devices Dmitry Torokhov
2026-02-14 2:52 ` [PATCH v2 1/3] driver core: platform: add kerneldoc to struct platform_device_info Dmitry Torokhov
2026-02-14 2:52 ` [PATCH v2 2/3] driver core: platform: allow attaching software nodes when creating devices Dmitry Torokhov
@ 2026-02-14 2:52 ` Dmitry Torokhov
2026-02-16 13:31 ` Bartosz Golaszewski
2026-02-14 10:55 ` [PATCH v2 0/3] Allow attaching software node when registering platform devices Danilo Krummrich
3 siblings, 1 reply; 13+ messages in thread
From: Dmitry Torokhov @ 2026-02-14 2:52 UTC (permalink / raw)
To: Greg Kroah-Hartman, Danilo Krummrich
Cc: Rafael J. Wysocki, Arnd Bergmann, Bartosz Golaszewski,
Hans de Goede, linux-kernel
Make checkpatch happy. This helps when checkpatch is set up as an
automatic linter.
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
drivers/base/platform.c | 49 ++++++++++++++++++-----------------------
1 file changed, 21 insertions(+), 28 deletions(-)
diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index ec467ccd05b3..4617d1e88772 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -75,7 +75,7 @@ struct resource *platform_get_mem_or_io(struct platform_device *dev,
for (i = 0; i < dev->num_resources; i++) {
struct resource *r = &dev->resource[i];
- if ((resource_type(r) & (IORESOURCE_MEM|IORESOURCE_IO)) && num-- == 0)
+ if ((resource_type(r) & (IORESOURCE_MEM | IORESOURCE_IO)) && num-- == 0)
return r;
}
return NULL;
@@ -97,7 +97,7 @@ EXPORT_SYMBOL_GPL(platform_get_mem_or_io);
*/
void __iomem *
devm_platform_get_and_ioremap_resource(struct platform_device *pdev,
- unsigned int index, struct resource **res)
+ unsigned int index, struct resource **res)
{
struct resource *r;
@@ -172,7 +172,7 @@ static const struct cpumask *get_irq_affinity(struct platform_device *dev,
* @num: interrupt number index
* @affinity: optional cpumask pointer to get the affinity of a per-cpu interrupt
*
- * Gets an interupt for a platform device. Device drivers should check the
+ * Gets an interrupt for a platform device. Device drivers should check the
* return value for errors so as to not pass a negative integer value to
* the request_irq() APIs. Optional affinity information is provided in the
* affinity pointer if available, and NULL otherwise.
@@ -844,8 +844,7 @@ EXPORT_SYMBOL_GPL(platform_device_unregister);
*
* Returns &struct platform_device pointer on success, or ERR_PTR() on error.
*/
-struct platform_device *platform_device_register_full(
- const struct platform_device_info *pdevinfo)
+struct platform_device *platform_device_register_full(const struct platform_device_info *pdevinfo)
{
int ret;
struct platform_device *pdev;
@@ -868,13 +867,11 @@ 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;
@@ -906,8 +903,7 @@ EXPORT_SYMBOL_GPL(platform_device_register_full);
* @drv: platform driver structure
* @owner: owning module/driver
*/
-int __platform_driver_register(struct platform_driver *drv,
- struct module *owner)
+int __platform_driver_register(struct platform_driver *drv, struct module *owner)
{
drv->driver.owner = owner;
drv->driver.bus = &platform_bus_type;
@@ -959,13 +955,14 @@ static int is_bound_to_driver(struct device *dev, void *driver)
* a negative error code and with the driver not registered.
*/
int __init_or_module __platform_driver_probe(struct platform_driver *drv,
- int (*probe)(struct platform_device *), struct module *module)
+ int (*probe)(struct platform_device *),
+ struct module *module)
{
int retval;
if (drv->driver.probe_type == PROBE_PREFER_ASYNCHRONOUS) {
pr_err("%s: drivers registered with %s can not be probed asynchronously\n",
- drv->driver.name, __func__);
+ drv->driver.name, __func__);
return -EINVAL;
}
@@ -1021,11 +1018,11 @@ EXPORT_SYMBOL_GPL(__platform_driver_probe);
*
* Returns &struct platform_device pointer on success, or ERR_PTR() on error.
*/
-struct platform_device * __init_or_module __platform_create_bundle(
- struct platform_driver *driver,
- int (*probe)(struct platform_device *),
- struct resource *res, unsigned int n_res,
- const void *data, size_t size, struct module *module)
+struct platform_device * __init_or_module
+__platform_create_bundle(struct platform_driver *driver,
+ int (*probe)(struct platform_device *),
+ struct resource *res, unsigned int n_res,
+ const void *data, size_t size, struct module *module)
{
struct platform_device *pdev;
int error;
@@ -1124,9 +1121,8 @@ void platform_unregister_drivers(struct platform_driver * const *drivers,
}
EXPORT_SYMBOL_GPL(platform_unregister_drivers);
-static const struct platform_device_id *platform_match_id(
- const struct platform_device_id *id,
- struct platform_device *pdev)
+static const struct platform_device_id *
+platform_match_id(const struct platform_device_id *id, struct platform_device *pdev)
{
while (id->name[0]) {
if (strcmp(pdev->name, id->name) == 0) {
@@ -1348,13 +1344,12 @@ static struct attribute *platform_dev_attrs[] = {
NULL,
};
-static umode_t platform_dev_attrs_visible(struct kobject *kobj, struct attribute *a,
- int n)
+static umode_t platform_dev_attrs_visible(struct kobject *kobj,
+ struct attribute *a, int n)
{
struct device *dev = container_of(kobj, typeof(*dev), kobj);
- if (a == &dev_attr_numa_node.attr &&
- dev_to_node(dev) == NUMA_NO_NODE)
+ if (a == &dev_attr_numa_node.attr && dev_to_node(dev) == NUMA_NO_NODE)
return 0;
return a->mode;
@@ -1366,7 +1361,6 @@ static const struct attribute_group platform_dev_group = {
};
__ATTRIBUTE_GROUPS(platform_dev);
-
/**
* platform_match - bind platform device to platform driver.
* @dev: device.
@@ -1419,8 +1413,7 @@ static int platform_uevent(const struct device *dev, struct kobj_uevent_env *env
if (rc != -ENODEV)
return rc;
- add_uevent_var(env, "MODALIAS=%s%s", PLATFORM_MODULE_PREFIX,
- pdev->name);
+ add_uevent_var(env, "MODALIAS=%s%s", PLATFORM_MODULE_PREFIX, pdev->name);
return 0;
}
--
2.53.0.310.g728cabbaf7-goog
^ permalink raw reply related [flat|nested] 13+ messages in thread