blob: 0c35b6caf0f6abd5be4eed4fe19266efb7b1254b [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 Ailus3e3119d2017-07-21 15:11:49 +030036#define NR_FWNODE_REFERENCE_ARGS 8
37
38/**
39 * struct fwnode_reference_args - Fwnode reference with additional arguments
40 * @fwnode:- A reference to the base fwnode
41 * @nargs: Number of elements in @args array
42 * @args: Integer arguments on the fwnode
43 */
44struct fwnode_reference_args {
45 struct fwnode_handle *fwnode;
46 unsigned int nargs;
47 unsigned int args[NR_FWNODE_REFERENCE_ARGS];
48};
49
Sakari Ailus37081842017-06-06 12:37:37 +030050/**
51 * struct fwnode_operations - Operations for fwnode interface
52 * @get: Get a reference to an fwnode.
53 * @put: Put a reference to an fwnode.
54 * @property_present: Return true if a property is present.
55 * @property_read_integer_array: Read an array of integer properties. Return
56 * zero on success, a negative error code
57 * otherwise.
58 * @property_read_string_array: Read an array of string properties. Return zero
59 * on success, a negative error code otherwise.
60 * @get_parent: Return the parent of an fwnode.
61 * @get_next_child_node: Return the next child node in an iteration.
62 * @get_named_child_node: Return a child node with a given name.
Sakari Ailus3e3119d2017-07-21 15:11:49 +030063 * @get_reference_args: Return a reference pointed to by a property, with args
Sakari Ailus3b27d002017-06-06 12:37:38 +030064 * @graph_get_next_endpoint: Return an endpoint node in an iteration.
65 * @graph_get_remote_endpoint: Return the remote endpoint node of a local
66 * endpoint node.
67 * @graph_get_port_parent: Return the parent node of a port node.
68 * @graph_parse_endpoint: Parse endpoint for port and endpoint id.
Sakari Ailus37081842017-06-06 12:37:37 +030069 */
70struct fwnode_operations {
71 void (*get)(struct fwnode_handle *fwnode);
72 void (*put)(struct fwnode_handle *fwnode);
Sakari Ailus37ba9832017-07-21 14:39:36 +030073 bool (*device_is_available)(const struct fwnode_handle *fwnode);
74 bool (*property_present)(const struct fwnode_handle *fwnode,
Sakari Ailus37081842017-06-06 12:37:37 +030075 const char *propname);
Sakari Ailus37ba9832017-07-21 14:39:36 +030076 int (*property_read_int_array)(const struct fwnode_handle *fwnode,
Sakari Ailus37081842017-06-06 12:37:37 +030077 const char *propname,
78 unsigned int elem_size, void *val,
79 size_t nval);
Sakari Ailus37ba9832017-07-21 14:39:36 +030080 int
81 (*property_read_string_array)(const struct fwnode_handle *fwnode_handle,
82 const char *propname, const char **val,
83 size_t nval);
84 struct fwnode_handle *(*get_parent)(const struct fwnode_handle *fwnode);
Sakari Ailus37081842017-06-06 12:37:37 +030085 struct fwnode_handle *
Sakari Ailus37ba9832017-07-21 14:39:36 +030086 (*get_next_child_node)(const struct fwnode_handle *fwnode,
Sakari Ailus37081842017-06-06 12:37:37 +030087 struct fwnode_handle *child);
88 struct fwnode_handle *
Sakari Ailus37ba9832017-07-21 14:39:36 +030089 (*get_named_child_node)(const struct fwnode_handle *fwnode,
90 const char *name);
Sakari Ailus3e3119d2017-07-21 15:11:49 +030091 int (*get_reference_args)(const struct fwnode_handle *fwnode,
92 const char *prop, const char *nargs_prop,
93 unsigned int nargs, unsigned int index,
94 struct fwnode_reference_args *args);
Sakari Ailus3b27d002017-06-06 12:37:38 +030095 struct fwnode_handle *
Sakari Ailus37ba9832017-07-21 14:39:36 +030096 (*graph_get_next_endpoint)(const struct fwnode_handle *fwnode,
Sakari Ailus3b27d002017-06-06 12:37:38 +030097 struct fwnode_handle *prev);
98 struct fwnode_handle *
Sakari Ailus37ba9832017-07-21 14:39:36 +030099 (*graph_get_remote_endpoint)(const struct fwnode_handle *fwnode);
Sakari Ailus3b27d002017-06-06 12:37:38 +0300100 struct fwnode_handle *
101 (*graph_get_port_parent)(struct fwnode_handle *fwnode);
Sakari Ailus37ba9832017-07-21 14:39:36 +0300102 int (*graph_parse_endpoint)(const struct fwnode_handle *fwnode,
Sakari Ailus3b27d002017-06-06 12:37:38 +0300103 struct fwnode_endpoint *endpoint);
Sakari Ailus37081842017-06-06 12:37:37 +0300104};
105
106#define fwnode_has_op(fwnode, op) \
107 ((fwnode) && (fwnode)->ops && (fwnode)->ops->op)
108#define fwnode_call_int_op(fwnode, op, ...) \
109 (fwnode ? (fwnode_has_op(fwnode, op) ? \
110 (fwnode)->ops->op(fwnode, ## __VA_ARGS__) : -ENXIO) : \
111 -EINVAL)
Sakari Ailuse8158b482017-07-11 18:20:20 +0300112#define fwnode_call_bool_op(fwnode, op, ...) \
113 (fwnode ? (fwnode_has_op(fwnode, op) ? \
114 (fwnode)->ops->op(fwnode, ## __VA_ARGS__) : false) : \
115 false)
Sakari Ailus37081842017-06-06 12:37:37 +0300116#define fwnode_call_ptr_op(fwnode, op, ...) \
117 (fwnode_has_op(fwnode, op) ? \
118 (fwnode)->ops->op(fwnode, ## __VA_ARGS__) : NULL)
119#define fwnode_call_void_op(fwnode, op, ...) \
120 do { \
121 if (fwnode_has_op(fwnode, op)) \
122 (fwnode)->ops->op(fwnode, ## __VA_ARGS__); \
123 } while (false)
124
Rafael J. Wysockice793482015-03-16 23:49:03 +0100125#endif