summaryrefslogtreecommitdiffstats
path: root/include/linux
diff options
context:
space:
mode:
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>2014-11-04 08:03:59 -0500
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2014-11-04 15:58:23 -0500
commit8a0662d9ed2968e1186208336a8e1fab3fdfea63 (patch)
tree2109aed71b5279750754f1417e9b0ba0c519caa7 /include/linux
parent633a21d80b4a2cd648aa2dacdb22494ffb2f28f0 (diff)
Driver core: Unified interface for firmware node properties
Add new generic routines are provided for retrieving properties from device description objects in the platform firmware in case there are no struct device objects for them (either those objects have not been created yet or they do not exist at all). The following functions are provided: fwnode_property_present() fwnode_property_read_u8() fwnode_property_read_u16() fwnode_property_read_u32() fwnode_property_read_u64() fwnode_property_read_string() fwnode_property_read_u8_array() fwnode_property_read_u16_array() fwnode_property_read_u32_array() fwnode_property_read_u64_array() fwnode_property_read_string_array() in analogy with the corresponding functions for struct device added previously. For all of them, the first argument is a pointer to struct fwnode_handle (new type) that allows a device description object (depending on what platform firmware interface is in use) to be obtained. Add a new macro device_for_each_child_node() for iterating over the children of the device description object associated with a given device and a new function device_get_child_node_count() returning the number of a given device's child nodes. The interface covers both ACPI and Device Trees. Suggested-by: Grant Likely <grant.likely@linaro.org> Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Acked-by: Grant Likely <grant.likely@linaro.org> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Diffstat (limited to 'include/linux')
-rw-r--r--include/linux/acpi.h26
-rw-r--r--include/linux/of.h22
-rw-r--r--include/linux/property.h70
3 files changed, 118 insertions, 0 deletions
diff --git a/include/linux/acpi.h b/include/linux/acpi.h
index 38296d686c55..5b8802216a93 100644
--- a/include/linux/acpi.h
+++ b/include/linux/acpi.h
@@ -440,6 +440,23 @@ struct platform_device *acpi_create_platform_device(struct acpi_device *);
440#define ACPI_COMPANION_SET(dev, adev) do { } while (0) 440#define ACPI_COMPANION_SET(dev, adev) do { } while (0)
441#define ACPI_HANDLE(dev) (NULL) 441#define ACPI_HANDLE(dev) (NULL)
442 442
443struct fwnode_handle;
444
445static inline bool is_acpi_node(struct fwnode_handle *fwnode)
446{
447 return false;
448}
449
450static inline struct acpi_device *acpi_node(struct fwnode_handle *fwnode)
451{
452 return NULL;
453}
454
455static inline struct fwnode_handle *acpi_fwnode_handle(struct acpi_device *adev)
456{
457 return NULL;
458}
459
443static inline const char *acpi_dev_name(struct acpi_device *adev) 460static inline const char *acpi_dev_name(struct acpi_device *adev)
444{ 461{
445 return NULL; 462 return NULL;
@@ -681,6 +698,9 @@ int acpi_dev_prop_read_single(struct acpi_device *adev, const char *propname,
681 enum dev_prop_type proptype, void *val); 698 enum dev_prop_type proptype, void *val);
682int acpi_dev_prop_read(struct acpi_device *adev, const char *propname, 699int acpi_dev_prop_read(struct acpi_device *adev, const char *propname,
683 enum dev_prop_type proptype, void *val, size_t nval); 700 enum dev_prop_type proptype, void *val, size_t nval);
701
702struct acpi_device *acpi_get_next_child(struct device *dev,
703 struct acpi_device *child);
684#else 704#else
685static inline int acpi_dev_get_property(struct acpi_device *adev, 705static inline int acpi_dev_get_property(struct acpi_device *adev,
686 const char *name, acpi_object_type type, 706 const char *name, acpi_object_type type,
@@ -725,6 +745,12 @@ static inline int acpi_dev_prop_read(struct acpi_device *adev,
725 return -ENXIO; 745 return -ENXIO;
726} 746}
727 747
748static inline struct acpi_device *acpi_get_next_child(struct device *dev,
749 struct acpi_device *child)
750{
751 return NULL;
752}
753
728#endif 754#endif
729 755
730#endif /*_LINUX_ACPI_H*/ 756#endif /*_LINUX_ACPI_H*/
diff --git a/include/linux/of.h b/include/linux/of.h
index ce9f6a2b3532..cf79be1441d2 100644
--- a/include/linux/of.h
+++ b/include/linux/of.h
@@ -50,6 +50,7 @@ struct device_node {
50 const char *type; 50 const char *type;
51 phandle phandle; 51 phandle phandle;
52 const char *full_name; 52 const char *full_name;
53 struct fwnode_handle fwnode;
53 54
54 struct property *properties; 55 struct property *properties;
55 struct property *deadprops; /* removed properties */ 56 struct property *deadprops; /* removed properties */
@@ -80,6 +81,7 @@ extern struct kobj_type of_node_ktype;
80static inline void of_node_init(struct device_node *node) 81static inline void of_node_init(struct device_node *node)
81{ 82{
82 kobject_init(&node->kobj, &of_node_ktype); 83 kobject_init(&node->kobj, &of_node_ktype);
84 node->fwnode.type = FWNODE_OF;
83} 85}
84 86
85/* true when node is initialized */ 87/* true when node is initialized */
@@ -115,6 +117,16 @@ extern struct device_node *of_aliases;
115extern struct device_node *of_stdout; 117extern struct device_node *of_stdout;
116extern raw_spinlock_t devtree_lock; 118extern raw_spinlock_t devtree_lock;
117 119
120static inline bool is_of_node(struct fwnode_handle *fwnode)
121{
122 return fwnode && fwnode->type == FWNODE_OF;
123}
124
125static inline struct device_node *of_node(struct fwnode_handle *fwnode)
126{
127 return fwnode ? container_of(fwnode, struct device_node, fwnode) : NULL;
128}
129
118static inline bool of_have_populated_dt(void) 130static inline bool of_have_populated_dt(void)
119{ 131{
120 return of_allnodes != NULL; 132 return of_allnodes != NULL;
@@ -360,6 +372,16 @@ bool of_console_check(struct device_node *dn, char *name, int index);
360 372
361#else /* CONFIG_OF */ 373#else /* CONFIG_OF */
362 374
375static inline bool is_of_node(struct fwnode_handle *fwnode)
376{
377 return false;
378}
379
380static inline struct device_node *of_node(struct fwnode_handle *fwnode)
381{
382 return NULL;
383}
384
363static inline const char* of_node_full_name(const struct device_node *np) 385static inline const char* of_node_full_name(const struct device_node *np)
364{ 386{
365 return "<no-node>"; 387 return "<no-node>";
diff --git a/include/linux/property.h b/include/linux/property.h
index 9242fb0221ba..a6a3d98bd7e9 100644
--- a/include/linux/property.h
+++ b/include/linux/property.h
@@ -40,6 +40,46 @@ int device_property_read_string_array(struct device *dev, const char *propname,
40int device_property_read_string(struct device *dev, const char *propname, 40int device_property_read_string(struct device *dev, const char *propname,
41 const char **val); 41 const char **val);
42 42
43enum fwnode_type {
44 FWNODE_INVALID = 0,
45 FWNODE_OF,
46 FWNODE_ACPI,
47};
48
49struct fwnode_handle {
50 enum fwnode_type type;
51};
52
53bool fwnode_property_present(struct fwnode_handle *fwnode, const char *propname);
54int fwnode_property_read_u8_array(struct fwnode_handle *fwnode,
55 const char *propname, u8 *val,
56 size_t nval);
57int fwnode_property_read_u16_array(struct fwnode_handle *fwnode,
58 const char *propname, u16 *val,
59 size_t nval);
60int fwnode_property_read_u32_array(struct fwnode_handle *fwnode,
61 const char *propname, u32 *val,
62 size_t nval);
63int fwnode_property_read_u64_array(struct fwnode_handle *fwnode,
64 const char *propname, u64 *val,
65 size_t nval);
66int fwnode_property_read_string_array(struct fwnode_handle *fwnode,
67 const char *propname, const char **val,
68 size_t nval);
69int fwnode_property_read_string(struct fwnode_handle *fwnode,
70 const char *propname, const char **val);
71
72struct fwnode_handle *device_get_next_child_node(struct device *dev,
73 struct fwnode_handle *child);
74
75#define device_for_each_child_node(dev, child) \
76 for (child = device_get_next_child_node(dev, NULL); child; \
77 child = device_get_next_child_node(dev, child))
78
79void fwnode_handle_put(struct fwnode_handle *fwnode);
80
81unsigned int device_get_child_node_count(struct device *dev);
82
43static inline bool device_property_read_bool(struct device *dev, 83static inline bool device_property_read_bool(struct device *dev,
44 const char *propname) 84 const char *propname)
45{ 85{
@@ -70,4 +110,34 @@ static inline int device_property_read_u64(struct device *dev,
70 return device_property_read_u64_array(dev, propname, val, 1); 110 return device_property_read_u64_array(dev, propname, val, 1);
71} 111}
72 112
113static inline bool fwnode_property_read_bool(struct fwnode_handle *fwnode,
114 const char *propname)
115{
116 return fwnode_property_present(fwnode, propname);
117}
118
119static inline int fwnode_property_read_u8(struct fwnode_handle *fwnode,
120 const char *propname, u8 *val)
121{
122 return fwnode_property_read_u8_array(fwnode, propname, val, 1);
123}
124
125static inline int fwnode_property_read_u16(struct fwnode_handle *fwnode,
126 const char *propname, u16 *val)
127{
128 return fwnode_property_read_u16_array(fwnode, propname, val, 1);
129}
130
131static inline int fwnode_property_read_u32(struct fwnode_handle *fwnode,
132 const char *propname, u32 *val)
133{
134 return fwnode_property_read_u32_array(fwnode, propname, val, 1);
135}
136
137static inline int fwnode_property_read_u64(struct fwnode_handle *fwnode,
138 const char *propname, u64 *val)
139{
140 return fwnode_property_read_u64_array(fwnode, propname, val, 1);
141}
142
73#endif /* _LINUX_PROPERTY_H_ */ 143#endif /* _LINUX_PROPERTY_H_ */