platform/x86: intel_cht_int33fe: Replacing the old connections with references
[linux-2.6-block.git] / include / linux / property.h
CommitLineData
b31384fa
RW
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
0fcc2bdc 16#include <linux/bits.h>
ce793486 17#include <linux/fwnode.h>
b31384fa
RW
18#include <linux/types.h>
19
20struct device;
21
22enum dev_prop_type {
23 DEV_PROP_U8,
24 DEV_PROP_U16,
25 DEV_PROP_U32,
26 DEV_PROP_U64,
27 DEV_PROP_STRING,
28 DEV_PROP_MAX,
29};
30
1b9863c6
SS
31enum dev_dma_attr {
32 DEV_DMA_NOT_SUPPORTED,
33 DEV_DMA_NON_COHERENT,
34 DEV_DMA_COHERENT,
35};
36
e44bb0cb
SA
37struct fwnode_handle *dev_fwnode(struct device *dev);
38
b31384fa
RW
39bool device_property_present(struct device *dev, const char *propname);
40int device_property_read_u8_array(struct device *dev, const char *propname,
41 u8 *val, size_t nval);
42int device_property_read_u16_array(struct device *dev, const char *propname,
43 u16 *val, size_t nval);
44int device_property_read_u32_array(struct device *dev, const char *propname,
45 u32 *val, size_t nval);
46int device_property_read_u64_array(struct device *dev, const char *propname,
47 u64 *val, size_t nval);
48int device_property_read_string_array(struct device *dev, const char *propname,
49 const char **val, size_t nval);
50int device_property_read_string(struct device *dev, const char *propname,
51 const char **val);
3f5c8d31
MW
52int device_property_match_string(struct device *dev,
53 const char *propname, const char *string);
b31384fa 54
37ba983c
SA
55bool fwnode_device_is_available(const struct fwnode_handle *fwnode);
56bool fwnode_property_present(const struct fwnode_handle *fwnode,
57 const char *propname);
58int fwnode_property_read_u8_array(const struct fwnode_handle *fwnode,
8a0662d9
RW
59 const char *propname, u8 *val,
60 size_t nval);
37ba983c 61int fwnode_property_read_u16_array(const struct fwnode_handle *fwnode,
8a0662d9
RW
62 const char *propname, u16 *val,
63 size_t nval);
37ba983c 64int fwnode_property_read_u32_array(const struct fwnode_handle *fwnode,
8a0662d9
RW
65 const char *propname, u32 *val,
66 size_t nval);
37ba983c 67int fwnode_property_read_u64_array(const struct fwnode_handle *fwnode,
8a0662d9
RW
68 const char *propname, u64 *val,
69 size_t nval);
37ba983c 70int fwnode_property_read_string_array(const struct fwnode_handle *fwnode,
8a0662d9
RW
71 const char *propname, const char **val,
72 size_t nval);
37ba983c 73int fwnode_property_read_string(const struct fwnode_handle *fwnode,
8a0662d9 74 const char *propname, const char **val);
37ba983c 75int fwnode_property_match_string(const struct fwnode_handle *fwnode,
3f5c8d31 76 const char *propname, const char *string);
3e3119d3
SA
77int fwnode_property_get_reference_args(const struct fwnode_handle *fwnode,
78 const char *prop, const char *nargs_prop,
79 unsigned int nargs, unsigned int index,
80 struct fwnode_reference_args *args);
8a0662d9 81
83b34afb
HK
82struct fwnode_handle *fwnode_find_reference(const struct fwnode_handle *fwnode,
83 const char *name,
84 unsigned int index);
85
37ba983c
SA
86struct fwnode_handle *fwnode_get_parent(const struct fwnode_handle *fwnode);
87struct fwnode_handle *fwnode_get_next_parent(
88 struct fwnode_handle *fwnode);
89struct fwnode_handle *fwnode_get_next_child_node(
90 const struct fwnode_handle *fwnode, struct fwnode_handle *child);
3395de96
MW
91struct fwnode_handle *fwnode_get_next_available_child_node(
92 const struct fwnode_handle *fwnode, struct fwnode_handle *child);
34055190
MW
93
94#define fwnode_for_each_child_node(fwnode, child) \
95 for (child = fwnode_get_next_child_node(fwnode, NULL); child; \
96 child = fwnode_get_next_child_node(fwnode, child))
afaf26fd 97
3395de96
MW
98#define fwnode_for_each_available_child_node(fwnode, child) \
99 for (child = fwnode_get_next_available_child_node(fwnode, NULL); child;\
100 child = fwnode_get_next_available_child_node(fwnode, child))
101
37ba983c
SA
102struct fwnode_handle *device_get_next_child_node(
103 struct device *dev, struct fwnode_handle *child);
8a0662d9 104
1d656fb7
AS
105#define device_for_each_child_node(dev, child) \
106 for (child = device_get_next_child_node(dev, NULL); child; \
8a0662d9
RW
107 child = device_get_next_child_node(dev, child))
108
37ba983c
SA
109struct fwnode_handle *fwnode_get_named_child_node(
110 const struct fwnode_handle *fwnode, const char *childname);
613e9721
AT
111struct fwnode_handle *device_get_named_child_node(struct device *dev,
112 const char *childname);
113
cf89a31c 114struct fwnode_handle *fwnode_handle_get(struct fwnode_handle *fwnode);
8a0662d9
RW
115void fwnode_handle_put(struct fwnode_handle *fwnode);
116
7c6c57f2
MW
117int fwnode_irq_get(struct fwnode_handle *fwnode, unsigned int index);
118
8a0662d9
RW
119unsigned int device_get_child_node_count(struct device *dev);
120
b31384fa
RW
121static inline bool device_property_read_bool(struct device *dev,
122 const char *propname)
123{
124 return device_property_present(dev, propname);
125}
126
127static inline int device_property_read_u8(struct device *dev,
128 const char *propname, u8 *val)
129{
130 return device_property_read_u8_array(dev, propname, val, 1);
131}
132
133static inline int device_property_read_u16(struct device *dev,
134 const char *propname, u16 *val)
135{
136 return device_property_read_u16_array(dev, propname, val, 1);
137}
138
139static inline int device_property_read_u32(struct device *dev,
140 const char *propname, u32 *val)
141{
142 return device_property_read_u32_array(dev, propname, val, 1);
143}
144
145static inline int device_property_read_u64(struct device *dev,
146 const char *propname, u64 *val)
147{
148 return device_property_read_u64_array(dev, propname, val, 1);
149}
150
37ba983c 151static inline bool fwnode_property_read_bool(const struct fwnode_handle *fwnode,
8a0662d9
RW
152 const char *propname)
153{
154 return fwnode_property_present(fwnode, propname);
155}
156
37ba983c 157static inline int fwnode_property_read_u8(const struct fwnode_handle *fwnode,
8a0662d9
RW
158 const char *propname, u8 *val)
159{
160 return fwnode_property_read_u8_array(fwnode, propname, val, 1);
161}
162
37ba983c 163static inline int fwnode_property_read_u16(const struct fwnode_handle *fwnode,
8a0662d9
RW
164 const char *propname, u16 *val)
165{
166 return fwnode_property_read_u16_array(fwnode, propname, val, 1);
167}
168
37ba983c 169static inline int fwnode_property_read_u32(const struct fwnode_handle *fwnode,
8a0662d9
RW
170 const char *propname, u32 *val)
171{
172 return fwnode_property_read_u32_array(fwnode, propname, val, 1);
173}
174
37ba983c 175static inline int fwnode_property_read_u64(const struct fwnode_handle *fwnode,
8a0662d9
RW
176 const char *propname, u64 *val)
177{
178 return fwnode_property_read_u64_array(fwnode, propname, val, 1);
179}
180
16ba08d5
RW
181/**
182 * struct property_entry - "Built-in" device property representation.
183 * @name: Name of the property.
318a1971 184 * @length: Length of data making up the value.
66586bab 185 * @is_array: True when the property is an array.
63dcc709 186 * @type: Type of the data in unions.
66586bab
AS
187 * @pointer: Pointer to the property (an array of items of the given type).
188 * @value: Value of the property (when it is a single item of the given type).
16ba08d5
RW
189 */
190struct property_entry {
191 const char *name;
318a1971 192 size_t length;
66586bab 193 bool is_array;
63dcc709 194 enum dev_prop_type type;
16ba08d5 195 union {
66586bab 196 union {
9426998c
DT
197 const u8 *u8_data;
198 const u16 *u16_data;
199 const u32 *u32_data;
200 const u64 *u64_data;
201 const char * const *str;
66586bab
AS
202 } pointer;
203 union {
66586bab
AS
204 u8 u8_data;
205 u16 u16_data;
206 u32 u32_data;
207 u64 u64_data;
208 const char *str;
209 } value;
210 };
16ba08d5
RW
211};
212
d76eebfa
AM
213/*
214 * Note: the below four initializers for the anonymous union are carefully
215 * crafted to avoid gcc-4.4.4's problems with initialization of anon unions
216 * and structs.
217 */
218
63dcc709
AS
219#define PROPERTY_ENTRY_INTEGER_ARRAY(_name_, _type_, _Type_, _val_) \
220(struct property_entry) { \
221 .name = _name_, \
222 .length = ARRAY_SIZE(_val_) * sizeof(_type_), \
223 .is_array = true, \
224 .type = DEV_PROP_##_Type_, \
225 { .pointer = { ._type_##_data = _val_ } }, \
a85f4204
HK
226}
227
228#define PROPERTY_ENTRY_U8_ARRAY(_name_, _val_) \
63dcc709 229 PROPERTY_ENTRY_INTEGER_ARRAY(_name_, u8, U8, _val_)
a85f4204 230#define PROPERTY_ENTRY_U16_ARRAY(_name_, _val_) \
63dcc709 231 PROPERTY_ENTRY_INTEGER_ARRAY(_name_, u16, U16, _val_)
a85f4204 232#define PROPERTY_ENTRY_U32_ARRAY(_name_, _val_) \
63dcc709 233 PROPERTY_ENTRY_INTEGER_ARRAY(_name_, u32, U32, _val_)
a85f4204 234#define PROPERTY_ENTRY_U64_ARRAY(_name_, _val_) \
63dcc709 235 PROPERTY_ENTRY_INTEGER_ARRAY(_name_, u64, U64, _val_)
a85f4204
HK
236
237#define PROPERTY_ENTRY_STRING_ARRAY(_name_, _val_) \
c505cbd4 238(struct property_entry) { \
a85f4204
HK
239 .name = _name_, \
240 .length = ARRAY_SIZE(_val_) * sizeof(const char *), \
241 .is_array = true, \
63dcc709 242 .type = DEV_PROP_STRING, \
d76eebfa 243 { .pointer = { .str = _val_ } }, \
a85f4204
HK
244}
245
63dcc709
AS
246#define PROPERTY_ENTRY_INTEGER(_name_, _type_, _Type_, _val_) \
247(struct property_entry) { \
248 .name = _name_, \
249 .length = sizeof(_type_), \
250 .type = DEV_PROP_##_Type_, \
251 { .value = { ._type_##_data = _val_ } }, \
a85f4204
HK
252}
253
254#define PROPERTY_ENTRY_U8(_name_, _val_) \
63dcc709 255 PROPERTY_ENTRY_INTEGER(_name_, u8, U8, _val_)
a85f4204 256#define PROPERTY_ENTRY_U16(_name_, _val_) \
63dcc709 257 PROPERTY_ENTRY_INTEGER(_name_, u16, U16, _val_)
a85f4204 258#define PROPERTY_ENTRY_U32(_name_, _val_) \
63dcc709 259 PROPERTY_ENTRY_INTEGER(_name_, u32, U32, _val_)
a85f4204 260#define PROPERTY_ENTRY_U64(_name_, _val_) \
63dcc709 261 PROPERTY_ENTRY_INTEGER(_name_, u64, U64, _val_)
a85f4204
HK
262
263#define PROPERTY_ENTRY_STRING(_name_, _val_) \
c505cbd4 264(struct property_entry) { \
a85f4204 265 .name = _name_, \
2b6e4924 266 .length = sizeof(const char *), \
63dcc709 267 .type = DEV_PROP_STRING, \
aace7367 268 { .value = { .str = _val_ } }, \
a85f4204
HK
269}
270
271#define PROPERTY_ENTRY_BOOL(_name_) \
c505cbd4 272(struct property_entry) { \
a85f4204
HK
273 .name = _name_, \
274}
275
2d479e1f
DT
276struct property_entry *
277property_entries_dup(const struct property_entry *properties);
278
279void property_entries_free(const struct property_entry *properties);
280
f4d05266 281int device_add_properties(struct device *dev,
bec84da8 282 const struct property_entry *properties);
f4d05266 283void device_remove_properties(struct device *dev);
16ba08d5 284
e5e55864
SS
285bool device_dma_supported(struct device *dev);
286
287enum dev_dma_attr device_get_dma_attr(struct device *dev);
b283f157 288
67dcc26d 289const void *device_get_match_data(struct device *dev);
e5e55864 290
4c96b7dc
JL
291int device_get_phy_mode(struct device *dev);
292
293void *device_get_mac_address(struct device *dev, char *addr, int alen);
294
b28f263b 295int fwnode_get_phy_mode(struct fwnode_handle *fwnode);
babe2dbb
MW
296void *fwnode_get_mac_address(struct fwnode_handle *fwnode,
297 char *addr, int alen);
07bb80d4 298struct fwnode_handle *fwnode_graph_get_next_endpoint(
37ba983c 299 const struct fwnode_handle *fwnode, struct fwnode_handle *prev);
6a71d8d7 300struct fwnode_handle *
37ba983c 301fwnode_graph_get_port_parent(const struct fwnode_handle *fwnode);
07bb80d4 302struct fwnode_handle *fwnode_graph_get_remote_port_parent(
37ba983c 303 const struct fwnode_handle *fwnode);
07bb80d4 304struct fwnode_handle *fwnode_graph_get_remote_port(
37ba983c 305 const struct fwnode_handle *fwnode);
07bb80d4 306struct fwnode_handle *fwnode_graph_get_remote_endpoint(
37ba983c
SA
307 const struct fwnode_handle *fwnode);
308struct fwnode_handle *
309fwnode_graph_get_remote_node(const struct fwnode_handle *fwnode, u32 port,
310 u32 endpoint);
07bb80d4 311
0fcc2bdc
SA
312/*
313 * Fwnode lookup flags
314 *
315 * @FWNODE_GRAPH_ENDPOINT_NEXT: In the case of no exact match, look for the
316 * closest endpoint ID greater than the specified
317 * one.
318 * @FWNODE_GRAPH_DEVICE_DISABLED: That the device to which the remote
319 * endpoint of the given endpoint belongs to,
320 * may be disabled.
321 */
322#define FWNODE_GRAPH_ENDPOINT_NEXT BIT(0)
323#define FWNODE_GRAPH_DEVICE_DISABLED BIT(1)
324
325struct fwnode_handle *
326fwnode_graph_get_endpoint_by_id(const struct fwnode_handle *fwnode,
327 u32 port, u32 endpoint, unsigned long flags);
328
5e4b1b70
SA
329#define fwnode_graph_for_each_endpoint(fwnode, child) \
330 for (child = NULL; \
331 (child = fwnode_graph_get_next_endpoint(fwnode, child)); )
332
37ba983c 333int fwnode_graph_parse_endpoint(const struct fwnode_handle *fwnode,
2bd5452d
SA
334 struct fwnode_endpoint *endpoint);
335
59abd836
HK
336/* -------------------------------------------------------------------------- */
337/* Software fwnode support - when HW description is incomplete or missing */
338
b06184ac
HK
339struct software_node;
340
341/**
342 * struct software_node_ref_args - Reference with additional arguments
343 * @node: Reference to a software node
344 * @nargs: Number of elements in @args array
345 * @args: Integer arguments
346 */
347struct software_node_ref_args {
348 const struct software_node *node;
349 unsigned int nargs;
350 u64 args[NR_FWNODE_REFERENCE_ARGS];
351};
352
353/**
354 * struct software_node_reference - Named software node reference property
355 * @name: Name of the property
356 * @nrefs: Number of elements in @refs array
357 * @refs: Array of references with optional arguments
358 */
359struct software_node_reference {
360 const char *name;
361 unsigned int nrefs;
362 const struct software_node_ref_args *refs;
363};
364
80488a6b
HK
365/**
366 * struct software_node - Software node description
367 * @name: Name of the software node
368 * @parent: Parent of the software node
369 * @properties: Array of device properties
b06184ac 370 * @references: Array of software node reference properties
80488a6b
HK
371 */
372struct software_node {
373 const char *name;
374 const struct software_node *parent;
375 const struct property_entry *properties;
b06184ac 376 const struct software_node_reference *references;
80488a6b
HK
377};
378
59abd836 379bool is_software_node(const struct fwnode_handle *fwnode);
80488a6b
HK
380const struct software_node *to_software_node(struct fwnode_handle *fwnode);
381struct fwnode_handle *software_node_fwnode(const struct software_node *node);
382
383int software_node_register_nodes(const struct software_node *nodes);
384void software_node_unregister_nodes(const struct software_node *nodes);
385
386int software_node_register(const struct software_node *node);
59abd836
HK
387
388int software_node_notify(struct device *dev, unsigned long action);
389
390struct fwnode_handle *
391fwnode_create_software_node(const struct property_entry *properties,
392 const struct fwnode_handle *parent);
393void fwnode_remove_software_node(struct fwnode_handle *fwnode);
394
b31384fa 395#endif /* _LINUX_PROPERTY_H_ */