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.
Unified · Split
| @@ -2198,6 +2198,10 @@ int device_add(struct device *dev) · 2197 unmodified lines | ||
| 2198 | 2198 | BUS_NOTIFY_ADD_DEVICE, dev); |
| 2199 | 2199 | |
| 2200 | 2200 | kobject_uevent(&dev->kobj, KOBJ_ADD); |
| 2201 | + | |
| 2202 | + if (dev->fwnode && !dev->fwnode->dev) | |
| 2203 | + dev->fwnode->dev = dev; | |
| 2204 | + | |
| 2201 | 2205 | bus_probe_device(dev); |
| 2202 | 2206 | if (parent) |
| 2203 | 2207 | klist_add_tail(&dev->p->knode_parent, |
| @@ -2342,6 +2346,9 @@ void device_del(struct device *dev) · 138 unmodified lines | ||
| 2342 | 2346 | kill_device(dev); |
| 2343 | 2347 | device_unlock(dev); |
| 2344 | 2348 | |
| 2349 | + if (dev->fwnode && dev->fwnode->dev == dev) | |
| 2350 | + dev->fwnode->dev = NULL; | |
| 2351 | + | |
| 2345 | 2352 | /* Notify clients of device removal. This call must come |
| 2346 | 2353 | * before dpm_sysfs_remove(). |
| 2347 | 2354 | */ |
| @@ -17,6 +17,7 @@ struct device; · 16 unmodified lines | ||
| 17 | 17 | struct fwnode_handle { |
| 18 | 18 | struct fwnode_handle *secondary; |
| 19 | 19 | const struct fwnode_operations *ops; |
| 20 | + struct device *dev; | |
| 20 | 21 | }; |
| 21 | 22 | |
| 22 | 23 | /** |
| @@ -123,5 +124,6 @@ struct fwnode_operations { · 100 unmodified lines | ||
| 123 | 124 | if (fwnode_has_op(fwnode, op)) \ |
| 124 | 125 | (fwnode)->ops->op(fwnode, ## __VA_ARGS__); \ |
| 125 | 126 | } while (false) |
| 127 | +#define get_dev_from_fwnode(fwnode) get_device((fwnode)->dev) | |
| 126 | 128 | |
| 127 | 129 | #endif |