2019-06-04 08:11:33 +00:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
2015-03-16 22:49:03 +00: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 09:37:37 +00:00
|
|
|
#include <linux/types.h>
|
2020-11-21 02:02:23 +00:00
|
|
|
#include <linux/list.h>
|
2021-10-13 14:37:07 +00:00
|
|
|
#include <linux/bits.h>
|
2021-02-05 22:26:41 +00:00
|
|
|
#include <linux/err.h>
|
2017-06-06 09:37:37 +00:00
|
|
|
|
|
|
|
struct fwnode_operations;
|
2017-12-13 07:20:49 +00:00
|
|
|
struct device;
|
2017-06-06 09:37:37 +00:00
|
|
|
|
2020-11-21 02:02:27 +00:00
|
|
|
/*
|
|
|
|
* fwnode link flags
|
|
|
|
*
|
2021-02-05 22:26:41 +00:00
|
|
|
* LINKS_ADDED: The fwnode has already be parsed to add fwnode links.
|
|
|
|
* NOT_DEVICE: The fwnode will never be populated as a struct device.
|
|
|
|
* INITIALIZED: The hardware corresponding to fwnode has been initialized.
|
2021-09-15 17:09:38 +00:00
|
|
|
* NEEDS_CHILD_BOUND_ON_ADD: For this fwnode/device to probe successfully, its
|
|
|
|
* driver needs its child devices to be bound with
|
|
|
|
* their respective drivers as soon as they are
|
|
|
|
* added.
|
2020-11-21 02:02:27 +00:00
|
|
|
*/
|
2021-09-15 17:09:38 +00:00
|
|
|
#define FWNODE_FLAG_LINKS_ADDED BIT(0)
|
|
|
|
#define FWNODE_FLAG_NOT_DEVICE BIT(1)
|
|
|
|
#define FWNODE_FLAG_INITIALIZED BIT(2)
|
|
|
|
#define FWNODE_FLAG_NEEDS_CHILD_BOUND_ON_ADD BIT(3)
|
2020-11-21 02:02:27 +00:00
|
|
|
|
2015-03-16 22:49:03 +00:00
|
|
|
struct fwnode_handle {
|
2015-04-03 21:23:37 +00:00
|
|
|
struct fwnode_handle *secondary;
|
2017-06-06 09:37:37 +00:00
|
|
|
const struct fwnode_operations *ops;
|
2019-09-04 21:11:20 +00:00
|
|
|
struct device *dev;
|
2020-11-21 02:02:23 +00:00
|
|
|
struct list_head suppliers;
|
|
|
|
struct list_head consumers;
|
2020-11-21 02:02:27 +00:00
|
|
|
u8 flags;
|
2020-11-21 02:02:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct fwnode_link {
|
|
|
|
struct fwnode_handle *supplier;
|
|
|
|
struct list_head s_hook;
|
|
|
|
struct fwnode_handle *consumer;
|
|
|
|
struct list_head c_hook;
|
2015-03-16 22:49:03 +00:00
|
|
|
};
|
|
|
|
|
2017-03-28 07:52:25 +00: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;
|
|
|
|
};
|
|
|
|
|
2021-01-07 13:28:30 +00:00
|
|
|
/*
|
|
|
|
* ports and endpoints defined as software_nodes should all follow a common
|
|
|
|
* naming scheme; use these macros to ensure commonality.
|
|
|
|
*/
|
|
|
|
#define SWNODE_GRAPH_PORT_NAME_FMT "port@%u"
|
|
|
|
#define SWNODE_GRAPH_ENDPOINT_NAME_FMT "endpoint@%u"
|
|
|
|
|
2017-07-21 12:11:49 +00: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 14:19:11 +00:00
|
|
|
u64 args[NR_FWNODE_REFERENCE_ARGS];
|
2017-07-21 12:11:49 +00:00
|
|
|
};
|
|
|
|
|
2017-06-06 09:37:37 +00: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 13:26:06 +00:00
|
|
|
* @device_is_available: Return true if the device is available.
|
2017-12-13 07:20:49 +00:00
|
|
|
* @device_get_match_data: Return the device driver match data.
|
2017-06-06 09:37:37 +00:00
|
|
|
* @property_present: Return true if a property is present.
|
2019-10-08 13:26:06 +00:00
|
|
|
* @property_read_int_array: Read an array of integer properties. Return zero on
|
|
|
|
* success, a negative error code otherwise.
|
2017-06-06 09:37:37 +00:00
|
|
|
* @property_read_string_array: Read an array of string properties. Return zero
|
|
|
|
* on success, a negative error code otherwise.
|
2019-10-03 12:32:12 +00:00
|
|
|
* @get_name: Return the name of an fwnode.
|
2019-10-03 12:32:13 +00:00
|
|
|
* @get_name_prefix: Get a prefix for a node (for printing purposes).
|
2017-06-06 09:37:37 +00: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 12:11:49 +00:00
|
|
|
* @get_reference_args: Return a reference pointed to by a property, with args
|
2017-06-06 09:37:38 +00: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.
|
2020-11-21 02:02:26 +00:00
|
|
|
* @add_links: Create fwnode links to all the suppliers of the fwnode. Return
|
|
|
|
* zero on success, a negative error code otherwise.
|
2017-06-06 09:37:37 +00:00
|
|
|
*/
|
|
|
|
struct fwnode_operations {
|
2017-09-19 09:39:11 +00:00
|
|
|
struct fwnode_handle *(*get)(struct fwnode_handle *fwnode);
|
2017-06-06 09:37:37 +00:00
|
|
|
void (*put)(struct fwnode_handle *fwnode);
|
2017-07-21 11:39:36 +00:00
|
|
|
bool (*device_is_available)(const struct fwnode_handle *fwnode);
|
2018-02-09 15:38:36 +00:00
|
|
|
const void *(*device_get_match_data)(const struct fwnode_handle *fwnode,
|
|
|
|
const struct device *dev);
|
2022-03-31 12:54:47 +00:00
|
|
|
bool (*device_dma_supported)(const struct fwnode_handle *fwnode);
|
|
|
|
enum dev_dma_attr
|
|
|
|
(*device_get_dma_attr)(const struct fwnode_handle *fwnode);
|
2017-07-21 11:39:36 +00:00
|
|
|
bool (*property_present)(const struct fwnode_handle *fwnode,
|
2017-06-06 09:37:37 +00:00
|
|
|
const char *propname);
|
2017-07-21 11:39:36 +00:00
|
|
|
int (*property_read_int_array)(const struct fwnode_handle *fwnode,
|
2017-06-06 09:37:37 +00:00
|
|
|
const char *propname,
|
|
|
|
unsigned int elem_size, void *val,
|
|
|
|
size_t nval);
|
2017-07-21 11:39:36 +00:00
|
|
|
int
|
|
|
|
(*property_read_string_array)(const struct fwnode_handle *fwnode_handle,
|
|
|
|
const char *propname, const char **val,
|
|
|
|
size_t nval);
|
2019-10-03 12:32:12 +00:00
|
|
|
const char *(*get_name)(const struct fwnode_handle *fwnode);
|
2019-10-03 12:32:13 +00:00
|
|
|
const char *(*get_name_prefix)(const struct fwnode_handle *fwnode);
|
2017-07-21 11:39:36 +00:00
|
|
|
struct fwnode_handle *(*get_parent)(const struct fwnode_handle *fwnode);
|
2017-06-06 09:37:37 +00:00
|
|
|
struct fwnode_handle *
|
2017-07-21 11:39:36 +00:00
|
|
|
(*get_next_child_node)(const struct fwnode_handle *fwnode,
|
2017-06-06 09:37:37 +00:00
|
|
|
struct fwnode_handle *child);
|
|
|
|
struct fwnode_handle *
|
2017-07-21 11:39:36 +00:00
|
|
|
(*get_named_child_node)(const struct fwnode_handle *fwnode,
|
|
|
|
const char *name);
|
2017-07-21 12:11:49 +00: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 09:37:38 +00:00
|
|
|
struct fwnode_handle *
|
2017-07-21 11:39:36 +00:00
|
|
|
(*graph_get_next_endpoint)(const struct fwnode_handle *fwnode,
|
2017-06-06 09:37:38 +00:00
|
|
|
struct fwnode_handle *prev);
|
|
|
|
struct fwnode_handle *
|
2017-07-21 11:39:36 +00:00
|
|
|
(*graph_get_remote_endpoint)(const struct fwnode_handle *fwnode);
|
2017-06-06 09:37:38 +00:00
|
|
|
struct fwnode_handle *
|
|
|
|
(*graph_get_port_parent)(struct fwnode_handle *fwnode);
|
2017-07-21 11:39:36 +00:00
|
|
|
int (*graph_parse_endpoint)(const struct fwnode_handle *fwnode,
|
2017-06-06 09:37:38 +00:00
|
|
|
struct fwnode_endpoint *endpoint);
|
2022-03-31 12:54:49 +00:00
|
|
|
void __iomem *(*iomap)(struct fwnode_handle *fwnode, int index);
|
2022-03-31 12:54:50 +00:00
|
|
|
int (*irq_get)(const struct fwnode_handle *fwnode, unsigned int index);
|
2020-11-21 02:02:32 +00:00
|
|
|
int (*add_links)(struct fwnode_handle *fwnode);
|
2017-06-06 09:37:37 +00:00
|
|
|
};
|
|
|
|
|
2022-04-08 18:48:40 +00:00
|
|
|
#define fwnode_has_op(fwnode, op) \
|
|
|
|
(!IS_ERR_OR_NULL(fwnode) && (fwnode)->ops && (fwnode)->ops->op)
|
|
|
|
|
2017-06-06 09:37:37 +00:00
|
|
|
#define fwnode_call_int_op(fwnode, op, ...) \
|
2022-04-08 18:48:40 +00:00
|
|
|
(fwnode_has_op(fwnode, op) ? \
|
|
|
|
(fwnode)->ops->op(fwnode, ## __VA_ARGS__) : (IS_ERR_OR_NULL(fwnode) ? -EINVAL : -ENXIO))
|
2019-08-23 20:32:27 +00:00
|
|
|
|
|
|
|
#define fwnode_call_bool_op(fwnode, op, ...) \
|
|
|
|
(fwnode_has_op(fwnode, op) ? \
|
|
|
|
(fwnode)->ops->op(fwnode, ## __VA_ARGS__) : false)
|
|
|
|
|
2017-06-06 09:37:37 +00: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-04 21:11:20 +00:00
|
|
|
#define get_dev_from_fwnode(fwnode) get_device((fwnode)->dev)
|
2017-06-06 09:37:37 +00:00
|
|
|
|
2020-11-21 02:02:22 +00:00
|
|
|
static inline void fwnode_init(struct fwnode_handle *fwnode,
|
|
|
|
const struct fwnode_operations *ops)
|
|
|
|
{
|
|
|
|
fwnode->ops = ops;
|
2020-11-21 02:02:23 +00:00
|
|
|
INIT_LIST_HEAD(&fwnode->consumers);
|
|
|
|
INIT_LIST_HEAD(&fwnode->suppliers);
|
2020-11-21 02:02:22 +00:00
|
|
|
}
|
|
|
|
|
2021-02-05 22:26:41 +00:00
|
|
|
static inline void fwnode_dev_initialized(struct fwnode_handle *fwnode,
|
|
|
|
bool initialized)
|
|
|
|
{
|
|
|
|
if (IS_ERR_OR_NULL(fwnode))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (initialized)
|
|
|
|
fwnode->flags |= FWNODE_FLAG_INITIALIZED;
|
|
|
|
else
|
|
|
|
fwnode->flags &= ~FWNODE_FLAG_INITIALIZED;
|
|
|
|
}
|
|
|
|
|
2020-02-22 01:40:35 +00:00
|
|
|
extern u32 fw_devlink_get_flags(void);
|
2021-02-05 22:26:39 +00:00
|
|
|
extern bool fw_devlink_is_strict(void);
|
2020-11-21 02:02:23 +00:00
|
|
|
int fwnode_link_add(struct fwnode_handle *con, struct fwnode_handle *sup);
|
|
|
|
void fwnode_links_purge(struct fwnode_handle *fwnode);
|
2021-05-06 00:44:22 +00:00
|
|
|
void fw_devlink_purge_absent_suppliers(struct fwnode_handle *fwnode);
|
2020-02-22 01:40:35 +00:00
|
|
|
|
2015-03-16 22:49:03 +00:00
|
|
|
#endif
|