History

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.

Saravana Kannan committed 7 years ago

Commit 372a67c1 parent 54ecb8f2 files · +9 −0Browse files

Unified · Split

2 files
  1. drivers/base/core.c +7 −0
  2. include/linux/fwnode.h +2 −0
drivers/base/core.c+7−0
@@ -2198,6 +2198,10 @@ int device_add(struct device *dev) · 2197 unmodified lines
21982198 BUS_NOTIFY_ADD_DEVICE, dev);
21992199
22002200 kobject_uevent(&dev->kobj, KOBJ_ADD);
2201+
2202+ if (dev->fwnode && !dev->fwnode->dev)
2203+ dev->fwnode->dev = dev;
2204+
22012205 bus_probe_device(dev);
22022206 if (parent)
22032207 klist_add_tail(&dev->p->knode_parent,
@@ -2342,6 +2346,9 @@ void device_del(struct device *dev) · 138 unmodified lines
23422346 kill_device(dev);
23432347 device_unlock(dev);
23442348
2349+ if (dev->fwnode && dev->fwnode->dev == dev)
2350+ dev->fwnode->dev = NULL;
2351+
23452352 /* Notify clients of device removal. This call must come
23462353 * before dpm_sysfs_remove().
23472354 */
include/linux/fwnode.h+2−0
@@ -17,6 +17,7 @@ struct device; · 16 unmodified lines
1717 struct fwnode_handle {
1818 struct fwnode_handle *secondary;
1919 const struct fwnode_operations *ops;
20+ struct device *dev;
2021 };
2122
2223 /**
@@ -123,5 +124,6 @@ struct fwnode_operations { · 100 unmodified lines
123124 if (fwnode_has_op(fwnode, op)) \
124125 (fwnode)->ops->op(fwnode, ## __VA_ARGS__); \
125126 } while (false)
127+#define get_dev_from_fwnode(fwnode) get_device((fwnode)->dev)
126128
127129 #endif

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t