blob: 8f64b3ae9c579067179f369ea354a20dc9ee62f8 [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
Rafael J. Wysockice793482015-03-16 23:49:03 +010017enum fwnode_type {
18 FWNODE_INVALID = 0,
19 FWNODE_OF,
20 FWNODE_ACPI,
Rafael J. Wysocki445b0eb2015-08-27 04:36:14 +020021 FWNODE_ACPI_DATA,
Lorenzo Pieralisi027b25b2016-11-21 10:01:33 +000022 FWNODE_ACPI_STATIC,
Rafael J. Wysocki16ba08d2015-04-03 16:05:11 +020023 FWNODE_PDATA,
Lorenzo Pieralisi027b25b2016-11-21 10:01:33 +000024 FWNODE_IRQCHIP
Rafael J. Wysockice793482015-03-16 23:49:03 +010025};
26
Sakari Ailus37081842017-06-06 12:37:37 +030027struct fwnode_operations;
28
Rafael J. Wysockice793482015-03-16 23:49:03 +010029struct fwnode_handle {
30 enum fwnode_type type;
Rafael J. Wysocki97badf82015-04-03 23:23:37 +020031 struct fwnode_handle *secondary;
Sakari Ailus37081842017-06-06 12:37:37 +030032 const struct fwnode_operations *ops;
Rafael J. Wysockice793482015-03-16 23:49:03 +010033};
34
Sakari Ailus2bd54522017-03-28 10:52:25 +030035/**
36 * struct fwnode_endpoint - Fwnode graph endpoint
37 * @port: Port number
38 * @id: Endpoint id
39 * @local_fwnode: reference to the related fwnode
40 */
41struct fwnode_endpoint {
42 unsigned int port;
43 unsigned int id;
44 const struct fwnode_handle *local_fwnode;
45};
46
Sakari Ailus37081842017-06-06 12:37:37 +030047/**
48 * struct fwnode_operations - Operations for fwnode interface
49 * @get: Get a reference to an fwnode.
50 * @put: Put a reference to an fwnode.
51 * @property_present: Return true if a property is present.
52 * @property_read_integer_array: Read an array of integer properties. Return
53 * zero on success, a negative error code
54 * otherwise.
55 * @property_read_string_array: Read an array of string properties. Return zero
56 * on success, a negative error code otherwise.
57 * @get_parent: Return the parent of an fwnode.
58 * @get_next_child_node: Return the next child node in an iteration.
59 * @get_named_child_node: Return a child node with a given name.
60 */
61struct fwnode_operations {
62 void (*get)(struct fwnode_handle *fwnode);
63 void (*put)(struct fwnode_handle *fwnode);
64 bool (*property_present)(struct fwnode_handle *fwnode,
65 const char *propname);
66 int (*property_read_int_array)(struct fwnode_handle *fwnode,
67 const char *propname,
68 unsigned int elem_size, void *val,
69 size_t nval);
70 int (*property_read_string_array)(struct fwnode_handle *fwnode_handle,
71 const char *propname,
72 const char **val, size_t nval);
73 struct fwnode_handle *(*get_parent)(struct fwnode_handle *fwnode);
74 struct fwnode_handle *
75 (*get_next_child_node)(struct fwnode_handle *fwnode,
76 struct fwnode_handle *child);
77 struct fwnode_handle *
78 (*get_named_child_node)(struct fwnode_handle *fwnode, const char *name);
79};
80
81#define fwnode_has_op(fwnode, op) \
82 ((fwnode) && (fwnode)->ops && (fwnode)->ops->op)
83#define fwnode_call_int_op(fwnode, op, ...) \
84 (fwnode ? (fwnode_has_op(fwnode, op) ? \
85 (fwnode)->ops->op(fwnode, ## __VA_ARGS__) : -ENXIO) : \
86 -EINVAL)
87#define fwnode_call_ptr_op(fwnode, op, ...) \
88 (fwnode_has_op(fwnode, op) ? \
89 (fwnode)->ops->op(fwnode, ## __VA_ARGS__) : NULL)
90#define fwnode_call_void_op(fwnode, op, ...) \
91 do { \
92 if (fwnode_has_op(fwnode, op)) \
93 (fwnode)->ops->op(fwnode, ## __VA_ARGS__); \
94 } while (false)
95
Rafael J. Wysockice793482015-03-16 23:49:03 +010096#endif