mfd: axp20x: Add AXP22x PMIC support
[linux-2.6/btrfs-unstable.git] / include / linux / property.h
blobde8bdf417a35adc745e37fc1df1de7453d518895
1 /*
2 * property.h - Unified device property interface.
4 * Copyright (C) 2014, Intel Corporation
5 * Authors: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
6 * Mika Westerberg <mika.westerberg@linux.intel.com>
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.
13 #ifndef _LINUX_PROPERTY_H_
14 #define _LINUX_PROPERTY_H_
16 #include <linux/fwnode.h>
17 #include <linux/types.h>
19 struct device;
21 enum dev_prop_type {
22 DEV_PROP_U8,
23 DEV_PROP_U16,
24 DEV_PROP_U32,
25 DEV_PROP_U64,
26 DEV_PROP_STRING,
27 DEV_PROP_MAX,
30 bool device_property_present(struct device *dev, const char *propname);
31 int device_property_read_u8_array(struct device *dev, const char *propname,
32 u8 *val, size_t nval);
33 int device_property_read_u16_array(struct device *dev, const char *propname,
34 u16 *val, size_t nval);
35 int device_property_read_u32_array(struct device *dev, const char *propname,
36 u32 *val, size_t nval);
37 int device_property_read_u64_array(struct device *dev, const char *propname,
38 u64 *val, size_t nval);
39 int device_property_read_string_array(struct device *dev, const char *propname,
40 const char **val, size_t nval);
41 int device_property_read_string(struct device *dev, const char *propname,
42 const char **val);
44 bool fwnode_property_present(struct fwnode_handle *fwnode, const char *propname);
45 int fwnode_property_read_u8_array(struct fwnode_handle *fwnode,
46 const char *propname, u8 *val,
47 size_t nval);
48 int fwnode_property_read_u16_array(struct fwnode_handle *fwnode,
49 const char *propname, u16 *val,
50 size_t nval);
51 int fwnode_property_read_u32_array(struct fwnode_handle *fwnode,
52 const char *propname, u32 *val,
53 size_t nval);
54 int fwnode_property_read_u64_array(struct fwnode_handle *fwnode,
55 const char *propname, u64 *val,
56 size_t nval);
57 int fwnode_property_read_string_array(struct fwnode_handle *fwnode,
58 const char *propname, const char **val,
59 size_t nval);
60 int fwnode_property_read_string(struct fwnode_handle *fwnode,
61 const char *propname, const char **val);
63 struct fwnode_handle *device_get_next_child_node(struct device *dev,
64 struct fwnode_handle *child);
66 #define device_for_each_child_node(dev, child) \
67 for (child = device_get_next_child_node(dev, NULL); child; \
68 child = device_get_next_child_node(dev, child))
70 void fwnode_handle_put(struct fwnode_handle *fwnode);
72 unsigned int device_get_child_node_count(struct device *dev);
74 static inline bool device_property_read_bool(struct device *dev,
75 const char *propname)
77 return device_property_present(dev, propname);
80 static inline int device_property_read_u8(struct device *dev,
81 const char *propname, u8 *val)
83 return device_property_read_u8_array(dev, propname, val, 1);
86 static inline int device_property_read_u16(struct device *dev,
87 const char *propname, u16 *val)
89 return device_property_read_u16_array(dev, propname, val, 1);
92 static inline int device_property_read_u32(struct device *dev,
93 const char *propname, u32 *val)
95 return device_property_read_u32_array(dev, propname, val, 1);
98 static inline int device_property_read_u64(struct device *dev,
99 const char *propname, u64 *val)
101 return device_property_read_u64_array(dev, propname, val, 1);
104 static inline bool fwnode_property_read_bool(struct fwnode_handle *fwnode,
105 const char *propname)
107 return fwnode_property_present(fwnode, propname);
110 static inline int fwnode_property_read_u8(struct fwnode_handle *fwnode,
111 const char *propname, u8 *val)
113 return fwnode_property_read_u8_array(fwnode, propname, val, 1);
116 static inline int fwnode_property_read_u16(struct fwnode_handle *fwnode,
117 const char *propname, u16 *val)
119 return fwnode_property_read_u16_array(fwnode, propname, val, 1);
122 static inline int fwnode_property_read_u32(struct fwnode_handle *fwnode,
123 const char *propname, u32 *val)
125 return fwnode_property_read_u32_array(fwnode, propname, val, 1);
128 static inline int fwnode_property_read_u64(struct fwnode_handle *fwnode,
129 const char *propname, u64 *val)
131 return fwnode_property_read_u64_array(fwnode, propname, val, 1);
135 * struct property_entry - "Built-in" device property representation.
136 * @name: Name of the property.
137 * @type: Type of the property.
138 * @nval: Number of items of type @type making up the value.
139 * @value: Value of the property (an array of @nval items of type @type).
141 struct property_entry {
142 const char *name;
143 enum dev_prop_type type;
144 size_t nval;
145 union {
146 void *raw_data;
147 u8 *u8_data;
148 u16 *u16_data;
149 u32 *u32_data;
150 u64 *u64_data;
151 const char **str;
152 } value;
156 * struct property_set - Collection of "built-in" device properties.
157 * @fwnode: Handle to be pointed to by the fwnode field of struct device.
158 * @properties: Array of properties terminated with a null entry.
160 struct property_set {
161 struct fwnode_handle fwnode;
162 struct property_entry *properties;
165 void device_add_property_set(struct device *dev, struct property_set *pset);
167 #endif /* _LINUX_PROPERTY_H_ */