Skip to content

Commit a2183f9

Browse files
committed
drivers: video: Introduce video device structure
Introduce a new video device structure representing a device in a video pipeline. Each video device embeds a pointer to its "source" device and other "video" characteristics. This structure give the video framework an access to all video features of the device and a hierachical view of the video pipeline that the device belongs to. Signed-off-by: Phi Bang Nguyen <phibang.nguyen@nxp.com>
1 parent 651ecab commit a2183f9

19 files changed

+139
-24
lines changed

cmake/linker_script/common/common-ram.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@ if(CONFIG_UVB)
125125
zephyr_iterable_section(NAME uvb_node GROUP DATA_REGION ${XIP_ALIGN_WITH_INPUT} SUBALIGN ${CONFIG_LINKER_ITERABLE_SUBALIGN})
126126
endif()
127127

128+
if(CONFIG_VIDEO)
129+
zephyr_iterable_section(NAME video_device GROUP DATA_REGION ${XIP_ALIGN_WITH_INPUT} SUBALIGN ${CONFIG_LINKER_ITERABLE_SUBALIGN})
130+
endif()
128131

129132
if(CONFIG_LOG)
130133
zephyr_iterable_section(NAME log_mpsc_pbuf GROUP DATA_REGION ${XIP_ALIGN_WITH_INPUT} SUBALIGN ${CONFIG_LINKER_ITERABLE_SUBALIGN})

drivers/video/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
zephyr_library()
44

55
zephyr_library_sources(video_common.c)
6+
zephyr_library_sources(video_device.c)
67

78
zephyr_library_sources_ifdef(CONFIG_VIDEO_MCUX_CSI video_mcux_csi.c)
89
zephyr_library_sources_ifdef(CONFIG_VIDEO_MCUX_MIPI_CSI2RX video_mcux_mipi_csi2rx.c)
@@ -18,3 +19,5 @@ zephyr_library_sources_ifdef(CONFIG_VIDEO_ESP32 video_esp32_dvp.c)
1819
zephyr_library_sources_ifdef(CONFIG_VIDEO_MCUX_SDMA video_mcux_smartdma.c)
1920
zephyr_library_sources_ifdef(CONFIG_VIDEO_EMUL_IMAGER video_emul_imager.c)
2021
zephyr_library_sources_ifdef(CONFIG_VIDEO_EMUL_RX video_emul_rx.c)
22+
23+
zephyr_linker_sources(DATA_SECTIONS video.ld)

drivers/video/gc2145.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
#include <zephyr/drivers/gpio.h>
1515

1616
#include <zephyr/logging/log.h>
17+
18+
#include "video_device.h"
19+
1720
LOG_MODULE_REGISTER(video_gc2145, CONFIG_VIDEO_LOG_LEVEL);
1821

1922
#define GC2145_REG_AMODE1 0x17
@@ -1208,3 +1211,5 @@ static int gc2145_init_0(const struct device *dev)
12081211

12091212
DEVICE_DT_INST_DEFINE(0, &gc2145_init_0, NULL, &gc2145_data_0, &gc2145_cfg_0, POST_KERNEL,
12101213
CONFIG_VIDEO_INIT_PRIORITY, &gc2145_driver_api);
1214+
1215+
VIDEO_DEVICE_DEFINE(gc2145, DEVICE_DT_INST_GET(0), NULL);

drivers/video/mt9m114.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
#include <zephyr/drivers/video-controls.h>
1616
#include <zephyr/drivers/i2c.h>
1717

18+
#include "video_device.h"
19+
1820
LOG_MODULE_REGISTER(video_mt9m114, CONFIG_VIDEO_LOG_LEVEL);
1921

2022
#define MT9M114_CHIP_ID_VAL 0x2481
@@ -569,4 +571,7 @@ static int mt9m114_init_0(const struct device *dev)
569571

570572
DEVICE_DT_INST_DEFINE(0, &mt9m114_init_0, NULL, &mt9m114_data_0, &mt9m114_cfg_0, POST_KERNEL,
571573
CONFIG_VIDEO_INIT_PRIORITY, &mt9m114_driver_api);
574+
575+
VIDEO_DEVICE_DEFINE(mt9m114, DEVICE_DT_INST_GET(0), NULL);
576+
572577
#endif

drivers/video/ov2640.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
#include <zephyr/drivers/i2c.h>
1515
#include <zephyr/drivers/gpio.h>
1616

17+
#include "video_device.h"
18+
1719
LOG_MODULE_REGISTER(video_ov2640, CONFIG_VIDEO_LOG_LEVEL);
1820

1921
/* DSP register bank FF=0x00*/
@@ -1062,3 +1064,5 @@ DEVICE_DT_INST_DEFINE(0, &ov2640_init_0, NULL,
10621064
&ov2640_data_0, &ov2640_cfg_0,
10631065
POST_KERNEL, CONFIG_VIDEO_INIT_PRIORITY,
10641066
&ov2640_driver_api);
1067+
1068+
VIDEO_DEVICE_DEFINE(ov2640, DEVICE_DT_INST_GET(0), NULL);

drivers/video/ov5640.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#include <zephyr/drivers/video-controls.h>
2020
#include <zephyr/dt-bindings/video/video-interfaces.h>
2121

22+
#include "video_device.h"
23+
2224
LOG_MODULE_REGISTER(video_ov5640, CONFIG_VIDEO_LOG_LEVEL);
2325

2426
#define CHIP_ID_REG 0x300a
@@ -1333,6 +1335,8 @@ static int ov5640_init(const struct device *dev)
13331335
}; \
13341336
\
13351337
DEVICE_DT_INST_DEFINE(n, &ov5640_init, NULL, &ov5640_data_##n, &ov5640_cfg_##n, \
1336-
POST_KERNEL, CONFIG_VIDEO_INIT_PRIORITY, &ov5640_driver_api);
1338+
POST_KERNEL, CONFIG_VIDEO_INIT_PRIORITY, &ov5640_driver_api); \
1339+
\
1340+
VIDEO_DEVICE_DEFINE(ov5640_##n, DEVICE_DT_INST_GET(n), NULL);
13371341

13381342
DT_INST_FOREACH_STATUS_OKAY(OV5640_INIT)

drivers/video/ov7670.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
#include <zephyr/drivers/video-controls.h>
1313
#include <zephyr/logging/log.h>
1414

15+
#include "video_device.h"
16+
1517
LOG_MODULE_REGISTER(video_ov7670, CONFIG_VIDEO_LOG_LEVEL);
1618

1719
/* Initialization register structure */
@@ -598,6 +600,8 @@ static DEVICE_API(video, ov7670_api) = {
598600
struct ov7670_data ov7670_data_##inst; \
599601
\
600602
DEVICE_DT_INST_DEFINE(inst, ov7670_init, NULL, &ov7670_data_##inst, &ov7670_config_##inst, \
601-
POST_KERNEL, CONFIG_VIDEO_INIT_PRIORITY, &ov7670_api);
603+
POST_KERNEL, CONFIG_VIDEO_INIT_PRIORITY, &ov7670_api); \
604+
\
605+
VIDEO_DEVICE_DEFINE(ov7670_##inst, DEVICE_DT_INST_GET(inst), NULL);
602606

603607
DT_INST_FOREACH_STATUS_OKAY(OV7670_INIT)

drivers/video/ov7725.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
#include <zephyr/drivers/i2c.h>
1515
#include <zephyr/drivers/gpio.h>
1616

17+
#include "video_device.h"
18+
1719
LOG_MODULE_REGISTER(video_ov7725, CONFIG_VIDEO_LOG_LEVEL);
1820

1921
#define OV7725_REVISION 0x7721U
@@ -639,3 +641,5 @@ DEVICE_DT_INST_DEFINE(0, &ov7725_init_0, NULL,
639641
&ov7725_data_0, &ov7725_cfg_0,
640642
POST_KERNEL, CONFIG_VIDEO_INIT_PRIORITY,
641643
&ov7725_driver_api);
644+
645+
VIDEO_DEVICE_DEFINE(ov7725, DEVICE_DT_INST_GET(0), NULL);

drivers/video/video.ld

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#include <zephyr/linker/iterable_sections.h>
2+
3+
ITERABLE_SECTION_RAM(video_device, Z_LINK_ITERABLE_SUBALIGN)

drivers/video/video_device.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Copyright 2025 NXP
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include "video_device.h"
8+
9+
struct video_device *video_find_vdev(const struct device *dev)
10+
{
11+
if (!dev) {
12+
return NULL;
13+
}
14+
15+
STRUCT_SECTION_FOREACH(video_device, vdev) {
16+
if (vdev->dev == dev) {
17+
return vdev;
18+
}
19+
}
20+
21+
return NULL;
22+
}

0 commit comments

Comments
 (0)