diff options
Diffstat (limited to 'include/linux/property.h')
-rw-r--r-- | include/linux/property.h | 143 |
1 files changed, 143 insertions, 0 deletions
diff --git a/include/linux/property.h b/include/linux/property.h new file mode 100644 index 000000000000..a6a3d98bd7e9 --- /dev/null +++ b/include/linux/property.h | |||
@@ -0,0 +1,143 @@ | |||
1 | /* | ||
2 | * property.h - Unified device property interface. | ||
3 | * | ||
4 | * Copyright (C) 2014, Intel Corporation | ||
5 | * Authors: Rafael J. Wysocki <rafael.j.wysocki@intel.com> | ||
6 | * Mika Westerberg <mika.westerberg@linux.intel.com> | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify | ||
9 | * it under the terms of the GNU General Public License version 2 as | ||
10 | * published by the Free Software Foundation. | ||
11 | */ | ||
12 | |||
13 | #ifndef _LINUX_PROPERTY_H_ | ||
14 | #define _LINUX_PROPERTY_H_ | ||
15 | |||
16 | #include <linux/types.h> | ||
17 | |||
18 | struct device; | ||
19 | |||
20 | enum dev_prop_type { | ||
21 | DEV_PROP_U8, | ||
22 | DEV_PROP_U16, | ||
23 | DEV_PROP_U32, | ||
24 | DEV_PROP_U64, | ||
25 | DEV_PROP_STRING, | ||
26 | DEV_PROP_MAX, | ||
27 | }; | ||
28 | |||
29 | bool device_property_present(struct device *dev, const char *propname); | ||
30 | int device_property_read_u8_array(struct device *dev, const char *propname, | ||
31 | u8 *val, size_t nval); | ||
32 | int device_property_read_u16_array(struct device *dev, const char *propname, | ||
33 | u16 *val, size_t nval); | ||
34 | int device_property_read_u32_array(struct device *dev, const char *propname, | ||
35 | u32 *val, size_t nval); | ||
36 | int device_property_read_u64_array(struct device *dev, const char *propname, | ||
37 | u64 *val, size_t nval); | ||
38 | int device_property_read_string_array(struct device *dev, const char *propname, | ||
39 | const char **val, size_t nval); | ||
40 | int device_property_read_string(struct device *dev, const char *propname, | ||
41 | const char **val); | ||
42 | |||
43 | enum fwnode_type { | ||
44 | FWNODE_INVALID = 0, | ||
45 | FWNODE_OF, | ||
46 | FWNODE_ACPI, | ||
47 | }; | ||
48 | |||
49 | struct fwnode_handle { | ||
50 | enum fwnode_type type; | ||
51 | }; | ||
52 | |||
53 | bool fwnode_property_present(struct fwnode_handle *fwnode, const char *propname); | ||
54 | int fwnode_property_read_u8_array(struct fwnode_handle *fwnode, | ||
55 | const char *propname, u8 *val, | ||
56 | size_t nval); | ||
57 | int fwnode_property_read_u16_array(struct fwnode_handle *fwnode, | ||
58 | const char *propname, u16 *val, | ||
59 | size_t nval); | ||
60 | int fwnode_property_read_u32_array(struct fwnode_handle *fwnode, | ||
61 | const char *propname, u32 *val, | ||
62 | size_t nval); | ||
63 | int fwnode_property_read_u64_array(struct fwnode_handle *fwnode, | ||
64 | const char *propname, u64 *val, | ||
65 | size_t nval); | ||
66 | int fwnode_property_read_string_array(struct fwnode_handle *fwnode, | ||
67 | const char *propname, const char **val, | ||
68 | size_t nval); | ||
69 | int fwnode_property_read_string(struct fwnode_handle *fwnode, | ||
70 | const char *propname, const char **val); | ||
71 | |||
72 | struct 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 | |||
79 | void fwnode_handle_put(struct fwnode_handle *fwnode); | ||
80 | |||
81 | unsigned int device_get_child_node_count(struct device *dev); | ||
82 | |||
83 | static inline bool device_property_read_bool(struct device *dev, | ||
84 | const char *propname) | ||
85 | { | ||
86 | return device_property_present(dev, propname); | ||
87 | } | ||
88 | |||
89 | static inline int device_property_read_u8(struct device *dev, | ||
90 | const char *propname, u8 *val) | ||
91 | { | ||
92 | return device_property_read_u8_array(dev, propname, val, 1); | ||
93 | } | ||
94 | |||
95 | static inline int device_property_read_u16(struct device *dev, | ||
96 | const char *propname, u16 *val) | ||
97 | { | ||
98 | return device_property_read_u16_array(dev, propname, val, 1); | ||
99 | } | ||
100 | |||
101 | static inline int device_property_read_u32(struct device *dev, | ||
102 | const char *propname, u32 *val) | ||
103 | { | ||
104 | return device_property_read_u32_array(dev, propname, val, 1); | ||
105 | } | ||
106 | |||
107 | static inline int device_property_read_u64(struct device *dev, | ||
108 | const char *propname, u64 *val) | ||
109 | { | ||
110 | return device_property_read_u64_array(dev, propname, val, 1); | ||
111 | } | ||
112 | |||
113 | static inline bool fwnode_property_read_bool(struct fwnode_handle *fwnode, | ||
114 | const char *propname) | ||
115 | { | ||
116 | return fwnode_property_present(fwnode, propname); | ||
117 | } | ||
118 | |||
119 | static 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 | |||
125 | static 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 | |||
131 | static 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 | |||
137 | static 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 | |||
143 | #endif /* _LINUX_PROPERTY_H_ */ | ||