]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - include/linux/fwnode.h
device property: Constify fwnode property API
[mirror_ubuntu-bionic-kernel.git] / include / linux / fwnode.h
CommitLineData
ce793486
RW
1/*
2 * fwnode.h - Firmware device node object handle type definition.
3 *
4 * Copyright (C) 2015, Intel Corporation
5 * Author: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#ifndef _LINUX_FWNODE_H_
13#define _LINUX_FWNODE_H_
14
3708184a
SA
15#include <linux/types.h>
16
3708184a
SA
17struct fwnode_operations;
18
ce793486 19struct fwnode_handle {
97badf87 20 struct fwnode_handle *secondary;
3708184a 21 const struct fwnode_operations *ops;
ce793486
RW
22};
23
2bd5452d
SA
24/**
25 * struct fwnode_endpoint - Fwnode graph endpoint
26 * @port: Port number
27 * @id: Endpoint id
28 * @local_fwnode: reference to the related fwnode
29 */
30struct fwnode_endpoint {
31 unsigned int port;
32 unsigned int id;
33 const struct fwnode_handle *local_fwnode;
34};
35
3708184a
SA
36/**
37 * struct fwnode_operations - Operations for fwnode interface
38 * @get: Get a reference to an fwnode.
39 * @put: Put a reference to an fwnode.
40 * @property_present: Return true if a property is present.
41 * @property_read_integer_array: Read an array of integer properties. Return
42 * zero on success, a negative error code
43 * otherwise.
44 * @property_read_string_array: Read an array of string properties. Return zero
45 * on success, a negative error code otherwise.
46 * @get_parent: Return the parent of an fwnode.
47 * @get_next_child_node: Return the next child node in an iteration.
48 * @get_named_child_node: Return a child node with a given name.
3b27d00e
SA
49 * @graph_get_next_endpoint: Return an endpoint node in an iteration.
50 * @graph_get_remote_endpoint: Return the remote endpoint node of a local
51 * endpoint node.
52 * @graph_get_port_parent: Return the parent node of a port node.
53 * @graph_parse_endpoint: Parse endpoint for port and endpoint id.
3708184a
SA
54 */
55struct fwnode_operations {
56 void (*get)(struct fwnode_handle *fwnode);
57 void (*put)(struct fwnode_handle *fwnode);
37ba983c
SA
58 bool (*device_is_available)(const struct fwnode_handle *fwnode);
59 bool (*property_present)(const struct fwnode_handle *fwnode,
3708184a 60 const char *propname);
37ba983c 61 int (*property_read_int_array)(const struct fwnode_handle *fwnode,
3708184a
SA
62 const char *propname,
63 unsigned int elem_size, void *val,
64 size_t nval);
37ba983c
SA
65 int
66 (*property_read_string_array)(const struct fwnode_handle *fwnode_handle,
67 const char *propname, const char **val,
68 size_t nval);
69 struct fwnode_handle *(*get_parent)(const struct fwnode_handle *fwnode);
3708184a 70 struct fwnode_handle *
37ba983c 71 (*get_next_child_node)(const struct fwnode_handle *fwnode,
3708184a
SA
72 struct fwnode_handle *child);
73 struct fwnode_handle *
37ba983c
SA
74 (*get_named_child_node)(const struct fwnode_handle *fwnode,
75 const char *name);
3b27d00e 76 struct fwnode_handle *
37ba983c 77 (*graph_get_next_endpoint)(const struct fwnode_handle *fwnode,
3b27d00e
SA
78 struct fwnode_handle *prev);
79 struct fwnode_handle *
37ba983c 80 (*graph_get_remote_endpoint)(const struct fwnode_handle *fwnode);
3b27d00e
SA
81 struct fwnode_handle *
82 (*graph_get_port_parent)(struct fwnode_handle *fwnode);
37ba983c 83 int (*graph_parse_endpoint)(const struct fwnode_handle *fwnode,
3b27d00e 84 struct fwnode_endpoint *endpoint);
3708184a
SA
85};
86
87#define fwnode_has_op(fwnode, op) \
88 ((fwnode) && (fwnode)->ops && (fwnode)->ops->op)
89#define fwnode_call_int_op(fwnode, op, ...) \
90 (fwnode ? (fwnode_has_op(fwnode, op) ? \
91 (fwnode)->ops->op(fwnode, ## __VA_ARGS__) : -ENXIO) : \
92 -EINVAL)
e8158b48
SA
93#define fwnode_call_bool_op(fwnode, op, ...) \
94 (fwnode ? (fwnode_has_op(fwnode, op) ? \
95 (fwnode)->ops->op(fwnode, ## __VA_ARGS__) : false) : \
96 false)
3708184a
SA
97#define fwnode_call_ptr_op(fwnode, op, ...) \
98 (fwnode_has_op(fwnode, op) ? \
99 (fwnode)->ops->op(fwnode, ## __VA_ARGS__) : NULL)
100#define fwnode_call_void_op(fwnode, op, ...) \
101 do { \
102 if (fwnode_has_op(fwnode, op)) \
103 (fwnode)->ops->op(fwnode, ## __VA_ARGS__); \
104 } while (false)
105
ce793486 106#endif