driver core: platform: allow attaching software nodes when creating devices
PATCH 1/1 driver core: platform: allow attaching software nodes when creating devices
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.
--- drivers/base/platform.c | 15 ++++++++++----- include/linux/platform_device.h | 23 ++++++++++++----------- 2 files changed, 22 insertions(+), 16 deletions(-)
drivers/base/platform.c +10 -5
@@ -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)
include/linux/platform_device.h +12 -11
@@ -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);
Signature · 5 lines
2.53.0.310.g728cabbaf7-goog -- Dmitry
Danilo Krummrich
maintainerQuoted 7 lines · Dmitry Torokhov
Extend
platform_device_infostructure 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?
Quoted 11 lines
Signed-off-by Dmitry Torokhov <[email protected]>--- drivers/base/platform.c | 15 ++++++++++----- include/linux/platform_device.h | 23 ++++++++++++----------- 2 files changed, 22 insertions(+), 16 deletions(-)drivers/base/platform.c +0
-0
drivers/base/platform.c struct platform_device *platform_device_register_full( · line 854
Quoted 5 lines
drivers/base/platform.c +2
-0@@ -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.
drivers/base/platform.c struct platform_device *platform_device_register_full( · line 869
Quoted 10 lines
drivers/base/platform.c +1
-2+ 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.
Quoted 44 lines
drivers/base/platform.c +7
-3+ 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)include/linux/platform_device.h +7
-7@@ -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;
include/linux/platform_device.h extern int platform_get_irq_byname_optional(struct platform_device *dev, · line 137
Quoted 10 lines
include/linux/platform_device.h +5
-4-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.
Quoted 3 lines
include/linux/platform_device.h +0
-0};extern struct platform_device *platform_device_register_full (const struct platform_device_info *pdevinfo);
Quoted 10 lines · Danilo Krummrich
Quoted 7 lines · Dmitry Torokhov
Extend
platform_device_infostructure 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...
Quoted 28 lines
Quoted 12 lines
Signed-off-by Dmitry Torokhov <[email protected]>--- drivers/base/platform.c | 15 ++++++++++----- include/linux/platform_device.h | 23 ++++++++++++----------- 2 files changed, 22 insertions(+), 16 deletions(-)drivers/base/platform.c +0
-0drivers/base/platform.c struct platform_device *platform_device_register_full( · line 854
Quoted 5 lines
drivers/base/platform.c +2
-0@@ -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.
Quoted 8 lines
drivers/base/platform.c +1
-0+ 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; }
Quoted 5 lines
drivers/base/platform.c struct platform_device *platform_device_register_full( · line 869
Quoted 2 lines
drivers/base/platform.c +0
-2- 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.
Quoted 52 lines
Quoted 52 lines
drivers/base/platform.c +7
-3+ 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)include/linux/platform_device.h +10
-10@@ -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;
Quoted 5 lines
include/linux/platform_device.h extern int platform_get_irq_byname_optional(struct platform_device *dev, · line 137
Quoted 3 lines
include/linux/platform_device.h +2
-1-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.
Signature · 1 line
Dmitry
Danilo Krummrich
maintainerQuoted 3 lines · Dmitry Torokhov
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.
Quoted 1 line
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.
Quoted 5 lines · Danilo Krummrich
Quoted 3 lines · Dmitry Torokhov
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...
Quoted 7 lines
If it helps you, I can provide a signed tag for this purpose once we land this patch.
Quoted 1 line
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.
Signature · 1 line
Dmitry