Skip to content

Commit de10d70

Browse files
committed
drivers: video: Add endpoint DT helpers
Add port/endpoint DT helpers so that drivers can retrieve the node id of the interested port/endpoint just by its id. Also, add helpers to retrieve the peer remote device object from the local endpoint. Signed-off-by: Phi Bang Nguyen <phibang.nguyen@nxp.com> Co-developed-by: Josuah Demangeon <me@josuah.net>
1 parent 0348270 commit de10d70

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

include/zephyr/drivers/video.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,38 @@ struct video_frmival_enum {
202202
};
203203
};
204204

205+
/**
206+
* @brief Port / Endpoint DT Helpers
207+
*
208+
*/
209+
210+
#define _DT_INST_PORT_BY_ID(n, pid) \
211+
COND_CODE_1(DT_NODE_EXISTS(DT_INST_CHILD(n, ports)), \
212+
(DT_CHILD(DT_INST_CHILD(n, ports), port_##pid)), (DT_INST_CHILD(n, port_##pid)))
213+
214+
/* pid = 0 means port_0 or port (without id). It works for both cases */
215+
#define DT_INST_PORT_BY_ID(n, pid) \
216+
COND_CODE_1(DT_NODE_EXISTS(_DT_INST_PORT_BY_ID(n, pid)), \
217+
(_DT_INST_PORT_BY_ID(n, pid)), (DT_INST_CHILD(n, port)))
218+
219+
#define _DT_INST_ENDPOINT_BY_ID(n, pid, eid) DT_CHILD(DT_INST_PORT_BY_ID(n, pid), endpoint_##eid)
220+
221+
/* pid/eid = 0 means port_0/endpoint_0 or port/endpoint (without id) */
222+
#define DT_INST_ENDPOINT_BY_ID(n, pid, eid) \
223+
COND_CODE_1(DT_NODE_EXISTS(_DT_INST_ENDPOINT_BY_ID(n, pid, eid)), \
224+
(_DT_INST_ENDPOINT_BY_ID(n, pid, eid)), \
225+
(DT_CHILD(DT_INST_PORT_BY_ID(n, pid), endpoint)))
226+
227+
/* Get node id of the device from its local endpoint node id */
228+
#define _DT_NODE_BY_ENDPOINT(ep) \
229+
COND_CODE_1(DT_NODE_EXISTS(DT_CHILD(DT_PARENT(DT_GPARENT(ep)), ports)), \
230+
(DT_PARENT(DT_GPARENT(ep))), (DT_GPARENT(ep)))
231+
232+
/* Get remote device object from the local endpoint node id */
233+
#define DEVICE_DT_GET_REMOTE_DEVICE(ep) \
234+
DEVICE_DT_GET( \
235+
_DT_NODE_BY_ENDPOINT(DT_NODELABEL(DT_STRING_TOKEN(ep, remote_endpoint_label))))
236+
205237
/**
206238
* @brief video_endpoint_id enum
207239
*

0 commit comments

Comments
 (0)