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>
This commit is contained in:
parent
d5201e179f
commit
2b46cc0b78
19 changed files with 139 additions and 24 deletions
|
@ -125,6 +125,9 @@ if(CONFIG_UVB)
|
|||
zephyr_iterable_section(NAME uvb_node GROUP DATA_REGION ${XIP_ALIGN_WITH_INPUT} SUBALIGN ${CONFIG_LINKER_ITERABLE_SUBALIGN})
|
||||
endif()
|
||||
|
||||
if(CONFIG_VIDEO)
|
||||
zephyr_iterable_section(NAME video_device GROUP DATA_REGION ${XIP_ALIGN_WITH_INPUT} SUBALIGN ${CONFIG_LINKER_ITERABLE_SUBALIGN})
|
||||
endif()
|
||||
|
||||
if(CONFIG_LOG)
|
||||
zephyr_iterable_section(NAME log_mpsc_pbuf GROUP DATA_REGION ${XIP_ALIGN_WITH_INPUT} SUBALIGN ${CONFIG_LINKER_ITERABLE_SUBALIGN})
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
zephyr_library()
|
||||
|
||||
zephyr_library_sources(video_common.c)
|
||||
zephyr_library_sources(video_device.c)
|
||||
|
||||
zephyr_library_sources_ifdef(CONFIG_VIDEO_MCUX_CSI video_mcux_csi.c)
|
||||
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)
|
|||
zephyr_library_sources_ifdef(CONFIG_VIDEO_MCUX_SDMA video_mcux_smartdma.c)
|
||||
zephyr_library_sources_ifdef(CONFIG_VIDEO_EMUL_IMAGER video_emul_imager.c)
|
||||
zephyr_library_sources_ifdef(CONFIG_VIDEO_EMUL_RX video_emul_rx.c)
|
||||
|
||||
zephyr_linker_sources(DATA_SECTIONS video.ld)
|
||||
|
|
|
@ -14,6 +14,9 @@
|
|||
#include <zephyr/drivers/gpio.h>
|
||||
|
||||
#include <zephyr/logging/log.h>
|
||||
|
||||
#include "video_device.h"
|
||||
|
||||
LOG_MODULE_REGISTER(video_gc2145, CONFIG_VIDEO_LOG_LEVEL);
|
||||
|
||||
#define GC2145_REG_AMODE1 0x17
|
||||
|
@ -1208,3 +1211,5 @@ static int gc2145_init_0(const struct device *dev)
|
|||
|
||||
DEVICE_DT_INST_DEFINE(0, &gc2145_init_0, NULL, &gc2145_data_0, &gc2145_cfg_0, POST_KERNEL,
|
||||
CONFIG_VIDEO_INIT_PRIORITY, &gc2145_driver_api);
|
||||
|
||||
VIDEO_DEVICE_DEFINE(gc2145, DEVICE_DT_INST_GET(0), NULL);
|
||||
|
|
|
@ -15,6 +15,8 @@
|
|||
#include <zephyr/drivers/video-controls.h>
|
||||
#include <zephyr/drivers/i2c.h>
|
||||
|
||||
#include "video_device.h"
|
||||
|
||||
LOG_MODULE_REGISTER(video_mt9m114, CONFIG_VIDEO_LOG_LEVEL);
|
||||
|
||||
#define MT9M114_CHIP_ID_VAL 0x2481
|
||||
|
@ -569,4 +571,7 @@ static int mt9m114_init_0(const struct device *dev)
|
|||
|
||||
DEVICE_DT_INST_DEFINE(0, &mt9m114_init_0, NULL, &mt9m114_data_0, &mt9m114_cfg_0, POST_KERNEL,
|
||||
CONFIG_VIDEO_INIT_PRIORITY, &mt9m114_driver_api);
|
||||
|
||||
VIDEO_DEVICE_DEFINE(mt9m114, DEVICE_DT_INST_GET(0), NULL);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
#include <zephyr/drivers/i2c.h>
|
||||
#include <zephyr/drivers/gpio.h>
|
||||
|
||||
#include "video_device.h"
|
||||
|
||||
LOG_MODULE_REGISTER(video_ov2640, CONFIG_VIDEO_LOG_LEVEL);
|
||||
|
||||
/* DSP register bank FF=0x00*/
|
||||
|
@ -1062,3 +1064,5 @@ DEVICE_DT_INST_DEFINE(0, &ov2640_init_0, NULL,
|
|||
&ov2640_data_0, &ov2640_cfg_0,
|
||||
POST_KERNEL, CONFIG_VIDEO_INIT_PRIORITY,
|
||||
&ov2640_driver_api);
|
||||
|
||||
VIDEO_DEVICE_DEFINE(ov2640, DEVICE_DT_INST_GET(0), NULL);
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
#include <zephyr/drivers/video-controls.h>
|
||||
#include <zephyr/dt-bindings/video/video-interfaces.h>
|
||||
|
||||
#include "video_device.h"
|
||||
|
||||
LOG_MODULE_REGISTER(video_ov5640, CONFIG_VIDEO_LOG_LEVEL);
|
||||
|
||||
#define CHIP_ID_REG 0x300a
|
||||
|
@ -1333,6 +1335,8 @@ static int ov5640_init(const struct device *dev)
|
|||
}; \
|
||||
\
|
||||
DEVICE_DT_INST_DEFINE(n, &ov5640_init, NULL, &ov5640_data_##n, &ov5640_cfg_##n, \
|
||||
POST_KERNEL, CONFIG_VIDEO_INIT_PRIORITY, &ov5640_driver_api);
|
||||
POST_KERNEL, CONFIG_VIDEO_INIT_PRIORITY, &ov5640_driver_api); \
|
||||
\
|
||||
VIDEO_DEVICE_DEFINE(ov5640_##n, DEVICE_DT_INST_GET(n), NULL);
|
||||
|
||||
DT_INST_FOREACH_STATUS_OKAY(OV5640_INIT)
|
||||
|
|
|
@ -12,6 +12,8 @@
|
|||
#include <zephyr/drivers/video-controls.h>
|
||||
#include <zephyr/logging/log.h>
|
||||
|
||||
#include "video_device.h"
|
||||
|
||||
LOG_MODULE_REGISTER(video_ov7670, CONFIG_VIDEO_LOG_LEVEL);
|
||||
|
||||
/* Initialization register structure */
|
||||
|
@ -598,6 +600,8 @@ static DEVICE_API(video, ov7670_api) = {
|
|||
struct ov7670_data ov7670_data_##inst; \
|
||||
\
|
||||
DEVICE_DT_INST_DEFINE(inst, ov7670_init, NULL, &ov7670_data_##inst, &ov7670_config_##inst, \
|
||||
POST_KERNEL, CONFIG_VIDEO_INIT_PRIORITY, &ov7670_api);
|
||||
POST_KERNEL, CONFIG_VIDEO_INIT_PRIORITY, &ov7670_api); \
|
||||
\
|
||||
VIDEO_DEVICE_DEFINE(ov7670_##inst, DEVICE_DT_INST_GET(inst), NULL);
|
||||
|
||||
DT_INST_FOREACH_STATUS_OKAY(OV7670_INIT)
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
#include <zephyr/drivers/i2c.h>
|
||||
#include <zephyr/drivers/gpio.h>
|
||||
|
||||
#include "video_device.h"
|
||||
|
||||
LOG_MODULE_REGISTER(video_ov7725, CONFIG_VIDEO_LOG_LEVEL);
|
||||
|
||||
#define OV7725_REVISION 0x7721U
|
||||
|
@ -639,3 +641,5 @@ DEVICE_DT_INST_DEFINE(0, &ov7725_init_0, NULL,
|
|||
&ov7725_data_0, &ov7725_cfg_0,
|
||||
POST_KERNEL, CONFIG_VIDEO_INIT_PRIORITY,
|
||||
&ov7725_driver_api);
|
||||
|
||||
VIDEO_DEVICE_DEFINE(ov7725, DEVICE_DT_INST_GET(0), NULL);
|
||||
|
|
3
drivers/video/video.ld
Normal file
3
drivers/video/video.ld
Normal file
|
@ -0,0 +1,3 @@
|
|||
#include <zephyr/linker/iterable_sections.h>
|
||||
|
||||
ITERABLE_SECTION_RAM(video_device, Z_LINK_ITERABLE_SUBALIGN)
|
22
drivers/video/video_device.c
Normal file
22
drivers/video/video_device.c
Normal file
|
@ -0,0 +1,22 @@
|
|||
/*
|
||||
* Copyright 2025 NXP
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include "video_device.h"
|
||||
|
||||
struct video_device *video_find_vdev(const struct device *dev)
|
||||
{
|
||||
if (!dev) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
STRUCT_SECTION_FOREACH(video_device, vdev) {
|
||||
if (vdev->dev == dev) {
|
||||
return vdev;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
25
drivers/video/video_device.h
Normal file
25
drivers/video/video_device.h
Normal file
|
@ -0,0 +1,25 @@
|
|||
/*
|
||||
* Copyright 2025 NXP
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#ifndef ZEPHYR_INCLUDE_DRIVERS_VIDEO_VIDEO_DEVICE_H_
|
||||
#define ZEPHYR_INCLUDE_DRIVERS_VIDEO_VIDEO_DEVICE_H_
|
||||
|
||||
#include <zephyr/device.h>
|
||||
|
||||
struct video_device {
|
||||
const struct device *dev;
|
||||
const struct device *src_dev;
|
||||
};
|
||||
|
||||
#define VIDEO_DEVICE_DEFINE(name, device, source) \
|
||||
static STRUCT_SECTION_ITERABLE(video_device, name) = { \
|
||||
.dev = device, \
|
||||
.src_dev = source, \
|
||||
}
|
||||
|
||||
struct video_device *video_find_vdev(const struct device *dev);
|
||||
|
||||
#endif /* ZEPHYR_INCLUDE_DRIVERS_VIDEO_VIDEO_DEVICE_H_ */
|
|
@ -17,6 +17,8 @@
|
|||
#include <zephyr/drivers/i2c.h>
|
||||
#include <zephyr/logging/log.h>
|
||||
|
||||
#include "video_device.h"
|
||||
|
||||
LOG_MODULE_REGISTER(video_emul_imager, CONFIG_VIDEO_LOG_LEVEL);
|
||||
|
||||
#define EMUL_IMAGER_REG_SENSOR_ID 0x0000
|
||||
|
@ -427,6 +429,8 @@ int emul_imager_init(const struct device *dev)
|
|||
\
|
||||
DEVICE_DT_INST_DEFINE(inst, &emul_imager_init, NULL, &emul_imager_data_##inst, \
|
||||
&emul_imager_cfg_##inst, POST_KERNEL, CONFIG_VIDEO_INIT_PRIORITY, \
|
||||
&emul_imager_driver_api);
|
||||
&emul_imager_driver_api); \
|
||||
\
|
||||
VIDEO_DEVICE_DEFINE(emul_imager_##inst, DEVICE_DT_INST_GET(inst), NULL);
|
||||
|
||||
DT_INST_FOREACH_STATUS_OKAY(EMUL_IMAGER_DEFINE)
|
||||
|
|
|
@ -15,6 +15,8 @@
|
|||
#include <zephyr/drivers/i2c.h>
|
||||
#include <zephyr/logging/log.h>
|
||||
|
||||
#include "video_device.h"
|
||||
|
||||
LOG_MODULE_REGISTER(video_emul_rx, CONFIG_VIDEO_LOG_LEVEL);
|
||||
|
||||
struct emul_rx_config {
|
||||
|
@ -296,6 +298,8 @@ int emul_rx_init(const struct device *dev)
|
|||
}; \
|
||||
\
|
||||
DEVICE_DT_INST_DEFINE(n, &emul_rx_init, NULL, &emul_rx_data_##n, &emul_rx_cfg_##n, \
|
||||
POST_KERNEL, CONFIG_VIDEO_INIT_PRIORITY, &emul_rx_driver_api);
|
||||
POST_KERNEL, CONFIG_VIDEO_INIT_PRIORITY, &emul_rx_driver_api); \
|
||||
\
|
||||
VIDEO_DEVICE_DEFINE(emul_rx_##n, DEVICE_DT_INST_GET(n), emul_rx_cfg_##n.source_dev);
|
||||
|
||||
DT_INST_FOREACH_STATUS_OKAY(EMUL_RX_DEFINE)
|
||||
|
|
|
@ -21,6 +21,9 @@
|
|||
#include <hal/cam_ll.h>
|
||||
|
||||
#include <zephyr/logging/log.h>
|
||||
|
||||
#include "video_device.h"
|
||||
|
||||
LOG_MODULE_REGISTER(video_esp32_lcd_cam, CONFIG_VIDEO_LOG_LEVEL);
|
||||
|
||||
#define VIDEO_ESP32_DMA_BUFFER_MAX_SIZE 4095
|
||||
|
@ -463,6 +466,8 @@ static struct video_esp32_data esp32_data = {0};
|
|||
DEVICE_DT_INST_DEFINE(0, video_esp32_init, NULL, &esp32_data, &esp32_config, POST_KERNEL,
|
||||
CONFIG_VIDEO_INIT_PRIORITY, &esp32_driver_api);
|
||||
|
||||
VIDEO_DEVICE_DEFINE(esp32, DEVICE_DT_INST_GET(0), esp32_config.source_dev);
|
||||
|
||||
static int video_esp32_cam_init_master_clock(void)
|
||||
{
|
||||
int ret = 0;
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
#include <fsl_cache.h>
|
||||
#endif
|
||||
|
||||
#include "video_device.h"
|
||||
|
||||
struct video_mcux_csi_config {
|
||||
CSI_Type *base;
|
||||
const struct device *source_dev;
|
||||
|
@ -506,4 +508,7 @@ static int video_mcux_csi_init_0(const struct device *dev)
|
|||
DEVICE_DT_INST_DEFINE(0, &video_mcux_csi_init_0, NULL, &video_mcux_csi_data_0,
|
||||
&video_mcux_csi_config_0, POST_KERNEL, CONFIG_VIDEO_MCUX_CSI_INIT_PRIORITY,
|
||||
&video_mcux_csi_driver_api);
|
||||
|
||||
VIDEO_DEVICE_DEFINE(csi, DEVICE_DT_INST_GET(0), video_mcux_csi_config_0.source_dev);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -15,6 +15,8 @@
|
|||
|
||||
#include <fsl_mipi_csi2rx.h>
|
||||
|
||||
#include "video_device.h"
|
||||
|
||||
LOG_MODULE_REGISTER(video_mipi_csi2rx, CONFIG_VIDEO_LOG_LEVEL);
|
||||
|
||||
#define MAX_SUPPORTED_PIXEL_RATE MHZ(96)
|
||||
|
@ -352,6 +354,9 @@ static int mipi_csi2rx_init(const struct device *dev)
|
|||
\
|
||||
DEVICE_DT_INST_DEFINE(n, &mipi_csi2rx_init, NULL, &mipi_csi2rx_data_##n, \
|
||||
&mipi_csi2rx_config_##n, POST_KERNEL, CONFIG_VIDEO_INIT_PRIORITY, \
|
||||
&mipi_csi2rx_driver_api);
|
||||
&mipi_csi2rx_driver_api); \
|
||||
\
|
||||
VIDEO_DEVICE_DEFINE(mipi_csi2rx_##n, DEVICE_DT_INST_GET(n), \
|
||||
mipi_csi2rx_config_##n.sensor_dev);
|
||||
|
||||
DT_INST_FOREACH_STATUS_OKAY(MIPI_CSI2RX_INIT)
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
#include <zephyr/logging/log.h>
|
||||
LOG_MODULE_REGISTER(nxp_video_sdma);
|
||||
|
||||
#include "video_device.h"
|
||||
|
||||
struct nxp_video_sdma_config {
|
||||
const struct device *dma_dev;
|
||||
const struct device *sensor_dev;
|
||||
|
@ -363,24 +365,24 @@ static DEVICE_API(video, nxp_video_sdma_api) = {
|
|||
.flush = nxp_video_sdma_flush
|
||||
};
|
||||
|
||||
#define NXP_VIDEO_SDMA_INIT(inst) \
|
||||
PINCTRL_DT_INST_DEFINE(inst); \
|
||||
const struct nxp_video_sdma_config sdma_config_##inst = { \
|
||||
.dma_dev = DEVICE_DT_GET(DT_INST_PARENT(inst)), \
|
||||
.sensor_dev = DEVICE_DT_GET(DT_INST_PHANDLE(inst, sensor)), \
|
||||
.pincfg = PINCTRL_DT_INST_DEV_CONFIG_GET(inst), \
|
||||
.vsync_pin = DT_INST_PROP(inst, vsync_pin), \
|
||||
.hsync_pin = DT_INST_PROP(inst, hsync_pin), \
|
||||
.pclk_pin = DT_INST_PROP(inst, pclk_pin), \
|
||||
}; \
|
||||
struct nxp_video_sdma_data sdma_data_##inst = { \
|
||||
.config = &sdma_config_##inst, \
|
||||
}; \
|
||||
\
|
||||
DEVICE_DT_INST_DEFINE(inst, nxp_video_sdma_init, NULL, \
|
||||
&sdma_data_##inst, &sdma_config_##inst, \
|
||||
POST_KERNEL, \
|
||||
CONFIG_KERNEL_INIT_PRIORITY_DEVICE, \
|
||||
&nxp_video_sdma_api);
|
||||
#define NXP_VIDEO_SDMA_INIT(inst) \
|
||||
PINCTRL_DT_INST_DEFINE(inst); \
|
||||
const struct nxp_video_sdma_config sdma_config_##inst = { \
|
||||
.dma_dev = DEVICE_DT_GET(DT_INST_PARENT(inst)), \
|
||||
.sensor_dev = DEVICE_DT_GET(DT_INST_PHANDLE(inst, sensor)), \
|
||||
.pincfg = PINCTRL_DT_INST_DEV_CONFIG_GET(inst), \
|
||||
.vsync_pin = DT_INST_PROP(inst, vsync_pin), \
|
||||
.hsync_pin = DT_INST_PROP(inst, hsync_pin), \
|
||||
.pclk_pin = DT_INST_PROP(inst, pclk_pin), \
|
||||
}; \
|
||||
struct nxp_video_sdma_data sdma_data_##inst = { \
|
||||
.config = &sdma_config_##inst, \
|
||||
}; \
|
||||
\
|
||||
DEVICE_DT_INST_DEFINE(inst, nxp_video_sdma_init, NULL, &sdma_data_##inst, \
|
||||
&sdma_config_##inst, POST_KERNEL, \
|
||||
CONFIG_KERNEL_INIT_PRIORITY_DEVICE, &nxp_video_sdma_api); \
|
||||
\
|
||||
VIDEO_DEVICE_DEFINE(sdma_##inst, DEVICE_DT_INST_GET(inst), sdma_config_##inst.sensor_dev);
|
||||
|
||||
DT_INST_FOREACH_STATUS_OKAY(NXP_VIDEO_SDMA_INIT)
|
||||
|
|
|
@ -20,6 +20,8 @@
|
|||
|
||||
#include <stm32_ll_dma.h>
|
||||
|
||||
#include "video_device.h"
|
||||
|
||||
LOG_MODULE_REGISTER(video_stm32_dcmi, CONFIG_VIDEO_LOG_LEVEL);
|
||||
|
||||
#if CONFIG_VIDEO_BUFFER_POOL_NUM_MAX < 2
|
||||
|
@ -521,3 +523,5 @@ DEVICE_DT_INST_DEFINE(0, &video_stm32_dcmi_init,
|
|||
&video_stm32_dcmi_config_0,
|
||||
POST_KERNEL, CONFIG_VIDEO_INIT_PRIORITY,
|
||||
&video_stm32_dcmi_driver_api);
|
||||
|
||||
VIDEO_DEVICE_DEFINE(dcmi, DEVICE_DT_INST_GET(0), video_stm32_dcmi_config_0.sensor_dev);
|
||||
|
|
|
@ -11,6 +11,8 @@
|
|||
#include <zephyr/drivers/video-controls.h>
|
||||
#include <zephyr/logging/log.h>
|
||||
|
||||
#include "video_device.h"
|
||||
|
||||
LOG_MODULE_REGISTER(video_sw_generator, CONFIG_VIDEO_LOG_LEVEL);
|
||||
|
||||
#define VIDEO_PATTERN_COLOR_BAR 0
|
||||
|
@ -372,3 +374,5 @@ static int video_sw_generator_init(const struct device *dev)
|
|||
DEVICE_DEFINE(video_sw_generator, "VIDEO_SW_GENERATOR", &video_sw_generator_init, NULL,
|
||||
&video_sw_generator_data_0, NULL, POST_KERNEL, CONFIG_VIDEO_INIT_PRIORITY,
|
||||
&video_sw_generator_driver_api);
|
||||
|
||||
VIDEO_DEVICE_DEFINE(video_sw_generator, DEVICE_GET(video_sw_generator), NULL);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue