blob: c5dbc48b55dd380ab829f8eef9038a5c9023e6b3 [file] [log] [blame]
Rafael J. Wysockice793482015-03-16 23:49:03 +01001/*
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
Sakari Ailus37081842017-06-06 12:37:37 +030015#include <linux/types.h>
16
Sakari Ailus37081842017-06-06 12:37:37 +030017struct fwnode_operations;
18
Rafael J. Wysockice793482015-03-16 23:49:03 +010019struct fwnode_handle {
Rafael J. Wysocki97badf82015-04-03 23:23:37 +020020 struct fwnode_handle *secondary;
Sakari Ailus37081842017-06-06 12:37:37 +030021 const struct fwnode_operations *ops;
Rafael J. Wysockice793482015-03-16 23:49:03 +010022};
23
Sakari Ailus2bd54522017-03-28 10:52:25 +030024/**
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
Sakari Ailus37081842017-06-06 12:37:37 +030036/**
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.
Sakari Ailus3b27d002017-06-06 12:37:38 +030049 * @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.
Sakari Ailus37081842017-06-06 12:37:37 +030054 */
55struct fwnode_operations {
56 void (*get)(struct fwnode_handle *fwnode);
57 void (*put)(struct fwnode_handle *fwnode);
Sakari Ailus2294b3a2017-06-06 12:37:39 +030058 bool (*device_is_available)(struct fwnode_handle *fwnode);
Sakari Ailus37081842017-06-06 12:37:37 +030059 bool (*property_present)(struct fwnode_handle *fwnode,
60 const char *propname);
61 int (*property_read_int_array)(struct fwnode_handle *fwnode,
62 const char *propname,
63 unsigned int elem_size, void *val,
64 size_t nval);
65 int (*property_read_string_array)(struct fwnode_handle *fwnode_handle,
66 const char *propname,
67 const char **val, size_t nval);
68 struct fwnode_handle *(*get_parent)(struct fwnode_handle *fwnode);
69 struct fwnode_handle *
70 (*get_next_child_node)(struct fwnode_handle *fwnode,
71 struct fwnode_handle *child);
72 struct fwnode_handle *
73 (*get_named_child_node)(struct fwnode_handle *fwnode, const char *name);
Sakari Ailus3b27d002017-06-06 12:37:38 +030074 struct fwnode_handle *
75 (*graph_get_next_endpoint)(struct fwnode_handle *fwnode,
76 struct fwnode_handle *prev);
77 struct fwnode_handle *
78 (*graph_get_remote_endpoint)(struct fwnode_handle *fwnode);
79 struct fwnode_handle *
80 (*graph_get_port_parent)(struct fwnode_handle *fwnode);
81 int (*graph_parse_endpoint)(struct fwnode_handle *fwnode,
82 struct fwnode_endpoint *endpoint);
Sakari Ailus37081842017-06-06 12:37:37 +030083};
84
85#define fwnode_has_op(fwnode, op) \
86 ((fwnode) && (fwnode)->ops && (fwnode)->ops->op)
87#define fwnode_call_int_op(fwnode, op, ...) \
88 (fwnode ? (fwnode_has_op(fwnode, op) ? \
89 (fwnode)->ops->op(fwnode, ## __VA_ARGS__) : -ENXIO) : \
90 -EINVAL)
Sakari Ailuse8158b482017-07-11 18:20:20 +030091#define fwnode_call_bool_op(fwnode, op, ...) \
92 (fwnode ? (fwnode_has_op(fwnode, op) ? \
93 (fwnode)->ops->op(fwnode, ## __VA_ARGS__) : false) : \
94 false)
Sakari Ailus37081842017-06-06 12:37:37 +030095#define fwnode_call_ptr_op(fwnode, op, ...) \
96 (fwnode_has_op(fwnode, op) ? \
97 (fwnode)->ops->op(fwnode, ## __VA_ARGS__) : NULL)
98#define fwnode_call_void_op(fwnode, op, ...) \
99 do { \
100 if (fwnode_has_op(fwnode, op)) \
101 (fwnode)->ops->op(fwnode, ## __VA_ARGS__); \
102 } while (false)
103
Rafael J. Wysockice793482015-03-16 23:49:03 +0100104#endif