From 3fb4e4f7fc41dc3b0108e6192d3b93ed6a5677e0 Mon Sep 17 00:00:00 2001 From: Josuah Demangeon Date: Mon, 20 May 2024 14:04:17 +0200 Subject: [PATCH] drivers: video: add a struct video_dt_spec and C macro This introduces a video_dt_spec that can be used by the APIs to refer one particular video endpoint out of a video device and refer it in one go. Signed-off-by: Josuah Demangeon --- include/zephyr/drivers/video.h | 36 ++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/include/zephyr/drivers/video.h b/include/zephyr/drivers/video.h index d3cd7cfaf98b9bd..b2899d32933f2d4 100644 --- a/include/zephyr/drivers/video.h +++ b/include/zephyr/drivers/video.h @@ -33,6 +33,42 @@ extern "C" { #endif +/** + * @brief Video Device Tree endpoint identifier + * + * Identify a particular port and particular endpoint of a video device, + * providing all the context necessary to act upon a video device, via one of + * its endpoint. + */ +struct video_dt_spec { + /** Device instance of the remote video device to communicate with. */ + const struct device *dev; + /** Devicetree address for this endpoint. */ + uint32_t endpoint; +}; + +/** + * @brief Get a device reference for an endpoint of a video controller. + * + * @code + * mipi0: mipi-controller@... { + * mipi0out: endpoint@0 { + * remote-endpoint = <&mjpeg0in>; + * }; + * }; + * @endcode + * + * Here, the devicetree spec for mipi0out can be obtaine with: + * + * @code + * struct video_dt_spec spec = VIDEO_DT_SPEC_GET(DT_NODELABEL(mipi0out)); + * @endcode + * + * @param node_id node identifier of an endpoint phandle property + */ +#define VIDEO_DT_SPEC_GET(node_id) \ + {.dev = DEVICE_DT_GET(DT_BUS(node_id)), .endpoint = VIDEO_DT_ENDPOINT_ID(node_id)} + /** * Obtain the endpoint ID out of an devicetree endpoint node. *