From cf630f0a66915ab6bcf1b937632ce1a6dfa98580 Mon Sep 17 00:00:00 2001 From: Phi Bang Nguyen Date: Tue, 25 Jun 2024 15:24:48 +0200 Subject: [PATCH 01/19] include: video: Add an utility function to get bytes per pixel As getting bytes per pixel of a pixel format is a very common operation, add an utility function for it instead of repeating the same codes in different drivers. Signed-off-by: Phi Bang Nguyen --- drivers/video/video_mcux_csi.c | 19 ------------------- include/zephyr/drivers/video.h | 24 ++++++++++++++++++++++++ 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/drivers/video/video_mcux_csi.c b/drivers/video/video_mcux_csi.c index c6a82accdb40b2..0818cc04098df6 100644 --- a/drivers/video/video_mcux_csi.c +++ b/drivers/video/video_mcux_csi.c @@ -32,25 +32,6 @@ struct video_mcux_csi_data { struct k_poll_signal *signal; }; -static inline unsigned int video_pix_fmt_bpp(uint32_t pixelformat) -{ - switch (pixelformat) { - case VIDEO_PIX_FMT_BGGR8: - case VIDEO_PIX_FMT_GBRG8: - case VIDEO_PIX_FMT_GRBG8: - case VIDEO_PIX_FMT_RGGB8: - return 1; - case VIDEO_PIX_FMT_RGB565: - case VIDEO_PIX_FMT_YUYV: - return 2; - case VIDEO_PIX_FMT_XRGB32: - case VIDEO_PIX_FMT_XYUV32: - return 4; - default: - return 0; - } -} - static void __frame_done_cb(CSI_Type *base, csi_handle_t *handle, status_t status, void *user_data) { struct video_mcux_csi_data *data = user_data; diff --git a/include/zephyr/drivers/video.h b/include/zephyr/drivers/video.h index b90707383166a8..fb647cac70fb17 100644 --- a/include/zephyr/drivers/video.h +++ b/include/zephyr/drivers/video.h @@ -827,6 +827,30 @@ void video_buffer_release(struct video_buffer *buf); * @} */ +/** + * @brief Get number of bytes per pixel of a pixel format + * + * @param pixfmt FourCC pixel format value (\ref video_pixel_formats). + */ +static inline unsigned int video_pix_fmt_bpp(uint32_t pixfmt) +{ + switch (pixfmt) { + case VIDEO_PIX_FMT_BGGR8: + case VIDEO_PIX_FMT_GBRG8: + case VIDEO_PIX_FMT_GRBG8: + case VIDEO_PIX_FMT_RGGB8: + return 1; + case VIDEO_PIX_FMT_RGB565: + case VIDEO_PIX_FMT_YUYV: + return 2; + case VIDEO_PIX_FMT_XRGB32: + case VIDEO_PIX_FMT_XYUV32: + return 4; + default: + return 0; + } +} + #ifdef __cplusplus } #endif From 4fe214349a7ac1ab6b86cc99440baa505df76b2e Mon Sep 17 00:00:00 2001 From: Phi Bang Nguyen Date: Wed, 24 Jul 2024 19:00:39 +0200 Subject: [PATCH 02/19] drivers: video: mcux_csi: Remove obsolete comment Remove the obsolete comment about the init order of the CSI and the camera sensors (e.g. mt9m114) which is not true anymore. Signed-off-by: Phi Bang Nguyen --- drivers/video/video_mcux_csi.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/drivers/video/video_mcux_csi.c b/drivers/video/video_mcux_csi.c index 0818cc04098df6..5b0a0d448c0ea1 100644 --- a/drivers/video/video_mcux_csi.c +++ b/drivers/video/video_mcux_csi.c @@ -471,11 +471,6 @@ static int video_mcux_csi_init_0(const struct device *dev) return video_mcux_csi_init(dev); } -/* CONFIG_KERNEL_INIT_PRIORITY_DEVICE is used to make sure the - * CSI peripheral is initialized before the camera, which is - * necessary since the clock to the camera is provided by the - * CSI peripheral. - */ 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); From d1c8a46b74d18fc22b5421eb439caa2e803c3ff4 Mon Sep 17 00:00:00 2001 From: Trung Hieu Le Date: Thu, 29 Aug 2024 15:14:12 +0200 Subject: [PATCH 03/19] drivers: video: mcux_csi: Fix start stop issue When stopping, video_flush() moves all the remaining buffers from the fifo_in to the fifo_out queue. When restarting, we have two issues: - There might be insufficient or no buffers in the fifo_in queue to get the pipeline started. - When dequeuing, users might immediatly get the incorrect buffers in the fifo_out which do not come from interruption. Fix it by moving all the remaining buffers from the fifo_out to the fifo_in before starting the video capture. Signed-off-by: Trung Hieu Le Signed-off-by: Phi Bang Nguyen --- drivers/video/video_mcux_csi.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/video/video_mcux_csi.c b/drivers/video/video_mcux_csi.c index 5b0a0d448c0ea1..90b4672e8b4752 100644 --- a/drivers/video/video_mcux_csi.c +++ b/drivers/video/video_mcux_csi.c @@ -198,6 +198,11 @@ static int video_mcux_csi_stream_start(const struct device *dev) const struct video_mcux_csi_config *config = dev->config; struct video_mcux_csi_data *data = dev->data; status_t ret; + struct video_buf *vbuf; + + while ((vbuf = k_fifo_get(&data->fifo_out, K_NO_WAIT))) { + k_fifo_put(&data->fifo_in, vbuf); + }; ret = CSI_TransferStart(config->base, &data->csi_handle); if (ret != kStatus_Success) { From 143ec5d4f7f3eb97c5e2ba8fe740d75455796975 Mon Sep 17 00:00:00 2001 From: Trung Hieu Le Date: Mon, 22 Jul 2024 17:23:39 +0200 Subject: [PATCH 04/19] drivers: video: mcux_csi: Add support for changing frame rate Add support for changing frame rate Signed-off-by: Trung Hieu Le Signed-off-by: Phi Bang Nguyen --- drivers/video/video_mcux_csi.c | 39 ++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/drivers/video/video_mcux_csi.c b/drivers/video/video_mcux_csi.c index 90b4672e8b4752..4b675860e14ae4 100644 --- a/drivers/video/video_mcux_csi.c +++ b/drivers/video/video_mcux_csi.c @@ -436,6 +436,42 @@ static int video_mcux_csi_set_signal(const struct device *dev, enum video_endpoi } #endif +static int video_mcux_csi_set_frmival(const struct device *dev, enum video_endpoint_id ep, + struct video_frmival *frmival) +{ + const struct video_mcux_csi_config *config = dev->config; + + return video_set_frmival(config->source_dev, ep, frmival); +} + +static int video_mcux_csi_get_frmival(const struct device *dev, enum video_endpoint_id ep, + struct video_frmival *frmival) +{ + const struct video_mcux_csi_config *config = dev->config; + + return video_get_frmival(config->source_dev, ep, frmival); +} + +static int video_mcux_csi_enum_frmival(const struct device *dev, enum video_endpoint_id ep, + struct video_frmival_enum *fie) +{ + const struct video_mcux_csi_config *config = dev->config; + const struct video_format *fie_fmt = fie->format; + int ret; + +#if defined(CONFIG_VIDEO_MCUX_MIPI_CSI2RX) + struct video_format converted_fmt = *fie->format; + + video_pix_fmt_convert(&converted_fmt, false); + fie->format = &converted_fmt; +#endif + + ret = video_enum_frmival(config->source_dev, ep, fie); + fie->format = fie_fmt; + + return ret; +} + static const struct video_driver_api video_mcux_csi_driver_api = { .set_format = video_mcux_csi_set_fmt, .get_format = video_mcux_csi_get_fmt, @@ -447,6 +483,9 @@ static const struct video_driver_api video_mcux_csi_driver_api = { .set_ctrl = video_mcux_csi_set_ctrl, .get_ctrl = video_mcux_csi_get_ctrl, .get_caps = video_mcux_csi_get_caps, + .set_frmival = video_mcux_csi_set_frmival, + .get_frmival = video_mcux_csi_get_frmival, + .enum_frmival = video_mcux_csi_enum_frmival, #ifdef CONFIG_POLL .set_signal = video_mcux_csi_set_signal, #endif From 759f16c650dfe35936a8dc1f01a1cde00d475d64 Mon Sep 17 00:00:00 2001 From: Phi Bang Nguyen Date: Wed, 24 Jul 2024 19:04:51 +0200 Subject: [PATCH 05/19] drivers: video: mcux_csi: Add NXP copyright The mcux csi is an NXP IP and the driver has been recently changed much by NXP, so add NXP copyright to it. Signed-off-by: Phi Bang Nguyen --- drivers/video/video_mcux_csi.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/video/video_mcux_csi.c b/drivers/video/video_mcux_csi.c index 4b675860e14ae4..b0ca8440dfc77b 100644 --- a/drivers/video/video_mcux_csi.c +++ b/drivers/video/video_mcux_csi.c @@ -1,5 +1,6 @@ /* * Copyright (c) 2019, Linaro Limited + * Copyright 2024 NXP * * SPDX-License-Identifier: Apache-2.0 */ From 673d0c7a64817d307219b6fe3f3db3a519c74881 Mon Sep 17 00:00:00 2001 From: Phi Bang Nguyen Date: Tue, 15 Oct 2024 11:16:18 +0200 Subject: [PATCH 06/19] dts-bindings: video: mipicsi2rx: Use video interfaces bindings Switch to use the new video interfaces bindings Signed-off-by: Phi Bang Nguyen --- dts/arm/nxp/nxp_rt11xx.dtsi | 2 +- dts/bindings/video/nxp,mipi-csi2rx.yaml | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/dts/arm/nxp/nxp_rt11xx.dtsi b/dts/arm/nxp/nxp_rt11xx.dtsi index 5dd41ed398b664..10e27d72507134 100644 --- a/dts/arm/nxp/nxp_rt11xx.dtsi +++ b/dts/arm/nxp/nxp_rt11xx.dtsi @@ -909,7 +909,7 @@ port@0 { reg = <0>; mipi_csi2rx_ep_out: endpoint { - remote-endpoint = <&csi_ep_in>; + remote-endpoint-label = "csi_ep_in"; }; }; diff --git a/dts/bindings/video/nxp,mipi-csi2rx.yaml b/dts/bindings/video/nxp,mipi-csi2rx.yaml index 1726d63b3299e1..c644083e61ffc7 100644 --- a/dts/bindings/video/nxp,mipi-csi2rx.yaml +++ b/dts/bindings/video/nxp,mipi-csi2rx.yaml @@ -15,3 +15,8 @@ properties: required: true type: phandle description: the connected camera sensor + +child-binding: + child-binding: + child-binding: + include: video-interfaces.yaml From 8c7e1c2ec4b907b3e36b18db75e8c98fd8891053 Mon Sep 17 00:00:00 2001 From: Phi Bang Nguyen Date: Tue, 15 Oct 2024 11:18:21 +0200 Subject: [PATCH 07/19] dts-bindings: video: csi: Use video interfaces bindings Switch to use the new video interfaces bindings Signed-off-by: Phi Bang Nguyen --- boards/madmachine/mm_swiftio/mm_swiftio.dts | 2 +- boards/shields/nxp_btb44_ov5640/nxp_btb44_ov5640.overlay | 2 +- dts/arm/nxp/nxp_rt11xx.dtsi | 2 +- dts/bindings/video/nxp,imx-csi.yaml | 4 ++++ 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/boards/madmachine/mm_swiftio/mm_swiftio.dts b/boards/madmachine/mm_swiftio/mm_swiftio.dts index e4212cd8294c6d..e7400d6b62acae 100644 --- a/boards/madmachine/mm_swiftio/mm_swiftio.dts +++ b/boards/madmachine/mm_swiftio/mm_swiftio.dts @@ -198,7 +198,7 @@ port { csi_ep_in: endpoint { - remote-endpoint = <&ov7725_ep_out>; + remote-endpoint-label = "ov7725_ep_out"; }; }; }; diff --git a/boards/shields/nxp_btb44_ov5640/nxp_btb44_ov5640.overlay b/boards/shields/nxp_btb44_ov5640/nxp_btb44_ov5640.overlay index e7c179f5d2355c..58c85e6b6604c6 100644 --- a/boards/shields/nxp_btb44_ov5640/nxp_btb44_ov5640.overlay +++ b/boards/shields/nxp_btb44_ov5640/nxp_btb44_ov5640.overlay @@ -37,7 +37,7 @@ reg = <1>; mipi_csi2rx_ep_in: endpoint { - remote-endpoint = <&ov5640_ep_out>; + remote-endpoint-label = "ov5640_ep_out"; }; }; }; diff --git a/dts/arm/nxp/nxp_rt11xx.dtsi b/dts/arm/nxp/nxp_rt11xx.dtsi index 10e27d72507134..9ac5a32d6c61fe 100644 --- a/dts/arm/nxp/nxp_rt11xx.dtsi +++ b/dts/arm/nxp/nxp_rt11xx.dtsi @@ -892,7 +892,7 @@ port { csi_ep_in: endpoint { - remote-endpoint = <&mipi_csi2rx_ep_out>; + remote-endpoint-label = "mipi_csi2rx_ep_out"; }; }; }; diff --git a/dts/bindings/video/nxp,imx-csi.yaml b/dts/bindings/video/nxp,imx-csi.yaml index bf7fd01eeaadd3..fa24ea25901238 100644 --- a/dts/bindings/video/nxp,imx-csi.yaml +++ b/dts/bindings/video/nxp,imx-csi.yaml @@ -19,3 +19,7 @@ properties: type: phandle description: the connected source device, e.g., a mipi csi or a camera sensor + +child-binding: + child-binding: + include: video-interfaces.yaml From af8d55c3fcfe651225250a342d8bf8561fe7f7cd Mon Sep 17 00:00:00 2001 From: Phi Bang Nguyen Date: Tue, 15 Oct 2024 11:09:15 +0200 Subject: [PATCH 08/19] dts-bindings: video: ov7725: Use video interfaces binding Switch to use the new video interfaces binding Signed-off-by: Phi Bang Nguyen --- boards/madmachine/mm_swiftio/mm_swiftio.dts | 2 +- dts/bindings/video/ovti,ov7725.yaml | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/boards/madmachine/mm_swiftio/mm_swiftio.dts b/boards/madmachine/mm_swiftio/mm_swiftio.dts index e7400d6b62acae..2f01c730bc118e 100644 --- a/boards/madmachine/mm_swiftio/mm_swiftio.dts +++ b/boards/madmachine/mm_swiftio/mm_swiftio.dts @@ -115,7 +115,7 @@ port { ov7725_ep_out: endpoint { - remote-endpoint = <&csi_ep_in>; + remote-endpoint-label = "csi_ep_in"; }; }; }; diff --git a/dts/bindings/video/ovti,ov7725.yaml b/dts/bindings/video/ovti,ov7725.yaml index 15b557d78e7409..a3648234d65129 100644 --- a/dts/bindings/video/ovti,ov7725.yaml +++ b/dts/bindings/video/ovti,ov7725.yaml @@ -13,3 +13,7 @@ properties: reset. The sensor receives this as an active-low signal. include: i2c-device.yaml + +child-binding: + child-binding: + include: video-interfaces.yaml From 2b8d454975e86207a3a80ae0f9681fb92b595a4d Mon Sep 17 00:00:00 2001 From: Phi Bang Nguyen Date: Tue, 15 Oct 2024 11:13:58 +0200 Subject: [PATCH 09/19] dts-bindings: video: ov5640: Use video interfaces binding Switch to use the new video interfaces binding Signed-off-by: Phi Bang Nguyen --- boards/shields/nxp_btb44_ov5640/nxp_btb44_ov5640.overlay | 2 +- dts/bindings/video/ovti,ov5640.yaml | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/boards/shields/nxp_btb44_ov5640/nxp_btb44_ov5640.overlay b/boards/shields/nxp_btb44_ov5640/nxp_btb44_ov5640.overlay index 58c85e6b6604c6..adab695be9c9f9 100644 --- a/boards/shields/nxp_btb44_ov5640/nxp_btb44_ov5640.overlay +++ b/boards/shields/nxp_btb44_ov5640/nxp_btb44_ov5640.overlay @@ -21,7 +21,7 @@ port { ov5640_ep_out: endpoint { - remote-endpoint = <&mipi_csi2rx_ep_in>; + remote-endpoint-label = "mipi_csi2rx_ep_in"; }; }; }; diff --git a/dts/bindings/video/ovti,ov5640.yaml b/dts/bindings/video/ovti,ov5640.yaml index eecb0e3d3192ba..9b10d9b2d27ffd 100644 --- a/dts/bindings/video/ovti,ov5640.yaml +++ b/dts/bindings/video/ovti,ov5640.yaml @@ -18,3 +18,7 @@ properties: description: | The PWDN pin is asserted to disable the sensor. The sensor receives this as an active-high signal. + +child-binding: + child-binding: + include: video-interfaces.yaml From 785df6644575d6eeeb01cce81e5cd35213ede9bd Mon Sep 17 00:00:00 2001 From: Phi Bang Nguyen Date: Wed, 16 Oct 2024 14:19:18 +0200 Subject: [PATCH 10/19] tests: drivers: build_all: video: Use the new endpoint binding The csi, mipicsi2rx, ov5640 devices now use the new video interface bindings. Change the test accordingly to take into account this. Signed-off-by: Phi Bang Nguyen --- .../mimxrt1170_evk_mimxrt1176_cm7.overlay | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/drivers/build_all/video/mimxrt1170_evk_mimxrt1176_cm7.overlay b/tests/drivers/build_all/video/mimxrt1170_evk_mimxrt1176_cm7.overlay index 99542ad4c78255..0619309444fc63 100644 --- a/tests/drivers/build_all/video/mimxrt1170_evk_mimxrt1176_cm7.overlay +++ b/tests/drivers/build_all/video/mimxrt1170_evk_mimxrt1176_cm7.overlay @@ -8,6 +8,8 @@ * (and be extended to test) real hardware. */ +#include + / { test { #address-cells = <1>; @@ -34,6 +36,14 @@ reg = <0x1>; reset-gpios = <&test_gpio 0 0>; powerdown-gpios = <&test_gpio 1 0>; + + port { + ov5640_ep_out: endpoint { + remote-endpoint-label = "mipi_csi2rx_ep_in"; + bus-type = ; + data-lanes = <1 2>; + }; + }; }; }; @@ -51,6 +61,20 @@ reg = <0x33334444 0x200>; status = "okay"; sensor = <&test_i2c_ov5640>; + + ports { + #address-cells = <1>; + #size-cells = <0>; + + port@1 { + reg = <1>; + + mipi_csi2rx_ep_in: endpoint { + remote-endpoint-label = "ov5640_ep_out"; + data-lanes = <1 2>; + }; + }; + }; }; }; }; From 8b6f262f3f6b036e17958bf2748330bb1ae41b96 Mon Sep 17 00:00:00 2001 From: Phi Bang Nguyen Date: Thu, 17 Oct 2024 10:39:06 +0200 Subject: [PATCH 11/19] boards: shields: dvp_fpc24_mt9m114: Use the new endpoint bindings As CSI now uses the new video-interfaces binding, this shield needs to be changed too. Signed-off-by: Phi Bang Nguyen --- boards/shields/dvp_fpc24_mt9m114/dvp_fpc24_mt9m114.overlay | 4 ++-- dts/bindings/video/aptina,mt9m114.yaml | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/boards/shields/dvp_fpc24_mt9m114/dvp_fpc24_mt9m114.overlay b/boards/shields/dvp_fpc24_mt9m114/dvp_fpc24_mt9m114.overlay index 52988535182d31..49bc018779a8fc 100644 --- a/boards/shields/dvp_fpc24_mt9m114/dvp_fpc24_mt9m114.overlay +++ b/boards/shields/dvp_fpc24_mt9m114/dvp_fpc24_mt9m114.overlay @@ -17,7 +17,7 @@ port { mt9m114_ep_out: endpoint { - remote-endpoint = <&dfi_ep_in>; + remote-endpoint-label = "dfi_ep_in"; }; }; }; @@ -28,7 +28,7 @@ port { dfi_ep_in: endpoint { - remote-endpoint = <&mt9m114_ep_out>; + remote-endpoint-label = "mt9m114_ep_out"; }; }; }; diff --git a/dts/bindings/video/aptina,mt9m114.yaml b/dts/bindings/video/aptina,mt9m114.yaml index 21dbefb5419eee..c233080ae0ca11 100644 --- a/dts/bindings/video/aptina,mt9m114.yaml +++ b/dts/bindings/video/aptina,mt9m114.yaml @@ -6,3 +6,7 @@ description: MT9M114 CMOS video sensor compatible: "aptina,mt9m114" include: i2c-device.yaml + +child-binding: + child-binding: + include: video-interfaces.yaml From 25a806501608b2a227b604e8fefc12035be3678f Mon Sep 17 00:00:00 2001 From: Phi Bang Nguyen Date: Tue, 15 Oct 2024 11:26:16 +0200 Subject: [PATCH 12/19] boards: shields: nxp_btb44_ov5640: Add some endpoint properties The ov5640 camera driver now supports both MIPI CSI2 (DPHY) and DVP modes. It is in MIPI CSI2 mode in this overlay. Add bus-type property for this. In this mode, data-lanes property is required as well. Signed-off-by: Phi Bang Nguyen --- boards/shields/nxp_btb44_ov5640/nxp_btb44_ov5640.overlay | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/boards/shields/nxp_btb44_ov5640/nxp_btb44_ov5640.overlay b/boards/shields/nxp_btb44_ov5640/nxp_btb44_ov5640.overlay index adab695be9c9f9..304df6bdb13ec0 100644 --- a/boards/shields/nxp_btb44_ov5640/nxp_btb44_ov5640.overlay +++ b/boards/shields/nxp_btb44_ov5640/nxp_btb44_ov5640.overlay @@ -4,6 +4,8 @@ * SPDX-License-Identifier: Apache-2.0 */ +#include + /{ chosen { zephyr,camera = &nxp_csi; @@ -22,6 +24,8 @@ port { ov5640_ep_out: endpoint { remote-endpoint-label = "mipi_csi2rx_ep_in"; + bus-type = ; + data-lanes = <1 2>; }; }; }; @@ -38,6 +42,7 @@ mipi_csi2rx_ep_in: endpoint { remote-endpoint-label = "ov5640_ep_out"; + data-lanes = <1 2>; }; }; }; From 968925cd949ea9064958cfa0ee39f0330b7cb65a Mon Sep 17 00:00:00 2001 From: Phi Bang Nguyen Date: Wed, 19 Jun 2024 14:56:05 +0200 Subject: [PATCH 13/19] drivers: video: mcux_mipi_csi2rx: Get data lanes number from devicetree Get number of data lanes from device tree instead of hard-coding it. Signed-off-by: Phi Bang Nguyen --- drivers/video/video_mcux_mipi_csi2rx.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/drivers/video/video_mcux_mipi_csi2rx.c b/drivers/video/video_mcux_mipi_csi2rx.c index 5ad56383fda4fe..e303841ab6f686 100644 --- a/drivers/video/video_mcux_mipi_csi2rx.c +++ b/drivers/video/video_mcux_mipi_csi2rx.c @@ -14,11 +14,6 @@ LOG_MODULE_REGISTER(video_mipi_csi2rx, CONFIG_VIDEO_LOG_LEVEL); -/* - * Two data lanes are set by default as 2-lanes camera sensors are - * more common and more performant but single lane is also supported. - */ -#define DEFAULT_MIPI_CSI_NUM_LANES 2 #define DEFAULT_CAMERA_FRAME_RATE 30 struct mipi_csi2rx_config { @@ -102,8 +97,6 @@ static int mipi_csi2rx_set_fmt(const struct device *dev, enum video_endpoint_id }, }; - csi2rxConfig.laneNum = DEFAULT_MIPI_CSI_NUM_LANES; - for (i = 0; i < ARRAY_SIZE(csi2rxHsSettle); i++) { if ((fmt->width == csi2rxHsSettle[i][0]) && (fmt->height == csi2rxHsSettle[i][1]) && (DEFAULT_CAMERA_FRAME_RATE == csi2rxHsSettle[i][2])) { @@ -203,7 +196,11 @@ static int mipi_csi2rx_init(const struct device *dev) } #define MIPI_CSI2RX_INIT(n) \ - static struct mipi_csi2rx_data mipi_csi2rx_data_##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), \ + }; \ \ static const struct mipi_csi2rx_config mipi_csi2rx_config_##n = { \ .base = (MIPI_CSI2RX_Type *)DT_INST_REG_ADDR(n), \ From 9b587699b04dac9266debd5ab121e2f5c8be044a Mon Sep 17 00:00:00 2001 From: Farah Fliss Date: Tue, 16 Jul 2024 11:19:43 +0200 Subject: [PATCH 14/19] drivers: video: mcux_mipi_csi2rx: Add set_ctrl callback Add set_ctrl callback to propagate controls to the sensor. Signed-off-by: Farah Fliss Signed-off-by: Phi Bang Nguyen --- drivers/video/video_mcux_mipi_csi2rx.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/video/video_mcux_mipi_csi2rx.c b/drivers/video/video_mcux_mipi_csi2rx.c index e303841ab6f686..90e7b9ba85278f 100644 --- a/drivers/video/video_mcux_mipi_csi2rx.c +++ b/drivers/video/video_mcux_mipi_csi2rx.c @@ -175,12 +175,24 @@ static int mipi_csi2rx_get_caps(const struct device *dev, enum video_endpoint_id return video_get_caps(config->sensor_dev, ep, caps); } +static inline int mipi_csi2rx_set_ctrl(const struct device *dev, unsigned int cid, void *value) +{ + const struct mipi_csi2rx_config *config = dev->config; + + if (config->sensor_dev) { + return video_set_ctrl(config->sensor_dev, cid, value); + } + + return -ENOTSUP; +} + static const struct video_driver_api mipi_csi2rx_driver_api = { .get_caps = mipi_csi2rx_get_caps, .get_format = mipi_csi2rx_get_fmt, .set_format = mipi_csi2rx_set_fmt, .stream_start = mipi_csi2rx_stream_start, .stream_stop = mipi_csi2rx_stream_stop, + .set_ctrl = mipi_csi2rx_set_ctrl, }; static int mipi_csi2rx_init(const struct device *dev) From 425a1df8d0dd14968a33398da2a9bb576867dfdb Mon Sep 17 00:00:00 2001 From: Trung Hieu Le Date: Wed, 24 Jul 2024 21:38:08 +0200 Subject: [PATCH 15/19] drivers: video: mcux_mipi_csi2rx: Set clocks according to pixel rate Instead of fixing csi2rx clock frequencies, set them according to the pixel rate got from the camera sensor. Signed-off-by: Trung Hieu Le Signed-off-by: Phi Bang Nguyen --- drivers/video/video_mcux_mipi_csi2rx.c | 153 ++++++++++++------------- soc/nxp/imxrt/imxrt11xx/soc.c | 40 +++++-- soc/nxp/imxrt/imxrt11xx/soc.h | 4 + 3 files changed, 106 insertions(+), 91 deletions(-) diff --git a/drivers/video/video_mcux_mipi_csi2rx.c b/drivers/video/video_mcux_mipi_csi2rx.c index 90e7b9ba85278f..fee26323b40ba8 100644 --- a/drivers/video/video_mcux_mipi_csi2rx.c +++ b/drivers/video/video_mcux_mipi_csi2rx.c @@ -9,12 +9,15 @@ #include #include #include +#include #include LOG_MODULE_REGISTER(video_mipi_csi2rx, CONFIG_VIDEO_LOG_LEVEL); -#define DEFAULT_CAMERA_FRAME_RATE 30 +#define MAX_SUPPORTED_PIXEL_RATE MHZ(96) + +#define ABS(a, b) (a > b ? a - b : b - a) struct mipi_csi2rx_config { const MIPI_CSI2RX_Type *base; @@ -25,98 +28,82 @@ struct mipi_csi2rx_data { csi2rx_config_t csi2rxConfig; }; -static int mipi_csi2rx_set_fmt(const struct device *dev, enum video_endpoint_id ep, - struct video_format *fmt) +struct mipi_csi2rx_tHsSettleEscClk_config { + uint64_t pixel_rate; + uint8_t tHsSettle_EscClk; +}; + +/* Must be in pixel rate ascending order */ +const struct mipi_csi2rx_tHsSettleEscClk_config tHsSettleEscClk_configs[] = { + {MHZ(24), 0x24}, + {MHZ(48), 0x12}, + {MHZ(96), 0x09}, +}; + +static int mipi_csi2rx_update_settings(const struct device *dev, enum video_endpoint_id ep) { const struct mipi_csi2rx_config *config = dev->config; struct mipi_csi2rx_data *drv_data = dev->data; - csi2rx_config_t csi2rxConfig = {0}; - uint8_t i = 0; + uint8_t bpp; + uint64_t sensor_pixel_rate, sensor_lane_rate, sensor_byte_clk; + uint32_t best_match; + int ret, ind = 0; + struct video_format fmt; + + ret = video_get_format(config->sensor_dev, ep, &fmt); + if (ret) { + LOG_ERR("Cannot get sensor_dev pixel format"); + return ret; + } - /* - * Initialize the MIPI CSI2 - * - * From D-PHY specification, the T-HSSETTLE should in the range of 85ns+6*UI to 145ns+10*UI - * UI is Unit Interval, equal to the duration of any HS state on the Clock Lane - * - * T-HSSETTLE = csi2rxConfig.tHsSettle_EscClk * (Tperiod of RxClkInEsc) - * - * csi2rxConfig.tHsSettle_EscClk setting for camera: - * - * Resolution | frame rate | T_HS_SETTLE - * ============================================= - * 720P | 30 | 0x12 - * --------------------------------------------- - * 720P | 15 | 0x17 - * --------------------------------------------- - * VGA | 30 | 0x1F - * --------------------------------------------- - * VGA | 15 | 0x24 - * --------------------------------------------- - * QVGA | 30 | 0x1F - * --------------------------------------------- - * QVGA | 15 | 0x24 - * --------------------------------------------- - */ - static const uint32_t csi2rxHsSettle[][4] = { - { - 1280, - 720, - 30, - 0x12, - }, - { - 1280, - 720, - 15, - 0x17, - }, - { - 640, - 480, - 30, - 0x1F, - }, - { - 640, - 480, - 15, - 0x24, - }, - { - 320, - 240, - 30, - 0x1F, - }, - { - 320, - 240, - 15, - 0x24, - }, - }; - - for (i = 0; i < ARRAY_SIZE(csi2rxHsSettle); i++) { - if ((fmt->width == csi2rxHsSettle[i][0]) && (fmt->height == csi2rxHsSettle[i][1]) && - (DEFAULT_CAMERA_FRAME_RATE == csi2rxHsSettle[i][2])) { - csi2rxConfig.tHsSettle_EscClk = csi2rxHsSettle[i][3]; - break; - } + ret = video_get_ctrl(config->sensor_dev, VIDEO_CID_PIXEL_RATE, &sensor_pixel_rate); + if (ret) { + LOG_ERR("Can not get sensor_dev pixel rate"); + return ret; } - if (i == ARRAY_SIZE(csi2rxHsSettle)) { - LOG_ERR("Unsupported resolution"); + bpp = video_pix_fmt_bpp(fmt.pixelformat) * 8; + sensor_lane_rate = sensor_pixel_rate * bpp / drv_data->csi2rxConfig.laneNum; + + if (sensor_pixel_rate > MAX_SUPPORTED_PIXEL_RATE) { + LOG_ERR("Sensor pixel rate is not supported"); return -ENOTSUP; } - drv_data->csi2rxConfig = csi2rxConfig; + sensor_byte_clk = sensor_pixel_rate * bpp / drv_data->csi2rxConfig.laneNum / 8; + if (sensor_byte_clk > CLOCK_GetRootClockFreq(kCLOCK_Root_Csi2)) { + mipi_csi2rx_clock_set_freq(kCLOCK_Root_Csi2, sensor_byte_clk); + } + + if (sensor_pixel_rate > CLOCK_GetRootClockFreq(kCLOCK_Root_Csi2_Ui)) { + mipi_csi2rx_clock_set_freq(kCLOCK_Root_Csi2_Ui, sensor_pixel_rate); + } + + /* Find the supported sensor_pixel_rate closest to the desired one */ + best_match = tHsSettleEscClk_configs[ind].pixel_rate; + for (uint8_t i = 0; i < ARRAY_SIZE(tHsSettleEscClk_configs); i++) { + if (ABS(tHsSettleEscClk_configs[i].pixel_rate, sensor_pixel_rate) < + ABS(tHsSettleEscClk_configs[i].pixel_rate, best_match)) { + best_match = tHsSettleEscClk_configs[i].pixel_rate; + ind = i; + } + } + + drv_data->csi2rxConfig.tHsSettle_EscClk = tHsSettleEscClk_configs[ind].tHsSettle_EscClk; + + return ret; +} + +static int mipi_csi2rx_set_fmt(const struct device *dev, enum video_endpoint_id ep, + struct video_format *fmt) +{ + const struct mipi_csi2rx_config *config = dev->config; if (video_set_format(config->sensor_dev, ep, fmt)) { return -EIO; } - return 0; + return mipi_csi2rx_update_settings(dev, ep); } static int mipi_csi2rx_get_fmt(const struct device *dev, enum video_endpoint_id ep, @@ -204,7 +191,13 @@ static int mipi_csi2rx_init(const struct device *dev) return -ENODEV; } - return 0; + /* + * CSI2 escape clock should be in the range [60, 80] Mhz. We set it + * to 60 Mhz. + */ + mipi_csi2rx_clock_set_freq(kCLOCK_Root_Csi2_Esc, MHZ(60)); + + return mipi_csi2rx_update_settings(dev, VIDEO_EP_ALL); } #define MIPI_CSI2RX_INIT(n) \ diff --git a/soc/nxp/imxrt/imxrt11xx/soc.c b/soc/nxp/imxrt/imxrt11xx/soc.c index 02e35c2d105e99..62726aafa1fdc2 100644 --- a/soc/nxp/imxrt/imxrt11xx/soc.c +++ b/soc/nxp/imxrt/imxrt11xx/soc.c @@ -474,17 +474,6 @@ static ALWAYS_INLINE void clock_init(void) CLOCK_EnableClock(kCLOCK_Video_Mux); VIDEO_MUX->VID_MUX_CTRL.SET = VIDEO_MUX_VID_MUX_CTRL_CSI_SEL_MASK; - /* Configure MIPI CSI-2 Rx clocks */ - rootCfg.div = 8; - rootCfg.mux = kCLOCK_CSI2_ClockRoot_MuxSysPll3Out; - CLOCK_SetRootClock(kCLOCK_Root_Csi2, &rootCfg); - - rootCfg.mux = kCLOCK_CSI2_ESC_ClockRoot_MuxSysPll3Out; - CLOCK_SetRootClock(kCLOCK_Root_Csi2_Esc, &rootCfg); - - rootCfg.mux = kCLOCK_CSI2_UI_ClockRoot_MuxSysPll3Out; - CLOCK_SetRootClock(kCLOCK_Root_Csi2_Ui, &rootCfg); - /* Enable power domain for MIPI CSI-2 */ PGMC_BPC4->BPC_POWER_CTRL |= (PGMC_BPC_BPC_POWER_CTRL_PSW_ON_SOFT_MASK | PGMC_BPC_BPC_POWER_CTRL_ISO_OFF_SOFT_MASK); @@ -682,6 +671,35 @@ void imxrt_post_init_display_interface(void) #endif +#if CONFIG_VIDEO_MCUX_MIPI_CSI2RX +void mipi_csi2rx_clock_set_freq(clock_root_t clock_root, uint32_t rate) +{ + clock_root_config_t rootCfg = {0}; + uint32_t freq; + clock_name_t clk_source; + + switch (clock_root) { + case kCLOCK_Root_Csi2: + rootCfg.mux = kCLOCK_CSI2_ClockRoot_MuxSysPll3Out; + break; + case kCLOCK_Root_Csi2_Esc: + rootCfg.mux = kCLOCK_CSI2_ESC_ClockRoot_MuxSysPll3Out; + break; + case kCLOCK_Root_Csi2_Ui: + rootCfg.mux = kCLOCK_CSI2_UI_ClockRoot_MuxSysPll3Out; + break; + default: + return; + } + + clk_source = CLOCK_GetRootClockSource(clock_root, rootCfg.mux); + freq = CLOCK_GetFreq(clk_source); + __ASSERT(rate < freq, "Requested rate is higher than the maximum clock frequency"); + rootCfg.div = (uint32_t)freq / rate; + CLOCK_SetRootClock(clock_root, &rootCfg); +} +#endif + /** * * @brief Perform basic hardware initialization diff --git a/soc/nxp/imxrt/imxrt11xx/soc.h b/soc/nxp/imxrt/imxrt11xx/soc.h index 88b344541793c3..c5b7b54a294c45 100644 --- a/soc/nxp/imxrt/imxrt11xx/soc.h +++ b/soc/nxp/imxrt/imxrt11xx/soc.h @@ -32,6 +32,10 @@ void imxrt_pre_init_display_interface(void); void imxrt_post_init_display_interface(void); #endif +#if CONFIG_VIDEO_MCUX_MIPI_CSI2RX +void mipi_csi2rx_clock_set_freq(clock_root_t clock_root, uint32_t rate); +#endif + void flexspi_clock_set_div(uint32_t value); uint32_t flexspi_clock_get_freq(void); From 1385de9483d238b7a719c185cf857937a9f01d69 Mon Sep 17 00:00:00 2001 From: Trung Hieu Le Date: Tue, 23 Jul 2024 13:29:59 +0200 Subject: [PATCH 16/19] drivers: video: mcux_mipi_csi2rx: Add support for changing frame rate Add support for changing frame rate. Signed-off-by: Trung Hieu Le Signed-off-by: Phi Bang Nguyen --- drivers/video/video_mcux_mipi_csi2rx.c | 113 +++++++++++++++++++++++++ 1 file changed, 113 insertions(+) diff --git a/drivers/video/video_mcux_mipi_csi2rx.c b/drivers/video/video_mcux_mipi_csi2rx.c index fee26323b40ba8..db6f2eb02c6e56 100644 --- a/drivers/video/video_mcux_mipi_csi2rx.c +++ b/drivers/video/video_mcux_mipi_csi2rx.c @@ -7,6 +7,7 @@ #define DT_DRV_COMPAT nxp_mipi_csi2rx #include +#include #include #include #include @@ -173,6 +174,115 @@ static inline int mipi_csi2rx_set_ctrl(const struct device *dev, unsigned int ci return -ENOTSUP; } +static int mipi_csi2rx_set_frmival(const struct device *dev, enum video_endpoint_id ep, + struct video_frmival *frmival) +{ + const struct mipi_csi2rx_config *config = dev->config; + int ret; + + ret = video_set_frmival(config->sensor_dev, ep, frmival); + if (ret) { + LOG_ERR("Cannot set sensor_dev frmival"); + return ret; + } + + ret = mipi_csi2rx_update_settings(dev, ep); + + return ret; +} + +static int mipi_csi2rx_get_frmival(const struct device *dev, enum video_endpoint_id ep, + struct video_frmival *frmival) +{ + const struct mipi_csi2rx_config *config = dev->config; + + return video_get_frmival(config->sensor_dev, ep, frmival); +} + +static uint64_t mipi_csi2rx_cal_frame_size(const struct video_format *fmt) +{ + return fmt->height * fmt->width * video_pix_fmt_bpp(fmt->pixelformat) * 8; +} + +static uint64_t mipi_csi2rx_estimate_pixel_rate(const struct video_frmival *cur_fmival, + const struct video_frmival *fie_frmival, + const struct video_format *cur_format, + const struct video_format *fie_format, + uint64_t cur_pixel_rate, uint8_t laneNum) +{ + return mipi_csi2rx_cal_frame_size(cur_format) * fie_frmival->denominator * + cur_fmival->numerator * cur_pixel_rate / + (mipi_csi2rx_cal_frame_size(fie_format) * fie_frmival->numerator * + cur_fmival->denominator); +} + +static int mipi_csi2rx_enum_frmival(const struct device *dev, enum video_endpoint_id ep, + struct video_frmival_enum *fie) +{ + const struct mipi_csi2rx_config *config = dev->config; + struct mipi_csi2rx_data *drv_data = dev->data; + int ret; + uint64_t cur_pixel_rate, est_pixel_rate; + struct video_frmival cur_frmival; + struct video_format cur_fmt; + + ret = video_enum_frmival(config->sensor_dev, ep, fie); + if (ret) { + return ret; + } + + ret = video_get_ctrl(config->sensor_dev, VIDEO_CID_PIXEL_RATE, &cur_pixel_rate); + if (ret) { + LOG_ERR("Cannot get sensor_dev pixel rate"); + return ret; + } + + ret = video_get_frmival(config->sensor_dev, ep, &cur_frmival); + if (ret) { + LOG_ERR("Cannot get sensor_dev frame rate"); + return ret; + } + + ret = video_get_format(config->sensor_dev, ep, &cur_fmt); + if (ret) { + LOG_ERR("Cannot get sensor_dev format"); + return ret; + } + + if (fie->type == VIDEO_FRMIVAL_TYPE_DISCRETE) { + est_pixel_rate = mipi_csi2rx_estimate_pixel_rate( + &cur_frmival, &fie->discrete, &cur_fmt, fie->format, cur_pixel_rate, + drv_data->csi2rxConfig.laneNum); + if (est_pixel_rate > MAX_SUPPORTED_PIXEL_RATE) { + return -EINVAL; + } + + } else { + /* Check the lane rate of the lower bound framerate */ + est_pixel_rate = mipi_csi2rx_estimate_pixel_rate( + &cur_frmival, &fie->stepwise.min, &cur_fmt, fie->format, cur_pixel_rate, + drv_data->csi2rxConfig.laneNum); + if (est_pixel_rate > MAX_SUPPORTED_PIXEL_RATE) { + return -EINVAL; + } + + /* Check the lane rate of the upper bound framerate */ + est_pixel_rate = mipi_csi2rx_estimate_pixel_rate( + &cur_frmival, &fie->stepwise.max, &cur_fmt, fie->format, cur_pixel_rate, + drv_data->csi2rxConfig.laneNum); + if (est_pixel_rate > MAX_SUPPORTED_PIXEL_RATE) { + fie->stepwise.max.denominator = + (mipi_csi2rx_cal_frame_size(&cur_fmt) * MAX_SUPPORTED_PIXEL_RATE * + cur_frmival.denominator) / + (mipi_csi2rx_cal_frame_size(fie->format) * cur_pixel_rate * + cur_frmival.numerator); + fie->stepwise.max.numerator = 1; + } + } + + return 0; +} + static const struct video_driver_api mipi_csi2rx_driver_api = { .get_caps = mipi_csi2rx_get_caps, .get_format = mipi_csi2rx_get_fmt, @@ -180,6 +290,9 @@ static const struct video_driver_api mipi_csi2rx_driver_api = { .stream_start = mipi_csi2rx_stream_start, .stream_stop = mipi_csi2rx_stream_stop, .set_ctrl = mipi_csi2rx_set_ctrl, + .set_frmival = mipi_csi2rx_set_frmival, + .get_frmival = mipi_csi2rx_get_frmival, + .enum_frmival = mipi_csi2rx_enum_frmival, }; static int mipi_csi2rx_init(const struct device *dev) From 2b855b849e51e6b603efd9b74d5438e4c9300df3 Mon Sep 17 00:00:00 2001 From: Phi Bang Nguyen Date: Mon, 21 Oct 2024 21:53:23 +0200 Subject: [PATCH 17/19] drivers: video: mipi_csi2rx: Remove sensor device phandle The peer remote device "sensor_dev" can be retrieved from the remote-endpoint-label. Direct reference via phandle is not needed. Signed-off-by: Phi Bang Nguyen --- boards/shields/nxp_btb44_ov5640/nxp_btb44_ov5640.overlay | 2 -- drivers/video/video_mcux_mipi_csi2rx.c | 6 +++++- dts/bindings/video/nxp,mipi-csi2rx.yaml | 6 ------ .../build_all/video/mimxrt1170_evk_mimxrt1176_cm7.overlay | 1 - 4 files changed, 5 insertions(+), 10 deletions(-) diff --git a/boards/shields/nxp_btb44_ov5640/nxp_btb44_ov5640.overlay b/boards/shields/nxp_btb44_ov5640/nxp_btb44_ov5640.overlay index 304df6bdb13ec0..9eca70c27cdebe 100644 --- a/boards/shields/nxp_btb44_ov5640/nxp_btb44_ov5640.overlay +++ b/boards/shields/nxp_btb44_ov5640/nxp_btb44_ov5640.overlay @@ -34,8 +34,6 @@ &nxp_mipi_csi { status = "okay"; - sensor = <&ov5640>; - ports { port@1 { reg = <1>; diff --git a/drivers/video/video_mcux_mipi_csi2rx.c b/drivers/video/video_mcux_mipi_csi2rx.c index db6f2eb02c6e56..e52a8d1199045e 100644 --- a/drivers/video/video_mcux_mipi_csi2rx.c +++ b/drivers/video/video_mcux_mipi_csi2rx.c @@ -20,6 +20,10 @@ 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; @@ -322,7 +326,7 @@ 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_GET(DT_INST_PHANDLE(n, sensor)), \ + .sensor_dev = DEVICE_DT_INST_GET_SENSOR_DEV(n), \ }; \ \ DEVICE_DT_INST_DEFINE(n, &mipi_csi2rx_init, NULL, &mipi_csi2rx_data_##n, \ diff --git a/dts/bindings/video/nxp,mipi-csi2rx.yaml b/dts/bindings/video/nxp,mipi-csi2rx.yaml index c644083e61ffc7..727289e567b3d1 100644 --- a/dts/bindings/video/nxp,mipi-csi2rx.yaml +++ b/dts/bindings/video/nxp,mipi-csi2rx.yaml @@ -10,12 +10,6 @@ compatible: "nxp,mipi-csi2rx" include: [base.yaml] -properties: - sensor: - required: true - type: phandle - description: the connected camera sensor - child-binding: child-binding: child-binding: diff --git a/tests/drivers/build_all/video/mimxrt1170_evk_mimxrt1176_cm7.overlay b/tests/drivers/build_all/video/mimxrt1170_evk_mimxrt1176_cm7.overlay index 0619309444fc63..aef4dce37c1c9a 100644 --- a/tests/drivers/build_all/video/mimxrt1170_evk_mimxrt1176_cm7.overlay +++ b/tests/drivers/build_all/video/mimxrt1170_evk_mimxrt1176_cm7.overlay @@ -60,7 +60,6 @@ compatible = "nxp,mipi-csi2rx"; reg = <0x33334444 0x200>; status = "okay"; - sensor = <&test_i2c_ov5640>; ports { #address-cells = <1>; From b3b0388f7e537aa324bbb9b3ba29647b21abc3ea Mon Sep 17 00:00:00 2001 From: Phi Bang Nguyen Date: Mon, 21 Oct 2024 22:00:15 +0200 Subject: [PATCH 18/19] drivers: video: csi: Remove source device phandle The peer remote device "source_dev" can be retrieved from the remote-endpoint-label. Direct reference via phandle is not needed. Signed-off-by: Phi Bang Nguyen --- boards/madmachine/mm_swiftio/mm_swiftio.dts | 1 - .../dvp_fpc24_mt9m114/boards/mimxrt1060_evkb.overlay | 9 --------- .../dvp_fpc24_mt9m114/boards/mimxrt1064_evk.overlay | 9 --------- drivers/video/video_mcux_csi.c | 12 +++++++++++- dts/arm/nxp/nxp_rt11xx.dtsi | 1 - dts/bindings/video/nxp,imx-csi.yaml | 6 ------ .../video/mimxrt1170_evk_mimxrt1176_cm7.overlay | 1 - 7 files changed, 11 insertions(+), 28 deletions(-) delete mode 100644 boards/shields/dvp_fpc24_mt9m114/boards/mimxrt1060_evkb.overlay delete mode 100644 boards/shields/dvp_fpc24_mt9m114/boards/mimxrt1064_evk.overlay diff --git a/boards/madmachine/mm_swiftio/mm_swiftio.dts b/boards/madmachine/mm_swiftio/mm_swiftio.dts index 2f01c730bc118e..7fa2a9cd37cff4 100644 --- a/boards/madmachine/mm_swiftio/mm_swiftio.dts +++ b/boards/madmachine/mm_swiftio/mm_swiftio.dts @@ -192,7 +192,6 @@ &csi { status = "okay"; - source = <&ov7725>; pinctrl-0 = <&pinmux_csi>; pinctrl-names = "default"; diff --git a/boards/shields/dvp_fpc24_mt9m114/boards/mimxrt1060_evkb.overlay b/boards/shields/dvp_fpc24_mt9m114/boards/mimxrt1060_evkb.overlay deleted file mode 100644 index a4aa7a273080dd..00000000000000 --- a/boards/shields/dvp_fpc24_mt9m114/boards/mimxrt1060_evkb.overlay +++ /dev/null @@ -1,9 +0,0 @@ -/* - * Copyright 2024 NXP - * - * SPDX-License-Identifier: Apache-2.0 - */ - -&dvp_fpc24_interface { - source = <&mt9m114>; -}; diff --git a/boards/shields/dvp_fpc24_mt9m114/boards/mimxrt1064_evk.overlay b/boards/shields/dvp_fpc24_mt9m114/boards/mimxrt1064_evk.overlay deleted file mode 100644 index a4aa7a273080dd..00000000000000 --- a/boards/shields/dvp_fpc24_mt9m114/boards/mimxrt1064_evk.overlay +++ /dev/null @@ -1,9 +0,0 @@ -/* - * Copyright 2024 NXP - * - * SPDX-License-Identifier: Apache-2.0 - */ - -&dvp_fpc24_interface { - source = <&mt9m114>; -}; diff --git a/drivers/video/video_mcux_csi.c b/drivers/video/video_mcux_csi.c index b0ca8440dfc77b..6fc4e662343957 100644 --- a/drivers/video/video_mcux_csi.c +++ b/drivers/video/video_mcux_csi.c @@ -18,6 +18,16 @@ #include #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; @@ -497,7 +507,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_GET(DT_INST_PHANDLE(0, source)), + .source_dev = DEVICE_DT_INST_GET_SOURCE_DEV(0), .pincfg = PINCTRL_DT_INST_DEV_CONFIG_GET(0), }; diff --git a/dts/arm/nxp/nxp_rt11xx.dtsi b/dts/arm/nxp/nxp_rt11xx.dtsi index 9ac5a32d6c61fe..214e35f2a8e3cf 100644 --- a/dts/arm/nxp/nxp_rt11xx.dtsi +++ b/dts/arm/nxp/nxp_rt11xx.dtsi @@ -888,7 +888,6 @@ reg = <0x40800000 0x4000>; interrupts = <56 1>; status = "disabled"; - source = <&mipi_csi2rx>; port { csi_ep_in: endpoint { diff --git a/dts/bindings/video/nxp,imx-csi.yaml b/dts/bindings/video/nxp,imx-csi.yaml index fa24ea25901238..f8f146c9c425de 100644 --- a/dts/bindings/video/nxp,imx-csi.yaml +++ b/dts/bindings/video/nxp,imx-csi.yaml @@ -14,12 +14,6 @@ properties: interrupts: required: true - source: - required: true - type: phandle - description: the connected source device, - e.g., a mipi csi or a camera sensor - child-binding: child-binding: include: video-interfaces.yaml diff --git a/tests/drivers/build_all/video/mimxrt1170_evk_mimxrt1176_cm7.overlay b/tests/drivers/build_all/video/mimxrt1170_evk_mimxrt1176_cm7.overlay index aef4dce37c1c9a..6d6559e4631546 100644 --- a/tests/drivers/build_all/video/mimxrt1170_evk_mimxrt1176_cm7.overlay +++ b/tests/drivers/build_all/video/mimxrt1170_evk_mimxrt1176_cm7.overlay @@ -53,7 +53,6 @@ status = "okay"; interrupt-parent = <&nvic>; interrupts = <56 1>; - source = <&test_mipi_csi2rx>; }; test_mipi_csi2rx: mipi_csi2rx@33334444 { From 6c68e6b208b3000c0ba9a1e1df734fc3204d1d22 Mon Sep 17 00:00:00 2001 From: Phi Bang Nguyen Date: Mon, 21 Oct 2024 22:00:45 +0200 Subject: [PATCH 19/19] drivers: video: csi: Increase init priority The CSI needs to be initialized BEFORE the camera sensor to provide clock to the camera sensor. It is now possible to do so as direct reference to the sensor via phandle is now not needed, so there is no failed check on the init order anymore when compiling. Signed-off-by: Phi Bang Nguyen --- drivers/video/Kconfig.mcux_csi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/video/Kconfig.mcux_csi b/drivers/video/Kconfig.mcux_csi index 88b57d3b461f17..e9bc48c7bd0915 100644 --- a/drivers/video/Kconfig.mcux_csi +++ b/drivers/video/Kconfig.mcux_csi @@ -11,7 +11,7 @@ config VIDEO_MCUX_CSI config VIDEO_MCUX_CSI_INIT_PRIORITY int "NXP MCUX CSI init priority" - default 61 + default 59 depends on VIDEO_MCUX_CSI help Initialization priority for the CSI interface on an NXP MCUX device.