mirror of
https://github.com/hardkernel/linux.git
synced 2026-06-08 11:50:43 +09:00
FROMGIT: driver core: Add fwnode_to_dev() to look up device from fwnode
It's often useful to look up a device that corresponds to a fwnode. So
add an API to do that irrespective of the bus on which the device has
been added to.
Signed-off-by: Saravana Kannan <saravanak@google.com>
Link: https://lore.kernel.org/r/20190904211126.47518-2-saravanak@google.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry-picked from commit 372a67c0c5
https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core.git driver-core-next)
Change-Id: I68c36177da083bfb04e73c1b754e740f40faf284
This commit is contained in:
@@ -1981,6 +1981,10 @@ int device_add(struct device *dev)
|
||||
BUS_NOTIFY_ADD_DEVICE, dev);
|
||||
|
||||
kobject_uevent(&dev->kobj, KOBJ_ADD);
|
||||
|
||||
if (dev->fwnode && !dev->fwnode->dev)
|
||||
dev->fwnode->dev = dev;
|
||||
|
||||
bus_probe_device(dev);
|
||||
if (parent)
|
||||
klist_add_tail(&dev->p->knode_parent,
|
||||
@@ -2123,6 +2127,9 @@ void device_del(struct device *dev)
|
||||
kill_device(dev);
|
||||
device_unlock(dev);
|
||||
|
||||
if (dev->fwnode && dev->fwnode->dev == dev)
|
||||
dev->fwnode->dev = NULL;
|
||||
|
||||
/* Notify clients of device removal. This call must come
|
||||
* before dpm_sysfs_remove().
|
||||
*/
|
||||
|
||||
@@ -20,6 +20,7 @@ struct device;
|
||||
struct fwnode_handle {
|
||||
struct fwnode_handle *secondary;
|
||||
const struct fwnode_operations *ops;
|
||||
struct device *dev;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -125,5 +126,6 @@ struct fwnode_operations {
|
||||
if (fwnode_has_op(fwnode, op)) \
|
||||
(fwnode)->ops->op(fwnode, ## __VA_ARGS__); \
|
||||
} while (false)
|
||||
#define get_dev_from_fwnode(fwnode) get_device((fwnode)->dev)
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user