driver core: platform: provide platform_device_set_fwnode()

Provide a helper function encapsulating the logic of assigning firmware
nodes to platform devices created with platform_device_alloc(). Make the
kerneldoc state that this is the proper interface for assigning firmware
nodes to dynamically allocated platform devices. This will allow us to
switch to counting the references of the device's firmware nodes in the
future, not only the OF nodes.

Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
Link: https://patch.msgid.link/20260706-pdev-fwnode-ref-v3-3-1ff028e33779@oss.qualcomm.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
Bartosz Golaszewski 2026-07-06 14:44:15 +02:00 committed by Greg Kroah-Hartman
parent 714cfe9e14
commit 8877c06885
2 changed files with 22 additions and 0 deletions

View File

@ -711,6 +711,25 @@ void platform_device_set_of_node(struct platform_device *pdev,
}
EXPORT_SYMBOL_GPL(platform_device_set_of_node);
/**
* platform_device_set_fwnode - assign a firmware node to device
* @pdev: platform device to set the node for
* @fwnode: new firmware node
*
* Assign a firmware node to this platform device. Internally keep track of the
* reference count. Devices created with platform_device_alloc() must use this
* function instead of assigning the node manually.
*/
void platform_device_set_fwnode(struct platform_device *pdev,
struct fwnode_handle *fwnode)
{
if (is_of_node(fwnode))
platform_device_set_of_node(pdev, to_of_node(fwnode));
else
pdev->dev.fwnode = fwnode;
}
EXPORT_SYMBOL_GPL(platform_device_set_fwnode);
/**
* platform_device_add - add a platform device to device hierarchy
* @pdev: platform device we're adding

View File

@ -20,6 +20,7 @@ struct mfd_cell;
struct property_entry;
struct platform_device_id;
struct device_node;
struct fwnode_handle;
struct platform_device {
const char *name;
@ -265,6 +266,8 @@ extern int platform_device_add_data(struct platform_device *pdev,
const void *data, size_t size);
void platform_device_set_of_node(struct platform_device *pdev,
struct device_node *np);
void platform_device_set_fwnode(struct platform_device *pdev,
struct fwnode_handle *fwnode);
extern int platform_device_add(struct platform_device *pdev);
extern void platform_device_del(struct platform_device *pdev);
extern void platform_device_put(struct platform_device *pdev);