blob: 7b50ee4edcfcdf86e7ddc2ad224dd437a9e2de98 [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 Ailus37ba9832017-07-21 14:39:36 +030058 bool (*device_is_available)(const struct fwnode_handle *fwnode);
59 bool (*property_present)(const struct fwnode_handle *fwnode,
Sakari Ailus37081842017-06-06 12:37:37 +030060 const char *propname);
Sakari Ailus37ba9832017-07-21 14:39:36 +030061 int (*property_read_int_array)(const struct fwnode_handle *fwnode,
Sakari Ailus37081842017-06-06 12:37:37 +030062 const char *propname,
63 unsigned int elem_size, void *val,
64 size_t nval);
Sakari Ailus37ba9832017-07-21 14:39:36 +030065 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);
Sakari Ailus37081842017-06-06 12:37:37 +030070 struct fwnode_handle *
Sakari Ailus37ba9832017-07-21 14:39:36 +030071 (*get_next_child_node)(const struct fwnode_handle *fwnode,
Sakari Ailus37081842017-06-06 12:37:37 +030072 struct fwnode_handle *child);
73 struct fwnode_handle *
Sakari Ailus37ba9832017-07-21 14:39:36 +030074 (*get_named_child_node)(const struct fwnode_handle *fwnode,
75 const char *name);
Sakari Ailus3b27d002017-06-06 12:37:38 +030076 struct fwnode_handle *
Sakari Ailus37ba9832017-07-21 14:39:36 +030077 (*graph_get_next_endpoint)(const struct fwnode_handle *fwnode,
Sakari Ailus3b27d002017-06-06 12:37:38 +030078 struct fwnode_handle *prev);
79 struct fwnode_handle *
Sakari Ailus37ba9832017-07-21 14:39:36 +030080 (*graph_get_remote_endpoint)(const struct fwnode_handle *fwnode);
Sakari Ailus3b27d002017-06-06 12:37:38 +030081 struct fwnode_handle *
82 (*graph_get_port_parent)(struct fwnode_handle *fwnode);
Sakari Ailus37ba9832017-07-21 14:39:36 +030083 int (*graph_parse_endpoint)(const struct fwnode_handle *fwnode,
Sakari Ailus3b27d002017-06-06 12:37:38 +030084 struct fwnode_endpoint *endpoint);
Sakari Ailus37081842017-06-06 12:37:37 +030085};
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)
Sakari Ailuse8158b482017-07-11 18:20:20 +030093#define fwnode_call_bool_op(fwnode, op, ...) \
94 (fwnode ? (fwnode_has_op(fwnode, op) ? \
95 (fwnode)->ops->op(fwnode, ## __VA_ARGS__) : false) : \
96 false)
Sakari Ailus37081842017-06-06 12:37:37 +030097#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
Rafael J. Wysockice793482015-03-16 23:49:03 +0100106#endif