Skip to content

Commit

Permalink
drivers: video: Use endpoint DT helpers
Browse files Browse the repository at this point in the history
Drop the driver-defined macros to use the endpoint DT helpers instead.

Signed-off-by: Phi Bang Nguyen <[email protected]>
  • Loading branch information
ngphibang committed Dec 6, 2024
1 parent 6c08072 commit 1ea737e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 45 deletions.
27 changes: 2 additions & 25 deletions drivers/video/video_emul_rx.c
Original file line number Diff line number Diff line change
Expand Up @@ -294,33 +294,10 @@ int emul_rx_init(const struct device *dev)
return 0;
}

/* See #80649 */

/* Handle the variability of "ports{port@0{}};" vs "port{};" while going down */
#define DT_INST_PORT_BY_ID(inst, pid) \
COND_CODE_1(DT_NODE_EXISTS(DT_INST_CHILD(inst, ports)), \
(DT_CHILD(DT_INST_CHILD(inst, ports), port_##pid)), \
(DT_INST_CHILD(inst, port)))

/* Handle the variability of "endpoint@0{};" vs "endpoint{};" while going down */
#define DT_INST_ENDPOINT_BY_ID(inst, pid, eid) \
COND_CODE_1(DT_NODE_EXISTS(DT_CHILD(DT_INST_PORT_BY_ID(inst, pid), endpoint)), \
(DT_CHILD(DT_INST_PORT_BY_ID(inst, pid), endpoint)), \
(DT_CHILD(DT_INST_PORT_BY_ID(inst, pid), endpoint_##eid)))

/* Handle the variability of "ports{port@0{}};" vs "port{};" while going up */
#define DT_ENDPOINT_PARENT_DEVICE(node) \
COND_CODE_1(DT_NODE_EXISTS(DT_CHILD(DT_GPARENT(node), port)), \
(DT_GPARENT(node)), (DT_PARENT(DT_GPARENT(node))))

/* Handle the "remote-endpoint-label" */
#define DEVICE_DT_GET_REMOTE_DEVICE(node) \
DEVICE_DT_GET(DT_ENDPOINT_PARENT_DEVICE( \
DT_NODELABEL(DT_STRING_TOKEN(node, remote_endpoint_label))))

#define EMUL_RX_DEFINE(n) \
static const struct emul_rx_config emul_rx_cfg_##n = { \
.source_dev = DEVICE_DT_GET_REMOTE_DEVICE(DT_INST_ENDPOINT_BY_ID(n, 0, 0)), \
.source_dev = \
DEVICE_DT_GET(DT_NODE_REMOTE_DEVICE(DT_INST_ENDPOINT_BY_ID(n, 0, 0))), \
}; \
\
static struct emul_rx_data emul_rx_data_##n = { \
Expand Down
12 changes: 1 addition & 11 deletions drivers/video/video_mcux_csi.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,6 @@
#include <fsl_cache.h>
#endif

#if defined(CONFIG_VIDEO_MCUX_MIPI_CSI2RX)
#define DEVICE_DT_INST_GET_SOURCE_DEV(n) \
DEVICE_DT_GET(DT_PARENT(DT_GPARENT(DT_NODELABEL(DT_STRING_TOKEN( \
DT_CHILD(DT_INST_CHILD(n, port), endpoint), remote_endpoint_label)))))
#else
#define DEVICE_DT_INST_GET_SOURCE_DEV(n) \
DEVICE_DT_GET(DT_GPARENT(DT_NODELABEL(DT_STRING_TOKEN( \
DT_CHILD(DT_INST_CHILD(n, port), endpoint), remote_endpoint_label))))
#endif

struct video_mcux_csi_config {
CSI_Type *base;
const struct device *source_dev;
Expand Down Expand Up @@ -502,7 +492,7 @@ PINCTRL_DT_INST_DEFINE(0);

static const struct video_mcux_csi_config video_mcux_csi_config_0 = {
.base = (CSI_Type *)DT_INST_REG_ADDR(0),
.source_dev = DEVICE_DT_INST_GET_SOURCE_DEV(0),
.source_dev = DEVICE_DT_GET(DT_NODE_REMOTE_DEVICE(DT_INST_ENDPOINT_BY_ID(0, 0, 0))),
.pincfg = PINCTRL_DT_INST_DEV_CONFIG_GET(0),
};

Expand Down
12 changes: 3 additions & 9 deletions drivers/video/video_mcux_mipi_csi2rx.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ LOG_MODULE_REGISTER(video_mipi_csi2rx, CONFIG_VIDEO_LOG_LEVEL);

#define ABS(a, b) (a > b ? a - b : b - a)

#define DEVICE_DT_INST_GET_SENSOR_DEV(n) \
DEVICE_DT_GET(DT_GPARENT(DT_NODELABEL( \
DT_STRING_TOKEN(DT_CHILD(DT_CHILD(DT_INST_CHILD(n, ports), port_1), endpoint), \
remote_endpoint_label))))

struct mipi_csi2rx_config {
const MIPI_CSI2RX_Type *base;
const struct device *sensor_dev;
Expand Down Expand Up @@ -349,9 +344,7 @@ static int mipi_csi2rx_init(const struct device *dev)

#define MIPI_CSI2RX_INIT(n) \
static struct mipi_csi2rx_data mipi_csi2rx_data_##n = { \
.csi2rxConfig.laneNum = \
DT_PROP_LEN(DT_CHILD(DT_CHILD(DT_INST_CHILD(n, ports), port_1), endpoint), \
data_lanes), \
.csi2rxConfig.laneNum = DT_PROP_LEN(DT_INST_ENDPOINT_BY_ID(n, 1, 0), data_lanes), \
.clock_dev = DEVICE_DT_GET(DT_INST_CLOCKS_CTLR(n)), \
.clock_root = (clock_control_subsys_t)DT_INST_CLOCKS_CELL_BY_IDX(n, 0, name), \
.clock_ui = (clock_control_subsys_t)DT_INST_CLOCKS_CELL_BY_IDX(n, 1, name), \
Expand All @@ -360,7 +353,8 @@ static int mipi_csi2rx_init(const struct device *dev)
\
static const struct mipi_csi2rx_config mipi_csi2rx_config_##n = { \
.base = (MIPI_CSI2RX_Type *)DT_INST_REG_ADDR(n), \
.sensor_dev = DEVICE_DT_INST_GET_SENSOR_DEV(n), \
.sensor_dev = \
DEVICE_DT_GET(DT_NODE_REMOTE_DEVICE(DT_INST_ENDPOINT_BY_ID(n, 1, 0))), \
}; \
\
DEVICE_DT_INST_DEFINE(n, &mipi_csi2rx_init, NULL, &mipi_csi2rx_data_##n, \
Expand Down

0 comments on commit 1ea737e

Please sign in to comment.