2019-06-04 15:11:33 +07:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
2015-03-17 05:49:03 +07:00
|
|
|
/*
|
|
|
|
* fwnode.h - Firmware device node object handle type definition.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2015, Intel Corporation
|
|
|
|
* Author: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _LINUX_FWNODE_H_
|
|
|
|
#define _LINUX_FWNODE_H_
|
|
|
|
|
2017-06-06 16:37:37 +07:00
|
|
|
#include <linux/types.h>
|
|
|
|
|
|
|
|
struct fwnode_operations;
|
2017-12-13 14:20:49 +07:00
|
|
|
struct device;
|
2017-06-06 16:37:37 +07:00
|
|
|
|
2015-03-17 05:49:03 +07:00
|
|
|
struct fwnode_handle {
|
2015-04-04 04:23:37 +07:00
|
|
|
struct fwnode_handle *secondary;
|
2017-06-06 16:37:37 +07:00
|
|
|
const struct fwnode_operations *ops;
|
2019-09-05 04:11:20 +07:00
|
|
|
struct device *dev;
|
2015-03-17 05:49:03 +07:00
|
|
|
};
|
|
|
|
|
2017-03-28 14:52:25 +07:00
|
|
|
/**
|
|
|
|
* struct fwnode_endpoint - Fwnode graph endpoint
|
|
|
|
* @port: Port number
|
|
|
|
* @id: Endpoint id
|
|
|
|
* @local_fwnode: reference to the related fwnode
|
|
|
|
*/
|
|
|
|
struct fwnode_endpoint {
|
|
|
|
unsigned int port;
|
|
|
|
unsigned int id;
|
|
|
|
const struct fwnode_handle *local_fwnode;
|
|
|
|
};
|
|
|
|
|
2017-07-21 19:11:49 +07:00
|
|
|
#define NR_FWNODE_REFERENCE_ARGS 8
|
|
|
|
|
|
|
|
/**
|
|
|
|
* struct fwnode_reference_args - Fwnode reference with additional arguments
|
|
|
|
* @fwnode:- A reference to the base fwnode
|
|
|
|
* @nargs: Number of elements in @args array
|
|
|
|
* @args: Integer arguments on the fwnode
|
|
|
|
*/
|
|
|
|
struct fwnode_reference_args {
|
|
|
|
struct fwnode_handle *fwnode;
|
|
|
|
unsigned int nargs;
|
2018-07-17 21:19:11 +07:00
|
|
|
u64 args[NR_FWNODE_REFERENCE_ARGS];
|
2017-07-21 19:11:49 +07:00
|
|
|
};
|
|
|
|
|
2017-06-06 16:37:37 +07:00
|
|
|
/**
|
|
|
|
* struct fwnode_operations - Operations for fwnode interface
|
|
|
|
* @get: Get a reference to an fwnode.
|
|
|
|
* @put: Put a reference to an fwnode.
|
2019-10-08 20:26:06 +07:00
|
|
|
* @device_is_available: Return true if the device is available.
|
2017-12-13 14:20:49 +07:00
|
|
|
* @device_get_match_data: Return the device driver match data.
|
2017-06-06 16:37:37 +07:00
|
|
|
* @property_present: Return true if a property is present.
|
2019-10-08 20:26:06 +07:00
|
|
|
* @property_read_int_array: Read an array of integer properties. Return zero on
|
|
|
|
* success, a negative error code otherwise.
|
2017-06-06 16:37:37 +07:00
|
|
|
* @property_read_string_array: Read an array of string properties. Return zero
|
|
|
|
* on success, a negative error code otherwise.
|
2019-10-03 19:32:12 +07:00
|
|
|
* @get_name: Return the name of an fwnode.
|
2019-10-03 19:32:13 +07:00
|
|
|
* @get_name_prefix: Get a prefix for a node (for printing purposes).
|
2017-06-06 16:37:37 +07:00
|
|
|
* @get_parent: Return the parent of an fwnode.
|
|
|
|
* @get_next_child_node: Return the next child node in an iteration.
|
|
|
|
* @get_named_child_node: Return a child node with a given name.
|
2017-07-21 19:11:49 +07:00
|
|
|
* @get_reference_args: Return a reference pointed to by a property, with args
|
2017-06-06 16:37:38 +07:00
|
|
|
* @graph_get_next_endpoint: Return an endpoint node in an iteration.
|
|
|
|
* @graph_get_remote_endpoint: Return the remote endpoint node of a local
|
|
|
|
* endpoint node.
|
|
|
|
* @graph_get_port_parent: Return the parent node of a port node.
|
|
|
|
* @graph_parse_endpoint: Parse endpoint for port and endpoint id.
|
2019-09-05 04:11:21 +07:00
|
|
|
* @add_links: Called after the device corresponding to the fwnode is added
|
|
|
|
* using device_add(). The function is expected to create device
|
|
|
|
* links to all the suppliers of the device that are available at
|
|
|
|
* the time this function is called. The function must NOT stop
|
|
|
|
* at the first failed device link if other unlinked supplier
|
2019-10-12 02:15:20 +07:00
|
|
|
* devices are present in the system. This is necessary for the
|
|
|
|
* driver/bus sync_state() callbacks to work correctly.
|
|
|
|
*
|
|
|
|
* For example, say Device-C depends on suppliers Device-S1 and
|
|
|
|
* Device-S2 and the dependency is listed in that order in the
|
|
|
|
* firmware. Say, S1 gets populated from the firmware after
|
|
|
|
* late_initcall_sync(). Say S2 is populated and probed way
|
|
|
|
* before that in device_initcall(). When C is populated, if this
|
|
|
|
* add_links() function doesn't continue past a "failed linking to
|
|
|
|
* S1" and continue linking C to S2, then S2 will get a
|
|
|
|
* sync_state() callback before C is probed. This is because from
|
|
|
|
* the perspective of S2, C was never a consumer when its
|
|
|
|
* sync_state() evaluation is done. To avoid this, the add_links()
|
|
|
|
* function has to go through all available suppliers of the
|
|
|
|
* device (that corresponds to this fwnode) and link to them
|
|
|
|
* before returning.
|
|
|
|
*
|
|
|
|
* If some suppliers are not yet available (indicated by an error
|
|
|
|
* return value), this function will be called again when other
|
2019-09-05 04:11:21 +07:00
|
|
|
* devices are added to allow creating device links to any newly
|
|
|
|
* available suppliers.
|
|
|
|
*
|
|
|
|
* Return 0 if device links have been successfully created to all
|
2019-11-13 09:35:59 +07:00
|
|
|
* the known suppliers of this device or if the supplier
|
|
|
|
* information is not known.
|
2019-10-29 05:00:24 +07:00
|
|
|
*
|
2019-11-13 09:35:59 +07:00
|
|
|
* Return -ENODEV if the suppliers needed for probing this device
|
|
|
|
* have not been registered yet (because device links can only be
|
|
|
|
* created to devices registered with the driver core).
|
2019-10-29 05:00:24 +07:00
|
|
|
*
|
2019-11-13 09:35:59 +07:00
|
|
|
* Return -EAGAIN if some of the suppliers of this device have not
|
|
|
|
* been registered yet, but none of those suppliers are necessary
|
|
|
|
* for probing the device.
|
2017-06-06 16:37:37 +07:00
|
|
|
*/
|
|
|
|
struct fwnode_operations {
|
2017-09-19 16:39:11 +07:00
|
|
|
struct fwnode_handle *(*get)(struct fwnode_handle *fwnode);
|
2017-06-06 16:37:37 +07:00
|
|
|
void (*put)(struct fwnode_handle *fwnode);
|
2017-07-21 18:39:36 +07:00
|
|
|
bool (*device_is_available)(const struct fwnode_handle *fwnode);
|
2018-02-09 22:38:36 +07:00
|
|
|
const void *(*device_get_match_data)(const struct fwnode_handle *fwnode,
|
|
|
|
const struct device *dev);
|
2017-07-21 18:39:36 +07:00
|
|
|
bool (*property_present)(const struct fwnode_handle *fwnode,
|
2017-06-06 16:37:37 +07:00
|
|
|
const char *propname);
|
2017-07-21 18:39:36 +07:00
|
|
|
int (*property_read_int_array)(const struct fwnode_handle *fwnode,
|
2017-06-06 16:37:37 +07:00
|
|
|
const char *propname,
|
|
|
|
unsigned int elem_size, void *val,
|
|
|
|
size_t nval);
|
2017-07-21 18:39:36 +07:00
|
|
|
int
|
|
|
|
(*property_read_string_array)(const struct fwnode_handle *fwnode_handle,
|
|
|
|
const char *propname, const char **val,
|
|
|
|
size_t nval);
|
2019-10-03 19:32:12 +07:00
|
|
|
const char *(*get_name)(const struct fwnode_handle *fwnode);
|
2019-10-03 19:32:13 +07:00
|
|
|
const char *(*get_name_prefix)(const struct fwnode_handle *fwnode);
|
2017-07-21 18:39:36 +07:00
|
|
|
struct fwnode_handle *(*get_parent)(const struct fwnode_handle *fwnode);
|
2017-06-06 16:37:37 +07:00
|
|
|
struct fwnode_handle *
|
2017-07-21 18:39:36 +07:00
|
|
|
(*get_next_child_node)(const struct fwnode_handle *fwnode,
|
2017-06-06 16:37:37 +07:00
|
|
|
struct fwnode_handle *child);
|
|
|
|
struct fwnode_handle *
|
2017-07-21 18:39:36 +07:00
|
|
|
(*get_named_child_node)(const struct fwnode_handle *fwnode,
|
|
|
|
const char *name);
|
2017-07-21 19:11:49 +07:00
|
|
|
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);
|
2017-06-06 16:37:38 +07:00
|
|
|
struct fwnode_handle *
|
2017-07-21 18:39:36 +07:00
|
|
|
(*graph_get_next_endpoint)(const struct fwnode_handle *fwnode,
|
2017-06-06 16:37:38 +07:00
|
|
|
struct fwnode_handle *prev);
|
|
|
|
struct fwnode_handle *
|
2017-07-21 18:39:36 +07:00
|
|
|
(*graph_get_remote_endpoint)(const struct fwnode_handle *fwnode);
|
2017-06-06 16:37:38 +07:00
|
|
|
struct fwnode_handle *
|
|
|
|
(*graph_get_port_parent)(struct fwnode_handle *fwnode);
|
2017-07-21 18:39:36 +07:00
|
|
|
int (*graph_parse_endpoint)(const struct fwnode_handle *fwnode,
|
2017-06-06 16:37:38 +07:00
|
|
|
struct fwnode_endpoint *endpoint);
|
2019-09-05 04:11:21 +07:00
|
|
|
int (*add_links)(const struct fwnode_handle *fwnode,
|
|
|
|
struct device *dev);
|
2017-06-06 16:37:37 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
#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)
|
2019-08-24 03:32:27 +07:00
|
|
|
|
|
|
|
#define fwnode_call_bool_op(fwnode, op, ...) \
|
|
|
|
(fwnode_has_op(fwnode, op) ? \
|
|
|
|
(fwnode)->ops->op(fwnode, ## __VA_ARGS__) : false)
|
|
|
|
|
2017-06-06 16:37:37 +07:00
|
|
|
#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)
|
2019-09-05 04:11:20 +07:00
|
|
|
#define get_dev_from_fwnode(fwnode) get_device((fwnode)->dev)
|
2017-06-06 16:37:37 +07:00
|
|
|
|
2015-03-17 05:49:03 +07:00
|
|
|
#endif
|