blob: 4cd4b326941f1336ecc52b0531ac250a700398e1 [file] [log] [blame]
Thomas Gleixnerd2912cb2019-06-04 10:11:33 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Rafael J. Wysockib31384f2014-11-04 01:28:56 +01002/*
3 * property.h - Unified device property interface.
4 *
5 * Copyright (C) 2014, Intel Corporation
6 * Authors: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
7 * Mika Westerberg <mika.westerberg@linux.intel.com>
Rafael J. Wysockib31384f2014-11-04 01:28:56 +01008 */
9
10#ifndef _LINUX_PROPERTY_H_
11#define _LINUX_PROPERTY_H_
12
Sakari Ailus0fcc2bd2019-04-02 13:30:37 +030013#include <linux/bits.h>
Rafael J. Wysockice793482015-03-16 23:49:03 +010014#include <linux/fwnode.h>
Rafael J. Wysockib31384f2014-11-04 01:28:56 +010015#include <linux/types.h>
16
17struct device;
Jakub Kicinskid9eb4492021-10-06 18:07:00 -070018struct net_device;
Rafael J. Wysockib31384f2014-11-04 01:28:56 +010019
20enum dev_prop_type {
21 DEV_PROP_U8,
22 DEV_PROP_U16,
23 DEV_PROP_U32,
24 DEV_PROP_U64,
25 DEV_PROP_STRING,
Dmitry Torokhove64b6742019-11-07 20:22:22 -080026 DEV_PROP_REF,
Rafael J. Wysockib31384f2014-11-04 01:28:56 +010027};
28
Suthikulpanit, Suravee1b9863c2015-10-28 15:50:47 -070029enum dev_dma_attr {
30 DEV_DMA_NOT_SUPPORTED,
31 DEV_DMA_NON_COHERENT,
32 DEV_DMA_COHERENT,
33};
34
Sakari Ailuse44bb0c2017-03-28 10:52:24 +030035struct fwnode_handle *dev_fwnode(struct device *dev);
36
Rafael J. Wysockib31384f2014-11-04 01:28:56 +010037bool device_property_present(struct device *dev, const char *propname);
38int device_property_read_u8_array(struct device *dev, const char *propname,
39 u8 *val, size_t nval);
40int device_property_read_u16_array(struct device *dev, const char *propname,
41 u16 *val, size_t nval);
42int device_property_read_u32_array(struct device *dev, const char *propname,
43 u32 *val, size_t nval);
44int device_property_read_u64_array(struct device *dev, const char *propname,
45 u64 *val, size_t nval);
46int device_property_read_string_array(struct device *dev, const char *propname,
47 const char **val, size_t nval);
48int device_property_read_string(struct device *dev, const char *propname,
49 const char **val);
Mika Westerberg3f5c8d32015-09-14 17:37:35 +030050int device_property_match_string(struct device *dev,
51 const char *propname, const char *string);
Rafael J. Wysockib31384f2014-11-04 01:28:56 +010052
Sakari Ailus37ba9832017-07-21 14:39:36 +030053bool fwnode_device_is_available(const struct fwnode_handle *fwnode);
54bool fwnode_property_present(const struct fwnode_handle *fwnode,
55 const char *propname);
56int fwnode_property_read_u8_array(const struct fwnode_handle *fwnode,
Rafael J. Wysocki8a0662d2014-11-04 14:03:59 +010057 const char *propname, u8 *val,
58 size_t nval);
Sakari Ailus37ba9832017-07-21 14:39:36 +030059int fwnode_property_read_u16_array(const struct fwnode_handle *fwnode,
Rafael J. Wysocki8a0662d2014-11-04 14:03:59 +010060 const char *propname, u16 *val,
61 size_t nval);
Sakari Ailus37ba9832017-07-21 14:39:36 +030062int fwnode_property_read_u32_array(const struct fwnode_handle *fwnode,
Rafael J. Wysocki8a0662d2014-11-04 14:03:59 +010063 const char *propname, u32 *val,
64 size_t nval);
Sakari Ailus37ba9832017-07-21 14:39:36 +030065int fwnode_property_read_u64_array(const struct fwnode_handle *fwnode,
Rafael J. Wysocki8a0662d2014-11-04 14:03:59 +010066 const char *propname, u64 *val,
67 size_t nval);
Sakari Ailus37ba9832017-07-21 14:39:36 +030068int fwnode_property_read_string_array(const struct fwnode_handle *fwnode,
Rafael J. Wysocki8a0662d2014-11-04 14:03:59 +010069 const char *propname, const char **val,
70 size_t nval);
Sakari Ailus37ba9832017-07-21 14:39:36 +030071int fwnode_property_read_string(const struct fwnode_handle *fwnode,
Rafael J. Wysocki8a0662d2014-11-04 14:03:59 +010072 const char *propname, const char **val);
Sakari Ailus37ba9832017-07-21 14:39:36 +030073int fwnode_property_match_string(const struct fwnode_handle *fwnode,
Mika Westerberg3f5c8d32015-09-14 17:37:35 +030074 const char *propname, const char *string);
Sakari Ailus3e3119d2017-07-21 15:11:49 +030075int fwnode_property_get_reference_args(const struct fwnode_handle *fwnode,
76 const char *prop, const char *nargs_prop,
77 unsigned int nargs, unsigned int index,
78 struct fwnode_reference_args *args);
Rafael J. Wysocki8a0662d2014-11-04 14:03:59 +010079
Heikki Krogerus83b34af2019-05-31 17:15:39 +030080struct fwnode_handle *fwnode_find_reference(const struct fwnode_handle *fwnode,
81 const char *name,
82 unsigned int index);
83
Sakari Ailusbc0500c2019-10-03 15:32:12 +030084const char *fwnode_get_name(const struct fwnode_handle *fwnode);
Sakari Ailuse7e242b2019-10-03 15:32:13 +030085const char *fwnode_get_name_prefix(const struct fwnode_handle *fwnode);
Sakari Ailus37ba9832017-07-21 14:39:36 +030086struct fwnode_handle *fwnode_get_parent(const struct fwnode_handle *fwnode);
87struct fwnode_handle *fwnode_get_next_parent(
88 struct fwnode_handle *fwnode);
Saravana Kannanb5d3e2f2020-11-20 18:02:25 -080089struct device *fwnode_get_next_parent_dev(struct fwnode_handle *fwnode);
Sakari Ailus87e5e952019-10-03 15:32:11 +030090unsigned int fwnode_count_parents(const struct fwnode_handle *fwn);
91struct fwnode_handle *fwnode_get_nth_parent(struct fwnode_handle *fwn,
92 unsigned int depth);
Saravana Kannanb5d3e2f2020-11-20 18:02:25 -080093bool fwnode_is_ancestor_of(struct fwnode_handle *test_ancestor,
94 struct fwnode_handle *test_child);
Sakari Ailus37ba9832017-07-21 14:39:36 +030095struct fwnode_handle *fwnode_get_next_child_node(
96 const struct fwnode_handle *fwnode, struct fwnode_handle *child);
Marcin Wojtas3395de96a2018-01-18 13:31:41 +010097struct fwnode_handle *fwnode_get_next_available_child_node(
98 const struct fwnode_handle *fwnode, struct fwnode_handle *child);
Mika Westerberg34055192017-03-28 10:52:18 +030099
100#define fwnode_for_each_child_node(fwnode, child) \
101 for (child = fwnode_get_next_child_node(fwnode, NULL); child; \
102 child = fwnode_get_next_child_node(fwnode, child))
Mika Westerbergafaf26f2017-03-28 10:52:17 +0300103
Marcin Wojtas3395de96a2018-01-18 13:31:41 +0100104#define fwnode_for_each_available_child_node(fwnode, child) \
105 for (child = fwnode_get_next_available_child_node(fwnode, NULL); child;\
106 child = fwnode_get_next_available_child_node(fwnode, child))
107
Sakari Ailus37ba9832017-07-21 14:39:36 +0300108struct fwnode_handle *device_get_next_child_node(
109 struct device *dev, struct fwnode_handle *child);
Rafael J. Wysocki8a0662d2014-11-04 14:03:59 +0100110
Andy Shevchenko1d656fb2015-11-30 17:11:34 +0200111#define device_for_each_child_node(dev, child) \
112 for (child = device_get_next_child_node(dev, NULL); child; \
Rafael J. Wysocki8a0662d2014-11-04 14:03:59 +0100113 child = device_get_next_child_node(dev, child))
114
Sakari Ailus37ba9832017-07-21 14:39:36 +0300115struct fwnode_handle *fwnode_get_named_child_node(
116 const struct fwnode_handle *fwnode, const char *childname);
Adam Thomson613e9722016-06-21 18:50:20 +0100117struct fwnode_handle *device_get_named_child_node(struct device *dev,
118 const char *childname);
119
Sakari Ailuscf89a312017-09-19 12:39:11 +0300120struct fwnode_handle *fwnode_handle_get(struct fwnode_handle *fwnode);
Rafael J. Wysocki8a0662d2014-11-04 14:03:59 +0100121void fwnode_handle_put(struct fwnode_handle *fwnode);
122
Andy Shevchenkofb38f312021-06-04 19:50:47 +0300123int fwnode_irq_get(const struct fwnode_handle *fwnode, unsigned int index);
Akhil Rca0acb512022-01-28 17:14:25 +0530124int fwnode_irq_get_byname(const struct fwnode_handle *fwnode, const char *name);
Marcin Wojtas7c6c57f2018-01-18 13:31:40 +0100125
Rafael J. Wysocki8a0662d2014-11-04 14:03:59 +0100126unsigned int device_get_child_node_count(struct device *dev);
127
Rafael J. Wysockib31384f2014-11-04 01:28:56 +0100128static inline bool device_property_read_bool(struct device *dev,
129 const char *propname)
130{
131 return device_property_present(dev, propname);
132}
133
134static inline int device_property_read_u8(struct device *dev,
135 const char *propname, u8 *val)
136{
137 return device_property_read_u8_array(dev, propname, val, 1);
138}
139
140static inline int device_property_read_u16(struct device *dev,
141 const char *propname, u16 *val)
142{
143 return device_property_read_u16_array(dev, propname, val, 1);
144}
145
146static inline int device_property_read_u32(struct device *dev,
147 const char *propname, u32 *val)
148{
149 return device_property_read_u32_array(dev, propname, val, 1);
150}
151
152static inline int device_property_read_u64(struct device *dev,
153 const char *propname, u64 *val)
154{
155 return device_property_read_u64_array(dev, propname, val, 1);
156}
157
Andy Shevchenko33ee09c2019-06-13 19:59:51 +0300158static inline int device_property_count_u8(struct device *dev, const char *propname)
159{
160 return device_property_read_u8_array(dev, propname, NULL, 0);
161}
162
163static inline int device_property_count_u16(struct device *dev, const char *propname)
164{
165 return device_property_read_u16_array(dev, propname, NULL, 0);
166}
167
168static inline int device_property_count_u32(struct device *dev, const char *propname)
169{
170 return device_property_read_u32_array(dev, propname, NULL, 0);
171}
172
173static inline int device_property_count_u64(struct device *dev, const char *propname)
174{
175 return device_property_read_u64_array(dev, propname, NULL, 0);
176}
177
Bartosz Golaszewski6b6ff4a2020-09-09 10:54:24 +0200178static inline int device_property_string_array_count(struct device *dev,
179 const char *propname)
180{
181 return device_property_read_string_array(dev, propname, NULL, 0);
182}
183
Sakari Ailus37ba9832017-07-21 14:39:36 +0300184static inline bool fwnode_property_read_bool(const struct fwnode_handle *fwnode,
Rafael J. Wysocki8a0662d2014-11-04 14:03:59 +0100185 const char *propname)
186{
187 return fwnode_property_present(fwnode, propname);
188}
189
Sakari Ailus37ba9832017-07-21 14:39:36 +0300190static inline int fwnode_property_read_u8(const struct fwnode_handle *fwnode,
Rafael J. Wysocki8a0662d2014-11-04 14:03:59 +0100191 const char *propname, u8 *val)
192{
193 return fwnode_property_read_u8_array(fwnode, propname, val, 1);
194}
195
Sakari Ailus37ba9832017-07-21 14:39:36 +0300196static inline int fwnode_property_read_u16(const struct fwnode_handle *fwnode,
Rafael J. Wysocki8a0662d2014-11-04 14:03:59 +0100197 const char *propname, u16 *val)
198{
199 return fwnode_property_read_u16_array(fwnode, propname, val, 1);
200}
201
Sakari Ailus37ba9832017-07-21 14:39:36 +0300202static inline int fwnode_property_read_u32(const struct fwnode_handle *fwnode,
Rafael J. Wysocki8a0662d2014-11-04 14:03:59 +0100203 const char *propname, u32 *val)
204{
205 return fwnode_property_read_u32_array(fwnode, propname, val, 1);
206}
207
Sakari Ailus37ba9832017-07-21 14:39:36 +0300208static inline int fwnode_property_read_u64(const struct fwnode_handle *fwnode,
Rafael J. Wysocki8a0662d2014-11-04 14:03:59 +0100209 const char *propname, u64 *val)
210{
211 return fwnode_property_read_u64_array(fwnode, propname, val, 1);
212}
213
Andy Shevchenko33ee09c2019-06-13 19:59:51 +0300214static inline int fwnode_property_count_u8(const struct fwnode_handle *fwnode,
215 const char *propname)
216{
217 return fwnode_property_read_u8_array(fwnode, propname, NULL, 0);
218}
219
220static inline int fwnode_property_count_u16(const struct fwnode_handle *fwnode,
221 const char *propname)
222{
223 return fwnode_property_read_u16_array(fwnode, propname, NULL, 0);
224}
225
226static inline int fwnode_property_count_u32(const struct fwnode_handle *fwnode,
227 const char *propname)
228{
229 return fwnode_property_read_u32_array(fwnode, propname, NULL, 0);
230}
231
232static inline int fwnode_property_count_u64(const struct fwnode_handle *fwnode,
233 const char *propname)
234{
235 return fwnode_property_read_u64_array(fwnode, propname, NULL, 0);
236}
237
Bartosz Golaszewski6b6ff4a2020-09-09 10:54:24 +0200238static inline int
239fwnode_property_string_array_count(const struct fwnode_handle *fwnode,
240 const char *propname)
241{
242 return fwnode_property_read_string_array(fwnode, propname, NULL, 0);
243}
244
Dmitry Torokhove64b6742019-11-07 20:22:22 -0800245struct software_node;
246
247/**
248 * struct software_node_ref_args - Reference property with additional arguments
249 * @node: Reference to a software node
250 * @nargs: Number of elements in @args array
251 * @args: Integer arguments
252 */
253struct software_node_ref_args {
254 const struct software_node *node;
255 unsigned int nargs;
256 u64 args[NR_FWNODE_REFERENCE_ARGS];
257};
258
Andy Shevchenkoe588fea2021-03-29 18:12:06 +0300259#define SOFTWARE_NODE_REFERENCE(_ref_, ...) \
260(const struct software_node_ref_args) { \
261 .node = _ref_, \
262 .nargs = ARRAY_SIZE(((u64[]){ 0, ##__VA_ARGS__ })) - 1, \
263 .args = { __VA_ARGS__ }, \
264}
265
Rafael J. Wysocki16ba08d2015-04-03 16:05:11 +0200266/**
267 * struct property_entry - "Built-in" device property representation.
268 * @name: Name of the property.
Andy Shevchenko318a19712015-11-30 17:11:31 +0200269 * @length: Length of data making up the value.
Dmitry Torokhove6bff4662019-11-07 20:22:20 -0800270 * @is_inline: True when the property value is stored inline.
Andy Shevchenko63dcc702018-05-15 20:32:02 +0300271 * @type: Type of the data in unions.
Dmitry Torokhove6bff4662019-11-07 20:22:20 -0800272 * @pointer: Pointer to the property when it is not stored inline.
273 * @value: Value of the property when it is stored inline.
Rafael J. Wysocki16ba08d2015-04-03 16:05:11 +0200274 */
275struct property_entry {
276 const char *name;
Andy Shevchenko318a19712015-11-30 17:11:31 +0200277 size_t length;
Dmitry Torokhove6bff4662019-11-07 20:22:20 -0800278 bool is_inline;
Andy Shevchenko63dcc702018-05-15 20:32:02 +0300279 enum dev_prop_type type;
Rafael J. Wysocki16ba08d2015-04-03 16:05:11 +0200280 union {
Dmitry Torokhov1f74d702019-10-23 13:02:24 -0700281 const void *pointer;
Andy Shevchenko66586ba2015-11-30 17:11:32 +0200282 union {
Dmitry Torokhov996b0832019-11-07 20:22:21 -0800283 u8 u8_data[sizeof(u64) / sizeof(u8)];
284 u16 u16_data[sizeof(u64) / sizeof(u16)];
285 u32 u32_data[sizeof(u64) / sizeof(u32)];
286 u64 u64_data[sizeof(u64) / sizeof(u64)];
287 const char *str[sizeof(u64) / sizeof(char *)];
Andy Shevchenko66586ba2015-11-30 17:11:32 +0200288 } value;
289 };
Rafael J. Wysocki16ba08d2015-04-03 16:05:11 +0200290};
291
Andrew Mortond76eebf2016-01-01 02:07:09 +0100292/*
Dmitry Torokhovdaeba9b2019-10-23 13:02:26 -0700293 * Note: the below initializers for the anonymous union are carefully
Andrew Mortond76eebf2016-01-01 02:07:09 +0100294 * crafted to avoid gcc-4.4.4's problems with initialization of anon unions
295 * and structs.
296 */
297
Dmitry Torokhovdaeba9b2019-10-23 13:02:26 -0700298#define __PROPERTY_ENTRY_ELEMENT_SIZE(_elem_) \
Dmitry Torokhov996b0832019-11-07 20:22:21 -0800299 sizeof(((struct property_entry *)NULL)->value._elem_[0])
Dmitry Torokhovdaeba9b2019-10-23 13:02:26 -0700300
Dmitry Torokhove64b6742019-11-07 20:22:22 -0800301#define __PROPERTY_ENTRY_ARRAY_ELSIZE_LEN(_name_, _elsize_, _Type_, \
302 _val_, _len_) \
Andy Shevchenko63dcc702018-05-15 20:32:02 +0300303(struct property_entry) { \
304 .name = _name_, \
Dmitry Torokhove64b6742019-11-07 20:22:22 -0800305 .length = (_len_) * (_elsize_), \
Andy Shevchenko63dcc702018-05-15 20:32:02 +0300306 .type = DEV_PROP_##_Type_, \
Dmitry Torokhov1f74d702019-10-23 13:02:24 -0700307 { .pointer = _val_ }, \
Heikki Krogerusa85f4202015-11-30 17:11:33 +0200308}
309
Dmitry Torokhove64b6742019-11-07 20:22:22 -0800310#define __PROPERTY_ENTRY_ARRAY_LEN(_name_, _elem_, _Type_, _val_, _len_)\
311 __PROPERTY_ENTRY_ARRAY_ELSIZE_LEN(_name_, \
312 __PROPERTY_ENTRY_ELEMENT_SIZE(_elem_), \
313 _Type_, _val_, _len_)
314
Dmitry Torokhov1741cfa2019-10-23 13:02:20 -0700315#define PROPERTY_ENTRY_U8_ARRAY_LEN(_name_, _val_, _len_) \
Dmitry Torokhovdaeba9b2019-10-23 13:02:26 -0700316 __PROPERTY_ENTRY_ARRAY_LEN(_name_, u8_data, U8, _val_, _len_)
Dmitry Torokhov1741cfa2019-10-23 13:02:20 -0700317#define PROPERTY_ENTRY_U16_ARRAY_LEN(_name_, _val_, _len_) \
Dmitry Torokhovdaeba9b2019-10-23 13:02:26 -0700318 __PROPERTY_ENTRY_ARRAY_LEN(_name_, u16_data, U16, _val_, _len_)
Dmitry Torokhov1741cfa2019-10-23 13:02:20 -0700319#define PROPERTY_ENTRY_U32_ARRAY_LEN(_name_, _val_, _len_) \
Dmitry Torokhovdaeba9b2019-10-23 13:02:26 -0700320 __PROPERTY_ENTRY_ARRAY_LEN(_name_, u32_data, U32, _val_, _len_)
Dmitry Torokhov1741cfa2019-10-23 13:02:20 -0700321#define PROPERTY_ENTRY_U64_ARRAY_LEN(_name_, _val_, _len_) \
Dmitry Torokhovdaeba9b2019-10-23 13:02:26 -0700322 __PROPERTY_ENTRY_ARRAY_LEN(_name_, u64_data, U64, _val_, _len_)
Dmitry Torokhov1741cfa2019-10-23 13:02:20 -0700323#define PROPERTY_ENTRY_STRING_ARRAY_LEN(_name_, _val_, _len_) \
Dmitry Torokhovdaeba9b2019-10-23 13:02:26 -0700324 __PROPERTY_ENTRY_ARRAY_LEN(_name_, str, STRING, _val_, _len_)
Dmitry Torokhove64b6742019-11-07 20:22:22 -0800325#define PROPERTY_ENTRY_REF_ARRAY_LEN(_name_, _val_, _len_) \
326 __PROPERTY_ENTRY_ARRAY_ELSIZE_LEN(_name_, \
327 sizeof(struct software_node_ref_args), \
328 REF, _val_, _len_)
Heikki Krogerusa85f4202015-11-30 17:11:33 +0200329
Dmitry Torokhov1741cfa2019-10-23 13:02:20 -0700330#define PROPERTY_ENTRY_U8_ARRAY(_name_, _val_) \
331 PROPERTY_ENTRY_U8_ARRAY_LEN(_name_, _val_, ARRAY_SIZE(_val_))
332#define PROPERTY_ENTRY_U16_ARRAY(_name_, _val_) \
333 PROPERTY_ENTRY_U16_ARRAY_LEN(_name_, _val_, ARRAY_SIZE(_val_))
334#define PROPERTY_ENTRY_U32_ARRAY(_name_, _val_) \
335 PROPERTY_ENTRY_U32_ARRAY_LEN(_name_, _val_, ARRAY_SIZE(_val_))
336#define PROPERTY_ENTRY_U64_ARRAY(_name_, _val_) \
337 PROPERTY_ENTRY_U64_ARRAY_LEN(_name_, _val_, ARRAY_SIZE(_val_))
338#define PROPERTY_ENTRY_STRING_ARRAY(_name_, _val_) \
339 PROPERTY_ENTRY_STRING_ARRAY_LEN(_name_, _val_, ARRAY_SIZE(_val_))
Dmitry Torokhove64b6742019-11-07 20:22:22 -0800340#define PROPERTY_ENTRY_REF_ARRAY(_name_, _val_) \
341 PROPERTY_ENTRY_REF_ARRAY_LEN(_name_, _val_, ARRAY_SIZE(_val_))
Dmitry Torokhov1741cfa2019-10-23 13:02:20 -0700342
Dmitry Torokhovdaeba9b2019-10-23 13:02:26 -0700343#define __PROPERTY_ENTRY_ELEMENT(_name_, _elem_, _Type_, _val_) \
344(struct property_entry) { \
345 .name = _name_, \
346 .length = __PROPERTY_ENTRY_ELEMENT_SIZE(_elem_), \
Dmitry Torokhove6bff4662019-11-07 20:22:20 -0800347 .is_inline = true, \
Dmitry Torokhovdaeba9b2019-10-23 13:02:26 -0700348 .type = DEV_PROP_##_Type_, \
Dmitry Torokhov996b0832019-11-07 20:22:21 -0800349 { .value = { ._elem_[0] = _val_ } }, \
Heikki Krogerusa85f4202015-11-30 17:11:33 +0200350}
351
Dmitry Torokhovdaeba9b2019-10-23 13:02:26 -0700352#define PROPERTY_ENTRY_U8(_name_, _val_) \
353 __PROPERTY_ENTRY_ELEMENT(_name_, u8_data, U8, _val_)
354#define PROPERTY_ENTRY_U16(_name_, _val_) \
355 __PROPERTY_ENTRY_ELEMENT(_name_, u16_data, U16, _val_)
356#define PROPERTY_ENTRY_U32(_name_, _val_) \
357 __PROPERTY_ENTRY_ELEMENT(_name_, u32_data, U32, _val_)
358#define PROPERTY_ENTRY_U64(_name_, _val_) \
359 __PROPERTY_ENTRY_ELEMENT(_name_, u64_data, U64, _val_)
360#define PROPERTY_ENTRY_STRING(_name_, _val_) \
361 __PROPERTY_ENTRY_ELEMENT(_name_, str, STRING, _val_)
Heikki Krogerusa85f4202015-11-30 17:11:33 +0200362
363#define PROPERTY_ENTRY_BOOL(_name_) \
Andy Shevchenkoc505cbd2018-01-22 18:01:42 +0200364(struct property_entry) { \
Heikki Krogerusa85f4202015-11-30 17:11:33 +0200365 .name = _name_, \
Dmitry Torokhove6bff4662019-11-07 20:22:20 -0800366 .is_inline = true, \
Heikki Krogerusa85f4202015-11-30 17:11:33 +0200367}
368
Dmitry Torokhove64b6742019-11-07 20:22:22 -0800369#define PROPERTY_ENTRY_REF(_name_, _ref_, ...) \
370(struct property_entry) { \
371 .name = _name_, \
372 .length = sizeof(struct software_node_ref_args), \
373 .type = DEV_PROP_REF, \
Andy Shevchenkoe588fea2021-03-29 18:12:06 +0300374 { .pointer = &SOFTWARE_NODE_REFERENCE(_ref_, ##__VA_ARGS__), }, \
Dmitry Torokhove64b6742019-11-07 20:22:22 -0800375}
376
Dmitry Torokhov2d479e12017-02-02 17:41:27 -0800377struct property_entry *
378property_entries_dup(const struct property_entry *properties);
379
380void property_entries_free(const struct property_entry *properties);
381
Suthikulpanit, Suraveee5e55862015-10-28 15:50:49 -0700382bool device_dma_supported(struct device *dev);
383
384enum dev_dma_attr device_get_dma_attr(struct device *dev);
385
Andy Shevchenko67dcc262018-02-09 17:38:36 +0200386const void *device_get_match_data(struct device *dev);
Sinan Kayab283f152017-12-13 02:20:49 -0500387
Jeremy Linton4c96b7d2015-08-12 17:06:26 -0500388int device_get_phy_mode(struct device *dev);
Marcin Wojtasb28f2632018-01-18 13:31:39 +0100389int fwnode_get_phy_mode(struct fwnode_handle *fwnode);
Andy Shevchenkob2638e52022-02-03 14:56:13 +0200390
391void __iomem *fwnode_iomap(struct fwnode_handle *fwnode, int index);
392
Mika Westerberg07bb80d42017-03-28 10:52:21 +0300393struct fwnode_handle *fwnode_graph_get_next_endpoint(
Sakari Ailus37ba9832017-07-21 14:39:36 +0300394 const struct fwnode_handle *fwnode, struct fwnode_handle *prev);
Kieran Bingham6a71d8d2017-06-06 12:37:41 +0300395struct fwnode_handle *
Sakari Ailus37ba9832017-07-21 14:39:36 +0300396fwnode_graph_get_port_parent(const struct fwnode_handle *fwnode);
Mika Westerberg07bb80d42017-03-28 10:52:21 +0300397struct fwnode_handle *fwnode_graph_get_remote_port_parent(
Sakari Ailus37ba9832017-07-21 14:39:36 +0300398 const struct fwnode_handle *fwnode);
Mika Westerberg07bb80d42017-03-28 10:52:21 +0300399struct fwnode_handle *fwnode_graph_get_remote_port(
Sakari Ailus37ba9832017-07-21 14:39:36 +0300400 const struct fwnode_handle *fwnode);
Mika Westerberg07bb80d42017-03-28 10:52:21 +0300401struct fwnode_handle *fwnode_graph_get_remote_endpoint(
Sakari Ailus37ba9832017-07-21 14:39:36 +0300402 const struct fwnode_handle *fwnode);
Mika Westerberg07bb80d42017-03-28 10:52:21 +0300403
Laurent Pinchart35694af2020-07-01 08:21:37 +0200404static inline bool fwnode_graph_is_endpoint(struct fwnode_handle *fwnode)
405{
406 return fwnode_property_present(fwnode, "remote-endpoint");
407}
408
Sakari Ailus0fcc2bd2019-04-02 13:30:37 +0300409/*
410 * Fwnode lookup flags
411 *
412 * @FWNODE_GRAPH_ENDPOINT_NEXT: In the case of no exact match, look for the
413 * closest endpoint ID greater than the specified
414 * one.
415 * @FWNODE_GRAPH_DEVICE_DISABLED: That the device to which the remote
416 * endpoint of the given endpoint belongs to,
Sakari Ailus49f39cb2021-12-01 14:59:30 +0200417 * may be disabled, or that the endpoint is not
418 * connected.
Sakari Ailus0fcc2bd2019-04-02 13:30:37 +0300419 */
420#define FWNODE_GRAPH_ENDPOINT_NEXT BIT(0)
421#define FWNODE_GRAPH_DEVICE_DISABLED BIT(1)
422
423struct fwnode_handle *
424fwnode_graph_get_endpoint_by_id(const struct fwnode_handle *fwnode,
425 u32 port, u32 endpoint, unsigned long flags);
Sakari Ailusc87b8fc2021-12-01 14:59:33 +0200426unsigned int fwnode_graph_get_endpoint_count(struct fwnode_handle *fwnode,
427 unsigned long flags);
Sakari Ailus0fcc2bd2019-04-02 13:30:37 +0300428
Sakari Ailus5e4b1b72017-09-19 12:39:12 +0300429#define fwnode_graph_for_each_endpoint(fwnode, child) \
430 for (child = NULL; \
431 (child = fwnode_graph_get_next_endpoint(fwnode, child)); )
432
Sakari Ailus37ba9832017-07-21 14:39:36 +0300433int fwnode_graph_parse_endpoint(const struct fwnode_handle *fwnode,
Sakari Ailus2bd54522017-03-28 10:52:25 +0300434 struct fwnode_endpoint *endpoint);
435
Heikki Krogerusd7cf5592020-09-07 15:05:31 +0300436typedef void *(*devcon_match_fn_t)(struct fwnode_handle *fwnode, const char *id,
437 void *data);
438
439void *fwnode_connection_find_match(struct fwnode_handle *fwnode,
440 const char *con_id, void *data,
441 devcon_match_fn_t match);
442
443static inline void *device_connection_find_match(struct device *dev,
444 const char *con_id, void *data,
445 devcon_match_fn_t match)
446{
447 return fwnode_connection_find_match(dev_fwnode(dev), con_id, data, match);
448}
449
Heikki Krogerus59abd832018-11-09 17:21:36 +0300450/* -------------------------------------------------------------------------- */
451/* Software fwnode support - when HW description is incomplete or missing */
452
Heikki Krogerusb06184a2019-05-31 17:15:36 +0300453/**
Heikki Krogerus80488a62019-05-31 17:15:34 +0300454 * struct software_node - Software node description
455 * @name: Name of the software node
456 * @parent: Parent of the software node
457 * @properties: Array of device properties
458 */
459struct software_node {
460 const char *name;
461 const struct software_node *parent;
462 const struct property_entry *properties;
463};
464
Heikki Krogerus59abd832018-11-09 17:21:36 +0300465bool is_software_node(const struct fwnode_handle *fwnode);
Sakari Ailus56c9aa072019-10-03 15:32:09 +0300466const struct software_node *
467to_software_node(const struct fwnode_handle *fwnode);
Heikki Krogerus80488a62019-05-31 17:15:34 +0300468struct fwnode_handle *software_node_fwnode(const struct software_node *node);
469
Heikki Krogerus1666fae2019-08-19 13:07:22 +0300470const struct software_node *
471software_node_find_by_name(const struct software_node *parent,
472 const char *name);
473
Heikki Krogerus80488a62019-05-31 17:15:34 +0300474int software_node_register_nodes(const struct software_node *nodes);
475void software_node_unregister_nodes(const struct software_node *nodes);
476
Andy Shevchenko02094d52020-04-08 19:09:02 +0300477int software_node_register_node_group(const struct software_node **node_group);
478void software_node_unregister_node_group(const struct software_node **node_group);
479
Heikki Krogerus80488a62019-05-31 17:15:34 +0300480int software_node_register(const struct software_node *node);
Greg Kroah-Hartman46d26812020-05-24 17:30:40 +0200481void software_node_unregister(const struct software_node *node);
Heikki Krogerus59abd832018-11-09 17:21:36 +0300482
Heikki Krogerus59abd832018-11-09 17:21:36 +0300483struct fwnode_handle *
484fwnode_create_software_node(const struct property_entry *properties,
485 const struct fwnode_handle *parent);
486void fwnode_remove_software_node(struct fwnode_handle *fwnode);
487
Heikki Krogerus2a92c902021-03-01 17:30:12 +0300488int device_add_software_node(struct device *dev, const struct software_node *node);
Heikki Krogeruse68d0112021-01-15 12:49:11 +0300489void device_remove_software_node(struct device *dev);
490
Heikki Krogerus151f6ff2021-02-04 17:17:06 +0300491int device_create_managed_software_node(struct device *dev,
492 const struct property_entry *properties,
493 const struct software_node *parent);
494
Rafael J. Wysockib31384f2014-11-04 01:28:56 +0100495#endif /* _LINUX_PROPERTY_H_ */