1 #include <linux/string.h>
2 #include <linux/kernel.h>
3 #include <linux/init.h>
4 #include <linux/module.h>
5 #include <linux/mod_devicetable.h>
6 #include <linux/slab.h>
9 #include <asm/of_device.h>
12 * of_match_node - Tell if an device_node has a matching of_match structure
13 * @ids: array of of device match structures to search in
14 * @node: the of device structure to match against
16 * Low level utility function used by device matching.
18 const struct of_device_id
*of_match_node(const struct of_device_id
*matches
,
19 const struct device_node
*node
)
21 while (matches
->name
[0] || matches
->type
[0] || matches
->compatible
[0]) {
25 && !strcmp(matches
->name
, node
->name
);
28 && !strcmp(matches
->type
, node
->type
);
29 if (matches
->compatible
[0])
30 match
&= device_is_compatible(node
,
40 * of_match_device - Tell if an of_device structure has a matching
42 * @ids: array of of device match structures to search in
43 * @dev: the of device structure to match against
45 * Used by a driver to check whether an of_device present in the
46 * system is in its list of supported devices.
48 const struct of_device_id
*of_match_device(const struct of_device_id
*matches
,
49 const struct of_device
*dev
)
53 return of_match_node(matches
, dev
->node
);
56 struct of_device
*of_dev_get(struct of_device
*dev
)
62 tmp
= get_device(&dev
->dev
);
64 return to_of_device(tmp
);
69 void of_dev_put(struct of_device
*dev
)
72 put_device(&dev
->dev
);
75 static ssize_t
dev_show_devspec(struct device
*dev
,
76 struct device_attribute
*attr
, char *buf
)
78 struct of_device
*ofdev
;
80 ofdev
= to_of_device(dev
);
81 return sprintf(buf
, "%s", ofdev
->node
->full_name
);
84 static DEVICE_ATTR(devspec
, S_IRUGO
, dev_show_devspec
, NULL
);
87 * of_release_dev - free an of device structure when all users of it are finished.
88 * @dev: device that's been disconnected
90 * Will be called only by the device core when all users of this of device are
93 void of_release_dev(struct device
*dev
)
95 struct of_device
*ofdev
;
97 ofdev
= to_of_device(dev
);
98 of_node_put(ofdev
->node
);
102 int of_device_register(struct of_device
*ofdev
)
106 BUG_ON(ofdev
->node
== NULL
);
108 rc
= device_register(&ofdev
->dev
);
112 device_create_file(&ofdev
->dev
, &dev_attr_devspec
);
117 void of_device_unregister(struct of_device
*ofdev
)
119 device_remove_file(&ofdev
->dev
, &dev_attr_devspec
);
121 device_unregister(&ofdev
->dev
);
125 EXPORT_SYMBOL(of_match_node
);
126 EXPORT_SYMBOL(of_match_device
);
127 EXPORT_SYMBOL(of_device_register
);
128 EXPORT_SYMBOL(of_device_unregister
);
129 EXPORT_SYMBOL(of_dev_get
);
130 EXPORT_SYMBOL(of_dev_put
);
131 EXPORT_SYMBOL(of_release_dev
);