Skip to content

Commit 5590f31

Browse files
ozbenhgregkh
authored andcommitted
drivers/core/of: Add symlink to device-tree from devices with an OF node
So I've been annoyed lately with having a bunch of devices such as i2c eeproms (for use by VPDs, server world !) and other bits and pieces that I want to be able to identify from userspace, and possibly provide additional data about from FW. Basically, it boils down to correlating the sysfs device with the OF tree device node, so that user space can use device-tree info such as additional "location" or "label" (or whatever else we can come up with) propreties to identify a given device, or get some attributes of use about it, etc... Now, so far, we've done that in some subsystem in a fairly ad-hoc basis using "devspec" properties. For example, PCI creates them if it can correlate the probed device with a DT node. Some powerpc specific busses do that too. However, i2c doesn't and it would be nice to have something more generic since technically any device can have a corresponding device tree node. This patch adds an "of_node" symlink to devices that have a non-NULL dev->of_node pointer, the patch is pretty trivial and seems to work just fine for me. Signed-off-by: Benjamin Herrenschmidt <[email protected]> Acked-by: Rob Herring <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent e8a51e1 commit 5590f31

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Note: This documents additional properties of any device beyond what
2+
# is documented in Documentation/sysfs-rules.txt
3+
4+
What: /sys/devices/*/of_path
5+
Date: February 2015
6+
Contact: Device Tree mailing list <[email protected]>
7+
Description:
8+
Any device associated with a device-tree node will have
9+
an of_path symlink pointing to the corresponding device
10+
node in /sys/firmware/devicetree/

drivers/base/core.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -805,16 +805,24 @@ static void cleanup_device_parent(struct device *dev)
805805

806806
static int device_add_class_symlinks(struct device *dev)
807807
{
808+
struct device_node *of_node = dev_of_node(dev);
808809
int error;
809810

811+
if (of_node) {
812+
error = sysfs_create_link(&dev->kobj, &of_node->kobj,"of_node");
813+
if (error)
814+
dev_warn(dev, "Error %d creating of_node link\n",error);
815+
/* An error here doesn't warrant bringing down the device */
816+
}
817+
810818
if (!dev->class)
811819
return 0;
812820

813821
error = sysfs_create_link(&dev->kobj,
814822
&dev->class->p->subsys.kobj,
815823
"subsystem");
816824
if (error)
817-
goto out;
825+
goto out_devnode;
818826

819827
if (dev->parent && device_is_not_partition(dev)) {
820828
error = sysfs_create_link(&dev->kobj, &dev->parent->kobj,
@@ -842,12 +850,16 @@ static int device_add_class_symlinks(struct device *dev)
842850

843851
out_subsys:
844852
sysfs_remove_link(&dev->kobj, "subsystem");
845-
out:
853+
out_devnode:
854+
sysfs_remove_link(&dev->kobj, "of_node");
846855
return error;
847856
}
848857

849858
static void device_remove_class_symlinks(struct device *dev)
850859
{
860+
if (dev_of_node(dev))
861+
sysfs_remove_link(&dev->kobj, "of_node");
862+
851863
if (!dev->class)
852864
return;
853865

0 commit comments

Comments
 (0)