Skip to content

Commit

Permalink
devicetree: add macros to deal with endpoints
Browse files Browse the repository at this point in the history
Add macros to access the port/endpoint constructs from drivers and
application.

Devicetrees currently use "port { endpoint { ... }; };" to describe
interconnection between devices. With introduction of the
"remote-endpoint-label = string" syntax, it is now possible to
describe circular dependencies until #57708 is addressed.

Signed-off-by: Josuah Demangeon <[email protected]>
  • Loading branch information
josuah committed Oct 18, 2024
1 parent 829c03b commit d7c9533
Showing 1 changed file with 86 additions and 0 deletions.
86 changes: 86 additions & 0 deletions include/zephyr/devicetree.h
Original file line number Diff line number Diff line change
Expand Up @@ -3787,6 +3787,92 @@
*/
#define DT_ON_BUS(node_id, bus) IS_ENABLED(DT_CAT3(node_id, _BUS_, bus))

/**
* @}
*/

/**
* @defgroup devicetree-generic-endpoint Endpoint helpers
* @ingroup devicetree
* @{
*/

/**
* @brief Get the remote endpoint node connected to a local endpoint.
*
* Some devices, such as video devices, can be interconnected through port and endpoints.
*
* For a selected node's endpoint, the remote endpoint connected to it can be access through
* @ref DT_REMOTE_ENDPOINT().
* This remote endpoint node can then be accessed using other macros to read its properties.
*
* Example devicetree overlay:
*
* @code{.dts}
* &sink {
* port {
* sink_in: endpoint@123 {
* remote-endpoint-label = "source_out";
* };
* };
* };
*
* &source {
* port {
* source_out: endpoint {
* remote-endpoint-label = "sink_in";
* };
* };
* };
* @endcode
*
* Example usage: starting from the sink, access the source endpoint connected to @c endpoint@123:
*
* @code{.c}
* DT_REMOTE_ENDPOINT(DT_NODELABEL(sink_in), port, endpoint_123)
* @endcode
*
* Example usage, starting from the source, to access the sink endpoint connected to @c endpoint:
*
* @code{.c}
* DT_REMOTE_ENDPOINT(DT_NODELABEL(source_out), port, endpoint)
* @endcode
*
* @note Once circular phandle references are supported, @c remote-endpoint-label (string) may be
* changed into @c remote-endpoint (phandle).
*
* @param node The local node.
* @param port The port to search.
* @param ep The endpoint to search.
*
* @return The remote node of the endpoint connected to @p port, @p ep.
*/
#define DT_REMOTE_ENDPOINT(node, port, ep) \
DT_NODELABEL(DT_STRING_TOKEN(DT_CHILD(DT_CHILD(node, port), ep), remote_endpoint_label))

/**
* @brief Get the remote device node connected to a local endpoint.
*
* For a given node, return the remote endpoint node connected to the specified port and endpoint.
* This permit accessing the remote device properties.
*
* Example usage, starting from the sink, to access the source device connected to @c endpoint@123:
*
* @code{.c}
* DT_REMOTE_ENDPOINT(DT_NODELABEL(sink_in), port, endpoint_123)
* @endcode
*
* @note Once circular phandle references are supported, @c remote-endpoint-label (string) may be
* changed into @c remote-endpoint (phandle).
*
* @param node The local node.
* @param port The port to search.
* @param ep The endpoint to search.
*
* @return The remote node of the device connected to @p port, @p ep.
*/
#define DT_REMOTE_DEVICE(node, port, ep) DT_GPARENT(DT_REMOTE_ENDPOINT(node, port, ep))

/**
* @}
*/
Expand Down

0 comments on commit d7c9533

Please sign in to comment.