summaryrefslogtreecommitdiff
path: root/components/legacy/fdt/inc/dtb_fwnode.h
blob: e8d303e37d57805e3b154df6a4862ec1f7410614 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#ifndef __DTB_FWNODE_H__
#define __DTB_FWNODE_H__

#include "libfdt_env.h"
#include <rtthread.h>
#include <stdint.h>
#include <stdbool.h>

struct fwnode_operations;
struct rt_device;

#define FWNODE_FLAG_LINKS_ADDED 0x01
#define FWNODE_FLAG_NOT_DEVICE 0x02
#define FWNODE_FLAG_INITIALIZED 0x04

#define NR_FWNODE_REFERENCE_ARGS 8

struct fwnode_handle
{
    struct fwnode_handle *secondary;
    const struct fwnode_operations *ops;
    struct rt_device *dev;
    struct rt_list_node suppliers;
    struct rt_list_node consumers;
    uint8_t flags;
};

struct fwnode_link
{
    struct fwnode_handle *supplier;
    struct rt_list_node s_hook;
    struct fwnode_handle *consumer;
    struct rt_list_node c_hook;
};

struct fwnode_endpoint
{
    unsigned int port;
    unsigned int id;
    const struct fwnode_handle *local_fwnode;
};

struct fwnode_reference_args
{
    struct fwnode_handle *fwnode;
    unsigned int nargs;
    uint64_t args[NR_FWNODE_REFERENCE_ARGS];
};

struct fwnode_operations
{
    struct fwnode_handle *(*get)(struct fwnode_handle *fwnode);
    void (*put)(struct fwnode_handle *fwnode);
    bool (*device_is_available)(const struct fwnode_handle *fwnode);
    const void *(*device_get_match_data)(const struct fwnode_handle *fwnode,
                                         const struct rt_device *dev);
    bool (*property_present)(const struct fwnode_handle *fwnode,
                             const char *propname);
    int (*property_read_int_array)(const struct fwnode_handle *fwnode,
                                   const char *propname,
                                   unsigned int elem_size, void *val,
                                   size_t nval);
    int (*property_read_string_array)(const struct fwnode_handle *fwnode_handle,
                                      const char *propname, const char **val,
                                      size_t nval);
    const char *(*get_name)(const struct fwnode_handle *fwnode);
    const char *(*get_name_prefix)(const struct fwnode_handle *fwnode);
    struct fwnode_handle *(*get_parent)(const struct fwnode_handle *fwnode);
    struct fwnode_handle *(*get_next_child_node)(const struct fwnode_handle *fwnode,
                                                 struct fwnode_handle *child);
    struct fwnode_handle *(*get_named_child_node)(const struct fwnode_handle *fwnode,
                                                  const char *name);
    int (*get_reference_args)(const struct fwnode_handle *fwnode,
                              const char *prop, const char *nargs_prop,
                              unsigned int nargs, unsigned int index,
                              struct fwnode_reference_args *args);
    struct fwnode_handle *(*graph_get_next_endpoint)(const struct fwnode_handle *fwnode,
                                                     struct fwnode_handle *prev);
    struct fwnode_handle *(*graph_get_remote_endpoint)(const struct fwnode_handle *fwnode);
    struct fwnode_handle *(*graph_get_port_parent)(struct fwnode_handle *fwnode);
    int (*graph_parse_endpoint)(const struct fwnode_handle *fwnode,
                                struct fwnode_endpoint *endpoint);
    int (*add_links)(struct fwnode_handle *fwnode);
};

#define fwnode_has_op(fwnode, op) \
    ((fwnode) && (fwnode)->ops && (fwnode)->ops->op)
#define fwnode_call_int_op(fwnode, op, ...) \
    (fwnode ? (fwnode_has_op(fwnode, op) ? (fwnode)->ops->op(fwnode, ##__VA_ARGS__) : -ENXIO) : -EINVAL)

#define fwnode_call_bool_op(fwnode, op, ...) \
    (fwnode_has_op(fwnode, op) ? (fwnode)->ops->op(fwnode, ##__VA_ARGS__) : false)

#define fwnode_call_ptr_op(fwnode, op, ...) \
    (fwnode_has_op(fwnode, op) ? (fwnode)->ops->op(fwnode, ##__VA_ARGS__) : NULL)
#define fwnode_call_void_op(fwnode, op, ...)          \
    do                                                \
    {                                                 \
        if (fwnode_has_op(fwnode, op))                \
            (fwnode)->ops->op(fwnode, ##__VA_ARGS__); \
    } while (false)

#define get_dev_from_fwnode(fwnode) ((fwnode)->dev)

static inline void fwnode_init(struct fwnode_handle *fwnode,
                               const struct fwnode_operations *ops)
{
    fwnode->ops = ops;
    rt_list_init(&fwnode->consumers);
    rt_list_init(&fwnode->suppliers);
}

static inline void fwnode_dev_initialized(struct fwnode_handle *fwnode,
                                          bool initialized)
{
    if (!fwnode)
        return;

    if (initialized)
        fwnode->flags |= FWNODE_FLAG_INITIALIZED;
    else
        fwnode->flags &= ~FWNODE_FLAG_INITIALIZED;
}

#endif //__DTB_FWNODE_H__